QMCPACK
RPAJastrow.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 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /** @file RPAJastrow.cpp
16  * @brief Definitions of RPAJastrow
17  */
18 
19 #include "RPAJastrow.h"
29 #include "OhmmsData/ParameterSet.h"
30 #include "OhmmsData/AttributeSet.h"
31 
32 namespace qmcplusplus
33 {
34 RPAJastrow::RPAJastrow(ParticleSet& target) : targetPtcl(target) {}
35 
36 RPAJastrow::~RPAJastrow() = default;
37 
38 bool RPAJastrow::put(xmlNodePtr cur)
39 {
40  ReportEngine PRE("RPAJastrow", "put");
41  app_log() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
42  app_log() << "!!! WARNING: RPAJastrow is not fully tested for production !!!\n";
43  app_log() << "!!! level calculations. Use at your own risk! !!!\n";
44  app_log() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
45  //capture attribute jastrow/@name
46  MyName = "RPA_Jee";
47  std::string useL = "yes";
48  std::string useS = "yes";
49  rpafunc = "rpa";
51  a.add(MyName, "name");
52  a.add(useL, "longrange");
53  a.add(useS, "shortrange");
54  a.add(rpafunc, "function");
55  a.put(cur);
56  Rs = -1.0;
57  Kc = -1.0;
58  std::string ID_Rs = "RPA_rs";
59  ParameterSet params;
60  params.add(Rs, "rs");
61  params.add(Kc, "kc");
62  params.put(cur);
63  buildOrbital(MyName, useL, useS, rpafunc, Rs, Kc);
64  return true;
65 }
66 
67 void RPAJastrow::buildOrbital(const std::string& name,
68  const std::string& UL,
69  const std::string& US,
70  const std::string& RF,
71  RealType R,
72  RealType K)
73 {
74  std::string ID_Rs = "RPA_rs";
75  MyName = name;
76  std::string useL = UL;
77  std::string useS = US;
78  rpafunc = RF;
79  Rs = R;
80  Kc = K;
81  app_log() << std::endl << " LongRangeForm is " << rpafunc << std::endl;
82  DropLongRange = (useL == "no");
83  DropShortRange = (useS == "no");
84  RealType tlen =
85  std::pow(3.0 / 4.0 / M_PI * targetPtcl.getLattice().Volume / static_cast<RealType>(targetPtcl.getTotalNum()),
86  1.0 / 3.0);
87  if (Rs < 0)
88  {
89  if (targetPtcl.getLattice().SuperCellEnum)
90  {
91  Rs = tlen;
92  }
93  else
94  {
95  std::cout << " Error finding rs. Is this an open system?!" << std::endl;
96  Rs = 100.0;
97  }
98  }
99  int indx = targetPtcl.getSimulationCell().getKLists().ksq.size() - 1;
100  double Kc_max = std::pow(targetPtcl.getSimulationCell().getKLists().ksq[indx], 0.5);
101  if (Kc < 0)
102  {
103  Kc = 2.0 * std::pow(2.25 * M_PI, 1.0 / 3.0) / tlen;
104  }
105  if (Kc > Kc_max)
106  {
107  Kc = Kc_max;
108  app_log() << " Kc set too high. Resetting to the maximum value" << std::endl;
109  }
110  app_log() << " RPAJastrowBuilder::addTwoBodyPart Rs = " << Rs << " Kc= " << Kc << std::endl;
111  if (rpafunc == "yukawa" || rpafunc == "breakup")
112  myHandler = std::make_unique<LRHandlerTemp<YukawaBreakup<RealType>, LPQHIBasis>>(targetPtcl, Kc);
113  else if (rpafunc == "rpa")
114  myHandler = std::make_unique<LRRPAHandlerTemp<RPABreakup<RealType>, LPQHIBasis>>(targetPtcl, Kc);
115  else if (rpafunc == "dyukawa")
116  myHandler = std::make_unique<LRHandlerTemp<DerivYukawaBreakup<RealType>, LPQHIBasis>>(targetPtcl, Kc);
117  else if (rpafunc == "drpa")
118  myHandler = std::make_unique<LRRPAHandlerTemp<DerivRPABreakup<RealType>, LPQHIBasis>>(targetPtcl, Kc);
119  else
120  throw std::invalid_argument("RPAJastrowBuilder::buildOrbital: Unrecognized rpa function type.\n");
121  myHandler->Breakup(targetPtcl, Rs);
122  app_log() << " Maximum K shell " << myHandler->MaxKshell << std::endl;
123  app_log() << " Number of k vectors " << myHandler->Fk.size() << std::endl;
124  if (!DropLongRange)
125  {
126  makeLongRange();
127  app_log() << " Using LongRange part" << std::endl;
128  }
129  if (!DropShortRange)
130  {
131  makeShortRange();
132  app_log() << " Using ShortRange part" << std::endl;
133  }
134 }
135 
137 {
138  // create two-body kSpaceJastrow
139  kSpaceJastrow::SymmetryType oneBodySymm, twoBodySymm;
140  bool oneBodySpin, twoBodySpin;
141  oneBodySymm = kSpaceJastrow::ISOTROPIC;
142  twoBodySymm = kSpaceJastrow::ISOTROPIC;
143  oneBodySpin = false;
144  twoBodySpin = false;
145  auto LongRangeRPA_uptr =
146  std::make_unique<kSpaceJastrow>(targetPtcl, targetPtcl, oneBodySymm, -1, "cG1", oneBodySpin, // no one-body part
147  twoBodySymm, Kc, "cG2", twoBodySpin);
148  LongRangeRPA = LongRangeRPA_uptr.get();
149  // fill in CG2 coefficients
150  std::vector<RealType> oneBodyCoefs, twoBodyCoefs;
151  twoBodyCoefs.resize(myHandler->MaxKshell);
152  // need to cancel prefactor in kSpaceJastrow
153  RealType prefactorInv = -targetPtcl.getLattice().Volume;
154  for (size_t is = 0; is < myHandler->MaxKshell; is++)
155  {
156  twoBodyCoefs[is] = prefactorInv * myHandler->Fk_symm[is];
157  }
158  LongRangeRPA->setCoefficients(oneBodyCoefs, twoBodyCoefs);
159  Psi.push_back(std::move(LongRangeRPA_uptr));
160 }
161 
163 {
164  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
165  // !!! WARNING: tiny, nparam, npts should be input parameters !!!
166  // !!! fix in a future PR! !!!
167  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
168  app_log() << " Adding Short Range part of RPA function" << std::endl;
169  //short-range uses realHandler
170  RealType tiny = 1e-6;
171  Rcut = myHandler->get_rc() - tiny;
172  //create numerical functor of type BsplineFunctor<RealType>.
173  auto nfunc_uptr = std::make_unique<FuncType>(my_name_ + "_short");
174  nfunc = nfunc_uptr.get();
176  SRA.setRmax(Rcut);
177  auto j2 = std::make_unique<TwoBodyJastrow<BsplineFunctor<RealType>>>("RPA", targetPtcl, false);
178  size_t nparam = 12; // number of Bspline parameters
179  size_t npts = 100; // number of 1D grid points for basis functions
180  RealType cusp = SRA.df(0);
181  RealType delta = Rcut / static_cast<double>(npts);
182  std::vector<RealType> X(npts + 1), Y(npts + 1);
183  for (size_t i = 0; i < npts; ++i)
184  {
185  X[i] = i * delta;
186  Y[i] = SRA.evaluate(X[i]);
187  }
188  X[npts] = npts * delta;
189  Y[npts] = 0.0;
190  std::string functype = "rpa";
191  std::string useit = "no";
192  nfunc->initialize(nparam, X, Y, cusp, Rcut + tiny, functype, useit);
193  for (size_t i = 0; i < npts; ++i)
194  {
195  X[i] = i * delta;
196  Y[i] = SRA.evaluate(X[i]);
197  }
198  j2->addFunc(0, 0, std::move(nfunc_uptr));
199  ShortRangeRPA = j2.get();
200  Psi.push_back(std::move(j2));
201 }
202 
204 {
207 }
208 
212 {
213  log_value_ = 0.0;
214  for (int i = 0; i < Psi.size(); i++)
215  log_value_ += Psi[i]->evaluateLog(P, G, L);
216  return log_value_;
217 }
218 
220 {
221  ValueType r(1.0);
222  for (int i = 0; i < Psi.size(); i++)
223  r *= Psi[i]->ratio(P, iat);
224  return static_cast<PsiValue>(r);
225 }
226 
228 {
229  GradType grad(0);
230  for (int i = 0; i < Psi.size(); i++)
231  grad += Psi[i]->evalGrad(P, iat);
232  return grad;
233 }
234 
236 {
237  ValueType r(1);
238  for (int i = 0; i < Psi.size(); i++)
239  {
240  r *= Psi[i]->ratioGrad(P, iat, grad_iat);
241  }
242  return static_cast<PsiValue>(r);
243 }
244 
245 
246 void RPAJastrow::acceptMove(ParticleSet& P, int iat, bool safe_to_delay)
247 {
248  for (int i = 0; i < Psi.size(); i++)
249  Psi[i]->acceptMove(P, iat, safe_to_delay);
250 }
251 
252 void RPAJastrow::restore(int iat)
253 {
254  for (int i = 0; i < Psi.size(); i++)
255  Psi[i]->restore(iat);
256 }
257 
259 {
260  for (int i = 0; i < Psi.size(); i++)
261  Psi[i]->registerData(P, buf);
262 }
263 
265 {
266  log_value_ = 0.0;
267  for (int i = 0; i < Psi.size(); i++)
268  log_value_ += Psi[i]->updateBuffer(P, buf, fromscratch);
269  return log_value_;
270 }
271 
273 {
274  for (int i = 0; i < Psi.size(); i++)
275  Psi[i]->copyFromBuffer(P, buf);
276 }
277 
278 /** this is a great deal of logic for make clone I'm wondering what is going on
279  */
280 std::unique_ptr<WaveFunctionComponent> RPAJastrow::makeClone(ParticleSet& tpq) const
281 {
282  std::unique_ptr<HandlerType> tempHandler;
283  if (rpafunc == "yukawa" || rpafunc == "breakup")
284  {
285  tempHandler =
286  std::make_unique<LRHandlerTemp<YukawaBreakup<RealType>, LPQHIBasis>>(dynamic_cast<const LRHandlerTemp<
288  *myHandler),
289  tpq);
290  }
291  else if (rpafunc == "rpa")
292  {
293  tempHandler =
294  std::make_unique<LRRPAHandlerTemp<RPABreakup<RealType>, LPQHIBasis>>(dynamic_cast<const LRRPAHandlerTemp<
296  *myHandler),
297  tpq);
298  }
299  else if (rpafunc == "dyukawa")
300  {
301  tempHandler = std::make_unique<LRHandlerTemp<
303  LPQHIBasis>>(dynamic_cast<const LRHandlerTemp<DerivYukawaBreakup<RealType>, LPQHIBasis>&>(*myHandler), tpq);
304  }
305  else if (rpafunc == "drpa")
306  {
307  tempHandler = std::make_unique<LRRPAHandlerTemp<
309  LPQHIBasis>>(dynamic_cast<const LRRPAHandlerTemp<DerivRPABreakup<RealType>, LPQHIBasis>&>(*myHandler), tpq);
310  }
311 
312  auto myClone = std::make_unique<RPAJastrow>(tpq);
313  myClone->Rcut = Rcut;
314  myClone->Kc = Kc;
315  myClone->setHandler(std::move(tempHandler));
316  if (!DropLongRange)
317  myClone->makeLongRange();
318  if (!DropShortRange)
319  myClone->makeShortRange();
320  return myClone;
321 }
322 
323 }; // namespace qmcplusplus
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
Definition: RPAJastrow.cpp:219
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
kSpaceJastrow * LongRangeRPA
object to handle the long-range part
Definition: RPAJastrow.h:112
const std::string my_name_
Name of the object It is required to be different for objects of the same derived type like multiple ...
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
WaveFunctionComponent * ShortRangeRPA
Definition: RPAJastrow.h:115
QTBase::RealType RealType
Definition: Configuration.h:58
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
RPAJastrow(ParticleSet &target)
Definition: RPAJastrow.cpp:34
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
this is a great deal of logic for make clone I&#39;m wondering what is going on
Definition: RPAJastrow.cpp:280
void setCoefficients(std::vector< RealType > &oneBodyCoefs, std::vector< RealType > &twoBodyCoefs)
Attaches a unit to a Vector for IO.
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
Definition: RPAJastrow.cpp:235
bool put(xmlNodePtr cur)
Definition: RPAJastrow.cpp:38
std::complex< QTFull::RealType > LogValue
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
Definition: RPAJastrow.cpp:209
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
virtual void checkOutVariables(const opt_variables_type &active)
check out variational optimizable variables
class to handle a set of parameters
Definition: ParameterSet.h:27
QTBase::ValueType ValueType
Definition: Configuration.h:60
A derivative of LRBasis class to provide the functionality of the LPQHI basis.
Definition: LPQHIBasis.h:28
Final class and should not be derived.
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
declaration of ProgressReportEngine
std::unique_ptr< HandlerType > myHandler
main handler
Definition: RPAJastrow.h:110
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
a move for iat-th particle is accepted.
Definition: RPAJastrow.cpp:246
ParticleSet & targetPtcl
Definition: RPAJastrow.h:119
Define a LRHandler with two template parameters.
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>
void initialize(int numPoints, std::vector< Real > &x, std::vector< Real > &y, REAL cusp, REAL rcut, std::string &id, std::string &optimize)
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
Definition: RPAJastrow.cpp:264
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: RPAJastrow.cpp:258
void restore(int iat) override
If a move for iat-th particle is rejected, restore to the content.
Definition: RPAJastrow.cpp:252
UPtrVector< WaveFunctionComponent > Psi
A list of WaveFunctionComponent*.
Definition: RPAJastrow.h:121
const auto & getLattice() const
Definition: ParticleSet.h:251
FuncType * nfunc
numerical function owned by ShortRangeRPA
Definition: RPAJastrow.h:117
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: RPAJastrow.cpp:272
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
Definition: RPAJastrow.cpp:227
void buildOrbital(const std::string &name, const std::string &UL, const std::string &US, const std::string &RF, RealType R, RealType K)
Definition: RPAJastrow.cpp:67
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
void checkOutVariables(const opt_variables_type &o) override
check out optimizable variables
Definition: RPAJastrow.cpp:203
Define a LRHandler with two template parameters.
declaration of the base class for many-body wavefunction.