Skip to content

Commit

Permalink
Excess printing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyvala committed Jul 27, 2021
1 parent d1d529d commit 3c05bc8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/interface/LAMMPS/src/USER-NNP/pair_nnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interface/LAMMPS/src/USER-NNP/pair_nnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PairNNP : public Pair {

bool showew;
bool resetew;
bool maxcdExceeded;
int showewsum;
int maxew;
int globalNumAtoms;
Expand All @@ -54,7 +55,6 @@ class PairNNP : public Pair {
double cfenergy;
double maxCutoffRadius;
double maxcd;
double forceMaxCd;
char* directory;
char* emap;
std::vector<double> committeeSumForces;
Expand Down
14 changes: 7 additions & 7 deletions src/libnnpif/LAMMPS/InterfaceLammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,11 @@ std::vector<double> InterfaceLammps::getComDisForce(std::vector<double> const& g
return committeeSumForces;
}

double InterfaceLammps::averageComDis(std::vector<double> const& committeeSumForces)
bool InterfaceLammps::averageComDis(std::vector<double> 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));
Expand All @@ -457,13 +456,14 @@ double InterfaceLammps::averageComDis(std::vector<double> 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
Expand Down
83 changes: 43 additions & 40 deletions src/libnnpif/LAMMPS/InterfaceLammps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand All @@ -140,6 +157,20 @@ class InterfaceLammps : public Mode
*/
double getComDisEnergy(std::vector<double> 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.
Expand All @@ -150,22 +181,6 @@ class InterfaceLammps : public Mode
std::vector<double> getComDisForce(std::vector<double> 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<double> 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.
Expand All @@ -178,33 +193,21 @@ class InterfaceLammps : public Mode
* @return Return global force vector.
*/
std::vector<double> 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<double> 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.
Expand Down

0 comments on commit 3c05bc8

Please sign in to comment.