diff --git a/src/ADIOS/dump_atom_adios.cpp b/src/ADIOS/dump_atom_adios.cpp index e6e486e096..038a332ae5 100644 --- a/src/ADIOS/dump_atom_adios.cpp +++ b/src/ADIOS/dump_atom_adios.cpp @@ -134,10 +134,10 @@ void DumpAtomADIOS::write() // Now we know the global size and the local subset size and offset // of the atoms table - auto nAtomsGlobal = static_cast(ntotal); - auto startRow = static_cast(atomOffset); - auto nAtomsLocal = static_cast(nme); - auto nColumns = static_cast(size_one); + auto nAtomsGlobal = static_cast(ntotal); + auto startRow = static_cast(atomOffset); + auto nAtomsLocal = static_cast(nme); + auto nColumns = static_cast(size_one); internal->varAtoms.SetShape({nAtomsGlobal, nColumns}); internal->varAtoms.SetSelection({{startRow, 0}, {nAtomsLocal, nColumns}}); @@ -238,7 +238,7 @@ void DumpAtomADIOS::init_style() columnNames = {"id", "type", "xs", "ys", "zs", "ix", "iy", "iz"}; } - for (int icol = 0; icol < (int)columnNames.size(); ++icol) + for (int icol = 0; icol < (int) columnNames.size(); ++icol) if (keyword_user[icol].size()) columnNames[icol] = keyword_user[icol]; // setup function ptrs @@ -296,7 +296,7 @@ void DumpAtomADIOS::init_style() int *boundaryptr = reinterpret_cast(domain->boundary); internal->io.DefineAttribute("boundary", boundaryptr, 6); - auto nColumns = static_cast(size_one); + auto nColumns = static_cast(size_one); internal->io.DefineAttribute("columns", columnNames.data(), nColumns); internal->io.DefineAttribute("columnstr", columns); internal->io.DefineAttribute("boundarystr", boundstr); diff --git a/src/ADIOS/dump_custom_adios.cpp b/src/ADIOS/dump_custom_adios.cpp index 40d06c15d8..5249021ed4 100644 --- a/src/ADIOS/dump_custom_adios.cpp +++ b/src/ADIOS/dump_custom_adios.cpp @@ -146,10 +146,10 @@ void DumpCustomADIOS::write() // Now we know the global size and the local subset size and offset // of the atoms table - auto nAtomsGlobal = static_cast(ntotal); - auto startRow = static_cast(atomOffset); - auto nAtomsLocal = static_cast(nme); - auto nColumns = static_cast(size_one); + auto nAtomsGlobal = static_cast(ntotal); + auto startRow = static_cast(atomOffset); + auto nAtomsLocal = static_cast(nme); + auto nColumns = static_cast(size_one); internal->varAtoms.SetShape({nAtomsGlobal, nColumns}); internal->varAtoms.SetSelection({{startRow, 0}, {nAtomsLocal, nColumns}}); @@ -221,8 +221,10 @@ void DumpCustomADIOS::init_style() int icol = 0; for (auto item : utils::split_words(columns_default)) { if (combined.size()) combined += " "; - if (keyword_user[icol].size()) combined += keyword_user[icol]; - else combined += item; + if (keyword_user[icol].size()) + combined += keyword_user[icol]; + else + combined += item; ++icol; } columns = utils::strdup(combined); @@ -249,34 +251,30 @@ void DumpCustomADIOS::init_style() */ // find current ptr for each compute,fix,variable // check that fix frequency is acceptable - int icompute; for (int i = 0; i < ncompute; i++) { - icompute = modify->find_compute(id_compute[i]); - if (icompute < 0) error->all(FLERR, "Could not find dump custom compute ID"); - compute[i] = modify->compute[icompute]; + compute[i] = modify->get_compute_by_id(id_compute[i]); + if (!compute[i]) + error->all(FLERR, "Could not find dump custom/adios compute ID {}", id_compute[i]); } - int ifix; for (int i = 0; i < nfix; i++) { - ifix = modify->find_fix(id_fix[i]); - if (ifix < 0) error->all(FLERR, "Could not find dump custom fix ID"); - fix[i] = modify->fix[ifix]; - if (nevery % modify->fix[ifix]->peratom_freq) - error->all(FLERR, "Dump custom and fix not computed at compatible times"); + fix[i] = modify->get_fix_by_id(id_fix[i]); + if (!fix[i]) error->all(FLERR, "Could not find dump custom/adios fix ID {}", id_fix[i]); + if (nevery % fix[i]->peratom_freq) + error->all(FLERR, "dump custom/adios and fix {} with ID {} not computed at compatible times", + fix[i]->style, id_fix[i]); } int ivariable; for (int i = 0; i < nvariable; i++) { ivariable = input->variable->find(id_variable[i]); - if (ivariable < 0) error->all(FLERR, "Could not find dump custom variable name"); + if (ivariable < 0) error->all(FLERR, "Could not find dump custom/adios variable name"); variable[i] = ivariable; } // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) error->all(FLERR, "Region ID for dump custom does not exist"); - } + if (idregion && !domain->find_region(idregion)) + error->all(FLERR, "Region {} for dump custom/adios does not exist", idregion); /* Define the group of variables for the atom style here since it's a fixed * set */ @@ -316,7 +314,7 @@ void DumpCustomADIOS::init_style() int *boundaryptr = reinterpret_cast(domain->boundary); internal->io.DefineAttribute("boundary", boundaryptr, 6); - auto nColumns = static_cast(size_one); + auto nColumns = static_cast(size_one); internal->io.DefineAttribute("columns", internal->columnNames.data(), nColumns); internal->io.DefineAttribute("columnstr", columns); internal->io.DefineAttribute("boundarystr", boundstr); diff --git a/src/ADIOS/reader_adios.cpp b/src/ADIOS/reader_adios.cpp index 893346ec71..37179c1221 100644 --- a/src/ADIOS/reader_adios.cpp +++ b/src/ADIOS/reader_adios.cpp @@ -221,7 +221,7 @@ bigint ReaderADIOS::read_header(double box[3][3], int &boxinfo, int &triclinic, uint64_t rem = nAtomsTotal % comm->nprocs; nAtoms = nAtomsTotal / comm->nprocs; atomOffset = comm->me * nAtoms; - if (comm->me < (int)rem) { + if (comm->me < (int) rem) { ++nAtoms; atomOffset += comm->me; } else { @@ -421,7 +421,7 @@ void ReaderADIOS::read_atoms(int n, int nfield, double **fields) adios2::Variable varAtoms = internal->io.InquireVariable("atoms"); - if ((uint64_t)n != nAtoms) + if ((uint64_t) n != nAtoms) error->one(FLERR, "ReaderADIOS::read_atoms() expects 'n={}' equal to the number of " "atoms (={}) for process {} in ADIOS file {}.", diff --git a/src/ADIOS/reader_adios.h b/src/ADIOS/reader_adios.h index 06616d94fd..18748a8584 100644 --- a/src/ADIOS/reader_adios.h +++ b/src/ADIOS/reader_adios.h @@ -40,8 +40,8 @@ class ReaderADIOS : public Reader { int read_time(bigint &) override; void skip() override; - bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, - int &, int &, int &) override; + bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, int &, + int &, int &) override; void read_atoms(int, int, double **) override; void open_file(const std::string &) override; diff --git a/src/ASPHERE/pair_resquared.cpp b/src/ASPHERE/pair_resquared.cpp index de0771a8e7..473489632a 100644 --- a/src/ASPHERE/pair_resquared.cpp +++ b/src/ASPHERE/pair_resquared.cpp @@ -317,10 +317,10 @@ void PairRESquared::coeff(int narg, char **arg) void PairRESquared::init_style() { - avec = dynamic_cast( atom->style_match("ellipsoid")); + avec = dynamic_cast(atom->style_match("ellipsoid")); if (!avec) error->all(FLERR, "Pair resquared requires atom style ellipsoid"); - neighbor->add_request(this,NeighConst::REQ_DEFAULT); + neighbor->add_request(this, NeighConst::REQ_DEFAULT); // per-type shape precalculations // require that atom shapes are identical within each type diff --git a/src/BOCS/fix_bocs.h b/src/BOCS/fix_bocs.h index ee5c70e432..6e567f1dac 100644 --- a/src/BOCS/fix_bocs.h +++ b/src/BOCS/fix_bocs.h @@ -30,7 +30,7 @@ namespace LAMMPS_NS { class FixBocs : public Fix { public: FixBocs(class LAMMPS *, int, char **); // MRD NJD - ~FixBocs() override; // MRD NJD + ~FixBocs() override; // MRD NJD int setmask() override; void init() override; void setup(int) override; diff --git a/src/BPM/bond_bpm_spring.cpp b/src/BPM/bond_bpm_spring.cpp index e2cbe5949e..d5935f612c 100644 --- a/src/BPM/bond_bpm_spring.cpp +++ b/src/BPM/bond_bpm_spring.cpp @@ -29,7 +29,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -BondBPMSpring::BondBPMSpring(LAMMPS *_lmp) : BondBPM(_lmp), k(nullptr), ecrit(nullptr), gamma(nullptr) +BondBPMSpring::BondBPMSpring(LAMMPS *_lmp) : + BondBPM(_lmp), k(nullptr), ecrit(nullptr), gamma(nullptr) { partial_flag = 1; smooth_flag = 1; diff --git a/src/BROWNIAN/fix_brownian_asphere.cpp b/src/BROWNIAN/fix_brownian_asphere.cpp index d25123aa54..18321cdafd 100644 --- a/src/BROWNIAN/fix_brownian_asphere.cpp +++ b/src/BROWNIAN/fix_brownian_asphere.cpp @@ -56,7 +56,7 @@ FixBrownianAsphere::FixBrownianAsphere(LAMMPS *lmp, int narg, char **arg) : void FixBrownianAsphere::init() { - avec = dynamic_cast( atom->style_match("ellipsoid")); + avec = dynamic_cast(atom->style_match("ellipsoid")); if (!avec) error->all(FLERR, "Compute brownian/asphere requires atom style ellipsoid"); // check that all particles are finite-size ellipsoids diff --git a/src/BROWNIAN/fix_brownian_base.h b/src/BROWNIAN/fix_brownian_base.h index cc8234f080..23a36b48bf 100644 --- a/src/BROWNIAN/fix_brownian_base.h +++ b/src/BROWNIAN/fix_brownian_base.h @@ -48,9 +48,9 @@ class FixBrownianBase : public Fix { int noise_flag; // 0/1 for noise off/on int gaussian_noise_flag; // 0/1 for uniform/gaussian noise - double temp; // temperature - double rot_temp; // temperature - double g1, g2; // prefactors in time stepping + double temp; // temperature + double rot_temp; // temperature + double g1, g2; // prefactors in time stepping class RanMars *rng; }; diff --git a/src/BROWNIAN/fix_propel_self.cpp b/src/BROWNIAN/fix_propel_self.cpp index 4df10f9ef4..55fce754a6 100644 --- a/src/BROWNIAN/fix_propel_self.cpp +++ b/src/BROWNIAN/fix_propel_self.cpp @@ -100,7 +100,7 @@ void FixPropelSelf::init() error->all(FLERR, "Fix propel/self requires atom attribute mu with option dipole"); if (mode == QUAT) { - avec = dynamic_cast( atom->style_match("ellipsoid")); + avec = dynamic_cast(atom->style_match("ellipsoid")); if (!avec) error->all(FLERR, "Fix propel/self requires atom style ellipsoid with option quat"); // check that all particles are finite-size ellipsoids diff --git a/src/CG-DNA/bond_oxdna_fene.cpp b/src/CG-DNA/bond_oxdna_fene.cpp index 58b127c63c..acaa26b7e1 100644 --- a/src/CG-DNA/bond_oxdna_fene.cpp +++ b/src/CG-DNA/bond_oxdna_fene.cpp @@ -145,16 +145,16 @@ void BondOxdnaFene::ev_tally_xyz(int i, int j, int nlocal, int newton_bond, doub ------------------------------------------------------------------------- */ void BondOxdnaFene::compute(int eflag, int vflag) { - int a,b,in,type; - double delf[3],delta[3],deltb[3]; // force, torque increment;; - double delr[3],ebond,fbond; - double rsq,Deltasq,rlogarg; - double r,rr0,rr0sq; + int a, b, in, type; + double delf[3], delta[3], deltb[3]; // force, torque increment;; + double delr[3], ebond, fbond; + double rsq, Deltasq, rlogarg; + double r, rr0, rr0sq; // vectors COM-backbone site in lab frame - double ra_cs[3],rb_cs[3]; + double ra_cs[3], rb_cs[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3], ay[3], az[3]; + double bx[3], by[3], bz[3]; double **x = atom->x; double **f = atom->f; @@ -170,9 +170,9 @@ void BondOxdnaFene::compute(int eflag, int vflag) // n(x/y/z)_xtrct = extracted local unit vectors in lab frame from oxdna_excv int dim; - nx_xtrct = (double **) force->pair->extract("nx",dim); - ny_xtrct = (double **) force->pair->extract("ny",dim); - nz_xtrct = (double **) force->pair->extract("nz",dim); + nx_xtrct = (double **) force->pair->extract("nx", dim); + ny_xtrct = (double **) force->pair->extract("ny", dim); + nz_xtrct = (double **) force->pair->extract("nz", dim); // loop over FENE bonds diff --git a/src/CG-DNA/bond_oxdna_fene.h b/src/CG-DNA/bond_oxdna_fene.h index d2aa84612a..178072f5f5 100644 --- a/src/CG-DNA/bond_oxdna_fene.h +++ b/src/CG-DNA/bond_oxdna_fene.h @@ -39,8 +39,8 @@ class BondOxdnaFene : public Bond { double single(int, double, int, int, double &) override; protected: - double *k, *Delta, *r0; // FENE - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double *k, *Delta, *r0; // FENE + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors void allocate(); void ev_tally_xyz(int, int, int, int, double, double, double, double, double, double, double); diff --git a/src/CG-DNA/pair_oxdna2_coaxstk.h b/src/CG-DNA/pair_oxdna2_coaxstk.h index 6bf763a1fe..6e6eceafa1 100644 --- a/src/CG-DNA/pair_oxdna2_coaxstk.h +++ b/src/CG-DNA/pair_oxdna2_coaxstk.h @@ -55,7 +55,7 @@ class PairOxdna2Coaxstk : public Pair { double **a_cxst6, **theta_cxst6_0, **dtheta_cxst6_ast; double **b_cxst6, **dtheta_cxst6_c; double **AA_cxst1, **BB_cxst1; - double **nx_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CG-DNA/pair_oxdna2_dh.h b/src/CG-DNA/pair_oxdna2_dh.h index db37ba0d43..7a6fd7b4ea 100644 --- a/src/CG-DNA/pair_oxdna2_dh.h +++ b/src/CG-DNA/pair_oxdna2_dh.h @@ -45,7 +45,7 @@ class PairOxdna2Dh : public Pair { protected: double **qeff_dh_pf, **kappa_dh; double **b_dh, **cut_dh_ast, **cutsq_dh_ast, **cut_dh_c, **cutsq_dh_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CG-DNA/pair_oxdna_coaxstk.h b/src/CG-DNA/pair_oxdna_coaxstk.h index 62ffb7f2c1..2fbd181dcc 100644 --- a/src/CG-DNA/pair_oxdna_coaxstk.h +++ b/src/CG-DNA/pair_oxdna_coaxstk.h @@ -57,7 +57,7 @@ class PairOxdnaCoaxstk : public Pair { double **b_cxst6, **dtheta_cxst6_c; double **a_cxst3p, **cosphi_cxst3p_ast, **b_cxst3p, **cosphi_cxst3p_c; double **a_cxst4p, **cosphi_cxst4p_ast, **b_cxst4p, **cosphi_cxst4p_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CG-DNA/pair_oxdna_excv.h b/src/CG-DNA/pair_oxdna_excv.h index a255c954bb..23ffcfde7a 100644 --- a/src/CG-DNA/pair_oxdna_excv.h +++ b/src/CG-DNA/pair_oxdna_excv.h @@ -54,7 +54,7 @@ class PairOxdnaExcv : public Pair { double **lj1_sb, **lj2_sb, **b_sb, **cut_sb_c, **cutsq_sb_c; double **epsilon_bb, **sigma_bb, **cut_bb_ast, **cutsq_bb_ast; double **lj1_bb, **lj2_bb, **b_bb, **cut_bb_c, **cutsq_bb_c; - double **nx, **ny, **nz; // per-atom arrays for local unit vectors + double **nx, **ny, **nz; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CG-DNA/pair_oxdna_hbond.h b/src/CG-DNA/pair_oxdna_hbond.h index 32120a79cf..4a6ab214aa 100644 --- a/src/CG-DNA/pair_oxdna_hbond.h +++ b/src/CG-DNA/pair_oxdna_hbond.h @@ -60,7 +60,7 @@ class PairOxdnaHbond : public Pair { double **b_hb7, **dtheta_hb7_c; double **a_hb8, **theta_hb8_0, **dtheta_hb8_ast; double **b_hb8, **dtheta_hb8_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors int seqdepflag; virtual void allocate(); diff --git a/src/CG-DNA/pair_oxdna_stk.h b/src/CG-DNA/pair_oxdna_stk.h index 5e9329ea57..346fa91abe 100644 --- a/src/CG-DNA/pair_oxdna_stk.h +++ b/src/CG-DNA/pair_oxdna_stk.h @@ -59,7 +59,7 @@ class PairOxdnaStk : public Pair { double **b_st6, **dtheta_st6_c; double **a_st1, **cosphi_st1_ast, **b_st1, **cosphi_st1_c; double **a_st2, **cosphi_st2_ast, **b_st2, **cosphi_st2_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors int seqdepflag; virtual void allocate(); diff --git a/src/CG-DNA/pair_oxdna_xstk.h b/src/CG-DNA/pair_oxdna_xstk.h index 8d0a126943..8e8e35e506 100644 --- a/src/CG-DNA/pair_oxdna_xstk.h +++ b/src/CG-DNA/pair_oxdna_xstk.h @@ -59,7 +59,7 @@ class PairOxdnaXstk : public Pair { double **b_xst7, **dtheta_xst7_c; double **a_xst8, **theta_xst8_0, **dtheta_xst8_ast; double **b_xst8, **dtheta_xst8_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CG-DNA/pair_oxrna2_stk.h b/src/CG-DNA/pair_oxrna2_stk.h index 8530544fdc..7f5d861296 100644 --- a/src/CG-DNA/pair_oxrna2_stk.h +++ b/src/CG-DNA/pair_oxrna2_stk.h @@ -60,7 +60,7 @@ class PairOxrna2Stk : public Pair { double **b_st10, **dtheta_st10_c; double **a_st1, **cosphi_st1_ast, **b_st1, **cosphi_st1_c; double **a_st2, **cosphi_st2_ast, **b_st2, **cosphi_st2_c; - double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **ny_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors int seqdepflag; virtual void allocate(); diff --git a/src/CG-DNA/pair_oxrna2_xstk.h b/src/CG-DNA/pair_oxrna2_xstk.h index c73839b4a7..3f8ce07862 100644 --- a/src/CG-DNA/pair_oxrna2_xstk.h +++ b/src/CG-DNA/pair_oxrna2_xstk.h @@ -56,7 +56,7 @@ class PairOxrna2Xstk : public Pair { double **b_xst7, **dtheta_xst7_c; double **a_xst8, **theta_xst8_0, **dtheta_xst8_ast; double **b_xst8, **dtheta_xst8_c; - double **nx_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors + double **nx_xtrct, **nz_xtrct; // per-atom arrays for local unit vectors virtual void allocate(); }; diff --git a/src/CLASS2/pair_lj_class2.cpp b/src/CLASS2/pair_lj_class2.cpp index 0278e5c682..f86ba3b035 100644 --- a/src/CLASS2/pair_lj_class2.cpp +++ b/src/CLASS2/pair_lj_class2.cpp @@ -484,7 +484,7 @@ void PairLJClass2::init_style() int list_style = NeighConst::REQ_DEFAULT; if (update->whichflag == 1 && utils::strmatch(update->integrate_style, "^respa")) { - auto respa = dynamic_cast( update->integrate); + auto respa = dynamic_cast(update->integrate); if (respa->level_inner >= 0) list_style = NeighConst::REQ_RESPA_INOUT; if (respa->level_middle >= 0) list_style = NeighConst::REQ_RESPA_ALL; } @@ -493,8 +493,8 @@ void PairLJClass2::init_style() // set rRESPA cutoffs if (utils::strmatch(update->integrate_style, "^respa") && - (dynamic_cast( update->integrate))->level_inner >= 0) - cut_respa = (dynamic_cast( update->integrate))->cutoff; + (dynamic_cast(update->integrate))->level_inner >= 0) + cut_respa = (dynamic_cast(update->integrate))->cutoff; else cut_respa = nullptr; } diff --git a/src/CLASS2/pair_lj_class2_coul_long.cpp b/src/CLASS2/pair_lj_class2_coul_long.cpp index d75c7dea9c..03b1378920 100644 --- a/src/CLASS2/pair_lj_class2_coul_long.cpp +++ b/src/CLASS2/pair_lj_class2_coul_long.cpp @@ -672,7 +672,7 @@ void PairLJClass2CoulLong::init_style() int list_style = NeighConst::REQ_DEFAULT; if (update->whichflag == 1 && utils::strmatch(update->integrate_style, "^respa")) { - auto respa = dynamic_cast( update->integrate); + auto respa = dynamic_cast(update->integrate); if (respa->level_inner >= 0) list_style = NeighConst::REQ_RESPA_INOUT; if (respa->level_middle >= 0) list_style = NeighConst::REQ_RESPA_ALL; } @@ -683,8 +683,8 @@ void PairLJClass2CoulLong::init_style() // set rRESPA cutoffs if (utils::strmatch(update->integrate_style, "^respa") && - (dynamic_cast( update->integrate))->level_inner >= 0) - cut_respa = (dynamic_cast( update->integrate))->cutoff; + (dynamic_cast(update->integrate))->level_inner >= 0) + cut_respa = (dynamic_cast(update->integrate))->cutoff; else cut_respa = nullptr; diff --git a/src/COLLOID/pair_brownian.cpp b/src/COLLOID/pair_brownian.cpp index 496d7cdee7..12362dab6f 100644 --- a/src/COLLOID/pair_brownian.cpp +++ b/src/COLLOID/pair_brownian.cpp @@ -494,7 +494,7 @@ void PairBrownian::init_style() else if (strstr(modify->fix[i]->style, "wall") != nullptr) { if (flagwall) error->all(FLERR, "Cannot use multiple fix wall commands with pair brownian"); flagwall = 1; // Walls exist - wallfix = dynamic_cast( modify->fix[i]); + wallfix = dynamic_cast(modify->fix[i]); if (wallfix->xflag) flagwall = 2; // Moving walls exist } } diff --git a/src/COLVARS/colvarproxy_lammps.h b/src/COLVARS/colvarproxy_lammps.h index 5dbbe8fcfe..579e645054 100644 --- a/src/COLVARS/colvarproxy_lammps.h +++ b/src/COLVARS/colvarproxy_lammps.h @@ -101,7 +101,8 @@ class colvarproxy_lammps : public colvarproxy { void log(std::string const &message) override; void error(std::string const &message) override; - cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const override; + cvm::rvector position_distance(cvm::atom_pos const &pos1, + cvm::atom_pos const &pos2) const override; int backup_file(char const *filename) override; diff --git a/src/COMPRESS/dump_cfg_gz.cpp b/src/COMPRESS/dump_cfg_gz.cpp index 3b2f10ddb0..43b24d7bdb 100644 --- a/src/COMPRESS/dump_cfg_gz.cpp +++ b/src/COMPRESS/dump_cfg_gz.cpp @@ -91,8 +91,10 @@ void DumpCFGGZ::write_header(bigint n) // so molecules are not split across periodic box boundaries double scale = 1.0; - if (atom->peri_flag) scale = atom->pdscale; - else if (unwrapflag == 1) scale = UNWRAPEXPAND; + if (atom->peri_flag) + scale = atom->pdscale; + else if (unwrapflag == 1) + scale = UNWRAPEXPAND; std::string header = fmt::format("Number of particles = {}\n", n); header += fmt::format("A = {:g} Angstrom (basic length-scale)\n", scale); diff --git a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp index 1914693221..ba27589a70 100644 --- a/src/DIELECTRIC/fix_polarize_bem_gmres.cpp +++ b/src/DIELECTRIC/fix_polarize_bem_gmres.cpp @@ -66,12 +66,12 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ FixPolarizeBEMGMRES::FixPolarizeBEMGMRES(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), q_backup(nullptr), c(nullptr), g(nullptr), h(nullptr), r(nullptr), s(nullptr), v(nullptr), - y(nullptr) + Fix(lmp, narg, arg), q_backup(nullptr), c(nullptr), g(nullptr), h(nullptr), r(nullptr), + s(nullptr), v(nullptr), y(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix polarize/bem/gmres command"); - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Fix polarize requires atom style dielectric"); // parse required arguments @@ -248,28 +248,28 @@ void FixPolarizeBEMGMRES::setup(int /*vflag*/) // check if the pair styles in use are compatible if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/msm/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else error->all(FLERR, "Pair style not compatible with fix polarize"); if (kspaceflag) { if (force->kspace) { if (strcmp(force->kspace_style, "pppm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else if (strcmp(force->kspace_style, "msm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else error->all(FLERR, "Kspace style not compatible with fix polarize/bem/gmres"); } else diff --git a/src/DIELECTRIC/fix_polarize_bem_icc.cpp b/src/DIELECTRIC/fix_polarize_bem_icc.cpp index 1a36518b1c..adabbb7f14 100644 --- a/src/DIELECTRIC/fix_polarize_bem_icc.cpp +++ b/src/DIELECTRIC/fix_polarize_bem_icc.cpp @@ -58,7 +58,7 @@ FixPolarizeBEMICC::FixPolarizeBEMICC(LAMMPS *lmp, int narg, char **arg) : Fix(lm { if (narg < 5) error->all(FLERR, "Illegal fix polarize/bem/icc command"); - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Fix polarize requires atom style dielectric"); // parse required arguments @@ -146,19 +146,19 @@ void FixPolarizeBEMICC::setup(int /*vflag*/) // check if the pair styles in use are compatible if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/msm/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else error->all(FLERR, "Pair style not compatible with fix polarize/bem/icc"); @@ -168,9 +168,9 @@ void FixPolarizeBEMICC::setup(int /*vflag*/) kspaceflag = 1; if (strcmp(force->kspace_style, "pppm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else if (strcmp(force->kspace_style, "msm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else error->all(FLERR, "Kspace style not compatible with fix polarize/bem/icc"); diff --git a/src/DIELECTRIC/fix_polarize_functional.cpp b/src/DIELECTRIC/fix_polarize_functional.cpp index 971ae3e98b..dd9eb67443 100644 --- a/src/DIELECTRIC/fix_polarize_functional.cpp +++ b/src/DIELECTRIC/fix_polarize_functional.cpp @@ -71,7 +71,7 @@ FixPolarizeFunctional::FixPolarizeFunctional(LAMMPS *lmp, int narg, char **arg) { if (narg < 4) error->all(FLERR, "Illegal fix polarize/functional command"); - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Fix polarize/functional requires atom style dielectric"); nevery = utils::inumeric(FLERR, arg[3], false, lmp); @@ -290,19 +290,19 @@ void FixPolarizeFunctional::setup(int /*vflag*/) // check if the pair styles in use are compatible if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/long/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/msm/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "lj/cut/coul/cut/dielectric/omp") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/long/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else if (strcmp(force->pair_style, "coul/cut/dielectric") == 0) - efield_pair = (dynamic_cast( force->pair))->efield; + efield_pair = (dynamic_cast(force->pair))->efield; else error->all(FLERR, "Pair style not compatible with fix polarize/functional"); @@ -310,9 +310,9 @@ void FixPolarizeFunctional::setup(int /*vflag*/) kspaceflag = 1; if (strcmp(force->kspace_style, "pppm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else if (strcmp(force->kspace_style, "msm/dielectric") == 0) - efield_kspace = (dynamic_cast( force->kspace))->efield; + efield_kspace = (dynamic_cast(force->kspace))->efield; else error->all(FLERR, "Kspace style not compatible with fix polarize/functional"); diff --git a/src/DIELECTRIC/pair_coul_cut_dielectric.cpp b/src/DIELECTRIC/pair_coul_cut_dielectric.cpp index dc1b2041d7..5e50558dc8 100644 --- a/src/DIELECTRIC/pair_coul_cut_dielectric.cpp +++ b/src/DIELECTRIC/pair_coul_cut_dielectric.cpp @@ -162,7 +162,7 @@ void PairCoulCutDielectric::compute(int eflag, int vflag) void PairCoulCutDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair coul/cut/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_coul_long_dielectric.cpp b/src/DIELECTRIC/pair_coul_long_dielectric.cpp index c8e5424a92..77b32ebf37 100644 --- a/src/DIELECTRIC/pair_coul_long_dielectric.cpp +++ b/src/DIELECTRIC/pair_coul_long_dielectric.cpp @@ -207,7 +207,7 @@ void PairCoulLongDielectric::compute(int eflag, int vflag) void PairCoulLongDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair coul/long/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_lj_cut_coul_cut_dielectric.cpp b/src/DIELECTRIC/pair_lj_cut_coul_cut_dielectric.cpp index ee95c1c2f5..8c3b34c74c 100644 --- a/src/DIELECTRIC/pair_lj_cut_coul_cut_dielectric.cpp +++ b/src/DIELECTRIC/pair_lj_cut_coul_cut_dielectric.cpp @@ -190,7 +190,7 @@ void PairLJCutCoulCutDielectric::compute(int eflag, int vflag) void PairLJCutCoulCutDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair lj/cut/coul/cut/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_lj_cut_coul_debye_dielectric.cpp b/src/DIELECTRIC/pair_lj_cut_coul_debye_dielectric.cpp index f9efd30ec1..ea0fd06720 100644 --- a/src/DIELECTRIC/pair_lj_cut_coul_debye_dielectric.cpp +++ b/src/DIELECTRIC/pair_lj_cut_coul_debye_dielectric.cpp @@ -194,7 +194,7 @@ void PairLJCutCoulDebyeDielectric::compute(int eflag, int vflag) void PairLJCutCoulDebyeDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair lj/cut/coul/debye/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_lj_cut_coul_long_dielectric.cpp b/src/DIELECTRIC/pair_lj_cut_coul_long_dielectric.cpp index 823c7de50f..6d22d8fc4a 100644 --- a/src/DIELECTRIC/pair_lj_cut_coul_long_dielectric.cpp +++ b/src/DIELECTRIC/pair_lj_cut_coul_long_dielectric.cpp @@ -244,7 +244,7 @@ void PairLJCutCoulLongDielectric::compute(int eflag, int vflag) void PairLJCutCoulLongDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair lj/cut/coul/long/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_lj_cut_coul_msm_dielectric.cpp b/src/DIELECTRIC/pair_lj_cut_coul_msm_dielectric.cpp index 4dffd81aa3..db24ed4444 100644 --- a/src/DIELECTRIC/pair_lj_cut_coul_msm_dielectric.cpp +++ b/src/DIELECTRIC/pair_lj_cut_coul_msm_dielectric.cpp @@ -352,7 +352,7 @@ double PairLJCutCoulMSMDielectric::single(int i, int j, int itype, int jtype, do void PairLJCutCoulMSMDielectric::init_style() { - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair lj/cut/coul/msm/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIELECTRIC/pair_lj_long_coul_long_dielectric.cpp b/src/DIELECTRIC/pair_lj_long_coul_long_dielectric.cpp index 0f72238e63..e9b32ce150 100644 --- a/src/DIELECTRIC/pair_lj_long_coul_long_dielectric.cpp +++ b/src/DIELECTRIC/pair_lj_long_coul_long_dielectric.cpp @@ -71,7 +71,7 @@ void PairLJLongCoulLongDielectric::init_style() { PairLJLongCoulLong::init_style(); - avec = dynamic_cast( atom->style_match("dielectric")); + avec = dynamic_cast(atom->style_match("dielectric")); if (!avec) error->all(FLERR, "Pair lj/long/coul/long/dielectric requires atom style dielectric"); neighbor->add_request(this, NeighConst::REQ_FULL); diff --git a/src/DIPOLE/pair_lj_sf_dipole_sf.h b/src/DIPOLE/pair_lj_sf_dipole_sf.h index 809d352472..783ec00ad8 100644 --- a/src/DIPOLE/pair_lj_sf_dipole_sf.h +++ b/src/DIPOLE/pair_lj_sf_dipole_sf.h @@ -26,7 +26,7 @@ namespace LAMMPS_NS { class PairLJSFDipoleSF : public Pair { public: - PairLJSFDipoleSF(class LAMMPS *_lmp) : Pair(_lmp) {}; + PairLJSFDipoleSF(class LAMMPS *_lmp) : Pair(_lmp){}; ~PairLJSFDipoleSF() override; void compute(int, int) override; void settings(int, char **) override; diff --git a/src/DRUDE/fix_drude_transform.h b/src/DRUDE/fix_drude_transform.h index cfe159c236..28c2aa0643 100644 --- a/src/DRUDE/fix_drude_transform.h +++ b/src/DRUDE/fix_drude_transform.h @@ -25,7 +25,7 @@ FixStyle(drude/transform/inverse,FixDrudeTransform); namespace LAMMPS_NS { -template class FixDrudeTransform: public Fix { +template class FixDrudeTransform : public Fix { public: FixDrudeTransform(class LAMMPS *, int, char **); ~FixDrudeTransform() override; diff --git a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp index d65b5b1d38..07803aca20 100644 --- a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp @@ -30,14 +30,12 @@ using namespace LAMMPS_NS; using namespace MathConst; - /* ---------------------------------------------------------------------- */ ComputeAveSphereAtom::ComputeAveSphereAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - result(nullptr) + Compute(lmp, narg, arg), result(nullptr) { - if (narg < 3 || narg > 5) error->all(FLERR,"Illegal compute ave/sphere/atom command"); + if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute ave/sphere/atom command"); // process optional args @@ -45,12 +43,13 @@ ComputeAveSphereAtom::ComputeAveSphereAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = 3; while (iarg < narg) { - if (strcmp(arg[iarg],"cutoff") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute ave/sphere/atom command"); - cutoff = utils::numeric(FLERR,arg[iarg+1],false,lmp); - if (cutoff <= 0.0) error->all(FLERR,"Illegal compute ave/sphere/atom command"); + if (strcmp(arg[iarg], "cutoff") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute ave/sphere/atom command"); + cutoff = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + if (cutoff <= 0.0) error->all(FLERR, "Illegal compute ave/sphere/atom command"); iarg += 2; - } else error->all(FLERR,"Illegal compute ave/sphere/atom command"); + } else + error->all(FLERR, "Illegal compute ave/sphere/atom command"); } peratom_flag = 1; @@ -74,32 +73,32 @@ ComputeAveSphereAtom::~ComputeAveSphereAtom() void ComputeAveSphereAtom::init() { if (!force->pair && cutoff == 0.0) - error->all(FLERR,"Compute ave/sphere/atom requires a cutoff be specified " + error->all(FLERR, + "Compute ave/sphere/atom requires a cutoff be specified " "or a pair style be defined"); double skin = neighbor->skin; if (cutoff != 0.0) { - double cutghost; // as computed by Neighbor and Comm + double cutghost; // as computed by Neighbor and Comm if (force->pair) - cutghost = MAX(force->pair->cutforce+skin,comm->cutghostuser); + cutghost = MAX(force->pair->cutforce + skin, comm->cutghostuser); else cutghost = comm->cutghostuser; if (cutoff > cutghost) - error->all(FLERR,"Compute ave/sphere/atom cutoff exceeds ghost atom range - " + error->all(FLERR, + "Compute ave/sphere/atom cutoff exceeds ghost atom range - " "use comm_modify cutoff command"); } int cutflag = 1; if (force->pair) { - if (cutoff == 0.0) { - cutoff = force->pair->cutforce; - } - if (cutoff <= force->pair->cutforce+skin) cutflag = 0; + if (cutoff == 0.0) { cutoff = force->pair->cutforce; } + if (cutoff <= force->pair->cutforce + skin) cutflag = 0; } - cutsq = cutoff*cutoff; - sphere_vol = 4.0/3.0*MY_PI*cutsq*cutoff; + cutsq = cutoff * cutoff; + sphere_vol = 4.0 / 3.0 * MY_PI * cutsq * cutoff; // need an occasional full neighbor list @@ -118,11 +117,11 @@ void ComputeAveSphereAtom::init_list(int /*id*/, NeighList *ptr) void ComputeAveSphereAtom::compute_peratom() { - int i,j,ii,jj,inum,jnum; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq; - int *ilist,*jlist,*numneigh,**firstneigh; + int i, j, ii, jj, inum, jnum; + double xtmp, ytmp, ztmp, delx, dely, delz, rsq; + int *ilist, *jlist, *numneigh, **firstneigh; int count; - double vsum[3],vavg[3],vnet[3]; + double vsum[3], vavg[3], vnet[3]; invoked_peratom = update->ntimestep; @@ -131,7 +130,7 @@ void ComputeAveSphereAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(result); nmax = atom->nmax; - memory->create(result,nmax,2,"ave/sphere/atom:result"); + memory->create(result, nmax, 2, "ave/sphere/atom:result"); array_atom = result; } @@ -179,7 +178,7 @@ void ComputeAveSphereAtom::compute_peratom() delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; + rsq = delx * delx + dely * dely + delz * delz; if (rsq < cutsq) { count++; vsum[0] += v[j][0]; @@ -188,9 +187,9 @@ void ComputeAveSphereAtom::compute_peratom() } } - vavg[0] = vsum[0]/count; - vavg[1] = vsum[1]/count; - vavg[2] = vsum[2]/count; + vavg[0] = vsum[0] / count; + vavg[1] = vsum[1] / count; + vavg[2] = vsum[2] / count; // i atom contribution @@ -198,7 +197,7 @@ void ComputeAveSphereAtom::compute_peratom() vnet[0] = v[i][0] - vavg[0]; vnet[1] = v[i][1] - vavg[1]; vnet[2] = v[i][2] - vavg[2]; - double ke_sum = vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + double ke_sum = vnet[0] * vnet[0] + vnet[1] * vnet[1] + vnet[2] * vnet[2]; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; @@ -207,17 +206,17 @@ void ComputeAveSphereAtom::compute_peratom() delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; + rsq = delx * delx + dely * dely + delz * delz; if (rsq < cutsq) { count++; vnet[0] = v[j][0] - vavg[0]; vnet[1] = v[j][1] - vavg[1]; vnet[2] = v[j][2] - vavg[2]; - ke_sum += vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + ke_sum += vnet[0] * vnet[0] + vnet[1] * vnet[1] + vnet[2] * vnet[2]; } } - double density = count/sphere_vol; - double temp = ke_sum/3.0/count; + double density = count / sphere_vol; + double temp = ke_sum / 3.0 / count; result[i][0] = density; result[i][1] = temp; } @@ -226,12 +225,12 @@ void ComputeAveSphereAtom::compute_peratom() /* ---------------------------------------------------------------------- */ -int ComputeAveSphereAtom::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) +int ComputeAveSphereAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, + int * /*pbc*/) { double **v = atom->v; - int i,m=0; + int i, m = 0; for (i = 0; i < n; ++i) { buf[m++] = v[list[i]][0]; buf[m++] = v[list[i]][1]; @@ -247,7 +246,7 @@ void ComputeAveSphereAtom::unpack_forward_comm(int n, int first, double *buf) { double **v = atom->v; - int i,last,m=0; + int i, last, m = 0; last = first + n; for (i = first; i < last; ++i) { v[i][0] = buf[m++]; @@ -262,6 +261,6 @@ void ComputeAveSphereAtom::unpack_forward_comm(int n, int first, double *buf) double ComputeAveSphereAtom::memory_usage() { - double bytes = (double)2*nmax * sizeof(double); + double bytes = (double) 2 * nmax * sizeof(double); return bytes; } diff --git a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h index 8e8ab0282d..bea4fd47d5 100644 --- a/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h +++ b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h @@ -12,9 +12,9 @@ ------------------------------------------------------------------------- */ #ifdef COMPUTE_CLASS - -ComputeStyle(ave/sphere/atom,ComputeAveSphereAtom) - +// clang-format off +ComputeStyle(ave/sphere/atom,ComputeAveSphereAtom); +// clang-format on #else #ifndef LMP_COMPUTE_AVE_SPHERE_ATOM_H @@ -37,18 +37,18 @@ class ComputeAveSphereAtom : public Compute { protected: int nmax; - double cutoff,cutsq,sphere_vol; + double cutoff, cutsq, sphere_vol; class NeighList *list; double **result; }; -} +} // namespace LAMMPS_NS #endif #endif -/* ERROR/WARNING messages: + /* ERROR/WARNING messages: E: Illegal ... command diff --git a/src/EXTRA-COMPUTE/compute_stress_cartesian.cpp b/src/EXTRA-COMPUTE/compute_stress_cartesian.cpp index 329d18901b..5a92f6c347 100644 --- a/src/EXTRA-COMPUTE/compute_stress_cartesian.cpp +++ b/src/EXTRA-COMPUTE/compute_stress_cartesian.cpp @@ -452,7 +452,8 @@ void ComputeStressCartesian::compute_pressure_1d(double fpair, double xi, double } void ComputeStressCartesian::compute_pressure_2d(double fpair, double xi, double yi, double /*xj*/, - double /*yj*/, double delx, double dely, double delz) + double /*yj*/, double delx, double dely, + double delz) { int bin1, bin2, next_bin1, next_bin2; double la = 0.0, lb = 0.0, l_sum = 0.0; diff --git a/src/EXTRA-DUMP/dump_yaml.h b/src/EXTRA-DUMP/dump_yaml.h index e9717ea0b3..08d4f42f70 100644 --- a/src/EXTRA-DUMP/dump_yaml.h +++ b/src/EXTRA-DUMP/dump_yaml.h @@ -28,7 +28,7 @@ class DumpYAML : public DumpCustom { public: DumpYAML(class LAMMPS *, int, char **); -protected: + protected: bool thermo; void init_style() override; diff --git a/src/EXTRA-DUMP/xdr_compat.h b/src/EXTRA-DUMP/xdr_compat.h index 6557a60a53..044d45ac76 100644 --- a/src/EXTRA-DUMP/xdr_compat.h +++ b/src/EXTRA-DUMP/xdr_compat.h @@ -59,8 +59,8 @@ extern "C" { typedef int bool_t; -#if defined(_WIN32) || defined(__APPLE__) || defined(__FreeBSD__) || \ - defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(_WIN32) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) typedef char *caddr_t; typedef unsigned int u_int; #endif diff --git a/src/EXTRA-FIX/fix_numdiff.cpp b/src/EXTRA-FIX/fix_numdiff.cpp index c092bd6375..472c7288ae 100644 --- a/src/EXTRA-FIX/fix_numdiff.cpp +++ b/src/EXTRA-FIX/fix_numdiff.cpp @@ -41,7 +41,8 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixNumDiff::FixNumDiff(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), temp_f(nullptr) + Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), + temp_f(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix numdiff command"); @@ -122,7 +123,7 @@ void FixNumDiff::init() kspace_compute_flag = 0; if (utils::strmatch(update->integrate_style, "^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels - 1; + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } } @@ -134,9 +135,9 @@ void FixNumDiff::setup(int vflag) if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel_respa); post_force_respa(vflag, ilevel_respa, 0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel_respa); } } diff --git a/src/EXTRA-FIX/fix_numdiff_virial.cpp b/src/EXTRA-FIX/fix_numdiff_virial.cpp index c34b3a8b1a..fa854ab3b1 100644 --- a/src/EXTRA-FIX/fix_numdiff_virial.cpp +++ b/src/EXTRA-FIX/fix_numdiff_virial.cpp @@ -132,7 +132,7 @@ void FixNumDiffVirial::init() kspace_compute_flag = 0; if (utils::strmatch(update->integrate_style, "^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels - 1; + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } } @@ -144,9 +144,9 @@ void FixNumDiffVirial::setup(int vflag) if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel_respa); post_force_respa(vflag, ilevel_respa, 0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel_respa); } } diff --git a/src/EXTRA-FIX/fix_ttm_grid.cpp b/src/EXTRA-FIX/fix_ttm_grid.cpp index 4188025525..5e6022af58 100644 --- a/src/EXTRA-FIX/fix_ttm_grid.cpp +++ b/src/EXTRA-FIX/fix_ttm_grid.cpp @@ -297,7 +297,7 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() == 0) { - ; // ignore comment only lines + ; // ignore comment only lines } else if (values.count() == 4) { ++nread; @@ -306,18 +306,18 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename) int iz = values.next_int(); if (ix < 0 || ix >= nxgrid || iy < 0 || iy >= nygrid || iz < 0 || iz >= nzgrid) - throw TokenizerException("Fix ttm/grid invalid grid index in input",""); + throw TokenizerException("Fix ttm/grid invalid grid index in input", ""); - if (ix >= nxlo_in && ix <= nxhi_in && iy >= nylo_in && iy <= nyhi_in - && iz >= nzlo_in && iz <= nzhi_in) { + if (ix >= nxlo_in && ix <= nxhi_in && iy >= nylo_in && iy <= nyhi_in && iz >= nzlo_in && + iz <= nzhi_in) { T_electron[iz][iy][ix] = values.next_double(); T_initial_set[iz][iy][ix] = 1; } } else { - throw TokenizerException("Incorrect format in fix ttm electron grid file",""); + throw TokenizerException("Incorrect format in fix ttm electron grid file", ""); } } catch (std::exception &e) { - error->one(FLERR,e.what()); + error->one(FLERR, e.what()); } } } @@ -356,9 +356,11 @@ void FixTTMGrid::write_electron_temperatures(const std::string &filename) FPout = fopen(filename.c_str(), "w"); if (!FPout) error->one(FLERR, "Fix ttm/grid could not open output file"); - fmt::print(FPout,"# DATE: {} UNITS: {} COMMENT: Electron temperature " - "{}x{}x{} grid at step {}. Created by fix {}\n", utils::current_date(), - update->unit_style, nxgrid, nygrid, nzgrid, update->ntimestep, style); + fmt::print(FPout, + "# DATE: {} UNITS: {} COMMENT: Electron temperature " + "{}x{}x{} grid at step {}. Created by fix {}\n", + utils::current_date(), update->unit_style, nxgrid, nygrid, nzgrid, update->ntimestep, + style); } gc->gather(GridComm::FIX, this, 1, sizeof(double), 1, nullptr, MPI_DOUBLE); diff --git a/src/EXTRA-FIX/fix_ttm_grid.h b/src/EXTRA-FIX/fix_ttm_grid.h index aeb1106e42..3329bbc81c 100644 --- a/src/EXTRA-FIX/fix_ttm_grid.h +++ b/src/EXTRA-FIX/fix_ttm_grid.h @@ -48,16 +48,16 @@ class FixTTMGrid : public FixTTM { double memory_usage() override; private: - int ngridmine,ngridout; - int nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in; - int nxlo_out,nxhi_out,nylo_out,nyhi_out,nzlo_out,nzhi_out; - double delxinv,delyinv,delzinv; + int ngridmine, ngridout; + int nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in; + int nxlo_out, nxhi_out, nylo_out, nyhi_out, nzlo_out, nzhi_out; + double delxinv, delyinv, delzinv; double skin_original; FILE *FPout; class GridComm *gc; - int ngc_buf1,ngc_buf2; - double *gc_buf1,*gc_buf2; + int ngc_buf1, ngc_buf2; + double *gc_buf1, *gc_buf2; void allocate_grid() override; void deallocate_grid() override; diff --git a/src/EXTRA-FIX/fix_viscous_sphere.cpp b/src/EXTRA-FIX/fix_viscous_sphere.cpp index cb5344076e..771b6f1c10 100644 --- a/src/EXTRA-FIX/fix_viscous_sphere.cpp +++ b/src/EXTRA-FIX/fix_viscous_sphere.cpp @@ -114,7 +114,7 @@ void FixViscousSphere::init() int max_respa = 0; if (utils::strmatch(update->integrate_style, "^respa")) { - ilevel_respa = max_respa = (dynamic_cast( update->integrate))->nlevels - 1; + ilevel_respa = max_respa = (dynamic_cast(update->integrate))->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, max_respa); } @@ -135,9 +135,9 @@ void FixViscousSphere::setup(int vflag) if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel_respa); post_force_respa(vflag, ilevel_respa, 0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel_respa); } } diff --git a/src/EXTRA-MOLECULE/bond_fene_nm.cpp b/src/EXTRA-MOLECULE/bond_fene_nm.cpp index 839217df78..6556ad1987 100644 --- a/src/EXTRA-MOLECULE/bond_fene_nm.cpp +++ b/src/EXTRA-MOLECULE/bond_fene_nm.cpp @@ -89,7 +89,7 @@ void BondFENENM::compute(int eflag, int vflag) fbond = -k[type] / rlogarg; // force from n-m term - if (rsq < sigma[type]*sigma[type]) { + if (rsq < sigma[type] * sigma[type]) { r = sqrt(rsq); fbond += epsilon[type] * (nn[type] * mm[type] / (nn[type] - mm[type])) * (pow(sigma[type] / r, nn[type]) - pow(sigma[type] / r, mm[type])) / rsq; @@ -99,7 +99,7 @@ void BondFENENM::compute(int eflag, int vflag) if (eflag) { ebond = -0.5 * k[type] * r0sq * log(rlogarg); - if (rsq < sigma[type]*sigma[type]) + if (rsq < sigma[type] * sigma[type]) ebond += (epsilon[type] / (nn[type] - mm[type])) * (mm[type] * pow(sigma[type] / r, nn[type]) - nn[type] * pow(sigma[type] / r, mm[type])); } @@ -257,7 +257,7 @@ double BondFENENM::single(int type, double rsq, int /*i*/, int /*j*/, double &ff double eng = -0.5 * k[type] * r0sq * log(rlogarg); fforce = -k[type] / rlogarg; - if (rsq < sigma[type]*sigma[type]) { + if (rsq < sigma[type] * sigma[type]) { r = sqrt(rsq); fforce += epsilon[type] * (nn[type] * mm[type] / (nn[type] - mm[type])) * (pow(sigma[type] / r, nn[type]) - pow(sigma[type] / r, mm[type])) / rsq; diff --git a/src/EXTRA-PAIR/pair_e3b.cpp b/src/EXTRA-PAIR/pair_e3b.cpp index f09a3bcae2..5011cc01e0 100644 --- a/src/EXTRA-PAIR/pair_e3b.cpp +++ b/src/EXTRA-PAIR/pair_e3b.cpp @@ -99,7 +99,7 @@ void PairE3B::compute(int eflag, int vflag) ev_init(eflag, vflag); //clear sumExp array - memset(sumExp, 0, sizeof(double)*maxID); + memset(sumExp, 0, sizeof(double) * maxID); evdwl = 0.0; pvector[0] = pvector[1] = pvector[2] = pvector[3] = 0.0; diff --git a/src/EXTRA-PAIR/pair_e3b.h b/src/EXTRA-PAIR/pair_e3b.h index 90fd48a8be..e887919ba6 100644 --- a/src/EXTRA-PAIR/pair_e3b.h +++ b/src/EXTRA-PAIR/pair_e3b.h @@ -49,8 +49,8 @@ class PairE3B : public Pair { int pairmax, pairPerAtom; // size of pair list int **pairO, ***pairH; // pair lists double ***exps, ****del3, ***fpair3, *sumExp; - int maxID; //size of global sumExp array - int natoms; //to make sure number of atoms is constant + int maxID; //size of global sumExp array + int natoms; //to make sure number of atoms is constant virtual void allocate(); void allocateE3B(); diff --git a/src/EXTRA-PAIR/pair_lj_smooth_linear.h b/src/EXTRA-PAIR/pair_lj_smooth_linear.h index 0b7d10ea48..dbae5aea9f 100644 --- a/src/EXTRA-PAIR/pair_lj_smooth_linear.h +++ b/src/EXTRA-PAIR/pair_lj_smooth_linear.h @@ -38,7 +38,8 @@ class PairLJSmoothLinear : public Pair { void write_restart_settings(FILE *) override; void read_restart_settings(FILE *) override; double single(int, int, int, int, double, double, double, double &) override; - double single_hessian(int, int, int, int, double, double[3], double, double, double &, double[6]) override; + double single_hessian(int, int, int, int, double, double[3], double, double, double &, + double[6]) override; protected: double cut_global; diff --git a/src/FEP/compute_fep.cpp b/src/FEP/compute_fep.cpp index f3ee1f3c4b..7a813018ad 100644 --- a/src/FEP/compute_fep.cpp +++ b/src/FEP/compute_fep.cpp @@ -213,7 +213,7 @@ void ComputeFEP::init() if ((strcmp(force->pair_style, "hybrid") == 0 || strcmp(force->pair_style, "hybrid/overlay") == 0)) { - auto pair = dynamic_cast( force->pair); + auto pair = dynamic_cast(force->pair); for (i = pert->ilo; i <= pert->ihi; i++) for (j = MAX(pert->jlo, i); j <= pert->jhi; j++) if (!pair->check_ijtype(i, j, pert->pstyle)) diff --git a/src/FEP/compute_fep_ta.h b/src/FEP/compute_fep_ta.h index b95266eb1a..d233b55b88 100644 --- a/src/FEP/compute_fep_ta.h +++ b/src/FEP/compute_fep_ta.h @@ -30,7 +30,7 @@ namespace LAMMPS_NS { class ComputeFEPTA : public Compute { public: - ComputeFEPTA(class LAMMPS *, int, char **); // compute ID groupID fep/ta temp xy/xz/yz scale_factor + ComputeFEPTA(class LAMMPS *, int, char **); ~ComputeFEPTA() override; void init() override; void compute_vector() override; diff --git a/src/GPU/gpu_extra.h b/src/GPU/gpu_extra.h index c2d9931e0a..bc8e969013 100644 --- a/src/GPU/gpu_extra.h +++ b/src/GPU/gpu_extra.h @@ -78,10 +78,12 @@ inline void check_flag(int error_flag, LAMMPS_NS::Error *error, MPI_Comm &world) else if (all_success == -13) error->all(FLERR, "Invalid device configuration."); else if (all_success == -15) - error->all(FLERR, "PPPM was compiled for double precision floating point " + error->all(FLERR, + "PPPM was compiled for double precision floating point " "but GPU device supports single precision only."); else if (all_success == -16) - error->all(FLERR, "GPU library was compiled for double or mixed precision " + error->all(FLERR, + "GPU library was compiled for double or mixed precision " "floating point but GPU device supports single precision only."); else error->all(FLERR, "Unknown error in GPU library"); diff --git a/src/GPU/pair_gayberne_gpu.cpp b/src/GPU/pair_gayberne_gpu.cpp index 80ea3af902..1d954bb66d 100644 --- a/src/GPU/pair_gayberne_gpu.cpp +++ b/src/GPU/pair_gayberne_gpu.cpp @@ -145,7 +145,7 @@ void PairGayBerneGPU::compute(int eflag, int vflag) void PairGayBerneGPU::init_style() { - avec = dynamic_cast( atom->style_match("ellipsoid")); + avec = dynamic_cast(atom->style_match("ellipsoid")); if (!avec) error->all(FLERR, "Pair gayberne/gpu requires atom style ellipsoid"); if (!atom->ellipsoid_flag) error->all(FLERR, "Pair gayberne/gpu requires atom style ellipsoid"); diff --git a/src/GPU/pair_resquared_gpu.cpp b/src/GPU/pair_resquared_gpu.cpp index 8992f615ee..2ee0da8f49 100644 --- a/src/GPU/pair_resquared_gpu.cpp +++ b/src/GPU/pair_resquared_gpu.cpp @@ -59,7 +59,7 @@ enum { SPHERE_SPHERE, SPHERE_ELLIPSE, ELLIPSE_SPHERE, ELLIPSE_ELLIPSE }; PairRESquaredGPU::PairRESquaredGPU(LAMMPS *lmp) : PairRESquared(lmp), gpu_mode(GPU_FORCE) { reinitflag = 0; - avec = dynamic_cast( atom->style_match("ellipsoid")); + avec = dynamic_cast(atom->style_match("ellipsoid")); if (!avec) error->all(FLERR, "Pair resquared/gpu requires atom style ellipsoid"); quat_nmax = 0; quat = nullptr; diff --git a/src/GRANULAR/fix_damping_cundall.cpp b/src/GRANULAR/fix_damping_cundall.cpp index 20b7de976a..6f2234d68f 100644 --- a/src/GRANULAR/fix_damping_cundall.cpp +++ b/src/GRANULAR/fix_damping_cundall.cpp @@ -115,7 +115,7 @@ void FixDampingCundall::init() int max_respa = 0; if (utils::strmatch(update->integrate_style, "^respa")) { - ilevel_respa = max_respa = (dynamic_cast( update->integrate))->nlevels - 1; + ilevel_respa = max_respa = (dynamic_cast(update->integrate))->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, max_respa); } @@ -143,9 +143,9 @@ void FixDampingCundall::setup(int vflag) if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel_respa); post_force_respa(vflag, ilevel_respa, 0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel_respa); } } diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index b231d50bcf..c43c975177 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -67,8 +67,8 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) // this is so final order of Modify:fix will conform to input script fix_history = nullptr; - fix_dummy = dynamic_cast( modify->add_fix("NEIGH_HISTORY_HH_DUMMY" + std::to_string(instance_me) + - " all DUMMY")); + fix_dummy = dynamic_cast( + modify->add_fix("NEIGH_HISTORY_HH_DUMMY" + std::to_string(instance_me) + " all DUMMY")); } /* ---------------------------------------------------------------------- */ @@ -443,8 +443,10 @@ void PairGranHookeHistory::init_style() // need a granular neighbor list - if (history) neighbor->add_request(this, NeighConst::REQ_SIZE|NeighConst::REQ_HISTORY); - else neighbor->add_request(this, NeighConst::REQ_SIZE); + if (history) + neighbor->add_request(this, NeighConst::REQ_SIZE | NeighConst::REQ_HISTORY); + else + neighbor->add_request(this, NeighConst::REQ_SIZE); dt = update->dt; @@ -454,8 +456,8 @@ void PairGranHookeHistory::init_style() if (history && (fix_history == nullptr)) { auto cmd = fmt::format("NEIGH_HISTORY_HH{} all NEIGH_HISTORY {}", instance_me, size_history); - fix_history = dynamic_cast( modify->replace_fix( - "NEIGH_HISTORY_HH_DUMMY" + std::to_string(instance_me), cmd, 1)); + fix_history = dynamic_cast( + modify->replace_fix("NEIGH_HISTORY_HH_DUMMY" + std::to_string(instance_me), cmd, 1)); fix_history->pair = this; } @@ -476,7 +478,8 @@ void PairGranHookeHistory::init_style() if (ifix->rigid_flag) { if (fix_rigid) error->all(FLERR, "Only one fix rigid command at a time allowed"); - else fix_rigid = ifix; + else + fix_rigid = ifix; } } @@ -521,8 +524,9 @@ void PairGranHookeHistory::init_style() // set fix which stores history info if (history) { - fix_history = dynamic_cast( 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"); + fix_history = dynamic_cast( + 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/INTERLAYER/pair_kolmogorov_crespi_full.cpp b/src/INTERLAYER/pair_kolmogorov_crespi_full.cpp index 3076242ee3..0c005d53a2 100644 --- a/src/INTERLAYER/pair_kolmogorov_crespi_full.cpp +++ b/src/INTERLAYER/pair_kolmogorov_crespi_full.cpp @@ -141,7 +141,8 @@ void PairKolmogorovCrespiFull::settings(int narg, char **arg) { if (narg < 1 || narg > 2) error->all(FLERR, "Illegal pair_style command"); if (!utils::strmatch(force->pair_style, "^hybrid/overlay")) - error->all(FLERR, "Pair style kolmogorov/crespi/full must be used as sub-style with hybrid/overlay"); + error->all(FLERR, + "Pair style kolmogorov/crespi/full must be used as sub-style with hybrid/overlay"); cut_global = utils::numeric(FLERR, arg[0], false, lmp); if (narg == 2) tap_flag = utils::numeric(FLERR, arg[1], false, lmp); diff --git a/src/KIM/kim_init.cpp b/src/KIM/kim_init.cpp index dae8812a60..7c3e4c2361 100644 --- a/src/KIM/kim_init.cpp +++ b/src/KIM/kim_init.cpp @@ -251,9 +251,10 @@ void KimInit::determine_model_type_and_units(char *model_name, char *user_units, return; } else if (unit_conversion_mode) { KIM_Model_Destroy(&pkim); - const char * unit_systems[] = {"metal", "real", "si", "cgs", "electron"}; + const char *unit_systems[] = {"metal", "real", "si", "cgs", "electron"}; for (auto units : unit_systems) { - get_kim_unit_names(units, lengthUnit, energyUnit, chargeUnit, temperatureUnit, timeUnit, error); + get_kim_unit_names(units, lengthUnit, energyUnit, chargeUnit, temperatureUnit, timeUnit, + error); kim_error = KIM_Model_Create(KIM_NUMBERING_zeroBased, lengthUnit, energyUnit, chargeUnit, temperatureUnit, timeUnit, model_name, &units_accepted, &pkim); if (units_accepted) { @@ -316,7 +317,7 @@ void KimInit::do_init(char *model_name, char *user_units, char *model_units, KIM modify->add_fix("KIM_MODEL_STORE all STORE/KIM"); ifix = modify->find_fix("KIM_MODEL_STORE"); - auto fix_store = dynamic_cast( modify->fix[ifix]); + auto fix_store = dynamic_cast(modify->fix[ifix]); fix_store->setptr("model_name", (void *) model_name); fix_store->setptr("user_units", (void *) user_units); fix_store->setptr("model_units", (void *) model_units); diff --git a/src/KIM/kim_init.h b/src/KIM/kim_init.h index 56922533ab..76d8f585ff 100644 --- a/src/KIM/kim_init.h +++ b/src/KIM/kim_init.h @@ -82,7 +82,7 @@ class KimInit : protected Pointers { void do_init(char *, char *, char *, KIM_Model *&); void do_variables(const std::string &, const std::string &); - void print_dirs(struct KIM_Collections * const collections) const; + void print_dirs(struct KIM_Collections *const collections) const; }; } // namespace LAMMPS_NS diff --git a/src/KOKKOS/fix_setforce_kokkos.cpp b/src/KOKKOS/fix_setforce_kokkos.cpp index a2657569c5..3b8165670e 100644 --- a/src/KOKKOS/fix_setforce_kokkos.cpp +++ b/src/KOKKOS/fix_setforce_kokkos.cpp @@ -87,9 +87,7 @@ void FixSetForceKokkos::post_force(int /*vflag*/) // update region if necessary - region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; + if (region) { region->prematch(); DAT::tdual_int_1d k_match = DAT::tdual_int_1d("setforce:k_match",nlocal); KokkosBase* regionKKBase = dynamic_cast(region); diff --git a/src/KOKKOS/fix_setforce_kokkos.h b/src/KOKKOS/fix_setforce_kokkos.h index 5260ae3421..319a0ea529 100644 --- a/src/KOKKOS/fix_setforce_kokkos.h +++ b/src/KOKKOS/fix_setforce_kokkos.h @@ -81,8 +81,6 @@ class FixSetForceKokkos : public FixSetForce { typename AT::t_x_array_randomread x; typename AT::t_f_array f; typename AT::t_int_1d_randomread mask; - - class Region* region; }; } diff --git a/src/KSPACE/fft3d_wrap.h b/src/KSPACE/fft3d_wrap.h index 351bf5713d..c1b33eefae 100644 --- a/src/KSPACE/fft3d_wrap.h +++ b/src/KSPACE/fft3d_wrap.h @@ -14,7 +14,7 @@ #ifndef LMP_FFT3D_WRAP_H #define LMP_FFT3D_WRAP_H -#include "fft3d.h" // IWYU pragma: export +#include "fft3d.h" // IWYU pragma: export #include "pointers.h" namespace LAMMPS_NS { diff --git a/src/KSPACE/pppm_disp_tip4p.h b/src/KSPACE/pppm_disp_tip4p.h index dbc3fb98aa..3d99ec12a6 100644 --- a/src/KSPACE/pppm_disp_tip4p.h +++ b/src/KSPACE/pppm_disp_tip4p.h @@ -31,8 +31,8 @@ class PPPMDispTIP4P : public PPPMDisp { void init() override; protected: - void particle_map_c(double, double, double, double, int **, int, int, int, int, int, int, - int, int) override; + void particle_map_c(double, double, double, double, int **, int, int, int, int, int, int, int, + int) override; void make_rho_c() override; void fieldforce_c_ik() override; void fieldforce_c_ad() override; diff --git a/src/LATBOLTZ/fix_lb_fluid.cpp b/src/LATBOLTZ/fix_lb_fluid.cpp index 71e689b84e..078a38a593 100644 --- a/src/LATBOLTZ/fix_lb_fluid.cpp +++ b/src/LATBOLTZ/fix_lb_fluid.cpp @@ -2387,8 +2387,8 @@ void FixLbFluid::dump(const bigint step) " \n" " \n\n", dm_lb / (dx_lb * dx_lb * dx_lb), fluid_global_n0[2], fluid_global_n0[1], - fluid_global_n0[0], sizeof(double), offset, fluid_global_n0[2], - fluid_global_n0[1], fluid_global_n0[0], dump_file_name_raw.c_str()); + fluid_global_n0[0], sizeof(double), offset, fluid_global_n0[2], fluid_global_n0[1], + fluid_global_n0[0], dump_file_name_raw.c_str()); fmt::print(dump_file_handle_xdmf, " \n" " srealloc(params,maxparam*sizeof(Param), - "pair:params"); + params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params"); // make certain all addional allocated storage is initialized // to avoid false positives when checking with valgrind - memset(params + nparams, 0, DELTA*sizeof(Param)); + memset(params + nparams, 0, DELTA * sizeof(Param)); } params[nparams].ielement = ielement; @@ -847,9 +846,9 @@ void PairEDIP::read_file(char *file) MPI_Bcast(&maxparam, 1, MPI_INT, 0, world); if (comm->me != 0) - params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params"); + params = (Param *) memory->srealloc(params, maxparam * sizeof(Param), "pair:params"); - MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world); + MPI_Bcast(params, maxparam * sizeof(Param), MPI_BYTE, 0, world); } /* ---------------------------------------------------------------------- */ diff --git a/src/MANYBODY/pair_edip.h b/src/MANYBODY/pair_edip.h index 741f428c93..9ced9fa4de 100644 --- a/src/MANYBODY/pair_edip.h +++ b/src/MANYBODY/pair_edip.h @@ -50,7 +50,7 @@ class PairEDIP : public Pair { double mu, Q0; // coefficients for function Q(Z) double u1, u2, u3, u4; // coefficients for function tau(Z) double cutsq; - int ielement, jelement, kelement, dummy; // dummy added for better alignment + int ielement, jelement, kelement, dummy; // dummy added for better alignment }; double *preInvR_ij; diff --git a/src/MANYBODY/pair_edip_multi.h b/src/MANYBODY/pair_edip_multi.h index 862c63dbec..c30d91bd38 100644 --- a/src/MANYBODY/pair_edip_multi.h +++ b/src/MANYBODY/pair_edip_multi.h @@ -50,7 +50,7 @@ class PairEDIPMulti : public Pair { double mu, Q0; // coefficients for function Q(Z) double u1, u2, u3, u4; // coefficients for function tau(Z) double cutsq; - int ielement, jelement, kelement, dummy; // dummy added for better alignment + int ielement, jelement, kelement, dummy; // dummy added for better alignment }; double *preForceCoord; diff --git a/src/MANYBODY/pair_sw.h b/src/MANYBODY/pair_sw.h index 02389020a3..459d92bc96 100644 --- a/src/MANYBODY/pair_sw.h +++ b/src/MANYBODY/pair_sw.h @@ -58,8 +58,8 @@ class PairSW : public Pair { void read_file(char *); virtual void setup_params(); void twobody(Param *, double, double &, int, double &); - virtual void threebody(Param *, Param *, Param *, double, double, double *, double *, double *, double *, - int, double &); + virtual void threebody(Param *, Param *, Param *, double, double, double *, double *, double *, + double *, int, double &); }; } // namespace LAMMPS_NS diff --git a/src/MC/fix_atom_swap.h b/src/MC/fix_atom_swap.h index 59145da84f..e66b383031 100644 --- a/src/MC/fix_atom_swap.h +++ b/src/MC/fix_atom_swap.h @@ -40,8 +40,8 @@ class FixAtomSwap : public Fix { private: int nevery, seed; - int ke_flag; // yes = conserve ke, no = do not conserve ke - int semi_grand_flag; // yes = semi-grand canonical, no = constant composition + int ke_flag; // yes = conserve ke, no = do not conserve ke + int semi_grand_flag; // yes = semi-grand canonical, no = constant composition int ncycles; int niswap, njswap; // # of i,j swap atoms on all procs int niswap_local, njswap_local; // # of swap atoms on this proc diff --git a/src/MC/fix_mol_swap.h b/src/MC/fix_mol_swap.h index 8962ea69a2..58c766cbc9 100644 --- a/src/MC/fix_mol_swap.h +++ b/src/MC/fix_mol_swap.h @@ -42,21 +42,21 @@ class FixMolSwap : public Fix { int itype, jtype; double temperature; - int ke_flag; // 1 if kinetic energy is also swapped - double i2j_vscale; // scale factors for velocity to keep KE constant + int ke_flag; // 1 if kinetic energy is also swapped + double i2j_vscale; // scale factors for velocity to keep KE constant double j2i_vscale; - int qflag; // 1 if charge is also swapped - double iq,jq; // charge values for all itype,jtype atoms + int qflag; // 1 if charge is also swapped + double iq, jq; // charge values for all itype,jtype atoms - bool unequal_cutoffs; // 1 if itype and jtype have any different cutoffs - tagint minmol,maxmol; // range of mol IDs selected for swaps + bool unequal_cutoffs; // 1 if itype and jtype have any different cutoffs + tagint minmol, maxmol; // range of mol IDs selected for swaps - double nswap_attempt; // cummulative stats on MC attempts and accepts + double nswap_attempt; // cummulative stats on MC attempts and accepts double nswap_accept; - double beta; // 1/kT - double energy_stored; // energy of current state as swaps are accepted + double beta; // 1/kT + double energy_stored; // energy of current state as swaps are accepted class RanPark *random; class Compute *c_pe; diff --git a/src/MESONT/pair_mesocnt.cpp b/src/MESONT/pair_mesocnt.cpp index 9137b19e7c..11391e71bb 100644 --- a/src/MESONT/pair_mesocnt.cpp +++ b/src/MESONT/pair_mesocnt.cpp @@ -890,8 +890,8 @@ void PairMesoCNT::read_file(const char *file) MPI_Bcast(uinf_data, uinf_points, MPI_DOUBLE, 0, world); MPI_Bcast(gamma_data, gamma_points, MPI_DOUBLE, 0, world); - MPI_Bcast(&phi_data[0][0], phi_points*phi_points, MPI_DOUBLE, 0, world); - MPI_Bcast(&usemi_data[0][0], usemi_points*usemi_points, MPI_DOUBLE, 0, world); + MPI_Bcast(&phi_data[0][0], phi_points * phi_points, MPI_DOUBLE, 0, world); + MPI_Bcast(&usemi_data[0][0], usemi_points * usemi_points, MPI_DOUBLE, 0, world); } /* ---------------------------------------------------------------------- diff --git a/src/MESONT/pair_mesocnt.h b/src/MESONT/pair_mesocnt.h index 795b27f8ff..57f28e7001 100644 --- a/src/MESONT/pair_mesocnt.h +++ b/src/MESONT/pair_mesocnt.h @@ -64,8 +64,7 @@ class PairMesoCNT : public Pair { void sort(int *, int); void read_file(const char *); void read_data(PotentialFileReader &, double *, double &, double &, int); - void read_data(PotentialFileReader &, double **, double &, double &, double &, double &, - int); + void read_data(PotentialFileReader &, double **, double &, double &, double &, double &, int); void spline_coeff(double *, double **, double, int); void spline_coeff(double **, double ****, double, double, int); diff --git a/src/MISC/pair_list.h b/src/MISC/pair_list.h index 3528ad10f8..7f0e745518 100644 --- a/src/MISC/pair_list.h +++ b/src/MISC/pair_list.h @@ -57,18 +57,18 @@ class PairList : public Pair { }; struct list_param { - int style; // potential style indicator - tagint id1, id2; // global atom ids - double cutsq; // cutoff**2 for this pair - double offset; // energy offset - union param_u param; // parameters for style + int style; // potential style indicator + tagint id1, id2; // global atom ids + double cutsq; // cutoff**2 for this pair + double offset; // energy offset + union param_u param; // parameters for style }; protected: - double cut_global; // global cutoff distance - list_param *params; // lisf of pair interaction parameters - int npairs; // # of atom pairs in global list - int check_flag; // 1 if checking for missing pairs + double cut_global; // global cutoff distance + list_param *params; // lisf of pair interaction parameters + int npairs; // # of atom pairs in global list + int check_flag; // 1 if checking for missing pairs }; } // namespace LAMMPS_NS diff --git a/src/ML-IAP/mliap_descriptor_snap.cpp b/src/ML-IAP/mliap_descriptor_snap.cpp index 7badf7b641..b2568d3a4d 100644 --- a/src/ML-IAP/mliap_descriptor_snap.cpp +++ b/src/ML-IAP/mliap_descriptor_snap.cpp @@ -416,7 +416,7 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) if ((keywd == "elems") || (keywd == "radelems") || (keywd == "welems") || (keywd == "rinnerelems") || (keywd == "drinnerelems")) { - if ((nelementsflag == 0) || ((int)words.count() != nelements + 1)) + if ((nelementsflag == 0) || ((int) words.count() != nelements + 1)) error->all(FLERR, "Incorrect SNAP parameter file"); if (comm->me == 0) utils::logmesg(lmp, "SNAP keyword {} \n", utils::trim(line)); diff --git a/src/ML-IAP/mliap_descriptor_snap.h b/src/ML-IAP/mliap_descriptor_snap.h index 2136eefc5e..0e217f82fa 100644 --- a/src/ML-IAP/mliap_descriptor_snap.h +++ b/src/ML-IAP/mliap_descriptor_snap.h @@ -42,8 +42,8 @@ class MLIAPDescriptorSNAP : public MLIAPDescriptor { int switchinnerflag; double rfac0, rmin0; - double* rinnerelem; - double* drinnerelem; + double *rinnerelem; + double *drinnerelem; }; } // namespace LAMMPS_NS diff --git a/src/ML-IAP/mliap_descriptor_so3.cpp b/src/ML-IAP/mliap_descriptor_so3.cpp index 48748d8565..21e1e5c5d0 100644 --- a/src/ML-IAP/mliap_descriptor_so3.cpp +++ b/src/ML-IAP/mliap_descriptor_so3.cpp @@ -125,7 +125,7 @@ void MLIAPDescriptorSO3::read_paramfile(char *paramfilename) // check for keywords with one value per element - if ((skeywd == "elems") || (skeywd == "radelems") || (skeywd == "welems")) { + if ((skeywd == "elems") || (skeywd == "radelems") || (skeywd == "welems")) { if (nelementsflag == 0 || nwords != nelements + 1) error->all(FLERR, "Incorrect SO3 parameter file"); @@ -137,7 +137,7 @@ void MLIAPDescriptorSO3::read_paramfile(char *paramfilename) } elementsflag = 1; - } else if (skeywd == "radelems") { + } else if (skeywd == "radelems") { for (int ielem = 0; ielem < nelements; ielem++) { radelem[ielem] = utils::numeric(FLERR, skeyval, false, lmp); if (ielem < nelements - 1) skeyval = p.next(); diff --git a/src/ML-IAP/mliap_model_python.cpp b/src/ML-IAP/mliap_model_python.cpp index 878d234c69..8f88fb319d 100644 --- a/src/ML-IAP/mliap_model_python.cpp +++ b/src/ML-IAP/mliap_model_python.cpp @@ -62,7 +62,9 @@ MLIAPModelPython::MLIAPModelPython(LAMMPS *lmp, char *coefffilename) : // if LAMMPS_POTENTIALS environment variable is set, add it to PYTHONPATH as well const char *potentials_path = getenv("LAMMPS_POTENTIALS"); - if (potentials_path != nullptr) { PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); } + if (potentials_path != nullptr) { + PyList_Append(py_path, PY_STRING_FROM_STRING(potentials_path)); + } PyGILState_Release(gstate); if (coefffilename) read_coeffs(coefffilename); diff --git a/src/ML-PACE/pair_pace.cpp b/src/ML-PACE/pair_pace.cpp index fca66fd328..11e8a659a5 100644 --- a/src/ML-PACE/pair_pace.cpp +++ b/src/ML-PACE/pair_pace.cpp @@ -221,7 +221,7 @@ void PairPACE::compute(int eflag, int vflag) // tally energy contribution if (eflag) { // evdwl = energy of atom I - evdwl = scale[itype][itype]*aceimpl->ace->e_atom; + evdwl = scale[itype][itype] * aceimpl->ace->e_atom; ev_tally_full(i, 2.0 * evdwl, 0.0, 0.0, 0.0, 0.0, 0.0); } } diff --git a/src/ML-RANN/rann_fingerprint_bondscreenedspin.h b/src/ML-RANN/rann_fingerprint_bondscreenedspin.h index 5d52a18926..227938a668 100644 --- a/src/ML-RANN/rann_fingerprint_bondscreenedspin.h +++ b/src/ML-RANN/rann_fingerprint_bondscreenedspin.h @@ -46,7 +46,8 @@ namespace RANN { void allocate() override; void compute_fingerprint(double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, - bool *, int, int, double *, double *, double *, int *, int, int *) override; + bool *, int, int, double *, double *, double *, int *, int, + int *) override; void do3bodyfeatureset_doubleneighborloop(double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, bool *, int, diff --git a/src/ML-RANN/rann_fingerprint_bondspin.h b/src/ML-RANN/rann_fingerprint_bondspin.h index fb97893c8d..daa873a494 100644 --- a/src/ML-RANN/rann_fingerprint_bondspin.h +++ b/src/ML-RANN/rann_fingerprint_bondspin.h @@ -43,9 +43,9 @@ namespace RANN { void write_values(FILE *) override; void init(int *, int) override; void allocate() override; - void compute_fingerprint(double *, double *, double *, double *, double *, double *, - double *, int, int, double *, double *, double *, int *, int, - int *) override; //spin + void compute_fingerprint(double *, double *, double *, double *, double *, double *, double *, + int, int, double *, double *, double *, int *, int, + int *) override; //spin void do3bodyfeatureset_doubleneighborloop(double *, double *, double *, double *, double *, double *, double *, int, int, double *, double *, double *, int *, int, int *); diff --git a/src/ML-RANN/rann_fingerprint_radialscreenedspin.h b/src/ML-RANN/rann_fingerprint_radialscreenedspin.h index 0ea498cf23..38f6ae5c6d 100644 --- a/src/ML-RANN/rann_fingerprint_radialscreenedspin.h +++ b/src/ML-RANN/rann_fingerprint_radialscreenedspin.h @@ -43,10 +43,10 @@ namespace RANN { void write_values(FILE *) override; void init(int *, int) override; void allocate() override; - void compute_fingerprint(double *, double *, double *, double *, double *, double *, - double *, double *, double *, double *, double *, double *, - double *, double *, bool *, int, int, double *, double *, - double *, int *, int, int *) override; //spin,screen + void compute_fingerprint(double *, double *, double *, double *, double *, double *, double *, + double *, double *, double *, double *, double *, double *, double *, + bool *, int, int, double *, double *, double *, int *, int, + int *) override; //spin,screen int get_length() override; double *radialtable; diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index 6a108ad3dd..1a29f5413f 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -692,7 +692,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) if (keywd == "rinner" || keywd == "drinner") { - if (words.size() != nelements+1) + if ((int)words.size() != nelements+1) error->all(FLERR,"Incorrect SNAP parameter file"); if (comm->me == 0) diff --git a/src/ML-SNAP/pair_snap.h b/src/ML-SNAP/pair_snap.h index 77ceeabd4f..9828e4127c 100644 --- a/src/ML-SNAP/pair_snap.h +++ b/src/ML-SNAP/pair_snap.h @@ -62,7 +62,7 @@ class PairSNAP : public Pair { int switchinnerflag; // inner cutoff switch double *rinnerelem; // element inner cutoff double *drinnerelem; // element inner cutoff range - int chunksize,parallel_thresh; + int chunksize, parallel_thresh; double rfac0, rmin0, wj1, wj2; int rcutfacflag, twojmaxflag; // flags for required parameters int beta_max; // length of beta diff --git a/src/ML-SNAP/sna.h b/src/ML-SNAP/sna.h index 03d77d52b4..43447a565d 100644 --- a/src/ML-SNAP/sna.h +++ b/src/ML-SNAP/sna.h @@ -71,21 +71,21 @@ class SNA : protected Pointers { // short neighbor list data void grow_rij(int); - int nmax; // allocated size of short lists + int nmax; // allocated size of short lists - double **rij; // short rij list - int *inside; // short neighbor list - double *wj; // short weight list - double *rcutij; // short cutoff list + double **rij; // short rij list + int *inside; // short neighbor list + double *wj; // short weight list + double *rcutij; // short cutoff list // only allocated for switch_inner_flag=1 - double *rinnerij; // short inner cutoff list - double *drinnerij;// short inner range list + double *rinnerij; // short inner cutoff list + double *drinnerij; // short inner range list // only allocated for chem_flag=1 - int *element; // short element list [0,nelements) + int *element; // short element list [0,nelements) private: double rmin0, rfac0; @@ -100,7 +100,7 @@ class SNA : protected Pointers { int ***idxcg_block; double *ulisttot_r, *ulisttot_i; - double **ulist_r_ij, **ulist_i_ij; // short u list + double **ulist_r_ij, **ulist_i_ij; // short u list int *idxu_block; double *zlist_r, *zlist_i; @@ -124,8 +124,7 @@ class SNA : protected Pointers { void compute_uarray(double, double, double, double, double, int); double deltacg(int, int, int); void compute_ncoeff(); - void compute_duarray(double, double, double, double, double, double, - double, double, int); + void compute_duarray(double, double, double, double, double, double, double, double, int); // Sets the style for the switching function // 0 = none diff --git a/src/MOLECULE/dihedral_charmm.cpp b/src/MOLECULE/dihedral_charmm.cpp index 0cfd624cbc..bd783316cd 100644 --- a/src/MOLECULE/dihedral_charmm.cpp +++ b/src/MOLECULE/dihedral_charmm.cpp @@ -350,7 +350,7 @@ void DihedralCharmm::coeff(int narg, char **arg) void DihedralCharmm::init_style() { if (utils::strmatch(update->integrate_style, "^respa")) { - auto r = dynamic_cast( update->integrate); + auto r = dynamic_cast(update->integrate); if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) error->all(FLERR, "Dihedral style charmm must be set to same r-RESPA level as 'pair'"); if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral)) diff --git a/src/MOLECULE/dihedral_charmmfsw.cpp b/src/MOLECULE/dihedral_charmmfsw.cpp index 607fa8fa4a..cd94283842 100644 --- a/src/MOLECULE/dihedral_charmmfsw.cpp +++ b/src/MOLECULE/dihedral_charmmfsw.cpp @@ -369,7 +369,7 @@ void DihedralCharmmfsw::coeff(int narg, char **arg) void DihedralCharmmfsw::init_style() { if (utils::strmatch(update->integrate_style, "^respa")) { - auto r = dynamic_cast( update->integrate); + auto r = dynamic_cast(update->integrate); if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) error->all(FLERR, "Dihedral style charmmfsw must be set to same r-RESPA level as 'pair'"); if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral)) diff --git a/src/MOLFILE/reader_molfile.h b/src/MOLFILE/reader_molfile.h index 946ea66b03..df193c43e7 100644 --- a/src/MOLFILE/reader_molfile.h +++ b/src/MOLFILE/reader_molfile.h @@ -35,8 +35,8 @@ class ReaderMolfile : public Reader { int read_time(bigint &) override; void skip() override; - bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, - int &, int &, int &) override; + bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, int &, + int &, int &) override; void read_atoms(int, int, double **) override; void open_file(const std::string &) override; diff --git a/src/MPIIO/dump_atom_mpiio.cpp b/src/MPIIO/dump_atom_mpiio.cpp index b3933cec36..3035e3a106 100644 --- a/src/MPIIO/dump_atom_mpiio.cpp +++ b/src/MPIIO/dump_atom_mpiio.cpp @@ -38,11 +38,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -DumpAtomMPIIO::DumpAtomMPIIO(LAMMPS *lmp, int narg, char **arg) - : DumpAtom(lmp, narg, arg) +DumpAtomMPIIO::DumpAtomMPIIO(LAMMPS *lmp, int narg, char **arg) : DumpAtom(lmp, narg, arg) { if (me == 0) - error->warning(FLERR,"MPI-IO output is unmaintained and unreliable. Use with caution."); + error->warning(FLERR, "MPI-IO output is unmaintained and unreliable. Use with caution."); } /* ---------------------------------------------------------------------- */ @@ -86,8 +85,8 @@ void DumpAtomMPIIO::openfile() } if (append_flag) { // append open - int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND | - MPI_MODE_WRONLY, MPI_INFO_NULL, &mpifh); + int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_APPEND | MPI_MODE_WRONLY, + MPI_INFO_NULL, &mpifh); if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}: {}", filecurrent, utils::getsyserror()); @@ -100,8 +99,8 @@ void DumpAtomMPIIO::openfile() } else { // replace open - int err = MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY, - MPI_INFO_NULL, &mpifh); + int err = + MPI_File_open(world, filecurrent, MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &mpifh); if (err != MPI_SUCCESS) error->one(FLERR, "Cannot open dump file {}: {}", filecurrent, utils::getsyserror()); @@ -214,8 +213,10 @@ void DumpAtomMPIIO::init_style() if (format_line_user) { format = utils::strdup(std::string(format_line_user) + "\n"); } else { - if (image_flag == 0) format = utils::strdup(TAGINT_FORMAT " %d %g %g %g\n"); - else format = utils::strdup(TAGINT_FORMAT " %d %g %g %g %d %d %d\n"); + if (image_flag == 0) + format = utils::strdup(TAGINT_FORMAT " %d %g %g %g\n"); + else + format = utils::strdup(TAGINT_FORMAT " %d %g %g %g %d %d %d\n"); } // setup boundary string @@ -239,8 +240,10 @@ void DumpAtomMPIIO::init_style() columns.clear(); for (auto item : utils::split_words(default_columns)) { if (columns.size()) columns += " "; - if (keyword_user[icol].size()) columns += keyword_user[icol]; - else columns += item; + if (keyword_user[icol].size()) + columns += keyword_user[icol]; + else + columns += item; ++icol; } diff --git a/src/MPIIO/dump_custom_mpiio.cpp b/src/MPIIO/dump_custom_mpiio.cpp index a911ea1149..34306db122 100644 --- a/src/MPIIO/dump_custom_mpiio.cpp +++ b/src/MPIIO/dump_custom_mpiio.cpp @@ -41,11 +41,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -DumpCustomMPIIO::DumpCustomMPIIO(LAMMPS *lmp, int narg, char **arg) - : DumpCustom(lmp, narg, arg) +DumpCustomMPIIO::DumpCustomMPIIO(LAMMPS *lmp, int narg, char **arg) : DumpCustom(lmp, narg, arg) { if (me == 0) - error->warning(FLERR,"MPI-IO output is unmaintained and unreliable. Use with caution."); + error->warning(FLERR, "MPI-IO output is unmaintained and unreliable. Use with caution."); } /* ---------------------------------------------------------------------- */ @@ -59,7 +58,7 @@ DumpCustomMPIIO::~DumpCustomMPIIO() void DumpCustomMPIIO::openfile() { - if (singlefile_opened) { // single file already opened, so just return after resetting filesize + if (singlefile_opened) { // single file already opened, so just return after resetting filesize mpifo = currentFileSize; MPI_File_set_size(mpifh, mpifo + headerSize + sumFileSize); currentFileSize = mpifo + headerSize + sumFileSize; @@ -212,8 +211,10 @@ void DumpCustomMPIIO::init_style() int icol = 0; for (auto item : utils::split_words(columns_default)) { if (combined.size()) combined += " "; - if (keyword_user[icol].size()) combined += keyword_user[icol]; - else combined += item; + if (keyword_user[icol].size()) + combined += keyword_user[icol]; + else + combined += item; ++icol; } columns = utils::strdup(combined); @@ -221,8 +222,10 @@ void DumpCustomMPIIO::init_style() // format = copy of default or user-specified line format delete[] format; - if (format_line_user) format = utils::strdup(format_line_user); - else format = utils::strdup(format_default); + if (format_line_user) + format = utils::strdup(format_line_user); + else + format = utils::strdup(format_default); // tokenize the format string and add space at end of each format element // if user-specified int/float format exists, use it instead @@ -230,10 +233,9 @@ void DumpCustomMPIIO::init_style() // lo priority = line, medium priority = int/float, hi priority = column auto words = utils::split_words(format); - if ((int) words.size() < nfield) - error->all(FLERR,"Dump_modify format line is too short"); + if ((int) words.size() < nfield) error->all(FLERR, "Dump_modify format line is too short"); - int i=0; + int i = 0; for (const auto &word : words) { delete[] vformat[i]; @@ -245,10 +247,11 @@ void DumpCustomMPIIO::init_style() vformat[i] = utils::strdup(std::string(format_float_user) + " "); else if (vtype[i] == Dump::BIGINT && format_bigint_user) vformat[i] = utils::strdup(std::string(format_bigint_user) + " "); - else vformat[i] = utils::strdup(word + " "); + else + vformat[i] = utils::strdup(word + " "); // remove trailing blank on last column's format - if (i == nfield-1) vformat[i][strlen(vformat[i])-1] = '\0'; + if (i == nfield - 1) vformat[i][strlen(vformat[i]) - 1] = '\0'; ++i; } @@ -278,29 +281,28 @@ void DumpCustomMPIIO::init_style() for (i = 0; i < ncompute; i++) { compute[i] = modify->get_compute_by_id(id_compute[i]); - if (!compute[i]) error->all(FLERR,"Could not find dump custom compute ID {}",id_compute[i]); + if (!compute[i]) + error->all(FLERR, "Could not find dump custom/mpiio compute ID {}", id_compute[i]); } for (i = 0; i < nfix; i++) { fix[i] = modify->get_fix_by_id(id_fix[i]); - if (!fix[i]) error->all(FLERR,"Could not find dump custom fix ID {}", id_fix[i]); + if (!fix[i]) error->all(FLERR, "Could not find dump custom/mpiio fix ID {}", id_fix[i]); if (nevery % fix[i]->peratom_freq) - error->all(FLERR,"Dump custom and fix not computed at compatible times"); + error->all(FLERR, "dump custom/mpiio and fix not computed at compatible times"); } for (i = 0; i < nvariable; i++) { int ivariable = input->variable->find(id_variable[i]); if (ivariable < 0) - error->all(FLERR,"Could not find dump custom variable name {}", id_variable[i]); + error->all(FLERR, "Could not find dump custom/mpiio variable name {}", id_variable[i]); variable[i] = ivariable; } // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) error->all(FLERR, "Region ID for dump custom does not exist"); - } + if (idregion && !domain->get_region_by_id(idregion)) + error->all(FLERR, "Region {} for dump custom/mpiio does not exist", idregion); } /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/domain_omp.cpp b/src/OPENMP/domain_omp.cpp index 48b1118333..acc4be204f 100644 --- a/src/OPENMP/domain_omp.cpp +++ b/src/OPENMP/domain_omp.cpp @@ -47,7 +47,7 @@ void DomainOMP::pbc() // verify owned atoms have valid numerical coords // may not if computed pairwise force between 2 atoms at same location - const double *_noalias const coord = atom->x[0]; // NOLINT + const double *_noalias const coord = atom->x[0]; // NOLINT const int n3 = 3 * nlocal; int flag = 0; #if defined(_OPENMP) // clang-format off diff --git a/src/OPENMP/fix_qeq_comb_omp.cpp b/src/OPENMP/fix_qeq_comb_omp.cpp index 84ca49b7e7..a0d622401c 100644 --- a/src/OPENMP/fix_qeq_comb_omp.cpp +++ b/src/OPENMP/fix_qeq_comb_omp.cpp @@ -49,13 +49,13 @@ void FixQEQCombOMP::init() if (nullptr != force->pair_match("comb3", 0)) error->all(FLERR, "No support for comb3 currently available in OPENMP"); - comb = dynamic_cast( force->pair_match("comb/omp", 1)); - if (comb == nullptr) comb = dynamic_cast( force->pair_match("comb", 1)); + comb = dynamic_cast(force->pair_match("comb/omp", 1)); + if (comb == nullptr) comb = dynamic_cast(force->pair_match("comb", 1)); if (comb == nullptr) error->all(FLERR, "Must use pair_style comb or comb/omp with fix qeq/comb/omp"); if (utils::strmatch(update->integrate_style, "^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels - 1; + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } diff --git a/src/OPENMP/pair_reaxff_omp.h b/src/OPENMP/pair_reaxff_omp.h index d2ec2fb6bb..b4e18781f0 100644 --- a/src/OPENMP/pair_reaxff_omp.h +++ b/src/OPENMP/pair_reaxff_omp.h @@ -22,7 +22,7 @@ PairStyle(reax/c/omp,PairReaxFFOMP); #define LMP_PAIR_REAXFF_OMP_H #include "pair_reaxff.h" -#include "thr_omp.h" // IWYU pragma: export +#include "thr_omp.h" // IWYU pragma: export namespace LAMMPS_NS { diff --git a/src/OPENMP/pppm_disp_omp.h b/src/OPENMP/pppm_disp_omp.h index bc463e60b4..731cdbfcbd 100644 --- a/src/OPENMP/pppm_disp_omp.h +++ b/src/OPENMP/pppm_disp_omp.h @@ -37,8 +37,8 @@ class PPPMDispOMP : public PPPMDisp, public ThrOMP { virtual void compute_gf(); virtual void compute_gf_6(); - void particle_map(double, double, double, double, int **, int, int, int, int, int, int, - int, int) override; + void particle_map(double, double, double, double, int **, int, int, int, int, int, int, int, + int) override; void fieldforce_c_ik() override; void fieldforce_c_ad() override; diff --git a/src/OPENMP/pppm_disp_tip4p_omp.h b/src/OPENMP/pppm_disp_tip4p_omp.h index 9b08f5966e..a00e6b0dcb 100644 --- a/src/OPENMP/pppm_disp_tip4p_omp.h +++ b/src/OPENMP/pppm_disp_tip4p_omp.h @@ -38,10 +38,10 @@ class PPPMDispTIP4POMP : public PPPMDispTIP4P, public ThrOMP { void compute(int, int) override; - void particle_map(double, double, double, double, int **, int, int, int, int, int, int, - int, int) override; - void particle_map_c(double, double, double, double, int **, int, int, int, int, int, int, - int, int) override; + void particle_map(double, double, double, double, int **, int, int, int, int, int, int, int, + int) override; + void particle_map_c(double, double, double, double, int **, int, int, int, int, int, int, int, + int) override; void make_rho_c() override; // XXX: not (yet) multi-threaded void make_rho_g() override; void make_rho_a() override; diff --git a/src/ORIENT/fix_orient_bcc.h b/src/ORIENT/fix_orient_bcc.h index 82d9829397..b13b223b33 100644 --- a/src/ORIENT/fix_orient_bcc.h +++ b/src/ORIENT/fix_orient_bcc.h @@ -70,7 +70,8 @@ class FixOrientBCC : public Fix { bool use_xismooth; static constexpr int half_bcc_nn = 4; - double Rxi[half_bcc_nn][3] = {}, Rchi[half_bcc_nn][3] = {}, half_xi_chi_vec[2][half_bcc_nn][3] = {}; + double Rxi[half_bcc_nn][3] = {}, Rchi[half_bcc_nn][3] = {}, + half_xi_chi_vec[2][half_bcc_nn][3] = {}; double xiid, xi0, xi1, xicutoffsq, cutsq, added_energy; int nmax; // expose 2 per-atom quantities diff --git a/src/ORIENT/fix_orient_fcc.h b/src/ORIENT/fix_orient_fcc.h index dd36a89547..a01e312e22 100644 --- a/src/ORIENT/fix_orient_fcc.h +++ b/src/ORIENT/fix_orient_fcc.h @@ -70,7 +70,8 @@ class FixOrientFCC : public Fix { bool use_xismooth; static constexpr int half_fcc_nn = 6; - double Rxi[half_fcc_nn][3] = {}, Rchi[half_fcc_nn][3] = {}, half_xi_chi_vec[2][half_fcc_nn][3] = {}; + double Rxi[half_fcc_nn][3] = {}, Rchi[half_fcc_nn][3] = {}, + half_xi_chi_vec[2][half_fcc_nn][3] = {}; double xiid, xi0, xi1, xicutoffsq, cutsq, added_energy; int nmax; // expose 2 per-atom quantities diff --git a/src/PERI/pair_peri.cpp b/src/PERI/pair_peri.cpp index 3ce8eeb08e..f80de4c7b5 100644 --- a/src/PERI/pair_peri.cpp +++ b/src/PERI/pair_peri.cpp @@ -104,9 +104,9 @@ double PairPeri::memory_usage() global settings ------------------------------------------------------------------------- */ -void PairPeri::settings(int narg, char **/*arg*/) +void PairPeri::settings(int narg, char ** /*arg*/) { - if (narg) error->all(FLERR,"Illegal pair_style command"); + if (narg) error->all(FLERR, "Illegal pair_style command"); } /* ---------------------------------------------------------------------- @@ -130,7 +130,7 @@ void PairPeri::init_style() // if first init, create Fix needed for storing fixed neighbors if (!fix_peri_neigh) - fix_peri_neigh = dynamic_cast( modify->add_fix("PERI_NEIGH all PERI_NEIGH")); + fix_peri_neigh = dynamic_cast(modify->add_fix("PERI_NEIGH all PERI_NEIGH")); neighbor->add_request(this); } diff --git a/src/PERI/pair_peri_lps.h b/src/PERI/pair_peri_lps.h index 13afdef06c..b369ceeb9d 100644 --- a/src/PERI/pair_peri_lps.h +++ b/src/PERI/pair_peri_lps.h @@ -25,7 +25,7 @@ PairStyle(peri/lps,PairPeriLPS); namespace LAMMPS_NS { class PairPeriLPS : public PairPeri { -public: + public: PairPeriLPS(class LAMMPS *); void compute(int, int) override; diff --git a/src/PHONON/dynamical_matrix.h b/src/PHONON/dynamical_matrix.h index 4a08420381..55448b6934 100644 --- a/src/PHONON/dynamical_matrix.h +++ b/src/PHONON/dynamical_matrix.h @@ -52,9 +52,9 @@ class DynamicalMatrix : public Command { double conv_mass; double del; int igroup, groupbit; - bigint gcount; // number of atoms in group - bigint dynlen; // rank of dynamical matrix - bigint dynlenb; // new dynlen if folded + bigint gcount; // number of atoms in group + bigint dynlen; // rank of dynamical matrix + bigint dynlenb; // new dynlen if folded int scaleflag; int me; bigint *groupmap; diff --git a/src/PHONON/third_order.h b/src/PHONON/third_order.h index e3d2cdc16e..8b706c78c8 100644 --- a/src/PHONON/third_order.h +++ b/src/PHONON/third_order.h @@ -23,9 +23,8 @@ class ThirdOrder : public Command { void setup(); protected: - int eflag,vflag; // flags for energy/virial computation - int external_force_clear; // clear forces locally or externally - + int eflag, vflag; // flags for energy/virial computation + int external_force_clear; // clear forces locally or externally int triclinic; // 0 if domain is orthog, 1 if triclinic int pairflag; @@ -37,8 +36,7 @@ class ThirdOrder : public Command { virtual void update_force(); virtual void force_clear(); - virtual void openfile(const char* filename); - + virtual void openfile(const char *filename); protected: void options(int, char **); @@ -54,7 +52,7 @@ class ThirdOrder : public Command { double conv_distance; double conv_mass; double del; - int igroup,groupbit; + int igroup, groupbit; bigint dynlen; bigint dynlenb; int scaleflag; diff --git a/src/PLUGIN/plugin.h b/src/PLUGIN/plugin.h index 0fd2cd5042..8cfabc9ef2 100644 --- a/src/PLUGIN/plugin.h +++ b/src/PLUGIN/plugin.h @@ -21,7 +21,7 @@ CommandStyle(plugin,Plugin); #define LMP_PLUGIN_H #include "command.h" -#include "lammpsplugin.h" // IWYU pragma: export +#include "lammpsplugin.h" // IWYU pragma: export namespace LAMMPS_NS { diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index 7ac3570f2f..20e0b7cc6b 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -357,8 +357,8 @@ void FixPOEMS::init() if (utils::strmatch(ifix->style, "^poems")) pflag = true; if (pflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag) if (comm->me == 0) - error->warning(FLERR,"Fix {} with ID {} alters forces after fix poems", - ifix->style, ifix->id); + error->warning(FLERR, "Fix {} with ID {} alters forces after fix poems", ifix->style, + ifix->id); } } diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index 4184607474..aeeee7b71a 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -1096,11 +1096,8 @@ void FixQEqReaxFF::get_chi_field() // update electric field region if necessary - Region *region = nullptr; - if (efield->iregion >= 0) { - region = domain->regions[efield->iregion]; - region->prematch(); - } + Region *region = efield->region; + if (region) region->prematch(); // efield energy is in real units of kcal/mol/angstrom, need to convert to eV diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index b4d146c8da..80460147ed 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -275,7 +275,7 @@ void FixReaxFFSpecies::init() if (atom->tag_enable == 0) error->all(FLERR, "Cannot use fix reaxff/species unless atoms have IDs"); - reaxff = dynamic_cast( force->pair_match("^reax..", 0)); + reaxff = dynamic_cast(force->pair_match("^reax..", 0)); if (reaxff == nullptr) error->all(FLERR, "Cannot use fix reaxff/species without " @@ -297,7 +297,7 @@ void FixReaxFFSpecies::init() // create a fix to point to fix_ave_atom for averaging stored properties auto fixcmd = fmt::format("SPECBOND_{} all ave/atom {} {} {}", id, nevery, nrepeat, nfreq); for (int i = 1; i < 32; ++i) fixcmd += fmt::format(" c_SPECATOM_{}[{}]", id, i); - f_SPECBOND = dynamic_cast( modify->add_fix(fixcmd)); + f_SPECBOND = dynamic_cast(modify->add_fix(fixcmd)); setupflag = 1; } } diff --git a/src/REAXFF/reaxff_api.h b/src/REAXFF/reaxff_api.h index 33436304f1..52ee3df603 100644 --- a/src/REAXFF/reaxff_api.h +++ b/src/REAXFF/reaxff_api.h @@ -21,7 +21,7 @@ #ifndef LMP_REAXFF_API_H #define LMP_REAXFF_API_H -#include "reaxff_types.h" // IWYU pragma: export +#include "reaxff_types.h" // IWYU pragma: export #include diff --git a/src/REAXFF/reaxff_types.h b/src/REAXFF/reaxff_types.h index 94818f6ebf..7b090c79ce 100644 --- a/src/REAXFF/reaxff_types.h +++ b/src/REAXFF/reaxff_types.h @@ -23,8 +23,8 @@ #include "lmptype.h" -#include "reaxff_defs.h" // IWYU pragma: export -#include "reaxff_inline.h" // IWYU pragma: export +#include "reaxff_defs.h" // IWYU pragma: export +#include "reaxff_inline.h" // IWYU pragma: export // forward declarations namespace LAMMPS_NS { @@ -77,7 +77,7 @@ struct single_body_parameters { double b_o_131; double b_o_132; double b_o_133; - double bcut_acks2; // ACKS2 bond cutoff + double bcut_acks2; // ACKS2 bond cutoff /* Line four in the field file */ double p_ovun2; diff --git a/src/REPLICA/fix_pimd.cpp b/src/REPLICA/fix_pimd.cpp index 87dc802dbf..32c468765e 100644 --- a/src/REPLICA/fix_pimd.cpp +++ b/src/REPLICA/fix_pimd.cpp @@ -614,8 +614,7 @@ void FixPIMD::comm_init() } if (buf_beads) { - for (int i = 0; i < np; i++) - delete[] buf_beads[i]; + for (int i = 0; i < np; i++) delete[] buf_beads[i]; delete[] buf_beads; } @@ -678,8 +677,8 @@ void FixPIMD::comm_exec(double **ptr) if (index < 0) { auto mesg = fmt::format("Atom {} is missing at world [{}] rank [{}] " "required by rank [{}] ({}, {}, {}).\n", - tag_send[i], universe->iworld, comm->me, - plan_recv[iplan], atom->tag[0], atom->tag[1], atom->tag[2]); + tag_send[i], universe->iworld, comm->me, plan_recv[iplan], + atom->tag[0], atom->tag[1], atom->tag[2]); error->universe_one(FLERR, mesg); } diff --git a/src/REPLICA/neb.h b/src/REPLICA/neb.h index c99ab60904..1bb1a06513 100644 --- a/src/REPLICA/neb.h +++ b/src/REPLICA/neb.h @@ -30,7 +30,7 @@ class NEB : public Command { NEB(class LAMMPS *, double, double, int, int, int, double *, double *); ~NEB() override; void command(int, char **) override; // process neb command - void run(); // run NEB + void run(); // run NEB double ebf, ebr; // forward and reverse energy barriers diff --git a/src/RIGID/fix_shake.h b/src/RIGID/fix_shake.h index 677cdfa942..863113a076 100644 --- a/src/RIGID/fix_shake.h +++ b/src/RIGID/fix_shake.h @@ -108,10 +108,11 @@ class FixShake : public Fix { int nlist, maxlist; // size and max-size of list // stat quantities - int *b_count, *b_count_all, *b_atom, *b_atom_all; // counts for each bond type, atoms in bond cluster - double *b_ave, *b_max, *b_min; // ave/max/min dist for each bond type - double *b_ave_all, *b_max_all, *b_min_all; // MPI summing arrays - int *a_count, *a_count_all; // ditto for angle types + int *b_count, *b_count_all, *b_atom, + *b_atom_all; // counts for each bond type, atoms in bond cluster + double *b_ave, *b_max, *b_min; // ave/max/min dist for each bond type + double *b_ave_all, *b_max_all, *b_min_all; // MPI summing arrays + int *a_count, *a_count_all; // ditto for angle types double *a_ave, *a_max, *a_min; double *a_ave_all, *a_max_all, *a_min_all; diff --git a/src/SPIN/fix_setforce_spin.cpp b/src/SPIN/fix_setforce_spin.cpp index 73acb45920..a88a84f0bb 100644 --- a/src/SPIN/fix_setforce_spin.cpp +++ b/src/SPIN/fix_setforce_spin.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,24 +22,26 @@ ------------------------------------------------------------------------- */ #include "fix_setforce_spin.h" + #include "atom.h" -#include "update.h" -#include "modify.h" #include "domain.h" -#include "region.h" #include "input.h" -#include "variable.h" #include "memory.h" +#include "modify.h" +#include "region.h" +#include "update.h" +#include "variable.h" using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE,CONSTANT,EQUAL,ATOM}; +enum { NONE, CONSTANT, EQUAL, ATOM }; /* ---------------------------------------------------------------------- */ -FixSetForceSpin::FixSetForceSpin(LAMMPS *lmp, int narg, char **arg) : - FixSetForce(lmp, narg, arg) {} +FixSetForceSpin::FixSetForceSpin(LAMMPS *_lmp, int narg, char **arg) : FixSetForce(_lmp, narg, arg) +{ +} /* ---------------------------------------------------------------------- */ @@ -53,18 +54,14 @@ void FixSetForceSpin::post_force(int /*vflag*/) // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // reallocate sforce array if necessary if (varflag == ATOM && atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(sforce); - memory->create(sforce,maxatom,3,"setforce:sforce"); + memory->create(sforce, maxatom, 3, "setforce:sforce"); } foriginal[0] = foriginal[1] = foriginal[2] = 0.0; @@ -73,7 +70,7 @@ void FixSetForceSpin::post_force(int /*vflag*/) if (varflag == CONSTANT) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += fm[i][0]; foriginal[1] += fm[i][1]; foriginal[2] += fm[i][2]; @@ -82,36 +79,45 @@ void FixSetForceSpin::post_force(int /*vflag*/) if (zstyle) fm[i][2] = zvalue; } - // variable force, wrap with clear/add + // variable force, wrap with clear/add } else { modify->clearstep_compute(); - if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar); + if (xstyle == EQUAL) + xvalue = input->variable->compute_equal(xvar); else if (xstyle == ATOM) - input->variable->compute_atom(xvar,igroup,&sforce[0][0],3,0); - if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar); + input->variable->compute_atom(xvar, igroup, &sforce[0][0], 3, 0); + if (ystyle == EQUAL) + yvalue = input->variable->compute_equal(yvar); else if (ystyle == ATOM) - input->variable->compute_atom(yvar,igroup,&sforce[0][1],3,0); - if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar); + input->variable->compute_atom(yvar, igroup, &sforce[0][1], 3, 0); + if (zstyle == EQUAL) + zvalue = input->variable->compute_equal(zvar); else if (zstyle == ATOM) - input->variable->compute_atom(zvar,igroup,&sforce[0][2],3,0); + input->variable->compute_atom(zvar, igroup, &sforce[0][2], 3, 0); modify->addstep_compute(update->ntimestep + 1); for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += fm[i][0]; foriginal[1] += fm[i][1]; foriginal[2] += fm[i][2]; - if (xstyle == ATOM) fm[i][0] = sforce[i][0]; - else if (xstyle) fm[i][0] = xvalue; - if (ystyle == ATOM) fm[i][1] = sforce[i][1]; - else if (ystyle) fm[i][1] = yvalue; - if (zstyle == ATOM) fm[i][2] = sforce[i][2]; - else if (zstyle) fm[i][2] = zvalue; + if (xstyle == ATOM) + fm[i][0] = sforce[i][0]; + else if (xstyle) + fm[i][0] = xvalue; + if (ystyle == ATOM) + fm[i][1] = sforce[i][1]; + else if (ystyle) + fm[i][1] = yvalue; + if (zstyle == ATOM) + fm[i][2] = sforce[i][2]; + else if (zstyle) + fm[i][2] = zvalue; } } } @@ -125,18 +131,14 @@ void FixSetForceSpin::single_setforce_spin(int i, double fmi[3]) // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // reallocate sforce array if necessary if (varflag == ATOM && atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(sforce); - memory->create(sforce,maxatom,3,"setforce:sforce"); + memory->create(sforce, maxatom, 3, "setforce:sforce"); } foriginal[0] = foriginal[1] = foriginal[2] = 0.0; @@ -146,7 +148,7 @@ void FixSetForceSpin::single_setforce_spin(int i, double fmi[3]) if (varflag == CONSTANT) { if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) return; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) return; foriginal[0] += fmi[0]; foriginal[1] += fmi[1]; foriginal[2] += fmi[2]; @@ -155,35 +157,44 @@ void FixSetForceSpin::single_setforce_spin(int i, double fmi[3]) if (zstyle) fmi[2] = zvalue; } - // variable force, wrap with clear/add + // variable force, wrap with clear/add } else { modify->clearstep_compute(); - if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar); + if (xstyle == EQUAL) + xvalue = input->variable->compute_equal(xvar); else if (xstyle == ATOM) - input->variable->compute_atom(xvar,igroup,&sforce[0][0],3,0); - if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar); + input->variable->compute_atom(xvar, igroup, &sforce[0][0], 3, 0); + if (ystyle == EQUAL) + yvalue = input->variable->compute_equal(yvar); else if (ystyle == ATOM) - input->variable->compute_atom(yvar,igroup,&sforce[0][1],3,0); - if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar); + input->variable->compute_atom(yvar, igroup, &sforce[0][1], 3, 0); + if (zstyle == EQUAL) + zvalue = input->variable->compute_equal(zvar); else if (zstyle == ATOM) - input->variable->compute_atom(zvar,igroup,&sforce[0][2],3,0); + input->variable->compute_atom(zvar, igroup, &sforce[0][2], 3, 0); modify->addstep_compute(update->ntimestep + 1); if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) return; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) return; foriginal[0] += fmi[0]; foriginal[1] += fmi[1]; foriginal[2] += fmi[2]; - if (xstyle == ATOM) fmi[0] = sforce[i][0]; - else if (xstyle) fmi[0] = xvalue; - if (ystyle == ATOM) fmi[1] = sforce[i][1]; - else if (ystyle) fmi[1] = yvalue; - if (zstyle == ATOM) fmi[2] = sforce[i][2]; - else if (zstyle) fmi[2] = zvalue; + if (xstyle == ATOM) + fmi[0] = sforce[i][0]; + else if (xstyle) + fmi[0] = xvalue; + if (ystyle == ATOM) + fmi[1] = sforce[i][1]; + else if (ystyle) + fmi[1] = yvalue; + if (zstyle == ATOM) + fmi[2] = sforce[i][2]; + else if (zstyle) + fmi[2] = zvalue; } } } @@ -194,13 +205,10 @@ void FixSetForceSpin::post_force_respa(int vflag, int ilevel, int /*iloop*/) { // set force to desired value on requested level, 0.0 on other levels - if (ilevel == ilevel_respa) post_force(vflag); + if (ilevel == ilevel_respa) + post_force(vflag); else { - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); double **x = atom->x; double **fm = atom->fm; @@ -209,7 +217,7 @@ void FixSetForceSpin::post_force_respa(int vflag, int ilevel, int /*iloop*/) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; if (xstyle) fm[i][0] = 0.0; if (ystyle) fm[i][1] = 0.0; if (zstyle) fm[i][2] = 0.0; diff --git a/src/SPIN/neb_spin.h b/src/SPIN/neb_spin.h index b667215520..406ba2c6ec 100644 --- a/src/SPIN/neb_spin.h +++ b/src/SPIN/neb_spin.h @@ -29,7 +29,7 @@ class NEBSpin : public Command { NEBSpin(class LAMMPS *); ~NEBSpin() override; void command(int, char **) override; // process neb/spin command - void run(); // run NEBSpin + void run(); // run NEBSpin double ebf, ebr; // forward and reverse energy barriers diff --git a/src/SRD/fix_srd.cpp b/src/SRD/fix_srd.cpp index dd27da08ea..76c5237f2d 100644 --- a/src/SRD/fix_srd.cpp +++ b/src/SRD/fix_srd.cpp @@ -142,7 +142,7 @@ FixSRD::FixSRD(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg], "overlap") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); - overlap = utils::logical(FLERR,arg[iarg+1],false,lmp); + overlap = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "inside") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); @@ -157,7 +157,7 @@ FixSRD::FixSRD(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg], "exact") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); - exactflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + exactflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "radius") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); @@ -196,7 +196,7 @@ FixSRD::FixSRD(LAMMPS *lmp, int narg, char **arg) : iarg += 3; } else if (strcmp(arg[iarg], "tstat") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); - tstat = utils::logical(FLERR,arg[iarg+1],false,lmp); + tstat = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "rescale") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix srd command"); @@ -289,9 +289,9 @@ FixSRD::FixSRD(LAMMPS *lmp, int narg, char **arg) : // atom style pointers to particles that store bonus info - avec_ellipsoid = dynamic_cast( atom->style_match("ellipsoid")); - avec_line = dynamic_cast( atom->style_match("line")); - avec_tri = dynamic_cast( atom->style_match("tri")); + avec_ellipsoid = dynamic_cast(atom->style_match("ellipsoid")); + avec_line = dynamic_cast(atom->style_match("line")); + avec_tri = dynamic_cast(atom->style_match("tri")); // fix parameters @@ -369,7 +369,7 @@ void FixSRD::init() if (strcmp(modify->fix[m]->style, "wall/srd") == 0) { if (wallexist) error->all(FLERR, "Cannot use fix wall/srd more than once"); wallexist = 1; - wallfix = dynamic_cast( modify->fix[m]); + wallfix = dynamic_cast(modify->fix[m]); nwall = wallfix->nwall; wallvarflag = wallfix->varflag; wallwhich = wallfix->wallwhich; @@ -394,7 +394,7 @@ void FixSRD::init() if (fixes[i]->box_change & BOX_CHANGE_SHAPE) change_shape = 1; if (strcmp(fixes[i]->style, "deform") == 0) { deformflag = 1; - auto deform = dynamic_cast( modify->fix[i]); + auto deform = dynamic_cast(modify->fix[i]); if ((deform->box_change & BOX_CHANGE_SHAPE) && deform->remapflag != Domain::V_REMAP) error->all(FLERR, "Using fix srd with inconsistent fix deform remap option"); } diff --git a/src/STUBS/mpi.cpp b/src/STUBS/mpi.cpp index 13d0446e0b..e914063889 100644 --- a/src/STUBS/mpi.cpp +++ b/src/STUBS/mpi.cpp @@ -429,8 +429,7 @@ int MPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group *newgroup) int MPI_Group_free(MPI_Group *group) { - if (group) - *group = MPI_GROUP_NULL; + if (group) *group = MPI_GROUP_NULL; return 0; } diff --git a/src/TALLY/compute_force_tally.h b/src/TALLY/compute_force_tally.h index a46e074103..d0639d20ea 100644 --- a/src/TALLY/compute_force_tally.h +++ b/src/TALLY/compute_force_tally.h @@ -40,7 +40,8 @@ class ComputeForceTally : public Compute { double memory_usage() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/TALLY/compute_heat_flux_tally.h b/src/TALLY/compute_heat_flux_tally.h index 8110ad6fc7..1324a1383b 100644 --- a/src/TALLY/compute_heat_flux_tally.h +++ b/src/TALLY/compute_heat_flux_tally.h @@ -39,7 +39,8 @@ class ComputeHeatFluxTally : public Compute { double memory_usage() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/TALLY/compute_heat_flux_virial_tally.h b/src/TALLY/compute_heat_flux_virial_tally.h index 1d664ce560..eeee7cf4a4 100644 --- a/src/TALLY/compute_heat_flux_virial_tally.h +++ b/src/TALLY/compute_heat_flux_virial_tally.h @@ -40,7 +40,8 @@ class ComputeHeatFluxVirialTally : public Compute { double memory_usage() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/TALLY/compute_pe_mol_tally.h b/src/TALLY/compute_pe_mol_tally.h index b123d7cf78..5d1f6d1d25 100644 --- a/src/TALLY/compute_pe_mol_tally.h +++ b/src/TALLY/compute_pe_mol_tally.h @@ -34,7 +34,8 @@ class ComputePEMolTally : public Compute { void compute_vector() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/TALLY/compute_pe_tally.h b/src/TALLY/compute_pe_tally.h index dfccce5f7e..7561ae4b9e 100644 --- a/src/TALLY/compute_pe_tally.h +++ b/src/TALLY/compute_pe_tally.h @@ -40,7 +40,8 @@ class ComputePETally : public Compute { double memory_usage() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/TALLY/compute_stress_tally.h b/src/TALLY/compute_stress_tally.h index 9910667df3..8e42dc717f 100644 --- a/src/TALLY/compute_stress_tally.h +++ b/src/TALLY/compute_stress_tally.h @@ -40,7 +40,8 @@ class ComputeStressTally : public Compute { double memory_usage() override; void pair_setup_callback(int, int) override; - void pair_tally_callback(int, int, int, int, double, double, double, double, double, double) override; + void pair_tally_callback(int, int, int, int, double, double, double, double, double, + double) override; private: bigint did_setup; diff --git a/src/balance.h b/src/balance.h index f7a3c60df5..2a01093683 100644 --- a/src/balance.h +++ b/src/balance.h @@ -46,6 +46,7 @@ class Balance : public Command { void dumpout(bigint); static constexpr int BSTR_SIZE = 3; + private: int me, nprocs; @@ -57,7 +58,7 @@ class Balance : public Command { int nitermax; // params for shift LB double stopthresh; - char bstr[BSTR_SIZE+1]; + char bstr[BSTR_SIZE + 1]; int shift_allocate; // 1 if SHIFT vectors have been allocated int ndim; // length of balance string bstr diff --git a/src/bond.h b/src/bond.h index 47c8687f50..d425eb17a0 100644 --- a/src/bond.h +++ b/src/bond.h @@ -23,7 +23,7 @@ class Bond : protected Pointers { friend class FixOMP; public: - static int instance_total; // # of Bond classes ever instantiated + static int instance_total; // # of Bond classes ever instantiated int allocated; int *setflag; @@ -33,9 +33,9 @@ class Bond : protected Pointers { double virial[6]; // accumulated virial: xx,yy,zz,xy,xz,yz double *eatom, **vatom; // accumulated per-atom energy/virial - int comm_forward; // size of forward communication (0 if none) - int comm_reverse; // size of reverse communication (0 if none) - int comm_reverse_off; // size of reverse comm even if newton off + int comm_forward; // size of forward communication (0 if none) + int comm_reverse; // size of reverse communication (0 if none) + int comm_reverse_off; // size of reverse comm even if newton off int reinitflag; // 1 if compatible with fix adapt and alike @@ -62,9 +62,9 @@ class Bond : protected Pointers { virtual double memory_usage(); virtual void *extract(const char *, int &) { return nullptr; } virtual void reinit(); - virtual int pack_forward_comm(int, int *, double *, int, int *) {return 0;} + virtual int pack_forward_comm(int, int *, double *, int, int *) { return 0; } virtual void unpack_forward_comm(int, int, double *) {} - virtual int pack_reverse_comm(int, int, double *) {return 0;} + virtual int pack_reverse_comm(int, int, double *) { return 0; } virtual void unpack_reverse_comm(int, int *, double *) {} void write_file(int, char **); diff --git a/src/command.h b/src/command.h index f1e754325e..fb0d9dc415 100644 --- a/src/command.h +++ b/src/command.h @@ -14,7 +14,7 @@ #ifndef LMP_COMMAND_H #define LMP_COMMAND_H -#include "pointers.h" // IWYU pragma: keep +#include "pointers.h" // IWYU pragma: keep namespace LAMMPS_NS { diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index 49435c49fc..226e0cd646 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -69,7 +69,7 @@ ComputeAngmomChunk::~ComputeAngmomChunk() void ComputeAngmomChunk::init() { - cchunk = dynamic_cast( modify->get_compute_by_id(idchunk)); + cchunk = dynamic_cast(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"); @@ -187,7 +187,7 @@ void ComputeAngmomChunk::lock_disable() { int icompute = modify->find_compute(idchunk); if (icompute >= 0) { - cchunk = dynamic_cast( modify->compute[icompute]); + cchunk = dynamic_cast(modify->compute[icompute]); cchunk->lockcount--; } } diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 4ad9a4467c..ee362927cf 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -162,7 +162,7 @@ void ComputeCentroidStressAtom::init() if (id_temp) { temperature = modify->get_compute_by_id(id_temp); if (!temperature) - error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}",id_temp); + error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}", id_temp); if (temperature->tempbias) biasflag = BIAS; else diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index d9358d5f10..b63ab23739 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -41,24 +40,23 @@ using namespace LAMMPS_NS; using namespace MathConst; -enum{LOWER,CENTER,UPPER,COORD}; -enum{BOX,LATTICE,REDUCED}; -enum{NODISCARD,MIXED,YESDISCARD}; -enum{ONCE,NFREQ,EVERY}; // used in several files -enum{LIMITMAX,LIMITEXACT}; +enum { LOWER, CENTER, UPPER, COORD }; +enum { BOX, LATTICE, REDUCED }; +enum { NODISCARD, MIXED, YESDISCARD }; +enum { ONCE, NFREQ, EVERY }; // used in several files +enum { LIMITMAX, LIMITEXACT }; -#define IDMAX 1024*1024 +#define IDMAX 1024 * 1024 /* ---------------------------------------------------------------------- */ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - chunk_volume_vec(nullptr), coord(nullptr), ichunk(nullptr), chunkID(nullptr), - cfvid(nullptr), idregion(nullptr), region(nullptr), cchunk(nullptr), fchunk(nullptr), - varatom(nullptr), id_fix(nullptr), fixstore(nullptr), lockfix(nullptr), chunk(nullptr), - exclude(nullptr), hash(nullptr) + Compute(lmp, narg, arg), chunk_volume_vec(nullptr), coord(nullptr), ichunk(nullptr), + chunkID(nullptr), cfvid(nullptr), idregion(nullptr), region(nullptr), cchunk(nullptr), + fchunk(nullptr), varatom(nullptr), id_fix(nullptr), fixstore(nullptr), lockfix(nullptr), + chunk(nullptr), exclude(nullptr), hash(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute chunk/atom command"); + if (narg < 4) error->all(FLERR, "Illegal compute chunk/atom command"); peratom_flag = 1; scalar_flag = 1; @@ -72,52 +70,51 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : binflag = 0; ncoord = 0; - cfvid = nullptr; - if (strcmp(arg[3],"bin/1d") == 0) { + if (strcmp(arg[3], "bin/1d") == 0) { binflag = 1; which = ArgInfo::BIN1D; ncoord = 1; iarg = 4; - readdim(narg,arg,iarg,0); + readdim(narg, arg, iarg, 0); iarg += 3; - } else if (strcmp(arg[3],"bin/2d") == 0) { + } else if (strcmp(arg[3], "bin/2d") == 0) { binflag = 1; which = ArgInfo::BIN2D; ncoord = 2; iarg = 4; - readdim(narg,arg,iarg,0); - readdim(narg,arg,iarg+3,1); + readdim(narg, arg, iarg, 0); + readdim(narg, arg, iarg + 3, 1); iarg += 6; - } else if (strcmp(arg[3],"bin/3d") == 0) { + } else if (strcmp(arg[3], "bin/3d") == 0) { binflag = 1; which = ArgInfo::BIN3D; ncoord = 3; iarg = 4; - readdim(narg,arg,iarg,0); - readdim(narg,arg,iarg+3,1); - readdim(narg,arg,iarg+6,2); + readdim(narg, arg, iarg, 0); + readdim(narg, arg, iarg + 3, 1); + readdim(narg, arg, iarg + 6, 2); iarg += 9; - } else if (strcmp(arg[3],"bin/sphere") == 0) { + } else if (strcmp(arg[3], "bin/sphere") == 0) { binflag = 1; which = ArgInfo::BINSPHERE; ncoord = 1; iarg = 4; - if (iarg+6 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - sorigin_user[0] = utils::numeric(FLERR,arg[iarg],false,lmp); - sorigin_user[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - sorigin_user[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - sradmin_user = utils::numeric(FLERR,arg[iarg+3],false,lmp); - sradmax_user = utils::numeric(FLERR,arg[iarg+4],false,lmp); - nsbin = utils::inumeric(FLERR,arg[iarg+5],false,lmp); + if (iarg + 6 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + sorigin_user[0] = utils::numeric(FLERR, arg[iarg], false, lmp); + sorigin_user[1] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + sorigin_user[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + sradmin_user = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + sradmax_user = utils::numeric(FLERR, arg[iarg + 4], false, lmp); + nsbin = utils::inumeric(FLERR, arg[iarg + 5], false, lmp); iarg += 6; - } else if (strcmp(arg[3],"bin/cylinder") == 0) { + } else if (strcmp(arg[3], "bin/cylinder") == 0) { binflag = 1; which = ArgInfo::BINCYLINDER; ncoord = 2; iarg = 4; - readdim(narg,arg,iarg,0); + readdim(narg, arg, iarg, 0); iarg += 3; if (dim[0] == 0) { cdim1 = 1; @@ -129,20 +126,20 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : cdim1 = 0; cdim2 = 1; } - if (iarg+5 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); + if (iarg + 5 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); corigin_user[dim[0]] = 0.0; - corigin_user[cdim1] = utils::numeric(FLERR,arg[iarg],false,lmp); - corigin_user[cdim2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - cradmin_user = utils::numeric(FLERR,arg[iarg+2],false,lmp); - cradmax_user = utils::numeric(FLERR,arg[iarg+3],false,lmp); + corigin_user[cdim1] = utils::numeric(FLERR, arg[iarg], false, lmp); + corigin_user[cdim2] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + cradmin_user = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + cradmax_user = utils::numeric(FLERR, arg[iarg + 3], false, lmp); - ncbin = utils::inumeric(FLERR,arg[iarg+4],false,lmp); + ncbin = utils::inumeric(FLERR, arg[iarg + 4], false, lmp); iarg += 5; - } else if (strcmp(arg[3],"type") == 0) { + } else if (strcmp(arg[3], "type") == 0) { which = ArgInfo::TYPE; iarg = 4; - } else if (strcmp(arg[3],"molecule") == 0) { + } else if (strcmp(arg[3], "molecule") == 0) { which = ArgInfo::MOLECULE; iarg = 4; @@ -153,16 +150,14 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : argindex = argi.get_index1(); cfvid = argi.copy_name(); - if ((which == ArgInfo::UNKNOWN) || (which == ArgInfo::NONE) - || (argi.get_dim() > 1)) - error->all(FLERR,"Illegal compute chunk/atom command"); + if ((which == ArgInfo::UNKNOWN) || (which == ArgInfo::NONE) || (argi.get_dim() > 1)) + error->all(FLERR, "Illegal compute chunk/atom command"); iarg = 4; } // optional args regionflag = 0; - idregion = nullptr; nchunksetflag = 0; nchunkflag = EVERY; limit = 0; @@ -182,80 +177,105 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : pbcflag = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - int iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for compute chunk/atom does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (!domain->get_region_by_id(arg[iarg + 1])) + error->all(FLERR, "Region {} for compute chunk/atom does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); regionflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"nchunk") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg+1],"once") == 0) nchunkflag = ONCE; - else if (strcmp(arg[iarg+1],"every") == 0) nchunkflag = EVERY; - else error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "nchunk") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg + 1], "once") == 0) + nchunkflag = ONCE; + else if (strcmp(arg[iarg + 1], "every") == 0) + nchunkflag = EVERY; + else + error->all(FLERR, "Illegal compute chunk/atom command"); nchunksetflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"limit") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - limit = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (limit < 0) error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "limit") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + limit = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + if (limit < 0) error->all(FLERR, "Illegal compute chunk/atom command"); if (limit && !compress) limitfirst = 1; iarg += 2; if (limit) { - if (iarg > narg) - error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg],"max") == 0) limitstyle = LIMITMAX; - else if (strcmp(arg[iarg],"exact") == 0) limitstyle = LIMITEXACT; - else error->all(FLERR,"Illegal compute chunk/atom command"); + if (iarg > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg], "max") == 0) + limitstyle = LIMITMAX; + else if (strcmp(arg[iarg], "exact") == 0) + limitstyle = LIMITEXACT; + else + error->all(FLERR, "Illegal compute chunk/atom command"); iarg++; } - } else if (strcmp(arg[iarg],"ids") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg+1],"once") == 0) idsflag = ONCE; - else if (strcmp(arg[iarg+1],"nfreq") == 0) idsflag = NFREQ; - else if (strcmp(arg[iarg+1],"every") == 0) idsflag = EVERY; - else error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "ids") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg + 1], "once") == 0) + idsflag = ONCE; + else if (strcmp(arg[iarg + 1], "nfreq") == 0) + idsflag = NFREQ; + else if (strcmp(arg[iarg + 1], "every") == 0) + idsflag = EVERY; + else + error->all(FLERR, "Illegal compute chunk/atom command"); iarg += 2; - } else if (strcmp(arg[iarg],"compress") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - compress = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "compress") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + compress = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"discard") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg+1],"mixed") == 0) discard = MIXED; - else if (strcmp(arg[iarg+1],"no") == 0) discard = NODISCARD; - else if (strcmp(arg[iarg+1],"yes") == 0) discard = YESDISCARD; - else error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "discard") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg + 1], "mixed") == 0) + discard = MIXED; + else if (strcmp(arg[iarg + 1], "no") == 0) + discard = NODISCARD; + else if (strcmp(arg[iarg + 1], "yes") == 0) + discard = YESDISCARD; + else + error->all(FLERR, "Illegal compute chunk/atom command"); discardsetflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"bound") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "bound") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); int idim = 0; - if (strcmp(arg[iarg+1],"x") == 0) idim = 0; - else if (strcmp(arg[iarg+1],"y") == 0) idim = 1; - else if (strcmp(arg[iarg+1],"z") == 0) idim = 2; - else error->all(FLERR,"Illegal compute chunk/atom command"); + if (strcmp(arg[iarg + 1], "x") == 0) + idim = 0; + else if (strcmp(arg[iarg + 1], "y") == 0) + idim = 1; + else if (strcmp(arg[iarg + 1], "z") == 0) + idim = 2; + else + error->all(FLERR, "Illegal compute chunk/atom command"); minflag[idim] = COORD; - if (strcmp(arg[iarg+2],"lower") == 0) minflag[idim] = LOWER; - else minvalue[idim] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + if (strcmp(arg[iarg + 2], "lower") == 0) + minflag[idim] = LOWER; + else + minvalue[idim] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); maxflag[idim] = COORD; - if (strcmp(arg[iarg+3],"upper") == 0) maxflag[idim] = UPPER; - else maxvalue[idim] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (strcmp(arg[iarg + 3], "upper") == 0) + maxflag[idim] = UPPER; + else + maxvalue[idim] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg+1],"box") == 0) scaleflag = BOX; - else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = LATTICE; - else if (strcmp(arg[iarg+1],"reduced") == 0) scaleflag = REDUCED; - else error->all(FLERR,"Illegal compute chunk/atom command"); + } else if (strcmp(arg[iarg], "units") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg + 1], "box") == 0) + scaleflag = BOX; + else if (strcmp(arg[iarg + 1], "lattice") == 0) + scaleflag = LATTICE; + else if (strcmp(arg[iarg + 1], "reduced") == 0) + scaleflag = REDUCED; + else + error->all(FLERR, "Illegal compute chunk/atom command"); iarg += 2; - } else if (strcmp(arg[iarg],"pbc") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute chunk/atom command"); - pbcflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "pbc") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute chunk/atom command"); + pbcflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else error->all(FLERR,"Illegal compute chunk/atom command"); + } else + error->all(FLERR, "Illegal compute chunk/atom command"); } // set nchunkflag and discard to default values if not explicitly set @@ -264,121 +284,126 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : if (!nchunksetflag) { if (binflag) { - if (scaleflag == REDUCED) nchunkflag = ONCE; - else nchunkflag = EVERY; + if (scaleflag == REDUCED) + nchunkflag = ONCE; + else + nchunkflag = EVERY; } if (which == ArgInfo::TYPE) nchunkflag = ONCE; if (which == ArgInfo::MOLECULE) { - if (regionflag) nchunkflag = EVERY; - else nchunkflag = ONCE; + if (regionflag) + nchunkflag = EVERY; + else + nchunkflag = ONCE; } if (compress) nchunkflag = EVERY; } if (!discardsetflag) { - if (binflag) discard = MIXED; - else discard = YESDISCARD; + if (binflag) + discard = MIXED; + else + discard = YESDISCARD; } // error checks if (which == ArgInfo::MOLECULE && !atom->molecule_flag) - error->all(FLERR,"Compute chunk/atom molecule for non-molecular system"); + error->all(FLERR, "Compute chunk/atom molecule for non-molecular system"); if (!binflag && discard == MIXED) - error->all(FLERR,"Compute chunk/atom without bins " + error->all(FLERR, + "Compute chunk/atom without bins " "cannot use discard mixed"); if (which == ArgInfo::BIN1D && delta[0] <= 0.0) - error->all(FLERR,"Illegal compute chunk/atom command"); + error->all(FLERR, "Illegal compute chunk/atom command"); if (which == ArgInfo::BIN2D && (delta[0] <= 0.0 || delta[1] <= 0.0)) - error->all(FLERR,"Illegal compute chunk/atom command"); + error->all(FLERR, "Illegal compute chunk/atom command"); if (which == ArgInfo::BIN2D && (dim[0] == dim[1])) - error->all(FLERR,"Illegal compute chunk/atom command"); - if (which == ArgInfo::BIN3D && - (delta[0] <= 0.0 || delta[1] <= 0.0 || delta[2] <= 0.0)) - error->all(FLERR,"Illegal compute chunk/atom command"); - if (which == ArgInfo::BIN3D && - (dim[0] == dim[1] || dim[1] == dim[2] || dim[0] == dim[2])) - error->all(FLERR,"Illegal compute chunk/atom command"); + error->all(FLERR, "Illegal compute chunk/atom command"); + if (which == ArgInfo::BIN3D && (delta[0] <= 0.0 || delta[1] <= 0.0 || delta[2] <= 0.0)) + error->all(FLERR, "Illegal compute chunk/atom command"); + if (which == ArgInfo::BIN3D && (dim[0] == dim[1] || dim[1] == dim[2] || dim[0] == dim[2])) + error->all(FLERR, "Illegal compute chunk/atom command"); if (which == ArgInfo::BINSPHERE) { if (domain->dimension == 2 && sorigin_user[2] != 0.0) - error->all(FLERR,"Compute chunk/atom sphere z origin must be 0.0 for 2d"); + error->all(FLERR, "Compute chunk/atom sphere z origin must be 0.0 for 2d"); if (sradmin_user < 0.0 || sradmin_user >= sradmax_user || nsbin < 1) - error->all(FLERR,"Illegal compute chunk/atom command"); + error->all(FLERR, "Illegal compute chunk/atom command"); } if (which == ArgInfo::BINCYLINDER) { - if (delta[0] <= 0.0) - error->all(FLERR,"Illegal compute chunk/atom command"); + if (delta[0] <= 0.0) error->all(FLERR, "Illegal compute chunk/atom command"); if (domain->dimension == 2 && dim[0] != 2) - error->all(FLERR,"Compute chunk/atom cylinder axis must be z for 2d"); + error->all(FLERR, "Compute chunk/atom cylinder axis must be z for 2d"); if (cradmin_user < 0.0 || cradmin_user >= cradmax_user || ncbin < 1) - error->all(FLERR,"Illegal compute chunk/atom command"); + error->all(FLERR, "Illegal compute chunk/atom command"); } if (which == ArgInfo::COMPUTE) { cchunk = modify->get_compute_by_id(cfvid); - if (!cchunk) - error->all(FLERR,"Compute ID {} for compute chunk /atom does not exist",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"); + 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"); + 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"); + 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"); + error->all(FLERR, "Compute chunk/atom compute array is accessed out-of-range"); } if (which == ArgInfo::FIX) { fchunk = modify->get_fix_by_id(cfvid); - if (!fchunk) - error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",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"); + 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"); + 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"); + 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"); + error->all(FLERR, "Compute chunk/atom fix array is accessed out-of-range"); } if (which == ArgInfo::VARIABLE) { int ivariable = input->variable->find(cfvid); - if (ivariable < 0) - error->all(FLERR,"Variable name for compute chunk/atom does not exist"); + 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) { xscale = domain->lattice->xlattice; yscale = domain->lattice->ylattice; zscale = domain->lattice->zlattice; - } else xscale = yscale = zscale = 1.0; + } else + xscale = yscale = zscale = 1.0; // apply scaling factors and cylinder dims orthogonal to axis if (binflag) { double scale = 1.0; - if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D - || which == ArgInfo::BIN3D || which == ArgInfo::BINCYLINDER) { + if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D || which == ArgInfo::BIN3D || + which == ArgInfo::BINCYLINDER) { if (which == ArgInfo::BIN1D || which == ArgInfo::BINCYLINDER) ndim = 1; if (which == ArgInfo::BIN2D) ndim = 2; if (which == ArgInfo::BIN3D) ndim = 3; for (int idim = 0; idim < ndim; idim++) { - if (dim[idim] == 0) scale = xscale; - else if (dim[idim] == 1) scale = yscale; - else if (dim[idim] == 2) scale = zscale; + if (dim[idim] == 0) + scale = xscale; + else if (dim[idim] == 1) + scale = yscale; + else if (dim[idim] == 2) + scale = zscale; delta[idim] *= scale; - invdelta[idim] = 1.0/delta[idim]; + invdelta[idim] = 1.0 / delta[idim]; if (originflag[idim] == COORD) origin[idim] *= scale; if (minflag[idim] == COORD) minvalue[idim] *= scale; if (maxflag[idim] == COORD) maxvalue[idim] *= scale; @@ -387,13 +412,13 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : sorigin_user[0] *= xscale; sorigin_user[1] *= yscale; sorigin_user[2] *= zscale; - sradmin_user *= xscale; // radii are scaled by xscale + sradmin_user *= xscale; // radii are scaled by xscale sradmax_user *= xscale; } else if (which == ArgInfo::BINCYLINDER) { if (dim[0] == 0) { corigin_user[cdim1] *= yscale; corigin_user[cdim2] *= zscale; - cradmin_user *= yscale; // radii are scaled by first non-axis dim + cradmin_user *= yscale; // radii are scaled by first non-axis dim cradmax_user *= yscale; } else if (dim[0] == 1) { corigin_user[cdim1] *= xscale; @@ -426,8 +451,10 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : // computeflag = 1 if this compute might invoke another compute // during assign_chunk_ids() - if (which == ArgInfo::COMPUTE || which == ArgInfo::FIX || which == ArgInfo::VARIABLE) computeflag = 1; - else computeflag = 0; + if (which == ArgInfo::COMPUTE || which == ArgInfo::FIX || which == ArgInfo::VARIABLE) + computeflag = 1; + else + computeflag = 0; // other initializations @@ -437,8 +464,10 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : id_fix = nullptr; fixstore = nullptr; - if (compress) hash = new std::map(); - else hash = nullptr; + if (compress) + hash = new std::map(); + else + hash = nullptr; maxvar = 0; varatom = nullptr; @@ -446,8 +475,10 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : lockcount = 0; lockfix = nullptr; - if (which == ArgInfo::MOLECULE) molcheck = 1; - else molcheck = 0; + if (which == ArgInfo::MOLECULE) + molcheck = 1; + else + molcheck = 0; } /* ---------------------------------------------------------------------- */ @@ -457,7 +488,7 @@ ComputeChunkAtom::~ComputeChunkAtom() // check nfix in case all fixes have already been deleted if (id_fix && modify->nfix) modify->delete_fix(id_fix); - delete [] id_fix; + delete[] id_fix; memory->destroy(chunk); memory->destroy(ichunk); @@ -466,8 +497,8 @@ ComputeChunkAtom::~ComputeChunkAtom() memory->destroy(coord); memory->destroy(chunkID); - delete [] idregion; - delete [] cfvid; + delete[] idregion; + delete[] cfvid; delete hash; memory->destroy(varatom); @@ -480,26 +511,21 @@ void ComputeChunkAtom::init() // set and check validity of region if (regionflag) { - int iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for compute chunk/atom does not exist"); - region = domain->regions[iregion]; + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for compute chunk/atom does not exist", idregion); } // set compute,fix,variable if (which == ArgInfo::COMPUTE) { cchunk = modify->get_compute_by_id(cfvid); - if (!cchunk) - error->all(FLERR,"Compute ID {} for compute chunk/atom does not exist",cfvid); + if (!cchunk) error->all(FLERR, "Compute ID {} for compute chunk/atom does not exist", cfvid); } else if (which == ArgInfo::FIX) { fchunk = modify->get_fix_by_id(cfvid); - if (!fchunk) - error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",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) - error->all(FLERR,"Variable name for compute chunk/atom does not exist"); + if (ivariable < 0) error->all(FLERR, "Variable name for compute chunk/atom does not exist"); vchunk = ivariable; } @@ -513,9 +539,8 @@ void ComputeChunkAtom::init() for (int i = 0; i < nlocal; i++) if (molecule[i] > maxone) maxone = molecule[i]; tagint maxall; - MPI_Allreduce(&maxone,&maxall,1,MPI_LMP_TAGINT,MPI_MAX,world); - if (maxall > MAXSMALLINT) - error->all(FLERR,"Molecule IDs too large for compute chunk/atom"); + MPI_Allreduce(&maxone, &maxall, 1, MPI_LMP_TAGINT, MPI_MAX, world); + if (maxall > MAXSMALLINT) error->all(FLERR, "Molecule IDs too large for compute chunk/atom"); } // for binning, if nchunkflag not already set, set it to ONCE or EVERY @@ -526,7 +551,8 @@ void ComputeChunkAtom::init() if (domain->box_change_size == 0) { if (nchunkflag == EVERY && invoked_setup >= 0) invoked_setup = -1; nchunkflag = ONCE; - } else nchunkflag = EVERY; + } else + nchunkflag = EVERY; } // require nchunkflag = ONCE if idsflag = ONCE @@ -534,7 +560,7 @@ void ComputeChunkAtom::init() // can't check until now since nchunkflag may have been adjusted in init() if (idsflag == ONCE && nchunkflag != ONCE) - error->all(FLERR,"Compute chunk/atom ids once but nchunk is not once"); + error->all(FLERR, "Compute chunk/atom ids once but nchunk is not once"); // create/destroy fix STORE for persistent chunk IDs as needed // need to do this if idsflag = ONCE or locks will be used by other commands @@ -545,8 +571,8 @@ void ComputeChunkAtom::init() if ((idsflag == ONCE || lockcount) && !fixstore) { id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); - fixstore = dynamic_cast( modify->add_fix(fmt::format("{} {} STORE peratom 1 1", - id_fix, group->names[igroup]))); + fixstore = dynamic_cast( + modify->add_fix(fmt::format("{} {} STORE peratom 1 1", id_fix, group->names[igroup]))); } if ((idsflag != ONCE && !lockcount) && fixstore) { @@ -564,8 +590,10 @@ void ComputeChunkAtom::init() void ComputeChunkAtom::setup() { if (nchunkflag == ONCE) setup_chunks(); - if (idsflag == ONCE) compute_ichunk(); - else invoked_ichunk = -1; + if (idsflag == ONCE) + compute_ichunk(); + else + invoked_ichunk = -1; } /* ---------------------------------------------------------------------- @@ -584,7 +612,7 @@ void ComputeChunkAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(chunk); nmax = atom->nmax; - memory->create(chunk,nmax,"chunk/atom:chunk"); + memory->create(chunk, nmax, "chunk/atom:chunk"); vector_atom = chunk; } @@ -597,15 +625,13 @@ void ComputeChunkAtom::compute_peratom() for (int i = 0; i < nlocal; i++) chunk[i] = ichunk[i]; } - /* ---------------------------------------------------------------------- to return the number of chunks, we first need to make certain that compute_peratom() has been called. ------------------------------------------------------------------------- */ double ComputeChunkAtom::compute_scalar() { - if (invoked_peratom != update->ntimestep) - compute_peratom(); + if (invoked_peratom != update->ntimestep) compute_peratom(); invoked_scalar = update->ntimestep; return (scalar = nchunk); @@ -631,7 +657,8 @@ void ComputeChunkAtom::lock(Fix *fixptr, bigint startstep, bigint stopstep) } if (startstep != lockstart || stopstep != lockstop) - error->all(FLERR,"Two fix commands using " + error->all(FLERR, + "Two fix commands using " "same compute chunk/atom command in incompatible ways"); // set lock to last calling Fix, since it will be last to unlock() @@ -675,7 +702,7 @@ void ComputeChunkAtom::compute_ichunk() if (restore) { invoked_ichunk = update->ntimestep; double *vstore = fixstore->vstore; - for (i = 0; i < nlocal; i++) ichunk[i] = static_cast (vstore[i]); + for (i = 0; i < nlocal; i++) ichunk[i] = static_cast(vstore[i]); return; } @@ -695,30 +722,37 @@ void ComputeChunkAtom::compute_ichunk() if (binflag) { for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - if (hash->find(ichunk[i]) == hash->end()) exclude[i] = 1; - else ichunk[i] = hash->find(ichunk[i])->second; + if (hash->find(ichunk[i]) == hash->end()) + exclude[i] = 1; + else + ichunk[i] = hash->find(ichunk[i])->second; } } else if (discard == NODISCARD) { for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - if (hash->find(ichunk[i]) == hash->end()) ichunk[i] = nchunk; - else ichunk[i] = hash->find(ichunk[i])->second; + if (hash->find(ichunk[i]) == hash->end()) + ichunk[i] = nchunk; + else + ichunk[i] = hash->find(ichunk[i])->second; } } else { for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - if (hash->find(ichunk[i]) == hash->end()) exclude[i] = 1; - else ichunk[i] = hash->find(ichunk[i])->second; + if (hash->find(ichunk[i]) == hash->end()) + exclude[i] = 1; + else + ichunk[i] = hash->find(ichunk[i])->second; } } - // else if no compression apply discard rule by itself + // else if no compression apply discard rule by itself } else { if (discard == NODISCARD) { for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - if (ichunk[i] < 1 || ichunk[i] > nchunk) ichunk[i] = nchunk;; + if (ichunk[i] < 1 || ichunk[i] > nchunk) ichunk[i] = nchunk; + ; } } else { for (i = 0; i < nlocal; i++) { @@ -776,8 +810,7 @@ int ComputeChunkAtom::setup_chunks() if (nchunkflag == ONCE && invoked_setup >= 0) flag = 1; if (flag) { - if (binflag && scaleflag == REDUCED && domain->box_change_size) - bin_volumes(); + if (binflag && scaleflag == REDUCED && domain->box_change_size) bin_volumes(); return nchunk; } @@ -790,11 +823,12 @@ int ComputeChunkAtom::setup_chunks() // IDs are needed to scan for max ID and for compress() if (binflag) { - if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D - || which == ArgInfo::BIN3D) + if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D || which == ArgInfo::BIN3D) nchunk = setup_xyz_bins(); - else if (which == ArgInfo::BINSPHERE) nchunk = setup_sphere_bins(); - else if (which == ArgInfo::BINCYLINDER) nchunk = setup_cylinder_bins(); + else if (which == ArgInfo::BINSPHERE) + nchunk = setup_sphere_bins(); + else if (which == ArgInfo::BINCYLINDER) + nchunk = setup_cylinder_bins(); bin_volumes(); } else { chunk_volume_scalar = domain->xprd * domain->yprd; @@ -806,7 +840,8 @@ int ComputeChunkAtom::setup_chunks() // set nchunk for chunk styles other than binning // for styles other than TYPE, scan for max ID - if (which == ArgInfo::TYPE) nchunk = atom->ntypes; + if (which == ArgInfo::TYPE) + nchunk = atom->ntypes; else if (!binflag) { int nlocal = atom->nlocal; @@ -816,7 +851,7 @@ int ComputeChunkAtom::setup_chunks() if (ichunk[i] > hi) hi = ichunk[i]; } - MPI_Allreduce(&hi,&nchunk,1,MPI_INT,MPI_MAX,world); + MPI_Allreduce(&hi, &nchunk, 1, MPI_INT, MPI_MAX, world); if (nchunk <= 0) nchunk = 1; } @@ -826,18 +861,22 @@ int ComputeChunkAtom::setup_chunks() if (limit && !binflag) { if (!compress) { - if (limitstyle == LIMITMAX) nchunk = MIN(nchunk,limit); - else if (limitstyle == LIMITEXACT) nchunk = limit; + if (limitstyle == LIMITMAX) + nchunk = MIN(nchunk, limit); + else if (limitstyle == LIMITEXACT) + nchunk = limit; } else if (limitfirst) { - nchunk = MIN(nchunk,limit); + nchunk = MIN(nchunk, limit); } } if (compress) compress_chunk_ids(); if (limit && !binflag && compress) { - if (limitstyle == LIMITMAX) nchunk = MIN(nchunk,limit); - else if (limitstyle == LIMITEXACT) nchunk = limit; + if (limitstyle == LIMITMAX) + nchunk = MIN(nchunk, limit); + else if (limitstyle == LIMITEXACT) + nchunk = limit; } return nchunk; @@ -861,8 +900,8 @@ void ComputeChunkAtom::assign_chunk_ids() memory->destroy(ichunk); memory->destroy(exclude); nmaxint = atom->nmax; - memory->create(ichunk,nmaxint,"chunk/atom:ichunk"); - memory->create(exclude,nmaxint,"chunk/atom:exclude"); + memory->create(ichunk, nmaxint, "chunk/atom:ichunk"); + memory->create(exclude, nmaxint, "chunk/atom:exclude"); } // update region if necessary @@ -878,14 +917,17 @@ void ComputeChunkAtom::assign_chunk_ids() if (regionflag) { for (i = 0; i < nlocal; i++) { - if (mask[i] & groupbit && - region->match(x[i][0],x[i][1],x[i][2])) exclude[i] = 0; - else exclude[i] = 1; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + exclude[i] = 0; + else + exclude[i] = 1; } } else { for (i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) exclude[i] = 0; - else exclude[i] = 1; + if (mask[i] & groupbit) + exclude[i] = 0; + else + exclude[i] = 1; } } @@ -893,11 +935,16 @@ void ComputeChunkAtom::assign_chunk_ids() // binning styles apply discard rule, others do not yet if (binflag) { - if (which == ArgInfo::BIN1D) atom2bin1d(); - else if (which == ArgInfo::BIN2D) atom2bin2d(); - else if (which == ArgInfo::BIN3D) atom2bin3d(); - else if (which == ArgInfo::BINSPHERE) atom2binsphere(); - else if (which == ArgInfo::BINCYLINDER) atom2bincylinder(); + if (which == ArgInfo::BIN1D) + atom2bin1d(); + else if (which == ArgInfo::BIN2D) + atom2bin2d(); + else if (which == ArgInfo::BIN3D) + atom2bin3d(); + else if (which == ArgInfo::BINSPHERE) + atom2binsphere(); + else if (which == ArgInfo::BINCYLINDER) + atom2bincylinder(); } else if (which == ArgInfo::TYPE) { int *type = atom->type; @@ -910,7 +957,7 @@ void ComputeChunkAtom::assign_chunk_ids() tagint *molecule = atom->molecule; for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (molecule[i]); + ichunk[i] = static_cast(molecule[i]); } } else if (which == ArgInfo::COMPUTE) { @@ -923,34 +970,35 @@ void ComputeChunkAtom::assign_chunk_ids() double *vec = cchunk->vector_atom; for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (vec[i]); + ichunk[i] = static_cast(vec[i]); } } else { double **array = cchunk->array_atom; int argm1 = argindex - 1; for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (array[i][argm1]); + ichunk[i] = static_cast(array[i][argm1]); } } } else if (which == ArgInfo::FIX) { if (update->ntimestep % fchunk->peratom_freq) - error->all(FLERR,"Fix used in compute chunk/atom not " + error->all(FLERR, + "Fix used in compute chunk/atom not " "computed at compatible time"); if (argindex == 0) { double *vec = fchunk->vector_atom; for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (vec[i]); + ichunk[i] = static_cast(vec[i]); } } else { double **array = fchunk->array_atom; int argm1 = argindex - 1; for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (array[i][argm1]); + ichunk[i] = static_cast(array[i][argm1]); } } @@ -958,13 +1006,13 @@ void ComputeChunkAtom::assign_chunk_ids() if (atom->nmax > maxvar) { maxvar = atom->nmax; memory->destroy(varatom); - memory->create(varatom,maxvar,"chunk/atom:varatom"); + memory->create(varatom, maxvar, "chunk/atom:varatom"); } - input->variable->compute_atom(vchunk,igroup,varatom,1,0); + input->variable->compute_atom(vchunk, igroup, varatom, 1, 0); for (i = 0; i < nlocal; i++) { if (exclude[i]) continue; - ichunk[i] = static_cast (varatom[i]); + ichunk[i] = static_cast(varatom[i]); } } } @@ -1001,17 +1049,16 @@ void ComputeChunkAtom::compress_chunk_ids() int n = hash->size(); bigint nbone = n; bigint nball; - MPI_Allreduce(&nbone,&nball,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&nbone, &nball, 1, MPI_LMP_BIGINT, MPI_SUM, world); // create my list of populated IDs int *list = nullptr; - memory->create(list,n,"chunk/atom:list"); + memory->create(list, n, "chunk/atom:list"); n = 0; - std::map::iterator pos; - for (pos = hash->begin(); pos != hash->end(); ++pos) - list[n++] = pos->first; + std::map::iterator pos; + for (pos = hash->begin(); pos != hash->end(); ++pos) list[n++] = pos->first; // if nall < 1M, just allgather all ID lists on every proc // else perform ring comm @@ -1023,20 +1070,20 @@ void ComputeChunkAtom::compress_chunk_ids() int nprocs = comm->nprocs; int nall = nball; - int *recvcounts,*displs,*listall; - memory->create(recvcounts,nprocs,"chunk/atom:recvcounts"); - memory->create(displs,nprocs,"chunk/atom:displs"); - memory->create(listall,nall,"chunk/atom:listall"); + int *recvcounts, *displs, *listall; + memory->create(recvcounts, nprocs, "chunk/atom:recvcounts"); + memory->create(displs, nprocs, "chunk/atom:displs"); + memory->create(listall, nall, "chunk/atom:listall"); - MPI_Allgather(&n,1,MPI_INT,recvcounts,1,MPI_INT,world); + MPI_Allgather(&n, 1, MPI_INT, recvcounts, 1, MPI_INT, world); displs[0] = 0; for (int iproc = 1; iproc < nprocs; iproc++) - displs[iproc] = displs[iproc-1] + recvcounts[iproc-1]; + displs[iproc] = displs[iproc - 1] + recvcounts[iproc - 1]; // allgatherv acquires list of populated IDs from all procs - MPI_Allgatherv(list,n,MPI_INT,listall,recvcounts,displs,MPI_INT,world); + MPI_Allgatherv(list, n, MPI_INT, listall, recvcounts, displs, MPI_INT, world); // add all unique IDs in listall to my hash @@ -1050,7 +1097,7 @@ void ComputeChunkAtom::compress_chunk_ids() memory->destroy(listall); } else { - comm->ring(n,sizeof(int),list,1,idring,nullptr,(void *)this,0); + comm->ring(n, sizeof(int), list, 1, idring, nullptr, (void *) this, 0); } memory->destroy(list); @@ -1066,7 +1113,7 @@ void ComputeChunkAtom::compress_chunk_ids() // used by fix ave/chunk and compute property/chunk memory->destroy(chunkID); - memory->create(chunkID,nchunk,"chunk/atom:chunkID"); + memory->create(chunkID, nchunk, "chunk/atom:chunkID"); n = 0; for (pos = hash->begin(); pos != hash->end(); ++pos) { @@ -1084,9 +1131,9 @@ void ComputeChunkAtom::compress_chunk_ids() void ComputeChunkAtom::idring(int n, char *cbuf, void *ptr) { - auto cptr = (ComputeChunkAtom *)ptr; + auto cptr = (ComputeChunkAtom *) ptr; auto list = (tagint *) cbuf; - std::map *hash = cptr->hash; + std::map *hash = cptr->hash; for (int i = 0; i < n; i++) (*hash)[list[i]] = 0; } @@ -1109,22 +1156,20 @@ void ComputeChunkAtom::check_molecules() if (!compress) { for (int i = 0; i < nlocal; i++) { - if (molecule[i] > 0 && molecule[i] <= nchunk && - ichunk[i] == 0) flag = 1; + if (molecule[i] > 0 && molecule[i] <= nchunk && ichunk[i] == 0) flag = 1; } } else { int molid; for (int i = 0; i < nlocal; i++) { - molid = static_cast (molecule[i]); + molid = static_cast(molecule[i]); if (hash->find(molid) != hash->end() && ichunk[i] == 0) flag = 1; } } int flagall; - MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); if (flagall && comm->me == 0) - error->warning(FLERR, - "One or more chunks do not contain all atoms in molecule"); + error->warning(FLERR, "One or more chunks do not contain all atoms in molecule"); } /* ---------------------------------------------------------------------- @@ -1135,14 +1180,14 @@ void ComputeChunkAtom::check_molecules() int ComputeChunkAtom::setup_xyz_bins() { - int i,j,k,m,n,idim; - double lo,hi,coord1,coord2; + int i, j, k, m, n, idim; + double lo, hi, coord1, coord2; // lo = bin boundary immediately below boxlo or minvalue // hi = bin boundary immediately above boxhi or maxvalue // allocate and initialize arrays based on new bin count - double binlo[3],binhi[3]; + double binlo[3], binhi[3]; if (scaleflag == REDUCED) { binlo[0] = domain->boxlo_lamda[0]; binlo[1] = domain->boxlo_lamda[1]; @@ -1170,63 +1215,64 @@ int ComputeChunkAtom::setup_xyz_bins() for (m = 0; m < ndim; m++) { idim = dim[m]; - if (originflag[m] == LOWER) origin[m] = binlo[idim]; - else if (originflag[m] == UPPER) origin[m] = binhi[idim]; + if (originflag[m] == LOWER) + origin[m] = binlo[idim]; + else if (originflag[m] == UPPER) + origin[m] = binhi[idim]; else if (originflag[m] == CENTER) origin[m] = 0.5 * (binlo[idim] + binhi[idim]); if (origin[m] < binlo[idim]) { - n = static_cast ((binlo[idim] - origin[m]) * invdelta[m]); - lo = origin[m] + n*delta[m]; + n = static_cast((binlo[idim] - origin[m]) * invdelta[m]); + lo = origin[m] + n * delta[m]; } else { - n = static_cast ((origin[m] - binlo[idim]) * invdelta[m]); - lo = origin[m] - n*delta[m]; + n = static_cast((origin[m] - binlo[idim]) * invdelta[m]); + lo = origin[m] - n * delta[m]; if (lo > binlo[idim]) lo -= delta[m]; } if (origin[m] < binhi[idim]) { - n = static_cast ((binhi[idim] - origin[m]) * invdelta[m]); - hi = origin[m] + n*delta[m]; + n = static_cast((binhi[idim] - origin[m]) * invdelta[m]); + hi = origin[m] + n * delta[m]; if (hi < binhi[idim]) hi += delta[m]; } else { - n = static_cast ((origin[m] - binhi[idim]) * invdelta[m]); - hi = origin[m] - n*delta[m]; + n = static_cast((origin[m] - binhi[idim]) * invdelta[m]); + hi = origin[m] - n * delta[m]; } - if (lo > hi) error->all(FLERR,"Invalid bin bounds in compute chunk/atom"); + if (lo > hi) error->all(FLERR, "Invalid bin bounds in compute chunk/atom"); offset[m] = lo; - nlayers[m] = static_cast ((hi-lo) * invdelta[m] + 0.5); + nlayers[m] = static_cast((hi - lo) * invdelta[m] + 0.5); nbins *= nlayers[m]; } // allocate and set bin coordinates memory->destroy(coord); - memory->create(coord,nbins,ndim,"chunk/atom:coord"); + memory->create(coord, nbins, ndim, "chunk/atom:coord"); if (ndim == 1) { - for (i = 0; i < nlayers[0]; i++) - coord[i][0] = offset[0] + (i+0.5)*delta[0]; + for (i = 0; i < nlayers[0]; i++) coord[i][0] = offset[0] + (i + 0.5) * delta[0]; } else if (ndim == 2) { m = 0; for (i = 0; i < nlayers[0]; i++) { - coord1 = offset[0] + (i+0.5)*delta[0]; + coord1 = offset[0] + (i + 0.5) * delta[0]; for (j = 0; j < nlayers[1]; j++) { coord[m][0] = coord1; - coord[m][1] = offset[1] + (j+0.5)*delta[1]; + coord[m][1] = offset[1] + (j + 0.5) * delta[1]; m++; } } } else if (ndim == 3) { m = 0; for (i = 0; i < nlayers[0]; i++) { - coord1 = offset[0] + (i+0.5)*delta[0]; + coord1 = offset[0] + (i + 0.5) * delta[0]; for (j = 0; j < nlayers[1]; j++) { - coord2 = offset[1] + (j+0.5)*delta[1]; + coord2 = offset[1] + (j + 0.5) * delta[1]; for (k = 0; k < nlayers[2]; k++) { coord[m][0] = coord1; coord[m][1] = coord2; - coord[m][2] = offset[2] + (k+0.5)*delta[2]; + coord[m][2] = offset[2] + (k + 0.5) * delta[2]; m++; } } @@ -1249,9 +1295,9 @@ int ComputeChunkAtom::setup_sphere_bins() // lamda2x works for either orthogonal or triclinic if (scaleflag == REDUCED) { - domain->lamda2x(sorigin_user,sorigin); - sradmin = sradmin_user * (domain->boxhi[0]-domain->boxlo[0]); - sradmax = sradmax_user * (domain->boxhi[0]-domain->boxlo[0]); + domain->lamda2x(sorigin_user, sorigin); + sradmin = sradmin_user * (domain->boxhi[0] - domain->boxlo[0]); + sradmax = sradmax_user * (domain->boxhi[0] - domain->boxlo[0]); } else { sorigin[0] = sorigin_user[0]; sorigin[1] = sorigin_user[1]; @@ -1270,28 +1316,28 @@ int ComputeChunkAtom::setup_sphere_bins() int flag = 0; if (periodicity[0] && sradmax > prd_half[0]) flag = 1; if (periodicity[1] && sradmax > prd_half[1]) flag = 1; - if (domain->dimension == 3 && - periodicity[2] && sradmax > prd_half[2]) flag = 1; + if (domain->dimension == 3 && periodicity[2] && sradmax > prd_half[2]) flag = 1; if (flag) - error->all(FLERR,"Compute chunk/atom bin/sphere radius " + error->all(FLERR, + "Compute chunk/atom bin/sphere radius " "is too large for periodic box"); } - sinvrad = nsbin / (sradmax-sradmin); + sinvrad = nsbin / (sradmax - sradmin); // allocate and set bin coordinates // coord = midpt of radii for a spherical shell memory->destroy(coord); - memory->create(coord,nsbin,1,"chunk/atom:coord"); + memory->create(coord, nsbin, 1, "chunk/atom:coord"); - double rlo,rhi; + double rlo, rhi; for (int i = 0; i < nsbin; i++) { - rlo = sradmin + i * (sradmax-sradmin) / nsbin; - rhi = sradmin + (i+1) * (sradmax-sradmin) / nsbin; - if (i == nsbin-1) rhi = sradmax; - coord[i][0] = 0.5 * (rlo+rhi); + rlo = sradmin + i * (sradmax - sradmin) / nsbin; + rhi = sradmin + (i + 1) * (sradmax - sradmin) / nsbin; + if (i == nsbin - 1) rhi = sradmax; + coord[i][0] = 0.5 * (rlo + rhi); } return nsbin; @@ -1315,9 +1361,9 @@ int ComputeChunkAtom::setup_cylinder_bins() // lamda2x works for either orthogonal or triclinic if (scaleflag == REDUCED) { - domain->lamda2x(corigin_user,corigin); - cradmin = cradmin_user * (domain->boxhi[cdim1]-domain->boxlo[cdim1]); - cradmax = cradmax_user * (domain->boxhi[cdim1]-domain->boxlo[cdim1]); + domain->lamda2x(corigin_user, corigin); + cradmin = cradmin_user * (domain->boxhi[cdim1] - domain->boxlo[cdim1]); + cradmax = cradmax_user * (domain->boxhi[cdim1] - domain->boxlo[cdim1]); } else { corigin[cdim1] = corigin_user[cdim1]; corigin[cdim2] = corigin_user[cdim2]; @@ -1336,11 +1382,12 @@ int ComputeChunkAtom::setup_cylinder_bins() if (periodicity[cdim1] && sradmax > prd_half[cdim1]) flag = 1; if (periodicity[cdim2] && sradmax > prd_half[cdim2]) flag = 1; if (flag) - error->all(FLERR,"Compute chunk/atom bin/cylinder radius " + error->all(FLERR, + "Compute chunk/atom bin/cylinder radius " "is too large for periodic box"); } - cinvrad = ncbin / (cradmax-cradmin); + cinvrad = ncbin / (cradmax - cradmin); // allocate and set radial bin coordinates // radial coord = midpt of radii for a cylindrical shell @@ -1348,21 +1395,21 @@ int ComputeChunkAtom::setup_cylinder_bins() // radcoord = saved bin coords in radial direction double **axiscoord = coord; - memory->create(coord,ncbin,1,"chunk/atom:coord"); + memory->create(coord, ncbin, 1, "chunk/atom:coord"); double **radcoord = coord; - double rlo,rhi; + double rlo, rhi; for (int i = 0; i < ncbin; i++) { - rlo = cradmin + i * (cradmax-cradmin) / ncbin; - rhi = cradmin + (i+1) * (cradmax-cradmin) / ncbin; - if (i == ncbin-1) rhi = cradmax; - coord[i][0] = 0.5 * (rlo+rhi); + rlo = cradmin + i * (cradmax - cradmin) / ncbin; + rhi = cradmin + (i + 1) * (cradmax - cradmin) / ncbin; + if (i == ncbin - 1) rhi = cradmax; + coord[i][0] = 0.5 * (rlo + rhi); } // create array of combined coords for all bins - memory->create(coord,ncbin*ncplane,2,"chunk/atom:coord"); + memory->create(coord, ncbin * ncplane, 2, "chunk/atom:coord"); int m = 0; for (int i = 0; i < ncbin; i++) for (int j = 0; j < ncplane; j++) { @@ -1373,7 +1420,7 @@ int ComputeChunkAtom::setup_cylinder_bins() memory->destroy(axiscoord); memory->destroy(radcoord); - return ncbin*ncplane; + return ncbin * ncplane; } /* ---------------------------------------------------------------------- @@ -1384,53 +1431,56 @@ int ComputeChunkAtom::setup_cylinder_bins() void ComputeChunkAtom::bin_volumes() { - if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D - || which == ArgInfo::BIN3D) { + if (which == ArgInfo::BIN1D || which == ArgInfo::BIN2D || which == ArgInfo::BIN3D) { if (domain->dimension == 3) chunk_volume_scalar = domain->xprd * domain->yprd * domain->zprd; - else chunk_volume_scalar = domain->xprd * domain->yprd; + else + chunk_volume_scalar = domain->xprd * domain->yprd; double *prd; - if (scaleflag == REDUCED) prd = domain->prd_lamda; - else prd = domain->prd; - for (int m = 0; m < ndim; m++) - chunk_volume_scalar *= delta[m]/prd[dim[m]]; + if (scaleflag == REDUCED) + prd = domain->prd_lamda; + else + prd = domain->prd; + for (int m = 0; m < ndim; m++) chunk_volume_scalar *= delta[m] / prd[dim[m]]; } else if (which == ArgInfo::BINSPHERE) { memory->destroy(chunk_volume_vec); - memory->create(chunk_volume_vec,nchunk,"chunk/atom:chunk_volume_vec"); - double rlo,rhi,vollo,volhi; + memory->create(chunk_volume_vec, nchunk, "chunk/atom:chunk_volume_vec"); + double rlo, rhi, vollo, volhi; for (int i = 0; i < nchunk; i++) { - rlo = sradmin + i * (sradmax-sradmin) / nsbin; - rhi = sradmin + (i+1) * (sradmax-sradmin) / nsbin; - if (i == nchunk-1) rhi = sradmax; - vollo = 4.0/3.0 * MY_PI * rlo*rlo*rlo; - volhi = 4.0/3.0 * MY_PI * rhi*rhi*rhi; + rlo = sradmin + i * (sradmax - sradmin) / nsbin; + rhi = sradmin + (i + 1) * (sradmax - sradmin) / nsbin; + if (i == nchunk - 1) rhi = sradmax; + vollo = 4.0 / 3.0 * MY_PI * rlo * rlo * rlo; + volhi = 4.0 / 3.0 * MY_PI * rhi * rhi * rhi; chunk_volume_vec[i] = volhi - vollo; } } else if (which == ArgInfo::BINCYLINDER) { memory->destroy(chunk_volume_vec); - memory->create(chunk_volume_vec,nchunk,"chunk/atom:chunk_volume_vec"); + memory->create(chunk_volume_vec, nchunk, "chunk/atom:chunk_volume_vec"); // slabthick = delta of bins along cylinder axis double *prd; - if (scaleflag == REDUCED) prd = domain->prd_lamda; - else prd = domain->prd; - double slabthick = domain->prd[dim[0]] * delta[0]/prd[dim[0]]; + if (scaleflag == REDUCED) + prd = domain->prd_lamda; + else + prd = domain->prd; + double slabthick = domain->prd[dim[0]] * delta[0] / prd[dim[0]]; // area lo/hi of concentric circles in radial direction int iradbin; - double rlo,rhi,arealo,areahi; + double rlo, rhi, arealo, areahi; for (int i = 0; i < nchunk; i++) { iradbin = i / ncplane; - rlo = cradmin + iradbin * (cradmax-cradmin) / ncbin; - rhi = cradmin + (iradbin+1) * (cradmax-cradmin) / ncbin; - if (iradbin == ncbin-1) rhi = cradmax; - arealo = MY_PI * rlo*rlo; - areahi = MY_PI * rhi*rhi; - chunk_volume_vec[i] = (areahi-arealo) * slabthick; + rlo = cradmin + iradbin * (cradmax - cradmin) / ncbin; + rhi = cradmin + (iradbin + 1) * (cradmax - cradmin) / ncbin; + if (iradbin == ncbin - 1) rhi = cradmax; + arealo = MY_PI * rlo * rlo; + areahi = MY_PI * rhi * rhi; + chunk_volume_vec[i] = (areahi - arealo) * slabthick; } } } @@ -1441,8 +1491,8 @@ void ComputeChunkAtom::bin_volumes() void ComputeChunkAtom::atom2bin1d() { - int i,ibin; - double *boxlo,*boxhi,*prd; + int i, ibin; + double *boxlo, *boxhi, *prd; double xremap; double **x = atom->x; @@ -1479,29 +1529,31 @@ void ComputeChunkAtom::atom2bin1d() if (xremap >= boxhi[idim]) xremap -= prd[idim]; } - ibin = static_cast ((xremap - offset[0]) * invdelta[0]); + ibin = static_cast((xremap - offset[0]) * invdelta[0]); if (xremap < offset[0]) ibin--; if (discard == MIXED) { - if (!minflag[idim]) ibin = MAX(ibin,0); + if (!minflag[idim]) + ibin = MAX(ibin, 0); else if (ibin < 0) { exclude[i] = 1; continue; } - if (!maxflag[idim]) ibin = MIN(ibin,nlayer1m1); + if (!maxflag[idim]) + ibin = MIN(ibin, nlayer1m1); else if (ibin > nlayer1m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - ibin = MAX(ibin,0); - ibin = MIN(ibin,nlayer1m1); + ibin = MAX(ibin, 0); + ibin = MIN(ibin, nlayer1m1); } else if (ibin < 0 || ibin > nlayer1m1) { exclude[i] = 1; continue; } - ichunk[i] = ibin+1; + ichunk[i] = ibin + 1; } if (scaleflag == REDUCED) domain->lamda2x(nlocal); @@ -1513,9 +1565,9 @@ void ComputeChunkAtom::atom2bin1d() void ComputeChunkAtom::atom2bin2d() { - int i,ibin,i1bin,i2bin; - double *boxlo,*boxhi,*prd; - double xremap,yremap; + int i, ibin, i1bin, i2bin; + double *boxlo, *boxhi, *prd; + double xremap, yremap; double **x = atom->x; int nlocal = atom->nlocal; @@ -1553,23 +1605,25 @@ void ComputeChunkAtom::atom2bin2d() if (xremap >= boxhi[idim]) xremap -= prd[idim]; } - i1bin = static_cast ((xremap - offset[0]) * invdelta[0]); + i1bin = static_cast((xremap - offset[0]) * invdelta[0]); if (xremap < offset[0]) i1bin--; if (discard == MIXED) { - if (!minflag[idim]) i1bin = MAX(i1bin,0); + if (!minflag[idim]) + i1bin = MAX(i1bin, 0); else if (i1bin < 0) { exclude[i] = 1; continue; } - if (!maxflag[idim]) i1bin = MIN(i1bin,nlayer1m1); + if (!maxflag[idim]) + i1bin = MIN(i1bin, nlayer1m1); else if (i1bin > nlayer1m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - i1bin = MAX(i1bin,0); - i1bin = MIN(i1bin,nlayer1m1); + i1bin = MAX(i1bin, 0); + i1bin = MIN(i1bin, nlayer1m1); } else if (i1bin < 0 || i1bin > nlayer1m1) { exclude[i] = 1; continue; @@ -1581,30 +1635,32 @@ void ComputeChunkAtom::atom2bin2d() if (yremap >= boxhi[jdim]) yremap -= prd[jdim]; } - i2bin = static_cast ((yremap - offset[1]) * invdelta[1]); + i2bin = static_cast((yremap - offset[1]) * invdelta[1]); if (yremap < offset[1]) i2bin--; if (discard == MIXED) { - if (!minflag[jdim]) i2bin = MAX(i2bin,0); + if (!minflag[jdim]) + i2bin = MAX(i2bin, 0); else if (i2bin < 0) { exclude[i] = 1; continue; } - if (!maxflag[jdim]) i2bin = MIN(i2bin,nlayer2m1); + if (!maxflag[jdim]) + i2bin = MIN(i2bin, nlayer2m1); else if (i2bin > nlayer2m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - i2bin = MAX(i2bin,0); - i2bin = MIN(i2bin,nlayer2m1); + i2bin = MAX(i2bin, 0); + i2bin = MIN(i2bin, nlayer2m1); } else if (i2bin < 0 || i2bin > nlayer2m1) { exclude[i] = 1; continue; } - ibin = i1bin*nlayers[1] + i2bin; - ichunk[i] = ibin+1; + ibin = i1bin * nlayers[1] + i2bin; + ichunk[i] = ibin + 1; } if (scaleflag == REDUCED) domain->lamda2x(nlocal); @@ -1616,9 +1672,9 @@ void ComputeChunkAtom::atom2bin2d() void ComputeChunkAtom::atom2bin3d() { - int i,ibin,i1bin,i2bin,i3bin; - double *boxlo,*boxhi,*prd; - double xremap,yremap,zremap; + int i, ibin, i1bin, i2bin, i3bin; + double *boxlo, *boxhi, *prd; + double xremap, yremap, zremap; double **x = atom->x; int nlocal = atom->nlocal; @@ -1658,23 +1714,25 @@ void ComputeChunkAtom::atom2bin3d() if (xremap >= boxhi[idim]) xremap -= prd[idim]; } - i1bin = static_cast ((xremap - offset[0]) * invdelta[0]); + i1bin = static_cast((xremap - offset[0]) * invdelta[0]); if (xremap < offset[0]) i1bin--; if (discard == MIXED) { - if (!minflag[idim]) i1bin = MAX(i1bin,0); + if (!minflag[idim]) + i1bin = MAX(i1bin, 0); else if (i1bin < 0) { exclude[i] = 1; continue; } - if (!maxflag[idim]) i1bin = MIN(i1bin,nlayer1m1); + if (!maxflag[idim]) + i1bin = MIN(i1bin, nlayer1m1); else if (i1bin > nlayer1m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - i1bin = MAX(i1bin,0); - i1bin = MIN(i1bin,nlayer1m1); + i1bin = MAX(i1bin, 0); + i1bin = MIN(i1bin, nlayer1m1); } else if (i1bin < 0 || i1bin > nlayer1m1) { exclude[i] = 1; continue; @@ -1686,23 +1744,25 @@ void ComputeChunkAtom::atom2bin3d() if (yremap >= boxhi[jdim]) yremap -= prd[jdim]; } - i2bin = static_cast ((yremap - offset[1]) * invdelta[1]); + i2bin = static_cast((yremap - offset[1]) * invdelta[1]); if (yremap < offset[1]) i2bin--; if (discard == MIXED) { - if (!minflag[jdim]) i2bin = MAX(i2bin,0); + if (!minflag[jdim]) + i2bin = MAX(i2bin, 0); else if (i2bin < 0) { exclude[i] = 1; continue; } - if (!maxflag[jdim]) i2bin = MIN(i2bin,nlayer2m1); + if (!maxflag[jdim]) + i2bin = MIN(i2bin, nlayer2m1); else if (i2bin > nlayer2m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - i2bin = MAX(i2bin,0); - i2bin = MIN(i2bin,nlayer2m1); + i2bin = MAX(i2bin, 0); + i2bin = MIN(i2bin, nlayer2m1); } else if (i2bin < 0 || i2bin > nlayer2m1) { exclude[i] = 1; continue; @@ -1714,30 +1774,32 @@ void ComputeChunkAtom::atom2bin3d() if (zremap >= boxhi[kdim]) zremap -= prd[kdim]; } - i3bin = static_cast ((zremap - offset[2]) * invdelta[2]); + i3bin = static_cast((zremap - offset[2]) * invdelta[2]); if (zremap < offset[2]) i3bin--; if (discard == MIXED) { - if (!minflag[kdim]) i3bin = MAX(i3bin,0); + if (!minflag[kdim]) + i3bin = MAX(i3bin, 0); else if (i3bin < 0) { exclude[i] = 1; continue; } - if (!maxflag[kdim]) i3bin = MIN(i3bin,nlayer3m1); + if (!maxflag[kdim]) + i3bin = MIN(i3bin, nlayer3m1); else if (i3bin > nlayer3m1) { exclude[i] = 1; continue; } } else if (discard == NODISCARD) { - i3bin = MAX(i3bin,0); - i3bin = MIN(i3bin,nlayer3m1); + i3bin = MAX(i3bin, 0); + i3bin = MIN(i3bin, nlayer3m1); } else if (i3bin < 0 || i3bin > nlayer3m1) { exclude[i] = 1; continue; } - ibin = i1bin*nlayers[1]*nlayers[2] + i2bin*nlayers[2] + i3bin; - ichunk[i] = ibin+1; + ibin = i1bin * nlayers[1] * nlayers[2] + i2bin * nlayers[2] + i3bin; + ichunk[i] = ibin + 1; } if (scaleflag == REDUCED) domain->lamda2x(nlocal); @@ -1749,9 +1811,9 @@ void ComputeChunkAtom::atom2bin3d() void ComputeChunkAtom::atom2binsphere() { - int i,ibin; - double dx,dy,dz,r; - double xremap,yremap,zremap; + int i, ibin; + double dx, dy, dz, r; + double xremap, yremap, zremap; double *boxlo = domain->boxlo; double *boxhi = domain->boxhi; @@ -1770,18 +1832,18 @@ void ComputeChunkAtom::atom2binsphere() xremap = x[i][0]; if (periodicity[0]) { - while (xremap < boxlo[0]) {xremap += prd[0];} - while (xremap >= boxhi[0]) {xremap -= prd[0];} + while (xremap < boxlo[0]) { xremap += prd[0]; } + while (xremap >= boxhi[0]) { xremap -= prd[0]; } } yremap = x[i][1]; if (periodicity[1]) { - while (yremap < boxlo[1]) {yremap += prd[1];} - while (yremap >= boxhi[1]) {yremap -= prd[1];} + while (yremap < boxlo[1]) { yremap += prd[1]; } + while (yremap >= boxhi[1]) { yremap -= prd[1]; } } zremap = x[i][2]; if (periodicity[2]) { - while (zremap < boxlo[2]) {zremap += prd[2];} - while (zremap >= boxhi[2]) {zremap -= prd[2];} + while (zremap < boxlo[2]) { zremap += prd[2]; } + while (zremap >= boxhi[2]) { zremap -= prd[2]; } } dx = xremap - sorigin[0]; @@ -1796,38 +1858,44 @@ void ComputeChunkAtom::atom2binsphere() if (pbcflag) { if (periodicity[0]) { while (fabs(dx) > prd_half[0]) { - if (dx < 0.0) dx += prd[0]; - else dx -= prd[0]; + if (dx < 0.0) + dx += prd[0]; + else + dx -= prd[0]; } } if (periodicity[1]) { while (fabs(dy) > prd_half[1]) { - if (dy < 0.0) dy += prd[1]; - else dy -= prd[1]; + if (dy < 0.0) + dy += prd[1]; + else + dy -= prd[1]; } } if (periodicity[2]) { while (fabs(dz) > prd_half[2]) { - if (dz < 0.0) dz += prd[2]; - else dz -= prd[2]; + if (dz < 0.0) + dz += prd[2]; + else + dz -= prd[2]; } } } - r = sqrt(dx*dx + dy*dy + dz*dz); + r = sqrt(dx * dx + dy * dy + dz * dz); - ibin = static_cast ((r - sradmin) * sinvrad); + ibin = static_cast((r - sradmin) * sinvrad); if (r < sradmin) ibin--; if (discard == MIXED || discard == NODISCARD) { - ibin = MAX(ibin,0); - ibin = MIN(ibin,nchunk-1); + ibin = MAX(ibin, 0); + ibin = MIN(ibin, nchunk - 1); } else if (ibin < 0 || ibin >= nchunk) { exclude[i] = 1; continue; } - ichunk[i] = ibin+1; + ichunk[i] = ibin + 1; } } @@ -1837,9 +1905,9 @@ void ComputeChunkAtom::atom2binsphere() void ComputeChunkAtom::atom2bincylinder() { - int i,rbin,kbin; - double d1,d2,r; - double remap1,remap2; + int i, rbin, kbin; + double d1, d2, r; + double remap1, remap2; // first use atom2bin1d() to bin all atoms along cylinder axis @@ -1886,26 +1954,30 @@ void ComputeChunkAtom::atom2bincylinder() if (pbcflag) { if (periodicity[cdim1]) { if (fabs(d1) > prd_half[cdim1]) { - if (d1 < 0.0) d1 += prd[cdim1]; - else d1 -= prd[cdim1]; + if (d1 < 0.0) + d1 += prd[cdim1]; + else + d1 -= prd[cdim1]; } } if (periodicity[cdim2]) { if (fabs(d2) > prd_half[cdim2]) { - if (d2 < 0.0) d2 += prd[cdim2]; - else d2 -= prd[cdim2]; + if (d2 < 0.0) + d2 += prd[cdim2]; + else + d2 -= prd[cdim2]; } } } - r = sqrt(d1*d1 + d2*d2); + r = sqrt(d1 * d1 + d2 * d2); - rbin = static_cast ((r - cradmin) * cinvrad); + rbin = static_cast((r - cradmin) * cinvrad); if (r < cradmin) rbin--; if (discard == MIXED || discard == NODISCARD) { - rbin = MAX(rbin,0); - rbin = MIN(rbin,ncbin-1); + rbin = MAX(rbin, 0); + rbin = MIN(rbin, ncbin - 1); } else if (rbin < 0 || rbin >= ncbin) { exclude[i] = 1; continue; @@ -1913,7 +1985,7 @@ void ComputeChunkAtom::atom2bincylinder() // combine axis and radial bin indices to set ichunk - ichunk[i] = rbin*ncplane + kbin + 1; + ichunk[i] = rbin * ncplane + kbin + 1; } } @@ -1924,23 +1996,30 @@ void ComputeChunkAtom::atom2bincylinder() void ComputeChunkAtom::readdim(int narg, char **arg, int iarg, int idim) { - if (narg < iarg+3) error->all(FLERR,"Illegal compute chunk/atom command"); - if (strcmp(arg[iarg],"x") == 0) dim[idim] = 0; - else if (strcmp(arg[iarg],"y") == 0) dim[idim] = 1; - else if (strcmp(arg[iarg],"z") == 0) dim[idim] = 2; - else error->all(FLERR,"Illegal compute chunk/atom command"); + if (narg < iarg + 3) error->all(FLERR, "Illegal compute chunk/atom command"); + if (strcmp(arg[iarg], "x") == 0) + dim[idim] = 0; + else if (strcmp(arg[iarg], "y") == 0) + dim[idim] = 1; + else if (strcmp(arg[iarg], "z") == 0) + dim[idim] = 2; + else + error->all(FLERR, "Illegal compute chunk/atom command"); if (dim[idim] == 2 && domain->dimension == 2) - error->all(FLERR,"Cannot use compute chunk/atom bin z for 2d model"); + error->all(FLERR, "Cannot use compute chunk/atom bin z for 2d model"); - if (strcmp(arg[iarg+1],"lower") == 0) originflag[idim] = LOWER; - else if (strcmp(arg[iarg+1],"center") == 0) originflag[idim] = CENTER; - else if (strcmp(arg[iarg+1],"upper") == 0) originflag[idim] = UPPER; - else originflag[idim] = COORD; - if (originflag[idim] == COORD) - origin[idim] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + if (strcmp(arg[iarg + 1], "lower") == 0) + originflag[idim] = LOWER; + else if (strcmp(arg[iarg + 1], "center") == 0) + originflag[idim] = CENTER; + else if (strcmp(arg[iarg + 1], "upper") == 0) + originflag[idim] = UPPER; + else + originflag[idim] = COORD; + if (originflag[idim] == COORD) origin[idim] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); - delta[idim] = utils::numeric(FLERR,arg[iarg+2],false,lmp); + delta[idim] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); } /* ---------------------------------------------------------------------- @@ -1962,9 +2041,9 @@ void ComputeChunkAtom::set_arrays(int i) double ComputeChunkAtom::memory_usage() { - double bytes = 2*MAX(nmaxint,0) * sizeof(int); // ichunk,exclude - bytes += (double)nmax * sizeof(double); // chunk - bytes += (double)ncoord*nchunk * sizeof(double); // coord - if (compress) bytes += (double)nchunk * sizeof(int); // chunkID + double bytes = 2 * MAX(nmaxint, 0) * sizeof(int); // ichunk,exclude + bytes += (double) nmax * sizeof(double); // chunk + bytes += (double) ncoord * nchunk * sizeof(double); // coord + if (compress) bytes += (double) nchunk * sizeof(int); // chunkID return bytes; } diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index e7cd73df19..f41a4eee4b 100644 --- a/src/compute_coord_atom.cpp +++ b/src/compute_coord_atom.cpp @@ -129,7 +129,7 @@ void ComputeCoordAtom::init() { if (cstyle == ORIENT) { int iorientorder = modify->find_compute(id_orientorder); - c_orientorder = dynamic_cast (modify->compute[iorientorder]); + c_orientorder = dynamic_cast(modify->compute[iorientorder]); cutsq = c_orientorder->cutsq; l = c_orientorder->qlcomp; // communicate real and imaginary 2*l+1 components of the normalized vector diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index 7b2059a0a0..9fbaa603ec 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -63,8 +63,8 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, a // id = compute-ID + COMPUTE_STORE, fix group = compute group id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); - fix = dynamic_cast( modify->add_fix( - fmt::format("{} {} STORE peratom 1 3", id_fix, group->names[igroup]))); + fix = dynamic_cast( + 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 @@ -127,7 +127,7 @@ void ComputeMSD::init() { // set fix which stores reference atom coords - fix = dynamic_cast( modify->get_fix_by_id(id_fix)); + fix = dynamic_cast(modify->get_fix_by_id(id_fix)); if (!fix) error->all(FLERR, "Could not find compute msd fix with ID {}", id_fix); // nmsd = # of atoms in group diff --git a/src/compute_orientorder_atom.cpp b/src/compute_orientorder_atom.cpp index 163f68e5ac..4f6bda7e2b 100644 --- a/src/compute_orientorder_atom.cpp +++ b/src/compute_orientorder_atom.cpp @@ -435,7 +435,7 @@ void ComputeOrientOrderAtom::calc_boop(double **rlist, int ncount, double qn[], for (int ineigh = 0; ineigh < ncount; ineigh++) { const double *const r = rlist[ineigh]; - double rmag = sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]); + double rmag = sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]); if (rmag <= MY_EPSILON) { return; } double costheta = r[2] / rmag; diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index b9800ae94e..018f658c61 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -35,41 +34,45 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - nvalues(0), which(nullptr), argindex(nullptr), flavor(nullptr), - value2index(nullptr), ids(nullptr), onevec(nullptr), replace(nullptr), indices(nullptr), - owner(nullptr), idregion(nullptr), varatom(nullptr) + Compute(lmp, narg, arg), nvalues(0), which(nullptr), argindex(nullptr), flavor(nullptr), + value2index(nullptr), ids(nullptr), onevec(nullptr), replace(nullptr), indices(nullptr), + owner(nullptr), idregion(nullptr), region(nullptr), varatom(nullptr) { int iarg = 0; - if (strcmp(style,"reduce") == 0) { - if (narg < 5) error->all(FLERR,"Illegal compute reduce command"); - idregion = nullptr; + if (strcmp(style, "reduce") == 0) { + if (narg < 5) error->all(FLERR, "Illegal compute reduce command"); iarg = 3; - } else if (strcmp(style,"reduce/region") == 0) { - if (narg < 6) error->all(FLERR,"Illegal compute reduce/region command"); - iregion = domain->find_region(arg[3]); - if (iregion == -1) - error->all(FLERR,"Region ID for compute reduce/region does not exist"); + } else if (strcmp(style, "reduce/region") == 0) { + if (narg < 6) error->all(FLERR, "Illegal compute reduce/region command"); + if (!domain->get_region_by_id(arg[3])) + error->all(FLERR, "Region {} for compute reduce/region does not exist", arg[3]); idregion = utils::strdup(arg[3]); iarg = 4; } - if (strcmp(arg[iarg],"sum") == 0) mode = SUM; - else if (strcmp(arg[iarg],"sumsq") == 0) mode = SUMSQ; - else if (strcmp(arg[iarg],"min") == 0) mode = MINN; - else if (strcmp(arg[iarg],"max") == 0) mode = MAXX; - else if (strcmp(arg[iarg],"ave") == 0) mode = AVE; - else if (strcmp(arg[iarg],"avesq") == 0) mode = AVESQ; - else error->all(FLERR,"Illegal compute reduce command"); + if (strcmp(arg[iarg], "sum") == 0) + mode = SUM; + else if (strcmp(arg[iarg], "sumsq") == 0) + mode = SUMSQ; + else if (strcmp(arg[iarg], "min") == 0) + mode = MINN; + else if (strcmp(arg[iarg], "max") == 0) + mode = MAXX; + else if (strcmp(arg[iarg], "ave") == 0) + mode = AVE; + else if (strcmp(arg[iarg], "avesq") == 0) + mode = AVESQ; + else + error->all(FLERR, "Illegal compute {} operation {}", style, arg[iarg]); iarg++; - MPI_Comm_rank(world,&me); + MPI_Comm_rank(world, &me); // expand args if any have wildcard character "*" int expand = 0; char **earg; - int nargnew = utils::expand_args(FLERR,narg-iarg,&arg[iarg],1,earg,lmp); + int nargnew = utils::expand_args(FLERR, narg - iarg, &arg[iarg], 1, earg, lmp); if (earg != &arg[iarg]) expand = 1; arg = earg; @@ -79,9 +82,9 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : which = new int[nargnew]; argindex = new int[nargnew]; flavor = new int[nargnew]; - ids = new char*[nargnew]; + ids = new char *[nargnew]; value2index = new int[nargnew]; - for (int i=0; i < nargnew; ++i) { + for (int i = 0; i < nargnew; ++i) { which[i] = argindex[i] = flavor[i] = value2index[i] = ArgInfo::UNKNOWN; ids[i] = nullptr; } @@ -91,33 +94,33 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : while (iarg < nargnew) { ids[nvalues] = nullptr; - if (strcmp(arg[iarg],"x") == 0) { + if (strcmp(arg[iarg], "x") == 0) { which[nvalues] = ArgInfo::X; argindex[nvalues++] = 0; - } else if (strcmp(arg[iarg],"y") == 0) { + } else if (strcmp(arg[iarg], "y") == 0) { which[nvalues] = ArgInfo::X; argindex[nvalues++] = 1; - } else if (strcmp(arg[iarg],"z") == 0) { + } else if (strcmp(arg[iarg], "z") == 0) { which[nvalues] = ArgInfo::X; argindex[nvalues++] = 2; - } else if (strcmp(arg[iarg],"vx") == 0) { + } else if (strcmp(arg[iarg], "vx") == 0) { which[nvalues] = ArgInfo::V; argindex[nvalues++] = 0; - } else if (strcmp(arg[iarg],"vy") == 0) { + } else if (strcmp(arg[iarg], "vy") == 0) { which[nvalues] = ArgInfo::V; argindex[nvalues++] = 1; - } else if (strcmp(arg[iarg],"vz") == 0) { + } else if (strcmp(arg[iarg], "vz") == 0) { which[nvalues] = ArgInfo::V; argindex[nvalues++] = 2; - } else if (strcmp(arg[iarg],"fx") == 0) { + } else if (strcmp(arg[iarg], "fx") == 0) { which[nvalues] = ArgInfo::F; argindex[nvalues++] = 0; - } else if (strcmp(arg[iarg],"fy") == 0) { + } else if (strcmp(arg[iarg], "fy") == 0) { which[nvalues] = ArgInfo::F; argindex[nvalues++] = 1; - } else if (strcmp(arg[iarg],"fz") == 0) { + } else if (strcmp(arg[iarg], "fz") == 0) { which[nvalues] = ArgInfo::F; argindex[nvalues++] = 2; @@ -130,7 +133,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : ids[nvalues] = argi.copy_name(); if ((which[nvalues] == ArgInfo::UNKNOWN) || (argi.get_dim() > 1)) - error->all(FLERR,"Illegal compute reduce command"); + error->all(FLERR, "Illegal compute reduce command"); if (which[nvalues] == ArgInfo::NONE) break; nvalues++; @@ -145,20 +148,21 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : for (int i = 0; i < nvalues; i++) replace[i] = -1; while (iarg < nargnew) { - if (strcmp(arg[iarg],"replace") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal compute reduce command"); + if (strcmp(arg[iarg], "replace") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal compute reduce command"); if (mode != MINN && mode != MAXX) - error->all(FLERR,"Compute reduce replace requires min or max mode"); - int col1 = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - int col2 = utils::inumeric(FLERR,arg[iarg+2],false,lmp) - 1; + error->all(FLERR, "Compute reduce replace requires min or max mode"); + int col1 = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + int col2 = utils::inumeric(FLERR, arg[iarg + 2], false, lmp) - 1; if (col1 < 0 || col1 >= nvalues || col2 < 0 || col2 >= nvalues) - error->all(FLERR,"Illegal compute reduce command"); - if (col1 == col2) error->all(FLERR,"Illegal compute reduce command"); + error->all(FLERR, "Illegal compute reduce command"); + if (col1 == col2) error->all(FLERR, "Illegal compute reduce command"); if (replace[col1] >= 0 || replace[col2] >= 0) - error->all(FLERR,"Invalid replace values in compute reduce"); + error->all(FLERR, "Invalid replace values in compute reduce"); replace[col1] = col2; iarg += 3; - } else error->all(FLERR,"Illegal compute reduce command"); + } else + error->all(FLERR, "Illegal compute reduce command"); } // delete replace if not set @@ -167,14 +171,14 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : for (int i = 0; i < nvalues; i++) if (replace[i] >= 0) flag = 1; if (!flag) { - delete [] replace; + delete[] replace; replace = nullptr; } // if wildcard expansion occurred, free earg memory from expand_args() if (expand) { - for (int i = 0; i < nargnew; i++) delete [] earg[i]; + for (int i = 0; i < nargnew; i++) delete[] earg[i]; memory->sfree(earg); } @@ -186,65 +190,61 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : else if (which[i] == ArgInfo::COMPUTE) { int icompute = modify->find_compute(ids[i]); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute reduce does not exist"); + if (icompute < 0) error->all(FLERR, "Compute ID for compute reduce does not exist"); if (modify->compute[icompute]->peratom_flag) { flavor[i] = PERATOM; - if (argindex[i] == 0 && - modify->compute[icompute]->size_peratom_cols != 0) - error->all(FLERR,"Compute reduce compute does not " + if (argindex[i] == 0 && modify->compute[icompute]->size_peratom_cols != 0) + error->all(FLERR, + "Compute reduce compute does not " "calculate a per-atom vector"); if (argindex[i] && modify->compute[icompute]->size_peratom_cols == 0) - error->all(FLERR,"Compute reduce compute does not " - "calculate a per-atom array"); - if (argindex[i] && - argindex[i] > modify->compute[icompute]->size_peratom_cols) error->all(FLERR, - "Compute reduce compute array is accessed out-of-range"); + "Compute reduce compute does not " + "calculate a per-atom array"); + if (argindex[i] && argindex[i] > modify->compute[icompute]->size_peratom_cols) + error->all(FLERR, "Compute reduce compute array is accessed out-of-range"); } else if (modify->compute[icompute]->local_flag) { flavor[i] = LOCAL; - if (argindex[i] == 0 && - modify->compute[icompute]->size_local_cols != 0) - error->all(FLERR,"Compute reduce compute does not " + if (argindex[i] == 0 && modify->compute[icompute]->size_local_cols != 0) + error->all(FLERR, + "Compute reduce compute does not " "calculate a local vector"); if (argindex[i] && modify->compute[icompute]->size_local_cols == 0) - error->all(FLERR,"Compute reduce compute does not " - "calculate a local array"); - if (argindex[i] && - argindex[i] > modify->compute[icompute]->size_local_cols) error->all(FLERR, - "Compute reduce compute array is accessed out-of-range"); - } else error->all(FLERR, - "Compute reduce compute calculates global values"); + "Compute reduce compute does not " + "calculate a local array"); + if (argindex[i] && argindex[i] > modify->compute[icompute]->size_local_cols) + error->all(FLERR, "Compute reduce compute array is accessed out-of-range"); + } else + error->all(FLERR, "Compute reduce compute calculates global values"); } else if (which[i] == ArgInfo::FIX) { auto ifix = modify->get_fix_by_id(ids[i]); - if (!ifix) - error->all(FLERR,"Fix ID {} for compute reduce does not exist", ids[i]); + if (!ifix) error->all(FLERR, "Fix ID {} for compute reduce does not exist", ids[i]); if (ifix->peratom_flag) { flavor[i] = PERATOM; if (argindex[i] == 0 && (ifix->size_peratom_cols != 0)) - error->all(FLERR,"Compute reduce fix {} does not calculate a per-atom vector", ids[i]); + error->all(FLERR, "Compute reduce fix {} does not calculate a per-atom vector", ids[i]); if (argindex[i] && (ifix->size_peratom_cols == 0)) - error->all(FLERR,"Compute reduce fix {} does not calculate a per-atom array", ids[i]); + error->all(FLERR, "Compute reduce fix {} does not calculate a per-atom array", ids[i]); if (argindex[i] && (argindex[i] > ifix->size_peratom_cols)) - error->all(FLERR,"Compute reduce fix {} array is accessed out-of-range", ids[i]); + error->all(FLERR, "Compute reduce fix {} array is accessed out-of-range", ids[i]); } else if (ifix->local_flag) { flavor[i] = LOCAL; if (argindex[i] == 0 && (ifix->size_local_cols != 0)) - error->all(FLERR,"Compute reduce fix {} does not calculate a local vector", ids[i]); + error->all(FLERR, "Compute reduce fix {} does not calculate a local vector", ids[i]); if (argindex[i] && (ifix->size_local_cols == 0)) - error->all(FLERR,"Compute reduce fix {} does not calculate a local array", ids[i]); + error->all(FLERR, "Compute reduce fix {} does not calculate a local array", ids[i]); if (argindex[i] && (argindex[i] > ifix->size_local_cols)) - error->all(FLERR,"Compute reduce fix {} array is accessed out-of-range", ids[i]); - } else error->all(FLERR,"Compute reduce fix {} calculates global values", ids[i]); + error->all(FLERR, "Compute reduce fix {} array is accessed out-of-range", ids[i]); + } else + error->all(FLERR, "Compute reduce fix {} calculates global values", ids[i]); } else if (which[i] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[i]); - if (ivariable < 0) - error->all(FLERR,"Variable name for compute reduce does not exist"); + if (ivariable < 0) error->all(FLERR, "Variable name for compute reduce does not exist"); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Compute reduce variable is not atom-style variable"); + error->all(FLERR, "Compute reduce variable is not atom-style variable"); flavor[i] = PERATOM; } } @@ -253,15 +253,19 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : if (nvalues == 1) { scalar_flag = 1; - if (mode == SUM || mode == SUMSQ) extscalar = 1; - else extscalar = 0; + if (mode == SUM || mode == SUMSQ) + extscalar = 1; + else + extscalar = 0; vector = onevec = nullptr; indices = owner = nullptr; } else { vector_flag = 1; size_vector = nvalues; - if (mode == SUM || mode == SUMSQ) extvector = 1; - else extvector = 0; + if (mode == SUM || mode == SUMSQ) + extvector = 1; + else + extvector = 0; vector = new double[size_vector]; onevec = new double[size_vector]; indices = new int[size_vector]; @@ -276,19 +280,19 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : ComputeReduce::~ComputeReduce() { - delete [] which; - delete [] argindex; - delete [] flavor; - for (int m = 0; m < nvalues; m++) delete [] ids[m]; - delete [] ids; - delete [] value2index; - delete [] replace; - delete [] idregion; + delete[] which; + delete[] argindex; + delete[] flavor; + for (int m = 0; m < nvalues; m++) delete[] ids[m]; + delete[] ids; + delete[] value2index; + delete[] replace; + delete[] idregion; - delete [] vector; - delete [] onevec; - delete [] indices; - delete [] owner; + delete[] vector; + delete[] onevec; + delete[] indices; + delete[] owner; memory->destroy(varatom); } @@ -302,31 +306,28 @@ void ComputeReduce::init() for (int m = 0; m < nvalues; m++) { if (which[m] == ArgInfo::COMPUTE) { int icompute = modify->find_compute(ids[m]); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute reduce does not exist"); + if (icompute < 0) error->all(FLERR, "Compute ID for compute reduce does not exist"); value2index[m] = icompute; } else if (which[m] == ArgInfo::FIX) { int ifix = modify->find_fix(ids[m]); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute reduce does not exist"); + if (ifix < 0) error->all(FLERR, "Fix ID for compute reduce does not exist"); value2index[m] = ifix; } else if (which[m] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[m]); - if (ivariable < 0) - error->all(FLERR,"Variable name for compute reduce does not exist"); + if (ivariable < 0) error->all(FLERR, "Variable name for compute reduce does not exist"); value2index[m] = ivariable; - } else value2index[m] = ArgInfo::UNKNOWN; + } else + value2index[m] = ArgInfo::UNKNOWN; } // set index and check validity of region if (idregion) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for compute reduce/region does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for compute reduce/region does not exist", idregion); } } @@ -336,16 +337,16 @@ double ComputeReduce::compute_scalar() { invoked_scalar = update->ntimestep; - double one = compute_one(0,-1); + double one = compute_one(0, -1); if (mode == SUM || mode == SUMSQ) { - MPI_Allreduce(&one,&scalar,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &scalar, 1, MPI_DOUBLE, MPI_SUM, world); } else if (mode == MINN) { - MPI_Allreduce(&one,&scalar,1,MPI_DOUBLE,MPI_MIN,world); + MPI_Allreduce(&one, &scalar, 1, MPI_DOUBLE, MPI_MIN, world); } else if (mode == MAXX) { - MPI_Allreduce(&one,&scalar,1,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(&one, &scalar, 1, MPI_DOUBLE, MPI_MAX, world); } else if (mode == AVE || mode == AVESQ) { - MPI_Allreduce(&one,&scalar,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &scalar, 1, MPI_DOUBLE, MPI_SUM, world); bigint n = count(0); if (n) scalar /= n; } @@ -361,61 +362,59 @@ void ComputeReduce::compute_vector() for (int m = 0; m < nvalues; m++) if (!replace || replace[m] < 0) { - onevec[m] = compute_one(m,-1); + onevec[m] = compute_one(m, -1); indices[m] = index; } if (mode == SUM || mode == SUMSQ) { for (int m = 0; m < nvalues; m++) - MPI_Allreduce(&onevec[m],&vector[m],1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&onevec[m], &vector[m], 1, MPI_DOUBLE, MPI_SUM, world); } else if (mode == MINN) { if (!replace) { for (int m = 0; m < nvalues; m++) - MPI_Allreduce(&onevec[m],&vector[m],1,MPI_DOUBLE,MPI_MIN,world); + MPI_Allreduce(&onevec[m], &vector[m], 1, MPI_DOUBLE, MPI_MIN, world); } else { for (int m = 0; m < nvalues; m++) if (replace[m] < 0) { pairme.value = onevec[m]; pairme.proc = me; - MPI_Allreduce(&pairme,&pairall,1,MPI_DOUBLE_INT,MPI_MINLOC,world); + MPI_Allreduce(&pairme, &pairall, 1, MPI_DOUBLE_INT, MPI_MINLOC, world); vector[m] = pairall.value; owner[m] = pairall.proc; } for (int m = 0; m < nvalues; m++) if (replace[m] >= 0) { - if (me == owner[replace[m]]) - vector[m] = compute_one(m,indices[replace[m]]); - MPI_Bcast(&vector[m],1,MPI_DOUBLE,owner[replace[m]],world); + if (me == owner[replace[m]]) vector[m] = compute_one(m, indices[replace[m]]); + MPI_Bcast(&vector[m], 1, MPI_DOUBLE, owner[replace[m]], world); } } } else if (mode == MAXX) { if (!replace) { for (int m = 0; m < nvalues; m++) - MPI_Allreduce(&onevec[m],&vector[m],1,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(&onevec[m], &vector[m], 1, MPI_DOUBLE, MPI_MAX, world); } else { for (int m = 0; m < nvalues; m++) if (replace[m] < 0) { pairme.value = onevec[m]; pairme.proc = me; - MPI_Allreduce(&pairme,&pairall,1,MPI_DOUBLE_INT,MPI_MAXLOC,world); + MPI_Allreduce(&pairme, &pairall, 1, MPI_DOUBLE_INT, MPI_MAXLOC, world); vector[m] = pairall.value; owner[m] = pairall.proc; } for (int m = 0; m < nvalues; m++) if (replace[m] >= 0) { - if (me == owner[replace[m]]) - vector[m] = compute_one(m,indices[replace[m]]); - MPI_Bcast(&vector[m],1,MPI_DOUBLE,owner[replace[m]],world); + if (me == owner[replace[m]]) vector[m] = compute_one(m, indices[replace[m]]); + MPI_Bcast(&vector[m], 1, MPI_DOUBLE, owner[replace[m]], world); } } } else if (mode == AVE || mode == AVESQ) { for (int m = 0; m < nvalues; m++) { - MPI_Allreduce(&onevec[m],&vector[m],1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&onevec[m], &vector[m], 1, MPI_DOUBLE, MPI_SUM, world); bigint n = count(m); if (n) vector[m] /= n; } @@ -462,22 +461,25 @@ double ComputeReduce::compute_one(int m, int flag) double **x = atom->x; if (flag < 0) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) combine(one,x[i][aidx],i); - } else one = x[flag][aidx]; + if (mask[i] & groupbit) combine(one, x[i][aidx], i); + } else + one = x[flag][aidx]; } else if (which[m] == ArgInfo::V) { double **v = atom->v; if (flag < 0) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) combine(one,v[i][aidx],i); - } else one = v[flag][aidx]; + if (mask[i] & groupbit) combine(one, v[i][aidx], i); + } else + one = v[flag][aidx]; } else if (which[m] == ArgInfo::F) { double **f = atom->f; if (flag < 0) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) combine(one,f[i][aidx],i); - } else one = f[flag][aidx]; + if (mask[i] & groupbit) combine(one, f[i][aidx], i); + } else + one = f[flag][aidx]; - // invoke compute if not previously invoked + // invoke compute if not previously invoked } else if (which[m] == ArgInfo::COMPUTE) { Compute *compute = modify->compute[vidx]; @@ -493,16 +495,18 @@ double ComputeReduce::compute_one(int m, int flag) int n = nlocal; if (flag < 0) { for (i = 0; i < n; i++) - if (mask[i] & groupbit) combine(one,comp_vec[i],i); - } else one = comp_vec[flag]; + if (mask[i] & groupbit) combine(one, comp_vec[i], i); + } else + one = comp_vec[flag]; } else { double **carray_atom = compute->array_atom; int n = nlocal; int aidxm1 = aidx - 1; if (flag < 0) { for (i = 0; i < n; i++) - if (mask[i] & groupbit) combine(one,carray_atom[i][aidxm1],i); - } else one = carray_atom[flag][aidxm1]; + if (mask[i] & groupbit) combine(one, carray_atom[i][aidxm1], i); + } else + one = carray_atom[flag][aidxm1]; } } else if (flavor[m] == LOCAL) { @@ -515,25 +519,26 @@ double ComputeReduce::compute_one(int m, int flag) double *comp_vec = compute->vector_local; int n = compute->size_local_rows; if (flag < 0) - for (i = 0; i < n; i++) - combine(one,comp_vec[i],i); - else one = comp_vec[flag]; + for (i = 0; i < n; i++) combine(one, comp_vec[i], i); + else + one = comp_vec[flag]; } else { double **carray_local = compute->array_local; int n = compute->size_local_rows; int aidxm1 = aidx - 1; if (flag < 0) - for (i = 0; i < n; i++) - combine(one,carray_local[i][aidxm1],i); - else one = carray_local[flag][aidxm1]; + for (i = 0; i < n; i++) combine(one, carray_local[i][aidxm1], i); + else + one = carray_local[flag][aidxm1]; } } - // access fix fields, check if fix frequency is a match + // access fix fields, check if fix frequency is a match } else if (which[m] == ArgInfo::FIX) { if (update->ntimestep % modify->fix[vidx]->peratom_freq) - error->all(FLERR,"Fix used in compute reduce not " + error->all(FLERR, + "Fix used in compute reduce not " "computed at compatible time"); Fix *fix = modify->fix[vidx]; @@ -543,15 +548,17 @@ double ComputeReduce::compute_one(int m, int flag) int n = nlocal; if (flag < 0) { for (i = 0; i < n; i++) - if (mask[i] & groupbit) combine(one,fix_vector[i],i); - } else one = fix_vector[flag]; + if (mask[i] & groupbit) combine(one, fix_vector[i], i); + } else + one = fix_vector[flag]; } else { double **fix_array = fix->array_atom; int aidxm1 = aidx - 1; if (flag < 0) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) combine(one,fix_array[i][aidxm1],i); - } else one = fix_array[flag][aidxm1]; + if (mask[i] & groupbit) combine(one, fix_array[i][aidxm1], i); + } else + one = fix_array[flag][aidxm1]; } } else if (flavor[m] == LOCAL) { @@ -559,34 +566,35 @@ double ComputeReduce::compute_one(int m, int flag) double *fix_vector = fix->vector_local; int n = fix->size_local_rows; if (flag < 0) - for (i = 0; i < n; i++) - combine(one,fix_vector[i],i); - else one = fix_vector[flag]; + for (i = 0; i < n; i++) combine(one, fix_vector[i], i); + else + one = fix_vector[flag]; } else { double **fix_array = fix->array_local; int n = fix->size_local_rows; int aidxm1 = aidx - 1; if (flag < 0) - for (i = 0; i < n; i++) - combine(one,fix_array[i][aidxm1],i); - else one = fix_array[flag][aidxm1]; + for (i = 0; i < n; i++) combine(one, fix_array[i][aidxm1], i); + else + one = fix_array[flag][aidxm1]; } } - // evaluate atom-style variable + // evaluate atom-style variable } else if (which[m] == ArgInfo::VARIABLE) { if (atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(varatom); - memory->create(varatom,maxatom,"reduce:varatom"); + memory->create(varatom, maxatom, "reduce:varatom"); } - input->variable->compute_atom(vidx,igroup,varatom,1,0); + input->variable->compute_atom(vidx, igroup, varatom, 1, 0); if (flag < 0) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) combine(one,varatom[i],i); - } else one = varatom[flag]; + if (mask[i] & groupbit) combine(one, varatom[i], i); + } else + one = varatom[flag]; } return one; @@ -607,7 +615,7 @@ bigint ComputeReduce::count(int m) } else if (flavor[m] == LOCAL) { bigint ncount = compute->size_local_rows; bigint ncountall; - MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&ncount, &ncountall, 1, MPI_LMP_BIGINT, MPI_SUM, world); return ncountall; } } else if (which[m] == ArgInfo::FIX) { @@ -617,7 +625,7 @@ bigint ComputeReduce::count(int m) } else if (flavor[m] == LOCAL) { bigint ncount = fix->size_local_rows; bigint ncountall; - MPI_Allreduce(&ncount,&ncountall,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&ncount, &ncountall, 1, MPI_LMP_BIGINT, MPI_SUM, world); return ncountall; } } else if (which[m] == ArgInfo::VARIABLE) @@ -634,8 +642,10 @@ bigint ComputeReduce::count(int m) void ComputeReduce::combine(double &one, double two, int i) { - if (mode == SUM || mode == AVE) one += two; - else if (mode == SUMSQ || mode == AVESQ) one += two*two; + if (mode == SUM || mode == AVE) + one += two; + else if (mode == SUMSQ || mode == AVESQ) + one += two * two; else if (mode == MINN) { if (two < one) { one = two; @@ -655,6 +665,6 @@ void ComputeReduce::combine(double &one, double two, int i) double ComputeReduce::memory_usage() { - double bytes = (double)maxatom * sizeof(double); + double bytes = (double) maxatom * sizeof(double); return bytes; } diff --git a/src/compute_reduce.h b/src/compute_reduce.h index ac2b1e60a2..1129c35075 100644 --- a/src/compute_reduce.h +++ b/src/compute_reduce.h @@ -38,14 +38,14 @@ class ComputeReduce : public Compute { protected: int me; - int mode, nvalues, iregion; + int mode, nvalues; int *which, *argindex, *flavor, *value2index; char **ids; double *onevec; int *replace, *indices, *owner; int index; char *idregion; - + class Region *region; int maxatom; double *varatom; diff --git a/src/compute_reduce_region.cpp b/src/compute_reduce_region.cpp index 6e634f9e88..f8a92c7bf3 100644 --- a/src/compute_reduce_region.cpp +++ b/src/compute_reduce_region.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -29,12 +28,14 @@ using namespace LAMMPS_NS; -#define BIG 1.0e20 +static constexpr double BIG = 1.0e20; /* ---------------------------------------------------------------------- */ ComputeReduceRegion::ComputeReduceRegion(LAMMPS *lmp, int narg, char **arg) : - ComputeReduce(lmp, narg, arg) {} + ComputeReduce(lmp, narg, arg) +{ +} /* ---------------------------------------------------------------------- calculate reduced value for one input M and return it @@ -47,9 +48,6 @@ ComputeReduceRegion::ComputeReduceRegion(LAMMPS *lmp, int narg, char **arg) : double ComputeReduceRegion::compute_one(int m, int flag) { - int i; - - Region *region = domain->regions[iregion]; region->prematch(); // invoke the appropriate attribute,compute,fix,variable @@ -78,26 +76,29 @@ double ComputeReduceRegion::compute_one(int m, int flag) if (which[m] == ArgInfo::X) { if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,x[i][j],i); - } else one = x[flag][j]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, x[i][j], i); + } else + one = x[flag][j]; } else if (which[m] == ArgInfo::V) { double **v = atom->v; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,v[i][j],i); - } else one = v[flag][j]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, v[i][j], i); + } else + one = v[flag][j]; } else if (which[m] == ArgInfo::F) { double **f = atom->f; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,f[i][j],i); - } else one = f[flag][j]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, f[i][j], i); + } else + one = f[flag][j]; - // invoke compute if not previously invoked + // invoke compute if not previously invoked } else if (which[m] == ArgInfo::COMPUTE) { Compute *compute = modify->compute[n]; @@ -111,18 +112,20 @@ double ComputeReduceRegion::compute_one(int m, int flag) if (j == 0) { double *compute_vector = compute->vector_atom; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,compute_vector[i],i); - } else one = compute_vector[flag]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, compute_vector[i], i); + } else + one = compute_vector[flag]; } else { double **compute_array = compute->array_atom; int jm1 = j - 1; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,compute_array[i][jm1],i); - } else one = compute_array[flag][jm1]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, compute_array[i][jm1], i); + } else + one = compute_array[flag][jm1]; } } else if (flavor[m] == LOCAL) { @@ -134,76 +137,79 @@ double ComputeReduceRegion::compute_one(int m, int flag) if (j == 0) { double *compute_vector = compute->vector_local; if (flag < 0) - for (i = 0; i < compute->size_local_rows; i++) - combine(one,compute_vector[i],i); - else one = compute_vector[flag]; + for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_vector[i], i); + else + one = compute_vector[flag]; } else { double **compute_array = compute->array_local; int jm1 = j - 1; if (flag < 0) - for (i = 0; i < compute->size_local_rows; i++) - combine(one,compute_array[i][jm1],i); - else one = compute_array[flag][jm1]; + for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_array[i][jm1], i); + else + one = compute_array[flag][jm1]; } } - // check if fix frequency is a match + // check if fix frequency is a match } else if (which[m] == ArgInfo::FIX) { if (update->ntimestep % modify->fix[n]->peratom_freq) - error->all(FLERR,"Fix used in compute reduce not computed at compatible time"); + error->all(FLERR, "Fix used in compute reduce not computed at compatible time"); Fix *fix = modify->fix[n]; if (flavor[m] == PERATOM) { if (j == 0) { double *fix_vector = fix->vector_atom; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,fix_vector[i],i); - } else one = fix_vector[flag]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, fix_vector[i], i); + } else + one = fix_vector[flag]; } else { double **fix_array = fix->array_atom; int jm1 = j - 1; if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,fix_array[i][jm1],i); - } else one = fix_array[flag][jm1]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, fix_array[i][jm1], i); + } else + one = fix_array[flag][jm1]; } } else if (flavor[m] == LOCAL) { if (j == 0) { double *fix_vector = fix->vector_local; if (flag < 0) - for (i = 0; i < fix->size_local_rows; i++) - combine(one,fix_vector[i],i); - else one = fix_vector[flag]; + for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_vector[i], i); + else + one = fix_vector[flag]; } else { double **fix_array = fix->array_local; int jm1 = j - 1; if (flag < 0) - for (i = 0; i < fix->size_local_rows; i++) - combine(one,fix_array[i][jm1],i); - else one = fix_array[flag][jm1]; + for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_array[i][jm1], i); + else + one = fix_array[flag][jm1]; } } - // evaluate atom-style variable + // evaluate atom-style variable } else if (which[m] == ArgInfo::VARIABLE) { if (atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(varatom); - memory->create(varatom,maxatom,"reduce/region:varatom"); + memory->create(varatom, maxatom, "reduce/region:varatom"); } - input->variable->compute_atom(n,igroup,varatom,1,0); + input->variable->compute_atom(n, igroup, varatom, 1, 0); if (flag < 0) { - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - combine(one,varatom[i],i); - } else one = varatom[flag]; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + combine(one, varatom[i], i); + } else + one = varatom[flag]; } return one; @@ -216,29 +222,29 @@ bigint ComputeReduceRegion::count(int m) int n = value2index[m]; if (which[m] == ArgInfo::X || which[m] == ArgInfo::V || which[m] == ArgInfo::F) - return group->count(igroup,iregion); + return group->count(igroup, region); else if (which[m] == ArgInfo::COMPUTE) { Compute *compute = modify->compute[n]; if (flavor[m] == PERATOM) { - return group->count(igroup,iregion); + return group->count(igroup, region); } else if (flavor[m] == LOCAL) { bigint ncount = compute->size_local_rows; bigint ncountall; - MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world); return ncountall; } } else if (which[m] == ArgInfo::FIX) { Fix *fix = modify->fix[n]; if (flavor[m] == PERATOM) { - return group->count(igroup,iregion); + return group->count(igroup, region); } else if (flavor[m] == LOCAL) { bigint ncount = fix->size_local_rows; bigint ncountall; - MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world); return ncountall; } } else if (which[m] == ArgInfo::VARIABLE) - return group->count(igroup,iregion); + return group->count(igroup, region); bigint dummy = 0; return dummy; diff --git a/src/compute_temp_deform.cpp b/src/compute_temp_deform.cpp index 3259ccd090..a9617596dd 100644 --- a/src/compute_temp_deform.cpp +++ b/src/compute_temp_deform.cpp @@ -67,9 +67,10 @@ void ComputeTempDeform::init() auto fixes = modify->get_fix_by_style("^deform"); if (fixes.size() > 0) { - if ((dynamic_cast( fixes[0]))->remapflag == Domain::X_REMAP && comm->me == 0) + if ((dynamic_cast(fixes[0]))->remapflag == Domain::X_REMAP && comm->me == 0) error->warning(FLERR, "Using compute temp/deform with inconsistent fix deform remap option"); - } else error->warning(FLERR, "Using compute temp/deform with no fix deform defined"); + } else + error->warning(FLERR, "Using compute temp/deform with no fix deform defined"); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_temp_region.cpp b/src/compute_temp_region.cpp index 34c0206eeb..d65ac67147 100644 --- a/src/compute_temp_region.cpp +++ b/src/compute_temp_region.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -28,14 +27,12 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - idregion(nullptr) + Compute(lmp, narg, arg), region(nullptr), idregion(nullptr) { - if (narg != 4) error->all(FLERR,"Illegal compute temp/region command"); + if (narg != 4) error->all(FLERR, "Illegal compute temp/region command"); - iregion = domain->find_region(arg[3]); - if (iregion == -1) - error->all(FLERR,"Region ID for compute temp/region does not exist"); + if (!domain->get_region_by_id(arg[3])) + error->all(FLERR, "Region {} for compute temp/region does not exist", arg[3]); idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; @@ -54,9 +51,9 @@ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : ComputeTempRegion::~ComputeTempRegion() { - delete [] idregion; + delete[] idregion; memory->destroy(vbiasall); - delete [] vector; + delete[] vector; } /* ---------------------------------------------------------------------- */ @@ -65,9 +62,8 @@ void ComputeTempRegion::init() { // set index and check validity of region - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for compute temp/region does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for compute temp/region does not exist", idregion); } /* ---------------------------------------------------------------------- */ @@ -83,7 +79,7 @@ void ComputeTempRegion::setup() void ComputeTempRegion::dof_remove_pre() { - domain->regions[iregion]->prematch(); + region->prematch(); } /* ---------------------------------------------------------------------- */ @@ -91,7 +87,7 @@ void ComputeTempRegion::dof_remove_pre() int ComputeTempRegion::dof_remove(int i) { double *x = atom->x[i]; - if (domain->regions[iregion]->match(x[0],x[1],x[2])) return 0; + if (region->match(x[0], x[1], x[2])) return 0; return 1; } @@ -109,7 +105,6 @@ double ComputeTempRegion::compute_scalar() int *mask = atom->mask; int nlocal = atom->nlocal; - Region *region = domain->regions[iregion]; region->prematch(); int count = 0; @@ -117,28 +112,29 @@ double ComputeTempRegion::compute_scalar() if (rmass) { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { count++; - t += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * rmass[i]; + t += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * rmass[i]; } } else { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { count++; - t += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * - mass[type[i]]; + t += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * mass[type[i]]; } } - double tarray[2],tarray_all[2]; + double tarray[2], tarray_all[2]; tarray[0] = count; tarray[1] = t; - MPI_Allreduce(tarray,tarray_all,2,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(tarray, tarray_all, 2, MPI_DOUBLE, MPI_SUM, world); dof = domain->dimension * tarray_all[0] - extra_dof; if (dof < 0.0 && tarray_all[0] > 0.0) - error->all(FLERR,"Temperature compute degrees of freedom < 0"); - if (dof > 0) scalar = force->mvv2e * tarray_all[1] / (dof * force->boltz); - else scalar = 0.0; + error->all(FLERR, "Temperature compute degrees of freedom < 0"); + if (dof > 0) + scalar = force->mvv2e * tarray_all[1] / (dof * force->boltz); + else + scalar = 0.0; return scalar; } @@ -158,25 +154,26 @@ void ComputeTempRegion::compute_vector() int *mask = atom->mask; int nlocal = atom->nlocal; - Region *region = domain->regions[iregion]; region->prematch(); - double massone,t[6]; + double massone, t[6]; for (i = 0; i < 6; i++) t[i] = 0.0; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - t[0] += massone * v[i][0]*v[i][0]; - t[1] += massone * v[i][1]*v[i][1]; - t[2] += massone * v[i][2]*v[i][2]; - t[3] += massone * v[i][0]*v[i][1]; - t[4] += massone * v[i][0]*v[i][2]; - t[5] += massone * v[i][1]*v[i][2]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + t[0] += massone * v[i][0] * v[i][0]; + t[1] += massone * v[i][1] * v[i][1]; + t[2] += massone * v[i][2] * v[i][2]; + t[3] += massone * v[i][0] * v[i][1]; + t[4] += massone * v[i][0] * v[i][2]; + t[5] += massone * v[i][1] * v[i][2]; } - MPI_Allreduce(t,vector,6,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(t, vector, 6, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < 6; i++) vector[i] *= force->mvv2e; } @@ -187,7 +184,7 @@ void ComputeTempRegion::compute_vector() void ComputeTempRegion::remove_bias(int i, double *v) { double *x = atom->x[i]; - if (domain->regions[iregion]->match(x[0],x[1],x[2])) + if (region->match(x[0], x[1], x[2])) vbias[0] = vbias[1] = vbias[2] = 0.0; else { vbias[0] = v[0]; @@ -204,7 +201,7 @@ void ComputeTempRegion::remove_bias(int i, double *v) void ComputeTempRegion::remove_bias_thr(int i, double *v, double *b) { double *x = atom->x[i]; - if (domain->regions[iregion]->match(x[0],x[1],x[2])) + if (region->match(x[0], x[1], x[2])) b[0] = b[1] = b[2] = 0.0; else { b[0] = v[0]; @@ -228,14 +225,12 @@ void ComputeTempRegion::remove_bias_all() if (atom->nmax > maxbias) { memory->destroy(vbiasall); maxbias = atom->nmax; - memory->create(vbiasall,maxbias,3,"temp/region:vbiasall"); + memory->create(vbiasall, maxbias, 3, "temp/region:vbiasall"); } - Region *region = domain->regions[iregion]; - for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region->match(x[i][0],x[i][1],x[i][2])) + if (region->match(x[i][0], x[i][1], x[i][2])) vbiasall[i][0] = vbiasall[i][1] = vbiasall[i][2] = 0.0; else { vbiasall[i][0] = v[i][0]; @@ -293,6 +288,6 @@ void ComputeTempRegion::restore_bias_all() double ComputeTempRegion::memory_usage() { - double bytes = 3*maxbias * sizeof(double); + double bytes = 3 * maxbias * sizeof(double); return bytes; } diff --git a/src/compute_temp_region.h b/src/compute_temp_region.h index 8129f01023..922e0b76f8 100644 --- a/src/compute_temp_region.h +++ b/src/compute_temp_region.h @@ -45,7 +45,7 @@ class ComputeTempRegion : public Compute { double memory_usage() override; protected: - int iregion; + class Region *region; char *idregion; }; diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index c19d9f3368..8690b7c28e 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -46,10 +45,10 @@ using namespace MathConst; #define EPSILON 1.0e-6 #define LB_FACTOR 1.1 -enum{BOX,REGION,SINGLE,RANDOM}; -enum{ATOM,MOLECULE}; -enum{COUNT,INSERT,INSERT_SELECTED}; -enum{NONE,RATIO,SUBSET}; +enum { BOX, REGION, SINGLE, RANDOM }; +enum { ATOM, MOLECULE }; +enum { COUNT, INSERT, INSERT_SELECTED }; +enum { NONE, RATIO, SUBSET }; /* ---------------------------------------------------------------------- */ @@ -59,70 +58,67 @@ CreateAtoms::CreateAtoms(LAMMPS *lmp) : Command(lmp), basistype(nullptr) {} void CreateAtoms::command(int narg, char **arg) { - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); - if (domain->box_exist == 0) - error->all(FLERR,"Create_atoms command before simulation box is defined"); + error->all(FLERR, "Create_atoms command before simulation box is defined"); if (modify->nfix_restart_peratom) - error->all(FLERR,"Cannot create_atoms after " + error->all(FLERR, + "Cannot create_atoms after " "reading restart file with per-atom info"); // check for compatible lattice int latsty = domain->lattice->style; if (domain->dimension == 2) { - if (latsty == Lattice::SC || latsty == Lattice::BCC - || latsty == Lattice::FCC || latsty == Lattice::HCP - || latsty == Lattice::DIAMOND) - error->all(FLERR,"Lattice style incompatible with simulation dimension"); + if (latsty == Lattice::SC || latsty == Lattice::BCC || latsty == Lattice::FCC || + latsty == Lattice::HCP || latsty == Lattice::DIAMOND) + error->all(FLERR, "Lattice style incompatible with simulation dimension"); } else { - if (latsty == Lattice::SQ ||latsty == Lattice::SQ2 - || latsty == Lattice::HEX) - error->all(FLERR,"Lattice style incompatible with simulation dimension"); + if (latsty == Lattice::SQ || latsty == Lattice::SQ2 || latsty == Lattice::HEX) + error->all(FLERR, "Lattice style incompatible with simulation dimension"); } // parse arguments - if (narg < 2) error->all(FLERR,"Illegal create_atoms command"); - ntype = utils::inumeric(FLERR,arg[0],false,lmp); + if (narg < 2) error->all(FLERR, "Illegal create_atoms command"); + ntype = utils::inumeric(FLERR, arg[0], false, lmp); int iarg; - if (strcmp(arg[1],"box") == 0) { + if (strcmp(arg[1], "box") == 0) { style = BOX; iarg = 2; - nregion = -1; - } else if (strcmp(arg[1],"region") == 0) { + region = nullptr; + } else if (strcmp(arg[1], "region") == 0) { style = REGION; - if (narg < 3) error->all(FLERR,"Illegal create_atoms command"); - nregion = domain->find_region(arg[2]); - if (nregion == -1) error->all(FLERR, - "Create_atoms region ID does not exist"); - domain->regions[nregion]->init(); - domain->regions[nregion]->prematch(); - iarg = 3;; - } else if (strcmp(arg[1],"single") == 0) { + if (narg < 3) error->all(FLERR, "Illegal create_atoms command"); + region = domain->get_region_by_id(arg[2]); + if (!region) error->all(FLERR, "Create_atoms region {} does not exist", arg[2]); + region->init(); + region->prematch(); + iarg = 3; + ; + } else if (strcmp(arg[1], "single") == 0) { style = SINGLE; - if (narg < 5) error->all(FLERR,"Illegal create_atoms command"); - xone[0] = utils::numeric(FLERR,arg[2],false,lmp); - xone[1] = utils::numeric(FLERR,arg[3],false,lmp); - xone[2] = utils::numeric(FLERR,arg[4],false,lmp); + if (narg < 5) error->all(FLERR, "Illegal create_atoms command"); + xone[0] = utils::numeric(FLERR, arg[2], false, lmp); + xone[1] = utils::numeric(FLERR, arg[3], false, lmp); + xone[2] = utils::numeric(FLERR, arg[4], false, lmp); iarg = 5; - } else if (strcmp(arg[1],"random") == 0) { + } else if (strcmp(arg[1], "random") == 0) { style = RANDOM; - if (narg < 5) error->all(FLERR,"Illegal create_atoms command"); - nrandom = utils::inumeric(FLERR,arg[2],false,lmp); - seed = utils::inumeric(FLERR,arg[3],false,lmp); - if (strcmp(arg[4],"NULL") == 0) nregion = -1; + if (narg < 5) error->all(FLERR, "Illegal create_atoms command"); + nrandom = utils::inumeric(FLERR, arg[2], false, lmp); + seed = utils::inumeric(FLERR, arg[3], false, lmp); + if (strcmp(arg[4], "NULL") == 0) + region = nullptr; else { - nregion = domain->find_region(arg[4]); - if (nregion == -1) error->all(FLERR, - "Create_atoms region ID does not exist"); - domain->regions[nregion]->init(); - domain->regions[nregion]->prematch(); + region = domain->get_region_by_id(arg[4]); + if (!region) error->all(FLERR, "Create_atoms region {} does not exist", arg[4]); + region->init(); + region->prematch(); } iarg = 5; - } else error->all(FLERR,"Illegal create_atoms command"); + } else + error->all(FLERR, "Illegal create_atoms command"); // process optional keywords @@ -141,112 +137,115 @@ void CreateAtoms::command(int narg, char **arg) for (int i = 0; i < nbasis; i++) basistype[i] = ntype; while (iarg < narg) { - if (strcmp(arg[iarg],"basis") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); - int ibasis = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - int itype = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + if (strcmp(arg[iarg], "basis") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal create_atoms command"); + int ibasis = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + int itype = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); if (ibasis <= 0 || ibasis > nbasis || itype <= 0 || itype > atom->ntypes) - error->all(FLERR,"Invalid basis setting in create_atoms command"); - basistype[ibasis-1] = itype; + error->all(FLERR, "Invalid basis setting in create_atoms command"); + basistype[ibasis - 1] = itype; iarg += 3; - } else if (strcmp(arg[iarg],"remap") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command"); - remapflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "remap") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_atoms command"); + remapflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"mol") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); - int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) error->all(FLERR,"Molecule template ID for " - "create_atoms does not exist"); - if (atom->molecules[imol]->nset > 1 && me == 0) - error->warning(FLERR,"Molecule template for " - "create_atoms has multiple molecules"); + } else if (strcmp(arg[iarg], "mol") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal create_atoms command"); + int imol = atom->find_molecule(arg[iarg + 1]); + if (imol == -1) + error->all(FLERR, + "Molecule template ID for " + "create_atoms does not exist"); + if ((atom->molecules[imol]->nset > 1) && (comm->me == 0)) + error->warning(FLERR, "Molecule template for create_atoms has multiple molecules"); mode = MOLECULE; onemol = atom->molecules[imol]; - molseed = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + molseed = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; - } else if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command"); - if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; - else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal create_atoms command"); + } else if (strcmp(arg[iarg], "units") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_atoms command"); + if (strcmp(arg[iarg + 1], "box") == 0) + scaleflag = 0; + else if (strcmp(arg[iarg + 1], "lattice") == 0) + scaleflag = 1; + else + error->all(FLERR, "Illegal create_atoms command"); iarg += 2; - } else if (strcmp(arg[iarg],"var") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command"); - delete [] vstr; - vstr = utils::strdup(arg[iarg+1]); + } else if (strcmp(arg[iarg], "var") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_atoms command"); + delete[] vstr; + vstr = utils::strdup(arg[iarg + 1]); varflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"set") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); - if (strcmp(arg[iarg+1],"x") == 0) { - delete [] xstr; - xstr = utils::strdup(arg[iarg+2]); - } else if (strcmp(arg[iarg+1],"y") == 0) { - delete [] ystr; - ystr = utils::strdup(arg[iarg+2]); - } else if (strcmp(arg[iarg+1],"z") == 0) { - delete [] zstr; - zstr = utils::strdup(arg[iarg+2]); - } else error->all(FLERR,"Illegal create_atoms command"); + } else if (strcmp(arg[iarg], "set") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal create_atoms command"); + if (strcmp(arg[iarg + 1], "x") == 0) { + delete[] xstr; + xstr = utils::strdup(arg[iarg + 2]); + } else if (strcmp(arg[iarg + 1], "y") == 0) { + delete[] ystr; + ystr = utils::strdup(arg[iarg + 2]); + } else if (strcmp(arg[iarg + 1], "z") == 0) { + delete[] zstr; + zstr = utils::strdup(arg[iarg + 2]); + } else + error->all(FLERR, "Illegal create_atoms command"); iarg += 3; - } else if (strcmp(arg[iarg],"rotate") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal create_atoms command"); + } else if (strcmp(arg[iarg], "rotate") == 0) { + if (iarg + 5 > narg) error->all(FLERR, "Illegal create_atoms command"); double thetaone; double axisone[3]; - thetaone = utils::numeric(FLERR,arg[iarg+1],false,lmp) / 180.0 * MY_PI;; - axisone[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - axisone[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); - axisone[2] = utils::numeric(FLERR,arg[iarg+4],false,lmp); + thetaone = utils::numeric(FLERR, arg[iarg + 1], false, lmp) / 180.0 * MY_PI; + ; + axisone[0] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + axisone[1] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + axisone[2] = utils::numeric(FLERR, arg[iarg + 4], false, lmp); if (axisone[0] == 0.0 && axisone[1] == 0.0 && axisone[2] == 0.0) - error->all(FLERR,"Illegal create_atoms command"); + error->all(FLERR, "Illegal create_atoms command"); if (domain->dimension == 2 && (axisone[0] != 0.0 || axisone[1] != 0.0)) - error->all(FLERR,"Invalid create_atoms rotation vector for 2d model"); + error->all(FLERR, "Invalid create_atoms rotation vector for 2d model"); MathExtra::norm3(axisone); - MathExtra::axisangle_to_quat(axisone,thetaone,quatone); + MathExtra::axisangle_to_quat(axisone, thetaone, quatone); iarg += 5; - } else if (strcmp(arg[iarg],"ratio") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); + } else if (strcmp(arg[iarg], "ratio") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal create_atoms command"); subsetflag = RATIO; - subsetfrac = utils::numeric(FLERR,arg[iarg+1],false,lmp); - subsetseed = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + subsetfrac = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + subsetseed = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); if (subsetfrac <= 0.0 || subsetfrac > 1.0 || subsetseed <= 0) - error->all(FLERR,"Illegal create_atoms command"); + error->all(FLERR, "Illegal create_atoms command"); iarg += 3; - } else if (strcmp(arg[iarg],"subset") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); + } else if (strcmp(arg[iarg], "subset") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal create_atoms command"); subsetflag = SUBSET; - nsubset = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); - subsetseed = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - if (nsubset <= 0 || subsetseed <= 0) - error->all(FLERR,"Illegal create_atoms command"); + nsubset = utils::bnumeric(FLERR, arg[iarg + 1], false, lmp); + subsetseed = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); + if (nsubset <= 0 || subsetseed <= 0) error->all(FLERR, "Illegal create_atoms command"); iarg += 3; - } else error->all(FLERR,"Illegal create_atoms command"); + } else + error->all(FLERR, "Illegal create_atoms command"); } // error checks if (mode == ATOM && (ntype <= 0 || ntype > atom->ntypes)) - error->all(FLERR,"Invalid atom type in create_atoms command"); + error->all(FLERR, "Invalid atom type in create_atoms command"); if (style == RANDOM) { - if (nrandom < 0) error->all(FLERR,"Illegal create_atoms command"); - if (seed <= 0) error->all(FLERR,"Illegal create_atoms command"); + if (nrandom < 0) error->all(FLERR, "Illegal create_atoms command"); + if (seed <= 0) error->all(FLERR, "Illegal create_atoms command"); } // error check and further setup for mode = MOLECULE ranmol = nullptr; if (mode == MOLECULE) { - if (onemol->xflag == 0) - error->all(FLERR,"Create_atoms molecule must have coordinates"); - if (onemol->typeflag == 0) - error->all(FLERR,"Create_atoms molecule must have atom types"); - if (ntype+onemol->ntypes <= 0 || ntype+onemol->ntypes > atom->ntypes) - error->all(FLERR,"Invalid atom type in create_atoms mol command"); + if (onemol->xflag == 0) error->all(FLERR, "Create_atoms molecule must have coordinates"); + if (onemol->typeflag == 0) error->all(FLERR, "Create_atoms molecule must have atom types"); + if (ntype + onemol->ntypes <= 0 || ntype + onemol->ntypes > atom->ntypes) + error->all(FLERR, "Invalid atom type in create_atoms mol command"); if (onemol->tag_require && !atom->tag_enable) - error->all(FLERR, - "Create_atoms molecule has atom IDs, but system does not"); + error->all(FLERR, "Create_atoms molecule has atom IDs, but system does not"); onemol->check_attributes(0); // create_atoms uses geoemetric center of molecule for insertion @@ -255,46 +254,42 @@ void CreateAtoms::command(int narg, char **arg) // molecule random number generator, different for each proc - ranmol = new RanMars(lmp,molseed+me); + ranmol = new RanMars(lmp, molseed + comm->me); } ranlatt = nullptr; - if (subsetflag != NONE) ranlatt = new RanMars(lmp,subsetseed+me); + if (subsetflag != NONE) ranlatt = new RanMars(lmp, subsetseed + comm->me); // error check and further setup for variable test if (!vstr && (xstr || ystr || zstr)) - error->all(FLERR,"Incomplete use of variables in create_atoms command"); + error->all(FLERR, "Incomplete use of variables in create_atoms command"); if (vstr && (!xstr && !ystr && !zstr)) - error->all(FLERR,"Incomplete use of variables in create_atoms command"); + error->all(FLERR, "Incomplete use of variables in create_atoms command"); if (varflag) { vvar = input->variable->find(vstr); - if (vvar < 0) - error->all(FLERR,"Variable name for create_atoms does not exist"); + if (vvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", vstr); if (!input->variable->equalstyle(vvar)) - error->all(FLERR,"Variable for create_atoms is invalid style"); + error->all(FLERR, "Variable for create_atoms is invalid style"); if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR,"Variable name for create_atoms does not exist"); + if (xvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", xstr); if (!input->variable->internalstyle(xvar)) - error->all(FLERR,"Variable for create_atoms is invalid style"); + error->all(FLERR, "Variable for create_atoms is invalid style"); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR,"Variable name for create_atoms does not exist"); + if (yvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", ystr); if (!input->variable->internalstyle(yvar)) - error->all(FLERR,"Variable for create_atoms is invalid style"); + error->all(FLERR, "Variable for create_atoms is invalid style"); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR,"Variable name for create_atoms does not exist"); + if (zvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", zstr); if (!input->variable->internalstyle(zvar)) - error->all(FLERR,"Variable for create_atoms is invalid style"); + error->all(FLERR, "Variable for create_atoms is invalid style"); } } @@ -305,8 +300,7 @@ void CreateAtoms::command(int narg, char **arg) // triclinic remapping occurs in add_single() if (style == BOX || style == REGION) { - if (nbasis == 0) - error->all(FLERR,"Cannot create atoms with undefined lattice"); + if (nbasis == 0) error->all(FLERR, "Cannot create atoms with undefined lattice"); } else if (scaleflag == 1) { xone[0] *= domain->lattice->xlattice; xone[1] *= domain->lattice->ylattice; @@ -328,7 +322,8 @@ void CreateAtoms::command(int narg, char **arg) triclinic = domain->triclinic; double epsilon[3]; - if (triclinic) epsilon[0] = epsilon[1] = epsilon[2] = EPSILON; + if (triclinic) + epsilon[0] = epsilon[1] = epsilon[2] = EPSILON; else { epsilon[0] = domain->prd[0] * EPSILON; epsilon[1] = domain->prd[1] * EPSILON; @@ -336,41 +331,47 @@ void CreateAtoms::command(int narg, char **arg) } if (triclinic == 0) { - sublo[0] = domain->sublo[0]; subhi[0] = domain->subhi[0]; - sublo[1] = domain->sublo[1]; subhi[1] = domain->subhi[1]; - sublo[2] = domain->sublo[2]; subhi[2] = domain->subhi[2]; + sublo[0] = domain->sublo[0]; + subhi[0] = domain->subhi[0]; + sublo[1] = domain->sublo[1]; + subhi[1] = domain->subhi[1]; + sublo[2] = domain->sublo[2]; + subhi[2] = domain->subhi[2]; } else { - sublo[0] = domain->sublo_lamda[0]; subhi[0] = domain->subhi_lamda[0]; - sublo[1] = domain->sublo_lamda[1]; subhi[1] = domain->subhi_lamda[1]; - sublo[2] = domain->sublo_lamda[2]; subhi[2] = domain->subhi_lamda[2]; + sublo[0] = domain->sublo_lamda[0]; + subhi[0] = domain->subhi_lamda[0]; + sublo[1] = domain->sublo_lamda[1]; + subhi[1] = domain->subhi_lamda[1]; + sublo[2] = domain->sublo_lamda[2]; + subhi[2] = domain->subhi_lamda[2]; } if (style == BOX || style == REGION) { if (comm->layout != Comm::LAYOUT_TILED) { if (domain->xperiodic) { if (comm->myloc[0] == 0) sublo[0] -= epsilon[0]; - if (comm->myloc[0] == comm->procgrid[0]-1) subhi[0] -= 2.0*epsilon[0]; + if (comm->myloc[0] == comm->procgrid[0] - 1) subhi[0] -= 2.0 * epsilon[0]; } if (domain->yperiodic) { if (comm->myloc[1] == 0) sublo[1] -= epsilon[1]; - if (comm->myloc[1] == comm->procgrid[1]-1) subhi[1] -= 2.0*epsilon[1]; + if (comm->myloc[1] == comm->procgrid[1] - 1) subhi[1] -= 2.0 * epsilon[1]; } if (domain->zperiodic) { if (comm->myloc[2] == 0) sublo[2] -= epsilon[2]; - if (comm->myloc[2] == comm->procgrid[2]-1) subhi[2] -= 2.0*epsilon[2]; + if (comm->myloc[2] == comm->procgrid[2] - 1) subhi[2] -= 2.0 * epsilon[2]; } } else { if (domain->xperiodic) { if (comm->mysplit[0][0] == 0.0) sublo[0] -= epsilon[0]; - if (comm->mysplit[0][1] == 1.0) subhi[0] -= 2.0*epsilon[0]; + if (comm->mysplit[0][1] == 1.0) subhi[0] -= 2.0 * epsilon[0]; } if (domain->yperiodic) { if (comm->mysplit[1][0] == 0.0) sublo[1] -= epsilon[1]; - if (comm->mysplit[1][1] == 1.0) subhi[1] -= 2.0*epsilon[1]; + if (comm->mysplit[1][1] == 1.0) subhi[1] -= 2.0 * epsilon[1]; } if (domain->zperiodic) { if (comm->mysplit[2][0] == 0.0) sublo[2] -= epsilon[2]; - if (comm->mysplit[2][1] == 1.0) subhi[2] -= 2.0*epsilon[2]; + if (comm->mysplit[2][1] == 1.0) subhi[2] -= 2.0 * epsilon[2]; } } } @@ -392,20 +393,22 @@ void CreateAtoms::command(int narg, char **arg) bigint natoms_previous = atom->natoms; int nlocal_previous = atom->nlocal; - if (style == SINGLE) add_single(); - else if (style == RANDOM) add_random(); - else add_lattice(); + if (style == SINGLE) + add_single(); + else if (style == RANDOM) + add_random(); + else + add_lattice(); // init per-atom fix/compute/variable values for created atoms - atom->data_fix_compute_variable(nlocal_previous,atom->nlocal); + atom->data_fix_compute_variable(nlocal_previous, atom->nlocal); // set new total # of atoms and error check bigint nblocal = atom->nlocal; - MPI_Allreduce(&nblocal,&atom->natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); - if (atom->natoms < 0 || atom->natoms >= MAXBIGINT) - error->all(FLERR,"Too many total atoms"); + MPI_Allreduce(&nblocal, &atom->natoms, 1, MPI_LMP_BIGINT, MPI_SUM, world); + if (atom->natoms < 0 || atom->natoms >= MAXBIGINT) error->all(FLERR, "Too many total atoms"); // add IDs for newly created atoms // check that atom IDs are valid @@ -443,7 +446,7 @@ void CreateAtoms::command(int narg, char **arg) bigint nmolme = molcreate; bigint nmoltotal; - MPI_Allreduce(&nmolme,&nmoltotal,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&nmolme, &nmoltotal, 1, MPI_LMP_BIGINT, MPI_SUM, world); atom->nbonds += nmoltotal * onemol->nbonds; atom->nangles += nmoltotal * onemol->nangles; atom->ndihedrals += nmoltotal * onemol->ndihedrals; @@ -457,10 +460,10 @@ void CreateAtoms::command(int narg, char **arg) tagint moloffset = 0; if (molecule_flag) { tagint max = 0; - for (int i = 0; i < nlocal_previous; i++) max = MAX(max,molecule[i]); + for (int i = 0; i < nlocal_previous; i++) max = MAX(max, molecule[i]); tagint maxmol; - MPI_Allreduce(&max,&maxmol,1,MPI_LMP_TAGINT,MPI_MAX,world); - MPI_Scan(&molcreate,&moloffset,1,MPI_LMP_TAGINT,MPI_SUM,world); + MPI_Allreduce(&max, &maxmol, 1, MPI_LMP_TAGINT, MPI_MAX, world); + MPI_Scan(&molcreate, &moloffset, 1, MPI_LMP_TAGINT, MPI_SUM, world); moloffset = moloffset - molcreate + maxmol; } @@ -493,7 +496,7 @@ void CreateAtoms::command(int narg, char **arg) int ilocal = nlocal_previous; for (int i = 0; i < molcreate; i++) { - if (tag) offset = tag[ilocal]-1; + if (tag) offset = tag[ilocal] - 1; for (int m = 0; m < natoms; m++) { if (molecule_flag) { if (onemol->moleculeflag) { @@ -507,8 +510,7 @@ void CreateAtoms::command(int narg, char **arg) atom->molatom[ilocal] = m; } else if (molecular != Atom::ATOMIC) { if (onemol->bondflag) - for (int j = 0; j < num_bond[ilocal]; j++) - bond_atom[ilocal][j] += offset; + for (int j = 0; j < num_bond[ilocal]; j++) bond_atom[ilocal][j] += offset; if (onemol->angleflag) for (int j = 0; j < num_angle[ilocal]; j++) { angle_atom1[ilocal][j] += offset; @@ -530,8 +532,7 @@ void CreateAtoms::command(int narg, char **arg) improper_atom4[ilocal][j] += offset; } if (onemol->specialflag) - for (int j = 0; j < nspecial[ilocal][2]; j++) - special[ilocal][j] += offset; + for (int j = 0; j < nspecial[ilocal][2]; j++) special[ilocal][j] += offset; } ilocal++; } @@ -549,7 +550,7 @@ void CreateAtoms::command(int narg, char **arg) double **x = atom->x; imageint *image = atom->image; int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) domain->remap(x[i],image[i]); + for (int i = 0; i < nlocal; i++) domain->remap(x[i], image[i]); if (domain->triclinic) domain->x2lamda(atom->nlocal); domain->reset_box(); @@ -564,11 +565,11 @@ void CreateAtoms::command(int narg, char **arg) delete ranmol; delete ranlatt; - delete [] basistype; - delete [] vstr; - delete [] xstr; - delete [] ystr; - delete [] zstr; + delete[] basistype; + delete[] vstr; + delete[] xstr; + delete[] ystr; + delete[] zstr; // for MOLECULE mode: // create special bond lists for molecular systems, @@ -579,19 +580,19 @@ void CreateAtoms::command(int narg, char **arg) if (atom->molecular == Atom::MOLECULAR && onemol->bondflag && !onemol->specialflag) { Special special(lmp); special.build(); - } } // print status MPI_Barrier(world); - if (me == 0) { - utils::logmesg(lmp,"Created {} atoms\n", atom->natoms - natoms_previous); - if (scaleflag) domain->print_box(" using lattice units in "); - else domain->print_box(" using box units in "); - utils::logmesg(lmp," create_atoms CPU = {:.3f} seconds\n", - platform::walltime() - time1); + if (comm->me == 0) { + utils::logmesg(lmp, "Created {} atoms\n", atom->natoms - natoms_previous); + if (scaleflag) + domain->print_box(" using lattice units in "); + else + domain->print_box(" using box units in "); + utils::logmesg(lmp, " create_atoms CPU = {:.3f} seconds\n", platform::walltime() - time1); } } @@ -605,38 +606,36 @@ void CreateAtoms::add_single() // remap atom if requested if (remapflag) { - imageint imagetmp = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - domain->remap(xone,imagetmp); + imageint imagetmp = ((imageint) IMGMAX << IMG2BITS) | ((imageint) IMGMAX << IMGBITS) | IMGMAX; + domain->remap(xone, imagetmp); } // if triclinic, convert to lamda coords (0-1) // with remapflag set and periodic dims, // resulting coord must satisfy 0.0 <= coord < 1.0 - double lamda[3],*coord; + double lamda[3], *coord; if (triclinic) { - domain->x2lamda(xone,lamda); + domain->x2lamda(xone, lamda); if (remapflag) { - if (domain->xperiodic && (lamda[0] < 0.0 || lamda[0] >= 1.0)) - lamda[0] = 0.0; - if (domain->yperiodic && (lamda[1] < 0.0 || lamda[1] >= 1.0)) - lamda[1] = 0.0; - if (domain->zperiodic && (lamda[2] < 0.0 || lamda[2] >= 1.0)) - lamda[2] = 0.0; + if (domain->xperiodic && (lamda[0] < 0.0 || lamda[0] >= 1.0)) lamda[0] = 0.0; + if (domain->yperiodic && (lamda[1] < 0.0 || lamda[1] >= 1.0)) lamda[1] = 0.0; + if (domain->zperiodic && (lamda[2] < 0.0 || lamda[2] >= 1.0)) lamda[2] = 0.0; } coord = lamda; - } else coord = xone; + } else + coord = xone; // if atom/molecule is in my subbox, create it - if (coord[0] >= sublo[0] && coord[0] < subhi[0] && - coord[1] >= sublo[1] && coord[1] < subhi[1] && + if (coord[0] >= sublo[0] && coord[0] < subhi[0] && coord[1] >= sublo[1] && coord[1] < subhi[1] && coord[2] >= sublo[2] && coord[2] < subhi[2]) { - if (mode == ATOM) atom->avec->create_atom(ntype,xone); + if (mode == ATOM) + atom->avec->create_atom(ntype, xone); else if (quatone[0] == 0.0 && quatone[1] == 0.0 && quatone[2] == 0.0) add_molecule(xone); - else add_molecule(xone,quatone); + else + add_molecule(xone, quatone); } } @@ -646,42 +645,48 @@ void CreateAtoms::add_single() void CreateAtoms::add_random() { - double xlo,ylo,zlo,xhi,yhi,zhi,zmid; - double lamda[3],*coord; - double *boxlo,*boxhi; + double xlo, ylo, zlo, xhi, yhi, zhi, zmid; + double lamda[3], *coord; + double *boxlo, *boxhi; // random number generator, same for all procs // warm up the generator 30x to avoid correlations in first-particle // positions if runs are repeated with consecutive seeds - auto random = new RanPark(lmp,seed); - for (int ii=0; ii < 30; ii++) random->uniform(); + auto random = new RanPark(lmp, seed); + for (int ii = 0; ii < 30; ii++) random->uniform(); // bounding box for atom creation // in real units, even if triclinic // only limit bbox by region if its bboxflag is set (interior region) if (triclinic == 0) { - xlo = domain->boxlo[0]; xhi = domain->boxhi[0]; - ylo = domain->boxlo[1]; yhi = domain->boxhi[1]; - zlo = domain->boxlo[2]; zhi = domain->boxhi[2]; - zmid = zlo + 0.5*(zhi-zlo); + xlo = domain->boxlo[0]; + xhi = domain->boxhi[0]; + ylo = domain->boxlo[1]; + yhi = domain->boxhi[1]; + zlo = domain->boxlo[2]; + zhi = domain->boxhi[2]; + zmid = zlo + 0.5 * (zhi - zlo); } else { - xlo = domain->boxlo_bound[0]; xhi = domain->boxhi_bound[0]; - ylo = domain->boxlo_bound[1]; yhi = domain->boxhi_bound[1]; - zlo = domain->boxlo_bound[2]; zhi = domain->boxhi_bound[2]; - zmid = zlo + 0.5*(zhi-zlo); + xlo = domain->boxlo_bound[0]; + xhi = domain->boxhi_bound[0]; + ylo = domain->boxlo_bound[1]; + yhi = domain->boxhi_bound[1]; + zlo = domain->boxlo_bound[2]; + zhi = domain->boxhi_bound[2]; + zmid = zlo + 0.5 * (zhi - zlo); boxlo = domain->boxlo_lamda; boxhi = domain->boxhi_lamda; } - if (nregion >= 0 && domain->regions[nregion]->bboxflag) { - xlo = MAX(xlo,domain->regions[nregion]->extent_xlo); - xhi = MIN(xhi,domain->regions[nregion]->extent_xhi); - ylo = MAX(ylo,domain->regions[nregion]->extent_ylo); - yhi = MIN(yhi,domain->regions[nregion]->extent_yhi); - zlo = MAX(zlo,domain->regions[nregion]->extent_zlo); - zhi = MIN(zhi,domain->regions[nregion]->extent_zhi); + if (region && region->bboxflag) { + xlo = MAX(xlo, region->extent_xlo); + xhi = MIN(xhi, region->extent_xhi); + ylo = MAX(ylo, region->extent_ylo); + yhi = MIN(yhi, region->extent_yhi); + zlo = MAX(zlo, region->extent_zlo); + zhi = MIN(zhi, region->extent_zhi); } // generate random positions for each new atom/molecule within bounding box @@ -689,41 +694,41 @@ void CreateAtoms::add_random() // if final atom position is in my subbox, create it if (xlo > xhi || ylo > yhi || zlo > zhi) - error->all(FLERR,"No overlap of box and region for create_atoms"); + error->all(FLERR, "No overlap of box and region for create_atoms"); int valid; for (int i = 0; i < nrandom; i++) { while (true) { - xone[0] = xlo + random->uniform() * (xhi-xlo); - xone[1] = ylo + random->uniform() * (yhi-ylo); - xone[2] = zlo + random->uniform() * (zhi-zlo); + xone[0] = xlo + random->uniform() * (xhi - xlo); + xone[1] = ylo + random->uniform() * (yhi - ylo); + xone[2] = zlo + random->uniform() * (zhi - zlo); if (domain->dimension == 2) xone[2] = zmid; valid = 1; - if (nregion >= 0 && - domain->regions[nregion]->match(xone[0],xone[1],xone[2]) == 0) - valid = 0; + if (region && (region->match(xone[0], xone[1], xone[2]) == 0)) valid = 0; if (varflag && vartest(xone) == 0) valid = 0; if (triclinic) { - domain->x2lamda(xone,lamda); + domain->x2lamda(xone, lamda); coord = lamda; - if (coord[0] < boxlo[0] || coord[0] >= boxhi[0] || - coord[1] < boxlo[1] || coord[1] >= boxhi[1] || - coord[2] < boxlo[2] || coord[2] >= boxhi[2]) valid = 0; - } else coord = xone; + if (coord[0] < boxlo[0] || coord[0] >= boxhi[0] || coord[1] < boxlo[1] || + coord[1] >= boxhi[1] || coord[2] < boxlo[2] || coord[2] >= boxhi[2]) + valid = 0; + } else + coord = xone; if (valid) break; } // if triclinic, coord is now in lamda units - if (coord[0] >= sublo[0] && coord[0] < subhi[0] && - coord[1] >= sublo[1] && coord[1] < subhi[1] && - coord[2] >= sublo[2] && coord[2] < subhi[2]) { - if (mode == ATOM) atom->avec->create_atom(ntype,xone); + if (coord[0] >= sublo[0] && coord[0] < subhi[0] && coord[1] >= sublo[1] && + coord[1] < subhi[1] && coord[2] >= sublo[2] && coord[2] < subhi[2]) { + if (mode == ATOM) + atom->avec->create_atom(ntype, xone); else if (quatone[0] == 0 && quatone[1] == 0 && quatone[2] == 0) add_molecule(xone); - else add_molecule(xone, quatone); + else + add_molecule(xone, quatone); } } @@ -743,25 +748,29 @@ void CreateAtoms::add_lattice() // for triclinic, use bounding box of my subbox // xyz min to max = bounding box around the domain corners in lattice space - double bboxlo[3],bboxhi[3]; + double bboxlo[3], bboxhi[3]; if (triclinic == 0) { - bboxlo[0] = domain->sublo[0]; bboxhi[0] = domain->subhi[0]; - bboxlo[1] = domain->sublo[1]; bboxhi[1] = domain->subhi[1]; - bboxlo[2] = domain->sublo[2]; bboxhi[2] = domain->subhi[2]; - } else domain->bbox(domain->sublo_lamda,domain->subhi_lamda,bboxlo,bboxhi); + bboxlo[0] = domain->sublo[0]; + bboxhi[0] = domain->subhi[0]; + bboxlo[1] = domain->sublo[1]; + bboxhi[1] = domain->subhi[1]; + bboxlo[2] = domain->sublo[2]; + bboxhi[2] = domain->subhi[2]; + } else + domain->bbox(domain->sublo_lamda, domain->subhi_lamda, bboxlo, bboxhi); // narrow down the subbox by the bounding box of the given region, if available. // for small regions in large boxes, this can result in a significant speedup - if ((style == REGION) && domain->regions[nregion]->bboxflag) { + if ((style == REGION) && region->bboxflag) { - const double rxmin = domain->regions[nregion]->extent_xlo; - const double rxmax = domain->regions[nregion]->extent_xhi; - const double rymin = domain->regions[nregion]->extent_ylo; - const double rymax = domain->regions[nregion]->extent_yhi; - const double rzmin = domain->regions[nregion]->extent_zlo; - const double rzmax = domain->regions[nregion]->extent_zhi; + const double rxmin = region->extent_xlo; + const double rxmax = region->extent_xhi; + const double rymin = region->extent_ylo; + const double rymax = region->extent_yhi; + const double rzmin = region->extent_zlo; + const double rzmax = region->extent_zhi; if (rxmin > bboxlo[0]) bboxlo[0] = (rxmin > bboxhi[0]) ? bboxhi[0] : rxmin; if (rxmax < bboxhi[0]) bboxhi[0] = (rxmax < bboxlo[0]) ? bboxlo[0] : rxmax; @@ -771,27 +780,19 @@ void CreateAtoms::add_lattice() if (rzmax < bboxhi[2]) bboxhi[2] = (rzmax < bboxlo[2]) ? bboxlo[2] : rzmax; } - double xmin,ymin,zmin,xmax,ymax,zmax; + double xmin, ymin, zmin, xmax, ymax, zmax; xmin = ymin = zmin = BIG; xmax = ymax = zmax = -BIG; // convert to lattice coordinates and set bounding box - domain->lattice->bbox(1,bboxlo[0],bboxlo[1],bboxlo[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxhi[0],bboxlo[1],bboxlo[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxlo[0],bboxhi[1],bboxlo[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxhi[0],bboxhi[1],bboxlo[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxlo[0],bboxlo[1],bboxhi[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxhi[0],bboxlo[1],bboxhi[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxlo[0],bboxhi[1],bboxhi[2], - xmin,ymin,zmin,xmax,ymax,zmax); - domain->lattice->bbox(1,bboxhi[0],bboxhi[1],bboxhi[2], - xmin,ymin,zmin,xmax,ymax,zmax); + domain->lattice->bbox(1, bboxlo[0], bboxlo[1], bboxlo[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxhi[0], bboxlo[1], bboxlo[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxlo[0], bboxhi[1], bboxlo[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxhi[0], bboxhi[1], bboxlo[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxlo[0], bboxlo[1], bboxhi[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxhi[0], bboxlo[1], bboxhi[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxlo[0], bboxhi[1], bboxhi[2], xmin, ymin, zmin, xmax, ymax, zmax); + domain->lattice->bbox(1, bboxhi[0], bboxhi[1], bboxhi[2], xmin, ymin, zmin, xmax, ymax, zmax); // ilo:ihi,jlo:jhi,klo:khi = loop bounds for lattice overlap of my subbox // overlap = any part of a unit cell (face,edge,pt) in common with my subbox @@ -802,12 +803,12 @@ void CreateAtoms::add_lattice() // which can lead to missing atoms in rare cases // extra decrement of lo if min < 0, since static_cast(-1.5) = -1 - ilo = static_cast (xmin) - 1; - jlo = static_cast (ymin) - 1; - klo = static_cast (zmin) - 1; - ihi = static_cast (xmax) + 1; - jhi = static_cast (ymax) + 1; - khi = static_cast (zmax) + 1; + ilo = static_cast(xmin) - 1; + jlo = static_cast(ymin) - 1; + klo = static_cast(zmin) - 1; + ihi = static_cast(xmax) + 1; + jhi = static_cast(ymax) + 1; + khi = static_cast(zmax) + 1; if (xmin < 0.0) ilo--; if (ymin < 0.0) jlo--; @@ -821,42 +822,44 @@ void CreateAtoms::add_lattice() // nadd = # of atoms each proc will insert (estimated if subsetflag) int overflow; - MPI_Allreduce(&nlatt_overflow,&overflow,1,MPI_INT,MPI_SUM,world); - if (overflow) - error->all(FLERR,"Create_atoms lattice size overflow on 1 or more procs"); + MPI_Allreduce(&nlatt_overflow, &overflow, 1, MPI_INT, MPI_SUM, world); + if (overflow) error->all(FLERR, "Create_atoms lattice size overflow on 1 or more procs"); bigint nadd; if (subsetflag == NONE) { - if (nprocs == 1) nadd = nlatt; - else nadd = static_cast (LB_FACTOR * nlatt); + if (comm->nprocs == 1) + nadd = nlatt; + else + nadd = static_cast(LB_FACTOR * nlatt); } else { bigint bnlatt = nlatt; bigint bnlattall; - MPI_Allreduce(&bnlatt,&bnlattall,1,MPI_LMP_BIGINT,MPI_SUM,world); - if (subsetflag == RATIO) - nsubset = static_cast (subsetfrac * bnlattall); - if (nsubset > bnlattall) - error->all(FLERR,"Create_atoms subset size > # of lattice sites"); - if (nprocs == 1) nadd = nsubset; - else nadd = static_cast (LB_FACTOR * nsubset/bnlattall * nlatt); + MPI_Allreduce(&bnlatt, &bnlattall, 1, MPI_LMP_BIGINT, MPI_SUM, world); + if (subsetflag == RATIO) nsubset = static_cast(subsetfrac * bnlattall); + if (nsubset > bnlattall) error->all(FLERR, "Create_atoms subset size > # of lattice sites"); + if (comm->nprocs == 1) + nadd = nsubset; + else + nadd = static_cast(LB_FACTOR * nsubset / bnlattall * nlatt); } // allocate atom arrays to size N, rounded up by AtomVec->DELTA bigint nbig = atom->avec->roundup(nadd + atom->nlocal); - int n = static_cast (nbig); + int n = static_cast(nbig); atom->avec->grow(n); // add atoms or molecules // if no subset: add to all lattice sites // if subset: count lattice sites, select random subset, then add - if (subsetflag == NONE) loop_lattice(INSERT); + if (subsetflag == NONE) + loop_lattice(INSERT); else { - memory->create(flag,nlatt,"create_atoms:flag"); - memory->create(next,nlatt,"create_atoms:next"); - ranlatt->select_subset(nsubset,nlatt,flag,next); + memory->create(flag, nlatt, "create_atoms:flag"); + memory->create(next, nlatt, "create_atoms:next"); + ranlatt->select_subset(nsubset, nlatt, flag, next); loop_lattice(INSERT_SELECTED); memory->destroy(flag); memory->destroy(next); @@ -874,9 +877,9 @@ void CreateAtoms::add_lattice() void CreateAtoms::loop_lattice(int action) { - int i,j,k,m; + int i, j, k, m; - const double * const * const basis = domain->lattice->basis; + const double *const *const basis = domain->lattice->basis; nlatt = 0; @@ -885,7 +888,7 @@ void CreateAtoms::loop_lattice(int action) for (i = ilo; i <= ihi; i++) { for (m = 0; m < nbasis; m++) { double *coord; - double x[3],lamda[3]; + double x[3], lamda[3]; x[0] = i + basis[m][0]; x[1] = j + basis[m][1]; @@ -893,12 +896,12 @@ void CreateAtoms::loop_lattice(int action) // convert from lattice coords to box coords - domain->lattice->lattice2box(x[0],x[1],x[2]); + domain->lattice->lattice2box(x[0], x[1], x[2]); // if a region was specified, test if atom is in it if (style == REGION) - if (!domain->regions[nregion]->match(x[0],x[1],x[2])) continue; + if (!region->match(x[0], x[1], x[2])) continue; // if variable test specified, eval variable @@ -907,30 +910,35 @@ void CreateAtoms::loop_lattice(int action) // test if atom/molecule position is in my subbox if (triclinic) { - domain->x2lamda(x,lamda); + domain->x2lamda(x, lamda); coord = lamda; - } else coord = x; + } else + coord = x; - if (coord[0] < sublo[0] || coord[0] >= subhi[0] || - coord[1] < sublo[1] || coord[1] >= subhi[1] || - coord[2] < sublo[2] || coord[2] >= subhi[2]) continue; + if (coord[0] < sublo[0] || coord[0] >= subhi[0] || coord[1] < sublo[1] || + coord[1] >= subhi[1] || coord[2] < sublo[2] || coord[2] >= subhi[2]) + continue; // this proc owns the lattice site // perform action: add, just count, add if flagged // add = add an atom or entire molecule to my list of atoms if (action == INSERT) { - if (mode == ATOM) atom->avec->create_atom(basistype[m],x); + if (mode == ATOM) + atom->avec->create_atom(basistype[m], x); else if (quatone[0] == 0 && quatone[1] == 0 && quatone[2] == 0) add_molecule(x); - else add_molecule(x,quatone); + else + add_molecule(x, quatone); } else if (action == COUNT) { if (nlatt == MAXSMALLINT) nlatt_overflow = 1; } else if (action == INSERT_SELECTED && flag[nlatt]) { - if (mode == ATOM) atom->avec->create_atom(basistype[m],x); + if (mode == ATOM) + atom->avec->create_atom(basistype[m], x); else if (quatone[0] == 0 && quatone[1] == 0 && quatone[2] == 0) add_molecule(x); - else add_molecule(x,quatone); + else + add_molecule(x, quatone); } nlatt++; @@ -948,11 +956,13 @@ void CreateAtoms::loop_lattice(int action) void CreateAtoms::add_molecule(double *center, double *quat_user) { int n; - double r[3],rotmat[3][3],quat[4],xnew[3]; + double r[3], rotmat[3][3], quat[4], xnew[3]; if (quat_user) { - quat[0] = quat_user[0]; quat[1] = quat_user[1]; - quat[2] = quat_user[2]; quat[3] = quat_user[3]; + quat[0] = quat_user[0]; + quat[1] = quat_user[1]; + quat[2] = quat_user[2]; + quat[3] = quat_user[3]; } else { if (domain->dimension == 3) { r[0] = ranmol->uniform() - 0.5; @@ -964,10 +974,10 @@ void CreateAtoms::add_molecule(double *center, double *quat_user) } MathExtra::norm3(r); double theta = ranmol->uniform() * MY_2PI; - MathExtra::axisangle_to_quat(r,theta,quat); + MathExtra::axisangle_to_quat(r, theta, quat); } - MathExtra::quat_to_mat(quat,rotmat); + MathExtra::quat_to_mat(quat, rotmat); onemol->quat_external = quat; // create atoms in molecule with atom ID = 0 and mol ID = 0 @@ -977,11 +987,11 @@ void CreateAtoms::add_molecule(double *center, double *quat_user) int natoms = onemol->natoms; for (int m = 0; m < natoms; m++) { - MathExtra::matvec(rotmat,onemol->dx[m],xnew); - MathExtra::add3(xnew,center,xnew); - atom->avec->create_atom(ntype+onemol->type[m],xnew); + MathExtra::matvec(rotmat, onemol->dx[m], xnew); + MathExtra::add3(xnew, center, xnew); + atom->avec->create_atom(ntype + onemol->type[m], xnew); n = atom->nlocal - 1; - atom->add_molecule_atom(onemol,m,n,0); + atom->add_molecule_atom(onemol, m, n, 0); } } @@ -992,9 +1002,9 @@ void CreateAtoms::add_molecule(double *center, double *quat_user) int CreateAtoms::vartest(double *x) { - if (xstr) input->variable->internal_set(xvar,x[0]); - if (ystr) input->variable->internal_set(yvar,x[1]); - if (zstr) input->variable->internal_set(zvar,x[2]); + if (xstr) input->variable->internal_set(xvar, x[0]); + if (ystr) input->variable->internal_set(yvar, x[1]); + if (zstr) input->variable->internal_set(zvar, x[2]); double value = input->variable->compute_equal(vvar); diff --git a/src/create_atoms.h b/src/create_atoms.h index 5b71394447..f07adf25d1 100644 --- a/src/create_atoms.h +++ b/src/create_atoms.h @@ -30,8 +30,7 @@ class CreateAtoms : public Command { void command(int, char **) override; private: - int me, nprocs; - int ntype, style, mode, nregion, nbasis, nrandom, seed; + int ntype, style, mode, nbasis, nrandom, seed; int remapflag; int subsetflag; bigint nsubset; @@ -51,6 +50,7 @@ class CreateAtoms : public Command { int *flag; // flag subset of particles to insert on lattice int *next; + class Region *region; class Molecule *onemol; class RanMars *ranmol; class RanMars *ranlatt; diff --git a/src/create_box.cpp b/src/create_box.cpp index 73b60eb799..cd6a63ca44 100644 --- a/src/create_box.cpp +++ b/src/create_box.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -36,23 +35,21 @@ CreateBox::CreateBox(LAMMPS *lmp) : Command(lmp) {} void CreateBox::command(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal create_box command"); + if (narg < 2) error->all(FLERR, "Illegal create_box command"); - if (domain->box_exist) - error->all(FLERR,"Cannot create_box after simulation box is defined"); + if (domain->box_exist) error->all(FLERR, "Cannot create_box after simulation box is defined"); if (domain->dimension == 2 && domain->zperiodic == 0) - error->all(FLERR,"Cannot run 2d simulation with nonperiodic Z dimension"); + error->all(FLERR, "Cannot run 2d simulation with nonperiodic Z dimension"); domain->box_exist = 1; // region check - int iregion = domain->find_region(arg[1]); - if (iregion == -1) error->all(FLERR,"Create_box region ID does not exist"); - if (domain->regions[iregion]->bboxflag == 0) - error->all(FLERR,"Create_box region does not support a bounding box"); + auto region = domain->get_region_by_id(arg[1]); + if (!region) error->all(FLERR, "Create_box region {} does not exist", arg[1]); + if (region->bboxflag == 0) error->all(FLERR, "Create_box region does not support a bounding box"); - domain->regions[iregion]->init(); + region->init(); // if region not prism: // setup orthogonal domain @@ -61,27 +58,27 @@ void CreateBox::command(int narg, char **arg) // seutp triclinic domain // set simulation domain params from prism params - if (strcmp(domain->regions[iregion]->style,"prism") != 0) { + if (strcmp(region->style, "prism") != 0) { domain->triclinic = 0; - domain->boxlo[0] = domain->regions[iregion]->extent_xlo; - domain->boxhi[0] = domain->regions[iregion]->extent_xhi; - domain->boxlo[1] = domain->regions[iregion]->extent_ylo; - domain->boxhi[1] = domain->regions[iregion]->extent_yhi; - domain->boxlo[2] = domain->regions[iregion]->extent_zlo; - domain->boxhi[2] = domain->regions[iregion]->extent_zhi; + domain->boxlo[0] = region->extent_xlo; + domain->boxhi[0] = region->extent_xhi; + domain->boxlo[1] = region->extent_ylo; + domain->boxhi[1] = region->extent_yhi; + domain->boxlo[2] = region->extent_zlo; + domain->boxhi[2] = region->extent_zhi; } else { domain->triclinic = 1; - auto region = dynamic_cast( domain->regions[iregion]); - domain->boxlo[0] = region->xlo; - domain->boxhi[0] = region->xhi; - domain->boxlo[1] = region->ylo; - domain->boxhi[1] = region->yhi; - domain->boxlo[2] = region->zlo; - domain->boxhi[2] = region->zhi; - domain->xy = region->xy; - domain->xz = region->xz; - domain->yz = region->yz; + auto prism = dynamic_cast(region); + domain->boxlo[0] = prism->xlo; + domain->boxhi[0] = prism->xhi; + domain->boxlo[1] = prism->ylo; + domain->boxhi[1] = prism->yhi; + domain->boxlo[2] = prism->zlo; + domain->boxhi[2] = prism->zhi; + domain->xy = prism->xy; + domain->xz = prism->xz; + domain->yz = prism->yz; } // if molecular, zero out topology info @@ -99,7 +96,7 @@ void CreateBox::command(int narg, char **arg) // set atom and topology type quantities - atom->ntypes = utils::inumeric(FLERR,arg[0],false,lmp); + atom->ntypes = utils::inumeric(FLERR, arg[0], false, lmp); atom->nbondtypes = 0; atom->nangletypes = 0; atom->ndihedraltypes = 0; @@ -109,60 +106,57 @@ void CreateBox::command(int narg, char **arg) int iarg = 2; while (iarg < narg) { - if (strcmp(arg[iarg],"bond/types") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); - if (!atom->avec->bonds_allow) - error->all(FLERR,"No bonds allowed with this atom style"); - atom->nbondtypes = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (strcmp(arg[iarg], "bond/types") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (!atom->avec->bonds_allow) error->all(FLERR, "No bonds allowed with this atom style"); + atom->nbondtypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"angle/types") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); - if (!atom->avec->angles_allow) - error->all(FLERR,"No angles allowed with this atom style"); - atom->nangletypes = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "angle/types") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (!atom->avec->angles_allow) error->all(FLERR, "No angles allowed with this atom style"); + atom->nangletypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"dihedral/types") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); + } else if (strcmp(arg[iarg], "dihedral/types") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); if (!atom->avec->dihedrals_allow) - error->all(FLERR,"No dihedrals allowed with this atom style"); - atom->ndihedraltypes = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + error->all(FLERR, "No dihedrals allowed with this atom style"); + atom->ndihedraltypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"improper/types") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); + } else if (strcmp(arg[iarg], "improper/types") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); if (!atom->avec->impropers_allow) - error->all(FLERR,"No impropers allowed with this atom style"); - atom->nimpropertypes = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + error->all(FLERR, "No impropers allowed with this atom style"); + atom->nimpropertypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"extra/bond/per/atom") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); - if (!atom->avec->bonds_allow) - error->all(FLERR,"No bonds allowed with this atom style"); - atom->bond_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "extra/bond/per/atom") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (!atom->avec->bonds_allow) error->all(FLERR, "No bonds allowed with this atom style"); + atom->bond_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"extra/angle/per/atom") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); - if (!atom->avec->angles_allow) - error->all(FLERR,"No angles allowed with this atom style"); - atom->angle_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "extra/angle/per/atom") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (!atom->avec->angles_allow) error->all(FLERR, "No angles allowed with this atom style"); + atom->angle_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"extra/dihedral/per/atom") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); + } else if (strcmp(arg[iarg], "extra/dihedral/per/atom") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); if (!atom->avec->dihedrals_allow) - error->all(FLERR,"No dihedrals allowed with this atom style"); - atom->dihedral_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + error->all(FLERR, "No dihedrals allowed with this atom style"); + atom->dihedral_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"extra/improper/per/atom") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); + } else if (strcmp(arg[iarg], "extra/improper/per/atom") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); if (!atom->avec->impropers_allow) - error->all(FLERR,"No impropers allowed with this atom style"); - atom->improper_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + error->all(FLERR, "No impropers allowed with this atom style"); + atom->improper_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"extra/special/per/atom") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal create_box command"); - force->special_extra = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "extra/special/per/atom") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + force->special_extra = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); atom->maxspecial += force->special_extra; iarg += 2; - } else error->all(FLERR,"Illegal create_box command"); + } else + error->all(FLERR, "Illegal create_box command"); } // problem setup using info from header diff --git a/src/dump.h b/src/dump.h index c8712e5909..0d75418de8 100644 --- a/src/dump.h +++ b/src/dump.h @@ -21,7 +21,8 @@ namespace LAMMPS_NS { class Dump : protected Pointers { - friend class Output; + friend class Output; + public: char *id; // user-defined name of Dump char *style; // style of Dump @@ -119,11 +120,11 @@ class Dump : protected Pointers { int fileidx; // index of file in names list char **nameslist; // list of history file names - bigint ntotal; // total # of per-atom lines in snapshot - int reorderflag; // 1 if OK to reorder instead of sort + bigint ntotal; // total # of per-atom lines in snapshot + int reorderflag; // 1 if OK to reorder instead of sort bigint ntotal_reorder; // # of atoms that must be in snapshot - int nme_reorder; // # of atoms I must own in snapshot - tagint idlo; // lowest ID I own when reordering + int nme_reorder; // # of atoms I must own in snapshot + tagint idlo; // lowest ID I own when reordering int maxbuf; // size of buf double *buf; // memory for atom quantities diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 5c8b133700..87bd04b2a9 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -53,14 +53,13 @@ enum{LT,LE,GT,GE,EQ,NEQ,XOR}; /* ---------------------------------------------------------------------- */ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : - Dump(lmp, narg, arg), - idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr), thresh_value(nullptr), - thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr), thresh_first(nullptr), - earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), columns_default(nullptr), - choose(nullptr), dchoose(nullptr), clist(nullptr), field2index(nullptr), argindex(nullptr), - id_compute(nullptr), compute(nullptr), id_fix(nullptr), fix(nullptr), id_variable(nullptr), - variable(nullptr), vbuf(nullptr), id_custom(nullptr), custom(nullptr), custom_flag(nullptr), - typenames(nullptr), pack_choice(nullptr) + Dump(lmp, narg, arg), idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr), + thresh_value(nullptr), thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr), + thresh_first(nullptr), earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), + columns_default(nullptr), choose(nullptr), dchoose(nullptr), clist(nullptr), + field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr), + fix(nullptr), id_variable(nullptr), variable(nullptr), vbuf(nullptr), id_custom(nullptr), + custom(nullptr), custom_flag(nullptr), typenames(nullptr), pack_choice(nullptr) { if (narg == 5) error->all(FLERR,"No dump custom arguments specified"); @@ -87,39 +86,16 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : buffer_allow = 1; buffer_flag = 1; - iregion = -1; - idregion = nullptr; nthresh = 0; - thresh_array = nullptr; - thresh_op = nullptr; - thresh_value = nullptr; - thresh_last = nullptr; - nthreshlast = 0; - thresh_fix = nullptr; - thresh_fixID = nullptr; - thresh_first = nullptr; // computes, fixes, variables which the dump accesses ncompute = 0; - id_compute = nullptr; - compute = nullptr; - nfix = 0; - id_fix = nullptr; - fix = nullptr; - nvariable = 0; - id_variable = nullptr; - variable = nullptr; - vbuf = nullptr; - ncustom = 0; - id_custom = nullptr; - custom = nullptr; - custom_flag = nullptr; // process attributes // ioptional = start of additional optional args in expanded args @@ -144,9 +120,6 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : // atom selection arrays maxlocal = 0; - choose = nullptr; - dchoose = nullptr; - clist = nullptr; // default element name for all types = C @@ -364,13 +337,10 @@ void DumpCustom::init_style() else if (flag && cols) custom_flag[i] = DARRAY; } - // set index and check validity of region + // check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for dump custom does not exist"); - } + if (idregion && !domain->get_region_by_id(idregion)) + error->all(FLERR,"Region {} for dump custom does not exist", idregion); // open single file, one time only @@ -625,8 +595,8 @@ int DumpCustom::count() // un-choose if not in region - if (iregion >= 0) { - Region *region = domain->regions[iregion]; + if (idregion) { + auto region = domain->get_region_by_id(idregion); region->prematch(); double **x = atom->x; for (i = 0; i < nlocal; i++) @@ -1690,12 +1660,13 @@ int DumpCustom::modify_param(int narg, char **arg) { if (strcmp(arg[0],"region") == 0) { if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - if (strcmp(arg[1],"none") == 0) iregion = -1; - else { - iregion = domain->find_region(arg[1]); - if (iregion == -1) - error->all(FLERR,"Dump_modify region ID {} does not exist",arg[1]); + if (strcmp(arg[1],"none") == 0) { delete[] idregion; + idregion = nullptr; + } else { + delete[] idregion; + if (!domain->get_region_by_id(arg[1])) + error->all(FLERR,"Dump_modify region {} does not exist", arg[1]); idregion = utils::strdup(arg[1]); } return 2; diff --git a/src/dump_custom.h b/src/dump_custom.h index 0dcfd82bba..06c9e25733 100644 --- a/src/dump_custom.h +++ b/src/dump_custom.h @@ -35,8 +35,7 @@ class DumpCustom : public Dump { protected: int nevery; // dump frequency for output - int iregion; // -1 if no region, else which region - char *idregion; // region ID + char *idregion; // region ID, nullptr if no region int nthresh; // # of defined thresholds int nthreshlast; // # of defined thresholds with value = LAST @@ -52,16 +51,16 @@ class DumpCustom : public Dump { char **thresh_fixID; // IDs of thresh_fixes int *thresh_first; // 1 the first time a FixStore values accessed - int expand; // flag for whether field args were expanded - char **earg; // field names with wildcard expansion - int nargnew; // size of earg - // - int *vtype; // type of each vector (INT, DOUBLE) - char **vformat; // format string for each vector element - // - char *columns; // column labels + int expand; // flag for whether field args were expanded + char **earg; // field names with wildcard expansion + int nargnew; // size of earg + // + int *vtype; // type of each vector (INT, DOUBLE) + char **vformat; // format string for each vector element + // + char *columns; // column labels char *columns_default; - // + // int nchoose; // # of selected atoms int maxlocal; // size of atom selection and variable arrays int *choose; // local indices of selected atoms diff --git a/src/fix.h b/src/fix.h index 34ef32207d..6bd6b0f241 100644 --- a/src/fix.h +++ b/src/fix.h @@ -280,8 +280,8 @@ class Fix : protected Pointers { } void v_setup(int); void v_tally(int, int *, double, double *); - void v_tally(int,int*,double,double*,int,int,int[][2],double*,double[][3]); - void v_tally(int,int*,double,double*,double[][3],double[][3],double[]); + void v_tally(int, int *, double, double *, int, int, int[][2], double *, double[][3]); + void v_tally(int, int *, double, double *, double[][3], double[][3], double[]); void v_tally(int, double *); void v_tally(int, int, double); }; diff --git a/src/fix_addforce.cpp b/src/fix_addforce.cpp index 0487854ade..48b006eb2d 100644 --- a/src/fix_addforce.cpp +++ b/src/fix_addforce.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -31,16 +30,15 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE,CONSTANT,EQUAL,ATOM}; +enum { NONE, CONSTANT, EQUAL, ATOM }; /* ---------------------------------------------------------------------- */ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - xstr(nullptr), ystr(nullptr), zstr(nullptr), estr(nullptr), - idregion(nullptr), sforce(nullptr) + Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), estr(nullptr), + idregion(nullptr), region(nullptr), sforce(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal fix addforce command"); + if (narg < 6) error->all(FLERR, "Illegal fix addforce command"); dynamic_group_allow = 1; scalar_flag = 1; @@ -54,71 +52,68 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) : respa_level_support = 1; ilevel_respa = 0; - xstr = ystr = zstr = nullptr; - - if (utils::strmatch(arg[3],"^v_")) { - xstr = utils::strdup(arg[3]+2); + if (utils::strmatch(arg[3], "^v_")) { + xstr = utils::strdup(arg[3] + 2); } else { - xvalue = utils::numeric(FLERR,arg[3],false,lmp); + xvalue = utils::numeric(FLERR, arg[3], false, lmp); xstyle = CONSTANT; } - if (utils::strmatch(arg[4],"^v_")) { - ystr = utils::strdup(arg[4]+2); + if (utils::strmatch(arg[4], "^v_")) { + ystr = utils::strdup(arg[4] + 2); } else { - yvalue = utils::numeric(FLERR,arg[4],false,lmp); + yvalue = utils::numeric(FLERR, arg[4], false, lmp); ystyle = CONSTANT; } - if (utils::strmatch(arg[5],"^v_")) { - zstr = utils::strdup(arg[5]+2); + if (utils::strmatch(arg[5], "^v_")) { + zstr = utils::strdup(arg[5] + 2); } else { - zvalue = utils::numeric(FLERR,arg[5],false,lmp); + zvalue = utils::numeric(FLERR, arg[5], false, lmp); zstyle = CONSTANT; } // optional args nevery = 1; - iregion = -1; - int iarg = 6; while (iarg < narg) { - if (strcmp(arg[iarg],"every") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix addforce command"); - nevery = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix addforce command"); + if (strcmp(arg[iarg], "every") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix addforce command"); + nevery = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + if (nevery <= 0) error->all(FLERR, "Illegal fix addforce command"); iarg += 2; - } else if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix addforce command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix addforce does not exist"); - idregion = utils::strdup(arg[iarg+1]); + } else if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix addforce command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix addforce does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"energy") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix addforce command"); - if (utils::strmatch(arg[iarg+1],"^v_")) { - estr = utils::strdup(arg[iarg+1]+2); - } else error->all(FLERR,"Illegal fix addforce command"); + } else if (strcmp(arg[iarg], "energy") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix addforce command"); + if (utils::strmatch(arg[iarg + 1], "^v_")) { + estr = utils::strdup(arg[iarg + 1] + 2); + } else + error->all(FLERR, "Illegal fix addforce command"); iarg += 2; - } else error->all(FLERR,"Illegal fix addforce command"); + } else + error->all(FLERR, "Illegal fix addforce command"); } force_flag = 0; foriginal[0] = foriginal[1] = foriginal[2] = foriginal[3] = 0.0; maxatom = 1; - memory->create(sforce,maxatom,4,"addforce:sforce"); + memory->create(sforce, maxatom, 4, "addforce:sforce"); } /* ---------------------------------------------------------------------- */ FixAddForce::~FixAddForce() { - delete [] xstr; - delete [] ystr; - delete [] zstr; - delete [] estr; - delete [] idregion; + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] estr; + delete[] idregion; memory->destroy(sforce); } @@ -143,60 +138,66 @@ void FixAddForce::init() if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR,"Variable name for fix addforce does not exist"); - if (input->variable->equalstyle(xvar)) xstyle = EQUAL; - else if (input->variable->atomstyle(xvar)) xstyle = ATOM; - else error->all(FLERR,"Variable for fix addforce is invalid style"); + if (xvar < 0) error->all(FLERR, "Variable {} for fix addforce does not exist", xstr); + if (input->variable->equalstyle(xvar)) + xstyle = EQUAL; + else if (input->variable->atomstyle(xvar)) + xstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix addforce is invalid style", xstr); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR,"Variable name for fix addforce does not exist"); - if (input->variable->equalstyle(yvar)) ystyle = EQUAL; - else if (input->variable->atomstyle(yvar)) ystyle = ATOM; - else error->all(FLERR,"Variable for fix addforce is invalid style"); + if (yvar < 0) error->all(FLERR, "Variable {} for fix addforce does not exist", ystr); + if (input->variable->equalstyle(yvar)) + ystyle = EQUAL; + else if (input->variable->atomstyle(yvar)) + ystyle = ATOM; + else + error->all(FLERR, "Variable {} for fix addforce is invalid style", ystr); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR,"Variable name for fix addforce does not exist"); - if (input->variable->equalstyle(zvar)) zstyle = EQUAL; - else if (input->variable->atomstyle(zvar)) zstyle = ATOM; - else error->all(FLERR,"Variable for fix addforce is invalid style"); + if (zvar < 0) error->all(FLERR, "Variable {} for fix addforce does not exist", zstr); + if (input->variable->equalstyle(zvar)) + zstyle = EQUAL; + else if (input->variable->atomstyle(zvar)) + zstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix addforce is invalid style", zstr); } if (estr) { evar = input->variable->find(estr); - if (evar < 0) - error->all(FLERR,"Variable name for fix addforce does not exist"); - if (input->variable->atomstyle(evar)) estyle = ATOM; - else error->all(FLERR,"Variable for fix addforce is invalid style"); - } else estyle = NONE; + if (evar < 0) error->all(FLERR, "Variable {} for fix addforce does not exist", estr); + if (input->variable->atomstyle(evar)) + estyle = ATOM; + else + error->all(FLERR, "Variable {} for fix addforce is invalid style", estr); + } else + estyle = NONE; // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix addforce does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix addforce does not exist", idregion); } if (xstyle == ATOM || ystyle == ATOM || zstyle == ATOM) varflag = ATOM; else if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) varflag = EQUAL; - else varflag = CONSTANT; + else + varflag = CONSTANT; if (varflag == CONSTANT && estyle != NONE) - error->all(FLERR,"Cannot use variable energy with " - "constant force in fix addforce"); - if ((varflag == EQUAL || varflag == ATOM) && - update->whichflag == 2 && estyle == NONE) - error->all(FLERR,"Must use variable energy with fix addforce"); + error->all(FLERR, "Cannot use variable energy with constant force in fix addforce"); + if ((varflag == EQUAL || varflag == ATOM) && update->whichflag == 2 && estyle == NONE) + error->all(FLERR, "Must use variable energy with fix addforce"); - if (utils::strmatch(update->integrate_style,"^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels-1; - if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); + if (utils::strmatch(update->integrate_style, "^respa")) { + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; + if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } } @@ -204,12 +205,12 @@ void FixAddForce::init() void FixAddForce::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) + if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); - post_force_respa(vflag,ilevel_respa,0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel_respa); + post_force_respa(vflag, ilevel_respa, 0); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel_respa); } } @@ -238,23 +239,18 @@ void FixAddForce::post_force(int vflag) v_init(vflag); if (lmp->kokkos) - atom->sync_modify(Host, (unsigned int) (F_MASK | MASK_MASK), - (unsigned int) F_MASK); + atom->sync_modify(Host, (unsigned int) (F_MASK | MASK_MASK), (unsigned int) F_MASK); // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // reallocate sforce array if necessary if ((varflag == ATOM || estyle == ATOM) && atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(sforce); - memory->create(sforce,maxatom,4,"addforce:sforce"); + memory->create(sforce, maxatom, 4, "addforce:sforce"); } // foriginal[0] = "potential energy" for added force @@ -270,9 +266,9 @@ void FixAddForce::post_force(int vflag) double unwrap[3]; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - domain->unmap(x[i],image[i],unwrap); - foriginal[0] -= xvalue*unwrap[0] + yvalue*unwrap[1] + zvalue*unwrap[2]; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + domain->unmap(x[i], image[i], unwrap); + foriginal[0] -= xvalue * unwrap[0] + yvalue * unwrap[1] + zvalue * unwrap[2]; foriginal[1] += f[i][0]; foriginal[2] += f[i][1]; foriginal[3] += f[i][2]; @@ -286,37 +282,39 @@ void FixAddForce::post_force(int vflag) v[3] = xvalue * unwrap[1]; v[4] = xvalue * unwrap[2]; v[5] = yvalue * unwrap[2]; - v_tally(i,v); + v_tally(i, v); } } - // variable force, wrap with clear/add - // potential energy = evar if defined, else 0.0 - // wrap with clear/add + // variable force, wrap with clear/add + // potential energy = evar if defined, else 0.0 + // wrap with clear/add } else { double unwrap[3]; modify->clearstep_compute(); - if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar); + if (xstyle == EQUAL) + xvalue = input->variable->compute_equal(xvar); else if (xstyle == ATOM) - input->variable->compute_atom(xvar,igroup,&sforce[0][0],4,0); - if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar); + input->variable->compute_atom(xvar, igroup, &sforce[0][0], 4, 0); + if (ystyle == EQUAL) + yvalue = input->variable->compute_equal(yvar); else if (ystyle == ATOM) - input->variable->compute_atom(yvar,igroup,&sforce[0][1],4,0); - if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar); + input->variable->compute_atom(yvar, igroup, &sforce[0][1], 4, 0); + if (zstyle == EQUAL) + zvalue = input->variable->compute_equal(zvar); else if (zstyle == ATOM) - input->variable->compute_atom(zvar,igroup,&sforce[0][2],4,0); - if (estyle == ATOM) - input->variable->compute_atom(evar,igroup,&sforce[0][3],4,0); + input->variable->compute_atom(zvar, igroup, &sforce[0][2], 4, 0); + if (estyle == ATOM) input->variable->compute_atom(evar, igroup, &sforce[0][3], 4, 0); modify->addstep_compute(update->ntimestep + 1); for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - domain->unmap(x[i],image[i],unwrap); + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + domain->unmap(x[i], image[i], unwrap); if (xstyle == ATOM) xvalue = sforce[i][0]; if (ystyle == ATOM) yvalue = sforce[i][1]; if (zstyle == ATOM) zvalue = sforce[i][2]; @@ -324,9 +322,9 @@ void FixAddForce::post_force(int vflag) if (estyle == ATOM) { foriginal[0] += sforce[i][3]; } else { - if (xstyle) foriginal[0] -= xvalue*unwrap[0]; - if (ystyle) foriginal[0] -= yvalue*unwrap[1]; - if (zstyle) foriginal[0] -= zvalue*unwrap[2]; + if (xstyle) foriginal[0] -= xvalue * unwrap[0]; + if (ystyle) foriginal[0] -= yvalue * unwrap[1]; + if (zstyle) foriginal[0] -= zvalue * unwrap[2]; } foriginal[1] += f[i][0]; foriginal[2] += f[i][1]; @@ -336,13 +334,13 @@ void FixAddForce::post_force(int vflag) if (ystyle) f[i][1] += yvalue; if (zstyle) f[i][2] += zvalue; if (evflag) { - v[0] = xstyle ? xvalue*unwrap[0] : 0.0; - v[1] = ystyle ? yvalue*unwrap[1] : 0.0; - v[2] = zstyle ? zvalue*unwrap[2] : 0.0; - v[3] = xstyle ? xvalue*unwrap[1] : 0.0; - v[4] = xstyle ? xvalue*unwrap[2] : 0.0; - v[5] = ystyle ? yvalue*unwrap[2] : 0.0; - v_tally(i,v); + v[0] = xstyle ? xvalue * unwrap[0] : 0.0; + v[1] = ystyle ? yvalue * unwrap[1] : 0.0; + v[2] = zstyle ? zvalue * unwrap[2] : 0.0; + v[3] = xstyle ? xvalue * unwrap[1] : 0.0; + v[4] = xstyle ? xvalue * unwrap[2] : 0.0; + v[5] = ystyle ? yvalue * unwrap[2] : 0.0; + v_tally(i, v); } } } @@ -372,7 +370,7 @@ double FixAddForce::compute_scalar() // only sum across procs one time if (force_flag == 0) { - MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(foriginal, foriginal_all, 4, MPI_DOUBLE, MPI_SUM, world); force_flag = 1; } return foriginal_all[0]; @@ -387,10 +385,10 @@ double FixAddForce::compute_vector(int n) // only sum across procs one time if (force_flag == 0) { - MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(foriginal, foriginal_all, 4, MPI_DOUBLE, MPI_SUM, world); force_flag = 1; } - return foriginal_all[n+1]; + return foriginal_all[n + 1]; } /* ---------------------------------------------------------------------- @@ -400,6 +398,6 @@ double FixAddForce::compute_vector(int n) double FixAddForce::memory_usage() { double bytes = 0.0; - if (varflag == ATOM) bytes = maxatom*4 * sizeof(double); + if (varflag == ATOM) bytes = maxatom * 4 * sizeof(double); return bytes; } diff --git a/src/fix_addforce.h b/src/fix_addforce.h index a3d579c495..5c5a58f16d 100644 --- a/src/fix_addforce.h +++ b/src/fix_addforce.h @@ -41,9 +41,10 @@ class FixAddForce : public Fix { private: double xvalue, yvalue, zvalue; - int varflag, iregion; + int varflag; char *xstr, *ystr, *zstr, *estr; char *idregion; + class Region *region; int xvar, yvar, zvar, evar, xstyle, ystyle, zstyle, estyle; double foriginal[4], foriginal_all[4]; int force_flag; diff --git a/src/fix_aveforce.cpp b/src/fix_aveforce.cpp index 2d172adb9b..e2369697ca 100644 --- a/src/fix_aveforce.cpp +++ b/src/fix_aveforce.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -29,15 +28,15 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE,CONSTANT,EQUAL}; +enum { NONE, CONSTANT, EQUAL }; /* ---------------------------------------------------------------------- */ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr) + Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr), + region(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal fix aveforce command"); + if (narg < 6) error->all(FLERR, "Illegal fix aveforce command"); dynamic_group_allow = 1; vector_flag = 1; @@ -49,61 +48,56 @@ FixAveForce::FixAveForce(LAMMPS *lmp, int narg, char **arg) : xstr = ystr = zstr = nullptr; - if (utils::strmatch(arg[3],"^v_")) { - xstr = utils::strdup(arg[3]+2); - } else if (strcmp(arg[3],"NULL") == 0) { + if (utils::strmatch(arg[3], "^v_")) { + xstr = utils::strdup(arg[3] + 2); + } else if (strcmp(arg[3], "NULL") == 0) { xstyle = NONE; } else { - xvalue = utils::numeric(FLERR,arg[3],false,lmp); + xvalue = utils::numeric(FLERR, arg[3], false, lmp); xstyle = CONSTANT; } - if (utils::strmatch(arg[4],"^v_")) { - ystr = utils::strdup(arg[4]+2); - } else if (strcmp(arg[4],"NULL") == 0) { + if (utils::strmatch(arg[4], "^v_")) { + ystr = utils::strdup(arg[4] + 2); + } else if (strcmp(arg[4], "NULL") == 0) { ystyle = NONE; } else { - yvalue = utils::numeric(FLERR,arg[4],false,lmp); + yvalue = utils::numeric(FLERR, arg[4], false, lmp); ystyle = CONSTANT; } - if (utils::strmatch(arg[5],"^v_")) { - zstr = utils::strdup(arg[5]+2); - } else if (strcmp(arg[5],"NULL") == 0) { + if (utils::strmatch(arg[5], "^v_")) { + zstr = utils::strdup(arg[5] + 2); + } else if (strcmp(arg[5], "NULL") == 0) { zstyle = NONE; } else { - zvalue = utils::numeric(FLERR,arg[5],false,lmp); + zvalue = utils::numeric(FLERR, arg[5], false, lmp); zstyle = CONSTANT; } // optional args - iregion = -1; - idregion = nullptr; - int iarg = 6; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix aveforce command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix aveforce does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix aveforce command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix aveforce does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else error->all(FLERR,"Illegal fix aveforce command"); - + } else + error->all(FLERR, "Illegal fix aveforce command"); } - foriginal_all[0] = foriginal_all[1] = - foriginal_all[2] = foriginal_all[3] = 0.0; + foriginal_all[0] = foriginal_all[1] = foriginal_all[2] = foriginal_all[3] = 0.0; } /* ---------------------------------------------------------------------- */ FixAveForce::~FixAveForce() { - delete [] xstr; - delete [] ystr; - delete [] zstr; - delete [] idregion; + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] idregion; } /* ---------------------------------------------------------------------- */ @@ -125,41 +119,47 @@ void FixAveForce::init() if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR,"Variable name for fix aveforce does not exist"); - if (input->variable->equalstyle(xvar)) xstyle = EQUAL; - else error->all(FLERR,"Variable for fix aveforce is invalid style"); + if (xvar < 0) error->all(FLERR, "Variable name for fix aveforce does not exist"); + if (input->variable->equalstyle(xvar)) + xstyle = EQUAL; + else + error->all(FLERR, "Variable for fix aveforce is invalid style"); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR,"Variable name for fix aveforce does not exist"); - if (input->variable->equalstyle(yvar)) ystyle = EQUAL; - else error->all(FLERR,"Variable for fix aveforce is invalid style"); + if (yvar < 0) error->all(FLERR, "Variable name for fix aveforce does not exist"); + if (input->variable->equalstyle(yvar)) + ystyle = EQUAL; + else + error->all(FLERR, "Variable for fix aveforce is invalid style"); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR,"Variable name for fix aveforce does not exist"); - if (input->variable->equalstyle(zvar)) zstyle = EQUAL; - else error->all(FLERR,"Variable for fix aveforce is invalid style"); + if (zvar < 0) error->all(FLERR, "Variable name for fix aveforce does not exist"); + if (input->variable->equalstyle(zvar)) + zstyle = EQUAL; + else + error->all(FLERR, "Variable for fix aveforce is invalid style"); } // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix aveforce does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix aveforce does not exist", idregion); } - if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) varflag = EQUAL; - else varflag = CONSTANT; + if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) + varflag = EQUAL; + else + varflag = CONSTANT; - if (utils::strmatch(update->integrate_style,"^respa")) { - nlevels_respa = (dynamic_cast( update->integrate))->nlevels; - if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1); - else ilevel_respa = nlevels_respa-1; + if (utils::strmatch(update->integrate_style, "^respa")) { + nlevels_respa = (dynamic_cast(update->integrate))->nlevels; + if (respa_level >= 0) + ilevel_respa = MIN(respa_level, nlevels_respa - 1); + else + ilevel_respa = nlevels_respa - 1; } } @@ -167,13 +167,13 @@ void FixAveForce::init() void FixAveForce::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) + if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel); - post_force_respa(vflag,ilevel,0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel); + post_force_respa(vflag, ilevel, 0); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel); } } @@ -190,11 +190,7 @@ void FixAveForce::post_force(int /*vflag*/) { // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // sum forces on participating atoms @@ -208,7 +204,7 @@ void FixAveForce::post_force(int /*vflag*/) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += f[i][0]; foriginal[1] += f[i][1]; foriginal[2] += f[i][2]; @@ -219,9 +215,9 @@ void FixAveForce::post_force(int /*vflag*/) // add in requested amount, computed via variable evaluation if necessary // wrap variable evaluation with clear/add - MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(foriginal, foriginal_all, 4, MPI_DOUBLE, MPI_SUM, world); - int ncount = static_cast (foriginal_all[3]); + int ncount = static_cast(foriginal_all[3]); if (ncount == 0) return; if (varflag == EQUAL) { @@ -233,16 +229,16 @@ void FixAveForce::post_force(int /*vflag*/) } double fave[3]; - fave[0] = foriginal_all[0]/ncount + xvalue; - fave[1] = foriginal_all[1]/ncount + yvalue; - fave[2] = foriginal_all[2]/ncount + zvalue; + fave[0] = foriginal_all[0] / ncount + xvalue; + fave[1] = foriginal_all[1] / ncount + yvalue; + fave[2] = foriginal_all[2] / ncount + zvalue; // set force of all participating atoms to same value // only for active dimensions for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; if (xstyle) f[i][0] = fave[0]; if (ystyle) f[i][1] = fave[1]; if (zstyle) f[i][2] = fave[2]; @@ -256,13 +252,10 @@ void FixAveForce::post_force_respa(int vflag, int ilevel, int /*iloop*/) // ave + extra force on selected RESPA level // just ave on all other levels - if (ilevel == ilevel_respa) post_force(vflag); - else { - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (ilevel == ilevel_respa) { + post_force(vflag); + } else { + if (region) region->prematch(); double **x = atom->x; double **f = atom->f; @@ -274,26 +267,26 @@ void FixAveForce::post_force_respa(int vflag, int ilevel, int /*iloop*/) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += f[i][0]; foriginal[1] += f[i][1]; foriginal[2] += f[i][2]; foriginal[3] += 1.0; } - MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(foriginal, foriginal_all, 4, MPI_DOUBLE, MPI_SUM, world); - int ncount = static_cast (foriginal_all[3]); + int ncount = static_cast(foriginal_all[3]); if (ncount == 0) return; double fave[3]; - fave[0] = foriginal_all[0]/ncount; - fave[1] = foriginal_all[1]/ncount; - fave[2] = foriginal_all[2]/ncount; + fave[0] = foriginal_all[0] / ncount; + fave[1] = foriginal_all[1] / ncount; + fave[2] = foriginal_all[2] / ncount; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; if (xstyle) f[i][0] = fave[0]; if (ystyle) f[i][1] = fave[1]; if (zstyle) f[i][2] = fave[2]; diff --git a/src/fix_aveforce.h b/src/fix_aveforce.h index 88c83064b0..92534685e7 100644 --- a/src/fix_aveforce.h +++ b/src/fix_aveforce.h @@ -42,8 +42,8 @@ class FixAveForce : public Fix { int varflag; char *xstr, *ystr, *zstr; char *idregion; + class Region *region; int xvar, yvar, zvar, xstyle, ystyle, zstyle; - int iregion; double foriginal_all[4]; int nlevels_respa, ilevel_respa; }; diff --git a/src/fix_efield.cpp b/src/fix_efield.cpp index a17a122e9d..3a2d8cfb5c 100644 --- a/src/fix_efield.cpp +++ b/src/fix_efield.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -40,10 +39,10 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixEfield::FixEfield(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), - estr(nullptr), idregion(nullptr), efield(nullptr) + Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), estr(nullptr), + idregion(nullptr), region(nullptr), efield(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal fix efield command"); + if (narg < 6) error->all(FLERR, "Illegal fix efield command"); dynamic_group_allow = 1; vector_flag = 1; @@ -60,56 +59,53 @@ FixEfield::FixEfield(LAMMPS *lmp, int narg, char **arg) : qe2f = force->qe2f; xstr = ystr = zstr = nullptr; - if (utils::strmatch(arg[3],"^v_")) { - xstr = utils::strdup(arg[3]+2); + if (utils::strmatch(arg[3], "^v_")) { + xstr = utils::strdup(arg[3] + 2); } else { - ex = qe2f * utils::numeric(FLERR,arg[3],false,lmp); + ex = qe2f * utils::numeric(FLERR, arg[3], false, lmp); xstyle = CONSTANT; } - if (utils::strmatch(arg[4],"^v_")) { - ystr = utils::strdup(arg[4]+2); + if (utils::strmatch(arg[4], "^v_")) { + ystr = utils::strdup(arg[4] + 2); } else { - ey = qe2f * utils::numeric(FLERR,arg[4],false,lmp); + ey = qe2f * utils::numeric(FLERR, arg[4], false, lmp); ystyle = CONSTANT; } - if (utils::strmatch(arg[5],"^v_")) { - zstr = utils::strdup(arg[5]+2); + if (utils::strmatch(arg[5], "^v_")) { + zstr = utils::strdup(arg[5] + 2); } else { - ez = qe2f * utils::numeric(FLERR,arg[5],false,lmp); + ez = qe2f * utils::numeric(FLERR, arg[5], false, lmp); zstyle = CONSTANT; } // optional args - iregion = -1; - idregion = nullptr; - estr = nullptr; - int iarg = 6; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix efield command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix efield does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix efield command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix efield does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"energy") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix efield command"); - if (utils::strmatch(arg[iarg+1],"^v_")) { - estr = utils::strdup(arg[iarg+1]+2); - } else error->all(FLERR,"Illegal fix efield command"); + } else if (strcmp(arg[iarg], "energy") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix efield command"); + if (utils::strmatch(arg[iarg + 1], "^v_")) { + estr = utils::strdup(arg[iarg + 1] + 2); + } else + error->all(FLERR, "Illegal fix efield command"); iarg += 2; - } else error->all(FLERR,"Illegal fix efield command"); + } else + error->all(FLERR, "Illegal fix efield command"); } force_flag = 0; fsum[0] = fsum[1] = fsum[2] = fsum[3] = 0.0; maxatom = atom->nmax; - memory->create(efield,maxatom,4,"efield:efield"); + memory->create(efield, maxatom, 4, "efield:efield"); maxatom_energy = 0; } @@ -118,11 +114,11 @@ FixEfield::FixEfield(LAMMPS *lmp, int narg, char **arg) : FixEfield::~FixEfield() { - delete [] xstr; - delete [] ystr; - delete [] zstr; - delete [] estr; - delete [] idregion; + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] estr; + delete[] idregion; memory->destroy(efield); } @@ -144,74 +140,78 @@ void FixEfield::init() qflag = muflag = 0; if (atom->q_flag) qflag = 1; if (atom->mu_flag && atom->torque_flag) muflag = 1; - if (!qflag && !muflag) - error->all(FLERR,"Fix efield requires atom attribute q or mu"); + if (!qflag && !muflag) error->all(FLERR, "Fix efield requires atom attribute q or mu"); // check variables if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR,"Variable name for fix efield does not exist"); - if (input->variable->equalstyle(xvar)) xstyle = EQUAL; - else if (input->variable->atomstyle(xvar)) xstyle = ATOM; - else error->all(FLERR,"Variable for fix efield is invalid style"); + if (xvar < 0) error->all(FLERR, "Variable {} for fix efield does not exist", xstr); + if (input->variable->equalstyle(xvar)) + xstyle = EQUAL; + else if (input->variable->atomstyle(xvar)) + xstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix efield is invalid style", xstr); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR,"Variable name for fix efield does not exist"); - if (input->variable->equalstyle(yvar)) ystyle = EQUAL; - else if (input->variable->atomstyle(yvar)) ystyle = ATOM; - else error->all(FLERR,"Variable for fix efield is invalid style"); + if (yvar < 0) error->all(FLERR, "Variable {} for fix efield does not exist", ystr); + if (input->variable->equalstyle(yvar)) + ystyle = EQUAL; + else if (input->variable->atomstyle(yvar)) + ystyle = ATOM; + else + error->all(FLERR, "Variable {} for fix efield is invalid style", ystr); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR,"Variable name for fix efield does not exist"); - if (input->variable->equalstyle(zvar)) zstyle = EQUAL; - else if (input->variable->atomstyle(zvar)) zstyle = ATOM; - else error->all(FLERR,"Variable for fix efield is invalid style"); + if (zvar < 0) error->all(FLERR, "Variable {} for fix efield does not exist", zstr); + if (input->variable->equalstyle(zvar)) + zstyle = EQUAL; + else if (input->variable->atomstyle(zvar)) + zstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix efield is invalid style", zstr); } if (estr) { evar = input->variable->find(estr); - if (evar < 0) - error->all(FLERR,"Variable name for fix efield does not exist"); - if (input->variable->atomstyle(evar)) estyle = ATOM; - else error->all(FLERR,"Variable for fix efield is invalid style"); - } else estyle = NONE; - + if (evar < 0) error->all(FLERR, "Variable {} for fix efield does not exist", estr); + if (input->variable->atomstyle(evar)) + estyle = ATOM; + else + error->all(FLERR, "Variable {} for fix efield is invalid style", estr); + } else + estyle = NONE; // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix aveforce does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix aveforce does not exist", idregion); } if (xstyle == ATOM || ystyle == ATOM || zstyle == ATOM) varflag = ATOM; else if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) varflag = EQUAL; - else varflag = CONSTANT; + else + varflag = CONSTANT; if (muflag && varflag == ATOM) - error->all(FLERR,"Fix efield with dipoles cannot use atom-style variables"); + error->all(FLERR, "Fix efield with dipoles cannot use atom-style variables"); if (muflag && update->whichflag == 2 && comm->me == 0) error->warning(FLERR, "The minimizer does not re-orient dipoles when using fix efield"); if (varflag == CONSTANT && estyle != NONE) - error->all(FLERR,"Cannot use variable energy with " - "constant efield in fix efield"); - if ((varflag == EQUAL || varflag == ATOM) && - update->whichflag == 2 && estyle == NONE) - error->all(FLERR,"Must use variable energy with fix efield"); + error->all(FLERR, "Cannot use variable energy with constant efield in fix efield"); + if ((varflag == EQUAL || varflag == ATOM) && update->whichflag == 2 && estyle == NONE) + error->all(FLERR, "Must use variable energy with fix efield"); - if (utils::strmatch(update->integrate_style,"^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels-1; - if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); + if (utils::strmatch(update->integrate_style, "^respa")) { + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; + if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } } @@ -219,12 +219,13 @@ void FixEfield::init() void FixEfield::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) + if (utils::strmatch(update->integrate_style, "^respa")) { + auto respa = dynamic_cast(update->integrate); + respa->copy_flevel_f(ilevel_respa); + post_force_respa(vflag, ilevel_respa, 0); + respa->copy_f_flevel(ilevel_respa); + } else { post_force(vflag); - else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); - post_force_respa(vflag,ilevel_respa,0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); } } @@ -256,16 +257,12 @@ void FixEfield::post_force(int vflag) if (varflag == ATOM && atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(efield); - memory->create(efield,maxatom,4,"efield:efield"); + memory->create(efield, maxatom, 4, "efield:efield"); } // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // fsum[0] = "potential energy" for added force // fsum[123] = extra force added to atoms @@ -274,7 +271,7 @@ void FixEfield::post_force(int vflag) force_flag = 0; double **x = atom->x; - double fx,fy,fz; + double fx, fy, fz; double v[6]; // constant efield @@ -288,27 +285,27 @@ void FixEfield::post_force(int vflag) if (qflag) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - fx = q[i]*ex; - fy = q[i]*ey; - fz = q[i]*ez; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + fx = q[i] * ex; + fy = q[i] * ey; + fz = q[i] * ez; f[i][0] += fx; f[i][1] += fy; f[i][2] += fz; - domain->unmap(x[i],image[i],unwrap); - fsum[0] -= fx*unwrap[0]+fy*unwrap[1]+fz*unwrap[2]; + domain->unmap(x[i], image[i], unwrap); + fsum[0] -= fx * unwrap[0] + fy * unwrap[1] + fz * unwrap[2]; fsum[1] += fx; fsum[2] += fy; fsum[3] += fz; if (evflag) { - v[0] = fx*unwrap[0]; - v[1] = fy*unwrap[1]; - v[2] = fz*unwrap[2]; - v[3] = fx*unwrap[1]; - v[4] = fx*unwrap[2]; - v[5] = fy*unwrap[2]; - v_tally(i,v); + v[0] = fx * unwrap[0]; + v[1] = fy * unwrap[1]; + v[2] = fz * unwrap[2]; + v[3] = fx * unwrap[1]; + v[4] = fx * unwrap[2]; + v[5] = fy * unwrap[2]; + v_tally(i, v); } } } @@ -319,38 +316,43 @@ void FixEfield::post_force(int vflag) if (muflag) { double **mu = atom->mu; double **t = atom->torque; - double tx,ty,tz; + double tx, ty, tz; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - tx = ez*mu[i][1] - ey*mu[i][2]; - ty = ex*mu[i][2] - ez*mu[i][0]; - tz = ey*mu[i][0] - ex*mu[i][1]; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + tx = ez * mu[i][1] - ey * mu[i][2]; + ty = ex * mu[i][2] - ez * mu[i][0]; + tz = ey * mu[i][0] - ex * mu[i][1]; t[i][0] += tx; t[i][1] += ty; t[i][2] += tz; - fsum[0] -= mu[i][0]*ex + mu[i][1]*ey + mu[i][2]*ez; + fsum[0] -= mu[i][0] * ex + mu[i][1] * ey + mu[i][2] * ez; } } - // variable efield, wrap with clear/add - // potential energy = evar if defined, else 0.0 + // variable efield, wrap with clear/add + // potential energy = evar if defined, else 0.0 } else { modify->clearstep_compute(); - if (xstyle == EQUAL) ex = qe2f * input->variable->compute_equal(xvar); - else if (xstyle == ATOM) - input->variable->compute_atom(xvar,igroup,&efield[0][0],4,0); - if (ystyle == EQUAL) ey = qe2f * input->variable->compute_equal(yvar); - else if (ystyle == ATOM) - input->variable->compute_atom(yvar,igroup,&efield[0][1],4,0); - if (zstyle == EQUAL) ez = qe2f * input->variable->compute_equal(zvar); - else if (zstyle == ATOM) - input->variable->compute_atom(zvar,igroup,&efield[0][2],4,0); - if (estyle == ATOM) - input->variable->compute_atom(evar,igroup,&efield[0][3],4,0); + if (xstyle == EQUAL) { + ex = qe2f * input->variable->compute_equal(xvar); + } else if (xstyle == ATOM) { + input->variable->compute_atom(xvar, igroup, &efield[0][0], 4, 0); + } + if (ystyle == EQUAL) { + ey = qe2f * input->variable->compute_equal(yvar); + } else if (ystyle == ATOM) { + input->variable->compute_atom(yvar, igroup, &efield[0][1], 4, 0); + } + if (zstyle == EQUAL) { + ez = qe2f * input->variable->compute_equal(zvar); + } else if (zstyle == ATOM) { + input->variable->compute_atom(zvar, igroup, &efield[0][2], 4, 0); + } + if (estyle == ATOM) input->variable->compute_atom(evar, igroup, &efield[0][3], 4, 0); modify->addstep_compute(update->ntimestep + 1); @@ -360,17 +362,26 @@ void FixEfield::post_force(int vflag) if (qflag) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - if (xstyle == ATOM) fx = qe2f * q[i]*efield[i][0]; - else fx = q[i]*ex; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + if (xstyle == ATOM) { + fx = qe2f * q[i] * efield[i][0]; + } else { + fx = q[i] * ex; + } f[i][0] += fx; fsum[1] += fx; - if (ystyle == ATOM) fy = qe2f * q[i]*efield[i][1]; - else fy = q[i]*ey; + if (ystyle == ATOM) { + fy = qe2f * q[i] * efield[i][1]; + } else { + fy = q[i] * ey; + } f[i][1] += fy; fsum[2] += fy; - if (zstyle == ATOM) fz = qe2f * q[i]*efield[i][2]; - else fz = q[i]*ez; + if (zstyle == ATOM) { + fz = qe2f * q[i] * efield[i][2]; + } else { + fz = q[i] * ez; + } f[i][2] += fz; fsum[3] += fz; if (estyle == ATOM) fsum[0] += efield[0][3]; @@ -383,13 +394,13 @@ void FixEfield::post_force(int vflag) if (muflag) { double **mu = atom->mu; double **t = atom->torque; - double tx,ty,tz; + double tx, ty, tz; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; - tx = ez*mu[i][1] - ey*mu[i][2]; - ty = ex*mu[i][2] - ez*mu[i][0]; - tz = ey*mu[i][0] - ex*mu[i][1]; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; + tx = ez * mu[i][1] - ey * mu[i][2]; + ty = ex * mu[i][2] - ez * mu[i][0]; + tz = ey * mu[i][0] - ex * mu[i][1]; t[i][0] += tx; t[i][1] += ty; t[i][2] += tz; @@ -419,7 +430,7 @@ void FixEfield::min_post_force(int vflag) double FixEfield::memory_usage() { double bytes = 0.0; - if (varflag == ATOM) bytes = atom->nmax*4 * sizeof(double); + if (varflag == ATOM) bytes = atom->nmax * 4 * sizeof(double); return bytes; } @@ -430,7 +441,7 @@ double FixEfield::memory_usage() double FixEfield::compute_scalar() { if (force_flag == 0) { - MPI_Allreduce(fsum,fsum_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(fsum, fsum_all, 4, MPI_DOUBLE, MPI_SUM, world); force_flag = 1; } return fsum_all[0]; @@ -443,9 +454,8 @@ double FixEfield::compute_scalar() double FixEfield::compute_vector(int n) { if (force_flag == 0) { - MPI_Allreduce(fsum,fsum_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(fsum, fsum_all, 4, MPI_DOUBLE, MPI_SUM, world); force_flag = 1; } - return fsum_all[n+1]; + return fsum_all[n + 1]; } - diff --git a/src/fix_efield.h b/src/fix_efield.h index 9148a94d99..2a9c0674d7 100644 --- a/src/fix_efield.h +++ b/src/fix_efield.h @@ -26,6 +26,7 @@ namespace LAMMPS_NS { class FixEfield : public Fix { friend class FixQEqReaxFF; + public: FixEfield(class LAMMPS *, int, char **); ~FixEfield() override; @@ -44,9 +45,10 @@ class FixEfield : public Fix { protected: double ex, ey, ez; - int varflag, iregion; + int varflag; char *xstr, *ystr, *zstr, *estr; char *idregion; + class Region *region; int xvar, yvar, zvar, evar, xstyle, ystyle, zstyle, estyle; int ilevel_respa; double qe2f; diff --git a/src/fix_evaporate.cpp b/src/fix_evaporate.cpp index 531dcf9ffd..ec3a85b259 100644 --- a/src/fix_evaporate.cpp +++ b/src/fix_evaporate.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -35,32 +34,31 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixEvaporate::FixEvaporate(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), idregion(nullptr), list(nullptr), mark(nullptr), random(nullptr) + Fix(lmp, narg, arg), idregion(nullptr), region(nullptr), list(nullptr), mark(nullptr), + random(nullptr) { - if (narg < 7) error->all(FLERR,"Illegal fix evaporate command"); + if (narg < 7) error->all(FLERR, "Illegal fix evaporate command"); scalar_flag = 1; global_freq = 1; extscalar = 0; - nevery = utils::inumeric(FLERR,arg[3],false,lmp); - nflux = utils::inumeric(FLERR,arg[4],false,lmp); - iregion = domain->find_region(arg[5]); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); + nflux = utils::inumeric(FLERR, arg[4], false, lmp); + region = domain->get_region_by_id(arg[5]); idregion = utils::strdup(arg[5]); - int seed = utils::inumeric(FLERR,arg[6],false,lmp); + int seed = utils::inumeric(FLERR, arg[6], false, lmp); - if (nevery <= 0 || nflux <= 0) - error->all(FLERR,"Illegal fix evaporate command"); - if (iregion == -1) - error->all(FLERR,"Region ID for fix evaporate does not exist"); - if (seed <= 0) error->all(FLERR,"Illegal fix evaporate command"); + if (nevery <= 0 || nflux <= 0) error->all(FLERR, "Illegal fix evaporate command"); + if (!region) error->all(FLERR, "Region {} for fix evaporate does not exist", idregion); + if (seed <= 0) error->all(FLERR, "Illegal fix evaporate command"); // random number generator, same for all procs // warm up the generator 30x to avoid correlations in first-particle // positions if runs are repeated with consecutive seeds - random = new RanPark(lmp,seed); - for (int ii=0; ii < 30; ii++) random->uniform(); + random = new RanPark(lmp, seed); + for (int ii = 0; ii < 30; ii++) random->uniform(); // optional args @@ -68,17 +66,18 @@ FixEvaporate::FixEvaporate(LAMMPS *lmp, int narg, char **arg) : int iarg = 7; while (iarg < narg) { - if (strcmp(arg[iarg],"molecule") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix evaporate command"); - molflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + if (strcmp(arg[iarg], "molecule") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix evaporate command"); + molflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else error->all(FLERR,"Illegal fix evaporate command"); + } else + error->all(FLERR, "Illegal fix evaporate command"); } // set up reneighboring force_reneighbor = 1; - next_reneighbor = (update->ntimestep/nevery)*nevery + nevery; + next_reneighbor = (update->ntimestep / nevery) * nevery + nevery; ndeleted = 0; nmax = 0; @@ -90,7 +89,7 @@ FixEvaporate::FixEvaporate(LAMMPS *lmp, int narg, char **arg) : FixEvaporate::~FixEvaporate() { - delete [] idregion; + delete[] idregion; delete random; memory->destroy(list); memory->destroy(mark); @@ -111,9 +110,8 @@ void FixEvaporate::init() { // set index and check validity of region - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix evaporate does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix evaporate does not exist", idregion); // check that no deletable atoms are in atom->firstgroup // deleting such an atom would not leave firstgroup atoms first @@ -128,10 +126,9 @@ void FixEvaporate::init() if ((mask[i] & groupbit) && (mask[i] && firstgroupbit)) flag = 1; int flagall; - MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); - if (flagall) - error->all(FLERR,"Cannot evaporate atoms in atom_modify first group"); + if (flagall) error->all(FLERR, "Cannot evaporate atoms in atom_modify first group"); } // if molflag not set, warn if any deletable atom has a mol ID @@ -145,15 +142,13 @@ void FixEvaporate::init() if (mask[i] & groupbit) if (molecule[i]) flag = 1; int flagall; - MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); if (flagall && comm->me == 0) - error->warning(FLERR, - "Fix evaporate may delete atom with non-zero molecule ID"); + error->warning(FLERR, "Fix evaporate may delete atom with non-zero molecule ID"); } if (molflag && atom->molecule_flag == 0) - error->all(FLERR, - "Fix evaporate molecule requires atom attribute molecule"); + error->all(FLERR, "Fix evaporate molecule requires atom attribute molecule"); } /* ---------------------------------------------------------------------- @@ -164,8 +159,8 @@ void FixEvaporate::init() void FixEvaporate::pre_exchange() { - int i,j,m,iwhichglobal,iwhichlocal; - int ndel,ndeltopo[4]; + int i, j, m, iwhichglobal, iwhichlocal; + int ndel, ndeltopo[4]; if (update->ntimestep != next_reneighbor) return; @@ -175,8 +170,8 @@ void FixEvaporate::pre_exchange() memory->destroy(list); memory->destroy(mark); nmax = atom->nmax; - memory->create(list,nmax,"evaporate:list"); - memory->create(mark,nmax,"evaporate:mark"); + memory->create(list, nmax, "evaporate:list"); + memory->create(mark, nmax, "evaporate:mark"); } // ncount = # of deletable atoms in region that I own @@ -184,7 +179,6 @@ void FixEvaporate::pre_exchange() // nbefore = # on procs before me // list[ncount] = list of local indices of atoms I can delete - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -195,11 +189,11 @@ void FixEvaporate::pre_exchange() int ncount = 0; for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) - if (region->match(x[i][0],x[i][1],x[i][2])) list[ncount++] = i; + if (region->match(x[i][0], x[i][1], x[i][2])) list[ncount++] = i; - int nall,nbefore; - MPI_Allreduce(&ncount,&nall,1,MPI_INT,MPI_SUM,world); - MPI_Scan(&ncount,&nbefore,1,MPI_INT,MPI_SUM,world); + int nall, nbefore; + MPI_Allreduce(&ncount, &nall, 1, MPI_INT, MPI_SUM, world); + MPI_Scan(&ncount, &nbefore, 1, MPI_INT, MPI_SUM, world); nbefore -= ncount; // ndel = total # of atom deletions, in or out of region @@ -216,27 +210,28 @@ void FixEvaporate::pre_exchange() if (molflag == 0) { while (nall && ndel < nflux) { - iwhichglobal = static_cast (nall*random->uniform()); - if (iwhichglobal < nbefore) nbefore--; + iwhichglobal = static_cast(nall * random->uniform()); + if (iwhichglobal < nbefore) + nbefore--; else if (iwhichglobal < nbefore + ncount) { iwhichlocal = iwhichglobal - nbefore; mark[list[iwhichlocal]] = 1; - list[iwhichlocal] = list[ncount-1]; + list[iwhichlocal] = list[ncount - 1]; ncount--; } ndel++; nall--; } - // molecule deletions - // choose one atom in one molecule randomly across all procs - // bcast mol ID and delete all atoms in that molecule on any proc - // update deletion count by total # of atoms in molecule - // shrink list of eligible candidates as any of my atoms get marked - // keep ndel,ndeltopo,ncount,nall,nbefore current after each mol deletion + // molecule deletions + // choose one atom in one molecule randomly across all procs + // bcast mol ID and delete all atoms in that molecule on any proc + // update deletion count by total # of atoms in molecule + // shrink list of eligible candidates as any of my atoms get marked + // keep ndel,ndeltopo,ncount,nall,nbefore current after each mol deletion } else { - int me,proc,iatom,ndelone,ndelall,index; + int me, proc, iatom, ndelone, ndelall, index; tagint imolecule; tagint *molecule = atom->molecule; int *molindex = atom->molindex; @@ -250,13 +245,14 @@ void FixEvaporate::pre_exchange() // pick an iatom,imolecule on proc me to delete - iwhichglobal = static_cast (nall*random->uniform()); + iwhichglobal = static_cast(nall * random->uniform()); if (iwhichglobal >= nbefore && iwhichglobal < nbefore + ncount) { iwhichlocal = iwhichglobal - nbefore; iatom = list[iwhichlocal]; imolecule = molecule[iatom]; me = comm->me; - } else me = -1; + } else + me = -1; // bcast mol ID to delete all atoms from // if mol ID > 0, delete any atom in molecule and decrement counters @@ -265,8 +261,8 @@ void FixEvaporate::pre_exchange() // for atom->molecular = Atom::MOLECULAR, do this for each deleted atom in molecule // for atom->molecular = Atom::TEMPLATE, use Molecule counts for just 1st atom in mol - MPI_Allreduce(&me,&proc,1,MPI_INT,MPI_MAX,world); - MPI_Bcast(&imolecule,1,MPI_LMP_TAGINT,proc,world); + MPI_Allreduce(&me, &proc, 1, MPI_INT, MPI_MAX, world); + MPI_Bcast(&imolecule, 1, MPI_LMP_TAGINT, proc, world); ndelone = 0; for (i = 0; i < nlocal; i++) { if (imolecule && molecule[i] == imolecule) { @@ -275,7 +271,8 @@ void FixEvaporate::pre_exchange() if (molecular == Atom::MOLECULAR) { if (atom->avec->bonds_allow) { - if (force->newton_bond) ndeltopo[0] += atom->num_bond[i]; + if (force->newton_bond) + ndeltopo[0] += atom->num_bond[i]; else { for (j = 0; j < atom->num_bond[i]; j++) { if (tag[i] < atom->bond_atom[i][j]) ndeltopo[0]++; @@ -283,7 +280,8 @@ void FixEvaporate::pre_exchange() } } if (atom->avec->angles_allow) { - if (force->newton_bond) ndeltopo[1] += atom->num_angle[i]; + if (force->newton_bond) + ndeltopo[1] += atom->num_angle[i]; else { for (j = 0; j < atom->num_angle[i]; j++) { m = atom->map(atom->angle_atom2[i][j]); @@ -292,7 +290,8 @@ void FixEvaporate::pre_exchange() } } if (atom->avec->dihedrals_allow) { - if (force->newton_bond) ndeltopo[2] += atom->num_dihedral[i]; + if (force->newton_bond) + ndeltopo[2] += atom->num_dihedral[i]; else { for (j = 0; j < atom->num_dihedral[i]; j++) { m = atom->map(atom->dihedral_atom2[i][j]); @@ -301,7 +300,8 @@ void FixEvaporate::pre_exchange() } } if (atom->avec->impropers_allow) { - if (force->newton_bond) ndeltopo[3] += atom->num_improper[i]; + if (force->newton_bond) + ndeltopo[3] += atom->num_improper[i]; else { for (j = 0; j < atom->num_improper[i]; j++) { m = atom->map(atom->improper_atom2[i][j]); @@ -331,19 +331,20 @@ void FixEvaporate::pre_exchange() i = 0; while (i < ncount) { if (mark[list[i]]) { - list[i] = list[ncount-1]; + list[i] = list[ncount - 1]; ncount--; - } else i++; + } else + i++; } // update ndel,ncount,nall,nbefore // ndelall is total atoms deleted on this iteration // ncount is already correct, so resum to get nall and nbefore - MPI_Allreduce(&ndelone,&ndelall,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&ndelone, &ndelall, 1, MPI_INT, MPI_SUM, world); ndel += ndelall; - MPI_Allreduce(&ncount,&nall,1,MPI_INT,MPI_SUM,world); - MPI_Scan(&ncount,&nbefore,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&ncount, &nall, 1, MPI_INT, MPI_SUM, world); + MPI_Scan(&ncount, &nbefore, 1, MPI_INT, MPI_SUM, world); nbefore -= ncount; } } @@ -353,9 +354,9 @@ void FixEvaporate::pre_exchange() AtomVec *avec = atom->avec; - for (i = nlocal-1; i >= 0; i--) { + for (i = nlocal - 1; i >= 0; i--) { if (mark[i]) { - avec->copy(atom->nlocal-1,i,1); + avec->copy(atom->nlocal - 1, i, 1); atom->nlocal--; } } @@ -367,7 +368,7 @@ void FixEvaporate::pre_exchange() atom->natoms -= ndel; if (molflag) { int all[4]; - MPI_Allreduce(ndeltopo,all,4,MPI_INT,MPI_SUM,world); + MPI_Allreduce(ndeltopo, all, 4, MPI_INT, MPI_SUM, world); atom->nbonds -= all[0]; atom->nangles -= all[1]; atom->ndihedrals -= all[2]; @@ -392,7 +393,7 @@ void FixEvaporate::pre_exchange() double FixEvaporate::compute_scalar() { - return 1.0*ndeleted; + return 1.0 * ndeleted; } /* ---------------------------------------------------------------------- @@ -401,6 +402,6 @@ double FixEvaporate::compute_scalar() double FixEvaporate::memory_usage() { - double bytes = 2*nmax * sizeof(int); + double bytes = 2 * nmax * sizeof(int); return bytes; } diff --git a/src/fix_evaporate.h b/src/fix_evaporate.h index e350c91608..78ad6483b9 100644 --- a/src/fix_evaporate.h +++ b/src/fix_evaporate.h @@ -35,10 +35,11 @@ class FixEvaporate : public Fix { double memory_usage() override; private: - int nevery, nflux, iregion; + int nevery, nflux; int molflag; int ndeleted; char *idregion; + class Region *region; int nmax; int *list, *mark; diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 1291721f0a..163f46b781 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -34,8 +33,8 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ -FixGroup::FixGroup(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -idregion(nullptr), idvar(nullptr), idprop(nullptr) +FixGroup::FixGroup(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), idregion(nullptr), idvar(nullptr), idprop(nullptr), region(nullptr) { // dgroupbit = bitmask of dynamic group // group ID is last part of fix ID @@ -53,42 +52,44 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) int iarg = 3; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); - if (domain->find_region(arg[iarg+1]) < 0) - error->all(FLERR,"Region ID for group dynamic does not exist"); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal group command"); + if (!domain->get_region_by_id(arg[iarg + 1])) + error->all(FLERR, "Region {} for group dynamic does not exist", arg[iarg + 1]); regionflag = 1; - delete [] idregion; - idregion = utils::strdup(arg[iarg+1]); + delete[] idregion; + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"var") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); - if (input->variable->find(arg[iarg+1]) < 0) - error->all(FLERR,"Variable name for group dynamic does not exist"); + } else if (strcmp(arg[iarg], "var") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal group command"); + if (input->variable->find(arg[iarg + 1]) < 0) + error->all(FLERR, "Variable name for group dynamic does not exist"); varflag = 1; - delete [] idvar; - idvar = utils::strdup(arg[iarg+1]); + delete[] idvar; + idvar = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"property") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); - int flag,cols; - iprop = atom->find_custom(arg[iarg+1],flag,cols); + } else if (strcmp(arg[iarg], "property") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal group command"); + int flag, cols; + iprop = atom->find_custom(arg[iarg + 1], flag, cols); if (iprop < 0 || cols) - error->all(FLERR,"Custom per-atom vector for group dynamic " + error->all(FLERR, + "Custom per-atom vector for group dynamic " "does not exist"); propflag = 1; - delete [] idprop; - idprop = utils::strdup(arg[iarg+1]); + delete[] idprop; + idprop = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"every") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); - nevery = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal group command"); + } else if (strcmp(arg[iarg], "every") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal group command"); + nevery = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + if (nevery <= 0) error->all(FLERR, "Illegal group command"); iarg += 2; - } else error->all(FLERR,"Illegal group command"); + } else + error->all(FLERR, "Illegal group command"); } } @@ -96,9 +97,9 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) FixGroup::~FixGroup() { - delete [] idregion; - delete [] idvar; - delete [] idprop; + delete[] idregion; + delete[] idvar; + delete[] idprop; } /* ---------------------------------------------------------------------- */ @@ -118,34 +119,30 @@ void FixGroup::init() // parent group cannot be dynamic // else order of FixGroup fixes would matter - if (group->dynamic[igroup]) - error->all(FLERR,"Group dynamic parent group cannot be dynamic"); + if (group->dynamic[igroup]) error->all(FLERR, "Group dynamic parent group cannot be dynamic"); - if (utils::strmatch(update->integrate_style,"^respa")) - nlevels_respa = (dynamic_cast( update->integrate))->nlevels; + if (utils::strmatch(update->integrate_style, "^respa")) + nlevels_respa = (dynamic_cast(update->integrate))->nlevels; // set current indices for region and variable and custom property if (regionflag) { - iregion = domain->find_region(idregion); - if (iregion < 0) - error->all(FLERR,"Region ID for group dynamic does not exist"); - region = domain->regions[iregion]; + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for group dynamic does not exist", idregion); } if (varflag) { ivar = input->variable->find(idvar); - if (ivar < 0) - error->all(FLERR,"Variable name for group dynamic does not exist"); + if (ivar < 0) error->all(FLERR, "Variable name for group dynamic does not exist"); if (!input->variable->atomstyle(ivar)) - error->all(FLERR,"Variable for group dynamic is invalid style"); + error->all(FLERR, "Variable for group dynamic is invalid style"); } if (propflag) { int cols; - iprop = atom->find_custom(idprop,proptype,cols); + iprop = atom->find_custom(idprop, proptype, cols); if (iprop < 0 || cols) - error->all(FLERR,"Group dynamic command custom property vector does not exist"); + error->all(FLERR, "Group dynamic command custom property vector does not exist"); } // warn if any FixGroup is not at tail end of all post_integrate fixes @@ -155,20 +152,22 @@ void FixGroup::init() int nfix = modify->nfix; int n = 0; - for (int i = 0; i < nfix; i++) if (POST_INTEGRATE & fmask[i]) n++; + for (int i = 0; i < nfix; i++) + if (POST_INTEGRATE & fmask[i]) n++; int warn = 0; for (int i = 0; i < nfix; i++) { if (POST_INTEGRATE & fmask[i]) { - for (int j = i+1; j < nfix; j++) { + for (int j = i + 1; j < nfix; j++) { if (POST_INTEGRATE & fmask[j]) { - if (strstr(fix[j]->id,"GROUP_") != fix[j]->id) warn = 1; + if (strstr(fix[j]->id, "GROUP_") != fix[j]->id) warn = 1; } } } } if (warn && comm->me == 0) - error->warning(FLERR,"One or more dynamic groups may not be " + error->warning(FLERR, + "One or more dynamic groups may not be " "updated at correct point in timestep"); } @@ -194,7 +193,7 @@ void FixGroup::post_integrate() void FixGroup::post_integrate_respa(int ilevel, int /*iloop*/) { - if (ilevel == nlevels_respa-1) post_integrate(); + if (ilevel == nlevels_respa - 1) post_integrate(); } /* ---------------------------------------------------------------------- */ @@ -216,8 +215,8 @@ void FixGroup::set_group() if (varflag) { update->post_integrate = 1; modify->clearstep_compute(); - memory->create(var,nlocal,"fix/group:varvalue"); - input->variable->compute_atom(ivar,igroup,var,1,0); + memory->create(var, nlocal, "fix/group:varvalue"); + input->variable->compute_atom(ivar, igroup, var, 1, 0); modify->addstep_compute(update->ntimestep + nevery); update->post_integrate = 0; } @@ -243,16 +242,19 @@ void FixGroup::set_group() for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { inflag = 1; - if (regionflag && !region->match(x[i][0],x[i][1],x[i][2])) inflag = 0; + if (regionflag && !region->match(x[i][0], x[i][1], x[i][2])) inflag = 0; if (varflag && var[i] == 0.0) inflag = 0; if (propflag) { if (!proptype && ivector[i] == 0) inflag = 0; if (proptype && dvector[i] == 0.0) inflag = 0; } - } else inflag = 0; + } else + inflag = 0; - if (inflag) mask[i] |= gbit; - else mask[i] &= gbitinverse; + if (inflag) + mask[i] |= gbit; + else + mask[i] &= gbitinverse; } if (varflag) memory->destroy(var); @@ -260,10 +262,10 @@ void FixGroup::set_group() /* ---------------------------------------------------------------------- */ -void *FixGroup::extract(const char *str, int &/*unused*/) +void *FixGroup::extract(const char *str, int & /*unused*/) { - if (strcmp(str,"property") == 0 && propflag) return (void *) idprop; - if (strcmp(str,"variable") == 0 && varflag) return (void *) idvar; - if (strcmp(str,"region") == 0 && regionflag) return (void *) idregion; + if (strcmp(str, "property") == 0 && propflag) return (void *) idprop; + if (strcmp(str, "variable") == 0 && varflag) return (void *) idvar; + if (strcmp(str, "region") == 0 && regionflag) return (void *) idregion; return nullptr; } diff --git a/src/fix_group.h b/src/fix_group.h index ffa2afcfc3..fb9d361b4e 100644 --- a/src/fix_group.h +++ b/src/fix_group.h @@ -38,7 +38,7 @@ class FixGroup : public Fix { private: int gbit, gbitinverse; int regionflag, varflag, propflag, proptype; - int iregion, ivar, iprop; + int ivar, iprop; char *idregion, *idvar, *idprop; class Region *region; diff --git a/src/fix_heat.cpp b/src/fix_heat.cpp index 6ceaf9c71e..db77dd7bdc 100644 --- a/src/fix_heat.cpp +++ b/src/fix_heat.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -36,45 +35,44 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{CONSTANT,EQUAL,ATOM}; +enum { CONSTANT, EQUAL, ATOM }; /* ---------------------------------------------------------------------- */ -FixHeat::FixHeat(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -idregion(nullptr), hstr(nullptr), vheat(nullptr), vscale(nullptr) +FixHeat::FixHeat(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), idregion(nullptr), region(nullptr), hstr(nullptr), vheat(nullptr), + vscale(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal fix heat command"); + if (narg < 4) error->all(FLERR, "Illegal fix heat command"); scalar_flag = 1; global_freq = 1; extscalar = 0; - nevery = utils::inumeric(FLERR,arg[3],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix heat command"); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); + if (nevery <= 0) error->all(FLERR, "Illegal fix heat command"); hstr = nullptr; - if (utils::strmatch(arg[4],"^v_")) { - hstr = utils::strdup(arg[4]+2); + if (utils::strmatch(arg[4], "^v_")) { + hstr = utils::strdup(arg[4] + 2); } else { - heat_input = utils::numeric(FLERR,arg[4],false,lmp); + heat_input = utils::numeric(FLERR, arg[4], false, lmp); hstyle = CONSTANT; } // optional args - iregion = -1; - int iarg = 5; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix heat command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix heat does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix heat command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix heat does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else error->all(FLERR,"Illegal fix heat command"); + } else + error->all(FLERR, "Illegal fix heat command"); } scale = 1.0; @@ -86,8 +84,8 @@ idregion(nullptr), hstr(nullptr), vheat(nullptr), vscale(nullptr) FixHeat::~FixHeat() { - delete [] hstr; - delete [] idregion; + delete[] hstr; + delete[] idregion; memory->destroy(vheat); memory->destroy(vscale); } @@ -107,34 +105,33 @@ void FixHeat::init() { // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix heat does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix heat does not exist", idregion); } // check variable if (hstr) { hvar = input->variable->find(hstr); - if (hvar < 0) - error->all(FLERR,"Variable name for fix heat does not exist"); - if (input->variable->equalstyle(hvar)) hstyle = EQUAL; - else if (input->variable->atomstyle(hvar)) hstyle = ATOM; - else error->all(FLERR,"Variable for fix heat is invalid style"); + if (hvar < 0) error->all(FLERR, "Variable name for fix heat does not exist"); + if (input->variable->equalstyle(hvar)) + hstyle = EQUAL; + else if (input->variable->atomstyle(hvar)) + hstyle = ATOM; + else + error->all(FLERR, "Variable for fix heat is invalid style"); } // check for rigid bodies in region (done here for performance reasons) - if (iregion >= 0 && modify->check_rigid_region_overlap(groupbit,domain->regions[iregion])) - error->warning(FLERR,"Cannot apply fix heat to atoms in rigid bodies"); + if (region && modify->check_rigid_region_overlap(groupbit, region)) + error->warning(FLERR, "Cannot apply fix heat to atoms in rigid bodies"); // cannot have 0 atoms in group - if (group->count(igroup) == 0) - error->all(FLERR,"Fix heat group has no atoms"); + if (group->count(igroup) == 0) error->all(FLERR, "Fix heat group has no atoms"); masstotal = group->mass(igroup); - if (masstotal <= 0.0) - error->all(FLERR,"Fix heat group has invalid mass"); + if (masstotal <= 0.0) error->all(FLERR, "Fix heat group has invalid mass"); } /* ---------------------------------------------------------------------- */ @@ -142,8 +139,8 @@ void FixHeat::init() void FixHeat::end_of_step() { int i; - double heat,ke,massone; - double vsub[3],vcm[3]; + double heat, ke, massone; + double vsub[3], vcm[3]; double **x = atom->x; double **v = atom->v; @@ -159,91 +156,88 @@ void FixHeat::end_of_step() maxatom = atom->nmax; memory->destroy(vheat); memory->destroy(vscale); - memory->create(vheat,maxatom,"heat:vheat"); - memory->create(vscale,maxatom,"heat:vscale"); + memory->create(vheat, maxatom, "heat:vheat"); + memory->create(vscale, maxatom, "heat:vscale"); } // evaluate variable if (hstyle != CONSTANT) { modify->clearstep_compute(); - if (hstyle == EQUAL) heat_input = input->variable->compute_equal(hvar); - else input->variable->compute_atom(hvar,igroup,vheat,1,0); + if (hstyle == EQUAL) + heat_input = input->variable->compute_equal(hvar); + else + input->variable->compute_atom(hvar, igroup, vheat, 1, 0); modify->addstep_compute(update->ntimestep + nevery); } // vcm = center-of-mass velocity of scaled atoms - if (iregion < 0) { - ke = group->ke(igroup)*force->ftm2v; - group->vcm(igroup,masstotal,vcm); + if (region) { + masstotal = group->mass(igroup, region); + if (masstotal == 0.0) error->all(FLERR, "Fix heat group has no atoms"); + ke = group->ke(igroup, region) * force->ftm2v; + group->vcm(igroup, masstotal, vcm, region); } else { - masstotal = group->mass(igroup,iregion); - if (masstotal == 0.0) error->all(FLERR,"Fix heat group has no atoms"); - ke = group->ke(igroup,iregion)*force->ftm2v; - group->vcm(igroup,masstotal,vcm,iregion); + ke = group->ke(igroup) * force->ftm2v; + group->vcm(igroup, masstotal, vcm); } - double vcmsq = vcm[0]*vcm[0] + vcm[1]*vcm[1] + vcm[2]*vcm[2]; + double vcmsq = vcm[0] * vcm[0] + vcm[1] * vcm[1] + vcm[2] * vcm[2]; // add heat via scale factor on velocities for CONSTANT and EQUAL cases // scale = velocity scale factor to accomplish eflux change in energy // vsub = velocity subtracted from each atom to preserve momentum // overall KE cannot go negative - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); if (hstyle != ATOM) { - heat = heat_input*nevery*update->dt*force->ftm2v; - double escale = - (ke + heat - 0.5*vcmsq*masstotal)/(ke - 0.5*vcmsq*masstotal); - if (escale < 0.0) error->all(FLERR,"Fix heat kinetic energy went negative"); + heat = heat_input * nevery * update->dt * force->ftm2v; + double escale = (ke + heat - 0.5 * vcmsq * masstotal) / (ke - 0.5 * vcmsq * masstotal); + if (escale < 0.0) error->all(FLERR, "Fix heat kinetic energy went negative"); scale = sqrt(escale); - vsub[0] = (scale-1.0) * vcm[0]; - vsub[1] = (scale-1.0) * vcm[1]; - vsub[2] = (scale-1.0) * vcm[2]; + vsub[0] = (scale - 1.0) * vcm[0]; + vsub[1] = (scale - 1.0) * vcm[1]; + vsub[2] = (scale - 1.0) * vcm[2]; - if (iregion < 0) { + if (region) { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) { - v[i][0] = scale*v[i][0] - vsub[0]; - v[i][1] = scale*v[i][1] - vsub[1]; - v[i][2] = scale*v[i][2] - vsub[2]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + v[i][0] = scale * v[i][0] - vsub[0]; + v[i][1] = scale * v[i][1] - vsub[1]; + v[i][2] = scale * v[i][2] - vsub[2]; } } else { for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - v[i][0] = scale*v[i][0] - vsub[0]; - v[i][1] = scale*v[i][1] - vsub[1]; - v[i][2] = scale*v[i][2] - vsub[2]; + if (mask[i] & groupbit) { + v[i][0] = scale * v[i][0] - vsub[0]; + v[i][1] = scale * v[i][1] - vsub[1]; + v[i][2] = scale * v[i][2] - vsub[2]; } } - // add heat via per-atom scale factor on velocities for ATOM case - // vscale = velocity scale factor to accomplish eflux change in energy - // vsub = velocity subtracted from each atom to preserve momentum - // KE of an atom cannot go negative + // add heat via per-atom scale factor on velocities for ATOM case + // vscale = velocity scale factor to accomplish eflux change in energy + // vsub = velocity subtracted from each atom to preserve momentum + // KE of an atom cannot go negative } else { vsub[0] = vsub[1] = vsub[2] = 0.0; - if (iregion < 0) { + if (region) { for (i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) { - heat = vheat[i]*nevery*update->dt*force->ftm2v; - vscale[i] = - (ke + heat - 0.5*vcmsq*masstotal)/(ke - 0.5*vcmsq*masstotal); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + heat = vheat[i] * nevery * update->dt * force->ftm2v; + vscale[i] = (ke + heat - 0.5 * vcmsq * masstotal) / (ke - 0.5 * vcmsq * masstotal); if (vscale[i] < 0.0) - error->all(FLERR, - "Fix heat kinetic energy of an atom went negative"); + error->all(FLERR, "Fix heat kinetic energy of an atom went negative"); scale = sqrt(vscale[i]); - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - vsub[0] += (scale-1.0) * v[i][0]*massone; - vsub[1] += (scale-1.0) * v[i][1]*massone; - vsub[2] += (scale-1.0) * v[i][2]*massone; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + vsub[0] += (scale - 1.0) * v[i][0] * massone; + vsub[1] += (scale - 1.0) * v[i][1] * massone; + vsub[2] += (scale - 1.0) * v[i][2] * massone; } } @@ -252,28 +246,27 @@ void FixHeat::end_of_step() vsub[2] /= masstotal; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { scale = sqrt(vscale[i]); - v[i][0] = scale*v[i][0] - vsub[0]; - v[i][1] = scale*v[i][1] - vsub[1]; - v[i][2] = scale*v[i][2] - vsub[2]; + v[i][0] = scale * v[i][0] - vsub[0]; + v[i][1] = scale * v[i][1] - vsub[1]; + v[i][2] = scale * v[i][2] - vsub[2]; } - } else { for (i = 0; i < nlocal; i++) { - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - heat = vheat[i]*nevery*update->dt*force->ftm2v; - vscale[i] = - (ke + heat - 0.5*vcmsq*masstotal)/(ke - 0.5*vcmsq*masstotal); + if (mask[i] & groupbit) { + heat = vheat[i] * nevery * update->dt * force->ftm2v; + vscale[i] = (ke + heat - 0.5 * vcmsq * masstotal) / (ke - 0.5 * vcmsq * masstotal); if (vscale[i] < 0.0) - error->all(FLERR, - "Fix heat kinetic energy of an atom went negative"); + error->all(FLERR, "Fix heat kinetic energy of an atom went negative"); scale = sqrt(vscale[i]); - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - vsub[0] += (scale-1.0) * v[i][0]*massone; - vsub[1] += (scale-1.0) * v[i][1]*massone; - vsub[2] += (scale-1.0) * v[i][2]*massone; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + vsub[0] += (scale - 1.0) * v[i][0] * massone; + vsub[1] += (scale - 1.0) * v[i][1] * massone; + vsub[2] += (scale - 1.0) * v[i][2] * massone; } } @@ -282,11 +275,11 @@ void FixHeat::end_of_step() vsub[2] /= masstotal; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit) { scale = sqrt(vscale[i]); - v[i][0] = scale*v[i][0] - vsub[0]; - v[i][1] = scale*v[i][1] - vsub[1]; - v[i][2] = scale*v[i][2] - vsub[2]; + v[i][0] = scale * v[i][0] - vsub[0]; + v[i][1] = scale * v[i][1] - vsub[1]; + v[i][2] = scale * v[i][2] - vsub[2]; } } } @@ -304,18 +297,17 @@ double FixHeat::compute_scalar() int *mask = atom->mask; double **x = atom->x; int nlocal = atom->nlocal; - if (iregion < 0) { + if (region) { + region->prematch(); for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { scale_sum += sqrt(vscale[i]); ncount++; } } } else { - Region *region = domain->regions[iregion]; - region->prematch(); for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit) { scale_sum += sqrt(vscale[i]); ncount++; } @@ -323,10 +315,12 @@ double FixHeat::compute_scalar() } double scale_sum_all = 0.0; int ncount_all = 0; - MPI_Allreduce(&scale_sum,&scale_sum_all,1,MPI_DOUBLE,MPI_SUM,world); - MPI_Allreduce(&ncount,&ncount_all,1,MPI_INT,MPI_SUM,world); - if (ncount_all == 0) average_scale = 0.0; - else average_scale = scale_sum_all/static_cast(ncount_all); + MPI_Allreduce(&scale_sum, &scale_sum_all, 1, MPI_DOUBLE, MPI_SUM, world); + MPI_Allreduce(&ncount, &ncount_all, 1, MPI_INT, MPI_SUM, world); + if (ncount_all == 0) + average_scale = 0.0; + else + average_scale = scale_sum_all / static_cast(ncount_all); } return average_scale; } @@ -338,6 +332,6 @@ double FixHeat::compute_scalar() double FixHeat::memory_usage() { double bytes = 0.0; - if (hstyle == ATOM) bytes = atom->nmax*2 * sizeof(double); + if (hstyle == ATOM) bytes = atom->nmax * 2 * sizeof(double); return bytes; } diff --git a/src/fix_heat.h b/src/fix_heat.h index 5d1d9a5dfd..c1aee30014 100644 --- a/src/fix_heat.h +++ b/src/fix_heat.h @@ -35,11 +35,11 @@ class FixHeat : public Fix { double memory_usage() override; private: - int iregion; double heat_input; double masstotal; double scale; char *idregion; + class Region *region; char *hstr; int hstyle, hvar; diff --git a/src/fix_move.cpp b/src/fix_move.cpp index 75f2eb1796..37e8647671 100644 --- a/src/fix_move.cpp +++ b/src/fix_move.cpp @@ -295,10 +295,10 @@ FixMove::FixMove(LAMMPS *lmp, int narg, char **arg) : // AtomVec pointers to retrieve per-atom storage of extra quantities - avec_ellipsoid = dynamic_cast( atom->style_match("ellipsoid")); - avec_line = dynamic_cast( atom->style_match("line")); - avec_tri = dynamic_cast( atom->style_match("tri")); - avec_body = dynamic_cast( atom->style_match("body")); + avec_ellipsoid = dynamic_cast(atom->style_match("ellipsoid")); + avec_line = dynamic_cast(atom->style_match("line")); + avec_tri = dynamic_cast(atom->style_match("tri")); + avec_body = dynamic_cast(atom->style_match("body")); // xoriginal = initial unwrapped positions of atoms // toriginal = initial theta of lines @@ -495,7 +495,7 @@ void FixMove::init() velocity = nullptr; if (utils::strmatch(update->integrate_style, "^respa")) - nlevels_respa = (dynamic_cast( update->integrate))->nlevels; + nlevels_respa = (dynamic_cast(update->integrate))->nlevels; } /* ---------------------------------------------------------------------- diff --git a/src/fix_setforce.cpp b/src/fix_setforce.cpp index a6e796f072..6a88e3ab17 100644 --- a/src/fix_setforce.cpp +++ b/src/fix_setforce.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -30,15 +29,15 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE,CONSTANT,EQUAL,ATOM}; +enum { NONE, CONSTANT, EQUAL, ATOM }; /* ---------------------------------------------------------------------- */ FixSetForce::FixSetForce(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr), sforce(nullptr) + Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr), + region(nullptr), sforce(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal fix setforce command"); + if (narg < 6) error->all(FLERR, "Illegal fix setforce command"); dynamic_group_allow = 1; vector_flag = 1; @@ -47,55 +46,51 @@ FixSetForce::FixSetForce(LAMMPS *lmp, int narg, char **arg) : extvector = 1; respa_level_support = 1; ilevel_respa = nlevels_respa = 0; - xstr = ystr = zstr = nullptr; - if (utils::strmatch(arg[3],"^v_")) { - xstr = utils::strdup(arg[3]+2); - } else if (strcmp(arg[3],"NULL") == 0) { + if (utils::strmatch(arg[3], "^v_")) { + xstr = utils::strdup(arg[3] + 2); + } else if (strcmp(arg[3], "NULL") == 0) { xstyle = NONE; } else { - xvalue = utils::numeric(FLERR,arg[3],false,lmp); + xvalue = utils::numeric(FLERR, arg[3], false, lmp); xstyle = CONSTANT; } - if (utils::strmatch(arg[4],"^v_")) { - ystr = utils::strdup(arg[4]+2); - } else if (strcmp(arg[4],"NULL") == 0) { + if (utils::strmatch(arg[4], "^v_")) { + ystr = utils::strdup(arg[4] + 2); + } else if (strcmp(arg[4], "NULL") == 0) { ystyle = NONE; } else { - yvalue = utils::numeric(FLERR,arg[4],false,lmp); + yvalue = utils::numeric(FLERR, arg[4], false, lmp); ystyle = CONSTANT; } - if (utils::strmatch(arg[5],"^v_")) { - zstr = utils::strdup(arg[5]+2); - } else if (strcmp(arg[5],"NULL") == 0) { + if (utils::strmatch(arg[5], "^v_")) { + zstr = utils::strdup(arg[5] + 2); + } else if (strcmp(arg[5], "NULL") == 0) { zstyle = NONE; } else { - zvalue = utils::numeric(FLERR,arg[5],false,lmp); + zvalue = utils::numeric(FLERR, arg[5], false, lmp); zstyle = CONSTANT; } // optional args - iregion = -1; - idregion = nullptr; - int iarg = 6; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix setforce command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix setforce does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix setforce command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else error->all(FLERR,"Illegal fix setforce command"); + } else + error->all(FLERR, "Illegal fix setforce command"); } force_flag = 0; foriginal[0] = foriginal[1] = foriginal[2] = 0.0; maxatom = 1; - memory->create(sforce,maxatom,3,"setforce:sforce"); + memory->create(sforce, maxatom, 3, "setforce:sforce"); } /* ---------------------------------------------------------------------- */ @@ -104,10 +99,10 @@ FixSetForce::~FixSetForce() { if (copymode) return; - delete [] xstr; - delete [] ystr; - delete [] zstr; - delete [] idregion; + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] idregion; memory->destroy(sforce); } @@ -130,47 +125,55 @@ void FixSetForce::init() if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR,"Variable name for fix setforce does not exist"); - if (input->variable->equalstyle(xvar)) xstyle = EQUAL; - else if (input->variable->atomstyle(xvar)) xstyle = ATOM; - else error->all(FLERR,"Variable for fix setforce is invalid style"); + if (xvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", xstr); + if (input->variable->equalstyle(xvar)) + xstyle = EQUAL; + else if (input->variable->atomstyle(xvar)) + xstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix setforce is invalid style", xstr); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR,"Variable name for fix setforce does not exist"); - if (input->variable->equalstyle(yvar)) ystyle = EQUAL; - else if (input->variable->atomstyle(yvar)) ystyle = ATOM; - else error->all(FLERR,"Variable for fix setforce is invalid style"); + if (yvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", ystr); + if (input->variable->equalstyle(yvar)) + ystyle = EQUAL; + else if (input->variable->atomstyle(yvar)) + ystyle = ATOM; + else + error->all(FLERR, "Variable {} for fix setforce is invalid style", ystr); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR,"Variable name for fix setforce does not exist"); - if (input->variable->equalstyle(zvar)) zstyle = EQUAL; - else if (input->variable->atomstyle(zvar)) zstyle = ATOM; - else error->all(FLERR,"Variable for fix setforce is invalid style"); + if (zvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", zstr); + if (input->variable->equalstyle(zvar)) + zstyle = EQUAL; + else if (input->variable->atomstyle(zvar)) + zstyle = ATOM; + else + error->all(FLERR, "Variable {} for fix setforce is invalid style", zstr); } // set index and check validity of region - if (iregion >= 0) { - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix setforce does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", idregion); } if (xstyle == ATOM || ystyle == ATOM || zstyle == ATOM) varflag = ATOM; else if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) varflag = EQUAL; - else varflag = CONSTANT; + else + varflag = CONSTANT; - if (utils::strmatch(update->integrate_style,"^respa")) { - nlevels_respa = (dynamic_cast( update->integrate))->nlevels; - if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1); - else ilevel_respa = nlevels_respa-1; + if (utils::strmatch(update->integrate_style, "^respa")) { + nlevels_respa = (dynamic_cast(update->integrate))->nlevels; + if (respa_level >= 0) + ilevel_respa = MIN(respa_level, nlevels_respa - 1); + else + ilevel_respa = nlevels_respa - 1; } // cannot use non-zero forces for a minimization since no energy is integrated @@ -185,21 +188,20 @@ void FixSetForce::init() if (ystyle == CONSTANT && yvalue != 0.0) flag = 1; if (zstyle == CONSTANT && zvalue != 0.0) flag = 1; } - if (flag) - error->all(FLERR,"Cannot use non-zero forces in an energy minimization"); + if (flag) error->all(FLERR, "Cannot use non-zero forces in an energy minimization"); } /* ---------------------------------------------------------------------- */ void FixSetForce::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) + if (utils::strmatch(update->integrate_style, "^verlet")) post_force(vflag); else for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel); - post_force_respa(vflag,ilevel,0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel); + (dynamic_cast(update->integrate))->copy_flevel_f(ilevel); + post_force_respa(vflag, ilevel, 0); + (dynamic_cast(update->integrate))->copy_f_flevel(ilevel); } } @@ -221,18 +223,14 @@ void FixSetForce::post_force(int /*vflag*/) // update region if necessary - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // reallocate sforce array if necessary if (varflag == ATOM && atom->nmax > maxatom) { maxatom = atom->nmax; memory->destroy(sforce); - memory->create(sforce,maxatom,3,"setforce:sforce"); + memory->create(sforce, maxatom, 3, "setforce:sforce"); } foriginal[0] = foriginal[1] = foriginal[2] = 0.0; @@ -241,7 +239,7 @@ void FixSetForce::post_force(int /*vflag*/) if (varflag == CONSTANT) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += f[i][0]; foriginal[1] += f[i][1]; foriginal[2] += f[i][2]; @@ -250,36 +248,45 @@ void FixSetForce::post_force(int /*vflag*/) if (zstyle) f[i][2] = zvalue; } - // variable force, wrap with clear/add + // variable force, wrap with clear/add } else { modify->clearstep_compute(); - if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar); + if (xstyle == EQUAL) + xvalue = input->variable->compute_equal(xvar); else if (xstyle == ATOM) - input->variable->compute_atom(xvar,igroup,&sforce[0][0],3,0); - if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar); + input->variable->compute_atom(xvar, igroup, &sforce[0][0], 3, 0); + if (ystyle == EQUAL) + yvalue = input->variable->compute_equal(yvar); else if (ystyle == ATOM) - input->variable->compute_atom(yvar,igroup,&sforce[0][1],3,0); - if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar); + input->variable->compute_atom(yvar, igroup, &sforce[0][1], 3, 0); + if (zstyle == EQUAL) + zvalue = input->variable->compute_equal(zvar); else if (zstyle == ATOM) - input->variable->compute_atom(zvar,igroup,&sforce[0][2],3,0); + input->variable->compute_atom(zvar, igroup, &sforce[0][2], 3, 0); modify->addstep_compute(update->ntimestep + 1); for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal[0] += f[i][0]; foriginal[1] += f[i][1]; foriginal[2] += f[i][2]; - if (xstyle == ATOM) f[i][0] = sforce[i][0]; - else if (xstyle) f[i][0] = xvalue; - if (ystyle == ATOM) f[i][1] = sforce[i][1]; - else if (ystyle) f[i][1] = yvalue; - if (zstyle == ATOM) f[i][2] = sforce[i][2]; - else if (zstyle) f[i][2] = zvalue; + if (xstyle == ATOM) + f[i][0] = sforce[i][0]; + else if (xstyle) + f[i][0] = xvalue; + if (ystyle == ATOM) + f[i][1] = sforce[i][1]; + else if (ystyle) + f[i][1] = yvalue; + if (zstyle == ATOM) + f[i][2] = sforce[i][2]; + else if (zstyle) + f[i][2] = zvalue; } } } @@ -298,11 +305,7 @@ void FixSetForce::post_force_respa(int vflag, int ilevel, int /*iloop*/) foriginal[1] += foriginal_saved[1]; foriginal[2] += foriginal_saved[2]; } else { - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); double **x = atom->x; double **f = atom->f; @@ -311,7 +314,7 @@ void FixSetForce::post_force_respa(int vflag, int ilevel, int /*iloop*/) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue; + if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue; foriginal_saved[0] += f[i][0]; foriginal_saved[1] += f[i][1]; foriginal_saved[2] += f[i][2]; @@ -338,7 +341,7 @@ double FixSetForce::compute_vector(int n) // only sum across procs one time if (force_flag == 0) { - MPI_Allreduce(foriginal,foriginal_all,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(foriginal, foriginal_all, 3, MPI_DOUBLE, MPI_SUM, world); force_flag = 1; } return foriginal_all[n]; @@ -351,6 +354,6 @@ double FixSetForce::compute_vector(int n) double FixSetForce::memory_usage() { double bytes = 0.0; - if (varflag == ATOM) bytes = maxatom*3 * sizeof(double); + if (varflag == ATOM) bytes = maxatom * 3 * sizeof(double); return bytes; } diff --git a/src/fix_setforce.h b/src/fix_setforce.h index ea242ba954..cbdd45e14f 100644 --- a/src/fix_setforce.h +++ b/src/fix_setforce.h @@ -41,9 +41,10 @@ class FixSetForce : public Fix { protected: double xvalue, yvalue, zvalue; - int varflag, iregion; + int varflag; char *xstr, *ystr, *zstr; char *idregion; + class Region *region; int xvar, yvar, zvar, xstyle, ystyle, zstyle; double foriginal[3], foriginal_all[3], foriginal_saved[3]; int force_flag; diff --git a/src/fix_wall_region.cpp b/src/fix_wall_region.cpp index 8f5a27e4a5..41a96fe374 100644 --- a/src/fix_wall_region.cpp +++ b/src/fix_wall_region.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -18,6 +17,7 @@ #include "domain.h" #include "error.h" #include "math_const.h" +#include "math_special.h" #include "region.h" #include "respa.h" #include "update.h" @@ -27,17 +27,18 @@ using namespace LAMMPS_NS; using namespace FixConst; -using namespace MathConst; +using MathConst::MY_2PI; +using MathConst::MY_SQRT2; +using MathSpecial::powint; -enum{LJ93,LJ126,LJ1043,COLLOID,HARMONIC,MORSE}; +enum { LJ93, LJ126, LJ1043, COLLOID, HARMONIC, MORSE }; /* ---------------------------------------------------------------------- */ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - idregion(nullptr) + Fix(lmp, narg, arg), idregion(nullptr), region(nullptr) { - if (narg < 8) error->all(FLERR,"Illegal fix wall/region command"); + if (narg < 8) error->all(FLERR, "Illegal fix wall/region command"); scalar_flag = 1; vector_flag = 1; @@ -52,40 +53,44 @@ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) : // parse args - iregion = domain->find_region(arg[3]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix wall/region does not exist"); + region = domain->get_region_by_id(arg[3]); + if (!region) error->all(FLERR, "Region {} for fix wall/region does not exist", arg[3]); idregion = utils::strdup(arg[3]); - if (strcmp(arg[4],"lj93") == 0) style = LJ93; - else if (strcmp(arg[4],"lj126") == 0) style = LJ126; - else if (strcmp(arg[4],"lj1043") == 0) style = LJ1043; - else if (strcmp(arg[4],"colloid") == 0) style = COLLOID; - else if (strcmp(arg[4],"harmonic") == 0) style = HARMONIC; - else if (strcmp(arg[4],"morse") == 0) style = MORSE; - else error->all(FLERR,"Illegal fix wall/region command"); + if (strcmp(arg[4], "lj93") == 0) + style = LJ93; + else if (strcmp(arg[4], "lj126") == 0) + style = LJ126; + else if (strcmp(arg[4], "lj1043") == 0) + style = LJ1043; + else if (strcmp(arg[4], "colloid") == 0) + style = COLLOID; + else if (strcmp(arg[4], "harmonic") == 0) + style = HARMONIC; + else if (strcmp(arg[4], "morse") == 0) + style = MORSE; + else + error->all(FLERR, "Illegal fix wall/region command"); if (style != COLLOID) dynamic_group_allow = 1; if (style == MORSE) { - if (narg != 9) - error->all(FLERR,"Illegal fix wall/region command"); + if (narg != 9) error->all(FLERR, "Illegal fix wall/region command"); - epsilon = utils::numeric(FLERR,arg[5],false,lmp); - alpha = utils::numeric(FLERR,arg[6],false,lmp); - sigma = utils::numeric(FLERR,arg[7],false,lmp); - cutoff = utils::numeric(FLERR,arg[8],false,lmp); + epsilon = utils::numeric(FLERR, arg[5], false, lmp); + alpha = utils::numeric(FLERR, arg[6], false, lmp); + sigma = utils::numeric(FLERR, arg[7], false, lmp); + cutoff = utils::numeric(FLERR, arg[8], false, lmp); } else { - if (narg != 8) - error->all(FLERR,"Illegal fix wall/region command"); + if (narg != 8) error->all(FLERR, "Illegal fix wall/region command"); - epsilon = utils::numeric(FLERR,arg[5],false,lmp); - sigma = utils::numeric(FLERR,arg[6],false,lmp); - cutoff = utils::numeric(FLERR,arg[7],false,lmp); + epsilon = utils::numeric(FLERR, arg[5], false, lmp); + sigma = utils::numeric(FLERR, arg[6], false, lmp); + cutoff = utils::numeric(FLERR, arg[7], false, lmp); } - if (cutoff <= 0.0) error->all(FLERR,"Fix wall/region cutoff <= 0.0"); + if (cutoff <= 0.0) error->all(FLERR, "Fix wall/region cutoff <= 0.0"); eflag = 0; ewall[0] = ewall[1] = ewall[2] = ewall[3] = 0.0; @@ -95,7 +100,7 @@ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) : FixWallRegion::~FixWallRegion() { - delete [] idregion; + delete[] idregion; } /* ---------------------------------------------------------------------- */ @@ -115,16 +120,14 @@ void FixWallRegion::init() { // set index and check validity of region - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix wall/region does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix wall/region does not exist", idregion); // error checks for style COLLOID // insure all particles in group are extended particles if (style == COLLOID) { - if (!atom->sphere_flag) - error->all(FLERR,"Fix wall/region colloid requires atom style sphere"); + if (!atom->sphere_flag) error->all(FLERR, "Fix wall/region colloid requires atom style sphere"); double *radius = atom->radius; int *mask = atom->mask; @@ -136,61 +139,59 @@ void FixWallRegion::init() if (radius[i] == 0.0) flag = 1; int flagall; - MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); - if (flagall) - error->all(FLERR,"Fix wall/region colloid requires extended particles"); + MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); + if (flagall) error->all(FLERR, "Fix wall/region colloid requires extended particles"); } // setup coefficients for each style if (style == LJ93) { - coeff1 = 6.0/5.0 * epsilon * pow(sigma,9.0); - coeff2 = 3.0 * epsilon * pow(sigma,3.0); - coeff3 = 2.0/15.0 * epsilon * pow(sigma,9.0); - coeff4 = epsilon * pow(sigma,3.0); - double rinv = 1.0/cutoff; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - offset = coeff3*r4inv*r4inv*rinv - coeff4*r2inv*rinv; + coeff1 = 6.0 / 5.0 * epsilon * powint(sigma, 9); + coeff2 = 3.0 * epsilon * powint(sigma, 3); + coeff3 = 2.0 / 15.0 * epsilon * powint(sigma, 9); + coeff4 = epsilon * powint(sigma, 3); + double rinv = 1.0 / cutoff; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + offset = coeff3 * r4inv * r4inv * rinv - coeff4 * r2inv * rinv; } else if (style == LJ126) { - coeff1 = 48.0 * epsilon * pow(sigma,12.0); - coeff2 = 24.0 * epsilon * pow(sigma,6.0); - coeff3 = 4.0 * epsilon * pow(sigma,12.0); - coeff4 = 4.0 * epsilon * pow(sigma,6.0); - double r2inv = 1.0/(cutoff*cutoff); - double r6inv = r2inv*r2inv*r2inv; - offset = r6inv*(coeff3*r6inv - coeff4); + coeff1 = 48.0 * epsilon * powint(sigma, 12); + coeff2 = 24.0 * epsilon * powint(sigma, 6); + coeff3 = 4.0 * epsilon * powint(sigma, 12); + coeff4 = 4.0 * epsilon * powint(sigma, 6); + double r2inv = 1.0 / (cutoff * cutoff); + double r6inv = r2inv * r2inv * r2inv; + offset = r6inv * (coeff3 * r6inv - coeff4); } else if (style == LJ1043) { - coeff1 = MY_2PI * 2.0/5.0 * epsilon * pow(sigma,10.0); - coeff2 = MY_2PI * epsilon * pow(sigma,4.0); - coeff3 = MY_2PI * pow(2.0,1/2.0) / 3 * epsilon * pow(sigma,3.0); - coeff4 = 0.61 / pow(2.0,1/2.0) * sigma; + coeff1 = MY_2PI * 2.0 / 5.0 * epsilon * powint(sigma, 10); + coeff2 = MY_2PI * epsilon * powint(sigma, 4); + coeff3 = MY_2PI * MY_SQRT2 / 3.0 * epsilon * powint(sigma, 3); + coeff4 = 0.61 / MY_SQRT2 * sigma; coeff5 = coeff1 * 10.0; coeff6 = coeff2 * 4.0; coeff7 = coeff3 * 3.0; - double rinv = 1.0/cutoff; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - offset = coeff1*r4inv*r4inv*r2inv - coeff2*r4inv - - coeff3*pow(cutoff+coeff4,-3.0); + double rinv = 1.0 / cutoff; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + offset = coeff1 * r4inv * r4inv * r2inv - coeff2 * r4inv - coeff3 * powint(cutoff + coeff4, -3); } else if (style == MORSE) { coeff1 = 2 * epsilon * alpha; double alpha_dr = -alpha * (cutoff - sigma); - offset = epsilon * (exp(2.0*alpha_dr) - 2.0*exp(alpha_dr)); + offset = epsilon * (exp(2.0 * alpha_dr) - 2.0 * exp(alpha_dr)); } else if (style == COLLOID) { - coeff1 = -4.0/315.0 * epsilon * pow(sigma,6.0); - coeff2 = -2.0/3.0 * epsilon; - coeff3 = epsilon * pow(sigma,6.0)/7560.0; - coeff4 = epsilon/6.0; - double rinv = 1.0/cutoff; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - offset = coeff3*r4inv*r4inv*rinv - coeff4*r2inv*rinv; + coeff1 = -4.0 / 315.0 * epsilon * powint(sigma, 6); + coeff2 = -2.0 / 3.0 * epsilon; + coeff3 = epsilon * powint(sigma, 6) / 7560.0; + coeff4 = epsilon / 6.0; + double rinv = 1.0 / cutoff; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + offset = coeff3 * r4inv * r4inv * rinv - coeff4 * r2inv * rinv; } - if (utils::strmatch(update->integrate_style,"^respa")) { - ilevel_respa = (dynamic_cast( update->integrate))->nlevels-1; - if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); + if (utils::strmatch(update->integrate_style, "^respa")) { + ilevel_respa = (dynamic_cast(update->integrate))->nlevels - 1; + if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } } @@ -198,12 +199,13 @@ void FixWallRegion::init() void FixWallRegion::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) + if (utils::strmatch(update->integrate_style, "^respa")) { + auto respa = dynamic_cast(update->integrate); + respa->copy_flevel_f(ilevel_respa); + post_force_respa(vflag, ilevel_respa, 0); + respa->copy_f_flevel(ilevel_respa); + } else { post_force(vflag); - else { - (dynamic_cast( update->integrate))->copy_flevel_f(ilevel_respa); - post_force_respa(vflag,ilevel_respa,0); - (dynamic_cast( update->integrate))->copy_f_flevel(ilevel_respa); } } @@ -218,8 +220,8 @@ void FixWallRegion::min_setup(int vflag) void FixWallRegion::post_force(int vflag) { - int i,m,n; - double rinv,fx,fy,fz,tooclose; + int i, m, n; + double rinv, fx, fy, fz, tooclose; double delx, dely, delz, v[6]; double **x = atom->x; @@ -228,7 +230,6 @@ void FixWallRegion::post_force(int vflag) int *mask = atom->mask; int nlocal = atom->nlocal; - Region *region = domain->regions[iregion]; region->prematch(); int onflag = 0; @@ -247,27 +248,36 @@ void FixWallRegion::post_force(int vflag) for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - if (!region->match(x[i][0],x[i][1],x[i][2])) { + if (!region->match(x[i][0], x[i][1], x[i][2])) { onflag = 1; continue; } - if (style == COLLOID) tooclose = radius[i]; - else tooclose = 0.0; + if (style == COLLOID) + tooclose = radius[i]; + else + tooclose = 0.0; - n = region->surface(x[i][0],x[i][1],x[i][2],cutoff); + n = region->surface(x[i][0], x[i][1], x[i][2], cutoff); for (m = 0; m < n; m++) { if (region->contact[m].r <= tooclose) { onflag = 1; continue; - } else rinv = 1.0/region->contact[m].r; + } else + rinv = 1.0 / region->contact[m].r; - if (style == LJ93) lj93(region->contact[m].r); - else if (style == LJ126) lj126(region->contact[m].r); - else if (style == LJ1043) lj1043(region->contact[m].r); - else if (style == MORSE) morse(region->contact[m].r); - else if (style == COLLOID) colloid(region->contact[m].r,radius[i]); - else harmonic(region->contact[m].r); + if (style == LJ93) + lj93(region->contact[m].r); + else if (style == LJ126) + lj126(region->contact[m].r); + else if (style == LJ1043) + lj1043(region->contact[m].r); + else if (style == MORSE) + morse(region->contact[m].r); + else if (style == COLLOID) + colloid(region->contact[m].r, radius[i]); + else + harmonic(region->contact[m].r); delx = region->contact[m].delx; dely = region->contact[m].dely; @@ -283,19 +293,18 @@ void FixWallRegion::post_force(int vflag) ewall[3] -= fz; ewall[0] += eng; if (evflag) { - v[0] = fx*delx; - v[1] = fy*dely; - v[2] = fz*delz; - v[3] = fx*dely; - v[4] = fx*delz; - v[5] = fy*delz; + v[0] = fx * delx; + v[1] = fy * dely; + v[2] = fz * delz; + v[3] = fx * dely; + v[4] = fx * delz; + v[5] = fy * delz; v_tally(i, v); } } } - if (onflag) error->one(FLERR,"Particle outside surface of region " - "used in fix wall/region"); + if (onflag) error->one(FLERR, "Particle outside surface of region used in fix wall/region"); } /* ---------------------------------------------------------------------- */ @@ -321,7 +330,7 @@ double FixWallRegion::compute_scalar() // only sum across procs one time if (eflag == 0) { - MPI_Allreduce(ewall,ewall_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(ewall, ewall_all, 4, MPI_DOUBLE, MPI_SUM, world); eflag = 1; } return ewall_all[0]; @@ -336,10 +345,10 @@ double FixWallRegion::compute_vector(int n) // only sum across procs one time if (eflag == 0) { - MPI_Allreduce(ewall,ewall_all,4,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(ewall, ewall_all, 4, MPI_DOUBLE, MPI_SUM, world); eflag = 1; } - return ewall_all[n+1]; + return ewall_all[n + 1]; } /* ---------------------------------------------------------------------- @@ -349,12 +358,12 @@ double FixWallRegion::compute_vector(int n) void FixWallRegion::lj93(double r) { - double rinv = 1.0/r; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - double r10inv = r4inv*r4inv*r2inv; - fwall = coeff1*r10inv - coeff2*r4inv; - eng = coeff3*r4inv*r4inv*rinv - coeff4*r2inv*rinv - offset; + double rinv = 1.0 / r; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + double r10inv = r4inv * r4inv * r2inv; + fwall = coeff1 * r10inv - coeff2 * r4inv; + eng = coeff3 * r4inv * r4inv * rinv - coeff4 * r2inv * rinv - offset; } /* ---------------------------------------------------------------------- @@ -364,11 +373,11 @@ void FixWallRegion::lj93(double r) void FixWallRegion::lj126(double r) { - double rinv = 1.0/r; - double r2inv = rinv*rinv; - double r6inv = r2inv*r2inv*r2inv; - fwall = r6inv*(coeff1*r6inv - coeff2) * rinv; - eng = r6inv*(coeff3*r6inv - coeff4) - offset; + double rinv = 1.0 / r; + double r2inv = rinv * rinv; + double r6inv = r2inv * r2inv * r2inv; + fwall = r6inv * (coeff1 * r6inv - coeff2) * rinv; + eng = r6inv * (coeff3 * r6inv - coeff4) - offset; } /* ---------------------------------------------------------------------- @@ -378,14 +387,12 @@ void FixWallRegion::lj126(double r) void FixWallRegion::lj1043(double r) { - double rinv = 1.0/r; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - double r10inv = r4inv*r4inv*r2inv; - fwall = coeff5*r10inv*rinv - coeff6*r4inv*rinv - - coeff7*pow(r+coeff4,-4.0); - eng = coeff1*r10inv - coeff2*r4inv - - coeff3*pow(r+coeff4,-3.0) - offset; + double rinv = 1.0 / r; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + double r10inv = r4inv * r4inv * r2inv; + fwall = coeff5 * r10inv * rinv - coeff6 * r4inv * rinv - coeff7 * powint(r + coeff4, -4); + eng = coeff1 * r10inv - coeff2 * r4inv - coeff3 * powint(r + coeff4, -3) - offset; } /* ---------------------------------------------------------------------- @@ -397,8 +404,8 @@ void FixWallRegion::morse(double r) { double dr = r - sigma; double dexp = exp(-alpha * dr); - fwall = coeff1 * (dexp*dexp - dexp); - eng = epsilon * (dexp*dexp - 2.0*dexp) - offset; + fwall = coeff1 * (dexp * dexp - dexp); + eng = epsilon * (dexp * dexp - 2.0 * dexp) - offset; } /* ---------------------------------------------------------------------- @@ -408,33 +415,35 @@ void FixWallRegion::morse(double r) void FixWallRegion::colloid(double r, double rad) { - double new_coeff2 = coeff2*rad*rad*rad; - double diam = 2.0*rad; + double new_coeff2 = coeff2 * rad * rad * rad; + double diam = 2.0 * rad; - double rad2 = rad*rad; - double rad4 = rad2*rad2; - double rad8 = rad4*rad4; - double delta2 = rad2 - r*r; - double rinv = 1.0/delta2; - double r2inv = rinv*rinv; - double r4inv = r2inv*r2inv; - double r8inv = r4inv*r4inv; - fwall = coeff1*(rad8*rad + 27.0*rad4*rad2*rad*pow(r,2.0) - + 63.0*rad4*rad*pow(r,4.0) - + 21.0*rad2*rad*pow(r,6.0))*r8inv - new_coeff2*r2inv; + double rad2 = rad * rad; + double rad4 = rad2 * rad2; + double rad8 = rad4 * rad4; + double delta2 = rad2 - r * r; + double rinv = 1.0 / delta2; + double r2inv = rinv * rinv; + double r4inv = r2inv * r2inv; + double r8inv = r4inv * r4inv; + fwall = coeff1 * + (rad8 * rad + 27.0 * rad4 * rad2 * rad * r * r + 63.0 * rad4 * rad * powint(r, 4) + + 21.0 * rad2 * rad * powint(r, 6)) * + r8inv - + new_coeff2 * r2inv; - double r2 = 0.5*diam - r; - double rinv2 = 1.0/r2; - double r2inv2 = rinv2*rinv2; - double r4inv2 = r2inv2*r2inv2; - double r3 = r + 0.5*diam; - double rinv3 = 1.0/r3; - double r2inv3 = rinv3*rinv3; - double r4inv3 = r2inv3*r2inv3; - eng = coeff3*((-3.5*diam+r)*r4inv2*r2inv2*rinv2 - + (3.5*diam+r)*r4inv3*r2inv3*rinv3) - - coeff4*((-diam*r+r2*r3*(log(-r2)-log(r3)))* - (-rinv2)*rinv3) - offset; + double r2 = 0.5 * diam - r; + double rinv2 = 1.0 / r2; + double r2inv2 = rinv2 * rinv2; + double r4inv2 = r2inv2 * r2inv2; + double r3 = r + 0.5 * diam; + double rinv3 = 1.0 / r3; + double r2inv3 = rinv3 * rinv3; + double r4inv3 = r2inv3 * r2inv3; + eng = coeff3 * + ((-3.5 * diam + r) * r4inv2 * r2inv2 * rinv2 + + (3.5 * diam + r) * r4inv3 * r2inv3 * rinv3) - + coeff4 * ((-diam * r + r2 * r3 * (log(-r2) - log(r3))) * (-rinv2) * rinv3) - offset; } /* ---------------------------------------------------------------------- @@ -445,6 +454,6 @@ void FixWallRegion::colloid(double r, double rad) void FixWallRegion::harmonic(double r) { double dr = cutoff - r; - fwall = 2.0*epsilon*dr; - eng = epsilon*dr*dr; + fwall = 2.0 * epsilon * dr; + eng = epsilon * dr * dr; } diff --git a/src/fix_wall_region.h b/src/fix_wall_region.h index 5da19f6698..6a2ab381ff 100644 --- a/src/fix_wall_region.h +++ b/src/fix_wall_region.h @@ -39,13 +39,14 @@ class FixWallRegion : public Fix { double compute_vector(int) override; private: - int style, iregion; + int style; double epsilon, sigma, cutoff; double alpha; int eflag; double ewall[4], ewall_all[4]; int ilevel_respa; char *idregion; + class Region *region; double coeff1, coeff2, coeff3, coeff4, offset; double coeff5, coeff6, coeff7; diff --git a/src/force.cpp b/src/force.cpp index 40c4eff92e..8bed122451 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -298,7 +298,7 @@ Pair *Force::pair_match(const std::string &word, int exact, int nsub) else if (!exact && utils::strmatch(pair_style, word)) return pair; else if (utils::strmatch(pair_style, "^hybrid")) { - auto hybrid = dynamic_cast( pair); + auto hybrid = dynamic_cast(pair); count = 0; for (int i = 0; i < hybrid->nstyles; i++) if ((exact && (word == hybrid->keywords[i])) || @@ -324,7 +324,7 @@ char *Force::pair_match_ptr(Pair *ptr) if (ptr == pair) return pair_style; if (utils::strmatch(pair_style, "^hybrid")) { - auto hybrid = dynamic_cast( pair); + auto hybrid = dynamic_cast(pair); for (int i = 0; i < hybrid->nstyles; i++) if (ptr == hybrid->styles[i]) return hybrid->keywords[i]; } @@ -393,7 +393,7 @@ Bond *Force::bond_match(const std::string &style) if (style == bond_style) return bond; else if (strcmp(bond_style, "hybrid") == 0) { - auto hybrid = dynamic_cast( bond); + auto hybrid = dynamic_cast(bond); for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; } @@ -461,7 +461,7 @@ Angle *Force::angle_match(const std::string &style) if (style == angle_style) return angle; else if (utils::strmatch(angle_style, "^hybrid")) { - auto hybrid = dynamic_cast( angle); + auto hybrid = dynamic_cast(angle); for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; } @@ -529,7 +529,7 @@ Dihedral *Force::dihedral_match(const std::string &style) if (style == dihedral_style) return dihedral; else if (utils::strmatch(dihedral_style, "^hybrid")) { - auto hybrid = dynamic_cast( dihedral); + auto hybrid = dynamic_cast(dihedral); for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; } @@ -597,7 +597,7 @@ Improper *Force::improper_match(const std::string &style) if (style == improper_style) return improper; else if (utils::strmatch(improper_style, "^hybrid")) { - auto hybrid = dynamic_cast( improper); + auto hybrid = dynamic_cast(improper); for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; } diff --git a/src/group.cpp b/src/group.cpp index a3d1299296..d678f2de86 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -857,10 +857,9 @@ double Group::mass(int igroup) use either per-type mass or per-atom rmass ------------------------------------------------------------------------- */ -double Group::mass(int igroup, int iregion) +double Group::mass(int igroup, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -887,6 +886,16 @@ double Group::mass(int igroup, int iregion) return all; } +/* ---------------------------------------------------------------------- + compute the total mass of group of atoms in region + use either per-type mass or per-atom rmass +------------------------------------------------------------------------- */ + +double Group::mass(int igroup, int iregion) +{ + return mass(igroup, domain->regions[iregion]); +} + /* ---------------------------------------------------------------------- compute the total charge of group of atoms ------------------------------------------------------------------------- */ @@ -1181,10 +1190,9 @@ void Group::vcm(int igroup, double masstotal, double *cm) return center-of-mass velocity in cm[] ------------------------------------------------------------------------- */ -void Group::vcm(int igroup, double masstotal, double *cm, int iregion) +void Group::vcm(int igroup, double masstotal, double *cm, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1224,6 +1232,17 @@ void Group::vcm(int igroup, double masstotal, double *cm, int iregion) } } +/* ---------------------------------------------------------------------- + compute the center-of-mass velocity of group of atoms in region + masstotal = total mass + return center-of-mass velocity in cm[] +------------------------------------------------------------------------- */ + +void Group::vcm(int igroup, double masstotal, double *cm, int iregion) +{ + vcm(igroup, masstotal, cm, domain->regions[iregion]); +} + /* ---------------------------------------------------------------------- compute the total force on group of atoms ------------------------------------------------------------------------- */ @@ -1316,10 +1335,9 @@ double Group::ke(int igroup) compute the total kinetic energy of group of atoms in region and return it ------------------------------------------------------------------------- */ -double Group::ke(int igroup, int iregion) +double Group::ke(int igroup, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1350,6 +1368,15 @@ double Group::ke(int igroup, int iregion) return all; } +/* ---------------------------------------------------------------------- + compute the total kinetic energy of group of atoms in region and return it +------------------------------------------------------------------------- */ + +double Group::ke(int igroup, int iregion) +{ + return ke(igroup, domain->regions[iregion]); +} + /* ---------------------------------------------------------------------- compute the radius-of-gyration of group of atoms around center-of-mass cm diff --git a/src/group.h b/src/group.h index bd5e996672..6b075bb4f8 100644 --- a/src/group.h +++ b/src/group.h @@ -19,6 +19,7 @@ #include namespace LAMMPS_NS { +class Region; class Group : protected Pointers { public: @@ -38,12 +39,13 @@ class Group : protected Pointers { void write_restart(FILE *); void read_restart(FILE *); - bigint count_all(); // count atoms in group all - bigint count(int); // count atoms in group - bigint count(int, int); // count atoms in group & region - bigint count(int, class Region *); // count atoms in group & region - double mass(int); // total mass of atoms in group + bigint count_all(); // count atoms in group all + bigint count(int); // count atoms in group + bigint count(int, int); // count atoms in group & region + bigint count(int, Region *); // count atoms in group & region + double mass(int); // total mass of atoms in group double mass(int, int); + double mass(int, Region *); double charge(int); // total charge of atoms in group double charge(int, int); void bounds(int, double *); // bounds of atoms in group @@ -52,10 +54,12 @@ class Group : protected Pointers { void xcm(int, double, double *, int); void vcm(int, double, double *); // center-of-mass velocity of group void vcm(int, double, double *, int); + void vcm(int, double, double *, Region *); void fcm(int, double *); // total force on group void fcm(int, double *, int); double ke(int); // kinetic energy of group double ke(int, int); + double ke(int, Region *); double gyration(int, double, double *); // radius-of-gyration of group double gyration(int, double, double *, int); void angmom(int, double *, double *); // angular momentum of group diff --git a/src/math_extra.h b/src/math_extra.h index 55d680b0f2..cbf9f78e53 100644 --- a/src/math_extra.h +++ b/src/math_extra.h @@ -665,15 +665,15 @@ inline void MathExtra::quatrotvec(double *a, double *b, double *c) double temp[4]; // temp = a*b - temp[0] = -a[1]*b[0] - a[2]*b[1] - a[3]*b[2]; - temp[1] = a[0]*b[0] + a[2]*b[2] - a[3]*b[1]; - temp[2] = a[0]*b[1] + a[3]*b[0] - a[1]*b[2]; - temp[3] = a[0]*b[2] + a[1]*b[1] - a[2]*b[0]; + temp[0] = -a[1] * b[0] - a[2] * b[1] - a[3] * b[2]; + temp[1] = a[0] * b[0] + a[2] * b[2] - a[3] * b[1]; + temp[2] = a[0] * b[1] + a[3] * b[0] - a[1] * b[2]; + temp[3] = a[0] * b[2] + a[1] * b[1] - a[2] * b[0]; // c = temp*conj(a) - c[0] = -a[1]*temp[0] + a[0]*temp[1] - a[3]*temp[2] + a[2]*temp[3]; - c[1] = -a[2]*temp[0] + a[3]*temp[1] + a[0]*temp[2] - a[1]*temp[3]; - c[2] = -a[3]*temp[0] - a[2]*temp[1] + a[1]*temp[2] + a[0]*temp[3]; + c[0] = -a[1] * temp[0] + a[0] * temp[1] - a[3] * temp[2] + a[2] * temp[3]; + c[1] = -a[2] * temp[0] + a[3] * temp[1] + a[0] * temp[2] - a[1] * temp[3]; + c[2] = -a[3] * temp[0] - a[2] * temp[1] + a[1] * temp[2] + a[0] * temp[3]; } /* ---------------------------------------------------------------------- diff --git a/src/memory.h b/src/memory.h index 5095cbb0a6..da2440450b 100644 --- a/src/memory.h +++ b/src/memory.h @@ -27,7 +27,7 @@ class Memory : protected Pointers { void sfree(void *); void fail(const char *); -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create/grow/destroy vecs and multidim arrays with contiguous memory blocks only use with primitive data types, e.g. 1d vec of ints, 2d array of doubles fail() prevents use with pointers, @@ -36,7 +36,7 @@ class Memory : protected Pointers { for these other cases, use smalloc/srealloc/sfree directly ------------------------------------------------------------------------- */ -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 1d array ------------------------------------------------------------------------- */ @@ -56,7 +56,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- grow or shrink 1d array ------------------------------------------------------------------------- */ @@ -81,7 +81,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 1d array ------------------------------------------------------------------------- */ @@ -91,7 +91,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 1d array with index from nlo to nhi inclusive cannot grow it ------------------------------------------------------------------------- */ @@ -114,7 +114,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 1d array with index offset ------------------------------------------------------------------------- */ @@ -124,7 +124,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 2d array ------------------------------------------------------------------------- */ @@ -153,7 +153,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- grow or shrink 1st dim of a 2d array last dim must stay the same ------------------------------------------------------------------------- */ @@ -188,7 +188,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 2d array ------------------------------------------------------------------------- */ @@ -200,7 +200,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 2d array with a ragged 2nd dimension ------------------------------------------------------------------------- */ @@ -226,15 +226,14 @@ class Memory : protected Pointers { } template - TYPE ***create_ragged(TYPE ***& array, int n1, int *n2, int **n3, const char *name) + TYPE ***create_ragged(TYPE ***&array, int n1, int *n2, int **n3, const char *name) { bigint size, nbytes; int i, j; size = 0; for (i = 0; i < n1; i++) - for (j = 0; j < n2[i]; j++) - size += n3[i][j]; + for (j = 0; j < n2[i]; j++) size += n3[i][j]; nbytes = ((bigint) sizeof(TYPE)) * size; TYPE *data = (TYPE *) smalloc(nbytes, name); @@ -260,7 +259,7 @@ class Memory : protected Pointers { return array; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 2d array with 2nd index from n2lo to n2hi inclusive cannot grow it ------------------------------------------------------------------------- */ @@ -285,7 +284,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 2d array with 2nd index offset ------------------------------------------------------------------------- */ @@ -297,7 +296,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 3d array ------------------------------------------------------------------------- */ @@ -334,7 +333,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- grow or shrink 1st dim of a 3d array last 2 dims must stay the same ------------------------------------------------------------------------- */ @@ -377,7 +376,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 3d array ------------------------------------------------------------------------- */ @@ -390,7 +389,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 3d array with 1st index from n1lo to n1hi inclusive cannot grow it ------------------------------------------------------------------------- */ @@ -414,7 +413,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- free a 3d array with 1st index offset ------------------------------------------------------------------------- */ @@ -427,7 +426,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 3d array with 1st index from n1lo to n1hi inclusive, 2nd index from n2lo to n2hi inclusive, @@ -461,7 +460,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- free a 3d array with all 3 indices offset ------------------------------------------------------------------------- */ @@ -475,7 +474,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 4d array ------------------------------------------------------------------------- */ @@ -522,7 +521,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- grow or shrink 1st dim of a 4d array last 3 dims must stay the same ------------------------------------------------------------------------- */ @@ -575,7 +574,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 4d array ------------------------------------------------------------------------- */ @@ -589,7 +588,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 4d array with indices 2nd index from n2lo to n2hi inclusive 3rd index from n3lo to n3hi inclusive @@ -624,7 +623,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- free a 4d array with indices 2,3,4 offset ------------------------------------------------------------------------- */ @@ -639,7 +638,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- create a 5d array ------------------------------------------------------------------------- */ @@ -693,7 +692,7 @@ class Memory : protected Pointers { return nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- destroy a 5d array ------------------------------------------------------------------------- */ @@ -708,7 +707,7 @@ class Memory : protected Pointers { array = nullptr; } -/* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- memory usage of arrays, including pointers ------------------------------------------------------------------------- */ diff --git a/src/modify.h b/src/modify.h index df8e52752f..0ad0d1fb33 100644 --- a/src/modify.h +++ b/src/modify.h @@ -179,8 +179,8 @@ 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; + std::vector fix_list; + std::vector compute_list; void list_init(int, int &, int *&); void list_init_end_of_step(int, int &, int *&); diff --git a/src/neigh_request.h b/src/neigh_request.h index c8c2277acc..2917ae6927 100644 --- a/src/neigh_request.h +++ b/src/neigh_request.h @@ -19,14 +19,15 @@ namespace LAMMPS_NS { class NeighRequest : protected Pointers { - friend class Neighbor; - friend class NBin; - friend class NeighList; - friend class NPair; - friend class NStencil; - friend class NeighborKokkos; - friend class NPairSkipIntel; - friend class FixIntel; + friend class Neighbor; + friend class NBin; + friend class NeighList; + friend class NPair; + friend class NStencil; + friend class NeighborKokkos; + friend class NPairSkipIntel; + friend class FixIntel; + protected: int index; // index of which neigh request this is void *requestor; // class that made request diff --git a/src/neighbor.h b/src/neighbor.h index 2feafe1bce..3d36063447 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -159,8 +159,8 @@ class Neighbor : protected Pointers { int any_full(); // Check if any old requests had full neighbor lists void build_collection(int); // build peratom collection array starting at the given index - bigint get_nneigh_full(); // return number of neighbors in a regular full neighbor list - bigint get_nneigh_half(); // return number of neighbors in a regular half neighbor list + bigint get_nneigh_full(); // return number of neighbors in a regular full neighbor list + bigint get_nneigh_half(); // return number of neighbors in a regular half neighbor list double memory_usage(); bigint last_setup_bins; // step of last neighbor::setup_bins() call diff --git a/src/output.h b/src/output.h index 54fc83c380..54cb1731d4 100644 --- a/src/output.h +++ b/src/output.h @@ -33,20 +33,20 @@ class Output : protected Pointers { int ivar_thermo; // variable index for thermo frequency class Thermo *thermo; // Thermodynamic computations - int ndump; // # of Dumps defined - int max_dump; // max size of Dump list - bigint next_dump_any; // next timestep for any dump - bigint next_time_dump_any; // next timestep for any time dump with computes - int any_time_dumps; // 1 if any time dump defined - int *mode_dump; // 0/1 if write every N timesteps or Delta in sim time - int *every_dump; // dump every N timesteps, 0 if variable - double *every_time_dump; // dump every Delta of sim time, 0.0 if variable - bigint *next_dump; // next timestep to perform dump - double *next_time_dump; // next simulation time to perform dump (mode = 1) - bigint *last_dump; // last timestep each snapshot was output - char **var_dump; // variable name for next dump (steps or sim time) - int *ivar_dump; // variable index of var_dump name - Dump **dump; // list of defined Dumps + int ndump; // # of Dumps defined + int max_dump; // max size of Dump list + bigint next_dump_any; // next timestep for any dump + bigint next_time_dump_any; // next timestep for any time dump with computes + int any_time_dumps; // 1 if any time dump defined + int *mode_dump; // 0/1 if write every N timesteps or Delta in sim time + int *every_dump; // dump every N timesteps, 0 if variable + double *every_time_dump; // dump every Delta of sim time, 0.0 if variable + bigint *next_dump; // next timestep to perform dump + double *next_time_dump; // next simulation time to perform dump (mode = 1) + bigint *last_dump; // last timestep each snapshot was output + char **var_dump; // variable name for next dump (steps or sim time) + int *ivar_dump; // variable index of var_dump name + Dump **dump; // list of defined Dumps int restart_flag; // 1 if any restart files are written int restart_flag_single; // 1 if single restart files are written diff --git a/src/pair_hybrid_scaled.cpp b/src/pair_hybrid_scaled.cpp index aef5ae4d5e..49ebaabe24 100644 --- a/src/pair_hybrid_scaled.cpp +++ b/src/pair_hybrid_scaled.cpp @@ -130,7 +130,7 @@ void PairHybridScaled::compute(int eflag, int vflag) Respa *respa = nullptr; respaflag = 0; if (utils::strmatch(update->integrate_style, "^respa")) { - respa = dynamic_cast( update->integrate); + respa = dynamic_cast(update->integrate); if (respa->nhybrid_styles > 0) respaflag = 1; } @@ -477,8 +477,8 @@ void PairHybridScaled::coeff(int narg, char **arg) // ensure that one_coeff flag is honored if (!none && styles[m]->one_coeff) - if ((strcmp(arg[0],"*") != 0) || (strcmp(arg[1],"*") != 0)) - error->all(FLERR,"Incorrect args for pair coefficients"); + if ((strcmp(arg[0], "*") != 0) || (strcmp(arg[1], "*") != 0)) + error->all(FLERR, "Incorrect args for pair coefficients"); // invoke sub-style coeff() starting with 1st remaining arg diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index 8c24bd2f70..503d7a3b33 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -478,7 +478,7 @@ void PairLJCut::init_style() int list_style = NeighConst::REQ_DEFAULT; if (update->whichflag == 1 && utils::strmatch(update->integrate_style, "^respa")) { - auto respa = dynamic_cast( update->integrate); + auto respa = dynamic_cast(update->integrate); if (respa->level_inner >= 0) list_style = NeighConst::REQ_RESPA_INOUT; if (respa->level_middle >= 0) list_style = NeighConst::REQ_RESPA_ALL; } @@ -487,8 +487,8 @@ void PairLJCut::init_style() // set rRESPA cutoffs if (utils::strmatch(update->integrate_style, "^respa") && - (dynamic_cast( update->integrate))->level_inner >= 0) - cut_respa = (dynamic_cast( update->integrate))->cutoff; + (dynamic_cast(update->integrate))->level_inner >= 0) + cut_respa = (dynamic_cast(update->integrate))->cutoff; else cut_respa = nullptr; } diff --git a/src/platform.cpp b/src/platform.cpp index 8645bca6e1..d37309c043 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -19,9 +19,9 @@ #include "text_file_reader.h" #include "utils.h" -#include -#include #include +#include +#include //////////////////////////////////////////////////////////////////////// // include system headers and tweak system settings @@ -71,11 +71,11 @@ struct compress_info { /// identifier for the different compression algorithms enum styles { NONE, GZIP, BZIP2, ZSTD, XZ, LZMA, LZ4 }; - const std::string extension; ///< filename extension for the current algorithm - const std::string command; ///< command to perform compression or decompression + const std::string extension; ///< filename extension for the current algorithm + const std::string command; ///< command to perform compression or decompression const std::string compressflags; ///< flags to append to compress from stdin to stdout const std::string uncompressflags; ///< flags to decompress file to stdout - const int style; ///< compression style flag + const int style; ///< compression style flag }; // clang-format off @@ -230,16 +230,16 @@ std::string platform::os_info() if (platform::file_is_readable("/etc/os-release")) { try { - TextFileReader reader("/etc/os-release",""); - while (true) { - auto words = reader.next_values(0,"="); - if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) { - buf += " " + utils::trim(words.next_string()); - break; - } + TextFileReader reader("/etc/os-release", ""); + while (true) { + auto words = reader.next_values(0, "="); + if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) { + buf += " " + utils::trim(words.next_string()); + break; } + } } catch (std::exception &e) { - ; // EOF but keyword not found + ; // EOF but keyword not found } } @@ -427,11 +427,11 @@ std::string platform::compress_info() std::string buf = "Available compression formats:\n\n"; bool none_found = true; for (const auto &cmpi : compress_styles) { - if (cmpi.style == ::compress_info::NONE) continue; - if (find_exe_path(cmpi.command).size()) { - none_found = false; - buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command); - } + if (cmpi.style == ::compress_info::NONE) continue; + if (find_exe_path(cmpi.command).size()) { + none_found = false; + buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command); + } } if (none_found) buf += "None\n"; return buf; @@ -450,7 +450,7 @@ int platform::putenv(const std::string &vardef) if (found == std::string::npos) return _putenv_s(vardef.c_str(), "1"); else - return _putenv_s(vardef.substr(0, found).c_str(), vardef.substr(found+1).c_str()); + return _putenv_s(vardef.substr(0, found).c_str(), vardef.substr(found + 1).c_str()); #else if (found == std::string::npos) return setenv(vardef.c_str(), "", 1); @@ -472,7 +472,7 @@ int platform::unsetenv(const std::string &variable) const char *ptr = getenv(variable.c_str()); if (!ptr) return -1; // empty _putenv_s() definition deletes variable - return _putenv_s(variable.c_str(),""); + return _putenv_s(variable.c_str(), ""); #else return ::unsetenv(variable.c_str()); #endif @@ -579,8 +579,10 @@ void *platform::dlopen(const std::string &fname) std::string platform::dlerror() { const char *errmesg = ::dlerror(); - if (errmesg) return {errmesg}; - else return {""}; + if (errmesg) + return {errmesg}; + else + return {""}; } // close a shared object @@ -758,7 +760,7 @@ int platform::chdir(const std::string &path) int platform::mkdir(const std::string &path) { - std::deque dirlist = { path }; + std::deque dirlist = {path}; std::string dirname = path_dirname(path); while ((dirname != ".") && (dirname != "")) { diff --git a/src/reader.h b/src/reader.h index adc93c6d7c..13351ee34f 100644 --- a/src/reader.h +++ b/src/reader.h @@ -36,9 +36,9 @@ class Reader : protected Pointers { virtual void close_file(); protected: - FILE *fp; // pointer to opened file or pipe - bool compressed; // flag for dump file compression - bool binary; // flag for (native) binary files + FILE *fp; // pointer to opened file or pipe + bool compressed; // flag for dump file compression + bool binary; // flag for (native) binary files }; } // namespace LAMMPS_NS diff --git a/src/reader_native.h b/src/reader_native.h index 6566df0680..146019f986 100644 --- a/src/reader_native.h +++ b/src/reader_native.h @@ -24,8 +24,8 @@ ReaderStyle(native,ReaderNative); #include "reader.h" -#include #include +#include namespace LAMMPS_NS { diff --git a/src/region.cpp b/src/region.cpp index eba9f48510..b533d45ea7 100644 --- a/src/region.cpp +++ b/src/region.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -30,9 +29,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Region::Region(LAMMPS *lmp, int /*narg*/, char **arg) : - Pointers(lmp), - id(nullptr), style(nullptr), contact(nullptr), list(nullptr), - xstr(nullptr), ystr(nullptr), zstr(nullptr), tstr(nullptr) + Pointers(lmp), id(nullptr), style(nullptr), reglist(nullptr), contact(nullptr), xstr(nullptr), + ystr(nullptr), zstr(nullptr), tstr(nullptr) { id = utils::strdup(arg[0]); style = utils::strdup(arg[1]); @@ -44,7 +42,6 @@ Region::Region(LAMMPS *lmp, int /*narg*/, char **arg) : size_restart = 5; Region::reset_vel(); copymode = 0; - list = nullptr; nregion = 1; } @@ -54,13 +51,13 @@ Region::~Region() { if (copymode) return; - delete [] id; - delete [] style; + delete[] id; + delete[] style; - delete [] xstr; - delete [] ystr; - delete [] zstr; - delete [] tstr; + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] tstr; } /* ---------------------------------------------------------------------- */ @@ -69,27 +66,27 @@ void Region::init() { if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) error->all(FLERR,"Variable name for region does not exist"); + if (xvar < 0) error->all(FLERR, "Variable name for region does not exist"); if (!input->variable->equalstyle(xvar)) - error->all(FLERR,"Variable for region is invalid style"); + error->all(FLERR, "Variable for region is invalid style"); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) error->all(FLERR,"Variable name for region does not exist"); + if (yvar < 0) error->all(FLERR, "Variable name for region does not exist"); if (!input->variable->equalstyle(yvar)) - error->all(FLERR,"Variable for region is not equal style"); + error->all(FLERR, "Variable for region is not equal style"); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) error->all(FLERR,"Variable name for region does not exist"); + if (zvar < 0) error->all(FLERR, "Variable name for region does not exist"); if (!input->variable->equalstyle(zvar)) - error->all(FLERR,"Variable for region is not equal style"); + error->all(FLERR, "Variable for region is not equal style"); } if (tstr) { tvar = input->variable->find(tstr); - if (tvar < 0) error->all(FLERR,"Variable name for region does not exist"); + if (tvar < 0) error->all(FLERR, "Variable name for region does not exist"); if (!input->variable->equalstyle(tvar)) - error->all(FLERR,"Variable for region is not equal style"); + error->all(FLERR, "Variable for region is not equal style"); } vel_timestep = -1; } @@ -133,9 +130,9 @@ void Region::prematch() int Region::match(double x, double y, double z) { - if (dynamic) inverse_transform(x,y,z); + if (dynamic) inverse_transform(x, y, z); if (openflag) return 1; - return !(inside(x,y,z) ^ interior); + return !(inside(x, y, z) ^ interior); } /* ---------------------------------------------------------------------- @@ -153,14 +150,14 @@ int Region::match(double x, double y, double z) int Region::surface(double x, double y, double z, double cutoff) { int ncontact; - double xs,ys,zs; - double xnear[3],xorig[3]; + double xs, ys, zs; + double xnear[3], xorig[3]; if (dynamic) { xorig[0] = x; xorig[1] = y; xorig[2] = z; - inverse_transform(x,y,z); + inverse_transform(x, y, z); } xnear[0] = x; @@ -168,12 +165,14 @@ int Region::surface(double x, double y, double z, double cutoff) xnear[2] = z; if (!openflag) { - if (interior) ncontact = surface_interior(xnear,cutoff); - else ncontact = surface_exterior(xnear,cutoff); + if (interior) + ncontact = surface_interior(xnear, cutoff); + else + ncontact = surface_exterior(xnear, cutoff); } else { // one of surface_int/ext() will return 0 // so no need to worry about offset of contact indices - ncontact = surface_exterior(xnear,cutoff) + surface_interior(xnear,cutoff); + ncontact = surface_exterior(xnear, cutoff) + surface_interior(xnear, cutoff); } if (rotateflag && ncontact) { @@ -181,7 +180,7 @@ int Region::surface(double x, double y, double z, double cutoff) xs = xnear[0] - contact[i].delx; ys = xnear[1] - contact[i].dely; zs = xnear[2] - contact[i].delz; - forward_transform(xs,ys,zs); + forward_transform(xs, ys, zs); contact[i].delx = xorig[0] - xs; contact[i].dely = xorig[1] - ys; contact[i].delz = xorig[2] - zs; @@ -202,7 +201,7 @@ void Region::add_contact(int n, double *x, double xp, double yp, double zp) double delx = x[0] - xp; double dely = x[1] - yp; double delz = x[2] - zp; - contact[n].r = sqrt(delx*delx + dely*dely + delz*delz); + contact[n].r = sqrt(delx * delx + dely * dely + delz * delz); contact[n].radius = 0; contact[n].delx = delx; contact[n].dely = dely; @@ -231,7 +230,7 @@ void Region::pretransform() void Region::forward_transform(double &x, double &y, double &z) { - if (rotateflag) rotate(x,y,z,theta); + if (rotateflag) rotate(x, y, z, theta); if (moveflag) { x += dx; y += dy; @@ -251,7 +250,7 @@ void Region::inverse_transform(double &x, double &y, double &z) y -= dy; z -= dz; } - if (rotateflag) rotate(x,y,z,-theta); + if (rotateflag) rotate(x, y, z, -theta); } /* ---------------------------------------------------------------------- @@ -272,26 +271,26 @@ void Region::inverse_transform(double &x, double &y, double &z) void Region::rotate(double &x, double &y, double &z, double angle) { - double a[3],b[3],c[3],d[3],disp[3]; + double a[3], b[3], c[3], d[3], disp[3]; double sine = sin(angle); double cosine = cos(angle); d[0] = x - point[0]; d[1] = y - point[1]; d[2] = z - point[2]; - double x0dotr = d[0]*runit[0] + d[1]*runit[1] + d[2]*runit[2]; + double x0dotr = d[0] * runit[0] + d[1] * runit[1] + d[2] * runit[2]; c[0] = x0dotr * runit[0]; c[1] = x0dotr * runit[1]; c[2] = x0dotr * runit[2]; a[0] = d[0] - c[0]; a[1] = d[1] - c[1]; a[2] = d[2] - c[2]; - b[0] = runit[1]*a[2] - runit[2]*a[1]; - b[1] = runit[2]*a[0] - runit[0]*a[2]; - b[2] = runit[0]*a[1] - runit[1]*a[0]; - disp[0] = a[0]*cosine + b[0]*sine; - disp[1] = a[1]*cosine + b[1]*sine; - disp[2] = a[2]*cosine + b[2]*sine; + b[0] = runit[1] * a[2] - runit[2] * a[1]; + b[1] = runit[2] * a[0] - runit[0] * a[2]; + b[2] = runit[0] * a[1] - runit[1] * a[0]; + disp[0] = a[0] * cosine + b[0] * sine; + disp[1] = a[1] * cosine + b[1] * sine; + disp[2] = a[2] * cosine + b[2] * sine; x = point[0] + c[0] + disp[0]; y = point[1] + c[1] + disp[1]; z = point[2] + c[2] + disp[2]; @@ -303,7 +302,7 @@ void Region::rotate(double &x, double &y, double &z, double angle) void Region::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR,"Illegal region command"); + if (narg < 0) error->all(FLERR, "Illegal region command"); // option defaults @@ -312,74 +311,78 @@ void Region::options(int narg, char **arg) moveflag = rotateflag = 0; openflag = 0; - for (int i = 0; i < 6; i++) open_faces[i] = 0; + for (int i = 0; i < 6; i++) open_faces[i] = 0; int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal region command"); - if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; - else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal region command"); + if (strcmp(arg[iarg], "units") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal region command"); + if (strcmp(arg[iarg + 1], "box") == 0) + scaleflag = 0; + else if (strcmp(arg[iarg + 1], "lattice") == 0) + scaleflag = 1; + else + error->all(FLERR, "Illegal region command"); iarg += 2; - } else if (strcmp(arg[iarg],"side") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal region command"); - if (strcmp(arg[iarg+1],"in") == 0) interior = 1; - else if (strcmp(arg[iarg+1],"out") == 0) interior = 0; - else error->all(FLERR,"Illegal region command"); + } else if (strcmp(arg[iarg], "side") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal region command"); + if (strcmp(arg[iarg + 1], "in") == 0) + interior = 1; + else if (strcmp(arg[iarg + 1], "out") == 0) + interior = 0; + else + error->all(FLERR, "Illegal region command"); iarg += 2; - } else if (strcmp(arg[iarg],"move") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal region command"); - if (strcmp(arg[iarg+1],"NULL") != 0) { - if (strstr(arg[iarg+1],"v_") != arg[iarg+1]) - error->all(FLERR,"Illegal region command"); - xstr = utils::strdup(&arg[iarg+1][2]); + } else if (strcmp(arg[iarg], "move") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal region command"); + if (strcmp(arg[iarg + 1], "NULL") != 0) { + if (strstr(arg[iarg + 1], "v_") != arg[iarg + 1]) + error->all(FLERR, "Illegal region command"); + xstr = utils::strdup(&arg[iarg + 1][2]); } - if (strcmp(arg[iarg+2],"NULL") != 0) { - if (strstr(arg[iarg+2],"v_") != arg[iarg+2]) - error->all(FLERR,"Illegal region command"); - ystr = utils::strdup(&arg[iarg+2][2]); + if (strcmp(arg[iarg + 2], "NULL") != 0) { + if (strstr(arg[iarg + 2], "v_") != arg[iarg + 2]) + error->all(FLERR, "Illegal region command"); + ystr = utils::strdup(&arg[iarg + 2][2]); } - if (strcmp(arg[iarg+3],"NULL") != 0) { - if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) - error->all(FLERR,"Illegal region command"); - zstr = utils::strdup(&arg[iarg+3][2]); + if (strcmp(arg[iarg + 3], "NULL") != 0) { + if (strstr(arg[iarg + 3], "v_") != arg[iarg + 3]) + error->all(FLERR, "Illegal region command"); + zstr = utils::strdup(&arg[iarg + 3][2]); } moveflag = 1; iarg += 4; - } else if (strcmp(arg[iarg],"rotate") == 0) { - if (iarg+8 > narg) error->all(FLERR,"Illegal region command"); - if (strstr(arg[iarg+1],"v_") != arg[iarg+1]) - error->all(FLERR,"Illegal region command"); - tstr = utils::strdup(&arg[iarg+1][2]); - point[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - point[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); - point[2] = utils::numeric(FLERR,arg[iarg+4],false,lmp); - axis[0] = utils::numeric(FLERR,arg[iarg+5],false,lmp); - axis[1] = utils::numeric(FLERR,arg[iarg+6],false,lmp); - axis[2] = utils::numeric(FLERR,arg[iarg+7],false,lmp); + } else if (strcmp(arg[iarg], "rotate") == 0) { + if (iarg + 8 > narg) error->all(FLERR, "Illegal region command"); + if (strstr(arg[iarg + 1], "v_") != arg[iarg + 1]) error->all(FLERR, "Illegal region command"); + tstr = utils::strdup(&arg[iarg + 1][2]); + point[0] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + point[1] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + point[2] = utils::numeric(FLERR, arg[iarg + 4], false, lmp); + axis[0] = utils::numeric(FLERR, arg[iarg + 5], false, lmp); + axis[1] = utils::numeric(FLERR, arg[iarg + 6], false, lmp); + axis[2] = utils::numeric(FLERR, arg[iarg + 7], false, lmp); rotateflag = 1; iarg += 8; - } else if (strcmp(arg[iarg],"open") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal region command"); - int iface = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (iface < 1 || iface > 6) error->all(FLERR,"Illegal region command"); + } else if (strcmp(arg[iarg], "open") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal region command"); + int iface = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + if (iface < 1 || iface > 6) error->all(FLERR, "Illegal region command"); // additional checks on valid face index are done by region classes - open_faces[iface-1] = 1; + open_faces[iface - 1] = 1; openflag = 1; iarg += 2; - } - else error->all(FLERR,"Illegal region command"); + } else + error->all(FLERR, "Illegal region command"); } // error check - if ((moveflag || rotateflag) && - (strcmp(style,"union") == 0 || strcmp(style,"intersect") == 0)) - error->all(FLERR,"Region union or intersect cannot be dynamic"); + if ((moveflag || rotateflag) && (strcmp(style, "union") == 0 || strcmp(style, "intersect") == 0)) + error->all(FLERR, "Region union or intersect cannot be dynamic"); // setup scaling @@ -387,8 +390,8 @@ void Region::options(int narg, char **arg) xscale = domain->lattice->xlattice; yscale = domain->lattice->ylattice; zscale = domain->lattice->zlattice; - } - else xscale = yscale = zscale = 1.0; + } else + xscale = yscale = zscale = 1.0; if (rotateflag) { point[0] *= xscale; @@ -399,16 +402,17 @@ void Region::options(int narg, char **arg) // runit = unit vector along rotation axis if (rotateflag) { - double len = sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]); - if (len == 0.0) - error->all(FLERR,"Region cannot have 0 length rotation vector"); - runit[0] = axis[0]/len; - runit[1] = axis[1]/len; - runit[2] = axis[2]/len; + double len = sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]); + if (len == 0.0) error->all(FLERR, "Region cannot have 0 length rotation vector"); + runit[0] = axis[0] / len; + runit[1] = axis[1] / len; + runit[2] = axis[2] / len; } - if (moveflag || rotateflag) dynamic = 1; - else dynamic = 0; + if (moveflag || rotateflag) + dynamic = 1; + else + dynamic = 0; } /* ---------------------------------------------------------------------- @@ -420,14 +424,13 @@ void Region::options(int narg, char **arg) else closest point is between A and B ------------------------------------------------------------------------- */ -void Region::point_on_line_segment(double *a, double *b, - double *c, double *d) +void Region::point_on_line_segment(double *a, double *b, double *c, double *d) { - double ba[3],ca[3]; + double ba[3], ca[3]; - MathExtra::sub3(b,a,ba); - MathExtra::sub3(c,a,ca); - double t = MathExtra::dot3(ca,ba) / MathExtra::dot3(ba,ba); + MathExtra::sub3(b, a, ba); + MathExtra::sub3(c, a, ca); + double t = MathExtra::dot3(ca, ba) / MathExtra::dot3(ba, ba); if (t <= 0.0) { d[0] = a[0]; d[1] = a[1]; @@ -437,9 +440,9 @@ void Region::point_on_line_segment(double *a, double *b, d[1] = b[1]; d[2] = b[2]; } else { - d[0] = a[0] + t*ba[0]; - d[1] = a[1] + t*ba[1]; - d[2] = a[2] + t*ba[2]; + d[0] = a[0] + t * ba[0]; + d[1] = a[1] + t * ba[1]; + d[2] = a[2] + t * ba[2]; } } @@ -460,11 +463,11 @@ void Region::set_velocity() vel_timestep = update->ntimestep; if (moveflag) { if (update->ntimestep > 0) { - v[0] = (dx - prev[0])/update->dt; - v[1] = (dy - prev[1])/update->dt; - v[2] = (dz - prev[2])/update->dt; - } - else v[0] = v[1] = v[2] = 0.0; + v[0] = (dx - prev[0]) / update->dt; + v[1] = (dy - prev[1]) / update->dt; + v[2] = (dz - prev[2]) / update->dt; + } else + v[0] = v[1] = v[2] = 0.0; prev[0] = dx; prev[1] = dy; prev[2] = dz; @@ -475,18 +478,16 @@ void Region::set_velocity() rpoint[1] = point[1] + dy; rpoint[2] = point[2] + dz; if (update->ntimestep > 0) { - double angvel = (theta-prev[3]) / update->dt; - omega[0] = angvel*axis[0]; - omega[1] = angvel*axis[1]; - omega[2] = angvel*axis[2]; - } - else omega[0] = omega[1] = omega[2] = 0.0; + double angvel = (theta - prev[3]) / update->dt; + omega[0] = angvel * axis[0]; + omega[1] = angvel * axis[1]; + omega[2] = angvel * axis[2]; + } else + omega[0] = omega[1] = omega[2] = 0.0; prev[3] = theta; } - if (varshape) { - set_velocity_shape(); - } + if (varshape) { set_velocity_shape(); } } /* ---------------------------------------------------------------------- @@ -511,15 +512,14 @@ void Region::velocity_contact(double *vwall, double *x, int ic) xc[0] = x[0] - contact[ic].delx; xc[1] = x[1] - contact[ic].dely; xc[2] = x[2] - contact[ic].delz; - vwall[0] += omega[1]*(xc[2] - rpoint[2]) - omega[2]*(xc[1] - rpoint[1]); - vwall[1] += omega[2]*(xc[0] - rpoint[0]) - omega[0]*(xc[2] - rpoint[2]); - vwall[2] += omega[0]*(xc[1] - rpoint[1]) - omega[1]*(xc[0] - rpoint[0]); + vwall[0] += omega[1] * (xc[2] - rpoint[2]) - omega[2] * (xc[1] - rpoint[1]); + vwall[1] += omega[2] * (xc[0] - rpoint[0]) - omega[0] * (xc[2] - rpoint[2]); + vwall[2] += omega[0] * (xc[1] - rpoint[1]) - omega[1] * (xc[0] - rpoint[0]); } if (varshape && contact[ic].varflag) velocity_contact_shape(vwall, xc); } - /* ---------------------------------------------------------------------- increment length of restart buffer based on region info used by restart of fix/wall/gran/region @@ -527,9 +527,8 @@ void Region::velocity_contact(double *vwall, double *x, int ic) void Region::length_restart_string(int &n) { - n += sizeof(int) + strlen(id)+1 + - sizeof(int) + strlen(style)+1 + sizeof(int) + - size_restart*sizeof(double); + n += sizeof(int) + strlen(id) + 1 + sizeof(int) + strlen(style) + 1 + sizeof(int) + + size_restart * sizeof(double); } /* ---------------------------------------------------------------------- @@ -539,14 +538,14 @@ void Region::length_restart_string(int &n) void Region::write_restart(FILE *fp) { - int sizeid = (strlen(id)+1); - int sizestyle = (strlen(style)+1); + int sizeid = (strlen(id) + 1); + int sizestyle = (strlen(style) + 1); fwrite(&sizeid, sizeof(int), 1, fp); - fwrite(id,1,sizeid,fp); - fwrite(&sizestyle,sizeof(int),1,fp); - fwrite(style,1,sizestyle,fp); - fwrite(&nregion,sizeof(int),1,fp); - fwrite(prev,sizeof(double),size_restart,fp); + fwrite(id, 1, sizeid, fp); + fwrite(&sizestyle, sizeof(int), 1, fp); + fwrite(style, 1, sizestyle, fp); + fwrite(&nregion, sizeof(int), 1, fp); + fwrite(prev, sizeof(double), size_restart, fp); } /* ---------------------------------------------------------------------- @@ -559,19 +558,19 @@ int Region::restart(char *buf, int &n) { int size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],id) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], id) != 0)) return 0; n += size; size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],style) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], style) != 0)) return 0; n += size; int restart_nreg = *((int *) (&buf[n])); n += sizeof(int); if (restart_nreg != nregion) return 0; - memcpy(prev,&buf[n],size_restart*sizeof(double)); + memcpy(prev, &buf[n], size_restart * sizeof(double)); return 1; } diff --git a/src/region.h b/src/region.h index 83810f5be3..ca1648ed08 100644 --- a/src/region.h +++ b/src/region.h @@ -21,6 +21,7 @@ namespace LAMMPS_NS { class Region : protected Pointers { public: char *id, *style; + Region **reglist; int interior; // 1 for interior, 0 for exterior int scaleflag; // 1 for lattice, 0 for box double xscale, yscale, zscale; // scale factors for box/lattice units @@ -66,7 +67,6 @@ class Region : protected Pointers { // prevents multiple fix/wall/gran/region calls int nregion; // For union and intersect int size_restart; - int *list; Region(class LAMMPS *, int, char **); ~Region() override; diff --git a/src/region_intersect.cpp b/src/region_intersect.cpp index 24b2da5a16..7e6c79b62e 100644 --- a/src/region_intersect.cpp +++ b/src/region_intersect.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -24,36 +23,35 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : - Region(lmp, narg, arg), idsub(nullptr) + Region(lmp, narg, arg), idsub(nullptr) { nregion = 0; - if (narg < 5) error->all(FLERR,"Illegal region command"); - int n = utils::inumeric(FLERR,arg[2],false,lmp); - if (n < 2) error->all(FLERR,"Illegal region command"); - options(narg-(n+3),&arg[n+3]); + if (narg < 5) error->all(FLERR, "Illegal region command"); + int n = utils::inumeric(FLERR, arg[2], false, lmp); + if (n < 2) error->all(FLERR, "Illegal region command"); + options(narg - (n + 3), &arg[n + 3]); // build list of regions to intersect // store sub-region IDs in idsub - idsub = new char*[n]; - list = new int[n]; + idsub = new char *[n]; + reglist = new Region *[n]; nregion = 0; for (int iarg = 0; iarg < n; iarg++) { - idsub[nregion] = utils::strdup(arg[iarg+3]); - int iregion = domain->find_region(idsub[nregion]); - if (iregion == -1) - error->all(FLERR,"Region intersect region ID does not exist"); - list[nregion++] = iregion; + idsub[nregion] = utils::strdup(arg[iarg + 3]); + reglist[nregion] = domain->get_region_by_id(idsub[nregion]); + if (!reglist[nregion]) + error->all(FLERR, "Region intersect region {} does not exist", idsub[nregion]); + nregion++; } // this region is variable shape or dynamic if any of sub-regions are - Region **regions = domain->regions; for (int ilist = 0; ilist < nregion; ilist++) { - if (regions[list[ilist]]->varshape) varshape = 1; - if (regions[list[ilist]]->dynamic) dynamic = 1; + if (reglist[ilist]->varshape) varshape = 1; + if (reglist[ilist]->dynamic) dynamic = 1; } // extent of intersection of regions @@ -61,29 +59,29 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : bboxflag = 0; for (int ilist = 0; ilist < nregion; ilist++) - if (regions[list[ilist]]->bboxflag == 1) bboxflag = 1; + if (reglist[ilist]->bboxflag == 1) bboxflag = 1; if (!interior) bboxflag = 0; if (bboxflag) { int first = 1; for (int ilist = 0; ilist < nregion; ilist++) { - if (regions[list[ilist]]->bboxflag == 0) continue; + if (reglist[ilist]->bboxflag == 0) continue; if (first) { - extent_xlo = regions[list[ilist]]->extent_xlo; - extent_ylo = regions[list[ilist]]->extent_ylo; - extent_zlo = regions[list[ilist]]->extent_zlo; - extent_xhi = regions[list[ilist]]->extent_xhi; - extent_yhi = regions[list[ilist]]->extent_yhi; - extent_zhi = regions[list[ilist]]->extent_zhi; + extent_xlo = reglist[ilist]->extent_xlo; + extent_ylo = reglist[ilist]->extent_ylo; + extent_zlo = reglist[ilist]->extent_zlo; + extent_xhi = reglist[ilist]->extent_xhi; + extent_yhi = reglist[ilist]->extent_yhi; + extent_zhi = reglist[ilist]->extent_zhi; first = 0; } - extent_xlo = MAX(extent_xlo,regions[list[ilist]]->extent_xlo); - extent_ylo = MAX(extent_ylo,regions[list[ilist]]->extent_ylo); - extent_zlo = MAX(extent_zlo,regions[list[ilist]]->extent_zlo); - extent_xhi = MIN(extent_xhi,regions[list[ilist]]->extent_xhi); - extent_yhi = MIN(extent_yhi,regions[list[ilist]]->extent_yhi); - extent_zhi = MIN(extent_zhi,regions[list[ilist]]->extent_zhi); + extent_xlo = MAX(extent_xlo, reglist[ilist]->extent_xlo); + extent_ylo = MAX(extent_ylo, reglist[ilist]->extent_ylo); + extent_zlo = MAX(extent_zlo, reglist[ilist]->extent_zlo); + extent_xhi = MIN(extent_xhi, reglist[ilist]->extent_xhi); + extent_yhi = MIN(extent_yhi, reglist[ilist]->extent_yhi); + extent_zhi = MIN(extent_zhi, reglist[ilist]->extent_zhi); } } @@ -91,14 +89,15 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : // for near contacts and touching contacts cmax = 0; - for (int ilist = 0; ilist < nregion; ilist++) - cmax += regions[list[ilist]]->cmax; + for (int ilist = 0; ilist < nregion; ilist++) cmax += reglist[ilist]->cmax; contact = new Contact[cmax]; tmax = 0; for (int ilist = 0; ilist < nregion; ilist++) { - if (interior) tmax += regions[list[ilist]]->tmax; - else tmax++; + if (interior) + tmax += reglist[ilist]->tmax; + else + tmax++; } } @@ -106,10 +105,10 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : RegIntersect::~RegIntersect() { - for (int ilist = 0; ilist < nregion; ilist++) delete [] idsub[ilist]; - delete [] idsub; - delete [] list; - delete [] contact; + for (int ilist = 0; ilist < nregion; ilist++) delete[] idsub[ilist]; + delete[] idsub; + delete[] reglist; + delete[] contact; } /* ---------------------------------------------------------------------- */ @@ -122,17 +121,14 @@ void RegIntersect::init() // error if a sub-region was deleted for (int ilist = 0; ilist < nregion; ilist++) { - int iregion = domain->find_region(idsub[ilist]); - if (iregion == -1) - error->all(FLERR,"Region union region ID does not exist"); - list[ilist] = iregion; + reglist[ilist] = domain->get_region_by_id(idsub[ilist]); + if (!reglist[ilist]) + error->all(FLERR, "Region intersect region {} does not exist", idsub[ilist]); } // init the sub-regions - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->init(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->init(); } /* ---------------------------------------------------------------------- @@ -143,9 +139,8 @@ void RegIntersect::init() int RegIntersect::inside(double x, double y, double z) { int ilist; - Region **regions = domain->regions; for (ilist = 0; ilist < nregion; ilist++) - if (!regions[list[ilist]]->match(x,y,z)) break; + if (!reglist[ilist]->match(x, y, z)) break; if (ilist == nregion) return 1; return 0; @@ -159,39 +154,36 @@ int RegIntersect::inside(double x, double y, double z) int RegIntersect::surface_interior(double *x, double cutoff) { - int m,ilist,jlist,iregion,jregion,ncontacts; - double xs,ys,zs; + int m, ilist, jlist, ncontacts; + double xs, ys, zs; - Region **regions = domain->regions; int n = 0; - int walloffset = 0; for (ilist = 0; ilist < nregion; ilist++) { - iregion = list[ilist]; - ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff); + auto region = reglist[ilist]; + ncontacts = region->surface(x[0], x[1], x[2], cutoff); for (m = 0; m < ncontacts; m++) { - xs = x[0] - regions[iregion]->contact[m].delx; - ys = x[1] - regions[iregion]->contact[m].dely; - zs = x[2] - regions[iregion]->contact[m].delz; + xs = x[0] - region->contact[m].delx; + ys = x[1] - region->contact[m].dely; + zs = x[2] - region->contact[m].delz; for (jlist = 0; jlist < nregion; jlist++) { if (jlist == ilist) continue; - jregion = list[jlist]; - if (!regions[jregion]->match(xs,ys,zs)) break; + if (!reglist[jlist]->match(xs, ys, zs)) break; } if (jlist == nregion) { - contact[n].r = regions[iregion]->contact[m].r; - contact[n].radius = regions[iregion]->contact[m].radius; - contact[n].delx = regions[iregion]->contact[m].delx; - contact[n].dely = regions[iregion]->contact[m].dely; - contact[n].delz = regions[iregion]->contact[m].delz; - contact[n].iwall = regions[iregion]->contact[m].iwall + walloffset; - contact[n].varflag = regions[iregion]->contact[m].varflag; + contact[n].r = region->contact[m].r; + contact[n].radius = region->contact[m].radius; + contact[n].delx = region->contact[m].delx; + contact[n].dely = region->contact[m].dely; + contact[n].delz = region->contact[m].delz; + contact[n].iwall = region->contact[m].iwall + walloffset; + contact[n].varflag = region->contact[m].varflag; n++; } } // increment by cmax instead of tmax to insure // possible wall IDs for sub-regions are non overlapping - walloffset += regions[iregion]->cmax; + walloffset += region->cmax; } return n; @@ -208,42 +200,37 @@ int RegIntersect::surface_interior(double *x, double cutoff) int RegIntersect::surface_exterior(double *x, double cutoff) { - int m,ilist,jlist,iregion,jregion,ncontacts; - double xs,ys,zs; + int m, ilist, jlist, ncontacts; + double xs, ys, zs; - Region **regions = domain->regions; int n = 0; - - for (ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->interior ^= 1; + for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1; for (ilist = 0; ilist < nregion; ilist++) { - iregion = list[ilist]; - ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff); + auto region = reglist[ilist]; + ncontacts = region->surface(x[0], x[1], x[2], cutoff); for (m = 0; m < ncontacts; m++) { - xs = x[0] - regions[iregion]->contact[m].delx; - ys = x[1] - regions[iregion]->contact[m].dely; - zs = x[2] - regions[iregion]->contact[m].delz; + xs = x[0] - region->contact[m].delx; + ys = x[1] - region->contact[m].dely; + zs = x[2] - region->contact[m].delz; for (jlist = 0; jlist < nregion; jlist++) { if (jlist == ilist) continue; - jregion = list[jlist]; - if (regions[jregion]->match(xs,ys,zs)) break; + if (reglist[jlist]->match(xs, ys, zs)) break; } if (jlist == nregion) { - contact[n].r = regions[iregion]->contact[m].r; - contact[n].radius = regions[iregion]->contact[m].radius; - contact[n].delx = regions[iregion]->contact[m].delx; - contact[n].dely = regions[iregion]->contact[m].dely; - contact[n].delz = regions[iregion]->contact[m].delz; + contact[n].r = region->contact[m].r; + contact[n].radius = region->contact[m].radius; + contact[n].delx = region->contact[m].delx; + contact[n].dely = region->contact[m].dely; + contact[n].delz = region->contact[m].delz; contact[n].iwall = ilist; - contact[n].varflag = regions[iregion]->contact[m].varflag; + contact[n].varflag = region->contact[m].varflag; n++; } } } - for (ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->interior ^= 1; + for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1; return n; } @@ -254,9 +241,7 @@ int RegIntersect::surface_exterior(double *x, double cutoff) void RegIntersect::shape_update() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->shape_update(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->shape_update(); } /* ---------------------------------------------------------------------- @@ -265,21 +250,16 @@ void RegIntersect::shape_update() void RegIntersect::pretransform() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->pretransform(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->pretransform(); } - /* ---------------------------------------------------------------------- get translational/angular velocities of all subregions ------------------------------------------------------------------------- */ void RegIntersect::set_velocity() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->set_velocity(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->set_velocity(); } /* ---------------------------------------------------------------------- @@ -287,13 +267,10 @@ void RegIntersect::set_velocity() used by restart of fix/wall/gran/region ------------------------------------------------------------------------- */ -void RegIntersect::length_restart_string(int& n) +void RegIntersect::length_restart_string(int &n) { - n += sizeof(int) + strlen(id)+1 + - sizeof(int) + strlen(style)+1 + sizeof(int); - for (int ilist = 0; ilist < nregion; ilist++) - domain->regions[list[ilist]]->length_restart_string(n); - + n += sizeof(int) + strlen(id) + 1 + sizeof(int) + strlen(style) + 1 + sizeof(int); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->length_restart_string(n); } /* ---------------------------------------------------------------------- region writes its current position/angle @@ -302,17 +279,15 @@ void RegIntersect::length_restart_string(int& n) void RegIntersect::write_restart(FILE *fp) { - int sizeid = (strlen(id)+1); - int sizestyle = (strlen(style)+1); + int sizeid = (strlen(id) + 1); + int sizestyle = (strlen(style) + 1); fwrite(&sizeid, sizeof(int), 1, fp); fwrite(id, 1, sizeid, fp); fwrite(&sizestyle, sizeof(int), 1, fp); fwrite(style, 1, sizestyle, fp); - fwrite(&nregion,sizeof(int),1,fp); + fwrite(&nregion, sizeof(int), 1, fp); - for (int ilist = 0; ilist < nregion; ilist++) { - domain->regions[list[ilist]]->write_restart(fp); - } + for (int ilist = 0; ilist < nregion; ilist++) { reglist[ilist]->write_restart(fp); } } /* ---------------------------------------------------------------------- @@ -324,12 +299,12 @@ int RegIntersect::restart(char *buf, int &n) { int size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],id) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], id) != 0)) return 0; n += size; size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],style) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], style) != 0)) return 0; n += size; int restart_nreg = *((int *) (&buf[n])); @@ -337,7 +312,7 @@ int RegIntersect::restart(char *buf, int &n) if (restart_nreg != nregion) return 0; for (int ilist = 0; ilist < nregion; ilist++) - if (!domain->regions[list[ilist]]->restart(buf,n)) return 0; + if (!reglist[ilist]->restart(buf, n)) return 0; return 1; } @@ -348,7 +323,5 @@ int RegIntersect::restart(char *buf, int &n) void RegIntersect::reset_vel() { - for (int ilist = 0; ilist < nregion; ilist++) - domain->regions[list[ilist]]->reset_vel(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->reset_vel(); } - diff --git a/src/region_union.cpp b/src/region_union.cpp index b7e0518d75..f4b26ade4d 100644 --- a/src/region_union.cpp +++ b/src/region_union.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -21,42 +20,41 @@ using namespace LAMMPS_NS; -#define BIG 1.0e20 +static constexpr double BIG = 1.0e20; /* ---------------------------------------------------------------------- */ -RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), - idsub(nullptr) +RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), idsub(nullptr) { nregion = 0; - if (narg < 5) error->all(FLERR,"Illegal region command"); - int n = utils::inumeric(FLERR,arg[2],false,lmp); - if (n < 2) error->all(FLERR,"Illegal region command"); - options(narg-(n+3),&arg[n+3]); + + if (narg < 5) error->all(FLERR, "Illegal region command"); + int n = utils::inumeric(FLERR, arg[2], false, lmp); + if (n < 2) error->all(FLERR, "Illegal region command"); + options(narg - (n + 3), &arg[n + 3]); // build list of region indices to union // store sub-region IDs in idsub - idsub = new char*[n]; - list = new int[n]; + idsub = new char *[n]; + reglist = new Region *[n]; nregion = 0; for (int iarg = 0; iarg < n; iarg++) { - idsub[nregion] = utils::strdup(arg[iarg+3]); - int iregion = domain->find_region(idsub[nregion]); - if (iregion == -1) - error->all(FLERR,"Region union region ID does not exist"); - list[nregion++] = iregion; + idsub[nregion] = utils::strdup(arg[iarg + 3]); + reglist[nregion] = domain->get_region_by_id(idsub[nregion]); + if (!reglist[nregion]) + error->all(FLERR, "Region union region {} does not exist", idsub[nregion]); + nregion++; } // this region is variable shape or dynamic if any of sub-regions are - Region **regions = domain->regions; for (int ilist = 0; ilist < nregion; ilist++) { - if (regions[list[ilist]]->varshape) varshape = 1; - if (regions[list[ilist]]->dynamic) dynamic = 1; - if (regions[list[ilist]]->moveflag) moveflag = 1; - if (regions[list[ilist]]->rotateflag) rotateflag = 1; + if (reglist[ilist]->varshape) varshape = 1; + if (reglist[ilist]->dynamic) dynamic = 1; + if (reglist[ilist]->moveflag) moveflag = 1; + if (reglist[ilist]->rotateflag) rotateflag = 1; } // extent of union of regions @@ -64,7 +62,7 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), bboxflag = 1; for (int ilist = 0; ilist < nregion; ilist++) - if (regions[list[ilist]]->bboxflag == 0) bboxflag = 0; + if (reglist[ilist]->bboxflag == 0) bboxflag = 0; if (!interior) bboxflag = 0; if (bboxflag) { @@ -72,12 +70,12 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), extent_xhi = extent_yhi = extent_zhi = -BIG; for (int ilist = 0; ilist < nregion; ilist++) { - extent_xlo = MIN(extent_xlo,regions[list[ilist]]->extent_xlo); - extent_ylo = MIN(extent_ylo,regions[list[ilist]]->extent_ylo); - extent_zlo = MIN(extent_zlo,regions[list[ilist]]->extent_zlo); - extent_xhi = MAX(extent_xhi,regions[list[ilist]]->extent_xhi); - extent_yhi = MAX(extent_yhi,regions[list[ilist]]->extent_yhi); - extent_zhi = MAX(extent_zhi,regions[list[ilist]]->extent_zhi); + extent_xlo = MIN(extent_xlo, reglist[ilist]->extent_xlo); + extent_ylo = MIN(extent_ylo, reglist[ilist]->extent_ylo); + extent_zlo = MIN(extent_zlo, reglist[ilist]->extent_zlo); + extent_xhi = MAX(extent_xhi, reglist[ilist]->extent_xhi); + extent_yhi = MAX(extent_yhi, reglist[ilist]->extent_yhi); + extent_zhi = MAX(extent_zhi, reglist[ilist]->extent_zhi); } } @@ -85,14 +83,15 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), // for near contacts and touching contacts cmax = 0; - for (int ilist = 0; ilist < nregion; ilist++) - cmax += regions[list[ilist]]->cmax; + for (int ilist = 0; ilist < nregion; ilist++) cmax += reglist[ilist]->cmax; contact = new Contact[cmax]; tmax = 0; for (int ilist = 0; ilist < nregion; ilist++) { - if (interior) tmax += regions[list[ilist]]->tmax; - else tmax++; + if (interior) + tmax += reglist[ilist]->tmax; + else + tmax++; } } @@ -100,10 +99,10 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), RegUnion::~RegUnion() { - for (int ilist = 0; ilist < nregion; ilist++) delete [] idsub[ilist]; - delete [] idsub; - delete [] list; - delete [] contact; + for (int ilist = 0; ilist < nregion; ilist++) delete[] idsub[ilist]; + delete[] idsub; + delete[] reglist; + delete[] contact; } /* ---------------------------------------------------------------------- */ @@ -116,17 +115,13 @@ void RegUnion::init() // error if a sub-region was deleted for (int ilist = 0; ilist < nregion; ilist++) { - int iregion = domain->find_region(idsub[ilist]); - if (iregion == -1) - error->all(FLERR,"Region union region ID does not exist"); - list[ilist] = iregion; + reglist[ilist] = domain->get_region_by_id(idsub[ilist]); + if (!reglist[ilist]) error->all(FLERR, "Region union region {} does not exist", idsub[ilist]); } // init the sub-regions - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->init(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->init(); } /* ---------------------------------------------------------------------- @@ -137,9 +132,8 @@ void RegUnion::init() int RegUnion::inside(double x, double y, double z) { int ilist; - Region **regions = domain->regions; for (ilist = 0; ilist < nregion; ilist++) - if (regions[list[ilist]]->match(x,y,z)) break; + if (reglist[ilist]->match(x, y, z)) break; if (ilist == nregion) return 0; return 1; @@ -153,40 +147,36 @@ int RegUnion::inside(double x, double y, double z) int RegUnion::surface_interior(double *x, double cutoff) { - int m,ilist,jlist,iregion,jregion,ncontacts; - double xs,ys,zs; + int m, ilist, jlist, ncontacts; + double xs, ys, zs; - Region **regions = domain->regions; int n = 0; - - int walloffset = 0 ; + int walloffset = 0; for (ilist = 0; ilist < nregion; ilist++) { - iregion = list[ilist]; - ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff); + auto region = reglist[ilist]; + ncontacts = region->surface(x[0], x[1], x[2], cutoff); for (m = 0; m < ncontacts; m++) { - xs = x[0] - regions[iregion]->contact[m].delx; - ys = x[1] - regions[iregion]->contact[m].dely; - zs = x[2] - regions[iregion]->contact[m].delz; + xs = x[0] - region->contact[m].delx; + ys = x[1] - region->contact[m].dely; + zs = x[2] - region->contact[m].delz; for (jlist = 0; jlist < nregion; jlist++) { if (jlist == ilist) continue; - jregion = list[jlist]; - if (regions[jregion]->match(xs,ys,zs) && - !regions[jregion]->openflag) break; + if (reglist[jlist]->match(xs, ys, zs) && !reglist[jlist]->openflag) break; } if (jlist == nregion) { - contact[n].r = regions[iregion]->contact[m].r; - contact[n].radius = regions[iregion]->contact[m].radius; - contact[n].delx = regions[iregion]->contact[m].delx; - contact[n].dely = regions[iregion]->contact[m].dely; - contact[n].delz = regions[iregion]->contact[m].delz; - contact[n].iwall = regions[iregion]->contact[m].iwall + walloffset; - contact[n].varflag = regions[iregion]->contact[m].varflag; + contact[n].r = region->contact[m].r; + contact[n].radius = region->contact[m].radius; + contact[n].delx = region->contact[m].delx; + contact[n].dely = region->contact[m].dely; + contact[n].delz = region->contact[m].delz; + contact[n].iwall = region->contact[m].iwall + walloffset; + contact[n].varflag = region->contact[m].varflag; n++; } } // increment by cmax instead of tmax to insure // possible wall IDs for sub-regions are non overlapping - walloffset += regions[iregion]->cmax; + walloffset += region->cmax; } return n; @@ -203,42 +193,37 @@ int RegUnion::surface_interior(double *x, double cutoff) int RegUnion::surface_exterior(double *x, double cutoff) { - int m,ilist,jlist,iregion,jregion,ncontacts; - double xs,ys,zs; + int m, ilist, jlist, ncontacts; + double xs, ys, zs; - Region **regions = domain->regions; int n = 0; - - for (ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->interior ^= 1; + for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1; for (ilist = 0; ilist < nregion; ilist++) { - iregion = list[ilist]; - ncontacts = regions[iregion]->surface(x[0],x[1],x[2],cutoff); + auto region = reglist[ilist]; + ncontacts = region->surface(x[0], x[1], x[2], cutoff); for (m = 0; m < ncontacts; m++) { - xs = x[0] - regions[iregion]->contact[m].delx; - ys = x[1] - regions[iregion]->contact[m].dely; - zs = x[2] - regions[iregion]->contact[m].delz; + xs = x[0] - region->contact[m].delx; + ys = x[1] - region->contact[m].dely; + zs = x[2] - region->contact[m].delz; for (jlist = 0; jlist < nregion; jlist++) { if (jlist == ilist) continue; - jregion = list[jlist]; - if (!regions[jregion]->match(xs,ys,zs)) break; + if (reglist[jlist]->match(xs, ys, zs)) break; } if (jlist == nregion) { - contact[n].r = regions[iregion]->contact[m].r; - contact[n].radius = regions[iregion]->contact[m].radius; - contact[n].delx = regions[iregion]->contact[m].delx; - contact[n].dely = regions[iregion]->contact[m].dely; - contact[n].delz = regions[iregion]->contact[m].delz; + contact[n].r = region->contact[m].r; + contact[n].radius = region->contact[m].radius; + contact[n].delx = region->contact[m].delx; + contact[n].dely = region->contact[m].dely; + contact[n].delz = region->contact[m].delz; contact[n].iwall = ilist; - contact[n].r = regions[iregion]->contact[m].varflag; + contact[n].varflag = region->contact[m].varflag; n++; } } } - for (ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->interior ^= 1; + for (ilist = 0; ilist < nregion; ilist++) reglist[ilist]->interior ^= 1; return n; } @@ -249,9 +234,7 @@ int RegUnion::surface_exterior(double *x, double cutoff) void RegUnion::shape_update() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->shape_update(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->shape_update(); } /* ---------------------------------------------------------------------- @@ -260,9 +243,7 @@ void RegUnion::shape_update() void RegUnion::pretransform() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->pretransform(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->pretransform(); } /* ---------------------------------------------------------------------- @@ -271,9 +252,7 @@ void RegUnion::pretransform() void RegUnion::set_velocity() { - Region **regions = domain->regions; - for (int ilist = 0; ilist < nregion; ilist++) - regions[list[ilist]]->set_velocity(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->set_velocity(); } /* ---------------------------------------------------------------------- @@ -281,13 +260,10 @@ void RegUnion::set_velocity() used by restart of fix/wall/gran/region ------------------------------------------------------------------------- */ -void RegUnion::length_restart_string(int& n) +void RegUnion::length_restart_string(int &n) { - n += sizeof(int) + strlen(id)+1 + - sizeof(int) + strlen(style)+1 + sizeof(int); - for (int ilist = 0; ilist < nregion; ilist++) - domain->regions[list[ilist]]->length_restart_string(n); - + n += sizeof(int) + strlen(id) + 1 + sizeof(int) + strlen(style) + 1 + sizeof(int); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->length_restart_string(n); } /* ---------------------------------------------------------------------- region writes its current position/angle @@ -296,15 +272,14 @@ void RegUnion::length_restart_string(int& n) void RegUnion::write_restart(FILE *fp) { - int sizeid = (strlen(id)+1); - int sizestyle = (strlen(style)+1); + int sizeid = (strlen(id) + 1); + int sizestyle = (strlen(style) + 1); fwrite(&sizeid, sizeof(int), 1, fp); fwrite(id, 1, sizeid, fp); fwrite(&sizestyle, sizeof(int), 1, fp); fwrite(style, 1, sizestyle, fp); - fwrite(&nregion,sizeof(int),1,fp); - for (int ilist = 0; ilist < nregion; ilist++) - domain->regions[list[ilist]]->write_restart(fp); + fwrite(&nregion, sizeof(int), 1, fp); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->write_restart(fp); } /* ---------------------------------------------------------------------- @@ -316,12 +291,12 @@ int RegUnion::restart(char *buf, int &n) { int size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],id) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], id) != 0)) return 0; n += size; size = *((int *) (&buf[n])); n += sizeof(int); - if ((size <= 0) || (strcmp(&buf[n],style) != 0)) return 0; + if ((size <= 0) || (strcmp(&buf[n], style) != 0)) return 0; n += size; int restart_nreg = *((int *) (&buf[n])); @@ -329,7 +304,7 @@ int RegUnion::restart(char *buf, int &n) if (restart_nreg != nregion) return 0; for (int ilist = 0; ilist < nregion; ilist++) - if (!domain->regions[list[ilist]]->restart(buf,n)) return 0; + if (!reglist[ilist]->restart(buf, n)) return 0; return 1; } @@ -340,6 +315,5 @@ int RegUnion::restart(char *buf, int &n) void RegUnion::reset_vel() { - for (int ilist = 0; ilist < nregion; ilist++) - domain->regions[list[ilist]]->reset_vel(); + for (int ilist = 0; ilist < nregion; ilist++) reglist[ilist]->reset_vel(); } diff --git a/src/respa.cpp b/src/respa.cpp index 97356eac47..9aca8a9427 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -121,7 +121,7 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : // the hybrid keyword requires a hybrid pair style if (!utils::strmatch(force->pair_style, "^hybrid")) error->all(FLERR, "Illegal run_style respa command"); - auto hybrid = dynamic_cast( force->pair); + auto hybrid = dynamic_cast(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"); @@ -296,7 +296,7 @@ void Respa::init() std::string cmd = fmt::format("RESPA all RESPA {}", nlevels); if (atom->torque_flag) cmd += " torque"; - fix_respa = dynamic_cast( modify->add_fix(cmd)); + fix_respa = dynamic_cast(modify->add_fix(cmd)); // insure respa inner/middle/outer is using Pair class that supports it diff --git a/src/text_file_reader.h b/src/text_file_reader.h index 017a721e67..e96387d423 100644 --- a/src/text_file_reader.h +++ b/src/text_file_reader.h @@ -18,7 +18,7 @@ #ifndef LMP_TEXT_FILE_READER_H #define LMP_TEXT_FILE_READER_H -#include "tokenizer.h" // IWYU pragma: export +#include "tokenizer.h" // IWYU pragma: export #include diff --git a/src/thermo.cpp b/src/thermo.cpp index a7d76017f8..0a810662ca 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -637,7 +637,7 @@ void Thermo::modify_params(int narg, char **arg) if (iarg + 3 > narg) error->all(FLERR, "Illegal thermo_modify command"); int icol = -1; if (utils::is_integer(arg[iarg + 1])) { - icol = utils::inumeric(FLERR,arg[iarg + 1],false,lmp); + icol = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); if (icol < 0) icol = nfield_initial + icol + 1; icol--; } else { @@ -647,8 +647,9 @@ void Thermo::modify_params(int narg, char **arg) icol = -1; } } - if ((icol < 0) || (icol >= nfield_initial)) error->all(FLERR, "Illegal thermo_modify command"); - keyword_user[icol] = arg[iarg+2]; + if ((icol < 0) || (icol >= nfield_initial)) + error->all(FLERR, "Illegal thermo_modify command"); + keyword_user[icol] = arg[iarg + 2]; iarg += 3; } } else if (strcmp(arg[iarg], "format") == 0) { @@ -675,7 +676,8 @@ void Thermo::modify_params(int narg, char **arg) found = format_int_user.find('d', found); if (found == std::string::npos) error->all(FLERR, "Thermo_modify int format does not contain a d conversion character"); - format_bigint_user = format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); + format_bigint_user = + format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); } else if (strcmp(arg[iarg + 1], "float") == 0) { format_float_user = arg[iarg + 2]; } else { @@ -691,7 +693,8 @@ void Thermo::modify_params(int narg, char **arg) icol = -1; } } - if (icol < 0 || icol >= nfield_initial + 1) error->all(FLERR, "Illegal thermo_modify command"); + if (icol < 0 || icol >= nfield_initial + 1) + error->all(FLERR, "Illegal thermo_modify command"); format_column_user[icol] = arg[iarg + 2]; } iarg += 3; @@ -746,9 +749,7 @@ void Thermo::allocate() int i = 0; key2col.clear(); - for (auto item : utils::split_words(line)) { - key2col[item] = i++; - } + for (auto item : utils::split_words(line)) { key2col[item] = i++; } } /* ---------------------------------------------------------------------- diff --git a/src/utils.cpp b/src/utils.cpp index a8e1b14104..91804055fd 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -22,8 +22,8 @@ #include "memory.h" #include "modify.h" #include "text_file_reader.h" -#include "update.h" #include "universe.h" +#include "update.h" #include #include @@ -141,7 +141,7 @@ void utils::flush_buffers(LAMMPS *lmp) { if (lmp->screen) fflush(lmp->screen); if (lmp->logfile) fflush(lmp->logfile); - if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); + if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile); } @@ -805,7 +805,7 @@ std::string utils::star_subst(const std::string &name, bigint step, int pad) auto star = name.find('*'); if (star == std::string::npos) return name; - return fmt::format("{}{:0{}}{}",name.substr(0,star),step,pad,name.substr(star+1)); + return fmt::format("{}{:0{}}{}", name.substr(0, star), step, pad, name.substr(star + 1)); } /* ---------------------------------------------------------------------- diff --git a/src/utils.h b/src/utils.h index 86f31508e7..fc39eef3c0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,7 +21,7 @@ #include -#include // IWYU pragma: export +#include // IWYU pragma: export namespace LAMMPS_NS { diff --git a/src/write_coeff.cpp b/src/write_coeff.cpp index 4a46f4c2db..f71cab0fdd 100644 --- a/src/write_coeff.cpp +++ b/src/write_coeff.cpp @@ -102,8 +102,8 @@ void WriteCoeff::command(int narg, char **arg) coeff_mode = CLASS2_MODE; } - const char * section = (const char *) ""; // NOLINT - fputs(str, two); // style + const char *section = (const char *) ""; // NOLINT + fputs(str, two); // style utils::sfgets(FLERR, str, BUF_SIZE, one, file, error); // coeff int n = strlen(str); strncpy(coeff, str, BUF_SIZE);