MADNESS  version 0.9
extra.h
Go to the documentation of this file.
1 #ifndef EXTRA_H
2 #define EXTRA_H
3 #include "wavef.h"
4 
6  static const int MAXNATOM=99;
7 
8  // IF YOU ADD A NEW PARAMETER DON'T FORGET TO INCLUDE IT IN
9  // a) read()
10  // b) serialize()
11  // c) operator<<()
12 
13  double L; // Box size for the simulation
14  double Lsmall; // Box size for small (near nucleus) plots
15  double Llarge; // Box size for large (far from nucleus) plots
16  double F; // Laser field strength
17  double omega; // Laser frequency
18  double ncycle; // Number of laser cycles in envelope
19  int natom; // Number of atoms
20  double Z[MAXNATOM]; // Nuclear charge of atoms
21  double R[MAXNATOM][3]; // Coordinates of atoms
22  int k; // wavelet order
23  double thresh; // precision for truncating wave function
24  double safety; // additional precision (thresh*safety) for operators and potential
25  double cut; // smoothing parameter for 1/r (same for all atoms for now)
26  std::string iState ; // initial state = "1s" or "2s"
27  std::string prefix; // Prefix for filenames
28  int ndump; // dump wave function to disk every ndump steps
29  int nplot; // dump opendx plot to disk every nplot steps
30  int nprint; // print stats every nprint steps
31  int nloadbal; // load balance every nloadbal steps
32  int nio; // Number of IO nodes
33  double tScale; // Scaling parameter for optimization
34  double target_time; // Target end-time for the simulation
35 
36  void read(const char* filename) {
37  std::ifstream f(filename);
38  std::string tag;
39  iState = "1s";
40  printf("\n");
41  printf(" Simulation parameters\n");
42  printf(" ---------------------\n");
43  while(f >> tag) {
44  if (tag[0] == '#') {
45  char ch;
46  printf(" comment %s ",tag.c_str());
47  while (f.get(ch)) {
48  printf("%c",ch);
49  if (ch == '\n') break;
50  }
51  }
52  else if (tag == "L") {
53  f >> L;
54  printf(" L = %.1f\n", L);
55  }
56  else if (tag == "Lsmall") {
57  f >> Lsmall;
58  printf(" Lsmall = %.1f\n", Lsmall);
59  }
60  else if (tag == "Llarge") {
61  f >> Llarge;
62  printf(" Llarge = %.1f\n", Llarge);
63  }
64  else if (tag == "F") {
65  f >> F;
66  printf(" F = %.6f\n", F);
67  }
68  else if (tag == "omega") {
69  f >> omega;
70  printf(" omega = %.6f\n", omega);
71  }
72  else if (tag == "ncycle") {
73  f >> ncycle;
74  printf(" ncycle = %.6f\n", ncycle);
75  }
76  else if (tag == "natom") {
77  f >> natom;
78  printf(" natom = %d\n", natom);
79  for (int i=0; i<natom; i++) {
80  f >> Z[i] >> R[i][0] >> R[i][1] >> R[i][2];
81  printf(" atom %2d %.1f %10.6f %10.6f %10.6f\n", i, Z[i], R[i][0], R[i][1], R[i][2]);
82  }
83  }
84  else if (tag == "k") {
85  f >> k;
86  printf(" k = %d\n", k);
87  }
88  else if (tag == "thresh") {
89  f >> thresh;
90  printf(" thresh = %.1e\n", thresh);
91  }
92  else if (tag == "safety") {
93  f >> safety;
94  printf(" safety = %.1e\n", safety);
95  }
96  else if (tag == "cut") {
97  f >> cut;
98  printf(" cut = %.2f\n", cut);
99  }
100  else if (tag == "iState") {
101  f >> iState;
102  printf(" iState = %s\n", iState.c_str());
103  }
104  else if (tag == "prefix") {
105  f >> prefix;
106  printf(" prefix = %s\n", prefix.c_str());
107  }
108  else if (tag == "ndump") {
109  f >> ndump;
110  printf(" ndump = %d\n", ndump);
111  }
112  else if (tag == "nplot") {
113  f >> nplot;
114  printf(" nplot = %d\n", nplot);
115  }
116  else if (tag == "nprint") {
117  f >> nprint;
118  printf(" nprint = %d\n", nprint);
119  }
120  else if (tag == "nloadbal") {
121  f >> nloadbal;
122  printf(" nloadbal = %d\n", nloadbal);
123  }
124  else if (tag == "nio") {
125  f >> nio;
126  printf(" nio = %d\n", nio);
127  }
128  else if (tag == "target_time") {
129  f >> target_time;
130  printf(" target_time = %.3f\n", target_time);
131  }
132  else if (tag == "tScale") {
133  f >> tScale;
134  printf(" tScale = %.5f\n", tScale);
135  }
136  else {
137  MADNESS_EXCEPTION("unknown input option", 0);
138  }
139  }
140  }
141 
142  template <typename Archive>
143  void serialize(Archive & ar) {
144  ar & L & Lsmall & Llarge & F & omega & ncycle & natom & Z;
145  ar & archive::wrap(&(R[0][0]), 3*MAXNATOM);
146  ar & k & thresh & safety & cut & iState & prefix & ndump & nplot & nprint & nloadbal & nio;
147  ar & target_time & tScale;
148  }
149 };
150 
151 std::ostream& operator<<(std::ostream& s, const InputParameters& p);
152 
153 struct WF {
156  WF(const std::string& STR, const complex_functionT& FUNC)
157  : str(STR)
158  , func(FUNC)
159  {
160  func.truncate();
161  }
162 };
163 
164 
165 const char* wave_function_filename(int step);
166 bool wave_function_exists(World& world, int step);
167 void wave_function_store(World& world, int step, const complex_functionT& psi);
168 complex_functionT wave_function_load(World& world, int step);
169 
170 // This controls the distribution of data across the machine
171 class LevelPmap : public WorldDCPmapInterface< Key<3> > {
172 private:
173  const int nproc;
174 public:
175  LevelPmap() : nproc(0) {};
176 
177  LevelPmap(World& world) : nproc(world.nproc()) {}
178 
179  // Find the owner of a given key
180  ProcessID owner(const Key<3>& key) const {
181  Level n = key.level();
182  if (n == 0) return 0;
183  hashT hash;
184 
185  // This randomly hashes levels 0-2 and then
186  // hashes nodes by their grand-parent key so as
187  // to increase locality separately on each level.
188  //if (n <= 2) hash = key.hash();
189  //else hash = key.parent(2).hash();
190 
191  // This randomly hashes levels 0-3 and then
192  // maps nodes on even levels to the same
193  // random node as their parent.
194  // if (n <= 3 || (n&0x1)) hash = key.hash();
195  // else hash = key.parent().hash();
196 
197  // This randomly hashes each key
198  hash = key.hash();
199 
200  return hash%nproc;
201  }
202 };
203 
204 
205 template<class T>
206 std::string toString( const T& a );
207 void loadDefaultBasis(World& world, std::vector<WF>& boundList, double Z);
208 void loadList(World& world, std::vector<std::string>& boundList, std::vector<std::string>& unboundList);
209 complexd zdipole( const vector3D& r);
210 void projectZdip(World& world, std::vector<WF> stateList);
211 void compare1F1(World& world, double cutoff);
212 
213 
214 complexd V(const vector3D& r);
215 double myreal(double t);
216 double myreal(const double_complex& t);
217 // Given psi and V evaluate the energy ... leaves psi compressed, potn reconstructed
218 template <typename T>
219 double energy(World& world, const Function<T,3>& psi, const Function<T,3>& potn);
220 void converge(World& world, complex_functionT& potn, complex_functionT& psi, double& eps);
221 void compareGroundState(World& world, double Z);
222 void printBasis(World& world, double Z, double cutoff = 10.0);
223 void belkic(World& world, double cutoff);
224 #endif
double Lsmall
Definition: extra.h:14
void printBasis(World &world, double Z, double cutoff=10.0)
Definition: extra.cc:358
ProcessID owner(const Key< 3 > &key) const
Maps key to processor.
Definition: extra.h:180
void compareGroundState(World &world, double Z)
Definition: extra.cc:313
double F
Definition: extra.h:16
std::complex< double > double_complex
Definition: lineplot.cc:16
double thresh
Definition: extra.h:23
A pmap that locates children on odd levels with their even level parents.
Definition: funcimpl.h:104
Function< T, NDIM > & truncate(double tol=0.0, bool fence=true)
Truncate the function with optional fence. Compresses with fence if not compressed.
Definition: mra.h:577
int nloadbal
Definition: extra.h:31
std::string toString(const T &a)
Definition: extra.cc:34
double Llarge
Definition: extra.h:15
std::string str
Definition: extra.h:154
complex_functionT wave_function_load(World &world, int step)
Definition: extra.cc:27
double safety
Definition: extra.h:24
void converge(World &world, complex_functionT &potn, complex_functionT &psi, double &eps)
Definition: extra.cc:291
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap dynamically allocated pointer as typed archive_array.
Definition: archive.h:820
void belkic(World &world, double cutoff)
Definition: extra.cc:446
::std::string string
Definition: gtest-port.h:872
LevelPmap(World &world)
Definition: extra.h:177
double target_time
Definition: extra.h:34
void loadList(World &world, std::vector< std::string > &boundList, std::vector< std::string > &unboundList)
Definition: extra.cc:53
const char * wave_function_filename(int step)
Definition: extra.cc:15
int k
Definition: extra.h:22
NDIM & f
Definition: mra.h:2179
double myreal(double t)
Definition: extra.cc:238
WF(const std::string &STR, const complex_functionT &FUNC)
Definition: extra.h:156
void projectZdip(World &world, std::vector< WF > stateList)
Definition: extra.cc:148
Definition: extra.h:5
complexd V(const vector3D &r)
Definition: extra.cc:257
int nprint
Definition: extra.h:30
double energy(World &world, const Function< T, 3 > &psi, const Function< T, 3 > &potn)
Definition: extra.cc:272
void loadDefaultBasis(World &world, std::vector< WF > &boundList, double Z)
Definition: extra.cc:39
double cut
Definition: extra.h:25
double Z[MAXNATOM]
Definition: extra.h:20
complex_functionT func
Definition: extra.h:155
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
double ncycle
Definition: extra.h:18
double tScale
Definition: extra.h:33
double R[MAXNATOM][3]
Definition: extra.h:21
double L
Definition: extra.h:13
double psi(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:42
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
Level level() const
Definition: key.h:220
void wave_function_store(World &world, int step, const complex_functionT &psi)
Definition: extra.cc:23
Definition: extra.h:153
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
int nplot
Definition: extra.h:29
std::size_t hashT
The hash value type.
Definition: worldhash.h:148
int nio
Definition: extra.h:32
std::string prefix
Definition: extra.h:27
int Level
Definition: key.h:58
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
void read(const char *filename)
Definition: extra.h:36
int ndump
Definition: extra.h:28
double_complex complexd
Definition: envelopedpulse.h:44
void serialize(Archive &ar)
Definition: extra.h:143
hashT hash() const
Definition: key.h:209
std::ostream & operator<<(std::ostream &s, const InputParameters &p)
Definition: extra.cc:4
int natom
Definition: extra.h:19
bool wave_function_exists(World &world, int step)
Definition: extra.cc:20
Interface to be provided by any process map.
Definition: worlddc.h:64
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
void compare1F1(World &world, double cutoff)
Definition: extra.cc:171
std::string iState
Definition: extra.h:26
LevelPmap()
Definition: extra.h:175
complexd zdipole(const vector3D &r)
Definition: extra.cc:140
double omega
Definition: extra.h:17
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
static const int MAXNATOM
Definition: extra.h:6