QMCPACK
kSpaceJastrow.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
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 kSpaceJastrow.h
17  * @brief Declaration of Long-range TwoBody Jastrow
18  *
19  * The initial coefficients are evaluated according to RPA.
20  * A set of k-dependent coefficients are generated.
21  * Optimization should use rpa_k0, ...rpa_kn as the names of the
22  * optimizable parameters.
23  */
24 #ifndef QMCPLUSPLUS_LR_KSPACEJASTROW_H
25 #define QMCPLUSPLUS_LR_KSPACEJASTROW_H
26 
28 #include "OhmmsData/libxmldefs.h"
29 #include "OhmmsPETE/OhmmsVector.h"
30 #include "OhmmsPETE/OhmmsMatrix.h"
32 
33 namespace qmcplusplus
34 {
35 /** Functor which return \f$frac{Rs}{k^2 (k^2+(1/Rs)^2)}\f$
36  */
37 template<typename T>
38 struct RPA0
39 {
40  T Rs;
42  RPA0(T rs = 1) : Rs(rs) { OneOverRsSq = 1.0 / (Rs * Rs); }
43  inline T operator()(T kk)
44  {
45  T k2 = std::sqrt(kk);
46  return Rs / (k2 * (k2 + OneOverRsSq));
47  //return (-0.5+0.5*std::pow(1.0+12.0*OneOverRs3/kk/kk,0.5));
48  }
49 };
50 
51 
52 template<typename T>
54 {
55 public:
56  // The coefficient
57  T cG;
58  // The first and last indices of the G-vectors to which this
59  // coefficient belongs
61  inline void set(std::vector<T>& unpackedCoefs)
62  {
63  for (int i = firstIndex; i <= lastIndex; i++)
64  unpackedCoefs[i] = cG;
65  }
66 };
67 
69 {
70 public:
71  typedef enum
72  {
76  } SymmetryType;
77 
78 private:
79  using ComplexType = std::complex<RealType>;
80  ////////////////
81  // Basic data //
82  ////////////////
84  int num_elecs;
85  int NumSpins;
87 
88  // Gvectors included in the summation for the
89  // one-body and two-body Jastrows, respectively
90  std::vector<PosType> OneBodyGvecs;
91  std::vector<PosType> TwoBodyGvecs;
92 
93  // Vectors of unique coefficients, one for each group of
94  // symmetry-equivalent G-vectors
95  std::vector<kSpaceCoef<ComplexType>> OneBodySymmCoefs;
96  std::vector<kSpaceCoef<RealType>> TwoBodySymmCoefs;
97 
98  // Vector of coefficients, one for each included G-vector
99  // in OneBodyGvecs/TwoBodyGvecs
100  std::vector<ComplexType> OneBodyCoefs;
101  std::vector<RealType> TwoBodyCoefs;
102 
103  // Stores how we choose to group the G-vectors by symmetry
105 
106  // Rho_k data
107  // For the ions
108  std::vector<ComplexType> Ion_rhoG;
109  // For the electrons
110  std::vector<ComplexType> OneBody_rhoG, TwoBody_rhoG;
111  // Holds the phase for the electrons with size commensurate with
112  // OneBodyGvecs, and TwoBodyGvecs, respectively
113  std::vector<RealType> OneBodyPhase, TwoBodyPhase;
114  //
117 
118  // Map of the optimizable variables:
119  //std::map<std::string,RealType*> VarMap;
120 
121  //////////////////////
122  // Member functions //
123  //////////////////////
124 
125  // Enumerate G-vectors with nonzero structure factors
126  void setupGvecs(RealType kcut, std::vector<PosType>& gvecs, bool useStructFact);
127  void setupCoefs();
128 
129  // Sort the G-vectors into appropriate symmtry groups
130  template<typename T>
131  void sortGvecs(std::vector<PosType>& gvecs, std::vector<kSpaceCoef<T>>& coefs, SymmetryType symm);
132 
133  // Returns true if G1 and G2 are equivalent by crystal symmetry
134  bool Equivalent(PosType G1, PosType G2);
135  void StructureFactor(PosType G, std::vector<ComplexType>& rho_G);
136 
138  std::string OneBodyID;
139  std::string TwoBodyID;
140  double Prefactor;
141 
142 public:
143  kSpaceJastrow(const ParticleSet& ions,
144  ParticleSet& elecs,
145  SymmetryType oneBodySymm,
146  RealType oneBodyCutoff,
147  std::string onebodyid,
148  bool oneBodySpin,
149  SymmetryType twoBodySymm,
150  RealType twoBodyCutoff,
151  std::string twobodyid,
152  bool twoBodySpin);
153 
154  kSpaceJastrow(const ParticleSet& ions);
155 
156  void setCoefficients(std::vector<RealType>& oneBodyCoefs, std::vector<RealType>& twoBodyCoefs);
157 
158  std::string getClassName() const override { return "kSpaceJastrow"; }
159  //implement virtual functions for optimizations
160  bool isOptimizable() const override { return true; }
161  void checkOutVariables(const opt_variables_type& active) override;
162 
163  void extractOptimizableObjectRefs(UniqueOptObjRefs& opt_obj_refs) override { opt_obj_refs.push_back(*this); }
164 
165  void checkInVariablesExclusive(opt_variables_type& active) final;
166  void resetParametersExclusive(const opt_variables_type& active) final;
167 
170  ParticleSet::ParticleLaplacian& L) override;
171 
172  PsiValue ratio(ParticleSet& P, int iat) override;
173 
174  GradType evalGrad(ParticleSet& P, int iat) override;
175  PsiValue ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override;
176 
177  void restore(int iat) override;
178  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override;
179 
180  // Allocate per-walker data in the PooledData buffer
181  void registerData(ParticleSet& P, WFBufferType& buf) override;
182  // Walker move has been accepted -- update the buffer
183  LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override;
184  // Pull data from the walker buffer at the beginning of a block of
185  // single-particle moves
186  void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override;
187 
188  ///process input file
189  bool put(xmlNodePtr cur);
190  ///output jastrow coefficients
191  void printOneBody(std::ostream& os);
192  void printTwoBody(std::ostream& os);
193 
194  // Implements strict weak ordering with respect to the
195  // structure factors. Used to sort the G-vectors according to
196  // crystal symmetry
197  bool operator()(PosType G1, PosType G2);
198  std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const override;
199 
201  const opt_variables_type& active,
202  Vector<ValueType>& dlogpsi,
203  Vector<ValueType>& dhpsioverpsi) override;
204 
205  /** evaluate the ratio
206  */
207  void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios) override;
208 
209 private:
210  void copyFrom(const kSpaceJastrow& old);
211  std::vector<int> TwoBodyVarMap;
212  std::vector<int> OneBodyVarMap;
213 };
214 } // namespace qmcplusplus
215 #endif
bool operator()(PosType G1, PosType G2)
void checkInVariablesExclusive(opt_variables_type &active) final
check in variational parameters to the global list of parameters used by the optimizer.
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
std::vector< ComplexType > OneBody_e2iGr
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< kSpaceCoef< ComplexType > > OneBodySymmCoefs
Definition: kSpaceJastrow.h:95
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
evaluate the ratio
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) override
extract underlying OptimizableObject references
void printTwoBody(std::ostream &os)
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
std::vector< ComplexType > OneBody_rhoG
void restore(int iat) override
If a move for iat-th particle is rejected, restore to the content.
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
std::string getClassName() const override
return class name
LatticeGaussianProduct::GradType GradType
void setCoefficients(std::vector< RealType > &oneBodyCoefs, std::vector< RealType > &twoBodyCoefs)
A collection of put/get functions to read from or write to a xmlNode defined in libxml2.
Attaches a unit to a Vector for IO.
Functor which return .
Definition: kSpaceJastrow.h:38
std::vector< int > OneBodyVarMap
Matrix< ComplexType > Delta_e2iGr
std::vector< ComplexType > TwoBody_e2iGr_new
An abstract class for a component of a many-body trial wave function.
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
const ParticleSet & Ions
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
std::vector< PosType > OneBodyGvecs
Definition: kSpaceJastrow.h:90
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
bool put(xmlNodePtr cur)
process input file
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
std::vector< RealType > TwoBodyPhase
std::vector< RealType > TwoBodyCoefs
bool isOptimizable() const override
if true, this contains optimizable components
std::vector< ComplexType > Ion_rhoG
std::complex< RealType > ComplexType
Definition: kSpaceJastrow.h:79
std::vector< ComplexType > OneBodyCoefs
void printOneBody(std::ostream &os)
output jastrow coefficients
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
void copyFrom(const kSpaceJastrow &old)
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
std::vector< ComplexType > TwoBody_rhoG
kSpaceJastrow(const ParticleSet &ions, ParticleSet &elecs, SymmetryType oneBodySymm, RealType oneBodyCutoff, std::string onebodyid, bool oneBodySpin, SymmetryType twoBodySymm, RealType twoBodyCutoff, std::string twobodyid, bool twoBodySpin)
void sortGvecs(std::vector< PosType > &gvecs, std::vector< kSpaceCoef< T >> &coefs, SymmetryType symm)
Declaration of WaveFunctionComponent.
std::complex< double > LogValue
std::vector< kSpaceCoef< RealType > > TwoBodySymmCoefs
Definition: kSpaceJastrow.h:96
std::vector< int > TwoBodyVarMap
void setupGvecs(RealType kcut, std::vector< PosType > &gvecs, bool useStructFact)
Define LRHandlerBase and DummyLRHandler<typename Func>
std::vector< ComplexType > TwoBody_e2iGr_old
void StructureFactor(PosType G, std::vector< ComplexType > &rho_G)
std::vector< RealType > OneBodyPhase
void push_back(OptimizableObject &obj)
bool Equivalent(PosType G1, PosType G2)
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
std::vector< PosType > TwoBodyGvecs
Definition: kSpaceJastrow.h:91
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
a move for iat-th particle is accepted.
void resetParametersExclusive(const opt_variables_type &active) final
reset the parameters during optimizations.