diff --git a/SECURITY.md b/SECURITY.md index 9f65e2f88e..f06b781d11 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -23,6 +23,10 @@ either a user mistake or a bug in the code. Bugs can be reported in the LAMMPS project [issue tracker on GitHub](https://github.com/lammps/lammps/issues). +To mitigate issues with using homoglyphs or bidirectional reordering in +unicode, which have been demonstrated as a vector to obfuscate and hide +malicious changes to the source code, all LAMMPS submissions are checked +for unicode characters and only all-ASCII source code is accepted. # Version Updates diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 60b95dbb62..bc79d68c54 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -81,9 +81,9 @@ check_for_autogen_files(${LAMMPS_SOURCE_DIR}) include(CheckIncludeFileCXX) # set required compiler flags and compiler/CPU arch specific optimizations -if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict") endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 74102ab244..28ad99fa31 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -85,7 +85,7 @@ endfunction(GenerateBinaryHeader) # fetch missing potential files function(FetchPotentials pkgfolder potfolder) - if (EXISTS "${pkgfolder}/potentials.txt") + if(EXISTS "${pkgfolder}/potentials.txt") file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].") foreach(line ${linelist}) string(FIND ${line} " " blank) diff --git a/cmake/Modules/Packages/MACHDYN.cmake b/cmake/Modules/Packages/MACHDYN.cmake index 8729d80dbf..d90ca8146c 100644 --- a/cmake/Modules/Packages/MACHDYN.cmake +++ b/cmake/Modules/Packages/MACHDYN.cmake @@ -8,7 +8,7 @@ option(DOWNLOAD_EIGEN3 "Download Eigen3 instead of using an already installed on if(DOWNLOAD_EIGEN3) message(STATUS "Eigen3 download requested - we will build our own") - set(EIGEN3_URL "https://download.lammps.org/thirdparty/eigen-3.4.0.tar.gz" CACHE STRING "URL for Eigen3 tarball") + set(EIGEN3_URL "${LAMMPS_THIRDPARTY_URL}/eigen-3.4.0.tar.gz" CACHE STRING "URL for Eigen3 tarball") set(EIGEN3_MD5 "4c527a9171d71a72a9d4186e65bea559" CACHE STRING "MD5 checksum of Eigen3 tarball") mark_as_advanced(EIGEN3_URL) mark_as_advanced(EIGEN3_MD5) diff --git a/cmake/Modules/Packages/ML-PACE.cmake b/cmake/Modules/Packages/ML-PACE.cmake index ccc7423355..d46197114d 100644 --- a/cmake/Modules/Packages/ML-PACE.cmake +++ b/cmake/Modules/Packages/ML-PACE.cmake @@ -1,11 +1,11 @@ +set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.10.25.tar.gz" CACHE STRING "URL for PACE evaluator library sources") -set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.4.9.tar.gz" CACHE STRING "URL for PACE evaluator library sources") -set(PACELIB_MD5 "4db54962fbd6adcf8c18d46e1798ceb5" CACHE STRING "MD5 checksum of PACE evaluator library tarball") +set(PACELIB_MD5 "a2ac3315c41a1a4a5c912bcb1bc9c5cc" CACHE STRING "MD5 checksum of PACE evaluator library tarball") mark_as_advanced(PACELIB_URL) mark_as_advanced(PACELIB_MD5) # download library sources to build folder -file(DOWNLOAD ${PACELIB_URL} ${CMAKE_BINARY_DIR}/libpace.tar.gz SHOW_PROGRESS EXPECTED_HASH MD5=${PACELIB_MD5}) +file(DOWNLOAD ${PACELIB_URL} ${CMAKE_BINARY_DIR}/libpace.tar.gz EXPECTED_HASH MD5=${PACELIB_MD5}) #SHOW_PROGRESS # uncompress downloaded sources execute_process( @@ -14,12 +14,19 @@ execute_process( WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) -file(GLOB PACE_EVALUATOR_INCLUDE_DIR ${CMAKE_BINARY_DIR}/lammps-user-pace-*/USER-PACE) -file(GLOB PACE_EVALUATOR_SOURCES ${CMAKE_BINARY_DIR}/lammps-user-pace-*/USER-PACE/*.cpp) +file(GLOB lib-pace ${CMAKE_BINARY_DIR}/lammps-user-pace-*) +add_subdirectory(${lib-pace}/yaml-cpp build-yaml-cpp) +set(YAML_CPP_INCLUDE_DIR ${lib-pace}/yaml-cpp/include) + +file(GLOB PACE_EVALUATOR_INCLUDE_DIR ${lib-pace}/ML-PACE) +file(GLOB PACE_EVALUATOR_SOURCES ${lib-pace}/ML-PACE/*.cpp) list(FILTER PACE_EVALUATOR_SOURCES EXCLUDE REGEX pair_pace.cpp) add_library(pace STATIC ${PACE_EVALUATOR_SOURCES}) set_target_properties(pace PROPERTIES CXX_EXTENSIONS ON OUTPUT_NAME lammps_pace${LAMMPS_MACHINE}) -target_include_directories(pace PUBLIC ${PACE_EVALUATOR_INCLUDE_DIR}) -target_link_libraries(lammps PRIVATE pace) +target_include_directories(pace PUBLIC ${PACE_EVALUATOR_INCLUDE_DIR} ${YAML_CPP_INCLUDE_DIR}) + +target_link_libraries(pace PRIVATE yaml-cpp-pace) + +target_link_libraries(lammps PRIVATE pace) diff --git a/cmake/Modules/Packages/ML-QUIP.cmake b/cmake/Modules/Packages/ML-QUIP.cmake index 92418e8939..947c555842 100644 --- a/cmake/Modules/Packages/ML-QUIP.cmake +++ b/cmake/Modules/Packages/ML-QUIP.cmake @@ -32,7 +32,8 @@ if(DOWNLOAD_QUIP) foreach(flag ${LAPACK_LIBRARIES}) set(temp "${temp} ${flag}") endforeach() - set(temp "${temp}\n") + # Fix cmake crashing when MATH_LINKOPTS not set, required for e.g. recent Cray Programming Environment + set(temp "${temp} -L/_DUMMY_PATH_\n") set(temp "${temp}PYTHON=python\nPIP=pip\nEXTRA_LINKOPTS=\n") set(temp "${temp}HAVE_CP2K=0\nHAVE_VASP=0\nHAVE_TB=0\nHAVE_PRECON=1\nHAVE_LOTF=0\nHAVE_ONIOM=0\n") set(temp "${temp}HAVE_LOCAL_E_MIX=0\nHAVE_QC=0\nHAVE_GAP=1\nHAVE_DESCRIPTORS_NONCOMMERCIAL=1\n") diff --git a/doc/Makefile b/doc/Makefile index d61f844a1b..a082018dfb 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -230,7 +230,7 @@ $(VENV): ) $(MATHJAX): - @git clone -b 3.2.0 -c advice.detachedHead=0 --depth 1 git://github.com/mathjax/MathJax.git $@ + @git clone -b 3.2.0 -c advice.detachedHead=0 --depth 1 https://github.com/mathjax/MathJax.git $@ $(ANCHORCHECK): $(VENV) @( \ diff --git a/doc/lammps.1 b/doc/lammps.1 index 0e2831f5ca..78b6c9fd67 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "1" "29 September 2021" "2021-09-29" +.TH LAMMPS "1" "27 October 2021" "2021-10-27" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index 01bd8e2c80..b68313aaed 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -321,9 +321,7 @@ following settings: .. code-block:: make - LMP_INC = -DLAMMPS_JPEG - LMP_INC = -DLAMMPS_PNG - LMP_INC = -DLAMMPS_FFMPEG + LMP_INC = -DLAMMPS_JPEG -DLAMMPS_PNG -DLAMMPS_FFMPEG JPG_INC = -I/usr/local/include # path to jpeglib.h, png.h, zlib.h header files if make cannot find them JPG_PATH = -L/usr/lib # paths to libjpeg.a, libpng.a, libz.a (.so) files if make cannot find them @@ -372,7 +370,7 @@ including :doc:`read_data `, :doc:`rerun `, and .. code-block:: make - LMP_INC = -DLAMMPS_GZIP + LMP_INC = -DLAMMPS_GZIP This option requires that your operating system fully supports the "popen()" function in the standard runtime library and that a ``gzip`` @@ -454,7 +452,7 @@ those systems: .. code-block:: make - LMP_INC = -DLAMMPS_LONGLONG_TO_LONG + LMP_INC = -DLAMMPS_LONGLONG_TO_LONG ---------- @@ -481,7 +479,7 @@ e.g. to Python. Of course, the calling code has to be set up to .. code-block:: make - LMP_INC = -DLAMMPS_EXCEPTIONS + LMP_INC = -DLAMMPS_EXCEPTIONS .. note:: @@ -522,7 +520,7 @@ executable, not the library. .. code-block:: make - LMP_INC = -DLAMMPS_TRAP_FPE + LMP_INC = -DLAMMPS_TRAP_FPE After compilation with this flag set, the LAMMPS executable will stop and produce a core dump when a division by zero, overflow, illegal math diff --git a/doc/src/Developer_platform.rst b/doc/src/Developer_platform.rst index fd5cf065eb..cdc4bb6770 100644 --- a/doc/src/Developer_platform.rst +++ b/doc/src/Developer_platform.rst @@ -42,6 +42,9 @@ Platform information functions .. doxygenfunction:: mpi_info :project: progguide +.. doxygenfunction:: compress_info + :project: progguide + File and path functions and global constants ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/src/Install_git.rst b/doc/src/Install_git.rst index 4e7db77873..7ad6ca18c1 100644 --- a/doc/src/Install_git.rst +++ b/doc/src/Install_git.rst @@ -156,9 +156,9 @@ changed. How to do this depends on the build system you are using. .. admonition:: Git protocols :class: note - The servers at github.com support the "git://" and "https://" access - protocols for anonymous, read-only access. If you have a suitably - configured GitHub account, you may also use SSH protocol with the + The servers at github.com support the "https://" access protocol for + anonymous, read-only access. If you have a suitably configured GitHub + account, you may also use SSH protocol with the URL "git@github.com:lammps/lammps.git". The LAMMPS GitHub project is currently managed by Axel Kohlmeyer diff --git a/doc/src/Intro_citing.rst b/doc/src/Intro_citing.rst index 0e10b7559a..08f82fac33 100644 --- a/doc/src/Intro_citing.rst +++ b/doc/src/Intro_citing.rst @@ -16,7 +16,7 @@ source code design, the program structure, the spatial decomposition approach, the neighbor finding, basic communications algorithms, and how users and developers have contributed to LAMMPS is: - `LAMMPS - A flexible simulation tool for particle-based materials modeling at the atomic, meso, and continuum scales, Comp. Phys. Comm. (accepted 09/2021), DOI:10.1016/j.cpc.2021.108171 `_ + `LAMMPS - A flexible simulation tool for particle-based materials modeling at the atomic, meso, and continuum scales, Comp. Phys. Comm. 271, 108171 (2022) `_ So a project using LAMMPS or a derivative application that uses LAMMPS as a simulation engine should cite this paper. The paper is expected to diff --git a/doc/src/dump_image.rst b/doc/src/dump_image.rst index be14a237e5..9b8c7febf4 100644 --- a/doc/src/dump_image.rst +++ b/doc/src/dump_image.rst @@ -6,6 +6,8 @@ dump image command dump movie command ================== +(see below for :ref:`dump_modify options ` specific to dump image/movie) + Syntax """""" @@ -15,7 +17,7 @@ Syntax * ID = user-assigned name for the dump * group-ID = ID of the group of atoms to be imaged -* style = *image* or *movie* = style of dump command (other styles *atom* or *cfg* or *dcd* or *xtc* or *xyz* or *local* or *custom* are discussed on the :doc:`dump ` doc page) +* style = *image* or *movie* = style of dump command (other styles such as *atom* or *cfg* or *dcd* or *xtc* or *xyz* or *local* or *custom* are discussed on the :doc:`dump ` doc page) * N = dump every this many timesteps * file = name of file to write image to * color = atom attribute that determines color of each atom @@ -79,6 +81,69 @@ Syntax seed = random # seed (positive integer) dfactor = strength of shading from 0.0 to 1.0 + +.. _dump_modify_image: + +dump_modify options for dump image/movie +======================================== + +Syntax +"""""" + +.. parsed-literal:: + + dump_modify dump-ID keyword values ... + +* these keywords apply only to the *image* and *movie* styles and are documented on this page +* keyword = *acolor* or *adiam* or *amap* or *backcolor* or *bcolor* or *bdiam* or *boxcolor* or *color* or *bitrate* or *framerate* +* see the :doc:`dump modify ` doc page for more general keywords + + .. parsed-literal:: + + *acolor* args = type color + type = atom type or range of types (see below) + color = name of color or color1/color2/... + *adiam* args = type diam + type = atom type or range of types (see below) + diam = diameter of atoms of that type (distance units) + *amap* args = lo hi style delta N entry1 entry2 ... entryN + lo = number or *min* = lower bound of range of color map + hi = number or *max* = upper bound of range of color map + style = 2 letters = "c" or "d" or "s" plus "a" or "f" + "c" for continuous + "d" for discrete + "s" for sequential + "a" for absolute + "f" for fractional + delta = binsize (only used for style "s", otherwise ignored) + binsize = range is divided into bins of this width + N = # of subsequent entries + entry = value color (for continuous style) + value = number or *min* or *max* = single value within range + color = name of color used for that value + entry = lo hi color (for discrete style) + lo/hi = number or *min* or *max* = lower/upper bound of subset of range + color = name of color used for that subset of values + entry = color (for sequential style) + color = name of color used for a bin of values + *backcolor* arg = color + color = name of color for background + *bcolor* args = type color + type = bond type or range of types (see below) + color = name of color or color1/color2/... + *bdiam* args = type diam + type = bond type or range of types (see below) + diam = diameter of bonds of that type (distance units) + *boxcolor* arg = color + color = name of color for simulation box lines and processor sub-domain lines + *color* args = name R G B + name = name of color + R,G,B = red/green/blue numeric values from 0.0 to 1.0 + *bitrate* arg = rate + rate = target bitrate for movie in kbps + *framerate* arg = fps + fps = frames per second for movie + Examples """""""" @@ -91,6 +156,8 @@ Examples dump m1 all movie 1000 movie.avi type type size 640 480 dump m2 all movie 100 movie.m4v type type zoom 1.8 adiam v_value size 1280 720 + dump_modify 1 amap min max cf 0.0 3 min green 0.5 yellow max blue boxcolor red + Description """"""""""" @@ -145,10 +212,10 @@ is used. Similarly, the format of the resulting movie is chosen with the *movie* dump style. This is handled by the underlying FFmpeg converter and thus details have to be looked up in the `FFmpeg documentation -`_. -Typical examples are: .avi, .mpg, .m4v, .mp4, .mkv, .flv, .mov, .gif -Additional settings of the movie compression like bitrate and -framerate can be set using the :doc:`dump_modify ` command. +`_. Typical examples are: .avi, .mpg, +.m4v, .mp4, .mkv, .flv, .mov, .gif Additional settings of the movie +compression like bitrate and framerate can be set using the +dump_modify command as described below. To write out JPEG and PNG format files, you must build LAMMPS with support for the corresponding JPEG or PNG library. To convert images @@ -210,19 +277,20 @@ to colors is as follows: * type 6 = cyan and repeats itself for types > 6. This mapping can be changed by the -:doc:`dump_modify acolor ` command. +"dump_modify acolor" command, as described below. If *type* is specified for the *diameter* setting then the diameter of each atom is determined by its atom type. By default all types have -diameter 1.0. This mapping can be changed by the :doc:`dump_modify adiam ` command. +diameter 1.0. This mapping can be changed by the "dump_modify adiam" +command, as described below. If *element* is specified for the *color* and/or *diameter* setting, then the color and/or diameter of each atom is determined by which element it is, which in turn is specified by the element-to-type -mapping specified by the "dump_modify element" command. By default -every atom type is C (carbon). Every element has a color and diameter -associated with it, which is the same as the colors and sizes used by -the `AtomEye `_ visualization package. +mapping specified by the "dump_modify element" command, as described +below. By default every atom type is C (carbon). Every element has a +color and diameter associated with it, which is the same as the colors +and sizes used by the `AtomEye `_ visualization package. .. _atomeye: http://li.mit.edu/Archive/Graphics/A/ @@ -232,13 +300,13 @@ settings, they are interpreted in the following way. If "vx", for example, is used as the *color* setting, then the color of the atom will depend on the x-component of its velocity. The association of a per-atom value with a specific color is determined by -a "color map", which can be specified via the -:doc:`dump_modify ` command. The basic idea is that the -atom-attribute will be within a range of values, and every value -within the range is mapped to a specific color. Depending on how the -color map is defined, that mapping can take place via interpolation so -that a value of -3.2 is halfway between "red" and "blue", or -discretely so that the value of -3.2 is "orange". +a "color map", which can be specified via the dump_modify command, as +described below. The basic idea is that the atom-attribute will be +within a range of values, and every value within the range is mapped +to a specific color. Depending on how the color map is defined, that +mapping can take place via interpolation so that a value of -3.2 is +halfway between "red" and "blue", or discretely so that the value of +-3.2 is "orange". If "vx", for example, is used as the *diameter* setting, then the atom will be rendered using the x-component of its velocity as the @@ -251,9 +319,10 @@ diameter, which can be used as the *diameter* setting. The various keywords listed above control how the image is rendered. As listed below, all of the keywords have defaults, most of which you -will likely not need to change. The :doc:`dump modify ` -also has options specific to the dump image style, particularly for -assigning colors to atoms, bonds, and other image features. +will likely not need to change. As described below, the dump modify +command also has options specific to the dump image style, +particularly for assigning colors to atoms, bonds, and other image +features. ---------- @@ -295,7 +364,7 @@ types to colors is as follows: * type 6 = cyan and repeats itself for bond types > 6. This mapping can be changed by -the :doc:`dump_modify bcolor ` command. +the "dump_modify bcolor" command, as described below. The bond *width* value can be a numeric value or *atom* or *type* (or *none* as indicated above). @@ -310,7 +379,8 @@ of the 2 atoms in the bond. If *type* is specified for the *width* value then the diameter of each bond is determined by its bond type. By default all types have -diameter 0.5. This mapping can be changed by the :doc:`dump_modify bdiam ` command. +diameter 0.5. This mapping can be changed by the "dump_modify bdiam" command, +as described below. ---------- @@ -330,7 +400,7 @@ mapping of types to colors is as follows: * type 6 = cyan and repeats itself for types > 6. There is not yet an option to -change this via the :doc:`dump_modify ` command. +change this via the dump_modify command. The line *width* can only be a numeric value, which specifies that all lines will be drawn as cylinders with that diameter, e.g. 1.0, which @@ -357,7 +427,7 @@ default the mapping of types to colors is as follows: * type 6 = cyan and repeats itself for types > 6. There is not yet an option to -change this via the :doc:`dump_modify ` command. +change this via the dump_modify command. ---------- @@ -390,7 +460,7 @@ particle. By default the mapping of types to colors is as follows: * type 6 = cyan and repeats itself for types > 6. There is not yet an option to -change this via the :doc:`dump_modify ` command. +change this via the dump_modify command. ---------- @@ -414,7 +484,7 @@ the mapping of types to colors is as follows: * type 6 = cyan and repeats itself for types > 6. There is not yet an option to -change this via the :doc:`dump_modify ` command. +change this via the dump_modify command. ---------- @@ -488,7 +558,8 @@ are rendered as thin cylinders in the image. If *no* is set, then the box boundaries are not drawn and the *diam* setting is ignored. If *yes* is set, the 12 edges of the box are drawn, with a diameter that is a fraction of the shortest box length in x,y,z (for 3d) or x,y (for -2d). The color of the box boundaries can be set with the :doc:`dump_modify boxcolor ` command. +2d). The color of the box boundaries can be set with the "dump_modify +boxcolor" command. The *axes* keyword determines if and how the coordinate axes are rendered as thin cylinders in the image. If *no* is set, then the @@ -507,7 +578,8 @@ set (default), then the sub-domain boundaries are not drawn and the *diam* setting is ignored. If *yes* is set, the 12 edges of each processor sub-domain are drawn, with a diameter that is a fraction of the shortest box length in x,y,z (for 3d) or x,y (for 2d). The color -of the sub-domain boundaries can be set with the :doc:`dump_modify boxcolor ` command. +of the sub-domain boundaries can be set with the "dump_modify +boxcolor" command. ---------- @@ -607,9 +679,272 @@ Play the movie: ---------- -See the :doc:`Modify ` page for information on how to add -new compute and fix styles to LAMMPS to calculate per-atom quantities -which could then be output into dump files. +Dump_modify keywords for dump image and dump movie +"""""""""""""""""""""""""""""""""""""""""""""""""" + +The following dump_modify keywords apply only to the dump image and +dump movie styles. Any keyword that works with dump image also works +with dump movie, since the movie is simply a collection of images. +Some of the keywords only affect the dump movie style. The +descriptions give details. + +---------- + +The *acolor* keyword can be used with the dump image command, when its +atom color setting is *type*, to set the color that atoms of each type +will be drawn in the image. + +The specified *type* should be an integer from 1 to Ntypes = the +number of atom types. A wildcard asterisk can be used in place of or +in conjunction with the *type* argument to specify a range of atom +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 specified *color* can be a single color which is any of the 140 +pre-defined colors (see below) or a color name defined by the +"dump_modify color" command, as described below. Or it can be two or +more colors separated by a "/" character, e.g. red/green/blue. In the +former case, that color is assigned to all the specified atom types. +In the latter case, the list of colors are assigned in a round-robin +fashion to each of the specified atom types. + +---------- + +The *adiam* keyword can be used with the dump image command, when its +atom diameter setting is *type*, to set the size that atoms of each +type will be drawn in the image. The specified *type* should be an +integer from 1 to Ntypes. As with the *acolor* keyword, a wildcard +asterisk can be used as part of the *type* argument to specify a range +of atom types. The specified *diam* is the size in whatever distance +:doc:`units ` the input script is using, e.g. Angstroms. + +---------- + +The *amap* keyword can be used with the dump image command, with its +*atom* keyword, when its atom setting is an atom-attribute, to setup a +color map. The color map is used to assign a specific RGB +(red/green/blue) color value to an individual atom when it is drawn, +based on the atom's attribute, which is a numeric value, e.g. its +x-component of velocity if the atom-attribute "vx" was specified. + +The basic idea of a color map is that the atom-attribute will be +within a range of values, and that range is associated with a series +of colors (e.g. red, blue, green). An atom's specific value (vx = +-3.2) can then mapped to the series of colors (e.g. halfway between +red and blue), and a specific color is determined via an interpolation +procedure. + +There are many possible options for the color map, enabled by the +*amap* keyword. Here are the details. + +The *lo* and *hi* settings determine the range of values allowed for +the atom attribute. If numeric values are used for *lo* and/or *hi*, +then values that are lower/higher than that value are set to the +value. I.e. the range is static. If *lo* is specified as *min* or +*hi* as *max* then the range is dynamic, and the lower and/or +upper bound will be calculated each time an image is drawn, based +on the set of atoms being visualized. + +The *style* setting is two letters, such as "ca". The first letter is +either "c" for continuous, "d" for discrete, or "s" for sequential. +The second letter is either "a" for absolute, or "f" for fractional. + +A continuous color map is one in which the color changes continuously +from value to value within the range. A discrete color map is one in +which discrete colors are assigned to sub-ranges of values within the +range. A sequential color map is one in which discrete colors are +assigned to a sequence of sub-ranges of values covering the entire +range. + +An absolute color map is one in which the values to which colors are +assigned are specified explicitly as values within the range. A +fractional color map is one in which the values to which colors are +assigned are specified as a fractional portion of the range. For +example if the range is from -10.0 to 10.0, and the color red is to be +assigned to atoms with a value of 5.0, then for an absolute color map +the number 5.0 would be used. But for a fractional map, the number +0.75 would be used since 5.0 is 3/4 of the way from -10.0 to 10.0. + +The *delta* setting must be specified for all styles, but is only used +for the sequential style; otherwise the value is ignored. It +specifies the bin size to use within the range for assigning +consecutive colors to. For example, if the range is from -10.0 to +10.0 and a *delta* of 1.0 is used, then 20 colors will be assigned to +the range. The first will be from -10.0 <= color1 < -9.0, then second +from -9.0 <= color2 < -8.0, etc. + +The *N* setting is how many entries follow. The format of the entries +depends on whether the color map style is continuous, discrete or +sequential. In all cases the *color* setting can be any of the 140 +pre-defined colors (see below) or a color name defined by the +dump_modify color option. + +For continuous color maps, each entry has a *value* and a *color*\ . +The *value* is either a number within the range of values or *min* or +*max*\ . The *value* of the first entry must be *min* and the *value* +of the last entry must be *max*\ . Any entries in between must have +increasing values. Note that numeric values can be specified either +as absolute numbers or as fractions (0.0 to 1.0) of the range, +depending on the "a" or "f" in the style setting for the color map. + +Here is how the entries are used to determine the color of an +individual atom, given the value X of its atom attribute. X will fall +between 2 of the entry values. The color of the atom is linearly +interpolated (in each of the RGB values) between the 2 colors +associated with those entries. For example, if X = -5.0 and the 2 +surrounding entries are "red" at -10.0 and "blue" at 0.0, then the +atom's color will be halfway between "red" and "blue", which happens +to be "purple". + +For discrete color maps, each entry has a *lo* and *hi* value and a +*color*\ . The *lo* and *hi* settings are either numbers within the +range of values or *lo* can be *min* or *hi* can be *max*\ . The *lo* +and *hi* settings of the last entry must be *min* and *max*\ . Other +entries can have any *lo* and *hi* values and the sub-ranges of +different values can overlap. Note that numeric *lo* and *hi* values +can be specified either as absolute numbers or as fractions (0.0 to +1.0) of the range, depending on the "a" or "f" in the style setting +for the color map. + +Here is how the entries are used to determine the color of an +individual atom, given the value X of its atom attribute. The entries +are scanned from first to last. The first time that *lo* <= X <= +*hi*, X is assigned the color associated with that entry. You can +think of the last entry as assigning a default color (since it will +always be matched by X), and the earlier entries as colors that +override the default. Also note that no interpolation of a color RGB +is done. All atoms will be drawn with one of the colors in the list +of entries. + +For sequential color maps, each entry has only a *color*\ . Here is how +the entries are used to determine the color of an individual atom, +given the value X of its atom attribute. The range is partitioned +into N bins of width *binsize*\ . Thus X will fall in a specific bin +from 1 to N, say the Mth bin. If it falls on a boundary between 2 +bins, it is considered to be in the higher of the 2 bins. Each bin is +assigned a color from the E entries. If E < N, then the colors are +repeated. For example if 2 entries with colors red and green are +specified, then the odd numbered bins will be red and the even bins +green. The color of the atom is the color of its bin. Note that the +sequential color map is really a shorthand way of defining a discrete +color map without having to specify where all the bin boundaries are. + +Here is an example of using a sequential color map to color all the +atoms in individual molecules with a different color. See the +examples/pour/in.pour.2d.molecule input script for an example of how +this is used. + +.. code-block:: LAMMPS + + variable colors string & + "red green blue yellow white & + purple pink orange lime gray" + variable mol atom mol%10 + dump 1 all image 250 image.*.jpg v_mol type & + zoom 1.6 adiam 1.5 + dump_modify 1 pad 5 amap 0 10 sa 1 10 ${colors} + +In this case, 10 colors are defined, and molecule IDs are +mapped to one of the colors, even if there are 1000s of molecules. + +---------- + +The *backcolor* sets the background color of the images. The color +name can be any of the 140 pre-defined colors (see below) or a color +name defined by the dump_modify color option. + +---------- + +The *bcolor* keyword can be used with the dump image command, with its +*bond* keyword, when its color setting is *type*, to set the color +that bonds of each type will be drawn in the image. + +The specified *type* should be an integer from 1 to Nbondtypes = the +number of bond types. A wildcard asterisk can be used in place of or +in conjunction with the *type* argument to specify a range of 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). + +The specified *color* can be a single color which is any of the 140 +pre-defined colors (see below) or a color name defined by the +dump_modify color option. Or it can be two or more colors separated +by a "/" character, e.g. red/green/blue. In the former case, that +color is assigned to all the specified bond types. In the latter +case, the list of colors are assigned in a round-robin fashion to each +of the specified bond types. + +---------- + +The *bdiam* keyword can be used with the dump image command, with its +*bond* keyword, when its diam setting is *type*, to set the diameter +that bonds of each type will be drawn in the image. The specified +*type* should be an integer from 1 to Nbondtypes. As with the +*bcolor* keyword, a wildcard asterisk can be used as part of the +*type* argument to specify a range of bond types. The specified +*diam* is the size in whatever distance :doc:`units ` you are +using, e.g. Angstroms. + +---------- + +The *bitrate* keyword can be used with the :doc:`dump movie +` command to define the size of the resulting movie file +and its quality via setting how many kbits per second are to be used +for the movie file. Higher bitrates require less compression and will +result in higher quality movies. The quality is also determined by +the compression format and encoder. The default setting is 2000 +kbit/s, which will result in average quality with older compression +formats. + +.. note:: + + Not all movie file formats supported by dump movie allow the + bitrate to be set. If not, the setting is silently ignored. + +---------- + +The *boxcolor* keyword sets the color of the simulation box drawn +around the atoms in each image as well as the color of processor +sub-domain boundaries. See the "dump image box" command for how to +specify that a box be drawn via the *box* keyword, and the sub-domain +boundaries via the *subbox* keyword. The color name can be any of the +140 pre-defined colors (see below) or a color name defined by the +dump_modify color option. + +---------- + +The *color* keyword allows definition of a new color name, in addition +to the 140-predefined colors (see below), and associates 3 +red/green/blue RGB values with that color name. The color name can +then be used with any other dump_modify keyword that takes a color +name as a value. The RGB values should each be floating point values +between 0.0 and 1.0 inclusive. + +When a color name is converted to RGB values, the user-defined color +names are searched first, then the 140 pre-defined color names. This +means you can also use the *color* keyword to overwrite one of the +pre-defined color names with new RBG values. + +---------- + +The *framerate* keyword can be used with the :doc:`dump movie +` command to define the duration of the resulting movie +file. Movie files written by the dump *movie* command have a default +frame rate of 24 frames per second and the images generated will be +converted at that rate. Thus a sequence of 1000 dump images will +result in a movie of about 42 seconds. To make a movie run longer you +can either generate images more frequently or lower the frame rate. +To speed a movie up, you can do the inverse. Using a frame rate +higher than 24 is not recommended, as it will result in simply +dropping the rendered images. It is more efficient to dump images less +frequently. ---------- @@ -664,7 +999,7 @@ Related commands Default """"""" -The defaults for the keywords are as follows: +The defaults for the dump image and dump movie keywords are as follows: * adiam = not specified (use diameter setting) * atom = yes @@ -682,3 +1017,101 @@ The defaults for the keywords are as follows: * subbox no 0.0 * shiny = 1.0 * ssao = no + +---------- + +The defaults for the dump_modify keywords specific to dump image and dump movie are as follows: + +* acolor = \* red/green/blue/yellow/aqua/cyan +* adiam = \* 1.0 +* amap = min max cf 0.0 2 min blue max red +* backcolor = black +* bcolor = \* red/green/blue/yellow/aqua/cyan +* bdiam = \* 0.5 +* bitrate = 2000 +* boxcolor = yellow +* color = 140 color names are pre-defined as listed below +* framerate = 24 + +---------- + +These are the standard 109 element names that LAMMPS pre-defines for +use with the dump image and dump_modify commands. + +* 1-10 = "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne" +* 11-20 = "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca" +* 21-30 = "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn" +* 31-40 = "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr" +* 41-50 = "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn" +* 51-60 = "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd" +* 61-70 = "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb" +* 71-80 = "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg" +* 81-90 = "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th" +* 91-100 = "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm" +* 101-109 = "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt" + +---------- + +These are the 140 colors that LAMMPS pre-defines for use with the dump +image and dump_modify commands. Additional colors can be defined with +the dump_modify color command. The 3 numbers listed for each name are +the RGB (red/green/blue) values. Divide each value by 255 to get the +equivalent 0.0 to 1.0 value. + ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| aliceblue = 240, 248, 255 | antiquewhite = 250, 235, 215 | aqua = 0, 255, 255 | aquamarine = 127, 255, 212 | azure = 240, 255, 255 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| beige = 245, 245, 220 | bisque = 255, 228, 196 | black = 0, 0, 0 | blanchedalmond = 255, 255, 205 | blue = 0, 0, 255 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| blueviolet = 138, 43, 226 | brown = 165, 42, 42 | burlywood = 222, 184, 135 | cadetblue = 95, 158, 160 | chartreuse = 127, 255, 0 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| chocolate = 210, 105, 30 | coral = 255, 127, 80 | cornflowerblue = 100, 149, 237 | cornsilk = 255, 248, 220 | crimson = 220, 20, 60 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| cyan = 0, 255, 255 | darkblue = 0, 0, 139 | darkcyan = 0, 139, 139 | darkgoldenrod = 184, 134, 11 | darkgray = 169, 169, 169 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| darkgreen = 0, 100, 0 | darkkhaki = 189, 183, 107 | darkmagenta = 139, 0, 139 | darkolivegreen = 85, 107, 47 | darkorange = 255, 140, 0 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| darkorchid = 153, 50, 204 | darkred = 139, 0, 0 | darksalmon = 233, 150, 122 | darkseagreen = 143, 188, 143 | darkslateblue = 72, 61, 139 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| darkslategray = 47, 79, 79 | darkturquoise = 0, 206, 209 | darkviolet = 148, 0, 211 | deeppink = 255, 20, 147 | deepskyblue = 0, 191, 255 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| dimgray = 105, 105, 105 | dodgerblue = 30, 144, 255 | firebrick = 178, 34, 34 | floralwhite = 255, 250, 240 | forestgreen = 34, 139, 34 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| fuchsia = 255, 0, 255 | gainsboro = 220, 220, 220 | ghostwhite = 248, 248, 255 | gold = 255, 215, 0 | goldenrod = 218, 165, 32 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| gray = 128, 128, 128 | green = 0, 128, 0 | greenyellow = 173, 255, 47 | honeydew = 240, 255, 240 | hotpink = 255, 105, 180 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| indianred = 205, 92, 92 | indigo = 75, 0, 130 | ivory = 255, 240, 240 | khaki = 240, 230, 140 | lavender = 230, 230, 250 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| lavenderblush = 255, 240, 245 | lawngreen = 124, 252, 0 | lemonchiffon = 255, 250, 205 | lightblue = 173, 216, 230 | lightcoral = 240, 128, 128 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| lightcyan = 224, 255, 255 | lightgoldenrodyellow = 250, 250, 210 | lightgreen = 144, 238, 144 | lightgrey = 211, 211, 211 | lightpink = 255, 182, 193 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| lightsalmon = 255, 160, 122 | lightseagreen = 32, 178, 170 | lightskyblue = 135, 206, 250 | lightslategray = 119, 136, 153 | lightsteelblue = 176, 196, 222 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| lightyellow = 255, 255, 224 | lime = 0, 255, 0 | limegreen = 50, 205, 50 | linen = 250, 240, 230 | magenta = 255, 0, 255 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| maroon = 128, 0, 0 | mediumaquamarine = 102, 205, 170 | mediumblue = 0, 0, 205 | mediumorchid = 186, 85, 211 | mediumpurple = 147, 112, 219 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| mediumseagreen = 60, 179, 113 | mediumslateblue = 123, 104, 238 | mediumspringgreen = 0, 250, 154 | mediumturquoise = 72, 209, 204 | mediumvioletred = 199, 21, 133 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| midnightblue = 25, 25, 112 | mintcream = 245, 255, 250 | mistyrose = 255, 228, 225 | moccasin = 255, 228, 181 | navajowhite = 255, 222, 173 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| navy = 0, 0, 128 | oldlace = 253, 245, 230 | olive = 128, 128, 0 | olivedrab = 107, 142, 35 | orange = 255, 165, 0 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| orangered = 255, 69, 0 | orchid = 218, 112, 214 | palegoldenrod = 238, 232, 170 | palegreen = 152, 251, 152 | paleturquoise = 175, 238, 238 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| palevioletred = 219, 112, 147 | papayawhip = 255, 239, 213 | peachpuff = 255, 239, 213 | peru = 205, 133, 63 | pink = 255, 192, 203 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| plum = 221, 160, 221 | powderblue = 176, 224, 230 | purple = 128, 0, 128 | red = 255, 0, 0 | rosybrown = 188, 143, 143 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| royalblue = 65, 105, 225 | saddlebrown = 139, 69, 19 | salmon = 250, 128, 114 | sandybrown = 244, 164, 96 | seagreen = 46, 139, 87 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| seashell = 255, 245, 238 | sienna = 160, 82, 45 | silver = 192, 192, 192 | skyblue = 135, 206, 235 | slateblue = 106, 90, 205 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| slategray = 112, 128, 144 | snow = 255, 250, 250 | springgreen = 0, 255, 127 | steelblue = 70, 130, 180 | tan = 210, 180, 140 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| teal = 0, 128, 128 | thistle = 216, 191, 216 | tomato = 253, 99, 71 | turquoise = 64, 224, 208 | violet = 238, 130, 238 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ +| wheat = 245, 222, 179 | white = 255, 255, 255 | whitesmoke = 245, 245, 245 | yellow = 255, 255, 0 | yellowgreen = 154, 205, 50 | ++-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ diff --git a/doc/src/dump_modify.rst b/doc/src/dump_modify.rst index 5fea976e70..33f7141762 100644 --- a/doc/src/dump_modify.rst +++ b/doc/src/dump_modify.rst @@ -3,6 +3,9 @@ dump_modify command =================== +:doc:`dump_modify ` command for image/movie options +=============================================================== + Syntax """""" @@ -12,8 +15,9 @@ Syntax * dump-ID = ID of dump to modify * one or more keyword/value pairs may be appended + * these keywords apply to various dump styles -* keyword = *append* or *at* or *buffer* or *delay* or *element* or *every* or *fileper* or *first* or *flush* or *format* or *image* or *label* or *maxfiles* or *nfile* or *pad* or *pbc* or *precision* or *region* or *refresh* or *scale* or *sfactor* or *sort* or *tfactor* or *thermo* or *thresh* or *time* or *units* or *unwrap* +* keyword = *append* or *at* or *buffer* or *delay* or *element* or *every* or *fileper* or *first* or *flush* or *format* or *header* or *image* or *label* or *maxfiles* or *nfile* or *pad* or *pbc* or *precision* or *region* or *refresh* or *scale* or *sfactor* or *sort* or *tfactor* or *thermo* or *thresh* or *time* or *units* or *unwrap* .. parsed-literal:: @@ -35,6 +39,9 @@ Syntax *format* args = *line* string, *int* string, *float* string, M string, or *none* string = C-style format string M = integer from 1 to N, where N = # of per-atom quantities being output + *header* arg = *yes* or *no* + *yes* to write the header + *no* to not write the header *image* arg = *yes* or *no* *label* arg = string string = character string (e.g. BONDS) to use in header of dump local file @@ -66,56 +73,11 @@ Syntax *unwrap* arg = *yes* or *no* * these keywords apply only to the *image* and *movie* :doc:`styles ` -* keyword = *acolor* or *adiam* or *amap* or *backcolor* or *bcolor* or *bdiam* or *boxcolor* or *color* or *bitrate* or *framerate* or *header* +* keyword = *acolor* or *adiam* or *amap* or *backcolor* or *bcolor* or *bdiam* or *boxcolor* or *color* or *bitrate* or *framerate* .. parsed-literal:: - *acolor* args = type color - type = atom type or range of types (see below) - color = name of color or color1/color2/... - *adiam* args = type diam - type = atom type or range of types (see below) - diam = diameter of atoms of that type (distance units) - *amap* args = lo hi style delta N entry1 entry2 ... entryN - lo = number or *min* = lower bound of range of color map - hi = number or *max* = upper bound of range of color map - style = 2 letters = "c" or "d" or "s" plus "a" or "f" - "c" for continuous - "d" for discrete - "s" for sequential - "a" for absolute - "f" for fractional - delta = binsize (only used for style "s", otherwise ignored) - binsize = range is divided into bins of this width - N = # of subsequent entries - entry = value color (for continuous style) - value = number or *min* or *max* = single value within range - color = name of color used for that value - entry = lo hi color (for discrete style) - lo/hi = number or *min* or *max* = lower/upper bound of subset of range - color = name of color used for that subset of values - entry = color (for sequential style) - color = name of color used for a bin of values - *backcolor* arg = color - color = name of color for background - *bcolor* args = type color - type = bond type or range of types (see below) - color = name of color or color1/color2/... - *bdiam* args = type diam - type = bond type or range of types (see below) - diam = diameter of bonds of that type (distance units) - *boxcolor* arg = color - color = name of color for simulation box lines and processor sub-domain lines - *color* args = name R G B - name = name of color - R,G,B = red/green/blue numeric values from 0.0 to 1.0 - *bitrate* arg = rate - rate = target bitrate for movie in kbps - *framerate* arg = fps - fps = frames per second for movie - *header* arg = *yes* or *no* - *yes* to write the header - *no* to not write the header + see the :doc:`dump image ` doc page for details * these keywords apply only to the */gz* and */zstd* dump styles * keyword = *compression_level* @@ -126,7 +88,7 @@ Syntax level = integer specifying the compression level that should be used (see below for supported levels) * these keywords apply only to the */zstd* dump styles -* keyword = *compression_level* +* keyword = *checksum* .. parsed-literal:: @@ -144,7 +106,6 @@ Examples dump_modify xtcdump precision 10000 sfactor 0.1 dump_modify 1 every 1000 nfile 20 dump_modify 1 every v_myVar - dump_modify 1 amap min max cf 0.0 3 min green 0.5 yellow max blue boxcolor red Description """"""""""" @@ -163,8 +124,9 @@ which allow for use of MPI-IO. ---------- -These keywords apply to various dump styles, including the :doc:`dump image ` and :doc:`dump movie ` styles. The -description gives details. +Unless otherwise noted, the following keywords apply to all the +various dump styles, including the :doc:`dump image ` and +:doc:`dump movie ` styles. ---------- @@ -380,6 +342,13 @@ The *fileper* keyword is documented below with the *nfile* keyword. ---------- +The *header* keyword toggles whether the dump file will include a header. +Excluding a header will reduce the size of the dump file for fixes such as +:doc:`fix pair/tracker ` which do not require the information +typically written to the header. + +---------- + The *image* keyword applies only to the dump *atom* style. If the image value is *yes*, 3 flags are appended to each atom's coords which are the absolute box image of the atom in each dimension. For @@ -715,297 +684,27 @@ box size stored with the snapshot. ---------- -These keywords apply only to the :doc:`dump image ` and -:doc:`dump movie ` styles. Any keyword that affects an -image, also affects a movie, since the movie is simply a collection of -images. Some of the keywords only affect the :doc:`dump movie ` style. The descriptions give details. +The COMPRESS package offers both GZ and Zstd compression variants of +styles atom, custom, local, cfg, and xyz. When using these styles the +compression level can be controlled by the :code:`compression_level` +keyword. File names with these styles have to end in either +:code:`.gz` or :code:`.zst`. ----------- - -The *acolor* keyword can be used with the :doc:`dump image ` -command, when its atom color setting is *type*, to set the color that -atoms of each type will be drawn in the image. - -The specified *type* should be an integer from 1 to Ntypes = the -number of atom types. A wildcard asterisk can be used in place of or -in conjunction with the *type* argument to specify a range of atom -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 specified *color* can be a single color which is any of the 140 -pre-defined colors (see below) or a color name defined by the -dump_modify color option. Or it can be two or more colors separated -by a "/" character, e.g. red/green/blue. In the former case, that -color is assigned to all the specified atom types. In the latter -case, the list of colors are assigned in a round-robin fashion to each -of the specified atom types. - ----------- - -The *adiam* keyword can be used with the :doc:`dump image ` -command, when its atom diameter setting is *type*, to set the size -that atoms of each type will be drawn in the image. The specified -*type* should be an integer from 1 to Ntypes. As with the *acolor* -keyword, a wildcard asterisk can be used as part of the *type* -argument to specify a range of atom types. The specified *diam* is -the size in whatever distance :doc:`units ` the input script is -using, e.g. Angstroms. - ----------- - -The *amap* keyword can be used with the :doc:`dump image ` -command, with its *atom* keyword, when its atom setting is an -atom-attribute, to setup a color map. The color map is used to assign -a specific RGB (red/green/blue) color value to an individual atom when -it is drawn, based on the atom's attribute, which is a numeric value, -e.g. its x-component of velocity if the atom-attribute "vx" was -specified. - -The basic idea of a color map is that the atom-attribute will be -within a range of values, and that range is associated with a series -of colors (e.g. red, blue, green). An atom's specific value (vx = --3.2) can then mapped to the series of colors (e.g. halfway between -red and blue), and a specific color is determined via an interpolation -procedure. - -There are many possible options for the color map, enabled by the -*amap* keyword. Here are the details. - -The *lo* and *hi* settings determine the range of values allowed for -the atom attribute. If numeric values are used for *lo* and/or *hi*, -then values that are lower/higher than that value are set to the -value. I.e. the range is static. If *lo* is specified as *min* or -*hi* as *max* then the range is dynamic, and the lower and/or -upper bound will be calculated each time an image is drawn, based -on the set of atoms being visualized. - -The *style* setting is two letters, such as "ca". The first letter is -either "c" for continuous, "d" for discrete, or "s" for sequential. -The second letter is either "a" for absolute, or "f" for fractional. - -A continuous color map is one in which the color changes continuously -from value to value within the range. A discrete color map is one in -which discrete colors are assigned to sub-ranges of values within the -range. A sequential color map is one in which discrete colors are -assigned to a sequence of sub-ranges of values covering the entire -range. - -An absolute color map is one in which the values to which colors are -assigned are specified explicitly as values within the range. A -fractional color map is one in which the values to which colors are -assigned are specified as a fractional portion of the range. For -example if the range is from -10.0 to 10.0, and the color red is to be -assigned to atoms with a value of 5.0, then for an absolute color map -the number 5.0 would be used. But for a fractional map, the number -0.75 would be used since 5.0 is 3/4 of the way from -10.0 to 10.0. - -The *delta* setting must be specified for all styles, but is only used -for the sequential style; otherwise the value is ignored. It -specifies the bin size to use within the range for assigning -consecutive colors to. For example, if the range is from -10.0 to -10.0 and a *delta* of 1.0 is used, then 20 colors will be assigned to -the range. The first will be from -10.0 <= color1 < -9.0, then second -from -9.0 <= color2 < -8.0, etc. - -The *N* setting is how many entries follow. The format of the entries -depends on whether the color map style is continuous, discrete or -sequential. In all cases the *color* setting can be any of the 140 -pre-defined colors (see below) or a color name defined by the -dump_modify color option. - -For continuous color maps, each entry has a *value* and a *color*\ . -The *value* is either a number within the range of values or *min* or -*max*\ . The *value* of the first entry must be *min* and the *value* -of the last entry must be *max*\ . Any entries in between must have -increasing values. Note that numeric values can be specified either -as absolute numbers or as fractions (0.0 to 1.0) of the range, -depending on the "a" or "f" in the style setting for the color map. - -Here is how the entries are used to determine the color of an -individual atom, given the value X of its atom attribute. X will fall -between 2 of the entry values. The color of the atom is linearly -interpolated (in each of the RGB values) between the 2 colors -associated with those entries. For example, if X = -5.0 and the 2 -surrounding entries are "red" at -10.0 and "blue" at 0.0, then the -atom's color will be halfway between "red" and "blue", which happens -to be "purple". - -For discrete color maps, each entry has a *lo* and *hi* value and a -*color*\ . The *lo* and *hi* settings are either numbers within the -range of values or *lo* can be *min* or *hi* can be *max*\ . The *lo* -and *hi* settings of the last entry must be *min* and *max*\ . Other -entries can have any *lo* and *hi* values and the sub-ranges of -different values can overlap. Note that numeric *lo* and *hi* values -can be specified either as absolute numbers or as fractions (0.0 to -1.0) of the range, depending on the "a" or "f" in the style setting -for the color map. - -Here is how the entries are used to determine the color of an -individual atom, given the value X of its atom attribute. The entries -are scanned from first to last. The first time that *lo* <= X <= -*hi*, X is assigned the color associated with that entry. You can -think of the last entry as assigning a default color (since it will -always be matched by X), and the earlier entries as colors that -override the default. Also note that no interpolation of a color RGB -is done. All atoms will be drawn with one of the colors in the list -of entries. - -For sequential color maps, each entry has only a *color*\ . Here is how -the entries are used to determine the color of an individual atom, -given the value X of its atom attribute. The range is partitioned -into N bins of width *binsize*\ . Thus X will fall in a specific bin -from 1 to N, say the Mth bin. If it falls on a boundary between 2 -bins, it is considered to be in the higher of the 2 bins. Each bin is -assigned a color from the E entries. If E < N, then the colors are -repeated. For example if 2 entries with colors red and green are -specified, then the odd numbered bins will be red and the even bins -green. The color of the atom is the color of its bin. Note that the -sequential color map is really a shorthand way of defining a discrete -color map without having to specify where all the bin boundaries are. - -Here is an example of using a sequential color map to color all the -atoms in individual molecules with a different color. See the -examples/pour/in.pour.2d.molecule input script for an example of how -this is used. - -.. code-block:: LAMMPS - - variable colors string & - "red green blue yellow white & - purple pink orange lime gray" - variable mol atom mol%10 - dump 1 all image 250 image.*.jpg v_mol type & - zoom 1.6 adiam 1.5 - dump_modify 1 pad 5 amap 0 10 sa 1 10 ${colors} - -In this case, 10 colors are defined, and molecule IDs are -mapped to one of the colors, even if there are 1000s of molecules. - ----------- - -The *backcolor* sets the background color of the images. The color -name can be any of the 140 pre-defined colors (see below) or a color -name defined by the dump_modify color option. - ----------- - -The *bcolor* keyword can be used with the :doc:`dump image ` -command, with its *bond* keyword, when its color setting is *type*, to -set the color that bonds of each type will be drawn in the image. - -The specified *type* should be an integer from 1 to Nbondtypes = the -number of bond types. A wildcard asterisk can be used in place of or -in conjunction with the *type* argument to specify a range of 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). - -The specified *color* can be a single color which is any of the 140 -pre-defined colors (see below) or a color name defined by the -dump_modify color option. Or it can be two or more colors separated -by a "/" character, e.g. red/green/blue. In the former case, that -color is assigned to all the specified bond types. In the latter -case, the list of colors are assigned in a round-robin fashion to each -of the specified bond types. - ----------- - -The *bdiam* keyword can be used with the :doc:`dump image ` -command, with its *bond* keyword, when its diam setting is *type*, to -set the diameter that bonds of each type will be drawn in the image. -The specified *type* should be an integer from 1 to Nbondtypes. As -with the *bcolor* keyword, a wildcard asterisk can be used as part of -the *type* argument to specify a range of bond types. The specified -*diam* is the size in whatever distance :doc:`units ` you are -using, e.g. Angstroms. - ----------- - -The *bitrate* keyword can be used with the :doc:`dump movie ` command to define the size of the resulting -movie file and its quality via setting how many kbits per second are -to be used for the movie file. Higher bitrates require less -compression and will result in higher quality movies. The quality is -also determined by the compression format and encoder. The default -setting is 2000 kbit/s, which will result in average quality with -older compression formats. - -.. note:: - - Not all movie file formats supported by dump movie allow the - bitrate to be set. If not, the setting is silently ignored. - ----------- - -The *boxcolor* keyword sets the color of the simulation box drawn -around the atoms in each image as well as the color of processor -sub-domain boundaries. See the "dump image box" command for how to -specify that a box be drawn via the *box* keyword, and the sub-domain -boundaries via the *subbox* keyword. The color name can be any of the -140 pre-defined colors (see below) or a color name defined by the -dump_modify color option. - ----------- - -The *color* keyword allows definition of a new color name, in addition -to the 140-predefined colors (see below), and associates 3 -red/green/blue RGB values with that color name. The color name can -then be used with any other dump_modify keyword that takes a color -name as a value. The RGB values should each be floating point values -between 0.0 and 1.0 inclusive. - -When a color name is converted to RGB values, the user-defined color -names are searched first, then the 140 pre-defined color names. This -means you can also use the *color* keyword to overwrite one of the -pre-defined color names with new RBG values. - ----------- - -The *framerate* keyword can be used with the :doc:`dump movie ` command to define the duration of the resulting -movie file. Movie files written by the dump *movie* command have a -default frame rate of 24 frames per second and the images generated -will be converted at that rate. Thus a sequence of 1000 dump images -will result in a movie of about 42 seconds. To make a movie run -longer you can either generate images more frequently or lower the -frame rate. To speed a movie up, you can do the inverse. Using a -frame rate higher than 24 is not recommended, as it will result in -simply dropping the rendered images. It is more efficient to dump -images less frequently. - ----------- - -The *header* keyword toggles whether the dump file will include a header. -Excluding a header will reduce the size of the dump file for fixes such as -:doc:`fix pair/tracker ` which do not require the information -typically written to the header. - ----------- - -The COMPRESS package offers both GZ and Zstd compression variants of styles -atom, custom, local, cfg, and xyz. When using these styles the compression -level can be controlled by the :code:`compression_level` parameter. File names -with these styles have to end in either :code:`.gz` or :code:`.zst`. - -GZ supports compression levels from -1 (default), 0 (no compression), and 1 to -9. 9 being the best compression. The COMPRESS :code:`/gz` styles use 9 as -default compression level. +GZ supports compression levels from -1 (default), 0 (no compression), +and 1 to +9. 9 being the best compression. The COMPRESS :code:`/gz` styles use 9 +as default compression level. Zstd offers a wider range of compression levels, including negative -levels that sacrifice compression for performance. 0 is the -default, positive levels are 1 to 22, with 22 being the most expensive +levels that sacrifice compression for performance. 0 is the default, +positive levels are 1 to 22, with 22 being the most expensive compression. Zstd promises higher compression/decompression speeds for similar compression ratios. For more details see `http://facebook.github.io/zstd/`. -In addition, Zstd compressed files can have a checksum of the entire -contents. The Zstd enabled dump styles enable this feature by default and it -can be disabled with the :code:`checksum` parameter. +In addition, Zstd compressed files can include a checksum of the +entire contents. The Zstd enabled dump styles enable this feature by +default and it can be disabled with the :code:`checksum` keyword. ---------- @@ -1046,100 +745,7 @@ The option defaults are * units = no * unwrap = no -* acolor = \* red/green/blue/yellow/aqua/cyan -* adiam = \* 1.0 -* amap = min max cf 0.0 2 min blue max red -* backcolor = black -* bcolor = \* red/green/blue/yellow/aqua/cyan -* bdiam = \* 0.5 -* bitrate = 2000 -* boxcolor = yellow -* color = 140 color names are pre-defined as listed below -* framerate = 24 - * compression_level = 9 (gz variants) * compression_level = 0 (zstd variants) * checksum = yes (zstd variants) ----------- - -These are the standard 109 element names that LAMMPS pre-defines for -use with the :doc:`dump image ` and dump_modify commands. - -* 1-10 = "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne" -* 11-20 = "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca" -* 21-30 = "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn" -* 31-40 = "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr" -* 41-50 = "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn" -* 51-60 = "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd" -* 61-70 = "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb" -* 71-80 = "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg" -* 81-90 = "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th" -* 91-100 = "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm" -* 101-109 = "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt" - ----------- - -These are the 140 colors that LAMMPS pre-defines for use with the -:doc:`dump image ` and dump_modify commands. Additional -colors can be defined with the dump_modify color command. The 3 -numbers listed for each name are the RGB (red/green/blue) values. -Divide each value by 255 to get the equivalent 0.0 to 1.0 value. - -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| aliceblue = 240, 248, 255 | antiquewhite = 250, 235, 215 | aqua = 0, 255, 255 | aquamarine = 127, 255, 212 | azure = 240, 255, 255 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| beige = 245, 245, 220 | bisque = 255, 228, 196 | black = 0, 0, 0 | blanchedalmond = 255, 255, 205 | blue = 0, 0, 255 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| blueviolet = 138, 43, 226 | brown = 165, 42, 42 | burlywood = 222, 184, 135 | cadetblue = 95, 158, 160 | chartreuse = 127, 255, 0 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| chocolate = 210, 105, 30 | coral = 255, 127, 80 | cornflowerblue = 100, 149, 237 | cornsilk = 255, 248, 220 | crimson = 220, 20, 60 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| cyan = 0, 255, 255 | darkblue = 0, 0, 139 | darkcyan = 0, 139, 139 | darkgoldenrod = 184, 134, 11 | darkgray = 169, 169, 169 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| darkgreen = 0, 100, 0 | darkkhaki = 189, 183, 107 | darkmagenta = 139, 0, 139 | darkolivegreen = 85, 107, 47 | darkorange = 255, 140, 0 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| darkorchid = 153, 50, 204 | darkred = 139, 0, 0 | darksalmon = 233, 150, 122 | darkseagreen = 143, 188, 143 | darkslateblue = 72, 61, 139 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| darkslategray = 47, 79, 79 | darkturquoise = 0, 206, 209 | darkviolet = 148, 0, 211 | deeppink = 255, 20, 147 | deepskyblue = 0, 191, 255 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| dimgray = 105, 105, 105 | dodgerblue = 30, 144, 255 | firebrick = 178, 34, 34 | floralwhite = 255, 250, 240 | forestgreen = 34, 139, 34 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| fuchsia = 255, 0, 255 | gainsboro = 220, 220, 220 | ghostwhite = 248, 248, 255 | gold = 255, 215, 0 | goldenrod = 218, 165, 32 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| gray = 128, 128, 128 | green = 0, 128, 0 | greenyellow = 173, 255, 47 | honeydew = 240, 255, 240 | hotpink = 255, 105, 180 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| indianred = 205, 92, 92 | indigo = 75, 0, 130 | ivory = 255, 240, 240 | khaki = 240, 230, 140 | lavender = 230, 230, 250 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| lavenderblush = 255, 240, 245 | lawngreen = 124, 252, 0 | lemonchiffon = 255, 250, 205 | lightblue = 173, 216, 230 | lightcoral = 240, 128, 128 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| lightcyan = 224, 255, 255 | lightgoldenrodyellow = 250, 250, 210 | lightgreen = 144, 238, 144 | lightgrey = 211, 211, 211 | lightpink = 255, 182, 193 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| lightsalmon = 255, 160, 122 | lightseagreen = 32, 178, 170 | lightskyblue = 135, 206, 250 | lightslategray = 119, 136, 153 | lightsteelblue = 176, 196, 222 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| lightyellow = 255, 255, 224 | lime = 0, 255, 0 | limegreen = 50, 205, 50 | linen = 250, 240, 230 | magenta = 255, 0, 255 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| maroon = 128, 0, 0 | mediumaquamarine = 102, 205, 170 | mediumblue = 0, 0, 205 | mediumorchid = 186, 85, 211 | mediumpurple = 147, 112, 219 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| mediumseagreen = 60, 179, 113 | mediumslateblue = 123, 104, 238 | mediumspringgreen = 0, 250, 154 | mediumturquoise = 72, 209, 204 | mediumvioletred = 199, 21, 133 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| midnightblue = 25, 25, 112 | mintcream = 245, 255, 250 | mistyrose = 255, 228, 225 | moccasin = 255, 228, 181 | navajowhite = 255, 222, 173 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| navy = 0, 0, 128 | oldlace = 253, 245, 230 | olive = 128, 128, 0 | olivedrab = 107, 142, 35 | orange = 255, 165, 0 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| orangered = 255, 69, 0 | orchid = 218, 112, 214 | palegoldenrod = 238, 232, 170 | palegreen = 152, 251, 152 | paleturquoise = 175, 238, 238 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| palevioletred = 219, 112, 147 | papayawhip = 255, 239, 213 | peachpuff = 255, 239, 213 | peru = 205, 133, 63 | pink = 255, 192, 203 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| plum = 221, 160, 221 | powderblue = 176, 224, 230 | purple = 128, 0, 128 | red = 255, 0, 0 | rosybrown = 188, 143, 143 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| royalblue = 65, 105, 225 | saddlebrown = 139, 69, 19 | salmon = 250, 128, 114 | sandybrown = 244, 164, 96 | seagreen = 46, 139, 87 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| seashell = 255, 245, 238 | sienna = 160, 82, 45 | silver = 192, 192, 192 | skyblue = 135, 206, 235 | slateblue = 106, 90, 205 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| slategray = 112, 128, 144 | snow = 255, 250, 250 | springgreen = 0, 255, 127 | steelblue = 70, 130, 180 | tan = 210, 180, 140 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| teal = 0, 128, 128 | thistle = 216, 191, 216 | tomato = 253, 99, 71 | turquoise = 64, 224, 208 | violet = 238, 130, 238 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ -| wheat = 245, 222, 179 | white = 255, 255, 255 | whitesmoke = 245, 245, 245 | yellow = 255, 255, 0 | yellowgreen = 154, 205, 50 | -+-------------------------------+--------------------------------------+---------------------------------+--------------------------------+--------------------------------+ diff --git a/doc/src/kspace_style.rst b/doc/src/kspace_style.rst index 1dec62bb43..b6287650b9 100644 --- a/doc/src/kspace_style.rst +++ b/doc/src/kspace_style.rst @@ -310,7 +310,7 @@ Forschungszentrum Juelich. The library is available for download at "http://scafacos.de" or can be cloned from the git-repository -"git://github.com/scafacos/scafacos.git". +"https://github.com/scafacos/scafacos.git". In order to use this KSpace style, you must download and build the ScaFaCoS library, then build LAMMPS with the SCAFACOS package diff --git a/doc/src/pair_meam.rst b/doc/src/pair_meam.rst index d091496325..022de60f98 100644 --- a/doc/src/pair_meam.rst +++ b/doc/src/pair_meam.rst @@ -28,16 +28,16 @@ Description as of November 2010; see description below of the mixture_ref_t parameter -Style *meam* computes pairwise interactions for a variety of materials -using modified embedded-atom method (MEAM) potentials +Pair style *meam* computes non-bonded interactions for a variety of materials +using the modified embedded-atom method (MEAM) :ref:`(Baskes) `. Conceptually, it is an extension to the original -:doc:`EAM potentials ` which adds angular forces. It is +:doc:`EAM method ` which adds angular forces. It is thus suitable for modeling metals and alloys with fcc, bcc, hcp and -diamond cubic structures, as well as covalently bonded materials like -silicon and carbon. Style *meam* is a translation of the (now obsolete) -*meam* code from Fortran to C++. It is functionally equivalent to *meam* -but more efficient, and thus *meam* has been removed from LAMMPS after -the 12 December 2018 release. +diamond cubic structures, as well as materials with covalent interactions +like silicon and carbon. This *meam* pair style is a translation of the +original Fortran version to C++. It is functionally equivalent but more +efficient and has additional features. The Fortran version of the *meam* +pair style has been removed from LAMMPS after the 12 December 2018 release. In the MEAM formulation, the total energy E of a system of atoms is given by: diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst index ff212a579a..24f882b658 100644 --- a/doc/src/read_data.rst +++ b/doc/src/read_data.rst @@ -254,7 +254,9 @@ the fix defines the syntax of the header line(s) and section that it reads from the data file. Note that the *header-string* can be specified as NULL, in which case no header lines are passed to the fix. This means the fix can infer the length of its Section from -standard header settings, such as the number of atoms. +standard header settings, such as the number of atoms. Also the +*section-string* may be specified as NULL, and in that case the fix +ID is used as section name. The formatting of individual lines in the data file (indentation, spacing between words and numbers) is not important except that header diff --git a/doc/utils/requirements.txt b/doc/utils/requirements.txt index 9b8e106875..9797d4d119 100644 --- a/doc/utils/requirements.txt +++ b/doc/utils/requirements.txt @@ -1,6 +1,6 @@ Sphinx sphinxcontrib-spelling -git+git://github.com/akohlmey/sphinx-fortran@parallel-read +git+https://github.com/akohlmey/sphinx-fortran@parallel-read sphinx_tabs breathe Pygments diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index e237c42d41..8bef055ad3 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -44,7 +44,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Need -restrict with Intel compilers -if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict") endif() diff --git a/examples/rigid/data.rigid-property b/examples/rigid/data.rigid-property index 66fc42d2d2..31c555afeb 100644 --- a/examples/rigid/data.rigid-property +++ b/examples/rigid/data.rigid-property @@ -99,7 +99,7 @@ Atoms 80 1 10 9.5 0 81 1 10 10 0 -Bodies +Clumps 1 1 2 1 diff --git a/examples/rigid/in.rigid.property b/examples/rigid/in.rigid.property index 53d62776e6..323781cd45 100644 --- a/examples/rigid/in.rigid.property +++ b/examples/rigid/in.rigid.property @@ -8,7 +8,7 @@ pair_style lj/cut 2.5 fix 0 all property/atom i_bodies -read_data data.rigid-property fix 0 NULL Bodies +read_data data.rigid-property fix 0 NULL Clumps velocity all create 100.0 4928459 diff --git a/lib/gpu/lal_atom.cu b/lib/gpu/lal_atom.cu index 1418459301..287d72803c 100644 --- a/lib/gpu/lal_atom.cu +++ b/lib/gpu/lal_atom.cu @@ -18,7 +18,7 @@ #endif __kernel void kernel_cast_x(__global numtyp4 *restrict x_type, - const __global double *restrict x, + const __global numtyp *restrict x, const __global int *restrict type, const int nall) { int ii=GLOBAL_ID_X; diff --git a/lib/gpu/lal_atom.h b/lib/gpu/lal_atom.h index 3cf97d94a0..77c1faa784 100644 --- a/lib/gpu/lal_atom.h +++ b/lib/gpu/lal_atom.h @@ -475,7 +475,7 @@ class Atom { UCL_Vector v; #ifdef GPU_CAST - UCL_Vector x_cast; + UCL_Vector x_cast; UCL_Vector type_cast; #endif diff --git a/lib/gpu/lal_zbl.cu b/lib/gpu/lal_zbl.cu index 09e1b4f6bb..2a7d4795da 100644 --- a/lib/gpu/lal_zbl.cu +++ b/lib/gpu/lal_zbl.cu @@ -82,9 +82,9 @@ __kernel void k_zbl(const __global numtyp4 *restrict x_, const __global numtyp4 *restrict coeff1, const __global numtyp4 *restrict coeff2, const __global numtyp4 *restrict coeff3, - const double cut_globalsq, - const double cut_innersq, - const double cut_inner, + const numtyp cut_globalsq, + const numtyp cut_innersq, + const numtyp cut_inner, const int lj_types, const __global int *dev_nbor, const __global int *dev_packed, @@ -174,9 +174,9 @@ __kernel void k_zbl_fast(const __global numtyp4 *restrict x_, const __global numtyp4 *restrict coeff1_in, const __global numtyp4 *restrict coeff2_in, const __global numtyp4 *restrict coeff3_in, - const double cut_globalsq, - const double cut_innersq, - const double cut_inner, + const numtyp cut_globalsq, + const numtyp cut_innersq, + const numtyp cut_inner, const __global int *dev_nbor, const __global int *dev_packed, __global acctyp4 *restrict ans, diff --git a/lib/gpu/lal_zbl.h b/lib/gpu/lal_zbl.h index af4f1b2eac..b7b525661c 100644 --- a/lib/gpu/lal_zbl.h +++ b/lib/gpu/lal_zbl.h @@ -67,9 +67,9 @@ class ZBL : public BaseAtomic { /// If atom type constants fit in shared memory, use fast kernels bool shared_types; - double _cut_globalsq; - double _cut_innersq; - double _cut_inner; + numtyp _cut_globalsq; + numtyp _cut_innersq; + numtyp _cut_inner; /// Number of atom types int _lj_types; diff --git a/lib/pace/Install.py b/lib/pace/Install.py index e90ae8c312..5b968732c9 100644 --- a/lib/pace/Install.py +++ b/lib/pace/Install.py @@ -15,12 +15,14 @@ from install_helpers import fullpath, geturl, checkmd5sum # settings thisdir = fullpath('.') -version = 'v.2021.4.9' +version = 'v.2021.10.25' # known checksums for different PACE versions. used to validate the download. checksums = { \ 'v.2021.2.3.upd2' : '8fd1162724d349b930e474927197f20d', 'v.2021.4.9' : '4db54962fbd6adcf8c18d46e1798ceb5', + 'v.2021.9.28' : 'f98363bb98adc7295ea63974738c2a1b', + 'v.2021.10.25' : 'a2ac3315c41a1a4a5c912bcb1bc9c5cc' } diff --git a/lib/pace/Makefile b/lib/pace/Makefile index c2e1892ddd..81f7c9db95 100644 --- a/lib/pace/Makefile +++ b/lib/pace/Makefile @@ -2,8 +2,11 @@ SHELL = /bin/sh # ------ FILES ------ -SRC_FILES = $(wildcard src/USER-PACE/*.cpp) -SRC = $(filter-out src/USER-PACE/pair_pace.cpp, $(SRC_FILES)) +YAML_CPP_PATH = src/yaml-cpp +YAML_CPP_INC = $(YAML_CPP_PATH)/include + +SRC_FILES = $(wildcard src/ML-PACE/*.cpp) +SRC = $(filter-out src/ML-PACE/pair_pace.cpp, $(SRC_FILES)) # ------ DEFINITIONS ------ @@ -12,7 +15,7 @@ OBJ = $(SRC:.cpp=.o) # ------ SETTINGS ------ -CXXFLAGS = -O3 -fPIC -Isrc/USER-PACE +CXXFLAGS = -O3 -fPIC -Isrc/ML-PACE -I$(YAML_CPP_INC) ARCHIVE = ar ARCHFLAG = -rc @@ -21,9 +24,13 @@ SYSLIB = # ------ MAKE PROCEDURE ------ -lib: $(OBJ) +lib: $(OBJ) lib-yaml-cpp $(ARCHIVE) $(ARFLAGS) $(LIB) $(OBJ) + +lib-yaml-cpp: + cd $(YAML_CPP_PATH) && $(MAKE) lib + # ------ COMPILE RULES ------ %.o: %.cpp @@ -32,6 +39,9 @@ lib: $(OBJ) # ------ CLEAN ------ clean-all: -rm -f *~ $(OBJ) $(LIB) + cd $(YAML_CPP_PATH) && $(MAKE) clean-all clean-build: -rm -f *~ $(OBJ) + cd $(YAML_CPP_PATH) && $(MAKE) clean-build + diff --git a/lib/pace/Makefile.lammps b/lib/pace/Makefile.lammps index 17820716df..f4cbeb8ffd 100644 --- a/lib/pace/Makefile.lammps +++ b/lib/pace/Makefile.lammps @@ -1,3 +1,3 @@ -pace_SYSINC =-I../../lib/pace/src/USER-PACE -pace_SYSLIB = -L../../lib/pace/ -lpace +pace_SYSINC =-I../../lib/pace/src/ML-PACE -I../../lib/pace/src/yaml-cpp/include +pace_SYSLIB = -L../../lib/pace/ -lpace -L../../lib/pace/src/yaml-cpp/ -lyaml-cpp pace_SYSPATH = diff --git a/python/examples/matplotlib_plot.py b/python/examples/matplotlib_plot.py index b85d40c4c4..0c918507ad 100755 --- a/python/examples/matplotlib_plot.py +++ b/python/examples/matplotlib_plot.py @@ -62,7 +62,6 @@ if me == 0: plt.show(block=False) # run nfreq steps at a time w/out pre/post, query compute, refresh plot -import time while ntimestep < nsteps: lmp.command("run %d pre no post no" % nfreq) diff --git a/python/examples/simple.py b/python/examples/simple.py index 861a208895..8925ce48c0 100755 --- a/python/examples/simple.py +++ b/python/examples/simple.py @@ -13,7 +13,6 @@ from __future__ import print_function import sys -import numpy as np import ctypes # parse command line diff --git a/python/lammps/core.py b/python/lammps/core.py index 7dea6e5e6e..fcd5c76ad5 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -99,7 +99,7 @@ class lammps(object): # load a shared object. try: - if ptr: self.lib = CDLL("",RTLD_GLOBAL) + if ptr is not None: self.lib = CDLL("",RTLD_GLOBAL) except OSError: self.lib = None @@ -329,7 +329,7 @@ class lammps(object): # ptr is the desired instance of LAMMPS # just convert it to ctypes ptr and store in self.lmp - if not ptr: + if ptr is None: # with mpi4py v2+, we can pass MPI communicators to LAMMPS # need to adjust for type of MPI communicator object @@ -338,7 +338,7 @@ class lammps(object): from mpi4py import MPI self.MPI = MPI - if comm: + if comm is not None: if not self.has_mpi_support: raise Exception('LAMMPS not compiled with real MPI library') if not self.has_mpi4py: @@ -354,7 +354,7 @@ class lammps(object): narg = 0 cargs = None - if cmdargs: + if cmdargs is not None: cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): @@ -376,7 +376,7 @@ class lammps(object): if self.has_mpi4py and self.has_mpi_support: self.comm = self.MPI.COMM_WORLD self.opened = 1 - if cmdargs: + if cmdargs is not None: cmdargs.insert(0,"lammps") narg = len(cmdargs) for i in range(narg): @@ -1361,7 +1361,7 @@ class lammps(object): This function is a wrapper around the :cpp:func:`lammps_create_atoms` function of the C-library interface, and the behavior is similar except that the *v*, *image*, and *shrinkexceed* arguments are optional and - default to *None*, *None*, and *False*, respectively. With none being + default to *None*, *None*, and *False*, respectively. With *None* being equivalent to a ``NULL`` pointer in C. The lists of coordinates, types, atom IDs, velocities, image flags can @@ -1389,7 +1389,7 @@ class lammps(object): :return: number of atoms created. 0 if insufficient or invalid data :rtype: int """ - if id: + if id is not None: id_lmp = (self.c_tagint*n)() try: id_lmp[:] = id[0:n] @@ -1411,7 +1411,7 @@ class lammps(object): except ValueError: return 0 - if v: + if v is not None: v_lmp = (c_double*(three_n))() try: v_lmp[:] = v[0:three_n] @@ -1420,7 +1420,7 @@ class lammps(object): else: v_lmp = None - if image: + if image is not None: img_lmp = (self.c_imageint*n)() try: img_lmp[:] = image[0:n] diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index a6e3578aef..abd4d6da98 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -854,30 +854,30 @@ class IPyLammps(PyLammps): """ cmd_args = [group, "image", filename, color, diameter] - if size: + if size is not None: width = size[0] height = size[1] cmd_args += ["size", width, height] - if view: + if view is not None: theta = view[0] phi = view[1] cmd_args += ["view", theta, phi] - if center: + if center is not None: flag = center[0] Cx = center[1] Cy = center[2] Cz = center[3] cmd_args += ["center", flag, Cx, Cy, Cz] - if up: + if up is not None: Ux = up[0] Uy = up[1] Uz = up[2] cmd_args += ["up", Ux, Uy, Uz] - if zoom: + if zoom is not None: cmd_args += ["zoom", zoom] cmd_args.append("modify backcolor " + background_color) diff --git a/src/.gitignore b/src/.gitignore index 7da6b7feb7..5c6d732a69 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1174,6 +1174,8 @@ /pair_oxrna2_*.cpp /pair_oxrna2_*.h /mf_oxdna.h +/pair_peri.cpp +/pair_peri.h /pair_peri_eps.cpp /pair_peri_eps.h /pair_peri_lps.cpp diff --git a/src/AWPMD/pair_awpmd_cut.cpp b/src/AWPMD/pair_awpmd_cut.cpp index 682a0dd3d6..15cd316f12 100644 --- a/src/AWPMD/pair_awpmd_cut.cpp +++ b/src/AWPMD/pair_awpmd_cut.cpp @@ -246,8 +246,8 @@ void PairAWPMDCut::compute(int eflag, int vflag) fi= new Vector_3[wpmd->ni]; // adding electrons - for (std::map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { - std::vector &el=it->second; + for (auto & it : etmap) { + std::vector &el=it.second; if (!el.size()) // should not happen continue; int s=spin[el[0]] >0 ? 0 : 1; diff --git a/src/DPD-REACT/fix_eos_table.cpp b/src/DPD-REACT/fix_eos_table.cpp index c9c23b51f8..61b4e7501a 100644 --- a/src/DPD-REACT/fix_eos_table.cpp +++ b/src/DPD-REACT/fix_eos_table.cpp @@ -207,7 +207,7 @@ void FixEOStable::read_table(Table *tb, Table *tb2, char *file, char *keyword) // loop until section found with matching keyword - while (1) { + while (true) { if (fgets(line,MAXLINE,fp) == nullptr) error->one(FLERR,"Did not find keyword in table file"); if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line diff --git a/src/DPD-REACT/fix_eos_table_rx.cpp b/src/DPD-REACT/fix_eos_table_rx.cpp index b39e029c3e..5e950642d3 100644 --- a/src/DPD-REACT/fix_eos_table_rx.cpp +++ b/src/DPD-REACT/fix_eos_table_rx.cpp @@ -321,7 +321,7 @@ void FixEOStableRX::read_file(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -427,7 +427,7 @@ void FixEOStableRX::read_table(Table *tb, Table *tb2, char *file, char *keyword) // loop until section found with matching keyword - while (1) { + while (true) { if (fgets(line,MAXLINE,fp) == nullptr) error->one(FLERR,"Did not find keyword in table file"); if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line diff --git a/src/DPD-REACT/fix_rx.cpp b/src/DPD-REACT/fix_rx.cpp index f21914e2d5..165a3a6dbf 100644 --- a/src/DPD-REACT/fix_rx.cpp +++ b/src/DPD-REACT/fix_rx.cpp @@ -255,7 +255,7 @@ void FixRX::post_constructor() int eof = 0; char * word; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -804,7 +804,7 @@ void FixRX::read_file(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -858,7 +858,7 @@ void FixRX::read_file(char *file) nreactions=0; sign = -1.0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -1155,7 +1155,7 @@ int FixRX::rkf45_h0 (const int neq, const double t, const double /*t_stop*/, // compute ydot at t=t0 rhs (t, y, ydot, v_params); - while (1) + while (true) { // Estimate y'' with finite-difference ... @@ -1254,7 +1254,7 @@ void FixRX::odeDiagnostics() double max_per_proc[numCounters]; double min_per_proc[numCounters]; - if (1) + if (true) { static bool firstStep = true; @@ -1285,7 +1285,7 @@ void FixRX::odeDiagnostics() printf("me= %d nst= %g nfc= %g time= %g nlocal= %g lmpnst= %g weight_idx= %d 1st= %d aveNeigh= %g\n", comm->me, this->diagnosticCounter[0], this->diagnosticCounter[1], this->diagnosticCounter[2], this->diagnosticCounter[3], this->diagnosticCounter[4], rx_weight_index, firstStep, averageNumNeighbors); - if (rx_weight_index != -1 && !firstStep && 0) + if (rx_weight_index != -1 && !firstStep && false) { double *rx_weight = atom->dvector[rx_weight_index]; diff --git a/src/DPD-REACT/pair_exp6_rx.cpp b/src/DPD-REACT/pair_exp6_rx.cpp index b0b9f97ca2..313e9f2583 100644 --- a/src/DPD-REACT/pair_exp6_rx.cpp +++ b/src/DPD-REACT/pair_exp6_rx.cpp @@ -731,7 +731,7 @@ void PairExp6rx::read_file(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -838,7 +838,7 @@ void PairExp6rx::read_file2(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { diff --git a/src/DPD-REACT/pair_multi_lucy.cpp b/src/DPD-REACT/pair_multi_lucy.cpp index 9f5e494991..4aaea3f81b 100644 --- a/src/DPD-REACT/pair_multi_lucy.cpp +++ b/src/DPD-REACT/pair_multi_lucy.cpp @@ -356,7 +356,7 @@ void PairMultiLucy::read_table(Table *tb, char *file, char *keyword) // loop until section found with matching keyword - while (1) { + while (true) { if (fgets(line,MAXLINE,fp) == nullptr) error->one(FLERR,"Did not find keyword in table file"); if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line diff --git a/src/DPD-REACT/pair_multi_lucy_rx.cpp b/src/DPD-REACT/pair_multi_lucy_rx.cpp index c386abded4..eac047d9f7 100644 --- a/src/DPD-REACT/pair_multi_lucy_rx.cpp +++ b/src/DPD-REACT/pair_multi_lucy_rx.cpp @@ -496,7 +496,7 @@ void PairMultiLucyRX::read_table(Table *tb, char *file, char *keyword) // loop until section found with matching keyword - while (1) { + while (true) { if (fgets(line,MAXLINE,fp) == nullptr) error->one(FLERR,"Did not find keyword in table file"); if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line diff --git a/src/EXTRA-FIX/fix_gle.cpp b/src/EXTRA-FIX/fix_gle.cpp index 8f31613188..de225c6980 100644 --- a/src/EXTRA-FIX/fix_gle.cpp +++ b/src/EXTRA-FIX/fix_gle.cpp @@ -234,7 +234,7 @@ FixGLE::FixGLE(LAMMPS *lmp, int narg, char **arg) : char line[MAXLINE],*ptr; int n,nwords,ndone=0,eof=0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fgle); if (ptr == nullptr) { @@ -300,7 +300,7 @@ FixGLE::FixGLE(LAMMPS *lmp, int narg, char **arg) : ndone = eof = 0; const double cfac = force->boltz / force->mvv2e; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fgle); if (ptr == nullptr) { diff --git a/src/EXTRA-FIX/fix_wall_ees.cpp b/src/EXTRA-FIX/fix_wall_ees.cpp index c224e59d12..26ed4f52f1 100644 --- a/src/EXTRA-FIX/fix_wall_ees.cpp +++ b/src/EXTRA-FIX/fix_wall_ees.cpp @@ -121,8 +121,10 @@ void FixWallEES::wall_particle(int m, int which, double coord) double* shape = bonus[ellipsoid[i]].shape;; MathExtra::quat_to_mat(bonus[ellipsoid[i]].quat,A); MathExtra::transpose_matvec(A,nhat,tempvec); - for (int k = 0; k<3; k++) tempvec[k] *= shape[k]; - for (int k = 0; k<3 ; k++) sigman2 += tempvec[k]*tempvec[k]; + for (int k = 0; k<3; k++) { + tempvec[k] *= shape[k]; + sigman2 += tempvec[k]*tempvec[k]; + } sigman = sqrt(sigman2); if (delta <= sigman) { diff --git a/src/EXTRA-FIX/fix_wall_region_ees.cpp b/src/EXTRA-FIX/fix_wall_region_ees.cpp index 81a67e8e58..261036333e 100644 --- a/src/EXTRA-FIX/fix_wall_region_ees.cpp +++ b/src/EXTRA-FIX/fix_wall_region_ees.cpp @@ -194,8 +194,10 @@ void FixWallRegionEES::post_force(int /*vflag*/) nhat[(which+2)%3] = 0 ; sn2 = 0 ; MathExtra::transpose_matvec(A,nhat,tempvec); - for (int k = 0; k<3; k++) tempvec[k] *= shape[k]; - for (int k = 0; k<3 ; k++) sn2 += tempvec[k]*tempvec[k]; + for (int k = 0; k<3; k++) { + tempvec[k] *= shape[k]; + sn2 += tempvec[k]*tempvec[k]; + } sn = sqrt(sn2); tooclose[which] = sn; } @@ -321,9 +323,11 @@ void FixWallRegionEES::ees(int m, int i) sigman2 = 0.0; MathExtra::transpose_matvec(A,nhat,tempvec); - for (int k = 0; k<3; k++) tempvec[k] *= shape[k]; - for (int k = 0; k<3; k++) sigman2 += tempvec[k]*tempvec[k]; - for (int k = 0; k<3; k++) SAn[k] = tempvec[k]; + for (int k = 0; k<3; k++) { + tempvec[k] *= shape[k]; + sigman2 += tempvec[k]*tempvec[k]; + SAn[k] = tempvec[k]; + } sigman = sqrt(sigman2); delta = fabs(region->contact[m].r); diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index b73593b1d7..34963430e3 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -41,7 +41,6 @@ using namespace MathConst; enum{ATOM,MOLECULE}; enum{ONE,RANGE,POLY}; -enum{CONSTANT,EQUAL}; // same as FixGravity #define EPSILON 0.001 #define SMALL 1.0e-10 @@ -186,10 +185,12 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : // grav = gravity in distance/time^2 units // assume grav = -magnitude at this point, enforce in init() - int ifix = modify->find_fix_by_style("^gravity"); - if (ifix == -1) - error->all(FLERR,"No fix gravity defined for fix pour"); - grav = - ((FixGravity *) modify->fix[ifix])->magnitude * force->ftm2v; + auto fixlist = modify->get_fix_by_style("^gravity"); + if (fixlist.size() != 1) + error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + auto fixgrav = (FixGravity *)fixlist.front(); + + grav = -fixgrav->magnitude * force->ftm2v; // nfreq = timesteps between insertions // should be time for a particle to fall from top of insertion region @@ -208,9 +209,8 @@ FixPour::FixPour(LAMMPS *lmp, int narg, char **arg) : v_relative = vy - rate; delta = yhi - ylo; } - double t = - (-v_relative - sqrt(v_relative*v_relative - 2.0*grav*delta)) / grav; - nfreq = static_cast (t/update->dt + 0.5); + double t = (-v_relative - sqrt(v_relative*v_relative - 2.0*grav*delta)) / grav; + nfreq = static_cast(t/update->dt + 0.5); // 1st insertion on next timestep @@ -309,17 +309,16 @@ void FixPour::init() // for 3d must point in -z, for 2d must point in -y // else insertion cannot work - int ifix = modify->find_fix_by_style("^gravity"); - if (ifix == -1) - error->all(FLERR,"No fix gravity defined for fix pour"); - - int varflag = ((FixGravity *) modify->fix[ifix])->varflag; - if (varflag != CONSTANT) + auto fixlist = modify->get_fix_by_style("^gravity"); + if (fixlist.size() != 1) + error->all(FLERR,"There must be exactly one fix gravity defined for fix pour"); + auto fixgrav = (FixGravity *)fixlist.front(); + if (fixgrav->varflag != FixGravity::CONSTANT) error->all(FLERR,"Fix gravity for fix pour must be constant"); - double xgrav = ((FixGravity *) modify->fix[ifix])->xgrav; - double ygrav = ((FixGravity *) modify->fix[ifix])->ygrav; - double zgrav = ((FixGravity *) modify->fix[ifix])->zgrav; + double xgrav = fixgrav->xgrav; + double ygrav = fixgrav->ygrav; + double zgrav = fixgrav->zgrav; if (domain->dimension == 3) { if (fabs(xgrav) > EPSILON || fabs(ygrav) > EPSILON || @@ -331,37 +330,29 @@ void FixPour::init() error->all(FLERR,"Gravity must point in -y to use with fix pour in 2d"); } - double gnew = - ((FixGravity *) modify->fix[ifix])->magnitude * force->ftm2v; - if (gnew != grav) - error->all(FLERR,"Gravity changed since fix pour was created"); + double gnew = -fixgrav->magnitude * force->ftm2v; + if (gnew != grav) error->all(FLERR,"Gravity changed since fix pour was created"); // if rigidflag defined, check for rigid/small fix // its molecule template must be same as this one - fixrigid = nullptr; if (rigidflag) { - int ifix = modify->find_fix(idrigid); - if (ifix < 0) error->all(FLERR,"Fix pour rigid fix does not exist"); - fixrigid = modify->fix[ifix]; + fixrigid = modify->get_fix_by_id(idrigid); + if (!fixrigid) error->all(FLERR,"Fix pour rigid fix does not exist"); int tmp; if (onemols != (Molecule **) fixrigid->extract("onemol",tmp)) - error->all(FLERR, - "Fix pour and fix rigid/small not using " - "same molecule template ID"); + error->all(FLERR,"Fix pour and fix rigid/small not using same molecule template ID"); } // if shakeflag defined, check for SHAKE fix // its molecule template must be same as this one - fixshake = nullptr; if (shakeflag) { - int ifix = modify->find_fix(idshake); - if (ifix < 0) error->all(FLERR,"Fix pour shake fix does not exist"); - fixshake = modify->fix[ifix]; + fixshake = modify->get_fix_by_id(idshake); + if (!fixshake) error->all(FLERR,"Fix pour shake fix does not exist"); int tmp; if (onemols != (Molecule **) fixshake->extract("onemol",tmp)) - error->all(FLERR,"Fix pour and fix shake not using " - "same molecule template ID"); + error->all(FLERR,"Fix pour and fix shake not using same molecule template ID"); } } @@ -851,7 +842,7 @@ void FixPour::xyz_random(double h, double *coord) coord[2] = h; } else { double r1,r2; - while (1) { + while (true) { r1 = random->uniform() - 0.5; r2 = random->uniform() - 0.5; if (r1*r1 + r2*r2 < 0.25) break; diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index 9bf2ae12d2..c9cdba1e35 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -451,24 +451,29 @@ void PairGranHookeHistory::init_style() // check for FixFreeze and set freeze_group_bit - int ifreeze = modify->find_fix_by_style("^freeze"); - if (ifreeze < 0) + auto fixlist = modify->get_fix_by_style("^freeze"); + if (fixlist.size() == 0) freeze_group_bit = 0; + else if (fixlist.size() > 1) + error->all(FLERR, "Only one fix freeze command at a time allowed"); else - freeze_group_bit = modify->fix[ifreeze]->groupbit; + freeze_group_bit = fixlist.front()->groupbit; // check for FixRigid so can extract rigid body masses - // FIXME: this only catches the first rigid fix, there may be multiple. fix_rigid = nullptr; - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) break; - if (i < modify->nfix) fix_rigid = modify->fix[i]; + for (const auto &ifix : modify->get_fix_list()) { + if (ifix->rigid_flag) { + if (fix_rigid) + error->all(FLERR, "Only one fix rigid command at a time allowed"); + else fix_rigid = ifix; + } + } // check for FixPour and FixDeposit so can extract particle radii - int ipour = modify->find_fix_by_style("^pour"); - int idep = modify->find_fix_by_style("^deposit"); + auto pours = modify->get_fix_by_style("^pour"); + auto deps = modify->get_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -476,13 +481,15 @@ void PairGranHookeHistory::init_style() int itype; for (i = 1; i <= atom->ntypes; i++) { onerad_dynamic[i] = onerad_frozen[i] = 0.0; - if (ipour >= 0) { + for (auto &ipour : pours) { itype = i; - onerad_dynamic[i] = *((double *) modify->fix[ipour]->extract("radius", itype)); + double maxrad = *((double *) ipour->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } - if (idep >= 0) { + for (auto &idep : deps) { itype = i; - onerad_dynamic[i] = *((double *) modify->fix[idep]->extract("radius", itype)); + double maxrad = *((double *) idep->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } } @@ -491,11 +498,12 @@ void PairGranHookeHistory::init_style() int *type = atom->type; int nlocal = atom->nlocal; - for (i = 0; i < nlocal; i++) + for (i = 0; i < nlocal; i++) { if (mask[i] & freeze_group_bit) onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]], radius[i]); else onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]], radius[i]); + } MPI_Allreduce(&onerad_dynamic[1], &maxrad_dynamic[1], atom->ntypes, MPI_DOUBLE, MPI_MAX, world); MPI_Allreduce(&onerad_frozen[1], &maxrad_frozen[1], atom->ntypes, MPI_DOUBLE, MPI_MAX, world); @@ -503,9 +511,8 @@ void PairGranHookeHistory::init_style() // set fix which stores history info if (history) { - int ifix = modify->find_fix("NEIGH_HISTORY_HH" + std::to_string(instance_me)); - if (ifix < 0) error->all(FLERR, "Could not find pair fix neigh history ID"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + fix_history = (FixNeighHistory *) modify->get_fix_by_id("NEIGH_HISTORY_HH" + std::to_string(instance_me)); + if (!fix_history) error->all(FLERR,"Could not find pair fix neigh history ID"); } } diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index 2846403e4c..8bcfc723ac 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -1130,22 +1130,29 @@ void PairGranular::init_style() // check for FixFreeze and set freeze_group_bit - int ifix = modify->find_fix_by_style("^freeze"); - if (ifix < 0) freeze_group_bit = 0; - else freeze_group_bit = modify->fix[ifix]->groupbit; + auto fixlist = modify->get_fix_by_style("^freeze"); + if (fixlist.size() == 0) + freeze_group_bit = 0; + else if (fixlist.size() > 1) + error->all(FLERR, "Only one fix freeze command at a time allowed"); + else + freeze_group_bit = fixlist.front()->groupbit; // check for FixRigid so can extract rigid body masses - // FIXME: this only catches the first rigid fix, there may be multiple. fix_rigid = nullptr; - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) break; - if (i < modify->nfix) fix_rigid = modify->fix[i]; + for (const auto &ifix : modify->get_fix_list()) { + if (ifix->rigid_flag) { + if (fix_rigid) + error->all(FLERR, "Only one fix rigid command at a time allowed"); + else fix_rigid = ifix; + } + } // check for FixPour and FixDeposit so can extract particle radii - int ipour = modify->find_fix_by_style("^pour"); - int idep = modify->find_fix_by_style("^deposit"); + auto pours = modify->get_fix_by_style("^pour"); + auto deps = modify->get_fix_by_style("^deposit"); // set maxrad_dynamic and maxrad_frozen for each type // include future FixPour and FixDeposit particles as dynamic @@ -1153,15 +1160,15 @@ void PairGranular::init_style() int itype; for (i = 1; i <= atom->ntypes; i++) { onerad_dynamic[i] = onerad_frozen[i] = 0.0; - if (ipour >= 0) { + for (auto &ipour : pours) { itype = i; - double radmax = *((double *) modify->fix[ipour]->extract("radius",itype)); - onerad_dynamic[i] = radmax; + double maxrad = *((double *) ipour->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } - if (idep >= 0) { + for (auto &idep : deps) { itype = i; - double radmax = *((double *) modify->fix[idep]->extract("radius",itype)); - onerad_dynamic[i] = radmax; + double maxrad = *((double *) idep->extract("radius", itype)); + if (maxrad > 0.0) onerad_dynamic[i] = maxrad; } } @@ -1171,12 +1178,10 @@ void PairGranular::init_style() int nlocal = atom->nlocal; for (i = 0; i < nlocal; i++) { - double radius_cut = radius[i]; - if (mask[i] & freeze_group_bit) { - onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]],radius_cut); - } else { - onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]],radius_cut); - } + if (mask[i] & freeze_group_bit) + onerad_frozen[type[i]] = MAX(onerad_frozen[type[i]], radius[i]); + else + onerad_dynamic[type[i]] = MAX(onerad_dynamic[type[i]], radius[i]); } MPI_Allreduce(&onerad_dynamic[1],&maxrad_dynamic[1],atom->ntypes,MPI_DOUBLE,MPI_MAX,world); @@ -1185,9 +1190,8 @@ void PairGranular::init_style() // set fix which stores history info if (size_history > 0) { - int ifix = modify->find_fix("NEIGH_HISTORY_GRANULAR"); - if (ifix < 0) error->all(FLERR,"Could not find pair fix neigh history ID"); - fix_history = (FixNeighHistory *) modify->fix[ifix]; + fix_history = (FixNeighHistory *) modify->get_fix_by_id("NEIGH_HISTORY_GRANULAR"); + if (!fix_history) error->all(FLERR,"Could not find pair fix neigh history ID"); } } diff --git a/src/KIM/kim_init.cpp b/src/KIM/kim_init.cpp index a4003b7510..2c8a19251f 100644 --- a/src/KIM/kim_init.cpp +++ b/src/KIM/kim_init.cpp @@ -251,17 +251,15 @@ void KimInit::determine_model_type_and_units(char *model_name, char *user_units, return; } else if (unit_conversion_mode) { KIM_Model_Destroy(&pkim); - int const num_systems = 5; - char const *const systems[num_systems] = {"metal", "real", "si", "cgs", "electron"}; - for (int i = 0; i < num_systems; ++i) { - get_kim_unit_names(systems[i], lengthUnit, energyUnit, chargeUnit, temperatureUnit, - timeUnit, error); + const char * unit_systems[] = {"metal", "real", "si", "cgs", "electron"}; + for (auto units : unit_systems) { + get_kim_unit_names(units, lengthUnit, energyUnit, chargeUnit, temperatureUnit, timeUnit, error); kim_error = KIM_Model_Create(KIM_NUMBERING_zeroBased, lengthUnit, energyUnit, chargeUnit, temperatureUnit, timeUnit, model_name, &units_accepted, &pkim); if (units_accepted) { logID = fmt::format("{}_Model", comm->me); KIM_Model_SetLogID(pkim, logID.c_str()); - *model_units = utils::strdup(systems[i]); + *model_units = utils::strdup(units); return; } KIM_Model_Destroy(&pkim); diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index 9a3aee87c0..74ac40198c 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -293,7 +293,7 @@ void KimInteractions::KIM_SET_TYPE_PARAMETERS(const std::string &input_line) con char line[MAXLINE], *ptr; int n, eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line, MAXLINE,fp); if (ptr == nullptr) { diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp index 63fb1e7a53..8379dc8f46 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp @@ -1966,7 +1966,7 @@ void FixACKS2ReaxFFKokkos::get_chi_field() namespace LAMMPS_NS { template class FixACKS2ReaxFFKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixACKS2ReaxFFKokkos; #endif } diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.h b/src/KOKKOS/fix_acks2_reaxff_kokkos.h index 67c737498f..bce90e97a3 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.h +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.h @@ -299,7 +299,7 @@ struct FixACKS2ReaxFFKokkosComputeHFunctor { c.template compute_h_team(team, atoms_per_team, vector_length); } - size_t team_shmem_size(int team_size) const { + size_t team_shmem_size(int /*team_size*/) const { size_t shmem_size = Kokkos::View::shmem_size( atoms_per_team) + // s_ilist @@ -347,7 +347,7 @@ struct FixACKS2ReaxFFKokkosComputeXFunctor { c.template compute_x_team(team, atoms_per_team, vector_length); } - size_t team_shmem_size(int team_size) const { + size_t team_shmem_size(int /*team_size*/) const { size_t shmem_size = Kokkos::View::shmem_size( atoms_per_team) + // s_ilist diff --git a/src/KOKKOS/fix_gravity_kokkos.cpp b/src/KOKKOS/fix_gravity_kokkos.cpp index ec6afbc133..63ac87a786 100644 --- a/src/KOKKOS/fix_gravity_kokkos.cpp +++ b/src/KOKKOS/fix_gravity_kokkos.cpp @@ -24,8 +24,6 @@ using namespace LAMMPS_NS; -enum{CONSTANT,EQUAL}; - /* ---------------------------------------------------------------------- */ template diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 63a18ec387..e26513a122 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -44,7 +44,7 @@ #define GPU_AWARE_UNKNOWN static int have_gpu_aware = -1; // TODO HIP: implement HIP-aware MPI support (UCX) detection -#if defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) +#if defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET) GPU_AWARE_UNKNOWN #elif defined(KOKKOS_ENABLE_CUDA) @@ -121,7 +121,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"g") == 0 || strcmp(arg[iarg],"gpus") == 0) { #ifndef LMP_KOKKOS_GPU - error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA, HIP, or SYCL"); + error->all(FLERR,"GPUs are requested but Kokkos has not been compiled using a GPU-enabled backend"); #endif if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); ngpus = atoi(arg[iarg+1]); @@ -162,7 +162,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (ngpus > 1 && !set_flag) error->all(FLERR,"Could not determine local MPI rank for multiple " - "GPUs with Kokkos CUDA, HIP, or SYCL because MPI library not recognized"); + "GPUs with Kokkos because MPI library not recognized"); } else if (strcmp(arg[iarg],"t") == 0 || strcmp(arg[iarg],"threads") == 0) { @@ -204,7 +204,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) #ifdef LMP_KOKKOS_GPU if (ngpus <= 0) - error->all(FLERR,"Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested"); + error->all(FLERR,"Kokkos has been compiled with GPU-enabled backend but no GPUs are requested"); #endif #ifndef KOKKOS_ENABLE_SERIAL @@ -311,7 +311,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) error->warning(FLERR,"Detected MPICH. Disabling GPU-aware MPI"); #else if (me == 0) - error->warning(FLERR,"Kokkos with CUDA, HIP, or SYCL assumes CUDA-aware MPI is available," + error->warning(FLERR,"Kokkos with GPU-enabled backend assumes GPU-aware MPI is available," " but cannot determine if this is the case\n try" " '-pk kokkos gpu/aware off' if getting segmentation faults"); diff --git a/src/KOKKOS/kokkos.h b/src/KOKKOS/kokkos.h index fa5ff42a44..af35d95b9e 100644 --- a/src/KOKKOS/kokkos.h +++ b/src/KOKKOS/kokkos.h @@ -87,7 +87,7 @@ E: Invalid Kokkos command-line args Self-explanatory. See Section 2.7 of the manual for details. -E: Could not determine local MPI rank for multiple GPUs with Kokkos CUDA +E: Could not determine local MPI rank for multiple GPUs with Kokkos because MPI library not recognized The local MPI rank was not found in one of four supported environment variables. @@ -96,13 +96,13 @@ E: Invalid number of threads requested for Kokkos: must be 1 or greater Self-explanatory. -E: GPUs are requested but Kokkos has not been compiled for CUDA +E: GPUs are requested but Kokkos has not been compiled using GPU-enabled backend -Recompile Kokkos with CUDA support to use GPUs. +Recompile Kokkos with GPU-enabled backend to use GPUs. -E: Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested +E: Kokkos has been compiled with GPU-enabled backend but no GPUs are requested -One or more GPUs must be used when Kokkos is compiled for CUDA/HIP/SYCL. +One or more GPUs must be used when Kokkos is compiled for CUDA/HIP/SYCL/OpenMPTarget. W: Kokkos package already initalized, cannot reinitialize with different parameters diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index cd829ec3e4..4c0dea819c 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include @@ -34,7 +34,7 @@ constexpr int HALF = 4; #define ISFINITE(x) std::isfinite(x) #endif -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) || defined(KOKKOS_ENABLE_OPENMPTARGET) #define LMP_KOKKOS_GPU #endif @@ -223,6 +223,11 @@ template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; }; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +template<> +struct ExecutionSpaceFromDevice { + static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; +}; #endif // set host pinned space @@ -232,6 +237,8 @@ typedef Kokkos::CudaHostPinnedSpace LMPPinnedHostType; typedef Kokkos::Experimental::HIPHostPinnedSpace LMPPinnedHostType; #elif defined(KOKKOS_ENABLE_SYCL) typedef Kokkos::Experimental::SYCLSharedUSMSpace LMPPinnedHostType; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +typedef Kokkos::Serial LMPPinnedHostType; #endif // create simple LMPDeviceSpace typedef for non CUDA-, HIP-, or SYCL-specific @@ -242,6 +249,8 @@ typedef Kokkos::Cuda LMPDeviceSpace; typedef Kokkos::Experimental::HIP LMPDeviceSpace; #elif defined(KOKKOS_ENABLE_SYCL) typedef Kokkos::Experimental::SYCL LMPDeviceSpace; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +typedef Kokkos::Experimental::OpenMPTarget LMPDeviceSpace; #endif @@ -280,6 +289,11 @@ template<> struct AtomicDup { using value = Kokkos::Experimental::ScatterAtomic; }; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) +template<> +struct AtomicDup { + using value = Kokkos::Experimental::ScatterAtomic; +}; #endif #ifdef LMP_KOKKOS_USE_ATOMICS diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 1110aef4a6..42ecedd78a 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -226,7 +226,8 @@ void NPairKokkos::build(NeighList *list_) data.h_resize() = 0; Kokkos::deep_copy(d_scalars, h_scalars); -#ifdef LMP_KOKKOS_GPU + +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) #define BINS_PER_BLOCK 2 const int factor = atoms_per_bin<64?2:1; #else @@ -605,14 +606,15 @@ void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolic other_x[MY_II + 3 * atoms_per_bin] = itype; } other_id[MY_II] = i; -#ifndef KOKKOS_ENABLE_SYCL +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; -#else +#elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); dev.team_reduce(Kokkos::Max(not_done)); if(not_done == 0) return; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) + dev.team_barrier(); #endif if (i >= 0 && i < nlocal) { @@ -1055,14 +1057,15 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP other_x[MY_II + 4 * atoms_per_bin] = radi; } other_id[MY_II] = i; -#ifndef KOKKOS_ENABLE_SYCL +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; -#else +#elif defined(KOKKOS_ENABLE_SYCL) int not_done = (i >= 0 && i <= nlocal); dev.team_reduce(Kokkos::Max(not_done)); if(not_done == 0) return; +#elif defined(KOKKOS_ENABLE_OPENMPTARGET) + dev.team_barrier(); #endif if (i >= 0 && i < nlocal) { diff --git a/src/KOKKOS/pair_reaxff_kokkos.cpp b/src/KOKKOS/pair_reaxff_kokkos.cpp index 43a650efb2..8d9c498005 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.cpp +++ b/src/KOKKOS/pair_reaxff_kokkos.cpp @@ -144,18 +144,15 @@ void PairReaxFFKokkos::init_style() acks2_flag = api->system->acks2_flag; if (acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - Fix* fix = modify->fix[ifix]; - if (!fix->kokkosable) + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + if (!ifix->kokkosable) error->all(FLERR,"Must use Kokkos version of acks2/reaxff with pair reaxff/kk"); - if (fix->execution_space == Host) { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + if (ifix->execution_space == Host) { + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } else { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } @@ -726,16 +723,13 @@ void PairReaxFFKokkos::compute(int eflag_in, int vflag_in) d_ilist = k_list->d_ilist; if (acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - Fix* fix = modify->fix[ifix]; - if (fix->execution_space == Host) { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + if (ifix->execution_space == Host) { + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } else { - FixACKS2ReaxFFKokkos* acks2_fix = (FixACKS2ReaxFFKokkos*) modify->fix[ifix]; - auto k_s = acks2_fix->get_s(); + auto k_s = ((FixACKS2ReaxFFKokkos*) ifix)->get_s(); k_s.sync(); d_s = k_s.view(); } diff --git a/src/KOKKOS/verlet_kokkos.cpp b/src/KOKKOS/verlet_kokkos.cpp index 5e9ab757c6..14540c9ace 100644 --- a/src/KOKKOS/verlet_kokkos.cpp +++ b/src/KOKKOS/verlet_kokkos.cpp @@ -283,7 +283,7 @@ void VerletKokkos::run(int n) atomKK->sync(Device,ALL_MASK); //static double time = 0.0; - //Kokkos::Impl::Timer ktimer; + //Kokkos::Timer ktimer; timer->init_timeout(); for (int i = 0; i < n; i++) { @@ -445,7 +445,7 @@ void VerletKokkos::run(int n) if (pair_compute_flag) { atomKK->sync(force->pair->execution_space,force->pair->datamask_read); atomKK->sync(force->pair->execution_space,~(~force->pair->datamask_read|(F_MASK | ENERGY_MASK | VIRIAL_MASK))); - Kokkos::Impl::Timer ktimer; + Kokkos::Timer ktimer; force->pair->compute(eflag,vflag); atomKK->modified(force->pair->execution_space,force->pair->datamask_modify); atomKK->modified(force->pair->execution_space,~(~force->pair->datamask_modify|(F_MASK | ENERGY_MASK | VIRIAL_MASK))); diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index 9d3a06f18e..06d90e5d0e 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -983,7 +983,7 @@ void PPPM::set_grid_global() h = h_x = h_y = h_z = 4.0/g_ewald; int count = 0; - while (1) { + while (true) { // set grid dimensions diff --git a/src/KSPACE/pppm_dipole.cpp b/src/KSPACE/pppm_dipole.cpp index 16e06ed13e..abadcc52be 100644 --- a/src/KSPACE/pppm_dipole.cpp +++ b/src/KSPACE/pppm_dipole.cpp @@ -783,7 +783,7 @@ void PPPMDipole::set_grid_global() h = h_x = h_y = h_z = 4.0/g_ewald; int count = 0; - while (1) { + while (true) { // set grid dimension diff --git a/src/KSPACE/pppm_disp.cpp b/src/KSPACE/pppm_disp.cpp index fa14cb23f0..85aceb8500 100644 --- a/src/KSPACE/pppm_disp.cpp +++ b/src/KSPACE/pppm_disp.cpp @@ -1471,7 +1471,7 @@ int PPPMDisp::qr_alg(double **A, double **Q, int n) // start loop for the matrix factorization int count = 0; int countmax = 100000; - while (1) { + while (true) { // make a Wilkinson shift an1 = A[n-2][n-2]; an = A[n-1][n-1]; @@ -2645,7 +2645,7 @@ void PPPMDisp::set_grid() if (!gridflag) { h = h_x = h_y = h_z = 4.0/g_ewald; int count = 0; - while (1) { + while (true) { // set grid dimension @@ -3663,7 +3663,7 @@ void PPPMDisp::set_n_pppm_6() // decrease grid spacing until required precision is obtained int count = 0; - while (1) { + while (true) { // set grid dimension nx_pppm_6 = static_cast (xprd/h_x); diff --git a/src/MAKE/MACHINES/Makefile.aarch64_arm_openmpi_armpl b/src/MAKE/MACHINES/Makefile.aarch64_arm_openmpi_armpl index ead00277c6..050670804e 100644 --- a/src/MAKE/MACHINES/Makefile.aarch64_arm_openmpi_armpl +++ b/src/MAKE/MACHINES/Makefile.aarch64_arm_openmpi_armpl @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.aarch64_arm_serial_armpl b/src/MAKE/MACHINES/Makefile.aarch64_arm_serial_armpl index 44c83ff1e0..2ad14ab258 100644 --- a/src/MAKE/MACHINES/Makefile.aarch64_arm_serial_armpl +++ b/src/MAKE/MACHINES/Makefile.aarch64_arm_serial_armpl @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.aarch64_g++_openmpi_armpl b/src/MAKE/MACHINES/Makefile.aarch64_g++_openmpi_armpl index 2ebd2ac744..efe91aed43 100644 --- a/src/MAKE/MACHINES/Makefile.aarch64_g++_openmpi_armpl +++ b/src/MAKE/MACHINES/Makefile.aarch64_g++_openmpi_armpl @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.aarch64_g++_serial_armpl b/src/MAKE/MACHINES/Makefile.aarch64_g++_serial_armpl index 054b530bc8..3c5a552b1b 100644 --- a/src/MAKE/MACHINES/Makefile.aarch64_g++_serial_armpl +++ b/src/MAKE/MACHINES/Makefile.aarch64_g++_serial_armpl @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.astra_arm b/src/MAKE/MACHINES/Makefile.astra_arm index f64f4da891..79461626e9 100644 --- a/src/MAKE/MACHINES/Makefile.astra_arm +++ b/src/MAKE/MACHINES/Makefile.astra_arm @@ -64,6 +64,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -73,7 +78,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.bgq b/src/MAKE/MACHINES/Makefile.bgq index f0401e0758..4baecb9fc3 100644 --- a/src/MAKE/MACHINES/Makefile.bgq +++ b/src/MAKE/MACHINES/Makefile.bgq @@ -15,7 +15,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.cori2 b/src/MAKE/MACHINES/Makefile.cori2 index ca902617fd..8421aedc78 100644 --- a/src/MAKE/MACHINES/Makefile.cori2 +++ b/src/MAKE/MACHINES/Makefile.cori2 @@ -75,6 +75,11 @@ JPG_INC = JPG_PATH = JPG_LIB = #-ljpeg +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -84,7 +89,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.cygwin b/src/MAKE/MACHINES/Makefile.cygwin index 1af9cfe802..153ae1e6c0 100644 --- a/src/MAKE/MACHINES/Makefile.cygwin +++ b/src/MAKE/MACHINES/Makefile.cygwin @@ -65,9 +65,10 @@ JPG_INC = JPG_PATH = JPG_LIB = -# library for loading shared objects (defaults to -ldl, but should be empty on Windows) +# library for loading shared objects (defaults to -ldl but must be empty on Windows) override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -77,7 +78,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.mac b/src/MAKE/MACHINES/Makefile.mac index fb749b5759..e2a78325a1 100644 --- a/src/MAKE/MACHINES/Makefile.mac +++ b/src/MAKE/MACHINES/Makefile.mac @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.mac_mpi b/src/MAKE/MACHINES/Makefile.mac_mpi index 4718c94e51..87f961e12e 100644 --- a/src/MAKE/MACHINES/Makefile.mac_mpi +++ b/src/MAKE/MACHINES/Makefile.mac_mpi @@ -66,6 +66,11 @@ JPG_INC = -I/opt/local/include JPG_PATH = -L/opt/local/lib JPG_LIB = -ljpeg +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.power b/src/MAKE/MACHINES/Makefile.power index 1671fd6273..9c8448abc3 100644 --- a/src/MAKE/MACHINES/Makefile.power +++ b/src/MAKE/MACHINES/Makefile.power @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.summit_kokkos b/src/MAKE/MACHINES/Makefile.summit_kokkos index 95ee7e39a8..87f8c75da2 100644 --- a/src/MAKE/MACHINES/Makefile.summit_kokkos +++ b/src/MAKE/MACHINES/Makefile.summit_kokkos @@ -72,6 +72,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -81,7 +86,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.theta b/src/MAKE/MACHINES/Makefile.theta index 62e125152d..8d04d25ac7 100644 --- a/src/MAKE/MACHINES/Makefile.theta +++ b/src/MAKE/MACHINES/Makefile.theta @@ -70,6 +70,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -79,7 +84,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.ubuntu b/src/MAKE/MACHINES/Makefile.ubuntu index f030ce64df..ed479d8969 100644 --- a/src/MAKE/MACHINES/Makefile.ubuntu +++ b/src/MAKE/MACHINES/Makefile.ubuntu @@ -69,6 +69,11 @@ JPG_INC = JPG_PATH = JPG_LIB = -ljpeg -lpng +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -78,7 +83,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.ubuntu_simple b/src/MAKE/MACHINES/Makefile.ubuntu_simple index e8b58fc804..3926777f03 100644 --- a/src/MAKE/MACHINES/Makefile.ubuntu_simple +++ b/src/MAKE/MACHINES/Makefile.ubuntu_simple @@ -68,6 +68,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -77,7 +82,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.white b/src/MAKE/MACHINES/Makefile.white index ff2103008c..cb101998b3 100644 --- a/src/MAKE/MACHINES/Makefile.white +++ b/src/MAKE/MACHINES/Makefile.white @@ -69,6 +69,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -78,7 +83,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/MACHINES/Makefile.xe6 b/src/MAKE/MACHINES/Makefile.xe6 index a6db78a053..9dbe0ba73e 100644 --- a/src/MAKE/MACHINES/Makefile.xe6 +++ b/src/MAKE/MACHINES/Makefile.xe6 @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index cf796be69b..933da9663e 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -65,7 +65,7 @@ JPG_INC = JPG_PATH = JPG_LIB = -# library for loading shared objects (defaults to -ldl) +# library for loading shared objects (defaults to -ldl, should be empty on Windows) # uncomment to change the default # override DYN_LIB = @@ -79,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.big b/src/MAKE/OPTIONS/Makefile.big index bdc093c6ae..d2cbf8a73e 100644 --- a/src/MAKE/OPTIONS/Makefile.big +++ b/src/MAKE/OPTIONS/Makefile.big @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.fftw b/src/MAKE/OPTIONS/Makefile.fftw index dd539fb5dc..65b568d3d2 100644 --- a/src/MAKE/OPTIONS/Makefile.fftw +++ b/src/MAKE/OPTIONS/Makefile.fftw @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.g++_mpich b/src/MAKE/OPTIONS/Makefile.g++_mpich index e0c77437f5..15257a9a45 100644 --- a/src/MAKE/OPTIONS/Makefile.g++_mpich +++ b/src/MAKE/OPTIONS/Makefile.g++_mpich @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.g++_mpich_link b/src/MAKE/OPTIONS/Makefile.g++_mpich_link index 4f2855a9cc..3498842be4 100644 --- a/src/MAKE/OPTIONS/Makefile.g++_mpich_link +++ b/src/MAKE/OPTIONS/Makefile.g++_mpich_link @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.g++_openmpi b/src/MAKE/OPTIONS/Makefile.g++_openmpi index 75c12f9b38..a619beefcc 100644 --- a/src/MAKE/OPTIONS/Makefile.g++_openmpi +++ b/src/MAKE/OPTIONS/Makefile.g++_openmpi @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.g++_openmpi_link b/src/MAKE/OPTIONS/Makefile.g++_openmpi_link index 0c9997dbb0..7d1743fec7 100644 --- a/src/MAKE/OPTIONS/Makefile.g++_openmpi_link +++ b/src/MAKE/OPTIONS/Makefile.g++_openmpi_link @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.g++_serial b/src/MAKE/OPTIONS/Makefile.g++_serial index d6b9bf3221..397a977ead 100644 --- a/src/MAKE/OPTIONS/Makefile.g++_serial +++ b/src/MAKE/OPTIONS/Makefile.g++_serial @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.gpu b/src/MAKE/OPTIONS/Makefile.gpu index 9ad5cf477c..2e183ef746 100644 --- a/src/MAKE/OPTIONS/Makefile.gpu +++ b/src/MAKE/OPTIONS/Makefile.gpu @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.hip b/src/MAKE/OPTIONS/Makefile.hip index 8be9e7260f..ed9f832a42 100644 --- a/src/MAKE/OPTIONS/Makefile.hip +++ b/src/MAKE/OPTIONS/Makefile.hip @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -80,7 +85,7 @@ endif EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.icc_mpich b/src/MAKE/OPTIONS/Makefile.icc_mpich index c630c42c26..30d7b3da81 100644 --- a/src/MAKE/OPTIONS/Makefile.icc_mpich +++ b/src/MAKE/OPTIONS/Makefile.icc_mpich @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.icc_mpich_link b/src/MAKE/OPTIONS/Makefile.icc_mpich_link index 8b89d2509a..232475f2e3 100644 --- a/src/MAKE/OPTIONS/Makefile.icc_mpich_link +++ b/src/MAKE/OPTIONS/Makefile.icc_mpich_link @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.icc_openmpi b/src/MAKE/OPTIONS/Makefile.icc_openmpi index 0a2c9598a6..5f3281c021 100644 --- a/src/MAKE/OPTIONS/Makefile.icc_openmpi +++ b/src/MAKE/OPTIONS/Makefile.icc_openmpi @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.icc_openmpi_link b/src/MAKE/OPTIONS/Makefile.icc_openmpi_link index 825d4cdff0..ab3909fd1e 100644 --- a/src/MAKE/OPTIONS/Makefile.icc_openmpi_link +++ b/src/MAKE/OPTIONS/Makefile.icc_openmpi_link @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.icc_serial b/src/MAKE/OPTIONS/Makefile.icc_serial index 2d2da54c68..5ec920c9ef 100644 --- a/src/MAKE/OPTIONS/Makefile.icc_serial +++ b/src/MAKE/OPTIONS/Makefile.icc_serial @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.intel_coprocessor b/src/MAKE/OPTIONS/Makefile.intel_coprocessor index 2b66c20f4a..99e8d22d82 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_coprocessor +++ b/src/MAKE/OPTIONS/Makefile.intel_coprocessor @@ -70,6 +70,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -79,7 +84,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi b/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi index 04ec1fdc64..0371078bd2 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi @@ -69,6 +69,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -78,7 +83,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich b/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich index dece0092f1..04a60f8f61 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich @@ -69,6 +69,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -78,7 +83,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi b/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi index 0053aef20a..9041dc797e 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi @@ -70,6 +70,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -79,7 +84,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.jpeg b/src/MAKE/OPTIONS/Makefile.jpeg index 268e7b94e8..c2b7ab6a49 100644 --- a/src/MAKE/OPTIONS/Makefile.jpeg +++ b/src/MAKE/OPTIONS/Makefile.jpeg @@ -65,6 +65,11 @@ JPG_INC = -I/usr/include JPG_PATH = -L/usr/lib JPG_LIB = -ljpeg +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.knl b/src/MAKE/OPTIONS/Makefile.knl index 091fd7558f..c6cf783331 100644 --- a/src/MAKE/OPTIONS/Makefile.knl +++ b/src/MAKE/OPTIONS/Makefile.knl @@ -68,6 +68,11 @@ JPG_INC = JPG_PATH = JPG_LIB = -ljpeg +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -77,7 +82,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi index c6071cf747..cb3ef0e442 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi +++ b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi @@ -70,6 +70,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -79,7 +84,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only b/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only index 0b2e42487f..6d5e8d779e 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only +++ b/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_omp b/src/MAKE/OPTIONS/Makefile.kokkos_omp index 3e8f7ba634..e505da8ae2 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_omp +++ b/src/MAKE/OPTIONS/Makefile.kokkos_omp @@ -66,6 +66,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -75,7 +80,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_phi b/src/MAKE/OPTIONS/Makefile.kokkos_phi index 0e2bec0a5a..b825ad691a 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_phi +++ b/src/MAKE/OPTIONS/Makefile.kokkos_phi @@ -67,6 +67,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -76,7 +81,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.mgptfast b/src/MAKE/OPTIONS/Makefile.mgptfast index da10701a9a..e7fd82a39c 100644 --- a/src/MAKE/OPTIONS/Makefile.mgptfast +++ b/src/MAKE/OPTIONS/Makefile.mgptfast @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.omp b/src/MAKE/OPTIONS/Makefile.omp index 573c2d826b..7a59d7f10d 100644 --- a/src/MAKE/OPTIONS/Makefile.omp +++ b/src/MAKE/OPTIONS/Makefile.omp @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.oneapi b/src/MAKE/OPTIONS/Makefile.oneapi index 2524773a76..d34f0900c6 100644 --- a/src/MAKE/OPTIONS/Makefile.oneapi +++ b/src/MAKE/OPTIONS/Makefile.oneapi @@ -68,6 +68,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -77,7 +82,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.opt b/src/MAKE/OPTIONS/Makefile.opt index 2cb5540fd4..acfd802c44 100644 --- a/src/MAKE/OPTIONS/Makefile.opt +++ b/src/MAKE/OPTIONS/Makefile.opt @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.pgi_mpich_link b/src/MAKE/OPTIONS/Makefile.pgi_mpich_link index daa8a79166..b09efd6fa0 100644 --- a/src/MAKE/OPTIONS/Makefile.pgi_mpich_link +++ b/src/MAKE/OPTIONS/Makefile.pgi_mpich_link @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MAKE/OPTIONS/Makefile.png b/src/MAKE/OPTIONS/Makefile.png index 40ebe43d32..8eff543af6 100644 --- a/src/MAKE/OPTIONS/Makefile.png +++ b/src/MAKE/OPTIONS/Makefile.png @@ -65,6 +65,11 @@ JPG_INC = -I/usr/include JPG_PATH = -L/usr/lib JPG_LIB = -lpng +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/MANIFOLD/fix_nve_manifold_rattle.cpp b/src/MANIFOLD/fix_nve_manifold_rattle.cpp index b4644a1350..e3c0024d57 100644 --- a/src/MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/MANIFOLD/fix_nve_manifold_rattle.cpp @@ -140,10 +140,8 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, if (strcmp(arg[argi], "every") == 0) { nevery = utils::inumeric(FLERR,arg[argi+1],false,lmp); next_output = update->ntimestep + nevery; - if (comm->me == 0) { - fprintf(screen,"Outputting every %d steps, next is %d\n", - nevery, next_output); - } + if (comm->me == 0) + utils::logmesg(lmp,"Outputting every {} steps, next is {}\n",nevery, next_output); argi += 2; } else if (error_on_unknown_keyword) { error->all(FLERR,"Error parsing arg \"{}\".\n",arg[argi]); @@ -211,11 +209,9 @@ void FixNVEManifoldRattle::print_stats( const char *header ) double inv_tdiff = 1.0/( static_cast(ntimestep) - stats.last_out ); stats.last_out = ntimestep; - fprintf(screen, "%s stats for time step " BIGINT_FORMAT " on %d atoms:\n", - header, ntimestep, stats.natoms); - fprintf(screen, " iters/atom: x = %f, v = %f, dofs removed %d", - x_iters * inv_tdiff, v_iters * inv_tdiff, stats.dofs_removed); - fprintf(screen,"\n"); + utils::logmesg(lmp, "{} stats for time step {} on {} atoms:\n", header, ntimestep, stats.natoms); + utils::logmesg(lmp, " iters/atom: x = {}, v = {}, dofs removed = {}\n", + x_iters * inv_tdiff, v_iters * inv_tdiff, stats.dofs_removed); } stats.x_iters_per_atom = 0; @@ -498,7 +494,7 @@ void FixNVEManifoldRattle::rattle_manifold_x(double *x, double *v, const double c_inv = 1.0 / c; - while (1) { + while (true) { v[0] = vt[0] - l*no_dt[0]; v[1] = vt[1] - l*no_dt[1]; v[2] = vt[2] - l*no_dt[2]; diff --git a/src/MANIFOLD/fix_nvt_manifold_rattle.cpp b/src/MANIFOLD/fix_nvt_manifold_rattle.cpp index f675cdff73..0dcc233b54 100644 --- a/src/MANIFOLD/fix_nvt_manifold_rattle.cpp +++ b/src/MANIFOLD/fix_nvt_manifold_rattle.cpp @@ -32,21 +32,21 @@ ------------------------------------------------------------------------- */ - #include "fix_nvt_manifold_rattle.h" -#include -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "error.h" -#include "group.h" #include "citeme.h" -#include "modify.h" #include "compute.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "modify.h" +#include "update.h" #include "manifold.h" +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -115,9 +115,7 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, mtchain = utils::inumeric(FLERR, arg[argi+1],false,lmp); argi += 2; } else if (error_on_unknown_keyword) { - char msg[2048]; - sprintf(msg,"Error parsing arg \"%s\".\n", arg[argi]); - error->all(FLERR, msg); + error->all(FLERR, "Error parsing arg \"{}\".\n", arg[argi]); } else { argi += 1; } @@ -271,12 +269,8 @@ void FixNVTManifoldRattle::nhc_temp_integrate() factor_eta = exp(-dthalf*eta_dot[0]); - if (factor_eta == 0) { - char msg[2048]; - sprintf(msg, "WTF, factor_eta is 0! dthalf = %f, eta_dot[0] = %f", - dthalf, eta_dot[0]); - error->all(FLERR,msg); - } + if (factor_eta == 0) + error->all(FLERR, "factor_eta is 0! dthalf = {}, eta_dot[0] = {}", dthalf, eta_dot[0]); nh_v_temp(); diff --git a/src/MANIFOLD/manifold_gaussian_bump.cpp b/src/MANIFOLD/manifold_gaussian_bump.cpp index 5eb2b08504..1483ff7489 100644 --- a/src/MANIFOLD/manifold_gaussian_bump.cpp +++ b/src/MANIFOLD/manifold_gaussian_bump.cpp @@ -67,9 +67,7 @@ public: double get_t_from_x( double xx ) const { if (xx < x0 || xx > x1) { - char msg[2048]; - sprintf(msg, "x ( %g ) out of bounds [%g, %g]", xx, x0, x1 ); - err->one(FLERR, msg); + err->one(FLERR,"x ( {} ) out of bounds [{}, {}]", xx, x0, x1 ); } // Newton iterate to get right t. @@ -271,8 +269,6 @@ void manifold_gaussian_bump::post_param_init() make_lut(); - - // test_lut(); } @@ -360,31 +356,3 @@ void manifold_gaussian_bump::lut_get_z_and_zp( double rr, double &zz, zz = zleft * fmin + zright * frac; zzp = zpleft * fmin + zpright * frac; } - - -void manifold_gaussian_bump::test_lut() -{ - double x[3], nn[3]; - if (comm->me != 0) return; - - FILE *fp = fopen( "test_lut_gaussian.dat", "w" ); - double dx = 0.1; - for (double xx = 0; xx < 20; xx += dx) { - x[0] = xx; - x[1] = 0.0; - x[2] = 0.0; - double gg = g( x ); - n( x, nn ); - double taper_z; - if (xx <= rc1) { - taper_z = gaussian_bump(xx); - } else if (xx < rc2) { - taper_z = lut_get_z( xx ); - } else { - taper_z = 0.0; - } - fprintf( fp, "%g %g %g %g %g %g %g\n", xx, gaussian_bump(xx), taper_z, - gg, nn[0], nn[1], nn[2] ); - } - fclose(fp); -} diff --git a/src/MANIFOLD/manifold_gaussian_bump.h b/src/MANIFOLD/manifold_gaussian_bump.h index 8c72db080f..4671b189df 100644 --- a/src/MANIFOLD/manifold_gaussian_bump.h +++ b/src/MANIFOLD/manifold_gaussian_bump.h @@ -86,8 +86,6 @@ namespace user_manifold { double lut_get_zp(double rr) const; void lut_get_z_and_zp(double rr, double &zz, double &zzp) const; - void test_lut(); - double taper(double); double taper_der(double); }; diff --git a/src/MANIFOLD/manifold_thylakoid.cpp b/src/MANIFOLD/manifold_thylakoid.cpp index b7004cac3a..ca50bfc881 100644 --- a/src/MANIFOLD/manifold_thylakoid.cpp +++ b/src/MANIFOLD/manifold_thylakoid.cpp @@ -34,17 +34,13 @@ manifold_thylakoid::manifold_thylakoid( LAMMPS *lmp, int /*narg*/, char ** /*arg // fix should call post_param_init(); } - - manifold_thylakoid::~manifold_thylakoid() { - for (std::size_t i = 0; i < parts.size(); ++i) { - delete parts[i]; + for (auto & part : parts) { + delete part; } } - - void manifold_thylakoid::post_param_init() { // Set coefficients: @@ -59,52 +55,21 @@ void manifold_thylakoid::post_param_init() LB = params[1]; lB = params[2]; - if (comm->me == 0) { - fprintf(screen,"My params are now: lT = %f, LT = %f, pad = %f, " - "wB = %f, LB = %f, lB = %f\n", lT, LT, pad, wB, LB, lB ); - fprintf(screen,"Calling init_domains() from post_param_init().\n"); - } init_domains(); - checkup(); } -void manifold_thylakoid::checkup() -{ - if (comm->me == 0) { - fprintf(screen,"This is checkup of thylakoid %p\n", this); - fprintf(screen,"I have %ld parts. They are:\n", parts.size()); - for (int i = 0; i < (int)parts.size(); ++i) { - fprintf(screen, "[%f, %f] x [%f, %f] x [%f, %f]\n", - parts[i]->xlo, parts[i]->xhi, - parts[i]->ylo, parts[i]->yhi, - parts[i]->zlo, parts[i]->zhi ); - } - fprintf(screen,"My params are:\n"); - for (int i = 0; i < NPARAMS; ++i) { - fprintf(screen,"%f\n", params[i]); - } - } -} - - double manifold_thylakoid::g( const double *x ) { int err = 0; std::size_t idx; thyla_part *p = get_thyla_part(x,&err,&idx); - if (err) { - char msg[2048]; - sprintf(msg,"Error getting thyla_part for x = (%f, %f, %f)",x[0],x[1],x[2]); - error->one(FLERR,msg); - } + if (err) error->one(FLERR,"Error getting thyla_part for x = ({}, {}, {})",x[0],x[1],x[2]); + double con_val = p->g(x); if (std::isfinite(con_val)) { return con_val; } else { - char msg[2048]; - sprintf(msg,"Error, thyla_part of type %d returned %f as constraint val!", - p->type, con_val); - error->one(FLERR,msg); + error->one(FLERR,"Error, thyla_part of type {} returned {} as constraint val!", p->type, con_val); return 0; } } @@ -114,20 +79,14 @@ void manifold_thylakoid::n( const double *x, double *n ) int err = 0; std::size_t idx; thyla_part *p = get_thyla_part(x,&err,&idx); - if (err) { - char msg[2048]; - sprintf(msg,"Error getting thyla_part for x = (%f, %f, %f)",x[0],x[1],x[2]); - error->one(FLERR,msg); - } + if (err) + error->one(FLERR,"Error getting thyla_part for x = ({}, {}, {})",x[0],x[1],x[2]); p->n(x,n); if (std::isfinite(n[0]) && std::isfinite(n[1]) && std::isfinite(n[2])) { return; - } else { - char msg[2048]; - sprintf(msg,"Error, thyla_part of type %d returned (%f,%f,%f) as gradient!", - p->type, n[0], n[1], n[2]); - error->one(FLERR,msg); - } + } else + error->one(FLERR,"thyla_part of type {} returned ({},{},{}) as gradient!", + p->type, n[0], n[1], n[2]); } thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_flag*/, std::size_t *idx ) @@ -140,9 +99,7 @@ thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_fla return p; } } - char msg[2048]; - sprintf(msg,"Could not find thyla_part for x = (%f,%f,%f)", x[0],x[1],x[2]); - error->one(FLERR,msg); + error->one(FLERR,"Could not find thyla_part for x = ({},{},{})", x[0],x[1],x[2]); return nullptr; } @@ -153,12 +110,9 @@ thyla_part *manifold_thylakoid::get_thyla_part( const double *x, int * /*err_fla void manifold_thylakoid::init_domains() { - if (wB + 2*lB > LT) { - char msg[2048]; - sprintf(msg,"LT = %f not large enough to accommodate bridge with " - "wB = %f and lB = %f! %f > %f\n", LT, wB, lB, wB + 2*lB, LT); - error->one(FLERR,msg); - } + if (wB + 2*lB > LT) + error->one(FLERR,"LT = {} not large enough to accommodate bridge with " + "wB = {} and lB = {}! {} > {}\n", LT, wB, lB, wB + 2*lB, LT); // Determine some constant coordinates: x0 = -( 0.5*LB + lB + lT + LT + lT + pad); @@ -375,12 +329,9 @@ void manifold_thylakoid::init_domains() parts.push_back(p); // Check if this plane lines up with bl: - if (fabs(plr.pt[0] - bl.pt[0] + lB) > 1e-8) { - char msg[2048]; - sprintf(msg,"Origins of plane left right and bridge left misaligned! %f != %f!\n", - plr.pt[0], bl.pt[0] - lB ); - error->one(FLERR,msg); - } + if (fabs(plr.pt[0] - bl.pt[0] + lB) > 1e-8) + error->one(FLERR,"Origins of plane left right and bridge left misaligned! {} != {}!\n", + plr.pt[0], bl.pt[0] - lB ); // Now, for the right stack, you can mirror the other... // To mirror them you need to invert lo[0] and hi[0] and flip their sign. @@ -428,12 +379,9 @@ void manifold_thylakoid::init_domains() set_domain(p, prr.lo, prr.hi); parts.push_back(p); - if (fabs(prr.pt[0] - br.pt[0] - lB) > 1e-8) { - char msg[2048]; - sprintf(msg,"Origins of plane left right and bridge left misaligned! %f != %f!\n", - prr.pt[0], br.pt[0] + lB); - error->one(FLERR,msg); - } + if (fabs(prr.pt[0] - br.pt[0] - lB) > 1e-8) + error->one(FLERR,"Origins of plane left right and bridge left misaligned! {} != {}!\n", + prr.pt[0], br.pt[0] + lB); } diff --git a/src/MANIFOLD/manifold_thylakoid.h b/src/MANIFOLD/manifold_thylakoid.h index 5470d722f9..0236c3bf54 100644 --- a/src/MANIFOLD/manifold_thylakoid.h +++ b/src/MANIFOLD/manifold_thylakoid.h @@ -37,7 +37,6 @@ namespace user_manifold { virtual int nparams() { return NPARAMS; } virtual void post_param_init(); - virtual void checkup(); // Some diagnostics... private: void init_domains(); diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index a02a5718ff..29d2121f1f 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -3485,8 +3485,8 @@ void PairAIREBO::read_file(char *filename) // global parameters current_section = "global parameters"; - for (int i = 0; i < (int)params.size(); i++) { - *params[i] = reader.next_double(); + for (auto & param : params) { + *param = reader.next_double(); } diff --git a/src/MANYBODY/pair_edip.cpp b/src/MANYBODY/pair_edip.cpp index 51b38037ab..af2314b8b9 100644 --- a/src/MANYBODY/pair_edip.cpp +++ b/src/MANYBODY/pair_edip.cpp @@ -789,7 +789,7 @@ void PairEDIP::read_file(char *file) char line[MAXLINE], *ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line, MAXLINE, fp); if (ptr == nullptr) { diff --git a/src/MANYBODY/pair_edip_multi.cpp b/src/MANYBODY/pair_edip_multi.cpp index 3cabec4505..8017fa4f8e 100644 --- a/src/MANYBODY/pair_edip_multi.cpp +++ b/src/MANYBODY/pair_edip_multi.cpp @@ -602,7 +602,7 @@ void PairEDIPMulti::read_file(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { diff --git a/src/MANYBODY/pair_extep.cpp b/src/MANYBODY/pair_extep.cpp index bc96a40c57..68db444f31 100644 --- a/src/MANYBODY/pair_extep.cpp +++ b/src/MANYBODY/pair_extep.cpp @@ -540,7 +540,7 @@ void PairExTeP::read_file(char *file) char line[MAXLINE],*ptr; int eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); if (ptr == nullptr) { @@ -669,7 +669,7 @@ void PairExTeP::read_file(char *file) F_corr_data[iel][jel][in][jn][ivar]=0; // loop until EOF - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fp); //fputs(line,stdout); diff --git a/src/MANYBODY/pair_lcbop.cpp b/src/MANYBODY/pair_lcbop.cpp index 3c6f08a7e7..547fc75154 100644 --- a/src/MANYBODY/pair_lcbop.cpp +++ b/src/MANYBODY/pair_lcbop.cpp @@ -935,7 +935,7 @@ void PairLCBOP::read_file(char *filename) // skip initial comment lines - while (1) { + while (true) { utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); if (s[0] != '#') break; } @@ -971,7 +971,7 @@ void PairLCBOP::read_file(char *filename) utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); sscanf(s,"%lg",&eps); utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); sscanf(s,"%lg",&delta); - while (1) { + while (true) { utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); if (s[0] != '#') break; } @@ -988,7 +988,7 @@ void PairLCBOP::read_file(char *filename) &F_conj_data[i][2][k][l], &F_conj_data[i][3][k][l]); } - while (1) { utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); if (s[0] != '#') break; } + while (true) { utils::sfgets(FLERR,s,MAXLINE,fp,filename,error); if (s[0] != '#') break; } } } diff --git a/src/MDI/mdi_engine.cpp b/src/MDI/mdi_engine.cpp index 4be739d187..4ae1c80a9a 100644 --- a/src/MDI/mdi_engine.cpp +++ b/src/MDI/mdi_engine.cpp @@ -20,8 +20,8 @@ #include "atom.h" #include "error.h" -#include "integrate.h" #include "fix_mdi_engine.h" +#include "integrate.h" #include "mdi.h" #include "min.h" #include "modify.h" @@ -176,17 +176,13 @@ void MDIEngine::command(int narg, char ** /*arg*/) // if the mdi/engine fix is not already present, add it now - int ifix = modify->find_fix_by_style("mdi/engine"); bool added_mdi_engine_fix = false; - if (ifix < 0) { - modify->add_fix("MDI_ENGINE_INTERNAL all mdi/engine"); + auto fixes = modify->get_fix_by_style("mdi/engine"); + if (fixes.size() == 0) { added_mdi_engine_fix = true; - } - - // identify the mdi_engine fix - - ifix = modify->find_fix_by_style("mdi/engine"); - mdi_fix = static_cast(modify->fix[ifix]); + mdi_fix = (FixMDIEngine *) modify->add_fix("MDI_ENGINE_INTERNAL all mdi/engine"); + } else + mdi_fix = (FixMDIEngine *) fixes.front(); // check that LAMMPS is setup as a compatible MDI engine @@ -200,7 +196,7 @@ void MDIEngine::command(int narg, char ** /*arg*/) char *command; - while (1) { + while (true) { // mdi/engine command only recognizes three nodes // DEFAULT, INIT_MD, INIT_OPTG @@ -224,7 +220,7 @@ void MDIEngine::command(int narg, char ** /*arg*/) error->all(FLERR, "MDI node exited with invalid command: {}", command); } - // remove mdi/engine fix that mdi/engine instantiated + // remove mdi/engine fix if instantiated here by mdi/engine if (added_mdi_engine_fix) modify->delete_fix("MDI_ENGINE_INTERNAL"); } @@ -265,7 +261,7 @@ char *MDIEngine::mdi_md() // run MD one step at a time - while (1) { + while (true) { update->whichflag = 1; timer->init_timeout(); update->nsteps += 1; diff --git a/src/MEAM/pair_meam.cpp b/src/MEAM/pair_meam.cpp index b69d17f0a9..e8c6c942a4 100644 --- a/src/MEAM/pair_meam.cpp +++ b/src/MEAM/pair_meam.cpp @@ -517,7 +517,7 @@ void PairMEAM::read_user_meam_file(const std::string &userfile) char * line = nullptr; char buffer[MAXLINE]; - while (1) { + while (true) { int which; int nindex, index[3]; double value; diff --git a/src/MESONT/pair_mesont_tpm.cpp b/src/MESONT/pair_mesont_tpm.cpp index 425722a569..293e9d02f5 100644 --- a/src/MESONT/pair_mesont_tpm.cpp +++ b/src/MESONT/pair_mesont_tpm.cpp @@ -197,7 +197,7 @@ MESONTList::MESONTList(const Atom* atom, const NeighList* nblist) { index_list.push_back(i); index_list_b[i] = index_list.size() - 1; int idx = i; - while (1) { + while (true) { idx = chain_list[idx][1]; if (idx == cnt_end || idx == domain_end) break; else index_list.push_back(idx); diff --git a/src/MGPT/mgpt_readpot.cpp b/src/MGPT/mgpt_readpot.cpp index df62bf735d..dd196142f5 100644 --- a/src/MGPT/mgpt_readpot.cpp +++ b/src/MGPT/mgpt_readpot.cpp @@ -131,7 +131,7 @@ static void getparmindata(const char *potin_file,int nvol[1],double vol0[1],doub exit(1); } - if (0) { + if (false) { printf("Before sort:\n"); for (int i = 0; i nvol = %d, vol0 = %.6f, x0= %.6f, x1 = %.6f, dx = %.6f\n", nvol,vol0,x0,x1,dx); } @@ -408,7 +408,7 @@ void potdata::readpot(const char *parmin_file,const char *potin_file,const doubl double vpair_tmp = vpairtab[i*nr+j]; vpairtab[i*nr+j] = vpairtab[i*nr+j]*fscr + v2a - v2b; - if (0) if (fabs(vol-ivol) < 0.01) { + if (false) if (fabs(vol-ivol) < 0.01) { static FILE *xfile = nullptr; if (j == 0) { xfile = fopen("mgpt5-pot.dat","w"); @@ -487,7 +487,7 @@ void potdata::readpot(const char *parmin_file,const char *potin_file,const doubl evalspline(nx-1,x0,x1,C,x,&evol0,&devol0,&unused); devol0 *= dxdv; - if (1) { + if (true) { printf("%% READPOT PARAMETERS:\n"); printf("%% ddl = %15.5e %15.5e %15.5e %15.5e\n",ddl[1],ddl[2],ddl[3],ddl[4]); diff --git a/src/MGPT/mgpt_splinetab.cpp b/src/MGPT/mgpt_splinetab.cpp index e31572fe50..fd6d4541c2 100644 --- a/src/MGPT/mgpt_splinetab.cpp +++ b/src/MGPT/mgpt_splinetab.cpp @@ -105,7 +105,7 @@ void evalspline(int n,double x0,double x1,double C[][4], xhat = xhat - idx; p = C[idx]; - if (0) { + if (false) { *y = p[0] + xhat*(p[1] + xhat*(p[2] + xhat*p[3])); *dy = p[1] + xhat*(2*p[2] + xhat*3*p[3]); diff --git a/src/MGPT/pair_mgpt.cpp b/src/MGPT/pair_mgpt.cpp index 2bea1273c6..4744693b0f 100644 --- a/src/MGPT/pair_mgpt.cpp +++ b/src/MGPT/pair_mgpt.cpp @@ -191,24 +191,24 @@ static inline double mtrace(int n,double A[8][8],double B[8][8]) { void PairMGPT::make_triplet(bond_data *ij_bond,bond_data *ik_bond, triplet_data *triptr) { - if (1) { - const trmul_fun tr_mul = linalg.tr_mul; - tr_mul(&(ij_bond->H.m[1][0]), &(ik_bond->H.m[1][0]) ,&(triptr->H1H2.m[1][0]) ); - tr_mul(&(ij_bond->Hx.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1xH2.m[1][0])); - tr_mul(&(ij_bond->Hy.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1yH2.m[1][0])); - tr_mul(&(ij_bond->Hz.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1zH2.m[1][0])); - tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hx.m[1][0]),&(triptr->H1H2x.m[1][0])); - tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hy.m[1][0]),&(triptr->H1H2y.m[1][0])); - tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hz.m[1][0]),&(triptr->H1H2z.m[1][0])); - } else { - transprod(ij_bond->H, ik_bond->H ,triptr->H1H2 ); - transprod(ij_bond->Hx,ik_bond->H ,triptr->H1xH2); - transprod(ij_bond->Hy,ik_bond->H ,triptr->H1yH2); - transprod(ij_bond->Hz,ik_bond->H ,triptr->H1zH2); - transprod(ij_bond->H ,ik_bond->Hx,triptr->H1H2x); - transprod(ij_bond->H ,ik_bond->Hy,triptr->H1H2y); - transprod(ij_bond->H ,ik_bond->Hz,triptr->H1H2z); - } +#if 1 + const trmul_fun tr_mul = linalg.tr_mul; + tr_mul(&(ij_bond->H.m[1][0]), &(ik_bond->H.m[1][0]) ,&(triptr->H1H2.m[1][0]) ); + tr_mul(&(ij_bond->Hx.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1xH2.m[1][0])); + tr_mul(&(ij_bond->Hy.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1yH2.m[1][0])); + tr_mul(&(ij_bond->Hz.m[1][0]),&(ik_bond->H.m[1][0]) ,&(triptr->H1zH2.m[1][0])); + tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hx.m[1][0]),&(triptr->H1H2x.m[1][0])); + tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hy.m[1][0]),&(triptr->H1H2y.m[1][0])); + tr_mul(&(ij_bond->H.m[1][0]) ,&(ik_bond->Hz.m[1][0]),&(triptr->H1H2z.m[1][0])); +#else + transprod(ij_bond->H, ik_bond->H ,triptr->H1H2 ); + transprod(ij_bond->Hx,ik_bond->H ,triptr->H1xH2); + transprod(ij_bond->Hy,ik_bond->H ,triptr->H1yH2); + transprod(ij_bond->Hz,ik_bond->H ,triptr->H1zH2); + transprod(ij_bond->H ,ik_bond->Hx,triptr->H1H2x); + transprod(ij_bond->H ,ik_bond->Hy,triptr->H1H2y); + transprod(ij_bond->H ,ik_bond->Hz,triptr->H1H2z); +#endif } static double t_make_t = 0.0,t_make_b = 0.0,n_make = 0.0; @@ -289,7 +289,7 @@ double PairMGPT::numderiv3t(double xx[][3],int i,int j,int k,int p) { xx[i][p] = xsave - delta; make_bond(xx,i,j,&Bij); - if (0) { /* This bond doesn't change when i is perturbed */ + if (false) { /* This bond doesn't change when i is perturbed */ make_bond(xx,j,k,&Bjk); } make_bond(xx,k,i,&Bki); @@ -341,7 +341,7 @@ double PairMGPT::numderiv4(double xx[][3],int i,int j,int k,int m,int p) { xx[i][p] = xsave - delta; make_bond(xx,i,j,&Bij); - if (0) { /* Only the i coordinates changed... */ + if (false) { /* Only the i coordinates changed... */ make_bond(xx,j,k,&Bjk); make_bond(xx,k,m,&Bkm); } @@ -438,7 +438,7 @@ void PairMGPT::force_debug_4(double xx[][3], for (int p = 0; p<3; p++) { /* Compute numerical derivatives by displacing atoms i,j,k,m */ double ndfi,ndfj,ndfk,ndfm; - if (1) { + if (true) { double ndf[] = {0.0,0.0,0.0,0.0}; for (int s = 0; s<4; s++) for (int t = 0; t<4; t++) @@ -765,7 +765,7 @@ void PairMGPT::compute_x(const int *nnei,const int * const *nlist, int c_p = 0, c_t = 0, c_q = 0; - if (0) + if (false) if (domain->triclinic) { if (comm->me == 0) printf("Can not handle triclinic box yet\n"); @@ -1690,7 +1690,7 @@ void PairMGPT::compute(int eflag, int vflag) compute_x(listfull->numneigh,listfull->firstneigh,&e_s,&e_p,&e_t,&e_q,evflag,newton_pair); - if (0) { // Stupid force calculation / verification + if (false) { // Stupid force calculation / verification int ii,nmax=-1; for (ii = 0; iiinum + listfull->gnum; ii++) { int i = listfull->ilist[ii]; @@ -1768,7 +1768,7 @@ void PairMGPT::compute(int eflag, int vflag) } - if (0) { + if (false) { printf("\nForces MGPT:\n"); const int iimax = (listfull->inum < 10) ? listfull->inum : 10; for (int ii = 0; iiall(FLERR, "Could not find pair fix neigh history ID"); fix_history = (FixNeighHistory *) modify->fix[ifix]; - ifix = modify->find_fix_by_style("pair/tracker"); - if (ifix < 0) error->all(FLERR, "Cannot use pair tracker without fix pair/tracker"); - fix_pair_tracker = (FixPairTracker *) modify->fix[ifix]; + auto trackfixes = modify->get_fix_by_style("pair/tracker"); + if (trackfixes.size() != 1) + error->all(FLERR, "Must use exactly one fix pair/tracker command with pair style tracker"); + fix_pair_tracker = (FixPairTracker *) trackfixes.front(); } /* ---------------------------------------------------------------------- diff --git a/src/ML-IAP/mliap_descriptor_snap.cpp b/src/ML-IAP/mliap_descriptor_snap.cpp index 6399ef63a3..5475117a99 100644 --- a/src/ML-IAP/mliap_descriptor_snap.cpp +++ b/src/ML-IAP/mliap_descriptor_snap.cpp @@ -382,7 +382,7 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) int eof = 0; int n,nwords; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fpparam); if (ptr == nullptr) { diff --git a/src/ML-IAP/mliap_descriptor_so3.cpp b/src/ML-IAP/mliap_descriptor_so3.cpp index d816bd0638..e8bedea377 100644 --- a/src/ML-IAP/mliap_descriptor_so3.cpp +++ b/src/ML-IAP/mliap_descriptor_so3.cpp @@ -93,7 +93,7 @@ void MLIAPDescriptorSO3::read_paramfile(char *paramfilename) int eof = 0; int n, nwords; - while (1) { + while (true) { if (comm->me == 0) { ptr = utils::fgets_trunc(line, MAXLINE, fpparam); if (ptr == nullptr) { diff --git a/src/ML-IAP/mliap_model_nn.cpp b/src/ML-IAP/mliap_model_nn.cpp index 10ef97300e..853f1d9c6c 100644 --- a/src/ML-IAP/mliap_model_nn.cpp +++ b/src/ML-IAP/mliap_model_nn.cpp @@ -125,7 +125,7 @@ void MLIAPModelNN::read_coeffs(char *coefffilename) int ielem = 0; int l = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fpcoeff); if (ptr == nullptr) { diff --git a/src/ML-PACE/pair_pace.cpp b/src/ML-PACE/pair_pace.cpp index f0d6547083..56e3d6005d 100644 --- a/src/ML-PACE/pair_pace.cpp +++ b/src/ML-PACE/pair_pace.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -43,52 +42,47 @@ Copyright 2021 Yury Lysogorskiy^1, Cas van der Oord^2, Anton Bochkarev^1, #include #include +#include "ace_c_basis.h" #include "ace_evaluator.h" #include "ace_recursive.h" -#include "ace_c_basis.h" #include "ace_version.h" namespace LAMMPS_NS { - struct ACEImpl { - ACEImpl() : basis_set(nullptr), ace(nullptr){} - ~ACEImpl() {delete basis_set; delete ace;} - ACECTildeBasisSet *basis_set; - ACERecursiveEvaluator *ace; - }; -} +struct ACEImpl { + ACEImpl() : basis_set(nullptr), ace(nullptr) {} + ~ACEImpl() + { + delete basis_set; + delete ace; + } + ACECTildeBasisSet *basis_set; + ACERecursiveEvaluator *ace; +}; +} // namespace LAMMPS_NS using namespace LAMMPS_NS; using namespace MathConst; -#define MAXLINE 1024 -#define DELTA 4 +static char const *const elements_pace[] = { + "X", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", + "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", + "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", + "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", + "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", + "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", + "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr"}; +static constexpr int elements_num_pace = sizeof(elements_pace) / sizeof(const char *); -//added YL - -//keywords for ACE evaluator style -#define RECURSIVE_KEYWORD "recursive" -#define PRODUCT_KEYWORD "product" - -static int elements_num_pace = 104; -static char const *const elements_pace[104] = {"X", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", - "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", - "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", - "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", - "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", - "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", - "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", - "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr" -}; - -static int AtomicNumberByName_pace(char *elname) { +static int AtomicNumberByName_pace(char *elname) +{ for (int i = 1; i < elements_num_pace; i++) - if (strcmp(elname, elements_pace[i]) == 0) - return i; + if (strcmp(elname, elements_pace[i]) == 0) return i; return -1; } /* ---------------------------------------------------------------------- */ -PairPACE::PairPACE(LAMMPS *lmp) : Pair(lmp) { +PairPACE::PairPACE(LAMMPS *lmp) : Pair(lmp) +{ single_enable = 0; restartinfo = 0; one_coeff = 1; @@ -104,7 +98,8 @@ PairPACE::PairPACE(LAMMPS *lmp) : Pair(lmp) { check if allocated, since class can be destructed when incomplete ------------------------------------------------------------------------- */ -PairPACE::~PairPACE() { +PairPACE::~PairPACE() +{ if (copymode) return; delete aceimpl; @@ -118,7 +113,8 @@ PairPACE::~PairPACE() { /* ---------------------------------------------------------------------- */ -void PairPACE::compute(int eflag, int vflag) { +void PairPACE::compute(int eflag, int vflag) +{ int i, j, ii, jj, inum, jnum; double delx, dely, delz, evdwl; double fij[3]; @@ -149,8 +145,7 @@ void PairPACE::compute(int eflag, int vflag) { // the pointer to the list of neighbors of "i" firstneigh = list->firstneigh; - if (inum != nlocal) - error->all(FLERR,"inum: {} nlocal: {} are different",inum, nlocal); + if (inum != nlocal) error->all(FLERR, "inum: {} nlocal: {} are different", inum, nlocal); // Aidan Thompson told RD (26 July 2019) that practically always holds: // inum = nlocal @@ -160,7 +155,6 @@ void PairPACE::compute(int eflag, int vflag) { // skin atoms can be removed by setting skin to zero but here // they are disregarded anyway - //determine the maximum number of neighbours int max_jnum = -1; int nei = 0; @@ -168,8 +162,7 @@ void PairPACE::compute(int eflag, int vflag) { i = ilist[ii]; jnum = numneigh[i]; nei = nei + jnum; - if (jnum > max_jnum) - max_jnum = jnum; + if (jnum > max_jnum) max_jnum = jnum; } aceimpl->ace->resize_neighbours_cache(max_jnum); @@ -199,6 +192,7 @@ void PairPACE::compute(int eflag, int vflag) { } catch (exception &e) { error->one(FLERR, e.what()); } + // 'compute_atom' will update the `aceimpl->ace->e_atom` and `aceimpl->ace->neighbours_forces(jj, alpha)` arrays for (jj = 0; jj < jnum; jj++) { @@ -209,9 +203,9 @@ void PairPACE::compute(int eflag, int vflag) { dely = x[j][1] - ytmp; delz = x[j][2] - ztmp; - fij[0] = scale[itype][jtype]*aceimpl->ace->neighbours_forces(jj, 0); - fij[1] = scale[itype][jtype]*aceimpl->ace->neighbours_forces(jj, 1); - fij[2] = scale[itype][jtype]*aceimpl->ace->neighbours_forces(jj, 2); + fij[0] = scale[itype][itype] * aceimpl->ace->neighbours_forces(jj, 0); + fij[1] = scale[itype][itype] * aceimpl->ace->neighbours_forces(jj, 1); + fij[2] = scale[itype][itype] * aceimpl->ace->neighbours_forces(jj, 2); f[i][0] += fij[0]; f[i][1] += fij[1]; @@ -222,15 +216,14 @@ void PairPACE::compute(int eflag, int vflag) { // tally per-atom virial contribution if (vflag) - ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, - fij[0], fij[1], fij[2], - -delx, -dely, -delz); + ev_tally_xyz(i, j, nlocal, newton_pair, 0.0, 0.0, fij[0], fij[1], fij[2], -delx, -dely, + -delz); } // tally energy contribution if (eflag) { // evdwl = energy of atom I - evdwl = scale[1][1]*aceimpl->ace->e_atom; + evdwl = scale[itype][itype]*aceimpl->ace->e_atom; ev_tally_full(i, 2.0 * evdwl, 0.0, 0.0, 0.0, 0.0, 0.0); } } @@ -242,42 +235,45 @@ void PairPACE::compute(int eflag, int vflag) { /* ---------------------------------------------------------------------- */ -void PairPACE::allocate() { +void PairPACE::allocate() +{ allocated = 1; - int n = atom->ntypes; + int n = atom->ntypes + 1; - memory->create(setflag, n + 1, n + 1, "pair:setflag"); - memory->create(cutsq, n + 1, n + 1, "pair:cutsq"); - memory->create(scale, n + 1, n + 1,"pair:scale"); - map = new int[n+1]; + memory->create(setflag, n, n, "pair:setflag"); + memory->create(cutsq, n, n, "pair:cutsq"); + memory->create(scale, n, n, "pair:scale"); + map = new int[n]; } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ -void PairPACE::settings(int narg, char **arg) { - if (narg > 1) - error->all(FLERR,"Illegal pair_style command."); +void PairPACE::settings(int narg, char **arg) +{ + if (narg > 1) error->all(FLERR, "Illegal pair_style command."); // ACE potentials are parameterized in metal units - if (strcmp("metal",update->unit_style) != 0) - error->all(FLERR,"ACE potentials require 'metal' units"); + if (strcmp("metal", update->unit_style) != 0) + error->all(FLERR, "ACE potentials require 'metal' units"); - recursive = true; // default evaluator style: RECURSIVE + recursive = true; // default evaluator style: RECURSIVE if (narg > 0) { - if (strcmp(arg[0], RECURSIVE_KEYWORD) == 0) + if (strcmp(arg[0], "recursive") == 0) recursive = true; - else if (strcmp(arg[0], PRODUCT_KEYWORD) == 0) { + else if (strcmp(arg[0], "product") == 0) { recursive = false; - } else error->all(FLERR,"Illegal pair_style command"); + } else + error->all(FLERR, "Illegal pair_style command"); } if (comm->me == 0) { - utils::logmesg(lmp,"ACE version: {}.{}.{}\n", - VERSION_YEAR, VERSION_MONTH, VERSION_DAY); - if (recursive) utils::logmesg(lmp,"Recursive evaluator is used\n"); - else utils::logmesg(lmp,"Product evaluator is used\n"); + utils::logmesg(lmp, "ACE version: {}.{}.{}\n", VERSION_YEAR, VERSION_MONTH, VERSION_DAY); + if (recursive) + utils::logmesg(lmp, "Recursive evaluator is used\n"); + else + utils::logmesg(lmp, "Product evaluator is used\n"); } } @@ -285,29 +281,29 @@ void PairPACE::settings(int narg, char **arg) { set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairPACE::coeff(int narg, char **arg) { +void PairPACE::coeff(int narg, char **arg) +{ if (!allocated) allocate(); - map_element2type(narg-3,arg+3); + map_element2type(narg - 3, arg + 3); auto potential_file_name = utils::get_potential_file_path(arg[2]); char **elemtypes = &arg[3]; //load potential file delete aceimpl->basis_set; - aceimpl->basis_set = new ACECTildeBasisSet(); - if (comm->me == 0) - utils::logmesg(lmp,"Loading {}\n", potential_file_name); - aceimpl->basis_set->load(potential_file_name); + if (comm->me == 0) utils::logmesg(lmp, "Loading {}\n", potential_file_name); + aceimpl->basis_set = new ACECTildeBasisSet(potential_file_name); if (comm->me == 0) { - utils::logmesg(lmp,"Total number of basis functions\n"); + utils::logmesg(lmp, "Total number of basis functions\n"); for (SPECIES_TYPE mu = 0; mu < aceimpl->basis_set->nelements; mu++) { int n_r1 = aceimpl->basis_set->total_basis_size_rank1[mu]; int n = aceimpl->basis_set->total_basis_size[mu]; - utils::logmesg(lmp,"\t{}: {} (r=1) {} (r>1)\n", aceimpl->basis_set->elements_name[mu], n_r1, n); + utils::logmesg(lmp, "\t{}: {} (r=1) {} (r>1)\n", aceimpl->basis_set->elements_name[mu], n_r1, + n); } } @@ -324,26 +320,25 @@ void PairPACE::coeff(int narg, char **arg) { for (int i = 1; i <= n; i++) { char *elemname = elemtypes[i - 1]; int atomic_number = AtomicNumberByName_pace(elemname); - if (atomic_number == -1) - error->all(FLERR,"'{}' is not a valid element\n", elemname); + if (atomic_number == -1) error->all(FLERR, "'{}' is not a valid element\n", elemname); SPECIES_TYPE mu = aceimpl->basis_set->get_species_index_by_name(elemname); if (mu != -1) { if (comm->me == 0) - utils::logmesg(lmp,"Mapping LAMMPS atom type #{}({}) -> " - "ACE species type #{}\n", i, elemname, mu); + utils::logmesg(lmp, "Mapping LAMMPS atom type #{}({}) -> ACE species type #{}\n", i, + elemname, mu); map[i] = mu; - aceimpl->ace->element_type_mapping(i) = mu; // set up LAMMPS atom type to ACE species mapping for ace evaluator + // set up LAMMPS atom type to ACE species mapping for ace evaluator + aceimpl->ace->element_type_mapping(i) = mu; } else { - error->all(FLERR,"Element {} is not supported by ACE-potential from file {}", elemname,potential_file_name); + error->all(FLERR, "Element {} is not supported by ACE-potential from file {}", elemname, + potential_file_name); } } // initialize scale factor for (int i = 1; i <= n; i++) { - for (int j = i; j <= n; j++) { - scale[i][j] = 1.0; - } + for (int j = i; j <= n; j++) { scale[i][j] = 1.0; } } aceimpl->ace->set_basis(*aceimpl->basis_set, 1); @@ -353,11 +348,10 @@ void PairPACE::coeff(int narg, char **arg) { init specific to this pair style ------------------------------------------------------------------------- */ -void PairPACE::init_style() { - if (atom->tag_enable == 0) - error->all(FLERR, "Pair style pACE requires atom IDs"); - if (force->newton_pair == 0) - error->all(FLERR, "Pair style pACE requires newton pair on"); +void PairPACE::init_style() +{ + if (atom->tag_enable == 0) error->all(FLERR, "Pair style pACE requires atom IDs"); + if (force->newton_pair == 0) error->all(FLERR, "Pair style pACE requires newton pair on"); // request a full neighbor list int irequest = neighbor->request(this, instance_me); @@ -369,7 +363,8 @@ void PairPACE::init_style() { init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ -double PairPACE::init_one(int i, int j) { +double PairPACE::init_one(int i, int j) +{ if (setflag[i][j] == 0) error->all(FLERR, "All pair coeffs are not set"); //cutoff from the basis set's radial functions settings scale[j][i] = scale[i][j]; @@ -382,7 +377,6 @@ double PairPACE::init_one(int i, int j) { void *PairPACE::extract(const char *str, int &dim) { dim = 2; - if (strcmp(str,"scale") == 0) return (void *) scale; + if (strcmp(str, "scale") == 0) return (void *) scale; return nullptr; } - diff --git a/src/ML-RANN/pair_rann.cpp b/src/ML-RANN/pair_rann.cpp index fbc54e745f..3e97b638dc 100644 --- a/src/ML-RANN/pair_rann.cpp +++ b/src/ML-RANN/pair_rann.cpp @@ -440,7 +440,7 @@ void PairRANN::read_mass(const std::vector &line1, const std::vecto if (nelements == -1)error->one(filename,linenum-1,"atom types must be defined before mass in potential file."); for (int i=0;i line,std::vector l if (nelements == -1)error->one(filename,linenum-1,"atom types must be defined before fingerprints per element in potential file."); for (i=0;i line,std::vectorn_body_type!=nwords-1) {error->one(filename,linenum,"invalid fingerprint for element combination");} k++; - fingerprints[i][i1]->init(atomtypes,utils::inumeric(filename,linenum,line1[k++].c_str(),1,lmp)); + fingerprints[i][i1]->init(atomtypes,utils::inumeric(filename,linenum,line1[k++].c_str(),true,lmp)); fingerprintcount[i]++; } delete[] atomtypes; @@ -523,7 +523,7 @@ void PairRANN::read_fingerprint_constants(std::vector line,std::vec for (j=0;jatomtypes[j]!=atomtypes[j]) {break;} if (j==n_body_type-1) { - if (line[nwords-3].compare(fingerprints[i][k]->style)==0 && utils::inumeric(filename,linenum,line[nwords-2].c_str(),1,lmp)==fingerprints[i][k]->id) { + if (line[nwords-3].compare(fingerprints[i][k]->style)==0 && utils::inumeric(filename,linenum,line[nwords-2].c_str(),true,lmp)==fingerprints[i][k]->id) { found=true; i1 = k; break; @@ -542,7 +542,7 @@ void PairRANN::read_network_layers(std::vector line,std::vectorone(filename,linenum-1,"atom types must be defined before network layers in potential file."); for (i=0;ione(filename,linenum,"invalid number of network layers"); delete[] net[i].dimensions; weightdefined[i] = new bool [net[i].layers]; @@ -570,9 +570,9 @@ void PairRANN::read_layer_size(std::vector line,std::vectorone(filename,linenum-1,"networklayers for each atom type must be defined before the corresponding layer sizes."); - int j = utils::inumeric(filename,linenum,line[2].c_str(),1,lmp); + int j = utils::inumeric(filename,linenum,line[2].c_str(),true,lmp); if (j>=net[i].layers || j<0) {error->one(filename,linenum,"invalid layer in layer size definition");}; - net[i].dimensions[j]= utils::inumeric(filename,linenum,line1[0].c_str(),1,lmp); + net[i].dimensions[j]= utils::inumeric(filename,linenum,line1[0].c_str(),true,lmp); return; } } @@ -587,7 +587,7 @@ void PairRANN::read_weight(std::vector line,std::vectorone(filename,*linenum-1,"networklayers must be defined before weights."); - i=utils::inumeric(filename,*linenum,line[2].c_str(),1,lmp); + i=utils::inumeric(filename,*linenum,line[2].c_str(),true,lmp); if (i>=net[l].layers || i<0)error->one(filename,*linenum-1,"invalid weight layer"); if (net[l].dimensions[i]==0 || net[l].dimensions[i+1]==0) error->one(filename,*linenum-1,"network layer sizes must be defined before corresponding weight"); net[l].Weights[i] = new double[net[l].dimensions[i]*net[l].dimensions[i+1]]; @@ -595,7 +595,7 @@ void PairRANN::read_weight(std::vector line,std::vectorone(filename,*linenum,"invalid weights per line"); for (k=0;k line,std::vectorone(filename,*linenum,"invalid weights per line"); for (k=0;k line,std::vector for (l=0;lone(filename,*linenum-1,"networklayers must be defined before biases."); - i=utils::inumeric(filename,*linenum,line[2].c_str(),1,lmp); + i=utils::inumeric(filename,*linenum,line[2].c_str(),true,lmp); if (i>=net[l].layers || i<0)error->one(filename,*linenum-1,"invalid bias layer"); if (net[l].dimensions[i]==0) error->one(filename,*linenum-1,"network layer sizes must be defined before corresponding bias"); biasdefined[l][i] = true; net[l].Biases[i] = new double[net[l].dimensions[i+1]]; - net[l].Biases[i][0] = utils::numeric(filename,*linenum,line1[0].c_str(),1,lmp); + net[l].Biases[i][0] = utils::numeric(filename,*linenum,line1[0].c_str(),true,lmp); for (j=1;jone(filename,*linenum,"unexpected end of potential file!"); (*linenum)++; Tokenizer values1 = Tokenizer(linetemp,": ,\t_\n"); line1 = values1.as_vector(); - net[l].Biases[i][j] = utils::numeric(filename,*linenum,line1[0].c_str(),1,lmp); + net[l].Biases[i][j] = utils::numeric(filename,*linenum,line1[0].c_str(),true,lmp); } return; } @@ -680,10 +680,10 @@ void PairRANN::read_screening(std::vector line,std::vectorone(filename,linenum-1,"unrecognized screening keyword"); delete[] atomtypes; diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index d6da639734..1eb078bc61 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -640,7 +640,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) } eof = 0; - while (1) { + while (true) { if (comm->me == 0) { ptr = fgets(line,MAXLINE,fpparam); if (ptr == nullptr) { diff --git a/src/MOLECULE/fix_cmap.cpp b/src/MOLECULE/fix_cmap.cpp index 4bc035fdf5..26a0ab2542 100644 --- a/src/MOLECULE/fix_cmap.cpp +++ b/src/MOLECULE/fix_cmap.cpp @@ -30,18 +30,19 @@ #include "fix_cmap.h" -#include - -#include #include "atom.h" -#include "update.h" -#include "respa.h" -#include "domain.h" -#include "force.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "respa.h" +#include "tokenizer.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -1043,12 +1044,24 @@ void FixCMAP::bc_interpol(double x1, double x2, int low1, int low2, double *gs, void FixCMAP::read_data_header(char *line) { - if (strstr(line,"crossterms")) { - sscanf(line,BIGINT_FORMAT,&ncmap); - } else error->all(FLERR,"Invalid read data header line for fix cmap"); + ValueTokenizer values(line); - // didn't set in constructor because this fix could be defined - // before newton command + try { + ncmap = values.next_bigint(); + if (values.count() == 2) { + if (values.next_string() != "crossterms") + throw TokenizerException("invalid format",utils::trim(line)); + } else if (values.count() == 3) { + if ((values.next_string() != "cmap") || (values.next_string() != "crossterms")) + throw TokenizerException("invalid format",utils::trim(line)); + } else { + throw TokenizerException("valid format",utils::trim(line)); + } + } catch (std::exception &e) { + error->all(FLERR,"Invalid read data header line for fix cmap: {}", e.what()); + } + + // not set in constructor because this fix could be defined before newton command newton_bond = force->newton_bond; } @@ -1064,26 +1077,28 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, { int m,tmp,itype; tagint atom1,atom2,atom3,atom4,atom5; - char *next; - next = strchr(buf,'\n'); - *next = '\0'; - int nwords = utils::count_words(utils::trim_comment(buf)); - *next = '\n'; - - if (nwords != 7) - error->all(FLERR,"Incorrect {} format in data file",keyword); + auto lines = utils::split_lines(buf); + if (lines.size() == 0) return; // loop over lines of CMAP crossterms // tokenize the line into values // add crossterm to one of my atoms, depending on newton_bond - for (int i = 0; i < n; i++) { - next = strchr(buf,'\n'); - *next = '\0'; - sscanf(buf,"%d %d " TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT - " " TAGINT_FORMAT " " TAGINT_FORMAT, - &tmp,&itype,&atom1,&atom2,&atom3,&atom4,&atom5); + for (const auto &line : lines) { + ValueTokenizer values(line); + try { + values.skip(); + itype = values.next_int(); + atom1 = values.next_tagint(); + atom2 = values.next_tagint(); + atom3 = values.next_tagint(); + atom4 = values.next_tagint(); + atom5 = values.next_tagint(); + if (values.has_next()) throw TokenizerException("too many items",line); + } catch (std::exception &e) { + error->all(FLERR,"Incorrect format of CMAP section: {}", e.what()); + } atom1 += id_offset; atom2 += id_offset; @@ -1092,8 +1107,7 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, atom5 += id_offset; if ((m = atom->map(atom1)) >= 0) { - if (num_crossterm[m] == CMAPMAX) - error->one(FLERR,"Too many CMAP crossterms for one atom"); + if (num_crossterm[m] == CMAPMAX) error->one(FLERR,"Too many CMAP crossterms for one atom"); crossterm_type[m][num_crossterm[m]] = itype; crossterm_atom1[m][num_crossterm[m]] = atom1; crossterm_atom2[m][num_crossterm[m]] = atom2; @@ -1104,8 +1118,7 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, } if ((m = atom->map(atom2)) >= 0) { - if (num_crossterm[m] == CMAPMAX) - error->one(FLERR,"Too many CMAP crossterms for one atom"); + if (num_crossterm[m] == CMAPMAX) error->one(FLERR,"Too many CMAP crossterms for one atom"); crossterm_type[m][num_crossterm[m]] = itype; crossterm_atom1[m][num_crossterm[m]] = atom1; crossterm_atom2[m][num_crossterm[m]] = atom2; @@ -1116,8 +1129,7 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, } if ((m = atom->map(atom3)) >= 0) { - if (num_crossterm[m] == CMAPMAX) - error->one(FLERR,"Too many CMAP crossterms for one atom"); + if (num_crossterm[m] == CMAPMAX) error->one(FLERR,"Too many CMAP crossterms for one atom"); crossterm_type[m][num_crossterm[m]] = itype; crossterm_atom1[m][num_crossterm[m]] = atom1; crossterm_atom2[m][num_crossterm[m]] = atom2; @@ -1128,8 +1140,7 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, } if ((m = atom->map(atom4)) >= 0) { - if (num_crossterm[m] == CMAPMAX) - error->one(FLERR,"Too many CMAP crossterms for one atom"); + if (num_crossterm[m] == CMAPMAX) error->one(FLERR,"Too many CMAP crossterms for one atom"); crossterm_type[m][num_crossterm[m]] = itype; crossterm_atom1[m][num_crossterm[m]] = atom1; crossterm_atom2[m][num_crossterm[m]] = atom2; @@ -1140,8 +1151,7 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, } if ((m = atom->map(atom5)) >= 0) { - if (num_crossterm[m] == CMAPMAX) - error->one(FLERR,"Too many CMAP crossterms for one atom"); + if (num_crossterm[m] == CMAPMAX) error->one(FLERR,"Too many CMAP crossterms for one atom"); crossterm_type[m][num_crossterm[m]] = itype; crossterm_atom1[m][num_crossterm[m]] = atom1; crossterm_atom2[m][num_crossterm[m]] = atom2; @@ -1150,8 +1160,6 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, crossterm_atom5[m][num_crossterm[m]] = atom5; num_crossterm[m]++; } - - buf = next + 1; } } @@ -1169,7 +1177,7 @@ bigint FixCMAP::read_data_skip_lines(char * /*keyword*/) void FixCMAP::write_data_header(FILE *fp, int /*mth*/) { - fprintf(fp,BIGINT_FORMAT " cmap crossterms\n",ncmap); + fmt::print(fp,"{} crossterms\n",ncmap); } /* ---------------------------------------------------------------------- @@ -1247,11 +1255,9 @@ void FixCMAP::write_data_section(int /*mth*/, FILE *fp, int n, double **buf, int index) { for (int i = 0; i < n; i++) - fprintf(fp,"%d %d " TAGINT_FORMAT " " TAGINT_FORMAT - " " TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT "\n", - index+i,(int) ubuf(buf[i][0]).i,(tagint) ubuf(buf[i][1]).i, - (tagint) ubuf(buf[i][2]).i,(tagint) ubuf(buf[i][3]).i, - (tagint) ubuf(buf[i][4]).i,(tagint) ubuf(buf[i][5]).i); + fmt::print(fp,"{} {} {} {} {} {} {}\n", + index+i,ubuf(buf[i][0]).i, ubuf(buf[i][1]).i, ubuf(buf[i][2]).i, + ubuf(buf[i][3]).i,ubuf(buf[i][4]).i,ubuf(buf[i][5]).i); } // ---------------------------------------------------------------------- diff --git a/src/OPENMP/fix_gravity_omp.cpp b/src/OPENMP/fix_gravity_omp.cpp index 7354ec2aa4..72d2fdc59b 100644 --- a/src/OPENMP/fix_gravity_omp.cpp +++ b/src/OPENMP/fix_gravity_omp.cpp @@ -30,7 +30,6 @@ using namespace LAMMPS_NS; using namespace FixConst; enum{CHUTE,SPHERICAL,GRADIENT,VECTOR}; -enum{CONSTANT,EQUAL}; /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/pair_peri_lps_omp.cpp b/src/OPENMP/pair_peri_lps_omp.cpp index b88794e274..0eefe8d55c 100644 --- a/src/OPENMP/pair_peri_lps_omp.cpp +++ b/src/OPENMP/pair_peri_lps_omp.cpp @@ -113,10 +113,10 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -225,7 +225,7 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) // Compute the dilatation on each particle if (iifrom < nlocal) - compute_dilatation_thr(iifrom, iito); + compute_dilatation(iifrom, iito); // wait until all threads are done before communication sync_threads(); @@ -237,7 +237,7 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) comm->forward_comm_pair(this); // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); } sync_threads(); @@ -363,93 +363,6 @@ void PairPeriLPSOMP::eval(int iifrom, int iito, ThrData * const thr) /* ---------------------------------------------------------------------- */ -void PairPeriLPSOMP::compute_dilatation_thr(int ifrom, int ito) -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = ifrom; i < ito; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // Look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // Skip if particle is "lost" - if (j < 0) continue; - - // Compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - -/* ---------------------------------------------------------------------- */ - double PairPeriLPSOMP::memory_usage() { double bytes = memory_usage_thr(); diff --git a/src/OPENMP/pair_peri_lps_omp.h b/src/OPENMP/pair_peri_lps_omp.h index 4bb71bbe5f..758e17bcf3 100644 --- a/src/OPENMP/pair_peri_lps_omp.h +++ b/src/OPENMP/pair_peri_lps_omp.h @@ -37,9 +37,6 @@ class PairPeriLPSOMP : public PairPeriLPS, public ThrOMP { virtual void compute(int, int); virtual double memory_usage(); - protected: - void compute_dilatation_thr(int ifrom, int ito); - private: template void eval(int ifrom, int ito, ThrData *const thr); diff --git a/src/OPENMP/pair_peri_pmb_omp.cpp b/src/OPENMP/pair_peri_pmb_omp.cpp index 73abf1c7e9..54d5969d8f 100644 --- a/src/OPENMP/pair_peri_pmb_omp.cpp +++ b/src/OPENMP/pair_peri_pmb_omp.cpp @@ -109,9 +109,9 @@ void PairPeriPMBOMP::eval(int iifrom, int iito, ThrData * const thr) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; // lc = lattice constant // init_style guarantees it's the same in x, y, and z diff --git a/src/OPENMP/pair_reaxff_omp.cpp b/src/OPENMP/pair_reaxff_omp.cpp index d39672f09b..454f56c55f 100644 --- a/src/OPENMP/pair_reaxff_omp.cpp +++ b/src/OPENMP/pair_reaxff_omp.cpp @@ -101,15 +101,17 @@ PairReaxFFOMP::~PairReaxFFOMP() void PairReaxFFOMP::init_style() { - bool have_qeq = ((modify->find_fix_by_style("^qeq/reax") != -1) - || (modify->find_fix_by_style("^qeq/shielded") != -1) - || (modify->find_fix_by_style("^acks2/reax") != -1)); - if (!have_qeq && qeqflag == 1) - error->all(FLERR,"Pair reaxff/omp requires use of fix qeq/reaxff or qeq/shielded" - " or fix acks2/reaxff"); + if (!atom->q_flag) error->all(FLERR,"Pair style reaxff/omp requires atom attribute q"); - int have_acks2 = (modify->find_fix_by_style("^acks2/reax") != -1); - api->system->acks2_flag = have_acks2; + auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); + int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size(); + + if (qeqflag && (have_qeq != 1)) + error->all(FLERR,"Pair style reaxff/omp requires use of exactly one of the " + "fix qeq/reaxff or fix qeq/shielded or fix acks2/reaxff commands"); + + api->system->acks2_flag = acks2_fixes.size(); if (api->system->acks2_flag) error->all(FLERR,"Cannot (yet) use ACKS2 with OPENMP ReaxFF"); diff --git a/src/OPENMP/respa_omp.cpp b/src/OPENMP/respa_omp.cpp index cc4d3925b1..c6500185ad 100644 --- a/src/OPENMP/respa_omp.cpp +++ b/src/OPENMP/respa_omp.cpp @@ -67,21 +67,23 @@ void RespaOMP::init() void RespaOMP::setup(int flag) { if (comm->me == 0 && screen) { - fprintf(screen,"Setting up r-RESPA/omp run ...\n"); + std::string mesg = "Setting up r-RESPA/omp run ...\n"; if (flag) { - fprintf(screen," Unit style : %s\n", update->unit_style); - fprintf(screen," Current step : " BIGINT_FORMAT "\n", update->ntimestep); - fprintf(screen," Time steps :"); - for (int ilevel=0; ilevel < nlevels; ++ilevel) - fprintf(screen," %d:%g",ilevel+1, step[ilevel]); - fprintf(screen,"\n r-RESPA fixes :"); - for (int l=0; l < modify->n_post_force_respa; ++l) { - Fix *f = modify->fix[modify->list_post_force_respa[l]]; + mesg += fmt::format(" Unit style : {}\n", update->unit_style); + mesg += fmt::format(" Current step : {}\n", update->ntimestep); + + mesg += " Time steps :"; + for (int ilevel = 0; ilevel < nlevels; ++ilevel) + mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); + + mesg += "\n r-RESPA fixes :"; + for (int l = 0; l < modify->n_post_force_respa; ++l) { + Fix *f = modify->get_fix_by_index(modify->list_post_force_respa[l]); if (f->respa_level >= 0) - fprintf(screen," %d:%s[%s]", - MIN(f->respa_level+1,nlevels),f->style,f->id); + mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); } - fprintf(screen,"\n"); + mesg += "\n"; + fputs(mesg.c_str(), screen); timer->print_timeout(screen); } } diff --git a/src/PERI/compute_damage_atom.cpp b/src/PERI/compute_damage_atom.cpp index 1e5a6102dc..6349d324b2 100644 --- a/src/PERI/compute_damage_atom.cpp +++ b/src/PERI/compute_damage_atom.cpp @@ -17,21 +17,23 @@ ------------------------------------------------------------------------- */ #include "compute_damage_atom.h" -#include + #include "atom.h" -#include "update.h" -#include "modify.h" #include "comm.h" +#include "error.h" #include "fix_peri_neigh.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeDamageAtom::ComputeDamageAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), damage(nullptr) + Compute(lmp, narg, arg), damage(nullptr), fix_peri_neigh(nullptr) { if (narg != 3) error->all(FLERR,"Illegal compute damage/atom command"); @@ -52,17 +54,15 @@ ComputeDamageAtom::~ComputeDamageAtom() void ComputeDamageAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"damage/peri") == 0) count++; - if (count > 1 && comm->me == 0) - error->warning(FLERR,"More than one compute damage/atom"); + if ((comm->me == 0) && (modify->get_compute_by_style("damage/atom").size() > 1)) + error->warning(FLERR,"More than one compute dilatation/atom"); // find associated PERI_NEIGH fix that must exist - ifix_peri = modify->find_fix_by_style("PERI_NEIGH"); - if (ifix_peri == -1) + auto fixes = modify->get_fix_by_style("PERI_NEIGH"); + if (fixes.size() == 0) error->all(FLERR,"Compute damage/atom requires a peridynamic potential"); + else fix_peri_neigh = (FixPeriNeigh *)fixes.front(); } /* ---------------------------------------------------------------------- */ @@ -85,9 +85,9 @@ void ComputeDamageAtom::compute_peratom() int nlocal = atom->nlocal; int *mask = atom->mask; double *vfrac = atom->vfrac; - double *vinter = ((FixPeriNeigh *) modify->fix[ifix_peri])->vinter; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double *vinter = fix_peri_neigh->vinter; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; int i,j,jj,jnum; double damage_temp; diff --git a/src/PERI/compute_damage_atom.h b/src/PERI/compute_damage_atom.h index 7530a1cb02..43b28c3794 100644 --- a/src/PERI/compute_damage_atom.h +++ b/src/PERI/compute_damage_atom.h @@ -35,7 +35,7 @@ class ComputeDamageAtom : public Compute { private: int nmax; double *damage; - int ifix_peri; + class FixPeriNeigh *fix_peri_neigh; }; } // namespace LAMMPS_NS diff --git a/src/PERI/compute_dilatation_atom.cpp b/src/PERI/compute_dilatation_atom.cpp index 7735bbbaac..fe78bc76bf 100644 --- a/src/PERI/compute_dilatation_atom.cpp +++ b/src/PERI/compute_dilatation_atom.cpp @@ -24,9 +24,7 @@ #include "force.h" #include "memory.h" #include "modify.h" -#include "pair_peri_eps.h" -#include "pair_peri_lps.h" -#include "pair_peri_ves.h" +#include "pair.h" #include "update.h" #include @@ -59,28 +57,13 @@ ComputeDilatationAtom::~ComputeDilatationAtom() void ComputeDilatationAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"dilatation/peri") == 0) count++; - if (count > 1 && comm->me == 0) + if ((comm->me == 0) && (modify->get_compute_by_style("dilatation/atom").size() > 1)) error->warning(FLERR,"More than one compute dilatation/atom"); - // check PD pair style + // check for compatible pair style - isPMB = isLPS = isVES = isEPS = 0; - if (force->pair_match("^peri/pmb",0)) isPMB = 1; - if (force->pair_match("^peri/lps",0)) isLPS = 1; - if (force->pair_match("^peri/ves",0)) isVES = 1; - if (force->pair_match("^peri/eps",0)) isEPS = 1; - - if (isPMB) - error->all(FLERR,"Compute dilatation/atom cannot be used " - "with this pair style"); - - // find associated PERI_NEIGH fix that must exist - - if (modify->find_fix_by_style("^PERI_NEIGH") == -1) - error->all(FLERR,"Compute dilatation/atom requires Peridynamic pair style"); + if ((force->pair_match("^peri",0) == nullptr) || force->pair_match("^peri/pmb",0)) + error->all(FLERR,"Compute dilatation/atom cannot be used with this pair style"); } /* ---------------------------------------------------------------------- */ @@ -100,11 +83,9 @@ void ComputeDilatationAtom::compute_peratom() // extract dilatation for each atom in group - double *theta; - Pair *anypair = force->pair_match("peri",0); - if (isLPS) theta = ((PairPeriLPS *) anypair)->theta; - if (isVES) theta = ((PairPeriVES *) anypair)->theta; - if (isEPS) theta = ((PairPeriEPS *) anypair)->theta; + int tmp; + auto anypair = force->pair_match("^peri",0); + double *theta = (double *)anypair->extract("theta",tmp); int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/PERI/compute_dilatation_atom.h b/src/PERI/compute_dilatation_atom.h index ee675c0bb7..476634753d 100644 --- a/src/PERI/compute_dilatation_atom.h +++ b/src/PERI/compute_dilatation_atom.h @@ -25,11 +25,6 @@ ComputeStyle(dilatation/atom,ComputeDilatationAtom); namespace LAMMPS_NS { class ComputeDilatationAtom : public Compute { - friend class PairPeriPMB; - friend class PairPeriLPS; - friend class PairPeriVES; - friend class PairPeriEPS; - public: ComputeDilatationAtom(class LAMMPS *, int, char **); ~ComputeDilatationAtom(); @@ -40,7 +35,6 @@ class ComputeDilatationAtom : public Compute { private: int nmax; double *dilatation; - int isPMB, isLPS, isVES, isEPS; }; } // namespace LAMMPS_NS diff --git a/src/PERI/compute_plasticity_atom.cpp b/src/PERI/compute_plasticity_atom.cpp index 74d4b298a7..11ecdfb7ec 100644 --- a/src/PERI/compute_plasticity_atom.cpp +++ b/src/PERI/compute_plasticity_atom.cpp @@ -17,22 +17,23 @@ ------------------------------------------------------------------------- */ #include "compute_plasticity_atom.h" -#include + #include "atom.h" -#include "update.h" -#include "modify.h" #include "comm.h" +#include "error.h" #include "fix_peri_neigh.h" #include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -ComputePlasticityAtom:: -ComputePlasticityAtom(LAMMPS *lmp, int narg, char **arg) : +ComputePlasticityAtom::ComputePlasticityAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg) { if (narg != 3) error->all(FLERR,"Illegal compute plasticity/atom command"); @@ -59,17 +60,15 @@ ComputePlasticityAtom::~ComputePlasticityAtom() void ComputePlasticityAtom::init() { - int count = 0; - for (int i = 0; i < modify->ncompute; i++) - if (strcmp(modify->compute[i]->style,"plasticity/peri") == 0) count++; - if (count > 1 && comm->me == 0) + if ((comm->me == 0) && (modify->get_compute_by_style("plasticity/atom").size() > 1)) error->warning(FLERR,"More than one compute plasticity/atom"); // find associated PERI_NEIGH fix that must exist - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Compute plasticity/atom requires a Peridynamics pair style"); + auto fixes = modify->get_fix_by_style("PERI_NEIGH"); + if (fixes.size() == 0) + error->all(FLERR,"Compute plasticity/atom requires a peridynamic potential"); + else fix_peri_neigh = (FixPeriNeigh *)fixes.front(); } /* ---------------------------------------------------------------------- */ @@ -89,7 +88,7 @@ void ComputePlasticityAtom::compute_peratom() // extract plasticity for each atom in group - double *lambdaValue = ((FixPeriNeigh *) modify->fix[ifix_peri])->lambdaValue; + double *lambdaValue = fix_peri_neigh->lambdaValue; int *mask = atom->mask; int nlocal = atom->nlocal; diff --git a/src/PERI/compute_plasticity_atom.h b/src/PERI/compute_plasticity_atom.h index b77182d251..cbb1182dee 100644 --- a/src/PERI/compute_plasticity_atom.h +++ b/src/PERI/compute_plasticity_atom.h @@ -35,7 +35,7 @@ class ComputePlasticityAtom : public Compute { private: int nmax; double *plasticity; - int ifix_peri; + class FixPeriNeigh *fix_peri_neigh; }; } // namespace LAMMPS_NS diff --git a/src/PERI/fix_peri_neigh.cpp b/src/PERI/fix_peri_neigh.cpp index 74b192b70f..47cb183a7d 100644 --- a/src/PERI/fix_peri_neigh.cpp +++ b/src/PERI/fix_peri_neigh.cpp @@ -18,7 +18,6 @@ #include "fix_peri_neigh.h" -#include #include "pair_peri_lps.h" #include "pair_peri_ves.h" #include "pair_peri_eps.h" @@ -34,6 +33,9 @@ #include "memory.h" #include "error.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -68,6 +70,7 @@ FixPeriNeigh::FixPeriNeigh(LAMMPS *lmp,int narg, char **arg) : wvolume = nullptr; grow_arrays(atom->nmax); + memset(wvolume,0,atom->nmax*sizeof(double)); atom->add_callback(Atom::GROW); atom->add_callback(Atom::RESTART); diff --git a/src/PERI/fix_peri_neigh.h b/src/PERI/fix_peri_neigh.h index ac9784f6e6..bde8f3f2da 100644 --- a/src/PERI/fix_peri_neigh.h +++ b/src/PERI/fix_peri_neigh.h @@ -25,6 +25,7 @@ FixStyle(PERI_NEIGH,FixPeriNeigh); namespace LAMMPS_NS { class FixPeriNeigh : public Fix { + friend class PairPeri; friend class PairPeriPMB; friend class PairPeriPMBOMP; friend class PairPeriLPS; diff --git a/src/PERI/pair_peri.cpp b/src/PERI/pair_peri.cpp new file mode 100644 index 0000000000..44c83661c9 --- /dev/null +++ b/src/PERI/pair_peri.cpp @@ -0,0 +1,263 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "pair_peri.h" + +#include "atom.h" +#include "domain.h" +#include "error.h" +#include "fix_peri_neigh.h" +#include "lattice.h" +#include "memory.h" +#include "modify.h" +#include "neigh_request.h" +#include "neighbor.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairPeri::PairPeri(LAMMPS *_lmp) : + Pair(_lmp), fix_peri_neigh(nullptr), bulkmodulus(nullptr), shearmodulus(nullptr), + m_lambdai(nullptr), m_taubi(nullptr), m_yieldstress(nullptr), s00(nullptr), alpha(nullptr), + cut(nullptr), kspring(nullptr), s0_new(nullptr), theta(nullptr), elastic_energy(nullptr) +{ + for (int i = 0; i < 6; i++) virial[i] = 0.0; + no_virial_fdotr_compute = 1; + single_enable = 0; + nmax = -1; +} + +/* ---------------------------------------------------------------------- */ + +PairPeri::~PairPeri() +{ + if (fix_peri_neigh) modify->delete_fix(fix_peri_neigh->id); + + if (allocated) { + memory->destroy(bulkmodulus); + memory->destroy(shearmodulus); + memory->destroy(m_lambdai); + memory->destroy(m_taubi); + memory->destroy(m_yieldstress); + memory->destroy(s00); + memory->destroy(alpha); + memory->destroy(cut); + memory->destroy(cutsq); + memory->destroy(setflag); + memory->destroy(kspring); + + memory->destroy(s0_new); + memory->destroy(theta); + memory->destroy(elastic_energy); + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairPeri::allocate() +{ + allocated = 1; + int n = atom->ntypes + 1; + + memory->create(setflag, n, n, "pair:setflag"); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) setflag[i][j] = 0; + + memory->create(cutsq, n, n, "pair:cutsq"); + memory->create(bulkmodulus, n, n, "pair:bulkmodulus"); + memory->create(shearmodulus, n, n, "pair:shearmodulus"); + memory->create(s00, n, n, "pair:s00"); + memory->create(alpha, n, n, "pair:alpha"); + memory->create(cut, n, n, "pair:cut"); + memory->create(m_yieldstress, n, n, "pair:m_yieldstress"); + memory->create(m_lambdai, n, n, "pair:m_lambdai"); + memory->create(m_taubi, n, n, "pair:m_taubi"); + memory->create(kspring, n, n, "pair:m_taubi"); +} + +/* ---------------------------------------------------------------------- + memory usage of local arrays +------------------------------------------------------------------------- */ + +double PairPeri::memory_usage() +{ + double bytes = 2.0 * (double) nmax * sizeof(double); + bytes += 10.0 * (double) atom->ntypes * atom->ntypes * sizeof(double); + return bytes; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairPeri::settings(int narg, char **/*arg*/) +{ + if (narg) error->all(FLERR,"Illegal pair_style command"); +} + +/* ---------------------------------------------------------------------- + init common to all peridynamics pair styles +------------------------------------------------------------------------- */ + +void PairPeri::init_style() +{ + // error checks + + if (!atom->peri_flag) error->all(FLERR, "Pair style peri requires atom style peri"); + if (atom->map_style == Atom::MAP_NONE) + error->all(FLERR, "Pair peri requires an atom map, see atom_modify"); + + if (domain->lattice == nullptr) error->all(FLERR, "Pair peri requires a lattice be defined"); + if (domain->lattice->xlattice != domain->lattice->ylattice || + domain->lattice->xlattice != domain->lattice->zlattice || + domain->lattice->ylattice != domain->lattice->zlattice) + error->all(FLERR, "Pair peri lattice is not identical in x, y, and z"); + + // if first init, create Fix needed for storing fixed neighbors + + if (!fix_peri_neigh) + fix_peri_neigh = (FixPeriNeigh *) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); + + neighbor->request(this, instance_me); +} + +/* ---------------------------------------------------------------------- */ + +void PairPeri::compute_dilatation(int ifrom, int ito) +{ + int i, j, jj, jnum, itype, jtype; + double xtmp, ytmp, ztmp, delx, dely, delz; + double xtmp0, ytmp0, ztmp0, delx0, dely0, delz0; + double rsq, r, dr; + double delta; + + double **x = atom->x; + int *type = atom->type; + double **x0 = atom->x0; + double *vfrac = atom->vfrac; + double vfrac_scale = 1.0; + + double lc = domain->lattice->xlattice; + double half_lc = 0.5 * lc; + + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + + int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; + + // compute the dilatation theta + + for (i = ifrom; i < ito; i++) { + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + xtmp0 = x0[i][0]; + ytmp0 = x0[i][1]; + ztmp0 = x0[i][2]; + jnum = npartner[i]; + theta[i] = 0.0; + itype = type[i]; + + for (jj = 0; jj < jnum; jj++) { + + // if bond already broken, skip this partner + if (partner[i][jj] == 0) continue; + + // look up local index of this partner particle + j = atom->map(partner[i][jj]); + + // skip if particle is "lost" + if (j < 0) continue; + + // compute force density and add to PD equation of motion + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + if (periodic) domain->minimum_image(delx, dely, delz); + rsq = delx * delx + dely * dely + delz * delz; + delx0 = xtmp0 - x0[j][0]; + dely0 = ytmp0 - x0[j][1]; + delz0 = ztmp0 - x0[j][2]; + if (periodic) domain->minimum_image(delx0, dely0, delz0); + + r = sqrt(rsq); + dr = r - r0[i][jj]; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; + + jtype = type[j]; + delta = cut[itype][jtype]; + + // scale vfrac[j] if particle j near the horizon + + if ((fabs(r0[i][jj] - delta)) <= half_lc) + vfrac_scale = + (-1.0 / (2 * half_lc)) * (r0[i][jj]) + (1.0 + ((delta - half_lc) / (2 * half_lc))); + else + vfrac_scale = 1.0; + + theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * vfrac[j] * vfrac_scale; + } + + // if wvolume[i] is zero, then particle i has no bonds + // therefore, the dilatation is set to zero + + if (wvolume[i] != 0.0) + theta[i] = (3.0 / wvolume[i]) * theta[i]; + else + theta[i] = 0; + } +} + +/* ---------------------------------------------------------------------- + communication routines +---------------------------------------------------------------------- */ + +int PairPeri::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) +{ + int i, j, m; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = theta[j]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void PairPeri::unpack_forward_comm(int n, int first, double *buf) +{ + int i, m, last; + + m = 0; + last = first + n; + for (i = first; i < last; i++) { theta[i] = buf[m++]; } +} + +/* ---------------------------------------------------------------------- */ + +void *PairPeri::extract(const char *name, int &dim) +{ + dim = 1; + if (strcmp(name, "theta") == 0) return (void *) theta; + if (strcmp(name, "elastic_energy") == 0) return (void *) elastic_energy; + return nullptr; +} diff --git a/src/PERI/pair_peri.h b/src/PERI/pair_peri.h new file mode 100644 index 0000000000..f3b41de4f5 --- /dev/null +++ b/src/PERI/pair_peri.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_PERI_H +#define LMP_PAIR_PERI_H + +#include "pair.h" +#include + +namespace LAMMPS_NS { + +class PairPeri : public Pair { + public: + PairPeri(class LAMMPS *); + virtual ~PairPeri(); + + virtual int pack_forward_comm(int, int *, double *, int, int *); + virtual void unpack_forward_comm(int, int, double *); + + virtual void init_style(); + virtual void settings(int, char **); + static constexpr double NEAR_ZERO = 2.2204e-16; + + double influence_function(const double &xi_x, const double &xi_y, const double &xi_z) const + { + const double r = sqrt((xi_x * xi_x) + (xi_y * xi_y) + (xi_z * xi_z)); + return (fabs(r) < NEAR_ZERO) ? 1.0 / NEAR_ZERO : (1.0 / r); + } + void compute_dilatation(int, int); + + double memory_usage(); + virtual void *extract(const char *, int &); + + protected: + class FixPeriNeigh *fix_peri_neigh; + double **bulkmodulus, **shearmodulus, **m_lambdai, **m_taubi, **m_yieldstress; + double **s00, **alpha, **cut, **kspring; + double *s0_new, *theta, *elastic_energy; + + int nmax; + + protected: + void allocate(); +}; + +} // namespace LAMMPS_NS + +#endif diff --git a/src/PERI/pair_peri_eps.cpp b/src/PERI/pair_peri_eps.cpp index f6e99332b3..8d1aa9b49f 100644 --- a/src/PERI/pair_peri_eps.cpp +++ b/src/PERI/pair_peri_eps.cpp @@ -26,6 +26,7 @@ #include "force.h" #include "lattice.h" #include "math_const.h" +#include "math_special.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" @@ -36,27 +37,12 @@ using namespace LAMMPS_NS; using namespace MathConst; +using MathSpecial::powint; /* ---------------------------------------------------------------------- */ -PairPeriEPS::PairPeriEPS(LAMMPS *lmp) : Pair(lmp) +PairPeriEPS::PairPeriEPS(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = -1; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - m_yieldstress = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -65,26 +51,6 @@ PairPeriEPS::PairPeriEPS(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriEPS::~PairPeriEPS() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(m_yieldstress); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriEPS::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -107,13 +73,12 @@ void PairPeriEPS::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - double **deviatorPlasticextension = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorPlasticextension; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - double *lambdaValue = ((FixPeriNeigh *) modify->fix[ifix_peri])->lambdaValue; + double **r0 = fix_peri_neigh->r0; + double **deviatorPlasticextension = fix_peri_neigh->deviatorPlasticextension; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + double *lambdaValue = fix_peri_neigh->lambdaValue; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -208,14 +173,12 @@ void PairPeriEPS::compute(int eflag, int vflag) int maxpartner = 0; for (i = 0; i < nlocal; i++) maxpartner = MAX(maxpartner,npartner[i]); - if (nlocal > nmax) { memory->destroy(s0_new); memory->destroy(theta); nmax = atom->nmax; memory->create(s0_new,nmax,"pair:s0_new"); memory->create(theta,nmax,"pair:theta"); - } // ******** temp array to store Plastic extension *********** /// @@ -228,7 +191,7 @@ void PairPeriEPS::compute(int eflag, int vflag) // ******** temp array to store Plastic extension *********** /// // compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); @@ -236,7 +199,7 @@ void PairPeriEPS::compute(int eflag, int vflag) // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // volume-dependent part of the energy @@ -269,21 +232,17 @@ void PairPeriEPS::compute(int eflag, int vflag) jnum = npartner[i]; first = true; - - double yieldStress = m_yieldstress[itype][itype]; - double horizon = cut[itype][itype]; - double tdnorm = compute_DeviatoricForceStateNorm(i); - double pointwiseYieldvalue = 25.0 * yieldStress * - yieldStress / 8 / MY_PI / pow(horizon,5); - - - double fsurf = (tdnorm * tdnorm)/2 - pointwiseYieldvalue; + const double yieldStress = m_yieldstress[itype][itype]; + const double horizon = cut[itype][itype]; + const double tdnorm = compute_DeviatoricForceStateNorm(i); + const double pointwiseYieldvalue = 25.0/8.0/MY_PI/powint(horizon,5)*yieldStress*yieldStress; + const double fsurf = (tdnorm * tdnorm)/2.0 - pointwiseYieldvalue; bool elastic = true; - if (fsurf > 0) { + if (fsurf > 0.0) { elastic = false; deltalambda = ((tdnorm /sqrt(2.0 * pointwiseYieldvalue)) - 1.0) * wvolume[i] - / (15 * shearmodulus[itype][itype]); + / (15.0 * shearmodulus[itype][itype]); double templambda = lambdaValue[i]; lambdaValue[i] = templambda + deltalambda; } @@ -316,34 +275,31 @@ void PairPeriEPS::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) { - dr = 0.0; - } + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); + vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + (1.0 + ((delta - half_lc)/(2*half_lc))); else vfrac_scale = 1.0; omega_plus = influence_function(-1.0*delx0,-1.0*dely0,-1.0*delz0); omega_minus = influence_function(delx0,dely0,delz0); - //Elastic Part - rk = ((3.0 * bulkmodulus[itype][itype]) * ( (omega_plus * theta[i] / wvolume[i]) + - ( omega_minus * theta[j] / wvolume[j] ) ) ) * r0[i][jj]; + // Elastic Part + rk = ((3.0 * bulkmodulus[itype][itype]) * ((omega_plus * theta[i] / wvolume[i]) + + (omega_minus * theta[j] / wvolume[j]))) * r0[i][jj]; if (r > 0.0) fbond = -((rk/r) * vfrac[j] * vfrac_scale); else fbond = 0.0; - //Plastic part + // Plastic part double deviatoric_extension = dr - (theta[i]* r0[i][jj] / 3.0); edpNp1 = deviatorPlasticextension[i][jj]; double tdtrialValue = ( 15 * shearmodulus[itype][itype]) * - ( (omega_plus / wvolume[i]) + (omega_minus / wvolume[j]) ) * + ((omega_plus / wvolume[i]) + (omega_minus / wvolume[j])) * (deviatoric_extension - edpNp1); if (elastic) { @@ -353,21 +309,17 @@ void PairPeriEPS::compute(int eflag, int vflag) deviatorPlasticExtTemp[i][jj] = edpNp1 + rkNew * deltalambda; } - if (r > 0.0) fbondElastoPlastic = -((rkNew/r) * vfrac[j] * vfrac_scale); else fbondElastoPlastic = 0.0; - // total Force state: elastic + plastic fbondFinal=fbond+fbondElastoPlastic; fbond=fbondFinal; - f[i][0] += delx*fbond; f[i][1] += dely*fbond; f[i][2] += delz*fbond; - // since I-J is double counted, set newton off & use 1/2 factor and I,I if (eflag) evdwl = (0.5 * 15 * shearmodulus[itype][itype]/wvolume[i] * @@ -379,7 +331,6 @@ void PairPeriEPS::compute(int eflag, int vflag) // find stretch in bond I-J and break if necessary // use s0 from previous timestep - stretch = dr / r0[i][jj]; if (stretch > MIN(s0[i],s0[j])) partner[i][jj] = 0; @@ -388,9 +339,7 @@ void PairPeriEPS::compute(int eflag, int vflag) if (first) s0_new[i] = s00[itype][jtype] - (alpha[itype][jtype] * stretch); else - s0_new[i] = MAX(s0_new[i],s00[itype][jtype] - - (alpha[itype][jtype] * stretch)); - + s0_new[i] = MAX(s0_new[i],s00[itype][jtype] - (alpha[itype][jtype] * stretch)); first = false; } } @@ -400,45 +349,12 @@ void PairPeriEPS::compute(int eflag, int vflag) memcpy(s0,s0_new,sizeof(double)*nlocal); if (nlocal*maxpartner > 0) { - memcpy(&(deviatorPlasticextension[0][0]), - &(deviatorPlasticExtTemp[0][0]), + memcpy(&(deviatorPlasticextension[0][0]),&(deviatorPlasticExtTemp[0][0]), sizeof(double)*nlocal*maxpartner); memory->destroy(deviatorPlasticExtTemp); } } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriEPS::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); - memory->create(m_yieldstress,n+1,n+1,"pair:m_yieldstress"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriEPS::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -493,40 +409,6 @@ double PairPeriEPS::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriEPS::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice == nullptr) - error->all(FLERR,"Pair peri requires a lattice be defined"); - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -581,120 +463,6 @@ void PairPeriEPS::read_restart(FILE *fp) } } -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriEPS::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriEPS::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriEPS::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // skip if particle is "lost" - if (j < 0) continue; - - // compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - /* ---------------------------------------------------------------------- */ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) @@ -714,12 +482,11 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) double lc = domain->lattice->xlattice; double half_lc = 0.5*lc; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - double **deviatorPlasticextension = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorPlasticextension; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; + double **deviatorPlasticextension = fix_peri_neigh->deviatorPlasticextension; int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; @@ -753,7 +520,7 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) if (periodic) domain->minimum_image(delx0,dely0,delz0); r = sqrt(rsq); dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon double vfrac_scale; @@ -785,34 +552,3 @@ double PairPeriEPS::compute_DeviatoricForceStateNorm(int i) } return sqrt(norm); } - - -/* ---------------------------------------------------------------------- - communication routines ----------------------------------------------------------------------- */ - -int PairPeriEPS::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriEPS::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_eps.h b/src/PERI/pair_peri_eps.h index 82d4c91ddb..5d9a437ac8 100644 --- a/src/PERI/pair_peri_eps.h +++ b/src/PERI/pair_peri_eps.h @@ -20,45 +20,23 @@ PairStyle(peri/eps,PairPeriEPS); #ifndef LMP_PAIR_PERI_EPS_H #define LMP_PAIR_PERI_EPS_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriEPS : public Pair { +class PairPeriEPS : public PairPeri { public: - double *theta; - double *elastic_energy; - PairPeriEPS(class LAMMPS *); - virtual ~PairPeriEPS(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriEPS() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); double compute_DeviatoricForceStateNorm(int); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut, **m_yieldstress; //NEW: **m_yieldstress - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -104,9 +82,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PERI/pair_peri_lps.cpp b/src/PERI/pair_peri_lps.cpp index 5b725306b0..f7c024983b 100644 --- a/src/PERI/pair_peri_lps.cpp +++ b/src/PERI/pair_peri_lps.cpp @@ -37,23 +37,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriLPS::PairPeriLPS(LAMMPS *lmp) : Pair(lmp) +PairPeriLPS::PairPeriLPS(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -62,25 +47,6 @@ PairPeriLPS::PairPeriLPS(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriLPS::~PairPeriLPS() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriLPS::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -101,10 +67,10 @@ void PairPeriLPS::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -205,13 +171,13 @@ void PairPeriLPS::compute(int eflag, int vflag) } // Compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); // communicate wighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // Volume-dependent part of the energy if (eflag) { @@ -272,7 +238,7 @@ void PairPeriLPS::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -335,37 +301,6 @@ void PairPeriLPS::compute(int eflag, int vflag) } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriLPS::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriLPS::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -418,38 +353,6 @@ double PairPeriLPS::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriLPS::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -500,148 +403,3 @@ void PairPeriLPS::read_restart(FILE *fp) } } } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriLPS::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriLPS::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function of pair peri/lps"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriLPS::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - if (partner[i][jj] == 0) continue; - - // Look up local index of this partner particle - j = atom->map(partner[i][jj]); - - // Skip if particle is "lost" - if (j < 0) continue; - - // Compute force density and add to PD equation of motion - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - - -/* ---------------------------------------------------------------------- - communication routines - ---------------------------------------------------------------------- */ - -int PairPeriLPS::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriLPS::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_lps.h b/src/PERI/pair_peri_lps.h index fb4647eb2f..0d9132f612 100644 --- a/src/PERI/pair_peri_lps.h +++ b/src/PERI/pair_peri_lps.h @@ -20,44 +20,22 @@ PairStyle(peri/lps,PairPeriLPS); #ifndef LMP_PAIR_PERI_LPS_H #define LMP_PAIR_PERI_LPS_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriLPS : public Pair { - public: - double *theta; - double *elastic_energy; - +class PairPeriLPS : public PairPeri { +public: PairPeriLPS(class LAMMPS *); - virtual ~PairPeriLPS(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriLPS() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -99,9 +77,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function of pair peri/lps - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PERI/pair_peri_pmb.cpp b/src/PERI/pair_peri_pmb.cpp index fa96ef0f26..0f88f0d80a 100644 --- a/src/PERI/pair_peri_pmb.cpp +++ b/src/PERI/pair_peri_pmb.cpp @@ -37,37 +37,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriPMB::PairPeriPMB(LAMMPS *lmp) : Pair(lmp) +PairPeriPMB::PairPeriPMB(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute=1; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - - kspring = nullptr; - s00 = nullptr; - alpha = nullptr; - cut = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairPeriPMB::~PairPeriPMB() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(kspring); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(s0_new); - } + single_enable = 1; } /* ---------------------------------------------------------------------- */ @@ -92,9 +64,9 @@ void PairPeriPMB::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -227,7 +199,7 @@ void PairPeriPMB::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -269,36 +241,6 @@ void PairPeriPMB::compute(int eflag, int vflag) for (i = 0; i < nlocal; i++) s0[i] = s0_new[i]; } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriPMB::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(kspring,n+1,n+1,"pair:kspring"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriPMB::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -348,38 +290,6 @@ double PairPeriPMB::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriPMB::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -439,9 +349,9 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, double *vfrac = atom->vfrac; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; + double **r0 = fix_peri_neigh->r0; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; double lc = domain->lattice->xlattice; double half_lc = 0.5*lc; @@ -473,7 +383,7 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, if (j < 0) continue; if (j == atom->map(partner[i][jj])) { dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; if ( (fabs(r0[i][jj] - sqrt(cutsq[itype][jtype]))) <= half_lc) vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + (1.0 + ((sqrt(cutsq[itype][jtype]) - half_lc)/(2*half_lc))); @@ -487,13 +397,3 @@ double PairPeriPMB::single(int i, int j, int itype, int jtype, double rsq, return energy; } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriPMB::memory_usage() -{ - double bytes = (double)nmax * sizeof(double); - return bytes; -} diff --git a/src/PERI/pair_peri_pmb.h b/src/PERI/pair_peri_pmb.h index cd65052dec..44a46093de 100644 --- a/src/PERI/pair_peri_pmb.h +++ b/src/PERI/pair_peri_pmb.h @@ -20,36 +20,25 @@ PairStyle(peri/pmb,PairPeriPMB); #ifndef LMP_PAIR_PERI_PMB_H #define LMP_PAIR_PERI_PMB_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriPMB : public Pair { +class PairPeriPMB : public PairPeri { public: PairPeriPMB(class LAMMPS *); - virtual ~PairPeriPMB(); + virtual ~PairPeriPMB() = default; + virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); + void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} + double single(int, int, int, int, double, double, double, double &); - virtual double memory_usage(); - - protected: - int ifix_peri; - double **kspring; - double **s00, **alpha; - double **cut; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS diff --git a/src/PERI/pair_peri_ves.cpp b/src/PERI/pair_peri_ves.cpp index ca8802396e..522d05e04f 100644 --- a/src/PERI/pair_peri_ves.cpp +++ b/src/PERI/pair_peri_ves.cpp @@ -37,25 +37,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairPeriVES::PairPeriVES(LAMMPS *lmp) : Pair(lmp) +PairPeriVES::PairPeriVES(LAMMPS *_lmp) : PairPeri(_lmp) { - for (int i = 0; i < 6; i++) virial[i] = 0.0; - no_virial_fdotr_compute = 1; - single_enable = 0; - - ifix_peri = -1; - - nmax = 0; - s0_new = nullptr; - theta = nullptr; - - bulkmodulus = nullptr; - shearmodulus = nullptr; - s00 = alpha = nullptr; - cut = nullptr; - m_lambdai = nullptr; - m_taubi = nullptr; - // set comm size needed by this Pair // comm_reverse not needed @@ -64,27 +47,6 @@ PairPeriVES::PairPeriVES(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairPeriVES::~PairPeriVES() -{ - if (ifix_peri >= 0) modify->delete_fix("PERI_NEIGH"); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - memory->destroy(bulkmodulus); - memory->destroy(shearmodulus); - memory->destroy(s00); - memory->destroy(alpha); - memory->destroy(cut); - memory->destroy(m_lambdai); - memory->destroy(m_taubi); - memory->destroy(theta); - memory->destroy(s0_new); - } -} - -/* ---------------------------------------------------------------------- */ - void PairPeriVES::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; @@ -108,14 +70,12 @@ void PairPeriVES::compute(int eflag, int vflag) double *vfrac = atom->vfrac; double *s0 = atom->s0; double **x0 = atom->x0; - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - double **deviatorextention = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorextention; - double **deviatorBackextention = - ((FixPeriNeigh *) modify->fix[ifix_peri])->deviatorBackextention; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; + double **r0 = fix_peri_neigh->r0; + double **deviatorextention = fix_peri_neigh->deviatorextention; + double **deviatorBackextention = fix_peri_neigh->deviatorBackextention; + tagint **partner = fix_peri_neigh->partner; + int *npartner = fix_peri_neigh->npartner; + double *wvolume = fix_peri_neigh->wvolume; // lc = lattice constant // init_style guarantees it's the same in x, y, and z @@ -216,7 +176,7 @@ void PairPeriVES::compute(int eflag, int vflag) } // Compute the dilatation on each particle - compute_dilatation(); + compute_dilatation(0,nlocal); // communicate dilatation (theta) of each particle comm->forward_comm_pair(this); @@ -224,7 +184,7 @@ void PairPeriVES::compute(int eflag, int vflag) // communicate weighted volume (wvolume) upon every reneighbor if (neighbor->ago == 0) - comm->forward_comm_fix(modify->fix[ifix_peri]); + comm->forward_comm_fix(fix_peri_neigh); // volume-dependent part of the energy @@ -286,7 +246,7 @@ void PairPeriVES::compute(int eflag, int vflag) // avoid roundoff errors - if (fabs(dr) < 2.2204e-016) dr = 0.0; + if (fabs(dr) < NEAR_ZERO) dr = 0.0; // scale vfrac[j] if particle j near the horizon @@ -381,39 +341,6 @@ void PairPeriVES::compute(int eflag, int vflag) for (i = 0; i < nlocal; i++) s0[i] = s0_new[i]; } -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairPeriVES::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(bulkmodulus,n+1,n+1,"pair:bulkmodulus"); - memory->create(shearmodulus,n+1,n+1,"pair:shearmodulus"); - memory->create(s00,n+1,n+1,"pair:s00"); - memory->create(alpha,n+1,n+1,"pair:alpha"); - memory->create(cut,n+1,n+1,"pair:cut"); - memory->create(m_lambdai,n+1,n+1,"pair:m_lambdai"); - memory->create(m_taubi,n+1,n+1,"pair:m_taubi"); -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairPeriVES::settings(int narg, char **/*arg*/) -{ - if (narg) error->all(FLERR,"Illegal pair_style command"); -} - /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ @@ -472,40 +399,6 @@ double PairPeriVES::init_one(int i, int j) return cut[i][j]; } -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairPeriVES::init_style() -{ - // error checks - - if (!atom->peri_flag) - error->all(FLERR,"Pair style peri requires atom style peri"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair peri requires an atom map, see atom_modify"); - - if (domain->lattice == nullptr) - error->all(FLERR,"Pair peri requires a lattice be defined"); - if (domain->lattice->xlattice != domain->lattice->ylattice || - domain->lattice->xlattice != domain->lattice->zlattice || - domain->lattice->ylattice != domain->lattice->zlattice) - error->all(FLERR,"Pair peri lattice is not identical in x, y, and z"); - - // if first init, create Fix needed for storing fixed neighbors - - if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); - - // find associated PERI_NEIGH fix that must exist - // could have changed locations in fix list since created - - ifix_peri = modify->find_fix_by_style("^PERI_NEIGH"); - if (ifix_peri == -1) - error->all(FLERR,"Fix peri neigh does not exist"); - - neighbor->request(this,instance_me); -} - /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ @@ -562,153 +455,3 @@ void PairPeriVES::read_restart(FILE *fp) } } } - -/* ---------------------------------------------------------------------- - memory usage of local atom-based arrays -------------------------------------------------------------------------- */ - -double PairPeriVES::memory_usage() -{ - double bytes = 2 * nmax * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - influence function definition -------------------------------------------------------------------------- */ - -double PairPeriVES::influence_function(double xi_x, double xi_y, double xi_z) -{ - double r = sqrt(xi_x*xi_x + xi_y*xi_y + xi_z*xi_z); - double omega; - - if (fabs(r) < 2.2204e-016) - error->one(FLERR,"Divide by 0 in influence function of pair peri/lps"); - omega = 1.0/r; - return omega; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriVES::compute_dilatation() -{ - int i,j,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz; - double xtmp0,ytmp0,ztmp0,delx0,dely0,delz0; - double rsq,r,dr; - double delta; - - double **x = atom->x; - int *type = atom->type; - double **x0 = atom->x0; - int nlocal = atom->nlocal; - double *vfrac = atom->vfrac; - double vfrac_scale = 1.0; - - double lc = domain->lattice->xlattice; - double half_lc = 0.5*lc; - - - double **r0 = ((FixPeriNeigh *) modify->fix[ifix_peri])->r0; - tagint **partner = ((FixPeriNeigh *) modify->fix[ifix_peri])->partner; - int *npartner = ((FixPeriNeigh *) modify->fix[ifix_peri])->npartner; - double *wvolume = ((FixPeriNeigh *) modify->fix[ifix_peri])->wvolume; - - int periodic = domain->xperiodic || domain->yperiodic || domain->zperiodic; - - // compute the dilatation theta - - for (i = 0; i < nlocal; i++) { - xtmp = x[i][0]; - ytmp = x[i][1]; - ztmp = x[i][2]; - xtmp0 = x0[i][0]; - ytmp0 = x0[i][1]; - ztmp0 = x0[i][2]; - jnum = npartner[i]; - theta[i] = 0.0; - itype = type[i]; - - for (jj = 0; jj < jnum; jj++) { - - // if bond already broken, skip this partner - - if (partner[i][jj] == 0) continue; - - // look up local index of this partner particle - - j = atom->map(partner[i][jj]); - - // skip if particle is "lost" - - if (j < 0) continue; - - // compute force density and add to PD equation of motion - - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - if (periodic) domain->minimum_image(delx,dely,delz); - rsq = delx*delx + dely*dely + delz*delz; - delx0 = xtmp0 - x0[j][0]; - dely0 = ytmp0 - x0[j][1]; - delz0 = ztmp0 - x0[j][2]; - if (periodic) domain->minimum_image(delx0,dely0,delz0); - - r = sqrt(rsq); - dr = r - r0[i][jj]; - if (fabs(dr) < 2.2204e-016) dr = 0.0; - - jtype = type[j]; - delta = cut[itype][jtype]; - - // scale vfrac[j] if particle j near the horizon - - if ((fabs(r0[i][jj] - delta)) <= half_lc) - vfrac_scale = (-1.0/(2*half_lc))*(r0[i][jj]) + - (1.0 + ((delta - half_lc)/(2*half_lc) ) ); - else vfrac_scale = 1.0; - - theta[i] += influence_function(delx0, dely0, delz0) * r0[i][jj] * dr * - vfrac[j] * vfrac_scale; - - } - - // if wvolume[i] is zero, then particle i has no bonds - // therefore, the dilatation is set to - - if (wvolume[i] != 0.0) theta[i] = (3.0/wvolume[i]) * theta[i]; - else theta[i] = 0; - } -} - - -/* ---------------------------------------------------------------------- - communication routines ----------------------------------------------------------------------- */ - -int PairPeriVES::pack_forward_comm(int n, int *list, double *buf, - int /*pbc_flag*/, int * /*pbc*/) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = theta[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void PairPeriVES::unpack_forward_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - theta[i] = buf[m++]; - } -} diff --git a/src/PERI/pair_peri_ves.h b/src/PERI/pair_peri_ves.h index 03659ae65d..e80c5e3383 100644 --- a/src/PERI/pair_peri_ves.h +++ b/src/PERI/pair_peri_ves.h @@ -20,46 +20,22 @@ PairStyle(peri/ves,PairPeriVES); #ifndef LMP_PAIR_PERI_VES_H #define LMP_PAIR_PERI_VES_H -#include "pair.h" +#include "pair_peri.h" namespace LAMMPS_NS { -class PairPeriVES : public Pair { +class PairPeriVES : public PairPeri { public: - double *theta; - double *elastic_energy; - PairPeriVES(class LAMMPS *); - virtual ~PairPeriVES(); - int pack_forward_comm(int, int *, double *, int, int *); - void unpack_forward_comm(int, int, double *); + virtual ~PairPeriVES() = default; virtual void compute(int, int); - void settings(int, char **); void coeff(int, char **); double init_one(int, int); - void init_style(); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *) {} void read_restart_settings(FILE *) {} - double memory_usage(); - double influence_function(double, double, double); - void compute_dilatation(); - - protected: - int ifix_peri; - double **bulkmodulus; - double **shearmodulus; - double **s00, **alpha; - double **cut; - double **m_lambdai; - double **m_taubi; - - double *s0_new; - int nmax; - - void allocate(); }; } // namespace LAMMPS_NS @@ -105,9 +81,4 @@ E: Fix peri neigh does not exist Somehow a fix that the pair style defines has been deleted. -E: Divide by 0 in influence function of pair peri/lps - -This should not normally occur. It is likely a problem with your -model. - */ diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 443fecc99f..33a252c39e 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -15,459 +14,429 @@ #include "plugin.h" #include "comm.h" +#include "compute.h" #include "domain.h" #include "error.h" -#include "input.h" +#include "fix.h" #include "force.h" +#include "input.h" #include "modify.h" +#include "region.h" #include -#include #include +#include -namespace LAMMPS_NS +namespace LAMMPS_NS { +// list of plugin information data for loaded styles +static std::list pluginlist; + +// map for counting references to dso handles +static std::map dso_refcounter; + +/* ---------------------------------------------------------------------- */ + +Plugin::Plugin(LAMMPS *lmp) : Command(lmp) {} + +/* ---------------------------------------------------------------------- */ + +void Plugin::command(int narg, char **arg) { - // list of plugin information data for loaded styles - static std::list pluginlist; + if (narg < 1) error->all(FLERR, "Illegal plugin command"); - // map for counting references to dso handles - static std::map dso_refcounter; + std::string cmd = arg[0]; + if (cmd == "load") { + if (narg < 2) error->all(FLERR, "Illegal plugin load command"); + for (int i = 1; i < narg; ++i) plugin_load(arg[i], lmp); + } else if (cmd == "unload") { + if (narg != 3) error->all(FLERR, "Illegal plugin unload command"); + plugin_unload(arg[1], arg[2], lmp); -/* ---------------------------------------------------------------------- */ + } else if (cmd == "clear") { + plugin_clear(lmp); - Plugin::Plugin(LAMMPS *lmp) : Command(lmp) {} - -/* ---------------------------------------------------------------------- */ - - void Plugin::command(int narg, char **arg) - { - if (narg < 1) error->all(FLERR,"Illegal plugin command"); - -#if defined(LMP_PLUGIN) - std::string cmd = arg[0]; - if (cmd == "load") { - if (narg < 2) error->all(FLERR,"Illegal plugin load command"); - for (int i=1; i < narg; ++i) - plugin_load(arg[i],lmp); - - } else if (cmd == "unload") { - if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); - plugin_unload(arg[1],arg[2],lmp); - - } else if (cmd == "clear") { - plugin_clear(lmp); - - } else if (cmd == "list") { - if (comm->me == 0) { - int num = plugin_get_num_plugins(); - utils::logmesg(lmp,"Currently loaded plugins\n"); - for (int i=0; i < num; ++i) { - auto entry = plugin_get_info(i); - utils::logmesg(lmp,"{:4}: {} style plugin {}\n", - i+1,entry->style,entry->name); - } + } else if (cmd == "list") { + if (comm->me == 0) { + int num = plugin_get_num_plugins(); + utils::logmesg(lmp, "Currently loaded plugins\n"); + for (int i = 0; i < num; ++i) { + auto entry = plugin_get_info(i); + utils::logmesg(lmp, "{:4}: {} style plugin {}\n", i + 1, entry->style, entry->name); } - } else error->all(FLERR,"Illegal plugin command"); -#else - if (comm->me == 0) - error->warning(FLERR,"Ignoring plugin command. LAMMPS must be built as " - "a shared library for it to work."); + } + } else + error->all(FLERR, "Illegal plugin command"); +#if 0 + if (comm->me == 0) + error->warning( + FLERR, "LAMMPS must be built as a shared library for it to work."); #endif - } +} - // load DSO and call included registration function - void plugin_load(const char *file, LAMMPS *lmp) - { +// load DSO and call included registration function +void plugin_load(const char *file, LAMMPS *lmp) +{ #if defined(LMP_PLUGIN) - int me = lmp->comm->me; + int me = lmp->comm->me; - // open DSO file from given path; load symbols globally + // open DSO file from given path; load symbols globally - platform::dlerror(); - void *dso = platform::dlopen(file); - if (dso == nullptr) { - if (me == 0) - utils::logmesg(lmp,"Open of file {} failed: {}\n",file,platform::dlerror()); - return; - } - - // look up lammpsplugin_init() function in DSO - // function must have C bindings so there is no name mangling - - platform::dlerror(); - void *initfunc = platform::dlsym(dso,"lammpsplugin_init"); - if (initfunc == nullptr) { - platform::dlclose(dso); - - if (me == 0) - utils::logmesg(lmp,"Plugin symbol lookup failure in file {}: {}\n", - file,platform::dlerror()); - return; - } - - // call initializer function loaded from DSO and pass a pointer - // to the LAMMPS instance, the DSO handle (for reference counting) - // and plugin registration function pointer - - (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, - (void *)&plugin_register); -#endif + platform::dlerror(); + void *dso = platform::dlopen(file); + if (dso == nullptr) { + if (me == 0) utils::logmesg(lmp, "Open of file {} failed: {}\n", file, platform::dlerror()); + return; } - /* -------------------------------------------------------------------- + // look up lammpsplugin_init() function in DSO + // function must have C bindings so there is no name mangling + + platform::dlerror(); + void *initfunc = platform::dlsym(dso, "lammpsplugin_init"); + if (initfunc == nullptr) { + platform::dlclose(dso); + + if (me == 0) + utils::logmesg(lmp, "Plugin symbol lookup failure in file {}: {}\n", file, + platform::dlerror()); + return; + } + + // call initializer function loaded from DSO and pass a pointer + // to the LAMMPS instance, the DSO handle (for reference counting) + // and plugin registration function pointer + + (*(lammpsplugin_initfunc) (initfunc))((void *) lmp, dso, (void *) &plugin_register); +#endif +} + +/* -------------------------------------------------------------------- register a new style from a plugin with LAMMPS this is the callback function that is called from within the plugin initializer function. all plugin information is taken from the lammpsplugin_t struct. -------------------------------------------------------------------- */ - void plugin_register(lammpsplugin_t *plugin, void *ptr) - { +void plugin_register(lammpsplugin_t *plugin, void *ptr) +{ #if defined(LMP_PLUGIN) - LAMMPS *lmp = (LAMMPS *)ptr; - int me = lmp->comm->me; + LAMMPS *lmp = (LAMMPS *) ptr; + int me = lmp->comm->me; - if (plugin == nullptr) return; + if (plugin == nullptr) return; - // ignore load request if same plugin already loaded - int idx = plugin_find(plugin->style,plugin->name); - if (idx >= 0) { - if (me == 0) - utils::logmesg(lmp,"Ignoring load of {} style {}: must " - "unload existing {} plugin first\n", - plugin->style,plugin->name,plugin->name); - return; - } - - if (me == 0) { - utils::logmesg(lmp,"Loading plugin: {} by {}\n", - plugin->info,plugin->author); - // print version info only if the versions of host and plugin don't match - if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) - utils::logmesg(lmp," compiled for LAMMPS version {}, loaded into " - "LAMMPS version {}\n",plugin->version,lmp->version); - } - - pluginlist.push_back(*plugin); - - if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { - ++ dso_refcounter[plugin->handle]; - } else { - dso_refcounter[plugin->handle] = 1; - } - - std::string pstyle = plugin->style; - if (pstyle == "pair") { - auto pair_map = lmp->force->pair_map; - if (pair_map->find(plugin->name) != pair_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in pair " - "style {} from plugin",plugin->name); - } - (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator.v1; - - } else if (pstyle == "bond") { - auto bond_map = lmp->force->bond_map; - if (bond_map->find(plugin->name) != bond_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in bond " - "style {} from plugin",plugin->name); - } - (*bond_map)[plugin->name] = (Force::BondCreator)plugin->creator.v1; - - } else if (pstyle == "angle") { - auto angle_map = lmp->force->angle_map; - if (angle_map->find(plugin->name) != angle_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in angle " - "style {} from plugin",plugin->name); - } - (*angle_map)[plugin->name] = (Force::AngleCreator)plugin->creator.v1; - - } else if (pstyle == "dihedral") { - auto dihedral_map = lmp->force->dihedral_map; - if (dihedral_map->find(plugin->name) != dihedral_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in dihedral " - "style {} from plugin",plugin->name); - } - (*dihedral_map)[plugin->name] = (Force::DihedralCreator)plugin->creator.v1; - - } else if (pstyle == "improper") { - auto improper_map = lmp->force->improper_map; - if (improper_map->find(plugin->name) != improper_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in improper " - "style {} from plugin",plugin->name); - } - (*improper_map)[plugin->name] = (Force::ImproperCreator)plugin->creator.v1; - - } else if (pstyle == "compute") { - auto compute_map = lmp->modify->compute_map; - if (compute_map->find(plugin->name) != compute_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in compute " - "style {} from plugin",plugin->name); - } - (*compute_map)[plugin->name] = (Modify::ComputeCreator)plugin->creator.v2; - - } else if (pstyle == "fix") { - auto fix_map = lmp->modify->fix_map; - if (fix_map->find(plugin->name) != fix_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in fix " - "style {} from plugin",plugin->name); - } - (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2; - - } else if (pstyle == "region") { - auto region_map = lmp->domain->region_map; - if (region_map->find(plugin->name) != region_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in region " - "style {} from plugin",plugin->name); - } - (*region_map)[plugin->name] = (Domain::RegionCreator)plugin->creator.v2; - - } else if (pstyle == "command") { - auto command_map = lmp->input->command_map; - if (command_map->find(plugin->name) != command_map->end()) { - if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"Overriding built-in command " - "style {} from plugin",plugin->name); - } - (*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator.v1; - - } else { - utils::logmesg(lmp,"Loading plugins for {} styles not " - "yet implemented\n",pstyle); - pluginlist.pop_back(); - } -#endif + // ignore load request if same plugin already loaded + int idx = plugin_find(plugin->style, plugin->name); + if (idx >= 0) { + if (me == 0) + utils::logmesg(lmp, "Ignoring load of {} style {}: must unload existing {} plugin first\n", + plugin->style, plugin->name, plugin->name); + return; } - /* -------------------------------------------------------------------- + if (me == 0) { + utils::logmesg(lmp, "Loading plugin: {} by {}\n", plugin->info, plugin->author); + // print version info only if the versions of host and plugin don't match + if ((plugin->version) && (strcmp(plugin->version, lmp->version) != 0)) + utils::logmesg(lmp, " compiled for LAMMPS version {}, loaded into LAMMPS version {}\n", + plugin->version, lmp->version); + } + + pluginlist.push_back(*plugin); + + if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { + ++dso_refcounter[plugin->handle]; + } else { + dso_refcounter[plugin->handle] = 1; + } + + std::string pstyle = plugin->style; + if (pstyle == "pair") { + auto pair_map = lmp->force->pair_map; + if (pair_map->find(plugin->name) != pair_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in pair style {} from plugin", plugin->name); + } + (*pair_map)[plugin->name] = (Force::PairCreator) plugin->creator.v1; + + } else if (pstyle == "bond") { + auto bond_map = lmp->force->bond_map; + if (bond_map->find(plugin->name) != bond_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in bond style {} from plugin", plugin->name); + } + (*bond_map)[plugin->name] = (Force::BondCreator) plugin->creator.v1; + + } else if (pstyle == "angle") { + auto angle_map = lmp->force->angle_map; + if (angle_map->find(plugin->name) != angle_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in angle style {} from plugin", plugin->name); + } + (*angle_map)[plugin->name] = (Force::AngleCreator) plugin->creator.v1; + + } else if (pstyle == "dihedral") { + auto dihedral_map = lmp->force->dihedral_map; + if (dihedral_map->find(plugin->name) != dihedral_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in dihedral style {} from plugin", + plugin->name); + } + (*dihedral_map)[plugin->name] = (Force::DihedralCreator) plugin->creator.v1; + + } else if (pstyle == "improper") { + auto improper_map = lmp->force->improper_map; + if (improper_map->find(plugin->name) != improper_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in improper style {} from plugin", + plugin->name); + } + (*improper_map)[plugin->name] = (Force::ImproperCreator) plugin->creator.v1; + + } else if (pstyle == "compute") { + auto compute_map = lmp->modify->compute_map; + if (compute_map->find(plugin->name) != compute_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in compute style {} from plugin", + plugin->name); + } + (*compute_map)[plugin->name] = (Modify::ComputeCreator) plugin->creator.v2; + + } else if (pstyle == "fix") { + auto fix_map = lmp->modify->fix_map; + if (fix_map->find(plugin->name) != fix_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in fix style {} from plugin", plugin->name); + } + (*fix_map)[plugin->name] = (Modify::FixCreator) plugin->creator.v2; + + } else if (pstyle == "region") { + auto region_map = lmp->domain->region_map; + if (region_map->find(plugin->name) != region_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in region style {} from plugin", plugin->name); + } + (*region_map)[plugin->name] = (Domain::RegionCreator) plugin->creator.v2; + + } else if (pstyle == "command") { + auto command_map = lmp->input->command_map; + if (command_map->find(plugin->name) != command_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR, "Overriding built-in command style {} from plugin", + plugin->name); + } + (*command_map)[plugin->name] = (Input::CommandCreator) plugin->creator.v1; + + } else { + utils::logmesg(lmp, "Loading plugins for {} styles not yet implemented\n", pstyle); + pluginlist.pop_back(); + } +#endif +} + +/* -------------------------------------------------------------------- remove plugin from given style table and plugin list optionally close the DSO handle if it is the last plugin from that DSO must also delete style instances if style is currently active -------------------------------------------------------------------- */ - void plugin_unload(const char *style, const char *name, LAMMPS *lmp) - { +void plugin_unload(const char *style, const char *name, LAMMPS *lmp) +{ #if defined(LMP_PLUGIN) - int me = lmp->comm->me; - - // ignore unload request from unsupported style categories - if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0) - && (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0) - && (strcmp(style,"improper") != 0) && (strcmp(style,"compute") != 0) - && (strcmp(style,"fix") != 0) && (strcmp(style,"region") != 0) - && (strcmp(style,"command") != 0)) { - if (me == 0) - utils::logmesg(lmp,"Ignoring unload: {} is not a " - "supported plugin style\n",style); - return; - } - - // ignore unload request if not loaded from a plugin - int idx = plugin_find(style,name); - if (idx < 0) { - if (me == 0) - utils::logmesg(lmp,"Ignoring unload of {} style {}: not " - "loaded from a plugin\n",style,name); - return; - } - - // make copy of DSO handle for later use - void *handle = plugin_get_info(idx)->handle; - - // remove selected plugin from list of plugins + int me = lmp->comm->me; + // ignore unload request from unsupported style categories + if ((strcmp(style, "pair") != 0) && (strcmp(style, "bond") != 0) && + (strcmp(style, "angle") != 0) && (strcmp(style, "dihedral") != 0) && + (strcmp(style, "improper") != 0) && (strcmp(style, "compute") != 0) && + (strcmp(style, "fix") != 0) && (strcmp(style, "region") != 0) && + (strcmp(style, "command") != 0)) { if (me == 0) - utils::logmesg(lmp,"Unloading {} style {}\n",style,name); - plugin_erase(style,name); - - // remove style of given name from corresponding map - // must delete style instance if currently active so - // we can close the DSO handle if the last reference is gone. - - std::string pstyle = style; - if (pstyle == "pair") { - - auto found = lmp->force->pair_map->find(name); - if (found != lmp->force->pair_map->end()) - lmp->force->pair_map->erase(found); - - // must delete pair style instance if in use - - if (lmp->force->pair_style) { - if (utils::strmatch(lmp->force->pair_style,"^hybrid")) { - if (lmp->force->pair_match(name,1,1) != nullptr) - lmp->force->create_pair("none",0); - } else { - if (strcmp(lmp->force->pair_style,name) == 0) - lmp->force->create_pair("none",0); - } - } - - } else if (pstyle == "bond") { - - auto found = lmp->force->bond_map->find(name); - if (found != lmp->force->bond_map->end()) - lmp->force->bond_map->erase(found); - - // must delete bond style instance if in use - - if ((lmp->force->bond_style != nullptr) - && (lmp->force->bond_match(name) != nullptr)) - lmp->force->create_bond("none",0); - - } else if (pstyle == "angle") { - - auto found = lmp->force->angle_map->find(name); - if (found != lmp->force->angle_map->end()) - lmp->force->angle_map->erase(found); - - // must delete angle style instance if in use - - if ((lmp->force->angle_style != nullptr) - && (lmp->force->angle_match(name) != nullptr)) - lmp->force->create_angle("none",0); - - } else if (pstyle == "dihedral") { - - auto found = lmp->force->dihedral_map->find(name); - if (found != lmp->force->dihedral_map->end()) - lmp->force->dihedral_map->erase(found); - - // must delete dihedral style instance if in use - - if ((lmp->force->dihedral_style) - && (lmp->force->dihedral_match(name) != nullptr)) - lmp->force->create_dihedral("none",0); - - } else if (pstyle == "improper") { - - auto found = lmp->force->improper_map->find(name); - if (found != lmp->force->improper_map->end()) - lmp->force->improper_map->erase(found); - - // must delete improper style instance if in use - - if ((lmp->force->improper_style != nullptr) - && (lmp->force->improper_match(name) != nullptr)) - lmp->force->create_improper("none",0); - - } else if (pstyle == "compute") { - - auto compute_map = lmp->modify->compute_map; - auto found = compute_map->find(name); - if (found != compute_map->end()) compute_map->erase(name); - - for (int icompute = lmp->modify->find_compute_by_style(name); - icompute >= 0; icompute = lmp->modify->find_compute_by_style(name)) - lmp->modify->delete_compute(icompute); - - } else if (pstyle == "fix") { - - auto fix_map = lmp->modify->fix_map; - auto found = fix_map->find(name); - if (found != fix_map->end()) fix_map->erase(name); - - for (int ifix = lmp->modify->find_fix_by_style(name); - ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) - lmp->modify->delete_fix(ifix); - - } else if (pstyle == "region") { - - auto region_map = lmp->domain->region_map; - auto found = region_map->find(name); - if (found != region_map->end()) region_map->erase(name); - - for (int iregion = lmp->domain->find_region_by_style(name); - iregion >= 0; iregion = lmp->domain->find_region_by_style(name)) - lmp->domain->delete_region(iregion); - - } else if (pstyle == "command") { - - auto command_map = lmp->input->command_map; - auto found = command_map->find(name); - if (found != command_map->end()) command_map->erase(name); - } - - // if reference count is down to zero, close DSO handle. - - -- dso_refcounter[handle]; - if (dso_refcounter[handle] == 0) { - platform::dlclose(handle); - } -#endif + utils::logmesg(lmp, "Ignoring unload: {} is not a supported plugin style\n", style); + return; } - /* -------------------------------------------------------------------- + // ignore unload request if not loaded from a plugin + int idx = plugin_find(style, name); + if (idx < 0) { + if (me == 0) + utils::logmesg(lmp, "Ignoring unload of {} style {}: not from a plugin\n", style, name); + return; + } + + // make copy of DSO handle for later use + void *handle = plugin_get_info(idx)->handle; + + // remove selected plugin from list of plugins + + if (me == 0) utils::logmesg(lmp, "Unloading {} style {}\n", style, name); + plugin_erase(style, name); + + // remove style of given name from corresponding map + // must delete style instance if currently active so + // we can close the DSO handle if the last reference is gone. + + std::string pstyle = style; + if (pstyle == "pair") { + + auto found = lmp->force->pair_map->find(name); + if (found != lmp->force->pair_map->end()) lmp->force->pair_map->erase(found); + + // must delete pair style instance if in use + + if (lmp->force->pair_style) { + if (utils::strmatch(lmp->force->pair_style, "^hybrid")) { + if (lmp->force->pair_match(name, 1, 1) != nullptr) lmp->force->create_pair("none", 0); + } else { + if (strcmp(lmp->force->pair_style, name) == 0) lmp->force->create_pair("none", 0); + } + } + + } else if (pstyle == "bond") { + + auto found = lmp->force->bond_map->find(name); + if (found != lmp->force->bond_map->end()) lmp->force->bond_map->erase(found); + + // must delete bond style instance if in use + + if ((lmp->force->bond_style != nullptr) && (lmp->force->bond_match(name) != nullptr)) + lmp->force->create_bond("none", 0); + + } else if (pstyle == "angle") { + + auto found = lmp->force->angle_map->find(name); + if (found != lmp->force->angle_map->end()) lmp->force->angle_map->erase(found); + + // must delete angle style instance if in use + + if ((lmp->force->angle_style != nullptr) && (lmp->force->angle_match(name) != nullptr)) + lmp->force->create_angle("none", 0); + + } else if (pstyle == "dihedral") { + + auto found = lmp->force->dihedral_map->find(name); + if (found != lmp->force->dihedral_map->end()) lmp->force->dihedral_map->erase(found); + + // must delete dihedral style instance if in use + + if ((lmp->force->dihedral_style) && (lmp->force->dihedral_match(name) != nullptr)) + lmp->force->create_dihedral("none", 0); + + } else if (pstyle == "improper") { + + auto found = lmp->force->improper_map->find(name); + if (found != lmp->force->improper_map->end()) lmp->force->improper_map->erase(found); + + // must delete improper style instance if in use + + if ((lmp->force->improper_style != nullptr) && (lmp->force->improper_match(name) != nullptr)) + lmp->force->create_improper("none", 0); + + } else if (pstyle == "compute") { + + auto compute_map = lmp->modify->compute_map; + auto found = compute_map->find(name); + if (found != compute_map->end()) compute_map->erase(name); + + // must delete all compute instances using this compute style + + for (auto icompute : lmp->modify->get_compute_by_style(name)) + lmp->modify->delete_compute(icompute->id); + + } else if (pstyle == "fix") { + + auto fix_map = lmp->modify->fix_map; + auto found = fix_map->find(name); + if (found != fix_map->end()) fix_map->erase(name); + + // must delete all fix instances using this fix style + + for (auto ifix : lmp->modify->get_fix_by_style(name)) lmp->modify->delete_fix(ifix->id); + + } else if (pstyle == "region") { + + auto region_map = lmp->domain->region_map; + auto found = region_map->find(name); + if (found != region_map->end()) region_map->erase(name); + + for (auto iregion : lmp->domain->get_region_by_style(name)) + lmp->domain->delete_region(iregion->id); + + } else if (pstyle == "command") { + + auto command_map = lmp->input->command_map; + auto found = command_map->find(name); + if (found != command_map->end()) command_map->erase(name); + } + + // if reference count is down to zero, close DSO handle. + + --dso_refcounter[handle]; + if (dso_refcounter[handle] == 0) { platform::dlclose(handle); } +#endif +} + +/* -------------------------------------------------------------------- unload all loaded plugins -------------------------------------------------------------------- */ - void plugin_clear(LAMMPS *lmp) - { - while (pluginlist.size() > 0) { - auto p = pluginlist.begin(); - plugin_unload(p->style,p->name,lmp); - } +void plugin_clear(LAMMPS *lmp) +{ + while (pluginlist.size() > 0) { + auto p = pluginlist.begin(); + plugin_unload(p->style, p->name, lmp); } +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- remove plugin of given name and style from internal lists -------------------------------------------------------------------- */ - void plugin_erase(const char *style, const char *name) - { - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if ((strcmp(style,p->style) == 0) - && (strcmp(name,p->name) == 0)) { - pluginlist.erase(p); - return; - } +void plugin_erase(const char *style, const char *name) +{ + for (auto p = pluginlist.begin(); p != pluginlist.end(); ++p) { + if ((strcmp(style, p->style) == 0) && (strcmp(name, p->name) == 0)) { + pluginlist.erase(p); + return; } } +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- number of styles loaded from plugin files -------------------------------------------------------------------- */ - int plugin_get_num_plugins() - { - return pluginlist.size(); - } +int plugin_get_num_plugins() +{ + return pluginlist.size(); +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- return position index in list of given plugin of given style -------------------------------------------------------------------- */ - int plugin_find(const char *style, const char *name) - { - int i=0; - for (auto entry : pluginlist) { - if ((strcmp(style,entry.style) == 0) - && (strcmp(name,entry.name) == 0)) - return i; - ++i; - } - return -1; +int plugin_find(const char *style, const char *name) +{ + int i = 0; + for (auto entry : pluginlist) { + if ((strcmp(style, entry.style) == 0) && (strcmp(name, entry.name) == 0)) return i; + ++i; } + return -1; +} - /* -------------------------------------------------------------------- +/* -------------------------------------------------------------------- get pointer to plugin initializer struct at position idx -------------------------------------------------------------------- */ - const lammpsplugin_t *plugin_get_info(int idx) - { - int i=0; - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if (i == idx) return &(*p); - ++i; - } - return nullptr; +const lammpsplugin_t *plugin_get_info(int idx) +{ + int i = 0; + for (const auto &p : pluginlist) { + if (i == idx) return &p; + ++i; } + return nullptr; } +} // namespace LAMMPS_NS diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index fdd8ef7a18..201e40b5b8 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -954,7 +954,7 @@ void FixPOEMS::readfile(char *file) int nlocal = atom->nlocal; int i,id,nlen; - while (1) { + while (true) { if (me == 0) nlen = readline(fp,&line,&maxline); MPI_Bcast(&nlen,1,MPI_INT,0,world); if (nlen == 0) break; @@ -986,7 +986,7 @@ int FixPOEMS::readline(FILE *fp, char **pline, int *pmaxline) char *line = *pline; int maxline = *pmaxline; - while (1) { + while (true) { if (n+1 >= maxline) { maxline += DELTA; memory->grow(line,maxline,"fix_poems:line"); @@ -1246,7 +1246,7 @@ int FixPOEMS::loopcheck(int nvert, int nedge, tagint **elist) int *stack = new int[nvert]; ncluster = 0; - while (1) { + while (true) { for (i = 0; i < nvert; i++) if (mark[i] == 0) break; if (i == nvert) break; diff --git a/src/PTM/ptm_convex_hull_incremental.cpp b/src/PTM/ptm_convex_hull_incremental.cpp index 580d88c578..25ff54c787 100644 --- a/src/PTM/ptm_convex_hull_incremental.cpp +++ b/src/PTM/ptm_convex_hull_incremental.cpp @@ -1,4 +1,3 @@ -// clang-format off /*Copyright (c) 2016 PM Larsen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -8,13 +7,14 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include #include "ptm_convex_hull_incremental.h" #include "ptm_constants.h" +#include +#include +#include +#include + namespace ptm { #define VISIBLE 1 @@ -22,354 +22,324 @@ namespace ptm { #define BOTH 3 #define TOLERANCE 1E-8 -static double norm_squared(double* p) +static double norm_squared(double *p) { - double x = p[0]; - double y = p[1]; - double z = p[2]; + double x = p[0]; + double y = p[1]; + double z = p[2]; - return x*x + y*y + z*z; + return x * x + y * y + z * z; } -static double dot_product(const double* a, const double* b) +static double dot_product(const double *a, const double *b) { - return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } -static void cross_product(double* a, double* b, double* c) +static void cross_product(double *a, double *b, double *c) { - c[0] = a[1] * b[2] - a[2] * b[1]; - c[1] = a[2] * b[0] - a[0] * b[2]; - c[2] = a[0] * b[1] - a[1] * b[0]; + c[0] = a[1] * b[2] - a[2] * b[1]; + c[1] = a[2] * b[0] - a[0] * b[2]; + c[2] = a[0] * b[1] - a[1] * b[0]; } -static void calculate_plane_normal(const double (*points)[3], int a, int b, int c, double* plane_normal) +static void calculate_plane_normal(const double (*points)[3], int a, int b, int c, + double *plane_normal) { - double u[3] = { points[b][0] - points[a][0], - points[b][1] - points[a][1], - points[b][2] - points[a][2] }; + double u[3] = {points[b][0] - points[a][0], points[b][1] - points[a][1], + points[b][2] - points[a][2]}; - double v[3] = { points[c][0] - points[a][0], - points[c][1] - points[a][1], - points[c][2] - points[a][2] }; + double v[3] = {points[c][0] - points[a][0], points[c][1] - points[a][1], + points[c][2] - points[a][2]}; - cross_product(u, v, plane_normal); - double norm = sqrt(norm_squared(plane_normal)); - plane_normal[0] /= norm; - plane_normal[1] /= norm; - plane_normal[2] /= norm; + cross_product(u, v, plane_normal); + double norm = sqrt(norm_squared(plane_normal)); + plane_normal[0] /= norm; + plane_normal[1] /= norm; + plane_normal[2] /= norm; } -static double point_plane_distance(const double* w, const double* plane_point, const double* plane_cross) +static double point_plane_distance(const double *w, const double *plane_point, + const double *plane_cross) { - return plane_cross[0] * (plane_point[0] - w[0]) - + plane_cross[1] * (plane_point[1] - w[1]) - + plane_cross[2] * (plane_point[2] - w[2]); + return plane_cross[0] * (plane_point[0] - w[0]) + plane_cross[1] * (plane_point[1] - w[1]) + + plane_cross[2] * (plane_point[2] - w[2]); } -static bool calc_max_extent(int num_points, const double (*points)[3], int* min_index, int* max_index) +static bool calc_max_extent(int num_points, const double (*points)[3], int *min_index, + int *max_index) { - for (int j=0;j<3;j++) - { - double dmin = DBL_MAX, dmax = -DBL_MAX; - int imin = 0, imax = 0; + for (int j = 0; j < 3; j++) { + double dmin = DBL_MAX, dmax = -DBL_MAX; + int imin = 0, imax = 0; - for (int i = 0;i dmax) - { - dmax = d; - imax = i; - } - } + for (int i = 0; i < num_points; i++) { + double d = points[i][j]; + if (d < dmin) { + dmin = d; + imin = i; + } + if (d > dmax) { + dmax = d; + imax = i; + } + } - if (imin == imax) - return false; //degenerate point set + if (imin == imax) return false; //degenerate point set - min_index[j] = imin; - max_index[j] = imax; - } + min_index[j] = imin; + max_index[j] = imax; + } - return true; + return true; } -static bool find_third_point(int num_points, const double (*points)[3], int a, int b, int* p_c) +static bool find_third_point(int num_points, const double (*points)[3], int a, int b, int *p_c) { - const double* x1 = points[a]; - const double* x2 = points[b]; + const double *x1 = points[a]; + const double *x2 = points[b]; - double x2x1[3] = {x2[0] - x1[0], x2[1] - x1[1], x2[2] - x1[2]}; - double ns_x2x1 = norm_squared(x2x1); + double x2x1[3] = {x2[0] - x1[0], x2[1] - x1[1], x2[2] - x1[2]}; + double ns_x2x1 = norm_squared(x2x1); - int bi = -1; - double max_dist = 0.0; - for (int i = 0;i max_dist) - { - max_dist = dist; - bi = i; - } - } + if (dist > max_dist) { + max_dist = dist; + bi = i; + } + } - *p_c = bi; - return max_dist > TOLERANCE; + *p_c = bi; + return max_dist > TOLERANCE; } -static bool find_fourth_point(int num_points, const double (*points)[3], int a, int b, int c, int* p_d) +static bool find_fourth_point(int num_points, const double (*points)[3], int a, int b, int c, + int *p_d) { - double plane_normal[3]; - calculate_plane_normal(points, a, b, c, plane_normal); + double plane_normal[3]; + calculate_plane_normal(points, a, b, c, plane_normal); + int bi = -1; + double max_dist = 0.0; + for (int i = 0; i < num_points; i++) { + if (i == a || i == b || i == c) continue; - int bi = -1; - double max_dist = 0.0; - for (int i = 0;i max_dist) { + max_dist = dist; + bi = i; + } + } - const double* x0 = points[i]; - double dist = fabs(point_plane_distance(x0, points[a], plane_normal)); - if (dist > max_dist) - { - max_dist = dist; - bi = i; - } - } - - *p_d = bi; - return max_dist > TOLERANCE; + *p_d = bi; + return max_dist > TOLERANCE; } -static int initial_simplex(int num_points, const double (*points)[3], int* initial_vertices) +static int initial_simplex(int num_points, const double (*points)[3], int *initial_vertices) { - int min_index[3] = {0}; - int max_index[3] = {0}; - if (!calc_max_extent(num_points, points, min_index, max_index)) - return -1; + int min_index[3] = {0}; + int max_index[3] = {0}; + if (!calc_max_extent(num_points, points, min_index, max_index)) return -1; - int bi = -1; - double max_dist = 0.0; - for (int i = 0;i<3;i++) - { - int a = min_index[i], b = max_index[i]; - double delta[3] = { points[a][0] - points[b][0], - points[a][1] - points[b][1], - points[a][2] - points[b][2] }; - double dist = norm_squared(delta); - if (dist > max_dist) - { - bi = i; - max_dist = dist; - } - } + int bi = -1; + double max_dist = 0.0; + for (int i = 0; i < 3; i++) { + int a = min_index[i], b = max_index[i]; + double delta[3] = {points[a][0] - points[b][0], points[a][1] - points[b][1], + points[a][2] - points[b][2]}; + double dist = norm_squared(delta); + if (dist > max_dist) { + bi = i; + max_dist = dist; + } + } - //first two points are (a, b) - int a = min_index[bi], b = max_index[bi], c = -1, d = -1; + //first two points are (a, b) + int a = min_index[bi], b = max_index[bi], c = -1, d = -1; - if (!find_third_point(num_points, points, a, b, &c)) - return -2; + if (!find_third_point(num_points, points, a, b, &c)) return -2; - if (!find_fourth_point(num_points, points, a, b, c, &d)) - return -3; + if (!find_fourth_point(num_points, points, a, b, c, &d)) return -3; - initial_vertices[0] = a; - initial_vertices[1] = b; - initial_vertices[2] = c; - initial_vertices[3] = d; - return 0; + initial_vertices[0] = a; + initial_vertices[1] = b; + initial_vertices[2] = c; + initial_vertices[3] = d; + return 0; } -static bool visible(const double* w, const double* plane_point, const double* plane_normal) +static bool visible(const double *w, const double *plane_point, const double *plane_normal) { - return point_plane_distance(w, plane_point, plane_normal) > 0; + return point_plane_distance(w, plane_point, plane_normal) > 0; } -void add_facet(const double (*points)[3], int a, int b, int c, int8_t* facet, double* plane_normal, double* barycentre) +void add_facet(const double (*points)[3], int a, int b, int c, int8_t *facet, double *plane_normal, + double *barycentre) { - calculate_plane_normal(points, a, b, c, plane_normal); - if (visible(barycentre, points[a], plane_normal)) - { - plane_normal[0] = -plane_normal[0]; - plane_normal[1] = -plane_normal[1]; - plane_normal[2] = -plane_normal[2]; + calculate_plane_normal(points, a, b, c, plane_normal); + if (visible(barycentre, points[a], plane_normal)) { + plane_normal[0] = -plane_normal[0]; + plane_normal[1] = -plane_normal[1]; + plane_normal[2] = -plane_normal[2]; - facet[0] = b; - facet[1] = a; - facet[2] = c; - } - else - { - facet[0] = a; - facet[1] = b; - facet[2] = c; - } + facet[0] = b; + facet[1] = a; + facet[2] = c; + } else { + facet[0] = a; + facet[1] = b; + facet[2] = c; + } } -static int initialize_convex_hull(int num_points, const double (*points)[3], int8_t facets[][3], double plane_normal[][3], bool* processed, int* initial_vertices, double* barycentre) +static int initialize_convex_hull(int num_points, const double (*points)[3], int8_t facets[][3], + double plane_normal[][3], bool *processed, int *initial_vertices, + double *barycentre) { - memset(processed, 0, PTM_MAX_POINTS * sizeof(bool)); - memset(barycentre, 0, 3 * sizeof(double)); - int ret = initial_simplex(num_points, points, initial_vertices); - if (ret != 0) - return ret; + memset(processed, 0, PTM_MAX_POINTS * sizeof(bool)); + memset(barycentre, 0, 3 * sizeof(double)); + int ret = initial_simplex(num_points, points, initial_vertices); + if (ret != 0) return ret; - for (int i = 0;i<4;i++) - { - int a = initial_vertices[i]; - processed[a] = true; + for (int i = 0; i < 4; i++) { + int a = initial_vertices[i]; + processed[a] = true; - barycentre[0] += points[a][0]; - barycentre[1] += points[a][1]; - barycentre[2] += points[a][2]; - } - barycentre[0] /= 4; - barycentre[1] /= 4; - barycentre[2] /= 4; + barycentre[0] += points[a][0]; + barycentre[1] += points[a][1]; + barycentre[2] += points[a][2]; + } + barycentre[0] /= 4; + barycentre[1] /= 4; + barycentre[2] /= 4; - add_facet(points, initial_vertices[0], initial_vertices[1], initial_vertices[2], facets[0], plane_normal[0], barycentre); - add_facet(points, initial_vertices[0], initial_vertices[1], initial_vertices[3], facets[1], plane_normal[1], barycentre); - add_facet(points, initial_vertices[0], initial_vertices[2], initial_vertices[3], facets[2], plane_normal[2], barycentre); - add_facet(points, initial_vertices[1], initial_vertices[2], initial_vertices[3], facets[3], plane_normal[3], barycentre); - return 0; + add_facet(points, initial_vertices[0], initial_vertices[1], initial_vertices[2], facets[0], + plane_normal[0], barycentre); + add_facet(points, initial_vertices[0], initial_vertices[1], initial_vertices[3], facets[1], + plane_normal[1], barycentre); + add_facet(points, initial_vertices[0], initial_vertices[2], initial_vertices[3], facets[2], + plane_normal[2], barycentre); + add_facet(points, initial_vertices[1], initial_vertices[2], initial_vertices[3], facets[3], + plane_normal[3], barycentre); + return 0; } -int get_convex_hull(int num_points, const double (*points)[3], convexhull_t* ch, int8_t simplex[][3]) +int get_convex_hull(int num_points, const double (*points)[3], convexhull_t *ch, + int8_t simplex[][3]) { - assert( num_points == PTM_NUM_POINTS_FCC - || num_points == PTM_NUM_POINTS_HCP - || num_points == PTM_NUM_POINTS_BCC - || num_points == PTM_NUM_POINTS_ICO - || num_points == PTM_NUM_POINTS_SC - || num_points == PTM_NUM_POINTS_DCUB - || num_points == PTM_NUM_POINTS_DHEX); + assert(num_points == PTM_NUM_POINTS_FCC || num_points == PTM_NUM_POINTS_HCP || + num_points == PTM_NUM_POINTS_BCC || num_points == PTM_NUM_POINTS_ICO || + num_points == PTM_NUM_POINTS_SC || num_points == PTM_NUM_POINTS_DCUB || + num_points == PTM_NUM_POINTS_DHEX); - int ret = 0; - int num_prev = ch->num_prev; - ch->num_prev = num_points; - if (!ch->ok || 0) - { - ret = initialize_convex_hull(num_points, points, ch->facets, ch->plane_normal, ch->processed, ch->initial_vertices, ch->barycentre); - if (ret != 0) - return ret; + int ret = 0; + int num_prev = ch->num_prev; + ch->num_prev = num_points; + if (!ch->ok) { + ret = initialize_convex_hull(num_points, points, ch->facets, ch->plane_normal, ch->processed, + ch->initial_vertices, ch->barycentre); + if (ret != 0) return ret; - ch->num_facets = 4; - num_prev = 0; - } + ch->num_facets = 4; + num_prev = 0; + } - for (int i = num_prev;iprocessed[i]) - continue; - ch->processed[i] = true; + for (int i = num_prev; i < num_points; i++) { + if (ch->processed[i]) continue; + ch->processed[i] = true; - int num_to_add = 0; - int8_t to_add[PTM_MAX_FACETS][3]; - int8_t edge_visible[PTM_MAX_POINTS][PTM_MAX_POINTS]; - memset(edge_visible, 0, sizeof(int8_t) * PTM_MAX_POINTS * PTM_MAX_POINTS); - for (int j = 0;jnum_facets;j++) - { - int a = ch->facets[j][0]; - int b = ch->facets[j][1]; - int c = ch->facets[j][2]; + int num_to_add = 0; + int8_t to_add[PTM_MAX_FACETS][3]; + int8_t edge_visible[PTM_MAX_POINTS][PTM_MAX_POINTS]; + memset(edge_visible, 0, sizeof(int8_t) * PTM_MAX_POINTS * PTM_MAX_POINTS); + for (int j = 0; j < ch->num_facets; j++) { + int a = ch->facets[j][0]; + int b = ch->facets[j][1]; + int c = ch->facets[j][2]; - int u = 0, v = 0, w = 0; + int u = 0, v = 0, w = 0; - double distance = point_plane_distance(points[i], points[a], ch->plane_normal[j]); - bool vis = distance > TOLERANCE; - if (vis) - { - u = edge_visible[a][b] |= VISIBLE; - edge_visible[b][a] |= VISIBLE; + double distance = point_plane_distance(points[i], points[a], ch->plane_normal[j]); + bool vis = distance > TOLERANCE; + if (vis) { + u = edge_visible[a][b] |= VISIBLE; + edge_visible[b][a] |= VISIBLE; - v = edge_visible[b][c] |= VISIBLE; - edge_visible[c][b] |= VISIBLE; + v = edge_visible[b][c] |= VISIBLE; + edge_visible[c][b] |= VISIBLE; - w = edge_visible[c][a] |= VISIBLE; - edge_visible[a][c] |= VISIBLE; + w = edge_visible[c][a] |= VISIBLE; + edge_visible[a][c] |= VISIBLE; - memcpy(ch->facets[j], ch->facets[ch->num_facets-1], 3 * sizeof(int8_t)); - memcpy(ch->plane_normal[j], ch->plane_normal[ch->num_facets-1], 3 * sizeof(double)); - ch->num_facets--; - j--; - } - else - { - u = edge_visible[a][b] |= INVISIBLE; - edge_visible[b][a] |= INVISIBLE; + memcpy(ch->facets[j], ch->facets[ch->num_facets - 1], 3 * sizeof(int8_t)); + memcpy(ch->plane_normal[j], ch->plane_normal[ch->num_facets - 1], 3 * sizeof(double)); + ch->num_facets--; + j--; + } else { + u = edge_visible[a][b] |= INVISIBLE; + edge_visible[b][a] |= INVISIBLE; - v = edge_visible[b][c] |= INVISIBLE; - edge_visible[c][b] |= INVISIBLE; + v = edge_visible[b][c] |= INVISIBLE; + edge_visible[c][b] |= INVISIBLE; - w = edge_visible[c][a] |= INVISIBLE; - edge_visible[a][c] |= INVISIBLE; - } + w = edge_visible[c][a] |= INVISIBLE; + edge_visible[a][c] |= INVISIBLE; + } - if (u == BOTH) - { - to_add[num_to_add][0] = i; - to_add[num_to_add][1] = a; - to_add[num_to_add][2] = b; - num_to_add++; - } + if (u == BOTH) { + to_add[num_to_add][0] = i; + to_add[num_to_add][1] = a; + to_add[num_to_add][2] = b; + num_to_add++; + } - if (v == BOTH) - { - to_add[num_to_add][0] = i; - to_add[num_to_add][1] = b; - to_add[num_to_add][2] = c; - num_to_add++; - } + if (v == BOTH) { + to_add[num_to_add][0] = i; + to_add[num_to_add][1] = b; + to_add[num_to_add][2] = c; + num_to_add++; + } - if (w == BOTH) - { - to_add[num_to_add][0] = i; - to_add[num_to_add][1] = c; - to_add[num_to_add][2] = a; - num_to_add++; - } - } + if (w == BOTH) { + to_add[num_to_add][0] = i; + to_add[num_to_add][1] = c; + to_add[num_to_add][2] = a; + num_to_add++; + } + } - for (int j = 0;jnum_facets >= PTM_MAX_FACETS) - return -4; + for (int j = 0; j < num_to_add; j++) { + if (ch->num_facets >= PTM_MAX_FACETS) return -4; - add_facet(points, to_add[j][0], to_add[j][1], to_add[j][2], ch->facets[ch->num_facets], ch->plane_normal[ch->num_facets], ch->barycentre); ch->num_facets++; - } - } + add_facet(points, to_add[j][0], to_add[j][1], to_add[j][2], ch->facets[ch->num_facets], + ch->plane_normal[ch->num_facets], ch->barycentre); + ch->num_facets++; + } + } - for (int i=0;inum_facets;i++) - { - int a = ch->facets[i][0]; - int b = ch->facets[i][1]; - int c = ch->facets[i][2]; - if (a == 0 || b == 0 || c == 0) - return 1; //central atom contained in convex hull + for (int i = 0; i < ch->num_facets; i++) { + int a = ch->facets[i][0]; + int b = ch->facets[i][1]; + int c = ch->facets[i][2]; + if (a == 0 || b == 0 || c == 0) return 1; //central atom contained in convex hull - simplex[i][0] = a - 1; - simplex[i][1] = b - 1; - simplex[i][2] = c - 1; - } - - return ret; -} + simplex[i][0] = a - 1; + simplex[i][1] = b - 1; + simplex[i][2] = c - 1; + } + return ret; } +} // namespace ptm diff --git a/src/QEQ/fix_qeq.cpp b/src/QEQ/fix_qeq.cpp index 5a4e4e4e7d..ffd45719a5 100644 --- a/src/QEQ/fix_qeq.cpp +++ b/src/QEQ/fix_qeq.cpp @@ -304,7 +304,7 @@ void FixQEq::init() ngroup = group->count(igroup); if (ngroup == 0) error->all(FLERR,"Fix {} group has no atoms", style); - if ((comm->me == 0) && (modify->find_fix_by_style("^efield") >= 0)) + if ((comm->me == 0) && (modify->get_fix_by_style("^efield").size() > 0)) error->warning(FLERR,"Fix efield is ignored during charge equilibration"); if (utils::strmatch(update->integrate_style,"^respa")) @@ -765,7 +765,7 @@ void FixQEq::read_file(char *file) file,utils::getsyserror())); TextFileReader reader(fp, "qeq parameter"); - while (1) { + while (true) { auto values = reader.next_values(0); if (values.count() == 0) continue; diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index bddeb330e4..31a09567ca 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -155,7 +155,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : master_group = (char *) "bond_react_MASTER_group"; // by using fixed group names, only one instance of fix bond/react is allowed. - if (modify->find_fix_by_style("^bond/react") != -1) + if (modify->get_fix_by_style("^bond/react").size() != 0) error->all(FLERR,"Only one instance of fix bond/react allowed at a time"); // let's find number of reactions specified @@ -2239,8 +2239,7 @@ double FixBondReact::custom_constraint(std::string varstr) } evlstr.push_back(varstr.substr(prev3+1)); - for (int i = 0; i < evlstr.size(); i++) - evlcat += evlstr[i]; + for (auto & evl : evlstr) evlcat += evl; char *cstr = utils::strdup(evlcat); val = input->variable->compute_equal(cstr); @@ -3763,7 +3762,7 @@ void FixBondReact::read(int myrxn) // stop when read an unrecognized line ncreate = 0; - while (1) { + while (true) { readline(line); diff --git a/src/REAXFF/fix_qeq_reaxff.cpp b/src/REAXFF/fix_qeq_reaxff.cpp index 874a10bbae..fa8fa79e00 100644 --- a/src/REAXFF/fix_qeq_reaxff.cpp +++ b/src/REAXFF/fix_qeq_reaxff.cpp @@ -380,18 +380,13 @@ void FixQEqReaxFF::init() if (group->count(igroup) == 0) error->all(FLERR,"Fix {} group has no atoms", style); - // there may be only one instance of fix efield - - int num_efield = 0; - for (int ifix = 0; ifix < modify->nfix; ++ifix) { - if (utils::strmatch(modify->fix[ifix]->style, "^efield")) ++num_efield; - } - if (num_efield > 1) - error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); + // get pointer to fix efield if present. there may be at most one instance of fix efield in use. efield = nullptr; - int ifix = modify->find_fix_by_style("^efield"); - if (ifix >= 0) efield = (FixEfield *) modify->fix[ifix]; + auto fixes = modify->get_fix_by_style("^efield"); + if (fixes.size() == 1) efield = (FixEfield *) fixes.front(); + else if (fixes.size() > 1) + error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); // ensure that fix efield is properly initialized before accessing its data and check some settings if (efield) { diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 3c8e808f93..3438d57977 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -63,9 +63,9 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : MPI_Comm_size(world,&nprocs); ntypes = atom->ntypes; - nevery = atoi(arg[3]); - nrepeat = atoi(arg[4]); - global_freq = nfreq = atoi(arg[5]); + nevery = utils::inumeric(FLERR,arg[3],false,lmp); + nrepeat = utils::inumeric(FLERR,arg[4],false,lmp); + global_freq = nfreq = utils::inumeric(FLERR,arg[5],false,lmp); comm_forward = 4; @@ -155,9 +155,9 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : // set BO cutoff if (strcmp(arg[iarg],"cutoff") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix reaxff/species command"); - itype = atoi(arg[iarg+1]); - jtype = atoi(arg[iarg+2]); - bo_cut = atof(arg[iarg+3]); + itype = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + jtype = utils::inumeric(FLERR,arg[iarg+2],false,lmp); + bo_cut = utils::numeric(FLERR,arg[iarg+3],false,lmp); if (itype > ntypes || jtype > ntypes) error->all(FLERR,"Illegal fix reaxff/species command"); if (itype <= 0 || jtype <= 0) @@ -187,7 +187,7 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"position") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal fix reaxff/species command"); posflag = 1; - posfreq = atoi(arg[iarg+1]); + posfreq = utils::inumeric(FLERR,arg[iarg+1],false,lmp); if (posfreq < nfreq || (posfreq%nfreq != 0)) error->all(FLERR,"Illegal fix reaxff/species command"); @@ -416,12 +416,12 @@ void FixReaxFFSpecies::FindMolecule () } loop = 0; - while (1) { + while (true) { comm->forward_comm_fix(this); loop ++; change = 0; - while (1) { + while (true) { done = 1; for (ii = 0; ii < inum; ii++) { diff --git a/src/REAXFF/pair_reaxff.cpp b/src/REAXFF/pair_reaxff.cpp index 1c6665b604..9a3bdf2f79 100644 --- a/src/REAXFF/pair_reaxff.cpp +++ b/src/REAXFF/pair_reaxff.cpp @@ -332,23 +332,19 @@ void PairReaxFF::coeff(int nargs, char **args) void PairReaxFF::init_style() { - if (!atom->q_flag) - error->all(FLERR,"Pair style reaxff requires atom attribute q"); + if (!atom->q_flag) error->all(FLERR,"Pair style reaxff requires atom attribute q"); - bool have_qeq = ((modify->find_fix_by_style("^qeq/reax") != -1) - || (modify->find_fix_by_style("^qeq/shielded") != -1) - || (modify->find_fix_by_style("^acks2/reax") != -1)); - if (!have_qeq && qeqflag == 1) - error->all(FLERR,"Pair reax/c requires use of fix qeq/reax or qeq/shielded" - " or fix acks2/reax"); + auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); + int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size(); - int have_acks2 = (modify->find_fix_by_style("^acks2/reax") != -1); - api->system->acks2_flag = have_acks2; - if (api->system->acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - FixACKS2ReaxFF* acks2_fix = (FixACKS2ReaxFF*) modify->fix[ifix]; - api->workspace->s = acks2_fix->get_s(); - } + if (qeqflag && (have_qeq != 1)) + error->all(FLERR,"Pair style reaxff requires use of exactly one of the " + "fix qeq/reaxff or fix qeq/shielded or fix acks2/reaxff commands"); + + api->system->acks2_flag = acks2_fixes.size(); + if (api->system->acks2_flag) + api->workspace->s = ((FixACKS2ReaxFF *)acks2_fixes.front())->get_s(); api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts @@ -476,9 +472,8 @@ void PairReaxFF::compute(int eflag, int vflag) api->system->bigN = static_cast (atom->natoms); // all atoms in the system if (api->system->acks2_flag) { - int ifix = modify->find_fix_by_style("^acks2/reax"); - FixACKS2ReaxFF* acks2_fix = (FixACKS2ReaxFF*) modify->fix[ifix]; - api->workspace->s = acks2_fix->get_s(); + auto ifix = modify->get_fix_by_style("^acks2/reax").front(); + api->workspace->s = ((FixACKS2ReaxFF*) ifix)->get_s(); } // setup data structures diff --git a/src/REAXFF/reaxff_allocate.cpp b/src/REAXFF/reaxff_allocate.cpp index cbb53420ba..16b71d041c 100644 --- a/src/REAXFF/reaxff_allocate.cpp +++ b/src/REAXFF/reaxff_allocate.cpp @@ -231,14 +231,11 @@ namespace ReaxFF { auto error = system->error_ptr; reallocate_data *wsr = &(workspace->realloc); - if (system->n >= DANGER_ZONE * system->local_cap || - (0 && system->n <= LOOSE_ZONE * system->local_cap)) { + if (system->n >= DANGER_ZONE * system->local_cap) system->local_cap = MAX((int)(system->n * safezone), mincap); - } int Nflag = 0; - if (system->N >= DANGER_ZONE * system->total_cap || - (0 && system->N <= LOOSE_ZONE * system->total_cap)) { + if (system->N >= DANGER_ZONE * system->total_cap) { Nflag = 1; system->total_cap = MAX((int)(system->N * safezone), mincap); } @@ -271,8 +268,7 @@ namespace ReaxFF { /* hydrogen bonds list */ if (control->hbond_cut > 0) { Hflag = 0; - if (system->numH >= DANGER_ZONE * system->Hcap || - (0 && system->numH <= LOOSE_ZONE * system->Hcap)) { + if (system->numH >= DANGER_ZONE * system->Hcap) { Hflag = 1; system->Hcap = int(MAX(system->numH * saferzone, mincap)); } diff --git a/src/REAXFF/reaxff_control.cpp b/src/REAXFF/reaxff_control.cpp index a95ec1d4ac..62a45b0dc7 100644 --- a/src/REAXFF/reaxff_control.cpp +++ b/src/REAXFF/reaxff_control.cpp @@ -83,7 +83,7 @@ namespace ReaxFF { LAMMPS_NS::TextFileReader reader(control_file, "ReaxFF control"); reader.ignore_comments = false; - while (1) { + while (true) { auto values = reader.next_values(0); // empty line diff --git a/src/REPLICA/fix_hyper_local.cpp b/src/REPLICA/fix_hyper_local.cpp index ba91644c53..b506ef4f4a 100644 --- a/src/REPLICA/fix_hyper_local.cpp +++ b/src/REPLICA/fix_hyper_local.cpp @@ -980,7 +980,7 @@ void FixHyperLocal::build_bond_list(int natom) "hyper/local:clist"); } - while (1) { + while (true) { if (firstflag) break; for (i = 0; i < nall; i++) numcoeff[i] = 0; for (i = 0; i < nall; i++) clist[i] = nullptr; diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 8cfc4b5c24..e730aac351 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -392,7 +392,7 @@ void NEB::readfile(char *file, int flag) if (flag == 0) { if (me_universe == 0) { open(file); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of NEB file"); start = &line[strspn(line," \t\n\v\f\r")]; @@ -408,7 +408,7 @@ void NEB::readfile(char *file, int flag) if (me == 0) { if (ireplica) { open(file); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of NEB file"); start = &line[strspn(line," \t\n\v\f\r")]; diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index db9767d01e..9c39518508 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -2281,7 +2281,7 @@ void FixRigid::readfile(int which, double *vec, if (fp == nullptr) error->one(FLERR,"Cannot open fix rigid file {}: {}", inpfile,utils::getsyserror()); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of fix rigid file"); start = &line[strspn(line," \t\n\v\f\r")]; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 0ef05d926c..5db24a96d5 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -2451,7 +2451,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) if (fp == nullptr) error->one(FLERR,"Cannot open fix rigid/small file {}: {}", inpfile,utils::getsyserror()); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of fix rigid/small file"); diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 9e45ec13d8..29739b294c 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -361,11 +361,17 @@ void FixShake::init() // could have changed locations in fix list since created // set ptrs to rRESPA variables + fix_respa = nullptr; if (utils::strmatch(update->integrate_style,"^respa")) { - ifix_respa = modify->find_fix_by_style("^RESPA"); - nlevels_respa = ((Respa *) update->integrate)->nlevels; - loop_respa = ((Respa *) update->integrate)->loop; - step_respa = ((Respa *) update->integrate)->step; + if (update->whichflag > 0) { + auto fixes = modify->get_fix_by_style("^RESPA"); + if (fixes.size() > 0) fix_respa = (FixRespa *) fixes.front(); + else error->all(FLERR,"Run style respa did not create fix RESPA"); + } + Respa *respa_style = (Respa *) update->integrate; + nlevels_respa = respa_style->nlevels; + loop_respa = respa_style->loop; + step_respa = respa_style->step; } // set equilibrium bond distances @@ -1619,7 +1625,7 @@ void FixShake::unconstrained_update_respa(int ilevel) // x + dt0 (v + dtN/m fN + 1/2 dt(N-1)/m f(N-1) + ... + 1/2 dt0/m f0) // also set dtfsq = dt0*dtN so that shake,shake3,etc can use it - double ***f_level = ((FixRespa *) modify->fix[ifix_respa])->f_level; + double ***f_level = fix_respa->f_level; dtfsq = dtf_inner * step_respa[ilevel]; double invmass,dtfmsq; diff --git a/src/RIGID/fix_shake.h b/src/RIGID/fix_shake.h index c5563ea9b9..3db415281d 100644 --- a/src/RIGID/fix_shake.h +++ b/src/RIGID/fix_shake.h @@ -77,8 +77,8 @@ class FixShake : public Fix { int molecular; // copy of atom->molecular double *bond_distance, *angle_distance; // constraint distances - int ifix_respa; // rRESPA fix needed by SHAKE - int nlevels_respa; // copies of needed rRESPA variables + class FixRespa *fix_respa; // rRESPA fix needed by SHAKE + int nlevels_respa; // copies of needed rRESPA variables int *loop_respa; double *step_respa; diff --git a/src/SPIN/neb_spin.cpp b/src/SPIN/neb_spin.cpp index 1c987f8e7e..0ed3ad28c3 100644 --- a/src/SPIN/neb_spin.cpp +++ b/src/SPIN/neb_spin.cpp @@ -387,7 +387,7 @@ void NEBSpin::readfile(char *file, int flag) if (flag == 0) { if (me_universe == 0) { open(file); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of neb/spin file"); start = &line[strspn(line," \t\n\v\f\r")]; @@ -401,7 +401,7 @@ void NEBSpin::readfile(char *file, int flag) if (me == 0) { if (ireplica) { open(file); - while (1) { + while (true) { eof = fgets(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of neb/spin file"); start = &line[strspn(line," \t\n\v\f\r")]; diff --git a/src/SPIN/pair_spin.cpp b/src/SPIN/pair_spin.cpp index 74f7aaaf77..4247918499 100644 --- a/src/SPIN/pair_spin.cpp +++ b/src/SPIN/pair_spin.cpp @@ -79,10 +79,8 @@ void PairSpin::init_style() // checking if nve/spin or neb/spin is a listed fix - bool have_fix = ((modify->find_fix_by_style("^nve/spin") != -1) - || (modify->find_fix_by_style("^neb/spin") != -1)); - - if (!have_fix && (comm->me == 0)) + if ((comm->me == 0) && ((modify->get_fix_by_style("^nve/spin").size() + + modify->get_fix_by_style("^neb/spin").size()) == 0)) error->warning(FLERR,"Using spin pair style without nve/spin or neb/spin"); // check if newton pair is on @@ -98,9 +96,11 @@ void PairSpin::init_style() // get the lattice_flag from nve/spin - int ifix = modify->find_fix_by_style("^nve/spin"); - if (ifix >=0) - lattice_flag = ((FixNVESpin *) modify->fix[ifix])->lattice_flag; + auto fixes = modify->get_fix_by_style("^nve/spin"); + if (fixes.size() == 1) + lattice_flag = ((FixNVESpin *) fixes.front())->lattice_flag; + else if (fixes.size() > 1) + error->warning(FLERR,"Using multiple instances of fix nve/spin or neb/spin"); // init. size of energy stacking lists diff --git a/src/SRD/fix_srd.cpp b/src/SRD/fix_srd.cpp index f1e17eaa24..48d7d55663 100644 --- a/src/SRD/fix_srd.cpp +++ b/src/SRD/fix_srd.cpp @@ -1433,7 +1433,7 @@ void FixSRD::collisions_multi() jlast = -1; dt = dt_big; - while (1) { + while (true) { nbig = nbinbig[ibin]; if (ibounce == 0) ncheck += nbig; @@ -2263,7 +2263,7 @@ void FixSRD::slip(double *vs, double *vb, double *xb, Big *big, double *xsurf, d double tangent[3], vsurf[3]; double *omega = big->omega; - while (1) { + while (true) { r1 = sigma * random->gaussian(); r2 = sigma * random->gaussian(); vnmag = sqrt(r1 * r1 + r2 * r2); @@ -2319,7 +2319,7 @@ void FixSRD::slip_wall(double *vs, int iwall, double *norm, double *vsnew) tangent2[1] = norm[2] * tangent1[0] - norm[0] * tangent1[2]; tangent2[2] = norm[0] * tangent1[1] - norm[1] * tangent1[0]; - while (1) { + while (true) { r1 = sigma * random->gaussian(); r2 = sigma * random->gaussian(); vnmag = sqrt(r1 * r1 + r2 * r2); @@ -2370,7 +2370,7 @@ void FixSRD::noslip(double *vs, double *vb, double *xb, Big *big, int iwall, dou tangent2[1] = norm[2] * tangent1[0] - norm[0] * tangent1[2]; tangent2[2] = norm[0] * tangent1[1] - norm[1] * tangent1[0]; - while (1) { + while (true) { r1 = sigma * random->gaussian(); r2 = sigma * random->gaussian(); vnmag = sqrt(r1 * r1 + r2 * r2); diff --git a/src/atom.cpp b/src/atom.cpp index 796c0ba156..0cf48406af 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1700,8 +1700,7 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) void Atom::data_fix_compute_variable(int nprev, int nnew) { - for (int m = 0; m < modify->nfix; m++) { - Fix *fix = modify->fix[m]; + for (const auto &fix : modify->get_fix_list()) { if (fix->create_attribute) for (int i = nprev; i < nnew; i++) fix->set_arrays(i); @@ -1904,7 +1903,7 @@ void Atom::add_molecule(int narg, char **arg) int ifile = 1; int index = 1; - while (1) { + while (true) { molecules = (Molecule **) memory->srealloc(molecules,(nmolecule+1)*sizeof(Molecule *), "atom::molecules"); @@ -2238,15 +2237,13 @@ void Atom::setup_sort_bins() #ifdef LMP_GPU if (userbinsize == 0.0) { - int ifix = modify->find_fix("package_gpu"); - if (ifix >= 0) { + FixGPU *fix = (FixGPU *)modify->get_fix_by_id("package_gpu"); + if (fix) { const double subx = domain->subhi[0] - domain->sublo[0]; const double suby = domain->subhi[1] - domain->sublo[1]; const double subz = domain->subhi[2] - domain->sublo[2]; - FixGPU *fix = static_cast(modify->fix[ifix]); - binsize = fix->binsize(subx, suby, subz, atom->nlocal, - neighbor->cutneighmax); + binsize = fix->binsize(subx, suby, subz, atom->nlocal,neighbor->cutneighmax); bininv = 1.0 / binsize; nbinx = static_cast (ceil(subx * bininv)); diff --git a/src/atom_vec_body.cpp b/src/atom_vec_body.cpp index a1ef126069..6308153be6 100644 --- a/src/atom_vec_body.cpp +++ b/src/atom_vec_body.cpp @@ -105,7 +105,7 @@ void AtomVecBody::process_args(int narg, char **arg) if (narg < 1) error->all(FLERR,"Invalid atom_style body command"); - if (0) { + if (false) { bptr = nullptr; #define BODY_CLASS diff --git a/src/balance.cpp b/src/balance.cpp index bd3ba007ef..f2fcda2712 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -496,11 +496,8 @@ void Balance::weight_storage(char *prefix) if (prefix) cmd = prefix; cmd += "IMBALANCE_WEIGHTS"; - int ifix = modify->find_fix(cmd); - if (ifix < 1) { - cmd += " all STORE peratom 0 1"; - fixstore = (FixStore *) modify->add_fix(cmd); - } else fixstore = (FixStore *) modify->fix[ifix]; + fixstore = (FixStore *) modify->get_fix_by_id(cmd); + if (!fixstore) fixstore = (FixStore *) modify->add_fix(cmd + " all STORE peratom 0 1"); // do not carry weights with atoms during normal atom migration @@ -930,7 +927,7 @@ int Balance::shift() // else add split I-1 or J+1 to set and try again // delta = size of expanded split set that will satisy criterion - while (1) { + while (true) { delta = (j-i) * close; midpt = 0.5 * (split[i]+split[j]); start = midpt - 0.5*delta; diff --git a/src/change_box.cpp b/src/change_box.cpp index 91d65bfcad..bbac78ab3d 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -291,16 +291,12 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == ORTHO) { if (domain->xy != 0.0 || domain->yz != 0.0 || domain->xz != 0.0) - error->all(FLERR, - "Cannot change box to orthogonal when tilt is non-zero"); + error->all(FLERR,"Cannot change box to orthogonal when tilt is non-zero"); if (output->ndump) - error->all(FLERR, - "Cannot change box ortho/triclinic with dumps defined"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->no_change_box) - error->all(FLERR, - "Cannot change box ortho/triclinic with " - "certain fixes defined"); + error->all(FLERR,"Cannot change box ortho/triclinic with dumps defined"); + for (const auto &fix : modify->get_fix_list()) + if (fix->no_change_box) + error->all(FLERR,"Cannot change box ortho/triclinic with certain fixes defined"); domain->triclinic = 0; domain->set_initial_box(); domain->set_global_box(); @@ -309,13 +305,10 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == TRICLINIC) { if (output->ndump) - error->all(FLERR, - "Cannot change box ortho/triclinic with dumps defined"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->no_change_box) - error->all(FLERR, - "Cannot change box ortho/triclinic with " - "certain fixes defined"); + error->all(FLERR,"Cannot change box ortho/triclinic with dumps defined"); + for (const auto &fix : modify->get_fix_list()) + if (fix->no_change_box) + error->all(FLERR,"Cannot change box ortho/triclinic with certain fixes defined"); domain->triclinic = 1; domain->set_lamda_box(); domain->set_initial_box(); diff --git a/src/comm.cpp b/src/comm.cpp index afe074cb5c..48dae2368a 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -201,8 +201,9 @@ void Comm::init() if (ghost_velocity) size_forward += atom->avec->size_velocity; if (ghost_velocity) size_border += atom->avec->size_velocity; - for (int i = 0; i < modify->nfix; i++) - size_border += modify->fix[i]->comm_border; + const auto &fix_list = modify->get_fix_list(); + for (const auto &fix : fix_list) + size_border += fix->comm_border; // per-atom limits for communication // maxexchange = max # of datums in exchange comm, set in exchange() @@ -217,9 +218,9 @@ void Comm::init() if (force->pair) maxforward = MAX(maxforward,force->pair->comm_forward); if (force->pair) maxreverse = MAX(maxreverse,force->pair->comm_reverse); - for (int i = 0; i < modify->nfix; i++) { - maxforward = MAX(maxforward,modify->fix[i]->comm_forward); - maxreverse = MAX(maxreverse,modify->fix[i]->comm_reverse); + for (const auto &fix : fix_list) { + maxforward = MAX(maxforward,fix->comm_forward); + maxreverse = MAX(maxreverse,fix->comm_reverse); } for (int i = 0; i < modify->ncompute; i++) { @@ -241,12 +242,9 @@ void Comm::init() maxexchange_atom = atom->avec->maxexchange; - int nfix = modify->nfix; - Fix **fix = modify->fix; - maxexchange_fix_dynamic = 0; - for (int i = 0; i < nfix; i++) - if (fix[i]->maxexchange_dynamic) maxexchange_fix_dynamic = 1; + for (const auto &fix : fix_list) + if (fix->maxexchange_dynamic) maxexchange_fix_dynamic = 1; if ((mode == Comm::MULTI) && (neighbor->style != Neighbor::MULTI)) error->all(FLERR,"Cannot use comm mode multi without multi-style neighbor lists"); @@ -267,12 +265,9 @@ void Comm::init() void Comm::init_exchange() { - int nfix = modify->nfix; - Fix **fix = modify->fix; - maxexchange_fix = 0; - for (int i = 0; i < nfix; i++) - maxexchange_fix += fix[i]->maxexchange; + for (const auto &fix : modify->get_fix_list()) + maxexchange_fix += fix->maxexchange; maxexchange = maxexchange_atom + maxexchange_fix; bufextra = maxexchange + BUFEXTRA; diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 482b90c4c2..28ef37b008 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -1884,7 +1884,7 @@ void CommTiled::box_drop_brick(int idim, double *lo, double *hi, int &indexme) if (index < 0 || index > procgrid[idim]) error->one(FLERR,"Comm tiled invalid index in box drop brick"); - while (1) { + while (true) { lower = boxlo[idim] + prd[idim]*split[index]; if (index < procgrid[idim]-1) upper = boxlo[idim] + prd[idim]*split[index+1]; diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index 818d8657b8..cb39f61ce0 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -166,7 +166,7 @@ void ComputeAggregateAtom::compute_peratom() int change,done,anychange; - while (1) { + while (true) { comm->forward_comm_compute(this); // reverse communication when bonds are not stored on every processor @@ -175,7 +175,7 @@ void ComputeAggregateAtom::compute_peratom() comm->reverse_comm_compute(this); change = 0; - while (1) { + while (true) { done = 1; for (i = 0; i < nlocal; i++) { if (!(mask[i] & groupbit)) continue; diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index 787dc43fc6..1351d379b7 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -29,10 +28,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - idchunk(nullptr), massproc(nullptr), masstotal(nullptr), com(nullptr), comall(nullptr), angmom(nullptr), angmomall(nullptr) + Compute(lmp, narg, arg), idchunk(nullptr), massproc(nullptr), masstotal(nullptr), com(nullptr), + comall(nullptr), angmom(nullptr), angmomall(nullptr) { - if (narg != 4) error->all(FLERR,"Illegal compute angmom/chunk command"); + if (narg != 4) error->all(FLERR, "Illegal compute angmom/chunk command"); array_flag = 1; size_array_cols = 3; @@ -57,7 +56,7 @@ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : ComputeAngmomChunk::~ComputeAngmomChunk() { - delete [] idchunk; + delete[] idchunk; memory->destroy(massproc); memory->destroy(masstotal); memory->destroy(com); @@ -70,21 +69,18 @@ ComputeAngmomChunk::~ComputeAngmomChunk() void ComputeAngmomChunk::init() { - int icompute = modify->find_compute(idchunk); - if (icompute < 0) - error->all(FLERR,"Chunk/atom compute does not exist for " - "compute angmom/chunk"); - cchunk = (ComputeChunkAtom *) modify->compute[icompute]; - if (strcmp(cchunk->style,"chunk/atom") != 0) - error->all(FLERR,"Compute angmom/chunk does not use chunk/atom compute"); + cchunk = (ComputeChunkAtom *) modify->get_compute_by_id(idchunk); + if (!cchunk) error->all(FLERR, "Chunk/atom compute does not exist for compute angmom/chunk"); + if (strcmp(cchunk->style, "chunk/atom") != 0) + error->all(FLERR, "Compute angmom/chunk does not use chunk/atom compute"); } /* ---------------------------------------------------------------------- */ void ComputeAngmomChunk::compute_array() { - int i,index; - double dx,dy,dz,massone; + int i, index; + double dx, dy, dz, massone; double unwrap[3]; invoked_array = update->ntimestep; @@ -120,19 +116,21 @@ void ComputeAngmomChunk::compute_array() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - index = ichunk[i]-1; + index = ichunk[i] - 1; if (index < 0) continue; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - domain->unmap(x[i],image[i],unwrap); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + domain->unmap(x[i], image[i], unwrap); massproc[index] += massone; com[index][0] += unwrap[0] * massone; com[index][1] += unwrap[1] * massone; com[index][2] += unwrap[2] * massone; } - MPI_Allreduce(massproc,masstotal,nchunk,MPI_DOUBLE,MPI_SUM,world); - MPI_Allreduce(&com[0][0],&comall[0][0],3*nchunk,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(massproc, masstotal, nchunk, MPI_DOUBLE, MPI_SUM, world); + MPI_Allreduce(&com[0][0], &comall[0][0], 3 * nchunk, MPI_DOUBLE, MPI_SUM, world); for (i = 0; i < nchunk; i++) { if (masstotal[i] > 0.0) { @@ -148,21 +146,22 @@ void ComputeAngmomChunk::compute_array() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - index = ichunk[i]-1; + index = ichunk[i] - 1; if (index < 0) continue; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - comall[index][0]; dy = unwrap[1] - comall[index][1]; dz = unwrap[2] - comall[index][2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - angmom[index][0] += massone * (dy*v[i][2] - dz*v[i][1]); - angmom[index][1] += massone * (dz*v[i][0] - dx*v[i][2]); - angmom[index][2] += massone * (dx*v[i][1] - dy*v[i][0]); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + angmom[index][0] += massone * (dy * v[i][2] - dz * v[i][1]); + angmom[index][1] += massone * (dz * v[i][0] - dx * v[i][2]); + angmom[index][2] += massone * (dx * v[i][1] - dy * v[i][0]); } - MPI_Allreduce(&angmom[0][0],&angmomall[0][0],3*nchunk, - MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&angmom[0][0], &angmomall[0][0], 3 * nchunk, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -209,7 +208,7 @@ int ComputeAngmomChunk::lock_length() void ComputeAngmomChunk::lock(Fix *fixptr, bigint startstep, bigint stopstep) { - cchunk->lock(fixptr,startstep,stopstep); + cchunk->lock(fixptr, startstep, stopstep); } /* ---------------------------------------------------------------------- @@ -234,12 +233,12 @@ void ComputeAngmomChunk::allocate() memory->destroy(angmom); memory->destroy(angmomall); maxchunk = nchunk; - memory->create(massproc,maxchunk,"angmom/chunk:massproc"); - memory->create(masstotal,maxchunk,"angmom/chunk:masstotal"); - memory->create(com,maxchunk,3,"angmom/chunk:com"); - memory->create(comall,maxchunk,3,"angmom/chunk:comall"); - memory->create(angmom,maxchunk,3,"angmom/chunk:angmom"); - memory->create(angmomall,maxchunk,3,"angmom/chunk:angmomall"); + memory->create(massproc, maxchunk, "angmom/chunk:massproc"); + memory->create(masstotal, maxchunk, "angmom/chunk:masstotal"); + memory->create(com, maxchunk, 3, "angmom/chunk:com"); + memory->create(comall, maxchunk, 3, "angmom/chunk:comall"); + memory->create(angmom, maxchunk, 3, "angmom/chunk:angmom"); + memory->create(angmomall, maxchunk, 3, "angmom/chunk:angmomall"); array = angmomall; } @@ -250,7 +249,7 @@ void ComputeAngmomChunk::allocate() double ComputeAngmomChunk::memory_usage() { double bytes = (bigint) maxchunk * 2 * sizeof(double); - bytes += (double) maxchunk * 2*3 * sizeof(double); - bytes += (double) maxchunk * 2*3 * sizeof(double); + bytes += (double) maxchunk * 2 * 3 * sizeof(double); + bytes += (double) maxchunk * 2 * 3 * sizeof(double); return bytes; } diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index c35b6a63e7..a050c8bb6a 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -13,33 +12,34 @@ ------------------------------------------------------------------------- */ #include "compute_centroid_stress_atom.h" -#include -#include "atom.h" -#include "update.h" -#include "comm.h" -#include "force.h" -#include "pair.h" -#include "bond.h" + #include "angle.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" #include "dihedral.h" +#include "error.h" +#include "fix.h" +#include "force.h" #include "improper.h" #include "kspace.h" -#include "modify.h" -#include "fix.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "pair.h" +#include "update.h" + +#include using namespace LAMMPS_NS; -enum{NOBIAS,BIAS}; +enum { NOBIAS, BIAS }; /* ---------------------------------------------------------------------- */ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char **arg) : - Compute(lmp, narg, arg), - id_temp(nullptr), stress(nullptr) + Compute(lmp, narg, arg), id_temp(nullptr), stress(nullptr) { - if (narg < 4) error->all(FLERR,"Illegal compute centroid/stress/atom command"); + if (narg < 4) error->all(FLERR, "Illegal compute centroid/stress/atom command"); peratom_flag = 1; size_peratom_cols = 9; @@ -50,17 +50,16 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char // store temperature ID used by stress computation // insure it is valid for temperature computation - if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; + if (strcmp(arg[3], "NULL") == 0) + id_temp = nullptr; else { id_temp = utils::strdup(arg[3]); - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute centroid/stress/atom temperature ID"); - if (modify->compute[icompute]->tempflag == 0) - error->all(FLERR, - "Compute centroid/stress/atom temperature ID does not " - "compute temperature"); + auto compute = modify->get_compute_by_id(id_temp); + if (!compute) + error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}", id_temp); + if (compute->tempflag == 0) + error->all(FLERR, "Compute centroid/stress/atom temperature ID does not compute temperature"); } // process optional args @@ -79,19 +78,28 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char fixflag = 0; int iarg = 4; while (iarg < narg) { - if (strcmp(arg[iarg],"ke") == 0) keflag = 1; - else if (strcmp(arg[iarg],"pair") == 0) pairflag = 1; - else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1; - else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1; - else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1; - else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1; - else if (strcmp(arg[iarg],"kspace") == 0) kspaceflag = 1; - else if (strcmp(arg[iarg],"fix") == 0) fixflag = 1; - else if (strcmp(arg[iarg],"virial") == 0) { + if (strcmp(arg[iarg], "ke") == 0) + keflag = 1; + else if (strcmp(arg[iarg], "pair") == 0) + pairflag = 1; + else if (strcmp(arg[iarg], "bond") == 0) + bondflag = 1; + else if (strcmp(arg[iarg], "angle") == 0) + angleflag = 1; + else if (strcmp(arg[iarg], "dihedral") == 0) + dihedralflag = 1; + else if (strcmp(arg[iarg], "improper") == 0) + improperflag = 1; + else if (strcmp(arg[iarg], "kspace") == 0) + kspaceflag = 1; + else if (strcmp(arg[iarg], "fix") == 0) + fixflag = 1; + else if (strcmp(arg[iarg], "virial") == 0) { pairflag = 1; bondflag = angleflag = dihedralflag = improperflag = 1; kspaceflag = fixflag = 1; - } else error->all(FLERR,"Illegal compute centroid/stress/atom command"); + } else + error->all(FLERR, "Illegal compute centroid/stress/atom command"); iarg++; } } @@ -103,7 +111,7 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char ComputeCentroidStressAtom::~ComputeCentroidStressAtom() { - delete [] id_temp; + delete[] id_temp; memory->destroy(stress); } @@ -115,13 +123,15 @@ void ComputeCentroidStressAtom::init() // fixes could have changed or compute_modify could have changed it if (id_temp) { - int icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Could not find compute centroid/stress/atom temperature ID"); - temperature = modify->compute[icompute]; - if (temperature->tempbias) biasflag = BIAS; - else biasflag = NOBIAS; - } else biasflag = NOBIAS; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR, "Could not find compute centroid/stress/atom temperature ID {}",id_temp); + if (temperature->tempbias) + biasflag = BIAS; + else + biasflag = NOBIAS; + } else + biasflag = NOBIAS; // check if force components and fixes support centroid atom stress // all bond styles support it as CENTROID_SAME @@ -158,12 +168,12 @@ void ComputeCentroidStressAtom::init() void ComputeCentroidStressAtom::compute_peratom() { - int i,j; + int i, j; double onemass; invoked_peratom = update->ntimestep; if (update->vflag_atom != invoked_peratom) - error->all(FLERR,"Per-atom virial was not tallied on needed timestep"); + error->all(FLERR, "Per-atom virial was not tallied on needed timestep"); // grow local stress array if necessary // needs to be atom->nmax in length @@ -171,7 +181,7 @@ void ComputeCentroidStressAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(stress); nmax = atom->nmax; - memory->create(stress,nmax,9,"centroid/stress/atom:stress"); + memory->create(stress, nmax, 9, "centroid/stress/atom:stress"); array_atom = stress; } @@ -194,8 +204,7 @@ void ComputeCentroidStressAtom::compute_peratom() // clear local stress array for (i = 0; i < ntotal; i++) - for (j = 0; j < 9; j++) - stress[i][j] = 0.0; + for (j = 0; j < 9; j++) stress[i][j] = 0.0; // add in per-atom contributions from all force components and fixes @@ -205,15 +214,12 @@ void ComputeCentroidStressAtom::compute_peratom() if (force->pair->centroidstressflag == CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } else { double **vatom = force->pair->vatom; for (i = 0; i < npair; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } } @@ -226,41 +232,34 @@ void ComputeCentroidStressAtom::compute_peratom() if (bondflag && force->bond) { double **vatom = force->bond->vatom; for (i = 0; i < nbond; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } if (angleflag && force->angle) { double **cvatom = force->angle->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (dihedralflag && force->dihedral) { double **cvatom = force->dihedral->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (improperflag && force->improper) { double **cvatom = force->improper->cvatom; for (i = 0; i < nbond; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; + for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; } if (kspaceflag && force->kspace && force->kspace->compute_flag) { double **vatom = force->kspace->vatom; for (i = 0; i < nkspace; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } @@ -279,18 +278,15 @@ void ComputeCentroidStressAtom::compute_peratom() double **vatom = fix[ifix]->vatom; if (vatom) for (i = 0; i < nlocal; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; + for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) stress[i][j] += vatom[i][j - 3]; } } } // communicate ghost virials between neighbor procs - if (force->newton || - (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) + if (force->newton || (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) comm->reverse_comm_compute(this); // zero virial of atoms not in group @@ -327,30 +323,30 @@ void ComputeCentroidStressAtom::compute_peratom() for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { onemass = mvv2e * rmass[i]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; } } else { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { onemass = mvv2e * mass[type[i]]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; } } @@ -359,41 +355,40 @@ void ComputeCentroidStressAtom::compute_peratom() // invoke temperature if it hasn't been already // this insures bias factor is pre-computed - if (keflag && temperature->invoked_scalar != update->ntimestep) - temperature->compute_scalar(); + if (keflag && temperature->invoked_scalar != update->ntimestep) temperature->compute_scalar(); if (rmass) { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - temperature->remove_bias(i,v[i]); + temperature->remove_bias(i, v[i]); onemass = mvv2e * rmass[i]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; - temperature->restore_bias(i,v[i]); + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; + temperature->restore_bias(i, v[i]); } } else { for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - temperature->remove_bias(i,v[i]); + temperature->remove_bias(i, v[i]); onemass = mvv2e * mass[type[i]]; - stress[i][0] += onemass*v[i][0]*v[i][0]; - stress[i][1] += onemass*v[i][1]*v[i][1]; - stress[i][2] += onemass*v[i][2]*v[i][2]; - stress[i][3] += onemass*v[i][0]*v[i][1]; - stress[i][4] += onemass*v[i][0]*v[i][2]; - stress[i][5] += onemass*v[i][1]*v[i][2]; - stress[i][6] += onemass*v[i][1]*v[i][0]; - stress[i][7] += onemass*v[i][2]*v[i][0]; - stress[i][8] += onemass*v[i][2]*v[i][1]; - temperature->restore_bias(i,v[i]); + stress[i][0] += onemass * v[i][0] * v[i][0]; + stress[i][1] += onemass * v[i][1] * v[i][1]; + stress[i][2] += onemass * v[i][2] * v[i][2]; + stress[i][3] += onemass * v[i][0] * v[i][1]; + stress[i][4] += onemass * v[i][0] * v[i][2]; + stress[i][5] += onemass * v[i][1] * v[i][2]; + stress[i][6] += onemass * v[i][1] * v[i][0]; + stress[i][7] += onemass * v[i][2] * v[i][0]; + stress[i][8] += onemass * v[i][2] * v[i][1]; + temperature->restore_bias(i, v[i]); } } } @@ -420,7 +415,7 @@ void ComputeCentroidStressAtom::compute_peratom() int ComputeCentroidStressAtom::pack_reverse_comm(int n, int first, double *buf) { - int i,m,last; + int i, m, last; m = 0; last = first + n; @@ -442,7 +437,7 @@ int ComputeCentroidStressAtom::pack_reverse_comm(int n, int first, double *buf) void ComputeCentroidStressAtom::unpack_reverse_comm(int n, int *list, double *buf) { - int i,j,m; + int i, j, m; m = 0; for (i = 0; i < n; i++) { @@ -465,6 +460,6 @@ void ComputeCentroidStressAtom::unpack_reverse_comm(int n, int *list, double *bu double ComputeCentroidStressAtom::memory_usage() { - double bytes = (double)nmax*9 * sizeof(double); + double bytes = (double) nmax * 9 * sizeof(double); return bytes; } diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index fc4f17e53a..daa8fc64e7 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -316,40 +316,30 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : } if (which == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(cfvid); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute chunk /atom does not exist"); - if (modify->compute[icompute]->peratom_flag == 0) - error->all(FLERR, - "Compute chunk/atom compute does not calculate " - "per-atom values"); - if (argindex == 0 && - modify->compute[icompute]->size_peratom_cols != 0) - error->all(FLERR,"Compute chunk/atom compute does not " - "calculate a per-atom vector"); - if (argindex && modify->compute[icompute]->size_peratom_cols == 0) - error->all(FLERR,"Compute chunk/atom compute does not " - "calculate a per-atom array"); - if (argindex && - argindex > modify->compute[icompute]->size_peratom_cols) - error->all(FLERR,"Compute chunk/atom compute array is " - "accessed out-of-range"); + cchunk = modify->get_compute_by_id(cfvid); + if (!cchunk) + error->all(FLERR,"Compute ID {} for compute chunk /atom does not exist",cfvid); + if (cchunk->peratom_flag == 0) + error->all(FLERR,"Compute chunk/atom compute does not calculate per-atom values"); + if ((argindex == 0) && (cchunk->size_peratom_cols != 0)) + error->all(FLERR,"Compute chunk/atom compute does not calculate a per-atom vector"); + if (argindex && (cchunk->size_peratom_cols == 0)) + error->all(FLERR,"Compute chunk/atom compute does not calculate a per-atom array"); + if (argindex && argindex > cchunk->size_peratom_cols) + error->all(FLERR,"Compute chunk/atom compute array is accessed out-of-range"); } if (which == ArgInfo::FIX) { - int ifix = modify->find_fix(cfvid); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute chunk/atom does not exist"); - if (modify->fix[ifix]->peratom_flag == 0) - error->all(FLERR,"Compute chunk/atom fix does not calculate " - "per-atom values"); - if (argindex == 0 && modify->fix[ifix]->size_peratom_cols != 0) - error->all(FLERR, - "Compute chunk/atom fix does not calculate a per-atom vector"); - if (argindex && modify->fix[ifix]->size_peratom_cols == 0) - error->all(FLERR, - "Compute chunk/atom fix does not calculate a per-atom array"); - if (argindex && argindex > modify->fix[ifix]->size_peratom_cols) + fchunk = modify->get_fix_by_id(cfvid); + if (!fchunk) + error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",cfvid); + if (fchunk->peratom_flag == 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate per-atom values"); + if (argindex == 0 && fchunk->size_peratom_cols != 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate a per-atom vector"); + if (argindex && fchunk->size_peratom_cols == 0) + error->all(FLERR,"Compute chunk/atom fix does not calculate a per-atom array"); + if (argindex && argindex > fchunk->size_peratom_cols) error->all(FLERR,"Compute chunk/atom fix array is accessed out-of-range"); } @@ -358,16 +348,14 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : if (ivariable < 0) error->all(FLERR,"Variable name for compute chunk/atom does not exist"); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Compute chunk/atom variable is not " - "atom-style variable"); + error->all(FLERR,"Compute chunk/atom variable is not atom-style variable"); } // setup scaling if (binflag) { if (domain->triclinic == 1 && scaleflag != REDUCED) - error->all(FLERR,"Compute chunk/atom for triclinic boxes " - "requires units reduced"); + error->all(FLERR,"Compute chunk/atom for triclinic boxes requires units reduced"); } if (scaleflag == LATTICE) { @@ -501,15 +489,13 @@ void ComputeChunkAtom::init() // set compute,fix,variable if (which == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(cfvid); - if (icompute < 0) - error->all(FLERR,"Compute ID for compute chunk/atom does not exist"); - cchunk = modify->compute[icompute]; + cchunk = modify->get_compute_by_id(cfvid); + if (!cchunk) + error->all(FLERR,"Compute ID {} for compute chunk/atom does not exist",cfvid); } else if (which == ArgInfo::FIX) { - int ifix = modify->find_fix(cfvid); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute chunk/atom does not exist"); - fchunk = modify->fix[ifix]; + fchunk = modify->get_fix_by_id(cfvid); + if (!fchunk) + error->all(FLERR,"Fix ID {} for compute chunk/atom does not exist",cfvid); } else if (which == ArgInfo::VARIABLE) { int ivariable = input->variable->find(cfvid); if (ivariable < 0) diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index 476af0bfa2..ca3fe1f453 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -164,11 +164,11 @@ void ComputeClusterAtom::compute_peratom() int change,done,anychange; - while (1) { + while (true) { comm->forward_comm_compute(this); change = 0; - while (1) { + while (true) { done = 1; for (ii = 0; ii < inum; ii++) { i = ilist[ii]; diff --git a/src/compute_fragment_atom.cpp b/src/compute_fragment_atom.cpp index 9ed57fef60..d361e29d41 100644 --- a/src/compute_fragment_atom.cpp +++ b/src/compute_fragment_atom.cpp @@ -150,7 +150,7 @@ void ComputeFragmentAtom::compute_peratom() int iteration = 0; - while (1) { + while (true) { iteration++; comm->forward_comm_compute(this); diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index e82be7d331..f21d1fc23d 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -693,7 +693,7 @@ void CreateAtoms::add_random() int valid; for (int i = 0; i < nrandom; i++) { - while (1) { + while (true) { xone[0] = xlo + random->uniform() * (xhi-xlo); xone[1] = ylo + random->uniform() * (yhi-ylo); xone[2] = zlo + random->uniform() * (zhi-zlo); diff --git a/src/domain.cpp b/src/domain.cpp index daaf41338f..22c38c977a 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -140,19 +140,19 @@ void Domain::init() int box_change_x=0, box_change_y=0, box_change_z=0; int box_change_yz=0, box_change_xz=0, box_change_xy=0; - Fix **fixes = modify->fix; + const auto &fixes = modify->get_fix_list(); if (nonperiodic == 2) box_change_size = 1; - for (int i = 0; i < modify->nfix; i++) { - if (fixes[i]->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1; - if (fixes[i]->box_change & Fix::BOX_CHANGE_X) box_change_x++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_Y) box_change_y++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_Z) box_change_z++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++; - if (fixes[i]->box_change & Fix::BOX_CHANGE_XY) box_change_xy++; + for (const auto &fix : fixes) { + if (fix->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1; + if (fix->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1; + if (fix->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1; + if (fix->box_change & Fix::BOX_CHANGE_X) box_change_x++; + if (fix->box_change & Fix::BOX_CHANGE_Y) box_change_y++; + if (fix->box_change & Fix::BOX_CHANGE_Z) box_change_z++; + if (fix->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++; + if (fix->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++; + if (fix->box_change & Fix::BOX_CHANGE_XY) box_change_xy++; } std::string mesg = "Must not have multiple fixes change box parameter "; @@ -174,12 +174,12 @@ void Domain::init() // check for fix deform deform_flag = deform_vremap = deform_groupbit = 0; - for (int i = 0; i < modify->nfix; i++) - if (utils::strmatch(modify->fix[i]->style,"^deform")) { + for (const auto &fix : fixes) + if (utils::strmatch(fix->style,"^deform")) { deform_flag = 1; - if (((FixDeform *) modify->fix[i])->remapflag == Domain::V_REMAP) { + if (((FixDeform *) fix)->remapflag == Domain::V_REMAP) { deform_vremap = 1; - deform_groupbit = modify->fix[i]->groupbit; + deform_groupbit = fix->groupbit; } } @@ -1742,7 +1742,7 @@ void Domain::add_region(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal region command"); if (strcmp(arg[1],"delete") == 0) { - delete_region(narg,arg); + delete_region(arg[0]); return; } @@ -1811,16 +1811,6 @@ Region *Domain::region_creator(LAMMPS *lmp, int narg, char ** arg) delete a region ------------------------------------------------------------------------- */ -void Domain::delete_region(int narg, char **arg) -{ - if (narg != 2) error->all(FLERR,"Illegal region command"); - - int iregion = find_region(arg[0]); - if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); - - delete_region(iregion); -} - void Domain::delete_region(int iregion) { if ((iregion < 0) || (iregion >= nregion)) return; @@ -1833,12 +1823,20 @@ void Domain::delete_region(int iregion) nregion--; } +void Domain::delete_region(const std::string &id) +{ + int iregion = find_region(id); + if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); + + delete_region(iregion); +} + /* ---------------------------------------------------------------------- return region index if name matches existing region ID return -1 if no such region ------------------------------------------------------------------------- */ -int Domain::find_region(const std::string &name) +int Domain::find_region(const std::string &name) const { for (int iregion = 0; iregion < nregion; iregion++) if (name == regions[iregion]->id) return iregion; @@ -1846,15 +1844,31 @@ int Domain::find_region(const std::string &name) } /* ---------------------------------------------------------------------- - return region index if name matches existing region style - return -1 if no such region + return pointer to region name matches existing region ID + return null if no match ------------------------------------------------------------------------- */ -int Domain::find_region_by_style(const std::string &name) +Region *Domain::get_region_by_id(const std::string &name) const { for (int iregion = 0; iregion < nregion; iregion++) - if (name == regions[iregion]->style) return iregion; - return -1; + if (name == regions[iregion]->id) return regions[iregion]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointers to regions by region style name + return vector with matching pointers +------------------------------------------------------------------------- */ + +const std::vector Domain::get_region_by_style(const std::string &name) const +{ + std::vector matches; + if (name.empty()) return matches; + + for (int iregion = 0; iregion < nregion; iregion++) + if (name == regions[iregion]->style) matches.push_back(regions[iregion]); + + return matches; } /* ---------------------------------------------------------------------- diff --git a/src/domain.h b/src/domain.h index 711bab0fb2..234bdbb837 100644 --- a/src/domain.h +++ b/src/domain.h @@ -137,10 +137,11 @@ class Domain : protected Pointers { void set_lattice(int, char **); void add_region(int, char **); - void delete_region(int, char **); void delete_region(int); - int find_region(const std::string &); - int find_region_by_style(const std::string &); + void delete_region(const std::string &); + int find_region(const std::string &) const; + Region *get_region_by_id(const std::string &) const; + const std::vector get_region_by_style(const std::string &) const; void set_boundary(int, char **, int); void set_box(int, char **); void print_box(const std::string &); diff --git a/src/dump.cpp b/src/dump.cpp index d00c42086d..4c02aa3070 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -248,8 +248,8 @@ void Dump::init() reorderflag = 0; int gcmcflag = 0; - for (int i = 0; i < modify->nfix; i++) - if ((strcmp(modify->fix[i]->style,"gcmc") == 0)) + for (const auto &fix : modify->get_fix_list()) + if (utils::strmatch(fix->style,"^gcmc")) gcmcflag = 1; if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag) { diff --git a/src/finish.cpp b/src/finish.cpp index 81ba59c1df..f3dbc83498 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -364,14 +364,13 @@ void Finish::end(int flag) } #ifdef LMP_OPENMP - int ifix = modify->find_fix("package_omp"); + FixOMP *fixomp = (FixOMP *) modify->get_fix_by_id("package_omp"); // print thread breakdown only with full timer detail - if ((ifix >= 0) && timer->has_full() && me == 0) { + if (fixomp && timer->has_full() && me == 0) { double thr_total = 0.0; ThrData *td; - FixOMP *fixomp = static_cast(lmp->modify->fix[ifix]); for (i=0; i < nthreads; ++i) { td = fixomp->get_thr(i); thr_total += td->get_time(Timer::ALL); diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index a3da6e6a3d..836121fdc2 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -243,10 +243,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : if (any_variable_length && (nrepeat > 1 || ave == RUNNING || ave == WINDOW)) { for (int i = 0; i < nvalues; i++) - if (varlen[i] && which[i] == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(ids[i]); - modify->compute[icompute]->lock_enable(); - } + if (varlen[i] && which[i] == ArgInfo::COMPUTE) + modify->get_compute_by_id(ids[i])->lock_enable(); lockforever = 0; } diff --git a/src/fix_deposit.cpp b/src/fix_deposit.cpp index 7f153cd172..c18a0e23dd 100644 --- a/src/fix_deposit.cpp +++ b/src/fix_deposit.cpp @@ -74,18 +74,18 @@ FixDeposit::FixDeposit(LAMMPS *lmp, int narg, char **arg) : // error checks on region and its extent being inside simulation box - if (iregion == -1) error->all(FLERR,"Must specify a region in fix deposit"); - if (domain->regions[iregion]->bboxflag == 0) + if (!iregion) error->all(FLERR,"Must specify a region in fix deposit"); + if (iregion->bboxflag == 0) error->all(FLERR,"Fix deposit region does not support a bounding box"); - if (domain->regions[iregion]->dynamic_check()) + if (iregion->dynamic_check()) error->all(FLERR,"Fix deposit region cannot be dynamic"); - xlo = domain->regions[iregion]->extent_xlo; - xhi = domain->regions[iregion]->extent_xhi; - ylo = domain->regions[iregion]->extent_ylo; - yhi = domain->regions[iregion]->extent_yhi; - zlo = domain->regions[iregion]->extent_zlo; - zhi = domain->regions[iregion]->extent_zhi; + xlo = iregion->extent_xlo; + xhi = iregion->extent_xhi; + ylo = iregion->extent_ylo; + yhi = iregion->extent_yhi; + zlo = iregion->extent_zlo; + zhi = iregion->extent_zhi; if (domain->triclinic == 0) { if (xlo < domain->boxlo[0] || xhi > domain->boxhi[0] || @@ -227,23 +227,19 @@ void FixDeposit::init() { // set index and check validity of region - iregion = domain->find_region(idregion); - if (iregion == -1) - error->all(FLERR,"Region ID for fix deposit does not exist"); + iregion = domain->get_region_by_id(idregion); + if (!iregion) error->all(FLERR,"Region ID {} for fix deposit does not exist", idregion); // if rigidflag defined, check for rigid/small fix // its molecule template must be same as this one fixrigid = nullptr; if (rigidflag) { - int ifix = modify->find_fix(idrigid); - if (ifix < 0) error->all(FLERR,"Fix deposit rigid fix does not exist"); - fixrigid = modify->fix[ifix]; + fixrigid = modify->get_fix_by_id(idrigid); + if (!fixrigid) error->all(FLERR,"Fix deposit rigid fix ID {} does not exist", idrigid); int tmp; if (onemols != (Molecule **) fixrigid->extract("onemol",tmp)) - error->all(FLERR, - "Fix deposit and fix rigid/small not using " - "same molecule template ID"); + error->all(FLERR, "Fix deposit and rigid fix are not using the same molecule template ID"); } // if shakeflag defined, check for SHAKE fix @@ -251,13 +247,11 @@ void FixDeposit::init() fixshake = nullptr; if (shakeflag) { - int ifix = modify->find_fix(idshake); - if (ifix < 0) error->all(FLERR,"Fix deposit shake fix does not exist"); - fixshake = modify->fix[ifix]; + fixshake = modify->get_fix_by_id(idshake); + if (!fixshake) error->all(FLERR,"Fix deposit shake fix ID {} does not exist", idshake); int tmp; if (onemols != (Molecule **) fixshake->extract("onemol",tmp)) - error->all(FLERR,"Fix deposit and fix shake not using " - "same molecule template ID"); + error->all(FLERR,"Fix deposit and fix shake are not using the same molecule template ID"); } // for finite size spherical particles: @@ -357,13 +351,13 @@ void FixDeposit::pre_exchange() coord[0] = xlo + random->uniform() * (xhi-xlo); coord[1] = ylo + random->uniform() * (yhi-ylo); coord[2] = zlo + random->uniform() * (zhi-zlo); - } while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0); + } while (iregion->match(coord[0],coord[1],coord[2]) == 0); } else if (distflag == DIST_GAUSSIAN) { do { coord[0] = xmid + random->gaussian() * sigma; coord[1] = ymid + random->gaussian() * sigma; coord[2] = zmid + random->gaussian() * sigma; - } while (domain->regions[iregion]->match(coord[0],coord[1],coord[2]) == 0); + } while (iregion->match(coord[0],coord[1],coord[2]) == 0); } else error->all(FLERR,"Unknown particle distribution in fix deposit"); // adjust vertical coord by offset @@ -662,7 +656,7 @@ void FixDeposit::options(int narg, char **arg) { // defaults - iregion = -1; + iregion = nullptr; idregion = nullptr; mode = ATOM; molfrac = nullptr; @@ -691,17 +685,15 @@ void FixDeposit::options(int narg, char **arg) while (iarg < narg) { if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); - iregion = domain->find_region(arg[iarg+1]); - if (iregion == -1) - error->all(FLERR,"Region ID for fix deposit does not exist"); + iregion = domain->get_region_by_id(arg[iarg+1]); + if (!iregion) error->all(FLERR,"Region ID {} for fix deposit does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"mol") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) - error->all(FLERR,"Molecule template ID for fix deposit does not exist"); + if (imol == -1) error->all(FLERR,"Molecule template ID for fix deposit does not exist"); mode = MOLECULE; onemols = &atom->molecules[imol]; nmol = onemols[0]->nset; diff --git a/src/fix_deposit.h b/src/fix_deposit.h index a7c506beb6..cc7d482fb0 100644 --- a/src/fix_deposit.h +++ b/src/fix_deposit.h @@ -38,12 +38,13 @@ class FixDeposit : public Fix { private: int ninsert, ntype, nfreq, seed; - int iregion, globalflag, localflag, maxattempt, rateflag, scaleflag, targetflag; + int globalflag, localflag, maxattempt, rateflag, scaleflag, targetflag; int mode, rigidflag, shakeflag, idnext, distflag, orientflag; double lo, hi, deltasq, nearsq, rate, sigma; double vxlo, vxhi, vylo, vyhi, vzlo, vzhi; double xlo, xhi, ylo, yhi, zlo, zhi, xmid, ymid, zmid; double rx, ry, rz, tx, ty, tz; + class Region *iregion; char *idregion; char *idrigid, *idshake; diff --git a/src/fix_gravity.cpp b/src/fix_gravity.cpp index 743fc705d2..16cd97469d 100644 --- a/src/fix_gravity.cpp +++ b/src/fix_gravity.cpp @@ -32,7 +32,6 @@ using namespace FixConst; using namespace MathConst; enum{CHUTE,SPHERICAL,VECTOR}; -enum{CONSTANT,EQUAL}; // same as FixPour /* ---------------------------------------------------------------------- */ diff --git a/src/fix_gravity.h b/src/fix_gravity.h index 31b6eb3478..389c5a1af1 100644 --- a/src/fix_gravity.h +++ b/src/fix_gravity.h @@ -37,6 +37,7 @@ class FixGravity : public Fix { virtual void post_force_respa(int, int, int); double compute_scalar(); void *extract(const char *, int &); + enum { CONSTANT, EQUAL }; protected: int style, disable; diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index f90d83af4b..f7b9662c24 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -18,6 +18,7 @@ #include "comm.h" #include "error.h" #include "memory.h" +#include "read_data.h" #include "tokenizer.h" #include @@ -54,8 +55,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"mol") == 0) { if (atom->molecule_flag) - error->all(FLERR,"Fix property/atom mol when atom_style " - "already has molecule attribute"); + error->all(FLERR,"Fix property/atom mol when atom_style already has molecule attribute"); if (molecule_flag) error->all(FLERR,"Fix property/atom cannot specify mol twice"); styles[nvalue] = MOLECULE; @@ -95,6 +95,8 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols); if (index[nvalue] >= 0) error->all(FLERR,"Fix property/atom vector name already exists"); + if (ReadData::is_data_section(id)) + error->all(FLERR,"Fix property/atom fix ID must not be a data file section name"); index[nvalue] = atom->add_custom(&arg[iarg][2],0,0); cols[nvalue] = 0; values_peratom++; @@ -107,6 +109,8 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols); if (index[nvalue] >= 0) error->all(FLERR,"Fix property/atom vector name already exists"); + if (ReadData::is_data_section(id)) + error->all(FLERR,"Fix property/atom fix ID must not be a data file section name"); index[nvalue] = atom->add_custom(&arg[iarg][2],1,0); cols[nvalue] = 0; values_peratom++; @@ -122,6 +126,8 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : which = atom->find_custom(&arg[iarg][3],flag,ncols); if (which >= 0) error->all(FLERR,"Fix property/atom array name {} already exists", &arg[iarg][3]); + if (ReadData::is_data_section(id)) + error->all(FLERR,"Fix property/atom fix ID must not be a data file section name"); ncols = utils::inumeric(FLERR,arg[iarg+1],true,lmp); if (ncols < 1) diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp index 9066182ed1..e916b8e9fe 100644 --- a/src/fix_vector.cpp +++ b/src/fix_vector.cpp @@ -65,64 +65,54 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) : // setup and error check // for fix inputs, check that fix frequency is acceptable - - for (int i = 0; i < nvalues; i++) { - if (which[i] == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(ids[i]); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix vector does not exist"); - if (argindex[i] == 0 && modify->compute[icompute]->scalar_flag == 0) - error->all(FLERR,"Fix vector compute does not calculate a scalar"); - if (argindex[i] && modify->compute[icompute]->vector_flag == 0) - error->all(FLERR,"Fix vector compute does not calculate a vector"); - if (argindex[i] && argindex[i] > modify->compute[icompute]->size_vector) - error->all(FLERR, - "Fix vector compute vector is accessed out-of-range"); - - } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for fix vector does not exist"); - if (argindex[i] == 0 && modify->fix[ifix]->scalar_flag == 0) - error->all(FLERR,"Fix vector fix does not calculate a scalar"); - if (argindex[i] && modify->fix[ifix]->vector_flag == 0) - error->all(FLERR,"Fix vector fix does not calculate a vector"); - if (argindex[i] && argindex[i] > modify->fix[ifix]->size_vector) - error->all(FLERR,"Fix vector fix vector is accessed out-of-range"); - if (nevery % modify->fix[ifix]->global_freq) - error->all(FLERR, - "Fix for fix vector not computed at compatible time"); - - } else if (which[i] == ArgInfo::VARIABLE) { - int ivariable = input->variable->find(ids[i]); - if (ivariable < 0) - error->all(FLERR,"Variable name for fix vector does not exist"); - if (argindex[i] == 0 && input->variable->equalstyle(ivariable) == 0) - error->all(FLERR,"Fix vector variable is not equal-style variable"); - if (argindex[i] && input->variable->vectorstyle(ivariable) == 0) - error->all(FLERR,"Fix vector variable is not vector-style variable"); - } - } - // this fix produces either a global vector or array // intensive/extensive flags set by compute,fix,variable that produces value int value,finalvalue; for (int i = 0; i < nvalues; i++) { if (which[i] == ArgInfo::COMPUTE) { - Compute *compute = modify->compute[modify->find_compute(ids[i])]; - if (argindex[0] == 0) value = compute->extscalar; - else if (compute->extvector >= 0) value = compute->extvector; - else value = compute->extlist[argindex[0]-1]; + auto icompute = modify->get_compute_by_id(ids[i]); + if (!icompute) error->all(FLERR,"Compute ID {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && icompute->scalar_flag == 0) + error->all(FLERR,"Fix vector compute {} does not calculate a scalar",ids[i]); + if (argindex[i] && icompute->vector_flag == 0) + error->all(FLERR,"Fix vector compute {} does not calculate a vector",ids[i]); + if (argindex[i] && argindex[i] > icompute->size_vector) + error->all(FLERR,"Fix vector compute {} vector is accessed out-of-range",ids[i]); + + if (argindex[i] == 0) value = icompute->extscalar; + else if (icompute->extvector >= 0) value = icompute->extvector; + else value = icompute->extlist[argindex[i]-1]; + } else if (which[i] == ArgInfo::FIX) { - Fix *fix = modify->fix[modify->find_fix(ids[i])]; - if (argindex[i] == 0) value = fix->extvector; - else value = fix->extarray; - } else if (which[i] == ArgInfo::VARIABLE) value = 0; + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) error->all(FLERR,"Fix ID {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && ifix->scalar_flag == 0) + error->all(FLERR,"Fix vector fix {} does not calculate a scalar",ids[i]); + if (argindex[i] && ifix->vector_flag == 0) + error->all(FLERR,"Fix vector fix {} does not calculate a vector",ids[i]); + if (argindex[i] && argindex[i] > ifix->size_vector) + error->all(FLERR,"Fix vector fix {} vector is accessed out-of-range",ids[i]); + if (nevery % ifix->global_freq) + error->all(FLERR,"Fix for fix {} vector not computed at compatible time",ids[i]); + + if (argindex[i] == 0) value = ifix->extvector; + else value = ifix->extarray; + + } else if (which[i] == ArgInfo::VARIABLE) { + int ivariable = input->variable->find(ids[i]); + if (ivariable < 0) + error->all(FLERR,"Variable name {} for fix vector does not exist",ids[i]); + if (argindex[i] == 0 && input->variable->equalstyle(ivariable) == 0) + error->all(FLERR,"Fix vector variable {} is not equal-style variable",ids[i]); + if (argindex[i] && input->variable->vectorstyle(ivariable) == 0) + error->all(FLERR,"Fix vector variable {} is not vector-style variable",ids[i]); + value = 0; + } + if (i == 0) finalvalue = value; else if (value != finalvalue) - error->all(FLERR,"Fix vector cannot set output array " - "intensive/extensive from these inputs"); + error->all(FLERR,"Fix vector cannot set output array intensive/extensive from these inputs"); } if (nvalues == 1) { @@ -191,14 +181,12 @@ void FixVector::init() for (int i = 0; i < nvalues; i++) { if (which[i] == ArgInfo::COMPUTE) { int icompute = modify->find_compute(ids[i]); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix vector does not exist"); + if (icompute < 0) error->all(FLERR,"Compute ID {} for fix vector does not exist",id[i]); value2index[i] = icompute; } else if (which[i] == ArgInfo::FIX) { int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for fix vector does not exist"); + if (ifix < 0) error->all(FLERR,"Fix ID {} for fix vector does not exist",id[i]); value2index[i] = ifix; } else if (which[i] == ArgInfo::VARIABLE) { @@ -254,7 +242,7 @@ void FixVector::end_of_step() // invoke compute if not previously invoked if (which[i] == ArgInfo::COMPUTE) { - Compute *compute = modify->compute[m]; + auto compute = modify->get_compute_by_index(m); if (argindex[i] == 0) { if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) { @@ -274,9 +262,9 @@ void FixVector::end_of_step() } else if (which[i] == ArgInfo::FIX) { if (argindex[i] == 0) - result[i] = modify->fix[m]->compute_scalar(); + result[i] = modify->get_fix_by_index(m)->compute_scalar(); else - result[i] = modify->fix[m]->compute_vector(argindex[i]-1); + result[i] = modify->get_fix_by_index(m)->compute_vector(argindex[i]-1); // evaluate equal-style or vector-style variable diff --git a/src/group.cpp b/src/group.cpp index 57c701a7fa..0dc0a560dd 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -105,8 +105,8 @@ void Group::assign(int narg, char **arg) int igroup = find(arg[0]); if (igroup == -1) error->all(FLERR,"Could not find group delete group ID"); if (igroup == 0) error->all(FLERR,"Cannot delete group all"); - for (i = 0; i < modify->nfix; i++) - if (modify->fix[i]->igroup == igroup) + for (const auto &fix : modify->get_fix_list()) + if (fix->igroup == igroup) error->all(FLERR,"Cannot delete group currently used by a fix"); for (i = 0; i < modify->ncompute; i++) if (modify->compute[i]->igroup == igroup) diff --git a/src/info.cpp b/src/info.cpp index bbc94fbccb..7e8dbd37b9 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -309,6 +309,7 @@ void Info::command(int narg, char **arg) #else // defined(LAMMPS_SMALLSMALL) fputs("-DLAMMPS_SMALLSMALL\n",out); #endif + if (has_gzip_support()) fmt::print(out,"\n{}\n",platform::compress_info()); int ncword, ncline = 0; fputs("\nInstalled packages:\n\n",out); @@ -566,16 +567,13 @@ void Info::command(int narg, char **arg) } if (flags & COMPUTES) { - int ncompute = modify->ncompute; - Compute **compute = modify->compute; + int i = 0; char **names = group->names; fputs("\nCompute information:\n",out); - for (int i=0; i < ncompute; ++i) { - fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", - i, std::string(compute[i]->id)+',', - std::string(compute[i]->style)+',', - names[compute[i]->igroup]); - } + for (const auto &compute : modify->get_compute_list()) + fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", i++, + std::string(compute->id)+',',std::string(compute->style)+',', + names[compute->igroup]); } if (flags & DUMPS) { @@ -587,10 +585,8 @@ void Info::command(int narg, char **arg) fputs("\nDump information:\n",out); for (int i=0; i < ndump; ++i) { fmt::print(out,"Dump[{:3d}]: {:16} file = {:16} style = {:16} group = {:16} ", - i, std::string(dump[i]->id)+',', - std::string(dump[i]->filename)+',', - std::string(dump[i]->style)+',', - std::string(names[dump[i]->igroup])+','); + i, std::string(dump[i]->id)+',',std::string(dump[i]->filename)+',', + std::string(dump[i]->style)+',',std::string(names[dump[i]->igroup])+','); if (nevery[i]) { fmt::print(out,"every = {}\n", nevery[i]); } else { @@ -600,16 +596,12 @@ void Info::command(int narg, char **arg) } if (flags & FIXES) { - int nfix = modify->nfix; - Fix **fix = modify->fix; + int i = 0; char **names = group->names; fputs("\nFix information:\n",out); - for (int i=0; i < nfix; ++i) { - fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n", - i,std::string(fix[i]->id)+',', - std::string(fix[i]->style)+',', - names[fix[i]->igroup]); - } + for (const auto &fix : modify->get_fix_list()) + fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n",i++, + std::string(fix->id)+',',std::string(fix->style)+',',names[fix->igroup]); } if (flags & VARIABLES) { @@ -621,8 +613,7 @@ void Info::command(int narg, char **arg) for (int i=0; i < nvar; ++i) { int ndata = 1; fmt::print(out,"Variable[{:3d}]: {:16} style = {:16} def =", - i,std::string(names[i])+',', - std::string(varstyles[style[i]])+','); + i,std::string(names[i])+',',std::string(varstyles[style[i]])+','); if (style[i] == Variable::INTERNAL) { fmt::print(out,"{:.8}\n",input->variable->dvalue[i]); continue; @@ -797,13 +788,13 @@ bool Info::is_active(const char *category, const char *name) if (strcmp(category,"package") == 0) { if (strcmp(name,"gpu") == 0) { - return (modify->find_fix("package_gpu") >= 0) ? true : false; + return (modify->get_fix_by_id("package_gpu")) ? true : false; } else if (strcmp(name,"intel") == 0) { - return (modify->find_fix("package_intel") >= 0) ? true : false; + return (modify->get_fix_by_id("package_intel")) ? true : false; } else if (strcmp(name,"kokkos") == 0) { return (lmp->kokkos && lmp->kokkos->kokkos_exists) ? true : false; } else if (strcmp(name,"omp") == 0) { - return (modify->find_fix("package_omp") >= 0) ? true : false; + return (modify->get_fix_by_id("package_omp")) ? true : false; } else error->all(FLERR,"Unknown name for info package category: {}", name); } else if (strcmp(category,"newton") == 0) { @@ -916,10 +907,8 @@ bool Info::is_defined(const char *category, const char *name) return true; } } else if (strcmp(category,"fix") == 0) { - int nfix = modify->nfix; - Fix **fix = modify->fix; - for (int i=0; i < nfix; ++i) { - if (strcmp(fix[i]->id,name) == 0) + for (const auto &fix : modify->get_fix_list()) { + if (strcmp(fix->id,name) == 0) return true; } } else if (strcmp(category,"group") == 0) { @@ -1023,7 +1012,7 @@ static std::vector get_style_names(std::map std::vector names; names.reserve(styles->size()); - for (auto const& kv : *styles) { + for (auto const &kv : *styles) { // skip "secret" styles if (isupper(kv.first[0])) continue; names.push_back(kv.first); diff --git a/src/input.cpp b/src/input.cpp index 21c092f356..08f62bdb42 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -180,7 +180,7 @@ void Input::file() { int m,n; - while (1) { + while (true) { // read a line from input script // n = length of line including str terminator, 0 if end of file @@ -189,7 +189,7 @@ void Input::file() if (me == 0) { m = 0; - while (1) { + while (true) { if (infile == nullptr) { n = 0; diff --git a/src/lammps.cpp b/src/lammps.cpp index 5d571b88dd..0829c4fdbd 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1379,6 +1379,8 @@ void LAMMPS::print_config(FILE *fp) sizeof(smallint)*8, sizeof(imageint)*8, sizeof(tagint)*8, sizeof(bigint)*8); + if (Info::has_gzip_support()) fmt::print(fp,"\n{}\n",platform::compress_info()); + fputs("\nInstalled packages:\n\n",fp); for (int i = 0; nullptr != (pkg = installed_packages[i]); ++i) { ncword = strlen(pkg); diff --git a/src/library.cpp b/src/library.cpp index ed208413e6..a27da0d478 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1689,9 +1689,8 @@ void *lammps_extract_compute(void *handle, const char *id, int style, int type) BEGIN_CAPTURE { - int icompute = lmp->modify->find_compute(id); - if (icompute < 0) return nullptr; - Compute *compute = lmp->modify->compute[icompute]; + auto compute = lmp->modify->get_compute_by_id(id); + if (!compute) return nullptr; if (style == LMP_STYLE_GLOBAL) { if (type == LMP_TYPE_SCALAR) { @@ -1876,9 +1875,8 @@ void *lammps_extract_fix(void *handle, const char *id, int style, int type, BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) return nullptr; - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) return nullptr; if (style == LMP_STYLE_GLOBAL) { if (type == LMP_TYPE_SCALAR) { @@ -2868,10 +2866,9 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) BEGIN_CAPTURE { #if defined(LAMMPS_BIGBIG) - lmp->error->all(FLERR,"Library function lammps_gather" - " not compatible with -DLAMMPS_BIGBIG"); + lmp->error->all(FLERR,"Library function lammps_gather not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,offset,fcid,ltype,icol; + int i,j,offset,ltype; // error if tags are not defined or not consecutive @@ -2892,76 +2889,72 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_gather: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) - lmp->error->all(FLERR,"lammps_gather:" - " fix not computed at compatible time"); + lmp->error->all(FLERR,"lammps_gather: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_gather: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: unknown property/atom id"); return; @@ -2972,23 +2965,23 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom type"); return; } - if (count == 1 && icol != 0) { + if ((count == 1) && (icol != 0)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom count"); return; } - if (count > 1 && icol != count) { + if ((count > 1) && (icol != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3111,7 +3104,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d lmp->error->all(FLERR,"Library function lammps_gather_concat" " not compatible with -DLAMMPS_BIGBIG"); #else - int i,offset,fcid,ltype,icol; + int i,offset,ltype; // error if tags are not defined or not consecutive @@ -3131,70 +3124,71 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) lmp->error->all(FLERR,"lammps_gather_concat: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom per-atom vector or array if ((vptr==nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: unknown property/atom id"); return; @@ -3205,23 +3199,23 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom type"); return; } - if (count == 1 && icol != 0) { + if ((count == 1) && (icol != 0)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } - if (count > 1 && icol != count) { + if ((count > 1) && (icol != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3364,7 +3358,7 @@ void lammps_gather_subset(void *handle, char *name, lmp->error->all(FLERR,"Library function lammps_gather_subset() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; tagint id; // error if tags are not defined or not consecutive @@ -3384,71 +3378,70 @@ void lammps_gather_subset(void *handle, char *name, if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather_subset: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for fix"); return; } - if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { + if (lmp->update->ntimestep % fix->peratom_freq) { if (lmp->comm->me == 0) lmp->error->all(FLERR,"lammps_gather_subset: fix not computed at compatible time"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: unknown property/atom id"); return; @@ -3471,11 +3464,11 @@ void lammps_gather_subset(void *handle, char *name, } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3611,7 +3604,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) lmp->error->all(FLERR,"Library function lammps_scatter() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; // error if tags are not defined or not consecutive or no atom map // NOTE: test that name = image or ids is not a 64-bit int in code? @@ -3634,70 +3627,66 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_scatter: count != values peratom for fix"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_scatter: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: unknown property/atom id"); return; @@ -3720,11 +3709,11 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -3833,7 +3822,7 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, lmp->error->all(FLERR,"Library function lammps_scatter_subset() " "is not compatible with -DLAMMPS_BIGBIG"); #else - int i,j,m,offset,fcid,ltype,icol; + int i,j,m,offset,ltype; tagint id; // error if tags are not defined or no atom map @@ -3855,70 +3844,66 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, if (vptr==nullptr && utils::strmatch(name,"^f_")) { - fcid = lmp->modify->find_fix(&name[2]); - if (fcid < 0) { + auto fix = lmp->modify->get_fix_by_id(&name[2]); + if (!fix) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown fix id"); return; } - if (lmp->modify->fix[fcid]->peratom_flag == 0) { + if (fix->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter_subset: fix does not return peratom data"); return; } - if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { + if ((count > 1) && (fix->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_scatter_subset: count != values peratom for fix"); return; } - if (count==1) vptr = (void *) lmp->modify->fix[fcid]->vector_atom; - else vptr = (void *) lmp->modify->fix[fcid]->array_atom; + if (count==1) vptr = (void *) fix->vector_atom; + else vptr = (void *) fix->array_atom; } // compute if (vptr==nullptr && utils::strmatch(name,"^c_")) { - fcid = lmp->modify->find_compute(&name[2]); - if (fcid < 0) { + auto compute = lmp->modify->get_compute_by_id(&name[2]); + if (!compute) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown compute id"); return; } - if (lmp->modify->compute[fcid]->peratom_flag == 0) { + if (compute->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_scatter_subset: compute does not return peratom data"); return; } - if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { + if ((count > 1) && (compute->size_peratom_cols != count)) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_scatter_subset: count != values peratom for compute"); return; } - if (lmp->modify->compute[fcid]->invoked_peratom != lmp->update->ntimestep) - lmp->modify->compute[fcid]->compute_peratom(); + if (compute->invoked_peratom != lmp->update->ntimestep) + compute->compute_peratom(); - if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; - else vptr = (void *) lmp->modify->compute[fcid]->array_atom; + if (count==1) vptr = (void *) compute->vector_atom; + else vptr = (void *) compute->array_atom; } // custom fix property/atom vector or array if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if (utils::strmatch(name,"^[id]_")) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); - else fcid = lmp->atom->find_custom(&name[3],ltype,icol); + int idx,icol; + if (utils::strmatch(name,"^[id]_")) idx = lmp->atom->find_custom(&name[2],ltype,icol); + else idx = lmp->atom->find_custom(&name[3],ltype,icol); - if (fcid < 0) { + if (idx < 0) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: unknown property/atom id"); return; @@ -3941,11 +3926,11 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[idx]; + else vptr = (void *) lmp->atom->dvector[idx]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[idx]; + else vptr = (void *) lmp->atom->darray[idx]; } } @@ -4242,10 +4227,9 @@ int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int n int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; - const int ifix = lmp->modify->find_fix(id); - if (ifix < 0) return -1; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) return -1; - Fix *fix = lmp->modify->fix[ifix]; // find neigh list for (int i = 0; i < lmp->neighbor->nlist; i++) { NeighList *list = lmp->neighbor->lists[i]; @@ -4272,10 +4256,9 @@ int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) { int lammps_find_compute_neighlist(void* handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; - const int icompute = lmp->modify->find_compute(id); - if (icompute < 0) return -1; + auto compute = lmp->modify->get_compute_by_id(id); + if (!compute) return -1; - Compute *compute = lmp->modify->compute[icompute]; // find neigh list for (int i = 0; i < lmp->neighbor->nlist; i++) { NeighList * list = lmp->neighbor->lists[i]; @@ -5089,11 +5072,8 @@ void lammps_set_fix_external_callback(void *handle, const char *id, FixExternalF BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Cannot find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Cannot find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style 'external'", id); @@ -5153,16 +5133,14 @@ double **lammps_fix_external_get_force(void *handle, const char *id) BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); - fexternal = (double **)fix->extract("fexternal",ifix); + int tmp; + fexternal = (double **)fix->extract("fexternal",tmp); } END_CAPTURE return fexternal; @@ -5202,11 +5180,8 @@ void lammps_fix_external_set_energy_global(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5253,11 +5228,8 @@ void lammps_fix_external_set_virial_global(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5304,11 +5276,8 @@ void lammps_fix_external_set_energy_peratom(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5358,11 +5327,8 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5405,11 +5371,8 @@ void lammps_fix_external_set_vector_length(void *handle, const char *id, int len BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); @@ -5462,11 +5425,8 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl BEGIN_CAPTURE { - int ifix = lmp->modify->find_fix(id); - if (ifix < 0) - lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); - - Fix *fix = lmp->modify->fix[ifix]; + auto fix = lmp->modify->get_fix_by_id(id); + if (!fix) lmp->error->all(FLERR,"Can not find fix with ID '{}'!", id); if (strcmp("external",fix->style) != 0) lmp->error->all(FLERR,"Fix '{}' is not of style external!", id); diff --git a/src/min.cpp b/src/min.cpp index 4780cf31eb..0c71607bd8 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -157,8 +157,7 @@ void Min::init() // detect if fix omp is present for clearing force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() @@ -230,9 +229,8 @@ void Min::setup(int flag) // compute for potential energy - int id = modify->find_compute("thermo_pe"); - if (id < 0) error->all(FLERR,"Minimization could not find thermo_pe compute"); - pe_compute = modify->compute[id]; + pe_compute = modify->get_compute_by_id("thermo_pe"); + if (!pe_compute) error->all(FLERR,"Minimization could not find thermo_pe compute"); // style-specific setup does two tasks // setup extra global dof vectors diff --git a/src/min_linesearch.cpp b/src/min_linesearch.cpp index a5d0aa326c..c4c10d8a1f 100644 --- a/src/min_linesearch.cpp +++ b/src/min_linesearch.cpp @@ -253,7 +253,7 @@ int MinLineSearch::linemin_backtrack(double eoriginal, double &alpha) // backtrack with alpha until energy decrease is sufficient - while (1) { + while (true) { ecurrent = alpha_step(alpha,1); // if energy change is better than ideal, exit with success @@ -412,7 +412,7 @@ int MinLineSearch::linemin_quadratic(double eoriginal, double &alpha) // etmp-eoriginal+alphatmp*fdothall); // alpha_step(0.0,1); - while (1) { + while (true) { ecurrent = alpha_step(alpha,1); // compute new fh, alpha, delfh @@ -708,7 +708,7 @@ int MinLineSearch::linemin_forcezero(double eoriginal, double &alpha) // main linesearch loop - while (1) { + while (true) { backtrack = false; fhPrev = fhCurr; engPrev = engCurr; diff --git a/src/modify.cpp b/src/modify.cpp index 89a26025af..2f7abe27fa 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -807,9 +807,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // since some fixes access domain settings in their constructor // nullptr must be last entry in this list - const char *exceptions[] = - {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", - "deprecated", "STORE/KIM", nullptr}; + const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", + "deprecated", "STORE/KIM", nullptr}; if (domain->box_exist == 0) { int m; @@ -822,7 +821,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // check group ID int igroup = group->find(arg[1]); - if (igroup == -1) error->all(FLERR,"Could not find fix group ID"); + if (igroup == -1) error->all(FLERR,"Could not find fix group ID {}", arg[1]); // if fix ID exists: // set newflag = 0 so create new fix in same location in fix list @@ -856,8 +855,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (estyle == fix[ifix]->style) match = 1; } } - if (!match) - error->all(FLERR,"Replacing a fix, but new style != old style"); + if (!match) error->all(FLERR,"Replacing a fix, but new style != old style"); if (fix[ifix]->igroup != igroup && comm->me == 0) error->warning(FLERR,"Replacing a fix, but new group != old group"); @@ -907,9 +905,12 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (fix[ifix] == nullptr) error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp)); - // increment nfix (if new) + // increment nfix and update fix_list vector (if new) - if (newflag) nfix++; + if (newflag) { + nfix++; + fix_list = std::vector(fix, fix+nfix); + } // post_constructor() can call virtual methods in parent or child // which would otherwise not yet be visible in child class @@ -983,25 +984,24 @@ Fix *Modify::add_fix(const std::string &fixcmd, int trysuffix) Fix *Modify::replace_fix(const char *replaceID, int narg, char **arg, int trysuffix) { - int ifix = find_fix(replaceID); - if (ifix < 0) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID); + auto oldfix = get_fix_by_id(replaceID); + if (!oldfix) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID); // change ID, igroup, style of fix being replaced to match new fix // requires some error checking on arguments for new fix if (narg < 3) error->all(FLERR,"Illegal replace_fix invocation"); - int jfix = find_fix(arg[0]); - if (jfix >= 0) error->all(FLERR,"Replace_fix ID is already in use"); + if (get_fix_by_id(arg[0])) error->all(FLERR,"Replace_fix ID {} is already in use",arg[0]); - delete [] fix[ifix]->id; - fix[ifix]->id = utils::strdup(arg[0]); + delete[] oldfix->id; + oldfix->id = utils::strdup(arg[0]); int jgroup = group->find(arg[1]); - if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID"); - fix[ifix]->igroup = jgroup; + if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID {}", arg[1]); + oldfix->igroup = jgroup; - delete [] fix[ifix]->style; - fix[ifix]->style = utils::strdup(arg[2]); + delete[] oldfix->style; + oldfix->style = utils::strdup(arg[2]); // invoke add_fix // it will find and overwrite the replaceID fix @@ -1047,7 +1047,7 @@ void Modify::modify_fix(int narg, char **arg) int ifix; for (ifix = 0; ifix < nfix; ifix++) if (strcmp(arg[0],fix[ifix]->id) == 0) break; - if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID"); + if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID {}", arg[0]); fix[ifix]->modify_params(narg-1,&arg[1]); } @@ -1060,7 +1060,7 @@ void Modify::modify_fix(int narg, char **arg) void Modify::delete_fix(const std::string &id) { int ifix = find_fix(id); - if (ifix < 0) error->all(FLERR,"Could not find fix ID to delete"); + if (ifix < 0) error->all(FLERR,"Could not find fix ID {} to delete", id); delete_fix(ifix); } @@ -1076,6 +1076,7 @@ void Modify::delete_fix(int ifix) for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i]; for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i]; nfix--; + fix_list = std::vector(fix, fix+nfix); } /* ---------------------------------------------------------------------- @@ -1092,15 +1093,42 @@ int Modify::find_fix(const std::string &id) } /* ---------------------------------------------------------------------- - find a fix by style - return index of fix or -1 if not found + look up pointer to Fix class by fix-ID + return null pointer if ID not found ------------------------------------------------------------------------- */ -int Modify::find_fix_by_style(const char *style) +Fix *Modify::get_fix_by_id(const std::string &id) const { + if (id.empty()) return nullptr; for (int ifix = 0; ifix < nfix; ifix++) - if (utils::strmatch(fix[ifix]->style,style)) return ifix; - return -1; + if (id == fix[ifix]->id) return fix[ifix]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointer to fixes by fix style name + return vector of matching pointers +------------------------------------------------------------------------- */ + +const std::vector Modify::get_fix_by_style(const std::string &style) const +{ + std::vector matches; + if (style.empty()) return matches; + + for (int ifix = 0; ifix < nfix; ifix++) + if (utils::strmatch(fix[ifix]->style,style)) matches.push_back(fix[ifix]); + + return matches; +} + +/* ---------------------------------------------------------------------- + return list of fixes as vector +------------------------------------------------------------------------- */ + +const std::vector &Modify::get_fix_list() +{ + fix_list = std::vector(fix, fix+nfix); + return fix_list; } /* ---------------------------------------------------------------------- @@ -1225,8 +1253,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) if (ncompute == maxcompute) { maxcompute += DELTA; - compute = (Compute **) - memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); + compute = (Compute **) memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); } // create the Compute @@ -1264,6 +1291,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) if (compute[ncompute] == nullptr) error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp)); + compute_list = std::vector(compute, compute+ncompute+1); return compute[ncompute++]; } @@ -1307,7 +1335,7 @@ void Modify::modify_compute(int narg, char **arg) for (icompute = 0; icompute < ncompute; icompute++) if (strcmp(arg[0],compute[icompute]->id) == 0) break; if (icompute == ncompute) - error->all(FLERR,"Could not find compute_modify ID"); + error->all(FLERR,"Could not find compute_modify ID {}", arg[0]); compute[icompute]->modify_params(narg-1,&arg[1]); } @@ -1319,7 +1347,7 @@ void Modify::modify_compute(int narg, char **arg) void Modify::delete_compute(const std::string &id) { int icompute = find_compute(id); - if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete"); + if (icompute < 0) error->all(FLERR,"Could not find compute ID {} to delete", id); delete_compute(icompute); } @@ -1332,6 +1360,7 @@ void Modify::delete_compute(int icompute) delete compute[icompute]; for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i]; ncompute--; + compute_list = std::vector(compute, compute+ncompute); } /* ---------------------------------------------------------------------- @@ -1348,15 +1377,42 @@ int Modify::find_compute(const std::string &id) } /* ---------------------------------------------------------------------- - find a compute by style - return index of compute or -1 if not found + look up pointer to Compute class by compute-ID + return null pointer if ID not found ------------------------------------------------------------------------- */ -int Modify::find_compute_by_style(const char *style) +Compute *Modify::get_compute_by_id(const std::string &id) const { + if (id.empty()) return nullptr; for (int icompute = 0; icompute < ncompute; icompute++) - if (utils::strmatch(compute[icompute]->style,style)) return icompute; - return -1; + if (id == compute[icompute]->id) return compute[icompute]; + return nullptr; +} + +/* ---------------------------------------------------------------------- + look up pointers to computes by compute style name + return vector with matching pointers +------------------------------------------------------------------------- */ + +const std::vector Modify::get_compute_by_style(const std::string &style) const +{ + std::vector matches; + if (style.empty()) return matches; + + for (int icompute = 0; icompute < ncompute; icompute++) + if (utils::strmatch(compute[icompute]->style,style)) matches.push_back(compute[icompute]); + + return matches; +} + +/* ---------------------------------------------------------------------- + return vector with Computes +------------------------------------------------------------------------- */ + +const std::vector &Modify::get_compute_list() +{ + compute_list = std::vector(compute, compute+ncompute); + return compute_list; } /* ---------------------------------------------------------------------- diff --git a/src/modify.h b/src/modify.h index 9446f285e7..c4f8c2ef02 100644 --- a/src/modify.h +++ b/src/modify.h @@ -17,6 +17,7 @@ #include "pointers.h" #include +#include namespace LAMMPS_NS { @@ -107,16 +108,28 @@ class Modify : protected Pointers { void modify_fix(int, char **); void delete_fix(const std::string &); void delete_fix(int); + + // deprecated API int find_fix(const std::string &); - int find_fix_by_style(const char *); + // new API + Fix *get_fix_by_id(const std::string &) const; + Fix *get_fix_by_index(int idx) const { return fix[idx]; } + const std::vector get_fix_by_style(const std::string &) const; + const std::vector &get_fix_list(); Compute *add_compute(int, char **, int trysuffix = 1); Compute *add_compute(const std::string &, int trysuffix = 1); void modify_compute(int, char **); void delete_compute(const std::string &); void delete_compute(int); + + // deprecated API int find_compute(const std::string &); - int find_compute_by_style(const char *); + // new API + Compute *get_compute_by_id(const std::string &) const; + Compute *get_compute_by_index(int idx) const { return compute[idx]; } + const std::vector get_compute_by_style(const std::string &) const; + const std::vector &get_compute_list(); void clearstep_compute(); void addstep_compute(bigint); @@ -165,6 +178,10 @@ class Modify : protected Pointers { int index_permanent; // fix/compute index returned to library call + // vectors to be used for new-API accessors as wrapper + std::vectorfix_list; + std::vectorcompute_list; + void list_init(int, int &, int *&); void list_init_end_of_step(int, int &, int *&); void list_init_energy_couple(int &, int *&); diff --git a/src/molecule.cpp b/src/molecule.cpp index 2c9b03337d..40ca218ecc 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -412,7 +412,7 @@ void Molecule::read(int flag) // skip blank lines or lines that start with "#" // stop when read an unrecognized line - while (1) { + while (true) { readline(line); diff --git a/src/platform.cpp b/src/platform.cpp index 5c18949482..708a42be8a 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -231,7 +231,7 @@ std::string platform::os_info() if (platform::file_is_readable("/etc/os-release")) { try { TextFileReader reader("/etc/os-release",""); - while (1) { + while (true) { auto words = reader.next_values(0,"="); if ((words.count() > 1) && (words.next_string() == "PRETTY_NAME")) { buf += " " + utils::trim(words.next_string()); @@ -418,6 +418,24 @@ std::string platform::mpi_info(int &major, int &minor) return {version}; } +/* ---------------------------------------------------------------------- + collect available compression tool info +------------------------------------------------------------------------- */ + +std::string platform::compress_info() +{ + std::string buf = "Available compression formats:\n\n"; + bool none_found = true; + for (const auto &cmpi : compress_styles) { + if (cmpi.style == ::compress_info::NONE) continue; + if (find_exe_path(cmpi.command).size()) { + none_found = false; + buf += fmt::format("Extension: .{:6} Command: {}\n", cmpi.extension, cmpi.command); + } + } + if (none_found) buf += "None\n"; + return buf; +} /* ---------------------------------------------------------------------- set environment variable ------------------------------------------------------------------------- */ @@ -948,7 +966,7 @@ bool platform::file_is_readable(const std::string &path) bool platform::has_compress_extension(const std::string &file) { - return find_compress_type(file).style != compress_info::NONE; + return find_compress_type(file).style != ::compress_info::NONE; } /* ---------------------------------------------------------------------- @@ -961,7 +979,7 @@ FILE *platform::compressed_read(const std::string &file) #if defined(LAMMPS_GZIP) auto compress = find_compress_type(file); - if (compress.style == compress_info::NONE) return nullptr; + if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) // put quotes around file name so that they may contain blanks @@ -980,7 +998,7 @@ FILE *platform::compressed_write(const std::string &file) #if defined(LAMMPS_GZIP) auto compress = find_compress_type(file); - if (compress.style == compress_info::NONE) return nullptr; + if (compress.style == ::compress_info::NONE) return nullptr; if (find_exe_path(compress.command).size()) // put quotes around file name so that they may contain blanks diff --git a/src/platform.h b/src/platform.h index eb14b403aa..c079fd2cd1 100644 --- a/src/platform.h +++ b/src/platform.h @@ -109,6 +109,15 @@ namespace platform { std::string mpi_info(int &major, int &minor); + /*! Return string with list of available compression types and executables + * + * This function tests which of the supported compression executables + * are available for reading or writing compressed files where supported. + * + * \return string with list of available compression tools */ + + std::string compress_info(); + /*! Add variable to the environment * * \param vardef variable name or variable definition (NAME=value) diff --git a/src/procmap.cpp b/src/procmap.cpp index ed3839fe7b..3fc8a2263e 100644 --- a/src/procmap.cpp +++ b/src/procmap.cpp @@ -294,7 +294,7 @@ void ProcMap::custom_grid(char *cfile, int nprocs, char *ptr; if (!fgets(line,MAXLINE,fp)) error->one(FLERR,"Unexpected end of custom file"); - while (1) { + while (true) { if ((ptr = strchr(line,'#'))) *ptr = '\0'; if (strspn(line," \t\n\r") != strlen(line)) break; if (!fgets(line,MAXLINE,fp)) diff --git a/src/rcb.cpp b/src/rcb.cpp index b4d1c135ec..92eafebc28 100644 --- a/src/rcb.cpp +++ b/src/rcb.cpp @@ -285,7 +285,7 @@ void RCB::compute(int dimension, int n, double **x, double *wt, first_iteration = 1; indexlo = indexhi = 0; - while (1) { + while (true) { // choose bisector value // use old value on 1st iteration if old cut dimension is the same @@ -814,7 +814,7 @@ void RCB::compute_old(int dimension, int n, double **x, double *wt, first_iteration = 1; indexlo = indexhi = 0; - while (1) { + while (true) { // choose bisector value // use old value on 1st iteration if old cut dimension is the same diff --git a/src/read_data.cpp b/src/read_data.cpp index edbfc16696..7e5d49e65c 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -39,6 +39,8 @@ #include #include +#include +#include using namespace LAMMPS_NS; @@ -49,9 +51,27 @@ static constexpr int DELTA = 4; // must be 2 or larger static constexpr int MAXBODY = 32; // max # of lines in one body // customize for new sections -// change when add to header::section_keywords -static constexpr int NSECTIONS = 25; +static std::unordered_set section_keywords = { + "Atoms", "Velocities", "Ellipsoids", "Lines", "Triangles", "Bodies", + "Bonds", "Angles", "Dihedrals", "Impropers", + "Masses", "Pair Coeffs", "PairIJ Coeffs", "Bond Coeffs", "Angle Coeffs", + "Dihedral Coeffs", "Improper Coeffs", + "BondBond Coeffs", "BondAngle Coeffs", "MiddleBondTorsion Coeffs", + "EndBondTorsion Coeffs", "AngleTorsion Coeffs", + "AngleAngleTorsion Coeffs", "BondBond13 Coeffs", "AngleAngle Coeffs" +}; + +// function to check whether a string is a known data section name +// made a static class member, so it can be called from other classes + +bool ReadData::is_data_section(const std::string &keyword) +{ + return section_keywords.count(keyword) > 0; +} + + +// clang-format off enum{NONE,APPEND,VALUE,MERGE}; // pair style suffixes to ignore @@ -266,18 +286,19 @@ void ReadData::command(int narg, char **arg) if (iarg+4 > narg) error->all(FLERR,"Illegal read_data command"); memory->grow(fix_index,nfix+1,"read_data:fix_index"); - fix_header = (char **) - memory->srealloc(fix_header,(nfix+1)*sizeof(char *), - "read_data:fix_header"); - fix_section = (char **) - memory->srealloc(fix_section,(nfix+1)*sizeof(char *), - "read_data:fix_section"); + fix_header = (char **) memory->srealloc(fix_header,(nfix+1)*sizeof(char *), + "read_data:fix_header"); + fix_section = (char **) memory->srealloc(fix_section,(nfix+1)*sizeof(char *), + "read_data:fix_section"); + if (is_data_section(arg[iarg+3])) + error->all(FLERR,"Custom data section name {} for fix {} collides with existing " + "data section",arg[iarg+3],arg[iarg+1]); fix_index[nfix] = modify->find_fix(arg[iarg+1]); - if (fix_index[nfix] < 0) - error->all(FLERR,"Fix ID for read_data does not exist"); + if (fix_index[nfix] < 0) error->all(FLERR,"Fix ID for read_data does not exist"); if (strcmp(arg[iarg+2],"NULL") == 0) fix_header[nfix] = nullptr; else fix_header[nfix] = utils::strdup(arg[iarg+2]); - fix_section[nfix] = utils::strdup(arg[iarg+3]); + if (strcmp(arg[iarg+3],"NULL") == 0) fix_section[nfix] = utils::strdup(arg[iarg+1]); + else fix_section[nfix] = utils::strdup(arg[iarg+3]); nfix++; iarg += 4; @@ -430,7 +451,7 @@ void ReadData::command(int narg, char **arg) nlocal_previous = atom->nlocal; int firstpass = 1; - while (1) { + while (true) { // open file on proc 0 @@ -521,6 +542,7 @@ void ReadData::command(int narg, char **arg) "from currently defined atom style"); atoms(); } else skip_lines(natoms); + } else if (strcmp(keyword,"Velocities") == 0) { if (atomflag == 0) error->all(FLERR,"Must read Atoms before Velocities"); @@ -529,52 +551,50 @@ void ReadData::command(int narg, char **arg) } else if (strcmp(keyword,"Bonds") == 0) { topoflag = bondflag = 1; - if (nbonds == 0) - error->all(FLERR,"Invalid data file section: Bonds"); + if (nbonds == 0) error->all(FLERR,"Invalid data file section: Bonds"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Bonds"); bonds(firstpass); + } else if (strcmp(keyword,"Angles") == 0) { topoflag = angleflag = 1; - if (nangles == 0) - error->all(FLERR,"Invalid data file section: Angles"); + if (nangles == 0) error->all(FLERR,"Invalid data file section: Angles"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Angles"); angles(firstpass); + } else if (strcmp(keyword,"Dihedrals") == 0) { topoflag = dihedralflag = 1; - if (ndihedrals == 0) - error->all(FLERR,"Invalid data file section: Dihedrals"); + if (ndihedrals == 0) error->all(FLERR,"Invalid data file section: Dihedrals"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Dihedrals"); dihedrals(firstpass); + } else if (strcmp(keyword,"Impropers") == 0) { topoflag = improperflag = 1; - if (nimpropers == 0) - error->all(FLERR,"Invalid data file section: Impropers"); + if (nimpropers == 0) error->all(FLERR,"Invalid data file section: Impropers"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Impropers"); impropers(firstpass); } else if (strcmp(keyword,"Ellipsoids") == 0) { ellipsoidflag = 1; - if (!avec_ellipsoid) - error->all(FLERR,"Invalid data file section: Ellipsoids"); - if (atomflag == 0) - error->all(FLERR,"Must read Atoms before Ellipsoids"); + if (!avec_ellipsoid) error->all(FLERR,"Invalid data file section: Ellipsoids"); + if (atomflag == 0) error->all(FLERR,"Must read Atoms before Ellipsoids"); if (firstpass) bonus(nellipsoids,(AtomVec *) avec_ellipsoid,"ellipsoids"); else skip_lines(nellipsoids); + } else if (strcmp(keyword,"Lines") == 0) { lineflag = 1; - if (!avec_line) - error->all(FLERR,"Invalid data file section: Lines"); + if (!avec_line) error->all(FLERR,"Invalid data file section: Lines"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Lines"); if (firstpass) bonus(nlines,(AtomVec *) avec_line,"lines"); else skip_lines(nlines); + } else if (strcmp(keyword,"Triangles") == 0) { triflag = 1; - if (!avec_tri) - error->all(FLERR,"Invalid data file section: Triangles"); + if (!avec_tri) error->all(FLERR,"Invalid data file section: Triangles"); if (atomflag == 0) error->all(FLERR,"Must read Atoms before Triangles"); if (firstpass) bonus(ntris,(AtomVec *) avec_tri,"triangles"); else skip_lines(ntris); + } else if (strcmp(keyword,"Bodies") == 0) { bodyflag = 1; if (!avec_body) @@ -655,6 +675,7 @@ void ReadData::command(int narg, char **arg) error->all(FLERR,"Must define angle_style before BondBond Coeffs"); if (firstpass) anglecoeffs(1); else skip_lines(nangletypes); + } else if (strcmp(keyword,"BondAngle Coeffs") == 0) { if (atom->avec->angles_allow == 0) error->all(FLERR,"Invalid data file section: BondAngle Coeffs"); @@ -665,46 +686,41 @@ void ReadData::command(int narg, char **arg) } else if (strcmp(keyword,"MiddleBondTorsion Coeffs") == 0) { if (atom->avec->dihedrals_allow == 0) - error->all(FLERR, - "Invalid data file section: MiddleBondTorsion Coeffs"); + error->all(FLERR,"Invalid data file section: MiddleBondTorsion Coeffs"); if (force->dihedral == nullptr) - error->all(FLERR, - "Must define dihedral_style before " - "MiddleBondTorsion Coeffs"); + error->all(FLERR,"Must define dihedral_style before MiddleBondTorsion Coeffs"); if (firstpass) dihedralcoeffs(1); else skip_lines(ndihedraltypes); + } else if (strcmp(keyword,"EndBondTorsion Coeffs") == 0) { if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Invalid data file section: EndBondTorsion Coeffs"); if (force->dihedral == nullptr) - error->all(FLERR, - "Must define dihedral_style before EndBondTorsion Coeffs"); + error->all(FLERR,"Must define dihedral_style before EndBondTorsion Coeffs"); if (firstpass) dihedralcoeffs(2); else skip_lines(ndihedraltypes); + } else if (strcmp(keyword,"AngleTorsion Coeffs") == 0) { if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Invalid data file section: AngleTorsion Coeffs"); if (force->dihedral == nullptr) - error->all(FLERR, - "Must define dihedral_style before AngleTorsion Coeffs"); + error->all(FLERR,"Must define dihedral_style before AngleTorsion Coeffs"); if (firstpass) dihedralcoeffs(3); else skip_lines(ndihedraltypes); + } else if (strcmp(keyword,"AngleAngleTorsion Coeffs") == 0) { if (atom->avec->dihedrals_allow == 0) - error->all(FLERR, - "Invalid data file section: AngleAngleTorsion Coeffs"); + error->all(FLERR,"Invalid data file section: AngleAngleTorsion Coeffs"); if (force->dihedral == nullptr) - error->all(FLERR, - "Must define dihedral_style before " - "AngleAngleTorsion Coeffs"); + error->all(FLERR,"Must define dihedral_style before AngleAngleTorsion Coeffs"); if (firstpass) dihedralcoeffs(4); else skip_lines(ndihedraltypes); + } else if (strcmp(keyword,"BondBond13 Coeffs") == 0) { if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Invalid data file section: BondBond13 Coeffs"); if (force->dihedral == nullptr) - error->all(FLERR, - "Must define dihedral_style before BondBond13 Coeffs"); + error->all(FLERR,"Must define dihedral_style before BondBond13 Coeffs"); if (firstpass) dihedralcoeffs(5); else skip_lines(ndihedraltypes); @@ -712,8 +728,7 @@ void ReadData::command(int narg, char **arg) if (atom->avec->impropers_allow == 0) error->all(FLERR,"Invalid data file section: AngleAngle Coeffs"); if (force->improper == nullptr) - error->all(FLERR, - "Must define improper_style before AngleAngle Coeffs"); + error->all(FLERR,"Must define improper_style before AngleAngle Coeffs"); if (firstpass) impropercoeffs(1); else skip_lines(nimpropertypes); @@ -724,8 +739,7 @@ void ReadData::command(int narg, char **arg) for (i = 0; i < nfix; i++) if (strcmp(keyword,fix_section[i]) == 0) { if (firstpass) fix(fix_index[i],keyword); - else skip_lines(modify->fix[fix_index[i]]-> - read_data_skip_lines(keyword)); + else skip_lines(modify->fix[fix_index[i]]->read_data_skip_lines(keyword)); parse_keyword(0); break; } @@ -882,8 +896,7 @@ void ReadData::command(int narg, char **arg) bigint nblocal = atom->nlocal; MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (natoms != atom->natoms) - error->all(FLERR, - "Read_data shrink wrap did not assign all atoms correctly"); + error->all(FLERR,"Read_data shrink wrap did not assign all atoms correctly"); } // restore old styles, when reading with nocoeff flag given @@ -947,17 +960,6 @@ void ReadData::header(int firstpass) atom->nimpropertypes = extra_improper_types; } - // customize for new sections - - const char *section_keywords[NSECTIONS] = - {"Atoms","Velocities","Ellipsoids","Lines","Triangles","Bodies", - "Bonds","Angles","Dihedrals","Impropers", - "Masses","Pair Coeffs","PairIJ Coeffs","Bond Coeffs","Angle Coeffs", - "Dihedral Coeffs","Improper Coeffs", - "BondBond Coeffs","BondAngle Coeffs","MiddleBondTorsion Coeffs", - "EndBondTorsion Coeffs","AngleTorsion Coeffs", - "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs"}; - // skip 1st line of file if (me == 0) { @@ -965,7 +967,7 @@ void ReadData::header(int firstpass) if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); } - while (1) { + while (true) { // read a line and bcast length @@ -1186,9 +1188,7 @@ void ReadData::header(int firstpass) // check that exiting string is a valid section keyword parse_keyword(1); - for (n = 0; n < NSECTIONS; n++) - if (strcmp(keyword,section_keywords[n]) == 0) break; - if (n == NSECTIONS) + if (!is_data_section(keyword)) error->all(FLERR,"Unknown identifier in data file: {}",keyword); // error checks on header values @@ -1730,8 +1730,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr) error->one(FLERR,"Too many values in body lines in data file"); if (onebody+1 > MAXBODY) - error->one(FLERR, - "Too many lines in one body in data file - boost MAXBODY"); + error->one(FLERR,"Too many lines in one body in data file - boost MAXBODY"); nchunk++; nline += onebody+1; diff --git a/src/read_data.h b/src/read_data.h index 3374f48be0..090e70484b 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -29,6 +29,7 @@ class ReadData : public Command { ReadData(class LAMMPS *); ~ReadData(); void command(int, char **); + static bool is_data_section(const std::string &); private: int me, compressed; diff --git a/src/read_dump.cpp b/src/read_dump.cpp index c09bd38c87..71d302c4f1 100644 --- a/src/read_dump.cpp +++ b/src/read_dump.cpp @@ -233,7 +233,7 @@ void ReadDump::setup_reader(int narg, char **arg) // create Nreader reader classes per reader // match readerstyle to options in style_reader.h - if (0) { + if (false) { return; // dummy line to enable else-if macro expansion #define READER_CLASS @@ -289,7 +289,7 @@ bigint ReadDump::seek(bigint nrequest, int exact) readers[0]->open_file(multiname.c_str()); } else readers[0]->open_file(files[ifile]); - while (1) { + while (true) { eofflag = readers[0]->read_time(ntimestep); if (eofflag) break; if (ntimestep >= nrequest) break; @@ -333,7 +333,7 @@ bigint ReadDump::seek(bigint nrequest, int exact) readers[i]->open_file(multiname.c_str()); bigint step; - while (1) { + while (true) { eofflag = readers[i]->read_time(step); if (eofflag) break; if (step == ntimestep) break; @@ -382,7 +382,7 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip) } else readers[0]->open_file(files[ifile]); } - while (1) { + while (true) { eofflag = readers[0]->read_time(ntimestep); if (eofflag) break; if (ntimestep > nlast) break; @@ -435,7 +435,7 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip) readers[i]->open_file(multiname.c_str()); bigint step; - while (1) { + while (true) { eofflag = readers[i]->read_time(step); if (eofflag) break; if (step == ntimestep) break; diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 0eab44baaa..f8ac14534b 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -445,8 +445,7 @@ void ReadRestart::command(int narg, char **arg) if (nextra) { memory->destroy(atom->extra); memory->create(atom->extra,atom->nmax,nextra,"atom:extra"); - int ifix = modify->find_fix("_read_restart"); - FixReadRestart *fix = (FixReadRestart *) modify->fix[ifix]; + auto fix = (FixReadRestart *) modify->get_fix_by_id("_read_restart"); int *count = fix->count; double **extra = fix->extra; double **atom_extra = atom->extra; diff --git a/src/rerun.cpp b/src/rerun.cpp index ce21fbc2b8..78b1a28cb6 100644 --- a/src/rerun.cpp +++ b/src/rerun.cpp @@ -156,7 +156,7 @@ void Rerun::command(int narg, char **arg) if (ntimestep < 0) error->all(FLERR,"Rerun dump file does not contain requested snapshot"); - while (1) { + while (true) { ndump++; rd->header(firstflag); update->reset_timestep(ntimestep); diff --git a/src/reset_mol_ids.cpp b/src/reset_mol_ids.cpp index 4c973f543f..a29ea98e18 100644 --- a/src/reset_mol_ids.cpp +++ b/src/reset_mol_ids.cpp @@ -151,24 +151,14 @@ void ResetMolIDs::create_computes(char *fixid, char *groupid) // 'fixid' allows for creating independent instances of the computes idfrag = fmt::format("{}_reset_mol_ids_FRAGMENT_ATOM",fixid); - if (singleflag) - modify->add_compute(fmt::format("{} {} fragment/atom single yes",idfrag,groupid)); - else - modify->add_compute(fmt::format("{} {} fragment/atom single no",idfrag,groupid)); + auto use_single = singleflag ? "yes" : "no"; + cfa = (ComputeFragmentAtom *) + modify->add_compute(fmt::format("{} {} fragment/atom single {}",idfrag,groupid,use_single)); idchunk = fmt::format("{}_reset_mol_ids_CHUNK_ATOM",fixid); if (compressflag) - modify->add_compute(fmt::format("{} {} chunk/atom molecule compress yes", - idchunk,groupid)); - - int icompute = modify->find_compute(idfrag); - cfa = (ComputeFragmentAtom *) modify->compute[icompute]; - - - if (compressflag) { - icompute = modify->find_compute(idchunk); - cca = (ComputeChunkAtom *) modify->compute[icompute]; - } + cca = (ComputeChunkAtom *) + modify->add_compute(fmt::format("{} {} chunk/atom molecule compress yes",idchunk,groupid)); } /* ---------------------------------------------------------------------- diff --git a/src/respa.cpp b/src/respa.cpp index 5190441994..9690105d40 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -46,23 +45,22 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : - Integrate(lmp, narg, arg), - step(nullptr), loop(nullptr), hybrid_level(nullptr), hybrid_compute(nullptr), - newton(nullptr), fix_respa(nullptr) + Integrate(lmp, narg, arg), step(nullptr), loop(nullptr), hybrid_level(nullptr), + hybrid_compute(nullptr), newton(nullptr), fix_respa(nullptr) { nhybrid_styles = 0; - if (narg < 1) error->all(FLERR,"Illegal run_style respa command"); + if (narg < 1) error->all(FLERR, "Illegal run_style respa command"); - nlevels = utils::inumeric(FLERR,arg[0],false,lmp); - if (nlevels < 1) error->all(FLERR,"Respa levels must be >= 1"); + nlevels = utils::inumeric(FLERR, arg[0], false, lmp); + if (nlevels < 1) error->all(FLERR, "Respa levels must be >= 1"); - if (narg < nlevels) error->all(FLERR,"Illegal run_style respa command"); + if (narg < nlevels) error->all(FLERR, "Illegal run_style respa command"); loop = new int[nlevels]; for (int iarg = 1; iarg < nlevels; iarg++) { - loop[iarg-1] = utils::inumeric(FLERR,arg[iarg],false,lmp); - if (loop[iarg-1] <= 0) error->all(FLERR,"Illegal run_style respa command"); + loop[iarg - 1] = utils::inumeric(FLERR, arg[iarg], false, lmp); + if (loop[iarg - 1] <= 0) error->all(FLERR, "Illegal run_style respa command"); } - loop[nlevels-1] = 1; + loop[nlevels - 1] = 1; // set level at which each force is computed // argument settings override defaults @@ -79,87 +77,86 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : int iarg = nlevels; while (iarg < narg) { - if (strcmp(arg[iarg],"bond") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_bond = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + if (strcmp(arg[iarg], "bond") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_bond = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"angle") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_angle = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "angle") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_angle = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"dihedral") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_dihedral = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "dihedral") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_dihedral = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"improper") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_improper = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "improper") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_improper = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"pair") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_pair = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "pair") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_pair = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"inner") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_inner = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - cutoff[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - cutoff[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "inner") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_inner = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + cutoff[0] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + cutoff[1] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"middle") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_middle = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - cutoff[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - cutoff[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "middle") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_middle = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + cutoff[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + cutoff[3] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"outer") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_outer = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "outer") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_outer = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"kspace") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run_style respa command"); - level_kspace = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; + } else if (strcmp(arg[iarg], "kspace") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal run_style respa command"); + level_kspace = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; iarg += 2; - } else if (strcmp(arg[iarg],"hybrid") == 0) { + } else if (strcmp(arg[iarg], "hybrid") == 0) { // the hybrid keyword requires a hybrid pair style - if (!utils::strmatch(force->pair_style,"^hybrid")) - error->all(FLERR,"Illegal run_style respa command"); + if (!utils::strmatch(force->pair_style, "^hybrid")) + error->all(FLERR, "Illegal run_style respa command"); PairHybrid *hybrid = (PairHybrid *) force->pair; nhybrid_styles = hybrid->nstyles; // each hybrid sub-style needs to be assigned to a respa level - if (iarg+nhybrid_styles > narg) - error->all(FLERR,"Illegal run_style respa command"); + if (iarg + nhybrid_styles > narg) error->all(FLERR, "Illegal run_style respa command"); hybrid_level = new int[nhybrid_styles]; hybrid_compute = new int[nhybrid_styles]; - for (int i=0; i < nhybrid_styles; ++i) { + for (int i = 0; i < nhybrid_styles; ++i) { ++iarg; - hybrid_level[i] = utils::inumeric(FLERR,arg[iarg],false,lmp)-1; + hybrid_level[i] = utils::inumeric(FLERR, arg[iarg], false, lmp) - 1; } ++iarg; - } else error->all(FLERR,"Illegal run_style respa command"); + } else + error->all(FLERR, "Illegal run_style respa command"); } // cannot specify both pair and inner/middle/outer - if (level_pair >= 0 && - (level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) - error->all(FLERR,"Cannot set both respa pair and inner/middle/outer"); + if (level_pair >= 0 && (level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) + error->all(FLERR, "Cannot set both respa pair and inner/middle/outer"); // if either inner and outer is specified, then both must be - if ((level_inner >= 0 && level_outer == -1) || - (level_outer >= 0 && level_inner == -1)) - error->all(FLERR,"Must set both respa inner and outer"); + if ((level_inner >= 0 && level_outer == -1) || (level_outer >= 0 && level_inner == -1)) + error->all(FLERR, "Must set both respa inner and outer"); // middle cannot be set without inner/outer if (level_middle >= 0 && level_inner == -1) - error->all(FLERR,"Cannot set respa middle without inner/outer"); + error->all(FLERR, "Cannot set respa middle without inner/outer"); // cannot combine hybrid with any of pair/inner/middle/outer - if ((nhybrid_styles > 0) && (level_pair >= 0 || level_inner >= 0 - || level_middle >= 0 || level_outer >= 0)) - error->all(FLERR,"Cannot set respa hybrid and " + if ((nhybrid_styles > 0) && + (level_pair >= 0 || level_inner >= 0 || level_middle >= 0 || level_outer >= 0)) + error->all(FLERR, + "Cannot set respa hybrid and " "any of pair/inner/middle/outer"); // set defaults if user did not specify level @@ -174,8 +171,7 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : if (level_dihedral == -1) level_dihedral = level_angle; if (level_improper == -1) level_improper = level_dihedral; - if (level_pair == -1 && level_inner == -1 && nhybrid_styles < 1) - level_pair = nlevels-1; + if (level_pair == -1 && level_inner == -1 && nhybrid_styles < 1) level_pair = nlevels - 1; if (level_kspace == -1 && level_pair >= 0) level_kspace = level_pair; if (level_kspace == -1 && level_pair == -1) { @@ -183,9 +179,8 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : level_kspace = level_outer; } else { int max_hybrid_level = -1; - for (int i=0; i < nhybrid_styles; ++i) { - if (max_hybrid_level < hybrid_level[i]) - max_hybrid_level = hybrid_level[i]; + for (int i = 0; i < nhybrid_styles; ++i) { + if (max_hybrid_level < hybrid_level[i]) max_hybrid_level = hybrid_level[i]; } level_kspace = max_hybrid_level; } @@ -196,59 +191,57 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : if (comm->me == 0) { std::string mesg = "Respa levels:\n"; for (int i = 0; i < nlevels; i++) { - mesg += fmt::format(" {} =",i+1); - if (level_bond == i) mesg += " bond"; - if (level_angle == i) mesg += " angle"; - if (level_dihedral == i) mesg += " dihedral"; - if (level_improper == i) mesg += " improper"; - if (level_pair == i) mesg += " pair"; - if (level_inner == i) mesg += " pair-inner"; - if (level_middle == i) mesg += " pair-middle"; - if (level_outer == i) mesg += " pair-outer"; - for (int j=0; j < nhybrid_styles; j++) - if (hybrid_level[j] == i) mesg += fmt::format(" hybrid-{}",j+1); - if (level_kspace == i) mesg += " kspace"; + mesg += fmt::format(" {} =", i + 1); + if (level_bond == i) mesg += " bond"; + if (level_angle == i) mesg += " angle"; + if (level_dihedral == i) mesg += " dihedral"; + if (level_improper == i) mesg += " improper"; + if (level_pair == i) mesg += " pair"; + if (level_inner == i) mesg += " pair-inner"; + if (level_middle == i) mesg += " pair-middle"; + if (level_outer == i) mesg += " pair-outer"; + for (int j = 0; j < nhybrid_styles; j++) + if (hybrid_level[j] == i) mesg += fmt::format(" hybrid-{}", j + 1); + if (level_kspace == i) mesg += " kspace"; mesg += "\n"; } - utils::logmesg(lmp,mesg); + utils::logmesg(lmp, mesg); } // check that levels are in correct order - if (level_angle < level_bond || level_dihedral < level_angle || - level_improper < level_dihedral) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_angle < level_bond || level_dihedral < level_angle || level_improper < level_dihedral) + error->all(FLERR, "Invalid order of forces within respa levels"); if (level_pair >= 0) { if (level_pair < level_improper || level_kspace < level_pair) - error->all(FLERR,"Invalid order of forces within respa levels"); + error->all(FLERR, "Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle == -1 && nhybrid_styles < 1) { - if (level_inner < level_improper || level_outer < level_inner || - level_kspace < level_outer) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_inner < level_improper || level_outer < level_inner || level_kspace < level_outer) + error->all(FLERR, "Invalid order of forces within respa levels"); } if (level_pair == -1 && level_middle >= 0) { - if (level_inner < level_improper || level_middle < level_inner || - level_outer < level_inner || level_kspace < level_outer) - error->all(FLERR,"Invalid order of forces within respa levels"); + if (level_inner < level_improper || level_middle < level_inner || level_outer < level_inner || + level_kspace < level_outer) + error->all(FLERR, "Invalid order of forces within respa levels"); } // warn if any levels are devoid of forces int flag = 0; for (int i = 0; i < nlevels; i++) - if (level_bond != i && level_angle != i && level_dihedral != i && - level_improper != i && level_pair != i && level_inner != i && - level_middle != i && level_outer != i && level_kspace != i) flag = 1; - if (flag && comm->me == 0) - error->warning(FLERR,"One or more respa levels compute no forces"); + if (level_bond != i && level_angle != i && level_dihedral != i && level_improper != i && + level_pair != i && level_inner != i && level_middle != i && level_outer != i && + level_kspace != i) + flag = 1; + if (flag && comm->me == 0) error->warning(FLERR, "One or more respa levels compute no forces"); // check cutoff consistency if inner/middle/outer are enabled if (level_inner >= 0 && cutoff[1] < cutoff[0]) - error->all(FLERR,"Respa inner cutoffs are invalid"); + error->all(FLERR, "Respa inner cutoffs are invalid"); if (level_middle >= 0 && (cutoff[3] < cutoff[2] || cutoff[2] < cutoff[1])) - error->all(FLERR,"Respa middle cutoffs are invalid"); + error->all(FLERR, "Respa middle cutoffs are invalid"); // set outer pair of cutoffs to inner pair if middle is not enabled @@ -275,12 +268,12 @@ Respa::Respa(LAMMPS *lmp, int narg, char **arg) : Respa::~Respa() { - delete [] loop; - delete [] newton; - delete [] step; + delete[] loop; + delete[] newton; + delete[] step; if (nhybrid_styles > 0) { - delete [] hybrid_level; - delete [] hybrid_compute; + delete[] hybrid_level; + delete[] hybrid_compute; } } @@ -295,13 +288,13 @@ void Respa::init() // warn if no fixes if (modify->nfix == 0 && comm->me == 0) - error->warning(FLERR,"No fixes defined, atoms won't move"); + error->warning(FLERR, "No fixes defined, atoms won't move"); // create fix needed for storing atom-based respa level forces // will delete it at end of run // if supported, we also store torques on a per-level basis - std::string cmd = fmt::format("RESPA all RESPA {}",nlevels); + std::string cmd = fmt::format("RESPA all RESPA {}", nlevels); if (atom->torque_flag) cmd += " torque"; fix_respa = (FixRespa *) modify->add_fix(cmd); @@ -309,7 +302,7 @@ void Respa::init() if (level_inner >= 0) if (force->pair && force->pair->respa_enable == 0) - error->all(FLERR,"Pair style does not support rRESPA inner/middle/outer"); + error->all(FLERR, "Pair style does not support rRESPA inner/middle/outer"); // virial_style = VIRIAL_PAIR (explicit) // since never computed implicitly with virial_fdotr_compute() like Verlet @@ -322,8 +315,7 @@ void Respa::init() // detect if fix omp is present and will clear force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() @@ -333,22 +325,22 @@ void Respa::init() // step[] = timestep for each level - step[nlevels-1] = update->dt; - for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) - step[ilevel] = step[ilevel+1]/loop[ilevel]; + step[nlevels - 1] = update->dt; + for (int ilevel = nlevels - 2; ilevel >= 0; ilevel--) + step[ilevel] = step[ilevel + 1] / loop[ilevel]; // set newton flag for each level for (int ilevel = 0; ilevel < nlevels; ilevel++) { newton[ilevel] = 0; if (force->newton_bond) { - if (level_bond == ilevel || level_angle == ilevel || - level_dihedral == ilevel || level_improper == ilevel) + if (level_bond == ilevel || level_angle == ilevel || level_dihedral == ilevel || + level_improper == ilevel) newton[ilevel] = 1; } if (force->newton_pair) { - if (level_pair == ilevel || level_inner == ilevel || - level_middle == ilevel || level_outer == ilevel) + if (level_pair == ilevel || level_inner == ilevel || level_middle == ilevel || + level_outer == ilevel) newton[ilevel] = 1; if (nhybrid_styles > 0) { @@ -372,23 +364,21 @@ void Respa::setup(int flag) if (comm->me == 0 && screen) { std::string mesg = "Setting up r-RESPA run ...\n"; if (flag) { - mesg += fmt::format(" Unit style : {}\n",update->unit_style); + mesg += fmt::format(" Unit style : {}\n", update->unit_style); mesg += fmt::format(" Current step : {}\n", update->ntimestep); mesg += " Time steps :"; - for (int ilevel=0; ilevel < nlevels; ++ilevel) - mesg += fmt::format(" {}:{}",ilevel+1, step[ilevel]); + for (int ilevel = 0; ilevel < nlevels; ++ilevel) + mesg += fmt::format(" {}:{}", ilevel + 1, step[ilevel]); mesg += "\n r-RESPA fixes :"; - for (int l=0; l < modify->n_post_force_respa; ++l) { - Fix *f = modify->fix[modify->list_post_force_respa[l]]; + for (int l = 0; l < modify->n_post_force_respa; ++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); + mesg += fmt::format(" {}:{}[{}]", MIN(f->respa_level + 1, nlevels), f->style, f->id); } mesg += "\n"; - fputs(mesg.c_str(),screen); + fputs(mesg.c_str(), screen); timer->print_timeout(screen); } } @@ -409,7 +399,7 @@ void Respa::setup(int flag) comm->exchange(); if (atom->sortfreq > 0) atom->sort(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); @@ -424,34 +414,26 @@ void Respa::setup(int flag) for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); - modify->setup_pre_force_respa(vflag,ilevel); + modify->setup_pre_force_respa(vflag, ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); } - if (level_pair == ilevel && pair_compute_flag) - force->pair->compute(eflag,vflag); - if (level_inner == ilevel && pair_compute_flag) - force->pair->compute_inner(); - if (level_middle == ilevel && pair_compute_flag) - force->pair->compute_middle(); - if (level_outer == ilevel && pair_compute_flag) - force->pair->compute_outer(eflag,vflag); - if (level_bond == ilevel && force->bond) - force->bond->compute(eflag,vflag); - if (level_angle == ilevel && force->angle) - force->angle->compute(eflag,vflag); - if (level_dihedral == ilevel && force->dihedral) - force->dihedral->compute(eflag,vflag); - if (level_improper == ilevel && force->improper) - force->improper->compute(eflag,vflag); + if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag, vflag); + if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); + if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); + if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag, vflag); + if (level_bond == ilevel && force->bond) force->bond->compute(eflag, vflag); + if (level_angle == ilevel && force->angle) force->angle->compute(eflag, vflag); + if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag, vflag); + if (level_improper == ilevel && force->improper) force->improper->compute(eflag, vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); - if (kspace_compute_flag) force->kspace->compute(eflag,vflag); + if (kspace_compute_flag) force->kspace->compute(eflag, vflag); } - modify->setup_pre_reverse(eflag,vflag); + modify->setup_pre_reverse(eflag, vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } @@ -485,7 +467,7 @@ void Respa::setup_minimal(int flag) if (neighbor->style) neighbor->setup_bins(); comm->exchange(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); domain->image_check(); domain->box_too_small_check(); modify->setup_pre_neighbor(); @@ -500,35 +482,27 @@ void Respa::setup_minimal(int flag) for (int ilevel = 0; ilevel < nlevels; ilevel++) { force_clear(newton[ilevel]); - modify->setup_pre_force_respa(vflag,ilevel); + modify->setup_pre_force_respa(vflag, ilevel); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); } - if (level_pair == ilevel && pair_compute_flag) - force->pair->compute(eflag,vflag); - if (level_inner == ilevel && pair_compute_flag) - force->pair->compute_inner(); - if (level_middle == ilevel && pair_compute_flag) - force->pair->compute_middle(); - if (level_outer == ilevel && pair_compute_flag) - force->pair->compute_outer(eflag,vflag); - if (level_bond == ilevel && force->bond) - force->bond->compute(eflag,vflag); - if (level_angle == ilevel && force->angle) - force->angle->compute(eflag,vflag); - if (level_dihedral == ilevel && force->dihedral) - force->dihedral->compute(eflag,vflag); - if (level_improper == ilevel && force->improper) - force->improper->compute(eflag,vflag); + if (level_pair == ilevel && pair_compute_flag) force->pair->compute(eflag, vflag); + if (level_inner == ilevel && pair_compute_flag) force->pair->compute_inner(); + if (level_middle == ilevel && pair_compute_flag) force->pair->compute_middle(); + if (level_outer == ilevel && pair_compute_flag) force->pair->compute_outer(eflag, vflag); + if (level_bond == ilevel && force->bond) force->bond->compute(eflag, vflag); + if (level_angle == ilevel && force->angle) force->angle->compute(eflag, vflag); + if (level_dihedral == ilevel && force->dihedral) force->dihedral->compute(eflag, vflag); + if (level_improper == ilevel && force->improper) force->improper->compute(eflag, vflag); if (level_kspace == ilevel && force->kspace) { force->kspace->setup(); - if (kspace_compute_flag) force->kspace->compute(eflag,vflag); + if (kspace_compute_flag) force->kspace->compute(eflag, vflag); } - modify->setup_pre_reverse(eflag,vflag); + modify->setup_pre_reverse(eflag, vflag); if (newton[ilevel]) comm->reverse_comm(); copy_f_flevel(ilevel); } @@ -555,7 +529,7 @@ void Respa::run(int n) ntimestep = ++update->ntimestep; ev_set(ntimestep); - recurse(nlevels-1); + recurse(nlevels - 1); // needed in case end_of_step() or output() use total force @@ -591,9 +565,9 @@ void Respa::cleanup() void Respa::reset_dt() { - step[nlevels-1] = update->dt; - for (int ilevel = nlevels-2; ilevel >= 0; ilevel--) - step[ilevel] = step[ilevel+1]/loop[ilevel]; + step[nlevels - 1] = update->dt; + for (int ilevel = nlevels - 2; ilevel >= 0; ilevel--) + step[ilevel] = step[ilevel + 1] / loop[ilevel]; } /* ---------------------------------------------------------------------- */ @@ -605,16 +579,15 @@ void Respa::recurse(int ilevel) for (int iloop = 0; iloop < loop[ilevel]; iloop++) { timer->stamp(); - modify->initial_integrate_respa(vflag,ilevel,iloop); - if (modify->n_post_integrate_respa) - modify->post_integrate_respa(ilevel,iloop); + modify->initial_integrate_respa(vflag, ilevel, iloop); + if (modify->n_post_integrate_respa) modify->post_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); // at outermost level, check on rebuilding neighbor list // at innermost level, communicate // at middle levels, do nothing - if (ilevel == nlevels-1) { + if (ilevel == nlevels - 1) { int nflag = neighbor->decide(); if (nflag) { if (modify->n_pre_exchange) { @@ -631,10 +604,9 @@ void Respa::recurse(int ilevel) } timer->stamp(); comm->exchange(); - if (atom->sortfreq > 0 && - update->ntimestep >= atom->nextsort) atom->sort(); + if (atom->sortfreq > 0 && update->ntimestep >= atom->nextsort) atom->sort(); comm->borders(); - if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); + if (triclinic) domain->lamda2x(atom->nlocal + atom->nghost); timer->stamp(Timer::COMM); if (modify->n_pre_neighbor) { modify->pre_neighbor(); @@ -665,7 +637,7 @@ void Respa::recurse(int ilevel) // b/c atoms migrated to new procs between short/long force calls // now they migrate at very start of rRESPA timestep, before all forces - if (ilevel) recurse(ilevel-1); + if (ilevel) recurse(ilevel - 1); // force computations // important that ordering is same as Verlet @@ -675,18 +647,18 @@ void Respa::recurse(int ilevel) force_clear(newton[ilevel]); if (modify->n_pre_force_respa) { timer->stamp(); - modify->pre_force_respa(vflag,ilevel,iloop); + modify->pre_force_respa(vflag, ilevel, iloop); timer->stamp(Timer::MODIFY); } timer->stamp(); if (nhybrid_styles > 0) { set_compute_flags(ilevel); - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_pair == ilevel && pair_compute_flag) { - force->pair->compute(eflag,vflag); + force->pair->compute(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_inner == ilevel && pair_compute_flag) { @@ -698,32 +670,32 @@ void Respa::recurse(int ilevel) timer->stamp(Timer::PAIR); } if (level_outer == ilevel && pair_compute_flag) { - force->pair->compute_outer(eflag,vflag); + force->pair->compute_outer(eflag, vflag); timer->stamp(Timer::PAIR); } if (level_bond == ilevel && force->bond) { - force->bond->compute(eflag,vflag); + force->bond->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_angle == ilevel && force->angle) { - force->angle->compute(eflag,vflag); + force->angle->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_dihedral == ilevel && force->dihedral) { - force->dihedral->compute(eflag,vflag); + force->dihedral->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_improper == ilevel && force->improper) { - force->improper->compute(eflag,vflag); + force->improper->compute(eflag, vflag); timer->stamp(Timer::BOND); } if (level_kspace == ilevel && kspace_compute_flag) { - force->kspace->compute(eflag,vflag); + force->kspace->compute(eflag, vflag); timer->stamp(Timer::KSPACE); } if (modify->n_pre_reverse) { - modify->pre_reverse(eflag,vflag); + modify->pre_reverse(eflag, vflag); timer->stamp(Timer::MODIFY); } @@ -732,9 +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); - modify->final_integrate_respa(ilevel,iloop); + if (modify->n_post_force_respa) modify->post_force_respa(vflag, ilevel, iloop); + modify->final_integrate_respa(ilevel, iloop); timer->stamp(Timer::MODIFY); } @@ -757,9 +728,9 @@ void Respa::force_clear(int /*newtonflag*/) if (force->newton) nbytes += sizeof(double) * atom->nghost; if (nbytes) { - memset(&atom->f[0][0],0,3*nbytes); - if (torqueflag) memset(&atom->torque[0][0],0,3*nbytes); - if (extraflag) atom->avec->force_clear(0,nbytes); + memset(&atom->f[0][0], 0, 3 * nbytes); + if (torqueflag) memset(&atom->torque[0][0], 0, 3 * nbytes); + if (extraflag) atom->avec->force_clear(0, nbytes); } } @@ -849,9 +820,9 @@ void Respa::set_compute_flags(int ilevel) if (nhybrid_styles < 1) return; pair_compute = 0; - for (int i=0; infix; ifix++) - if (modify->fix[ifix]->special_alter_flag) - modify->fix[ifix]->rebuild_special(); + for (const auto &ifix : modify->get_fix_list()) + if (ifix->special_alter_flag) ifix->rebuild_special(); } /* ---------------------------------------------------------------------- diff --git a/src/thermo.cpp b/src/thermo.cpp index 434012870b..e39d7d7c57 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -267,23 +267,20 @@ void Thermo::init() // find current ptr for each Compute ID - int icompute; for (i = 0; i < ncompute; i++) { - icompute = modify->find_compute(id_compute[i]); - if (icompute < 0) error->all(FLERR,"Could not find thermo compute ID"); - computes[i] = modify->compute[icompute]; + computes[i] = modify->get_compute_by_id(id_compute[i]); + if (!computes[i]) error->all(FLERR,"Could not find thermo compute with ID {}",id_compute[i]); } // find current ptr for each Fix ID // check that fix frequency is acceptable with thermo output frequency - int ifix; for (i = 0; i < nfix; i++) { - ifix = modify->find_fix(id_fix[i]); - if (ifix < 0) error->all(FLERR,"Could not find thermo fix ID"); - fixes[i] = modify->fix[ifix]; + fixes[i] = modify->get_fix_by_id(id_fix[i]); + if (!fixes[i]) error->all(FLERR,"Could not find thermo fix ID {}",id_fix[i]); + if (output->thermo_every % fixes[i]->global_freq) - error->all(FLERR,"Thermo and fix not computed at compatible times"); + error->all(FLERR,"Thermo and fix {} not computed at compatible times",id_fix[i]); } // find current ptr for each Variable ID @@ -467,36 +464,33 @@ void Thermo::modify_params(int narg, char **arg) if (strcmp(arg[iarg],"temp") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); if (index_temp < 0) error->all(FLERR,"Thermo style does not use temp"); - delete [] id_compute[index_temp]; + delete[] id_compute[index_temp]; id_compute[index_temp] = utils::strdup(arg[iarg+1]); - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) - error->all(FLERR,"Could not find thermo_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(arg[iarg+1]); + if (!temperature) + error->all(FLERR,"Could not find thermo_modify temperature compute {}",arg[iarg+1]); if (temperature->tempflag == 0) - error->all(FLERR,"Thermo_modify temperature ID does not " - "compute temperature"); + error->all(FLERR,"Thermo_modify compute {} does not compute temperature",arg[iarg+1]); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR, - "Temperature for thermo pressure is not for group all"); + error->warning(FLERR,"Temperature for thermo pressure is not for group all"); // reset id_temp of pressure to new temperature ID // either pressure currently being used by thermo or "thermo_press" + Compute *pcompute; if (index_press_scalar >= 0) { - icompute = modify->find_compute(id_compute[index_press_scalar]); - if (icompute < 0) error->all(FLERR, - "Pressure ID for thermo does not exist"); + pcompute = modify->get_compute_by_id(id_compute[index_press_scalar]); + if (!pcompute) error->all(FLERR, "Pressure compute {} for thermo output does not exist", + id_compute[index_press_scalar]); } else if (index_press_vector >= 0) { - icompute = modify->find_compute(id_compute[index_press_vector]); - if (icompute < 0) error->all(FLERR, - "Pressure ID for thermo does not exist"); - } else icompute = modify->find_compute("thermo_press"); - - modify->compute[icompute]->reset_extra_compute_fix(arg[iarg+1]); + pcompute = modify->get_compute_by_id(id_compute[index_press_vector]); + if (!pcompute) error->all(FLERR,"Pressure compute {} for thermo output does not exist", + id_compute[index_press_vector]); + } else pcompute = modify->get_compute_by_id("thermo_press"); + pcompute->reset_extra_compute_fix(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"press") == 0) { @@ -513,13 +507,12 @@ void Thermo::modify_params(int narg, char **arg) id_compute[index_press_vector] = utils::strdup(arg[iarg+1]); } - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) error->all(FLERR, - "Could not find thermo_modify pressure ID"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(arg[iarg+1]); + if (!pressure) + error->all(FLERR,"Could not find thermo_modify pressure compute {}",arg[iarg+1]); if (pressure->pressflag == 0) - error->all(FLERR,"Thermo_modify pressure ID does not compute pressure"); + error->all(FLERR,"Thermo_modify compute {} does not compute pressure",arg[iarg+1]); iarg += 2; @@ -912,24 +905,24 @@ void Thermo::parse_fields(char *str) argindex2[nfield] = (argi.get_dim() > 1) ? argi.get_index2() : 0; if (argi.get_type() == ArgInfo::COMPUTE) { - int n = modify->find_compute(argi.get_name()); - if (n < 0) error->all(FLERR,"Could not find thermo custom compute ID"); - if (argindex1[nfield] == 0 && modify->compute[n]->scalar_flag == 0) + auto icompute = modify->get_compute_by_id(argi.get_name()); + if (!icompute) error->all(FLERR,"Could not find thermo custom compute ID"); + if (argindex1[nfield] == 0 && icompute->scalar_flag == 0) error->all(FLERR,"Thermo compute does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { - if (modify->compute[n]->vector_flag == 0) + if (icompute->vector_flag == 0) error->all(FLERR,"Thermo compute does not compute vector"); - if (argindex1[nfield] > modify->compute[n]->size_vector && - modify->compute[n]->size_vector_variable == 0) + if (argindex1[nfield] > icompute->size_vector && + icompute->size_vector_variable == 0) error->all(FLERR,"Thermo compute vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (modify->compute[n]->array_flag == 0) + if (icompute->array_flag == 0) error->all(FLERR,"Thermo compute does not compute array"); - if (argindex1[nfield] > modify->compute[n]->size_array_rows && - modify->compute[n]->size_array_rows_variable == 0) + if (argindex1[nfield] > icompute->size_array_rows && + icompute->size_array_rows_variable == 0) error->all(FLERR,"Thermo compute array is accessed out-of-range"); - if (argindex2[nfield] > modify->compute[n]->size_array_cols) + if (argindex2[nfield] > icompute->size_array_cols) error->all(FLERR,"Thermo compute array is accessed out-of-range"); } @@ -942,24 +935,24 @@ void Thermo::parse_fields(char *str) addfield(word.c_str(), &Thermo::compute_compute, FLOAT); } else if (argi.get_type() == ArgInfo::FIX) { - int n = modify->find_fix(argi.get_name()); - if (n < 0) error->all(FLERR,"Could not find thermo custom fix ID"); - if (argindex1[nfield] == 0 && modify->fix[n]->scalar_flag == 0) + auto ifix = modify->get_fix_by_id(argi.get_name()); + if (!ifix) error->all(FLERR,"Could not find thermo custom fix ID"); + if (argindex1[nfield] == 0 && ifix->scalar_flag == 0) error->all(FLERR,"Thermo fix does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { - if (modify->fix[n]->vector_flag == 0) + if (ifix->vector_flag == 0) error->all(FLERR,"Thermo fix does not compute vector"); - if (argindex1[nfield] > modify->fix[n]->size_vector && - modify->fix[n]->size_vector_variable == 0) + if (argindex1[nfield] > ifix->size_vector && + ifix->size_vector_variable == 0) error->all(FLERR,"Thermo fix vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (modify->fix[n]->array_flag == 0) + if (ifix->array_flag == 0) error->all(FLERR,"Thermo fix does not compute array"); - if (argindex1[nfield] > modify->fix[n]->size_array_rows && - modify->fix[n]->size_array_rows_variable == 0) + if (argindex1[nfield] > ifix->size_array_rows && + ifix->size_array_rows_variable == 0) error->all(FLERR,"Thermo fix array is accessed out-of-range"); - if (argindex2[nfield] > modify->fix[n]->size_array_cols) + if (argindex2[nfield] > ifix->size_array_cols) error->all(FLERR,"Thermo fix array is accessed out-of-range"); } @@ -971,11 +964,9 @@ void Thermo::parse_fields(char *str) if (n < 0) error->all(FLERR,"Could not find thermo custom variable name"); if (argindex1[nfield] == 0 && input->variable->equalstyle(n) == 0) - error->all(FLERR, - "Thermo custom variable is not equal-style variable"); + error->all(FLERR,"Thermo custom variable is not equal-style variable"); if (argindex1[nfield] && input->variable->vectorstyle(n) == 0) - error->all(FLERR, - "Thermo custom variable is not vector-style variable"); + error->all(FLERR,"Thermo custom variable is not vector-style variable"); if (argindex2[nfield]) error->all(FLERR,"Thermo custom variable cannot have two indices"); diff --git a/src/universe.cpp b/src/universe.cpp index 005a91fc6b..bd06300d12 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -98,7 +98,7 @@ void Universe::reorder(char *style, char *arg) char *ptr; if (!fgets(line,MAXLINE,fp)) error->one(FLERR,"Unexpected end of -reorder file"); - while (1) { + while (true) { if ((ptr = strchr(line,'#'))) *ptr = '\0'; if (strspn(line," \t\n\r") != strlen(line)) break; if (!fgets(line,MAXLINE,fp)) diff --git a/src/update.cpp b/src/update.cpp index 72b60c3d3b..95dc47573e 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -488,41 +488,29 @@ void Update::reset_timestep(bigint newstep) output->reset_timestep(ntimestep); - for (int i = 0; i < modify->nfix; i++) { - if (modify->fix[i]->time_depend) - error->all(FLERR, - "Cannot reset timestep with a time-dependent fix defined"); - } + for (const auto &ifix : modify->get_fix_list()) + if (ifix->time_depend) + error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined",ifix->style); // reset eflag/vflag global so no commands will think eng/virial are current eflag_global = vflag_global = -1; - // reset invoked flags of computes, - // so no commands will think they are current between runs - - for (int i = 0; i < modify->ncompute; i++) { - modify->compute[i]->invoked_scalar = -1; - modify->compute[i]->invoked_vector = -1; - modify->compute[i]->invoked_array = -1; - modify->compute[i]->invoked_peratom = -1; - modify->compute[i]->invoked_local = -1; - } - + // reset invoked flags of computes, so no commands will think they are current between runs // clear timestep list of computes that store future invocation times - for (int i = 0; i < modify->ncompute; i++) - if (modify->compute[i]->timeflag) modify->compute[i]->clearstep(); + for (const auto &icompute : modify->get_compute_list()) { + icompute->invoked_scalar = -1; + icompute->invoked_vector = -1; + icompute->invoked_array = -1; + icompute->invoked_peratom = -1; + icompute->invoked_local = -1; + if (icompute->timeflag) icompute->clearstep(); + } // Neighbor Bin/Stencil/Pair classes store timestamps that need to be cleared neighbor->reset_timestep(ntimestep); - - // NOTE: 7Jun12, adding rerun command, don't think this is required - - //for (int i = 0; i < domain->nregion; i++) - // if (domain->regions[i]->dynamic_check()) - // error->all(FLERR,"Cannot reset timestep with a dynamic region defined"); } /* ---------------------------------------------------------------------- diff --git a/src/utils.cpp b/src/utils.cpp index 507500f116..f70a60da7c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -583,12 +583,11 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // compute if (word[0] == 'c') { - int icompute = lmp->modify->find_compute(id); + auto compute = lmp->modify->get_compute_by_id(id); // check for global vector/array, peratom array, local array - if (icompute >= 0) { - Compute *compute = lmp->modify->compute[icompute]; + if (compute) { if (mode == 0 && compute->vector_flag) { nmax = compute->size_vector; expandflag = 1; @@ -607,13 +606,11 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // fix } else if (word[0] == 'f') { - int ifix = lmp->modify->find_fix(id); + auto fix = lmp->modify->get_fix_by_id(id); // check for global vector/array, peratom array, local array - if (ifix >= 0) { - Fix *fix = lmp->modify->fix[ifix]; - + if (fix) { if (mode == 0 && fix->vector_flag) { nmax = fix->size_vector; expandflag = 1; @@ -957,7 +954,7 @@ std::vector utils::split_words(const std::string &text) } // unquoted - while (1) { + while (true) { if ((c == '\'') || (c == '"')) goto quoted; // skip escaped quote if ((c == '\\') && ((buf[1] == '\'') || (buf[1] == '"'))) { diff --git a/src/variable.cpp b/src/variable.cpp index 22f792b5ec..58a505b9ec 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -692,7 +692,7 @@ int Variable::next(int narg, char **arg) if (!random) random = new RanMars(lmp,seed); int delay = (int) (1000000*random->uniform()); platform::usleep(delay); - while (1) { + while (true) { if (!rename("tmp.lammps.variable","tmp.lammps.variable.lock")) break; delay = (int) (1000000*random->uniform()); platform::usleep(delay); @@ -963,8 +963,7 @@ double Variable::compute_equal(int ivar) else if (style[ivar] == PYTHON) { int ifunc = python->find(data[ivar][0]); if (ifunc < 0) - print_var_error(FLERR,fmt::format("cannot find python function {}", - data[ivar][0]),ivar); + print_var_error(FLERR,fmt::format("cannot find python function {}",data[ivar][0]),ivar); python->invoke_function(ifunc,data[ivar][1]); value = atof(data[ivar][1]); } @@ -1234,7 +1233,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (str == nullptr) print_var_error(FLERR,"Invalid syntax in variable formula",ivar); - while (1) { + while (true) { onechar = str[i]; // whitespace: just skip @@ -1324,10 +1323,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // compute // ---------------- - if (strncmp(word,"c_",2) == 0 || strncmp(word,"C_",2) == 0) { + if (utils::strmatch(word,"^[Cc]_")) { if (domain->box_exist == 0) - print_var_error(FLERR,"Variable evaluation before " - "simulation box is defined",ivar); + print_var_error(FLERR,"Variable evaluation before simulation box is defined",ivar); // uppercase used to force access of // global vector vs global scalar, and global array vs global vector @@ -1335,14 +1333,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int lowercase = 1; if (word[0] == 'C') lowercase = 0; - int icompute = modify->find_compute(word+2); - if (icompute < 0) { - std::string mesg = "Invalid compute ID '"; - mesg += (word+2); - mesg += "' in variable formula"; - print_var_error(FLERR,mesg,ivar); - } - Compute *compute = modify->compute[icompute]; + Compute *compute = modify->get_compute_by_id(word+2); + if (!compute) + print_var_error(FLERR,fmt::format("Invalid compute ID '{}' in variable formula", word+2),ivar); + // parse zero or one or two trailing brackets // point i beyond last bracket @@ -1371,8 +1365,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (update->whichflag == 0) { if (compute->invoked_scalar != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= Compute::INVOKED_SCALAR; @@ -1392,12 +1385,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (index1 > compute->size_vector && compute->size_vector_variable == 0) - print_var_error(FLERR,"Variable formula compute vector " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute vector is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -1419,15 +1410,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (index1 > compute->size_array_rows && compute->size_array_rows_variable == 0) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (index2 > compute->size_array_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -1448,18 +1436,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 0 && compute->vector_flag) { if (tree == nullptr) - print_var_error(FLERR,"Compute global vector in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in equal-style variable formula",ivar); if (treetype == ATOM) - print_var_error(FLERR,"Compute global vector in " - "atom-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); if (compute->size_vector == 0) - print_var_error(FLERR,"Variable formula compute " - "vector is zero length",ivar); + print_var_error(FLERR,"Variable formula compute vector is zero length",ivar); if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -1477,18 +1461,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 1 && compute->array_flag) { if (tree == nullptr) - print_var_error(FLERR,"Compute global vector in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in equal-style variable formula",ivar); if (treetype == ATOM) - print_var_error(FLERR,"Compute global vector in " - "atom-style variable formula",ivar); + print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); if (compute->size_array_rows == 0) - print_var_error(FLERR,"Variable formula compute array " - "is zero length",ivar); + print_var_error(FLERR,"Variable formula compute array is zero length",ivar); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between " - "runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -1508,8 +1488,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1550,15 +1529,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) compute->size_peratom_cols == 0) { if (tree == nullptr) - print_var_error(FLERR,"Per-atom compute in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar); if (treetype == VECTOR) - print_var_error(FLERR,"Per-atom compute in " - "vector-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1576,18 +1552,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) compute->size_peratom_cols > 0) { if (tree == nullptr) - print_var_error(FLERR,"Per-atom compute in " - "equal-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar); if (treetype == VECTOR) - print_var_error(FLERR,"Per-atom compute in " - "vector-style variable formula",ivar); + print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); if (index1 > compute->size_peratom_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_peratom != update->ntimestep) - print_var_error(FLERR,"Compute used in variable " - "between runs is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= Compute::INVOKED_PERATOM; @@ -1602,17 +1574,15 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else if (nbracket == 1 && compute->local_flag) { print_var_error(FLERR,"Cannot access local data via indexing",ivar); - } else print_var_error(FLERR, - "Mismatched compute in variable formula",ivar); + } else print_var_error(FLERR,"Mismatched compute in variable formula",ivar); // ---------------- // fix // ---------------- - } else if (strncmp(word,"f_",2) == 0 || strncmp(word,"F_",2) == 0) { + } else if (utils::strmatch(word,"^[fF]_")) { if (domain->box_exist == 0) - print_var_error(FLERR,"Variable evaluation before " - "simulation box is defined",ivar); + print_var_error(FLERR,"Variable evaluation before simulation box is defined",ivar); // uppercase used to force access of // global vector vs global scalar, and global array vs global vector @@ -1620,11 +1590,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int lowercase = 1; if (word[0] == 'F') lowercase = 0; - int ifix = modify->find_fix(word+2); - if (ifix < 0) - print_var_error(FLERR,fmt::format("Invalid fix ID '{}' in variable" - " formula",word+2),ivar); - Fix *fix = modify->fix[ifix]; + Fix *fix = modify->get_fix_by_id(word+2); + if (!fix) + print_var_error(FLERR,fmt::format("Invalid fix ID '{}' in variable formula",word+2),ivar); + // parse zero or one or two trailing brackets // point i beyond last bracket @@ -3214,7 +3183,7 @@ int Variable::find_matching_paren(char *str, int i, char *&contents, int ivar) int istart = i; int ilevel = 0; - while (1) { + while (true) { i++; if (!str[i]) break; if (str[i] == '(') ilevel++; @@ -4057,19 +4026,17 @@ int Variable::special_function(char *word, char *contents, Tree **tree, *ptr1 = '\0'; } else index = 0; - int icompute = modify->find_compute(&args[0][2]); - if (icompute < 0) { + compute = modify->get_compute_by_id(&args[0][2]); + if (!compute) { std::string mesg = "Invalid compute ID '"; mesg += (args[0]+2); mesg += "' in variable formula"; print_var_error(FLERR,mesg,ivar); } - compute = modify->compute[icompute]; if (index == 0 && compute->vector_flag) { if (update->whichflag == 0) { if (compute->invoked_vector != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= Compute::INVOKED_VECTOR; @@ -4078,12 +4045,10 @@ int Variable::special_function(char *word, char *contents, Tree **tree, nstride = 1; } else if (index && compute->array_flag) { if (index > compute->size_array_cols) - print_var_error(FLERR,"Variable formula compute array " - "is accessed out-of-range",ivar,0); + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (update->whichflag == 0) { if (compute->invoked_array != update->ntimestep) - print_var_error(FLERR,"Compute used in variable between runs " - "is not current",ivar); + print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); } else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; @@ -4102,14 +4067,13 @@ int Variable::special_function(char *word, char *contents, Tree **tree, *ptr1 = '\0'; } else index = 0; - int ifix = modify->find_fix(&args[0][2]); - if (ifix < 0) { + fix = modify->get_fix_by_id(&args[0][2]); + if (!fix) { std::string mesg = "Invalid fix ID '"; mesg += (args[0]+2); mesg += "' in variable formula"; print_var_error(FLERR,mesg,ivar); } - fix = modify->fix[ifix]; if (index == 0 && fix->vector_flag) { if (update->whichflag > 0 && update->ntimestep % fix->global_freq) { std::string mesg = "Fix with ID '"; @@ -4722,7 +4686,7 @@ double Variable::evaluate_boolean(char *str) int i = 0; int expect = ARG; - while (1) { + while (true) { onechar = str[i]; // whitespace: just skip @@ -5016,7 +4980,7 @@ int VarReader::read_scalar(char *str) // read one string from file if (me == 0) { - while (1) { + while (true) { ptr = fgets(str,MAXLINE,fp); if (!ptr) { n=0; break; } // end of file ptr[strcspn(ptr,"#")] = '\0'; // strip comment @@ -5059,7 +5023,7 @@ int VarReader::read_peratom() char str[MAXLINE]; if (me == 0) { - while (1) { + while (true) { ptr = fgets(str,MAXLINE,fp); if (!ptr) { n=0; break; } // end of file ptr[strcspn(ptr,"#")] = '\0'; // strip comment diff --git a/src/velocity.cpp b/src/velocity.cpp index 4a449d00e7..34b8d5a700 100644 --- a/src/velocity.cpp +++ b/src/velocity.cpp @@ -43,7 +43,7 @@ enum{NONE,CONSTANT,EQUAL,ATOM}; /* ---------------------------------------------------------------------- */ -Velocity::Velocity(LAMMPS *lmp) : Command(lmp) {} +Velocity::Velocity(LAMMPS *lmp) : Command(lmp), rigid_fix(nullptr), temperature(nullptr) {} /* ---------------------------------------------------------------------- */ @@ -91,7 +91,6 @@ void Velocity::command(int narg, char **arg) bias_flag = 0; loop_flag = ALL; scale_flag = 1; - rfix = -1; // read options from end of input line // change defaults as options specify @@ -108,8 +107,7 @@ void Velocity::command(int narg, char **arg) // b/c methods invoked in the compute/fix perform forward/reverse comm int initcomm = 0; - if (style == ZERO && rfix >= 0 && - utils::strmatch(modify->fix[rfix]->style,"^rigid.*/small.*")) initcomm = 1; + if (style == ZERO && rigid_fix && utils::strmatch(rigid_fix->style,"^rigid.*/small.*")) initcomm = 1; if ((style == CREATE || style == SET) && temperature && strcmp(temperature->style,"temp/cs") == 0) initcomm = 1; @@ -154,7 +152,6 @@ void Velocity::init_external(const char *extgroup) momentum_flag = 1; rotation_flag = 0; loop_flag = ALL; - rfix = -1; scale_flag = 1; bias_flag = 0; } @@ -692,21 +689,21 @@ void Velocity::ramp(int /*narg*/, char **arg) void Velocity::zero(int /*narg*/, char **arg) { if (strcmp(arg[0],"linear") == 0) { - if (rfix < 0) zero_momentum(); - else if (utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) { - modify->fix[rfix]->setup_pre_neighbor(); - modify->fix[rfix]->zero_momentum(); - } else if (utils::strmatch(modify->fix[rfix]->style,"^rigid")) { - modify->fix[rfix]->zero_momentum(); + if (!rigid_fix) zero_momentum(); + else if (utils::strmatch(rigid_fix->style,"^rigid/small")) { + rigid_fix->setup_pre_neighbor(); + rigid_fix->zero_momentum(); + } else if (utils::strmatch(rigid_fix->style,"^rigid")) { + rigid_fix->zero_momentum(); } else error->all(FLERR,"Velocity rigid used with non-rigid fix-ID"); } else if (strcmp(arg[0],"angular") == 0) { - if (rfix < 0) zero_rotation(); - else if (utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) { - modify->fix[rfix]->setup_pre_neighbor(); - modify->fix[rfix]->zero_rotation(); - } else if (utils::strmatch(modify->fix[rfix]->style,"^rigid")) { - modify->fix[rfix]->zero_rotation(); + if (!rigid_fix) zero_rotation(); + else if (utils::strmatch(rigid_fix->style,"^rigid/small")) { + rigid_fix->setup_pre_neighbor(); + rigid_fix->zero_rotation(); + } else if (utils::strmatch(rigid_fix->style,"^rigid")) { + rigid_fix->zero_rotation(); } else error->all(FLERR,"Velocity rigid used with non-rigid fix-ID"); } else error->all(FLERR,"Illegal velocity command"); @@ -843,11 +840,10 @@ void Velocity::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"temp") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); - int icompute = modify->find_compute(arg[iarg+1]); - if (icompute < 0) error->all(FLERR,"Could not find velocity temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(arg[iarg+1]); + if (!temperature) error->all(FLERR,"Could not find velocity temperature compute ID"); if (temperature->tempflag == 0) - error->all(FLERR,"Velocity temperature ID does not compute temperature"); + error->all(FLERR,"Velocity temperature compute {} does not compute temperature", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"bias") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); @@ -862,8 +858,8 @@ void Velocity::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); - rfix = modify->find_fix(arg[iarg+1]); - if (rfix < 0) error->all(FLERR,"Fix ID for velocity does not exist"); + rigid_fix = modify->get_fix_by_id(arg[iarg+1]); + if (!rigid_fix) error->all(FLERR,"Fix ID {} for velocity does not exist", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"units") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal velocity command"); diff --git a/src/velocity.h b/src/velocity.h index f0a756350c..cce8508021 100644 --- a/src/velocity.h +++ b/src/velocity.h @@ -36,8 +36,9 @@ class Velocity : public Command { int igroup, groupbit; int style; int dist_flag, sum_flag, momentum_flag, rotation_flag; - int bias_flag, loop_flag, scale_flag, rfix; + int bias_flag, loop_flag, scale_flag; double xscale, yscale, zscale; + class Fix *rigid_fix; class Compute *temperature; void set(int, char **); diff --git a/src/verlet.cpp b/src/verlet.cpp index b9b0b392e1..aa180f5644 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -22,6 +22,7 @@ #include "dihedral.h" #include "domain.h" #include "error.h" +#include "fix.h" #include "force.h" #include "improper.h" #include "kspace.h" @@ -49,10 +50,14 @@ void Verlet::init() { Integrate::init(); - // warn if no fixes + // warn if no fixes doing time integration - if (modify->nfix == 0 && comm->me == 0) - error->warning(FLERR,"No fixes defined, atoms won't move"); + bool do_time_integrate = false; + for (const auto &fix : modify->get_fix_list()) + if (fix->time_integrate) do_time_integrate; + + if (!do_time_integrate && (comm->me == 0)) + error->warning(FLERR,"No fixes with time integration, atoms won't move"); // virial_style: // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions @@ -68,8 +73,7 @@ void Verlet::init() // detect if fix omp is present for clearing force arrays - int ifix = modify->find_fix("package_omp"); - if (ifix >= 0) external_force_clear = 1; + if (modify->get_fix_by_id("package_omp")) external_force_clear = 1; // set flags for arrays to clear in force_clear() diff --git a/src/version.h b/src/version.h index c1b2b627a8..21f49398e0 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "29 Sep 2021" +#define LAMMPS_VERSION "27 Oct 2021" diff --git a/src/write_coeff.cpp b/src/write_coeff.cpp index 6f53a97e8f..a21a2634fc 100644 --- a/src/write_coeff.cpp +++ b/src/write_coeff.cpp @@ -92,7 +92,7 @@ void WriteCoeff::command(int narg, char **arg) fprintf(two,"# LAMMPS coeff file via write_coeff, version %s\n", lmp->version); - while (1) { + while (true) { int coeff_mode = REGULAR_MODE; if (fgets(str,256,one) == nullptr) break; diff --git a/src/write_data.cpp b/src/write_data.cpp index 82c237a07e..c2c59fd046 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -213,9 +213,9 @@ void WriteData::write(const std::string &file) // extra sections managed by fixes if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->wd_section) - for (int m = 0; m < modify->fix[i]->wd_section; m++) fix(i,m); + for (auto &ifix : modify->get_fix_list()) + if (ifix->wd_section) + for (int m = 0; m < ifix->wd_section; m++) fix(ifix,m); // close data file @@ -267,22 +267,19 @@ void WriteData::header() // fix info if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->wd_header) - for (int m = 0; m < modify->fix[i]->wd_header; m++) - modify->fix[i]->write_data_header(fp,m); + for (auto &ifix : modify->get_fix_list()) + if (ifix->wd_header) + for (int m = 0; m < ifix->wd_header; m++) + ifix->write_data_header(fp,m); // box info - auto box = fmt::format("\n{} {} xlo xhi" - "\n{} {} ylo yhi" - "\n{} {} zlo zhi\n", + auto box = fmt::format("\n{} {} xlo xhi\n{} {} ylo yhi\n{} {} zlo zhi\n", domain->boxlo[0],domain->boxhi[0], domain->boxlo[1],domain->boxhi[1], domain->boxlo[2],domain->boxhi[2]); if (domain->triclinic) - box += fmt::format("{} {} {} xy xz yz\n", - domain->xy,domain->xz,domain->yz); + box += fmt::format("{} {} {} xy xz yz\n",domain->xy,domain->xz,domain->yz); fputs(box.c_str(),fp); } @@ -722,13 +719,13 @@ void WriteData::bonus(int flag) write out Mth section of data file owned by Fix ifix ------------------------------------------------------------------------- */ -void WriteData::fix(int ifix, int mth) +void WriteData::fix(Fix *ifix, int mth) { // communication buffer for Fix info // maxrow X ncol = largest buffer needed by any proc int sendrow,ncol; - modify->fix[ifix]->write_data_section_size(mth,sendrow,ncol); + ifix->write_data_section_size(mth,sendrow,ncol); int maxrow; MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); @@ -738,7 +735,7 @@ void WriteData::fix(int ifix, int mth) // pack my fix data into buf - modify->fix[ifix]->write_data_section_pack(mth,buf); + ifix->write_data_section_pack(mth,buf); // write one chunk of info per proc to file // proc 0 pings each proc, receives its chunk, writes to file @@ -751,7 +748,7 @@ void WriteData::fix(int ifix, int mth) MPI_Status status; MPI_Request request; - modify->fix[ifix]->write_data_section_keyword(mth,fp); + ifix->write_data_section_keyword(mth,fp); for (int iproc = 0; iproc < nprocs; iproc++) { if (iproc) { MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); @@ -761,7 +758,7 @@ void WriteData::fix(int ifix, int mth) recvrow /= ncol; } else recvrow = sendrow; - modify->fix[ifix]->write_data_section(mth,fp,recvrow,buf,index); + ifix->write_data_section(mth,fp,recvrow,buf,index); index += recvrow; } diff --git a/src/write_data.h b/src/write_data.h index 74e7e6136e..d62f048894 100644 --- a/src/write_data.h +++ b/src/write_data.h @@ -51,7 +51,7 @@ class WriteData : public Command { void dihedrals(); void impropers(); void bonus(int); - void fix(int, int); + void fix(class Fix *, int); }; } // namespace LAMMPS_NS diff --git a/src/write_dump.cpp b/src/write_dump.cpp index 89c976fe09..53ab80149a 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -57,7 +57,7 @@ void WriteDump::command(int narg, char **arg) for (int i = 2; i < modindex; ++i) dumpargs[i+2] = arg[i]; - if (0) { + if (false) { return; // dummy line to enable else-if macro expansion #define DUMP_CLASS diff --git a/src/write_restart.cpp b/src/write_restart.cpp index 4333fa5416..661585605d 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -269,7 +269,7 @@ void WriteRestart::write(const std::string &file) double *buf; memory->create(buf,max_size,"write_restart:buf"); - memset(buf,0,max_size*sizeof(buf)); + memset(buf,0,max_size*sizeof(double)); // all procs write file layout info which may include per-proc sizes @@ -413,9 +413,9 @@ void WriteRestart::write(const std::string &file) // invoke any fixes that write their own restart file - for (int ifix = 0; ifix < modify->nfix; ifix++) - if (modify->fix[ifix]->restart_file) - modify->fix[ifix]->write_restart_file(file.c_str()); + for (auto &fix : modify->get_fix_list()) + if (fix->restart_file) + fix->write_restart_file(file.c_str()); } /* ---------------------------------------------------------------------- diff --git a/tools/binary2txt.cpp b/tools/binary2txt.cpp index a7724ffbd2..dfa81e8a6e 100644 --- a/tools/binary2txt.cpp +++ b/tools/binary2txt.cpp @@ -97,7 +97,7 @@ int main(int narg, char **arg) // loop over snapshots in file - while (1) { + while (true) { int endian = 0x0001; int revision = 0x0001; diff --git a/tools/offline/scripts/init_http_cache.sh b/tools/offline/scripts/init_http_cache.sh index 44a07da35a..926a74f499 100755 --- a/tools/offline/scripts/init_http_cache.sh +++ b/tools/offline/scripts/init_http_cache.sh @@ -40,29 +40,31 @@ echo "Dowloading thirdparty tarballs..." MPICH2_WIN64_DEVEL_URL="${LAMMPS_THIRDPARTY_URL}/mpich2-win64-devel.tar.gz" MPICH2_WIN32_DEVEL_URL="${LAMMPS_THIRDPARTY_URL}/mpich2-win32-devel.tar.gz" VORO_URL="${LAMMPS_THIRDPARTY_URL}/voro++-0.4.6.tar.gz" -OPENCL_LOADER_URL="${LAMMPS_THIRDPARTY_URL}/opencl-loader-2021.06.30.tar.gz" +OPENCL_LOADER_URL="${LAMMPS_THIRDPARTY_URL}/opencl-loader-2021.09.18.tar.gz" SCAFACOS_FIX_URL="${LAMMPS_THIRDPARTY_URL}/scafacos-1.0.1-fix.diff" -GTEST_URL="https://github.com/google/googletest/archive/release-1.10.0.tar.gz" +GTEST_URL="https://github.com/google/googletest/archive/release-1.11.0.tar.gz" YAML_URL="https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz" MATHJAX_URL="https://github.com/mathjax/MathJax/archive/3.1.3.tar.gz" -EIGEN3_URL="https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz" +EIGEN3_URL="${LAMMPS_THIRDPARTY_URL}/eigen-3.4.0.tar.gz" CUB_URL="https://github.com/NVlabs/cub/archive/1.12.0.tar.gz" KOKKOS_URL="https://github.com/kokkos/kokkos/archive/3.4.01.tar.gz" KIM_URL="https://s3.openkim.org/kim-api/kim-api-2.2.1.txz" MSCG_URL="https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz" PLUMED_URL="https://github.com/plumed/plumed2/releases/download/v2.7.2/plumed-src-2.7.2.tgz" -PACELIB_URL="https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.4.9.tar.gz" +PACELIB_URL="https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.10.25.tar.gz" LATTE_URL="https://github.com/lanl/LATTE/archive/v1.2.2.tar.gz" SCAFACOS_URL="https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz" MDI_URL="https://github.com/MolSSI-MDI/MDI_Library/archive/v1.2.9.tar.gz" +N2P2_URL="https://github.com/CompPhysVienna/n2p2/archive/v2.1.4.tar.gz" -GTEST_FILENAME="gtest-1.10.0.tar.gz" +GTEST_FILENAME="gtest-1.11.0.tar.gz" MATHJAX_FILENAME="mathjax-3.1.3.tar.gz" CUB_FILENAME="cub-1.12.0.tar.gz" KOKKOS_FILENAME="kokkos-3.4.01.tar.gz" MSCG_FILENAME="mscg-1.7.3.1.tar.gz" LATTE_FILENAME="latte-1.2.2.tar.gz" -PACELIB_FILENAME="pacelib-2021.4.9.tar.gz" +N2P2_FILENAME="n2p2-2.1.4.tar.gz" +PACELIB_FILENAME="pacelib-2021.10.25.tar.gz" TARBALLS=( MPICH2_WIN64_DEVEL_URL @@ -83,6 +85,7 @@ TARBALLS=( LATTE_URL SCAFACOS_URL MDI_URL + N2P2_URL ) ############################################################################### diff --git a/tools/offline/scripts/update_downloads.sh b/tools/offline/scripts/update_downloads.sh index 247b92e562..28cd267c27 100755 --- a/tools/offline/scripts/update_downloads.sh +++ b/tools/offline/scripts/update_downloads.sh @@ -14,11 +14,41 @@ function update_setting() sed -i "/^$1=/c$1=\"$2\"" init_http_cache.sh } +DETECTED_URLS=$(grep -PoRh "\w+_URL" ../../../cmake/ | sort | uniq | grep -v ^LAMMPS) +KNOWN_URLS=$(grep -Rh "_URL=" init_http_cache.sh | grep -v ^LAMMPS | grep -v SCAFACOS_FIX | cut -d= -f1) -URLS=$(grep -Rh "_URL=" init_http_cache.sh | grep -v ^LAMMPS | grep -v SCAFACOS_FIX | cut -d= -f1) +# check if init_http_cache.sh contains all URLs +for URL in $DETECTED_URLS +do + grep -q ^$URL= init_http_cache.sh + if [ $? -ne 0 ] + then + FILENAME_VAR="${URL/_URL/_FILENAME}" + echo $URL is not known. Please update 'init_http_cache.sh' as follows: + echo + echo 1. add the following line: + echo + echo $URL="" + echo + echo 2. Define a new $FILENAME_VAR if necessary + echo + echo $FILENAME_VAR="pkgname-0.0.0.tar.gz" + echo + echo 3. extend TARBALLS with $URL + echo + echo TARBALLS=\( + echo " ..." + echo " $URL" + echo \) + echo + echo 4. Rerun this script + echo + exit 1 + fi +done # update URLs by grabbing the latest ones from cmake files -for URL in $URLS +for URL in $KNOWN_URLS do extract_setting "$URL" update_setting "$URL" ${!URL} diff --git a/tools/offline/scripts/use_git_cache.sh b/tools/offline/scripts/use_git_cache.sh index 46e42ca7bd..e65c06c8ed 100644 --- a/tools/offline/scripts/use_git_cache.sh +++ b/tools/offline/scripts/use_git_cache.sh @@ -8,12 +8,12 @@ fi export GIT_CONFIG_COUNT=1 export GIT_CONFIG_KEY_0="url.$GITHUB_PROXY_DIR/.insteadOf" -export GIT_CONFIG_VALUE_0=git://github.com/ +export GIT_CONFIG_VALUE_0=https://github.com/ -echo "Redirecting git://github.com urls to local cache..." +echo "Redirecting https://github.com urls to local cache..." function deactivate_git_cache { - echo "Removing git://github.com redirect..." + echo "Removing https://github.com redirect..." unset GIT_CONFIG_COUNT unset GIT_CONFIG_KEY_0 unset GIT_CONFIG_VALUE_0 diff --git a/tools/offline/use_caches.sh b/tools/offline/use_caches.sh index 71d955fe4c..5db78fd765 100644 --- a/tools/offline/use_caches.sh +++ b/tools/offline/use_caches.sh @@ -63,7 +63,7 @@ echo "or" echo echo "-D LAMMPS_DOWNLOADS_URL=${HTTP_CACHE_URL} -C \"${LAMMPS_HTTP_CACHE_CONFIG}\"" echo -echo "pip installations and git clones (from git://) are automatically redirected" +echo "pip installations and git clones (from https://) are automatically redirected" echo echo Use 'deactivate_caches' to revert changes echo diff --git a/tools/singularity/README.md b/tools/singularity/README.md index bd13d75ad7..db7aa9e3b0 100644 --- a/tools/singularity/README.md +++ b/tools/singularity/README.md @@ -15,7 +15,7 @@ built CentOS 7.x singularity container. ``` cd some/work/directory -git clone --depth 500 git://github.com/lammps/lammps.git lammps +git clone --depth 500 https://github.com/lammps/lammps.git lammps mkdir build-centos7 cd build-centos7 sudo singularity build centos7.sif ../tools/singularity/centos7.def diff --git a/unittest/c-library/test_library_commands.cpp b/unittest/c-library/test_library_commands.cpp index 267ee6108e..b16dc6e9dd 100644 --- a/unittest/c-library/test_library_commands.cpp +++ b/unittest/c-library/test_library_commands.cpp @@ -54,14 +54,14 @@ TEST_F(LibraryCommands, from_file) const char cont_file[] = "in.cont"; fp = fopen(demo_file, "w"); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - fputs(demo_input[i], fp); + for (auto & inp : demo_input) { + fputs(inp, fp); fputc('\n', fp); } fclose(fp); fp = fopen(cont_file, "w"); - for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { - fputs(cont_input[i], fp); + for (auto & inp : cont_input) { + fputs(inp, fp); fputc('\n', fp); } fclose(fp); @@ -84,8 +84,8 @@ TEST_F(LibraryCommands, from_line) { EXPECT_EQ(lammps_get_natoms(lmp), 0); if (!verbose) ::testing::internal::CaptureStdout(); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - lammps_command(lmp, demo_input[i]); + for (auto & inp : demo_input) { + lammps_command(lmp, inp); } if (!verbose) ::testing::internal::GetCapturedStdout(); EXPECT_EQ(lammps_get_natoms(lmp), 1); @@ -105,12 +105,12 @@ TEST_F(LibraryCommands, from_string) { std::string cmds(""); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - cmds += demo_input[i]; + for (auto & inp : demo_input) { + cmds += inp; cmds += "\n"; } - for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { - cmds += cont_input[i]; + for (auto & inp : cont_input) { + cmds += inp; cmds += "\n"; } EXPECT_EQ(lammps_get_natoms(lmp), 0); @@ -125,12 +125,12 @@ TEST_F(LibraryCommands, from_string) if (!verbose) ::testing::internal::GetCapturedStdout(); cmds.clear(); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - cmds += demo_input[i]; + for (auto & inp : demo_input) { + cmds += inp; cmds += "\r\n"; } - for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { - cmds += cont_input[i]; + for (auto & inp : cont_input) { + cmds += inp; cmds += "\r\n"; } EXPECT_EQ(lammps_get_natoms(lmp), 0); diff --git a/unittest/cplusplus/test_input_class.cpp b/unittest/cplusplus/test_input_class.cpp index 4af7450ed8..87bea36081 100644 --- a/unittest/cplusplus/test_input_class.cpp +++ b/unittest/cplusplus/test_input_class.cpp @@ -60,14 +60,14 @@ TEST_F(Input_commands, from_file) const char cont_file[] = "in.cont"; fp = fopen(demo_file, "w"); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - fputs(demo_input[i], fp); + for (auto & inp : demo_input) { + fputs(inp, fp); fputc('\n', fp); } fclose(fp); fp = fopen(cont_file, "w"); - for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { - fputs(cont_input[i], fp); + for (auto & inp : cont_input) { + fputs(inp, fp); fputc('\n', fp); } fclose(fp); @@ -84,8 +84,8 @@ TEST_F(Input_commands, from_file) TEST_F(Input_commands, from_line) { EXPECT_EQ(lmp->atom->natoms, 0); - for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { - lmp->input->one(demo_input[i]); + for (auto & inp : demo_input) { + lmp->input->one(inp); } EXPECT_EQ(lmp->atom->natoms, 1); }; diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index 945c16c649..65e9e4b0f6 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -83,7 +83,7 @@ void TestConfigReader::prerequisites(const yaml_event_t &event) std::stringstream data((char *)event.data.scalar.value); std::string key, value; - while (1) { + while (true) { data >> key >> value; if (data.eof()) break; config.prerequisites.emplace_back(key, value); @@ -138,7 +138,7 @@ void TestConfigReader::extract(const yaml_event_t &event) std::stringstream data((char *)event.data.scalar.value); std::string name; int value; - while (1) { + while (true) { data >> name >> value; if (data.eof()) break; config.extract.emplace_back(name, value); diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index f3526d6d4b..bd8512894f 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -1,6 +1,6 @@ -import sys,os,unittest -from lammps import lammps, LMP_VAR_ATOM, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR +import sys,os,unittest,ctypes +from lammps import lammps, LMP_VAR_ATOM, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, LAMMPS_DOUBLE_2D, LAMMPS_AUTODETECT has_manybody=False try: @@ -494,6 +494,43 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) + def test_create_atoms(self): + self.lmp.command("boundary f p m") + self.lmp.command("region box block 0 10 0 10 0 10") + self.lmp.command("create_box 2 box") + # second atom is outside the box -> dropped + self.lmp.create_atoms(2, [1,2], [1,1], [1.0, 1.0, 3.0, 5.0, 8.0, 12.0]) + self.assertEqual(self.lmp.get_natoms(),1) + # non-zero velocities + self.lmp.create_atoms(2, None, [2,2], [2.0, 2.0, 1.0, 3.0, 4.0, 6.0], v=[0.1, 0.2, 0.3, -0.1, -0.2, -0.3]) + self.assertEqual(self.lmp.get_natoms(),3) + # first atom is dropped, extend shrinkwrapped box for second atom, third atoms is wrapped around PBC. + self.lmp.create_atoms(3, [5,8,10], [1,2,1], [-1.0, 1.0, 3.0, 5.0, 8.0, 12.0, 1.0, -1.0, 1.0], shrinkexceed=True) + self.assertEqual(self.lmp.get_natoms(),5) + # set image flags + self.lmp.create_atoms(1, None, [2], [5.0, 8.0, 1.0], image=[self.lmp.encode_image_flags(1,0,-1)]) + self.assertEqual(self.lmp.get_natoms(),6) + tag = self.lmp.extract_atom("id") + typ = self.lmp.extract_atom("type") + pos = self.lmp.extract_atom("x",LAMMPS_DOUBLE_2D) + vel = self.lmp.extract_atom("v",LAMMPS_DOUBLE_2D) + img = self.lmp.extract_atom("image",LAMMPS_AUTODETECT) + # expected results: tag, type, x, v, image + result = [ [ 1, 1, [1.0, 1.0, 3.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [ 2, 2, [2.0, 2.0, 1.0], [ 0.1, 0.2, 0.3], [0, 0, 0]],\ + [ 3, 2, [3.0, 4.0, 6.0], [-0.1, -0.2, -0.3], [0, 0, 0]],\ + [ 8, 2, [5.0, 8.0, 12.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [10, 1, [1.0, 9.0, 1.0], [ 0.0, 0.0, 0.0], [0, 0, 0]],\ + [11, 2, [5.0, 8.0, 1.0], [ 0.0, 0.0, 0.0], [1, 0, -1]] ] + for i in range(len(result)): + self.assertEqual(tag[i],result[i][0]) + self.assertEqual(typ[i],result[i][1]) + for j in range(3): + self.assertEqual(pos[i][0:3],result[i][2]) + self.assertEqual(vel[i][0:3],result[i][3]) + self.assertEqual(self.lmp.decode_image_flags(img[i]), result[i][4]) + + ############################## if __name__ == "__main__": unittest.main()