SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
SSAGES::Constraint Class Referenceabstract

Interface for Constraint implementations. More...

#include <Constraint.h>

Inheritance diagram for SSAGES::Constraint:
Inheritance graph
[legend]

Public Member Functions

 Constraint (unsigned int frequency, boost::mpi::communicator &comm)
 Constructor. More...
 
virtual ~Constraint ()
 Destructor.
 
virtual void PreSimulation (Snapshot *snapshot, const CVList &cvs) override=0
 Method call prior to simulation initiation. More...
 
virtual void PostIntegration (Snapshot *snapshot, const CVList &cvs) override=0
 Method call post integration. More...
 
virtual void PostSimulation (Snapshot *snapshot, const CVList &cvs) override=0
 Method call post simulation. More...
 
- Public Member Functions inherited from SSAGES::EventListener
 EventListener (uint frequency)
 Constructor. More...
 
uint GetFrequency () const
 Get frequency of event listener. More...
 
virtual void PreSimulation (Snapshot *snapshot, const class CVManager &cvmanager)=0
 Method call prior to simulation initiation. More...
 
virtual void PostIntegration (Snapshot *snapshot, const class CVManager &cvmanager)=0
 Method call post integration. More...
 
virtual void PostSimulation (Snapshot *snapshot, const class CVManager &cvmanager)=0
 Method call post simulation. More...
 
virtual ~EventListener ()
 Destructor.
 

Static Public Member Functions

static ConstraintBuildConstraint (const Json::Value &json, boost::mpi::communicator &comm)
 Build a constraint from a JSON node. More...
 
static ConstraintBuildConstraint (const Json::Value &json, boost::mpi::communicator &comm, const std::string &path)
 Overloaded function allowing JSON path specification. More...
 
static void BuildConstraint (const Json::Value &json, ConstraintList &clist, boost::mpi::communicator &comm, const std::string &path)
 Build constraint. More...
 

Protected Attributes

boost::mpi::communicator comm_
 MPI global communicator.
 

Detailed Description

Interface for Constraint implementations.

Definition at line 41 of file Constraint.h.

Constructor & Destructor Documentation

SSAGES::Constraint::Constraint ( unsigned int  frequency,
boost::mpi::communicator &  comm 
)
inline

Constructor.

Parameters
frequencyFrequency of sampling.
commMPI global communicator.
Note
Frequency of sampling must be specified by all methods.

Definition at line 55 of file Constraint.h.

56  :
57  EventListener(frequency), comm_(comm){}
boost::mpi::communicator comm_
MPI global communicator.
Definition: Constraint.h:45
EventListener(uint frequency)
Constructor.
Definition: EventListener.h:44

Member Function Documentation

Constraint * SSAGES::Constraint::BuildConstraint ( const Json::Value &  json,
boost::mpi::communicator &  comm 
)
static

Build a constraint from a JSON node.

Parameters
jsonJSON value containing input information.
commMPI communicator.
Returns
Pointer to the new constraint. nullptr in case of an unknown error.

This function builds a constraint from a JSON node. Returns a pointer to the built constraint. If an unknown error occured, the return value is nullptr, but in general, a BuildException will be thrown on failure.

Note
Object lifetime is the caller's responsibility.

Definition at line 33 of file Constraint.cpp.

35  {
36  return BuildConstraint(json, comm, "#/Constraints");
37  }
static Constraint * BuildConstraint(const Json::Value &json, boost::mpi::communicator &comm)
Build a constraint from a JSON node.
Definition: Constraint.cpp:33
Constraint * SSAGES::Constraint::BuildConstraint ( const Json::Value &  json,
boost::mpi::communicator &  comm,
const std::string &  path 
)
static

Overloaded function allowing JSON path specification.

Parameters
jsonJSON value containing input information.
commMPI global communicator.
pathPath for JSON path specification.
Returns
Pointer to the new constraint. nullptr in case of an unknown error.

Definition at line 39 of file Constraint.cpp.

References Json::Requirement::GetErrors(), Json::Requirement::HasErrors(), Json::ObjectRequirement::Parse(), and Json::ObjectRequirement::Validate().

42  {
43  ObjectRequirement validator;
44  Value schema;
45  Reader reader;
46 
47  Constraint* constraint = nullptr;
48 
49  // Random device for seed generation.
50  // std::random_device rd;
51  // auto maxi = std::numeric_limits<int>::max();
52  // auto seed = json.get("seed", rd() % maxi).asUInt();
53 
54  // Get move type.
55  std::string type = json.get("type", "none").asString();
56 
57  if(type == "COPSS")
58  {
59  reader.parse(JsonSchema::COPSSConstraint, schema);
60  validator.Parse(schema, path);
61 
62  // Validate inputs.
63  validator.Validate(json, path);
64  if(validator.HasErrors())
65  throw BuildException(validator.GetErrors());
66 
67  auto* c = new COPSS(comm, 1);
68 
69  constraint = static_cast<Constraint*>(c);
70  }
71  else if(type == "COPSSImage")
72  {
73  reader.parse(JsonSchema::COPSSImageConstraint, schema);
74  validator.Parse(schema, path);
75 
76  // Validate inputs.
77  validator.Validate(json, path);
78  if(validator.HasErrors())
79  throw BuildException(validator.GetErrors());
80 
81  double einner = json.get("einner",1).asDouble();
82 
83  int ion_type_start = json.get("ion_type_start",1).asInt();
84 
85  std::vector<double> atomTypeRadius;
86  for(auto& atomType : json["atom type radius"])
87  atomTypeRadius.push_back(atomType.asDouble());
88 
89  auto* c = new COPSSImage(comm, 1, einner, ion_type_start, atomTypeRadius);
90 
91  constraint = static_cast<Constraint*>(c);
92 
93  }
94  else
95  {
96  throw BuildException({path + ": Unknown constraint type specified."+type+" is not a valid type!"});
97  }
98 
99  return constraint;
100  }
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
Requirements on an object.
Constraint(unsigned int frequency, boost::mpi::communicator &comm)
Constructor.
Definition: Constraint.h:55
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.

Here is the call graph for this function:

void SSAGES::Constraint::BuildConstraint ( const Json::Value &  json,
ConstraintList clist,
boost::mpi::communicator &  comm,
const std::string &  path 
)
static

Build constraint.

Parameters
jsonJSON value containing input information.
clistList of constraints.
commMPI global communicator.
pathPath for JSON path specification.

This function builds a new constraint and adds it to the specified list of constraints. On failure, an exception is thrown.

Note
Object lifetime management is caller's responsibility.

Definition at line 102 of file Constraint.cpp.

References BuildConstraint(), Json::Requirement::GetErrors(), Json::Requirement::HasErrors(), Json::ArrayRequirement::Parse(), and Json::ArrayRequirement::Validate().

Referenced by BuildConstraint().

106  {
107  ArrayRequirement validator;
108  Value schema;
109  Reader reader;
110 
111  reader.parse(JsonSchema::constraints, schema);
112  validator.Parse(schema, path);
113 
114  // Validate high level schema.
115  validator.Validate(json, path);
116  if(validator.HasErrors())
117  throw BuildException(validator.GetErrors());
118 
119  // Loop through CVs.
120  int i = 0;
121  for(auto& m : json)
122  {
123  clist.push_back(BuildConstraint(m, comm, path + "/" + std::to_string(i)));
124  ++i;
125  }
126  }
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86
Array of Requirements.
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
static Constraint * BuildConstraint(const Json::Value &json, boost::mpi::communicator &comm)
Build a constraint from a JSON node.
Definition: Constraint.cpp:33
virtual void Validate(const Value &json, const std::string &path) override
Validate json value.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and fill array.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void SSAGES::Constraint::PostIntegration ( Snapshot snapshot,
const CVList cvs 
)
overridepure virtual

Method call post integration.

Parameters
snapshotPointer to current snapshot.
cvsList of CVs.

Implemented in SSAGES::COPSSImage, and SSAGES::COPSS.

virtual void SSAGES::Constraint::PostSimulation ( Snapshot snapshot,
const CVList cvs 
)
overridepure virtual

Method call post simulation.

Parameters
snapshotPointer to current snapshot.
cvsList of CVs.

Implemented in SSAGES::COPSSImage, and SSAGES::COPSS.

virtual void SSAGES::Constraint::PreSimulation ( Snapshot snapshot,
const CVList cvs 
)
overridepure virtual

Method call prior to simulation initiation.

Parameters
snapshotSimulation snapshot.
cvsList of CVs.

Implemented in SSAGES::COPSSImage, and SSAGES::COPSS.


The documentation for this class was generated from the following files: