faunus
forcemove.h
1 #pragma once
2 #include "move.h"
3 #include "energy.h"
4 
5 namespace Faunus::move {
6 
24 {
25  std::normal_distribution<double> normal_distribution;
26 
27  public:
28  explicit NormalRandomVector(double mean = 0.0, double stddev = 1.0)
29  : normal_distribution(mean, stddev) {};
30 
31  template <typename random_engine> Point operator()(random_engine& engine)
32  {
33  return {normal_distribution(engine), normal_distribution(engine),
34  normal_distribution(engine)};
35  }
36 };
37 
46 {
47  protected:
48  Space& spc;
49  Energy::EnergyTerm& energy;
51  virtual ~IntegratorBase() = default;
52 
53  public:
60  virtual void step(PointVector& velocities,
61  PointVector& forces) = 0; // todo shall we return real time progress?
62  virtual void from_json(const json& j) = 0;
63  virtual void to_json(json& j) const = 0;
64 };
65 
66 void from_json(const json& j, IntegratorBase& i);
67 void to_json(json& j, const IntegratorBase& i);
68 
75 {
76  double time_step;
77  double friction_coefficient;
79  random_vector;
80  [[nodiscard]] inline Point positionIncrement(
81  const Point& velocity) const;
82  [[nodiscard]] inline Point
83  velocityIncrement(const Point& force,
84  double mass) const;
85  inline Point velocityFluctuationDissipation(const Point& velocity, double mass);
88 
89  public:
91  LangevinVelocityVerlet(Space& spc, Energy::EnergyTerm& energy, double time_step,
92  double friction_coefficient);
93  LangevinVelocityVerlet(Space& spc, Energy::EnergyTerm& energy, const json& j);
94  void step(PointVector& velocities, PointVector& forces) override;
95  void from_json(const json& j) override;
96  void to_json(json& j) const override;
97 };
98 
99 void from_json(const json& j, IntegratorBase& i);
100 void to_json(json& j, const IntegratorBase& i);
101 
108 class ForceMove : public Move
109 {
110  protected:
111  std::shared_ptr<IntegratorBase> integrator;
112  unsigned int
116 
117  size_t resizeForcesAndVelocities();
118  void generateVelocities();
120  void _to_json(json& j) const override;
121  void _from_json(const json& j) override;
122  void _move(Change& change) override;
123  ForceMove(Space& spc, const std::string& name, const std::string& cite,
124  std::shared_ptr<IntegratorBase> integrator, unsigned int nsteps);
125  ~ForceMove() override = default;
126 
127  public:
128  double bias(Change&, double, double) override;
129  [[nodiscard]] const PointVector& getForces() const;
130  [[nodiscard]] const PointVector& getVelocities() const;
131 };
132 
137 {
138  protected:
139  LangevinDynamics(Space& spc, const std::string& name, const std::string& cite,
140  std::shared_ptr<IntegratorBase> integrator, unsigned int nsteps);
141 
142  public:
143  LangevinDynamics(Space& spc, std::shared_ptr<IntegratorBase> integrator, unsigned int nsteps);
146  void _to_json(json& j) const override;
147  void _from_json(const json& j) override;
148 };
149 
150 } // namespace Faunus::move
nlohmann::json json
JSON object.
Definition: json_support.h:10
Eigen::Vector3d Point
3D vector used for positions, velocities, forces etc.
Definition: coordinates.h:7
std::vector< Point > PointVector
Vector of 3D vectors.
Definition: core.h:24
PointVector velocities
Vector of velocities matching each active particle in Space.
Definition: forcemove.h:114
Base class for all moves (MC, Langevin, ...)
Definition: move.h:38
Definition: chainmove.cpp:6
unsigned int number_of_steps
number of integration steps to perform during a single MC move
Definition: forcemove.h:113
Base class for dynamics integrators.
Definition: forcemove.h:45
Langevin dynamics move using Langevin equation of motion.
Definition: forcemove.h:136
All energies inherit from this class.
Definition: externalpotential.h:21
Specify changes made to a system.
Definition: space.h:29
Generate a random 3d vector from the normal distribution.
Definition: forcemove.h:23
Placeholder for atoms and molecules.
Definition: space.h:92
Symmetric Langevin velocity-Verlet method (BAOAB)
Definition: forcemove.h:74
Base class for force moves, e.g., molecular dynamics or Langevin dynamics.
Definition: forcemove.h:108
PointVector forces
Vector of forces matching each active particle in Space.
Definition: forcemove.h:115