QMCPACK
test_hamiltonian_pool.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) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 
16 #include "Configuration.h"
17 #include "Message/Communicate.h"
18 #include "OhmmsData/Libxml2Doc.h"
23 
24 #include <stdio.h>
25 #include <string>
26 #include <sstream>
27 
28 
29 namespace qmcplusplus
30 {
31 extern std::unique_ptr<ParticleSet> createElectronParticleSet(const SimulationCell& simulation_cell);
32 
33 TEST_CASE("HamiltonianPool", "[qmcapp]")
34 {
35  Communicate* c;
37 
38  // See src/QMCHamiltonians/tests/test_hamiltonian_factory for parsing tests
39  const char* hamiltonian_xml = R"(<hamiltonian name="h0" type="generic" target="e">
40  <pairpot type="coulomb" name="ElecElec" source="e" target="e"/>
41 </hamiltonian>)";
42 
44  bool okay = doc.parseFromString(hamiltonian_xml);
45  REQUIRE(okay);
46 
47  xmlNodePtr root = doc.getRoot();
48 
49  ParticleSetPool pp(c);
51  pp.addParticleSet(std::move(qp));
52 
53  RuntimeOptions runtime_options;
54  WaveFunctionPool wfp(runtime_options, pp, c);
55  wfp.addFactory(WaveFunctionFactory::buildEmptyTWFForTesting(runtime_options, "psi0"), true);
56 
57  HamiltonianPool hpool(pp, wfp, c);
58 
59  REQUIRE(hpool.empty());
60 
61  hpool.put(root);
62 
63  QMCHamiltonian* h = hpool.getHamiltonian("h0");
64  REQUIRE(h != nullptr);
65 
66  // Bare kinetic energy is always added
67  REQUIRE(h->size() == 2);
68 }
69 
70 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
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
Collection of Local Energy Operators.
void addFactory(std::unique_ptr< TrialWaveFunction > psi, bool primary)
add a TrialWaveFunction* to myPool
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))
Declaration of WaveFunctionPool.
int size() const
return the number of Hamiltonians
Manage a collection of ParticleSet objects.
std::unique_ptr< ParticleSet > createElectronParticleSet(const SimulationCell &simulation_cell)
QMCHamiltonian * getHamiltonian(const std::string &pname)
return the pointer to a QMCHamiltonian with the name
static std::unique_ptr< TrialWaveFunction > buildEmptyTWFForTesting(const RuntimeOptions &runtime_options, const std::string_view name)
create an empty TrialWaveFunction for testing use.
Declaration of HamiltonianPool.
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
const auto & getSimulationCell() const
get simulation cell
Manage a collection of TrialWaveFunction objects.
Declaration of ParticleSetPool.
Manage a collection of QMCHamiltonian objects.