SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
BoxVolumeCV.h
1 
20 #pragma once
21 
22 #include "CollectiveVariable.h"
23 #include "Validator/ObjectRequirement.h"
24 #include "Drivers/DriverException.h"
25 #include "Snapshot.h"
26 #include "schema.h"
27 
28 namespace SSAGES
29 {
31 
37  {
38  public:
41  {}
42 
44  void Initialize(const Snapshot& snapshot) override
45  {
46  }
47 
49 
52  void Evaluate(const Snapshot& snapshot) override
53  {
54  // Fill empty gradient.
55  auto n = snapshot.GetNumAtoms();
56  std::fill(grad_.begin(), grad_.end(), Vector3{0,0,0});
57  grad_.resize(n, Vector3{0,0,0});
58 
59  val_ = snapshot.GetVolume();
60  if(snapshot.GetCommunicator().rank() == 0)
61  boxgrad_ = val_*Matrix3::Identity();
62  }
63 
64  static BoxVolumeCV* Build(const Json::Value& json, const std::string& path)
65  {
66  Json::ObjectRequirement validator;
67  Json::Value schema;
68  Json::Reader reader;
69 
70  reader.parse(JsonSchema::BoxVolumeCV, schema);
71  validator.Parse(schema, path);
72 
73  // Validate inputs.
74  validator.Validate(json, path);
75  if(validator.HasErrors())
76  throw BuildException(validator.GetErrors());
77 
78  return new BoxVolumeCV();
79  }
80  };
81 }
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
Definition: Snapshot.h:200
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:43
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
Definition: BoxVolumeCV.h:52
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
std::vector< Vector3 > grad_
Gradient vector dCv/dxi.
const mxx::comm & GetCommunicator() const
Get communicator for walker.
Definition: Snapshot.h:184
void Initialize(const Snapshot &snapshot) override
Initialize the CV.
Definition: BoxVolumeCV.h:44
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
double GetVolume() const
Get system volume.
Definition: Snapshot.h:157
Requirements on an object.
Eigen::Vector3d Vector3
Three-dimensional vector.
Definition: types.h:33
double val_
Current value of CV.
Abstract class for a collective variable.
Matrix3 boxgrad_
Gradient w.r.t box vectors dCv/dHij.
BoxVolumeCV()
Constructor.
Definition: BoxVolumeCV.h:40
Collective variable on the volume of a box.
Definition: BoxVolumeCV.h:36
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.