faunus
penalty.h
1 #pragma once
2 
3 #include "mpicontroller.h"
4 #include "externalpotential.h"
5 #include "reactioncoordinate.h"
6 #include "aux/table_1d.h"
7 
8 namespace Faunus::Energy {
9 
17 class Penalty : public EnergyTerm
18 {
19  private:
20  const Space& spc;
21  std::string penalty_function_filename;
22  std::string histogram_filename;
23  bool overwrite_penalty = true; // overwrite input penalty function?
24  void loadPenaltyFunction(const std::string& filename);
25  void toDisk();
26  void initializePenaltyFunction(const json& j);
27  void to_json(json& j) const override;
28  virtual void updatePenalty(const std::vector<double>& coordinate);
29 
30  protected:
31  typedef typename std::shared_ptr<ReactionCoordinate::ReactionCoordinateBase> Tcoord;
32  bool verbose = false;
33  bool avoid_energy_drift = true;
35  size_t update_counter = 0;
37  size_t penalty_function_exchange_counter = 0;
38  size_t samplings;
41  double energy_increment = 0.0;
42  std::vector<Tcoord> reaction_coordinates_functions;
43  std::vector<double> latest_coordinate;
45 
48  void logBarrierInformation() const;
49 
50  public:
51  Penalty(const json& j, const Space& spc);
52  ~Penalty() override;
53  double energy(const Change& change) override;
54  void sync(EnergyTerm* other, const Change& change) override;
55  void streamPenaltyFunction(std::ostream& stream) const;
56  void streamHistogram(std::ostream& stream) const;
57 };
58 
59 #ifdef ENABLE_MPI
60 
63 class PenaltyMPI : public Penalty
64 {
65  private:
66  const MPI::Controller& mpi;
67  Eigen::VectorXi weights;
68  Eigen::VectorXd buffer;
69  void updatePenalty(const std::vector<double>& coordinate)
70  override;
71  void averagePenaltyFunctions();
72  public:
73  PenaltyMPI(const json& j, Space& spc, const MPI::Controller& mpi);
74 };
75 #endif
76 
77 } // namespace Faunus::Energy
nlohmann::json json
JSON object.
Definition: json_support.h:10
size_t number_of_reaction_coordinates
number of reaction coordinate
Definition: penalty.h:34
bool avoid_energy_drift
avoid energy drift when upgrading penalty function
Definition: penalty.h:33
sum_of_energy_increments is the total change of updating the energy function.
Definition: penalty.h:17
Table< double > penalty_energy
penalty energy as a function of coordinates
Definition: penalty.h:47
Table< unsigned int > histogram
count how often a reaction coordinate is visited
Definition: penalty.h:46
size_t number_of_steps_between_updates
update frequency [steps]
Definition: penalty.h:36
~Penalty() override
destruct and save to disk (!)
Definition: penalty.cpp:78
Definition: actions.h:8
double sum_of_energy_increments
total energy change of updating penalty function
Definition: penalty.h:39
std::vector< double > latest_coordinate
latest reaction coordinate (length = 1 or 2)
Definition: penalty.h:44
std::vector< Tcoord > reaction_coordinates_functions
vector of reaction coordinate functions (length = 1 or 2)
Definition: penalty.h:42
void logBarrierInformation() const
Add barrier information to output log.
Definition: penalty.cpp:176
void sync(EnergyTerm *other, const Change &change) override
Called when a move is accepted or rejected, as well as when initializing the system.
Definition: penalty.cpp:187
void streamPenaltyFunction(std::ostream &stream) const
Stream penalty function, offset with the minimum observed energy.
Definition: penalty.cpp:86
All energies inherit from this class.
Definition: externalpotential.h:21
Specify changes made to a system.
Definition: space.h:29
double energy_increment_scaling_factor
scaling factor for f0
Definition: penalty.h:40
double energy(const Change &change) override
energy due to change
Definition: penalty.cpp:129
Placeholder for atoms and molecules.
Definition: space.h:92
bool verbose
kæft op?
Definition: penalty.h:32
double energy_increment
penalty increment
Definition: penalty.h:41
size_t update_counter
number of calls to sync()
Definition: penalty.h:35