Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
builder_Integrator.cpp
Go to the documentation of this file.
1 
14 #include "builder_Integrator.h"
15 
16 #include "integrator_UpdateU.h"
17 #include "integrator_UpdateP.h"
18 #include "integrator_Leapfrog.h"
19 #include "integrator_Omelyan.h"
20 
21 
22 
23 const std::string Builder_Integrator::class_name = "Builder_Integrator";
24 
25 //====================================================================
26 Builder_Integrator::Builder_Integrator(const ActionList& action_list, std::vector<Director *> director)
27  : m_vl(CommonParameters::Vlevel()),
28  m_Nprec(0),
29  m_lambda_Omelyan(0.0),
30  m_str_integrator_type(""),
31  m_actions(action_list),
32  m_director(director)
33 {
35 
36  m_Nprec = 0;
37  m_lambda_Omelyan = 0.0;
38 }
39 
40 
41 //====================================================================
43 {
44  const std::string str_vlevel = params.get_string("verbose_level");
45 
46  m_vl = vout.set_verbose_level(str_vlevel);
47 
48  //- fetch and check input parameters
49  std::string str_integrator_type;
50 
51  std::vector<int> Nstep;
52 
53  int Nprec;
54  double lambda_Omelyan;
55 
56  int err = 0;
57 
58  if (m_str_integrator_type == "") {
59  err += params.fetch_string("integrator", str_integrator_type);
60  } else {
61  str_integrator_type = m_str_integrator_type;
62  }
63 
64  err += params.fetch_int_vector("number_of_steps", Nstep);
65 
66  err += params.fetch_int("order_of_exp_iP", Nprec);
67 
68  if ((m_str_integrator_type == "") || (m_str_integrator_type == "Omelyan")) {
69  err += params.fetch_double("lambda_Omelyan", lambda_Omelyan);
70  } else {
71  lambda_Omelyan = 0.0;
72  }
73 
74  if (err) {
75  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
76  exit(EXIT_FAILURE);
77  }
78 
79 
80  set_parameters(str_integrator_type, Nstep, Nprec, lambda_Omelyan);
81 }
82 
83 
84 //====================================================================
85 void Builder_Integrator::set_parameters(std::string str_integrator_type,
86  const std::vector<int>& Nstep,
87  const int Nprec,
88  const double lambda_Omelyan)
89 {
90  //- print input parameters
91  vout.general(m_vl, "%s:\n", class_name.c_str());
92  vout.general(m_vl, " Integrator = %s\n", str_integrator_type.c_str());
93  for (int lv = 0; lv < Nstep.size(); ++lv) {
94  vout.general(m_vl, " level = %2d: Nstep = %4d\n", lv, Nstep[lv]);
95  }
96  vout.general(m_vl, " Nprec = %4d\n", Nprec);
97 
98  //- range check
99  int err = 0;
100  err += ParameterCheck::non_NULL(str_integrator_type);
101  // NB. Nstep == 0 is allowed.
102  err += ParameterCheck::non_zero(Nprec);
103  // NB. lambda_Omelyan == 0 is allowed.
104 
105  if (err) {
106  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
107  exit(EXIT_FAILURE);
108  }
109 
110  //- store values
111  m_str_integrator_type = str_integrator_type;
112 
113  m_Nstep = Nstep;
114 
115  m_Nprec = Nprec;
116  m_lambda_Omelyan = lambda_Omelyan;
117 }
118 
119 
120 //====================================================================
122 {
123  //- select leapfrog or omelyan
124  Integrator *integrator;
125 
126  if (m_str_integrator_type == "Leapfrog") {
127  integrator = build_leapfrog();
128  } else if (m_str_integrator_type == "Omelyan") {
129  integrator = build_omelyan();
130  } else {
131  vout.crucial("Error at %s::build : unsupported integrator type \"%s\".\n", class_name.c_str(), m_str_integrator_type.c_str());
132  exit(EXIT_FAILURE);
133  }
134 
135  return integrator;
136 }
137 
138 
139 //====================================================================
141 {
142  // ##### Following setup is for PUP order.
143 
144  // lowest level: update_U
146 
147  m_integs.push_back(update_U);
148 
149  update_U->set_parameters(m_Nprec);
150 
151  Integrator *integrator = update_U;
152 
153  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
155  m_integs.push_back(update_p);
156 
157  // append notify client
158  update_U->append_notify(update_p);
159 
160  Integrator_Leapfrog *integ = new Integrator_Leapfrog(update_p, integrator);
161  m_integs.push_back(integ);
162 
163  integ->set_parameters(lv, m_Nstep[lv]);
164 
165  // forward to upper level integrator
166  integrator = integ;
167  }
168 
169  return integrator;
170 }
171 
172 
173 //====================================================================
175 {
176  // ##### Following setup is for PUP order.
177 
178  // lowest level: update_U
180 
181  m_integs.push_back(update_U);
182 
183  update_U->set_parameters(m_Nprec);
184 
185  Integrator *integrator = update_U;
186 
187  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
189  m_integs.push_back(update_p);
190 
191  // append notify client
192  update_U->append_notify(update_p);
193 
194  Integrator_Omelyan *integ = new Integrator_Omelyan(update_p, integrator);
195  m_integs.push_back(integ);
196 
197  integ->set_parameters(lv, m_Nstep[lv], m_lambda_Omelyan);
198 
199  // forward to upper level integrator
200  integrator = integ;
201  }
202 
203  return integrator;
204 }
205 
206 
207 //====================================================================
209 {
210  for (size_t i = 0, n = m_integs.size(); i < n; ++i) {
211  if (m_integs[i]) delete m_integs[i];
212  }
213 
214  m_integs.resize(0);
215 }
216 
217 
218 //====================================================================
219 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:495
Integrator * build_leapfrog()
Standard leapfrog integrator to compose MD integrator.
std::vector< int > m_Nstep
Number of steps at each level.
void set_parameters(const Parameters &params)
void general(const char *format,...)
Definition: bridgeIO.cpp:195
Bridge::VerboseLevel m_vl
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:211
void set_parameters(const Parameters &params)
void set_parameters(const Parameters &params)
std::vector< Director * > m_director
Class for parameters.
Definition: parameters.h:46
int m_Nprec
precision parameter of exponentiation
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:262
void append_notify(Integrator *const integ)
Base class of Integrator class family.
Definition: integrator.h:29
Integrator of conjugate momenta for given link variables.
ActionSet get_actions() const
Definition: action_list.cpp:80
void set_parameters(const Parameters &params)
Omelyan integrator to compose MD integrator.
Builder_Integrator(const ActionList &action_list, std::vector< Director * > director=std::vector< Director * >())
constructor with ActionList
std::string m_str_integrator_type
static const std::string class_name
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:230
std::vector< Integrator * > m_integs
Integrator to be constructed.
Integrator * build_omelyan()
Common parameter class: provides parameters as singleton.
int non_NULL(const std::string v)
Definition: checker.cpp:61
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
lists of actions at respective integrator levels.
Definition: action_list.h:40
int non_zero(const double v)
Definition: checker.cpp:31
std::string get_integrator_type(const int level) const
string get_string(const string &key) const
Definition: parameters.cpp:116
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:294
Integrator of link variable for a given conjugate momenta.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131