diff --git a/src/CORESHELL/compute_temp_cs.cpp b/src/CORESHELL/compute_temp_cs.cpp index ed6634f4b0..04c7a743d8 100644 --- a/src/CORESHELL/compute_temp_cs.cpp +++ b/src/CORESHELL/compute_temp_cs.cpp @@ -19,19 +19,19 @@ #include "compute_temp_cs.h" -#include - #include "atom.h" #include "atom_vec.h" +#include "comm.h" #include "domain.h" -#include "update.h" +#include "error.h" +#include "fix_store.h" #include "force.h" #include "group.h" -#include "modify.h" -#include "fix_store.h" -#include "comm.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -74,8 +74,7 @@ ComputeTempCS::ComputeTempCS(LAMMPS *lmp, int narg, char **arg) : strcpy(id_fix,fixcmd.c_str()); fixcmd += fmt::format(" {} STORE peratom 0 1", group->names[igroup]); - modify->add_fix(fixcmd); - fix = (FixStore *) modify->fix[modify->nfix-1]; + fix = (FixStore *)modify->add_fix(fixcmd); // set fix store values = 0 for now // fill them in via setup() once Comm::borders() has been called diff --git a/src/DPD-REACT/fix_rx.cpp b/src/DPD-REACT/fix_rx.cpp index 52dcaaf2d5..e50e145853 100644 --- a/src/DPD-REACT/fix_rx.cpp +++ b/src/DPD-REACT/fix_rx.cpp @@ -18,6 +18,7 @@ #include "comm.h" #include "domain.h" #include "error.h" +#include "fix_property_atom.h" #include "force.h" #include "group.h" #include "math_special.h" @@ -344,12 +345,9 @@ void FixRX::post_constructor() newcmd1 += " ghost yes"; newcmd2 += " ghost yes"; - modify->add_fix(newcmd1); - fix_species = (FixPropertyAtom *) modify->fix[modify->nfix-1]; - restartFlag = modify->fix[modify->nfix-1]->restart_reset; - - modify->add_fix(newcmd2); - fix_species_old = (FixPropertyAtom *) modify->fix[modify->nfix-1]; + fix_species = (FixPropertyAtom *) modify->add_fix(newcmd1); + restartFlag = fix_species->restart_reset; + fix_species_old = (FixPropertyAtom *) modify->add_fix(newcmd2); if (nspecies==0) error->all(FLERR,"There are no rx species specified."); diff --git a/src/DPD-REACT/fix_rx.h b/src/DPD-REACT/fix_rx.h index debf4d911e..1d65c4c09e 100644 --- a/src/DPD-REACT/fix_rx.h +++ b/src/DPD-REACT/fix_rx.h @@ -136,7 +136,7 @@ class FixRX : public Fix { //!< ODE Solver diagnostics. void odeDiagnostics(void); - private: + protected: char *kineticsFile; char *id_fix_species, *id_fix_species_old; class FixPropertyAtom *fix_species, *fix_species_old; diff --git a/src/EXTRA-COMPUTE/compute_hma.cpp b/src/EXTRA-COMPUTE/compute_hma.cpp index 09a2840906..043dcec6cf 100644 --- a/src/EXTRA-COMPUTE/compute_hma.cpp +++ b/src/EXTRA-COMPUTE/compute_hma.cpp @@ -91,9 +91,8 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) : // our new fix's group = same as compute group id_fix = utils::strdup(std::string(id)+"_COMPUTE_STORE"); - modify->add_fix(fmt::format("{} {} STORE peratom 1 3", - id_fix, group->names[igroup])); - fix = (FixStore *) modify->fix[modify->nfix-1]; + fix = (FixStore *)modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/FEP/fix_adapt_fep.cpp b/src/FEP/fix_adapt_fep.cpp index b5aad03887..3b4290f2c9 100644 --- a/src/FEP/fix_adapt_fep.cpp +++ b/src/FEP/fix_adapt_fep.cpp @@ -216,10 +216,8 @@ void FixAdaptFEP::post_constructor() id_fix_chg = nullptr; if (diamflag) { - auto cmd = fmt::format("{}_FIX_STORE_DIAM {} STORE peratom 1 1", - group->names[igroup]); - modify->add_fix(cmd); - fix_diam = (FixStore *) modify->fix[modify->nfix-1]; + auto cmd = fmt::format("{}_FIX_STORE_DIAM {} STORE peratom 1 1", group->names[igroup]); + fix_diam = (FixStore *) modify->add_fix(cmd); if (fix_diam->restart_reset) fix_diam->restart_reset = 0; else { @@ -236,10 +234,8 @@ void FixAdaptFEP::post_constructor() } if (chgflag) { - auto cmd = fmt::format("{}_FIX_STORE_CHG {} STORE peratom 1 1", - group->names[igroup]); - modify->add_fix(cmd); - fix_chg = (FixStore *) modify->fix[modify->nfix-1]; + auto cmd = fmt::format("{}_FIX_STORE_CHG {} STORE peratom 1 1", group->names[igroup]); + fix_chg = (FixStore *) modify->add_fix(cmd); if (fix_chg->restart_reset) fix_chg->restart_reset = 0; else { diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index 753cceb247..cf51d5db3e 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -68,8 +67,7 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) // this is so final order of Modify:fix will conform to input script fix_history = nullptr; - modify->add_fix("NEIGH_HISTORY_HH_DUMMY all DUMMY"); - fix_dummy = (FixDummy *) modify->fix[modify->nfix-1]; + fix_dummy = (FixDummy *) modify->add_fix("NEIGH_HISTORY_HH_DUMMY all DUMMY"); } /* ---------------------------------------------------------------------- */ @@ -436,22 +434,19 @@ void PairGranHookeHistory::init_style() // this is so its order in the fix list is preserved if (history && (fix_history == nullptr)) { - auto cmd = fmt::format("NEIGH_HISTORY_HH all NEIGH_HISTORY {}", - size_history); - modify->replace_fix("NEIGH_HISTORY_HH_DUMMY",cmd,1); - int ifix = modify->find_fix("NEIGH_HISTORY_HH"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + auto cmd = fmt::format("NEIGH_HISTORY_HH all NEIGH_HISTORY {}", size_history); + fix_history = (FixNeighHistory *) modify->replace_fix("NEIGH_HISTORY_HH_DUMMY", cmd, 1); fix_history->pair = this; } // check for FixFreeze and set freeze_group_bit - for (i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"freeze") == 0) break; - if (i < modify->nfix) freeze_group_bit = modify->fix[i]->groupbit; - else freeze_group_bit = 0; + int ifreeze = modify->find_fix_by_style("^freeze"); + if (ifreeze < 0) freeze_group_bit = 0; + else freeze_group_bit = modify->fix[ifreeze]->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++) @@ -460,15 +455,8 @@ void PairGranHookeHistory::init_style() // check for FixPour and FixDeposit so can extract particle radii - int ipour; - for (ipour = 0; ipour < modify->nfix; ipour++) - if (strcmp(modify->fix[ipour]->style,"pour") == 0) break; - if (ipour == modify->nfix) ipour = -1; - - int idep; - for (idep = 0; idep < modify->nfix; idep++) - if (strcmp(modify->fix[idep]->style,"deposit") == 0) break; - if (idep == modify->nfix) idep = -1; + int ipour = modify->find_fix_by_style("^pour"); + int idep = modify->find_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -499,10 +487,8 @@ void PairGranHookeHistory::init_style() 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); + 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); // set fix which stores history info diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index cca349b819..d0e75d4812 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -20,25 +20,24 @@ #include "pair_granular.h" -#include -#include - #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" +#include "comm.h" +#include "error.h" #include "fix.h" #include "fix_dummy.h" #include "fix_neigh_history.h" -#include "comm.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "force.h" #include "math_const.h" #include "math_special.h" +#include "memory.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace MathConst; @@ -103,8 +102,7 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp) // this is so final order of Modify:fix will conform to input script fix_history = nullptr; - modify->add_fix("NEIGH_HISTORY_GRANULAR_DUMMY all DUMMY"); - fix_dummy = (FixDummy *) modify->fix[modify->nfix-1]; + fix_dummy = (FixDummy *) modify->add_fix("NEIGH_HISTORY_GRANULAR_DUMMY all DUMMY"); } /* ---------------------------------------------------------------------- */ @@ -1122,21 +1120,21 @@ void PairGranular::init_style() // this is so its order in the fix list is preserved if (use_history && fix_history == nullptr) { - modify->replace_fix("NEIGH_HISTORY_GRANULAR_DUMMY","NEIGH_HISTORY_GRANULAR" - " all NEIGH_HISTORY " + std::to_string(size_history),1); - int ifix = modify->find_fix("NEIGH_HISTORY_GRANULAR"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + fix_history = (FixNeighHistory *) modify->replace_fix("NEIGH_HISTORY_GRANULAR_DUMMY", + "NEIGH_HISTORY_GRANULAR" + " all NEIGH_HISTORY " + + std::to_string(size_history),1); fix_history->pair = this; } // check for FixFreeze and set freeze_group_bit - for (i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"freeze") == 0) break; - if (i < modify->nfix) freeze_group_bit = modify->fix[i]->groupbit; - else freeze_group_bit = 0; + int ifix = modify->find_fix_by_style("^freeze"); + if (ifix < 0) freeze_group_bit = 0; + else freeze_group_bit = modify->fix[ifix]->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++) @@ -1145,15 +1143,8 @@ void PairGranular::init_style() // check for FixPour and FixDeposit so can extract particle radii - int ipour; - for (ipour = 0; ipour < modify->nfix; ipour++) - if (strcmp(modify->fix[ipour]->style,"pour") == 0) break; - if (ipour == modify->nfix) ipour = -1; - - int idep; - for (idep = 0; idep < modify->nfix; idep++) - if (strcmp(modify->fix[idep]->style,"deposit") == 0) break; - if (idep == modify->nfix) idep = -1; + int ipour = modify->find_fix_by_style("^pour"); + int idep = modify->find_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -1187,10 +1178,8 @@ void PairGranular::init_style() } } - 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); + 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); // set fix which stores history info diff --git a/src/KOKKOS/fix_rx_kokkos.cpp b/src/KOKKOS/fix_rx_kokkos.cpp index 7bc7bf95c3..15b4a39849 100644 --- a/src/KOKKOS/fix_rx_kokkos.cpp +++ b/src/KOKKOS/fix_rx_kokkos.cpp @@ -13,24 +13,25 @@ ------------------------------------------------------------------------- */ #include "fix_rx_kokkos.h" -#include -#include "atom_masks.h" + #include "atom_kokkos.h" -#include "force.h" -#include "memory_kokkos.h" -#include "update.h" -#include "modify.h" -#include "neighbor.h" -#include "neigh_list_kokkos.h" -#include "neigh_request.h" -#include "error.h" -#include "math_special_kokkos.h" +#include "atom_masks.h" #include "comm.h" #include "domain.h" +#include "error.h" +#include "fix_property_atom.h" +#include "force.h" #include "kokkos.h" - +#include "math_special_kokkos.h" +#include "memory_kokkos.h" +#include "modify.h" +#include "neigh_list_kokkos.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" #include // DBL_EPSILON +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -104,7 +105,7 @@ void FixRxKokkos::post_constructor() FixRX::post_constructor(); // Need a copy of this - this->my_restartFlag = modify->fix[modify->nfix-1]->restart_reset; + this->my_restartFlag = fix_species->restart_reset; } /* ---------------------------------------------------------------------- */ diff --git a/src/MISC/pair_srp.cpp b/src/MISC/pair_srp.cpp index 332e103b12..0fef989c88 100644 --- a/src/MISC/pair_srp.cpp +++ b/src/MISC/pair_srp.cpp @@ -84,8 +84,7 @@ PairSRP::PairSRP(LAMMPS *lmp) : Pair(lmp), fix_id(nullptr) // will be invoked before other fixes that migrate atoms // this is checked for in FixSRP - modify->add_fix(fmt::format("{:02d}_FIX_SRP all SRP",srp_instance)); - f_srp = (FixSRP *) modify->fix[modify->nfix-1]; + f_srp = (FixSRP *) modify->add_fix(fmt::format("{:02d}_FIX_SRP all SRP",srp_instance)); ++srp_instance; } diff --git a/src/OPENMP/pair_reaxff_omp.cpp b/src/OPENMP/pair_reaxff_omp.cpp index 69d68e67e8..6cf3e90575 100644 --- a/src/OPENMP/pair_reaxff_omp.cpp +++ b/src/OPENMP/pair_reaxff_omp.cpp @@ -136,10 +136,8 @@ void PairReaxFFOMP::init_style() error->warning(FLERR,"Total cutoff < 2*bond cutoff. May need to use an " "increased neighbor list skin."); - if (fix_reaxff == nullptr) { - modify->add_fix(fmt::format("{} all REAXFF",fix_id)); - fix_reaxff = (FixReaxFF *) modify->fix[modify->nfix-1]; - } + if (fix_reaxff == nullptr) + fix_reaxff = (FixReaxFF *) modify->add_fix(fmt::format("{} all REAXFF",fix_id)); api->control->nthreads = comm->nthreads; } diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index 46d7efdf8d..e52347727f 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -701,37 +701,25 @@ it will have the name 'i_limit_tags' and will be intitialized to 0 (not in group void FixBondReact::post_constructor() { // let's add the limit_tags per-atom property fix - std::string cmd = std::string("bond_react_props_internal"); - id_fix2 = new char[cmd.size()+1]; - strcpy(id_fix2,cmd.c_str()); - - int ifix = modify->find_fix(id_fix2); - if (ifix == -1) { - cmd += std::string(" all property/atom i_limit_tags i_react_tags ghost yes"); - modify->add_fix(cmd); - } + id_fix2 = utils::strdup("bond_react_props_internal"); + if (modify->find_fix(id_fix2) < 0) + modify->add_fix(std::string(id_fix2)+" all property/atom i_limit_tags i_react_tags ghost yes"); // create master_group if not already existing // NOTE: limit_tags and react_tags automaticaly intitialized to zero (unless read from restart) group->find_or_create(master_group); - cmd = fmt::format("{} dynamic all property limit_tags",master_group); + std::string cmd = fmt::format("{} dynamic all property limit_tags",master_group); group->assign(cmd); if (stabilization_flag == 1) { int groupid = group->find(exclude_group); // create exclude_group if not already existing, or use as parent group if static if (groupid == -1 || group->dynamic[groupid] == 0) { - // create stabilization per-atom property - cmd = std::string("bond_react_stabilization_internal"); - id_fix3 = new char[cmd.size()+1]; - strcpy(id_fix3,cmd.c_str()); - ifix = modify->find_fix(id_fix3); - if (ifix == -1) { - cmd += std::string(" all property/atom i_statted_tags ghost yes"); - modify->add_fix(cmd); - fix3 = modify->fix[modify->nfix-1]; - } + // create stabilization per-atom property + id_fix3 = utils::strdup("bond_react_stabilization_internal"); + if (modify->find_fix(id_fix3) < 0) + fix3 = modify->add_fix(std::string(id_fix3) + " all property/atom i_statted_tags ghost yes"); statted_id = utils::strdup("statted_tags"); @@ -770,7 +758,7 @@ void FixBondReact::post_constructor() // this returns names of corresponding property int unused; - char * idprop; + char *idprop; idprop = (char *) fix->extract("property",unused); if (idprop == nullptr) error->all(FLERR,"Exclude group must be a per-atom property group"); @@ -787,17 +775,10 @@ void FixBondReact::post_constructor() // let's create a new nve/limit fix to limit newly reacted atoms - cmd = std::string("bond_react_MASTER_nve_limit"); - id_fix1 = new char[cmd.size()+1]; - strcpy(id_fix1,cmd.c_str()); - - ifix = modify->find_fix(id_fix1); - - if (ifix == -1) { - cmd += fmt::format(" {} nve/limit {}",master_group,nve_limit_xmax); - modify->add_fix(cmd); - fix1 = modify->fix[modify->nfix-1]; - } + id_fix1 = utils::strdup("bond_react_MASTER_nve_limit"); + if (modify->find_fix(id_fix1) < 0) + fix1 = modify->add_fix(fmt::format("{} {} nve/limit {}", + id_fix1,master_group,nve_limit_xmax)); } }