modernize access for fixes and computes

This commit is contained in:
Axel Kohlmeyer
2023-07-16 20:05:52 -04:00
parent 89d82fde22
commit 27aa6898f8
10 changed files with 45 additions and 53 deletions

View File

@ -1818,17 +1818,16 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset)
void Atom::data_fix_compute_variable(int nprev, int nnew)
{
for (const auto &fix : modify->get_fix_list()) {
if (fix->create_attribute)
for (const auto &ifix : modify->get_fix_list()) {
if (ifix->create_attribute)
for (int i = nprev; i < nnew; i++)
fix->set_arrays(i);
ifix->set_arrays(i);
}
for (int m = 0; m < modify->ncompute; m++) {
Compute *compute = modify->compute[m];
if (compute->create_attribute)
for (const auto &icompute : modify->get_compute_list()) {
if (icompute->create_attribute)
for (int i = nprev; i < nnew; i++)
compute->set_arrays(i);
icompute->set_arrays(i);
}
for (int i = nprev; i < nnew; i++)

View File

@ -17,6 +17,7 @@
#include "error.h"
#include "fix.h"
#include "fix_adapt.h"
#include "fix_adapt_fep.h"
#include "math_const.h"
#include "modify.h"
@ -88,12 +89,18 @@ void AtomVecSphere::init()
// check if optional radvary setting should have been set to 1
for (int i = 0; i < modify->nfix; i++)
if (strcmp(modify->fix[i]->style, "adapt") == 0) {
auto fix = dynamic_cast<FixAdapt *>(modify->fix[i]);
if (fix->diamflag && radvary == 0)
for (auto &ifix : modify->get_fix_by_style("^adapt")) {
if (utils::strmatch(ifix->style, "^adapt$")) {
auto fix = dynamic_cast<FixAdapt *>(ifix);
if (fix && fix->diamflag && radvary == 0)
error->all(FLERR, "Fix adapt changes particle radii but atom_style sphere is not dynamic");
}
if (utils::strmatch(ifix->style, "^adapt/fep$")) {
auto fix = dynamic_cast<FixAdaptFEP *>(ifix);
if (fix && fix->diamflag && radvary == 0)
error->all(FLERR, "Fix adapt/fep changes particle radii but atom_style sphere is not dynamic");
}
}
}
/* ----------------------------------------------------------------------

View File

@ -82,10 +82,8 @@ void ComputeAggregateAtom::init()
neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL);
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style, "aggregate/atom") == 0) count++;
if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute aggregate/atom");
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -93,14 +93,12 @@ void ComputeCentroAtom::init()
if (force->pair == nullptr)
error->all(FLERR, "Compute centro/atom requires a pair style be defined");
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style, "centro/atom") == 0) count++;
if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute centro/atom");
// need an occasional full neighbor list
neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL);
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -69,10 +69,8 @@ void ComputeClusterAtom::init()
neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL);
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style, "cluster/atom") == 0) count++;
if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute cluster/atom");
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -76,19 +76,15 @@ void ComputeCNAAtom::init()
// cannot use neighbor->cutneighmax b/c neighbor has not yet been init
if (2.0 * sqrt(cutsq) > force->pair->cutforce + neighbor->skin && comm->me == 0)
error->warning(FLERR,
"Compute cna/atom cutoff may be too large to find "
"ghost atom neighbors");
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style, "cna/atom") == 0) count++;
if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute cna/atom defined");
if ((2.0 * sqrt(cutsq)) > (force->pair->cutforce + neighbor->skin) && (comm->me == 0))
error->warning(FLERR, "Compute cna/atom cutoff may be too large to find ghost atom neighbors");
// need an occasional full neighbor list
neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL);
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -82,10 +82,11 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
id_orientorder = utils::strdup(arg[4]);
int iorientorder = modify->find_compute(id_orientorder);
if (iorientorder < 0) error->all(FLERR, "Could not find compute coord/atom compute ID");
if (!utils::strmatch(modify->compute[iorientorder]->style, "^orientorder/atom"))
error->all(FLERR, "Compute coord/atom compute ID is not orientorder/atom");
auto iorientorder = modify->get_compute_by_id(id_orientorder);
if (!iorientorder)
error->all(FLERR, "Could not find compute coord/atom compute ID {}", id_orientorder);
if (!utils::strmatch(iorientorder->style, "^orientorder/atom"))
error->all(FLERR, "Compute coord/atom compute ID {} is not orientorder/atom", id_orientorder);
threshold = utils::numeric(FLERR, arg[5], false, lmp);
if (threshold <= -1.0 || threshold >= 1.0)
@ -128,8 +129,11 @@ ComputeCoordAtom::~ComputeCoordAtom()
void ComputeCoordAtom::init()
{
if (cstyle == ORIENT) {
int iorientorder = modify->find_compute(id_orientorder);
c_orientorder = dynamic_cast<ComputeOrientOrderAtom *>(modify->compute[iorientorder]);
c_orientorder =
dynamic_cast<ComputeOrientOrderAtom *>(modify->get_compute_by_id(id_orientorder));
if (!c_orientorder)
error->all(FLERR, "Could not find compute coord/atom compute ID {}", id_orientorder);
cutsq = c_orientorder->cutsq;
l = c_orientorder->qlcomp;
// communicate real and imaginary 2*l+1 components of the normalized vector

View File

@ -57,11 +57,8 @@ ComputeErotateSphereAtom::~ComputeErotateSphereAtom()
void ComputeErotateSphereAtom::init()
{
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style,"erotate/sphere/atom") == 0) count++;
if (count > 1 && comm->me == 0)
error->warning(FLERR,"More than one compute erotate/sphere/atom");
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
pfactor = 0.5 * force->mvv2e * INERTIA;
}

View File

@ -84,11 +84,8 @@ void ComputeFragmentAtom::init()
if (atom->molecular != Atom::MOLECULAR)
error->all(FLERR,"Compute fragment/atom requires a molecular system");
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style,"fragment/atom") == 0) count++;
if (count > 1 && comm->me == 0)
error->warning(FLERR,"More than one compute fragment/atom");
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -47,10 +47,8 @@ ComputeKEAtom::~ComputeKEAtom()
void ComputeKEAtom::init()
{
int count = 0;
for (int i = 0; i < modify->ncompute; i++)
if (strcmp(modify->compute[i]->style, "ke/atom") == 0) count++;
if (count > 1 && comm->me == 0) error->warning(FLERR, "More than one compute ke/atom");
if (modify->get_compute_by_style(style).size() > 1)
if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
}
/* ---------------------------------------------------------------------- */