From b8f606357842967f84e7dad3c10b871d3fc66e42 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 10:47:49 -0400 Subject: [PATCH 01/21] correct documentation of angle style cosine/periodic --- doc/src/angle_cosine_periodic.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 71c2caa3f0..61b6407eb9 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -32,7 +32,7 @@ center: .. math:: - E = C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] + E = 2.0*C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. @@ -47,10 +47,9 @@ or :doc:`read_restart ` commands: * :math:`B` = 1 or -1 * :math:`n` = 1, 2, 3, 4, 5 or 6 for periodicity -Note that the prefactor :math:`C` is specified and not the overall force +Note that the prefactor :math:`C` is specified as coefficient and not the overall force constant :math:`K = \frac{C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the -linear geometry. When :math:`B = -1`, it leads to a maximum for the linear -geometry. +linear geometry. When :math:`B = -1`, it leads to a maximum for the linear geometry. ---------- From e8c8ceaf81a0bc7621a6f033545ddcfd1d41bb80 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 11:28:22 -0400 Subject: [PATCH 02/21] correct attribution of angle style cosine/squared with DREIDING --- doc/src/Howto_bioFF.rst | 1 + doc/src/angle_cosine_periodic.rst | 7 ++----- doc/src/angle_cosine_squared.rst | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/src/Howto_bioFF.rst b/doc/src/Howto_bioFF.rst index bac1b566e1..9bffe5d4c9 100644 --- a/doc/src/Howto_bioFF.rst +++ b/doc/src/Howto_bioFF.rst @@ -91,6 +91,7 @@ documentation for the formula it computes. * :doc:`bond_style ` harmonic * :doc:`bond_style ` morse +* :doc:`angle_style ` cosine/squared * :doc:`angle_style ` harmonic * :doc:`angle_style ` cosine * :doc:`angle_style ` cosine/periodic diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 61b6407eb9..ec2426154d 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -24,9 +24,8 @@ Examples Description """"""""""" -The *cosine/periodic* angle style uses the following potential, which -is commonly used in the :doc:`DREIDING ` force field, -particularly for organometallic systems where :math:`n` = 4 might be used +The *cosine/periodic* angle style uses the following potential, which may be +particularly used for organometallic systems where :math:`n` = 4 might be used for an octahedral complex and :math:`n` = 3 might be used for a trigonal center: @@ -36,8 +35,6 @@ center: where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. -See :ref:`(Mayo) ` for a description of the DREIDING force field - The following coefficients must be defined for each angle type via the :doc:`angle_coeff ` command as in the example above, or in the data file or restart files read by the :doc:`read_data ` diff --git a/doc/src/angle_cosine_squared.rst b/doc/src/angle_cosine_squared.rst index 4a6a1debe9..d674eb61d8 100644 --- a/doc/src/angle_cosine_squared.rst +++ b/doc/src/angle_cosine_squared.rst @@ -30,8 +30,11 @@ The *cosine/squared* angle style uses the potential E = K [\cos(\theta) - \cos(\theta_0)]^2 -where :math:`\theta_0` is the equilibrium value of the angle, and :math:`K` is a -prefactor. Note that the usual 1/2 factor is included in :math:`K`. +, which is commonly used in the :doc:`DREIDING ` force field, +where :math:`\theta_0` is the equilibrium value of the angle, and :math:`K` +is a prefactor. Note that the usual 1/2 factor is included in :math:`K`. + +See :ref:`(Mayo) ` for a description of the DREIDING force field. The following coefficients must be defined for each angle type via the :doc:`angle_coeff ` command as in the example above, or in @@ -66,3 +69,10 @@ Default """"""" none + +---------- + +.. _cosine-Mayo: + +**(Mayo)** Mayo, Olfason, Goddard III, J Phys Chem, 94, 8897-8909 +(1990). From aabfe40ad3341d0676a875ccbee3c2443748126b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 15:10:45 -0400 Subject: [PATCH 03/21] add missing 1/n**2 term to pair style cosine/periodic energy function --- doc/src/angle_cosine_periodic.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index ec2426154d..5e13c98cfc 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -31,7 +31,7 @@ center: .. math:: - E = 2.0*C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] + E = \frac{2.0}{n^2} * C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. From 58744f0a4926a0d9a1991da4718837eb48dff463 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 15:32:24 -0400 Subject: [PATCH 04/21] correct expression for K --- doc/src/angle_cosine_periodic.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 5e13c98cfc..8c60ac1ebb 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -45,7 +45,7 @@ or :doc:`read_restart ` commands: * :math:`n` = 1, 2, 3, 4, 5 or 6 for periodicity Note that the prefactor :math:`C` is specified as coefficient and not the overall force -constant :math:`K = \frac{C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the +constant :math:`K = \frac{2 C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the linear geometry. When :math:`B = -1`, it leads to a maximum for the linear geometry. ---------- From 56121a524c97ca1606be03ac9243e4b47026412d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 16:26:50 -0400 Subject: [PATCH 05/21] correct equilibrium angle computation for angle style cosine/periodic if b < 0 --- src/MOLECULE/angle_cosine_periodic.cpp | 4 ++-- unittest/force-styles/tests/angle-cosine_periodic.yaml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MOLECULE/angle_cosine_periodic.cpp b/src/MOLECULE/angle_cosine_periodic.cpp index f72a196b41..0df103c333 100644 --- a/src/MOLECULE/angle_cosine_periodic.cpp +++ b/src/MOLECULE/angle_cosine_periodic.cpp @@ -222,9 +222,9 @@ void AngleCosinePeriodic::coeff(int narg, char **arg) /* ---------------------------------------------------------------------- */ -double AngleCosinePeriodic::equilibrium_angle(int /*i*/) +double AngleCosinePeriodic::equilibrium_angle(int i) { - return MY_PI; + return MY_PI*(1.0 - (b[i]>0)?0.0:1.0/static_cast(multiplicity[i])); } /* ---------------------------------------------------------------------- diff --git a/unittest/force-styles/tests/angle-cosine_periodic.yaml b/unittest/force-styles/tests/angle-cosine_periodic.yaml index 814c837dcd..d8fba5c6ee 100644 --- a/unittest/force-styles/tests/angle-cosine_periodic.yaml +++ b/unittest/force-styles/tests/angle-cosine_periodic.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:34 202 +lammps_version: 10 Mar 2021 +date_generated: Mon Mar 22 16:25:49 202 epsilon: 2.5e-13 prerequisites: ! | atom full @@ -14,7 +14,7 @@ angle_coeff: ! | 2 45.0 1 2 3 50.0 -1 3 4 100.0 -1 4 -equilibrium: 4 3.141592653589793 3.141592653589793 3.141592653589793 3.141592653589793 +equilibrium: 4 1.5707963267948966 1.5707963267948966 0 0 extract: ! "" natoms: 29 init_energy: 946.676664091363 From ca1496e02848265aa0930002479f996fa4c8f3e1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 21:36:25 -0400 Subject: [PATCH 06/21] simplify --- src/KIM/pair_kim.cpp | 49 ++++++++----------- src/USER-MANIFOLD/fix_manifoldforce.cpp | 18 +++---- src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp | 20 +++----- src/USER-MISC/dihedral_table.cpp | 6 +-- 4 files changed, 34 insertions(+), 59 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 1b709a65c2..cf6374ab2d 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -477,12 +477,10 @@ void PairKIM::coeff(int narg, char **arg) if (paramname == str_name_str) break; } - if (param_index >= numberOfParameters) { - auto msg = fmt::format("Wrong argument for pair coefficients.\n" - "This Model does not have the requested " - "'{}' parameter", paramname); - error->all(FLERR,msg); - } + if (param_index >= numberOfParameters) + error->all(FLERR,fmt::format("Wrong argument for pair coefficients.\n" + "This Model does not have the requested " + "'{}' parameter", paramname)); // Get the index_range for the requested parameter int nlbound(0); @@ -492,12 +490,10 @@ void PairKIM::coeff(int narg, char **arg) std::string argtostr(arg[i++]); // Check to see if the indices range contains only integer numbers & : - if (argtostr.find_first_not_of("0123456789:") != std::string::npos) { - auto msg = fmt::format("Illegal index_range.\nExpected integer " - "parameter(s) instead of '{}' in " - "index_range", argtostr); - error->all(FLERR,msg); - } + if (argtostr.find_first_not_of("0123456789:") != std::string::npos) + error->all(FLERR,fmt::format("Illegal index_range.\nExpected integer" + " parameter(s) instead of '{}' in " + "index_range", argtostr)); std::string::size_type npos = argtostr.find(':'); if (npos != std::string::npos) { @@ -507,21 +503,17 @@ void PairKIM::coeff(int narg, char **arg) nubound = atoi(words[1].c_str()); if (nubound < 1 || nubound > extent || - nlbound < 1 || nlbound > nubound) { - auto msg = fmt::format("Illegal index_range '{}-{}' for '{}' " - "parameter with the extent of '{}'", - nlbound, nubound, paramname, extent); - error->all(FLERR,msg); - } + nlbound < 1 || nlbound > nubound) + error->all(FLERR,fmt::format("Illegal index_range '{}-{}' for '{}' " + "parameter with the extent of '{}'", + nlbound, nubound, paramname, extent)); } else { nlbound = atoi(argtostr.c_str()); - if (nlbound < 1 || nlbound > extent) { - auto msg = fmt::format("Illegal index '{}' for '{}' parameter " - "with the extent of '{}'", nlbound, - paramname, extent); - error->all(FLERR,msg); - } + if (nlbound < 1 || nlbound > extent) + error->all(FLERR,fmt::format("Illegal index '{}' for '{}' parameter " + "with the extent of '{}'", nlbound, + paramname, extent)); nubound = nlbound; } @@ -551,11 +543,10 @@ void PairKIM::coeff(int narg, char **arg) } else error->all(FLERR,"Wrong parameter type to update"); } else { - auto msg = fmt::format("Wrong number of variable values for pair " - "coefficients.\n'{}' values are requested " - "for '{}' parameter", nubound - nlbound + 1, - paramname); - error->all(FLERR,msg); + error->all(FLERR,fmt::format("Wrong number of variable values for pair " + "coefficients.\n'{}' values are requested " + "for '{}' parameter", nubound - nlbound + 1, + paramname)); } } diff --git a/src/USER-MANIFOLD/fix_manifoldforce.cpp b/src/USER-MANIFOLD/fix_manifoldforce.cpp index d389b9787e..26d209e7a9 100644 --- a/src/USER-MANIFOLD/fix_manifoldforce.cpp +++ b/src/USER-MANIFOLD/fix_manifoldforce.cpp @@ -58,22 +58,16 @@ FixManifoldForce::FixManifoldForce(LAMMPS *lmp, int narg, char **arg) : ptr_m = create_manifold(m_name,lmp,narg,arg); // Construct manifold from factory: - if (!ptr_m) { - char msg[2048]; - snprintf(msg,2048,"Manifold pointer for manifold '%s' was NULL for some reason", arg[3]); - error->all(FLERR,msg); - } - + if (!ptr_m) + error->all(FLERR,fmt::format("Manifold pointer for manifold '{}' " + "was NULL for some reason", arg[3])); // After constructing the manifold, you can safely make // room for the parameters nvars = ptr_m->nparams(); - if (narg < nvars+4) { - char msg[2048]; - sprintf(msg,"Manifold %s needs at least %d argument(s)!", - m_name, nvars); - error->all(FLERR,msg); - } + if (narg < nvars+4) + error->all(FLERR,fmt::format("Manifold {} needs at least {} " + "argument(s)!", m_name, nvars)); ptr_m->params = new double[nvars]; if (ptr_m->params == nullptr) { diff --git a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp index 5d5bdea156..a45d62a588 100644 --- a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp @@ -95,9 +95,7 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, max_iter = utils::numeric( FLERR, arg[4] ,false,lmp); ptr_m = create_manifold(arg[5], lmp, narg, arg); - if (!ptr_m) { - error->all(FLERR,"Error creating manifold pointer"); - } + if (!ptr_m) error->all(FLERR,"Error creating manifold pointer"); nvars = ptr_m->nparams(); tstrs = new char*[nvars]; @@ -105,17 +103,13 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, tstyle = new int[nvars]; is_var = new int[nvars]; - if (!tstrs || !tvars || !tstyle || !is_var) { + if (!tstrs || !tvars || !tstyle || !is_var) error->all(FLERR, "Error creating manifold arg arrays"); - } // Check if you have enough args: - if (6 + nvars > narg) { - char msg[2048]; - sprintf(msg, "Not enough args for manifold %s, %d expected but got %d\n", - ptr_m->id(), nvars, narg - 6); - error->all(FLERR, msg); - } + if (6 + nvars > narg) + error->all(FLERR,fmt::format("Not enough args for manifold {}, {} expected " + "but got {}\n",ptr_m->id(),nvars, narg - 6)); // Loop over manifold args: for (int i = 0; i < nvars; ++i) { int len = 0, offset = 0; @@ -154,9 +148,7 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, } argi += 2; } else if (error_on_unknown_keyword) { - char msg[2048]; - sprintf(msg,"Error parsing arg \"%s\".\n", arg[argi]); - error->all(FLERR, msg); + error->all(FLERR,fmt::format("Error parsing arg \"{}\".\n",arg[argi])); } else { argi += 1; } diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index 30e6192275..a81037cad6 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -1183,10 +1183,8 @@ void DihedralTable::spline_table(Table *tb) } } // for (int i=0; ininput; i++) - if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) { - std::string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); - error->all(FLERR, msg); - } + if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) + error->all(FLERR,"Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); } // check for consistency if (! tb->f_unspecified) From 4b076e01bec603acb1b7eac8343a669eecaf38ea Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 21:36:33 -0400 Subject: [PATCH 07/21] silence compiler warning --- src/fix_property_atom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 56add7a0d1..6ce5b6360b 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -227,7 +227,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, try { ValueTokenizer values(buf); - if (values.count() != nvalue+1) + if ((int)values.count() != nvalue+1) error->all(FLERR,fmt::format("Incorrect format in {} section " "of data file: {}",keyword,buf)); From b7296b6d0b456bb1f7520934b2c45a36cfbd3fb0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 13:49:37 -0400 Subject: [PATCH 08/21] consolidate documentation for dihedral styles table and table/cut into one file --- doc/src/Commands_bond.rst | 2 +- doc/src/dihedral_style.rst | 2 +- doc/src/dihedral_table.rst | 89 ++++++++++--- doc/src/dihedral_table_cut.rst | 229 --------------------------------- 4 files changed, 72 insertions(+), 250 deletions(-) delete mode 100644 doc/src/dihedral_table_cut.rst diff --git a/doc/src/Commands_bond.rst b/doc/src/Commands_bond.rst index a826228219..70a021849d 100644 --- a/doc/src/Commands_bond.rst +++ b/doc/src/Commands_bond.rst @@ -126,7 +126,7 @@ OPT. * :doc:`quadratic (o) ` * :doc:`spherical ` * :doc:`table (o) ` - * :doc:`table/cut ` + * :doc:`table/cut ` .. _improper: diff --git a/doc/src/dihedral_style.rst b/doc/src/dihedral_style.rst index bf3cf4902a..4301824b40 100644 --- a/doc/src/dihedral_style.rst +++ b/doc/src/dihedral_style.rst @@ -113,7 +113,7 @@ more of (g,i,k,o,t) to indicate which accelerated styles exist. * :doc:`quadratic ` - dihedral with quadratic term in angle * :doc:`spherical ` - dihedral which includes angle terms to avoid singularities * :doc:`table ` - tabulated dihedral -* :doc:`table/cut ` - tabulated dihedral with analytic cutoff +* :doc:`table/cut ` - tabulated dihedral with analytic cutoff ---------- diff --git a/doc/src/dihedral_table.rst b/doc/src/dihedral_table.rst index ff3e61baee..f1b14065fd 100644 --- a/doc/src/dihedral_table.rst +++ b/doc/src/dihedral_table.rst @@ -1,19 +1,24 @@ .. index:: dihedral_style table .. index:: dihedral_style table/omp +.. index:: dihedral_style table/cut dihedral_style table command ============================ Accelerator Variants: *table/omp* +dihedral_style table/cut command +================================ + Syntax """""" .. code-block:: LAMMPS - dihedral_style table style Ntable + dihedral_style style interp Ntable -* style = *linear* or *spline* = method of interpolation +* style = *table* or *table/cut* +* interp = *linear* or *spline* = method of interpolation * Ntable = size of the internal lookup table Examples @@ -26,13 +31,21 @@ Examples dihedral_coeff 1 file.table DIH_TABLE1 dihedral_coeff 2 file.table DIH_TABLE2 + dihedral_style table/cut spline 400 + dihedral_style table/cut linear 1000 + dihedral_coeff 1 aat 1.0 177 180 file.table DIH_TABLE1 + dihedral_coeff 2 aat 0.5 170 180 file.table DIH_TABLE2 + Description """"""""""" -The *table* dihedral style creates interpolation tables of length -*Ntable* from dihedral potential and derivative values listed in a -file(s) as a function of the dihedral angle "phi". The files are read -by the :doc:`dihedral_coeff ` command. +The *table* and *table/cut* dihedral styles create interpolation tables +of length *Ntable* from dihedral potential and derivative values listed +in a file(s) as a function of the dihedral angle "phi". The files are +read by the :doc:`dihedral_coeff ` command. For +dihedral style *table/cut* additionally an analytic cutoff that is +quadratic in the bond-angle (theta) is applied in order to regularize +the dihedral interaction. The interpolation tables are created by fitting cubic splines to the file values and interpolating energy and derivative values at each of @@ -51,16 +64,53 @@ interpolated table. For a given dihedral angle (phi), the appropriate coefficients are chosen from this list, and a cubic polynomial is used to compute the energy and the derivative at this angle. -The following coefficients must be defined for each dihedral type via -the :doc:`dihedral_coeff ` command as in the example -above. +For dihedral style *table* the following coefficients must be defined +for each dihedral type via the :doc:`dihedral_coeff ` +command as in the example above. * filename * keyword -The filename specifies a file containing tabulated energy and -derivative values. The keyword specifies a section of the file. The -format of this file is described below. +The filename specifies a file containing tabulated energy and derivative +values. The keyword specifies which section of the file to read. The +format of this file is the same for both dihedral styles and described +below. + +For dihedral style *table/cut* the following coefficients must be +defined for each dihedral type via the :doc:`dihedral_coeff +` command as in the example above. + +* style (aat) +* cutoff prefactor +* cutoff angle1 +* cutoff angle2 +* filename +* keyword + +The cutoff dihedral style uses a tabulated dihedral interaction with a +cutoff function: + +.. math:: + + f(\theta) & = K \qquad\qquad\qquad\qquad\qquad\qquad \theta < \theta_1 \\ + f(\theta) & = K \left(1-\frac{(\theta - \theta_1)^2}{(\theta_2 - \theta_1)^2}\right) \qquad \theta_1 < \theta < \theta_2 + +The cutoff specifies an prefactor to the cutoff function. While this +value would ordinarily equal 1 there may be situations where the value +should change. + +The cutoff :math:`\theta_1` specifies the angle (in degrees) below which +the dihedral interaction is unmodified, i.e. the cutoff function is 1. + +The cutoff function is applied between :math:`\theta_1` and +:math:`\theta_2`, which is the angle at which the cutoff function drops +to zero. The value of zero effectively "turns off" the dihedral +interaction. + +The filename specifies a file containing tabulated energy and derivative +values. The keyword specifies which section of the file to read. The +format of this file is the same for both dihedral styles and described +below. ---------- @@ -182,18 +232,19 @@ that matches the specified keyword. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -This dihedral style writes the settings for the "dihedral_style table" -command to :doc:`binary restart files `, so a dihedral_style -command does not need to specified in an input script that reads a -restart file. However, the coefficient information is not stored in -the restart file, since it is tabulated in the potential files. Thus, +These dihedral styles write the settings for the "dihedral_style table" +or "dihedral_style table/cut" command to :doc:`binary restart files +`, so a dihedral_style command does not need to specified in an +input script that reads a restart file. However, the coefficient +information loaded from the table file(s) is not stored in the restart +file, since it is tabulated in the potential files. Thus, suitable dihedral_coeff commands do need to be specified in the restart input -script. +script after reading the restart file. Restrictions """""""""""" -This dihedral style can only be used if LAMMPS was built with the +These dihedral styles can only be used if LAMMPS was built with the USER-MISC package. See the :doc:`Build package ` doc page for more info. diff --git a/doc/src/dihedral_table_cut.rst b/doc/src/dihedral_table_cut.rst deleted file mode 100644 index a29844da19..0000000000 --- a/doc/src/dihedral_table_cut.rst +++ /dev/null @@ -1,229 +0,0 @@ -.. index:: dihedral_style table/cut - -dihedral_style table/cut command -================================ - -Syntax -"""""" - -.. code-block:: LAMMPS - - dihedral_style table/cut style Ntable - -* style = *linear* or *spline* = method of interpolation -* Ntable = size of the internal lookup table - -Examples -"""""""" - -.. code-block:: LAMMPS - - dihedral_style table/cut spline 400 - dihedral_style table/cut linear 1000 - dihedral_coeff 1 aat 1.0 177 180 file.table DIH_TABLE1 - dihedral_coeff 2 aat 0.5 170 180 file.table DIH_TABLE2 - -Description -""""""""""" - -The *table/cut* dihedral style creates interpolation tables of length -*Ntable* from dihedral potential and derivative values listed in a -file(s) as a function of the dihedral angle "phi". In addition, an -analytic cutoff that is quadratic in the bond-angle (theta) is applied -in order to regularize the dihedral interaction. The dihedral table -files are read by the :doc:`dihedral_coeff ` command. - -The interpolation tables are created by fitting cubic splines to the -file values and interpolating energy and derivative values at each of -*Ntable* dihedral angles. During a simulation, these tables are used -to interpolate energy and force values on individual atoms as -needed. The interpolation is done in one of 2 styles: *linear* or -*spline*\ . - -For the *linear* style, the dihedral angle (phi) is used to find 2 -surrounding table values from which an energy or its derivative is -computed by linear interpolation. - -For the *spline* style, cubic spline coefficients are computed and -stored at each of the *Ntable* evenly-spaced values in the -interpolated table. For a given dihedral angle (phi), the appropriate -coefficients are chosen from this list, and a cubic polynomial is used -to compute the energy and the derivative at this angle. - -The following coefficients must be defined for each dihedral type via -the :doc:`dihedral_coeff ` command as in the example -above. - -* style (aat) -* cutoff prefactor -* cutoff angle1 -* cutoff angle2 -* filename -* keyword - -The cutoff dihedral style uses a tabulated dihedral interaction with a -cutoff function: - -.. math:: - - f(\theta) & = K \qquad\qquad\qquad\qquad\qquad\qquad \theta < \theta_1 \\ - f(\theta) & = K \left(1-\frac{(\theta - \theta_1)^2}{(\theta_2 - \theta_1)^2}\right) \qquad \theta_1 < \theta < \theta_2 - -The cutoff specifies an prefactor to the cutoff function. While this value -would ordinarily equal 1 there may be situations where the value should change. - -The cutoff :math:`\theta_1` specifies the angle (in degrees) below which the dihedral -interaction is unmodified, i.e. the cutoff function is 1. - -The cutoff function is applied between :math:`\theta_1` and :math:`\theta_2`, which is -the angle at which the cutoff function drops to zero. The value of zero effectively -"turns off" the dihedral interaction. - -The filename specifies a file containing tabulated energy and -derivative values. The keyword specifies a section of the file. The -format of this file is described below. - ----------- - -The format of a tabulated file is as follows (without the -parenthesized comments). It can begin with one or more comment -or blank lines. - -.. parsed-literal:: - - # Table of the potential and its negative derivative - - DIH_TABLE1 (keyword is the first text on line) - N 30 DEGREES (N, NOF, DEGREES, RADIANS, CHECKU/F) - (blank line) - 1 -168.0 -1.40351172223 0.0423346818422 - 2 -156.0 -1.70447981034 0.00811786522531 - 3 -144.0 -1.62956100432 -0.0184129719987 - ... - 30 180.0 -0.707106781187 0.0719306095245 - - # Example 2: table of the potential. Forces omitted - - DIH_TABLE2 - N 30 NOF CHECKU testU.dat CHECKF testF.dat - - 1 -168.0 -1.40351172223 - 2 -156.0 -1.70447981034 - 3 -144.0 -1.62956100432 - ... - 30 180.0 -0.707106781187 - -A section begins with a non-blank line whose first character is not a -"#"; blank lines or lines starting with "#" can be used as comments -between sections. The first line begins with a keyword which -identifies the section. The line can contain additional text, but the -initial text must match the argument specified in the -:doc:`dihedral_coeff ` command. The next line lists (in -any order) one or more parameters for the table. Each parameter is a -keyword followed by one or more numeric values. - -Following a blank line, the next N lines list the tabulated values. On -each line, the first value is the index from 1 to N, the second value is -the angle value, the third value is the energy (in energy units), and -the fourth is -dE/d(phi) also in energy units). The third term is the -energy of the 4-atom configuration for the specified angle. The fourth -term (when present) is the negative derivative of the energy with -respect to the angle (in degrees, or radians depending on whether the -user selected DEGREES or RADIANS). Thus the units of the last term -are still energy, not force. The dihedral angle values must increase -from one line to the next. - -Dihedral table splines are cyclic. There is no discontinuity at 180 -degrees (or at any other angle). Although in the examples above, the -angles range from -180 to 180 degrees, in general, the first angle in -the list can have any value (positive, zero, or negative). However -the *range* of angles represented in the table must be *strictly* less -than 360 degrees (2pi radians) to avoid angle overlap. (You may not -supply entries in the table for both 180 and -180, for example.) If -the user's table covers only a narrow range of dihedral angles, -strange numerical behavior can occur in the large remaining gap. - -**Parameters:** - -The parameter "N" is required and its value is the number of table -entries that follow. Note that this may be different than the N -specified in the :doc:`dihedral_style table ` command. -Let *Ntable* is the number of table entries requested dihedral_style -command, and let *Nfile* be the parameter following "N" in the -tabulated file ("30" in the sparse example above). What LAMMPS does -is a preliminary interpolation by creating splines using the *Nfile* -tabulated values as nodal points. It uses these to interpolate as -needed to generate energy and derivative values at *Ntable* different -points (which are evenly spaced over a 360 degree range, even if the -angles in the file are not). The resulting tables of length *Ntable* -are then used as described above, when computing energy and force for -individual dihedral angles and their atoms. This means that if you -want the interpolation tables of length *Ntable* to match exactly what -is in the tabulated file (with effectively nopreliminary -interpolation), you should set *Ntable* = *Nfile*\ . To insure the -nodal points in the user's file are aligned with the interpolated -table entries, the angles in the table should be integer multiples of -360/\ *Ntable* degrees, or 2\*PI/\ *Ntable* radians (depending on your -choice of angle units). - -The optional "NOF" keyword allows the user to omit the forces -(negative energy derivatives) from the table file (normally located in -the fourth column). In their place, forces will be calculated -automatically by differentiating the potential energy function -indicated by the third column of the table (using either linear or -spline interpolation). - -The optional "DEGREES" keyword allows the user to specify angles in -degrees instead of radians (default). - -The optional "RADIANS" keyword allows the user to specify angles in -radians instead of degrees. (Note: This changes the way the forces -are scaled in the fourth column of the data file.) - -The optional "CHECKU" keyword is followed by a filename. This allows -the user to save all of the *Ntable* different entries in the -interpolated energy table to a file to make sure that the interpolated -function agrees with the user's expectations. (Note: You can -temporarily increase the *Ntable* parameter to a high value for this -purpose. "\ *Ntable*\ " is explained above.) - -The optional "CHECKF" keyword is analogous to the "CHECKU" keyword. -It is followed by a filename, and it allows the user to check the -interpolated force table. This option is available even if the user -selected the "NOF" option. - -Note that one file can contain many sections, each with a tabulated -potential. LAMMPS reads the file section by section until it finds one -that matches the specified keyword. - -Restart, fix_modify, output, run start/stop, minimize info -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -This dihedral style writes the settings for the "dihedral_style table/cut" -command to :doc:`binary restart files `, so a dihedral_style -command does not need to specified in an input script that reads a -restart file. However, the coefficient information is not stored in -the restart file, since it is tabulated in the potential files. Thus, -dihedral_coeff commands do need to be specified in the restart input -script. - -Restrictions -"""""""""""" - -This dihedral style can only be used if LAMMPS was built with the -USER-MISC package. See the :doc:`Build package ` doc -page for more info. - -Related commands -"""""""""""""""" - -:doc:`dihedral_coeff `, :doc:`dihedral_style table ` - -Default -""""""" - -none - -.. _dihedralcut-Salerno: - -**(Salerno)** Salerno, Bernstein, J Chem Theory Comput, --, ---- (2018). From 27e31c4b151ae6c950d66fe630e45111fa4f4f90 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 14:49:49 -0400 Subject: [PATCH 09/21] simplify --- src/ASPHERE/compute_temp_asphere.cpp | 4 +--- src/BODY/compute_temp_body.cpp | 4 +--- src/GPU/fix_npt_gpu.cpp | 32 ++++++---------------------- src/GPU/fix_nvt_gpu.cpp | 19 ++++------------- src/USER-OMP/fix_npt_omp.cpp | 27 ++++------------------- src/USER-OMP/fix_nvt_omp.cpp | 14 ++---------- 6 files changed, 18 insertions(+), 82 deletions(-) diff --git a/src/ASPHERE/compute_temp_asphere.cpp b/src/ASPHERE/compute_temp_asphere.cpp index 2fe2e9699c..9afae4d2d9 100644 --- a/src/ASPHERE/compute_temp_asphere.cpp +++ b/src/ASPHERE/compute_temp_asphere.cpp @@ -58,9 +58,7 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/asphere command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/BODY/compute_temp_body.cpp b/src/BODY/compute_temp_body.cpp index 730a857aec..fb16723b23 100644 --- a/src/BODY/compute_temp_body.cpp +++ b/src/BODY/compute_temp_body.cpp @@ -56,9 +56,7 @@ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/body command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 2ba0be29e0..073d5dc6c1 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -25,44 +25,24 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix npt/omp"); + error->all(FLERR,"Temperature control must be used with fix npt/gpu"); if (!pstat_flag) - error->all(FLERR,"Pressure control must be used with fix npt/omp"); + error->all(FLERR,"Pressure control must be used with fix npt/gpu"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(id_temp+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/GPU/fix_nvt_gpu.cpp b/src/GPU/fix_nvt_gpu.cpp index 7d7826b6bf..6858c26497 100644 --- a/src/GPU/fix_nvt_gpu.cpp +++ b/src/GPU/fix_nvt_gpu.cpp @@ -26,25 +26,14 @@ FixNVTGPU::FixNVTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix nvt"); + error->all(FLERR,"Temperature control must be used with fix nvt/gpu"); if (pstat_flag) - error->all(FLERR,"Pressure control can not be used with fix nvt"); + error->all(FLERR,"Pressure control can not be used with fix nvt/gpu"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } - diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index f3f08c15c2..54328803f4 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -34,35 +34,16 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_omp.cpp b/src/USER-OMP/fix_nvt_omp.cpp index bfa2dcbe49..127876b4e8 100644 --- a/src/USER-OMP/fix_nvt_omp.cpp +++ b/src/USER-OMP/fix_nvt_omp.cpp @@ -33,17 +33,7 @@ FixNVTOMP::FixNVTOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } From 2b34d88b71ce3b3757b1cfbf991e422b8d92e0bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 17:19:03 -0400 Subject: [PATCH 10/21] fix bug --- src/GPU/fix_npt_gpu.cpp | 2 +- src/USER-OMP/fix_npt_omp.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 073d5dc6c1..3847f31a65 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -35,7 +35,7 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(id_temp+" all temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index 54328803f4..4037dd928e 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -34,7 +34,6 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; From 2baafda5171a8bf3291162ba4ef225b395695728 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 17:19:11 -0400 Subject: [PATCH 11/21] simplify --- src/USER-OMP/fix_nph_omp.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/USER-OMP/fix_nph_omp.cpp b/src/USER-OMP/fix_nph_omp.cpp index ba7f6e6c26..8c2f9ed3a3 100644 --- a/src/USER-OMP/fix_nph_omp.cpp +++ b/src/USER-OMP/fix_nph_omp.cpp @@ -34,35 +34,15 @@ FixNPHOMP::FixNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } From 53f32cea7e2b42c3ea3bf915ef3dfc3db4be6796 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 19:42:41 -0400 Subject: [PATCH 12/21] simplify using utils::strdup() --- src/GRANULAR/fix_pour.cpp | 8 ++----- src/GRANULAR/fix_wall_gran.cpp | 4 +--- src/KOKKOS/atom_kokkos.cpp | 8 ++----- src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 9 +++----- src/KOKKOS/fix_nph_kokkos.cpp | 33 ++++++--------------------- src/KOKKOS/fix_npt_kokkos.cpp | 33 ++++++--------------------- src/KOKKOS/fix_nvt_kokkos.cpp | 18 ++++----------- 7 files changed, 26 insertions(+), 87 deletions(-) diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 3b93722426..08dae55d17 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -948,18 +948,14 @@ void FixPour::options(int narg, char **arg) } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + 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"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 73d2a2f8ba..d18b72aa65 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -338,9 +338,7 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"region") == 0) { if (narg < iarg+2) error->all(FLERR,"Illegal fix wall/gran command"); wallstyle = REGION; - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index c41a42c99a..19cfe02c96 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -257,9 +257,7 @@ int AtomKokkos::add_custom(const char *name, int flag) nivector++; iname = (char **) memory->srealloc(iname,nivector*sizeof(char *), "atom:iname"); - int n = strlen(name) + 1; - iname[index] = new char[n]; - strcpy(iname[index],name); + iname[index] = utils::strdup(name); ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *), "atom:ivector"); memory->create(ivector[index],nmax,"atom:ivector"); @@ -268,9 +266,7 @@ int AtomKokkos::add_custom(const char *name, int flag) ndvector++; dname = (char **) memory->srealloc(dname,ndvector*sizeof(char *), "atom:dname"); - int n = strlen(name) + 1; - dname[index] = new char[n]; - strcpy(dname[index],name); + dname[index] = utils::strdup(name); this->sync(Device,DVECTOR_MASK); memoryKK->grow_kokkos(k_dvector,dvector,ndvector,nmax, "atom:dvector"); diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index f1390f754b..907d1d555f 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -72,8 +72,7 @@ void AtomVecHybridKokkos::process_args(int narg, char **arg) if (strcmp(arg[iarg],keywords[i]) == 0) error->all(FLERR,"Atom style hybrid cannot use same atom style twice"); styles[nstyles] = atom->new_avec(arg[iarg],1,dummy); - keywords[nstyles] = new char[strlen(arg[iarg])+1]; - strcpy(keywords[nstyles],arg[iarg]); + keywords[nstyles] = utils::strdup(arg[iarg]); jarg = iarg + 1; while (jarg < narg && !known_style(arg[jarg])) jarg++; styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]); @@ -1175,10 +1174,8 @@ void AtomVecHybridKokkos::build_styles() int n; nallstyles = 0; #define ATOM_CLASS -#define AtomStyle(key,Class) \ - n = strlen(#key) + 1; \ - allstyles[nallstyles] = new char[n]; \ - strcpy(allstyles[nallstyles],#key); \ +#define AtomStyle(key,Class) \ + allstyles[nallstyles] = utils::strdup(#key); \ nallstyles++; #include "style_atom.h" // IWYU pragma: keep #undef AtomStyle diff --git a/src/KOKKOS/fix_nph_kokkos.cpp b/src/KOKKOS/fix_nph_kokkos.cpp index 71639083d9..f679940eaf 100644 --- a/src/KOKKOS/fix_nph_kokkos.cpp +++ b/src/KOKKOS/fix_nph_kokkos.cpp @@ -29,45 +29,26 @@ FixNPHKokkos::FixNPHKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (this->tstat_flag) - this->error->all(FLERR,"Temperature control can not be used with fix nph"); + this->error->all(FLERR,"Temperature control can not be used with fix nph/kk"); if (!this->pstat_flag) - this->error->all(FLERR,"Pressure control must be used with fix nph"); + this->error->all(FLERR,"Pressure control must be used with fix nph/kk"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(this->id) + 7; - this->id_press = new char[n]; - strcpy(this->id_press,this->id); - strcat(this->id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = this->id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = this->id_temp; - this->modify->add_compute(4,newarg); - delete [] newarg; + this->id_press = utils::strdup(std::string(this->id)+"_press"); + this->modify->add_compute(std::string(this->id_press) + +" all pressure "+this->id_temp); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_npt_kokkos.cpp b/src/KOKKOS/fix_npt_kokkos.cpp index 55c1d9d33f..baa47e026f 100644 --- a/src/KOKKOS/fix_npt_kokkos.cpp +++ b/src/KOKKOS/fix_npt_kokkos.cpp @@ -29,45 +29,26 @@ FixNPTKokkos::FixNPTKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (!this->tstat_flag) - this->error->all(FLERR,"Temperature control must be used with fix npt"); + this->error->all(FLERR,"Temperature control must be used with fix npt/kk"); if (!this->pstat_flag) - this->error->all(FLERR,"Pressure control must be used with fix npt"); + this->error->all(FLERR,"Pressure control must be used with fix npt/kk"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(this->id) + 7; - this->id_press = new char[n]; - strcpy(this->id_press,this->id); - strcat(this->id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = this->id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = this->id_temp; - this->modify->add_compute(4,newarg); - delete [] newarg; + this->id_press = utils::strdup(std::string(this->id)+"_press"); + this->modify->add_compute(std::string(this->id_press) + +" all pressure "+this->id_temp); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index 25984726b7..f589600dde 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -30,25 +30,15 @@ FixNVTKokkos::FixNVTKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (!this->tstat_flag) - this->error->all(FLERR,"Temperature control must be used with fix nvt"); + this->error->all(FLERR,"Temperature control must be used with fix nvt/kk"); if (this->pstat_flag) - this->error->all(FLERR,"Pressure control can not be used with fix nvt"); + this->error->all(FLERR,"Pressure control can not be used with fix nvt/kk"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = this->group->names[this->igroup]; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; } From 756d935d0651768d042dc7c2dcdd91e0d1e68e5b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 21:13:24 -0400 Subject: [PATCH 13/21] use std:: namespace for STL containers --- src/USER-AWPMD/pair_awpmd_cut.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/USER-AWPMD/pair_awpmd_cut.cpp b/src/USER-AWPMD/pair_awpmd_cut.cpp index 3d4e1f12a7..54f851171b 100644 --- a/src/USER-AWPMD/pair_awpmd_cut.cpp +++ b/src/USER-AWPMD/pair_awpmd_cut.cpp @@ -150,7 +150,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) # if 1 // mapping of the LAMMPS numbers to the AWPMC numbers - vector gmap(ntot,-1); + std::vector gmap(ntot,-1); for (int ii = 0; ii < inum; ii++) { int i = ilist[ii]; @@ -226,7 +226,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) // prepare the solver object wpmd->reset(); - map > etmap; + std::map > etmap; // add particles to the AWPMD solver object for (int i = 0; i < ntot; i++) { //int i = ilist[ii]; @@ -246,8 +246,8 @@ void PairAWPMDCut::compute(int eflag, int vflag) fi= new Vector_3[wpmd->ni]; // adding electrons - for (map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { - vector &el=it->second; + for (std::map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { + std::vector &el=it->second; if (!el.size()) // should not happen continue; int s=spin[el[0]] >0 ? 0 : 1; From e85f945d8e22ab813c472c6b3857fc5a4576440f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 26 Mar 2021 23:12:29 -0400 Subject: [PATCH 14/21] fix typos --- cmake/CMakeLists.txt | 2 +- doc/src/pair_polymorphic.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 06600d02c4..6d98385d02 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -31,7 +31,7 @@ endif() # If enabled, no need to use LD_LIBRARY_PATH / DYLD_LIBRARY_PATH when installed option(LAMMPS_INSTALL_RPATH "Set runtime path for shared libraries linked to LAMMPS binaries" OFF) -if (LAMMPS_INSTALL_RPATH) +if(LAMMPS_INSTALL_RPATH) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) endif() diff --git a/doc/src/pair_polymorphic.rst b/doc/src/pair_polymorphic.rst index 6abe037581..3df70a017c 100644 --- a/doc/src/pair_polymorphic.rst +++ b/doc/src/pair_polymorphic.rst @@ -319,7 +319,7 @@ This pair style is part of the MANYBODY package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. -This pair potential requires the :doc:`newtion ` setting to be +This pair potential requires the :doc:`newton ` setting to be "on" for pair interactions. The potential files provided with LAMMPS (see the potentials directory) From 35abca1b40de24c634bce37c2173f56028d07ae9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Mar 2021 11:18:59 -0400 Subject: [PATCH 15/21] we should include when using strcasecmp() --- src/USER-DIFFRACTION/compute_saed.cpp | 1 + src/USER-DIFFRACTION/compute_xrd.cpp | 1 + src/USER-MOLFILE/molfile_interface.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/USER-DIFFRACTION/compute_saed.cpp b/src/USER-DIFFRACTION/compute_saed.cpp index e825006dba..b1fa296315 100644 --- a/src/USER-DIFFRACTION/compute_saed.cpp +++ b/src/USER-DIFFRACTION/compute_saed.cpp @@ -30,6 +30,7 @@ #include #include +#include // for strcasecmp() #include "omp_compat.h" using namespace LAMMPS_NS; diff --git a/src/USER-DIFFRACTION/compute_xrd.cpp b/src/USER-DIFFRACTION/compute_xrd.cpp index a077df0183..720e5809b1 100644 --- a/src/USER-DIFFRACTION/compute_xrd.cpp +++ b/src/USER-DIFFRACTION/compute_xrd.cpp @@ -31,6 +31,7 @@ #include #include +#include // for strcasecmp() #include "omp_compat.h" using namespace LAMMPS_NS; diff --git a/src/USER-MOLFILE/molfile_interface.cpp b/src/USER-MOLFILE/molfile_interface.cpp index 1ced86da86..dc40859127 100644 --- a/src/USER-MOLFILE/molfile_interface.cpp +++ b/src/USER-MOLFILE/molfile_interface.cpp @@ -23,6 +23,7 @@ #include #include #include +#include // for strcasecmp() #if defined(_WIN32) #include From dfb18caf5a38b9e32ae6262ce6645f9a37135566 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Mar 2021 15:52:14 -0400 Subject: [PATCH 16/21] simplify using utils::strdup(), update order of include files --- src/KOKKOS/pair_exp6_rx_kokkos.cpp | 10 +---- src/KOKKOS/pair_table_rx_kokkos.cpp | 18 +++------ src/LATTE/fix_latte.cpp | 5 +-- src/MC/fix_atom_swap.cpp | 45 +++++++++++---------- src/MC/fix_bond_swap.cpp | 34 ++++++++-------- src/MC/fix_gcmc.cpp | 53 +++++++++++-------------- src/MC/fix_widom.cpp | 4 +- src/MISC/compute_ti.cpp | 26 +++++------- src/MISC/fix_deposit.cpp | 12 ++---- src/MISC/fix_evaporate.cpp | 4 +- src/MISC/fix_oneway.cpp | 4 +- src/MISC/fix_orient_bcc.cpp | 16 ++------ src/MISC/fix_orient_fcc.cpp | 16 ++------ src/MLIAP/mliap_descriptor_snap.cpp | 9 ++--- src/MLIAP/mliap_model_nn.cpp | 2 +- src/REPLICA/compute_event_displace.cpp | 4 +- src/REPLICA/prd.cpp | 22 +++-------- src/REPLICA/tad.cpp | 19 +++------ src/RIGID/compute_erotate_rigid.cpp | 16 ++++---- src/RIGID/compute_ke_rigid.cpp | 16 ++++---- src/RIGID/compute_rigid_local.cpp | 4 +- src/RIGID/fix_ehex.cpp | 22 +++++------ src/RIGID/fix_rigid_nh.cpp | 8 +--- src/RIGID/fix_rigid_nh_small.cpp | 8 +--- src/RIGID/fix_rigid_nph.cpp | 27 ++----------- src/RIGID/fix_rigid_nph_small.cpp | 27 ++----------- src/RIGID/fix_rigid_npt.cpp | 27 ++----------- src/RIGID/fix_rigid_npt_small.cpp | 27 ++----------- src/SHOCK/fix_msst.cpp | 25 ++++++------ src/SHOCK/fix_nphug.cpp | 55 +++++++------------------- src/SPIN/fix_neb_spin.cpp | 28 +++++-------- 31 files changed, 191 insertions(+), 402 deletions(-) diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 5c1a3b3589..c0cfd11466 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -1800,14 +1800,8 @@ void PairExp6rxKokkos::read_file(char *file) } params[nparams].ispecies = ispecies; - - n = strlen(&atom->dname[ispecies][0]) + 1; - params[nparams].name = new char[n]; - strcpy(params[nparams].name,&atom->dname[ispecies][0]); - - n = strlen(words[1]) + 1; - params[nparams].potential = new char[n]; - strcpy(params[nparams].potential,words[1]); + params[nparams].name = utils::strdup(&atom->dname[ispecies][0]); + params[nparams].potential = utils::strdup(words[1]); if (strcmp(params[nparams].potential,"exp6") == 0) { params[nparams].alpha = atof(words[2]); params[nparams].epsilon = atof(words[3]); diff --git a/src/KOKKOS/pair_table_rx_kokkos.cpp b/src/KOKKOS/pair_table_rx_kokkos.cpp index c3e23b6e5e..41b0343443 100644 --- a/src/KOKKOS/pair_table_rx_kokkos.cpp +++ b/src/KOKKOS/pair_table_rx_kokkos.cpp @@ -1040,25 +1040,19 @@ void PairTableRXKokkos::coeff(int narg, char **arg) nspecies = atom->nspecies_dpd; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); + site1 = utils::strdup(arg[4]); int ispecies; - for (ispecies = 0; ispecies < nspecies; ispecies++) { + for (ispecies = 0; ispecies < nspecies; ispecies++) if (strcmp(site1,&atom->dname[ispecies][0]) == 0) break; - } + if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); - - for (ispecies = 0; ispecies < nspecies; ispecies++) { + site2 = utils::strdup(arg[5]); + for (ispecies = 0; ispecies < nspecies; ispecies++) if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; - } + if (ispecies == nspecies && strcmp(site2,"1fluid") != 0) error->all(FLERR,"Site2 name not recognized in pair coefficients"); diff --git a/src/LATTE/fix_latte.cpp b/src/LATTE/fix_latte.cpp index ababe2f185..81d7cb3201 100644 --- a/src/LATTE/fix_latte.cpp +++ b/src/LATTE/fix_latte.cpp @@ -84,10 +84,7 @@ FixLatte::FixLatte(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Fix latte does not yet support a LAMMPS calculation " "of a Coulomb potential"); - int n = strlen(arg[3]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[3]); - + id_pe = utils::strdup(arg[3]); int ipe = modify->find_compute(id_pe); if (ipe < 0) error->all(FLERR,"Could not find fix latte compute ID"); if (modify->compute[ipe]->peatomflag == 0) diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index 92671fb637..954ce46aa6 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -18,30 +18,31 @@ #include "fix_atom_swap.h" +#include "angle.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" +#include "compute.h" +#include "dihedral.h" +#include "domain.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "group.h" +#include "improper.h" +#include "kspace.h" +#include "memory.h" +#include "modify.h" +#include "neighbor.h" +#include "pair.h" +#include "random_park.h" +#include "region.h" +#include "update.h" + #include #include #include #include -#include "atom.h" -#include "update.h" -#include "modify.h" -#include "fix.h" -#include "comm.h" -#include "compute.h" -#include "group.h" -#include "domain.h" -#include "region.h" -#include "random_park.h" -#include "force.h" -#include "pair.h" -#include "bond.h" -#include "angle.h" -#include "dihedral.h" -#include "improper.h" -#include "kspace.h" -#include "memory.h" -#include "error.h" -#include "neighbor.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -138,9 +139,7 @@ void FixAtomSwap::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix atom/swap does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"ke") == 0) { diff --git a/src/MC/fix_bond_swap.cpp b/src/MC/fix_bond_swap.cpp index 119c95d842..84d89a9626 100644 --- a/src/MC/fix_bond_swap.cpp +++ b/src/MC/fix_bond_swap.cpp @@ -13,27 +13,27 @@ #include "fix_bond_swap.h" -#include -#include -#include "atom.h" -#include "force.h" -#include "pair.h" -#include "bond.h" #include "angle.h" -#include "neighbor.h" +#include "atom.h" +#include "bond.h" +#include "citeme.h" +#include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "memory.h" +#include "modify.h" #include "neigh_list.h" #include "neigh_request.h" -#include "comm.h" -#include "domain.h" -#include "modify.h" -#include "compute.h" +#include "neighbor.h" +#include "pair.h" #include "random_mars.h" -#include "citeme.h" -#include "memory.h" -#include "error.h" - #include "update.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -642,9 +642,7 @@ int FixBondSwap::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index b8eecf95ca..b946615b04 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -17,32 +17,33 @@ #include "fix_gcmc.h" -#include -#include +#include "angle.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "update.h" -#include "modify.h" -#include "fix.h" +#include "bond.h" #include "comm.h" #include "compute.h" -#include "group.h" -#include "domain.h" -#include "region.h" -#include "random_park.h" -#include "force.h" -#include "pair.h" -#include "bond.h" -#include "angle.h" #include "dihedral.h" +#include "domain.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "group.h" #include "improper.h" #include "kspace.h" -#include "math_extra.h" #include "math_const.h" +#include "math_extra.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "molecule.h" #include "neighbor.h" +#include "pair.h" +#include "random_park.h" +#include "region.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -301,9 +302,7 @@ void FixGCMC::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix gcmc does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"maxangle") == 0) { @@ -327,18 +326,14 @@ void FixGCMC::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + 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 gcmc command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"full_energy") == 0) { @@ -353,9 +348,7 @@ void FixGCMC::options(int narg, char **arg) ngroupsmax*sizeof(char *), "fix_gcmc:groupstrings"); } - int n = strlen(arg[iarg+1]) + 1; - groupstrings[ngroups] = new char[n]; - strcpy(groupstrings[ngroups],arg[iarg+1]); + groupstrings[ngroups] = utils::strdup(arg[iarg+1]); ngroups++; iarg += 2; } else if (strcmp(arg[iarg],"grouptype") == 0) { @@ -370,9 +363,7 @@ void FixGCMC::options(int narg, char **arg) "fix_gcmc:grouptypestrings"); } grouptypes[ngrouptypes] = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - int n = strlen(arg[iarg+2]) + 1; - grouptypestrings[ngrouptypes] = new char[n]; - strcpy(grouptypestrings[ngrouptypes],arg[iarg+2]); + grouptypestrings[ngrouptypes] = utils::strdup(arg[iarg+2]); ngrouptypes++; iarg += 3; } else if (strcmp(arg[iarg],"intra_energy") == 0) { diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index a1bdc32515..e898196e14 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -224,9 +224,7 @@ void FixWidom::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix widom does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"charge") == 0) { diff --git a/src/MISC/compute_ti.cpp b/src/MISC/compute_ti.cpp index e81dd81c86..5ba85679a3 100644 --- a/src/MISC/compute_ti.cpp +++ b/src/MISC/compute_ti.cpp @@ -17,17 +17,17 @@ #include "compute_ti.h" -#include #include "atom.h" -#include "update.h" #include "domain.h" -#include "force.h" -#include "pair.h" -#include "kspace.h" -#include "input.h" -#include "variable.h" #include "error.h" +#include "force.h" +#include "input.h" +#include "kspace.h" +#include "pair.h" +#include "update.h" +#include "variable.h" +#include using namespace LAMMPS_NS; @@ -77,21 +77,15 @@ ComputeTI::ComputeTI(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg],"tail") == 0) which[nterms] = TAIL; else which[nterms] = PAIR; - int n = strlen(arg[iarg]) + 1; - pstyle[nterms] = new char[n]; - strcpy(pstyle[nterms],arg[iarg]); + pstyle[nterms] = utils::strdup(arg[iarg]); utils::bounds(FLERR,arg[iarg+1],1,atom->ntypes,ilo[nterms],ihi[nterms],error); iarg += 1; if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) { - int n = strlen(&arg[iarg+1][2]) + 1; - var1[nterms] = new char[n]; - strcpy(var1[nterms],&arg[iarg+1][2]); + var1[nterms] = utils::strdup(&arg[iarg+1][2]); } else error->all(FLERR,"Illegal compute ti command"); if (strstr(arg[iarg+2],"v_") == arg[iarg+2]) { - int n = strlen(&arg[iarg+2][2]) + 1; - var2[nterms] = new char[n]; - strcpy(var2[nterms],&arg[iarg+2][2]); + var2[nterms] = utils::strdup(&arg[iarg+2][2]); } else error->all(FLERR,"Illegal compute ti command"); nterms++; diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index e832b37e67..6af537f6f4 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -697,9 +697,7 @@ void FixDeposit::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix deposit does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"mol") == 0) { @@ -728,18 +726,14 @@ void FixDeposit::options(int narg, char **arg) iarg += nmol+1; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + 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 deposit command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; diff --git a/src/MISC/fix_evaporate.cpp b/src/MISC/fix_evaporate.cpp index d0e016b554..2a11d1675a 100644 --- a/src/MISC/fix_evaporate.cpp +++ b/src/MISC/fix_evaporate.cpp @@ -44,9 +44,7 @@ FixEvaporate::FixEvaporate(LAMMPS *lmp, int narg, char **arg) : nevery = utils::inumeric(FLERR,arg[3],false,lmp); nflux = utils::inumeric(FLERR,arg[4],false,lmp); iregion = domain->find_region(arg[5]); - int n = strlen(arg[5]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[5]); + idregion = utils::strdup(arg[5]); int seed = utils::inumeric(FLERR,arg[6],false,lmp); if (nevery <= 0 || nflux <= 0) diff --git a/src/MISC/fix_oneway.cpp b/src/MISC/fix_oneway.cpp index a2e612730c..7e655e60c6 100644 --- a/src/MISC/fix_oneway.cpp +++ b/src/MISC/fix_oneway.cpp @@ -42,9 +42,7 @@ FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery < 1) error->all(FLERR,"Illegal fix oneway command"); - int len = strlen(arg[4]); - regionstr = new char[len+1]; - strcpy(regionstr,arg[4]); + regionstr = utils::strdup(arg[4]); if (strcmp(arg[5], "x") == 0) direction = X|PLUS; if (strcmp(arg[5], "X") == 0) direction = X|PLUS; diff --git a/src/MISC/fix_orient_bcc.cpp b/src/MISC/fix_orient_bcc.cpp index 186e651504..4c6693f729 100644 --- a/src/MISC/fix_orient_bcc.cpp +++ b/src/MISC/fix_orient_bcc.cpp @@ -82,19 +82,11 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) : uxif_high = utils::numeric(FLERR,arg[8],false,lmp); if (direction_of_motion == 0) { - int n = strlen(arg[9]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[9]); - n = strlen(arg[10]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[10]); + chifilename = utils::strdup(arg[9]); + xifilename = utils::strdup(arg[10]); } else if (direction_of_motion == 1) { - int n = strlen(arg[9]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[9]); - n = strlen(arg[10]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[10]); + xifilename = utils::strdup(arg[9]); + chifilename = utils::strdup(arg[10]); } else error->all(FLERR,"Illegal fix orient/bcc command"); // initializations diff --git a/src/MISC/fix_orient_fcc.cpp b/src/MISC/fix_orient_fcc.cpp index 04eae4ac3e..a59e412fde 100644 --- a/src/MISC/fix_orient_fcc.cpp +++ b/src/MISC/fix_orient_fcc.cpp @@ -80,19 +80,11 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) : uxif_high = utils::numeric(FLERR,arg[8],false,lmp); if (direction_of_motion == 0) { - int n = strlen(arg[9]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[9]); - n = strlen(arg[10]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[10]); + chifilename = utils::strdup(arg[9]); + xifilename = utils::strdup(arg[10]); } else if (direction_of_motion == 1) { - int n = strlen(arg[9]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[9]); - n = strlen(arg[10]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[10]); + xifilename = utils::strdup(arg[9]); + chifilename = utils::strdup(arg[10]); } else error->all(FLERR,"Illegal fix orient/fcc command"); // initializations diff --git a/src/MLIAP/mliap_descriptor_snap.cpp b/src/MLIAP/mliap_descriptor_snap.cpp index 388561e248..0fdc548fc1 100644 --- a/src/MLIAP/mliap_descriptor_snap.cpp +++ b/src/MLIAP/mliap_descriptor_snap.cpp @@ -427,22 +427,19 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) if (strcmp(keywd,"elems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - char* elemtmp = keyval; - int n = strlen(elemtmp) + 1; - elements[ielem] = new char[n]; - strcpy(elements[ielem],elemtmp); + elements[ielem] = utils::strdup(keyval); keyval = strtok(nullptr,"' \t\n\r\f"); } elementsflag = 1; } else if (strcmp(keywd,"radelems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - radelem[ielem] = atof(keyval); + radelem[ielem] = utils::numeric(FLERR,keyval,false,lmp); keyval = strtok(nullptr,"' \t\n\r\f"); } radelemflag = 1; } else if (strcmp(keywd,"welems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - wjelem[ielem] = atof(keyval); + wjelem[ielem] = utils::numeric(FLERR,keyval,false,lmp); keyval = strtok(nullptr,"' \t\n\r\f"); } wjelemflag = 1; diff --git a/src/MLIAP/mliap_model_nn.cpp b/src/MLIAP/mliap_model_nn.cpp index 2bf75385b4..3805a5761b 100644 --- a/src/MLIAP/mliap_model_nn.cpp +++ b/src/MLIAP/mliap_model_nn.cpp @@ -18,9 +18,9 @@ #include "mliap_model_nn.h" #include "pair_mliap.h" #include "mliap_data.h" -#include "error.h" #include "comm.h" +#include "error.h" #include "memory.h" #include "tokenizer.h" diff --git a/src/REPLICA/compute_event_displace.cpp b/src/REPLICA/compute_event_displace.cpp index 958c2d3c22..0ef14b8603 100644 --- a/src/REPLICA/compute_event_displace.cpp +++ b/src/REPLICA/compute_event_displace.cpp @@ -206,7 +206,5 @@ void ComputeEventDisplace::reset_extra_compute_fix(const char *id_new) id_event = nullptr; if (id_new == nullptr) return; - int n = strlen(id_new) + 1; - id_event = new char[n]; - strcpy(id_event,id_new); + id_event = utils::strdup(id_new); } diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index de45116194..40e5fc8833 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -77,8 +77,7 @@ void PRD::command(int narg, char **arg) t_dephase = utils::inumeric(FLERR,arg[3],false,lmp); t_corr = utils::inumeric(FLERR,arg[4],false,lmp); - char *id_compute = new char[strlen(arg[5])+1]; - strcpy(id_compute,arg[5]); + char *id_compute = utils::strdup(arg[5]); int seed = utils::inumeric(FLERR,arg[6],false,lmp); options(narg-7,&arg[7]); @@ -875,15 +874,8 @@ void PRD::options(int narg, char **arg) temp_flag = 0; stepmode = 0; - char *str = (char *) "geom"; - int n = strlen(str) + 1; - loop_setting = new char[n]; - strcpy(loop_setting,str); - - str = (char *) "gaussian"; - n = strlen(str) + 1; - dist_setting = new char[n]; - strcpy(dist_setting,str); + loop_setting = utils::strdup("geom"); + dist_setting = utils::strdup("gaussian"); int iarg = 0; while (iarg < narg) { @@ -912,16 +904,12 @@ void PRD::options(int narg, char **arg) else if (strcmp(arg[iarg+1],"local") == 0) loop_setting = nullptr; else if (strcmp(arg[iarg+1],"geom") == 0) loop_setting = nullptr; else error->all(FLERR,"Illegal prd command"); - int n = strlen(arg[iarg+1]) + 1; - loop_setting = new char[n]; - strcpy(loop_setting,arg[iarg+1]); + loop_setting = utils::strdup(arg[iarg+1]); if (strcmp(arg[iarg+2],"uniform") == 0) dist_setting = nullptr; else if (strcmp(arg[iarg+2],"gaussian") == 0) dist_setting = nullptr; else error->all(FLERR,"Illegal prd command"); - n = strlen(arg[iarg+2]) + 1; - dist_setting = new char[n]; - strcpy(dist_setting,arg[iarg+2]); + dist_setting = utils::strdup(arg[iarg+2]); iarg += 3; diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 0fc611b307..0bab7a31c8 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -89,15 +89,12 @@ void TAD::command(int narg, char **arg) delta_conf = utils::numeric(FLERR,arg[4],false,lmp); tmax = utils::numeric(FLERR,arg[5],false,lmp); - char *id_compute = new char[strlen(arg[6])+1]; - strcpy(id_compute,arg[6]); + char *id_compute = utils::strdup(arg[6]); // quench minimizer is set by min_style command // NEB minimizer is set by options, default = quickmin - int n = strlen(update->minimize_style) + 1; - min_style = new char[n]; - strcpy(min_style,update->minimize_style); + min_style = utils::strdup(update->minimize_style); options(narg-7,&arg[7]); @@ -585,9 +582,7 @@ void TAD::options(int narg, char **arg) n2steps_neb = 100; nevery_neb = 10; - int n = strlen("quickmin") + 1; - min_style_neb = new char[n]; - strcpy(min_style_neb,"quickmin"); + min_style_neb = utils::strdup("quickmin"); dt_neb = update->dt; neb_logfilename = nullptr; @@ -619,9 +614,7 @@ void TAD::options(int narg, char **arg) } else if (strcmp(arg[iarg],"neb_style") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal tad command"); delete [] min_style_neb; - int n = strlen(arg[iarg+1]) + 1; - min_style_neb = new char[n]; - strcpy(min_style_neb,arg[iarg+1]); + min_style_neb = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"neb_step") == 0) { @@ -635,9 +628,7 @@ void TAD::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal tad command"); if (strcmp(arg[iarg+1],"none") == 0) neb_logfilename = nullptr; else { - int n = strlen(arg[iarg+1]) + 1; - neb_logfilename = new char[n]; - strcpy(neb_logfilename,arg[iarg+1]); + neb_logfilename = utils::strdup(arg[iarg+1]); } iarg += 2; } else error->all(FLERR,"Illegal tad command"); diff --git a/src/RIGID/compute_erotate_rigid.cpp b/src/RIGID/compute_erotate_rigid.cpp index b20e11e359..d1567cfe2e 100644 --- a/src/RIGID/compute_erotate_rigid.cpp +++ b/src/RIGID/compute_erotate_rigid.cpp @@ -12,14 +12,16 @@ ------------------------------------------------------------------------- */ #include "compute_erotate_rigid.h" -#include -#include "update.h" -#include "force.h" -#include "modify.h" + +#include "error.h" #include "fix.h" #include "fix_rigid.h" #include "fix_rigid_small.h" -#include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -33,9 +35,7 @@ ComputeERotateRigid::ComputeERotateRigid(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; extscalar = 1; - int n = strlen(arg[3]) + 1; - rfix = new char[n]; - strcpy(rfix,arg[3]); + rfix = utils::strdup(arg[3]); } /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/compute_ke_rigid.cpp b/src/RIGID/compute_ke_rigid.cpp index c005f6ac25..9da5aabb9a 100644 --- a/src/RIGID/compute_ke_rigid.cpp +++ b/src/RIGID/compute_ke_rigid.cpp @@ -12,14 +12,16 @@ ------------------------------------------------------------------------- */ #include "compute_ke_rigid.h" -#include -#include "update.h" -#include "force.h" -#include "modify.h" + +#include "error.h" #include "fix.h" #include "fix_rigid.h" #include "fix_rigid_small.h" -#include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -33,9 +35,7 @@ ComputeKERigid::ComputeKERigid(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; extscalar = 1; - int n = strlen(arg[3]) + 1; - rfix = new char[n]; - strcpy(rfix,arg[3]); + rfix = utils::strdup(arg[3]); } /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/compute_rigid_local.cpp b/src/RIGID/compute_rigid_local.cpp index 0a40062055..9de227531d 100644 --- a/src/RIGID/compute_rigid_local.cpp +++ b/src/RIGID/compute_rigid_local.cpp @@ -40,9 +40,7 @@ ComputeRigidLocal::ComputeRigidLocal(LAMMPS *lmp, int narg, char **arg) : local_flag = 1; nvalues = narg - 4; - int n = strlen(arg[3]) + 1; - idrigid = new char[n]; - strcpy(idrigid,arg[3]); + idrigid = utils::strdup(arg[3]); rstyle = new int[nvalues]; diff --git a/src/RIGID/fix_ehex.cpp b/src/RIGID/fix_ehex.cpp index 7229dc8b02..4bfabea3dd 100644 --- a/src/RIGID/fix_ehex.cpp +++ b/src/RIGID/fix_ehex.cpp @@ -24,17 +24,19 @@ #include "fix_ehex.h" -#include -#include #include "atom.h" #include "domain.h" -#include "region.h" -#include "group.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "region.h" +#include "update.h" + +#include +#include + #include "fix_shake.h" using namespace LAMMPS_NS; @@ -91,9 +93,7 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix ehex does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index a29c8d9863..6fb2bd7a94 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -1202,9 +1202,7 @@ int FixRigidNH::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1236,9 +1234,7 @@ int FixRigidNH::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index cfefe285f3..af2adb540d 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -1319,9 +1319,7 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1353,9 +1351,7 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/RIGID/fix_rigid_nph.cpp b/src/RIGID/fix_rigid_nph.cpp index a2eb079f5c..77c42f0873 100644 --- a/src/RIGID/fix_rigid_nph.cpp +++ b/src/RIGID/fix_rigid_nph.cpp @@ -55,34 +55,15 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 414e408a9a..55c0f55379 100644 --- a/src/RIGID/fix_rigid_nph_small.cpp +++ b/src/RIGID/fix_rigid_nph_small.cpp @@ -58,34 +58,15 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index e50b1a5045..59d7fa2764 100644 --- a/src/RIGID/fix_rigid_npt.cpp +++ b/src/RIGID/fix_rigid_npt.cpp @@ -65,34 +65,15 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index efb9c414f6..5b1ef61865 100644 --- a/src/RIGID/fix_rigid_npt_small.cpp +++ b/src/RIGID/fix_rigid_npt_small.cpp @@ -69,34 +69,15 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/SHOCK/fix_msst.cpp b/src/SHOCK/fix_msst.cpp index 10ec0f0351..7a1efa064f 100644 --- a/src/SHOCK/fix_msst.cpp +++ b/src/SHOCK/fix_msst.cpp @@ -19,19 +19,20 @@ #include "fix_msst.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "modify.h" -#include "fix_external.h" #include "compute.h" -#include "kspace.h" -#include "update.h" #include "domain.h" -#include "memory.h" #include "error.h" +#include "fix_external.h" +#include "force.h" +#include "kspace.h" +#include "memory.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -840,9 +841,7 @@ int FixMSST::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -864,9 +863,7 @@ int FixMSST::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(id_press); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/SHOCK/fix_nphug.cpp b/src/SHOCK/fix_nphug.cpp index 1fa7b77f6a..7467b7a293 100644 --- a/src/SHOCK/fix_nphug.cpp +++ b/src/SHOCK/fix_nphug.cpp @@ -12,15 +12,17 @@ ------------------------------------------------------------------------- */ #include "fix_nphug.h" -#include -#include -#include "modify.h" -#include "error.h" -#include "update.h" + #include "compute.h" -#include "force.h" #include "domain.h" +#include "error.h" +#include "force.h" #include "group.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -118,51 +120,22 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; // create a new compute potential energy compute - n = strlen(id) + 4; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char*)"all"; - newarg[2] = (char*)"pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id)+"_pe"); + modify->add_compute(std::string(id_pe)+" all pe"); peflag = 1; } diff --git a/src/SPIN/fix_neb_spin.cpp b/src/SPIN/fix_neb_spin.cpp index 935365ce1b..620d0a47bd 100644 --- a/src/SPIN/fix_neb_spin.cpp +++ b/src/SPIN/fix_neb_spin.cpp @@ -23,18 +23,19 @@ #include "fix_neb_spin.h" -#include -#include -#include "universe.h" -#include "update.h" #include "atom.h" #include "comm.h" -#include "modify.h" #include "compute.h" -#include "group.h" -#include "memory.h" #include "error.h" #include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "universe.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -120,17 +121,8 @@ FixNEBSpin::FixNEBSpin(LAMMPS *lmp, int narg, char **arg) : // create a new compute pe style // id = fix-ID + pe, compute group = all - int n = strlen(id) + 4; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - char **newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id)+"_pe"); + modify->add_compute(std::string(id_pe)+" all pe"); // initialize local storage From 31726f56e6b2605799144f9877b5f52ab803033f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Mar 2021 13:12:39 -0400 Subject: [PATCH 17/21] refactor group2ndx and ndx2group commands to use fmtlib, tokenizer and utils --- src/USER-COLVARS/group_ndx.cpp | 189 ++++++++++++-------------- src/USER-COLVARS/group_ndx.h | 2 + src/USER-COLVARS/ndx_group.cpp | 233 ++++++++++++++------------------- src/USER-COLVARS/ndx_group.h | 3 +- src/group.cpp | 2 +- src/group.h | 2 +- 6 files changed, 187 insertions(+), 244 deletions(-) diff --git a/src/USER-COLVARS/group_ndx.cpp b/src/USER-COLVARS/group_ndx.cpp index 96c3663ca0..995f60ac85 100644 --- a/src/USER-COLVARS/group_ndx.cpp +++ b/src/USER-COLVARS/group_ndx.cpp @@ -23,6 +23,8 @@ #include "error.h" #include "group.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- @@ -40,96 +42,6 @@ static int cmptagint(const void *p1, const void *p2) } } -/* ---------------------------------------------------------------------- - helper function. writes out one group to a gromacs style index file - ---------------------------------------------------------------------- */ - -static void write_group(FILE *fp, int gid, Atom *atom, Group *group, int me, - int np, MPI_Comm world, FILE *screen, FILE *logfile) -{ - char fmt[16]; - tagint *sendlist, *recvlist; - bigint num = group->count(gid); - int lnum, cols; - - if (me == 0) { - if (screen) fprintf(screen, " writing group %s... ", group->names[gid]); - if (logfile) fprintf(logfile, " writing group %s... ", group->names[gid]); - - // the "all" group in LAMMPS is called "System" in gromacs - if (gid == 0) { - fputs("[ System ]\n", fp); - } else { - fprintf(fp,"[ %s ]\n", group->names[gid]); - } - - // derive format string for index lists - bigint j = atom->natoms; - int i=0; - while (j > 0) { - ++i; - j /= 10; - } - snprintf(fmt,16,"%%%dd ", i); - cols = 80 / (i+1); - } - - if (num > 0) { - const int * const mask = atom->mask; - const tagint * const tag = atom->tag; - const int groupbit = group->bitmask[gid]; - const int nlocal = atom->nlocal; - int i; - - sendlist = new tagint[nlocal]; - recvlist = new tagint[num]; - lnum = 0; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) sendlist[lnum++] = tag[i]; - - int nrecv,allrecv; - if (me == 0) { - MPI_Status status; - MPI_Request request; - - for (i=0; i < lnum; i++) - recvlist[i] = sendlist[i]; - - allrecv = lnum; - for (i=1; i < np; ++i) { - MPI_Irecv(recvlist+allrecv,num-allrecv,MPI_LMP_TAGINT,i,0, world,&request); - MPI_Send(&nrecv,0,MPI_INT,i,0,world); - MPI_Wait(&request,&status); - MPI_Get_count(&status,MPI_LMP_TAGINT,&nrecv); - allrecv += nrecv; - } - - // sort received list - qsort((void *)recvlist, num, sizeof(tagint), cmptagint); - } else { - MPI_Recv(&nrecv,0,MPI_INT,0,0,world,MPI_STATUS_IGNORE); - MPI_Rsend(sendlist,lnum,MPI_LMP_TAGINT,0,0,world); - } - delete [] sendlist; - } - - if (me == 0) { - int i, j; - for (i=0, j=0; i < num; ++i) { - fprintf(fp,fmt,recvlist[i]); - ++j; - if (j == cols) { - fputs("\n",fp); - j = 0; - } - } - if (j > 0) fputs("\n",fp); - if (screen) fputs("done\n",screen); - if (logfile) fputs("done\n",logfile); - } - if (num > 0) delete[] recvlist; -} - /* ---------------------------------------------------------------------- */ void Group2Ndx::command(int narg, char **arg) @@ -144,31 +56,100 @@ void Group2Ndx::command(int narg, char **arg) if (comm->me == 0) { fp = fopen(arg[0], "w"); if (fp == nullptr) - error->one(FLERR,"Cannot open index file for writing"); - - if (screen) - fprintf(screen, "Writing groups to index file %s:\n",arg[0]); - if (logfile) - fprintf(logfile,"Writing groups to index file %s:\n",arg[0]); + error->one(FLERR,fmt::format("Cannot open index file for writing: {}", + utils::getsyserror())); + utils::logmesg(lmp,fmt::format("Writing groups to index file {}:\n",arg[0])); } if (narg == 1) { // write out all groups for (int i=0; i < group->ngroup; ++i) { - write_group(fp,i,atom,group,comm->me,comm->nprocs,world,screen,logfile); + write_group(fp,i); } - } else { // write only selected groups for (int i=1; i < narg; ++i) { int gid = group->find(arg[i]); if (gid < 0) error->all(FLERR, "Non-existing group requested"); - write_group(fp,gid,atom,group,comm->me,comm->nprocs,world,screen,logfile); + write_group(fp,gid); } } - if (comm->me == 0) { - if (screen) fputs("\n",screen); - if (logfile) fputs("\n",logfile); - fclose(fp); - } + if (comm->me == 0) fclose(fp); } +/* ---------------------------------------------------------------------- + write out one group to a Gromacs style index file + ---------------------------------------------------------------------- */ +void Group2Ndx::write_group(FILE *fp, int gid) +{ + tagint *sendlist, *recvlist; + bigint gcount = group->count(gid); + int lnum, width, cols; + + if (comm->me == 0) { + utils::logmesg(lmp,fmt::format(" writing group {}...",group->names[gid])); + + // the "all" group in LAMMPS is called "System" in Gromacs + if (gid == 0) { + fputs("[ System ]\n", fp); + } else { + fmt::print(fp,"[ {} ]\n", group->names[gid]); + } + width = log10((double) atom->natoms)+2; + cols = 80 / width; + } + + if (gcount > 0) { + const int * const mask = atom->mask; + const tagint * const tag = atom->tag; + const int groupbit = group->bitmask[gid]; + const int nlocal = atom->nlocal; + int i; + + sendlist = new tagint[nlocal]; + recvlist = new tagint[gcount]; + lnum = 0; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) sendlist[lnum++] = tag[i]; + + int nrecv=0; + bigint allrecv; + if (comm->me == 0) { + MPI_Status status; + MPI_Request request; + + for (i=0; i < lnum; i++) + recvlist[i] = sendlist[i]; + + allrecv = lnum; + for (i=1; i < comm->nprocs; ++i) { + MPI_Irecv(recvlist+allrecv,gcount-allrecv,MPI_LMP_TAGINT,i,0, world,&request); + MPI_Send(&nrecv,0,MPI_INT,i,0,world); // block rank "i" until we are ready to receive + MPI_Wait(&request,&status); + MPI_Get_count(&status,MPI_LMP_TAGINT,&nrecv); + allrecv += nrecv; + } + + // sort received list + qsort((void *)recvlist, allrecv, sizeof(tagint), cmptagint); + } else { + MPI_Recv(&nrecv,0,MPI_INT,0,0,world,MPI_STATUS_IGNORE); + MPI_Rsend(sendlist,lnum,MPI_LMP_TAGINT,0,0,world); + } + delete [] sendlist; + } + + if (comm->me == 0) { + int i, j; + for (i=0, j=0; i < gcount; ++i) { + fmt::print(fp,"{:>{}}",recvlist[i],width); + ++j; + if (j == cols) { + fputs("\n",fp); + j = 0; + } + } + if (j > 0) fputs("\n",fp); + utils::logmesg(lmp,"done\n"); + } + if (gcount > 0) delete[] recvlist; +} diff --git a/src/USER-COLVARS/group_ndx.h b/src/USER-COLVARS/group_ndx.h index 25c38dcf9f..fa15f0e82e 100644 --- a/src/USER-COLVARS/group_ndx.h +++ b/src/USER-COLVARS/group_ndx.h @@ -30,6 +30,8 @@ class Group2Ndx : protected Pointers { public: Group2Ndx(class LAMMPS *lmp) : Pointers(lmp) {}; void command(int, char **); + private: + void write_group(FILE *, int); }; } diff --git a/src/USER-COLVARS/ndx_group.cpp b/src/USER-COLVARS/ndx_group.cpp index bf1c5d060a..184faa62cc 100644 --- a/src/USER-COLVARS/ndx_group.cpp +++ b/src/USER-COLVARS/ndx_group.cpp @@ -22,64 +22,52 @@ #include "comm.h" #include "error.h" #include "group.h" +#include "memory.h" +#include "tokenizer.h" -#include +#include using namespace LAMMPS_NS; #define BUFLEN 4096 #define DELTA 16384 -static char *find_section(FILE *fp, const char *name) +// read file until next section "name" or any next section if name == "" + +static std::string find_section(FILE *fp, const std::string &name) { char linebuf[BUFLEN]; - char *n,*p,*t,*r; - while ((p = fgets(linebuf,BUFLEN,fp))) { - t = strtok(p," \t\n\r\f"); - if ((t != nullptr) && *t == '[') { - t = strtok(nullptr," \t\n\r\f"); - if (t != nullptr) { - n = t; - t = strtok(nullptr," \t\n\r\f"); - if ((t != nullptr) && *t == ']') { - if ((name == nullptr) || strcmp(name,n) == 0) { - int l = strlen(n); - r = new char[l+1]; - strncpy(r,n,l+1); - return r; - } - } - } - } + std::string pattern = "^\\s*\\[\\s+\\S+\\s+\\]\\s*$"; + if (!name.empty()) + pattern = fmt::format("^\\s*\\[\\s+{}\\s+\\]\\s*$",name); + + fgets(linebuf,BUFLEN,fp); + while (!feof(fp)) { + if (utils::strmatch(linebuf,pattern)) + return Tokenizer(linebuf).as_vector()[1]; + fgets(linebuf,BUFLEN,fp); } - return nullptr; + return ""; } -static tagint *read_section(FILE *fp, bigint &num) +static std::vector read_section(FILE *fp, std::string &name) { char linebuf[BUFLEN]; - char *p,*t; - tagint *tagbuf; - bigint nmax; + std::vector tagbuf; + std::string pattern = "^\\s*\\[\\s+\\S+\\s+\\]\\s*$"; - num = 0; - nmax = DELTA; - tagbuf = (tagint *)malloc(sizeof(tagint)*nmax); - - while ((p = fgets(linebuf,BUFLEN,fp))) { - t = strtok(p," \t\n\r\f"); - while (t != nullptr) { - // start of a new section. we are done here. - if (*t == '[') return tagbuf; - - tagbuf[num++] = ATOTAGINT(t); - if (num == nmax) { - nmax += DELTA; - tagbuf = (tagint *)realloc(tagbuf,sizeof(tagint)*nmax); - } - t = strtok(nullptr," \t\n\r\f"); + while (fgets(linebuf,BUFLEN,fp)) { + // start of new section. we are done, update "name" + if (utils::strmatch(linebuf,pattern)) { + name = Tokenizer(linebuf).as_vector()[1]; + return tagbuf; } + ValueTokenizer values(linebuf); + while (values.has_next()) + tagbuf.push_back(values.next_tagint()); } + // set empty name to indicate end of file + name = ""; return tagbuf; } @@ -90,151 +78,122 @@ void Ndx2Group::command(int narg, char **arg) int len; bigint num; FILE *fp; - char *name = nullptr; - tagint *tags; + tagint *tagbuf; + std::string name = "", next; if (narg < 1) error->all(FLERR,"Illegal ndx2group command"); - if (atom->tag_enable == 0) - error->all(FLERR,"Must have atom IDs for ndx2group command"); - + error->all(FLERR,"Must have atom IDs for ndx2group command"); if (comm->me == 0) { fp = fopen(arg[0], "r"); if (fp == nullptr) - error->one(FLERR,"Cannot open index file for reading"); - - if (screen) - fprintf(screen, "Reading groups from index file %s:\n",arg[0]); - if (logfile) - fprintf(logfile,"Reading groups from index file %s:\n",arg[0]); + error->one(FLERR,fmt::format("Cannot open index file for reading: {}", + utils::getsyserror())); + utils::logmesg(lmp,fmt::format("Reading groups from index file {}:\n",arg[0])); } - if (narg == 1) { // restore all groups + if (narg == 1) { // restore all groups - do { - if (comm->me == 0) { - len = 0; + if (comm->me == 0) { + name = find_section(fp,""); + while (!name.empty()) { - // find the next section. - // if we had processed a section, before we need to step back - if (name != nullptr) { - rewind(fp); - char *tmp = find_section(fp,name); - delete[] tmp; - delete[] name; - name = nullptr; + // skip over group "all", which is called "System" in gromacs + if (name == "System") { + name = find_section(fp,""); + continue; } - name = find_section(fp,nullptr); - if (name != nullptr) { - len=strlen(name)+1; - // skip over group "all", which is called "System" in gromacs - if (strcmp(name,"System") == 0) continue; - - if (screen) - fprintf(screen," Processing group '%s'\n",name); - if (logfile) - fprintf(logfile," Processing group '%s'\n",name); - } + utils::logmesg(lmp,fmt::format(" Processing group '{}'\n",name)); + len = name.size()+1; MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - MPI_Bcast(name,len,MPI_CHAR,0,world); + if (len > 1) { + MPI_Bcast((void *)name.c_str(),len,MPI_CHAR,0,world); // read tags for atoms in group and broadcast - num = 0; - tags = read_section(fp,num); + std::vector tags = read_section(fp,next); + num = tags.size(); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); - } - } else { - MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - delete[] name; - name = new char[len]; - MPI_Bcast(name,len,MPI_CHAR,0,world); - - MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - tags = (tagint *)malloc(sizeof(tagint)*(num ? num : 1)); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + MPI_Bcast((void *)tags.data(),num,MPI_LMP_TAGINT,0,world); + create(name,tags); + name = next; } } - } while (len); + len = -1; + MPI_Bcast(&len,1,MPI_INT,0,world); + + } else { + + while (1) { + MPI_Bcast(&len,1,MPI_INT,0,world); + if (len < 0) break; + if (len > 1) { + char *buf = new char[len]; + MPI_Bcast(buf,len,MPI_CHAR,0,world); + MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); + tagint *tbuf = new tagint[num]; + MPI_Bcast(tbuf,num,MPI_LMP_TAGINT,0,world); + create(buf,std::vector(tbuf,tbuf+num)); + delete[] buf; + delete[] tbuf; + } + } + } } else { // restore selected groups - for (int idx=1; idx < narg; ++idx) { + for (int idx=1; idx < narg; ++idx) { if (comm->me == 0) { - len = 0; // find named section, search from beginning of file - if (name != nullptr) delete[] name; rewind(fp); name = find_section(fp,arg[idx]); - if (name != nullptr) len=strlen(name)+1; - - if (screen) - fprintf(screen," %s group '%s'\n", - len ? "Processing" : "Skipping",arg[idx]); - if (logfile) - fprintf(logfile,"%s group '%s'\n", - len ? "Processing" : "Skipping",arg[idx]); - + utils::logmesg(lmp,fmt::format(" {} group '{}'\n", name.size() + ? "Processing" : "Skipping",arg[idx])); + len = name.size()+1; MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - MPI_Bcast(name,len,MPI_CHAR,0,world); + if (len > 1) { + MPI_Bcast((void *)name.c_str(),len,MPI_CHAR,0,world); + // read tags for atoms in group and broadcast - num = 0; - tags = read_section(fp,num); + std::vector tags = read_section(fp,name); + num = tags.size(); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + MPI_Bcast((void *)tags.data(),num,MPI_LMP_TAGINT,0,world); + create(name,tags); } } else { - MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - delete[] name; - name = new char[len]; - MPI_Bcast(name,len,MPI_CHAR,0,world); - + if (len > 1) { + char *buf = new char[len]; + MPI_Bcast(buf,len,MPI_CHAR,0,world); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - tags = (tagint *)malloc(sizeof(tagint)*(num ? num : 1)); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + tagint *tbuf = new tagint[num]; + MPI_Bcast(tbuf,num,MPI_LMP_TAGINT,0,world); + create(buf,std::vector(tbuf,tbuf+num)); + delete[] buf; + delete[] tbuf; } } } } - - delete[] name; - if (comm->me == 0) { - if (screen) fputs("\n",screen); - if (logfile) fputs("\n",logfile); - fclose(fp); - } + if (comm->me == 0) fclose(fp); } /* ---------------------------------------------------------------------- */ -void Ndx2Group::create(char *name, bigint num, tagint *tags) +void Ndx2Group::create(const std::string &name, const std::vector &tags) { // wipe out all members if the group exists. gid==0 is group "all" int gid = group->find(name); - if (gid > 0) group->assign(std::string(name) + " clear"); + if (gid > 0) group->assign(name + " clear"); // map from global to local const int nlocal = atom->nlocal; int *flags = (int *)calloc(nlocal,sizeof(int)); - for (bigint i=0; i < num; ++i) { + for (bigint i=0; i < tags.size(); ++i) { const int id = atom->map(tags[i]); - if (id < nlocal && id >= 0) - flags[id] = 1; + if (id < nlocal && id >= 0) flags[id] = 1; } group->create(name,flags); free(flags); diff --git a/src/USER-COLVARS/ndx_group.h b/src/USER-COLVARS/ndx_group.h index cd3250a1d5..ceca1f9570 100644 --- a/src/USER-COLVARS/ndx_group.h +++ b/src/USER-COLVARS/ndx_group.h @@ -23,6 +23,7 @@ CommandStyle(ndx2group,Ndx2Group) #define LMP_NDX_GROUP_H #include "pointers.h" +#include namespace LAMMPS_NS { @@ -30,7 +31,7 @@ class Ndx2Group : protected Pointers { public: Ndx2Group(class LAMMPS *lmp) : Pointers(lmp) {}; void command(int, char **); - void create(char *, bigint, tagint *); + void create(const std::string &, const std::vector &); }; } diff --git a/src/group.cpp b/src/group.cpp index aa05ca6951..ebab78dd0f 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -553,7 +553,7 @@ void Group::assign(const std::string &groupcmd) add flagged atoms to a new or existing group ------------------------------------------------------------------------- */ -void Group::create(const char *name, int *flag) +void Group::create(const std::string &name, int *flag) { int i; diff --git a/src/group.h b/src/group.h index 0c5a18384c..37199712c5 100644 --- a/src/group.h +++ b/src/group.h @@ -32,7 +32,7 @@ class Group : protected Pointers { ~Group(); void assign(int, char **); // assign atoms to a group void assign(const std::string &); // convenience function - void create(const char *, int *); // add flagged atoms to a group + void create(const std::string &, int *); // add flagged atoms to a group int find(const std::string &); // lookup name in list of groups int find_or_create(const char *); // lookup name or create new group void write_restart(FILE *); From b32570c15ebbc0d03da0e03263888c96b15f2ce8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Mar 2021 17:02:49 -0400 Subject: [PATCH 18/21] simplify by using utils::strdup() and reorder includes --- src/ASPHERE/fix_nph_asphere.cpp | 17 ++--- src/ASPHERE/fix_npt_asphere.cpp | 17 ++--- src/ASPHERE/fix_nve_asphere.cpp | 3 +- src/ASPHERE/fix_nvt_asphere.cpp | 13 ++-- src/BODY/fix_nph_body.cpp | 19 ++---- src/BODY/fix_npt_body.cpp | 19 ++---- src/BODY/fix_nvt_body.cpp | 13 ++-- src/GPU/fix_npt_gpu.cpp | 6 +- src/GPU/fix_nvt_gpu.cpp | 8 ++- src/KOKKOS/fix_nph_kokkos.cpp | 12 ++-- src/KOKKOS/fix_npt_kokkos.cpp | 12 ++-- src/KOKKOS/fix_nvt_kokkos.cpp | 2 +- src/MC/fix_bond_swap.cpp | 7 +- src/RIGID/fix_rigid_nph.cpp | 6 +- src/RIGID/fix_rigid_nph_small.cpp | 6 +- src/RIGID/fix_rigid_npt.cpp | 6 +- src/RIGID/fix_rigid_npt_small.cpp | 6 +- src/SHOCK/fix_nphug.cpp | 4 +- src/USER-BOCS/compute_pressure_bocs.cpp | 8 +-- src/USER-BOCS/fix_bocs.cpp | 43 +++--------- src/USER-DPD/fix_rx.cpp | 57 ++++------------ src/USER-DPD/pair_exp6_rx.cpp | 31 +++------ src/USER-DPD/pair_multi_lucy_rx.cpp | 9 +-- src/USER-DPD/pair_table_rx.cpp | 10 +-- src/USER-DRUDE/compute_temp_drude.cpp | 17 +++-- src/USER-DRUDE/fix_tgnh_drude.cpp | 32 +++++---- src/USER-DRUDE/fix_tgnpt_drude.cpp | 19 ++---- src/USER-DRUDE/fix_tgnvt_drude.cpp | 13 ++-- src/USER-EFF/compute_temp_region_eff.cpp | 17 +++-- src/USER-EFF/fix_nph_eff.cpp | 32 ++------- src/USER-EFF/fix_npt_eff.cpp | 32 ++------- src/USER-EFF/fix_nvt_eff.cpp | 21 ++---- src/USER-EFF/fix_nvt_sllod_eff.cpp | 32 ++++----- src/USER-EFF/fix_temp_rescale_eff.cpp | 29 +++----- src/USER-INTEL/fix_npt_intel.cpp | 36 +++------- src/USER-INTEL/fix_nvt_intel.cpp | 24 +++---- src/USER-INTEL/fix_nvt_sllod_intel.cpp | 15 +---- src/USER-LB/fix_lb_fluid.cpp | 24 +++---- src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp | 35 +--------- src/USER-MISC/fix_grem.cpp | 67 +++++-------------- src/USER-MISC/fix_npt_cauchy.cpp | 60 ++++++----------- src/USER-OMP/fix_nph_asphere_omp.cpp | 32 ++------- src/USER-OMP/fix_nph_omp.cpp | 12 ++-- src/USER-OMP/fix_nph_sphere_omp.cpp | 32 ++------- src/USER-OMP/fix_npt_asphere_omp.cpp | 32 ++------- src/USER-OMP/fix_npt_omp.cpp | 12 ++-- src/USER-OMP/fix_npt_sphere_omp.cpp | 32 ++------- src/USER-OMP/fix_nvt_asphere_omp.cpp | 15 +---- src/USER-OMP/fix_nvt_omp.cpp | 6 +- src/USER-OMP/fix_nvt_sllod_omp.cpp | 36 +++++----- src/USER-OMP/fix_nvt_sphere_omp.cpp | 19 ++---- src/USER-OMP/fix_rigid_nph_omp.cpp | 31 ++------- src/USER-OMP/fix_rigid_npt_omp.cpp | 33 ++------- src/USER-QTB/fix_qbmsst.cpp | 46 ++++--------- src/USER-UEF/fix_nh_uef.cpp | 54 ++++++--------- src/VORONOI/compute_voronoi_atom.cpp | 4 +- src/fix_box_relax.cpp | 31 ++++----- src/fix_nph.cpp | 19 ++---- src/fix_nph_sphere.cpp | 19 ++---- src/fix_npt.cpp | 19 ++---- src/fix_npt_sphere.cpp | 19 ++---- src/fix_nve.cpp | 12 ++-- src/fix_nvt.cpp | 12 +--- src/fix_nvt_sllod.cpp | 22 +++--- src/fix_nvt_sphere.cpp | 13 ++-- src/fix_press_berendsen.cpp | 31 ++++----- src/fix_temp_berendsen.cpp | 6 +- src/fix_temp_csld.cpp | 6 +- src/fix_temp_csvr.cpp | 6 +- src/fix_temp_rescale.cpp | 6 +- 70 files changed, 447 insertions(+), 1009 deletions(-) diff --git a/src/ASPHERE/fix_nph_asphere.cpp b/src/ASPHERE/fix_nph_asphere.cpp index 5231434a45..538e467133 100644 --- a/src/ASPHERE/fix_nph_asphere.cpp +++ b/src/ASPHERE/fix_nph_asphere.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_nph_asphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -36,21 +35,15 @@ FixNPHAsphere::FixNPHAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/asphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_npt_asphere.cpp b/src/ASPHERE/fix_npt_asphere.cpp index 6492dfcde4..99909e5a2a 100644 --- a/src/ASPHERE/fix_npt_asphere.cpp +++ b/src/ASPHERE/fix_npt_asphere.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_npt_asphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +34,15 @@ FixNPTAsphere::FixNPTAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/asphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_nve_asphere.cpp b/src/ASPHERE/fix_nve_asphere.cpp index 95fb89d5c9..62bb1db172 100644 --- a/src/ASPHERE/fix_nve_asphere.cpp +++ b/src/ASPHERE/fix_nve_asphere.cpp @@ -16,10 +16,11 @@ ------------------------------------------------------------------------- */ #include "fix_nve_asphere.h" -#include "math_extra.h" + #include "atom.h" #include "atom_vec_ellipsoid.h" #include "error.h" +#include "math_extra.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/ASPHERE/fix_nvt_asphere.cpp b/src/ASPHERE/fix_nvt_asphere.cpp index 903d88f97a..ef6d97ec99 100644 --- a/src/ASPHERE/fix_nvt_asphere.cpp +++ b/src/ASPHERE/fix_nvt_asphere.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_asphere.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,8 @@ FixNVTAsphere::FixNVTAsphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/asphere",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/asphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/BODY/fix_nph_body.cpp b/src/BODY/fix_nph_body.cpp index 1ebde47de6..a876ac9dc7 100644 --- a/src/BODY/fix_nph_body.cpp +++ b/src/BODY/fix_nph_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_nph_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -41,22 +41,15 @@ FixNPHBody::FixNPHBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/body",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_npt_body.cpp b/src/BODY/fix_npt_body.cpp index adc5cd4587..bc669fc971 100644 --- a/src/BODY/fix_npt_body.cpp +++ b/src/BODY/fix_npt_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_npt_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -41,22 +41,15 @@ FixNPTBody::FixNPTBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/body",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_nvt_body.cpp b/src/BODY/fix_nvt_body.cpp index a3884f330a..442aed2c94 100644 --- a/src/BODY/fix_nvt_body.cpp +++ b/src/BODY/fix_nvt_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -39,11 +39,8 @@ FixNVTBody::FixNVTBody(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/body", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 3847f31a65..ce601548d4 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_gpu.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,7 +35,7 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/GPU/fix_nvt_gpu.cpp b/src/GPU/fix_nvt_gpu.cpp index 6858c26497..191039e343 100644 --- a/src/GPU/fix_nvt_gpu.cpp +++ b/src/GPU/fix_nvt_gpu.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_gpu.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -33,7 +35,7 @@ FixNVTGPU::FixNVTGPU(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - id_temp = utils::strdup(std::string(id)+"_temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nph_kokkos.cpp b/src/KOKKOS/fix_nph_kokkos.cpp index f679940eaf..e2c3bd8d14 100644 --- a/src/KOKKOS/fix_nph_kokkos.cpp +++ b/src/KOKKOS/fix_nph_kokkos.cpp @@ -16,8 +16,6 @@ #include "modify.h" #include "error.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; @@ -38,17 +36,17 @@ FixNPHKokkos::FixNPHKokkos(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->id_temp = utils::strdup(std::string(this->id) + "_temp"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - this->id_press = utils::strdup(std::string(this->id)+"_press"); - this->modify->add_compute(std::string(this->id_press) - +" all pressure "+this->id_temp); + this->id_press = utils::strdup(std::string(this->id) + "_press"); + this->modify->add_compute(fmt::format("{} all pressure {}", + this->id_press, this->id_temp)); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_npt_kokkos.cpp b/src/KOKKOS/fix_npt_kokkos.cpp index baa47e026f..565703aa35 100644 --- a/src/KOKKOS/fix_npt_kokkos.cpp +++ b/src/KOKKOS/fix_npt_kokkos.cpp @@ -16,8 +16,6 @@ #include "modify.h" #include "error.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; @@ -38,17 +36,17 @@ FixNPTKokkos::FixNPTKokkos(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->id_temp = utils::strdup(std::string(this->id) + "_temp"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - this->id_press = utils::strdup(std::string(this->id)+"_press"); - this->modify->add_compute(std::string(this->id_press) - +" all pressure "+this->id_temp); + this->id_press = utils::strdup(std::string(this->id) + "_press"); + this->modify->add_compute(fmt::format("{} all pressure {}", + this->id_press, this->id_temp)); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index f589600dde..8eeffcb9f8 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -38,7 +38,7 @@ FixNVTKokkos::FixNVTKokkos(LAMMPS *lmp, int narg, char **arg) : // id = fix-ID + temp this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; } diff --git a/src/MC/fix_bond_swap.cpp b/src/MC/fix_bond_swap.cpp index 84d89a9626..1f3026888a 100644 --- a/src/MC/fix_bond_swap.cpp +++ b/src/MC/fix_bond_swap.cpp @@ -86,11 +86,8 @@ FixBondSwap::FixBondSwap(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - modify->add_compute(cmd + " all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // initialize atom list diff --git a/src/RIGID/fix_rigid_nph.cpp b/src/RIGID/fix_rigid_nph.cpp index 77c42f0873..1c93df4599 100644 --- a/src/RIGID/fix_rigid_nph.cpp +++ b/src/RIGID/fix_rigid_nph.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -56,7 +56,7 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 55c0f55379..ad5a48f1c2 100644 --- a/src/RIGID/fix_rigid_nph_small.cpp +++ b/src/RIGID/fix_rigid_nph_small.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph_small.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -59,7 +59,7 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index 59d7fa2764..4f65929476 100644 --- a/src/RIGID/fix_rigid_npt.cpp +++ b/src/RIGID/fix_rigid_npt.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -66,7 +66,7 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index 5b1ef61865..6f7c025bc8 100644 --- a/src/RIGID/fix_rigid_npt_small.cpp +++ b/src/RIGID/fix_rigid_npt_small.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt_small.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -70,7 +70,7 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/SHOCK/fix_nphug.cpp b/src/SHOCK/fix_nphug.cpp index 7467b7a293..20038c7df6 100644 --- a/src/SHOCK/fix_nphug.cpp +++ b/src/SHOCK/fix_nphug.cpp @@ -121,7 +121,7 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style @@ -135,7 +135,7 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // create a new compute potential energy compute id_pe = utils::strdup(std::string(id)+"_pe"); - modify->add_compute(std::string(id_pe)+" all pe"); + modify->add_compute(fmt::format("{} all pe",id_pe)); peflag = 1; } diff --git a/src/USER-BOCS/compute_pressure_bocs.cpp b/src/USER-BOCS/compute_pressure_bocs.cpp index a84442e658..43cf7efb8f 100644 --- a/src/USER-BOCS/compute_pressure_bocs.cpp +++ b/src/USER-BOCS/compute_pressure_bocs.cpp @@ -59,9 +59,7 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -446,7 +444,5 @@ void ComputePressureBocs::virial_compute(int n, int ndiag) void ComputePressureBocs::reset_extra_compute_fix(const char *id_new) { delete [] id_temp; - int n = strlen(id_new) + 1; - id_temp = new char[n]; - strcpy(id_temp,id_new); + id_temp = utils::strdup(id_new); } diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index 28a0d6c01a..87d4653da5 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -16,11 +16,6 @@ #include "fix_bocs.h" -#include - -#include -#include - #include "atom.h" #include "citeme.h" #include "comm.h" @@ -29,7 +24,6 @@ #include "domain.h" #include "error.h" #include "fix_deform.h" - #include "force.h" #include "group.h" #include "irregular.h" @@ -40,6 +34,10 @@ #include "respa.h" #include "update.h" +#include +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -70,7 +68,8 @@ const int NUM_INPUT_DATA_COLUMNS = 2; // columns in the pressure correction FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - rfix(nullptr), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), id_press(nullptr), + rfix(nullptr), id_dilate(nullptr), irregular(nullptr), + id_temp(nullptr), id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr) @@ -403,38 +402,16 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "PRESSURE/BOCS"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); pcomputeflag = 1; /*~ MRD End of stuff copied from fix_npt.cpp~*/ diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index c9d12506ab..675c3d6dea 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -257,7 +257,6 @@ void FixRX::post_constructor() bool match; char **tmpspecies = new char*[maxspecies]; - int tmpmaxstrlen = 0; for (int jj=0; jj < maxspecies; jj++) tmpspecies[jj] = nullptr; @@ -316,9 +315,7 @@ void FixRX::post_constructor() if (!match) { if (nUniqueSpecies+1>=maxspecies) error->all(FLERR,"Exceeded the maximum number of species permitted in fix rx."); - tmpspecies[nUniqueSpecies] = new char[strlen(word)+1]; - strcpy(tmpspecies[nUniqueSpecies],word); - tmpmaxstrlen = MAX(tmpmaxstrlen,(int)strlen(word)); + tmpspecies[nUniqueSpecies] = utils::strdup(word); nUniqueSpecies++; } word = strtok(nullptr, " \t\n\r\f"); @@ -335,61 +332,31 @@ void FixRX::post_constructor() id_fix_species = nullptr; id_fix_species_old = nullptr; - n = strlen(id) + strlen("_SPECIES") + 1; - id_fix_species = new char[n]; - n = strlen(id) + strlen("_SPECIES_OLD") + 1; - id_fix_species_old = new char[n]; + id_fix_species = utils::strdup(std::string(id)+"_SPECIES"); + id_fix_species_old = utils::strdup(std::string(id)+"_SPECIES_OLD"); - strcpy(id_fix_species,id); - strcat(id_fix_species,"_SPECIES"); - strcpy(id_fix_species_old,id); - strcat(id_fix_species_old,"_SPECIES_OLD"); - - char **newarg = new char*[nspecies+5]; - char **newarg2 = new char*[nspecies+5]; - newarg[0] = id_fix_species; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "property/atom"; - newarg2[0] = id_fix_species_old; - newarg2[1] = group->names[igroup]; - newarg2[2] = (char *) "property/atom"; - char *str1 = new char[tmpmaxstrlen+3]; - char *str2 = new char[tmpmaxstrlen+6]; + const std::string fmtstr = "{} {} property/atom "; + auto newcmd1 = fmt::format(fmtstr,id_fix_species,group->names[igroup]); + auto newcmd2 = fmt::format(fmtstr,id_fix_species_old,group->names[igroup]); for (int ii=0; iiadd_fix(nspecies+5,newarg,1); + modify->add_fix(newcmd1); fix_species = (FixPropertyAtom *) modify->fix[modify->nfix-1]; restartFlag = modify->fix[modify->nfix-1]->restart_reset; - modify->add_fix(nspecies+5,newarg2,1); + modify->add_fix(newcmd2); fix_species_old = (FixPropertyAtom *) modify->fix[modify->nfix-1]; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); for (int jj=0;jjall(FLERR,"There are no rx species specified."); read_file(arg[2]); - n = strlen(arg[3]) + 1; - site1 = new char[n]; - strcpy(site1,arg[3]); + site1 = utils::strdup(arg[3]); int ispecies; for (ispecies = 0; ispecies < nspecies; ispecies++) { @@ -607,9 +605,7 @@ void PairExp6rx::coeff(int narg, char **arg) if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[4]) + 1; - site2 = new char[n]; - strcpy(site2,arg[4]); + site2 = utils::strdup(arg[4]); for (ispecies = 0; ispecies < nspecies; ispecies++) { if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; @@ -806,17 +802,12 @@ void PairExp6rx::read_file(char *file) params[nparams].ispecies = ispecies; - n = strlen(&atom->dname[ispecies][0]) + 1; - params[nparams].name = new char[n]; - strcpy(params[nparams].name,&atom->dname[ispecies][0]); - - n = strlen(words[1]) + 1; - params[nparams].potential = new char[n]; - strcpy(params[nparams].potential,words[1]); + params[nparams].name = utils::strdup(&atom->dname[ispecies][0]); + params[nparams].potential = utils::strdup(words[1]); if (strcmp(params[nparams].potential,"exp6") == 0) { - params[nparams].alpha = atof(words[2]); - params[nparams].epsilon = atof(words[3]); - params[nparams].rm = atof(words[4]); + params[nparams].alpha = utils::numeric(FLERR,words[2],false,lmp); + params[nparams].epsilon = utils::numeric(FLERR,words[3],false,lmp); + params[nparams].rm = utils::numeric(FLERR,words[4],false,lmp); if (params[nparams].epsilon <= 0.0 || params[nparams].rm <= 0.0 || params[nparams].alpha < 0.0) error->all(FLERR,"Illegal exp6/rx parameters. Rm and Epsilon must be greater than zero. Alpha cannot be negative."); @@ -842,11 +833,9 @@ void PairExp6rx::read_file2(char *file) fp = nullptr; if (comm->me == 0) { fp = fopen(file,"r"); - if (fp == nullptr) { - char str[128]; - snprintf(str,128,"Cannot open polynomial file %s",file); - error->one(FLERR,str); - } + if (fp == nullptr) + error->one(FLERR,fmt::format("Cannot open polynomial file {}: {}", + file,utils::getsyserror())); } // one set of params can span multiple lines diff --git a/src/USER-DPD/pair_multi_lucy_rx.cpp b/src/USER-DPD/pair_multi_lucy_rx.cpp index bd720ae138..c0f6af8a7e 100644 --- a/src/USER-DPD/pair_multi_lucy_rx.cpp +++ b/src/USER-DPD/pair_multi_lucy_rx.cpp @@ -387,14 +387,9 @@ void PairMultiLucyRX::coeff(int narg, char **arg) bcast_table(tb); nspecies = atom->nspecies_dpd; - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); + site1 = utils::strdup(arg[4]); + site2 = utils::strdup(arg[5]); // set table cutoff diff --git a/src/USER-DPD/pair_table_rx.cpp b/src/USER-DPD/pair_table_rx.cpp index cefbe5a73d..85879d11fa 100644 --- a/src/USER-DPD/pair_table_rx.cpp +++ b/src/USER-DPD/pair_table_rx.cpp @@ -322,10 +322,8 @@ void PairTableRX::coeff(int narg, char **arg) nspecies = atom->nspecies_dpd; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); + + site1 = utils::strdup(arg[4]); int ispecies; for (ispecies = 0; ispecies < nspecies; ispecies++) { @@ -334,9 +332,7 @@ void PairTableRX::coeff(int narg, char **arg) if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); + site2 = utils::strdup(arg[5]); for (ispecies = 0; ispecies < nspecies; ispecies++) { if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; diff --git a/src/USER-DRUDE/compute_temp_drude.cpp b/src/USER-DRUDE/compute_temp_drude.cpp index fe75c10fe3..4325c9d6ae 100644 --- a/src/USER-DRUDE/compute_temp_drude.cpp +++ b/src/USER-DRUDE/compute_temp_drude.cpp @@ -13,15 +13,16 @@ #include "compute_temp_drude.h" -#include #include "atom.h" -#include "update.h" -#include "force.h" -#include "modify.h" -#include "fix_drude.h" +#include "comm.h" #include "domain.h" #include "error.h" -#include "comm.h" +#include "fix_drude.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -116,9 +117,7 @@ int ComputeTempDrude::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/USER-DRUDE/fix_tgnh_drude.cpp b/src/USER-DRUDE/fix_tgnh_drude.cpp index 8185b9bcbb..49a4061878 100644 --- a/src/USER-DRUDE/fix_tgnh_drude.cpp +++ b/src/USER-DRUDE/fix_tgnh_drude.cpp @@ -16,23 +16,25 @@ ---------------------------------------------------------------------------------------- */ #include "fix_tgnh_drude.h" -#include -#include + #include "atom.h" +#include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "fix_deform.h" #include "force.h" #include "group.h" -#include "comm.h" -#include "neighbor.h" #include "irregular.h" -#include "modify.h" -#include "fix_deform.h" -#include "compute.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "domain.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -1428,9 +1430,7 @@ int FixTGNHDrude::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1462,9 +1462,7 @@ int FixTGNHDrude::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-DRUDE/fix_tgnpt_drude.cpp b/src/USER-DRUDE/fix_tgnpt_drude.cpp index 987af367c3..301e0aa029 100644 --- a/src/USER-DRUDE/fix_tgnpt_drude.cpp +++ b/src/USER-DRUDE/fix_tgnpt_drude.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_tgnpt_drude.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixTGNPTDrude::FixTGNPTDrude(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp, tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press, pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-DRUDE/fix_tgnvt_drude.cpp b/src/USER-DRUDE/fix_tgnvt_drude.cpp index bd6809aaed..2339a6f9a7 100644 --- a/src/USER-DRUDE/fix_tgnvt_drude.cpp +++ b/src/USER-DRUDE/fix_tgnvt_drude.cpp @@ -12,11 +12,12 @@ ------------------------------------------------------------------------- */ #include "fix_tgnvt_drude.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -34,11 +35,7 @@ FixTGNVTDrude::FixTGNVTDrude(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp, tcmd.c_str()); - - tcmd += fmt::format(" {} temp", group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/compute_temp_region_eff.cpp b/src/USER-EFF/compute_temp_region_eff.cpp index 1ca62f39d3..ca13aac06b 100644 --- a/src/USER-EFF/compute_temp_region_eff.cpp +++ b/src/USER-EFF/compute_temp_region_eff.cpp @@ -16,17 +16,18 @@ ------------------------------------------------------------------------- */ -#include - #include "compute_temp_region_eff.h" + #include "atom.h" -#include "update.h" -#include "force.h" #include "domain.h" -#include "region.h" +#include "error.h" +#include "force.h" #include "group.h" #include "memory.h" -#include "error.h" +#include "region.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -43,9 +44,7 @@ ComputeTempRegionEff::ComputeTempRegionEff(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute temp/region/eff does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; size_vector = 6; diff --git a/src/USER-EFF/fix_nph_eff.cpp b/src/USER-EFF/fix_nph_eff.cpp index 2478211c77..1e9871da02 100644 --- a/src/USER-EFF/fix_nph_eff.cpp +++ b/src/USER-EFF/fix_nph_eff.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_eff.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHEff::FixNPHEff(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/eff",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-EFF/fix_npt_eff.cpp b/src/USER-EFF/fix_npt_eff.cpp index 98b76b1b43..4612810c02 100644 --- a/src/USER-EFF/fix_npt_eff.cpp +++ b/src/USER-EFF/fix_npt_eff.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_eff.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTEff::FixNPTEff(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/eff",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-EFF/fix_nvt_eff.cpp b/src/USER-EFF/fix_nvt_eff.cpp index 8f37cbf2b1..f5358b5db1 100644 --- a/src/USER-EFF/fix_nvt_eff.cpp +++ b/src/USER-EFF/fix_nvt_eff.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_eff.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,8 @@ FixNVTEff::FixNVTEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/eff", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/fix_nvt_sllod_eff.cpp b/src/USER-EFF/fix_nvt_sllod_eff.cpp index b5d40251bf..36a5cbb8ab 100644 --- a/src/USER-EFF/fix_nvt_sllod_eff.cpp +++ b/src/USER-EFF/fix_nvt_sllod_eff.cpp @@ -11,19 +11,20 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include -#include - #include "fix_nvt_sllod_eff.h" -#include "math_extra.h" + #include "atom.h" +#include "compute.h" #include "domain.h" -#include "group.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -45,18 +46,9 @@ FixNVTSllodEff::FixNVTSllodEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} tmp/deform/eff", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/fix_temp_rescale_eff.cpp b/src/USER-EFF/fix_temp_rescale_eff.cpp index f796c7cb02..1ebed8b9ff 100644 --- a/src/USER-EFF/fix_temp_rescale_eff.cpp +++ b/src/USER-EFF/fix_temp_rescale_eff.cpp @@ -15,18 +15,19 @@ Contributing author: Andres Jaramillo-Botero ------------------------------------------------------------------------- */ -#include - -#include #include "fix_temp_rescale_eff.h" + #include "atom.h" -#include "force.h" -#include "group.h" -#include "update.h" #include "comm.h" -#include "modify.h" #include "compute.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -56,17 +57,9 @@ FixTempRescaleEff::FixTempRescaleEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp/eff // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[6]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/eff"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/eff", + id_temp,group->names[igroup])); tflag = 1; energy = 0.0; diff --git a/src/USER-INTEL/fix_npt_intel.cpp b/src/USER-INTEL/fix_npt_intel.cpp index 4d69e80515..3f48130f99 100644 --- a/src/USER-INTEL/fix_npt_intel.cpp +++ b/src/USER-INTEL/fix_npt_intel.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_intel.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -25,44 +25,24 @@ FixNPTIntel::FixNPTIntel(LAMMPS *lmp, int narg, char **arg) : FixNHIntel(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix npt/omp"); + error->all(FLERR,"Temperature control must be used with fix npt/intel"); if (!pstat_flag) - error->all(FLERR,"Pressure control must be used with fix npt/omp"); + error->all(FLERR,"Pressure control must be used with fix npt/intl"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-INTEL/fix_nvt_intel.cpp b/src/USER-INTEL/fix_nvt_intel.cpp index b9ceea4c71..61259fba2f 100644 --- a/src/USER-INTEL/fix_nvt_intel.cpp +++ b/src/USER-INTEL/fix_nvt_intel.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_intel.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -26,25 +28,15 @@ FixNVTIntel::FixNVTIntel(LAMMPS *lmp, int narg, char **arg) : FixNHIntel(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix nvt"); + error->all(FLERR,"Temperature control must be used with fix nvt/intel"); if (pstat_flag) - error->all(FLERR,"Pressure control can not be used with fix nvt"); + error->all(FLERR,"Pressure control can not be used with fix nvt/intel"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-INTEL/fix_nvt_sllod_intel.cpp b/src/USER-INTEL/fix_nvt_sllod_intel.cpp index 3880adc055..efe124cb2d 100644 --- a/src/USER-INTEL/fix_nvt_sllod_intel.cpp +++ b/src/USER-INTEL/fix_nvt_sllod_intel.cpp @@ -46,18 +46,9 @@ FixNVTSllodIntel::FixNVTSllodIntel(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-LB/fix_lb_fluid.cpp b/src/USER-LB/fix_lb_fluid.cpp index 351e078dad..dafd5d2a3a 100644 --- a/src/USER-LB/fix_lb_fluid.cpp +++ b/src/USER-LB/fix_lb_fluid.cpp @@ -17,22 +17,22 @@ ------------------------------------------------------------------------- */ #include "fix_lb_fluid.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "random_mars.h" +#include "update.h" + #include - - #include #include #include -#include "comm.h" -#include "memory.h" -#include "error.h" -#include "domain.h" -#include "atom.h" -#include "group.h" -#include "random_mars.h" -#include "update.h" -#include "force.h" -#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp index 310dae8725..844f99b725 100644 --- a/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp @@ -131,24 +131,10 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, } // Create temperature compute: - const char *fix_id = arg[1]; - int n = strlen(fix_id)+6; - id_temp = new char[n]; - strcpy(id_temp,fix_id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char*) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); int icompute = modify->find_compute(id_temp); - if (icompute < 0) { - error->all(FLERR,"Temperature ID for fix nvt/manifold/rattle " - "does not exist"); - } temperature = modify->compute[icompute]; if (temperature->tempbias) which = BIAS; else which = NOBIAS; @@ -167,8 +153,6 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, for (int ich = 0; ich < mtchain; ++ich) { eta[ich] = eta_dot[ich] = eta_dotdot[ich] = 0.0; } - - } /* ---------------------------------------------------------------------- */ @@ -185,9 +169,6 @@ FixNVTManifoldRattle::~FixNVTManifoldRattle() if (id_temp) delete[] id_temp; } - - - int FixNVTManifoldRattle::setmask() { int mask = 0; @@ -198,7 +179,6 @@ int FixNVTManifoldRattle::setmask() return mask; } - /* -------------------------------------------------------------------------- Check that force modification happens before position and velocity update. Make sure respa is not used. @@ -219,8 +199,6 @@ void FixNVTManifoldRattle::init() } - - void FixNVTManifoldRattle::setup(int /*vflag*/) { compute_temp_target(); @@ -359,9 +337,6 @@ void FixNVTManifoldRattle::nh_v_temp() } } - - - // Most of this logic is based on fix_nh: void FixNVTManifoldRattle::initial_integrate(int /*vflag*/) { @@ -381,8 +356,6 @@ void FixNVTManifoldRattle::final_integrate() nhc_temp_integrate(); } - - /* ---------------------------------------------------------------------- */ void FixNVTManifoldRattle::reset_dt() { @@ -395,10 +368,6 @@ void FixNVTManifoldRattle::reset_dt() } - - - - double FixNVTManifoldRattle::memory_usage() { double bytes = FixNVEManifoldRattle::memory_usage(); diff --git a/src/USER-MISC/fix_grem.cpp b/src/USER-MISC/fix_grem.cpp index b1f1bded85..64c7e4a6b7 100644 --- a/src/USER-MISC/fix_grem.cpp +++ b/src/USER-MISC/fix_grem.cpp @@ -23,14 +23,16 @@ ------------------------------------------------------------------------- */ #include "fix_grem.h" -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "domain.h" #include "compute.h" +#include "domain.h" #include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -65,65 +67,28 @@ FixGrem::FixGrem(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[5]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "PRESSURE/GREM"; - newarg[3] = id_temp; - newarg[4] = id; - modify->add_compute(5,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all PRESSURE/GREM {}", + id_press, id_temp)); // create a new compute ke style // id = fix-ID + ke - n = strlen(id) + 8; - id_ke = new char[n]; - strcpy(id_ke,id); - strcat(id_ke,"_ke"); - - newarg = new char*[3]; - newarg[0] = id_ke; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "ke"; - modify->add_compute(3,newarg); - delete [] newarg; + id_ke = utils::strdup(std::string(id) + "_ke"); + modify->add_compute(fmt::format("{} all ke",id_temp)); // create a new compute pe style // id = fix-ID + pe - n = strlen(id) + 9; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id) + "_pe"); + modify->add_compute(fmt::format("{} all pe",id_temp)); int ifix = modify->find_fix(id_nh); if (ifix < 0) diff --git a/src/USER-MISC/fix_npt_cauchy.cpp b/src/USER-MISC/fix_npt_cauchy.cpp index 5d51114262..37d6e5286b 100644 --- a/src/USER-MISC/fix_npt_cauchy.cpp +++ b/src/USER-MISC/fix_npt_cauchy.cpp @@ -15,27 +15,28 @@ Contributing authors: ------------------------------------------------------------------------- */ -#include - -#include #include "fix_npt_cauchy.h" -#include "math_extra.h" + #include "atom.h" -#include "force.h" -#include "group.h" #include "comm.h" -#include "neighbor.h" -#include "irregular.h" -#include "modify.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "fix_deform.h" #include "fix_store.h" -#include "compute.h" +#include "force.h" +#include "group.h" +#include "irregular.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "domain.h" +#include "math_extra.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -53,7 +54,8 @@ enum{ISO,ANISO,TRICLINIC}; FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - rfix(nullptr), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), id_press(nullptr), + rfix(nullptr), id_dilate(nullptr), irregular(nullptr), + id_temp(nullptr), id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr), id_store(nullptr),init_store(nullptr) @@ -604,36 +606,16 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_asphere_omp.cpp b/src/USER-OMP/fix_nph_asphere_omp.cpp index 4f20d9657c..eeeb4ef2ea 100644 --- a/src/USER-OMP/fix_nph_asphere_omp.cpp +++ b/src/USER-OMP/fix_nph_asphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_asphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHAsphereOMP::FixNPHAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_omp.cpp b/src/USER-OMP/fix_nph_omp.cpp index 8c2f9ed3a3..733600b4bf 100644 --- a/src/USER-OMP/fix_nph_omp.cpp +++ b/src/USER-OMP/fix_nph_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,15 +34,15 @@ FixNPHOMP::FixNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(std::string(id_press)+" all pressure "+id_temp); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_sphere_omp.cpp b/src/USER-OMP/fix_nph_sphere_omp.cpp index 0e2a805dcf..35387b51f2 100644 --- a/src/USER-OMP/fix_nph_sphere_omp.cpp +++ b/src/USER-OMP/fix_nph_sphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_sphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHSphereOMP::FixNPHSphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_asphere_omp.cpp b/src/USER-OMP/fix_npt_asphere_omp.cpp index c05fca9043..e896db8712 100644 --- a/src/USER-OMP/fix_npt_asphere_omp.cpp +++ b/src/USER-OMP/fix_npt_asphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_asphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTAsphereOMP::FixNPTAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index 4037dd928e..386be81acc 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,15 +34,15 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(std::string(id_press)+" all pressure "+id_temp); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_sphere_omp.cpp b/src/USER-OMP/fix_npt_sphere_omp.cpp index 93b6cdda69..4e40fb63d5 100644 --- a/src/USER-OMP/fix_npt_sphere_omp.cpp +++ b/src/USER-OMP/fix_npt_sphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_sphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTSphereOMP::FixNPTSphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_asphere_omp.cpp b/src/USER-OMP/fix_nvt_asphere_omp.cpp index 353d839b4f..c8db9cc98d 100644 --- a/src/USER-OMP/fix_nvt_asphere_omp.cpp +++ b/src/USER-OMP/fix_nvt_asphere_omp.cpp @@ -33,17 +33,8 @@ FixNVTAsphereOMP::FixNVTAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/asphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_omp.cpp b/src/USER-OMP/fix_nvt_omp.cpp index 127876b4e8..240825b2c6 100644 --- a/src/USER-OMP/fix_nvt_omp.cpp +++ b/src/USER-OMP/fix_nvt_omp.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_omp.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-OMP/fix_nvt_sllod_omp.cpp b/src/USER-OMP/fix_nvt_sllod_omp.cpp index a665241efb..3193d58386 100644 --- a/src/USER-OMP/fix_nvt_sllod_omp.cpp +++ b/src/USER-OMP/fix_nvt_sllod_omp.cpp @@ -15,18 +15,21 @@ Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ -#include "omp_compat.h" #include "fix_nvt_sllod_omp.h" -#include -#include "math_extra.h" + #include "atom.h" -#include "group.h" -#include "modify.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" -#include "domain.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" + +#include + +#include "omp_compat.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -51,18 +54,9 @@ FixNVTSllodOMP::FixNVTSllodOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } @@ -82,7 +76,7 @@ void FixNVTSllodOMP::init() int i; for (i = 0; i < modify->nfix; i++) - if (strncmp(modify->fix[i]->style,"deform",6) == 0) { + if (utils::strmatch(modify->fix[i]->style,"^deform")) { if (((FixDeform *) modify->fix[i])->remapflag != Domain::V_REMAP) error->all(FLERR,"Using fix nvt/sllod/omp with inconsistent fix " "deform remap option"); diff --git a/src/USER-OMP/fix_nvt_sphere_omp.cpp b/src/USER-OMP/fix_nvt_sphere_omp.cpp index 680ddd7f17..d53d9ec32d 100644 --- a/src/USER-OMP/fix_nvt_sphere_omp.cpp +++ b/src/USER-OMP/fix_nvt_sphere_omp.cpp @@ -11,11 +11,11 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_sphere_omp.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +33,8 @@ FixNVTSphereOMP::FixNVTSphereOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/sphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-OMP/fix_rigid_nph_omp.cpp b/src/USER-OMP/fix_rigid_nph_omp.cpp index cb59ad0828..80bfbe8141 100644 --- a/src/USER-OMP/fix_rigid_nph_omp.cpp +++ b/src/USER-OMP/fix_rigid_nph_omp.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph_omp.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -57,34 +57,15 @@ FixRigidNPHOMP::FixRigidNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_rigid_npt_omp.cpp b/src/USER-OMP/fix_rigid_npt_omp.cpp index f496dd0a11..f832dda618 100644 --- a/src/USER-OMP/fix_rigid_npt_omp.cpp +++ b/src/USER-OMP/fix_rigid_npt_omp.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt_omp.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -67,36 +67,17 @@ FixRigidNPTOMP::FixRigidNPTOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) - // and thus its KE/temperature contribution should use group all + // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-QTB/fix_qbmsst.cpp b/src/USER-QTB/fix_qbmsst.cpp index b221ecbca8..0b54811db0 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -18,9 +18,6 @@ #include "fix_qbmsst.h" -#include -#include - #include "atom.h" #include "force.h" #include "update.h" @@ -34,6 +31,9 @@ #include "kspace.h" #include "math_const.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; @@ -204,45 +204,23 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = const_cast("all"); - newarg[2] = const_cast("temp"); - modify->add_compute(3,newarg); - delete [] newarg; + + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = const_cast("all"); - newarg[2] = const_cast("pressure"); - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pflag = 1; // create a new compute potential energy compute - n = strlen(id) + 3; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char*)"all"; - newarg[2] = (char*)"pe"; - modify->add_compute(3,newarg); - delete [] newarg; + + id_pe = utils::strdup(std::string(id) + "_pe"); + modify->add_compute(fmt::format("{} all pe",id_temp)); peflag = 1; // allocate qbmsst diff --git a/src/USER-UEF/fix_nh_uef.cpp b/src/USER-UEF/fix_nh_uef.cpp index b757900703..91125fd4ed 100644 --- a/src/USER-UEF/fix_nh_uef.cpp +++ b/src/USER-UEF/fix_nh_uef.cpp @@ -14,24 +14,26 @@ ------------------------------------------------------------------------- */ #include "fix_nh_uef.h" -#include -#include + #include "atom.h" -#include "force.h" -#include "comm.h" #include "citeme.h" -#include "irregular.h" -#include "modify.h" +#include "comm.h" #include "compute.h" -#include "update.h" -#include "domain.h" -#include "error.h" -#include "output.h" -#include "timer.h" -#include "neighbor.h" #include "compute_pressure_uef.h" #include "compute_temp_uef.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "irregular.h" +#include "modify.h" +#include "neighbor.h" +#include "output.h" +#include "timer.h" #include "uef_utils.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -179,29 +181,12 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) : // Create temp and pressure computes for nh/uef - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/uef"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/uef",id_temp)); tcomputeflag = 1; - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure/uef"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure/uef {}",id_press, id_temp)); pcomputeflag = 1; nevery = 1; @@ -214,8 +199,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) : FixNHUef::~FixNHUef() { delete uefbox; - if (pcomputeflag && !pstat_flag) - { + if (pcomputeflag && !pstat_flag) { modify->delete_compute(id_press); delete [] id_press; } diff --git a/src/VORONOI/compute_voronoi_atom.cpp b/src/VORONOI/compute_voronoi_atom.cpp index bcd9031b6e..d9cd746ca6 100644 --- a/src/VORONOI/compute_voronoi_atom.cpp +++ b/src/VORONOI/compute_voronoi_atom.cpp @@ -80,9 +80,7 @@ ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg], "radius") == 0) { if (iarg + 2 > narg || strstr(arg[iarg+1],"v_") != arg[iarg+1] ) error->all(FLERR,"Illegal compute voronoi/atom command"); - int n = strlen(&arg[iarg+1][2]) + 1; - radstr = new char[n]; - strcpy(radstr,&arg[iarg+1][2]); + radstr = utils::strdup(&arg[iarg+1][2]); iarg += 2; } else if (strcmp(arg[iarg], "surface") == 0) { diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index ef576e96f6..76bd8f05c2 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -16,20 +16,20 @@ ------------------------------------------------------------------------- */ #include "fix_box_relax.h" -#include -#include #include "atom.h" -#include "domain.h" -#include "update.h" #include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "force.h" #include "kspace.h" -#include "modify.h" -#include "compute.h" -#include "error.h" #include "math_extra.h" +#include "modify.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -319,24 +319,17 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style (virial only) // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp) + " virial"; - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {} virial", + id_press, id_temp)); pflag = 1; dimension = domain->dimension; diff --git a/src/fix_nph.cpp b/src/fix_nph.cpp index 6002d2e40d..5b160689dd 100644 --- a/src/fix_nph.cpp +++ b/src/fix_nph.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_nph.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixNPH::FixNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_nph_sphere.cpp b/src/fix_nph_sphere.cpp index 27197c48a7..20e072d5b5 100644 --- a/src/fix_nph_sphere.cpp +++ b/src/fix_nph_sphere.cpp @@ -12,10 +12,11 @@ ------------------------------------------------------------------------- */ #include "fix_nph_sphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +36,15 @@ FixNPHSphere::FixNPHSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/sphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_npt.cpp b/src/fix_npt.cpp index 7ee346985d..78acf0cf7e 100644 --- a/src/fix_npt.cpp +++ b/src/fix_npt.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_npt.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixNPT::FixNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_npt_sphere.cpp b/src/fix_npt_sphere.cpp index b806cf5362..a6dfeba425 100644 --- a/src/fix_npt_sphere.cpp +++ b/src/fix_npt_sphere.cpp @@ -12,10 +12,11 @@ ------------------------------------------------------------------------- */ #include "fix_npt_sphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +36,15 @@ FixNPTSphere::FixNPTSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/sphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_nve.cpp b/src/fix_nve.cpp index 23f69abc86..e14ff47e46 100644 --- a/src/fix_nve.cpp +++ b/src/fix_nve.cpp @@ -12,12 +12,12 @@ ------------------------------------------------------------------------- */ #include "fix_nve.h" -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "respa.h" #include "error.h" +#include "force.h" +#include "respa.h" +#include "update.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -27,7 +27,7 @@ using namespace FixConst; FixNVE::FixNVE(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { - if (strcmp(style,"nve/sphere") != 0 && narg < 3) + if (!utils::strmatch(style,"^nve/sphere") && narg < 3) error->all(FLERR,"Illegal fix nve command"); dynamic_group_allow = 1; @@ -53,7 +53,7 @@ void FixNVE::init() dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/fix_nvt.cpp b/src/fix_nvt.cpp index ad69e6ee81..14251a269a 100644 --- a/src/fix_nvt.cpp +++ b/src/fix_nvt.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,7 @@ FixNVT::FixNVT(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_nvt_sllod.cpp b/src/fix_nvt_sllod.cpp index 2257fa6c56..ba81adee0c 100644 --- a/src/fix_nvt_sllod.cpp +++ b/src/fix_nvt_sllod.cpp @@ -16,17 +16,18 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_sllod.h" -#include -#include "math_extra.h" + #include "atom.h" +#include "compute.h" #include "domain.h" -#include "group.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -49,12 +50,9 @@ FixNVTSllod::FixNVTSllod(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/deform",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_nvt_sphere.cpp b/src/fix_nvt_sphere.cpp index 1119d345bc..0733a27678 100644 --- a/src/fix_nvt_sphere.cpp +++ b/src/fix_nvt_sphere.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_sphere.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,8 @@ FixNVTSphere::FixNVTSphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/sphere",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/sphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index d929ca6f28..9cd9de9485 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -12,19 +12,20 @@ ------------------------------------------------------------------------- */ #include "fix_press_berendsen.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "modify.h" -#include "fix_deform.h" #include "compute.h" -#include "kspace.h" -#include "update.h" #include "domain.h" #include "error.h" +#include "fix_deform.h" +#include "force.h" +#include "kspace.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -218,24 +219,16 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pflag = 1; nrigid = 0; diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index 39b8a5fefd..38ce9de333 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -72,10 +72,8 @@ FixTempBerendsen::FixTempBerendsen(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; energy = 0; diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index 787b4dd34e..bf3d0eb7f6 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -81,10 +81,8 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; vhold = nullptr; diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index 525cf5b74a..2d04243a11 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -81,10 +81,8 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; nmax = -1; diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index b57f6c238c..73c55f2793 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -68,10 +68,8 @@ FixTempRescale::FixTempRescale(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; energy = 0.0; From e481eb115456f7332ec7e9dd19151f02e23af515 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 07:29:14 -0400 Subject: [PATCH 19/21] simplify by using utils::strdup() fmt::format() and reorder includes --- src/USER-BOCS/fix_bocs.cpp | 8 ++---- src/USER-DPD/fix_eos_table_rx.cpp | 7 +++-- src/USER-DPD/fix_rx.cpp | 26 +++++++++---------- src/USER-DPD/pair_exp6_rx.cpp | 15 +++++------ src/USER-DPD/pair_multi_lucy.cpp | 22 +++++++--------- src/USER-DPD/pair_multi_lucy_rx.cpp | 26 +++++++++---------- src/USER-EFF/fix_temp_rescale_eff.cpp | 4 +-- src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp | 7 ++--- src/USER-MGPT/pair_mgpt.cpp | 16 +++++------- src/USER-MISC/compute_gyration_shape.cpp | 13 +++++----- .../compute_gyration_shape_chunk.cpp | 21 +++++++-------- src/USER-MISC/compute_hma.cpp | 24 +++-------------- src/USER-MISC/compute_pressure_grem.cpp | 8 +++--- 13 files changed, 80 insertions(+), 117 deletions(-) diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index 87d4653da5..60fb03cdf8 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -1525,9 +1525,7 @@ int FixBocs::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1559,9 +1557,7 @@ int FixBocs::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-DPD/fix_eos_table_rx.cpp b/src/USER-DPD/fix_eos_table_rx.cpp index 28cd4eb4c3..7b0bec93f2 100644 --- a/src/USER-DPD/fix_eos_table_rx.cpp +++ b/src/USER-DPD/fix_eos_table_rx.cpp @@ -17,16 +17,15 @@ #include "fix_eos_table_rx.h" - -#include -#include #include "atom.h" +#include "comm.h" #include "error.h" #include "force.h" #include "memory.h" -#include "comm.h" #include "modify.h" +#include +#include #define MAXLINE 1024 diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index 675c3d6dea..4f0f381e6d 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -13,28 +13,26 @@ #include "fix_rx.h" - -#include -#include -#include // DBL_EPSILON #include "atom.h" -#include "error.h" -#include "group.h" -#include "modify.h" -#include "force.h" -#include "memory.h" #include "comm.h" -#include "update.h" #include "domain.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "math_special.h" +#include "memory.h" +#include "modify.h" #include "neigh_list.h" #include "neigh_request.h" -#include "math_special.h" +#include "neighbor.h" #include "pair_dpd_fdt_energy.h" +#include "update.h" - -#include // std::vector<> #include // std::max +#include // DBL_EPSILON +#include +#include +#include // std::vector<> using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-DPD/pair_exp6_rx.cpp b/src/USER-DPD/pair_exp6_rx.cpp index 036d31060b..ba8d52776f 100644 --- a/src/USER-DPD/pair_exp6_rx.cpp +++ b/src/USER-DPD/pair_exp6_rx.cpp @@ -13,20 +13,19 @@ #include "pair_exp6_rx.h" -#include - -#include -#include #include "atom.h" #include "comm.h" +#include "error.h" +#include "fix.h" #include "force.h" -#include "neigh_list.h" #include "math_special.h" #include "memory.h" -#include "error.h" - #include "modify.h" -#include "fix.h" +#include "neigh_list.h" + +#include +#include +#include using namespace LAMMPS_NS; using namespace MathSpecial; diff --git a/src/USER-DPD/pair_multi_lucy.cpp b/src/USER-DPD/pair_multi_lucy.cpp index 70ea8b40ad..85cab8a37f 100644 --- a/src/USER-DPD/pair_multi_lucy.cpp +++ b/src/USER-DPD/pair_multi_lucy.cpp @@ -21,21 +21,19 @@ The Journal of Chemical Physics, 2016, 144, 104501. ------------------------------------------------------------------------------------------- */ +#include "pair_multi_lucy.h" + +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "neigh_list.h" #include -#include "math_const.h" - #include -#include "pair_multi_lucy.h" -#include "atom.h" -#include "force.h" -#include "comm.h" -#include "neigh_list.h" -#include "memory.h" -#include "error.h" - -#include "citeme.h" - using namespace LAMMPS_NS; diff --git a/src/USER-DPD/pair_multi_lucy_rx.cpp b/src/USER-DPD/pair_multi_lucy_rx.cpp index c0f6af8a7e..5bea395725 100644 --- a/src/USER-DPD/pair_multi_lucy_rx.cpp +++ b/src/USER-DPD/pair_multi_lucy_rx.cpp @@ -21,23 +21,21 @@ The Journal of Chemical Physics, 2016, 144, 104501. ------------------------------------------------------------------------------------------- */ +#include "pair_multi_lucy_rx.h" + +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "modify.h" +#include "neigh_list.h" #include -#include "math_const.h" - #include -#include "pair_multi_lucy_rx.h" -#include "atom.h" -#include "force.h" -#include "comm.h" -#include "neigh_list.h" -#include "memory.h" -#include "error.h" - -#include "citeme.h" -#include "modify.h" -#include "fix.h" - using namespace LAMMPS_NS; diff --git a/src/USER-EFF/fix_temp_rescale_eff.cpp b/src/USER-EFF/fix_temp_rescale_eff.cpp index 1ebed8b9ff..0d3bf6ed43 100644 --- a/src/USER-EFF/fix_temp_rescale_eff.cpp +++ b/src/USER-EFF/fix_temp_rescale_eff.cpp @@ -165,9 +165,7 @@ int FixTempRescaleEff::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); diff --git a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp index a45d62a588..4b141a3bd1 100644 --- a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp @@ -31,10 +31,8 @@ ------------------------------------------------------------------------- */ - #include "fix_nve_manifold_rattle.h" -#include #include "atom.h" #include "force.h" #include "update.h" @@ -44,18 +42,17 @@ #include "citeme.h" #include "comm.h" +#include + #include "manifold_factory.h" #include "manifold.h" - using namespace LAMMPS_NS; using namespace FixConst; using namespace user_manifold; - enum { CONST, EQUAL }; // For treating the variables. - static const char* cite_fix_nve_manifold_rattle = "fix nve/manifold/rattle command:\n\n" "@article{paquay-2016,\n" diff --git a/src/USER-MGPT/pair_mgpt.cpp b/src/USER-MGPT/pair_mgpt.cpp index 75f870e1b2..7061d1f86b 100644 --- a/src/USER-MGPT/pair_mgpt.cpp +++ b/src/USER-MGPT/pair_mgpt.cpp @@ -23,20 +23,18 @@ #include "pair_mgpt.h" -#include - -#include -#include - #include "atom.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" +#include +#include +#include using namespace LAMMPS_NS; diff --git a/src/USER-MISC/compute_gyration_shape.cpp b/src/USER-MISC/compute_gyration_shape.cpp index daec7a6b4b..ac073d4cbc 100644 --- a/src/USER-MISC/compute_gyration_shape.cpp +++ b/src/USER-MISC/compute_gyration_shape.cpp @@ -15,17 +15,18 @@ * Contributing author: Evangelos Voyiatzis (Royal DSM) * ------------------------------------------------------------------------- */ - #include "compute_gyration_shape.h" -#include -#include + #include "error.h" -#include "math_extra.h" #include "math_eigen.h" +#include "math_extra.h" #include "math_special.h" #include "modify.h" #include "update.h" +#include +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -41,9 +42,7 @@ ComputeGyrationShape::ComputeGyrationShape(LAMMPS *lmp, int narg, char **arg) : extvector = 0; // ID of compute gyration - int n = strlen(arg[3]) + 1; - id_gyration = new char[n]; - strcpy(id_gyration,arg[3]); + id_gyration = utils::strdup(arg[3]); init(); diff --git a/src/USER-MISC/compute_gyration_shape_chunk.cpp b/src/USER-MISC/compute_gyration_shape_chunk.cpp index e0ab646ce2..e66173d704 100644 --- a/src/USER-MISC/compute_gyration_shape_chunk.cpp +++ b/src/USER-MISC/compute_gyration_shape_chunk.cpp @@ -15,17 +15,18 @@ * Contributing author: Evangelos Voyiatzis (Royal DSM) * ------------------------------------------------------------------------- */ - #include "compute_gyration_shape_chunk.h" + +#include "error.h" +#include "math_eigen.h" +#include "math_extra.h" +#include "math_special.h" +#include "memory.h" +#include "modify.h" +#include "update.h" + #include #include -#include "error.h" -#include "math_extra.h" -#include "math_eigen.h" -#include "math_special.h" -#include "modify.h" -#include "memory.h" -#include "update.h" using namespace LAMMPS_NS; @@ -37,9 +38,7 @@ ComputeGyrationShapeChunk::ComputeGyrationShapeChunk(LAMMPS *lmp, int narg, char if (narg != 4) error->all(FLERR,"Illegal compute gyration/shape/chunk command"); // ID of compute gyration - int n = strlen(arg[3]) + 1; - id_gyration_chunk = new char[n]; - strcpy(id_gyration_chunk,arg[3]); + id_gyration_chunk = utils::strdup(arg[3]); init(); diff --git a/src/USER-MISC/compute_hma.cpp b/src/USER-MISC/compute_hma.cpp index 8220abebc4..fbe8c67d39 100644 --- a/src/USER-MISC/compute_hma.cpp +++ b/src/USER-MISC/compute_hma.cpp @@ -78,11 +78,7 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) : if (narg < 4) error->all(FLERR,"Illegal compute hma command"); if (igroup) error->all(FLERR,"Compute hma must use group all"); if (strcmp(arg[3],"NULL") == 0) {error->all(FLERR,"fix ID specifying the set temperature of canonical simulation is required");} - else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); - } + else id_temp = utils::strdup(arg[3]); create_attribute = 1; extscalar = 1; @@ -92,23 +88,11 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) : // our new fix's id (id_fix)= compute-ID + COMPUTE_STORE // our new fix's group = same as compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); - - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + id_fix = utils::strdup(std::string(id)+"_COMPUTE_STORE"); + modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; - // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/USER-MISC/compute_pressure_grem.cpp b/src/USER-MISC/compute_pressure_grem.cpp index 6ba4462c29..98f699491f 100644 --- a/src/USER-MISC/compute_pressure_grem.cpp +++ b/src/USER-MISC/compute_pressure_grem.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ #include "compute_pressure_grem.h" -#include + #include "update.h" #include "domain.h" #include "modify.h" @@ -21,6 +21,8 @@ #include "kspace.h" #include "error.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- @@ -30,9 +32,7 @@ using namespace LAMMPS_NS; ComputePressureGrem::ComputePressureGrem(LAMMPS *lmp, int narg, char **arg) : ComputePressure(lmp, narg-1, arg) { - int len = strlen(arg[narg-1])+1; - fix_grem = new char[len]; - strcpy(fix_grem,arg[narg-1]); + fix_grem = utils::strdup(arg[narg-1]); } /* ---------------------------------------------------------------------- */ From 806f4e73edf18719a18d9255ac8dbc97b647cd6b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 07:32:43 -0400 Subject: [PATCH 20/21] make dihedral style table/cut a derived class from table and remove redundant code --- src/USER-MISC/dihedral_table.cpp | 67 +-- src/USER-MISC/dihedral_table.h | 8 +- src/USER-MISC/dihedral_table_cut.cpp | 842 ++------------------------- src/USER-MISC/dihedral_table_cut.h | 118 +--- 4 files changed, 62 insertions(+), 973 deletions(-) diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index a81037cad6..ffbc9aad31 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -464,7 +464,6 @@ DihedralTable::~DihedralTable() if (allocated) { memory->destroy(setflag); - //memory->destroy(phi0); <- equilibrium angles not supported memory->destroy(tabindex); } } @@ -718,49 +717,18 @@ void DihedralTable::compute(int eflag, int vflag) } } // void DihedralTable::compute() - - - - - - -// single() calculates the dihedral-angle energy of atoms i1, i2, i3, i4. -double DihedralTable::single(int type, int i1, int i2, int i3, int i4) -{ - double vb12[g_dim]; - double vb23[g_dim]; - double vb34[g_dim]; - double n123[g_dim]; - double n234[g_dim]; - - double **x = atom->x; - - double phi = Phi(x[i1], x[i2], x[i3], x[i4], domain, - vb12, vb23, vb34, n123, n234); - - double u=0.0; - u_lookup(type, phi, u); //Calculate the energy, and store it in "u" - - return u; -} - - /* ---------------------------------------------------------------------- */ - - void DihedralTable::allocate() { allocated = 1; int n = atom->ndihedraltypes; memory->create(tabindex,n+1,"dihedral:tabindex"); - //memory->create(phi0,n+1,"dihedral:phi0"); <-equilibrium angles not supported memory->create(setflag,n+1,"dihedral:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; } - /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ @@ -791,16 +759,13 @@ void DihedralTable::settings(int narg, char **arg) tables = nullptr; } - - /* ---------------------------------------------------------------------- set coeffs for one type ------------------------------------------------------------------------- */ - void DihedralTable::coeff(int narg, char **arg) { - if (narg != 3) error->all(FLERR,"Illegal dihedral_coeff command"); + if (narg != 3) error->all(FLERR,"Incorrect args for dihedral coefficients"); if (!allocated) allocate(); int ilo,ihi; @@ -815,25 +780,22 @@ void DihedralTable::coeff(int narg, char **arg) if (me == 0) read_table(tb,arg[1],arg[2]); bcast_table(tb); - // --- check the angle data for range errors --- // --- and resolve issues with periodicity --- - if (tb->ninput < 2) { - error->one(FLERR,fmt::format("Invalid dihedral table length ({}).", - arg[2])); - } else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { - error->one(FLERR,fmt::format("Invalid dihedral spline table length. " - "(Try linear)\n ({}).",arg[2])); - } + if (tb->ninput < 2) + error->all(FLERR,fmt::format("Invalid dihedral table length: {}",arg[2])); + else if ((tb->ninput == 2) && (tabstyle == SPLINE)) + error->all(FLERR,fmt::format("Invalid dihedral spline table length: {} " + "(Try linear)",arg[2])); // check for monotonicity for (int i=0; i < tb->ninput-1; i++) { if (tb->phifile[i] >= tb->phifile[i+1]) { auto err_msg = fmt::format("Dihedral table values are not increasing " - "({}, {}th entry)",arg[2],i+1); + "({}, entry {})",arg[2],i+1); if (i==0) - err_msg += std::string("\n(This is probably a mistake with your table format.)\n"); + err_msg += "\n(This is probably a mistake with your table format.)\n"; error->all(FLERR,err_msg); } } @@ -971,15 +933,12 @@ void DihedralTable::coeff(int narg, char **arg) } ntables++; - if (count == 0) - error->all(FLERR,"Illegal dihedral_coeff command"); - -} //DihedralTable::coeff() - + if (count == 0) error->all(FLERR,"Incorrect args for dihedral coefficients"); +} /* ---------------------------------------------------------------------- - proc 0 writes to restart file - ------------------------------------------------------------------------- */ + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ void DihedralTable::write_restart(FILE *fp) { @@ -1065,7 +1024,6 @@ void DihedralTable::read_table(Table *tb, char *file, char *keyword) error->one(FLERR,"Did not find keyword in table file"); } - // read args on 2nd line of section // allocate table arrays for file values @@ -1279,7 +1237,6 @@ void DihedralTable::compute_table(Table *tb) void DihedralTable::param_extract(Table *tb, char *line) { - //tb->theta0 = 180.0; <- equilibrium angles not supported tb->ninput = 0; tb->f_unspecified = false; //default tb->use_degrees = true; //default diff --git a/src/USER-MISC/dihedral_table.h b/src/USER-MISC/dihedral_table.h index a8d1f8f8bb..9d5b03f5cc 100644 --- a/src/USER-MISC/dihedral_table.h +++ b/src/USER-MISC/dihedral_table.h @@ -25,7 +25,6 @@ DihedralStyle(table,DihedralTable) #define LMP_DIHEDRAL_TABLE_H #include "dihedral.h" - namespace LAMMPS_NS { class DihedralTable : public Dihedral { @@ -34,7 +33,7 @@ class DihedralTable : public Dihedral { virtual ~DihedralTable(); virtual void compute(int, int); void settings(int, char **); - void coeff(int, char **); + virtual void coeff(int, char **); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -43,13 +42,11 @@ class DihedralTable : public Dihedral { protected: int tabstyle,tablength; - // double *phi0; <- equilibrium angles not supported std::string checkU_fname; std::string checkF_fname; struct Table { int ninput; - //double phi0; <-equilibrium angles not supported int f_unspecified; // boolean (but MPI does not like type "bool") int use_degrees; // boolean (but MPI does not like type "bool") double *phifile,*efile,*ffile; @@ -62,7 +59,7 @@ class DihedralTable : public Dihedral { Table *tables; int *tabindex; - void allocate(); + virtual void allocate(); void null_table(Table *); void free_table(Table *); void read_table(Table *, char *, char *); @@ -152,6 +149,5 @@ class DihedralTable : public Dihedral { } // namespace LAMMPS_NS - #endif //#ifndef LMP_DIHEDRAL_TABLE_H #endif //#ifdef DIHEDRAL_CLASS ... #else diff --git a/src/USER-MISC/dihedral_table_cut.cpp b/src/USER-MISC/dihedral_table_cut.cpp index ed7b3ac0d6..dc7a6f9685 100644 --- a/src/USER-MISC/dihedral_table_cut.cpp +++ b/src/USER-MISC/dihedral_table_cut.cpp @@ -18,28 +18,23 @@ #include "dihedral_table_cut.h" -#include +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "neighbor.h" +#include "update.h" + #include - #include - #include // IWYU pragma: keep #include // IWYU pragma: keep -#include "atom.h" -#include "neighbor.h" -#include "update.h" -#include "comm.h" -#include "force.h" -#include "citeme.h" -#include "math_const.h" -#include "memory.h" -#include "error.h" - - using namespace LAMMPS_NS; using namespace MathConst; -using namespace std; static const char cite_dihedral_tablecut[] = "dihedral_style table/cut command:\n\n" @@ -89,272 +84,6 @@ enum { //GSL status return codes. }; -static int solve_cyc_tridiag( const double diag[], size_t d_stride, - const double offdiag[], size_t o_stride, - const double b[], size_t b_stride, - double x[], size_t x_stride, - size_t N, bool warn) -{ - int status = GSL_SUCCESS; - double * delta = (double *) malloc (N * sizeof (double)); - double * gamma = (double *) malloc (N * sizeof (double)); - double * alpha = (double *) malloc (N * sizeof (double)); - double * c = (double *) malloc (N * sizeof (double)); - double * z = (double *) malloc (N * sizeof (double)); - - if (delta == 0 || gamma == 0 || alpha == 0 || c == 0 || z == 0) { - if (warn) - fprintf(stderr,"Internal Cyclic Spline Error: failed to allocate working space\n"); - - if (delta) free(delta); - if (gamma) free(gamma); - if (alpha) free(alpha); - if (c) free(c); - if (z) free(z); - return GSL_ENOMEM; - } - else - { - size_t i, j; - double sum = 0.0; - - /* factor */ - - if (N == 1) - { - x[0] = b[0] / diag[0]; - free(delta); - free(gamma); - free(alpha); - free(c); - free(z); - return GSL_SUCCESS; - } - - alpha[0] = diag[0]; - gamma[0] = offdiag[0] / alpha[0]; - delta[0] = offdiag[o_stride * (N-1)] / alpha[0]; - - if (alpha[0] == 0) { - status = GSL_EZERODIV; - } - - for (i = 1; i < N - 2; i++) - { - alpha[i] = diag[d_stride * i] - offdiag[o_stride * (i-1)] * gamma[i - 1]; - gamma[i] = offdiag[o_stride * i] / alpha[i]; - delta[i] = -delta[i - 1] * offdiag[o_stride * (i-1)] / alpha[i]; - if (alpha[i] == 0) { - status = GSL_EZERODIV; - } - } - - for (i = 0; i < N - 2; i++) - { - sum += alpha[i] * delta[i] * delta[i]; - } - - alpha[N - 2] = diag[d_stride * (N - 2)] - offdiag[o_stride * (N - 3)] * gamma[N - 3]; - - gamma[N - 2] = (offdiag[o_stride * (N - 2)] - offdiag[o_stride * (N - 3)] * delta[N - 3]) / alpha[N - 2]; - - alpha[N - 1] = diag[d_stride * (N - 1)] - sum - alpha[(N - 2)] * gamma[N - 2] * gamma[N - 2]; - - /* update */ - z[0] = b[0]; - for (i = 1; i < N - 1; i++) - { - z[i] = b[b_stride * i] - z[i - 1] * gamma[i - 1]; - } - sum = 0.0; - for (i = 0; i < N - 2; i++) - { - sum += delta[i] * z[i]; - } - z[N - 1] = b[b_stride * (N - 1)] - sum - gamma[N - 2] * z[N - 2]; - for (i = 0; i < N; i++) - { - c[i] = z[i] / alpha[i]; - } - - /* backsubstitution */ - x[x_stride * (N - 1)] = c[N - 1]; - x[x_stride * (N - 2)] = c[N - 2] - gamma[N - 2] * x[x_stride * (N - 1)]; - if (N >= 3) - { - for (i = N - 3, j = 0; j <= N - 3; j++, i--) - { - x[x_stride * i] = c[i] - gamma[i] * x[x_stride * (i + 1)] - delta[i] * x[x_stride * (N - 1)]; - } - } - } - - free (z); - free (c); - free (alpha); - free (gamma); - free (delta); - - if ((status == GSL_EZERODIV) && warn) - fprintf(stderr, "Internal Cyclic Spline Error: Matrix must be positive definite.\n"); - - return status; -} //solve_cyc_tridiag() - -/* ---------------------------------------------------------------------- - spline and splint routines modified from Numerical Recipes -------------------------------------------------------------------------- */ - -static int cyc_spline(double const *xa, - double const *ya, - int n, - double period, - double *y2a, bool warn) -{ - - double *diag = new double[n]; - double *offdiag = new double[n]; - double *rhs = new double[n]; - double xa_im1, xa_ip1; - - // In the cyclic case, there are n equations with n unknows. - // The for loop sets up the equations we need to solve. - // Later we invoke the GSL tridiagonal matrix solver to solve them. - - for (int i=0; i < n; i++) { - - // I have to lookup xa[i+1] and xa[i-1]. This gets tricky because of - // periodic boundary conditions. We handle that now. - int im1 = i-1; - if (im1<0) { - im1 += n; - xa_im1 = xa[im1] - period; - } - else - xa_im1 = xa[im1]; - - int ip1 = i+1; - if (ip1>=n) { - ip1 -= n; - xa_ip1 = xa[ip1] + period; - } - else - xa_ip1 = xa[ip1]; - - // Recall that we want to find the y2a[] parameters (there are n of them). - // To solve for them, we have a linear equation with n unknowns - // (in the cyclic case that is). For details, the non-cyclic case is - // explained in equation 3.3.7 in Numerical Recipes in C, p. 115. - diag[i] = (xa_ip1 - xa_im1) / 3.0; - offdiag[i] = (xa_ip1 - xa[i]) / 6.0; - rhs[i] = ((ya[ip1] - ya[i]) / (xa_ip1 - xa[i])) - - ((ya[i] - ya[im1]) / (xa[i] - xa_im1)); - } - - // Because this matrix is tridiagonal (and cyclic), we can use the following - // cheap method to invert it. - if (solve_cyc_tridiag(diag, 1, - offdiag, 1, - rhs, 1, - y2a, 1, - n, warn) != GSL_SUCCESS) { - if (warn) - fprintf(stderr,"Error in inverting matrix for splines.\n"); - - delete [] diag; - delete [] offdiag; - delete [] rhs; - return 1; - } - delete [] diag; - delete [] offdiag; - delete [] rhs; - return 0; -} // cyc_spline() - -/* ---------------------------------------------------------------------- */ - -// cyc_splint(): Evaluates a spline at position x, with n control -// points located at xa[], ya[], and with parameters y2a[] -// The xa[] must be monotonically increasing and their -// range should not exceed period (ie xa[n-1] < xa[0] + period). -// x must lie in the range: [(xa[n-1]-period), (xa[0]+period)] -// "period" is typically 2*PI. -static double cyc_splint(double const *xa, - double const *ya, - double const *y2a, - int n, - double period, - double x) -{ - int klo = -1; - int khi = n; - int k; - double xlo = xa[n-1] - period; - double xhi = xa[0] + period; - while (khi-klo > 1) { - k = (khi+klo) >> 1; //(k=(khi+klo)/2) - if (xa[k] > x) { - khi = k; - xhi = xa[k]; - } - else { - klo = k; - xlo = xa[k]; - } - } - - if (khi == n) khi = 0; - if (klo ==-1) klo = n-1; - - double h = xhi-xlo; - double a = (xhi-x) / h; - double b = (x-xlo) / h; - double y = a*ya[klo] + b*ya[khi] + - ((a*a*a-a)*y2a[klo] + (b*b*b-b)*y2a[khi]) * (h*h)/6.0; - - return y; - -} // cyc_splint() - - -static double cyc_lin(double const *xa, - double const *ya, - int n, - double period, - double x) -{ - int klo = -1; - int khi = n; - int k; - double xlo = xa[n-1] - period; - double xhi = xa[0] + period; - while (khi-klo > 1) { - k = (khi+klo) >> 1; //(k=(khi+klo)/2) - if (xa[k] > x) { - khi = k; - xhi = xa[k]; - } - else { - klo = k; - xlo = xa[k]; - } - } - - if (khi == n) khi = 0; - if (klo ==-1) klo = n-1; - - double h = xhi-xlo; - double a = (xhi-x) / h; - double b = (x-xlo) / h; - double y = a*ya[klo] + b*ya[khi]; - - return y; - -} // cyc_lin() - - - // cyc_splintD(): Evaluate the deriviative of a cyclic spline at position x, // with n control points at xa[], ya[], with parameters y2a[]. @@ -405,35 +134,26 @@ static double cyc_splintD(double const *xa, } // cyc_splintD() +// -------------------------------------------- +// ------- Calculate the dihedral angle ------- +// -------------------------------------------- +static const int g_dim=3; /* ---------------------------------------------------------------------- */ -DihedralTableCut::DihedralTableCut(LAMMPS *lmp) : Dihedral(lmp) +DihedralTableCut::DihedralTableCut(LAMMPS *lmp) : DihedralTable(lmp) { if (lmp->citeme) lmp->citeme->add(cite_dihedral_tablecut); - ntables = 0; - tables = nullptr; - checkU_fname = checkF_fname = nullptr; + aat_k = aat_theta0_1 = aat_theta0_2 = nullptr; } /* ---------------------------------------------------------------------- */ DihedralTableCut::~DihedralTableCut() { - if (allocated) { - memory->destroy(aat_k); - memory->destroy(aat_theta0_1); - memory->destroy(aat_theta0_2); - - for (int m = 0; m < ntables; m++) free_table(&tables[m]); - memory->sfree(tables); - memory->sfree(checkU_fname); - memory->sfree(checkF_fname); - - memory->destroy(setflag); - memory->destroy(tabindex); - - } + memory->destroy(aat_k); + memory->destroy(aat_theta0_1); + memory->destroy(aat_theta0_2); } /* ---------------------------------------------------------------------- */ @@ -702,7 +422,7 @@ void DihedralTableCut::compute(int eflag, int vflag) for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) - fabcd[i][j] -= - gt*gtt*fpphi*dphidr[i][j] + fabcd[i][j] -= gt*gtt*fpphi*dphidr[i][j] - gt*gptt*fphi*dthetadr[1][i][j] + gpt*gtt*fphi*dthetadr[0][i][j]; // apply force to each of 4 atoms @@ -751,35 +471,7 @@ void DihedralTableCut::allocate() memory->create(tabindex,n+1,"dihedral:tabindex"); memory->create(setflag,n+1,"dihedral:setflag"); - - for (int i = 1; i <= n; i++) - setflag[i] = 0; -} - -void DihedralTableCut::settings(int narg, char **arg) -{ - if (narg != 2) error->all(FLERR,"Illegal dihedral_style command"); - - if (strcmp(arg[0],"linear") == 0) tabstyle = LINEAR; - else if (strcmp(arg[0],"spline") == 0) tabstyle = SPLINE; - else error->all(FLERR,"Unknown table style in dihedral style table_cut"); - - tablength = utils::inumeric(FLERR,arg[1],false,lmp); - if (tablength < 3) - error->all(FLERR,"Illegal number of dihedral table entries"); - // delete old tables, since cannot just change settings - - for (int m = 0; m < ntables; m++) free_table(&tables[m]); - memory->sfree(tables); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(tabindex); - } - allocated = 0; - - ntables = 0; - tables = nullptr; + for (int i = 1; i <= n; i++) setflag[i] = 0; } /* ---------------------------------------------------------------------- @@ -790,9 +482,9 @@ void DihedralTableCut::settings(int narg, char **arg) void DihedralTableCut::coeff(int narg, char **arg) { - if (narg != 7) error->all(FLERR,"Incorrect args for dihedral coefficients"); if (!allocated) allocate(); + int ilo,ihi; utils::bounds(FLERR,arg[0],1,atom->ndihedraltypes,ilo,ihi,error); @@ -820,29 +512,19 @@ void DihedralTableCut::coeff(int narg, char **arg) // --- check the angle data for range errors --- // --- and resolve issues with periodicity --- - if (tb->ninput < 2) { - string err_msg; - err_msg = string("Invalid dihedral table length (") - + string(arg[5]) + string(")."); - error->one(FLERR,err_msg); - } - else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { - string err_msg; - err_msg = string("Invalid dihedral spline table length. (Try linear)\n (") - + string(arg[5]) + string(")."); - error->one(FLERR,err_msg); - } + if (tb->ninput < 2) + error->all(FLERR,fmt::format("Invalid dihedral table length: {}",arg[5])); + else if ((tb->ninput == 2) && (tabstyle == SPLINE)) + error->all(FLERR,fmt::format("Invalid dihedral spline table length: {} " + "(Try linear)",arg[5])); // check for monotonicity for (int i=0; i < tb->ninput-1; i++) { if (tb->phifile[i] >= tb->phifile[i+1]) { - stringstream i_str; - i_str << i+1; - string err_msg = - string("Dihedral table values are not increasing (") + - string(arg[5]) + string(", ")+i_str.str()+string("th entry)"); + auto err_msg =fmt::format("Dihedral table values are not increasing " + "({}, entry {})",arg[5],i+1); if (i==0) - err_msg += string("\n(This is probably a mistake with your table format.)\n"); + err_msg += "\n(This is probably a mistake with your table format.)\n"; error->all(FLERR,err_msg); } } @@ -851,20 +533,13 @@ void DihedralTableCut::coeff(int narg, char **arg) double philo = tb->phifile[0]; double phihi = tb->phifile[tb->ninput-1]; if (tb->use_degrees) { - if ((phihi - philo) >= 360) { - string err_msg; - err_msg = string("Dihedral table angle range must be < 360 degrees (") - +string(arg[5]) + string(")."); - error->all(FLERR,err_msg); - } - } - else { - if ((phihi - philo) >= MY_2PI) { - string err_msg; - err_msg = string("Dihedral table angle range must be < 2*PI radians (") - + string(arg[5]) + string(")."); - error->all(FLERR,err_msg); - } + if ((phihi - philo) >= 360) + error->all(FLERR,fmt::format("Dihedral table angle range must be < 360 " + "degrees ({})",arg[5])); + } else { + if ((phihi - philo) >= MY_2PI) + error->all(FLERR,fmt::format("Dihedral table angle range must be < 2*PI " + "radians ({})",arg[5])); } // convert phi from degrees to radians @@ -932,10 +607,9 @@ void DihedralTableCut::coeff(int narg, char **arg) // Optional: allow the user to print out the interpolated spline tables if (me == 0) { - if (checkU_fname && (strlen(checkU_fname) != 0)) - { - ofstream checkU_file; - checkU_file.open(checkU_fname, ios::out); + if (!checkU_fname.empty()) { + std::ofstream checkU_file; + checkU_file.open(checkU_fname, std::ios::out); for (int i=0; i < tablength; i++) { double phi = i*MY_2PI/tablength; double u = tb->e[i]; @@ -945,12 +619,10 @@ void DihedralTableCut::coeff(int narg, char **arg) } checkU_file.close(); } - if (checkF_fname && (strlen(checkF_fname) != 0)) - { - ofstream checkF_file; - checkF_file.open(checkF_fname, ios::out); - for (int i=0; i < tablength; i++) - { + if (!checkF_fname.empty()) { + std::ofstream checkF_file; + checkF_file.open(checkF_fname, std::ios::out); + for (int i=0; i < tablength; i++) { double phi = i*MY_2PI/tablength; double f; if ((tabstyle == SPLINE) && (tb->f_unspecified)) { @@ -992,429 +664,3 @@ void DihedralTableCut::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for dihedral coefficients"); } - -/* ---------------------------------------------------------------------- - proc 0 writes out coeffs to restart file -------------------------------------------------------------------------- */ - -void DihedralTableCut::write_restart(FILE *fp) -{ - write_restart_settings(fp); -} - -/* ---------------------------------------------------------------------- - proc 0 reads coeffs from restart file, bcasts them -------------------------------------------------------------------------- */ - -void DihedralTableCut::read_restart(FILE *fp) -{ - read_restart_settings(fp); - allocate(); -} - -/* ---------------------------------------------------------------------- - proc 0 writes out coeffs to restart file -------------------------------------------------------------------------- */ - -void DihedralTableCut::write_restart_settings(FILE *fp) -{ - fwrite(&tabstyle,sizeof(int),1,fp); - fwrite(&tablength,sizeof(int),1,fp); -} - -/* ---------------------------------------------------------------------- - proc 0 reads coeffs from restart file, bcasts them -------------------------------------------------------------------------- */ - -void DihedralTableCut::read_restart_settings(FILE *fp) -{ - if (comm->me == 0) { - utils::sfread(FLERR,&tabstyle,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&tablength,sizeof(int),1,fp,nullptr,error); - } - - MPI_Bcast(&tabstyle,1,MPI_INT,0,world); - MPI_Bcast(&tablength,1,MPI_INT,0,world); -} - -/* ---------------------------------------------------------------------- */ - -void DihedralTableCut::null_table(Table *tb) -{ - tb->phifile = tb->efile = tb->ffile = nullptr; - tb->e2file = tb->f2file = nullptr; - tb->phi = tb->e = tb->de = nullptr; - tb->f = tb->df = tb->e2 = tb->f2 = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -void DihedralTableCut::free_table(Table *tb) -{ - memory->destroy(tb->phifile); - memory->destroy(tb->efile); - memory->destroy(tb->ffile); - memory->destroy(tb->e2file); - memory->destroy(tb->f2file); - - memory->destroy(tb->phi); - memory->destroy(tb->e); - memory->destroy(tb->de); - memory->destroy(tb->f); - memory->destroy(tb->df); - memory->destroy(tb->e2); - memory->destroy(tb->f2); -} - -/* ---------------------------------------------------------------------- - read table file, only called by proc 0 -------------------------------------------------------------------------- */ - -static const int MAXLINE=2048; - -void DihedralTableCut::read_table(Table *tb, char *file, char *keyword) -{ - char line[MAXLINE]; - - // open file - - FILE *fp = utils::open_potential(file,lmp,nullptr); - if (fp == nullptr) { - string err_msg = string("Cannot open file ") + string(file); - error->one(FLERR,err_msg); - } - - // loop until section found with matching keyword - - while (1) { - if (fgets(line,MAXLINE,fp) == nullptr) { - string err_msg=string("Did not find keyword \"") - +string(keyword)+string("\" in dihedral table file."); - error->one(FLERR, err_msg); - } - if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line - if (line[0] == '#') continue; // comment - char *word = strtok(line," \t\n\r"); - if (strcmp(word,keyword) == 0) break; // matching keyword - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); // no match, skip section - param_extract(tb,line); - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - for (int i = 0; i < tb->ninput; i++) - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - } - - // read args on 2nd line of section - // allocate table arrays for file values - - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - param_extract(tb,line); - memory->create(tb->phifile,tb->ninput,"dihedral:phifile"); - memory->create(tb->efile,tb->ninput,"dihedral:efile"); - memory->create(tb->ffile,tb->ninput,"dihedral:ffile"); - - // read a,e,f table values from file - - int itmp; - for (int i = 0; i < tb->ninput; i++) { - // Read the next line. Make sure the file is long enough. - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - - // Skip blank lines and delete text following a '#' character - char *pe = strchr(line, '#'); - if (pe != nullptr) *pe = '\0'; //terminate string at '#' character - char *pc = line; - while ((*pc != '\0') && isspace(*pc)) - pc++; - if (*pc != '\0') { //If line is not a blank line - stringstream line_ss(line); - if (tb->f_unspecified) { - line_ss >> itmp; - line_ss >> tb->phifile[i]; - line_ss >> tb->efile[i]; - } else { - line_ss >> itmp; - line_ss >> tb->phifile[i]; - line_ss >> tb->efile[i]; - line_ss >> tb->ffile[i]; - } - if (! line_ss) { - stringstream err_msg; - err_msg << "Read error in table "<< keyword<<", near line "<f_unspecified) && (i==0)) - err_msg << "\n (This sometimes occurs if users forget to specify the \"NOF\" option.)\n"; - error->one(FLERR, err_msg.str().c_str()); - } - } else //if it is a blank line, then skip it. - i--; - } //for (int i = 0; (i < tb->ninput) && fp; i++) { - - fclose(fp); -} - -/* ---------------------------------------------------------------------- - build spline representation of e,f over entire range of read-in table - this function sets these values in e2file,f2file. - I also perform a crude check for force & energy consistency. -------------------------------------------------------------------------- */ - -void DihedralTableCut::spline_table(Table *tb) -{ - memory->create(tb->e2file,tb->ninput,"dihedral:e2file"); - memory->create(tb->f2file,tb->ninput,"dihedral:f2file"); - - if (cyc_spline(tb->phifile, tb->efile, tb->ninput, - MY_2PI,tb->e2file,comm->me == 0)) - error->one(FLERR,"Error computing dihedral spline tables"); - - if (! tb->f_unspecified) { - if (cyc_spline(tb->phifile, tb->ffile, tb->ninput, - MY_2PI, tb->f2file, comm->me == 0)) - error->one(FLERR,"Error computing dihedral spline tables"); - } - - // CHECK to help make sure the user calculated forces in a way - // which is grossly numerically consistent with the energy table. - if (! tb->f_unspecified) { - int num_disagreements = 0; - for (int i=0; ininput; i++) { - - // Calculate what the force should be at the control points - // by using linear interpolation of the derivatives of the energy: - - double phi_i = tb->phifile[i]; - - // First deal with periodicity - double phi_im1, phi_ip1; - int im1 = i-1; - if (im1 < 0) { - im1 += tb->ninput; - phi_im1 = tb->phifile[im1] - MY_2PI; - } - else - phi_im1 = tb->phifile[im1]; - int ip1 = i+1; - if (ip1 >= tb->ninput) { - ip1 -= tb->ninput; - phi_ip1 = tb->phifile[ip1] + MY_2PI; - } - else - phi_ip1 = tb->phifile[ip1]; - - // Now calculate the midpoints above and below phi_i = tb->phifile[i] - double phi_lo= 0.5*(phi_im1 + phi_i); //midpoint between phi_im1 and phi_i - double phi_hi= 0.5*(phi_i + phi_ip1); //midpoint between phi_i and phi_ip1 - - // Use a linear approximation to the derivative at these two midpoints - double dU_dphi_lo = - (tb->efile[i] - tb->efile[im1]) - / - (phi_i - phi_im1); - double dU_dphi_hi = - (tb->efile[ip1] - tb->efile[i]) - / - (phi_ip1 - phi_i); - - // Now calculate the derivative at position - // phi_i (=tb->phifile[i]) using linear interpolation - - double a = (phi_i - phi_lo) / (phi_hi - phi_lo); - double b = (phi_hi - phi_i) / (phi_hi - phi_lo); - double dU_dphi = a*dU_dphi_lo + b*dU_dphi_hi; - double f = -dU_dphi; - // Alternately, we could use spline interpolation instead: - // double f = - splintD(tb->phifile, tb->efile, tb->e2file, - // tb->ninput, MY_2PI, tb->phifile[i]); - // This is the way I originally did it, but I trust - // the ugly simple linear way above better. - // Recall this entire block of code doess not calculate - // anything important. It does not have to be perfect. - // We are only checking for stupid user errors here. - - if ((f != 0.0) && - (tb->ffile[i] != 0.0) && - ((f/tb->ffile[i] < 0.5) || (f/tb->ffile[i] > 2.0))) { - num_disagreements++; - } - } // for (int i=0; ininput; i++) - - if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) { - string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); - error->all(FLERR,msg.c_str()); - } - - } // check for consistency if (! tb->f_unspecified) - -} // DihedralTable::spline_table() - - -/* ---------------------------------------------------------------------- - compute a,e,f vectors from splined values -------------------------------------------------------------------------- */ - -void DihedralTableCut::compute_table(Table *tb) -{ - //delta = table spacing in dihedral angle for tablength (cyclic) bins - tb->delta = MY_2PI / tablength; - tb->invdelta = 1.0/tb->delta; - tb->deltasq6 = tb->delta*tb->delta / 6.0; - - // N evenly spaced bins in dihedral angle from 0 to 2*PI - // phi,e,f = value at lower edge of bin - // de,df values = delta values of e,f (cyclic, in this case) - // phi,e,f,de,df are arrays containing "tablength" number of entries - - memory->create(tb->phi,tablength,"dihedral:phi"); - memory->create(tb->e,tablength,"dihedral:e"); - memory->create(tb->de,tablength,"dihedral:de"); - memory->create(tb->f,tablength,"dihedral:f"); - memory->create(tb->df,tablength,"dihedral:df"); - memory->create(tb->e2,tablength,"dihedral:e2"); - memory->create(tb->f2,tablength,"dihedral:f2"); - - if (tabstyle == SPLINE) { - // Use cubic spline interpolation to calculate the entries in the - // internal table. (This is true regardless...even if tabstyle!=SPLINE.) - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_splint(tb->phifile,tb->efile,tb->e2file,tb->ninput,MY_2PI,phi); - if (! tb->f_unspecified) - tb->f[i] = cyc_splint(tb->phifile,tb->ffile,tb->f2file,tb->ninput,MY_2PI,phi); - } - } // if (tabstyle == SPLINE) - else if (tabstyle == LINEAR) { - if (! tb->f_unspecified) { - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_lin(tb->phifile,tb->efile,tb->ninput,MY_2PI,phi); - tb->f[i]= cyc_lin(tb->phifile,tb->ffile,tb->ninput,MY_2PI,phi); - } - } - else { - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_lin(tb->phifile,tb->efile,tb->ninput,MY_2PI,phi); - } - // In the linear case, if the user did not specify the forces, then we - // must generate the "f" array. Do this using linear interpolation - // of the e array (which itself was generated above) - for (int i = 0; i < tablength; i++) { - int im1 = i-1; if (im1 < 0) im1 += tablength; - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - double dedx = (tb->e[ip1] - tb->e[im1]) / (2.0 * tb->delta); - // (This is the average of the linear slopes on either side of the node. - // Note that the nodes in the internal table are evenly spaced.) - tb->f[i] = -dedx; - } - } - - - // Fill the linear interpolation tables (de, df) - for (int i = 0; i < tablength; i++) { - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - tb->de[i] = tb->e[ip1] - tb->e[i]; - tb->df[i] = tb->f[ip1] - tb->f[i]; - } - } // else if (tabstyle == LINEAR) - - - - cyc_spline(tb->phi, tb->e, tablength, MY_2PI, tb->e2, comm->me == 0); - if (! tb->f_unspecified) - cyc_spline(tb->phi, tb->f, tablength, MY_2PI, tb->f2, comm->me == 0); -} - - -/* ---------------------------------------------------------------------- - extract attributes from parameter line in table section - format of line: N value NOF DEGREES RADIANS - N is required, other params are optional -------------------------------------------------------------------------- */ - -void DihedralTableCut::param_extract(Table *tb, char *line) -{ - //tb->theta0 = 180.0; <- equilibrium angles not supported - tb->ninput = 0; - tb->f_unspecified = false; //default - tb->use_degrees = true; //default - - char *word = strtok(line," \t\n\r\f"); - while (word) { - if (strcmp(word,"N") == 0) { - word = strtok(nullptr," \t\n\r\f"); - tb->ninput = atoi(word); - } - else if (strcmp(word,"NOF") == 0) { - tb->f_unspecified = true; - } - else if ((strcmp(word,"DEGREES") == 0) || (strcmp(word,"degrees") == 0)) { - tb->use_degrees = true; - } - else if ((strcmp(word,"RADIANS") == 0) || (strcmp(word,"radians") == 0)) { - tb->use_degrees = false; - } - else if (strcmp(word,"CHECKU") == 0) { - word = strtok(nullptr," \t\n\r\f"); - memory->sfree(checkU_fname); - memory->create(checkU_fname,strlen(word)+1,"dihedral_table:checkU"); - strcpy(checkU_fname, word); - } - else if (strcmp(word,"CHECKF") == 0) { - word = strtok(nullptr," \t\n\r\f"); - memory->sfree(checkF_fname); - memory->create(checkF_fname,strlen(word)+1,"dihedral_table:checkF"); - strcpy(checkF_fname, word); - } - // COMMENTING OUT: equilibrium angles are not supported - //else if (strcmp(word,"EQ") == 0) { - // word = strtok(nullptr," \t\n\r\f"); - // tb->theta0 = atof(word); - //} - else { - string err_msg("Invalid keyword in dihedral angle table parameters"); - err_msg += string(" (") + string(word) + string(")"); - error->one(FLERR, err_msg); - } - word = strtok(nullptr," \t\n\r\f"); - } - - if (tb->ninput == 0) - error->one(FLERR,"Dihedral table parameters did not set N"); - -} // DihedralTable::param_extract() - - -/* ---------------------------------------------------------------------- - broadcast read-in table info from proc 0 to other procs - this function communicates these values in Table: - ninput,phifile,efile,ffile, - f_unspecified,use_degrees -------------------------------------------------------------------------- */ - -void DihedralTableCut::bcast_table(Table *tb) -{ - MPI_Bcast(&tb->ninput,1,MPI_INT,0,world); - - int me; - MPI_Comm_rank(world,&me); - if (me > 0) { - memory->create(tb->phifile,tb->ninput,"dihedral:phifile"); - memory->create(tb->efile,tb->ninput,"dihedral:efile"); - memory->create(tb->ffile,tb->ninput,"dihedral:ffile"); - } - - MPI_Bcast(tb->phifile,tb->ninput,MPI_DOUBLE,0,world); - MPI_Bcast(tb->efile,tb->ninput,MPI_DOUBLE,0,world); - MPI_Bcast(tb->ffile,tb->ninput,MPI_DOUBLE,0,world); - - MPI_Bcast(&tb->f_unspecified,1,MPI_INT,0,world); - MPI_Bcast(&tb->use_degrees,1,MPI_INT,0,world); - - // COMMENTING OUT: equilibrium angles are not supported - //MPI_Bcast(&tb->theta0,1,MPI_DOUBLE,0,world); -} - - diff --git a/src/USER-MISC/dihedral_table_cut.h b/src/USER-MISC/dihedral_table_cut.h index b07e925f08..b956069e14 100644 --- a/src/USER-MISC/dihedral_table_cut.h +++ b/src/USER-MISC/dihedral_table_cut.h @@ -20,131 +20,21 @@ DihedralStyle(table/cut,DihedralTableCut) #ifndef LMP_DIHEDRAL_TABLE_CUT_H #define LMP_DIHEDRAL_TABLE_CUT_H -#include "dihedral.h" +#include "dihedral_table.h" namespace LAMMPS_NS { -class DihedralTableCut : public Dihedral { +class DihedralTableCut : public DihedralTable { public: DihedralTableCut(class LAMMPS *); virtual ~DihedralTableCut(); virtual void compute(int, int); - void settings(int, char **); - void coeff(int, char **); - void write_restart(FILE *); - void read_restart(FILE *); - void write_restart_settings(FILE *); - void read_restart_settings(FILE *); + virtual void coeff(int, char **); protected: double *aat_k,*aat_theta0_1,*aat_theta0_2; - void allocate(); - - int tabstyle,tablength; - char *checkU_fname; - char *checkF_fname; - - struct Table { - int ninput; - int f_unspecified; // boolean (but MPI does not like type "bool") - int use_degrees; // boolean (but MPI does not like type "bool") - double *phifile,*efile,*ffile; - double *e2file,*f2file; - double delta,invdelta,deltasq6; - double *phi,*e,*de,*f,*df,*e2,*f2; - }; - - int ntables; - Table *tables; - int *tabindex; - - void null_table(Table *); - void free_table(Table *); - void read_table(Table *, char *, char *); - void bcast_table(Table *); - void spline_table(Table *); - void compute_table(Table *); - - void param_extract(Table *, char *); - - // -------------------------------------------- - // ------------ inline functions -------------- - // -------------------------------------------- - - // ----------------------------------------------------------- - // uf_lookup() - // quickly calculate the potential u and force f at angle x, - // using the internal tables tb->e and tb->f (evenly spaced) - // ----------------------------------------------------------- - enum{LINEAR,SPLINE}; - - inline void uf_lookup(int type, double x, double &u, double &f) - { - Table *tb = &tables[tabindex[type]]; - double x_over_delta = x*tb->invdelta; - int i = static_cast (x_over_delta); - double a; - double b = x_over_delta - i; - // Apply periodic boundary conditions to indices i and i+1 - if (i >= tablength) i -= tablength; - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - - switch(tabstyle) { - case LINEAR: - u = tb->e[i] + b * tb->de[i]; - f = -(tb->f[i] + b * tb->df[i]); //<--works even if tb->f_unspecified==true - break; - case SPLINE: - a = 1.0 - b; - u = a * tb->e[i] + b * tb->e[ip1] + - ((a*a*a-a)*tb->e2[i] + (b*b*b-b)*tb->e2[ip1]) * - tb->deltasq6; - if (tb->f_unspecified) - //Formula below taken from equation3.3.5 of "numerical recipes in c" - //"f"=-derivative of e with respect to x (or "phi" in this case) - f = -((tb->e[i]-tb->e[ip1])*tb->invdelta + - ((3.0*a*a-1.0)*tb->e2[i]+(1.0-3.0*b*b)*tb->e2[ip1])*tb->delta/6.0); - else - f = -(a * tb->f[i] + b * tb->f[ip1] + - ((a*a*a-a)*tb->f2[i] + (b*b*b-b)*tb->f2[ip1]) * - tb->deltasq6); - break; - } // switch(tabstyle) - } // uf_lookup() - - - // ---------------------------------------------------------- - // u_lookup() - // quickly calculate the potential u at angle x using tb->e - //----------------------------------------------------------- - - inline void u_lookup(int type, double x, double &u) - { - Table *tb = &tables[tabindex[type]]; - int N = tablength; - - // i = static_cast ((x - tb->lo) * tb->invdelta); <-general version - double x_over_delta = x*tb->invdelta; - int i = static_cast (x_over_delta); - double b = x_over_delta - i; - - // Apply periodic boundary conditions to indices i and i+1 - if (i >= N) i -= N; - int ip1 = i+1; if (ip1 >= N) ip1 -= N; - - if (tabstyle == LINEAR) { - u = tb->e[i] + b * tb->de[i]; - } - else if (tabstyle == SPLINE) { - double a = 1.0 - b; - u = a * tb->e[i] + b * tb->e[ip1] + - ((a*a*a-a)*tb->e2[i] + (b*b*b-b)*tb->e2[ip1]) * - tb->deltasq6; - } - } // u_lookup() - - + virtual void allocate(); }; } From 1e3f1c584c569601efef6111babd3b3302dde656 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 08:12:37 -0400 Subject: [PATCH 21/21] simplify by using utils::strdup() fmt::format() and reorder includes --- src/USER-MISC/fix_orient_eco.cpp | 4 +- src/USER-MISC/fix_pafi.cpp | 4 +- src/USER-MISC/fix_wall_region_ees.cpp | 5 +-- src/USER-MISC/temper_grem.cpp | 26 ++++++------ src/USER-MOLFILE/dump_molfile.cpp | 11 ++--- src/USER-PHONON/fix_phonon.cpp | 61 +++++++++++---------------- src/USER-PLUMED/fix_plumed.cpp | 27 +++++------- src/USER-PTM/compute_ptm_atom.cpp | 11 ++--- src/USER-QTB/fix_qbmsst.cpp | 20 ++++----- src/USER-QTB/fix_qtb.cpp | 24 +++++------ src/USER-QUIP/pair_quip.cpp | 37 +++++++--------- src/USER-REACTION/fix_bond_react.cpp | 48 +++++---------------- src/USER-REAXC/fix_qeq_reax.cpp | 28 ++++++------ src/USER-REAXC/fix_reaxc_species.cpp | 19 +++++---- src/USER-SCAFACOS/scafacos.cpp | 17 ++++---- src/USER-SMD/fix_smd_setvel.cpp | 16 ++----- src/USER-SMD/fix_smd_wall_surface.cpp | 38 +++-------------- src/USER-SMD/fix_smd_wall_surface.h | 1 - 18 files changed, 151 insertions(+), 246 deletions(-) diff --git a/src/USER-MISC/fix_orient_eco.cpp b/src/USER-MISC/fix_orient_eco.cpp index ce412e6fc9..3d6db4cd4f 100644 --- a/src/USER-MISC/fix_orient_eco.cpp +++ b/src/USER-MISC/fix_orient_eco.cpp @@ -87,9 +87,7 @@ FixOrientECO::FixOrientECO(LAMMPS *lmp, int narg, char **arg) : // read reference orientations from file // work on rank 0 only - int n = strlen(arg[6]) + 1; - dir_filename = new char[n]; - strcpy(dir_filename, arg[6]); + dir_filename = utils::strdup(arg[6]); if (me == 0) { char line[IMGMAX]; char *result; diff --git a/src/USER-MISC/fix_pafi.cpp b/src/USER-MISC/fix_pafi.cpp index ec0733657a..c2ad62d7d0 100644 --- a/src/USER-MISC/fix_pafi.cpp +++ b/src/USER-MISC/fix_pafi.cpp @@ -74,9 +74,7 @@ FixPAFI::FixPAFI(LAMMPS *lmp, int narg, char **arg) : com_flag = 1; time_integrate = 1; - int n = strlen(arg[3])+1; - computename = new char[n]; - strcpy(computename,&arg[3][0]); + computename = utils::strdup(&arg[3][0]); icompute = modify->find_compute(computename); if (icompute == -1) diff --git a/src/USER-MISC/fix_wall_region_ees.cpp b/src/USER-MISC/fix_wall_region_ees.cpp index 44067b0742..51e0af9dc4 100644 --- a/src/USER-MISC/fix_wall_region_ees.cpp +++ b/src/USER-MISC/fix_wall_region_ees.cpp @@ -52,10 +52,7 @@ FixWallRegionEES::FixWallRegionEES(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for fix wall/region/ees does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,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); diff --git a/src/USER-MISC/temper_grem.cpp b/src/USER-MISC/temper_grem.cpp index ee3c5ae5e4..3b987aaad2 100644 --- a/src/USER-MISC/temper_grem.cpp +++ b/src/USER-MISC/temper_grem.cpp @@ -16,21 +16,23 @@ ------------------------------------------------------------------------- */ #include "temper_grem.h" -#include -#include -#include "fix_grem.h" -#include "universe.h" + +#include "compute.h" #include "domain.h" -#include "update.h" +#include "error.h" +#include "finish.h" +#include "fix.h" +#include "fix_grem.h" +#include "force.h" #include "integrate.h" #include "modify.h" -#include "compute.h" -#include "force.h" -#include "fix.h" #include "random_park.h" -#include "finish.h" #include "timer.h" -#include "error.h" +#include "universe.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; @@ -90,9 +92,7 @@ void TemperGrem::command(int narg, char **arg) double pressref = 0; // Get and check for nh fix - int n = strlen(arg[4])+1; - id_nh = new char[n]; - strcpy(id_nh,arg[4]); + id_nh = utils::strdup(arg[4]); int ifix = modify->find_fix(id_nh); if (ifix < 0) error->all(FLERR,"Fix id for nvt or npt fix does not exist"); diff --git a/src/USER-MOLFILE/dump_molfile.cpp b/src/USER-MOLFILE/dump_molfile.cpp index 9de9a79e26..20790d4b32 100644 --- a/src/USER-MOLFILE/dump_molfile.cpp +++ b/src/USER-MOLFILE/dump_molfile.cpp @@ -17,15 +17,16 @@ #include "dump_molfile.h" -#include -#include -#include "domain.h" #include "atom.h" #include "comm.h" -#include "update.h" +#include "domain.h" +#include "error.h" #include "group.h" #include "memory.h" -#include "error.h" +#include "update.h" + +#include +#include #include "molfile_interface.h" diff --git a/src/USER-PHONON/fix_phonon.cpp b/src/USER-PHONON/fix_phonon.cpp index 30fb7baad5..222f3fa1d2 100644 --- a/src/USER-PHONON/fix_phonon.cpp +++ b/src/USER-PHONON/fix_phonon.cpp @@ -23,21 +23,22 @@ konglt@sjtu.edu.cn; konglt@gmail.com ------------------------------------------------------------------------- */ +#include "fix_phonon.h" + +#include "atom.h" +#include "citeme.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "fft3d_wrap.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "update.h" #include #include -#include "fix_phonon.h" -#include "fft3d_wrap.h" -#include "atom.h" -#include "compute.h" -#include "domain.h" -#include "force.h" -#include "group.h" -#include "modify.h" -#include "update.h" -#include "citeme.h" -#include "memory.h" -#include "error.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -77,15 +78,9 @@ FixPhonon::FixPhonon(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) waitsteps = utils::bnumeric(FLERR,arg[5],false,lmp); // Wait this many timesteps before actually measuring if (waitsteps < 0) error->all(FLERR,"Illegal fix phonon command: waitsteps < 0 !"); - int n = strlen(arg[6]) + 1; // map file - mapfile = new char[n]; - strcpy(mapfile, arg[6]); - - n = strlen(arg[7]) + 1; // prefix of output - prefix = new char[n]; - strcpy(prefix, arg[7]); - logfile = new char[n+4]; - sprintf(logfile,"%s.log",prefix); + mapfile = utils::strdup(arg[6]); + prefix = utils::strdup(arg[7]); + logfile = utils::strdup(std::string(prefix)+".log"); int sdim = sysdim = domain->dimension; int iarg = 8; @@ -184,11 +179,9 @@ FixPhonon::FixPhonon(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) // output some information on the system to log file if (me == 0) { flog = fopen(logfile, "w"); - if (flog == nullptr) { - char str[MAXLINE]; - sprintf(str,"Can not open output file %s",logfile); - error->one(FLERR,str); - } + if (flog == nullptr) + error->one(FLERR,fmt::format("Can not open output file {}: {}", + logfile,utils::getsyserror())); fprintf(flog,"############################################################\n"); fprintf(flog,"# group name of the atoms under study : %s\n", group->names[igroup]); fprintf(flog,"# total number of atoms in the group : %d\n", ngroup); @@ -440,9 +433,7 @@ int FixPhonon::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temp ID"); @@ -563,10 +554,9 @@ void FixPhonon::readmap() // read from map file for others char line[MAXLINE]; FILE *fp = fopen(mapfile, "r"); - if (fp == nullptr) { - sprintf(line,"Cannot open input map file %s", mapfile); - error->all(FLERR,line); - } + if (fp == nullptr) + error->all(FLERR,fmt::format("Cannot open input map file {}: {}", + mapfile, utils::getsyserror())); if (fgets(line,MAXLINE,fp) == nullptr) error->all(FLERR,"Error while reading header of mapping file!"); @@ -712,9 +702,8 @@ void FixPhonon::postprocess( ) // write binary file, in fact, it is the force constants matrix that is written // Enforcement of ASR and the conversion of dynamical matrix is done in the postprocessing code - char fname[MAXLINE]; - sprintf(fname,"%s.bin." BIGINT_FORMAT,prefix,update->ntimestep); - FILE *fp_bin = fopen(fname,"wb"); + auto fname = fmt::format("{}.bin.{}",prefix,update->ntimestep); + FILE *fp_bin = fopen(fname.c_str(),"wb"); fwrite(&sysdim, sizeof(int), 1, fp_bin); fwrite(&nx, sizeof(int), 1, fp_bin); diff --git a/src/USER-PLUMED/fix_plumed.cpp b/src/USER-PLUMED/fix_plumed.cpp index 1217237e19..8d3cdd5c34 100644 --- a/src/USER-PLUMED/fix_plumed.cpp +++ b/src/USER-PLUMED/fix_plumed.cpp @@ -16,25 +16,24 @@ Pablo Piaggi (EPFL) ------------------------------------------------------------------------- */ -#include - -#include +#include "fix_plumed.h" #include "atom.h" #include "comm.h" -#include "update.h" -#include "force.h" -#include "respa.h" +#include "compute.h" #include "domain.h" #include "error.h" +#include "force.h" #include "group.h" -#include "fix_plumed.h" -#include "universe.h" -#include "compute.h" #include "modify.h" #include "pair.h" - +#include "respa.h" #include "timer.h" +#include "universe.h" +#include "update.h" + +#include +#include #include "plumed/wrapper/Plumed.h" @@ -542,9 +541,7 @@ int FixPlumed::modify_param(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); modify->delete_compute(id_pe); delete[] id_pe; - int n = strlen(arg[1]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[1]); + id_pe = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify potential energy ID"); @@ -561,9 +558,7 @@ int FixPlumed::modify_param(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); modify->delete_compute(id_press); delete[] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-PTM/compute_ptm_atom.cpp b/src/USER-PTM/compute_ptm_atom.cpp index 376253dd84..0622b9dcc0 100644 --- a/src/USER-PTM/compute_ptm_atom.cpp +++ b/src/USER-PTM/compute_ptm_atom.cpp @@ -17,23 +17,24 @@ under ------------------------------------------------------------------------- */ #include "compute_ptm_atom.h" -#include -#include -#include -#include #include "atom.h" #include "citeme.h" #include "comm.h" #include "error.h" #include "force.h" +#include "group.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "update.h" -#include "group.h" + +#include +#include +#include +#include #include "ptm_functions.h" diff --git a/src/USER-QTB/fix_qbmsst.cpp b/src/USER-QTB/fix_qbmsst.cpp index 0b54811db0..a9dfb83f06 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -19,17 +19,17 @@ #include "fix_qbmsst.h" #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" +#include "comm.h" #include "compute.h" #include "domain.h" -#include "comm.h" -#include "random_mars.h" -#include "memory.h" #include "error.h" +#include "force.h" #include "kspace.h" #include "math_const.h" +#include "memory.h" +#include "modify.h" +#include "random_mars.h" +#include "update.h" #include #include @@ -869,9 +869,7 @@ int FixQBMSST::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); @@ -891,9 +889,7 @@ int FixQBMSST::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(id_press); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-QTB/fix_qtb.cpp b/src/USER-QTB/fix_qtb.cpp index 4c79fbeaae..e4e645a1bb 100644 --- a/src/USER-QTB/fix_qtb.cpp +++ b/src/USER-QTB/fix_qtb.cpp @@ -18,20 +18,20 @@ #include "fix_qtb.h" -#include -#include - #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "compute.h" -#include "respa.h" #include "comm.h" -#include "random_mars.h" +#include "compute.h" +#include "error.h" +#include "force.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "random_mars.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -345,9 +345,7 @@ int FixQTB::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index f850925764..2d338da158 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -16,21 +16,21 @@ Aidan Thompson (Sandia, athomps@sandia.gov) ------------------------------------------------------------------------- */ -#include -#include - -#include #include "pair_quip.h" + #include "atom.h" -#include "update.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" -#include "domain.h" +#include "neighbor.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; @@ -252,24 +252,17 @@ void PairQUIP::coeff(int narg, char **arg) if (!allocated) allocate(); int n = atom->ntypes; - if (narg != (4+n)) { - char str[1024]; - sprintf(str,"Number of arguments %d is not correct, it should be %d", narg, 4+n); - error->all(FLERR,str); - } + if (narg != (4+n)) + error->all(FLERR,fmt::format("Number of arguments {} is not correct, " + "it should be {}", narg, 4+n)); // ensure I,J args are * * if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) error->all(FLERR,"Incorrect args for pair coefficients"); - n_quip_file = strlen(arg[2]); - quip_file = new char[n_quip_file+1]; - strcpy(quip_file,arg[2]); - - n_quip_string = strlen(arg[3]); - quip_string = new char[n_quip_string+1]; - strcpy(quip_string,arg[3]); + quip_file = utils::strdup(arg[2]); + quip_string = utils::strdup(arg[3]); for (int i = 4; i < narg; i++) { if (strcmp(arg[i],"NULL") == 0) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 91354506d1..201949a874 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -169,9 +169,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[iarg+1],"yes") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix bond/react command:" "'stabilization' keyword has too few arguments"); - int n = strlen(arg[iarg+2]) + 1; - exclude_group = new char[n]; - strcpy(exclude_group,arg[iarg+2]); + exclude_group = utils::strdup(arg[iarg+2]); stabilization_flag = 1; nve_limit_xmax = arg[iarg+3]; iarg += 4; @@ -273,9 +271,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : groupbits[rxn] = group->bitmask[groupid]; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[NEVERY][rxn] = input->variable->find(str); if (var_id[NEVERY][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -291,9 +287,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : iarg++; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[RMIN][rxn] = input->variable->find(str); if (var_id[RMIN][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -312,9 +306,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : iarg++; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[RMAX][rxn] = input->variable->find(str); if (var_id[RMAX][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -340,8 +332,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : "fix bond/react does not exist"); //read superimpose file - files[rxn] = new char[strlen(arg[iarg])+1]; - strcpy(files[rxn],arg[iarg]); + files[rxn] = utils::strdup(arg[iarg]); iarg++; while (iarg < narg && strcmp(arg[iarg],"react") != 0) { @@ -350,9 +341,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : "'prob' keyword has too few arguments"); // check if probability is a variable if (strncmp(arg[iarg+1],"v_",2) == 0) { - int n = strlen(&arg[iarg+1][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg+1][2]); + char *str = utils::strdup(&arg[iarg+1][2]); var_id[PROB][rxn] = input->variable->find(str); if (var_id[PROB][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -727,21 +716,14 @@ void FixBondReact::post_constructor() fix3 = modify->fix[modify->nfix-1]; } - len = strlen("statted_tags") + 1; - statted_id = new char[len]; - strcpy(statted_id,"statted_tags"); + statted_id = utils::strdup("statted_tags"); // if static group exists, use as parent group // also, rename dynamic exclude_group by appending '_REACT' char *exclude_PARENT_group; - int n = strlen(exclude_group) + 1; - exclude_PARENT_group = new char[n]; - strcpy(exclude_PARENT_group,exclude_group); - n += strlen("_REACT"); + exclude_PARENT_group = utils::strdup(exclude_group); delete [] exclude_group; - exclude_group = new char[n]; - strcpy(exclude_group,exclude_PARENT_group); - strcat(exclude_group,"_REACT"); + exclude_group = utils::strdup(std::string(exclude_PARENT_group)+"_REACT"); group->find_or_create(exclude_group); if (groupid == -1) @@ -766,13 +748,8 @@ void FixBondReact::post_constructor() // sleeping code, for future capabilities custom_exclude_flag = 1; // first we have to find correct fix group reference - int n = strlen("GROUP_") + strlen(exclude_group) + 1; - char *fix_group = new char[n]; - strcpy(fix_group,"GROUP_"); - strcat(fix_group,exclude_group); - int ifix = modify->find_fix(fix_group); + int ifix = modify->find_fix(std::string("GROUP_")+exclude_group); Fix *fix = modify->fix[ifix]; - delete [] fix_group; // this returns names of corresponding property int unused; @@ -780,10 +757,7 @@ void FixBondReact::post_constructor() idprop = (char *) fix->extract("property",unused); if (idprop == nullptr) error->all(FLERR,"Exclude group must be a per-atom property group"); - - len = strlen(idprop) + 1; - statted_id = new char[len]; - strcpy(statted_id,idprop); + statted_id = utils::strdup(idprop); // initialize per-atom statted_tags to 1 // need to correct for smooth restarts diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 355cbbb770..44088043f0 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -20,22 +20,24 @@ #include "fix_qeq_reax.h" -#include -#include -#include "pair_reaxc.h" #include "atom.h" +#include "citeme.h" #include "comm.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "update.h" +#include "error.h" #include "force.h" #include "group.h" -#include "pair.h" -#include "respa.h" #include "memory.h" -#include "citeme.h" -#include "error.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "pair.h" +#include "pair_reaxc.h" +#include "respa.h" +#include "update.h" + +#include +#include + #include "reaxc_defs.h" #include "reaxc_types.h" @@ -70,9 +72,7 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : swa = utils::numeric(FLERR,arg[4],false,lmp); swb = utils::numeric(FLERR,arg[5],false,lmp); tolerance = utils::numeric(FLERR,arg[6],false,lmp); - int len = strlen(arg[7]) + 1; - pertype_option = new char[len]; - strcpy(pertype_option,arg[7]); + pertype_option = utils::strdup(arg[7]); // dual CG support only available for USER-OMP variant // check for compatibility is in Fix::post_constructor() diff --git a/src/USER-REAXC/fix_reaxc_species.cpp b/src/USER-REAXC/fix_reaxc_species.cpp index e90cde2529..81b1dafa61 100644 --- a/src/USER-REAXC/fix_reaxc_species.cpp +++ b/src/USER-REAXC/fix_reaxc_species.cpp @@ -18,20 +18,21 @@ #include "fix_reaxc_species.h" - -#include -#include "fix_ave_atom.h" #include "atom.h" -#include "domain.h" -#include "update.h" -#include "modify.h" -#include "neighbor.h" -#include "neigh_list.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "fix_ave_atom.h" #include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neigh_list.h" +#include "neighbor.h" #include "pair_reaxc.h" +#include "update.h" + +#include + #include "reaxc_defs.h" using namespace LAMMPS_NS; diff --git a/src/USER-SCAFACOS/scafacos.cpp b/src/USER-SCAFACOS/scafacos.cpp index 0ce027ec1e..fa12cffe4c 100644 --- a/src/USER-SCAFACOS/scafacos.cpp +++ b/src/USER-SCAFACOS/scafacos.cpp @@ -15,21 +15,22 @@ Contributing author: Rene Halver (JSC) ------------------------------------------------------------------------- */ -#include -#include -#include #include "scafacos.h" + #include "atom.h" #include "comm.h" #include "domain.h" +#include "error.h" #include "force.h" #include "memory.h" -#include "error.h" + +#include +#include +#include +#include // ScaFaCoS library -#include -#include #include "fcs.h" using namespace LAMMPS_NS; @@ -54,9 +55,7 @@ void Scafacos::settings(int narg, char **arg) { if (narg != 2) error->all(FLERR,"Illegal scafacos command"); - int n = strlen(arg[0]) + 1; - method = new char[n]; - strcpy(method,arg[0]); + method = utils::strdup(arg[0]); tolerance = utils::numeric(FLERR,arg[1],false,lmp); // optional ScaFaCoS library setting defaults diff --git a/src/USER-SMD/fix_smd_setvel.cpp b/src/USER-SMD/fix_smd_setvel.cpp index f4c23e9f7a..471159ea53 100644 --- a/src/USER-SMD/fix_smd_setvel.cpp +++ b/src/USER-SMD/fix_smd_setvel.cpp @@ -60,9 +60,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : xstr = ystr = zstr = nullptr; if (strstr(arg[3], "v_") == arg[3]) { - int n = strlen(&arg[3][2]) + 1; - xstr = new char[n]; - strcpy(xstr, &arg[3][2]); + xstr = utils::strdup( &arg[3][2]); } else if (strcmp(arg[3], "NULL") == 0) { xstyle = NONE; } else { @@ -70,9 +68,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : xstyle = CONSTANT; } if (strstr(arg[4], "v_") == arg[4]) { - int n = strlen(&arg[4][2]) + 1; - ystr = new char[n]; - strcpy(ystr, &arg[4][2]); + ystr = utils::strdup( &arg[4][2]); } else if (strcmp(arg[4], "NULL") == 0) { ystyle = NONE; } else { @@ -80,9 +76,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : ystyle = CONSTANT; } if (strstr(arg[5], "v_") == arg[5]) { - int n = strlen(&arg[5][2]) + 1; - zstr = new char[n]; - strcpy(zstr, &arg[5][2]); + zstr = utils::strdup( &arg[5][2]); } else if (strcmp(arg[5], "NULL") == 0) { zstyle = NONE; } else { @@ -103,9 +97,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[iarg + 1]); if (iregion == -1) error->all(FLERR, "Region ID for fix setvelocity does not exist"); - int n = strlen(arg[iarg + 1]) + 1; - idregion = new char[n]; - strcpy(idregion, arg[iarg + 1]); + idregion = utils::strdup( arg[iarg + 1]); iarg += 2; } else error->all(FLERR, "Illegal fix setvelocity command"); diff --git a/src/USER-SMD/fix_smd_wall_surface.cpp b/src/USER-SMD/fix_smd_wall_surface.cpp index f37c9ec873..e9d32b5684 100644 --- a/src/USER-SMD/fix_smd_wall_surface.cpp +++ b/src/USER-SMD/fix_smd_wall_surface.cpp @@ -184,32 +184,6 @@ void FixSMDWallSurface::setup(int /*vflag*/) { read_triangles(0); } -/* ---------------------------------------------------------------------- - function to determine number of values in a text line - ------------------------------------------------------------------------- */ - -int FixSMDWallSurface::count_words(const char *line) { - int n = strlen(line) + 1; - char *copy; - memory->create(copy, n, "atom:copy"); - strcpy(copy, line); - - char *ptr; - if ((ptr = strchr(copy, '#'))) - *ptr = '\0'; - - if (strtok(copy, " \t\n\r\f") == nullptr) { - memory->destroy(copy); - return 0; - } - n = 1; - while (strtok(nullptr, " \t\n\r\f")) - n++; - - memory->destroy(copy); - return n; -} - /* ---------------------------------------------------------------------- size of atom nlocal's restart data ------------------------------------------------------------------------- */ @@ -265,7 +239,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading number of triangle pairs"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords < 1) { error->one(FLERR,"first line of file is incorrect"); } @@ -290,7 +264,7 @@ void FixSMDWallSurface::read_triangles(int pass) { while (fgets(line, sizeof(line), fp)) { // read a line, should be the facet line // evaluate facet line - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 5) { //sprintf(str, "found end solid line"); //error->message(FLERR, str); @@ -322,7 +296,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR, "error reading outer loop"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 2) { error->one(FLERR,"error reading outer loop"); } @@ -335,7 +309,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading vertex line"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 4) { error->one(FLERR,"error reading vertex line"); } @@ -366,7 +340,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR, "error reading endloop"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 1) { error->one(FLERR,"error reading endloop"); } @@ -377,7 +351,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading endfacet"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 1) { error->one(FLERR,"error reading endfacet"); } diff --git a/src/USER-SMD/fix_smd_wall_surface.h b/src/USER-SMD/fix_smd_wall_surface.h index 10f80c4ca8..3ff2b49737 100644 --- a/src/USER-SMD/fix_smd_wall_surface.h +++ b/src/USER-SMD/fix_smd_wall_surface.h @@ -34,7 +34,6 @@ public: void setup(int); void min_setup(int); - int count_words(const char *line); void read_triangles(int pass); private: