diff --git a/doc/src/Howto_bpm.rst b/doc/src/Howto_bpm.rst index 8da6511213..2f015162e0 100644 --- a/doc/src/Howto_bpm.rst +++ b/doc/src/Howto_bpm.rst @@ -3,7 +3,6 @@ Bonded particle models The BPM package implements bonded particle models which can be used to simulate mesoscale solids. Solids are constructed as a collection of - particles which each represent a coarse-grained region of space much larger than the atomistic scale. Particles within a solid region are then connected by a network of bonds to provide solid elasticity. @@ -47,33 +46,29 @@ this, LAMMPS requires :doc:`newton ` bond off such that all processors containing an atom know when a bond breaks. Additionally, one must do either (A) or (B). -(A) +A) Use the following special bond settings -Use the following special bond settings + .. code-block:: LAMMPS -.. code-block:: LAMMPS + special_bonds lj 0 1 1 coul 1 1 1 - special_bonds lj 0 1 1 coul 1 1 1 + These settings accomplish two goals. First, they turn off 1-3 and 1-4 + special bond lists, which are not currently supported for BPMs. As + BPMs often have dense bond networks, generating 1-3 and 1-4 special + bond lists is expensive. By setting the lj weight for 1-2 bonds to + zero, this turns off pairwise interactions. Even though there are no + charges in BPM models, setting a nonzero coul weight for 1-2 bonds + ensures all bonded neighbors are still included in the neighbor list + in case bonds break between neighbor list builds. -These settings accomplish two goals. First, they turn off 1-3 and 1-4 -special bond lists, which are not currently supported for BPMs. As -BPMs often have dense bond networks, generating 1-3 and 1-4 special -bond lists is expensive. By setting the lj weight for 1-2 bonds to -zero, this turns off pairwise interactions. Even though there are no -charges in BPM models, setting a nonzero coul weight for 1-2 bonds -ensures all bonded neighbors are still included in the neighbor list -in case bonds break between neighbor list builds. +B) Alternatively, one can simply overlay pair interactions such that all + bonded particles also feel pair interactions. This can be + accomplished by using the *overlay/pair* keyword present in all bpm + bond styles and by using the following special bond settings -(B) + .. code-block:: LAMMPS -Alternatively, one can simply overlay pair interactions such that all -bonded particles also feel pair interactions. This can be accomplished -by using the *overlay/pair* keyword present in all bpm bond styles and -by using the following special bond settings - -.. code-block:: LAMMPS - - special_bonds lj/coul 1 1 1 + special_bonds lj/coul 1 1 1 See the :doc:`Howto ` page on broken bonds for more information. diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 1276adf444..625a5b01d0 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -305,7 +305,7 @@ with fix_adapt are +------------------------------------+-------+-----------------+ | :doc:`fene ` | k,r0 | type bonds | +------------------------------------+-------+-----------------+ -| :doc:`fene/nm ` | k,r0 | type bonds | +| :doc:`fene/nm ` | k,r0 | type bonds | +------------------------------------+-------+-----------------+ | :doc:`gromos ` | k,r0 | type bonds | +------------------------------------+-------+-----------------+ diff --git a/doc/src/fix_nve.rst b/doc/src/fix_nve.rst index dc17f844cd..c50bc4d62f 100644 --- a/doc/src/fix_nve.rst +++ b/doc/src/fix_nve.rst @@ -36,7 +36,7 @@ are (full) periodic boundary conditions and no other "manipulations" of the system (e.g. fixes that modify forces or velocities). This fix invokes the velocity form of the -Störmer-Verlet time integration algorithm (velocity-Verlet). Other +Stoermer-Verlet time integration algorithm (velocity-Verlet). Other time integration options can be invoked using the :doc:`run_style ` command. ---------- diff --git a/doc/src/run_style.rst b/doc/src/run_style.rst index 8becbec671..e8ba264495 100644 --- a/doc/src/run_style.rst +++ b/doc/src/run_style.rst @@ -68,7 +68,7 @@ Choose the style of time integrator used for molecular dynamics simulations performed by LAMMPS. The *verlet* style is the velocity form of the -Störmer-Verlet time integration algorithm (velocity-Verlet) +Stoermer-Verlet time integration algorithm (velocity-Verlet) ---------- diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index ee183a5877..62983f4f39 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -315,6 +315,7 @@ borophene Botero Botu Bouguet +Bourasseau Bourne boxcolor boxhi @@ -342,6 +343,7 @@ Broglie brownian brownw Broyden +Brusselle Bryantsev Btarget btype @@ -674,6 +676,7 @@ Deresiewicz Derjagin Derjaguin Derlet +Desbiens Deserno Destree destructor @@ -787,6 +790,7 @@ Dullweber dumpfile Dunbrack Dunweg +Dupend Dupont dUs dV @@ -1669,6 +1673,7 @@ Kusters Kutta Kuznetsov kx +Lachet Lackmann Ladd lagrangian @@ -3188,6 +3193,7 @@ stochastically stochasticity Stockmayer Stoddard +Stoermer stoichiometric stoichiometry Stokesian @@ -3665,6 +3671,7 @@ Wittmaack wn Wolde workflow +workflows Workum Worley Wriggers diff --git a/lib/atc/LammpsInterface.cpp b/lib/atc/LammpsInterface.cpp index 8f7d20361c..9e2df3e46c 100644 --- a/lib/atc/LammpsInterface.cpp +++ b/lib/atc/LammpsInterface.cpp @@ -387,7 +387,7 @@ double LammpsInterface::atom_quantity_conversion(FundamentalAtomQuantity quantit int LammpsInterface::dimension() const { return lammps_->domain->dimension; } -int LammpsInterface::nregion() const { return lammps_->domain->nregion; } +int LammpsInterface::nregion() const { return lammps_->domain->get_region_list().size(); } void LammpsInterface::box_bounds(double & boxxlo, double & boxxhi, double & boxylo, double & boxyhi, @@ -527,14 +527,15 @@ void LammpsInterface::box_periodicity(int & xperiodic, zperiodic = lammps_->domain->zperiodic; } -int LammpsInterface::region_id(const char * regionName) const { - int nregion = this->nregion(); - for (int iregion = 0; iregion < nregion; iregion++) { - if (strcmp(regionName, region_name(iregion)) == 0) { +int LammpsInterface::region_id(const char *regionName) const { + auto regions = lammps_->domain->get_region_list(); + int iregion = 0; + for (auto reg : regions) { + if (strcmp(regionName, reg->id) == 0) { return iregion; } + ++iregion; } - throw ATC_Error("Region has not been defined"); return -1; } @@ -1322,61 +1323,73 @@ int** LammpsInterface::bond_list() const { return lammps_->neighbor->bondlist; char * LammpsInterface::region_name(int iRegion) const { - return lammps_->domain->regions[iRegion]->id; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->id; } char * LammpsInterface::region_style(int iRegion) const { - return lammps_->domain->regions[iRegion]->style; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->style; } double LammpsInterface::region_xlo(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_xlo; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_xlo; } double LammpsInterface::region_xhi(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_xhi; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_xhi; } double LammpsInterface::region_ylo(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_ylo; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_ylo; } double LammpsInterface::region_yhi(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_yhi; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_yhi; } double LammpsInterface::region_zlo(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_zlo; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_zlo; } double LammpsInterface::region_zhi(int iRegion) const { - return lammps_->domain->regions[iRegion]->extent_zhi; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->extent_zhi; } double LammpsInterface::region_xscale(int iRegion) const { - return lammps_->domain->regions[iRegion]->xscale; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->xscale; } double LammpsInterface::region_yscale(int iRegion) const { - return lammps_->domain->regions[iRegion]->yscale; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->yscale; } double LammpsInterface::region_zscale(int iRegion) const { - return lammps_->domain->regions[iRegion]->zscale; + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->zscale; } int LammpsInterface::region_match(int iRegion, double x, double y, double z) const { - return lammps_->domain->regions[iRegion]->match(x,y,z); + auto regions = lammps_->domain->get_region_list(); + return regions[iRegion]->match(x,y,z); } // ----------------------------------------------------------------- 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..0ffe612f2c 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->get_region_by_id(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/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/EFF/compute_temp_region_eff.cpp b/src/EFF/compute_temp_region_eff.cpp index 3b5147b900..de61abc4b7 100644 --- a/src/EFF/compute_temp_region_eff.cpp +++ b/src/EFF/compute_temp_region_eff.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -16,7 +15,6 @@ Contributing author: Andres Jaramillo-Botero (Caltech) ------------------------------------------------------------------------- */ - #include "compute_temp_region_eff.h" #include "atom.h" @@ -33,16 +31,15 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeTempRegionEff::ComputeTempRegionEff(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg) + Compute(lmp, narg, arg), region(nullptr), idregion(nullptr) { if (!atom->electron_flag) - error->all(FLERR,"Compute temp/region/eff requires atom style electron"); + error->all(FLERR, "Compute temp/region/eff requires atom style electron"); - if (narg != 4) error->all(FLERR,"Illegal compute temp/region/eff command"); + if (narg != 4) error->all(FLERR, "Illegal compute temp/region/eff command"); - iregion = domain->find_region(arg[3]); - if (iregion == -1) - error->all(FLERR,"Region ID for compute temp/region/eff does not exist"); + region = domain->get_region_by_id(arg[3]); + if (!region) error->all(FLERR, "Region {} for compute temp/region/eff does not exist", arg[3]); idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; @@ -61,9 +58,9 @@ ComputeTempRegionEff::ComputeTempRegionEff(LAMMPS *lmp, int narg, char **arg) : ComputeTempRegionEff::~ComputeTempRegionEff() { - delete [] idregion; + delete[] idregion; memory->destroy(vbiasall); - delete [] vector; + delete[] vector; } /* ---------------------------------------------------------------------- */ @@ -72,9 +69,8 @@ void ComputeTempRegionEff::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/eff does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for compute temp/region/eff does not exist", idregion); } /* ---------------------------------------------------------------------- */ @@ -90,7 +86,7 @@ void ComputeTempRegionEff::setup() void ComputeTempRegionEff::dof_remove_pre() { - domain->regions[iregion]->prematch(); + region->prematch(); } /* ---------------------------------------------------------------------- */ @@ -98,7 +94,7 @@ void ComputeTempRegionEff::dof_remove_pre() int ComputeTempRegionEff::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; } @@ -116,9 +112,8 @@ double ComputeTempRegionEff::compute_scalar() int *type = atom->type; int *mask = atom->mask; int nlocal = atom->nlocal; - double mefactor = domain->dimension/4.0; + double mefactor = domain->dimension / 4.0; - Region *region = domain->regions[iregion]; region->prematch(); int count = 0; @@ -127,34 +122,35 @@ double ComputeTempRegionEff::compute_scalar() if (mass) { 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]]; - if (abs(spin[i])==1) { - t += mefactor*mass[type[i]]*ervel[i]*ervel[i]; + t += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * mass[type[i]]; + if (abs(spin[i]) == 1) { + t += mefactor * mass[type[i]] * ervel[i] * ervel[i]; ecount++; } } } - double tarray[2],tarray_all[2]; + double tarray[2], tarray_all[2]; // Assume 3/2 k T per nucleus - tarray[0] = count-ecount; + tarray[0] = count - ecount; 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"); + error->all(FLERR, "Temperature compute degrees of freedom < 0"); int one = 0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - if (abs(spin[i])==1) one++; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + if (abs(spin[i]) == 1) one++; } - if (dof > 0.0) scalar = force->mvv2e * tarray_all[1] / (dof * force->boltz); - else scalar = 0.0; + if (dof > 0.0) + scalar = force->mvv2e * tarray_all[1] / (dof * force->boltz); + else + scalar = 0.0; return scalar; } @@ -174,33 +170,32 @@ void ComputeTempRegionEff::compute_vector() int *type = atom->type; int *mask = atom->mask; int nlocal = atom->nlocal; - double mefactor = domain->dimension/4.0; + double mefactor = domain->dimension / 4.0; - 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 (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { 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]; + 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 (abs(spin[i])==1) { - t[0] += mefactor * massone * ervel[i]*ervel[i]; - t[1] += mefactor * massone * ervel[i]*ervel[i]; - t[2] += mefactor * massone * ervel[i]*ervel[i]; + if (abs(spin[i]) == 1) { + t[0] += mefactor * massone * ervel[i] * ervel[i]; + t[1] += mefactor * massone * ervel[i] * ervel[i]; + t[2] += mefactor * massone * ervel[i] * ervel[i]; } } - 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; } @@ -212,7 +207,7 @@ void ComputeTempRegionEff::compute_vector() void ComputeTempRegionEff::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]; @@ -236,14 +231,12 @@ void ComputeTempRegionEff::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]; @@ -289,6 +282,6 @@ void ComputeTempRegionEff::restore_bias_all() double ComputeTempRegionEff::memory_usage() { - double bytes = (double)maxbias * sizeof(double); + double bytes = (double) maxbias * sizeof(double); return bytes; } diff --git a/src/EFF/compute_temp_region_eff.h b/src/EFF/compute_temp_region_eff.h index bc8f930374..a3dd7e5dd4 100644 --- a/src/EFF/compute_temp_region_eff.h +++ b/src/EFF/compute_temp_region_eff.h @@ -42,7 +42,7 @@ class ComputeTempRegionEff : public Compute { double memory_usage() override; protected: - int iregion; + class Region *region; char *idregion; }; 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..14556d810f 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,13 +37,13 @@ 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 diff --git a/src/EXTRA-COMPUTE/compute_born_matrix.cpp b/src/EXTRA-COMPUTE/compute_born_matrix.cpp index cbcc077129..f62c11d241 100644 --- a/src/EXTRA-COMPUTE/compute_born_matrix.cpp +++ b/src/EXTRA-COMPUTE/compute_born_matrix.cpp @@ -354,7 +354,6 @@ void ComputeBornMatrix::compute_vector() if (angleflag) compute_angles(); if (dihedflag) compute_dihedrals(); - // sum Born contributions over all procs MPI_Allreduce(values_local, values_global, nvalues, MPI_DOUBLE, MPI_SUM, world); @@ -373,7 +372,6 @@ void ComputeBornMatrix::compute_vector() } for (int m = 0; m < nvalues; m++) vector[m] = values_global[m]; - } /* ---------------------------------------------------------------------- @@ -390,10 +388,8 @@ void ComputeBornMatrix::compute_pairs() int *type = atom->type; int *mask = atom->mask; - int nlocal = atom->nlocal; double *special_coul = force->special_coul; double *special_lj = force->special_lj; - int newton_pair = force->newton_pair; // invoke half neighbor list (will copy or build if necessary) neighbor->build_one(list); @@ -412,7 +408,6 @@ void ComputeBornMatrix::compute_pairs() int a, b, c, d; double xi1, xi2, xi3; - double fi1, fi2, fi3; double xj1, xj2, xj3; double rij[3]; double pair_pref; @@ -454,7 +449,7 @@ void ComputeBornMatrix::compute_pairs() pair_pref = dupair = du2pair = 0.0; pair->born_matrix(i, j, itype, jtype, rsq, factor_coul, factor_lj, dupair, du2pair); - pair_pref = 0.5*du2pair - dupair * rinv; + pair_pref = 0.5 * du2pair - dupair * rinv; // See albemunu in compute_born_matrix.h for indices order. @@ -476,7 +471,6 @@ void ComputeBornMatrix::compute_pairs() void ComputeBornMatrix::compute_numdiff() { - double energy; int vec_index; // grow arrays if necessary @@ -498,8 +492,6 @@ void ComputeBornMatrix::compute_numdiff() // loop over 6 strain directions // compute stress finite difference in each direction - int flag, allflag; - for (int idir = 0; idir < NDIR_VIRIAL; idir++) { // forward @@ -528,8 +520,7 @@ void ComputeBornMatrix::compute_numdiff() // apply derivative factor double denominator = -0.5 / numdelta; - for (int m = 0; m < nvalues; m++) - values_global[m] *= denominator; + for (int m = 0; m < nvalues; m++) values_global[m] *= denominator; // recompute virial so all virial and energy contributions are as before // also needed for virial stress addon contributions to Born matrix @@ -633,11 +624,7 @@ void ComputeBornMatrix::update_virial() void ComputeBornMatrix::virial_addon() { - - int kd, nd, id, jd; - int m; - - double* sigv = compute_virial->vector; + double *sigv = compute_virial->vector; // This way of doing is not very elegant but is correct. // The complete Cijkl terms are the sum of symmetric terms @@ -678,7 +665,6 @@ void ComputeBornMatrix::virial_addon() values_global[18] += 0.5 * sigv[3]; values_global[19] += 0.5 * sigv[4]; values_global[20] += 0.5 * sigv[5]; - } /* ---------------------------------------------------------------------- @@ -727,13 +713,11 @@ double ComputeBornMatrix::memory_usage() void ComputeBornMatrix::compute_bonds() { - int i, m, n, nb, atom1, atom2, imol, iatom, btype, ivar; + int i, m, nb, atom1, atom2, imol, iatom, btype; tagint tagprev; double dx, dy, dz, rsq; double **x = atom->x; - double **v = atom->v; - int *type = atom->type; tagint *tag = atom->tag; int *num_bond = atom->num_bond; tagint **bond_atom = atom->bond_atom; @@ -821,13 +805,12 @@ void ComputeBornMatrix::compute_bonds() void ComputeBornMatrix::compute_angles() { - int i, m, n, na, atom1, atom2, atom3, imol, iatom, atype, ivar; + int i, m, na, atom1, atom2, atom3, imol, iatom, atype; tagint tagprev; double delx1, dely1, delz1, delx2, dely2, delz2; double rsq1, rsq2, r1, r2, cost; double r1r2, r1r2inv; double rsq1inv, rsq2inv, cinv; - double *ptr; double **x = atom->x; tagint *tag = atom->tag; @@ -920,18 +903,18 @@ void ComputeBornMatrix::compute_angles() // Worst case scenario. A 0 cosine has an undefined logarithm. // We then add a small amount of the third bond to the first one // so they are not orthogonal anymore and recompute. - del1[0] += SMALL*del2[0]; - del1[1] += SMALL*del2[1]; - del1[2] += SMALL*del2[2]; + del1[0] += SMALL * del2[0]; + del1[1] += SMALL * del2[1]; + del1[2] += SMALL * del2[2]; r1r2 = del1[0] * del2[0] + del1[1] * del2[1] + del1[2] * del2[2]; - r1r2inv = 1/r1r2; + r1r2inv = 1 / r1r2; // cost = cosine of angle - cost = r1r2/(r1 * r2); + cost = r1r2 / (r1 * r2); } else { - r1r2inv = 1/r1r2; - cost = r1r2/(r1 * r2); + r1r2inv = 1 / r1r2; + cost = r1r2 / (r1 * r2); } if (cost > 1.0) cost = 1.0; @@ -986,12 +969,11 @@ void ComputeBornMatrix::compute_angles() void ComputeBornMatrix::compute_dihedrals() { - int i, m, n, nd, atom1, atom2, atom3, atom4, imol, iatom, dtype, ivar; + int i, m, nd, atom1, atom2, atom3, atom4, imol, iatom; tagint tagprev; - double vb1x, vb1y, vb1z, vb2x, vb2y, vb2z, vb3x, vb3y, vb3z, vb2xm, vb2ym, vb2zm; - double ax, ay, az, bx, by, bz, rasq, rbsq, dotab, rgsq, rg, ra2inv, rb2inv, dotabinv, rabinv; - double si, co, phi; - double *ptr; + double vb1x, vb1y, vb1z, vb2x, vb2y, vb2z, vb3x, vb3y, vb3z; + double ax, ay, az, bx, by, bz, rasq, rbsq, dotab, ra2inv, rb2inv, dotabinv, rabinv; + double co; double **x = atom->x; tagint *tag = atom->tag; @@ -1013,28 +995,15 @@ void ComputeBornMatrix::compute_dihedrals() Dihedral *dihedral = force->dihedral; - double dudih, du2dih; int al, be, mu, nu, e, f; - double b1sq; - double b2sq; - double b3sq; - double b1b2; - double b1b3; - double b2b3; - double b1[3]; - double b2[3]; - double b3[3]; + double dudih, du2dih, b1sq, b2sq, b3sq, b1b2, b1b3, b2b3; + double b1[3], b2[3], b3[3]; // 1st and 2nd order derivatives of the dot products - double dab[6]; - double daa[6]; - double dbb[6]; - double d2ab; - double d2aa; - double d2bb; + double dab[6], daa[6], dbb[6]; + double d2ab, d2aa, d2bb; - double dcos[6]; - double d2cos; + double dcos[6], d2cos; for (i = 0; i < 6; i++) dab[i] = daa[i] = dbb[i] = dcos[i] = 0; @@ -1043,7 +1012,8 @@ void ComputeBornMatrix::compute_dihedrals() // if (molecular == 1) // nd = num_dihedral[atom2]; - if (molecular == Atom::MOLECULAR) nd = num_dihedral[atom2]; + if (molecular == Atom::MOLECULAR) + nd = num_dihedral[atom2]; else { if (molindex[atom2] < 0) continue; imol = molindex[atom2]; @@ -1120,26 +1090,23 @@ void ComputeBornMatrix::compute_dihedrals() rasq = ax * ax + ay * ay + az * az; rbsq = bx * bx + by * by + bz * bz; - rgsq = vb2x * vb2x + vb2y * vb2y + vb2z * vb2z; - dotab = ax*bx + ay*by + az*bz; - rg = sqrt(rgsq); + dotab = ax * bx + ay * by + az * bz; ra2inv = rb2inv = rabinv = dotabinv = 0.0; if (rasq > 0) ra2inv = 1.0 / rasq; if (rbsq > 0) rb2inv = 1.0 / rbsq; - if (dotab != 0.) dotabinv = 1.0/dotab; + if (dotab != 0.) dotabinv = 1.0 / dotab; rabinv = sqrt(ra2inv * rb2inv); co = (ax * bx + ay * by + az * bz) * rabinv; - si = sqrt(b2sq) * rabinv * (ax * vb3x + ay * vb3y + az * vb3z); - if (co == 0.) { + if (co == 0.0) { // Worst case scenario. A 0 cosine has an undefined logarithm. // We then add a small amount of the third bond to the first one // so they are not orthogonal anymore and recompute. - b1[0] += SMALL*b3[0]; - b1[1] += SMALL*b3[1]; - b1[2] += SMALL*b3[2]; + b1[0] += SMALL * b3[0]; + b1[1] += SMALL * b3[1]; + b1[2] += SMALL * b3[2]; b1sq = b1[0] * b1[0] + b1[1] * b1[1] + b1[2] * b1[2]; b3sq = b3[0] * b3[0] + b3[1] * b3[1] + b3[2] * b3[2]; b1b2 = b1[0] * b2[0] + b1[1] * b2[1] + b1[2] * b2[2]; @@ -1153,20 +1120,17 @@ void ComputeBornMatrix::compute_dihedrals() bz = b2[0] * b3[1] - b2[1] * b3[0]; rasq = ax * ax + ay * ay + az * az; rbsq = bx * bx + by * by + bz * bz; - dotab = ax*bx + ay*by + az*bz; + dotab = ax * bx + ay * by + az * bz; ra2inv = rb2inv = rabinv = dotabinv = 0.0; if (rasq > 0) ra2inv = 1.0 / rasq; if (rbsq > 0) rb2inv = 1.0 / rbsq; - if (dotab != 0.) dotabinv = 1.0/dotab; + if (dotab != 0.) dotabinv = 1.0 / dotab; rabinv = sqrt(ra2inv * rb2inv); co = (ax * bx + ay * by + az * bz) * rabinv; - si = sqrt(b2sq) * rabinv * (ax * vb3x + ay * vb3y + az * vb3z); } if (co > 1.0) co = 1.0; if (co < -1.0) co = -1.0; - phi = atan2(si, co); - al = be = mu = nu = e = f = 0; // clang-format off for (m = 0; m<6; m++) { 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_electron_stopping.cpp b/src/EXTRA-FIX/fix_electron_stopping.cpp index a61cedcf27..e9cc501744 100644 --- a/src/EXTRA-FIX/fix_electron_stopping.cpp +++ b/src/EXTRA-FIX/fix_electron_stopping.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -39,63 +38,53 @@ using namespace LAMMPS_NS; using namespace FixConst; -#define MAXLINE 1024 - /* ---------------------------------------------------------------------- */ FixElectronStopping::FixElectronStopping(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg) + Fix(lmp, narg, arg), elstop_ranges(nullptr), idregion(nullptr), region(nullptr), list(nullptr) { - scalar_flag = 1; // Has compute_scalar - global_freq = 1; // SeLoss computed every step - extscalar = 0; // SeLoss compute_scalar is intensive - nevery = 1; // Run fix every step - + scalar_flag = 1; // Has compute_scalar + global_freq = 1; // SeLoss computed every step + extscalar = 0; // SeLoss compute_scalar is intensive + nevery = 1; // Run fix every step // args: 0 = fix ID, 1 = group ID, 2 = "electron/stopping" // 3 = Ecut, 4 = file path // optional rest: "region" // "minneigh" - if (narg < 5) error->all(FLERR, - "Illegal fix electron/stopping command: too few arguments"); + if (narg < 5) error->all(FLERR, "Illegal fix electron/stopping command: too few arguments"); - Ecut = utils::numeric(FLERR, arg[3],false,lmp); - if (Ecut <= 0.0) error->all(FLERR, - "Illegal fix electron/stopping command: Ecut <= 0"); + Ecut = utils::numeric(FLERR, arg[3], false, lmp); + if (Ecut <= 0.0) error->all(FLERR, "Illegal fix electron/stopping command: Ecut <= 0"); int iarg = 5; - iregion = -1; minneigh = 1; bool minneighflag = false; while (iarg < narg) { if (strcmp(arg[iarg], "region") == 0) { - if (iregion >= 0) error->all(FLERR, - "Illegal fix electron/stopping command: region given twice"); - if (iarg+2 > narg) error->all(FLERR, - "Illegal fix electron/stopping command: region name missing"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion < 0) error->all(FLERR, - "Region ID for fix electron/stopping does not exist"); + if (region) error->all(FLERR, "Illegal fix electron/stopping command: region given twice"); + if (iarg + 2 > narg) + error->all(FLERR, "Illegal fix electron/stopping command: region name missing"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) + error->all(FLERR, "Region {} for fix electron/stopping does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } - else if (strcmp(arg[iarg], "minneigh") == 0) { - if (minneighflag) error->all(FLERR, - "Illegal fix electron/stopping command: minneigh given twice"); + } else if (strcmp(arg[iarg], "minneigh") == 0) { + if (minneighflag) + error->all(FLERR, "Illegal fix electron/stopping command: minneigh given twice"); minneighflag = true; - if (iarg+2 > narg) error->all(FLERR, - "Illegal fix electron/stopping command: minneigh number missing"); - minneigh = utils::inumeric(FLERR, arg[iarg+1],false,lmp); - if (minneigh < 0) error->all(FLERR, - "Illegal fix electron/stopping command: minneigh < 0"); + if (iarg + 2 > narg) + error->all(FLERR, "Illegal fix electron/stopping command: minneigh number missing"); + minneigh = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + if (minneigh < 0) error->all(FLERR, "Illegal fix electron/stopping command: minneigh < 0"); iarg += 2; - } - else error->all(FLERR, - "Illegal fix electron/stopping command: unknown argument"); + } else + error->all(FLERR, "Illegal fix electron/stopping command: unknown argument"); } - // Read the input file for energy ranges and stopping powers. // First proc 0 reads the file, then bcast to others. const int ncol = atom->ntypes + 1; @@ -105,13 +94,12 @@ FixElectronStopping::FixElectronStopping(LAMMPS *lmp, int narg, char **arg) : read_table(arg[4]); } - MPI_Bcast(&maxlines, 1 , MPI_INT, 0, world); - MPI_Bcast(&table_entries, 1 , MPI_INT, 0, world); + MPI_Bcast(&maxlines, 1, MPI_INT, 0, world); + MPI_Bcast(&table_entries, 1, MPI_INT, 0, world); - if (comm->me != 0) - memory->create(elstop_ranges, ncol, maxlines, "electron/stopping:table"); + if (comm->me != 0) memory->create(elstop_ranges, ncol, maxlines, "electron/stopping:table"); - MPI_Bcast(&elstop_ranges[0][0], ncol*maxlines, MPI_DOUBLE, 0, world); + MPI_Bcast(&elstop_ranges[0][0], ncol * maxlines, MPI_DOUBLE, 0, world); } /* ---------------------------------------------------------------------- */ @@ -136,6 +124,10 @@ void FixElectronStopping::init() { SeLoss_sync_flag = 0; SeLoss = 0.0; + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix electron/stopping does not exist", idregion); + } // need an occasional full neighbor list neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); @@ -176,18 +168,17 @@ void FixElectronStopping::post_force(int /*vflag*/) int itype = type[i]; double massone = (atom->rmass) ? atom->rmass[i] : atom->mass[itype]; - double v2 = v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]; + double v2 = v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]; double energy = 0.5 * force->mvv2e * massone * v2; if (energy < Ecut) continue; if (energy < elstop_ranges[0][0]) continue; - if (energy > elstop_ranges[0][table_entries - 1]) error->one(FLERR, - "Atom kinetic energy too high for fix electron/stopping"); + if (energy > elstop_ranges[0][table_entries - 1]) + error->one(FLERR, "Atom kinetic energy too high for fix electron/stopping"); - if (iregion >= 0) { + if (region) { // Only apply in the given region - if (domain->regions[iregion]->match(x[i][0], x[i][1], x[i][2]) != 1) - continue; + if (region->match(x[i][0], x[i][1], x[i][2]) != 1) continue; } // Binary search to find correct energy range @@ -196,8 +187,10 @@ void FixElectronStopping::post_force(int /*vflag*/) while (true) { int ihalf = idown + (iup - idown) / 2; if (ihalf == idown) break; - if (elstop_ranges[0][ihalf] < energy) idown = ihalf; - else iup = ihalf; + if (elstop_ranges[0][ihalf] < energy) + idown = ihalf; + else + iup = ihalf; } double Se_lo = elstop_ranges[itype][idown]; @@ -215,7 +208,7 @@ void FixElectronStopping::post_force(int /*vflag*/) f[i][1] += v[i][1] * factor; f[i][2] += v[i][2] * factor; - SeLoss += Se * vabs * dt; // very rough approx + SeLoss += Se * vabs * dt; // very rough approx } } @@ -254,19 +247,17 @@ void FixElectronStopping::read_table(const char *file) ValueTokenizer values(line); elstop_ranges[0][nlines] = values.next_double(); if (elstop_ranges[0][nlines] <= oldvalue) - throw TokenizerException("energy values must be positive and in ascending order",line); + throw TokenizerException("energy values must be positive and in ascending order", line); oldvalue = elstop_ranges[0][nlines]; - for (int i = 1; i < ncol; ++i) - elstop_ranges[i][nlines] = values.next_double(); + for (int i = 1; i < ncol; ++i) elstop_ranges[i][nlines] = values.next_double(); ++nlines; } } catch (std::exception &e) { error->one(FLERR, "Problem parsing electron stopping data: {}", e.what()); } - if (nlines == 0) - error->one(FLERR, "Did not find any data in electron/stopping table file"); + if (nlines == 0) error->one(FLERR, "Did not find any data in electron/stopping table file"); table_entries = nlines; } @@ -281,8 +272,7 @@ void FixElectronStopping::grow_table() double **new_array; memory->create(new_array, ncol, new_maxlines, "electron/stopping:table"); - for (int i = 0; i < ncol; i++) - memcpy(new_array[i], elstop_ranges[i], maxlines*sizeof(double)); + for (int i = 0; i < ncol; i++) memcpy(new_array[i], elstop_ranges[i], maxlines * sizeof(double)); memory->destroy(elstop_ranges); elstop_ranges = new_array; diff --git a/src/EXTRA-FIX/fix_electron_stopping.h b/src/EXTRA-FIX/fix_electron_stopping.h index 015d444996..762435e966 100644 --- a/src/EXTRA-FIX/fix_electron_stopping.h +++ b/src/EXTRA-FIX/fix_electron_stopping.h @@ -52,8 +52,9 @@ class FixElectronStopping : public Fix { double **elstop_ranges; // [ 0][i]: energies // [>0][i]: stopping powers per type - int iregion; // region index if used, else -1 - int minneigh; // minimum number of neighbors + char *idregion; // region id + class Region *region; // region pointer if used, else NULL + int minneigh; // minimum number of neighbors class NeighList *list; }; 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_oneway.cpp b/src/EXTRA-FIX/fix_oneway.cpp index 465813ef57..7a4a0a02e3 100644 --- a/src/EXTRA-FIX/fix_oneway.cpp +++ b/src/EXTRA-FIX/fix_oneway.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -28,35 +27,36 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE=-1,X=0,Y=1,Z=2,XYZMASK=3,MINUS=4,PLUS=0}; +enum { NONE = -1, X = 0, Y = 1, Z = 2, XYZMASK = 3, MINUS = 4, PLUS = 0 }; /* ---------------------------------------------------------------------- */ -FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) +FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), region(nullptr), idregion(nullptr) { direction = NONE; - regionidx = 0; - regionstr = nullptr; - if (narg < 6) error->all(FLERR,"Illegal fix oneway command"); + if (narg < 6) error->all(FLERR, "Illegal fix oneway command"); - nevery = utils::inumeric(FLERR,arg[3],false,lmp); - if (nevery < 1) error->all(FLERR,"Illegal fix oneway command"); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); + if (nevery < 1) error->all(FLERR, "Illegal fix oneway command"); - regionstr = utils::strdup(arg[4]); + idregion = utils::strdup(arg[4]); + if (!domain->get_region_by_id(idregion)) + error->all(FLERR, "Region {} for fix oneway does not exist", idregion); - if (strcmp(arg[5], "x") == 0) direction = X|PLUS; - if (strcmp(arg[5], "X") == 0) direction = X|PLUS; - if (strcmp(arg[5], "y") == 0) direction = Y|PLUS; - if (strcmp(arg[5], "Y") == 0) direction = Y|PLUS; - if (strcmp(arg[5], "z") == 0) direction = Z|PLUS; - if (strcmp(arg[5], "Z") == 0) direction = Z|PLUS; - if (strcmp(arg[5],"-x") == 0) direction = X|MINUS; - if (strcmp(arg[5],"-X") == 0) direction = X|MINUS; - if (strcmp(arg[5],"-y") == 0) direction = Y|MINUS; - if (strcmp(arg[5],"-Y") == 0) direction = Y|MINUS; - if (strcmp(arg[5],"-z") == 0) direction = Z|MINUS; - if (strcmp(arg[5],"-Z") == 0) direction = Z|MINUS; + if (strcmp(arg[5], "x") == 0) direction = X | PLUS; + if (strcmp(arg[5], "X") == 0) direction = X | PLUS; + if (strcmp(arg[5], "y") == 0) direction = Y | PLUS; + if (strcmp(arg[5], "Y") == 0) direction = Y | PLUS; + if (strcmp(arg[5], "z") == 0) direction = Z | PLUS; + if (strcmp(arg[5], "Z") == 0) direction = Z | PLUS; + if (strcmp(arg[5], "-x") == 0) direction = X | MINUS; + if (strcmp(arg[5], "-X") == 0) direction = X | MINUS; + if (strcmp(arg[5], "-y") == 0) direction = Y | MINUS; + if (strcmp(arg[5], "-Y") == 0) direction = Y | MINUS; + if (strcmp(arg[5], "-z") == 0) direction = Z | MINUS; + if (strcmp(arg[5], "-Z") == 0) direction = Z | MINUS; global_freq = nevery; } @@ -65,7 +65,7 @@ FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) FixOneWay::~FixOneWay() { - delete[] regionstr; + delete[] idregion; } /* ---------------------------------------------------------------------- */ @@ -79,26 +79,24 @@ int FixOneWay::setmask() void FixOneWay::init() { - regionidx = domain->find_region(regionstr); - if (regionidx < 0) - error->all(FLERR,"Region for fix oneway does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix oneway does not exist", idregion); } /* ---------------------------------------------------------------------- */ void FixOneWay::end_of_step() { - Region *region = domain->regions[regionidx]; region->prematch(); const int idx = direction & XYZMASK; - const double * const * const x = atom->x; - double * const * const v = atom->v; + const double *const *const x = atom->x; + double *const *const v = atom->v; const int *mask = atom->mask; const int nlocal = atom->nlocal; 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])) { if (direction & MINUS) { if (v[i][idx] > 0.0) v[i][idx] = -v[i][idx]; } else { @@ -107,4 +105,3 @@ void FixOneWay::end_of_step() } } } - diff --git a/src/EXTRA-FIX/fix_oneway.h b/src/EXTRA-FIX/fix_oneway.h index ad6a5dc106..c9017aad52 100644 --- a/src/EXTRA-FIX/fix_oneway.h +++ b/src/EXTRA-FIX/fix_oneway.h @@ -34,8 +34,8 @@ class FixOneWay : public Fix { protected: int direction; - int regionidx; - char *regionstr; + class Region *region; + char *idregion; }; } // namespace LAMMPS_NS 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-FIX/fix_wall_region_ees.cpp b/src/EXTRA-FIX/fix_wall_region_ees.cpp index eb1ede5c4a..a9f6205373 100644 --- a/src/EXTRA-FIX/fix_wall_region_ees.cpp +++ b/src/EXTRA-FIX/fix_wall_region_ees.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,6 +22,7 @@ #include "domain.h" #include "error.h" #include "math_extra.h" +#include "math_special.h" #include "region.h" #include "respa.h" #include "update.h" @@ -31,13 +31,14 @@ using namespace LAMMPS_NS; using namespace FixConst; +using MathSpecial::powint; /* ---------------------------------------------------------------------- */ FixWallRegionEES::FixWallRegionEES(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg) + Fix(lmp, narg, arg), idregion(nullptr), region(nullptr) { - if (narg != 7) error->all(FLERR,"Illegal fix wall/region/ees command"); + if (narg != 7) error->all(FLERR, "Illegal fix wall/region/ees command"); scalar_flag = 1; vector_flag = 1; @@ -49,15 +50,14 @@ FixWallRegionEES::FixWallRegionEES(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/ees does not exist"); + region = domain->get_region_by_id(arg[3]); + if (!region) error->all(FLERR, "Region {} for fix wall/region/ees does not exist", arg[3]); idregion = utils::strdup(arg[3]); - epsilon = utils::numeric(FLERR,arg[4],false,lmp); - sigma = utils::numeric(FLERR,arg[5],false,lmp); - cutoff = utils::numeric(FLERR,arg[6],false,lmp); + epsilon = utils::numeric(FLERR, arg[4], false, lmp); + sigma = utils::numeric(FLERR, arg[5], false, lmp); + cutoff = utils::numeric(FLERR, arg[6], false, lmp); - if (cutoff <= 0.0) error->all(FLERR,"Fix wall/region/ees cutoff <= 0.0"); + if (cutoff <= 0.0) error->all(FLERR, "Fix wall/region/ees cutoff <= 0.0"); eflag = 0; ewall[0] = ewall[1] = ewall[2] = ewall[3] = 0.0; @@ -67,7 +67,7 @@ FixWallRegionEES::FixWallRegionEES(LAMMPS *lmp, int narg, char **arg) : FixWallRegionEES::~FixWallRegionEES() { - delete [] idregion; + delete[] idregion; } /* ---------------------------------------------------------------------- */ @@ -87,13 +87,11 @@ void FixWallRegionEES::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/ees does not exist"); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix wall/region/ees does not exist", idregion); - avec = dynamic_cast( atom->style_match("ellipsoid")); - if (!avec) - error->all(FLERR,"Fix wall/region/ees requires atom style ellipsoid"); + avec = dynamic_cast(atom->style_match("ellipsoid")); + if (!avec) error->all(FLERR, "Fix wall/region/ees requires atom style ellipsoid"); // check that all particles are finite-size ellipsoids // no point particles allowed, spherical is OK @@ -105,33 +103,33 @@ void FixWallRegionEES::init() for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) if (ellipsoid[i] < 0) - error->one(FLERR,"Fix wall/region/ees requires extended particles"); + error->one(FLERR, "Fix wall/region/ees requires only extended particles"); // setup coefficients - coeff1 = ( 2. / 4725. ) * epsilon * pow(sigma,12.0); - coeff2 = ( 1. / 24. ) * epsilon * pow(sigma,6.0); - coeff3 = ( 2. / 315. ) * epsilon * pow(sigma,12.0); - coeff4 = ( 1. / 3. ) * epsilon * pow(sigma,6.0); - coeff5 = ( 4. / 315. ) * epsilon * pow(sigma,12.0); - coeff6 = ( 1. / 12. ) * epsilon * pow(sigma,6.0); + coeff1 = (2.0 / 4725.0) * epsilon * powint(sigma, 12); + coeff2 = (1.0 / 24.0) * epsilon * powint(sigma, 6); + coeff3 = (2.0 / 315.0) * epsilon * powint(sigma, 12); + coeff4 = (1.0 / 3.0) * epsilon * powint(sigma, 6); + coeff5 = (4.0 / 315.0) * epsilon * powint(sigma, 12); + coeff6 = (1.0 / 12.0) * epsilon * powint(sigma, 6); offset = 0; - - 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; } /* ---------------------------------------------------------------------- */ void FixWallRegionEES::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(nlevels_respa - 1); + post_force_respa(vflag, nlevels_respa - 1, 0); + respa->copy_f_flevel(nlevels_respa - 1); + } else { post_force(vflag); - else { - (dynamic_cast( update->integrate))->copy_flevel_f(nlevels_respa-1); - post_force_respa(vflag,nlevels_respa-1,0); - (dynamic_cast( update->integrate))->copy_f_flevel(nlevels_respa-1); } } @@ -139,7 +137,7 @@ void FixWallRegionEES::setup(int vflag) void FixWallRegionEES::min_setup(int vflag) { - post_force(vflag); + post_force(vflag); } /* ---------------------------------------------------------------------- */ @@ -149,8 +147,8 @@ void FixWallRegionEES::post_force(int /*vflag*/) //sth is needed here, but I dont know what //that is calculation of sn - int i,m,n; - double rinv,fx,fy,fz,sn,tooclose[3]; + int i, m, n; + double rinv, fx, fy, fz, sn, tooclose[3]; eflag = 0; ewall[0] = ewall[1] = ewall[2] = ewall[3] = 0.0; @@ -165,7 +163,6 @@ void FixWallRegionEES::post_force(int /*vflag*/) int *mask = atom->mask; int nlocal = atom->nlocal; - Region *region = domain->regions[iregion]; region->prematch(); int onflag = 0; @@ -176,33 +173,34 @@ void FixWallRegionEES::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; } - double A[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; - double tempvec[3]= {0,0,0}; + double A[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + double tempvec[3] = {0, 0, 0}; double sn2 = 0.0; - double nhat[3] = {0,0,0}; - double* shape = bonus[ellipsoid[i]].shape;; - MathExtra::quat_to_mat(bonus[ellipsoid[i]].quat,A); + double nhat[3] = {0, 0, 0}; + double *shape = bonus[ellipsoid[i]].shape; + ; + MathExtra::quat_to_mat(bonus[ellipsoid[i]].quat, A); - for (int which = 0 ; which < 3; which ++) {//me - nhat[which]=1; - nhat[(which+1)%3] = 0 ; - nhat[(which+2)%3] = 0 ; - sn2 = 0 ; - MathExtra::transpose_matvec(A,nhat,tempvec); - for (int k = 0; k<3; k++) { + for (int which = 0; which < 3; which++) { //me + nhat[which] = 1; + nhat[(which + 1) % 3] = 0; + nhat[(which + 2) % 3] = 0; + sn2 = 0; + MathExtra::transpose_matvec(A, nhat, tempvec); + for (int k = 0; k < 3; k++) { tempvec[k] *= shape[k]; - sn2 += tempvec[k]*tempvec[k]; + sn2 += tempvec[k] * tempvec[k]; } sn = sqrt(sn2); tooclose[which] = sn; } - 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++) { @@ -212,12 +210,13 @@ void FixWallRegionEES::post_force(int /*vflag*/) } else if (region->contact[m].dely != 0 && region->contact[m].r <= tooclose[1]) { onflag = 1; continue; - } else if (region->contact[m].delz !=0 && region->contact[m].r <= tooclose[2]) { + } else if (region->contact[m].delz != 0 && region->contact[m].r <= tooclose[2]) { onflag = 1; continue; - } else rinv = 1.0/region->contact[m].r; + } else + rinv = 1.0 / region->contact[m].r; - ees(m,i); + ees(m, i); ewall[0] += eng; fx = fwall * region->contact[m].delx * rinv; @@ -237,15 +236,15 @@ void FixWallRegionEES::post_force(int /*vflag*/) } } - if (onflag) error->one(FLERR,"Particle on or inside surface of region " - "used in fix wall/region/ees"); + if (onflag) + error->one(FLERR, "Particle on or inside surface of region used in fix wall/region/ees"); } /* ---------------------------------------------------------------------- */ void FixWallRegionEES::post_force_respa(int vflag, int ilevel, int /*iloop*/) { - if (ilevel == nlevels_respa-1) post_force(vflag); + if (ilevel == nlevels_respa - 1) post_force(vflag); } /* ---------------------------------------------------------------------- */ @@ -264,7 +263,7 @@ double FixWallRegionEES::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]; @@ -279,10 +278,10 @@ double FixWallRegionEES::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]; } /* ---------------------------------------------------------------------- @@ -292,24 +291,23 @@ double FixWallRegionEES::compute_vector(int n) void FixWallRegionEES::ees(int m, int i) { - Region *region = domain->regions[iregion]; region->prematch(); double delta, delta2, delta3, delta4, delta5, delta6; - double sigman, sigman2 , sigman3, sigman4, sigman5, sigman6; - double hhss, hhss2, hhss4, hhss7, hhss8; //h^2 - s_n^2 - double hps; //h+s_n - double hms; //h-s_n + double sigman, sigman2, sigman3, sigman4, sigman5, sigman6; + double hhss, hhss2, hhss4, hhss7, hhss8; //h^2 - s_n^2 + double hps; //h+s_n + double hms; //h-s_n double twall; double A[3][3], nhat[3], SAn[3], that[3]; - double tempvec[3]= {0,0,0}; - double tempvec2[3]= {0,0,0}; + double tempvec[3] = {0, 0, 0}; + double tempvec2[3] = {0, 0, 0}; - double Lx[3][3] = {{0,0,0},{0,0,-1},{0,1,0}}; - double Ly[3][3] = {{0,0,1},{0,0,0},{-1,0,0}}; - double Lz[3][3] = {{0,-1,0},{1,0,0},{0,0,0}}; + double Lx[3][3] = {{0, 0, 0}, {0, 0, -1}, {0, 1, 0}}; + double Ly[3][3] = {{0, 0, 1}, {0, 0, 0}, {-1, 0, 0}}; + double Lz[3][3] = {{0, -1, 0}, {1, 0, 0}, {0, 0, 0}}; nhat[0] = region->contact[m].delx / region->contact[m].r; nhat[1] = region->contact[m].dely / region->contact[m].r; @@ -318,14 +316,15 @@ void FixWallRegionEES::ees(int m, int i) AtomVecEllipsoid::Bonus *bonus = avec->bonus; int *ellipsoid = atom->ellipsoid; - double* shape = bonus[ellipsoid[i]].shape;; - MathExtra::quat_to_mat(bonus[ellipsoid[i]].quat,A); + double *shape = bonus[ellipsoid[i]].shape; + ; + MathExtra::quat_to_mat(bonus[ellipsoid[i]].quat, A); sigman2 = 0.0; - MathExtra::transpose_matvec(A,nhat,tempvec); - for (int k = 0; k<3; k++) { + MathExtra::transpose_matvec(A, nhat, tempvec); + for (int k = 0; k < 3; k++) { tempvec[k] *= shape[k]; - sigman2 += tempvec[k]*tempvec[k]; + sigman2 += tempvec[k] * tempvec[k]; SAn[k] = tempvec[k]; } @@ -337,14 +336,14 @@ void FixWallRegionEES::ees(int m, int i) sigman5 = sigman4 * sigman; sigman6 = sigman3 * sigman3; - delta2 = delta * delta; + delta2 = delta * delta; delta3 = delta2 * delta; delta4 = delta2 * delta2; delta5 = delta3 * delta2; delta6 = delta3 * delta3; hhss = delta2 - sigman2; - hhss2 = hhss * hhss; + hhss2 = hhss * hhss; hhss4 = hhss2 * hhss2; hhss8 = hhss4 * hhss4; hhss7 = hhss4 * hhss2 * hhss; @@ -352,31 +351,31 @@ void FixWallRegionEES::ees(int m, int i) hps = delta + sigman; hms = delta - sigman; - fwall = -1*coeff4/hhss2 + coeff3 - * (21*delta6 + 63*delta4*sigman2 + 27*delta2*sigman4 + sigman6) / hhss8; + fwall = -1 * coeff4 / hhss2 + + coeff3 * (21 * delta6 + 63 * delta4 * sigman2 + 27 * delta2 * sigman4 + sigman6) / hhss8; - eng = -1*coeff2 * (4*delta/sigman2/hhss + 2*log(hms/hps)/sigman3) + - coeff1 * (35*delta5 + 70*delta3*sigman2 + 15*delta*sigman4) / hhss7; + eng = -1 * coeff2 * (4 * delta / sigman2 / hhss + 2 * log(hms / hps) / sigman3) + + coeff1 * (35 * delta5 + 70 * delta3 * sigman2 + 15 * delta * sigman4) / hhss7; - twall = coeff6 * (6*delta3/sigman4/hhss2 - 10*delta/sigman2/hhss2 - + 3*log(hms/hps)/sigman5) - + coeff5 * (21.*delta5 + 30.*delta3*sigman2 + 5.*delta*sigman4) / hhss8; + twall = coeff6 * + (6 * delta3 / sigman4 / hhss2 - 10 * delta / sigman2 / hhss2 + + 3 * log(hms / hps) / sigman5) + + coeff5 * (21. * delta5 + 30. * delta3 * sigman2 + 5. * delta * sigman4) / hhss8; - MathExtra::matvec(Lx,nhat,tempvec); - MathExtra::transpose_matvec(A,tempvec,tempvec2); - for (int k = 0; k<3; k++) tempvec2[k] *= shape[k]; - that[0] = MathExtra::dot3(SAn,tempvec2); - - MathExtra::matvec(Ly,nhat,tempvec); - MathExtra::transpose_matvec(A,tempvec,tempvec2); - for (int k = 0; k<3; k++) tempvec2[k] *= shape[k]; - that[1] = MathExtra::dot3(SAn,tempvec2); - - MathExtra::matvec(Lz,nhat,tempvec); - MathExtra::transpose_matvec(A,tempvec,tempvec2); + MathExtra::matvec(Lx, nhat, tempvec); + MathExtra::transpose_matvec(A, tempvec, tempvec2); for (int k = 0; k < 3; k++) tempvec2[k] *= shape[k]; - that[2] = MathExtra::dot3(SAn,tempvec2); + that[0] = MathExtra::dot3(SAn, tempvec2); - for (int j = 0; j<3 ; j++) - torque[j] = twall * that[j]; + MathExtra::matvec(Ly, nhat, tempvec); + MathExtra::transpose_matvec(A, tempvec, tempvec2); + for (int k = 0; k < 3; k++) tempvec2[k] *= shape[k]; + that[1] = MathExtra::dot3(SAn, tempvec2); + + MathExtra::matvec(Lz, nhat, tempvec); + MathExtra::transpose_matvec(A, tempvec, tempvec2); + for (int k = 0; k < 3; k++) tempvec2[k] *= shape[k]; + that[2] = MathExtra::dot3(SAn, tempvec2); + + for (int j = 0; j < 3; j++) torque[j] = twall * that[j]; } diff --git a/src/EXTRA-FIX/fix_wall_region_ees.h b/src/EXTRA-FIX/fix_wall_region_ees.h index 5163d99e90..ee5932e959 100644 --- a/src/EXTRA-FIX/fix_wall_region_ees.h +++ b/src/EXTRA-FIX/fix_wall_region_ees.h @@ -41,12 +41,12 @@ class FixWallRegionEES : public Fix { private: class AtomVecEllipsoid *avec; - int iregion; double epsilon, sigma, cutoff; int eflag; double ewall[4], ewall_all[4]; int nlevels_respa; char *idregion; + class Region *region; double coeff1, coeff2, coeff3, coeff4, offset; double coeff5, coeff6; diff --git a/src/EXTRA-MOLECULE/bond_fene_nm.cpp b/src/EXTRA-MOLECULE/bond_fene_nm.cpp index bd9d16b95d..291c9bc465 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-MOLECULE/bond_gaussian.cpp b/src/EXTRA-MOLECULE/bond_gaussian.cpp index 0ad125aeca..76637dbd88 100644 --- a/src/EXTRA-MOLECULE/bond_gaussian.cpp +++ b/src/EXTRA-MOLECULE/bond_gaussian.cpp @@ -34,7 +34,8 @@ using namespace MathConst; BondGaussian::BondGaussian(LAMMPS *lmp) : Bond(lmp), nterms(nullptr), bond_temperature(nullptr), alpha(nullptr), width(nullptr), r0(nullptr) -{} +{ +} /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-MOLECULE/dihedral_nharmonic.cpp b/src/EXTRA-MOLECULE/dihedral_nharmonic.cpp index fc1717bc94..9e3caa1393 100644 --- a/src/EXTRA-MOLECULE/dihedral_nharmonic.cpp +++ b/src/EXTRA-MOLECULE/dihedral_nharmonic.cpp @@ -345,13 +345,11 @@ void DihedralNHarmonic::born_matrix(int nd, int i1, int i2, int i3, int i4, double &dudih, double &du2dih) { int i,type; double vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z,vb2xm,vb2ym,vb2zm; - double ax,ay,az,bx,by,bz,rasq,rbsq,rgsq,rg,rginv,ra2inv,rb2inv,rabinv; - double c,s,kf; + double c,ax,ay,az,bx,by,bz,rasq,rbsq,ra2inv,rb2inv,rabinv; int **dihedrallist = neighbor->dihedrallist; double **x = atom->x; - int ndihedrallist = neighbor->ndihedrallist; type = dihedrallist[nd][4]; vb1x = x[i1][0] - x[i2][0]; diff --git a/src/EXTRA-MOLECULE/dihedral_nharmonic.h b/src/EXTRA-MOLECULE/dihedral_nharmonic.h index 46d6303ae3..28dd2e084e 100644 --- a/src/EXTRA-MOLECULE/dihedral_nharmonic.h +++ b/src/EXTRA-MOLECULE/dihedral_nharmonic.h @@ -33,7 +33,7 @@ class DihedralNHarmonic : public Dihedral { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; - void born_matrix(int /*dtype*/, int, int, int, int, double&, double&) override; + void born_matrix(int /*dtype*/, int, int, int, int, double &, double &) override; protected: int *nterms; 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/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 2a25efc6f2..7a8bf630df 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -37,106 +36,101 @@ using namespace LAMMPS_NS; using namespace FixConst; -using namespace MathConst; +using MathConst::MY_2PI; +using MathConst::MY_4PI3; +using MathConst::MY_PI; -enum{ATOM,MOLECULE}; -enum{ONE,RANGE,POLY}; +enum { ATOM, MOLECULE }; +enum { ONE, RANGE, POLY }; -#define EPSILON 0.001 -#define SMALL 1.0e-10 +static constexpr double EPSILON = 0.001; +static constexpr double SMALL = 1.0e-10; /* ---------------------------------------------------------------------- */ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), radius_poly(nullptr), frac_poly(nullptr), - idrigid(nullptr), idshake(nullptr), onemols(nullptr), molfrac(nullptr), coords(nullptr), - imageflags(nullptr), fixrigid(nullptr), fixshake(nullptr), recvcounts(nullptr), - displs(nullptr), random(nullptr), random2(nullptr) + Fix(lmp, narg, arg), radius_poly(nullptr), frac_poly(nullptr), idrigid(nullptr), + idshake(nullptr), idregion(nullptr), region(nullptr), onemols(nullptr), molfrac(nullptr), + coords(nullptr), imageflags(nullptr), fixrigid(nullptr), fixshake(nullptr), recvcounts(nullptr), + displs(nullptr), random(nullptr), random2(nullptr) { - if (narg < 6) error->all(FLERR,"Illegal fix pour command"); + if (narg < 6) error->all(FLERR, "Illegal fix pour command"); - if (lmp->kokkos) - error->all(FLERR,"Cannot yet use fix pour with the KOKKOS package"); + if (lmp->kokkos) error->all(FLERR, "Cannot yet use fix pour with the KOKKOS package"); time_depend = 1; if (!atom->radius_flag || !atom->rmass_flag) - error->all(FLERR,"Fix pour requires atom attributes radius, rmass"); + error->all(FLERR, "Fix pour requires atom attributes radius, rmass"); // required args - ninsert = utils::inumeric(FLERR,arg[3],false,lmp); - ntype = utils::inumeric(FLERR,arg[4],false,lmp); - seed = utils::inumeric(FLERR,arg[5],false,lmp); + ninsert = utils::inumeric(FLERR, arg[3], false, lmp); + ntype = utils::inumeric(FLERR, arg[4], false, lmp); + seed = utils::inumeric(FLERR, arg[5], false, lmp); - if (seed <= 0) error->all(FLERR,"Illegal fix pour command"); + if (seed <= 0) error->all(FLERR, "Illegal fix pour command"); // read options from end of input line - options(narg-6,&arg[6]); + options(narg - 6, &arg[6]); // error check on type if (mode == ATOM && (ntype <= 0 || ntype > atom->ntypes)) - error->all(FLERR,"Invalid atom type in fix pour command"); + error->all(FLERR, "Invalid atom type in fix pour command"); // error checks on region and its extent being inside simulation box - if (iregion == -1) error->all(FLERR,"Must specify a region in fix pour"); - if (domain->regions[iregion]->bboxflag == 0) - error->all(FLERR,"Fix pour region does not support a bounding box"); - if (domain->regions[iregion]->dynamic_check()) - error->all(FLERR,"Fix pour region cannot be dynamic"); + if (!region) error->all(FLERR, "Must specify a region in fix pour"); + if (region->bboxflag == 0) + error->all(FLERR, "Fix pour region {} does not support a bounding box", idregion); + if (region->dynamic_check()) error->all(FLERR, "Fix pour region {} cannot be dynamic", idregion); - if (strcmp(domain->regions[iregion]->style,"block") == 0) { + if (strcmp(region->style, "block") == 0) { + auto block = dynamic_cast(region); region_style = 1; - xlo = (dynamic_cast( domain->regions[iregion]))->xlo; - xhi = (dynamic_cast( domain->regions[iregion]))->xhi; - ylo = (dynamic_cast( domain->regions[iregion]))->ylo; - yhi = (dynamic_cast( domain->regions[iregion]))->yhi; - zlo = (dynamic_cast( domain->regions[iregion]))->zlo; - zhi = (dynamic_cast( domain->regions[iregion]))->zhi; - if (xlo < domain->boxlo[0] || xhi > domain->boxhi[0] || - ylo < domain->boxlo[1] || yhi > domain->boxhi[1] || - zlo < domain->boxlo[2] || zhi > domain->boxhi[2]) - error->all(FLERR,"Insertion region extends outside simulation box"); - } else if (strcmp(domain->regions[iregion]->style,"cylinder") == 0) { + xlo = block->xlo; + xhi = block->xhi; + ylo = block->ylo; + yhi = block->yhi; + zlo = block->zlo; + zhi = block->zhi; + if (xlo < domain->boxlo[0] || xhi > domain->boxhi[0] || ylo < domain->boxlo[1] || + yhi > domain->boxhi[1] || zlo < domain->boxlo[2] || zhi > domain->boxhi[2]) + error->all(FLERR, "Insertion region extends outside simulation box"); + } else if (strcmp(region->style, "cylinder") == 0) { + auto cylinder = dynamic_cast(region); region_style = 2; - char axis = (dynamic_cast( domain->regions[iregion]))->axis; - xc = (dynamic_cast( domain->regions[iregion]))->c1; - yc = (dynamic_cast( domain->regions[iregion]))->c2; - rc = (dynamic_cast( domain->regions[iregion]))->radius; - zlo = (dynamic_cast( domain->regions[iregion]))->lo; - zhi = (dynamic_cast( domain->regions[iregion]))->hi; - if (axis != 'z') - error->all(FLERR,"Must use a z-axis cylinder region with fix pour"); - if (xc-rc < domain->boxlo[0] || xc+rc > domain->boxhi[0] || - yc-rc < domain->boxlo[1] || yc+rc > domain->boxhi[1] || - zlo < domain->boxlo[2] || zhi > domain->boxhi[2]) - error->all(FLERR,"Insertion region extends outside simulation box"); - } else error->all(FLERR,"Must use a block or cylinder region with fix pour"); + char axis = cylinder->axis; + xc = cylinder->c1; + yc = cylinder->c2; + rc = cylinder->radius; + zlo = cylinder->lo; + zhi = cylinder->hi; + if (axis != 'z') error->all(FLERR, "Must use a z-axis cylinder region with fix pour"); + if (xc - rc < domain->boxlo[0] || xc + rc > domain->boxhi[0] || yc - rc < domain->boxlo[1] || + yc + rc > domain->boxhi[1] || zlo < domain->boxlo[2] || zhi > domain->boxhi[2]) + error->all(FLERR, "Insertion region extends outside simulation box"); + } else + error->all(FLERR, "Must use a block or cylinder region with fix pour"); if (region_style == 2 && domain->dimension == 2) - error->all(FLERR, - "Must use a block region with fix pour for 2d simulations"); + error->all(FLERR, "Must use a block region with fix pour for 2d simulations"); // error check and further setup for mode = MOLECULE - if (atom->tag_enable == 0) - error->all(FLERR,"Cannot use fix_pour unless atoms have IDs"); + if (atom->tag_enable == 0) error->all(FLERR, "Cannot use fix_pour unless atoms have IDs"); if (mode == MOLECULE) { for (int i = 0; i < nmol; i++) { - if (onemols[i]->xflag == 0) - error->all(FLERR,"Fix pour molecule must have coordinates"); - if (onemols[i]->typeflag == 0) - error->all(FLERR,"Fix pour molecule must have atom types"); - if (ntype+onemols[i]->ntypes <= 0 || - ntype+onemols[i]->ntypes > atom->ntypes) - error->all(FLERR,"Invalid atom type in fix pour mol command"); + if (onemols[i]->xflag == 0) error->all(FLERR, "Fix pour molecule must have coordinates"); + if (onemols[i]->typeflag == 0) error->all(FLERR, "Fix pour molecule must have atom types"); + if (ntype + onemols[i]->ntypes <= 0 || ntype + onemols[i]->ntypes > atom->ntypes) + error->all(FLERR, "Invalid atom type in fix pour mol command"); if (atom->molecular == Atom::TEMPLATE && onemols != atom->avec->onemols) - error->all(FLERR,"Fix pour molecule template ID must be same as atom style template ID"); + error->all(FLERR, "Fix pour molecule template ID must be same as atom style template ID"); onemols[i]->check_attributes(0); // fix pour uses geoemetric center of molecule for insertion @@ -145,23 +139,20 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : } } - if (rigidflag && mode == ATOM) - error->all(FLERR,"Cannot use fix pour rigid and not molecule"); - if (shakeflag && mode == ATOM) - error->all(FLERR,"Cannot use fix pour shake and not molecule"); - if (rigidflag && shakeflag) - error->all(FLERR,"Cannot use fix pour rigid and shake"); + if (rigidflag && mode == ATOM) error->all(FLERR, "Cannot use fix pour rigid and not molecule"); + if (shakeflag && mode == ATOM) error->all(FLERR, "Cannot use fix pour shake and not molecule"); + if (rigidflag && shakeflag) error->all(FLERR, "Cannot use fix pour rigid and shake"); // setup of coords and imageflags array - if (mode == ATOM) natom_max = 1; + if (mode == ATOM) + natom_max = 1; else { natom_max = 0; - for (int i = 0; i < nmol; i++) - natom_max = MAX(natom_max,onemols[i]->natoms); + for (int i = 0; i < nmol; i++) natom_max = MAX(natom_max, onemols[i]->natoms); } - memory->create(coords,natom_max,4,"pour:coords"); - memory->create(imageflags,natom_max,"pour:imageflags"); + memory->create(coords, natom_max, 4, "pour:coords"); + memory->create(imageflags, natom_max, "pour:imageflags"); // find max atom and molecule IDs just once @@ -171,13 +162,13 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : // 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(); // allgather arrays - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); + MPI_Comm_rank(world, &me); + MPI_Comm_size(world, &nprocs); recvcounts = new int[nprocs]; displs = new int[nprocs]; @@ -186,7 +177,7 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : auto fixlist = modify->get_fix_by_style("^gravity"); if (fixlist.size() != 1) - error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + error->all(FLERR, "There must be exactly one fix gravity defined for fix pour"); auto fixgrav = dynamic_cast(fixlist.front()); grav = -fixgrav->magnitude * force->ftm2v; @@ -200,7 +191,7 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : // gives t = [-(vz-rate) - sqrt((vz-rate)^2 - 2*grav*(zhi-zlo))] / grav // where zhi-zlo > 0, grav < 0, and vz & rate can be either > 0 or < 0 - double v_relative,delta; + double v_relative, delta; if (domain->dimension == 3) { v_relative = vz - rate; delta = zhi - zlo; @@ -208,8 +199,8 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : v_relative = vy - rate; delta = yhi - ylo; } - double t = (-v_relative - sqrt(v_relative*v_relative - 2.0*grav*delta)) / grav; - nfreq = static_cast(t/update->dt + 0.5); + double t = (-v_relative - sqrt(v_relative * v_relative - 2.0 * grav * delta)) / grav; + nfreq = static_cast(t / update->dt + 0.5); // 1st insertion on next timestep @@ -224,52 +215,51 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : // volume_one = volume of inserted particle (with max possible radius) // in 3d, insure dy >= 1, for quasi-2d simulations - double volume,volume_one=1.0; + double volume, volume_one = 1.0; molradius_max = 0.0; if (mode == MOLECULE) { - for (int i = 0; i < nmol; i++) - molradius_max = MAX(molradius_max,onemols[i]->molradius); + for (int i = 0; i < nmol; i++) molradius_max = MAX(molradius_max, onemols[i]->molradius); } if (domain->dimension == 3) { if (region_style == 1) { double dy = yhi - ylo; if (dy < 1.0) dy = 1.0; - volume = (xhi-xlo) * dy * (zhi-zlo); - } else volume = MY_PI*rc*rc * (zhi-zlo); + volume = (xhi - xlo) * dy * (zhi - zlo); + } else + volume = MY_PI * rc * rc * (zhi - zlo); if (mode == MOLECULE) { - volume_one = 4.0/3.0 * MY_PI * molradius_max*molradius_max*molradius_max; + volume_one = MY_4PI3 * molradius_max * molradius_max * molradius_max; } else if (dstyle == ONE || dstyle == RANGE) { - volume_one = 4.0/3.0 * MY_PI * radius_max*radius_max*radius_max; + volume_one = MY_4PI3 * radius_max * radius_max * radius_max; } else if (dstyle == POLY) { volume_one = 0.0; for (int i = 0; i < npoly; i++) - volume_one += (4.0/3.0 * MY_PI * - radius_poly[i]*radius_poly[i]*radius_poly[i]) * frac_poly[i]; + volume_one += (MY_4PI3 * radius_poly[i] * radius_poly[i] * radius_poly[i]) * frac_poly[i]; } } else { - volume = (xhi-xlo) * (yhi-ylo); + volume = (xhi - xlo) * (yhi - ylo); if (mode == MOLECULE) { - volume_one = MY_PI * molradius_max*molradius_max; + volume_one = MY_PI * molradius_max * molradius_max; } else if (dstyle == ONE || dstyle == RANGE) { - volume_one = MY_PI * radius_max*radius_max; + volume_one = MY_PI * radius_max * radius_max; } else if (dstyle == POLY) { volume_one = 0.0; for (int i = 0; i < npoly; i++) - volume_one += (MY_PI * radius_poly[i]*radius_poly[i]) * frac_poly[i]; + volume_one += (MY_PI * radius_poly[i] * radius_poly[i]) * frac_poly[i]; } } - nper = static_cast (volfrac*volume/volume_one); - if (nper == 0) error->all(FLERR,"Fix pour insertion count per timestep is 0"); - int nfinal = update->ntimestep + 1 + ((bigint)ninsert-1)/nper * nfreq; + nper = static_cast(volfrac * volume / volume_one); + if (nper == 0) error->all(FLERR, "Fix pour insertion count per timestep is 0"); + int nfinal = update->ntimestep + 1 + ((bigint) ninsert - 1) / nper * nfreq; // print stats if (me == 0) - utils::logmesg(lmp, "Particle insertion: {} every {} steps, {} by step {}\n", - nper,nfreq,ninsert,nfinal); + utils::logmesg(lmp, "Particle insertion: {} every {} steps, {} by step {}\n", nper, nfreq, + ninsert, nfinal); } /* ---------------------------------------------------------------------- */ @@ -277,15 +267,15 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : FixPour::~FixPour() { delete random; - delete [] molfrac; - delete [] idrigid; - delete [] idshake; - delete [] radius_poly; - delete [] frac_poly; + delete[] molfrac; + delete[] idrigid; + delete[] idshake; + delete[] radius_poly; + delete[] frac_poly; memory->destroy(coords); memory->destroy(imageflags); - delete [] recvcounts; - delete [] displs; + delete[] recvcounts; + delete[] displs; } /* ---------------------------------------------------------------------- */ @@ -301,8 +291,10 @@ int FixPour::setmask() void FixPour::init() { - if (domain->triclinic) - error->all(FLERR,"Cannot use fix pour with triclinic box"); + if (domain->triclinic) error->all(FLERR, "Cannot use fix pour with triclinic box"); + + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Fix pour region {} does not exist", idregion); // insure gravity fix (still) exists // for 3d must point in -z, for 2d must point in -y @@ -310,37 +302,35 @@ void FixPour::init() auto fixlist = modify->get_fix_by_style("^gravity"); if (fixlist.size() != 1) - error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + error->all(FLERR, "There must be exactly one fix gravity defined for fix pour"); auto fixgrav = dynamic_cast(fixlist.front()); if (fixgrav->varflag != FixGravity::CONSTANT) - error->all(FLERR,"Fix gravity for fix pour must be constant"); + error->all(FLERR, "Fix gravity for fix pour must be constant"); double xgrav = fixgrav->xgrav; double ygrav = fixgrav->ygrav; double zgrav = fixgrav->zgrav; if (domain->dimension == 3) { - if (fabs(xgrav) > EPSILON || fabs(ygrav) > EPSILON || - fabs(zgrav+1.0) > EPSILON) - error->all(FLERR,"Gravity must point in -z to use with fix pour in 3d"); + if (fabs(xgrav) > EPSILON || fabs(ygrav) > EPSILON || fabs(zgrav + 1.0) > EPSILON) + error->all(FLERR, "Gravity must point in -z to use with fix pour in 3d"); } else { - if (fabs(xgrav) > EPSILON || fabs(ygrav+1.0) > EPSILON || - fabs(zgrav) > EPSILON) - error->all(FLERR,"Gravity must point in -y to use with fix pour in 2d"); + if (fabs(xgrav) > EPSILON || fabs(ygrav + 1.0) > EPSILON || fabs(zgrav) > EPSILON) + error->all(FLERR, "Gravity must point in -y to use with fix pour in 2d"); } double gnew = -fixgrav->magnitude * force->ftm2v; - if (gnew != grav) error->all(FLERR,"Gravity changed since fix pour was created"); + if (gnew != grav) error->all(FLERR, "Gravity changed since fix pour was created"); // if rigidflag defined, check for rigid/small fix // its molecule template must be same as this one if (rigidflag) { fixrigid = modify->get_fix_by_id(idrigid); - if (!fixrigid) error->all(FLERR,"Fix pour rigid fix does not exist"); + if (!fixrigid) error->all(FLERR, "Fix pour rigid fix {} does not exist", idrigid); int tmp; - if (onemols != (Molecule **) fixrigid->extract("onemol",tmp)) - error->all(FLERR,"Fix pour and fix rigid/small not using same molecule template ID"); + if (onemols != (Molecule **) fixrigid->extract("onemol", tmp)) + error->all(FLERR, "Fix pour and fix rigid/small not using same molecule template ID"); } // if shakeflag defined, check for SHAKE fix @@ -348,10 +338,10 @@ void FixPour::init() if (shakeflag) { fixshake = modify->get_fix_by_id(idshake); - if (!fixshake) error->all(FLERR,"Fix pour shake fix does not exist"); + if (!fixshake) error->all(FLERR, "Fix pour shake fix {} does not exist", idshake); int tmp; - if (onemols != (Molecule **) fixshake->extract("onemol",tmp)) - error->all(FLERR,"Fix pour and fix shake not using same molecule template ID"); + if (onemols != (Molecule **) fixshake->extract("onemol", tmp)) + error->all(FLERR, "Fix pour and fix shake not using same molecule template ID"); } } @@ -359,8 +349,10 @@ void FixPour::init() void FixPour::setup_pre_exchange() { - if (ninserted < ninsert) next_reneighbor = update->ntimestep + 1; - else next_reneighbor = 0; + if (ninserted < ninsert) + next_reneighbor = update->ntimestep + 1; + else + next_reneighbor = 0; } /* ---------------------------------------------------------------------- @@ -369,8 +361,8 @@ void FixPour::setup_pre_exchange() void FixPour::pre_exchange() { - int i,m,flag,nlocalprev,imol,natom; - double r[3],rotmat[3][3],quat[4],vnew[3]; + int i, m, flag, nlocalprev, imol, natom; + double r[3], rotmat[3][3], quat[4], vnew[3]; double *newcoord; // just return if should not be called on this timestep @@ -414,24 +406,24 @@ void FixPour::pre_exchange() if (overlap(i)) ncount++; int nprevious; - MPI_Allreduce(&ncount,&nprevious,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&ncount, &nprevious, 1, MPI_INT, MPI_SUM, world); // xmine is for my atoms // xnear is for atoms from all procs + atoms to be inserted - double **xmine,**xnear; - memory->create(xmine,ncount,4,"fix_pour:xmine"); - memory->create(xnear,nprevious+nnew*natom_max,4,"fix_pour:xnear"); + double **xmine, **xnear; + memory->create(xmine, ncount, 4, "fix_pour:xmine"); + memory->create(xnear, nprevious + nnew * natom_max, 4, "fix_pour:xnear"); int nnear = nprevious; // setup for allgatherv - int n = 4*ncount; - MPI_Allgather(&n,1,MPI_INT,recvcounts,1,MPI_INT,world); + int n = 4 * ncount; + 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]; // load up xmine array @@ -452,8 +444,7 @@ void FixPour::pre_exchange() double *ptr = nullptr; if (ncount) ptr = xmine[0]; - MPI_Allgatherv(ptr,4*ncount,MPI_DOUBLE, - xnear[0],recvcounts,displs,MPI_DOUBLE,world); + MPI_Allgatherv(ptr, 4 * ncount, MPI_DOUBLE, xnear[0], recvcounts, displs, MPI_DOUBLE, world); // insert new particles into xnear list, one by one // check against all nearby atoms and previously inserted ones @@ -468,7 +459,7 @@ void FixPour::pre_exchange() // store image flag modified due to PBC int success; - double radtmp,delx,dely,delz,rsq,radsum,rn,h; + double radtmp, delx, dely, delz, rsq, radsum, rn, h; double coord[3]; double denstmp; @@ -481,13 +472,13 @@ void FixPour::pre_exchange() while (nsuccess < nnew) { rn = random->uniform(); - h = hi_current - rn*rn * (hi_current-lo_current); + h = hi_current - rn * rn * (hi_current - lo_current); if (mode == ATOM) radtmp = radius_sample(); success = 0; while (attempt < maxiter) { attempt++; - xyz_random(h,coord); + xyz_random(h, coord); if (mode == ATOM) { natom = 1; @@ -495,8 +486,7 @@ void FixPour::pre_exchange() coords[0][1] = coord[1]; coords[0][2] = coord[2]; coords[0][3] = radtmp; - imageflags[0] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; + imageflags[0] = ((imageint) IMGMAX << IMG2BITS) | ((imageint) IMGMAX << IMGBITS) | IMGMAX; } else { double rng = random->uniform(); imol = 0; @@ -512,10 +502,10 @@ void FixPour::pre_exchange() } double theta = random->uniform() * MY_2PI; MathExtra::norm3(r); - MathExtra::axisangle_to_quat(r,theta,quat); - MathExtra::quat_to_mat(quat,rotmat); + MathExtra::axisangle_to_quat(r, theta, quat); + MathExtra::quat_to_mat(quat, rotmat); for (i = 0; i < natom; i++) { - MathExtra::matvec(rotmat,onemols[imol]->dx[i],coords[i]); + MathExtra::matvec(rotmat, onemols[imol]->dx[i], coords[i]); coords[i][0] += coord[0]; coords[i][1] += coord[1]; coords[i][2] += coord[2]; @@ -526,11 +516,11 @@ void FixPour::pre_exchange() if (onemols[imol]->radiusflag) coords[i][3] = onemols[imol]->radius[i]; - else coords[i][3] = 0.5; + else + coords[i][3] = 0.5; - imageflags[i] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - domain->remap(coords[i],imageflags[i]); + imageflags[i] = ((imageint) IMGMAX << IMG2BITS) | ((imageint) IMGMAX << IMGBITS) | IMGMAX; + domain->remap(coords[i], imageflags[i]); } } @@ -542,10 +532,10 @@ void FixPour::pre_exchange() delx = coords[m][0] - xnear[i][0]; dely = coords[m][1] - xnear[i][1]; delz = coords[m][2] - xnear[i][2]; - domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; + domain->minimum_image(delx, dely, delz); + rsq = delx * delx + dely * dely + delz * delz; radsum = coords[m][3] + xnear[i][3]; - if (rsq <= radsum*radsum) break; + if (rsq <= radsum * radsum) break; } if (i < nnear) break; } @@ -582,12 +572,12 @@ void FixPour::pre_exchange() // coord[2] = hi_current + vz*t + 1/2 grav t^2 if (dimension == 3) { - vnew[0] = vxlo + random->uniform() * (vxhi-vxlo); - vnew[1] = vylo + random->uniform() * (vyhi-vylo); - vnew[2] = -sqrt(vz*vz + 2.0*grav*(coord[2]-hi_current)); + vnew[0] = vxlo + random->uniform() * (vxhi - vxlo); + vnew[1] = vylo + random->uniform() * (vyhi - vylo); + vnew[2] = -sqrt(vz * vz + 2.0 * grav * (coord[2] - hi_current)); } else { - vnew[0] = vxlo + random->uniform() * (vxhi-vxlo); - vnew[1] = -sqrt(vy*vy + 2.0*grav*(coord[1]-hi_current)); + vnew[0] = vxlo + random->uniform() * (vxhi - vxlo); + vnew[1] = -sqrt(vy * vy + 2.0 * grav * (coord[1] - hi_current)); vnew[2] = 0.0; } @@ -597,45 +587,47 @@ void FixPour::pre_exchange() // set group mask to "all" plus fix group for (m = 0; m < natom; m++) { - if (mode == ATOM) - denstmp = density_lo + random->uniform() * (density_hi-density_lo); + if (mode == ATOM) denstmp = density_lo + random->uniform() * (density_hi - density_lo); newcoord = coords[m]; flag = 0; - if (newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] && - newcoord[1] >= sublo[1] && newcoord[1] < subhi[1] && - newcoord[2] >= sublo[2] && newcoord[2] < subhi[2]) flag = 1; + if (newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] && newcoord[1] >= sublo[1] && + newcoord[1] < subhi[1] && newcoord[2] >= sublo[2] && newcoord[2] < subhi[2]) + flag = 1; else if (dimension == 3 && newcoord[2] >= domain->boxhi[2]) { if (comm->layout != Comm::LAYOUT_TILED) { - if (comm->myloc[2] == comm->procgrid[2]-1 && - newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] && - newcoord[1] >= sublo[1] && newcoord[1] < subhi[1]) flag = 1; + if (comm->myloc[2] == comm->procgrid[2] - 1 && newcoord[0] >= sublo[0] && + newcoord[0] < subhi[0] && newcoord[1] >= sublo[1] && newcoord[1] < subhi[1]) + flag = 1; } else { - if (comm->mysplit[2][1] == 1.0 && - newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] && - newcoord[1] >= sublo[1] && newcoord[1] < subhi[1]) flag = 1; + if (comm->mysplit[2][1] == 1.0 && newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] && + newcoord[1] >= sublo[1] && newcoord[1] < subhi[1]) + flag = 1; } } else if (dimension == 2 && newcoord[1] >= domain->boxhi[1]) { if (comm->layout != Comm::LAYOUT_TILED) { - if (comm->myloc[1] == comm->procgrid[1]-1 && - newcoord[0] >= sublo[0] && newcoord[0] < subhi[0]) flag = 1; + if (comm->myloc[1] == comm->procgrid[1] - 1 && newcoord[0] >= sublo[0] && + newcoord[0] < subhi[0]) + flag = 1; } else { - if (comm->mysplit[1][1] == 1.0 && - newcoord[0] >= sublo[0] && newcoord[0] < subhi[0]) flag = 1; + if (comm->mysplit[1][1] == 1.0 && newcoord[0] >= sublo[0] && newcoord[0] < subhi[0]) + flag = 1; } } if (flag) { - if (mode == ATOM) atom->avec->create_atom(ntype,coords[m]); - else atom->avec->create_atom(ntype+onemols[imol]->type[m],coords[m]); + if (mode == ATOM) + atom->avec->create_atom(ntype, coords[m]); + else + atom->avec->create_atom(ntype + onemols[imol]->type[m], coords[m]); int n = atom->nlocal - 1; - atom->tag[n] = maxtag_all + m+1; + atom->tag[n] = maxtag_all + m + 1; if (mode == MOLECULE) { if (atom->molecule_flag) { if (onemols[imol]->moleculeflag) { atom->molecule[n] = maxmol_all + onemols[imol]->molecule[m]; } else { - atom->molecule[n] = maxmol_all+1; + atom->molecule[n] = maxmol_all + 1; } } if (atom->molecular == Atom::TEMPLATE) { @@ -651,10 +643,10 @@ void FixPour::pre_exchange() if (mode == ATOM) { radtmp = newcoord[3]; atom->radius[n] = radtmp; - atom->rmass[n] = 4.0*MY_PI/3.0 * radtmp*radtmp*radtmp * denstmp; + atom->rmass[n] = 4.0 * MY_PI / 3.0 * radtmp * radtmp * radtmp * denstmp; } else { onemols[imol]->quat_external = quat; - atom->add_molecule_atom(onemols[imol],m,n,maxtag_all); + atom->add_molecule_atom(onemols[imol], m, n, maxtag_all); } modify->create_attribute(n); @@ -666,9 +658,9 @@ void FixPour::pre_exchange() // FixShake::set_molecule stores shake info for molecule if (rigidflag) - fixrigid->set_molecule(nlocalprev,maxtag_all,imol,coord,vnew,quat); + fixrigid->set_molecule(nlocalprev, maxtag_all, imol, coord, vnew, quat); else if (shakeflag) - fixshake->set_molecule(nlocalprev,maxtag_all,imol,coord,vnew,quat); + fixshake->set_molecule(nlocalprev, maxtag_all, imol, coord, vnew, quat); maxtag_all += natom; if (mode == MOLECULE && atom->molecule_flag) { @@ -685,8 +677,7 @@ void FixPour::pre_exchange() int ninserted_atoms = nnear - nprevious; int ninserted_mols = ninserted_atoms / natom; ninserted += ninserted_mols; - if (ninserted_mols < nnew && me == 0) - error->warning(FLERR,"Less insertions than requested"); + if (ninserted_mols < nnew && me == 0) error->warning(FLERR, "Less insertions than requested"); // reset global natoms,nbonds,etc // increment maxtag_all and maxmol_all if necessary @@ -696,16 +687,14 @@ void FixPour::pre_exchange() if (ninserted_atoms) { atom->natoms += ninserted_atoms; - if (atom->natoms < 0) - error->all(FLERR,"Too many total atoms"); + if (atom->natoms < 0) error->all(FLERR, "Too many total atoms"); if (mode == MOLECULE) { - atom->nbonds += (bigint)onemols[imol]->nbonds * ninserted_mols; - atom->nangles += (bigint)onemols[imol]->nangles * ninserted_mols; - atom->ndihedrals += (bigint)onemols[imol]->ndihedrals * ninserted_mols; - atom->nimpropers += (bigint)onemols[imol]->nimpropers * ninserted_mols; + atom->nbonds += (bigint) onemols[imol]->nbonds * ninserted_mols; + atom->nangles += (bigint) onemols[imol]->nangles * ninserted_mols; + atom->ndihedrals += (bigint) onemols[imol]->ndihedrals * ninserted_mols; + atom->nimpropers += (bigint) onemols[imol]->nimpropers * ninserted_mols; } - if (maxtag_all >= MAXTAGINT) - error->all(FLERR,"New atom IDs exceed maximum allowed ID"); + if (maxtag_all >= MAXTAGINT) error->all(FLERR, "New atom IDs exceed maximum allowed ID"); } // rebuild atom map @@ -722,8 +711,10 @@ void FixPour::pre_exchange() // next timestep to insert - if (ninserted < ninsert) next_reneighbor += nfreq; - else next_reneighbor = 0; + if (ninserted < ninsert) + next_reneighbor += nfreq; + else + next_reneighbor = 0; } /* ---------------------------------------------------------------------- @@ -738,13 +729,13 @@ void FixPour::find_maxid() int nlocal = atom->nlocal; tagint max = 0; - for (int i = 0; i < nlocal; i++) max = MAX(max,tag[i]); - MPI_Allreduce(&max,&maxtag_all,1,MPI_LMP_TAGINT,MPI_MAX,world); + for (int i = 0; i < nlocal; i++) max = MAX(max, tag[i]); + MPI_Allreduce(&max, &maxtag_all, 1, MPI_LMP_TAGINT, MPI_MAX, world); if (mode == MOLECULE && molecule) { max = 0; - for (int i = 0; i < nlocal; i++) max = MAX(max,molecule[i]); - MPI_Allreduce(&max,&maxmol_all,1,MPI_LMP_TAGINT,MPI_MAX,world); + for (int i = 0; i < nlocal; i++) max = MAX(max, molecule[i]); + MPI_Allreduce(&max, &maxmol_all, 1, MPI_LMP_TAGINT, MPI_MAX, world); } } @@ -766,29 +757,31 @@ int FixPour::overlap(int i) if (ignoretri && atom->tri[i] >= 0) return 0; } - if (mode == ATOM) delta = atom->radius[i] + radius_max; - else delta = atom->radius[i] + molradius_max; + if (mode == ATOM) + delta = atom->radius[i] + radius_max; + else + delta = atom->radius[i] + molradius_max; double *x = atom->x[i]; if (domain->dimension == 3) { if (region_style == 1) { - if (outside(0,x[0],xlo-delta,xhi+delta)) return 0; - if (outside(1,x[1],ylo-delta,yhi+delta)) return 0; - if (outside(2,x[2],lo_current-delta,hi_current+delta)) return 0; + if (outside(0, x[0], xlo - delta, xhi + delta)) return 0; + if (outside(1, x[1], ylo - delta, yhi + delta)) return 0; + if (outside(2, x[2], lo_current - delta, hi_current + delta)) return 0; } else { double delx = x[0] - xc; double dely = x[1] - yc; double delz = 0.0; - domain->minimum_image(delx,dely,delz); - double rsq = delx*delx + dely*dely; + domain->minimum_image(delx, dely, delz); + double rsq = delx * delx + dely * dely; double r = rc + delta; - if (rsq > r*r) return 0; - if (outside(2,x[2],lo_current-delta,hi_current+delta)) return 0; + if (rsq > r * r) return 0; + if (outside(2, x[2], lo_current - delta, hi_current + delta)) return 0; } } else { - if (outside(0,x[0],xlo-delta,xhi+delta)) return 0; - if (outside(1,x[1],lo_current-delta,hi_current+delta)) return 0; + if (outside(0, x[0], xlo - delta, xhi + delta)) return 0; + if (outside(1, x[1], lo_current - delta, hi_current + delta)) return 0; } return 1; @@ -836,22 +829,22 @@ void FixPour::xyz_random(double h, double *coord) { if (domain->dimension == 3) { if (region_style == 1) { - coord[0] = xlo + random->uniform() * (xhi-xlo); - coord[1] = ylo + random->uniform() * (yhi-ylo); + coord[0] = xlo + random->uniform() * (xhi - xlo); + coord[1] = ylo + random->uniform() * (yhi - ylo); coord[2] = h; } else { - double r1,r2; + double r1, r2; while (true) { r1 = random->uniform() - 0.5; r2 = random->uniform() - 0.5; - if (r1*r1 + r2*r2 < 0.25) break; + if (r1 * r1 + r2 * r2 < 0.25) break; } - coord[0] = xc + 2.0*r1*rc; - coord[1] = yc + 2.0*r2*rc; + coord[0] = xc + 2.0 * r1 * rc; + coord[1] = yc + 2.0 * r2 * rc; coord[2] = h; } } else { - coord[0] = xlo + random->uniform() * (xhi-xlo); + coord[0] = xlo + random->uniform() * (xhi - xlo); coord[1] = h; coord[2] = 0.0; } @@ -862,8 +855,7 @@ void FixPour::xyz_random(double h, double *coord) double FixPour::radius_sample() { if (dstyle == ONE) return radius_one; - if (dstyle == RANGE) return radius_lo + - random->uniform()*(radius_hi-radius_lo); + if (dstyle == RANGE) return radius_lo + random->uniform() * (radius_hi - radius_lo); double value = random->uniform(); @@ -873,7 +865,7 @@ double FixPour::radius_sample() sum += frac_poly[i]; i++; } - return radius_poly[i-1]; + return radius_poly[i - 1]; } /* ---------------------------------------------------------------------- @@ -884,18 +876,13 @@ void FixPour::options(int narg, char **arg) { // defaults - iregion = -1; mode = ATOM; - molfrac = nullptr; rigidflag = 0; - idrigid = nullptr; shakeflag = 0; - idshake = nullptr; idnext = 0; ignoreflag = ignoreline = ignoretri = 0; dstyle = ONE; radius_max = radius_one = 0.5; - radius_poly = frac_poly = nullptr; density_lo = density_hi = 1.0; volfrac = 0.25; maxattempt = 50; @@ -904,139 +891,141 @@ void FixPour::options(int narg, char **arg) int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) error->all(FLERR,"Fix pour region ID does not exist"); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Fix pour region {} does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - - } else if (strcmp(arg[iarg],"mol") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) - error->all(FLERR,"Molecule template ID for fix pour does not exist"); + } else if (strcmp(arg[iarg], "mol") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + int imol = atom->find_molecule(arg[iarg + 1]); + if (imol == -1) error->all(FLERR, "Molecule template ID for fix pour does not exist"); mode = MOLECULE; onemols = &atom->molecules[imol]; nmol = onemols[0]->nset; - delete [] molfrac; + delete[] molfrac; molfrac = new double[nmol]; - molfrac[0] = 1.0/nmol; - for (int i = 1; i < nmol-1; i++) molfrac[i] = molfrac[i-1] + 1.0/nmol; - molfrac[nmol-1] = 1.0; + molfrac[0] = 1.0 / nmol; + for (int i = 1; i < nmol - 1; i++) molfrac[i] = molfrac[i - 1] + 1.0 / nmol; + molfrac[nmol - 1] = 1.0; iarg += 2; - } else if (strcmp(arg[iarg],"molfrac") == 0) { - if (mode != MOLECULE) error->all(FLERR,"Illegal fix pour command"); - if (iarg+nmol+1 > narg) error->all(FLERR,"Illegal fix pour command"); - molfrac[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "molfrac") == 0) { + if (mode != MOLECULE) error->all(FLERR, "Illegal fix pour command"); + if (iarg + nmol + 1 > narg) error->all(FLERR, "Illegal fix pour command"); + molfrac[0] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); for (int i = 1; i < nmol; i++) - molfrac[i] = molfrac[i-1] + utils::numeric(FLERR,arg[iarg+i+1],false,lmp); - if (molfrac[nmol-1] < 1.0-EPSILON || molfrac[nmol-1] > 1.0+EPSILON) - error->all(FLERR,"Illegal fix pour command"); - molfrac[nmol-1] = 1.0; - iarg += nmol+1; + molfrac[i] = molfrac[i - 1] + utils::numeric(FLERR, arg[iarg + i + 1], false, lmp); + if (molfrac[nmol - 1] < 1.0 - EPSILON || molfrac[nmol - 1] > 1.0 + EPSILON) + error->all(FLERR, "Illegal fix pour command"); + molfrac[nmol - 1] = 1.0; + iarg += nmol + 1; - } else if (strcmp(arg[iarg],"rigid") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - delete [] idrigid; - idrigid = utils::strdup(arg[iarg+1]); + } else if (strcmp(arg[iarg], "rigid") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + delete[] idrigid; + idrigid = utils::strdup(arg[iarg + 1]); rigidflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"shake") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - delete [] idshake; - idshake = utils::strdup(arg[iarg+1]); + } else if (strcmp(arg[iarg], "shake") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + delete[] idshake; + idshake = utils::strdup(arg[iarg + 1]); shakeflag = 1; iarg += 2; - } else if (strcmp(arg[iarg],"id") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - if (strcmp(arg[iarg+1],"max") == 0) idnext = 0; - else if (strcmp(arg[iarg+1],"next") == 0) idnext = 1; - else error->all(FLERR,"Illegal fix pour command"); + } else if (strcmp(arg[iarg], "id") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + if (strcmp(arg[iarg + 1], "max") == 0) + idnext = 0; + else if (strcmp(arg[iarg + 1], "next") == 0) + idnext = 1; + else + error->all(FLERR, "Illegal fix pour command"); iarg += 2; - } else if (strcmp(arg[iarg],"ignore") == 0) { + } else if (strcmp(arg[iarg], "ignore") == 0) { if (atom->line_flag) ignoreline = 1; if (atom->tri_flag) ignoretri = 1; if (ignoreline || ignoretri) ignoreflag = 1; iarg += 1; - } else if (strcmp(arg[iarg],"diam") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - if (strcmp(arg[iarg+1],"one") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix pour command"); + } else if (strcmp(arg[iarg], "diam") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + if (strcmp(arg[iarg + 1], "one") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix pour command"); dstyle = ONE; - radius_one = 0.5 * utils::numeric(FLERR,arg[iarg+2],false,lmp); + radius_one = 0.5 * utils::numeric(FLERR, arg[iarg + 2], false, lmp); radius_max = radius_one; iarg += 3; - } else if (strcmp(arg[iarg+1],"range") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix pour command"); + } else if (strcmp(arg[iarg + 1], "range") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix pour command"); dstyle = RANGE; - radius_lo = 0.5 * utils::numeric(FLERR,arg[iarg+2],false,lmp); - radius_hi = 0.5 * utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (radius_lo > radius_hi) error->all(FLERR,"Illegal fix pour command"); + radius_lo = 0.5 * utils::numeric(FLERR, arg[iarg + 2], false, lmp); + radius_hi = 0.5 * utils::numeric(FLERR, arg[iarg + 3], false, lmp); + if (radius_lo > radius_hi) error->all(FLERR, "Illegal fix pour command"); radius_max = radius_hi; iarg += 4; - } else if (strcmp(arg[iarg+1],"poly") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix pour command"); + } else if (strcmp(arg[iarg + 1], "poly") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix pour command"); dstyle = POLY; - npoly = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - if (npoly <= 0) error->all(FLERR,"Illegal fix pour command"); - if (iarg+3 + 2*npoly > narg) - error->all(FLERR,"Illegal fix pour command"); + npoly = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); + if (npoly <= 0) error->all(FLERR, "Illegal fix pour command"); + if (iarg + 3 + 2 * npoly > narg) error->all(FLERR, "Illegal fix pour command"); radius_poly = new double[npoly]; frac_poly = new double[npoly]; iarg += 3; radius_max = 0.0; for (int i = 0; i < npoly; i++) { - radius_poly[i] = 0.5 * utils::numeric(FLERR,arg[iarg++],false,lmp); - frac_poly[i] = utils::numeric(FLERR,arg[iarg++],false,lmp); + radius_poly[i] = 0.5 * utils::numeric(FLERR, arg[iarg++], false, lmp); + frac_poly[i] = utils::numeric(FLERR, arg[iarg++], false, lmp); if (radius_poly[i] <= 0.0 || frac_poly[i] < 0.0) - error->all(FLERR,"Illegal fix pour command"); - radius_max = MAX(radius_max,radius_poly[i]); + error->all(FLERR, "Illegal fix pour command"); + radius_max = MAX(radius_max, radius_poly[i]); } double sum = 0.0; for (int i = 0; i < npoly; i++) sum += frac_poly[i]; if (fabs(sum - 1.0) > SMALL) - error->all(FLERR,"Fix pour polydisperse fractions do not sum to 1.0"); - } else error->all(FLERR,"Illegal fix pour command"); + error->all(FLERR, "Fix pour polydisperse fractions do not sum to 1.0"); + } else + error->all(FLERR, "Illegal fix pour command"); - } else if (strcmp(arg[iarg],"dens") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix pour command"); - density_lo = utils::numeric(FLERR,arg[iarg+1],false,lmp); - density_hi = utils::numeric(FLERR,arg[iarg+2],false,lmp); - if (density_lo > density_hi) error->all(FLERR,"Illegal fix pour command"); + } else if (strcmp(arg[iarg], "dens") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix pour command"); + density_lo = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + density_hi = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + if (density_lo > density_hi) error->all(FLERR, "Illegal fix pour command"); iarg += 3; - } else if (strcmp(arg[iarg],"vol") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix pour command"); - volfrac = utils::numeric(FLERR,arg[iarg+1],false,lmp); - maxattempt = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + } else if (strcmp(arg[iarg], "vol") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix pour command"); + volfrac = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + maxattempt = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); iarg += 3; - } else if (strcmp(arg[iarg],"rate") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - rate = utils::numeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "rate") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix pour command"); + rate = utils::numeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"vel") == 0) { + } else if (strcmp(arg[iarg], "vel") == 0) { if (domain->dimension == 3) { - if (iarg+6 > narg) error->all(FLERR,"Illegal fix pour command"); - vxlo = utils::numeric(FLERR,arg[iarg+1],false,lmp); - vxhi = utils::numeric(FLERR,arg[iarg+2],false,lmp); - vylo = utils::numeric(FLERR,arg[iarg+3],false,lmp); - vyhi = utils::numeric(FLERR,arg[iarg+4],false,lmp); - if (vxlo > vxhi || vylo > vyhi) - error->all(FLERR,"Illegal fix pour command"); - vz = utils::numeric(FLERR,arg[iarg+5],false,lmp); + if (iarg + 6 > narg) error->all(FLERR, "Illegal fix pour command"); + vxlo = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + vxhi = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + vylo = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + vyhi = utils::numeric(FLERR, arg[iarg + 4], false, lmp); + if (vxlo > vxhi || vylo > vyhi) error->all(FLERR, "Illegal fix pour command"); + vz = utils::numeric(FLERR, arg[iarg + 5], false, lmp); iarg += 6; } else { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix pour command"); - vxlo = utils::numeric(FLERR,arg[iarg+1],false,lmp); - vxhi = utils::numeric(FLERR,arg[iarg+2],false,lmp); - vy = utils::numeric(FLERR,arg[iarg+3],false,lmp); + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix pour command"); + vxlo = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + vxhi = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + vy = utils::numeric(FLERR, arg[iarg + 3], false, lmp); vz = 0.0; - if (vxlo > vxhi) error->all(FLERR,"Illegal fix pour command"); + if (vxlo > vxhi) error->all(FLERR, "Illegal fix pour command"); iarg += 4; } - } else error->all(FLERR,"Illegal fix pour command"); + } else + error->all(FLERR, "Illegal fix pour command"); } } @@ -1044,7 +1033,7 @@ void FixPour::options(int narg, char **arg) void FixPour::reset_dt() { - error->all(FLERR,"Cannot change timestep with fix pour"); + error->all(FLERR, "Cannot change timestep with fix pour"); } /* ---------------------------------------------------------------------- @@ -1053,10 +1042,12 @@ void FixPour::reset_dt() void *FixPour::extract(const char *str, int &itype) { - if (strcmp(str,"radius") == 0) { + if (strcmp(str, "radius") == 0) { if (mode == ATOM) { - if (itype == ntype) oneradius = radius_max; - else oneradius = 0.0; + if (itype == ntype) + oneradius = radius_max; + else + oneradius = 0.0; } else { @@ -1065,7 +1056,7 @@ void *FixPour::extract(const char *str, int &itype) oneradius = 0.0; for (int i = 0; i < nmol; i++) { - if (itype > ntype+onemols[i]->ntypes) continue; + if (itype > ntype + onemols[i]->ntypes) continue; double *radius = onemols[i]->radius; int *type = onemols[i]->type; int natoms = onemols[i]->natoms; @@ -1075,9 +1066,11 @@ void *FixPour::extract(const char *str, int &itype) // same as atom->avec->create_atom(), invoked in pre_exchange() for (int i = 0; i < natoms; i++) - if (type[i]+ntype == itype) { - if (radius) oneradius = MAX(oneradius,radius[i]); - else oneradius = MAX(oneradius,0.5); + if (type[i] + ntype == itype) { + if (radius) + oneradius = MAX(oneradius, radius[i]); + else + oneradius = MAX(oneradius, 0.5); } } } diff --git a/src/GRANULAR/fix_pour.h b/src/GRANULAR/fix_pour.h index 16ef3b7f32..d22b6e4b1e 100644 --- a/src/GRANULAR/fix_pour.h +++ b/src/GRANULAR/fix_pour.h @@ -37,7 +37,7 @@ class FixPour : public Fix { private: int ninsert, ntype, seed; - int iregion, mode, idnext, dstyle, npoly, rigidflag, shakeflag; + int mode, idnext, dstyle, npoly, rigidflag, shakeflag; int ignoreflag, ignoreline, ignoretri; double radius_one, radius_max; double radius_lo, radius_hi; @@ -52,6 +52,8 @@ class FixPour : public Fix { double xc, yc, rc; double grav; char *idrigid, *idshake; + char *idregion; + class Region *region; class Molecule **onemols; int nmol, natom_max; diff --git a/src/GRANULAR/fix_wall_gran_region.cpp b/src/GRANULAR/fix_wall_gran_region.cpp index f04b03b340..dc2bfce142 100644 --- a/src/GRANULAR/fix_wall_gran_region.cpp +++ b/src/GRANULAR/fix_wall_gran_region.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -35,21 +34,16 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixWallGranRegion::FixWallGranRegion(LAMMPS *lmp, int narg, char **arg) : - FixWallGran(lmp, narg, arg), region(nullptr), region_style(nullptr), - ncontact(nullptr), - walls(nullptr), history_many(nullptr), c2r(nullptr) + FixWallGran(lmp, narg, arg), region(nullptr), ncontact(nullptr), walls(nullptr), + history_many(nullptr), c2r(nullptr) { restart_global = 1; motion_resetflag = 0; - int iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix wall/gran/region does not exist"); - region = domain->regions[iregion]; - region_style = utils::strdup(region->style); + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix wall/gran/region does not exist", idregion); nregion = region->nregion; - - tmax = domain->regions[iregion]->tmax; + tmax = region->tmax; c2r = new int[tmax]; // re-allocate atom-based arrays with nshear @@ -67,8 +61,7 @@ FixWallGranRegion::FixWallGranRegion(LAMMPS *lmp, int narg, char **arg) : if (use_history) { int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) - ncontact[i] = 0; + for (int i = 0; i < nlocal; i++) ncontact[i] = 0; } } @@ -76,8 +69,8 @@ FixWallGranRegion::FixWallGranRegion(LAMMPS *lmp, int narg, char **arg) : FixWallGranRegion::~FixWallGranRegion() { - delete [] c2r; - delete [] region_style; + delete[] c2r; + delete[] region_style; memory->destroy(ncontact); memory->destroy(walls); @@ -90,25 +83,32 @@ void FixWallGranRegion::init() { FixWallGran::init(); - int iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix wall/gran/region does not exist"); - region = domain->regions[iregion]; + auto newregion = domain->get_region_by_id(idregion); + if (!newregion) error->all(FLERR, "Region {} for fix wall/gran/region does not exist", idregion); // check if region properties changed between runs // reset if restart info was inconsistent - if ((strcmp(idregion,region->id) != 0) - || (strcmp(region_style,region->style) != 0) - || (nregion != region->nregion)) { - error->warning(FLERR,"Region properties for region {} changed between " - "runs, resetting its motion",idregion); + if (newregion != region) { + region = newregion; + if (comm->me == 0) + error->warning(FLERR, + "Region properties for region {} changed between runs, resetting its motion", + idregion); + nregion = region->nregion; + tmax = region->tmax; + delete[] c2r; + c2r = new int[tmax]; + region = newregion; region->reset_vel(); } if (motion_resetflag) { - error->warning(FLERR,"Region properties for region {} are inconsistent " - "with restart file, resetting its motion",idregion); + if (comm->me == 0) + error->warning(FLERR, + "Region properties for region {} are inconsistent with restart file, " + "resetting its motion", + idregion); region->reset_vel(); } } @@ -117,8 +117,8 @@ void FixWallGranRegion::init() void FixWallGranRegion::post_force(int /*vflag*/) { - int i,m,nc,iwall; - double dx,dy,dz,rsq,meff; + int i, m, nc, iwall; + double dx, dy, dz, rsq, meff; double vwall[3]; // do not update shear history during setup @@ -133,17 +133,19 @@ void FixWallGranRegion::post_force(int /*vflag*/) if (neighbor->ago == 0 && fix_rigid) { int tmp; - int *body = (int *) fix_rigid->extract("body",tmp); - auto mass_body = (double *) fix_rigid->extract("masstotal",tmp); + int *body = (int *) fix_rigid->extract("body", tmp); + auto mass_body = (double *) fix_rigid->extract("masstotal", tmp); if (atom->nmax > nmax) { memory->destroy(mass_rigid); nmax = atom->nmax; - memory->create(mass_rigid,nmax,"wall/gran:mass_rigid"); + memory->create(mass_rigid, nmax, "wall/gran:mass_rigid"); } int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - if (body[i] >= 0) mass_rigid[i] = mass_body[body[i]]; - else mass_rigid[i] = 0.0; + if (body[i] >= 0) + mass_rigid[i] = mass_body[body[i]]; + else + mass_rigid[i] = 0.0; } } @@ -169,23 +171,18 @@ void FixWallGranRegion::post_force(int /*vflag*/) region->set_velocity(); } - if (peratom_flag) { - clear_stored_contacts(); - } + if (peratom_flag) { clear_stored_contacts(); } for (i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (!region->match(x[i][0],x[i][1],x[i][2])) continue; + if (!region->match(x[i][0], x[i][1], x[i][2])) continue; if (pairstyle == FixWallGran::GRANULAR && normal_model == FixWallGran::JKR) { - nc = region->surface(x[i][0],x[i][1],x[i][2], - radius[i]+pulloff_distance(radius[i])); + nc = region->surface(x[i][0], x[i][1], x[i][2], radius[i] + pulloff_distance(radius[i])); + } else { + nc = region->surface(x[i][0], x[i][1], x[i][2], radius[i]); } - else{ - nc = region->surface(x[i][0],x[i][1],x[i][2],radius[i]); - } - if (nc > tmax) - error->one(FLERR,"Too many wall/gran/region contacts for one particle"); + if (nc > tmax) error->one(FLERR, "Too many wall/gran/region contacts for one particle"); // shear history maintenance // update ncontact,walls,shear2many for particle I @@ -204,11 +201,11 @@ void FixWallGranRegion::post_force(int /*vflag*/) if (ncontact[i] == 0) { ncontact[i] = 1; walls[i][0] = iwall; - for (m = 0; m < size_history; m++) - history_many[i][0][m] = 0.0; + for (m = 0; m < size_history; m++) history_many[i][0][m] = 0.0; } else if (ncontact[i] > 1 || iwall != walls[i][0]) - update_contacts(i,nc); - } else update_contacts(i,nc); + update_contacts(i, nc); + } else + update_contacts(i, nc); } // process current contacts @@ -217,12 +214,11 @@ void FixWallGranRegion::post_force(int /*vflag*/) // rsq = squared contact distance // xc = contact point - rsq = region->contact[ic].r*region->contact[ic].r; + rsq = region->contact[ic].r * region->contact[ic].r; if (pairstyle == FixWallGran::GRANULAR && normal_model == FixWallGran::JKR) { - if (history_many[i][c2r[ic]][0] == 0.0 && rsq > radius[i]*radius[i]) { - for (m = 0; m < size_history; m++) - history_many[i][0][m] = 0.0; + if (history_many[i][c2r[ic]][0] == 0.0 && rsq > radius[i] * radius[i]) { + for (m = 0; m < size_history; m++) history_many[i][0][m] = 0.0; continue; } } @@ -256,20 +252,16 @@ void FixWallGranRegion::post_force(int /*vflag*/) contact = nullptr; if (pairstyle == FixWallGran::HOOKE) - hooke(rsq,dx,dy,dz,vwall,v[i],f[i], - omega[i],torque[i],radius[i],meff, contact); + hooke(rsq, dx, dy, dz, vwall, v[i], f[i], omega[i], torque[i], radius[i], meff, contact); else if (pairstyle == FixWallGran::HOOKE_HISTORY) - hooke_history(rsq,dx,dy,dz,vwall,v[i],f[i], - omega[i],torque[i],radius[i],meff, - history_many[i][c2r[ic]], contact); + hooke_history(rsq, dx, dy, dz, vwall, v[i], f[i], omega[i], torque[i], radius[i], meff, + history_many[i][c2r[ic]], contact); else if (pairstyle == FixWallGran::HERTZ_HISTORY) - hertz_history(rsq,dx,dy,dz,vwall,region->contact[ic].radius, - v[i],f[i],omega[i],torque[i], - radius[i],meff,history_many[i][c2r[ic]], contact); + hertz_history(rsq, dx, dy, dz, vwall, region->contact[ic].radius, v[i], f[i], omega[i], + torque[i], radius[i], meff, history_many[i][c2r[ic]], contact); else if (pairstyle == FixWallGran::GRANULAR) - granular(rsq,dx,dy,dz,vwall,region->contact[ic].radius, - v[i],f[i],omega[i],torque[i], - radius[i],meff,history_many[i][c2r[ic]],contact); + granular(rsq, dx, dy, dz, vwall, region->contact[ic].radius, v[i], f[i], omega[i], + torque[i], radius[i], meff, history_many[i][c2r[ic]], contact); } } } @@ -285,7 +277,7 @@ void FixWallGranRegion::post_force(int /*vflag*/) void FixWallGranRegion::update_contacts(int i, int nc) { - int j,m,iold,nold,ilast,inew,iadd,iwall; + int j, m, iold, nold, ilast, inew, iadd, iwall; // loop over old contacts // if not in new contact list: @@ -296,12 +288,12 @@ void FixWallGranRegion::update_contacts(int i, int nc) for (m = 0; m < nc; m++) if (region->contact[m].iwall == walls[i][iold]) break; if (m >= nc) { - ilast = ncontact[i]-1; - for (j = 0; j < size_history; j++) - history_many[i][iold][j] = history_many[i][ilast][j]; + ilast = ncontact[i] - 1; + for (j = 0; j < size_history; j++) history_many[i][iold][j] = history_many[i][ilast][j]; walls[i][iold] = walls[i][ilast]; ncontact[i]--; - } else iold++; + } else + iold++; } // loop over new contacts @@ -315,13 +307,13 @@ void FixWallGranRegion::update_contacts(int i, int nc) iwall = region->contact[inew].iwall; for (m = 0; m < nold; m++) if (walls[i][m] == iwall) break; - if (m < nold) c2r[m] = inew; + if (m < nold) + c2r[m] = inew; else { iadd = ncontact[i]; c2r[iadd] = inew; - for (j = 0; j < size_history; j++) - history_many[i][iadd][j] = 0.0; + for (j = 0; j < size_history; j++) history_many[i][iadd][j] = 0.0; walls[i][iadd] = iwall; ncontact[i]++; } @@ -336,12 +328,12 @@ double FixWallGranRegion::memory_usage() { int nmax = atom->nmax; double bytes = 0.0; - if (use_history) { // shear history - bytes += (double)nmax * sizeof(int); // ncontact - bytes += (double)nmax*tmax * sizeof(int); // walls - bytes += (double)nmax*tmax*size_history * sizeof(double); // history_many + if (use_history) { // shear history + bytes += (double) nmax * sizeof(int); // ncontact + bytes += (double) nmax * tmax * sizeof(int); // walls + bytes += (double) nmax * tmax * size_history * sizeof(double); // history_many } - if (fix_rigid) bytes += (double)nmax * sizeof(int); // mass_rigid + if (fix_rigid) bytes += (double) nmax * sizeof(int); // mass_rigid return bytes; } @@ -352,12 +344,11 @@ double FixWallGranRegion::memory_usage() void FixWallGranRegion::grow_arrays(int nmax) { if (use_history) { - memory->grow(ncontact,nmax,"fix_wall_gran:ncontact"); - memory->grow(walls,nmax,tmax,"fix_wall_gran:walls"); - memory->grow(history_many,nmax,tmax,size_history,"fix_wall_gran:history_many"); + memory->grow(ncontact, nmax, "fix_wall_gran:ncontact"); + memory->grow(walls, nmax, tmax, "fix_wall_gran:walls"); + memory->grow(history_many, nmax, tmax, size_history, "fix_wall_gran:history_many"); } - if (peratom_flag) - memory->grow(array_atom,nmax,size_peratom_cols,"fix_wall_gran:array_atom"); + if (peratom_flag) memory->grow(array_atom, nmax, size_peratom_cols, "fix_wall_gran:array_atom"); } /* ---------------------------------------------------------------------- @@ -366,21 +357,19 @@ void FixWallGranRegion::grow_arrays(int nmax) void FixWallGranRegion::copy_arrays(int i, int j, int /*delflag*/) { - int m,n,iwall; + int m, n, iwall; if (use_history) { n = ncontact[i]; for (iwall = 0; iwall < n; iwall++) { walls[j][iwall] = walls[i][iwall]; - for (m = 0; m < size_history; m++) - history_many[j][iwall][m] = history_many[i][iwall][m]; + for (m = 0; m < size_history; m++) history_many[j][iwall][m] = history_many[i][iwall][m]; } ncontact[j] = ncontact[i]; } if (peratom_flag) { - for (int m = 0; m < size_peratom_cols; m++) - array_atom[j][m] = array_atom[i][m]; + for (int m = 0; m < size_peratom_cols; m++) array_atom[j][m] = array_atom[i][m]; } } @@ -390,11 +379,9 @@ void FixWallGranRegion::copy_arrays(int i, int j, int /*delflag*/) void FixWallGranRegion::set_arrays(int i) { - if (use_history) - ncontact[i] = 0; + if (use_history) ncontact[i] = 0; if (peratom_flag) { - for (int m = 0; m < size_peratom_cols; m++) - array_atom[i][m] = 0; + for (int m = 0; m < size_peratom_cols; m++) array_atom[i][m] = 0; } } @@ -412,13 +399,11 @@ int FixWallGranRegion::pack_exchange(int i, double *buf) buf[n++] = ubuf(count).d; for (int iwall = 0; iwall < count; iwall++) { buf[n++] = ubuf(walls[i][iwall]).d; - for (m = 0; m < size_history; m++) - buf[n++] = history_many[i][iwall][m]; + for (m = 0; m < size_history; m++) buf[n++] = history_many[i][iwall][m]; } } if (peratom_flag) { - for (int m = 0; m < size_peratom_cols; m++) - buf[n++] = array_atom[i][m]; + for (int m = 0; m < size_peratom_cols; m++) buf[n++] = array_atom[i][m]; } return n; @@ -432,19 +417,16 @@ int FixWallGranRegion::unpack_exchange(int nlocal, double *buf) { int m; - int n = 0; if (use_history) { int count = ncontact[nlocal] = (int) ubuf(buf[n++]).i; for (int iwall = 0; iwall < count; iwall++) { walls[nlocal][iwall] = (int) ubuf(buf[n++]).i; - for (m = 0; m < size_history; m++) - history_many[nlocal][iwall][m] = buf[n++]; + for (m = 0; m < size_history; m++) history_many[nlocal][iwall][m] = buf[n++]; } } if (peratom_flag) { - for (int m = 0; m < size_peratom_cols; m++) - array_atom[nlocal][m] = buf[n++]; + for (int m = 0; m < size_peratom_cols; m++) array_atom[nlocal][m] = buf[n++]; } return n; @@ -466,8 +448,7 @@ int FixWallGranRegion::pack_restart(int i, double *buf) buf[n++] = ubuf(count).d; for (int iwall = 0; iwall < count; iwall++) { buf[n++] = ubuf(walls[i][iwall]).d; - for (m = 0; m < size_history; m++) - buf[n++] = history_many[i][iwall][m]; + for (m = 0; m < size_history; m++) buf[n++] = history_many[i][iwall][m]; } // pack buf[0] this way because other fixes unpack it buf[0] = n; @@ -490,14 +471,13 @@ void FixWallGranRegion::unpack_restart(int nlocal, int nth) // unpack the Nth first values this way because other fixes pack them int m = 0; - for (int i = 0; i < nth; i++) m += static_cast (extra[nlocal][m]); + for (int i = 0; i < nth; i++) m += static_cast(extra[nlocal][m]); m++; int count = ncontact[nlocal] = (int) ubuf(extra[nlocal][m++]).i; for (int iwall = 0; iwall < count; iwall++) { walls[nlocal][iwall] = (int) ubuf(extra[nlocal][m++]).i; - for (k = 0; k < size_history; k++) - history_many[nlocal][iwall][k] = extra[nlocal][m++]; + for (k = 0; k < size_history; k++) history_many[nlocal][iwall][k] = extra[nlocal][m++]; } } @@ -508,7 +488,7 @@ void FixWallGranRegion::unpack_restart(int nlocal, int nth) int FixWallGranRegion::maxsize_restart() { if (!use_history) return 0; - return 2 + tmax*(size_history+1); + return 2 + tmax * (size_history + 1); } /* ---------------------------------------------------------------------- @@ -518,7 +498,7 @@ int FixWallGranRegion::maxsize_restart() int FixWallGranRegion::size_restart(int nlocal) { if (!use_history) return 0; - return 2 + ncontact[nlocal]*(size_history+1); + return 2 + ncontact[nlocal] * (size_history + 1); } /* ---------------------------------------------------------------------- @@ -530,7 +510,7 @@ void FixWallGranRegion::write_restart(FILE *fp) if (comm->me) return; int len = 0; region->length_restart_string(len); - fwrite(&len, sizeof(int),1,fp); + fwrite(&len, sizeof(int), 1, fp); region->write_restart(fp); } @@ -541,5 +521,5 @@ void FixWallGranRegion::write_restart(FILE *fp) void FixWallGranRegion::restart(char *buf) { int n = 0; - if (!region->restart(buf,n)) motion_resetflag = 1; + if (!region->restart(buf, n)) motion_resetflag = 1; } 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" " all(FLERR, "Illegal fix setvelocity command"); + Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr), + region(nullptr), sforce(nullptr) +{ + if (narg < 6) error->all(FLERR, "Illegal fix setvelocity command"); - dynamic_group_allow = 1; - vector_flag = 1; - size_vector = 3; - global_freq = 1; - extvector = 1; + dynamic_group_allow = 1; + vector_flag = 1; + size_vector = 3; + global_freq = 1; + extvector = 1; - xstr = ystr = zstr = nullptr; + if (strstr(arg[3], "v_") == arg[3]) { + xstr = utils::strdup(&arg[3][2]); + } else if (strcmp(arg[3], "NULL") == 0) { + xstyle = NONE; + } else { + xvalue = utils::numeric(FLERR, arg[3], false, lmp); + xstyle = CONSTANT; + } + if (strstr(arg[4], "v_") == arg[4]) { + ystr = utils::strdup(&arg[4][2]); + } else if (strcmp(arg[4], "NULL") == 0) { + ystyle = NONE; + } else { + yvalue = utils::numeric(FLERR, arg[4], false, lmp); + ystyle = CONSTANT; + } + if (strstr(arg[5], "v_") == arg[5]) { + zstr = utils::strdup(&arg[5][2]); + } else if (strcmp(arg[5], "NULL") == 0) { + zstyle = NONE; + } else { + zvalue = utils::numeric(FLERR, arg[5], false, lmp); + zstyle = CONSTANT; + } - if (strstr(arg[3], "v_") == arg[3]) { - xstr = utils::strdup( &arg[3][2]); - } else if (strcmp(arg[3], "NULL") == 0) { - xstyle = NONE; - } else { - xvalue = utils::numeric(FLERR, arg[3],false,lmp); - xstyle = CONSTANT; - } - if (strstr(arg[4], "v_") == arg[4]) { - ystr = utils::strdup( &arg[4][2]); - } else if (strcmp(arg[4], "NULL") == 0) { - ystyle = NONE; - } else { - yvalue = utils::numeric(FLERR, arg[4],false,lmp); - ystyle = CONSTANT; - } - if (strstr(arg[5], "v_") == arg[5]) { - zstr = utils::strdup( &arg[5][2]); - } else if (strcmp(arg[5], "NULL") == 0) { - zstyle = NONE; - } else { - zvalue = utils::numeric(FLERR, arg[5],false,lmp); - zstyle = CONSTANT; - } + // optional args - // optional args + int iarg = 6; + while (iarg < narg) { + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix setvelocity command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix setvelocity does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); + iarg += 2; + } else + error->all(FLERR, "Illegal fix setvelocity command"); + } - iregion = -1; - idregion = nullptr; + force_flag = 0; + foriginal[0] = foriginal[1] = foriginal[2] = 0.0; - int iarg = 6; - while (iarg < narg) { - if (strcmp(arg[iarg], "region") == 0) { - if (iarg + 2 > narg) - error->all(FLERR, "Illegal fix setvelocity command"); - iregion = domain->find_region(arg[iarg + 1]); - if (iregion == -1) - error->all(FLERR, "Region ID for fix setvelocity does not exist"); - idregion = utils::strdup( arg[iarg + 1]); - iarg += 2; - } else - error->all(FLERR, "Illegal fix setvelocity command"); - } - - force_flag = 0; - foriginal[0] = foriginal[1] = foriginal[2] = 0.0; - - maxatom = atom->nmax; - memory->create(sforce, maxatom, 3, "setvelocity:sforce"); + maxatom = atom->nmax; + memory->create(sforce, maxatom, 3, "setvelocity:sforce"); } /* ---------------------------------------------------------------------- */ -FixSMDSetVel::~FixSMDSetVel() { - delete[] xstr; - delete[] ystr; - delete[] zstr; - delete[] idregion; - memory->destroy(sforce); +FixSMDSetVel::~FixSMDSetVel() +{ + delete[] xstr; + delete[] ystr; + delete[] zstr; + delete[] idregion; + memory->destroy(sforce); } /* ---------------------------------------------------------------------- */ -int FixSMDSetVel::setmask() { - int mask = 0; - //mask |= INITIAL_INTEGRATE; - mask |= POST_FORCE; - return mask; +int FixSMDSetVel::setmask() +{ + int mask = 0; + mask |= POST_FORCE; + return mask; } /* ---------------------------------------------------------------------- */ -void FixSMDSetVel::init() { - // check variables +void FixSMDSetVel::init() +{ + // check variables - if (xstr) { - xvar = input->variable->find(xstr); - if (xvar < 0) - error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); - } - if (ystr) { - yvar = input->variable->find(ystr); - if (yvar < 0) - error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); - } - if (zstr) { - zvar = input->variable->find(zstr); - if (zvar < 0) - error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); - } + if (xstr) { + xvar = input->variable->find(xstr); + if (xvar < 0) error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); + } + if (ystr) { + yvar = input->variable->find(ystr); + if (yvar < 0) error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); + } + if (zstr) { + zvar = input->variable->find(zstr); + if (zvar < 0) error->all(FLERR, "Variable name for fix setvelocity 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 setvelocity is invalid style"); + } - // set index and check validity of region + // 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 setvelocity does not exist"); - } + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix setvelocity 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; + if (xstyle == ATOM || ystyle == ATOM || zstyle == ATOM) + varflag = ATOM; + else if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) + varflag = EQUAL; + else + varflag = CONSTANT; - // cannot use non-zero forces for a minimization since no energy is integrated - // use fix addforce instead + // cannot use non-zero forces for a minimization since no energy is integrated + // use fix addforce instead - int flag = 0; - if (update->whichflag == 2) { - if (xstyle == EQUAL || xstyle == ATOM) - flag = 1; - if (ystyle == EQUAL || ystyle == ATOM) - flag = 1; - if (zstyle == EQUAL || zstyle == ATOM) - flag = 1; - if (xstyle == CONSTANT && xvalue != 0.0) - flag = 1; - 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"); + int flag = 0; + if (update->whichflag == 2) { + if (xstyle == EQUAL || xstyle == ATOM) flag = 1; + if (ystyle == EQUAL || ystyle == ATOM) flag = 1; + if (zstyle == EQUAL || zstyle == ATOM) flag = 1; + if (xstyle == CONSTANT && xvalue != 0.0) flag = 1; + 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"); } /* ---------------------------------------------------------------------- */ -void FixSMDSetVel::setup(int vflag) { - if (utils::strmatch(update->integrate_style,"^verlet")) - post_force(vflag); - else - error->all(FLERR,"Fix smd/setvel does not support RESPA"); +void FixSMDSetVel::setup(int vflag) +{ + if (utils::strmatch(update->integrate_style, "^verlet")) + post_force(vflag); + else + error->all(FLERR, "Fix smd/setvel does not support RESPA"); } /* ---------------------------------------------------------------------- */ -void FixSMDSetVel::min_setup(int vflag) { - post_force(vflag); +void FixSMDSetVel::min_setup(int vflag) +{ + post_force(vflag); } /* ---------------------------------------------------------------------- */ -//void FixSMDSetVel::initial_integrate(int vflag) { -void FixSMDSetVel::post_force(int /*vflag*/) { - double **x = atom->x; - double **f = atom->f; - double **v = atom->v; - double **vest = atom->vest; - int *mask = atom->mask; - int nlocal = atom->nlocal; +void FixSMDSetVel::post_force(int /*vflag*/) +{ + double **x = atom->x; + double **f = atom->f; + double **v = atom->v; + double **vest = atom->vest; + int *mask = atom->mask; + int nlocal = atom->nlocal; - // update region if necessary + // 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, "setvelocity:sforce"); + } + + foriginal[0] = foriginal[1] = foriginal[2] = 0.0; + force_flag = 0; + + 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; + foriginal[0] += f[i][0]; + foriginal[1] += f[i][1]; + foriginal[2] += f[i][2]; + if (xstyle) { + v[i][0] = xvalue; + vest[i][0] = xvalue; + f[i][0] = 0.0; + } + if (ystyle) { + v[i][1] = yvalue; + vest[i][1] = yvalue; + f[i][1] = 0.0; + } + if (zstyle) { + v[i][2] = zvalue; + vest[i][2] = zvalue; + f[i][2] = 0.0; + } + } + + // variable force, wrap with clear/add + + } else { + + modify->clearstep_compute(); + + 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); + else if (ystyle == ATOM) + 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); + + 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; + foriginal[0] += f[i][0]; + foriginal[1] += f[i][1]; + foriginal[2] += f[i][2]; + if (xstyle == ATOM) { + vest[i][0] = v[i][0] = sforce[i][0]; + f[i][0] = 0.0; + } else if (xstyle) { + vest[i][0] = v[i][0] = xvalue; + f[i][0] = 0.0; } - // reallocate sforce array if necessary - - if (varflag == ATOM && atom->nmax > maxatom) { - maxatom = atom->nmax; - memory->destroy(sforce); - memory->create(sforce, maxatom, 3, "setvelocity:sforce"); + if (ystyle == ATOM) { + vest[i][1] = v[i][1] = sforce[i][1]; + f[i][1] = 0.0; + } else if (ystyle) { + vest[i][1] = v[i][1] = yvalue; + f[i][1] = 0.0; } - foriginal[0] = foriginal[1] = foriginal[2] = 0.0; - force_flag = 0; - - 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; - foriginal[0] += f[i][0]; - foriginal[1] += f[i][1]; - foriginal[2] += f[i][2]; - if (xstyle) { - v[i][0] = xvalue; - vest[i][0] = xvalue; - f[i][0] = 0.0; - } - if (ystyle) { - v[i][1] = yvalue; - vest[i][1] = yvalue; - f[i][1] = 0.0; - } - if (zstyle) { - v[i][2] = zvalue; - vest[i][2] = zvalue; - f[i][2] = 0.0; - } - } - - // variable force, wrap with clear/add - - } else { - - modify->clearstep_compute(); - - 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); - else if (ystyle == ATOM) - 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); - - modify->addstep_compute(update->ntimestep + 1); - - //printf("setting velocity at timestep %d\n", update->ntimestep); - - 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; - foriginal[0] += f[i][0]; - foriginal[1] += f[i][1]; - foriginal[2] += f[i][2]; - if (xstyle == ATOM) { - vest[i][0] = v[i][0] = sforce[i][0]; - f[i][0] = 0.0; - } else if (xstyle) { - vest[i][0] = v[i][0] = xvalue; - f[i][0] = 0.0; - } - - if (ystyle == ATOM) { - vest[i][1] = v[i][1] = sforce[i][1]; - f[i][1] = 0.0; - } else if (ystyle) { - vest[i][1] = v[i][1] = yvalue; - f[i][1] = 0.0; - } - - if (zstyle == ATOM) { - vest[i][2] = v[i][2] = sforce[i][2]; - f[i][2] = 0.0; - } else if (zstyle) { - vest[i][2] = v[i][2] = zvalue; - f[i][2] = 0.0; - } - - } + if (zstyle == ATOM) { + vest[i][2] = v[i][2] = sforce[i][2]; + f[i][2] = 0.0; + } else if (zstyle) { + vest[i][2] = v[i][2] = zvalue; + f[i][2] = 0.0; } + } + } } /* ---------------------------------------------------------------------- return components of total force on fix group before force was changed ------------------------------------------------------------------------- */ -double FixSMDSetVel::compute_vector(int n) { -// only sum across procs one time +double FixSMDSetVel::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); - force_flag = 1; - } - return foriginal_all[n]; + if (force_flag == 0) { + MPI_Allreduce(foriginal, foriginal_all, 3, MPI_DOUBLE, MPI_SUM, world); + force_flag = 1; + } + return foriginal_all[n]; } /* ---------------------------------------------------------------------- memory usage of local atom-based array ------------------------------------------------------------------------- */ -double FixSMDSetVel::memory_usage() { - double bytes = 0.0; - if (varflag == ATOM) - bytes = atom->nmax * 3 * sizeof(double); - return bytes; +double FixSMDSetVel::memory_usage() +{ + double bytes = 0.0; + if (varflag == ATOM) bytes = atom->nmax * 3 * sizeof(double); + return bytes; } diff --git a/src/MACHDYN/fix_smd_setvel.h b/src/MACHDYN/fix_smd_setvel.h index 30071d0875..5fd0d2637c 100644 --- a/src/MACHDYN/fix_smd_setvel.h +++ b/src/MACHDYN/fix_smd_setvel.h @@ -50,9 +50,10 @@ class FixSMDSetVel : public Fix { private: 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]; int force_flag; diff --git a/src/MANIFOLD/manifold_thylakoid.h b/src/MANIFOLD/manifold_thylakoid.h index 01b54ed108..5c30ccbdba 100644 --- a/src/MANIFOLD/manifold_thylakoid.h +++ b/src/MANIFOLD/manifold_thylakoid.h @@ -37,6 +37,7 @@ namespace user_manifold { int nparams() override { return NPARAMS; } void post_param_init() override; + private: void init_domains(); diff --git a/src/MANYBODY/pair_edip.cpp b/src/MANYBODY/pair_edip.cpp index 23361e56cb..8becba670b 100644 --- a/src/MANYBODY/pair_edip.cpp +++ b/src/MANYBODY/pair_edip.cpp @@ -369,7 +369,7 @@ void PairEDIP::compute(int eflag, int vflag) directorCos_ik_z = invR_ik * dr_ik[2]; cosTeta = directorCos_ij_x * directorCos_ik_x + directorCos_ij_y * directorCos_ik_y + - directorCos_ij_z * directorCos_ik_z; + directorCos_ij_z * directorCos_ik_z; cosTetaDiff = cosTeta + tauFunction; cosTetaDiffCosTetaDiff = cosTetaDiff * cosTetaDiff; @@ -377,33 +377,33 @@ void PairEDIP::compute(int eflag, int vflag) expMinusQFunctionCosTetaDiffCosTetaDiff = exp(-qFunctionCosTetaDiffCosTetaDiff); potentia3B_factor = lambda * - ((1.0 - expMinusQFunctionCosTetaDiffCosTetaDiff) + - eta * qFunctionCosTetaDiffCosTetaDiff); + ((1.0 - expMinusQFunctionCosTetaDiffCosTetaDiff) + + eta * qFunctionCosTetaDiffCosTetaDiff); exp3B_ik = preExp3B_ij[neighbor_k]; exp3BDerived_ik = preExp3BDerived_ij[neighbor_k]; forceMod3B_factor1_ij = -exp3BDerived_ij * exp3B_ik * potentia3B_factor; forceMod3B_factor2 = 2.0 * lambda * exp3B_ij * exp3B_ik * qFunction * cosTetaDiff * - (eta + expMinusQFunctionCosTetaDiffCosTetaDiff); + (eta + expMinusQFunctionCosTetaDiffCosTetaDiff); forceMod3B_factor2_ij = forceMod3B_factor2 * invR_ij; f_ij[0] = forceMod3B_factor1_ij * directorCos_ij_x + - forceMod3B_factor2_ij * (cosTeta * directorCos_ij_x - directorCos_ik_x); + forceMod3B_factor2_ij * (cosTeta * directorCos_ij_x - directorCos_ik_x); f_ij[1] = forceMod3B_factor1_ij * directorCos_ij_y + - forceMod3B_factor2_ij * (cosTeta * directorCos_ij_y - directorCos_ik_y); + forceMod3B_factor2_ij * (cosTeta * directorCos_ij_y - directorCos_ik_y); f_ij[2] = forceMod3B_factor1_ij * directorCos_ij_z + - forceMod3B_factor2_ij * (cosTeta * directorCos_ij_z - directorCos_ik_z); + forceMod3B_factor2_ij * (cosTeta * directorCos_ij_z - directorCos_ik_z); forceMod3B_factor1_ik = -exp3BDerived_ik * exp3B_ij * potentia3B_factor; forceMod3B_factor2_ik = forceMod3B_factor2 * invR_ik; f_ik[0] = forceMod3B_factor1_ik * directorCos_ik_x + - forceMod3B_factor2_ik * (cosTeta * directorCos_ik_x - directorCos_ij_x); + forceMod3B_factor2_ik * (cosTeta * directorCos_ik_x - directorCos_ij_x); f_ik[1] = forceMod3B_factor1_ik * directorCos_ik_y + - forceMod3B_factor2_ik * (cosTeta * directorCos_ik_y - directorCos_ij_y); + forceMod3B_factor2_ik * (cosTeta * directorCos_ik_y - directorCos_ij_y); f_ik[2] = forceMod3B_factor1_ik * directorCos_ik_z + - forceMod3B_factor2_ik * (cosTeta * directorCos_ik_z - directorCos_ij_z); + forceMod3B_factor2_ik * (cosTeta * directorCos_ik_z - directorCos_ij_z); forceModCoord += (forceMod3B_factor2 * (tauFunctionDerived - 0.5 * mu * cosTetaDiff)); @@ -800,13 +800,12 @@ void PairEDIP::read_file(char *file) if (nparams == maxparam) { maxparam += DELTA; - params = (Param *) memory->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.cpp b/src/MC/fix_atom_swap.cpp index 8405919db8..a231a94990 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -40,9 +39,9 @@ #include "region.h" #include "update.h" -#include #include #include +#include #include using namespace LAMMPS_NS; @@ -51,13 +50,12 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixAtomSwap::FixAtomSwap(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - idregion(nullptr), type_list(nullptr), mu(nullptr), qtype(nullptr), - sqrt_mass_ratio(nullptr), local_swap_iatom_list(nullptr), - local_swap_jatom_list(nullptr), local_swap_atom_list(nullptr), - random_equal(nullptr), random_unequal(nullptr), c_pe(nullptr) + Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), type_list(nullptr), mu(nullptr), + qtype(nullptr), sqrt_mass_ratio(nullptr), local_swap_iatom_list(nullptr), + local_swap_jatom_list(nullptr), local_swap_atom_list(nullptr), random_equal(nullptr), + random_unequal(nullptr), c_pe(nullptr) { - if (narg < 10) error->all(FLERR,"Illegal fix atom/swap command"); + if (narg < 10) error->all(FLERR, "Illegal fix atom/swap command"); dynamic_group_allow = 1; @@ -70,33 +68,33 @@ FixAtomSwap::FixAtomSwap(LAMMPS *lmp, int narg, char **arg) : // required args - nevery = utils::inumeric(FLERR,arg[3],false,lmp); - ncycles = utils::inumeric(FLERR,arg[4],false,lmp); - seed = utils::inumeric(FLERR,arg[5],false,lmp); - double temperature = utils::numeric(FLERR,arg[6],false,lmp); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); + ncycles = utils::inumeric(FLERR, arg[4], false, lmp); + seed = utils::inumeric(FLERR, arg[5], false, lmp); + double temperature = utils::numeric(FLERR, arg[6], false, lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix atom/swap command"); - if (ncycles < 0) error->all(FLERR,"Illegal fix atom/swap command"); - if (seed <= 0) error->all(FLERR,"Illegal fix atom/swap command"); - if (temperature <= 0.0) error->all(FLERR,"Illegal fix atom/swap command"); + if (nevery <= 0) error->all(FLERR, "Illegal fix atom/swap command"); + if (ncycles < 0) error->all(FLERR, "Illegal fix atom/swap command"); + if (seed <= 0) error->all(FLERR, "Illegal fix atom/swap command"); + if (temperature <= 0.0) error->all(FLERR, "Illegal fix atom/swap command"); - beta = 1.0/(force->boltz*temperature); + beta = 1.0 / (force->boltz * temperature); - memory->create(type_list,atom->ntypes,"atom/swap:type_list"); - memory->create(mu,atom->ntypes+1,"atom/swap:mu"); + memory->create(type_list, atom->ntypes, "atom/swap:type_list"); + memory->create(mu, atom->ntypes + 1, "atom/swap:mu"); for (int i = 1; i <= atom->ntypes; i++) mu[i] = 0.0; // read options from end of input line - options(narg-7,&arg[7]); + options(narg - 7, &arg[7]); // random number generator, same for all procs - random_equal = new RanPark(lmp,seed); + random_equal = new RanPark(lmp, seed); // random number generator, not the same for all procs - random_unequal = new RanPark(lmp,seed); + random_unequal = new RanPark(lmp, seed); // set up reneighboring @@ -115,9 +113,10 @@ FixAtomSwap::FixAtomSwap(LAMMPS *lmp, int narg, char **arg) : // set comm size needed by this Fix - if (atom->q_flag) comm_forward = 2; - else comm_forward = 1; - + if (atom->q_flag) + comm_forward = 2; + else + comm_forward = 1; } /* ---------------------------------------------------------------------- */ @@ -130,7 +129,7 @@ FixAtomSwap::~FixAtomSwap() memory->destroy(sqrt_mass_ratio); memory->destroy(local_swap_iatom_list); memory->destroy(local_swap_jatom_list); - if (regionflag) delete [] idregion; + delete[] idregion; delete random_equal; delete random_unequal; } @@ -141,54 +140,51 @@ FixAtomSwap::~FixAtomSwap() void FixAtomSwap::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR,"Illegal fix atom/swap command"); + if (narg < 0) error->all(FLERR, "Illegal fix atom/swap command"); - regionflag = 0; ke_flag = 1; semi_grand_flag = 0; nswaptypes = 0; nmutypes = 0; - iregion = -1; int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix atom/swap does not exist"); - idregion = utils::strdup(arg[iarg+1]); - regionflag = 1; + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix atom/swap command"); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix atom/swap does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"ke") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); - ke_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "ke") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix atom/swap command"); + ke_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"semi-grand") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); - semi_grand_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "semi-grand") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix atom/swap command"); + semi_grand_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"types") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal fix atom/swap command"); + } else if (strcmp(arg[iarg], "types") == 0) { + if (iarg + 3 > narg) error->all(FLERR, "Illegal fix atom/swap command"); iarg++; while (iarg < narg) { if (isalpha(arg[iarg][0])) break; - if (nswaptypes >= atom->ntypes) error->all(FLERR,"Illegal fix atom/swap command"); - type_list[nswaptypes] = utils::numeric(FLERR,arg[iarg],false,lmp); + if (nswaptypes >= atom->ntypes) error->all(FLERR, "Illegal fix atom/swap command"); + type_list[nswaptypes] = utils::numeric(FLERR, arg[iarg], false, lmp); nswaptypes++; iarg++; } - } else if (strcmp(arg[iarg],"mu") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix atom/swap command"); + } else if (strcmp(arg[iarg], "mu") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal fix atom/swap command"); iarg++; while (iarg < narg) { if (isalpha(arg[iarg][0])) break; nmutypes++; - if (nmutypes > atom->ntypes) error->all(FLERR,"Illegal fix atom/swap command"); - mu[nmutypes] = utils::numeric(FLERR,arg[iarg],false,lmp); + if (nmutypes > atom->ntypes) error->all(FLERR, "Illegal fix atom/swap command"); + mu[nmutypes] = utils::numeric(FLERR, arg[iarg], false, lmp); iarg++; } - } else error->all(FLERR,"Illegal fix atom/swap command"); + } else + error->all(FLERR, "Illegal fix atom/swap command"); } } @@ -205,36 +201,40 @@ int FixAtomSwap::setmask() void FixAtomSwap::init() { - auto id_pe = (char *) "thermo_pe"; - int ipe = modify->find_compute(id_pe); - c_pe = modify->compute[ipe]; + c_pe = modify->get_compute_by_id("thermo_pe"); int *type = atom->type; - if (nswaptypes < 2) - error->all(FLERR,"Must specify at least 2 types in fix atom/swap command"); + if (nswaptypes < 2) error->all(FLERR, "Must specify at least 2 types in fix atom/swap command"); if (semi_grand_flag) { if (nswaptypes != nmutypes) - error->all(FLERR,"Need nswaptypes mu values in fix atom/swap command"); + error->all(FLERR, "Need nswaptypes mu values in fix atom/swap command"); } else { if (nswaptypes != 2) - error->all(FLERR,"Only 2 types allowed when not using semi-grand in fix atom/swap command"); + error->all(FLERR, "Only 2 types allowed when not using semi-grand in fix atom/swap command"); if (nmutypes != 0) - error->all(FLERR,"Mu not allowed when not using semi-grand in fix atom/swap command"); + error->all(FLERR, "Mu not allowed when not using semi-grand in fix atom/swap command"); + } + + // set index and check validity of region + + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", idregion); } for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) if (type_list[iswaptype] <= 0 || type_list[iswaptype] > atom->ntypes) - error->all(FLERR,"Invalid atom type in fix atom/swap command"); + error->all(FLERR, "Invalid atom type in fix atom/swap command"); // this is only required for non-semi-grand // in which case, nswaptypes = 2 if (atom->q_flag && !semi_grand_flag) { - double qmax,qmin; - int firstall,first; - memory->create(qtype,nswaptypes,"atom/swap:qtype"); + double qmax, qmin; + int firstall, first; + memory->create(qtype, nswaptypes, "atom/swap:qtype"); for (int iswaptype = 0; iswaptype < nswaptypes; iswaptype++) { first = 1; for (int i = 0; i < atom->nlocal; i++) { @@ -244,24 +244,26 @@ void FixAtomSwap::init() qtype[iswaptype] = atom->q[i]; first = 0; } else if (qtype[iswaptype] != atom->q[i]) - error->one(FLERR,"All atoms of a swapped type must have the same charge."); + error->one(FLERR, "All atoms of a swapped type must have the same charge."); } } } - MPI_Allreduce(&first,&firstall,1,MPI_INT,MPI_MIN,world); - if (firstall) error->all(FLERR,"At least one atom of each swapped type must be present to define charges."); + MPI_Allreduce(&first, &firstall, 1, MPI_INT, MPI_MIN, world); + if (firstall) + error->all(FLERR, + "At least one atom of each swapped type must be present to define charges."); if (first) qtype[iswaptype] = -DBL_MAX; - MPI_Allreduce(&qtype[iswaptype],&qmax,1,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(&qtype[iswaptype], &qmax, 1, MPI_DOUBLE, MPI_MAX, world); if (first) qtype[iswaptype] = DBL_MAX; - MPI_Allreduce(&qtype[iswaptype],&qmin,1,MPI_DOUBLE,MPI_MIN,world); - if (qmax != qmin) error->all(FLERR,"All atoms of a swapped type must have same charge."); + MPI_Allreduce(&qtype[iswaptype], &qmin, 1, MPI_DOUBLE, MPI_MIN, world); + if (qmax != qmin) error->all(FLERR, "All atoms of a swapped type must have same charge."); } } - memory->create(sqrt_mass_ratio,atom->ntypes+1,atom->ntypes+1,"atom/swap:sqrt_mass_ratio"); + memory->create(sqrt_mass_ratio, atom->ntypes + 1, atom->ntypes + 1, "atom/swap:sqrt_mass_ratio"); for (int itype = 1; itype <= atom->ntypes; itype++) for (int jtype = 1; jtype <= atom->ntypes; jtype++) - sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype]/atom->mass[jtype]); + sqrt_mass_ratio[itype][jtype] = sqrt(atom->mass[itype] / atom->mass[jtype]); // check to see if itype and jtype cutoffs are the same // if not, reneighboring will be needed between swaps @@ -286,10 +288,9 @@ void FixAtomSwap::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 do atom/swap on atoms in atom_modify first group"); + if (flagall) error->all(FLERR, "Cannot do atom/swap on atoms in atom_modify first group"); } } @@ -309,7 +310,7 @@ void FixAtomSwap::pre_exchange() domain->pbc(); comm->exchange(); comm->borders(); - if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (domain->triclinic) domain->lamda2x(atom->nlocal + atom->nghost); if (modify->n_pre_neighbor) modify->pre_neighbor(); neighbor->build(1); @@ -353,14 +354,14 @@ int FixAtomSwap::attempt_semi_grand() // pick a random atom and perform swap - int itype,jtype,jswaptype; + int itype, jtype, jswaptype; int i = pick_semi_grand_atom(); if (i >= 0) { - jswaptype = static_cast (nswaptypes*random_unequal->uniform()); + jswaptype = static_cast(nswaptypes * random_unequal->uniform()); jtype = type_list[jswaptype]; itype = atom->type[i]; while (itype == jtype) { - jswaptype = static_cast (nswaptypes*random_unequal->uniform()); + jswaptype = static_cast(nswaptypes * random_unequal->uniform()); jtype = type_list[jswaptype]; } atom->type[i] = jtype; @@ -374,7 +375,7 @@ int FixAtomSwap::attempt_semi_grand() if (domain->triclinic) domain->x2lamda(atom->nlocal); comm->exchange(); comm->borders(); - if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (domain->triclinic) domain->lamda2x(atom->nlocal + atom->nghost); if (modify->n_pre_neighbor) modify->pre_neighbor(); neighbor->build(1); } else { @@ -389,11 +390,11 @@ int FixAtomSwap::attempt_semi_grand() int success = 0; if (i >= 0) if (random_unequal->uniform() < - exp(beta*(energy_before - energy_after - + mu[jtype] - mu[itype]))) success = 1; + exp(beta * (energy_before - energy_after + mu[jtype] - mu[itype]))) + success = 1; int success_all = 0; - MPI_Allreduce(&success,&success_all,1,MPI_INT,MPI_MAX,world); + MPI_Allreduce(&success, &success_all, 1, MPI_INT, MPI_MAX, world); // swap accepted, return 1 @@ -460,7 +461,7 @@ int FixAtomSwap::attempt_swap() domain->pbc(); comm->exchange(); comm->borders(); - if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (domain->triclinic) domain->lamda2x(atom->nlocal + atom->nghost); if (modify->n_pre_neighbor) modify->pre_neighbor(); neighbor->build(1); } else { @@ -474,8 +475,7 @@ int FixAtomSwap::attempt_swap() // swap accepted, return 1 // if ke_flag, rescale atom velocities - if (random_equal->uniform() < - exp(beta*(energy_before - energy_after))) { + if (random_equal->uniform() < exp(beta * (energy_before - energy_after))) { update_swap_atoms_list(); if (ke_flag) { if (i >= 0) { @@ -521,16 +521,16 @@ double FixAtomSwap::energy_full() if (modify->n_pre_force) modify->pre_force(vflag); - if (force->pair) force->pair->compute(eflag,vflag); + if (force->pair) force->pair->compute(eflag, vflag); if (atom->molecular != Atom::ATOMIC) { - if (force->bond) force->bond->compute(eflag,vflag); - if (force->angle) force->angle->compute(eflag,vflag); - if (force->dihedral) force->dihedral->compute(eflag,vflag); - if (force->improper) force->improper->compute(eflag,vflag); + if (force->bond) force->bond->compute(eflag, vflag); + if (force->angle) force->angle->compute(eflag, vflag); + if (force->dihedral) force->dihedral->compute(eflag, vflag); + if (force->improper) force->improper->compute(eflag, vflag); } - if (force->kspace) force->kspace->compute(eflag,vflag); + if (force->kspace) force->kspace->compute(eflag, vflag); if (modify->n_post_force_any) modify->post_force(vflag); @@ -546,9 +546,8 @@ double FixAtomSwap::energy_full() int FixAtomSwap::pick_semi_grand_atom() { int i = -1; - int iwhichglobal = static_cast (nswap*random_equal->uniform()); - if ((iwhichglobal >= nswap_before) && - (iwhichglobal < nswap_before + nswap_local)) { + int iwhichglobal = static_cast(nswap * random_equal->uniform()); + if ((iwhichglobal >= nswap_before) && (iwhichglobal < nswap_before + nswap_local)) { int iwhichlocal = iwhichglobal - nswap_before; i = local_swap_atom_list[iwhichlocal]; } @@ -562,9 +561,8 @@ int FixAtomSwap::pick_semi_grand_atom() int FixAtomSwap::pick_i_swap_atom() { int i = -1; - int iwhichglobal = static_cast (niswap*random_equal->uniform()); - if ((iwhichglobal >= niswap_before) && - (iwhichglobal < niswap_before + niswap_local)) { + int iwhichglobal = static_cast(niswap * random_equal->uniform()); + if ((iwhichglobal >= niswap_before) && (iwhichglobal < niswap_before + niswap_local)) { int iwhichlocal = iwhichglobal - niswap_before; i = local_swap_iatom_list[iwhichlocal]; } @@ -578,9 +576,8 @@ int FixAtomSwap::pick_i_swap_atom() int FixAtomSwap::pick_j_swap_atom() { int j = -1; - int jwhichglobal = static_cast (njswap*random_equal->uniform()); - if ((jwhichglobal >= njswap_before) && - (jwhichglobal < njswap_before + njswap_local)) { + int jwhichglobal = static_cast(njswap * random_equal->uniform()); + if ((jwhichglobal >= njswap_before) && (jwhichglobal < njswap_before + njswap_local)) { int jwhichlocal = jwhichglobal - njswap_before; j = local_swap_jatom_list[jwhichlocal]; } @@ -600,16 +597,15 @@ void FixAtomSwap::update_semi_grand_atoms_list() if (atom->nmax > atom_swap_nmax) { memory->sfree(local_swap_atom_list); atom_swap_nmax = atom->nmax; - local_swap_atom_list = (int *) memory->smalloc(atom_swap_nmax*sizeof(int), - "MCSWAP:local_swap_atom_list"); + local_swap_atom_list = + (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_atom_list"); } nswap_local = 0; - if (regionflag) { - + if (region) { for (int i = 0; i < nlocal; i++) { - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 1) { + if (region->match(x[i][0], x[i][1], x[i][2]) == 1) { if (atom->mask[i] & groupbit) { int itype = atom->type[i]; int iswaptype; @@ -625,23 +621,22 @@ void FixAtomSwap::update_semi_grand_atoms_list() } else { for (int i = 0; i < nlocal; i++) { if (atom->mask[i] & groupbit) { - int itype = atom->type[i]; - int iswaptype; - for (iswaptype = 0; iswaptype < nswaptypes; iswaptype++) - if (itype == type_list[iswaptype]) break; - if (iswaptype == nswaptypes) continue; + int itype = atom->type[i]; + int iswaptype; + for (iswaptype = 0; iswaptype < nswaptypes; iswaptype++) + if (itype == type_list[iswaptype]) break; + if (iswaptype == nswaptypes) continue; local_swap_atom_list[nswap_local] = i; nswap_local++; } } } - MPI_Allreduce(&nswap_local,&nswap,1,MPI_INT,MPI_SUM,world); - MPI_Scan(&nswap_local,&nswap_before,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&nswap_local, &nswap, 1, MPI_INT, MPI_SUM, world); + MPI_Scan(&nswap_local, &nswap_before, 1, MPI_INT, MPI_SUM, world); nswap_before -= nswap_local; } - /* ---------------------------------------------------------------------- update the list of gas atoms ------------------------------------------------------------------------- */ @@ -656,24 +651,24 @@ void FixAtomSwap::update_swap_atoms_list() memory->sfree(local_swap_iatom_list); memory->sfree(local_swap_jatom_list); atom_swap_nmax = atom->nmax; - local_swap_iatom_list = (int *) memory->smalloc(atom_swap_nmax*sizeof(int), - "MCSWAP:local_swap_iatom_list"); - local_swap_jatom_list = (int *) memory->smalloc(atom_swap_nmax*sizeof(int), - "MCSWAP:local_swap_jatom_list"); + local_swap_iatom_list = + (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_iatom_list"); + local_swap_jatom_list = + (int *) memory->smalloc(atom_swap_nmax * sizeof(int), "MCSWAP:local_swap_jatom_list"); } niswap_local = 0; njswap_local = 0; - if (regionflag) { + if (region) { for (int i = 0; i < nlocal; i++) { - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 1) { + if (region->match(x[i][0], x[i][1], x[i][2]) == 1) { if (atom->mask[i] & groupbit) { - if (type[i] == type_list[0]) { + if (type[i] == type_list[0]) { local_swap_iatom_list[niswap_local] = i; niswap_local++; - } else if (type[i] == type_list[1]) { + } else if (type[i] == type_list[1]) { local_swap_jatom_list[njswap_local] = i; njswap_local++; } @@ -684,10 +679,10 @@ void FixAtomSwap::update_swap_atoms_list() } else { for (int i = 0; i < nlocal; i++) { if (atom->mask[i] & groupbit) { - if (type[i] == type_list[0]) { + if (type[i] == type_list[0]) { local_swap_iatom_list[niswap_local] = i; niswap_local++; - } else if (type[i] == type_list[1]) { + } else if (type[i] == type_list[1]) { local_swap_jatom_list[njswap_local] = i; njswap_local++; } @@ -695,12 +690,12 @@ void FixAtomSwap::update_swap_atoms_list() } } - MPI_Allreduce(&niswap_local,&niswap,1,MPI_INT,MPI_SUM,world); - MPI_Scan(&niswap_local,&niswap_before,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&niswap_local, &niswap, 1, MPI_INT, MPI_SUM, world); + MPI_Scan(&niswap_local, &niswap_before, 1, MPI_INT, MPI_SUM, world); niswap_before -= niswap_local; - MPI_Allreduce(&njswap_local,&njswap,1,MPI_INT,MPI_SUM,world); - MPI_Scan(&njswap_local,&njswap_before,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&njswap_local, &njswap, 1, MPI_INT, MPI_SUM, world); + MPI_Scan(&njswap_local, &njswap_before, 1, MPI_INT, MPI_SUM, world); njswap_before -= njswap_local; } @@ -708,7 +703,7 @@ void FixAtomSwap::update_swap_atoms_list() int FixAtomSwap::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) { - int i,j,m; + int i, j, m; int *type = atom->type; double *q = atom->q; @@ -735,7 +730,7 @@ int FixAtomSwap::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag void FixAtomSwap::unpack_forward_comm(int n, int first, double *buf) { - int i,m,last; + int i, m, last; int *type = atom->type; double *q = atom->q; @@ -745,12 +740,11 @@ void FixAtomSwap::unpack_forward_comm(int n, int first, double *buf) if (atom->q_flag) { for (i = first; i < last; i++) { - type[i] = static_cast (buf[m++]); + type[i] = static_cast(buf[m++]); q[i] = buf[m++]; } } else { - for (i = first; i < last; i++) - type[i] = static_cast (buf[m++]); + for (i = first; i < last; i++) type[i] = static_cast(buf[m++]); } } @@ -771,7 +765,7 @@ double FixAtomSwap::compute_vector(int n) double FixAtomSwap::memory_usage() { - double bytes = (double)atom_swap_nmax * sizeof(int); + double bytes = (double) atom_swap_nmax * sizeof(int); return bytes; } @@ -792,8 +786,8 @@ void FixAtomSwap::write_restart(FILE *fp) if (comm->me == 0) { int size = n * sizeof(double); - fwrite(&size,sizeof(int),1,fp); - fwrite(list,sizeof(double),n,fp); + fwrite(&size, sizeof(int), 1, fp); + fwrite(list, sizeof(double), n, fp); } } @@ -806,10 +800,10 @@ void FixAtomSwap::restart(char *buf) int n = 0; auto list = (double *) buf; - seed = static_cast (list[n++]); + seed = static_cast(list[n++]); random_equal->reset(seed); - seed = static_cast (list[n++]); + seed = static_cast(list[n++]); random_unequal->reset(seed); next_reneighbor = (bigint) ubuf(list[n++]).i; @@ -819,5 +813,5 @@ void FixAtomSwap::restart(char *buf) bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; if (ntimestep_restart != update->ntimestep) - error->all(FLERR,"Must not reset timestep when restarting fix atom/swap"); + error->all(FLERR, "Must not reset timestep when restarting fix atom/swap"); } diff --git a/src/MC/fix_atom_swap.h b/src/MC/fix_atom_swap.h index 59145da84f..c4e280cf06 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 @@ -49,8 +49,7 @@ class FixAtomSwap : public Fix { int nswap; // # of swap atoms on all procs int nswap_local; // # of swap atoms on this proc int nswap_before; // # of swap atoms on procs < this proc - int regionflag; // 0 = anywhere in box, 1 = specific region - int iregion; // swap region + class Region *region; // swap region char *idregion; // swap region id int nswaptypes, nmutypes; diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index a526ba4756..835d049bc6 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -68,7 +68,7 @@ enum{NONE,MOVEATOM,MOVEMOL}; // movemode FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - idregion(nullptr), full_flag(false), ngroups(0), groupstrings(nullptr), ngrouptypes(0), + region(nullptr), idregion(nullptr), full_flag(false), groupstrings(nullptr), grouptypestrings(nullptr), grouptypebits(nullptr), grouptypes(nullptr), local_gas_list(nullptr), molcoords(nullptr), molq(nullptr), molimage(nullptr), random_equal(nullptr), random_unequal(nullptr), fixrigid(nullptr), fixshake(nullptr), idrigid(nullptr), idshake(nullptr) @@ -87,6 +87,9 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : restart_global = 1; time_depend = 1; + ngroups = 0; + ngrouptypes = 0; + // required args nevery = utils::inumeric(FLERR,arg[3],false,lmp); @@ -122,18 +125,18 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : region_xlo = region_xhi = region_ylo = region_yhi = region_zlo = region_zhi = 0.0; - if (regionflag) { - if (domain->regions[iregion]->bboxflag == 0) + if (region) { + if (region->bboxflag == 0) error->all(FLERR,"Fix gcmc region does not support a bounding box"); - if (domain->regions[iregion]->dynamic_check()) + if (region->dynamic_check()) error->all(FLERR,"Fix gcmc region cannot be dynamic"); - region_xlo = domain->regions[iregion]->extent_xlo; - region_xhi = domain->regions[iregion]->extent_xhi; - region_ylo = domain->regions[iregion]->extent_ylo; - region_yhi = domain->regions[iregion]->extent_yhi; - region_zlo = domain->regions[iregion]->extent_zlo; - region_zhi = domain->regions[iregion]->extent_zhi; + region_xlo = region->extent_xlo; + region_xhi = region->extent_xhi; + region_ylo = region->extent_ylo; + region_yhi = region->extent_yhi; + region_zlo = region->extent_zlo; + region_zhi = region->extent_zhi; if (region_xlo < domain->boxlo[0] || region_xhi > domain->boxhi[0] || region_ylo < domain->boxlo[1] || region_yhi > domain->boxhi[1] || @@ -149,15 +152,14 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - if (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) != 0) + if (region->match(coord[0],coord[1],coord[2]) != 0) inside++; } - double max_region_volume = (region_xhi - region_xlo)* - (region_yhi - region_ylo)*(region_zhi - region_zlo); + double max_region_volume = (region_xhi - region_xlo) * + (region_yhi - region_ylo) * (region_zhi - region_zlo); - region_volume = max_region_volume*static_cast (inside)/ - static_cast (attempts); + region_volume = max_region_volume * static_cast(inside) / static_cast(attempts); } // error check and further setup for exchmode = EXCHMOL @@ -241,8 +243,6 @@ void FixGCMC::options(int narg, char **arg) pmolrotate = 0.0; pmctot = 0.0; max_rotation_angle = 10*MY_PI/180; - regionflag = 0; - iregion = -1; region_volume = 0; max_region_attempts = 1000; molecule_group = 0; @@ -300,11 +300,10 @@ void FixGCMC::options(int narg, char **arg) iarg += 4; } else if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix gcmc does not exist"); + region = domain->get_region_by_id(arg[iarg+1]); + if (!region) + error->all(FLERR,"Region {} for fix gcmc does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); - regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"maxangle") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); @@ -397,7 +396,7 @@ void FixGCMC::options(int narg, char **arg) FixGCMC::~FixGCMC() { - if (regionflag) delete [] idregion; + delete[] idregion; delete random_equal; delete random_unequal; @@ -406,12 +405,12 @@ FixGCMC::~FixGCMC() memory->destroy(molq); memory->destroy(molimage); - delete [] idrigid; - delete [] idshake; + delete[] idrigid; + delete[] idshake; if (ngroups > 0) { for (int igroup = 0; igroup < ngroups; igroup++) - delete [] groupstrings[igroup]; + delete[] groupstrings[igroup]; memory->sfree(groupstrings); } @@ -419,7 +418,7 @@ FixGCMC::~FixGCMC() memory->destroy(grouptypes); memory->destroy(grouptypebits); for (int igroup = 0; igroup < ngrouptypes; igroup++) - delete [] grouptypestrings[igroup]; + delete[] grouptypestrings[igroup]; memory->sfree(grouptypestrings); } if (full_flag && group) { @@ -443,6 +442,13 @@ int FixGCMC::setmask() void FixGCMC::init() { + // set index and check validity of region + + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix gcmc does not exist", idregion); + } + triclinic = domain->triclinic; // set probabilities for MC moves @@ -719,7 +725,7 @@ void FixGCMC::pre_exchange() subhi = domain->subhi; } - if (regionflag) volume = region_volume; + if (region) volume = region_volume; else volume = domain->xprd * domain->yprd * domain->zprd; if (triclinic) domain->x2lamda(atom->nlocal); @@ -801,8 +807,7 @@ void FixGCMC::attempt_atomic_translation() double **x = atom->x; double energy_before = energy(i,ngcmc_type,-1,x[i]); if (overlap_flag && energy_before > MAXENERGYTEST) - error->warning(FLERR,"Energy of old configuration in " - "fix gcmc is > MAXENERGYTEST."); + error->warning(FLERR,"Energy of old configuration in fix gcmc is > MAXENERGYTEST."); double rsq = 1.1; double rx,ry,rz; rx = ry = rz = 0.0; @@ -816,8 +821,8 @@ void FixGCMC::attempt_atomic_translation() coord[0] = x[i][0] + displace*rx; coord[1] = x[i][1] + displace*ry; coord[2] = x[i][2] + displace*rz; - if (regionflag) { - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + if (region) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { rsq = 1.1; while (rsq > 1.0) { rx = 2*random_unequal->uniform() - 1.0; @@ -913,12 +918,12 @@ void FixGCMC::attempt_atomic_insertion() // pick coordinates for insertion point double coord[3]; - if (regionflag) { + if (region) { int region_attempt = 0; coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); @@ -1043,7 +1048,7 @@ void FixGCMC::attempt_molecule_translation() com_displace[1] = displace*ry; com_displace[2] = displace*rz; - if (regionflag) { + if (region) { int *mask = atom->mask; for (int i = 0; i < atom->nlocal; i++) { if (atom->molecule[i] == translation_molecule) { @@ -1058,7 +1063,7 @@ void FixGCMC::attempt_molecule_translation() coord[0] = com[0] + displace*rx; coord[1] = com[1] + displace*ry; coord[2] = com[2] + displace*rz; - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { rsq = 1.1; while (rsq > 1.0) { rx = 2*random_equal->uniform() - 1.0; @@ -1266,7 +1271,7 @@ void FixGCMC::attempt_molecule_insertion() if (ngas >= max_ngas) return; double com_coord[3]; - if (regionflag) { + if (region) { int region_attempt = 0; com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -1274,7 +1279,7 @@ void FixGCMC::attempt_molecule_insertion() (region_yhi-region_ylo); com_coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(com_coord[0],com_coord[1], + while (region->match(com_coord[0],com_coord[1], com_coord[2]) == 0) { com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -1485,8 +1490,8 @@ void FixGCMC::attempt_atomic_translation_full() coord[0] = x[i][0] + displace*rx; coord[1] = x[i][1] + displace*ry; coord[2] = x[i][2] + displace*rz; - if (regionflag) { - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + if (region) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { rsq = 1.1; while (rsq > 1.0) { rx = 2*random_unequal->uniform() - 1.0; @@ -1602,12 +1607,12 @@ void FixGCMC::attempt_atomic_insertion_full() double energy_before = energy_stored; double coord[3]; - if (regionflag) { + if (region) { int region_attempt = 0; coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); @@ -1726,7 +1731,7 @@ void FixGCMC::attempt_molecule_translation_full() com_displace[1] = displace*ry; com_displace[2] = displace*rz; - if (regionflag) { + if (region) { int *mask = atom->mask; for (int i = 0; i < atom->nlocal; i++) { if (atom->molecule[i] == translation_molecule) { @@ -1741,7 +1746,7 @@ void FixGCMC::attempt_molecule_translation_full() coord[0] = com[0] + displace*rx; coord[1] = com[1] + displace*ry; coord[2] = com[2] + displace*rz; - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { rsq = 1.1; while (rsq > 1.0) { rx = 2*random_equal->uniform() - 1.0; @@ -1998,7 +2003,7 @@ void FixGCMC::attempt_molecule_insertion_full() int nlocalprev = atom->nlocal; double com_coord[3]; - if (regionflag) { + if (region) { int region_attempt = 0; com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -2006,7 +2011,7 @@ void FixGCMC::attempt_molecule_insertion_full() (region_yhi-region_ylo); com_coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(com_coord[0],com_coord[1], + while (region->match(com_coord[0],com_coord[1], com_coord[2]) == 0) { com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -2408,7 +2413,7 @@ void FixGCMC::update_gas_atoms_list() ngas_local = 0; - if (regionflag) { + if (region) { if (exchmode == EXCHMOL || movemode == MOVEMOL) { @@ -2441,7 +2446,7 @@ void FixGCMC::update_gas_atoms_list() for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (domain->regions[iregion]->match(comx[molecule[i]], + if (region->match(comx[molecule[i]], comy[molecule[i]],comz[molecule[i]]) == 1) { local_gas_list[ngas_local] = i; ngas_local++; @@ -2454,7 +2459,7 @@ void FixGCMC::update_gas_atoms_list() } else { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 1) { + if (region->match(x[i][0],x[i][1],x[i][2]) == 1) { local_gas_list[ngas_local] = i; ngas_local++; } diff --git a/src/MC/fix_gcmc.h b/src/MC/fix_gcmc.h index 79ce515b20..bddf0c425a 100644 --- a/src/MC/fix_gcmc.h +++ b/src/MC/fix_gcmc.h @@ -65,17 +65,16 @@ class FixGCMC : public Fix { int ngcmc_type, nevery, seed; int ncycles, nexchanges, nmcmoves; double patomtrans, pmoltrans, pmolrotate, pmctot; - int ngas; // # of gas atoms on all procs - int ngas_local; // # of gas atoms on this proc - int ngas_before; // # of gas atoms on procs < this proc - int exchmode; // exchange ATOM or MOLECULE - int movemode; // move ATOM or MOLECULE - int regionflag; // 0 = anywhere in box, 1 = specific region - int iregion; // gcmc region - char *idregion; // gcmc region id - bool pressure_flag; // true if user specified reservoir pressure - bool charge_flag; // true if user specified atomic charge - bool full_flag; // true if doing full system energy calculations + int ngas; // # of gas atoms on all procs + int ngas_local; // # of gas atoms on this proc + int ngas_before; // # of gas atoms on procs < this proc + int exchmode; // exchange ATOM or MOLECULE + int movemode; // move ATOM or MOLECULE + class Region *region; // gcmc region + char *idregion; // gcmc region id + bool pressure_flag; // true if user specified reservoir pressure + bool charge_flag; // true if user specified atomic charge + bool full_flag; // true if doing full system energy calculations int natoms_per_molecule; // number of atoms in each inserted molecule int nmaxmolatoms; // number of atoms allocated for molecule arrays 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/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index bb20313ea8..0adabe5eae 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -46,7 +46,6 @@ #include #include -using namespace std; using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; @@ -59,8 +58,8 @@ enum{EXCHATOM,EXCHMOL}; // exchmode FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - idregion(nullptr), full_flag(false), local_gas_list(nullptr), molcoords(nullptr), - molq(nullptr), molimage(nullptr), random_equal(nullptr) + region(nullptr), idregion(nullptr), full_flag(false), local_gas_list(nullptr), + molcoords(nullptr),molq(nullptr), molimage(nullptr), random_equal(nullptr) { if (narg < 8) error->all(FLERR,"Illegal fix widom command"); @@ -76,8 +75,6 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : restart_global = 1; time_depend = 1; - //ave_widom_chemical_potential = 0; - // required args nevery = utils::inumeric(FLERR,arg[3],false,lmp); @@ -104,18 +101,18 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : region_xlo = region_xhi = region_ylo = region_yhi = region_zlo = region_zhi = 0.0; - if (regionflag) { - if (domain->regions[iregion]->bboxflag == 0) + if (region) { + if (region->bboxflag == 0) error->all(FLERR,"Fix widom region does not support a bounding box"); - if (domain->regions[iregion]->dynamic_check()) + if (region->dynamic_check()) error->all(FLERR,"Fix widom region cannot be dynamic"); - region_xlo = domain->regions[iregion]->extent_xlo; - region_xhi = domain->regions[iregion]->extent_xhi; - region_ylo = domain->regions[iregion]->extent_ylo; - region_yhi = domain->regions[iregion]->extent_yhi; - region_zlo = domain->regions[iregion]->extent_zlo; - region_zhi = domain->regions[iregion]->extent_zhi; + region_xlo = region->extent_xlo; + region_xhi = region->extent_xhi; + region_ylo = region->extent_ylo; + region_yhi = region->extent_yhi; + region_zlo = region->extent_zlo; + region_zhi = region->extent_zhi; if (region_xlo < domain->boxlo[0] || region_xhi > domain->boxhi[0] || region_ylo < domain->boxlo[1] || region_yhi > domain->boxhi[1] || @@ -131,15 +128,14 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - if (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) != 0) + if (region->match(coord[0],coord[1],coord[2]) != 0) inside++; } - double max_region_volume = (region_xhi - region_xlo)* - (region_yhi - region_ylo)*(region_zhi - region_zlo); + double max_region_volume = (region_xhi - region_xlo) * + (region_yhi - region_ylo) * (region_zhi - region_zlo); - region_volume = max_region_volume*static_cast (inside)/ - static_cast (attempts); + region_volume = max_region_volume * static_cast(inside) / static_cast(attempts); } // error check and further setup for exchmode = EXCHMOL @@ -191,8 +187,6 @@ void FixWidom::options(int narg, char **arg) // defaults exchmode = EXCHATOM; - regionflag = 0; - iregion = -1; region_volume = 0; max_region_attempts = 1000; molecule_group = 0; @@ -221,11 +215,10 @@ void FixWidom::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix widom does not exist"); + region = domain->get_region_by_id(arg[iarg+1]); + if (!region) + error->all(FLERR,"Region {} for fix widom does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); - regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"charge") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); @@ -247,7 +240,7 @@ void FixWidom::options(int narg, char **arg) FixWidom::~FixWidom() { - if (regionflag) delete [] idregion; + delete[] idregion; delete random_equal; memory->destroy(local_gas_list); @@ -271,11 +264,18 @@ int FixWidom::setmask() void FixWidom::init() { + // set index and check validity of region + + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix widom does not exist", idregion); + } + triclinic = domain->triclinic; ave_widom_chemical_potential = 0; - if (regionflag) volume = region_volume; + if (region) volume = region_volume; else volume = domain->xprd * domain->yprd * domain->zprd; // decide whether to switch to the full_energy option @@ -283,8 +283,8 @@ void FixWidom::init() if ((force->kspace) || (force->pair == nullptr) || (force->pair->single_enable == 0) || - (force->pair_match("hybrid",0)) || - (force->pair_match("eam",0)) || + (force->pair_match("^hybrid",0)) || + (force->pair_match("^eam",0)) || (force->pair->tail_flag)) { full_flag = true; if (comm->me == 0) @@ -434,7 +434,7 @@ void FixWidom::pre_exchange() subhi = domain->subhi; } - if (regionflag) volume = region_volume; + if (region) volume = region_volume; else volume = domain->xprd * domain->yprd * domain->zprd; if (triclinic) domain->x2lamda(atom->nlocal); @@ -486,12 +486,12 @@ void FixWidom::attempt_atomic_insertion() // pick coordinates for insertion point - if (regionflag) { + if (region) { int region_attempt = 0; coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); @@ -562,7 +562,7 @@ void FixWidom::attempt_molecule_insertion() for (int imove = 0; imove < ninsertions; imove++) { - if (regionflag) { + if (region) { int region_attempt = 0; com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -570,7 +570,7 @@ void FixWidom::attempt_molecule_insertion() (region_yhi-region_ylo); com_coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(com_coord[0],com_coord[1], + while (region->match(com_coord[0],com_coord[1], com_coord[2]) == 0) { com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -688,12 +688,12 @@ void FixWidom::attempt_atomic_insertion_full() for (int imove = 0; imove < ninsertions; imove++) { - if (regionflag) { + if (region) { int region_attempt = 0; coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0) { + while (region->match(coord[0],coord[1],coord[2]) == 0) { coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); coord[1] = region_ylo + random_equal->uniform() * (region_yhi-region_ylo); coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); @@ -801,7 +801,7 @@ void FixWidom::attempt_molecule_insertion_full() for (int imove = 0; imove < ninsertions; imove++) { double com_coord[3]; - if (regionflag) { + if (region) { int region_attempt = 0; com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -809,7 +809,7 @@ void FixWidom::attempt_molecule_insertion_full() (region_yhi-region_ylo); com_coord[2] = region_zlo + random_equal->uniform() * (region_zhi-region_zlo); - while (domain->regions[iregion]->match(com_coord[0],com_coord[1], + while (region->match(com_coord[0],com_coord[1], com_coord[2]) == 0) { com_coord[0] = region_xlo + random_equal->uniform() * (region_xhi-region_xlo); @@ -1081,7 +1081,7 @@ void FixWidom::update_gas_atoms_list() ngas_local = 0; - if (regionflag) { + if (region) { if (exchmode == EXCHMOL) { @@ -1114,7 +1114,7 @@ void FixWidom::update_gas_atoms_list() for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (domain->regions[iregion]->match(comx[molecule[i]], + if (region->match(comx[molecule[i]], comy[molecule[i]],comz[molecule[i]]) == 1) { local_gas_list[ngas_local] = i; ngas_local++; @@ -1127,7 +1127,7 @@ void FixWidom::update_gas_atoms_list() } else { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 1) { + if (region->match(x[i][0],x[i][1],x[i][2]) == 1) { local_gas_list[ngas_local] = i; ngas_local++; } diff --git a/src/MC/fix_widom.h b/src/MC/fix_widom.h index d2240fd6c8..ec273f73a7 100644 --- a/src/MC/fix_widom.h +++ b/src/MC/fix_widom.h @@ -53,15 +53,14 @@ class FixWidom : public Fix { int exclusion_group, exclusion_group_bit; int nwidom_type, nevery, seed; int ninsertions; - int ngas; // # of gas atoms on all procs - int ngas_local; // # of gas atoms on this proc - int exchmode; // exchange ATOM or MOLECULE - int movemode; // move ATOM or MOLECULE - int regionflag; // 0 = anywhere in box, 1 = specific region - int iregion; // widom region - char *idregion; // widom region id - bool charge_flag; // true if user specified atomic charge - bool full_flag; // true if doing full system energy calculations + int ngas; // # of gas atoms on all procs + int ngas_local; // # of gas atoms on this proc + int exchmode; // exchange ATOM or MOLECULE + int movemode; // move ATOM or MOLECULE + class Region *region; // widom region + char *idregion; // widom region id + bool charge_flag; // true if user specified atomic charge + bool full_flag; // true if doing full system energy calculations int natoms_per_molecule; // number of atoms in each inserted molecule int nmaxmolatoms; // number of atoms allocated for molecule arrays 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 3ba14c5872..208857cd90 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/angle_cosine.cpp b/src/MOLECULE/angle_cosine.cpp index f11fff8af0..7ef81ef808 100644 --- a/src/MOLECULE/angle_cosine.cpp +++ b/src/MOLECULE/angle_cosine.cpp @@ -240,7 +240,7 @@ double AngleCosine::single(int type, int i1, int i2, int i3) /* ---------------------------------------------------------------------- */ -void AngleCosine::born_matrix(int type, int i1, int i2, int i3, double &du, double &du2) +void AngleCosine::born_matrix(int type, int /*i1*/, int /*i2*/, int /*i3*/, double &du, double &du2) { du2 = 0; du = k[type]; diff --git a/src/MOLECULE/angle_cosine_squared.cpp b/src/MOLECULE/angle_cosine_squared.cpp index 32e6f39b36..669d25b9a1 100644 --- a/src/MOLECULE/angle_cosine_squared.cpp +++ b/src/MOLECULE/angle_cosine_squared.cpp @@ -288,7 +288,6 @@ void AngleCosineSquared::born_matrix(int type, int i1, int i2, int i3, double& d if (c < -1.0) c = -1.0; double dcostheta = c - cos(theta0[type]); - double tk = k[type] * dcostheta; du2 = 2*k[type]; du = du2*dcostheta; } 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.cpp b/src/PLUGIN/plugin.cpp index f8dfb8af22..6b11ac269f 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -388,8 +388,7 @@ void plugin_unload(const char *style, const char *name, LAMMPS *lmp) auto found = region_map->find(name); if (found != region_map->end()) region_map->erase(name); - for (auto iregion : lmp->domain->get_region_by_style(name)) - lmp->domain->delete_region(iregion->id); + for (auto iregion : lmp->domain->get_region_by_style(name)) lmp->domain->delete_region(iregion); } else if (pstyle == "command") { 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/hyper.cpp b/src/REPLICA/hyper.cpp index 00c594e7a3..9fa4910473 100644 --- a/src/REPLICA/hyper.cpp +++ b/src/REPLICA/hyper.cpp @@ -155,12 +155,11 @@ void Hyper::command(int narg, char **arg) // cannot use hyper with time-dependent fixes or regions - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->time_depend) - error->all(FLERR,"Cannot use hyper with a time-dependent fix defined"); + for (auto ifix : modify->get_fix_list()) + if (ifix->time_depend) error->all(FLERR,"Cannot use hyper with a time-dependent fix defined"); - for (int i = 0; i < domain->nregion; i++) - if (domain->regions[i]->dynamic_check()) + for (auto reg : domain->get_region_list()) + if (reg->dynamic_check()) error->all(FLERR,"Cannot use hyper with a time-dependent region defined"); // perform hyperdynamics simulation 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/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 671bb49b64..79d09080ec 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -229,12 +229,11 @@ void PRD::command(int narg, char **arg) // cannot use PRD with time-dependent fixes or regions - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->time_depend) - error->all(FLERR,"Cannot use PRD with a time-dependent fix defined"); + for (auto ifix : modify->get_fix_list()) + if (ifix->time_depend) error->all(FLERR,"Cannot use PRD with a time-dependent fix defined"); - for (int i = 0; i < domain->nregion; i++) - if (domain->regions[i]->dynamic_check()) + for (auto reg : domain->get_region_list()) + if (reg->dynamic_check()) error->all(FLERR,"Cannot use PRD with a time-dependent region defined"); // perform PRD simulation diff --git a/src/RIGID/fix_ehex.cpp b/src/RIGID/fix_ehex.cpp index 01fe76757b..1962578691 100644 --- a/src/RIGID/fix_ehex.cpp +++ b/src/RIGID/fix_ehex.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -43,18 +42,18 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{CONSTANT,EQUAL,ATOM}; +enum { CONSTANT, EQUAL, ATOM }; /* ---------------------------------------------------------------------- */ -FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - idregion(nullptr), x(nullptr), f(nullptr), v(nullptr), - mass(nullptr), rmass(nullptr), type(nullptr), scalingmask(nullptr) +FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), region(nullptr), idregion(nullptr), x(nullptr), f(nullptr), v(nullptr), + mass(nullptr), rmass(nullptr), type(nullptr), scalingmask(nullptr) { MPI_Comm_rank(world, &me); // check - if (narg < 4) error->all(FLERR,"Illegal fix ehex command: wrong number of parameters "); + if (narg < 4) error->all(FLERR, "Illegal fix ehex command: wrong number of parameters "); scalar_flag = 1; global_freq = 1; @@ -62,18 +61,16 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), // apply fix every nevery timesteps - nevery = utils::inumeric(FLERR,arg[3],false,lmp); + nevery = utils::inumeric(FLERR, arg[3], false, lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix ehex command"); + if (nevery <= 0) error->all(FLERR, "Illegal fix ehex command"); // heat flux into the reservoir - heat_input = utils::numeric(FLERR,arg[4],false,lmp); + heat_input = utils::numeric(FLERR, arg[4], false, lmp); // optional args - iregion = -1; - // NOTE: constraints are deactivated by default constraints = 0; @@ -89,12 +86,12 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), int iarg = 5; while (iarg < narg) { - if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix ehex command: wrong number of parameters "); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix ehex does not exist"); - idregion = utils::strdup(arg[iarg+1]); + if (strcmp(arg[iarg], "region") == 0) { + if (iarg + 2 > narg) + error->all(FLERR, "Illegal fix ehex command: wrong number of parameters "); + region = domain->get_region_by_id(arg[iarg + 1]); + if (!region) error->all(FLERR, "Region {} for fix ehex does not exist", arg[iarg + 1]); + idregion = utils::strdup(arg[iarg + 1]); iarg += 2; } @@ -115,10 +112,9 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), // don't apply a coordinate correction if this keyword is specified else if (strcmp(arg[iarg], "hex") == 0) { - hex = 1; - iarg+= 1; - } - else + hex = 1; + iarg += 1; + } else error->all(FLERR, "Illegal fix ehex keyword "); } @@ -128,28 +124,25 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), error->all(FLERR, "You can only use the keyword 'com' together with the keyword 'constrain' "); scale = 1.0; - scalingmask = nullptr; + scalingmask = nullptr; FixEHEX::grow_arrays(atom->nmax); atom->add_callback(Atom::GROW); - } - /* ---------------------------------------------------------------------- */ -void FixEHEX::grow_arrays(int nmax) { - memory->grow(scalingmask, nmax,"ehex:scalingmask"); +void FixEHEX::grow_arrays(int nmax) +{ + memory->grow(scalingmask, nmax, "ehex:scalingmask"); } - /* ---------------------------------------------------------------------- */ FixEHEX::~FixEHEX() { - atom->delete_callback(id,Atom::GROW); - delete [] idregion; + atom->delete_callback(id, Atom::GROW); + delete[] idregion; memory->destroy(scalingmask); - } /* ---------------------------------------------------------------------- */ @@ -167,16 +160,14 @@ void FixEHEX::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 ehex does not exist"); + if (idregion) { + region = domain->get_region_by_id(idregion); + if (!region) error->all(FLERR, "Region {} for fix ehex does not exist", idregion); } // cannot have 0 atoms in group - if (group->count(igroup) == 0) - error->all(FLERR,"Fix ehex group has no atoms"); + if (group->count(igroup) == 0) error->all(FLERR, "Fix ehex group has no atoms"); fshake = nullptr; if (constraints) { @@ -194,30 +185,29 @@ void FixEHEX::init() } if (cnt_shake > 1) - error->all(FLERR,"Multiple instances of fix shake/rattle detected (not supported yet)"); - else if (cnt_shake == 1) { - fshake = (dynamic_cast( modify->fix[id_shake])); - } - else if (cnt_shake == 0) - error->all(FLERR, "Fix ehex was configured with keyword constrain, but shake/rattle was not defined"); + error->all(FLERR, "Multiple instances of fix shake/rattle detected (not supported yet)"); + else if (cnt_shake == 1) { + fshake = (dynamic_cast(modify->fix[id_shake])); + } else if (cnt_shake == 0) + error->all( + FLERR, + "Fix ehex was configured with keyword constrain, but shake/rattle was not defined"); } } - - /* ---------------------------------------------------------------------- */ - -void FixEHEX::end_of_step() { +void FixEHEX::end_of_step() +{ // store local pointers - x = atom->x; - f = atom->f; - v = atom->v; - mass = atom->mass; - rmass = atom->rmass; - type = atom->type; - nlocal = atom->nlocal; + x = atom->x; + f = atom->f; + v = atom->v; + mass = atom->mass; + rmass = atom->rmass; + type = atom->type; + nlocal = atom->nlocal; // determine which sites are to be rescaled @@ -229,20 +219,18 @@ void FixEHEX::end_of_step() { // if required use shake/rattle to correct coordinates and velocities - if (constraints && fshake) - fshake->shake_end_of_step(0); + if (constraints && fshake) fshake->shake_end_of_step(0); } - - /* ---------------------------------------------------------------------- Iterate over all atoms, rescale the velocities and apply coordinate corrections. ------------------------------------------------------------------------- */ -void FixEHEX::rescale() { +void FixEHEX::rescale() +{ double Kr, Ke, escale; - double vsub[3],vcm[3], sfr[3]; + double vsub[3], vcm[3], sfr[3]; double mi; double dt; double F, mr, epsr_ik, sfvr, eta_ik; @@ -255,54 +243,54 @@ void FixEHEX::rescale() { // heat flux into the reservoir - F = heat_input * force->ftm2v * nevery; + F = heat_input * force->ftm2v * nevery; // total mass - mr = masstotal; + mr = masstotal; // energy scaling factor - escale = 1. + (F*dt)/Kr; + escale = 1. + (F * dt) / Kr; // safety check for kinetic energy - if (escale < 0.0) error->all(FLERR,"Fix ehex kinetic energy went negative"); + if (escale < 0.0) error->all(FLERR, "Fix ehex 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]; for (int i = 0; i < nlocal; i++) { if (scalingmask[i]) { - mi = (rmass) ? rmass[i] : mass[type[i]]; + mi = (rmass) ? rmass[i] : mass[type[i]]; - for (int k=0; k<3; k++) { + for (int k = 0; k < 3; k++) { // apply coordinate correction unless running in hex mode if (!hex) { - // epsr_ik implements Eq. (20) in the paper + // epsr_ik implements Eq. (20) in the paper - eta_ik = mi * F/(2.*Kr) * (v[i][k] - vcm[k]); - epsr_ik = eta_ik / (mi*Kr) * (F/48. + sfvr/6.*force->ftm2v) - F/(12.*Kr) * (f[i][k]/mi - sfr[k]/mr)*force->ftm2v; + eta_ik = mi * F / (2. * Kr) * (v[i][k] - vcm[k]); + epsr_ik = eta_ik / (mi * Kr) * (F / 48. + sfvr / 6. * force->ftm2v) - + F / (12. * Kr) * (f[i][k] / mi - sfr[k] / mr) * force->ftm2v; - x[i][k] -= dt*dt*dt * epsr_ik; + x[i][k] -= dt * dt * dt * epsr_ik; } // rescale the velocity - v[i][k] = scale*v[i][k] - vsub[k]; + v[i][k] = scale * v[i][k] - vsub[k]; } } } } - /* ---------------------------------------------------------------------- */ double FixEHEX::compute_scalar() @@ -317,17 +305,17 @@ double FixEHEX::compute_scalar() double FixEHEX::memory_usage() { double bytes = 0.0; - bytes += (double)atom->nmax * sizeof(double); + bytes += (double) atom->nmax * sizeof(double); return bytes; } - /* ---------------------------------------------------------------------- Update the array scalingmask depending on which individual atoms will be rescaled or not. ------------------------------------------------------------------------- */ -void FixEHEX::update_scalingmask() { +void FixEHEX::update_scalingmask() +{ int m; int lid; bool stat; @@ -335,11 +323,7 @@ void FixEHEX::update_scalingmask() { // prematch region - Region *region = nullptr; - if (iregion >= 0) { - region = domain->regions[iregion]; - region->prematch(); - } + if (region) region->prematch(); // only rescale molecules whose center of mass if fully contained in the region @@ -347,28 +331,33 @@ void FixEHEX::update_scalingmask() { // loop over all clusters - for (int i=0; i < fshake->nlist; i++) { + for (int i = 0; i < fshake->nlist; i++) { // cluster id - m = fshake->list[i]; + m = fshake->list[i]; // check if the centre of mass of the cluster is inside the region // if region == nullptr, just check the group information of all sites - if (fshake->shake_flag[m] == 1) nsites = 3; - else if (fshake->shake_flag[m] == 2) nsites = 2; - else if (fshake->shake_flag[m] == 3) nsites = 3; - else if (fshake->shake_flag[m] == 4) nsites = 4; - else nsites = 0; + if (fshake->shake_flag[m] == 1) + nsites = 3; + else if (fshake->shake_flag[m] == 2) + nsites = 2; + else if (fshake->shake_flag[m] == 3) + nsites = 3; + else if (fshake->shake_flag[m] == 4) + nsites = 4; + else + nsites = 0; if (nsites == 0) { - error->all(FLERR,"Internal error: shake_flag[m] has to be between 1 and 4 for m in nlist"); + error->all(FLERR, "Internal error: shake_flag[m] has to be between 1 and 4 for m in nlist"); } stat = check_cluster(fshake->shake_atom[m], nsites, region); - for (int l=0; l < nsites; l++) { + for (int l = 0; l < nsites; l++) { lid = atom->map(fshake->shake_atom[m][l]); scalingmask[lid] = stat; } @@ -376,9 +365,8 @@ void FixEHEX::update_scalingmask() { // check atoms that do not belong to any cluster - for (int i=0; inlocal; i++) { - if (fshake->shake_flag[i] == 0) - scalingmask[i] = rescale_atom(i,region); + for (int i = 0; i < atom->nlocal; i++) { + if (fshake->shake_flag[i] == 0) scalingmask[i] = rescale_atom(i, region); } } @@ -386,41 +374,39 @@ void FixEHEX::update_scalingmask() { // no clusters, just individual sites (e.g. monatomic system or flexible molecules) else { - for (int i=0; inlocal; i++) - scalingmask[i] = rescale_atom(i,region); + for (int i = 0; i < atom->nlocal; i++) scalingmask[i] = rescale_atom(i, region); } - } - /* ---------------------------------------------------------------------- Check if the centre of mass of the cluster to be constrained is inside the region. ------------------------------------------------------------------------- */ -bool FixEHEX::check_cluster(tagint *shake_atom, int n, Region * region) { +bool FixEHEX::check_cluster(tagint *shake_atom, int n, Region *region) +{ // IMPORTANT NOTE: If any site of the cluster belongs to a group // which should not be rescaled than all of the sites // will be ignored! - double **x = atom->x; - double * rmass = atom->rmass; - double * mass = atom->mass; - int * type = atom->type; - int * mask = atom->mask; - double xcom[3], xtemp[3]; - double mcluster, mi; - bool stat; - int lid[4]; + double **x = atom->x; + double *rmass = atom->rmass; + double *mass = atom->mass; + int *type = atom->type; + int *mask = atom->mask; + double xcom[3], xtemp[3]; + double mcluster, mi; + bool stat; + int lid[4]; // accumulate mass and centre of mass position - stat = true; - xcom[0] = 0.; - xcom[1] = 0.; - xcom[2] = 0.; - mcluster = 0; + stat = true; + xcom[0] = 0.; + xcom[1] = 0.; + xcom[2] = 0.; + mcluster = 0; for (int i = 0; i < n; i++) { @@ -432,26 +418,24 @@ bool FixEHEX::check_cluster(tagint *shake_atom, int n, Region * region) { stat = stat && (mask[lid[i]] & groupbit); - if (region && stat) { + if (region && stat) { // check if reduced mass is used - mi = (rmass) ? rmass[lid[i]] : mass[type[lid[i]]]; + mi = (rmass) ? rmass[lid[i]] : mass[type[lid[i]]]; mcluster += mi; // accumulate centre of mass // NOTE: you can either use unwrapped coordinates or take site x[lid[0]] as reference, // i.e. reconstruct the molecule around this site and calculate the com. - for (int k=0; k<3; k++) - xtemp[k] = x[lid[i]][k] - x[lid[0]][k]; + for (int k = 0; k < 3; k++) xtemp[k] = x[lid[i]][k] - x[lid[0]][k]; // take into account pbc domain->minimum_image(xtemp); - for (int k=0; k<3; k++) - xcom[k] += mi * (x[lid[0]][k] + xtemp[k]) ; + for (int k = 0; k < 3; k++) xcom[k] += mi * (x[lid[0]][k] + xtemp[k]); } } @@ -461,14 +445,11 @@ bool FixEHEX::check_cluster(tagint *shake_atom, int n, Region * region) { // check mass - if (mcluster < 1.e-14) { - error->all(FLERR, "Fix ehex shake cluster has almost zero mass."); - } + if (mcluster < 1.e-14) { error->all(FLERR, "Fix ehex shake cluster has almost zero mass."); } // divide by total mass - for (int k=0; k<3; k++) - xcom[k] = xcom[k]/mcluster; + for (int k = 0; k < 3; k++) xcom[k] = xcom[k] / mcluster; // apply periodic boundary conditions (centre of mass could be outside the box) // and check if molecule is inside the region @@ -480,12 +461,12 @@ bool FixEHEX::check_cluster(tagint *shake_atom, int n, Region * region) { return stat; } - /* ---------------------------------------------------------------------- Check if atom i has the correct group and is inside the region. ------------------------------------------------------------------------- */ -bool FixEHEX::rescale_atom(int i, Region*region) { +bool FixEHEX::rescale_atom(int i, Region *region) +{ bool stat; double x_r[3]; @@ -505,7 +486,7 @@ bool FixEHEX::rescale_atom(int i, Region*region) { // check if the atom is in the group/region - stat = stat && region->match(x_r[0],x_r[1],x_r[2]); + stat = stat && region->match(x_r[0], x_r[1], x_r[2]); } return stat; @@ -516,102 +497,101 @@ bool FixEHEX::rescale_atom(int i, Region*region) { (e.g. com velocity, kinetic energy, total mass,...) ------------------------------------------------------------------------- */ -void FixEHEX::com_properties(double * vr, double * sfr, double *sfvr, double *K, double *Kr, double *mr) { - double ** f = atom->f; - double ** v = atom->v; - int nlocal = atom->nlocal; - double *rmass= atom->rmass; - double *mass = atom->mass; - int *type = atom->type; - double l_vr[3]; - double l_mr; - double l_sfr[3]; - double l_sfvr; - double l_K; - double mi; - double l_buf[9]; - double buf[9]; +void FixEHEX::com_properties(double *vr, double *sfr, double *sfvr, double *K, double *Kr, + double *mr) +{ + double **f = atom->f; + double **v = atom->v; + int nlocal = atom->nlocal; + double *rmass = atom->rmass; + double *mass = atom->mass; + int *type = atom->type; + double l_vr[3]; + double l_mr; + double l_sfr[3]; + double l_sfvr; + double l_K; + double mi; + double l_buf[9]; + double buf[9]; - // calculate partial sums + // calculate partial sums - l_vr[0] = l_vr[1] = l_vr[2] = 0; - l_sfr[0] = l_sfr[1] = l_sfr[2] = 0; - l_sfvr = 0; - l_mr = 0; - l_K = 0; + l_vr[0] = l_vr[1] = l_vr[2] = 0; + l_sfr[0] = l_sfr[1] = l_sfr[2] = 0; + l_sfvr = 0; + l_mr = 0; + l_K = 0; - for (int i = 0; i < nlocal; i++) { - if (scalingmask[i]) { + for (int i = 0; i < nlocal; i++) { + if (scalingmask[i]) { - // check if reduced mass is used + // check if reduced mass is used - mi = (rmass) ? rmass[i] : mass[type[i]]; + mi = (rmass) ? rmass[i] : mass[type[i]]; - // accumulate total mass + // accumulate total mass - l_mr += mi; + l_mr += mi; - // accumulate kinetic energy + // accumulate kinetic energy - l_K += mi/2. * (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]); + l_K += mi / 2. * (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]); - // sum_j f_j * v_j + // sum_j f_j * v_j - l_sfvr += f[i][0]*v[i][0] + f[i][1]*v[i][1] + f[i][2]*v[i][2]; + l_sfvr += f[i][0] * v[i][0] + f[i][1] * v[i][1] + f[i][2] * v[i][2]; - // accumulate com velocity and sum of forces + // accumulate com velocity and sum of forces - for (int k=0; k<3; k++) { - l_vr[k] += mi * v[i][k]; - l_sfr[k]+= f[i][k]; - } - } - } + for (int k = 0; k < 3; k++) { + l_vr[k] += mi * v[i][k]; + l_sfr[k] += f[i][k]; + } + } + } - // reduce sums + // reduce sums - l_buf[0] = l_vr[0]; - l_buf[1] = l_vr[1]; - l_buf[2] = l_vr[2]; - l_buf[3] = l_K; - l_buf[4] = l_mr; - l_buf[5] = l_sfr[0]; - l_buf[6] = l_sfr[1]; - l_buf[7] = l_sfr[2]; - l_buf[8] = l_sfvr; + l_buf[0] = l_vr[0]; + l_buf[1] = l_vr[1]; + l_buf[2] = l_vr[2]; + l_buf[3] = l_K; + l_buf[4] = l_mr; + l_buf[5] = l_sfr[0]; + l_buf[6] = l_sfr[1]; + l_buf[7] = l_sfr[2]; + l_buf[8] = l_sfvr; - MPI_Allreduce(l_buf, buf, 9, MPI_DOUBLE, MPI_SUM, world); + MPI_Allreduce(l_buf, buf, 9, MPI_DOUBLE, MPI_SUM, world); - // total mass of region + // total mass of region - *mr = buf[4]; + *mr = buf[4]; - if (*mr < 1.e-14) { - error->all(FLERR, "Fix ehex error mass of region is close to zero"); - } + if (*mr < 1.e-14) { error->all(FLERR, "Fix ehex error mass of region is close to zero"); } - // total kinetic energy of region + // total kinetic energy of region - *K = buf[3]; + *K = buf[3]; - // centre of mass velocity of region + // centre of mass velocity of region - vr[0] = buf[0]/(*mr); - vr[1] = buf[1]/(*mr); - vr[2] = buf[2]/(*mr); + vr[0] = buf[0] / (*mr); + vr[1] = buf[1] / (*mr); + vr[2] = buf[2] / (*mr); - // sum of forces + // sum of forces - sfr[0] = buf[5]; - sfr[1] = buf[6]; - sfr[2] = buf[7]; + sfr[0] = buf[5]; + sfr[1] = buf[6]; + sfr[2] = buf[7]; - // calculate non-translational kinetic energy + // calculate non-translational kinetic energy - *Kr = *K - 0.5* (*mr) * (vr[0]*vr[0]+vr[1]*vr[1]+vr[2]*vr[2]); + *Kr = *K - 0.5 * (*mr) * (vr[0] * vr[0] + vr[1] * vr[1] + vr[2] * vr[2]); - // calculate sum_j f_j * (v_j - v_r) = sum_j f_j * v_j - v_r * sum_j f_j + // calculate sum_j f_j * (v_j - v_r) = sum_j f_j * v_j - v_r * sum_j f_j - *sfvr = buf[8] - (vr[0]*sfr[0] + vr[1]*sfr[1] + vr[2]*sfr[2]); + *sfvr = buf[8] - (vr[0] * sfr[0] + vr[1] * sfr[1] + vr[2] * sfr[2]); } - diff --git a/src/RIGID/fix_ehex.h b/src/RIGID/fix_ehex.h index f4ea872533..7b3b9a5ff8 100644 --- a/src/RIGID/fix_ehex.h +++ b/src/RIGID/fix_ehex.h @@ -43,10 +43,10 @@ class FixEHEX : public Fix { bool check_cluster(tagint *shake_atom, int n, class Region *region); private: - int iregion; double heat_input; double masstotal; double scale; + class Region *region; char *idregion; int me; 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/VTK/dump_vtk.cpp b/src/VTK/dump_vtk.cpp index fd7f4b2c2b..51c6632b78 100644 --- a/src/VTK/dump_vtk.cpp +++ b/src/VTK/dump_vtk.cpp @@ -246,12 +246,11 @@ void DumpVTK::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 vtk does not exist"); + if (idregion) { + if (!domain->get_region_by_id(idregion)) + error->all(FLERR,"Region {} for dump vtk does not exist",idregion); } } @@ -335,8 +334,8 @@ int DumpVTK::count() // un-choose if not in region - if (iregion >= 0) { - Region *region = domain->regions[iregion]; + auto region = domain->get_region_by_id(idregion); + if (region) { region->prematch(); double **x = atom->x; for (i = 0; i < nlocal; i++) @@ -2054,11 +2053,12 @@ int DumpVTK::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 { + if (!domain->get_region_by_id(arg[1])) + error->all(FLERR,"Dump_modify region {} does not exist",arg[1]); delete[] idregion; idregion = utils::strdup(arg[1]); } diff --git a/src/angle.cpp b/src/angle.cpp index 5abc02cd0f..6fdb9307cb 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -361,8 +361,7 @@ double Angle::memory_usage() void Angle::reinit() { - if (!reinitflag) - error->all(FLERR, "Fix adapt interface to this angle style not supported"); + if (!reinitflag) error->all(FLERR, "Fix adapt interface to this angle style not supported"); init(); } diff --git a/src/angle.h b/src/angle.h index be3644640d..ec10226b69 100644 --- a/src/angle.h +++ b/src/angle.h @@ -25,7 +25,7 @@ class Angle : protected Pointers { public: int allocated; int *setflag; - int writedata; // 1 if writes coeffs to data file + int writedata; // 1 if writes coeffs to data file int born_matrix_enable; double energy; // accumulated energies double virial[6]; // accumulated virial: xx,yy,zz,xy,xz,yz @@ -37,8 +37,8 @@ class Angle : protected Pointers { // CENTROID_AVAIL = different and implemented // CENTROID_NOTAVAIL = different, not yet implemented - int reinitflag; // 0 if not compatible with fix adapt - // extract() method may still need to be added + int reinitflag; // 0 if not compatible with fix adapt + // extract() method may still need to be added // KOKKOS host/device flag and data masks @@ -60,7 +60,8 @@ class Angle : protected Pointers { virtual void read_restart_settings(FILE *){}; virtual void write_data(FILE *) {} virtual double single(int, int, int, int) = 0; - virtual void born_matrix(int/*atype*/, int/*at1*/, int/*at2*/, int/*at3*/, double& du, double& du2) + virtual void born_matrix(int /*atype*/, int /*at1*/, int /*at2*/, int /*at3*/, double &du, + double &du2) { du = 0.0; du2 = 0.0; diff --git a/src/atom_vec_hybrid.h b/src/atom_vec_hybrid.h index ef5589484f..234b746df3 100644 --- a/src/atom_vec_hybrid.h +++ b/src/atom_vec_hybrid.h @@ -74,8 +74,8 @@ class AtomVecHybrid : public AtomVec { int nstyles_bonus; class AtomVec **styles_bonus; - void merge_fields(std::vector &, const std::vector &, - int, std::vector &); + void merge_fields(std::vector &, const std::vector &, int, + std::vector &); void build_styles(); int known_style(char *); }; 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.cpp b/src/bond.cpp index ffdf2b8daf..18cdaf8c6d 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -343,8 +343,7 @@ double Bond::memory_usage() void Bond::reinit() { - if (!reinitflag) - error->all(FLERR, "Fix adapt interface to this bond style not supported"); + if (!reinitflag) error->all(FLERR, "Fix adapt interface to this bond style not supported"); init(); } diff --git a/src/bond.h b/src/bond.h index 5c0d01747b..3c5cb0f2d2 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; @@ -35,12 +35,12 @@ class Bond : protected Pointers { int born_matrix_enable; - 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; // 0 if not compatible with fix adapt - // extract() method may still need to be added + int reinitflag; // 0 if not compatible with fix adapt + // extract() method may still need to be added // KOKKOS host/device flag and data masks @@ -64,14 +64,15 @@ class Bond : protected Pointers { virtual double single(int, double, int, int, double &) = 0; virtual double memory_usage(); virtual void *extract(const char *, int &) { return nullptr; } - void reinit(); + 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 *) {} - virtual void born_matrix(int/*btype*/, double/*rsq*/, int/*at1*/, int/*at2*/, double& du, double& du2) + virtual void born_matrix(int /*btype*/, double /*rsq*/, int /*at1*/, int /*at2*/, double &du, + double &du2) { du = 0.0; du2 = 0.0; 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_cluster_atom.cpp b/src/compute_cluster_atom.cpp index 7cb47acaf4..c2cb2816d3 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -184,8 +184,8 @@ void ComputeClusterAtom::compute_peratom() /* ---------------------------------------------------------------------- */ -int ComputeClusterAtom::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) +int ComputeClusterAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, + int * /*pbc*/) { int i, j, m; diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index 9c22f9fb62..7bf749b1be 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 @@ -311,8 +311,8 @@ void ComputeCoordAtom::compute_peratom() /* ---------------------------------------------------------------------- */ -int ComputeCoordAtom::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) +int ComputeCoordAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, + int * /*pbc*/) { int i, m = 0, j; for (i = 0; i < n; ++i) { 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/dihedral.h b/src/dihedral.h index 2dfd5da636..5b7e62e800 100644 --- a/src/dihedral.h +++ b/src/dihedral.h @@ -25,7 +25,7 @@ class Dihedral : protected Pointers { public: int allocated; int *setflag; - int writedata; // 1 if writes coeffs to data file + int writedata; // 1 if writes coeffs to data file int born_matrix_enable; double energy; // accumulated energy double virial[6]; // accumulated virial: xx,yy,zz,xy,xz,yz @@ -56,7 +56,8 @@ class Dihedral : protected Pointers { virtual void read_restart_settings(FILE *){}; virtual void write_data(FILE *) {} virtual double memory_usage(); - virtual void born_matrix(int/*dtype*/, int/*at1*/, int/*at2*/, int/*at3*/, int /*at4*/, double& du, double& du2) + virtual void born_matrix(int /*dtype*/, int /*at1*/, int /*at2*/, int /*at3*/, int /*at4*/, + double &du, double &du2) { du = 0.0; du2 = 0.0; diff --git a/src/domain.cpp b/src/domain.cpp index d3804d75bd..ebc468faed 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -104,10 +104,7 @@ Domain::Domain(LAMMPS *lmp) : Pointers(lmp) args[0] = (char *) "none"; args[1] = (char *) "1.0"; set_lattice(2,args); - delete [] args; - - nregion = maxregion = 0; - regions = nullptr; + delete[] args; copymode = 0; @@ -128,10 +125,9 @@ Domain::~Domain() { if (copymode) return; + for (auto reg : regions) delete reg; + regions.clear(); delete lattice; - for (int i = 0; i < nregion; i++) delete regions[i]; - memory->sfree(regions); - delete region_map; } @@ -194,7 +190,7 @@ void Domain::init() // region inits - for (int i = 0; i < nregion; i++) regions[i]->init(); + for (auto reg : regions) reg->init(); } /* ---------------------------------------------------------------------- @@ -1758,88 +1754,61 @@ void Domain::add_region(int narg, char **arg) if (strcmp(arg[1],"none") == 0) error->all(FLERR,"Unrecognized region style 'none'"); - if (find_region(arg[0]) >= 0) error->all(FLERR,"Reuse of region ID"); - - // extend Region list if necessary - - if (nregion == maxregion) { - maxregion += DELTAREGION; - regions = (Region **) - memory->srealloc(regions,maxregion*sizeof(Region *),"domain:regions"); - } + if (get_region_by_id(arg[0])) error->all(FLERR,"Reuse of region ID {}", arg[0]); // create the Region + Region *newregion = nullptr; if (lmp->suffix_enable) { if (lmp->suffix) { std::string estyle = std::string(arg[1]) + "/" + lmp->suffix; if (region_map->find(estyle) != region_map->end()) { RegionCreator ®ion_creator = (*region_map)[estyle]; - regions[nregion] = region_creator(lmp, narg, arg); - regions[nregion]->init(); - nregion++; - return; + newregion = region_creator(lmp, narg, arg); } } - if (lmp->suffix2) { + if (!newregion && lmp->suffix2) { std::string estyle = std::string(arg[1]) + "/" + lmp->suffix2; if (region_map->find(estyle) != region_map->end()) { RegionCreator ®ion_creator = (*region_map)[estyle]; - regions[nregion] = region_creator(lmp, narg, arg); - regions[nregion]->init(); - nregion++; - return; + newregion = region_creator(lmp, narg, arg); } } } - if (region_map->find(arg[1]) != region_map->end()) { + if (!newregion && (region_map->find(arg[1]) != region_map->end())) { RegionCreator ®ion_creator = (*region_map)[arg[1]]; - regions[nregion] = region_creator(lmp, narg, arg); - } else error->all(FLERR,utils::check_packages_for_style("region",arg[1],lmp)); + newregion = region_creator(lmp, narg, arg); + } + + if (!newregion) + error->all(FLERR,utils::check_packages_for_style("region",arg[1],lmp)); // initialize any region variables via init() // in case region is used between runs, e.g. to print a variable - regions[nregion]->init(); - nregion++; + newregion->init(); + regions.insert(newregion); } /* ---------------------------------------------------------------------- delete a region ------------------------------------------------------------------------- */ -void Domain::delete_region(int iregion) +void Domain::delete_region(Region *reg) { - if ((iregion < 0) || (iregion >= nregion)) return; + if (!reg) return; - // delete and move other Regions down in list one slot - - delete regions[iregion]; - for (int i = iregion+1; i < nregion; ++i) - regions[i-1] = regions[i]; - nregion--; + regions.erase(reg); + delete reg; } void Domain::delete_region(const std::string &id) { - int iregion = find_region(id); - if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); - - delete_region(iregion); -} - -/* ---------------------------------------------------------------------- - return region index if name matches existing region ID - return -1 if no such region -------------------------------------------------------------------------- */ - -int Domain::find_region(const std::string &name) const -{ - for (int iregion = 0; iregion < nregion; iregion++) - if (name == regions[iregion]->id) return iregion; - return -1; + auto reg = get_region_by_id(id); + if (!reg) error->all(FLERR,"Delete region {} does not exist", id); + delete_region(reg); } /* ---------------------------------------------------------------------- @@ -1849,8 +1818,8 @@ int Domain::find_region(const std::string &name) const Region *Domain::get_region_by_id(const std::string &name) const { - for (int iregion = 0; iregion < nregion; iregion++) - if (name == regions[iregion]->id) return regions[iregion]; + for (auto ® : regions) + if (name == reg->id) return reg; return nullptr; } @@ -1864,12 +1833,21 @@ const std::vector Domain::get_region_by_style(const std::string &name) std::vector matches; if (name.empty()) return matches; - for (int iregion = 0; iregion < nregion; iregion++) - if (name == regions[iregion]->style) matches.push_back(regions[iregion]); + for (auto ® : regions) + if (name == reg->style) matches.push_back(reg); return matches; } +/* ---------------------------------------------------------------------- + return list of regions as vector +------------------------------------------------------------------------- */ + +const std::vector Domain::get_region_list() +{ + return std::vector(regions.begin(), regions.end()); +} + /* ---------------------------------------------------------------------- (re)set boundary settings flag = 0, called from the input script diff --git a/src/domain.h b/src/domain.h index 68ff5aece5..abb3fd5cf0 100644 --- a/src/domain.h +++ b/src/domain.h @@ -18,6 +18,8 @@ #include #include +#include +#include namespace LAMMPS_NS { class Region; @@ -98,10 +100,6 @@ class Domain : protected Pointers { class Lattice *lattice; // user-defined lattice - int nregion; // # of defined Regions - int maxregion; // max # list can hold - Region **regions; // list of defined Regions - int copymode; enum { NO_REMAP, X_REMAP, V_REMAP }; @@ -137,11 +135,11 @@ class Domain : protected Pointers { void set_lattice(int, char **); void add_region(int, char **); - void delete_region(int); + void delete_region(Region *); void delete_region(const std::string &); - int find_region(const std::string &) const; Region *get_region_by_id(const std::string &) const; const std::vector get_region_by_style(const std::string &) const; + const std::vector get_region_list(); void set_boundary(int, char **, int); void set_box(int, char **); void print_box(const std::string &); @@ -175,6 +173,7 @@ class Domain : protected Pointers { protected: double small[3]; // fractions of box lengths + std::unordered_set regions; }; } // namespace LAMMPS_NS 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 0a31b97f5f..00deab3ef8 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 @@ -55,42 +54,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"); } } @@ -98,9 +99,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"); } } @@ -171,7 +168,7 @@ void FixGroup::post_force(int /*vflag*/) void FixGroup::post_force_respa(int vflag, int ilevel, int /*iloop*/) { - if (ilevel == nlevels_respa-1) post_force(vflag); + if (ilevel == nlevels_respa - 1) post_force(vflag); } /* ---------------------------------------------------------------------- */ @@ -192,8 +189,8 @@ void FixGroup::set_group() if (varflag) { modify->clearstep_compute(); - memory->create(var,nlocal,"fix/group:var"); - input->variable->compute_atom(ivar,igroup,var,1,0); + memory->create(var, nlocal, "fix/group:var"); + input->variable->compute_atom(ivar, igroup, var, 1, 0); modify->addstep_compute(update->ntimestep + nevery); } @@ -216,16 +213,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); @@ -237,8 +237,7 @@ void FixGroup::set_group() /* ---------------------------------------------------------------------- */ -int FixGroup::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) +int FixGroup::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) { int i, j, m; @@ -269,10 +268,10 @@ void FixGroup::unpack_forward_comm(int n, int first, double *buf) /* ---------------------------------------------------------------------- */ -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 e4c4c9bd32..ea8af4e5d5 100644 --- a/src/fix_group.h +++ b/src/fix_group.h @@ -40,7 +40,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 9aec2c8382..41c24b8f48 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -40,8 +40,8 @@ using namespace LAMMPS_NS; -#define MAX_GROUP 32 -#define EPSILON 1.0e-6 +static constexpr int MAX_GROUP = 32; +static constexpr double EPSILON = 1.0e-6; enum{NONE,TYPE,MOLECULE,ID}; enum{LT,LE,GT,GE,EQ,NEQ,BETWEEN}; @@ -176,13 +176,13 @@ void Group::assign(int narg, char **arg) if (narg != 3) error->all(FLERR,"Illegal group command"); - int iregion = domain->find_region(arg[2]); - if (iregion == -1) error->all(FLERR,"Group region ID does not exist"); - domain->regions[iregion]->init(); - domain->regions[iregion]->prematch(); + auto region = domain->get_region_by_id(arg[2]); + if (!region) error->all(FLERR,"Group region {} does not exist", arg[2]); + region->init(); + region->prematch(); for (i = 0; i < nlocal; i++) - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2])) + if (region->match(x[i][0],x[i][1],x[i][2])) mask[i] |= bit; // create an empty group @@ -794,15 +794,14 @@ bigint Group::count(int igroup) count atoms in group and region ------------------------------------------------------------------------- */ -bigint Group::count(int igroup, int iregion) +bigint Group::count(int igroup, Region *region) { - int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); + const int groupbit = bitmask[igroup]; double **x = atom->x; int *mask = atom->mask; - int nlocal = atom->nlocal; + const int nlocal = atom->nlocal; int n = 0; for (int i = 0; i < nlocal; i++) @@ -849,10 +848,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; @@ -904,10 +902,9 @@ double Group::charge(int igroup) compute the total charge of group of atoms in region ------------------------------------------------------------------------- */ -double Group::charge(int igroup, int iregion) +double Group::charge(int igroup, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -973,10 +970,9 @@ void Group::bounds(int igroup, double *minmax) periodic images are not considered, so atoms are NOT unwrapped ------------------------------------------------------------------------- */ -void Group::bounds(int igroup, double *minmax, int iregion) +void Group::bounds(int igroup, double *minmax, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double extent[6]; @@ -1073,10 +1069,9 @@ void Group::xcm(int igroup, double masstotal, double *cm) must unwrap atoms to compute center-of-mass correctly ------------------------------------------------------------------------- */ -void Group::xcm(int igroup, double masstotal, double *cm, int iregion) +void Group::xcm(int igroup, double masstotal, double *cm, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1173,10 +1168,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; @@ -1245,10 +1239,9 @@ void Group::fcm(int igroup, double *cm) compute the total force on group of atoms in region ------------------------------------------------------------------------- */ -void Group::fcm(int igroup, double *cm, int iregion) +void Group::fcm(int igroup, double *cm, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1308,10 +1301,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; @@ -1387,10 +1379,9 @@ double Group::gyration(int igroup, double masstotal, double *cm) must unwrap atoms to compute Rg correctly ------------------------------------------------------------------------- */ -double Group::gyration(int igroup, double masstotal, double *cm, int iregion) +double Group::gyration(int igroup, double masstotal, double *cm, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1469,10 +1460,9 @@ void Group::angmom(int igroup, double *cm, double *lmom) must unwrap atoms to compute L correctly ------------------------------------------------------------------------- */ -void Group::angmom(int igroup, double *cm, double *lmom, int iregion) +void Group::angmom(int igroup, double *cm, double *lmom, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1548,10 +1538,9 @@ void Group::torque(int igroup, double *cm, double *tq) must unwrap atoms to compute T correctly ------------------------------------------------------------------------- */ -void Group::torque(int igroup, double *cm, double *tq, int iregion) +void Group::torque(int igroup, double *cm, double *tq, Region *region) { int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; @@ -1634,12 +1623,11 @@ void Group::inertia(int igroup, double *cm, double itensor[3][3]) must unwrap atoms to compute itensor correctly ------------------------------------------------------------------------- */ -void Group::inertia(int igroup, double *cm, double itensor[3][3], int iregion) +void Group::inertia(int igroup, double *cm, double itensor[3][3], Region *region) { int i,j; int groupbit = bitmask[igroup]; - Region *region = domain->regions[iregion]; region->prematch(); double **x = atom->x; diff --git a/src/group.h b/src/group.h index 8c4d10a24f..66c5e737f9 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,31 +39,31 @@ 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 - double mass(int); // total mass of atoms in group - double mass(int, int); + bigint count_all(); // count atoms in group all + bigint count(int); // count atoms in group + bigint count(int, Region *); // count atoms in group & region + double mass(int); // total mass of atoms in group + double mass(int, Region *); double charge(int); // total charge of atoms in group - double charge(int, int); + double charge(int, Region *); void bounds(int, double *); // bounds of atoms in group - void bounds(int, double *, int); + void bounds(int, double *, Region *); void xcm(int, double, double *); // center-of-mass coords of group - void xcm(int, double, double *, int); + void xcm(int, double, double *, Region *); 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); + void fcm(int, double *, Region *); 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); + double gyration(int, double, double *, Region *); void angmom(int, double *, double *); // angular momentum of group - void angmom(int, double *, double *, int); + void angmom(int, double *, double *, Region *); void torque(int, double *, double *); // torque on group - void torque(int, double *, double *, int); + void torque(int, double *, double *, Region *); void inertia(int, double *, double[3][3]); // inertia tensor - void inertia(int, double *, double[3][3], int); + void inertia(int, double *, double[3][3], Region *); void omega(double *, double[3][3], double *); // angular velocity private: diff --git a/src/improper.h b/src/improper.h index 7d1aa13029..dacdfc9797 100644 --- a/src/improper.h +++ b/src/improper.h @@ -25,7 +25,7 @@ class Improper : protected Pointers { public: int allocated; int *setflag; - int writedata; // 1 if writes coeffs to data file + int writedata; // 1 if writes coeffs to data file int born_matrix_enable; double energy; // accumulated energies double virial[6]; // accumulated virial: xx,yy,zz,xy,xz,yz @@ -56,7 +56,8 @@ class Improper : protected Pointers { virtual void read_restart_settings(FILE *){}; virtual void write_data(FILE *) {} virtual double memory_usage(); - virtual void born_matrix(int/*dtype*/, int/*at1*/, int/*at2*/, int/*at3*/, int /*at4*/, double& du, double& du2) + virtual void born_matrix(int /*dtype*/, int /*at1*/, int /*at2*/, int /*at3*/, int /*at4*/, + double &du, double &du2) { du = 0.0; du2 = 0.0; diff --git a/src/info.cpp b/src/info.cpp index 5e53864253..d50c45457b 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -546,19 +546,17 @@ void Info::command(int narg, char **arg) } if (flags & REGIONS) { - int nreg = domain->nregion; - Region **regs = domain->regions; fputs("\nRegion information:\n",out); - for (int i=0; i < nreg; ++i) { + int i=0; + for (auto ® : domain->get_region_list()) { fmt::print(out,"Region[{:3d}]: {:16} style = {:16} side = {}\n", - i, std::string(regs[i]->id)+',', - std::string(regs[i]->style)+',', - regs[i]->interior ? "in" : "out"); - if (regs[i]->bboxflag) + i, std::string(reg->id)+',', std::string(reg->style)+',', + reg->interior ? "in" : "out"); + if (reg->bboxflag) fmt::print(out," Boundary: lo {:.8} {:.8} {:.8} hi {:.8} {:.8} {:.8}\n", - regs[i]->extent_xlo, regs[i]->extent_ylo, - regs[i]->extent_zlo, regs[i]->extent_xhi, - regs[i]->extent_yhi, regs[i]->extent_zhi); + reg->extent_xlo, reg->extent_ylo, + reg->extent_zlo, reg->extent_xhi, + reg->extent_yhi, reg->extent_zhi); else fputs(" No Boundary\n",out); } } @@ -916,12 +914,8 @@ bool Info::is_defined(const char *category, const char *name) return true; } } else if (strcmp(category,"region") == 0) { - int nreg = domain->nregion; - Region **regs = domain->regions; - for (int i=0; i < nreg; ++i) { - if (strcmp(regs[i]->id,name) == 0) - return true; - } + for (auto ® : domain->get_region_list()) + if (strcmp(reg->id,name) == 0) return true; } else if (strcmp(category,"variable") == 0) { int nvar = input->variable->nvar; char **names = input->variable->names; diff --git a/src/library.cpp b/src/library.cpp index 8ab97321ba..793c817e9a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4772,10 +4772,8 @@ int lammps_has_id(void *handle, const char *category, const char *name) { if (strcmp(name,molecule[i]->id) == 0) return 1; } } else if (strcmp(category,"region") == 0) { - int nregion = lmp->domain->nregion; - Region **region = lmp->domain->regions; - for (int i=0; i < nregion; ++i) { - if (strcmp(name,region[i]->id) == 0) return 1; + for (auto ® : lmp->domain->get_region_list()) { + if (strcmp(name,reg->id) == 0) return 1; } } else if (strcmp(category,"variable") == 0) { int nvariable = lmp->input->variable->nvar; @@ -4818,7 +4816,7 @@ int lammps_id_count(void *handle, const char *category) { } else if (strcmp(category,"molecule") == 0) { return lmp->atom->nmolecule; } else if (strcmp(category,"region") == 0) { - return lmp->domain->nregion; + return lmp->domain->get_region_list().size(); } else if (strcmp(category,"variable") == 0) { return lmp->input->variable->nvar; } @@ -4848,8 +4846,7 @@ set to an empty string, otherwise 1. * \param buf_size size of the provided string buffer * \return 1 if successful, otherwise 0 */ -int lammps_id_name(void *handle, const char *category, int idx, - char *buffer, int buf_size) { +int lammps_id_name(void *handle, const char *category, int idx, char *buffer, int buf_size) { auto lmp = (LAMMPS *) handle; if (strcmp(category,"compute") == 0) { @@ -4878,8 +4875,9 @@ int lammps_id_name(void *handle, const char *category, int idx, return 1; } } else if (strcmp(category,"region") == 0) { - if ((idx >=0) && (idx < lmp->domain->nregion)) { - strncpy(buffer, lmp->domain->regions[idx]->id, buf_size); + auto regions = lmp->domain->get_region_list(); + if ((idx >=0) && (idx < (int) regions.size())) { + strncpy(buffer, regions[idx]->id, buf_size); return 1; } } else if (strcmp(category,"variable") == 0) { diff --git a/src/math_const.h b/src/math_const.h index 1ad0b3e717..1a6b5c3b47 100644 --- a/src/math_const.h +++ b/src/math_const.h @@ -23,6 +23,7 @@ namespace MathConst { static constexpr double MY_2PI = 6.28318530717958647692; // 2pi static constexpr double MY_3PI = 9.42477796076937971538; // 3pi static constexpr double MY_4PI = 12.56637061435917295384; // 4pi + static constexpr double MY_4PI3 = 4.18879020478639098461; // 4/3pi static constexpr double MY_PI2 = 1.57079632679489661923; // pi/2 static constexpr double MY_PI4 = 0.78539816339744830962; // pi/4 static constexpr double MY_PIS = 1.77245385090551602729; // sqrt(pi) 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.cpp b/src/modify.cpp index 6e7e16d2b8..90b911b9ab 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -457,13 +457,11 @@ void Modify::pre_reverse(int eflag, int vflag) void Modify::post_force(int vflag) { if (n_post_force_group) { - for (int i = 0; i < n_post_force_group; i++) - fix[list_post_force_group[i]]->post_force(vflag); + for (int i = 0; i < n_post_force_group; i++) fix[list_post_force_group[i]]->post_force(vflag); } if (n_post_force) { - for (int i = 0; i < n_post_force; i++) - fix[list_post_force[i]]->post_force(vflag); + for (int i = 0; i < n_post_force; i++) fix[list_post_force[i]]->post_force(vflag); } } @@ -886,7 +884,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) fix[ifix]->style = utils::strdup(estyle); } } - if (fix[ifix] == nullptr && lmp->suffix2) { + if ((fix[ifix] == nullptr) && lmp->suffix2) { std::string estyle = arg[2] + std::string("/") + lmp->suffix2; if (fix_map->find(estyle) != fix_map->end()) { FixCreator &fix_creator = (*fix_map)[estyle]; @@ -897,7 +895,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) } } - if (fix[ifix] == nullptr && fix_map->find(arg[2]) != fix_map->end()) { + if ((fix[ifix] == nullptr) && (fix_map->find(arg[2]) != fix_map->end())) { FixCreator &fix_creator = (*fix_map)[arg[2]]; fix[ifix] = fix_creator(lmp, narg, arg); } @@ -1754,13 +1752,12 @@ void Modify::list_init_post_force_group(int &n, int *&list) n = 0; for (int i = 0; i < nfix; i++) - if (strcmp(fix[i]->style,"GROUP") == 0) n++; + if (strcmp(fix[i]->style, "GROUP") == 0) n++; list = new int[n]; n = 0; for (int i = 0; i < nfix; i++) - if (strcmp(fix[i]->style,"GROUP") == 0) - list[n++] = i; + if (strcmp(fix[i]->style, "GROUP") == 0) list[n++] = i; } /* ---------------------------------------------------------------------- diff --git a/src/modify.h b/src/modify.h index 5e05cfce6a..303ec65124 100644 --- a/src/modify.h +++ b/src/modify.h @@ -184,8 +184,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 bc86f66b24..2c0c574f70 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; } @@ -401,7 +401,6 @@ double PairHybridScaled::single(int i, int j, int itype, int jtype, double rsq, double fone; fforce = 0.0; double esum = 0.0; - double scale; for (int m = 0; m < nmap[itype][jtype]; m++) { auto pstyle = styles[map[itype][jtype][m]]; @@ -430,8 +429,8 @@ double PairHybridScaled::single(int i, int j, int itype, int jtype, double rsq, ------------------------------------------------------------------------- */ void PairHybridScaled::born_matrix(int i, int j, int itype, int jtype, double rsq, - double factor_coul, double factor_lj, - double &dupair, double &du2pair) + double factor_coul, double factor_lj, double &dupair, + double &du2pair) { if (nmap[itype][jtype] == 0) error->one(FLERR, "Invoked pair born_matrix on pair style none"); @@ -468,8 +467,8 @@ void PairHybridScaled::born_matrix(int i, int j, int itype, int jtype, double rs du = du2 = 0.0; scale = scaleval[map[itype][jtype][m]]; pstyle->born_matrix(i, j, itype, jtype, rsq, factor_coul, factor_lj, du, du2); - dupair += scale*du; - du2pair += scale*du2; + dupair += scale * du; + du2pair += scale * du2; } } } @@ -528,8 +527,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 f41e5ef740..73d46b26ce 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -479,7 +479,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; } @@ -488,8 +488,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; } @@ -674,23 +674,23 @@ double PairLJCut::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, /* ---------------------------------------------------------------------- */ void PairLJCut::born_matrix(int /*i*/, int /*j*/, int itype, int jtype, double rsq, - double /*factor_coul*/, double factor_lj, - double &dupair, double &du2pair) + double /*factor_coul*/, double factor_lj, double &dupair, + double &du2pair) { - double rinv,r2inv,r6inv,du,du2; + double rinv, r2inv, r6inv, du, du2; - r2inv = 1.0/rsq; + r2inv = 1.0 / rsq; rinv = sqrt(r2inv); - r6inv = r2inv*r2inv*r2inv; + r6inv = r2inv * r2inv * r2inv; // Reminder: lj1 = 48*e*s^12, lj2 = 24*e*s^6 // so dupair = -forcelj/r = -fforce*r (forcelj from single method) - du = r6inv * rinv * (lj2[itype][jtype] - lj1[itype][jtype]*r6inv); - du2 = r6inv * r2inv * (13*lj1[itype][jtype]*r6inv - 7*lj2[itype][jtype]); + du = r6inv * rinv * (lj2[itype][jtype] - lj1[itype][jtype] * r6inv); + du2 = r6inv * r2inv * (13 * lj1[itype][jtype] * r6inv - 7 * lj2[itype][jtype]); - dupair = factor_lj*du; - du2pair = factor_lj*du2; + dupair = factor_lj * du; + du2pair = factor_lj * du2; } /* ---------------------------------------------------------------------- */ 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 b99aedecf3..5a715d737f 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 @@ -704,8 +704,7 @@ void Respa::recurse(int ilevel) timer->stamp(Timer::COMM); } timer->stamp(); - if (modify->n_post_force_respa_any) - modify->post_force_respa(vflag, ilevel, iloop); + if (modify->n_post_force_respa_any) modify->post_force_respa(vflag, ilevel, iloop); modify->final_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); } diff --git a/src/set.cpp b/src/set.cpp index 904863a596..2843281d78 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -713,13 +713,13 @@ void Set::selection(int n) else select[i] = 0; } else if (style == REGION_SELECT) { - int iregion = domain->find_region(id); - if (iregion == -1) error->all(FLERR,"Set region ID does not exist"); - domain->regions[iregion]->prematch(); + auto region = domain->get_region_by_id(id); + if (!region) error->all(FLERR,"Set region {} does not exist", id); + region->prematch(); double **x = atom->x; for (int i = 0; i < n; i++) - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2])) + if (region->match(x[i][0],x[i][1],x[i][2])) select[i] = 1; else select[i] = 0; } 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/variable.cpp b/src/variable.cpp index 42afda5cd8..8455227ad7 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -3043,18 +3043,18 @@ double Variable::eval_tree(Tree *tree, int i) } if (tree->type == GMASK) { - if (atom->mask[i] & tree->ivalue1) return 1.0; + if (atom->mask[i] & tree->ivalue) return 1.0; else return 0.0; } if (tree->type == RMASK) { - if (domain->regions[tree->ivalue1]->match(atom->x[i][0], atom->x[i][1], atom->x[i][2])) return 1.0; + if (tree->region->match(atom->x[i][0], atom->x[i][1], atom->x[i][2])) return 1.0; else return 0.0; } if (tree->type == GRMASK) { - if ((atom->mask[i] & tree->ivalue1) && - (domain->regions[tree->ivalue2]->match(atom->x[i][0], atom->x[i][1], atom->x[i][2]))) return 1.0; + if ((atom->mask[i] & tree->ivalue) && + (tree->region->match(atom->x[i][0], atom->x[i][1], atom->x[i][2]))) return 1.0; else return 0.0; } @@ -3664,32 +3664,31 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre int igroup = group->find(args[0]); if (igroup == -1) { - std::string mesg = "Group ID '"; - mesg += args[0]; - mesg += "' in variable formula does not exist"; - print_var_error(FLERR,mesg,ivar); + const auto errmesg = fmt::format("Group {} in variable formula does not exist", args[0]); + print_var_error(FLERR, errmesg, ivar); } // match word to group function double value = 0.0; + const auto group_errmesg = fmt::format("Invalid {}() function in variable formula", word); if (strcmp(word,"count") == 0) { if (narg == 1) value = group->count(igroup); else if (narg == 2) value = group->count(igroup,region_function(args[1],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"mass") == 0) { if (narg == 1) value = group->mass(igroup); else if (narg == 2) value = group->mass(igroup,region_function(args[1],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"charge") == 0) { if (narg == 1) value = group->charge(igroup); else if (narg == 2) value = group->charge(igroup,region_function(args[1],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"xcm") == 0) { atom->check_mass(FLERR); @@ -3698,14 +3697,14 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre double masstotal = group->mass(igroup); group->xcm(igroup,masstotal,xcm); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = xcm[0]; else if (strcmp(args[1],"y") == 0) value = xcm[1]; else if (strcmp(args[1],"z") == 0) value = xcm[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"vcm") == 0) { atom->check_mass(FLERR); @@ -3714,38 +3713,38 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre double masstotal = group->mass(igroup); group->vcm(igroup,masstotal,vcm); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->vcm(igroup,masstotal,vcm,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->vcm(igroup,masstotal,vcm,region); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = vcm[0]; else if (strcmp(args[1],"y") == 0) value = vcm[1]; else if (strcmp(args[1],"z") == 0) value = vcm[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"fcm") == 0) { double fcm[3]; if (narg == 2) group->fcm(igroup,fcm); else if (narg == 3) group->fcm(igroup,fcm,region_function(args[2],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = fcm[0]; else if (strcmp(args[1],"y") == 0) value = fcm[1]; else if (strcmp(args[1],"z") == 0) value = fcm[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"bound") == 0) { double minmax[6]; if (narg == 2) group->bounds(igroup,minmax); else if (narg == 3) group->bounds(igroup,minmax,region_function(args[2],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"xmin") == 0) value = minmax[0]; else if (strcmp(args[1],"xmax") == 0) value = minmax[1]; else if (strcmp(args[1],"ymin") == 0) value = minmax[2]; else if (strcmp(args[1],"ymax") == 0) value = minmax[3]; else if (strcmp(args[1],"zmin") == 0) value = minmax[4]; else if (strcmp(args[1],"zmax") == 0) value = minmax[5]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"gyration") == 0) { atom->check_mass(FLERR); @@ -3755,16 +3754,16 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre group->xcm(igroup,masstotal,xcm); value = group->gyration(igroup,masstotal,xcm); } else if (narg == 2) { - int iregion = region_function(args[1],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - value = group->gyration(igroup,masstotal,xcm,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[1],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + value = group->gyration(igroup,masstotal,xcm,region); + } else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"ke") == 0) { if (narg == 1) value = group->ke(igroup); else if (narg == 2) value = group->ke(igroup,region_function(args[1],ivar)); - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"angmom") == 0) { atom->check_mass(FLERR); @@ -3774,15 +3773,15 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre group->xcm(igroup,masstotal,xcm); group->angmom(igroup,xcm,lmom); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - group->angmom(igroup,xcm,lmom,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + group->angmom(igroup,xcm,lmom,region); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = lmom[0]; else if (strcmp(args[1],"y") == 0) value = lmom[1]; else if (strcmp(args[1],"z") == 0) value = lmom[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"torque") == 0) { atom->check_mass(FLERR); @@ -3792,15 +3791,15 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre group->xcm(igroup,masstotal,xcm); group->torque(igroup,xcm,tq); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - group->torque(igroup,xcm,tq,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + group->torque(igroup,xcm,tq,region); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = tq[0]; else if (strcmp(args[1],"y") == 0) value = tq[1]; else if (strcmp(args[1],"z") == 0) value = tq[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"inertia") == 0) { atom->check_mass(FLERR); @@ -3810,18 +3809,18 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre group->xcm(igroup,masstotal,xcm); group->inertia(igroup,xcm,inertia); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - group->inertia(igroup,xcm,inertia,iregion); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + group->inertia(igroup,xcm,inertia,region); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"xx") == 0) value = inertia[0][0]; else if (strcmp(args[1],"yy") == 0) value = inertia[1][1]; else if (strcmp(args[1],"zz") == 0) value = inertia[2][2]; else if (strcmp(args[1],"xy") == 0) value = inertia[0][1]; else if (strcmp(args[1],"yz") == 0) value = inertia[1][2]; else if (strcmp(args[1],"xz") == 0) value = inertia[0][2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } else if (strcmp(word,"omega") == 0) { atom->check_mass(FLERR); @@ -3833,17 +3832,17 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre group->inertia(igroup,xcm,inertia); group->omega(angmom,inertia,omega); } else if (narg == 3) { - int iregion = region_function(args[2],ivar); - double masstotal = group->mass(igroup,iregion); - group->xcm(igroup,masstotal,xcm,iregion); - group->angmom(igroup,xcm,angmom,iregion); - group->inertia(igroup,xcm,inertia,iregion); + auto region = region_function(args[2],ivar); + double masstotal = group->mass(igroup,region); + group->xcm(igroup,masstotal,xcm,region); + group->angmom(igroup,xcm,angmom,region); + group->inertia(igroup,xcm,inertia,region); group->omega(angmom,inertia,omega); - } else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + } else print_var_error(FLERR,group_errmesg,ivar); if (strcmp(args[1],"x") == 0) value = omega[0]; else if (strcmp(args[1],"y") == 0) value = omega[1]; else if (strcmp(args[1],"z") == 0) value = omega[2]; - else print_var_error(FLERR,"Invalid group function in variable formula",ivar); + else print_var_error(FLERR,group_errmesg,ivar); } // delete stored args @@ -3864,21 +3863,16 @@ int Variable::group_function(char *word, char *contents, Tree **tree, Tree **tre /* ---------------------------------------------------------------------- */ -int Variable::region_function(char *id, int ivar) +Region *Variable::region_function(char *id, int ivar) { - int iregion = domain->find_region(id); - if (iregion == -1) { - std::string mesg = "Region ID '"; - mesg += id; - mesg += "' in variable formula does not exist"; - print_var_error(FLERR,mesg,ivar); - } + auto region = domain->get_region_by_id(id); + if (!region) + print_var_error(FLERR, fmt::format("Region {} in variable formula does not exist", id), ivar); // init region in case sub-regions have been deleted - domain->regions[iregion]->init(); - - return iregion; + region->init(); + return region; } /* ---------------------------------------------------------------------- @@ -4149,7 +4143,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t auto newtree = new Tree(); newtree->type = GMASK; - newtree->ivalue1 = group->bitmask[igroup]; + newtree->ivalue = group->bitmask[igroup]; treestack[ntreestack++] = newtree; } else if (strcmp(word,"rmask") == 0) { @@ -4158,12 +4152,12 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t if (narg != 1) print_var_error(FLERR,"Invalid special function in variable formula",ivar); - int iregion = region_function(args[0],ivar); - domain->regions[iregion]->prematch(); + auto region = region_function(args[0],ivar); + region->prematch(); auto newtree = new Tree(); newtree->type = RMASK; - newtree->ivalue1 = iregion; + newtree->region = region; treestack[ntreestack++] = newtree; } else if (strcmp(word,"grmask") == 0) { @@ -4175,13 +4169,13 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t int igroup = group->find(args[0]); if (igroup == -1) print_var_error(FLERR,"Group ID in variable formula does not exist",ivar); - int iregion = region_function(args[1],ivar); - domain->regions[iregion]->prematch(); + auto region = region_function(args[1],ivar); + region->prematch(); auto newtree = new Tree(); newtree->type = GRMASK; - newtree->ivalue1 = group->bitmask[igroup]; - newtree->ivalue2 = iregion; + newtree->ivalue = group->bitmask[igroup]; + newtree->region = region; treestack[ntreestack++] = newtree; // special function for file-style or atomfile-style variables diff --git a/src/variable.h b/src/variable.h index 7b51b45f38..ed8a2a9964 100644 --- a/src/variable.h +++ b/src/variable.h @@ -17,6 +17,7 @@ #include "pointers.h" namespace LAMMPS_NS { +class Region; class Variable : protected Pointers { friend class Info; @@ -110,14 +111,15 @@ class Variable : protected Pointers { int nvector; // length of array for vector-style variable int nstride; // stride between atoms if array is a 2d array int selfalloc; // 1 if array is allocated here, else 0 - int ivalue1, ivalue2; // extra values needed for gmask,rmask,grmask + int ivalue; // extra value needed for gmask, grmask int nextra; // # of additional args beyond first 2 + Region *region; // region pointer for rmask, grmask Tree *first, *second; // ptrs further down tree for first 2 args Tree **extra; // ptrs further down tree for nextra args Tree() : - array(nullptr), iarray(nullptr), barray(nullptr), selfalloc(0), ivalue1(0), ivalue2(0), - nextra(0), first(nullptr), second(nullptr), extra(nullptr) + array(nullptr), iarray(nullptr), barray(nullptr), selfalloc(0), ivalue(0), nextra(0), + region(nullptr), first(nullptr), second(nullptr), extra(nullptr) { } }; @@ -135,7 +137,7 @@ class Variable : protected Pointers { int find_matching_paren(char *, int, char *&, int); int math_function(char *, char *, Tree **, Tree **, int &, double *, int &, int); int group_function(char *, char *, Tree **, Tree **, int &, double *, int &, int); - int region_function(char *, int); + Region *region_function(char *, int); int special_function(char *, char *, Tree **, Tree **, int &, double *, int &, int); void peratom2global(int, char *, double *, int, tagint, Tree **, Tree **, int &, double *, int &); int is_atom_vector(char *); 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); diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index a356a02cca..b0706ea775 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -151,7 +151,8 @@ TEST_F(GroupTest, RegionClear) ASSERT_EQ(group->count_all(), lmp->atom->natoms); TEST_FAILURE(".*ERROR: Illegal group command.*", command("group three region left xxx");); - TEST_FAILURE(".*ERROR: Group region ID does not exist.*", command("group four region dummy");); + TEST_FAILURE(".*ERROR: Group region dummy does not exist.*", + command("group four region dummy");); BEGIN_HIDE_OUTPUT(); command("group one clear"); @@ -196,8 +197,8 @@ TEST_F(GroupTest, SelectRestart) ASSERT_EQ(group->count(group->find("four")), 32); ASSERT_EQ(group->count(group->find("five")), 16); ASSERT_EQ(group->count(group->find("six")), 8); - ASSERT_EQ(group->count(group->find("half"), domain->find_region("top")), 8); - ASSERT_DOUBLE_EQ(group->mass(group->find("half"), domain->find_region("top")), 8.0); + ASSERT_EQ(group->count(group->find("half"), domain->get_region_by_id("top")), 8); + ASSERT_DOUBLE_EQ(group->mass(group->find("half"), domain->get_region_by_id("top")), 8.0); BEGIN_HIDE_OUTPUT(); command("write_restart group.restart"); @@ -243,9 +244,9 @@ TEST_F(GroupTest, Molecular) ASSERT_EQ(group->count(group->find("two")), 16); ASSERT_EQ(group->count(group->find("three")), 15); ASSERT_DOUBLE_EQ(group->mass(group->find("half")), 40); - ASSERT_DOUBLE_EQ(group->mass(group->find("half"), domain->find_region("top")), 10); + ASSERT_DOUBLE_EQ(group->mass(group->find("half"), domain->get_region_by_id("top")), 10); ASSERT_NEAR(group->charge(group->find("top")), 0, 1.0e-14); - ASSERT_NEAR(group->charge(group->find("right"), domain->find_region("top")), 0, 1.0e-14); + ASSERT_NEAR(group->charge(group->find("right"), domain->get_region_by_id("top")), 0, 1.0e-14); TEST_FAILURE(".*ERROR: Illegal group command.*", command("group three include xxx");); } diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long_soft.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long_soft.yaml index a032e501dd..29cd06c4a9 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long_soft.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long_soft.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:32 2022 -epsilon: 2.5e-13 +epsilon: 1.0e-12 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml b/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml index 91c42f3bbd..78a20a9d19 100644 --- a/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml +++ b/unittest/force-styles/tests/mol-pair-tip4p_cut.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:36 2022 -epsilon: 7.5e-13 +epsilon: 1.0e-11 skip_tests: prerequisites: ! | atom full