Bridge++  Ver. 2.0.2
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 const std::string Builder_Integrator::class_name = "Builder_Integrator";
22 
23 //====================================================================
24 Builder_Integrator::Builder_Integrator(const ActionList& action_list, std::vector<Director *> director)
25  : m_vl(CommonParameters::Vlevel()),
26  m_Nprec(0),
27  m_lambda_Omelyan(0.0),
28  m_str_integrator_type(""),
29  m_actions(action_list),
30  m_director(director)
31 {
33 
34  m_Nprec = 0;
35  m_lambda_Omelyan = 0.0;
36 }
37 
38 
39 //====================================================================
41  std::vector<Director *> director,
42  const Parameters& params)
43  : m_vl(CommonParameters::Vlevel()),
44  m_Nprec(0),
45  m_lambda_Omelyan(0.0),
46  m_str_integrator_type(""),
47  m_actions(action_list),
48  m_director(director)
49 {
51 
52  m_Nprec = 0;
53  m_lambda_Omelyan = 0.0;
54 
55  set_parameters(params);
56 }
57 
58 
59 //====================================================================
61  const Parameters& params)
62  : m_vl(CommonParameters::Vlevel()),
63  m_Nprec(0),
64  m_lambda_Omelyan(0.0),
65  m_str_integrator_type(""),
66  m_actions(action_list),
67  m_director()
68 {
70 
71  m_Nprec = 0;
72  m_lambda_Omelyan = 0.0;
73 
74  set_parameters(params);
75 }
76 
77 
78 //====================================================================
80 {
81  std::string vlevel;
82  if (!params.fetch_string("verbose_level", vlevel)) {
83  m_vl = vout.set_verbose_level(vlevel);
84  }
85 
86  //- fetch and check input parameters
87  std::string str_integrator_type;
88 
89  std::vector<int> Nstep;
90 
91  int Nprec;
92  double lambda_Omelyan;
93 
94  int err = 0;
95 
96  if (m_str_integrator_type == "") {
97  err += params.fetch_string("integrator", str_integrator_type);
98  } else {
99  str_integrator_type = m_str_integrator_type;
100  }
101 
102  err += params.fetch_int_vector("number_of_steps", Nstep);
103 
104  err += params.fetch_int("order_of_exp_iP", Nprec);
105 
106  if ((m_str_integrator_type == "") || (m_str_integrator_type == "Omelyan")) {
107  err += params.fetch_double("lambda_Omelyan", lambda_Omelyan);
108  } else {
109  lambda_Omelyan = 0.0;
110  }
111 
112  if (err) {
113  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
114  exit(EXIT_FAILURE);
115  }
116 
117 
118  set_parameters(str_integrator_type, Nstep, Nprec, lambda_Omelyan);
119 }
120 
121 
122 //====================================================================
124 {
125  params.set_string("integrator", m_str_integrator_type);
126  params.set_int_vector("number_of_steps", m_Nstep);
127  params.set_int("order_of_exp_iP", m_Nprec);
128 
129  if ((m_str_integrator_type == "") || (m_str_integrator_type == "Omelyan")) {
130  params.set_double("lambda_Omelyan", m_lambda_Omelyan);
131  }
132 
133  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
134 }
135 
136 
137 //====================================================================
138 void Builder_Integrator::set_parameters(const std::string str_integrator_type,
139  const std::vector<int>& Nstep,
140  const int Nprec,
141  const double lambda_Omelyan)
142 {
143  //- print input parameters
144  vout.general(m_vl, "%s:\n", class_name.c_str());
145  vout.general(m_vl, " Integrator = %s\n", str_integrator_type.c_str());
146  for (int lv = 0; lv < Nstep.size(); ++lv) {
147  vout.general(m_vl, " level = %2d: Nstep = %4d\n", lv, Nstep[lv]);
148  }
149  vout.general(m_vl, " Nprec = %4d\n", Nprec);
150 
151  //- range check
152  int err = 0;
153  err += ParameterCheck::non_NULL(str_integrator_type);
154  // NB. Nstep == 0 is allowed.
155  err += ParameterCheck::non_zero(Nprec);
156  // NB. lambda_Omelyan == 0 is allowed.
157 
158  if (err) {
159  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
160  exit(EXIT_FAILURE);
161  }
162 
163  //- store values
164  m_str_integrator_type = str_integrator_type;
165 
166  m_Nstep = Nstep;
167 
168  m_Nprec = Nprec;
169  m_lambda_Omelyan = lambda_Omelyan;
170 }
171 
172 
173 //====================================================================
175 {
176  //- select leapfrog or omelyan
177  Integrator *integrator;
178 
179  if (m_str_integrator_type == "Leapfrog") {
180  integrator = build_leapfrog();
181  } else if (m_str_integrator_type == "Omelyan") {
182  integrator = build_omelyan();
183  } else {
184  vout.crucial("Error at %s::build : unsupported integrator type \"%s\".\n", class_name.c_str(), m_str_integrator_type.c_str());
185  exit(EXIT_FAILURE);
186  }
187 
188  return integrator;
189 }
190 
191 
192 //====================================================================
194 {
195  // ##### Following setup is for PUP order.
196 
197  // lowest level: update_U
199 
200  m_integs.push_back(update_U);
201 
202  update_U->set_parameters(m_Nprec);
203 
204  Integrator *integrator = update_U;
205 
206  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
208  m_integs.push_back(update_p);
209 
210  // append notify client
211  update_U->append_notify(update_p);
212 
213  Integrator_Leapfrog *integ = new Integrator_Leapfrog(update_p, integrator);
214  m_integs.push_back(integ);
215 
216  integ->set_parameters(lv, m_Nstep[lv]);
217 
218  // forward to upper level integrator
219  integrator = integ;
220  }
221 
222  return integrator;
223 }
224 
225 
226 //====================================================================
228 {
229  // ##### Following setup is for PUP order.
230 
231  // lowest level: update_U
233 
234  m_integs.push_back(update_U);
235 
236  update_U->set_parameters(m_Nprec);
237 
238  Integrator *integrator = update_U;
239 
240  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
242  m_integs.push_back(update_p);
243 
244  // append notify client
245  update_U->append_notify(update_p);
246 
247  Integrator_Omelyan *integ = new Integrator_Omelyan(update_p, integrator);
248  m_integs.push_back(integ);
249 
250  integ->set_parameters(lv, m_Nstep[lv], m_lambda_Omelyan);
251 
252  // forward to upper level integrator
253  integrator = integ;
254  }
255 
256  return integrator;
257 }
258 
259 
260 //====================================================================
262 {
263  for (size_t i = 0, n = m_integs.size(); i < n; ++i) {
264  if (m_integs[i]) delete m_integs[i];
265  }
266 
267  m_integs.resize(0);
268 }
269 
270 
271 //====================================================================
272 //============================================================END=====
Builder_Integrator::m_integs
std::vector< Integrator * > m_integs
Integrator to be constructed.
Definition: builder_Integrator.h:59
Builder_Integrator::m_lambda_Omelyan
double m_lambda_Omelyan
Definition: builder_Integrator.h:51
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
Integrator_Leapfrog::set_parameters
void set_parameters(const Parameters &params)
Definition: integrator_Leapfrog.cpp:19
CommonParameters
Common parameter class: provides parameters as singleton.
Definition: commonParameters.h:42
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Builder_Integrator::m_actions
ActionList m_actions
Definition: builder_Integrator.h:55
integrator_UpdateP.h
Integrator_UpdateP
Integrator of conjugate momenta for given link variables.
Definition: integrator_UpdateP.h:37
ActionList::get_integrator_type
std::string get_integrator_type(const int level) const
Definition: action_list.cpp:104
builder_Integrator.h
ActionList
lists of actions at respective integrator levels.
Definition: action_list.h:40
Builder_Integrator::m_Nprec
int m_Nprec
precision parameter of exponentiation
Definition: builder_Integrator.h:50
Integrator_Omelyan::set_parameters
void set_parameters(const Parameters &params)
Definition: integrator_Omelyan.cpp:19
Integrator_UpdateU::append_notify
void append_notify(Integrator *const integ)
Definition: integrator_UpdateU.h:71
Parameters::fetch_int_vector
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
Builder_Integrator::m_Nstep
std::vector< int > m_Nstep
Number of steps at each level.
Definition: builder_Integrator.h:48
Builder_Integrator::set_parameters
void set_parameters(const Parameters &params)
Definition: builder_Integrator.cpp:79
Integrator_UpdateU
Integrator of link variable for a given conjugate momenta.
Definition: integrator_UpdateU.h:34
Builder_Integrator::m_director
std::vector< Director * > m_director
Definition: builder_Integrator.h:56
Builder_Integrator::class_name
static const std::string class_name
Definition: builder_Integrator.h:42
Integrator_Leapfrog
Standard leapfrog integrator to compose MD integrator.
Definition: integrator_Leapfrog.h:31
integrator_Leapfrog.h
Integrator_Omelyan
Omelyan integrator to compose MD integrator.
Definition: integrator_Omelyan.h:31
Parameters::set_int_vector
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
Builder_Integrator::build
Integrator * build()
Definition: builder_Integrator.cpp:174
Builder_Integrator::m_vl
Bridge::VerboseLevel m_vl
Definition: builder_Integrator.h:45
Builder_Integrator::get_parameters
void get_parameters(Parameters &params) const
Definition: builder_Integrator.cpp:123
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Builder_Integrator::build_leapfrog
Integrator * build_leapfrog()
Definition: builder_Integrator.cpp:193
ParameterCheck::non_zero
int non_zero(const double v)
Definition: parameterCheck.cpp:32
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
ActionList::get_actions
ActionSet get_actions() const
Definition: action_list.cpp:82
Builder_Integrator::tidyup
void tidyup()
Definition: builder_Integrator.cpp:261
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
integrator_UpdateU.h
Builder_Integrator::build_omelyan
Integrator * build_omelyan()
Definition: builder_Integrator.cpp:227
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Integrator
Base class of Integrator class family.
Definition: integrator.h:29
integrator_Omelyan.h
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Integrator_UpdateU::set_parameters
void set_parameters(const Parameters &params)
Definition: integrator_UpdateU.cpp:19
Builder_Integrator::m_str_integrator_type
std::string m_str_integrator_type
Definition: builder_Integrator.h:53
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154
Builder_Integrator::Builder_Integrator
Builder_Integrator(const ActionList &action_list, std::vector< Director * > director=std::vector< Director * >())
constructor with ActionList
Definition: builder_Integrator.cpp:24