diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7d1b2894c8..99d51614c8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -105,8 +105,28 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") endif() endif() +# silence excessive warnings for new Intel Compilers +if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") + set(CMAKE_TUNE_DEFAULT "-Wno-tautological-constant-compare") +endif() + +# silence excessive warnings for PGI/NVHPC compilers +if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI")) + set(CMAKE_TUNE_DEFAULT "-Minform=severe") +endif() + +# silence nvcc warnings +if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA)) + set(CMAKE_TUNE_DEFAULT "${CMAKE_TUNE_DEFAULT} -Xcudafe --diag_suppress=unrecognized_pragma") +endif() + # we require C++11 without extensions. Kokkos requires at least C++14 (currently) -set(CMAKE_CXX_STANDARD 11) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() +if(CMAKE_CXX_STANDARD LESS 11) + message(FATAL_ERROR "C++ standard must be set to at least 11") +endif() if(PKG_KOKKOS AND (CMAKE_CXX_STANDARD LESS 14)) set(CMAKE_CXX_STANDARD 14) endif() @@ -468,6 +488,7 @@ set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine separate_arguments(CMAKE_TUNE_FLAGS) foreach(_FLAG ${CMAKE_TUNE_FLAGS}) target_compile_options(lammps PRIVATE ${_FLAG}) + target_compile_options(lmp PRIVATE ${_FLAG}) endforeach() ######################################################################## # Basic system tests (standard libraries, headers, functions, types) # diff --git a/cmake/Modules/Documentation.cmake b/cmake/Modules/Documentation.cmake index 16dd5dd4fa..35661843a2 100644 --- a/cmake/Modules/Documentation.cmake +++ b/cmake/Modules/Documentation.cmake @@ -7,13 +7,13 @@ if(BUILD_DOC) # Sphinx 3.x requires at least Python 3.5 if(CMAKE_VERSION VERSION_LESS 3.12) find_package(PythonInterp 3.5 REQUIRED) - set(VIRTUALENV ${PYTHON_EXECUTABLE} -m virtualenv -p ${PYTHON_EXECUTABLE}) + set(VIRTUALENV ${PYTHON_EXECUTABLE} -m venv) else() find_package(Python3 REQUIRED COMPONENTS Interpreter) if(Python3_VERSION VERSION_LESS 3.5) message(FATAL_ERROR "Python 3.5 and up is required to build the HTML documentation") endif() - set(VIRTUALENV ${Python3_EXECUTABLE} -m virtualenv -p ${Python3_EXECUTABLE}) + set(VIRTUALENV ${Python3_EXECUTABLE} -m venv) endif() find_package(Doxygen 1.8.10 REQUIRED) diff --git a/cmake/Modules/Packages/COLVARS.cmake b/cmake/Modules/Packages/COLVARS.cmake index 3488aa62b1..da5b685536 100644 --- a/cmake/Modules/Packages/COLVARS.cmake +++ b/cmake/Modules/Packages/COLVARS.cmake @@ -19,6 +19,10 @@ endif() add_library(colvars STATIC ${COLVARS_SOURCES}) target_compile_definitions(colvars PRIVATE -DCOLVARS_LAMMPS) +separate_arguments(CMAKE_TUNE_FLAGS) +foreach(_FLAG ${CMAKE_TUNE_FLAGS}) + target_compile_options(colvars PRIVATE ${_FLAG}) +endforeach() set_target_properties(colvars PROPERTIES OUTPUT_NAME lammps_colvars${LAMMPS_MACHINE}) target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars) # The line below is needed to locate math_eigen_impl.h diff --git a/cmake/Modules/Packages/MACHDYN.cmake b/cmake/Modules/Packages/MACHDYN.cmake index d90ca8146c..fcc298da2f 100644 --- a/cmake/Modules/Packages/MACHDYN.cmake +++ b/cmake/Modules/Packages/MACHDYN.cmake @@ -36,3 +36,5 @@ endif() if((CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")) target_compile_definitions(lammps PRIVATE -DEIGEN_DONT_VECTORIZE) endif() + +target_compile_definitions(lammps PRIVATE -DEIGEN_NO_CUDA) diff --git a/cmake/presets/kokkos-cuda.cmake b/cmake/presets/kokkos-cuda.cmake index 36d099479d..c0f9e7f21b 100644 --- a/cmake/presets/kokkos-cuda.cmake +++ b/cmake/presets/kokkos-cuda.cmake @@ -5,7 +5,5 @@ set(PKG_KOKKOS ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA ON CACHE BOOL "" FORCE) -set(Kokkos_ARCH_MAXWELL50 on CACHE BOOL "" FORCE) +set(Kokkos_ARCH_PASCAL60 ON CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) -get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokkos/bin/nvcc_wrapper ABSOLUTE) -set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE) diff --git a/cmake/presets/pgi.cmake b/cmake/presets/pgi.cmake index b34cb05331..2b7fee7efa 100644 --- a/cmake/presets/pgi.cmake +++ b/cmake/presets/pgi.cmake @@ -1,4 +1,4 @@ -# preset that will enable clang/clang++ with support for MPI and OpenMP (on Linux boxes) +# preset that will enable PGI (Nvidia) compilers with support for MPI and OpenMP (on Linux boxes) set(CMAKE_CXX_COMPILER "pgc++" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "pgcc" CACHE STRING "" FORCE) diff --git a/doc/Makefile b/doc/Makefile index 58be62e712..113a64ec10 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -14,23 +14,22 @@ ANCHORCHECK = $(VENV)/bin/rst_anchor_check SPHINXCONFIG = $(BUILDDIR)/utils/sphinx-config MATHJAX = $(SPHINXCONFIG)/_static/mathjax -PYTHON = $(shell which python3) -DOXYGEN = $(shell which doxygen) -VIRTUALENV = virtualenv +PYTHON = $(word 3,$(shell type python3)) +DOXYGEN = $(word 3,$(shell type doxygen)) HAS_PYTHON3 = NO HAS_DOXYGEN = NO HAS_PDFLATEX = NO -ifeq ($(shell which python3 >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type python3 >/dev/null 2>&1; echo $$?), 0) HAS_PYTHON3 = YES endif -ifeq ($(shell which doxygen >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type doxygen >/dev/null 2>&1; echo $$?), 0) HAS_DOXYGEN = YES endif -ifeq ($(shell which pdflatex >/dev/null 2>&1; echo $$?), 0) -ifeq ($(shell which latexmk >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type pdflatex >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type latexmk >/dev/null 2>&1; echo $$?), 0) HAS_PDFLATEX = YES endif endif diff --git a/doc/src/Developer_utils.rst b/doc/src/Developer_utils.rst index 9c6ef67945..aceecd7a46 100644 --- a/doc/src/Developer_utils.rst +++ b/doc/src/Developer_utils.rst @@ -211,6 +211,9 @@ Convenience functions .. doxygenfunction:: logmesg(LAMMPS *lmp, const std::string &mesg) :project: progguide +.. doxygenfunction:: errorurl + :project: progguide + .. doxygenfunction:: flush_buffers(LAMMPS *lmp) :project: progguide diff --git a/doc/src/Errors.rst b/doc/src/Errors.rst index 5975c22c41..3e8ebc7f8e 100644 --- a/doc/src/Errors.rst +++ b/doc/src/Errors.rst @@ -11,6 +11,7 @@ them. :maxdepth: 1 Errors_common + Errors_details Errors_bugs Errors_debug Errors_messages diff --git a/doc/src/Errors_details.rst b/doc/src/Errors_details.rst new file mode 100644 index 0000000000..70fe0e90ff --- /dev/null +++ b/doc/src/Errors_details.rst @@ -0,0 +1,27 @@ +Detailed discussion of errors and warnings +========================================== + +Many errors or warnings are self-explanatory and thus straightforward to +resolve. However, there are also cases, where there is no single cause +and explanation, where LAMMPS can only detect symptoms of an error but +not the exact cause, or where the explanation needs to be more detailed than +what can be fit into a message printed by the program. The following are +discussions of such cases. + +.. _err0001: + +Unknown identifier in data file +------------------------------- + +This error happens when LAMMPS encounters a line of text in an unexpected format +while reading a data file. This is most commonly cause by inconsistent header and +section data. The header section informs LAMMPS how many entries or lines are expected in the +various sections (like Atoms, Masses, Pair Coeffs, *etc.*\ ) of the data file. +If there is a mismatch, LAMMPS will either keep reading beyond the end of a section +or stop reading before the section has ended. + +Such a mismatch can happen unexpectedly when the first line of the data +is *not* a comment as required by the format. That would result in +LAMMPS expecting, for instance, 0 atoms because the "atoms" header line +is treated as a comment. + diff --git a/doc/src/Modify_atom.rst b/doc/src/Modify_atom.rst index 5c3a96789e..6d278b3816 100644 --- a/doc/src/Modify_atom.rst +++ b/doc/src/Modify_atom.rst @@ -9,34 +9,34 @@ A new atom style can be created if one of the existing atom styles does not define all the attributes you need to store and communicate with atoms. -Atom_vec_atomic.cpp is the simplest example of an atom style. +The file ``atom_vec_atomic.cpp`` is the simplest example of an atom style. Examining the code for others will make these instructions more clear. -Note that the :doc:`atom style hybrid ` command can be -used to define atoms or particles which have the union of properties -of individual styles. Also the :doc:`fix property/atom ` -command can be used to add a single property (e.g. charge -or a molecule ID) to a style that does not have it. It can also be -used to add custom properties to an atom, with options to communicate -them with ghost atoms or read them from a data file. Other LAMMPS -commands can access these custom properties, as can new pair, fix, -compute styles that are written to work with these properties. For +Note that the :doc:`atom style hybrid ` command can be used +to define atoms or particles which have the union of properties of +individual styles. Also the :doc:`fix property/atom +` command can be used to add a single property +(e.g. charge or a molecule ID) to a style that does not have it. It can +also be used to add custom properties to an atom, with options to +communicate them with ghost atoms or read them from a data file. Other +LAMMPS commands can access these custom properties, as can new pair, +fix, compute styles that are written to work with these properties. For example, the :doc:`set ` command can be used to set the values of custom per-atom properties from an input script. All of these methods -are less work than writing code for a new atom style. +are less work than writing and testing(!) code for a new atom style. If you follow these directions your new style will automatically work in tandem with others via the :doc:`atom_style hybrid ` command. -The first step is to define a set of strings in the constructor of the -new derived class. Each string will have zero or more space-separated -variable names which are identical to those used in the atom.h header -file for per-atom properties. Note that some represent per-atom +The first step is to define a set of string lists in the constructor of +the new derived class. Each list will have zero or more comma-separated +strings that correspond to the variable names used in the ``atom.h`` +header file for per-atom properties. Note that some represent per-atom vectors (q, molecule) while other are per-atom arrays (x,v). For all -but the last 2 strings you do not need to specify any of +but the last two lists you do not need to specify any of (id,type,x,v,f). Those are included automatically as needed in the -other strings. +other lists. .. list-table:: @@ -65,16 +65,16 @@ other strings. * - fields_data_vel - list of properties (in order) in the Velocities section of a data file, as read by :doc:`read_data ` -In these strings you can list variable names which LAMMPS already -defines (in some other atom style), or you can create new variable -names. You should not re-use a LAMMPS variable for something with -different meaning in your atom style. If the meaning is related, but -interpreted differently by your atom style, then using the same -variable name means a user should not use your style and the other -style together in a :doc:`atom_style hybrid ` command. -Because there will only be one value of the variable and different -parts of LAMMPS will then likely use it differently. LAMMPS has -no way of checking for this. +In these lists you can list variable names which LAMMPS already defines +(in some other atom style), or you can create new variable names. You +should not re-use a LAMMPS variable in your atom style that is used for +something with a different meaning in another atom style. If the +meaning is related, but interpreted differently by your atom style, then +using the same variable name means a user must not use your style and +the other style together in a :doc:`atom_style hybrid ` +command. Because there will only be one value of the variable and +different parts of LAMMPS will then likely use it differently. LAMMPS +has no way of checking for this. If you are defining new variable names then make them descriptive and unique to your new atom style. For example choosing "e" for energy is @@ -85,32 +85,31 @@ If any of the variable names in your new atom style do not exist in LAMMPS, you need to add them to the src/atom.h and atom.cpp files. Search for the word "customize" or "customization" in these 2 files to -see where to add your variable. Adding a flag to the 2nd -customization section in atom.h is only necessary if your code (e.g. a -pair style) needs to check that a per-atom property is defined. These -flags should also be set in the constructor of the atom style child -class. +see where to add your variable. Adding a flag to the 2nd customization +section in ``atom.h`` is only necessary if your code (e.g. a pair style) +needs to check that a per-atom property is defined. These flags should +also be set in the constructor of the atom style child class. -In atom.cpp, aside from the constructor and destructor, there are 3 +In ``atom.cpp``, aside from the constructor and destructor, there are 3 methods that a new variable name or flag needs to be added to. -In Atom::peratom_create() when using the add_peratom() method, a -final length argument of 0 is for per-atom vectors, a length > 1 is -for per-atom arrays. Note the use of an extra per-thread flag and the -add_peratom_vary() method when last dimension of the array is +In ``Atom::peratom_create()`` when using the ``Atom::add_peratom()`` +method, a cols argument of 0 is for per-atom vectors, a length > +1 is for per-atom arrays. Note the use of the extra per-thread flag and +the add_peratom_vary() method when last dimension of the array is variable-length. -Adding the variable name to Atom::extract() enable the per-atom data +Adding the variable name to Atom::extract() enables the per-atom data to be accessed through the :doc:`LAMMPS library interface ` by a calling code, including from :doc:`Python `. The constructor of the new atom style will also typically set a few -flags which are defined at the top of atom_vec.h. If these are +flags which are defined at the top of ``atom_vec.h``. If these are unclear, see how other atom styles use them. -The grow_pointers() method is also required to make -a copy of peratom data pointers, as explained in the code. +The grow_pointers() method is also required to make a copy of peratom +data pointers, as explained in the code. There are a number of other optional methods which your atom style can implement. These are only needed if you need to do something diff --git a/doc/src/compute_rigid_local.rst b/doc/src/compute_rigid_local.rst index 574f3343be..6817f0ac1e 100644 --- a/doc/src/compute_rigid_local.rst +++ b/doc/src/compute_rigid_local.rst @@ -127,19 +127,16 @@ The *vx*, *vy*, *vz*, *fx*, *fy*, *fz* attributes are components of the COM velocity and force on the COM of the body. The *omegax*, *omegay*, and *omegaz* attributes are the angular -velocity components of the body around its COM. +velocity components of the body in the system frame around its COM. The *angmomx*, *angmomy*, and *angmomz* attributes are the angular -momentum components of the body around its COM. +momentum components of the body in the system frame around its COM. The *quatw*, *quati*, *quatj*, and *quatk* attributes are the components of the 4-vector quaternion representing the orientation of the rigid body. See the :doc:`set ` command for an explanation of the quaternion vector. -The *angmomx*, *angmomy*, and *angmomz* attributes are the angular -momentum components of the body around its COM. - The *tqx*, *tqy*, *tqz* attributes are components of the torque acting on the body around its COM. diff --git a/doc/src/compute_temp_profile.rst b/doc/src/compute_temp_profile.rst index b70206781f..e5830f5cf7 100644 --- a/doc/src/compute_temp_profile.rst +++ b/doc/src/compute_temp_profile.rst @@ -76,21 +76,28 @@ velocity for each atom. Note that if there is only one atom in the bin, its thermal velocity will thus be 0.0. After the spatially-averaged velocity field has been subtracted from -each atom, the temperature is calculated by the formula KE = (dim\*N -- dim\*Nx\*Ny\*Nz) k T/2, where KE = total kinetic energy of the group of -atoms (sum of 1/2 m v\^2), dim = 2 or 3 = dimensionality of the -simulation, N = number of atoms in the group, k = Boltzmann constant, -and T = temperature. The dim\*Nx\*Ny\*Nz term are degrees of freedom -subtracted to adjust for the removal of the center-of-mass velocity in -each of Nx\*Ny\*Nz bins, as discussed in the :ref:`(Evans) ` paper. +each atom, the temperature is calculated by the formula +*KE* = (*dim\*N* - *Ns\*Nx\*Ny\*Nz* - *extra* ) *k* *T*/2, where *KE* = total +kinetic energy of the group of atoms (sum of 1/2 *m* *v*\^2), *dim* = 2 +or 3 = dimensionality of the simulation, *Ns* = 0, 1, 2 or 3 for +streaming velocity subtracted in 0, 1, 2 or 3 dimensions, *extra* = extra +degrees-of-freedom, *N* = number of atoms in the group, *k* = Boltzmann +constant, and *T* = temperature. The *Ns\*Nx\*Ny\*Nz* term is degrees +of freedom subtracted to adjust for the removal of the center-of-mass +velocity in each direction of the *Nx\*Ny\*Nz* bins, as discussed in the +:ref:`(Evans) ` paper. The extra term defaults to (*dim* - *Ns*) +and accounts for overall conservation of center-of-mass velocity across +the group in directions where streaming velocity is *not* subtracted. This +can be altered using the *extra* option of the +:doc:`compute_modify ` command. If the *out* keyword is used with a *tensor* value, which is the default, a kinetic energy tensor, stored as a 6-element vector, is also calculated by this compute for use in the computation of a pressure tensor. The formula for the components of the tensor is the -same as the above formula, except that v\^2 is replaced by vx\*vy for -the xy component, etc. The 6 components of the vector are ordered xx, -yy, zz, xy, xz, yz. +same as the above formula, except that *v*\^2 is replaced by *vx\*vy* for +the xy component, etc. The 6 components of the vector are ordered *xx, +yy, zz, xy, xz, yz.* If the *out* keyword is used with a *bin* value, the count of atoms and computed temperature for each bin are stored for output, as an @@ -123,10 +130,20 @@ needed, the subtracted degrees-of-freedom can be altered using the .. note:: When using the *out* keyword with a value of *bin*, the - calculated temperature for each bin does not include the - degrees-of-freedom adjustment described in the preceding paragraph, - for fixes that constrain molecular motion. It does include the - adjustment due to the *extra* option, which is applied to each bin. + calculated temperature for each bin includes the degrees-of-freedom + adjustment described in the preceding paragraph for fixes that + constrain molecular motion, as well as the adjustment due to + the *extra* option (which defaults to *dim* - *Ns* as described above), + by fractionally applying them based on the fraction of atoms in each + bin. As a result, the bin degrees-of-freedom summed over all bins exactly + equals the degrees-of-freedom used in the scalar temperature calculation, + :math:`\Sigma N_{DOF_i} = N_{DOF}` and the corresponding relation for temperature + is also satisfied :math:`\Sigma N_{DOF_i} T_i = N_{DOF} T`. + These relations will breakdown in cases where the adjustment + exceeds the actual number of degrees-of-freedom in a bin. This could happen + if a bin is empty or in situations where rigid molecules + are non-uniformly distributed, in which case the reported + temperature within a bin may not be accurate. See the :doc:`Howto thermostat ` page for a discussion of different ways to compute temperature and perform diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index b7151334db..1276adf444 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -14,7 +14,7 @@ Syntax * adapt = style name of this fix command * N = adapt simulation settings every this many timesteps * one or more attribute/arg pairs may be appended -* attribute = *pair* or *bond* or *kspace* or *atom* +* attribute = *pair* or *bond* or *angle* or *kspace* or *atom* .. parsed-literal:: @@ -28,11 +28,16 @@ Syntax bparam = parameter to adapt over time I = type bond to set parameter for v_name = variable with name that calculates value of bparam + *angle* args = astyle aparam I v_name + astyle = angle style name, e.g. harmonic + aparam = parameter to adapt over time + I = type angle to set parameter for + v_name = variable with name that calculates value of aparam *kspace* arg = v_name v_name = variable with name that calculates scale factor on K-space terms - *atom* args = aparam v_name - aparam = parameter to adapt over time - v_name = variable with name that calculates value of aparam + *atom* args = atomparam v_name + atomparam = parameter to adapt over time + v_name = variable with name that calculates value of atomparam * zero or more keyword/value pairs may be appended * keyword = *scale* or *reset* or *mass* @@ -283,30 +288,62 @@ operates. The only difference is that now a bond coefficient for a given bond type is adapted. A wild-card asterisk can be used in place of or in conjunction with -the bond type argument to set the coefficients for multiple bond types. -This takes the form "\*" or "\*n" or "n\*" or "m\*n". If N = the number of -atom types, then an asterisk with no numeric values means all types -from 1 to N. A leading asterisk means all types from 1 to n (inclusive). -A trailing asterisk means all types from n to N (inclusive). A middle -asterisk means all types from m to n (inclusive). +the bond type argument to set the coefficients for multiple bond +types. This takes the form "\*" or "\*n" or "n\*" or "m\*n". If N = +the number of bond types, then an asterisk with no numeric values +means all types from 1 to N. A leading asterisk means all types from +1 to n (inclusive). A trailing asterisk means all types from n to N +(inclusive). A middle asterisk means all types from m to n +(inclusive). Currently *bond* does not support bond_style hybrid nor bond_style -hybrid/overlay as bond styles. The only bonds that currently are -working with fix_adapt are +hybrid/overlay as bond styles. The bond styles that currently work +with fix_adapt are -+------------------------------------+-------+------------+ -| :doc:`class2 ` | r0 | type bonds | -+------------------------------------+-------+------------+ -| :doc:`fene ` | k, r0 | type bonds | -+------------------------------------+-------+------------+ -| :doc:`gromos ` | k, r0 | type bonds | -+------------------------------------+-------+------------+ -| :doc:`harmonic ` | k,r0 | type bonds | -+------------------------------------+-------+------------+ -| :doc:`morse ` | r0 | type bonds | -+------------------------------------+-------+------------+ -| :doc:`nonlinear ` | r0 | type bonds | -+------------------------------------+-------+------------+ ++------------------------------------+-------+-----------------+ +| :doc:`class2 ` | r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`fene ` | k,r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`fene/nm ` | k,r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`gromos ` | k,r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`harmonic ` | k,r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`morse ` | r0 | type bonds | ++------------------------------------+-------+-----------------+ +| :doc:`nonlinear ` | epsilon,r0 | type bonds | ++------------------------------------+-------+-----------------+ + +---------- + +The *angle* keyword uses the specified variable to change the value of +an angle coefficient over time, very similar to how the *pair* keyword +operates. The only difference is that now an angle coefficient for a +given angle type is adapted. + +A wild-card asterisk can be used in place of or in conjunction with +the angle type argument to set the coefficients for multiple angle +types. This takes the form "\*" or "\*n" or "n\*" or "m\*n". If N = +the number of angle types, then an asterisk with no numeric values +means all types from 1 to N. A leading asterisk means all types from +1 to n (inclusive). A trailing asterisk means all types from n to N +(inclusive). A middle asterisk means all types from m to n +(inclusive). + +Currently *angle* does not support angle_style hybrid nor angle_style +hybrid/overlay as angle styles. The angle styles that currently work +with fix_adapt are + ++------------------------------------+-------+-----------------+ +| :doc:`harmonic ` | k,theta0 | type angles | ++------------------------------------+-------+-----------------+ +| :doc:`cosine ` | k | type angles | ++------------------------------------+-------+-----------------+ + +Note that internally, theta0 is stored in radians, so the variable +this fix uses to reset theta0 needs to generate values in radians. ---------- diff --git a/doc/src/fix_nve.rst b/doc/src/fix_nve.rst index da2184c99f..dc17f844cd 100644 --- a/doc/src/fix_nve.rst +++ b/doc/src/fix_nve.rst @@ -35,6 +35,10 @@ consistent with the microcanonical ensemble (NVE) provided there are (full) periodic boundary conditions and no other "manipulations" of the system (e.g. fixes that modify forces or velocities). +This fix invokes the velocity form of the +Störmer-Verlet time integration algorithm (velocity-Verlet). Other +time integration options can be invoked using the :doc:`run_style ` command. + ---------- .. include:: accel_styles.rst @@ -57,7 +61,7 @@ Restrictions Related commands """""""""""""""" -:doc:`fix nvt `, :doc:`fix npt ` +:doc:`fix nvt `, :doc:`fix npt `, :doc:`run_style ` Default """"""" diff --git a/doc/src/fix_property_atom.rst b/doc/src/fix_property_atom.rst index cc92c18655..09286cca38 100644 --- a/doc/src/fix_property_atom.rst +++ b/doc/src/fix_property_atom.rst @@ -304,13 +304,15 @@ uninterrupted fashion. .. warning:: When reading data from a restart file, this fix command has to be - specified **exactly** the same was in the input script that created - the restart file. LAMMPS will only check whether a fix is of the - same style and has the same fix ID and in case of a match will then - try to initialize the fix with the data stored in the binary - restart file. If the names and associated date types in the new - fix property/atom command do not match the old one exactly, data - can be corrupted or LAMMPS may crash. + specified **after** the *read_restart* command and **exactly** the + same was in the input script that created the restart file. LAMMPS + will only check whether a fix is of the same style and has the same + fix ID and in case of a match will then try to initialize the fix + with the data stored in the binary restart file. If the names and + associated date types in the new fix property/atom command do not + match the old one exactly, data can be corrupted or LAMMPS may crash. + If the fix is specified **before** the *read_restart* command its + data will not be restored. None of the :doc:`fix_modify ` options are relevant to this fix. No global or per-atom quantities are stored by this fix for diff --git a/doc/src/fix_ttm.rst b/doc/src/fix_ttm.rst index c2b4f2cf97..d146321395 100644 --- a/doc/src/fix_ttm.rst +++ b/doc/src/fix_ttm.rst @@ -217,7 +217,7 @@ units used. .. note:: The electronic temperature at each grid point must be a non-zero - positive value, both initially, and as the temperature evovles over + positive value, both initially, and as the temperature evolves over time. Thus you must use either the *set* or *infile* keyword or be restarting a simulation that used this fix previously. diff --git a/doc/src/group.rst b/doc/src/group.rst index 1720ecfe1a..9d93e949f9 100644 --- a/doc/src/group.rst +++ b/doc/src/group.rst @@ -258,11 +258,17 @@ assignment is made at the beginning of the minimization, but not during the iterations of the minimizer. The point in the timestep at which atoms are assigned to a dynamic -group is after the initial stage of velocity Verlet time integration -has been performed, and before neighbor lists or forces are computed. -This is the point in the timestep where atom positions have just -changed due to the time integration, so the region criterion should be -accurate, if applied. +group is after interatomic forces have been computed, but before any +fixes which alter forces or otherwise update the system have been +invoked. This means that atom positions have been updated, neighbor +lists and ghost atoms are current, and both intermolecular and +intramolecular forces have been calculated based on the new +coordinates. Thus the region criterion, if applied, should be +accurate. Also, any computes invoked by an atom-style variable should +use updated information for that timestep, e.g. potential energy/atom +or coordination number/atom. Similarly, fixes or computes which are +invoked after that point in the timestep, should operate on the new +group of atoms. .. note:: diff --git a/doc/src/run_style.rst b/doc/src/run_style.rst index fd63c82b90..8becbec671 100644 --- a/doc/src/run_style.rst +++ b/doc/src/run_style.rst @@ -67,7 +67,8 @@ Description Choose the style of time integrator used for molecular dynamics simulations performed by LAMMPS. -The *verlet* style is a standard velocity-Verlet integrator. +The *verlet* style is the velocity form of the +Störmer-Verlet time integration algorithm (velocity-Verlet) ---------- diff --git a/doc/src/thermo_modify.rst b/doc/src/thermo_modify.rst index ffdbf020a1..225dafdc33 100644 --- a/doc/src/thermo_modify.rst +++ b/doc/src/thermo_modify.rst @@ -252,6 +252,6 @@ flush = no, and temp/press = compute IDs defined by thermo_style. The defaults for the line and format options depend on the thermo style. For styles "one" and "custom", the line and format defaults are "one", -"%10d", and "%12.8g". For style "multi", the line and format defaults +"%10d", and "%14.8g". For style "multi", the line and format defaults are "multi", "%14d", and "%14.4f". For style "yaml", the line and format defaults are "%d" and "%.15g". diff --git a/doc/src/thermo_style.rst b/doc/src/thermo_style.rst index ff0e41ffb0..5d63ed81b6 100644 --- a/doc/src/thermo_style.rst +++ b/doc/src/thermo_style.rst @@ -10,7 +10,7 @@ Syntax thermo_style style args -* style = *one* or *multi* *yaml* or *custom* +* style = *one* or *multi* or *yaml* or *custom* * args = list of arguments for a particular style .. parsed-literal:: diff --git a/doc/utils/requirements.txt b/doc/utils/requirements.txt index 1f5711dd6b..9ff18b3652 100644 --- a/doc/utils/requirements.txt +++ b/doc/utils/requirements.txt @@ -6,3 +6,4 @@ breathe Pygments six pyyaml +wheel diff --git a/src/AWPMD/atom_vec_wavepacket.cpp b/src/AWPMD/atom_vec_wavepacket.cpp index c339e8343f..59a503571e 100644 --- a/src/AWPMD/atom_vec_wavepacket.cpp +++ b/src/AWPMD/atom_vec_wavepacket.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -20,8 +19,6 @@ #include "atom.h" -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -32,33 +29,29 @@ AtomVecWavepacket::AtomVecWavepacket(LAMMPS *lmp) : AtomVec(lmp) molecular = Atom::ATOMIC; forceclearflag = 1; - atom->wavepacket_flag = 1; - atom->electron_flag = 1; // compatible with eff - atom->q_flag = atom->spin_flag = atom->eradius_flag = - atom->ervel_flag = atom->erforce_flag = 1; - atom->cs_flag = atom->csforce_flag = - atom->vforce_flag = atom->ervelforce_flag = atom->etag_flag = 1; + atom->wavepacket_flag = atom->q_flag = atom->spin_flag = atom->eradius_flag = 1; + atom->ervel_flag = atom->erforce_flag = atom->cs_flag = atom->csforce_flag = 1; + atom->vforce_flag = atom->ervelforce_flag = atom->etag_flag = 1; // strings with peratom variables to include in each AtomVec method // strings cannot contain fields in corresponding AtomVec default strings // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "q spin eradius ervel erforce cs csforce " - "vforce ervelforce etag"; - fields_copy = (char *) "q spin eradius ervel cs etag"; - fields_comm = (char *) "eradius"; - fields_comm_vel = (char *) "eradius ervel cs"; - fields_reverse = (char *) "erforce ervelforce vforce csforce"; - fields_border = (char *) "q spin eradius etag"; - fields_border_vel = (char *) "q spin eradius etag ervel cs"; - fields_exchange = (char *) "q spin eradius ervel etag cs"; - fields_restart = (char *) "q spin eradius ervel etag cs"; - fields_create = (char *) "q spin eradius ervel etag cs"; - fields_data_atom = (char *) "id type q spin eradius etag cs x"; - fields_data_vel = (char *) "id v ervel"; + fields_grow = {"q", "spin", "eradius", "ervel", "erforce", + "cs", "csforce", "vforce", "ervelforce", "etag"}; + fields_copy = {"q", "spin", "eradius", "ervel", "cs", "etag"}; + fields_comm = {"eradius"}; + fields_comm_vel = {"eradius", "ervel", "cs"}; + fields_reverse = {"erforce", "ervelforce", "vforce", "csforce"}; + fields_border = {"q", "spin", "eradius", "etag"}; + fields_border_vel = {"q", "spin", "eradius", "etag", "ervel", "cs"}; + fields_exchange = {"q", "spin", "eradius", "ervel", "etag", "cs"}; + fields_restart = {"q", "spin", "eradius", "ervel", "etag", "cs"}; + fields_create = {"q", "spin", "eradius", "ervel", "etag", "cs"}; + fields_data_atom = {"id", "type", "q", "spin", "eradius", "etag", "cs", "x"}; + fields_data_vel = {"id", "v", "ervel"}; setup_fields(); } @@ -84,7 +77,7 @@ void AtomVecWavepacket::grow_pointers() void AtomVecWavepacket::force_clear(int n, size_t nbytes) { - memset(&erforce[n],0,nbytes); + memset(&erforce[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -112,12 +105,12 @@ void AtomVecWavepacket::data_atom_post(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecWavepacket::property_atom(char *name) +int AtomVecWavepacket::property_atom(const std::string &name) { - if (strcmp(name,"spin") == 0) return 0; - if (strcmp(name,"eradius") == 0) return 1; - if (strcmp(name,"ervel") == 0) return 2; - if (strcmp(name,"erforce") == 0) return 3; + if (name == "spin") return 0; + if (name == "eradius") return 1; + if (name == "ervel") return 2; + if (name == "erforce") return 3; return -1; } @@ -126,34 +119,41 @@ int AtomVecWavepacket::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecWavepacket::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecWavepacket::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int nlocal = atom->nlocal; int n = 0; if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = spin[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = spin[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = eradius[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = eradius[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 2) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = ervel[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = ervel[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 3) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = erforce[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = erforce[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/AWPMD/atom_vec_wavepacket.h b/src/AWPMD/atom_vec_wavepacket.h index 0a23e23019..9ceaadbb5a 100644 --- a/src/AWPMD/atom_vec_wavepacket.h +++ b/src/AWPMD/atom_vec_wavepacket.h @@ -32,7 +32,7 @@ class AtomVecWavepacket : public AtomVec { void force_clear(int, size_t) override; void create_atom_post(int) override; void data_atom_post(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: diff --git a/src/BPM/atom_vec_bpm_sphere.cpp b/src/BPM/atom_vec_bpm_sphere.cpp index 3b775cdd83..460377db6b 100644 --- a/src/BPM/atom_vec_bpm_sphere.cpp +++ b/src/BPM/atom_vec_bpm_sphere.cpp @@ -14,6 +14,7 @@ #include "atom_vec_bpm_sphere.h" #include "atom.h" +#include "comm.h" #include "error.h" #include "fix.h" #include "fix_adapt.h" @@ -43,23 +44,21 @@ AtomVecBPMSphere::AtomVecBPMSphere(LAMMPS *_lmp) : AtomVec(_lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - // clang-format off - fields_grow = (char *) "molecule num_bond bond_type bond_atom nspecial special radius rmass " - "omega torque quat"; - fields_copy = (char *) "molecule num_bond bond_type bond_atom nspecial special radius rmass " - "omega quat"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "omega quat"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "molecule radius rmass"; - fields_border_vel = (char *) "molecule radius rmass omega quat"; - fields_exchange = (char *) "molecule num_bond bond_type bond_atom nspecial special radius rmass " - "omega quat"; - fields_restart = (char *) "molecule num_bond bond_type bond_atom radius rmass omega quat"; - fields_create = (char *) "molecule num_bond nspecial radius rmass omega quat"; - fields_data_atom = (char *) "id molecule type radius rmass x"; - fields_data_vel = (char *) "id v omega"; - // clang-format on + fields_grow = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", "special", + "radius", "rmass", "omega", "torque", "quat"}; + fields_copy = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", + "special", "radius", "rmass", "omega", "quat"}; + fields_comm_vel = {"omega", "quat"}; + fields_reverse = {"torque"}; + fields_border = {"molecule", "radius", "rmass"}; + fields_border_vel = {"molecule", "radius", "rmass", "omega", "quat"}; + fields_exchange = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", + "special", "radius", "rmass", "omega", "quat"}; + fields_restart = {"molecule", "num_bond", "bond_type", "bond_atom", + "radius", "rmass", "omega", "quat"}; + fields_create = {"molecule", "num_bond", "nspecial", "radius", "rmass", "omega", "quat"}; + fields_data_atom = {"id", "molecule", "type", "radius", "rmass", "x"}; + fields_data_vel = {"id", "v", "omega"}; bond_per_atom = 0; bond_negative = NULL; @@ -83,8 +82,8 @@ void AtomVecBPMSphere::process_args(int narg, char **arg) // dynamic particle radius and mass must be communicated every step if (radvary) { - fields_comm = (char *) "radius rmass"; - fields_comm_vel = (char *) "radius rmass omega"; + fields_comm = {"radius", "rmass"}; + fields_comm_vel = {"radius", "rmass", "omega"}; } // delay setting up of fields until now @@ -100,12 +99,16 @@ void AtomVecBPMSphere::init() // check if optional radvary setting should have been set to 1 - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style, "adapt") == 0) { - FixAdapt *fix = (FixAdapt *) modify->fix[i]; - if (fix->diamflag && radvary == 0) + for (auto ifix : modify->get_fix_by_style("^adapt")) { + if (radvary == 0) { + if ((strcmp(ifix->style, "adapt") == 0) && (dynamic_cast(ifix)->diamflag)) error->all(FLERR, "Fix adapt changes atom radii but atom_style bpm/sphere is not dynamic"); + // cannot properly check for fix adapt/fep since its header is optional + if ((strcmp(ifix->style, "adapt/fep") == 0) && (comm->me == 0)) + error->warning( + FLERR, "Fix adapt/fep may change atom radii but atom_style bpm/sphere is not dynamic"); } + } } /* ---------------------------------------------------------------------- diff --git a/src/BPM/atom_vec_bpm_sphere.h b/src/BPM/atom_vec_bpm_sphere.h index e7672eeb3c..c6f80b89d9 100644 --- a/src/BPM/atom_vec_bpm_sphere.h +++ b/src/BPM/atom_vec_bpm_sphere.h @@ -45,7 +45,7 @@ class AtomVecBPMSphere : public AtomVec { int **nspecial; double *radius, *rmass; - double **omega, **torque, **quat; + double **omega, **quat; int any_bond_negative; int bond_per_atom; diff --git a/src/BPM/pair_bpm_spring.cpp b/src/BPM/pair_bpm_spring.cpp index 0dd113e2ed..40f40b8a3b 100644 --- a/src/BPM/pair_bpm_spring.cpp +++ b/src/BPM/pair_bpm_spring.cpp @@ -253,13 +253,13 @@ void PairBPMSpring::read_restart(FILE *fp) int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { - if (me == 0) fread(&setflag[i][j], sizeof(int), 1, fp); + if (me == 0) utils::sfread(FLERR, &setflag[i][j], sizeof(int), 1, fp, nullptr, error); MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world); if (setflag[i][j]) { if (me == 0) { - fread(&k[i][j], sizeof(double), 1, fp); - fread(&cut[i][j], sizeof(double), 1, fp); - fread(&gamma[i][j], sizeof(double), 1, fp); + utils::sfread(FLERR, &k[i][j], sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &cut[i][j], sizeof(double), 1, fp, nullptr, error); + utils::sfread(FLERR, &gamma[i][j], sizeof(double), 1, fp, nullptr, error); } MPI_Bcast(&k[i][j], 1, MPI_DOUBLE, 0, world); MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world); diff --git a/src/CG-DNA/atom_vec_oxdna.cpp b/src/CG-DNA/atom_vec_oxdna.cpp index 120fe5d9ac..52380eca57 100644 --- a/src/CG-DNA/atom_vec_oxdna.cpp +++ b/src/CG-DNA/atom_vec_oxdna.cpp @@ -33,18 +33,13 @@ AtomVecOxdna::AtomVecOxdna(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "id5p"; - fields_copy = (char *) "id5p"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "id5p"; - fields_border_vel = (char *) ""; - fields_exchange = (char *) "id5p"; - fields_restart = (char *) "id5p"; - fields_create = (char *) ""; - fields_data_atom = (char *) "id type x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"id5p"}; + fields_copy = {"id5p"}; + fields_border = {"id5p"}; + fields_exchange = {"id5p"}; + fields_restart = {"id5p"}; + fields_data_atom = {"id", "type", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); diff --git a/src/DIELECTRIC/atom_vec_dielectric.cpp b/src/DIELECTRIC/atom_vec_dielectric.cpp index 89ce8da9a6..b15b233991 100644 --- a/src/DIELECTRIC/atom_vec_dielectric.cpp +++ b/src/DIELECTRIC/atom_vec_dielectric.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/ Sandia National Laboratories @@ -18,23 +17,21 @@ #include "citeme.h" #include -#include using namespace LAMMPS_NS; static const char cite_user_dielectric_package[] = - "DIELECTRIC package:\n\n" - "@Article{TrungCPC19,\n" - " author = {Trung Dac Nguyen, Honghao Li, Debarshee Bagchi," - " Francisco J. Solis, Monica Olvera de la Cruz,\n" - " title = {Incorporating surface polarization effects into large-scale" - " coarse-grained Molecular Dynamics simulation},\n" - " journal = {Comp.~Phys.~Comm.},\n" - " year = 2019,\n" - " volume = 241,\n" - " pages = {80--91}\n" - "}\n\n" - ; + "DIELECTRIC package:\n\n" + "@Article{TrungCPC19,\n" + " author = {Trung Dac Nguyen, Honghao Li, Debarshee Bagchi," + " Francisco J. Solis, Monica Olvera de la Cruz,\n" + " title = {Incorporating surface polarization effects into large-scale" + " coarse-grained Molecular Dynamics simulation},\n" + " journal = {Comp.~Phys.~Comm.},\n" + " year = 2019,\n" + " volume = 241,\n" + " pages = {80--91}\n" + "}\n\n"; /* ---------------------------------------------------------------------- */ @@ -54,55 +51,39 @@ AtomVecDielectric::AtomVecDielectric(LAMMPS *_lmp) : AtomVec(_lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special " - "mu area ed em epsilon curvature q_unscaled"; - fields_copy = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special " - "mu area ed em epsilon curvature q_unscaled"; - fields_comm = (char *) "q mu area ed em epsilon curvature q_unscaled"; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "q molecule mu area ed em epsilon curvature q_unscaled"; - fields_border_vel = (char *) "q molecule mu area ed em epsilon curvature q_unscaled"; - fields_exchange = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special " - "mu area ed em epsilon curvature q_unscaled"; - fields_restart = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "mu area ed em epsilon curvature q_unscaled"; - fields_create = (char *) - "q molecule num_bond num_angle num_dihedral num_improper nspecial " - "mu area ed em epsilon curvature q_unscaled"; - fields_data_atom = (char *) "id molecule type q x " - "mu3 area ed em epsilon curvature"; - fields_data_vel = (char *) "id v"; + // clang-format off + fields_grow = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special", + "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_copy = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special", + "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_comm = {"q", "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_border = {"q", "molecule", "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_border_vel = {"q", "molecule", "mu", "area", "ed", "em", "epsilon", "curvature", + "q_unscaled"}; + fields_exchange = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", + "angle_type", "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", + "dihedral_atom1", "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", + "improper_type", "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", + "nspecial", "special", "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_restart = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", + "angle_type", "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", + "dihedral_atom1", "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", + "improper_type", "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", + "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_create = {"q", "molecule", "num_bond", "num_angle", "num_dihedral", "num_improper", + "nspecial", "mu", "area", "ed", "em", "epsilon", "curvature", "q_unscaled"}; + fields_data_atom = { "id", "molecule", "type", "q", "x", "mu3", "area", "ed", "em", "epsilon", + "curvature"}; + fields_data_vel = {"id v"}; + // clang-format on setup_fields(); - bond_per_atom = angle_per_atom = dihedral_per_atom = improper_per_atom = 0; } @@ -158,13 +139,12 @@ void AtomVecDielectric::data_atom_post(int ilocal) nspecial[ilocal][1] = 0; nspecial[ilocal][2] = 0; - double* q = atom->q; + double *q = atom->q; q_unscaled[ilocal] = q[ilocal]; q[ilocal] /= epsilon[ilocal]; double *mu_one = mu[ilocal]; - mu_one[3] = - sqrt(mu_one[0]*mu_one[0] + mu_one[1]*mu_one[1] + mu_one[2]*mu_one[2]); + mu_one[3] = sqrt(mu_one[0] * mu_one[0] + mu_one[1] * mu_one[1] + mu_one[2] * mu_one[2]); } /* ---------------------------------------------------------------------- @@ -183,14 +163,14 @@ void AtomVecDielectric::unpack_restart_init(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecDielectric::property_atom(char *name) +int AtomVecDielectric::property_atom(const std::string &name) { - if (strcmp(name,"area") == 0) return 0; - if (strcmp(name,"ed") == 0) return 1; - if (strcmp(name,"em") == 0) return 2; - if (strcmp(name,"epsilon") == 0) return 3; - if (strcmp(name,"curvature") == 0) return 4; - if (strcmp(name,"q_unscaled") == 0) return 5; + if (name == "area") return 0; + if (name == "ed") return 1; + if (name == "em") return 2; + if (name == "epsilon") return 3; + if (name == "curvature") return 4; + if (name == "q_unscaled") return 5; return -1; } @@ -199,8 +179,7 @@ int AtomVecDielectric::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecDielectric::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecDielectric::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int *mask = atom->mask; int nlocal = atom->nlocal; @@ -208,38 +187,50 @@ void AtomVecDielectric::pack_property_atom(int index, double *buf, if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = area[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = area[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = ed[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = ed[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 2) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = em[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = em[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 3) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = epsilon[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = epsilon[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 4) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = curvature[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = curvature[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 5) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = q_unscaled[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = q_unscaled[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/DIELECTRIC/atom_vec_dielectric.h b/src/DIELECTRIC/atom_vec_dielectric.h index 2d4510b330..7e38164582 100644 --- a/src/DIELECTRIC/atom_vec_dielectric.h +++ b/src/DIELECTRIC/atom_vec_dielectric.h @@ -35,7 +35,7 @@ class AtomVecDielectric : public AtomVec { void create_atom_post(int) override; void data_atom_post(int) override; void unpack_restart_init(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; protected: diff --git a/src/DIPOLE/atom_vec_dipole.cpp b/src/DIPOLE/atom_vec_dipole.cpp index a38e1d6d01..2e9fd4226c 100644 --- a/src/DIPOLE/atom_vec_dipole.cpp +++ b/src/DIPOLE/atom_vec_dipole.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -34,18 +33,17 @@ AtomVecDipole::AtomVecDipole(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "q mu"; - fields_copy = (char *) "q mu"; - fields_comm = (char *) "mu3"; - fields_comm_vel = (char *) "mu3"; - fields_reverse = (char *) ""; - fields_border = (char *) "q mu"; - fields_border_vel = (char *) "q mu"; - fields_exchange = (char *) "q mu"; - fields_restart = (char *) "q mu"; - fields_create = (char *) "q mu"; - fields_data_atom = (char *) "id type q x mu3"; - fields_data_vel = (char *) "id v"; + fields_grow = {"q", "mu"}; + fields_copy = {"q", "mu"}; + fields_comm = {"mu3"}; + fields_comm_vel = {"mu3"}; + fields_border = {"q", "mu"}; + fields_border_vel = {"q", "mu"}; + fields_exchange = {"q", "mu"}; + fields_restart = {"q", "mu"}; + fields_create = {"q", "mu"}; + fields_data_atom = {"id", "type", "q", "x", "mu3"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -68,6 +66,5 @@ void AtomVecDipole::grow_pointers() void AtomVecDipole::data_atom_post(int ilocal) { double *mu_one = mu[ilocal]; - mu_one[3] = - sqrt(mu_one[0]*mu_one[0] + mu_one[1]*mu_one[1] + mu_one[2]*mu_one[2]); + mu_one[3] = sqrt(mu_one[0] * mu_one[0] + mu_one[1] * mu_one[1] + mu_one[2] * mu_one[2]); } diff --git a/src/DPD-MESO/atom_vec_edpd.cpp b/src/DPD-MESO/atom_vec_edpd.cpp index cf7c8ed29f..d8592d26f5 100644 --- a/src/DPD-MESO/atom_vec_edpd.cpp +++ b/src/DPD-MESO/atom_vec_edpd.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -38,18 +37,18 @@ AtomVecEDPD::AtomVecEDPD(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "edpd_cv edpd_temp edpd_flux vest vest_temp"; - fields_copy = (char *) "edpd_cv edpd_temp edpd_flux vest vest_temp"; - fields_comm = (char *) "edpd_temp vest vest_temp"; - fields_comm_vel = (char *) "edpd_temp vest vest_temp"; - fields_reverse = (char *) "edpd_flux"; - fields_border = (char *) "edpd_cv edpd_temp vest vest_temp"; - fields_border_vel = (char *) "edpd_cv edpd_temp vest vest_temp"; - fields_exchange = (char *) "edpd_cv edpd_temp vest vest_temp"; - fields_restart = (char * ) "edpd_cv edpd_temp vest vest_temp"; - fields_create = (char *) "edpd_cv edpd_temp edpd_flux vest vest_temp"; - fields_data_atom = (char *) "id type edpd_temp edpd_cv x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"edpd_cv", "edpd_temp", "edpd_flux", "vest", "vest_temp"}; + fields_copy = {"edpd_cv", "edpd_temp", "edpd_flux", "vest", "vest_temp"}; + fields_comm = {"edpd_temp", "vest", "vest_temp"}; + fields_comm_vel = {"edpd_temp", "vest", "vest_temp"}; + fields_reverse = {"edpd_flux"}; + fields_border = {"edpd_cv", "edpd_temp", "vest", "vest_temp"}; + fields_border_vel = {"edpd_cv", "edpd_temp", "vest", "vest_temp"}; + fields_exchange = {"edpd_cv", "edpd_temp", "vest", "vest_temp"}; + fields_restart = {"edpd_cv", "edpd_temp", "vest", "vest_temp"}; + fields_create = {"edpd_cv", "edpd_temp", "edpd_flux", "vest", "vest_temp"}; + fields_data_atom = {"id", "type", "edpd_temp", "edpd_cv", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -60,8 +59,7 @@ void AtomVecEDPD::init() { AtomVec::init(); - if (strcmp(update->unit_style,"lj") != 0) - error->all(FLERR,"Atom style edpd requires lj units"); + if (strcmp(update->unit_style, "lj") != 0) error->all(FLERR, "Atom style edpd requires lj units"); } /* ---------------------------------------------------------------------- @@ -85,7 +83,7 @@ void AtomVecEDPD::grow_pointers() void AtomVecEDPD::force_clear(int n, size_t nbytes) { - memset(&edpd_flux[n],0,nbytes); + memset(&edpd_flux[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -95,7 +93,7 @@ void AtomVecEDPD::force_clear(int n, size_t nbytes) void AtomVecEDPD::create_atom_post(int ilocal) { edpd_temp[ilocal] = 1.0; - edpd_cv[ilocal]= 1.0e5; + edpd_cv[ilocal] = 1.0e5; vest_temp[ilocal] = edpd_temp[ilocal]; } diff --git a/src/DPD-MESO/atom_vec_mdpd.cpp b/src/DPD-MESO/atom_vec_mdpd.cpp index 5a05d33b79..4b9b58b0d6 100644 --- a/src/DPD-MESO/atom_vec_mdpd.cpp +++ b/src/DPD-MESO/atom_vec_mdpd.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -13,10 +12,12 @@ ------------------------------------------------------------------------- */ #include "atom_vec_mdpd.h" -#include + #include "atom.h" -#include "update.h" #include "error.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -36,18 +37,18 @@ AtomVecMDPD::AtomVecMDPD(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rho drho vest"; - fields_copy = (char *) "rho drho vest"; - fields_comm = (char *) "rho vest"; - fields_comm_vel = (char *) "rho vest"; - fields_reverse = (char *) "drho"; - fields_border = (char *) "rho vest"; - fields_border_vel = (char *) "rho vest"; - fields_exchange = (char *) "rho vest"; - fields_restart = (char * ) "rho vest"; - fields_create = (char *) "rho drho vest"; - fields_data_atom = (char *) "id type rho x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"rho", "drho", "vest"}; + fields_copy = {"rho", "drho", "vest"}; + fields_comm = {"rho", "vest"}; + fields_comm_vel = {"rho", "vest"}; + fields_reverse = {"drho"}; + fields_border = {"rho", "vest"}; + fields_border_vel = {"rho", "vest"}; + fields_exchange = {"rho", "vest"}; + fields_restart = {"rho", "vest"}; + fields_create = {"rho", "drho", "vest"}; + fields_data_atom = {"id", "type", "rho", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -58,8 +59,7 @@ void AtomVecMDPD::init() { AtomVec::init(); - if (strcmp(update->unit_style,"lj") != 0) - error->all(FLERR,"Atom style mdpd requires lj units"); + if (strcmp(update->unit_style, "lj") != 0) error->all(FLERR, "Atom style mdpd requires lj units"); } /* ---------------------------------------------------------------------- @@ -81,7 +81,7 @@ void AtomVecMDPD::grow_pointers() void AtomVecMDPD::force_clear(int n, size_t nbytes) { - memset(&drho[n],0,nbytes); + memset(&drho[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -102,10 +102,10 @@ void AtomVecMDPD::data_atom_post(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecMDPD::property_atom(char *name) +int AtomVecMDPD::property_atom(const std::string &name) { - if (strcmp(name,"rho") == 0) return 0; - if (strcmp(name,"drho") == 0) return 1; + if (name == "rho") return 0; + if (name == "drho") return 1; return -1; } @@ -114,8 +114,7 @@ int AtomVecMDPD::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecMDPD::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecMDPD::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int *mask = atom->mask; int nlocal = atom->nlocal; @@ -123,14 +122,18 @@ void AtomVecMDPD::pack_property_atom(int index, double *buf, int n = 0; if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = rho[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = rho[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = drho[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = drho[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/DPD-MESO/atom_vec_mdpd.h b/src/DPD-MESO/atom_vec_mdpd.h index 4e8aefeebe..1d7bc3db71 100644 --- a/src/DPD-MESO/atom_vec_mdpd.h +++ b/src/DPD-MESO/atom_vec_mdpd.h @@ -32,7 +32,7 @@ class AtomVecMDPD : public AtomVec { void grow_pointers() override; void force_clear(int, size_t) override; void data_atom_post(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: diff --git a/src/DPD-MESO/atom_vec_tdpd.cpp b/src/DPD-MESO/atom_vec_tdpd.cpp index 8b558457ed..bbd6bc89bc 100644 --- a/src/DPD-MESO/atom_vec_tdpd.cpp +++ b/src/DPD-MESO/atom_vec_tdpd.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -13,11 +12,12 @@ ------------------------------------------------------------------------- */ #include "atom_vec_tdpd.h" -#include -#include "atom.h" -#include "update.h" -#include "error.h" +#include "atom.h" +#include "error.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -37,18 +37,18 @@ AtomVecTDPD::AtomVecTDPD(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "cc cc_flux vest"; - fields_copy = (char *) "cc vest"; - fields_comm = (char *) "cc vest"; - fields_comm_vel = (char *) "cc vest"; - fields_reverse = (char *) "cc_flux"; - fields_border = (char *) "cc vest"; - fields_border_vel = (char *) "cc vest"; - fields_exchange = (char *) "cc vest"; - fields_restart = (char * ) "cc vest"; - fields_create = (char *) "cc vest"; - fields_data_atom = (char *) "id type x cc"; - fields_data_vel = (char *) "id v"; + fields_grow = {"cc", "cc_flux", "vest"}; + fields_copy = {"cc", "vest"}; + fields_comm = {"cc", "vest"}; + fields_comm_vel = {"cc", "vest"}; + fields_reverse = {"cc_flux"}; + fields_border = {"cc", "vest"}; + fields_border_vel = {"cc", "vest"}; + fields_exchange = {"cc", "vest"}; + fields_restart = {"cc", "vest"}; + fields_create = {"cc", "vest"}; + fields_data_atom = {"id", "type", "x", "cc"}; + fields_data_vel = {"id", "v"}; } /* ---------------------------------------------------------------------- @@ -58,13 +58,13 @@ AtomVecTDPD::AtomVecTDPD(LAMMPS *lmp) : AtomVec(lmp) void AtomVecTDPD::process_args(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Invalid atom_style tdpd command"); + if (narg < 1) error->all(FLERR, "Invalid atom_style tdpd command"); - atom->cc_species = utils::inumeric(FLERR,arg[0],false,lmp); + atom->cc_species = utils::inumeric(FLERR, arg[0], false, lmp); cc_species = atom->cc_species; - atom->add_peratom_change_columns("cc",cc_species); - atom->add_peratom_change_columns("cc_flux",cc_species); + atom->add_peratom_change_columns("cc", cc_species); + atom->add_peratom_change_columns("cc_flux", cc_species); // delay setting up of fields until now @@ -77,8 +77,7 @@ void AtomVecTDPD::init() { AtomVec::init(); - if (strcmp(update->unit_style,"lj") != 0) - error->all(FLERR,"Atom style tdpd requires lj units"); + if (strcmp(update->unit_style, "lj") != 0) error->all(FLERR, "Atom style tdpd requires lj units"); } /* ---------------------------------------------------------------------- @@ -92,7 +91,6 @@ void AtomVecTDPD::grow_pointers() vest = atom->vest; } - /* ---------------------------------------------------------------------- clear extra forces starting at atom N nbytes = # of bytes to clear for a per-atom vector @@ -100,7 +98,7 @@ void AtomVecTDPD::grow_pointers() void AtomVecTDPD::force_clear(int n, size_t nbytes) { - memset(&cc_flux[n][0],0,cc_species*nbytes); + memset(&cc_flux[n][0], 0, cc_species * nbytes); } /* ---------------------------------------------------------------------- diff --git a/src/DPD-REACT/atom_vec_dpd.cpp b/src/DPD-REACT/atom_vec_dpd.cpp index 461b1d2246..b6a62a3083 100644 --- a/src/DPD-REACT/atom_vec_dpd.cpp +++ b/src/DPD-REACT/atom_vec_dpd.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -17,6 +16,7 @@ ------------------------------------------------------------------------- */ #include "atom_vec_dpd.h" + #include "atom.h" #include "error.h" @@ -37,18 +37,17 @@ AtomVecDPD::AtomVecDPD(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rho dpdTheta uCond uMech uChem uCG uCGnew duChem"; - fields_copy = (char *) "dpdTheta uCond uMech uChem uCG uCGnew"; - fields_comm = (char *) "dpdTheta uCond uMech uChem"; - fields_comm_vel = (char *) "dpdTheta uCond uMech uChem"; - fields_reverse = (char *) ""; - fields_border = (char *) "dpdTheta uCond uMech uChem uCG uCGnew"; - fields_border_vel = (char *) "dpdTheta uCond uMech uChem uCG uCGnew"; - fields_exchange = (char *) "dpdTheta uCond uMech uChem uCG uCGnew"; - fields_restart = (char *) "dpdTheta uCond uMech uChem"; - fields_create = (char *) "rho dpdTheta uCond uMech uChem uCG uCGnew duChem"; - fields_data_atom = (char *) "id type dpdTheta x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"rho", "dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew", "duChem"}; + fields_copy = {"dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew"}; + fields_comm = {"dpdTheta", "uCond", "uMech", "uChem"}; + fields_comm_vel = {"dpdTheta", "uCond", "uMech", "uChem"}; + fields_border = {"dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew"}; + fields_border_vel = {"dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew"}; + fields_exchange = {"dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew"}; + fields_restart = {"dpdTheta", "uCond", "uMech", "uChem"}; + fields_create = {"rho", "dpdTheta", "uCond", "uMech", "uChem", "uCG", "uCGnew", "duChem"}; + fields_data_atom = {"id", "type", "dpdTheta", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -94,6 +93,5 @@ void AtomVecDPD::data_atom_post(int ilocal) uCGnew[ilocal] = 0.0; if (dpdTheta[ilocal] <= 0) - error->one(FLERR,"Internal temperature in Atoms section of date file " - "must be > zero"); + error->one(FLERR, "Internal temperature in Atoms section of date file must be > zero"); } diff --git a/src/EFF/atom_vec_electron.cpp b/src/EFF/atom_vec_electron.cpp index ca80f186a8..1f9d1f3e65 100644 --- a/src/EFF/atom_vec_electron.cpp +++ b/src/EFF/atom_vec_electron.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -21,20 +20,19 @@ #include "atom.h" #include "citeme.h" -#include - using namespace LAMMPS_NS; static const char cite_user_eff_package[] = - "EFF package:\n\n" - "@Article{Jaramillo-Botero11,\n" - " author = {A. Jaramillo-Botero, J. Su, A. Qi, W. A. Goddard III},\n" - " title = {Large-Scale, Long-Term Nonadiabatic Electron Molecular Dynamics for Describing Material Properties and Phenomena in Extreme Environments},\n" - " journal = {J.~Comp.~Chem.},\n" - " year = 2011,\n" - " volume = 32,\n" - " pages = {497--512}\n" - "}\n\n"; + "EFF package:\n\n" + "@Article{Jaramillo-Botero11,\n" + " author = {A. Jaramillo-Botero, J. Su, A. Qi, W. A. Goddard III},\n" + " title = {Large-Scale, Long-Term Nonadiabatic Electron Molecular Dynamics for Describing " + "Material Properties and Phenomena in Extreme Environments},\n" + " journal = {J.~Comp.~Chem.},\n" + " year = 2011,\n" + " volume = 32,\n" + " pages = {497--512}\n" + "}\n\n"; /* ---------------------------------------------------------------------- */ @@ -47,26 +45,25 @@ AtomVecElectron::AtomVecElectron(LAMMPS *lmp) : AtomVec(lmp) forceclearflag = 1; atom->electron_flag = 1; - atom->q_flag = atom->spin_flag = atom->eradius_flag = - atom->ervel_flag = atom->erforce_flag = 1; + atom->q_flag = atom->spin_flag = atom->eradius_flag = atom->ervel_flag = atom->erforce_flag = 1; // strings with peratom variables to include in each AtomVec method // strings cannot contain fields in corresponding AtomVec default strings // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "q spin eradius ervel erforce"; - fields_copy = (char *) "q spin eradius ervel"; - fields_comm = (char *) "eradius"; - fields_comm_vel = (char *) "eradius"; - fields_reverse = (char *) "erforce"; - fields_border = (char *) "q spin eradius"; - fields_border_vel = (char *) "q spin eradius"; - fields_exchange = (char *) "q spin eradius ervel"; - fields_restart = (char *) "q spin eradius ervel"; - fields_create = (char *) "q spin eradius ervel"; - fields_data_atom = (char *) "id type q spin eradius x"; - fields_data_vel = (char *) "id v ervel"; + fields_grow = {"q", "spin", "eradius", "ervel", "erforce"}; + fields_copy = {"q", "spin", "eradius", "ervel"}; + fields_comm = {"eradius"}; + fields_comm_vel = {"eradius"}; + fields_reverse = {"erforce"}; + fields_border = {"q", "spin", "eradius"}; + fields_border_vel = {"q", "spin", "eradius"}; + fields_exchange = {"q", "spin", "eradius", "ervel"}; + fields_restart = {"q", "spin", "eradius", "ervel"}; + fields_create = {"q", "spin", "eradius", "ervel"}; + fields_data_atom = {"id", "type", "q", "spin", "eradius", "x"}; + fields_data_vel = {"id", "v", "ervel"}; setup_fields(); } @@ -91,7 +88,7 @@ void AtomVecElectron::grow_pointers() void AtomVecElectron::force_clear(int n, size_t nbytes) { - memset(&erforce[n],0,nbytes); + memset(&erforce[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -119,12 +116,12 @@ void AtomVecElectron::data_atom_post(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecElectron::property_atom(char *name) +int AtomVecElectron::property_atom(const std::string &name) { - if (strcmp(name,"spin") == 0) return 0; - if (strcmp(name,"eradius") == 0) return 1; - if (strcmp(name,"ervel") == 0) return 2; - if (strcmp(name,"erforce") == 0) return 3; + if (name == "spin") return 0; + if (name == "eradius") return 1; + if (name == "ervel") return 2; + if (name == "erforce") return 3; return -1; } @@ -133,8 +130,7 @@ int AtomVecElectron::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecElectron::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecElectron::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int *mask = atom->mask; int nlocal = atom->nlocal; @@ -142,26 +138,34 @@ void AtomVecElectron::pack_property_atom(int index, double *buf, if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = spin[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = spin[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = eradius[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = eradius[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 2) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = ervel[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = ervel[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 3) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = erforce[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = erforce[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/EFF/atom_vec_electron.h b/src/EFF/atom_vec_electron.h index 6c9b11cccb..21015d56b0 100644 --- a/src/EFF/atom_vec_electron.h +++ b/src/EFF/atom_vec_electron.h @@ -32,7 +32,7 @@ class AtomVecElectron : public AtomVec { void force_clear(int, size_t) override; void create_atom_post(int) override; void data_atom_post(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: diff --git a/src/EXTRA-COMPUTE/compute_born_matrix.cpp b/src/EXTRA-COMPUTE/compute_born_matrix.cpp index a018405fd1..cbcc077129 100644 --- a/src/EXTRA-COMPUTE/compute_born_matrix.cpp +++ b/src/EXTRA-COMPUTE/compute_born_matrix.cpp @@ -586,7 +586,7 @@ void ComputeBornMatrix::restore_atoms(int nall, int idir) int k = dirlist[idir][0]; int l = dirlist[idir][1]; double **x = atom->x; - if (l == k) + if (l == k) for (int i = 0; i < nall; i++) x[i][k] = temp_x[i][k]; else for (int i = 0; i < nall; i++) { diff --git a/src/EXTRA-MOLECULE/bond_fene_nm.cpp b/src/EXTRA-MOLECULE/bond_fene_nm.cpp index 839217df78..bd9d16b95d 100644 --- a/src/EXTRA-MOLECULE/bond_fene_nm.cpp +++ b/src/EXTRA-MOLECULE/bond_fene_nm.cpp @@ -273,7 +273,7 @@ double BondFENENM::single(int type, double rsq, int /*i*/, int /*j*/, double &ff void *BondFENENM::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kappa") == 0) return (void *) k; + if (strcmp(str, "k") == 0) return (void *) k; if (strcmp(str, "r0") == 0) return (void *) r0; return nullptr; } diff --git a/src/EXTRA-MOLECULE/bond_gaussian.cpp b/src/EXTRA-MOLECULE/bond_gaussian.cpp index c2ab00dfde..0ad125aeca 100644 --- a/src/EXTRA-MOLECULE/bond_gaussian.cpp +++ b/src/EXTRA-MOLECULE/bond_gaussian.cpp @@ -34,9 +34,7 @@ using namespace MathConst; BondGaussian::BondGaussian(LAMMPS *lmp) : Bond(lmp), nterms(nullptr), bond_temperature(nullptr), alpha(nullptr), width(nullptr), r0(nullptr) -{ - reinitflag = 1; -} +{} /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-PAIR/pair_coul_slater_long.cpp b/src/EXTRA-PAIR/pair_coul_slater_long.cpp index d30d346fa0..65619f0f65 100644 --- a/src/EXTRA-PAIR/pair_coul_slater_long.cpp +++ b/src/EXTRA-PAIR/pair_coul_slater_long.cpp @@ -45,7 +45,6 @@ using namespace LAMMPS_NS; PairCoulSlaterLong::PairCoulSlaterLong(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; - //ftable = nullptr; qdist = 0.0; } @@ -117,7 +116,6 @@ void PairCoulSlaterLong::compute(int eflag, int vflag) if (rsq < cut_coulsq) { r2inv = 1.0/rsq; -// if (!ncoultablebits || rsq <= tabinnersq) { r = sqrt(rsq); grij = g_ewald * r; expm2 = exp(-grij*grij); @@ -127,22 +125,6 @@ void PairCoulSlaterLong::compute(int eflag, int vflag) prefactor = qqrd2e * scale[itype][jtype] * qtmp*q[j]/r; forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - slater_term); if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; -/* - } else { - union_int_float_t rsq_lookup; - rsq_lookup.f = rsq; - itable = rsq_lookup.i & ncoulmask; - itable >>= ncoulshiftbits; - fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; - table = ftable[itable] + fraction*dftable[itable]; - forcecoul = scale[itype][jtype] * qtmp*q[j] * table; - if (factor_coul < 1.0) { - table = ctable[itable] + fraction*dctable[itable]; - prefactor = scale[itype][jtype] * qtmp*q[j] * table; - forcecoul -= (1.0-factor_coul)*prefactor; - } - } -*/ fpair = forcecoul * r2inv; @@ -156,14 +138,7 @@ void PairCoulSlaterLong::compute(int eflag, int vflag) } if (eflag) { -// if (!ncoultablebits || rsq <= tabinnersq) ecoul = prefactor*(erfc - (1 + r/lamda)*exp(-2*r/lamda)); -/* - else { - table = etable[itable] + fraction*detable[itable]; - ecoul = scale[itype][jtype] * qtmp*q[j] * table; - } -*/ if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } @@ -296,10 +271,10 @@ void PairCoulSlaterLong::read_restart(FILE *fp) int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { - if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); + if (me == 0) utils::sfread(FLERR, &setflag[i][j],sizeof(int),1,fp, nullptr, error); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { - if (me == 0) fread(&scale[i][j],sizeof(double),1,fp); + if (me == 0) utils::sfread(FLERR, &scale[i][j],sizeof(double),1,fp, nullptr, error); MPI_Bcast(&scale[i][j],1,MPI_DOUBLE,0,world); } } @@ -315,8 +290,6 @@ void PairCoulSlaterLong::write_restart_settings(FILE *fp) fwrite(&lamda,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); - //fwrite(&ncoultablebits,sizeof(int),1,fp); - //fwrite(&tabinner,sizeof(double),1,fp); } /* ---------------------------------------------------------------------- @@ -326,71 +299,39 @@ void PairCoulSlaterLong::write_restart_settings(FILE *fp) void PairCoulSlaterLong::read_restart_settings(FILE *fp) { if (comm->me == 0) { - fread(&cut_coul,sizeof(double),1,fp); - fread(&lamda,sizeof(double),1,fp); - fread(&offset_flag,sizeof(int),1,fp); - fread(&mix_flag,sizeof(int),1,fp); - //fread(&ncoultablebits,sizeof(int),1,fp); - //fread(&tabinner,sizeof(double),1,fp); + utils::sfread(FLERR, &cut_coul,sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR, &lamda,sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR, &offset_flag,sizeof(int),1,fp,nullptr,error); + utils::sfread(FLERR, &mix_flag,sizeof(int),1,fp,nullptr,error); } MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world); MPI_Bcast(&lamda,1,MPI_DOUBLE,0,world); MPI_Bcast(&offset_flag,1,MPI_INT,0,world); MPI_Bcast(&mix_flag,1,MPI_INT,0,world); - //MPI_Bcast(&ncoultablebits,1,MPI_INT,0,world); - //MPI_Bcast(&tabinner,1,MPI_DOUBLE,0,world); } /* ---------------------------------------------------------------------- */ -double PairCoulSlaterLong::single(int i, int j, int /*itype*/, int /*jtype*/, - double rsq, - double factor_coul, double /*factor_lj*/, - double &fforce) +double PairCoulSlaterLong::single(int i, int j, int /*itype*/, int /*jtype*/, double rsq, + double factor_coul, double /*factor_lj*/, double &fforce) { double r2inv,r,grij,expm2,t,erfc,prefactor; double slater_term; -// double fraction,table; double forcecoul,phicoul; -// int itable; r2inv = 1.0/rsq; -// if (!ncoultablebits || rsq <= tabinnersq) { - r = sqrt(rsq); - grij = g_ewald * r; - expm2 = exp(-grij*grij); - t = 1.0 / (1.0 + EWALD_P*grij); - erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; - slater_term = exp(-2*r/lamda)*(1 + (2*r/lamda*(1+r/lamda))); - prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; - forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - slater_term); - if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; -/* - } else { - union_int_float_t rsq_lookup; - rsq_lookup.f = rsq; - itable = rsq_lookup.i & ncoulmask; - itable >>= ncoulshiftbits; - fraction = (rsq_lookup.f - rtable[itable]) * drtable[itable]; - table = ftable[itable] + fraction*dftable[itable]; - forcecoul = atom->q[i]*atom->q[j] * table; - if (factor_coul < 1.0) { - table = ctable[itable] + fraction*dctable[itable]; - prefactor = atom->q[i]*atom->q[j] * table; - forcecoul -= (1.0-factor_coul)*prefactor; - } - } -*/ + r = sqrt(rsq); + grij = g_ewald * r; + expm2 = exp(-grij*grij); + t = 1.0 / (1.0 + EWALD_P*grij); + erfc = t * (A1+t*(A2+t*(A3+t*(A4+t*A5)))) * expm2; + slater_term = exp(-2*r/lamda)*(1 + (2*r/lamda*(1+r/lamda))); + prefactor = force->qqrd2e * atom->q[i]*atom->q[j]/r; + forcecoul = prefactor * (erfc + EWALD_F*grij*expm2 - slater_term); + if (factor_coul < 1.0) forcecoul -= (1.0-factor_coul)*prefactor; fforce = forcecoul * r2inv; -// if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*(erfc - (1 + r/lamda)*exp(-2*r/lamda)); -/* - else { - table = etable[itable] + fraction*detable[itable]; - phicoul = atom->q[i]*atom->q[j] * table; - } -*/ + phicoul = prefactor*(erfc - (1 + r/lamda)*exp(-2*r/lamda)); if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; return phicoul; diff --git a/src/EXTRA-PAIR/pair_coul_slater_long.h b/src/EXTRA-PAIR/pair_coul_slater_long.h index 66002ca2fa..f9c1da5040 100644 --- a/src/EXTRA-PAIR/pair_coul_slater_long.h +++ b/src/EXTRA-PAIR/pair_coul_slater_long.h @@ -43,7 +43,6 @@ class PairCoulSlaterLong : public Pair { protected: double cut_coul, cut_coulsq, qdist; double lamda; - //double *cut_respa; double g_ewald; double **scale; diff --git a/src/EXTRA-PAIR/pair_wf_cut.cpp b/src/EXTRA-PAIR/pair_wf_cut.cpp index 2fb363a161..b25e519bcf 100644 --- a/src/EXTRA-PAIR/pair_wf_cut.cpp +++ b/src/EXTRA-PAIR/pair_wf_cut.cpp @@ -294,15 +294,15 @@ void PairWFCut::read_restart(FILE *fp) int me = comm->me; for (i = 1; i <= atom->ntypes; i++) for (j = i; j <= atom->ntypes; j++) { - if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp); + if (me == 0) utils::sfread(FLERR, &setflag[i][j],sizeof(int),1,fp, nullptr, error); MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); if (setflag[i][j]) { if (me == 0) { - fread(&epsilon[i][j],sizeof(double),1,fp); - fread(&sigma[i][j],sizeof(double),1,fp); - fread(&nu[i][j],sizeof(int),1,fp); - fread(&mu[i][j],sizeof(int),1,fp); - fread(&cut[i][j],sizeof(double),1,fp); + utils::sfread(FLERR, &epsilon[i][j],sizeof(double),1,fp, nullptr, error); + utils::sfread(FLERR, &sigma[i][j],sizeof(double),1,fp, nullptr, error); + utils::sfread(FLERR, &nu[i][j],sizeof(int),1,fp, nullptr, error); + utils::sfread(FLERR, &mu[i][j],sizeof(int),1,fp, nullptr, error); + utils::sfread(FLERR, &cut[i][j],sizeof(double),1,fp, nullptr, error); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); @@ -331,9 +331,9 @@ void PairWFCut::write_restart_settings(FILE *fp) void PairWFCut::read_restart_settings(FILE *fp) { if (comm->me == 0) { - fread(&cut_global,sizeof(double),1,fp); - fread(&offset_flag,sizeof(int),1,fp); - fread(&mix_flag,sizeof(int),1,fp); + utils::sfread(FLERR, &cut_global,sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR, &offset_flag,sizeof(int),1,fp,nullptr,error); + utils::sfread(FLERR, &mix_flag,sizeof(int),1,fp,nullptr,error); } MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world); MPI_Bcast(&offset_flag,1,MPI_INT,0,world); diff --git a/src/INTEL/verlet_lrt_intel.cpp b/src/INTEL/verlet_lrt_intel.cpp index 0d8eb2e468..4102510c66 100644 --- a/src/INTEL/verlet_lrt_intel.cpp +++ b/src/INTEL/verlet_lrt_intel.cpp @@ -215,7 +215,7 @@ void VerletLRTIntel::run(int n) int n_pre_neighbor = modify->n_pre_neighbor; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; int n_end_of_step = modify->n_end_of_step; if (atom->sortfreq > 0) sortflag = 1; diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 22ce80478c..c733e5fe18 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -1073,17 +1073,14 @@ void AtomVecHybridKokkos::write_data(FILE *fp, int n, double **buf) int k,m; for (int i = 0; i < n; i++) { - fprintf(fp,TAGINT_FORMAT " %d %-1.16e %-1.16e %-1.16e", - (tagint) ubuf(buf[i][0]).i,(int) ubuf(buf[i][1]).i, - buf[i][2],buf[i][3],buf[i][4]); + fmt::print(fp,"{} {} {:.16e} {:.16e} {:.16e}", ubuf(buf[i][0]).i, ubuf(buf[i][1]).i, + buf[i][2], buf[i][3], buf[i][4]); m = 5; for (k = 0; k < nstyles; k++) m += styles[k]->write_data_hybrid(fp,&buf[i][m]); - fprintf(fp," %d %d %d\n", - (int) ubuf(buf[i][m]).i,(int) ubuf(buf[i][m+1]).i, - (int) ubuf(buf[i][m+2]).i); + fmt::print(fp," {} {} {}\n", ubuf(buf[i][m]).i, ubuf(buf[i][m+1]).i, ubuf(buf[i][m+2]).i); } } @@ -1119,8 +1116,7 @@ void AtomVecHybridKokkos::write_vel(FILE *fp, int n, double **buf) int k,m; for (int i = 0; i < n; i++) { - fprintf(fp,TAGINT_FORMAT " %g %g %g", - (tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3]); + fmt::print(fp,"{} {} {} {}", (tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3]); m = 4; for (k = 0; k < nstyles; k++) @@ -1136,7 +1132,7 @@ void AtomVecHybridKokkos::write_vel(FILE *fp, int n, double **buf) return -1 if name is unknown to any sub-styles ------------------------------------------------------------------------- */ -int AtomVecHybridKokkos::property_atom(char *name) +int AtomVecHybridKokkos::property_atom(const std::string &name) { for (int k = 0; k < nstyles; k++) { int index = styles[k]->property_atom(name); @@ -1150,8 +1146,7 @@ int AtomVecHybridKokkos::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecHybridKokkos::pack_property_atom(int multiindex, double *buf, - int nvalues, int groupbit) +void AtomVecHybridKokkos::pack_property_atom(int multiindex, double *buf, int nvalues, int groupbit) { int k = multiindex % nstyles; int index = multiindex/nstyles; diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.h b/src/KOKKOS/atom_vec_hybrid_kokkos.h index 29417f1e05..e1a5eb6182 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.h +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.h @@ -64,7 +64,7 @@ class AtomVecHybridKokkos : public AtomVecKokkos { void write_data(FILE *, int, double **) override; void pack_vel(double **) override; void write_vel(FILE *, int, double **) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; double memory_usage() override; diff --git a/src/KOKKOS/dynamical_matrix_kokkos.cpp b/src/KOKKOS/dynamical_matrix_kokkos.cpp index dc180a1743..7b85a3766d 100644 --- a/src/KOKKOS/dynamical_matrix_kokkos.cpp +++ b/src/KOKKOS/dynamical_matrix_kokkos.cpp @@ -159,7 +159,7 @@ void DynamicalMatrixKokkos::update_force() { int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; lmp->kokkos->auto_sync = 0; diff --git a/src/KOKKOS/third_order_kokkos.cpp b/src/KOKKOS/third_order_kokkos.cpp index 2aeb9152a1..56c9295e70 100644 --- a/src/KOKKOS/third_order_kokkos.cpp +++ b/src/KOKKOS/third_order_kokkos.cpp @@ -160,7 +160,7 @@ void ThirdOrderKokkos::update_force() { int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; lmp->kokkos->auto_sync = 0; diff --git a/src/KOKKOS/verlet_kokkos.cpp b/src/KOKKOS/verlet_kokkos.cpp index 2d142edd83..1816415b47 100644 --- a/src/KOKKOS/verlet_kokkos.cpp +++ b/src/KOKKOS/verlet_kokkos.cpp @@ -271,7 +271,7 @@ void VerletKokkos::run(int n) int n_post_neighbor = modify->n_post_neighbor; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; int n_end_of_step = modify->n_end_of_step; lmp->kokkos->auto_sync = 0; diff --git a/src/MACHDYN/atom_vec_smd.cpp b/src/MACHDYN/atom_vec_smd.cpp index 81f32ca0a2..cfceadfbd4 100644 --- a/src/MACHDYN/atom_vec_smd.cpp +++ b/src/MACHDYN/atom_vec_smd.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- * * *** Smooth Mach Dynamics *** @@ -27,8 +26,6 @@ #include "atom.h" -#include - using namespace LAMMPS_NS; #define NMAT_FULL 9 @@ -63,42 +60,33 @@ AtomVecSMD::AtomVecSMD(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "esph desph vfrac rmass x0 radius contact_radius molecule " - "smd_data_9 vest smd_stress " - "eff_plastic_strain eff_plastic_strain_rate damage"; - fields_copy = (char *) - "esph vfrac rmass x0 radius contact_radius molecule " - "eff_plastic_strain eff_plastic_strain_rate vest " - "smd_data_9 smd_stress damage"; - fields_comm = (char *) "radius vfrac vest esph"; - fields_comm_vel = (char *) "radius vfrac vest esph"; - fields_reverse = (char *) "desph"; - fields_border = (char *) - "x0 molecule radius rmass vfrac contact_radius esph " - "eff_plastic_strain smd_data_9 smd_stress"; - fields_border_vel = (char *) - "x0 molecule radius rmass vfrac contact_radius esph " - "eff_plastic_strain smd_data_9 smd_stress vest"; - fields_exchange = (char *) - "x0 molecule radius rmass vfrac contact_radius esph " - "eff_plastic_strain eff_plastic_strain_rate smd_data_9 smd_stress " - "vest damage"; - fields_restart = (char *) - "x0 molecule radius rmass vfrac contact_radius esph " - "eff_plastic_strain eff_plastic_strain_rate smd_data_9 smd_stress " - "vest damage"; - fields_create = (char *) - "x0 vest vfrac rmass radius contact_radius molecule esph " - "eff_plastic_strain eff_plastic_strain_rate smd_data_9 smd_stress damage"; - fields_data_atom = (char *) - "id type molecule vfrac rmass radius contact_radius x0 x"; - fields_data_vel = (char *) "id v"; + // clang-format off + fields_grow = {"esph", "desph", "vfrac", "rmass", "x0", "radius", "contact_radius", "molecule", + "smd_data_9", "vest", "smd_stress", "eff_plastic_strain", "eff_plastic_strain_rate", "damage"}; + fields_copy = {"esph", "vfrac", "rmass", "x0", "radius", "contact_radius", "molecule", + "eff_plastic_strain", "eff_plastic_strain_rate", "vest", "smd_data_9", "smd_stress", "damage"}; + fields_comm = {"radius", "vfrac", "vest", "esph"}; + fields_comm_vel = {"radius", "vfrac", "vest", "esph"}; + fields_reverse = {"desph"}; + fields_border = {"x0", "molecule", "radius", "rmass", "vfrac", "contact_radius", "esph", + "eff_plastic_strain", "smd_data_9", "smd_stress"}; + fields_border_vel = {"x0", "molecule", "radius", "rmass", "vfrac", "contact_radius", "esph", + "eff_plastic_strain", "smd_data_9", "smd_stress", "vest"}; + fields_exchange = {"x0", "molecule", "radius", "rmass", "vfrac", "contact_radius", "esph", + "eff_plastic_strain", "eff_plastic_strain_rate", "smd_data_9", "smd_stress", "vest", "damage"}; + fields_restart ={"x0", "molecule", "radius", "rmass", "vfrac", "contact_radius", "esph", + "eff_plastic_strain", "eff_plastic_strain_rate", "smd_data_9", "smd_stress", "vest", "damage"}; + fields_create = {"x0", "vest", "vfrac", "rmass", "radius", "contact_radius", "molecule", + "esph", "eff_plastic_strain", "eff_plastic_strain_rate", "smd_data_9", "smd_stress", "damage"}; + fields_data_atom = {"id", "type", "molecule", "vfrac", "rmass", "radius", "contact_radius", + "x0", "x"}; + fields_data_vel = {"id", "v"}; + // clang-format on // set these array sizes based on defines - atom->add_peratom_change_columns("smd_data_9",NMAT_FULL); - atom->add_peratom_change_columns("smd_stress",NMAT_SYMM); + atom->add_peratom_change_columns("smd_data_9", NMAT_FULL); + atom->add_peratom_change_columns("smd_stress", NMAT_SYMM); setup_fields(); } @@ -134,7 +122,7 @@ void AtomVecSMD::grow_pointers() void AtomVecSMD::force_clear(int n, size_t nbytes) { - memset(&desph[n],0,nbytes); + memset(&desph[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -153,9 +141,9 @@ void AtomVecSMD::create_atom_post(int ilocal) contact_radius[ilocal] = 0.5; molecule[ilocal] = 1; - smd_data_9[ilocal][0] = 1.0; // xx - smd_data_9[ilocal][4] = 1.0; // yy - smd_data_9[ilocal][8] = 1.0; // zz + smd_data_9[ilocal][0] = 1.0; // xx + smd_data_9[ilocal][4] = 1.0; // yy + smd_data_9[ilocal][8] = 1.0; // zz } /* ---------------------------------------------------------------------- @@ -179,13 +167,11 @@ void AtomVecSMD::data_atom_post(int ilocal) eff_plastic_strain[ilocal] = 0.0; eff_plastic_strain_rate[ilocal] = 0.0; - for (int k = 0; k < NMAT_FULL; k++) - smd_data_9[ilocal][k] = 0.0; + for (int k = 0; k < NMAT_FULL; k++) smd_data_9[ilocal][k] = 0.0; - for (int k = 0; k < NMAT_SYMM; k++) - smd_stress[ilocal][k] = 0.0; + for (int k = 0; k < NMAT_SYMM; k++) smd_stress[ilocal][k] = 0.0; - smd_data_9[ilocal][0] = 1.0; // xx - smd_data_9[ilocal][4] = 1.0; // yy - smd_data_9[ilocal][8] = 1.0; // zz + smd_data_9[ilocal][0] = 1.0; // xx + smd_data_9[ilocal][4] = 1.0; // yy + smd_data_9[ilocal][8] = 1.0; // zz } diff --git a/src/MAKE/MACHINES/Makefile.summit_kokkos b/src/MAKE/MACHINES/Makefile.summit_kokkos index f22b27cc74..557ebd22b2 100644 --- a/src/MAKE/MACHINES/Makefile.summit_kokkos +++ b/src/MAKE/MACHINES/Makefile.summit_kokkos @@ -9,7 +9,7 @@ SHELL = /bin/sh KOKKOS_ABSOLUTE_PATH = $(shell cd $(KOKKOS_PATH); pwd) CC = $(KOKKOS_ABSOLUTE_PATH)/bin/nvcc_wrapper -CCFLAGS = -g -O3 -DNDEBUG +CCFLAGS = -g -O3 -DNDEBUG -Xcudafe --diag_suppress=unrecognized_pragma SHFLAGS = -fPIC DEPFLAGS = -M diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi index 42a8236c7c..b73c441c71 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi +++ b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi @@ -10,7 +10,7 @@ KOKKOS_ABSOLUTE_PATH = $(shell cd $(KOKKOS_PATH); pwd) export MPICH_CXX = $(KOKKOS_ABSOLUTE_PATH)/bin/nvcc_wrapper export OMPI_CXX = $(KOKKOS_ABSOLUTE_PATH)/bin/nvcc_wrapper CC = mpicxx -CCFLAGS = -g -O3 -DNDEBUG +CCFLAGS = -g -O3 -DNDEBUG -Xcudafe --diag_suppress=unrecognized_pragma SHFLAGS = -fPIC DEPFLAGS = -M @@ -55,7 +55,7 @@ MPI_LIB = # PATH = path for FFT library # LIB = name of FFT library -FFT_INC = -DFFT_CUFFT +FFT_INC = -DFFT_CUFFT FFT_PATH = FFT_LIB = -lcufft diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index 690e628fe3..8405919db8 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -532,7 +532,7 @@ double FixAtomSwap::energy_full() if (force->kspace) force->kspace->compute(eflag,vflag); - if (modify->n_post_force) modify->post_force(vflag); + if (modify->n_post_force_any) modify->post_force(vflag); update->eflag_global = update->ntimestep; double total_energy = c_pe->compute_scalar(); diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index a5a2eaff82..81f722bb6c 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -1129,7 +1129,7 @@ double FixChargeRegulation::energy_full() { if (force->kspace) force->kspace->compute(eflag, vflag); if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); - if (modify->n_post_force) modify->post_force(vflag); + if (modify->n_post_force_any) modify->post_force(vflag); update->eflag_global = update->ntimestep; double total_energy = c_pe->compute_scalar(); diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index 6937b90202..a526ba4756 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -2316,7 +2316,7 @@ double FixGCMC::energy_full() // but Modify::pre_reverse() is needed for INTEL if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); - if (modify->n_post_force) modify->post_force(vflag); + if (modify->n_post_force_any) modify->post_force(vflag); // NOTE: all fixes with energy_global_flag set and which // operate at pre_force() or post_force() diff --git a/src/MC/fix_mol_swap.cpp b/src/MC/fix_mol_swap.cpp index c93f0093a8..c23ceb7d36 100644 --- a/src/MC/fix_mol_swap.cpp +++ b/src/MC/fix_mol_swap.cpp @@ -390,7 +390,7 @@ double FixMolSwap::energy_full() if (force->kspace) force->kspace->compute(eflag,vflag); - if (modify->n_post_force) modify->post_force(vflag); + if (modify->n_post_force_any) modify->post_force(vflag); update->eflag_global = update->ntimestep; double total_energy = c_pe->compute_scalar(); diff --git a/src/MESONT/atom_vec_mesont.cpp b/src/MESONT/atom_vec_mesont.cpp index 5e57479b63..e3d03ff3e1 100644 --- a/src/MESONT/atom_vec_mesont.cpp +++ b/src/MESONT/atom_vec_mesont.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -33,18 +32,16 @@ AtomVecMesoNT::AtomVecMesoNT(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rmass radius length buckling bond_nt molecule"; - fields_copy = (char *) "rmass radius length buckling bond_nt molecule"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "rmass radius length buckling bond_nt molecule"; - fields_border_vel = (char *) "rmass radius length buckling bond_nt molecule"; - fields_exchange = (char *) "rmass radius length buckling bond_nt molecule"; - fields_restart = (char *) "rmass radius length buckling bond_nt molecule"; - fields_create = (char *) "rmass radius length buckling bond_nt molecule"; - fields_data_atom = (char *) "id molecule type bond_nt rmass radius length buckling x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_copy = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_border = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_border_vel = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_exchange = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_restart = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_create = {"rmass", "radius", "length", "buckling", "bond_nt", "molecule"}; + fields_data_atom = {"id", "molecule", "type", "bond_nt", "rmass", + "radius", "length", "buckling", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index 6a108ad3dd..3ba14c5872 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -703,7 +703,6 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) if (keywd == "rinner") { keyval = words[iword]; for (int ielem = 0; ielem < nelements; ielem++) { - printf("rinnerelem = %p ielem = %d nelements = %d iword = %d nwords = %d\n",rinnerelem, ielem, nelements, iword, nwords); rinnerelem[ielem] = utils::numeric(FLERR,keyval,false,lmp); iword++; } diff --git a/src/MOLECULE/angle_cosine.cpp b/src/MOLECULE/angle_cosine.cpp index dffecaf90b..8dba156177 100644 --- a/src/MOLECULE/angle_cosine.cpp +++ b/src/MOLECULE/angle_cosine.cpp @@ -237,10 +237,21 @@ double AngleCosine::single(int type, int i1, int i2, int i3) return k[type] * (1.0 + c); } + /* ---------------------------------------------------------------------- */ void AngleCosine::born_matrix(int type, int i1, int i2, int i3, double& du, double& du2) { du2 = 0; du = k[type]; + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *AngleCosine::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + return nullptr; } diff --git a/src/MOLECULE/angle_cosine.h b/src/MOLECULE/angle_cosine.h index 47eb119140..d86e0dc92f 100644 --- a/src/MOLECULE/angle_cosine.h +++ b/src/MOLECULE/angle_cosine.h @@ -36,6 +36,7 @@ class AngleCosine : public Angle { void write_data(FILE *) override; double single(int, int, int, int) override; void born_matrix(int type, int i1, int i2, int i3, double& du, double& du2) override; + void *extract(const char *, int &) override; protected: double *k; diff --git a/src/MOLECULE/angle_harmonic.cpp b/src/MOLECULE/angle_harmonic.cpp index 261770d9a3..aa24fa27b4 100644 --- a/src/MOLECULE/angle_harmonic.cpp +++ b/src/MOLECULE/angle_harmonic.cpp @@ -264,3 +264,15 @@ double AngleHarmonic::single(int type, int i1, int i2, int i3) double tk = k[type] * dtheta; return tk * dtheta; } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *AngleHarmonic::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "theta0") == 0) return (void *) theta0; + return nullptr; +} diff --git a/src/MOLECULE/angle_harmonic.h b/src/MOLECULE/angle_harmonic.h index 718ac4bd0a..2643ea3a17 100644 --- a/src/MOLECULE/angle_harmonic.h +++ b/src/MOLECULE/angle_harmonic.h @@ -35,6 +35,7 @@ class AngleHarmonic : public Angle { void read_restart(FILE *) override; void write_data(FILE *) override; double single(int, int, int, int) override; + void *extract(const char *, int &) override; protected: double *k, *theta0; diff --git a/src/MOLECULE/atom_vec_angle.cpp b/src/MOLECULE/atom_vec_angle.cpp index 06a4f441ca..366e1d1a9e 100644 --- a/src/MOLECULE/atom_vec_angle.cpp +++ b/src/MOLECULE/atom_vec_angle.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -32,26 +31,22 @@ AtomVecAngle::AtomVecAngle(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 nspecial special"; - fields_copy = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 nspecial special"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "molecule"; - fields_border_vel = (char *) "molecule"; - fields_exchange = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 nspecial special"; - fields_restart = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3"; - fields_create = (char *) "molecule num_bond num_angle nspecial"; - fields_data_atom = (char *) "id molecule type x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"molecule", "num_bond", "bond_type", "bond_atom", + "num_angle", "angle_type", "angle_atom1", "angle_atom2", + "angle_atom3", "nspecial", "special"}; + fields_copy = {"molecule", "num_bond", "bond_type", "bond_atom", + "num_angle", "angle_type", "angle_atom1", "angle_atom2", + "angle_atom3", "nspecial", "special"}; + fields_border = {"molecule"}; + fields_border_vel = {"molecule"}; + fields_exchange = {"molecule", "num_bond", "bond_type", "bond_atom", + "num_angle", "angle_type", "angle_atom1", "angle_atom2", + "angle_atom3", "nspecial", "special"}; + fields_restart = {"molecule", "num_bond", "bond_type", "bond_atom", "num_angle", + "angle_type", "angle_atom1", "angle_atom2", "angle_atom3"}; + fields_create = {"molecule", "num_bond", "num_angle", "nspecial"}; + fields_data_atom = {"id", "molecule", "type", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); @@ -63,8 +58,8 @@ AtomVecAngle::AtomVecAngle(LAMMPS *lmp) : AtomVec(lmp) AtomVecAngle::~AtomVecAngle() { - delete [] bond_negative; - delete [] angle_negative; + delete[] bond_negative; + delete[] angle_negative; } /* ---------------------------------------------------------------------- @@ -90,12 +85,12 @@ void AtomVecAngle::pack_restart_pre(int ilocal) // insure negative vectors are needed length if (bond_per_atom < atom->bond_per_atom) { - delete [] bond_negative; + delete[] bond_negative; bond_per_atom = atom->bond_per_atom; bond_negative = new int[bond_per_atom]; } if (angle_per_atom < atom->angle_per_atom) { - delete [] angle_negative; + delete[] angle_negative; angle_per_atom = atom->angle_per_atom; angle_negative = new int[angle_per_atom]; } @@ -108,7 +103,8 @@ void AtomVecAngle::pack_restart_pre(int ilocal) bond_negative[m] = 1; bond_type[ilocal][m] = -bond_type[ilocal][m]; any_bond_negative = 1; - } else bond_negative[m] = 0; + } else + bond_negative[m] = 0; } any_angle_negative = 0; @@ -117,7 +113,8 @@ void AtomVecAngle::pack_restart_pre(int ilocal) angle_negative[m] = 1; angle_type[ilocal][m] = -angle_type[ilocal][m]; any_angle_negative = 1; - } else angle_negative[m] = 0; + } else + angle_negative[m] = 0; } } diff --git a/src/MOLECULE/atom_vec_bond.cpp b/src/MOLECULE/atom_vec_bond.cpp index acd0bc9979..29a1a0f4e4 100644 --- a/src/MOLECULE/atom_vec_bond.cpp +++ b/src/MOLECULE/atom_vec_bond.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -32,21 +31,15 @@ AtomVecBond::AtomVecBond(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "molecule num_bond bond_type bond_atom nspecial special"; - fields_copy = (char *) - "molecule num_bond bond_type bond_atom nspecial special"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "molecule"; - fields_border_vel = (char *) "molecule"; - fields_exchange = (char *) - "molecule num_bond bond_type bond_atom nspecial special"; - fields_restart = (char *) "molecule num_bond bond_type bond_atom"; - fields_create = (char *) "molecule num_bond nspecial"; - fields_data_atom = (char *) "id molecule type x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", "special"}; + fields_copy = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", "special"}; + fields_border = {"molecule"}; + fields_border_vel = {"molecule"}; + fields_exchange = {"molecule", "num_bond", "bond_type", "bond_atom", "nspecial", "special"}; + fields_restart = {"molecule", "num_bond", "bond_type", "bond_atom"}; + fields_create = {"molecule", "num_bond", "nspecial"}; + fields_data_atom = {"id", "molecule", "type", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); @@ -58,7 +51,7 @@ AtomVecBond::AtomVecBond(LAMMPS *lmp) : AtomVec(lmp) AtomVecBond::~AtomVecBond() { - delete [] bond_negative; + delete[] bond_negative; } /* ---------------------------------------------------------------------- @@ -82,7 +75,7 @@ void AtomVecBond::pack_restart_pre(int ilocal) // insure bond_negative vector is needed length if (bond_per_atom < atom->bond_per_atom) { - delete [] bond_negative; + delete[] bond_negative; bond_per_atom = atom->bond_per_atom; bond_negative = new int[bond_per_atom]; } @@ -95,7 +88,8 @@ void AtomVecBond::pack_restart_pre(int ilocal) bond_negative[m] = 1; bond_type[ilocal][m] = -bond_type[ilocal][m]; any_bond_negative = 1; - } else bond_negative[m] = 0; + } else + bond_negative[m] = 0; } } diff --git a/src/MOLECULE/atom_vec_full.cpp b/src/MOLECULE/atom_vec_full.cpp index e88c4d7a62..a78f3616a4 100644 --- a/src/MOLECULE/atom_vec_full.cpp +++ b/src/MOLECULE/atom_vec_full.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -32,47 +31,31 @@ AtomVecFull::AtomVecFull(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_copy = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "q molecule"; - fields_border_vel = (char *) "q molecule"; - fields_exchange = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_restart = (char *) - "q molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4"; - fields_create = (char *) - "q molecule num_bond num_angle num_dihedral num_improper nspecial"; - fields_data_atom = (char *) "id molecule type q x"; - fields_data_vel = (char *) "id v"; - + // clang-format off + fields_grow = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_copy = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_border = {"q", "molecule"}; + fields_border_vel = {"q", "molecule"}; + fields_exchange = {"q", "molecule", "num_bond", "bond_type", "bond_atom", + "num_angle", "angle_type", "angle_atom1", "angle_atom2", "angle_atom3", + "num_dihedral", "dihedral_type", "dihedral_atom1", "dihedral_atom2", + "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", "improper_atom1", + "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_restart = {"q", "molecule", "num_bond", "bond_type", "bond_atom", "num_angle", + "angle_type", "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", + "dihedral_atom1", "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", + "improper_type", "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4"}; + fields_create = {"q", "molecule", "num_bond", "num_angle", + "num_dihedral", "num_improper", "nspecial"}; + fields_data_atom = {"id", "molecule", "type", "q", "x"}; + fields_data_vel = {"id", "v"}; + // clang-format on setup_fields(); bond_per_atom = angle_per_atom = dihedral_per_atom = improper_per_atom = 0; @@ -83,10 +66,10 @@ AtomVecFull::AtomVecFull(LAMMPS *lmp) : AtomVec(lmp) AtomVecFull::~AtomVecFull() { - delete [] bond_negative; - delete [] angle_negative; - delete [] dihedral_negative; - delete [] improper_negative; + delete[] bond_negative; + delete[] angle_negative; + delete[] dihedral_negative; + delete[] improper_negative; } /* ---------------------------------------------------------------------- @@ -116,22 +99,22 @@ void AtomVecFull::pack_restart_pre(int ilocal) // insure negative vectors are needed length if (bond_per_atom < atom->bond_per_atom) { - delete [] bond_negative; + delete[] bond_negative; bond_per_atom = atom->bond_per_atom; bond_negative = new int[bond_per_atom]; } if (angle_per_atom < atom->angle_per_atom) { - delete [] angle_negative; + delete[] angle_negative; angle_per_atom = atom->angle_per_atom; angle_negative = new int[angle_per_atom]; } if (dihedral_per_atom < atom->dihedral_per_atom) { - delete [] dihedral_negative; + delete[] dihedral_negative; dihedral_per_atom = atom->dihedral_per_atom; dihedral_negative = new int[dihedral_per_atom]; } if (improper_per_atom < atom->improper_per_atom) { - delete [] improper_negative; + delete[] improper_negative; improper_per_atom = atom->improper_per_atom; improper_negative = new int[improper_per_atom]; } @@ -144,7 +127,8 @@ void AtomVecFull::pack_restart_pre(int ilocal) bond_negative[m] = 1; bond_type[ilocal][m] = -bond_type[ilocal][m]; any_bond_negative = 1; - } else bond_negative[m] = 0; + } else + bond_negative[m] = 0; } any_angle_negative = 0; @@ -153,7 +137,8 @@ void AtomVecFull::pack_restart_pre(int ilocal) angle_negative[m] = 1; angle_type[ilocal][m] = -angle_type[ilocal][m]; any_angle_negative = 1; - } else angle_negative[m] = 0; + } else + angle_negative[m] = 0; } any_dihedral_negative = 0; @@ -162,7 +147,8 @@ void AtomVecFull::pack_restart_pre(int ilocal) dihedral_negative[m] = 1; dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; any_dihedral_negative = 1; - } else dihedral_negative[m] = 0; + } else + dihedral_negative[m] = 0; } any_improper_negative = 0; @@ -171,7 +157,8 @@ void AtomVecFull::pack_restart_pre(int ilocal) improper_negative[m] = 1; improper_type[ilocal][m] = -improper_type[ilocal][m]; any_improper_negative = 1; - } else improper_negative[m] = 0; + } else + improper_negative[m] = 0; } } @@ -195,14 +182,12 @@ void AtomVecFull::pack_restart_post(int ilocal) if (any_dihedral_negative) { for (int m = 0; m < num_dihedral[ilocal]; m++) - if (dihedral_negative[m]) - dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; + if (dihedral_negative[m]) dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; } if (any_improper_negative) { for (int m = 0; m < num_improper[ilocal]; m++) - if (improper_negative[m]) - improper_type[ilocal][m] = -improper_type[ilocal][m]; + if (improper_negative[m]) improper_type[ilocal][m] = -improper_type[ilocal][m]; } } diff --git a/src/MOLECULE/atom_vec_molecular.cpp b/src/MOLECULE/atom_vec_molecular.cpp index 9cb3f53f5a..72f094d7c2 100644 --- a/src/MOLECULE/atom_vec_molecular.cpp +++ b/src/MOLECULE/atom_vec_molecular.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -32,46 +31,29 @@ AtomVecMolecular::AtomVecMolecular(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_copy = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "molecule"; - fields_border_vel = (char *) "molecule"; - fields_exchange = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4 " - "nspecial special"; - fields_restart = (char *) - "molecule num_bond bond_type bond_atom " - "num_angle angle_type angle_atom1 angle_atom2 angle_atom3 " - "num_dihedral dihedral_type dihedral_atom1 dihedral_atom2 " - "dihedral_atom3 dihedral_atom4 " - "num_improper improper_type improper_atom1 improper_atom2 " - "improper_atom3 improper_atom4"; - fields_create = (char *) - "molecule num_bond num_angle num_dihedral num_improper nspecial"; - fields_data_atom = (char *) "id molecule type x"; - fields_data_vel = (char *) "id v"; + // clang-format off + fields_grow = {"molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_copy = {"molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_border = {"molecule"}; + fields_border_vel = {"molecule"}; + fields_exchange = {"molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4", "nspecial", "special"}; + fields_restart = {"molecule", "num_bond", "bond_type", "bond_atom", "num_angle", "angle_type", + "angle_atom1", "angle_atom2", "angle_atom3", "num_dihedral", "dihedral_type", "dihedral_atom1", + "dihedral_atom2", "dihedral_atom3", "dihedral_atom4", "num_improper", "improper_type", + "improper_atom1", "improper_atom2", "improper_atom3", "improper_atom4"}; + fields_create = {"molecule", "num_bond", "num_angle", "num_dihedral", "num_improper", "nspecial"}; + fields_data_atom = {"id", "molecule", "type", "x"}; + fields_data_vel = {"id", "v"}; + // clang-format on setup_fields(); @@ -83,10 +65,10 @@ AtomVecMolecular::AtomVecMolecular(LAMMPS *lmp) : AtomVec(lmp) AtomVecMolecular::~AtomVecMolecular() { - delete [] bond_negative; - delete [] angle_negative; - delete [] dihedral_negative; - delete [] improper_negative; + delete[] bond_negative; + delete[] angle_negative; + delete[] dihedral_negative; + delete[] improper_negative; } /* ---------------------------------------------------------------------- @@ -116,22 +98,22 @@ void AtomVecMolecular::pack_restart_pre(int ilocal) // insure negative vectors are needed length if (bond_per_atom < atom->bond_per_atom) { - delete [] bond_negative; + delete[] bond_negative; bond_per_atom = atom->bond_per_atom; bond_negative = new int[bond_per_atom]; } if (angle_per_atom < atom->angle_per_atom) { - delete [] angle_negative; + delete[] angle_negative; angle_per_atom = atom->angle_per_atom; angle_negative = new int[angle_per_atom]; } if (dihedral_per_atom < atom->dihedral_per_atom) { - delete [] dihedral_negative; + delete[] dihedral_negative; dihedral_per_atom = atom->dihedral_per_atom; dihedral_negative = new int[dihedral_per_atom]; } if (improper_per_atom < atom->improper_per_atom) { - delete [] improper_negative; + delete[] improper_negative; improper_per_atom = atom->improper_per_atom; improper_negative = new int[improper_per_atom]; } @@ -144,7 +126,8 @@ void AtomVecMolecular::pack_restart_pre(int ilocal) bond_negative[m] = 1; bond_type[ilocal][m] = -bond_type[ilocal][m]; any_bond_negative = 1; - } else bond_negative[m] = 0; + } else + bond_negative[m] = 0; } any_angle_negative = 0; @@ -153,7 +136,8 @@ void AtomVecMolecular::pack_restart_pre(int ilocal) angle_negative[m] = 1; angle_type[ilocal][m] = -angle_type[ilocal][m]; any_angle_negative = 1; - } else angle_negative[m] = 0; + } else + angle_negative[m] = 0; } any_dihedral_negative = 0; @@ -162,7 +146,8 @@ void AtomVecMolecular::pack_restart_pre(int ilocal) dihedral_negative[m] = 1; dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; any_dihedral_negative = 1; - } else dihedral_negative[m] = 0; + } else + dihedral_negative[m] = 0; } any_improper_negative = 0; @@ -171,7 +156,8 @@ void AtomVecMolecular::pack_restart_pre(int ilocal) improper_negative[m] = 1; improper_type[ilocal][m] = -improper_type[ilocal][m]; any_improper_negative = 1; - } else improper_negative[m] = 0; + } else + improper_negative[m] = 0; } } @@ -195,14 +181,12 @@ void AtomVecMolecular::pack_restart_post(int ilocal) if (any_dihedral_negative) { for (int m = 0; m < num_dihedral[ilocal]; m++) - if (dihedral_negative[m]) - dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; + if (dihedral_negative[m]) dihedral_type[ilocal][m] = -dihedral_type[ilocal][m]; } if (any_improper_negative) { for (int m = 0; m < num_improper[ilocal]; m++) - if (improper_negative[m]) - improper_type[ilocal][m] = -improper_type[ilocal][m]; + if (improper_negative[m]) improper_type[ilocal][m] = -improper_type[ilocal][m]; } } diff --git a/src/MOLECULE/atom_vec_template.cpp b/src/MOLECULE/atom_vec_template.cpp index 919f5c9aec..8202ea77f3 100644 --- a/src/MOLECULE/atom_vec_template.cpp +++ b/src/MOLECULE/atom_vec_template.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -36,18 +35,15 @@ AtomVecTemplate::AtomVecTemplate(LAMMPS *lmp) : AtomVec(lmp) // order of fields in the string does not matter // except fields_data_atom and fields_data_vel which must match data file - fields_grow = (char *) "molecule molindex molatom"; - fields_copy = (char *) "molecule molindex molatom"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "molecule molindex molatom"; - fields_border_vel = (char *) "molecule molindex molatom"; - fields_exchange = (char *) "molecule molindex molatom"; - fields_restart = (char *) "molecule molindex molatom"; - fields_create = (char *) "molecule molindex molatom"; - fields_data_atom = (char *) "id molecule molindex molatom type x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"molecule", "molindex", "molatom"}; + fields_copy = {"molecule", "molindex", "molatom"}; + fields_border = {"molecule", "molindex", "molatom"}; + fields_border_vel = {"molecule", "molindex", "molatom"}; + fields_exchange = {"molecule", "molindex", "molatom"}; + fields_restart = {"molecule", "molindex", "molatom"}; + fields_create = {"molecule", "molindex", "molatom"}; + fields_data_atom = {"id", "molecule", "molindex", "molatom", "type", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -58,11 +54,10 @@ AtomVecTemplate::AtomVecTemplate(LAMMPS *lmp) : AtomVec(lmp) void AtomVecTemplate::process_args(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Illegal atom_style template command"); + if (narg != 1) error->all(FLERR, "Illegal atom_style template command"); int imol = atom->find_molecule(arg[0]); - if (imol == -1) error->all(FLERR,"Molecule template ID for " - "atom_style template does not exist"); + if (imol == -1) error->all(FLERR, "Molecule template ID for atom_style template does not exist"); onemols = &atom->molecules[imol]; nset = atom->molecules[imol]->nset; @@ -81,10 +76,10 @@ void AtomVecTemplate::process_args(int narg, char **arg) // do this here b/c data file will typically not contain these settings for (int i = 0; i < nset; i++) { - atom->nbondtypes = MAX(atom->nbondtypes,onemols[i]->nbondtypes); - atom->nangletypes = MAX(atom->nangletypes,onemols[i]->nangletypes); - atom->ndihedraltypes = MAX(atom->ndihedraltypes,onemols[i]->ndihedraltypes); - atom->nimpropertypes = MAX(atom->nimpropertypes,onemols[i]->nimpropertypes); + atom->nbondtypes = MAX(atom->nbondtypes, onemols[i]->nbondtypes); + atom->nangletypes = MAX(atom->nangletypes, onemols[i]->nangletypes); + atom->ndihedraltypes = MAX(atom->ndihedraltypes, onemols[i]->ndihedraltypes); + atom->nimpropertypes = MAX(atom->nimpropertypes, onemols[i]->nimpropertypes); } } @@ -129,7 +124,6 @@ void AtomVecTemplate::pack_data_post(int ilocal) molatom[ilocal]--; } - /* ---------------------------------------------------------------------- modify what AtomVec::data_atom() just unpacked or initialize other atom quantities @@ -141,7 +135,7 @@ void AtomVecTemplate::data_atom_post(int ilocal) int molatom_one = --molatom[ilocal]; if ((molindex_one < -1) || (molindex_one >= nset)) - error->one(FLERR,"Invalid template index in Atoms section of data file"); + error->one(FLERR, "Invalid template index in Atoms section of data file"); if ((molatom_one < -1) || ((molindex_one >= 0) && (molatom_one >= onemols[molindex_one]->natoms))) - error->one(FLERR,"Invalid template atom in Atoms section of data file"); + error->one(FLERR, "Invalid template atom in Atoms section of data file"); } diff --git a/src/MOLECULE/bond_fene.cpp b/src/MOLECULE/bond_fene.cpp index 8daf6e862c..2950d48ca6 100644 --- a/src/MOLECULE/bond_fene.cpp +++ b/src/MOLECULE/bond_fene.cpp @@ -265,7 +265,7 @@ double BondFENE::single(int type, double rsq, int /*i*/, int /*j*/, double &ffor void *BondFENE::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kappa") == 0) return (void *) k; + if (strcmp(str, "k") == 0) return (void *) k; if (strcmp(str, "r0") == 0) return (void *) r0; return nullptr; } diff --git a/src/MOLECULE/bond_gromos.cpp b/src/MOLECULE/bond_gromos.cpp index adf3f91044..4572d2c900 100644 --- a/src/MOLECULE/bond_gromos.cpp +++ b/src/MOLECULE/bond_gromos.cpp @@ -30,10 +30,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -BondGromos::BondGromos(LAMMPS *_lmp) : Bond(_lmp) -{ - reinitflag = 1; -} +BondGromos::BondGromos(LAMMPS *_lmp) : Bond(_lmp) {} /* ---------------------------------------------------------------------- */ @@ -200,7 +197,7 @@ double BondGromos::single(int type, double rsq, int /*i*/, int /*j*/, double &ff void *BondGromos::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kappa") == 0) return (void *) k; + if (strcmp(str, "k") == 0) return (void *) k; if (strcmp(str, "r0") == 0) return (void *) r0; return nullptr; } diff --git a/src/MOLECULE/bond_harmonic.cpp b/src/MOLECULE/bond_harmonic.cpp index b7c16084a0..c946d9ff89 100644 --- a/src/MOLECULE/bond_harmonic.cpp +++ b/src/MOLECULE/bond_harmonic.cpp @@ -29,7 +29,6 @@ using namespace LAMMPS_NS; BondHarmonic::BondHarmonic(LAMMPS *_lmp) : Bond(_lmp) { - reinitflag = 1; born_matrix_enable = 1; } @@ -216,12 +215,13 @@ void BondHarmonic::born_matrix(int type, double rsq, int /*i*/, int /*j*/, } /* ---------------------------------------------------------------------- - Return ptr to internal members upon request. + return ptr to internal members upon request ------------------------------------------------------------------------ */ + void *BondHarmonic::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kappa") == 0) return (void *) k; + if (strcmp(str, "k") == 0) return (void *) k; if (strcmp(str, "r0") == 0) return (void *) r0; return nullptr; } diff --git a/src/OPENMP/respa_omp.cpp b/src/OPENMP/respa_omp.cpp index c6500185ad..93eb3c41ef 100644 --- a/src/OPENMP/respa_omp.cpp +++ b/src/OPENMP/respa_omp.cpp @@ -77,7 +77,7 @@ void RespaOMP::setup(int flag) mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); mesg += "\n r-RESPA fixes :"; - for (int l = 0; l < modify->n_post_force_respa; ++l) { + for (int l = 0; l < modify->n_post_force_respa_any; ++l) { Fix *f = modify->get_fix_by_index(modify->list_post_force_respa[l]); if (f->respa_level >= 0) mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); @@ -420,7 +420,7 @@ void RespaOMP::recurse(int ilevel) timer->stamp(Timer::COMM); } timer->stamp(); - if (modify->n_post_force_respa) + if (modify->n_post_force_respa_any) modify->post_force_respa(vflag,ilevel,iloop); modify->final_integrate_respa(ilevel,iloop); timer->stamp(Timer::MODIFY); diff --git a/src/PERI/atom_vec_peri.cpp b/src/PERI/atom_vec_peri.cpp index a0483efb4d..fd6b47990a 100644 --- a/src/PERI/atom_vec_peri.cpp +++ b/src/PERI/atom_vec_peri.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,20 +22,19 @@ #include "error.h" #include -#include using namespace LAMMPS_NS; static const char cite_peri_package[] = - "PERI package for Peridynamics:\n\n" - "@Article{Parks08,\n" - " author = {M. L. Parks, R. B. Lehoucq, S. J. Plimpton, S. A. Silling},\n" - " title = {Implementing peridynamics within a molecular dynamics code},\n" - " journal = {Comp.~Phys.~Comm.},\n" - " year = 2008,\n" - " volume = 179,\n" - " pages = {777--783}\n" - "}\n\n"; + "PERI package for Peridynamics:\n\n" + "@Article{Parks08,\n" + " author = {M. L. Parks, R. B. Lehoucq, S. J. Plimpton, S. A. Silling},\n" + " title = {Implementing peridynamics within a molecular dynamics code},\n" + " journal = {Comp.~Phys.~Comm.},\n" + " year = 2008,\n" + " volume = 179,\n" + " pages = {777--783}\n" + "}\n\n"; /* ---------------------------------------------------------------------- */ @@ -55,18 +53,17 @@ AtomVecPeri::AtomVecPeri(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rmass vfrac s0 x0"; - fields_copy = (char *) "rmass vfrac s0 x0"; - fields_comm = (char *) "s0"; - fields_comm_vel = (char *) "s0"; - fields_reverse = (char *) ""; - fields_border = (char *) "rmass vfrac s0 x0"; - fields_border_vel = (char *) "rmass vfrac s0 x0"; - fields_exchange = (char *) "rmass vfrac s0 x0"; - fields_restart = (char *) "rmass vfrac s0 x0"; - fields_create = (char *) "rmass vfrac s0 x0"; - fields_data_atom = (char *) "id type vfrac rmass x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"rmass", "vfrac", "s0", "x0"}; + fields_copy = {"rmass", "vfrac", "s0", "x0"}; + fields_comm = {"s0"}; + fields_comm_vel = {"s0"}; + fields_border = {"rmass", "vfrac", "s0", "x0"}; + fields_border_vel = {"rmass", "vfrac", "s0", "x0"}; + fields_exchange = {"rmass", "vfrac", "s0", "x0"}; + fields_restart = {"rmass", "vfrac", "s0", "x0"}; + fields_create = {"rmass", "vfrac", "s0", "x0"}; + fields_data_atom = {"id", "type", "vfrac", "rmass", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -110,8 +107,7 @@ void AtomVecPeri::data_atom_post(int ilocal) x0[ilocal][1] = x[ilocal][1]; x0[ilocal][2] = x[ilocal][2]; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid mass in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid mass in Atoms section of data file"); } /* ---------------------------------------------------------------------- @@ -119,10 +115,10 @@ void AtomVecPeri::data_atom_post(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecPeri::property_atom(char *name) +int AtomVecPeri::property_atom(const std::string &name) { - if (strcmp(name,"vfrac") == 0) return 0; - if (strcmp(name,"s0") == 0) return 1; + if (name == "vfrac") return 0; + if (name == "s0") return 1; return -1; } @@ -131,8 +127,7 @@ int AtomVecPeri::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecPeri::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecPeri::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int *mask = atom->mask; int nlocal = atom->nlocal; @@ -140,14 +135,18 @@ void AtomVecPeri::pack_property_atom(int index, double *buf, if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = vfrac[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = vfrac[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = s0[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = s0[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/PERI/atom_vec_peri.h b/src/PERI/atom_vec_peri.h index 0d37138b36..3e990afb88 100644 --- a/src/PERI/atom_vec_peri.h +++ b/src/PERI/atom_vec_peri.h @@ -31,7 +31,7 @@ class AtomVecPeri : public AtomVec { void grow_pointers() override; void create_atom_post(int) override; void data_atom_post(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: diff --git a/src/PHONON/dynamical_matrix.cpp b/src/PHONON/dynamical_matrix.cpp index 3723a7a467..8f667f51f2 100644 --- a/src/PHONON/dynamical_matrix.cpp +++ b/src/PHONON/dynamical_matrix.cpp @@ -431,7 +431,7 @@ void DynamicalMatrix::update_force() force_clear(); int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; if (n_pre_force) { modify->pre_force(vflag); diff --git a/src/PHONON/third_order.cpp b/src/PHONON/third_order.cpp index 76d90c65bd..bbd6818b95 100644 --- a/src/PHONON/third_order.cpp +++ b/src/PHONON/third_order.cpp @@ -487,7 +487,7 @@ void ThirdOrder::update_force() neighbor->ago = 0; if (modify->get_fix_by_id("package_intel")) neighbor->decide(); force_clear(); - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; diff --git a/src/REPLICA/verlet_split.cpp b/src/REPLICA/verlet_split.cpp index 95cd54119c..661b86129c 100644 --- a/src/REPLICA/verlet_split.cpp +++ b/src/REPLICA/verlet_split.cpp @@ -300,7 +300,7 @@ void VerletSplit::run(int n) int n_pre_neighbor = modify->n_pre_neighbor; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force = modify->n_post_force_any; int n_end_of_step = modify->n_end_of_step; if (atom->sortfreq > 0) sortflag = 1; diff --git a/src/SPH/atom_vec_sph.cpp b/src/SPH/atom_vec_sph.cpp index 46f9d828e8..a26967a57b 100644 --- a/src/SPH/atom_vec_sph.cpp +++ b/src/SPH/atom_vec_sph.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -16,8 +15,6 @@ #include "atom.h" -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -38,18 +35,18 @@ AtomVecSPH::AtomVecSPH(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rho drho esph desph cv vest"; - fields_copy = (char *) "rho drho esph desph cv vest"; - fields_comm = (char *) "rho esph vest"; - fields_comm_vel = (char *) "rho esph vest"; - fields_reverse = (char *) "drho desph"; - fields_border = (char *) "rho esph cv vest"; - fields_border_vel = (char *) "rho esph cv vest"; - fields_exchange = (char *) "rho esph cv vest"; - fields_restart = (char * ) "rho esph cv vest"; - fields_create = (char *) "rho esph cv vest desph drho"; - fields_data_atom = (char *) "id type rho esph cv x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"rho", "drho", "esph", "desph", "cv", "vest"}; + fields_copy = {"rho", "drho", "esph", "desph", "cv", "vest"}; + fields_comm = {"rho", "esph", "vest"}; + fields_comm_vel = {"rho", "esph", "vest"}; + fields_reverse = {"drho", "desph"}; + fields_border = {"rho", "esph", "cv", "vest"}; + fields_border_vel = {"rho", "esph", "cv", "vest"}; + fields_exchange = {"rho", "esph", "cv", "vest"}; + fields_restart = {"rho", "esph", "cv", "vest"}; + fields_create = {"rho", "esph", "cv", "vest", "desph", "drho"}; + fields_data_atom = {"id", "type", "rho", "esph", "cv", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -76,8 +73,8 @@ void AtomVecSPH::grow_pointers() void AtomVecSPH::force_clear(int n, size_t nbytes) { - memset(&desph[n],0,nbytes); - memset(&drho[n],0,nbytes); + memset(&desph[n], 0, nbytes); + memset(&drho[n], 0, nbytes); } /* ---------------------------------------------------------------------- @@ -108,13 +105,13 @@ void AtomVecSPH::data_atom_post(int ilocal) return -1 if name is unknown to this atom style ------------------------------------------------------------------------- */ -int AtomVecSPH::property_atom(char *name) +int AtomVecSPH::property_atom(const std::string &name) { - if (strcmp(name,"rho") == 0) return 0; - if (strcmp(name,"drho") == 0) return 1; - if (strcmp(name,"esph") == 0) return 2; - if (strcmp(name,"desph") == 0) return 3; - if (strcmp(name,"cv") == 0) return 4; + if (name == "rho") return 0; + if (name == "drho") return 1; + if (name == "esph") return 2; + if (name == "desph") return 3; + if (name == "cv") return 4; return -1; } @@ -123,8 +120,7 @@ int AtomVecSPH::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecSPH::pack_property_atom(int index, double *buf, - int nvalues, int groupbit) +void AtomVecSPH::pack_property_atom(int index, double *buf, int nvalues, int groupbit) { int *mask = atom->mask; int nlocal = atom->nlocal; @@ -132,32 +128,42 @@ void AtomVecSPH::pack_property_atom(int index, double *buf, if (index == 0) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = rho[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = rho[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 1) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = drho[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = drho[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 2) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = esph[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = esph[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 3) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = desph[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = desph[i]; + else + buf[n] = 0.0; n += nvalues; } } else if (index == 4) { for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = cv[i]; - else buf[n] = 0.0; + if (mask[i] & groupbit) + buf[n] = cv[i]; + else + buf[n] = 0.0; n += nvalues; } } diff --git a/src/SPH/atom_vec_sph.h b/src/SPH/atom_vec_sph.h index 8af3ac2fc3..18d82d76de 100644 --- a/src/SPH/atom_vec_sph.h +++ b/src/SPH/atom_vec_sph.h @@ -32,7 +32,7 @@ class AtomVecSPH : public AtomVec { void force_clear(int, size_t) override; void create_atom_post(int) override; void data_atom_post(int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: diff --git a/src/SPIN/atom_vec_spin.cpp b/src/SPIN/atom_vec_spin.cpp index 4f3d0a3aab..209704fef8 100644 --- a/src/SPIN/atom_vec_spin.cpp +++ b/src/SPIN/atom_vec_spin.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator @@ -25,10 +24,11 @@ ------------------------------------------------------------------------- */ #include "atom_vec_spin.h" -#include -#include + #include "atom.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -46,18 +46,18 @@ AtomVecSpin::AtomVecSpin(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "sp fm fm_long"; - fields_copy = (char *) "sp"; - fields_comm = (char *) "sp"; - fields_comm_vel = (char *) "sp"; - fields_reverse = (char *) "fm fm_long"; - fields_border = (char *) "sp"; - fields_border_vel = (char *) "sp"; - fields_exchange = (char *) "sp"; - fields_restart = (char *) "sp"; - fields_create = (char *) "sp"; - fields_data_atom = (char *) "id type x sp"; - fields_data_vel = (char *) "id v"; + fields_grow = {"sp", "fm", "fm_long"}; + fields_copy = {"sp"}; + fields_comm = {"sp"}; + fields_comm_vel = {"sp"}; + fields_reverse = {"fm", "fm_long"}; + fields_border = {"sp"}; + fields_border_vel = {"sp"}; + fields_exchange = {"sp"}; + fields_restart = {"sp"}; + fields_create = {"sp"}; + fields_data_atom = {"id", "type", "x", "sp"}; + fields_data_vel = {"id", "v"}; setup_fields(); } @@ -82,8 +82,8 @@ void AtomVecSpin::grow_pointers() void AtomVecSpin::force_clear(int n, size_t nbytes) { - memset(&fm[n][0],0,3*nbytes); - memset(&fm_long[n][0],0,3*nbytes); + memset(&fm[n][0], 0, 3 * nbytes); + memset(&fm_long[n][0], 0, 3 * nbytes); } /* ---------------------------------------------------------------------- @@ -94,8 +94,7 @@ void AtomVecSpin::force_clear(int n, size_t nbytes) void AtomVecSpin::data_atom_post(int ilocal) { double *sp_one = sp[ilocal]; - double norm = - 1.0/sqrt(sp_one[0]*sp_one[0] + sp_one[1]*sp_one[1] + sp_one[2]*sp_one[2]); + double norm = 1.0 / sqrt(sp_one[0] * sp_one[0] + sp_one[1] * sp_one[1] + sp_one[2] * sp_one[2]); sp_one[0] *= norm; sp_one[1] *= norm; sp_one[2] *= norm; diff --git a/src/angle.cpp b/src/angle.cpp index d41b7e2541..5abc02cd0f 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -354,3 +354,15 @@ double Angle::memory_usage() bytes += (double) comm->nthreads * maxcvatom * 9 * sizeof(double); return bytes; } + +/* ----------------------------------------------------------------------- + reset all type-based angle params via init() +-------------------------------------------------------------------------- */ + +void Angle::reinit() +{ + if (!reinitflag) + error->all(FLERR, "Fix adapt interface to this angle style not supported"); + + init(); +} diff --git a/src/angle.h b/src/angle.h index bf6488c08e..be3644640d 100644 --- a/src/angle.h +++ b/src/angle.h @@ -37,6 +37,9 @@ class Angle : protected Pointers { // CENTROID_AVAIL = different and implemented // CENTROID_NOTAVAIL = different, not yet implemented + int reinitflag; // 0 if not compatible with fix adapt + // extract() method may still need to be added + // KOKKOS host/device flag and data masks ExecutionSpace execution_space; @@ -63,6 +66,8 @@ class Angle : protected Pointers { du2 = 0.0; } virtual double memory_usage(); + virtual void *extract(const char *, int &) { return nullptr; } + void reinit(); protected: int suffix_flag; // suffix compatibility flag diff --git a/src/atom.cpp b/src/atom.cpp index 7fc126269c..69a3b21cf5 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -47,7 +47,6 @@ using namespace LAMMPS_NS; using namespace MathConst; #define DELTA 1 -#define DELTA_PERATOM 64 #define EPSILON 1.0e-6 /* ---------------------------------------------------------------------- @@ -105,11 +104,6 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) binhead = nullptr; next = permute = nullptr; - // data structure with info on per-atom vectors/arrays - - nperatom = maxperatom = 0; - peratom = nullptr; - // -------------------------------------------------------------------- // 1st customization section: customize by adding new per-atom variables @@ -286,11 +280,11 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) Atom::~Atom() { - delete [] atom_style; + delete[] atom_style; delete avec; delete avec_map; - delete [] firstgroupname; + delete[] firstgroupname; memory->destroy(binhead); memory->destroy(next); memory->destroy(permute); @@ -303,12 +297,6 @@ Atom::~Atom() memory->destroy(v); memory->destroy(f); - // delete peratom data struct - - for (int i = 0; i < nperatom; i++) - delete [] peratom[i].name; - memory->sfree(peratom); - // delete custom atom arrays for (int i = 0; i < nivector; i++) { @@ -385,12 +373,7 @@ void Atom::settings(Atom *old) void Atom::peratom_create() { - for (int i = 0; i < nperatom; i++) - delete [] peratom[i].name; - memory->sfree(peratom); - - peratom = nullptr; - nperatom = maxperatom = 0; + peratom.clear(); // -------------------------------------------------------------------- // 2nd customization section: add peratom variables here, order does not matter @@ -571,23 +554,11 @@ void Atom::peratom_create() use add_peratom_vary() when column count varies per atom ------------------------------------------------------------------------- */ -void Atom::add_peratom(const char *name, void *address, +void Atom::add_peratom(const std::string &name, void *address, int datatype, int cols, int threadflag) { - if (nperatom == maxperatom) { - maxperatom += DELTA_PERATOM; - peratom = (PerAtom *) - memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom"); - } - - peratom[nperatom].name = utils::strdup(name); - peratom[nperatom].address = address; - peratom[nperatom].datatype = datatype; - peratom[nperatom].cols = cols; - peratom[nperatom].threadflag = threadflag; - peratom[nperatom].address_length = nullptr; - - nperatom++; + PerAtom item = {name, address, nullptr, nullptr, datatype, cols, 0, threadflag}; + peratom.push_back(item); } /* ---------------------------------------------------------------------- @@ -596,15 +567,13 @@ void Atom::add_peratom(const char *name, void *address, see atom_style tdpd as an example ------------------------------------------------------------------------- */ -void Atom::add_peratom_change_columns(const char *name, int cols) +void Atom::add_peratom_change_columns(const std::string &name, int cols) { - for (int i = 0; i < nperatom; i++) { - if (strcmp(name,peratom[i].name) == 0) { - peratom[i].cols = cols; - return; - } - } - error->all(FLERR,"Could not find name of peratom array for column change"); + auto match = std::find_if(peratom.begin(), peratom.end(), + [&name] (const PerAtom &p) { return p.name == name; }); + + if (match != peratom.end()) (*match).cols = cols; + else error->all(FLERR,"Could not find per-atom array name {} for column change", name); } /* ---------------------------------------------------------------------- @@ -619,25 +588,11 @@ void Atom::add_peratom_change_columns(const char *name, int cols) e.g. nspecial ------------------------------------------------------------------------- */ -void Atom::add_peratom_vary(const char *name, void *address, +void Atom::add_peratom_vary(const std::string &name, void *address, int datatype, int *cols, void *length, int collength) { - if (nperatom == maxperatom) { - maxperatom += DELTA_PERATOM; - peratom = (PerAtom *) - memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom"); - } - - peratom[nperatom].name = utils::strdup(name); - peratom[nperatom].address = address; - peratom[nperatom].datatype = datatype; - peratom[nperatom].cols = -1; - peratom[nperatom].threadflag = 0; - peratom[nperatom].address_maxcols = cols; - peratom[nperatom].address_length = length; - peratom[nperatom].collength = collength; - - nperatom++; + PerAtom item = {name, address, length, cols, datatype, -1, collength, 0}; + peratom.push_back(item); } /* ---------------------------------------------------------------------- @@ -2917,4 +2872,3 @@ double Atom::memory_usage() return bytes; } - diff --git a/src/atom.h b/src/atom.h index 06e65a4358..00de80fc6b 100644 --- a/src/atom.h +++ b/src/atom.h @@ -213,7 +213,7 @@ class Atom : protected Pointers { // per-atom data struct describing all per-atom vectors/arrays struct PerAtom { - char *name; + std::string name; void *address; void *address_length; int *address_maxcols; @@ -223,8 +223,7 @@ class Atom : protected Pointers { int threadflag; }; - PerAtom *peratom; - int nperatom, maxperatom; + std::vector peratom; // custom vectors and arrays used by fix property/atom @@ -293,9 +292,9 @@ class Atom : protected Pointers { void settings(class Atom *); void peratom_create(); - void add_peratom(const char *, void *, int, int, int threadflag = 0); - void add_peratom_change_columns(const char *, int); - void add_peratom_vary(const char *, void *, int, int *, void *, int collength = 0); + void add_peratom(const std::string &, void *, int, int, int threadflag = 0); + void add_peratom_change_columns(const std::string &, int); + void add_peratom_vary(const std::string &, void *, int, int *, void *, int collength = 0); void create_avec(const std::string &, int, char **, int); virtual AtomVec *new_avec(const std::string &, int, int &); diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index 6d1412cbd4..deff0cfd58 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -28,7 +27,24 @@ #include using namespace LAMMPS_NS; -using namespace MathConst; + +// peratom variables that are auto-included in corresponding child style field lists +// these fields cannot be specified in the fields strings + +const std::vector AtomVec::default_grow = {"id", "type", "mask", "image", + "x", "v", "f"}; +const std::vector AtomVec::default_copy = {"id", "type", "mask", "image", "x", "v"}; +const std::vector AtomVec::default_comm = {"x"}; +const std::vector AtomVec::default_comm_vel = {"x", "v"}; +const std::vector AtomVec::default_reverse = {"f"}; +const std::vector AtomVec::default_border = {"id", "type", "mask", "x"}; +const std::vector AtomVec::default_border_vel = {"id", "type", "mask", "x", "v"}; +const std::vector AtomVec::default_exchange = {"id", "type", "mask", + "image", "x", "v"}; +const std::vector AtomVec::default_restart = {"id", "type", "mask", "image", "x", "v"}; +const std::vector AtomVec::default_create = {"id", "type", "mask", "image", "x", "v"}; +const std::vector AtomVec::default_data_atom = {}; +const std::vector AtomVec::default_data_vel = {}; /* ---------------------------------------------------------------------- */ @@ -56,33 +72,17 @@ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp) x = v = f = nullptr; threads = nullptr; - - // peratom variables auto-included in corresponding child style fields string - // these fields cannot be specified in the fields string - - default_grow = "id type mask image x v f"; - default_copy = "id type mask image x v"; - default_comm = "x"; - default_comm_vel = "x v"; - default_reverse = "f"; - default_border = "id type mask x"; - default_border_vel = "id type mask x v"; - default_exchange = "id type mask image x v"; - default_restart = "id type mask image x v"; - default_create = "id type mask image x v"; - default_data_atom = ""; - default_data_vel = ""; } /* ---------------------------------------------------------------------- */ AtomVec::~AtomVec() { - int datatype,cols; + int datatype, cols; void *pdata; - for (int i = 0; i < nargcopy; i++) delete [] argcopy[i]; - delete [] argcopy; + for (int i = 0; i < nargcopy; i++) delete[] argcopy[i]; + delete[] argcopy; for (int i = 0; i < ngrow; i++) { pdata = mgrow.pdata[i]; @@ -115,7 +115,7 @@ AtomVec::~AtomVec() } } - delete [] threads; + delete[] threads; } /* ---------------------------------------------------------------------- @@ -125,10 +125,11 @@ AtomVec::~AtomVec() void AtomVec::store_args(int narg, char **arg) { nargcopy = narg; - if (nargcopy) argcopy = new char*[nargcopy]; - else argcopy = nullptr; - for (int i = 0; i < nargcopy; i++) - argcopy[i] = utils::strdup(arg[i]); + if (nargcopy) + argcopy = new char *[nargcopy]; + else + argcopy = nullptr; + for (int i = 0; i < nargcopy; i++) argcopy[i] = utils::strdup(arg[i]); } /* ---------------------------------------------------------------------- @@ -137,7 +138,7 @@ void AtomVec::store_args(int narg, char **arg) void AtomVec::process_args(int narg, char ** /*arg*/) { - if (narg) error->all(FLERR,"Invalid atom_style command"); + if (narg) error->all(FLERR, "Invalid atom_style command"); } /* ---------------------------------------------------------------------- @@ -152,10 +153,10 @@ void AtomVec::init() h_rate = domain->h_rate; if (lmp->kokkos != nullptr && !kokkosable) - error->all(FLERR,"KOKKOS package requires a kokkos enabled atom_style"); + error->all(FLERR, "KOKKOS package requires a kokkos enabled atom_style"); } -static constexpr bigint DELTA=16384; +static constexpr bigint DELTA = 16384; /* ---------------------------------------------------------------------- roundup N so it is a multiple of DELTA @@ -164,9 +165,8 @@ static constexpr bigint DELTA=16384; bigint AtomVec::roundup(bigint n) { - if (n % DELTA) n = n/DELTA * DELTA + DELTA; - if (n > MAXSMALLINT) - error->one(FLERR,"Too many atoms created on one or more procs"); + if (n % DELTA) n = n / DELTA * DELTA + DELTA; + if (n > MAXSMALLINT) error->one(FLERR, "Too many atoms created on one or more procs"); return n; } @@ -176,11 +176,11 @@ bigint AtomVec::roundup(bigint n) void AtomVec::grow_nmax() { - nmax = nmax/DELTA * DELTA; + nmax = nmax / DELTA * DELTA; nmax += DELTA; } -static constexpr bigint DELTA_BONUS=8192; +static constexpr bigint DELTA_BONUS = 8192; /* ---------------------------------------------------------------------- grow nmax_bonus so it is a multiple of DELTA_BONUS @@ -188,7 +188,7 @@ static constexpr bigint DELTA_BONUS=8192; int AtomVec::grow_nmax_bonus(int nmax_bonus) { - nmax_bonus = nmax_bonus/DELTA_BONUS * DELTA_BONUS; + nmax_bonus = nmax_bonus / DELTA_BONUS * DELTA_BONUS; nmax_bonus += DELTA_BONUS; return nmax_bonus; } @@ -201,22 +201,23 @@ int AtomVec::grow_nmax_bonus(int nmax_bonus) void AtomVec::grow(int n) { - int datatype,cols,maxcols; + int datatype, cols, maxcols; void *pdata; - if (n == 0) grow_nmax(); - else nmax = n; + if (n == 0) + grow_nmax(); + else + nmax = n; atom->nmax = nmax; - if (nmax < 0 || nmax > MAXSMALLINT) - error->one(FLERR,"Per-processor system is too big"); + if (nmax < 0 || nmax > MAXSMALLINT) error->one(FLERR, "Per-processor system is too big"); - tag = memory->grow(atom->tag,nmax,"atom:tag"); - type = memory->grow(atom->type,nmax,"atom:type"); - mask = memory->grow(atom->mask,nmax,"atom:mask"); - image = memory->grow(atom->image,nmax,"atom:image"); - x = memory->grow(atom->x,nmax,3,"atom:x"); - v = memory->grow(atom->v,nmax,3,"atom:v"); - f = memory->grow(atom->f,nmax*comm->nthreads,3,"atom:f"); + tag = memory->grow(atom->tag, nmax, "atom:tag"); + type = memory->grow(atom->type, nmax, "atom:type"); + mask = memory->grow(atom->mask, nmax, "atom:mask"); + image = memory->grow(atom->image, nmax, "atom:image"); + x = memory->grow(atom->x, nmax, 3, "atom:x"); + v = memory->grow(atom->v, nmax, 3, "atom:v"); + f = memory->grow(atom->f, nmax * comm->nthreads, 3, "atom:f"); for (int i = 0; i < ngrow; i++) { pdata = mgrow.pdata[i]; @@ -225,30 +226,30 @@ void AtomVec::grow(int n) const int nthreads = threads[i] ? comm->nthreads : 1; if (datatype == Atom::DOUBLE) { if (cols == 0) - memory->grow(*((double **) pdata),nmax*nthreads,"atom:dvec"); + memory->grow(*((double **) pdata), nmax * nthreads, "atom:dvec"); else if (cols > 0) - memory->grow(*((double ***) pdata),nmax*nthreads,cols,"atom:darray"); + memory->grow(*((double ***) pdata), nmax * nthreads, cols, "atom:darray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((double ***) pdata),nmax*nthreads,maxcols,"atom:darray"); + memory->grow(*((double ***) pdata), nmax * nthreads, maxcols, "atom:darray"); } } else if (datatype == Atom::INT) { if (cols == 0) - memory->grow(*((int **) pdata),nmax*nthreads,"atom:ivec"); + memory->grow(*((int **) pdata), nmax * nthreads, "atom:ivec"); else if (cols > 0) - memory->grow(*((int ***) pdata),nmax*nthreads,cols,"atom:iarray"); + memory->grow(*((int ***) pdata), nmax * nthreads, cols, "atom:iarray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((int ***) pdata),nmax*nthreads,maxcols,"atom:iarray"); + memory->grow(*((int ***) pdata), nmax * nthreads, maxcols, "atom:iarray"); } } else if (datatype == Atom::BIGINT) { if (cols == 0) - memory->grow(*((bigint **) pdata),nmax*nthreads,"atom:bvec"); + memory->grow(*((bigint **) pdata), nmax * nthreads, "atom:bvec"); else if (cols > 0) - memory->grow(*((bigint ***) pdata),nmax*nthreads,cols,"atom:barray"); + memory->grow(*((bigint ***) pdata), nmax * nthreads, cols, "atom:barray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((bigint ***) pdata),nmax*nthreads,maxcols,"atom:barray"); + memory->grow(*((bigint ***) pdata), nmax * nthreads, maxcols, "atom:barray"); } } } @@ -265,8 +266,8 @@ void AtomVec::grow(int n) void AtomVec::copy(int i, int j, int delflag) { - int m,n,datatype,cols,collength,ncols; - void *pdata,*plength; + int m, n, datatype, cols, collength, ncols; + void *pdata, *plength; tag[j] = tag[i]; type[j] = type[i]; @@ -290,33 +291,33 @@ void AtomVec::copy(int i, int j, int delflag) vec[j] = vec[i]; } else if (cols > 0) { double **array = *((double ***) pdata); - for (m = 0; m < cols; m++) - array[j][m] = array[i][m]; + for (m = 0; m < cols; m++) array[j][m] = array[i][m]; } else { double **array = *((double ***) pdata); collength = mcopy.collength[n]; plength = mcopy.plength[n]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (m = 0; m < ncols; m++) - array[j][m] = array[i][m]; - } + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (m = 0; m < ncols; m++) array[j][m] = array[i][m]; + } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); vec[j] = vec[i]; } else if (cols > 0) { int **array = *((int ***) pdata); - for (m = 0; m < cols; m++) - array[j][m] = array[i][m]; + for (m = 0; m < cols; m++) array[j][m] = array[i][m]; } else { int **array = *((int ***) pdata); collength = mcopy.collength[n]; plength = mcopy.plength[n]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (m = 0; m < ncols; m++) - array[j][m] = array[i][m]; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (m = 0; m < ncols; m++) array[j][m] = array[i][m]; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -324,35 +325,34 @@ void AtomVec::copy(int i, int j, int delflag) vec[j] = vec[i]; } else if (cols > 0) { bigint **array = *((bigint ***) pdata); - for (m = 0; m < cols; m++) - array[j][m] = array[i][m]; + for (m = 0; m < cols; m++) array[j][m] = array[i][m]; } else { bigint **array = *((bigint ***) pdata); collength = mcopy.collength[n]; plength = mcopy.plength[n]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (m = 0; m < ncols; m++) - array[j][m] = array[i][m]; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (m = 0; m < ncols; m++) array[j][m] = array[i][m]; } } } } - if (bonus_flag) copy_bonus(i,j,delflag); + if (bonus_flag) copy_bonus(i, j, delflag); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); + modify->fix[atom->extra_grow[iextra]]->copy_arrays(i, j, delflag); } /* ---------------------------------------------------------------------- */ -int AtomVec::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) +int AtomVec::pack_comm(int n, int *list, double *buf, int pbc_flag, int *pbc) { - int i,j,m,mm,nn,datatype,cols; - double dx,dy,dz; + int i, j, m, mm, nn, datatype, cols; + double dx, dy, dz; void *pdata; m = 0; @@ -365,13 +365,13 @@ int AtomVec::pack_comm(int n, int *list, double *buf, } } else { if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd; + dy = pbc[1] * domain->yprd; + dz = pbc[2] * domain->zprd; } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd + pbc[5] * domain->xy + pbc[4] * domain->xz; + dy = pbc[1] * domain->yprd + pbc[3] * domain->yz; + dz = pbc[2] * domain->zprd; } for (i = 0; i < n; i++) { j = list[i]; @@ -397,8 +397,7 @@ int AtomVec::pack_comm(int n, int *list, double *buf, double **array = *((double ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = array[j][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[j][mm]; } } } else if (datatype == Atom::INT) { @@ -412,8 +411,7 @@ int AtomVec::pack_comm(int n, int *list, double *buf, int **array = *((int ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } else if (datatype == Atom::BIGINT) { @@ -427,26 +425,24 @@ int AtomVec::pack_comm(int n, int *list, double *buf, bigint **array = *((bigint ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } } } - if (bonus_flag) m += pack_comm_bonus(n,list,&buf[m]); + if (bonus_flag) m += pack_comm_bonus(n, list, &buf[m]); return m; } /* ---------------------------------------------------------------------- */ -int AtomVec::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) +int AtomVec::pack_comm_vel(int n, int *list, double *buf, int pbc_flag, int *pbc) { - int i,j,m,mm,nn,datatype,cols; - double dx,dy,dz,dvx,dvy,dvz; + int i, j, m, mm, nn, datatype, cols; + double dx, dy, dz, dvx, dvy, dvz; void *pdata; m = 0; @@ -462,13 +458,13 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, } } else { if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd; + dy = pbc[1] * domain->yprd; + dz = pbc[2] * domain->zprd; } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd + pbc[5] * domain->xy + pbc[4] * domain->xz; + dy = pbc[1] * domain->yprd + pbc[3] * domain->yz; + dz = pbc[2] * domain->zprd; } if (!deform_vremap) { for (i = 0; i < n; i++) { @@ -481,9 +477,9 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, buf[m++] = v[j][2]; } } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; + dvx = pbc[0] * h_rate[0] + pbc[5] * h_rate[5] + pbc[4] * h_rate[4]; + dvy = pbc[1] * h_rate[1] + pbc[3] * h_rate[3]; + dvz = pbc[2] * h_rate[2]; for (i = 0; i < n; i++) { j = list[i]; buf[m++] = x[j][0] + dx; @@ -518,8 +514,7 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, double **array = *((double ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = array[j][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[j][mm]; } } } else if (datatype == Atom::INT) { @@ -533,8 +528,7 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, int **array = *((int ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } else if (datatype == Atom::BIGINT) { @@ -548,15 +542,14 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, bigint **array = *((bigint ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } } } - if (bonus_flag) m += pack_comm_bonus(n,list,&buf[m]); + if (bonus_flag) m += pack_comm_bonus(n, list, &buf[m]); return m; } @@ -565,7 +558,7 @@ int AtomVec::pack_comm_vel(int n, int *list, double *buf, void AtomVec::unpack_comm(int n, int first, double *buf) { - int i,m,last,mm,nn,datatype,cols; + int i, m, last, mm, nn, datatype, cols; void *pdata; m = 0; @@ -584,48 +577,42 @@ void AtomVec::unpack_comm(int n, int first, double *buf) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - for (i = first; i < last; i++) - vec[i] = buf[m++]; + for (i = first; i < last; i++) vec[i] = buf[m++]; } else { double **array = *((double ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[i][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - for (i = first; i < last; i++) - vec[i] = (int) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - for (i = first; i < last; i++) - vec[i] = (bigint) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (bigint) ubuf(buf[m++]).i; } } } } - if (bonus_flag) unpack_comm_bonus(n,first,&buf[m]); + if (bonus_flag) unpack_comm_bonus(n, first, &buf[m]); } /* ---------------------------------------------------------------------- */ void AtomVec::unpack_comm_vel(int n, int first, double *buf) { - int i,m,last,mm,nn,datatype,cols; + int i, m, last, mm, nn, datatype, cols; void *pdata; m = 0; @@ -647,48 +634,42 @@ void AtomVec::unpack_comm_vel(int n, int first, double *buf) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - for (i = first; i < last; i++) - vec[i] = buf[m++]; + for (i = first; i < last; i++) vec[i] = buf[m++]; } else { double **array = *((double ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[i][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - for (i = first; i < last; i++) - vec[i] = (int) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - for (i = first; i < last; i++) - vec[i] = (bigint) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (bigint) ubuf(buf[m++]).i; } } } } - if (bonus_flag) unpack_comm_bonus(n,first,&buf[m]); + if (bonus_flag) unpack_comm_bonus(n, first, &buf[m]); } /* ---------------------------------------------------------------------- */ int AtomVec::pack_reverse(int n, int first, double *buf) { - int i,m,last,mm,nn,datatype,cols; + int i, m, last, mm, nn, datatype, cols; void *pdata; m = 0; @@ -707,40 +688,31 @@ int AtomVec::pack_reverse(int n, int first, double *buf) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - for (i = first; i < last; i++) { - buf[m++] = vec[i]; - } + for (i = first; i < last; i++) { buf[m++] = vec[i]; } } else { double **array = *((double ***) pdata); for (i = first; i < last; i++) { - for (mm = 0; mm < cols; mm++) - buf[m++] = array[i][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[i][mm]; } } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - for (i = first; i < last; i++) { - buf[m++] = ubuf(vec[i]).d; - } + for (i = first; i < last; i++) { buf[m++] = ubuf(vec[i]).d; } } else { int **array = *((int ***) pdata); for (i = first; i < last; i++) { - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - for (i = first; i < last; i++) { - buf[m++] = ubuf(vec[i]).d; - } + for (i = first; i < last; i++) { buf[m++] = ubuf(vec[i]).d; } } else { bigint **array = *((bigint ***) pdata); for (i = first; i < last; i++) { - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } } } @@ -754,7 +726,7 @@ int AtomVec::pack_reverse(int n, int first, double *buf) void AtomVec::unpack_reverse(int n, int *list, double *buf) { - int i,j,m,mm,nn,datatype,cols; + int i, j, m, mm, nn, datatype, cols; void *pdata; m = 0; @@ -781,8 +753,7 @@ void AtomVec::unpack_reverse(int n, int *list, double *buf) double **array = *((double ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - array[j][mm] += buf[m++]; + for (mm = 0; mm < cols; mm++) array[j][mm] += buf[m++]; } } } else if (datatype == Atom::INT) { @@ -796,8 +767,7 @@ void AtomVec::unpack_reverse(int n, int *list, double *buf) int **array = *((int ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - array[j][mm] += (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[j][mm] += (int) ubuf(buf[m++]).i; } } } else if (datatype == Atom::BIGINT) { @@ -811,8 +781,7 @@ void AtomVec::unpack_reverse(int n, int *list, double *buf) bigint **array = *((bigint ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - array[j][mm] += (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[j][mm] += (bigint) ubuf(buf[m++]).i; } } } @@ -824,8 +793,8 @@ void AtomVec::unpack_reverse(int n, int *list, double *buf) int AtomVec::pack_border(int n, int *list, double *buf, int pbc_flag, int *pbc) { - int i,j,m,mm,nn,datatype,cols; - double dx,dy,dz; + int i, j, m, mm, nn, datatype, cols; + double dx, dy, dz; void *pdata; m = 0; @@ -841,9 +810,9 @@ int AtomVec::pack_border(int n, int *list, double *buf, int pbc_flag, int *pbc) } } else { if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd; + dy = pbc[1] * domain->yprd; + dz = pbc[2] * domain->zprd; } else { dx = pbc[0]; dy = pbc[1]; @@ -876,8 +845,7 @@ int AtomVec::pack_border(int n, int *list, double *buf, int pbc_flag, int *pbc) double **array = *((double ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = array[j][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[j][mm]; } } } else if (datatype == Atom::INT) { @@ -891,8 +859,7 @@ int AtomVec::pack_border(int n, int *list, double *buf, int pbc_flag, int *pbc) int **array = *((int ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } else if (datatype == Atom::BIGINT) { @@ -906,30 +873,28 @@ int AtomVec::pack_border(int n, int *list, double *buf, int pbc_flag, int *pbc) bigint **array = *((bigint ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } } } - if (bonus_flag) m += pack_border_bonus(n,list,&buf[m]); + if (bonus_flag) m += pack_border_bonus(n, list, &buf[m]); if (atom->nextra_border) for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); + m += modify->fix[atom->extra_border[iextra]]->pack_border(n, list, &buf[m]); return m; } /* ---------------------------------------------------------------------- */ -int AtomVec::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) +int AtomVec::pack_border_vel(int n, int *list, double *buf, int pbc_flag, int *pbc) { - int i,j,m,mm,nn,datatype,cols; - double dx,dy,dz,dvx,dvy,dvz; + int i, j, m, mm, nn, datatype, cols; + double dx, dy, dz, dvx, dvy, dvz; void *pdata; m = 0; @@ -948,9 +913,9 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, } } else { if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; + dx = pbc[0] * domain->xprd; + dy = pbc[1] * domain->yprd; + dz = pbc[2] * domain->zprd; } else { dx = pbc[0]; dy = pbc[1]; @@ -970,9 +935,9 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, buf[m++] = v[j][2]; } } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; + dvx = pbc[0] * h_rate[0] + pbc[5] * h_rate[5] + pbc[4] * h_rate[4]; + dvy = pbc[1] * h_rate[1] + pbc[3] * h_rate[3]; + dvz = pbc[2] * h_rate[2]; for (i = 0; i < n; i++) { j = list[i]; buf[m++] = x[j][0] + dx; @@ -1010,8 +975,7 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, double **array = *((double ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = array[j][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[j][mm]; } } } else if (datatype == Atom::INT) { @@ -1025,8 +989,7 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, int **array = *((int ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } else if (datatype == Atom::BIGINT) { @@ -1040,19 +1003,18 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, bigint **array = *((bigint ***) pdata); for (i = 0; i < n; i++) { j = list[i]; - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[j][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[j][mm]).d; } } } } } - if (bonus_flag) m += pack_border_bonus(n,list,&buf[m]); + if (bonus_flag) m += pack_border_bonus(n, list, &buf[m]); if (atom->nextra_border) for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); + m += modify->fix[atom->extra_border[iextra]]->pack_border(n, list, &buf[m]); return m; } @@ -1061,7 +1023,7 @@ int AtomVec::pack_border_vel(int n, int *list, double *buf, void AtomVec::unpack_border(int n, int first, double *buf) { - int i,m,last,mm,nn,datatype,cols; + int i, m, last, mm, nn, datatype, cols; void *pdata; m = 0; @@ -1085,53 +1047,46 @@ void AtomVec::unpack_border(int n, int first, double *buf) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - for (i = first; i < last; i++) - vec[i] = buf[m++]; + for (i = first; i < last; i++) vec[i] = buf[m++]; } else { double **array = *((double ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[i][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - for (i = first; i < last; i++) - vec[i] = (int) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - for (i = first; i < last; i++) - vec[i] = (bigint) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (bigint) ubuf(buf[m++]).i; } } } } - if (bonus_flag) m += unpack_border_bonus(n,first,&buf[m]); + if (bonus_flag) m += unpack_border_bonus(n, first, &buf[m]); if (atom->nextra_border) for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); + m += modify->fix[atom->extra_border[iextra]]->unpack_border(n, first, &buf[m]); } /* ---------------------------------------------------------------------- */ void AtomVec::unpack_border_vel(int n, int first, double *buf) { - int i,m,last,mm,nn,datatype,cols; + int i, m, last, mm, nn, datatype, cols; void *pdata; m = 0; @@ -1158,46 +1113,39 @@ void AtomVec::unpack_border_vel(int n, int first, double *buf) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - for (i = first; i < last; i++) - vec[i] = buf[m++]; + for (i = first; i < last; i++) vec[i] = buf[m++]; } else { double **array = *((double ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[i][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - for (i = first; i < last; i++) - vec[i] = (int) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - for (i = first; i < last; i++) - vec[i] = (bigint) ubuf(buf[m++]).i; + for (i = first; i < last; i++) vec[i] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); for (i = first; i < last; i++) - for (mm = 0; mm < cols; mm++) - array[i][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[i][mm] = (bigint) ubuf(buf[m++]).i; } } } } - if (bonus_flag) m += unpack_border_bonus(n,first,&buf[m]); + if (bonus_flag) m += unpack_border_bonus(n, first, &buf[m]); if (atom->nextra_border) for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); + m += modify->fix[atom->extra_border[iextra]]->unpack_border(n, first, &buf[m]); } /* ---------------------------------------------------------------------- @@ -1207,8 +1155,8 @@ void AtomVec::unpack_border_vel(int n, int first, double *buf) int AtomVec::pack_exchange(int i, double *buf) { - int mm,nn,datatype,cols,collength,ncols; - void *pdata,*plength; + int mm, nn, datatype, cols, collength, ncols; + void *pdata, *plength; int m = 1; buf[m++] = x[i][0]; @@ -1233,60 +1181,62 @@ int AtomVec::pack_exchange(int i, double *buf) buf[m++] = vec[i]; } else if (cols > 0) { double **array = *((double ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = array[i][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[i][mm]; } else { double **array = *((double ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = array[i][mm]; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = array[i][mm]; } - } if (datatype == Atom::INT) { + } + if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); buf[m++] = ubuf(vec[i]).d; } else if (cols > 0) { int **array = *((int ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } else { int **array = *((int ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = ubuf(array[i][mm]).d; } - } if (datatype == Atom::BIGINT) { + } + if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); buf[m++] = ubuf(vec[i]).d; } else if (cols > 0) { bigint **array = *((bigint ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } else { bigint **array = *((bigint ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = ubuf(array[i][mm]).d; } } } } - if (bonus_flag) m += pack_exchange_bonus(i,&buf[m]); + if (bonus_flag) m += pack_exchange_bonus(i, &buf[m]); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); + m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i, &buf[m]); buf[0] = m; return m; @@ -1296,8 +1246,8 @@ int AtomVec::pack_exchange(int i, double *buf) int AtomVec::unpack_exchange(double *buf) { - int mm,nn,datatype,cols,collength,ncols; - void *pdata,*plength; + int mm, nn, datatype, cols, collength, ncols; + void *pdata, *plength; int nlocal = atom->nlocal; if (nlocal == nmax) grow(0); @@ -1325,16 +1275,16 @@ int AtomVec::unpack_exchange(double *buf) vec[nlocal] = buf[m++]; } else if (cols > 0) { double **array = *((double ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = buf[m++]; } else { double **array = *((double ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = buf[m++]; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1342,16 +1292,16 @@ int AtomVec::unpack_exchange(double *buf) vec[nlocal] = (int) ubuf(buf[m++]).i; } else if (cols > 0) { int **array = *((int ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = (int) ubuf(buf[m++]).i; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1359,27 +1309,26 @@ int AtomVec::unpack_exchange(double *buf) vec[nlocal] = (bigint) ubuf(buf[m++]).i; } else if (cols > 0) { bigint **array = *((bigint ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); collength = mexchange.collength[nn]; plength = mexchange.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; } } } } - if (bonus_flag) m += unpack_exchange_bonus(nlocal,&buf[m]); + if (bonus_flag) m += unpack_exchange_bonus(nlocal, &buf[m]); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); + m += modify->fix[atom->extra_grow[iextra]]->unpack_exchange(nlocal, &buf[m]); atom->nlocal++; return m; @@ -1392,7 +1341,7 @@ int AtomVec::unpack_exchange(double *buf) int AtomVec::size_restart() { - int i,nn,cols,collength,ncols; + int i, nn, cols, collength, ncols; void *plength; // NOTE: need to worry about overflow of returned int N @@ -1406,14 +1355,18 @@ int AtomVec::size_restart() if (nrestart) { for (nn = 0; nn < nrestart; nn++) { cols = mrestart.cols[nn]; - if (cols == 0) n += nlocal; - else if (cols > 0) n += cols*nlocal; + if (cols == 0) + n += nlocal; + else if (cols > 0) + n += cols * nlocal; else { collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; for (i = 0; i < nlocal; i++) { - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; n += ncols; } } @@ -1424,8 +1377,7 @@ int AtomVec::size_restart() if (atom->nextra_restart) for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); + for (i = 0; i < nlocal; i++) n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); return n; } @@ -1438,8 +1390,8 @@ int AtomVec::size_restart() int AtomVec::pack_restart(int i, double *buf) { - int mm,nn,datatype,cols,collength,ncols; - void *pdata,*plength; + int mm, nn, datatype, cols, collength, ncols; + void *pdata, *plength; // if needed, change values before packing @@ -1467,16 +1419,16 @@ int AtomVec::pack_restart(int i, double *buf) buf[m++] = vec[i]; } else if (cols > 0) { double **array = *((double ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = array[i][mm]; + for (mm = 0; mm < cols; mm++) buf[m++] = array[i][mm]; } else { double **array = *((double ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = array[i][mm]; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = array[i][mm]; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1484,16 +1436,16 @@ int AtomVec::pack_restart(int i, double *buf) buf[m++] = ubuf(vec[i]).d; } else if (cols > 0) { int **array = *((int ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } else { int **array = *((int ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = ubuf(array[i][mm]).d; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1501,21 +1453,21 @@ int AtomVec::pack_restart(int i, double *buf) buf[m++] = ubuf(vec[i]).d; } else if (cols > 0) { bigint **array = *((bigint ***) pdata); - for (mm = 0; mm < cols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + for (mm = 0; mm < cols; mm++) buf[m++] = ubuf(array[i][mm]).d; } else { bigint **array = *((bigint ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[i][collength-1]; - else ncols = (*((int **) plength))[i]; - for (mm = 0; mm < ncols; mm++) - buf[m++] = ubuf(array[i][mm]).d; + if (collength) + ncols = (*((int ***) plength))[i][collength - 1]; + else + ncols = (*((int **) plength))[i]; + for (mm = 0; mm < ncols; mm++) buf[m++] = ubuf(array[i][mm]).d; } } } - if (bonus_flag) m += pack_restart_bonus(i,&buf[m]); + if (bonus_flag) m += pack_restart_bonus(i, &buf[m]); // if needed, restore values after packing @@ -1524,7 +1476,7 @@ int AtomVec::pack_restart(int i, double *buf) // invoke fixes which store peratom restart info for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); + m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i, &buf[m]); buf[0] = m; return m; @@ -1536,14 +1488,13 @@ int AtomVec::pack_restart(int i, double *buf) int AtomVec::unpack_restart(double *buf) { - int mm,nn,datatype,cols,collength,ncols; - void *pdata,*plength; + int mm, nn, datatype, cols, collength, ncols; + void *pdata, *plength; int nlocal = atom->nlocal; if (nlocal == nmax) { grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); + if (atom->nextra_store) memory->grow(atom->extra, nmax, atom->nextra_store, "atom:extra"); } int m = 1; @@ -1568,16 +1519,16 @@ int AtomVec::unpack_restart(double *buf) vec[nlocal] = buf[m++]; } else if (cols > 0) { double **array = *((double ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = buf[m++]; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = buf[m++]; } else { double **array = *((double ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = buf[m++]; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = buf[m++]; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1585,16 +1536,16 @@ int AtomVec::unpack_restart(double *buf) vec[nlocal] = (int) ubuf(buf[m++]).i; } else if (cols > 0) { int **array = *((int ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = (int) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = (int) ubuf(buf[m++]).i; } else { int **array = *((int ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = (int) ubuf(buf[m++]).i; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = (int) ubuf(buf[m++]).i; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1602,21 +1553,21 @@ int AtomVec::unpack_restart(double *buf) vec[nlocal] = (bigint) ubuf(buf[m++]).i; } else if (cols > 0) { bigint **array = *((bigint ***) pdata); - for (mm = 0; mm < cols; mm++) - array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; + for (mm = 0; mm < cols; mm++) array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; } else { bigint **array = *((bigint ***) pdata); collength = mrestart.collength[nn]; plength = mrestart.plength[nn]; - if (collength) ncols = (*((int ***) plength))[nlocal][collength-1]; - else ncols = (*((int **) plength))[nlocal]; - for (mm = 0; mm < ncols; mm++) - array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; + if (collength) + ncols = (*((int ***) plength))[nlocal][collength - 1]; + else + ncols = (*((int **) plength))[nlocal]; + for (mm = 0; mm < ncols; mm++) array[nlocal][mm] = (bigint) ubuf(buf[m++]).i; } } } - if (bonus_flag) m += unpack_restart_bonus(nlocal,&buf[m]); + if (bonus_flag) m += unpack_restart_bonus(nlocal, &buf[m]); // if needed, initialize other peratom values @@ -1626,7 +1577,7 @@ int AtomVec::unpack_restart(double *buf) double **extra = atom->extra; if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; + int size = static_cast(buf[0]) - m; for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; } @@ -1641,7 +1592,7 @@ int AtomVec::unpack_restart(double *buf) void AtomVec::create_atom(int itype, double *coord) { - int m,n,datatype,cols; + int m, n, datatype, cols; void *pdata; int nlocal = atom->nlocal; @@ -1653,8 +1604,7 @@ void AtomVec::create_atom(int itype, double *coord) x[nlocal][1] = coord[1]; x[nlocal][2] = coord[2]; mask[nlocal] = 1; - image[nlocal] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; + image[nlocal] = ((imageint) IMGMAX << IMG2BITS) | ((imageint) IMGMAX << IMGBITS) | IMGMAX; v[nlocal][0] = 0.0; v[nlocal][1] = 0.0; v[nlocal][2] = 0.0; @@ -1671,8 +1621,7 @@ void AtomVec::create_atom(int itype, double *coord) vec[nlocal] = 0.0; } else { double **array = *((double ***) pdata); - for (m = 0; m < cols; m++) - array[nlocal][m] = 0.0; + for (m = 0; m < cols; m++) array[nlocal][m] = 0.0; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1680,8 +1629,7 @@ void AtomVec::create_atom(int itype, double *coord) vec[nlocal] = 0; } else { int **array = *((int ***) pdata); - for (m = 0; m < cols; m++) - array[nlocal][m] = 0; + for (m = 0; m < cols; m++) array[nlocal][m] = 0; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1689,8 +1637,7 @@ void AtomVec::create_atom(int itype, double *coord) vec[nlocal] = 0; } else { bigint **array = *((bigint ***) pdata); - for (m = 0; m < cols; m++) - array[nlocal][m] = 0; + for (m = 0; m < cols; m++) array[nlocal][m] = 0; } } } @@ -1709,7 +1656,7 @@ void AtomVec::create_atom(int itype, double *coord) void AtomVec::data_atom(double *coord, imageint imagetmp, const std::vector &values) { - int m,n,datatype,cols; + int m, n, datatype, cols; void *pdata; int nlocal = atom->nlocal; @@ -1732,43 +1679,42 @@ void AtomVec::data_atom(double *coord, imageint imagetmp, const std::vectorx) { // x was already set by coord arg + if (array == atom->x) { // x was already set by coord arg ivalue += cols; continue; } for (m = 0; m < cols; m++) - array[nlocal][m] = utils::numeric(FLERR,values[ivalue++],true,lmp); + array[nlocal][m] = utils::numeric(FLERR, values[ivalue++], true, lmp); } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - vec[nlocal] = utils::inumeric(FLERR,values[ivalue++],true,lmp); + vec[nlocal] = utils::inumeric(FLERR, values[ivalue++], true, lmp); } else { int **array = *((int ***) pdata); for (m = 0; m < cols; m++) - array[nlocal][m] = utils::inumeric(FLERR,values[ivalue++],true,lmp); + array[nlocal][m] = utils::inumeric(FLERR, values[ivalue++], true, lmp); } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - vec[nlocal] = utils::bnumeric(FLERR,values[ivalue++],true,lmp); + vec[nlocal] = utils::bnumeric(FLERR, values[ivalue++], true, lmp); } else { bigint **array = *((bigint ***) pdata); for (m = 0; m < cols; m++) - array[nlocal][m] = utils::bnumeric(FLERR,values[ivalue++],true,lmp); + array[nlocal][m] = utils::bnumeric(FLERR, values[ivalue++], true, lmp); } } } // error checks applicable to all styles - if (tag[nlocal] <= 0) - error->one(FLERR,"Invalid atom ID in Atoms section of data file"); + if (tag[nlocal] <= 0) error->one(FLERR, "Invalid atom ID in Atoms section of data file"); if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); + error->one(FLERR, "Invalid atom type in Atoms section of data file"); // if needed, modify unpacked values or initialize other peratom values @@ -1783,7 +1729,7 @@ void AtomVec::data_atom(double *coord, imageint imagetmp, const std::vectornlocal; @@ -1805,8 +1751,7 @@ void AtomVec::pack_data(double **buf) buf[i][j++] = vec[i]; } else { double **array = *((double ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = array[i][m]; + for (m = 0; m < cols; m++) buf[i][j++] = array[i][m]; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1814,8 +1759,7 @@ void AtomVec::pack_data(double **buf) buf[i][j++] = ubuf(vec[i]).d; } else { int **array = *((int ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = ubuf(array[i][m]).d; + for (m = 0; m < cols; m++) buf[i][j++] = ubuf(array[i][m]).d; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1823,8 +1767,7 @@ void AtomVec::pack_data(double **buf) buf[i][j++] = ubuf(vec[i]).d; } else { bigint **array = *((bigint ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = ubuf(array[i][m]).d; + for (m = 0; m < cols; m++) buf[i][j++] = ubuf(array[i][m]).d; } } } @@ -1846,10 +1789,10 @@ void AtomVec::pack_data(double **buf) void AtomVec::write_data(FILE *fp, int n, double **buf) { - int i,j,m,nn,datatype,cols; + int i, j, m, nn, datatype, cols; for (i = 0; i < n; i++) { - fmt::print(fp,"{}",ubuf(buf[i][0]).i); + fmt::print(fp, "{}", ubuf(buf[i][0]).i); j = 1; for (nn = 1; nn < ndata_atom; nn++) { @@ -1857,32 +1800,26 @@ void AtomVec::write_data(FILE *fp, int n, double **buf) cols = mdata_atom.cols[nn]; if (datatype == Atom::DOUBLE) { if (cols == 0) { - fmt::print(fp," {}",buf[i][j++]); + fmt::print(fp, " {:.16}", buf[i][j++]); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",buf[i][j++]); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", buf[i][j++]); } } else if (datatype == Atom::INT) { if (cols == 0) { - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } } else if (datatype == Atom::BIGINT) { if (cols == 0) { - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } } } - fmt::print(fp," {} {} {}\n", - (int) ubuf(buf[i][j]).i, - (int) ubuf(buf[i][j+1]).i, - (int) ubuf(buf[i][j+2]).i); + fmt::print(fp, " {} {} {}\n", ubuf(buf[i][j]).i, ubuf(buf[i][j + 1]).i, ubuf(buf[i][j + 2]).i); } } @@ -1892,14 +1829,14 @@ void AtomVec::write_data(FILE *fp, int n, double **buf) void AtomVec::data_vel(int ilocal, const std::vector &values) { - int m,n,datatype,cols; + int m, n, datatype, cols; void *pdata; double **v = atom->v; int ivalue = 1; - v[ilocal][0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - v[ilocal][1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - v[ilocal][2] = utils::numeric(FLERR,values[ivalue++],true,lmp); + v[ilocal][0] = utils::numeric(FLERR, values[ivalue++], true, lmp); + v[ilocal][1] = utils::numeric(FLERR, values[ivalue++], true, lmp); + v[ilocal][2] = utils::numeric(FLERR, values[ivalue++], true, lmp); if (ndata_vel > 2) { for (n = 2; n < ndata_vel; n++) { @@ -1909,29 +1846,29 @@ void AtomVec::data_vel(int ilocal, const std::vector &values) if (datatype == Atom::DOUBLE) { if (cols == 0) { double *vec = *((double **) pdata); - vec[ilocal] = utils::numeric(FLERR,values[ivalue++],true,lmp); + vec[ilocal] = utils::numeric(FLERR, values[ivalue++], true, lmp); } else { double **array = *((double ***) pdata); for (m = 0; m < cols; m++) - array[ilocal][m] = utils::numeric(FLERR,values[ivalue++],true,lmp); + array[ilocal][m] = utils::numeric(FLERR, values[ivalue++], true, lmp); } } else if (datatype == Atom::INT) { if (cols == 0) { int *vec = *((int **) pdata); - vec[ilocal] = utils::inumeric(FLERR,values[ivalue++],true,lmp); + vec[ilocal] = utils::inumeric(FLERR, values[ivalue++], true, lmp); } else { int **array = *((int ***) pdata); for (m = 0; m < cols; m++) - array[ilocal][m] = utils::inumeric(FLERR,values[ivalue++],true,lmp); + array[ilocal][m] = utils::inumeric(FLERR, values[ivalue++], true, lmp); } } else if (datatype == Atom::BIGINT) { if (cols == 0) { bigint *vec = *((bigint **) pdata); - vec[ilocal] = utils::bnumeric(FLERR,values[ivalue++],true,lmp); + vec[ilocal] = utils::bnumeric(FLERR, values[ivalue++], true, lmp); } else { bigint **array = *((bigint ***) pdata); for (m = 0; m < cols; m++) - array[ilocal][m] = utils::bnumeric(FLERR,values[ivalue++],true,lmp); + array[ilocal][m] = utils::bnumeric(FLERR, values[ivalue++], true, lmp); } } } @@ -1944,7 +1881,7 @@ void AtomVec::data_vel(int ilocal, const std::vector &values) void AtomVec::pack_vel(double **buf) { - int i,j,m,n,datatype,cols; + int i, j, m, n, datatype, cols; void *pdata; int nlocal = atom->nlocal; @@ -1961,8 +1898,7 @@ void AtomVec::pack_vel(double **buf) buf[i][j++] = vec[i]; } else { double **array = *((double ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = array[i][m]; + for (m = 0; m < cols; m++) buf[i][j++] = array[i][m]; } } else if (datatype == Atom::INT) { if (cols == 0) { @@ -1970,8 +1906,7 @@ void AtomVec::pack_vel(double **buf) buf[i][j++] = ubuf(vec[i]).d; } else { int **array = *((int ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = ubuf(array[i][m]).d; + for (m = 0; m < cols; m++) buf[i][j++] = ubuf(array[i][m]).d; } } else if (datatype == Atom::BIGINT) { if (cols == 0) { @@ -1979,8 +1914,7 @@ void AtomVec::pack_vel(double **buf) buf[i][j++] = ubuf(vec[i]).d; } else { bigint **array = *((bigint ***) pdata); - for (m = 0; m < cols; m++) - buf[i][j++] = ubuf(array[i][m]).d; + for (m = 0; m < cols; m++) buf[i][j++] = ubuf(array[i][m]).d; } } } @@ -1994,10 +1928,10 @@ void AtomVec::pack_vel(double **buf) void AtomVec::write_vel(FILE *fp, int n, double **buf) { - int i,j,m,nn,datatype,cols; + int i, j, m, nn, datatype, cols; for (i = 0; i < n; i++) { - fmt::print(fp,"{}",ubuf(buf[i][0]).i); + fmt::print(fp, "{}", ubuf(buf[i][0]).i); j = 1; for (nn = 1; nn < ndata_vel; nn++) { @@ -2005,28 +1939,25 @@ void AtomVec::write_vel(FILE *fp, int n, double **buf) cols = mdata_vel.cols[nn]; if (datatype == Atom::DOUBLE) { if (cols == 0) { - fmt::print(fp," {}",buf[i][j++]); + fmt::print(fp, " {}", buf[i][j++]); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",buf[i][j++]); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", buf[i][j++]); } } else if (datatype == Atom::INT) { if (cols == 0) { - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } } else if (datatype == Atom::BIGINT) { if (cols == 0) { - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } else { - for (m = 0; m < cols; m++) - fmt::print(fp," {}",ubuf(buf[i][j++]).i); + for (m = 0; m < cols; m++) fmt::print(fp, " {}", ubuf(buf[i][j++]).i); } } } - fputs("\n",fp); + fputs("\n", fp); } } @@ -2046,14 +1977,14 @@ int AtomVec::pack_bond(tagint **buf) int nlocal = atom->nlocal; int newton_bond = force->newton_bond; - int i,j; + int i, j; int m = 0; if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_bond[i]; j++) { if (bond_type[i][j] == 0) continue; if (buf) { - buf[m][0] = MAX(bond_type[i][j],-bond_type[i][j]); + buf[m][0] = MAX(bond_type[i][j], -bond_type[i][j]); buf[m][1] = tag[i]; buf[m][2] = bond_atom[i][j]; } @@ -2065,7 +1996,7 @@ int AtomVec::pack_bond(tagint **buf) if (tag[i] < bond_atom[i][j]) { if (bond_type[i][j] == 0) continue; if (buf) { - buf[m][0] = MAX(bond_type[i][j],-bond_type[i][j]); + buf[m][0] = MAX(bond_type[i][j], -bond_type[i][j]); buf[m][1] = tag[i]; buf[m][2] = bond_atom[i][j]; } @@ -2083,7 +2014,7 @@ int AtomVec::pack_bond(tagint **buf) void AtomVec::write_bond(FILE *fp, int n, tagint **buf, int index) { for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {} {}\n",index,buf[i][0],buf[i][1],buf[i][2]); + fmt::print(fp, "{} {} {} {}\n", index, buf[i][0], buf[i][1], buf[i][2]); index++; } } @@ -2106,14 +2037,14 @@ int AtomVec::pack_angle(tagint **buf) int nlocal = atom->nlocal; int newton_bond = force->newton_bond; - int i,j; + int i, j; int m = 0; if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_angle[i]; j++) { if (angle_type[i][j] == 0) continue; if (buf) { - buf[m][0] = MAX(angle_type[i][j],-angle_type[i][j]); + buf[m][0] = MAX(angle_type[i][j], -angle_type[i][j]); buf[m][1] = angle_atom1[i][j]; buf[m][2] = angle_atom2[i][j]; buf[m][3] = angle_atom3[i][j]; @@ -2126,7 +2057,7 @@ int AtomVec::pack_angle(tagint **buf) if (tag[i] == angle_atom2[i][j]) { if (angle_type[i][j] == 0) continue; if (buf) { - buf[m][0] = MAX(angle_type[i][j],-angle_type[i][j]); + buf[m][0] = MAX(angle_type[i][j], -angle_type[i][j]); buf[m][1] = angle_atom1[i][j]; buf[m][2] = angle_atom2[i][j]; buf[m][3] = angle_atom3[i][j]; @@ -2145,8 +2076,7 @@ int AtomVec::pack_angle(tagint **buf) void AtomVec::write_angle(FILE *fp, int n, tagint **buf, int index) { for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {} {} {}\n",index, - buf[i][0],buf[i][1],buf[i][2],buf[i][3]); + fmt::print(fp, "{} {} {} {} {}\n", index, buf[i][0], buf[i][1], buf[i][2], buf[i][3]); index++; } } @@ -2167,13 +2097,13 @@ int AtomVec::pack_dihedral(tagint **buf) int nlocal = atom->nlocal; int newton_bond = force->newton_bond; - int i,j; + int i, j; int m = 0; if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_dihedral[i]; j++) { if (buf) { - buf[m][0] = MAX(dihedral_type[i][j],-dihedral_type[i][j]); + buf[m][0] = MAX(dihedral_type[i][j], -dihedral_type[i][j]); buf[m][1] = dihedral_atom1[i][j]; buf[m][2] = dihedral_atom2[i][j]; buf[m][3] = dihedral_atom3[i][j]; @@ -2186,7 +2116,7 @@ int AtomVec::pack_dihedral(tagint **buf) for (j = 0; j < num_dihedral[i]; j++) if (tag[i] == dihedral_atom2[i][j]) { if (buf) { - buf[m][0] = MAX(dihedral_type[i][j],-dihedral_type[i][j]); + buf[m][0] = MAX(dihedral_type[i][j], -dihedral_type[i][j]); buf[m][1] = dihedral_atom1[i][j]; buf[m][2] = dihedral_atom2[i][j]; buf[m][3] = dihedral_atom3[i][j]; @@ -2206,8 +2136,8 @@ int AtomVec::pack_dihedral(tagint **buf) void AtomVec::write_dihedral(FILE *fp, int n, tagint **buf, int index) { for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {} {} {} {}\n",index,buf[i][0], - buf[i][1],buf[i][2],buf[i][3],buf[i][4]); + fmt::print(fp, "{} {} {} {} {} {}\n", index, buf[i][0], buf[i][1], buf[i][2], buf[i][3], + buf[i][4]); index++; } } @@ -2228,13 +2158,13 @@ int AtomVec::pack_improper(tagint **buf) int nlocal = atom->nlocal; int newton_bond = force->newton_bond; - int i,j; + int i, j; int m = 0; if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_improper[i]; j++) { if (buf) { - buf[m][0] = MAX(improper_type[i][j],-improper_type[i][j]); + buf[m][0] = MAX(improper_type[i][j], -improper_type[i][j]); buf[m][1] = improper_atom1[i][j]; buf[m][2] = improper_atom2[i][j]; buf[m][3] = improper_atom3[i][j]; @@ -2247,7 +2177,7 @@ int AtomVec::pack_improper(tagint **buf) for (j = 0; j < num_improper[i]; j++) if (tag[i] == improper_atom2[i][j]) { if (buf) { - buf[m][0] = MAX(improper_type[i][j],-improper_type[i][j]); + buf[m][0] = MAX(improper_type[i][j], -improper_type[i][j]); buf[m][1] = improper_atom1[i][j]; buf[m][2] = improper_atom2[i][j]; buf[m][3] = improper_atom3[i][j]; @@ -2267,8 +2197,8 @@ int AtomVec::pack_improper(tagint **buf) void AtomVec::write_improper(FILE *fp, int n, tagint **buf, int index) { for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {} {} {} {}\n",index,buf[i][0], - buf[i][1],buf[i][2],buf[i][3],buf[i][4]); + fmt::print(fp, "{} {} {} {} {} {}\n", index, buf[i][0], buf[i][1], buf[i][2], buf[i][3], + buf[i][4]); index++; } } @@ -2279,18 +2209,18 @@ void AtomVec::write_improper(FILE *fp, int n, tagint **buf, int index) double AtomVec::memory_usage() { - int datatype,cols,maxcols; + int datatype, cols, maxcols; void *pdata; double bytes = 0; - bytes += memory->usage(tag,nmax); - bytes += memory->usage(type,nmax); - bytes += memory->usage(mask,nmax); - bytes += memory->usage(image,nmax); - bytes += memory->usage(x,nmax,3); - bytes += memory->usage(v,nmax,3); - bytes += memory->usage(f,nmax*comm->nthreads,3); + bytes += memory->usage(tag, nmax); + bytes += memory->usage(type, nmax); + bytes += memory->usage(mask, nmax); + bytes += memory->usage(image, nmax); + bytes += memory->usage(x, nmax, 3); + bytes += memory->usage(v, nmax, 3); + bytes += memory->usage(f, nmax * comm->nthreads, 3); for (int i = 0; i < ngrow; i++) { pdata = mgrow.pdata[i]; @@ -2299,30 +2229,30 @@ double AtomVec::memory_usage() const int nthreads = threads[i] ? comm->nthreads : 1; if (datatype == Atom::DOUBLE) { if (cols == 0) { - bytes += memory->usage(*((double **) pdata),nmax*nthreads); + bytes += memory->usage(*((double **) pdata), nmax * nthreads); } else if (cols > 0) { - bytes += memory->usage(*((double ***) pdata),nmax*nthreads,cols); + bytes += memory->usage(*((double ***) pdata), nmax * nthreads, cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((double ***) pdata),nmax*nthreads,maxcols); + bytes += memory->usage(*((double ***) pdata), nmax * nthreads, maxcols); } } else if (datatype == Atom::INT) { if (cols == 0) { - bytes += memory->usage(*((int **) pdata),nmax*nthreads); + bytes += memory->usage(*((int **) pdata), nmax * nthreads); } else if (cols > 0) { - bytes += memory->usage(*((int ***) pdata),nmax*nthreads,cols); + bytes += memory->usage(*((int ***) pdata), nmax * nthreads, cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((int ***) pdata),nmax*nthreads,maxcols); + bytes += memory->usage(*((int ***) pdata), nmax * nthreads, maxcols); } } else if (datatype == Atom::BIGINT) { if (cols == 0) { - bytes += memory->usage(*((bigint **) pdata),nmax*nthreads); + bytes += memory->usage(*((bigint **) pdata), nmax * nthreads); } else if (cols > 0) { - bytes += memory->usage(*((bigint ***) pdata),nmax*nthreads,cols); + bytes += memory->usage(*((bigint ***) pdata), nmax * nthreads, cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((bigint ***) pdata),nmax*nthreads,maxcols); + bytes += memory->usage(*((bigint ***) pdata), nmax * nthreads, maxcols); } } } @@ -2342,52 +2272,53 @@ double AtomVec::memory_usage() void AtomVec::setup_fields() { - int n,cols; + int n, cols; - if (!utils::strmatch(fields_data_atom,"^id ")) - error->all(FLERR,"Atom style fields_data_atom must have id as first field"); - if (!utils::strmatch(fields_data_vel,"^id v")) - error->all(FLERR,"Atom style fields_data_vel must have " - "'id v' as first fields"); + if ((fields_data_atom.size() < 1) || (fields_data_atom[0] != "id")) + error->all(FLERR, "Atom style fields_data_atom must have 'id' as first field"); + if ((fields_data_vel.size() < 2) || (fields_data_vel[0] != "id") || (fields_data_vel[1] != "v")) + error->all(FLERR, "Atom style fields_data_vel must have 'id' and 'v' as first two fields"); // process field strings - // return # of fields and matching index into atom->peratom (in Method struct) + // return # of fields and matching index into atom.peratom (in Method struct) - ngrow = process_fields(fields_grow,default_grow,&mgrow); - ncopy = process_fields(fields_copy,default_copy,&mcopy); - ncomm = process_fields(fields_comm,default_comm,&mcomm); - ncomm_vel = process_fields(fields_comm_vel,default_comm_vel,&mcomm_vel); - nreverse = process_fields(fields_reverse,default_reverse,&mreverse); - nborder = process_fields(fields_border,default_border,&mborder); - nborder_vel = process_fields(fields_border_vel,default_border_vel,&mborder_vel); - nexchange = process_fields(fields_exchange,default_exchange,&mexchange); - nrestart = process_fields(fields_restart,default_restart,&mrestart); - ncreate = process_fields(fields_create,default_create,&mcreate); - ndata_atom = process_fields(fields_data_atom,default_data_atom,&mdata_atom); - ndata_vel = process_fields(fields_data_vel,default_data_vel,&mdata_vel); + ngrow = process_fields(fields_grow, default_grow, &mgrow); + ncopy = process_fields(fields_copy, default_copy, &mcopy); + ncomm = process_fields(fields_comm, default_comm, &mcomm); + ncomm_vel = process_fields(fields_comm_vel, default_comm_vel, &mcomm_vel); + nreverse = process_fields(fields_reverse, default_reverse, &mreverse); + nborder = process_fields(fields_border, default_border, &mborder); + nborder_vel = process_fields(fields_border_vel, default_border_vel, &mborder_vel); + nexchange = process_fields(fields_exchange, default_exchange, &mexchange); + nrestart = process_fields(fields_restart, default_restart, &mrestart); + ncreate = process_fields(fields_create, default_create, &mcreate); + ndata_atom = process_fields(fields_data_atom, default_data_atom, &mdata_atom); + ndata_vel = process_fields(fields_data_vel, default_data_vel, &mdata_vel); // populate field-based data struct for each method to use - init_method(ngrow,&mgrow); - init_method(ncopy,&mcopy); - init_method(ncomm,&mcomm); - init_method(ncomm_vel,&mcomm_vel); - init_method(nreverse,&mreverse); - init_method(nborder,&mborder); - init_method(nborder_vel,&mborder_vel); - init_method(nexchange,&mexchange); - init_method(nrestart,&mrestart); - init_method(ncreate,&mcreate); - init_method(ndata_atom,&mdata_atom); - init_method(ndata_vel,&mdata_vel); + init_method(ngrow, &mgrow); + init_method(ncopy, &mcopy); + init_method(ncomm, &mcomm); + init_method(ncomm_vel, &mcomm_vel); + init_method(nreverse, &mreverse); + init_method(nborder, &mborder); + init_method(nborder_vel, &mborder_vel); + init_method(nexchange, &mexchange); + init_method(nrestart, &mrestart); + init_method(ncreate, &mcreate); + init_method(ndata_atom, &mdata_atom); + init_method(ndata_vel, &mdata_vel); // create threads data struct for grow and memory_usage to use - if (ngrow) threads = new bool[ngrow]; - else threads = nullptr; + if (ngrow) + threads = new bool[ngrow]; + else + threads = nullptr; for (int i = 0; i < ngrow; i++) { - Atom::PerAtom *field = &atom->peratom[mgrow.index[i]]; - threads[i] = field->threadflag == 1; + const auto &field = atom->peratom[mgrow.index[i]]; + threads[i] = field.threadflag == 1; } // set style-specific sizes @@ -2396,53 +2327,66 @@ void AtomVec::setup_fields() if (ncomm) comm_x_only = 0; if (bonus_flag && size_forward_bonus) comm_x_only = 0; - if (nreverse == 0) comm_f_only = 1; - else comm_f_only = 0; + if (nreverse == 0) + comm_f_only = 1; + else + comm_f_only = 0; size_forward = 3; for (n = 0; n < ncomm; n++) { cols = mcomm.cols[n]; - if (cols == 0) size_forward++; - else size_forward += cols; + if (cols == 0) + size_forward++; + else + size_forward += cols; } if (bonus_flag) size_forward += size_forward_bonus; size_reverse = 3; for (n = 0; n < nreverse; n++) { cols = mreverse.cols[n]; - if (cols == 0) size_reverse++; - else size_reverse += cols; + if (cols == 0) + size_reverse++; + else + size_reverse += cols; } size_border = 6; for (n = 0; n < nborder; n++) { cols = mborder.cols[n]; - if (cols == 0) size_border++; - else size_border += cols; + if (cols == 0) + size_border++; + else + size_border += cols; } if (bonus_flag) size_border += size_border_bonus; size_velocity = 3; for (n = 0; n < ncomm_vel; n++) { cols = mcomm_vel.cols[n]; - if (cols == 0) size_velocity++; - else size_velocity += cols; + if (cols == 0) + size_velocity++; + else + size_velocity += cols; } size_data_atom = 0; for (n = 0; n < ndata_atom; n++) { cols = mdata_atom.cols[n]; - if (strcmp(atom->peratom[mdata_atom.index[n]].name,"x") == 0) - xcol_data = size_data_atom + 1; - if (cols == 0) size_data_atom++; - else size_data_atom += cols; + if (atom->peratom[mdata_atom.index[n]].name == "x") xcol_data = size_data_atom + 1; + if (cols == 0) + size_data_atom++; + else + size_data_atom += cols; } size_data_vel = 0; for (n = 0; n < ndata_vel; n++) { cols = mdata_vel.cols[n]; - if (cols == 0) size_data_vel++; - else size_data_vel += cols; + if (cols == 0) + size_data_vel++; + else + size_data_vel += cols; } } @@ -2450,52 +2394,42 @@ void AtomVec::setup_fields() process a single field string ------------------------------------------------------------------------- */ -int AtomVec::process_fields(char *str, const char *default_str, Method *method) +int AtomVec::process_fields(const std::vector &words, + const std::vector &def_words, Method *method) { - if (str == nullptr) { - return 0; - } - - // tokenize words in both strings - std::vector words = Tokenizer(str, " ").as_vector(); - std::vector def_words = Tokenizer(default_str, " ").as_vector(); - int nfield = words.size(); - int ndef = def_words.size(); + int ndef = def_words.size(); // process fields one by one, add to index vector - Atom::PerAtom *peratom = atom->peratom; - int nperatom = atom->nperatom; + const auto &peratom = atom->peratom; + const int nperatom = peratom.size(); // allocate memory in method method->resize(nfield); - std::vector & index = method->index; + std::vector &index = method->index; int match; for (int i = 0; i < nfield; i++) { - const std::string & field = words[i]; + const std::string &field = words[i]; // find field in master Atom::peratom list for (match = 0; match < nperatom; match++) if (field == peratom[match].name) break; - if (match == nperatom) - error->all(FLERR,"Peratom field {} not recognized", field); + if (match == nperatom) error->all(FLERR, "Peratom field {} not recognized", field); index[i] = match; // error if field appears multiple times for (match = 0; match < i; match++) - if (index[i] == index[match]) - error->all(FLERR,"Peratom field {} is repeated", field); + if (index[i] == index[match]) error->all(FLERR, "Peratom field {} is repeated", field); // error if field is in default str for (match = 0; match < ndef; match++) - if (field == def_words[match]) - error->all(FLERR,"Peratom field {} is a default", field); + if (field == def_words[match]) error->all(FLERR, "Peratom field {} is a default", field); } return nfield; @@ -2508,14 +2442,14 @@ int AtomVec::process_fields(char *str, const char *default_str, Method *method) void AtomVec::init_method(int nfield, Method *method) { for (int i = 0; i < nfield; i++) { - Atom::PerAtom *field = &atom->peratom[method->index[i]]; - method->pdata[i] = (void *) field->address; - method->datatype[i] = field->datatype; - method->cols[i] = field->cols; + const auto &field = atom->peratom[method->index[i]]; + method->pdata[i] = (void *) field.address; + method->datatype[i] = field.datatype; + method->cols[i] = field.cols; if (method->cols[i] < 0) { - method->maxcols[i] = field->address_maxcols; - method->collength[i] = field->collength; - method->plength[i] = field->address_length; + method->maxcols[i] = field.address_maxcols; + method->collength[i] = field.collength; + method->plength[i] = field.address_length; } } } @@ -2524,7 +2458,8 @@ void AtomVec::init_method(int nfield, Method *method) Method class members ------------------------------------------------------------------------- */ -void AtomVec::Method::resize(int nfield) { +void AtomVec::Method::resize(int nfield) +{ pdata.resize(nfield); datatype.resize(nfield); cols.resize(nfield); diff --git a/src/atom_vec.h b/src/atom_vec.h index ad1c7f3315..1af160ccbd 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -59,11 +59,10 @@ class AtomVec : protected Pointers { // additional list of peratom fields operated on by different methods // set or created by child styles - char *fields_grow, *fields_copy; - char *fields_comm, *fields_comm_vel, *fields_reverse; - char *fields_border, *fields_border_vel; - char *fields_exchange, *fields_restart; - char *fields_create, *fields_data_atom, *fields_data_vel; + std::vector fields_grow, fields_copy, fields_comm, fields_comm_vel; + std::vector fields_reverse, fields_border, fields_border_vel; + std::vector fields_exchange, fields_restart, fields_create; + std::vector fields_data_atom, fields_data_vel; // methods @@ -152,7 +151,7 @@ class AtomVec : protected Pointers { virtual int pack_data_bonus(double *, int) { return 0; } virtual void write_data_bonus(FILE *, int, double *, int) {} - virtual int property_atom(char *) { return -1; } + virtual int property_atom(const std::string &) { return -1; } virtual void pack_property_atom(int, double *, int, int) {} virtual double memory_usage(); @@ -187,11 +186,10 @@ class AtomVec : protected Pointers { // standard list of peratom fields always operated on by different methods // common to all styles, so not listed in field strings - const char *default_grow, *default_copy; - const char *default_comm, *default_comm_vel, *default_reverse; - const char *default_border, *default_border_vel; - const char *default_exchange, *default_restart; - const char *default_create, *default_data_atom, *default_data_vel; + static const std::vector default_grow, default_copy, default_comm, default_comm_vel; + static const std::vector default_reverse, default_border, default_border_vel; + static const std::vector default_exchange, default_restart, default_create; + static const std::vector default_data_atom, default_data_vel; struct Method { std::vector pdata; @@ -223,7 +221,7 @@ class AtomVec : protected Pointers { void grow_nmax(); int grow_nmax_bonus(int); void setup_fields(); - int process_fields(char *, const char *, Method *); + int process_fields(const std::vector &, const std::vector &, Method *); void init_method(int, Method *); }; diff --git a/src/atom_vec_atomic.cpp b/src/atom_vec_atomic.cpp index 88584981f5..44fb7d2fee 100644 --- a/src/atom_vec_atomic.cpp +++ b/src/atom_vec_atomic.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -30,18 +29,8 @@ AtomVecAtomic::AtomVecAtomic(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) ""; - fields_copy = (char *) ""; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) ""; - fields_border_vel = (char *) ""; - fields_exchange = (char *) ""; - fields_restart = (char *) ""; - fields_create = (char *) ""; - fields_data_atom = (char *) "id type x"; - fields_data_vel = (char *) "id v"; + fields_data_atom = {"id", "type", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } diff --git a/src/atom_vec_body.cpp b/src/atom_vec_body.cpp index 8d62b6b7e7..f2eef1d207 100644 --- a/src/atom_vec_body.cpp +++ b/src/atom_vec_body.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,8 +22,6 @@ #include "modify.h" #include "my_pool_chunk.h" -#include - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -54,27 +51,29 @@ AtomVecBody::AtomVecBody(LAMMPS *lmp) : AtomVec(lmp) bptr = nullptr; - if (sizeof(double) == sizeof(int)) intdoubleratio = 1; - else if (sizeof(double) == 2*sizeof(int)) intdoubleratio = 2; - else error->all(FLERR,"Internal error in atom_style body"); + if (sizeof(double) == sizeof(int)) + intdoubleratio = 1; + else if (sizeof(double) == 2 * sizeof(int)) + intdoubleratio = 2; + else + error->all(FLERR, "Internal error in atom_style body"); // strings with peratom variables to include in each AtomVec method // strings cannot contain fields in corresponding AtomVec default strings // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "radius rmass angmom torque body"; - fields_copy = (char *) "radius rmass angmom"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "angmom"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "radius rmass"; - fields_border_vel = (char *) "radius rmass angmom"; - fields_exchange = (char *) "radius rmass angmom"; - fields_restart = (char *) "radius rmass angmom"; - fields_create = (char *) "radius rmass angmom body"; - fields_data_atom = (char *) "id type body rmass x"; - fields_data_vel = (char *) "id v angmom"; + fields_grow = {"radius", "rmass", "angmom", "torque", "body"}; + fields_copy = {"radius", "rmass", "angmom"}; + fields_comm_vel = {"angmom"}; + fields_reverse = {"torque"}; + fields_border = {"radius", "rmass"}; + fields_border_vel = {"radius", "rmass", "angmom"}; + fields_exchange = {"radius", "rmass", "angmom"}; + fields_restart = {"radius", "rmass", "angmom"}; + fields_create = {"radius", "rmass", "angmom", "body"}; + fields_data_atom = {"id", "type", "body", "rmass", "x"}; + fields_data_vel = {"id", "v", "angmom"}; } /* ---------------------------------------------------------------------- */ @@ -101,23 +100,25 @@ void AtomVecBody::process_args(int narg, char **arg) { // suppress unused parameter warning dependent on style_body.h - (void)(arg); + (void) (arg); - if (narg < 1) error->all(FLERR,"Invalid atom_style body command"); + if (narg < 1) error->all(FLERR, "Invalid atom_style body command"); - if (false) { // NOLINT + if (false) { // NOLINT bptr = nullptr; #define BODY_CLASS -#define BodyStyle(key,Class) \ - } else if (strcmp(arg[0],#key) == 0) { \ - bptr = new Class(lmp,narg,arg); -#include "style_body.h" // IWYU pragma: keep +#define BodyStyle(key, Class) \ + } \ + else if (strcmp(arg[0], #key) == 0) \ + { \ + bptr = new Class(lmp, narg, arg); +#include "style_body.h" // IWYU pragma: keep #undef BodyStyle #undef BODY_CLASS - } else error->all(FLERR,utils:: - check_packages_for_style("body",arg[0],lmp).c_str()); + } else + error->all(FLERR, utils::check_packages_for_style("body", arg[0], lmp).c_str()); bptr->avec = this; icp = bptr->icp; @@ -153,11 +154,9 @@ void AtomVecBody::grow_pointers() void AtomVecBody::grow_bonus() { nmax_bonus = grow_nmax_bonus(nmax_bonus); - if (nmax_bonus < 0) - error->one(FLERR,"Per-processor system is too big"); + if (nmax_bonus < 0) error->one(FLERR, "Per-processor system is too big"); - bonus = (Bonus *) memory->srealloc(bonus,nmax_bonus*sizeof(Bonus), - "atom:bonus"); + bonus = (Bonus *) memory->srealloc(bonus, nmax_bonus * sizeof(Bonus), "atom:bonus"); } /* ---------------------------------------------------------------------- @@ -173,7 +172,7 @@ void AtomVecBody::copy_bonus(int i, int j, int delflag) int k = body[j]; icp->put(bonus[k].iindex); dcp->put(bonus[k].dindex); - copy_bonus_all(nlocal_bonus-1,k); + copy_bonus_all(nlocal_bonus - 1, k); nlocal_bonus--; } @@ -192,7 +191,7 @@ void AtomVecBody::copy_bonus(int i, int j, int delflag) void AtomVecBody::copy_bonus_all(int i, int j) { body[bonus[i].ilocal] = j; - memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); + memcpy(&bonus[j], &bonus[i], sizeof(Bonus)); } /* ---------------------------------------------------------------------- @@ -218,7 +217,7 @@ void AtomVecBody::clear_bonus() int AtomVecBody::pack_comm_bonus(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; double *quat; m = 0; @@ -230,7 +229,7 @@ int AtomVecBody::pack_comm_bonus(int n, int *list, double *buf) buf[m++] = quat[1]; buf[m++] = quat[2]; buf[m++] = quat[3]; - m += bptr->pack_comm_body(&bonus[body[j]],&buf[m]); + m += bptr->pack_comm_body(&bonus[body[j]], &buf[m]); } } @@ -241,7 +240,7 @@ int AtomVecBody::pack_comm_bonus(int n, int *list, double *buf) void AtomVecBody::unpack_comm_bonus(int n, int first, double *buf) { - int i,m,last; + int i, m, last; double *quat; m = 0; @@ -253,7 +252,7 @@ void AtomVecBody::unpack_comm_bonus(int n, int first, double *buf) quat[1] = buf[m++]; quat[2] = buf[m++]; quat[3] = buf[m++]; - m += bptr->unpack_comm_body(&bonus[body[i]],&buf[m]); + m += bptr->unpack_comm_body(&bonus[body[i]], &buf[m]); } } } @@ -262,13 +261,14 @@ void AtomVecBody::unpack_comm_bonus(int n, int first, double *buf) int AtomVecBody::pack_border_bonus(int n, int *list, double *buf) { - int i,j,m; - double *quat,*inertia; + int i, j, m; + double *quat, *inertia; m = 0; for (i = 0; i < n; i++) { j = list[i]; - if (body[j] < 0) buf[m++] = ubuf(0).d; + if (body[j] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; quat = bonus[body[j]].quat; @@ -282,7 +282,7 @@ int AtomVecBody::pack_border_bonus(int n, int *list, double *buf) buf[m++] = inertia[2]; buf[m++] = ubuf(bonus[body[j]].ninteger).d; buf[m++] = ubuf(bonus[body[j]].ndouble).d; - m += bptr->pack_border_body(&bonus[body[j]],&buf[m]); + m += bptr->pack_border_body(&bonus[body[j]], &buf[m]); } } @@ -293,14 +293,15 @@ int AtomVecBody::pack_border_bonus(int n, int *list, double *buf) int AtomVecBody::unpack_border_bonus(int n, int first, double *buf) { - int i,j,m,last; - double *quat,*inertia; + int i, j, m, last; + double *quat, *inertia; m = 0; last = first + n; for (i = first; i < last; i++) { body[i] = (int) ubuf(buf[m++]).i; - if (body[i] == 0) body[i] = -1; + if (body[i] == 0) + body[i] = -1; else { j = nlocal_bonus + nghost_bonus; if (j == nmax_bonus) grow_bonus(); @@ -316,9 +317,9 @@ int AtomVecBody::unpack_border_bonus(int n, int first, double *buf) bonus[j].ninteger = (int) ubuf(buf[m++]).i; bonus[j].ndouble = (int) ubuf(buf[m++]).i; // corresponding put() calls are in clear_bonus() - bonus[j].ivalue = icp->get(bonus[j].ninteger,bonus[j].iindex); - bonus[j].dvalue = dcp->get(bonus[j].ndouble,bonus[j].dindex); - m += bptr->unpack_border_body(&bonus[j],&buf[m]); + bonus[j].ivalue = icp->get(bonus[j].ninteger, bonus[j].iindex); + bonus[j].dvalue = dcp->get(bonus[j].ndouble, bonus[j].dindex); + m += bptr->unpack_border_body(&bonus[j], &buf[m]); bonus[j].ilocal = i; body[i] = j; nghost_bonus++; @@ -337,7 +338,8 @@ int AtomVecBody::pack_exchange_bonus(int i, double *buf) { int m = 0; - if (body[i] < 0) buf[m++] = ubuf(0).d; + if (body[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = body[i]; @@ -352,10 +354,12 @@ int AtomVecBody::pack_exchange_bonus(int i, double *buf) buf[m++] = inertia[2]; buf[m++] = ubuf(bonus[j].ninteger).d; buf[m++] = ubuf(bonus[j].ndouble).d; - memcpy(&buf[m],bonus[j].ivalue,bonus[j].ninteger*sizeof(int)); - if (intdoubleratio == 1) m += bonus[j].ninteger; - else m += (bonus[j].ninteger+1)/2; - memcpy(&buf[m],bonus[j].dvalue,bonus[j].ndouble*sizeof(double)); + memcpy(&buf[m], bonus[j].ivalue, bonus[j].ninteger * sizeof(int)); + if (intdoubleratio == 1) + m += bonus[j].ninteger; + else + m += (bonus[j].ninteger + 1) / 2; + memcpy(&buf[m], bonus[j].dvalue, bonus[j].ndouble * sizeof(double)); m += bonus[j].ndouble; } @@ -369,7 +373,8 @@ int AtomVecBody::unpack_exchange_bonus(int ilocal, double *buf) int m = 0; body[ilocal] = (int) ubuf(buf[m++]).i; - if (body[ilocal] == 0) body[ilocal] = -1; + if (body[ilocal] == 0) + body[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *quat = bonus[nlocal_bonus].quat; @@ -384,16 +389,14 @@ int AtomVecBody::unpack_exchange_bonus(int ilocal, double *buf) bonus[nlocal_bonus].ninteger = (int) ubuf(buf[m++]).i; bonus[nlocal_bonus].ndouble = (int) ubuf(buf[m++]).i; // corresponding put() calls are in copy() - bonus[nlocal_bonus].ivalue = icp->get(bonus[nlocal_bonus].ninteger, - bonus[nlocal_bonus].iindex); - bonus[nlocal_bonus].dvalue = dcp->get(bonus[nlocal_bonus].ndouble, - bonus[nlocal_bonus].dindex); - memcpy(bonus[nlocal_bonus].ivalue,&buf[m], - bonus[nlocal_bonus].ninteger*sizeof(int)); - if (intdoubleratio == 1) m += bonus[nlocal_bonus].ninteger; - else m += (bonus[nlocal_bonus].ninteger+1)/2; - memcpy(bonus[nlocal_bonus].dvalue,&buf[m], - bonus[nlocal_bonus].ndouble*sizeof(double)); + bonus[nlocal_bonus].ivalue = icp->get(bonus[nlocal_bonus].ninteger, bonus[nlocal_bonus].iindex); + bonus[nlocal_bonus].dvalue = dcp->get(bonus[nlocal_bonus].ndouble, bonus[nlocal_bonus].dindex); + memcpy(bonus[nlocal_bonus].ivalue, &buf[m], bonus[nlocal_bonus].ninteger * sizeof(int)); + if (intdoubleratio == 1) + m += bonus[nlocal_bonus].ninteger; + else + m += (bonus[nlocal_bonus].ninteger + 1) / 2; + memcpy(bonus[nlocal_bonus].dvalue, &buf[m], bonus[nlocal_bonus].ndouble * sizeof(double)); m += bonus[nlocal_bonus].ndouble; bonus[nlocal_bonus].ilocal = ilocal; @@ -416,10 +419,13 @@ int AtomVecBody::size_restart_bonus() for (i = 0; i < nlocal; i++) { if (body[i] >= 0) { n += size_restart_bonus_one; - if (intdoubleratio == 1) n += bonus[body[i]].ninteger; - else n += (bonus[body[i]].ninteger+1)/2; + if (intdoubleratio == 1) + n += bonus[body[i]].ninteger; + else + n += (bonus[body[i]].ninteger + 1) / 2; n += bonus[body[i]].ndouble; - } else n++; + } else + n++; } return n; @@ -435,7 +441,8 @@ int AtomVecBody::pack_restart_bonus(int i, double *buf) { int m = 0; - if (body[i] < 0) buf[m++] = ubuf(0).d; + if (body[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = body[i]; @@ -450,10 +457,12 @@ int AtomVecBody::pack_restart_bonus(int i, double *buf) buf[m++] = inertia[2]; buf[m++] = ubuf(bonus[j].ninteger).d; buf[m++] = ubuf(bonus[j].ndouble).d; - memcpy(&buf[m],bonus[j].ivalue,bonus[j].ninteger*sizeof(int)); - if (intdoubleratio == 1) m += bonus[j].ninteger; - else m += (bonus[j].ninteger+1)/2; - memcpy(&buf[m],bonus[j].dvalue,bonus[j].ndouble*sizeof(double)); + memcpy(&buf[m], bonus[j].ivalue, bonus[j].ninteger * sizeof(int)); + if (intdoubleratio == 1) + m += bonus[j].ninteger; + else + m += (bonus[j].ninteger + 1) / 2; + memcpy(&buf[m], bonus[j].dvalue, bonus[j].ndouble * sizeof(double)); m += bonus[j].ndouble; } @@ -469,7 +478,8 @@ int AtomVecBody::unpack_restart_bonus(int ilocal, double *buf) int m = 0; body[ilocal] = (int) ubuf(buf[m++]).i; - if (body[ilocal] == 0) body[ilocal] = -1; + if (body[ilocal] == 0) + body[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *quat = bonus[nlocal_bonus].quat; @@ -483,16 +493,14 @@ int AtomVecBody::unpack_restart_bonus(int ilocal, double *buf) inertia[2] = buf[m++]; bonus[nlocal_bonus].ninteger = (int) ubuf(buf[m++]).i; bonus[nlocal_bonus].ndouble = (int) ubuf(buf[m++]).i; - bonus[nlocal_bonus].ivalue = icp->get(bonus[nlocal_bonus].ninteger, - bonus[nlocal_bonus].iindex); - bonus[nlocal_bonus].dvalue = dcp->get(bonus[nlocal_bonus].ndouble, - bonus[nlocal_bonus].dindex); - memcpy(bonus[nlocal_bonus].ivalue,&buf[m], - bonus[nlocal_bonus].ninteger*sizeof(int)); - if (intdoubleratio == 1) m += bonus[nlocal_bonus].ninteger; - else m += (bonus[nlocal_bonus].ninteger+1)/2; - memcpy(bonus[nlocal_bonus].dvalue,&buf[m], - bonus[nlocal_bonus].ndouble*sizeof(double)); + bonus[nlocal_bonus].ivalue = icp->get(bonus[nlocal_bonus].ninteger, bonus[nlocal_bonus].iindex); + bonus[nlocal_bonus].dvalue = dcp->get(bonus[nlocal_bonus].ndouble, bonus[nlocal_bonus].dindex); + memcpy(bonus[nlocal_bonus].ivalue, &buf[m], bonus[nlocal_bonus].ninteger * sizeof(int)); + if (intdoubleratio == 1) + m += bonus[nlocal_bonus].ninteger; + else + m += (bonus[nlocal_bonus].ninteger + 1) / 2; + memcpy(bonus[nlocal_bonus].dvalue, &buf[m], bonus[nlocal_bonus].ndouble * sizeof(double)); m += bonus[nlocal_bonus].ndouble; bonus[nlocal_bonus].ilocal = ilocal; body[ilocal] = nlocal_bonus++; @@ -521,13 +529,15 @@ void AtomVecBody::create_atom_post(int ilocal) void AtomVecBody::data_atom_post(int ilocal) { body_flag = body[ilocal]; - if (body_flag == 0) body_flag = -1; - else if (body_flag == 1) body_flag = 0; - else error->one(FLERR,"Invalid body flag in Atoms section of data file"); + if (body_flag == 0) + body_flag = -1; + else if (body_flag == 1) + body_flag = 0; + else + error->one(FLERR, "Invalid body flag in Atoms section of data file"); body[ilocal] = body_flag; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid density in Atoms section of data file"); radius[ilocal] = 0.5; angmom[ilocal][0] = 0.0; @@ -539,14 +549,12 @@ void AtomVecBody::data_atom_post(int ilocal) unpack one body from Bodies section of data file ------------------------------------------------------------------------- */ -void AtomVecBody::data_body(int m, int ninteger, int ndouble, - int *ivalues, double *dvalues) +void AtomVecBody::data_body(int m, int ninteger, int ndouble, int *ivalues, double *dvalues) { - if (body[m]) - error->one(FLERR,"Assigning body parameters to non-body atom"); + if (body[m]) error->one(FLERR, "Assigning body parameters to non-body atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); bonus[nlocal_bonus].ilocal = m; - bptr->data_body(nlocal_bonus,ninteger,ndouble,ivalues,dvalues); + bptr->data_body(nlocal_bonus, ninteger, ndouble, ivalues, dvalues); body[m] = nlocal_bonus++; } @@ -557,14 +565,14 @@ void AtomVecBody::data_body(int m, int ninteger, int ndouble, double AtomVecBody::memory_usage_bonus() { double bytes = 0; - bytes += (double)nmax_bonus*sizeof(Bonus); + bytes += (double) nmax_bonus * sizeof(Bonus); bytes += icp->size() + dcp->size(); int nall = nlocal_bonus + nghost_bonus; for (int i = 0; i < nall; i++) { if (body[i] >= 0) { - bytes += (double)bonus[body[i]].ninteger * sizeof(int); - bytes += (double)bonus[body[i]].ndouble * sizeof(double); + bytes += (double) bonus[body[i]].ninteger * sizeof(int); + bytes += (double) bonus[body[i]].ndouble * sizeof(double); } } @@ -579,8 +587,10 @@ void AtomVecBody::pack_data_pre(int ilocal) { body_flag = body[ilocal]; - if (body_flag < 0) body[ilocal] = 0; - else body[ilocal] = 1; + if (body_flag < 0) + body[ilocal] = 0; + else + body[ilocal] = 1; } /* ---------------------------------------------------------------------- @@ -598,7 +608,7 @@ int AtomVecBody::pack_data_bonus(double *buf, int /*flag*/) int m = 0; for (i = 0; i < nlocal; i++) { if (body[i] < 0) continue; - int n = bptr->pack_data_body(tag[i],body[i],buf); + int n = bptr->pack_data_body(tag[i], body[i], buf); m += n; if (buf) buf += n; } @@ -613,9 +623,7 @@ int AtomVecBody::pack_data_bonus(double *buf, int /*flag*/) void AtomVecBody::write_data_bonus(FILE *fp, int n, double *buf, int /*flag*/) { int i = 0; - while (i < n) { - i += bptr->write_data_body(fp,&buf[i]); - } + while (i < n) { i += bptr->write_data_body(fp, &buf[i]); } } /* ---------------------------------------------------------------------- @@ -631,10 +639,9 @@ void AtomVecBody::pack_data_post(int ilocal) body computes its size based on ivalues/dvalues and returns it ------------------------------------------------------------------------- */ -double AtomVecBody::radius_body(int ninteger, int ndouble, - int *ivalues, double *dvalues) +double AtomVecBody::radius_body(int ninteger, int ndouble, int *ivalues, double *dvalues) { - return bptr->radius_body(ninteger,ndouble,ivalues,dvalues); + return bptr->radius_body(ninteger, ndouble, ivalues, dvalues); } /* ---------------------------------------------------------------------- @@ -644,10 +651,12 @@ double AtomVecBody::radius_body(int ninteger, int ndouble, void AtomVecBody::set_quat(int m, double *quat_external) { - if (body[m] < 0) error->one(FLERR,"Assigning quat to non-body atom"); + if (body[m] < 0) error->one(FLERR, "Assigning quat to non-body atom"); double *quat = bonus[body[m]].quat; - quat[0] = quat_external[0]; quat[1] = quat_external[1]; - quat[2] = quat_external[2]; quat[3] = quat_external[3]; + quat[0] = quat_external[0]; + quat[1] = quat_external[1]; + quat[2] = quat_external[2]; + quat[3] = quat_external[3]; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec_charge.cpp b/src/atom_vec_charge.cpp index ca66048558..73164b6273 100644 --- a/src/atom_vec_charge.cpp +++ b/src/atom_vec_charge.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -31,18 +30,15 @@ AtomVecCharge::AtomVecCharge(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "q"; - fields_copy = (char *) "q"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) ""; - fields_reverse = (char *) ""; - fields_border = (char *) "q"; - fields_border_vel = (char *) "q"; - fields_exchange = (char *) "q"; - fields_restart = (char *) "q"; - fields_create = (char *) "q"; - fields_data_atom = (char *) "id type q x"; - fields_data_vel = (char *) "id v"; + fields_grow = {"q"}; + fields_copy = {"q"}; + fields_border = {"q"}; + fields_border_vel = {"q"}; + fields_exchange = {"q"}; + fields_restart = {"q"}; + fields_create = {"q"}; + fields_data_atom = {"id", "type", "q", "x"}; + fields_data_vel = {"id", "v"}; setup_fields(); } diff --git a/src/atom_vec_ellipsoid.cpp b/src/atom_vec_ellipsoid.cpp index 6c39e4cfaf..cae0d1bc11 100644 --- a/src/atom_vec_ellipsoid.cpp +++ b/src/atom_vec_ellipsoid.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -26,10 +25,8 @@ #include "memory.h" #include "modify.h" -#include - using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; /* ---------------------------------------------------------------------- */ @@ -54,18 +51,17 @@ AtomVecEllipsoid::AtomVecEllipsoid(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "rmass angmom torque ellipsoid"; - fields_copy = (char *) "rmass angmom"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "angmom"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "rmass"; - fields_border_vel = (char *) "rmass angmom"; - fields_exchange = (char *) "rmass angmom"; - fields_restart = (char *) "rmass angmom"; - fields_create = (char *) "rmass angmom ellipsoid"; - fields_data_atom = (char *) "id type ellipsoid rmass x"; - fields_data_vel = (char *) "id v angmom"; + fields_grow = {"rmass", "angmom", "torque", "ellipsoid"}; + fields_copy = {"rmass", "angmom"}; + fields_comm_vel = {"angmom"}; + fields_reverse = {"torque"}; + fields_border = {"rmass"}; + fields_border_vel = {"rmass", "angmom"}; + fields_exchange = {"rmass", "angmom"}; + fields_restart = {"rmass", "angmom"}; + fields_create = {"rmass", "angmom", "ellipsoid"}; + fields_data_atom = {"id", "type", "ellipsoid", "rmass", "x"}; + fields_data_vel = {"id", "v", "angmom"}; setup_fields(); } @@ -96,11 +92,9 @@ void AtomVecEllipsoid::grow_pointers() void AtomVecEllipsoid::grow_bonus() { nmax_bonus = grow_nmax_bonus(nmax_bonus); - if (nmax_bonus < 0) - error->one(FLERR,"Per-processor system is too big"); + if (nmax_bonus < 0) error->one(FLERR, "Per-processor system is too big"); - bonus = (Bonus *) memory->srealloc(bonus,nmax_bonus*sizeof(Bonus), - "atom:bonus"); + bonus = (Bonus *) memory->srealloc(bonus, nmax_bonus * sizeof(Bonus), "atom:bonus"); } /* ---------------------------------------------------------------------- @@ -112,7 +106,7 @@ void AtomVecEllipsoid::copy_bonus(int i, int j, int delflag) // if deleting atom J via delflag and J has bonus data, then delete it if (delflag && ellipsoid[j] >= 0) { - copy_bonus_all(nlocal_bonus-1,ellipsoid[j]); + copy_bonus_all(nlocal_bonus - 1, ellipsoid[j]); nlocal_bonus--; } @@ -131,7 +125,7 @@ void AtomVecEllipsoid::copy_bonus(int i, int j, int delflag) void AtomVecEllipsoid::copy_bonus_all(int i, int j) { ellipsoid[bonus[i].ilocal] = j; - memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); + memcpy(&bonus[j], &bonus[i], sizeof(Bonus)); } /* ---------------------------------------------------------------------- @@ -152,7 +146,7 @@ void AtomVecEllipsoid::clear_bonus() int AtomVecEllipsoid::pack_comm_bonus(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; double *quat; m = 0; @@ -174,7 +168,7 @@ int AtomVecEllipsoid::pack_comm_bonus(int n, int *list, double *buf) void AtomVecEllipsoid::unpack_comm_bonus(int n, int first, double *buf) { - int i,m,last; + int i, m, last; double *quat; m = 0; @@ -194,13 +188,14 @@ void AtomVecEllipsoid::unpack_comm_bonus(int n, int first, double *buf) int AtomVecEllipsoid::pack_border_bonus(int n, int *list, double *buf) { - int i,j,m; - double *shape,*quat; + int i, j, m; + double *shape, *quat; m = 0; for (i = 0; i < n; i++) { j = list[i]; - if (ellipsoid[j] < 0) buf[m++] = ubuf(0).d; + if (ellipsoid[j] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; shape = bonus[ellipsoid[j]].shape; @@ -222,14 +217,15 @@ int AtomVecEllipsoid::pack_border_bonus(int n, int *list, double *buf) int AtomVecEllipsoid::unpack_border_bonus(int n, int first, double *buf) { - int i,j,m,last; - double *shape,*quat; + int i, j, m, last; + double *shape, *quat; m = 0; last = first + n; for (i = first; i < last; i++) { ellipsoid[i] = (int) ubuf(buf[m++]).i; - if (ellipsoid[i] == 0) ellipsoid[i] = -1; + if (ellipsoid[i] == 0) + ellipsoid[i] = -1; else { j = nlocal_bonus + nghost_bonus; if (j == nmax_bonus) grow_bonus(); @@ -260,7 +256,8 @@ int AtomVecEllipsoid::pack_exchange_bonus(int i, double *buf) { int m = 0; - if (ellipsoid[i] < 0) buf[m++] = ubuf(0).d; + if (ellipsoid[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = ellipsoid[i]; @@ -285,7 +282,8 @@ int AtomVecEllipsoid::unpack_exchange_bonus(int ilocal, double *buf) int m = 0; ellipsoid[ilocal] = (int) ubuf(buf[m++]).i; - if (ellipsoid[ilocal] == 0) ellipsoid[ilocal] = -1; + if (ellipsoid[ilocal] == 0) + ellipsoid[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *shape = bonus[nlocal_bonus].shape; @@ -316,8 +314,10 @@ int AtomVecEllipsoid::size_restart_bonus() int n = 0; int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - if (ellipsoid[i] >= 0) n += size_restart_bonus_one; - else n++; + if (ellipsoid[i] >= 0) + n += size_restart_bonus_one; + else + n++; } return n; @@ -333,7 +333,8 @@ int AtomVecEllipsoid::pack_restart_bonus(int i, double *buf) { int m = 0; - if (ellipsoid[i] < 0) buf[m++] = ubuf(0).d; + if (ellipsoid[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = ellipsoid[i]; @@ -358,7 +359,8 @@ int AtomVecEllipsoid::unpack_restart_bonus(int ilocal, double *buf) int m = 0; ellipsoid[ilocal] = (int) ubuf(buf[m++]).i; - if (ellipsoid[ilocal] == 0) ellipsoid[ilocal] = -1; + if (ellipsoid[ilocal] == 0) + ellipsoid[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *shape = bonus[nlocal_bonus].shape; @@ -381,32 +383,31 @@ int AtomVecEllipsoid::unpack_restart_bonus(int ilocal, double *buf) unpack one line from Ellipsoids section of data file ------------------------------------------------------------------------- */ -void AtomVecEllipsoid::data_atom_bonus(int m, const std::vector & values) +void AtomVecEllipsoid::data_atom_bonus(int m, const std::vector &values) { - if (ellipsoid[m]) - error->one(FLERR,"Assigning ellipsoid parameters to non-ellipsoid atom"); + if (ellipsoid[m]) error->one(FLERR, "Assigning ellipsoid parameters to non-ellipsoid atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); double *shape = bonus[nlocal_bonus].shape; int ivalue = 1; - shape[0] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); - shape[1] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); - shape[2] = 0.5 * utils::numeric(FLERR,values[ivalue++],true,lmp); + shape[0] = 0.5 * utils::numeric(FLERR, values[ivalue++], true, lmp); + shape[1] = 0.5 * utils::numeric(FLERR, values[ivalue++], true, lmp); + shape[2] = 0.5 * utils::numeric(FLERR, values[ivalue++], true, lmp); if (shape[0] <= 0.0 || shape[1] <= 0.0 || shape[2] <= 0.0) - error->one(FLERR,"Invalid shape in Ellipsoids section of data file"); + error->one(FLERR, "Invalid shape in Ellipsoids section of data file"); double *quat = bonus[nlocal_bonus].quat; - quat[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - quat[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - quat[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); - quat[3] = utils::numeric(FLERR,values[ivalue++],true,lmp); + quat[0] = utils::numeric(FLERR, values[ivalue++], true, lmp); + quat[1] = utils::numeric(FLERR, values[ivalue++], true, lmp); + quat[2] = utils::numeric(FLERR, values[ivalue++], true, lmp); + quat[3] = utils::numeric(FLERR, values[ivalue++], true, lmp); MathExtra::qnormalize(quat); // reset ellipsoid mass // previously stored density in rmass - rmass[m] *= 4.0*MY_PI/3.0 * shape[0]*shape[1]*shape[2]; + rmass[m] *= 4.0 * MY_PI / 3.0 * shape[0] * shape[1] * shape[2]; bonus[nlocal_bonus].ilocal = m; ellipsoid[m] = nlocal_bonus++; @@ -419,7 +420,7 @@ void AtomVecEllipsoid::data_atom_bonus(int m, const std::vector & v double AtomVecEllipsoid::memory_usage_bonus() { double bytes = 0; - bytes += nmax_bonus*sizeof(Bonus); + bytes += nmax_bonus * sizeof(Bonus); return bytes; } @@ -441,13 +442,15 @@ void AtomVecEllipsoid::create_atom_post(int ilocal) void AtomVecEllipsoid::data_atom_post(int ilocal) { ellipsoid_flag = ellipsoid[ilocal]; - if (ellipsoid_flag == 0) ellipsoid_flag = -1; - else if (ellipsoid_flag == 1) ellipsoid_flag = 0; - else error->one(FLERR,"Invalid ellipsoid flag in Atoms section of data file"); + if (ellipsoid_flag == 0) + ellipsoid_flag = -1; + else if (ellipsoid_flag == 1) + ellipsoid_flag = 0; + else + error->one(FLERR, "Invalid ellipsoid flag in Atoms section of data file"); ellipsoid[ilocal] = ellipsoid_flag; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid density in Atoms section of data file"); angmom[ilocal][0] = 0.0; angmom[ilocal][1] = 0.0; @@ -465,12 +468,14 @@ void AtomVecEllipsoid::pack_data_pre(int ilocal) ellipsoid_flag = atom->ellipsoid[ilocal]; rmass_one = atom->rmass[ilocal]; - if (ellipsoid_flag < 0) ellipsoid[ilocal] = 0; - else ellipsoid[ilocal] = 1; + if (ellipsoid_flag < 0) + ellipsoid[ilocal] = 0; + else + ellipsoid[ilocal] = 1; if (ellipsoid_flag >= 0) { shape = bonus[ellipsoid_flag].shape; - rmass[ilocal] /= 4.0*MY_PI/3.0 * shape[0]*shape[1]*shape[2]; + rmass[ilocal] /= 4.0 * MY_PI / 3.0 * shape[0] * shape[1] * shape[2]; } } @@ -491,7 +496,7 @@ void AtomVecEllipsoid::pack_data_post(int ilocal) int AtomVecEllipsoid::pack_data_bonus(double *buf, int /*flag*/) { - int i,j; + int i, j; tagint *tag = atom->tag; int nlocal = atom->nlocal; @@ -502,14 +507,15 @@ int AtomVecEllipsoid::pack_data_bonus(double *buf, int /*flag*/) if (buf) { buf[m++] = ubuf(tag[i]).d; j = ellipsoid[i]; - buf[m++] = 2.0*bonus[j].shape[0]; - buf[m++] = 2.0*bonus[j].shape[1]; - buf[m++] = 2.0*bonus[j].shape[2]; + buf[m++] = 2.0 * bonus[j].shape[0]; + buf[m++] = 2.0 * bonus[j].shape[1]; + buf[m++] = 2.0 * bonus[j].shape[2]; buf[m++] = bonus[j].quat[0]; buf[m++] = bonus[j].quat[1]; buf[m++] = bonus[j].quat[2]; buf[m++] = bonus[j].quat[3]; - } else m += size_data_bonus; + } else + m += size_data_bonus; } return m; @@ -523,8 +529,8 @@ void AtomVecEllipsoid::write_data_bonus(FILE *fp, int n, double *buf, int /*flag { int i = 0; while (i < n) { - fmt::print(fp,"{} {} {} {} {} {} {} {}\n",ubuf(buf[i]).i, - buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]); + fmt::print(fp, "{} {} {} {} {} {} {} {}\n", ubuf(buf[i]).i, buf[i + 1], buf[i + 2], buf[i + 3], + buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7]); i += size_data_bonus; } } @@ -552,7 +558,7 @@ void AtomVecEllipsoid::set_shape(int i, double shapex, double shapey, double sha bonus[nlocal_bonus].ilocal = i; ellipsoid[i] = nlocal_bonus++; } else if (shapex == 0.0 && shapey == 0.0 && shapez == 0.0) { - copy_bonus_all(nlocal_bonus-1,ellipsoid[i]); + copy_bonus_all(nlocal_bonus - 1, ellipsoid[i]); nlocal_bonus--; ellipsoid[i] = -1; } else { diff --git a/src/atom_vec_hybrid.cpp b/src/atom_vec_hybrid.cpp index dd83619da8..0d24486c86 100644 --- a/src/atom_vec_hybrid.cpp +++ b/src/atom_vec_hybrid.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -19,12 +18,12 @@ #include "error.h" #include "tokenizer.h" +#include #include using namespace LAMMPS_NS; -#define NFIELDSTRINGS 12 // # of field strings -enum{ELLIPSOID,LINE,TRIANGLE,BODY}; // also in WriteData +enum { ELLIPSOID, LINE, TRIANGLE, BODY }; // also in WriteData /* ---------------------------------------------------------------------- */ @@ -33,22 +32,16 @@ AtomVecHybrid::AtomVecHybrid(LAMMPS *lmp) : AtomVec(lmp) nstyles = 0; styles = nullptr; keywords = nullptr; - fieldstrings = nullptr; bonus_flag = 0; nstyles_bonus = 0; styles_bonus = nullptr; - // these strings will be concatenated from sub-style strings + // field strings will be concatenated from sub-style strings // fields_data_atom & fields_data_vel start with fields common to all styles - fields_grow = fields_copy = fields_comm = fields_comm_vel = (char *) ""; - fields_reverse = fields_border = fields_border_vel = (char *) ""; - fields_exchange = fields_restart = fields_create = (char *) ""; - fields_data_atom = (char *) "id type x"; - fields_data_vel = (char *) "id v"; - - fields_allocated = 0; + fields_data_atom = {"id", "type", "x"}; + fields_data_vel = {"id", "v"}; } /* ---------------------------------------------------------------------- */ @@ -56,28 +49,10 @@ AtomVecHybrid::AtomVecHybrid(LAMMPS *lmp) : AtomVec(lmp) AtomVecHybrid::~AtomVecHybrid() { for (int k = 0; k < nstyles; k++) delete styles[k]; - delete [] styles; - for (int k = 0; k < nstyles; k++) delete [] keywords[k]; - delete [] keywords; - delete [] styles_bonus; - - if (!fields_allocated) return; - - delete [] fields_grow; - delete [] fields_copy; - delete [] fields_comm; - delete [] fields_comm_vel; - delete [] fields_reverse; - delete [] fields_border; - delete [] fields_border_vel; - delete [] fields_exchange; - delete [] fields_restart; - delete [] fields_create; - delete [] fields_data_atom; - delete [] fields_data_vel; - - for (int k = 0; k < nstyles; k++) delete [] fieldstrings[k].fstr; - delete [] fieldstrings; + delete[] styles; + for (int k = 0; k < nstyles; k++) delete[] keywords[k]; + delete[] keywords; + delete[] styles_bonus; } /* ---------------------------------------------------------------------- @@ -92,28 +67,27 @@ void AtomVecHybrid::process_args(int narg, char **arg) // allocate list of sub-styles as big as possibly needed if no extra args - styles = new AtomVec*[narg]; - keywords = new char*[narg]; + styles = new AtomVec *[narg]; + keywords = new char *[narg]; // allocate each sub-style // call process_args() with set of args that are not atom style names // use known_style() to determine which args these are - int i,k,jarg,dummy; - + int dummy; int iarg = 0; nstyles = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"hybrid") == 0) - error->all(FLERR,"Atom style hybrid cannot have hybrid as an argument"); - for (i = 0; i < nstyles; i++) - 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); + if (strcmp(arg[iarg], "hybrid") == 0) + error->all(FLERR, "Atom style hybrid cannot have hybrid as an argument"); + for (int i = 0; i < nstyles; i++) + 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] = utils::strdup(arg[iarg]); - jarg = iarg + 1; + int jarg = iarg + 1; while (jarg < narg && !known_style(arg[jarg])) jarg++; - styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]); + styles[nstyles]->process_args(jarg - iarg - 1, &arg[iarg + 1]); iarg = jarg; nstyles++; } @@ -124,20 +98,19 @@ void AtomVecHybrid::process_args(int narg, char **arg) molecular = Atom::ATOMIC; maxexchange = 0; - for (k = 0; k < nstyles; k++) { + for (int k = 0; k < nstyles; k++) { if ((styles[k]->molecular == Atom::MOLECULAR && molecular == Atom::TEMPLATE) || (styles[k]->molecular == Atom::TEMPLATE && molecular == Atom::MOLECULAR)) - error->all(FLERR, - "Cannot mix molecular and molecule template atom styles"); - molecular = MAX(molecular,styles[k]->molecular); + error->all(FLERR, "Cannot mix molecular and molecule template atom styles"); + molecular = MAX(molecular, styles[k]->molecular); - bonds_allow = MAX(bonds_allow,styles[k]->bonds_allow); - angles_allow = MAX(angles_allow,styles[k]->angles_allow); - dihedrals_allow = MAX(dihedrals_allow,styles[k]->dihedrals_allow); - impropers_allow = MAX(impropers_allow,styles[k]->impropers_allow); - mass_type = MAX(mass_type,styles[k]->mass_type); - dipole_type = MAX(dipole_type,styles[k]->dipole_type); - forceclearflag = MAX(forceclearflag,styles[k]->forceclearflag); + bonds_allow = MAX(bonds_allow, styles[k]->bonds_allow); + angles_allow = MAX(angles_allow, styles[k]->angles_allow); + dihedrals_allow = MAX(dihedrals_allow, styles[k]->dihedrals_allow); + impropers_allow = MAX(impropers_allow, styles[k]->impropers_allow); + mass_type = MAX(mass_type, styles[k]->mass_type); + dipole_type = MAX(dipole_type, styles[k]->dipole_type); + forceclearflag = MAX(forceclearflag, styles[k]->forceclearflag); maxexchange += styles[k]->maxexchange; if (styles[k]->molecular == Atom::TEMPLATE) onemols = styles[k]->onemols; @@ -148,95 +121,71 @@ void AtomVecHybrid::process_args(int narg, char **arg) int mass_pertype = 0; int mass_peratom = 0; - for (k = 0; k < nstyles; k++) { + for (int k = 0; k < nstyles; k++) { if (styles[k]->mass_type == 0) mass_peratom = 1; if (styles[k]->mass_type == 1) mass_pertype = 1; } if (mass_pertype && mass_peratom && comm->me == 0) - error->warning(FLERR, "Atom style hybrid defines both, per-type " + error->warning(FLERR, + "Atom style hybrid defines both, per-type " "and per-atom masses; both must be set, but only " "per-atom masses will be used"); // free allstyles created by build_styles() - for (i = 0; i < nallstyles; i++) delete [] allstyles[i]; - delete [] allstyles; - - // set field strings from all substyles - - fieldstrings = new FieldStrings[nstyles]; - - for (k = 0; k < nstyles; k++) { - fieldstrings[k].fstr = new char*[NFIELDSTRINGS]; - fieldstrings[k].fstr[0] = styles[k]->fields_grow; - fieldstrings[k].fstr[1] = styles[k]->fields_copy; - fieldstrings[k].fstr[2] = styles[k]->fields_comm; - fieldstrings[k].fstr[3] = styles[k]->fields_comm_vel; - fieldstrings[k].fstr[4] = styles[k]->fields_reverse; - fieldstrings[k].fstr[5] = styles[k]->fields_border; - fieldstrings[k].fstr[6] = styles[k]->fields_border_vel; - fieldstrings[k].fstr[7] = styles[k]->fields_exchange; - fieldstrings[k].fstr[8] = styles[k]->fields_restart; - fieldstrings[k].fstr[9] = styles[k]->fields_create; - fieldstrings[k].fstr[10] = styles[k]->fields_data_atom; - fieldstrings[k].fstr[11] = styles[k]->fields_data_vel; - } + for (int i = 0; i < nallstyles; i++) delete[] allstyles[i]; + delete[] allstyles; // merge field strings from all sub-styles // save concat_grow to check for duplicates of special-case fields - char *concat_grow;; - char *dummyptr = nullptr; + std::vector concat_grow; + std::vector concat_dummy; - fields_grow = merge_fields(0,fields_grow,1,concat_grow); - fields_copy = merge_fields(1,fields_copy,0,dummyptr); - fields_comm = merge_fields(2,fields_comm,0,dummyptr); - fields_comm_vel = merge_fields(3,fields_comm_vel,0,dummyptr); - fields_reverse = merge_fields(4,fields_reverse,0,dummyptr); - fields_border = merge_fields(5,fields_border,0,dummyptr); - fields_border_vel = merge_fields(6,fields_border_vel,0,dummyptr); - fields_exchange = merge_fields(7,fields_exchange,0,dummyptr); - fields_restart = merge_fields(8,fields_restart,0,dummyptr); - fields_create = merge_fields(9,fields_create,0,dummyptr); - fields_data_atom = merge_fields(10,fields_data_atom,0,dummyptr); - fields_data_vel = merge_fields(11,fields_data_vel,0,dummyptr); - - fields_allocated = 1; + for (int k = 0; k < nstyles; k++) { + merge_fields(fields_grow, styles[k]->fields_grow, 1, concat_grow); + merge_fields(fields_copy, styles[k]->fields_copy, 0, concat_dummy); + merge_fields(fields_comm, styles[k]->fields_comm, 0, concat_dummy); + merge_fields(fields_comm_vel, styles[k]->fields_comm_vel, 0, concat_dummy); + merge_fields(fields_reverse, styles[k]->fields_reverse, 0, concat_dummy); + merge_fields(fields_border, styles[k]->fields_border, 0, concat_dummy); + merge_fields(fields_border_vel, styles[k]->fields_border_vel, 0, concat_dummy); + merge_fields(fields_exchange, styles[k]->fields_exchange, 0, concat_dummy); + merge_fields(fields_restart, styles[k]->fields_restart, 0, concat_dummy); + merge_fields(fields_create, styles[k]->fields_create, 0, concat_dummy); + merge_fields(fields_data_atom, styles[k]->fields_data_atom, 0, concat_dummy); + merge_fields(fields_data_vel, styles[k]->fields_data_vel, 0, concat_dummy); + } // check concat_grow for multiple special-case fields // may cause issues with style-specific create_atom() and data_atom() methods // issue warnings if appear in multiple sub-styles - const char *dupfield[] = {"radius","rmass"}; - int ndupfield = 2; - char *ptr; + std::vector dupfield = {"radius", "rmass"}; - for (int idup = 0; idup < ndupfield; idup++) { - auto dup = (char *) dupfield[idup]; - ptr = strstr(concat_grow,dup); - if ((ptr && strstr(ptr+1,dup)) && (comm->me == 0)) - error->warning(FLERR,fmt::format("Per-atom {} is used in multiple sub-" - "styles; must be used consistently",dup)); + for (const auto &idup : dupfield) { + if ((comm->me == 0) && (std::count(concat_grow.begin(), concat_grow.end(), idup) > 1)) + error->warning(FLERR, + "Per-atom field {} is used in multiple sub-styles; must be used consistently", + idup); } - delete [] concat_grow; - // set bonus_flag if any substyle has bonus data // set nstyles_bonus & styles_bonus // sum two sizes over contributions from each substyle with bonus data. nstyles_bonus = 0; - for (k = 0; k < nstyles; k++) + for (int k = 0; k < nstyles; k++) if (styles[k]->bonus_flag) nstyles_bonus++; if (nstyles_bonus) { bonus_flag = 1; - styles_bonus = new AtomVec*[nstyles_bonus]; + styles_bonus = new AtomVec *[nstyles_bonus]; nstyles_bonus = 0; size_forward_bonus = 0; size_border_bonus = 0; - for (k = 0; k < nstyles; k++) { + for (int k = 0; k < nstyles; k++) { if (styles[k]->bonus_flag) { styles_bonus[nstyles_bonus++] = styles[k]; size_forward_bonus += styles[k]->size_forward_bonus; @@ -270,23 +219,21 @@ void AtomVecHybrid::grow_pointers() void AtomVecHybrid::force_clear(int n, size_t nbytes) { for (int k = 0; k < nstyles; k++) - if (styles[k]->forceclearflag) styles[k]->force_clear(n,nbytes); + if (styles[k]->forceclearflag) styles[k]->force_clear(n, nbytes); } /* ---------------------------------------------------------------------- */ void AtomVecHybrid::copy_bonus(int i, int j, int delflag) { - for (int k = 0; k < nstyles_bonus; k++) - styles_bonus[k]->copy_bonus(i,j,delflag); + for (int k = 0; k < nstyles_bonus; k++) styles_bonus[k]->copy_bonus(i, j, delflag); } /* ---------------------------------------------------------------------- */ void AtomVecHybrid::clear_bonus() { - for (int k = 0; k < nstyles_bonus; k++) - styles_bonus[k]->clear_bonus(); + for (int k = 0; k < nstyles_bonus; k++) styles_bonus[k]->clear_bonus(); } /* ---------------------------------------------------------------------- */ @@ -294,8 +241,7 @@ void AtomVecHybrid::clear_bonus() int AtomVecHybrid::pack_comm_bonus(int n, int *list, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->pack_comm_bonus(n,list,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->pack_comm_bonus(n, list, buf); return m; } @@ -303,8 +249,7 @@ int AtomVecHybrid::pack_comm_bonus(int n, int *list, double *buf) void AtomVecHybrid::unpack_comm_bonus(int n, int first, double *buf) { - for (int k = 0; k < nstyles_bonus; k++) - styles_bonus[k]->unpack_comm_bonus(n,first,buf); + for (int k = 0; k < nstyles_bonus; k++) styles_bonus[k]->unpack_comm_bonus(n, first, buf); } /* ---------------------------------------------------------------------- */ @@ -312,8 +257,7 @@ void AtomVecHybrid::unpack_comm_bonus(int n, int first, double *buf) int AtomVecHybrid::pack_border_bonus(int n, int *list, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->pack_border_bonus(n,list,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->pack_border_bonus(n, list, buf); return m; } @@ -322,8 +266,7 @@ int AtomVecHybrid::pack_border_bonus(int n, int *list, double *buf) int AtomVecHybrid::unpack_border_bonus(int n, int first, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->unpack_border_bonus(n,first,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->unpack_border_bonus(n, first, buf); return m; } @@ -332,8 +275,7 @@ int AtomVecHybrid::unpack_border_bonus(int n, int first, double *buf) int AtomVecHybrid::pack_exchange_bonus(int i, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->pack_exchange_bonus(i,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->pack_exchange_bonus(i, buf); return m; } @@ -342,8 +284,7 @@ int AtomVecHybrid::pack_exchange_bonus(int i, double *buf) int AtomVecHybrid::unpack_exchange_bonus(int ilocal, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->unpack_exchange_bonus(ilocal,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->unpack_exchange_bonus(ilocal, buf); return m; } @@ -352,8 +293,7 @@ int AtomVecHybrid::unpack_exchange_bonus(int ilocal, double *buf) int AtomVecHybrid::size_restart_bonus() { int n = 0; - for (int k = 0; k < nstyles_bonus; k++) - n += styles_bonus[k]->size_restart_bonus(); + for (int k = 0; k < nstyles_bonus; k++) n += styles_bonus[k]->size_restart_bonus(); return n; } @@ -362,8 +302,7 @@ int AtomVecHybrid::size_restart_bonus() int AtomVecHybrid::pack_restart_bonus(int i, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->pack_restart_bonus(i,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->pack_restart_bonus(i, buf); return m; } @@ -372,8 +311,7 @@ int AtomVecHybrid::pack_restart_bonus(int i, double *buf) int AtomVecHybrid::unpack_restart_bonus(int ilocal, double *buf) { int m = 0; - for (int k = 0; k < nstyles_bonus; k++) - m += styles_bonus[k]->unpack_restart_bonus(ilocal,buf); + for (int k = 0; k < nstyles_bonus; k++) m += styles_bonus[k]->unpack_restart_bonus(ilocal, buf); return m; } @@ -382,8 +320,7 @@ int AtomVecHybrid::unpack_restart_bonus(int ilocal, double *buf) double AtomVecHybrid::memory_usage_bonus() { double bytes = 0; - for (int k = 0; k < nstyles_bonus; k++) - bytes += styles_bonus[k]->memory_usage_bonus(); + for (int k = 0; k < nstyles_bonus; k++) bytes += styles_bonus[k]->memory_usage_bonus(); return bytes; } @@ -393,8 +330,7 @@ double AtomVecHybrid::memory_usage_bonus() void AtomVecHybrid::pack_restart_pre(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->pack_restart_pre(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->pack_restart_pre(ilocal); } /* ---------------------------------------------------------------------- @@ -403,8 +339,7 @@ void AtomVecHybrid::pack_restart_pre(int ilocal) void AtomVecHybrid::pack_restart_post(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->pack_restart_post(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->pack_restart_post(ilocal); } /* ---------------------------------------------------------------------- @@ -413,8 +348,7 @@ void AtomVecHybrid::pack_restart_post(int ilocal) void AtomVecHybrid::unpack_restart_init(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->unpack_restart_init(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->unpack_restart_init(ilocal); } /* ---------------------------------------------------------------------- @@ -423,8 +357,7 @@ void AtomVecHybrid::unpack_restart_init(int ilocal) void AtomVecHybrid::create_atom_post(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->create_atom_post(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->create_atom_post(ilocal); } /* ---------------------------------------------------------------------- @@ -434,16 +367,15 @@ void AtomVecHybrid::create_atom_post(int ilocal) void AtomVecHybrid::data_atom_post(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->data_atom_post(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->data_atom_post(ilocal); } /* ---------------------------------------------------------------------- modify what AtomVec::data_bonds() just unpacked or initialize other bond quantities ------------------------------------------------------------------------- */ -void AtomVecHybrid::data_bonds_post(int m, int num_bond, tagint atom1, - tagint atom2, tagint id_offset) +void AtomVecHybrid::data_bonds_post(int m, int num_bond, tagint atom1, tagint atom2, + tagint id_offset) { for (int k = 0; k < nstyles; k++) styles[k]->data_bonds_post(m, num_bond, atom1, atom2, id_offset); @@ -455,8 +387,7 @@ void AtomVecHybrid::data_bonds_post(int m, int num_bond, tagint atom1, void AtomVecHybrid::pack_data_pre(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->pack_data_pre(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->pack_data_pre(ilocal); } /* ---------------------------------------------------------------------- @@ -465,8 +396,7 @@ void AtomVecHybrid::pack_data_pre(int ilocal) void AtomVecHybrid::pack_data_post(int ilocal) { - for (int k = 0; k < nstyles; k++) - styles[k]->pack_data_post(ilocal); + for (int k = 0; k < nstyles; k++) styles[k]->pack_data_post(ilocal); } /* ---------------------------------------------------------------------- @@ -476,12 +406,12 @@ void AtomVecHybrid::pack_data_post(int ilocal) int AtomVecHybrid::pack_data_bonus(double *buf, int flag) { for (int k = 0; k < nstyles; k++) { - if (flag == ELLIPSOID && strcmp(keywords[k],"ellipsoid") != 0) continue; - if (flag == LINE && strcmp(keywords[k],"line") != 0) continue; - if (flag == TRIANGLE && strcmp(keywords[k],"tri") != 0) continue; - if (flag == BODY && strcmp(keywords[k],"body") != 0) continue; + if (flag == ELLIPSOID && strcmp(keywords[k], "ellipsoid") != 0) continue; + if (flag == LINE && strcmp(keywords[k], "line") != 0) continue; + if (flag == TRIANGLE && strcmp(keywords[k], "tri") != 0) continue; + if (flag == BODY && strcmp(keywords[k], "body") != 0) continue; - return styles[k]->pack_data_bonus(buf,flag); + return styles[k]->pack_data_bonus(buf, flag); } return 0; } @@ -493,12 +423,12 @@ int AtomVecHybrid::pack_data_bonus(double *buf, int flag) void AtomVecHybrid::write_data_bonus(FILE *fp, int n, double *buf, int flag) { for (int k = 0; k < nstyles; k++) { - if (flag == ELLIPSOID && strcmp(keywords[k],"ellipsoid") != 0) continue; - if (flag == LINE && strcmp(keywords[k],"line") != 0) continue; - if (flag == TRIANGLE && strcmp(keywords[k],"tri") != 0) continue; - if (flag == BODY && strcmp(keywords[k],"body") != 0) continue; + if (flag == ELLIPSOID && strcmp(keywords[k], "ellipsoid") != 0) continue; + if (flag == LINE && strcmp(keywords[k], "line") != 0) continue; + if (flag == TRIANGLE && strcmp(keywords[k], "tri") != 0) continue; + if (flag == BODY && strcmp(keywords[k], "body") != 0) continue; - styles[k]->write_data_bonus(fp,n,buf,flag); + styles[k]->write_data_bonus(fp, n, buf, flag); } } @@ -508,11 +438,11 @@ void AtomVecHybrid::write_data_bonus(FILE *fp, int n, double *buf, int flag) return -1 if name is unknown to any sub-styles ------------------------------------------------------------------------- */ -int AtomVecHybrid::property_atom(char *name) +int AtomVecHybrid::property_atom(const std::string &name) { for (int k = 0; k < nstyles; k++) { int index = styles[k]->property_atom(name); - if (index >= 0) return index*nstyles + k; + if (index >= 0) return index * nstyles + k; } return -1; } @@ -522,12 +452,11 @@ int AtomVecHybrid::property_atom(char *name) index maps to data specific to this atom style ------------------------------------------------------------------------- */ -void AtomVecHybrid::pack_property_atom(int multiindex, double *buf, - int nvalues, int groupbit) +void AtomVecHybrid::pack_property_atom(int multiindex, double *buf, int nvalues, int groupbit) { int k = multiindex % nstyles; - int index = multiindex/nstyles; - styles[k]->pack_property_atom(index,buf,nvalues,groupbit); + int index = multiindex / nstyles; + styles[k]->pack_property_atom(index, buf, nvalues, groupbit); } // ---------------------------------------------------------------------- @@ -535,48 +464,21 @@ void AtomVecHybrid::pack_property_atom(int multiindex, double *buf, // ---------------------------------------------------------------------- /* ---------------------------------------------------------------------- - merge fields and remove duplicate fields - concat = root + Inum fields string from all substyles - return dedup = concat with duplicate fields removed + merge fields into root vector and remove duplicate fields if concat_flag set, also return concat (w/ duplicates) - so caller can check for problematic fields, call will free it + so caller can check for problematic fields ------------------------------------------------------------------------- */ -char *AtomVecHybrid::merge_fields(int inum, char *root, - int concat_flag, char *&concat_str) +void AtomVecHybrid::merge_fields(std::vector &root, + const std::vector &fields, int concat_flag, + std::vector &concat) { - // create vector with all words combined + // grow vector with all words combined with dedup and - std::string concat; - if (root) concat += root; - for (int k = 0; k < nstyles; k++) { - if (concat.size() > 0) concat += " "; - concat += fieldstrings[k].fstr[inum]; + for (const auto &field : fields) { + if (concat_flag) concat.push_back(field); + if (std::find(root.begin(), root.end(), field) == root.end()) root.push_back(field); } - if (concat_flag) concat_str = utils::strdup(concat); - - // remove duplicate words without changing the order - - auto words = Tokenizer(concat, " ").as_vector(); - std::vector dedup; - for (auto &w : words) { - bool found = false; - for (auto &d : dedup) { - if (w == d) found = true; - } - if (!found) dedup.push_back(w); - } - - // create final concatenated, deduped string - concat.clear(); - for (auto &d : dedup) { - concat += d; - concat += " "; - } - - // remove trailing blank - if (concat.size() > 0) concat.pop_back(); - return utils::strdup(concat); } /* ---------------------------------------------------------------------- @@ -587,19 +489,19 @@ void AtomVecHybrid::build_styles() { nallstyles = 0; #define ATOM_CLASS -#define AtomStyle(key,Class) nallstyles++; -#include "style_atom.h" // IWYU pragma: keep +#define AtomStyle(key, Class) nallstyles++; +#include "style_atom.h" // IWYU pragma: keep #undef AtomStyle #undef ATOM_CLASS - allstyles = new char*[nallstyles]; + allstyles = new char *[nallstyles]; nallstyles = 0; #define ATOM_CLASS -#define AtomStyle(key,Class) \ +#define AtomStyle(key, Class) \ allstyles[nallstyles] = utils::strdup(#key); \ nallstyles++; -#include "style_atom.h" // IWYU pragma: keep +#include "style_atom.h" // IWYU pragma: keep #undef AtomStyle #undef ATOM_CLASS } @@ -611,6 +513,6 @@ void AtomVecHybrid::build_styles() int AtomVecHybrid::known_style(char *str) { for (int i = 0; i < nallstyles; i++) - if (strcmp(str,allstyles[i]) == 0) return 1; + if (strcmp(str, allstyles[i]) == 0) return 1; return 0; } diff --git a/src/atom_vec_hybrid.h b/src/atom_vec_hybrid.h index 8d1a791044..ef5589484f 100644 --- a/src/atom_vec_hybrid.h +++ b/src/atom_vec_hybrid.h @@ -64,23 +64,18 @@ class AtomVecHybrid : public AtomVec { int pack_data_bonus(double *, int) override; void write_data_bonus(FILE *, int, double *, int) override; - int property_atom(char *) override; + int property_atom(const std::string &) override; void pack_property_atom(int, double *, int, int) override; private: int nallstyles; char **allstyles; - int fields_allocated; - - struct FieldStrings { - char **fstr; - }; - FieldStrings *fieldstrings; int nstyles_bonus; class AtomVec **styles_bonus; - char *merge_fields(int, char *, int, char *&); + void merge_fields(std::vector &, const std::vector &, + int, std::vector &); void build_styles(); int known_style(char *); }; diff --git a/src/atom_vec_line.cpp b/src/atom_vec_line.cpp index e15bc61f2f..2f05684c69 100644 --- a/src/atom_vec_line.cpp +++ b/src/atom_vec_line.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -23,12 +22,11 @@ #include "modify.h" #include -#include using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; -#define EPSILON 0.001 +static constexpr double EPSILON = 0.001; /* ---------------------------------------------------------------------- */ @@ -55,18 +53,17 @@ AtomVecLine::AtomVecLine(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "molecule radius rmass omega torque line"; - fields_copy = (char *) "molecule radius rmass omega"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "omega"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "molecule radius rmass"; - fields_border_vel = (char *) "molecule radius rmass omega"; - fields_exchange = (char *) "molecule radius rmass omega"; - fields_restart = (char *) "molecule radius rmass omega"; - fields_create = (char *) "molecule radius rmass omega line"; - fields_data_atom = (char *) "id molecule type line rmass x"; - fields_data_vel = (char *) "id v omega"; + fields_grow = {"molecule", "radius", "rmass", "omega", "torque", "line"}; + fields_copy = {"molecule", "radius", "rmass", "omega"}; + fields_comm_vel = {"omega"}; + fields_reverse = {"torque"}; + fields_border = {"molecule", "radius", "rmass"}; + fields_border_vel = {"molecule", "radius", "rmass", "omega"}; + fields_exchange = {"molecule", "radius", "rmass", "omega"}; + fields_restart = {"molecule", "radius", "rmass", "omega"}; + fields_create = {"molecule", "radius", "rmass", "omega", "line"}; + fields_data_atom = {"id", "molecule", "type", "line", "rmass", "x"}; + fields_data_vel = {"id", "v", "omega"}; setup_fields(); } @@ -85,7 +82,7 @@ void AtomVecLine::init() AtomVec::init(); if (domain->dimension != 2) - error->all(FLERR,"Atom_style line can only be used in 2d simulations"); + error->all(FLERR, "Atom_style line can only be used in 2d simulations"); } /* ---------------------------------------------------------------------- @@ -108,11 +105,9 @@ void AtomVecLine::grow_pointers() void AtomVecLine::grow_bonus() { nmax_bonus = grow_nmax_bonus(nmax_bonus); - if (nmax_bonus < 0) - error->one(FLERR,"Per-processor system is too big"); + if (nmax_bonus < 0) error->one(FLERR, "Per-processor system is too big"); - bonus = (Bonus *) memory->srealloc(bonus,nmax_bonus*sizeof(Bonus), - "atom:bonus"); + bonus = (Bonus *) memory->srealloc(bonus, nmax_bonus * sizeof(Bonus), "atom:bonus"); } /* ---------------------------------------------------------------------- @@ -124,7 +119,7 @@ void AtomVecLine::copy_bonus(int i, int j, int delflag) // if deleting atom J via delflag and J has bonus data, then delete it if (delflag && line[j] >= 0) { - copy_bonus_all(nlocal_bonus-1,line[j]); + copy_bonus_all(nlocal_bonus - 1, line[j]); nlocal_bonus--; } @@ -143,7 +138,7 @@ void AtomVecLine::copy_bonus(int i, int j, int delflag) void AtomVecLine::copy_bonus_all(int i, int j) { line[bonus[i].ilocal] = j; - memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); + memcpy(&bonus[j], &bonus[i], sizeof(Bonus)); } /* ---------------------------------------------------------------------- @@ -164,7 +159,7 @@ void AtomVecLine::clear_bonus() int AtomVecLine::pack_comm_bonus(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; m = 0; for (i = 0; i < n; i++) { @@ -179,7 +174,7 @@ int AtomVecLine::pack_comm_bonus(int n, int *list, double *buf) void AtomVecLine::unpack_comm_bonus(int n, int first, double *buf) { - int i,m,last; + int i, m, last; m = 0; last = first + n; @@ -192,12 +187,13 @@ void AtomVecLine::unpack_comm_bonus(int n, int first, double *buf) int AtomVecLine::pack_border_bonus(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; m = 0; for (i = 0; i < n; i++) { j = list[i]; - if (line[j] < 0) buf[m++] = ubuf(0).d; + if (line[j] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; buf[m++] = bonus[line[j]].length; @@ -212,13 +208,14 @@ int AtomVecLine::pack_border_bonus(int n, int *list, double *buf) int AtomVecLine::unpack_border_bonus(int n, int first, double *buf) { - int i,j,m,last; + int i, j, m, last; m = 0; last = first + n; for (i = first; i < last; i++) { line[i] = (int) ubuf(buf[m++]).i; - if (line[i] == 0) line[i] = -1; + if (line[i] == 0) + line[i] = -1; else { j = nlocal_bonus + nghost_bonus; if (j == nmax_bonus) grow_bonus(); @@ -242,7 +239,8 @@ int AtomVecLine::pack_exchange_bonus(int i, double *buf) { int m = 0; - if (line[i] < 0) buf[m++] = ubuf(0).d; + if (line[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = line[i]; @@ -260,7 +258,8 @@ int AtomVecLine::unpack_exchange_bonus(int ilocal, double *buf) int m = 0; line[ilocal] = (int) ubuf(buf[m++]).i; - if (line[ilocal] == 0) line[ilocal] = -1; + if (line[ilocal] == 0) + line[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); bonus[nlocal_bonus].length = buf[m++]; @@ -284,8 +283,10 @@ int AtomVecLine::size_restart_bonus() int n = 0; int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - if (line[i] >= 0) n += size_restart_bonus_one; - else n++; + if (line[i] >= 0) + n += size_restart_bonus_one; + else + n++; } return n; @@ -301,7 +302,8 @@ int AtomVecLine::pack_restart_bonus(int i, double *buf) { int m = 0; - if (line[i] < 0) buf[m++] = ubuf(0).d; + if (line[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = line[i]; @@ -321,7 +323,8 @@ int AtomVecLine::unpack_restart_bonus(int ilocal, double *buf) int m = 0; line[ilocal] = (int) ubuf(buf[m++]).i; - if (line[ilocal] == 0) line[ilocal] = -1; + if (line[ilocal] == 0) + line[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); bonus[nlocal_bonus].length = buf[m++]; @@ -339,31 +342,32 @@ int AtomVecLine::unpack_restart_bonus(int ilocal, double *buf) void AtomVecLine::data_atom_bonus(int m, const std::vector &values) { - if (line[m]) error->one(FLERR,"Assigning line parameters to non-line atom"); + if (line[m]) error->one(FLERR, "Assigning line parameters to non-line atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); int ivalue = 1; - double x1 = utils::numeric(FLERR,values[ivalue++],true,lmp); - double y1 = utils::numeric(FLERR,values[ivalue++],true,lmp); - double x2 = utils::numeric(FLERR,values[ivalue++],true,lmp); - double y2 = utils::numeric(FLERR,values[ivalue++],true,lmp); + double x1 = utils::numeric(FLERR, values[ivalue++], true, lmp); + double y1 = utils::numeric(FLERR, values[ivalue++], true, lmp); + double x2 = utils::numeric(FLERR, values[ivalue++], true, lmp); + double y2 = utils::numeric(FLERR, values[ivalue++], true, lmp); double dx = x2 - x1; double dy = y2 - y1; - double length = sqrt(dx*dx + dy*dy); + double length = sqrt(dx * dx + dy * dy); bonus[nlocal_bonus].length = length; - if (dy >= 0.0) bonus[nlocal_bonus].theta = acos(dx/length); - else bonus[nlocal_bonus].theta = -acos(dx/length); + if (dy >= 0.0) + bonus[nlocal_bonus].theta = acos(dx / length); + else + bonus[nlocal_bonus].theta = -acos(dx / length); - double xc = 0.5*(x1+x2); - double yc = 0.5*(y1+y2); + double xc = 0.5 * (x1 + x2); + double yc = 0.5 * (y1 + y2); dx = xc - x[m][0]; dy = yc - x[m][1]; - double delta = sqrt(dx*dx + dy*dy); + double delta = sqrt(dx * dx + dy * dy); - if (delta/length > EPSILON) - error->one(FLERR,"Inconsistent line segment in data file"); + if (delta / length > EPSILON) error->one(FLERR, "Inconsistent line segment in data file"); x[m][0] = xc; x[m][1] = yc; @@ -385,7 +389,7 @@ void AtomVecLine::data_atom_bonus(int m, const std::vector &values) double AtomVecLine::memory_usage_bonus() { double bytes = 0; - bytes += (double)nmax_bonus*sizeof(Bonus); + bytes += (double) nmax_bonus * sizeof(Bonus); return bytes; } @@ -398,7 +402,7 @@ void AtomVecLine::create_atom_post(int ilocal) { double radius_one = 0.5; radius[ilocal] = radius_one; - rmass[ilocal] = 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; + rmass[ilocal] = 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; line[ilocal] = -1; } @@ -410,19 +414,22 @@ void AtomVecLine::create_atom_post(int ilocal) void AtomVecLine::data_atom_post(int ilocal) { line_flag = line[ilocal]; - if (line_flag == 0) line_flag = -1; - else if (line_flag == 1) line_flag = 0; - else error->one(FLERR,"Invalid line flag in Atoms section of data file"); + if (line_flag == 0) + line_flag = -1; + else if (line_flag == 1) + line_flag = 0; + else + error->one(FLERR, "Invalid line flag in Atoms section of data file"); line[ilocal] = line_flag; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid density in Atoms section of data file"); if (line_flag < 0) { double radius_one = 0.5; radius[ilocal] = radius_one; - rmass[ilocal] *= 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; - } else radius[ilocal] = 0.0; + rmass[ilocal] *= 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; + } else + radius[ilocal] = 0.0; omega[ilocal][0] = 0.0; omega[ilocal][1] = 0.0; @@ -438,13 +445,16 @@ void AtomVecLine::pack_data_pre(int ilocal) line_flag = line[ilocal]; rmass_one = rmass[ilocal]; - if (line_flag < 0) line[ilocal] = 0; - else line[ilocal] = 1; + if (line_flag < 0) + line[ilocal] = 0; + else + line[ilocal] = 1; if (line_flag < 0) { double radius_one = radius[ilocal]; - rmass[ilocal] /= 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; - } else rmass[ilocal] /= bonus[line_flag].length; + rmass[ilocal] /= 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; + } else + rmass[ilocal] /= bonus[line_flag].length; } /* ---------------------------------------------------------------------- @@ -464,9 +474,9 @@ void AtomVecLine::pack_data_post(int ilocal) int AtomVecLine::pack_data_bonus(double *buf, int /*flag*/) { - int i,j; - double length,theta; - double xc,yc,x1,x2,y1,y2; + int i, j; + double length, theta; + double xc, yc, x1, x2, y1, y2; double **x = atom->x; tagint *tag = atom->tag; @@ -482,15 +492,16 @@ int AtomVecLine::pack_data_bonus(double *buf, int /*flag*/) theta = bonus[j].theta; xc = x[i][0]; yc = x[i][1]; - x1 = xc - 0.5*cos(theta)*length; - y1 = yc - 0.5*sin(theta)*length; - x2 = xc + 0.5*cos(theta)*length; - y2 = yc + 0.5*sin(theta)*length; + x1 = xc - 0.5 * cos(theta) * length; + y1 = yc - 0.5 * sin(theta) * length; + x2 = xc + 0.5 * cos(theta) * length; + y2 = yc + 0.5 * sin(theta) * length; buf[m++] = x1; buf[m++] = y1; buf[m++] = x2; buf[m++] = y2; - } else m += size_data_bonus; + } else + m += size_data_bonus; } return m; } @@ -503,8 +514,8 @@ void AtomVecLine::write_data_bonus(FILE *fp, int n, double *buf, int /*flag*/) { int i = 0; while (i < n) { - fmt::print(fp,"{} {} {} {} {}\n",ubuf(buf[i]).i, - buf[i+1],buf[i+2],buf[i+3],buf[i+4]); + fmt::print(fp, "{} {} {} {} {}\n", ubuf(buf[i]).i, buf[i + 1], buf[i + 2], buf[i + 3], + buf[i + 4]); i += size_data_bonus; } } @@ -525,10 +536,11 @@ void AtomVecLine::set_length(int i, double value) bonus[nlocal_bonus].ilocal = i; line[i] = nlocal_bonus++; } else if (value == 0.0) { - copy_bonus_all(nlocal_bonus-1,line[i]); + copy_bonus_all(nlocal_bonus - 1, line[i]); nlocal_bonus--; line[i] = -1; - } else bonus[line[i]].length = value; + } else + bonus[line[i]].length = value; // also set radius = half of length // unless value = 0.0, then set diameter = 1.0 @@ -536,40 +548,3 @@ void AtomVecLine::set_length(int i, double value) radius[i] = 0.5 * value; if (value == 0.0) radius[i] = 0.5; } - -/* ---------------------------------------------------------------------- - check consistency of internal Bonus data structure - n = # of atoms in regular structure to check against -------------------------------------------------------------------------- */ - -/* -void AtomVecLine::consistency_check(int n, char *str) -{ - int iflag = 0; - int count = 0; - for (int i = 0; i < n; i++) { - - if (line[i] >= 0) { - count++; - if (line[i] >= nlocal_bonus) iflag++; - if (bonus[line[i]].ilocal != i) iflag++; - //if (comm->me == 1 && update->ntimestep == 873) - // printf("CCHK %s: %d %d: %d %d: %d %d\n", - // str,i,n,line[i],nlocal_bonus,bonus[line[i]].ilocal,iflag); - } - } - - if (iflag) { - printf("BAD vecline ptrs: %s: %d %d: %d\n",str,comm->me, - update->ntimestep,iflag); - MPI_Abort(world,1); - } - - if (count != nlocal_bonus) { - char msg[128]; - printf("BAD vecline count: %s: %d %d: %d %d\n", - str,comm->me,update->ntimestep,count,nlocal_bonus); - MPI_Abort(world,1); - } -} -*/ diff --git a/src/atom_vec_sphere.cpp b/src/atom_vec_sphere.cpp index 0ca87db80e..2a3c58e77e 100644 --- a/src/atom_vec_sphere.cpp +++ b/src/atom_vec_sphere.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -21,8 +20,6 @@ #include "math_const.h" #include "modify.h" -#include - using namespace LAMMPS_NS; using namespace MathConst; @@ -34,26 +31,24 @@ AtomVecSphere::AtomVecSphere(LAMMPS *lmp) : AtomVec(lmp) molecular = Atom::ATOMIC; atom->sphere_flag = 1; - atom->radius_flag = atom->rmass_flag = atom->omega_flag = - atom->torque_flag = 1; + atom->radius_flag = atom->rmass_flag = atom->omega_flag = atom->torque_flag = 1; // strings with peratom variables to include in each AtomVec method // strings cannot contain fields in corresponding AtomVec default strings // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "radius rmass omega torque"; - fields_copy = (char *) "radius rmass omega"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "omega"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "radius rmass"; - fields_border_vel = (char *) "radius rmass omega"; - fields_exchange = (char *) "radius rmass omega"; - fields_restart = (char *) "radius rmass omega"; - fields_create = (char *) "radius rmass omega"; - fields_data_atom = (char *) "id type radius rmass x"; - fields_data_vel = (char *) "id v omega"; + fields_grow = {"radius", "rmass", "omega", "torque"}; + fields_copy = {"radius", "rmass", "omega"}; + fields_comm_vel = {"omega"}; + fields_reverse = {"torque"}; + fields_border = {"radius", "rmass"}; + fields_border_vel = {"radius", "rmass", "omega"}; + fields_exchange = {"radius", "rmass", "omega"}; + fields_restart = {"radius", "rmass", "omega"}; + fields_create = {"radius", "rmass", "omega"}; + fields_data_atom = {"id", "type", "radius", "rmass", "x"}; + fields_data_vel = {"id", "v", "omega"}; } /* ---------------------------------------------------------------------- @@ -63,21 +58,19 @@ AtomVecSphere::AtomVecSphere(LAMMPS *lmp) : AtomVec(lmp) void AtomVecSphere::process_args(int narg, char **arg) { - if (narg != 0 && narg != 1) - error->all(FLERR,"Illegal atom_style sphere command"); + if (narg != 0 && narg != 1) error->all(FLERR, "Illegal atom_style sphere command"); radvary = 0; if (narg == 1) { - radvary = utils::numeric(FLERR,arg[0],true,lmp); - if (radvary < 0 || radvary > 1) - error->all(FLERR,"Illegal atom_style sphere command"); + radvary = utils::numeric(FLERR, arg[0], true, lmp); + if (radvary < 0 || radvary > 1) error->all(FLERR, "Illegal atom_style sphere command"); } // dynamic particle radius and mass must be communicated every step if (radvary) { - fields_comm = (char *) "radius rmass"; - fields_comm_vel = (char *) "radius rmass omega"; + fields_comm = {"radius", "rmass"}; + fields_comm_vel = {"radius", "rmass", "omega"}; } // delay setting up of fields until now @@ -94,11 +87,10 @@ void AtomVecSphere::init() // check if optional radvary setting should have been set to 1 for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"adapt") == 0) { - auto fix = dynamic_cast( modify->fix[i]); + if (strcmp(modify->fix[i]->style, "adapt") == 0) { + auto fix = dynamic_cast(modify->fix[i]); if (fix->diamflag && radvary == 0) - error->all(FLERR,"Fix adapt changes particle radii " - "but atom_style sphere is not dynamic"); + error->all(FLERR, "Fix adapt changes particle radii but atom_style sphere is not dynamic"); } } @@ -121,7 +113,7 @@ void AtomVecSphere::grow_pointers() void AtomVecSphere::create_atom_post(int ilocal) { radius[ilocal] = 0.5; - rmass[ilocal] = 4.0*MY_PI/3.0 * 0.5*0.5*0.5; + rmass[ilocal] = 4.0 * MY_PI / 3.0 * 0.5 * 0.5 * 0.5; } /* ---------------------------------------------------------------------- @@ -133,11 +125,9 @@ void AtomVecSphere::data_atom_post(int ilocal) { radius_one = 0.5 * atom->radius[ilocal]; radius[ilocal] = radius_one; - if (radius_one > 0.0) - rmass[ilocal] *= 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; + if (radius_one > 0.0) rmass[ilocal] *= 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid density in Atoms section of data file"); omega[ilocal][0] = 0.0; omega[ilocal][1] = 0.0; @@ -154,9 +144,8 @@ void AtomVecSphere::pack_data_pre(int ilocal) rmass_one = rmass[ilocal]; radius[ilocal] *= 2.0; - if (radius_one!= 0.0) - rmass[ilocal] = - rmass_one / (4.0*MY_PI/3.0 * radius_one*radius_one*radius_one); + if (radius_one != 0.0) + rmass[ilocal] = rmass_one / (4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one); } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec_tri.cpp b/src/atom_vec_tri.cpp index 4b1ee0d921..4dbd0dd677 100644 --- a/src/atom_vec_tri.cpp +++ b/src/atom_vec_tri.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -19,18 +18,17 @@ #include "error.h" #include "fix.h" #include "math_const.h" -#include "math_extra.h" #include "math_eigen.h" +#include "math_extra.h" #include "memory.h" #include "modify.h" #include -#include using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::MY_PI; -#define EPSILON 0.001 +static constexpr double EPSILON = 0.001; /* ---------------------------------------------------------------------- */ @@ -58,18 +56,17 @@ AtomVecTri::AtomVecTri(LAMMPS *lmp) : AtomVec(lmp) // order of fields in a string does not matter // except: fields_data_atom & fields_data_vel must match data file - fields_grow = (char *) "molecule radius rmass omega angmom torque tri"; - fields_copy = (char *) "molecule radius rmass omega angmom"; - fields_comm = (char *) ""; - fields_comm_vel = (char *) "omega angmom"; - fields_reverse = (char *) "torque"; - fields_border = (char *) "molecule radius rmass"; - fields_border_vel = (char *) "molecule radius rmass omega"; - fields_exchange = (char *) "molecule radius rmass omega angmom"; - fields_restart = (char *) "molecule radius rmass omega angmom"; - fields_create = (char *) "molecule radius rmass omega angmom tri"; - fields_data_atom = (char *) "id molecule type tri rmass x"; - fields_data_vel = (char *) "id v omega angmom"; + fields_grow = {"molecule", "radius", "rmass", "omega", "angmom", "torque", "tri"}; + fields_copy = {"molecule", "radius", "rmass", "omega", "angmom"}; + fields_comm_vel = {"omega", "angmom"}; + fields_reverse = {"torque"}; + fields_border = {"molecule", "radius", "rmass"}; + fields_border_vel = {"molecule", "radius", "rmass", "omega"}; + fields_exchange = {"molecule", "radius", "rmass", "omega", "angmom"}; + fields_restart = {"molecule", "radius", "rmass", "omega", "angmom"}; + fields_create = {"molecule", "radius", "rmass", "omega", "angmom", "tri"}; + fields_data_atom = {"id", "molecule", "type", "tri", "rmass", "x"}; + fields_data_vel = {"id", "v", "omega", "angmom"}; setup_fields(); } @@ -88,7 +85,7 @@ void AtomVecTri::init() AtomVec::init(); if (domain->dimension != 3) - error->all(FLERR,"Atom_style tri can only be used in 3d simulations"); + error->all(FLERR, "Atom_style tri can only be used in 3d simulations"); } /* ---------------------------------------------------------------------- @@ -112,11 +109,9 @@ void AtomVecTri::grow_pointers() void AtomVecTri::grow_bonus() { nmax_bonus = grow_nmax_bonus(nmax_bonus); - if (nmax_bonus < 0) - error->one(FLERR,"Per-processor system is too big"); + if (nmax_bonus < 0) error->one(FLERR, "Per-processor system is too big"); - bonus = (Bonus *) memory->srealloc(bonus,nmax_bonus*sizeof(Bonus), - "atom:bonus"); + bonus = (Bonus *) memory->srealloc(bonus, nmax_bonus * sizeof(Bonus), "atom:bonus"); } /* ---------------------------------------------------------------------- @@ -129,7 +124,7 @@ void AtomVecTri::copy_bonus(int i, int j, int delflag) // if deleting atom J via delflag and J has bonus data, then delete it if (delflag && tri[j] >= 0) { - copy_bonus_all(nlocal_bonus-1,tri[j]); + copy_bonus_all(nlocal_bonus - 1, tri[j]); nlocal_bonus--; } @@ -148,7 +143,7 @@ void AtomVecTri::copy_bonus(int i, int j, int delflag) void AtomVecTri::copy_bonus_all(int i, int j) { tri[bonus[i].ilocal] = j; - memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); + memcpy(&bonus[j], &bonus[i], sizeof(Bonus)); } /* ---------------------------------------------------------------------- @@ -169,7 +164,7 @@ void AtomVecTri::clear_bonus() int AtomVecTri::pack_comm_bonus(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; double *quat; m = 0; @@ -191,7 +186,7 @@ int AtomVecTri::pack_comm_bonus(int n, int *list, double *buf) void AtomVecTri::unpack_comm_bonus(int n, int first, double *buf) { - int i,m,last; + int i, m, last; double *quat; m = 0; @@ -211,13 +206,14 @@ void AtomVecTri::unpack_comm_bonus(int n, int first, double *buf) int AtomVecTri::pack_border_bonus(int n, int *list, double *buf) { - int i,j,m; - double *quat,*c1,*c2,*c3,*inertia; + int i, j, m; + double *quat, *c1, *c2, *c3, *inertia; m = 0; for (i = 0; i < n; i++) { j = list[i]; - if (tri[j] < 0) buf[m++] = ubuf(0).d; + if (tri[j] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; quat = bonus[tri[j]].quat; @@ -251,14 +247,15 @@ int AtomVecTri::pack_border_bonus(int n, int *list, double *buf) int AtomVecTri::unpack_border_bonus(int n, int first, double *buf) { - int i,j,m,last; - double *quat,*c1,*c2,*c3,*inertia; + int i, j, m, last; + double *quat, *c1, *c2, *c3, *inertia; m = 0; last = first + n; for (i = first; i < last; i++) { tri[i] = (int) ubuf(buf[m++]).i; - if (tri[i] == 0) tri[i] = -1; + if (tri[i] == 0) + tri[i] = -1; else { j = nlocal_bonus + nghost_bonus; if (j == nmax_bonus) grow_bonus(); @@ -301,7 +298,8 @@ int AtomVecTri::pack_exchange_bonus(int i, double *buf) { int m = 0; - if (tri[i] < 0) buf[m++] = ubuf(0).d; + if (tri[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = tri[i]; @@ -338,7 +336,8 @@ int AtomVecTri::unpack_exchange_bonus(int ilocal, double *buf) int m = 0; tri[ilocal] = (int) ubuf(buf[m++]).i; - if (tri[ilocal] == 0) tri[ilocal] = -1; + if (tri[ilocal] == 0) + tri[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *quat = bonus[nlocal_bonus].quat; @@ -381,8 +380,10 @@ int AtomVecTri::size_restart_bonus() int n = 0; int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - if (tri[i] >= 0) n += size_restart_bonus_one; - else n++; + if (tri[i] >= 0) + n += size_restart_bonus_one; + else + n++; } return n; @@ -396,7 +397,8 @@ int AtomVecTri::pack_restart_bonus(int i, double *buf) { int m = 0; - if (tri[i] < 0) buf[m++] = ubuf(0).d; + if (tri[i] < 0) + buf[m++] = ubuf(0).d; else { buf[m++] = ubuf(1).d; int j = tri[i]; @@ -435,7 +437,8 @@ int AtomVecTri::unpack_restart_bonus(int ilocal, double *buf) int m = 0; tri[ilocal] = (int) ubuf(buf[m++]).i; - if (tri[ilocal] == 0) tri[ilocal] = -1; + if (tri[ilocal] == 0) + tri[ilocal] = -1; else { if (nlocal_bonus == nmax_bonus) grow_bonus(); double *quat = bonus[nlocal_bonus].quat; @@ -472,52 +475,51 @@ int AtomVecTri::unpack_restart_bonus(int ilocal, double *buf) void AtomVecTri::data_atom_bonus(int m, const std::vector &values) { - if (tri[m]) error->one(FLERR,"Assigning tri parameters to non-tri atom"); + if (tri[m]) error->one(FLERR, "Assigning tri parameters to non-tri atom"); if (nlocal_bonus == nmax_bonus) grow_bonus(); - double c1[3],c2[3],c3[3]; + double c1[3], c2[3], c3[3]; int ivalue = 1; - c1[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c1[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c1[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c2[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c2[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c2[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c3[0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c3[1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - c3[2] = utils::numeric(FLERR,values[ivalue++],true,lmp); + c1[0] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c1[1] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c1[2] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c2[0] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c2[1] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c2[2] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c3[0] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c3[1] = utils::numeric(FLERR, values[ivalue++], true, lmp); + c3[2] = utils::numeric(FLERR, values[ivalue++], true, lmp); // check for duplicate points if (c1[0] == c2[0] && c1[1] == c2[1] && c1[2] == c2[2]) - error->one(FLERR,"Invalid shape in Triangles section of data file"); + error->one(FLERR, "Invalid shape in Triangles section of data file"); if (c1[0] == c3[0] && c1[1] == c3[1] && c1[2] == c3[2]) - error->one(FLERR,"Invalid shape in Triangles section of data file"); + error->one(FLERR, "Invalid shape in Triangles section of data file"); if (c2[0] == c3[0] && c2[1] == c3[1] && c2[2] == c3[2]) - error->one(FLERR,"Invalid shape in Triangles section of data file"); + error->one(FLERR, "Invalid shape in Triangles section of data file"); // size = length of one edge - double c2mc1[3],c3mc1[3]; - MathExtra::sub3(c2,c1,c2mc1); - MathExtra::sub3(c3,c1,c3mc1); - double size = MAX(MathExtra::len3(c2mc1),MathExtra::len3(c3mc1)); + double c2mc1[3], c3mc1[3]; + MathExtra::sub3(c2, c1, c2mc1); + MathExtra::sub3(c3, c1, c3mc1); + double size = MAX(MathExtra::len3(c2mc1), MathExtra::len3(c3mc1)); // centroid = 1/3 of sum of vertices double centroid[3]; - centroid[0] = (c1[0]+c2[0]+c3[0]) / 3.0; - centroid[1] = (c1[1]+c2[1]+c3[1]) / 3.0; - centroid[2] = (c1[2]+c2[2]+c3[2]) / 3.0; + centroid[0] = (c1[0] + c2[0] + c3[0]) / 3.0; + centroid[1] = (c1[1] + c2[1] + c3[1]) / 3.0; + centroid[2] = (c1[2] + c2[2] + c3[2]) / 3.0; double dx = centroid[0] - x[m][0]; double dy = centroid[1] - x[m][1]; double dz = centroid[2] - x[m][2]; - double delta = sqrt(dx*dx + dy*dy + dz*dz); + double delta = sqrt(dx * dx + dy * dy + dz * dz); - if (delta/size > EPSILON) - error->one(FLERR,"Inconsistent triangle in data file"); + if (delta / size > EPSILON) error->one(FLERR, "Inconsistent triangle in data file"); x[m][0] = centroid[0]; x[m][1] = centroid[1]; @@ -528,29 +530,29 @@ void AtomVecTri::data_atom_bonus(int m, const std::vector &values) // tri area = 0.5 len(U x V), where U,V are edge vectors from one vertex double c4[3]; - MathExtra::sub3(c1,centroid,c4); + MathExtra::sub3(c1, centroid, c4); radius[m] = MathExtra::lensq3(c4); - MathExtra::sub3(c2,centroid,c4); - radius[m] = MAX(radius[m],MathExtra::lensq3(c4)); - MathExtra::sub3(c3,centroid,c4); - radius[m] = MAX(radius[m],MathExtra::lensq3(c4)); + MathExtra::sub3(c2, centroid, c4); + radius[m] = MAX(radius[m], MathExtra::lensq3(c4)); + MathExtra::sub3(c3, centroid, c4); + radius[m] = MAX(radius[m], MathExtra::lensq3(c4)); radius[m] = sqrt(radius[m]); double norm[3]; - MathExtra::cross3(c2mc1,c3mc1,norm); + MathExtra::cross3(c2mc1, c3mc1, norm); double area = 0.5 * MathExtra::len3(norm); rmass[m] *= area; // inertia = inertia tensor of triangle as 6-vector in Voigt ordering double inertia[6]; - MathExtra::inertia_triangle(c1,c2,c3,rmass[m],inertia); + MathExtra::inertia_triangle(c1, c2, c3, rmass[m], inertia); // diagonalize inertia tensor via Jacobi rotations // bonus[].inertia = 3 eigenvalues = principal moments of inertia // evectors and exzy_space = 3 evectors = principal axes of triangle - double tensor[3][3],evectors[3][3]; + double tensor[3][3], evectors[3][3]; tensor[0][0] = inertia[0]; tensor[1][1] = inertia[1]; tensor[2][2] = inertia[2]; @@ -558,10 +560,10 @@ void AtomVecTri::data_atom_bonus(int m, const std::vector &values) tensor[0][2] = tensor[2][0] = inertia[4]; tensor[0][1] = tensor[1][0] = inertia[5]; - int ierror = MathEigen::jacobi3(tensor,bonus[nlocal_bonus].inertia,evectors); - if (ierror) error->one(FLERR,"Insufficient Jacobi rotations for triangle"); + int ierror = MathEigen::jacobi3(tensor, bonus[nlocal_bonus].inertia, evectors); + if (ierror) error->one(FLERR, "Insufficient Jacobi rotations for triangle"); - double ex_space[3],ey_space[3],ez_space[3]; + double ex_space[3], ey_space[3], ez_space[3]; ex_space[0] = evectors[0][0]; ex_space[1] = evectors[1][0]; ex_space[2] = evectors[2][0]; @@ -575,26 +577,23 @@ void AtomVecTri::data_atom_bonus(int m, const std::vector &values) // enforce 3 orthogonal vectors as a right-handed coordinate system // flip 3rd vector if needed - MathExtra::cross3(ex_space,ey_space,norm); - if (MathExtra::dot3(norm,ez_space) < 0.0) MathExtra::negate3(ez_space); + MathExtra::cross3(ex_space, ey_space, norm); + if (MathExtra::dot3(norm, ez_space) < 0.0) MathExtra::negate3(ez_space); // create initial quaternion - MathExtra::exyz_to_q(ex_space,ey_space,ez_space,bonus[nlocal_bonus].quat); + MathExtra::exyz_to_q(ex_space, ey_space, ez_space, bonus[nlocal_bonus].quat); // bonus c1,c2,c3 = displacement of c1,c2,c3 from centroid // in basis of principal axes double disp[3]; - MathExtra::sub3(c1,centroid,disp); - MathExtra::transpose_matvec(ex_space,ey_space,ez_space, - disp,bonus[nlocal_bonus].c1); - MathExtra::sub3(c2,centroid,disp); - MathExtra::transpose_matvec(ex_space,ey_space,ez_space, - disp,bonus[nlocal_bonus].c2); - MathExtra::sub3(c3,centroid,disp); - MathExtra::transpose_matvec(ex_space,ey_space,ez_space, - disp,bonus[nlocal_bonus].c3); + MathExtra::sub3(c1, centroid, disp); + MathExtra::transpose_matvec(ex_space, ey_space, ez_space, disp, bonus[nlocal_bonus].c1); + MathExtra::sub3(c2, centroid, disp); + MathExtra::transpose_matvec(ex_space, ey_space, ez_space, disp, bonus[nlocal_bonus].c2); + MathExtra::sub3(c3, centroid, disp); + MathExtra::transpose_matvec(ex_space, ey_space, ez_space, disp, bonus[nlocal_bonus].c3); bonus[nlocal_bonus].ilocal = m; tri[m] = nlocal_bonus++; @@ -607,7 +606,7 @@ void AtomVecTri::data_atom_bonus(int m, const std::vector &values) double AtomVecTri::memory_usage_bonus() { double bytes = 0; - bytes += (double)nmax_bonus*sizeof(Bonus); + bytes += (double) nmax_bonus * sizeof(Bonus); return bytes; } @@ -620,7 +619,7 @@ void AtomVecTri::create_atom_post(int ilocal) { double radius_one = 0.5; radius[ilocal] = radius_one; - rmass[ilocal] = 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; + rmass[ilocal] = 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; tri[ilocal] = -1; } @@ -632,19 +631,22 @@ void AtomVecTri::create_atom_post(int ilocal) void AtomVecTri::data_atom_post(int ilocal) { tri_flag = tri[ilocal]; - if (tri_flag == 0) tri_flag = -1; - else if (tri_flag == 1) tri_flag = 0; - else error->one(FLERR,"Invalid tri flag in Atoms section of data file"); + if (tri_flag == 0) + tri_flag = -1; + else if (tri_flag == 1) + tri_flag = 0; + else + error->one(FLERR, "Invalid tri flag in Atoms section of data file"); tri[ilocal] = tri_flag; - if (rmass[ilocal] <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); + if (rmass[ilocal] <= 0.0) error->one(FLERR, "Invalid density in Atoms section of data file"); if (tri_flag < 0) { double radius_one = 0.5; radius[ilocal] = radius_one; - rmass[ilocal] *= 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; - } else radius[ilocal] = 0.0; + rmass[ilocal] *= 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; + } else + radius[ilocal] = 0.0; omega[ilocal][0] = 0.0; omega[ilocal][1] = 0.0; @@ -663,17 +665,19 @@ void AtomVecTri::pack_data_pre(int ilocal) tri_flag = tri[ilocal]; rmass_one = rmass[ilocal]; - if (tri_flag < 0) tri[ilocal] = 0; - else tri[ilocal] = 1; + if (tri_flag < 0) + tri[ilocal] = 0; + else + tri[ilocal] = 1; if (tri_flag < 0) { double radius_one = radius[ilocal]; - rmass[ilocal] /= 4.0*MY_PI/3.0 * radius_one*radius_one*radius_one; + rmass[ilocal] /= 4.0 * MY_PI / 3.0 * radius_one * radius_one * radius_one; } else { - double c2mc1[3],c3mc1[3],norm[3]; - MathExtra::sub3(bonus[tri_flag].c2,bonus[tri_flag].c1,c2mc1); - MathExtra::sub3(bonus[tri_flag].c3,bonus[tri_flag].c1,c3mc1); - MathExtra::cross3(c2mc1,c3mc1,norm); + double c2mc1[3], c3mc1[3], norm[3]; + MathExtra::sub3(bonus[tri_flag].c2, bonus[tri_flag].c1, c2mc1); + MathExtra::sub3(bonus[tri_flag].c3, bonus[tri_flag].c1, c3mc1); + MathExtra::cross3(c2mc1, c3mc1, norm); double area = 0.5 * MathExtra::len3(norm); rmass[ilocal] /= area; } @@ -696,9 +700,9 @@ void AtomVecTri::pack_data_post(int ilocal) int AtomVecTri::pack_data_bonus(double *buf, int /*flag*/) { - int i,j; - double xc,yc,zc; - double dc1[3],dc2[3],dc3[3]; + int i, j; + double xc, yc, zc; + double dc1[3], dc2[3], dc3[3]; double p[3][3]; double **x = atom->x; @@ -711,10 +715,10 @@ int AtomVecTri::pack_data_bonus(double *buf, int /*flag*/) if (buf) { buf[m++] = ubuf(tag[i]).d; j = tri[i]; - MathExtra::quat_to_mat(bonus[j].quat,p); - MathExtra::matvec(p,bonus[j].c1,dc1); - MathExtra::matvec(p,bonus[j].c2,dc2); - MathExtra::matvec(p,bonus[j].c3,dc3); + MathExtra::quat_to_mat(bonus[j].quat, p); + MathExtra::matvec(p, bonus[j].c1, dc1); + MathExtra::matvec(p, bonus[j].c2, dc2); + MathExtra::matvec(p, bonus[j].c3, dc3); xc = x[i][0]; yc = x[i][1]; zc = x[i][2]; @@ -727,7 +731,8 @@ int AtomVecTri::pack_data_bonus(double *buf, int /*flag*/) buf[m++] = xc + dc3[0]; buf[m++] = yc + dc3[1]; buf[m++] = zc + dc3[2]; - } else m += size_data_bonus; + } else + m += size_data_bonus; } return m; } @@ -740,9 +745,8 @@ void AtomVecTri::write_data_bonus(FILE *fp, int n, double *buf, int /*flag*/) { int i = 0; while (i < n) { - fmt::print(fp,"{} {} {} {} {} {} {} {} {} {}\n", ubuf(buf[i]).i, - buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6], - buf[i+7],buf[i+8],buf[i+9]); + fmt::print(fp, "{} {} {} {} {} {} {} {} {} {}\n", ubuf(buf[i]).i, buf[i + 1], buf[i + 2], + buf[i + 3], buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7], buf[i + 8], buf[i + 9]); i += size_data_bonus; } } @@ -770,24 +774,24 @@ void AtomVecTri::set_equilateral(int i, double size) quat[1] = 0.0; quat[2] = 0.0; quat[3] = 0.0; - c1[0] = -size/2.0; - c1[1] = -sqrt(3.0)/2.0 * size / 3.0; + c1[0] = -size / 2.0; + c1[1] = -sqrt(3.0) / 2.0 * size / 3.0; c1[2] = 0.0; - c2[0] = size/2.0; - c2[1] = -sqrt(3.0)/2.0 * size / 3.0; + c2[0] = size / 2.0; + c2[1] = -sqrt(3.0) / 2.0 * size / 3.0; c2[2] = 0.0; c3[0] = 0.0; - c3[1] = sqrt(3.0)/2.0 * size * 2.0/3.0; + c3[1] = sqrt(3.0) / 2.0 * size * 2.0 / 3.0; c3[2] = 0.0; - inertia[0] = sqrt(3.0)/96.0 * size*size*size*size; - inertia[1] = sqrt(3.0)/96.0 * size*size*size*size; - inertia[2] = sqrt(3.0)/48.0 * size*size*size*size; + inertia[0] = sqrt(3.0) / 96.0 * size * size * size * size; + inertia[1] = sqrt(3.0) / 96.0 * size * size * size * size; + inertia[2] = sqrt(3.0) / 48.0 * size * size * size * size; radius[i] = MathExtra::len3(c1); bonus[nlocal_bonus].ilocal = i; tri[i] = nlocal_bonus++; } else if (size == 0.0) { radius[i] = 0.5; - copy_bonus_all(nlocal_bonus-1,tri[i]); + copy_bonus_all(nlocal_bonus - 1, tri[i]); nlocal_bonus--; tri[i] = -1; } else { @@ -795,18 +799,18 @@ void AtomVecTri::set_equilateral(int i, double size) double *c2 = bonus[tri[i]].c2; double *c3 = bonus[tri[i]].c3; double *inertia = bonus[tri[i]].inertia; - c1[0] = -size/2.0; - c1[1] = -sqrt(3.0)/2.0 * size / 3.0; + c1[0] = -size / 2.0; + c1[1] = -sqrt(3.0) / 2.0 * size / 3.0; c1[2] = 0.0; - c2[0] = size/2.0; - c2[1] = -sqrt(3.0)/2.0 * size / 3.0; + c2[0] = size / 2.0; + c2[1] = -sqrt(3.0) / 2.0 * size / 3.0; c2[2] = 0.0; c3[0] = 0.0; - c3[1] = sqrt(3.0)/2.0 * size * 2.0/3.0; + c3[1] = sqrt(3.0) / 2.0 * size * 2.0 / 3.0; c3[2] = 0.0; - inertia[0] = sqrt(3.0)/96.0 * size*size*size*size; - inertia[1] = sqrt(3.0)/96.0 * size*size*size*size; - inertia[2] = sqrt(3.0)/48.0 * size*size*size*size; + inertia[0] = sqrt(3.0) / 96.0 * size * size * size * size; + inertia[1] = sqrt(3.0) / 96.0 * size * size * size * size; + inertia[2] = sqrt(3.0) / 48.0 * size * size * size * size; radius[i] = MathExtra::len3(c1); } } diff --git a/src/bond.cpp b/src/bond.cpp index 4c4eafe751..ffdf2b8daf 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -43,6 +43,7 @@ Bond::Bond(LAMMPS *_lmp) : Pointers(_lmp) energy = 0.0; virial[0] = virial[1] = virial[2] = virial[3] = virial[4] = virial[5] = 0.0; writedata = 1; + reinitflag = 1; comm_forward = comm_reverse = comm_reverse_off = 0; @@ -337,11 +338,13 @@ double Bond::memory_usage() } /* ----------------------------------------------------------------------- - Reset all type-based bond params via init. + reset all type-based bond params via init() -------------------------------------------------------------------------- */ + void Bond::reinit() { - if (!reinitflag) error->all(FLERR, "Fix adapt interface to this bond style not supported"); + if (!reinitflag) + error->all(FLERR, "Fix adapt interface to this bond style not supported"); init(); } diff --git a/src/bond.h b/src/bond.h index 5ba0a6fc28..5c0d01747b 100644 --- a/src/bond.h +++ b/src/bond.h @@ -39,7 +39,8 @@ class Bond : protected Pointers { int comm_reverse; // size of reverse communication (0 if none) int comm_reverse_off; // size of reverse comm even if newton off - int reinitflag; // 1 if compatible with fix adapt and alike + int reinitflag; // 0 if not compatible with fix adapt + // extract() method may still need to be added // KOKKOS host/device flag and data masks @@ -63,7 +64,8 @@ class Bond : protected Pointers { virtual double single(int, double, int, int, double &) = 0; virtual double memory_usage(); virtual void *extract(const char *, int &) { return nullptr; } - virtual void reinit(); + void reinit(); + virtual int pack_forward_comm(int, int *, double *, int, int *) {return 0;} virtual void unpack_forward_comm(int, int, double *) {} virtual int pack_reverse_comm(int, int, double *) {return 0;} diff --git a/src/compute.h b/src/compute.h index 3d6323b3d1..6d0e4bd0f1 100644 --- a/src/compute.h +++ b/src/compute.h @@ -108,7 +108,7 @@ class Compute : protected Pointers { Compute(class LAMMPS *, int, char **); ~Compute() override; void modify_params(int, char **); - void reset_extra_dof(); + virtual void reset_extra_dof(); virtual void init() = 0; virtual void init_list(int, class NeighList *) {} diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index 07a0c700ee..7cb47acaf4 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -30,8 +30,6 @@ using namespace LAMMPS_NS; -enum { CLUSTER, MASK, COORDS }; - /* ---------------------------------------------------------------------- */ ComputeClusterAtom::ComputeClusterAtom(LAMMPS *lmp, int narg, char **arg) : @@ -44,7 +42,7 @@ ComputeClusterAtom::ComputeClusterAtom(LAMMPS *lmp, int narg, char **arg) : peratom_flag = 1; size_peratom_cols = 0; - comm_forward = 3; + comm_forward = 1; nmax = 0; } @@ -117,22 +115,6 @@ void ComputeClusterAtom::compute_peratom() numneigh = list->numneigh; firstneigh = list->firstneigh; - // if update->post_integrate set: - // a dynamic group in FixGroup is invoking a variable with this compute - // thus ghost atom coords need to be up-to-date after initial_integrate() - - if (update->post_integrate) { - commflag = COORDS; - comm->forward_comm(this); - } - - // if group is dynamic, insure ghost atom masks are current - - if (group->dynamic[igroup]) { - commflag = MASK; - comm->forward_comm(this); - } - // every atom starts in its own cluster, with clusterID = atomID tagint *tag = atom->tag; @@ -153,7 +135,6 @@ void ComputeClusterAtom::compute_peratom() // iterate until no changes in my atoms // then check if any proc made changes - commflag = CLUSTER; double **x = atom->x; int change, done, anychange; @@ -203,31 +184,15 @@ void ComputeClusterAtom::compute_peratom() /* ---------------------------------------------------------------------- */ -int ComputeClusterAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, - int * /*pbc*/) +int ComputeClusterAtom::pack_forward_comm(int n, int *list, double *buf, + int /*pbc_flag*/, int * /*pbc*/) { int i, j, m; m = 0; - if (commflag == CLUSTER) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = clusterID[j]; - } - } else if (commflag == MASK) { - int *mask = atom->mask; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = ubuf(mask[j]).d; - } - } else if (commflag == COORDS) { - double **x = atom->x; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = x[j][0]; - buf[m++] = x[j][1]; - buf[m++] = x[j][2]; - } + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = clusterID[j]; } return m; @@ -241,19 +206,7 @@ void ComputeClusterAtom::unpack_forward_comm(int n, int first, double *buf) m = 0; last = first + n; - if (commflag == CLUSTER) { - for (i = first; i < last; i++) clusterID[i] = buf[m++]; - } else if (commflag == MASK) { - int *mask = atom->mask; - for (i = first; i < last; i++) mask[i] = (int) ubuf(buf[m++]).i; - } else if (commflag == COORDS) { - double **x = atom->x; - for (i = first; i < last; i++) { - x[i][0] = buf[m++]; - x[i][1] = buf[m++]; - x[i][2] = buf[m++]; - } - } + for (i = first; i < last; i++) clusterID[i] = buf[m++]; } /* ---------------------------------------------------------------------- diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index e7cd73df19..9c22f9fb62 100644 --- a/src/compute_coord_atom.cpp +++ b/src/compute_coord_atom.cpp @@ -259,14 +259,16 @@ void ComputeCoordAtom::compute_peratom() j = jlist[jj]; j &= NEIGHMASK; - jtype = type[j]; - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx * delx + dely * dely + delz * delz; - if (rsq < cutsq) { - for (m = 0; m < ncol; m++) - if (jtype >= typelo[m] && jtype <= typehi[m]) count[m] += 1.0; + if (mask[j] & jgroupbit) { + jtype = type[j]; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx * delx + dely * dely + delz * delz; + if (rsq < cutsq) { + for (m = 0; m < ncol; m++) + if (jtype >= typelo[m] && jtype <= typehi[m]) count[m] += 1.0; + } } } } @@ -309,8 +311,8 @@ void ComputeCoordAtom::compute_peratom() /* ---------------------------------------------------------------------- */ -int ComputeCoordAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, - int * /*pbc*/) +int ComputeCoordAtom::pack_forward_comm(int n, int *list, double *buf, + int /*pbc_flag*/, int * /*pbc*/) { int i, m = 0, j; for (i = 0; i < n; ++i) { diff --git a/src/compute_temp_profile.cpp b/src/compute_temp_profile.cpp index ff6bc36a08..4b8e77029b 100644 --- a/src/compute_temp_profile.cpp +++ b/src/compute_temp_profile.cpp @@ -119,6 +119,9 @@ ComputeTempProfile::ComputeTempProfile(LAMMPS *lmp, int narg, char **arg) : nbins = nbinx*nbiny*nbinz; if (nbins <= 0) error->all(FLERR,"Illegal compute temp/profile command"); + nstreaming = (xflag==0 ? 0 : 1) + (yflag==0 ? 0 : 1) + (zflag==0 ? 0 : 1); + reset_extra_dof(); + memory->create(vbin,nbins,ncount,"temp/profile:vbin"); memory->create(binave,nbins,ncount,"temp/profile:binave"); @@ -197,9 +200,10 @@ void ComputeTempProfile::dof_compute() natoms_temp = group->count(igroup); dof = domain->dimension * natoms_temp; - // subtract additional d*Nbins DOF, as in Evans and Morriss paper + // subtract additional Nbins DOF for each adjusted direction, + // as in Evans and Morriss paper - dof -= extra_dof + fix_dof + domain->dimension*nbins; + dof -= extra_dof + fix_dof + nstreaming*nbins; if (dof > 0) tfactor = force->mvv2e / (dof * force->boltz); else tfactor = 0.0; } @@ -334,14 +338,19 @@ void ComputeTempProfile::compute_array() MPI_Allreduce(tbin,tbinall,nbins,MPI_DOUBLE,MPI_SUM,world); - int nper = domain->dimension; + double totcount = 0.0; for (i = 0; i < nbins; i++) { array[i][0] = binave[i][ncount-1]; + totcount += array[i][0]; + } + double nper = domain->dimension - (extra_dof + fix_dof)/totcount; + double dofbin, tfactorbin; + for (i = 0; i < nbins; i++) { if (array[i][0] > 0.0) { - dof = nper*array[i][0] - extra_dof; - if (dof > 0) tfactor = force->mvv2e / (dof * force->boltz); - else tfactor = 0.0; - array[i][1] = tfactor*tbinall[i]; + dofbin = nper*array[i][0] - nstreaming; + if (dofbin > 0) tfactorbin = force->mvv2e / (dofbin * force->boltz); + else tfactorbin = 0.0; + array[i][1] = tfactorbin*tbinall[i]; } else array[i][1] = 0.0; } } @@ -576,6 +585,12 @@ void ComputeTempProfile::bin_assign() /* ---------------------------------------------------------------------- */ +void ComputeTempProfile::reset_extra_dof() { + extra_dof = domain->dimension - nstreaming; +} + +/* ---------------------------------------------------------------------- */ + double ComputeTempProfile::memory_usage() { double bytes = (double)maxatom * sizeof(int); diff --git a/src/compute_temp_profile.h b/src/compute_temp_profile.h index f9f2e42156..2d73781e3f 100644 --- a/src/compute_temp_profile.h +++ b/src/compute_temp_profile.h @@ -34,6 +34,7 @@ class ComputeTempProfile : public Compute { void compute_vector() override; void compute_array() override; + void reset_extra_dof() override; void remove_bias(int, double *) override; void remove_bias_thr(int, double *, double *) override; void remove_bias_all() override; @@ -47,6 +48,7 @@ class ComputeTempProfile : public Compute { int nbinx, nbiny, nbinz, nbins; int ivx, ivy, ivz; double tfactor; + double nstreaming; int box_change, triclinic; int *periodicity; diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 2632ccf597..edaa5c9866 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -14,6 +14,7 @@ #include "fix_adapt.h" +#include "angle.h" #include "atom.h" #include "bond.h" #include "domain.h" @@ -38,13 +39,14 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR,KSPACE,ATOM,BOND}; +enum{PAIR,KSPACE,ATOM,BOND,ANGLE}; enum{DIAMETER,CHARGE}; /* ---------------------------------------------------------------------- */ -FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) +FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), nadapt(0), anypair(0), anybond(0), anyangle(0), + id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) { if (narg < 5) error->all(FLERR,"Illegal fix adapt command"); nevery = utils::inumeric(FLERR,arg[3],false,lmp); @@ -75,6 +77,10 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) if (iarg+5 > narg) error->all(FLERR,"Illegal fix adapt command"); nadapt++; iarg += 5; + } else if (strcmp(arg[iarg],"angle") == 0) { + if (iarg+5 > narg) error->all(FLERR,"Illegal fix adapt command"); + nadapt++; + iarg += 5; } else break; } @@ -119,6 +125,20 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) nadapt++; iarg += 5; + } else if (strcmp(arg[iarg],"angle") == 0) { + if (iarg+5 > narg) error->all(FLERR, "Illegal fix adapt command"); + adapt[nadapt].which = ANGLE; + adapt[nadapt].angle = nullptr; + adapt[nadapt].astyle = utils::strdup(arg[iarg+1]); + adapt[nadapt].aparam = utils::strdup(arg[iarg+2]); + utils::bounds(FLERR,arg[iarg+3],1,atom->nangletypes, + adapt[nadapt].ilo,adapt[nadapt].ihi,error); + if (utils::strmatch(arg[iarg+4],"^v_")) { + adapt[nadapt].var = utils::strdup(arg[iarg+4]+2); + } else error->all(FLERR,"Illegal fix adapt command"); + nadapt++; + iarg += 5; + } else if (strcmp(arg[iarg],"kspace") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt command"); adapt[nadapt].which = KSPACE; @@ -133,12 +153,12 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) adapt[nadapt].which = ATOM; if (strcmp(arg[iarg+1],"diameter") == 0 || strcmp(arg[iarg+1],"diameter/disc") == 0) { - adapt[nadapt].aparam = DIAMETER; + adapt[nadapt].atomparam = DIAMETER; diamflag = 1; discflag = 0; if (strcmp(arg[iarg+1],"diameter/disc") == 0) discflag = 1; } else if (strcmp(arg[iarg+1],"charge") == 0) { - adapt[nadapt].aparam = CHARGE; + adapt[nadapt].atomparam = CHARGE; chgflag = 1; } else error->all(FLERR,"Illegal fix adapt command"); if (utils::strmatch(arg[iarg+2],"^v_")) { @@ -191,6 +211,13 @@ nadapt(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) for (int m = 0; m < nadapt; ++m) if (adapt[m].which == BOND) memory->create(adapt[m].vector_orig,n+1,"adapt:vector_orig"); + + // allocate angle style arrays: + + n = atom->nbondtypes; + for (int m = 0; m < nadapt; ++m) + if (adapt[m].which == ANGLE) + memory->create(adapt[m].vector_orig,n+1,"adapt:vector_orig"); } /* ---------------------------------------------------------------------- */ @@ -207,6 +234,10 @@ FixAdapt::~FixAdapt() delete [] adapt[m].bstyle; delete [] adapt[m].bparam; memory->destroy(adapt[m].vector_orig); + } else if (adapt[m].which == ANGLE) { + delete [] adapt[m].astyle; + delete [] adapt[m].aparam; + memory->destroy(adapt[m].vector_orig); } } delete [] adapt; @@ -299,6 +330,7 @@ void FixAdapt::init() anypair = 0; anybond = 0; + anyangle = 0; for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; @@ -357,6 +389,7 @@ void FixAdapt::init() } delete [] pstyle; + } else if (ad->which == BOND) { ad->bond = nullptr; anybond = 1; @@ -383,13 +416,39 @@ void FixAdapt::init() delete [] bstyle; + } else if (ad->which == ANGLE) { + ad->angle = nullptr; + anyangle = 1; + + char *astyle = utils::strdup(ad->astyle); + if (lmp->suffix_enable) + ad->angle = force->angle_match(fmt::format("{}/{}",astyle,lmp->suffix)); + + if (ad->angle == nullptr) ad->angle = force->angle_match(astyle); + if (ad->angle == nullptr ) + error->all(FLERR,"Fix adapt angle style does not exist"); + + void *ptr = ad->angle->extract(ad->aparam,ad->bdim); + + if (ptr == nullptr) + error->all(FLERR,"Fix adapt angle style param not supported"); + + // for angle styles, use a vector + + if (ad->adim == 1) ad->vector = (double *) ptr; + + if (utils::strmatch(force->angle_style,"^hybrid")) + error->all(FLERR,"Fix adapt does not support angle_style hybrid"); + + delete [] astyle; + } else if (ad->which == KSPACE) { if (force->kspace == nullptr) error->all(FLERR,"Fix adapt kspace style does not exist"); kspace_scale = (double *) force->kspace->extract("scale"); } else if (ad->which == ATOM) { - if (ad->aparam == DIAMETER) { + if (ad->atomparam == DIAMETER) { if (!atom->radius_flag) error->all(FLERR,"Fix adapt requires atom attribute diameter"); if (!atom->rmass_flag) @@ -398,7 +457,7 @@ void FixAdapt::init() error->all(FLERR,"Fix adapt requires 2d simulation"); if (!restart_reset) previous_diam_scale = 1.0; } - if (ad->aparam == CHARGE) { + if (ad->atomparam == CHARGE) { if (!atom->q_flag) error->all(FLERR,"Fix adapt requires atom attribute charge"); if (!restart_reset) previous_chg_scale = 1.0; @@ -408,7 +467,7 @@ void FixAdapt::init() if (restart_reset) restart_reset = 0; - // make copy of original pair/bond array values + // make copy of original pair/bond/angle array values for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; @@ -422,6 +481,10 @@ void FixAdapt::init() } else if (ad->which == BOND && ad->bdim == 1) { for (i = ad->ilo; i <= ad->ihi; ++i ) ad->vector_orig[i] = ad->vector[i]; + + } else if (ad->which == ANGLE && ad->adim == 1) { + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector_orig[i] = ad->vector[i]; } } @@ -483,7 +546,7 @@ void FixAdapt::post_run() } /* ---------------------------------------------------------------------- - change pair,kspace,atom parameters based on variable evaluation + change pair,bond,angle,kspace,atom parameters based on variable evaluation ------------------------------------------------------------------------- */ void FixAdapt::change_settings() @@ -527,6 +590,18 @@ void FixAdapt::change_settings() ad->vector[i] = value; } + // set angle type array values: + + } else if (ad->which == ANGLE) { + if (ad->adim == 1) { + if (scaleflag) + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector[i] = value*ad->vector_orig[i]; + else + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector[i] = value; + } + // set kspace scale factor } else if (ad->which == KSPACE) { @@ -540,7 +615,7 @@ void FixAdapt::change_settings() // also reset rmass to new value assuming density remains constant // for scaleflag, previous_diam_scale is the scale factor on previous step - if (ad->aparam == DIAMETER) { + if (ad->atomparam == DIAMETER) { double scale; double *radius = atom->radius; double *rmass = atom->rmass; @@ -567,7 +642,7 @@ void FixAdapt::change_settings() // reset charge to new value, for both owned and ghost atoms // for scaleflag, previous_chg_scale is the scale factor on previous step - } else if (ad->aparam == CHARGE) { + } else if (ad->atomparam == CHARGE) { double scale; double *q = atom->q; int *mask = atom->mask; @@ -591,7 +666,7 @@ void FixAdapt::change_settings() modify->addstep_compute(update->ntimestep + nevery); // re-initialize pair styles if any PAIR settings were changed - // ditto for bond styles if any BOND settings were changed + // ditto for bond/angle styles if any BOND/ANGLE settings were changed // this resets other coeffs that may depend on changed values, // and also offset and tail corrections // we must call force->pair->reinit() instead of the individual @@ -601,6 +676,7 @@ void FixAdapt::change_settings() if (anypair) force->pair->reinit(); if (anybond) force->bond->reinit(); + if (anyangle) force->angle->reinit(); // reset KSpace charges if charges have changed @@ -624,7 +700,13 @@ void FixAdapt::restore_settings() } } else if (ad->which == BOND) { - if (ad->pdim == 1) { + if (ad->bdim == 1) { + for (int i = ad->ilo; i <= ad->ihi; i++) + ad->vector[i] = ad->vector_orig[i]; + } + + } else if (ad->which == ANGLE) { + if (ad->adim == 1) { for (int i = ad->ilo; i <= ad->ihi; i++) ad->vector[i] = ad->vector_orig[i]; } @@ -668,6 +750,7 @@ void FixAdapt::restore_settings() if (anypair) force->pair->reinit(); if (anybond) force->bond->reinit(); + if (anyangle) force->angle->reinit(); if (chgflag && force->kspace) force->kspace->qsum_qsq(); } diff --git a/src/fix_adapt.h b/src/fix_adapt.h index 939f46f8a2..121ef06ece 100644 --- a/src/fix_adapt.h +++ b/src/fix_adapt.h @@ -45,7 +45,7 @@ class FixAdapt : public Fix { private: int nadapt, resetflag, scaleflag, massflag; - int anypair, anybond; + int anypair, anybond, anyangle; int nlevels_respa; char *id_fix_diam, *id_fix_chg; class FixStore *fix_diam, *fix_chg; @@ -57,14 +57,16 @@ class FixAdapt : public Fix { char *var; char *pstyle, *pparam; char *bstyle, *bparam; + char *astyle, *aparam; int ilo, ihi, jlo, jhi; - int pdim, bdim; + int pdim, bdim, adim; double *scalar, scalar_orig; double *vector, *vector_orig; double **array, **array_orig; - int aparam; + int atomparam; class Pair *pair; class Bond *bond; + class Angle *angle; }; Adapt *adapt; diff --git a/src/fix_bond_history.h b/src/fix_bond_history.h index 511bc57bd2..9ac5a9e393 100644 --- a/src/fix_bond_history.h +++ b/src/fix_bond_history.h @@ -41,7 +41,7 @@ class FixBondHistory : public Fix { double memory_usage() override; void write_restart(FILE *fp) override; void restart(char *buf) override; - void set_arrays(int); + void set_arrays(int) override; void update_atom_value(int, int, int, double); double get_atom_value(int, int, int); diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 1291721f0a..0a31b97f5f 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -44,6 +44,8 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) gbit = group->bitmask[group->find(dgroupid)]; gbitinverse = group->inversemask[group->find(dgroupid)]; + comm_forward = 1; + // process optional args regionflag = 0; @@ -106,8 +108,6 @@ FixGroup::~FixGroup() int FixGroup::setmask() { int mask = 0; - mask |= POST_INTEGRATE; - mask |= POST_INTEGRATE_RESPA; return mask; } @@ -147,29 +147,6 @@ void FixGroup::init() if (iprop < 0 || cols) error->all(FLERR,"Group dynamic command custom property vector does not exist"); } - - // warn if any FixGroup is not at tail end of all post_integrate fixes - - Fix **fix = modify->fix; - int *fmask = modify->fmask; - int nfix = modify->nfix; - - int n = 0; - for (int i = 0; i < nfix; i++) if (POST_INTEGRATE & fmask[i]) n++; - int warn = 0; - for (int i = 0; i < nfix; i++) { - if (POST_INTEGRATE & fmask[i]) { - for (int j = i+1; j < nfix; j++) { - if (POST_INTEGRATE & fmask[j]) { - if (strstr(fix[j]->id,"GROUP_") != fix[j]->id) warn = 1; - } - } - } - } - - if (warn && comm->me == 0) - error->warning(FLERR,"One or more dynamic groups may not be " - "updated at correct point in timestep"); } /* ---------------------------------------------------------------------- @@ -183,7 +160,7 @@ void FixGroup::setup(int /*vflag*/) /* ---------------------------------------------------------------------- */ -void FixGroup::post_integrate() +void FixGroup::post_force(int /*vflag*/) { // only assign atoms to group on steps that are multiples of nevery @@ -192,9 +169,9 @@ void FixGroup::post_integrate() /* ---------------------------------------------------------------------- */ -void FixGroup::post_integrate_respa(int ilevel, int /*iloop*/) +void FixGroup::post_force_respa(int vflag, int ilevel, int /*iloop*/) { - if (ilevel == nlevels_respa-1) post_integrate(); + if (ilevel == nlevels_respa-1) post_force(vflag); } /* ---------------------------------------------------------------------- */ @@ -204,22 +181,20 @@ void FixGroup::set_group() int nlocal = atom->nlocal; // invoke atom-style variable if defined - // set post_integrate flag to 1, then unset after - // this is for any compute to check if it needs to - // operate differently due to invocation this early in timestep - // e.g. perform ghost comm update due to atoms having just moved + // NOTE: after variable invocation could reset invoked computes to not-invoked + // this would avoid an issue where other post-force fixes + // change the compute result since it will not be re-invoked at end-of-step, + // e.g. if compute pe/atom includes pe contributions from fixes double *var = nullptr; int *ivector = nullptr; double *dvector = nullptr; if (varflag) { - update->post_integrate = 1; modify->clearstep_compute(); - memory->create(var,nlocal,"fix/group:varvalue"); + memory->create(var,nlocal,"fix/group:var"); input->variable->compute_atom(ivar,igroup,var,1,0); modify->addstep_compute(update->ntimestep + nevery); - update->post_integrate = 0; } // set ptr to custom atom vector @@ -233,8 +208,6 @@ void FixGroup::set_group() // set mask for each atom // only in group if in parent group, in region, variable is non-zero - // if compute, fix, etc needs updated masks of ghost atoms, - // it must do forward_comm() to update them double **x = atom->x; int *mask = atom->mask; @@ -256,6 +229,42 @@ void FixGroup::set_group() } if (varflag) memory->destroy(var); + + // insure ghost atom masks are also updated + + comm->forward_comm(this); +} + +/* ---------------------------------------------------------------------- */ + +int FixGroup::pack_forward_comm(int n, int *list, double *buf, + int /*pbc_flag*/, int * /*pbc*/) +{ + int i, j, m; + + int *mask = atom->mask; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = ubuf(mask[j]).d; + } + + return m; +} + +/* ---------------------------------------------------------------------- */ + +void FixGroup::unpack_forward_comm(int n, int first, double *buf) +{ + int i, m, last; + + m = 0; + last = first + n; + + int *mask = atom->mask; + + for (i = first; i < last; i++) mask[i] = (int) ubuf(buf[m++]).i; } /* ---------------------------------------------------------------------- */ diff --git a/src/fix_group.h b/src/fix_group.h index ffa2afcfc3..e4c4c9bd32 100644 --- a/src/fix_group.h +++ b/src/fix_group.h @@ -31,8 +31,10 @@ class FixGroup : public Fix { int setmask() override; void init() override; void setup(int) override; - void post_integrate() override; - void post_integrate_respa(int, int) override; + void post_force(int) override; + void post_force_respa(int, int, int) override; + int pack_forward_comm(int, int *, double *, int, int *) override; + void unpack_forward_comm(int, int, double *) override; void *extract(const char *, int &) override; private: diff --git a/src/fmt/core.h b/src/fmt/core.h index b7f9a960c6..8444cd9546 100644 --- a/src/fmt/core.h +++ b/src/fmt/core.h @@ -429,7 +429,9 @@ template inline auto convert_for_visit(T) -> monostate { template FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned::type { - FMT_ASSERT(value >= 0, "negative value"); + // LAMMPS CUSTOMIZATION + // FMT_ASSERT(value >= 0, "negative value"); + // END LAMMPS CUSTOMIZATION return static_cast::type>(value); } diff --git a/src/modify.cpp b/src/modify.cpp index 7554079e2a..6e7e16d2b8 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -51,20 +51,22 @@ Modify::Modify(LAMMPS *lmp) : Pointers(lmp) nfix = maxfix = 0; n_initial_integrate = n_post_integrate = 0; n_pre_exchange = n_pre_neighbor = n_post_neighbor = 0; - n_pre_force = n_pre_reverse = n_post_force = 0; + n_pre_force = n_pre_reverse = n_post_force_any = 0; n_final_integrate = n_end_of_step = 0; n_energy_couple = n_energy_global = n_energy_atom = 0; n_initial_integrate_respa = n_post_integrate_respa = 0; - n_pre_force_respa = n_post_force_respa = n_final_integrate_respa = 0; + n_pre_force_respa = n_post_force_respa_any = n_final_integrate_respa = 0; n_min_pre_exchange = n_min_pre_force = n_min_pre_reverse = 0; n_min_post_force = n_min_energy = 0; + n_timeflag = -1; fix = nullptr; fmask = nullptr; list_initial_integrate = list_post_integrate = nullptr; list_pre_exchange = list_pre_neighbor = list_post_neighbor = nullptr; - list_pre_force = list_pre_reverse = list_post_force = nullptr; + list_pre_force = list_pre_reverse = nullptr; + list_post_force = list_post_force_group = nullptr; list_final_integrate = list_end_of_step = nullptr; list_energy_couple = list_energy_global = list_energy_atom = nullptr; list_initial_integrate_respa = list_post_integrate_respa = nullptr; @@ -139,6 +141,7 @@ Modify::~Modify() delete[] list_pre_force; delete[] list_pre_reverse; delete[] list_post_force; + delete[] list_post_force_group; delete[] list_final_integrate; delete[] list_end_of_step; delete[] list_energy_couple; @@ -221,6 +224,7 @@ void Modify::init() list_init(PRE_FORCE, n_pre_force, list_pre_force); list_init(PRE_REVERSE, n_pre_reverse, list_pre_reverse); list_init(POST_FORCE, n_post_force, list_post_force); + list_init_post_force_group(n_post_force_group, list_post_force_group); list_init(FINAL_INTEGRATE, n_final_integrate, list_final_integrate); list_init_end_of_step(END_OF_STEP, n_end_of_step, list_end_of_step); list_init_energy_couple(n_energy_couple, list_energy_couple); @@ -241,6 +245,11 @@ void Modify::init() list_init(MIN_POST_FORCE, n_min_post_force, list_min_post_force); list_init(MIN_ENERGY, n_min_energy, list_min_energy); + // two post_force_any counters used by integrators add in post_force_group + + n_post_force_any = n_post_force + n_post_force_group; + n_post_force_respa_any = n_post_force_respa + n_post_force_group; + // create list of computes that store invocation times list_init_compute(); @@ -441,11 +450,21 @@ void Modify::pre_reverse(int eflag, int vflag) /* ---------------------------------------------------------------------- post_force call, only for relevant fixes + first call any instances of fix GROUP if they exist + they are not in n_post_force count ------------------------------------------------------------------------- */ void Modify::post_force(int vflag) { - for (int i = 0; i < n_post_force; i++) fix[list_post_force[i]]->post_force(vflag); + if (n_post_force_group) { + for (int i = 0; i < n_post_force_group; i++) + fix[list_post_force_group[i]]->post_force(vflag); + } + + if (n_post_force) { + for (int i = 0; i < n_post_force; i++) + fix[list_post_force[i]]->post_force(vflag); + } } /* ---------------------------------------------------------------------- @@ -585,12 +604,20 @@ void Modify::pre_force_respa(int vflag, int ilevel, int iloop) /* ---------------------------------------------------------------------- rRESPA post_force call, only for relevant fixes + first call any instances of fix GROUP if they exist ------------------------------------------------------------------------- */ void Modify::post_force_respa(int vflag, int ilevel, int iloop) { - for (int i = 0; i < n_post_force_respa; i++) - fix[list_post_force_respa[i]]->post_force_respa(vflag, ilevel, iloop); + if (n_post_force_group) { + for (int i = 0; i < n_post_force_group; i++) + fix[list_post_force_group[i]]->post_force_respa(vflag, ilevel, iloop); + } + + if (n_post_force_respa) { + for (int i = 0; i < n_post_force_respa; i++) + fix[list_post_force_respa[i]]->post_force_respa(vflag, ilevel, iloop); + } } /* ---------------------------------------------------------------------- @@ -1716,6 +1743,26 @@ void Modify::list_init_energy_atom(int &n, int *&list) if (fix[i]->energy_peratom_flag && fix[i]->thermo_energy) list[n++] = i; } +/* ---------------------------------------------------------------------- + create list of fix indices for fix GROUP + are invoked first in post_force() or post_force_respa() +------------------------------------------------------------------------- */ + +void Modify::list_init_post_force_group(int &n, int *&list) +{ + delete[] list; + + n = 0; + for (int i = 0; i < nfix; i++) + if (strcmp(fix[i]->style,"GROUP") == 0) n++; + list = new int[n]; + + n = 0; + for (int i = 0; i < nfix; i++) + if (strcmp(fix[i]->style,"GROUP") == 0) + list[n++] = i; +} + /* ---------------------------------------------------------------------- create list of compute indices for computes which store invocation times ------------------------------------------------------------------------- */ diff --git a/src/modify.h b/src/modify.h index df8e52752f..5e05cfce6a 100644 --- a/src/modify.h +++ b/src/modify.h @@ -33,11 +33,11 @@ class Modify : protected Pointers { public: int n_initial_integrate, n_post_integrate, n_pre_exchange; int n_pre_neighbor, n_post_neighbor; - int n_pre_force, n_pre_reverse, n_post_force; + int n_pre_force, n_pre_reverse, n_post_force_any; int n_final_integrate, n_end_of_step; int n_energy_couple, n_energy_global, n_energy_atom; int n_initial_integrate_respa, n_post_integrate_respa; - int n_pre_force_respa, n_post_force_respa, n_final_integrate_respa; + int n_pre_force_respa, n_post_force_respa_any, n_final_integrate_respa; int n_min_pre_exchange, n_min_pre_neighbor, n_min_post_neighbor; int n_min_pre_force, n_min_pre_reverse, n_min_post_force, n_min_energy; @@ -147,11 +147,16 @@ class Modify : protected Pointers { double memory_usage(); protected: + // internal fix counts + + int n_post_force, n_post_force_group, n_post_force_respa; + // lists of fixes to apply at different stages of timestep int *list_initial_integrate, *list_post_integrate; int *list_pre_exchange, *list_pre_neighbor, *list_post_neighbor; - int *list_pre_force, *list_pre_reverse, *list_post_force; + int *list_pre_force, *list_pre_reverse; + int *list_post_force, *list_post_force_group; int *list_final_integrate, *list_end_of_step; int *list_energy_couple, *list_energy_global, *list_energy_atom; int *list_initial_integrate_respa, *list_post_integrate_respa; @@ -187,6 +192,8 @@ class Modify : protected Pointers { void list_init_energy_couple(int &, int *&); void list_init_energy_global(int &, int *&); void list_init_energy_atom(int &, int *&); + void list_init_post_force_group(int &, int *&); + void list_init_post_force_respa_group(int &, int *&); void list_init_dofflag(int &, int *&); void list_init_compute(); diff --git a/src/read_data.cpp b/src/read_data.cpp index 5505b5a5a0..b77394bcb3 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -744,9 +744,9 @@ void ReadData::command(int narg, char **arg) break; } if (i == nfix) - error->all(FLERR,"Unknown identifier in data file: {}",keyword); + error->all(FLERR,"Unknown identifier in data file: {}{}", keyword, utils::errorurl(1)); - } else error->all(FLERR,"Unknown identifier in data file: {}",keyword); + } else error->all(FLERR,"Unknown identifier in data file: {}{}", keyword, utils::errorurl(1)); parse_keyword(0); } diff --git a/src/read_restart.cpp b/src/read_restart.cpp index dea062ed87..645f0c1d6d 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -118,6 +118,10 @@ void ReadRestart::command(int narg, char **arg) format_revision(); check_eof_magic(); + if ((comm->me == 0) && (modify->get_fix_by_style("property/atom").size() > 0)) + error->warning(FLERR, "Fix property/atom command must be specified after read_restart " + "to restore its data."); + // read header info which creates simulation box header(); diff --git a/src/respa.cpp b/src/respa.cpp index 97356eac47..b99aedecf3 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -372,7 +372,7 @@ void Respa::setup(int flag) mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); mesg += "\n r-RESPA fixes :"; - for (int l = 0; l < modify->n_post_force_respa; ++l) { + for (int l = 0; l < modify->n_post_force_respa_any; ++l) { Fix *f = modify->get_fix_by_index(modify->list_post_force_respa[l]); if (f->respa_level >= 0) mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); @@ -704,7 +704,8 @@ void Respa::recurse(int ilevel) timer->stamp(Timer::COMM); } timer->stamp(); - if (modify->n_post_force_respa) modify->post_force_respa(vflag, ilevel, iloop); + if (modify->n_post_force_respa_any) + modify->post_force_respa(vflag, ilevel, iloop); modify->final_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); } diff --git a/src/update.cpp b/src/update.cpp index 3870f6d38e..297053e39d 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -60,7 +60,6 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) beginstep = endstep = 0; restrict_output = 0; setupflag = 0; - post_integrate = 0; multireplica = 0; eflag_global = vflag_global = -1; diff --git a/src/update.h b/src/update.h index afcafb87cb..c3e79b72a2 100644 --- a/src/update.h +++ b/src/update.h @@ -35,7 +35,6 @@ class Update : protected Pointers { int max_eval; // max force evaluations for minimizer int restrict_output; // 1 if output should not write dump/restart int setupflag; // set when setup() is computing forces - int post_integrate; // 1 if now at post_integrate() in timestep int multireplica; // 1 if min across replicas, else 0 int dt_default; // 1 if dt is at default value, else 0 diff --git a/src/utils.cpp b/src/utils.cpp index a8e1b14104..0d0bc91227 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -22,8 +22,8 @@ #include "memory.h" #include "modify.h" #include "text_file_reader.h" -#include "update.h" #include "universe.h" +#include "update.h" #include #include @@ -137,11 +137,16 @@ void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_ar } } +std::string utils::errorurl(int errorcode) +{ + return fmt::format("\nFor more information see https://docs.lammps.org/err{:04d}", errorcode); +} + void utils::flush_buffers(LAMMPS *lmp) { if (lmp->screen) fflush(lmp->screen); if (lmp->logfile) fflush(lmp->logfile); - if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); + if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile); } @@ -805,7 +810,7 @@ std::string utils::star_subst(const std::string &name, bigint step, int pad) auto star = name.find('*'); if (star == std::string::npos) return name; - return fmt::format("{}{:0{}}{}",name.substr(0,star),step,pad,name.substr(star+1)); + return fmt::format("{}{:0{}}{}", name.substr(0, star), step, pad, name.substr(star + 1)); } /* ---------------------------------------------------------------------- diff --git a/src/utils.h b/src/utils.h index 86f31508e7..4dbb2fb8bb 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,7 +21,7 @@ #include -#include // IWYU pragma: export +#include // IWYU pragma: export namespace LAMMPS_NS { @@ -74,6 +74,18 @@ namespace utils { void logmesg(LAMMPS *lmp, const std::string &mesg); + /*! Return text redirecting the user to a specific paragraph in the manual + * + * The LAMMPS manual contains detailed detailed explanations for errors and + * warnings where a simple error message may not be sufficient. These can + * be reached through URLs with a numeric code. This function creates the + * corresponding text to be included into the error message that redirects + * the user to that URL. + * + * \param errorcode number pointing to a paragraph in the manual */ + + std::string errorurl(int errorcode); + /*! Flush output buffers * * This function calls fflush() on screen and logfile FILE pointers diff --git a/src/verlet.cpp b/src/verlet.cpp index 342dc3d951..15e1ab0800 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -237,7 +237,7 @@ void Verlet::run(int n) int n_post_neighbor = modify->n_post_neighbor; int n_pre_force = modify->n_pre_force; int n_pre_reverse = modify->n_pre_reverse; - int n_post_force = modify->n_post_force; + int n_post_force_any = modify->n_post_force_any; int n_end_of_step = modify->n_end_of_step; if (atom->sortfreq > 0) sortflag = 1; @@ -344,7 +344,7 @@ void Verlet::run(int n) // force modifications, final time integration, diagnostics - if (n_post_force) modify->post_force(vflag); + if (n_post_force_any) modify->post_force(vflag); modify->final_integrate(); if (n_end_of_step) modify->end_of_step(); timer->stamp(Timer::MODIFY); diff --git a/tools/singularity/ubuntu16.04.def b/tools/singularity/ubuntu16.04.def index 35e4e26138..f22826cabd 100644 --- a/tools/singularity/ubuntu16.04.def +++ b/tools/singularity/ubuntu16.04.def @@ -14,7 +14,7 @@ From: ubuntu:16.04 libfftw3-dev libjpeg-dev libpng12-dev libblas-dev liblapack-dev \ python-dev libeigen3-dev libgsl-dev libopenblas-dev libreadline-dev \ virtualenv python3-dev python3-pip python3-pkg-resources \ - python3-setuptools python3-virtualenv \ + python3-setuptools python3-virtualenv python3-venv \ enchant # create missing readline pkgconfig file diff --git a/tools/singularity/ubuntu18.04.def b/tools/singularity/ubuntu18.04.def index ebea335d6b..456d3add56 100644 --- a/tools/singularity/ubuntu18.04.def +++ b/tools/singularity/ubuntu18.04.def @@ -107,7 +107,7 @@ From: ubuntu:18.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu18.04_amd_rocm.def b/tools/singularity/ubuntu18.04_amd_rocm.def index f1d327052d..e2a9adc9d9 100644 --- a/tools/singularity/ubuntu18.04_amd_rocm.def +++ b/tools/singularity/ubuntu18.04_amd_rocm.def @@ -137,7 +137,7 @@ From: ubuntu:18.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu18.04_gpu.def b/tools/singularity/ubuntu18.04_gpu.def index 452a3eaee8..6aa37ccf84 100644 --- a/tools/singularity/ubuntu18.04_gpu.def +++ b/tools/singularity/ubuntu18.04_gpu.def @@ -174,7 +174,7 @@ From: ubuntu:18.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu18.04_intel_opencl.def b/tools/singularity/ubuntu18.04_intel_opencl.def index fd7363dbae..1f7c136fac 100644 --- a/tools/singularity/ubuntu18.04_intel_opencl.def +++ b/tools/singularity/ubuntu18.04_intel_opencl.def @@ -108,7 +108,7 @@ From: ubuntu:18.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu18.04_nvidia.def b/tools/singularity/ubuntu18.04_nvidia.def index f834e1a91e..70f41708de 100644 --- a/tools/singularity/ubuntu18.04_nvidia.def +++ b/tools/singularity/ubuntu18.04_nvidia.def @@ -107,7 +107,7 @@ From: nvidia/cuda:11.4.2-devel-ubuntu18.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04.def b/tools/singularity/ubuntu20.04.def index 53690fd1b9..5665546eda 100644 --- a/tools/singularity/ubuntu20.04.def +++ b/tools/singularity/ubuntu20.04.def @@ -52,6 +52,7 @@ From: ubuntu:20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ texlive \ @@ -101,7 +102,7 @@ From: ubuntu:20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04_amd_rocm.def b/tools/singularity/ubuntu20.04_amd_rocm.def index e52ff02798..21f1ecc77b 100644 --- a/tools/singularity/ubuntu20.04_amd_rocm.def +++ b/tools/singularity/ubuntu20.04_amd_rocm.def @@ -82,6 +82,7 @@ From: ubuntu:20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ vim-nox \ @@ -122,7 +123,7 @@ From: ubuntu:20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04_gpu.def b/tools/singularity/ubuntu20.04_gpu.def index abb43f46df..23bddeb14f 100644 --- a/tools/singularity/ubuntu20.04_gpu.def +++ b/tools/singularity/ubuntu20.04_gpu.def @@ -87,6 +87,7 @@ From: ubuntu:20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ vim-nox \ @@ -160,7 +161,7 @@ From: ubuntu:20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04_intel_opencl.def b/tools/singularity/ubuntu20.04_intel_opencl.def index 0e3cae67d7..c02d2cd3a4 100644 --- a/tools/singularity/ubuntu20.04_intel_opencl.def +++ b/tools/singularity/ubuntu20.04_intel_opencl.def @@ -52,6 +52,7 @@ From: ubuntu:20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ vim-nox \ @@ -100,7 +101,7 @@ From: ubuntu:20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04_nvidia.def b/tools/singularity/ubuntu20.04_nvidia.def index 274efecadc..e0995301f4 100644 --- a/tools/singularity/ubuntu20.04_nvidia.def +++ b/tools/singularity/ubuntu20.04_nvidia.def @@ -55,6 +55,7 @@ From: nvidia/cuda:11.4.2-devel-ubuntu20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ vim-nox \ @@ -102,7 +103,7 @@ From: nvidia/cuda:11.4.2-devel-ubuntu20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/tools/singularity/ubuntu20.04_oneapi.def b/tools/singularity/ubuntu20.04_oneapi.def index e5077fe184..a5d59efbc5 100644 --- a/tools/singularity/ubuntu20.04_oneapi.def +++ b/tools/singularity/ubuntu20.04_oneapi.def @@ -51,6 +51,7 @@ From: ubuntu:20.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ + python3-venv \ rsync \ ssh \ texlive \ @@ -139,7 +140,7 @@ From: ubuntu:20.04 # Plumed ########################################################################### - export PLUMED_PKG_VERSION=2.7.3 + export PLUMED_PKG_VERSION=2.7.4 mkdir plumed cd plumed diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index a166ad792a..40ef8204aa 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -20,6 +20,12 @@ add_library(GTest::GMock ALIAS gmock) add_library(GTest::GTestMain ALIAS gtest_main) add_library(GTest::GMockMain ALIAS gmock_main) +# import +foreach(_FLAG ${CMAKE_TUNE_FLAGS}) + add_compile_options(${_FLAG}) +endforeach() + + ######################################## # General tests using the LAMMPS executable itself ######################################## diff --git a/unittest/commands/test_compute_global.cpp b/unittest/commands/test_compute_global.cpp index 1c9be99ba4..e21acdbca0 100644 --- a/unittest/commands/test_compute_global.cpp +++ b/unittest/commands/test_compute_global.cpp @@ -102,24 +102,24 @@ TEST_F(ComputeGlobalTest, Energy) EXPECT_DOUBLE_EQ(get_scalar("pe1"), 24155.155261642241); EXPECT_DOUBLE_EQ(get_scalar("pe2"), 361.37528652881286); EXPECT_DOUBLE_EQ(get_scalar("pe3"), 0.0); - EXPECT_DOUBLE_EQ(get_scalar("pr1"), 1956948.4735454607); - EXPECT_DOUBLE_EQ(get_scalar("pr2"), 1956916.7725807722); + EXPECT_NEAR(get_scalar("pr1"), 1956948.4735454607, 0.0000000005); + EXPECT_NEAR(get_scalar("pr2"), 1956916.7725807722, 0.0000000005); EXPECT_DOUBLE_EQ(get_scalar("pr3"), 0.0); auto pr1 = get_vector("pr1"); auto pr2 = get_vector("pr2"); auto pr3 = get_vector("pr3"); - EXPECT_DOUBLE_EQ(pr1[0], 2150600.9207200543); - EXPECT_DOUBLE_EQ(pr1[1], 1466949.7512112649); - EXPECT_DOUBLE_EQ(pr1[2], 2253294.7487050635); - EXPECT_DOUBLE_EQ(pr1[3], 856643.16926486336); - EXPECT_DOUBLE_EQ(pr1[4], 692710.86929464422); - EXPECT_DOUBLE_EQ(pr1[5], -44403.909298603547); - EXPECT_DOUBLE_EQ(pr2[0], 2150575.6989334146); - EXPECT_DOUBLE_EQ(pr2[1], 1466911.3911461537); - EXPECT_DOUBLE_EQ(pr2[2], 2253263.2276627473); - EXPECT_DOUBLE_EQ(pr2[3], 856632.34707690508); - EXPECT_DOUBLE_EQ(pr2[4], 692712.89222328411); - EXPECT_DOUBLE_EQ(pr2[5], -44399.277068014424); + EXPECT_NEAR(pr1[0], 2150600.9207200543, 0.0000000005); + EXPECT_NEAR(pr1[1], 1466949.7512112649, 0.0000000005); + EXPECT_NEAR(pr1[2], 2253294.7487050635, 0.0000000005); + EXPECT_NEAR(pr1[3], 856643.16926486336, 0.0000000005); + EXPECT_NEAR(pr1[4], 692710.86929464422, 0.0000000005); + EXPECT_NEAR(pr1[5], -44403.909298603547, 0.0000000005); + EXPECT_NEAR(pr2[0], 2150575.6989334146, 0.0000000005); + EXPECT_NEAR(pr2[1], 1466911.3911461537, 0.0000000005); + EXPECT_NEAR(pr2[2], 2253263.2276627473, 0.0000000005); + EXPECT_NEAR(pr2[3], 856632.34707690508, 0.0000000005); + EXPECT_NEAR(pr2[4], 692712.89222328411, 0.0000000005); + EXPECT_NEAR(pr2[5], -44399.277068014424, 0.0000000005); EXPECT_DOUBLE_EQ(pr3[0], 0.0); EXPECT_DOUBLE_EQ(pr3[1], 0.0); EXPECT_DOUBLE_EQ(pr3[2], 0.0); diff --git a/unittest/force-styles/tests/angle-cosine.yaml b/unittest/force-styles/tests/angle-cosine.yaml index 5a59fcce86..43629712d4 100644 --- a/unittest/force-styles/tests/angle-cosine.yaml +++ b/unittest/force-styles/tests/angle-cosine.yaml @@ -16,7 +16,8 @@ angle_coeff: ! | 3 50.0 4 100.0 equilibrium: 4 3.141592653589793 3.141592653589793 3.141592653589793 3.141592653589793 -extract: ! "" +extract: ! | + k 1 natoms: 29 init_energy: 1347.8670856939623 init_stress: ! |2- diff --git a/unittest/force-styles/tests/angle-harmonic.yaml b/unittest/force-styles/tests/angle-harmonic.yaml index dee700aa2c..d2164af8c5 100644 --- a/unittest/force-styles/tests/angle-harmonic.yaml +++ b/unittest/force-styles/tests/angle-harmonic.yaml @@ -16,7 +16,9 @@ angle_coeff: ! | 3 50.0 120.0 4 100.0 108.5 equilibrium: 4 1.9216075064457567 1.9373154697137058 2.0943951023931953 1.8936822384138476 -extract: ! "" +extract: ! | + k 1 + theta0 1 natoms: 29 init_energy: 41.53081789649104 init_stress: ! |2- diff --git a/unittest/force-styles/tests/bond-fene.yaml b/unittest/force-styles/tests/bond-fene.yaml index 88c02574cb..e5077eda0e 100644 --- a/unittest/force-styles/tests/bond-fene.yaml +++ b/unittest/force-styles/tests/bond-fene.yaml @@ -18,7 +18,7 @@ bond_coeff: ! | 5 450 2 0.018 1 equilibrium: 5 1.455 1.067 1.261 1.164 0.97 extract: ! | - kappa 1 + k 1 r0 1 natoms: 29 init_energy: 7104.900486467235 diff --git a/unittest/force-styles/tests/bond-fene_nm.yaml b/unittest/force-styles/tests/bond-fene_nm.yaml index c6be31a1c3..892d26c7aa 100644 --- a/unittest/force-styles/tests/bond-fene_nm.yaml +++ b/unittest/force-styles/tests/bond-fene_nm.yaml @@ -18,7 +18,7 @@ bond_coeff: ! | 5 450 2 0.018 1 12 6 equilibrium: 5 1.455 1.067 1.261 1.164 0.97 extract: ! | - kappa 1 + k 1 r0 1 natoms: 29 init_energy: 7104.538647187164 diff --git a/unittest/force-styles/tests/bond-gromos.yaml b/unittest/force-styles/tests/bond-gromos.yaml index a2f7e7ef3e..18abc99a3c 100644 --- a/unittest/force-styles/tests/bond-gromos.yaml +++ b/unittest/force-styles/tests/bond-gromos.yaml @@ -18,7 +18,7 @@ bond_coeff: ! | 5 450.0 1.0 equilibrium: 5 1.5 1.1 1.3 1.2 1 extract: ! | - kappa 1 + k 1 r0 1 natoms: 29 init_energy: 33.70930417641326 diff --git a/unittest/force-styles/tests/bond-harmonic.yaml b/unittest/force-styles/tests/bond-harmonic.yaml index 9ee14c07b9..bf686558d7 100644 --- a/unittest/force-styles/tests/bond-harmonic.yaml +++ b/unittest/force-styles/tests/bond-harmonic.yaml @@ -18,7 +18,7 @@ bond_coeff: ! | 5 450.0 1.0 equilibrium: 5 1.5 1.1 1.3 1.2 1 extract: ! | - kappa 1 + k 1 r0 1 natoms: 29 init_energy: 4.789374024601252