QMCPACK
SkParserHDF5.cpp
Go to the documentation of this file.
1 #include "SkParserHDF5.h"
3 #include <cmath>
4 
5 namespace qmcplusplus
6 {
7 void SkParserHDF5::parse(const std::string& fname)
8 {
9  bool result = statfile.open(fname);
10  if (!result)
11  {
12  std::cout << "SkParserHDF5::parse could not open " << fname << std::endl;
13  exit(1);
14  }
15 
16  //read the kpoints
17  std::vector<int> readShape;
18  statfile.getShape<int>(skname + "/kpoints/value", readShape);
19  assert(readShape[1] == 3);
20  std::array<int, 2> kdims{readShape[0], readShape[1]};
21  std::vector<RealType> ktmp;
22  statfile.readSlabReshaped(ktmp, kdims, skname + "/kpoints/value");
23  for (int ik = 0; ik < readShape[0]; ik++)
24  {
25  PosType k;
26  k[0] = ktmp[3 * ik];
27  k[1] = ktmp[3 * ik + 1];
28  k[2] = ktmp[3 * ik + 2];
29  kgridraw.push_back(k);
30  }
31  int nKpts = kgridraw.size();
32 
33  //read the <rho_-k*rho_k> term
34  statfile.getShape<int>(skname + "/rhok_e_e/value", readShape);
35  assert(readShape[1] == nKpts);
36  std::vector<RealType> rhok_e_tmp;
37  std::array<int, 2> rhok_e_dims{readShape[0], readShape[1]};
38  statfile.readSlabReshaped(rhok_e_tmp, rhok_e_dims, skname + "/rhok_e_e/value");
39  int nBlocks = readShape[0];
40 
41  //read the Im(rho_k) term
42  statfile.getShape<int>(skname + "/rhok_e_i/value", readShape);
43  std::vector<RealType> rhok_i_tmp;
44  std::array<int, 2> rhok_i_dims{readShape[0], readShape[1]};
45  statfile.readSlabReshaped(rhok_i_tmp, rhok_i_dims, skname + "/rhok_e_i/value");
46  assert(readShape[0] == nBlocks);
47  assert(readShape[1] == nKpts);
48 
49  //read the Re(rho_k)
50  statfile.getShape<int>(skname + "/rhok_e_r/value", readShape);
51  std::vector<RealType> rhok_r_tmp;
52  std::array<int, 2> rhok_r_dims{readShape[0], readShape[1]};
53  statfile.readSlabReshaped(rhok_r_tmp, rhok_r_dims, skname + "/rhok_e_r/value");
54  assert(readShape[0] == nBlocks);
55  assert(readShape[1] == nKpts);
56 
57  //For each k, evaluate the flucuating S(k) for all blocks.
58  //Then perform a simple equilibration estimate for this particular S(k) value
59  //Store the average and error after throwing out the equilibration
60  for (int ik = 0; ik < nKpts; ik++)
61  {
62  std::vector<RealType> block_data;
63  for (int ib = 0; ib < nBlocks; ib++)
64  {
65  RealType re, rr, ri;
66  re = rhok_e_tmp[nKpts * ib + ik];
67  rr = rhok_r_tmp[nKpts * ib + ik];
68  ri = rhok_i_tmp[nKpts * ib + ik];
69  block_data.push_back(re - (rr * rr + ri * ri));
70  }
71  int ieq = estimateEquilibration(block_data);
72  RealType avg, err;
73  getStats(block_data, avg, err, ieq);
74  skraw.push_back(avg);
75  skerr_raw.push_back(err);
76  }
77 
78  hasGrid = false;
79  isNormalized = false;
80  isParseSuccess = true;
81 
82  statfile.close();
83 }
84 
85 } // namespace qmcplusplus
std::vector< RealType > skerr_raw
Definition: SkParserBase.h:60
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
std::vector< PosType > kgridraw
Definition: SkParserBase.h:61
std::vector< RealType > skraw
Definition: SkParserBase.h:59
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
void readSlabReshaped(T &data, const std::array< IT, RANK > &shape, const std::string &aname)
read file dataset with a specific shape into a container and check status
Definition: hdf_archive.h:321
bool getShape(const std::string &aname, std::vector< int > &sizes_out)
read the shape of multidimensional filespace from the group aname this function can be used to query ...
Definition: hdf_archive.h:231
void getStats(const std::vector< RealType > &vals, RealType &avg, RealType &err, int start)
Simpleaverage and error estimate.
Definition: FSUtilities.cpp:31
int estimateEquilibration(const std::vector< RealType > &vals, RealType frac)
estimate equilibration of block data
Definition: FSUtilities.cpp:50
void parse(const std::string &fname) override
Definition: SkParserHDF5.cpp:7