QMCPACK
test_drift.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 #include "Particle/ParticleSet.h"
19 
20 namespace qmcplusplus
21 {
22 TEST_CASE("drift pbyp and node correction real", "[drivers][drift]")
23 {
24  const SimulationCell simulation_cell;
25  MCWalkerConfiguration elec(simulation_cell);
26 
27  elec.setName("elec");
28  std::vector<int> agroup(1);
29  agroup[0] = 1;
30  elec.create(agroup);
31 
32  ParticleSet::RealType tau = 0.5;
33  ParticleSet::RealType mass = 0.85;
34  std::vector<ParticleSet::RealType> massinv(1, 1. / mass);
35  ParticleSet::ParticlePos drift(1);
36 
37  // check from -xtot/2 to xtot/2 in step size of dx i.e. np.arange(-xtot/2,xtot/2,dx)
38  double xtot = 10.;
39  int nx = 100;
40  double gradx = -xtot / 2.;
41  double dx = xtot / nx;
42 
43  //app_log() << " begin printing" << std::endl;
44  for (int ix = 0; ix < nx; ix++)
45  {
46  elec.G[0][0] = gradx;
47  setScaledDriftPbyPandNodeCorr(tau, massinv, elec.G, drift);
48  double dval = drift[0][0];
49 
50  double scale_factor = (-1. + std::sqrt(1. + 2. * gradx * gradx * tau / mass)) / (gradx * gradx * tau / mass);
51  CHECK(dval == Approx(scale_factor * gradx * tau / mass));
52 
53  //app_log() << gradx << " " << dval << std::endl;
54  gradx += dx;
55  }
56  //app_log() << " end printing." << std::endl;
57 }
58 
59 #ifdef QMC_COMPLEX
60 TEST_CASE("drift pbyp and node correction complex", "[drivers][drift]")
61 { // basically copy and pasted from real test, except "myi"
62  const SimulationCell simulation_cell;
63  MCWalkerConfiguration elec(simulation_cell);
64 
65  elec.setName("elec");
66  std::vector<int> agroup(1);
67  agroup[0] = 1;
68  elec.create(agroup);
69 
70  ParticleSet::RealType tau = 0.5;
71  ParticleSet::RealType mass = 0.85;
72  std::vector<ParticleSet::RealType> massinv(1, 1. / mass);
73  ParticleSet::ParticlePos drift(1);
74 
75  // check from -xtot/2 to xtot/2 in step size of dx i.e. np.arange(-xtot/2,xtot/2,dx)
76  double xtot = 10.;
77  int nx = 100;
78  double gradx = -xtot / 2.;
79  double dx = xtot / nx;
80 
81  // imaginary component of wf gradient should NOT affect drift
82  std::complex<double> myi(0, 1.9);
83  for (int ix = 0; ix < nx; ix++)
84  {
85  elec.G[0][0] = gradx + myi;
86  setScaledDriftPbyPandNodeCorr(tau, massinv, elec.G, drift);
87  double dval = drift[0][0];
88 
89  double scale_factor = (-1. + std::sqrt(1. + 2. * gradx * gradx * tau / mass)) / (gradx * gradx * tau / mass);
90  CHECK(dval == Approx(scale_factor * gradx * tau / mass));
91 
92  gradx += dx;
93  }
94 }
95 #endif
96 
97 TEST_CASE("get scaled drift real", "[drivers][drift]")
98 {
99  const SimulationCell simulation_cell;
100  MCWalkerConfiguration elec(simulation_cell);
101 
102  elec.setName("elec");
103  std::vector<int> agroup(1);
104  agroup[0] = 1;
105  elec.create(agroup);
106 
107  ParticleSet::RealType tau = 0.5;
108  ParticleSet::RealType mass = 0.85;
109  std::vector<ParticleSet::RealType> massinv(1, 1. / mass);
110  ParticleSet::PosType drift;
111 
112  // check from -xtot/2 to xtot/2 in step size of dx i.e. np.arange(-xtot/2,xtot/2,dx)
113  double xtot = 10.;
114  int nx = 100;
115  double gradx = -xtot / 2.;
116  double dx = xtot / nx;
117 
118  DriftModifierUNR DM;
119  for (int ix = 0; ix < nx; ix++)
120  {
121  elec.G[0][0] = gradx;
122  DM.getDrift(tau / mass, elec.G[0], drift);
123  double dval = drift[0];
124 
125  double scale_factor = (-1. + std::sqrt(1. + 2. * gradx * gradx * tau / mass)) / (gradx * gradx * tau / mass);
126  CHECK(dval == Approx(scale_factor * gradx * tau / mass));
127 
128  gradx += dx;
129  }
130 }
131 
132 #ifdef QMC_COMPLEX
133 TEST_CASE("get scaled drift complex", "[drivers][drift]")
134 {
135  const SimulationCell simulation_cell;
136  MCWalkerConfiguration elec(simulation_cell);
137 
138  elec.setName("elec");
139  std::vector<int> agroup(1);
140  agroup[0] = 1;
141  elec.create(agroup);
142 
143  ParticleSet::RealType tau = 0.5;
144  ParticleSet::RealType mass = 0.85;
145  std::vector<ParticleSet::RealType> massinv(1, 1. / mass);
146  ParticleSet::PosType drift;
147 
148  // check from -xtot/2 to xtot/2 in step size of dx i.e. np.arange(-xtot/2,xtot/2,dx)
149  double xtot = 10.;
150  int nx = 100;
151  double gradx = -xtot / 2.;
152  double dx = xtot / nx;
153 
154  DriftModifierUNR DM;
155 
156  // imaginary component of wf gradient should NOT affect drift
157  std::complex<double> myi(0, 1.9);
158  for (int ix = 0; ix < nx; ix++)
159  {
160  elec.G[0][0] = gradx + myi;
161  DM.getDrift(tau / mass, elec.G[0], drift);
162  double dval = drift[0];
163 
164  double scale_factor = (-1. + std::sqrt(1. + 2. * gradx * gradx * tau / mass)) / (gradx * gradx * tau / mass);
165  CHECK(dval == Approx(scale_factor * gradx * tau / mass));
166 
167  gradx += dx;
168  }
169 }
170 #endif
171 
172 } // namespace qmcplusplus
void setName(const std::string &aname)
Definition: ParticleSet.h:237
A set of walkers that are to be advanced by Metropolis Monte Carlo.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
TEST_CASE("complex_helper", "[type_traits]")
void getDrift(RealType tau, const GradType &qf, PosType &drift) const final
evaluate a drift with a real force
Attaches a unit to a Vector for IO.
T setScaledDriftPbyPandNodeCorr(T tau, const ParticleAttrib< TinyVector< T1, D >> &qf, ParticleAttrib< TinyVector< T, D >> &drift)
scale drift
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
QTBase::PosType PosType
Definition: Configuration.h:61
void create(const std::vector< int > &agroup)
create grouped particles
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
Declaration of a MCWalkerConfiguration.