Bridge++  Version 1.5.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 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 {
42  const std::string str_vlevel = params.get_string("verbose_level");
43 
44  m_vl = vout.set_verbose_level(str_vlevel);
45 
46  //- fetch and check input parameters
47  std::string str_integrator_type;
48 
49  std::vector<int> Nstep;
50 
51  int Nprec;
52  double lambda_Omelyan;
53 
54  int err = 0;
55 
56  if (m_str_integrator_type == "") {
57  err += params.fetch_string("integrator", str_integrator_type);
58  } else {
59  str_integrator_type = m_str_integrator_type;
60  }
61 
62  err += params.fetch_int_vector("number_of_steps", Nstep);
63 
64  err += params.fetch_int("order_of_exp_iP", Nprec);
65 
66  if ((m_str_integrator_type == "") || (m_str_integrator_type == "Omelyan")) {
67  err += params.fetch_double("lambda_Omelyan", lambda_Omelyan);
68  } else {
69  lambda_Omelyan = 0.0;
70  }
71 
72  if (err) {
73  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
74  exit(EXIT_FAILURE);
75  }
76 
77 
78  set_parameters(str_integrator_type, Nstep, Nprec, lambda_Omelyan);
79 }
80 
81 
82 //====================================================================
83 void Builder_Integrator::set_parameters(const std::string str_integrator_type,
84  const std::vector<int>& Nstep,
85  const int Nprec,
86  const double lambda_Omelyan)
87 {
88  //- print input parameters
89  vout.general(m_vl, "%s:\n", class_name.c_str());
90  vout.general(m_vl, " Integrator = %s\n", str_integrator_type.c_str());
91  for (int lv = 0; lv < Nstep.size(); ++lv) {
92  vout.general(m_vl, " level = %2d: Nstep = %4d\n", lv, Nstep[lv]);
93  }
94  vout.general(m_vl, " Nprec = %4d\n", Nprec);
95 
96  //- range check
97  int err = 0;
98  err += ParameterCheck::non_NULL(str_integrator_type);
99  // NB. Nstep == 0 is allowed.
100  err += ParameterCheck::non_zero(Nprec);
101  // NB. lambda_Omelyan == 0 is allowed.
102 
103  if (err) {
104  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
105  exit(EXIT_FAILURE);
106  }
107 
108  //- store values
109  m_str_integrator_type = str_integrator_type;
110 
111  m_Nstep = Nstep;
112 
113  m_Nprec = Nprec;
114  m_lambda_Omelyan = lambda_Omelyan;
115 }
116 
117 
118 //====================================================================
120 {
121  //- select leapfrog or omelyan
122  Integrator *integrator;
123 
124  if (m_str_integrator_type == "Leapfrog") {
125  integrator = build_leapfrog();
126  } else if (m_str_integrator_type == "Omelyan") {
127  integrator = build_omelyan();
128  } else {
129  vout.crucial("Error at %s::build : unsupported integrator type \"%s\".\n", class_name.c_str(), m_str_integrator_type.c_str());
130  exit(EXIT_FAILURE);
131  }
132 
133  return integrator;
134 }
135 
136 
137 //====================================================================
139 {
140  // ##### Following setup is for PUP order.
141 
142  // lowest level: update_U
144 
145  m_integs.push_back(update_U);
146 
147  update_U->set_parameters(m_Nprec);
148 
149  Integrator *integrator = update_U;
150 
151  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
153  m_integs.push_back(update_p);
154 
155  // append notify client
156  update_U->append_notify(update_p);
157 
158  Integrator_Leapfrog *integ = new Integrator_Leapfrog(update_p, integrator);
159  m_integs.push_back(integ);
160 
161  integ->set_parameters(lv, m_Nstep[lv]);
162 
163  // forward to upper level integrator
164  integrator = integ;
165  }
166 
167  return integrator;
168 }
169 
170 
171 //====================================================================
173 {
174  // ##### Following setup is for PUP order.
175 
176  // lowest level: update_U
178 
179  m_integs.push_back(update_U);
180 
181  update_U->set_parameters(m_Nprec);
182 
183  Integrator *integrator = update_U;
184 
185  for (int lv = m_Nstep.size() - 1; lv >= 0; --lv) {
187  m_integs.push_back(update_p);
188 
189  // append notify client
190  update_U->append_notify(update_p);
191 
192  Integrator_Omelyan *integ = new Integrator_Omelyan(update_p, integrator);
193  m_integs.push_back(integ);
194 
195  integ->set_parameters(lv, m_Nstep[lv], m_lambda_Omelyan);
196 
197  // forward to upper level integrator
198  integrator = integ;
199  }
200 
201  return integrator;
202 }
203 
204 
205 //====================================================================
207 {
208  for (size_t i = 0, n = m_integs.size(); i < n; ++i) {
209  if (m_integs[i]) delete m_integs[i];
210  }
211 
212  m_integs.resize(0);
213 }
214 
215 
216 //====================================================================
217 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
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:197
Bridge::VerboseLevel m_vl
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
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:378
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:89
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:346
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)
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)
std::string get_integrator_type(const int level) const
string get_string(const string &key) const
Definition: parameters.cpp:221
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
Integrator of link variable for a given conjugate momenta.
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131