SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
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 
65  static BoxVolumeCV* Build(const Json::Value& json, const std::string& path)
66  {
67  Json::ObjectRequirement validator;
68  Json::Value schema;
69  Json::CharReaderBuilder rbuilder;
70  Json::CharReader* reader = rbuilder.newCharReader();
71 
72  reader->parse(JsonSchema::BoxVolumeCV.c_str(),
73  JsonSchema::BoxVolumeCV.c_str() + JsonSchema::BoxVolumeCV.size(),
74  &schema, nullptr);
75  validator.Parse(schema, path);
76 
77  // Validate inputs.
78  validator.Validate(json, path);
79  if(validator.HasErrors())
80  throw BuildException(validator.GetErrors());
81 
82  return new BoxVolumeCV();
83  }
84  };
85 }
Requirements on an object.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86
Collective variable on the volume of a box.
Definition: BoxVolumeCV.h:37
void Initialize(const Snapshot &) override
Initialize the CV.
Definition: BoxVolumeCV.h:44
void Evaluate(const Snapshot &snapshot) override
Evaluate the CV.
Definition: BoxVolumeCV.h:52
static BoxVolumeCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
Definition: BoxVolumeCV.h:65
BoxVolumeCV()
Constructor.
Definition: BoxVolumeCV.h:40
Exception to be thrown when building the Driver fails.
Abstract class for a collective variable.
Matrix3 boxgrad_
Gradient w.r.t box vectors dCv/dHij.
std::vector< Vector3 > grad_
Gradient vector dCv/dxi.
double val_
Current value of CV.
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:48
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
Definition: Snapshot.h:202
double GetVolume() const
Get system volume.
Definition: Snapshot.h:159
const mxx::comm & GetCommunicator() const
Get communicator for walker.
Definition: Snapshot.h:186
Eigen::Vector3d Vector3
Three-dimensional vector.
Definition: types.h:33