QMCPACK
PWBasis.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 PWBasis.cpp
17  * @brief Definition of member functions of Plane-wave basis set
18  */
19 #include "PWBasis.h"
20 
21 namespace qmcplusplus
22 {
23 int PWBasis::readbasis(hdf_archive& h5basisgroup,
24  RealType ecutoff,
25  const ParticleLayout& lat,
26  const std::string& pwname,
27  const std::string& pwmultname,
28  bool resizeContainer)
29 {
30  ///make a local copy
31  Lattice = lat;
32  ecut = ecutoff;
33  app_log() << " PWBasis::" << pwmultname << " is found " << std::endl;
34  h5basisgroup.read(gvecs, "/electrons/kpoint_0/gvectors");
35  NumPlaneWaves = std::max(gvecs.size(), kplusgvecs_cart.size());
36  if (NumPlaneWaves == 0)
37  throw std::runtime_error(" PWBasis::readbasis Basis is missing.");
38 
39  if (kplusgvecs_cart.empty())
40  {
42  for (int i = 0; i < NumPlaneWaves; i++)
44  }
45  //app_log() << " Gx Gy Gz " << std::endl;
46  //for(int i=0; i<kplusgvecs_cart.size(); i++)
47  //{
48  // app_log() << kplusgvecs_cart[i] << std::endl;
49  //}
50  //Now remove elements outside Ecut. At the same time, fill k+G and |k+G| lists.
51  //Also keep track of the original index ordering (using indexmap[]) so that
52  //orbital coefficients can be ordered and trimmed for ecut in the same way.
53  //support older parser
54  if (resizeContainer)
55  reset();
56  //std::copy(gvecs.begin(),gvecs.end(),std::ostream_iterator<GIndex_t>(std::cout,"\n"));
57  return NumPlaneWaves;
58 }
59 
61 {
62  PosType dang = twist - tang;
63  bool sameTwist = dot(dang, dang) < std::numeric_limits<RealType>::epsilon();
64  if (maxmaxg && sameTwist)
65  return;
66  twist = tang;
67  reset();
68 }
69 
71 {
72  trimforecut();
73  //logC.resize(3,2*maxmaxg+1);
74  Z.resize(NumPlaneWaves, 2 + DIM);
77 }
78 
79 /** Remove basis elements if kinetic energy > ecut.
80  *
81  * Keep and indexmap so we know how to match coefficients on read.
82  */
84 {
85  //Convert the twist angle to Cartesian coordinates.
87  inputmap.resize(NumPlaneWaves);
88  app_log() << " PWBasis::TwistAngle (unit) =" << twist << std::endl;
89  app_log() << " PWBasis::TwistAngle (cart) =" << twist_cart << std::endl;
90  app_log() << " PWBasis::trimforecut NumPlaneWaves (before) =" << NumPlaneWaves << std::endl;
91  std::vector<GIndex_t> gvecCopy(gvecs);
92  std::vector<PosType> gcartCopy(kplusgvecs_cart);
93  gvecs.clear();
94  kplusgvecs_cart.clear();
96  // RealType kcutoff2 = 2.0*ecut; //std::sqrt(2.0*ecut);
97  int ngIn = NumPlaneWaves;
98  for (int ig = 0, newig = 0; ig < ngIn; ig++)
99  {
100  //PosType tempvec = Lattice.k_cart(gvecCopy[ig]+twist);
101  PosType tempvec = gcartCopy[ig] + twist_cart;
102  RealType mod2 = dot(tempvec, tempvec);
103 
104  // Keep all the g-vectors
105  // The cutoff energy is not stored in the HDF file now.
106  // Is truncating the gvectors to a spherical shell necessary?
107  if (true)
108  {
109  gvecs.push_back(gvecCopy[ig]);
110  kplusgvecs_cart.push_back(tempvec);
111  minusModKplusG2.push_back(-mod2);
112  //Remember which position in the HDF5 file this came from...for coefficients
113  inputmap[ig] = newig++;
114  }
115 #if 0
116  if(mod2<=kcutoff2)
117  {
118  gvecs.push_back(gvecCopy[ig]);
119  kplusgvecs_cart.push_back(tempvec);
120  minusModKplusG2.push_back(-mod2);
121  //Remember which position in the HDF5 file this came from...for coefficients
122  inputmap[ig] = newig++;
123  }
124  else
125  {
126  inputmap[ig] = -1; //Temporary value...need to know final NumPlaneWaves.
127  NumPlaneWaves--;
128  }
129 #endif
130  }
131 #if defined(PWBASIS_USE_RECURSIVE)
132  //Store the maximum number of translations, within ecut, of any reciprocal cell vector.
133  for (int ig = 0; ig < NumPlaneWaves; ig++)
134  for (int i = 0; i < OHMMS_DIM; i++)
135  if (std::abs(gvecs[ig][i]) > maxg[i])
136  maxg[i] = std::abs(gvecs[ig][i]);
138  for (int ig = 0; ig < NumPlaneWaves; ig++)
139  gvecs_shifted[ig] = gvecs[ig] + maxg;
140  maxmaxg = std::max(maxg[0], std::max(maxg[1], maxg[2]));
141  //changes the order???? ok
142  C.resize(3, 2 * maxmaxg + 2);
143 #else
144  maxmaxg = 1;
145 #endif
146  // //make a copy of input to gvecCopy
147  //// for(int ig=0, newig=0; ig<ngIn; ig++) {
148  // //Check size of this g-vector
149  // PosType tempvec = Lattice.k_cart(gvecCopy[ig]+twist);
150  // RealType mod2 = dot(tempvec,tempvec);
151  // if(mod2<=kcutoff2){ //Keep this element
152  // gvecs.push_back(gvecCopy[ig]);
153  // kplusgvecs_cart.push_back(tempvec);
154  // minusModKplusG2.push_back(-mod2);
155  // //Remember which position in the HDF5 file this came from...for coefficients
156  // inputmap[ig] = newig++;
157  ////#if !defined(QMC_COMPLEX)
158  //// //Build the negative vector. See comment at declaration (above) for details.
159  //// if(gvecCopy[ig][0] < 0)
160  //// negative.push_back(0);
161  //// else if(gvecCopy[ig][0] > 0)
162  //// negative.push_back(1);
163  //// else { //gx == 0, test gy
164  //// if(gvecCopy[ig][1] < 0)
165  //// negative.push_back(0);
166  //// else if(gvecCopy[ig][1] > 0)
167  //// negative.push_back(1);
168  //// else { //gx == gy == 0; test gz. If gz==0 also, take negative=1 (arbitrary)
169  //// if(gvecCopy[ig][2] < 0)
170  //// negative.push_back(0);
171  //// else
172  //// negative.push_back(1);
173  //// }
174  //// }
175  ////#endif
176  // } else {
177  // inputmap[ig] = -1; //Temporary value...need to know final NumPlaneWaves.
178  // NumPlaneWaves--;
179  // }
180  // }
181  //Finalize the basis. Fix temporary values of inputmap.
182  //for(int ig=0; ig<inputmap.size(); ig++)
183  // if(inputmap[ig] == -1)
184  // inputmap[ig] = NumPlaneWaves; //For dumping coefficients of PWs>ecut
185  app_log() << " NumPlaneWaves (after) =" << NumPlaneWaves << std::endl;
186 }
187 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
a class that defines a supercell in D-dimensional Euclean space.
PosType twist
twist angle in reduced
Definition: PWBasis.h:54
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
Vector< RealType > phi
Definition: PWBasis.h:106
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
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
void setTwistAngle(const PosType &tang)
set the twist angle
Definition: PWBasis.cpp:60
std::vector< GIndex_t > gvecs_shifted
Reduced coordinates with offset gvecs_shifted[][idim]=gvecs[][idim]+maxg[idim].
Definition: PWBasis.h:61
class to handle hdf file
Definition: hdf_archive.h:51
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
int maxmaxg
max of maxg[i]
Definition: PWBasis.h:48
#define OHMMS_DIM
Definition: config.h:64
Matrix< ComplexType > C
Definition: PWBasis.h:66
Vector< ComplexType > Zv
Definition: PWBasis.h:89
SingleParticlePos k_cart(const SingleParticlePos &kin) const
conversion of a reciprocal-vector
Matrix< ComplexType > Z
Definition: PWBasis.h:87
void trimforecut()
Remove basis elements if kinetic energy > ecut.
Definition: PWBasis.cpp:83
void reset()
reset
Definition: PWBasis.cpp:70
std::vector< GIndex_t > gvecs
gvecs in reduced coordiates
Definition: PWBasis.h:59
int readbasis(hdf_archive &h5basisgroup, RealType ecutoff, const ParticleLayout &lat, const std::string &pwname="planewaves", const std::string &pwmultname="multipliers", bool resizeContainer=true)
Read basisset from hdf5 file.
Definition: PWBasis.cpp:23
int NumPlaneWaves
total number of basis functions
Definition: PWBasis.h:111
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
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
std::vector< RealType > minusModKplusG2
Definition: PWBasis.h:63
Declaration of Plane-wave basis set.
PosType twist_cart
twist angle in cartesian
Definition: PWBasis.h:56
std::vector< PosType > kplusgvecs_cart
Definition: PWBasis.h:64
std::vector< int > inputmap
Definition: PWBasis.h:108