QMCPACK
SOVMCUpdateAll.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: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore 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 #include "SOVMCUpdateAll.h"
18 #include "Concurrency/OpenMP.h"
19 
20 namespace qmcplusplus
21 {
23 
25  TrialWaveFunction& psi,
26  QMCHamiltonian& h,
28  : QMCUpdateBase(w, psi, h, rg)
29 {
30  UpdatePbyP = false;
31 }
32 
34 
35 void SOVMCUpdateAll::advanceWalker(Walker_t& thisWalker, bool recompute)
36 {
37  /* thisWalker.R will track the last accepted configuration
38  * W.R will track the proposed configuration
39  *
40  * upon Call:
41  * thisWalker.R,G,L,Properties must be consistent
42  * recompute flag is for pbyp driver and is not used here
43  *
44  * upon Return:
45  * thisWalker.R,G,L,Properties must be kept consistent
46  * */
47  bool updated = false;
48  W.loadWalker(
49  thisWalker,
50  false); // W.R,G,L = thisWalker.R,G,L; false indicates W.DistTables & SK are not updated in this call. W.DistTables,SK are now stale.
51  RealType logpsi_old = thisWalker.Properties(WP::LOGPSI);
52 
53  RealType invSqrtSpinMass = 1.0 / std::sqrt(spinMass);
54 
55  for (int iter = 0; iter < nSubSteps; ++iter)
56  { // make a few Monte-Carlo steps to decorrelate samples without calculating observables
59  updated = false;
60  if (UseDrift)
61  {
62  APP_ABORT("All-electron spin moves with drift are not implemented\n");
63  }
64  else
65  {
66  if (W.makeMoveAllParticles(thisWalker, deltaR, SqrtTauOverMass))
67  {
68  //Assume that since the spatial move is fine, the spin move will be.
69  //Compute that now.
70  for (int iat = 0; iat < deltaR.size(); ++iat)
71  W.spins[iat] = thisWalker.spins[iat] + invSqrtSpinMass * SqrtTauOverMass[iat] * deltaS[iat];
72 
73  // W.R += dR*dt; W.DistTables,SK are updated; W.G,L are now stale
74  RealType logpsi = Psi.evaluateLog(W); // update W.G,L at changed W.R; update Psi.log_real_,PhaseValue
75  RealType g = std::exp(2.0 * (logpsi - logpsi_old));
76  if (RandomGen() <= g)
77  { // move is accepted; logpsi_old and R_old are stale
78  logpsi_old = logpsi; // update logpsi_old
79  thisWalker.R = W.R; // update R_old; side effect: thisWalker.G,L,DistTables,SK,Properties are now stale
80  thisWalker.spins =
81  W.spins; // update R_old; side effect: thisWalker.G,L,DistTables,SK,Properties are now stale
82  ++nAccept;
83  updated = true;
84  }
85  }
86  }
87 
88  if (!updated)
89  { // W.R,G,L,DistTables,SK are not updated. i.e. they are still consistent
90  thisWalker.Age++;
91  ++nReject;
92  }
93  }
94 
95  if (!updated)
96  { // W.G and W.L have to be computed because the last move was rejected
97  W.loadWalker(thisWalker, false); // move W back to last accepted configuration
98  W.update(); // update W.DistTables and SK
99  logpsi_old = Psi.evaluateLog(W); // update W.G,L
100  } // W and logpsi_old are up-to-date at this point
101 
102  RealType eloc = H.evaluate(
103  W); // calculate local energy; W.SK must be up-to-date if Coulomb interaction is used with periodic boundary. W.SK is used to calculate the long-range part of the Coulomb potential.
104  W.saveWalker(thisWalker);
105  thisWalker.resetProperty(logpsi_old, Psi.getPhase(),
106  eloc); // update thisWalker::Properties[WP::LOGPSI,WP::SIGN,WP::LOCALENERGY]
107  H.auxHevaluate(W, thisWalker); // update auxiliary observables, i.e. fill H::Observables
108  H.saveProperty(thisWalker.getPropertyBase()); // copy H::Observables to thisWalker::Properties
109 }
110 
111 } // namespace qmcplusplus
RealType evaluateLog(ParticleSet &P)
evalaute the log (internally gradients and laplacian) of the trial wavefunction.
PropertyContainer_t Properties
scalar properties of a walker
Definition: Walker.h:125
Base class for update methods for each step.
Definition: QMCUpdateBase.h:41
A set of walkers that are to be advanced by Metropolis Monte Carlo.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
ParticleScalar spins
internal spin variables for dynamical spin calculations
Definition: ParticleSet.h:81
QTBase::RealType RealType
Definition: Configuration.h:58
TrialWaveFunction & Psi
trial function
RealType spinMass
spin mass
Definition: QMCUpdateBase.h:75
ParticleSet::ParticleScalar deltaS
temporart storage for spin displacement
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
Collection of Local Energy Operators.
void update(bool skipSK=false)
update the internal data
ParticleSet::ParticlePos deltaR
temporary storage for random displacement
int Age
Age of this walker age is incremented when a walker is not moved after a sweep.
Definition: Walker.h:100
SOVMCUpdateAll(MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, RandomBase< FullPrecRealType > &rg)
Constructor.
ParticleScalar spins
Definition: Walker.h:117
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
std::vector< RealType > SqrtTauOverMass
sqrt(tau/Mass) per particle
void saveWalker(Walker_t &awalker)
save this to awalker
ParticlePos R
Position.
Definition: ParticleSet.h:79
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
MCWalkerConfiguration & W
walker ensemble
void advanceWalker(Walker_t &thisWalker, bool recompute) override
move a walker
void loadWalker(Walker_t &awalker, bool pbyp)
load a Walker_t to the current ParticleSet
void auxHevaluate(ParticleSet &P)
int nSubSteps
number of steps per measurement
Definition: QMCUpdateBase.h:56
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Class to represent a many-body trial wave function.
RandomBase< FullPrecRealType > & RandomGen
random number generator
Indexes
an enum denoting index of physical properties
FullPrecRealType evaluate(ParticleSet &P)
evaluate Local Energy
IndexType nAccept
counter for number of moves accepted
Definition: QMCUpdateBase.h:63
IndexType nReject
counter for number of moves rejected
Definition: QMCUpdateBase.h:65
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
bool makeMoveAllParticles(const Walker_t &awalker, const ParticlePos &deltaR, RealType dt)
move all the particles of a walker
A container class to represent a walker.
Definition: Walker.h:49
QMCHamiltonian & H
Hamiltonian.
void resetProperty(FullPrecRealType logpsi, FullPrecRealType sigN, FullPrecRealType ene)
reset the property of a walker
Definition: Walker.h:296
ParticlePos R
The configuration vector (3N-dimensional vector to store the positions of all the particles for a sin...
Definition: Walker.h:114
bool UpdatePbyP
update particle-by-particle
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)