QMCPACK
test_ConstantSPOSet.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) 2023 QMCPACK developers.
6 //
7 // File developed by: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
8 //
9 // File created by: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 #include "Configuration.h"
18 namespace qmcplusplus
19 {
20 //Ray: Figure out how to template me on value type.
21 TEST_CASE("ConstantSPOSet", "[wavefunction]")
22 {
23  //For now, do a small square case.
24  const int nelec = 2;
25  const int norb = 2;
27  using Real = WF::Real;
28  using Value = WF::Value;
29  using Grad = WF::Grad;
30  using ValueVector = Vector<Value>;
31  using GradVector = Vector<Grad>;
32  using ValueMatrix = Matrix<Value>;
33  using GradMatrix = Matrix<Grad>;
34 
35  ValueVector row0{Value(0.92387953), Value(0.92387953)};
36  ValueVector row1{Value(0.29131988), Value(0.81078057)};
37 
38  GradVector grow0{Grad({-2.22222, -1.11111, 0.33333}), Grad({8.795388, -0.816057, -0.9238793})};
39  GradVector grow1{Grad({2.22222, 1.11111, -0.33333}), Grad({-8.795388, 0.816057, 0.9238793})};
40 
41  ValueVector lrow0{Value(-0.2234545), Value(0.72340234)};
42  ValueVector lrow1{Value(-12.291810), Value(6.879057)};
43 
44 
45  ValueMatrix spomat;
46  GradMatrix gradspomat;
47  ValueMatrix laplspomat;
48 
49  spomat.resize(nelec, norb);
50  gradspomat.resize(nelec, norb);
51  laplspomat.resize(nelec, norb);
52 
53  for (int iorb = 0; iorb < norb; iorb++)
54  {
55  spomat(0, iorb) = row0[iorb];
56  spomat(1, iorb) = row1[iorb];
57 
58  gradspomat(0, iorb) = grow0[iorb];
59  gradspomat(1, iorb) = grow1[iorb];
60 
61  laplspomat(0, iorb) = lrow0[iorb];
62  laplspomat(1, iorb) = lrow1[iorb];
63  }
64 
65 
66  const SimulationCell simulation_cell;
67  ParticleSet elec(simulation_cell);
68 
69  elec.create({nelec});
70 
71  ValueVector psiV = {0.0, 0.0};
72  ValueVector psiL = {0.0, 0.0};
73  GradVector psiG;
74  psiG.resize(norb);
75 
76  //Test of value only constructor.
77  auto sposet = std::make_unique<ConstantSPOSet>("constant_spo", nelec, norb);
78  sposet->setRefVals(spomat);
79  sposet->setRefEGrads(gradspomat);
80  sposet->setRefELapls(laplspomat);
81 
82  sposet->evaluateValue(elec, 0, psiV);
83 
84  CHECK(psiV[0] == row0[0]);
85  CHECK(psiV[1] == row0[1]);
86 
87 
88  psiV = 0.0;
89 
90  sposet->evaluateValue(elec, 1, psiV);
91  CHECK(psiV[0] == row1[0]);
92  CHECK(psiV[1] == row1[1]);
93 
94  psiV = 0.0;
95 
96  sposet->evaluateVGL(elec, 1, psiV, psiG, psiL);
97 
98  for (int iorb = 0; iorb < norb; iorb++)
99  {
100  CHECK(psiV[iorb] == row1[iorb]);
101  CHECK(psiL[iorb] == lrow1[iorb]);
102 
103  for (int idim = 0; idim < OHMMS_DIM; idim++)
104  CHECK(psiG[iorb][idim] == grow1[iorb][idim]);
105  }
106  //Test of evaluate_notranspose.
107  ValueMatrix phimat, lphimat;
108  GradMatrix gphimat;
109  phimat.resize(nelec, norb);
110  gphimat.resize(nelec, norb);
111  lphimat.resize(nelec, norb);
112 
113  const int first_index = 0; //Only 2 electrons in this case.
114  const int last_index = 2;
115  sposet->evaluate_notranspose(elec, first_index, last_index, phimat, gphimat, lphimat);
116 
117  auto check = checkMatrix(phimat, spomat);
118  CHECKED_ELSE(check.result) { FAIL(check.result_message); }
119  check = checkMatrix(lphimat, laplspomat);
120  CHECKED_ELSE(check.result) { FAIL(check.result_message); }
121 
122  //Test of makeClone()
123  auto sposet_vgl2 = sposet->makeClone();
124  phimat = 0.0;
125  gphimat = 0.0;
126  lphimat = 0.0;
127 
128  sposet_vgl2->evaluate_notranspose(elec, first_index, last_index, phimat, gphimat, lphimat);
129 
130  check = checkMatrix(phimat, spomat);
131  CHECKED_ELSE(check.result) { FAIL(check.result_message); }
132  check = checkMatrix(lphimat, laplspomat);
133  CHECKED_ELSE(check.result) { FAIL(check.result_message); }
134 
135  //Lastly, check if name is correct.
136  std::string myname = sposet_vgl2->getClassName();
137  std::string targetstring("ConstantSPOSet");
138  CHECK(myname == targetstring);
139 }
140 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Consistent way to get the set of types used in the QMCWaveFunction module, without resorting to ifdef...
CHECKED_ELSE(check_matrix_result.result)
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
OrbitalSetTraits< ValueType >::ValueVector ValueVector
#define OHMMS_DIM
Definition: config.h:64
ForceBase::Real Real
Definition: ForceBase.cpp:26
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void create(const std::vector< int > &agroup)
create grouped particles
CheckMatrixResult checkMatrix(M1 &a_mat, M2 &b_mat, const bool check_all=false, std::optional< const double > eps=std::nullopt)
This function checks equality a_mat and b_mat elements M1, M2 need to have their element type declare...
Definition: checkMatrix.hpp:63
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))