QMCPACK
BsplineReader.h
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) 2023 QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
9 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /** @file BsplineReader.h
17  *
18  * base class to read data and manage spline tables
19  */
20 #ifndef QMCPLUSPLUS_BSPLINE_READER_H
21 #define QMCPLUSPLUS_BSPLINE_READER_H
22 
23 #include <vector>
24 #include <einspline/bspline_base.h>
25 #include <BandInfo.h>
26 #include "EinsplineSetBuilder.h"
27 
28 namespace qmcplusplus
29 {
30 struct SPOSetInputInfo;
31 
32 /**
33  * Each SplineC2X needs a reader derived from BsplineReader.
34  * This base class handles common chores
35  * - check_twists : read gvectors, set twists for folded bands if needed, and set the phase for the special K
36  * - set_grid : create the basic grid and boundary conditions for einspline
37  * Note that template is abused but it works.
38  */
40 {
41  ///pointer to the EinsplineSetBuilder
43  ///communicator
45  ///mesh size
46  ///check the norm of orbitals
47  bool checkNorm;
48  ///save spline coefficients to storage
50  ///apply orbital rotations
51  bool rotate;
52  ///map from spo index to band index
53  std::vector<std::vector<int>> spo2band;
54 
56 
57  virtual ~BsplineReader();
58 
59  std::string getSplineDumpFileName(const BandInfoGroup& bandgroup) const
60  {
61  auto& MeshSize = mybuilder->MeshSize;
62  std::ostringstream oo;
63  oo << bandgroup.myName << ".g" << MeshSize[0] << "x" << MeshSize[1] << "x" << MeshSize[2] << ".h5";
64  return oo.str();
65  }
66 
67  /** read gvectors and set the mesh, and prepare for einspline
68  */
69  template<typename GT, typename BCT>
70  inline bool set_grid(const TinyVector<int, 3>& halfg, GT* xyz_grid, BCT* xyz_bc) const
71  {
72  //This sets MeshSize from the input file
73  bool havePsig = mybuilder->ReadGvectors_ESHDF();
74 
75  for (int j = 0; j < 3; ++j)
76  {
77  xyz_grid[j].start = 0.0;
78  xyz_grid[j].end = 1.0;
79  xyz_grid[j].num = mybuilder->MeshSize[j];
80 
81  if (halfg[j])
82  {
83  xyz_bc[j].lCode = ANTIPERIODIC;
84  xyz_bc[j].rCode = ANTIPERIODIC;
85  }
86  else
87  {
88  xyz_bc[j].lCode = PERIODIC;
89  xyz_bc[j].rCode = PERIODIC;
90  }
91 
92  xyz_bc[j].lVal = 0.0;
93  xyz_bc[j].rVal = 0.0;
94  }
95  return havePsig;
96  }
97 
98  /** initialize twist-related data for N orbitals
99  */
100  template<typename SPE>
101  inline void check_twists(SPE& bspline, const BandInfoGroup& bandgroup) const
102  {
103  //init(orbitalSet,bspline);
104  bspline.PrimLattice = mybuilder->PrimCell;
105  bspline.GGt = dot(transpose(bspline.PrimLattice.G), bspline.PrimLattice.G);
106 
107  int N = bandgroup.getNumDistinctOrbitals();
108  int numOrbs = bandgroup.getNumSPOs();
109 
110  bspline.setOrbitalSetSize(numOrbs);
111  bspline.resizeStorage(N, N);
112 
113  bspline.first_spo = bandgroup.getFirstSPO();
114  bspline.last_spo = bandgroup.getLastSPO();
115 
116  int num = 0;
117  const std::vector<BandInfo>& cur_bands = bandgroup.myBands;
118  for (int iorb = 0; iorb < N; iorb++)
119  {
120  int ti = cur_bands[iorb].TwistIndex;
121  bspline.kPoints[iorb] = mybuilder->PrimCell.k_cart(-mybuilder->primcell_kpoints[ti]);
122  bspline.MakeTwoCopies[iorb] = (num < (numOrbs - 1)) && cur_bands[iorb].MakeTwoCopies;
123  num += bspline.MakeTwoCopies[iorb] ? 2 : 1;
124  }
125 
126  app_log() << "NumDistinctOrbitals " << N << " numOrbs = " << numOrbs << std::endl;
127 
128  bspline.HalfG = 0;
129  TinyVector<int, 3> bconds = mybuilder->TargetPtcl.getLattice().BoxBConds;
130  if (!bspline.isComplex())
131  {
132  //no k-point folding, single special k point (G, L ...)
134  for (int i = 0; i < 3; i++)
135  if (bconds[i] && ((std::abs(std::abs(twist0[i]) - 0.5) < 1.0e-8)))
136  bspline.HalfG[i] = 1;
137  else
138  bspline.HalfG[i] = 0;
139  app_log() << " TwistIndex = " << cur_bands[0].TwistIndex << " TwistAngle " << twist0 << std::endl;
140  app_log() << " HalfG = " << bspline.HalfG << std::endl;
141  }
142  app_log().flush();
143  }
144 
145  /** return the path name in hdf5
146  * @param ti twist index
147  * @param spin spin index
148  * @param ib band index
149  */
150  inline std::string psi_g_path(int ti, int spin, int ib) const
151  {
152  std::ostringstream path;
153  path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << ib << "/psi_g";
154  return path.str();
155  }
156 
157  /** return the path name in hdf5
158  * @param ti twist index
159  * @param spin spin index
160  * @param ib band index
161  */
162  inline std::string psi_r_path(int ti, int spin, int ib) const
163  {
164  std::ostringstream path;
165  path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << ib << "/psi_r";
166  return path.str();
167  }
168 
169  /** create the actual spline sets
170  */
171  virtual std::unique_ptr<SPOSet> create_spline_set(const std::string& my_name,
172  int spin,
173  const BandInfoGroup& bandgroup) = 0;
174 
175  /** setting common parameters
176  */
177  void setCommon(xmlNodePtr cur);
178 
179  /** create the spline after one of the kind is created */
180  std::unique_ptr<SPOSet> create_spline_set(int spin, xmlNodePtr cur, SPOSetInputInfo& input_info);
181 
182  /** create the spline set */
183  std::unique_ptr<SPOSet> create_spline_set(int spin, xmlNodePtr cur);
184 
185  /** Set the checkNorm variable */
186  inline void setCheckNorm(bool new_checknorm) { checkNorm = new_checknorm; };
187 
188  /** Set the orbital rotation flag. Rotations are applied to balance the real/imaginary components. */
189  inline void setRotate(bool new_rotate) { rotate = new_rotate; };
190 
191  void initialize_spo2band(int spin,
192  const std::vector<BandInfo>& bigspace,
193  SPOSetInfo& sposet,
194  std::vector<int>& band2spo);
195 };
196 
197 } // namespace qmcplusplus
198 #endif
double bspline(double x, const std::vector< double > &t, const std::vector< double > &c, int k)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
class to read state range information from sposet input
int getLastSPO() const
return the indext of the last SPO set
Definition: BandInfo.h:89
Communicate * myComm
communicator
Definition: BsplineReader.h:44
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_log()
Definition: OutputManager.h:65
ParticleSet & TargetPtcl
quantum particle set
std::string myName
name of this band
Definition: BandInfo.h:81
Define helper class to sort bands according to the band and twist and functions.
void check_twists(SPE &bspline, const BandInfoGroup &bandgroup) const
initialize twist-related data for N orbitals
Builder class for einspline-based SPOSet objects.
void setCheckNorm(bool new_checknorm)
Set the checkNorm variable.
int getNumSPOs() const
return the number of SPOs
Definition: BandInfo.h:91
int getNumDistinctOrbitals() const
return the size of this band
Definition: BandInfo.h:85
Wrapping information on parallelism.
Definition: Communicate.h:68
SingleParticlePos k_cart(const SingleParticlePos &kin) const
conversion of a reciprocal-vector
Each SplineC2X needs a reader derived from BsplineReader.
Definition: BsplineReader.h:39
a group of bands
Definition: BandInfo.h:66
std::vector< std::vector< int > > spo2band
map from spo index to band index
Definition: BsplineReader.h:53
int TwistIndex
twist index set by the full band not by the subset
Definition: BandInfo.h:77
int getFirstSPO() const
return the indext of the first SPO set
Definition: BandInfo.h:87
collection of orbital info for SPOSet instance or builder
Definition: SPOSetInfo.h:25
void setCommon(xmlNodePtr cur)
setting common parameters
AntiSymTensor< T, D > transpose(const AntiSymTensor< T, D > &rhs)
std::string getSplineDumpFileName(const BandInfoGroup &bandgroup) const
Definition: BsplineReader.h:59
std::string psi_g_path(int ti, int spin, int ib) const
return the path name in hdf5
bool ReadGvectors_ESHDF()
read gvectors for each twist
BsplineReader(EinsplineSetBuilder *e)
bool set_grid(const TinyVector< int, 3 > &halfg, GT *xyz_grid, BCT *xyz_bc) const
read gvectors and set the mesh, and prepare for einspline
Definition: BsplineReader.h:70
virtual std::unique_ptr< SPOSet > create_spline_set(const std::string &my_name, int spin, const BandInfoGroup &bandgroup)=0
create the actual spline sets
const auto & getLattice() const
Definition: ParticleSet.h:251
void initialize_spo2band(int spin, const std::vector< BandInfo > &bigspace, SPOSetInfo &sposet, std::vector< int > &band2spo)
build index tables to map a state to band with k-point folidng
std::vector< TinyVector< double, OHMMS_DIM > > primcell_kpoints
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
EinsplineSetBuilder * mybuilder
pointer to the EinsplineSetBuilder
Definition: BsplineReader.h:42
bool rotate
apply orbital rotations
Definition: BsplineReader.h:51
std::string psi_r_path(int ti, int spin, int ib) const
return the path name in hdf5
void setRotate(bool new_rotate)
Set the orbital rotation flag.
bool checkNorm
mesh size check the norm of orbitals
Definition: BsplineReader.h:47
std::vector< BandInfo > myBands
Bands that belong to this group.
Definition: BandInfo.h:79
bool saveSplineCoefs
save spline coefficients to storage
Definition: BsplineReader.h:49