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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign 8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign 9 // 10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign 11 ////////////////////////////////////////////////////////////////////////////////////// 12 13 14 /**@file HamiltonianPool.h 15 * @brief Declaration of HamiltonianPool 16 */ 17 #ifndef QMCPLUSPLUS_QMCHAMILTONIANS_H 18 #define QMCPLUSPLUS_QMCHAMILTONIANS_H 19 20 #include "QMCHamiltonians/HamiltonianFactory.h" 21 #include "OhmmsData/OhmmsElementBase.h" 22 #include "Message/MPIObjectBase.h" 23 #include <map> 24 25 struct Libxml2Document; 26 27 namespace qmcplusplus 28 { 29 class ParticleSet; 30 class MCWalkerConfiguration; 31 class ParticleSetPool; 32 class WaveFunctionPool; 33 34 /** @ingroup qmcapp 35 * @brief Manage a collection of QMCHamiltonian objects 36 * 37 * This object handles \<hamiltonian\> elements and 38 * functions as a builder class for QMCHamiltonian objects. 39 */ 40 class HamiltonianPool : public MPIObjectBase 41 { 42 public: 43 using PoolType = std::map<std::string, HamiltonianFactory*>; 44 45 HamiltonianPool(ParticleSetPool& pset_pool, 46 WaveFunctionPool& psi_pool, 47 Communicate* c, 48 const char* aname = "hamiltonian"); 49 HamiltonianPool(const HamiltonianPool&) = delete; 50 HamiltonianPool& operator=(const HamiltonianPool&) = delete; 51 HamiltonianPool(HamiltonianPool&&) = default; 52 HamiltonianPool& operator=(HamiltonianPool&&) = delete; 53 ~HamiltonianPool(); 54 55 bool put(xmlNodePtr cur); 56 bool get(std::ostream& os) const; 57 void reset(); 58 empty()59 inline bool empty() const { return myPool.empty(); } 60 61 /** return the pointer to the primary QMCHamiltonian 62 * 63 * The first QMCHamiltonian is assigned to the primaryH. 64 * The last QMCHamiltonian with role="primary" will be the primaryH. 65 */ getPrimary()66 inline QMCHamiltonian* getPrimary() { return primaryH; } 67 68 /** return the pointer to a QMCHamiltonian with the name 69 * @param pname name of the QMCHamiltonian 70 */ getHamiltonian(const std::string & pname)71 inline QMCHamiltonian* getHamiltonian(const std::string& pname) 72 { 73 PoolType::iterator hit(myPool.find(pname)); 74 if (hit == myPool.end()) 75 { 76 if (myPool.empty()) 77 return nullptr; 78 else 79 return (*(myPool.begin())).second->getH(); 80 } 81 else 82 return (*hit).second->getH(); 83 } 84 setDocument(Libxml2Document * doc)85 void setDocument(Libxml2Document* doc) { curDoc = doc; } 86 87 private: 88 /** pointer to the primary QMCHamiltonian 89 */ 90 QMCHamiltonian* primaryH; 91 92 /** pointer to a current QMCHamiltonian to be built. 93 */ 94 QMCHamiltonian* curH; 95 96 /** pointer to ParticleSetPool 97 * 98 * QMCHamiltonian needs to know which ParticleSet object 99 * is used as an input object for the evaluations. 100 * Any number of ParticleSet can be used to describe 101 * a QMCHamiltonian. 102 */ 103 ParticleSetPool& ptcl_pool_; 104 105 /** pointer to WaveFunctionPool 106 * 107 * For those OperatorBase that depends on TrialWaveFunction, 108 * e.g., NonLocalPPotential. 109 */ 110 WaveFunctionPool& psi_pool_; 111 112 113 /** point to the working document */ 114 Libxml2Document* curDoc; 115 116 /** storage for HamiltonianFactory */ 117 PoolType myPool; 118 }; 119 } // namespace qmcplusplus 120 #endif 121