From 3c05bc8182009c0a792d337743cb8b146fb30ff9 Mon Sep 17 00:00:00 2001 From: Kyvala Date: Tue, 27 Jul 2021 12:05:56 +0200 Subject: [PATCH] Excess printing fix --- .../LAMMPS/src/USER-NNP/pair_nnp.cpp | 8 +- src/interface/LAMMPS/src/USER-NNP/pair_nnp.h | 2 +- src/libnnpif/LAMMPS/InterfaceLammps.cpp | 14 ++-- src/libnnpif/LAMMPS/InterfaceLammps.h | 83 ++++++++++--------- 4 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp b/src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp index 329ef0474b..0db8ccaa1c 100644 --- a/src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp +++ b/src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp @@ -81,7 +81,7 @@ void PairNNP::compute(int eflag, int vflag) committeeSumForces.assign(globalNumAtoms,0.0);} double* comSumForces = &committeeSumForces[0]; MPI_Bcast(comSumForces, globalNumAtoms, MPI_DOUBLE, 0, MPI_COMM_WORLD); - forceMaxCd = interface.averageComDis(committeeSumForces); + maxcdExceeded = interface.averageComDis(committeeSumForces, maxcd); } else { interface.getForces(atom->f); @@ -132,7 +132,7 @@ void PairNNP::settings(int narg, char **arg) comSize = 1; calcd = 1; maxcd = 0.0; - forceMaxCd = 0.0; + maxcdExceeded = false; resetew = false; cflength = 1.0; cfenergy = 1.0; @@ -490,8 +490,8 @@ void PairNNP::handleExtrapolationWarnings() // Stop if energy committee disagreement is exceeded. if (comSize > 1 && calcd > 0 && update->ntimestep % calcd == 0) { - if (forceMaxCd > maxcd) { - error->one(FLERR,"Force committee disagreement exceeded set threshold. See committee.txt"); + if (maxcdExceeded) { + error->one(FLERR,"Force committee disagreement exceeded set threshold. See committee-force.txt"); } } diff --git a/src/interface/LAMMPS/src/USER-NNP/pair_nnp.h b/src/interface/LAMMPS/src/USER-NNP/pair_nnp.h index 2b2a8ee9a1..51d7e2a6a6 100644 --- a/src/interface/LAMMPS/src/USER-NNP/pair_nnp.h +++ b/src/interface/LAMMPS/src/USER-NNP/pair_nnp.h @@ -43,6 +43,7 @@ class PairNNP : public Pair { bool showew; bool resetew; + bool maxcdExceeded; int showewsum; int maxew; int globalNumAtoms; @@ -54,7 +55,6 @@ class PairNNP : public Pair { double cfenergy; double maxCutoffRadius; double maxcd; - double forceMaxCd; char* directory; char* emap; std::vector committeeSumForces; diff --git a/src/libnnpif/LAMMPS/InterfaceLammps.cpp b/src/libnnpif/LAMMPS/InterfaceLammps.cpp index b2fedb2cd9..cdf7c28269 100644 --- a/src/libnnpif/LAMMPS/InterfaceLammps.cpp +++ b/src/libnnpif/LAMMPS/InterfaceLammps.cpp @@ -441,12 +441,11 @@ std::vector InterfaceLammps::getComDisForce(std::vector const& g return committeeSumForces; } -double InterfaceLammps::averageComDis(std::vector const& committeeSumForces) +bool InterfaceLammps::averageComDis(std::vector const& committeeSumForces, double const& maxcd) { Atom* ai = NULL; - double maxcd{0.0}; + bool maxcdExceeded{false}; ofstream outfile; - outfile.open("committee-force.txt", std::ios_base::app); for (size_t i = 0; i < structure.atoms.size(); ++i) { ai = &(structure.atoms.at(i)); @@ -457,13 +456,14 @@ double InterfaceLammps::averageComDis(std::vector const& committeeSumFor } ai->aveComDis = sqrt(ai->aveComDis/(3*(ai->numNeighborsCom+1))); if (ai->aveComDis > maxcd){ - maxcd = ai->aveComDis; + maxcdExceeded = true; + outfile.open("committee-force.txt", std::ios_base::app); + outfile << strpr("%i %16.6E %i\n", ai->tag, ai->aveComDis, ai->numNeighborsCom+1); + outfile.close(); } - outfile << strpr("%i %16.6E %i\n", ai->tag, ai->aveComDis, ai->numNeighborsCom+1); } - outfile.close(); - return maxcd; + return maxcdExceeded; } double InterfaceLammps::getAtomicEnergy(int index) const diff --git a/src/libnnpif/LAMMPS/InterfaceLammps.h b/src/libnnpif/LAMMPS/InterfaceLammps.h index 2c12e34d88..ce510b6df9 100644 --- a/src/libnnpif/LAMMPS/InterfaceLammps.h +++ b/src/libnnpif/LAMMPS/InterfaceLammps.h @@ -111,6 +111,18 @@ class InterfaceLammps : public Mode * energy contributions. */ void process(); + /** Calculate forces and add to LAMMPS atomic force arrays. + * + * @param[in,out] atomF LAMMPS force array for local and ghost atoms. + */ + void getForces(double* const* const& atomF) const; + /** Calculate forces and add to LAMMPS atomic force arrays and local force array. + * + * @param[in,out] atomF LAMMPS force array for local and ghost atoms. + * @param[in] globalNumAtoms Global number of atoms. + */ + void getForcesCom(double* const* const& atomF, + int const& globalNumAtoms) const; /** Return committee size. * * @return Return committee size. @@ -120,16 +132,21 @@ class InterfaceLammps : public Mode * * @return Return committee cutoff. */ - double getComCutoff() const; - /** Get global number of atoms. - * - * @return Return global number of atoms. - */ int reduceNumAtoms() const; /** Return sum of local energy contributions. * * @return Sum of local energy contributions. */ + double getComCutoff() const; + /** Get largest cutoff. + * + * @return Largest cutoff of all symmetry functions. + */ + double getMaxCutoffRadius() const; + /** Get global number of atoms. + * + * @return Return global number of atoms. + */ double getEnergy() const; /** Return global energy committee disagreement. * @@ -140,6 +157,20 @@ class InterfaceLammps : public Mode */ double getComDisEnergy(std::vector const& globalEnergyCom, int const& globalNumAtoms); + /** Return energy contribution of one atom. + * + * @param[in] index Atom index. + * + * @return energy contribution of atom with given index. + * + * @attention These atomic contributions are not physical! + */ + double getAtomicEnergy(int index) const; + /** Calculate buffer size for extrapolation warning communication. + * + * @return Buffer size. + */ + long getEWBufferSize() const; /** Return global force committee disagreement per atom. * * @param[in] globalForceCom Reduced force committee vector. @@ -150,22 +181,6 @@ class InterfaceLammps : public Mode std::vector getComDisForce(std::vector const& globalForceCom, std::size_t const& globalNumAtoms, std::size_t const& comSize) const; - /** Calculate averaged force committee disagreement over committee cutoff. - * - * @param[in] committeeSumForces Square norm of force committee disagrement. - * - * @return Return maximum force committee disagreement per atom. - */ - double averageComDis(std::vector const& committeeSumForces); - /** Return energy contribution of one atom. - * - * @param[in] index Atom index. - * - * @return energy contribution of atom with given index. - * - * @attention These atomic contributions are not physical! - */ - double getAtomicEnergy(int index) const; /** Reduce local committee energy contributions to global committee energy. * * @return Return global committee energy. @@ -178,33 +193,21 @@ class InterfaceLammps : public Mode * @return Return global force vector. */ std::vector reduceForceCom(int const& globalNumAtoms) const; - /** Calculate forces and add to LAMMPS atomic force arrays. + /** Calculate averaged force committee disagreement over committee cutoff. + * + * @param[in] committeeSumForces Square norm of force committee disagrement. * - * @param[in,out] atomF LAMMPS force array for local and ghost atoms. - */ - void getForces(double* const* const& atomF) const; - /** Calculate forces and add to LAMMPS atomic force arrays and local force array. + * @param[in] maxd Force committee disagreent threshold. * - * @param[in,out] atomF LAMMPS force array for local and ghost atoms. - * @param[in] globalNumAtoms Global number of atoms. + * @return True if maxcd is exceeded. */ - void getForcesCom(double* const* const& atomF, - int const& globalNumAtoms) const; + bool averageComDis(std::vector const& committeeSumForces, + double const& maxcd); /** Check if this interface is correctly initialized. * * @return `True` if initialized, `False` otherwise. */ bool isInitialized() const; - /** Get largest cutoff. - * - * @return Largest cutoff of all symmetry functions. - */ - double getMaxCutoffRadius() const; - /** Calculate buffer size for extrapolation warning communication. - * - * @return Buffer size. - */ - long getEWBufferSize() const; /** Fill provided buffer with extrapolation warning entries. * * @param[in,out] buf Communication buffer to fill.