diff --git a/src/GPU/fix_nh_gpu.cpp b/src/GPU/fix_nh_gpu.cpp index 9d4fbcc668..00df278ea8 100644 --- a/src/GPU/fix_nh_gpu.cpp +++ b/src/GPU/fix_nh_gpu.cpp @@ -129,9 +129,7 @@ void FixNHGPU::remap() } } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -304,9 +302,7 @@ void FixNHGPU::remap() } } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- diff --git a/src/INTEL/fix_nh_intel.cpp b/src/INTEL/fix_nh_intel.cpp index 2c05c3f6fa..688101ab13 100644 --- a/src/INTEL/fix_nh_intel.cpp +++ b/src/INTEL/fix_nh_intel.cpp @@ -138,9 +138,7 @@ void FixNHIntel::remap() } } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -321,9 +319,7 @@ void FixNHIntel::remap() } } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/fix_nh_kokkos.cpp b/src/KOKKOS/fix_nh_kokkos.cpp index 939b88889c..3d2d3ebb71 100644 --- a/src/KOKKOS/fix_nh_kokkos.cpp +++ b/src/KOKKOS/fix_nh_kokkos.cpp @@ -310,10 +310,9 @@ void FixNHKokkos::remap() // domain->x2lamda(x[i],x[i]); //} - if (nrigid) + if (rfix.size() > 0) error->all(FLERR,"Cannot (yet) use rigid bodies with fix nh and Kokkos"); - //for (i = 0; i < nrigid; i++) - // modify->fix[rfix[i]]->deform(0); + // for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -459,9 +458,7 @@ void FixNHKokkos::remap() // domain->lamda2x(x[i],x[i]); //} - //if (nrigid) - // for (i = 0; i < nrigid; i++) - // modify->fix[rfix[i]]->deform(1); + // for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- diff --git a/src/OPENMP/fix_nh_omp.cpp b/src/OPENMP/fix_nh_omp.cpp index aada50949e..a7fe2738ca 100644 --- a/src/OPENMP/fix_nh_omp.cpp +++ b/src/OPENMP/fix_nh_omp.cpp @@ -68,9 +68,7 @@ void FixNHOMP::remap() domain->x2lamda(x[i],x[i]); } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -218,9 +216,7 @@ void FixNHOMP::remap() domain->lamda2x(x[i],x[i]); } - if (nrigid) - for (int i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index fba050e89c..1f715a1dd4 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -319,9 +319,6 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : pflag = 1; dimension = domain->dimension; - nrigid = 0; - rfix = nullptr; - current_lifo = 0; } @@ -329,8 +326,6 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : FixBoxRelax::~FixBoxRelax() { - delete[] rfix; - // delete temperature and pressure if fix created them if (tflag) modify->delete_compute(id_temp); @@ -368,20 +363,10 @@ void FixBoxRelax::init() else kspace_flag = 0; // detect if any rigid fixes exist so rigid bodies move when box is remapped - // rfix[] = indices to each fix rigid - delete[] rfix; - nrigid = 0; - rfix = nullptr; - - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigid++; - if (nrigid) { - rfix = new int[nrigid]; - nrigid = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) rfix[nrigid++] = i; - } + rfix.clear(); + for (auto &ifix : modify->get_fix_list()) + if (ifix->rigid_flag) rfix.push_back(ifix); // initial box dimensions @@ -638,9 +623,7 @@ void FixBoxRelax::remap() domain->x2lamda(x[i],x[i]); } - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -678,9 +661,7 @@ void FixBoxRelax::remap() domain->lamda2x(x[i],x[i]); } - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- */ diff --git a/src/fix_box_relax.h b/src/fix_box_relax.h index bedf7faef3..0870ed522d 100644 --- a/src/fix_box_relax.h +++ b/src/fix_box_relax.h @@ -68,8 +68,7 @@ class FixBoxRelax : public Fix { class Compute *temperature, *pressure; int tflag, pflag; - int nrigid; - int *rfix; + std::vector rfix; double sigma[6]; // scaled target stress double utsigma[3]; // weighting for upper-tri elements diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index 12272c3123..562ca51c29 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -53,12 +53,9 @@ enum{ISO,ANISO,TRICLINIC}; ---------------------------------------------------------------------- */ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - rfix(nullptr), id_dilate(nullptr), irregular(nullptr), - id_temp(nullptr), id_press(nullptr), - eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), - eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), - etap_mass(nullptr) + Fix(lmp, narg, arg), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), + id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), + etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr) { if (narg < 4) utils::missing_cmd_args(FLERR, std::string("fix ") + style, error); @@ -271,7 +268,7 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[iarg+1],"all") == 0) allremap = 1; else { allremap = 0; - delete [] id_dilate; + delete[] id_dilate; id_dilate = utils::strdup(arg[iarg+1]); int idilate = group->find(id_dilate); if (idilate == -1) @@ -564,9 +561,6 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : if (deviatoric_flag) size_vector += 1; } - nrigid = 0; - rfix = nullptr; - if (pre_exchange_flag) irregular = new Irregular(lmp); else irregular = nullptr; @@ -582,31 +576,29 @@ FixNH::~FixNH() { if (copymode) return; - delete [] id_dilate; - delete [] rfix; - + delete[] id_dilate; delete irregular; // delete temperature and pressure if fix created them if (tcomputeflag) modify->delete_compute(id_temp); - delete [] id_temp; + delete[] id_temp; if (tstat_flag) { - delete [] eta; - delete [] eta_dot; - delete [] eta_dotdot; - delete [] eta_mass; + delete[] eta; + delete[] eta_dot; + delete[] eta_dotdot; + delete[] eta_mass; } if (pstat_flag) { if (pcomputeflag) modify->delete_compute(id_press); - delete [] id_press; + delete[] id_press; if (mpchain) { - delete [] etap; - delete [] etap_dot; - delete [] etap_dotdot; - delete [] etap_mass; + delete[] etap; + delete[] etap_dot; + delete[] etap_dotdot; + delete[] etap_mass; } } } @@ -641,15 +633,17 @@ void FixNH::init() // ensure no conflict with fix deform if (pstat_flag) - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0) { - int *dimflag = (dynamic_cast(modify->fix[i]))->dimflag; + for (auto &ifix : modify->get_fix_by_style("^deform")) { + auto deform = dynamic_cast(ifix); + if (deform) { + int *dimflag = deform->dimflag; if ((p_flag[0] && dimflag[0]) || (p_flag[1] && dimflag[1]) || (p_flag[2] && dimflag[2]) || (p_flag[3] && dimflag[3]) || (p_flag[4] && dimflag[4]) || (p_flag[5] && dimflag[5])) error->all(FLERR,"Cannot use fix {} and fix deform on " "same component of stress tensor", style); } + } // set temperature and pressure ptrs @@ -718,20 +712,10 @@ void FixNH::init() } // detect if any rigid fixes exist so rigid bodies move when box is remapped - // rfix[] = indices to each fix rigid - delete [] rfix; - nrigid = 0; - rfix = nullptr; - - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigid++; - if (nrigid) { - rfix = new int[nrigid]; - nrigid = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) rfix[nrigid++] = i; - } + rfix.clear(); + for (auto &ifix : modify->get_fix_list()) + if (ifix->rigid_flag) rfix.push_back(ifix); } /* ---------------------------------------------------------------------- @@ -1090,9 +1074,7 @@ void FixNH::remap() domain->x2lamda(x[i],x[i]); } - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -1237,9 +1219,7 @@ void FixNH::remap() domain->lamda2x(x[i],x[i]); } - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- @@ -1398,7 +1378,7 @@ int FixNH::modify_param(int narg, char **arg) modify->delete_compute(id_temp); tcomputeflag = 0; } - delete [] id_temp; + delete[] id_temp; id_temp = utils::strdup(arg[1]); temperature = modify->get_compute_by_id(arg[1]); @@ -1428,7 +1408,7 @@ int FixNH::modify_param(int narg, char **arg) modify->delete_compute(id_press); pcomputeflag = 0; } - delete [] id_press; + delete[] id_press; id_press = utils::strdup(arg[1]); pressure = modify->get_compute_by_id(arg[1]); diff --git a/src/fix_nh.h b/src/fix_nh.h index 3e406929b2..4741f3bac5 100644 --- a/src/fix_nh.h +++ b/src/fix_nh.h @@ -66,9 +66,8 @@ class FixNH : public Fix { double drag, tdrag_factor; // drag factor on particle thermostat double pdrag_factor; // drag factor on barostat int kspace_flag; // 1 if KSpace invoked, 0 if not - int nrigid; // number of rigid fixes int dilate_group_bit; // mask for dilation group - int *rfix; // indices of rigid fixes + std::vector rfix; // list of rigid fixes char *id_dilate; // group name to dilate class Irregular *irregular; // for migrating atoms after box flips