Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
TargettedTemporaryConstantForce Class Reference

Class for a constant force source. More...

#include <TargettedTemporaryConstantForce.h>

Inheritance diagram for TargettedTemporaryConstantForce:
Inheritance graph
Collaboration diagram for TargettedTemporaryConstantForce:
Collaboration graph

Public Member Functions

 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. More...
 
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. More...
 
 operator std::string () const override
 Conversion from a force source object to a string containing its name. More...
 
- Public Member Functions inherited from TargettedForceSource
 TargettedForceSource (const std::vector< size_t > &target_indices)
 
virtual ~TargettedForceSource ()=default
 Virtual destructor for correct cleanup of derived classes. More...
 

Private Attributes

const std::array< double, 3 > force
 Force exerted on the particles. More...
 
const double start_time
 Start Time within the simulation from which on the force is exerted. More...
 
const double end_time
 End Time within the simulation until which the force is exerted. More...
 

Additional Inherited Members

- Protected Attributes inherited from TargettedForceSource
std::vector< size_t > target_indices
 Indices of the particles on which the force is applied. More...
 

Detailed Description

Class for a constant force source.

Class for a constant force source, which exerts a constant force on the particles with the specified indices.

Definition at line 10 of file TargettedTemporaryConstantForce.h.

Constructor & Destructor Documentation

◆ TargettedTemporaryConstantForce()

TargettedTemporaryConstantForce::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.

Parameters
targetIndicesIndices of the particles on which the force is applied
forceForce exerted on the particles
start_timeTime for which the force is exerted
end_timeTime until which the force is exerted

Definition at line 7 of file TargettedTemporaryConstantForce.cpp.

TargettedForceSource(const std::vector< size_t > &target_indices)
const double end_time
End Time within the simulation until which the force is exerted.
const std::array< double, 3 > force
Force exerted on the particles.
const double start_time
Start Time within the simulation from which on the force is exerted.

Member Function Documentation

◆ applyForce()

void TargettedTemporaryConstantForce::applyForce ( std::vector< Particle > &  particle_vector,
double  curr_simulation_time 
) const
overridevirtual

Applies the force directly to the particles with the specified indices within the vector.

Parameters
particle_vectorParticle vector on which the force is applied
curr_simulation_timeCurrent simulation time

Calculates and applies the force exerted on the particles identified by index within the given particle vector.

Implements TargettedForceSource.

Definition at line 11 of file TargettedTemporaryConstantForce.cpp.

11  {
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 }
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
std::vector< size_t > target_indices
Indices of the particles on which the force is applied.

◆ operator std::string()

TargettedTemporaryConstantForce::operator std::string ( ) const
explicitoverridevirtual

Conversion from a force source object to a string containing its name.

Implements TargettedForceSource.

Definition at line 22 of file TargettedTemporaryConstantForce.cpp.

22  {
23  return fmt::format("TargettedTemporaryConstantForce (start: {}, end: {}, force: [{}, {}, {}])", start_time, end_time, force[0],
24  force[1], force[2]);
25 }

Member Data Documentation

◆ end_time

const double TargettedTemporaryConstantForce::end_time
private

End Time within the simulation until which the force is exerted.

Definition at line 25 of file TargettedTemporaryConstantForce.h.

◆ force

const std::array<double, 3> TargettedTemporaryConstantForce::force
private

Force exerted on the particles.

Definition at line 15 of file TargettedTemporaryConstantForce.h.

◆ start_time

const double TargettedTemporaryConstantForce::start_time
private

Start Time within the simulation from which on the force is exerted.

Definition at line 20 of file TargettedTemporaryConstantForce.h.


The documentation for this class was generated from the following files: