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) void Atom::data_fix_compute_variable(int nprev, int nnew)
{ {
for (const auto &fix : modify->get_fix_list()) { for (const auto &ifix : modify->get_fix_list()) {
if (fix->create_attribute) if (ifix->create_attribute)
for (int i = nprev; i < nnew; i++) for (int i = nprev; i < nnew; i++)
fix->set_arrays(i); ifix->set_arrays(i);
} }
for (int m = 0; m < modify->ncompute; m++) { for (const auto &icompute : modify->get_compute_list()) {
Compute *compute = modify->compute[m]; if (icompute->create_attribute)
if (compute->create_attribute)
for (int i = nprev; i < nnew; i++) for (int i = nprev; i < nnew; i++)
compute->set_arrays(i); icompute->set_arrays(i);
} }
for (int i = nprev; i < nnew; i++) for (int i = nprev; i < nnew; i++)

View File

@ -17,6 +17,7 @@
#include "error.h" #include "error.h"
#include "fix.h" #include "fix.h"
#include "fix_adapt.h" #include "fix_adapt.h"
#include "fix_adapt_fep.h"
#include "math_const.h" #include "math_const.h"
#include "modify.h" #include "modify.h"
@ -88,12 +89,18 @@ void AtomVecSphere::init()
// check if optional radvary setting should have been set to 1 // check if optional radvary setting should have been set to 1
for (int i = 0; i < modify->nfix; i++) for (auto &ifix : modify->get_fix_by_style("^adapt")) {
if (strcmp(modify->fix[i]->style, "adapt") == 0) { if (utils::strmatch(ifix->style, "^adapt$")) {
auto fix = dynamic_cast<FixAdapt *>(modify->fix[i]); auto fix = dynamic_cast<FixAdapt *>(ifix);
if (fix->diamflag && radvary == 0) if (fix && fix->diamflag && radvary == 0)
error->all(FLERR, "Fix adapt changes particle radii but atom_style sphere is not dynamic"); 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); neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL);
int count = 0; if (modify->get_compute_by_style(style).size() > 1)
for (int i = 0; i < modify->ncompute; i++) if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
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");
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

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

View File

@ -76,19 +76,15 @@ void ComputeCNAAtom::init()
// cannot use neighbor->cutneighmax b/c neighbor has not yet been 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) if ((2.0 * sqrt(cutsq)) > (force->pair->cutforce + neighbor->skin) && (comm->me == 0))
error->warning(FLERR, error->warning(FLERR, "Compute cna/atom cutoff may be too large to find ghost atom neighbors");
"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");
// need an occasional full neighbor list // need an occasional full neighbor list
neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); 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]); id_orientorder = utils::strdup(arg[4]);
int iorientorder = modify->find_compute(id_orientorder); auto iorientorder = modify->get_compute_by_id(id_orientorder);
if (iorientorder < 0) error->all(FLERR, "Could not find compute coord/atom compute ID"); if (!iorientorder)
if (!utils::strmatch(modify->compute[iorientorder]->style, "^orientorder/atom")) error->all(FLERR, "Could not find compute coord/atom compute ID {}", id_orientorder);
error->all(FLERR, "Compute coord/atom compute ID is not orientorder/atom"); 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); threshold = utils::numeric(FLERR, arg[5], false, lmp);
if (threshold <= -1.0 || threshold >= 1.0) if (threshold <= -1.0 || threshold >= 1.0)
@ -128,8 +129,11 @@ ComputeCoordAtom::~ComputeCoordAtom()
void ComputeCoordAtom::init() void ComputeCoordAtom::init()
{ {
if (cstyle == ORIENT) { if (cstyle == ORIENT) {
int iorientorder = modify->find_compute(id_orientorder); c_orientorder =
c_orientorder = dynamic_cast<ComputeOrientOrderAtom *>(modify->compute[iorientorder]); 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; cutsq = c_orientorder->cutsq;
l = c_orientorder->qlcomp; l = c_orientorder->qlcomp;
// communicate real and imaginary 2*l+1 components of the normalized vector // communicate real and imaginary 2*l+1 components of the normalized vector

View File

@ -57,11 +57,8 @@ ComputeErotateSphereAtom::~ComputeErotateSphereAtom()
void ComputeErotateSphereAtom::init() void ComputeErotateSphereAtom::init()
{ {
int count = 0; if (modify->get_compute_by_style(style).size() > 1)
for (int i = 0; i < modify->ncompute; i++) if (comm->me == 0) error->warning(FLERR, "More than one compute {}", style);
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");
pfactor = 0.5 * force->mvv2e * INERTIA; pfactor = 0.5 * force->mvv2e * INERTIA;
} }

View File

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

View File

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