Path Integral Quantum Monte Carlo
constants.cpp
Go to the documentation of this file.
1 
8 #include "constants.h"
9 #include <time.h>
10 
11 // ---------------------------------------------------------------------------
12 // ---------------------------------------------------------------------------
13 // CONSTANT PARAMETERS CLASS ------------------------------------------------
14 // ---------------------------------------------------------------------------
15 // ---------------------------------------------------------------------------
16 
17 /**************************************************************************/
21 {
22  /* empty constructor */
23 }
24 
25 /**************************************************************************/
32 void ConstantParameters::initConstants(po::variables_map &params) {
33 
34  /* We use boost to generate a UUID for the simulation */
35  if (params["restart"].empty()) {
36 
37  id_ = boost::uuids::to_string(boost::uuids::random_generator()());
38 
39  /* Add a possible user specified label */
40  string label_ = params["label"].as<string>();
41  if (label_.length() > 12)
42  label_ = label_.substr(0,12);
43 
44  id_.replace(id_.end()-label_.length(),id_.end(),label_);
45  restart_ = false;
46  }
47  else {
48  id_ = params["restart"].as<string>();
49  restart_ = true;
50  }
51 
52  /* Are we starting from a supplied state file? */
53  startWithState_ = !params["start_with_state"].as<string>().empty();
54 
55  /* Set the wall clock state */
56  if (params["wall_clock"].empty()) {
57  wallClockOn_ = false;
58  wallClock_ = 0;
59  }
60  else {
61  wallClockOn_ = true;
62  /* Set wallClock_ in seconds*/
63  wallClock_ = uint32( floor(params["wall_clock"].as<double>()*3600));
64  }
65 
66  /* Are we working in the grand canonical ensemble? */
67  canonical_ = !params["canonical"].empty();
68 
69  /* Are we saving a state file every bin? */
70  saveStateFiles_ = params["no_save_state"].empty();
71 
72  /* Do we want variable length diagonal updates? */
73  varUpdates_ = params["var_updates"].empty();
74 
75  /* Set the particle number window */
76  window_ = canonical_ && !params["window"].empty();
77  if (window_)
78  windowWidth_ = params["window"].as<int>();
79  else
80  windowWidth_ = 0;
81 
82  /* Set the ensemble weight */
83  gaussianEnsemble_ = canonical_ && !params["gaussian_window_width"].empty();
84  if (gaussianEnsemble_)
85  gaussianEnsembleSD_ = params["gaussian_window_width"].as<double>();
86  else
87  gaussianEnsembleSD_ = 0.0;
88 
89  /* The maximum winding number sampled */
90  maxWind_ = params["max_winding"].as<int>();
91 
92  /* Assigned values */
93  b_ = int (ceil(log(1.0*params["update_length"].as<int>()) / log(2.0)-EPS));
94 
95  /* We need to make sure b_ < numTimeSlices */
96  while (ipow(2,b_) >= params["number_time_slices"].as<int>())
97  b_--;
98 
99  /* Assigned values */
100  Mbar_ = params["update_length"].as<int>();
101  T_ = params["temperature"].as<double>();
102  imagTimeLength_ = params["imaginary_time_length"].as<double>();
103  mu_ = params["chemical_potential"].as<double>();
104  m_ = params["mass"].as<double>();
105  lambda_ = 24.24 / m_;
106  rc_ = params["potential_cutoff"].as<double>();
107  rc2_ = rc_*rc_;
108  C0_ = params["worm_constant"].as<double>();
109  numTimeSlices_ = params["number_time_slices"].as<int>();
110  if (PIGS)
111  tau_ = 1.0/((numTimeSlices_-1)*T_);
112  else
113  tau_ = 1.0/(numTimeSlices_*T_);
114  V_ = params["volume"].as<double>();
115  L_ = params["side"].as<dVec>()[NDIM-1];
116  numEqSteps_ = params["number_eq_steps"].as<uint32>();
117 
118  graphenelut3d_file_prefix_ = params["graphenelut3d_file_prefix"].as<string>();
119  virialWindow_ = params["virial_window"].as<int>();
120 
121  initialNumParticles_ = params["number_particles"].as<int>();
122  numBroken_ = params["number_broken"].as<int>();
123 
124  spatialSubregionOn_ = !params["spatial_subregion"].empty();
125  if (spatialSubregionOn_)
126  spatialSubregion_ = params["spatial_subregion"].as<double>();
127 
128  endFactor_ = params["end_factor"].as<double>();
129  Npaths_ = params["number_paths"].as<int>();
130 
131  intPotentialType_ = params["interaction"].as<string>();
132  extPotentialType_ = params["external"].as<string>();
133  waveFunctionType_ = params["wavefunction"].as<string>();
134  actionType_ = params["action"].as<string>();
135 
136  /* Computed values */
137  dBWavelength_ = 2.0*sqrt(M_PI * lambda_ / T_);
138  comDelta_ = 0.04*dBWavelength_;
139  displaceDelta_ = 0.04*dBWavelength_;
140  getC();
141 
142  /* Set the move probabilities */
143 
144  /* At present, the pigs code has only diagonal moves */
145  if (PIGS) {
146  attemptProb_["open"] = 0.0;
147  attemptProb_["insert"] = 0.0;
148  attemptProb_["close"] = 0.0;
149  attemptProb_["advance head"] = 0.0;
150  attemptProb_["recede head"] = 0.0;
151  attemptProb_["advance tail"] = 0.0;
152  attemptProb_["recede tail"] = 0.0;
153  attemptProb_["remove"] = 0.0;
154  attemptProb_["swap head"] = 0.0;
155  attemptProb_["swap tail"] = 0.0;
156  attemptProb_["diagonal"] = 0.6;
157  attemptProb_["center of mass"] = 0.1;
158  attemptProb_["displace"] = 0.0;
159  attemptProb_["end staging"] = 0.3;
160  attemptProb_["mid staging"] = 0.0;
161  attemptProb_["swap break"] = 0.0;
162  }
163  else {
164  attemptProb_["open"] = 0.4;
165  attemptProb_["insert"] = 0.4;
166  attemptProb_["close"] = 0.15;
167  attemptProb_["advance head"] = 0.075;
168  attemptProb_["recede head"] = 0.075;
169  attemptProb_["advance tail"] = 0.075;
170  attemptProb_["recede tail"] = 0.075;
171  attemptProb_["remove"] = 0.15;
172  attemptProb_["swap head"] = 0.10;
173  attemptProb_["swap tail"] = 0.10;
174  attemptProb_["diagonal"] = 0.19;
175  attemptProb_["center of mass"] = 0.01;
176  attemptProb_["displace"] = 0.0;
177  attemptProb_["end staging"] = 0.0;
178  attemptProb_["swap break"] = 0.0;
179  attemptProb_["mid staging"] = 0.0;
180  }
181 
182  double totProb = attemptProb_["close"] + attemptProb_["advance head"] + attemptProb_["recede head"]
183  + attemptProb_["advance tail"] + attemptProb_["recede tail"] + attemptProb_["remove"]
184  + attemptProb_["swap head"] + attemptProb_["swap tail"] + attemptProb_["diagonal"]
185  + attemptProb_["center of mass"] + attemptProb_["displace"] + attemptProb_["end staging"]
186  + attemptProb_["mid staging"]+attemptProb_["swap break"];
187 
188  if (abs(totProb - 1.0) > EPS) {
189  cout << "Close + AdvanceHead + RecedeHead + AdvanceTail + RecedeTail + Remove + SwapHead "
190  << "+ SwapTail + Diagonal + CoM Probability != 1" << endl;
191  cout << totProb << endl;
192  exit(EXIT_FAILURE);
193  }
194  PIMC_ASSERT(totProb-1.0 < EPS);
195 
196  totProb = attemptProb_["open"] + attemptProb_["insert"] + attemptProb_["diagonal"]
197  + attemptProb_["center of mass"] + attemptProb_["displace"] + attemptProb_["swap break"]
198  + attemptProb_["end staging"] + attemptProb_["mid staging"];
199 
200  if (abs(totProb - 1.0) > EPS) {
201  cout << "Open + Insert + Diagonal + CoM Probability != 1" << endl;
202  cout << totProb << endl;
203  exit(EXIT_FAILURE);
204  }
205  PIMC_ASSERT(totProb-1.0 < EPS);
206 }
207 
208 /**************************************************************************/
213 {
214  static ConstantParameters inst;
215  return &inst;
216 }
Constant simulation parameters.
Definition: constants.h:34
ConstantParameters()
An empty constructor which simply sets all constants to null.
Definition: constants.cpp:20
static ConstantParameters * getInstance()
This public method returns an instance of the constant object, Only one can ever exist at a time.
Definition: constants.cpp:212
void initConstants(po::variables_map &)
Initialize all constants from command line, XMl and defaults.
Definition: constants.cpp:32
void getC()
Get the value of the worm constant.
Definition: constants.h:128
#define NDIM
Number of spatial dimnsions.
Definition: common.h:71
int ipow(int base, int power)
Return the integer value of a number raised to a power.
Definition: common.h:136
unsigned long uint32
Unsigned integer type, at least 32 bits.
Definition: common.h:105
#define EPS
A small number.
Definition: common.h:94
TinyVector< double, NDIM > dVec
A NDIM-vector of type double.
Definition: common.h:111
#define PIMC_ASSERT(X)
Rename assert method.
Definition: common.h:64
ConstantParameters class definition.