SSAGES  0.8.5
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

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
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.

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

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

Here is the caller graph for this function:

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  }
std::vector< CollectiveVariable * > cvs_
List of collective variables.
Definition: CVManager.h:46
CVList SSAGES::CVManager::GetCVs ( const std::vector< unsigned int > &  mask = std::vector<unsigned int>()) const
inline

Get CV iterator.

Parameters
maskVector mask which contains the indices of which CV to include in the container.
Returns
CVList containing pointers to requested CVs.

Definition at line 81 of file CVManager.h.

Referenced by SSAGES::DirectForwardFlux::CheckForInterfaceCrossings(), SSAGES::DirectForwardFlux::PostIntegration(), SSAGES::Logger::PostIntegration(), SSAGES::ElasticBand::PostIntegration(), SSAGES::FiniteTempString::PostIntegration(), SSAGES::Swarm::PostIntegration(), SSAGES::ANN::PostIntegration(), SSAGES::Umbrella::PostIntegration(), SSAGES::Meta::PostIntegration(), SSAGES::BFS::PostIntegration(), SSAGES::ABF::PostIntegration(), SSAGES::Hook::PostIntegrationHook(), SSAGES::Hook::PostSimulationHook(), SSAGES::Logger::PreSimulation(), SSAGES::ANN::PreSimulation(), SSAGES::Umbrella::PreSimulation(), SSAGES::Meta::PreSimulation(), SSAGES::StringMethod::PreSimulation(), SSAGES::BFS::PreSimulation(), SSAGES::ABF::PreSimulation(), SSAGES::ForwardFlux::PreSimulation(), and SSAGES::Hook::PreSimulationHook().

82  {
83  if(mask.empty())
84  return cvs_;
85 
86  // Pack from mask.
87  std::vector<CollectiveVariable*> cvs;
88  for(auto& i : mask)
89  cvs.push_back(cvs_[i]);
90 
91  return cvs;
92  }
std::vector< CollectiveVariable * > cvs_
List of collective variables.
Definition: CVManager.h:46

Here is the caller graph for this function:

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.

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

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  }
static std::map< std::string, unsigned int > cvmap_
Map between CV names and ID&#39;s.
Definition: CVManager.h:49

Here is the caller graph for this function:


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