SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
SSAGES::CVManager Class Reference

Collective variable manager. More...

#include <CVManager.h>

Public Member Functions

void AddCV (CollectiveVariable *cv)
 Adds a CV to the CV manager. More...
 
void ClearCVs ()
 Clears CVs from CV manager. More...
 
CVList GetCVs (const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
 Get CV iterator. More...
 

Static Public Member Functions

static void AddCVtoMap (const std::string &name, unsigned int id)
 Register CV name with map. More...
 
static int LookupCV (const Json::Value &cv, const std::string &path)
 Get CV id from map. More...
 

Private Attributes

std::vector< CollectiveVariable * > cvs_
 List of collective variables.
 

Static Private Attributes

static std::map< std::string, unsigned int > cvmap_ = {}
 Map between CV names and ID's.
 

Detailed Description

Collective variable manager.

CVManager is a class used to manage collective variables (CVs) and how they are exposed to methods. A metohd may wish to bias on a subset of available CVs. The CVManager provides a seamless interface to masking unwanted CVs and providing a suitable iterator which can be used to iterate through the desired CVs.

CVManager is also responsible for maintaining the lifetime of the CV objects it contains.

Definition at line 42 of file CVManager.h.

Member Function Documentation

◆ AddCV()

void SSAGES::CVManager::AddCV ( CollectiveVariable cv)
inline

Adds a CV to the CV manager.

Parameters
cvPointer to collective variable.

Definition at line 58 of file CVManager.h.

59  {
60  if(std::find(cvs_.begin(), cvs_.end(), cv) == cvs_.end())
61  cvs_.push_back(cv);
62  }
std::vector< CollectiveVariable * > cvs_
List of collective variables.
Definition: CVManager.h:46

References cvs_.

◆ AddCVtoMap()

static void SSAGES::CVManager::AddCVtoMap ( const std::string &  name,
unsigned int  id 
)
inlinestatic

Register CV name with map.

Parameters
nameName of CV to register.
idID to associate with name.
Note
If a previous name is already used, it will override the old entry.

Definition at line 101 of file CVManager.h.

102  {
103  cvmap_[name] = id;
104  }
static std::map< std::string, unsigned int > cvmap_
Map between CV names and ID's.
Definition: CVManager.h:49

References cvmap_.

Referenced by SSAGES::ResourceHandler::Build().

Here is the caller graph for this function:

◆ ClearCVs()

void SSAGES::CVManager::ClearCVs ( )
inline

Clears CVs from CV manager.

Note
This destroys all CVs stored in the CV manager!

Definition at line 68 of file CVManager.h.

69  {
70  for(auto& cv : cvs_)
71  delete cv;
72  cvs_.clear();
73  }

References cvs_.

◆ GetCVs()

CVList SSAGES::CVManager::GetCVs ( const std::vector< unsigned int > &  mask = std::vector<unsigned int>()) const
inline

◆ LookupCV()

static int SSAGES::CVManager::LookupCV ( const Json::Value &  cv,
const std::string &  path 
)
inlinestatic

Get CV id from map.

Parameters
cvJSON Value (CV) to look up.
pathPath for JSON path specification.
Returns
ID of CV.

Definition at line 112 of file CVManager.h.

113  {
114  int id = -1;
115  if (cv.isString())
116  {
117  auto name = cv.asString();
118  if(cvmap_.find(name) == cvmap_.end())
119  {
120  throw BuildException({path + ": CV mask name \"" + name + "\" does not exist."});
121  }
122  id = cvmap_.at(name);
123  }
124  else if(cv.isIntegral())
125  {
126  id = cv.asInt();
127  if(id < 0 || id >= static_cast<int>(cvmap_.size()))
128  {
129  throw BuildException({path + ": CV mask index of " + std::to_string(id) + " does not exist. " +
130  "Index must be nonnegative and less than " + std::to_string(cvmap_.size()) + "."});
131  }
132  }
133  else
134  {
135  throw BuildException({path + ": CV mask must contain strings or nonnegative integers."});
136  }
137 
138  return id;
139  }

References cvmap_.

Referenced by SSAGES::ResourceHandler::Build().

Here is the caller graph for this function:

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