Molecular Dynamics Simulation  1.0
TargettedTemporaryConstantForce.cpp
Go to the documentation of this file.
2 
3 #include <spdlog/formatter.h>
4 
5 #include "utils/ArrayUtils.h"
6 
7 TargettedTemporaryConstantForce::TargettedTemporaryConstantForce(const std::vector<size_t>& targetIndices,
8  const std::array<double, 3UL>& force, double start_time, double end_time)
9  : TargettedForceSource(targetIndices), force(force), start_time(start_time), end_time(end_time) {}
10 
11 void TargettedTemporaryConstantForce::applyForce(std::vector<Particle>& particle_vector, double curr_simulation_time) const {
12  if (curr_simulation_time < start_time || curr_simulation_time > end_time) {
13  return;
14  }
15 
16  for (auto& index : target_indices) {
17  Particle& particle = particle_vector[index];
18  particle.setF(particle.getF() + force);
19  }
20 }
21 
22 TargettedTemporaryConstantForce::operator std::string() const {
23  return fmt::format("TargettedTemporaryConstantForce (start: {}, end: {}, force: [{}, {}, {}])", start_time, end_time, force[0],
24  force[1], force[2]);
25 }
Class to represent a particle.
Definition: Particle.h:26
void setF(const std::array< double, 3 > &f)
Sets the force of the particle.
Definition: Particle.h:123
const std::array< double, 3 > & getF() const
Gets the total force of the particle.
Definition: Particle.h:167
Interface for targetted force source classes.
std::vector< size_t > target_indices
Indices of the particles on which the force is applied.
const double end_time
End Time within the simulation until which the force is exerted.
TargettedTemporaryConstantForce(const std::vector< size_t > &targetIndices, const std::array< double, 3 > &force, double start_time, double end_time)
Construct a new Targetted Temporary Constant Force object.
void applyForce(std::vector< Particle > &particle_vector, double curr_simulation_time) const override
Applies the force directly to the particles with the specified indices within the vector.
const std::array< double, 3 > force
Force exerted on the particles.