QMCPACK
PWParameterSet.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /** @file PWParameterSet.cpp
17  * @brief Utility class to handle hdf5
18  */
19 #include "PWParameterSet.h"
20 #include "Message/Communicate.h"
21 #include "Message/CommOperators.h"
22 
23 namespace qmcplusplus
24 {
27  hasSpin(true),
28  twistIndex(0),
29  numBands(0),
30  Ecut(-1),
31  Rcut(-1),
32  BufferRadius(-1),
33  BoxDup(1),
34  paramTag("parameters"),
35  basisTag("basis"),
36  pwTag("planewaves"),
37  pwMultTag("multipliers"),
38  eigTag("eigenstates"),
39  twistTag("twist"),
40  bandTag("band"),
41  spinTag("spin"),
42  eigvecTag("eigenvector")
43 {
44  m_param.setName("h5tag");
45  m_param.add(twistIndex, "twistIndex");
46  m_param.add(Rcut, "rcut");
47  m_param.add(BufferRadius, "bufferLayer");
48  m_param.add(BoxDup, "expand");
49  m_param.add(paramTag, "parameters");
50  m_param.add(basisTag, "basis");
51  m_param.add(pwTag, "planewaves");
52  m_param.add(pwMultTag, "multiplers");
53  m_param.add(eigTag, "eigenstates");
54  m_param.add(twistTag, "twist");
55  m_param.add(bandTag, "band");
56  m_param.add(spinTag, "spin");
57  m_param.add(eigvecTag, "eigenvector");
58 }
59 
60 double PWParameterSet::getEcut(double ecut)
61 {
62  if (Ecut < 0 || Ecut >= ecut)
63  Ecut = ecut;
64  return Ecut;
65 }
66 
68 {
69  int rank = 0;
70  if (is_manager())
71  {
72  std::ostringstream oss;
73  oss << "/" << eigTag << "/" << twistTag << twistIndex << "/" << bandTag << 0;
74  //if(version[1]==10)
75  if (hasSpin)
76  oss << "/" << spinTag << 0;
77  oss << "/eigenvector";
78  hsize_t dimTot[4];
79  hid_t dataset = H5Dopen(h, oss.str().c_str(), H5P_DEFAULT);
80  hid_t dataspace = H5Dget_space(dataset);
81  rank = H5Sget_simple_extent_ndims(dataspace);
82  int status_n = H5Sget_simple_extent_dims(dataspace, dimTot, NULL);
83  }
84  myComm->bcast(rank);
85  return rank == 4;
86 }
87 
89 {
90  int iscomplex = 0;
91  // Should be the tag "/electrons/psi_r_is_complex", but the test HDF files
92  // don't have this set
93 #if 0
94  if(is_manager())
95  {
96  std::ostringstream oss;
97  oss << paramTag << "/complex_coefficients";
98  h_file.read(iscomplex, oss.str());
99  }
100 #endif
101  myComm->bcast(iscomplex);
102  return iscomplex;
103 }
104 
106 {
107  std::ostringstream oss;
108  oss << eigTag << "/" << twistTag << twistIndex << "/twist_angle";
109  return oss.str();
110 }
111 
113 
115 {
116  std::ostringstream oss;
117  oss << twistTag << i;
118  return oss.str();
119 }
120 
121 std::string PWParameterSet::getBandName(int ib, int ispin)
122 {
123  std::ostringstream oss;
124  oss << "spin_" << ispin << "/"
125  << "state_" << ib;
126  return oss.str();
127 }
128 
129 std::string PWParameterSet::getEigVectorName(const std::string& hg, int ib, int ispin)
130 {
131  std::ostringstream oss;
132  oss << hg << "/" << bandTag << ib;
133  //if(version[1]==10)
134  if (hasSpin)
135  {
136  oss << "/" << spinTag << ispin;
137  }
138  oss << "/eigenvector";
139  return oss.str();
140 }
141 
142 std::string PWParameterSet::getCenterName(const std::string& hg, int ib)
143 {
144  std::ostringstream oss;
145  oss << hg << "/" << bandTag << ib << "/center";
146  return oss.str();
147 }
148 
149 std::string PWParameterSet::getOriginName(const std::string& hg, int ib)
150 {
151  std::ostringstream oss;
152  oss << hg << "/" << bandTag << ib << "/origin";
153  return oss.str();
154 }
155 
156 std::string PWParameterSet::getEigVectorName(int ib, int ispin)
157 {
158  std::ostringstream oss;
159  oss << "/" << eigTag << "/" << twistTag << twistIndex << "/" << bandTag << ib;
160  //if(version[1]==10)
161  if (hasSpin)
162  {
163  oss << "/" << spinTag << ispin;
164  }
165  oss << "/eigenvector";
166  return oss.str();
167 }
168 
169 std::string PWParameterSet::getBandName(int ib)
170 {
171  std::ostringstream oss;
172  oss << bandTag << ib;
173  return oss.str();
174 }
175 
176 std::string PWParameterSet::getSpinName(int ispin)
177 {
178  std::ostringstream oss;
179  oss << spinTag << ispin;
180  return oss.str();
181 }
182 
184 {
185  if (is_manager())
186  {
187  hid_t dataset = H5Dopen(h.getFileID(), "version", H5P_DEFAULT);
188  hid_t datatype = H5Dget_type(dataset);
189  H5T_class_t classtype = H5Tget_class(datatype);
190  H5Tclose(datatype);
191  H5Dclose(dataset);
192  if (classtype == H5T_INTEGER)
193  {
194  h.read(version, "version");
195  }
196  else if (classtype == H5T_FLOAT)
197  {
199  h.read(vt, "version");
200  version[0] = static_cast<int>(vt[0]);
201  version[1] = static_cast<int>(vt[1]);
202  }
203  else
204  {
205  APP_ABORT("PWParameterSet::checkVersion The type of version is not integer or double.");
206  }
207  }
208  myComm->bcast(version);
209  app_log() << "\tWavefunction HDF version: " << version[0] << "." << version[1] << std::endl;
210  if (version[0] == 0)
211  {
212  if (version[1] == 11)
213  {
214  hasSpin = false;
215  paramTag = "parameters_0";
216  basisTag = "basis_1";
217  pwTag = "planewaves";
218  pwMultTag = "multipliers";
219  eigTag = "eigenstates_3";
220  twistTag = "twist_";
221  bandTag = "band_";
222  }
223  else if (version[1] == 10)
224  {
225  pwMultTag = "planewaves";
226  pwTag = "0";
227  }
228  }
229 }
230 } // namespace qmcplusplus
std::string eigTag
tag for eigentstates
std::string bandTag
tag for the band
ParameterSet m_param
xml processor
Base class for any object which needs to know about a MPI communicator.
Definition: MPIObjectBase.h:26
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
hid_t getFileID() const
return file_id. should be only be used for connecting to old codes when porting
Definition: hdf_archive.h:126
std::string basisTag
tag for the basis
std::string pwTag
tag for the planewaves
PWParameterSet(Communicate *comm)
TinyVector< int, OHMMS_DIM > BoxDup
cell multiplications
void setName(const std::string &aname)
set name
std::ostream & app_log()
Definition: OutputManager.h:65
int twistIndex
index of the twist angle
std::string getCenterName(const std::string &hg, int ib)
double BufferRadius
radius of buffer layer for truncated orbitals
class to handle hdf file
Definition: hdf_archive.h:51
std::string getEigVectorName(const std::string &hg, int ib, int ispin)
double getEcut(double ecut)
std::string pwMultTag
tag for the multipliers of the planewaves
Wrapping information on parallelism.
Definition: Communicate.h:68
std::string getOriginName(const std::string &hg, int ib)
double Ecut
energy cutoff for QMC wavefunction
std::string getBandName(int ib, int ispin)
bool getEigVectorType(hid_t h)
get the dimensions of the eigenvectors
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
double Rcut
cutoff radius for truncated orbitals
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
TinyVector< int, 2 > version
version
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
std::string spinTag
tag for the spin
std::string paramTag
tag for the parameters
void checkVersion(hdf_archive &h)
bool is_manager() const
return true if the rank == 0
Definition: MPIObjectBase.h:51
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
void bcast(T &)
bool hasSpin
true if spin channel exists
int rank() const
return the rank of the communicator
Definition: MPIObjectBase.h:35
std::string eigvecTag
tag for eigvector
std::string twistTag
tag for twist angles
bool hasComplexData(hdf_archive &h)
std::string getSpinName(int ispin)