faunus
montecarlo.h
1 #pragma once
2 #ifndef FAUNUS_MONTECARLO_H
3 #define FAUNUS_MONTECARLO_H
4 
5 #include "space.h"
6 #include <memory>
7 
8 namespace Faunus {
9 
10 namespace Energy {
11 class Hamiltonian;
12 }
13 
14 namespace move {
15 class Move;
16 class MoveCollection;
17 } // namespace move
18 
36 {
37  public:
52  struct State
53  {
54  std::unique_ptr<Space> spc;
55  std::unique_ptr<Energy::Hamiltonian> pot;
56  void
57  sync(const State& other,
58  const Change& change);
59  };
60 
61  private:
62  spdlog::level::level_enum original_log_level;
63  std::unique_ptr<State> state;
64  std::unique_ptr<State> trial_state;
65  std::unique_ptr<move::MoveCollection> moves;
66  std::string latest_move_name;
67  double sum_of_energy_changes = 0.0;
68  double initial_energy = 0.0;
69  Average<double> average_energy;
70  void init();
71  void performMove(move::Move& move);
72  double getEnergyChange(double new_energy, double old_energy) const;
73  friend void to_json(json&, const MetropolisMonteCarlo&);
74  unsigned int number_of_sweeps = 0;
75 
76  public:
77  MetropolisMonteCarlo(const json& j);
78  Energy::Hamiltonian& getHamiltonian();
79  Space& getSpace();
80  Space& getTrialSpace();
81  double relativeEnergyDrift();
82  void sweep();
83  void restore(const json& j);
84  static bool metropolisCriterion(double energy_change);
86 };
87 
88 void from_json(const json&, MetropolisMonteCarlo::State&);
89 void to_json(json&, const MetropolisMonteCarlo&);
90 
113 {
114  private:
115  const Space& trial_spc;
116  const Space& spc;
117  double bias(int trial_count, int count) const;
118  double atomSwapEnergy(
119  const Change::GroupChange& group_change) const;
120  double atomChangeEnergy(int molid) const;
121  double moleculeChangeEnergy(
122  int molid) const;
123 
124  public:
125  TranslationalEntropy(const Space& trial_space, const Space& space);
126  double energy(const Change& change);
127 };
128 
129 } // namespace Faunus
130 #endif // FAUNUS_MONTECARLO_H
nlohmann::json json
JSON object.
Definition: json_support.h:10
Base class for all moves (MC, Langevin, ...)
Definition: move.h:38
Class to handle Monte Carlo moves.
Definition: montecarlo.h:35
std::unique_ptr< Space > spc
Simulation space (positions, geometry, molecules)
Definition: montecarlo.h:54
Properties of changed groups.
Definition: space.h:40
std::unique_ptr< Energy::Hamiltonian > pot
Hamiltonian for calc. potential energy.
Definition: montecarlo.h:55
Cell list class templates.
Definition: actions.cpp:11
Aggregate and sum energy terms.
Definition: energy.h:1954
Specify changes made to a system.
Definition: space.h:29
Placeholder for atoms and molecules.
Definition: space.h:92
Entropy change due to particle fluctuations.
Definition: montecarlo.h:112
Class to describe a system state.
Definition: montecarlo.h:52