diff --git a/src/.gitignore b/src/.gitignore index 49148e6666..a590048622 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1191,6 +1191,8 @@ /pair_oxrna2_*.cpp /pair_oxrna2_*.h /mf_oxdna.h +/pair_peri.cpp +/pair_peri.h /pair_peri_eps.cpp /pair_peri_eps.h /pair_peri_lps.cpp diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 4c83e13a7b..34963430e3 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -41,7 +41,6 @@ using namespace MathConst; enum{ATOM,MOLECULE}; enum{ONE,RANGE,POLY}; -enum{CONSTANT,EQUAL}; // same as FixGravity #define EPSILON 0.001 #define SMALL 1.0e-10 @@ -186,10 +185,12 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : // grav = gravity in distance/time^2 units // assume grav = -magnitude at this point, enforce in init() - int ifix = modify->find_fix_by_style("^gravity"); - if (ifix == -1) - error->all(FLERR,"No fix gravity defined for fix pour"); - grav = - ((FixGravity *) modify->fix[ifix])->magnitude * force->ftm2v; + auto fixlist = modify->get_fix_by_style("^gravity"); + if (fixlist.size() != 1) + error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + auto fixgrav = (FixGravity *)fixlist.front(); + + grav = -fixgrav->magnitude * force->ftm2v; // nfreq = timesteps between insertions // should be time for a particle to fall from top of insertion region @@ -208,9 +209,8 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : v_relative = vy - rate; delta = yhi - ylo; } - double t = - (-v_relative - sqrt(v_relative*v_relative - 2.0*grav*delta)) / grav; - nfreq = static_cast (t/update->dt + 0.5); + double t = (-v_relative - sqrt(v_relative*v_relative - 2.0*grav*delta)) / grav; + nfreq = static_cast(t/update->dt + 0.5); // 1st insertion on next timestep @@ -309,17 +309,16 @@ void FixPour::init() // for 3d must point in -z, for 2d must point in -y // else insertion cannot work - int ifix = modify->find_fix_by_style("^gravity"); - if (ifix == -1) - error->all(FLERR,"No fix gravity defined for fix pour"); - - int varflag = ((FixGravity *) modify->fix[ifix])->varflag; - if (varflag != CONSTANT) + auto fixlist = modify->get_fix_by_style("^gravity"); + if (fixlist.size() != 1) + error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + auto fixgrav = (FixGravity *)fixlist.front(); + if (fixgrav->varflag != FixGravity::CONSTANT) error->all(FLERR,"Fix gravity for fix pour must be constant"); - double xgrav = ((FixGravity *) modify->fix[ifix])->xgrav; - double ygrav = ((FixGravity *) modify->fix[ifix])->ygrav; - double zgrav = ((FixGravity *) modify->fix[ifix])->zgrav; + double xgrav = fixgrav->xgrav; + double ygrav = fixgrav->ygrav; + double zgrav = fixgrav->zgrav; if (domain->dimension == 3) { if (fabs(xgrav) > EPSILON || fabs(ygrav) > EPSILON || @@ -331,37 +330,29 @@ void FixPour::init() error->all(FLERR,"Gravity must point in -y to use with fix pour in 2d"); } - double gnew = - ((FixGravity *) modify->fix[ifix])->magnitude * force->ftm2v; - if (gnew != grav) - error->all(FLERR,"Gravity changed since fix pour was created"); + double gnew = -fixgrav->magnitude * force->ftm2v; + if (gnew != grav) error->all(FLERR,"Gravity changed since fix pour was created"); // if rigidflag defined, check for rigid/small fix // its molecule template must be same as this one - fixrigid = nullptr; if (rigidflag) { - int ifix = modify->find_fix(idrigid); - if (ifix < 0) error->all(FLERR,"Fix pour rigid fix does not exist"); - fixrigid = modify->fix[ifix]; + fixrigid = modify->get_fix_by_id(idrigid); + if (!fixrigid) error->all(FLERR,"Fix pour rigid fix does not exist"); int tmp; if (onemols != (Molecule **) fixrigid->extract("onemol",tmp)) - error->all(FLERR, - "Fix pour and fix rigid/small not using " - "same molecule template ID"); + error->all(FLERR,"Fix pour and fix rigid/small not using same molecule template ID"); } // if shakeflag defined, check for SHAKE fix // its molecule template must be same as this one - fixshake = nullptr; if (shakeflag) { - int ifix = modify->find_fix(idshake); - if (ifix < 0) error->all(FLERR,"Fix pour shake fix does not exist"); - fixshake = modify->fix[ifix]; + fixshake = modify->get_fix_by_id(idshake); + if (!fixshake) error->all(FLERR,"Fix pour shake fix does not exist"); int tmp; if (onemols != (Molecule **) fixshake->extract("onemol",tmp)) - error->all(FLERR,"Fix pour and fix shake not using " - "same molecule template ID"); + error->all(FLERR,"Fix pour and fix shake not using same molecule template ID"); } } diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index d4ffbf5e93..3e1578724b 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -461,24 +461,29 @@ void PairGranHookeHistory::init_style() // check for FixFreeze and set freeze_group_bit - int ifreeze = modify->find_fix_by_style("^freeze"); - if (ifreeze < 0) + auto fixlist = modify->get_fix_by_style("^freeze"); + if (fixlist.size() == 0) freeze_group_bit = 0; + else if (fixlist.size() > 1) + error->all(FLERR, "Only one fix freeze command at a time allowed"); else - freeze_group_bit = modify->fix[ifreeze]->groupbit; + freeze_group_bit = fixlist.front()->groupbit; // check for FixRigid so can extract rigid body masses - // FIXME: this only catches the first rigid fix, there may be multiple. fix_rigid = nullptr; - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) break; - if (i < modify->nfix) fix_rigid = modify->fix[i]; + for (const auto &ifix : modify->get_fix_list()) { + if (ifix->rigid_flag) { + if (fix_rigid) + error->all(FLERR, "Only one fix rigid command at a time allowed"); + else fix_rigid = ifix; + } + } // check for FixPour and FixDeposit so can extract particle radii - int ipour = modify->find_fix_by_style("^pour"); - int idep = modify->find_fix_by_style("^deposit"); + auto pours = modify->get_fix_by_style("^pour"); + auto deps = modify->get_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -486,13 +491,15 @@ void PairGranHookeHistory::init_style() int itype; for (i = 1; i <= atom->ntypes; i++) { onerad_dynamic[i] = onerad_frozen[i] = 0.0; - if (ipour >= 0) { + for (auto &ipour : pours) { itype = i; - onerad_dynamic[i] = *((double *) modify->fix[ipour]->extract("radius", itype)); + double maxrad = *((double *) ipour->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } - if (idep >= 0) { + for (auto &idep : deps) { itype = i; - onerad_dynamic[i] = *((double *) modify->fix[idep]->extract("radius", itype)); + double maxrad = *((double *) idep->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } } @@ -501,11 +508,12 @@ void PairGranHookeHistory::init_style() int *type = atom->type; int nlocal = atom->nlocal; - for (i = 0; i < nlocal; i++) + for (i = 0; i < nlocal; i++) { if (mask[i] & freeze_group_bit) onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]], radius[i]); else onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]], radius[i]); + } MPI_Allreduce(&onerad_dynamic[1], &maxrad_dynamic[1], atom->ntypes, MPI_DOUBLE, MPI_MAX, world); MPI_Allreduce(&onerad_frozen[1], &maxrad_frozen[1], atom->ntypes, MPI_DOUBLE, MPI_MAX, world); @@ -513,9 +521,8 @@ void PairGranHookeHistory::init_style() // set fix which stores history info if (history) { - int ifix = modify->find_fix("NEIGH_HISTORY_HH" + std::to_string(instance_me)); - if (ifix < 0) error->all(FLERR, "Could not find pair fix neigh history ID"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + fix_history = (FixNeighHistory *) modify->get_fix_by_id("NEIGH_HISTORY_HH" + std::to_string(instance_me)); + if (!fix_history) error->all(FLERR,"Could not find pair fix neigh history ID"); } } diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index ccfbea5b1f..049e19c4b6 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -1140,22 +1140,29 @@ void PairGranular::init_style() // check for FixFreeze and set freeze_group_bit - int ifix = modify->find_fix_by_style("^freeze"); - if (ifix < 0) freeze_group_bit = 0; - else freeze_group_bit = modify->fix[ifix]->groupbit; + auto fixlist = modify->get_fix_by_style("^freeze"); + if (fixlist.size() == 0) + freeze_group_bit = 0; + else if (fixlist.size() > 1) + error->all(FLERR, "Only one fix freeze command at a time allowed"); + else + freeze_group_bit = fixlist.front()->groupbit; // check for FixRigid so can extract rigid body masses - // FIXME: this only catches the first rigid fix, there may be multiple. fix_rigid = nullptr; - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) break; - if (i < modify->nfix) fix_rigid = modify->fix[i]; + for (const auto &ifix : modify->get_fix_list()) { + if (ifix->rigid_flag) { + if (fix_rigid) + error->all(FLERR, "Only one fix rigid command at a time allowed"); + else fix_rigid = ifix; + } + } // check for FixPour and FixDeposit so can extract particle radii - int ipour = modify->find_fix_by_style("^pour"); - int idep = modify->find_fix_by_style("^deposit"); + auto pours = modify->get_fix_by_style("^pour"); + auto deps = modify->get_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -1163,15 +1170,15 @@ void PairGranular::init_style() int itype; for (i = 1; i <= atom->ntypes; i++) { onerad_dynamic[i] = onerad_frozen[i] = 0.0; - if (ipour >= 0) { + for (auto &ipour : pours) { itype = i; - double radmax = *((double *) modify->fix[ipour]->extract("radius",itype)); - onerad_dynamic[i] = radmax; + double maxrad = *((double *) ipour->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } - if (idep >= 0) { + for (auto &idep : deps) { itype = i; - double radmax = *((double *) modify->fix[idep]->extract("radius",itype)); - onerad_dynamic[i] = radmax; + double maxrad = *((double *) idep->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } } @@ -1181,12 +1188,10 @@ void PairGranular::init_style() int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - double radius_cut = radius[i]; - if (mask[i] & freeze_group_bit) { - onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]],radius_cut); - } else { - onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]],radius_cut); - } + if (mask[i] & freeze_group_bit) + onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]], radius[i]); + else + onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]], radius[i]); } MPI_Allreduce(&onerad_dynamic[1],&maxrad_dynamic[1],atom->ntypes,MPI_DOUBLE,MPI_MAX,world); @@ -1195,9 +1200,8 @@ void PairGranular::init_style() // set fix which stores history info if (size_history > 0) { - int ifix = modify->find_fix("NEIGH_HISTORY_GRANULAR"); - if (ifix < 0) error->all(FLERR,"Could not find pair fix neigh history ID"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + fix_history = (FixNeighHistory *) modify->get_fix_by_id("NEIGH_HISTORY_GRANULAR"); + if (!fix_history) error->all(FLERR,"Could not find pair fix neigh history ID"); } } diff --git a/src/KOKKOS/fix_gravity_kokkos.cpp b/src/KOKKOS/fix_gravity_kokkos.cpp index ec6afbc133..63ac87a786 100644 --- a/src/KOKKOS/fix_gravity_kokkos.cpp +++ b/src/KOKKOS/fix_gravity_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -enum{CONSTANT,EQUAL}; - /* ---------------------------------------------------------------------- */ template diff --git a/src/KOKKOS/pair_reaxff_kokkos.cpp b/src/KOKKOS/pair_reaxff_kokkos.cpp index 43a650efb2..8d9c498005 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.cpp +++ b/src/KOKKOS/pair_reaxff_kokkos.cpp @@ -144,18 +144,15 @@ void PairReaxFFKokkos::init_style() acks2_flag = api->system->acks2_flag; if (acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - Fix* fix = modify->fix[ifix]; - if (!fix->kokkosable) + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + if (!ifix->kokkosable) error->all(FLERR,"Must use Kokkos version of acks2/reaxff with pair reaxff/kk"); - if (fix->execution_space == Host) { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + if (ifix->execution_space == Host) { + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } else { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } @@ -726,16 +723,13 @@ void PairReaxFFKokkos::compute(int eflag_in, int vflag_in) d_ilist = k_list->d_ilist; if (acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - Fix* fix = modify->fix[ifix]; - if (fix->execution_space == Host) { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + if (ifix->execution_space == Host) { + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } else { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } diff --git a/src/MDI/mdi_engine.cpp b/src/MDI/mdi_engine.cpp index 5194c44189..4ae1c80a9a 100644 --- a/src/MDI/mdi_engine.cpp +++ b/src/MDI/mdi_engine.cpp @@ -20,8 +20,8 @@ #include "atom.h" #include "error.h" -#include "integrate.h" #include "fix_mdi_engine.h" +#include "integrate.h" #include "mdi.h" #include "min.h" #include "modify.h" @@ -176,17 +176,13 @@ void MDIEngine::command(int narg, char ** /*arg*/) // if the mdi/engine fix is not already present, add it now - int ifix = modify->find_fix_by_style("mdi/engine"); bool added_mdi_engine_fix = false; - if (ifix < 0) { - modify->add_fix("MDI_ENGINE_INTERNAL all mdi/engine"); + auto fixes = modify->get_fix_by_style("mdi/engine"); + if (fixes.size() == 0) { added_mdi_engine_fix = true; - } - - // identify the mdi_engine fix - - ifix = modify->find_fix_by_style("mdi/engine"); - mdi_fix = static_cast(modify->fix[ifix]); + mdi_fix = (FixMDIEngine *) modify->add_fix("MDI_ENGINE_INTERNAL all mdi/engine"); + } else + mdi_fix = (FixMDIEngine *) fixes.front(); // check that LAMMPS is setup as a compatible MDI engine @@ -224,7 +220,7 @@ void MDIEngine::command(int narg, char ** /*arg*/) error->all(FLERR, "MDI node exited with invalid command: {}", command); } - // remove mdi/engine fix that mdi/engine instantiated + // remove mdi/engine fix if instantiated here by mdi/engine if (added_mdi_engine_fix) modify->delete_fix("MDI_ENGINE_INTERNAL"); } diff --git a/src/OPENMP/fix_gravity_omp.cpp b/src/OPENMP/fix_gravity_omp.cpp index 7354ec2aa4..72d2fdc59b 100644 --- a/src/OPENMP/fix_gravity_omp.cpp +++ b/src/OPENMP/fix_gravity_omp.cpp @@ -30,7 +30,6 @@ using namespace LAMMPS_NS; using namespace FixConst; enum{CHUTE,SPHERICAL,GRADIENT,VECTOR}; -enum{CONSTANT,EQUAL}; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/pair_peri_lps_omp.cpp b/src/OPENMP/pair_peri_lps_omp.cpp index b88794e274..0eefe8d55c 100644 --- a/src/OPENMP/pair_peri_lps_omp.cpp +++ b/src/OPENMP/pair_peri_lps_omp.cpp @@ -113,10 +113,10 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -225,7 +225,7 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) // Compute the dilatation on each particle if (iifrom < nlocal) - compute_dilatation_thr(iifrom, iito); + compute_dilatation(iifrom, iito); // wait until all threads are done before communication sync_threads(); @@ -237,7 +237,7 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) comm->forward_comm_pair(this); // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); } sync_threads(); @@ -363,93 +363,6 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) /* ---------------------------------------------------------------------- */ -void PairPeriLPSOMP::compute_dilatation_thr(int ifrom, int ito) -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = ifrom; i < ito; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // Look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // Skip if particle is "lost" - if (j < 0) continue; - - // Compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - -/* ---------------------------------------------------------------------- */ - double PairPeriLPSOMP::memory_usage() { double bytes = memory_usage_thr(); diff --git a/src/OPENMP/pair_peri_lps_omp.h b/src/OPENMP/pair_peri_lps_omp.h index 4bb71bbe5f..758e17bcf3 100644 --- a/src/OPENMP/pair_peri_lps_omp.h +++ b/src/OPENMP/pair_peri_lps_omp.h @@ -37,9 +37,6 @@ class PairPeriLPSOMP : public PairPeriLPS, public ThrOMP { virtual void compute(int, int); virtual double memory_usage(); - protected: - void compute_dilatation_thr(int ifrom, int ito); - private: template void eval(int ifrom, int ito, ThrData *const thr); diff --git a/src/OPENMP/pair_peri_pmb_omp.cpp b/src/OPENMP/pair_peri_pmb_omp.cpp index 73abf1c7e9..54d5969d8f 100644 --- a/src/OPENMP/pair_peri_pmb_omp.cpp +++ b/src/OPENMP/pair_peri_pmb_omp.cpp @@ -109,9 +109,9 @@ void PairPeriPMBOMP::eval(int iifrom, int iito, ThrData * const thr) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; // lc = lattice constant // init_style guarantees it's the same in x, y, and z diff --git a/src/OPENMP/pair_reaxff_omp.cpp b/src/OPENMP/pair_reaxff_omp.cpp index d39672f09b..454f56c55f 100644 --- a/src/OPENMP/pair_reaxff_omp.cpp +++ b/src/OPENMP/pair_reaxff_omp.cpp @@ -101,15 +101,17 @@ PairReaxFFOMP::~PairReaxFFOMP() void PairReaxFFOMP::init_style() { - bool have_qeq = ((modify->find_fix_by_style("^qeq/reax") != -1) - || (modify->find_fix_by_style("^qeq/shielded") != -1) - || (modify->find_fix_by_style("^acks2/reax") != -1)); - if (!have_qeq && qeqflag == 1) - error->all(FLERR,"Pair reaxff/omp requires use of fix qeq/reaxff or qeq/shielded" - " or fix acks2/reaxff"); + if (!atom->q_flag) error->all(FLERR,"Pair style reaxff/omp requires atom attribute q"); - int have_acks2 = (modify->find_fix_by_style("^acks2/reax") != -1); - api->system->acks2_flag = have_acks2; + auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); + int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size(); + + if (qeqflag && (have_qeq != 1)) + error->all(FLERR,"Pair style reaxff/omp requires use of exactly one of the " + "fix qeq/reaxff or fix qeq/shielded or fix acks2/reaxff commands"); + + api->system->acks2_flag = acks2_fixes.size(); if (api->system->acks2_flag) error->all(FLERR,"Cannot (yet) use ACKS2 with OPENMP ReaxFF"); diff --git a/src/OPENMP/respa_omp.cpp b/src/OPENMP/respa_omp.cpp index cc4d3925b1..c6500185ad 100644 --- a/src/OPENMP/respa_omp.cpp +++ b/src/OPENMP/respa_omp.cpp @@ -67,21 +67,23 @@ void RespaOMP::init() void RespaOMP::setup(int flag) { if (comm->me == 0 && screen) { - fprintf(screen,"Setting up r-RESPA/omp run ...\n"); + std::string mesg = "Setting up r-RESPA/omp run ...\n"; if (flag) { - fprintf(screen," Unit style : %s\n", update->unit_style); - fprintf(screen," Current step : " BIGINT_FORMAT "\n", update->ntimestep); - fprintf(screen," Time steps :"); - for (int ilevel=0; ilevel < nlevels; ++ilevel) - fprintf(screen," %d:%g",ilevel+1, step[ilevel]); - fprintf(screen,"\n r-RESPA fixes :"); - for (int l=0; l < modify->n_post_force_respa; ++l) { - Fix *f = modify->fix[modify->list_post_force_respa[l]]; + mesg += fmt::format(" Unit style : {}\n", update->unit_style); + mesg += fmt::format(" Current step : {}\n", update->ntimestep); + + mesg += " Time steps :"; + for (int ilevel = 0; ilevel < nlevels; ++ilevel) + mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); + + mesg += "\n r-RESPA fixes :"; + for (int l = 0; l < modify->n_post_force_respa; ++l) { + Fix *f = modify->get_fix_by_index(modify->list_post_force_respa[l]); if (f->respa_level >= 0) - fprintf(screen," %d:%s[%s]", - MIN(f->respa_level+1,nlevels),f->style,f->id); + mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); } - fprintf(screen,"\n"); + mesg += "\n"; + fputs(mesg.c_str(), screen); timer->print_timeout(screen); } } diff --git a/src/PERI/compute_damage_atom.cpp b/src/PERI/compute_damage_atom.cpp index 1e5a6102dc..6349d324b2 100644 --- a/src/PERI/compute_damage_atom.cpp +++ b/src/PERI/compute_damage_atom.cpp @@ -17,21 +17,23 @@ ------------------------------------------------------------------------- */ #include "compute_damage_atom.h" -#include + #include "atom.h" -#include "update.h" -#include "modify.h" #include "comm.h" +#include "error.h" #include "fix_peri_neigh.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeDamageAtom::ComputeDamageAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), damage(nullptr) + Compute(lmp, narg, arg), damage(nullptr), fix_peri_neigh(nullptr) { if (narg != 3) error->all(FLERR,"Illegal compute damage/atom command"); @@ -52,17 +54,15 @@ ComputeDamageAtom::~ComputeDamageAtom() void ComputeDamageAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"damage/peri") == 0) count++; - if (count > 1 && comm->me == 0) - error->warning(FLERR,"More than one compute damage/atom"); + if ((comm->me == 0) && (modify->get_compute_by_style("damage/atom").size() > 1)) + error->warning(FLERR,"More than one compute dilatation/atom"); // find associated PERI_NEIGH fix that must exist - ifix_peri = modify->find_fix_by_style("PERI_NEIGH"); - if (ifix_peri == -1) + auto fixes = modify->get_fix_by_style("PERI_NEIGH"); + if (fixes.size() == 0) error->all(FLERR,"Compute damage/atom requires a peridynamic potential"); + else fix_peri_neigh = (FixPeriNeigh *)fixes.front(); } /* ---------------------------------------------------------------------- */ @@ -85,9 +85,9 @@ void ComputeDamageAtom::compute_peratom() int nlocal = atom->nlocal; int *mask = atom->mask; double *vfrac = atom->vfrac; - double *vinter = ((FixPeriNeigh *) modify->fix[ifix_peri])->vinter; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double *vinter = fix_peri_neigh->vinter; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; int i,j,jj,jnum; double damage_temp; diff --git a/src/PERI/compute_damage_atom.h b/src/PERI/compute_damage_atom.h index 7530a1cb02..43b28c3794 100644 --- a/src/PERI/compute_damage_atom.h +++ b/src/PERI/compute_damage_atom.h @@ -35,7 +35,7 @@ class ComputeDamageAtom : public Compute { private: int nmax; double *damage; - int ifix_peri; + class FixPeriNeigh *fix_peri_neigh; }; } // namespace LAMMPS_NS diff --git a/src/PERI/compute_dilatation_atom.cpp b/src/PERI/compute_dilatation_atom.cpp index 7735bbbaac..fe78bc76bf 100644 --- a/src/PERI/compute_dilatation_atom.cpp +++ b/src/PERI/compute_dilatation_atom.cpp @@ -24,9 +24,7 @@ #include "force.h" #include "memory.h" #include "modify.h" -#include "pair_peri_eps.h" -#include "pair_peri_lps.h" -#include "pair_peri_ves.h" +#include "pair.h" #include "update.h" #include @@ -59,28 +57,13 @@ ComputeDilatationAtom::~ComputeDilatationAtom() void ComputeDilatationAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"dilatation/peri") == 0) count++; - if (count > 1 && comm->me == 0) + if ((comm->me == 0) && (modify->get_compute_by_style("dilatation/atom").size() > 1)) error->warning(FLERR,"More than one compute dilatation/atom"); - // check PD pair style + // check for compatible pair style - isPMB = isLPS = isVES = isEPS = 0; - if (force->pair_match("^peri/pmb",0)) isPMB = 1; - if (force->pair_match("^peri/lps",0)) isLPS = 1; - if (force->pair_match("^peri/ves",0)) isVES = 1; - if (force->pair_match("^peri/eps",0)) isEPS = 1; - - if (isPMB) - error->all(FLERR,"Compute dilatation/atom cannot be used " - "with this pair style"); - - // find associated PERI_NEIGH fix that must exist - - if (modify->find_fix_by_style("^PERI_NEIGH") == -1) - error->all(FLERR,"Compute dilatation/atom requires Peridynamic pair style"); + if ((force->pair_match("^peri",0) == nullptr) || force->pair_match("^peri/pmb",0)) + error->all(FLERR,"Compute dilatation/atom cannot be used with this pair style"); } /* ---------------------------------------------------------------------- */ @@ -100,11 +83,9 @@ void ComputeDilatationAtom::compute_peratom() // extract dilatation for each atom in group - double *theta; - Pair *anypair = force->pair_match("peri",0); - if (isLPS) theta = ((PairPeriLPS *) anypair)->theta; - if (isVES) theta = ((PairPeriVES *) anypair)->theta; - if (isEPS) theta = ((PairPeriEPS *) anypair)->theta; + int tmp; + auto anypair = force->pair_match("^peri",0); + double *theta = (double *)anypair->extract("theta",tmp); int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/PERI/compute_dilatation_atom.h b/src/PERI/compute_dilatation_atom.h index ee675c0bb7..476634753d 100644 --- a/src/PERI/compute_dilatation_atom.h +++ b/src/PERI/compute_dilatation_atom.h @@ -25,11 +25,6 @@ ComputeStyle(dilatation/atom,ComputeDilatationAtom); namespace LAMMPS_NS { class ComputeDilatationAtom : public Compute { - friend class PairPeriPMB; - friend class PairPeriLPS; - friend class PairPeriVES; - friend class PairPeriEPS; - public: ComputeDilatationAtom(class LAMMPS *, int, char **); ~ComputeDilatationAtom(); @@ -40,7 +35,6 @@ class ComputeDilatationAtom : public Compute { private: int nmax; double *dilatation; - int isPMB, isLPS, isVES, isEPS; }; } // namespace LAMMPS_NS diff --git a/src/PERI/compute_plasticity_atom.cpp b/src/PERI/compute_plasticity_atom.cpp index 74d4b298a7..11ecdfb7ec 100644 --- a/src/PERI/compute_plasticity_atom.cpp +++ b/src/PERI/compute_plasticity_atom.cpp @@ -17,22 +17,23 @@ ------------------------------------------------------------------------- */ #include "compute_plasticity_atom.h" -#include + #include "atom.h" -#include "update.h" -#include "modify.h" #include "comm.h" +#include "error.h" #include "fix_peri_neigh.h" #include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -ComputePlasticityAtom:: -ComputePlasticityAtom(LAMMPS *lmp, int narg, char **arg) : +ComputePlasticityAtom::ComputePlasticityAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg) { if (narg != 3) error->all(FLERR,"Illegal compute plasticity/atom command"); @@ -59,17 +60,15 @@ ComputePlasticityAtom::~ComputePlasticityAtom() void ComputePlasticityAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"plasticity/peri") == 0) count++; - if (count > 1 && comm->me == 0) + if ((comm->me == 0) && (modify->get_compute_by_style("plasticity/atom").size() > 1)) error->warning(FLERR,"More than one compute plasticity/atom"); // find associated PERI_NEIGH fix that must exist - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Compute plasticity/atom requires a Peridynamics pair style"); + auto fixes = modify->get_fix_by_style("PERI_NEIGH"); + if (fixes.size() == 0) + error->all(FLERR,"Compute plasticity/atom requires a peridynamic potential"); + else fix_peri_neigh = (FixPeriNeigh *)fixes.front(); } /* ---------------------------------------------------------------------- */ @@ -89,7 +88,7 @@ void ComputePlasticityAtom::compute_peratom() // extract plasticity for each atom in group - double *lambdaValue = ((FixPeriNeigh *) modify->fix[ifix_peri])->lambdaValue; + double *lambdaValue = fix_peri_neigh->lambdaValue; int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/PERI/compute_plasticity_atom.h b/src/PERI/compute_plasticity_atom.h index b77182d251..cbb1182dee 100644 --- a/src/PERI/compute_plasticity_atom.h +++ b/src/PERI/compute_plasticity_atom.h @@ -35,7 +35,7 @@ class ComputePlasticityAtom : public Compute { private: int nmax; double *plasticity; - int ifix_peri; + class FixPeriNeigh *fix_peri_neigh; }; } // namespace LAMMPS_NS diff --git a/src/PERI/fix_peri_neigh.cpp b/src/PERI/fix_peri_neigh.cpp index 74b192b70f..47cb183a7d 100644 --- a/src/PERI/fix_peri_neigh.cpp +++ b/src/PERI/fix_peri_neigh.cpp @@ -18,7 +18,6 @@ #include "fix_peri_neigh.h" -#include #include "pair_peri_lps.h" #include "pair_peri_ves.h" #include "pair_peri_eps.h" @@ -34,6 +33,9 @@ #include "memory.h" #include "error.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -68,6 +70,7 @@ FixPeriNeigh::FixPeriNeigh(LAMMPS *lmp,int narg, char **arg) : wvolume = nullptr; grow_arrays(atom->nmax); + memset(wvolume,0,atom->nmax*sizeof(double)); atom->add_callback(Atom::GROW); atom->add_callback(Atom::RESTART); diff --git a/src/PERI/fix_peri_neigh.h b/src/PERI/fix_peri_neigh.h index ac9784f6e6..bde8f3f2da 100644 --- a/src/PERI/fix_peri_neigh.h +++ b/src/PERI/fix_peri_neigh.h @@ -25,6 +25,7 @@ FixStyle(PERI_NEIGH,FixPeriNeigh); namespace LAMMPS_NS { class FixPeriNeigh : public Fix { + friend class PairPeri; friend class PairPeriPMB; friend class PairPeriPMBOMP; friend class PairPeriLPS; diff --git a/src/PERI/pair_peri.cpp b/src/PERI/pair_peri.cpp new file mode 100644 index 0000000000..44c83661c9 --- /dev/null +++ b/src/PERI/pair_peri.cpp @@ -0,0 +1,263 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "pair_peri.h" + +#include "atom.h" +#include "domain.h" +#include "error.h" +#include "fix_peri_neigh.h" +#include "lattice.h" +#include "memory.h" +#include "modify.h" +#include "neigh_request.h" +#include "neighbor.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairPeri::PairPeri(LAMMPS *_lmp) : + Pair(_lmp), fix_peri_neigh(nullptr), bulkmodulus(nullptr), shearmodulus(nullptr), + m_lambdai(nullptr), m_taubi(nullptr), m_yieldstress(nullptr), s00(nullptr), alpha(nullptr), + cut(nullptr), kspring(nullptr), s0_new(nullptr), theta(nullptr), elastic_energy(nullptr) +{ + for (int i = 0; i < 6; i++) virial[i] = 0.0; + no_virial_fdotr_compute = 1; + single_enable = 0; + nmax = -1; +} + +/* ---------------------------------------------------------------------- */ + +PairPeri::~PairPeri() +{ + if (fix_peri_neigh) modify->delete_fix(fix_peri_neigh->id); + + if (allocated) { + memory->destroy(bulkmodulus); + memory->destroy(shearmodulus); + memory->destroy(m_lambdai); + memory->destroy(m_taubi); + memory->destroy(m_yieldstress); + memory->destroy(s00); + memory->destroy(alpha); + memory->destroy(cut); + memory->destroy(cutsq); + memory->destroy(setflag); + memory->destroy(kspring); + + memory->destroy(s0_new); + memory->destroy(theta); + memory->destroy(elastic_energy); + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairPeri::allocate() +{ + allocated = 1; + int n = atom->ntypes + 1; + + memory->create(setflag, n, n, "pair:setflag"); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) setflag[i][j] = 0; + + memory->create(cutsq, n, n, "pair:cutsq"); + memory->create(bulkmodulus, n, n, "pair:bulkmodulus"); + memory->create(shearmodulus, n, n, "pair:shearmodulus"); + memory->create(s00, n, n, "pair:s00"); + memory->create(alpha, n, n, "pair:alpha"); + memory->create(cut, n, n, "pair:cut"); + memory->create(m_yieldstress, n, n, "pair:m_yieldstress"); + memory->create(m_lambdai, n, n, "pair:m_lambdai"); + memory->create(m_taubi, n, n, "pair:m_taubi"); + memory->create(kspring, n, n, "pair:m_taubi"); +} + +/* ---------------------------------------------------------------------- + memory usage of local arrays +------------------------------------------------------------------------- */ + +double PairPeri::memory_usage() +{ + double bytes = 2.0 * (double) nmax * sizeof(double); + bytes += 10.0 * (double) atom->ntypes * atom->ntypes * sizeof(double); + return bytes; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairPeri::settings(int narg, char **/*arg*/) +{ + if (narg) error->all(FLERR,"Illegal pair_style command"); +} + +/* ---------------------------------------------------------------------- + init common to all peridynamics pair styles +------------------------------------------------------------------------- */ + +void PairPeri::init_style() +{ + // error checks + + if (!atom->peri_flag) error->all(FLERR, "Pair style peri requires atom style peri"); + if (atom->map_style == Atom::MAP_NONE) + error->all(FLERR, "Pair peri requires an atom map, see atom_modify"); + + if (domain->lattice == nullptr) error->all(FLERR, "Pair peri requires a lattice be defined"); + if (domain->lattice->xlattice != domain->lattice->ylattice || + domain->lattice->xlattice != domain->lattice->zlattice || + domain->lattice->ylattice != domain->lattice->zlattice) + error->all(FLERR, "Pair peri lattice is not identical in x, y, and z"); + + // if first init, create Fix needed for storing fixed neighbors + + if (!fix_peri_neigh) + fix_peri_neigh = (FixPeriNeigh *) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); + + neighbor->request(this, instance_me); +} + +/* ---------------------------------------------------------------------- */ + +void PairPeri::compute_dilatation(int ifrom, int ito) +{ + int i, j, jj, jnum, itype, jtype; + double xtmp, ytmp, ztmp, delx, dely, delz; + double xtmp0, ytmp0, ztmp0, delx0, dely0, delz0; + double rsq, r, dr; + double delta; + + double **x = atom->x; + int *type = atom->type; + double **x0 = atom->x0; + double *vfrac = atom->vfrac; + double vfrac_scale = 1.0; + + double lc = domain->lattice->xlattice; + double half_lc = 0.5 * lc; + + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + + int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; + + // compute the dilatation theta + + for (i = ifrom; i < ito; i++) { + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + xtmp0 = x0[i][0]; + ytmp0 = x0[i][1]; + ztmp0 = x0[i][2]; + jnum = npartner[i]; + theta[i] = 0.0; + itype = type[i]; + + for (jj = 0; jj < jnum; jj++) { + + // if bond already broken, skip this partner + if (partner[i][jj] == 0) continue; + + // look up local index of this partner particle + j = atom->map(partner[i][jj]); + + // skip if particle is "lost" + if (j < 0) continue; + + // compute force density and add to PD equation of motion + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + if (periodic) domain->minimum_image(delx, dely, delz); + rsq = delx * delx + dely * dely + delz * delz; + delx0 = xtmp0 - x0[j][0]; + dely0 = ytmp0 - x0[j][1]; + delz0 = ztmp0 - x0[j][2]; + if (periodic) domain->minimum_image(delx0, dely0, delz0); + + r = sqrt(rsq); + dr = r - r0[i][jj]; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; + + jtype = type[j]; + delta = cut[itype][jtype]; + + // scale vfrac[j] if particle j near the horizon + + if ((fabs(r0[i][jj] - delta)) <= half_lc) + vfrac_scale = + (-1.0 / (2 * half_lc)) * (r0[i][jj]) + (1.0 + ((delta - half_lc) / (2 * half_lc))); + else + vfrac_scale = 1.0; + + theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * vfrac[j] * vfrac_scale; + } + + // if wvolume[i] is zero, then particle i has no bonds + // therefore, the dilatation is set to zero + + if (wvolume[i] != 0.0) + theta[i] = (3.0 / wvolume[i]) * theta[i]; + else + theta[i] = 0; + } +} + +/* ---------------------------------------------------------------------- + communication routines +---------------------------------------------------------------------- */ + +int PairPeri::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) +{ + int i, j, m; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = theta[j]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void PairPeri::unpack_forward_comm(int n, int first, double *buf) +{ + int i, m, last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { theta[i] = buf[m++]; } +} + +/* ---------------------------------------------------------------------- */ + +void *PairPeri::extract(const char *name, int &dim) +{ + dim = 1; + if (strcmp(name, "theta") == 0) return (void *) theta; + if (strcmp(name, "elastic_energy") == 0) return (void *) elastic_energy; + return nullptr; +} diff --git a/src/PERI/pair_peri.h b/src/PERI/pair_peri.h new file mode 100644 index 0000000000..f3b41de4f5 --- /dev/null +++ b/src/PERI/pair_peri.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_PERI_H +#define LMP_PAIR_PERI_H + +#include "pair.h" +#include + +namespace LAMMPS_NS { + +class PairPeri : public Pair { + public: + PairPeri(class LAMMPS *); + virtual ~PairPeri(); + + virtual int pack_forward_comm(int, int *, double *, int, int *); + virtual void unpack_forward_comm(int, int, double *); + + virtual void init_style(); + virtual void settings(int, char **); + static constexpr double NEAR_ZERO = 2.2204e-16; + + double influence_function(const double &xi_x, const double &xi_y, const double &xi_z) const + { + const double r = sqrt((xi_x * xi_x) + (xi_y * xi_y) + (xi_z * xi_z)); + return (fabs(r) < NEAR_ZERO) ? 1.0 / NEAR_ZERO : (1.0 / r); + } + void compute_dilatation(int, int); + + double memory_usage(); + virtual void *extract(const char *, int &); + + protected: + class FixPeriNeigh *fix_peri_neigh; + double **bulkmodulus, **shearmodulus, **m_lambdai, **m_taubi, **m_yieldstress; + double **s00, **alpha, **cut, **kspring; + double *s0_new, *theta, *elastic_energy; + + int nmax; + + protected: + void allocate(); +}; + +} // namespace LAMMPS_NS + +#endif diff --git a/src/PERI/pair_peri_eps.cpp b/src/PERI/pair_peri_eps.cpp index f6e99332b3..8d1aa9b49f 100644 --- a/src/PERI/pair_peri_eps.cpp +++ b/src/PERI/pair_peri_eps.cpp @@ -26,6 +26,7 @@ #include "force.h" #include "lattice.h" #include "math_const.h" +#include "math_special.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" @@ -36,27 +37,12 @@ using namespace LAMMPS_NS; using namespace MathConst; +using MathSpecial::powint; /* ---------------------------------------------------------------------- */ -PairPeriEPS::PairPeriEPS(LAMMPS *lmp) : Pair(lmp) +PairPeriEPS::PairPeriEPS(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = -1; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - m_yieldstress = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -65,26 +51,6 @@ PairPeriEPS::PairPeriEPS(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriEPS::~PairPeriEPS() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(m_yieldstress); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriEPS::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -107,13 +73,12 @@ void PairPeriEPS::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - double **deviatorPlasticextension = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorPlasticextension; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - double *lambdaValue = ((FixPeriNeigh *) modify->fix[ifix_peri])->lambdaValue; + double **r0 = fix_peri_neigh->r0; + double **deviatorPlasticextension = fix_peri_neigh->deviatorPlasticextension; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + double *lambdaValue = fix_peri_neigh->lambdaValue; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -208,14 +173,12 @@ void PairPeriEPS::compute(int eflag, int vflag) int maxpartner = 0; for (i = 0; i < nlocal; i++) maxpartner = MAX(maxpartner,npartner[i]); - if (nlocal > nmax) { memory->destroy(s0_new); memory->destroy(theta); nmax = atom->nmax; memory->create(s0_new,nmax,"pair:s0_new"); memory->create(theta,nmax,"pair:theta"); - } // ******** temp array to store Plastic extension *********** /// @@ -228,7 +191,7 @@ void PairPeriEPS::compute(int eflag, int vflag) // ******** temp array to store Plastic extension *********** /// // compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); @@ -236,7 +199,7 @@ void PairPeriEPS::compute(int eflag, int vflag) // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // volume-dependent part of the energy @@ -269,21 +232,17 @@ void PairPeriEPS::compute(int eflag, int vflag) jnum = npartner[i]; first = true; - - double yieldStress = m_yieldstress[itype][itype]; - double horizon = cut[itype][itype]; - double tdnorm = compute_DeviatoricForceStateNorm(i); - double pointwiseYieldvalue = 25.0 * yieldStress * - yieldStress / 8 / MY_PI / pow(horizon,5); - - - double fsurf = (tdnorm * tdnorm)/2 - pointwiseYieldvalue; + const double yieldStress = m_yieldstress[itype][itype]; + const double horizon = cut[itype][itype]; + const double tdnorm = compute_DeviatoricForceStateNorm(i); + const double pointwiseYieldvalue = 25.0/8.0/MY_PI/powint(horizon,5)*yieldStress*yieldStress; + const double fsurf = (tdnorm * tdnorm)/2.0 - pointwiseYieldvalue; bool elastic = true; - if (fsurf > 0) { + if (fsurf > 0.0) { elastic = false; deltalambda = ((tdnorm /sqrt(2.0 * pointwiseYieldvalue)) - 1.0) * wvolume[i] - / (15 * shearmodulus[itype][itype]); + / (15.0 * shearmodulus[itype][itype]); double templambda = lambdaValue[i]; lambdaValue[i] = templambda + deltalambda; } @@ -316,34 +275,31 @@ void PairPeriEPS::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) { - dr = 0.0; - } + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); + vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + (1.0 + ((delta - half_lc)/(2*half_lc))); else vfrac_scale = 1.0; omega_plus = influence_function(-1.0*delx0,-1.0*dely0,-1.0*delz0); omega_minus = influence_function(delx0,dely0,delz0); - //Elastic Part - rk = ((3.0 * bulkmodulus[itype][itype]) * ( (omega_plus * theta[i] / wvolume[i]) + - ( omega_minus * theta[j] / wvolume[j] ) ) ) * r0[i][jj]; + // Elastic Part + rk = ((3.0 * bulkmodulus[itype][itype]) * ((omega_plus * theta[i] / wvolume[i]) + + (omega_minus * theta[j] / wvolume[j]))) * r0[i][jj]; if (r > 0.0) fbond = -((rk/r) * vfrac[j] * vfrac_scale); else fbond = 0.0; - //Plastic part + // Plastic part double deviatoric_extension = dr - (theta[i]* r0[i][jj] / 3.0); edpNp1 = deviatorPlasticextension[i][jj]; double tdtrialValue = ( 15 * shearmodulus[itype][itype]) * - ( (omega_plus / wvolume[i]) + (omega_minus / wvolume[j]) ) * + ((omega_plus / wvolume[i]) + (omega_minus / wvolume[j])) * (deviatoric_extension - edpNp1); if (elastic) { @@ -353,21 +309,17 @@ void PairPeriEPS::compute(int eflag, int vflag) deviatorPlasticExtTemp[i][jj] = edpNp1 + rkNew * deltalambda; } - if (r > 0.0) fbondElastoPlastic = -((rkNew/r) * vfrac[j] * vfrac_scale); else fbondElastoPlastic = 0.0; - // total Force state: elastic + plastic fbondFinal=fbond+fbondElastoPlastic; fbond=fbondFinal; - f[i][0] += delx*fbond; f[i][1] += dely*fbond; f[i][2] += delz*fbond; - // since I-J is double counted, set newton off & use 1/2 factor and I,I if (eflag) evdwl = (0.5 * 15 * shearmodulus[itype][itype]/wvolume[i] * @@ -379,7 +331,6 @@ void PairPeriEPS::compute(int eflag, int vflag) // find stretch in bond I-J and break if necessary // use s0 from previous timestep - stretch = dr / r0[i][jj]; if (stretch > MIN(s0[i],s0[j])) partner[i][jj] = 0; @@ -388,9 +339,7 @@ void PairPeriEPS::compute(int eflag, int vflag) if (first) s0_new[i] = s00[itype][jtype] - (alpha[itype][jtype] * stretch); else - s0_new[i] = MAX(s0_new[i],s00[itype][jtype] - - (alpha[itype][jtype] * stretch)); - + s0_new[i] = MAX(s0_new[i],s00[itype][jtype] - (alpha[itype][jtype] * stretch)); first = false; } } @@ -400,45 +349,12 @@ void PairPeriEPS::compute(int eflag, int vflag) memcpy(s0,s0_new,sizeof(double)*nlocal); if (nlocal*maxpartner > 0) { - memcpy(&(deviatorPlasticextension[0][0]), - &(deviatorPlasticExtTemp[0][0]), + memcpy(&(deviatorPlasticextension[0][0]),&(deviatorPlasticExtTemp[0][0]), sizeof(double)*nlocal*maxpartner); memory->destroy(deviatorPlasticExtTemp); } } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriEPS::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); - memory->create(m_yieldstress,n+1,n+1,"pair:m_yieldstress"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriEPS::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -493,40 +409,6 @@ double PairPeriEPS::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriEPS::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice == nullptr) - error->all(FLERR,"Pair peri requires a lattice be defined"); - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -581,120 +463,6 @@ void PairPeriEPS::read_restart(FILE *fp) } } -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriEPS::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriEPS::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriEPS::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // skip if particle is "lost" - if (j < 0) continue; - - // compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - /* ---------------------------------------------------------------------- */ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) @@ -714,12 +482,11 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) double lc = domain->lattice->xlattice; double half_lc = 0.5*lc; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - double **deviatorPlasticextension = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorPlasticextension; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + double **deviatorPlasticextension = fix_peri_neigh->deviatorPlasticextension; int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; @@ -753,7 +520,7 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) if (periodic) domain->minimum_image(delx0,dely0,delz0); r = sqrt(rsq); dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon double vfrac_scale; @@ -785,34 +552,3 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) } return sqrt(norm); } - - -/* ---------------------------------------------------------------------- - communication routines ----------------------------------------------------------------------- */ - -int PairPeriEPS::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriEPS::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_eps.h b/src/PERI/pair_peri_eps.h index 82d4c91ddb..5d9a437ac8 100644 --- a/src/PERI/pair_peri_eps.h +++ b/src/PERI/pair_peri_eps.h @@ -20,45 +20,23 @@ PairStyle(peri/eps,PairPeriEPS); #ifndef LMP_PAIR_PERI_EPS_H #define LMP_PAIR_PERI_EPS_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriEPS : public Pair { +class PairPeriEPS : public PairPeri { public: - double *theta; - double *elastic_energy; - PairPeriEPS(class LAMMPS *); - virtual ~PairPeriEPS(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriEPS() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); double compute_DeviatoricForceStateNorm(int); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut, **m_yieldstress; //NEW: **m_yieldstress - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -104,9 +82,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PERI/pair_peri_lps.cpp b/src/PERI/pair_peri_lps.cpp index 5b725306b0..f7c024983b 100644 --- a/src/PERI/pair_peri_lps.cpp +++ b/src/PERI/pair_peri_lps.cpp @@ -37,23 +37,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriLPS::PairPeriLPS(LAMMPS *lmp) : Pair(lmp) +PairPeriLPS::PairPeriLPS(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -62,25 +47,6 @@ PairPeriLPS::PairPeriLPS(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriLPS::~PairPeriLPS() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriLPS::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -101,10 +67,10 @@ void PairPeriLPS::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -205,13 +171,13 @@ void PairPeriLPS::compute(int eflag, int vflag) } // Compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); // communicate wighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // Volume-dependent part of the energy if (eflag) { @@ -272,7 +238,7 @@ void PairPeriLPS::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -335,37 +301,6 @@ void PairPeriLPS::compute(int eflag, int vflag) } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriLPS::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriLPS::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -418,38 +353,6 @@ double PairPeriLPS::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriLPS::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -500,148 +403,3 @@ void PairPeriLPS::read_restart(FILE *fp) } } } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriLPS::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriLPS::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function of pair peri/lps"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriLPS::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // Look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // Skip if particle is "lost" - if (j < 0) continue; - - // Compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - - -/* ---------------------------------------------------------------------- - communication routines - ---------------------------------------------------------------------- */ - -int PairPeriLPS::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriLPS::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_lps.h b/src/PERI/pair_peri_lps.h index fb4647eb2f..0d9132f612 100644 --- a/src/PERI/pair_peri_lps.h +++ b/src/PERI/pair_peri_lps.h @@ -20,44 +20,22 @@ PairStyle(peri/lps,PairPeriLPS); #ifndef LMP_PAIR_PERI_LPS_H #define LMP_PAIR_PERI_LPS_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriLPS : public Pair { - public: - double *theta; - double *elastic_energy; - +class PairPeriLPS : public PairPeri { +public: PairPeriLPS(class LAMMPS *); - virtual ~PairPeriLPS(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriLPS() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -99,9 +77,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function of pair peri/lps - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PERI/pair_peri_pmb.cpp b/src/PERI/pair_peri_pmb.cpp index fa96ef0f26..0f88f0d80a 100644 --- a/src/PERI/pair_peri_pmb.cpp +++ b/src/PERI/pair_peri_pmb.cpp @@ -37,37 +37,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriPMB::PairPeriPMB(LAMMPS *lmp) : Pair(lmp) +PairPeriPMB::PairPeriPMB(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute=1; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - - kspring = nullptr; - s00 = nullptr; - alpha = nullptr; - cut = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairPeriPMB::~PairPeriPMB() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(kspring); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(s0_new); - } + single_enable = 1; } /* ---------------------------------------------------------------------- */ @@ -92,9 +64,9 @@ void PairPeriPMB::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -227,7 +199,7 @@ void PairPeriPMB::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -269,36 +241,6 @@ void PairPeriPMB::compute(int eflag, int vflag) for (i = 0; i < nlocal; i++) s0[i] = s0_new[i]; } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriPMB::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(kspring,n+1,n+1,"pair:kspring"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriPMB::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -348,38 +290,6 @@ double PairPeriPMB::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriPMB::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -439,9 +349,9 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, double *vfrac = atom->vfrac; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; double lc = domain->lattice->xlattice; double half_lc = 0.5*lc; @@ -473,7 +383,7 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, if (j < 0) continue; if (j == atom->map(partner[i][jj])) { dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; if ( (fabs(r0[i][jj] - sqrt(cutsq[itype][jtype]))) <= half_lc) vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + (1.0 + ((sqrt(cutsq[itype][jtype]) - half_lc)/(2*half_lc))); @@ -487,13 +397,3 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, return energy; } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriPMB::memory_usage() -{ - double bytes = (double)nmax * sizeof(double); - return bytes; -} diff --git a/src/PERI/pair_peri_pmb.h b/src/PERI/pair_peri_pmb.h index cd65052dec..44a46093de 100644 --- a/src/PERI/pair_peri_pmb.h +++ b/src/PERI/pair_peri_pmb.h @@ -20,36 +20,25 @@ PairStyle(peri/pmb,PairPeriPMB); #ifndef LMP_PAIR_PERI_PMB_H #define LMP_PAIR_PERI_PMB_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriPMB : public Pair { +class PairPeriPMB : public PairPeri { public: PairPeriPMB(class LAMMPS *); - virtual ~PairPeriPMB(); + virtual ~PairPeriPMB() = default; + virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); + void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} + double single(int, int, int, int, double, double, double, double &); - virtual double memory_usage(); - - protected: - int ifix_peri; - double **kspring; - double **s00, **alpha; - double **cut; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/PERI/pair_peri_ves.cpp b/src/PERI/pair_peri_ves.cpp index ca8802396e..522d05e04f 100644 --- a/src/PERI/pair_peri_ves.cpp +++ b/src/PERI/pair_peri_ves.cpp @@ -37,25 +37,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriVES::PairPeriVES(LAMMPS *lmp) : Pair(lmp) +PairPeriVES::PairPeriVES(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - m_lambdai = nullptr; - m_taubi = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -64,27 +47,6 @@ PairPeriVES::PairPeriVES(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriVES::~PairPeriVES() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(m_lambdai); - memory->destroy(m_taubi); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriVES::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -108,14 +70,12 @@ void PairPeriVES::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - double **deviatorextention = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorextention; - double **deviatorBackextention = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorBackextention; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + double **deviatorextention = fix_peri_neigh->deviatorextention; + double **deviatorBackextention = fix_peri_neigh->deviatorBackextention; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -216,7 +176,7 @@ void PairPeriVES::compute(int eflag, int vflag) } // Compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); @@ -224,7 +184,7 @@ void PairPeriVES::compute(int eflag, int vflag) // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // volume-dependent part of the energy @@ -286,7 +246,7 @@ void PairPeriVES::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -381,39 +341,6 @@ void PairPeriVES::compute(int eflag, int vflag) for (i = 0; i < nlocal; i++) s0[i] = s0_new[i]; } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriVES::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); - memory->create(m_lambdai,n+1,n+1,"pair:m_lambdai"); - memory->create(m_taubi,n+1,n+1,"pair:m_taubi"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriVES::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -472,40 +399,6 @@ double PairPeriVES::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriVES::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice == nullptr) - error->all(FLERR,"Pair peri requires a lattice be defined"); - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -562,153 +455,3 @@ void PairPeriVES::read_restart(FILE *fp) } } } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriVES::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriVES::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function of pair peri/lps"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriVES::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - - if (partner[i][jj] == 0) continue; - - // look up local index of this partner particle - - j = atom->map(partner[i][jj]); - - // skip if particle is "lost" - - if (j < 0) continue; - - // compute force density and add to PD equation of motion - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - - -/* ---------------------------------------------------------------------- - communication routines ----------------------------------------------------------------------- */ - -int PairPeriVES::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriVES::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_ves.h b/src/PERI/pair_peri_ves.h index 03659ae65d..e80c5e3383 100644 --- a/src/PERI/pair_peri_ves.h +++ b/src/PERI/pair_peri_ves.h @@ -20,46 +20,22 @@ PairStyle(peri/ves,PairPeriVES); #ifndef LMP_PAIR_PERI_VES_H #define LMP_PAIR_PERI_VES_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriVES : public Pair { +class PairPeriVES : public PairPeri { public: - double *theta; - double *elastic_energy; - PairPeriVES(class LAMMPS *); - virtual ~PairPeriVES(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriVES() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut; - double **m_lambdai; - double **m_taubi; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -105,9 +81,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function of pair peri/lps - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 4c20ff6fdd..33a252c39e 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -15,459 +14,429 @@ #include "plugin.h" #include "comm.h" +#include "compute.h" #include "domain.h" #include "error.h" -#include "input.h" +#include "fix.h" #include "force.h" +#include "input.h" #include "modify.h" +#include "region.h" #include -#include #include +#include -namespace LAMMPS_NS +namespace LAMMPS_NS { +// list of plugin information data for loaded styles +static std::list pluginlist; + +// map for counting references to dso handles +static std::map dso_refcounter; + +/* ---------------------------------------------------------------------- */ + +Plugin::Plugin(LAMMPS *lmp) : Command(lmp) {} + +/* ---------------------------------------------------------------------- */ + +void Plugin::command(int narg, char **arg) { - // list of plugin information data for loaded styles - static std::list pluginlist; + if (narg < 1) error->all(FLERR, "Illegal plugin command"); - // map for counting references to dso handles - static std::map dso_refcounter; + std::string cmd = arg[0]; + if (cmd == "load") { + if (narg < 2) error->all(FLERR, "Illegal plugin load command"); + for (int i = 1; i < narg; ++i) plugin_load(arg[i], lmp); + } else if (cmd == "unload") { + if (narg != 3) error->all(FLERR, "Illegal plugin unload command"); + plugin_unload(arg[1], arg[2], lmp); -/* ---------------------------------------------------------------------- */ + } else if (cmd == "clear") { + plugin_clear(lmp); - Plugin::Plugin(LAMMPS *lmp) : Command(lmp) {} - -/* ---------------------------------------------------------------------- */ - - void Plugin::command(int narg, char **arg) - { - if (narg < 1) error->all(FLERR,"Illegal plugin command"); - -#if defined(LMP_PLUGIN) - std::string cmd = arg[0]; - if (cmd == "load") { - if (narg < 2) error->all(FLERR,"Illegal plugin load command"); - for (int i=1; i < narg; ++i) - plugin_load(arg[i],lmp); - - } else if (cmd == "unload") { - if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); - plugin_unload(arg[1],arg[2],lmp); - - } else if (cmd == "clear") { - plugin_clear(lmp); - - } else if (cmd == "list") { - if (comm->me == 0) { - int num = plugin_get_num_plugins(); - utils::logmesg(lmp,"Currently loaded plugins\n"); - for (int i=0; i < num; ++i) { - auto entry = plugin_get_info(i); - utils::logmesg(lmp,"{:4}: {} style plugin {}\n", - i+1,entry->style,entry->name); - } + } else if (cmd == "list") { + if (comm->me == 0) { + int num = plugin_get_num_plugins(); + utils::logmesg(lmp, "Currently loaded plugins\n"); + for (int i = 0; i < num; ++i) { + auto entry = plugin_get_info(i); + utils::logmesg(lmp, "{:4}: {} style plugin {}\n", i + 1, entry->style, entry->name); } - } else error->all(FLERR,"Illegal plugin command"); -#else - if (comm->me == 0) - error->warning(FLERR,"Ignoring plugin command. LAMMPS must be built as " - "a shared library for it to work."); + } + } else + error->all(FLERR, "Illegal plugin command"); +#if 0 + if (comm->me == 0) + error->warning( + FLERR, "LAMMPS must be built as a shared library for it to work."); #endif - } +} - // load DSO and call included registration function - void plugin_load(const char *file, LAMMPS *lmp) - { +// load DSO and call included registration function +void plugin_load(const char *file, LAMMPS *lmp) +{ #if defined(LMP_PLUGIN) - int me = lmp->comm->me; + int me = lmp->comm->me; - // open DSO file from given path; load symbols globally + // open DSO file from given path; load symbols globally - platform::dlerror(); - void *dso = platform::dlopen(file); - if (dso == nullptr) { - if (me == 0) - utils::logmesg(lmp,"Open of file {} failed: {}\n",file,platform::dlerror()); - return; - } - - // look up lammpsplugin_init() function in DSO - // function must have C bindings so there is no name mangling - - platform::dlerror(); - void *initfunc = platform::dlsym(dso,"lammpsplugin_init"); - if (initfunc == nullptr) { - platform::dlclose(dso); - - if (me == 0) - utils::logmesg(lmp,"Plugin symbol lookup failure in file {}: {}\n", - file,platform::dlerror()); - return; - } - - // call initializer function loaded from DSO and pass a pointer - // to the LAMMPS instance, the DSO handle (for reference counting) - // and plugin registration function pointer - - (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, - (void *)&plugin_register); -#endif + platform::dlerror(); + void *dso = platform::dlopen(file); + if (dso == nullptr) { + if (me == 0) utils::logmesg(lmp, "Open of file {} failed: {}\n", file, platform::dlerror()); + return; } - /* -------------------------------------------------------------------- + // look up lammpsplugin_init() function in DSO + // function must have C bindings so there is no name mangling + + platform::dlerror(); + void *initfunc = platform::dlsym(dso, "lammpsplugin_init"); + if (initfunc == nullptr) { + platform::dlclose(dso); + + if (me == 0) + utils::logmesg(lmp, "Plugin symbol lookup failure in file {}: {}\n", file, + platform::dlerror()); + return; + } + + // call initializer function loaded from DSO and pass a pointer + // to the LAMMPS instance, the DSO handle (for reference counting) + // and plugin registration function pointer + + (*(lammpsplugin_initfunc) (initfunc))((void *) lmp, dso, (void *) &plugin_register); +#endif +} + +/* -------------------------------------------------------------------- register a new style from a plugin with LAMMPS this is the callback function that is called from within the plugin initializer function. all plugin information is taken from the lammpsplugin_t struct. -------------------------------------------------------------------- */ - void plugin_register(lammpsplugin_t *plugin, void *ptr) - { +void plugin_register(lammpsplugin_t *plugin, void *ptr) +{ #if defined(LMP_PLUGIN) - LAMMPS *lmp = (LAMMPS *)ptr; - int me = lmp->comm->me; + LAMMPS *lmp = (LAMMPS *) ptr; + int me = lmp->comm->me; - if (plugin == nullptr) return; + if (plugin == nullptr) return; - // ignore load request if same plugin already loaded - int idx = plugin_find(plugin->style,plugin->name); - if (idx >= 0) { - if (me == 0) - utils::logmesg(lmp,"Ignoring load of {} style {}: must " - "unload existing {} plugin first\n", - plugin->style,plugin->name,plugin->name); - return; - } - - if (me == 0) { - utils::logmesg(lmp,"Loading plugin: {} by {}\n", - plugin->info,plugin->author); - // print version info only if the versions of host and plugin don't match - if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) - utils::logmesg(lmp," compiled for LAMMPS version {}, loaded into " - "LAMMPS version {}\n",plugin->version,lmp->version); - } - - pluginlist.push_back(*plugin); - - if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { - ++ dso_refcounter[plugin->handle]; - } else { - dso_refcounter[plugin->handle] = 1; - } - - std::string pstyle = plugin->style; - if (pstyle == "pair") { - auto pair_map = lmp->force->pair_map; - if (pair_map->find(plugin->name) != pair_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in pair " - "style {} from plugin",plugin->name); - } - (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator.v1; - - } else if (pstyle == "bond") { - auto bond_map = lmp->force->bond_map; - if (bond_map->find(plugin->name) != bond_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in bond " - "style {} from plugin",plugin->name); - } - (*bond_map)[plugin->name] = (Force::BondCreator)plugin->creator.v1; - - } else if (pstyle == "angle") { - auto angle_map = lmp->force->angle_map; - if (angle_map->find(plugin->name) != angle_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in angle " - "style {} from plugin",plugin->name); - } - (*angle_map)[plugin->name] = (Force::AngleCreator)plugin->creator.v1; - - } else if (pstyle == "dihedral") { - auto dihedral_map = lmp->force->dihedral_map; - if (dihedral_map->find(plugin->name) != dihedral_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in dihedral " - "style {} from plugin",plugin->name); - } - (*dihedral_map)[plugin->name] = (Force::DihedralCreator)plugin->creator.v1; - - } else if (pstyle == "improper") { - auto improper_map = lmp->force->improper_map; - if (improper_map->find(plugin->name) != improper_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in improper " - "style {} from plugin",plugin->name); - } - (*improper_map)[plugin->name] = (Force::ImproperCreator)plugin->creator.v1; - - } else if (pstyle == "compute") { - auto compute_map = lmp->modify->compute_map; - if (compute_map->find(plugin->name) != compute_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in compute " - "style {} from plugin",plugin->name); - } - (*compute_map)[plugin->name] = (Modify::ComputeCreator)plugin->creator.v2; - - } else if (pstyle == "fix") { - auto fix_map = lmp->modify->fix_map; - if (fix_map->find(plugin->name) != fix_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in fix " - "style {} from plugin",plugin->name); - } - (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2; - - } else if (pstyle == "region") { - auto region_map = lmp->domain->region_map; - if (region_map->find(plugin->name) != region_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in region " - "style {} from plugin",plugin->name); - } - (*region_map)[plugin->name] = (Domain::RegionCreator)plugin->creator.v2; - - } else if (pstyle == "command") { - auto command_map = lmp->input->command_map; - if (command_map->find(plugin->name) != command_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in command " - "style {} from plugin",plugin->name); - } - (*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator.v1; - - } else { - utils::logmesg(lmp,"Loading plugins for {} styles not " - "yet implemented\n",pstyle); - pluginlist.pop_back(); - } -#endif + // ignore load request if same plugin already loaded + int idx = plugin_find(plugin->style, plugin->name); + if (idx >= 0) { + if (me == 0) + utils::logmesg(lmp, "Ignoring load of {} style {}: must unload existing {} plugin first\n", + plugin->style, plugin->name, plugin->name); + return; } - /* -------------------------------------------------------------------- + if (me == 0) { + utils::logmesg(lmp, "Loading plugin: {} by {}\n", plugin->info, plugin->author); + // print version info only if the versions of host and plugin don't match + if ((plugin->version) && (strcmp(plugin->version, lmp->version) != 0)) + utils::logmesg(lmp, " compiled for LAMMPS version {}, loaded into LAMMPS version {}\n", + plugin->version, lmp->version); + } + + pluginlist.push_back(*plugin); + + if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { + ++dso_refcounter[plugin->handle]; + } else { + dso_refcounter[plugin->handle] = 1; + } + + std::string pstyle = plugin->style; + if (pstyle == "pair") { + auto pair_map = lmp->force->pair_map; + if (pair_map->find(plugin->name) != pair_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in pair style {} from plugin", plugin->name); + } + (*pair_map)[plugin->name] = (Force::PairCreator) plugin->creator.v1; + + } else if (pstyle == "bond") { + auto bond_map = lmp->force->bond_map; + if (bond_map->find(plugin->name) != bond_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in bond style {} from plugin", plugin->name); + } + (*bond_map)[plugin->name] = (Force::BondCreator) plugin->creator.v1; + + } else if (pstyle == "angle") { + auto angle_map = lmp->force->angle_map; + if (angle_map->find(plugin->name) != angle_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in angle style {} from plugin", plugin->name); + } + (*angle_map)[plugin->name] = (Force::AngleCreator) plugin->creator.v1; + + } else if (pstyle == "dihedral") { + auto dihedral_map = lmp->force->dihedral_map; + if (dihedral_map->find(plugin->name) != dihedral_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in dihedral style {} from plugin", + plugin->name); + } + (*dihedral_map)[plugin->name] = (Force::DihedralCreator) plugin->creator.v1; + + } else if (pstyle == "improper") { + auto improper_map = lmp->force->improper_map; + if (improper_map->find(plugin->name) != improper_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in improper style {} from plugin", + plugin->name); + } + (*improper_map)[plugin->name] = (Force::ImproperCreator) plugin->creator.v1; + + } else if (pstyle == "compute") { + auto compute_map = lmp->modify->compute_map; + if (compute_map->find(plugin->name) != compute_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in compute style {} from plugin", + plugin->name); + } + (*compute_map)[plugin->name] = (Modify::ComputeCreator) plugin->creator.v2; + + } else if (pstyle == "fix") { + auto fix_map = lmp->modify->fix_map; + if (fix_map->find(plugin->name) != fix_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in fix style {} from plugin", plugin->name); + } + (*fix_map)[plugin->name] = (Modify::FixCreator) plugin->creator.v2; + + } else if (pstyle == "region") { + auto region_map = lmp->domain->region_map; + if (region_map->find(plugin->name) != region_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in region style {} from plugin", plugin->name); + } + (*region_map)[plugin->name] = (Domain::RegionCreator) plugin->creator.v2; + + } else if (pstyle == "command") { + auto command_map = lmp->input->command_map; + if (command_map->find(plugin->name) != command_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in command style {} from plugin", + plugin->name); + } + (*command_map)[plugin->name] = (Input::CommandCreator) plugin->creator.v1; + + } else { + utils::logmesg(lmp, "Loading plugins for {} styles not yet implemented\n", pstyle); + pluginlist.pop_back(); + } +#endif +} + +/* -------------------------------------------------------------------- remove plugin from given style table and plugin list optionally close the DSO handle if it is the last plugin from that DSO must also delete style instances if style is currently active -------------------------------------------------------------------- */ - void plugin_unload(const char *style, const char *name, LAMMPS *lmp) - { +void plugin_unload(const char *style, const char *name, LAMMPS *lmp) +{ #if defined(LMP_PLUGIN) - int me = lmp->comm->me; - - // ignore unload request from unsupported style categories - if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0) - && (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0) - && (strcmp(style,"improper") != 0) && (strcmp(style,"compute") != 0) - && (strcmp(style,"fix") != 0) && (strcmp(style,"region") != 0) - && (strcmp(style,"command") != 0)) { - if (me == 0) - utils::logmesg(lmp,"Ignoring unload: {} is not a " - "supported plugin style\n",style); - return; - } - - // ignore unload request if not loaded from a plugin - int idx = plugin_find(style,name); - if (idx < 0) { - if (me == 0) - utils::logmesg(lmp,"Ignoring unload of {} style {}: not " - "loaded from a plugin\n",style,name); - return; - } - - // make copy of DSO handle for later use - void *handle = plugin_get_info(idx)->handle; - - // remove selected plugin from list of plugins + int me = lmp->comm->me; + // ignore unload request from unsupported style categories + if ((strcmp(style, "pair") != 0) && (strcmp(style, "bond") != 0) && + (strcmp(style, "angle") != 0) && (strcmp(style, "dihedral") != 0) && + (strcmp(style, "improper") != 0) && (strcmp(style, "compute") != 0) && + (strcmp(style, "fix") != 0) && (strcmp(style, "region") != 0) && + (strcmp(style, "command") != 0)) { if (me == 0) - utils::logmesg(lmp,"Unloading {} style {}\n",style,name); - plugin_erase(style,name); - - // remove style of given name from corresponding map - // must delete style instance if currently active so - // we can close the DSO handle if the last reference is gone. - - std::string pstyle = style; - if (pstyle == "pair") { - - auto found = lmp->force->pair_map->find(name); - if (found != lmp->force->pair_map->end()) - lmp->force->pair_map->erase(found); - - // must delete pair style instance if in use - - if (lmp->force->pair_style) { - if (utils::strmatch(lmp->force->pair_style,"^hybrid")) { - if (lmp->force->pair_match(name,1,1) != nullptr) - lmp->force->create_pair("none",0); - } else { - if (strcmp(lmp->force->pair_style,name) == 0) - lmp->force->create_pair("none",0); - } - } - - } else if (pstyle == "bond") { - - auto found = lmp->force->bond_map->find(name); - if (found != lmp->force->bond_map->end()) - lmp->force->bond_map->erase(found); - - // must delete bond style instance if in use - - if ((lmp->force->bond_style != nullptr) - && (lmp->force->bond_match(name) != nullptr)) - lmp->force->create_bond("none",0); - - } else if (pstyle == "angle") { - - auto found = lmp->force->angle_map->find(name); - if (found != lmp->force->angle_map->end()) - lmp->force->angle_map->erase(found); - - // must delete angle style instance if in use - - if ((lmp->force->angle_style != nullptr) - && (lmp->force->angle_match(name) != nullptr)) - lmp->force->create_angle("none",0); - - } else if (pstyle == "dihedral") { - - auto found = lmp->force->dihedral_map->find(name); - if (found != lmp->force->dihedral_map->end()) - lmp->force->dihedral_map->erase(found); - - // must delete dihedral style instance if in use - - if ((lmp->force->dihedral_style) - && (lmp->force->dihedral_match(name) != nullptr)) - lmp->force->create_dihedral("none",0); - - } else if (pstyle == "improper") { - - auto found = lmp->force->improper_map->find(name); - if (found != lmp->force->improper_map->end()) - lmp->force->improper_map->erase(found); - - // must delete improper style instance if in use - - if ((lmp->force->improper_style != nullptr) - && (lmp->force->improper_match(name) != nullptr)) - lmp->force->create_improper("none",0); - - } else if (pstyle == "compute") { - - auto compute_map = lmp->modify->compute_map; - auto found = compute_map->find(name); - if (found != compute_map->end()) compute_map->erase(name); - - for (int icompute = lmp->modify->find_compute_by_style(name); - icompute >= 0; icompute = lmp->modify->find_compute_by_style(name)) - lmp->modify->delete_compute(icompute); - - } else if (pstyle == "fix") { - - auto fix_map = lmp->modify->fix_map; - auto found = fix_map->find(name); - if (found != fix_map->end()) fix_map->erase(name); - - for (int ifix = lmp->modify->find_fix_by_style(name); - ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) - lmp->modify->delete_fix(ifix); - - } else if (pstyle == "region") { - - auto region_map = lmp->domain->region_map; - auto found = region_map->find(name); - if (found != region_map->end()) region_map->erase(name); - - for (int iregion = lmp->domain->find_region_by_style(name); - iregion >= 0; iregion = lmp->domain->find_region_by_style(name)) - lmp->domain->delete_region(iregion); - - } else if (pstyle == "command") { - - auto command_map = lmp->input->command_map; - auto found = command_map->find(name); - if (found != command_map->end()) command_map->erase(name); - } - - // if reference count is down to zero, close DSO handle. - - -- dso_refcounter[handle]; - if (dso_refcounter[handle] == 0) { - platform::dlclose(handle); - } -#endif + utils::logmesg(lmp, "Ignoring unload: {} is not a supported plugin style\n", style); + return; } - /* -------------------------------------------------------------------- + // ignore unload request if not loaded from a plugin + int idx = plugin_find(style, name); + if (idx < 0) { + if (me == 0) + utils::logmesg(lmp, "Ignoring unload of {} style {}: not from a plugin\n", style, name); + return; + } + + // make copy of DSO handle for later use + void *handle = plugin_get_info(idx)->handle; + + // remove selected plugin from list of plugins + + if (me == 0) utils::logmesg(lmp, "Unloading {} style {}\n", style, name); + plugin_erase(style, name); + + // remove style of given name from corresponding map + // must delete style instance if currently active so + // we can close the DSO handle if the last reference is gone. + + std::string pstyle = style; + if (pstyle == "pair") { + + auto found = lmp->force->pair_map->find(name); + if (found != lmp->force->pair_map->end()) lmp->force->pair_map->erase(found); + + // must delete pair style instance if in use + + if (lmp->force->pair_style) { + if (utils::strmatch(lmp->force->pair_style, "^hybrid")) { + if (lmp->force->pair_match(name, 1, 1) != nullptr) lmp->force->create_pair("none", 0); + } else { + if (strcmp(lmp->force->pair_style, name) == 0) lmp->force->create_pair("none", 0); + } + } + + } else if (pstyle == "bond") { + + auto found = lmp->force->bond_map->find(name); + if (found != lmp->force->bond_map->end()) lmp->force->bond_map->erase(found); + + // must delete bond style instance if in use + + if ((lmp->force->bond_style != nullptr) && (lmp->force->bond_match(name) != nullptr)) + lmp->force->create_bond("none", 0); + + } else if (pstyle == "angle") { + + auto found = lmp->force->angle_map->find(name); + if (found != lmp->force->angle_map->end()) lmp->force->angle_map->erase(found); + + // must delete angle style instance if in use + + if ((lmp->force->angle_style != nullptr) && (lmp->force->angle_match(name) != nullptr)) + lmp->force->create_angle("none", 0); + + } else if (pstyle == "dihedral") { + + auto found = lmp->force->dihedral_map->find(name); + if (found != lmp->force->dihedral_map->end()) lmp->force->dihedral_map->erase(found); + + // must delete dihedral style instance if in use + + if ((lmp->force->dihedral_style) && (lmp->force->dihedral_match(name) != nullptr)) + lmp->force->create_dihedral("none", 0); + + } else if (pstyle == "improper") { + + auto found = lmp->force->improper_map->find(name); + if (found != lmp->force->improper_map->end()) lmp->force->improper_map->erase(found); + + // must delete improper style instance if in use + + if ((lmp->force->improper_style != nullptr) && (lmp->force->improper_match(name) != nullptr)) + lmp->force->create_improper("none", 0); + + } else if (pstyle == "compute") { + + auto compute_map = lmp->modify->compute_map; + auto found = compute_map->find(name); + if (found != compute_map->end()) compute_map->erase(name); + + // must delete all compute instances using this compute style + + for (auto icompute : lmp->modify->get_compute_by_style(name)) + lmp->modify->delete_compute(icompute->id); + + } else if (pstyle == "fix") { + + auto fix_map = lmp->modify->fix_map; + auto found = fix_map->find(name); + if (found != fix_map->end()) fix_map->erase(name); + + // must delete all fix instances using this fix style + + for (auto ifix : lmp->modify->get_fix_by_style(name)) lmp->modify->delete_fix(ifix->id); + + } else if (pstyle == "region") { + + auto region_map = lmp->domain->region_map; + auto found = region_map->find(name); + if (found != region_map->end()) region_map->erase(name); + + for (auto iregion : lmp->domain->get_region_by_style(name)) + lmp->domain->delete_region(iregion->id); + + } else if (pstyle == "command") { + + auto command_map = lmp->input->command_map; + auto found = command_map->find(name); + if (found != command_map->end()) command_map->erase(name); + } + + // if reference count is down to zero, close DSO handle. + + --dso_refcounter[handle]; + if (dso_refcounter[handle] == 0) { platform::dlclose(handle); } +#endif +} + +/* -------------------------------------------------------------------- unload all loaded plugins -------------------------------------------------------------------- */ - void plugin_clear(LAMMPS *lmp) - { - while (pluginlist.size() > 0) { - auto p = pluginlist.begin(); - plugin_unload(p->style,p->name,lmp); - } +void plugin_clear(LAMMPS *lmp) +{ + while (pluginlist.size() > 0) { + auto p = pluginlist.begin(); + plugin_unload(p->style, p->name, lmp); } +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- remove plugin of given name and style from internal lists -------------------------------------------------------------------- */ - void plugin_erase(const char *style, const char *name) - { - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if ((strcmp(style,p->style) == 0) - && (strcmp(name,p->name) == 0)) { - pluginlist.erase(p); - return; - } +void plugin_erase(const char *style, const char *name) +{ + for (auto p = pluginlist.begin(); p != pluginlist.end(); ++p) { + if ((strcmp(style, p->style) == 0) && (strcmp(name, p->name) == 0)) { + pluginlist.erase(p); + return; } } +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- number of styles loaded from plugin files -------------------------------------------------------------------- */ - int plugin_get_num_plugins() - { - return pluginlist.size(); - } +int plugin_get_num_plugins() +{ + return pluginlist.size(); +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- return position index in list of given plugin of given style -------------------------------------------------------------------- */ - int plugin_find(const char *style, const char *name) - { - int i=0; - for (auto entry : pluginlist) { - if ((strcmp(style,entry.style) == 0) - && (strcmp(name,entry.name) == 0)) - return i; - ++i; - } - return -1; +int plugin_find(const char *style, const char *name) +{ + int i = 0; + for (auto entry : pluginlist) { + if ((strcmp(style, entry.style) == 0) && (strcmp(name, entry.name) == 0)) return i; + ++i; } + return -1; +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- get pointer to plugin initializer struct at position idx -------------------------------------------------------------------- */ - const lammpsplugin_t *plugin_get_info(int idx) - { - int i=0; - for (auto & p : pluginlist) { - if (i == idx) return &p; - ++i; - } - return nullptr; +const lammpsplugin_t *plugin_get_info(int idx) +{ + int i = 0; + for (const auto &p : pluginlist) { + if (i == idx) return &p; + ++i; } + return nullptr; } +} // namespace LAMMPS_NS diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index 62d55cbcb3..ffd45719a5 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -304,7 +304,7 @@ void FixQEq::init() ngroup = group->count(igroup); if (ngroup == 0) error->all(FLERR,"Fix {} group has no atoms", style); - if ((comm->me == 0) && (modify->find_fix_by_style("^efield") >= 0)) + if ((comm->me == 0) && (modify->get_fix_by_style("^efield").size() > 0)) error->warning(FLERR,"Fix efield is ignored during charge equilibration"); if (utils::strmatch(update->integrate_style,"^respa")) diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index dbee51e034..31a09567ca 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -155,7 +155,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : master_group = (char *) "bond_react_MASTER_group"; // by using fixed group names, only one instance of fix bond/react is allowed. - if (modify->find_fix_by_style("^bond/react") != -1) + if (modify->get_fix_by_style("^bond/react").size() != 0) error->all(FLERR,"Only one instance of fix bond/react allowed at a time"); // let's find number of reactions specified diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index 874a10bbae..fa8fa79e00 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -380,18 +380,13 @@ void FixQEqReaxFF::init() if (group->count(igroup) == 0) error->all(FLERR,"Fix {} group has no atoms", style); - // there may be only one instance of fix efield - - int num_efield = 0; - for (int ifix = 0; ifix < modify->nfix; ++ifix) { - if (utils::strmatch(modify->fix[ifix]->style, "^efield")) ++num_efield; - } - if (num_efield > 1) - error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); + // get pointer to fix efield if present. there may be at most one instance of fix efield in use. efield = nullptr; - int ifix = modify->find_fix_by_style("^efield"); - if (ifix >= 0) efield = (FixEfield *) modify->fix[ifix]; + auto fixes = modify->get_fix_by_style("^efield"); + if (fixes.size() == 1) efield = (FixEfield *) fixes.front(); + else if (fixes.size() > 1) + error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); // ensure that fix efield is properly initialized before accessing its data and check some settings if (efield) { diff --git a/src/REAXFF/pair_reaxff.cpp b/src/REAXFF/pair_reaxff.cpp index 1c6665b604..9a3bdf2f79 100644 --- a/src/REAXFF/pair_reaxff.cpp +++ b/src/REAXFF/pair_reaxff.cpp @@ -332,23 +332,19 @@ void PairReaxFF::coeff(int nargs, char **args) void PairReaxFF::init_style() { - if (!atom->q_flag) - error->all(FLERR,"Pair style reaxff requires atom attribute q"); + if (!atom->q_flag) error->all(FLERR,"Pair style reaxff requires atom attribute q"); - bool have_qeq = ((modify->find_fix_by_style("^qeq/reax") != -1) - || (modify->find_fix_by_style("^qeq/shielded") != -1) - || (modify->find_fix_by_style("^acks2/reax") != -1)); - if (!have_qeq && qeqflag == 1) - error->all(FLERR,"Pair reax/c requires use of fix qeq/reax or qeq/shielded" - " or fix acks2/reax"); + auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); + int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size(); - int have_acks2 = (modify->find_fix_by_style("^acks2/reax") != -1); - api->system->acks2_flag = have_acks2; - if (api->system->acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - FixACKS2ReaxFF* acks2_fix = (FixACKS2ReaxFF*) modify->fix[ifix]; - api->workspace->s = acks2_fix->get_s(); - } + if (qeqflag && (have_qeq != 1)) + error->all(FLERR,"Pair style reaxff requires use of exactly one of the " + "fix qeq/reaxff or fix qeq/shielded or fix acks2/reaxff commands"); + + api->system->acks2_flag = acks2_fixes.size(); + if (api->system->acks2_flag) + api->workspace->s = ((FixACKS2ReaxFF *)acks2_fixes.front())->get_s(); api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts @@ -476,9 +472,8 @@ void PairReaxFF::compute(int eflag, int vflag) api->system->bigN = static_cast (atom->natoms); // all atoms in the system if (api->system->acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - FixACKS2ReaxFF* acks2_fix = (FixACKS2ReaxFF*) modify->fix[ifix]; - api->workspace->s = acks2_fix->get_s(); + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + api->workspace->s = ((FixACKS2ReaxFF*) ifix)->get_s(); } // setup data structures diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 9e45ec13d8..29739b294c 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -361,11 +361,17 @@ void FixShake::init() // could have changed locations in fix list since created // set ptrs to rRESPA variables + fix_respa = nullptr; if (utils::strmatch(update->integrate_style,"^respa")) { - ifix_respa = modify->find_fix_by_style("^RESPA"); - nlevels_respa = ((Respa *) update->integrate)->nlevels; - loop_respa = ((Respa *) update->integrate)->loop; - step_respa = ((Respa *) update->integrate)->step; + if (update->whichflag > 0) { + auto fixes = modify->get_fix_by_style("^RESPA"); + if (fixes.size() > 0) fix_respa = (FixRespa *) fixes.front(); + else error->all(FLERR,"Run style respa did not create fix RESPA"); + } + Respa *respa_style = (Respa *) update->integrate; + nlevels_respa = respa_style->nlevels; + loop_respa = respa_style->loop; + step_respa = respa_style->step; } // set equilibrium bond distances @@ -1619,7 +1625,7 @@ void FixShake::unconstrained_update_respa(int ilevel) // x + dt0 (v + dtN/m fN + 1/2 dt(N-1)/m f(N-1) + ... + 1/2 dt0/m f0) // also set dtfsq = dt0*dtN so that shake,shake3,etc can use it - double ***f_level = ((FixRespa *) modify->fix[ifix_respa])->f_level; + double ***f_level = fix_respa->f_level; dtfsq = dtf_inner * step_respa[ilevel]; double invmass,dtfmsq; diff --git a/src/RIGID/fix_shake.h b/src/RIGID/fix_shake.h index c5563ea9b9..3db415281d 100644 --- a/src/RIGID/fix_shake.h +++ b/src/RIGID/fix_shake.h @@ -77,8 +77,8 @@ class FixShake : public Fix { int molecular; // copy of atom->molecular double *bond_distance, *angle_distance; // constraint distances - int ifix_respa; // rRESPA fix needed by SHAKE - int nlevels_respa; // copies of needed rRESPA variables + class FixRespa *fix_respa; // rRESPA fix needed by SHAKE + int nlevels_respa; // copies of needed rRESPA variables int *loop_respa; double *step_respa; diff --git a/src/SPIN/pair_spin.cpp b/src/SPIN/pair_spin.cpp index 74f7aaaf77..4247918499 100644 --- a/src/SPIN/pair_spin.cpp +++ b/src/SPIN/pair_spin.cpp @@ -79,10 +79,8 @@ void PairSpin::init_style() // checking if nve/spin or neb/spin is a listed fix - bool have_fix = ((modify->find_fix_by_style("^nve/spin") != -1) - || (modify->find_fix_by_style("^neb/spin") != -1)); - - if (!have_fix && (comm->me == 0)) + if ((comm->me == 0) && ((modify->get_fix_by_style("^nve/spin").size() + + modify->get_fix_by_style("^neb/spin").size()) == 0)) error->warning(FLERR,"Using spin pair style without nve/spin or neb/spin"); // check if newton pair is on @@ -98,9 +96,11 @@ void PairSpin::init_style() // get the lattice_flag from nve/spin - int ifix = modify->find_fix_by_style("^nve/spin"); - if (ifix >=0) - lattice_flag = ((FixNVESpin *) modify->fix[ifix])->lattice_flag; + auto fixes = modify->get_fix_by_style("^nve/spin"); + if (fixes.size() == 1) + lattice_flag = ((FixNVESpin *) fixes.front())->lattice_flag; + else if (fixes.size() > 1) + error->warning(FLERR,"Using multiple instances of fix nve/spin or neb/spin"); // init. size of energy stacking lists diff --git a/src/atom.cpp b/src/atom.cpp index 03b02b193e..1c18b5a109 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1704,8 +1704,7 @@ 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 (int m = 0; m < modify->nfix; m++) { - Fix *fix = modify->fix[m]; + for (const auto &fix : modify->get_fix_list()) { if (fix->create_attribute) for (int i = nprev; i < nnew; i++) fix->set_arrays(i); @@ -2242,15 +2241,13 @@ void Atom::setup_sort_bins() #ifdef LMP_GPU if (userbinsize == 0.0) { - int ifix = modify->find_fix("package_gpu"); - if (ifix >= 0) { + FixGPU *fix = (FixGPU *)modify->get_fix_by_id("package_gpu"); + if (fix) { const double subx = domain->subhi[0] - domain->sublo[0]; const double suby = domain->subhi[1] - domain->sublo[1]; const double subz = domain->subhi[2] - domain->sublo[2]; - FixGPU *fix = static_cast(modify->fix[ifix]); - binsize = fix->binsize(subx, suby, subz, atom->nlocal, - neighbor->cutneighmax); + binsize = fix->binsize(subx, suby, subz, atom->nlocal,neighbor->cutneighmax); bininv = 1.0 / binsize; nbinx = static_cast (ceil(subx * bininv)); diff --git a/src/balance.cpp b/src/balance.cpp index 3f325dffe6..f2fcda2712 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -496,11 +496,8 @@ void Balance::weight_storage(char *prefix) if (prefix) cmd = prefix; cmd += "IMBALANCE_WEIGHTS"; - int ifix = modify->find_fix(cmd); - if (ifix < 1) { - cmd += " all STORE peratom 0 1"; - fixstore = (FixStore *) modify->add_fix(cmd); - } else fixstore = (FixStore *) modify->fix[ifix]; + fixstore = (FixStore *) modify->get_fix_by_id(cmd); + if (!fixstore) fixstore = (FixStore *) modify->add_fix(cmd + " all STORE peratom 0 1"); // do not carry weights with atoms during normal atom migration diff --git a/src/change_box.cpp b/src/change_box.cpp index 91d65bfcad..bbac78ab3d 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -291,16 +291,12 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == ORTHO) { if (domain->xy != 0.0 || domain->yz != 0.0 || domain->xz != 0.0) - error->all(FLERR, - "Cannot change box to orthogonal when tilt is non-zero"); + error->all(FLERR,"Cannot change box to orthogonal when tilt is non-zero"); if (output->ndump) - error->all(FLERR, - "Cannot change box ortho/triclinic with dumps defined"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->no_change_box) - error->all(FLERR, - "Cannot change box ortho/triclinic with " - "certain fixes defined"); + error->all(FLERR,"Cannot change box ortho/triclinic with dumps defined"); + for (const auto &fix : modify->get_fix_list()) + if (fix->no_change_box) + error->all(FLERR,"Cannot change box ortho/triclinic with certain fixes defined"); domain->triclinic = 0; domain->set_initial_box(); domain->set_global_box(); @@ -309,13 +305,10 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == TRICLINIC) { if (output->ndump) - error->all(FLERR, - "Cannot change box ortho/triclinic with dumps defined"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->no_change_box) - error->all(FLERR, - "Cannot change box ortho/triclinic with " - "certain fixes defined"); + error->all(FLERR,"Cannot change box ortho/triclinic with dumps defined"); + for (const auto &fix : modify->get_fix_list()) + if (fix->no_change_box) + error->all(FLERR,"Cannot change box ortho/triclinic with certain fixes defined"); domain->triclinic = 1; domain->set_lamda_box(); domain->set_initial_box(); diff --git a/src/comm.cpp b/src/comm.cpp index 7a8a520059..84059d16cf 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -201,8 +201,9 @@ void Comm::init() if (ghost_velocity) size_forward += atom->avec->size_velocity; if (ghost_velocity) size_border += atom->avec->size_velocity; - for (int i = 0; i < modify->nfix; i++) - size_border += modify->fix[i]->comm_border; + const auto &fix_list = modify->get_fix_list(); + for (const auto &fix : fix_list) + size_border += fix->comm_border; // per-atom limits for communication // maxexchange = max # of datums in exchange comm, set in exchange() @@ -220,9 +221,9 @@ void Comm::init() if (force->bond) maxforward = MAX(maxforward,force->bond->comm_forward); if (force->bond) maxreverse = MAX(maxreverse,force->bond->comm_reverse); - for (int i = 0; i < modify->nfix; i++) { - maxforward = MAX(maxforward,modify->fix[i]->comm_forward); - maxreverse = MAX(maxreverse,modify->fix[i]->comm_reverse); + for (const auto &fix : fix_list) { + maxforward = MAX(maxforward,fix->comm_forward); + maxreverse = MAX(maxreverse,fix->comm_reverse); } for (int i = 0; i < modify->ncompute; i++) { @@ -245,12 +246,9 @@ void Comm::init() maxexchange_atom = atom->avec->maxexchange; - int nfix = modify->nfix; - Fix **fix = modify->fix; - maxexchange_fix_dynamic = 0; - for (int i = 0; i < nfix; i++) - if (fix[i]->maxexchange_dynamic) maxexchange_fix_dynamic = 1; + for (const auto &fix : fix_list) + if (fix->maxexchange_dynamic) maxexchange_fix_dynamic = 1; if ((mode == Comm::MULTI) && (neighbor->style != Neighbor::MULTI)) error->all(FLERR,"Cannot use comm mode multi without multi-style neighbor lists"); @@ -271,12 +269,9 @@ void Comm::init() void Comm::init_exchange() { - int nfix = modify->nfix; - Fix **fix = modify->fix; - maxexchange_fix = 0; - for (int i = 0; i < nfix; i++) - maxexchange_fix += fix[i]->maxexchange; + for (const auto &fix : modify->get_fix_list()) + maxexchange_fix += fix->maxexchange; maxexchange = maxexchange_atom + maxexchange_fix; bufextra = maxexchange + BUFEXTRA; diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index 787dc43fc6..1351d379b7 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -29,10 +28,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - idchunk(nullptr), massproc(nullptr), masstotal(nullptr), com(nullptr), comall(nullptr), angmom(nullptr), angmomall(nullptr) + Compute(lmp, narg, arg), idchunk(nullptr), massproc(nullptr), masstotal(nullptr), com(nullptr), + comall(nullptr), angmom(nullptr), angmomall(nullptr) { - if (narg != 4) error->all(FLERR,"Illegal compute angmom/chunk command"); + if (narg != 4) error->all(FLERR, "Illegal compute angmom/chunk command"); array_flag = 1; size_array_cols = 3; @@ -57,7 +56,7 @@ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : ComputeAngmomChunk::~ComputeAngmomChunk() { - delete [] idchunk; + delete[] idchunk; memory->destroy(massproc); memory->destroy(masstotal); memory->destroy(com); @@ -70,21 +69,18 @@ ComputeAngmomChunk::~ComputeAngmomChunk() void ComputeAngmomChunk::init() { - int icompute = modify->find_compute(idchunk); - if (icompute < 0) - error->all(FLERR,"Chunk/atom compute does not exist for " - "compute angmom/chunk"); - cchunk = (ComputeChunkAtom *) modify->compute[icompute]; - if (strcmp(cchunk->style,"chunk/atom") != 0) - error->all(FLERR,"Compute angmom/chunk does not use chunk/atom compute"); + cchunk = (ComputeChunkAtom *) modify->get_compute_by_id(idchunk); + if (!cchunk) error->all(FLERR, "Chunk/atom compute does not exist for compute angmom/chunk"); + if (strcmp(cchunk->style, "chunk/atom") != 0) + error->all(FLERR, "Compute angmom/chunk does not use chunk/atom compute"); } /* ---------------------------------------------------------------------- */ void ComputeAngmomChunk::compute_array() { - int i,index; - double dx,dy,dz,massone; + int i, index; + double dx, dy, dz, massone; double unwrap[3]; invoked_array = update->ntimestep; @@ -120,19 +116,21 @@ void ComputeAngmomChunk::compute_array() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - index = ichunk[i]-1; + index = ichunk[i] - 1; if (index < 0) continue; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - domain->unmap(x[i],image[i],unwrap); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + domain->unmap(x[i], image[i], unwrap); massproc[index] += massone; com[index][0] += unwrap[0] * massone; com[index][1] += unwrap[1] * massone; com[index][2] += unwrap[2] * massone; } - MPI_Allreduce(massproc,masstotal,nchunk,MPI_DOUBLE,MPI_SUM,world); - MPI_Allreduce(&com[0][0],&comall[0][0],3*nchunk,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(massproc, masstotal, nchunk, MPI_DOUBLE, MPI_SUM, world); + MPI_Allreduce(&com[0][0], &comall[0][0], 3 * nchunk, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < nchunk; i++) { if (masstotal[i] > 0.0) { @@ -148,21 +146,22 @@ void ComputeAngmomChunk::compute_array() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - index = ichunk[i]-1; + index = ichunk[i] - 1; if (index < 0) continue; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - comall[index][0]; dy = unwrap[1] - comall[index][1]; dz = unwrap[2] - comall[index][2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - angmom[index][0] += massone * (dy*v[i][2] - dz*v[i][1]); - angmom[index][1] += massone * (dz*v[i][0] - dx*v[i][2]); - angmom[index][2] += massone * (dx*v[i][1] - dy*v[i][0]); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + angmom[index][0] += massone * (dy * v[i][2] - dz * v[i][1]); + angmom[index][1] += massone * (dz * v[i][0] - dx * v[i][2]); + angmom[index][2] += massone * (dx * v[i][1] - dy * v[i][0]); } - MPI_Allreduce(&angmom[0][0],&angmomall[0][0],3*nchunk, - MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&angmom[0][0], &angmomall[0][0], 3 * nchunk, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -209,7 +208,7 @@ int ComputeAngmomChunk::lock_length() void ComputeAngmomChunk::lock(Fix *fixptr, bigint startstep, bigint stopstep) { - cchunk->lock(fixptr,startstep,stopstep); + cchunk->lock(fixptr, startstep, stopstep); } /* ---------------------------------------------------------------------- @@ -234,12 +233,12 @@ void ComputeAngmomChunk::allocate() memory->destroy(angmom); memory->destroy(angmomall); maxchunk = nchunk; - memory->create(massproc,maxchunk,"angmom/chunk:massproc"); - memory->create(masstotal,maxchunk,"angmom/chunk:masstotal"); - memory->create(com,maxchunk,3,"angmom/chunk:com"); - memory->create(comall,maxchunk,3,"angmom/chunk:comall"); - memory->create(angmom,maxchunk,3,"angmom/chunk:angmom"); - memory->create(angmomall,maxchunk,3,"angmom/chunk:angmomall"); + memory->create(massproc, maxchunk, "angmom/chunk:massproc"); + memory->create(masstotal, maxchunk, "angmom/chunk:masstotal"); + memory->create(com, maxchunk, 3, "angmom/chunk:com"); + memory->create(comall, maxchunk, 3, "angmom/chunk:comall"); + memory->create(angmom, maxchunk, 3, "angmom/chunk:angmom"); + memory->create(angmomall, maxchunk, 3, "angmom/chunk:angmomall"); array = angmomall; } @@ -250,7 +249,7 @@ void ComputeAngmomChunk::allocate() double ComputeAngmomChunk::memory_usage() { double bytes = (bigint) maxchunk * 2 * sizeof(double); - bytes += (double) maxchunk * 2*3 * sizeof(double); - bytes += (double) maxchunk * 2*3 * sizeof(double); + bytes += (double) maxchunk * 2 * 3 * sizeof(double); + bytes += (double) maxchunk * 2 * 3 * sizeof(double); return bytes; } diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index c35b6a63e7..a050c8bb6a 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -13,33 +12,34 @@ ------------------------------------------------------------------------- */ #include "compute_centroid_stress_atom.h" -#include -#include "atom.h" -#include "update.h" -#include "comm.h" -#include "force.h" -#include "pair.h" -#include "bond.h" + #include "angle.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" #include "dihedral.h" +#include "error.h" +#include "fix.h" +#include "force.h" #include "improper.h" #include "kspace.h" -#include "modify.h" -#include "fix.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "pair.h" +#include "update.h" + +#include using namespace LAMMPS_NS; -enum{NOBIAS,BIAS}; +enum { NOBIAS, BIAS }; /* ---------------------------------------------------------------------- */ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - id_temp(nullptr), stress(nullptr) + Compute(lmp, narg, arg), id_temp(nullptr), stress(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute centroid/stress/atom command"); + if (narg < 4) error->all(FLERR, "Illegal compute centroid/stress/atom command"); peratom_flag = 1; size_peratom_cols = 9; @@ -50,17 +50,16 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char // store temperature ID used by stress computation // insure it is valid for temperature computation - if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; + if (strcmp(arg[3], "NULL") == 0) + id_temp = nullptr; else { id_temp = utils::strdup(arg[3]); - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute centroid/stress/atom temperature ID"); - if (modify->compute[icompute]->tempflag == 0) - error->all(FLERR, - "Compute centroid/stress/atom temperature ID does not " - "compute temperature"); + auto compute = modify->get_compute_by_id(id_temp); + if (!compute) + error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}", id_temp); + if (compute->tempflag == 0) + error->all(FLERR, "Compute centroid/stress/atom temperature ID does not compute temperature"); } // process optional args @@ -79,19 +78,28 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char fixflag = 0; int iarg = 4; while (iarg < narg) { - if (strcmp(arg[iarg],"ke") == 0) keflag = 1; - else if (strcmp(arg[iarg],"pair") == 0) pairflag = 1; - else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1; - else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1; - else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1; - else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1; - else if (strcmp(arg[iarg],"kspace") == 0) kspaceflag = 1; - else if (strcmp(arg[iarg],"fix") == 0) fixflag = 1; - else if (strcmp(arg[iarg],"virial") == 0) { + if (strcmp(arg[iarg], "ke") == 0) + keflag = 1; + else if (strcmp(arg[iarg], "pair") == 0) + pairflag = 1; + else if (strcmp(arg[iarg], "bond") == 0) + bondflag = 1; + else if (strcmp(arg[iarg], "angle") == 0) + angleflag = 1; + else if (strcmp(arg[iarg], "dihedral") == 0) + dihedralflag = 1; + else if (strcmp(arg[iarg], "improper") == 0) + improperflag = 1; + else if (strcmp(arg[iarg], "kspace") == 0) + kspaceflag = 1; + else if (strcmp(arg[iarg], "fix") == 0) + fixflag = 1; + else if (strcmp(arg[iarg], "virial") == 0) { pairflag = 1; bondflag = angleflag = dihedralflag = improperflag = 1; kspaceflag = fixflag = 1; - } else error->all(FLERR,"Illegal compute centroid/stress/atom command"); + } else + error->all(FLERR, "Illegal compute centroid/stress/atom command"); iarg++; } } @@ -103,7 +111,7 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char ComputeCentroidStressAtom::~ComputeCentroidStressAtom() { - delete [] id_temp; + delete[] id_temp; memory->destroy(stress); } @@ -115,13 +123,15 @@ void ComputeCentroidStressAtom::init() // fixes could have changed or compute_modify could have changed it if (id_temp) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute centroid/stress/atom temperature ID"); - temperature = modify->compute[icompute]; - if (temperature->tempbias) biasflag = BIAS; - else biasflag = NOBIAS; - } else biasflag = NOBIAS; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}",id_temp); + if (temperature->tempbias) + biasflag = BIAS; + else + biasflag = NOBIAS; + } else + biasflag = NOBIAS; // check if force components and fixes support centroid atom stress // all bond styles support it as CENTROID_SAME @@ -158,12 +168,12 @@ void ComputeCentroidStressAtom::init() void ComputeCentroidStressAtom::compute_peratom() { - int i,j; + int i, j; double onemass; invoked_peratom = update->ntimestep; if (update->vflag_atom != invoked_peratom) - error->all(FLERR,"Per-atom virial was not tallied on needed timestep"); + error->all(FLERR, "Per-atom virial was not tallied on needed timestep"); // grow local stress array if necessary // needs to be atom->nmax in length @@ -171,7 +181,7 @@ void ComputeCentroidStressAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(stress); nmax = atom->nmax; - memory->create(stress,nmax,9,"centroid/stress/atom:stress"); + memory->create(stress, nmax, 9, "centroid/stress/atom:stress"); array_atom = stress; } @@ -194,8 +204,7 @@ void ComputeCentroidStressAtom::compute_peratom() // clear local stress array for (i = 0; i < ntotal; i++) - for (j = 0; j < 9; j++) - stress[i][j] = 0.0; + for (j = 0; j < 9; j++) stress[i][j] = 0.0; // add in per-atom contributions from all force components and fixes @@ -205,15 +214,12 @@ void ComputeCentroidStressAtom::compute_peratom() if (force->pair->centroidstressflag == CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } else { double **vatom = force->pair->vatom; for (i = 0; i < npair; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } } @@ -226,41 +232,34 @@ void ComputeCentroidStressAtom::compute_peratom() if (bondflag && force->bond) { double **vatom = force->bond->vatom; for (i = 0; i < nbond; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } if (angleflag && force->angle) { double **cvatom = force->angle->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (dihedralflag && force->dihedral) { double **cvatom = force->dihedral->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (improperflag && force->improper) { double **cvatom = force->improper->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (kspaceflag && force->kspace && force->kspace->compute_flag) { double **vatom = force->kspace->vatom; for (i = 0; i < nkspace; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } @@ -279,18 +278,15 @@ void ComputeCentroidStressAtom::compute_peratom() double **vatom = fix[ifix]->vatom; if (vatom) for (i = 0; i < nlocal; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } } // communicate ghost virials between neighbor procs - if (force->newton || - (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) + if (force->newton || (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) comm->reverse_comm_compute(this); // zero virial of atoms not in group @@ -327,30 +323,30 @@ void ComputeCentroidStressAtom::compute_peratom() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { onemass = mvv2e * rmass[i]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; } } else { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { onemass = mvv2e * mass[type[i]]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; } } @@ -359,41 +355,40 @@ void ComputeCentroidStressAtom::compute_peratom() // invoke temperature if it hasn't been already // this insures bias factor is pre-computed - if (keflag && temperature->invoked_scalar != update->ntimestep) - temperature->compute_scalar(); + if (keflag && temperature->invoked_scalar != update->ntimestep) temperature->compute_scalar(); if (rmass) { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - temperature->remove_bias(i,v[i]); + temperature->remove_bias(i, v[i]); onemass = mvv2e * rmass[i]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; - temperature->restore_bias(i,v[i]); + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; + temperature->restore_bias(i, v[i]); } } else { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - temperature->remove_bias(i,v[i]); + temperature->remove_bias(i, v[i]); onemass = mvv2e * mass[type[i]]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; - temperature->restore_bias(i,v[i]); + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; + temperature->restore_bias(i, v[i]); } } } @@ -420,7 +415,7 @@ void ComputeCentroidStressAtom::compute_peratom() int ComputeCentroidStressAtom::pack_reverse_comm(int n, int first, double *buf) { - int i,m,last; + int i, m, last; m = 0; last = first + n; @@ -442,7 +437,7 @@ int ComputeCentroidStressAtom::pack_reverse_comm(int n, int first, double *buf) void ComputeCentroidStressAtom::unpack_reverse_comm(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; m = 0; for (i = 0; i < n; i++) { @@ -465,6 +460,6 @@ void ComputeCentroidStressAtom::unpack_reverse_comm(int n, int *list, double *bu double ComputeCentroidStressAtom::memory_usage() { - double bytes = (double)nmax*9 * sizeof(double); + double bytes = (double) nmax * 9 * sizeof(double); return bytes; } diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index fc4f17e53a..daa8fc64e7 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -316,40 +316,30 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : } if (which == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(cfvid); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute chunk /atom does not exist"); - if (modify->compute[icompute]->peratom_flag == 0) - error->all(FLERR, - "Compute chunk/atom compute does not calculate " - "per-atom values"); - if (argindex == 0 && - modify->compute[icompute]->size_peratom_cols != 0) - error->all(FLERR,"Compute chunk/atom compute does not " - "calculate a per-atom vector"); - if (argindex && modify->compute[icompute]->size_peratom_cols == 0) - error->all(FLERR,"Compute chunk/atom compute does not " - "calculate a per-atom array"); - if (argindex && - argindex > modify->compute[icompute]->size_peratom_cols) - error->all(FLERR,"Compute chunk/atom compute array is " - "accessed out-of-range"); + cchunk = modify->get_compute_by_id(cfvid); + if (!cchunk) + error->all(FLERR,"Compute ID {} for compute chunk /atom does not exist",cfvid); + if (cchunk->peratom_flag == 0) + error->all(FLERR,"Compute chunk/atom compute does not calculate per-atom values"); + if ((argindex == 0) && (cchunk->size_peratom_cols != 0)) + error->all(FLERR,"Compute chunk/atom compute does not calculate a per-atom vector"); + if (argindex && (cchunk->size_peratom_cols == 0)) + error->all(FLERR,"Compute chunk/atom compute does not calculate a per-atom array"); + if (argindex && argindex > cchunk->size_peratom_cols) + error->all(FLERR,"Compute chunk/atom compute array is accessed out-of-range"); } if (which == ArgInfo::FIX) { - int ifix = modify->find_fix(cfvid); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute chunk/atom does not exist"); - if (modify->fix[ifix]->peratom_flag == 0) - error->all(FLERR,"Compute chunk/atom fix does not calculate " - "per-atom values"); - if (argindex == 0 && modify->fix[ifix]->size_peratom_cols != 0) - error->all(FLERR, - "Compute chunk/atom fix does not calculate a per-atom vector"); - if (argindex && modify->fix[ifix]->size_peratom_cols == 0) - error->all(FLERR, - "Compute chunk/atom fix does not calculate a per-atom array"); - if (argindex && argindex > modify->fix[ifix]->size_peratom_cols) + fchunk = modify->get_fix_by_id(cfvid); + if (!fchunk) + error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",cfvid); + if (fchunk->peratom_flag == 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate per-atom values"); + if (argindex == 0 && fchunk->size_peratom_cols != 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate a per-atom vector"); + if (argindex && fchunk->size_peratom_cols == 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate a per-atom array"); + if (argindex && argindex > fchunk->size_peratom_cols) error->all(FLERR,"Compute chunk/atom fix array is accessed out-of-range"); } @@ -358,16 +348,14 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : if (ivariable < 0) error->all(FLERR,"Variable name for compute chunk/atom does not exist"); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Compute chunk/atom variable is not " - "atom-style variable"); + error->all(FLERR,"Compute chunk/atom variable is not atom-style variable"); } // setup scaling if (binflag) { if (domain->triclinic == 1 && scaleflag != REDUCED) - error->all(FLERR,"Compute chunk/atom for triclinic boxes " - "requires units reduced"); + error->all(FLERR,"Compute chunk/atom for triclinic boxes requires units reduced"); } if (scaleflag == LATTICE) { @@ -501,15 +489,13 @@ void ComputeChunkAtom::init() // set compute,fix,variable if (which == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(cfvid); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute chunk/atom does not exist"); - cchunk = modify->compute[icompute]; + cchunk = modify->get_compute_by_id(cfvid); + if (!cchunk) + error->all(FLERR,"Compute ID {} for compute chunk/atom does not exist",cfvid); } else if (which == ArgInfo::FIX) { - int ifix = modify->find_fix(cfvid); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute chunk/atom does not exist"); - fchunk = modify->fix[ifix]; + fchunk = modify->get_fix_by_id(cfvid); + if (!fchunk) + error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",cfvid); } else if (which == ArgInfo::VARIABLE) { int ivariable = input->variable->find(cfvid); if (ivariable < 0) diff --git a/src/domain.cpp b/src/domain.cpp index daaf41338f..22c38c977a 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -140,19 +140,19 @@ void Domain::init() int box_change_x=0, box_change_y=0, box_change_z=0; int box_change_yz=0, box_change_xz=0, box_change_xy=0; - Fix **fixes = modify->fix; + const auto &fixes = modify->get_fix_list(); if (nonperiodic == 2) box_change_size = 1; - for (int i = 0; i < modify->nfix; i++) { - if (fixes[i]->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_X) box_change_x++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_Y) box_change_y++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_Z) box_change_z++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_XY) box_change_xy++; + for (const auto &fix : fixes) { + if (fix->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1; + if (fix->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1; + if (fix->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1; + if (fix->box_change & Fix::BOX_CHANGE_X) box_change_x++; + if (fix->box_change & Fix::BOX_CHANGE_Y) box_change_y++; + if (fix->box_change & Fix::BOX_CHANGE_Z) box_change_z++; + if (fix->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++; + if (fix->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++; + if (fix->box_change & Fix::BOX_CHANGE_XY) box_change_xy++; } std::string mesg = "Must not have multiple fixes change box parameter "; @@ -174,12 +174,12 @@ void Domain::init() // check for fix deform deform_flag = deform_vremap = deform_groupbit = 0; - for (int i = 0; i < modify->nfix; i++) - if (utils::strmatch(modify->fix[i]->style,"^deform")) { + for (const auto &fix : fixes) + if (utils::strmatch(fix->style,"^deform")) { deform_flag = 1; - if (((FixDeform *) modify->fix[i])->remapflag == Domain::V_REMAP) { + if (((FixDeform *) fix)->remapflag == Domain::V_REMAP) { deform_vremap = 1; - deform_groupbit = modify->fix[i]->groupbit; + deform_groupbit = fix->groupbit; } } @@ -1742,7 +1742,7 @@ void Domain::add_region(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal region command"); if (strcmp(arg[1],"delete") == 0) { - delete_region(narg,arg); + delete_region(arg[0]); return; } @@ -1811,16 +1811,6 @@ Region *Domain::region_creator(LAMMPS *lmp, int narg, char ** arg) delete a region ------------------------------------------------------------------------- */ -void Domain::delete_region(int narg, char **arg) -{ - if (narg != 2) error->all(FLERR,"Illegal region command"); - - int iregion = find_region(arg[0]); - if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); - - delete_region(iregion); -} - void Domain::delete_region(int iregion) { if ((iregion < 0) || (iregion >= nregion)) return; @@ -1833,12 +1823,20 @@ void Domain::delete_region(int iregion) nregion--; } +void Domain::delete_region(const std::string &id) +{ + int iregion = find_region(id); + if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); + + delete_region(iregion); +} + /* ---------------------------------------------------------------------- return region index if name matches existing region ID return -1 if no such region ------------------------------------------------------------------------- */ -int Domain::find_region(const std::string &name) +int Domain::find_region(const std::string &name) const { for (int iregion = 0; iregion < nregion; iregion++) if (name == regions[iregion]->id) return iregion; @@ -1846,15 +1844,31 @@ int Domain::find_region(const std::string &name) } /* ---------------------------------------------------------------------- - return region index if name matches existing region style - return -1 if no such region + return pointer to region name matches existing region ID + return null if no match ------------------------------------------------------------------------- */ -int Domain::find_region_by_style(const std::string &name) +Region *Domain::get_region_by_id(const std::string &name) const { for (int iregion = 0; iregion < nregion; iregion++) - if (name == regions[iregion]->style) return iregion; - return -1; + if (name == regions[iregion]->id) return regions[iregion]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointers to regions by region style name + return vector with matching pointers +------------------------------------------------------------------------- */ + +const std::vector Domain::get_region_by_style(const std::string &name) const +{ + std::vector matches; + if (name.empty()) return matches; + + for (int iregion = 0; iregion < nregion; iregion++) + if (name == regions[iregion]->style) matches.push_back(regions[iregion]); + + return matches; } /* ---------------------------------------------------------------------- diff --git a/src/domain.h b/src/domain.h index 711bab0fb2..234bdbb837 100644 --- a/src/domain.h +++ b/src/domain.h @@ -137,10 +137,11 @@ class Domain : protected Pointers { void set_lattice(int, char **); void add_region(int, char **); - void delete_region(int, char **); void delete_region(int); - int find_region(const std::string &); - int find_region_by_style(const std::string &); + void delete_region(const std::string &); + int find_region(const std::string &) const; + Region *get_region_by_id(const std::string &) const; + const std::vector get_region_by_style(const std::string &) const; void set_boundary(int, char **, int); void set_box(int, char **); void print_box(const std::string &); diff --git a/src/dump.cpp b/src/dump.cpp index d00c42086d..4c02aa3070 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -248,8 +248,8 @@ void Dump::init() reorderflag = 0; int gcmcflag = 0; - for (int i = 0; i < modify->nfix; i++) - if ((strcmp(modify->fix[i]->style,"gcmc") == 0)) + for (const auto &fix : modify->get_fix_list()) + if (utils::strmatch(fix->style,"^gcmc")) gcmcflag = 1; if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag) { diff --git a/src/finish.cpp b/src/finish.cpp index 81ba59c1df..f3dbc83498 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -364,14 +364,13 @@ void Finish::end(int flag) } #ifdef LMP_OPENMP - int ifix = modify->find_fix("package_omp"); + FixOMP *fixomp = (FixOMP *) modify->get_fix_by_id("package_omp"); // print thread breakdown only with full timer detail - if ((ifix >= 0) && timer->has_full() && me == 0) { + if (fixomp && timer->has_full() && me == 0) { double thr_total = 0.0; ThrData *td; - FixOMP *fixomp = static_cast(lmp->modify->fix[ifix]); for (i=0; i < nthreads; ++i) { td = fixomp->get_thr(i); thr_total += td->get_time(Timer::ALL); diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index a3da6e6a3d..836121fdc2 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -243,10 +243,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : if (any_variable_length && (nrepeat > 1 || ave == RUNNING || ave == WINDOW)) { for (int i = 0; i < nvalues; i++) - if (varlen[i] && which[i] == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(ids[i]); - modify->compute[icompute]->lock_enable(); - } + if (varlen[i] && which[i] == ArgInfo::COMPUTE) + modify->get_compute_by_id(ids[i])->lock_enable(); lockforever = 0; } diff --git a/src/fix_deposit.cpp b/src/fix_deposit.cpp index 7f153cd172..c18a0e23dd 100644 --- a/src/fix_deposit.cpp +++ b/src/fix_deposit.cpp @@ -74,18 +74,18 @@ FixDeposit::FixDeposit(LAMMPS *lmp, int narg, char **arg) : // error checks on region and its extent being inside simulation box - if (iregion == -1) error->all(FLERR,"Must specify a region in fix deposit"); - if (domain->regions[iregion]->bboxflag == 0) + if (!iregion) error->all(FLERR,"Must specify a region in fix deposit"); + if (iregion->bboxflag == 0) error->all(FLERR,"Fix deposit region does not support a bounding box"); - if (domain->regions[iregion]->dynamic_check()) + if (iregion->dynamic_check()) error->all(FLERR,"Fix deposit region cannot be dynamic"); - xlo = domain->regions[iregion]->extent_xlo; - xhi = domain->regions[iregion]->extent_xhi; - ylo = domain->regions[iregion]->extent_ylo; - yhi = domain->regions[iregion]->extent_yhi; - zlo = domain->regions[iregion]->extent_zlo; - zhi = domain->regions[iregion]->extent_zhi; + xlo = iregion->extent_xlo; + xhi = iregion->extent_xhi; + ylo = iregion->extent_ylo; + yhi = iregion->extent_yhi; + zlo = iregion->extent_zlo; + zhi = iregion->extent_zhi; if (domain->triclinic == 0) { if (xlo < domain->boxlo[0] || xhi > domain->boxhi[0] || @@ -227,23 +227,19 @@ void FixDeposit::init() { // set index and check validity of region - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix deposit does not exist"); + iregion = domain->get_region_by_id(idregion); + if (!iregion) error->all(FLERR,"Region ID {} for fix deposit does not exist", idregion); // if rigidflag defined, check for rigid/small fix // its molecule template must be same as this one fixrigid = nullptr; if (rigidflag) { - int ifix = modify->find_fix(idrigid); - if (ifix < 0) error->all(FLERR,"Fix deposit rigid fix does not exist"); - fixrigid = modify->fix[ifix]; + fixrigid = modify->get_fix_by_id(idrigid); + if (!fixrigid) error->all(FLERR,"Fix deposit rigid fix ID {} does not exist", idrigid); int tmp; if (onemols != (Molecule **) fixrigid->extract("onemol",tmp)) - error->all(FLERR, - "Fix deposit and fix rigid/small not using " - "same molecule template ID"); + error->all(FLERR, "Fix deposit and rigid fix are not using the same molecule template ID"); } // if shakeflag defined, check for SHAKE fix @@ -251,13 +247,11 @@ void FixDeposit::init() fixshake = nullptr; if (shakeflag) { - int ifix = modify->find_fix(idshake); - if (ifix < 0) error->all(FLERR,"Fix deposit shake fix does not exist"); - fixshake = modify->fix[ifix]; + fixshake = modify->get_fix_by_id(idshake); + if (!fixshake) error->all(FLERR,"Fix deposit shake fix ID {} does not exist", idshake); int tmp; if (onemols != (Molecule **) fixshake->extract("onemol",tmp)) - error->all(FLERR,"Fix deposit and fix shake not using " - "same molecule template ID"); + error->all(FLERR,"Fix deposit and fix shake are not using the same molecule template ID"); } // for finite size spherical particles: @@ -357,13 +351,13 @@ void FixDeposit::pre_exchange() coord[0] = xlo + random->uniform() * (xhi-xlo); coord[1] = ylo + random->uniform() * (yhi-ylo); coord[2] = zlo + random->uniform() * (zhi-zlo); - } while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0); + } while (iregion->match(coord[0],coord[1],coord[2]) == 0); } else if (distflag == DIST_GAUSSIAN) { do { coord[0] = xmid + random->gaussian() * sigma; coord[1] = ymid + random->gaussian() * sigma; coord[2] = zmid + random->gaussian() * sigma; - } while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0); + } while (iregion->match(coord[0],coord[1],coord[2]) == 0); } else error->all(FLERR,"Unknown particle distribution in fix deposit"); // adjust vertical coord by offset @@ -662,7 +656,7 @@ void FixDeposit::options(int narg, char **arg) { // defaults - iregion = -1; + iregion = nullptr; idregion = nullptr; mode = ATOM; molfrac = nullptr; @@ -691,17 +685,15 @@ void FixDeposit::options(int narg, char **arg) while (iarg < narg) { if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix deposit does not exist"); + iregion = domain->get_region_by_id(arg[iarg+1]); + if (!iregion) error->all(FLERR,"Region ID {} for fix deposit does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"mol") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) - error->all(FLERR,"Molecule template ID for fix deposit does not exist"); + if (imol == -1) error->all(FLERR,"Molecule template ID for fix deposit does not exist"); mode = MOLECULE; onemols = &atom->molecules[imol]; nmol = onemols[0]->nset; diff --git a/src/fix_deposit.h b/src/fix_deposit.h index a7c506beb6..cc7d482fb0 100644 --- a/src/fix_deposit.h +++ b/src/fix_deposit.h @@ -38,12 +38,13 @@ class FixDeposit : public Fix { private: int ninsert, ntype, nfreq, seed; - int iregion, globalflag, localflag, maxattempt, rateflag, scaleflag, targetflag; + int globalflag, localflag, maxattempt, rateflag, scaleflag, targetflag; int mode, rigidflag, shakeflag, idnext, distflag, orientflag; double lo, hi, deltasq, nearsq, rate, sigma; double vxlo, vxhi, vylo, vyhi, vzlo, vzhi; double xlo, xhi, ylo, yhi, zlo, zhi, xmid, ymid, zmid; double rx, ry, rz, tx, ty, tz; + class Region *iregion; char *idregion; char *idrigid, *idshake; diff --git a/src/fix_gravity.cpp b/src/fix_gravity.cpp index 743fc705d2..16cd97469d 100644 --- a/src/fix_gravity.cpp +++ b/src/fix_gravity.cpp @@ -32,7 +32,6 @@ using namespace FixConst; using namespace MathConst; enum{CHUTE,SPHERICAL,VECTOR}; -enum{CONSTANT,EQUAL}; // same as FixPour /* ---------------------------------------------------------------------- */ diff --git a/src/fix_gravity.h b/src/fix_gravity.h index 31b6eb3478..389c5a1af1 100644 --- a/src/fix_gravity.h +++ b/src/fix_gravity.h @@ -37,6 +37,7 @@ class FixGravity : public Fix { virtual void post_force_respa(int, int, int); double compute_scalar(); void *extract(const char *, int &); + enum { CONSTANT, EQUAL }; protected: int style, disable; diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp index 9066182ed1..e916b8e9fe 100644 --- a/src/fix_vector.cpp +++ b/src/fix_vector.cpp @@ -65,64 +65,54 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) : // setup and error check // for fix inputs, check that fix frequency is acceptable - - for (int i = 0; i < nvalues; i++) { - if (which[i] == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(ids[i]); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix vector does not exist"); - if (argindex[i] == 0 && modify->compute[icompute]->scalar_flag == 0) - error->all(FLERR,"Fix vector compute does not calculate a scalar"); - if (argindex[i] && modify->compute[icompute]->vector_flag == 0) - error->all(FLERR,"Fix vector compute does not calculate a vector"); - if (argindex[i] && argindex[i] > modify->compute[icompute]->size_vector) - error->all(FLERR, - "Fix vector compute vector is accessed out-of-range"); - - } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for fix vector does not exist"); - if (argindex[i] == 0 && modify->fix[ifix]->scalar_flag == 0) - error->all(FLERR,"Fix vector fix does not calculate a scalar"); - if (argindex[i] && modify->fix[ifix]->vector_flag == 0) - error->all(FLERR,"Fix vector fix does not calculate a vector"); - if (argindex[i] && argindex[i] > modify->fix[ifix]->size_vector) - error->all(FLERR,"Fix vector fix vector is accessed out-of-range"); - if (nevery % modify->fix[ifix]->global_freq) - error->all(FLERR, - "Fix for fix vector not computed at compatible time"); - - } else if (which[i] == ArgInfo::VARIABLE) { - int ivariable = input->variable->find(ids[i]); - if (ivariable < 0) - error->all(FLERR,"Variable name for fix vector does not exist"); - if (argindex[i] == 0 && input->variable->equalstyle(ivariable) == 0) - error->all(FLERR,"Fix vector variable is not equal-style variable"); - if (argindex[i] && input->variable->vectorstyle(ivariable) == 0) - error->all(FLERR,"Fix vector variable is not vector-style variable"); - } - } - // this fix produces either a global vector or array // intensive/extensive flags set by compute,fix,variable that produces value int value,finalvalue; for (int i = 0; i < nvalues; i++) { if (which[i] == ArgInfo::COMPUTE) { - Compute *compute = modify->compute[modify->find_compute(ids[i])]; - if (argindex[0] == 0) value = compute->extscalar; - else if (compute->extvector >= 0) value = compute->extvector; - else value = compute->extlist[argindex[0]-1]; + auto icompute = modify->get_compute_by_id(ids[i]); + if (!icompute) error->all(FLERR,"Compute ID {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && icompute->scalar_flag == 0) + error->all(FLERR,"Fix vector compute {} does not calculate a scalar",ids[i]); + if (argindex[i] && icompute->vector_flag == 0) + error->all(FLERR,"Fix vector compute {} does not calculate a vector",ids[i]); + if (argindex[i] && argindex[i] > icompute->size_vector) + error->all(FLERR,"Fix vector compute {} vector is accessed out-of-range",ids[i]); + + if (argindex[i] == 0) value = icompute->extscalar; + else if (icompute->extvector >= 0) value = icompute->extvector; + else value = icompute->extlist[argindex[i]-1]; + } else if (which[i] == ArgInfo::FIX) { - Fix *fix = modify->fix[modify->find_fix(ids[i])]; - if (argindex[i] == 0) value = fix->extvector; - else value = fix->extarray; - } else if (which[i] == ArgInfo::VARIABLE) value = 0; + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) error->all(FLERR,"Fix ID {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && ifix->scalar_flag == 0) + error->all(FLERR,"Fix vector fix {} does not calculate a scalar",ids[i]); + if (argindex[i] && ifix->vector_flag == 0) + error->all(FLERR,"Fix vector fix {} does not calculate a vector",ids[i]); + if (argindex[i] && argindex[i] > ifix->size_vector) + error->all(FLERR,"Fix vector fix {} vector is accessed out-of-range",ids[i]); + if (nevery % ifix->global_freq) + error->all(FLERR,"Fix for fix {} vector not computed at compatible time",ids[i]); + + if (argindex[i] == 0) value = ifix->extvector; + else value = ifix->extarray; + + } else if (which[i] == ArgInfo::VARIABLE) { + int ivariable = input->variable->find(ids[i]); + if (ivariable < 0) + error->all(FLERR,"Variable name {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && input->variable->equalstyle(ivariable) == 0) + error->all(FLERR,"Fix vector variable {} is not equal-style variable",ids[i]); + if (argindex[i] && input->variable->vectorstyle(ivariable) == 0) + error->all(FLERR,"Fix vector variable {} is not vector-style variable",ids[i]); + value = 0; + } + if (i == 0) finalvalue = value; else if (value != finalvalue) - error->all(FLERR,"Fix vector cannot set output array " - "intensive/extensive from these inputs"); + error->all(FLERR,"Fix vector cannot set output array intensive/extensive from these inputs"); } if (nvalues == 1) { @@ -191,14 +181,12 @@ void FixVector::init() for (int i = 0; i < nvalues; i++) { if (which[i] == ArgInfo::COMPUTE) { int icompute = modify->find_compute(ids[i]); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix vector does not exist"); + if (icompute < 0) error->all(FLERR,"Compute ID {} for fix vector does not exist",id[i]); value2index[i] = icompute; } else if (which[i] == ArgInfo::FIX) { int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for fix vector does not exist"); + if (ifix < 0) error->all(FLERR,"Fix ID {} for fix vector does not exist",id[i]); value2index[i] = ifix; } else if (which[i] == ArgInfo::VARIABLE) { @@ -254,7 +242,7 @@ void FixVector::end_of_step() // invoke compute if not previously invoked if (which[i] == ArgInfo::COMPUTE) { - Compute *compute = modify->compute[m]; + auto compute = modify->get_compute_by_index(m); if (argindex[i] == 0) { if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) { @@ -274,9 +262,9 @@ void FixVector::end_of_step() } else if (which[i] == ArgInfo::FIX) { if (argindex[i] == 0) - result[i] = modify->fix[m]->compute_scalar(); + result[i] = modify->get_fix_by_index(m)->compute_scalar(); else - result[i] = modify->fix[m]->compute_vector(argindex[i]-1); + result[i] = modify->get_fix_by_index(m)->compute_vector(argindex[i]-1); // evaluate equal-style or vector-style variable diff --git a/src/group.cpp b/src/group.cpp index 57c701a7fa..0dc0a560dd 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -105,8 +105,8 @@ void Group::assign(int narg, char **arg) int igroup = find(arg[0]); if (igroup == -1) error->all(FLERR,"Could not find group delete group ID"); if (igroup == 0) error->all(FLERR,"Cannot delete group all"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->igroup == igroup) + for (const auto &fix : modify->get_fix_list()) + if (fix->igroup == igroup) error->all(FLERR,"Cannot delete group currently used by a fix"); for (i = 0; i < modify->ncompute; i++) if (modify->compute[i]->igroup == igroup) diff --git a/src/info.cpp b/src/info.cpp index a726b2f00b..7e8dbd37b9 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -567,16 +567,13 @@ void Info::command(int narg, char **arg) } if (flags & COMPUTES) { - int ncompute = modify->ncompute; - Compute **compute = modify->compute; + int i = 0; char **names = group->names; fputs("\nCompute information:\n",out); - for (int i=0; i < ncompute; ++i) { - fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", - i, std::string(compute[i]->id)+',', - std::string(compute[i]->style)+',', - names[compute[i]->igroup]); - } + for (const auto &compute : modify->get_compute_list()) + fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", i++, + std::string(compute->id)+',',std::string(compute->style)+',', + names[compute->igroup]); } if (flags & DUMPS) { @@ -588,10 +585,8 @@ void Info::command(int narg, char **arg) fputs("\nDump information:\n",out); for (int i=0; i < ndump; ++i) { fmt::print(out,"Dump[{:3d}]: {:16} file = {:16} style = {:16} group = {:16} ", - i, std::string(dump[i]->id)+',', - std::string(dump[i]->filename)+',', - std::string(dump[i]->style)+',', - std::string(names[dump[i]->igroup])+','); + i, std::string(dump[i]->id)+',',std::string(dump[i]->filename)+',', + std::string(dump[i]->style)+',',std::string(names[dump[i]->igroup])+','); if (nevery[i]) { fmt::print(out,"every = {}\n", nevery[i]); } else { @@ -601,16 +596,12 @@ void Info::command(int narg, char **arg) } if (flags & FIXES) { - int nfix = modify->nfix; - Fix **fix = modify->fix; + int i = 0; char **names = group->names; fputs("\nFix information:\n",out); - for (int i=0; i < nfix; ++i) { - fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n", - i,std::string(fix[i]->id)+',', - std::string(fix[i]->style)+',', - names[fix[i]->igroup]); - } + for (const auto &fix : modify->get_fix_list()) + fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n",i++, + std::string(fix->id)+',',std::string(fix->style)+',',names[fix->igroup]); } if (flags & VARIABLES) { @@ -622,8 +613,7 @@ void Info::command(int narg, char **arg) for (int i=0; i < nvar; ++i) { int ndata = 1; fmt::print(out,"Variable[{:3d}]: {:16} style = {:16} def =", - i,std::string(names[i])+',', - std::string(varstyles[style[i]])+','); + i,std::string(names[i])+',',std::string(varstyles[style[i]])+','); if (style[i] == Variable::INTERNAL) { fmt::print(out,"{:.8}\n",input->variable->dvalue[i]); continue; @@ -798,13 +788,13 @@ bool Info::is_active(const char *category, const char *name) if (strcmp(category,"package") == 0) { if (strcmp(name,"gpu") == 0) { - return (modify->find_fix("package_gpu") >= 0) ? true : false; + return (modify->get_fix_by_id("package_gpu")) ? true : false; } else if (strcmp(name,"intel") == 0) { - return (modify->find_fix("package_intel") >= 0) ? true : false; + return (modify->get_fix_by_id("package_intel")) ? true : false; } else if (strcmp(name,"kokkos") == 0) { return (lmp->kokkos && lmp->kokkos->kokkos_exists) ? true : false; } else if (strcmp(name,"omp") == 0) { - return (modify->find_fix("package_omp") >= 0) ? true : false; + return (modify->get_fix_by_id("package_omp")) ? true : false; } else error->all(FLERR,"Unknown name for info package category: {}", name); } else if (strcmp(category,"newton") == 0) { @@ -917,10 +907,8 @@ bool Info::is_defined(const char *category, const char *name) return true; } } else if (strcmp(category,"fix") == 0) { - int nfix = modify->nfix; - Fix **fix = modify->fix; - for (int i=0; i < nfix; ++i) { - if (strcmp(fix[i]->id,name) == 0) + for (const auto &fix : modify->get_fix_list()) { + if (strcmp(fix->id,name) == 0) return true; } } else if (strcmp(category,"group") == 0) { @@ -1024,7 +1012,7 @@ static std::vector get_style_names(std::map std::vector names; names.reserve(styles->size()); - for (auto const& kv : *styles) { + for (auto const &kv : *styles) { // skip "secret" styles if (isupper(kv.first[0])) continue; names.push_back(kv.first); diff --git a/src/library.cpp b/src/library.cpp index ed208413e6..a27da0d478 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1689,9 +1689,8 @@ void *lammps_extract_compute(void *handle, const char *id, int style, int type) BEGIN_CAPTURE { - int icompute = lmp->modify->find_compute(id); - if (icompute < 0) return nullptr; - Compute *compute = lmp->modify->compute[icompute]; + auto compute = lmp->modify->get_compute_by_id(id); + if (!compute) return nullptr; if (style == LMP_STYLE_GLOBAL) { if (type == LMP_TYPE_SCALAR) { @@ -1876,9 +1875,8 @@ void *lammps_extract_fix(void *handle, const char *id, int style, int type, BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) return nullptr; - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) return nullptr; if (style == LMP_STYLE_GLOBAL) { if (type == LMP_TYPE_SCALAR) { @@ -2868,10 +2866,9 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) BEGIN_CAPTURE { #if defined(LAMMPS_BIGBIG) - lmp->error->all(FLERR,"Library function lammps_gather" - " not compatible with -DLAMMPS_BIGBIG"); + lmp->error->all(FLERR,"Library function lammps_gather not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,offset,fcid,ltype,icol; + int i,j,offset,ltype; // error if tags are not defined or not consecutive @@ -2892,76 +2889,72 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_gather: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) - lmp->error->all(FLERR,"lammps_gather:" - " fix not computed at compatible time"); + lmp->error->all(FLERR,"lammps_gather: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_gather: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown property/atom id"); return; @@ -2972,23 +2965,23 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom type"); return; } - if (count == 1 && icol != 0) { + if ((count == 1) && (icol != 0)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom count"); return; } - if (count > 1 && icol != count) { + if ((count > 1) && (icol != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3111,7 +3104,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d lmp->error->all(FLERR,"Library function lammps_gather_concat" " not compatible with -DLAMMPS_BIGBIG"); #else - int i,offset,fcid,ltype,icol; + int i,offset,ltype; // error if tags are not defined or not consecutive @@ -3131,70 +3124,71 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) lmp->error->all(FLERR,"lammps_gather_concat: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom per-atom vector or array if ((vptr==nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown property/atom id"); return; @@ -3205,23 +3199,23 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom type"); return; } - if (count == 1 && icol != 0) { + if ((count == 1) && (icol != 0)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } - if (count > 1 && icol != count) { + if ((count > 1) && (icol != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3364,7 +3358,7 @@ void lammps_gather_subset(void *handle, char *name, lmp->error->all(FLERR,"Library function lammps_gather_subset() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; tagint id; // error if tags are not defined or not consecutive @@ -3384,71 +3378,70 @@ void lammps_gather_subset(void *handle, char *name, if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather_subset: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) lmp->error->all(FLERR,"lammps_gather_subset: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown property/atom id"); return; @@ -3471,11 +3464,11 @@ void lammps_gather_subset(void *handle, char *name, } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3611,7 +3604,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) lmp->error->all(FLERR,"Library function lammps_scatter() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; // error if tags are not defined or not consecutive or no atom map // NOTE: test that name = image or ids is not a 64-bit int in code? @@ -3634,70 +3627,66 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_scatter: count != values peratom for fix"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_scatter: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown property/atom id"); return; @@ -3720,11 +3709,11 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3833,7 +3822,7 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, lmp->error->all(FLERR,"Library function lammps_scatter_subset() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; tagint id; // error if tags are not defined or no atom map @@ -3855,70 +3844,66 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter_subset: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_scatter_subset: count != values peratom for fix"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter_subset: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_scatter_subset: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown property/atom id"); return; @@ -3941,11 +3926,11 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -4242,10 +4227,9 @@ int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int n int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; - const int ifix = lmp->modify->find_fix(id); - if (ifix < 0) return -1; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) return -1; - Fix *fix = lmp->modify->fix[ifix]; // find neigh list for (int i = 0; i < lmp->neighbor->nlist; i++) { NeighList *list = lmp->neighbor->lists[i]; @@ -4272,10 +4256,9 @@ int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) { int lammps_find_compute_neighlist(void* handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; - const int icompute = lmp->modify->find_compute(id); - if (icompute < 0) return -1; + auto compute = lmp->modify->get_compute_by_id(id); + if (!compute) return -1; - Compute *compute = lmp->modify->compute[icompute]; // find neigh list for (int i = 0; i < lmp->neighbor->nlist; i++) { NeighList * list = lmp->neighbor->lists[i]; @@ -5089,11 +5072,8 @@ void lammps_set_fix_external_callback(void *handle, const char *id, FixExternalF BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Cannot find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Cannot find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style 'external'", id); @@ -5153,16 +5133,14 @@ double **lammps_fix_external_get_force(void *handle, const char *id) BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); - fexternal = (double **)fix->extract("fexternal",ifix); + int tmp; + fexternal = (double **)fix->extract("fexternal",tmp); } END_CAPTURE return fexternal; @@ -5202,11 +5180,8 @@ void lammps_fix_external_set_energy_global(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5253,11 +5228,8 @@ void lammps_fix_external_set_virial_global(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5304,11 +5276,8 @@ void lammps_fix_external_set_energy_peratom(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5358,11 +5327,8 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5405,11 +5371,8 @@ void lammps_fix_external_set_vector_length(void *handle, const char *id, int len BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5462,11 +5425,8 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); diff --git a/src/min.cpp b/src/min.cpp index 4780cf31eb..0c71607bd8 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -157,8 +157,7 @@ void Min::init() // detect if fix omp is present for clearing force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() @@ -230,9 +229,8 @@ void Min::setup(int flag) // compute for potential energy - int id = modify->find_compute("thermo_pe"); - if (id < 0) error->all(FLERR,"Minimization could not find thermo_pe compute"); - pe_compute = modify->compute[id]; + pe_compute = modify->get_compute_by_id("thermo_pe"); + if (!pe_compute) error->all(FLERR,"Minimization could not find thermo_pe compute"); // style-specific setup does two tasks // setup extra global dof vectors diff --git a/src/modify.cpp b/src/modify.cpp index 89a26025af..2f7abe27fa 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -807,9 +807,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // since some fixes access domain settings in their constructor // nullptr must be last entry in this list - const char *exceptions[] = - {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", - "deprecated", "STORE/KIM", nullptr}; + const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", + "deprecated", "STORE/KIM", nullptr}; if (domain->box_exist == 0) { int m; @@ -822,7 +821,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // check group ID int igroup = group->find(arg[1]); - if (igroup == -1) error->all(FLERR,"Could not find fix group ID"); + if (igroup == -1) error->all(FLERR,"Could not find fix group ID {}", arg[1]); // if fix ID exists: // set newflag = 0 so create new fix in same location in fix list @@ -856,8 +855,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (estyle == fix[ifix]->style) match = 1; } } - if (!match) - error->all(FLERR,"Replacing a fix, but new style != old style"); + if (!match) error->all(FLERR,"Replacing a fix, but new style != old style"); if (fix[ifix]->igroup != igroup && comm->me == 0) error->warning(FLERR,"Replacing a fix, but new group != old group"); @@ -907,9 +905,12 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (fix[ifix] == nullptr) error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp)); - // increment nfix (if new) + // increment nfix and update fix_list vector (if new) - if (newflag) nfix++; + if (newflag) { + nfix++; + fix_list = std::vector(fix, fix+nfix); + } // post_constructor() can call virtual methods in parent or child // which would otherwise not yet be visible in child class @@ -983,25 +984,24 @@ Fix *Modify::add_fix(const std::string &fixcmd, int trysuffix) Fix *Modify::replace_fix(const char *replaceID, int narg, char **arg, int trysuffix) { - int ifix = find_fix(replaceID); - if (ifix < 0) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID); + auto oldfix = get_fix_by_id(replaceID); + if (!oldfix) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID); // change ID, igroup, style of fix being replaced to match new fix // requires some error checking on arguments for new fix if (narg < 3) error->all(FLERR,"Illegal replace_fix invocation"); - int jfix = find_fix(arg[0]); - if (jfix >= 0) error->all(FLERR,"Replace_fix ID is already in use"); + if (get_fix_by_id(arg[0])) error->all(FLERR,"Replace_fix ID {} is already in use",arg[0]); - delete [] fix[ifix]->id; - fix[ifix]->id = utils::strdup(arg[0]); + delete[] oldfix->id; + oldfix->id = utils::strdup(arg[0]); int jgroup = group->find(arg[1]); - if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID"); - fix[ifix]->igroup = jgroup; + if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID {}", arg[1]); + oldfix->igroup = jgroup; - delete [] fix[ifix]->style; - fix[ifix]->style = utils::strdup(arg[2]); + delete[] oldfix->style; + oldfix->style = utils::strdup(arg[2]); // invoke add_fix // it will find and overwrite the replaceID fix @@ -1047,7 +1047,7 @@ void Modify::modify_fix(int narg, char **arg) int ifix; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(arg[0],fix[ifix]->id) == 0) break; - if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID"); + if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID {}", arg[0]); fix[ifix]->modify_params(narg-1,&arg[1]); } @@ -1060,7 +1060,7 @@ void Modify::modify_fix(int narg, char **arg) void Modify::delete_fix(const std::string &id) { int ifix = find_fix(id); - if (ifix < 0) error->all(FLERR,"Could not find fix ID to delete"); + if (ifix < 0) error->all(FLERR,"Could not find fix ID {} to delete", id); delete_fix(ifix); } @@ -1076,6 +1076,7 @@ void Modify::delete_fix(int ifix) for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i]; for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i]; nfix--; + fix_list = std::vector(fix, fix+nfix); } /* ---------------------------------------------------------------------- @@ -1092,15 +1093,42 @@ int Modify::find_fix(const std::string &id) } /* ---------------------------------------------------------------------- - find a fix by style - return index of fix or -1 if not found + look up pointer to Fix class by fix-ID + return null pointer if ID not found ------------------------------------------------------------------------- */ -int Modify::find_fix_by_style(const char *style) +Fix *Modify::get_fix_by_id(const std::string &id) const { + if (id.empty()) return nullptr; for (int ifix = 0; ifix < nfix; ifix++) - if (utils::strmatch(fix[ifix]->style,style)) return ifix; - return -1; + if (id == fix[ifix]->id) return fix[ifix]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointer to fixes by fix style name + return vector of matching pointers +------------------------------------------------------------------------- */ + +const std::vector Modify::get_fix_by_style(const std::string &style) const +{ + std::vector matches; + if (style.empty()) return matches; + + for (int ifix = 0; ifix < nfix; ifix++) + if (utils::strmatch(fix[ifix]->style,style)) matches.push_back(fix[ifix]); + + return matches; +} + +/* ---------------------------------------------------------------------- + return list of fixes as vector +------------------------------------------------------------------------- */ + +const std::vector &Modify::get_fix_list() +{ + fix_list = std::vector(fix, fix+nfix); + return fix_list; } /* ---------------------------------------------------------------------- @@ -1225,8 +1253,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) if (ncompute == maxcompute) { maxcompute += DELTA; - compute = (Compute **) - memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); + compute = (Compute **) memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); } // create the Compute @@ -1264,6 +1291,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) if (compute[ncompute] == nullptr) error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp)); + compute_list = std::vector(compute, compute+ncompute+1); return compute[ncompute++]; } @@ -1307,7 +1335,7 @@ void Modify::modify_compute(int narg, char **arg) for (icompute = 0; icompute < ncompute; icompute++) if (strcmp(arg[0],compute[icompute]->id) == 0) break; if (icompute == ncompute) - error->all(FLERR,"Could not find compute_modify ID"); + error->all(FLERR,"Could not find compute_modify ID {}", arg[0]); compute[icompute]->modify_params(narg-1,&arg[1]); } @@ -1319,7 +1347,7 @@ void Modify::modify_compute(int narg, char **arg) void Modify::delete_compute(const std::string &id) { int icompute = find_compute(id); - if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete"); + if (icompute < 0) error->all(FLERR,"Could not find compute ID {} to delete", id); delete_compute(icompute); } @@ -1332,6 +1360,7 @@ void Modify::delete_compute(int icompute) delete compute[icompute]; for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i]; ncompute--; + compute_list = std::vector(compute, compute+ncompute); } /* ---------------------------------------------------------------------- @@ -1348,15 +1377,42 @@ int Modify::find_compute(const std::string &id) } /* ---------------------------------------------------------------------- - find a compute by style - return index of compute or -1 if not found + look up pointer to Compute class by compute-ID + return null pointer if ID not found ------------------------------------------------------------------------- */ -int Modify::find_compute_by_style(const char *style) +Compute *Modify::get_compute_by_id(const std::string &id) const { + if (id.empty()) return nullptr; for (int icompute = 0; icompute < ncompute; icompute++) - if (utils::strmatch(compute[icompute]->style,style)) return icompute; - return -1; + if (id == compute[icompute]->id) return compute[icompute]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointers to computes by compute style name + return vector with matching pointers +------------------------------------------------------------------------- */ + +const std::vector Modify::get_compute_by_style(const std::string &style) const +{ + std::vector matches; + if (style.empty()) return matches; + + for (int icompute = 0; icompute < ncompute; icompute++) + if (utils::strmatch(compute[icompute]->style,style)) matches.push_back(compute[icompute]); + + return matches; +} + +/* ---------------------------------------------------------------------- + return vector with Computes +------------------------------------------------------------------------- */ + +const std::vector &Modify::get_compute_list() +{ + compute_list = std::vector(compute, compute+ncompute); + return compute_list; } /* ---------------------------------------------------------------------- diff --git a/src/modify.h b/src/modify.h index 9446f285e7..c4f8c2ef02 100644 --- a/src/modify.h +++ b/src/modify.h @@ -17,6 +17,7 @@ #include "pointers.h" #include +#include namespace LAMMPS_NS { @@ -107,16 +108,28 @@ class Modify : protected Pointers { void modify_fix(int, char **); void delete_fix(const std::string &); void delete_fix(int); + + // deprecated API int find_fix(const std::string &); - int find_fix_by_style(const char *); + // new API + Fix *get_fix_by_id(const std::string &) const; + Fix *get_fix_by_index(int idx) const { return fix[idx]; } + const std::vector get_fix_by_style(const std::string &) const; + const std::vector &get_fix_list(); Compute *add_compute(int, char **, int trysuffix = 1); Compute *add_compute(const std::string &, int trysuffix = 1); void modify_compute(int, char **); void delete_compute(const std::string &); void delete_compute(int); + + // deprecated API int find_compute(const std::string &); - int find_compute_by_style(const char *); + // new API + Compute *get_compute_by_id(const std::string &) const; + Compute *get_compute_by_index(int idx) const { return compute[idx]; } + const std::vector get_compute_by_style(const std::string &) const; + const std::vector &get_compute_list(); void clearstep_compute(); void addstep_compute(bigint); @@ -165,6 +178,10 @@ class Modify : protected Pointers { int index_permanent; // fix/compute index returned to library call + // vectors to be used for new-API accessors as wrapper + std::vectorfix_list; + std::vectorcompute_list; + void list_init(int, int &, int *&); void list_init_end_of_step(int, int &, int *&); void list_init_energy_couple(int &, int *&); diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 0eab44baaa..f8ac14534b 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -445,8 +445,7 @@ void ReadRestart::command(int narg, char **arg) if (nextra) { memory->destroy(atom->extra); memory->create(atom->extra,atom->nmax,nextra,"atom:extra"); - int ifix = modify->find_fix("_read_restart"); - FixReadRestart *fix = (FixReadRestart *) modify->fix[ifix]; + auto fix = (FixReadRestart *) modify->get_fix_by_id("_read_restart"); int *count = fix->count; double **extra = fix->extra; double **atom_extra = atom->extra; diff --git a/src/reset_mol_ids.cpp b/src/reset_mol_ids.cpp index 4c973f543f..a29ea98e18 100644 --- a/src/reset_mol_ids.cpp +++ b/src/reset_mol_ids.cpp @@ -151,24 +151,14 @@ void ResetMolIDs::create_computes(char *fixid, char *groupid) // 'fixid' allows for creating independent instances of the computes idfrag = fmt::format("{}_reset_mol_ids_FRAGMENT_ATOM",fixid); - if (singleflag) - modify->add_compute(fmt::format("{} {} fragment/atom single yes",idfrag,groupid)); - else - modify->add_compute(fmt::format("{} {} fragment/atom single no",idfrag,groupid)); + auto use_single = singleflag ? "yes" : "no"; + cfa = (ComputeFragmentAtom *) + modify->add_compute(fmt::format("{} {} fragment/atom single {}",idfrag,groupid,use_single)); idchunk = fmt::format("{}_reset_mol_ids_CHUNK_ATOM",fixid); if (compressflag) - modify->add_compute(fmt::format("{} {} chunk/atom molecule compress yes", - idchunk,groupid)); - - int icompute = modify->find_compute(idfrag); - cfa = (ComputeFragmentAtom *) modify->compute[icompute]; - - - if (compressflag) { - icompute = modify->find_compute(idchunk); - cca = (ComputeChunkAtom *) modify->compute[icompute]; - } + cca = (ComputeChunkAtom *) + modify->add_compute(fmt::format("{} {} chunk/atom molecule compress yes",idchunk,groupid)); } /* ---------------------------------------------------------------------- diff --git a/src/respa.cpp b/src/respa.cpp index 5190441994..9690105d40 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -46,23 +45,22 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : - Integrate(lmp, narg, arg), - step(nullptr), loop(nullptr), hybrid_level(nullptr), hybrid_compute(nullptr), - newton(nullptr), fix_respa(nullptr) + Integrate(lmp, narg, arg), step(nullptr), loop(nullptr), hybrid_level(nullptr), + hybrid_compute(nullptr), newton(nullptr), fix_respa(nullptr) { nhybrid_styles = 0; - if (narg < 1) error->all(FLERR,"Illegal run_style respa command"); + if (narg < 1) error->all(FLERR, "Illegal run_style respa command"); - nlevels = utils::inumeric(FLERR,arg[0],false,lmp); - if (nlevels < 1) error->all(FLERR,"Respa levels must be >= 1"); + nlevels = utils::inumeric(FLERR, arg[0], false, lmp); + if (nlevels < 1) error->all(FLERR, "Respa levels must be >= 1"); - if (narg < nlevels) error->all(FLERR,"Illegal run_style respa command"); + if (narg < nlevels) error->all(FLERR, "Illegal run_style respa command"); loop = new int[nlevels]; for (int iarg = 1; iarg < nlevels; iarg++) { - loop[iarg-1] = utils::inumeric(FLERR,arg[iarg],false,lmp); - if (loop[iarg-1] <= 0) error->all(FLERR,"Illegal run_style respa command"); + loop[iarg - 1] = utils::inumeric(FLERR, arg[iarg], false, lmp); + if (loop[iarg - 1] <= 0) error->all(FLERR, "Illegal run_style respa command"); } - loop[nlevels-1] = 1; + loop[nlevels - 1] = 1; // set level at which each force is computed // argument settings override defaults @@ -79,87 +77,86 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : int iarg = nlevels; while (iarg < narg) { - if (strcmp(arg[iarg],"bond") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_bond = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + if (strcmp(arg[iarg], "bond") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_bond = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"angle") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_angle = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "angle") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_angle = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"dihedral") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_dihedral = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "dihedral") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_dihedral = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"improper") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_improper = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "improper") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_improper = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"pair") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_pair = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "pair") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_pair = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"inner") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_inner = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - cutoff[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - cutoff[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "inner") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_inner = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + cutoff[0] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + cutoff[1] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"middle") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_middle = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - cutoff[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - cutoff[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "middle") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_middle = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + cutoff[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + cutoff[3] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"outer") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_outer = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "outer") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_outer = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"kspace") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_kspace = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "kspace") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_kspace = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"hybrid") == 0) { + } else if (strcmp(arg[iarg], "hybrid") == 0) { // the hybrid keyword requires a hybrid pair style - if (!utils::strmatch(force->pair_style,"^hybrid")) - error->all(FLERR,"Illegal run_style respa command"); + if (!utils::strmatch(force->pair_style, "^hybrid")) + error->all(FLERR, "Illegal run_style respa command"); PairHybrid *hybrid = (PairHybrid *) force->pair; nhybrid_styles = hybrid->nstyles; // each hybrid sub-style needs to be assigned to a respa level - if (iarg+nhybrid_styles > narg) - error->all(FLERR,"Illegal run_style respa command"); + if (iarg + nhybrid_styles > narg) error->all(FLERR, "Illegal run_style respa command"); hybrid_level = new int[nhybrid_styles]; hybrid_compute = new int[nhybrid_styles]; - for (int i=0; i < nhybrid_styles; ++i) { + for (int i = 0; i < nhybrid_styles; ++i) { ++iarg; - hybrid_level[i] = utils::inumeric(FLERR,arg[iarg],false,lmp)-1; + hybrid_level[i] = utils::inumeric(FLERR, arg[iarg], false, lmp) - 1; } ++iarg; - } else error->all(FLERR,"Illegal run_style respa command"); + } else + error->all(FLERR, "Illegal run_style respa command"); } // cannot specify both pair and inner/middle/outer - if (level_pair >= 0 && - (level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) - error->all(FLERR,"Cannot set both respa pair and inner/middle/outer"); + if (level_pair >= 0 && (level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) + error->all(FLERR, "Cannot set both respa pair and inner/middle/outer"); // if either inner and outer is specified, then both must be - if ((level_inner >= 0 && level_outer == -1) || - (level_outer >= 0 && level_inner == -1)) - error->all(FLERR,"Must set both respa inner and outer"); + if ((level_inner >= 0 && level_outer == -1) || (level_outer >= 0 && level_inner == -1)) + error->all(FLERR, "Must set both respa inner and outer"); // middle cannot be set without inner/outer if (level_middle >= 0 && level_inner == -1) - error->all(FLERR,"Cannot set respa middle without inner/outer"); + error->all(FLERR, "Cannot set respa middle without inner/outer"); // cannot combine hybrid with any of pair/inner/middle/outer - if ((nhybrid_styles > 0) && (level_pair >= 0 || level_inner >= 0 - || level_middle >= 0 || level_outer >= 0)) - error->all(FLERR,"Cannot set respa hybrid and " + if ((nhybrid_styles > 0) && + (level_pair >= 0 || level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) + error->all(FLERR, + "Cannot set respa hybrid and " "any of pair/inner/middle/outer"); // set defaults if user did not specify level @@ -174,8 +171,7 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : if (level_dihedral == -1) level_dihedral = level_angle; if (level_improper == -1) level_improper = level_dihedral; - if (level_pair == -1 && level_inner == -1 && nhybrid_styles < 1) - level_pair = nlevels-1; + if (level_pair == -1 && level_inner == -1 && nhybrid_styles < 1) level_pair = nlevels - 1; if (level_kspace == -1 && level_pair >= 0) level_kspace = level_pair; if (level_kspace == -1 && level_pair == -1) { @@ -183,9 +179,8 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : level_kspace = level_outer; } else { int max_hybrid_level = -1; - for (int i=0; i < nhybrid_styles; ++i) { - if (max_hybrid_level < hybrid_level[i]) - max_hybrid_level = hybrid_level[i]; + for (int i = 0; i < nhybrid_styles; ++i) { + if (max_hybrid_level < hybrid_level[i]) max_hybrid_level = hybrid_level[i]; } level_kspace = max_hybrid_level; } @@ -196,59 +191,57 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : if (comm->me == 0) { std::string mesg = "Respa levels:\n"; for (int i = 0; i < nlevels; i++) { - mesg += fmt::format(" {} =",i+1); - if (level_bond == i) mesg += " bond"; - if (level_angle == i) mesg += " angle"; - if (level_dihedral == i) mesg += " dihedral"; - if (level_improper == i) mesg += " improper"; - if (level_pair == i) mesg += " pair"; - if (level_inner == i) mesg += " pair-inner"; - if (level_middle == i) mesg += " pair-middle"; - if (level_outer == i) mesg += " pair-outer"; - for (int j=0; j < nhybrid_styles; j++) - if (hybrid_level[j] == i) mesg += fmt::format(" hybrid-{}",j+1); - if (level_kspace == i) mesg += " kspace"; + mesg += fmt::format(" {} =", i + 1); + if (level_bond == i) mesg += " bond"; + if (level_angle == i) mesg += " angle"; + if (level_dihedral == i) mesg += " dihedral"; + if (level_improper == i) mesg += " improper"; + if (level_pair == i) mesg += " pair"; + if (level_inner == i) mesg += " pair-inner"; + if (level_middle == i) mesg += " pair-middle"; + if (level_outer == i) mesg += " pair-outer"; + for (int j = 0; j < nhybrid_styles; j++) + if (hybrid_level[j] == i) mesg += fmt::format(" hybrid-{}", j + 1); + if (level_kspace == i) mesg += " kspace"; mesg += "\n"; } - utils::logmesg(lmp,mesg); + utils::logmesg(lmp, mesg); } // check that levels are in correct order - if (level_angle < level_bond || level_dihedral < level_angle || - level_improper < level_dihedral) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_angle < level_bond || level_dihedral < level_angle || level_improper < level_dihedral) + error->all(FLERR, "Invalid order of forces within respa levels"); if (level_pair >= 0) { if (level_pair < level_improper || level_kspace < level_pair) - error->all(FLERR,"Invalid order of forces within respa levels"); + error->all(FLERR, "Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle == -1 && nhybrid_styles < 1) { - if (level_inner < level_improper || level_outer < level_inner || - level_kspace < level_outer) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_inner < level_improper || level_outer < level_inner || level_kspace < level_outer) + error->all(FLERR, "Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle >= 0) { - if (level_inner < level_improper || level_middle < level_inner || - level_outer < level_inner || level_kspace < level_outer) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_inner < level_improper || level_middle < level_inner || level_outer < level_inner || + level_kspace < level_outer) + error->all(FLERR, "Invalid order of forces within respa levels"); } // warn if any levels are devoid of forces int flag = 0; for (int i = 0; i < nlevels; i++) - if (level_bond != i && level_angle != i && level_dihedral != i && - level_improper != i && level_pair != i && level_inner != i && - level_middle != i && level_outer != i && level_kspace != i) flag = 1; - if (flag && comm->me == 0) - error->warning(FLERR,"One or more respa levels compute no forces"); + if (level_bond != i && level_angle != i && level_dihedral != i && level_improper != i && + level_pair != i && level_inner != i && level_middle != i && level_outer != i && + level_kspace != i) + flag = 1; + if (flag && comm->me == 0) error->warning(FLERR, "One or more respa levels compute no forces"); // check cutoff consistency if inner/middle/outer are enabled if (level_inner >= 0 && cutoff[1] < cutoff[0]) - error->all(FLERR,"Respa inner cutoffs are invalid"); + error->all(FLERR, "Respa inner cutoffs are invalid"); if (level_middle >= 0 && (cutoff[3] < cutoff[2] || cutoff[2] < cutoff[1])) - error->all(FLERR,"Respa middle cutoffs are invalid"); + error->all(FLERR, "Respa middle cutoffs are invalid"); // set outer pair of cutoffs to inner pair if middle is not enabled @@ -275,12 +268,12 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : Respa::~Respa() { - delete [] loop; - delete [] newton; - delete [] step; + delete[] loop; + delete[] newton; + delete[] step; if (nhybrid_styles > 0) { - delete [] hybrid_level; - delete [] hybrid_compute; + delete[] hybrid_level; + delete[] hybrid_compute; } } @@ -295,13 +288,13 @@ void Respa::init() // warn if no fixes if (modify->nfix == 0 && comm->me == 0) - error->warning(FLERR,"No fixes defined, atoms won't move"); + error->warning(FLERR, "No fixes defined, atoms won't move"); // create fix needed for storing atom-based respa level forces // will delete it at end of run // if supported, we also store torques on a per-level basis - std::string cmd = fmt::format("RESPA all RESPA {}",nlevels); + std::string cmd = fmt::format("RESPA all RESPA {}", nlevels); if (atom->torque_flag) cmd += " torque"; fix_respa = (FixRespa *) modify->add_fix(cmd); @@ -309,7 +302,7 @@ void Respa::init() if (level_inner >= 0) if (force->pair && force->pair->respa_enable == 0) - error->all(FLERR,"Pair style does not support rRESPA inner/middle/outer"); + error->all(FLERR, "Pair style does not support rRESPA inner/middle/outer"); // virial_style = VIRIAL_PAIR (explicit) // since never computed implicitly with virial_fdotr_compute() like Verlet @@ -322,8 +315,7 @@ void Respa::init() // detect if fix omp is present and will clear force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() @@ -333,22 +325,22 @@ void Respa::init() // step[] = timestep for each level - step[nlevels-1] = update->dt; - for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) - step[ilevel] = step[ilevel+1]/loop[ilevel]; + step[nlevels - 1] = update->dt; + for (int ilevel = nlevels - 2; ilevel >= 0; ilevel--) + step[ilevel] = step[ilevel + 1] / loop[ilevel]; // set newton flag for each level for (int ilevel = 0; ilevel < nlevels; ilevel++) { newton[ilevel] = 0; if (force->newton_bond) { - if (level_bond == ilevel || level_angle == ilevel || - level_dihedral == ilevel || level_improper == ilevel) + if (level_bond == ilevel || level_angle == ilevel || level_dihedral == ilevel || + level_improper == ilevel) newton[ilevel] = 1; } if (force->newton_pair) { - if (level_pair == ilevel || level_inner == ilevel || - level_middle == ilevel || level_outer == ilevel) + if (level_pair == ilevel || level_inner == ilevel || level_middle == ilevel || + level_outer == ilevel) newton[ilevel] = 1; if (nhybrid_styles > 0) { @@ -372,23 +364,21 @@ void Respa::setup(int flag) if (comm->me == 0 && screen) { std::string mesg = "Setting up r-RESPA run ...\n"; if (flag) { - mesg += fmt::format(" Unit style : {}\n",update->unit_style); + mesg += fmt::format(" Unit style : {}\n", update->unit_style); mesg += fmt::format(" Current step : {}\n", update->ntimestep); mesg += " Time steps :"; - for (int ilevel=0; ilevel < nlevels; ++ilevel) - mesg += fmt::format(" {}:{}",ilevel+1, step[ilevel]); + for (int ilevel = 0; ilevel < nlevels; ++ilevel) + mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); mesg += "\n r-RESPA fixes :"; - for (int l=0; l < modify->n_post_force_respa; ++l) { - Fix *f = modify->fix[modify->list_post_force_respa[l]]; + for (int l = 0; l < modify->n_post_force_respa; ++l) { + Fix *f = modify->get_fix_by_index(modify->list_post_force_respa[l]); if (f->respa_level >= 0) - mesg += fmt::format(" {}:{}[{}]", - MIN(f->respa_level+1,nlevels), - f->style,f->id); + mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); } mesg += "\n"; - fputs(mesg.c_str(),screen); + fputs(mesg.c_str(), screen); timer->print_timeout(screen); } } @@ -409,7 +399,7 @@ void Respa::setup(int flag) comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); @@ -424,34 +414,26 @@ void Respa::setup(int flag) for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); - modify->setup_pre_force_respa(vflag,ilevel); + modify->setup_pre_force_respa(vflag, ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); } - if (level_pair == ilevel && pair_compute_flag) - force->pair->compute(eflag,vflag); - if (level_inner == ilevel && pair_compute_flag) - force->pair->compute_inner(); - if (level_middle == ilevel && pair_compute_flag) - force->pair->compute_middle(); - if (level_outer == ilevel && pair_compute_flag) - force->pair->compute_outer(eflag,vflag); - if (level_bond == ilevel && force->bond) - force->bond->compute(eflag,vflag); - if (level_angle == ilevel && force->angle) - force->angle->compute(eflag,vflag); - if (level_dihedral == ilevel && force->dihedral) - force->dihedral->compute(eflag,vflag); - if (level_improper == ilevel && force->improper) - force->improper->compute(eflag,vflag); + if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag, vflag); + if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); + if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); + if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag, vflag); + if (level_bond == ilevel && force->bond) force->bond->compute(eflag, vflag); + if (level_angle == ilevel && force->angle) force->angle->compute(eflag, vflag); + if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag, vflag); + if (level_improper == ilevel && force->improper) force->improper->compute(eflag, vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); - if (kspace_compute_flag) force->kspace->compute(eflag,vflag); + if (kspace_compute_flag) force->kspace->compute(eflag, vflag); } - modify->setup_pre_reverse(eflag,vflag); + modify->setup_pre_reverse(eflag, vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } @@ -485,7 +467,7 @@ void Respa::setup_minimal(int flag) if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); @@ -500,35 +482,27 @@ void Respa::setup_minimal(int flag) for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); - modify->setup_pre_force_respa(vflag,ilevel); + modify->setup_pre_force_respa(vflag, ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); } - if (level_pair == ilevel && pair_compute_flag) - force->pair->compute(eflag,vflag); - if (level_inner == ilevel && pair_compute_flag) - force->pair->compute_inner(); - if (level_middle == ilevel && pair_compute_flag) - force->pair->compute_middle(); - if (level_outer == ilevel && pair_compute_flag) - force->pair->compute_outer(eflag,vflag); - if (level_bond == ilevel && force->bond) - force->bond->compute(eflag,vflag); - if (level_angle == ilevel && force->angle) - force->angle->compute(eflag,vflag); - if (level_dihedral == ilevel && force->dihedral) - force->dihedral->compute(eflag,vflag); - if (level_improper == ilevel && force->improper) - force->improper->compute(eflag,vflag); + if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag, vflag); + if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); + if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); + if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag, vflag); + if (level_bond == ilevel && force->bond) force->bond->compute(eflag, vflag); + if (level_angle == ilevel && force->angle) force->angle->compute(eflag, vflag); + if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag, vflag); + if (level_improper == ilevel && force->improper) force->improper->compute(eflag, vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); - if (kspace_compute_flag) force->kspace->compute(eflag,vflag); + if (kspace_compute_flag) force->kspace->compute(eflag, vflag); } - modify->setup_pre_reverse(eflag,vflag); + modify->setup_pre_reverse(eflag, vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } @@ -555,7 +529,7 @@ void Respa::run(int n) ntimestep = ++update->ntimestep; ev_set(ntimestep); - recurse(nlevels-1); + recurse(nlevels - 1); // needed in case end_of_step() or output() use total force @@ -591,9 +565,9 @@ void Respa::cleanup() void Respa::reset_dt() { - step[nlevels-1] = update->dt; - for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) - step[ilevel] = step[ilevel+1]/loop[ilevel]; + step[nlevels - 1] = update->dt; + for (int ilevel = nlevels - 2; ilevel >= 0; ilevel--) + step[ilevel] = step[ilevel + 1] / loop[ilevel]; } /* ---------------------------------------------------------------------- */ @@ -605,16 +579,15 @@ void Respa::recurse(int ilevel) for (int iloop = 0; iloop < loop[ilevel]; iloop++) { timer->stamp(); - modify->initial_integrate_respa(vflag,ilevel,iloop); - if (modify->n_post_integrate_respa) - modify->post_integrate_respa(ilevel,iloop); + modify->initial_integrate_respa(vflag, ilevel, iloop); + if (modify->n_post_integrate_respa) modify->post_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); // at outermost level, check on rebuilding neighbor list // at innermost level, communicate // at middle levels, do nothing - if (ilevel == nlevels-1) { + if (ilevel == nlevels - 1) { int nflag = neighbor->decide(); if (nflag) { if (modify->n_pre_exchange) { @@ -631,10 +604,9 @@ void Respa::recurse(int ilevel) } timer->stamp(); comm->exchange(); - if (atom->sortfreq > 0 && - update->ntimestep >= atom->nextsort) atom->sort(); + if (atom->sortfreq > 0 && update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); timer->stamp(Timer::COMM); if (modify->n_pre_neighbor) { modify->pre_neighbor(); @@ -665,7 +637,7 @@ void Respa::recurse(int ilevel) // b/c atoms migrated to new procs between short/long force calls // now they migrate at very start of rRESPA timestep, before all forces - if (ilevel) recurse(ilevel-1); + if (ilevel) recurse(ilevel - 1); // force computations // important that ordering is same as Verlet @@ -675,18 +647,18 @@ void Respa::recurse(int ilevel) force_clear(newton[ilevel]); if (modify->n_pre_force_respa) { timer->stamp(); - modify->pre_force_respa(vflag,ilevel,iloop); + modify->pre_force_respa(vflag, ilevel, iloop); timer->stamp(Timer::MODIFY); } timer->stamp(); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_pair == ilevel && pair_compute_flag) { - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_inner == ilevel && pair_compute_flag) { @@ -698,32 +670,32 @@ void Respa::recurse(int ilevel) timer->stamp(Timer::PAIR); } if (level_outer == ilevel && pair_compute_flag) { - force->pair->compute_outer(eflag,vflag); + force->pair->compute_outer(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_bond == ilevel && force->bond) { - force->bond->compute(eflag,vflag); + force->bond->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_angle == ilevel && force->angle) { - force->angle->compute(eflag,vflag); + force->angle->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_dihedral == ilevel && force->dihedral) { - force->dihedral->compute(eflag,vflag); + force->dihedral->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_improper == ilevel && force->improper) { - force->improper->compute(eflag,vflag); + force->improper->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_kspace == ilevel && kspace_compute_flag) { - force->kspace->compute(eflag,vflag); + force->kspace->compute(eflag, vflag); timer->stamp(Timer::KSPACE); } if (modify->n_pre_reverse) { - modify->pre_reverse(eflag,vflag); + modify->pre_reverse(eflag, vflag); timer->stamp(Timer::MODIFY); } @@ -732,9 +704,8 @@ void Respa::recurse(int ilevel) timer->stamp(Timer::COMM); } timer->stamp(); - if (modify->n_post_force_respa) - modify->post_force_respa(vflag,ilevel,iloop); - modify->final_integrate_respa(ilevel,iloop); + if (modify->n_post_force_respa) modify->post_force_respa(vflag, ilevel, iloop); + modify->final_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); } @@ -757,9 +728,9 @@ void Respa::force_clear(int /*newtonflag*/) if (force->newton) nbytes += sizeof(double) * atom->nghost; if (nbytes) { - memset(&atom->f[0][0],0,3*nbytes); - if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); - if (extraflag) atom->avec->force_clear(0,nbytes); + memset(&atom->f[0][0], 0, 3 * nbytes); + if (torqueflag) memset(&atom->torque[0][0], 0, 3 * nbytes); + if (extraflag) atom->avec->force_clear(0, nbytes); } } @@ -849,9 +820,9 @@ void Respa::set_compute_flags(int ilevel) if (nhybrid_styles < 1) return; pair_compute = 0; - for (int i=0; infix; ifix++) - if (modify->fix[ifix]->special_alter_flag) - modify->fix[ifix]->rebuild_special(); + for (const auto &ifix : modify->get_fix_list()) + if (ifix->special_alter_flag) ifix->rebuild_special(); } /* ---------------------------------------------------------------------- diff --git a/src/thermo.cpp b/src/thermo.cpp index 434012870b..e39d7d7c57 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -267,23 +267,20 @@ void Thermo::init() // find current ptr for each Compute ID - int icompute; for (i = 0; i < ncompute; i++) { - icompute = modify->find_compute(id_compute[i]); - if (icompute < 0) error->all(FLERR,"Could not find thermo compute ID"); - computes[i] = modify->compute[icompute]; + computes[i] = modify->get_compute_by_id(id_compute[i]); + if (!computes[i]) error->all(FLERR,"Could not find thermo compute with ID {}",id_compute[i]); } // find current ptr for each Fix ID // check that fix frequency is acceptable with thermo output frequency - int ifix; for (i = 0; i < nfix; i++) { - ifix = modify->find_fix(id_fix[i]); - if (ifix < 0) error->all(FLERR,"Could not find thermo fix ID"); - fixes[i] = modify->fix[ifix]; + fixes[i] = modify->get_fix_by_id(id_fix[i]); + if (!fixes[i]) error->all(FLERR,"Could not find thermo fix ID {}",id_fix[i]); + if (output->thermo_every % fixes[i]->global_freq) - error->all(FLERR,"Thermo and fix not computed at compatible times"); + error->all(FLERR,"Thermo and fix {} not computed at compatible times",id_fix[i]); } // find current ptr for each Variable ID @@ -467,36 +464,33 @@ void Thermo::modify_params(int narg, char **arg) if (strcmp(arg[iarg],"temp") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); if (index_temp < 0) error->all(FLERR,"Thermo style does not use temp"); - delete [] id_compute[index_temp]; + delete[] id_compute[index_temp]; id_compute[index_temp] = utils::strdup(arg[iarg+1]); - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) - error->all(FLERR,"Could not find thermo_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(arg[iarg+1]); + if (!temperature) + error->all(FLERR,"Could not find thermo_modify temperature compute {}",arg[iarg+1]); if (temperature->tempflag == 0) - error->all(FLERR,"Thermo_modify temperature ID does not " - "compute temperature"); + error->all(FLERR,"Thermo_modify compute {} does not compute temperature",arg[iarg+1]); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR, - "Temperature for thermo pressure is not for group all"); + error->warning(FLERR,"Temperature for thermo pressure is not for group all"); // reset id_temp of pressure to new temperature ID // either pressure currently being used by thermo or "thermo_press" + Compute *pcompute; if (index_press_scalar >= 0) { - icompute = modify->find_compute(id_compute[index_press_scalar]); - if (icompute < 0) error->all(FLERR, - "Pressure ID for thermo does not exist"); + pcompute = modify->get_compute_by_id(id_compute[index_press_scalar]); + if (!pcompute) error->all(FLERR, "Pressure compute {} for thermo output does not exist", + id_compute[index_press_scalar]); } else if (index_press_vector >= 0) { - icompute = modify->find_compute(id_compute[index_press_vector]); - if (icompute < 0) error->all(FLERR, - "Pressure ID for thermo does not exist"); - } else icompute = modify->find_compute("thermo_press"); - - modify->compute[icompute]->reset_extra_compute_fix(arg[iarg+1]); + pcompute = modify->get_compute_by_id(id_compute[index_press_vector]); + if (!pcompute) error->all(FLERR,"Pressure compute {} for thermo output does not exist", + id_compute[index_press_vector]); + } else pcompute = modify->get_compute_by_id("thermo_press"); + pcompute->reset_extra_compute_fix(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"press") == 0) { @@ -513,13 +507,12 @@ void Thermo::modify_params(int narg, char **arg) id_compute[index_press_vector] = utils::strdup(arg[iarg+1]); } - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) error->all(FLERR, - "Could not find thermo_modify pressure ID"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(arg[iarg+1]); + if (!pressure) + error->all(FLERR,"Could not find thermo_modify pressure compute {}",arg[iarg+1]); if (pressure->pressflag == 0) - error->all(FLERR,"Thermo_modify pressure ID does not compute pressure"); + error->all(FLERR,"Thermo_modify compute {} does not compute pressure",arg[iarg+1]); iarg += 2; @@ -912,24 +905,24 @@ void Thermo::parse_fields(char *str) argindex2[nfield] = (argi.get_dim() > 1) ? argi.get_index2() : 0; if (argi.get_type() == ArgInfo::COMPUTE) { - int n = modify->find_compute(argi.get_name()); - if (n < 0) error->all(FLERR,"Could not find thermo custom compute ID"); - if (argindex1[nfield] == 0 && modify->compute[n]->scalar_flag == 0) + auto icompute = modify->get_compute_by_id(argi.get_name()); + if (!icompute) error->all(FLERR,"Could not find thermo custom compute ID"); + if (argindex1[nfield] == 0 && icompute->scalar_flag == 0) error->all(FLERR,"Thermo compute does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { - if (modify->compute[n]->vector_flag == 0) + if (icompute->vector_flag == 0) error->all(FLERR,"Thermo compute does not compute vector"); - if (argindex1[nfield] > modify->compute[n]->size_vector && - modify->compute[n]->size_vector_variable == 0) + if (argindex1[nfield] > icompute->size_vector && + icompute->size_vector_variable == 0) error->all(FLERR,"Thermo compute vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (modify->compute[n]->array_flag == 0) + if (icompute->array_flag == 0) error->all(FLERR,"Thermo compute does not compute array"); - if (argindex1[nfield] > modify->compute[n]->size_array_rows && - modify->compute[n]->size_array_rows_variable == 0) + if (argindex1[nfield] > icompute->size_array_rows && + icompute->size_array_rows_variable == 0) error->all(FLERR,"Thermo compute array is accessed out-of-range"); - if (argindex2[nfield] > modify->compute[n]->size_array_cols) + if (argindex2[nfield] > icompute->size_array_cols) error->all(FLERR,"Thermo compute array is accessed out-of-range"); } @@ -942,24 +935,24 @@ void Thermo::parse_fields(char *str) addfield(word.c_str(), &Thermo::compute_compute, FLOAT); } else if (argi.get_type() == ArgInfo::FIX) { - int n = modify->find_fix(argi.get_name()); - if (n < 0) error->all(FLERR,"Could not find thermo custom fix ID"); - if (argindex1[nfield] == 0 && modify->fix[n]->scalar_flag == 0) + auto ifix = modify->get_fix_by_id(argi.get_name()); + if (!ifix) error->all(FLERR,"Could not find thermo custom fix ID"); + if (argindex1[nfield] == 0 && ifix->scalar_flag == 0) error->all(FLERR,"Thermo fix does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { - if (modify->fix[n]->vector_flag == 0) + if (ifix->vector_flag == 0) error->all(FLERR,"Thermo fix does not compute vector"); - if (argindex1[nfield] > modify->fix[n]->size_vector && - modify->fix[n]->size_vector_variable == 0) + if (argindex1[nfield] > ifix->size_vector && + ifix->size_vector_variable == 0) error->all(FLERR,"Thermo fix vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (modify->fix[n]->array_flag == 0) + if (ifix->array_flag == 0) error->all(FLERR,"Thermo fix does not compute array"); - if (argindex1[nfield] > modify->fix[n]->size_array_rows && - modify->fix[n]->size_array_rows_variable == 0) + if (argindex1[nfield] > ifix->size_array_rows && + ifix->size_array_rows_variable == 0) error->all(FLERR,"Thermo fix array is accessed out-of-range"); - if (argindex2[nfield] > modify->fix[n]->size_array_cols) + if (argindex2[nfield] > ifix->size_array_cols) error->all(FLERR,"Thermo fix array is accessed out-of-range"); } @@ -971,11 +964,9 @@ void Thermo::parse_fields(char *str) if (n < 0) error->all(FLERR,"Could not find thermo custom variable name"); if (argindex1[nfield] == 0 && input->variable->equalstyle(n) == 0) - error->all(FLERR, - "Thermo custom variable is not equal-style variable"); + error->all(FLERR,"Thermo custom variable is not equal-style variable"); if (argindex1[nfield] && input->variable->vectorstyle(n) == 0) - error->all(FLERR, - "Thermo custom variable is not vector-style variable"); + error->all(FLERR,"Thermo custom variable is not vector-style variable"); if (argindex2[nfield]) error->all(FLERR,"Thermo custom variable cannot have two indices"); diff --git a/src/update.cpp b/src/update.cpp index 72b60c3d3b..95dc47573e 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -488,41 +488,29 @@ void Update::reset_timestep(bigint newstep) output->reset_timestep(ntimestep); - for (int i = 0; i < modify->nfix; i++) { - if (modify->fix[i]->time_depend) - error->all(FLERR, - "Cannot reset timestep with a time-dependent fix defined"); - } + for (const auto &ifix : modify->get_fix_list()) + if (ifix->time_depend) + error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined",ifix->style); // reset eflag/vflag global so no commands will think eng/virial are current eflag_global = vflag_global = -1; - // reset invoked flags of computes, - // so no commands will think they are current between runs - - for (int i = 0; i < modify->ncompute; i++) { - modify->compute[i]->invoked_scalar = -1; - modify->compute[i]->invoked_vector = -1; - modify->compute[i]->invoked_array = -1; - modify->compute[i]->invoked_peratom = -1; - modify->compute[i]->invoked_local = -1; - } - + // reset invoked flags of computes, so no commands will think they are current between runs // clear timestep list of computes that store future invocation times - for (int i = 0; i < modify->ncompute; i++) - if (modify->compute[i]->timeflag) modify->compute[i]->clearstep(); + for (const auto &icompute : modify->get_compute_list()) { + icompute->invoked_scalar = -1; + icompute->invoked_vector = -1; + icompute->invoked_array = -1; + icompute->invoked_peratom = -1; + icompute->invoked_local = -1; + if (icompute->timeflag) icompute->clearstep(); + } // Neighbor Bin/Stencil/Pair classes store timestamps that need to be cleared neighbor->reset_timestep(ntimestep); - - // NOTE: 7Jun12, adding rerun command, don't think this is required - - //for (int i = 0; i < domain->nregion; i++) - // if (domain->regions[i]->dynamic_check()) - // error->all(FLERR,"Cannot reset timestep with a dynamic region defined"); } /* ---------------------------------------------------------------------- diff --git a/src/utils.cpp b/src/utils.cpp index b6c0908934..f70a60da7c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -583,12 +583,11 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // compute if (word[0] == 'c') { - int icompute = lmp->modify->find_compute(id); + auto compute = lmp->modify->get_compute_by_id(id); // check for global vector/array, peratom array, local array - if (icompute >= 0) { - Compute *compute = lmp->modify->compute[icompute]; + if (compute) { if (mode == 0 && compute->vector_flag) { nmax = compute->size_vector; expandflag = 1; @@ -607,13 +606,11 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // fix } else if (word[0] == 'f') { - int ifix = lmp->modify->find_fix(id); + auto fix = lmp->modify->get_fix_by_id(id); // check for global vector/array, peratom array, local array - if (ifix >= 0) { - Fix *fix = lmp->modify->fix[ifix]; - + if (fix) { if (mode == 0 && fix->vector_flag) { nmax = fix->size_vector; expandflag = 1; diff --git a/src/variable.cpp b/src/variable.cpp index 0add581c48..58a505b9ec 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -963,8 +963,7 @@ double Variable::compute_equal(int ivar) else if (style[ivar] == PYTHON) { int ifunc = python->find(data[ivar][0]); if (ifunc < 0) - print_var_error(FLERR,fmt::format("cannot find python function {}", - data[ivar][0]),ivar); + print_var_error(FLERR,fmt::format("cannot find python function {}",data[ivar][0]),ivar); python->invoke_function(ifunc,data[ivar][1]); value = atof(data[ivar][1]); } @@ -1324,10 +1323,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // compute // ---------------- - if (strncmp(word,"c_",2) == 0 || strncmp(word,"C_",2) == 0) { + if (utils::strmatch(word,"^[Cc]_")) { if (domain->box_exist == 0) - print_var_error(FLERR,"Variable evaluation before " - "simulation box is defined",ivar); + print_var_error(FLERR,"Variable evaluation before simulation box is defined",ivar); // uppercase used to force access of // global vector vs global scalar, and global array vs global vector @@ -1335,14 +1333,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int lowercase = 1; if (word[0] == 'C') lowercase = 0; - int icompute = modify->find_compute(word+2); - if (icompute < 0) { - std::string mesg = "Invalid compute ID '"; - mesg += (word+2); - mesg += "' in variable formula"; - print_var_error(FLERR,mesg,ivar); - } - Compute *compute = modify->compute[icompute]; + Compute *compute = modify->get_compute_by_id(word+2); + if (!compute) + print_var_error(FLERR,fmt::format("Invalid compute ID '{}' in variable formula", word+2),ivar); + // parse zero or one or two trailing brackets // point i beyond last bracket @@ -1371,8 +1365,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (update->whichflag == 0) { if (compute->invoked_scalar != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= Compute::INVOKED_SCALAR; @@ -1392,12 +1385,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (index1 > compute->size_vector && compute->size_vector_variable == 0) - print_var_error(FLERR,"Variable formula compute vector " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute vector is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -1419,15 +1410,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (index1 > compute->size_array_rows && compute->size_array_rows_variable == 0) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (index2 > compute->size_array_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -1448,18 +1436,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 0 && compute->vector_flag) { if (tree == nullptr) - print_var_error(FLERR,"Compute global vector in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in equal-style variable formula",ivar); if (treetype == ATOM) - print_var_error(FLERR,"Compute global vector in " - "atom-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); if (compute->size_vector == 0) - print_var_error(FLERR,"Variable formula compute " - "vector is zero length",ivar); + print_var_error(FLERR,"Variable formula compute vector is zero length",ivar); if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -1477,18 +1461,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 1 && compute->array_flag) { if (tree == nullptr) - print_var_error(FLERR,"Compute global vector in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in equal-style variable formula",ivar); if (treetype == ATOM) - print_var_error(FLERR,"Compute global vector in " - "atom-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); if (compute->size_array_rows == 0) - print_var_error(FLERR,"Variable formula compute array " - "is zero length",ivar); + print_var_error(FLERR,"Variable formula compute array is zero length",ivar); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -1508,8 +1488,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1550,15 +1529,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) compute->size_peratom_cols == 0) { if (tree == nullptr) - print_var_error(FLERR,"Per-atom compute in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar); if (treetype == VECTOR) - print_var_error(FLERR,"Per-atom compute in " - "vector-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1576,18 +1552,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) compute->size_peratom_cols > 0) { if (tree == nullptr) - print_var_error(FLERR,"Per-atom compute in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar); if (treetype == VECTOR) - print_var_error(FLERR,"Per-atom compute in " - "vector-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); if (index1 > compute->size_peratom_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1602,17 +1574,15 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 1 && compute->local_flag) { print_var_error(FLERR,"Cannot access local data via indexing",ivar); - } else print_var_error(FLERR, - "Mismatched compute in variable formula",ivar); + } else print_var_error(FLERR,"Mismatched compute in variable formula",ivar); // ---------------- // fix // ---------------- - } else if (strncmp(word,"f_",2) == 0 || strncmp(word,"F_",2) == 0) { + } else if (utils::strmatch(word,"^[fF]_")) { if (domain->box_exist == 0) - print_var_error(FLERR,"Variable evaluation before " - "simulation box is defined",ivar); + print_var_error(FLERR,"Variable evaluation before simulation box is defined",ivar); // uppercase used to force access of // global vector vs global scalar, and global array vs global vector @@ -1620,11 +1590,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int lowercase = 1; if (word[0] == 'F') lowercase = 0; - int ifix = modify->find_fix(word+2); - if (ifix < 0) - print_var_error(FLERR,fmt::format("Invalid fix ID '{}' in variable" - " formula",word+2),ivar); - Fix *fix = modify->fix[ifix]; + Fix *fix = modify->get_fix_by_id(word+2); + if (!fix) + print_var_error(FLERR,fmt::format("Invalid fix ID '{}' in variable formula",word+2),ivar); + // parse zero or one or two trailing brackets // point i beyond last bracket @@ -4057,19 +4026,17 @@ int Variable::special_function(char *word, char *contents, Tree **tree, *ptr1 = '\0'; } else index = 0; - int icompute = modify->find_compute(&args[0][2]); - if (icompute < 0) { + compute = modify->get_compute_by_id(&args[0][2]); + if (!compute) { std::string mesg = "Invalid compute ID '"; mesg += (args[0]+2); mesg += "' in variable formula"; print_var_error(FLERR,mesg,ivar); } - compute = modify->compute[icompute]; if (index == 0 && compute->vector_flag) { if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -4078,12 +4045,10 @@ int Variable::special_function(char *word, char *contents, Tree **tree, nstride = 1; } else if (index && compute->array_flag) { if (index > compute->size_array_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -4102,14 +4067,13 @@ int Variable::special_function(char *word, char *contents, Tree **tree, *ptr1 = '\0'; } else index = 0; - int ifix = modify->find_fix(&args[0][2]); - if (ifix < 0) { + fix = modify->get_fix_by_id(&args[0][2]); + if (!fix) { std::string mesg = "Invalid fix ID '"; mesg += (args[0]+2); mesg += "' in variable formula"; print_var_error(FLERR,mesg,ivar); } - fix = modify->fix[ifix]; if (index == 0 && fix->vector_flag) { if (update->whichflag > 0 && update->ntimestep % fix->global_freq) { std::string mesg = "Fix with ID '"; diff --git a/src/velocity.cpp b/src/velocity.cpp index 4a449d00e7..34b8d5a700 100644 --- a/src/velocity.cpp +++ b/src/velocity.cpp @@ -43,7 +43,7 @@ enum{NONE,CONSTANT,EQUAL,ATOM}; /* ---------------------------------------------------------------------- */ -Velocity::Velocity(LAMMPS *lmp) : Command(lmp) {} +Velocity::Velocity(LAMMPS *lmp) : Command(lmp), rigid_fix(nullptr), temperature(nullptr) {} /* ---------------------------------------------------------------------- */ @@ -91,7 +91,6 @@ void Velocity::command(int narg, char **arg) bias_flag = 0; loop_flag = ALL; scale_flag = 1; - rfix = -1; // read options from end of input line // change defaults as options specify @@ -108,8 +107,7 @@ void Velocity::command(int narg, char **arg) // b/c methods invoked in the compute/fix perform forward/reverse comm int initcomm = 0; - if (style == ZERO && rfix >= 0 && - utils::strmatch(modify->fix[rfix]->style,"^rigid.*/small.*")) initcomm = 1; + if (style == ZERO && rigid_fix && utils::strmatch(rigid_fix->style,"^rigid.*/small.*")) initcomm = 1; if ((style == CREATE || style == SET) && temperature && strcmp(temperature->style,"temp/cs") == 0) initcomm = 1; @@ -154,7 +152,6 @@ void Velocity::init_external(const char *extgroup) momentum_flag = 1; rotation_flag = 0; loop_flag = ALL; - rfix = -1; scale_flag = 1; bias_flag = 0; } @@ -692,21 +689,21 @@ void Velocity::ramp(int /*narg*/, char **arg) void Velocity::zero(int /*narg*/, char **arg) { if (strcmp(arg[0],"linear") == 0) { - if (rfix < 0) zero_momentum(); - else if (utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) { - modify->fix[rfix]->setup_pre_neighbor(); - modify->fix[rfix]->zero_momentum(); - } else if (utils::strmatch(modify->fix[rfix]->style,"^rigid")) { - modify->fix[rfix]->zero_momentum(); + if (!rigid_fix) zero_momentum(); + else if (utils::strmatch(rigid_fix->style,"^rigid/small")) { + rigid_fix->setup_pre_neighbor(); + rigid_fix->zero_momentum(); + } else if (utils::strmatch(rigid_fix->style,"^rigid")) { + rigid_fix->zero_momentum(); } else error->all(FLERR,"Velocity rigid used with non-rigid fix-ID"); } else if (strcmp(arg[0],"angular") == 0) { - if (rfix < 0) zero_rotation(); - else if (utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) { - modify->fix[rfix]->setup_pre_neighbor(); - modify->fix[rfix]->zero_rotation(); - } else if (utils::strmatch(modify->fix[rfix]->style,"^rigid")) { - modify->fix[rfix]->zero_rotation(); + if (!rigid_fix) zero_rotation(); + else if (utils::strmatch(rigid_fix->style,"^rigid/small")) { + rigid_fix->setup_pre_neighbor(); + rigid_fix->zero_rotation(); + } else if (utils::strmatch(rigid_fix->style,"^rigid")) { + rigid_fix->zero_rotation(); } else error->all(FLERR,"Velocity rigid used with non-rigid fix-ID"); } else error->all(FLERR,"Illegal velocity command"); @@ -843,11 +840,10 @@ void Velocity::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"temp") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) error->all(FLERR,"Could not find velocity temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(arg[iarg+1]); + if (!temperature) error->all(FLERR,"Could not find velocity temperature compute ID"); if (temperature->tempflag == 0) - error->all(FLERR,"Velocity temperature ID does not compute temperature"); + error->all(FLERR,"Velocity temperature compute {} does not compute temperature", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"bias") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); @@ -862,8 +858,8 @@ void Velocity::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); - rfix = modify->find_fix(arg[iarg+1]); - if (rfix < 0) error->all(FLERR,"Fix ID for velocity does not exist"); + rigid_fix = modify->get_fix_by_id(arg[iarg+1]); + if (!rigid_fix) error->all(FLERR,"Fix ID {} for velocity does not exist", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"units") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); diff --git a/src/velocity.h b/src/velocity.h index f0a756350c..cce8508021 100644 --- a/src/velocity.h +++ b/src/velocity.h @@ -36,8 +36,9 @@ class Velocity : public Command { int igroup, groupbit; int style; int dist_flag, sum_flag, momentum_flag, rotation_flag; - int bias_flag, loop_flag, scale_flag, rfix; + int bias_flag, loop_flag, scale_flag; double xscale, yscale, zscale; + class Fix *rigid_fix; class Compute *temperature; void set(int, char **); diff --git a/src/verlet.cpp b/src/verlet.cpp index b9b0b392e1..aa180f5644 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -22,6 +22,7 @@ #include "dihedral.h" #include "domain.h" #include "error.h" +#include "fix.h" #include "force.h" #include "improper.h" #include "kspace.h" @@ -49,10 +50,14 @@ void Verlet::init() { Integrate::init(); - // warn if no fixes + // warn if no fixes doing time integration - if (modify->nfix == 0 && comm->me == 0) - error->warning(FLERR,"No fixes defined, atoms won't move"); + bool do_time_integrate = false; + for (const auto &fix : modify->get_fix_list()) + if (fix->time_integrate) do_time_integrate; + + if (!do_time_integrate && (comm->me == 0)) + error->warning(FLERR,"No fixes with time integration, atoms won't move"); // virial_style: // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions @@ -68,8 +73,7 @@ void Verlet::init() // detect if fix omp is present for clearing force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() diff --git a/src/write_data.cpp b/src/write_data.cpp index 82c237a07e..c2c59fd046 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -213,9 +213,9 @@ void WriteData::write(const std::string &file) // extra sections managed by fixes if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->wd_section) - for (int m = 0; m < modify->fix[i]->wd_section; m++) fix(i,m); + for (auto &ifix : modify->get_fix_list()) + if (ifix->wd_section) + for (int m = 0; m < ifix->wd_section; m++) fix(ifix,m); // close data file @@ -267,22 +267,19 @@ void WriteData::header() // fix info if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->wd_header) - for (int m = 0; m < modify->fix[i]->wd_header; m++) - modify->fix[i]->write_data_header(fp,m); + for (auto &ifix : modify->get_fix_list()) + if (ifix->wd_header) + for (int m = 0; m < ifix->wd_header; m++) + ifix->write_data_header(fp,m); // box info - auto box = fmt::format("\n{} {} xlo xhi" - "\n{} {} ylo yhi" - "\n{} {} zlo zhi\n", + auto box = fmt::format("\n{} {} xlo xhi\n{} {} ylo yhi\n{} {} zlo zhi\n", domain->boxlo[0],domain->boxhi[0], domain->boxlo[1],domain->boxhi[1], domain->boxlo[2],domain->boxhi[2]); if (domain->triclinic) - box += fmt::format("{} {} {} xy xz yz\n", - domain->xy,domain->xz,domain->yz); + box += fmt::format("{} {} {} xy xz yz\n",domain->xy,domain->xz,domain->yz); fputs(box.c_str(),fp); } @@ -722,13 +719,13 @@ void WriteData::bonus(int flag) write out Mth section of data file owned by Fix ifix ------------------------------------------------------------------------- */ -void WriteData::fix(int ifix, int mth) +void WriteData::fix(Fix *ifix, int mth) { // communication buffer for Fix info // maxrow X ncol = largest buffer needed by any proc int sendrow,ncol; - modify->fix[ifix]->write_data_section_size(mth,sendrow,ncol); + ifix->write_data_section_size(mth,sendrow,ncol); int maxrow; MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); @@ -738,7 +735,7 @@ void WriteData::fix(int ifix, int mth) // pack my fix data into buf - modify->fix[ifix]->write_data_section_pack(mth,buf); + ifix->write_data_section_pack(mth,buf); // write one chunk of info per proc to file // proc 0 pings each proc, receives its chunk, writes to file @@ -751,7 +748,7 @@ void WriteData::fix(int ifix, int mth) MPI_Status status; MPI_Request request; - modify->fix[ifix]->write_data_section_keyword(mth,fp); + ifix->write_data_section_keyword(mth,fp); for (int iproc = 0; iproc < nprocs; iproc++) { if (iproc) { MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); @@ -761,7 +758,7 @@ void WriteData::fix(int ifix, int mth) recvrow /= ncol; } else recvrow = sendrow; - modify->fix[ifix]->write_data_section(mth,fp,recvrow,buf,index); + ifix->write_data_section(mth,fp,recvrow,buf,index); index += recvrow; } diff --git a/src/write_data.h b/src/write_data.h index 74e7e6136e..d62f048894 100644 --- a/src/write_data.h +++ b/src/write_data.h @@ -51,7 +51,7 @@ class WriteData : public Command { void dihedrals(); void impropers(); void bonus(int); - void fix(int, int); + void fix(class Fix *, int); }; } // namespace LAMMPS_NS diff --git a/src/write_restart.cpp b/src/write_restart.cpp index e9be7f9c36..661585605d 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -413,9 +413,9 @@ void WriteRestart::write(const std::string &file) // invoke any fixes that write their own restart file - for (int ifix = 0; ifix < modify->nfix; ifix++) - if (modify->fix[ifix]->restart_file) - modify->fix[ifix]->write_restart_file(file.c_str()); + for (auto &fix : modify->get_fix_list()) + if (fix->restart_file) + fix->write_restart_file(file.c_str()); } /* ----------------------------------------------------------------------