ERKALE
ERKALE - DFT from Hel
 All Classes Functions Variables Friends Pages
checkpoint.h
1 /*
2  * This source code is part of
3  *
4  * E R K A L E
5  * -
6  * HF/DFT from Hel
7  *
8  * Written by Susi Lehtola, 2010-2011
9  * Copyright (c) 2010-2011, Susi Lehtola
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  */
16 
17 #ifndef ERKALE_CHECKPOINT
18 #define ERKALE_CHECKPOINT
19 
20 #include "global.h"
21 class BasisSet;
22 #include "scf.h"
23 
24 #include <armadillo>
25 #include <string>
26 
27 // Use C routines, since C++ routines don't seem to add any ease of use.
28 extern "C" {
29 #include <hdf5.h>
30 }
31 
33 #define ERKALE_CHKVER 2
34 
36 typedef struct {
38  int am;
40  hbool_t uselm;
42  hsize_t cenind;
44  hsize_t indstart;
45 } shell_data_t;
46 
48 #define SYMLEN 10
49 
51 typedef struct {
53  hsize_t ind;
55  double rx;
57  double ry;
59  double rz;
61  hbool_t bsse;
63  int Z;
65  char sym[SYMLEN];
66 } nuc_t;
67 
69 class Checkpoint {
71  std::string filename;
73  bool writemode;
74 
76  bool opend;
78  hid_t file;
79 
80  // *** Helper functions ***
81 
83  void write(const std::string & name, hbool_t val);
85  void read(const std::string & name, hbool_t & val);
86 
87  public:
89  Checkpoint(const std::string & filename, bool write, bool trunc=true);
91  ~Checkpoint();
92 
94  void open();
96  void close();
98  void flush();
99 
101  bool is_open() const;
103  bool exist(const std::string & name);
104 
105 
112  void remove(const std::string & name);
113 
120  void write(const std::string & name, const arma::mat & mat);
123  void read(const std::string & name, arma::mat & mat);
124 
126  void cwrite(const std::string & name, const arma::cx_mat & mat);
128  void cread(const std::string & name, arma::cx_mat & mat);
129 
131  void write(const std::string & name, const std::vector<double> & v);
133  void read(const std::string & name, std::vector<double> & v);
134 
136  void write(const std::string & name, const std::vector<hsize_t> & v);
138  void read(const std::string & name, std::vector<hsize_t> & v);
139 
141  void write(const BasisSet & basis);
143  void read(BasisSet & basis);
144 
146  void write(const energy_t & en);
148  void read(energy_t & en);
149 
151  void write(const std::string & name, double val);
153  void read(const std::string & name, double & val);
154 
156  void write(const std::string & name, int val);
158  void read(const std::string & name, int & val);
159 
161  void write(const std::string & name, hsize_t val);
163  void read(const std::string & name, hsize_t & val);
164 
166  void write(const std::string & name, bool val);
168  void read(const std::string & name, bool & val);
169 
171  void write(const std::string & name, const std::string & val);
173  void read(const std::string & name, std::string & val);
174 };
175 
177 bool file_exists(const std::string & name);
178 
180 std::string get_cwd();
182 void change_dir(std::string dir, bool create=false);
183 
185 std::string tempname();
186 
187 #endif
hid_t file
The checkpoint file.
Definition: checkpoint.h:78
hsize_t ind
Index of nucleus.
Definition: checkpoint.h:53
void flush()
Flush the data.
Definition: checkpoint.cpp:91
hsize_t cenind
Index of center.
Definition: checkpoint.h:42
void read(const std::string &name, hbool_t &val)
Read value.
Definition: checkpoint.cpp:1053
bool exist(const std::string &name)
Does the entry exist in the file?
Definition: checkpoint.cpp:100
void write(const std::string &name, hbool_t val)
Save value.
Definition: checkpoint.cpp:1016
void close()
Close the file.
Definition: checkpoint.cpp:83
void cread(const std::string &name, arma::cx_mat &mat)
Read complex matrix.
Definition: checkpoint.cpp:230
Energy info.
Definition: scf.h:83
hsize_t indstart
First function on shell.
Definition: checkpoint.h:44
int Z
Charge.
Definition: checkpoint.h:63
Fixed-length data for shell.
Definition: checkpoint.h:36
void open()
Open the file.
Definition: checkpoint.cpp:63
void cwrite(const std::string &name, const arma::cx_mat &mat)
Save complex matrix.
Definition: checkpoint.cpp:222
hbool_t uselm
Are spherical harmonics used?
Definition: checkpoint.h:40
bool writemode
Is file open for writing?
Definition: checkpoint.h:73
double ry
y coordinate
Definition: checkpoint.h:57
double rz
z coordinate
Definition: checkpoint.h:59
bool is_open() const
Is the file open?
Definition: checkpoint.cpp:96
double rx
x coordinate
Definition: checkpoint.h:55
Checkpoint(const std::string &filename, bool write, bool trunc=true)
Create checkpoint file.
Definition: checkpoint.cpp:25
Basis set.
Definition: basis.h:187
~Checkpoint()
Destructor.
Definition: checkpoint.cpp:58
Nucleus type.
Definition: checkpoint.h:51
hbool_t bsse
Counterpoise?
Definition: checkpoint.h:61
bool opend
Is the file open.
Definition: checkpoint.h:76
int am
Angular momentum of shell.
Definition: checkpoint.h:38
std::string filename
Name of the file.
Definition: checkpoint.h:71
Checkpointing class.
Definition: checkpoint.h:69