SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
CVManager.h
1 
20 #pragma once
21 
22 #include "CollectiveVariable.h"
23 #include <vector>
24 
25 namespace SSAGES
26 {
28 
40  class CVManager
41  {
42  private:
44  std::vector<CollectiveVariable*> cvs_;
45 
47  static std::map<std::string, unsigned int> cvmap_;
48 
49  public:
50  CVManager() = default;
51 
53 
58  {
59  if(std::find(cvs_.begin(), cvs_.end(), cv) == cvs_.end())
60  cvs_.push_back(cv);
61  }
62 
64  /*
65  * \note This destroys all CVs stored in the CV manager!
66  */
67  void ClearCVs()
68  {
69  for(auto& cv : cvs_)
70  delete cv;
71  cvs_.clear();
72  }
73 
75  /*
76  * \param mask Vector mask which contains the indices of
77  * which CV to include in the container.
78  * \return Vector containing pointers to requested CVs.
79  */
80  std::vector<CollectiveVariable*> GetCVs(const std::vector<unsigned int>& mask = std::vector<unsigned int>()) const
81  {
82  if(mask.empty())
83  return cvs_;
84 
85  // Pack from mask.
86  std::vector<CollectiveVariable*> cvs;
87  for(auto& i : mask)
88  cvs.push_back(cvs_[i]);
89 
90  return cvs;
91  }
92 
94  /*
95  * \param name Name of CV to register.
96  * \param id ID to associate with name.
97  *
98  * \note If a previous name is already used, it will override the old entry.
99  */
100  static void AddCVtoMap(const std::string& name, unsigned int id)
101  {
102  cvmap_[name] = id;
103  }
104 
106  /*
107  * \param name Name of CV to look up.
108  * \return ID of CV. -1 if nonexistent.
109  */
110  static int LookupCV(const std::string& name)
111  {
112  if(cvmap_.find(name) == cvmap_.end())
113  return -1;
114 
115  return cvmap_.at(name);
116  }
117 
118  ~CVManager()
119  {
120  for(auto& cv : cvs_)
121  delete cv;
122  }
123  };
124 }
std::vector< CollectiveVariable * > GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Definition: CVManager.h:80
Collective variable manager.
Definition: CVManager.h:40
std::vector< CollectiveVariable * > cvs_
List of collective variables.
Definition: CVManager.h:44
static void AddCVtoMap(const std::string &name, unsigned int id)
Register CV name with map.
Definition: CVManager.h:100
static std::map< std::string, unsigned int > cvmap_
Map between CV names and ID&#39;s.
Definition: CVManager.h:47
void AddCV(CollectiveVariable *cv)
Adds a CV to the CV manager.
Definition: CVManager.h:57
void ClearCVs()
Clears CVs from CV manager.
Definition: CVManager.h:67
static int LookupCV(const std::string &name)
Get CV id from map.
Definition: CVManager.h:110
Abstract class for a collective variable.