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/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_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/modify.h b/src/modify.h index 60365cd56c..c4f8c2ef02 100644 --- a/src/modify.h +++ b/src/modify.h @@ -113,6 +113,7 @@ class Modify : protected Pointers { int find_fix(const std::string &); // 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(); @@ -126,6 +127,7 @@ class Modify : protected Pointers { int find_compute(const std::string &); // 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(); diff --git a/src/respa.cpp b/src/respa.cpp index af8b0c21ac..9690105d40 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -373,7 +373,7 @@ void Respa::setup(int flag) 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]]; + 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); } diff --git a/src/special.cpp b/src/special.cpp index 9f480da78f..ceba160be2 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -1290,9 +1290,8 @@ int Special::rendezvous_pairs(int n, char *inbuf, int &flag, int *&proclist, void Special::fix_alteration() { - for (int ifix = 0; ifix < modify->nfix; 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/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"); } /* ----------------------------------------------------------------------