From 1c6f5949adf4dbd7bbfbe5cd3ddf97b8a65f4ad8 Mon Sep 17 00:00:00 2001 From: "Fattebert J.-L" Date: Wed, 5 Jun 2024 09:22:12 -0400 Subject: [PATCH 1/4] Add example driver * shows use of MGmol as a force/energy computational engine --- drivers/CMakeLists.txt | 8 +- drivers/example1.cc | 162 +++++++++++++++++++++++++++++++++++++++++ src/Ions.cc | 68 +++++++++++------ src/Ions.h | 10 ++- src/MGmol.cc | 24 ++++++ src/MGmol.h | 9 +++ src/MGmolInterface.h | 5 ++ src/md.cc | 12 ++- 8 files changed, 266 insertions(+), 32 deletions(-) create mode 100644 drivers/example1.cc diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index d0797ba0..4eb1c741 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,9 +1,11 @@ include_directories( ${CMAKE_SOURCE_DIR}/src ) -add_executable(check_input - check_input.cc - ) +add_executable(check_input check_input.cc) + +add_executable(example1 example1.cc) target_include_directories(check_input PRIVATE ${Boost_INCLUDE_DIRS}) +target_include_directories(example1 PRIVATE ${Boost_INCLUDE_DIRS}) target_link_libraries(check_input mgmol_src) +target_link_libraries(example1 mgmol_src) diff --git a/drivers/example1.cc b/drivers/example1.cc new file mode 100644 index 00000000..b453425a --- /dev/null +++ b/drivers/example1.cc @@ -0,0 +1,162 @@ +// Copyright (c) 2017, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and the Oak Ridge +// National Laboratory. +// LLNL-CODE-743438 +// All rights reserved. +// This file is part of MGmol. For details, see https://github.com/llnl/mgmol. +// Please also read this link https://github.com/llnl/mgmol/LICENSE + +#include "Control.h" +#include "ExtendedGridOrbitals.h" +#include "LocGridOrbitals.h" +#include "MGmol.h" +#include "MGmol_MPI.h" +#include "MPIdata.h" +#include "mgmol_run.h" + +#include +#include +#include +#include + +#include +namespace po = boost::program_options; + +int main(int argc, char** argv) +{ + int mpirc = MPI_Init(&argc, &argv); + if (mpirc != MPI_SUCCESS) + { + std::cerr << "MPI Initialization failed!!!" << std::endl; + MPI_Abort(MPI_COMM_WORLD, 0); + } + + MPI_Comm comm = MPI_COMM_WORLD; + + /* + * Initialize general things, like magma, openmp, IO, ... + */ + mgmol_init(comm); + + /* + * read runtime parameters + */ + std::string input_filename(""); + std::string lrs_filename; + std::string constraints_filename(""); + + float total_spin = 0.; + bool with_spin = false; + + po::variables_map vm; + + // read from PE0 only + if (MPIdata::onpe0) + { + read_config(argc, argv, vm, input_filename, lrs_filename, + constraints_filename, total_spin, with_spin); + } + + MGmol_MPI::setup(comm, std::cout, with_spin); + MGmol_MPI& mmpi = *(MGmol_MPI::instance()); + MPI_Comm global_comm = mmpi.commGlobal(); + + /* + * Setup control struct with run time parameters + */ + Control::setup(global_comm, with_spin, total_spin); + Control& ct = *(Control::instance()); + + ct.setOptions(vm); + + int ret = ct.checkOptions(); + if (ret < 0) return ret; + + mmpi.bcastGlobal(input_filename); + mmpi.bcastGlobal(lrs_filename); + + // Enter main scope + { + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "Construct MGmol object..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + + MGmolInterface* mgmol; + if (ct.isLocMode()) + mgmol = new MGmol(global_comm, *MPIdata::sout, + input_filename, lrs_filename, constraints_filename); + else + mgmol = new MGmol(global_comm, *MPIdata::sout, + input_filename, lrs_filename, constraints_filename); + + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "MGmol setup..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + mgmol->setup(); + + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "Setup done..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + + // here we just use the atomic positions read in and used + // to initialize MGmol + std::vector positions; + mgmol->getAtomicPositions(positions); + if (MPIdata::onpe0) + { + std::cout << "Positions:" << std::endl; + for (std::vector::iterator it = positions.begin(); + it != positions.end(); it += 3) + { + for (int i = 0; i < 3; i++) + std::cout << " " << *(it + i); + std::cout << std::endl; + } + } + + // compute energy and forces using all MPI tasks + // expect positions to be replicated on all MPI tasks + std::vector forces; + mgmol->evaluateEnergyAndForces(positions, forces); + + // print out results + if (MPIdata::onpe0) + { + std::cout << "Forces:" << std::endl; + for (std::vector::iterator it = forces.begin(); + it != forces.end(); it += 3) + { + for (int i = 0; i < 3; i++) + std::cout << " " << *(it + i); + std::cout << std::endl; + } + } + + delete mgmol; + + } // close main scope + + mgmol_finalize(); + + mpirc = MPI_Finalize(); + if (mpirc != MPI_SUCCESS) + { + std::cerr << "MPI Finalize failed!!!" << std::endl; + } + + time_t tt; + time(&tt); + if (onpe0) std::cout << " Run ended at " << ctime(&tt) << std::endl; + + return 0; +} diff --git a/src/Ions.cc b/src/Ions.cc index 53ee0cf4..cef6175a 100644 --- a/src/Ions.cc +++ b/src/Ions.cc @@ -10,6 +10,7 @@ #include "Ions.h" #include "Control.h" #include "HDFrestart.h" +#include "MGmol_MPI.h" #include "MGmol_blas1.h" #include "MPIdata.h" #include "Mesh.h" @@ -169,12 +170,9 @@ void Ions::computeMaxNumProjs() << " initialized" << std::endl; #endif - std::vector::iterator ion = list_ions_.begin(); - while (ion != list_ions_.end()) + for (auto& ion : list_ions_) { - max_num_proj_ = std::max(max_num_proj_, (*ion)->nProjectors()); - - ion++; + max_num_proj_ = std::max(max_num_proj_, ion->nProjectors()); } MGmol_MPI& mmpi(*(MGmol_MPI::instance())); @@ -210,11 +208,9 @@ void Ions::setup() if (ct.verbose > 0) printWithTimeStamp("Ions::setup()... individual ions...", std::cout); - std::vector::iterator ion = list_ions_.begin(); - while (ion != list_ions_.end()) + for (auto& ion : list_ions_) { - (*ion)->setup(); - ion++; + ion->setup(); } setMapVL(); @@ -1569,7 +1565,7 @@ Ion* Ions::findLocalIon(const int index) const return nullptr; } -void Ions::setPositions(const std::vector& tau) +void Ions::setLocalPositions(const std::vector& tau) { assert(tau.size() == 3 * local_ions_.size()); @@ -2118,8 +2114,6 @@ int Ions::read1atom(std::ifstream* tfile, const bool cell_relative) // Ion needs to be created by each MPI task to set global ids Ion* new_ion = new Ion(species_[isp], name_read, crds, velocity, locked); - // assert( (new_ion->locked() == false) || (new_ion->locked() == true) ); - #ifdef DEBUG if (onpe0) (*MPIdata::sout) << "Ion read..." << std::endl; #endif @@ -2131,11 +2125,11 @@ int Ions::read1atom(std::ifstream* tfile, const bool cell_relative) // populate local_ions_ list if (inLocalIons(crds[0], crds[1], crds[2])) { - (new_ion)->set_here(true); + new_ion->set_here(true); local_ions_.push_back(new_ion); } else - (new_ion)->set_here(false); + new_ion->set_here(false); } else { @@ -2193,7 +2187,7 @@ void Ions::setVelocities(const std::vector& tau0, } } -void Ions::getPositions(std::vector& tau) const +void Ions::getLocalPositions(std::vector& tau) const { assert(tau.size() == 3 * local_ions_.size()); @@ -2207,6 +2201,32 @@ void Ions::getPositions(std::vector& tau) const } } +void Ions::getPositions(std::vector& tau) +{ + std::vector tau_local(3 * local_ions_.size()); + + getLocalPositions(tau_local); + + int n = getNumIons(); + tau.resize(3 * n); + + MGmol_MPI& mmpi = *(MGmol_MPI::instance()); + mmpi.allGatherV(tau_local, tau); +} + +void Ions::getForces(std::vector& forces) +{ + std::vector forces_local(3 * local_ions_.size()); + + getLocalForces(forces_local); + + int n = getNumIons(); + forces.resize(3 * n); + + MGmol_MPI& mmpi = *(MGmol_MPI::instance()); + mmpi.allGatherV(forces_local, forces); +} + void Ions::setTau0() { assert(tau0_.size() == 3 * local_ions_.size()); @@ -2236,6 +2256,14 @@ void Ions::setPositionsToTau0() } } +void Ions::setPositions(const std::vector& tau) +{ + setLocalPositions(tau); + + // setup required after updating local ions positions + setup(); +} + void Ions::setVelocitiesToVel() { assert(velocity_.size() == 3 * local_ions_.size()); @@ -2249,7 +2277,7 @@ void Ions::setVelocitiesToVel() } } -void Ions::getForces(std::vector& tau) const +void Ions::getLocalForces(std::vector& tau) const { assert(tau.size() == 3 * local_ions_.size()); @@ -2380,12 +2408,10 @@ double Ions::computeMaxNLprojRadius() const { double radius = 0.; - std::vector::const_iterator iion = local_ions_.begin(); - while (iion != local_ions_.end()) + for (auto& iion : local_ions_) { - double r = (*iion)->radiusNLproj(); + double r = iion->radiusNLproj(); radius = r > radius ? r : radius; - iion++; } MGmol_MPI& mmpi(*(MGmol_MPI::instance())); @@ -3061,7 +3087,7 @@ void Ions::updateForcesInteractingIons() MGmol_MPI& mmpi(*(MGmol_MPI::instance())); // get computed forces into fion_ - getForces(fion_); + getLocalForces(fion_); // initialize with local names and forces DistributedIonicData forces_data(local_names_, fion_); diff --git a/src/Ions.h b/src/Ions.h index 2351d678..7f224a36 100644 --- a/src/Ions.h +++ b/src/Ions.h @@ -16,7 +16,6 @@ #include #include -#include "DataDistribution.h" #include "DistributedIonicData.h" #include "Ion.h" #include "hdf5.h" @@ -247,7 +246,7 @@ class Ions // check if ion is in list of local ions bool isLocal(const std::string& ion_name) const; - void setPositions(const std::vector& tau); + void setLocalPositions(const std::vector& tau); void get_positions(std::vector>& r) const; void set_positions(const std::vector>& r); void get_forces(std::vector>& f) const; @@ -268,9 +267,12 @@ class Ions void setTau0(); void setPositionsToTau0(); void setVelocitiesToVel(); + void setPositions(const std::vector& tau); - void getPositions(std::vector& tau) const; - void getForces(std::vector& tau) const; + void getLocalPositions(std::vector& tau) const; + void getPositions(std::vector& tau); + void getForces(std::vector& forces); + void getLocalForces(std::vector& tau) const; void syncData(const std::vector& sp); // void syncNames(const int nions, std::vector& local_names, // std::vector& names); diff --git a/src/MGmol.cc b/src/MGmol.cc index 85acc78d..7516b5b1 100644 --- a/src/MGmol.cc +++ b/src/MGmol.cc @@ -1405,6 +1405,30 @@ void MGmol::addResidualSpreadPenalty( spread_penalty_->addResidual(phi, res); } +template +void MGmol::getAtomicPositions(std::vector& tau) +{ + ions_->getPositions(tau); +} + +template +double MGmol::evaluateEnergyAndForces( + const std::vector& tau, std::vector& forces) +{ + Control& ct = *(Control::instance()); + + ions_->setPositions(tau); + + double eks = 0.; + quench(current_orbitals_, *ions_, ct.max_electronic_steps, 20, eks); + + force(*current_orbitals_, *ions_); + + ions_->getForces(forces); + + return eks; +} + template class MGmol; template class MGmol; template int MGmol::initial(); diff --git a/src/MGmol.h b/src/MGmol.h index ceec7390..5f5b4701 100644 --- a/src/MGmol.h +++ b/src/MGmol.h @@ -179,6 +179,15 @@ class MGmol : public MGmolInterface ~MGmol() override; void run() override; + + double evaluateEnergyAndForces( + const std::vector& tau, std::vector& forces); + + /* + * get internal atomic positions + */ + void getAtomicPositions(std::vector& tau); + void initNuc(Ions& ions); void initKBR(); diff --git a/src/MGmolInterface.h b/src/MGmolInterface.h index 9932dd9f..9766d776 100644 --- a/src/MGmolInterface.h +++ b/src/MGmolInterface.h @@ -11,6 +11,7 @@ #define MGMOLINTERFACE_H #include +#include class MGmolInterface { @@ -24,6 +25,10 @@ class MGmolInterface virtual int setupConstraintsFromInput(const std::string input_file) = 0; virtual void setup() = 0; virtual void run() = 0; + virtual double evaluateEnergyAndForces( + const std::vector& tau, std::vector& forces) + = 0; + virtual void getAtomicPositions(std::vector& tau) = 0; }; #endif diff --git a/src/md.cc b/src/md.cc index 41dcd39b..5f690e82 100644 --- a/src/md.cc +++ b/src/md.cc @@ -344,8 +344,9 @@ void MGmol::md(OrbitalsType** orbitals, Ions& ions) constraints_->enforceConstraints(20); stepper->updateTau(); - ions.setPositions(tau0); + ions.setLocalPositions(tau0); + // setup required after updating local ions positions ions.setup(); } @@ -489,7 +490,7 @@ void MGmol::md(OrbitalsType** orbitals, Ions& ions) force(**orbitals, ions); // set fion - ions.getForces(fion); + ions.getLocalForces(fion); // constraints need to be added again and setup as atoms // may have moved and local atoms are not the same anymore @@ -717,12 +718,15 @@ OrbitalsType* MGmol::loadOrbitalFromRestartFile( while the extrapolated function is set as the current orbitals. This is how the restart file is saved via dumprestartFile. - For now, we just enforce to not use the restart files with extrapolation. + For now, we just enforce to not use the restart files with + extrapolation. */ if (flag_extrapolated_data) { if (onpe0) - (*MPIdata::serr) << "loadRestartFile: does not support restart files with extrapolation." << std::endl; + (*MPIdata::serr) << "loadRestartFile: does not support restart " + "files with extrapolation." + << std::endl; global_exit(0); } From 82682934933eaa55f97287a11c1c152098c5390b Mon Sep 17 00:00:00 2001 From: "Fattebert J.-L" Date: Wed, 5 Jun 2024 15:03:01 -0400 Subject: [PATCH 2/4] Split function --- src/Ions.cc | 13 +++++++++++-- src/Ions.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Ions.cc b/src/Ions.cc index cef6175a..8b6966ef 100644 --- a/src/Ions.cc +++ b/src/Ions.cc @@ -1781,6 +1781,7 @@ int Ions::readAtomsFromXYZ( } ++count; } + delete tfile; } mmpi.bcastGlobal(&count, 1); @@ -1789,6 +1790,16 @@ int Ions::readAtomsFromXYZ( mmpi.bcastGlobal(&crds[0], 3 * natoms); mmpi.bcastGlobal(&spec[0], natoms); + return setAtoms(crds, spec); +} + +int Ions::setAtoms(std::vector& crds, std::vector& spec) +{ + MGmol_MPI& mmpi(*(MGmol_MPI::instance())); + Control& ct(*(Control::instance())); + + const int natoms = crds.size()/3; + double velocity[3] = { 0., 0., 0. }; bool locked = false; for (int ia = 0; ia < natoms; ++ia) @@ -1874,8 +1885,6 @@ int Ions::readAtomsFromXYZ( // std::cout<::iterator ita = anumbers.begin(); for (std::vector::iterator it = positions.begin(); it != positions.end(); it += 3) { + std::cout << *ita; for (int i = 0; i < 3; i++) std::cout << " " << *(it + i); std::cout << std::endl; + ita++; } } // compute energy and forces using all MPI tasks // expect positions to be replicated on all MPI tasks std::vector forces; - mgmol->evaluateEnergyAndForces(positions, forces); + mgmol->evaluateEnergyAndForces(positions, anumbers, forces); // print out results if (MPIdata::onpe0) diff --git a/src/Ions.cc b/src/Ions.cc index 8b6966ef..2a7e15e5 100644 --- a/src/Ions.cc +++ b/src/Ions.cc @@ -239,7 +239,7 @@ Ions::~Ions() void Ions::setupListOverlappingIons() { Control& ct = *(Control::instance()); - if (ct.verbose > 0) + if (ct.verbose > 1) printWithTimeStamp("Ions::setupListOverlappingIons()...", std::cout); overlappingNL_ions_.clear(); @@ -265,7 +265,7 @@ void Ions::setupListOverlappingIons() void Ions::setupInteractingIons() { Control& ct = *(Control::instance()); - if (ct.verbose > 0) + if (ct.verbose > 1) printWithTimeStamp("Ions::setupInteractingIons()...", std::cout); ions_setupInteractingIons_tm.start(); @@ -1781,7 +1781,7 @@ int Ions::readAtomsFromXYZ( } ++count; } - delete tfile; + delete tfile; } mmpi.bcastGlobal(&count, 1); @@ -1793,12 +1793,13 @@ int Ions::readAtomsFromXYZ( return setAtoms(crds, spec); } -int Ions::setAtoms(std::vector& crds, std::vector& spec) +int Ions::setAtoms( + const std::vector& crds, const std::vector& spec) { MGmol_MPI& mmpi(*(MGmol_MPI::instance())); Control& ct(*(Control::instance())); - const int natoms = crds.size()/3; + const int natoms = crds.size() / 3; double velocity[3] = { 0., 0., 0. }; bool locked = false; @@ -1827,7 +1828,7 @@ int Ions::setAtoms(std::vector& crds, std::vector& spec) } if (spname.compare("") == 0) { - (*MPIdata::serr) << "Ions::readAtomsFromXYZ() --- ERROR: unknown " + (*MPIdata::serr) << "Ions::setAtoms() --- ERROR: unknown " "species for atomic number " << spec[ia] << std::endl; return -1; @@ -1848,7 +1849,7 @@ int Ions::setAtoms(std::vector& crds, std::vector& spec) // Populate list_ions_ list // std::cout<<"crds: "<& tau) getLocalPositions(tau_local); - int n = getNumIons(); - tau.resize(3 * n); - MGmol_MPI& mmpi = *(MGmol_MPI::instance()); mmpi.allGatherV(tau_local, tau); } +void Ions::getAtomicNumbers(std::vector& atnumbers) +{ + std::vector local_atnumbers; + + for (auto& ion : local_ions_) + { + local_atnumbers.push_back(ion->atomic_number()); + } + + MGmol_MPI& mmpi = *(MGmol_MPI::instance()); + mmpi.allGatherV(local_atnumbers, atnumbers); +} + void Ions::getForces(std::vector& forces) { std::vector forces_local(3 * local_ions_.size()); @@ -2265,9 +2276,15 @@ void Ions::setPositionsToTau0() } } -void Ions::setPositions(const std::vector& tau) +void Ions::setPositions( + const std::vector& tau, const std::vector& anumbers) { - setLocalPositions(tau); + assert(tau.size() == anumbers.size() * 3); + + // clear previous data + clearLists(); + + num_ions_ = setAtoms(tau, anumbers); // setup required after updating local ions positions setup(); @@ -3171,6 +3188,18 @@ void Ions::updateTaupInteractingIons() } } +void Ions::clearLists() +{ + local_ions_.clear(); + std::vector::iterator ion = list_ions_.begin(); + while (ion != list_ions_.end()) + { + delete *ion; + ion++; + } + list_ions_.clear(); +} + // update list of local ions void Ions::updateListIons() { @@ -3195,15 +3224,7 @@ void Ions::updateListIons() // Note: this is based on data from MD std::vectors // First cleanup list_ions_ - local_ions_.clear(); - // delete current ions from list - std::vector::iterator ion = list_ions_.begin(); - while (ion != list_ions_.end()) - { - delete *ion; - ion++; - } - list_ions_.clear(); + clearLists(); // Update list starting with local ion data. // This enables overlapping data accumulation with communication. diff --git a/src/Ions.h b/src/Ions.h index 4157b760..37a4fbac 100644 --- a/src/Ions.h +++ b/src/Ions.h @@ -157,6 +157,7 @@ class Ions void gatherForces( std::vector& forces, const int root, const MPI_Comm comm) const; bool hasLockedAtoms() const; + void clearLists(); public: Ions(const double lat[3], const std::vector& sp); @@ -259,7 +260,8 @@ class Ions int readAtoms(const std::string& filename, const bool cell_relative); int readAtoms(std::ifstream* tfile, const bool cell_relative); void initFromRestartFile(HDFrestart& h5_file); - int setAtoms(std::vector& crds, std::vector& spec); + int setAtoms( + const std::vector& crds, const std::vector& spec); int getNValenceElectrons() const; void syncForces(); @@ -268,10 +270,13 @@ class Ions void setTau0(); void setPositionsToTau0(); void setVelocitiesToVel(); - void setPositions(const std::vector& tau); + void setPositions( + const std::vector& tau, const std::vector& anumbers); void getLocalPositions(std::vector& tau) const; void getPositions(std::vector& tau); + void getAtomicNumbers(std::vector& atnumbers); + void getForces(std::vector& forces); void getLocalForces(std::vector& tau) const; void syncData(const std::vector& sp); diff --git a/src/MGmol.cc b/src/MGmol.cc index 7516b5b1..e1f65d21 100644 --- a/src/MGmol.cc +++ b/src/MGmol.cc @@ -1411,13 +1411,22 @@ void MGmol::getAtomicPositions(std::vector& tau) ions_->getPositions(tau); } +template +void MGmol::getAtomicNumbers(std::vector& an) +{ + ions_->getAtomicNumbers(an); +} + template double MGmol::evaluateEnergyAndForces( - const std::vector& tau, std::vector& forces) + const std::vector& tau, std::vector& atnumbers, + std::vector& forces) { + assert(tau.size() == 3 * atnumbers.size()); + Control& ct = *(Control::instance()); - ions_->setPositions(tau); + ions_->setPositions(tau, atnumbers); double eks = 0.; quench(current_orbitals_, *ions_, ct.max_electronic_steps, 20, eks); diff --git a/src/MGmol.h b/src/MGmol.h index 5f5b4701..fd75cf21 100644 --- a/src/MGmol.h +++ b/src/MGmol.h @@ -180,14 +180,16 @@ class MGmol : public MGmolInterface void run() override; - double evaluateEnergyAndForces( - const std::vector& tau, std::vector& forces); + double evaluateEnergyAndForces(const std::vector& tau, + std::vector& atnumbers, std::vector& forces); /* * get internal atomic positions */ void getAtomicPositions(std::vector& tau); + void getAtomicNumbers(std::vector& an); + void initNuc(Ions& ions); void initKBR(); diff --git a/src/MGmolInterface.h b/src/MGmolInterface.h index 9766d776..046459d6 100644 --- a/src/MGmolInterface.h +++ b/src/MGmolInterface.h @@ -25,10 +25,11 @@ class MGmolInterface virtual int setupConstraintsFromInput(const std::string input_file) = 0; virtual void setup() = 0; virtual void run() = 0; - virtual double evaluateEnergyAndForces( - const std::vector& tau, std::vector& forces) + virtual double evaluateEnergyAndForces(const std::vector& tau, + std::vector& atnumbers, std::vector& forces) = 0; virtual void getAtomicPositions(std::vector& tau) = 0; + virtual void getAtomicNumbers(std::vector& an) = 0; }; #endif From 27cfd0205da9225caa4e904d3b662fb4c7d3d28c Mon Sep 17 00:00:00 2001 From: Jean-Luc Fattebert Date: Thu, 6 Jun 2024 10:28:25 -0400 Subject: [PATCH 4/4] Clean up --- src/Ions.cc | 63 ----------------------------------------------------- src/Ions.h | 12 +++++----- src/MGmol.h | 4 ---- 3 files changed, 6 insertions(+), 73 deletions(-) diff --git a/src/Ions.cc b/src/Ions.cc index 2a7e15e5..940e12e8 100644 --- a/src/Ions.cc +++ b/src/Ions.cc @@ -1582,69 +1582,6 @@ void Ions::setLocalPositions(const std::vector& tau) setup_ = false; } -void Ions::get_positions(std::vector>& rr) const -{ - assert(rr.size() == local_ions_.size()); - if (local_ions_.empty()) return; - std::vector tau(3); - int i = 0; - std::vector::const_iterator ion = local_ions_.begin(); - while (ion != local_ions_.end()) - { - tau[0] = (*ion)->position(0); - tau[1] = (*ion)->position(1); - tau[2] = (*ion)->position(2); - rr[i] = tau; - ion++; - i++; - } -} -void Ions::set_positions(const std::vector>& rr) -{ - assert(rr.size() == local_ions_.size()); - - if (local_ions_.empty()) return; - std::vector::iterator ion = local_ions_.begin(); - int i = 0; - while (ion != local_ions_.end()) - { - assert(rr[i].size() == 3); - (*ion)->setPosition(rr[i][0], rr[i][1], rr[i][2]); - ion++; - i++; - } -} -void Ions::get_forces(std::vector>& ff) const -{ - assert(ff.size() == local_ions_.size()); - - if (local_ions_.empty()) return; - int i = 0; - std::vector::const_iterator ion = local_ions_.begin(); - while (ion != local_ions_.end()) - { - ff[i][0] = (*ion)->force(0); - ff[i][1] = (*ion)->force(1); - ff[i][2] = (*ion)->force(2); - ion++; - i++; - } -} -void Ions::set_forces(const std::vector>& ff) -{ - assert(ff.size() == local_ions_.size()); - - if (local_ions_.empty()) return; - std::vector::iterator ion = local_ions_.begin(); - int i = 0; - while (ion != local_ions_.end()) - { - (*ion)->setForce(ff[i][0], ff[i][1], ff[i][2]); - ion++; - i++; - } -} - int Ions::readAtoms(const std::string& filename, const bool cell_relative) { diff --git a/src/Ions.h b/src/Ions.h index 37a4fbac..772c51d1 100644 --- a/src/Ions.h +++ b/src/Ions.h @@ -36,7 +36,12 @@ class Ions const std::vector& species_; std::vector list_ions_; - std::vector local_ions_; // centered in local sub-domain + + /* + * ions located in local sub-domain + */ + std::vector local_ions_; + std::vector interacting_ions_; // for ion-ion interactions std::vector overlappingNL_ions_; // with projectors overlapping local sub-domain @@ -61,7 +66,6 @@ class Ions void readRestartPositions(HDFrestart& h5_file); int read1atom(std::ifstream* tfile, const bool cell_relative); - // void associate2PE(); void setupInteractingIons(); void setupListOverlappingIons(); void setMapVL(); @@ -248,10 +252,6 @@ class Ions bool isLocal(const std::string& ion_name) const; void setLocalPositions(const std::vector& tau); - void get_positions(std::vector>& r) const; - void set_positions(const std::vector>& r); - void get_forces(std::vector>& f) const; - void set_forces(const std::vector>& f); void lockAtom(const std::string& name); diff --git a/src/MGmol.h b/src/MGmol.h index fd75cf21..cb5c54f3 100644 --- a/src/MGmol.h +++ b/src/MGmol.h @@ -287,10 +287,6 @@ class MGmol : public MGmolInterface double get_evnl(const Ions& ions); void sebprintPositions(); void sebprintForces(); - void get_positions(std::vector>& r); - void set_positions(std::vector>& r); - void get_forces(std::vector>& f); - void set_forces(std::vector>& f); int nions() { return ions_->getNumIons(); } double getTotalEnergy(); void cleanup();