QMCPACK
PWRealOrbitalSet.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 PWRealOrbitalSet.cpp
17  * @brief declaration of the member functions of PWRealOrbitalSet
18  *
19  * Not the most optimized method to use wavefunctions in a plane-wave basis.
20  */
21 #include "Message/Communicate.h"
22 #include "PWRealOrbitalSet.h"
25 
26 namespace qmcplusplus
27 {
29 {
30  if (OwnBasisSet && myBasisSet)
31  delete myBasisSet;
32 }
33 
34 std::unique_ptr<SPOSet> PWRealOrbitalSet::makeClone() const
35 {
36  auto myclone = std::make_unique<PWRealOrbitalSet>(*this);
37  myclone->myBasisSet = new PWBasis(*myBasisSet);
38  return myclone;
39 }
40 
42 
43 void PWRealOrbitalSet::resize(PWBasisPtr bset, int nbands, bool cleanup)
44 {
45  myBasisSet = bset;
46  OrbitalSetSize = nbands;
47  OwnBasisSet = cleanup;
52  app_log() << " PWRealOrbitalSet::resize OrbitalSetSize =" << OrbitalSetSize << " BasisSetSize = " << BasisSetSize
53  << std::endl;
54 }
55 
56 void PWRealOrbitalSet::addVector(const std::vector<RealType>& coefs, int jorb)
57 {
58  int ng = myBasisSet->inputmap.size();
59  if (ng != coefs.size())
60  {
61  app_error() << " Input G map does not match the basis size of wave functions " << std::endl;
63  }
64  //drop G points for the given TwistAngle
65  const std::vector<int>& inputmap(myBasisSet->inputmap);
66  for (int ig = 0; ig < ng; ig++)
67  {
68  if (inputmap[ig] > -1)
69  CC[jorb][inputmap[ig]] = coefs[ig];
70  }
71 }
72 
73 void PWRealOrbitalSet::addVector(const std::vector<ComplexType>& coefs, int jorb)
74 {
75  int ng = myBasisSet->inputmap.size();
76  if (ng != coefs.size())
77  {
78  app_error() << " Input G map does not match the basis size of wave functions " << std::endl;
80  }
81  //drop G points for the given TwistAngle
82  const std::vector<int>& inputmap(myBasisSet->inputmap);
83  for (int ig = 0; ig < ng; ig++)
84  {
85  if (inputmap[ig] > -1)
86  CC[jorb][inputmap[ig]] = coefs[ig];
87  }
88 }
89 
91 {
92  myBasisSet->evaluate(P.activeR(iat));
94  for (int j = 0; j < OrbitalSetSize; j++)
95  psi[j] = tempPsi[j].real();
96 }
97 
99  int iat,
100  ValueVector& psi,
101  GradVector& dpsi,
102  ValueVector& d2psi)
103 {
104  myBasisSet->evaluateAll(P, iat);
106  const ComplexType* restrict tptr = Temp.data();
107  for (int j = 0; j < OrbitalSetSize; j++, tptr += PW_MAXINDEX)
108  {
109  psi[j] = tptr[PW_VALUE].real();
110  d2psi[j] = tptr[PW_LAP].real();
111 #if OHMMS_DIM == 3
112  dpsi[j] = GradType(tptr[PW_GRADX].real(), tptr[PW_GRADY].real(), tptr[PW_GRADZ].real());
113 #elif OHMMS_DIM == 2
114  dpsi[j] = GradType(tptr[PW_GRADX].real(), tptr[PW_GRADY].real());
115 #elif OHMMS_DIM == 1
116  dpsi[j] = GradType(tptr[PW_GRADX].real());
117 #else
118 #error "Only physical dimensions 1/2/3 are supported."
119 #endif
120  }
121 }
122 
124  int first,
125  int last,
126  ValueMatrix& logdet,
127  GradMatrix& dlogdet,
128  ValueMatrix& d2logdet)
129 {
130  for (int iat = first, i = 0; iat < last; iat++, i++)
131  {
132  myBasisSet->evaluateAll(P, iat);
134  const ComplexType* restrict tptr = Temp.data();
135  for (int j = 0; j < OrbitalSetSize; j++, tptr += PW_MAXINDEX)
136  {
137  convertToReal(tptr[PW_VALUE], logdet(i, j));
138  convertToReal(tptr[PW_LAP], d2logdet(i, j));
139 #if OHMMS_DIM == 3
140  dlogdet(i, j) = GradType(tptr[PW_GRADX].real(), tptr[PW_GRADY].real(), tptr[PW_GRADZ].real());
141 #elif OHMMS_DIM == 2
142  dlogdet(i, j) = GradType(tptr[PW_GRADX].real(), tptr[PW_GRADY].real());
143 #elif OHMMS_DIM == 1
144  dlogdet(i, j) = GradType(tptr[PW_GRADX].real());
145 #else
146 #error "Only physical dimensions 1/2/3 are supported."
147 #endif
148  }
149  }
150 }
151 } // namespace qmcplusplus
void evaluateAll(const ParticleSet &P, int iat)
Definition: PWBasis.h:291
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::GradType GradType
Definition: Configuration.h:62
void evaluate(const PosType &pos)
Definition: PWBasis.h:284
void addVector(const std::vector< RealType > &coefs, int jorb)
add eigenstate for jorb-th orbital
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_error()
Definition: OutputManager.h:67
void convertToReal(const T1 &in, T2 &out)
generic conversion from type T1 to type T2 using implicit conversion
Definition: ConvertToReal.h:32
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
~PWRealOrbitalSet() override
delete BasisSet only it owns this
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Matrix< ComplexType > Temp
temporary array to perform gemm operation
Vector< ComplexType > Zv
Definition: PWBasis.h:89
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
std::unique_ptr< SPOSet > makeClone() const override
make a clone of itself every derived class must implement this to have threading working correctly...
void resize(PWBasisPtr bset, int nbands, bool cleanup=false)
resize the orbital base
Matrix< ComplexType > CC
Plane-wave coefficients of complex: (iband,g-vector)
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
PWBasisPtr myBasisSet
My basis set.
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
Matrix< ComplexType > Z
Definition: PWBasis.h:87
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) override
evaluate the values of this single-particle orbital set
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
IndexType OrbitalSetSize
number of Single-particle orbitals
Definition: SPOSet.h:566
const PosType & activeR(int iat) const
return the active position if the particle is active or the return current position if not ...
Definition: ParticleSet.h:265
void evaluate_notranspose(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet) override
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
IndexType BasisSetSize
number of basis
void abort() const
int NumPlaneWaves
total number of basis functions
Definition: PWBasis.h:111
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
QMCTraits::ComplexType ComplexType
Define PWRealOrbitalSet derived from SPOSet.
Plane-wave basis set.
Definition: PWBasis.h:40
Vector< ComplexType > tempPsi
temporary complex vector before assigning to a real psi
void setOrbitalSetSize(int norbs) override
set the OrbitalSetSize
std::vector< int > inputmap
Definition: PWBasis.h:108