diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f99a336dbb..deeea5df90 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -151,12 +151,12 @@ tools/vim/* @hammondkd unittest/* @akohlmey # cmake -cmake/* @rbberger +cmake/* @akohlmey cmake/Modules/LAMMPSInterfacePlugin.cmake @akohlmey cmake/Modules/MPI4WIN.cmake @akohlmey cmake/Modules/OpenCLLoader.cmake @akohlmey -cmake/Modules/Packages/COLVARS.cmake @rbberger @giacomofiorin -cmake/Modules/Packages/KIM.cmake @rbberger @ellio167 +cmake/Modules/Packages/COLVARS.cmake @giacomofiorin +cmake/Modules/Packages/KIM.cmake @ellio167 cmake/presets/*.cmake @akohlmey # python diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 380d722caa..eead4d0423 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -2,7 +2,6 @@ ######################################## # CMake build system # This file is part of LAMMPS -# Created by Christoph Junghans and Richard Berger cmake_minimum_required(VERSION 3.10) ######################################## # set policy to silence warnings about ignoring _ROOT but use it @@ -112,7 +111,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4) set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512") else() - set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=2196") + set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196") endif() endif() endif() @@ -151,6 +150,7 @@ if(MSVC) add_compile_options(/Zc:__cplusplus) add_compile_options(/wd4244) add_compile_options(/wd4267) + add_compile_options(/wd4250) add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) @@ -438,6 +438,18 @@ if(BUILD_OMP) target_link_libraries(lmp PRIVATE OpenMP::OpenMP_CXX) endif() +# lower C++ standard for fmtlib sources when using Intel classic compiler +if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_STANDARD GREATER_EQUAL 17) + AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2021.10)) + message(STATUS "Lowering C++ standard for compiling fmtlib sources with Intel Classic compiler") + get_filename_component(LMP_UTILS_SRC "${LAMMPS_SOURCE_DIR}/utils.cpp" ABSOLUTE) + get_filename_component(LMP_VARIABLE_SRC "${LAMMPS_SOURCE_DIR}/variable.cpp" ABSOLUTE) + get_filename_component(FMT_FORMAT_SRC "${LAMMPS_SOURCE_DIR}/fmtlib_format.cpp" ABSOLUTE) + get_filename_component(FMT_OS_SRC "${LAMMPS_SOURCE_DIR}/fmtlib_os.cpp" ABSOLUTE) + set_source_files_properties("${FMT_FORMAT_SRC}" "${FMT_OS_SRC}" "${LMP_VARIABLE_SRC}" "${LMP_UTILS_SRC}" + PROPERTIES COMPILE_OPTIONS "-std=c++14") +endif() + if(PKG_MSCG OR PKG_ATC OR PKG_AWPMD OR PKG_ML-QUIP OR PKG_ML-POD OR PKG_ELECTRODE OR BUILD_TOOLS) enable_language(C) if (NOT USE_INTERNAL_LINALG) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 1ceec7e06e..d464aa4dca 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -83,17 +83,17 @@ function(check_for_autogen_files source_dir) file(GLOB SRC_AUTOGEN_FILES ${CONFIGURE_DEPENDS} ${source_dir}/style_*.h) file(GLOB SRC_AUTOGEN_PACKAGES ${CONFIGURE_DEPENDS} ${source_dir}/packages_*.h) list(APPEND SRC_AUTOGEN_FILES ${SRC_AUTOGEN_PACKAGES} ${source_dir}/lmpinstalledpkgs.h ${source_dir}/lmpgitversion.h) - list(APPEND SRC_AUTOGEN_FILES ${SRC_AUTOGEN_PACKAGES} ${source_dir}/mliap_model_python_couple.h ${source_dir}/mliap_model_python_couple.cpp) + list(APPEND SRC_AUTOGEN_FILES ${source_dir}/mliap_model_python_couple.h ${source_dir}/mliap_model_python_couple.cpp) foreach(_SRC ${SRC_AUTOGEN_FILES}) get_filename_component(FILENAME "${_SRC}" NAME) if(EXISTS ${source_dir}/${FILENAME}) message(FATAL_ERROR "\n########################################################################\n" - "Found header file(s) generated by the make-based build system\n" - "\n" - "Please run\n" - "make -C ${source_dir} purge\n" - "to remove\n" - "########################################################################") + "Found header file ${source_dir}/${FILENAME} generated by the make-based build system\n" + "\n" + "Please run\n" + "make -C ${source_dir} purge\n" + "to remove\n" + "########################################################################") endif() endforeach() endfunction() diff --git a/cmake/Modules/Packages/ML-PACE.cmake b/cmake/Modules/Packages/ML-PACE.cmake index 6cdb751617..ce8f02f5f4 100644 --- a/cmake/Modules/Packages/ML-PACE.cmake +++ b/cmake/Modules/Packages/ML-PACE.cmake @@ -1,6 +1,6 @@ -set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.01.3.fix.tar.gz" CACHE STRING "URL for PACE evaluator library sources") +set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.10.04.tar.gz" CACHE STRING "URL for PACE evaluator library sources") -set(PACELIB_MD5 "4f0b3b5b14456fe9a73b447de3765caa" CACHE STRING "MD5 checksum of PACE evaluator library tarball") +set(PACELIB_MD5 "70ff79f4e59af175e55d24f3243ad1ff" CACHE STRING "MD5 checksum of PACE evaluator library tarball") mark_as_advanced(PACELIB_URL) mark_as_advanced(PACELIB_MD5) GetFallbackURL(PACELIB_URL PACELIB_FALLBACK) diff --git a/cmake/presets/kokkos-cuda.cmake b/cmake/presets/kokkos-cuda.cmake index ace8ff0879..c3ee081898 100644 --- a/cmake/presets/kokkos-cuda.cmake +++ b/cmake/presets/kokkos-cuda.cmake @@ -6,6 +6,8 @@ set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA ON CACHE BOOL "" FORCE) set(Kokkos_ARCH_PASCAL60 ON CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) +get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokkos/bin/nvcc_wrapper ABSOLUTE) +set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE) # hide deprecation warnings temporarily for stable release set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) diff --git a/doc/Makefile b/doc/Makefile index 2a4edc70f3..b652c515e1 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -63,6 +63,7 @@ help: @echo " anchor_check scan for duplicate anchor labels" @echo " style_check check for complete and consistent style lists" @echo " package_check check for complete and consistent package lists" + @echo " role_check check for misformatted role keywords" @echo " spelling spell-check the manual" # ------------------------------------------ @@ -98,6 +99,7 @@ html: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) env LC_ALL=C grep -n '[^ -~]' $(RSTDIR)/*.rst ;\ env LC_ALL=C grep -n ' :[a-z]\+`' $(RSTDIR)/*.rst ;\ env LC_ALL=C grep -n ' `[^`]\+<[a-z][^`]\+`[^_]' $(RSTDIR)/*.rst ;\ + env LC_ALL=C grep -n ':\(ref\|doc\):[^`]' $(RSTDIR)/*.rst ;\ $(PYTHON) $(BUILDDIR)/utils/check-styles.py -s ../src -d src ;\ echo "############################################" ;\ deactivate ;\ @@ -179,6 +181,7 @@ pdf: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) env LC_ALL=C grep -n '[^ -~]' $(RSTDIR)/*.rst ;\ env LC_ALL=C grep -n ' :[a-z]\+`' $(RSTDIR)/*.rst ;\ env LC_ALL=C grep -n ' `[^`]\+<[a-z][^`]\+`[^_]' $(RSTDIR)/*.rst ;\ + env LC_ALL=C grep -n ':\(ref\|doc\):[^`]' $(RSTDIR)/*.rst ;\ $(PYTHON) utils/check-styles.py -s ../src -d src ;\ echo "############################################" ;\ deactivate ;\ @@ -227,6 +230,7 @@ char_check : role_check : @( env LC_ALL=C grep -n ' :[a-z]\+`' $(RSTDIR)/*.rst && exit 1 || : ) @( env LC_ALL=C grep -n ' `[^`]\+<[a-z][^`]\+`[^_]' $(RSTDIR)/*.rst && exit 1 || : ) + @( env LC_ALL=C grep -n ':\(ref\|doc\):[^`]' $(RSTDIR)/*.rst && exit 1 || : ) link_check : $(VENV) html @(\ diff --git a/doc/src/Howto_lammps_gui.rst b/doc/src/Howto_lammps_gui.rst index f7d4cffe13..471424e98b 100644 --- a/doc/src/Howto_lammps_gui.rst +++ b/doc/src/Howto_lammps_gui.rst @@ -90,8 +90,8 @@ The run can be stopped cleanly by using either the ``Stop LAMMPS`` entry in the ``Run`` menu, the hotkey `Ctrl-/` (`Command-/` on macOS), or clicking on the red button in the status bar. This will cause that the running LAMMPS process will complete the current iteration and then -stop. This is equivalent to the command `timer timeout 0 ` and -implemented by calling the :cpp:func:`lammps_force_timeout()` function +stop. This is equivalent to the command :doc:`timer timeout 0 ` +and implemented by calling the :cpp:func:`lammps_force_timeout()` function of the LAMMPS C-library interface. diff --git a/doc/src/compute_saed.rst b/doc/src/compute_saed.rst index 9ec455d03b..3079afb7ce 100644 --- a/doc/src/compute_saed.rst +++ b/doc/src/compute_saed.rst @@ -68,7 +68,7 @@ reciprocal lattice nodes. The mesh spacing is defined either (a) by the entire simulation domain or (b) manually using selected values as shown in the 2D diagram below. -.. image:: img/saed_mesh.jpg +.. image:: img/saed_mesh.png :scale: 75% :align: center diff --git a/doc/src/compute_xrd.rst b/doc/src/compute_xrd.rst index 8673ce9199..fe066f9836 100644 --- a/doc/src/compute_xrd.rst +++ b/doc/src/compute_xrd.rst @@ -72,7 +72,7 @@ reciprocal lattice nodes. The mesh spacing is defined either (a) by the entire simulation domain or (b) manually using selected values as shown in the 2D diagram below. -.. image:: img/xrd_mesh.jpg +.. image:: img/xrd_mesh.png :scale: 75% :align: center diff --git a/doc/src/fix_adapt_fep.rst b/doc/src/fix_adapt_fep.rst index c35986de49..1b2298cd96 100644 --- a/doc/src/fix_adapt_fep.rst +++ b/doc/src/fix_adapt_fep.rst @@ -307,7 +307,9 @@ the :doc:`run ` command. This fix is not invoked during Restrictions """""""""""" - none + +The keyword "scale yes" is not supported for scaling per-atom parameters +diameter and change. You can use :doc:`fix adapt ` for those. Related commands """""""""""""""" diff --git a/doc/src/fix_atom_swap.rst b/doc/src/fix_atom_swap.rst index ffd14ebb0f..aa8127561c 100644 --- a/doc/src/fix_atom_swap.rst +++ b/doc/src/fix_atom_swap.rst @@ -181,6 +181,12 @@ This fix is part of the MC package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. +This fix cannot be used with systems that do not have per-type masses +(e.g. atom style sphere) since the implemented algorithm pre-computes +velocity rescaling factors from per-type masses and ignores any per-atom +masses, if present. In case both, per-type and per-atom masses are +present, a warning is printed. + Related commands """""""""""""""" diff --git a/doc/src/fix_ave_chunk.rst b/doc/src/fix_ave_chunk.rst index 3c358c9aa5..adbfb43d72 100644 --- a/doc/src/fix_ave_chunk.rst +++ b/doc/src/fix_ave_chunk.rst @@ -541,10 +541,10 @@ Restrictions Related commands """""""""""""""" -:doc:`compute `, :doc:`fix ave/atom `, `fix -:doc:ave/histo `, :doc:`fix ave/time `, -:doc:`variable `, :doc:`fix ave/correlate -:doc:`, `fix ave/atogrid ` +:doc:`compute `, :doc:`fix ave/atom `, +:doc:`fix ave/histo `, :doc:`fix ave/time `, +:doc:`variable `, :doc:`fix ave/correlate `, +:doc:`fix ave/grid ` Default diff --git a/doc/src/fix_nh_uef.rst b/doc/src/fix_nh_uef.rst index a515375746..2d4cc32c76 100644 --- a/doc/src/fix_nh_uef.rst +++ b/doc/src/fix_nh_uef.rst @@ -62,7 +62,7 @@ performed using the :doc:`fix deform `, :doc:`fix nvt/sllod `, and :doc:`compute temp/deform ` commands. -The applied flow field is set by the *eps* keyword. The values +The applied flow field is set by the *erate* keyword. The values *edot_x* and *edot_y* correspond to the strain rates in the xx and yy directions. It is implicitly assumed that the flow field is traceless, and therefore the strain rate in the zz direction is eqal diff --git a/doc/src/img/saed_mesh.jpg b/doc/src/img/saed_mesh.jpg deleted file mode 100644 index 7b0bf4117f..0000000000 Binary files a/doc/src/img/saed_mesh.jpg and /dev/null differ diff --git a/doc/src/img/saed_mesh.png b/doc/src/img/saed_mesh.png new file mode 100644 index 0000000000..bd558ce072 Binary files /dev/null and b/doc/src/img/saed_mesh.png differ diff --git a/doc/src/img/xrd_mesh.jpg b/doc/src/img/xrd_mesh.jpg deleted file mode 100644 index 677234caab..0000000000 Binary files a/doc/src/img/xrd_mesh.jpg and /dev/null differ diff --git a/doc/src/img/xrd_mesh.png b/doc/src/img/xrd_mesh.png new file mode 100644 index 0000000000..e58c7322a5 Binary files /dev/null and b/doc/src/img/xrd_mesh.png differ diff --git a/doc/src/improper_amoeba.rst b/doc/src/improper_amoeba.rst index 18c7f11080..1a93b0d32a 100644 --- a/doc/src/improper_amoeba.rst +++ b/doc/src/improper_amoeba.rst @@ -68,8 +68,8 @@ for more info. Related commands """""""""""""""" -:doc:`improper_coeff `, `improper_harmonic -:doc:` +:doc:`improper_coeff `, +:doc:`improper_harmonic ` Default """"""" diff --git a/doc/src/pair_beck.rst b/doc/src/pair_beck.rst index 2bf027515c..6bb4afdc80 100644 --- a/doc/src/pair_beck.rst +++ b/doc/src/pair_beck.rst @@ -30,11 +30,11 @@ Description Style *beck* computes interactions based on the potential by :ref:`(Beck) `, originally designed for simulation of Helium. It -includes truncation at a cutoff distance Rc. +includes truncation at a cutoff distance :math:`r_c`. .. math:: - E(r) &= A \exp\left[-\alpha r - \beta r^6\right] - \frac{B}{\left(r^2+a^2\right)^3} \left(1+\frac{2.709+3a^2}{r^2+a^2}\right) \qquad r < R_c \\ + E(r) &= A \exp\left[-\alpha r - \beta r^6\right] - \frac{B}{\left(r^2+a^2\right)^3} \left(1+\frac{2.709+3a^2}{r^2+a^2}\right) \qquad r < r_c \\ The following coefficients must be defined for each pair of atoms types via the :doc:`pair_coeff ` command as in the examples @@ -50,7 +50,7 @@ commands. * cutoff (distance units) The last coefficient is optional. If not specified, the global cutoff -:math:`R_c` is used. +:math:`r_c` is used. ---------- diff --git a/doc/src/pair_lj_smooth_linear.rst b/doc/src/pair_lj_smooth_linear.rst index 7a3ba7a3d5..20b5e6cbda 100644 --- a/doc/src/pair_lj_smooth_linear.rst +++ b/doc/src/pair_lj_smooth_linear.rst @@ -31,13 +31,13 @@ Style *lj/smooth/linear* computes a truncated and force-shifted LJ interaction (aka Shifted Force Lennard-Jones) that combines the standard 12/6 Lennard-Jones function and subtracts a linear term based on the cutoff distance, so that both, the potential and the force, go -continuously to zero at the cutoff Rc :ref:`(Toxvaerd) `: +continuously to zero at the cutoff :math:`r_c` :ref:`(Toxvaerd) `: .. math:: \phi\left(r\right) & = 4 \epsilon \left[ \left(\frac{\sigma}{r}\right)^{12} - \left(\frac{\sigma}{r}\right)^6 \right] \\ - E\left(r\right) & = \phi\left(r\right) - \phi\left(R_c\right) - \left(r - R_c\right) \left.\frac{d\phi}{d r} \right|_{r=R_c} \qquad r < R_c + E\left(r\right) & = \phi\left(r\right) - \phi\left(r_c\right) - \left(r - r_c\right) \left.\frac{d\phi}{d r} \right|_{r=r_c} \qquad r < r_c The following coefficients must be defined for each pair of atoms types via the :doc:`pair_coeff ` command as in the examples @@ -77,8 +77,9 @@ tail option for adding long-range tail corrections to energy and pressure, since the energy of the pair interaction is smoothed to 0.0 at the cutoff. -This pair style writes its information to :doc:`binary restart files `, so pair_style and pair_coeff commands do not need -to be specified in an input script that reads a restart file. +This pair style writes its information to :doc:`binary restart files `, +so pair_style and pair_coeff commands do not need to be specified +in an input script that reads a restart file. This pair style can only be used via the *pair* keyword of the :doc:`run_style respa ` command. It does not support the diff --git a/doc/src/pair_mie.rst b/doc/src/pair_mie.rst index 089f8d3d29..6e9eec1f5c 100644 --- a/doc/src/pair_mie.rst +++ b/doc/src/pair_mie.rst @@ -35,7 +35,7 @@ The *mie/cut* style computes the Mie potential, given by E = C \epsilon \left[ \left(\frac{\sigma}{r}\right)^{\gamma_{rep}} - \left(\frac{\sigma}{r}\right)^{\gamma_{att}} \right] \qquad r < r_c -Rc is the cutoff and C is a function that depends on the repulsive and +:math:`r_c` is the cutoff and C is a function that depends on the repulsive and attractive exponents, given by: .. math:: diff --git a/doc/src/pair_morse.rst b/doc/src/pair_morse.rst index 807882980d..4b93d182bb 100644 --- a/doc/src/pair_morse.rst +++ b/doc/src/pair_morse.rst @@ -53,7 +53,7 @@ Style *morse* computes pairwise interactions with the formula E = D_0 \left[ e^{- 2 \alpha (r - r_0)} - 2 e^{- \alpha (r - r_0)} \right] \qquad r < r_c -Rc is the cutoff. +:math:`r_c` is the cutoff. The following coefficients must be defined for each pair of atoms types via the :doc:`pair_coeff ` command as in the examples @@ -78,7 +78,7 @@ so that both, potential energy and force, go to zero at the cut-off: .. math:: \phi\left(r\right) & = D_0 \left[ e^{- 2 \alpha (r - r_0)} - 2 e^{- \alpha (r - r_0)} \right] \qquad r < r_c \\ - E\left(r\right) & = \phi\left(r\right) - \phi\left(R_c\right) - \left(r - R_c\right) \left.\frac{d\phi}{d r} \right|_{r=R_c} \qquad r < R_c + E\left(r\right) & = \phi\left(r\right) - \phi\left(r_c\right) - \left(r - r_c\right) \left.\frac{d\phi}{d r} \right|_{r=r_c} \qquad r < r_c The syntax of the pair_style and pair_coeff commands are the same for the *morse* and *morse/smooth/linear* styles. diff --git a/doc/src/pair_soft.rst b/doc/src/pair_soft.rst index 1702811ed9..e21ae28432 100644 --- a/doc/src/pair_soft.rst +++ b/doc/src/pair_soft.rst @@ -44,8 +44,9 @@ It is useful for pushing apart overlapping atoms, since it does not blow up as r goes to 0. A is a prefactor that can be made to vary in time from the start to the end of the run (see discussion below), e.g. to start with a very soft potential and slowly harden the -interactions over time. Rc is the cutoff. See the :doc:`fix nve/limit ` command for another way to push apart -overlapping atoms. +interactions over time. :math:`r_c` is the cutoff. +See the :doc:`fix nve/limit ` command for another way +to push apart overlapping atoms. The following coefficients must be defined for each pair of atom types via the :doc:`pair_coeff ` command as in the examples above, diff --git a/doc/src/pair_spica.rst b/doc/src/pair_spica.rst index 74a069d8a2..859506593f 100644 --- a/doc/src/pair_spica.rst +++ b/doc/src/pair_spica.rst @@ -81,7 +81,7 @@ given by as required for the SPICA (formerly called SDK) and the pSPICA Coarse-grained MD parameterization discussed in :ref:`(Shinoda) `, :ref:`(DeVane) `, :ref:`(Seo) `, and :ref:`(Miyazaki) `. -Rc is the cutoff. +:math:`r_c` is the cutoff. Summary information on these force fields can be found at https://www.spica-ff.org Style *lj/spica/coul/long* computes the adds Coulombic interactions diff --git a/doc/utils/sphinx-config/LAMMPSLexer.py b/doc/utils/sphinx-config/LAMMPSLexer.py index a7ba5d92a8..ee548dc602 100644 --- a/doc/utils/sphinx-config/LAMMPSLexer.py +++ b/doc/utils/sphinx-config/LAMMPSLexer.py @@ -76,12 +76,12 @@ class LAMMPSLexer(RegexLexer): include('conditionals'), include('keywords'), (r'#.*?\n', Comment), - ('"', String, 'string'), - ('\'', String, 'single_quote_string'), + (r'"', String, 'string'), + (r'\'', String, 'single_quote_string'), (r'[0-9]+:[0-9]+(:[0-9]+)?', Number), (r'[0-9]+(\.[0-9]+)?([eE]\-?[0-9]+)?', Number), - ('\$?\(', Name.Variable, 'expression'), - ('\$\{', Name.Variable, 'variable'), + (r'\$?\(', Name.Variable, 'expression'), + (r'\$\{', Name.Variable, 'variable'), (r'[\w_\.\[\]]+', Name), (r'\$[\w_]+', Name.Variable), (r'\s+', Whitespace), @@ -97,21 +97,21 @@ class LAMMPSLexer(RegexLexer): ] , 'variable' : [ - ('[^\}]+', Name.Variable), - ('\}', Name.Variable, '#pop'), + (r'[^\}]+', Name.Variable), + (r'\}', Name.Variable, '#pop'), ], 'string' : [ - ('[^"]+', String), - ('"', String, '#pop'), + (r'[^"]+', String), + (r'"', String, '#pop'), ], 'single_quote_string' : [ - ('[^\']+', String), - ('\'', String, '#pop'), + (r'[^\']+', String), + (r'\'', String, '#pop'), ], 'expression' : [ - ('[^\(\)]+', Name.Variable), - ('\(', Name.Variable, 'expression'), - ('\)', Name.Variable, '#pop'), + (r'[^\(\)]+', Name.Variable), + (r'\(', Name.Variable, 'expression'), + (r'\)', Name.Variable, '#pop'), ], 'modify_cmd' : [ (r'[\w_\-\.\[\]]+', Name.Variable.Identifier), diff --git a/lib/pace/Install.py b/lib/pace/Install.py index 4f3cf299ac..8d31852e44 100644 --- a/lib/pace/Install.py +++ b/lib/pace/Install.py @@ -18,11 +18,11 @@ from install_helpers import fullpath, geturl, checkmd5sum, getfallback # settings thisdir = fullpath('.') -version ='v.2023.01.3.fix' +version ='v.2023.10.04' # known checksums for different PACE versions. used to validate the download. checksums = { \ - 'v.2023.01.3.fix': '4f0b3b5b14456fe9a73b447de3765caa' + 'v.2023.10.04': '70ff79f4e59af175e55d24f3243ad1ff' } parser = ArgumentParser(prog='Install.py', description="LAMMPS library build wrapper script") diff --git a/python/install.py b/python/install.py index 853479e9f6..fd9f95f1bf 100644 --- a/python/install.py +++ b/python/install.py @@ -18,7 +18,7 @@ parser = ArgumentParser(prog='install.py', description='LAMMPS python package installer script') parser.add_argument("-p", "--package", required=True, - help="path to the LAMMPS Python package") + help="path to the LAMMPS Python package folder") parser.add_argument("-l", "--lib", required=True, help="path to the compiled LAMMPS shared library") parser.add_argument("-n", "--noinstall", action="store_true", default=False, @@ -34,15 +34,21 @@ args = parser.parse_args() if args.package: if not os.path.exists(args.package): - print("ERROR: LAMMPS package folder %s does not exist" % args.package) + print("\nERROR: LAMMPS package folder %s does not exist\n" % args.package) parser.print_help() sys.exit(1) else: args.package = os.path.abspath(args.package) + if ((os.path.basename(args.package) != "lammps") + and ((os.path.basename(os.path.dirname(args.package)) != "python"))): + print("\nERROR: LAMMPS package folder path %s does not end in %s\n" + % (args.package, os.path.join("python", "lammps"))) + parser.print_help() + sys.exit(1) if args.lib: if not os.path.exists(args.lib): - print("ERROR: LAMMPS shared library %s does not exist" % args.lib) + print("\nERROR: LAMMPS shared library %s does not exist\n" % args.lib) parser.print_help() sys.exit(1) else: @@ -50,7 +56,7 @@ if args.lib: if args.wheeldir: if not os.path.exists(args.wheeldir): - print("ERROR: directory %s to store the wheel does not exist" % args.wheeldir) + print("\nERROR: directory %s to store the wheel does not exist\n" % args.wheeldir) parser.print_help() sys.exit(1) else: @@ -58,7 +64,7 @@ if args.wheeldir: if args.versionfile: if not os.path.exists(args.versionfile): - print("ERROR: LAMMPS version file at %s does not exist" % args.versionfile) + print("\nERROR: LAMMPS version file at %s does not exist\n" % args.versionfile) parser.print_help() sys.exit(1) else: diff --git a/python/lammps/core.py b/python/lammps/core.py index 84a80e77a3..1ff123760b 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -379,8 +379,9 @@ class lammps(object): for i in range(narg): if type(cmdargs[i]) is str: cmdargs[i] = cmdargs[i].encode() - cargs = (c_char_p*narg)(*cmdargs) - self.lib.lammps_open.argtypes = [c_int, c_char_p*narg, MPI_Comm, c_void_p] + cargs = (c_char_p*(narg+1))(*cmdargs) + cargs[narg] = None + self.lib.lammps_open.argtypes = [c_int, c_char_p*(narg+1), MPI_Comm, c_void_p] else: self.lib.lammps_open.argtypes = [c_int, c_char_p, MPI_Comm, c_void_p] @@ -399,8 +400,9 @@ class lammps(object): for i in range(narg): if type(cmdargs[i]) is str: cmdargs[i] = cmdargs[i].encode() - cargs = (c_char_p*narg)(*cmdargs) - self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p*narg, c_void_p] + cargs = (c_char_p*(narg+1))(*cmdargs) + cargs[narg] = None + self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p*(narg+1), c_void_p] self.lmp = c_void_p(self.lib.lammps_open_no_mpi(narg,cargs,None)) else: self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p, c_void_p] diff --git a/src/BOCS/fix_bocs.cpp b/src/BOCS/fix_bocs.cpp index d17884855a..17bb1af002 100644 --- a/src/BOCS/fix_bocs.cpp +++ b/src/BOCS/fix_bocs.cpp @@ -1024,7 +1024,10 @@ void FixBocs::final_integrate() if (pstat_flag) { if (pstyle == ISO) pressure->compute_scalar(); - else pressure->compute_vector(); + else { + temperature->compute_vector(); + pressure->compute_vector(); + } couple(); pressure->addstep(update->ntimestep+1); } @@ -1961,6 +1964,7 @@ void FixBocs::nhc_press_integrate() int ich,i,pdof; double expfac,factor_etap,kecurrent; double kt = boltz * t_target; + double lkt_press; // Update masses, to preserve initial freq, if flag set @@ -2006,7 +2010,8 @@ void FixBocs::nhc_press_integrate() } } - double lkt_press = pdof * kt; + if (pstyle == ISO) lkt_press = kt; + else lkt_press = pdof * kt; etap_dotdot[0] = (kecurrent - lkt_press)/etap_mass[0]; double ncfac = 1.0/nc_pchain; diff --git a/src/DPD-MESO/fix_mvv_dpd.cpp b/src/DPD-MESO/fix_mvv_dpd.cpp index 18c88bd293..d51000b15b 100644 --- a/src/DPD-MESO/fix_mvv_dpd.cpp +++ b/src/DPD-MESO/fix_mvv_dpd.cpp @@ -63,13 +63,20 @@ int FixMvvDPD::setmask() void FixMvvDPD::init() { if (!atom->vest_flag) - error->all(FLERR,"Fix mvv/dpd requires atom attribute vest"); + error->all(FLERR,"Fix mvv/dpd requires atom attribute vest e.g. from atom style mdpd"); + + if (!force->pair_match("^mdpd",0) && !force->pair_match("^dpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!(force->pair_match("^mdpd",0,1) || force->pair_match("^dpd",0),1)) { + error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd"); + } + } else { + error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd"); + } + } dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - - if (!force->pair_match("^edpd",0) && !force->pair_match("^dpd",0)) - error->all(FLERR, "Must use a dpd or edpd pair style with fix mvv/edpd"); } /* ---------------------------------------------------------------------- diff --git a/src/DPD-MESO/fix_mvv_edpd.cpp b/src/DPD-MESO/fix_mvv_edpd.cpp index 03dd048119..7ac0dc3de7 100644 --- a/src/DPD-MESO/fix_mvv_edpd.cpp +++ b/src/DPD-MESO/fix_mvv_edpd.cpp @@ -71,11 +71,20 @@ int FixMvvEDPD::setmask() void FixMvvEDPD::init() { + if (!atom->edpd_flag) error->all(FLERR,"Fix mvv/edpd requires atom style edpd"); + + if (!force->pair_match("^edpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!force->pair_match("^edpd",0,1)) { + error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); + } + } else { + error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); + } + } + dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - - if (!force->pair_match("^edpd",0)) - error->all(FLERR, "Must use pair style edpd with fix mvv/edpd"); } /* ---------------------------------------------------------------------- diff --git a/src/DPD-MESO/fix_mvv_tdpd.cpp b/src/DPD-MESO/fix_mvv_tdpd.cpp index f3894da214..122fd56365 100644 --- a/src/DPD-MESO/fix_mvv_tdpd.cpp +++ b/src/DPD-MESO/fix_mvv_tdpd.cpp @@ -69,10 +69,20 @@ int FixMvvTDPD::setmask() void FixMvvTDPD::init() { + if (!atom->tdpd_flag) error->all(FLERR,"Fix mvv/tdpd requires atom style tdpd"); + + if (!force->pair_match("^tdpd",0)) { + if (force->pair_match("^hybrid",0)) { + if (!force->pair_match("^tdpd",0,1)) { + error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); + } + } else { + error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); + } + } + dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (!force->pair_match("^tdpd",0)) - error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd"); } /* ---------------------------------------------------------------------- diff --git a/src/Depend.sh b/src/Depend.sh index 4004f12686..5022d5c734 100755 --- a/src/Depend.sh +++ b/src/Depend.sh @@ -64,6 +64,7 @@ fi if (test $1 = "COLLOID") then depend GPU + depend KOKKOS depend OPENMP fi diff --git a/src/EXTRA-DUMP/dump_yaml.cpp b/src/EXTRA-DUMP/dump_yaml.cpp index 3ca5c59edf..6c21c24f77 100644 --- a/src/EXTRA-DUMP/dump_yaml.cpp +++ b/src/EXTRA-DUMP/dump_yaml.cpp @@ -24,6 +24,8 @@ using namespace LAMMPS_NS; +static constexpr char special_chars[] = "{}[],&:*#?|-<>=!%@\\"; + /* ---------------------------------------------------------------------- */ DumpYAML::DumpYAML(class LAMMPS *_lmp, int narg, char **args) : DumpCustom(_lmp, narg, args), thermo(false) @@ -67,7 +69,12 @@ void DumpYAML::write_header(bigint ndump) const auto &fields = th->get_fields(); thermo_data += "thermo:\n - keywords: [ "; - for (int i = 0; i < nfield; ++i) thermo_data += fmt::format("{}, ", keywords[i]); + for (int i = 0; i < nfield; ++i) { + if (keywords[i].find_first_of(special_chars) == std::string::npos) + thermo_data += fmt::format("{}, ", keywords[i]); + else + thermo_data += fmt::format("'{}', ", keywords[i]); + } thermo_data += "]\n - data: [ "; for (int i = 0; i < nfield; ++i) { @@ -107,7 +114,12 @@ void DumpYAML::write_header(bigint ndump) if (domain->triclinic) fmt::print(fp, " - [ {}, {}, {} ]\n", boxxy, boxxz, boxyz); fmt::print(fp, "keywords: [ "); - for (const auto &item : utils::split_words(columns)) fmt::print(fp, "{}, ", item); + for (const auto &item : utils::split_words(columns)) { + if (item.find_first_of(special_chars) == std::string::npos) + fmt::print(fp, "{}, ", item); + else + fmt::print(fp, "'{}', ", item); + } fputs(" ]\ndata:\n", fp); } else // reset so that the remainder of the output is not multi-proc filewriter = 0; diff --git a/src/FEP/fix_adapt_fep.cpp b/src/FEP/fix_adapt_fep.cpp index e050b8cf21..e0c5868e96 100644 --- a/src/FEP/fix_adapt_fep.cpp +++ b/src/FEP/fix_adapt_fep.cpp @@ -40,17 +40,17 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR,KSPACE,ATOM}; -enum{DIAMETER,CHARGE}; +enum{PAIR, KSPACE, ATOM}; +enum{DIAMETER, CHARGE}; /* ---------------------------------------------------------------------- */ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { - if (narg < 5) error->all(FLERR,"Illegal fix adapt/fep command"); + if (narg < 5) utils::missing_cmd_args(FLERR,"fix adapt/fep", error); nevery = utils::inumeric(FLERR,arg[3],false,lmp); - if (nevery < 0) error->all(FLERR,"Illegal fix adapt/fep command"); + if (nevery < 0) error->all(FLERR,"Illegal fix adapt/fep every value {}", nevery); dynamic_group_allow = 1; create_attribute = 1; @@ -62,21 +62,21 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : int iarg = 4; while (iarg < narg) { if (strcmp(arg[iarg],"pair") == 0) { - if (iarg+6 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); + if (iarg+6 > narg) utils::missing_cmd_args(FLERR,"fix adapt/fep pair", error); nadapt++; iarg += 6; } else if (strcmp(arg[iarg],"kspace") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR,"fix adapt/fep kspace", error); nadapt++; iarg += 2; } else if (strcmp(arg[iarg],"atom") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR,"fix adapt/fep atom", error); nadapt++; iarg += 4; } else break; } - if (nadapt == 0) error->all(FLERR,"Illegal fix adapt/fep command"); + if (nadapt == 0) error->all(FLERR,"Nothing to adapt in fix adapt/fep command"); adapt = new Adapt[nadapt]; // parse keywords @@ -136,11 +136,11 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"reset") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR,"fix adapt/fep reset", error); resetflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"scale") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix adapt/fep command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR,"fix adapt/fep scale", error); scaleflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"after") == 0) { @@ -165,21 +165,21 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) : FixAdaptFEP::~FixAdaptFEP() { for (int m = 0; m < nadapt; m++) { - delete [] adapt[m].var; + delete[] adapt[m].var; if (adapt[m].which == PAIR) { - delete [] adapt[m].pstyle; - delete [] adapt[m].pparam; + delete[] adapt[m].pstyle; + delete[] adapt[m].pparam; memory->destroy(adapt[m].array_orig); } } - delete [] adapt; + delete[] adapt; // check nfix in case all fixes have already been deleted if (id_fix_diam && modify->nfix) modify->delete_fix(id_fix_diam); if (id_fix_chg && modify->nfix) modify->delete_fix(id_fix_chg); - delete [] id_fix_diam; - delete [] id_fix_chg; + delete[] id_fix_diam; + delete[] id_fix_chg; } /* ---------------------------------------------------------------------- */ @@ -208,7 +208,7 @@ void FixAdaptFEP::post_constructor() id_fix_diam = nullptr; id_fix_chg = nullptr; - if (diam_flag) { + if (diam_flag && atom->radius_flag) { id_fix_diam = utils::strdup(id + std::string("_FIX_STORE_DIAM")); fix_diam = dynamic_cast( modify->add_fix(fmt::format("{} {} STORE/ATOM 1 0 0 1", id_fix_diam,group->names[igroup]))); @@ -226,7 +226,7 @@ void FixAdaptFEP::post_constructor() } } - if (chgflag) { + if (chgflag && atom->q_flag) { id_fix_chg = utils::strdup(id + std::string("_FIX_STORE_CHG")); fix_chg = dynamic_cast( modify->add_fix(fmt::format("{} {} STORE/ATOM 1 0 0 1",id_fix_chg,group->names[igroup]))); @@ -267,9 +267,9 @@ void FixAdaptFEP::init() ad->ivar = input->variable->find(ad->var); if (ad->ivar < 0) - error->all(FLERR,"Variable name for fix adapt/fep does not exist"); + error->all(FLERR,"Variable name {} for fix adapt/fep does not exist", ad->var); if (!input->variable->equalstyle(ad->ivar)) - error->all(FLERR,"Variable for fix adapt/fep is invalid style"); + error->all(FLERR,"Variable {} for fix adapt/fep is invalid style", ad->var); if (ad->which == PAIR) { anypair = 1; @@ -285,8 +285,9 @@ void FixAdaptFEP::init() if (ptr == nullptr) error->all(FLERR,"Fix adapt/fep pair style param not supported"); - ad->pdim = 2; - if (ad->pdim == 0) ad->scalar = (double *) ptr; + if (ad->pdim != 2) + error->all(FLERR,"Pair style parameter {} is not compatible with fix adapt/fep", ad->pparam); + if (ad->pdim == 2) ad->array = (double **) ptr; // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style @@ -434,6 +435,8 @@ void FixAdaptFEP::change_settings() } else if (ad->which == ATOM) { + if (scaleflag) + error->all(FLERR, "Keyword 'scale yes' is not supported with fix adapt/fep for 'atom'"); // reset radius from diameter // also scale rmass to new value diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index 03537e7b88..bc393b29d8 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -44,6 +44,9 @@ AtomKokkos::AtomKokkos(LAMMPS *lmp) : Atom(lmp) h_tag_min = Kokkos::subview(h_tag_min_max,0); h_tag_max = Kokkos::subview(h_tag_min_max,1); + + nprop_atom = 0; + fix_prop_atom = nullptr; } /* ---------------------------------------------------------------------- */ @@ -112,6 +115,7 @@ AtomKokkos::~AtomKokkos() memoryKK->destroy_kokkos(k_dvector, dvector); dvector = nullptr; + delete [] fix_prop_atom; } /* ---------------------------------------------------------------------- */ @@ -125,11 +129,37 @@ void AtomKokkos::init() /* ---------------------------------------------------------------------- */ +void AtomKokkos::update_property_atom() +{ + nprop_atom = 0; + std::vector prop_atom_fixes; + for (auto &ifix : modify->get_fix_by_style("^property/atom")) { + if (!ifix->kokkosable) + error->all(FLERR, "KOKKOS package requires a Kokkos-enabled version of fix property/atom"); + + ++nprop_atom; + prop_atom_fixes.push_back(ifix); + } + + delete[] fix_prop_atom; + fix_prop_atom = new FixPropertyAtomKokkos *[nprop_atom]; + + int n = 0; + for (auto &ifix : prop_atom_fixes) + fix_prop_atom[n++] = dynamic_cast(ifix); +} + +/* ---------------------------------------------------------------------- */ + void AtomKokkos::sync(const ExecutionSpace space, unsigned int mask) { - if (space == Device && lmp->kokkos->auto_sync) avecKK->modified(Host, mask); + if (space == Device && lmp->kokkos->auto_sync) { + avecKK->modified(Host, mask); + for (int n = 0; n < nprop_atom; n++) fix_prop_atom[n]->modified(Host, mask); + } avecKK->sync(space, mask); + for (int n = 0; n < nprop_atom; n++) fix_prop_atom[n]->sync(space, mask); } /* ---------------------------------------------------------------------- */ @@ -137,13 +167,20 @@ void AtomKokkos::sync(const ExecutionSpace space, unsigned int mask) void AtomKokkos::modified(const ExecutionSpace space, unsigned int mask) { avecKK->modified(space, mask); + for (int n = 0; n < nprop_atom; n++) fix_prop_atom[n]->modified(space, mask); - if (space == Device && lmp->kokkos->auto_sync) avecKK->sync(Host, mask); + if (space == Device && lmp->kokkos->auto_sync) { + avecKK->sync(Host, mask); + for (int n = 0; n < nprop_atom; n++) fix_prop_atom[n]->sync(Host, mask); + } } +/* ---------------------------------------------------------------------- */ + void AtomKokkos::sync_overlapping_device(const ExecutionSpace space, unsigned int mask) { avecKK->sync_overlapping_device(space, mask); + for (int n = 0; n < nprop_atom; n++) fix_prop_atom[n]->sync_overlapping_device(space, mask); } /* ---------------------------------------------------------------------- */ @@ -375,7 +412,7 @@ AtomVec *AtomKokkos::new_avec(const std::string &style, int trysuffix, int &sfla int hybrid_substyle_flag = (avec != nullptr); AtomVec *avec = Atom::new_avec(style, trysuffix, sflag); - if (!avec->kokkosable) error->all(FLERR, "KOKKOS package requires a kokkos enabled atom_style"); + if (!avec->kokkosable) error->all(FLERR, "KOKKOS package requires a Kokkos-enabled atom_style"); if (!hybrid_substyle_flag) avecKK = dynamic_cast(avec); diff --git a/src/KOKKOS/atom_kokkos.h b/src/KOKKOS/atom_kokkos.h index 23566cff03..e077a4033e 100644 --- a/src/KOKKOS/atom_kokkos.h +++ b/src/KOKKOS/atom_kokkos.h @@ -14,6 +14,7 @@ #include "atom.h" // IWYU pragma: export #include "kokkos_type.h" +#include "fix_property_atom_kokkos.h" #include @@ -25,6 +26,8 @@ namespace LAMMPS_NS { class AtomKokkos : public Atom { public: bool sort_classic; + int nprop_atom; + FixPropertyAtomKokkos** fix_prop_atom; DAT::tdual_tagint_1d k_tag; DAT::tdual_int_1d k_type, k_mask; @@ -144,6 +147,7 @@ class AtomKokkos : public Atom { } void init() override; + void update_property_atom(); void allocate_type_arrays() override; void sync(const ExecutionSpace space, unsigned int mask); void modified(const ExecutionSpace space, unsigned int mask); diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index a8ce29f666..c3430b9f6e 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -963,7 +963,6 @@ void AtomVecDPDKokkos::sync(ExecutionSpace space, unsigned int mask) if (mask & UCG_MASK) atomKK->k_uCG.sync(); if (mask & UCGNEW_MASK) atomKK->k_uCGnew.sync(); if (mask & DUCHEM_MASK) atomKK->k_duChem.sync(); - if (mask & DVECTOR_MASK) atomKK->k_dvector.sync(); } else { if (mask & X_MASK) atomKK->k_x.sync(); if (mask & V_MASK) atomKK->k_v.sync(); @@ -980,7 +979,6 @@ void AtomVecDPDKokkos::sync(ExecutionSpace space, unsigned int mask) if (mask & UCG_MASK) atomKK->k_uCG.sync(); if (mask & UCGNEW_MASK) atomKK->k_uCGnew.sync(); if (mask & DUCHEM_MASK) atomKK->k_duChem.sync(); - if (mask & DVECTOR_MASK) atomKK->k_dvector.sync(); } } @@ -1019,8 +1017,6 @@ void AtomVecDPDKokkos::sync_overlapping_device(ExecutionSpace space, unsigned in perform_async_copy(atomKK->k_uCGnew,space); if ((mask & DUCHEM_MASK) && atomKK->k_duChem.need_sync()) perform_async_copy(atomKK->k_duChem,space); - if ((mask & DVECTOR_MASK) && atomKK->k_dvector.need_sync()) - perform_async_copy(atomKK->k_dvector,space); } else { if ((mask & X_MASK) && atomKK->k_x.need_sync()) perform_async_copy(atomKK->k_x,space); @@ -1052,8 +1048,6 @@ void AtomVecDPDKokkos::sync_overlapping_device(ExecutionSpace space, unsigned in perform_async_copy(atomKK->k_uCGnew,space); if ((mask & DUCHEM_MASK) && atomKK->k_duChem.need_sync()) perform_async_copy(atomKK->k_duChem,space); - if ((mask & DVECTOR_MASK) && atomKK->k_dvector.need_sync()) - perform_async_copy(atomKK->k_dvector,space); } } @@ -1077,7 +1071,6 @@ void AtomVecDPDKokkos::modified(ExecutionSpace space, unsigned int mask) if (mask & UCG_MASK) atomKK->k_uCG.modify(); if (mask & UCGNEW_MASK) atomKK->k_uCGnew.modify(); if (mask & DUCHEM_MASK) atomKK->k_duChem.modify(); - if (mask & DVECTOR_MASK) atomKK->k_dvector.modify(); } else { if (mask & X_MASK) atomKK->k_x.modify(); if (mask & V_MASK) atomKK->k_v.modify(); @@ -1094,6 +1087,5 @@ void AtomVecDPDKokkos::modified(ExecutionSpace space, unsigned int mask) if (mask & UCG_MASK) atomKK->k_uCG.modify(); if (mask & UCGNEW_MASK) atomKK->k_uCGnew.modify(); if (mask & DUCHEM_MASK) atomKK->k_duChem.modify(); - if (mask & DVECTOR_MASK) atomKK->k_dvector.modify(); } } diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index 310f1f4d48..9d267176f1 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -139,6 +139,8 @@ class AtomVecKokkos : virtual public AtomVec { DAT::tdual_int_1d k_count; + public: + #ifdef LMP_KOKKOS_GPU template Kokkos::Viewk_fm.clear_sync_state(); // will be cleared below + atomKK->k_fm_long.clear_sync_state(); // will be cleared below + + // local variables for lambda capture + + auto l_fm = atomKK->k_fm.d_view; + auto l_fm_long = atomKK->k_fm_long.d_view; + + Kokkos::parallel_for(nzero, LAMMPS_LAMBDA(int i) { + l_fm(i,0) = 0.0; + l_fm(i,1) = 0.0; + l_fm(i,2) = 0.0; + l_fm_long(i,0) = 0.0; + l_fm_long(i,1) = 0.0; + l_fm_long(i,2) = 0.0; + }); + + atomKK->modified(Device,FM_MASK|FML_MASK); + } +} + /* ---------------------------------------------------------------------- */ void AtomVecSpinKokkos::sync(ExecutionSpace space, unsigned int mask) diff --git a/src/KOKKOS/atom_vec_spin_kokkos.h b/src/KOKKOS/atom_vec_spin_kokkos.h index d14d01fb62..f0145e4db7 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.h +++ b/src/KOKKOS/atom_vec_spin_kokkos.h @@ -34,6 +34,7 @@ class AtomVecSpinKokkos : public AtomVecKokkos, public AtomVecSpin { AtomVecSpinKokkos(class LAMMPS *); void grow(int) override; void grow_pointers() override; + void force_clear(int, size_t) override; void sort_kokkos(Kokkos::BinSort &Sorter) override; int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, diff --git a/src/KOKKOS/fix_dt_reset_kokkos.cpp b/src/KOKKOS/fix_dt_reset_kokkos.cpp index f3435e711e..6e7709ace1 100644 --- a/src/KOKKOS/fix_dt_reset_kokkos.cpp +++ b/src/KOKKOS/fix_dt_reset_kokkos.cpp @@ -52,14 +52,6 @@ void FixDtResetKokkos::init() { FixDtReset::init(); - k_emax = Kokkos::DualView("FixDtResetKokkos:gamma", 1); - - k_emax.h_view(0) = emax; - - - k_emax.template modify(); - k_emax.template sync(); - if (utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Cannot (yet) use respa with Kokkos"); } @@ -93,43 +85,38 @@ void FixDtResetKokkos::end_of_step() MPI_Allreduce(MPI_IN_PLACE, &dt, 1, MPI_DOUBLE, MPI_MIN, world); - atomKK->modified(execution_space, F_MASK); + if (minbound) dt = MAX(dt, tmin); + if (maxbound) dt = MIN(dt, tmax); - if (minbound) dt = MAX(dt, tmin); - if (maxbound) dt = MIN(dt, tmax); + // if timestep didn't change, just return + // else reset update->dt and other classes that depend on it + // rRESPA, pair style, fixes - // if timestep didn't change, just return - // else reset update->dt and other classes that depend on it - // rRESPA, pair style, fixes + if (dt == update->dt) return; - if (dt == update->dt) return; + laststep = update->ntimestep; - laststep = update->ntimestep; - - // calls to other classes that need to know timestep size changed - // similar logic is in Input::timestep() - - update->update_time(); - update->dt = dt; - update->dt_default = 0; - if (force->pair) force->pair->reset_dt(); - for (int i = 0; i < modify->nfix; i++) modify->fix[i]->reset_dt(); - output->reset_dt(); + // calls to other classes that need to know timestep size changed + // similar logic is in Input::timestep() + update->update_time(); + update->dt = dt; + update->dt_default = 0; + if (force->pair) force->pair->reset_dt(); + for (auto &ifix : modify->get_fix_list()) ifix->reset_dt(); + output->reset_dt(); } /* ---------------------------------------------------------------------- */ template KOKKOS_INLINE_FUNCTION -void FixDtResetKokkos::operator()(TagFixDtResetMass, const int &i, double &k_dt) const { +void FixDtResetKokkos::operator()(TagFixDtResetMass, const int &i, double &dt_min) const { - double dtv, dtf, dte, dtsq; + double dt, dtv, dtf, dte, dtsq; double vsq, fsq, massinv; double delx, dely, delz, delr; - double emax = k_emax.d_view(0); - if (mask[i] & groupbit) { massinv = 1.0 / mass[type[i]]; @@ -138,32 +125,31 @@ void FixDtResetKokkos::operator()(TagFixDtResetMass, const int &i, d dtv = dtf = dte = BIG; if (vsq > 0.0) dtv = xmax / sqrt(vsq); if (fsq > 0.0) dtf = sqrt(2.0 * xmax / (ftm2v * sqrt(fsq) * massinv)); - k_dt = MIN(dtv, dtf); + dt = MIN(dtv, dtf); if ((emax > 0.0) && (fsq * vsq > 0.0)) { dte = emax / sqrt(fsq * vsq) / sqrt(ftm2v * mvv2e); - k_dt = MIN(dt, dte); + dt = MIN(dt, dte); } - dtsq = k_dt * k_dt; - delx = k_dt * v(i,0) + 0.5 * dtsq * massinv * f(i,0) * ftm2v; - dely = k_dt * v(i,1) + 0.5 * dtsq * massinv * f(i,1) * ftm2v; - delz = k_dt * v(i,2) + 0.5 * dtsq * massinv * f(i,2) * ftm2v; + dtsq = dt * dt; + delx = dt * v(i,0) + 0.5 * dtsq * massinv * f(i,0) * ftm2v; + dely = dt * v(i,1) + 0.5 * dtsq * massinv * f(i,1) * ftm2v; + delz = dt * v(i,2) + 0.5 * dtsq * massinv * f(i,2) * ftm2v; delr = sqrt(delx * delx + dely * dely + delz * delz); - if (delr > xmax) k_dt *= xmax / delr; + if (delr > xmax) dt *= xmax / delr; + dt_min = MIN(dt_min,dt); } - } +} /* ---------------------------------------------------------------------- */ template KOKKOS_INLINE_FUNCTION -void FixDtResetKokkos::operator()(TagFixDtResetRMass, const int &i, double &k_dt) const { +void FixDtResetKokkos::operator()(TagFixDtResetRMass, const int &i, double &dt_min) const { - double dtv, dtf, dte, dtsq; + double dt, dtv, dtf, dte, dtsq; double vsq, fsq, massinv; double delx, dely, delz, delr; - double emax = k_emax.d_view(0); - if (mask[i] & groupbit) { massinv = 1.0 / rmass[i]; @@ -172,17 +158,18 @@ void FixDtResetKokkos::operator()(TagFixDtResetRMass, const int &i, dtv = dtf = dte = BIG; if (vsq > 0.0) dtv = xmax / sqrt(vsq); if (fsq > 0.0) dtf = sqrt(2.0 * xmax / (ftm2v * sqrt(fsq) * massinv)); - k_dt = MIN(dtv, dtf); + dt = MIN(dtv, dtf); if ((emax > 0.0) && (fsq * vsq > 0.0)) { dte = emax / sqrt(fsq * vsq) / sqrt(ftm2v * mvv2e); - k_dt = MIN(dt, dte); + dt = MIN(dt, dte); } - dtsq = k_dt * k_dt; - delx = k_dt * v(i,0) + 0.5 * dtsq * massinv * f(i,0) * ftm2v; - dely = k_dt * v(i,1) + 0.5 * dtsq * massinv * f(i,1) * ftm2v; - delz = k_dt * v(i,2) + 0.5 * dtsq * massinv * f(i,2) * ftm2v; + dtsq = dt * dt; + delx = dt * v(i,0) + 0.5 * dtsq * massinv * f(i,0) * ftm2v; + dely = dt * v(i,1) + 0.5 * dtsq * massinv * f(i,1) * ftm2v; + delz = dt * v(i,2) + 0.5 * dtsq * massinv * f(i,2) * ftm2v; delr = sqrt(delx * delx + dely * dely + delz * delz); - if (delr > xmax) k_dt *= xmax / delr; + if (delr > xmax) dt *= xmax / delr; + dt_min = MIN(dt_min,dt); } } diff --git a/src/KOKKOS/fix_enforce2d_kokkos.cpp b/src/KOKKOS/fix_enforce2d_kokkos.cpp index 11402e4568..24cf307827 100644 --- a/src/KOKKOS/fix_enforce2d_kokkos.cpp +++ b/src/KOKKOS/fix_enforce2d_kokkos.cpp @@ -17,15 +17,14 @@ ------------------------------------------------------------------------- */ #include "fix_enforce2d_kokkos.h" + #include "atom_masks.h" #include "atom_kokkos.h" #include "comm.h" #include "error.h" - using namespace LAMMPS_NS; - template FixEnforce2DKokkos::FixEnforce2DKokkos(LAMMPS *lmp, int narg, char **arg) : FixEnforce2D(lmp, narg, arg) @@ -34,21 +33,16 @@ FixEnforce2DKokkos::FixEnforce2DKokkos(LAMMPS *lmp, int narg, char * atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; - datamask_read = V_MASK | F_MASK | OMEGA_MASK | MASK_MASK - | TORQUE_MASK | ANGMOM_MASK; - - datamask_modify = V_MASK | F_MASK | OMEGA_MASK - | TORQUE_MASK | ANGMOM_MASK; + datamask_read = V_MASK | F_MASK | OMEGA_MASK | MASK_MASK | TORQUE_MASK | ANGMOM_MASK; + datamask_modify = V_MASK | F_MASK | OMEGA_MASK | TORQUE_MASK | ANGMOM_MASK; } - template void FixEnforce2DKokkos::setup(int vflag) { post_force(vflag); } - template void FixEnforce2DKokkos::post_force(int /*vflag*/) { @@ -66,7 +60,6 @@ void FixEnforce2DKokkos::post_force(int /*vflag*/) if (atomKK->torque_flag) torque = atomKK->k_torque.view(); - mask = atomKK->k_mask.view(); int nlocal = atomKK->nlocal; @@ -125,13 +118,6 @@ void FixEnforce2DKokkos::post_force(int /*vflag*/) copymode = 0; atomKK->modified(execution_space,datamask_modify); - - for (int m = 0; m < nfixlist; m++) { - atomKK->sync(flist[m]->execution_space,flist[m]->datamask_read); - flist[m]->enforce2d(); - atomKK->modified(flist[m]->execution_space,flist[m]->datamask_modify); - } - } diff --git a/src/KOKKOS/fix_property_atom_kokkos.cpp b/src/KOKKOS/fix_property_atom_kokkos.cpp index 1de07b39dc..dcd943cac6 100644 --- a/src/KOKKOS/fix_property_atom_kokkos.cpp +++ b/src/KOKKOS/fix_property_atom_kokkos.cpp @@ -30,7 +30,46 @@ FixPropertyAtomKokkos::FixPropertyAtomKokkos(LAMMPS *lmp, int narg, char **arg) FixPropertyAtom(lmp, narg, arg) { atomKK = (AtomKokkos *) atom; - grow_arrays(atom->nmax); + kokkosable = 1; + + dvector_flag = 0; + for (int nv = 0; nv < nvalue; nv++) + if (styles[nv] == DVEC) dvector_flag = 1; +} + +/* ---------------------------------------------------------------------- */ + +void FixPropertyAtomKokkos::post_constructor() +{ + atomKK->update_property_atom(); + + FixPropertyAtom::post_constructor(); +} + +/* ---------------------------------------------------------------------- */ + +FixPropertyAtomKokkos::~FixPropertyAtomKokkos() +{ + // deallocate per-atom vectors in Atom class + // set ptrs to a null pointer, so they no longer exist for Atom class + + for (int nv = 0; nv < nvalue; nv++) { + if (styles[nv] == MOLECULE) { + atom->molecule_flag = 0; + memoryKK->destroy_kokkos(atomKK->k_molecule,atom->molecule); + atom->molecule = nullptr; + } else if (styles[nv] == CHARGE) { + atom->q_flag = 0; + memoryKK->destroy_kokkos(atomKK->k_q,atom->q); + atom->q = nullptr; + } else if (styles[nv] == RMASS) { + atom->rmass_flag = 0; + memoryKK->destroy_kokkos(atomKK->k_rmass,atom->rmass); + atom->rmass = nullptr; + } + } + + atomKK->update_property_atom(); } /* ---------------------------------------------------------------------- @@ -44,17 +83,17 @@ void FixPropertyAtomKokkos::grow_arrays(int nmax) { for (int nv = 0; nv < nvalue; nv++) { if (styles[nv] == MOLECULE) { - memory->grow(atom->molecule,nmax,"atom:molecule"); - size_t nbytes = (nmax-nmax_old) * sizeof(tagint); - memset(&atom->molecule[nmax_old],0,nbytes); + atomKK->sync(Device,MOLECULE_MASK); + memoryKK->grow_kokkos(atomKK->k_molecule,atom->molecule,nmax,"atom:molecule"); + atomKK->modified(Device,MOLECULE_MASK); } else if (styles[nv] == CHARGE) { - memory->grow(atom->q,nmax,"atom:q"); - size_t nbytes = (nmax-nmax_old) * sizeof(double); - memset(&atom->q[nmax_old],0,nbytes); + atomKK->sync(Device,Q_MASK); + memoryKK->grow_kokkos(atomKK->k_q,atom->q,nmax,"atom:q"); + atomKK->modified(Device,Q_MASK); } else if (styles[nv] == RMASS) { - memory->grow(atom->rmass,nmax,"atom:rmass"); - size_t nbytes = (nmax-nmax_old) * sizeof(double); - memset(&atom->rmass[nmax_old],0,nbytes); + atomKK->sync(Device,RMASS_MASK); + memoryKK->grow_kokkos(atomKK->k_rmass,atom->rmass,nmax,"atom:rmass"); + atomKK->modified(Device,RMASS_MASK); } else if (styles[nv] == TEMPERATURE) { memory->grow(atom->temperature, nmax, "atom:temperature"); size_t nbytes = (nmax - nmax_old) * sizeof(double); @@ -69,7 +108,7 @@ void FixPropertyAtomKokkos::grow_arrays(int nmax) memset(&atom->ivector[index[nv]][nmax_old],0,nbytes); } else if (styles[nv] == DVEC) { atomKK->sync(Device,DVECTOR_MASK); - memoryKK->grow_kokkos(atomKK->k_dvector,atomKK->dvector,atomKK->k_dvector.extent(0),nmax, + memoryKK->grow_kokkos(atomKK->k_dvector,atom->dvector,atomKK->k_dvector.extent(0),nmax, "atom:dvector"); atomKK->modified(Device,DVECTOR_MASK); } else if (styles[nv] == IARRAY) { @@ -84,3 +123,62 @@ void FixPropertyAtomKokkos::grow_arrays(int nmax) } nmax_old = nmax; } + +/* ---------------------------------------------------------------------- */ + +void FixPropertyAtomKokkos::sync(ExecutionSpace space, unsigned int mask) +{ + if (space == Device) { + if (molecule_flag && (mask & MOLECULE_MASK)) atomKK->k_molecule.sync(); + if (q_flag && (mask & Q_MASK)) atomKK->k_q.sync(); + if (rmass_flag && (mask & RMASS_MASK)) {atomKK->k_rmass.sync();} + if (dvector_flag && (mask & DVECTOR_MASK)) atomKK->k_dvector.sync(); + } else { + if (molecule_flag && (mask & MOLECULE_MASK)) atomKK->k_molecule.sync(); + if (q_flag && (mask & Q_MASK)) atomKK->k_q.sync(); + if (rmass_flag && (mask & RMASS_MASK)) atomKK->k_rmass.sync(); + if (dvector_flag && (mask & DVECTOR_MASK)) atomKK->k_dvector.sync(); + } +} + +/* ---------------------------------------------------------------------- */ + +void FixPropertyAtomKokkos::sync_overlapping_device(ExecutionSpace space, unsigned int mask) +{ + if (space == Device) { + if ((mask & MOLECULE_MASK) && atomKK->k_molecule.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_molecule,space); + if ((mask & Q_MASK) && atomKK->k_q.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_q,space); + if ((mask & RMASS_MASK) && atomKK->k_rmass.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_rmass,space); + if ((mask & DVECTOR_MASK) && atomKK->k_dvector.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_dvector,space); + } else { + if ((mask & MOLECULE_MASK) && atomKK->k_molecule.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_molecule,space); + if ((mask & Q_MASK) && atomKK->k_q.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_q,space); + if ((mask & RMASS_MASK) && atomKK->k_rmass.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_rmass,space); + if ((mask & DVECTOR_MASK) && atomKK->k_dvector.need_sync()) + atomKK->avecKK->perform_async_copy(atomKK->k_dvector,space); + } +} + +/* ---------------------------------------------------------------------- */ + +void FixPropertyAtomKokkos::modified(ExecutionSpace space, unsigned int mask) +{ + if (space == Device) { + if (molecule_flag && (mask & MOLECULE_MASK)) atomKK->k_molecule.modify(); + if (q_flag && (mask & Q_MASK)) atomKK->k_q.modify(); + if (rmass_flag && (mask & RMASS_MASK)) atomKK->k_rmass.modify(); + if (dvector_flag && (mask & DVECTOR_MASK)) atomKK->k_dvector.modify(); + } else { + if (molecule_flag && (mask & MOLECULE_MASK)) atomKK->k_molecule.modify(); + if (q_flag && (mask & Q_MASK)) atomKK->k_q.modify(); + if (rmass_flag && (mask & RMASS_MASK)) atomKK->k_rmass.modify(); + if (dvector_flag && (mask & DVECTOR_MASK)) atomKK->k_dvector.modify(); + } +} diff --git a/src/KOKKOS/fix_property_atom_kokkos.h b/src/KOKKOS/fix_property_atom_kokkos.h index 90eddc98e0..adbe6ab20b 100644 --- a/src/KOKKOS/fix_property_atom_kokkos.h +++ b/src/KOKKOS/fix_property_atom_kokkos.h @@ -22,14 +22,23 @@ FixStyle(property/atom/kk,FixPropertyAtomKokkos); #define LMP_FIX_PROPERTY_ATOM_KOKKOS_H #include "fix_property_atom.h" +#include "atom_vec_kokkos.h" namespace LAMMPS_NS { class FixPropertyAtomKokkos : public FixPropertyAtom { public: FixPropertyAtomKokkos(class LAMMPS *, int, char **); - + void post_constructor() override; + ~FixPropertyAtomKokkos() override; void grow_arrays(int) override; + + void sync(ExecutionSpace space, unsigned int mask); + void modified(ExecutionSpace space, unsigned int mask); + void sync_overlapping_device(ExecutionSpace space, unsigned int mask); + + private: + int dvector_flag; }; } diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 91ea6d37ac..e3fefd7cad 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -104,7 +104,9 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int me = 0; MPI_Comm_rank(world,&me); - if (me == 0) error->message(FLERR,"KOKKOS mode is enabled"); + if (me == 0) + error->message(FLERR,"KOKKOS mode with Kokkos version {}.{}.{} is enabled", + KOKKOS_VERSION / 10000, (KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100); // process any command-line args that invoke Kokkos settings @@ -143,6 +145,14 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (device >= skip_gpu) device++; set_flag = 1; } + if ((str = getenv("FLUX_TASK_LOCAL_ID"))) { + if (ngpus > 0) { + int local_rank = atoi(str); + device = local_rank % ngpus; + if (device >= skip_gpu) device++; + set_flag = 1; + } + } if ((str = getenv("MPT_LRANK"))) { if (ngpus > 0) { int local_rank = atoi(str); diff --git a/src/KOKKOS/kokkos_base.h b/src/KOKKOS/kokkos_base.h index 7d9ecb5d80..1e22a38657 100644 --- a/src/KOKKOS/kokkos_base.h +++ b/src/KOKKOS/kokkos_base.h @@ -41,11 +41,6 @@ class KokkosBase { int, int *) {return 0;}; virtual void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d &) {} - - // Region - virtual void match_all_kokkos(int, DAT::tdual_int_1d) {} - - // Fix virtual int pack_exchange_kokkos(const int & /*nsend*/, DAT::tdual_xfloat_2d & /*k_buf*/, DAT::tdual_int_1d /*k_sendlist*/, DAT::tdual_int_1d /*k_copylist*/, @@ -54,6 +49,9 @@ class KokkosBase { DAT::tdual_int_1d & /*indices*/, int /*nrecv*/, ExecutionSpace /*space*/) {} + // Region + virtual void match_all_kokkos(int, DAT::tdual_int_1d) {} + using KeyViewType = DAT::t_x_array; using BinOp = BinOp3DLAMMPS; virtual void diff --git a/src/KOKKOS/min_kokkos.cpp b/src/KOKKOS/min_kokkos.cpp index 4e1c3967ff..c01a53c7b3 100644 --- a/src/KOKKOS/min_kokkos.cpp +++ b/src/KOKKOS/min_kokkos.cpp @@ -59,6 +59,9 @@ void MinKokkos::init() { Min::init(); + if (!fix_minimize->kokkosable) + error->all(FLERR,"KOKKOS package requires fix minimize/kk"); + fix_minimize_kk = (FixMinimizeKokkos*) fix_minimize; } @@ -69,8 +72,7 @@ void MinKokkos::init() void MinKokkos::setup(int flag) { if (comm->me == 0 && screen) { - fmt::print(screen,"Setting up {} style minimization ...\n", - update->minimize_style); + fmt::print(screen,"Setting up {} style minimization ...\n", update->minimize_style); if (flag) { fmt::print(screen," Unit style : {}\n", update->unit_style); fmt::print(screen," Current step : {}\n", update->ntimestep); @@ -89,14 +91,13 @@ void MinKokkos::setup(int flag) fextra = new double[nextra_global]; if (comm->me == 0) error->warning(FLERR, "Energy due to {} extra global DOFs will" - " be included in minimizer energies\n", nextra_global); + " be included in minimizer energies\n",nextra_global); } // 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 @@ -534,6 +535,7 @@ double MinKokkos::energy_force(int resetflag) if (resetflag) fix_minimize_kk->reset_coords(); reset_vectors(); } + return energy; } @@ -572,7 +574,14 @@ void MinKokkos::force_clear() l_torque(i,2) = 0.0; } }); + + if (extraflag) { + size_t nbytes = sizeof(double) * atom->nlocal; + if (force->newton) nbytes += sizeof(double) * atom->nghost; + atom->avec->force_clear(0,nbytes); + } } + atomKK->modified(Device,F_MASK|TORQUE_MASK); } diff --git a/src/KOKKOS/mliap_data_kokkos.cpp b/src/KOKKOS/mliap_data_kokkos.cpp index a2a8743c66..18637543f8 100644 --- a/src/KOKKOS/mliap_data_kokkos.cpp +++ b/src/KOKKOS/mliap_data_kokkos.cpp @@ -85,6 +85,7 @@ void MLIAPDataKokkos::generate_neighdata(class NeighList *list_in, i // clear gradforce and elems arrays int nall = atom->nlocal + atom->nghost; + nlocal = atom->nlocal; ntotal = nall; if (gradgradflag > -1){ auto d_gradforce = k_gradforce.template view(); diff --git a/src/KOKKOS/mliap_data_kokkos.h b/src/KOKKOS/mliap_data_kokkos.h index f641085c6a..7d95793aa2 100644 --- a/src/KOKKOS/mliap_data_kokkos.h +++ b/src/KOKKOS/mliap_data_kokkos.h @@ -118,6 +118,7 @@ public: egradient(nullptr), ntotal(base.ntotal), nlistatoms(base.nlistatoms), + nlocal(base.nlocal), natomneigh(base.natomneigh), numneighs(base.numneighs), iatoms(base.k_iatoms.d_view.data()), @@ -171,6 +172,7 @@ public: // Neighborlist stuff const int ntotal; const int nlistatoms; + const int nlocal; const int natomneigh; int *numneighs; int *iatoms; @@ -191,7 +193,7 @@ public: int dev; #ifdef LMP_KOKKOS_GPU - MLIAPDataKokkosDevice(MLIAPDataKokkos &base) : ndescriptors(-1),nparams(-1),nelements(-1),ntotal(-1),nlistatoms(-1),natomneigh(-1), + MLIAPDataKokkosDevice(MLIAPDataKokkos &base) : ndescriptors(-1),nparams(-1),nelements(-1),ntotal(-1),nlistatoms(-1),nlocal(-1),natomneigh(-1), nneigh_max(-1),npairs(-1) { // It cannot get here, but needed for compilation diff --git a/src/KOKKOS/mliap_model_python_couple_kokkos.pyx b/src/KOKKOS/mliap_model_python_couple_kokkos.pyx index 6dec8cdbfe..24a0e0897f 100644 --- a/src/KOKKOS/mliap_model_python_couple_kokkos.pyx +++ b/src/KOKKOS/mliap_model_python_couple_kokkos.pyx @@ -25,6 +25,7 @@ cdef extern from "mliap_data_kokkos.h" namespace "LAMMPS_NS": cdef cppclass MLIAPDataKokkosDevice: # Array shapes int nlistatoms + int nlocal int ndescriptors # Input data @@ -130,14 +131,14 @@ cdef create_array(device, void *pointer, shape,is_int): return numpy.asarray(pointer) else: return numpy.asarray(pointer) - + cdef public void MLIAPPYKokkos_compute_gradients(MLIAPModelPythonKokkosDevice * c_model, MLIAPDataKokkosDevice * data) with gil: dev=data.dev torch.cuda.nvtx.range_push("set data fields") - model = retrieve(c_model) + model = retrieve(c_model) n_d = data.ndescriptors n_a = data.nlistatoms @@ -148,7 +149,7 @@ cdef public void MLIAPPYKokkos_compute_gradients(MLIAPModelPythonKokkosDevice * beta_cp = create_array(dev, data.betas, (n_a, n_d), False) desc_cp = create_array(dev, data.descriptors, (n_a, n_d), False) torch.cuda.nvtx.range_pop() - + # Invoke python model on numpy arrays. torch.cuda.nvtx.range_push("call model") model(elem_cp,desc_cp,beta_cp,en_cp,dev==1) diff --git a/src/KOKKOS/mliap_unified_couple_kokkos.pyx b/src/KOKKOS/mliap_unified_couple_kokkos.pyx index bd94b79eb4..97d807ac33 100644 --- a/src/KOKKOS/mliap_unified_couple_kokkos.pyx +++ b/src/KOKKOS/mliap_unified_couple_kokkos.pyx @@ -59,6 +59,7 @@ cdef extern from "mliap_data_kokkos.h" namespace "LAMMPS_NS": int ntotal # total number of owned and ghost atoms on this proc int nlistatoms # current number of atoms in local atom lists + int nlocal int natomneigh # current number of atoms and ghosts in atom neighbor arrays int * numneighs # neighbors count for each atom int * iatoms # index of each atom @@ -133,14 +134,14 @@ cdef create_array(device, void *pointer, shape,is_int): return np.asarray(pointer) else: return np.asarray(pointer) - + # Cython implementation of MLIAPData # Automatically converts between C arrays and numpy when needed cdef class MLIAPDataPy: cdef MLIAPDataKokkosDevice * data - + def __cinit__(self): self.data = NULL @@ -157,7 +158,7 @@ cdef class MLIAPDataPy: ptr = eij.data.ptr except: ptr = eij.data_ptr() - update_pair_energy(self.data, ptr) + update_pair_energy(self.data, ptr) def update_pair_energy(self, eij): if self.data.dev==0: self.update_pair_energy_cpu(eij) @@ -177,7 +178,7 @@ cdef class MLIAPDataPy: ptr = fij.data.ptr except: ptr = fij.data_ptr() - update_pair_forces(self.data, ptr) + update_pair_forces(self.data, ptr) def update_pair_forces(self, fij): if self.data.dev==0: self.update_pair_forces_cpu(fij) @@ -189,11 +190,11 @@ cdef class MLIAPDataPy: return None return create_array(self.data.dev, self.data.f, [self.ntotal, 3],False) - + @property def size_gradforce(self): return self.data.size_gradforce - + @write_only_property def gradforce(self, value): if self.data.gradforce is NULL: @@ -202,7 +203,7 @@ cdef class MLIAPDataPy: cdef double[:, :] value_view = value gradforce_view[:] = value_view print("This code has not been tested or optimized for the GPU, if you are getting this warning optimize gradforce") - + @write_only_property def betas(self, value): if self.data.betas is NULL: @@ -280,7 +281,7 @@ cdef class MLIAPDataPy: @property def ntotal(self): return self.data.ntotal - + @property def elems(self): if self.data.elems is NULL: @@ -290,7 +291,11 @@ cdef class MLIAPDataPy: @property def nlistatoms(self): return self.data.nlistatoms - + + @property + def nlocal(self): + return self.data.nlocal + @property def natomneigh(self): return self.data.natomneigh @@ -306,7 +311,7 @@ cdef class MLIAPDataPy: if self.data.iatoms is NULL: return None return create_array(self.data.dev, self.data.iatoms, [self.natomneigh],True) - + @property def ielems(self): if self.data.ielems is NULL: @@ -322,7 +327,7 @@ cdef class MLIAPDataPy: if self.data.pair_i is NULL: return None return create_array(self.data.dev, self.data.pair_i, [self.npairs],True) - + @property def pair_j(self): return self.jatoms @@ -332,7 +337,7 @@ cdef class MLIAPDataPy: if self.data.jatoms is NULL: return None return create_array(self.data.dev, self.data.jatoms, [self.npairs],True) - + @property def jelems(self): if self.data.jelems is NULL: @@ -383,13 +388,13 @@ cdef class MLIAPUnifiedInterfaceKokkos: self.model = NULL self.descriptor = NULL self.unified_impl = unified_impl - + def compute_gradients(self, data): self.unified_impl.compute_gradients(data) - + def compute_descriptors(self, data): self.unified_impl.compute_descriptors(data) - + def compute_forces(self, data): self.unified_impl.compute_forces(data) @@ -443,7 +448,7 @@ cdef public object mliap_unified_connect_kokkos(char *fname, MLIAPDummyModel * m if unified.element_types is None: raise ValueError("no element type set") - + cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) diff --git a/src/KOKKOS/mliap_unified_kokkos.cpp b/src/KOKKOS/mliap_unified_kokkos.cpp index deb9cbc346..4c38e4f1d6 100644 --- a/src/KOKKOS/mliap_unified_kokkos.cpp +++ b/src/KOKKOS/mliap_unified_kokkos.cpp @@ -271,8 +271,8 @@ void LAMMPS_NS::update_pair_energy(MLIAPDataKokkosDevice *data, double *eij) { auto d_eatoms = data->eatoms; auto d_pair_i= data->pair_i; - const auto nlistatoms = data->nlistatoms; - Kokkos::parallel_for(nlistatoms, KOKKOS_LAMBDA(int ii){ + const auto nlocal = data->nlocal; + Kokkos::parallel_for(nlocal, KOKKOS_LAMBDA(int ii){ d_eatoms[ii] = 0; }); @@ -281,7 +281,7 @@ void LAMMPS_NS::update_pair_energy(MLIAPDataKokkosDevice *data, double *eij) double e = 0.5 * eij[ii]; // must not count any contribution where i is not a local atom - if (i < nlistatoms) { + if (i < nlocal) { Kokkos::atomic_add(&d_eatoms[i], e); local_sum += e; } @@ -294,7 +294,7 @@ void LAMMPS_NS::update_pair_energy(MLIAPDataKokkosDevice *data, double *eij) void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) { - const auto nlistatoms = data->nlistatoms; + const auto nlocal = data->nlocal; auto *f = data->f; auto pair_i = data->pair_i; auto j_atoms = data->jatoms; @@ -315,7 +315,7 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) int i = pair_i[ii]; int j = j_atoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlistatoms) { + if (i < nlocal) { Kokkos::atomic_add(&f[i*3+0], fij[ii3+0]); Kokkos::atomic_add(&f[i*3+1], fij[ii3+1]); Kokkos::atomic_add(&f[i*3+2], fij[ii3+2]); @@ -378,12 +378,12 @@ void LAMMPS_NS::update_pair_forces(MLIAPDataKokkosDevice *data, double *fij) void LAMMPS_NS::update_atom_energy(MLIAPDataKokkosDevice *data, double *ei) { auto d_eatoms = data->eatoms; - const auto nlistatoms = data->nlistatoms; + const auto nlocal = data->nlocal; - Kokkos::parallel_reduce(nlistatoms, KOKKOS_LAMBDA(int i, double &local_sum){ + Kokkos::parallel_reduce(nlocal, KOKKOS_LAMBDA(int i, double &local_sum){ double e = ei[i]; // must not count any contribution where i is not a local atom - if (i < nlistatoms) { + if (i < nlocal) { d_eatoms[i] = e; local_sum += e; } diff --git a/src/KOKKOS/modify_kokkos.cpp b/src/KOKKOS/modify_kokkos.cpp index 0b81a1cabb..8d8ffca671 100644 --- a/src/KOKKOS/modify_kokkos.cpp +++ b/src/KOKKOS/modify_kokkos.cpp @@ -362,6 +362,17 @@ void ModifyKokkos::pre_reverse(int eflag, int vflag) void ModifyKokkos::post_force(int vflag) { + for (int i = 0; i < n_post_force_group; i++) { + atomKK->sync(fix[list_post_force_group[i]]->execution_space, + fix[list_post_force_group[i]]->datamask_read); + int prev_auto_sync = lmp->kokkos->auto_sync; + if (!fix[list_post_force_group[i]]->kokkosable) lmp->kokkos->auto_sync = 1; + fix[list_post_force_group[i]]->post_force(vflag); + lmp->kokkos->auto_sync = prev_auto_sync; + atomKK->modified(fix[list_post_force_group[i]]->execution_space, + fix[list_post_force_group[i]]->datamask_modify); + } + for (int i = 0; i < n_post_force; i++) { atomKK->sync(fix[list_post_force[i]]->execution_space, fix[list_post_force[i]]->datamask_read); diff --git a/src/KOKKOS/neigh_bond_kokkos.cpp b/src/KOKKOS/neigh_bond_kokkos.cpp index 4cfe440b1f..b749590779 100644 --- a/src/KOKKOS/neigh_bond_kokkos.cpp +++ b/src/KOKKOS/neigh_bond_kokkos.cpp @@ -112,9 +112,8 @@ void NeighBondKokkos::init_topology_kk() { int i,m; int bond_off = 0; int angle_off = 0; - for (i = 0; i < modify->nfix; i++) - if ((strcmp(modify->fix[i]->style,"shake") == 0) - || (strcmp(modify->fix[i]->style,"rattle") == 0)) + for (const auto &ifix : modify->get_fix_list()) + if (utils::strmatch(ifix->style,"^shake") || utils::strmatch(ifix->style,"^rattle")) bond_off = angle_off = 1; if (force->bond && force->bond_match("quartic")) bond_off = 1; diff --git a/src/KOKKOS/neighbor_kokkos.cpp b/src/KOKKOS/neighbor_kokkos.cpp index 0b40bce841..efb1247560 100644 --- a/src/KOKKOS/neighbor_kokkos.cpp +++ b/src/KOKKOS/neighbor_kokkos.cpp @@ -308,7 +308,8 @@ void NeighborKokkos::build_kokkos(int topoflag) for (i = 0; i < npair_perpetual; i++) { m = plist[i]; if (!lists[m]->kokkos) atomKK->sync(Host,ALL_MASK); - if (!lists[m]->copy) lists[m]->grow(nlocal,nall); + if (!lists[m]->copy || lists[m]->trim || lists[m]->kk2cpu) + lists[m]->grow(nlocal,nall); neigh_pair[m]->build_setup(); neigh_pair[m]->build(lists[m]); } diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 06567cbeb6..2a16ca95b4 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -113,7 +113,7 @@ void NPairKokkos::copy_stencil_info() NPair::copy_stencil_info(); nstencil = ns->nstencil; - if (ns->last_stencil != last_stencil_old) { + if (ns->last_stencil != last_stencil_old || ns->last_stencil == update->ntimestep) { // copy stencil to device as it may have changed last_stencil_old = ns->last_stencil; diff --git a/src/KOKKOS/npair_trim_kokkos.cpp b/src/KOKKOS/npair_trim_kokkos.cpp index 97931bf250..d04d8676d7 100644 --- a/src/KOKKOS/npair_trim_kokkos.cpp +++ b/src/KOKKOS/npair_trim_kokkos.cpp @@ -62,8 +62,8 @@ void NPairTrimKokkos::trim_to_kokkos(NeighList *list) d_ilist_copy = k_list_copy->d_ilist; d_numneigh_copy = k_list_copy->d_numneigh; d_neighbors_copy = k_list_copy->d_neighbors; - int inum_copy = list->listcopy->inum; - if (list->ghost) inum_copy += list->listcopy->gnum; + int inum_trim = list->listcopy->inum; + if (list->ghost) inum_trim += list->listcopy->gnum; NeighListKokkos* k_list = static_cast*>(list); k_list->maxneighs = k_list_copy->maxneighs; // simple, but could be made more memory efficient @@ -75,7 +75,7 @@ void NPairTrimKokkos::trim_to_kokkos(NeighList *list) // loop over parent list and trim copymode = 1; - Kokkos::parallel_for(Kokkos::RangePolicy(0,inum_copy),*this); + Kokkos::parallel_for(Kokkos::RangePolicy(0,inum_trim),*this); copymode = 0; list->inum = k_list_copy->inum; @@ -132,8 +132,8 @@ void NPairTrimKokkos::trim_to_cpu(NeighList *list) int inum = listcopy->inum; int gnum = listcopy->gnum; - int inum_all = inum; - if (list->ghost) inum_all += gnum; + int inum_trim = inum; + if (list->ghost) inum_trim += gnum; auto h_ilist = listcopy_kk->k_ilist.h_view; auto h_numneigh = Kokkos::create_mirror_view_and_copy(LMPHostType(),listcopy_kk->d_numneigh); auto h_neighbors = Kokkos::create_mirror_view_and_copy(LMPHostType(),listcopy_kk->d_neighbors); @@ -151,7 +151,7 @@ void NPairTrimKokkos::trim_to_cpu(NeighList *list) MyPage *ipage = list->ipage; ipage->reset(); - for (int ii = 0; ii < inum_all; ii++) { + for (int ii = 0; ii < inum_trim; ii++) { int n = 0; neighptr = ipage->vget(); diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.h b/src/KOKKOS/pair_buck_coul_cut_kokkos.h index b91348d557..9b6cc31898 100644 --- a/src/KOKKOS/pair_buck_coul_cut_kokkos.h +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.h @@ -112,15 +112,18 @@ class PairBuckCoulCutKokkos : public PairBuckCoulCut { void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckCoulCutKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairBuckCoulCutKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairBuckCoulCutKokkos*); diff --git a/src/KOKKOS/pair_buck_coul_long_kokkos.h b/src/KOKKOS/pair_buck_coul_long_kokkos.h index b776a84e3c..bed9b0d0f8 100644 --- a/src/KOKKOS/pair_buck_coul_long_kokkos.h +++ b/src/KOKKOS/pair_buck_coul_long_kokkos.h @@ -115,27 +115,33 @@ class PairBuckCoulLongKokkos : public PairBuckCoulLong { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairBuckCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairBuckCoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairBuckCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairBuckCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairBuckCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairBuckCoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairBuckCoulLongKokkos*); diff --git a/src/KOKKOS/pair_buck_kokkos.h b/src/KOKKOS/pair_buck_kokkos.h index 364716453b..15325cd56a 100644 --- a/src/KOKKOS/pair_buck_kokkos.h +++ b/src/KOKKOS/pair_buck_kokkos.h @@ -91,16 +91,19 @@ class PairBuckKokkos : public PairBuck { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairBuckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairBuckKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairBuckKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairBuckKokkos*); }; diff --git a/src/KOKKOS/pair_coul_cut_kokkos.h b/src/KOKKOS/pair_coul_cut_kokkos.h index 6626889660..3e0501edd9 100644 --- a/src/KOKKOS/pair_coul_cut_kokkos.h +++ b/src/KOKKOS/pair_coul_cut_kokkos.h @@ -112,15 +112,18 @@ class PairCoulCutKokkos : public PairCoulCut { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulCutKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairCoulCutKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairCoulCutKokkos*); diff --git a/src/KOKKOS/pair_coul_debye_kokkos.h b/src/KOKKOS/pair_coul_debye_kokkos.h index b6bed9d557..d239291a25 100644 --- a/src/KOKKOS/pair_coul_debye_kokkos.h +++ b/src/KOKKOS/pair_coul_debye_kokkos.h @@ -112,15 +112,18 @@ class PairCoulDebyeKokkos : public PairCoulDebye { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairCoulDebyeKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairCoulDebyeKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairCoulDebyeKokkos*); diff --git a/src/KOKKOS/pair_coul_long_kokkos.h b/src/KOKKOS/pair_coul_long_kokkos.h index fcb1402028..232cdbb6df 100644 --- a/src/KOKKOS/pair_coul_long_kokkos.h +++ b/src/KOKKOS/pair_coul_long_kokkos.h @@ -114,27 +114,33 @@ class PairCoulLongKokkos : public PairCoulLong { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairCoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairCoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairCoulLongKokkos*); diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.cpp b/src/KOKKOS/pair_eam_alloy_kokkos.cpp index 2b81e21e2b..1e5279cb6f 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.cpp +++ b/src/KOKKOS/pair_eam_alloy_kokkos.cpp @@ -1477,7 +1477,7 @@ void PairEAMAlloyKokkos::file2array_alloy() template template struct PairEAMAlloyKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { auto policy = Kokkos::RangePolicy(0,inum); return policy; @@ -1488,7 +1488,7 @@ struct PairEAMAlloyKokkos::policyInstance { template<> template struct PairEAMAlloyKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { static_assert(t_ffloat_2d_n7::static_extent(2) == 7, "Breaking assumption of spline dim for KernelAB and KernelC scratch caching"); diff --git a/src/KOKKOS/pair_eam_fs_kokkos.cpp b/src/KOKKOS/pair_eam_fs_kokkos.cpp index 4572d14e48..6753f43f6d 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.cpp +++ b/src/KOKKOS/pair_eam_fs_kokkos.cpp @@ -1487,7 +1487,7 @@ void PairEAMFSKokkos::file2array_fs() template template struct PairEAMFSKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { auto policy = Kokkos::RangePolicy(0,inum); return policy; @@ -1498,7 +1498,7 @@ struct PairEAMFSKokkos::policyInstance { template<> template struct PairEAMFSKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { static_assert(t_ffloat_2d_n7::static_extent(2) == 7, "Breaking assumption of spline dim for KernelAB and KernelC scratch caching"); diff --git a/src/KOKKOS/pair_eam_kokkos.cpp b/src/KOKKOS/pair_eam_kokkos.cpp index de6d3646bf..ec84ccb0c1 100644 --- a/src/KOKKOS/pair_eam_kokkos.cpp +++ b/src/KOKKOS/pair_eam_kokkos.cpp @@ -1162,7 +1162,7 @@ void PairEAMKokkos::ev_tally(EV_FLOAT &ev, const int &i, const int & template template struct PairEAMKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { auto policy = Kokkos::RangePolicy(0,inum); return policy; @@ -1173,7 +1173,7 @@ struct PairEAMKokkos::policyInstance { template<> template struct PairEAMKokkos::policyInstance { - KOKKOS_INLINE_FUNCTION + static auto get(int inum) { static_assert(t_ffloat_2d_n7::static_extent(2) == 7, "Breaking assumption of spline dim for KernelAB and KernelC scratch caching"); diff --git a/src/KOKKOS/pair_kokkos.h b/src/KOKKOS/pair_kokkos.h index f6925a376d..2b8c7ec1c9 100644 --- a/src/KOKKOS/pair_kokkos.h +++ b/src/KOKKOS/pair_kokkos.h @@ -50,7 +50,7 @@ struct DoCoul<1> { //Specialisation for Neighborlist types Half, HalfThread, Full -template +template struct PairComputeFunctor { typedef typename PairStyle::device_type device_type ; typedef ArrayTypes AT; @@ -137,7 +137,7 @@ struct PairComputeFunctor { F_FLOAT fytmp = 0.0; F_FLOAT fztmp = 0.0; - if (NEIGHFLAG == FULL) { + if (NEIGHFLAG == FULL && ZEROFLAG) { f(i,0) = 0.0; f(i,1) = 0.0; f(i,2) = 0.0; @@ -211,7 +211,7 @@ struct PairComputeFunctor { F_FLOAT fytmp = 0.0; F_FLOAT fztmp = 0.0; - if (NEIGHFLAG == FULL) { + if (NEIGHFLAG == FULL && ZEROFLAG) { f(i,0) = 0.0; f(i,1) = 0.0; f(i,2) = 0.0; @@ -292,11 +292,13 @@ struct PairComputeFunctor { const X_FLOAT ztmp = c.x(i,2); const int itype = c.type(i); - Kokkos::single(Kokkos::PerThread(team), [&] (){ - f(i,0) = 0.0; - f(i,1) = 0.0; - f(i,2) = 0.0; - }); + if (ZEROFLAG) { + Kokkos::single(Kokkos::PerThread(team), [&] (){ + f(i,0) = 0.0; + f(i,1) = 0.0; + f(i,2) = 0.0; + }); + } const AtomNeighborsConst neighbors_i = list.get_neighbors_const(i); const int jnum = list.d_numneigh[i]; @@ -355,11 +357,13 @@ struct PairComputeFunctor { const int itype = c.type(i); const F_FLOAT qtmp = c.q(i); - Kokkos::single(Kokkos::PerThread(team), [&] (){ - f(i,0) = 0.0; - f(i,1) = 0.0; - f(i,2) = 0.0; - }); + if (ZEROFLAG) { + Kokkos::single(Kokkos::PerThread(team), [&] (){ + f(i,0) = 0.0; + f(i,1) = 0.0; + f(i,2) = 0.0; + }); + } const AtomNeighborsConst neighbors_i = list.get_neighbors_const(i); const int jnum = list.d_numneigh[i]; @@ -423,11 +427,13 @@ struct PairComputeFunctor { const X_FLOAT ztmp = c.x(i,2); const int itype = c.type(i); - Kokkos::single(Kokkos::PerThread(team), [&] (){ - f(i,0) = 0.0; - f(i,1) = 0.0; - f(i,2) = 0.0; - }); + if (ZEROFLAG) { + Kokkos::single(Kokkos::PerThread(team), [&] (){ + f(i,0) = 0.0; + f(i,1) = 0.0; + f(i,2) = 0.0; + }); + } const AtomNeighborsConst neighbors_i = list.get_neighbors_const(i); const int jnum = list.d_numneigh[i]; @@ -525,11 +531,13 @@ struct PairComputeFunctor { const int itype = c.type(i); const F_FLOAT qtmp = c.q(i); - Kokkos::single(Kokkos::PerThread(team), [&] (){ - f(i,0) = 0.0; - f(i,1) = 0.0; - f(i,2) = 0.0; - }); + if (ZEROFLAG) { + Kokkos::single(Kokkos::PerThread(team), [&] (){ + f(i,0) = 0.0; + f(i,1) = 0.0; + f(i,2) = 0.0; + }); + } const AtomNeighborsConst neighbors_i = list.get_neighbors_const(i); const int jnum = list.d_numneigh[i]; @@ -740,7 +748,7 @@ struct PairComputeFunctor { // By having the enable_if with a ! and without it, exactly one of the functions // pair_compute_neighlist will match - either the dummy version // or the real one further below. -template +template EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if*>::type list) { EV_FLOAT ev; (void) fpair; @@ -770,7 +778,7 @@ int GetTeamSize(FunctorStyle& KOKKOS_GPU_ARG(functor), int KOKKOS_GPU_ARG(inum), } // Submit ParallelFor for NEIGHFLAG=HALF,HALFTHREAD,FULL -template +template EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if<(NEIGHFLAG&PairStyle::EnabledNeighFlags) != 0, NeighListKokkos*>::type list) { EV_FLOAT ev; @@ -784,13 +792,13 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if<(NEIG int atoms_per_team = 32; if (fpair->atom->ntypes > MAX_TYPES_STACKPARAMS) { - PairComputeFunctor ff(fpair,list); + PairComputeFunctor ff(fpair,list); atoms_per_team = GetTeamSize(ff, list->inum, (fpair->eflag || fpair->vflag), atoms_per_team, vector_length); Kokkos::TeamPolicy > policy(list->inum,atoms_per_team,vector_length); if (fpair->eflag || fpair->vflag) Kokkos::parallel_reduce(policy,ff,ev); else Kokkos::parallel_for(policy,ff); } else { - PairComputeFunctor ff(fpair,list); + PairComputeFunctor ff(fpair,list); atoms_per_team = GetTeamSize(ff, list->inum, (fpair->eflag || fpair->vflag), atoms_per_team, vector_length); Kokkos::TeamPolicy > policy(list->inum,atoms_per_team,vector_length); if (fpair->eflag || fpair->vflag) Kokkos::parallel_reduce(policy,ff,ev); @@ -798,12 +806,12 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if<(NEIG } } else { if (fpair->atom->ntypes > MAX_TYPES_STACKPARAMS) { - PairComputeFunctor ff(fpair,list); + PairComputeFunctor ff(fpair,list); if (fpair->eflag || fpair->vflag) Kokkos::parallel_reduce(list->inum,ff,ev); else Kokkos::parallel_for(list->inum,ff); ff.contribute(); } else { - PairComputeFunctor ff(fpair,list); + PairComputeFunctor ff(fpair,list); if (fpair->eflag || fpair->vflag) Kokkos::parallel_reduce(list->inum,ff,ev); else Kokkos::parallel_for(list->inum,ff); ff.contribute(); @@ -812,16 +820,21 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if<(NEIG return ev; } -template +template EV_FLOAT pair_compute (PairStyle* fpair, NeighListKokkos* list) { EV_FLOAT ev; if (fpair->neighflag == FULL) { - fpair->fuse_force_clear_flag = 1; - ev = pair_compute_neighlist (fpair,list); + if (utils::strmatch(fpair->lmp->force->pair_style,"^hybrid/overlay")) { + fpair->fuse_force_clear_flag = 0; + ev = pair_compute_neighlist (fpair,list); + } else { + fpair->fuse_force_clear_flag = 1; + ev = pair_compute_neighlist (fpair,list); + } } else if (fpair->neighflag == HALFTHREAD) { - ev = pair_compute_neighlist (fpair,list); + ev = pair_compute_neighlist (fpair,list); } else if (fpair->neighflag == HALF) { - ev = pair_compute_neighlist (fpair,list); + ev = pair_compute_neighlist (fpair,list); } return ev; } diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h index ae27ee68ab..7e21676fd5 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.h @@ -110,27 +110,33 @@ class PairLJCharmmCoulCharmmImplicitKokkos : public PairLJCharmmCoulCharmmImplic void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmImplicitKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulCharmmImplicitKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmImplicitKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmImplicitKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulCharmmImplicitKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCharmmCoulCharmmImplicitKokkos*); diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h index 912ad573c6..1f26242ded 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.h @@ -108,27 +108,33 @@ class PairLJCharmmCoulCharmmKokkos : public PairLJCharmmCoulCharmm { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulCharmmKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulCharmmKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulCharmmKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulCharmmKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCharmmCoulCharmmKokkos*); diff --git a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h index 4ae8a12944..c6c80e76dc 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h +++ b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.h @@ -106,27 +106,33 @@ class PairLJCharmmCoulLongKokkos : public PairLJCharmmCoulLong { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCharmmCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCharmmCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCharmmCoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCharmmCoulLongKokkos*); diff --git a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h index 5ca276c28e..9399345458 100644 --- a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h +++ b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.h @@ -104,15 +104,18 @@ class PairLJClass2CoulCutKokkos : public PairLJClass2CoulCut { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2CoulCutKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairLJClass2CoulCutKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJClass2CoulCutKokkos*); diff --git a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h index 599cc2a83c..1cf6590855 100644 --- a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h +++ b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.h @@ -107,27 +107,33 @@ class PairLJClass2CoulLongKokkos : public PairLJClass2CoulLong { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJClass2CoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJClass2CoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJClass2CoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJClass2CoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJClass2CoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJClass2CoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJClass2CoulLongKokkos*); diff --git a/src/KOKKOS/pair_lj_class2_kokkos.h b/src/KOKKOS/pair_lj_class2_kokkos.h index 0936399ca8..5594680929 100644 --- a/src/KOKKOS/pair_lj_class2_kokkos.h +++ b/src/KOKKOS/pair_lj_class2_kokkos.h @@ -96,16 +96,19 @@ class PairLJClass2Kokkos : public PairLJClass2 { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJClass2Kokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJClass2Kokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJClass2Kokkos*); }; diff --git a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.h index 87464b37dc..affc67bf16 100644 --- a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.h +++ b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.h @@ -104,15 +104,18 @@ class PairLJCutCoulCutKokkos : public PairLJCutCoulCut { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulCutKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairLJCutCoulCutKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCutCoulCutKokkos*); diff --git a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h index ea0b401959..eeed483b76 100644 --- a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h +++ b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.h @@ -104,15 +104,18 @@ class PairLJCutCoulDebyeKokkos : public PairLJCutCoulDebye { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDebyeKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairLJCutCoulDebyeKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCutCoulDebyeKokkos*); diff --git a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h index e420bd22a9..d9e5fcfe49 100644 --- a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h +++ b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.h @@ -101,15 +101,18 @@ class PairLJCutCoulDSFKokkos : public PairLJCutCoulDSF { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutCoulDSFKokkos*,NeighListKokkos*); friend EV_FLOAT pair_compute(PairLJCutCoulDSFKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCutCoulDSFKokkos*); diff --git a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.h b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.h index bcb97a59cd..ec6e2db176 100644 --- a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.h +++ b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.h @@ -107,27 +107,33 @@ class PairLJCutCoulLongKokkos : public PairLJCutCoulLong { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCutCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCutCoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJCutCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJCutCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJCutCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJCutCoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCutCoulLongKokkos*); diff --git a/src/KOKKOS/pair_lj_cut_kokkos.h b/src/KOKKOS/pair_lj_cut_kokkos.h index 106f1a9048..b44c1aa6fe 100644 --- a/src/KOKKOS/pair_lj_cut_kokkos.h +++ b/src/KOKKOS/pair_lj_cut_kokkos.h @@ -92,16 +92,19 @@ class PairLJCutKokkos : public PairLJCut { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairLJCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJCutKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJCutKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJCutKokkos*); }; diff --git a/src/KOKKOS/pair_lj_expand_coul_long_kokkos.h b/src/KOKKOS/pair_lj_expand_coul_long_kokkos.h index 09a694a122..30e82b7dab 100644 --- a/src/KOKKOS/pair_lj_expand_coul_long_kokkos.h +++ b/src/KOKKOS/pair_lj_expand_coul_long_kokkos.h @@ -116,27 +116,33 @@ class PairLJExpandCoulLongKokkos : public PairLJExpandCoulLong { double qqrd2e; void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJExpandCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJExpandCoulLongKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJExpandCoulLongKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJExpandCoulLongKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJExpandCoulLongKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJExpandCoulLongKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJExpandCoulLongKokkos*); }; diff --git a/src/KOKKOS/pair_lj_expand_kokkos.h b/src/KOKKOS/pair_lj_expand_kokkos.h index 0df0a6f8f8..64fe7d8b8e 100644 --- a/src/KOKKOS/pair_lj_expand_kokkos.h +++ b/src/KOKKOS/pair_lj_expand_kokkos.h @@ -97,16 +97,19 @@ class PairLJExpandKokkos : public PairLJExpand { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJExpandKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJExpandKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJExpandKokkos*); }; diff --git a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h index 359c4a1229..020b621e33 100644 --- a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h +++ b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.h @@ -115,27 +115,33 @@ class PairLJGromacsCoulGromacsKokkos : public PairLJGromacsCoulGromacs { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJGromacsCoulGromacsKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJGromacsCoulGromacsKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJGromacsCoulGromacsKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsCoulGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJGromacsCoulGromacsKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJGromacsCoulGromacsKokkos*); diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.h b/src/KOKKOS/pair_lj_gromacs_kokkos.h index 95c600a415..ad41ca5120 100644 --- a/src/KOKKOS/pair_lj_gromacs_kokkos.h +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.h @@ -115,27 +115,33 @@ class PairLJGromacsKokkos : public PairLJGromacs { void allocate() override; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJGromacsKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJGromacsKokkos*, NeighListKokkos*); - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist >(PairLJGromacsKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute >(PairLJGromacsKokkos*, + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend struct PairComputeFunctor>; + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist>(PairLJGromacsKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute>(PairLJGromacsKokkos*, NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJGromacsKokkos*); diff --git a/src/KOKKOS/pair_lj_spica_kokkos.h b/src/KOKKOS/pair_lj_spica_kokkos.h index b330af4bfd..06c70ebd3e 100644 --- a/src/KOKKOS/pair_lj_spica_kokkos.h +++ b/src/KOKKOS/pair_lj_spica_kokkos.h @@ -97,16 +97,19 @@ class PairLJSPICAKokkos : public PairLJSPICA { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairLJSPICAKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairLJSPICAKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairLJSPICAKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairLJSPICAKokkos*); }; diff --git a/src/KOKKOS/pair_mliap_kokkos.cpp b/src/KOKKOS/pair_mliap_kokkos.cpp index d19d81e314..59f15b8c96 100644 --- a/src/KOKKOS/pair_mliap_kokkos.cpp +++ b/src/KOKKOS/pair_mliap_kokkos.cpp @@ -138,6 +138,7 @@ template void PairMLIAPKokkos::allocate() { int n = atom->ntypes; + memoryKK->destroy_kokkos(k_map, map); memoryKK->destroy_kokkos(k_cutsq, cutsq); memoryKK->destroy_kokkos(k_setflag, setflag); @@ -275,7 +276,10 @@ void PairMLIAPKokkos::coeff(int narg, char **arg) { auto h_cutsq=k_cutsq.template view(); for (int itype=1; itype <= atom->ntypes; ++itype) for (int jtype=1; jtype <= atom->ntypes; ++jtype) - h_cutsq(itype,jtype) = descriptor->cutsq[map[itype]][map[jtype]]; + // do not set cuts for NULL atoms + if (map[itype] >= 0 && map[jtype] >= 0) { + h_cutsq(itype,jtype) = descriptor->cutsq[map[itype]][map[jtype]]; + } k_cutsq.modify(); k_cutsq.sync(); constexpr int gradgradflag = -1; diff --git a/src/KOKKOS/pair_morse_kokkos.h b/src/KOKKOS/pair_morse_kokkos.h index d06cf2deb1..ccf27b018b 100644 --- a/src/KOKKOS/pair_morse_kokkos.h +++ b/src/KOKKOS/pair_morse_kokkos.h @@ -92,16 +92,19 @@ class PairMorseKokkos : public PairMorse { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairMorseKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairMorseKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairMorseKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairMorseKokkos*); }; diff --git a/src/KOKKOS/pair_pace_kokkos.cpp b/src/KOKKOS/pair_pace_kokkos.cpp index 55d0081110..58fd83317d 100644 --- a/src/KOKKOS/pair_pace_kokkos.cpp +++ b/src/KOKKOS/pair_pace_kokkos.cpp @@ -237,6 +237,9 @@ void PairPACEKokkos::copy_splines() ACERadialFunctions* radial_functions = dynamic_cast(basis_set->radial_functions); + if (radial_functions == nullptr) + error->all(FLERR,"Chosen radial basis style not supported by pair style pace/kk"); + for (int i = 0; i < nelements; i++) { for (int j = 0; j < nelements; j++) { k_splines_gk.h_view(i, j) = radial_functions->splines_gk(i, j); diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 45bacb4c97..1791e1875d 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -63,10 +63,6 @@ PairSNAPKokkos::PairSNAPKokkos(LAMMPS *lmp datamask_read = EMPTY_MASK; datamask_modify = EMPTY_MASK; - k_cutsq = tdual_fparams("PairSNAPKokkos::cutsq",atom->ntypes+1,atom->ntypes+1); - auto d_cutsq = k_cutsq.template view(); - rnd_cutsq = d_cutsq; - host_flag = (execution_space == Host); } @@ -546,6 +542,9 @@ void PairSNAPKokkos::allocate() int n = atom->ntypes; MemKK::realloc_kokkos(d_map,"PairSNAPKokkos::map",n+1); + + MemKK::realloc_kokkos(k_cutsq,"PairSNAPKokkos::cutsq",n+1,n+1); + rnd_cutsq = k_cutsq.template view(); } diff --git a/src/KOKKOS/pair_table_kokkos.cpp b/src/KOKKOS/pair_table_kokkos.cpp index b1514c8c6f..437679e412 100644 --- a/src/KOKKOS/pair_table_kokkos.cpp +++ b/src/KOKKOS/pair_table_kokkos.cpp @@ -133,19 +133,19 @@ void PairTableKokkos::compute_style(int eflag_in, int vflag_in) EV_FLOAT ev; if (atom->ntypes > MAX_TYPES_STACKPARAMS) { if (neighflag == FULL) { - PairComputeFunctor,FULL,false,S_TableCompute > + PairComputeFunctor,FULL,false,0,S_TableCompute > ff(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,ff,ev); else Kokkos::parallel_for(list->inum,ff); ff.contribute(); } else if (neighflag == HALFTHREAD) { - PairComputeFunctor,HALFTHREAD,false,S_TableCompute > + PairComputeFunctor,HALFTHREAD,false,0,S_TableCompute > ff(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,ff,ev); else Kokkos::parallel_for(list->inum,ff); ff.contribute(); } else if (neighflag == HALF) { - PairComputeFunctor,HALF,false,S_TableCompute > + PairComputeFunctor,HALF,false,0,S_TableCompute > f(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,f,ev); else Kokkos::parallel_for(list->inum,f); @@ -153,19 +153,19 @@ void PairTableKokkos::compute_style(int eflag_in, int vflag_in) } } else { if (neighflag == FULL) { - PairComputeFunctor,FULL,true,S_TableCompute > + PairComputeFunctor,FULL,true,0,S_TableCompute > f(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,f,ev); else Kokkos::parallel_for(list->inum,f); f.contribute(); } else if (neighflag == HALFTHREAD) { - PairComputeFunctor,HALFTHREAD,true,S_TableCompute > + PairComputeFunctor,HALFTHREAD,true,0,S_TableCompute > f(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,f,ev); else Kokkos::parallel_for(list->inum,f); f.contribute(); } else if (neighflag == HALF) { - PairComputeFunctor,HALF,true,S_TableCompute > + PairComputeFunctor,HALF,true,0,S_TableCompute > f(this,(NeighListKokkos*) list); if (eflag || vflag) Kokkos::parallel_reduce(list->inum,f,ev); else Kokkos::parallel_for(list->inum,f); diff --git a/src/KOKKOS/pair_table_kokkos.h b/src/KOKKOS/pair_table_kokkos.h index 80226d3770..18112e4c18 100644 --- a/src/KOKKOS/pair_table_kokkos.h +++ b/src/KOKKOS/pair_table_kokkos.h @@ -35,9 +35,6 @@ struct S_TableCompute { static constexpr int TabStyle = TABSTYLE; }; -template -struct PairTableComputeFunctor; - template class PairTableKokkos : public PairTable { public: @@ -135,33 +132,33 @@ class PairTableKokkos : public PairTable { F_FLOAT compute_ecoul(const F_FLOAT& /*rsq*/, const int& /*i*/, const int& /*j*/, const int& /*itype*/, const int& /*jtype*/) const { return 0; } - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; - friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; + friend struct PairComputeFunctor >; friend void pair_virial_fdotr_compute(PairTableKokkos*); }; diff --git a/src/KOKKOS/pair_yukawa_kokkos.h b/src/KOKKOS/pair_yukawa_kokkos.h index e04f65264b..dc93e83aea 100644 --- a/src/KOKKOS/pair_yukawa_kokkos.h +++ b/src/KOKKOS/pair_yukawa_kokkos.h @@ -95,20 +95,19 @@ class PairYukawaKokkos : public PairYukawa { int nlocal,nall,eflag,vflag; void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist( - PairYukawaKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist( - PairYukawaKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist( - PairYukawaKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute( - PairYukawaKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairYukawaKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairYukawaKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairYukawaKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairYukawaKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairYukawaKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairYukawaKokkos*); }; diff --git a/src/KOKKOS/pair_zbl_kokkos.h b/src/KOKKOS/pair_zbl_kokkos.h index bd33cdb5e0..b7638a25e0 100644 --- a/src/KOKKOS/pair_zbl_kokkos.h +++ b/src/KOKKOS/pair_zbl_kokkos.h @@ -89,16 +89,19 @@ class PairZBLKokkos : public PairZBL { void allocate() override; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend struct PairComputeFunctor; + friend struct PairComputeFunctor; + friend struct PairComputeFunctor; friend struct PairComputeFunctor; friend struct PairComputeFunctor; - friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); - friend EV_FLOAT pair_compute(PairZBLKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute_neighlist(PairZBLKokkos*,NeighListKokkos*); + friend EV_FLOAT pair_compute(PairZBLKokkos*,NeighListKokkos*); friend void pair_virial_fdotr_compute(PairZBLKokkos*); }; diff --git a/src/MAKE/OPTIONS/Makefile.intel_coprocessor b/src/MAKE/OPTIONS/Makefile.intel_coprocessor index 99e8d22d82..d8a67428de 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_coprocessor +++ b/src/MAKE/OPTIONS/Makefile.intel_coprocessor @@ -14,6 +14,7 @@ CCFLAGS = -qopenmp -qoffload -ansi-alias -restrict \ -DLMP_INTEL_USELRT -DLMP_USE_MKL_RNG -DLMP_INTEL_OFFLOAD \ $(OPTFLAGS) -I$(MKLROOT)/include SHFLAGS = -fPIC +FMTFLAGS = -std=c++11 DEPFLAGS = -M LINK = mpiicpc -std=c++11 @@ -118,6 +119,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi b/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi index 3439244b09..681bbaabe1 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_intelmpi @@ -6,13 +6,14 @@ SHELL = /bin/sh # compiler/linker settings # specify flags and libraries needed for your compiler -CC = mpiicpc -std=c++11 -diag-disable=10441 -diag-disable=2196 +CC = mpiicpc -std=c++11 -diag-disable=10441 -diag-disable=2196 -diag-disable=11074 -diag-disable=11076 OPTFLAGS = -xHost -O2 -fp-model fast=2 -no-prec-div -qoverride-limits \ -qopt-zmm-usage=high CCFLAGS = -qopenmp -qno-offload -ansi-alias -restrict \ -DLMP_INTEL_USELRT -DLMP_USE_MKL_RNG $(OPTFLAGS) \ -I$(MKLROOT)/include SHFLAGS = -fPIC +FMTFLAGS = -std=c++11 DEPFLAGS = -M LINK = mpiicpc -std=c++11 -diag-disable=10441 -diag-disable=2196 @@ -117,6 +118,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich b/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich index 042b207c91..f1a8c97fc6 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_mpich @@ -6,13 +6,14 @@ SHELL = /bin/sh # compiler/linker settings # specify flags and libraries needed for your compiler -CC = mpicxx -cxx=icc -std=c++11 -diag-disable=10441 -diag-disable=2196 +CC = mpicxx -cxx=icc -std=c++11 -diag-disable=10441 -diag-disable=2196 -diag-disable=11074 -diag-disable=11076 OPTFLAGS = -xHost -O2 -fp-model fast=2 -no-prec-div -qoverride-limits \ -qopt-zmm-usage=high CCFLAGS = -qopenmp -qno-offload -ansi-alias -restrict \ -DLMP_INTEL_USELRT -DLMP_USE_MKL_RNG $(OPTFLAGS) \ -I$(MKLROOT)/include SHFLAGS = -fPIC +FMTFLAGS = -std=c++11 DEPFLAGS = -M LINK = mpicxx -cxx=icc -std=c++11 -diag-disable=10441 -diag-disable=2196 @@ -117,6 +118,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi b/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi index 9f6de64987..c3e4451c7c 100644 --- a/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi +++ b/src/MAKE/OPTIONS/Makefile.intel_cpu_openmpi @@ -7,13 +7,14 @@ SHELL = /bin/sh # specify flags and libraries needed for your compiler export OMPI_CXX = icc -CC = mpicxx -std=c++11 -diag-disable=10441 -diag-disable=2196 +CC = mpicxx -std=c++11 -diag-disable=10441 -diag-disable=2196 -diag-disable=11074 -diag-disable=11076 OPTFLAGS = -xHost -O2 -fp-model fast=2 -no-prec-div -qoverride-limits \ -qopt-zmm-usage=high CCFLAGS = -qopenmp -qno-offload -ansi-alias -restrict \ -DLMP_INTEL_USELRT -DLMP_USE_MKL_RNG $(OPTFLAGS) \ -I$(MKLROOT)/include SHFLAGS = -fPIC +FMTFLAGS = -std=c++11 DEPFLAGS = -M LINK = mpicxx -std=c++11 -diag-disable=10441 -diag-disable=2196 @@ -118,6 +119,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi index b73c441c71..e78be1acdc 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi +++ b/src/MAKE/OPTIONS/Makefile.kokkos_cuda_mpi @@ -12,6 +12,8 @@ export OMPI_CXX = $(KOKKOS_ABSOLUTE_PATH)/bin/nvcc_wrapper CC = mpicxx CCFLAGS = -g -O3 -DNDEBUG -Xcudafe --diag_suppress=unrecognized_pragma SHFLAGS = -fPIC +# uncomment when compiling with Intel 21.5 or older +FMTFLAGS = # -std=c++11 DEPFLAGS = -M LINK = mpicxx @@ -36,7 +38,7 @@ KOKKOS_ARCH = Volta70 LMP_INC = -DLAMMPS_GZIP # MPI library -# see discussion in Section 2.2 (step 5) of manual +# see discussion in Section 3.4 of the manual # MPI wrapper compiler/linker can provide this info # can point to dummy MPI library in src/STUBS as in Makefile.serial # use -D MPICH and OMPI settings in INC to avoid C++ lib conflicts @@ -118,6 +120,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only b/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only index 0adb53eef0..e1f7005617 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only +++ b/src/MAKE/OPTIONS/Makefile.kokkos_mpi_only @@ -9,6 +9,8 @@ SHELL = /bin/sh CC = mpicxx CCFLAGS = -g -O3 -DNDEBUG SHFLAGS = -fPIC +# uncomment when compiling with Intel 21.5 or older +FMTFLAGS = # -std=c++11 DEPFLAGS = -M LINK = mpicxx @@ -114,6 +116,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_omp b/src/MAKE/OPTIONS/Makefile.kokkos_omp index 82144652dd..5f91af7a1e 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_omp +++ b/src/MAKE/OPTIONS/Makefile.kokkos_omp @@ -9,6 +9,8 @@ SHELL = /bin/sh CC = mpicxx CCFLAGS = -g -O3 -DNDEBUG SHFLAGS = -fPIC +# uncomment when compiling with Intel 21.5 or older +FMTFLAGS = # -std=c++11 DEPFLAGS = -M LINK = mpicxx @@ -114,6 +116,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MAKE/OPTIONS/Makefile.kokkos_phi b/src/MAKE/OPTIONS/Makefile.kokkos_phi index 9d5691251c..05b24f8721 100644 --- a/src/MAKE/OPTIONS/Makefile.kokkos_phi +++ b/src/MAKE/OPTIONS/Makefile.kokkos_phi @@ -9,6 +9,8 @@ SHELL = /bin/sh CC = mpicxx CCFLAGS = -g -O3 -DNDEBUG SHFLAGS = -fPIC +# uncomment when compiling with Intel 21.5 or older +FMTFLAGS = # -std=c++11 DEPFLAGS = -M LINK = mpicxx @@ -115,6 +117,18 @@ $(SHLIB): $(OBJ) $(EXTRA_LINK_DEPENDS) %.o:%.cpp $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) -c $< +variable.o : ../variable.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +utils.o : ../utils.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_format.o : ../fmtlib_format.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + +fmtlib_os.o : ../fmtlib_os.cpp + $(CC) $(CCFLAGS) $(SHFLAGS) $(EXTRA_INC) $(FMTFLAGS) -c $< + # Individual dependencies depend : fastdep.exe $(SRC) diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index fa69773d82..6fe0ac98b7 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -203,6 +203,10 @@ int FixAtomSwap::setmask() void FixAtomSwap::init() { + if (!atom->mass) error->all(FLERR, "Fix atom/swap requires per atom type masses"); + if (atom->rmass_flag && (comm->me == 0)) + error->warning(FLERR, "Fix atom/swap will use per-type masses for velocity rescaling"); + c_pe = modify->get_compute_by_id("thermo_pe"); int *type = atom->type; diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index ff8c5eb9c9..2e29b403fd 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -89,6 +89,7 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : ngroups = 0; ngrouptypes = 0; + triclinic = domain->triclinic; // required args @@ -123,8 +124,7 @@ FixGCMC::FixGCMC(LAMMPS *lmp, int narg, char **arg) : // error checks on region and its extent being inside simulation box - region_xlo = region_xhi = region_ylo = region_yhi = - region_zlo = region_zhi = 0.0; + region_xlo = region_xhi = region_ylo = region_yhi = region_zlo = region_zhi = 0.0; if (region) { if (region->bboxflag == 0) error->all(FLERR,"Fix gcmc region does not support a bounding box"); @@ -298,8 +298,7 @@ void FixGCMC::options(int narg, char **arg) } else if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); region = domain->get_region_by_id(arg[iarg+1]); - if (!region) - error->all(FLERR,"Region {} for fix gcmc does not exist",arg[iarg+1]); + if (!region) error->all(FLERR,"Region {} for fix gcmc does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"maxangle") == 0) { @@ -464,6 +463,8 @@ int FixGCMC::setmask() void FixGCMC::init() { + triclinic = domain->triclinic; + // set index and check validity of region if (idregion) { @@ -471,19 +472,31 @@ void FixGCMC::init() if (!region) error->all(FLERR, "Region {} for fix gcmc does not exist", idregion); } - triclinic = domain->triclinic; + if (region) { + if (region->bboxflag == 0) + error->all(FLERR,"Fix gcmc region does not support a bounding box"); + if (region->dynamic_check()) + error->all(FLERR,"Fix gcmc region cannot be dynamic"); - if (triclinic) { - if ((region_xlo < domain->boxlo_bound[0]) || (region_xhi > domain->boxhi_bound[0]) || - (region_ylo < domain->boxlo_bound[1]) || (region_yhi > domain->boxhi_bound[1]) || - (region_zlo < domain->boxlo_bound[2]) || (region_zhi > domain->boxhi_bound[2])) { - error->all(FLERR,"Fix gcmc region extends outside simulation box"); + region_xlo = region->extent_xlo; + region_xhi = region->extent_xhi; + region_ylo = region->extent_ylo; + region_yhi = region->extent_yhi; + region_zlo = region->extent_zlo; + region_zhi = region->extent_zhi; + + if (triclinic) { + if ((region_xlo < domain->boxlo_bound[0]) || (region_xhi > domain->boxhi_bound[0]) || + (region_ylo < domain->boxlo_bound[1]) || (region_yhi > domain->boxhi_bound[1]) || + (region_zlo < domain->boxlo_bound[2]) || (region_zhi > domain->boxhi_bound[2])) { + error->all(FLERR,"Fix gcmc region extends outside simulation box"); + } + } else { + if ((region_xlo < domain->boxlo[0]) || (region_xhi > domain->boxhi[0]) || + (region_ylo < domain->boxlo[1]) || (region_yhi > domain->boxhi[1]) || + (region_zlo < domain->boxlo[2]) || (region_zhi > domain->boxhi[2])) + error->all(FLERR,"Fix gcmc region extends outside simulation box"); } - } else { - if ((region_xlo < domain->boxlo[0]) || (region_xhi > domain->boxhi[0]) || - (region_ylo < domain->boxlo[1]) || (region_yhi > domain->boxhi[1]) || - (region_zlo < domain->boxlo[2]) || (region_zhi > domain->boxhi[2])) - error->all(FLERR,"Fix gcmc region extends outside simulation box"); } // set probabilities for MC moves diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index cc2f1bc94d..7869b213a0 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -73,6 +73,8 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : restart_global = 1; time_depend = 1; + triclinic = domain->triclinic; + // required args nevery = utils::inumeric(FLERR,arg[3],false,lmp); @@ -111,18 +113,6 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : region_zlo = region->extent_zlo; region_zhi = region->extent_zhi; - if (triclinic) { - if ((region_xlo < domain->boxlo_bound[0]) || (region_xhi > domain->boxhi_bound[0]) || - (region_ylo < domain->boxlo_bound[1]) || (region_yhi > domain->boxhi_bound[1]) || - (region_zlo < domain->boxlo_bound[2]) || (region_zhi > domain->boxhi_bound[2])) - error->all(FLERR,"Fix widom region {} extends outside simulation box", region->id); - } else { - if ((region_xlo < domain->boxlo[0]) || (region_xhi > domain->boxhi[0]) || - (region_ylo < domain->boxlo[1]) || (region_yhi > domain->boxhi[1]) || - (region_zlo < domain->boxlo[2]) || (region_zhi > domain->boxhi[2])) - error->all(FLERR,"Fix widom region {} extends outside simulation box", region->id); - } - // estimate region volume using MC trials double coord[3]; @@ -216,8 +206,7 @@ void FixWidom::options(int narg, char **arg) } else if (strcmp(arg[iarg],"region") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); region = domain->get_region_by_id(arg[iarg+1]); - if (!region) - error->all(FLERR,"Region {} for fix widom does not exist",arg[iarg+1]); + if (!region) error->all(FLERR,"Region {} for fix widom does not exist",arg[iarg+1]); idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"charge") == 0) { @@ -292,6 +281,7 @@ int FixWidom::setmask() void FixWidom::init() { + triclinic = domain->triclinic; // set index and check validity of region @@ -300,7 +290,31 @@ void FixWidom::init() if (!region) error->all(FLERR, "Region {} for fix widom does not exist", idregion); } - triclinic = domain->triclinic; + if (region) { + if (region->bboxflag == 0) + error->all(FLERR,"Fix gcmc region does not support a bounding box"); + if (region->dynamic_check()) + error->all(FLERR,"Fix gcmc region cannot be dynamic"); + + region_xlo = region->extent_xlo; + region_xhi = region->extent_xhi; + region_ylo = region->extent_ylo; + region_yhi = region->extent_yhi; + region_zlo = region->extent_zlo; + region_zhi = region->extent_zhi; + + if (triclinic) { + if ((region_xlo < domain->boxlo_bound[0]) || (region_xhi > domain->boxhi_bound[0]) || + (region_ylo < domain->boxlo_bound[1]) || (region_yhi > domain->boxhi_bound[1]) || + (region_zlo < domain->boxlo_bound[2]) || (region_zhi > domain->boxhi_bound[2])) + error->all(FLERR,"Fix widom region {} extends outside simulation box", region->id); + } else { + if ((region_xlo < domain->boxlo[0]) || (region_xhi > domain->boxhi[0]) || + (region_ylo < domain->boxlo[1]) || (region_yhi > domain->boxhi[1]) || + (region_zlo < domain->boxlo[2]) || (region_zhi > domain->boxhi[2])) + error->all(FLERR,"Fix widom region {} extends outside simulation box", region->id); + } + } ave_widom_chemical_potential = 0.0; diff --git a/src/MISC/fix_ipi.cpp b/src/MISC/fix_ipi.cpp index 69e0f2a7f3..30a6fe893d 100644 --- a/src/MISC/fix_ipi.cpp +++ b/src/MISC/fix_ipi.cpp @@ -98,7 +98,7 @@ static void open_socket(int &sockfd, int inet, int port, char *host, Error *erro // creates socket sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (sockfd < 0) error->one(FLERR, "Error opening socket"); + if (sockfd < 0) error->one(FLERR, "Error creating socket for fix ipi"); // makes connection if (connect(sockfd, res->ai_addr, res->ai_addrlen) < 0) @@ -116,6 +116,7 @@ static void open_socket(int &sockfd, int inet, int port, char *host, Error *erro // creates the socket sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd < 0) error->one(FLERR, "Error creating socket for fix ipi"); // connects if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) diff --git a/src/ML-IAP/mliap_data.cpp b/src/ML-IAP/mliap_data.cpp index 1c817bd3bd..b40fefd3ba 100644 --- a/src/ML-IAP/mliap_data.cpp +++ b/src/ML-IAP/mliap_data.cpp @@ -115,6 +115,7 @@ void MLIAPData::generate_neighdata(NeighList *list_in, int eflag_in, int vflag_i int **firstneigh = list->firstneigh; int nall = atom->nlocal + atom->nghost; + nlocal = atom->nlocal; ntotal = nall; // grow nmax gradforce, elems arrays if necessary diff --git a/src/ML-IAP/mliap_data.h b/src/ML-IAP/mliap_data.h index dc468b99cb..adb0dc4bd0 100644 --- a/src/ML-IAP/mliap_data.h +++ b/src/ML-IAP/mliap_data.h @@ -61,6 +61,7 @@ class MLIAPData : protected Pointers { int ntotal; // total number of owned and ghost atoms on this proc int nlistatoms; // current number of atoms in local atom lists int nlistatoms_max; // allocated size of descriptor array + int nlocal; int natomneigh; // current number of atoms and ghosts in atom neighbor arrays int natomneigh_max; // allocated size of atom neighbor arrays int *numneighs; // neighbors count for each atom diff --git a/src/ML-IAP/mliap_model_python_couple.pyx b/src/ML-IAP/mliap_model_python_couple.pyx index 1f5b739092..3beffc77bb 100644 --- a/src/ML-IAP/mliap_model_python_couple.pyx +++ b/src/ML-IAP/mliap_model_python_couple.pyx @@ -18,6 +18,7 @@ cdef extern from "mliap_data.h" namespace "LAMMPS_NS": cdef cppclass MLIAPData: # Array shapes int nlistatoms + int nlocal int ndescriptors # Input data diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index a3727976de..4de1709468 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -246,6 +246,7 @@ void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) { double e_total = 0.0; const auto nlistatoms = data->nlistatoms; + const auto nlocal = data->nlocal; for (int ii = 0; ii < nlistatoms; ii++) data->eatoms[ii] = 0; for (int ii = 0; ii < data->npairs; ii++) { @@ -253,7 +254,7 @@ void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) double e = 0.5 * eij[ii]; // must not count any contribution where i is not a local atom - if (i < nlistatoms) { + if (i < nlocal) { data->eatoms[i] += e; e_total += e; } @@ -267,7 +268,7 @@ void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) { - const auto nlistatoms = data->nlistatoms; + const auto nlocal = data->nlocal; double **f = data->f; for (int ii = 0; ii < data->npairs; ii++) { int ii3 = ii * 3; @@ -275,7 +276,7 @@ void LAMMPS_NS::update_pair_forces(MLIAPData *data, double *fij) int j = data->jatoms[ii]; // must not count any contribution where i is not a local atom - if (i < nlistatoms) { + if (i < nlocal) { f[i][0] += fij[ii3]; f[i][1] += fij[ii3 + 1]; f[i][2] += fij[ii3 + 2]; diff --git a/src/ML-IAP/mliap_unified_couple.pyx b/src/ML-IAP/mliap_unified_couple.pyx index 25852a1c5f..3148b96b51 100644 --- a/src/ML-IAP/mliap_unified_couple.pyx +++ b/src/ML-IAP/mliap_unified_couple.pyx @@ -53,7 +53,8 @@ cdef extern from "mliap_data.h" namespace "LAMMPS_NS": # only neighbors strictly inside descriptor cutoff int ntotal # total number of owned and ghost atoms on this proc - int nlistatoms # current number of atoms in local atom lists + int nlistatoms # current number of non-NULL atoms in local atom lists + int nlocal # current number of NULL and normal atoms in local atom lists int natomneigh # current number of atoms and ghosts in atom neighbor arrays int * numneighs # neighbors count for each atom int * iatoms # index of each atom @@ -113,11 +114,11 @@ cdef class MLIAPDataPy: def __cinit__(self): self.data = NULL - + def update_pair_energy(self, eij): cdef double[:] eij_arr = eij update_pair_energy(self.data, &eij_arr[0]) - + def update_pair_forces(self, fij): cdef double[:, ::1] fij_arr = fij update_pair_forces(self.data, &fij_arr[0][0]) @@ -127,11 +128,11 @@ cdef class MLIAPDataPy: if self.data.f is NULL: return None return np.asarray( &self.data.f[0][0]) - + @property def size_gradforce(self): return self.data.size_gradforce - + @write_only_property def gradforce(self, value): if self.data.gradforce is NULL: @@ -139,7 +140,7 @@ cdef class MLIAPDataPy: cdef double[:, :] gradforce_view = &self.data.gradforce[0][0] cdef double[:, :] value_view = value gradforce_view[:] = value_view - + @write_only_property def betas(self, value): if self.data.betas is NULL: @@ -216,7 +217,7 @@ cdef class MLIAPDataPy: @property def ntotal(self): return self.data.ntotal - + @property def elems(self): if self.data.elems is NULL: @@ -226,7 +227,11 @@ cdef class MLIAPDataPy: @property def nlistatoms(self): return self.data.nlistatoms - + + @property + def nlocal(self): + return self.data.nlocal + @property def natomneigh(self): return self.data.natomneigh @@ -242,13 +247,13 @@ cdef class MLIAPDataPy: if self.data.iatoms is NULL: return None return np.asarray( &self.data.iatoms[0]) - + @property def ielems(self): if self.data.ielems is NULL: return None return np.asarray( &self.data.ielems[0]) - + @property def npairs(self): return self.data.npairs @@ -258,7 +263,7 @@ cdef class MLIAPDataPy: if self.data.pair_i is NULL: return None return np.asarray( &self.data.pair_i[0]) - + @property def pair_j(self): return self.jatoms @@ -268,7 +273,7 @@ cdef class MLIAPDataPy: if self.data.jatoms is NULL: return None return np.asarray( &self.data.jatoms[0]) - + @property def jelems(self): if self.data.jelems is NULL: @@ -318,13 +323,13 @@ cdef class MLIAPUnifiedInterface: self.model = NULL self.descriptor = NULL self.unified_impl = unified_impl - + def compute_gradients(self, data): self.unified_impl.compute_gradients(data) - + def compute_descriptors(self, data): self.unified_impl.compute_descriptors(data) - + def compute_forces(self, data): self.unified_impl.compute_forces(data) @@ -379,7 +384,7 @@ cdef public object mliap_unified_connect(char *fname, MLIAPDummyModel * model, if unified.element_types is None: raise ValueError("no element type set") - + cdef int nelements = len(unified.element_types) cdef char **elements = malloc(nelements * sizeof(char*)) diff --git a/src/ML-PACE/pair_pace_extrapolation.cpp b/src/ML-PACE/pair_pace_extrapolation.cpp index 8a0116526a..dc0fb1848b 100644 --- a/src/ML-PACE/pair_pace_extrapolation.cpp +++ b/src/ML-PACE/pair_pace_extrapolation.cpp @@ -202,8 +202,10 @@ void PairPACEExtrapolation::compute(int eflag, int vflag) // jnum(0) = 50 // jlist(neigh ind of 0-atom) = [1,2,10,7,99,25, .. 50 element in total] try { - if (flag_compute_extrapolation_grade) + if (flag_compute_extrapolation_grade) { + aceimpl->ace->compute_projections = true; aceimpl->ace->compute_atom(i, x, type, jnum, jlist); + } else aceimpl->rec_ace->compute_atom(i, x, type, jnum, jlist); } catch (std::exception &e) { diff --git a/src/OPENMP/fix_rigid_nh_omp.cpp b/src/OPENMP/fix_rigid_nh_omp.cpp index 2f1b81fd5b..19e5d4f240 100644 --- a/src/OPENMP/fix_rigid_nh_omp.cpp +++ b/src/OPENMP/fix_rigid_nh_omp.cpp @@ -211,16 +211,31 @@ void FixRigidNHOMP::initial_integrate(int vflag) // set coords/orient and velocity/rotation of atoms in rigid bodies // from quarternion and omega - if (triclinic) - if (evflag) - set_xv_thr<1,1>(); - else - set_xv_thr<1,0>(); - else - if (evflag) - set_xv_thr<0,1>(); - else - set_xv_thr<0,0>(); + if (domain->dimension == 2) { + if (triclinic) { + if (evflag) + set_xv_thr<1,1,2>(); + else + set_xv_thr<1,0,2>(); + } else { + if (evflag) + set_xv_thr<0,1,2>(); + else + set_xv_thr<0,0,2>(); + } + } else { + if (triclinic) { + if (evflag) + set_xv_thr<1,1,3>(); + else + set_xv_thr<1,0,3>(); + } else { + if (evflag) + set_xv_thr<0,1,3>(); + else + set_xv_thr<0,0,3>(); + } + } // remap simulation box by full step // redo KSpace coeffs since volume has changed @@ -323,11 +338,13 @@ void FixRigidNHOMP::compute_forces_and_torques() // a few atoms each. so we loop over all atoms for all threads // and then each thread only processes some bodies. - const int nthreads=comm->nthreads; memset(&sum[0][0],0,6*nbody*sizeof(double)); #if defined(_OPENMP) + const int nthreads=comm->nthreads; #pragma omp parallel LMP_DEFAULT_NONE +#else + const int nthreads=1; #endif { #if defined(_OPENMP) @@ -503,13 +520,23 @@ void FixRigidNHOMP::final_integrate() // virial is already setup from initial_integrate // triclinic only matters for virial calculation. - if (evflag) - if (triclinic) - set_v_thr<1,1>(); + if (domain->dimension == 2) { + if (evflag) + if (triclinic) + set_v_thr<1,1,2>(); + else + set_v_thr<0,1,2>(); else - set_v_thr<0,1>(); - else - set_v_thr<0,0>(); + set_v_thr<0,0,2>(); + } else { + if (evflag) + if (triclinic) + set_v_thr<1,1,3>(); + else + set_v_thr<0,1,3>(); + else + set_v_thr<0,0,3>(); + } // compute current temperature if (tcomputeflag) t_current = temperature->compute_scalar(); @@ -558,9 +585,7 @@ void FixRigidNHOMP::remap() domain->x2lamda(x[i],x[i]); } - if (nrigid) - for (int i = 0; i < nrigidfix; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -590,9 +615,7 @@ void FixRigidNHOMP::remap() domain->lamda2x(x[i],x[i]); } - if (nrigid) - for (int i = 0; i< nrigidfix; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- @@ -603,7 +626,7 @@ void FixRigidNHOMP::remap() NOTE: this needs to be kept in sync with FixRigidOMP ------------------------------------------------------------------------- */ -template +template void FixRigidNHOMP::set_xv_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -665,6 +688,8 @@ void FixRigidNHOMP::set_xv_thr() v[i].y = omegai.z*x[i].x - omegai.x*x[i].z + vcmi.y; v[i].z = omegai.x*x[i].y - omegai.y*x[i].x + vcmi.z; + if (DIMENSION == 2) x[i].z = v[i].z = 0.0; + // add center of mass to displacement // map back into periodic box via xbox,ybox,zbox // for triclinic, add in box tilt factors as well @@ -803,7 +828,7 @@ void FixRigidNHOMP::set_xv_thr() NOTE: this needs to be kept in sync with FixRigidOMP ------------------------------------------------------------------------- */ -template +template void FixRigidNHOMP::set_v_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -852,6 +877,8 @@ void FixRigidNHOMP::set_v_thr() v[i].y = omegai.z*delta[0] - omegai.x*delta[2] + vcmi.y; v[i].z = omegai.x*delta[1] - omegai.y*delta[0] + vcmi.z; + if (DIMENSION == 2) v[i].z = 0.0; + // virial = unwrapped coords dotted into body constraint force // body constraint force = implied force due to v change minus f external // assume f does not include forces internal to body diff --git a/src/OPENMP/fix_rigid_nh_omp.h b/src/OPENMP/fix_rigid_nh_omp.h index 6b70841058..169bef706f 100644 --- a/src/OPENMP/fix_rigid_nh_omp.h +++ b/src/OPENMP/fix_rigid_nh_omp.h @@ -24,14 +24,14 @@ class FixRigidNHOMP : public FixRigidNH { void initial_integrate(int) override; void final_integrate() override; - virtual void remap(); + void remap() override; protected: - virtual void compute_forces_and_torques(); + void compute_forces_and_torques() override; private: // copied from FixRigidOMP - template void set_xv_thr(); - template void set_v_thr(); + template void set_xv_thr(); + template void set_v_thr(); }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/fix_rigid_omp.cpp b/src/OPENMP/fix_rigid_omp.cpp index de381415a0..75794b3419 100644 --- a/src/OPENMP/fix_rigid_omp.cpp +++ b/src/OPENMP/fix_rigid_omp.cpp @@ -16,33 +16,35 @@ Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ -#include "omp_compat.h" #include "fix_rigid_omp.h" -#include -#include #include "atom.h" #include "atom_vec_ellipsoid.h" #include "atom_vec_line.h" #include "atom_vec_tri.h" #include "comm.h" -#include "error.h" #include "domain.h" +#include "error.h" +#include "math_const.h" +#include "math_extra.h" +#include "rigid_const.h" + +#include +#include #if defined(_OPENMP) #include #endif - -#include "math_extra.h" -#include "math_const.h" -#include "rigid_const.h" +#include "omp_compat.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; using namespace RigidConst; -typedef struct { double x,y,z; } dbl3_t; +typedef struct { + double x, y, z; +} dbl3_t; /* ---------------------------------------------------------------------- */ @@ -77,13 +79,11 @@ void FixRigidOMP::initial_integrate(int vflag) // returns new normalized quaternion, also updated omega at 1/2 step // update ex,ey,ez to reflect new quaternion - MathExtra::angmom_to_omega(angmom[ibody],ex_space[ibody],ey_space[ibody], - ez_space[ibody],inertia[ibody],omega[ibody]); - MathExtra::richardson(quat[ibody],angmom[ibody],omega[ibody], - inertia[ibody],dtq); - MathExtra::q_to_exyz(quat[ibody], - ex_space[ibody],ey_space[ibody],ez_space[ibody]); - } // end of omp parallel for + MathExtra::angmom_to_omega(angmom[ibody], ex_space[ibody], ey_space[ibody], ez_space[ibody], + inertia[ibody], omega[ibody]); + MathExtra::richardson(quat[ibody], angmom[ibody], omega[ibody], inertia[ibody], dtq); + MathExtra::q_to_exyz(quat[ibody], ex_space[ibody], ey_space[ibody], ez_space[ibody]); + } // end of omp parallel for // virial setup before call to set_xv @@ -92,16 +92,32 @@ void FixRigidOMP::initial_integrate(int vflag) // set coords/orient and velocity/rotation of atoms in rigid bodies // from quarternion and omega - if (triclinic) - if (evflag) - set_xv_thr<1,1>(); - else - set_xv_thr<1,0>(); - else - if (evflag) - set_xv_thr<0,1>(); - else - set_xv_thr<0,0>(); + if (domain->dimension == 2) { + if (triclinic) { + if (evflag) + set_xv_thr<1,1,2>(); + else + set_xv_thr<1,0,2>(); + } else { + if (evflag) + set_xv_thr<0,1,2>(); + else + set_xv_thr<0,0,2>(); + } + } else { + + if (triclinic) { + if (evflag) + set_xv_thr<1,1,3>(); + else + set_xv_thr<1,0,3>(); + } else { + if (evflag) + set_xv_thr<0,1,3>(); + else + set_xv_thr<0,0,3>(); + } + } } /* ---------------------------------------------------------------------- */ @@ -152,7 +168,7 @@ void FixRigidOMP::compute_forces_and_torques() } else if (rstyle == GROUP) { - // we likely have only a rather number of groups so we loops + // we likely have a rather small number of groups so we loop // over bodies and thread over all atoms for each of them. for (int ib = 0; ib < nbody; ++ib) { @@ -196,11 +212,13 @@ void FixRigidOMP::compute_forces_and_torques() // a few atoms each. so we loop over all atoms for all threads // and then each thread only processes some bodies. - const int nthreads=comm->nthreads; memset(&sum[0][0],0,6*nbody*sizeof(double)); #if defined(_OPENMP) + const int nthreads=comm->nthreads; #pragma omp parallel LMP_DEFAULT_NONE +#else + const int nthreads=1; #endif { #if defined(_OPENMP) @@ -250,12 +268,12 @@ void FixRigidOMP::compute_forces_and_torques() #pragma omp parallel for LMP_DEFAULT_NONE schedule(static) #endif for (int ibody = 0; ibody < nbody; ibody++) { - fcm[ibody][0] = all[ibody][0] + langextra[ibody][0]; - fcm[ibody][1] = all[ibody][1] + langextra[ibody][1]; - fcm[ibody][2] = all[ibody][2] + langextra[ibody][2]; - torque[ibody][0] = all[ibody][3] + langextra[ibody][3]; - torque[ibody][1] = all[ibody][4] + langextra[ibody][4]; - torque[ibody][2] = all[ibody][5] + langextra[ibody][5]; + fcm[ibody][0] = all[ibody][0] + fflag[ibody][0]*langextra[ibody][0]; + fcm[ibody][1] = all[ibody][1] + fflag[ibody][1]*langextra[ibody][1]; + fcm[ibody][2] = all[ibody][2] + fflag[ibody][2]*langextra[ibody][2]; + torque[ibody][0] = all[ibody][3] + tflag[ibody][0]*langextra[ibody][3]; + torque[ibody][1] = all[ibody][4] + tflag[ibody][1]*langextra[ibody][4]; + torque[ibody][2] = all[ibody][5] + tflag[ibody][2]*langextra[ibody][5]; } // add gravity force to COM of each body @@ -277,6 +295,7 @@ void FixRigidOMP::compute_forces_and_torques() void FixRigidOMP::final_integrate() { if (!earlyflag) compute_forces_and_torques(); + if (domain->dimension == 2) enforce2d(); // update vcm and angmom @@ -306,13 +325,27 @@ void FixRigidOMP::final_integrate() // virial is already setup from initial_integrate // triclinic only matters for virial calculation. - if (evflag) - if (triclinic) - set_v_thr<1,1>(); +#if defined(_OPENMP) + if (domain->dimension == 2) { + if (evflag) + if (triclinic) + set_v_thr<1,1,2>(); + else + set_v_thr<0,1,2>(); else - set_v_thr<0,1>(); - else - set_v_thr<0,0>(); + set_v_thr<0,0,2>(); + } else { + if (evflag) + if (triclinic) + set_v_thr<1,1,3>(); + else + set_v_thr<0,1,3>(); + else + set_v_thr<0,0,3>(); + } +#else + set_v(); +#endif } /* ---------------------------------------------------------------------- @@ -323,7 +356,7 @@ void FixRigidOMP::final_integrate() NOTE: this needs to be kept in sync with FixRigidNHOMP ------------------------------------------------------------------------- */ -template +template void FixRigidOMP::set_xv_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -385,6 +418,8 @@ void FixRigidOMP::set_xv_thr() v[i].y = omegai.z*x[i].x - omegai.x*x[i].z + vcmi.y; v[i].z = omegai.x*x[i].y - omegai.y*x[i].x + vcmi.z; + if (DIMENSION == 2) x[i].z = v[i].z = 0.0; + // add center of mass to displacement // map back into periodic box via xbox,ybox,zbox // for triclinic, add in box tilt factors as well @@ -523,7 +558,7 @@ void FixRigidOMP::set_xv_thr() NOTE: this needs to be kept in sync with FixRigidNHOMP ------------------------------------------------------------------------- */ -template +template void FixRigidOMP::set_v_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -572,6 +607,8 @@ void FixRigidOMP::set_v_thr() v[i].y = omegai.z*delta[0] - omegai.x*delta[2] + vcmi.y; v[i].z = omegai.x*delta[1] - omegai.y*delta[0] + vcmi.z; + if (DIMENSION == 2) v[i].z = 0.0; + // virial = unwrapped coords dotted into body constraint force // body constraint force = implied force due to v change minus f external // assume f does not include forces internal to body diff --git a/src/OPENMP/fix_rigid_omp.h b/src/OPENMP/fix_rigid_omp.h index 679dff7508..b74b808544 100644 --- a/src/OPENMP/fix_rigid_omp.h +++ b/src/OPENMP/fix_rigid_omp.h @@ -32,11 +32,11 @@ class FixRigidOMP : public FixRigid { void final_integrate() override; protected: - virtual void compute_forces_and_torques(); + void compute_forces_and_torques() override; private: - template void set_xv_thr(); - template void set_v_thr(); + template void set_xv_thr(); + template void set_v_thr(); }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/fix_rigid_small_omp.cpp b/src/OPENMP/fix_rigid_small_omp.cpp index e11b98b7e1..59fd274f95 100644 --- a/src/OPENMP/fix_rigid_small_omp.cpp +++ b/src/OPENMP/fix_rigid_small_omp.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -16,31 +15,36 @@ Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ -#include "omp_compat.h" #include "fix_rigid_small_omp.h" -#include + #include "atom.h" #include "atom_vec_ellipsoid.h" #include "atom_vec_line.h" #include "atom_vec_tri.h" #include "comm.h" #include "domain.h" +#include "math_const.h" +#include "math_extra.h" +#include "rigid_const.h" + +#include + +#include "omp_compat.h" #if defined(_OPENMP) #include #endif -#include "math_extra.h" -#include "math_const.h" -#include "rigid_const.h" - using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; using namespace RigidConst; -typedef struct { double x,y,z; } dbl3_t; +typedef struct { + double x, y, z; +} dbl3_t; +// clang-format off /* ---------------------------------------------------------------------- */ void FixRigidSmallOMP::initial_integrate(int vflag) @@ -94,16 +98,36 @@ void FixRigidSmallOMP::initial_integrate(int vflag) // set coords/orient and velocity/rotation of atoms in rigid bodies - if (triclinic) - if (evflag) - set_xv_thr<1,1>(); - else - set_xv_thr<1,0>(); - else - if (evflag) - set_xv_thr<0,1>(); - else - set_xv_thr<0,0>(); +#if defined(_OPENMP) + if (domain->dimension == 2) { + if (triclinic) { + if (evflag) + set_xv_thr<1,1,2>(); + else + set_xv_thr<1,0,2>(); + } else { + + if (evflag) + set_xv_thr<0,1,2>(); + else + set_xv_thr<0,0,2>(); + } + } else { + if (triclinic) { + if (evflag) + set_xv_thr<1,1,3>(); + else + set_xv_thr<1,0,3>(); + } else { + if (evflag) + set_xv_thr<0,1,3>(); + else + set_xv_thr<0,0,3>(); + } + } +#else + set_xv(); +#endif } /* ---------------------------------------------------------------------- */ @@ -114,7 +138,6 @@ void FixRigidSmallOMP::compute_forces_and_torques() const auto * _noalias const f = (dbl3_t *) atom->f[0]; const double * const * const torque_one = atom->torque; const int nlocal = atom->nlocal; - const int nthreads=comm->nthreads; #if defined(_OPENMP) #pragma omp parallel for LMP_DEFAULT_NONE schedule(static) @@ -132,7 +155,10 @@ void FixRigidSmallOMP::compute_forces_and_torques() // and then each thread only processes some bodies. #if defined(_OPENMP) + const int nthreads=comm->nthreads; #pragma omp parallel LMP_DEFAULT_NONE +#else + const int nthreads=1; #endif { #if defined(_OPENMP) @@ -218,6 +244,7 @@ void FixRigidSmallOMP::compute_forces_and_torques() void FixRigidSmallOMP::final_integrate() { if (!earlyflag) compute_forces_and_torques(); + if (domain->dimension == 2) enforce2d(); // update vcm and angmom, recompute omega @@ -253,24 +280,34 @@ void FixRigidSmallOMP::final_integrate() // virial is already setup from initial_integrate // triclinic only matters for virial calculation. - if (evflag) - if (triclinic) - set_v_thr<1,1>(); + if (domain->dimension == 2) { + if (evflag) { + if (triclinic) + set_v_thr<1,1,2>(); + else + set_v_thr<0,1,2>(); + } else { + set_v_thr<0,0,2>(); + } + } else { + if (evflag) + if (triclinic) + set_v_thr<1,1,3>(); + else + set_v_thr<0,1,3>(); else - set_v_thr<0,1>(); - else - set_v_thr<0,0>(); + set_v_thr<0,0,3>(); + } } - /* ---------------------------------------------------------------------- set space-frame coords and velocity of each atom in each rigid body set orientation and rotation of extended particles x = Q displace + Xcm, mapped back to periodic box v = Vcm + (W cross (x - Xcm)) -------------------------------------------------------------------------- */ + ------------------------------------------------------------------------- */ -template +template void FixRigidSmallOMP::set_xv_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -329,6 +366,8 @@ void FixRigidSmallOMP::set_xv_thr() v[i].y = b.omega[2]*x[i].x - b.omega[0]*x[i].z + b.vcm[1]; v[i].z = b.omega[0]*x[i].y - b.omega[1]*x[i].x + b.vcm[2]; + if (DIMENSION == 2) x[i].z = v[i].z = 0.0; + // add center of mass to displacement // map back into periodic box via xbox,ybox,zbox // for triclinic, add in box tilt factors as well @@ -463,9 +502,9 @@ void FixRigidSmallOMP::set_xv_thr() set space-frame velocity of each atom in a rigid body set omega and angmom of extended particles v = Vcm + (W cross (x - Xcm)) -------------------------------------------------------------------------- */ + ------------------------------------------------------------------------- */ -template +template void FixRigidSmallOMP::set_v_thr() { auto * _noalias const x = (dbl3_t *) atom->x[0]; @@ -512,6 +551,8 @@ void FixRigidSmallOMP::set_v_thr() v[i].y = b.omega[2]*delta[0] - b.omega[0]*delta[2] + b.vcm[1]; v[i].z = b.omega[0]*delta[1] - b.omega[1]*delta[0] + b.vcm[2]; + if (DIMENSION == 2) v[i].z = 0.0; + // virial = unwrapped coords dotted into body constraint force // body constraint force = implied force due to v change minus f external // assume f does not include forces internal to body @@ -564,8 +605,8 @@ void FixRigidSmallOMP::set_v_thr() } } // end of parallel for - // second part of thread safe virial accumulation - // add global virial component after it was reduced across all threads + // second part of thread safe virial accumulation + // add global virial component after it was reduced across all threads if (EVFLAG) { if (vflag_global) { virial[0] += v0; @@ -624,4 +665,3 @@ void FixRigidSmallOMP::set_v_thr() } } } - diff --git a/src/OPENMP/fix_rigid_small_omp.h b/src/OPENMP/fix_rigid_small_omp.h index 3d8bca1a6d..d3a7bd6349 100644 --- a/src/OPENMP/fix_rigid_small_omp.h +++ b/src/OPENMP/fix_rigid_small_omp.h @@ -36,11 +36,11 @@ class FixRigidSmallOMP : public FixRigidSmall { void final_integrate() override; protected: - virtual void compute_forces_and_torques(); + void compute_forces_and_torques() override; private: - template void set_xv_thr(); - template void set_v_thr(); + template void set_xv_thr(); + template void set_v_thr(); }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/npair_halffull_newton_trim_omp.cpp b/src/OPENMP/npair_halffull_newton_trim_omp.cpp index 1446175013..98a7d6dd68 100644 --- a/src/OPENMP/npair_halffull_newton_trim_omp.cpp +++ b/src/OPENMP/npair_halffull_newton_trim_omp.cpp @@ -15,7 +15,9 @@ #include "npair_halffull_newton_trim_omp.h" #include "atom.h" +#include "domain.h" #include "error.h" +#include "force.h" #include "my_page.h" #include "neigh_list.h" #include "npair_omp.h" @@ -38,6 +40,8 @@ NPairHalffullNewtonTrimOmp::NPairHalffullNewtonTrimOmp(LAMMPS *lmp) : NPair(lmp) void NPairHalffullNewtonTrimOmp::build(NeighList *list) { const int inum_full = list->listfull->inum; + const double delta = 0.01 * force->angstrom; + const int triclinic = domain->triclinic; NPAIR_OMP_INIT; #if defined(_OPENMP) @@ -86,8 +90,17 @@ void NPairHalffullNewtonTrimOmp::build(NeighList *list) for (jj = 0; jj < jnum; jj++) { joriginal = jlist[jj]; j = joriginal & NEIGHMASK; + if (j < nlocal) { if (i > j) continue; + } else if (triclinic) { + if (fabs(x[j][2]-ztmp) > delta) { + if (x[j][2] < ztmp) continue; + } else if (fabs(x[j][1]-ytmp) > delta) { + if (x[j][1] < ytmp) continue; + } else { + if (x[j][0] < xtmp) continue; + } } else { if (x[j][2] < ztmp) continue; if (x[j][2] == ztmp) { diff --git a/src/OPENMP/npair_omp.h b/src/OPENMP/npair_omp.h index 318fddfd54..7249c59406 100644 --- a/src/OPENMP/npair_omp.h +++ b/src/OPENMP/npair_omp.h @@ -32,6 +32,7 @@ namespace LAMMPS_NS { // get access to number of threads and per-thread data structures via FixOMP #define NPAIR_OMP_INIT \ const int nthreads = comm->nthreads; \ + omp_set_num_threads(nthreads); \ const int ifix = modify->find_fix("package_omp") // get thread id and then assign each thread a fixed chunk of atoms diff --git a/src/OPENMP/reaxff_forces_omp.cpp b/src/OPENMP/reaxff_forces_omp.cpp index 50157da594..26922add1e 100644 --- a/src/OPENMP/reaxff_forces_omp.cpp +++ b/src/OPENMP/reaxff_forces_omp.cpp @@ -354,6 +354,9 @@ namespace ReaxFF { // Need to wait for all indices and tmp arrays accumulated. #if defined(_OPENMP) #pragma omp barrier + { + ; + } #endif #if defined(_OPENMP) diff --git a/src/OPENMP/thr_omp.cpp b/src/OPENMP/thr_omp.cpp index c27a99028d..88344a900d 100644 --- a/src/OPENMP/thr_omp.cpp +++ b/src/OPENMP/thr_omp.cpp @@ -34,6 +34,10 @@ #include +#if defined(_OPENMP) +#include +#endif + using namespace LAMMPS_NS; using MathConst::THIRD; @@ -44,6 +48,9 @@ ThrOMP::ThrOMP(LAMMPS *ptr, int style) : lmp(ptr), fix(nullptr), thr_style(style // register fix omp with this class fix = static_cast(lmp->modify->get_fix_by_id("package_omp")); if (!fix) lmp->error->all(FLERR, "The 'package omp' command is required for /omp styles"); +#if defined(_OPENMP) + omp_set_num_threads(lmp->comm->nthreads); +#endif } // clang-format off diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 57f8ea1cf0..ea4ac63ce7 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -29,19 +29,31 @@ #ifdef MLIAP_PYTHON #include "mliap_model_python.h" +#if defined(__PYX_EXTERN_C) && !defined(CYTHON_EXTERN_C) +#undef __PYX_EXTERN_C +#endif #include "mliap_unified.h" // The above should somehow really be included in the next file. // We could get around this with cython --capi-reexport-cincludes // However, that exposes -too many- headers. #include "mliap_model_python_couple.h" +#if defined(__PYX_EXTERN_C) && !defined(CYTHON_EXTERN_C) +#undef __PYX_EXTERN_C +#endif #include "mliap_unified_couple.h" #ifdef LMP_KOKKOS #include "mliap_model_python_kokkos.h" +#if defined(__PYX_EXTERN_C) && !defined(CYTHON_EXTERN_C) +#undef __PYX_EXTERN_C +#endif #include "mliap_unified_kokkos.h" // The above should somehow really be included in the next file. // We could get around this with cython --capi-reexport-cincludes // However, that exposes -too many- headers. #include "mliap_model_python_couple_kokkos.h" +#if defined(__PYX_EXTERN_C) && !defined(CYTHON_EXTERN_C) +#undef __PYX_EXTERN_C +#endif #include "mliap_unified_couple_kokkos.h" @@ -61,17 +73,22 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) nfunc = 0; pfuncs = nullptr; -#if PY_MAJOR_VERSION >= 3 -#ifndef Py_LIMITED_API +#if PY_MAJOR_VERSION >= 3 && !defined(Py_LIMITED_API) // check for PYTHONUNBUFFERED environment variable const char *PYTHONUNBUFFERED = getenv("PYTHONUNBUFFERED"); + // Force the stdout and stderr streams to be unbuffered. + bool unbuffered = PYTHONUNBUFFERED != nullptr && strcmp(PYTHONUNBUFFERED, "1") == 0; - if (PYTHONUNBUFFERED != nullptr && strcmp(PYTHONUNBUFFERED, "1") == 0) { - // Python Global configuration variable - // Force the stdout and stderr streams to be unbuffered. - Py_UnbufferedStdioFlag = 1; - } +#if (PY_VERSION_HEX >= 0x030800f0) && !defined(__APPLE__) + PyConfig config; + PyConfig_InitPythonConfig(&config); + config.buffered_stdio = !unbuffered; +#else + // Python Global configuration variable + Py_UnbufferedStdioFlag = unbuffered; #endif +#else +#warning Cannot force stdout and stderr to be unbuffered #endif #ifdef MLIAP_PYTHON @@ -94,12 +111,17 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) #endif #endif +#if PY_VERSION_HEX >= 0x030800f0 && !defined(Py_LIMITED_API) + Py_InitializeFromConfig(&config); + PyConfig_Clear(&config); +#else Py_Initialize(); +#endif // only needed for Python 2.x and Python 3 < 3.7 // With Python 3.7 this function is now called by Py_Initialize() // Deprecated since version 3.9, will be removed in version 3.11 -#if PY_MAJOR_VERSION < 3 || PY_MINOR_VERSION < 7 +#if PY_VERSION_HEX < 0x030700f0 if (!PyEval_ThreadsInitialized()) { PyEval_InitThreads(); } #endif diff --git a/src/Purge.list b/src/Purge.list index 1d2cdcf06b..42c669c39d 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -8,6 +8,7 @@ style_compute.h style_dihedral.h style_dump.h style_fix.h +style_gran_sub_mod.h style_improper.h style_integrate.h style_kspace.h @@ -32,6 +33,7 @@ packages_compute.h packages_dihedral.h packages_dump.h packages_fix.h +packages_gran_sub_mod.h packages_improper.h packages_integrate.h packages_kspace.h diff --git a/src/QTB/fix_qbmsst.cpp b/src/QTB/fix_qbmsst.cpp index b5fb5ca77c..a8a72b002b 100644 --- a/src/QTB/fix_qbmsst.cpp +++ b/src/QTB/fix_qbmsst.cpp @@ -74,6 +74,7 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) vector_flag = 1; size_vector = 5; ecouple_flag = 1; + energy_global_flag = 1; qmass = 1.0e1; mu = 0.0; diff --git a/src/REAXFF/reaxff_ffield.cpp b/src/REAXFF/reaxff_ffield.cpp index d79d63b87b..12fbc781db 100644 --- a/src/REAXFF/reaxff_ffield.cpp +++ b/src/REAXFF/reaxff_ffield.cpp @@ -336,7 +336,7 @@ namespace ReaxFF { values = reader.next_values(0); ++lineno; - if (values.count() < 8) + if (values.count() < 7) THROW_ERROR("Invalid force field file format"); if ((j < ntypes) && (k < ntypes)) { @@ -346,7 +346,11 @@ namespace ReaxFF { values.skip(); tbp[j][k].p_bo1 = tbp[k][j].p_bo1 = values.next_double(); tbp[j][k].p_bo2 = tbp[k][j].p_bo2 = values.next_double(); - tbp[j][k].ovc = tbp[k][j].ovc = values.next_double(); + // if the 8th value is missing use 0.0 + if (values.has_next()) + tbp[j][k].ovc = tbp[k][j].ovc = values.next_double(); + else + tbp[j][k].ovc = tbp[k][j].ovc = 0.0; } } diff --git a/src/REPLICA/fix_pimd_langevin.cpp b/src/REPLICA/fix_pimd_langevin.cpp index 7ba502d2e6..553da625c7 100644 --- a/src/REPLICA/fix_pimd_langevin.cpp +++ b/src/REPLICA/fix_pimd_langevin.cpp @@ -1353,7 +1353,7 @@ void FixPIMDLangevin::compute_tote() void FixPIMDLangevin::compute_t_prim() { - t_prim = 1.5 * atom->natoms * np * force->boltz * temp - total_spring_energy; + t_prim = 1.5 * atom->natoms * np * force->boltz * temp - total_spring_energy * inverse_np; } /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 44427d2914..628abb240e 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -47,18 +46,16 @@ using namespace RigidConst; /* ---------------------------------------------------------------------- */ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), step_respa(nullptr), - inpfile(nullptr), nrigid(nullptr), mol2body(nullptr), body2mol(nullptr), - body(nullptr), displace(nullptr), masstotal(nullptr), xcm(nullptr), - vcm(nullptr), fcm(nullptr), inertia(nullptr), ex_space(nullptr), - ey_space(nullptr), ez_space(nullptr), angmom(nullptr), omega(nullptr), - torque(nullptr), quat(nullptr), imagebody(nullptr), fflag(nullptr), - tflag(nullptr), langextra(nullptr), sum(nullptr), all(nullptr), - remapflag(nullptr), xcmimage(nullptr), eflags(nullptr), orient(nullptr), - dorient(nullptr), id_dilate(nullptr), id_gravity(nullptr), random(nullptr), - avec_ellipsoid(nullptr), avec_line(nullptr), avec_tri(nullptr) + Fix(lmp, narg, arg), step_respa(nullptr), inpfile(nullptr), nrigid(nullptr), mol2body(nullptr), + body2mol(nullptr), body(nullptr), displace(nullptr), masstotal(nullptr), xcm(nullptr), + vcm(nullptr), fcm(nullptr), inertia(nullptr), ex_space(nullptr), ey_space(nullptr), + ez_space(nullptr), angmom(nullptr), omega(nullptr), torque(nullptr), quat(nullptr), + imagebody(nullptr), fflag(nullptr), tflag(nullptr), langextra(nullptr), sum(nullptr), + all(nullptr), remapflag(nullptr), xcmimage(nullptr), eflags(nullptr), orient(nullptr), + dorient(nullptr), id_dilate(nullptr), id_gravity(nullptr), random(nullptr), + avec_ellipsoid(nullptr), avec_line(nullptr), avec_tri(nullptr) { - int i,ibody; + int i, ibody; scalar_flag = 1; extscalar = 0; @@ -68,12 +65,8 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : thermo_virial = 1; create_attribute = 1; dof_flag = 1; - enforce2d_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); - // perform initial allocation of atom-based arrays // register with Atom class @@ -90,7 +83,7 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : // parse args for rigid body specification // set nbody and body[i] for each atom - if (narg < 4) error->all(FLERR,"Illegal fix rigid command"); + if (narg < 4) utils::missing_cmd_args(FLERR, std::string("fix ") + style, error); int iarg; mol2body = nullptr; @@ -100,7 +93,7 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : // nbody = 1 // all atoms in fix group are part of body - if (strcmp(arg[3],"single") == 0) { + if (strcmp(arg[3], "single") == 0) { rstyle = SINGLE; iarg = 4; nbody = 1; @@ -113,67 +106,68 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : if (mask[i] & groupbit) body[i] = 0; } - // each molecule in fix group is a rigid body - // maxmol = largest molecule ID - // ncount = # of atoms in each molecule (have to sum across procs) - // nbody = # of non-zero ncount values - // use nall as incremented ptr to set body[] values for each atom + // each molecule in fix group is a rigid body + // maxmol = largest molecule ID + // ncount = # of atoms in each molecule (have to sum across procs) + // nbody = # of non-zero ncount values + // use nall as incremented ptr to set body[] values for each atom - } else if (strcmp(arg[3],"molecule") == 0 || strcmp(arg[3],"custom") == 0) { + } else if ((strcmp(arg[3], "molecule") == 0) || (strcmp(arg[3], "custom") == 0)) { rstyle = MOLECULE; tagint *molecule; int *mask = atom->mask; int nlocal = atom->nlocal; - int custom_flag = strcmp(arg[3],"custom") == 0; + int custom_flag = strcmp(arg[3], "custom") == 0; if (custom_flag) { - if (narg < 5) error->all(FLERR,"Illegal fix rigid command"); + if (narg < 5) utils::missing_cmd_args(FLERR, fmt::format("fix {} custom"), error); // determine whether atom-style variable or atom property is used - if (utils::strmatch(arg[4],"^i_")) { - int is_double,cols; - int custom_index = atom->find_custom(arg[4]+2,is_double,cols); + if (utils::strmatch(arg[4], "^i_")) { + int is_double, cols; + int custom_index = atom->find_custom(arg[4] + 2, is_double, cols); if (custom_index == -1) - error->all(FLERR,"Fix rigid custom requires previously defined property/atom"); + error->all(FLERR, "Fix {} custom requires previously defined property/atom", style); else if (is_double) - error->all(FLERR,"Fix rigid custom requires integer-valued property/atom vector"); + error->all(FLERR, "Fix {} custom requires integer-valued property/atom vector", style); int minval = INT_MAX; int *value = atom->ivector[custom_index]; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) minval = MIN(minval,value[i]); + if (mask[i] & groupbit) minval = MIN(minval, value[i]); int vmin = minval; - MPI_Allreduce(&vmin,&minval,1,MPI_INT,MPI_MIN,world); + MPI_Allreduce(&vmin, &minval, 1, MPI_INT, MPI_MIN, world); molecule = new tagint[nlocal]; for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) - molecule[i] = (tagint)(value[i] - minval + 1); + molecule[i] = (tagint) (value[i] - minval + 1); else molecule[i] = 0; - } else if (utils::strmatch(arg[4],"^v_")) { - int ivariable = input->variable->find(arg[4]+2); + } else if (utils::strmatch(arg[4], "^v_")) { + int ivariable = input->variable->find(arg[4] + 2); if (ivariable < 0) - error->all(FLERR,"Variable {} for fix rigid/small custom does not exist", arg[4]+2); + error->all(FLERR, "Variable {} for fix {} custom does not exist", arg[4] + 2, style); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Fix rigid custom variable {} is not atom-style variable", arg[4]+2); + error->all(FLERR, "Fix {} custom variable {} is not atom-style variable", style, + arg[4] + 2); auto value = new double[nlocal]; - input->variable->compute_atom(ivariable,0,value,1,0); + input->variable->compute_atom(ivariable, 0, value, 1, 0); int minval = INT_MAX; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) minval = MIN(minval,(int)value[i]); + if (mask[i] & groupbit) minval = MIN(minval, (int) value[i]); int vmin = minval; - MPI_Allreduce(&vmin,&minval,1,MPI_INT,MPI_MIN,world); + MPI_Allreduce(&vmin, &minval, 1, MPI_INT, MPI_MIN, world); molecule = new tagint[nlocal]; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) - molecule[i] = (tagint)((tagint)value[i] - minval + 1); + if (mask[i] & groupbit) molecule[i] = (tagint) ((tagint) value[i] - minval + 1); delete[] value; - } else error->all(FLERR,"Unsupported fix rigid custom property"); + } else + error->all(FLERR, "Unsupported fix {} custom property: {}", style, arg[4]); } else { if (atom->molecule_flag == 0) - error->all(FLERR,"Fix rigid molecule requires atom attribute molecule"); + error->all(FLERR, "Fix {} molecule requires atom attribute molecule", style); molecule = atom->molecule; } @@ -181,30 +175,31 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : tagint maxmol_tag = -1; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) maxmol_tag = MAX(maxmol_tag,molecule[i]); + if (mask[i] & groupbit) maxmol_tag = MAX(maxmol_tag, molecule[i]); tagint itmp; - MPI_Allreduce(&maxmol_tag,&itmp,1,MPI_LMP_TAGINT,MPI_MAX,world); - if (itmp+1 > MAXSMALLINT) - error->all(FLERR,"Too many molecules for fix rigid"); + MPI_Allreduce(&maxmol_tag, &itmp, 1, MPI_LMP_TAGINT, MPI_MAX, world); + if (itmp + 1 > MAXSMALLINT) error->all(FLERR, "Too many molecules for fix {}", style); maxmol = (int) itmp; int *ncount; - memory->create(ncount,maxmol+1,"rigid:ncount"); + memory->create(ncount, maxmol + 1, "rigid:ncount"); for (i = 0; i <= maxmol; i++) ncount[i] = 0; for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) ncount[molecule[i]]++; - memory->create(mol2body,maxmol+1,"rigid:mol2body"); - MPI_Allreduce(ncount,mol2body,maxmol+1,MPI_INT,MPI_SUM,world); + memory->create(mol2body, maxmol + 1, "rigid:mol2body"); + MPI_Allreduce(ncount, mol2body, maxmol + 1, MPI_INT, MPI_SUM, world); nbody = 0; for (i = 0; i <= maxmol; i++) - if (mol2body[i]) mol2body[i] = nbody++; - else mol2body[i] = -1; + if (mol2body[i]) + mol2body[i] = nbody++; + else + mol2body[i] = -1; - memory->create(body2mol,nbody,"rigid:body2mol"); + memory->create(body2mol, nbody, "rigid:body2mol"); nbody = 0; for (i = 0; i <= maxmol; i++) @@ -218,24 +213,24 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : memory->destroy(ncount); if (custom_flag) delete[] molecule; - // each listed group is a rigid body - // check if all listed groups exist - // an atom must belong to fix group and listed group to be in rigid body - // error if atom belongs to more than 1 rigid body + // each listed group is a rigid body + // check if all listed groups exist + // an atom must belong to fix group and listed group to be in rigid body + // error if atom belongs to more than 1 rigid body - } else if (strcmp(arg[3],"group") == 0) { - if (narg < 5) error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[3], "group") == 0) { + if (narg < 5) utils::missing_cmd_args(FLERR, fmt::format("fix {} group"), error); rstyle = GROUP; - nbody = utils::inumeric(FLERR,arg[4],false,lmp); - if (nbody <= 0) error->all(FLERR,"Illegal fix rigid command"); - if (narg < 5+nbody) error->all(FLERR,"Illegal fix rigid command"); - iarg = 5+nbody; + nbody = utils::inumeric(FLERR, arg[4], false, lmp); + if (nbody <= 0) error->all(FLERR, "Illegal fix {} number of groups {}", style, nbody); + if (narg < 5 + nbody) utils::missing_cmd_args(FLERR, fmt::format("fix {} group"), error); + iarg = 5 + nbody; int *igroups = new int[nbody]; for (ibody = 0; ibody < nbody; ibody++) { - igroups[ibody] = group->find(arg[5+ibody]); + igroups[ibody] = group->find(arg[5 + ibody]); if (igroups[ibody] == -1) - error->all(FLERR,"Could not find fix rigid group ID"); + error->all(FLERR, "Could not find fix {} group ID {}", style, arg[5 + ibody]); } int *mask = atom->mask; @@ -253,41 +248,41 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : } int flagall; - MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); - if (flagall) - error->all(FLERR,"One or more atoms belong to multiple rigid bodies"); + MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world); + if (flagall) error->all(FLERR, "One or more atoms belong to multiple rigid bodies"); delete[] igroups; - } else error->all(FLERR,"Illegal fix rigid command"); + } else + error->all(FLERR, "Unknown fix {} mode {}", style, arg[3]); // error check on nbody - if (nbody == 0) error->all(FLERR,"No rigid bodies defined"); + if (nbody == 0) error->all(FLERR, "No rigid bodies defined"); // create all nbody-length arrays - memory->create(nrigid,nbody,"rigid:nrigid"); - memory->create(masstotal,nbody,"rigid:masstotal"); - memory->create(xcm,nbody,3,"rigid:xcm"); - memory->create(vcm,nbody,3,"rigid:vcm"); - memory->create(fcm,nbody,3,"rigid:fcm"); - memory->create(inertia,nbody,3,"rigid:inertia"); - memory->create(ex_space,nbody,3,"rigid:ex_space"); - memory->create(ey_space,nbody,3,"rigid:ey_space"); - memory->create(ez_space,nbody,3,"rigid:ez_space"); - memory->create(angmom,nbody,3,"rigid:angmom"); - memory->create(omega,nbody,3,"rigid:omega"); - memory->create(torque,nbody,3,"rigid:torque"); - memory->create(quat,nbody,4,"rigid:quat"); - memory->create(imagebody,nbody,"rigid:imagebody"); - memory->create(fflag,nbody,3,"rigid:fflag"); - memory->create(tflag,nbody,3,"rigid:tflag"); - memory->create(langextra,nbody,6,"rigid:langextra"); + memory->create(nrigid, nbody, "rigid:nrigid"); + memory->create(masstotal, nbody, "rigid:masstotal"); + memory->create(xcm, nbody, 3, "rigid:xcm"); + memory->create(vcm, nbody, 3, "rigid:vcm"); + memory->create(fcm, nbody, 3, "rigid:fcm"); + memory->create(inertia, nbody, 3, "rigid:inertia"); + memory->create(ex_space, nbody, 3, "rigid:ex_space"); + memory->create(ey_space, nbody, 3, "rigid:ey_space"); + memory->create(ez_space, nbody, 3, "rigid:ez_space"); + memory->create(angmom, nbody, 3, "rigid:angmom"); + memory->create(omega, nbody, 3, "rigid:omega"); + memory->create(torque, nbody, 3, "rigid:torque"); + memory->create(quat, nbody, 4, "rigid:quat"); + memory->create(imagebody, nbody, "rigid:imagebody"); + memory->create(fflag, nbody, 3, "rigid:fflag"); + memory->create(tflag, nbody, 3, "rigid:tflag"); + memory->create(langextra, nbody, 6, "rigid:langextra"); - memory->create(sum,nbody,6,"rigid:sum"); - memory->create(all,nbody,6,"rigid:all"); - memory->create(remapflag,nbody,4,"rigid:remapflag"); + memory->create(sum, nbody, 6, "rigid:sum"); + memory->create(all, nbody, 6, "rigid:all"); + memory->create(remapflag, nbody, 4, "rigid:remapflag"); // initialize force/torque flags to default = 1.0 // for 2d: fz, tx, ty = 0.0 @@ -328,7 +323,6 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : pcouple = NONE; pstyle = ANISO; - dimension = domain->dimension; for (i = 0; i < 3; i++) { p_start[i] = p_stop[i] = p_period[i] = 0.0; @@ -336,229 +330,254 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : } while (iarg < narg) { - if (strcmp(arg[iarg],"force") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal fix rigid command"); + if (strcmp(arg[iarg], "force") == 0) { + if (iarg + 5 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} force", style), error); - int mlo,mhi; - utils::bounds(FLERR,arg[iarg+1],1,nbody,mlo,mhi,error); + int mlo, mhi; + utils::bounds(FLERR, arg[iarg + 1], 1, nbody, mlo, mhi, error); - double xflag,yflag,zflag; - if (strcmp(arg[iarg+2],"off") == 0) xflag = 0.0; - else if (strcmp(arg[iarg+2],"on") == 0) xflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(arg[iarg+3],"off") == 0) yflag = 0.0; - else if (strcmp(arg[iarg+3],"on") == 0) yflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(arg[iarg+4],"off") == 0) zflag = 0.0; - else if (strcmp(arg[iarg+4],"on") == 0) zflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); + double xflag, yflag, zflag; + if (strcmp(arg[iarg + 2], "off") == 0) + xflag = 0.0; + else if (strcmp(arg[iarg + 2], "on") == 0) + xflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); + if (strcmp(arg[iarg + 3], "off") == 0) + yflag = 0.0; + else if (strcmp(arg[iarg + 3], "on") == 0) + yflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); + if (strcmp(arg[iarg + 4], "off") == 0) + zflag = 0.0; + else if (strcmp(arg[iarg + 4], "on") == 0) + zflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); - if (domain->dimension == 2 && zflag == 1.0) - error->all(FLERR,"Fix rigid z force cannot be on for 2d simulation"); + if ((domain->dimension == 2) && (zflag == 1.0)) + error->all(FLERR, "Fix rigid z force cannot be on for 2d simulation"); int count = 0; for (int m = mlo; m <= mhi; m++) { - fflag[m-1][0] = xflag; - fflag[m-1][1] = yflag; - fflag[m-1][2] = zflag; + fflag[m - 1][0] = xflag; + fflag[m - 1][1] = yflag; + fflag[m - 1][2] = zflag; count++; } - if (count == 0) error->all(FLERR,"Illegal fix rigid command"); + if (count == 0) error->all(FLERR, "Illegal fix {} command", style); iarg += 5; - } else if (strcmp(arg[iarg],"torque") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "torque") == 0) { + if (iarg + 5 > narg) error->all(FLERR, "Illegal fix {} command", style); - int mlo,mhi; - utils::bounds(FLERR,arg[iarg+1],1,nbody,mlo,mhi,error); + int mlo, mhi; + utils::bounds(FLERR, arg[iarg + 1], 1, nbody, mlo, mhi, error); - double xflag,yflag,zflag; - if (strcmp(arg[iarg+2],"off") == 0) xflag = 0.0; - else if (strcmp(arg[iarg+2],"on") == 0) xflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(arg[iarg+3],"off") == 0) yflag = 0.0; - else if (strcmp(arg[iarg+3],"on") == 0) yflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(arg[iarg+4],"off") == 0) zflag = 0.0; - else if (strcmp(arg[iarg+4],"on") == 0) zflag = 1.0; - else error->all(FLERR,"Illegal fix rigid command"); + double xflag, yflag, zflag; + if (strcmp(arg[iarg + 2], "off") == 0) + xflag = 0.0; + else if (strcmp(arg[iarg + 2], "on") == 0) + xflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); + if (strcmp(arg[iarg + 3], "off") == 0) + yflag = 0.0; + else if (strcmp(arg[iarg + 3], "on") == 0) + yflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); + if (strcmp(arg[iarg + 4], "off") == 0) + zflag = 0.0; + else if (strcmp(arg[iarg + 4], "on") == 0) + zflag = 1.0; + else + error->all(FLERR, "Illegal fix {} command", style); if (domain->dimension == 2 && (xflag == 1.0 || yflag == 1.0)) - error->all(FLERR,"Fix rigid xy torque cannot be on for 2d simulation"); + error->all(FLERR, "Fix rigid xy torque cannot be on for 2d simulation"); int count = 0; for (int m = mlo; m <= mhi; m++) { - tflag[m-1][0] = xflag; - tflag[m-1][1] = yflag; - tflag[m-1][2] = zflag; + tflag[m - 1][0] = xflag; + tflag[m - 1][1] = yflag; + tflag[m - 1][2] = zflag; count++; } - if (count == 0) error->all(FLERR,"Illegal fix rigid command"); + if (count == 0) error->all(FLERR, "Illegal fix {} command", style); iarg += 5; - } else if (strcmp(arg[iarg],"langevin") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(style,"rigid") != 0 && strcmp(style,"rigid/nve") != 0 && - strcmp(style,"rigid/omp") != 0 && strcmp(style,"rigid/nve/omp") != 0) - error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "langevin") == 0) { + if (iarg + 5 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (strcmp(style, "rigid") != 0 && strcmp(style, "rigid/nve") != 0 && + strcmp(style, "rigid/omp") != 0 && strcmp(style, "rigid/nve/omp") != 0) + error->all(FLERR, "Illegal fix {} command", style); langflag = 1; - t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); - t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); - t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); - seed = utils::inumeric(FLERR,arg[iarg+4],false,lmp); - if (t_period <= 0.0) - error->all(FLERR,"Fix rigid langevin period must be > 0.0"); - if (seed <= 0) error->all(FLERR,"Illegal fix rigid command"); + t_start = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + t_stop = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + t_period = utils::numeric(FLERR, arg[iarg + 3], false, lmp); + seed = utils::inumeric(FLERR, arg[iarg + 4], false, lmp); + if (t_period <= 0.0) error->all(FLERR, "Fix rigid langevin period must be > 0.0"); + if (seed <= 0) error->all(FLERR, "Illegal fix {} command", style); iarg += 5; - } else if (strcmp(arg[iarg],"temp") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/n.t")) - error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "temp") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/n.t")) error->all(FLERR, "Illegal fix {} command", style); tstat_flag = 1; - t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); - t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); - t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); + t_start = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + t_stop = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + t_period = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"iso") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "iso") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/np.")) error->all(FLERR, "Illegal fix {} command", style); pcouple = XYZ; - p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[0] = p_period[1] = p_period[2] = - utils::numeric(FLERR,arg[iarg+3],false,lmp); + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); p_flag[0] = p_flag[1] = p_flag[2] = 1; - if (dimension == 2) { - p_start[2] = p_stop[2] = p_period[2] = 0.0; + if (domain->dimension == 2) { + p_start[2] = p_stop[2] = p_period[2] = 0.0; p_flag[2] = 0; } iarg += 4; - } else if (strcmp(arg[iarg],"aniso") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); - p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[0] = p_period[1] = p_period[2] = - utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "aniso") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/np.")) error->all(FLERR, "Illegal fix {} command", style); + p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); p_flag[0] = p_flag[1] = p_flag[2] = 1; - if (dimension == 2) { + if (domain->dimension == 2) { p_start[2] = p_stop[2] = p_period[2] = 0.0; - p_flag[2] = 0; + p_flag[2] = 0; } iarg += 4; - } else if (strcmp(arg[iarg],"x") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); - p_start[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[0] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "x") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/np.")) error->all(FLERR, "Illegal fix {} command", style); + p_start[0] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + p_stop[0] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + p_period[0] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); p_flag[0] = 1; iarg += 4; - } else if (strcmp(arg[iarg],"y") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); - p_start[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "y") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/np.")) error->all(FLERR, "Illegal fix {} command", style); + p_start[1] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + p_stop[1] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + p_period[1] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); p_flag[1] = 1; iarg += 4; - } else if (strcmp(arg[iarg],"z") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); - p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "z") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal fix {} command", style); + if (!utils::strmatch(style, "^rigid/np.")) error->all(FLERR, "Illegal fix {} command", style); + p_start[2] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + p_stop[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + p_period[2] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); p_flag[2] = 1; iarg += 4; - } else if (strcmp(arg[iarg],"couple") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; - else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; - else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; - else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; - else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NONE; - else error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "couple") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} couple", style), error); + if (strcmp(arg[iarg + 1], "xyz") == 0) + pcouple = XYZ; + else if (strcmp(arg[iarg + 1], "xy") == 0) + pcouple = XY; + else if (strcmp(arg[iarg + 1], "yz") == 0) + pcouple = YZ; + else if (strcmp(arg[iarg + 1], "xz") == 0) + pcouple = XZ; + else if (strcmp(arg[iarg + 1], "none") == 0) + pcouple = NONE; + else + error->all(FLERR, "Unknown fix {} couple option ", style, arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"dilate") == 0) { - if (iarg+2 > narg) - error->all(FLERR,"Illegal fix rigid npt/nph command"); - if (strcmp(arg[iarg+1],"all") == 0) allremap = 1; + } else if (strcmp(arg[iarg], "dilate") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} dilate", style), error); + if (strcmp(arg[iarg + 1], "all") == 0) + allremap = 1; else { allremap = 0; delete[] id_dilate; - id_dilate = utils::strdup(arg[iarg+1]); + id_dilate = utils::strdup(arg[iarg + 1]); int idilate = group->find(id_dilate); if (idilate == -1) - error->all(FLERR, - "Fix rigid npt/nph dilate group ID does not exist"); + error->all(FLERR, "Fix {} dilate group ID {} does not exist", style, id_dilate); } iarg += 2; - } else if (strcmp(arg[iarg],"tparam") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/n.t")) - error->all(FLERR,"Illegal fix rigid command"); - t_chain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - t_iter = utils::inumeric(FLERR,arg[iarg+2],false,lmp); - t_order = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "tparam") == 0) { + if (iarg + 4 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} tparam", style), error); + if (!utils::strmatch(style, "^rigid/n.t")) + error->all(FLERR, "Illegal fix {} command option tparam", style); + t_chain = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); + t_iter = utils::inumeric(FLERR, arg[iarg + 2], false, lmp); + t_order = utils::inumeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"pchain") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command"); - if (!utils::strmatch(style,"^rigid/np.")) - error->all(FLERR,"Illegal fix rigid command"); - p_chain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "pchain") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} pchain", style), error); + if (!utils::strmatch(style, "^rigid/np.")) + error->all(FLERR, "Illegal fix {} command option pchain", style); + p_chain = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"infile") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "infile") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} infile", style), error); delete[] inpfile; - inpfile = utils::strdup(arg[iarg+1]); + inpfile = utils::strdup(arg[iarg + 1]); restart_file = 1; reinitflag = 0; iarg += 2; - } else if (strcmp(arg[iarg],"reinit") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command"); - reinitflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "reinit") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} reinit", style), error); + reinitflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"gravity") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid command"); + } else if (strcmp(arg[iarg], "gravity") == 0) { + if (iarg + 2 > narg) + utils::missing_cmd_args(FLERR, fmt::format("fix {} gravity", style), error); delete[] id_gravity; - id_gravity = utils::strdup(arg[iarg+1]); + id_gravity = utils::strdup(arg[iarg + 1]); iarg += 2; - } else error->all(FLERR,"Illegal fix rigid command"); + } else + error->all(FLERR, "Illegal fix {} command", style); } + // clang-format off + // set pstat_flag pstat_flag = 0; for (i = 0; i < 3; i++) if (p_flag[i]) pstat_flag = 1; - if (pcouple == XYZ || (dimension == 2 && pcouple == XY)) pstyle = ISO; + if (pcouple == XYZ || (domain->dimension == 2 && pcouple == XY)) pstyle = ISO; else pstyle = ANISO; // initialize Marsaglia RNG with processor-unique seed - if (langflag) random = new RanMars(lmp,seed + me); + if (langflag) random = new RanMars(lmp, seed + comm->me); else random = nullptr; // initialize vector output quantities in case accessed before run @@ -600,7 +619,7 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : int nsum = 0; for (ibody = 0; ibody < nbody; ibody++) nsum += nrigid[ibody]; - if (me == 0) + if (comm->me == 0) utils::logmesg(lmp," {} rigid bodies with {} atoms\n",nbody,nsum); } @@ -686,14 +705,15 @@ void FixRigid::init() int count = 0; for (auto &ifix : modify->get_fix_list()) if (ifix->rigid_flag) count++; - if (count > 1 && me == 0) error->warning(FLERR,"More than one fix rigid"); + if (count > 1 && comm->me == 0) + error->warning(FLERR,"More than one fix rigid"); if (earlyflag) { bool rflag = false; for (auto &ifix : modify->get_fix_list()) { if (ifix->rigid_flag) rflag = true; if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag) - error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid", + error->warning(FLERR, "Fix {} with ID {} alters forces after fix rigid", ifix->style, ifix->id); } } @@ -856,6 +876,10 @@ void FixRigid::setup(int vflag) torque[ibody][2] = all[ibody][2]; } + // enforce 2d body forces and torques + + if (domain->dimension == 2) enforce2d(); + // zero langextra in case Langevin thermostat not used // no point to calling post_force() here since langextra // is only added to fcm/torque in final_integrate() @@ -936,6 +960,131 @@ void FixRigid::initial_integrate(int vflag) set_xv(); } +/* ---------------------------------------------------------------------- + remap xcm of each rigid body back into periodic simulation box + done during pre_neighbor so will be after call to pbc() + and after fix_deform::pre_exchange() may have flipped box + use domain->remap() in case xcm is far away from box + due to first-time definition of rigid body in setup_bodies_static() + or due to box flip + also adjust imagebody = rigid body image flags, due to xcm remap + also reset body xcmimage flags of all atoms in bodies + xcmimage flags are relative to xcm so that body can be unwrapped + if don't do this, would need xcm to move with true image flags + then a body could end up very far away from box + set_xv() will then compute huge displacements every step to + reset coords of all body atoms to be back inside the box, + ditto for triclinic box flip, which causes numeric problems +------------------------------------------------------------------------- */ + +void FixRigid::pre_neighbor() +{ + for (int ibody = 0; ibody < nbody; ibody++) + domain->remap(xcm[ibody],imagebody[ibody]); + image_shift(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigid::post_force(int /*vflag*/) +{ + if (langflag) apply_langevin_thermostat(); + if (earlyflag) compute_forces_and_torques(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigid::final_integrate() +{ + int ibody; + double dtfm; + + // compute forces and torques (after all post_force contributions) + // if 2d model, enforce2d() on body forces/torques + + if (!earlyflag) compute_forces_and_torques(); + if (domain->dimension == 2) enforce2d(); + + // update vcm and angmom + // fflag,tflag = 0 for some dimensions in 2d + + for (ibody = 0; ibody < nbody; ibody++) { + + // update vcm by 1/2 step + + dtfm = dtf / masstotal[ibody]; + vcm[ibody][0] += dtfm * fcm[ibody][0] * fflag[ibody][0]; + vcm[ibody][1] += dtfm * fcm[ibody][1] * fflag[ibody][1]; + vcm[ibody][2] += dtfm * fcm[ibody][2] * fflag[ibody][2]; + + // update angular momentum by 1/2 step + + angmom[ibody][0] += dtf * torque[ibody][0] * tflag[ibody][0]; + angmom[ibody][1] += dtf * torque[ibody][1] * tflag[ibody][1]; + angmom[ibody][2] += dtf * torque[ibody][2] * tflag[ibody][2]; + + MathExtra::angmom_to_omega(angmom[ibody],ex_space[ibody],ey_space[ibody], + ez_space[ibody],inertia[ibody],omega[ibody]); + } + + // set velocity/rotation of atoms in rigid bodies + // virial is already setup from initial_integrate + + set_v(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigid::initial_integrate_respa(int vflag, int ilevel, int /*iloop*/) +{ + dtv = step_respa[ilevel]; + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + dtq = 0.5 * step_respa[ilevel]; + + if (ilevel == 0) initial_integrate(vflag); + else final_integrate(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigid::final_integrate_respa(int ilevel, int /*iloop*/) +{ + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + final_integrate(); +} + +/* ---------------------------------------------------------------------- + reset body xcmimage flags of atoms in bodies + xcmimage flags are relative to xcm so that body can be unwrapped + xcmimage = true image flag - imagebody flag +------------------------------------------------------------------------- */ + +void FixRigid::image_shift() +{ + int ibody; + imageint tdim,bdim,xdim[3]; + + imageint *image = atom->image; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (body[i] < 0) continue; + ibody = body[i]; + + tdim = image[i] & IMGMASK; + bdim = imagebody[ibody] & IMGMASK; + xdim[0] = IMGMAX + tdim - bdim; + tdim = (image[i] >> IMGBITS) & IMGMASK; + bdim = (imagebody[ibody] >> IMGBITS) & IMGMASK; + xdim[1] = IMGMAX + tdim - bdim; + tdim = image[i] >> IMG2BITS; + bdim = imagebody[ibody] >> IMG2BITS; + xdim[2] = IMGMAX + tdim - bdim; + + xcmimage[i] = (xdim[2] << IMG2BITS) | (xdim[1] << IMGBITS) | xdim[0]; + } +} + /* ---------------------------------------------------------------------- apply Langevin thermostat to all 6 DOF of rigid bodies computed by proc 0, broadcast to other procs @@ -945,7 +1094,7 @@ void FixRigid::initial_integrate(int vflag) void FixRigid::apply_langevin_thermostat() { - if (me == 0) { + if (comm->me == 0) { double gamma1,gamma2; double wbody[3],tbody[3]; double delta = update->ntimestep - update->beginstep; @@ -991,31 +1140,6 @@ void FixRigid::apply_langevin_thermostat() MPI_Bcast(&langextra[0][0],6*nbody,MPI_DOUBLE,0,world); } -/* ---------------------------------------------------------------------- - called from FixEnforce2d post_force() for 2d problems - zero all body values that should be zero for 2d model -------------------------------------------------------------------------- */ - -void FixRigid::enforce2d() -{ - for (int ibody = 0; ibody < nbody; ibody++) { - xcm[ibody][2] = 0.0; - vcm[ibody][2] = 0.0; - fcm[ibody][2] = 0.0; - torque[ibody][0] = 0.0; - torque[ibody][1] = 0.0; - angmom[ibody][0] = 0.0; - angmom[ibody][1] = 0.0; - omega[ibody][0] = 0.0; - omega[ibody][1] = 0.0; - if (langflag && langextra) { - langextra[ibody][2] = 0.0; - langextra[ibody][3] = 0.0; - langextra[ibody][4] = 0.0; - } - } -} - /* ---------------------------------------------------------------------- */ void FixRigid::compute_forces_and_torques() @@ -1093,124 +1217,28 @@ void FixRigid::compute_forces_and_torques() } } -/* ---------------------------------------------------------------------- */ - -void FixRigid::post_force(int /*vflag*/) -{ - if (langflag) apply_langevin_thermostat(); - if (earlyflag) compute_forces_and_torques(); -} - -/* ---------------------------------------------------------------------- */ - -void FixRigid::final_integrate() -{ - int ibody; - double dtfm; - - if (!earlyflag) compute_forces_and_torques(); - - // update vcm and angmom - // fflag,tflag = 0 for some dimensions in 2d - - for (ibody = 0; ibody < nbody; ibody++) { - - // update vcm by 1/2 step - - dtfm = dtf / masstotal[ibody]; - vcm[ibody][0] += dtfm * fcm[ibody][0] * fflag[ibody][0]; - vcm[ibody][1] += dtfm * fcm[ibody][1] * fflag[ibody][1]; - vcm[ibody][2] += dtfm * fcm[ibody][2] * fflag[ibody][2]; - - // update angular momentum by 1/2 step - - angmom[ibody][0] += dtf * torque[ibody][0] * tflag[ibody][0]; - angmom[ibody][1] += dtf * torque[ibody][1] * tflag[ibody][1]; - angmom[ibody][2] += dtf * torque[ibody][2] * tflag[ibody][2]; - - MathExtra::angmom_to_omega(angmom[ibody],ex_space[ibody],ey_space[ibody], - ez_space[ibody],inertia[ibody],omega[ibody]); - } - - // set velocity/rotation of atoms in rigid bodies - // virial is already setup from initial_integrate - - set_v(); -} - -/* ---------------------------------------------------------------------- */ - -void FixRigid::initial_integrate_respa(int vflag, int ilevel, int /*iloop*/) -{ - dtv = step_respa[ilevel]; - dtf = 0.5 * step_respa[ilevel] * force->ftm2v; - dtq = 0.5 * step_respa[ilevel]; - - if (ilevel == 0) initial_integrate(vflag); - else final_integrate(); -} - -/* ---------------------------------------------------------------------- */ - -void FixRigid::final_integrate_respa(int ilevel, int /*iloop*/) -{ - dtf = 0.5 * step_respa[ilevel] * force->ftm2v; - final_integrate(); -} - /* ---------------------------------------------------------------------- - remap xcm of each rigid body back into periodic simulation box - done during pre_neighbor so will be after call to pbc() - and after fix_deform::pre_exchange() may have flipped box - use domain->remap() in case xcm is far away from box - due to first-time definition of rigid body in setup_bodies_static() - or due to box flip - also adjust imagebody = rigid body image flags, due to xcm remap - also reset body xcmimage flags of all atoms in bodies - xcmimage flags are relative to xcm so that body can be unwrapped - if don't do this, would need xcm to move with true image flags - then a body could end up very far away from box - set_xv() will then compute huge displacements every step to - reset coords of all body atoms to be back inside the box, - ditto for triclinic box flip, which causes numeric problems + called from FixEnforce2d post_force() for 2d problems + zero all body values that should be zero for 2d model ------------------------------------------------------------------------- */ -void FixRigid::pre_neighbor() +void FixRigid::enforce2d() { - for (int ibody = 0; ibody < nbody; ibody++) - domain->remap(xcm[ibody],imagebody[ibody]); - image_shift(); -} - -/* ---------------------------------------------------------------------- - reset body xcmimage flags of atoms in bodies - xcmimage flags are relative to xcm so that body can be unwrapped - xcmimage = true image flag - imagebody flag -------------------------------------------------------------------------- */ - -void FixRigid::image_shift() -{ - int ibody; - imageint tdim,bdim,xdim[3]; - - imageint *image = atom->image; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) { - if (body[i] < 0) continue; - ibody = body[i]; - - tdim = image[i] & IMGMASK; - bdim = imagebody[ibody] & IMGMASK; - xdim[0] = IMGMAX + tdim - bdim; - tdim = (image[i] >> IMGBITS) & IMGMASK; - bdim = (imagebody[ibody] >> IMGBITS) & IMGMASK; - xdim[1] = IMGMAX + tdim - bdim; - tdim = image[i] >> IMG2BITS; - bdim = imagebody[ibody] >> IMG2BITS; - xdim[2] = IMGMAX + tdim - bdim; - - xcmimage[i] = (xdim[2] << IMG2BITS) | (xdim[1] << IMGBITS) | xdim[0]; + for (int ibody = 0; ibody < nbody; ibody++) { + xcm[ibody][2] = 0.0; + vcm[ibody][2] = 0.0; + fcm[ibody][2] = 0.0; + torque[ibody][0] = 0.0; + torque[ibody][1] = 0.0; + angmom[ibody][0] = 0.0; + angmom[ibody][1] = 0.0; + omega[ibody][0] = 0.0; + omega[ibody][1] = 0.0; + if (langflag && langextra) { + langextra[ibody][2] = 0.0; + langextra[ibody][3] = 0.0; + langextra[ibody][4] = 0.0; + } } } @@ -1264,7 +1292,7 @@ int FixRigid::dof(int tgroup) if (nall[ibody]+mall[ibody] > 0 && nall[ibody]+mall[ibody] != nrigid[ibody]) flag = 1; } - if (flag && me == 0) + if (flag && (comm->me == 0)) error->warning(FLERR,"Computing temperature of portions of rigid bodies"); // remove appropriate DOFs for each rigid body wholly in temperature group @@ -1382,6 +1410,7 @@ void FixRigid::set_xv() // x = displacement from center-of-mass, based on body orientation // v = vcm + omega around center-of-mass + // enforce 2d x and v MathExtra::matvec(ex_space[ibody],ey_space[ibody], ez_space[ibody],displace[i],x[i]); @@ -1390,6 +1419,11 @@ void FixRigid::set_xv() v[i][1] = omega[ibody][2]*x[i][0] - omega[ibody][0]*x[i][2] + vcm[ibody][1]; v[i][2] = omega[ibody][0]*x[i][1] - omega[ibody][1]*x[i][0] + vcm[ibody][2]; + if (domain->dimension == 2) { + x[i][2] = 0.0; + v[i][2] = 0.0; + } + // add center of mass to displacement // map back into periodic box via xbox,ybox,zbox // for triclinic, add in box tilt factors as well @@ -1541,10 +1575,15 @@ void FixRigid::set_v() v2 = v[i][2]; } + // compute new v + // enforce 2d v + v[i][0] = omega[ibody][1]*delta[2] - omega[ibody][2]*delta[1] + vcm[ibody][0]; v[i][1] = omega[ibody][2]*delta[0] - omega[ibody][0]*delta[2] + vcm[ibody][1]; v[i][2] = omega[ibody][0]*delta[1] - omega[ibody][1]*delta[0] + vcm[ibody][2]; + if (domain->dimension == 2) v[i][2] = 0.0; + // virial = unwrapped coords dotted into body constraint force // body constraint force = implied force due to v change minus f external // assume f does not include forces internal to body @@ -1756,8 +1795,7 @@ void FixRigid::setup_bodies_static() if ((xbox && !periodicity[0]) || (ybox && !periodicity[1]) || (zbox && !periodicity[2])) - error->one(FLERR,"Fix rigid atom has non-zero image flag " - "in a non-periodic dimension"); + error->one(FLERR,"Fix rigid atom has non-zero image flag in a non-periodic dimension"); if (triclinic == 0) { xunwrap = x[i][0] + xbox*xprd; @@ -2265,7 +2303,7 @@ void FixRigid::readfile(int which, double *vec, double **array1, double **array2 char line[MAXLINE]; // open file and read and parse first non-empty, non-comment line containing the number of bodies - if (me == 0) { + if (comm->me == 0) { fp = fopen(inpfile,"r"); if (fp == nullptr) error->one(FLERR,"Cannot open fix rigid infile {}: {}", inpfile, utils::getsyserror()); @@ -2290,6 +2328,7 @@ void FixRigid::readfile(int which, double *vec, double **array1, double **array2 auto buffer = new char[CHUNK*MAXLINE]; int nread = 0; + int me = comm->me; while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); @@ -2364,7 +2403,7 @@ void FixRigid::readfile(int which, double *vec, double **array1, double **array2 nread += nchunk; } - if (me == 0) fclose(fp); + if (comm->me == 0) fclose(fp); delete[] buffer; } diff --git a/src/RIGID/fix_rigid.h b/src/RIGID/fix_rigid.h index 1e94adec09..361ddd2720 100644 --- a/src/RIGID/fix_rigid.h +++ b/src/RIGID/fix_rigid.h @@ -50,7 +50,6 @@ class FixRigid : public Fix { void pre_neighbor() override; int dof(int) override; void deform(int) override; - void enforce2d() override; void reset_dt() override; void zero_momentum() override; void zero_rotation() override; @@ -61,7 +60,6 @@ class FixRigid : public Fix { double compute_array(int, int) override; protected: - int me, nprocs; double dtv, dtf, dtq; double *step_respa; int triclinic; @@ -72,7 +70,6 @@ class FixRigid : public Fix { int setupflag; // 1 if body properties are setup, else 0 int earlyflag; // 1 if forces/torques computed at post_force() - int dimension; // # of dimensions int nbody; // # of rigid bodies int nlinear; // # of linear rigid bodies int *nrigid; // # of atoms in each rigid body @@ -146,7 +143,8 @@ class FixRigid : public Fix { void setup_bodies_static(); void setup_bodies_dynamic(); void apply_langevin_thermostat(); - void compute_forces_and_torques(); + virtual void compute_forces_and_torques(); + void enforce2d(); void readfile(int, double *, double **, double **, double **, imageint *, int *); }; diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index 9c9d582d94..f628b639ab 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -45,12 +45,11 @@ using namespace RigidConst; /* ---------------------------------------------------------------------- */ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) : - FixRigid(lmp, narg, arg), conjqm(nullptr), w(nullptr), - wdti1(nullptr), wdti2(nullptr), wdti4(nullptr), q_t(nullptr), q_r(nullptr), - eta_t(nullptr), eta_r(nullptr), eta_dot_t(nullptr), eta_dot_r(nullptr), - f_eta_t(nullptr), f_eta_r(nullptr), q_b(nullptr), eta_b(nullptr), - eta_dot_b(nullptr), f_eta_b(nullptr), rfix(nullptr), id_temp(nullptr), - id_press(nullptr), temperature(nullptr), pressure(nullptr) + FixRigid(lmp, narg, arg), conjqm(nullptr), w(nullptr), wdti1(nullptr), wdti2(nullptr), + wdti4(nullptr), q_t(nullptr), q_r(nullptr), eta_t(nullptr), eta_r(nullptr), eta_dot_t(nullptr), + eta_dot_r(nullptr), f_eta_t(nullptr), f_eta_r(nullptr), q_b(nullptr), eta_b(nullptr), + eta_dot_b(nullptr), f_eta_b(nullptr), id_temp(nullptr), id_press(nullptr), + temperature(nullptr), pressure(nullptr) { if (tstat_flag || pstat_flag) ecouple_flag = 1; @@ -59,57 +58,54 @@ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) : if ((p_flag[0] == 1 && p_period[0] <= 0.0) || (p_flag[1] == 1 && p_period[1] <= 0.0) || (p_flag[2] == 1 && p_period[2] <= 0.0)) - error->all(FLERR,"Fix rigid npt/nph period must be > 0.0"); + error->all(FLERR,"Fix {} period must be > 0.0", style); - if (dimension == 2 && p_flag[2]) - error->all(FLERR,"Invalid fix rigid npt/nph command for a 2d simulation"); - if (dimension == 2 && (pcouple == YZ || pcouple == XZ)) - error->all(FLERR,"Invalid fix rigid npt/nph command for a 2d simulation"); + if (domain->dimension == 2 && p_flag[2]) + error->all(FLERR,"Invalid fix {} command for a 2d simulation", style); + if (domain->dimension == 2 && (pcouple == YZ || pcouple == XZ)) + error->all(FLERR,"Invalid fix {} command for a 2d simulation", style); if (pcouple == XYZ && (p_flag[0] == 0 || p_flag[1] == 0)) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); - if (pcouple == XYZ && dimension == 3 && p_flag[2] == 0) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); + if (pcouple == XYZ && domain->dimension == 3 && p_flag[2] == 0) + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XY && (p_flag[0] == 0 || p_flag[1] == 0)) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == YZ && (p_flag[1] == 0 || p_flag[2] == 0)) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XZ && (p_flag[0] == 0 || p_flag[2] == 0)) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); // require periodicity in tensile dimension if (p_flag[0] && domain->xperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid npt/nph on a non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); if (p_flag[1] && domain->yperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid npt/nph on a non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); if (p_flag[2] && domain->zperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid npt/nph on a non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); - if (pcouple == XYZ && dimension == 3 && + if (pcouple == XYZ && domain->dimension == 3 && (p_start[0] != p_start[1] || p_start[0] != p_start[2] || p_stop[0] != p_stop[1] || p_stop[0] != p_stop[2] || p_period[0] != p_period[1] || p_period[0] != p_period[2])) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); - if (pcouple == XYZ && dimension == 2 && + error->all(FLERR,"Invalid fix {} command pressure settings", style); + if (pcouple == XYZ && domain->dimension == 2 && (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || p_period[0] != p_period[1])) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XY && (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || p_period[0] != p_period[1])) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == YZ && (p_start[1] != p_start[2] || p_stop[1] != p_stop[2] || p_period[1] != p_period[2])) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XZ && (p_start[0] != p_start[2] || p_stop[0] != p_stop[2] || p_period[0] != p_period[2])) - error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (p_flag[0]) box_change |= BOX_CHANGE_X; if (p_flag[1]) box_change |= BOX_CHANGE_Y; @@ -119,7 +115,7 @@ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) : (p_flag[0] && p_period[0] <= 0.0) || (p_flag[1] && p_period[1] <= 0.0) || (p_flag[2] && p_period[2] <= 0.0)) - error->all(FLERR,"Fix rigid nvt/npt/nph damping parameters must be > 0.0"); + error->all(FLERR,"Fix {} damping parameters must be > 0.0", style); // memory allocation and initialization @@ -147,11 +143,6 @@ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) : eta_b[i] = eta_dot_b[i] = 0.0; } - // rigid body pointers - - nrigidfix = 0; - rfix = nullptr; - vol0 = 0.0; t0 = 1.0; @@ -172,16 +163,14 @@ FixRigidNH::~FixRigidNH() deallocate_order(); } - delete[] rfix; - if (tcomputeflag) modify->delete_compute(id_temp); - delete [] id_temp; + delete[] id_temp; // delete pressure if fix created it if (pstat_flag) { if (pcomputeflag) modify->delete_compute(id_press); - delete [] id_press; + delete[] id_press; } } @@ -205,7 +194,7 @@ void FixRigidNH::init() if (allremap == 0) { int idilate = group->find(id_dilate); if (idilate == -1) - error->all(FLERR,"Fix rigid npt/nph dilate group ID does not exist"); + error->all(FLERR,"Fix {} dilate group ID does not exist", style); dilate_group_bit = group->bitmask[idilate]; } @@ -224,6 +213,7 @@ void FixRigidNH::init() if (force->kspace) kspace_flag = 1; else kspace_flag = 0; + int dimension = domain->dimension; nf_t = dimension * nbody; if (dimension == 3) { nf_r = dimension * nbody; @@ -254,28 +244,27 @@ void FixRigidNH::init() } } - int icompute; if (tcomputeflag) { - icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Temperature ID for fix rigid nvt/npt/nph does not exist"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Temperature ID {} for fix {} does not exist", id_temp, style); } if (pstat_flag) { if (domain->triclinic) - error->all(FLERR,"Fix rigid npt/nph does not yet allow triclinic box"); + error->all(FLERR,"Fix {} does not yet allow triclinic box", style); // ensure no conflict with fix deform - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0) { - int *dimflag = (dynamic_cast(modify->fix[i]))->dimflag; + for (auto &ifix : modify->get_fix_by_style("^deform")) { + auto deform = dynamic_cast(ifix); + if (deform) { + int *dimflag = deform->dimflag; if ((p_flag[0] && dimflag[0]) || (p_flag[1] && dimflag[1]) || (p_flag[2] && dimflag[2])) - error->all(FLERR,"Cannot use fix rigid npt/nph and fix deform on " - "same component of stress tensor"); + error->all(FLERR,"Cannot use fix {} and fix deform on same component of stress tensor", style); } + } // set frequency @@ -294,27 +283,15 @@ void FixRigidNH::init() // set pressure compute ptr - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix rigid npt/nph does not exist"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Pressure ID {} for fix {} does not exist", id_press, style); // detect if any rigid fixes exist so rigid bodies move on remap - // rfix[] = indices to each fix rigid // this will include self - delete[] rfix; - nrigidfix = 0; - rfix = nullptr; - - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigidfix++; - if (nrigidfix) { - rfix = new int[nrigidfix]; - nrigidfix = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) rfix[nrigidfix++] = i; - } + rfix.clear(); + for (auto &ifix : modify->get_fix_list()) + if (ifix->rigid_flag) rfix.push_back(ifix); } } @@ -391,6 +368,7 @@ void FixRigidNH::setup(int vflag) // initial forces on barostat thermostat variables + int dimension = domain->dimension; if (pstat_flag) { for (int i = 0; i < 3; i++) if (p_flag[i]) { @@ -821,6 +799,7 @@ void FixRigidNH::nhc_press_integrate() // update thermostat masses + int dimension = domain->dimension; double tb_mass = kt / (p_freq_max * p_freq_max); q_b[0] = dimension * dimension * tb_mass; for (i = 1; i < p_chain; i++) { @@ -927,7 +906,7 @@ double FixRigidNH::compute_scalar() energy += e*(0.5/pdim); double vol; - if (dimension == 2) vol = domain->xprd * domain->yprd; + if (domain->dimension == 2) vol = domain->xprd * domain->yprd; else vol = domain->xprd * domain->yprd * domain->zprd; double p0 = (p_target[0] + p_target[1] + p_target[2]) / 3.0; @@ -996,9 +975,7 @@ void FixRigidNH::remap() domain->x2lamda(x[i],x[i]); } - if (nrigidfix) - for (i = 0; i < nrigidfix; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -1025,9 +1002,7 @@ void FixRigidNH::remap() domain->lamda2x(x[i],x[i]); } - if (nrigidfix) - for (i = 0; i< nrigidfix; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- @@ -1071,7 +1046,7 @@ void FixRigidNH::nh_epsilon_dot() int i; double volume,scale,f_epsilon; - if (dimension == 2) volume = domain->xprd*domain->yprd; + if (domain->dimension == 2) volume = domain->xprd*domain->yprd; else volume = domain->xprd*domain->yprd*domain->zprd; // MTK terms @@ -1206,13 +1181,11 @@ int FixRigidNH::modify_param(int narg, char **arg) modify->delete_compute(id_temp); tcomputeflag = 0; } - delete [] id_temp; + delete[] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) - error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) error->all(FLERR,"Could not find fix_modify temperature ID {}", id_temp); if (temperature->tempflag == 0) error->all(FLERR, @@ -1223,10 +1196,9 @@ int FixRigidNH::modify_param(int narg, char **arg) // reset id_temp of pressure to new temperature ID if (pstat_flag) { - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix modify does not exist"); - modify->compute[icompute]->reset_extra_compute_fix(id_temp); + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Pressure ID {} for fix modify does not exist", id_press); + pressure->reset_extra_compute_fix(id_temp); } return 2; @@ -1238,15 +1210,13 @@ int FixRigidNH::modify_param(int narg, char **arg) modify->delete_compute(id_press); pcomputeflag = 0; } - delete [] id_press; + delete[] id_press; id_press = utils::strdup(arg[1]); - - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Could not find fix_modify pressure ID {}", id_press); if (pressure->pressflag == 0) - error->all(FLERR,"Fix_modify pressure ID does not compute pressure"); + error->all(FLERR,"Fix_modify pressure ID {} does not compute pressure", id_press); return 2; } @@ -1298,21 +1268,21 @@ void FixRigidNH::allocate_order() void FixRigidNH::deallocate_chain() { if (tstat_flag) { - delete [] q_t; - delete [] q_r; - delete [] eta_t; - delete [] eta_r; - delete [] eta_dot_t; - delete [] eta_dot_r; - delete [] f_eta_t; - delete [] f_eta_r; + delete[] q_t; + delete[] q_r; + delete[] eta_t; + delete[] eta_r; + delete[] eta_dot_t; + delete[] eta_dot_r; + delete[] f_eta_t; + delete[] f_eta_r; } if (pstat_flag) { - delete [] q_b; - delete [] eta_b; - delete [] eta_dot_b; - delete [] f_eta_b; + delete[] q_b; + delete[] eta_b; + delete[] eta_dot_b; + delete[] f_eta_b; } } @@ -1320,8 +1290,8 @@ void FixRigidNH::deallocate_chain() void FixRigidNH::deallocate_order() { - delete [] w; - delete [] wdti1; - delete [] wdti2; - delete [] wdti4; + delete[] w; + delete[] wdti1; + delete[] wdti2; + delete[] wdti4; } diff --git a/src/RIGID/fix_rigid_nh.h b/src/RIGID/fix_rigid_nh.h index 94600f97d1..7d357cfdf9 100644 --- a/src/RIGID/fix_rigid_nh.h +++ b/src/RIGID/fix_rigid_nh.h @@ -50,9 +50,8 @@ class FixRigidNH : public FixRigid { double *f_eta_b; // thermo forces double akin_t, akin_r; // translational/rotational kinetic energies - int kspace_flag; // 1 if KSpace invoked, 0 if not - int nrigidfix; // number of rigid fixes - int *rfix; // indices of rigid fixes + int kspace_flag; // 1 if KSpace invoked, 0 if not + std::vector rfix; // indices of rigid fixes double vol0; // reference volume double t0; // reference temperature @@ -70,7 +69,7 @@ class FixRigidNH : public FixRigid { int tcomputeflag, pcomputeflag; // 1 = compute was created by fix. 0 = external void couple(); - void remap(); + virtual void remap(); void nhc_temp_integrate(); void nhc_press_integrate(); diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index 8d4c015f96..952dc29032 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -46,83 +46,62 @@ using namespace RigidConst; /* ---------------------------------------------------------------------- */ FixRigidNHSmall::FixRigidNHSmall(LAMMPS *lmp, int narg, char **arg) : - FixRigidSmall(lmp, narg, arg), w(nullptr), wdti1(nullptr), - wdti2(nullptr), wdti4(nullptr), q_t(nullptr), q_r(nullptr), eta_t(nullptr), - eta_r(nullptr), eta_dot_t(nullptr), eta_dot_r(nullptr), f_eta_t(nullptr), - f_eta_r(nullptr), q_b(nullptr), eta_b(nullptr), eta_dot_b(nullptr), - f_eta_b(nullptr), rfix(nullptr), id_temp(nullptr), id_press(nullptr), - temperature(nullptr), pressure(nullptr) + FixRigidSmall(lmp, narg, arg), w(nullptr), wdti1(nullptr), wdti2(nullptr), wdti4(nullptr), + q_t(nullptr), q_r(nullptr), eta_t(nullptr), eta_r(nullptr), eta_dot_t(nullptr), + eta_dot_r(nullptr), f_eta_t(nullptr), f_eta_r(nullptr), q_b(nullptr), eta_b(nullptr), + eta_dot_b(nullptr), f_eta_b(nullptr), id_temp(nullptr), id_press(nullptr), + temperature(nullptr), pressure(nullptr) { if (tstat_flag || pstat_flag) ecouple_flag = 1; // error checks - if ((p_flag[0] == 1 && p_period[0] <= 0.0) || - (p_flag[1] == 1 && p_period[1] <= 0.0) || - (p_flag[2] == 1 && p_period[2] <= 0.0)) - error->all(FLERR,"Fix rigid/small npt/nph period must be > 0.0"); - - dimension = domain->dimension; - - if (dimension == 2 && p_flag[2]) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "for a 2d simulation"); - if (dimension == 2 && (pcouple == YZ || pcouple == XZ)) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "for a 2d simulation"); + if (domain->dimension == 2 && p_flag[2]) + error->all(FLERR,"Invalid fix {} command for a 2d simulation", style); + if (domain->dimension == 2 && (pcouple == YZ || pcouple == XZ)) + error->all(FLERR,"Invalid fix {} command for a 2d simulation", style); if (pcouple == XYZ && (p_flag[0] == 0 || p_flag[1] == 0)) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "pressure settings"); - if (pcouple == XYZ && dimension == 3 && p_flag[2] == 0) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); + if (pcouple == XYZ && domain->dimension == 3 && p_flag[2] == 0) + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XY && (p_flag[0] == 0 || p_flag[1] == 0)) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == YZ && (p_flag[1] == 0 || p_flag[2] == 0)) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); if (pcouple == XZ && (p_flag[0] == 0 || p_flag[2] == 0)) - error->all(FLERR,"Invalid fix rigid/small npt/nph command " - "pressure settings"); + error->all(FLERR,"Invalid fix {} command pressure settings", style); // require periodicity in tensile dimension if (p_flag[0] && domain->xperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid/small npt/nph on a " - "non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); if (p_flag[1] && domain->yperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid/small npt/nph on a " - "non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); if (p_flag[2] && domain->zperiodic == 0) - error->all(FLERR, - "Cannot use fix rigid/small npt/nph on a " - "non-periodic dimension"); + error->all(FLERR, "Cannot use fix {} on a non-periodic dimension", style); - if (pcouple == XYZ && dimension == 3 && + if (pcouple == XYZ && domain->dimension == 3 && (p_start[0] != p_start[1] || p_start[0] != p_start[2] || p_stop[0] != p_stop[1] || p_stop[0] != p_stop[2] || p_period[0] != p_period[1] || p_period[0] != p_period[2])) - error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); - if (pcouple == XYZ && dimension == 2 && + error->all(FLERR, "Invalid fix {} command pressure settings", style); + if (pcouple == XYZ && domain->dimension == 2 && (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || p_period[0] != p_period[1])) - error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); + error->all(FLERR, "Invalid fix {} command pressure settings", style); if (pcouple == XY && (p_start[0] != p_start[1] || p_stop[0] != p_stop[1] || p_period[0] != p_period[1])) - error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); + error->all(FLERR, "Invalid fix {} command pressure settings", style); if (pcouple == YZ && (p_start[1] != p_start[2] || p_stop[1] != p_stop[2] || p_period[1] != p_period[2])) - error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); + error->all(FLERR, "Invalid fix {} command pressure settings", style); if (pcouple == XZ && (p_start[0] != p_start[2] || p_stop[0] != p_stop[2] || p_period[0] != p_period[2])) - error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); + error->all(FLERR, "Invalid fix {} command pressure settings", style); if (p_flag[0]) box_change |= BOX_CHANGE_X; if (p_flag[1]) box_change |= BOX_CHANGE_Y; @@ -132,8 +111,7 @@ FixRigidNHSmall::FixRigidNHSmall(LAMMPS *lmp, int narg, char **arg) : (p_flag[0] && p_period[0] <= 0.0) || (p_flag[1] && p_period[1] <= 0.0) || (p_flag[2] && p_period[2] <= 0.0)) - error->all(FLERR,"Fix rigid/small nvt/npt/nph damping parameters " - "must be > 0.0"); + error->all(FLERR,"Fix {} damping parameters must be > 0.0", style); // memory allocation and initialization @@ -160,19 +138,11 @@ FixRigidNHSmall::FixRigidNHSmall(LAMMPS *lmp, int narg, char **arg) : eta_b[i] = eta_dot_b[i] = 0.0; } - // rigid body pointers - - nrigidfix = 0; - rfix = nullptr; - vol0 = 0.0; t0 = 1.0; tcomputeflag = 0; pcomputeflag = 0; - - id_temp = nullptr; - id_press = nullptr; } /* ---------------------------------------------------------------------- */ @@ -184,16 +154,14 @@ FixRigidNHSmall::~FixRigidNHSmall() deallocate_order(); } - delete[] rfix; - if (tcomputeflag) modify->delete_compute(id_temp); - delete [] id_temp; + delete[] id_temp; // delete pressure if fix created it if (pstat_flag) { if (pcomputeflag) modify->delete_compute(id_press); - delete [] id_press; + delete[] id_press; } } @@ -216,8 +184,7 @@ void FixRigidNHSmall::init() if (allremap == 0) { int idilate = group->find(id_dilate); - if (idilate == -1) - error->all(FLERR,"Fix rigid npt/nph dilate group ID does not exist"); + if (idilate == -1) error->all(FLERR,"Fix {} dilate group ID does not exist", style); dilate_group_bit = group->bitmask[idilate]; } @@ -254,26 +221,26 @@ void FixRigidNHSmall::init() int icompute; if (tcomputeflag) { - icompute = modify->find_compute(id_temp); - if (icompute < 0) - error->all(FLERR,"Temperature ID for fix rigid nvt/npt/nph does not exist"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) + error->all(FLERR,"Temperature ID {} for fix {} does not exist", id_temp, style); } if (pstat_flag) { if (domain->triclinic) - error->all(FLERR,"Fix rigid npt/nph does not yet allow triclinic box"); + error->all(FLERR,"Fix {} does not yet allow triclinic box", style); // ensure no conflict with fix deform - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0) { - int *dimflag = (dynamic_cast(modify->fix[i]))->dimflag; + for (auto &ifix : modify->get_fix_by_style("^deform")) { + auto deform = dynamic_cast(ifix); + if (deform) { + int *dimflag = deform->dimflag; if ((p_flag[0] && dimflag[0]) || (p_flag[1] && dimflag[1]) || (p_flag[2] && dimflag[2])) - error->all(FLERR,"Cannot use fix rigid npt/nph and fix deform on " - "same component of stress tensor"); + error->all(FLERR,"Cannot use fix {} and fix deform on same component of stress tensor", style); } + } // set frequency @@ -286,33 +253,21 @@ void FixRigidNHSmall::init() pdim = p_flag[0] + p_flag[1] + p_flag[2]; if (vol0 == 0.0) { - if (dimension == 2) vol0 = domain->xprd * domain->yprd; + if (domain->dimension == 2) vol0 = domain->xprd * domain->yprd; else vol0 = domain->xprd * domain->yprd * domain->zprd; } // set pressure compute ptr - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix rigid npt/nph does not exist"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Pressure ID {} for fix {} does not exist", id_press, style); // detect if any rigid fixes exist so rigid bodies move on remap - // rfix[] = indices to each fix rigid // this will include self - delete[] rfix; - nrigidfix = 0; - rfix = nullptr; - - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigidfix++; - if (nrigidfix) { - rfix = new int[nrigidfix]; - nrigidfix = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) rfix[nrigidfix++] = i; - } + rfix.clear(); + for (auto &ifix : modify->get_fix_list()) + if (ifix->rigid_flag) rfix.push_back(ifix); } } @@ -404,6 +359,7 @@ void FixRigidNHSmall::setup(int vflag) } // initial forces on barostat thermostat variables + int dimension = domain->dimension; if (pstat_flag) { for (int i = 0; i < 3; i++) @@ -855,6 +811,7 @@ void FixRigidNHSmall::nhc_press_integrate() // update thermostat masses + int dimension = domain->dimension; double tb_mass = kt / (p_freq_max * p_freq_max); q_b[0] = dimension * dimension * tb_mass; for (i = 1; i < p_chain; i++) { @@ -1011,7 +968,7 @@ double FixRigidNHSmall::compute_scalar() energy += e*(0.5/pdim); double vol; - if (dimension == 2) vol = domain->xprd * domain->yprd; + if (domain->dimension == 2) vol = domain->xprd * domain->yprd; else vol = domain->xprd * domain->yprd * domain->zprd; double p0 = (p_target[0] + p_target[1] + p_target[2]) / 3.0; @@ -1080,9 +1037,7 @@ void FixRigidNHSmall::remap() domain->x2lamda(x[i],x[i]); } - if (nrigidfix) - for (i = 0; i < nrigidfix; i++) - modify->fix[rfix[i]]->deform(0); + for (auto &ifix : rfix) ifix->deform(0); // reset global and local box to new size/shape @@ -1109,9 +1064,7 @@ void FixRigidNHSmall::remap() domain->lamda2x(x[i],x[i]); } - if (nrigidfix) - for (i = 0; i< nrigidfix; i++) - modify->fix[rfix[i]]->deform(1); + for (auto &ifix : rfix) ifix->deform(1); } /* ---------------------------------------------------------------------- @@ -1155,7 +1108,7 @@ void FixRigidNHSmall::nh_epsilon_dot() int i; double volume,scale,f_epsilon; - if (dimension == 2) volume = domain->xprd*domain->yprd; + if (domain->dimension == 2) volume = domain->xprd*domain->yprd; else volume = domain->xprd*domain->yprd*domain->zprd; // MTK terms @@ -1183,6 +1136,7 @@ void FixRigidNHSmall::nh_epsilon_dot() void FixRigidNHSmall::compute_dof() { // total translational and rotational degrees of freedom + int dimension = domain->dimension; nf_t = dimension * nlocal_body; if (dimension == 3) { @@ -1316,27 +1270,23 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) modify->delete_compute(id_temp); tcomputeflag = 0; } - delete [] id_temp; + delete[] id_temp; id_temp = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) - error->all(FLERR,"Could not find fix_modify temperature ID"); - temperature = modify->compute[icompute]; + temperature = modify->get_compute_by_id(id_temp); + if (!temperature) error->all(FLERR,"Could not find fix_modify temperature ID {}", id_temp); if (temperature->tempflag == 0) - error->all(FLERR, - "Fix_modify temperature ID does not compute temperature"); + error->all(FLERR, "Fix_modify temperature ID {} does not compute temperature", id_temp); if (temperature->igroup != 0 && comm->me == 0) error->warning(FLERR,"Temperature for fix modify is not for group all"); // reset id_temp of pressure to new temperature ID if (pstat_flag) { - icompute = modify->find_compute(id_press); - if (icompute < 0) - error->all(FLERR,"Pressure ID for fix modify does not exist"); - modify->compute[icompute]->reset_extra_compute_fix(id_temp); + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Pressure ID {} for fix modify does not exist", id_press); + pressure->reset_extra_compute_fix(id_temp); } return 2; @@ -1348,15 +1298,14 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) modify->delete_compute(id_press); pcomputeflag = 0; } - delete [] id_press; + delete[] id_press; id_press = utils::strdup(arg[1]); - int icompute = modify->find_compute(arg[1]); - if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); - pressure = modify->compute[icompute]; + pressure = modify->get_compute_by_id(id_press); + if (!pressure) error->all(FLERR,"Could not find fix_modify pressure ID {}", id_press); if (pressure->pressflag == 0) - error->all(FLERR,"Fix_modify pressure ID does not compute pressure"); + error->all(FLERR,"Fix_modify pressure ID {} does not compute pressure", id_press); return 2; } @@ -1408,21 +1357,21 @@ void FixRigidNHSmall::allocate_order() void FixRigidNHSmall::deallocate_chain() { if (tstat_flag) { - delete [] q_t; - delete [] q_r; - delete [] eta_t; - delete [] eta_r; - delete [] eta_dot_t; - delete [] eta_dot_r; - delete [] f_eta_t; - delete [] f_eta_r; + delete[] q_t; + delete[] q_r; + delete[] eta_t; + delete[] eta_r; + delete[] eta_dot_t; + delete[] eta_dot_r; + delete[] f_eta_t; + delete[] f_eta_r; } if (pstat_flag) { - delete [] q_b; - delete [] eta_b; - delete [] eta_dot_b; - delete [] f_eta_b; + delete[] q_b; + delete[] eta_b; + delete[] eta_dot_b; + delete[] f_eta_b; } } @@ -1430,8 +1379,8 @@ void FixRigidNHSmall::deallocate_chain() void FixRigidNHSmall::deallocate_order() { - delete [] w; - delete [] wdti1; - delete [] wdti2; - delete [] wdti4; + delete[] w; + delete[] wdti1; + delete[] wdti2; + delete[] wdti4; } diff --git a/src/RIGID/fix_rigid_nh_small.h b/src/RIGID/fix_rigid_nh_small.h index 3d637b6aea..735a15205c 100644 --- a/src/RIGID/fix_rigid_nh_small.h +++ b/src/RIGID/fix_rigid_nh_small.h @@ -36,7 +36,6 @@ class FixRigidNHSmall : public FixRigidSmall { protected: double boltz, nktv2p, mvv2e; // boltzman constant, conversion factors - int dimension; // # of dimensions int nf_t, nf_r; // trans/rot degrees of freedom double *w, *wdti1, *wdti2, *wdti4; // Yoshida-Suzuki coefficients double *q_t, *q_r; // trans/rot thermostat masses @@ -50,9 +49,8 @@ class FixRigidNHSmall : public FixRigidSmall { double *f_eta_b; // thermo forces double akin_t, akin_r; // translational/rotational kinetic energies - int kspace_flag; // 1 if KSpace invoked, 0 if not - int nrigidfix; // number of rigid fixes - int *rfix; // indices of rigid fixes + int kspace_flag; // 1 if KSpace invoked, 0 if not + std::vector rfix; // indices of rigid fixes double vol0; // reference volume double t0; // reference temperature diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index bf0a847d48..bd49834f15 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -72,13 +72,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : thermo_virial = 1; create_attribute = 1; dof_flag = 1; - enforce2d_flag = 1; stores_ids = 1; centroidstressflag = CENTROID_AVAIL; - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); - // perform initial allocation of atom-based arrays // register with Atom class @@ -100,10 +96,10 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : tagint *bodyID = nullptr; int nlocal = atom->nlocal; - if (narg < 4) error->all(FLERR,"Illegal fix rigid/small command"); + if (narg < 4) utils::missing_cmd_args(FLERR, fmt::format("fix {}", style), error); if (strcmp(arg[3],"molecule") == 0) { if (atom->molecule_flag == 0) - error->all(FLERR,"Fix rigid/small requires atom attribute molecule"); + error->all(FLERR,"Fix {} requires atom attribute molecule", style); bodyID = atom->molecule; } else if (strcmp(arg[3],"custom") == 0) { @@ -117,9 +113,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : int is_double,cols; int custom_index = atom->find_custom(arg[4]+2,is_double,cols); if (custom_index == -1) - error->all(FLERR,"Fix rigid/small custom requires previously defined property/atom"); + error->all(FLERR,"Fix {} custom requires previously defined property/atom", style); else if (is_double || cols) - error->all(FLERR,"Fix rigid/small custom requires integer-valued property/atom vector"); + error->all(FLERR,"Fix {} custom requires integer-valued property/atom vector", style); int minval = INT_MAX; int *value = atom->ivector[custom_index]; for (i = 0; i < nlocal; i++) @@ -135,10 +131,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : } else if (utils::strmatch(arg[4],"^v_")) { int ivariable = input->variable->find(arg[4]+2); if (ivariable < 0) - error->all(FLERR,"Variable {} for fix rigid/small custom does not exist", arg[4]+2); + error->all(FLERR,"Variable {} for fix {} custom does not exist", arg[4]+2, style); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Fix rigid/small custom variable {} is not atom-style variable", - arg[4]+2); + error->all(FLERR,"Fix {} custom variable {} is not atom-style variable", style, arg[4]+2); auto value = new double[nlocal]; input->variable->compute_atom(ivariable,0,value,1,0); int minval = INT_MAX; @@ -152,11 +147,11 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : bodyID[i] = (tagint)((tagint)value[i] - minval + 1); else bodyID[0] = 0; delete[] value; - } else error->all(FLERR,"Unsupported fix rigid custom property"); - } else error->all(FLERR,"Illegal fix rigid/small command"); + } else error->all(FLERR,"Unsupported fix {} custom property", style, arg[4]); + } else error->all(FLERR,"Unknown fix {} keyword {}", style, arg[3]); if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Fix rigid/small requires an atom map, see atom_modify"); + error->all(FLERR,"Fix {} requires an atom map, see atom_modify", style); // maxmol = largest bodyID # @@ -201,23 +196,21 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"langevin") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal fix rigid/small command"); - if ((strcmp(style,"rigid/small") != 0) && - (strcmp(style,"rigid/nve/small") != 0) && - (strcmp(style,"rigid/nph/small") != 0)) - error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+5 > narg) error->all(FLERR,"Illegal fix {} command", style); + if (utils::strmatch(style, "^rigid/n.t/small")) + error->all(FLERR,"Illegal fix {} command", style); langflag = 1; t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); t_period = utils::numeric(FLERR,arg[iarg+3],false,lmp); seed = utils::inumeric(FLERR,arg[iarg+4],false,lmp); if (t_period <= 0.0) - error->all(FLERR,"Fix rigid/small langevin period must be > 0.0"); - if (seed <= 0) error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Fix {} langevin period must be > 0.0", style); + if (seed <= 0) error->all(FLERR,"Illegal fix {} command", style); iarg += 5; } else if (strcmp(arg[iarg],"infile") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} infile command", style); delete[] inpfile; inpfile = utils::strdup(arg[iarg+1]); restart_file = 1; @@ -225,23 +218,24 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 2; } else if (strcmp(arg[iarg],"reinit") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} reinit command", style); reinitflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"mol") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} mol command", style); int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) error->all(FLERR,"Molecule template ID for fix rigid/small does not exist"); + if (imol == -1) + error->all(FLERR,"Molecule template ID {} for fix {} does not exist", arg[iarg+1], style); onemols = &atom->molecules[imol]; nmol = onemols[0]->nset; restart_file = 1; iarg += 2; } else if (strcmp(arg[iarg],"temp") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR, "Illegal fix {} temp command", style); if (!utils::strmatch(style,"^rigid/n.t/small")) - error->all(FLERR,"Illegal fix rigid command"); + error->all(FLERR, "Illegal fix {} temp", style); tstat_flag = 1; t_start = utils::numeric(FLERR,arg[iarg+1],false,lmp); t_stop = utils::numeric(FLERR,arg[iarg+2],false,lmp); @@ -249,15 +243,16 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"iso") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR, "Illegal fix {} iso command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} iso command", style); pcouple = XYZ; p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); p_period[0] = p_period[1] = p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); p_flag[0] = p_flag[1] = p_flag[2] = 1; + if (domain->dimension == 2) { p_start[2] = p_stop[2] = p_period[2] = 0.0; p_flag[2] = 0; @@ -265,9 +260,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"aniso") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR,"Illegal fix {} ansio command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} aniso command", style); p_start[0] = p_start[1] = p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); p_stop[0] = p_stop[1] = p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); p_period[0] = p_period[1] = p_period[2] = @@ -280,9 +275,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"x") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR,"Illegal fix {} x command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} x command", style); p_start[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); p_stop[0] = utils::numeric(FLERR,arg[iarg+2],false,lmp); p_period[0] = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -290,9 +285,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"y") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR,"Illegal fix {} y command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} y command", style); p_start[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); p_stop[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); p_period[1] = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -300,9 +295,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"z") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR,"Illegal fix {} z command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} z command", style); p_start[2] = utils::numeric(FLERR,arg[iarg+1],false,lmp); p_stop[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); p_period[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -310,18 +305,18 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : iarg += 4; } else if (strcmp(arg[iarg],"couple") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} couple command", style); if (strcmp(arg[iarg+1],"xyz") == 0) pcouple = XYZ; else if (strcmp(arg[iarg+1],"xy") == 0) pcouple = XY; else if (strcmp(arg[iarg+1],"yz") == 0) pcouple = YZ; else if (strcmp(arg[iarg+1],"xz") == 0) pcouple = XZ; else if (strcmp(arg[iarg+1],"none") == 0) pcouple = NONE; - else error->all(FLERR,"Illegal fix rigid/small command"); + else error->all(FLERR,"Illegal fix {} couple command", style); iarg += 2; } else if (strcmp(arg[iarg],"dilate") == 0) { if (iarg+2 > narg) - error->all(FLERR,"Illegal fix rigid/small nvt/npt/nph command"); + error->all(FLERR,"Illegal fix {} dilate command", style); if (strcmp(arg[iarg+1],"all") == 0) allremap = 1; else { allremap = 0; @@ -329,34 +324,33 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : id_dilate = utils::strdup(arg[iarg+1]); int idilate = group->find(id_dilate); if (idilate == -1) - error->all(FLERR,"Fix rigid/small nvt/npt/nph dilate group ID " - "does not exist"); + error->all(FLERR,"Fix {} dilate group ID {} does not exist", style, id_dilate); } iarg += 2; } else if (strcmp(arg[iarg],"tparam") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+4 > narg) error->all(FLERR,"Illegal fix {} tparam command", style); if (!utils::strmatch(style,"^rigid/n.t/small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} tparam command", style); t_chain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); t_iter = utils::inumeric(FLERR,arg[iarg+2],false,lmp); t_order = utils::inumeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg],"pchain") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} pchain command", style); if (!utils::strmatch(style,"^rigid/np./small")) - error->all(FLERR,"Illegal fix rigid/small command"); + error->all(FLERR,"Illegal fix {} pchain command", style); p_chain = utils::inumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"gravity") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix {} gravity command", style); delete[] id_gravity; id_gravity = utils::strdup(arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal fix rigid/small command"); + } else error->all(FLERR,"Unknown fix {} keyword {}", style, arg[iarg]); } // error check and further setup for Molecule template @@ -364,9 +358,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : if (onemols) { for (i = 0; i < nmol; i++) { if (onemols[i]->xflag == 0) - error->all(FLERR,"Fix rigid/small molecule must have coordinates"); + error->all(FLERR,"Fix {} molecule must have coordinates", style); if (onemols[i]->typeflag == 0) - error->all(FLERR,"Fix rigid/small molecule must have atom types"); + error->all(FLERR,"Fix {} molecule must have atom types", style); // fix rigid/small uses center, masstotal, COM, inertia of molecule @@ -452,7 +446,7 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : bigint atomall; MPI_Allreduce(&atomone,&atomall,1,MPI_LMP_BIGINT,MPI_SUM,world); - if (me == 0) { + if (comm->me == 0) { utils::logmesg(lmp," {} rigid bodies with {} atoms\n" " {:.8} = max distance from body owner to body atom\n", nbody,atomall,maxextent); @@ -531,15 +525,16 @@ void FixRigidSmall::init() int count = 0; for (auto &ifix : modify->get_fix_list()) if (ifix->rigid_flag) count++; - if (count > 1 && me == 0) error->warning(FLERR,"More than one fix rigid"); + if (count > 1 && comm->me == 0) + error->warning(FLERR, "More than one fix rigid command"); if (earlyflag) { bool rflag = false; for (auto &ifix : modify->get_fix_list()) { if (ifix->rigid_flag) rflag = true; if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag) - error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid/small", - ifix->style, ifix->id); + error->warning(FLERR,"Fix {} with ID {} alters forces after fix {}", + ifix->style, ifix->id, style); } } @@ -568,9 +563,9 @@ void FixRigidSmall::init() if (id_gravity) { auto ifix = modify->get_fix_by_id(id_gravity); - if (!ifix) error->all(FLERR,"Fix rigid/small cannot find fix gravity ID {}", id_gravity); + if (!ifix) error->all(FLERR,"Fix {} cannot find fix gravity ID {}", style, id_gravity); if (!utils::strmatch(ifix->style,"^gravity")) - error->all(FLERR,"Fix rigid/small gravity fix ID {} is not a gravity fix style", id_gravity); + error->all(FLERR,"Fix {} gravity fix ID {} is not a gravity fix style", style, id_gravity); int tmp; gvec = (double *) ifix->extract("gvec", tmp); } @@ -629,7 +624,7 @@ void FixRigidSmall::setup(int vflag) double cutghost = MAX(neighbor->cutneighmax,comm->cutghostuser); if (maxextent > cutghost) - error->all(FLERR,"Rigid body extent > ghost cutoff - use comm_modify cutoff"); + error->all(FLERR,"Rigid body extent {} > ghost atom cutoff - use comm_modify cutoff", maxextent); //check(1); @@ -690,6 +685,10 @@ void FixRigidSmall::setup(int vflag) } } + // enforce 2d body forces and torques + + if (domain->dimension == 2) enforce2d(); + // reverse communicate fcm, torque of all bodies commflag = FORCE_TORQUE; @@ -780,6 +779,151 @@ void FixRigidSmall::initial_integrate(int vflag) set_xv(); } +/* ---------------------------------------------------------------------- + remap xcm of each rigid body back into periodic simulation box + done during pre_neighbor so will be after call to pbc() + and after fix_deform::pre_exchange() may have flipped box + use domain->remap() in case xcm is far away from box + due to first-time definition of rigid body in setup_bodies_static() + or due to box flip + also adjust imagebody = rigid body image flags, due to xcm remap + then communicate bodies so other procs will know of changes to body xcm + then adjust xcmimage flags of all atoms in bodies via image_shift() + for two effects + (1) change in true image flags due to pbc() call during exchange + (2) change in imagebody due to xcm remap + xcmimage flags are always -1,0,-1 so that body can be unwrapped + around in-box xcm and stay close to simulation box + if just inferred unwrapped from atom image flags, + then a body could end up very far away + when unwrapped by true image flags + then set_xv() will compute huge displacements every step to reset coords of + all the body atoms to be back inside the box, ditto for triclinic box flip + note: so just want to avoid that numeric problem? +------------------------------------------------------------------------- */ + +void FixRigidSmall::pre_neighbor() +{ + for (int ibody = 0; ibody < nlocal_body; ibody++) { + Body *b = &body[ibody]; + domain->remap(b->xcm,b->image); + } + + nghost_body = 0; + commflag = FULL_BODY; + comm->forward_comm(this); + reset_atom2body(); + //check(4); + + image_shift(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigidSmall::post_force(int /*vflag*/) +{ + if (langflag) apply_langevin_thermostat(); + if (earlyflag) compute_forces_and_torques(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigidSmall::final_integrate() +{ + double dtfm; + + //check(3); + + // compute forces and torques (after all post_force contributions) + // if 2d model, enforce2d() on body forces/torques + + if (!earlyflag) compute_forces_and_torques(); + if (domain->dimension == 2) enforce2d(); + + // update vcm and angmom, recompute omega + + for (int ibody = 0; ibody < nlocal_body; ibody++) { + Body *b = &body[ibody]; + + // update vcm by 1/2 step + + dtfm = dtf / b->mass; + b->vcm[0] += dtfm * b->fcm[0]; + b->vcm[1] += dtfm * b->fcm[1]; + b->vcm[2] += dtfm * b->fcm[2]; + + // update angular momentum by 1/2 step + + b->angmom[0] += dtf * b->torque[0]; + b->angmom[1] += dtf * b->torque[1]; + b->angmom[2] += dtf * b->torque[2]; + + MathExtra::angmom_to_omega(b->angmom,b->ex_space,b->ey_space, + b->ez_space,b->inertia,b->omega); + } + + // forward communicate updated info of all bodies + + commflag = FINAL; + comm->forward_comm(this,10); + + // set velocity/rotation of atoms in rigid bodies + // virial is already setup from initial_integrate + + set_v(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigidSmall::initial_integrate_respa(int vflag, int ilevel, int /*iloop*/) +{ + dtv = step_respa[ilevel]; + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + dtq = 0.5 * step_respa[ilevel]; + + if (ilevel == 0) initial_integrate(vflag); + else final_integrate(); +} + +/* ---------------------------------------------------------------------- */ + +void FixRigidSmall::final_integrate_respa(int ilevel, int /*iloop*/) +{ + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + final_integrate(); +} + +/* ---------------------------------------------------------------------- + reset body xcmimage flags of atoms in bodies + xcmimage flags are relative to xcm so that body can be unwrapped + xcmimage = true image flag - imagebody flag +------------------------------------------------------------------------- */ + +void FixRigidSmall::image_shift() +{ + imageint tdim,bdim,xdim[3]; + + imageint *image = atom->image; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (atom2body[i] < 0) continue; + Body *b = &body[atom2body[i]]; + + tdim = image[i] & IMGMASK; + bdim = b->image & IMGMASK; + xdim[0] = IMGMAX + tdim - bdim; + tdim = (image[i] >> IMGBITS) & IMGMASK; + bdim = (b->image >> IMGBITS) & IMGMASK; + xdim[1] = IMGMAX + tdim - bdim; + tdim = image[i] >> IMG2BITS; + bdim = b->image >> IMG2BITS; + xdim[2] = IMGMAX + tdim - bdim; + + xcmimage[i] = (xdim[2] << IMG2BITS) | (xdim[1] << IMGBITS) | xdim[0]; + } +} + /* ---------------------------------------------------------------------- apply Langevin thermostat to all 6 DOF of rigid bodies I own unlike fix langevin, this stores extra force in extra arrays, @@ -845,52 +989,9 @@ void FixRigidSmall::apply_langevin_thermostat() // convert langevin torques from body frame back to space frame MathExtra::matvec(ex_space,ey_space,ez_space,tbody,&langextra[ibody][3]); - - // enforce 2d motion - - if (domain->dimension == 2) - langextra[ibody][2] = langextra[ibody][3] = langextra[ibody][4] = 0.0; } } -/* ---------------------------------------------------------------------- - called from FixEnforce post_force() for 2d problems - zero all body values that should be zero for 2d model -------------------------------------------------------------------------- */ - -void FixRigidSmall::enforce2d() -{ - Body *b; - - for (int ibody = 0; ibody < nlocal_body; ibody++) { - b = &body[ibody]; - b->xcm[2] = 0.0; - b->vcm[2] = 0.0; - b->fcm[2] = 0.0; - b->xgc[2] = 0.0; - b->torque[0] = 0.0; - b->torque[1] = 0.0; - b->angmom[0] = 0.0; - b->angmom[1] = 0.0; - b->omega[0] = 0.0; - b->omega[1] = 0.0; - if (langflag && langextra) { - langextra[ibody][2] = 0.0; - langextra[ibody][3] = 0.0; - langextra[ibody][4] = 0.0; - } - } -} - -/* ---------------------------------------------------------------------- */ - -void FixRigidSmall::post_force(int /*vflag*/) -{ - if (langflag) apply_langevin_thermostat(); - if (earlyflag) compute_forces_and_torques(); -} - - /* ---------------------------------------------------------------------- */ void FixRigidSmall::compute_forces_and_torques() @@ -988,136 +1089,32 @@ void FixRigidSmall::compute_forces_and_torques() } } -/* ---------------------------------------------------------------------- */ - -void FixRigidSmall::final_integrate() -{ - double dtfm; - - //check(3); - - if (!earlyflag) compute_forces_and_torques(); - - // update vcm and angmom, recompute omega - - for (int ibody = 0; ibody < nlocal_body; ibody++) { - Body *b = &body[ibody]; - - // update vcm by 1/2 step - - dtfm = dtf / b->mass; - b->vcm[0] += dtfm * b->fcm[0]; - b->vcm[1] += dtfm * b->fcm[1]; - b->vcm[2] += dtfm * b->fcm[2]; - - // update angular momentum by 1/2 step - - b->angmom[0] += dtf * b->torque[0]; - b->angmom[1] += dtf * b->torque[1]; - b->angmom[2] += dtf * b->torque[2]; - - MathExtra::angmom_to_omega(b->angmom,b->ex_space,b->ey_space, - b->ez_space,b->inertia,b->omega); - } - - // forward communicate updated info of all bodies - - commflag = FINAL; - comm->forward_comm(this,10); - - // set velocity/rotation of atoms in rigid bodies - // virial is already setup from initial_integrate - - set_v(); -} - -/* ---------------------------------------------------------------------- */ - -void FixRigidSmall::initial_integrate_respa(int vflag, int ilevel, int /*iloop*/) -{ - dtv = step_respa[ilevel]; - dtf = 0.5 * step_respa[ilevel] * force->ftm2v; - dtq = 0.5 * step_respa[ilevel]; - - if (ilevel == 0) initial_integrate(vflag); - else final_integrate(); -} - -/* ---------------------------------------------------------------------- */ - -void FixRigidSmall::final_integrate_respa(int ilevel, int /*iloop*/) -{ - dtf = 0.5 * step_respa[ilevel] * force->ftm2v; - final_integrate(); -} - /* ---------------------------------------------------------------------- - remap xcm of each rigid body back into periodic simulation box - done during pre_neighbor so will be after call to pbc() - and after fix_deform::pre_exchange() may have flipped box - use domain->remap() in case xcm is far away from box - due to first-time definition of rigid body in setup_bodies_static() - or due to box flip - also adjust imagebody = rigid body image flags, due to xcm remap - then communicate bodies so other procs will know of changes to body xcm - then adjust xcmimage flags of all atoms in bodies via image_shift() - for two effects - (1) change in true image flags due to pbc() call during exchange - (2) change in imagebody due to xcm remap - xcmimage flags are always -1,0,-1 so that body can be unwrapped - around in-box xcm and stay close to simulation box - if just inferred unwrapped from atom image flags, - then a body could end up very far away - when unwrapped by true image flags - then set_xv() will compute huge displacements every step to reset coords of - all the body atoms to be back inside the box, ditto for triclinic box flip - note: so just want to avoid that numeric problem? + called from FixEnforce post_force() for 2d problems + zero all body values that should be zero for 2d model ------------------------------------------------------------------------- */ -void FixRigidSmall::pre_neighbor() +void FixRigidSmall::enforce2d() { + Body *b; + for (int ibody = 0; ibody < nlocal_body; ibody++) { - Body *b = &body[ibody]; - domain->remap(b->xcm,b->image); - } - - nghost_body = 0; - commflag = FULL_BODY; - comm->forward_comm(this); - reset_atom2body(); - //check(4); - - image_shift(); -} - -/* ---------------------------------------------------------------------- - reset body xcmimage flags of atoms in bodies - xcmimage flags are relative to xcm so that body can be unwrapped - xcmimage = true image flag - imagebody flag -------------------------------------------------------------------------- */ - -void FixRigidSmall::image_shift() -{ - imageint tdim,bdim,xdim[3]; - - imageint *image = atom->image; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) { - if (atom2body[i] < 0) continue; - Body *b = &body[atom2body[i]]; - - tdim = image[i] & IMGMASK; - bdim = b->image & IMGMASK; - xdim[0] = IMGMAX + tdim - bdim; - tdim = (image[i] >> IMGBITS) & IMGMASK; - bdim = (b->image >> IMGBITS) & IMGMASK; - xdim[1] = IMGMAX + tdim - bdim; - tdim = image[i] >> IMG2BITS; - bdim = b->image >> IMG2BITS; - xdim[2] = IMGMAX + tdim - bdim; - - xcmimage[i] = (xdim[2] << IMG2BITS) | (xdim[1] << IMGBITS) | xdim[0]; + b = &body[ibody]; + b->xcm[2] = 0.0; + b->vcm[2] = 0.0; + b->fcm[2] = 0.0; + b->xgc[2] = 0.0; + b->torque[0] = 0.0; + b->torque[1] = 0.0; + b->angmom[0] = 0.0; + b->angmom[1] = 0.0; + b->omega[0] = 0.0; + b->omega[1] = 0.0; + if (langflag && langextra) { + langextra[ibody][2] = 0.0; + langextra[ibody][3] = 0.0; + langextra[ibody][4] = 0.0; + } } } @@ -1182,7 +1179,7 @@ int FixRigidSmall::dof(int tgroup) } int flagall; MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_MAX,world); - if (flagall && me == 0) + if (flagall && comm->me == 0) error->warning(FLERR,"Computing temperature of portions of rigid bodies"); // remove appropriate DOFs for each rigid body wholly in temperature group @@ -1297,6 +1294,7 @@ void FixRigidSmall::set_xv() // x = displacement from center-of-mass, based on body orientation // v = vcm + omega around center-of-mass + // enforce 2d x and v MathExtra::matvec(b->ex_space,b->ey_space,b->ez_space,displace[i],x[i]); @@ -1304,6 +1302,11 @@ void FixRigidSmall::set_xv() v[i][1] = b->omega[2]*x[i][0] - b->omega[0]*x[i][2] + b->vcm[1]; v[i][2] = b->omega[0]*x[i][1] - b->omega[1]*x[i][0] + b->vcm[2]; + if (domain->dimension == 2) { + x[i][2] = 0.0; + v[i][2] = 0.0; + } + // add center of mass to displacement // map back into periodic box via xbox,ybox,zbox // for triclinic, add in box tilt factors as well @@ -1345,6 +1348,7 @@ void FixRigidSmall::set_xv() } // update the position of geometric center + for (int ibody = 0; ibody < nlocal_body + nghost_body; ibody++) { Body *b = &body[ibody]; MathExtra::matvec(b->ex_space,b->ey_space,b->ez_space, @@ -1462,10 +1466,15 @@ void FixRigidSmall::set_v() v2 = v[i][2]; } + // compute new v + // enforce 2d v + v[i][0] = b->omega[1]*delta[2] - b->omega[2]*delta[1] + b->vcm[0]; v[i][1] = b->omega[2]*delta[0] - b->omega[0]*delta[2] + b->vcm[1]; v[i][2] = b->omega[0]*delta[1] - b->omega[1]*delta[0] + b->vcm[2]; + if (domain->dimension == 2) v[i][2] = 0.0; + // virial = unwrapped coords dotted into body constraint force // body constraint force = implied force due to v change minus f external // assume f does not include forces internal to body @@ -1583,6 +1592,8 @@ void FixRigidSmall::create_bodies(tagint *bodyID) double **x = atom->x; tagint *tag = atom->tag; imageint *image = atom->image; + int me = comm->me; + int nprocs = comm->nprocs; m = 0; for (i = 0; i < nlocal; i++) { @@ -2108,8 +2119,7 @@ void FixRigidSmall::setup_bodies_static() inertia = body[ibody].inertia; ierror = MathEigen::jacobi3(tensor,inertia,evectors); - if (ierror) error->all(FLERR, - "Insufficient Jacobi rotations for rigid body"); + if (ierror) error->all(FLERR, "Insufficient Jacobi rotations for rigid body"); ex = body[ibody].ex_space; ex[0] = evectors[0][0]; @@ -2305,30 +2315,30 @@ void FixRigidSmall::setup_bodies_static() if (inertia[0] == 0.0) { if (fabs(itensor[ibody][0]) > TOLERANCE) - error->all(FLERR,"Fix rigid: Bad principal moments"); + error->all(FLERR,"Fix {}: Bad principal moments", style); } else { if (fabs((itensor[ibody][0]-inertia[0])/inertia[0]) > - TOLERANCE) error->all(FLERR,"Fix rigid: Bad principal moments"); + TOLERANCE) error->all(FLERR,"Fix {}: Bad principal moments", style); } if (inertia[1] == 0.0) { if (fabs(itensor[ibody][1]) > TOLERANCE) - error->all(FLERR,"Fix rigid: Bad principal moments"); + error->all(FLERR,"Fix {}: Bad principal moments", style); } else { if (fabs((itensor[ibody][1]-inertia[1])/inertia[1]) > - TOLERANCE) error->all(FLERR,"Fix rigid: Bad principal moments"); + TOLERANCE) error->all(FLERR,"Fix {}: Bad principal moments", style); } if (inertia[2] == 0.0) { if (fabs(itensor[ibody][2]) > TOLERANCE) - error->all(FLERR,"Fix rigid: Bad principal moments"); + error->all(FLERR,"Fix {}: Bad principal moments", style); } else { if (fabs((itensor[ibody][2]-inertia[2])/inertia[2]) > - TOLERANCE) error->all(FLERR,"Fix rigid: Bad principal moments"); + TOLERANCE) error->all(FLERR,"Fix {}: Bad principal moments", style); } norm = (inertia[0] + inertia[1] + inertia[2]) / 3.0; if (fabs(itensor[ibody][3]/norm) > TOLERANCE || fabs(itensor[ibody][4]/norm) > TOLERANCE || fabs(itensor[ibody][5]/norm) > TOLERANCE) - error->all(FLERR,"Fix rigid: Bad principal moments"); + error->all(FLERR,"Fix {}: Bad principal moments", style); } // clean up @@ -2474,13 +2484,13 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) // open file and read header - if (me == 0) { + if (comm->me == 0) { fp = fopen(inpfile,"r"); if (fp == nullptr) - error->one(FLERR,"Cannot open fix rigid/small file {}: {}", inpfile, utils::getsyserror()); + error->one(FLERR,"Cannot open fix {} file {}: {}", style, inpfile, utils::getsyserror()); while (true) { eof = fgets(line,MAXLINE,fp); - if (eof == nullptr) error->one(FLERR,"Unexpected end of fix rigid/small file"); + if (eof == nullptr) error->one(FLERR,"Unexpected end of fix {} file", style); start = &line[strspn(line," \t\n\v\f\r")]; if (*start != '\0' && *start != '#') break; } @@ -2495,14 +2505,16 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) // generation when no infile was previously used. if (nlines == 0) return; - else if (nlines < 0) error->all(FLERR,"Fix rigid infile has incorrect format"); + else if (nlines < 0) error->all(FLERR,"Fix {} infile has incorrect format", style); auto buffer = new char[CHUNK*MAXLINE]; int nread = 0; + int me = comm->me; + while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); - if (eofflag) error->all(FLERR,"Unexpected end of fix rigid/small file"); + if (eofflag) error->all(FLERR,"Unexpected end of fix {} file", style); buf = buffer; next = strchr(buf,'\n'); @@ -2511,7 +2523,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) *next = '\n'; if (nwords != ATTRIBUTE_PERBODY) - error->all(FLERR,"Incorrect rigid body format in fix rigid/small file"); + error->all(FLERR,"Incorrect rigid body format in fix {} file", style); // loop over lines of rigid body attributes // tokenize the line into values @@ -2528,7 +2540,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) tagint id = values.next_tagint(); if (id <= 0 || id > maxmol) - error->all(FLERR,"Invalid rigid body molecude ID {} in fix rigid/small file", id); + error->all(FLERR,"Invalid rigid body molecude ID {} in fix {} file", id, style); if (hash.find(id) == hash.end()) { buf = next + 1; @@ -2565,14 +2577,14 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) array[m][3] = values.next_double(); } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid fix rigid/small infile: {}", e.what()); + error->all(FLERR, "Invalid fix {} infile: {}", style, e.what()); } buf = next + 1; } nread += nchunk; } - if (me == 0) fclose(fp); + if (comm->me == 0) fclose(fp); delete[] buffer; } @@ -2592,11 +2604,12 @@ void FixRigidSmall::write_restart_file(const char *file) // proc 0 opens file and writes header - if (me == 0) { + if (comm->me == 0) { auto outfile = std::string(file) + ".rigid"; fp = fopen(outfile.c_str(),"w"); if (fp == nullptr) - error->one(FLERR,"Cannot open fix rigid restart file {}: {}",outfile,utils::getsyserror()); + error->one(FLERR, "Cannot open fix {} restart file {}: {}", + style, outfile, utils::getsyserror()); fmt::print(fp,"# fix rigid mass, COM, inertia tensor info for " "{} bodies on timestep {}\n\n",nbody,update->ntimestep); @@ -2613,7 +2626,7 @@ void FixRigidSmall::write_restart_file(const char *file) MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); double **buf; - if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"rigid/small:buf"); + if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"rigid/small:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"rigid/small:buf"); // pack my rigid body info into buf @@ -2656,10 +2669,10 @@ void FixRigidSmall::write_restart_file(const char *file) int tmp,recvrow; - if (me == 0) { + if (comm->me == 0) { MPI_Status status; MPI_Request request; - for (int iproc = 0; iproc < nprocs; iproc++) { + for (int iproc = 0; iproc < comm->nprocs; iproc++) { if (iproc) { MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); MPI_Send(&tmp,0,MPI_INT,iproc,0,world); @@ -2691,7 +2704,7 @@ void FixRigidSmall::write_restart_file(const char *file) // clean up and close file memory->destroy(buf); - if (me == 0) fclose(fp); + if (comm->me == 0) fclose(fp); } /* ---------------------------------------------------------------------- @@ -3367,9 +3380,8 @@ void FixRigidSmall::reset_atom2body() if (bodytag[i]) { iowner = atom->map(bodytag[i]); if (iowner == -1) - error->one(FLERR,"Rigid body atoms {} {} missing on " - "proc {} at step {}",atom->tag[i], - bodytag[i],comm->me,update->ntimestep); + error->one(FLERR, "Rigid body atoms {} {} missing on proc {} at step {}", + atom->tag[i], bodytag[i], comm->me, update->ntimestep); atom2body[i] = bodyown[iowner]; } diff --git a/src/RIGID/fix_rigid_small.h b/src/RIGID/fix_rigid_small.h index b473026fdb..0070d976df 100644 --- a/src/RIGID/fix_rigid_small.h +++ b/src/RIGID/fix_rigid_small.h @@ -56,7 +56,6 @@ class FixRigidSmall : public Fix { void pre_neighbor() override; int dof(int) override; void deform(int) override; - void enforce2d() override; void reset_dt() override; void zero_momentum() override; void zero_rotation() override; @@ -68,7 +67,6 @@ class FixRigidSmall : public Fix { double memory_usage() override; protected: - int me, nprocs; double dtv, dtf, dtq; double *step_respa; int triclinic; @@ -202,7 +200,8 @@ class FixRigidSmall : public Fix { void setup_bodies_static(); void setup_bodies_dynamic(); void apply_langevin_thermostat(); - void compute_forces_and_torques(); + virtual void compute_forces_and_torques(); + void enforce2d(); void readfile(int, double **, int *); void grow_body(); void reset_atom2body(); diff --git a/src/angle_write.cpp b/src/angle_write.cpp index e64c2f23c8..fb0e65ccf5 100644 --- a/src/angle_write.cpp +++ b/src/angle_write.cpp @@ -123,11 +123,9 @@ void AngleWrite::command(int narg, char **arg) if (comm->me == 0) { // set up new LAMMPS instance with dummy system to evaluate angle potential - const char *args[] = {"AngleWrite", "-nocite", "-echo", "none", - "-log", "none", "-screen", "none"}; - char **argv = (char **) args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *writer = new LAMMPS(argc, argv, singlecomm); + LAMMPS::argv args = {"AngleWrite", "-nocite", "-echo", "none", + "-log", "none", "-screen", "none"}; + LAMMPS *writer = new LAMMPS(args, singlecomm); // create dummy system replicating angle style settings writer->input->one(fmt::format("units {}", update->unit_style)); diff --git a/src/balance.cpp b/src/balance.cpp index 3bd083e2b9..f63dc0cc33 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -198,8 +198,10 @@ void Balance::command(int narg, char **arg) if (style != -1) error->all(FLERR,"Illegal balance command"); if (iarg+4 > narg) error->all(FLERR,"Illegal balance command"); style = SHIFT; - if (strlen(arg[iarg+1]) > BSTR_SIZE) error->all(FLERR,"Illegal balance command"); - strncpy(bstr,arg[iarg+1],BSTR_SIZE+1); + const int blen = strlen(arg[iarg+1]); + if (blen > BSTR_SIZE) error->all(FLERR,"Illegal balance command"); + memset(bstr, 0, BSTR_SIZE+1); + memcpy(bstr,arg[iarg+1],blen); nitermax = utils::inumeric(FLERR,arg[iarg+2],false,lmp); if (nitermax <= 0) error->all(FLERR,"Illegal balance command"); stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -473,7 +475,7 @@ void Balance::options(int iarg, int narg, char **arg, int sortflag_default) } iarg += 2+nopt; - } else if (strcmp(arg[iarg+1],"sort") == 0) { + } else if (strcmp(arg[iarg],"sort") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "balance sort", error); sortflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; diff --git a/src/compute_aggregate_atom.cpp b/src/compute_aggregate_atom.cpp index e68062b73e..5a489092b7 100644 --- a/src/compute_aggregate_atom.cpp +++ b/src/compute_aggregate_atom.cpp @@ -35,6 +35,7 @@ using namespace LAMMPS_NS; +static constexpr int MAXLOOP = 100; /* ---------------------------------------------------------------------- */ ComputeAggregateAtom::ComputeAggregateAtom(LAMMPS *lmp, int narg, char **arg) : @@ -110,6 +111,11 @@ void ComputeAggregateAtom::compute_peratom() vector_atom = aggregateID; } + // communicate coords for ghost atoms if box can change, e.g. fix deform + // this ensures ghost atom coords are current + + comm->forward_comm(); + // invoke full neighbor list (will copy or build if necessary) // on the first step of a run, set preflag to one in neighbor->build_one(...) @@ -158,8 +164,11 @@ void ComputeAggregateAtom::compute_peratom() int change, done, anychange; - while (true) { + int counter = 0; + // stop after MAXLOOP iterations + while (counter < MAXLOOP) { comm->forward_comm(this); + ++counter; // reverse communication when bonds are not stored on every processor @@ -218,6 +227,8 @@ void ComputeAggregateAtom::compute_peratom() MPI_Allreduce(&change, &anychange, 1, MPI_INT, MPI_MAX, world); if (!anychange) break; } + if ((comm->me == 0) && (counter >= MAXLOOP)) + error->warning(FLERR, "Compute aggregate/atom did not converge after {} iterations", MAXLOOP); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index ae44fbcd37..ba0f263747 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -29,6 +29,7 @@ using namespace LAMMPS_NS; +static constexpr int MAXLOOP = 100; /* ---------------------------------------------------------------------- */ ComputeClusterAtom::ComputeClusterAtom(LAMMPS *lmp, int narg, char **arg) : @@ -99,6 +100,11 @@ void ComputeClusterAtom::compute_peratom() vector_atom = clusterID; } + // communicate coords for ghost atoms if box can change, e.g. fix deform + // this ensures ghost atom coords are current + + comm->forward_comm(); + // invoke full neighbor list (will copy or build if necessary) // on the first step of a run, set preflag to one in neighbor->build_one(...) @@ -136,9 +142,11 @@ void ComputeClusterAtom::compute_peratom() int change, done, anychange; - while (true) { + int counter = 0; + // stop after MAXLOOP iterations + while (counter < MAXLOOP) { comm->forward_comm(this); - + ++counter; change = 0; while (true) { done = 1; @@ -177,6 +185,8 @@ void ComputeClusterAtom::compute_peratom() MPI_Allreduce(&change, &anychange, 1, MPI_INT, MPI_MAX, world); if (!anychange) break; } + if ((comm->me == 0) && (counter >= MAXLOOP)) + error->warning(FLERR, "Compute cluster/atom did not converge after {} iterations", MAXLOOP); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_fragment_atom.cpp b/src/compute_fragment_atom.cpp index 035f554c8d..7e3f3437b6 100644 --- a/src/compute_fragment_atom.cpp +++ b/src/compute_fragment_atom.cpp @@ -31,7 +31,8 @@ using namespace LAMMPS_NS; -#define BIG 1.0e20 +static constexpr double BIG = 1.0e20; +static constexpr int MAXLOOP = 100; /* ---------------------------------------------------------------------- */ @@ -145,8 +146,11 @@ void ComputeFragmentAtom::compute_peratom() commflag = 1; - while (true) { + int counter = 0; + // stop after MAXLOOP iterations + while (counter < MAXLOOP) { comm->forward_comm(this); + ++counter; done = 1; // set markflag = 0 for all owned atoms, for new iteration @@ -223,6 +227,8 @@ void ComputeFragmentAtom::compute_peratom() MPI_Allreduce(&done,&alldone,1,MPI_INT,MPI_MIN,world); if (alldone) break; } + if ((comm->me == 0) && (counter >= MAXLOOP)) + error->warning(FLERR, "Compute fragment/atom did not converge after {} iterations", MAXLOOP); } /* ---------------------------------------------------------------------- */ diff --git a/src/dihedral_write.cpp b/src/dihedral_write.cpp index 285d9cf931..3d87591bcc 100644 --- a/src/dihedral_write.cpp +++ b/src/dihedral_write.cpp @@ -124,12 +124,8 @@ void DihedralWrite::command(int narg, char **arg) if (comm->me == 0) { // set up new LAMMPS instance with dummy system to evaluate dihedral potential - // const char *args[] = {"DihedralWrite", "-nocite", "-echo", "none", - // "-log", "none", "-screen", "none"}; - const char *args[] = {"DihedralWrite", "-nocite", "-echo", "screen", "-log", "none"}; - char **argv = (char **) args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *writer = new LAMMPS(argc, argv, singlecomm); + LAMMPS::argv args = {"DihedralWrite", "-nocite", "-echo", "screen", "-log", "none"}; + LAMMPS *writer = new LAMMPS(args, singlecomm); // create dummy system replicating dihedral style settings writer->input->one(fmt::format("units {}", update->unit_style)); diff --git a/src/dump_image.cpp b/src/dump_image.cpp index 1ba433f93f..c426151b00 100644 --- a/src/dump_image.cpp +++ b/src/dump_image.cpp @@ -140,13 +140,9 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) : } char *fixID = nullptr; - thetastr = phistr = nullptr; cflag = STATIC; cx = cy = cz = 0.5; - cxstr = cystr = czstr = nullptr; - upxstr = upystr = upzstr = nullptr; - zoomstr = nullptr; boxflag = YES; boxdiam = 0.02; axesflag = NO; @@ -471,6 +467,16 @@ DumpImage::~DumpImage() memory->destroy(bufcopy); memory->destroy(gbuf); + delete[] upxstr; + delete[] upystr; + delete[] upzstr; + delete[] zoomstr; + delete[] thetastr; + delete[] phistr; + delete[] cxstr; + delete[] cystr; + delete[] czstr; + delete[] id_grid_compute; delete[] id_grid_fix; } diff --git a/src/fix.cpp b/src/fix.cpp index 70e4133cdd..754948fdd1 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -72,7 +72,6 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : dynamic = 0; dof_flag = 0; special_alter_flag = 0; - enforce2d_flag = 0; respa_level_support = 0; respa_level = -1; maxexchange = 0; diff --git a/src/fix.h b/src/fix.h index 5d55048c28..9b595f0c60 100644 --- a/src/fix.h +++ b/src/fix.h @@ -72,7 +72,6 @@ class Fix : protected Pointers { int dynamic_group_allow; // 1 if can be used with dynamic group, else 0 int dof_flag; // 1 if has dof() method (not min_dof()) int special_alter_flag; // 1 if has special_alter() meth for spec lists - int enforce2d_flag; // 1 if has enforce2d method int respa_level_support; // 1 if fix supports fix_modify respa int respa_level; // which respa level to apply fix (1-Nrespa) int maxexchange; // max # of per-atom values for Comm::exchange() @@ -241,7 +240,6 @@ class Fix : protected Pointers { virtual void deform(int) {} virtual void reset_target(double) {} virtual void reset_dt() {} - virtual void enforce2d() {} virtual void read_data_header(char *) {} virtual void read_data_section(char *, int, char *, tagint) {} diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 660e3f6107..996597ab8b 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -39,8 +39,8 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR,KSPACE,ATOM,BOND,ANGLE}; -enum{DIAMETER,CHARGE}; +enum{PAIR, KSPACE, ATOM, BOND, ANGLE}; +enum{DIAMETER, CHARGE}; /* ---------------------------------------------------------------------- */ diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index 844ffe474e..2de8991d8a 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -67,9 +67,10 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : int iarg = 5; if (lbstyle == SHIFT) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix balance command"); - if (strlen(arg[iarg+1]) > Balance::BSTR_SIZE) - error->all(FLERR,"Illegal fix balance command"); - strncpy(bstr,arg[iarg+1], Balance::BSTR_SIZE+1); + const int blen = strlen(arg[iarg+1]); + if (blen > Balance::BSTR_SIZE) error->all(FLERR,"Illegal balance command"); + memset(bstr, 0, Balance::BSTR_SIZE+1); + memcpy(bstr,arg[iarg+1],blen); nitermax = utils::inumeric(FLERR,arg[iarg+2],false,lmp); if (nitermax <= 0) error->all(FLERR,"Illegal fix balance command"); stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp index c6816c2355..c13e2147a3 100644 --- a/src/fix_enforce2d.cpp +++ b/src/fix_enforce2d.cpp @@ -27,12 +27,9 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixEnforce2D::FixEnforce2D(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), - flist(nullptr) + Fix(lmp, narg, arg) { if (narg != 3) error->all(FLERR,"Illegal fix enforce2d command"); - - nfixlist = 0; } /* ---------------------------------------------------------------------- */ @@ -40,8 +37,6 @@ FixEnforce2D::FixEnforce2D(LAMMPS *lmp, int narg, char **arg) : FixEnforce2D::~FixEnforce2D() { if (copymode) return; - - delete [] flist; } /* ---------------------------------------------------------------------- */ @@ -61,29 +56,6 @@ void FixEnforce2D::init() { if (domain->dimension == 3) error->all(FLERR,"Cannot use fix enforce2d with 3d simulation"); - - // list of fixes with enforce2d methods - - nfixlist = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->enforce2d_flag) nfixlist++; - - if (nfixlist) { - int myindex = -1; - delete [] flist; - flist = new Fix*[nfixlist]; - nfixlist = 0; - for (int i = 0; i < modify->nfix; i++) { - if (modify->fix[i]->enforce2d_flag) { - if (myindex < 0) - flist[nfixlist++] = modify->fix[i]; - else - error->all(FLERR,"Fix enforce2d must be defined after fix {}", - modify->fix[i]->style); - } - if (modify->fix[i] == this) myindex = i; - } - } } /* ---------------------------------------------------------------------- */ @@ -153,12 +125,6 @@ void FixEnforce2D::post_force(int /*vflag*/) torque[i][1] = 0.0; } } - - // invoke other fixes that enforce 2d - // fix rigid variants - - for (int m = 0; m < nfixlist; m++) - flist[m]->enforce2d(); } /* ---------------------------------------------------------------------- */ diff --git a/src/fix_enforce2d.h b/src/fix_enforce2d.h index 4572785158..95429ba7dc 100644 --- a/src/fix_enforce2d.h +++ b/src/fix_enforce2d.h @@ -35,10 +35,6 @@ class FixEnforce2D : public Fix { void post_force(int) override; void post_force_respa(int, int, int) override; void min_post_force(int) override; - - protected: - int nfixlist; - class Fix **flist; }; } // namespace LAMMPS_NS diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 994b4f0f19..3a53110839 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -198,16 +198,24 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : astyle = utils::strdup(atom->atom_style); - // perform initial allocation of atom-based array // register with Atom class - nmax_old = 0; - if (!lmp->kokkos) FixPropertyAtom::grow_arrays(atom->nmax); atom->add_callback(Atom::GROW); atom->add_callback(Atom::RESTART); if (border) atom->add_callback(Atom::BORDER); } + +/* ---------------------------------------------------------------------- */ + +void FixPropertyAtom::post_constructor() +{ + // perform initial allocation of atom-based array + + nmax_old = 0; + grow_arrays(atom->nmax); +} + /* ---------------------------------------------------------------------- */ FixPropertyAtom::~FixPropertyAtom() diff --git a/src/fix_property_atom.h b/src/fix_property_atom.h index 92497d6188..c50b6049dc 100644 --- a/src/fix_property_atom.h +++ b/src/fix_property_atom.h @@ -27,6 +27,7 @@ namespace LAMMPS_NS { class FixPropertyAtom : public Fix { public: FixPropertyAtom(class LAMMPS *, int, char **); + void post_constructor() override; ~FixPropertyAtom() override; int setmask() override; void init() override; diff --git a/src/force.cpp b/src/force.cpp index 347b3087cf..a64865cf58 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -332,6 +332,8 @@ void Force::create_bond(const std::string &style, int trysuffix) { delete[] bond_style; if (bond) delete bond; + bond_style = nullptr; + bond = nullptr; int sflag; bond = new_bond(style, trysuffix, sflag); @@ -400,6 +402,8 @@ void Force::create_angle(const std::string &style, int trysuffix) { delete[] angle_style; if (angle) delete angle; + angle_style = nullptr; + angle = nullptr; int sflag; angle = new_angle(style, trysuffix, sflag); @@ -468,6 +472,8 @@ void Force::create_dihedral(const std::string &style, int trysuffix) { delete[] dihedral_style; if (dihedral) delete dihedral; + dihedral_style = nullptr; + dihedral = nullptr; int sflag; dihedral = new_dihedral(style, trysuffix, sflag); @@ -536,6 +542,8 @@ void Force::create_improper(const std::string &style, int trysuffix) { delete[] improper_style; if (improper) delete improper; + improper_style = nullptr; + improper = nullptr; int sflag; improper = new_improper(style, trysuffix, sflag); @@ -604,6 +612,8 @@ void Force::create_kspace(const std::string &style, int trysuffix) { delete[] kspace_style; if (kspace) delete kspace; + kspace_style = nullptr; + kspace = nullptr; int sflag; kspace = new_kspace(style, trysuffix, sflag); diff --git a/src/info.cpp b/src/info.cpp index 4b9a761af5..73f4ba4bdc 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -1243,6 +1243,10 @@ std::string Info::get_accelerator_info(const std::string &package) if (has_accelerator_feature("KOKKOS","precision","single")) mesg += " single"; if (has_accelerator_feature("KOKKOS","precision","mixed")) mesg += " mixed"; if (has_accelerator_feature("KOKKOS","precision","double")) mesg += " double"; +#if LMP_KOKKOS + mesg += fmt::format("\nKokkos library version: {}.{}.{}", KOKKOS_VERSION / 10000, + (KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100); +#endif mesg += "\n"; } if ((package.empty() || (package == "OPENMP")) && has_package("OPENMP")) { @@ -1253,6 +1257,9 @@ std::string Info::get_accelerator_info(const std::string &package) if (has_accelerator_feature("OPENMP","precision","single")) mesg += " single"; if (has_accelerator_feature("OPENMP","precision","mixed")) mesg += " mixed"; if (has_accelerator_feature("OPENMP","precision","double")) mesg += " double"; +#if defined(_OPENMP) + mesg += "\nOpenMP standard: " + platform::openmp_standard(); +#endif mesg += "\n"; } if ((package.empty() || (package == "INTEL")) && has_package("INTEL")) { diff --git a/src/lammps.cpp b/src/lammps.cpp index 9ac4c98bc3..ab20aedea7 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -16,6 +16,7 @@ #include "style_angle.h" // IWYU pragma: keep #include "style_atom.h" // IWYU pragma: keep +#include "style_body.h" // IWYU pragma: keep #include "style_bond.h" // IWYU pragma: keep #include "style_command.h" // IWYU pragma: keep #include "style_compute.h" // IWYU pragma: keep @@ -27,6 +28,7 @@ #include "style_kspace.h" // IWYU pragma: keep #include "style_minimize.h" // IWYU pragma: keep #include "style_pair.h" // IWYU pragma: keep +#include "style_reader.h" // IWYU pragma: keep #include "style_region.h" // IWYU pragma: keep #include "accelerator_kokkos.h" @@ -107,6 +109,15 @@ using namespace LAMMPS_NS; * The specifics of setting up and running a simulation are handled by the * individual component class instances. */ +/** Create a LAMMPS simulation instance + * + * \param args list of arguments + * \param communicator MPI communicator used by this LAMMPS instance + */ +LAMMPS::LAMMPS(argv & args, MPI_Comm communicator) : + LAMMPS(args.size(), argv_pointers(args).data(), communicator) { +} + /** Create a LAMMPS simulation instance * * The LAMMPS constructor starts up a simulation by allocating all @@ -210,7 +221,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : suffix = suffix2 = nullptr; suffix_enable = 0; pair_only_flag = 0; - if (arg) exename = arg[0]; + if (arg) exename = utils::strdup(arg[0]); else exename = nullptr; packargs = nullptr; num_package = 0; @@ -802,6 +813,7 @@ LAMMPS::~LAMMPS() delete memory; delete pkg_lists; + delete[] exename; } /* ---------------------------------------------------------------------- @@ -1152,9 +1164,9 @@ const char *LAMMPS::match_style(const char *style, const char *name) check_for_match(bond,style,name); check_for_match(command,style,name); check_for_match(compute,style,name); + check_for_match(dihedral,style,name); check_for_match(dump,style,name); check_for_match(fix,style,name); - check_for_match(compute,style,name); check_for_match(improper,style,name); check_for_match(integrate,style,name); check_for_match(kspace,style,name); @@ -1165,6 +1177,8 @@ const char *LAMMPS::match_style(const char *style, const char *name) return nullptr; } +#undef check_for_match + /** \brief Return suffix for non-pair styles depending on pair_only_flag * * \return suffix or null pointer @@ -1467,3 +1481,17 @@ void LAMMPS::print_config(FILE *fp) } fputs("\n\n",fp); } + +/** Create vector of argv string pointers including terminating nullptr element + * + * \param args list of arguments + */ +std::vector LAMMPS::argv_pointers(argv & args){ + std::vector r; + r.reserve(args.size()+1); + for(auto & a : args) { + r.push_back((char*)a.data()); + } + r.push_back(nullptr); + return r; +} diff --git a/src/lammps.h b/src/lammps.h index 03b019ed43..0d6d62fc60 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -16,6 +16,8 @@ #include #include +#include +#include namespace LAMMPS_NS { @@ -84,6 +86,10 @@ class LAMMPS { static const char *git_branch(); static const char *git_descriptor(); + using argv = std::vector; + static std::vector argv_pointers(argv & args); + + LAMMPS(argv & args, MPI_Comm); LAMMPS(int, char **, MPI_Comm); ~LAMMPS(); void create(); diff --git a/src/library.cpp b/src/library.cpp index a88498a5e9..f36d75a40a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -822,14 +822,17 @@ void *lammps_last_thermo(void *handle, const char *what, int index) { auto lmp = (LAMMPS *) handle; void *val = nullptr; + + if (!lmp->output) return val; Thermo *th = lmp->output->thermo; - if (!th) return nullptr; + if (!th) return val; const int nfield = *th->get_nfield(); BEGIN_CAPTURE { if (strcmp(what, "setup") == 0) { - val = (void *) &lmp->update->setupflag; + if (lmp->update) + val = (void *) &lmp->update->setupflag; } else if (strcmp(what, "step") == 0) { val = (void *) th->get_timestep(); diff --git a/src/min.cpp b/src/min.cpp index 5a469a788b..acc7d17654 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -215,6 +215,9 @@ void Min::setup(int flag) } update->setupflag = 1; + if (lmp->kokkos) + error->all(FLERR,"KOKKOS package requires Kokkos-enabled min_style"); + // setup extra global dof due to fixes // cannot be done in init() b/c update init() is before modify init() diff --git a/src/neighbor.cpp b/src/neighbor.cpp index df1547e5eb..741b469750 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1126,15 +1126,14 @@ int Neighbor::init_pair() } /* ---------------------------------------------------------------------- - sort NeighRequests by cutoff distance - to find smallest list for trimming + sort NeighRequests by cutoff distance for trimming ------------------------------------------------------------------------- */ void Neighbor::sort_requests() { - NeighRequest *jrq; + NeighRequest *irq,*jrq; int i,j,jmin; - double jcut; + double icut,jcut; delete[] j_sorted; j_sorted = new int[nrequest]; @@ -1142,20 +1141,24 @@ void Neighbor::sort_requests() for (i = 0; i < nrequest; i++) j_sorted[i] = i; - for (i = 0; i < nrequest; i++) { - double cutoff_min = cutneighmax; + for (i = 0; i < nrequest-1; i++) { + irq = requests[j_sorted[i]]; + if (irq->cut) icut = irq->cutoff; + else icut = cutneighmax; + double cutoff_min = icut; jmin = i; - for (j = i; j < nrequest-1; j++) { + for (j = i+1; j < nrequest; j++) { jrq = requests[j_sorted[j]]; if (jrq->cut) jcut = jrq->cutoff; else jcut = cutneighmax; - if (jcut <= cutoff_min) { + if (jcut < cutoff_min) { cutoff_min = jcut; jmin = j; } } + int tmp = j_sorted[i]; j_sorted[i] = j_sorted[jmin]; j_sorted[jmin] = tmp; diff --git a/src/npair_trim.cpp b/src/npair_trim.cpp index 14974d72ab..a4b6c1c6a1 100644 --- a/src/npair_trim.cpp +++ b/src/npair_trim.cpp @@ -50,11 +50,15 @@ void NPairTrim::build(NeighList *list) int *numneigh_copy = listcopy->numneigh; int **firstneigh_copy = listcopy->firstneigh; int inum = listcopy->inum; + int gnum = listcopy->gnum; list->inum = inum; - list->gnum = listcopy->gnum; + list->gnum = gnum; - for (ii = 0; ii < inum; ii++) { + int inum_trim = inum; + if (list->ghost) inum_trim += gnum; + + for (ii = 0; ii < inum_trim; ii++) { n = 0; neighptr = ipage->vget(); diff --git a/src/platform.cpp b/src/platform.cpp index 861e3d7722..a53318958d 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -239,6 +239,8 @@ std::string platform::os_info() buf = "Windows 11 21H2"; } else if (build == "22621") { buf = "Windows 11 22H2"; + } else if (build == "22631") { + buf = "Windows 11 23H2"; } else { const char *entry = "ProductName"; RegGetValue(HKEY_LOCAL_MACHINE, subkey, entry, RRF_RT_REG_SZ, nullptr, &value, @@ -389,8 +391,16 @@ std::string platform::openmp_standard() // Supported OpenMP version corresponds to the release date of the // specifications as posted at https://www.openmp.org/specifications/ -#if _OPENMP > 202011 - return "OpenMP newer than version 5.1"; +#if _OPENMP > 202411 + return "OpenMP newer than version 6.0"; +#elif _OPENMP == 202411 + return "OpenMP 6.0"; +#elif _OPENMP == 202311 + return "OpenMP 6.0 preview 2"; +#elif _OPENMP == 202211 + return "OpenMP 6.0 preview 1"; +#elif _OPENMP == 202111 + return "OpenMP 5.2"; #elif _OPENMP == 202011 return "OpenMP 5.1"; #elif _OPENMP == 201811 diff --git a/src/region_cone.cpp b/src/region_cone.cpp index 76bedf4c92..5fe7b4b5db 100644 --- a/src/region_cone.cpp +++ b/src/region_cone.cpp @@ -131,7 +131,7 @@ RegCone::RegCone(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg), lo if (radiushi < 0.0) error->all(FLERR, "Illegal radius in region cone command"); if (radiuslo == 0.0 && radiushi == 0.0) error->all(FLERR, "Illegal radius in region cone command"); - if (hi == lo) error->all(FLERR, "Illegal cone length in region cone command"); + if (hi <= lo) error->all(FLERR, "Illegal cone length in region cone command"); // extent of cone diff --git a/src/region_ellipsoid.cpp b/src/region_ellipsoid.cpp index 3520b55813..0296178648 100644 --- a/src/region_ellipsoid.cpp +++ b/src/region_ellipsoid.cpp @@ -190,8 +190,8 @@ int RegEllipsoid::surface_interior(double *x, double cutoff) double b_r = b - cutoff; double c_r = c - cutoff; double delx_r = b_r * c_r * (x[0] - xc); - double dely_r = a_r * c_r * (x[1] - xc); - double delz_r = a_r * b_r * (x[2] - xc); + double dely_r = a_r * c_r * (x[1] - yc); + double delz_r = a_r * b_r * (x[2] - zc); double r_r = delx_r * delx_r + dely_r * dely_r + delz_r * delz_r; double rc_r = a_r * a_r * b_r * b_r * c_r * c_r; @@ -217,9 +217,9 @@ int RegEllipsoid::surface_interior(double *x, double cutoff) contact[0].r = DistancePointEllipsoid( axes[sorting[2]], axes[sorting[1]], axes[sorting[0]], coords[sorting[2]], coords[sorting[1]], coords[sorting[0]], x0[sorting[2]], x0[sorting[1]], x0[sorting[0]]); - contact[0].delx = x[0] - (copysign(x0[sorting[2]], x[0] - xc) + xc); - contact[0].dely = x[1] - (copysign(x0[sorting[1]], x[1] - yc) + yc); - contact[0].delz = x[2] - (copysign(x0[sorting[0]], x[2] - zc) + zc); + contact[0].delx = x[0] - (copysign(x0[0], x[0] - xc) + xc); + contact[0].dely = x[1] - (copysign(x0[1], x[1] - yc) + yc); + contact[0].delz = x[2] - (copysign(x0[2], x[2] - zc) + zc); // contact[0].radius = -radius; contact[0].iwall = 0; contact[0].varflag = 1; @@ -236,7 +236,7 @@ int RegEllipsoid::surface_interior(double *x, double cutoff) double a_r = a - cutoff; double b_r = b - cutoff; double delx_r = b_r * (x[0] - xc); - double dely_r = a_r * (x[1] - xc); + double dely_r = a_r * (x[1] - yc); double r_r = delx_r * delx_r + dely_r * dely_r; double rc_r = a_r * a_r * b_r * b_r; @@ -281,8 +281,8 @@ int RegEllipsoid::surface_exterior(double *x, double cutoff) double b_r = b + cutoff; double c_r = c + cutoff; double delx_r = b_r * c_r * (x[0] - xc); - double dely_r = a_r * c_r * (x[1] - xc); - double delz_r = a_r * b_r * (x[2] - xc); + double dely_r = a_r * c_r * (x[1] - yc); + double delz_r = a_r * b_r * (x[2] - zc); double r_r = delx_r * delx_r + dely_r * dely_r + delz_r * delz_r; double rc_r = a_r * a_r * b_r * b_r * c_r * c_r; @@ -308,9 +308,9 @@ int RegEllipsoid::surface_exterior(double *x, double cutoff) contact[0].r = DistancePointEllipsoid( axes[sorting[2]], axes[sorting[1]], axes[sorting[0]], coords[sorting[2]], coords[sorting[1]], coords[sorting[0]], x0[sorting[2]], x0[sorting[1]], x0[sorting[0]]); - contact[0].delx = x[0] - (copysign(x0[sorting[2]], x[0] - xc) + xc); - contact[0].dely = x[1] - (copysign(x0[sorting[1]], x[1] - yc) + yc); - contact[0].delz = x[2] - (copysign(x0[sorting[0]], x[2] - zc) + zc); + contact[0].delx = x[0] - (copysign(x0[0], x[0] - xc) + xc); + contact[0].dely = x[1] - (copysign(x0[1], x[1] - yc) + yc); + contact[0].delz = x[2] - (copysign(x0[2], x[2] - zc) + zc); // contact[0].radius = radius; contact[0].iwall = 0; contact[0].varflag = 1; @@ -327,7 +327,7 @@ int RegEllipsoid::surface_exterior(double *x, double cutoff) double a_r = a + cutoff; double b_r = b + cutoff; double delx_r = b_r * (x[0] - xc); - double dely_r = a_r * (x[1] - xc); + double dely_r = a_r * (x[1] - yc); double r_r = delx_r * delx_r + dely_r * dely_r; double rc_r = a_r * a_r * b_r * b_r; diff --git a/src/replicate.cpp b/src/replicate.cpp index 01cc1faabb..6a4c8bfd74 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -52,8 +52,11 @@ void Replicate::command(int narg, char **arg) int nx = utils::inumeric(FLERR,arg[0],false,lmp); int ny = utils::inumeric(FLERR,arg[1],false,lmp); int nz = utils::inumeric(FLERR,arg[2],false,lmp); - int nrep = nx*ny*nz; + if ((nx <= 0) || (ny <= 0) || (nz <= 0)) + error->all(FLERR, "Illegal replication grid {}x{}x{}. All replications must be > 0", + nx, ny, nz); + int nrep = nx*ny*nz; if (me == 0) utils::logmesg(lmp, "Replication is creating a {}x{}x{} = {} times larger system...\n", nx, ny, nz, nrep); diff --git a/src/update.cpp b/src/update.cpp index e6b97e5731..093dd375d5 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -332,6 +332,8 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) delete[] integrate_style; delete integrate; + integrate_style = nullptr; + integrate = nullptr; int sflag; @@ -396,10 +398,12 @@ void Update::new_integrate(char *style, int narg, char **arg, int trysuffix, int void Update::create_minimize(int narg, char **arg, int trysuffix) { - if (narg < 1) error->all(FLERR, "Illegal run_style command"); + if (narg < 1) error->all(FLERR, "Illegal minimize_style command"); delete[] minimize_style; delete minimize; + minimize_style = nullptr; + minimize = nullptr; // temporarily assign the style name without suffix (for error messages during creation) minimize_style = arg[0]; diff --git a/src/version.h b/src/version.h index e7f36633bf..b99170567b 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ #define LAMMPS_VERSION "2 Aug 2023" -#define LAMMPS_UPDATE "Update 1" +#define LAMMPS_UPDATE "Update 2" diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt index 67e8807b1e..de8e2aa7dc 100644 --- a/tools/lammps-gui/CMakeLists.txt +++ b/tools/lammps-gui/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -project(lammps-gui VERSION 1.2.4 LANGUAGES CXX) +project(lammps-gui VERSION 1.2.5 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index 68b29d4830..50f9a0b735 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -530,6 +530,8 @@ void LammpsGui::open_file(const QString &fileName) update_variables(); } +// write file and update CWD to its folder + void LammpsGui::write_file(const QString &fileName) { QFileInfo path(fileName); @@ -542,6 +544,7 @@ void LammpsGui::write_file(const QString &fileName) return; } setWindowTitle(QString("LAMMPS-GUI - " + current_file)); + QDir::setCurrent(current_dir); update_recents(path.absoluteFilePath()); @@ -1084,17 +1087,17 @@ void LammpsGui::preferences() QSettings settings; int oldthreads = settings.value("nthreads", 1).toInt(); int oldaccel = settings.value("accelerator", AcceleratorTab::None).toInt(); - bool oldecho = settings.value("echo", 0).toBool(); - bool oldcite = settings.value("cite", 0).toBool(); + bool oldecho = settings.value("echo", 0).toBool(); + bool oldcite = settings.value("cite", 0).toBool(); Preferences prefs(&lammps); if (prefs.exec() == QDialog::Accepted) { // must delete LAMMPS instance after preferences have changed that require // using different command line flags when creating the LAMMPS instance like // suffixes or package commands + int newthreads = settings.value("nthreads", 1).toInt(); if ((oldaccel != settings.value("accelerator", AcceleratorTab::None).toInt()) || - (oldthreads != settings.value("nthreads", 1).toInt()) || - (oldecho != settings.value("echo", 0).toBool()) || + (oldthreads != newthreads) || (oldecho != settings.value("echo", 0).toBool()) || (oldcite != settings.value("cite", 0).toBool())) { if (lammps.is_running()) { stop_run(); @@ -1103,6 +1106,10 @@ void LammpsGui::preferences() } lammps.close(); lammpsstatus->hide(); +#if defined(_OPENMP) + qputenv("OMP_NUM_THREADS", std::to_string(newthreads).c_str()); + omp_set_num_threads(newthreads); +#endif } if (imagewindow) imagewindow->createImage(); } @@ -1170,9 +1177,17 @@ void LammpsGui::start_lammps() lammps.open(narg, args); lammpsstatus->show(); + // must have at least 2 August 2023 version of LAMMPS + if (lammps.version() < 20230802) { + QMessageBox::critical(this, "Incompatible LAMMPS Version", + "LAMMPS-GUI version " LAMMPS_GUI_VERSION " requires\n" + "LAMMPS version 2 August 2023 or later"); + exit(1); + } + // delete additional arguments again (3 were there initially while (lammps_args.size() > initial_narg) { - delete lammps_args.back(); + delete[] lammps_args.back(); lammps_args.pop_back(); } diff --git a/tools/lammps-gui/lammpswrapper.cpp b/tools/lammps-gui/lammpswrapper.cpp index bb46d7c425..ac6bbb1cbc 100644 --- a/tools/lammps-gui/lammpswrapper.cpp +++ b/tools/lammps-gui/lammpswrapper.cpp @@ -32,6 +32,19 @@ void LammpsWrapper::open(int narg, char **args) #endif } +int LammpsWrapper::version() +{ + int val = 0; + if (lammps_handle) { +#if defined(LAMMPS_GUI_USE_PLUGIN) + val = ((liblammpsplugin_t *)plugin_handle)->version(lammps_handle); +#else + val = lammps_version(lammps_handle); +#endif + } + return val; +} + int LammpsWrapper::extract_setting(const char *keyword) { int val = 0; diff --git a/tools/lammps-gui/lammpswrapper.h b/tools/lammps-gui/lammpswrapper.h index 555307960c..7723326145 100644 --- a/tools/lammps-gui/lammpswrapper.h +++ b/tools/lammps-gui/lammpswrapper.h @@ -28,6 +28,7 @@ public: void force_timeout(); + int version(); int extract_setting(const char *keyword); void *extract_global(const char *keyword); void *extract_atom(const char *keyword); diff --git a/tools/lammps-gui/periodic_table.h b/tools/lammps-gui/periodic_table.h index 22138c19ad..1193341ada 100644 --- a/tools/lammps-gui/periodic_table.h +++ b/tools/lammps-gui/periodic_table.h @@ -13,11 +13,13 @@ * all tables and functions are declared static, so that it * can be safely included by all plugins that may need it. * - * 2002-2009 akohlmey@cmm.chem.upenn.edu, vmd@ks.uiuc.edu + * 2002-2009,2023 akohlmey@gmail.com, vmd@ks.uiuc.edu */ -#include #include +#include + +// clang-format off /* periodic table of elements for translation of ordinal to atom type */ static const char *pte_label[] = { diff --git a/tools/lammps-gui/preferences.cpp b/tools/lammps-gui/preferences.cpp index 7ce80261a9..91d8026e3f 100644 --- a/tools/lammps-gui/preferences.cpp +++ b/tools/lammps-gui/preferences.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #if defined(_OPENMP) #include @@ -115,8 +116,13 @@ void Preferences::accept() // store number of threads QLineEdit *field = tabWidget->findChild("nthreads"); - if (field) - if (field->hasAcceptableInput()) settings->setValue("nthreads", field->text()); + if (field) { + int accel = settings->value("accelerator", AcceleratorTab::None).toInt(); + if ((accel == AcceleratorTab::None) || (accel == AcceleratorTab::Opt)) + settings->setValue("nthreads", 1); + else if (field->hasAcceptableInput()) + settings->setValue("nthreads", field->text()); + } // store image width, height, zoom, and rendering settings @@ -366,11 +372,11 @@ AcceleratorTab::AcceleratorTab(QSettings *_settings, LammpsWrapper *_lammps, QWi int maxthreads = 1; #if defined(_OPENMP) - maxthreads = omp_get_max_threads(); + maxthreads = QThread::idealThreadCount(); #endif auto *choices = new QFrame; auto *choiceLayout = new QVBoxLayout; - auto *ntlabel = new QLabel("Number of threads:"); + auto *ntlabel = new QLabel(QString("Number of threads (max %1):").arg(maxthreads)); auto *ntchoice = new QLineEdit(settings->value("nthreads", maxthreads).toString()); auto *intval = new QIntValidator(1, maxthreads, this); ntchoice->setValidator(intval); @@ -397,7 +403,7 @@ SnapshotTab::SnapshotTab(QSettings *_settings, QWidget *parent) : auto *ssao = new QLabel("HQ Image mode:"); auto *bbox = new QLabel("Show Box:"); auto *axes = new QLabel("Show Axes:"); - auto *vdw = new QLabel("VDW Style:"); + auto *vdw = new QLabel("VDW Style:"); auto *cback = new QLabel("Background Color:"); auto *cbox = new QLabel("Box Color:"); settings->beginGroup("snapshot"); diff --git a/tools/phonon/CMakeLists.txt b/tools/phonon/CMakeLists.txt index f3c3b8386c..697c7870b9 100644 --- a/tools/phonon/CMakeLists.txt +++ b/tools/phonon/CMakeLists.txt @@ -119,5 +119,9 @@ if(USE_SPGLIB) target_link_libraries(phana PRIVATE SPGLIB::SYMSPG) endif() +# add dependency when using local linear algebra lib +if(NOT LAPACK_FOUND OR NOT BLAS_FOUND OR USE_INTERNAL_LINALG) + add_dependencies(phana linalg) +endif() target_link_libraries(phana PRIVATE tricubic ${LAPACK_LIBRARIES}) install(TARGETS phana EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/tools/valgrind/MPICH.supp b/tools/valgrind/MPICH.supp new file mode 100644 index 0000000000..6934cf8fbd --- /dev/null +++ b/tools/valgrind/MPICH.supp @@ -0,0 +1,41 @@ +{ + MPICH_MPI_init1 + Memcheck:Leak + match-leak-kinds: reachable + fun:malloc + obj:* + ... + fun:psm3_init + ... + fun:MPIDI_OFI_init_local + ... + fun:PMPI_Init + fun:main +} +{ + MPICH_MPI_init2 + Memcheck:Leak + match-leak-kinds: reachable + fun:malloc + fun:strdup + obj:* + ... + fun:fi_ini + ... + fun:MPIDI_OFI_init_local + ... + fun:PMPI_Init + fun:main +} +{ + MPICH_MPI_init3 + Memcheck:Leak + match-leak-kinds: reachable + fun:calloc + obj:* + ... + fun:MPIDI_OFI_init_local + ... + fun:PMPI_Init + fun:main +} diff --git a/tools/valgrind/README b/tools/valgrind/README index 63c440f7b2..e62031da9b 100644 --- a/tools/valgrind/README +++ b/tools/valgrind/README @@ -8,6 +8,7 @@ on running LAMMPS, use a command line like following: valgrind --show-leak-kinds=all --track-origins=yes \ --suppressions=/path/to/lammps/tools/valgrind/OpenMP.supp \ --suppressions=/path/to/lammps/tools/valgrind/OpenMPI.supp \ + --suppressions=/path/to/lammps/tools/valgrind/MPICH.supp \ --suppressions=/path/to/lammps/tools/valgrind/Python3.supp \ --suppressions=/path/to/lammps/tools/valgrind/GTest.supp \ --suppressions=/path/to/lammps/tools/valgrind/FlexiBLAS.supp \ diff --git a/unittest/c-library/test_library_commands.cpp b/unittest/c-library/test_library_commands.cpp index d4e326cd36..31f8268a8f 100644 --- a/unittest/c-library/test_library_commands.cpp +++ b/unittest/c-library/test_library_commands.cpp @@ -26,10 +26,11 @@ protected: void SetUp() override { const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", - "-var", "x", "2", "-var", "zpos", "1.5"}; + "-var", "x", "2", "-var", "zpos", "1.5", + nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); lmp = lammps_open_no_mpi(argc, argv, nullptr); diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index f402ffc2e9..a1f9cf0006 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -29,10 +29,11 @@ protected: { const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", - "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; + "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER), + nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); lmp = lammps_open_no_mpi(argc, argv, nullptr); diff --git a/unittest/c-library/test_library_external.cpp b/unittest/c-library/test_library_external.cpp index 57d3bef080..9011ac19a8 100644 --- a/unittest/c-library/test_library_external.cpp +++ b/unittest/c-library/test_library_external.cpp @@ -64,9 +64,9 @@ static void callback(void *handle, step_t timestep, int nlocal, tag_t *, double TEST(lammps_external, callback) { - const char *args[] = {"liblammps", "-log", "none", "-nocite"}; + const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *handle = lammps_open_no_mpi(argc, argv, nullptr); @@ -131,9 +131,9 @@ TEST(lammps_external, callback) TEST(lammps_external, array) { - const char *args[] = {"liblammps", "-log", "none", "-nocite"}; + const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *handle = lammps_open_no_mpi(argc, argv, nullptr); diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 1609107ae0..f60105a229 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -34,9 +34,9 @@ TEST(MPI, global_box) int boxflag; ::testing::internal::CaptureStdout(); - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lammps_command(lmp, "units lj"); lammps_command(lmp, "atom_style atomic"); @@ -77,9 +77,9 @@ TEST(MPI, sub_box) int boxflag; ::testing::internal::CaptureStdout(); - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lammps_command(lmp, "units lj"); lammps_command(lmp, "atom_style atomic"); @@ -143,9 +143,9 @@ TEST(MPI, split_comm) MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; void *lmp = lammps_open(argc, argv, newcomm, nullptr); lammps_command(lmp, "units lj"); lammps_command(lmp, "atom_style atomic"); @@ -173,9 +173,9 @@ TEST(MPI, multi_partition) MPI_Comm_rank(MPI_COMM_WORLD, &me); const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "4x1", - "-echo", "screen", "-nocite", "-in", "none"}; + "-echo", "screen", "-nocite", "-in", "none", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lammps_command(lmp, "units lj"); @@ -205,9 +205,9 @@ protected: void SetUp() override { - const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; if (!verbose) ::testing::internal::CaptureStdout(); lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); InitSystem(); diff --git a/unittest/c-library/test_library_open.cpp b/unittest/c-library/test_library_open.cpp index 1cd65d843d..267f8e0978 100644 --- a/unittest/c-library/test_library_open.cpp +++ b/unittest/c-library/test_library_open.cpp @@ -39,9 +39,9 @@ TEST(lammps_open, null_args) TEST(lammps_open, with_args) { - const char *args[] = {"liblammps", "-log", "none", "-nocite"}; + const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; // MPI is already initialized MPI_Comm mycomm; @@ -78,9 +78,9 @@ TEST(lammps_open, with_args) TEST(lammps_open, with_kokkos) { if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); - const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none"}; + const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *alt_ptr; @@ -108,9 +108,9 @@ TEST(lammps_open, with_kokkos) TEST(lammps_open_no_mpi, no_screen) { - const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite"}; + const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *alt_ptr; @@ -139,9 +139,9 @@ TEST(lammps_open_no_mpi, with_omp) { if (!LAMMPS_NS::LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no", - "-sf", "omp", "-log", "none", "-nocite"}; + "-sf", "omp", "-log", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *alt_ptr; @@ -201,9 +201,9 @@ TEST(lammps_open_fortran, no_args) TEST(lammps_open_no_mpi, lammps_error) { - const char *args[] = {"liblammps", "-log", "none", "-nocite"}; + const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *alt_ptr; diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 14eab06213..1eace87f77 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -33,10 +33,11 @@ protected: { const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", - "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; + "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER), + nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); lmp = lammps_open_no_mpi(argc, argv, nullptr); @@ -554,10 +555,10 @@ protected: void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); lmp = lammps_open_no_mpi(argc, argv, nullptr); @@ -635,10 +636,10 @@ TEST(SystemSettings, kokkos) // clang-format off const char *args[] = {"SystemSettings", "-log", "none", "-echo", "screen", "-nocite", - "-k", "on", "t", "4", "-sf", "kk"}; + "-k", "on", "t", "4", "-sf", "kk", nullptr}; // clang-format on char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); void *lmp = lammps_open_no_mpi(argc, argv, nullptr); diff --git a/unittest/c-library/test_library_scatter_gather.cpp b/unittest/c-library/test_library_scatter_gather.cpp index ee672c9b86..0303a47337 100644 --- a/unittest/c-library/test_library_scatter_gather.cpp +++ b/unittest/c-library/test_library_scatter_gather.cpp @@ -32,10 +32,11 @@ protected: { const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", - "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; + "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER), + nullptr}; char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = (sizeof(args) / sizeof(char *)) - 1; ::testing::internal::CaptureStdout(); lmp = lammps_open_no_mpi(argc, argv, nullptr); diff --git a/unittest/commands/test_mpi_load_balancing.cpp b/unittest/commands/test_mpi_load_balancing.cpp index bc5f07beb1..efdee8c4eb 100644 --- a/unittest/commands/test_mpi_load_balancing.cpp +++ b/unittest/commands/test_mpi_load_balancing.cpp @@ -33,11 +33,9 @@ protected: void SetUp() override { - const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); InitSystem(); if (!verbose) ::testing::internal::GetCapturedStdout(); } diff --git a/unittest/cplusplus/test_input_class.cpp b/unittest/cplusplus/test_input_class.cpp index 6595c24695..708d3f7cae 100644 --- a/unittest/cplusplus/test_input_class.cpp +++ b/unittest/cplusplus/test_input_class.cpp @@ -8,6 +8,7 @@ #include #include +#include "../testing/utils.h" #include "gtest/gtest.h" const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box", @@ -21,9 +22,9 @@ protected: LAMMPS *lmp; Input_commands() { - const char *args[] = {"LAMMPS_test"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + const char * args[] = {"LAMMPS_test", nullptr}; + char ** argv = (char**)args; + int argc = 1; int flag; MPI_Initialized(&flag); @@ -33,13 +34,11 @@ protected: void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", - "-var", "zpos", "1.5", "-var", "x", "2"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", + "-var", "zpos", "1.5", "-var", "x", "2"}; ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS ("); } diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 64ce1eefb1..6f279fc96c 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -21,9 +21,9 @@ protected: LAMMPS *lmp; LAMMPS_plain() : lmp(nullptr) { - const char *args[] = {"LAMMPS_test"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + const char * args[] = {"LAMMPS_test", nullptr}; + char ** argv = (char**)args; + int argc = 1; int flag; MPI_Initialized(&flag); @@ -34,12 +34,10 @@ protected: void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"}; ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, StartsWith("LAMMPS (")); } @@ -159,9 +157,9 @@ protected: LAMMPS *lmp; LAMMPS_omp() : lmp(nullptr) { - const char *args[] = {"LAMMPS_test"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + const char * args[] = {"LAMMPS_test", nullptr}; + char ** argv = (char**)args; + int argc = 1; int flag; MPI_Initialized(&flag); @@ -172,15 +170,13 @@ protected: void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen", - "-pk", "omp", "2", "neigh", "yes", "-sf", "omp"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen", + "-pk", "omp", "2", "neigh", "yes", "-sf", "omp"}; // only run this test fixture with omp suffix if OPENMP package is installed if (LAMMPS::is_installed_pkg("OPENMP")) - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); else GTEST_SKIP(); } @@ -242,9 +238,9 @@ protected: LAMMPS *lmp; LAMMPS_kokkos() : lmp(nullptr) { - const char *args[] = {"LAMMPS_test"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + const char * args[] = {"LAMMPS_test", nullptr}; + char ** argv = (char**)args; + int argc = 1; int flag; MPI_Initialized(&flag); @@ -255,15 +251,13 @@ protected: void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none", - "-k", "on", "t", "1", "-sf", "kk"}; + LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none", + "-k", "on", "t", "1", "-sf", "kk"}; if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[10] = "2"; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); if (LAMMPS::is_installed_pkg("KOKKOS")) { ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); ::testing::internal::GetCapturedStdout(); } else GTEST_SKIP(); @@ -333,12 +327,10 @@ TEST(LAMMPS_init, OpenMP) fputs("\n", fp); fclose(fp); - const char *args[] = {"LAMMPS_init", "-in", "in.lammps_empty", "-log", "none", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"LAMMPS_init", "-in", "in.lammps_empty", "-log", "none", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, ContainsRegex(".*using 2 OpenMP thread.*per MPI task.*")); @@ -366,12 +358,10 @@ TEST(LAMMPS_init, NoOpenMP) fclose(fp); platform::unsetenv("OMP_NUM_THREADS"); - const char *args[] = {"LAMMPS_init", "-in", "in.lammps_class_noomp", "-log", "none", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"LAMMPS_init", "-in", "in.lammps_class_noomp", "-log", "none", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, ContainsRegex( ".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index e9f4a3f7fc..3476ae8dde 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -26,6 +26,7 @@ #include "angle.h" #include "atom.h" #include "compute.h" +#include "exceptions.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -59,11 +60,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -90,7 +91,21 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // utility lambdas to improve readability auto command = [&](const std::string &line) { - lmp->input->one(line); + try { + lmp->input->one(line); + } catch (LAMMPSAbortException &ae) { + fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); + exit(2); + } catch (LAMMPSException &e) { + fprintf(stderr, "LAMMPS Error: %s\n", e.what()); + exit(3); + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + exit(4); + } catch (std::exception &e) { + fprintf(stderr, "General exception: %s\n", e.what()); + exit(5); + } }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -211,11 +226,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -303,13 +316,10 @@ TEST(AngleStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -358,7 +368,7 @@ TEST(AngleStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -422,14 +432,11 @@ TEST(AngleStyle, omp) if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -482,7 +489,7 @@ TEST(AngleStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -525,14 +532,11 @@ TEST(AngleStyle, single) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -672,13 +676,10 @@ TEST(AngleStyle, extract) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index c723541366..f7ecd835b0 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -26,6 +26,7 @@ #include "atom.h" #include "bond.h" #include "compute.h" +#include "exceptions.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -59,11 +60,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -90,7 +91,21 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // utility lambdas to improve readability auto command = [&](const std::string &line) { - lmp->input->one(line); + try { + lmp->input->one(line); + } catch (LAMMPSAbortException &ae) { + fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); + exit(2); + } catch (LAMMPSException &e) { + fprintf(stderr, "LAMMPS Error: %s\n", e.what()); + exit(3); + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + exit(4); + } catch (std::exception &e) { + fprintf(stderr, "General exception: %s\n", e.what()); + exit(5); + } }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -211,11 +226,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -303,13 +316,10 @@ TEST(BondStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -358,7 +368,7 @@ TEST(BondStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -424,14 +434,11 @@ TEST(BondStyle, omp) if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -484,7 +491,7 @@ TEST(BondStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -527,14 +534,11 @@ TEST(BondStyle, single) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -785,13 +789,10 @@ TEST(BondStyle, extract) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 2039155644..662d63909d 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -26,6 +26,7 @@ #include "atom.h" #include "compute.h" #include "dihedral.h" +#include "exceptions.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -59,11 +60,9 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) { - LAMMPS *lmp; - - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -90,7 +89,21 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // utility lambdas to improve readability auto command = [&](const std::string &line) { - lmp->input->one(line); + try { + lmp->input->one(line); + } catch (LAMMPSAbortException &ae) { + fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); + exit(2); + } catch (LAMMPSException &e) { + fprintf(stderr, "LAMMPS Error: %s\n", e.what()); + exit(3); + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + exit(4); + } catch (std::exception &e) { + fprintf(stderr, "General exception: %s\n", e.what()); + exit(5); + } }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -220,11 +233,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -306,13 +317,10 @@ TEST(DihedralStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -361,7 +369,7 @@ TEST(DihedralStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -427,14 +435,11 @@ TEST(DihedralStyle, omp) if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -488,7 +493,7 @@ TEST(DihedralStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index b65eab2049..2d2c2fa0b8 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -61,11 +61,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use_respa = false) +LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool use_respa = false) { LAMMPS *lmp; - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -169,11 +169,8 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg, bool use_rmass, bool use void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"FixIntegrate", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS::argv args = {"FixIntegrate", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -252,13 +249,10 @@ TEST(FixTimestep, plain) if (test_config.skip_tests.count("static")) GTEST_SKIP(); #endif - const char *args[] = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -420,7 +414,7 @@ TEST(FixTimestep, plain) if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp = init_lammps(argc, argv, test_config, true); + lmp = init_lammps(args, test_config, true); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -554,14 +548,12 @@ TEST(FixTimestep, omp) if (test_config.skip_tests.count("static")) GTEST_SKIP(); #endif - const char *args[] = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; + LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -723,7 +715,7 @@ TEST(FixTimestep, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp = init_lammps(argc, argv, test_config, true); + lmp = init_lammps(args, test_config, true); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 259bd9008d..dc1b846b5a 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -25,6 +25,7 @@ #include "atom.h" #include "compute.h" +#include "exceptions.h" #include "fmt/format.h" #include "force.h" #include "improper.h" @@ -59,11 +60,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -90,7 +91,21 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // utility lambdas to improve readability auto command = [&](const std::string &line) { - lmp->input->one(line); + try { + lmp->input->one(line); + } catch (LAMMPSAbortException &ae) { + fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); + exit(2); + } catch (LAMMPSException &e) { + fprintf(stderr, "LAMMPS Error: %s\n", e.what()); + exit(3); + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + exit(4); + } catch (std::exception &e) { + fprintf(stderr, "General exception: %s\n", e.what()); + exit(5); + } }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -211,11 +226,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -297,13 +310,10 @@ TEST(ImproperStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -352,7 +362,7 @@ TEST(ImproperStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -418,14 +428,11 @@ TEST(ImproperStyle, omp) if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -479,7 +486,7 @@ TEST(ImproperStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index f44a6e61d3..9db9c7ac8b 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -26,6 +26,7 @@ #include "atom.h" #include "compute.h" #include "domain.h" +#include "exceptions.h" #include "force.h" #include "info.h" #include "input.h" @@ -61,11 +62,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) { LAMMPS *lmp; - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(args, MPI_COMM_WORLD); // check if prerequisite styles are available Info *info = new Info(lmp); @@ -92,8 +93,23 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new // utility lambdas to improve readability auto command = [&](const std::string &line) { - lmp->input->one(line); + try { + lmp->input->one(line); + } catch (LAMMPSAbortException &ae) { + fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); + exit(2); + } catch (LAMMPSException &e) { + fprintf(stderr, "LAMMPS Error: %s\n", e.what()); + exit(3); + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + exit(4); + } catch (std::exception &e) { + fprintf(stderr, "General exception: %s\n", e.what()); + exit(5); + } }; + auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); }; @@ -225,11 +241,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - LAMMPS *lmp = init_lammps(argc, argv, config); + LAMMPS *lmp = init_lammps(args, config); if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -323,13 +337,10 @@ TEST(PairStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -388,7 +399,7 @@ TEST(PairStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton pair is forced to be on @@ -469,7 +480,7 @@ TEST(PairStyle, plain) if (pair->respa_enable) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2"); run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -501,17 +512,14 @@ TEST(PairStyle, omp) if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "omp", "4", "-sf", "omp"}; + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "omp", "4", "-sf", "omp"}; // cannot run dpd styles with more than 1 thread due to using multiple pRNGs if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1"; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -570,7 +578,7 @@ TEST(PairStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; @@ -626,8 +634,8 @@ TEST(PairStyle, kokkos_omp) if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", - "-k", "on", "t", "4", "-sf", "kk"}; + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-k", "on", "t", "4", "-sf", "kk"}; // cannot run dpd styles in plain or hybrid with more than 1 thread due to using multiple pRNGs if (utils::strmatch(test_config.pair_style, "^dpd") || @@ -642,11 +650,8 @@ TEST(PairStyle, kokkos_omp) utils::strmatch(test_config.pair_style, " pace")) args[9] = "1"; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -704,7 +709,7 @@ TEST(PairStyle, kokkos_omp) if (lmp->force->newton_pair == 0) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(argc, argv, test_config, false); + lmp = init_lammps(args, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; @@ -767,22 +772,19 @@ TEST(PairStyle, gpu) (!Info::has_fft_single_support())) GTEST_SKIP(); - const char *args_neigh[] = {"PairStyle", "-log", "none", "-echo", - "screen", "-nocite", "-sf", "gpu"}; - const char *args_noneigh[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", - "gpu", "-pk", "gpu", "0", "neigh", "no"}; - - char **argv = (char **)args_neigh; - int argc = sizeof(args_neigh) / sizeof(char *); + LAMMPS::argv args_neigh = {"PairStyle", "-log", "none", "-echo", + "screen", "-nocite", "-sf", "gpu"}; + LAMMPS::argv args_noneigh = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", + "gpu", "-pk", "gpu", "0", "neigh", "no"}; + LAMMPS::argv args = args_neigh; // cannot use GPU neighbor list with hybrid pair style (yet) if (test_config.pair_style.substr(0, 6) == "hybrid") { - argv = (char **)args_noneigh; - argc = sizeof(args_noneigh) / sizeof(char *); + args = args_noneigh; } ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, false); + LAMMPS *lmp = init_lammps(args, test_config, false); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -854,18 +856,15 @@ TEST(PairStyle, intel) if (!LAMMPS::is_installed_pkg("INTEL")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", - "-pk", "intel", "0", "mode", "double", "omp", - "4", "lrt", "no", "-sf", "intel"}; + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", + "-pk", "intel", "0", "mode", "double", "omp", + "4", "lrt", "no", "-sf", "intel"}; // cannot use more than 1 thread for dpd styles due to pRNG if (utils::strmatch(test_config.pair_style, "^dpd")) args[12] = "1"; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -942,13 +941,10 @@ TEST(PairStyle, opt) if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -1025,17 +1021,14 @@ TEST(PairStyle, single) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; // need to add this dependency test_config.prerequisites.emplace_back("atom", "full"); // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config); + LAMMPS *lmp = init_lammps(args, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -1276,13 +1269,10 @@ TEST(PairStyle, extract) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + LAMMPS *lmp = init_lammps(args, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { diff --git a/unittest/fortran/wrap_extract_variable.cpp b/unittest/fortran/wrap_extract_variable.cpp index 1082a381bb..8c81897c0a 100644 --- a/unittest/fortran/wrap_extract_variable.cpp +++ b/unittest/fortran/wrap_extract_variable.cpp @@ -71,10 +71,10 @@ protected: // clang-format off const char *args[] = { "LAMMPS_Fortran_test", "-l", "none", "-echo", "screen", "-nocite", - "-var", "input_dir", input_dir, "-var", "zpos", "1.5", "-var", "x", "2" }; + "-var", "input_dir", input_dir, "-var", "zpos", "1.5", "-var", "x", "2", nullptr }; // clang-format on char **argv = (char **)args; - int argc = sizeof(args) / sizeof(const char *); + int argc = (sizeof(args) / sizeof(const char *)) - 1; ::testing::internal::CaptureStdout(); lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_c_args(argc, argv); diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 272d1d21c5..6e7feb4409 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -115,31 +115,21 @@ public: } protected: - std::string testbinary = "LAMMPSTest"; - std::vector args = {"-log", "none", "-echo", "screen", "-nocite"}; + std::string testbinary = "LAMMPSTest"; + LAMMPS::argv args = {"-log", "none", "-echo", "screen", "-nocite"}; LAMMPS *lmp; Info *info; void SetUp() override { - int argc = args.size() + 1; - char **argv = new char *[argc]; - argv[0] = LAMMPS_NS::utils::strdup(testbinary); - for (int i = 1; i < argc; i++) { - argv[i] = LAMMPS_NS::utils::strdup(args[i - 1]); - } + LAMMPS::argv full_args = {testbinary}; + full_args.insert(full_args.end(), args.begin(), args.end()); HIDE_OUTPUT([&] { - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + lmp = new LAMMPS(full_args, MPI_COMM_WORLD); info = new Info(lmp); }); InitSystem(); - - for (int i = 0; i < argc; i++) { - delete[] argv[i]; - argv[i] = nullptr; - } - delete[] argv; } virtual void InitSystem() {}