QMCPACK
test_einset.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 "OhmmsData/Libxml2Doc.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "Particle/ParticleSet.h"
22 #include <ResourceCollection.h>
23 
24 #include <stdio.h>
25 #include <string>
26 #include <limits>
27 
28 using std::string;
29 
30 namespace qmcplusplus
31 {
32 TEST_CASE("Einspline SPO from HDF diamond_1x1x1", "[wavefunction]")
33 {
35 
37  // monoO
38  // lattice.R(0,0) = {5.10509515, -3.23993545, 0.0, 5.10509515, 3.23993545, 0.0, -6.49690625, 0.0, 7.08268015};
39 
40  // diamondC_1x1x1
41  lattice.R = {3.37316115, 3.37316115, 0.0, 0.0, 3.37316115, 3.37316115, 3.37316115, 0.0, 3.37316115};
42 
45  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
46  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
47  ParticleSet& ions_(*ions_uptr);
48  ParticleSet& elec_(*elec_uptr);
49 
50  ions_.setName("ion");
51  ptcl.addParticleSet(std::move(ions_uptr));
52  ions_.create({2});
53  ions_.R[0] = {0.0, 0.0, 0.0};
54  ions_.R[1] = {1.68658058, 1.68658058, 1.68658058};
55 
56 
57  elec_.setName("elec");
58  ptcl.addParticleSet(std::move(elec_uptr));
59  elec_.create({2});
60  elec_.R[0] = {0.0, 0.0, 0.0};
61  elec_.R[1] = {0.0, 1.0, 0.0};
62 
63  SpeciesSet& tspecies = elec_.getSpeciesSet();
64  int upIdx = tspecies.addSpecies("u");
65  int chargeIdx = tspecies.addAttribute("charge");
66  tspecies(chargeIdx, upIdx) = -1;
67 
68  //diamondC_1x1x1
69  // add save_coefs="yes" to create an HDF file of spline coefficients for the eval_bspline_spo.py script
70  const char* particles = R"(<tmp>
71 <determinantset type="einspline" href="diamondC_1x1x1.pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float" size="8"/>
72 </tmp>)";
73 
75  bool okay = doc.parseFromString(particles);
76  REQUIRE(okay);
77 
78  xmlNodePtr root = doc.getRoot();
79 
80  xmlNodePtr ein1 = xmlFirstElementChild(root);
81 
82  EinsplineSetBuilder einSet(elec_, ptcl.getPool(), c, ein1);
83  auto spo = einSet.createSPOSetFromXML(ein1);
84  REQUIRE(spo);
85 
86  // Test the case where the number of psi values is not the orbital set size
87  // or the number of electrons/2
88  const int psi_size = 3;
89  SPOSet::ValueMatrix psiM(elec_.R.size(), psi_size);
90  SPOSet::GradMatrix dpsiM(elec_.R.size(), psi_size);
91  SPOSet::ValueMatrix d2psiM(elec_.R.size(), psi_size);
92  spo->evaluate_notranspose(elec_, 0, elec_.R.size(), psiM, dpsiM, d2psiM);
93 
94  // value
95  CHECK(std::real(psiM[0][0]) == Approx(-0.42546836868));
96  CHECK(std::real(psiM[0][1]) == Approx(0.0));
97  CHECK(std::real(psiM[1][0]) == Approx(-0.8886948824));
98  CHECK(std::real(psiM[1][1]) == Approx(1.419412370359));
99  // grad
100  CHECK(std::real(dpsiM[1][0][0]) == Approx(-0.0000183403));
101  CHECK(std::real(dpsiM[1][0][1]) == Approx(0.1655139178));
102  CHECK(std::real(dpsiM[1][0][2]) == Approx(-0.0000193077));
103  CHECK(std::real(dpsiM[1][1][0]) == Approx(-1.3131694794));
104  CHECK(std::real(dpsiM[1][1][1]) == Approx(-1.1174004078));
105  CHECK(std::real(dpsiM[1][1][2]) == Approx(-0.8462534547));
106  // lapl
107  CHECK(std::real(d2psiM[1][0]) == Approx(1.3313053846));
108  CHECK(std::real(d2psiM[1][1]) == Approx(-4.712583065));
109 
110  // for vgh
111  SPOSet::ValueVector psiV(psiM[1], psi_size);
112  SPOSet::GradVector dpsiV(dpsiM[1], psi_size);
113  SPOSet::HessVector ddpsiV(psi_size);
114  spo->evaluateVGH(elec_, 1, psiV, dpsiV, ddpsiV);
115 
116  // Catch default is 100*(float epsilson)
117  double eps = 2000 * std::numeric_limits<float>::epsilon();
118  //hess
119  CHECK(std::real(ddpsiV[1](0, 0)) == Approx(-2.3160984034));
120  CHECK(std::real(ddpsiV[1](0, 1)) == Approx(1.8089479397));
121  CHECK(std::real(ddpsiV[1](0, 2)) == Approx(0.5608575749));
122  CHECK(std::real(ddpsiV[1](1, 0)) == Approx(1.8089479397));
123  CHECK(std::real(ddpsiV[1](1, 1)) == Approx(-0.07996207476).epsilon(eps));
124  CHECK(std::real(ddpsiV[1](1, 2)) == Approx(0.5237969314));
125  CHECK(std::real(ddpsiV[1](2, 0)) == Approx(0.5608575749));
126  CHECK(std::real(ddpsiV[1](2, 1)) == Approx(0.5237969314));
127  CHECK(std::real(ddpsiV[1](2, 2)) == Approx(-2.316497764));
128 
129  SPOSet::HessMatrix hesspsiV(elec_.R.size(), psi_size);
130  SPOSet::GGGMatrix d3psiV(elec_.R.size(), psi_size);
131  spo->evaluate_notranspose(elec_, 0, elec_.R.size(), psiM, dpsiM, hesspsiV, d3psiV);
132 
133  //The reference values for grad_grad_grad_psi.
134  /*
135  d3psiV(1,0)[0][0]=(0.046337127685546875,-0.046337127685546875)
136  d3psiV(1,0)[0][1]=(1.1755813360214233,-1.1755813360214233)
137  d3psiV(1,0)[0][2]=(0.066015571355819702,-0.066015541553497314)
138  d3psiV(1,0)[0][4]=(0.041470438241958618,-0.041470438241958618)
139  d3psiV(1,0)[0][5]=(-0.51674127578735352,0.51674127578735352)
140  d3psiV(1,0)[0][8]=(0.065953642129898071,-0.065953642129898071)
141  d3psiV(1,0)[1][4]=(-4.8771157264709473,4.8771157264709473)
142  d3psiV(1,0)[1][5]=(0.041532635688781738,-0.041532605886459351)
143  d3psiV(1,0)[1][8]=(1.1755810976028442,-1.1755810976028442)
144  d3psiV(1,0)[2][8]=(0.046399354934692383,-0.046399354934692383)
145 
146  d3psiV(1,1)[0][0]=(6.7155771255493164,-7.5906991958618164)
147  d3psiV(1,1)[0][1]=(5.545051097869873,-5.0280308723449707)
148  d3psiV(1,1)[0][2]=(0.98297119140625,-0.50021600723266602)
149  d3psiV(1,1)[0][4]=(-3.1704092025756836,3.8900821208953857)
150  d3psiV(1,1)[0][5]=(-1.9537661075592041,1.7758266925811768)
151  d3psiV(1,1)[0][8]=(1.9305641651153564,-2.1480715274810791)
152  d3psiV(1,1)[1][4]=(3.605137825012207,-3.2767453193664551)
153  d3psiV(1,1)[1][5]=(-0.73825764656066895,-0.33745908737182617)
154  d3psiV(1,1)[1][8]=(5.5741839408874512,-5.0784988403320312)
155  d3psiV(1,1)[2][8]=(3.131234884262085,-1.3596141338348389)
156 */
157 
158 #if 0 //Enable when finite precision issue on Rhea is found.
159  CHECK(std::real(d3psiV(1,0)[0][0] ) == Approx(0.0463371276));
160  CHECK(std::real(d3psiV(1,0)[0][1] ) == Approx(1.1755813360));
161  CHECK(std::real(d3psiV(1,0)[0][2] ) == Approx(0.0660155713));
162  CHECK(std::real(d3psiV(1,0)[0][4] ) == Approx(0.0414704382));
163  CHECK(std::real(d3psiV(1,0)[0][5] ) == Approx(-0.5167412758));
164  CHECK(std::real(d3psiV(1,0)[0][8] ) == Approx(0.0659536421));
165  CHECK(std::real(d3psiV(1,0)[1][4] ) == Approx(-4.8771157264));
166  CHECK(std::real(d3psiV(1,0)[1][5] ) == Approx(0.0415326356));
167  CHECK(std::real(d3psiV(1,0)[1][8] ) == Approx(1.1755810976));
168  CHECK(std::real(d3psiV(1,0)[2][8] ) == Approx(0.0463993549));
169 
170  CHECK(std::real(d3psiV(1,1)[0][0] ) == Approx(6.7155771255));
171  CHECK(std::real(d3psiV(1,1)[0][1] ) == Approx(5.5450510978));
172  CHECK(std::real(d3psiV(1,1)[0][2] ) == Approx(0.9829711914));
173  CHECK(std::real(d3psiV(1,1)[0][4] ) == Approx(-3.1704092025));
174  CHECK(std::real(d3psiV(1,1)[0][5] ) == Approx(-1.9537661075));
175  CHECK(std::real(d3psiV(1,1)[0][8] ) == Approx(1.9305641651));
176  CHECK(std::real(d3psiV(1,1)[1][4] ) == Approx(3.6051378250));
177  CHECK(std::real(d3psiV(1,1)[1][5] ) == Approx(-0.7382576465));
178  CHECK(std::real(d3psiV(1,1)[1][8] ) == Approx(5.5741839408));
179  CHECK(std::real(d3psiV(1,1)[2][8] ) == Approx(3.1312348842));
180 #endif
181 
182  // Test the batched interface
183  ParticleSet elec_2(elec_);
184  // interchange positions
185  elec_2.R[0] = elec_.R[1];
186  elec_2.R[1] = elec_.R[0];
187  RefVectorWithLeader<ParticleSet> p_list(elec_);
188  p_list.push_back(elec_);
189  p_list.push_back(elec_2);
190 
191  std::unique_ptr<SPOSet> spo_2(spo->makeClone());
192  RefVectorWithLeader<SPOSet> spo_list(*spo);
193  spo_list.push_back(*spo);
194  spo_list.push_back(*spo_2);
195 
196  ResourceCollection pset_res("test_pset_res");
197  ResourceCollection spo_res("test_spo_res");
198 
199  elec_.createResource(pset_res);
200  spo->createResource(spo_res);
201 
202  ResourceCollectionTeamLock<ParticleSet> mw_pset_lock(pset_res, p_list);
203  ResourceCollectionTeamLock<SPOSet> mw_sposet_lock(spo_res, spo_list);
204 
205  const int ne = elec_.R.size();
206  SPOSet::ValueMatrix psi(ne, psi_size);
207  SPOSet::GradMatrix dpsi(ne, psi_size);
208  SPOSet::ValueMatrix d2psi(ne, psi_size);
209  SPOSet::ValueMatrix psi_2(ne, psi_size);
210  SPOSet::GradMatrix dpsi_2(ne, psi_size);
211  SPOSet::ValueMatrix d2psi_2(ne, psi_size);
212 
214  RefVector<SPOSet::GradMatrix> dpsi_v_list;
215  RefVector<SPOSet::ValueMatrix> d2psi_v_list;
216 
217  psi_v_list.push_back(psi);
218  psi_v_list.push_back(psi_2);
219  dpsi_v_list.push_back(dpsi);
220  dpsi_v_list.push_back(dpsi_2);
221  d2psi_v_list.push_back(d2psi);
222  d2psi_v_list.push_back(d2psi_2);
223  spo->mw_evaluate_notranspose(spo_list, p_list, 0, elec_.R.size(), psi_v_list, dpsi_v_list, d2psi_v_list);
224 
225  CHECK(std::real(psi_v_list[0].get()[0][0]) == Approx(-0.42546836868));
226  CHECK(std::real(psi_v_list[0].get()[1][0]) == Approx(-0.8886948824));
227  // Second particle set had particle positions flipped
228  CHECK(std::real(psi_v_list[1].get()[0][0]) == Approx(-0.8886948824));
229  CHECK(std::real(psi_v_list[1].get()[1][0]) == Approx(-0.42546836868));
230 
231 #if 0
232  // Dump values of the orbitals
233  int orbSize= spo->getOrbitalSetSize();
234  int basisSize= spo->getBasisSetSize();
235  printf("orb size = %d basis set size = %d\n",orbSize, basisSize);
236 
237  FILE *fspo = fopen("spo.dat", "w");
238  for (int ix = 0; ix < 30; ix++) {
239  for (int iy = 0; iy < 30; iy++) {
240  for (int iz = 0; iz < 30; iz++) {
241  double x = 0.1*ix - 1.5;
242  double y = 0.1*iy - 1.5;
243  double z = 0.1*iz - 1.5;
244  elec_.R[0] = {x, y, z};
245  elec_.update();
246  SPOSet::ValueVector orbs(orbSize);
247  spo->evaluate(elec_, 0, orbs);
248  fprintf(fspo, "%g %g %g",x,y,z);
249  for (int j = 0; j < orbSize; j++) {
250  fprintf(fspo, " %g ",orbs[j]);
251  }
252  fprintf(fspo, "\n");
253  }
254  }
255  }
256  fclose(fspo);
257 
258 #endif
259 }
260 
261 TEST_CASE("Einspline SPO from HDF diamond_2x1x1 5 electrons", "[wavefunction]")
262 {
264 
266  // diamondC_2x1x1
267  lattice.R = {6.7463223, 6.7463223, 0.0, 0.0, 3.37316115, 3.37316115, 3.37316115, 0.0, 3.37316115};
268 
271  auto ions_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
272  auto elec_uptr = std::make_unique<ParticleSet>(ptcl.getSimulationCell());
273  ParticleSet& ions_(*ions_uptr);
274  ParticleSet& elec_(*elec_uptr);
275 
276  ions_.setName("ion");
277  ptcl.addParticleSet(std::move(ions_uptr));
278  ions_.create({4});
279  ions_.R[0] = {0.0, 0.0, 0.0};
280  ions_.R[1] = {1.68658058, 1.68658058, 1.68658058};
281  ions_.R[2] = {3.37316115, 3.37316115, 0.0};
282  ions_.R[3] = {5.05974173, 5.05974173, 1.68658058};
283 
284 
285  elec_.setName("elec");
286  ptcl.addParticleSet(std::move(elec_uptr));
287  elec_.create({5});
288  elec_.R[0] = {0.0, 0.0, 0.0};
289  elec_.R[1] = {0.0, 1.0, 0.0};
290  elec_.R[2] = {0.0, 1.1, 0.0};
291  elec_.R[3] = {0.0, 1.2, 0.0};
292  elec_.R[4] = {0.0, 1.3, 0.0};
293 
294  SpeciesSet& tspecies = elec_.getSpeciesSet();
295  int upIdx = tspecies.addSpecies("u");
296  int chargeIdx = tspecies.addAttribute("charge");
297  tspecies(chargeIdx, upIdx) = -1;
298 
299  //diamondC_2x1x1
300  const char* particles = R"(<tmp>
301 <determinantset type="einspline" href="diamondC_2x1x1.pwscf.h5" tilematrix="2 0 0 0 1 0 0 0 1" twistnum="0" source="ion" meshfactor="1.0" precision="float" size="5"/>
302 </tmp>
303 )";
304 
306  bool okay = doc.parseFromString(particles);
307  REQUIRE(okay);
308 
309  xmlNodePtr root = doc.getRoot();
310 
311  xmlNodePtr ein1 = xmlFirstElementChild(root);
312 
313  EinsplineSetBuilder einSet(elec_, ptcl.getPool(), c, ein1);
314  auto spo = einSet.createSPOSetFromXML(ein1);
315  REQUIRE(spo);
316 
317  // for vgl
318  SPOSet::ValueMatrix psiM(elec_.R.size(), spo->getOrbitalSetSize());
319  SPOSet::GradMatrix dpsiM(elec_.R.size(), spo->getOrbitalSetSize());
320  SPOSet::ValueMatrix d2psiM(elec_.R.size(), spo->getOrbitalSetSize());
321  spo->evaluate_notranspose(elec_, 0, elec_.R.size(), psiM, dpsiM, d2psiM);
322 
323  // real part
324  // due to the different ordering of bands skip the tests on CUDA+Real builds
325  // checking evaluations, reference values are not independently generated.
326  // value
327  CHECK(std::real(psiM[1][0]) == Approx(0.9008999467));
328  CHECK(std::real(psiM[1][1]) == Approx(1.2383049726));
329  // grad
330  CHECK(std::real(dpsiM[1][0][0]) == Approx(0.0025820041));
331  CHECK(std::real(dpsiM[1][0][1]) == Approx(-0.1880052537));
332  CHECK(std::real(dpsiM[1][0][2]) == Approx(-0.0025404284));
333  CHECK(std::real(dpsiM[1][1][0]) == Approx(0.1069662273));
334  CHECK(std::real(dpsiM[1][1][1]) == Approx(-0.4364597797));
335  CHECK(std::real(dpsiM[1][1][2]) == Approx(-0.106951952));
336  // lapl
337  CHECK(std::real(d2psiM[1][0]) == Approx(-1.3757134676));
338  CHECK(std::real(d2psiM[1][1]) == Approx(-2.4803137779));
339 
340 #if defined(QMC_COMPLEX)
341  // imaginary part
342  // value
343  CHECK(std::imag(psiM[1][0]) == Approx(0.9008999467));
344  CHECK(std::imag(psiM[1][1]) == Approx(1.2383049726));
345  // grad
346  CHECK(std::imag(dpsiM[1][0][0]) == Approx(0.0025820041));
347  CHECK(std::imag(dpsiM[1][0][1]) == Approx(-0.1880052537));
348  CHECK(std::imag(dpsiM[1][0][2]) == Approx(-0.0025404284));
349  CHECK(std::imag(dpsiM[1][1][0]) == Approx(0.1069453433));
350  CHECK(std::imag(dpsiM[1][1][1]) == Approx(-0.43649593));
351  CHECK(std::imag(dpsiM[1][1][2]) == Approx(-0.1069145575));
352  // lapl
353  CHECK(std::imag(d2psiM[1][0]) == Approx(-1.3757134676));
354  CHECK(std::imag(d2psiM[1][1]) == Approx(-2.4919104576));
355 #endif
356 
357  // test batched interfaces
358  ParticleSet elec_2(elec_);
359  // interchange positions
360  elec_2.R[0] = elec_.R[1];
361  elec_2.R[1] = elec_.R[0];
362  RefVectorWithLeader<ParticleSet> p_list(elec_);
363  p_list.push_back(elec_);
364  p_list.push_back(elec_2);
365 
366  std::unique_ptr<SPOSet> spo_2(spo->makeClone());
367  RefVectorWithLeader<SPOSet> spo_list(*spo);
368  spo_list.push_back(*spo);
369  spo_list.push_back(*spo_2);
370 
371  ResourceCollection pset_res("test_pset_res");
372  ResourceCollection spo_res("test_spo_res");
373 
374  elec_.createResource(pset_res);
375  spo->createResource(spo_res);
376 
377  ResourceCollectionTeamLock<ParticleSet> mw_pset_lock(pset_res, p_list);
378  ResourceCollectionTeamLock<SPOSet> mw_sposet_lock(spo_res, spo_list);
379 
380  SPOSet::ValueVector psi(spo->getOrbitalSetSize());
381  SPOSet::GradVector dpsi(spo->getOrbitalSetSize());
382  SPOSet::ValueVector d2psi(spo->getOrbitalSetSize());
383  SPOSet::ValueVector psi_2(spo->getOrbitalSetSize());
384  SPOSet::GradVector dpsi_2(spo->getOrbitalSetSize());
385  SPOSet::ValueVector d2psi_2(spo->getOrbitalSetSize());
386 
388  RefVector<SPOSet::GradVector> dpsi_v_list;
389  RefVector<SPOSet::ValueVector> d2psi_v_list;
390 
391  psi_v_list.push_back(psi);
392  psi_v_list.push_back(psi_2);
393  dpsi_v_list.push_back(dpsi);
394  dpsi_v_list.push_back(dpsi_2);
395  d2psi_v_list.push_back(d2psi);
396  d2psi_v_list.push_back(d2psi_2);
397 
398  spo->mw_evaluateVGL(spo_list, p_list, 0, psi_v_list, dpsi_v_list, d2psi_v_list);
399  // real part
400  // due to the different ordering of bands skip the tests on CUDA+Real builds
401  // checking evaluations, reference values are not independently generated.
402  // value
403  CHECK(std::real(psi_v_list[1].get()[0]) == Approx(0.9008999467));
404  CHECK(std::real(psi_v_list[1].get()[1]) == Approx(1.2383049726));
405  // grad
406  CHECK(std::real(dpsi_v_list[1].get()[0][0]) == Approx(0.0025820041));
407  CHECK(std::real(dpsi_v_list[1].get()[0][1]) == Approx(-0.1880052537));
408  CHECK(std::real(dpsi_v_list[1].get()[0][2]) == Approx(-0.0025404284));
409  CHECK(std::real(dpsi_v_list[1].get()[1][0]) == Approx(0.1069662273));
410  CHECK(std::real(dpsi_v_list[1].get()[1][1]) == Approx(-0.4364597797));
411  CHECK(std::real(dpsi_v_list[1].get()[1][2]) == Approx(-0.106951952));
412  // lapl
413  CHECK(std::real(d2psi_v_list[1].get()[0]) == Approx(-1.3757134676));
414  CHECK(std::real(d2psi_v_list[1].get()[1]) == Approx(-2.4803137779));
415 
416 #if defined(QMC_COMPLEX)
417  // imaginary part
418  // value
419  CHECK(std::imag(psi_v_list[1].get()[0]) == Approx(0.9008999467));
420  CHECK(std::imag(psi_v_list[1].get()[1]) == Approx(1.2383049726));
421  // grad
422  CHECK(std::imag(dpsi_v_list[1].get()[0][0]) == Approx(0.0025820041));
423  CHECK(std::imag(dpsi_v_list[1].get()[0][1]) == Approx(-0.1880052537));
424  CHECK(std::imag(dpsi_v_list[1].get()[0][2]) == Approx(-0.0025404284));
425  CHECK(std::imag(dpsi_v_list[1].get()[1][0]) == Approx(0.1069453433));
426  CHECK(std::imag(dpsi_v_list[1].get()[1][1]) == Approx(-0.43649593));
427  CHECK(std::imag(dpsi_v_list[1].get()[1][2]) == Approx(-0.1069145575));
428  // lapl
429  CHECK(std::imag(d2psi_v_list[1].get()[0]) == Approx(-1.3757134676));
430  CHECK(std::imag(d2psi_v_list[1].get()[1]) == Approx(-2.4919104576));
431 #endif
432 
433  const size_t nw = 2;
434  std::vector<SPOSet::ValueType> ratio_v(nw);
435  std::vector<SPOSet::GradType> grads_v(nw);
436 
438  inv_row = {0.1, 0.2, 0.3, 0.4, 0.5};
439  inv_row.updateTo();
440 
441  std::vector<const SPOSet::ValueType*> inv_row_ptr(nw, inv_row.device_data());
442 
443  SPOSet::OffloadMWVGLArray phi_vgl_v;
444  phi_vgl_v.resize(QMCTraits::DIM_VGL, nw, 5);
445  spo->mw_evaluateVGLandDetRatioGrads(spo_list, p_list, 0, inv_row_ptr, phi_vgl_v, ratio_v, grads_v);
446 #if !defined(QMC_COMPLEX)
447  CHECK(std::real(ratio_v[0]) == Approx(0.2365307168));
448  CHECK(std::real(grads_v[0][0]) == Approx(-5.4095164399));
449  CHECK(std::real(grads_v[0][1]) == Approx(14.37990087));
450  CHECK(std::real(grads_v[0][2]) == Approx(16.9374788259));
451  CHECK(std::real(ratio_v[1]) == Approx(1.0560744941));
452  CHECK(std::real(grads_v[1][0]) == Approx(-0.0863436466));
453  CHECK(std::real(grads_v[1][1]) == Approx(-0.7499371447));
454  CHECK(std::real(grads_v[1][2]) == Approx(0.8570534314));
455 #endif
456 }
457 
458 TEST_CASE("EinsplineSetBuilder CheckLattice", "[wavefunction]")
459 {
461 
463  lattice.R = 0.0;
464  lattice.R(0, 0) = 1.0;
465  lattice.R(1, 1) = 1.0;
466  lattice.R(2, 2) = 1.0;
467 
468  const SimulationCell simulation_cell(lattice);
469  auto elec_ptr = std::make_unique<ParticleSet>(simulation_cell);
470  auto& elec(*elec_ptr);
471 
472  elec.setName("elec");
473  std::vector<int> agroup(2);
474  agroup[0] = 1;
475  agroup[1] = 1;
476  elec.create(agroup);
477  elec.R[0] = {0.0, 0.0, 0.0};
478  elec.R[1] = {0.0, 1.0, 0.0};
479 
481  ptcl_map.emplace(elec_ptr->getName(), std::move(elec_ptr));
482 
483  xmlNodePtr cur = NULL;
484  EinsplineSetBuilder esb(elec, ptcl_map, c, cur);
485 
486  esb.SuperLattice = 0.0;
487  esb.SuperLattice(0, 0) = 1.0;
488  esb.SuperLattice(1, 1) = 1.0;
489  esb.SuperLattice(2, 2) = 1.0;
490 
491  REQUIRE(esb.CheckLattice());
492 
493  esb.SuperLattice(0, 0) = 1.1;
494  REQUIRE_FALSE(esb.CheckLattice());
495 }
496 
497 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
OrbitalSetTraits< ValueType >::HessVector HessVector
Definition: SPOSet.h:53
void setName(const std::string &aname)
Definition: ParticleSet.h:237
void setSimulationCell(const SimulationCell &simulation_cell)
set simulation cell
class that handles xmlDoc
Definition: Libxml2Doc.h:76
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
pointer device_data()
Return the device_ptr matching X if this is a vector attached or owning dual space memory...
Definition: OhmmsVector.h:245
void addParticleSet(std::unique_ptr< ParticleSet > &&p)
add a ParticleSet* to the pool with its ownership transferred ParticleSet built outside the ParticleS...
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
Builder class for einspline-based SPOSet objects.
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
Derives EinsplineSetBuilder.
void update(bool skipSK=false)
update the internal data
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
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
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
Wrapping information on parallelism.
Definition: Communicate.h:68
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
size_type size() const
return the current size
Definition: OhmmsVector.h:162
REQUIRE(std::filesystem::exists(filename))
Manage a collection of ParticleSet objects.
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
std::map< std::string, const std::unique_ptr< ParticleSet > > PSetMap
ParticlePos R
Position.
Definition: ParticleSet.h:79
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
std::vector< std::reference_wrapper< T > > RefVector
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Tensor< double, OHMMS_DIM > SuperLattice
handles acquire/release resource by the consumer (RefVectorWithLeader type).
Declaration of WaveFunctionComponent.
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
const PoolType & getPool() const
get the Pool object
void updateTo(size_type size=0, std::ptrdiff_t offset=0)
Definition: OhmmsVector.h:263
OrbitalSetTraits< ValueType >::GradHessMatrix GGGMatrix
Definition: SPOSet.h:56
std::unique_ptr< SPOSet > createSPOSetFromXML(xmlNodePtr cur) override
initialize the Antisymmetric wave function for electrons
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
const auto & getSimulationCell() const
get simulation cell
Declaration of ParticleSetPool.
OrbitalSetTraits< ValueType >::HessMatrix HessMatrix
Definition: SPOSet.h:54