SSAGES  0.8.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, NULL);
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 }
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
const mxx::comm & GetCommunicator() const
Get communicator for walker.
Definition: Snapshot.h:184
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.
static BoxVolumeCV * Build(const Json::Value &json, const std::string &path)
Set up collective variable.
Definition: BoxVolumeCV.h:65
double GetVolume() const
Get system volume.
Definition: Snapshot.h:157
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
void Initialize(const Snapshot &) override
Initialize the CV.
Definition: BoxVolumeCV.h:44
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.