QMCPACK
test_density_estimator.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: William F Godoy, godoywf@ornl.gov, Oak Ridge National Laboratory
8 // File created by: William F Godoy, godoywf@ornl.gov, Oak Ridge National Laboratory
9 //////////////////////////////////////////////////////////////////////////////////////
10 
11 #include "catch.hpp"
12 
13 #include "OhmmsData/Libxml2Doc.h"
14 #include "OhmmsPETE/OhmmsMatrix.h"
15 #include "Particle/ParticleSet.h"
17 
18 #include <stdio.h>
19 #include <string>
20 
21 
22 namespace qmcplusplus
23 {
24 TEST_CASE("Density Estimator", "[hamiltonian]")
25 {
26  const SimulationCell simulation_cell;
27  ParticleSet elec(simulation_cell);
28 
29  elec.setName("elec");
30  elec.create({2});
31  elec.R[0] = {0.0, 1.0, 0.0};
32  elec.R[1] = {0.4, 0.3, 0.0};
33 
34  SpeciesSet& tspecies = elec.getSpeciesSet();
35  int upIdx = tspecies.addSpecies("u");
36  //int chargeIdx = tspecies.addAttribute("charge");
37  int massIdx = tspecies.addAttribute("mass");
38  int eChargeIdx = tspecies.addAttribute("charge");
39  tspecies(eChargeIdx, upIdx) = -1.0;
40  tspecies(massIdx, upIdx) = 1.0;
41 
42  // The call to resetGroups is needed transfer the SpeciesSet
43  // settings to the ParticleSet
44  elec.resetGroups();
45  elec.update();
46 
47  DensityEstimator density_estimator(elec);
48 
50  density_estimator.setHistories(dummy);
51 
52  const double val = density_estimator.evaluate(elec);
53  CHECK(val == Approx(0.0));
54 }
55 
56 TEST_CASE("Density Estimator evaluate exception", "[hamiltonian]")
57 {
58  const SimulationCell simulation_cell;
59  ParticleSet elec(simulation_cell);
60  DensityEstimator density_estimator(elec);
61  REQUIRE(density_estimator.getClassName() == "DensityEstimator");
62  // empty function
63  density_estimator.resetTargetParticleSet(elec);
64  // check exception is thrown when weights are not defined
65  CHECK_THROWS_AS(density_estimator.evaluate(elec), std::invalid_argument);
66 }
67 
68 } // namespace qmcplusplus
void setName(const std::string &aname)
Definition: ParticleSet.h:237
Walker< QMCTraits, PtclOnLatticeTraits > Walker_t
walker type
Definition: ParticleSet.h:59
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
std::string getClassName() const override
return class name
TEST_CASE("complex_helper", "[type_traits]")
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
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
REQUIRE(std::filesystem::exists(filename))
ParticlePos R
Position.
Definition: ParticleSet.h:79
virtual void setHistories(Walker_t &ThisWalker)
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void create(const std::vector< int > &agroup)
create grouped particles
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
A container class to represent a walker.
Definition: Walker.h:49
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.