QMCPACK
test_vmc.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: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 
18 #include "OhmmsData/Libxml2Doc.h"
19 #include "OhmmsPETE/OhmmsMatrix.h"
20 #include "Particle/ParticleSet.h"
31 
32 
33 #include <stdio.h>
34 #include <string>
35 
36 
37 using std::string;
38 
39 namespace qmcplusplus
40 {
41 TEST_CASE("VMC Particle-by-Particle advanceWalkers", "[drivers][vmc]")
42 {
43  const SimulationCell simulation_cell;
44  ParticleSet ions(simulation_cell);
45  MCWalkerConfiguration elec(simulation_cell);
46 
47  ions.setName("ion");
48  ions.create({1});
49  ions.R[0] = {0.0, 0.0, 0.0};
50  elec.setName("elec");
51  std::vector<int> agroup(1);
52  agroup[0] = 2;
53  elec.create(agroup);
54  elec.R[0] = {1.0, 0.0, 0.0};
55  elec.R[1] = {0.0, 0.0, 1.0};
56  elec.createWalkers(1);
57 
58  SpeciesSet& tspecies = elec.getSpeciesSet();
59  int upIdx = tspecies.addSpecies("u");
60  int chargeIdx = tspecies.addAttribute("charge");
61  int massIdx = tspecies.addAttribute("mass");
62  tspecies(chargeIdx, upIdx) = -1;
63  tspecies(massIdx, upIdx) = 1.0;
64 
65  elec.addTable(ions);
66  elec.update();
67 
68  RuntimeOptions runtime_options;
69  TrialWaveFunction psi(runtime_options);
70  psi.addComponent(std::make_unique<ConstantOrbital>());
71  psi.registerData(elec, elec[0]->DataSet);
72  elec[0]->DataSet.allocate();
73 
74  FakeRandom rg;
75 
77  h.addOperator(std::make_unique<BareKineticEnergy>(elec, psi), "Kinetic");
78  h.addObservables(elec); // get double free error on 'h.Observables' w/o this
79 
80  elec.resetWalkerProperty(); // get memory corruption w/o this
81 
82  VMCUpdatePbyP vmc(elec, psi, h, rg);
84  SimpleFixedNodeBranch branch(0.1, 1);
85  TraceManager TM;
87  vmc.resetRun(&branch, &EM, &TM, &DM);
88  vmc.startBlock(1);
89 
90  VMCUpdatePbyP::WalkerIter_t begin = elec.begin();
91  VMCUpdatePbyP::WalkerIter_t end = elec.end();
92  vmc.advanceWalkers(begin, end, true);
93 
94  // With the constant wavefunction, no moves should be rejected
95  REQUIRE(vmc.nReject == 0);
96  REQUIRE(vmc.nAccept == 2);
97 
98  // Each electron moved sqrt(tau)*gaussian_rng()
99  // See ParticleBase/tests/test_random_seq.cpp for the gaussian random numbers
100  // Values from diffuse.py
101  CHECK(elec.R[0][0] == Approx(0.627670258894097));
102  CHECK(elec.R[0][1] == Approx(0.0));
103  CHECK(elec.R[0][2] == Approx(-0.372329741105903));
104 
105  CHECK(elec.R[1][0] == Approx(0.0));
106  CHECK(elec.R[1][1] == Approx(-0.372329741105903));
107  CHECK(elec.R[1][2] == Approx(1.0));
108 }
109 } // namespace qmcplusplus
int addObservables(ParticleSet &P)
add each term to the PropertyList for averages
void setName(const std::string &aname)
Definition: ParticleSet.h:237
A set of walkers that are to be advanced by Metropolis Monte Carlo.
MCWalkerConfiguration::iterator WalkerIter_t
Definition: QMCUpdateBase.h:45
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void addOperator(std::unique_ptr< OperatorBase > &&h, const std::string &aname, bool physical=true)
add an operator
TEST_CASE("complex_helper", "[type_traits]")
Collection of Local Energy Operators.
void update(bool skipSK=false)
update the internal data
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
Definition: SpeciesSet.cpp:45
void startBlock(int steps)
prepare to start a block
void resetRun(BranchEngineType *brancher, EstimatorManagerBase *est, TraceManager *traces, const DriftModifierBase *driftmodifer)
reset the QMCUpdateBase parameters
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Manages the state of QMC sections and handles population control for DMCs.
REQUIRE(std::filesystem::exists(filename))
Implements the VMC algorithm using particle-by-particle move.
Definition: VMCUpdatePbyP.h:25
void registerData(ParticleSet &P, WFBufferType &buf)
register all the wavefunction components in buffer.
ParticlePos R
Position.
Definition: ParticleSet.h:79
Manager class of scalar estimators.
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
Class to manage a set of ScalarEstimators.
Declaration of a TrialWaveFunction.
Class to represent a many-body trial wave function.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Declaration of WaveFunctionComponent.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
IndexType nAccept
counter for number of moves accepted
Definition: QMCUpdateBase.h:63
IndexType nReject
counter for number of moves rejected
Definition: QMCUpdateBase.h:65
void createWalkers(int numWalkers)
create numWalkers Walkers
virtual void advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool recompute)
advance walkers executed at each step
iterator end()
return the last iterator, [begin(), end())
Declare a global Random Number Generator.
Declaration of a MCWalkerConfiguration.
void addComponent(std::unique_ptr< WaveFunctionComponent > &&aterm)
add a WaveFunctionComponent
Declaration of ParticleSetPool.
void resetWalkerProperty(int ncopy=1)
reset the Property container of all the walkers
iterator begin()
return the first iterator