From 4ea486eff513a29b146cabbecc4588a657a91c34 Mon Sep 17 00:00:00 2001 From: Steven Hahn Date: Thu, 28 Sep 2023 11:36:43 -0400 Subject: [PATCH] start fixing build errors Signed-off-by: Steven Hahn --- src/Particle/CMakeLists.txt | 1 - src/Particle/ParticleSetPool.cpp | 239 ------------------------------- src/Particle/ParticleSetPool.h | 100 +------------ src/Particle/ParticleSetT.h | 1 - 4 files changed, 3 insertions(+), 338 deletions(-) delete mode 100644 src/Particle/ParticleSetPool.cpp diff --git a/src/Particle/CMakeLists.txt b/src/Particle/CMakeLists.txt index ddd7243148..b7b82eeed0 100644 --- a/src/Particle/CMakeLists.txt +++ b/src/Particle/CMakeLists.txt @@ -16,7 +16,6 @@ set(PARTICLE InitMolecularSystem.cpp InitMolecularSystemT.cpp SimulationCellT.cpp - ParticleSetPool.cpp ParticleSetPoolT.cpp ParticleSetT.cpp PSdispatcher.cpp diff --git a/src/Particle/ParticleSetPool.cpp b/src/Particle/ParticleSetPool.cpp deleted file mode 100644 index 7f4cb7f3a5..0000000000 --- a/src/Particle/ParticleSetPool.cpp +++ /dev/null @@ -1,239 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2020 QMCPACK developers. -// -// File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign -// Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory -// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign -// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign -////////////////////////////////////////////////////////////////////////////////////// - - -/**@file ParticleSetPool.cpp - * @brief Implements ParticleSetPool operators. - */ -#include "ParticleSetPool.h" -#include "ParticleBase/RandomSeqGenerator.h" -#include "ParticleIO/XMLParticleIO.h" -#include "ParticleIO/LatticeIO.h" -#include "Utilities/ProgressReportEngine.h" -#include "OhmmsData/AttributeSet.h" -#include "OhmmsData/Libxml2Doc.h" -#include "Particle/InitMolecularSystem.h" -#include "LongRange/LRCoulombSingleton.h" -#include -#include - -namespace qmcplusplus -{ -ParticleSetPool::ParticleSetPool(Communicate* c, const char* aname) - : MPIObjectBase(c), simulation_cell_(std::make_unique()) -{ - ClassName = "ParticleSetPool"; - myName = aname; -} - -ParticleSetPool::ParticleSetPool(ParticleSetPool&& other) noexcept - : MPIObjectBase(other.myComm), simulation_cell_(std::move(other.simulation_cell_)), myPool(std::move(other.myPool)) -{ - ClassName = other.ClassName; - myName = other.myName; -} - -ParticleSetPool::~ParticleSetPool() = default; - -ParticleSet* ParticleSetPool::getParticleSet(const std::string& pname) -{ - if (auto pit = myPool.find(pname); pit == myPool.end()) - return nullptr; - else - return pit->second.get(); -} - -MCWalkerConfiguration* ParticleSetPool::getWalkerSet(const std::string& pname) -{ - auto mc = dynamic_cast(getParticleSet(pname)); - if (mc == nullptr) - { - throw std::runtime_error("ParticleSePool::getWalkerSet missing " + pname); - } - return mc; -} - -void ParticleSetPool::addParticleSet(std::unique_ptr&& p) -{ - const auto pit(myPool.find(p->getName())); - if (pit == myPool.end()) - { - auto& pname = p->getName(); - LOGMSG(" Adding " << pname << " ParticleSet to the pool") - if (&p->getSimulationCell() != simulation_cell_.get()) - throw std::runtime_error("Bug detected! ParticleSetPool::addParticleSet requires p created with the simulation " - "cell from ParticleSetPool."); - myPool.emplace(pname, std::move(p)); - } - else - throw std::runtime_error(p->getName() + " exists. Cannot be added again."); -} - -bool ParticleSetPool::readSimulationCellXML(xmlNodePtr cur) -{ - ReportEngine PRE("ParticleSetPool", "putLattice"); - - bool lattice_defined = false; - try - { - LatticeParser a(simulation_cell_->lattice_); - lattice_defined = a.put(cur); - } - catch (const UniformCommunicateError& ue) - { - myComm->barrier_and_abort(ue.what()); - } - - if (lattice_defined) - { - app_log() << " Overwriting global supercell " << std::endl; - simulation_cell_->resetLRBox(); - if (outputManager.isHighActive()) - simulation_cell_->lattice_.print(app_log(), 2); - else - simulation_cell_->lattice_.print(app_summary(), 1); - } - return lattice_defined; -} - -/** process an xml element - * @param cur current xmlNodePtr - * @return true, if successful. - * - * Creating MCWalkerConfiguration for all the ParticleSet - * objects. - */ -bool ParticleSetPool::put(xmlNodePtr cur) -{ - ReportEngine PRE("ParticleSetPool", "put"); - std::string id("e"); - std::string role("none"); - std::string randomR("no"); - std::string randomsrc; - std::string useGPU; - std::string spinor; - OhmmsAttributeSet pAttrib; - pAttrib.add(id, "id"); - pAttrib.add(id, "name"); - pAttrib.add(role, "role"); - pAttrib.add(randomR, "random"); - pAttrib.add(randomsrc, "randomsrc"); - pAttrib.add(randomsrc, "random_source"); - pAttrib.add(spinor, "spinor", {"no", "yes"}); - pAttrib.add(useGPU, "gpu", CPUOMPTargetSelector::candidate_values); - pAttrib.put(cur); - //backward compatibility - if (id == "e" && role == "none") - role = "MC"; - ParticleSet* pTemp = getParticleSet(id); - if (pTemp == 0) - { - const bool use_offload = CPUOMPTargetSelector::selectPlatform(useGPU) == PlatformKind::OMPTARGET; - app_summary() << std::endl; - app_summary() << " Particle Set" << std::endl; - app_summary() << " ------------" << std::endl; - app_summary() << " Name: " << id << " Offload : " << (use_offload ? "yes" : "no") << std::endl; - app_summary() << std::endl; - - // select OpenMP offload implementation in ParticleSet. - if (use_offload) - pTemp = new MCWalkerConfiguration(*simulation_cell_, DynamicCoordinateKind::DC_POS_OFFLOAD); - else - pTemp = new MCWalkerConfiguration(*simulation_cell_, DynamicCoordinateKind::DC_POS); - - myPool.emplace(id, pTemp); - - try - { - XMLParticleParser pread(*pTemp); - pread.readXML(cur); - } - catch (const UniformCommunicateError& ue) - { - myComm->barrier_and_abort(ue.what()); - } - - //if random_source is given, create a node - if (randomR == "yes" && !randomsrc.empty()) - { - xmlNodePtr anode = xmlNewNode(NULL, (const xmlChar*)"init"); - xmlNewProp(anode, (const xmlChar*)"source", (const xmlChar*)randomsrc.c_str()); - xmlNewProp(anode, (const xmlChar*)"target", (const xmlChar*)id.c_str()); - randomize_nodes.push_back(anode); - } - pTemp->setName(id); - pTemp->setSpinor(spinor == "yes"); - app_summary() << " Particle set size: " << pTemp->getTotalNum() << " Groups : " << pTemp->groups() << std::endl; - app_summary() << std::endl; - return true; - } - else - { - app_warning() << "Particle set " << id << " is already created. Ignoring this section." << std::endl; - } - app_summary() << std::endl; - return true; -} - -void ParticleSetPool::randomize() -{ - app_log() << "ParticleSetPool::randomize " << randomize_nodes.size() << " ParticleSet" - << (randomize_nodes.size() == 1 ? "" : "s") << "." << std::endl; - bool success = true; - for (int i = 0; i < randomize_nodes.size(); ++i) - { - InitMolecularSystem moinit(*this); - success &= moinit.put(randomize_nodes[i]); - xmlFreeNode(randomize_nodes[i]); - } - randomize_nodes.clear(); - if (!success) - throw std::runtime_error("ParticleSePool::randomize failed to randomize some Particlesets!"); -} - -bool ParticleSetPool::get(std::ostream& os) const -{ - os << "ParticleSetPool has: " << std::endl << std::endl; - os.setf(std::ios::scientific, std::ios::floatfield); - os.precision(14); - for (const auto& [name, pset] : myPool) - if (outputManager.isDebugActive()) - pset->print(os, 0); - else - pset->print(os, 10 /* maxParticlesToPrint */); - return true; -} - -void ParticleSetPool::output_particleset_info(Libxml2Document& doc, xmlNodePtr root) -{ - xmlNodePtr particles_info = doc.addChild(root, "particles"); - PoolType::const_iterator it(myPool.begin()), it_end(myPool.end()); - while (it != it_end) - { - xmlNodePtr particle = doc.addChild(particles_info, "particle"); - doc.addChild(particle, "name", (*it).second->getName()); - doc.addChild(particle, "size", (*it).second->getTotalNum()); - ++it; - } -} - -/** reset is used to initialize and evaluate the distance tables - */ -void ParticleSetPool::reset() -{ - for (const auto& [key, pset] : myPool) - pset->update(); -} - -} // namespace qmcplusplus diff --git a/src/Particle/ParticleSetPool.h b/src/Particle/ParticleSetPool.h index 63f252a997..08cc089678 100644 --- a/src/Particle/ParticleSetPool.h +++ b/src/Particle/ParticleSetPool.h @@ -18,107 +18,13 @@ #ifndef QMCPLUSPLUS_PARTICLESETPOOL_H #define QMCPLUSPLUS_PARTICLESETPOOL_H -#include "OhmmsData/OhmmsElementBase.h" -#include "Particle/MCWalkerConfiguration.h" -#include "Message/MPIObjectBase.h" -#include "SimulationCell.h" +#include "Configuration.h" +#include "Particle/ParticleSetPoolT.h" namespace qmcplusplus { -/** @ingroup qmcapp - * @brief Manage a collection of ParticleSet objects - * - * This object handles \ elements and - * functions as a builder class for ParticleSet objects. - */ -class ParticleSetPool : public MPIObjectBase -{ -public: - using PoolType = std::map>; - - /** constructor - * @param aname xml tag - */ - ParticleSetPool(Communicate* c, const char* aname = "particleset"); - ~ParticleSetPool(); - - ParticleSetPool(const ParticleSetPool&) = delete; - ParticleSetPool& operator=(const ParticleSetPool&) = delete; - ParticleSetPool(ParticleSetPool&& pset) noexcept; - ParticleSetPool& operator=(ParticleSetPool&&) = default; - - bool put(xmlNodePtr cur); - bool get(std::ostream& os) const; - void reset(); - - void output_particleset_info(Libxml2Document& doc, xmlNodePtr root); - - /** initialize the supercell shared by all the particle sets - * - * return value is never checked anywhere - * side effect simulation_cell_ UPtr is set - * to particle layout created on heap. - * This is later directly assigned to pset member variable Lattice. - */ - bool readSimulationCellXML(xmlNodePtr cur); - - ///return true, if the pool is empty - inline bool empty() const { return myPool.empty(); } - - /** add a ParticleSet* to the pool with its ownership transferred - * ParticleSet built outside the ParticleSetPool must be constructed with - * the simulation cell from this->simulation_cell_. - */ - void addParticleSet(std::unique_ptr&& p); - - /** get a named ParticleSet - * @param pname name of the ParticleSet - * @return a MCWalkerConfiguration object with pname - * - * When the named ParticleSet is not in this object, return 0. - */ - ParticleSet* getParticleSet(const std::string& pname); - - /** get a named MCWalkerConfiguration - * @param pname name of the MCWalkerConfiguration - * @return a MCWalkerConfiguration object with pname - * - * When the named MCWalkerConfiguration is not in this object, return 0. - */ - MCWalkerConfiguration* getWalkerSet(const std::string& pname); - - /** get the Pool object - */ - inline const PoolType& getPool() const { return myPool; } - - /// get simulation cell - const auto& getSimulationCell() const { return *simulation_cell_; } - - /// set simulation cell - void setSimulationCell(const SimulationCell& simulation_cell) { *simulation_cell_ = simulation_cell; } - /** randomize a particleset particleset/@random='yes' && particleset@random_source exists - */ - void randomize(); +using ParticleSetPool = ParticleSetPoolT; -private: - /** global simulation cell - * - * updated by - * - readSimulationCellXML() parsing element - * - setSimulationCell() - */ - std::unique_ptr simulation_cell_; - /** List of ParticleSet owned - * - * Each ParticleSet has to have a unique name which is used as a key for the map. - */ - PoolType myPool; - /** xml node for random initialization. - * - * randomize() process initializations just before starting qmc sections - */ - std::vector randomize_nodes; -}; } // namespace qmcplusplus #endif diff --git a/src/Particle/ParticleSetT.h b/src/Particle/ParticleSetT.h index bb3451da06..53c93627f4 100644 --- a/src/Particle/ParticleSetT.h +++ b/src/Particle/ParticleSetT.h @@ -83,7 +83,6 @@ class ParticleSetT : public OhmmsElementBase using ParticleIndex = typename LatticeParticleTraits::ParticleIndex; using ParticlePos = typename LatticeParticleTraits::ParticlePos; using ParticleScalar = typename LatticeParticleTraits::ParticleScalar; - using ParticleTensor = ParticleAttrib; using ParticleGradient = typename LatticeParticleTraits::ParticleGradient; using ParticleLaplacian =