Molecular Dynamics Simulation  1.0
VerletFunctor.cpp
Go to the documentation of this file.
1 #include "VerletFunctor.h"
2 
3 #include "utils/ArrayUtils.h"
4 
5 void VerletFunctor::step(std::unique_ptr<ParticleContainer>& particle_container,
6  const std::vector<std::shared_ptr<SimpleForceSource>>& simple_force_sources,
7  const std::vector<std::shared_ptr<PairwiseForceSource>>& pairwise_force_sources,
8  const std::vector<std::shared_ptr<TargettedForceSource>>& targetted_force_sources, double delta_t,
9  double curr_simulation_time) const {
10  for (auto& p : *particle_container) {
11  // update position
12  if (!p.isLocked()) {
13  const std::array<double, 3> new_x = p.getX() + delta_t * p.getV() + (delta_t * delta_t / (2 * p.getM())) * p.getF();
14  p.setX(new_x);
15  }
16 
17  // reset forces
18  p.setOldF(p.getF());
19  p.setF({0, 0, 0});
20  }
21 
22  // calculate new forces
23  particle_container->prepareForceCalculation();
24  particle_container->applySimpleForces(simple_force_sources);
25  particle_container->applyPairwiseForces(pairwise_force_sources);
26  particle_container->applyTargettedForces(targetted_force_sources, curr_simulation_time);
27 
28  // update velocity
29  for (auto& p : *particle_container) {
30  if (!p.isLocked()) {
31  const std::array<double, 3> new_v = p.getV() + (delta_t / (2 * p.getM())) * (p.getF() + p.getOldF());
32  p.setV(new_v);
33  } else {
34  p.setV({0, 0, 0});
35  }
36  }
37 }
void step(std::unique_ptr< ParticleContainer > &particle_container, const std::vector< std::shared_ptr< SimpleForceSource >> &simple_force_sources, const std::vector< std::shared_ptr< PairwiseForceSource >> &pairwise_force_sources, const std::vector< std::shared_ptr< TargettedForceSource >> &targetted_force_sources, double delta_t, double curr_simulation_time) const override
Performs one step with the respective integration method.