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/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/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 71c2caa3f0..8c60ac1ebb 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -24,20 +24,17 @@ 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: .. math:: - E = 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. -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 ` @@ -47,10 +44,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 -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. +Note that the prefactor :math:`C` is specified as coefficient and not the overall force +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. ---------- 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). 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). 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) 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/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/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/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 2ba0be29e0..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; @@ -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(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(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..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; @@ -26,25 +28,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/GPU/pair_sw_gpu.cpp b/src/GPU/pair_sw_gpu.cpp index 7bfbe2810f..b819580488 100644 --- a/src/GPU/pair_sw_gpu.cpp +++ b/src/GPU/pair_sw_gpu.cpp @@ -186,7 +186,7 @@ void PairSWGPU::init_style() if (i < 0 || j < 0) continue; else { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; ncutsq[ii][jj] = params[ijparam].cutsq; ncut[ii][jj] = params[ijparam].cut; sigma[ii][jj] = params[ijparam].sigma; @@ -206,7 +206,7 @@ void PairSWGPU::init_style() if (k < 0) continue; else { - int ijkparam = elem2param[i][j][k]; + int ijkparam = elem3param[i][j][k]; costheta[ii][jj][kk] = params[ijkparam].costheta; lambda_epsilon[ii][jj][kk] = params[ijkparam].lambda_epsilon; } @@ -218,7 +218,7 @@ void PairSWGPU::init_style() int success = sw_gpu_init(tp1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, ncutsq, ncut, sigma, powerp, powerq, sigma_gamma, c1, c2, c3, c4, c5, - c6, lambda_epsilon, costheta, map, elem2param); + c6, lambda_epsilon, costheta, map, elem3param); memory->destroy(ncutsq); memory->destroy(ncut); diff --git a/src/GPU/pair_tersoff_gpu.cpp b/src/GPU/pair_tersoff_gpu.cpp index e675ba6903..c2f3413d3d 100644 --- a/src/GPU/pair_tersoff_gpu.cpp +++ b/src/GPU/pair_tersoff_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int tersoff_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, const int nelements, - int*** host_elem2param, const int nparams, + int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, @@ -218,7 +218,7 @@ void PairTersoffGPU::init_style() int success = tersoff_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c, d, h, gamma, beta, powern, _cutsq); diff --git a/src/GPU/pair_tersoff_mod_gpu.cpp b/src/GPU/pair_tersoff_mod_gpu.cpp index 98a7248c1f..6a5e9892ec 100644 --- a/src/GPU/pair_tersoff_mod_gpu.cpp +++ b/src/GPU/pair_tersoff_mod_gpu.cpp @@ -40,7 +40,7 @@ using namespace LAMMPS_NS; int tersoff_mod_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, - int* host_map, const int nelements, int*** host_elem2param, const int nparams, + int* host_map, const int nelements, int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, const double* ts_bigr, const double* ts_bigd, const double* ts_c1, @@ -211,7 +211,7 @@ void PairTersoffMODGPU::init_style() int success = tersoff_mod_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c5, h, beta, powern, powern_del, ca1, _cutsq); diff --git a/src/GPU/pair_tersoff_zbl_gpu.cpp b/src/GPU/pair_tersoff_zbl_gpu.cpp index e17b48fec5..0c56212fef 100644 --- a/src/GPU/pair_tersoff_zbl_gpu.cpp +++ b/src/GPU/pair_tersoff_zbl_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int tersoff_zbl_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, const int nelements, - int*** host_elem2param, const int nparams, + int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, @@ -227,7 +227,7 @@ void PairTersoffZBLGPU::init_style() int success = tersoff_zbl_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c, d, h, gamma, beta, powern, Z_i, Z_j, ZBLcut, ZBLexpscale, diff --git a/src/GPU/pair_vashishta_gpu.cpp b/src/GPU/pair_vashishta_gpu.cpp index c5dd722974..b3c703952f 100644 --- a/src/GPU/pair_vashishta_gpu.cpp +++ b/src/GPU/pair_vashishta_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int vashishta_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, - const int nelements, int*** host_elem2param, + const int nelements, int*** host_elem3param, const int nparams, const double* cutsq, const double* r0, const double* gamma, const double* eta, const double* lam1inv, const double* lam4inv, @@ -217,7 +217,7 @@ void PairVashishtaGPU::init_style() int mnf = 5e-2 * neighbor->oneatom; int success = vashishta_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, cutsq, r0, gamma, eta, lam1inv, + elem3param, nparams, cutsq, r0, gamma, eta, lam1inv, lam4inv, zizj, mbigd, dvrc, big6w, heta, bigh, bigw, c0, costheta, bigb, big2b, bigc); memory->destroy(cutsq); 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/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/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..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; @@ -29,45 +27,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(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 - 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(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 55c1d9d33f..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; @@ -29,45 +27,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(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 - 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(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 25984726b7..8eeffcb9f8 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(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; } 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_sw_kokkos.cpp b/src/KOKKOS/pair_sw_kokkos.cpp index 5d629dc42a..2fb90b7aec 100644 --- a/src/KOKKOS/pair_sw_kokkos.cpp +++ b/src/KOKKOS/pair_sw_kokkos.cpp @@ -289,7 +289,7 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf const X_FLOAT delz = ztmp - x(j,2); const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); if (rsq >= d_params[ijparam].cutsq) continue; twobody(d_params[ijparam],rsq,fpair,eflag,evdwl); @@ -313,7 +313,7 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf int j = d_neighbors_short(i,jj); j &= NEIGHMASK; const int jtype = d_map[type[j]]; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); delr1[0] = x(j,0) - xtmp; delr1[1] = x(j,1) - ytmp; delr1[2] = x(j,2) - ztmp; @@ -328,8 +328,8 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf int k = d_neighbors_short(i,kk); k &= NEIGHMASK; const int ktype = d_map[type[k]]; - const int ikparam = d_elem2param(itype,ktype,ktype); - const int ijkparam = d_elem2param(itype,jtype,ktype); + const int ikparam = d_elem3param(itype,ktype,ktype); + const int ijkparam = d_elem3param(itype,jtype,ktype); delr2[0] = x(k,0) - xtmp; delr2[1] = x(k,1) - ytmp; @@ -412,7 +412,7 @@ void PairSWKokkos::operator()(TagPairSWComputeFullA= d_params[ijparam].cutsq) continue; @@ -434,7 +434,7 @@ void PairSWKokkos::operator()(TagPairSWComputeFullA::operator()(TagPairSWComputeFullA::operator()(TagPairSWComputeFullB= nlocal) continue; const int jtype = d_map[type[j]]; - const int jiparam = d_elem2param(jtype,itype,itype); + const int jiparam = d_elem3param(jtype,itype,itype); const X_FLOAT xtmpj = x(j,0); const X_FLOAT ytmpj = x(j,1); const X_FLOAT ztmpj = x(j,2); @@ -530,8 +530,8 @@ void PairSWKokkos::operator()(TagPairSWComputeFullB::setup_params() { PairSW::setup_params(); - // sync elem2param and params + // sync elem3param and params - tdual_int_3d k_elem2param = tdual_int_3d("pair:elem2param",nelements,nelements,nelements); - t_host_int_3d h_elem2param = k_elem2param.h_view; + tdual_int_3d k_elem3param = tdual_int_3d("pair:elem3param",nelements,nelements,nelements); + t_host_int_3d h_elem3param = k_elem3param.h_view; tdual_param_1d k_params = tdual_param_1d("pair:params",nparams); t_host_param_1d h_params = k_params.h_view; @@ -646,17 +646,17 @@ void PairSWKokkos::setup_params() for (int i = 0; i < nelements; i++) for (int j = 0; j < nelements; j++) for (int k = 0; k < nelements; k++) - h_elem2param(i,j,k) = elem2param[i][j][k]; + h_elem3param(i,j,k) = elem3param[i][j][k]; for (int m = 0; m < nparams; m++) h_params[m] = params[m]; - k_elem2param.template modify(); - k_elem2param.template sync(); + k_elem3param.template modify(); + k_elem3param.template sync(); k_params.template modify(); k_params.template sync(); - d_elem2param = k_elem2param.template view(); + d_elem3param = k_elem3param.template view(); d_params = k_params.template view(); } diff --git a/src/KOKKOS/pair_sw_kokkos.h b/src/KOKKOS/pair_sw_kokkos.h index 31b7f3301d..b9f4559bc2 100644 --- a/src/KOKKOS/pair_sw_kokkos.h +++ b/src/KOKKOS/pair_sw_kokkos.h @@ -102,7 +102,7 @@ class PairSWKokkos : public PairSW { typedef typename tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; typedef typename tdual_int_3d::t_host t_host_int_3d; - t_int_3d_randomread d_elem2param; + t_int_3d_randomread d_elem3param; typename AT::t_int_1d_randomread d_map; typedef Kokkos::DualView tdual_param_1d; 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/KOKKOS/pair_tersoff_kokkos.cpp b/src/KOKKOS/pair_tersoff_kokkos.cpp index 41a32a61e3..72a79c0b49 100644 --- a/src/KOKKOS/pair_tersoff_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_kokkos.cpp @@ -125,7 +125,7 @@ void PairTersoffKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).gamma = params[m].gamma; k_params.h_view(i,j,k).lam3 = params[m].lam3; diff --git a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp index bd8e4d7528..c8431abc4b 100644 --- a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp @@ -124,7 +124,7 @@ void PairTersoffMODKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).lam3 = params[m].lam3; k_params.h_view(i,j,k).h = params[m].h; diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index 5e201dbc1c..3c362ad340 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -135,7 +135,7 @@ void PairTersoffZBLKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).gamma = params[m].gamma; k_params.h_view(i,j,k).lam3 = params[m].lam3; diff --git a/src/KOKKOS/pair_vashishta_kokkos.cpp b/src/KOKKOS/pair_vashishta_kokkos.cpp index 4b7b50afe9..71f3215931 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.cpp +++ b/src/KOKKOS/pair_vashishta_kokkos.cpp @@ -208,7 +208,7 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeShortNei int j = d_neighbors(i,jj); j &= NEIGHMASK; const int jtype = d_map[type[j]]; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); const X_FLOAT delx = xtmp - x(j,0); const X_FLOAT dely = ytmp - x(j,1); @@ -279,7 +279,7 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullB= nlocal) continue; const int jtype = d_map[type[j]]; - const int jiparam = d_elem2param(jtype,itype,itype); + const int jiparam = d_elem3param(jtype,itype,itype); const X_FLOAT xtmpj = x(j,0); const X_FLOAT ytmpj = x(j,1); const X_FLOAT ztmpj = x(j,2); @@ -508,8 +508,8 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeFullB::setup_params() { PairVashishta::setup_params(); - // sync elem2param and params + // sync elem3param and params - tdual_int_3d k_elem2param = tdual_int_3d("pair:elem2param",nelements,nelements,nelements); - t_host_int_3d h_elem2param = k_elem2param.h_view; + tdual_int_3d k_elem3param = tdual_int_3d("pair:elem3param",nelements,nelements,nelements); + t_host_int_3d h_elem3param = k_elem3param.h_view; tdual_param_1d k_params = tdual_param_1d("pair:params",nparams); t_host_param_1d h_params = k_params.h_view; @@ -622,17 +622,17 @@ void PairVashishtaKokkos::setup_params() for (int i = 0; i < nelements; i++) for (int j = 0; j < nelements; j++) for (int k = 0; k < nelements; k++) - h_elem2param(i,j,k) = elem2param[i][j][k]; + h_elem3param(i,j,k) = elem3param[i][j][k]; for (int m = 0; m < nparams; m++) h_params[m] = params[m]; - k_elem2param.template modify(); - k_elem2param.template sync(); + k_elem3param.template modify(); + k_elem3param.template sync(); k_params.template modify(); k_params.template sync(); - d_elem2param = k_elem2param.template view(); + d_elem3param = k_elem3param.template view(); d_params = k_params.template view(); } diff --git a/src/KOKKOS/pair_vashishta_kokkos.h b/src/KOKKOS/pair_vashishta_kokkos.h index 14dcf755df..aa8543e751 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.h +++ b/src/KOKKOS/pair_vashishta_kokkos.h @@ -102,7 +102,7 @@ class PairVashishtaKokkos : public PairVashishta { typedef typename tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; typedef typename tdual_int_3d::t_host t_host_int_3d; - t_int_3d_randomread d_elem2param; + t_int_3d_randomread d_elem3param; typename AT::t_int_1d_randomread d_map; typedef Kokkos::DualView tdual_param_1d; 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/MANYBODY/pair_adp.cpp b/src/MANYBODY/pair_adp.cpp index aa11e0682a..59afbc280b 100644 --- a/src/MANYBODY/pair_adp.cpp +++ b/src/MANYBODY/pair_adp.cpp @@ -45,7 +45,6 @@ PairADP::PairADP(LAMMPS *lmp) : Pair(lmp) fp = nullptr; mu = nullptr; lambda = nullptr; - map = nullptr; setfl = nullptr; @@ -86,7 +85,6 @@ PairADP::~PairADP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] type2frho; memory->destroy(type2rhor); memory->destroy(type2z2r); diff --git a/src/MANYBODY/pair_adp.h b/src/MANYBODY/pair_adp.h index 65596113ba..6a292dda14 100644 --- a/src/MANYBODY/pair_adp.h +++ b/src/MANYBODY/pair_adp.h @@ -67,8 +67,6 @@ class PairADP : public Pair { // potentials as file data - int *map; // which element each atom type maps to - struct Setfl { char **elements; int nelements,nrho,nr; diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index be4f17b291..a8f64853bc 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -69,7 +69,6 @@ PairBOP::PairBOP(LAMMPS *lmp) : Pair(lmp) BOP_index3 = nullptr; BOP_total = nullptr; BOP_total3 = nullptr; - map = nullptr; pi_a = nullptr; pro_delta = nullptr; pi_delta = nullptr; @@ -184,7 +183,6 @@ PairBOP::~PairBOP() if (allocated) { memory_theta_destroy(); if (otfly==0) memory->destroy(cos_index); - delete [] map; memory->destroy(BOP_index); memory->destroy(BOP_total); @@ -620,11 +618,6 @@ void PairBOP::coeff(int narg, char **arg) if (narg != 3 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - // ensure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - // read the potential file nr=2000; nBOt=2000; @@ -657,6 +650,7 @@ void PairBOP::coeff(int narg, char **arg) if (elements) { for (i = 0; i < bop_types; i++) delete [] elements[i]; delete [] elements; + elements = nullptr; } } // clear setflag since coeff() called once with I,J = * * @@ -4922,10 +4916,7 @@ void _noopt PairBOP::read_table(char *filename) ValueTokenizer values = reader.next_values(3); values.next_int(); values.next_double(); - std::string name = values.next_string(); - - elements[i] = new char[name.length()+1]; - strcpy(elements[i], name.c_str()); + elements[i] = utils::strdup(values.next_string()); } ValueTokenizer values = reader.next_values(2); diff --git a/src/MANYBODY/pair_bop.h b/src/MANYBODY/pair_bop.h index d61c969094..ba75d5c591 100644 --- a/src/MANYBODY/pair_bop.h +++ b/src/MANYBODY/pair_bop.h @@ -46,17 +46,12 @@ class PairBOP : public Pair { int update_list; // check for changing maximum size of neighbor list int maxbopn; // maximum size of bop neighbor list for allocation int maxnall; // maximum size of bop neighbor list for allocation - int *map; // mapping from atom types to elements - int nelements; // # of unique elements int nr; // increments for the BOP pair potential int ntheta; // increments for the angle function int npower; // power of the angular function int nBOt; // second BO increments int bop_types; // number of elements in potential int npairs; // number of element pairs - char **elements; // names of unique elements - int ***elem2param; - int nparams; int bop_step; int allocate_neigh; int nb_pi,nb_sg; diff --git a/src/MANYBODY/pair_comb.cpp b/src/MANYBODY/pair_comb.cpp index 2d93c6783e..a1fc65deb7 100644 --- a/src/MANYBODY/pair_comb.cpp +++ b/src/MANYBODY/pair_comb.cpp @@ -62,12 +62,7 @@ PairComb::PairComb(LAMMPS *lmp) : Pair(lmp) map = nullptr; esm = nullptr; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; intype = nullptr; fafb = nullptr; @@ -97,12 +92,8 @@ PairComb::~PairComb() { memory->destroy(NCo); - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(intype); memory->destroy(fafb); @@ -120,7 +111,6 @@ PairComb::~PairComb() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] esm; } } @@ -184,7 +174,7 @@ void PairComb::compute(int eflag, int vflag) iq = q[i]; NCo[i] = 0; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom @@ -223,7 +213,7 @@ void PairComb::compute(int eflag, int vflag) dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -282,7 +272,7 @@ void PairComb::compute(int eflag, int vflag) for (jj = 0; jj < sht_jnum; jj++) { j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (params[iparam_ij].hfocor > 0.0) { delr1[0] = x[j][0] - xtmp; @@ -303,7 +293,7 @@ void PairComb::compute(int eflag, int vflag) j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // this Qj for q-dependent BSi @@ -326,7 +316,7 @@ void PairComb::compute(int eflag, int vflag) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -370,7 +360,7 @@ void PairComb::compute(int eflag, int vflag) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -445,54 +435,15 @@ void PairComb::settings(int narg, char **/*arg*/) void PairComb::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - // generate streitz-mintmire direct 1/r energy look-up table if (comm->me == 0 && screen) @@ -506,24 +457,6 @@ void PairComb::coeff(int narg, char **arg) else fputs(" will not apply over-coordination correction ...\n",screen); } - - // clear setflag since coeff() called once with I,J = * * - - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -741,12 +674,12 @@ void PairComb::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -760,7 +693,7 @@ void PairComb::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs @@ -1403,7 +1336,7 @@ void PairComb::sm_table() if (map[i+1] < 0) continue; r = drin; itype = params[map[i+1]].ielement; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm1; if (comm->me == 0 && screen) @@ -1425,7 +1358,7 @@ void PairComb::sm_table() if (j == i) { itype = params[map[i+1]].ielement; inty = intype[itype][itype]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm1; zrc = z * rc; exp2ersh = exp(-2.0 * zrc); @@ -1451,10 +1384,10 @@ void PairComb::sm_table() itype = params[map[i+1]].ielement; jtype = params[map[j+1]].ielement; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; ea = params[iparam_ij].esm1; ea3 = ea*ea*ea; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ji = elem3param[jtype][itype][itype]; eb = params[iparam_ji].esm1; eb3 = eb*eb*eb; E1 = ea*eb3*eb/((ea+eb)*(ea+eb)*(ea-eb)*(ea-eb)); @@ -1672,7 +1605,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) ytmp = x[i][1]; ztmp = x[i][2]; iq = q[i]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // charge force from self energy @@ -1706,7 +1639,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; rsq1 = dot3(delr1,delr1); - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -1743,7 +1676,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; rsq1 = dot3(delr1,delr1); - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/MANYBODY/pair_comb.h b/src/MANYBODY/pair_comb.h index c127bc0543..51b522badf 100644 --- a/src/MANYBODY/pair_comb.h +++ b/src/MANYBODY/pair_comb.h @@ -62,12 +62,6 @@ class PairComb : public Pair { }; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double precision; Param *params; // parameter set for an I-J-K interaction diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index d7814737ea..a0fa3b96b6 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -63,12 +63,7 @@ PairComb3::PairComb3(LAMMPS *lmp) : Pair(lmp) map = nullptr; esm = nullptr; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; intype = nullptr; afb = nullptr; @@ -107,12 +102,8 @@ PairComb3::~PairComb3() { memory->destroy(NCo); - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(afb); memory->destroy(dpl); @@ -139,7 +130,6 @@ PairComb3::~PairComb3() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; delete [] esm; } @@ -184,78 +174,31 @@ void PairComb3::settings(int narg, char **arg) void PairComb3::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + cflag = 0; + for (int i = 3; i < narg; i++) + if (strcmp(arg[i],"C") == 0) { + cflag = 1; + break; + } - // insure I,J args are * * - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if ((strcmp(arg[i],"C") == 0) && (cflag == 0)) { - if (comm->me == 0 && screen) - fputs(" PairComb3: Found C: reading additional library file\n",screen); + if (cflag) { + if (comm->me == 0 && screen) + fputs(" PairComb3: Found C: reading additional library file\n",screen); read_lib(); - cflag = 1; - } - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } } + map_element2type(narg-3,arg+3); + // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - // generate Wolf 1/r energy and van der Waals look-up tables + tables(); - - // clear setflag since coeff() called once with I,J = * * - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - } /* ---------------------------------------------------------------------- @@ -687,12 +630,12 @@ void PairComb3::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -706,7 +649,7 @@ void PairComb3::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs @@ -804,7 +747,7 @@ void PairComb3::Short_neigh() delrj[2] = x[i][2] - x[j][2]; rsq1 = dot3(delrj,delrj); jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > cutmin) continue; @@ -928,8 +871,8 @@ void PairComb3::compute(int eflag, int vflag) delrj[2] = x[j][2] - ztmp; rsq = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq > params[iparam_ij].lcutsq) continue; @@ -950,7 +893,7 @@ void PairComb3::compute(int eflag, int vflag) ztmp = x[i][2]; iq = q[i]; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom yaself = self(¶ms[iparam_i],iq); @@ -991,8 +934,8 @@ void PairComb3::compute(int eflag, int vflag) dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq > params[iparam_ij].lcutsq) continue; @@ -1091,8 +1034,8 @@ void PairComb3::compute(int eflag, int vflag) ycn = NCo[j]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; delrj[0] = x[j][0] - xtmp; delrj[1] = x[j][1] - ytmp; @@ -1114,10 +1057,10 @@ void PairComb3::compute(int eflag, int vflag) if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; - iparam_ikj = elem2param[itype][ktype][jtype]; - iparam_jik = elem2param[jtype][itype][ktype]; - iparam_ik = elem2param[itype][ktype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; + iparam_ikj = elem3param[itype][ktype][jtype]; + iparam_jik = elem3param[jtype][itype][ktype]; + iparam_ik = elem3param[itype][ktype][ktype]; delrk[0] = x[k][0] - xtmp; delrk[1] = x[k][1] - ytmp; delrk[2] = x[k][2] - ztmp; @@ -1133,7 +1076,7 @@ void PairComb3::compute(int eflag, int vflag) if (params[iparam_ij].rad_flag > 0 && params[iparam_ik].ielementgp == 1 && params[iparam_ik].jelementgp == 1) { - iparam_ki = elem2param[ktype][itype][itype]; + iparam_ki = elem3param[ktype][itype][itype]; kcn=NCo[k]; kconjug += rad_init(rsq2,¶ms[iparam_ki],i,kradtot,kcn); @@ -1157,11 +1100,11 @@ void PairComb3::compute(int eflag, int vflag) delrl[1] = x[l][1] - x[j][1]; delrl[2] = x[l][2] - x[j][2]; rsq3 = dot3(delrl,delrl); - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; if (rsq3 > params[iparam_jl].cutsq) continue; - iparam_ikl = elem2param[itype][ktype][ltype]; + iparam_ikl = elem3param[itype][ktype][ltype]; torindx = params[iparam_ij].tor_flag; bbtor += bbtor1(torindx, ¶ms[iparam_ikl],¶ms[iparam_jl], rsq1,rsq2,rsq3,delrj,delrk,delrl,srmu); @@ -1178,10 +1121,10 @@ void PairComb3::compute(int eflag, int vflag) if (l == i) continue; ltype = map[type[l]]; - iparam_jil = elem2param[jtype][itype][ltype]; - iparam_ijl = elem2param[itype][jtype][ltype]; - iparam_jl = elem2param[jtype][ltype][ltype]; - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_jil = elem3param[jtype][itype][ltype]; + iparam_ijl = elem3param[itype][jtype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; + iparam_lj = elem3param[ltype][jtype][jtype]; delrk[0] = x[l][0] - x[j][0]; delrk[1] = x[l][1] - x[j][1]; @@ -1204,7 +1147,7 @@ void PairComb3::compute(int eflag, int vflag) if (params[iparam_ji].rad_flag > 0 && params[iparam_jl].ielementgp == 1 && params[iparam_jl].jelementgp == 1) { - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_lj = elem3param[ltype][jtype][jtype]; lcn=NCo[l]; lconjug += rad_init(rsq2,¶ms[iparam_lj],j,lradtot,lcn); } @@ -1240,10 +1183,10 @@ void PairComb3::compute(int eflag, int vflag) sht_mnum = sht_num[k]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; - iparam_ikj = elem2param[itype][ktype][jtype]; - iparam_jik = elem2param[jtype][itype][ktype]; - iparam_ik = elem2param[itype][ktype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; + iparam_ikj = elem3param[itype][ktype][jtype]; + iparam_jik = elem3param[jtype][itype][ktype]; + iparam_ik = elem3param[itype][ktype][ktype]; delrk[0] = x[k][0] - xtmp; delrk[1] = x[k][1] - ytmp; delrk[2] = x[k][2] - ztmp; @@ -1289,9 +1232,9 @@ void PairComb3::compute(int eflag, int vflag) delrl[2] = x[l][2] - x[j][2]; rsq3 = dot3(delrl,delrl); - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; if (rsq3 > params[iparam_jl].cutsq) continue; - iparam_ikl = elem2param[itype][ktype][ltype]; + iparam_ikl = elem3param[itype][ktype][ltype]; torindx = params[iparam_ij].tor_flag; tor_force(torindx, ¶ms[iparam_ikl], ¶ms[iparam_jl],srmu, rsq1,rsq2,rsq3,delrj,delrk,delrl); @@ -1309,7 +1252,7 @@ void PairComb3::compute(int eflag, int vflag) if ( params[iparam_ijk].rad_flag>=1 && params[iparam_ijk].ielementgp==1 && params[iparam_ijk].kelementgp==1) { - iparam_ki = elem2param[ktype][itype][itype]; + iparam_ki = elem3param[ktype][itype][itype]; kcn=NCo[k]; double rik=sqrt(rsq2); kradtot = -comb_fc(rik,¶ms[iparam_ki])*params[iparam_ki].pcross+kcn; @@ -1333,8 +1276,8 @@ void PairComb3::compute(int eflag, int vflag) delrm[2] = x[m][2] - x[k][2]; rsq3 = dot3(delrm,delrm); - iparam_km = elem2param[ktype][mtype][mtype]; - iparam_ki = elem2param[ktype][itype][itype]; + iparam_km = elem3param[ktype][mtype][mtype]; + iparam_ki = elem3param[ktype][itype][itype]; if (rsq3 > params[iparam_km].cutsq) continue; @@ -1364,10 +1307,10 @@ void PairComb3::compute(int eflag, int vflag) sht_pnum = sht_num[l]; ltype = map[type[l]]; - iparam_jil = elem2param[jtype][itype][ltype]; - iparam_jli = elem2param[jtype][ltype][itype]; - iparam_ijl = elem2param[itype][jtype][ltype]; - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jil = elem3param[jtype][itype][ltype]; + iparam_jli = elem3param[jtype][ltype][itype]; + iparam_ijl = elem3param[itype][jtype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; delrk[0] = x[l][0] - x[j][0]; delrk[1] = x[l][1] - x[j][1]; delrk[2] = x[l][2] - x[j][2]; @@ -1405,7 +1348,7 @@ void PairComb3::compute(int eflag, int vflag) if ( params[iparam_jil].rad_flag >= 1 && params[iparam_jil].ielementgp == 1 && params[iparam_jil].kelementgp == 1) { - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_lj = elem3param[ltype][jtype][jtype]; lcn=NCo[l]; double rjl=sqrt(rsq2); lradtot=-comb_fc(rjl,¶ms[iparam_lj])*params[iparam_lj].pcross +lcn; @@ -1428,7 +1371,7 @@ void PairComb3::compute(int eflag, int vflag) delrp[2] = x[p][2] - x[l][2]; rsq3 = dot3(delrp,delrp); - iparam_lp = elem2param[ltype][ptype][ptype]; + iparam_lp = elem3param[ltype][ptype][ptype]; if (rsq3 > params[iparam_lp].cutsq) continue; @@ -2354,7 +2297,7 @@ void PairComb3::tables() if (map[i+1] < 0) continue; r = drin - dra; itype = map[i+1]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm; exp2ershift = exp(-2.0*z*rc); afbshift = -exp2ershift*(z+1.0/rc); @@ -2381,7 +2324,7 @@ void PairComb3::tables() if (j == i) { itype = map[i+1]; inty = intype[itype][itype]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm; zrc = z * rc; exp2ersh = exp(-2.0 * zrc); @@ -2407,10 +2350,10 @@ void PairComb3::tables() itype = map[i+1]; jtype = map[j+1]; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; ea = params[iparam_ij].esm; ea3 = ea*ea*ea; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ji = elem3param[jtype][itype][itype]; eb = params[iparam_ji].esm; eb3 = eb*eb*eb; E1 = ea*eb3*eb/((ea+eb)*(ea+eb)*(ea-eb)*(ea-eb)); @@ -2474,7 +2417,7 @@ void PairComb3::tables() itype = ii; jtype = jj; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // parameter check: eps > 0 if (params[iparam_ij].vdwflag > 0) { @@ -2521,7 +2464,7 @@ void PairComb3::tables() itype = ii; jtype = jj; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; r = drin; for (k = 0; k < ncoul; k ++) { r6 = r*r*r*r*r*r; @@ -3229,7 +3172,7 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) ytmp = x[i][1]; ztmp = x[i][2]; iq = q[i]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // charge force from self energy fqi = qfo_self(¶ms[iparam_i],iq); @@ -3257,8 +3200,8 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) delrj[2] = ztmp - x[j][2]; rsq1 = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; // long range q-dependent @@ -3304,8 +3247,8 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) delrj[2] = ztmp - x[j][2]; rsq1 = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq1 >= params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/MANYBODY/pair_comb3.h b/src/MANYBODY/pair_comb3.h index b999d2cece..d03ee0e474 100644 --- a/src/MANYBODY/pair_comb3.h +++ b/src/MANYBODY/pair_comb3.h @@ -61,16 +61,10 @@ class PairComb3 : public Pair { }; // general setups - int nelements; // # of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double PI,PI2,PI4,PIsq; // PIs double cutmin; // min cutoff for all elements double cutmax; // max cutoff for all elements double precision; // tolerance for QEq convergence - char **elements; // names of unique elements Param *params; // parameter set for an I-J-K interaction int debug_eng1, debug_eng2, debug_fq; // logic controlling debugging outputs int pack_flag; diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index 03098904c8..b5fd507687 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -49,7 +49,6 @@ PairEAM::PairEAM(LAMMPS *lmp) : Pair(lmp) rho = nullptr; fp = nullptr; numforce = nullptr; - map = nullptr; type2frho = nullptr; nfuncfl = 0; @@ -90,9 +89,7 @@ PairEAM::~PairEAM() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] type2frho; - map = nullptr; type2frho = nullptr; memory->destroy(type2rhor); memory->destroy(type2z2r); @@ -348,6 +345,7 @@ void PairEAM::allocate() memory->create(cutsq,n+1,n+1,"pair:cutsq"); + delete[] map; map = new int[n+1]; for (int i = 1; i <= n; i++) map[i] = -1; diff --git a/src/MANYBODY/pair_eam.h b/src/MANYBODY/pair_eam.h index 7e47c0f4e9..e9cbd15f34 100644 --- a/src/MANYBODY/pair_eam.h +++ b/src/MANYBODY/pair_eam.h @@ -75,8 +75,6 @@ class PairEAM : public Pair { // potentials as file data - int *map; // which element each atom type maps to - struct Funcfl { char *file; int nrho,nr; diff --git a/src/MANYBODY/pair_eim.cpp b/src/MANYBODY/pair_eim.cpp index b82a410791..eda1838a5a 100644 --- a/src/MANYBODY/pair_eim.cpp +++ b/src/MANYBODY/pair_eim.cpp @@ -46,10 +46,6 @@ PairEIM::PairEIM(LAMMPS *lmp) : Pair(lmp) nmax = 0; rho = nullptr; fp = nullptr; - map = nullptr; - - nelements = 0; - elements = nullptr; negativity = nullptr; q0 = nullptr; @@ -80,15 +76,11 @@ PairEIM::~PairEIM() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; memory->destroy(type2Fij); memory->destroy(type2Gij); memory->destroy(type2phiij); } - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - deallocate_setfl(); delete [] negativity; @@ -353,8 +345,6 @@ void PairEIM::settings(int narg, char **/*arg*/) void PairEIM::coeff(int narg, char **arg) { - int i,j,m,n; - if (!allocated) allocate(); if (narg < 5) error->all(FLERR,"Incorrect args for pair coefficients"); @@ -364,23 +354,8 @@ void PairEIM::coeff(int narg, char **arg) if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // read EIM element names before filename - // nelements = # of EIM elements to read from file - // elements = list of unique element names - - if (nelements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - nelements = narg - 3 - atom->ntypes; - if (nelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); - elements = new char*[nelements]; - - for (i = 0; i < nelements; i++) { - n = strlen(arg[i+2]) + 1; - elements[i] = new char[n]; - strcpy(elements[i],arg[i+2]); - } + const int ntypes = atom->ntypes; + map_element2type(ntypes,arg+(narg-ntypes)); // read EIM file @@ -388,38 +363,12 @@ void PairEIM::coeff(int narg, char **arg) setfl = new Setfl(); read_file(arg[2+nelements]); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" + // set per-type atomic masses - for (i = 3 + nelements; i < narg; i++) { - m = i - (3+nelements) + 1; - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - if (j < nelements) map[m] = j; - else if (strcmp(arg[i],"NULL") == 0) map[m] = -1; - else error->all(FLERR,"Incorrect args for pair coefficients"); - } - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - // set mass of atom type if i = j - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; + for (int i = 1; i <= ntypes; i++) + for (int j = i; j <= ntypes; j++) + if ((map[i] >= 0) && (map[j] >= 0)) if (i == j) atom->set_mass(FLERR,i,setfl->mass[map[i]]); - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_eim.h b/src/MANYBODY/pair_eim.h index 75f8ea6bea..7611898c45 100644 --- a/src/MANYBODY/pair_eim.h +++ b/src/MANYBODY/pair_eim.h @@ -60,10 +60,6 @@ class PairEIM : public Pair { int nmax; double *rho,*fp; int rhofp; - int *map; // which element each atom type maps to - - int nelements; // # of elements to read from potential file - char **elements; // element names Setfl *setfl; diff --git a/src/MANYBODY/pair_gw.cpp b/src/MANYBODY/pair_gw.cpp index 6039e00c0a..7e0cb3a3a2 100644 --- a/src/MANYBODY/pair_gw.cpp +++ b/src/MANYBODY/pair_gw.cpp @@ -51,12 +51,7 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; } /* ---------------------------------------------------------------------- @@ -65,16 +60,12 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) PairGW::~PairGW() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -142,7 +133,7 @@ void PairGW::compute(int eflag, int vflag) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,eflag,evdwl); @@ -165,7 +156,7 @@ void PairGW::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -182,7 +173,7 @@ void PairGW::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -214,7 +205,7 @@ void PairGW::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -271,70 +262,14 @@ void PairGW::settings(int narg, char **/*arg*/) void PairGW::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -480,12 +415,12 @@ void PairGW::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -500,7 +435,7 @@ void PairGW::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_gw.h b/src/MANYBODY/pair_gw.h index 620f0b1af0..a1cbdb5c86 100644 --- a/src/MANYBODY/pair_gw.h +++ b/src/MANYBODY/pair_gw.h @@ -52,13 +52,7 @@ class PairGW : public Pair { }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to paramegw - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int **pages; // neighbor list pages int maxlocal; // size of numneigh, firstneigh arrays diff --git a/src/MANYBODY/pair_lcbop.cpp b/src/MANYBODY/pair_lcbop.cpp index a2a8c3d1fa..727556dd50 100644 --- a/src/MANYBODY/pair_lcbop.cpp +++ b/src/MANYBODY/pair_lcbop.cpp @@ -74,8 +74,6 @@ PairLCBOP::~PairLCBOP() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - - delete [] map; } } @@ -128,48 +126,17 @@ void PairLCBOP::coeff(int narg, char **arg) { if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + map_element2type(narg-3,arg+3); - // insure I,J args are * * + // only element "C" is allowed - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to C and "NULL" - // map[i] = which element (0 for C) the Ith atom type is, -1 if "NULL" - - for (int i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - } else if (strcmp(arg[i],"C") == 0) { - map[i-2] = 0; - } else error->all(FLERR,"Incorrect args for pair coefficients"); - } + if ((nelements != 1) || (strcmp(elements[0],"C") != 0)) + error->all(FLERR,"Incorrect args for pair coefficients"); // read potential file and initialize fitting splines read_file(arg[2]); spline_init(); - - // clear setflag since coeff() called once with I,J = * * - - int n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -965,11 +932,9 @@ void PairLCBOP::read_file(char *filename) int i,k,l; char s[MAXLINE]; - MPI_Comm_rank(world,&me); - // read file on proc 0 - if (me == 0) { + if (comm->me == 0) { FILE *fp = utils::open_potential(filename,lmp,nullptr); if (fp == nullptr) { char str[128]; diff --git a/src/MANYBODY/pair_lcbop.h b/src/MANYBODY/pair_lcbop.h index dacbe74158..4ee89b4148 100644 --- a/src/MANYBODY/pair_lcbop.h +++ b/src/MANYBODY/pair_lcbop.h @@ -39,9 +39,6 @@ class PairLCBOP : public Pair { protected: int **pages; // neighbor list pages - int *map; // 0 (C) or -1 ("NULL") for each type - - int me; double cutLR; // LR cutoff diff --git a/src/MANYBODY/pair_nb3b_harmonic.cpp b/src/MANYBODY/pair_nb3b_harmonic.cpp index a1dc903a43..dfc4046eda 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.cpp +++ b/src/MANYBODY/pair_nb3b_harmonic.cpp @@ -50,12 +50,7 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; } /* ---------------------------------------------------------------------- @@ -64,16 +59,12 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) PairNb3bHarmonic::~PairNb3bHarmonic() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -117,7 +108,7 @@ void PairNb3bHarmonic::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -128,8 +119,8 @@ void PairNb3bHarmonic::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -186,70 +177,14 @@ void PairNb3bHarmonic::settings(int narg, char **/*arg*/) void PairNb3bHarmonic::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } @@ -374,12 +309,12 @@ void PairNb3bHarmonic::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -393,7 +328,7 @@ void PairNb3bHarmonic::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/MANYBODY/pair_nb3b_harmonic.h b/src/MANYBODY/pair_nb3b_harmonic.h index b68974e15f..38ec07c78b 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.h +++ b/src/MANYBODY/pair_nb3b_harmonic.h @@ -44,12 +44,6 @@ class PairNb3bHarmonic : public Pair { }; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/MANYBODY/pair_polymorphic.cpp b/src/MANYBODY/pair_polymorphic.cpp index a353ad1c47..e267031901 100644 --- a/src/MANYBODY/pair_polymorphic.cpp +++ b/src/MANYBODY/pair_polymorphic.cpp @@ -49,14 +49,11 @@ PairPolymorphic::PairPolymorphic(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; match = nullptr; pairParameters = nullptr; tripletParameters = nullptr; elem2param = nullptr; elem3param = nullptr; - map = nullptr; epsilon = 0.0; neighsize = 0; firstneighV = nullptr; @@ -78,9 +75,6 @@ PairPolymorphic::PairPolymorphic(LAMMPS *lmp) : Pair(lmp) PairPolymorphic::~PairPolymorphic() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; delete [] match; delete [] pairParameters; @@ -91,7 +85,6 @@ PairPolymorphic::~PairPolymorphic() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] firstneighV; delete [] firstneighW; delete [] firstneighW1; @@ -466,74 +459,19 @@ void PairPolymorphic::settings(int narg, char **/*arg*/) void PairPolymorphic::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg == 4 + atom->ntypes) { - narg--; - epsilon = atof(arg[narg]); - } else if (narg != 3 + atom->ntypes) { - error->all(FLERR,"Incorrect args for pair coefficients"); - } + // parse and remove optional last parameter - // insure I,J args are * * + if (narg == 4 + atom->ntypes) + epsilon = utils::numeric(FLERR,arg[--narg],false,lmp); - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_polymorphic.h b/src/MANYBODY/pair_polymorphic.h index c94acd6230..a8a74267cd 100644 --- a/src/MANYBODY/pair_polymorphic.h +++ b/src/MANYBODY/pair_polymorphic.h @@ -302,13 +302,8 @@ class PairPolymorphic : public Pair { double *delxV,*delyV,*delzV,*drV; double *delxW,*delyW,*delzW,*drW; - char **elements; // names of unique elements - int **elem2param; // map: element pairs to parameters - int ***elem3param; // map: element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements double cutmaxsq; - int nelements; // # of unique elements int npair,ntriple; int *match; diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index e7a334d9a9..fe7e56456e 100644 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -46,12 +46,7 @@ PairSW::PairSW(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; maxshort = 10; neighshort = nullptr; @@ -65,17 +60,13 @@ PairSW::~PairSW() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -135,7 +126,7 @@ void PairSW::compute(int eflag, int vflag) rsq = delx*delx + dely*dely + delz*delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) { continue; } else { @@ -175,7 +166,7 @@ void PairSW::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -187,8 +178,8 @@ void PairSW::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -250,70 +241,14 @@ void PairSW::settings(int narg, char **/*arg*/) void PairSW::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -451,12 +386,12 @@ void PairSW::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -470,7 +405,7 @@ void PairSW::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_sw.h b/src/MANYBODY/pair_sw.h index 4fdc538430..4e13caee85 100644 --- a/src/MANYBODY/pair_sw.h +++ b/src/MANYBODY/pair_sw.h @@ -50,12 +50,6 @@ class PairSW : public Pair { protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction int maxshort; // size of short neighbor list array int *neighshort; // short neighbor list array diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index dea01589a6..2a642e6244 100644 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -54,12 +54,7 @@ PairTersoff::PairTersoff(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; maxshort = 10; neighshort = nullptr; @@ -73,17 +68,13 @@ PairTersoff::~PairTersoff() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -204,7 +195,7 @@ void PairTersoff::eval() } jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq >= params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -231,7 +222,7 @@ void PairTersoff::eval() for (jj = 0; jj < numshort; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -255,7 +246,7 @@ void PairTersoff::eval() if (jj == kk) continue; k = neighshort[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -295,7 +286,7 @@ void PairTersoff::eval() if (jj == kk) continue; k = neighshort[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -383,70 +374,14 @@ void PairTersoff::settings(int narg, char **arg) void PairTersoff::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -598,12 +533,12 @@ void PairTersoff::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -617,7 +552,7 @@ void PairTersoff::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_tersoff.h b/src/MANYBODY/pair_tersoff.h index 18c6ebc5f9..a4612d03be 100644 --- a/src/MANYBODY/pair_tersoff.h +++ b/src/MANYBODY/pair_tersoff.h @@ -59,13 +59,7 @@ class PairTersoff : public Pair { }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int maxshort; // size of short neighbor list array int *neighshort; // short neighbor list array diff --git a/src/MANYBODY/pair_tersoff_mod.cpp b/src/MANYBODY/pair_tersoff_mod.cpp index 86994ccc0e..465bc0ebd0 100644 --- a/src/MANYBODY/pair_tersoff_mod.cpp +++ b/src/MANYBODY/pair_tersoff_mod.cpp @@ -163,12 +163,12 @@ void PairTersoffMOD::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -182,7 +182,7 @@ void PairTersoffMOD::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_vashishta.cpp b/src/MANYBODY/pair_vashishta.cpp index 94f211dd95..cacfa7078e 100644 --- a/src/MANYBODY/pair_vashishta.cpp +++ b/src/MANYBODY/pair_vashishta.cpp @@ -48,12 +48,7 @@ PairVashishta::PairVashishta(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; r0max = 0.0; maxshort = 10; @@ -68,17 +63,13 @@ PairVashishta::~PairVashishta() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -158,7 +149,7 @@ void PairVashishta::compute(int eflag, int vflag) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody(¶ms[ijparam],rsq,fpair,eflag,evdwl); @@ -179,7 +170,7 @@ void PairVashishta::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -192,8 +183,8 @@ void PairVashishta::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -257,70 +248,14 @@ void PairVashishta::settings(int narg, char **/*arg*/) void PairVashishta::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -465,12 +400,12 @@ void PairVashishta::setup_params() { int i,j,k,m,n; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -484,7 +419,7 @@ void PairVashishta::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/MANYBODY/pair_vashishta.h b/src/MANYBODY/pair_vashishta.h index 19a8e01cd9..06c23b2384 100644 --- a/src/MANYBODY/pair_vashishta.h +++ b/src/MANYBODY/pair_vashishta.h @@ -48,12 +48,6 @@ class PairVashishta : public Pair { }; protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction double r0max; // largest value of r0 int maxshort; // size of short neighbor list array diff --git a/src/MANYBODY/pair_vashishta_table.cpp b/src/MANYBODY/pair_vashishta_table.cpp index 76b44d8664..14dacdae3f 100644 --- a/src/MANYBODY/pair_vashishta_table.cpp +++ b/src/MANYBODY/pair_vashishta_table.cpp @@ -120,7 +120,7 @@ void PairVashishtaTable::compute(int eflag, int vflag) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody_table(params[ijparam],rsq,fpair,eflag,evdwl); @@ -141,7 +141,7 @@ void PairVashishtaTable::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -154,8 +154,8 @@ void PairVashishtaTable::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -272,7 +272,7 @@ void PairVashishtaTable::create_tables() for (i = 0; i < nelements; i++) { for (j = 0; j < nelements; j++) { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; for (idx = 0; idx <= ntable; idx++) { rsq = tabinnersq + idx*deltaR2; PairVashishta::twobody(¶ms[ijparam],rsq,fpair,1,eng); 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..1f3026888a 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; @@ -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 @@ -642,9 +639,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/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/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..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; @@ -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(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/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 414e408a9a..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; @@ -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(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/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index e50b1a5045..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; @@ -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(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/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index efb9c414f6..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; @@ -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(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/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..20038c7df6 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(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; // 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(fmt::format("{} all pe",id_pe)); peflag = 1; } diff --git a/src/SNAP/pair_snap.cpp b/src/SNAP/pair_snap.cpp index 7d57ca3673..ae0023ddec 100644 --- a/src/SNAP/pair_snap.cpp +++ b/src/SNAP/pair_snap.cpp @@ -42,8 +42,6 @@ PairSNAP::PairSNAP(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; radelem = nullptr; wjelem = nullptr; coeffelem = nullptr; @@ -60,14 +58,9 @@ PairSNAP::~PairSNAP() { if (copymode) return; - if (nelements) { - for (int i = 0; i < nelements; i++) - delete[] elements[i]; - delete[] elements; - memory->destroy(radelem); - memory->destroy(wjelem); - memory->destroy(coeffelem); - } + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(coeffelem); memory->destroy(beta); memory->destroy(bispectrum); @@ -77,7 +70,6 @@ PairSNAP::~PairSNAP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - memory->destroy(map); } } @@ -362,7 +354,7 @@ void PairSNAP::allocate() memory->create(setflag,n+1,n+1,"pair:setflag"); memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(map,n+1,"pair:map"); + map = new int[n+1]; } /* ---------------------------------------------------------------------- @@ -384,61 +376,11 @@ void PairSNAP::coeff(int narg, char **arg) if (!allocated) allocate(); if (narg != 4 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - char* type1 = arg[0]; - char* type2 = arg[1]; - char* coefffilename = arg[2]; - char* paramfilename = arg[3]; - char** elemtypes = &arg[4]; - - // insure I,J args are * * - - if (strcmp(type1,"*") != 0 || strcmp(type2,"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // clean out old arrays - - if (elements) { - for (int i = 0; i < nelements; i++) - delete[] elements[i]; - delete[] elements; - memory->destroy(radelem); - memory->destroy(wjelem); - memory->destroy(coeffelem); - } - - // nelements = # of unique elements declared - // elements = list of unique element names - // allocate as ntypes >= nelements - - elements = new char*[atom->ntypes]; - for (int i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - // read args that map atom types to SNAP elements - // map[i] = which element the Ith atom type is, -1 if not mapped - // map[0] is not used - - nelements = 0; - for (int i = 1; i <= atom->ntypes; i++) { - char* elemstring = elemtypes[i-1]; - if (strcmp(elemstring,"NULL") == 0) { - map[i] = -1; - continue; - } - int j; - for (j = 0; j < nelements; j++) - if (strcmp(elemstring,elements[j]) == 0) break; - map[i] = j; - if (j == nelements) { - int n = strlen(elemstring) + 1; - elements[j] = new char[n]; - strcpy(elements[j],elemstring); - nelements++; - } - } + map_element2type(narg-4,arg+4); // read snapcoeff and snapparam files - read_files(coefffilename,paramfilename); + read_files(arg[2],arg[3]); if (!quadraticflag) ncoeff = ncoeffall - 1; @@ -455,25 +397,6 @@ void PairSNAP::coeff(int narg, char **arg) } } - // clear setflag since coeff() called once with I,J = * * - - int n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements); @@ -571,8 +494,11 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) "file: {}", e.what())); } - // set up element lists + // clean out old arrays and set up element lists + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(coeffelem); memory->create(radelem,nelements,"pair:radelem"); memory->create(wjelem,nelements,"pair:wjelem"); memory->create(coeffelem,nelements,ncoeffall,"pair:coeffelem"); diff --git a/src/SNAP/pair_snap.h b/src/SNAP/pair_snap.h index d60000da3a..ee596d2ba7 100644 --- a/src/SNAP/pair_snap.h +++ b/src/SNAP/pair_snap.h @@ -50,14 +50,11 @@ protected: void compute_bispectrum(); double rcutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements double *radelem; // element radii double *wjelem; // elements weights double **coeffelem; // element bispectrum coefficients double** beta; // betas for all atoms in list double** bispectrum; // bispectrum components for all atoms in list - int *map; // mapping from atom types to elements int twojmax, switchflag, bzeroflag, bnormflag; int chemflag, wselfallflag; int chunksize; 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 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; 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..60fb03cdf8 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~*/ @@ -1548,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) @@ -1582,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-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/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-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 c9d12506ab..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; @@ -257,7 +255,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 +313,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 +330,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;jj - -#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; @@ -596,9 +595,7 @@ void PairExp6rx::coeff(int narg, char **arg) if (nspecies==0) error->all(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 +604,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 +801,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 +832,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.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 bd720ae138..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; @@ -387,14 +385,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..0d3bf6ed43 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; @@ -172,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-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-INTEL/pair_sw_intel.cpp b/src/USER-INTEL/pair_sw_intel.cpp index 984b2100a3..bc5c40a258 100644 --- a/src/USER-INTEL/pair_sw_intel.cpp +++ b/src/USER-INTEL/pair_sw_intel.cpp @@ -1204,7 +1204,7 @@ void PairSWIntel::pack_force_const(ForceConst &fc, fc.p2e[ii][jj].c5 = 0; fc.p2e[ii][jj].c6 = 0; } else { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; fc.p2[ii][jj].cutsq = params[ijparam].cutsq; fc.p2[ii][jj].cut = params[ijparam].cut; fc.p2[ii][jj].sigma_gamma = params[ijparam].sigma_gamma; @@ -1237,7 +1237,7 @@ void PairSWIntel::pack_force_const(ForceConst &fc, mytypes++; _onetype = ii * tp1 + jj; _onetype3 = ii * tp1 * tp1 + jj * tp1 + kk; - int ijkparam = elem2param[i][j][k]; + int ijkparam = elem3param[i][j][k]; fc.p3[ii][jj][kk].costheta = params[ijkparam].costheta; fc.p3[ii][jj][kk].lambda_epsilon = params[ijkparam].lambda_epsilon; fc.p3[ii][jj][kk].lambda_epsilon2 = params[ijkparam].lambda_epsilon2; diff --git a/src/USER-INTEL/pair_tersoff_intel.cpp b/src/USER-INTEL/pair_tersoff_intel.cpp index 4284309b74..eb3ce562fa 100644 --- a/src/USER-INTEL/pair_tersoff_intel.cpp +++ b/src/USER-INTEL/pair_tersoff_intel.cpp @@ -482,7 +482,7 @@ void PairTersoffIntel::pack_force_const(ForceConst &fc, fc.c_inner_loop[i][0][j].d2 = 1.0; fc.c_inner_loop[0][i][j].d2 = 1.0; for (int k = 1; k < tp1; k++) { - Param * param = ¶ms[elem2param[map[i]][map[j]][map[k]]]; + Param * param = ¶ms[elem3param[map[i]][map[j]][map[k]]]; fc.c_cutoff_inner[i][k][j].cutsq = static_cast(param->cutsq); fc.c_inner_loop[i][j][k].lam3 = static_cast(param->lam3); fc.c_inner_loop[i][j][k].bigr = static_cast(param->bigr); @@ -504,7 +504,7 @@ void PairTersoffIntel::pack_force_const(ForceConst &fc, fc.c_inner[i][j][k].powermint = static_cast(param->powermint); } - Param * param = ¶ms[elem2param[map[i]][map[j]][map[j]]]; + Param * param = ¶ms[elem3param[map[i]][map[j]][map[j]]]; fc.c_cutoff_outer[i][j].cutsq = static_cast(param->cutsq); fc.c_first_loop[i][j].bigr = static_cast(param->bigr); fc.c_first_loop[i][j].bigd = static_cast(param->bigd); 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_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..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" @@ -95,9 +92,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 +100,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 +145,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-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-MEAMC/pair_meamc.cpp b/src/USER-MEAMC/pair_meamc.cpp index 29d81e9516..67ab3522ad 100644 --- a/src/USER-MEAMC/pair_meamc.cpp +++ b/src/USER-MEAMC/pair_meamc.cpp @@ -55,7 +55,7 @@ PairMEAMC::PairMEAMC(LAMMPS *lmp) : Pair(lmp) allocated = 0; - nelements = 0; + nlibelements = 0; meam_inst = new MEAM(memory); scale = nullptr; @@ -78,7 +78,6 @@ PairMEAMC::~PairMEAMC() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(scale); - delete [] map; } } @@ -239,23 +238,23 @@ void PairMEAMC::coeff(int narg, char **arg) error->all(FLERR,"Incorrect args for pair coefficients"); // MEAM element names between 2 filenames - // nelements = # of MEAM elements + // nlibelements = # of MEAM elements // elements = list of unique element names - if (nelements) { - elements.clear(); + if (nlibelements) { + libelements.clear(); mass.clear(); } - nelements = paridx - 3; - if (nelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); - if (nelements > maxelt) + nlibelements = paridx - 3; + if (nlibelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); + if (nlibelements > maxelt) error->all(FLERR,fmt::format("Too many elements extracted from MEAM " "library (current limit: {}). Increase " "'maxelt' in meam.h and recompile.", maxelt)); - for (int i = 0; i < nelements; i++) { - elements.push_back(arg[i+3]); + for (int i = 0; i < nlibelements; i++) { + libelements.push_back(arg[i+3]); mass.push_back(0.0); } @@ -269,12 +268,12 @@ void PairMEAMC::coeff(int narg, char **arg) // read args that map atom types to MEAM elements // map[i] = which element the Ith atom type is, -1 if not mapped - for (int i = 4 + nelements; i < narg; i++) { - m = i - (4+nelements) + 1; + for (int i = 4 + nlibelements; i < narg; i++) { + m = i - (4+nlibelements) + 1; int j; - for (j = 0; j < nelements; j++) - if (elements[j] == arg[i]) break; - if (j < nelements) map[m] = j; + for (j = 0; j < nlibelements; j++) + if (libelements[j] == arg[i]) break; + if (j < nlibelements) map[m] = j; else if (strcmp(arg[i],"NULL") == 0) map[m] = -1; else error->all(FLERR,"Incorrect args for pair coefficients"); } @@ -359,25 +358,25 @@ void PairMEAMC::read_files(const std::string &globalfile, void PairMEAMC::read_global_meamc_file(const std::string &globalfile) { // allocate parameter arrays - std::vector lat(nelements); - std::vector ielement(nelements); - std::vector ibar(nelements); - std::vector z(nelements); - std::vector atwt(nelements); - std::vector alpha(nelements); - std::vector b0(nelements); - std::vector b1(nelements); - std::vector b2(nelements); - std::vector b3(nelements); - std::vector alat(nelements); - std::vector esub(nelements); - std::vector asub(nelements); - std::vector t0(nelements); - std::vector t1(nelements); - std::vector t2(nelements); - std::vector t3(nelements); - std::vector rozero(nelements); - std::vector found(nelements, false); + std::vector lat(nlibelements); + std::vector ielement(nlibelements); + std::vector ibar(nlibelements); + std::vector z(nlibelements); + std::vector atwt(nlibelements); + std::vector alpha(nlibelements); + std::vector b0(nlibelements); + std::vector b1(nlibelements); + std::vector b2(nlibelements); + std::vector b3(nlibelements); + std::vector alat(nlibelements); + std::vector esub(nlibelements); + std::vector asub(nlibelements); + std::vector t0(nlibelements); + std::vector t1(nlibelements); + std::vector t2(nlibelements); + std::vector t3(nlibelements); + std::vector rozero(nlibelements); + std::vector found(nlibelements, false); // open global meamf file on proc 0 @@ -401,9 +400,9 @@ void PairMEAMC::read_global_meamc_file(const std::string &globalfile) // skip if element name isn't in element list int index; - for (index = 0; index < nelements; index++) - if (elements[index] == element) break; - if (index == nelements) continue; + for (index = 0; index < nlibelements; index++) + if (libelements[index] == element) break; + if (index == nlibelements) continue; // skip if element already appeared (technically error in library file, but always ignored) @@ -452,47 +451,47 @@ void PairMEAMC::read_global_meamc_file(const std::string &globalfile) // error if didn't find all elements in file - if (nset != nelements) { + if (nset != nlibelements) { std::string msg = "Did not find all elements in MEAM library file, missing:"; - for (int i = 0; i < nelements; i++) + for (int i = 0; i < nlibelements; i++) if (!found[i]) { msg += " "; - msg += elements[i]; + msg += libelements[i]; } error->one(FLERR,msg); } } // distribute complete parameter sets - MPI_Bcast(lat.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(ielement.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(ibar.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(z.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(atwt.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(alpha.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b0.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b1.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b2.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b3.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(alat.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(esub.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(asub.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t0.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t1.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t2.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t3.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(rozero.data(), nelements, MPI_DOUBLE, 0, world); + MPI_Bcast(lat.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(ielement.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(ibar.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(z.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(atwt.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(alpha.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b0.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b1.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b2.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b3.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(alat.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(esub.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(asub.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t0.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t1.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t2.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t3.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(rozero.data(), nlibelements, MPI_DOUBLE, 0, world); // pass element parameters to MEAM package - meam_inst->meam_setup_global(nelements, lat.data(), ielement.data(), atwt.data(), + meam_inst->meam_setup_global(nlibelements, lat.data(), ielement.data(), atwt.data(), alpha.data(), b0.data(), b1.data(), b2.data(), b3.data(), alat.data(), esub.data(), asub.data(), t0.data(), t1.data(), t2.data(), t3.data(), rozero.data(), ibar.data()); // set element masses - for (int i = 0; i < nelements; i++) mass[i] = atwt[i]; + for (int i = 0; i < nlibelements; i++) mass[i] = atwt[i]; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MEAMC/pair_meamc.h b/src/USER-MEAMC/pair_meamc.h index 6bf6923869..24625c4076 100644 --- a/src/USER-MEAMC/pair_meamc.h +++ b/src/USER-MEAMC/pair_meamc.h @@ -47,12 +47,11 @@ class PairMEAMC : public Pair { private: class MEAM *meam_inst; - double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - std::vector elements; // names of unique elements - std::vector mass; // mass of each element + double cutmax; // max cutoff for all elements + int nlibelements; // # of library elements + std::vector libelements; // names of library elements + std::vector mass; // mass of library element - int *map; // mapping from atom types (1-indexed) to elements (1-indexed) double **scale; // scaling factor for adapt void allocate(); 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]); } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index 30e6192275..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 @@ -1183,10 +1141,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) @@ -1281,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(); }; } 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-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/pair_agni.cpp b/src/USER-MISC/pair_agni.cpp index 7481ca35d4..7acaf90e4f 100644 --- a/src/USER-MISC/pair_agni.cpp +++ b/src/USER-MISC/pair_agni.cpp @@ -67,12 +67,7 @@ PairAGNI::PairAGNI(LAMMPS *lmp) : Pair(lmp) no_virial_fdotr_compute = 1; - nelements = 0; - elements = nullptr; - elem2param = nullptr; - nparams = 0; params = nullptr; - map = nullptr; cutmax = 0.0; } @@ -82,9 +77,6 @@ PairAGNI::PairAGNI(LAMMPS *lmp) : Pair(lmp) PairAGNI::~PairAGNI() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; if (params) { for (int i = 0; i < nparams; ++i) { memory->destroy(params[i].eta); @@ -94,12 +86,11 @@ PairAGNI::~PairAGNI() memory->destroy(params); params = nullptr; } - memory->destroy(elem2param); + memory->destroy(elem1param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -135,7 +126,7 @@ void PairAGNI::compute(int eflag, int vflag) ztmp = x[i][2]; fxtmp = fytmp = fztmp = 0.0; - const Param &iparam = params[elem2param[itype]]; + const Param &iparam = params[elem1param[itype]]; Vx = new double[iparam.numeta]; Vy = new double[iparam.numeta]; Vz = new double[iparam.numeta]; @@ -238,46 +229,10 @@ void PairAGNI::settings(int narg, char ** /* arg */) void PairAGNI::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + map_element2type(narg-3,arg+3); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } if (nelements != 1) error->all(FLERR,"Cannot handle multi-element systems with this potential"); @@ -285,25 +240,6 @@ void PairAGNI::coeff(int narg, char **arg) read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -466,10 +402,10 @@ void PairAGNI::setup_params() int i,m,n; double rtmp; - // set elem2param for all elements + // set elem1param for all elements - memory->destroy(elem2param); - memory->create(elem2param,nelements,"pair:elem2param"); + memory->destroy(elem1param); + memory->create(elem1param,nelements,"pair:elem1param"); for (i = 0; i < nelements; i++) { n = -1; @@ -480,7 +416,7 @@ void PairAGNI::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i] = n; + elem1param[i] = n; } // compute parameter values derived from inputs diff --git a/src/USER-MISC/pair_agni.h b/src/USER-MISC/pair_agni.h index 6fba506d04..0a33c11b95 100644 --- a/src/USER-MISC/pair_agni.h +++ b/src/USER-MISC/pair_agni.h @@ -45,11 +45,6 @@ class PairAGNI : public Pair { protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique atom type labels - char **elements; // names of unique elements - int *elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets int atomic_feature_version; // version of fingerprint Param *params; // parameter set for an I-J interaction virtual void allocate(); diff --git a/src/USER-MISC/pair_drip.cpp b/src/USER-MISC/pair_drip.cpp index 45b49ee293..0f571dd41e 100644 --- a/src/USER-MISC/pair_drip.cpp +++ b/src/USER-MISC/pair_drip.cpp @@ -22,17 +22,17 @@ #include "pair_drip.h" -#include - -#include #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" + +#include +#include using namespace LAMMPS_NS; @@ -51,10 +51,6 @@ PairDRIP::PairDRIP(LAMMPS *lmp) : Pair(lmp) params = nullptr; nearest3neigh = nullptr; - elements = nullptr; - elem2param = nullptr; - map = nullptr; - nelements = 0; cutmax = 0.0; } @@ -65,14 +61,8 @@ PairDRIP::~PairDRIP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } - if (elements != nullptr) { - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - elements = nullptr; - } memory->destroy(params); memory->destroy(elem2param); memory->destroy(nearest3neigh); @@ -127,64 +117,10 @@ void PairDRIP::settings(int narg, char ** /* arg */) void PairDRIP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - - // clear setflag since coeff() called once with I,J = * * - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_drip.h b/src/USER-MISC/pair_drip.h index 3ea6c735a6..59dac076c8 100644 --- a/src/USER-MISC/pair_drip.h +++ b/src/USER-MISC/pair_drip.h @@ -58,10 +58,6 @@ protected: }; Param *params; // parameter set for I-J interactions int **nearest3neigh; // nearest 3 neighbors of atoms - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements double cutmax; // max cutoff for all species void read_file(char *); diff --git a/src/USER-MISC/pair_edip.cpp b/src/USER-MISC/pair_edip.cpp index 12390ba69d..88b8728c38 100644 --- a/src/USER-MISC/pair_edip.cpp +++ b/src/USER-MISC/pair_edip.cpp @@ -23,18 +23,18 @@ #include "pair_edip.h" -#include -#include - -#include #include "atom.h" -#include "neighbor.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" -#include "comm.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" + +#include +#include +#include using namespace LAMMPS_NS; @@ -64,11 +64,7 @@ PairEDIP::PairEDIP(LAMMPS *lmp) : manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -77,16 +73,12 @@ PairEDIP::PairEDIP(LAMMPS *lmp) : PairEDIP::~PairEDIP() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; deallocateGrids(); deallocatePreLoops(); @@ -198,7 +190,7 @@ void PairEDIP::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -313,7 +305,7 @@ void PairEDIP::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -367,7 +359,7 @@ void PairEDIP::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; dr_ik[0] = x[k][0] - xtmp; dr_ik[1] = x[k][1] - ytmp; @@ -766,47 +758,9 @@ void PairEDIP::initGrids(void) void PairEDIP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3); if (nelements != 1) error->all(FLERR,"Pair style edip only supports single element potentials"); @@ -815,25 +769,6 @@ void PairEDIP::coeff(int narg, char **arg) read_file(arg[2]); setup_params(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // allocate tables and internal structures allocatePreLoops(); @@ -1015,12 +950,12 @@ void PairEDIP::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -1034,7 +969,7 @@ void PairEDIP::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_edip.h b/src/USER-MISC/pair_edip.h index 6c4a37d795..006c124229 100644 --- a/src/USER-MISC/pair_edip.h +++ b/src/USER-MISC/pair_edip.h @@ -87,12 +87,6 @@ class PairEDIP : public Pair { double u4; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/USER-MISC/pair_edip_multi.cpp b/src/USER-MISC/pair_edip_multi.cpp index c0969831b9..4db52da11a 100644 --- a/src/USER-MISC/pair_edip_multi.cpp +++ b/src/USER-MISC/pair_edip_multi.cpp @@ -82,11 +82,7 @@ PairEDIPMulti::PairEDIPMulti(LAMMPS *lmp) : Pair(lmp), preForceCoord(nullptr) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -95,16 +91,12 @@ PairEDIPMulti::PairEDIPMulti(LAMMPS *lmp) : Pair(lmp), preForceCoord(nullptr) PairEDIPMulti::~PairEDIPMulti() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } deallocatePreLoops(); } @@ -173,7 +165,7 @@ void PairEDIPMulti::compute(int eflag, int vflag) r_ij = delx * delx + dely * dely + delz * delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -214,7 +206,7 @@ void PairEDIPMulti::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -246,8 +238,8 @@ void PairEDIPMulti::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = x[k][0] - xtmp; dr_ik[1] = x[k][1] - ytmp; @@ -537,71 +529,15 @@ void PairEDIPMulti::settings(int narg, char **/*arg*/) void PairEDIPMulti::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // (re-)allocate tables and internal structures deallocatePreLoops(); @@ -784,12 +720,12 @@ void PairEDIPMulti::setup() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -803,7 +739,7 @@ void PairEDIPMulti::setup() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_edip_multi.h b/src/USER-MISC/pair_edip_multi.h index cf1d56945f..2aba064aa9 100644 --- a/src/USER-MISC/pair_edip_multi.h +++ b/src/USER-MISC/pair_edip_multi.h @@ -54,12 +54,6 @@ class PairEDIPMulti : public Pair { double *preForceCoord; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/USER-MISC/pair_extep.cpp b/src/USER-MISC/pair_extep.cpp index ea4a8031a1..c64c7474cd 100644 --- a/src/USER-MISC/pair_extep.cpp +++ b/src/USER-MISC/pair_extep.cpp @@ -52,18 +52,13 @@ PairExTeP::PairExTeP(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; maxlocal = 0; SR_numneigh = nullptr; SR_firstneigh = nullptr; ipage = nullptr; pgsize = oneatom = 0; - map = nullptr; Nt = nullptr; Nd = nullptr; @@ -75,11 +70,8 @@ PairExTeP::PairExTeP(LAMMPS *lmp) : Pair(lmp) PairExTeP::~PairExTeP() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(SR_numneigh); memory->sfree(SR_firstneigh); @@ -91,7 +83,6 @@ PairExTeP::~PairExTeP() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; } } @@ -159,7 +150,7 @@ void PairExTeP::SR_neigh() rsq = delx*delx + dely*dely + delz*delz; jtype=map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq < params[iparam_ij].cutsq) { neighptr[n++] = j; @@ -246,7 +237,7 @@ void PairExTeP::compute(int eflag, int vflag) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,eflag,evdwl); @@ -270,7 +261,7 @@ void PairExTeP::compute(int eflag, int vflag) j &= NEIGHMASK; jtag = tag[j]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -337,7 +328,7 @@ void PairExTeP::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -352,7 +343,7 @@ void PairExTeP::compute(int eflag, int vflag) /* F_IJ (2) */ // compute force components due to spline derivatives // uses only the part with FXY_x (FXY_y is done when i and j are inversed) - int iparam_ik = elem2param[itype][ktype][0]; + int iparam_ik = elem3param[itype][ktype][0]; double fc_ik_d = ters_fc_d(r2,¶ms[iparam_ik]); double fc_prefac_ik_0 = 1.0 * fc_ik_d * fa / r2; double fc_prefac_ik = dFc_dNtij * fc_prefac_ik_0; @@ -396,7 +387,7 @@ void PairExTeP::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -455,71 +446,15 @@ void PairExTeP::settings(int narg, char **/*arg*/) void PairExTeP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); spline_init(); setup(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -818,12 +753,12 @@ void PairExTeP::setup() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -837,7 +772,7 @@ void PairExTeP::setup() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/USER-MISC/pair_extep.h b/src/USER-MISC/pair_extep.h index 599147c46e..08ee6d9a82 100644 --- a/src/USER-MISC/pair_extep.h +++ b/src/USER-MISC/pair_extep.h @@ -48,30 +48,24 @@ class PairExTeP : public Pair { double c1,c2,c3,c4; int ielement,jelement,kelement; int powermint; - double Z_i,Z_j; // added for ExTePZBL + double Z_i,Z_j; // added for ExTePZBL double ZBLcut,ZBLexpscale; - double c5,ca1,ca4; // added for ExTePMOD + double c5,ca1,ca4; // added for ExTePMOD double powern_del; }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets - int maxlocal; // size of numneigh, firstneigh arrays - int maxpage; // # of pages currently allocated - int pgsize; // size of neighbor page - int oneatom; // max # of neighbors for one atom - MyPage *ipage; // neighbor list pages - int *SR_numneigh; // # of pair neighbors for each atom - int **SR_firstneigh; // ptr to 1st neighbor of each atom + int maxlocal; // size of numneigh, firstneigh arrays + int maxpage; // # of pages currently allocated + int pgsize; // size of neighbor page + int oneatom; // max # of neighbors for one atom + MyPage *ipage; // neighbor list pages + int *SR_numneigh; // # of pair neighbors for each atom + int **SR_firstneigh; // ptr to 1st neighbor of each atom - double *Nt, *Nd; // sum of cutoff fns ( f_C ) with SR neighs + double *Nt, *Nd; // sum of cutoff fns ( f_C ) with SR neighs void allocate(); void spline_init(); diff --git a/src/USER-MISC/pair_ilp_graphene_hbn.cpp b/src/USER-MISC/pair_ilp_graphene_hbn.cpp index 982e67d4c1..2870d175c4 100644 --- a/src/USER-MISC/pair_ilp_graphene_hbn.cpp +++ b/src/USER-MISC/pair_ilp_graphene_hbn.cpp @@ -22,20 +22,19 @@ #include "pair_ilp_graphene_hbn.h" -#include - -#include #include "atom.h" +#include "citeme.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" +#include "my_page.h" #include "neigh_list.h" #include "neigh_request.h" -#include "my_page.h" -#include "memory.h" -#include "error.h" -#include "citeme.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -66,13 +65,8 @@ PairILPGrapheneHBN::PairILPGrapheneHBN(LAMMPS *lmp) : Pair(lmp) pvector = new double[nextra]; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; cutILPsq = nullptr; - map = nullptr; nmax = 0; maxlocal = 0; @@ -110,13 +104,8 @@ PairILPGrapheneHBN::~PairILPGrapheneHBN() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - memory->destroy(params); memory->destroy(elem2param); memory->destroy(cutILPsq); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- @@ -168,68 +157,10 @@ void PairILPGrapheneHBN::settings(int narg, char **arg) void PairILPGrapheneHBN::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - cut[i][j] = cut_global; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_ilp_graphene_hbn.h b/src/USER-MISC/pair_ilp_graphene_hbn.h index aadb792cad..4f5e187782 100644 --- a/src/USER-MISC/pair_ilp_graphene_hbn.h +++ b/src/USER-MISC/pair_ilp_graphene_hbn.h @@ -56,12 +56,6 @@ class PairILPGrapheneHBN : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int nmax; // max # of atoms double cut_global; diff --git a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp index c5fa33bbac..45ad36dd7c 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp +++ b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp @@ -21,21 +21,20 @@ ------------------------------------------------------------------------- */ #include "pair_kolmogorov_crespi_full.h" -#include - -#include #include "atom.h" +#include "citeme.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" +#include "my_page.h" #include "neigh_list.h" #include "neigh_request.h" -#include "my_page.h" -#include "memory.h" -#include "error.h" -#include "citeme.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -66,13 +65,8 @@ PairKolmogorovCrespiFull::PairKolmogorovCrespiFull(LAMMPS *lmp) : Pair(lmp) pvector = new double[nextra]; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; cutKCsq = nullptr; - map = nullptr; nmax = 0; maxlocal = 0; @@ -111,13 +105,9 @@ PairKolmogorovCrespiFull::~PairKolmogorovCrespiFull() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); memory->destroy(cutKCsq); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- @@ -169,68 +159,9 @@ void PairKolmogorovCrespiFull::settings(int narg, char **arg) void PairKolmogorovCrespiFull::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - cut[i][j] = cut_global; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_kolmogorov_crespi_full.h b/src/USER-MISC/pair_kolmogorov_crespi_full.h index f7d9237be4..dd2721d37e 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_full.h +++ b/src/USER-MISC/pair_kolmogorov_crespi_full.h @@ -57,12 +57,6 @@ class PairKolmogorovCrespiFull : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int nmax; // max # of atoms double cut_global; diff --git a/src/USER-MISC/pair_kolmogorov_crespi_z.cpp b/src/USER-MISC/pair_kolmogorov_crespi_z.cpp index 1bea688be5..4b5de2314e 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_z.cpp +++ b/src/USER-MISC/pair_kolmogorov_crespi_z.cpp @@ -23,16 +23,15 @@ #include "pair_kolmogorov_crespi_z.h" -#include - -#include #include "atom.h" #include "comm.h" -#include "force.h" -#include "neigh_list.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "memory.h" +#include "neigh_list.h" +#include +#include using namespace LAMMPS_NS; @@ -69,12 +68,8 @@ PairKolmogorovCrespiZ::~PairKolmogorovCrespiZ() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- */ @@ -221,45 +216,13 @@ void PairKolmogorovCrespiZ::settings(int narg, char **arg) void PairKolmogorovCrespiZ::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3,false); read_file(arg[2]); // set setflag only for i,j pairs where both are mapped to elements diff --git a/src/USER-MISC/pair_kolmogorov_crespi_z.h b/src/USER-MISC/pair_kolmogorov_crespi_z.h index 1a90fdfa0b..7d242d67fd 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_z.h +++ b/src/USER-MISC/pair_kolmogorov_crespi_z.h @@ -43,12 +43,6 @@ class PairKolmogorovCrespiZ : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double cut_global; double **cut; diff --git a/src/USER-MISC/pair_lebedeva_z.cpp b/src/USER-MISC/pair_lebedeva_z.cpp index a600f5b761..afd7209c6b 100644 --- a/src/USER-MISC/pair_lebedeva_z.cpp +++ b/src/USER-MISC/pair_lebedeva_z.cpp @@ -24,16 +24,15 @@ #include "pair_lebedeva_z.h" -#include - -#include #include "atom.h" #include "comm.h" -#include "force.h" -#include "neigh_list.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "memory.h" +#include "neigh_list.h" +#include +#include using namespace LAMMPS_NS; @@ -48,12 +47,7 @@ PairLebedevaZ::PairLebedevaZ(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; // always compute energy offset offset_flag = 1; @@ -70,12 +64,8 @@ PairLebedevaZ::~PairLebedevaZ() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- */ @@ -217,45 +207,13 @@ void PairLebedevaZ::settings(int narg, char **arg) void PairLebedevaZ::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3,false); read_file(arg[2]); // set setflag only for i,j pairs where both are mapped to elements diff --git a/src/USER-MISC/pair_lebedeva_z.h b/src/USER-MISC/pair_lebedeva_z.h index e221087a0a..57cf445889 100644 --- a/src/USER-MISC/pair_lebedeva_z.h +++ b/src/USER-MISC/pair_lebedeva_z.h @@ -43,12 +43,6 @@ class PairLebedevaZ : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double cut_global; double **cut; diff --git a/src/USER-MISC/pair_meam_spline.cpp b/src/USER-MISC/pair_meam_spline.cpp index a6bf602c70..e956d96cf2 100644 --- a/src/USER-MISC/pair_meam_spline.cpp +++ b/src/USER-MISC/pair_meam_spline.cpp @@ -32,18 +32,18 @@ ------------------------------------------------------------------------- */ #include "pair_meam_spline.h" -#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 using namespace LAMMPS_NS; @@ -55,10 +55,6 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; - nelements = 0; - elements = nullptr; - map = nullptr; - Uprime_values = nullptr; nmax = 0; maxNeighbors = 0; @@ -80,10 +76,6 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp) PairMEAMSpline::~PairMEAMSpline() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - delete[] twoBodyInfo; memory->destroy(Uprime_values); @@ -98,8 +90,6 @@ PairMEAMSpline::~PairMEAMSpline() delete[] gs; delete[] zero_atom_energies; - - delete [] map; } } @@ -389,11 +379,6 @@ void PairMEAMSpline::coeff(int narg, char **arg) if (narg != 3 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - // read potential file: also sets the number of elements. read_file(arg[2]); diff --git a/src/USER-MISC/pair_meam_spline.h b/src/USER-MISC/pair_meam_spline.h index d1dc5064f5..b20454f18d 100644 --- a/src/USER-MISC/pair_meam_spline.h +++ b/src/USER-MISC/pair_meam_spline.h @@ -67,10 +67,6 @@ public: double memory_usage(); protected: - char **elements; // names of unique elements - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - class SplineFunction { public: /// Default constructor. diff --git a/src/USER-MISC/pair_meam_sw_spline.cpp b/src/USER-MISC/pair_meam_sw_spline.cpp index 58c0f75546..ff7b89fbe7 100644 --- a/src/USER-MISC/pair_meam_sw_spline.cpp +++ b/src/USER-MISC/pair_meam_sw_spline.cpp @@ -24,18 +24,18 @@ ------------------------------------------------------------------------- */ #include "pair_meam_sw_spline.h" -#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 using namespace LAMMPS_NS; @@ -49,9 +49,6 @@ PairMEAMSWSpline::PairMEAMSWSpline(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - Uprime_values = nullptr; //ESWprime_values = nullptr; nmax = 0; @@ -66,10 +63,6 @@ PairMEAMSWSpline::PairMEAMSWSpline(LAMMPS *lmp) : Pair(lmp) PairMEAMSWSpline::~PairMEAMSWSpline() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - delete[] twoBodyInfo; memory->destroy(Uprime_values); //memory->destroy(ESWprime_values); @@ -77,7 +70,6 @@ PairMEAMSWSpline::~PairMEAMSWSpline() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -381,46 +373,9 @@ void PairMEAMSWSpline::settings(int narg, char **/*arg*/) void PairMEAMSWSpline::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // for now, only allow single element @@ -431,25 +386,6 @@ void PairMEAMSWSpline::coeff(int narg, char **arg) // read potential file read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-MISC/pair_meam_sw_spline.h b/src/USER-MISC/pair_meam_sw_spline.h index 7b40d123ed..ecf56c7931 100644 --- a/src/USER-MISC/pair_meam_sw_spline.h +++ b/src/USER-MISC/pair_meam_sw_spline.h @@ -54,9 +54,6 @@ public: double memory_usage(); protected: - char **elements; // names of unique elements - int *map; // mapping from atom types to elements - int nelements; // # of unique elements class SplineFunction { public: diff --git a/src/USER-MISC/pair_tersoff_table.cpp b/src/USER-MISC/pair_tersoff_table.cpp index 0d5bbc1147..ed05961fa7 100644 --- a/src/USER-MISC/pair_tersoff_table.cpp +++ b/src/USER-MISC/pair_tersoff_table.cpp @@ -22,21 +22,19 @@ #include "pair_tersoff_table.h" -#include - -#include #include "atom.h" -#include "neighbor.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" -#include "comm.h" -#include "memory.h" - -#include "tokenizer.h" +#include "neighbor.h" #include "potential_file_reader.h" +#include "tokenizer.h" -#include "error.h" +#include +#include using namespace LAMMPS_NS; @@ -64,11 +62,7 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; allocated = 0; preGtetaFunction = preGtetaFunctionDerived = nullptr; @@ -88,17 +82,12 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) PairTersoffTable::~PairTersoffTable() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; - } deallocateGrids(); deallocatePreLoops(); @@ -177,7 +166,7 @@ void PairTersoffTable::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -208,8 +197,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -264,7 +253,7 @@ void PairTersoffTable::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -308,8 +297,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -333,8 +322,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -392,8 +381,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -457,8 +446,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -608,7 +597,7 @@ void PairTersoffTable::allocateGrids(void) r = -1.0; deltaArgumentGtetaFunction = 1.0 / GRIDDENSITY_GTETA; - int iparam = elem2param[i][i][i]; + int iparam = elem3param[i][i][i]; double c = params[iparam].c; double d = params[iparam].d; double h = params[iparam].h; @@ -628,7 +617,7 @@ void PairTersoffTable::allocateGrids(void) for (i=0; intypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // allocate tables and internal structures + allocatePreLoops(); allocateGrids(); } @@ -966,12 +900,12 @@ void PairTersoffTable::setup_params() { int i,j,k,m,n; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -985,7 +919,7 @@ void PairTersoffTable::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_tersoff_table.h b/src/USER-MISC/pair_tersoff_table.h index d63a5be5a6..84e6f6fe50 100644 --- a/src/USER-MISC/pair_tersoff_table.h +++ b/src/USER-MISC/pair_tersoff_table.h @@ -59,12 +59,6 @@ class PairTersoffTable : public Pair { double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); 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-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 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 ba7f6e6c26..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,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(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_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 f3f08c15c2..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,35 +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 - 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_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 bfa2dcbe49..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; @@ -33,17 +35,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; } 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-OMP/pair_agni_omp.cpp b/src/USER-OMP/pair_agni_omp.cpp index 02a6126e03..258c833cdf 100644 --- a/src/USER-OMP/pair_agni_omp.cpp +++ b/src/USER-OMP/pair_agni_omp.cpp @@ -101,7 +101,7 @@ void PairAGNIOMP::eval(int iifrom, int iito, ThrData * const thr) ztmp = x[i].z; fxtmp = fytmp = fztmp = 0.0; - const Param &iparam = params[elem2param[itype]]; + const Param &iparam = params[elem1param[itype]]; Vx = new double[iparam.numeta]; Vy = new double[iparam.numeta]; Vz = new double[iparam.numeta]; diff --git a/src/USER-OMP/pair_comb_omp.cpp b/src/USER-OMP/pair_comb_omp.cpp index cfde8ff905..52c8855738 100644 --- a/src/USER-OMP/pair_comb_omp.cpp +++ b/src/USER-OMP/pair_comb_omp.cpp @@ -139,7 +139,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) iq = q[i]; NCo[i] = 0; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom @@ -180,7 +180,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -242,7 +242,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < sht_jnum; jj++) { j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (params[iparam_ij].hfocor > 0.0) { delr1[0] = x[j][0] - xtmp; @@ -264,7 +264,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // this Qj for q-dependent BSi @@ -288,7 +288,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -332,7 +332,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -434,7 +434,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) const double ytmp = x[i][1]; const double ztmp = x[i][2]; const double iq = q[i]; - const int iparam_i = elem2param[itype][itype][itype]; + const int iparam_i = elem3param[itype][itype][itype]; // charge force from self energy @@ -467,7 +467,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; double rsq1 = dot3(delr1,delr1); - const int iparam_ij = elem2param[itype][jtype][jtype]; + const int iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -505,7 +505,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; double rsq1 = dot3(delr1,delr1); - const int iparam_ij = elem2param[itype][jtype][jtype]; + const int iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/USER-OMP/pair_edip_omp.cpp b/src/USER-OMP/pair_edip_omp.cpp index 106d038743..b2e8708305 100644 --- a/src/USER-OMP/pair_edip_omp.cpp +++ b/src/USER-OMP/pair_edip_omp.cpp @@ -184,7 +184,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -299,7 +299,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -353,7 +353,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; dr_ik[0] = x[k].x - xtmp; dr_ik[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_sw_omp.cpp b/src/USER-OMP/pair_sw_omp.cpp index 92d0d0c15a..28e450f517 100644 --- a/src/USER-OMP/pair_sw_omp.cpp +++ b/src/USER-OMP/pair_sw_omp.cpp @@ -121,7 +121,7 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = delx*delx + dely*dely + delz*delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) { continue; } else { @@ -161,7 +161,7 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -173,8 +173,8 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_mod_c_omp.cpp b/src/USER-OMP/pair_tersoff_mod_c_omp.cpp index c6947bbde7..8f255ee1ba 100644 --- a/src/USER-OMP/pair_tersoff_mod_c_omp.cpp +++ b/src/USER-OMP/pair_tersoff_mod_c_omp.cpp @@ -157,7 +157,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = rsqtmp; } - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -185,7 +185,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -210,7 +210,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -251,7 +251,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_mod_omp.cpp b/src/USER-OMP/pair_tersoff_mod_omp.cpp index e689803c38..454a387982 100644 --- a/src/USER-OMP/pair_tersoff_mod_omp.cpp +++ b/src/USER-OMP/pair_tersoff_mod_omp.cpp @@ -159,7 +159,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = rsqtmp; } - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -187,7 +187,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -212,7 +212,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -253,7 +253,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_omp.cpp b/src/USER-OMP/pair_tersoff_omp.cpp index 7fb3c70d78..c12e3b9859 100644 --- a/src/USER-OMP/pair_tersoff_omp.cpp +++ b/src/USER-OMP/pair_tersoff_omp.cpp @@ -173,7 +173,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq >= params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -200,7 +200,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < numshort; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -224,7 +224,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) if (jj == kk) continue; k = neighshort_thr[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -264,7 +264,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) if (jj == kk) continue; k = neighshort_thr[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_table_omp.cpp b/src/USER-OMP/pair_tersoff_table_omp.cpp index 2e52492491..02752c8577 100644 --- a/src/USER-OMP/pair_tersoff_table_omp.cpp +++ b/src/USER-OMP/pair_tersoff_table_omp.cpp @@ -154,7 +154,7 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -185,8 +185,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -241,7 +241,7 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -285,8 +285,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -310,8 +310,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -370,8 +370,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -436,8 +436,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; diff --git a/src/USER-OMP/pair_vashishta_omp.cpp b/src/USER-OMP/pair_vashishta_omp.cpp index 303de78e37..23d7235578 100644 --- a/src/USER-OMP/pair_vashishta_omp.cpp +++ b/src/USER-OMP/pair_vashishta_omp.cpp @@ -143,7 +143,7 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody(¶ms[ijparam],rsq,fpair,EFLAG,evdwl); @@ -164,7 +164,7 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -177,8 +177,8 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_vashishta_table_omp.cpp b/src/USER-OMP/pair_vashishta_table_omp.cpp index 50c985ad68..c03d827d9b 100644 --- a/src/USER-OMP/pair_vashishta_table_omp.cpp +++ b/src/USER-OMP/pair_vashishta_table_omp.cpp @@ -141,7 +141,7 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody_table(params[ijparam],rsq,fpair,EFLAG,evdwl); @@ -162,7 +162,7 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -175,8 +175,8 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; 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 b221ecbca8..a9dfb83f06 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -18,21 +18,21 @@ #include "fix_qbmsst.h" -#include -#include - #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 using namespace LAMMPS_NS; using namespace FixConst; @@ -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 @@ -891,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"); @@ -913,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 94d1a596f8..17754c8297 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-REAXC/pair_reaxc.cpp b/src/USER-REAXC/pair_reaxc.cpp index fe78fbbb37..4d6f240ec6 100644 --- a/src/USER-REAXC/pair_reaxc.cpp +++ b/src/USER-REAXC/pair_reaxc.cpp @@ -22,23 +22,23 @@ #include "pair_reaxc.h" -#include - -#include -#include #include "atom.h" -#include "update.h" -#include "force.h" +#include "citeme.h" #include "comm.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_reaxc.h" -#include "citeme.h" +#include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" + +#include +#include +#include // for strcasecmp() #include "reaxc_defs.h" #include "reaxc_types.h" @@ -175,7 +175,6 @@ PairReaxC::~PairReaxC() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; delete [] chi; delete [] eta; diff --git a/src/USER-REAXC/pair_reaxc.h b/src/USER-REAXC/pair_reaxc.h index a833ddbcf0..53b41ba9c8 100644 --- a/src/USER-REAXC/pair_reaxc.h +++ b/src/USER-REAXC/pair_reaxc.h @@ -62,9 +62,6 @@ class PairReaxC : public Pair { protected: char *fix_id; double cutmax; - int nelements; // # of unique elements - char **elements; // names of unique elements - int *map; class FixReaxC *fix_reax; double *chi,*eta,*gamma; 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: diff --git a/src/USER-SMTBQ/pair_smtbq.cpp b/src/USER-SMTBQ/pair_smtbq.cpp index 7ed37fefc4..5a27855a47 100644 --- a/src/USER-SMTBQ/pair_smtbq.cpp +++ b/src/USER-SMTBQ/pair_smtbq.cpp @@ -91,10 +91,6 @@ PairSMTBQ::PairSMTBQ(LAMMPS *lmp) : Pair(lmp) ds = 0.0; kmax = 0; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; intparams = nullptr; @@ -153,8 +149,6 @@ PairSMTBQ::~PairSMTBQ() { int i; if (elements) { - for ( i = 0; i < nelements; i++) delete [] elements[i]; - for (i = 0; i < atom->ntypes ; i++ ) free( params[i].nom); for (i = 1; i <= maxintparam ; i++ ) free( intparams[i].typepot); for (i = 1; i <= maxintparam ; i++ ) free( intparams[i].mode); @@ -166,7 +160,6 @@ PairSMTBQ::~PairSMTBQ() free(writeenerg); free(Bavard); - delete [] elements; memory->sfree(params); memory->sfree(intparams); @@ -216,7 +209,6 @@ PairSMTBQ::~PairSMTBQ() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] esm; } @@ -252,92 +244,30 @@ void PairSMTBQ::settings(int narg, char ** /* arg */) void PairSMTBQ::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (strstr(force->pair_style,"hybrid")) + if (utils::strmatch(force->pair_style,"^hybrid")) error->all(FLERR,"Pair style SMTBQ is not compatible with hybrid styles"); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); - n = atom->ntypes; - // generate Coulomb 1/r energy look-up table - if (comm->me == 0 && screen) fprintf(screen,"Pair SMTBQ:\n"); if (comm->me == 0 && screen) - fprintf(screen," generating Coulomb integral lookup table ...\n"); + fputs("Pair SMTBQ: generating Coulomb integral lookup table ...\n",screen); tabqeq(); // ------------ - if (comm->me == 0 && screen) - fprintf(screen," generating Second Moment integral lookup table ...\n"); + fputs(" generating Second Moment integral lookup table ...\n",screen); tabsm(); - - // ------------ - - // clear setflag since coeff() called once with I,J = * * - - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-SMTBQ/pair_smtbq.h b/src/USER-SMTBQ/pair_smtbq.h index 4681c94895..8bf1cba57c 100644 --- a/src/USER-SMTBQ/pair_smtbq.h +++ b/src/USER-SMTBQ/pair_smtbq.h @@ -60,8 +60,6 @@ protected: int loopmax; // max of iteration double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements char *QEqMode; // name of QEqMode char *Bavard; // Verbose parameter char *writepot; // write or not the electronegativity component @@ -70,11 +68,8 @@ protected: double zlim1QEq; // z limit for QEq equilibration double zlim2QEq; // z limit for QEq equilibration double QOxInit; // Initial charge for oxygen atoms (if the charge is not specified) - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets - int maxintparam; // max # of interaction sets - int maxintsm; // max # of interaction SM + int maxintparam; // max # of interaction sets + int maxintsm; // max # of interaction SM double r1Coord,r2Coord; Param *params; // parameter set for an I atom Intparam *intparams; // parameter set for an I interaction 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_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)); 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; 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 *); diff --git a/src/input.cpp b/src/input.cpp index 53fcc606db..f96cf8c75c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1697,6 +1697,9 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); + if ((narg < 2) || (force->pair->one_coeff && ((strcmp(arg[0],"*") != 0) + || (strcmp(arg[1],"*") != 0)))) + error->all(FLERR,"Incorrect args for pair coefficients"); force->pair->coeff(narg,arg); } diff --git a/src/pair.cpp b/src/pair.cpp index 27a8831eb1..767fa638cf 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -106,6 +106,13 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) num_tally_compute = 0; list_tally_compute = nullptr; + nelements = nparams = maxparam = 0; + elements = nullptr; + elem1param = nullptr; + elem2param = nullptr; + elem3param = nullptr; + map = nullptr; + nondefault_history_transfer = 0; beyond_contact = 0; @@ -129,6 +136,11 @@ Pair::~Pair() if (copymode) return; + if (elements) + for (int i = 0; i < nelements; i++) delete[] elements[i]; + delete[] elements; + + delete[] map; memory->destroy(eatom); memory->destroy(vatom); memory->destroy(cvatom); @@ -776,6 +788,68 @@ void Pair::del_tally_callback(Compute *ptr) } } +/* ------------------------------------------------------------------- + build element to atom type mapping for manybody potentials + also clear and reset setflag[][] array and check missing entries +---------------------------------------------------------------------- */ + +void Pair::map_element2type(int narg, char **arg, bool update_setflag) +{ + int i,j; + const int ntypes = atom->ntypes; + + // read args that map atom types to elements in potential file + // map[i] = which element the Ith atom type is, -1 if "NULL" + // nelements = # of unique elements + // elements = list of element names + + if (narg != ntypes) + error->all(FLERR,"Incorrect args for pair coefficients"); + + if (elements) { + for (i = 0; i < nelements; i++) delete[] elements[i]; + delete[] elements; + } + elements = new char*[ntypes]; + for (i = 0; i < ntypes; i++) elements[i] = nullptr; + + nelements = 0; + map[0] = -1; + for (i = 1; i <= narg; i++) { + std::string entry = arg[i-1]; + if (entry == "NULL") { + map[i] = -1; + continue; + } + for (j = 0; j < nelements; j++) + if (entry == elements[j]) break; + map[i] = j; + if (j == nelements) { + elements[j] = utils::strdup(entry); + nelements++; + } + } + + // if requested, clear setflag[i][j] and set it for type pairs + // where both are mapped to elements in map. + + if (update_setflag) { + + int count = 0; + for (i = 1; i <= ntypes; i++) { + for (j = i; j <= ntypes; j++) { + setflag[i][j] = 0; + if ((map[i] >= 0) && (map[j] >= 0)) { + setflag[i][j] = 1; + count++; + } + } + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); + } +} + /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag diff --git a/src/pair.h b/src/pair.h index 9bca64fbf3..b25ad448eb 100644 --- a/src/pair.h +++ b/src/pair.h @@ -216,17 +216,27 @@ class Pair : protected Pointers { virtual void del_tally_callback(class Compute *); protected: - int instance_me; // which Pair class instantiation I am + int instance_me; // which Pair class instantiation I am + int special_lj[4]; // copied from force->special_lj for Kokkos + int suffix_flag; // suffix compatibility flag - int special_lj[4]; // copied from force->special_lj for Kokkos - - int suffix_flag; // suffix compatibility flag - - // pair_modify settings - int offset_flag,mix_flag; // flags for offset and mixing - double tabinner; // inner cutoff for Coulomb table - double tabinner_disp; // inner cutoff for dispersion table + // pair_modify settings + int offset_flag,mix_flag; // flags for offset and mixing + double tabinner; // inner cutoff for Coulomb table + double tabinner_disp; // inner cutoff for dispersion table + protected: + // for mapping of elements to atom types and parameters + // mostly used for manybody potentials + int nelements; // # of unique elements + char **elements; // names of unique elements + int *elem1param; // mapping from elements to parameters + int **elem2param; // mapping from element pairs to parameters + int ***elem3param; // mapping from element triplets to parameters + int *map; // mapping from atom types to elements + int nparams; // # of stored parameter sets + int maxparam; // max # of parameter sets + void map_element2type(int, char**, bool update_setflag=true); public: // custom data type for accessing Coulomb tables diff --git a/src/pair_coul_streitz.cpp b/src/pair_coul_streitz.cpp index 68790c0f03..55529f9eae 100644 --- a/src/pair_coul_streitz.cpp +++ b/src/pair_coul_streitz.cpp @@ -49,13 +49,8 @@ PairCoulStreitz::PairCoulStreitz(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; nmax = 0; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -64,12 +59,8 @@ PairCoulStreitz::PairCoulStreitz(LAMMPS *lmp) : Pair(lmp) PairCoulStreitz::~PairCoulStreitz() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem1param); if (allocated) { memory->destroy(setflag); @@ -80,7 +71,6 @@ PairCoulStreitz::~PairCoulStreitz() memory->destroy(qeq_g); memory->destroy(qeq_z); memory->destroy(qeq_c); - delete [] map; } } @@ -130,69 +120,19 @@ void PairCoulStreitz::settings(int narg, char **arg) void PairCoulStreitz::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - elements[j] = utils::strdup(arg[i]); - nelements++; - } - } + map_element2type(narg-3, arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - - // clear setflag since coeff() called once with I,J = * * + const int n = atom->ntypes; for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { + for (int j = 1; j <= n; j++) scale[i][j] = 1.0; - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -308,10 +248,10 @@ void PairCoulStreitz::setup_params() { int i,m,n; - // set elem2param + // set elem1param - memory->destroy(elem2param); - memory->create(elem2param,nelements,"pair:elem2param"); + memory->destroy(elem1param); + memory->create(elem1param,nelements,"pair:elem1param"); for (i = 0; i < nelements; i++) { n = -1; @@ -322,7 +262,7 @@ void PairCoulStreitz::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i] = n; + elem1param[i] = n; } // Wolf sum self energy @@ -381,7 +321,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) ytmp = x[i][1]; ztmp = x[i][2]; itype = map[type[i]]; - iparam_i = elem2param[itype]; + iparam_i = elem1param[itype]; qi = q[i]; zei = params[iparam_i].zeta; @@ -401,7 +341,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) j &= NEIGHMASK; jtype = map[type[j]]; - iparam_j = elem2param[jtype]; + iparam_j = elem1param[jtype]; qj = q[j]; zej = params[iparam_j].zeta; zj = params[iparam_j].zcore; @@ -454,7 +394,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) ytmp = x[i][1]; ztmp = x[i][2]; itype = map[type[i]]; - iparam_i = elem2param[itype]; + iparam_i = elem1param[itype]; qi = q[i]; zei = params[iparam_i].zeta; @@ -473,7 +413,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_j = elem2param[jtype]; + iparam_j = elem1param[jtype]; qj = q[j]; zej = params[iparam_j].zeta; zj = params[iparam_j].zcore; diff --git a/src/pair_coul_streitz.h b/src/pair_coul_streitz.h index 2f62846212..12da6afcfe 100644 --- a/src/pair_coul_streitz.h +++ b/src/pair_coul_streitz.h @@ -45,14 +45,8 @@ class PairCoulStreitz : public Pair { }; int nmax; - int nelements; // # of unique elements - char **elements; // names of unique elements - int *elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double precision; - Param *params; // parameter set for an I-J-K interaction + Param *params; // parameter sets for elements // Kspace parameters int kspacetype; 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