diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 51d45e6b6c..35ec32e544 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -27,6 +27,7 @@ jobs: run: | python3 -m pip install numpy cmake -C cmake/presets/windows.cmake \ + -D PKG_PYTHON=on \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ -D LAMMPS_EXCEPTIONS=on \ diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index cd6728bc10..3f409c3820 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -359,11 +359,13 @@ if(BUILD_OMP) ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts. # Intel 18.0 was tested to support both, so we switch to OpenMP 4+ from 19.x onward to be safe. - target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=4) + set(LAMMPS_OMP_COMPAT_LEVEL 4) else() - target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=3) + set(LAMMPS_OMP_COMPAT_LEVEL 3) endif() + target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=${LAMMPS_OMP_COMPAT_LEVEL}) target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX) + target_link_libraries(lmp PRIVATE OpenMP::OpenMP_CXX) endif() if(PKG_MSCG OR PKG_ATC OR PKG_AWPMD OR PKG_ML-QUIP OR PKG_LATTE) @@ -738,7 +740,7 @@ install( if(BUILD_SHARED_LIBS) if(CMAKE_VERSION VERSION_LESS 3.12) # adjust so we find Python 3 versions before Python 2 on old systems with old CMake - set(Python_ADDITIONAL_VERSIONS 3.10 3.9 3.8 3.7 3.6 3.5) + set(Python_ADDITIONAL_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7 3.6) find_package(PythonInterp) # Deprecated since version 3.12 if(PYTHONINTERP_FOUND) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) diff --git a/cmake/CMakeSettings.json b/cmake/CMakeSettings.json index ee4b3c46d5..9320341ec4 100644 --- a/cmake/CMakeSettings.json +++ b/cmake/CMakeSettings.json @@ -6,7 +6,7 @@ "configurationType": "Debug", "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${workspaceRoot}\\install\\${name}", - "cmakeCommandArgs": "-S ${workspaceRoot}\\cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DENABLE_TESTING=on", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake", "buildCommandArgs": "", "ctestCommandArgs": "", "inheritEnvironments": [ "msvc_x64_x64" ], @@ -25,6 +25,54 @@ "name": "LAMMPS_EXCEPTIONS", "value": "True", "type": "BOOL" + }, + { + "name": "PKG_PYTHON", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" + } + ] + }, + { + "name": "x64-Release-MSVC", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${workspaceRoot}\\install\\${name}", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [ + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_TOOLS", + "value": "True", + "type": "BOOL" + }, + { + "name": "LAMMPS_EXCEPTIONS", + "value": "True", + "type": "BOOL" + }, + { + "name": "PKG_PYTHON", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" } ] }, @@ -34,11 +82,16 @@ "configurationType": "Debug", "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${workspaceRoot}\\install\\${name}", - "cmakeCommandArgs": "-S ${workspaceRoot}\\cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DENABLE_TESTING=on", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake", "buildCommandArgs": "", "ctestCommandArgs": "", "inheritEnvironments": [ "clang_cl_x64" ], "variables": [ + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, { "name": "BUILD_TOOLS", "value": "True", @@ -48,6 +101,16 @@ "name": "LAMMPS_EXCEPTIONS", "value": "True", "type": "BOOL" + }, + { + "name": "PKG_PYTHON", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" } ] }, @@ -57,7 +120,7 @@ "configurationType": "Debug", "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${workspaceRoot}\\install\\${name}", - "cmakeCommandArgs": "-S ${workspaceRoot}\\cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DENABLE_TESTING=on -DCMAKE_CXX_COMPILER=icx -DCMAKE_C_COMPILER=icx -DBUILD_MPI=off", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DCMAKE_CXX_COMPILER=icx -DCMAKE_C_COMPILER=icx", "buildCommandArgs": "", "ctestCommandArgs": "", "inheritEnvironments": [ "msvc_x64_x64" ], @@ -76,6 +139,21 @@ "name": "LAMMPS_EXCEPTIONS", "value": "True", "type": "BOOL" + }, + { + "name": "PKG_PYTHON", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_MPI", + "value": "False", + "type": "BOOL" } ] }, @@ -85,7 +163,7 @@ "configurationType": "Debug", "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${workspaceRoot}\\install\\${name}", - "cmakeCommandArgs": "-S ${workspaceRoot}\\cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DENABLE_TESTING=off -DCMAKE_CXX_COMPILER=icl -DCMAKE_C_COMPILER=icl -DCMAKE_Fortran_COMPILER=ifort -DBUILD_MPI=off", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DCMAKE_CXX_COMPILER=icl -DCMAKE_C_COMPILER=icl -DCMAKE_Fortran_COMPILER=ifort", "buildCommandArgs": "", "ctestCommandArgs": "", "inheritEnvironments": [ "msvc_x64_x64" ], @@ -104,8 +182,23 @@ "name": "LAMMPS_EXCEPTIONS", "value": "True", "type": "BOOL" + }, + { + "name": "PKG_PYTHON", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "False", + "type": "BOOL" + }, + { + "name": "BUILD_MPI", + "value": "False", + "type": "BOOL" } ] } ] -} \ No newline at end of file +} diff --git a/cmake/Modules/FindCythonize.cmake b/cmake/Modules/FindCythonize.cmake index 9a37904ea7..2a4cc753e8 100644 --- a/cmake/Modules/FindCythonize.cmake +++ b/cmake/Modules/FindCythonize.cmake @@ -8,18 +8,19 @@ #============================================================================= if(CMAKE_VERSION VERSION_LESS 3.12) + set(Python_ADDITIONAL_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7 3.6) find_package(PythonInterp 3.6 QUIET) # Deprecated since version 3.12 if(PYTHONINTERP_FOUND) - set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) endif() else() - find_package(Python3 3.6 COMPONENTS Interpreter QUIET) + find_package(Python 3.6 COMPONENTS Interpreter QUIET) endif() # Use the Cython executable that lives next to the Python executable # if it is a local installation. -if(Python3_EXECUTABLE) - get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) +if(Python_EXECUTABLE) + get_filename_component(_python_path ${Python_EXECUTABLE} PATH) find_program(Cythonize_EXECUTABLE NAMES cythonize3 cythonize cythonize.bat HINTS ${_python_path}) diff --git a/cmake/Modules/Packages/COMPRESS.cmake b/cmake/Modules/Packages/COMPRESS.cmake index 887dfb88a6..bdcf1aa3f8 100644 --- a/cmake/Modules/Packages/COMPRESS.cmake +++ b/cmake/Modules/Packages/COMPRESS.cmake @@ -1,10 +1,11 @@ find_package(ZLIB REQUIRED) target_link_libraries(lammps PRIVATE ZLIB::ZLIB) -find_package(PkgConfig REQUIRED) -pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) - -if(Zstd_FOUND) +find_package(PkgConfig QUIET) +if(PkgConfig_FOUND) + pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) + if(Zstd_FOUND) target_compile_definitions(lammps PRIVATE -DLAMMPS_ZSTD) target_link_libraries(lammps PRIVATE PkgConfig::Zstd) + endif() endif() diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index ebc5adff5b..bccfdf7243 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -11,8 +11,14 @@ if(Kokkos_ENABLE_CUDA) endif() # Adding OpenMP compiler flags without the checks done for # BUILD_OMP can result in compile failures. Enforce consistency. -if(Kokkos_ENABLE_OPENMP AND NOT BUILD_OMP) - message(FATAL_ERROR "Must enable BUILD_OMP with Kokkos_ENABLE_OPENMP") +if(Kokkos_ENABLE_OPENMP) + if(NOT BUILD_OMP) + message(FATAL_ERROR "Must enable BUILD_OMP with Kokkos_ENABLE_OPENMP") + else() + if(LAMMPS_OMP_COMPAT_LEVEL LESS 4) + message(FATAL_ERROR "Compiler must support OpenMP 4.0 or later with Kokkos_ENABLE_OPENMP") + endif() + endif() endif() ######################################################################## @@ -27,6 +33,8 @@ if(DOWNLOAD_KOKKOS) endforeach() message(STATUS "KOKKOS download requested - we will build our own") list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_INSTALL_PREFIX=") + # build KOKKOS downloaded libraries as static libraries but with PIC, if needed + list(APPEND KOKKOS_LIB_BUILD_ARGS "-DBUILD_SHARED_LIBS=OFF") if(CMAKE_REQUEST_PIC) list(APPEND KOKKOS_LIB_BUILD_ARGS ${CMAKE_REQUEST_PIC}) endif() @@ -47,18 +55,22 @@ if(DOWNLOAD_KOKKOS) URL ${KOKKOS_URL} URL_MD5 ${KOKKOS_MD5} CMAKE_ARGS ${KOKKOS_LIB_BUILD_ARGS} - BUILD_BYPRODUCTS /lib/libkokkoscore.a + BUILD_BYPRODUCTS /lib/libkokkoscore.a /lib/libkokkoscontainers.a ) ExternalProject_get_property(kokkos_build INSTALL_DIR) file(MAKE_DIRECTORY ${INSTALL_DIR}/include) - add_library(LAMMPS::KOKKOS UNKNOWN IMPORTED) - set_target_properties(LAMMPS::KOKKOS PROPERTIES + add_library(LAMMPS::KOKKOSCORE UNKNOWN IMPORTED) + add_library(LAMMPS::KOKKOSCONTAINERS UNKNOWN IMPORTED) + set_target_properties(LAMMPS::KOKKOSCORE PROPERTIES IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscore.a" INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include" INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) - target_link_libraries(lammps PRIVATE LAMMPS::KOKKOS) - target_link_libraries(lmp PRIVATE LAMMPS::KOKKOS) - add_dependencies(LAMMPS::KOKKOS kokkos_build) + set_target_properties(LAMMPS::KOKKOSCONTAINERS PROPERTIES + IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscontainers.a") + target_link_libraries(lammps PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS) + target_link_libraries(lmp PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS) + add_dependencies(LAMMPS::KOKKOSCORE kokkos_build) + add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build) elseif(EXTERNAL_KOKKOS) find_package(Kokkos 3.5.00 REQUIRED CONFIG) target_link_libraries(lammps PRIVATE Kokkos::kokkos) @@ -66,8 +78,14 @@ elseif(EXTERNAL_KOKKOS) else() set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos) set(LAMMPS_LIB_KOKKOS_BIN_DIR ${LAMMPS_LIB_BINARY_DIR}/kokkos) + # build KOKKOS internal libraries as static libraries but with PIC, if needed + set(BUILD_SHARED_LIBS OFF) + if(CMAKE_REQUEST_PIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() add_subdirectory(${LAMMPS_LIB_KOKKOS_SRC_DIR} ${LAMMPS_LIB_KOKKOS_BIN_DIR}) + set(Kokkos_INCLUDE_DIRS ${LAMMPS_LIB_KOKKOS_SRC_DIR}/core/src ${LAMMPS_LIB_KOKKOS_SRC_DIR}/containers/src ${LAMMPS_LIB_KOKKOS_SRC_DIR}/algorithms/src diff --git a/cmake/Modules/Packages/ML-HDNNP.cmake b/cmake/Modules/Packages/ML-HDNNP.cmake index e27b3a1410..5a4c287fa2 100644 --- a/cmake/Modules/Packages/ML-HDNNP.cmake +++ b/cmake/Modules/Packages/ML-HDNNP.cmake @@ -46,12 +46,10 @@ if(DOWNLOAD_N2P2) if((CMAKE_SYSTEM_NAME STREQUAL Windows) AND CMAKE_CROSSCOMPILING) get_target_property(N2P2_MPI_INCLUDE MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES) set(N2P2_PROJECT_OPTIONS "-I${N2P2_MPI_INCLUDE}") - set(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") get_target_property(N2P2_MPI_INCLUDE MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES) set(N2P2_PROJECT_OPTIONS "-I${N2P2_MPI_INCLUDE}") - set(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) endif() endif() @@ -64,8 +62,8 @@ if(DOWNLOAD_N2P2) string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) set(N2P2_BUILD_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}} ${N2P2_CXX_STD}") set(N2P2_BUILD_OPTIONS INTERFACES=LAMMPS COMP=${N2P2_COMP} "PROJECT_OPTIONS=${N2P2_PROJECT_OPTIONS}" "PROJECT_DEBUG=" - "PROJECT_CC=${CMAKE_CXX_COMPILER}" "PROJECT_MPICC=${MPI_CXX_COMPILER}" "PROJECT_CFLAGS=${N2P2_BUILD_FLAGS}" - "PROJECT_AR=${N2P2_AR}") + "PROJECT_CC=${CMAKE_CXX_COMPILER}" "PROJECT_MPICC=${CMAKE_CXX_COMPILER}" "PROJECT_CFLAGS=${N2P2_BUILD_FLAGS}" + "PROJECT_AR=${N2P2_AR}" "APP_CORE=nnp-convert" "APP_TRAIN=nnp-train" "APP=nnp-convert") # echo final flag for debugging message(STATUS "N2P2 BUILD OPTIONS: ${N2P2_BUILD_OPTIONS}") diff --git a/doc/src/Developer_utils.rst b/doc/src/Developer_utils.rst index a9969b7543..7172f81eb7 100644 --- a/doc/src/Developer_utils.rst +++ b/doc/src/Developer_utils.rst @@ -205,6 +205,9 @@ Convenience functions .. doxygenfunction:: logmesg(LAMMPS *lmp, const std::string &mesg) :project: progguide +.. doxygenfunction:: flush_buffers(LAMMPS *lmp) + :project: progguide + .. doxygenfunction:: getsyserror :project: progguide diff --git a/doc/src/Howto_pylammps.rst b/doc/src/Howto_pylammps.rst index e6d3d7b91d..6c788e2365 100644 --- a/doc/src/Howto_pylammps.rst +++ b/doc/src/Howto_pylammps.rst @@ -545,6 +545,6 @@ Feedback and Contributing ------------------------- If you find this Python interface useful, please feel free to provide feedback -and ideas on how to improve it to Richard Berger (richard.berger@temple.edu). We also +and ideas on how to improve it to Richard Berger (richard.berger@outlook.com). We also want to encourage people to write tutorial style IPython notebooks showcasing LAMMPS usage and maybe their latest research results. diff --git a/doc/src/Intro_authors.rst b/doc/src/Intro_authors.rst index fc609e12cf..a0902ccda1 100644 --- a/doc/src/Intro_authors.rst +++ b/doc/src/Intro_authors.rst @@ -8,7 +8,7 @@ University: * Aidan Thompson, athomps at sandia.gov * Stan Moore, stamoor at sandia.gov * Axel Kohlmeyer, akohlmey at gmail.com -* Richard Berger, richard.berger at temple.edu +* Richard Berger, richard.berger at outlook.com .. _sjp: http://www.cs.sandia.gov/~sjplimp .. _lws: https://www.lammps.org diff --git a/doc/src/Library_utility.rst b/doc/src/Library_utility.rst index 32fac6bcc8..da64e3b8f0 100644 --- a/doc/src/Library_utility.rst +++ b/doc/src/Library_utility.rst @@ -13,6 +13,7 @@ functions. They do not directly call the LAMMPS library. - :cpp:func:`lammps_fix_external_set_virial_peratom` - :cpp:func:`lammps_fix_external_set_vector_length` - :cpp:func:`lammps_fix_external_set_vector` +- :cpp:func:`lammps_flush_buffers` - :cpp:func:`lammps_free` - :cpp:func:`lammps_is_running` - :cpp:func:`lammps_force_timeout` @@ -72,6 +73,11 @@ where such memory buffers were allocated that require the use of ----------------------- +.. doxygenfunction:: lammps_flush_buffers + :project: progguide + +----------------------- + .. doxygenfunction:: lammps_free :project: progguide diff --git a/doc/src/Tools.rst b/doc/src/Tools.rst index 0d8ffa3f45..0788a27623 100644 --- a/doc/src/Tools.rst +++ b/doc/src/Tools.rst @@ -278,16 +278,20 @@ eam database tool ----------------------------- The tools/eam_database directory contains a Fortran program that will -generate EAM alloy setfl potential files for any combination of 16 +generate EAM alloy setfl potential files for any combination of 17 elements: Cu, Ag, Au, Ni, Pd, Pt, Al, Pb, Fe, Mo, Ta, W, Mg, Co, Ti, -Zr. The files can then be used with the :doc:`pair_style eam/alloy ` command. +Zr, Cr. The files can then be used with the :doc:`pair_style eam/alloy ` command. The tool is authored by Xiaowang Zhou (Sandia), xzhou at sandia.gov, -and is based on his paper: +with updates from Lucas Hale (NIST) lucas.hale at nist.gov and is based on his paper: X. W. Zhou, R. A. Johnson, and H. N. G. Wadley, Phys. Rev. B, 69, 144113 (2004). +The parameters for Cr were taken from: + +Lin Z B, Johnson R A and Zhigilei L V, Phys. Rev. B 77 214108 (2008). + ---------- .. _eamgn: diff --git a/doc/utils/check-styles.py b/doc/utils/check-styles.py index 2ad75aeeda..4294f5a5bc 100755 --- a/doc/utils/check-styles.py +++ b/doc/utils/check-styles.py @@ -259,7 +259,7 @@ skip_pair = ('meam/c','lj/sf','reax/c') counter = 0 -counter += check_style('Commands_all.rst', doc_dir, ":doc:`(.+) <.+>`",command,'Command',suffix=False) +counter += check_style('Commands_all.rst', doc_dir, ":doc:`(.+) <.+>`",command,'Command',suffix=True) counter += check_style('Commands_compute.rst', doc_dir, ":doc:`(.+) `",compute,'Compute',suffix=True) counter += check_style('compute.rst', doc_dir, ":doc:`(.+) ` -",compute,'Compute',suffix=False) counter += check_style('Commands_fix.rst', doc_dir, ":doc:`(.+) `",fix,'Fix',skip=skip_fix,suffix=True) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 408a20f179..1d4c27822b 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1012,6 +1012,7 @@ fexternal Fexternal ffield ffl +fflush ffmpeg FFmpeg ffplay diff --git a/lib/kokkos/core/src/desul/atomics/Generic.hpp b/lib/kokkos/core/src/desul/atomics/Generic.hpp index 9d5e87ece2..19d7a453fa 100644 --- a/lib/kokkos/core/src/desul/atomics/Generic.hpp +++ b/lib/kokkos/core/src/desul/atomics/Generic.hpp @@ -10,8 +10,10 @@ SPDX-License-Identifier: (BSD-3-Clause) #define DESUL_ATOMICS_GENERIC_HPP_ #include +#if defined(__GNUC__) && (!defined(__clang__)) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif #include "desul/atomics/Common.hpp" #include "desul/atomics/Compare_Exchange.hpp" #include "desul/atomics/Lock_Array.hpp" @@ -686,5 +688,7 @@ DESUL_INLINE_FUNCTION bool atomic_compare_exchange_weak(T* const dest, #include #include #include +#if defined(__GNUC__) && (!defined(__clang__)) #pragma GCC diagnostic pop #endif +#endif diff --git a/lib/kokkos/core/src/impl/Kokkos_Core.cpp b/lib/kokkos/core/src/impl/Kokkos_Core.cpp index a1f9d33632..00d6b5850b 100644 --- a/lib/kokkos/core/src/impl/Kokkos_Core.cpp +++ b/lib/kokkos/core/src/impl/Kokkos_Core.cpp @@ -58,7 +58,7 @@ #ifndef _WIN32 #include #else -#include +#include #endif //---------------------------------------------------------------------------- diff --git a/python/lammps/core.py b/python/lammps/core.py index 62b0f5d8b6..d934ee1baa 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -164,6 +164,7 @@ class lammps(object): self.lib.lammps_open.restype = c_void_p self.lib.lammps_open_no_mpi.restype = c_void_p self.lib.lammps_close.argtypes = [c_void_p] + self.lib.lammps_flush_buffers.argtypes = [c_void_p] self.lib.lammps_free.argtypes = [c_void_p] self.lib.lammps_file.argtypes = [c_void_p, c_char_p] @@ -1118,6 +1119,16 @@ class lammps(object): # ------------------------------------------------------------------------- + def flush_buffers(self): + """Flush output buffers + + This is a wrapper around the :cpp:func:`lammps_flush_buffers` + function of the C-library interface. + """ + self.lib.lammps_flush_buffers(self.lmp) + + # ------------------------------------------------------------------------- + def set_variable(self,name,value): """Set a new value for a LAMMPS string style variable diff --git a/python/lammps/numpy_wrapper.py b/python/lammps/numpy_wrapper.py index 20ec85d001..3619728081 100644 --- a/python/lammps/numpy_wrapper.py +++ b/python/lammps/numpy_wrapper.py @@ -92,7 +92,7 @@ class numpy_wrapper: if dim == LAMMPS_AUTODETECT: if dtype in (LAMMPS_INT_2D, LAMMPS_DOUBLE_2D, LAMMPS_INT64_2D): # TODO add other fields - if name in ("x", "v", "f", "x0", "omega", "angmom", "torque", "vforce", "vest"): + if name in ("x", "v", "f", "x0","omega", "angmom", "torque", "csforce", "vforce", "vest"): dim = 3 elif name == "smd_data_9": dim = 9 diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index abd4d6da98..cdb6620c27 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -20,47 +20,47 @@ from __future__ import print_function +import io import os import re -import select +import sys +import tempfile from collections import namedtuple from .core import lammps +# ------------------------------------------------------------------------- class OutputCapture(object): """ Utility class to capture LAMMPS library output """ - def __init__(self): - self.stdout_pipe_read, self.stdout_pipe_write = os.pipe() self.stdout_fd = 1 + self.captured_output = "" def __enter__(self): - self.stdout = os.dup(self.stdout_fd) - os.dup2(self.stdout_pipe_write, self.stdout_fd) + self.tmpfile = tempfile.TemporaryFile(mode='w+b') + + sys.stdout.flush() + + # make copy of original stdout + self.stdout_orig = os.dup(self.stdout_fd) + + # replace stdout and redirect to temp file + os.dup2(self.tmpfile.fileno(), self.stdout_fd) return self def __exit__(self, exc_type, exc_value, traceback): - os.dup2(self.stdout, self.stdout_fd) - os.close(self.stdout) - os.close(self.stdout_pipe_read) - os.close(self.stdout_pipe_write) - - # check if we have more to read from the pipe - def more_data(self, pipe): - r, _, _ = select.select([pipe], [], [], 0) - return bool(r) - - # read the whole pipe - def read_pipe(self, pipe): - out = "" - while self.more_data(pipe): - out += os.read(pipe, 1024).decode() - return out + os.dup2(self.stdout_orig, self.stdout_fd) + os.close(self.stdout_orig) + self.tmpfile.close() @property def output(self): - return self.read_pipe(self.stdout_pipe_read) + sys.stdout.flush() + self.tmpfile.flush() + self.tmpfile.seek(0, io.SEEK_SET) + self.captured_output = self.tmpfile.read().decode('utf-8') + return self.captured_output # ------------------------------------------------------------------------- @@ -109,9 +109,9 @@ class AtomList(object): """ if index not in self._loaded: if self.dimensions == 2: - atom = Atom2D(self._pylmp, index + 1) + atom = Atom2D(self._pylmp, index) else: - atom = Atom(self._pylmp, index + 1) + atom = Atom(self._pylmp, index) self._loaded[index] = atom return self._loaded[index] @@ -134,6 +134,12 @@ class Atom(object): def __dir__(self): return [k for k in super().__dir__() if not k.startswith('_')] + def get(self, name, index): + prop = self._pylmp.lmp.numpy.extract_atom(name) + if prop is not None: + return prop[index] + return None + @property def id(self): """ @@ -141,7 +147,7 @@ class Atom(object): :type: int """ - return int(self._pylmp.eval("id[%d]" % self.index)) + return self.get("id", self.index) @property def type(self): @@ -150,7 +156,7 @@ class Atom(object): :type: int """ - return int(self._pylmp.eval("type[%d]" % self.index)) + return self.get("type", self.index) @property def mol(self): @@ -159,7 +165,7 @@ class Atom(object): :type: int """ - return self._pylmp.eval("mol[%d]" % self.index) + return self.get("mol", self.index) @property def mass(self): @@ -168,52 +174,114 @@ class Atom(object): :type: float """ - return self._pylmp.eval("mass[%d]" % self.index) + return self.get("mass", self.index) + + @property + def radius(self): + """ + Return the particle radius + + :type: float + """ + return self.get("radius", self.index) @property def position(self): """ :getter: Return position of atom :setter: Set position of atom - :type: tuple (float, float, float) + :type: numpy.array (float, float, float) """ - return (self._pylmp.eval("x[%d]" % self.index), - self._pylmp.eval("y[%d]" % self.index), - self._pylmp.eval("z[%d]" % self.index)) + return self.get("x", self.index) @position.setter def position(self, value): - """ - :getter: Return velocity of atom - :setter: Set velocity of atom - :type: tuple (float, float, float) - """ - self._pylmp.set("atom", self.index, "x", value[0]) - self._pylmp.set("atom", self.index, "y", value[1]) - self._pylmp.set("atom", self.index, "z", value[2]) + current = self.position + current[:] = value @property def velocity(self): - return (self._pylmp.eval("vx[%d]" % self.index), - self._pylmp.eval("vy[%d]" % self.index), - self._pylmp.eval("vz[%d]" % self.index)) + """ + :getter: Return velocity of atom + :setter: Set velocity of atom + :type: numpy.array (float, float, float) + """ + return self.get("v", self.index) @velocity.setter def velocity(self, value): - self._pylmp.set("atom", self.index, "vx", value[0]) - self._pylmp.set("atom", self.index, "vy", value[1]) - self._pylmp.set("atom", self.index, "vz", value[2]) + current = self.velocity + current[:] = value @property def force(self): """ Return the total force acting on the atom - :type: tuple (float, float, float) + :type: numpy.array (float, float, float) """ - return (self._pylmp.eval("fx[%d]" % self.index), - self._pylmp.eval("fy[%d]" % self.index), - self._pylmp.eval("fz[%d]" % self.index)) + return self.get("f", self.index) + + @force.setter + def force(self, value): + current = self.force + current[:] = value + + @property + def torque(self): + """ + Return the total torque acting on the atom + + :type: numpy.array (float, float, float) + """ + return self.get("torque", self.index) + + @force.setter + def torque(self, value): + current = self.torque + current[:] = value + + @property + def omega(self): + """ + Return the rotational velocity of the particle + + :type: numpy.array (float, float, float) + """ + return self.get("torque", self.index) + + @omega.setter + def omega(self, value): + current = self.torque + current[:] = value + + @property + def torque(self): + """ + Return the total torque acting on the particle + + :type: numpy.array (float, float, float) + """ + return self.get("torque", self.index) + + @torque.setter + def torque(self, value): + current = self.torque + current[:] = value + + @property + def angular_momentum(self): + """ + Return the angular momentum of the particle + + :type: numpy.array (float, float, float) + """ + return self.get("angmom", self.index) + + @angular_momentum.setter + def angular_momentum(self, value): + current = self.angular_momentum + current[:] = value @property def charge(self): @@ -222,7 +290,7 @@ class Atom(object): :type: float """ - return self._pylmp.eval("q[%d]" % self.index) + return self.get("q", self.index) # ------------------------------------------------------------------------- @@ -244,39 +312,42 @@ class Atom2D(Atom): :getter: Return position of atom :setter: Set position of atom - :type: tuple (float, float) + :type: numpy.array (float, float) """ - return (self._pylmp.eval("x[%d]" % self.index), - self._pylmp.eval("y[%d]" % self.index)) + return super(Atom2D, self).position[0:2] @position.setter def position(self, value): - self._pylmp.set("atom", self.index, "x", value[0]) - self._pylmp.set("atom", self.index, "y", value[1]) + current = self.position + current[:] = value @property def velocity(self): """Access to velocity of an atom :getter: Return velocity of atom :setter: Set velocity of atom - :type: tuple (float, float) + :type: numpy.array (float, float) """ - return (self._pylmp.eval("vx[%d]" % self.index), - self._pylmp.eval("vy[%d]" % self.index)) + return super(Atom2D, self).velocity[0:2] @velocity.setter def velocity(self, value): - self._pylmp.set("atom", self.index, "vx", value[0]) - self._pylmp.set("atom", self.index, "vy", value[1]) + current = self.velocity + current[:] = value @property def force(self): """Access to force of an atom - - :type: tuple (float, float) + :getter: Return force of atom + :setter: Set force of atom + :type: numpy.array (float, float) """ - return (self._pylmp.eval("fx[%d]" % self.index), - self._pylmp.eval("fy[%d]" % self.index)) + return super(Atom2D, self).force[0:2] + + @force.setter + def force(self, value): + current = self.force + current[:] = value # ------------------------------------------------------------------------- @@ -541,7 +612,8 @@ class PyLammps(object): :getter: Returns an object with properties storing the current system state :type: namedtuple """ - output = self.info("system") + output = self.lmp_info("system") + output = output[output.index("System information:")+1:] d = self._parse_info_system(output) return namedtuple('System', d.keys())(*d.values()) @@ -553,7 +625,8 @@ class PyLammps(object): :getter: Returns an object with properties storing the current communication state :type: namedtuple """ - output = self.info("communication") + output = self.lmp_info("communication") + output = output[output.index("Communication information:")+1:] d = self._parse_info_communication(output) return namedtuple('Communication', d.keys())(*d.values()) @@ -565,7 +638,8 @@ class PyLammps(object): :getter: Returns a list of computes that are currently active in this LAMMPS instance :type: list """ - output = self.info("computes") + output = self.lmp_info("computes") + output = output[output.index("Compute information:")+1:] return self._parse_element_list(output) @property @@ -576,7 +650,8 @@ class PyLammps(object): :getter: Returns a list of dumps that are currently active in this LAMMPS instance :type: list """ - output = self.info("dumps") + output = self.lmp_info("dumps") + output = output[output.index("Dump information:")+1:] return self._parse_element_list(output) @property @@ -587,7 +662,8 @@ class PyLammps(object): :getter: Returns a list of fixes that are currently active in this LAMMPS instance :type: list """ - output = self.info("fixes") + output = self.lmp_info("fixes") + output = output[output.index("Fix information:")+1:] return self._parse_element_list(output) @property @@ -598,7 +674,8 @@ class PyLammps(object): :getter: Returns a list of atom groups that are currently active in this LAMMPS instance :type: list """ - output = self.info("groups") + output = self.lmp_info("groups") + output = output[output.index("Group information:")+1:] return self._parse_groups(output) @property @@ -609,11 +686,12 @@ class PyLammps(object): :getter: Returns a dictionary of all variables that are defined in this LAMMPS instance :type: dict """ - output = self.info("variables") - vars = {} + output = self.lmp_info("variables") + output = output[output.index("Variable information:")+1:] + variables = {} for v in self._parse_element_list(output): - vars[v['name']] = Variable(self, v['name'], v['style'], v['def']) - return vars + variables[v['name']] = Variable(self, v['name'], v['style'], v['def']) + return variables def eval(self, expr): """ @@ -638,10 +716,9 @@ class PyLammps(object): return [x.strip() for x in value.split('=')] def _parse_info_system(self, output): - lines = output[5:-2] system = {} - for line in lines: + for line in output: if line.startswith("Units"): system['units'] = self._get_pair(line)[1] elif line.startswith("Atom style"): @@ -699,10 +776,9 @@ class PyLammps(object): return system def _parse_info_communication(self, output): - lines = output[5:-3] comm = {} - for line in lines: + for line in output: if line.startswith("MPI library"): comm['mpi_version'] = line.split(':')[1].strip() elif line.startswith("Comm style"): @@ -720,10 +796,10 @@ class PyLammps(object): return comm def _parse_element_list(self, output): - lines = output[5:-3] elements = [] - for line in lines: + for line in output: + if not line or (":" not in line): continue element_info = self._split_values(line.split(':')[1].strip()) element = {'name': element_info[0]} for key, value in [self._get_pair(x) for x in element_info[1:]]: @@ -732,11 +808,10 @@ class PyLammps(object): return elements def _parse_groups(self, output): - lines = output[5:-3] groups = [] group_pattern = re.compile(r"(?P.+) \((?P.+)\)") - for line in lines: + for line in output: m = group_pattern.match(line.split(':')[1].strip()) group = {'name': m.group('name'), 'type': m.group('type')} groups.append(group) @@ -747,7 +822,7 @@ class PyLammps(object): return self.__getattr__("print")(s) def __dir__(self): - return ['angle_coeff', 'angle_style', 'atom_modify', 'atom_style', 'atom_style', + return sorted(set(['angle_coeff', 'angle_style', 'atom_modify', 'atom_style', 'atom_style', 'bond_coeff', 'bond_style', 'boundary', 'change_box', 'communicate', 'compute', 'create_atoms', 'create_box', 'delete_atoms', 'delete_bonds', 'dielectric', 'dihedral_coeff', 'dihedral_style', 'dimension', 'dump', 'fix', 'fix_modify', @@ -757,7 +832,16 @@ class PyLammps(object): 'pair_style', 'processors', 'read', 'read_data', 'read_restart', 'region', 'replicate', 'reset_timestep', 'restart', 'run', 'run_style', 'thermo', 'thermo_modify', 'thermo_style', 'timestep', 'undump', 'unfix', 'units', - 'variable', 'velocity', 'write_restart'] + 'variable', 'velocity', 'write_restart'] + self.lmp.available_styles("command"))) + + def lmp_info(self, s): + # skip anything before and after Info-Info-Info + # also skip timestamp line + output = self.__getattr__("info")(s) + indices = [index for index, line in enumerate(output) if line.startswith("Info-Info-Info-Info")] + start = indices[0] + end = indices[1] + return [line for line in output[start+2:end] if line] def __getattr__(self, name): """ @@ -773,10 +857,12 @@ class PyLammps(object): """ def handler(*args, **kwargs): cmd_args = [name] + [str(x) for x in args] + self.lmp.flush_buffers() with OutputCapture() as capture: cmd = ' '.join(cmd_args) self.command(cmd) + self.lmp.flush_buffers() output = capture.output comm = self.lmp.get_mpi_comm() diff --git a/src/CG-DNA/bond_oxdna_fene.cpp b/src/CG-DNA/bond_oxdna_fene.cpp index 4db0fb4cf1..58b127c63c 100644 --- a/src/CG-DNA/bond_oxdna_fene.cpp +++ b/src/CG-DNA/bond_oxdna_fene.cpp @@ -24,7 +24,6 @@ #include "neighbor.h" #include "update.h" -#include "atom_vec_ellipsoid.h" #include "math_extra.h" #include "pair.h" @@ -161,10 +160,6 @@ void BondOxdnaFene::compute(int eflag, int vflag) double **f = atom->f; double **torque = atom->torque; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int **bondlist = neighbor->bondlist; int nbondlist = neighbor->nbondlist; int nlocal = atom->nlocal; diff --git a/src/CG-DNA/pair_oxdna2_coaxstk.cpp b/src/CG-DNA/pair_oxdna2_coaxstk.cpp index 8b3609983b..1e53104003 100644 --- a/src/CG-DNA/pair_oxdna2_coaxstk.cpp +++ b/src/CG-DNA/pair_oxdna2_coaxstk.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna2_coaxstk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -102,7 +101,7 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair,factor_lj; + double evdwl,finc,tpair,factor_lj; double v1tmp[3]; double delr_ss[3],delr_ss_norm[3],rsq_ss,r_ss,rinv_ss; double delr_st[3],delr_st_norm[3],rsq_st,r_st,rinv_st; @@ -119,8 +118,8 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) double rb_cs[3],rb_cst[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; @@ -132,10 +131,6 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; double f2,f4f6t1,f4t4,f4t5,f4t6; @@ -322,8 +317,6 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between stacking sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -338,7 +331,6 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) // radial force finc = -df2 * f4f6t1 * f4t4 * f4t5 * f4t6 * rinv_st * factor_lj; - fpair += finc; delf[0] += delr_st[0] * finc; delf[1] += delr_st[1] * finc; @@ -348,7 +340,6 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) if (theta5 && theta5p) { finc = -f2 * f4f6t1 * f4t4 * df4t5 * f4t6 * rinv_st * factor_lj; - fpair += finc; delf[0] += (delr_st_norm[0]*cost5 - az[0]) * finc; delf[1] += (delr_st_norm[1]*cost5 - az[1]) * finc; @@ -360,7 +351,6 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) if (theta6 && theta6p) { finc = -f2 * f4f6t1* f4t4 * f4t5 * df4t6 * rinv_st * factor_lj; - fpair += finc; delf[0] += (delr_st_norm[0]*cost6 - bz[0]) * finc; delf[1] += (delr_st_norm[1]*cost6 - bz[1]) * finc; diff --git a/src/CG-DNA/pair_oxdna2_dh.cpp b/src/CG-DNA/pair_oxdna2_dh.cpp index cf79fd07cf..19b158ea61 100644 --- a/src/CG-DNA/pair_oxdna2_dh.cpp +++ b/src/CG-DNA/pair_oxdna2_dh.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna2_dh.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -101,10 +100,6 @@ void PairOxdna2Dh::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; evdwl = 0.0; diff --git a/src/CG-DNA/pair_oxdna_coaxstk.cpp b/src/CG-DNA/pair_oxdna_coaxstk.cpp index 49b25bb81b..1976de0f62 100644 --- a/src/CG-DNA/pair_oxdna_coaxstk.cpp +++ b/src/CG-DNA/pair_oxdna_coaxstk.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna_coaxstk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -107,7 +106,7 @@ PairOxdnaCoaxstk::~PairOxdnaCoaxstk() void PairOxdnaCoaxstk::compute(int eflag, int vflag) { double delf[3],delt[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair,factor_lj; + double evdwl,finc,tpair,factor_lj; double v1tmp[3],v2tmp[3],v3tmp[3]; double delr_ss[3],delr_ss_norm[3],rsq_ss,r_ss,rinv_ss; double delr_st[3],delr_st_norm[3],rsq_st,r_st,rinv_st; @@ -130,7 +129,7 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) double rb_cs[3],rb_cst[3]; // Cartesian unit vectors in lab frame double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; @@ -142,10 +141,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; double f2,f4t1,f4t4,f4t5,f4t6,f5c3; @@ -345,8 +340,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between stacking sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -361,7 +354,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) // radial force finc = -df2 * f4t1 * f4t4 * f4t5 * f4t6 * f5c3 * f5c3 * rinv_st * factor_lj; - fpair += finc; delf[0] += delr_st[0] * finc; delf[1] += delr_st[1] * finc; @@ -371,7 +363,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) if (theta5 && theta5p) { finc = -f2 * f4t1 * f4t4 * df4t5 * f4t6 * f5c3 * f5c3 * rinv_st * factor_lj; - fpair += finc; delf[0] += (delr_st_norm[0]*cost5 - az[0]) * finc; delf[1] += (delr_st_norm[1]*cost5 - az[1]) * finc; @@ -383,7 +374,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) if (theta6 && theta6p) { finc = -f2 * f4t1* f4t4 * f4t5 * df4t6 * f5c3 * f5c3 * rinv_st * factor_lj; - fpair += finc; delf[0] += (delr_st_norm[0]*cost6 - bz[0]) * finc; delf[1] += (delr_st_norm[1]*cost6 - bz[1]) * finc; @@ -400,7 +390,6 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) ay[2] = ny_xtrct[a][2]; finc = -f2 * f4t1* f4t4 * f4t5 * f4t6 * 2.0 * f5c3 * df5c3 * factor_lj; - fpair += finc; gamma = d_cs - d_cst; gammacub = gamma * gamma * gamma; diff --git a/src/CG-DNA/pair_oxdna_excv.cpp b/src/CG-DNA/pair_oxdna_excv.cpp index ae5752028a..f47f92d63c 100644 --- a/src/CG-DNA/pair_oxdna_excv.cpp +++ b/src/CG-DNA/pair_oxdna_excv.cpp @@ -143,7 +143,7 @@ void PairOxdnaExcv::compute(int eflag, int vflag) AtomVecEllipsoid::Bonus *bonus = avec->bonus; int *ellipsoid = atom->ellipsoid; - int n,a,b,in,ia,ib,anum,bnum,atype,btype; + int a,b,in,ia,ib,anum,bnum,atype,btype; evdwl = 0.0; ev_init(eflag,vflag); diff --git a/src/CG-DNA/pair_oxdna_excv.h b/src/CG-DNA/pair_oxdna_excv.h index 5cf781feaa..a255c954bb 100644 --- a/src/CG-DNA/pair_oxdna_excv.h +++ b/src/CG-DNA/pair_oxdna_excv.h @@ -41,8 +41,8 @@ class PairOxdnaExcv : public Pair { void write_data(FILE *) override; void write_data_all(FILE *) override; void *extract(const char *, int &) override; - virtual int pack_forward_comm(int, int *, double *, int, int *); - virtual void unpack_forward_comm(int, int, double *); + int pack_forward_comm(int, int *, double *, int, int *) override; + void unpack_forward_comm(int, int, double *) override; protected: // s=sugar-phosphate backbone site, b=base site, st=stacking site diff --git a/src/CG-DNA/pair_oxdna_hbond.cpp b/src/CG-DNA/pair_oxdna_hbond.cpp index 3d2e803aa8..3f563767c5 100644 --- a/src/CG-DNA/pair_oxdna_hbond.cpp +++ b/src/CG-DNA/pair_oxdna_hbond.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna_hbond.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -135,7 +134,7 @@ void PairOxdnaHbond::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair,factor_lj; + double evdwl,finc,tpair,factor_lj; double delr_hb[3],delr_hb_norm[3],rsq_hb,r_hb,rinv_hb; double theta1,t1dir[3],cost1; double theta2,t2dir[3],cost2; @@ -149,8 +148,8 @@ void PairOxdnaHbond::compute(int eflag, int vflag) // vectors COM-h-bonding site in lab frame double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; @@ -162,10 +161,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; double f1,f4t1,f4t4,f4t2,f4t3,f4t7,f4t8; @@ -338,8 +333,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) // force, torque and virial contribution for forces between h-bonding sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -354,7 +347,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) // radial force finc = -df1 * f4t1 * f4t2 * f4t3 * f4t4 * f4t7 * f4t8 * factor_lj; - fpair += finc; delf[0] += delr_hb[0] * finc; delf[1] += delr_hb[1] * finc; @@ -364,7 +356,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) if (theta2) { finc = -f1 * f4t1 * df4t2 * f4t3 * f4t4 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost2 + ax[0]) * finc; delf[1] += (delr_hb_norm[1]*cost2 + ax[1]) * finc; @@ -376,7 +367,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) if (theta3) { finc = -f1 * f4t1 * f4t2 * df4t3 * f4t4 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost3 - bx[0]) * finc; delf[1] += (delr_hb_norm[1]*cost3 - bx[1]) * finc; @@ -388,7 +378,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) if (theta7) { finc = -f1 * f4t1 * f4t2 * f4t3 * f4t4 * df4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost7 + az[0]) * finc; delf[1] += (delr_hb_norm[1]*cost7 + az[1]) * finc; @@ -400,7 +389,6 @@ void PairOxdnaHbond::compute(int eflag, int vflag) if (theta8) { finc = -f1 * f4t1 * f4t2 * f4t3 * f4t4 * f4t7 * df4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost8 - bz[0]) * finc; delf[1] += (delr_hb_norm[1]*cost8 - bz[1]) * finc; diff --git a/src/CG-DNA/pair_oxdna_stk.cpp b/src/CG-DNA/pair_oxdna_stk.cpp index feeb41d78b..0f17d332d6 100644 --- a/src/CG-DNA/pair_oxdna_stk.cpp +++ b/src/CG-DNA/pair_oxdna_stk.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna_stk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -213,7 +212,7 @@ void PairOxdnaStk::ev_tally_xyz(int i, int j, int nlocal, int newton_bond, void PairOxdnaStk::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair; + double evdwl,finc,tpair; double delr_ss[3],delr_ss_norm[3],rsq_ss,r_ss,rinv_ss; double delr_st[3],delr_st_norm[3],rsq_st,r_st,rinv_st; double theta4,t4dir[3],cost4; @@ -243,10 +242,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) tagint *id5p = atom->id5p; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,btemp,in,atype,btype; double f1,f4t4,f4t5,f4t6,f5c1,f5c2; @@ -430,8 +425,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between stacking sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -446,7 +439,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) // radial force finc = -df1 * f4t4 * f4t5 * f4t6 * f5c1 * f5c2; - fpair += finc; delf[0] += delr_st[0] * finc; delf[1] += delr_st[1] * finc; @@ -456,7 +448,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) if (theta5p) { finc = -f1 * f4t4 * df4t5 * f4t6 * f5c1 * f5c2 * rinv_st; - fpair += finc; delf[0] += (delr_st_norm[0]*cost5p - bz[0]) * finc; delf[1] += (delr_st_norm[1]*cost5p - bz[1]) * finc; @@ -468,7 +459,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) if (theta6p) { finc = -f1 * f4t4 * f4t5 * df4t6 * f5c1 * f5c2 * rinv_st; - fpair += finc; delf[0] += (delr_st_norm[0]*cost6p - az[0]) * finc; delf[1] += (delr_st_norm[1]*cost6p - az[1]) * finc; @@ -520,8 +510,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between backbone sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -538,7 +526,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) if (cosphi1) { finc = -f1 * f4t4 * f4t5 * f4t6 * df5c1 * f5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cosphi1 - by[0]) * finc; delf[1] += (delr_ss_norm[1]*cosphi1 - by[1]) * finc; @@ -550,7 +537,6 @@ void PairOxdnaStk::compute(int eflag, int vflag) if (cosphi2) { finc = -f1 * f4t4 * f4t5 * f4t6 * f5c1 * df5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cosphi2 - ay[0]) * finc; delf[1] += (delr_ss_norm[1]*cosphi2 - ay[1]) * finc; diff --git a/src/CG-DNA/pair_oxdna_xstk.cpp b/src/CG-DNA/pair_oxdna_xstk.cpp index 61dc1a8100..f50d5219f9 100644 --- a/src/CG-DNA/pair_oxdna_xstk.cpp +++ b/src/CG-DNA/pair_oxdna_xstk.cpp @@ -18,7 +18,6 @@ #include "pair_oxdna_xstk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -112,7 +111,7 @@ PairOxdnaXstk::~PairOxdnaXstk() void PairOxdnaXstk::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair,factor_lj; + double evdwl,finc,tpair,factor_lj; double delr_hb[3],delr_hb_norm[3],rsq_hb,r_hb,rinv_hb; double theta1,t1dir[3],cost1; double theta2,t2dir[3],cost2; @@ -126,8 +125,8 @@ void PairOxdnaXstk::compute(int eflag, int vflag) // vectors COM-h-bonding site in lab frame double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; @@ -139,10 +138,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; double f2,f4t1,f4t4,f4t2,f4t3,f4t7,f4t8; @@ -337,8 +332,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between h-bonding sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -353,7 +346,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) // radial force finc = -df2 * f4t1 * f4t2 * f4t3 * f4t4 * f4t7 * f4t8 * rinv_hb *factor_lj; - fpair += finc; delf[0] += delr_hb[0] * finc; delf[1] += delr_hb[1] * finc; @@ -363,7 +355,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) if (theta2) { finc = -f2 * f4t1 * df4t2 * f4t3 * f4t4 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost2 + ax[0]) * finc; delf[1] += (delr_hb_norm[1]*cost2 + ax[1]) * finc; @@ -375,7 +366,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) if (theta3) { finc = -f2 * f4t1 * f4t2 * df4t3 * f4t4 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost3 - bx[0]) * finc; delf[1] += (delr_hb_norm[1]*cost3 - bx[1]) * finc; @@ -387,7 +377,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) if (theta7) { finc = -f2 * f4t1 * f4t2 * f4t3 * f4t4 * df4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost7 + az[0]) * finc; delf[1] += (delr_hb_norm[1]*cost7 + az[1]) * finc; @@ -399,7 +388,6 @@ void PairOxdnaXstk::compute(int eflag, int vflag) if (theta8) { finc = -f2 * f4t1 * f4t2 * f4t3 * f4t4 * f4t7 * df4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost8 - bz[0]) * finc; delf[1] += (delr_hb_norm[1]*cost8 - bz[1]) * finc; diff --git a/src/CG-DNA/pair_oxrna2_stk.cpp b/src/CG-DNA/pair_oxrna2_stk.cpp index c5fa47e25e..a14f78e715 100644 --- a/src/CG-DNA/pair_oxrna2_stk.cpp +++ b/src/CG-DNA/pair_oxrna2_stk.cpp @@ -18,7 +18,6 @@ #include "pair_oxrna2_stk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -222,7 +221,7 @@ void PairOxrna2Stk::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair; + double evdwl,finc,tpair; double delr_ss[3],delr_ss_norm[3],rsq_ss,r_ss,rinv_ss; double delr_st[3],delr_st_norm[3],rsq_st,r_st,rinv_st; double theta5p,t5pdir[3],cost5p; @@ -262,10 +261,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) tagint *id5p = atom->id5p; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,btemp,in,atype,btype; double f1,f4t5,f4t6,f4t9,f4t10,f5c1,f5c2; @@ -462,8 +457,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between stacking sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -478,7 +471,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) // radial force finc = -df1 * f4t5 * f4t6 * f4t9 * f4t10 * f5c1 * f5c2; - fpair += finc; delf[0] += delr_st[0] * finc; delf[1] += delr_st[1] * finc; @@ -488,7 +480,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (theta5p) { finc = -f1 * df4t5 * f4t6 * f4t9 * f4t10 * f5c1 * f5c2 * rinv_st; - fpair += finc; delf[0] += (delr_st_norm[0]*cost5p - bz[0]) * finc; delf[1] += (delr_st_norm[1]*cost5p - bz[1]) * finc; @@ -500,7 +491,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (theta6p) { finc = -f1 * f4t5 * df4t6 * f4t9 * f4t10 * f5c1 * f5c2 * rinv_st; - fpair += finc; delf[0] += (delr_st_norm[0]*cost6p - az[0]) * finc; delf[1] += (delr_st_norm[1]*cost6p - az[1]) * finc; @@ -552,8 +542,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between backbone sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -570,7 +558,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (theta9) { finc = -f1 * f4t5 * f4t6 * df4t9 * f4t10 * f5c1 * f5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cost9 - aux3p[0]) * finc; delf[1] += (delr_ss_norm[1]*cost9 - aux3p[1]) * finc; @@ -582,7 +569,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (theta10) { finc = -f1 * f4t5 * f4t6 * f4t9 * df4t10 * f5c1 * f5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cost10 - aux5p[0]) * finc; delf[1] += (delr_ss_norm[1]*cost10 - aux5p[1]) * finc; @@ -594,7 +580,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (cosphi1) { finc = -f1 * f4t5 * f4t6 * f4t9 * f4t10 * df5c1 * f5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cosphi1 - by[0]) * finc; delf[1] += (delr_ss_norm[1]*cosphi1 - by[1]) * finc; @@ -606,7 +591,6 @@ void PairOxrna2Stk::compute(int eflag, int vflag) if (cosphi2) { finc = -f1 * f4t5 * f4t6 * f4t9 * f4t10 * f5c1 * df5c2 * rinv_ss; - fpair += finc; delf[0] += (delr_ss_norm[0]*cosphi2 - ay[0]) * finc; delf[1] += (delr_ss_norm[1]*cosphi2 - ay[1]) * finc; diff --git a/src/CG-DNA/pair_oxrna2_xstk.cpp b/src/CG-DNA/pair_oxrna2_xstk.cpp index 1f069e6b2f..09f8e68943 100644 --- a/src/CG-DNA/pair_oxrna2_xstk.cpp +++ b/src/CG-DNA/pair_oxrna2_xstk.cpp @@ -18,7 +18,6 @@ #include "pair_oxrna2_xstk.h" #include "atom.h" -#include "atom_vec_ellipsoid.h" #include "comm.h" #include "error.h" #include "force.h" @@ -107,7 +106,7 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) { double delf[3],delta[3],deltb[3]; // force, torque increment; - double evdwl,fpair,finc,tpair,factor_lj; + double evdwl,finc,tpair,factor_lj; double delr_hb[3],delr_hb_norm[3],rsq_hb,r_hb,rinv_hb; double theta1,t1dir[3],cost1; double theta2,t2dir[3],cost2; @@ -121,8 +120,8 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; @@ -134,10 +133,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) int *alist,*blist,*numneigh,**firstneigh; double *special_lj = force->special_lj; - AtomVecEllipsoid *avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - AtomVecEllipsoid::Bonus *bonus = avec->bonus; - int *ellipsoid = atom->ellipsoid; - int a,b,ia,ib,anum,bnum,atype,btype; double f2,f4t1,f4t2,f4t3,f4t7,f4t8; @@ -310,8 +305,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) // force, torque and virial contribution for forces between h-bonding sites - fpair = 0.0; - delf[0] = 0.0; delf[1] = 0.0; delf[2] = 0.0; @@ -326,7 +319,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) // radial force finc = -df2 * f4t1 * f4t2 * f4t3 * f4t7 * f4t8 * rinv_hb *factor_lj; - fpair += finc; delf[0] += delr_hb[0] * finc; delf[1] += delr_hb[1] * finc; @@ -336,7 +328,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) if (theta2) { finc = -f2 * f4t1 * df4t2 * f4t3 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost2 + ax[0]) * finc; delf[1] += (delr_hb_norm[1]*cost2 + ax[1]) * finc; @@ -348,7 +339,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) if (theta3) { finc = -f2 * f4t1 * f4t2 * df4t3 * f4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost3 - bx[0]) * finc; delf[1] += (delr_hb_norm[1]*cost3 - bx[1]) * finc; @@ -360,7 +350,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) if (theta7) { finc = -f2 * f4t1 * f4t2 * f4t3 * df4t7 * f4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost7 + az[0]) * finc; delf[1] += (delr_hb_norm[1]*cost7 + az[1]) * finc; @@ -372,7 +361,6 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) if (theta8) { finc = -f2 * f4t1 * f4t2 * f4t3 * f4t7 * df4t8 * rinv_hb * factor_lj; - fpair += finc; delf[0] += (delr_hb_norm[0]*cost8 - bz[0]) * finc; delf[1] += (delr_hb_norm[1]*cost8 - bz[1]) * finc; diff --git a/src/DIELECTRIC/msm_dielectric.h b/src/DIELECTRIC/msm_dielectric.h index cfc0cb43e2..64982afae2 100644 --- a/src/DIELECTRIC/msm_dielectric.h +++ b/src/DIELECTRIC/msm_dielectric.h @@ -30,12 +30,12 @@ class MSMDielectric : public MSM { ~MSMDielectric() override; void init() override; void compute(int, int) override; - void fieldforce(); double **efield; double *phi; protected: + void fieldforce() override; class AtomVecDielectric *avec; }; diff --git a/src/DPD-REACT/fix_rx.cpp b/src/DPD-REACT/fix_rx.cpp index 165a3a6dbf..f55cb4d943 100644 --- a/src/DPD-REACT/fix_rx.cpp +++ b/src/DPD-REACT/fix_rx.cpp @@ -689,20 +689,14 @@ void FixRX::pre_force(int /*vflag*/) // Zero the counters for the ODE solvers. int nSteps = 0; - int nIters = 0; int nFuncs = 0; int nFails = 0; - if (odeIntegrationFlag == ODE_LAMMPS_RKF45 && diagnosticFrequency == 1) - { + if (odeIntegrationFlag == ODE_LAMMPS_RKF45 && diagnosticFrequency == 1) { memory->create( diagnosticCounterPerODE[StepSum], nlocal, "FixRX::diagnosticCounterPerODE"); memory->create( diagnosticCounterPerODE[FuncSum], nlocal, "FixRX::diagnosticCounterPerODE"); } -#if 0 - #pragma omp parallel \ - reduction(+: nSteps, nIters, nFuncs, nFails ) -#endif { double *rwork = new double[8*nspecies]; @@ -712,11 +706,8 @@ void FixRX::pre_force(int /*vflag*/) int ode_counter[4] = { 0 }; - //#pragma omp for schedule(runtime) - for (int i = 0; i < nlocal; i++) - { - if (mask[i] & groupbit) - { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { double theta; if (localTempFlag) theta = dpdThetaLocal[i]; @@ -735,7 +726,6 @@ void FixRX::pre_force(int /*vflag*/) } nSteps += ode_counter[0]; - nIters += ode_counter[1]; nFuncs += ode_counter[2]; nFails += ode_counter[3]; diff --git a/src/EXTRA-FIX/fix_numdiff.cpp b/src/EXTRA-FIX/fix_numdiff.cpp index 97067d316b..7265ec0b79 100644 --- a/src/EXTRA-FIX/fix_numdiff.cpp +++ b/src/EXTRA-FIX/fix_numdiff.cpp @@ -41,7 +41,7 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixNumDiff::FixNumDiff(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), temp_f(nullptr) + Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), temp_f(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix numdiff command"); @@ -109,9 +109,8 @@ void FixNumDiff::init() // check for PE compute - int icompute = modify->find_compute(id_pe); - if (icompute < 0) error->all(FLERR, "Compute ID for fix numdiff does not exist"); - pe = modify->compute[icompute]; + pe = modify->get_compute_by_id(id_pe); + if (!pe) error->all(FLERR, "PE compute ID for fix numdiff does not exist"); if (force->pair && force->pair->compute_flag) pair_compute_flag = 1; diff --git a/src/EXTRA-FIX/fix_numdiff_virial.cpp b/src/EXTRA-FIX/fix_numdiff_virial.cpp index ac7654e166..f2226f4a59 100644 --- a/src/EXTRA-FIX/fix_numdiff_virial.cpp +++ b/src/EXTRA-FIX/fix_numdiff_virial.cpp @@ -41,7 +41,7 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixNumDiffVirial::FixNumDiffVirial(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_pe(nullptr), temp_x(nullptr), temp_f(nullptr) + Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), temp_x(nullptr), temp_f(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix numdiff/virial command"); if (igroup) error->all(FLERR, "Compute numdiff/virial must use group all"); @@ -121,9 +121,8 @@ void FixNumDiffVirial::init() { // check for PE compute - int icompute = modify->find_compute(id_pe); - if (icompute < 0) error->all(FLERR, "Compute ID for fix numdiff does not exist"); - pe = modify->compute[icompute]; + pe = modify->get_compute_by_id(id_pe); + if (!pe) error->all(FLERR, "PE compute ID for fix numdiff/virial does not exist"); if (force->pair && force->pair->compute_flag) pair_compute_flag = 1; @@ -210,7 +209,6 @@ void FixNumDiffVirial::calculate_virial() // loop over 6 strain directions // compute a finite difference force in each dimension - int flag, allflag; double nktv2p = force->nktv2p; double inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd); diff --git a/src/EXTRA-PAIR/pair_harmonic_cut.cpp b/src/EXTRA-PAIR/pair_harmonic_cut.cpp index f2e1c422fe..89c3e0bf6b 100644 --- a/src/EXTRA-PAIR/pair_harmonic_cut.cpp +++ b/src/EXTRA-PAIR/pair_harmonic_cut.cpp @@ -146,7 +146,7 @@ void PairHarmonicCut::allocate() global settings ------------------------------------------------------------------------- */ -void PairHarmonicCut::settings(int narg, char **arg) +void PairHarmonicCut::settings(int narg, char ** /*arg*/) { if (narg > 0) error->all(FLERR, "Illegal pair_style command"); } diff --git a/src/GRANULAR/pair_gran_hertz_history.cpp b/src/GRANULAR/pair_gran_hertz_history.cpp index 2fa0f5acb8..19cf09cd02 100644 --- a/src/GRANULAR/pair_gran_hertz_history.cpp +++ b/src/GRANULAR/pair_gran_hertz_history.cpp @@ -204,11 +204,12 @@ void PairGranHertzHistory::compute(int eflag, int vflag) shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); - // rotate shear displacements - - rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; - rsht *= rsqinv; if (shearupdate) { + + // rotate shear displacements + + rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; + rsht *= rsqinv; shear[0] -= rsht*delx; shear[1] -= rsht*dely; shear[2] -= rsht*delz; @@ -320,7 +321,7 @@ double PairGranHertzHistory::single(int i, int j, int /*itype*/, int /*jtype*/, double r,rinv,rsqinv,delx,dely,delz; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3,wr1,wr2,wr3; double mi,mj,meff,damp,ccel,polyhertz; - double vtr1,vtr2,vtr3,vrel,shrmag,rsht; + double vtr1,vtr2,vtr3,vrel,shrmag; double fs1,fs2,fs3,fs,fn; double *radius = atom->radius; @@ -426,11 +427,6 @@ double PairGranHertzHistory::single(int i, int j, int /*itype*/, int /*jtype*/, shrmag = sqrt(shear[0]*shear[0] + shear[1]*shear[1] + shear[2]*shear[2]); - // rotate shear displacements - - rsht = shear[0]*delx + shear[1]*dely + shear[2]*delz; - rsht *= rsqinv; - // tangential forces = shear + tangential velocity damping fs1 = -polyhertz * (kt*shear[0] + meff*gammat*vtr1); diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index c9cdba1e35..74bfb4bcee 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -264,11 +264,12 @@ void PairGranHookeHistory::compute(int eflag, int vflag) } shrmag = sqrt(shear[0] * shear[0] + shear[1] * shear[1] + shear[2] * shear[2]); - // rotate shear displacements - - rsht = shear[0] * delx + shear[1] * dely + shear[2] * delz; - rsht *= rsqinv; if (shearupdate) { + + // rotate shear displacements + + rsht = shear[0] * delx + shear[1] * dely + shear[2] * delz; + rsht *= rsqinv; shear[0] -= rsht * delx; shear[1] -= rsht * dely; shear[2] -= rsht * delz; @@ -616,7 +617,7 @@ double PairGranHookeHistory::single(int i, int j, int /*itype*/, int /*jtype*/, double r, rinv, rsqinv, delx, dely, delz; double vr1, vr2, vr3, vnnr, vn1, vn2, vn3, vt1, vt2, vt3, wr1, wr2, wr3; double mi, mj, meff, damp, ccel; - double vtr1, vtr2, vtr3, vrel, shrmag, rsht; + double vtr1, vtr2, vtr3, vrel, shrmag; double fs1, fs2, fs3, fs, fn; double *radius = atom->radius; @@ -718,11 +719,6 @@ double PairGranHookeHistory::single(int i, int j, int /*itype*/, int /*jtype*/, double *shear = &allshear[3 * neighprev]; shrmag = sqrt(shear[0] * shear[0] + shear[1] * shear[1] + shear[2] * shear[2]); - // rotate shear displacements - - rsht = shear[0] * delx + shear[1] * dely + shear[2] * delz; - rsht *= rsqinv; - // tangential forces = shear + tangential velocity damping fs1 = -(kt * shear[0] + meff * gammat * vtr1); diff --git a/src/INTEL/intel_buffers.cpp b/src/INTEL/intel_buffers.cpp index cbbc609fc0..f84505955c 100644 --- a/src/INTEL/intel_buffers.cpp +++ b/src/INTEL/intel_buffers.cpp @@ -27,7 +27,7 @@ using namespace LAMMPS_NS; template IntelBuffers::IntelBuffers(class LAMMPS *lmp_in) : lmp(lmp_in), _x(0), _q(0), _quat(0), _f(0), _off_threads(0), - _buf_size(0), _buf_local_size(0), _n_list_ptrs(1), _max_list_ptrs(4) { + _n_list_ptrs(1), _max_list_ptrs(4), _buf_size(0), _buf_local_size(0) { _neigh_list_ptrs = new IntelNeighListPtrs[_max_list_ptrs]; _neigh_list_ptrs[0].cnumneigh = 0; _list_alloc_atoms = 0; diff --git a/src/INTEL/pair_airebo_intel.cpp b/src/INTEL/pair_airebo_intel.cpp index 95b80fe801..c5fd47afd6 100644 --- a/src/INTEL/pair_airebo_intel.cpp +++ b/src/INTEL/pair_airebo_intel.cpp @@ -242,17 +242,17 @@ PairAIREBOIntelParam PairAIREBOIntel::get_param() PairAIREBOIntelParam fc; #define A(a) \ - for (int i = 0; i < sizeof(this->a)/sizeof(double); i++) { \ + for (size_t i = 0; i < sizeof(this->a)/sizeof(double); i++) { \ reinterpret_cast(&fc.a)[i] = \ reinterpret_cast(&this->a)[i]; \ } #define A0(a) \ - for (int i = 0; i < sizeof(fc.a)/sizeof(flt_t); i++) { \ + for (size_t i = 0; i < sizeof(fc.a)/sizeof(flt_t); i++) { \ reinterpret_cast(&fc.a)[i] = \ reinterpret_cast(this->a[0])[i]; \ } #define B(a) \ - for (int i = 0; i < sizeof(this->a)/sizeof(double); i++) { \ + for (size_t i = 0; i < sizeof(this->a)/sizeof(double); i++) { \ reinterpret_cast(&fc.a)[i] = \ reinterpret_cast(&this->a)[i]; \ } diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index e26513a122..0c730fda65 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -600,7 +600,8 @@ void KokkosLMP::my_signal_handler(int sig) { if (sig == SIGSEGV) { #if defined(_WIN32) - kill(_getpid(),SIGABRT); + // there is no kill() function on Windows + exit(1); #else kill(getpid(),SIGABRT); #endif diff --git a/src/KOKKOS/nbin_ssa_kokkos.cpp b/src/KOKKOS/nbin_ssa_kokkos.cpp index b91ff7bd41..d6ad5ade0c 100644 --- a/src/KOKKOS/nbin_ssa_kokkos.cpp +++ b/src/KOKKOS/nbin_ssa_kokkos.cpp @@ -142,7 +142,7 @@ void NBinSSAKokkos::bin_atoms() k_gbincount.sync(); ghosts_per_gbin = 0; NPairSSAKokkosBinIDGhostsFunctor f(*this); - Kokkos::parallel_reduce(Kokkos::RangePolicy(nlocal,nall), f, ghosts_per_gbin); + Kokkos::parallel_reduce(Kokkos::RangePolicy(nlocal,nall), f, ghosts_per_gbin); } // actually bin the ghost atoms diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 0988cb4910..d96e9f3f65 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -17,9 +17,7 @@ ------------------------------------------------------------------------- */ #include "pair_exp6_rx_kokkos.h" -#include -#include #include "atom.h" #include "comm.h" #include "force.h" @@ -28,12 +26,14 @@ #include "memory_kokkos.h" #include "error.h" #include "fix.h" -#include #include "atom_masks.h" #include "neigh_request.h" #include "atom_kokkos.h" #include "kokkos.h" +#include +#include +#include #ifdef _OPENMP #include @@ -57,22 +57,6 @@ using namespace MathSpecialKokkos; #define exp6PotentialType (1) #define isExp6PotentialType(_type) ( (_type) == exp6PotentialType ) -namespace /* anonymous */ -{ - -//typedef double TimerType; -//TimerType getTimeStamp(void) { return platform::walltime(); } -//double getElapsedTime( const TimerType &t0, const TimerType &t1) { return t1-t0; } - -typedef struct timespec TimerType; -TimerType getTimeStamp(void) { TimerType tick; clock_gettime( CLOCK_MONOTONIC, &tick); return tick; } -double getElapsedTime( const TimerType &t0, const TimerType &t1) -{ - return (t1.tv_sec - t0.tv_sec) + 1e-9*(t1.tv_nsec - t0.tv_nsec); -} - -} // end namespace - /* ---------------------------------------------------------------------- */ template @@ -142,8 +126,6 @@ void PairExp6rxKokkos::init_style() template void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) { - //TimerType t_start = getTimeStamp(); - copymode = 1; eflag = eflag_in; @@ -187,7 +169,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) // and ghost atoms. Make the parameter data persistent // and exchange like any other atom property later. - //TimerType t_mix_start = getTimeStamp(); { const int np_total = nlocal + atom->nghost; @@ -260,7 +241,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) error->all(FLERR,"Computed fraction less than -10*DBL_EPSILON"); #endif } - //TimerType t_mix_stop = getTimeStamp(); k_error_flag.template modify(); k_error_flag.template sync(); @@ -377,9 +357,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) } copymode = 0; - - //TimerType t_stop = getTimeStamp(); - //printf("PairExp6rxKokkos::compute %f %f\n", getElapsedTime(t_start, t_stop), getElapsedTime(t_mix_start, t_mix_stop)); } template diff --git a/src/KOKKOS/pair_hybrid_kokkos.cpp b/src/KOKKOS/pair_hybrid_kokkos.cpp index b1d3e0259f..00abc36768 100644 --- a/src/KOKKOS/pair_hybrid_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_kokkos.cpp @@ -1,4 +1,5 @@ // clang-format off + /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -52,10 +53,10 @@ PairHybridKokkos::~PairHybridKokkos() /* ---------------------------------------------------------------------- call each sub-style's compute() or compute_outer() function accumulate sub-style global/peratom energy/virial in hybrid - for global vflag = 1: + for global vflag = VIRIAL_PAIR: each sub-style computes own virial[6] sum sub-style virial[6] to hybrid's virial[6] - for global vflag = 2: + for global vflag = VIRIAL_FDOTR: call sub-style with adjusted vflag to prevent it calling virial_fdotr_compute() hybrid calls virial_fdotr_compute() on final accumulated f @@ -65,24 +66,25 @@ void PairHybridKokkos::compute(int eflag, int vflag) { int i,j,m,n; - // if no_virial_fdotr_compute is set and global component of - // incoming vflag = VIRIAL_FDOTR, then - // reset vflag as if global component were VIRIAL_PAIR + // check if no_virial_fdotr_compute is set and global component of + // incoming vflag = VIRIAL_FDOTR + // if so, reset vflag as if global component were VIRIAL_PAIR // necessary since one or more sub-styles cannot compute virial as F dot r int neighflag = lmp->kokkos->neighflag; if (neighflag == FULL) no_virial_fdotr_compute = 1; - if (no_virial_fdotr_compute && vflag & VIRIAL_FDOTR) vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); + if (no_virial_fdotr_compute && (vflag & VIRIAL_FDOTR)) + vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); ev_init(eflag,vflag); // check if global component of incoming vflag = VIRIAL_FDOTR - // if so, reset vflag passed to substyle as if it were VIRIAL_NONE + // if so, reset vflag passed to substyle so VIRIAL_FDOTR is turned off // necessary so substyle will not invoke virial_fdotr_compute() int vflag_substyle; - if (vflag & VIRIAL_FDOTR) vflag_substyle = VIRIAL_NONE | (vflag & ~VIRIAL_FDOTR); + if (vflag & VIRIAL_FDOTR) vflag_substyle = vflag & ~VIRIAL_FDOTR; else vflag_substyle = vflag; double *saved_special = save_special(); @@ -140,6 +142,30 @@ void PairHybridKokkos::compute(int eflag, int vflag) for (j = 0; j < 6; j++) vatom[i][j] += vatom_substyle[i][j]; } + + // substyles may be CENTROID_SAME or CENTROID_AVAIL + + if (cvflag_atom) { + n = atom->nlocal; + if (force->newton_pair) n += atom->nghost; + if (styles[m]->centroidstressflag == CENTROID_AVAIL) { + double **cvatom_substyle = styles[m]->cvatom; + for (i = 0; i < n; i++) + for (j = 0; j < 9; j++) + cvatom[i][j] += cvatom_substyle[i][j]; + } else { + double **vatom_substyle = styles[m]->vatom; + for (i = 0; i < n; i++) { + for (j = 0; j < 6; j++) { + cvatom[i][j] += vatom_substyle[i][j]; + } + for (j = 6; j < 9; j++) { + cvatom[i][j] += vatom_substyle[i][j-3]; + } + } + } + } + } delete [] saved_special; diff --git a/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp b/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp index c815e2ad72..7b0e79075d 100644 --- a/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_overlay_kokkos.cpp @@ -13,12 +13,11 @@ ------------------------------------------------------------------------- */ #include "pair_hybrid_overlay_kokkos.h" -#include -#include + #include "atom.h" -#include "force.h" #include "error.h" +#include using namespace LAMMPS_NS; @@ -43,7 +42,7 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) // 4th arg = pair sub-style index if name used multiple times // allow for "none" as valid sub-style name - int multflag; + int multflag = 0; int m; for (m = 0; m < nstyles; m++) { @@ -52,10 +51,7 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) if (multiple[m]) { multflag = 1; if (narg < 4) error->all(FLERR,"Incorrect args for pair coefficients"); - if (!isdigit(arg[3][0])) - error->all(FLERR,"Incorrect args for pair coefficients"); - int index = utils::inumeric(FLERR,arg[3],false,lmp); - if (index == multiple[m]) break; + if (multiple[m] == utils::inumeric(FLERR,arg[3],false,lmp)) break; else continue; } else break; } @@ -74,9 +70,15 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) arg[2+multflag] = arg[1]; arg[1+multflag] = arg[0]; + // ensure that one_coeff flag is honored + + if (!none && styles[m]->one_coeff) + if ((strcmp(arg[0],"*") != 0) || (strcmp(arg[1],"*") != 0)) + error->all(FLERR,"Incorrect args for pair coefficients"); + // invoke sub-style coeff() starting with 1st remaining arg - if (!none) styles[m]->coeff(narg-1-multflag,&arg[1+multflag]); + if (!none) styles[m]->coeff(narg-1-multflag,arg+1+multflag); // set setflag and which type pairs map to which sub-style // if sub-style is none: set hybrid subflag, wipe out map @@ -104,3 +106,52 @@ void PairHybridOverlayKokkos::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } + + +/* ---------------------------------------------------------------------- + we need to handle Pair::svector special for hybrid/overlay +------------------------------------------------------------------------- */ + +void PairHybridOverlayKokkos::init_svector() +{ + // single_extra = list all sub-style single_extra + // allocate svector + + single_extra = 0; + for (int m = 0; m < nstyles; m++) + single_extra += styles[m]->single_extra; + + if (single_extra) { + delete [] svector; + svector = new double[single_extra]; + } +} + +/* ---------------------------------------------------------------------- + we need to handle Pair::svector special for hybrid/overlay +------------------------------------------------------------------------- */ + +void PairHybridOverlayKokkos::copy_svector(int itype, int jtype) +{ + int n=0; + Pair *this_style = nullptr; + + // fill svector array. + // copy data from active styles and use 0.0 for inactive ones + for (int m = 0; m < nstyles; m++) { + for (int k = 0; k < nmap[itype][jtype]; ++k) { + if (m == map[itype][jtype][k]) { + this_style = styles[m]; + } else { + this_style = nullptr; + } + } + for (int l = 0; l < styles[m]->single_extra; ++l) { + if (this_style) { + svector[n++] = this_style->svector[l]; + } else { + svector[n++] = 0.0; + } + } + } +} diff --git a/src/KOKKOS/pair_hybrid_overlay_kokkos.h b/src/KOKKOS/pair_hybrid_overlay_kokkos.h index e14e5929c9..0b2ff38d4f 100644 --- a/src/KOKKOS/pair_hybrid_overlay_kokkos.h +++ b/src/KOKKOS/pair_hybrid_overlay_kokkos.h @@ -29,6 +29,9 @@ class PairHybridOverlayKokkos : public PairHybridKokkos { public: PairHybridOverlayKokkos(class LAMMPS *); void coeff(int, char **) override; + + void init_svector() override; + void copy_svector(int, int) override; }; } diff --git a/src/KOKKOS/pair_kokkos.h b/src/KOKKOS/pair_kokkos.h index 2e2b24b662..af959ad63a 100644 --- a/src/KOKKOS/pair_kokkos.h +++ b/src/KOKKOS/pair_kokkos.h @@ -266,7 +266,7 @@ struct PairComputeFunctor { // Loop over neighbors of one atom without coulomb interaction // This function is called in parallel KOKKOS_FUNCTION - void compute_item_team(Kokkos::TeamPolicy<>::member_type team, + void compute_item_team(typename Kokkos::TeamPolicy::member_type team, const NeighListKokkos &list, const NoCoulTag&) const { const int inum = team.league_size(); @@ -322,7 +322,7 @@ struct PairComputeFunctor { // Loop over neighbors of one atom with coulomb interaction // This function is called in parallel KOKKOS_FUNCTION - void compute_item_team(Kokkos::TeamPolicy<>::member_type team, + void compute_item_team(typename Kokkos::TeamPolicy::member_type team, const NeighListKokkos &list, const CoulTag& ) const { const int inum = team.league_size(); @@ -383,7 +383,7 @@ struct PairComputeFunctor { // Loop over neighbors of one atom without coulomb interaction // This function is called in parallel KOKKOS_FUNCTION - EV_FLOAT compute_item_team_ev(Kokkos::TeamPolicy<>::member_type team, + EV_FLOAT compute_item_team_ev(typename Kokkos::TeamPolicy::member_type team, const NeighListKokkos &list, const NoCoulTag&) const { EV_FLOAT ev; @@ -478,7 +478,7 @@ struct PairComputeFunctor { // Loop over neighbors of one atom with coulomb interaction // This function is called in parallel KOKKOS_FUNCTION - EV_FLOAT compute_item_team_ev(Kokkos::TeamPolicy<>::member_type team, + EV_FLOAT compute_item_team_ev(typename Kokkos::TeamPolicy::member_type team, const NeighListKokkos &list, const CoulTag& ) const { EV_FLOAT ev; @@ -687,12 +687,12 @@ struct PairComputeFunctor { } KOKKOS_INLINE_FUNCTION - void operator()(const typename Kokkos::TeamPolicy<>::member_type& team) const { + void operator()(const typename Kokkos::TeamPolicy::member_type& team) const { compute_item_team(team,list,typename DoCoul::type()); } KOKKOS_INLINE_FUNCTION - void operator()(const typename Kokkos::TeamPolicy<>::member_type& team, value_type &energy_virial) const { + void operator()(const typename Kokkos::TeamPolicy::member_type& team, value_type &energy_virial) const { energy_virial += compute_item_team_ev(team,list,typename DoCoul::type()); } }; @@ -714,7 +714,7 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if +template int GetTeamSize(FunctorStyle& KOKKOS_GPU_ARG(functor), int KOKKOS_GPU_ARG(inum), int KOKKOS_GPU_ARG(reduce_flag), int team_size, int KOKKOS_GPU_ARG(vector_length)) { @@ -722,9 +722,9 @@ int GetTeamSize(FunctorStyle& KOKKOS_GPU_ARG(functor), int KOKKOS_GPU_ARG(inum), int team_size_max; if (reduce_flag) - team_size_max = Kokkos::TeamPolicy<>(inum,Kokkos::AUTO).team_size_max(functor,Kokkos::ParallelReduceTag()); + team_size_max = Kokkos::TeamPolicy(inum,Kokkos::AUTO).team_size_max(functor,Kokkos::ParallelReduceTag()); else - team_size_max = Kokkos::TeamPolicy<>(inum,Kokkos::AUTO).team_size_max(functor,Kokkos::ParallelForTag()); + team_size_max = Kokkos::TeamPolicy(inum,Kokkos::AUTO).team_size_max(functor,Kokkos::ParallelForTag()); if (team_size*vector_length > team_size_max) team_size = team_size_max/vector_length; @@ -749,14 +749,14 @@ EV_FLOAT pair_compute_neighlist (PairStyle* fpair, typename std::enable_if<(NEIG if (fpair->atom->ntypes > MAX_TYPES_STACKPARAMS) { 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); + 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); - 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); + 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); } diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp index 0764a35fac..4647b14ade 100644 --- a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp @@ -61,6 +61,8 @@ PairLJGromacsKokkos::~PairLJGromacsKokkos() memoryKK->destroy_kokkos(k_eatom,eatom); memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->destroy_kokkos(k_cutsq,cutsq); + memoryKK->destroy_kokkos(k_cut_inner,cut_inner); + memoryKK->destroy_kokkos(k_cut_inner_sq,cut_inner_sq); } } diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp index 1107d39fe9..820e0e4924 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp @@ -669,7 +669,7 @@ int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdua d_sendlist = k_sendlist.view(); iswap = iswap_in; v_buf = buf.view(); - Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); + Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; } @@ -687,7 +687,7 @@ void PairMultiLucyRXKokkos::unpack_forward_comm_kokkos(int n, int fi { first = first_in; v_buf = buf.view(); - Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); + Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); atomKK->modified(execution_space,DPDRHO_MASK); // needed for auto_sync } diff --git a/src/KOKKOS/pair_tersoff_kokkos.cpp b/src/KOKKOS/pair_tersoff_kokkos.cpp index 121d89d366..d98b690c9c 100644 --- a/src/KOKKOS/pair_tersoff_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_kokkos.cpp @@ -171,7 +171,7 @@ void PairTersoffKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -271,7 +271,7 @@ void PairTersoffKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -480,7 +480,7 @@ void PairTersoffKokkos::operator()(TagPairTersoffComputeHalf::operator()(TagPairTersoffComputeFullA::operator()(TagPairTersoffComputeFullB::v_tally3(EV_FLOAT &ev, const int &i, const i F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1233,6 +1233,13 @@ void PairTersoffKokkos::v_tally3(EV_FLOAT &ev, const int &i, const i } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { diff --git a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp index c3cdcca066..388e216a41 100644 --- a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp @@ -171,7 +171,7 @@ void PairTersoffMODKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -271,7 +271,7 @@ void PairTersoffMODKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -480,7 +480,7 @@ void PairTersoffMODKokkos::operator()(TagPairTersoffMODComputeHalf::operator()(TagPairTersoffMODComputeFullA< f_y += fi[1]; f_z += fi[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrij[3], delrik[3]; delrij[0] = -delx1; delrij[1] = -dely1; delrij[2] = -delz1; delrik[0] = -delx2; delrik[1] = -dely2; delrik[2] = -delz2; @@ -764,7 +764,7 @@ void PairTersoffMODKokkos::operator()(TagPairTersoffMODComputeFullB< f_y += fj[1]; f_z += fj[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrji[3], delrjk[3]; delrji[0] = -delx1; delrji[1] = -dely1; delrji[2] = -delz1; delrjk[0] = -delx2; delrjk[1] = -dely2; delrjk[2] = -delz2; @@ -1219,12 +1219,12 @@ void PairTersoffMODKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1236,6 +1236,13 @@ void PairTersoffMODKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index 011cb8ebc6..d718e2a785 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -31,6 +31,7 @@ #include "memory_kokkos.h" #include "error.h" #include "atom_masks.h" +#include "suffix.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -44,6 +45,7 @@ template PairTersoffZBLKokkos::PairTersoffZBLKokkos(LAMMPS *lmp) : PairTersoffZBL(lmp) { respa_enable = 0; + suffix_flag |= Suffix::KOKKOS; kokkosable = 1; atomKK = (AtomKokkos *) atom; @@ -185,7 +187,7 @@ void PairTersoffZBLKokkos::compute(int eflag_in, int vflag_in) memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom"); d_eatom = k_eatom.view(); } - if (vflag_atom) { + if (vflag_either) { memoryKK->destroy_kokkos(k_vatom,vatom); memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"pair:vatom"); d_vatom = k_vatom.view(); @@ -285,7 +287,7 @@ void PairTersoffZBLKokkos::compute(int eflag_in, int vflag_in) k_eatom.template sync(); } - if (vflag_atom) { + if (vflag_either) { if (need_dup) Kokkos::Experimental::contribute(d_vatom, dup_vatom); k_vatom.template modify(); @@ -524,7 +526,7 @@ void PairTersoffZBLKokkos::operator()(TagPairTersoffZBLComputeHalf::operator()(TagPairTersoffZBLComputeFullA< f_y += fi[1]; f_z += fi[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrij[3], delrik[3]; delrij[0] = -delx1; delrij[1] = -dely1; delrij[2] = -delz1; delrik[0] = -delx2; delrik[1] = -dely2; delrik[2] = -delz2; @@ -838,7 +840,7 @@ void PairTersoffZBLKokkos::operator()(TagPairTersoffZBLComputeFullB< f_y += fj[1]; f_z += fj[2]; - if (vflag_atom) { + if (vflag_either) { F_FLOAT delrji[3], delrjk[3]; delrji[0] = -delx1; delrji[1] = -dely1; delrji[2] = -delz1; delrjk[0] = -delx2; delrjk[1] = -dely2; delrjk[2] = -delz2; @@ -1313,12 +1315,12 @@ void PairTersoffZBLKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons F_FLOAT v[6]; - v[0] = THIRD * (drij[0]*fj[0] + drik[0]*fk[0]); - v[1] = THIRD * (drij[1]*fj[1] + drik[1]*fk[1]); - v[2] = THIRD * (drij[2]*fj[2] + drik[2]*fk[2]); - v[3] = THIRD * (drij[0]*fj[1] + drik[0]*fk[1]); - v[4] = THIRD * (drij[0]*fj[2] + drik[0]*fk[2]); - v[5] = THIRD * (drij[1]*fj[2] + drik[1]*fk[2]); + v[0] = (drij[0]*fj[0] + drik[0]*fk[0]); + v[1] = (drij[1]*fj[1] + drik[1]*fk[1]); + v[2] = (drij[2]*fj[2] + drik[2]*fk[2]); + v[3] = (drij[0]*fj[1] + drik[0]*fk[1]); + v[4] = (drij[0]*fj[2] + drik[0]*fk[2]); + v[5] = (drij[1]*fj[2] + drik[1]*fk[2]); if (vflag_global) { ev.v[0] += v[0]; @@ -1330,6 +1332,13 @@ void PairTersoffZBLKokkos::v_tally3(EV_FLOAT &ev, const int &i, cons } if (vflag_atom) { + v[0] *= THIRD; + v[1] *= THIRD; + v[2] *= THIRD; + v[3] *= THIRD; + v[4] *= THIRD; + v[5] *= THIRD; + a_vatom(i,0) += v[0]; a_vatom(i,1) += v[1]; a_vatom(i,2) += v[2]; a_vatom(i,3) += v[3]; a_vatom(i,4) += v[4]; a_vatom(i,5) += v[5]; if (NEIGHFLAG != FULL) { diff --git a/src/KOKKOS/pppm_kokkos.cpp b/src/KOKKOS/pppm_kokkos.cpp index da18bba001..a5073129e8 100644 --- a/src/KOKKOS/pppm_kokkos.cpp +++ b/src/KOKKOS/pppm_kokkos.cpp @@ -2711,10 +2711,9 @@ void PPPMKokkos::compute_rho_coeff() { int j,k,l,m; FFT_SCALAR s; - - //FFT_SCALAR **a; - //memory->create2d_offset(a,order,-order,order,"pppm:a"); - FFT_SCALAR a[order][2*order+1]; + FFT_SCALAR **a = new FFT_SCALAR *[order]; + for (int i = 0; i < order; ++i) + a[i] = new FFT_SCALAR[2*order+1]; for (k = 0; k <= 2*order; k++) for (l = 0; l < order; l++) @@ -2744,7 +2743,9 @@ void PPPMKokkos::compute_rho_coeff() h_rho_coeff(l,m-(1-order)/2) = a[l][k+order]; m++; } - //memory->destroy2d_offset(a,-order); + for (int i = 0; i < order; ++i) + delete[] a[i]; + delete[] a; } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index da4a2ad658..a6bfba3e6f 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -820,15 +820,8 @@ void MSM::deallocate_levels() { if (world_levels) { for (int n=0; n < levels; ++n) { - if (qgrid[n]) { - memory->destroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); - qgrid[n] = nullptr; - } - - if (egrid[n]) { - memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); - egrid[n] = nullptr; - } + memory->destroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); + memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); if (gc) { if (gc[n]) { @@ -1093,6 +1086,8 @@ void MSM::set_grid_global() h_z = 1.0/tmp[2]; } + deallocate_levels(); + // find maximum number of levels levels = MAX(xlevels,ylevels); @@ -1106,15 +1101,13 @@ void MSM::set_grid_global() levels = xlevels = ylevels = zlevels = 2; nx_max = ny_max = nz_max = 2; if (gridflag) - error->warning(FLERR, - "MSM mesh too small, increasing to 2 points in each direction"); + error->warning(FLERR,"MSM mesh too small, increasing to 2 points in each direction"); } // omit top grid level for periodic systems if (!domain->nonperiodic) levels -= 1; - deallocate_levels(); allocate_levels(); // find number of grid levels in each direction @@ -1141,33 +1134,19 @@ void MSM::set_grid_global() error->all(FLERR,"MSM grid is too large"); // compute number of extra grid points needed for non-periodic boundary conditions + // need to always do this, so we can handle the case of switching from periodic + // to non-periodic. - if (domain->nonperiodic) { - alpha[0] = -(order/2 - 1); - betax[0] = nx_msm[0] + (order/2 - 1); - betay[0] = ny_msm[0] + (order/2 - 1); - betaz[0] = nz_msm[0] + (order/2 - 1); - for (int n = 1; n < levels; n++) { - alpha[n] = -((-alpha[n-1]+1)/2) - (order/2 - 1); - betax[n] = ((betax[n-1]+1)/2) + (order/2 - 1); - betay[n] = ((betay[n-1]+1)/2) + (order/2 - 1); - betaz[n] = ((betaz[n-1]+1)/2) + (order/2 - 1); - } + alpha[0] = -(order/2 - 1); + betax[0] = nx_msm[0] + (order/2 - 1); + betay[0] = ny_msm[0] + (order/2 - 1); + betaz[0] = nz_msm[0] + (order/2 - 1); + for (int n = 1; n < levels; n++) { + alpha[n] = -((-alpha[n-1]+1)/2) - (order/2 - 1); + betax[n] = ((betax[n-1]+1)/2) + (order/2 - 1); + betay[n] = ((betay[n-1]+1)/2) + (order/2 - 1); + betaz[n] = ((betaz[n-1]+1)/2) + (order/2 - 1); } - - if (domain->nonperiodic) { - alpha[0] = -(order/2 - 1); - betax[0] = nx_msm[0] + (order/2 - 1); - betay[0] = ny_msm[0] + (order/2 - 1); - betaz[0] = nz_msm[0] + (order/2 - 1); - for (int n = 1; n < levels; n++) { - alpha[n] = -((-alpha[n-1]+1)/2) - (order/2 - 1); - betax[n] = ((betax[n-1]+1)/2) + (order/2 - 1); - betay[n] = ((betay[n-1]+1)/2) + (order/2 - 1); - betaz[n] = ((betaz[n-1]+1)/2) + (order/2 - 1); - } - } - } /* ---------------------------------------------------------------------- @@ -1182,6 +1161,10 @@ void MSM::set_grid_local() for (int n=0; ndestroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); + memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); + // partition global grid across procs // n xyz lo/hi in[] = lower/upper bounds of global grid this proc owns // indices range from 0 to N-1 inclusive in each dim @@ -3267,7 +3250,7 @@ void MSM::get_g_direct_top(int n) int nmax_top = 8*(nx+1)*(ny*1)*(nz+1); - if (g_direct_top) memory->destroy(g_direct_top); + memory->destroy(g_direct_top); memory->create(g_direct_top,nmax_top,"msm:g_direct_top"); double a = cutoff; diff --git a/src/KSPACE/msm.h b/src/KSPACE/msm.h index 75cba695fd..980d8182f8 100644 --- a/src/KSPACE/msm.h +++ b/src/KSPACE/msm.h @@ -111,8 +111,8 @@ class MSM : public KSpace { void allocate_levels(); void deallocate_levels(); int factorable(int, int &, int &); - void particle_map(); - void make_rho(); + virtual void particle_map(); + virtual void make_rho(); virtual void direct(int); void direct_peratom(int); void direct_top(int); @@ -121,8 +121,8 @@ class MSM : public KSpace { void prolongation(int); void grid_swap_forward(int, double ***&); void grid_swap_reverse(int, double ***&); - void fieldforce(); - void fieldforce_peratom(); + virtual void fieldforce(); + virtual void fieldforce_peratom(); void compute_phis(const double &, const double &, const double &); void compute_phis_and_dphis(const double &, const double &, const double &); inline double compute_phi(const double &); diff --git a/src/KSPACE/msm_cg.h b/src/KSPACE/msm_cg.h index 00680589b5..9ab78ba65d 100644 --- a/src/KSPACE/msm_cg.h +++ b/src/KSPACE/msm_cg.h @@ -38,10 +38,10 @@ class MSMCG : public MSM { double smallq; protected: - virtual void particle_map(); - virtual void make_rho(); - virtual void fieldforce(); - virtual void fieldforce_peratom(); + void particle_map() override; + void make_rho() override; + void fieldforce() override; + void fieldforce_peratom() override; }; } // namespace LAMMPS_NS diff --git a/src/MC/fix_bond_create.cpp b/src/MC/fix_bond_create.cpp index 22cf5fc911..e245b2d738 100644 --- a/src/MC/fix_bond_create.cpp +++ b/src/MC/fix_bond_create.cpp @@ -412,6 +412,14 @@ void FixBondCreate::post_integrate() int *mask = atom->mask; int *type = atom->type; + if (constrainflag) { + // communicate partner and 1-2 special neighbors + // to correctly handle angle constraints + + commflag = 3; + comm->forward_comm_fix(this); + } + neighbor->build_one(list,1); inum = list->inum; ilist = list->ilist; diff --git a/src/Makefile b/src/Makefile index eeccc19ae0..44cebcb20c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -183,7 +183,6 @@ PACKMOST = \ orient \ peri \ plugin \ - poems \ qeq \ reaction \ reaxff \ diff --git a/src/OPENMP/msm_cg_omp.h b/src/OPENMP/msm_cg_omp.h index 253851bb5a..7ad12c8123 100644 --- a/src/OPENMP/msm_cg_omp.h +++ b/src/OPENMP/msm_cg_omp.h @@ -38,10 +38,10 @@ class MSMCGOMP : public MSMOMP { double smallq; protected: - virtual void particle_map(); - virtual void make_rho(); - virtual void fieldforce(); - virtual void fieldforce_peratom(); + void particle_map() override; + void make_rho() override; + void fieldforce() override; + void fieldforce_peratom() override; }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/pair_reaxff_omp.cpp b/src/OPENMP/pair_reaxff_omp.cpp index 454f56c55f..be270cd3d0 100644 --- a/src/OPENMP/pair_reaxff_omp.cpp +++ b/src/OPENMP/pair_reaxff_omp.cpp @@ -117,7 +117,6 @@ void PairReaxFFOMP::init_style() api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts - api->system->bigN = static_cast (atom->natoms); // all atoms in the system api->system->wsize = comm->nprocs; if (atom->tag_enable == 0) @@ -125,11 +124,6 @@ void PairReaxFFOMP::init_style() if (force->newton_pair == 0) error->all(FLERR,"Pair style reaxff/omp requires newton pair on"); - // because system->bigN is an int, we cannot have more atoms than MAXSMALLINT - - if (atom->natoms > MAXSMALLINT) - error->all(FLERR,"Too many atoms for pair style reaxff/omp"); - // need a half neighbor list w/ Newton off and ghost neighbors // built whenever re-neighboring occurs @@ -159,7 +153,6 @@ void PairReaxFFOMP::setup() api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts oldN = api->system->N; - api->system->bigN = static_cast (atom->natoms); // all atoms in the system if (api->system->N > nmax) { memory->destroy(num_nbrs_offset); @@ -226,7 +219,6 @@ void PairReaxFFOMP::setup() void PairReaxFFOMP::compute(int eflag, int vflag) { - double evdwl,ecoul; // communicate num_bonds once every reneighboring // 2 num arrays stored by fix, grab ptr to them @@ -235,12 +227,10 @@ void PairReaxFFOMP::compute(int eflag, int vflag) int *num_bonds = fix_reaxff->num_bonds; int *num_hbonds = fix_reaxff->num_hbonds; - evdwl = ecoul = 0.0; ev_init(eflag,vflag); api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts - api->system->bigN = static_cast (atom->natoms); // all atoms in the system const int nall = api->system->N; #if defined(_OPENMP) @@ -304,20 +294,6 @@ void PairReaxFFOMP::compute(int eflag, int vflag) // energies and pressure if (eflag_global) { - evdwl += api->data->my_en.e_bond; - evdwl += api->data->my_en.e_ov; - evdwl += api->data->my_en.e_un; - evdwl += api->data->my_en.e_lp; - evdwl += api->data->my_en.e_ang; - evdwl += api->data->my_en.e_pen; - evdwl += api->data->my_en.e_coa; - evdwl += api->data->my_en.e_hb; - evdwl += api->data->my_en.e_tor; - evdwl += api->data->my_en.e_con; - evdwl += api->data->my_en.e_vdW; - - ecoul += api->data->my_en.e_ele; - ecoul += api->data->my_en.e_pol; // Store the different parts of the energy // in a list for output by compute pair command diff --git a/src/PHONON/dynamical_matrix.cpp b/src/PHONON/dynamical_matrix.cpp index 3a596bfd05..11dc5625b9 100644 --- a/src/PHONON/dynamical_matrix.cpp +++ b/src/PHONON/dynamical_matrix.cpp @@ -282,10 +282,11 @@ void DynamicalMatrix::calculateMatrix() dynmat_clear(dynmat); if (me == 0 && screen) { - fprintf(screen,"Calculating Dynamical Matrix ...\n"); - fprintf(screen," Total # of atoms = " BIGINT_FORMAT "\n", natoms); - fprintf(screen," Atoms in group = " BIGINT_FORMAT "\n", gcount); - fprintf(screen," Total dynamical matrix elements = " BIGINT_FORMAT "\n", (dynlen*dynlen) ); + fputs("Calculating Dynamical Matrix ...\n", screen); + fmt::print(screen," Total # of atoms = {}\n" + " Atoms in group = {}\n" + " Total dynamical matrix elements = {}\n", + natoms, gcount, dynlen*dynlen); } // emit dynlen rows of dimalpha*dynlen*dimbeta elements diff --git a/src/PHONON/third_order.cpp b/src/PHONON/third_order.cpp index 7bc03aaf6f..0f70a591d8 100644 --- a/src/PHONON/third_order.cpp +++ b/src/PHONON/third_order.cpp @@ -232,6 +232,7 @@ void ThirdOrder::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR, "Illegal third_order command"); filename = arg[iarg + 1]; file_flag = 1; + iarg += 2; } else if (strcmp(arg[iarg],"fold") == 0) { if (iarg+2 > narg) error->all(FLERR, "Illegal Third Order command"); if (strcmp(arg[iarg+1],"yes") == 0) { @@ -300,11 +301,11 @@ void ThirdOrder::calculateMatrix() getNeighbortags(); if (comm->me == 0 && screen) { - fprintf(screen, "Calculating Third Order ...\n"); - fprintf(screen, " Total # of atoms = " BIGINT_FORMAT "\n", natoms); - fprintf(screen, " Atoms in group = " BIGINT_FORMAT "\n", gcount); - fprintf(screen, " Total third order elements = " - BIGINT_FORMAT "\n", (dynlen * dynlen * dynlen)); + fputs("Calculating Third Order ...\n", screen); + fmt::print(screen," Total # of atoms = {}\n" + " Atoms in group = {}\n" + " Total third order elements = {}\n", + natoms, gcount, dynlen*dynlen*dynlen); } update->nsteps = 0; @@ -436,31 +437,19 @@ void ThirdOrder::writeMatrix(double *dynmat, bigint i, int a, bigint j, int b) clearerr(fp); if (folded){ for (int k = 0; k < atom->natoms; k++){ - norm = square(dynmat[k*3])+ - square(dynmat[k*3+1])+ - square(dynmat[k*3+2]); + norm = square(dynmat[k*3])+square(dynmat[k*3+1])+square(dynmat[k*3+2]); if (norm > 1.0e-16) - fprintf(fp, - BIGINT_FORMAT " %d " BIGINT_FORMAT " %d " BIGINT_FORMAT - " %7.8f %7.8f %7.8f\n", - i+1, a + 1, j+1, b + 1, k+1, - dynmat[k*3] * conversion, - dynmat[k*3+1] * conversion, - dynmat[k*3+2] * conversion); + fmt::print(fp, "{} {} {} {} {} {:17.8f} {:17.8f} {:17.8f}\n", + i+1, a+1, j+1, b+1, k+1, dynmat[k*3] * conversion, + dynmat[k*3+1] * conversion, dynmat[k*3+2] * conversion); } } else { for (int k = 0; k < gcount; k++){ - norm = square(dynmat[k*3])+ - square(dynmat[k*3+1])+ - square(dynmat[k*3+2]); + norm = square(dynmat[k*3])+square(dynmat[k*3+1])+square(dynmat[k*3+2]); if (norm > 1.0e-16) - fprintf(fp, - BIGINT_FORMAT " %d " BIGINT_FORMAT " %d " BIGINT_FORMAT - " %7.8f %7.8f %7.8f\n", - i+1, a + 1, j+1, b + 1, groupmap[k]+1, - dynmat[k*3] * conversion, - dynmat[k*3+1] * conversion, - dynmat[k*3+2] * conversion); + fmt::print(fp, "{} {} {} {} {} {:17.8f} {:17.8f} {:17.8f}\n", + i+1, a+1, j+1, b+1, groupmap[k]+1, dynmat[k*3] * conversion, + dynmat[k*3+1] * conversion, dynmat[k*3+2] * conversion); } } } else if (binaryflag && fp) { @@ -672,8 +661,7 @@ void ThirdOrder::create_groupmap() } //combine subgroup maps into total temporary groupmap - MPI_Allgatherv(sub_groupmap,gid,MPI_LMP_BIGINT, - temp_groupmap,recv,displs,MPI_LMP_BIGINT,world); + MPI_Allgatherv(sub_groupmap,gid,MPI_LMP_BIGINT,temp_groupmap,recv,displs,MPI_LMP_BIGINT,world); std::sort(temp_groupmap,temp_groupmap+gcount); //populate member groupmap based on temp groupmap diff --git a/src/REAXFF/pair_reaxff.cpp b/src/REAXFF/pair_reaxff.cpp index 9a3bdf2f79..f7b4056427 100644 --- a/src/REAXFF/pair_reaxff.cpp +++ b/src/REAXFF/pair_reaxff.cpp @@ -90,7 +90,6 @@ PairReaxFF::PairReaxFF(LAMMPS *lmp) : Pair(lmp) api->system->num_nbrs = 0; api->system->n = 0; // my atoms api->system->N = 0; // mine + ghosts - api->system->bigN = 0; // all atoms in the system api->system->local_cap = 0; api->system->total_cap = 0; api->system->my_atoms = nullptr; @@ -348,7 +347,6 @@ void PairReaxFF::init_style() api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts - api->system->bigN = static_cast (atom->natoms); // all atoms in the system api->system->wsize = comm->nprocs; if (atom->tag_enable == 0) @@ -356,11 +354,6 @@ void PairReaxFF::init_style() if (force->newton_pair == 0) error->all(FLERR,"Pair style reaxff requires newton pair on"); - // because system->bigN is an int, we cannot have more atoms than MAXSMALLINT - - if (atom->natoms > MAXSMALLINT) - error->all(FLERR,"Too many atoms for pair style reaxff"); - // need a half neighbor list w/ Newton off and ghost neighbors // built whenever re-neighboring occurs @@ -388,7 +381,6 @@ void PairReaxFF::setup() api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts oldN = api->system->N; - api->system->bigN = static_cast (atom->natoms); // all atoms in the system if (setup_flag == 0) { @@ -455,8 +447,6 @@ double PairReaxFF::init_one(int i, int j) void PairReaxFF::compute(int eflag, int vflag) { - double evdwl,ecoul; - // communicate num_bonds once every reneighboring // 2 num arrays stored by fix, grab ptr to them @@ -464,12 +454,10 @@ void PairReaxFF::compute(int eflag, int vflag) int *num_bonds = fix_reaxff->num_bonds; int *num_hbonds = fix_reaxff->num_hbonds; - evdwl = ecoul = 0.0; ev_init(eflag,vflag); api->system->n = atom->nlocal; // my atoms api->system->N = atom->nlocal + atom->nghost; // mine + ghosts - api->system->bigN = static_cast (atom->natoms); // all atoms in the system if (api->system->acks2_flag) { auto ifix = modify->get_fix_by_style("^acks2/reax").front(); @@ -496,20 +484,6 @@ void PairReaxFF::compute(int eflag, int vflag) // energies and pressure if (eflag_global) { - evdwl += api->data->my_en.e_bond; - evdwl += api->data->my_en.e_ov; - evdwl += api->data->my_en.e_un; - evdwl += api->data->my_en.e_lp; - evdwl += api->data->my_en.e_ang; - evdwl += api->data->my_en.e_pen; - evdwl += api->data->my_en.e_coa; - evdwl += api->data->my_en.e_hb; - evdwl += api->data->my_en.e_tor; - evdwl += api->data->my_en.e_con; - evdwl += api->data->my_en.e_vdW; - - ecoul += api->data->my_en.e_ele; - ecoul += api->data->my_en.e_pol; // Store the different parts of the energy // in a list for output by compute pair command diff --git a/src/REAXFF/reaxff_types.h b/src/REAXFF/reaxff_types.h index 1eac663e52..94818f6ebf 100644 --- a/src/REAXFF/reaxff_types.h +++ b/src/REAXFF/reaxff_types.h @@ -196,7 +196,6 @@ struct LR_lookup_table; // forward declaration struct reax_system { reax_interaction reax_param; - rc_bigint bigN; int n, N, numH; int local_cap, total_cap, Hcap; int wsize, my_rank, num_nbrs; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index cbaef073da..e09d4eb569 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -1351,8 +1351,8 @@ void FixRigidSmall::set_xv() vr[4] = 0.5*x0*fc2; vr[5] = 0.5*x1*fc2; - double rlist[][3] = {x0, x1, x2}; - double flist[][3] = {0.5*fc0, 0.5*fc1, 0.5*fc2}; + double rlist[1][3] = {{x0, x1, x2}}; + double flist[1][3] = {{0.5*fc0, 0.5*fc1, 0.5*fc2}}; v_tally(1,&i,1.0,vr,rlist,flist,b->xgc); } } @@ -1513,8 +1513,8 @@ void FixRigidSmall::set_v() vr[4] = 0.5*x0*fc2; vr[5] = 0.5*x1*fc2; - double rlist[][3] = {x0, x1, x2}; - double flist[][3] = {0.5*fc0, 0.5*fc1, 0.5*fc2}; + double rlist[1][3] = {{x0, x1, x2}}; + double flist[1][3] = {{0.5*fc0, 0.5*fc1, 0.5*fc2}}; v_tally(1,&i,1.0,vr,rlist,flist,b->xgc); } } diff --git a/src/atom.cpp b/src/atom.cpp index 0b448a5433..3a3d537ce3 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -54,6 +54,15 @@ using namespace MathConst; #define DELTA_PERATOM 64 #define EPSILON 1.0e-6 +/* ---------------------------------------------------------------------- + one instance per AtomVec style in style_atom.h +------------------------------------------------------------------------- */ + +template static AtomVec *avec_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ /** \class LAMMPS_NS::Atom @@ -743,16 +752,6 @@ AtomVec *Atom::new_avec(const std::string &style, int trysuffix, int &sflag) return nullptr; } -/* ---------------------------------------------------------------------- - one instance per AtomVec style in style_atom.h -------------------------------------------------------------------------- */ - -template -AtomVec *Atom::avec_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- */ void Atom::init() diff --git a/src/atom.h b/src/atom.h index ad8349d11c..2c1acb7805 100644 --- a/src/atom.h +++ b/src/atom.h @@ -416,9 +416,6 @@ class Atom : protected Pointers { void set_atomflag_defaults(); void setup_sort_bins(); int next_prime(int); - - private: - template static AtomVec *avec_creator(LAMMPS *); }; } // namespace LAMMPS_NS diff --git a/src/domain.cpp b/src/domain.cpp index 22c38c977a..29244dff6a 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -47,6 +47,15 @@ using namespace LAMMPS_NS; #define DELTAREGION 4 #define BONDSTRETCH 1.1 +/* ---------------------------------------------------------------------- + one instance per region style in style_region.h +------------------------------------------------------------------------- */ + +template static Region *region_creator(LAMMPS *lmp, int narg, char ** arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- default is periodic ------------------------------------------------------------------------- */ @@ -1797,16 +1806,6 @@ void Domain::add_region(int narg, char **arg) nregion++; } -/* ---------------------------------------------------------------------- - one instance per region style in style_region.h -------------------------------------------------------------------------- */ - -template -Region *Domain::region_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); -} - /* ---------------------------------------------------------------------- delete a region ------------------------------------------------------------------------- */ diff --git a/src/domain.h b/src/domain.h index a3a526610e..68ff5aece5 100644 --- a/src/domain.h +++ b/src/domain.h @@ -175,9 +175,6 @@ class Domain : protected Pointers { protected: double small[3]; // fractions of box lengths - - private: - template static Region *region_creator(LAMMPS *, int, char **); }; } // namespace LAMMPS_NS diff --git a/src/dump.cpp b/src/dump.cpp index 46622c2efa..f11f21f71e 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -952,76 +952,67 @@ void Dump::balance() int nswap = 0; MPI_Request *request = new MPI_Request[nprocs]; - int procstart = 0; - int iproc = me; - int iproc_prev; - for (int i = 0; i < nme_balance; i++) { + // find which proc starting atom belongs to - // find which proc this atom belongs to + int startproc = me; + while (proc_new_offsets[me] < proc_offsets[startproc]) startproc--; + while (proc_new_offsets[me] > proc_offsets[startproc+1]-1) startproc++; - while (proc_new_offsets[me] + i < proc_offsets[iproc]) iproc--; - while (proc_new_offsets[me] + i > proc_offsets[iproc+1]-1) iproc++; + // find which proc ending atom belongs to - if (i != 0 && (iproc != iproc_prev || i == nme_balance - 1)) { + int endproc = me; + while (proc_new_offsets[me] + nme_balance-1 < proc_offsets[endproc]) endproc--; + while (proc_new_offsets[me] + nme_balance-1 > proc_offsets[endproc+1]-1) endproc++; - // finished with proc + // loop over procs - int procrecv = iproc; - if (iproc != iproc_prev) procrecv = iproc_prev; + for (int iproc = startproc; iproc <= endproc; iproc++) { + int istart = MAX(0, proc_offsets[iproc] - proc_new_offsets[me]); + int iend = MIN(nme_balance-1, proc_offsets[iproc+1]-1 - proc_new_offsets[me]); + int nrecv = iend - istart + 1; + if (nrecv == 0) continue; - int procnrecv = i - procstart + 1; - if (iproc != iproc_prev) procnrecv--; + // post receive for this proc - // post receive for this proc - - if (iproc_prev != me) - MPI_Irecv(&buf_balance[procstart*size_one],procnrecv*size_one,MPI_DOUBLE, - procrecv,0,world,&request[nswap++]); - - procstart = i; - } - - iproc_prev = iproc; + if (iproc != me) + MPI_Irecv(&buf_balance[istart*size_one],nrecv*size_one,MPI_DOUBLE, + iproc,0,world,&request[nswap++]); } // compute which atoms I am sending and to which procs - procstart = 0; - iproc = me; - for (int i = 0; i < nme; i++) { + // find which proc starting atom belongs to - // find which proc this atom should belong to + startproc = me; + while (proc_offsets[me] < proc_new_offsets[startproc]) startproc--; + while (proc_offsets[me] > proc_new_offsets[startproc+1]-1) startproc++; - while (proc_offsets[me] + i < proc_new_offsets[iproc]) iproc--; - while (proc_offsets[me] + i > proc_new_offsets[iproc+1] - 1) iproc++; + // find which proc ending atom belongs to - if (i != 0 && (iproc != iproc_prev || i == nme - 1)) { + endproc = me; + while (proc_offsets[me] + nme-1 < proc_new_offsets[endproc]) endproc--; + while (proc_offsets[me] + nme-1 > proc_new_offsets[endproc+1]-1) endproc++; - // finished with proc + // loop over procs - int procsend = iproc; - if (iproc != iproc_prev) procsend = iproc_prev; + for (int iproc = startproc; iproc <= endproc; iproc++) { + int istart = MAX(0,proc_new_offsets[iproc] - proc_offsets[me]); + int iend = MIN(nme-1,proc_new_offsets[iproc+1]-1 - proc_offsets[me]); + int nsend = iend - istart + 1; + if (nsend == 0) continue; - int procnsend = i - procstart + 1; - if (iproc != iproc_prev) procnsend--; + // send for this proc - // send for this proc + if (iproc != me) { + MPI_Send(&buf[istart*size_one],nsend*size_one,MPI_DOUBLE,iproc,0,world); + } else { - if (iproc_prev != me) { - MPI_Send(&buf[procstart*size_one],procnsend*size_one,MPI_DOUBLE,procsend,0,world); - } else { + // sending to self, copy buffers - // sending to self, copy buffers - - int offset_me = proc_offsets[me] - proc_new_offsets[me]; - memcpy(&buf_balance[(offset_me + procstart)*size_one],&buf[procstart*size_one],sizeof(double)*procnsend*size_one); - } - - procstart = i; + int offset_me = proc_offsets[me] - proc_new_offsets[me]; + memcpy(&buf_balance[(offset_me + istart)*size_one],&buf[istart*size_one],sizeof(double)*nsend*size_one); } - - iproc_prev = iproc; } // wait for all recvs diff --git a/src/error.cpp b/src/error.cpp index e2162cf661..912093c865 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -213,8 +213,7 @@ void Error::one(const std::string &file, int line, const std::string &str) throw LAMMPSAbortException(mesg, world); #else - if (screen) fflush(screen); - if (logfile) fflush(logfile); + utils::flush_buffers(lmp); KokkosLMP::finalize(); MPI_Abort(world,1); exit(1); // to trick "smart" compilers into believing this does not return diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 68893701a0..de24d9d652 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -393,7 +393,6 @@ void FixDeform::init() // error if more than one fix deform // domain, fix nvt/sllod, compute temp/deform only work on single h_rate - int count = 0; if (modify->get_fix_by_style("deform").size() > 1) error->all(FLERR,"More than one fix deform"); diff --git a/src/force.cpp b/src/force.cpp index 333a6e4715..35bd8644ee 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -25,8 +24,8 @@ #include "bond_hybrid.h" #include "dihedral_hybrid.h" #include "improper_hybrid.h" -#include "pair_hybrid.h" #include "kspace.h" +#include "pair_hybrid.h" #include "atom.h" #include "comm.h" @@ -36,6 +35,14 @@ using namespace LAMMPS_NS; +// template for factory functions: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static S *style_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ Force::Force(LAMMPS *lmp) : Pointers(lmp) @@ -49,8 +56,8 @@ Force::Force(LAMMPS *lmp) : Pointers(lmp) special_extra = 0; dielectric = 1.0; - qqr2e_lammps_real = 332.06371; // these constants are toggled - qqr2e_charmm_real = 332.0716; // by new CHARMM pair styles + qqr2e_lammps_real = 332.06371; // these constants are toggled + qqr2e_charmm_real = 332.0716; // by new CHARMM pair styles pair = nullptr; bond = nullptr; @@ -77,54 +84,48 @@ void _noopt Force::create_factories() pair_map = new PairCreatorMap(); #define PAIR_CLASS -#define PairStyle(key,Class) \ - (*pair_map)[#key] = &pair_creator; -#include "style_pair.h" // IWYU pragma: keep +#define PairStyle(key, Class) (*pair_map)[#key] = &style_creator; +#include "style_pair.h" // IWYU pragma: keep #undef PairStyle #undef PAIR_CLASS bond_map = new BondCreatorMap(); #define BOND_CLASS -#define BondStyle(key,Class) \ - (*bond_map)[#key] = &bond_creator; -#include "style_bond.h" // IWYU pragma: keep +#define BondStyle(key, Class) (*bond_map)[#key] = &style_creator; +#include "style_bond.h" // IWYU pragma: keep #undef BondStyle #undef BOND_CLASS angle_map = new AngleCreatorMap(); #define ANGLE_CLASS -#define AngleStyle(key,Class) \ - (*angle_map)[#key] = &angle_creator; -#include "style_angle.h" // IWYU pragma: keep +#define AngleStyle(key, Class) (*angle_map)[#key] = &style_creator; +#include "style_angle.h" // IWYU pragma: keep #undef AngleStyle #undef ANGLE_CLASS dihedral_map = new DihedralCreatorMap(); #define DIHEDRAL_CLASS -#define DihedralStyle(key,Class) \ - (*dihedral_map)[#key] = &dihedral_creator; -#include "style_dihedral.h" // IWYU pragma: keep +#define DihedralStyle(key, Class) (*dihedral_map)[#key] = &style_creator; +#include "style_dihedral.h" // IWYU pragma: keep #undef DihedralStyle #undef DIHEDRAL_CLASS improper_map = new ImproperCreatorMap(); #define IMPROPER_CLASS -#define ImproperStyle(key,Class) \ - (*improper_map)[#key] = &improper_creator; -#include "style_improper.h" // IWYU pragma: keep +#define ImproperStyle(key, Class) (*improper_map)[#key] = &style_creator; +#include "style_improper.h" // IWYU pragma: keep #undef ImproperStyle #undef IMPROPER_CLASS kspace_map = new KSpaceCreatorMap(); #define KSPACE_CLASS -#define KSpaceStyle(key,Class) \ - (*kspace_map)[#key] = &kspace_creator; -#include "style_kspace.h" // IWYU pragma: keep +#define KSpaceStyle(key, Class) (*kspace_map)[#key] = &style_creator; +#include "style_kspace.h" // IWYU pragma: keep #undef KSpaceStyle #undef KSPACE_CLASS } @@ -168,17 +169,17 @@ Force::~Force() void Force::init() { - qqrd2e = qqr2e/dielectric; + qqrd2e = qqr2e / dielectric; // check if pair style must be specified after restart if (pair_restart) { if (!pair) - error->all(FLERR,"Must re-specify non-restarted pair style " - "({}) after read_restart", pair_restart); + error->all(FLERR, "Must re-specify non-restarted pair style ({}) after read_restart", + pair_restart); } - if (kspace) kspace->init(); // kspace must come before pair - if (pair) pair->init(); // so g_ewald is defined + if (kspace) kspace->init(); // kspace must come before pair + if (pair) pair->init(); // so g_ewald is defined if (bond) bond->init(); if (angle) angle->init(); if (dihedral) dihedral->init(); @@ -188,22 +189,22 @@ void Force::init() if (comm->me == 0) { if (!bond && (atom->nbonds > 0)) { - error->warning(FLERR,"Bonds are defined but no bond style is set"); + error->warning(FLERR, "Bonds are defined but no bond style is set"); if ((special_lj[1] != 1.0) || (special_coul[1] != 1.0)) - error->warning(FLERR,"Likewise 1-2 special neighbor interactions != 1.0"); + error->warning(FLERR, "Likewise 1-2 special neighbor interactions != 1.0"); } if (!angle && (atom->nangles > 0)) { - error->warning(FLERR,"Angles are defined but no angle style is set"); + error->warning(FLERR, "Angles are defined but no angle style is set"); if ((special_lj[2] != 1.0) || (special_coul[2] != 1.0)) - error->warning(FLERR,"Likewise 1-3 special neighbor interactions != 1.0"); + error->warning(FLERR, "Likewise 1-3 special neighbor interactions != 1.0"); } if (!dihedral && (atom->ndihedrals > 0)) { - error->warning(FLERR,"Dihedrals are defined but no dihedral style is set"); + error->warning(FLERR, "Dihedrals are defined but no dihedral style is set"); if ((special_lj[3] != 1.0) || (special_coul[3] != 1.0)) - error->warning(FLERR,"Likewise 1-4 special neighbor interactions != 1.0"); + error->warning(FLERR, "Likewise 1-4 special neighbor interactions != 1.0"); } if (!improper && (atom->nimpropers > 0)) - error->warning(FLERR,"Impropers are defined but no improper style is set"); + error->warning(FLERR, "Impropers are defined but no improper style is set"); } } @@ -228,8 +229,8 @@ void Force::create_pair(const std::string &style, int trysuffix) pair_restart = nullptr; int sflag; - pair = new_pair(style,trysuffix,sflag); - pair_style = store_style(style,sflag); + pair = new_pair(style, trysuffix, sflag); + pair_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -275,21 +276,11 @@ Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag) return pair_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("pair",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("pair", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per pair style in style_pair.h -------------------------------------------------------------------------- */ - -template -Pair *Force::pair_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to Pair class if matches word or matches hybrid sub-style if exact, then style name must be exact match to word @@ -300,16 +291,18 @@ Pair *Force::pair_creator(LAMMPS *lmp) Pair *Force::pair_match(const std::string &word, int exact, int nsub) { - int iwhich,count; + int iwhich, count; - if (exact && (word == pair_style)) return pair; - else if (!exact && utils::strmatch(pair_style,word)) return pair; - else if (utils::strmatch(pair_style,"^hybrid")) { + if (exact && (word == pair_style)) + return pair; + else if (!exact && utils::strmatch(pair_style, word)) + return pair; + else if (utils::strmatch(pair_style, "^hybrid")) { PairHybrid *hybrid = (PairHybrid *) pair; count = 0; for (int i = 0; i < hybrid->nstyles; i++) if ((exact && (word == hybrid->keywords[i])) || - (!exact && utils::strmatch(hybrid->keywords[i],word))) { + (!exact && utils::strmatch(hybrid->keywords[i], word))) { iwhich = i; count++; if (nsub == count) return hybrid->styles[iwhich]; @@ -330,7 +323,7 @@ char *Force::pair_match_ptr(Pair *ptr) { if (ptr == pair) return pair_style; - if (utils::strmatch(pair_style,"^hybrid")) { + if (utils::strmatch(pair_style, "^hybrid")) { PairHybrid *hybrid = (PairHybrid *) pair; for (int i = 0; i < hybrid->nstyles; i++) if (ptr == hybrid->styles[i]) return hybrid->keywords[i]; @@ -349,8 +342,8 @@ void Force::create_bond(const std::string &style, int trysuffix) if (bond) delete bond; int sflag; - bond = new_bond(style,trysuffix,sflag); - bond_style = store_style(style,sflag); + bond = new_bond(style, trysuffix, sflag); + bond_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -386,29 +379,20 @@ Bond *Force::new_bond(const std::string &style, int trysuffix, int &sflag) return bond_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("bond",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("bond", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per bond style in style_bond.h -------------------------------------------------------------------------- */ - -template -Bond *Force::bond_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to current bond class or hybrid sub-class if matches style ------------------------------------------------------------------------- */ Bond *Force::bond_match(const std::string &style) { - if (style == bond_style) return bond; - else if (strcmp(bond_style,"hybrid") == 0) { + if (style == bond_style) + return bond; + else if (strcmp(bond_style, "hybrid") == 0) { BondHybrid *hybrid = (BondHybrid *) bond; for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; @@ -426,8 +410,8 @@ void Force::create_angle(const std::string &style, int trysuffix) if (angle) delete angle; int sflag; - angle = new_angle(style,trysuffix,sflag); - angle_style = store_style(style,sflag); + angle = new_angle(style, trysuffix, sflag); + angle_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -463,29 +447,20 @@ Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag) return angle_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("angle",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("angle", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per angle style in style_angle.h -------------------------------------------------------------------------- */ - -template -Angle *Force::angle_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to current angle class or hybrid sub-class if matches style ------------------------------------------------------------------------- */ Angle *Force::angle_match(const std::string &style) { - if (style == angle_style) return angle; - else if (utils::strmatch(angle_style,"^hybrid")) { + if (style == angle_style) + return angle; + else if (utils::strmatch(angle_style, "^hybrid")) { AngleHybrid *hybrid = (AngleHybrid *) angle; for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; @@ -503,8 +478,8 @@ void Force::create_dihedral(const std::string &style, int trysuffix) if (dihedral) delete dihedral; int sflag; - dihedral = new_dihedral(style,trysuffix,sflag); - dihedral_style = store_style(style,sflag); + dihedral = new_dihedral(style, trysuffix, sflag); + dihedral_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -540,29 +515,20 @@ Dihedral *Force::new_dihedral(const std::string &style, int trysuffix, int &sfla return dihedral_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("dihedral",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("dihedral", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per dihedral style in style_dihedral.h -------------------------------------------------------------------------- */ - -template -Dihedral *Force::dihedral_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to current angle class or hybrid sub-class if matches style ------------------------------------------------------------------------- */ Dihedral *Force::dihedral_match(const std::string &style) { - if (style == dihedral_style) return dihedral; - else if (utils::strmatch(dihedral_style,"^hybrid")) { + if (style == dihedral_style) + return dihedral; + else if (utils::strmatch(dihedral_style, "^hybrid")) { DihedralHybrid *hybrid = (DihedralHybrid *) dihedral; for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; @@ -580,8 +546,8 @@ void Force::create_improper(const std::string &style, int trysuffix) if (improper) delete improper; int sflag; - improper = new_improper(style,trysuffix,sflag); - improper_style = store_style(style,sflag); + improper = new_improper(style, trysuffix, sflag); + improper_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -617,29 +583,20 @@ Improper *Force::new_improper(const std::string &style, int trysuffix, int &sfla return improper_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("improper",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("improper", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per improper style in style_improper.h -------------------------------------------------------------------------- */ - -template -Improper *Force::improper_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to current improper class or hybrid sub-class if matches style ------------------------------------------------------------------------- */ Improper *Force::improper_match(const std::string &style) { - if (style == improper_style) return improper; - else if (utils::strmatch(improper_style,"^hybrid")) { + if (style == improper_style) + return improper; + else if (utils::strmatch(improper_style, "^hybrid")) { ImproperHybrid *hybrid = (ImproperHybrid *) improper; for (int i = 0; i < hybrid->nstyles; i++) if (style == hybrid->keywords[i]) return hybrid->styles[i]; @@ -657,8 +614,8 @@ void Force::create_kspace(const std::string &style, int trysuffix) if (kspace) delete kspace; int sflag; - kspace = new_kspace(style,trysuffix,sflag); - kspace_style = store_style(style,sflag); + kspace = new_kspace(style, trysuffix, sflag); + kspace_style = store_style(style, sflag); } /* ---------------------------------------------------------------------- @@ -694,21 +651,11 @@ KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag) return kspace_creator(lmp); } - error->all(FLERR,utils::check_packages_for_style("kspace",style,lmp)); + error->all(FLERR, utils::check_packages_for_style("kspace", style, lmp)); return nullptr; } -/* ---------------------------------------------------------------------- - one instance per kspace style in style_kspace.h -------------------------------------------------------------------------- */ - -template -KSpace *Force::kspace_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- return ptr to Kspace class if matches word if exact, then style name must be exact match to word @@ -718,8 +665,10 @@ KSpace *Force::kspace_creator(LAMMPS *lmp) KSpace *Force::kspace_match(const std::string &word, int exact) { - if (exact && (word == kspace_style)) return kspace; - else if (!exact && utils::strmatch(kspace_style,word)) return kspace; + if (exact && (word == kspace_style)) + return kspace; + else if (!exact && utils::strmatch(kspace_style, word)) + return kspace; return nullptr; } @@ -733,9 +682,12 @@ char *Force::store_style(const std::string &style, int sflag) { std::string estyle = style; - if (sflag == 1) estyle += std::string("/") + lmp->suffix; - else if (sflag == 2) estyle += std::string("/") + lmp->suffix2; - else if (sflag == 3) estyle += std::string("/") + lmp->suffixp; + if (sflag == 1) + estyle += std::string("/") + lmp->suffix; + else if (sflag == 2) + estyle += std::string("/") + lmp->suffix2; + else if (sflag == 3) + estyle += std::string("/") + lmp->suffixp; return utils::strdup(estyle); } @@ -745,7 +697,7 @@ char *Force::store_style(const std::string &style, int sflag) void Force::set_special(int narg, char **arg) { - if (narg == 0) error->all(FLERR,"Illegal special_bonds command"); + if (narg == 0) error->all(FLERR, "Illegal special_bonds command"); // defaults, but do not reset special_extra @@ -755,17 +707,17 @@ void Force::set_special(int narg, char **arg) int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"amber") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal special_bonds command"); + if (strcmp(arg[iarg], "amber") == 0) { + if (iarg + 1 > narg) error->all(FLERR, "Illegal special_bonds command"); special_lj[1] = 0.0; special_lj[2] = 0.0; special_lj[3] = 0.5; special_coul[1] = 0.0; special_coul[2] = 0.0; - special_coul[3] = 5.0/6.0; + special_coul[3] = 5.0 / 6.0; iarg += 1; - } else if (strcmp(arg[iarg],"charmm") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal special_bonds command"); + } else if (strcmp(arg[iarg], "charmm") == 0) { + if (iarg + 1 > narg) error->all(FLERR, "Illegal special_bonds command"); special_lj[1] = 0.0; special_lj[2] = 0.0; special_lj[3] = 0.0; @@ -773,8 +725,8 @@ void Force::set_special(int narg, char **arg) special_coul[2] = 0.0; special_coul[3] = 0.0; iarg += 1; - } else if (strcmp(arg[iarg],"dreiding") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal special_bonds command"); + } else if (strcmp(arg[iarg], "dreiding") == 0) { + if (iarg + 1 > narg) error->all(FLERR, "Illegal special_bonds command"); special_lj[1] = 0.0; special_lj[2] = 0.0; special_lj[3] = 1.0; @@ -782,8 +734,8 @@ void Force::set_special(int narg, char **arg) special_coul[2] = 0.0; special_coul[3] = 1.0; iarg += 1; - } else if (strcmp(arg[iarg],"fene") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal special_bonds command"); + } else if (strcmp(arg[iarg], "fene") == 0) { + if (iarg + 1 > narg) error->all(FLERR, "Illegal special_bonds command"); special_lj[1] = 0.0; special_lj[2] = 1.0; special_lj[3] = 1.0; @@ -791,39 +743,40 @@ void Force::set_special(int narg, char **arg) special_coul[2] = 1.0; special_coul[3] = 1.0; iarg += 1; - } else if (strcmp(arg[iarg],"lj/coul") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_lj[1] = special_coul[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - special_lj[2] = special_coul[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - special_lj[3] = special_coul[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "lj/coul") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal special_bonds command"); + special_lj[1] = special_coul[1] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + special_lj[2] = special_coul[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + special_lj[3] = special_coul[3] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"lj") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_lj[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - special_lj[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - special_lj[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "lj") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal special_bonds command"); + special_lj[1] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + special_lj[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + special_lj[3] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"coul") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_coul[1] = utils::numeric(FLERR,arg[iarg+1],false,lmp); - special_coul[2] = utils::numeric(FLERR,arg[iarg+2],false,lmp); - special_coul[3] = utils::numeric(FLERR,arg[iarg+3],false,lmp); + } else if (strcmp(arg[iarg], "coul") == 0) { + if (iarg + 4 > narg) error->all(FLERR, "Illegal special_bonds command"); + special_coul[1] = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + special_coul[2] = utils::numeric(FLERR, arg[iarg + 2], false, lmp); + special_coul[3] = utils::numeric(FLERR, arg[iarg + 3], false, lmp); iarg += 4; - } else if (strcmp(arg[iarg],"angle") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_angle = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "angle") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal special_bonds command"); + special_angle = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"dihedral") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal special_bonds command"); - special_dihedral = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "dihedral") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal special_bonds command"); + special_dihedral = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else error->all(FLERR,"Illegal special_bonds command"); + } else + error->all(FLERR, "Illegal special_bonds command"); } for (int i = 1; i <= 3; i++) - if (special_lj[i] < 0.0 || special_lj[i] > 1.0 || - special_coul[i] < 0.0 || special_coul[i] > 1.0) - error->all(FLERR,"Illegal special_bonds command"); + if (special_lj[i] < 0.0 || special_lj[i] > 1.0 || special_coul[i] < 0.0 || + special_coul[i] > 1.0) + error->all(FLERR, "Illegal special_bonds command"); } /* ---------------------------------------------------------------------- diff --git a/src/force.h b/src/force.h index 3ea03fdbe2..677817f4b3 100644 --- a/src/force.h +++ b/src/force.h @@ -153,12 +153,6 @@ class Force : protected Pointers { private: void create_factories(); - template static Pair *pair_creator(LAMMPS *); - template static Bond *bond_creator(LAMMPS *); - template static Angle *angle_creator(LAMMPS *); - template static Dihedral *dihedral_creator(LAMMPS *); - template static Improper *improper_creator(LAMMPS *); - template static KSpace *kspace_creator(LAMMPS *); }; } // namespace LAMMPS_NS diff --git a/src/input.cpp b/src/input.cpp index 4107f5d163..980a2c1e1f 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -57,6 +57,15 @@ using namespace LAMMPS_NS; #define DELTALINE 256 #define DELTA 4 +/* ---------------------------------------------------------------------- + one instance per command in style_command.h +------------------------------------------------------------------------- */ + +template static Command *command_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ /** \class LAMMPS_NS::Input @@ -810,16 +819,6 @@ int Input::execute_command() return -1; } -/* ---------------------------------------------------------------------- - one instance per command in style_command.h -------------------------------------------------------------------------- */ - -template -Command *Input::command_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ diff --git a/src/input.h b/src/input.h index 1fe79ba561..3e9edfe0a6 100644 --- a/src/input.h +++ b/src/input.h @@ -64,9 +64,6 @@ class Input : protected Pointers { typedef std::map CommandCreatorMap; CommandCreatorMap *command_map; - protected: - template static Command *command_creator(LAMMPS *); - private: void parse(); // parse an input text line char *nextword(char *, char **); // find next word in string with quotes diff --git a/src/library.cpp b/src/library.cpp index a27da0d478..af5fe36dd0 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -5439,6 +5439,21 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl /* ---------------------------------------------------------------------- */ +/** Flush output buffers + +\verbatim embed:rst +This function can be used to flush buffered output to be written to screen +and logfile pointers to simplify capturing output from LAMMPS library calls. +\endverbatim + * + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + */ +void lammps_flush_buffers(void *handle) { + utils::flush_buffers((LAMMPS *) handle); +} + +/* ---------------------------------------------------------------------- */ + /** Free memory buffer allocated by LAMMPS. * \verbatim embed:rst diff --git a/src/library.h b/src/library.h index 1605267818..94fd7f7380 100644 --- a/src/library.h +++ b/src/library.h @@ -246,6 +246,8 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double void lammps_fix_external_set_vector_length(void *handle, const char *id, int len); void lammps_fix_external_set_vector(void *handle, const char *id, int idx, double val); +void lammps_flush_buffers(void *ptr); + void lammps_free(void *ptr); int lammps_is_running(void *handle); diff --git a/src/modify.cpp b/src/modify.cpp index 2f7abe27fa..7c6f8e4ae3 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -13,15 +12,15 @@ ------------------------------------------------------------------------- */ #include "modify.h" -#include "style_compute.h" // IWYU pragma: keep -#include "style_fix.h" // IWYU pragma: keep +#include "style_compute.h" // IWYU pragma: keep +#include "style_fix.h" // IWYU pragma: keep #include "atom.h" #include "comm.h" -#include "compute.h" // IWYU pragma: keep +#include "compute.h" // IWYU pragma: keep #include "domain.h" #include "error.h" -#include "fix.h" // IWYU pragma: keep +#include "fix.h" // IWYU pragma: keep #include "group.h" #include "input.h" #include "memory.h" @@ -37,6 +36,14 @@ using namespace FixConst; #define DELTA 4 #define BIG 1.0e20 +// template for factory function: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static S *style_creator(LAMMPS *lmp, int narg, char **arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- */ Modify::Modify(LAMMPS *lmp) : Pointers(lmp) @@ -92,9 +99,8 @@ void _noopt Modify::create_factories() fix_map = new FixCreatorMap(); #define FIX_CLASS -#define FixStyle(key,Class) \ - (*fix_map)[#key] = &fix_creator; -#include "style_fix.h" // IWYU pragma: keep +#define FixStyle(key, Class) (*fix_map)[#key] = &style_creator; +#include "style_fix.h" // IWYU pragma: keep #undef FixStyle #undef FIX_CLASS @@ -103,9 +109,8 @@ void _noopt Modify::create_factories() compute_map = new ComputeCreatorMap(); #define COMPUTE_CLASS -#define ComputeStyle(key,Class) \ - (*compute_map)[#key] = &compute_creator; -#include "style_compute.h" // IWYU pragma: keep +#define ComputeStyle(key, Class) (*compute_map)[#key] = &style_creator; +#include "style_compute.h" // IWYU pragma: keep #undef ComputeStyle #undef COMPUTE_CLASS } @@ -126,34 +131,34 @@ Modify::~Modify() for (int i = 0; i < ncompute; i++) delete compute[i]; memory->sfree(compute); - delete [] list_initial_integrate; - delete [] list_post_integrate; - delete [] list_pre_exchange; - delete [] list_pre_neighbor; - delete [] list_post_neighbor; - delete [] list_pre_force; - delete [] list_pre_reverse; - delete [] list_post_force; - delete [] list_final_integrate; - delete [] list_end_of_step; - delete [] list_energy_couple; - delete [] list_energy_global; - delete [] list_energy_atom; - delete [] list_initial_integrate_respa; - delete [] list_post_integrate_respa; - delete [] list_pre_force_respa; - delete [] list_post_force_respa; - delete [] list_final_integrate_respa; - delete [] list_min_pre_exchange; - delete [] list_min_pre_neighbor; - delete [] list_min_post_neighbor; - delete [] list_min_pre_force; - delete [] list_min_pre_reverse; - delete [] list_min_post_force; - delete [] list_min_energy; + delete[] list_initial_integrate; + delete[] list_post_integrate; + delete[] list_pre_exchange; + delete[] list_pre_neighbor; + delete[] list_post_neighbor; + delete[] list_pre_force; + delete[] list_pre_reverse; + delete[] list_post_force; + delete[] list_final_integrate; + delete[] list_end_of_step; + delete[] list_energy_couple; + delete[] list_energy_global; + delete[] list_energy_atom; + delete[] list_initial_integrate_respa; + delete[] list_post_integrate_respa; + delete[] list_pre_force_respa; + delete[] list_post_force_respa; + delete[] list_final_integrate_respa; + delete[] list_min_pre_exchange; + delete[] list_min_pre_neighbor; + delete[] list_min_post_neighbor; + delete[] list_min_pre_force; + delete[] list_min_pre_reverse; + delete[] list_min_post_force; + delete[] list_min_energy; - delete [] end_of_step_every; - delete [] list_timeflag; + delete[] end_of_step_every; + delete[] list_timeflag; restart_deallocate(0); @@ -167,7 +172,7 @@ Modify::~Modify() void Modify::init() { - int i,j; + int i, j; // delete storage of restart info since it is not valid after 1st run @@ -208,33 +213,33 @@ void Modify::init() // needs to happen after init() of computes // b/c a compute::init() can delete a fix, e.g. compute chunk/atom - list_init(INITIAL_INTEGRATE,n_initial_integrate,list_initial_integrate); - list_init(POST_INTEGRATE,n_post_integrate,list_post_integrate); - list_init(PRE_EXCHANGE,n_pre_exchange,list_pre_exchange); - list_init(PRE_NEIGHBOR,n_pre_neighbor,list_pre_neighbor); - list_init(POST_NEIGHBOR,n_post_neighbor,list_post_neighbor); - list_init(PRE_FORCE,n_pre_force,list_pre_force); - list_init(PRE_REVERSE,n_pre_reverse,list_pre_reverse); - list_init(POST_FORCE,n_post_force,list_post_force); - list_init(FINAL_INTEGRATE,n_final_integrate,list_final_integrate); - list_init_end_of_step(END_OF_STEP,n_end_of_step,list_end_of_step); - list_init_energy_couple(n_energy_couple,list_energy_couple); - list_init_energy_global(n_energy_global,list_energy_global); - list_init_energy_atom(n_energy_atom,list_energy_atom); + list_init(INITIAL_INTEGRATE, n_initial_integrate, list_initial_integrate); + list_init(POST_INTEGRATE, n_post_integrate, list_post_integrate); + list_init(PRE_EXCHANGE, n_pre_exchange, list_pre_exchange); + list_init(PRE_NEIGHBOR, n_pre_neighbor, list_pre_neighbor); + list_init(POST_NEIGHBOR, n_post_neighbor, list_post_neighbor); + list_init(PRE_FORCE, n_pre_force, list_pre_force); + list_init(PRE_REVERSE, n_pre_reverse, list_pre_reverse); + list_init(POST_FORCE, n_post_force, list_post_force); + list_init(FINAL_INTEGRATE, n_final_integrate, list_final_integrate); + list_init_end_of_step(END_OF_STEP, n_end_of_step, list_end_of_step); + list_init_energy_couple(n_energy_couple, list_energy_couple); + list_init_energy_global(n_energy_global, list_energy_global); + list_init_energy_atom(n_energy_atom, list_energy_atom); - list_init(INITIAL_INTEGRATE_RESPA,n_initial_integrate_respa,list_initial_integrate_respa); - list_init(POST_INTEGRATE_RESPA,n_post_integrate_respa,list_post_integrate_respa); - list_init(POST_FORCE_RESPA,n_post_force_respa,list_post_force_respa); - list_init(PRE_FORCE_RESPA,n_pre_force_respa,list_pre_force_respa); - list_init(FINAL_INTEGRATE_RESPA,n_final_integrate_respa,list_final_integrate_respa); + list_init(INITIAL_INTEGRATE_RESPA, n_initial_integrate_respa, list_initial_integrate_respa); + list_init(POST_INTEGRATE_RESPA, n_post_integrate_respa, list_post_integrate_respa); + list_init(POST_FORCE_RESPA, n_post_force_respa, list_post_force_respa); + list_init(PRE_FORCE_RESPA, n_pre_force_respa, list_pre_force_respa); + list_init(FINAL_INTEGRATE_RESPA, n_final_integrate_respa, list_final_integrate_respa); - list_init(MIN_PRE_EXCHANGE,n_min_pre_exchange,list_min_pre_exchange); - list_init(MIN_PRE_NEIGHBOR,n_min_pre_neighbor,list_min_pre_neighbor); - list_init(MIN_POST_NEIGHBOR,n_min_post_neighbor,list_min_post_neighbor); - list_init(MIN_PRE_FORCE,n_min_pre_force,list_min_pre_force); - list_init(MIN_PRE_REVERSE,n_min_pre_reverse,list_min_pre_reverse); - list_init(MIN_POST_FORCE,n_min_post_force,list_min_post_force); - list_init(MIN_ENERGY,n_min_energy,list_min_energy); + list_init(MIN_PRE_EXCHANGE, n_min_pre_exchange, list_min_pre_exchange); + list_init(MIN_PRE_NEIGHBOR, n_min_pre_neighbor, list_min_pre_neighbor); + list_init(MIN_POST_NEIGHBOR, n_min_post_neighbor, list_min_post_neighbor); + list_init(MIN_PRE_FORCE, n_min_pre_force, list_min_pre_force); + list_init(MIN_PRE_REVERSE, n_min_pre_reverse, list_min_pre_reverse); + list_init(MIN_POST_FORCE, n_min_post_force, list_min_post_force); + list_init(MIN_ENERGY, n_min_energy, list_min_energy); // create list of computes that store invocation times @@ -244,14 +249,11 @@ void Modify::init() for (i = 0; i < nfix; i++) if (!fix[i]->dynamic_group_allow && group->dynamic[fix[i]->igroup]) - error->all(FLERR,"Fix {} does not allow use with a " - "dynamic group",fix[i]->id); + error->all(FLERR, "Fix {} does not allow use with a dynamic group", fix[i]->id); for (i = 0; i < ncompute; i++) - if (!compute[i]->dynamic_group_allow && - group->dynamic[compute[i]->igroup]) - error->all(FLERR,"Compute {} does not allow use with a " - "dynamic group",compute[i]->id); + if (!compute[i]->dynamic_group_allow && group->dynamic[compute[i]->igroup]) + error->all(FLERR, "Compute {} does not allow use with a dynamic group", compute[i]->id); // warn if any particle is time integrated more than once @@ -273,13 +275,12 @@ void Modify::init() for (i = 0; i < nlocal; i++) if (flag[i] > 1) check = 1; - delete [] flag; + delete[] flag; int checkall; - MPI_Allreduce(&check,&checkall,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&check, &checkall, 1, MPI_INT, MPI_SUM, world); if (comm->me == 0 && checkall) - error->warning(FLERR, - "One or more atoms are time integrated more than once"); + error->warning(FLERR, "One or more atoms are time integrated more than once"); } /* ---------------------------------------------------------------------- @@ -295,7 +296,7 @@ void Modify::setup(int vflag) // needs to be done before temperature compute setup for (int i = 0; i < nfix; i++) - if (strcmp(fix[i]->style,"GROUP") == 0) fix[i]->setup(vflag); + if (strcmp(fix[i]->style, "GROUP") == 0) fix[i]->setup(vflag); for (int i = 0; i < ncompute; i++) compute[i]->setup(); @@ -313,8 +314,7 @@ void Modify::setup(int vflag) void Modify::setup_pre_exchange() { if (update->whichflag <= 1) - for (int i = 0; i < n_pre_exchange; i++) - fix[list_pre_exchange[i]]->setup_pre_exchange(); + for (int i = 0; i < n_pre_exchange; i++) fix[list_pre_exchange[i]]->setup_pre_exchange(); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_exchange; i++) fix[list_min_pre_exchange[i]]->setup_pre_exchange(); @@ -328,8 +328,7 @@ void Modify::setup_pre_exchange() void Modify::setup_pre_neighbor() { if (update->whichflag == 1) - for (int i = 0; i < n_pre_neighbor; i++) - fix[list_pre_neighbor[i]]->setup_pre_neighbor(); + for (int i = 0; i < n_pre_neighbor; i++) fix[list_pre_neighbor[i]]->setup_pre_neighbor(); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_neighbor; i++) fix[list_min_pre_neighbor[i]]->setup_pre_neighbor(); @@ -343,8 +342,7 @@ void Modify::setup_pre_neighbor() void Modify::setup_post_neighbor() { if (update->whichflag == 1) - for (int i = 0; i < n_post_neighbor; i++) - fix[list_post_neighbor[i]]->setup_post_neighbor(); + for (int i = 0; i < n_post_neighbor; i++) fix[list_post_neighbor[i]]->setup_post_neighbor(); else if (update->whichflag == 2) for (int i = 0; i < n_min_post_neighbor; i++) fix[list_min_post_neighbor[i]]->setup_post_neighbor(); @@ -358,11 +356,9 @@ void Modify::setup_post_neighbor() void Modify::setup_pre_force(int vflag) { if (update->whichflag == 1) - for (int i = 0; i < n_pre_force; i++) - fix[list_pre_force[i]]->setup_pre_force(vflag); + for (int i = 0; i < n_pre_force; i++) fix[list_pre_force[i]]->setup_pre_force(vflag); else if (update->whichflag == 2) - for (int i = 0; i < n_min_pre_force; i++) - fix[list_min_pre_force[i]]->setup_pre_force(vflag); + for (int i = 0; i < n_min_pre_force; i++) fix[list_min_pre_force[i]]->setup_pre_force(vflag); } /* ---------------------------------------------------------------------- @@ -374,10 +370,10 @@ void Modify::setup_pre_reverse(int eflag, int vflag) { if (update->whichflag == 1) for (int i = 0; i < n_pre_reverse; i++) - fix[list_pre_reverse[i]]->setup_pre_reverse(eflag,vflag); + fix[list_pre_reverse[i]]->setup_pre_reverse(eflag, vflag); else if (update->whichflag == 2) for (int i = 0; i < n_min_pre_reverse; i++) - fix[list_min_pre_reverse[i]]->setup_pre_reverse(eflag,vflag); + fix[list_min_pre_reverse[i]]->setup_pre_reverse(eflag, vflag); } /* ---------------------------------------------------------------------- @@ -396,8 +392,7 @@ void Modify::initial_integrate(int vflag) void Modify::post_integrate() { - for (int i = 0; i < n_post_integrate; i++) - fix[list_post_integrate[i]]->post_integrate(); + for (int i = 0; i < n_post_integrate; i++) fix[list_post_integrate[i]]->post_integrate(); } /* ---------------------------------------------------------------------- @@ -406,8 +401,7 @@ void Modify::post_integrate() void Modify::pre_exchange() { - for (int i = 0; i < n_pre_exchange; i++) - fix[list_pre_exchange[i]]->pre_exchange(); + for (int i = 0; i < n_pre_exchange; i++) fix[list_pre_exchange[i]]->pre_exchange(); } /* ---------------------------------------------------------------------- @@ -416,8 +410,7 @@ void Modify::pre_exchange() void Modify::pre_neighbor() { - for (int i = 0; i < n_pre_neighbor; i++) - fix[list_pre_neighbor[i]]->pre_neighbor(); + for (int i = 0; i < n_pre_neighbor; i++) fix[list_pre_neighbor[i]]->pre_neighbor(); } /* ---------------------------------------------------------------------- @@ -426,8 +419,7 @@ void Modify::pre_neighbor() void Modify::post_neighbor() { - for (int i = 0; i < n_post_neighbor; i++) - fix[list_post_neighbor[i]]->post_neighbor(); + for (int i = 0; i < n_post_neighbor; i++) fix[list_post_neighbor[i]]->post_neighbor(); } /* ---------------------------------------------------------------------- @@ -436,8 +428,7 @@ void Modify::post_neighbor() void Modify::pre_force(int vflag) { - for (int i = 0; i < n_pre_force; i++) - fix[list_pre_force[i]]->pre_force(vflag); + for (int i = 0; i < n_pre_force; i++) fix[list_pre_force[i]]->pre_force(vflag); } /* ---------------------------------------------------------------------- pre_reverse call, only for relevant fixes @@ -445,8 +436,7 @@ void Modify::pre_force(int vflag) void Modify::pre_reverse(int eflag, int vflag) { - for (int i = 0; i < n_pre_reverse; i++) - fix[list_pre_reverse[i]]->pre_reverse(eflag,vflag); + for (int i = 0; i < n_pre_reverse; i++) fix[list_pre_reverse[i]]->pre_reverse(eflag, vflag); } /* ---------------------------------------------------------------------- @@ -455,8 +445,7 @@ void Modify::pre_reverse(int eflag, int vflag) void Modify::post_force(int vflag) { - for (int i = 0; i < n_post_force; i++) - fix[list_post_force[i]]->post_force(vflag); + for (int i = 0; i < n_post_force; i++) fix[list_post_force[i]]->post_force(vflag); } /* ---------------------------------------------------------------------- @@ -465,8 +454,7 @@ void Modify::post_force(int vflag) void Modify::final_integrate() { - for (int i = 0; i < n_final_integrate; i++) - fix[list_final_integrate[i]]->final_integrate(); + for (int i = 0; i < n_final_integrate; i++) fix[list_final_integrate[i]]->final_integrate(); } /* ---------------------------------------------------------------------- @@ -477,8 +465,7 @@ void Modify::final_integrate() void Modify::end_of_step() { for (int i = 0; i < n_end_of_step; i++) - if (update->ntimestep % end_of_step_every[i] == 0) - fix[list_end_of_step[i]]->end_of_step(); + if (update->ntimestep % end_of_step_every[i] == 0) fix[list_end_of_step[i]]->end_of_step(); } /* ---------------------------------------------------------------------- @@ -490,8 +477,7 @@ void Modify::end_of_step() double Modify::energy_couple() { double energy = 0.0; - for (int i = 0; i < n_energy_couple; i++) - energy += fix[list_energy_couple[i]]->compute_scalar(); + for (int i = 0; i < n_energy_couple; i++) energy += fix[list_energy_couple[i]]->compute_scalar(); return energy; } @@ -504,8 +490,7 @@ double Modify::energy_couple() double Modify::energy_global() { double energy = 0.0; - for (int i = 0; i < n_energy_global; i++) - energy += fix[list_energy_global[i]]->compute_scalar(); + for (int i = 0; i < n_energy_global; i++) energy += fix[list_energy_global[i]]->compute_scalar(); return energy; } @@ -516,7 +501,7 @@ double Modify::energy_global() void Modify::energy_atom(int nlocal, double *energy) { - int i,j; + int i, j; double *eatom; for (i = 0; i < n_energy_atom; i++) { @@ -565,7 +550,7 @@ void Modify::create_attribute(int n) void Modify::setup_pre_force_respa(int vflag, int ilevel) { for (int i = 0; i < n_pre_force_respa; i++) - fix[list_pre_force_respa[i]]->setup_pre_force_respa(vflag,ilevel); + fix[list_pre_force_respa[i]]->setup_pre_force_respa(vflag, ilevel); } /* ---------------------------------------------------------------------- @@ -575,8 +560,7 @@ void Modify::setup_pre_force_respa(int vflag, int ilevel) void Modify::initial_integrate_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_initial_integrate_respa; i++) - fix[list_initial_integrate_respa[i]]-> - initial_integrate_respa(vflag,ilevel,iloop); + fix[list_initial_integrate_respa[i]]->initial_integrate_respa(vflag, ilevel, iloop); } /* ---------------------------------------------------------------------- @@ -586,7 +570,7 @@ void Modify::initial_integrate_respa(int vflag, int ilevel, int iloop) void Modify::post_integrate_respa(int ilevel, int iloop) { for (int i = 0; i < n_post_integrate_respa; i++) - fix[list_post_integrate_respa[i]]->post_integrate_respa(ilevel,iloop); + fix[list_post_integrate_respa[i]]->post_integrate_respa(ilevel, iloop); } /* ---------------------------------------------------------------------- @@ -596,7 +580,7 @@ void Modify::post_integrate_respa(int ilevel, int iloop) void Modify::pre_force_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_pre_force_respa; i++) - fix[list_pre_force_respa[i]]->pre_force_respa(vflag,ilevel,iloop); + fix[list_pre_force_respa[i]]->pre_force_respa(vflag, ilevel, iloop); } /* ---------------------------------------------------------------------- @@ -606,7 +590,7 @@ void Modify::pre_force_respa(int vflag, int ilevel, int iloop) void Modify::post_force_respa(int vflag, int ilevel, int iloop) { for (int i = 0; i < n_post_force_respa; i++) - fix[list_post_force_respa[i]]->post_force_respa(vflag,ilevel,iloop); + fix[list_post_force_respa[i]]->post_force_respa(vflag, ilevel, iloop); } /* ---------------------------------------------------------------------- @@ -616,7 +600,7 @@ void Modify::post_force_respa(int vflag, int ilevel, int iloop) void Modify::final_integrate_respa(int ilevel, int iloop) { for (int i = 0; i < n_final_integrate_respa; i++) - fix[list_final_integrate_respa[i]]->final_integrate_respa(ilevel,iloop); + fix[list_final_integrate_respa[i]]->final_integrate_respa(ilevel, iloop); } /* ---------------------------------------------------------------------- @@ -625,8 +609,7 @@ void Modify::final_integrate_respa(int ilevel, int iloop) void Modify::min_pre_exchange() { - for (int i = 0; i < n_min_pre_exchange; i++) - fix[list_min_pre_exchange[i]]->min_pre_exchange(); + for (int i = 0; i < n_min_pre_exchange; i++) fix[list_min_pre_exchange[i]]->min_pre_exchange(); } /* ---------------------------------------------------------------------- @@ -635,8 +618,7 @@ void Modify::min_pre_exchange() void Modify::min_pre_neighbor() { - for (int i = 0; i < n_min_pre_neighbor; i++) - fix[list_min_pre_neighbor[i]]->min_pre_neighbor(); + for (int i = 0; i < n_min_pre_neighbor; i++) fix[list_min_pre_neighbor[i]]->min_pre_neighbor(); } /* ---------------------------------------------------------------------- @@ -645,8 +627,7 @@ void Modify::min_pre_neighbor() void Modify::min_post_neighbor() { - for (int i = 0; i < n_min_post_neighbor; i++) - fix[list_min_post_neighbor[i]]->min_post_neighbor(); + for (int i = 0; i < n_min_post_neighbor; i++) fix[list_min_post_neighbor[i]]->min_post_neighbor(); } /* ---------------------------------------------------------------------- @@ -655,8 +636,7 @@ void Modify::min_post_neighbor() void Modify::min_pre_force(int vflag) { - for (int i = 0; i < n_min_pre_force; i++) - fix[list_min_pre_force[i]]->min_pre_force(vflag); + for (int i = 0; i < n_min_pre_force; i++) fix[list_min_pre_force[i]]->min_pre_force(vflag); } /* ---------------------------------------------------------------------- @@ -666,7 +646,7 @@ void Modify::min_pre_force(int vflag) void Modify::min_pre_reverse(int eflag, int vflag) { for (int i = 0; i < n_min_pre_reverse; i++) - fix[list_min_pre_reverse[i]]->min_pre_reverse(eflag,vflag); + fix[list_min_pre_reverse[i]]->min_pre_reverse(eflag, vflag); } /* ---------------------------------------------------------------------- @@ -675,8 +655,7 @@ void Modify::min_pre_reverse(int eflag, int vflag) void Modify::min_post_force(int vflag) { - for (int i = 0; i < n_min_post_force; i++) - fix[list_min_post_force[i]]->min_post_force(vflag); + for (int i = 0; i < n_min_post_force; i++) fix[list_min_post_force[i]]->min_post_force(vflag); } /* ---------------------------------------------------------------------- @@ -686,7 +665,7 @@ void Modify::min_post_force(int vflag) double Modify::min_energy(double *fextra) { - int ifix,index; + int ifix, index; index = 0; double eng = 0.0; @@ -704,8 +683,7 @@ double Modify::min_energy(double *fextra) void Modify::min_store() { - for (int i = 0; i < n_min_energy; i++) - fix[list_min_energy[i]]->min_store(); + for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_store(); } /* ---------------------------------------------------------------------- @@ -714,20 +692,17 @@ void Modify::min_store() void Modify::min_clearstore() { - for (int i = 0; i < n_min_energy; i++) - fix[list_min_energy[i]]->min_clearstore(); + for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_clearstore(); } void Modify::min_pushstore() { - for (int i = 0; i < n_min_energy; i++) - fix[list_min_energy[i]]->min_pushstore(); + for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_pushstore(); } void Modify::min_popstore() { - for (int i = 0; i < n_min_energy; i++) - fix[list_min_energy[i]]->min_popstore(); + for (int i = 0; i < n_min_energy; i++) fix[list_min_energy[i]]->min_popstore(); } /* ---------------------------------------------------------------------- @@ -736,12 +711,12 @@ void Modify::min_popstore() void Modify::min_step(double alpha, double *hextra) { - int ifix,index; + int ifix, index; index = 0; for (int i = 0; i < n_min_energy; i++) { ifix = list_min_energy[i]; - fix[ifix]->min_step(alpha,&hextra[index]); + fix[ifix]->min_step(alpha, &hextra[index]); index += fix[ifix]->min_dof(); } } @@ -752,14 +727,14 @@ void Modify::min_step(double alpha, double *hextra) double Modify::max_alpha(double *hextra) { - int ifix,index; + int ifix, index; double alpha = BIG; index = 0; for (int i = 0; i < n_min_energy; i++) { ifix = list_min_energy[i]; double alpha_one = fix[ifix]->max_alpha(&hextra[index]); - alpha = MIN(alpha,alpha_one); + alpha = MIN(alpha, alpha_one); index += fix[ifix]->min_dof(); } return alpha; @@ -772,8 +747,7 @@ double Modify::max_alpha(double *hextra) int Modify::min_dof() { int ndof = 0; - for (int i = 0; i < n_min_energy; i++) - ndof += fix[list_min_energy[i]]->min_dof(); + for (int i = 0; i < n_min_energy; i++) ndof += fix[list_min_energy[i]]->min_dof(); return ndof; } @@ -783,7 +757,7 @@ int Modify::min_dof() int Modify::min_reset_ref() { - int itmp,itmpall; + int itmp, itmpall; itmpall = 0; for (int i = 0; i < n_min_energy; i++) { itmp = fix[list_min_energy[i]]->min_reset_ref(); @@ -798,7 +772,7 @@ int Modify::min_reset_ref() Fix *Modify::add_fix(int narg, char **arg, int trysuffix) { - if (narg < 3) error->all(FLERR,"Illegal fix command"); + if (narg < 3) error->all(FLERR, "Illegal fix command"); // cannot define fix before box exists unless style is in exception list // don't like this way of checking for exceptions by adding fixes to list, @@ -807,21 +781,20 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // since some fixes access domain settings in their constructor // nullptr must be last entry in this list - const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx", - "deprecated", "STORE/KIM", nullptr}; + const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap", + "cmap3", "rx", "deprecated", "STORE/KIM", nullptr}; if (domain->box_exist == 0) { int m; for (m = 0; exceptions[m] != nullptr; m++) - if (strcmp(arg[2],exceptions[m]) == 0) break; - if (exceptions[m] == nullptr) - error->all(FLERR,"Fix command before simulation box is defined"); + if (strcmp(arg[2], exceptions[m]) == 0) break; + if (exceptions[m] == nullptr) error->all(FLERR, "Fix command before simulation box is defined"); } // check group ID int igroup = group->find(arg[1]); - if (igroup == -1) error->all(FLERR,"Could not find fix group ID {}", arg[1]); + if (igroup == -1) error->all(FLERR, "Could not find fix group ID {}", arg[1]); // if fix ID exists: // set newflag = 0 so create new fix in same location in fix list @@ -836,15 +809,15 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // set newflag = 1 so create new fix // extend fix and fmask lists as necessary - int ifix,newflag; + int ifix, newflag; for (ifix = 0; ifix < nfix; ifix++) - if (strcmp(arg[0],fix[ifix]->id) == 0) break; + if (strcmp(arg[0], fix[ifix]->id) == 0) break; if (ifix < nfix) { newflag = 0; int match = 0; - if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1; + if (strcmp(arg[2], fix[ifix]->style) == 0) match = 1; if (!match && trysuffix && lmp->suffix_enable) { if (lmp->suffix) { std::string estyle = arg[2] + std::string("/") + lmp->suffix; @@ -855,10 +828,10 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (estyle == fix[ifix]->style) match = 1; } } - if (!match) error->all(FLERR,"Replacing a fix, but new style != old style"); + if (!match) error->all(FLERR, "Replacing a fix, but new style != old style"); if (fix[ifix]->igroup != igroup && comm->me == 0) - error->warning(FLERR,"Replacing a fix, but new group != old group"); + error->warning(FLERR, "Replacing a fix, but new group != old group"); delete fix[ifix]; fix[ifix] = nullptr; @@ -866,8 +839,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) newflag = 1; if (nfix == maxfix) { maxfix += DELTA; - fix = (Fix **) memory->srealloc(fix,maxfix*sizeof(Fix *),"modify:fix"); - memory->grow(fmask,maxfix,"modify:fmask"); + fix = (Fix **) memory->srealloc(fix, maxfix * sizeof(Fix *), "modify:fix"); + memory->grow(fmask, maxfix, "modify:fmask"); } } @@ -881,7 +854,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) std::string estyle = arg[2] + std::string("/") + lmp->suffix; if (fix_map->find(estyle) != fix_map->end()) { FixCreator &fix_creator = (*fix_map)[estyle]; - fix[ifix] = fix_creator(lmp,narg,arg); + fix[ifix] = fix_creator(lmp, narg, arg); delete[] fix[ifix]->style; fix[ifix]->style = utils::strdup(estyle); } @@ -890,7 +863,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) std::string estyle = arg[2] + std::string("/") + lmp->suffix2; if (fix_map->find(estyle) != fix_map->end()) { FixCreator &fix_creator = (*fix_map)[estyle]; - fix[ifix] = fix_creator(lmp,narg,arg); + fix[ifix] = fix_creator(lmp, narg, arg); delete[] fix[ifix]->style; fix[ifix]->style = utils::strdup(estyle); } @@ -899,17 +872,16 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) if (fix[ifix] == nullptr && fix_map->find(arg[2]) != fix_map->end()) { FixCreator &fix_creator = (*fix_map)[arg[2]]; - fix[ifix] = fix_creator(lmp,narg,arg); + fix[ifix] = fix_creator(lmp, narg, arg); } - if (fix[ifix] == nullptr) - error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp)); + if (fix[ifix] == nullptr) error->all(FLERR, utils::check_packages_for_style("fix", arg[2], lmp)); // increment nfix and update fix_list vector (if new) if (newflag) { nfix++; - fix_list = std::vector(fix, fix+nfix); + fix_list = std::vector(fix, fix + nfix); } // post_constructor() can call virtual methods in parent or child @@ -924,31 +896,32 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix) // if yes, pass state info to the Fix so it can reset itself for (int i = 0; i < nfix_restart_global; i++) - if (strcmp(id_restart_global[i],fix[ifix]->id) == 0 && - strcmp(style_restart_global[i],fix[ifix]->style) == 0) { + if (strcmp(id_restart_global[i], fix[ifix]->id) == 0 && + strcmp(style_restart_global[i], fix[ifix]->style) == 0) { fix[ifix]->restart(state_restart_global[i]); used_restart_global[i] = 1; fix[ifix]->restart_reset = 1; if (comm->me == 0) - utils::logmesg(lmp,"Resetting global fix info from restart file:\n" + utils::logmesg(lmp, + "Resetting global fix info from restart file:\n" " fix style: {}, fix ID: {}\n", - fix[ifix]->style,fix[ifix]->id); + fix[ifix]->style, fix[ifix]->id); } // check if Fix is in restart_peratom list // if yes, loop over atoms so they can extract info from atom->extra array for (int i = 0; i < nfix_restart_peratom; i++) - if (strcmp(id_restart_peratom[i],fix[ifix]->id) == 0 && - strcmp(style_restart_peratom[i],fix[ifix]->style) == 0) { + if (strcmp(id_restart_peratom[i], fix[ifix]->id) == 0 && + strcmp(style_restart_peratom[i], fix[ifix]->style) == 0) { used_restart_peratom[i] = 1; - for (int j = 0; j < atom->nlocal; j++) - fix[ifix]->unpack_restart(j,index_restart_peratom[i]); + for (int j = 0; j < atom->nlocal; j++) fix[ifix]->unpack_restart(j, index_restart_peratom[i]); fix[ifix]->restart_reset = 1; if (comm->me == 0) - utils::logmesg(lmp,"Resetting peratom fix info from restart file:\n" + utils::logmesg(lmp, + "Resetting peratom fix info from restart file:\n" " fix style: {}, fix ID: {}\n", - fix[ifix]->style,fix[ifix]->id); + fix[ifix]->style, fix[ifix]->id); } // set fix mask values @@ -969,10 +942,8 @@ Fix *Modify::add_fix(const std::string &fixcmd, int trysuffix) auto args = utils::split_words(fixcmd); std::vector newarg(args.size()); int i = 0; - for (const auto &arg : args) { - newarg[i++] = (char *)arg.c_str(); - } - return add_fix(args.size(),newarg.data(),trysuffix); + for (const auto &arg : args) { newarg[i++] = (char *) arg.c_str(); } + return add_fix(args.size(), newarg.data(), trysuffix); } /* ---------------------------------------------------------------------- @@ -985,19 +956,19 @@ Fix *Modify::add_fix(const std::string &fixcmd, int trysuffix) Fix *Modify::replace_fix(const char *replaceID, int narg, char **arg, int trysuffix) { auto oldfix = get_fix_by_id(replaceID); - if (!oldfix) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID); + if (!oldfix) error->all(FLERR, "Modify replace_fix ID {} could not be found", replaceID); // change ID, igroup, style of fix being replaced to match new fix // requires some error checking on arguments for new fix - if (narg < 3) error->all(FLERR,"Illegal replace_fix invocation"); - if (get_fix_by_id(arg[0])) error->all(FLERR,"Replace_fix ID {} is already in use",arg[0]); + if (narg < 3) error->all(FLERR, "Illegal replace_fix invocation"); + if (get_fix_by_id(arg[0])) error->all(FLERR, "Replace_fix ID {} is already in use", arg[0]); delete[] oldfix->id; oldfix->id = utils::strdup(arg[0]); int jgroup = group->find(arg[1]); - if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID {}", arg[1]); + if (jgroup == -1) error->all(FLERR, "Could not find replace_fix group ID {}", arg[1]); oldfix->igroup = jgroup; delete[] oldfix->style; @@ -1006,7 +977,7 @@ Fix *Modify::replace_fix(const char *replaceID, int narg, char **arg, int trysuf // invoke add_fix // it will find and overwrite the replaceID fix - return add_fix(narg,arg,trysuffix); + return add_fix(narg, arg, trysuffix); } /* ---------------------------------------------------------------------- @@ -1018,20 +989,8 @@ Fix *Modify::replace_fix(const std::string &oldfix, const std::string &fixcmd, i auto args = utils::split_words(fixcmd); std::vector newarg(args.size()); int i = 0; - for (const auto &arg : args) { - newarg[i++] = (char *)arg.c_str(); - } - return replace_fix(oldfix.c_str(),args.size(),newarg.data(),trysuffix); -} - -/* ---------------------------------------------------------------------- - one instance per fix in style_fix.h -------------------------------------------------------------------------- */ - -template -Fix *Modify::fix_creator(LAMMPS *lmp, int narg, char **arg) -{ - return new T(lmp,narg,arg); + for (const auto &arg : args) { newarg[i++] = (char *) arg.c_str(); } + return replace_fix(oldfix.c_str(), args.size(), newarg.data(), trysuffix); } /* ---------------------------------------------------------------------- @@ -1040,16 +999,16 @@ Fix *Modify::fix_creator(LAMMPS *lmp, int narg, char **arg) void Modify::modify_fix(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); + if (narg < 2) error->all(FLERR, "Illegal fix_modify command"); // lookup Fix ID int ifix; for (ifix = 0; ifix < nfix; ifix++) - if (strcmp(arg[0],fix[ifix]->id) == 0) break; - if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID {}", arg[0]); + if (strcmp(arg[0], fix[ifix]->id) == 0) break; + if (ifix == nfix) error->all(FLERR, "Could not find fix_modify ID {}", arg[0]); - fix[ifix]->modify_params(narg-1,&arg[1]); + fix[ifix]->modify_params(narg - 1, &arg[1]); } /* ---------------------------------------------------------------------- @@ -1060,7 +1019,7 @@ void Modify::modify_fix(int narg, char **arg) void Modify::delete_fix(const std::string &id) { int ifix = find_fix(id); - if (ifix < 0) error->all(FLERR,"Could not find fix ID {} to delete", id); + if (ifix < 0) error->all(FLERR, "Could not find fix ID {} to delete", id); delete_fix(ifix); } @@ -1073,10 +1032,10 @@ void Modify::delete_fix(int ifix) delete fix[ifix]; atom->update_callback(ifix); - for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i]; - for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i]; + for (int i = ifix + 1; i < nfix; i++) fix[i - 1] = fix[i]; + for (int i = ifix + 1; i < nfix; i++) fmask[i - 1] = fmask[i]; nfix--; - fix_list = std::vector(fix, fix+nfix); + fix_list = std::vector(fix, fix + nfix); } /* ---------------------------------------------------------------------- @@ -1116,7 +1075,7 @@ const std::vector Modify::get_fix_by_style(const std::string &style) cons if (style.empty()) return matches; for (int ifix = 0; ifix < nfix; ifix++) - if (utils::strmatch(fix[ifix]->style,style)) matches.push_back(fix[ifix]); + if (utils::strmatch(fix[ifix]->style, style)) matches.push_back(fix[ifix]); return matches; } @@ -1127,7 +1086,7 @@ const std::vector Modify::get_fix_by_style(const std::string &style) cons const std::vector &Modify::get_fix_list() { - fix_list = std::vector(fix, fix+nfix); + fix_list = std::vector(fix, fix + nfix); return fix_list; } @@ -1151,23 +1110,23 @@ int Modify::check_package(const char *package_fix_name) int Modify::check_rigid_group_overlap(int groupbit) { - const int * const mask = atom->mask; + const int *const mask = atom->mask; const int nlocal = atom->nlocal; int dim; int n = 0; for (int ifix = 0; ifix < nfix; ifix++) { - if (utils::strmatch(fix[ifix]->style,"^rigid")) { - const int * const body = (const int *)fix[ifix]->extract("body",dim); + if (utils::strmatch(fix[ifix]->style, "^rigid")) { + const int *const body = (const int *) fix[ifix]->extract("body", dim); if ((body == nullptr) || (dim != 1)) break; - for (int i=0; (i < nlocal) && (n == 0); ++i) + for (int i = 0; (i < nlocal) && (n == 0); ++i) if ((mask[i] & groupbit) && (body[i] >= 0)) ++n; } } int n_all = 0; - MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n, &n_all, 1, MPI_INT, MPI_SUM, world); if (n_all > 0) return 1; return 0; @@ -1181,26 +1140,25 @@ int Modify::check_rigid_group_overlap(int groupbit) int Modify::check_rigid_region_overlap(int groupbit, Region *reg) { - const int * const mask = atom->mask; - const double * const * const x = atom->x; + const int *const mask = atom->mask; + const double *const *const x = atom->x; const int nlocal = atom->nlocal; int dim; int n = 0; reg->prematch(); for (int ifix = 0; ifix < nfix; ifix++) { - if (strncmp("rigid",fix[ifix]->style,5) == 0) { - const int * const body = (const int *)fix[ifix]->extract("body",dim); + if (strncmp("rigid", fix[ifix]->style, 5) == 0) { + const int *const body = (const int *) fix[ifix]->extract("body", dim); if ((body == nullptr) || (dim != 1)) break; - for (int i=0; (i < nlocal) && (n == 0); ++i) - if ((mask[i] & groupbit) && (body[i] >= 0) - && reg->match(x[i][0],x[i][1],x[i][2])) ++n; + for (int i = 0; (i < nlocal) && (n == 0); ++i) + if ((mask[i] & groupbit) && (body[i] >= 0) && reg->match(x[i][0], x[i][1], x[i][2])) ++n; } } int n_all = 0; - MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n, &n_all, 1, MPI_INT, MPI_SUM, world); if (n_all > 0) return 1; return 0; @@ -1219,17 +1177,17 @@ int Modify::check_rigid_list_overlap(int *select) int n = 0; for (int ifix = 0; ifix < nfix; ifix++) { - if (utils::strmatch(fix[ifix]->style,"^rigid")) { - const int * const body = (const int *)fix[ifix]->extract("body",dim); + if (utils::strmatch(fix[ifix]->style, "^rigid")) { + const int *const body = (const int *) fix[ifix]->extract("body", dim); if ((body == nullptr) || (dim != 1)) break; - for (int i=0; (i < nlocal) && (n == 0); ++i) + for (int i = 0; (i < nlocal) && (n == 0); ++i) if ((body[i] >= 0) && select[i]) ++n; } } int n_all = 0; - MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + MPI_Allreduce(&n, &n_all, 1, MPI_INT, MPI_SUM, world); if (n_all > 0) return 1; return 0; @@ -1241,19 +1199,20 @@ int Modify::check_rigid_list_overlap(int *select) Compute *Modify::add_compute(int narg, char **arg, int trysuffix) { - if (narg < 3) error->all(FLERR,"Illegal compute command"); + if (narg < 3) error->all(FLERR, "Illegal compute command"); // error check for (int icompute = 0; icompute < ncompute; icompute++) - if (strcmp(arg[0],compute[icompute]->id) == 0) - error->all(FLERR,"Reuse of compute ID '{}'",arg[0]); + if (strcmp(arg[0], compute[icompute]->id) == 0) + error->all(FLERR, "Reuse of compute ID '{}'", arg[0]); // extend Compute list if necessary if (ncompute == maxcompute) { maxcompute += DELTA; - compute = (Compute **) memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute"); + compute = + (Compute **) memory->srealloc(compute, maxcompute * sizeof(Compute *), "modify:compute"); } // create the Compute @@ -1266,7 +1225,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) std::string estyle = arg[2] + std::string("/") + lmp->suffix; if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator &compute_creator = (*compute_map)[estyle]; - compute[ncompute] = compute_creator(lmp,narg,arg); + compute[ncompute] = compute_creator(lmp, narg, arg); delete[] compute[ncompute]->style; compute[ncompute]->style = utils::strdup(estyle); } @@ -1275,23 +1234,22 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) std::string estyle = arg[2] + std::string("/") + lmp->suffix2; if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator &compute_creator = (*compute_map)[estyle]; - compute[ncompute] = compute_creator(lmp,narg,arg); + compute[ncompute] = compute_creator(lmp, narg, arg); delete[] compute[ncompute]->style; compute[ncompute]->style = utils::strdup(estyle); } } } - if (compute[ncompute] == nullptr && - compute_map->find(arg[2]) != compute_map->end()) { + if (compute[ncompute] == nullptr && compute_map->find(arg[2]) != compute_map->end()) { ComputeCreator &compute_creator = (*compute_map)[arg[2]]; - compute[ncompute] = compute_creator(lmp,narg,arg); + compute[ncompute] = compute_creator(lmp, narg, arg); } if (compute[ncompute] == nullptr) - error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp)); + error->all(FLERR, utils::check_packages_for_style("compute", arg[2], lmp)); - compute_list = std::vector(compute, compute+ncompute+1); + compute_list = std::vector(compute, compute + ncompute + 1); return compute[ncompute++]; } @@ -1302,23 +1260,10 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix) Compute *Modify::add_compute(const std::string &computecmd, int trysuffix) { auto args = utils::split_words(computecmd); - std::vectornewarg(args.size()); - int i=0; - for (const auto &arg : args) { - newarg[i++] = (char *)arg.c_str(); - } - return add_compute(args.size(),newarg.data(),trysuffix); -} - - -/* ---------------------------------------------------------------------- - one instance per compute in style_compute.h -------------------------------------------------------------------------- */ - -template -Compute *Modify::compute_creator(LAMMPS *lmp, int narg, char **arg) -{ - return new T(lmp,narg,arg); + std::vector newarg(args.size()); + int i = 0; + for (const auto &arg : args) { newarg[i++] = (char *) arg.c_str(); } + return add_compute(args.size(), newarg.data(), trysuffix); } /* ---------------------------------------------------------------------- @@ -1327,17 +1272,16 @@ Compute *Modify::compute_creator(LAMMPS *lmp, int narg, char **arg) void Modify::modify_compute(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal compute_modify command"); + if (narg < 2) error->all(FLERR, "Illegal compute_modify command"); // lookup Compute ID int icompute; for (icompute = 0; icompute < ncompute; icompute++) - if (strcmp(arg[0],compute[icompute]->id) == 0) break; - if (icompute == ncompute) - error->all(FLERR,"Could not find compute_modify ID {}", arg[0]); + if (strcmp(arg[0], compute[icompute]->id) == 0) break; + if (icompute == ncompute) error->all(FLERR, "Could not find compute_modify ID {}", arg[0]); - compute[icompute]->modify_params(narg-1,&arg[1]); + compute[icompute]->modify_params(narg - 1, &arg[1]); } /* ---------------------------------------------------------------------- @@ -1347,7 +1291,7 @@ void Modify::modify_compute(int narg, char **arg) void Modify::delete_compute(const std::string &id) { int icompute = find_compute(id); - if (icompute < 0) error->all(FLERR,"Could not find compute ID {} to delete", id); + if (icompute < 0) error->all(FLERR, "Could not find compute ID {} to delete", id); delete_compute(icompute); } @@ -1358,9 +1302,9 @@ void Modify::delete_compute(int icompute) // delete and move other Computes down in list one slot delete compute[icompute]; - for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i]; + for (int i = icompute + 1; i < ncompute; i++) compute[i - 1] = compute[i]; ncompute--; - compute_list = std::vector(compute, compute+ncompute); + compute_list = std::vector(compute, compute + ncompute); } /* ---------------------------------------------------------------------- @@ -1400,7 +1344,7 @@ const std::vector Modify::get_compute_by_style(const std::string &sty if (style.empty()) return matches; for (int icompute = 0; icompute < ncompute; icompute++) - if (utils::strmatch(compute[icompute]->style,style)) matches.push_back(compute[icompute]); + if (utils::strmatch(compute[icompute]->style, style)) matches.push_back(compute[icompute]); return matches; } @@ -1411,7 +1355,7 @@ const std::vector Modify::get_compute_by_style(const std::string &sty const std::vector &Modify::get_compute_list() { - compute_list = std::vector(compute, compute+ncompute); + compute_list = std::vector(compute, compute + ncompute); return compute_list; } @@ -1440,8 +1384,8 @@ void Modify::addstep_compute(bigint newstep) // initialized, thus defer to addstep_compute_all() instead if (n_timeflag < 0) { - addstep_compute_all(newstep); - return; + addstep_compute_all(newstep); + return; } for (int icompute = 0; icompute < n_timeflag; icompute++) @@ -1476,18 +1420,18 @@ void Modify::write_restart(FILE *fp) for (int i = 0; i < nfix; i++) if (fix[i]->restart_global) count++; - if (me == 0) fwrite(&count,sizeof(int),1,fp); + if (me == 0) fwrite(&count, sizeof(int), 1, fp); int n; for (int i = 0; i < nfix; i++) if (fix[i]->restart_global) { if (me == 0) { n = strlen(fix[i]->id) + 1; - fwrite(&n,sizeof(int),1,fp); - fwrite(fix[i]->id,sizeof(char),n,fp); + fwrite(&n, sizeof(int), 1, fp); + fwrite(fix[i]->id, sizeof(char), n, fp); n = strlen(fix[i]->style) + 1; - fwrite(&n,sizeof(int),1,fp); - fwrite(fix[i]->style,sizeof(char),n,fp); + fwrite(&n, sizeof(int), 1, fp); + fwrite(fix[i]->style, sizeof(char), n, fp); } fix[i]->write_restart(fp); } @@ -1496,19 +1440,19 @@ void Modify::write_restart(FILE *fp) for (int i = 0; i < nfix; i++) if (fix[i]->restart_peratom) count++; - if (me == 0) fwrite(&count,sizeof(int),1,fp); + if (me == 0) fwrite(&count, sizeof(int), 1, fp); for (int i = 0; i < nfix; i++) if (fix[i]->restart_peratom) { int maxsize_restart = fix[i]->maxsize_restart(); if (me == 0) { n = strlen(fix[i]->id) + 1; - fwrite(&n,sizeof(int),1,fp); - fwrite(fix[i]->id,sizeof(char),n,fp); + fwrite(&n, sizeof(int), 1, fp); + fwrite(fix[i]->id, sizeof(char), n, fp); n = strlen(fix[i]->style) + 1; - fwrite(&n,sizeof(int),1,fp); - fwrite(fix[i]->style,sizeof(char),n,fp); - fwrite(&maxsize_restart,sizeof(int),1,fp); + fwrite(&n, sizeof(int), 1, fp); + fwrite(fix[i]->style, sizeof(char), n, fp); + fwrite(&maxsize_restart, sizeof(int), 1, fp); } } } @@ -1525,15 +1469,15 @@ int Modify::read_restart(FILE *fp) // nfix_restart_global = # of restart entries with global state info int me = comm->me; - if (me == 0) utils::sfread(FLERR,&nfix_restart_global,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&nfix_restart_global,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &nfix_restart_global, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&nfix_restart_global, 1, MPI_INT, 0, world); // allocate space for each entry if (nfix_restart_global) { - id_restart_global = new char*[nfix_restart_global]; - style_restart_global = new char*[nfix_restart_global]; - state_restart_global = new char*[nfix_restart_global]; + id_restart_global = new char *[nfix_restart_global]; + style_restart_global = new char *[nfix_restart_global]; + state_restart_global = new char *[nfix_restart_global]; used_restart_global = new int[nfix_restart_global]; } @@ -1542,23 +1486,23 @@ int Modify::read_restart(FILE *fp) int n; for (int i = 0; i < nfix_restart_global; i++) { - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); id_restart_global[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,id_restart_global[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(id_restart_global[i],n,MPI_CHAR,0,world); + if (me == 0) utils::sfread(FLERR, id_restart_global[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(id_restart_global[i], n, MPI_CHAR, 0, world); - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); style_restart_global[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,style_restart_global[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(style_restart_global[i],n,MPI_CHAR,0,world); + if (me == 0) utils::sfread(FLERR, style_restart_global[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(style_restart_global[i], n, MPI_CHAR, 0, world); - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); state_restart_global[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,state_restart_global[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(state_restart_global[i],n,MPI_CHAR,0,world); + if (me == 0) utils::sfread(FLERR, state_restart_global[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(state_restart_global[i], n, MPI_CHAR, 0, world); used_restart_global[i] = 0; } @@ -1567,14 +1511,14 @@ int Modify::read_restart(FILE *fp) int maxsize = 0; - if (me == 0) utils::sfread(FLERR,&nfix_restart_peratom,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&nfix_restart_peratom,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &nfix_restart_peratom, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&nfix_restart_peratom, 1, MPI_INT, 0, world); // allocate space for each entry if (nfix_restart_peratom) { - id_restart_peratom = new char*[nfix_restart_peratom]; - style_restart_peratom = new char*[nfix_restart_peratom]; + id_restart_peratom = new char *[nfix_restart_peratom]; + style_restart_peratom = new char *[nfix_restart_peratom]; index_restart_peratom = new int[nfix_restart_peratom]; used_restart_peratom = new int[nfix_restart_peratom]; } @@ -1584,20 +1528,21 @@ int Modify::read_restart(FILE *fp) // set index = which set of extra data this fix represents for (int i = 0; i < nfix_restart_peratom; i++) { - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); id_restart_peratom[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,id_restart_peratom[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(id_restart_peratom[i],n,MPI_CHAR,0,world); + if (me == 0) utils::sfread(FLERR, id_restart_peratom[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(id_restart_peratom[i], n, MPI_CHAR, 0, world); - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); style_restart_peratom[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,style_restart_peratom[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(style_restart_peratom[i],n,MPI_CHAR,0,world); + if (me == 0) + utils::sfread(FLERR, style_restart_peratom[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(style_restart_peratom[i], n, MPI_CHAR, 0, world); - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); maxsize += n; index_restart_peratom[i] = i; @@ -1620,26 +1565,26 @@ void Modify::restart_deallocate(int flag) for (i = 0; i < nfix_restart_global; i++) if (used_restart_global[i] == 0) break; if (i == nfix_restart_global) { - utils::logmesg(lmp,"All restart file global fix info was re-assigned\n"); + utils::logmesg(lmp, "All restart file global fix info was re-assigned\n"); } else { - utils::logmesg(lmp,"Unused restart file global fix info:\n"); + utils::logmesg(lmp, "Unused restart file global fix info:\n"); for (i = 0; i < nfix_restart_global; i++) { if (used_restart_global[i]) continue; - utils::logmesg(lmp," fix style: {}, fix ID: {}\n", - style_restart_global[i],id_restart_global[i]); + utils::logmesg(lmp, " fix style: {}, fix ID: {}\n", style_restart_global[i], + id_restart_global[i]); } } } for (int i = 0; i < nfix_restart_global; i++) { - delete [] id_restart_global[i]; - delete [] style_restart_global[i]; - delete [] state_restart_global[i]; + delete[] id_restart_global[i]; + delete[] style_restart_global[i]; + delete[] state_restart_global[i]; } - delete [] id_restart_global; - delete [] style_restart_global; - delete [] state_restart_global; - delete [] used_restart_global; + delete[] id_restart_global; + delete[] style_restart_global; + delete[] state_restart_global; + delete[] used_restart_global; } if (nfix_restart_peratom) { @@ -1648,25 +1593,25 @@ void Modify::restart_deallocate(int flag) for (i = 0; i < nfix_restart_peratom; i++) if (used_restart_peratom[i] == 0) break; if (i == nfix_restart_peratom) { - utils::logmesg(lmp,"All restart file peratom fix info was re-assigned\n"); + utils::logmesg(lmp, "All restart file peratom fix info was re-assigned\n"); } else { - utils::logmesg(lmp,"Unused restart file peratom fix info:\n"); + utils::logmesg(lmp, "Unused restart file peratom fix info:\n"); for (i = 0; i < nfix_restart_peratom; i++) { if (used_restart_peratom[i]) continue; - utils::logmesg(lmp," fix style: {}, fix ID: {}\n", - style_restart_peratom[i],id_restart_peratom[i]); + utils::logmesg(lmp, " fix style: {}, fix ID: {}\n", style_restart_peratom[i], + id_restart_peratom[i]); } } } for (int i = 0; i < nfix_restart_peratom; i++) { - delete [] id_restart_peratom[i]; - delete [] style_restart_peratom[i]; + delete[] id_restart_peratom[i]; + delete[] style_restart_peratom[i]; } - delete [] id_restart_peratom; - delete [] style_restart_peratom; - delete [] index_restart_peratom; - delete [] used_restart_peratom; + delete[] id_restart_peratom; + delete[] style_restart_peratom; + delete[] index_restart_peratom; + delete[] used_restart_peratom; } nfix_restart_global = nfix_restart_peratom = 0; @@ -1678,14 +1623,16 @@ void Modify::restart_deallocate(int flag) void Modify::list_init(int mask, int &n, int *&list) { - delete [] list; + delete[] list; n = 0; - for (int i = 0; i < nfix; i++) if (fmask[i] & mask) n++; + for (int i = 0; i < nfix; i++) + if (fmask[i] & mask) n++; list = new int[n]; n = 0; - for (int i = 0; i < nfix; i++) if (fmask[i] & mask) list[n++] = i; + for (int i = 0; i < nfix; i++) + if (fmask[i] & mask) list[n++] = i; } /* ---------------------------------------------------------------------- @@ -1695,11 +1642,12 @@ void Modify::list_init(int mask, int &n, int *&list) void Modify::list_init_end_of_step(int mask, int &n, int *&list) { - delete [] list; - delete [] end_of_step_every; + delete[] list; + delete[] end_of_step_every; n = 0; - for (int i = 0; i < nfix; i++) if (fmask[i] & mask) n++; + for (int i = 0; i < nfix; i++) + if (fmask[i] & mask) n++; list = new int[n]; end_of_step_every = new int[n]; @@ -1718,7 +1666,7 @@ void Modify::list_init_end_of_step(int mask, int &n, int *&list) void Modify::list_init_energy_couple(int &n, int *&list) { - delete [] list; + delete[] list; n = 0; for (int i = 0; i < nfix; i++) @@ -1737,7 +1685,7 @@ void Modify::list_init_energy_couple(int &n, int *&list) void Modify::list_init_energy_global(int &n, int *&list) { - delete [] list; + delete[] list; n = 0; for (int i = 0; i < nfix; i++) @@ -1756,7 +1704,7 @@ void Modify::list_init_energy_global(int &n, int *&list) void Modify::list_init_energy_atom(int &n, int *&list) { - delete [] list; + delete[] list; n = 0; for (int i = 0; i < nfix; i++) @@ -1774,7 +1722,7 @@ void Modify::list_init_energy_atom(int &n, int *&list) void Modify::list_init_compute() { - delete [] list_timeflag; + delete[] list_timeflag; n_timeflag = 0; for (int i = 0; i < ncompute; i++) @@ -1793,9 +1741,7 @@ void Modify::list_init_compute() double Modify::memory_usage() { double bytes = 0; - for (int i = 0; i < nfix; i++) - bytes += fix[i]->memory_usage(); - for (int i = 0; i < ncompute; i++) - bytes += compute[i]->memory_usage(); + for (int i = 0; i < nfix; i++) bytes += fix[i]->memory_usage(); + for (int i = 0; i < ncompute; i++) bytes += compute[i]->memory_usage(); return bytes; } diff --git a/src/modify.h b/src/modify.h index e340012b04..df8e52752f 100644 --- a/src/modify.h +++ b/src/modify.h @@ -201,8 +201,6 @@ class Modify : protected Pointers { protected: void create_factories(); - template static Compute *compute_creator(LAMMPS *, int, char **); - template static Fix *fix_creator(LAMMPS *, int, char **); }; } // namespace LAMMPS_NS diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 74bb3bf762..489d76eaed 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -100,6 +100,14 @@ static const char cite_neigh_multi[] = " year = {2020}\n" "}\n\n"; +// template for factory functions: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static S *style_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + //#define NEIGH_LIST_DEBUG 1 /* ---------------------------------------------------------------------- */ @@ -693,7 +701,7 @@ void Neighbor::init_styles() #define NBIN_CLASS #define NBinStyle(key,Class,bitmasks) \ binnames[nbclass] = (char *) #key; \ - binclass[nbclass] = &bin_creator; \ + binclass[nbclass] = &style_creator; \ binmasks[nbclass++] = bitmasks; #include "style_nbin.h" // IWYU pragma: keep #undef NBinStyle @@ -717,7 +725,7 @@ void Neighbor::init_styles() #define NSTENCIL_CLASS #define NStencilStyle(key,Class,bitmasks) \ stencilnames[nsclass] = (char *) #key; \ - stencilclass[nsclass] = &stencil_creator; \ + stencilclass[nsclass] = &style_creator; \ stencilmasks[nsclass++] = bitmasks; #include "style_nstencil.h" // IWYU pragma: keep #undef NStencilStyle @@ -741,7 +749,7 @@ void Neighbor::init_styles() #define NPAIR_CLASS #define NPairStyle(key,Class,bitmasks) \ pairnames[npclass] = (char *) #key; \ - pairclass[npclass] = &pair_creator; \ + pairclass[npclass] = &style_creator; \ pairmasks[npclass++] = bitmasks; #include "style_npair.h" // IWYU pragma: keep #undef NPairStyle @@ -2028,36 +2036,6 @@ int Neighbor::request(void *requestor, int instance) return nrequest-1; } -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_bin.h -------------------------------------------------------------------------- */ - -template -NBin *Neighbor::bin_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_stencil.h -------------------------------------------------------------------------- */ - -template -NStencil *Neighbor::stencil_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - -/* ---------------------------------------------------------------------- - one instance per entry in style_neigh_pair.h -------------------------------------------------------------------------- */ - -template -NPair *Neighbor::pair_creator(LAMMPS *lmp) -{ - return new T(lmp); -} - /* ---------------------------------------------------------------------- setup neighbor binning and neighbor stencils called before run and every reneighbor if box size/shape changes diff --git a/src/neighbor.h b/src/neighbor.h index 60687525a3..45468c0c9b 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -231,10 +231,6 @@ class Neighbor : protected Pointers { int choose_stencil(class NeighRequest *); int choose_pair(class NeighRequest *); - template static NBin *bin_creator(class LAMMPS *); - template static NStencil *stencil_creator(class LAMMPS *); - template static NPair *pair_creator(class LAMMPS *); - // dummy functions provided by NeighborKokkos, called in init() // otherwise NeighborKokkos would have to overwrite init() diff --git a/src/output.cpp b/src/output.cpp index 1376d365d8..a3c79d4cda 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -43,6 +43,15 @@ using namespace LAMMPS_NS; enum {SETUP, WRITE, RESET_DT}; +/* ---------------------------------------------------------------------- + one instance per dump style in style_dump.h +------------------------------------------------------------------------- */ + +template static Dump *dump_creator(LAMMPS *lmp, int narg, char ** arg) +{ + return new T(lmp, narg, arg); +} + /* ---------------------------------------------------------------------- initialize all output ------------------------------------------------------------------------- */ @@ -784,16 +793,6 @@ void Output::add_dump(int narg, char **arg) ndump++; } -/* ---------------------------------------------------------------------- - one instance per dump style in style_dump.h -------------------------------------------------------------------------- */ - -template -Dump *Output::dump_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); -} - /* ---------------------------------------------------------------------- modify parameters of a Dump ------------------------------------------------------------------------- */ diff --git a/src/output.h b/src/output.h index 14c1de6522..54fc83c380 100644 --- a/src/output.h +++ b/src/output.h @@ -93,7 +93,6 @@ class Output : protected Pointers { void memory_usage(); // print out memory usage private: - template static Dump *dump_creator(LAMMPS *, int, char **); void calculate_next_dump(int, int, bigint); }; diff --git a/src/platform.h b/src/platform.h index c079fd2cd1..45f74ee4ea 100644 --- a/src/platform.h +++ b/src/platform.h @@ -277,19 +277,19 @@ namespace platform { int mkdir(const std::string &path); /*! Delete a directory - * - * \param path directory path - * \return -1 if unsuccessful, otherwise >= 0 */ - - int rmdir(const std::string &path); - - /*! Delete a directory and its contents * * Unlike the the ``rmdir()`` or ``_rmdir()`` function of the * C library, this function will check for the contents of the * folder and recurse into any sub-folders, if necessary and * delete all contained folders and their contents before * deleting the folder *path*. + * + * \param path directory path + * \return -1 if unsuccessful, otherwise >= 0 */ + + int rmdir(const std::string &path); + + /*! Delete a file * * \param path path to file to be deleted * \return 0 on success, -1 on error */ diff --git a/src/thermo.cpp b/src/thermo.cpp index e39d7d7c57..27d74c58b6 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -375,8 +375,7 @@ void Thermo::compute(int flag) if (me == 0) { utils::logmesg(lmp,line); - if (screen && flushflag) fflush(screen); - if (logfile && flushflag) fflush(logfile); + if (flushflag) utils::flush_buffers(lmp); } // set to 1, so that subsequent invocations of CPU time will be non-zero diff --git a/src/update.cpp b/src/update.cpp index da412ee89e..c82a1ddc18 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -14,15 +13,15 @@ #include "update.h" -#include "style_integrate.h" // IWYU pragma: keep -#include "style_minimize.h" // IWYU pragma: keep +#include "style_integrate.h" // IWYU pragma: keep +#include "style_minimize.h" // IWYU pragma: keep #include "comm.h" #include "compute.h" -#include "integrate.h" #include "error.h" #include "fix.h" #include "force.h" +#include "integrate.h" #include "min.h" #include "modify.h" #include "neighbor.h" @@ -32,6 +31,19 @@ using namespace LAMMPS_NS; +// template for factory functions: +// there will be one instance for each style keyword in the respective style_xxx.h files + +template static Integrate *integrate_creator(LAMMPS *lmp, int narg, char **arg) +{ + return new T(lmp, narg, arg); +} + +template static Min *minimize_creator(LAMMPS *lmp) +{ + return new T(lmp); +} + /* ---------------------------------------------------------------------- */ Update::Update(LAMMPS *lmp) : Pointers(lmp) @@ -67,38 +79,36 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) integrate_map = new IntegrateCreatorMap(); #define INTEGRATE_CLASS -#define IntegrateStyle(key,Class) \ - (*integrate_map)[#key] = &integrate_creator; -#include "style_integrate.h" // IWYU pragma: keep +#define IntegrateStyle(key, Class) (*integrate_map)[#key] = &integrate_creator; +#include "style_integrate.h" // IWYU pragma: keep #undef IntegrateStyle #undef INTEGRATE_CLASS minimize_map = new MinimizeCreatorMap(); #define MINIMIZE_CLASS -#define MinimizeStyle(key,Class) \ - (*minimize_map)[#key] = &minimize_creator; +#define MinimizeStyle(key, Class) (*minimize_map)[#key] = &minimize_creator; #include "style_minimize.h" // IWYU pragma: keep #undef MinimizeStyle #undef MINIMIZE_CLASS str = (char *) "verlet"; - create_integrate(1,&str,1); + create_integrate(1, &str, 1); str = (char *) "cg"; - create_minimize(1,&str,1); + create_minimize(1, &str, 1); } /* ---------------------------------------------------------------------- */ Update::~Update() { - delete [] unit_style; + delete[] unit_style; - delete [] integrate_style; + delete[] integrate_style; delete integrate; - delete [] minimize_style; + delete[] minimize_style; delete minimize; delete integrate_map; @@ -113,8 +123,10 @@ void Update::init() // if neither (e.g. from write_restart) then just return if (whichflag == 0) return; - if (whichflag == 1) integrate->init(); - else if (whichflag == 2) minimize->init(); + if (whichflag == 1) + integrate->init(); + else if (whichflag == 2) + minimize->init(); // only set first_update if a run or minimize is being performed @@ -131,7 +143,7 @@ void Update::set_units(const char *style) double dt_old = dt; - if (strcmp(style,"lj") == 0) { + if (strcmp(style, "lj") == 0) { force->boltz = 1.0; force->hplanck = 1.0; force->mvv2e = 1.0; @@ -152,18 +164,18 @@ void Update::set_units(const char *style) dt = 0.005; neighbor->skin = 0.3; - } else if (strcmp(style,"real") == 0) { + } else if (strcmp(style, "real") == 0) { force->boltz = 0.0019872067; force->hplanck = 95.306976368; force->mvv2e = 48.88821291 * 48.88821291; force->ftm2v = 1.0 / 48.88821291 / 48.88821291; force->mv2d = 1.0 / 0.602214129; force->nktv2p = 68568.415; - force->qqr2e = 332.06371; // see also force->qqr2d_lammps_real + force->qqr2e = 332.06371; // see also force->qqr2d_lammps_real force->qe2f = 23.060549; force->vxmu2f = 1.4393264316e4; force->xxt2kmu = 0.1; - force->e_mass = 1.0/1836.1527556560675; + force->e_mass = 1.0 / 1836.1527556560675; force->hhmrr2e = 0.0957018663603261; force->mvh2r = 1.5339009481951; force->angstrom = 1.0; @@ -173,7 +185,7 @@ void Update::set_units(const char *style) dt = 1.0; neighbor->skin = 2.0; - } else if (strcmp(style,"metal") == 0) { + } else if (strcmp(style, "metal") == 0) { force->boltz = 8.617343e-5; force->hplanck = 4.135667403e-3; force->mvv2e = 1.0364269e-4; @@ -194,7 +206,7 @@ void Update::set_units(const char *style) dt = 0.001; neighbor->skin = 2.0; - } else if (strcmp(style,"si") == 0) { + } else if (strcmp(style, "si") == 0) { force->boltz = 1.3806504e-23; force->hplanck = 6.62606896e-34; force->mvv2e = 1.0; @@ -215,7 +227,7 @@ void Update::set_units(const char *style) dt = 1.0e-8; neighbor->skin = 0.001; - } else if (strcmp(style,"cgs") == 0) { + } else if (strcmp(style, "cgs") == 0) { force->boltz = 1.3806504e-16; force->hplanck = 6.62606896e-27; force->mvv2e = 1.0; @@ -236,7 +248,7 @@ void Update::set_units(const char *style) dt = 1.0e-8; neighbor->skin = 0.1; - } else if (strcmp(style,"electron") == 0) { + } else if (strcmp(style, "electron") == 0) { force->boltz = 3.16681534e-6; force->hplanck = 0.1519829846; force->mvv2e = 1.06657236; @@ -257,7 +269,7 @@ void Update::set_units(const char *style) dt = 0.001; neighbor->skin = 2.0; - } else if (strcmp(style,"micro") == 0) { + } else if (strcmp(style, "micro") == 0) { force->boltz = 1.3806504e-8; force->hplanck = 6.62606896e-13; force->mvv2e = 1.0; @@ -278,7 +290,7 @@ void Update::set_units(const char *style) dt = 2.0; neighbor->skin = 0.1; - } else if (strcmp(style,"nano") == 0) { + } else if (strcmp(style, "nano") == 0) { force->boltz = 0.013806504; force->hplanck = 6.62606896e-4; force->mvv2e = 1.0; @@ -299,15 +311,16 @@ void Update::set_units(const char *style) dt = 0.00045; neighbor->skin = 0.1; - } else error->all(FLERR,"Illegal units command"); + } else + error->all(FLERR, "Illegal units command"); - delete [] unit_style; + delete[] unit_style; unit_style = utils::strdup(style); // check if timestep was changed from default value if (!dt_default && (comm->me == 0)) { - error->warning(FLERR,"Changing timestep from {:.6} to {:.6} due to " - "changing units to {}", dt_old, dt, unit_style); + error->warning(FLERR, "Changing timestep from {:.6} to {:.6} due to changing units to {}", + dt_old, dt, unit_style); } dt_default = 1; } @@ -316,24 +329,26 @@ void Update::set_units(const char *style) void Update::create_integrate(int narg, char **arg, int trysuffix) { - if (narg < 1) error->all(FLERR,"Illegal run_style command"); + if (narg < 1) error->all(FLERR, "Illegal run_style command"); - delete [] integrate_style; + delete[] integrate_style; delete integrate; int sflag; - if (narg-1 > 0) { - new_integrate(arg[0],narg-1,&arg[1],trysuffix,sflag); + if (narg - 1 > 0) { + new_integrate(arg[0], narg - 1, &arg[1], trysuffix, sflag); } else { - new_integrate(arg[0],0,nullptr,trysuffix,sflag); + new_integrate(arg[0], 0, nullptr, trysuffix, sflag); } std::string estyle = arg[0]; if (sflag) { estyle += "/"; - if (sflag == 1) estyle += lmp->suffix; - else estyle += lmp->suffix2; + if (sflag == 1) + estyle += lmp->suffix; + else + estyle += lmp->suffix2; } integrate_style = utils::strdup(estyle); } @@ -342,8 +357,7 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) create the Integrate style, first with suffix appended ------------------------------------------------------------------------- */ -void Update::new_integrate(char *style, int narg, char **arg, - int trysuffix, int &sflag) +void Update::new_integrate(char *style, int narg, char **arg, int trysuffix, int &sflag) { if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { @@ -374,36 +388,28 @@ void Update::new_integrate(char *style, int narg, char **arg, return; } - error->all(FLERR,"Illegal integrate style"); -} - -/* ---------------------------------------------------------------------- - one instance per integrate style in style_integrate.h -------------------------------------------------------------------------- */ - -template -Integrate *Update::integrate_creator(LAMMPS *lmp, int narg, char ** arg) -{ - return new T(lmp, narg, arg); + error->all(FLERR, "Illegal integrate style"); } /* ---------------------------------------------------------------------- */ 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 run_style command"); - delete [] minimize_style; + delete[] minimize_style; delete minimize; int sflag; - new_minimize(arg[0],narg-1,&arg[1],trysuffix,sflag); + new_minimize(arg[0], narg - 1, &arg[1], trysuffix, sflag); std::string estyle = arg[0]; if (sflag) { estyle += "/"; - if (sflag == 1) estyle += lmp->suffix; - else estyle += lmp->suffix2; + if (sflag == 1) + estyle += lmp->suffix; + else + estyle += lmp->suffix2; } minimize_style = utils::strdup(estyle); } @@ -412,8 +418,7 @@ void Update::create_minimize(int narg, char **arg, int trysuffix) create the Minimize style, first with suffix appended ------------------------------------------------------------------------- */ -void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, - int trysuffix, int &sflag) +void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, int trysuffix, int &sflag) { if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { @@ -444,17 +449,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, return; } - error->all(FLERR,"Illegal minimize style"); -} - -/* ---------------------------------------------------------------------- - one instance per minimize style in style_minimize.h -------------------------------------------------------------------------- */ - -template -Min *Update::minimize_creator(LAMMPS *lmp) -{ - return new T(lmp); + error->all(FLERR, "Illegal minimize style"); } /* ---------------------------------------------------------------------- @@ -463,8 +458,8 @@ Min *Update::minimize_creator(LAMMPS *lmp) void Update::reset_timestep(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Illegal reset_timestep command"); - bigint newstep = utils::bnumeric(FLERR,arg[0],false,lmp); + if (narg != 1) error->all(FLERR, "Illegal reset_timestep command"); + bigint newstep = utils::bnumeric(FLERR, arg[0], false, lmp); reset_timestep(newstep); } @@ -475,7 +470,7 @@ void Update::reset_timestep(int narg, char **arg) void Update::reset_timestep(bigint newstep) { - if (newstep < 0) error->all(FLERR,"Timestep must be >= 0"); + if (newstep < 0) error->all(FLERR, "Timestep must be >= 0"); bigint oldstep = ntimestep; ntimestep = newstep; @@ -499,7 +494,7 @@ void Update::reset_timestep(bigint newstep) for (const auto &ifix : modify->get_fix_list()) if (ifix->time_depend) - error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined",ifix->style); + error->all(FLERR, "Cannot reset timestep with time-dependent fix {} defined", ifix->style); // reset eflag/vflag global so no commands will think eng/virial are current @@ -529,7 +524,7 @@ void Update::reset_timestep(bigint newstep) void Update::update_time() { - atime += (ntimestep-atimestep) * dt; + atime += (ntimestep - atimestep) * dt; atimestep = ntimestep; } @@ -540,7 +535,9 @@ void Update::update_time() double Update::memory_usage() { double bytes = 0; - if (whichflag == 1) bytes += integrate->memory_usage(); - else if (whichflag == 2) bytes += minimize->memory_usage(); + if (whichflag == 1) + bytes += integrate->memory_usage(); + else if (whichflag == 2) + bytes += minimize->memory_usage(); return bytes; } diff --git a/src/update.h b/src/update.h index 25af895bf3..f763dfa559 100644 --- a/src/update.h +++ b/src/update.h @@ -73,9 +73,6 @@ class Update : protected Pointers { private: void new_integrate(char *, int, char **, int, int &); void new_minimize(char *, int, char **, int, int &); - - template static Integrate *integrate_creator(LAMMPS *, int, char **); - template static Min *minimize_creator(LAMMPS *); }; } // namespace LAMMPS_NS diff --git a/src/utils.cpp b/src/utils.cpp index ca2a0c4f5b..c60908a2f2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -24,6 +24,7 @@ #include "text_file_reader.h" #include "tokenizer.h" #include "update.h" +#include "universe.h" #include #include @@ -138,6 +139,14 @@ void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_ar } } +void utils::flush_buffers(LAMMPS *lmp) +{ + if (lmp->screen) fflush(lmp->screen); + if (lmp->logfile) fflush(lmp->logfile); + if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); + if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile); +} + /* define this here, so we won't have to include the headers everywhere and utils.h will more likely be included anyway. */ diff --git a/src/utils.h b/src/utils.h index 47a4ace5f9..6811dbe874 100644 --- a/src/utils.h +++ b/src/utils.h @@ -74,6 +74,16 @@ namespace utils { void logmesg(LAMMPS *lmp, const std::string &mesg); + /*! Flush output buffers + * + * This function calls fflush() on screen and logfile FILE pointers + * if available and thus tells the operating system to output all + * currently buffered data. This is local operation and independent + * from buffering by a file system or an MPI library. + */ + + void flush_buffers(LAMMPS *lmp); + /*! Return a string representing the current system error status * * This is a wrapper around calling strerror(errno). diff --git a/tools/eam_database/EAM_code b/tools/eam_database/EAM_code index 6968a03aff..d339c87ab4 100644 --- a/tools/eam_database/EAM_code +++ b/tools/eam_database/EAM_code @@ -446,3 +446,31 @@ Zr 1.0 0.85 1.15 +Cr +2.493879 +1.793835 +17.641302 +19.60545 +8.604593 +7.170494 +1.551848 +1.827556 +0.18533 +0.277995 +-2.022754 +0.039608 +-0.183611 +-2.245972 +-2.02 +0.00 +-0.056517 +0.439144 +0.456 +-2.020038 +24 +51.9961 +0.439144 +7.170494 +0.277995 +0.85 +1.15 diff --git a/tools/eam_database/README b/tools/eam_database/README index 8d42eb7a12..fa868b583b 100644 --- a/tools/eam_database/README +++ b/tools/eam_database/README @@ -1,22 +1,35 @@ EAM database tool Xiaowang Zhou (Sandia), xzhou at sandia.gov +Revised version including fixes from https://www.ctcms.nist.gov/potentials/entry/2004--Zhou-X-W-Johnson-R-A-Wadley-H-N-G--Al/ + based on this paper: X. W. Zhou, R. A. Johnson, and H. N. G. Wadley, Phys. Rev. B, 69, 144113 (2004). +Parameters for Cr were taken from: +Lin Z B, Johnson R A and Zhigilei L V, Phys. Rev. B 77 214108 (2008) + This tool can be used to create an DYNAMO-formatted EAM -setfl file for alloy systems, using any combination +setfl file for alloy systems, using any combination of the elements discussed in the paper and listed in the EAM_code file, namely: -Cu, Ag, Au, Ni, Pd, Pt, Al, Pb, Fe, Mo, Ta, W, Mg, Co, Ti, Zr +Cu, Ag, Au, Ni, Pd, Pt, Al, Pb, Fe, Mo, Ta, W, Mg, Co, Ti, Zr, Cr + +WARNING: Please note that the parameter sets used here are all optimized +for the pure metals of the individual elements and that mixing rules will +be applied for creating the inter-element interactions. Those are inferior +to models where the mixed terms were specifically optimized for particular +alloys. Thus any potential files created with this tool should be used +with care and test calculations (e.g. on multiple binary mixtures) performed +to gauge the error. Steps: 1) compile create.f -> a.out (e.g. gfortran create.f) 2) edit the input file EAM.input to list 2 or more desired elements to include -3) a.out < EAM.input will create an EAM *.set file -4) in DYNAMO or LAMMPS lingo, this is a setfl file +3) a.out < EAM.input will create an *.eam.alloy potential file +4) in DYNAMO or LAMMPS context this file is referred to as a setfl file that can be used with the LAMMPS pair_style eam/alloy command diff --git a/tools/eam_database/create.f b/tools/eam_database/create.f index 528b4251db..ce6f03a7ac 100644 --- a/tools/eam_database/create.f +++ b/tools/eam_database/create.f @@ -1,4 +1,5 @@ C author: X. W. Zhou, xzhou@sandia.gov +C updates by: Lucas Hale lucas.hale@nist.gov c open(unit=5,file='a.i') call inter c close(5) @@ -9,6 +10,8 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c main subroutine. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine inter + implicit real*8 (a-h,o-z) + implicit integer (i-m) character*80 atomtype,atommatch,outfile,outelem namelist /funccard/ atomtype common /pass1/ re(16),fe(16),rhoe(16),alpha(16), @@ -17,9 +20,9 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc * Fm0(16),Fm1(16),Fm2(16),Fm3(16),Fm4(16), * fnn(16),Fn(16),rhoin(16),rhoout(16),rhol(16), * rhoh(16),rhos(16) - common /pass2/ ielement(16),amass(16),Fr(5000,16), - * rhor(5000,16),z2r(5000,16,16),ntypes,blat(16), - * nrho,drho,nr,dr,rc,outfile,outelem + common /pass2/ amass(16),Fr(5000,16),rhor(5000,16), + * z2r(5000,16,16),blat(16),drho,dr,rc,outfile,outelem + common /pass3/ ielement(16),ntypes,nrho,nr ntypes=0 10 continue atomtype='none' @@ -69,7 +72,7 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc read(10,*) ramda1(ntypes) read(10,*) rhol(ntypes) read(10,*) rhoh(ntypes) - blat(ntypes)=sqrt(2.0)*re(ntypes) + blat(ntypes)=sqrt(2.0_8)*re(ntypes) rhoin(ntypes)=rhol(ntypes)*rhoe(ntypes) rhoout(ntypes)=rhoh(ntypes)*rhoe(ntypes) else @@ -91,15 +94,15 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc if (alatmax .lt. blat(i)) alatmax=blat(i) if (rhoemax .lt. rhoe(i)) rhoemax=rhoe(i) 2 continue - rc=sqrt(10.0)/2.0*alatmax - rst=0.5 - dr=rc/(nr-1.0) - fmax=-1.0 + rc=sqrt(10.0_8)/2.0_8*alatmax + rst=0.5_8 + dr=rc/(nr-1.0_8) + fmax=-1.0_8 do i1=1,ntypes do i2=1,i1 if ( i1 .eq. i2) then do i=1,nr - r=(i-1.0)*dr + r=(i-1.0_8)*dr if (r .lt. rst) r=rst call prof(i1,r,fvalue) if (fmax .lt. fvalue) fmax=fvalue @@ -109,7 +112,7 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc end do else do i=1,nr - r=(i-1.0)*dr + r=(i-1.0_8)*dr if (r .lt. rst) r=rst call pair(i1,i2,r,psi) z2r(i,i1,i2)=r*psi @@ -119,12 +122,13 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc end do end do rhom=fmax - if (rhom .lt. 2.0*rhoemax) rhom=2.0*rhoemax - if (rhom .lt. 100.0) rhom=100.0 - drho=rhom/(nrho-1.0) + if (rhom .lt. 2.0_8*rhoemax) rhom=2.0_8*rhoemax + if (rhom .lt. 100.0_8) rhom=100.0_8 + drho=rhom/(nrho-1.0_8) do 6 it=1,ntypes do 7 i=1,nrho - rhoF=(i-1.0)*drho + rhoF=(i-1)*drho + if (i .eq. 1) rhoF=0.0_8 call embed(it,rhoF,emb) Fr(i,it)=emb 7 continue @@ -135,20 +139,24 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c This subroutine calculates the electron density. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine prof(it,r,f) + implicit real*8 (a-h,o-z) + implicit integer (i-m) common /pass1/ re(16),fe(16),rhoe(16),alpha(16), * beta(16),beta1(16),A(16),B(16),cai(16),ramda(16), * ramda1(16),Fi0(16),Fi1(16),Fi2(16),Fi3(16), * Fm0(16),Fm1(16),Fm2(16),Fm3(16),Fm4(16), * fnn(16),Fn(16),rhoin(16),rhoout(16),rhol(16), * rhoh(16),rhos(16) - f=fe(it)*exp(-beta1(it)*(r/re(it)-1.0)) - f=f/(1.0+(r/re(it)-ramda1(it))**20) + f=fe(it)*exp(-beta1(it)*(r/re(it)-1.0_8)) + f=f/(1.0_8+(r/re(it)-ramda1(it))**20) return end ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c This subroutine calculates the pair potential. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine pair(it1,it2,r,psi) + implicit real*8 (a-h,o-z) + implicit integer (i-m) common /pass1/ re(16),fe(16),rhoe(16),alpha(16), * beta(16),beta1(16),A(16),B(16),cai(16),ramda(16), * ramda1(16),Fi0(16),Fi1(16),Fi2(16),Fi3(16), @@ -156,25 +164,25 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc * fnn(16),Fn(16),rhoin(16),rhoout(16),rhol(16), * rhoh(16),rhos(16) if (it1 .eq. it2) then - psi1=A(it1)*exp(-alpha(it1)*(r/re(it1)-1.0)) - psi1=psi1/(1.0+(r/re(it1)-cai(it1))**20) - psi2=B(it1)*exp(-beta(it1)*(r/re(it1)-1.0)) - psi2=psi2/(1.0+(r/re(it1)-ramda(it1))**20) + psi1=A(it1)*exp(-alpha(it1)*(r/re(it1)-1.0_8)) + psi1=psi1/(1.0_8+(r/re(it1)-cai(it1))**20) + psi2=B(it1)*exp(-beta(it1)*(r/re(it1)-1.0_8)) + psi2=psi2/(1.0_8+(r/re(it1)-ramda(it1))**20) psi=psi1-psi2 else - psi1=A(it1)*exp(-alpha(it1)*(r/re(it1)-1.0)) - psi1=psi1/(1.0+(r/re(it1)-cai(it1))**20) - psi2=B(it1)*exp(-beta(it1)*(r/re(it1)-1.0)) - psi2=psi2/(1.0+(r/re(it1)-ramda(it1))**20) + psi1=A(it1)*exp(-alpha(it1)*(r/re(it1)-1.0_8)) + psi1=psi1/(1.0_8+(r/re(it1)-cai(it1))**20) + psi2=B(it1)*exp(-beta(it1)*(r/re(it1)-1.0_8)) + psi2=psi2/(1.0_8+(r/re(it1)-ramda(it1))**20) psia=psi1-psi2 - psi1=A(it2)*exp(-alpha(it2)*(r/re(it2)-1.0)) - psi1=psi1/(1.0+(r/re(it2)-cai(it2))**20) - psi2=B(it2)*exp(-beta(it2)*(r/re(it2)-1.0)) - psi2=psi2/(1.0+(r/re(it2)-ramda(it2))**20) + psi1=A(it2)*exp(-alpha(it2)*(r/re(it2)-1.0_8)) + psi1=psi1/(1.0_8+(r/re(it2)-cai(it2))**20) + psi2=B(it2)*exp(-beta(it2)*(r/re(it2)-1.0_8)) + psi2=psi2/(1.0_8+(r/re(it2)-ramda(it2))**20) psib=psi1-psi2 call prof(it1,r,f1) call prof(it2,r,f2) - psi=0.5*(f2/f1*psia+f1/f2*psib) + psi=0.5_8*(f2/f1*psia+f1/f2*psib) endif return end @@ -182,6 +190,8 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c This subroutine calculates the embedding energy. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine embed(it,rho,emb) + implicit real*8 (a-h,o-z) + implicit integer (i-m) common /pass1/ re(16),fe(16),rhoe(16),alpha(16), * beta(16),beta1(16),A(16),B(16),cai(16),ramda(16), * ramda1(16),Fi0(16),Fi1(16),Fi2(16),Fi3(16), @@ -193,18 +203,20 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc else Fm33=Fm4(it) endif - if (rho .lt. rhoin(it)) then + if (rho .eq. 0.0_8) then + emb = 0.0_8 + else if (rho .lt. rhoin(it)) then emb=Fi0(it)+ - * Fi1(it)*(rho/rhoin(it)-1.0)+ - * Fi2(it)*(rho/rhoin(it)-1.0)**2+ - * Fi3(it)*(rho/rhoin(it)-1.0)**3 + * Fi1(it)*(rho/rhoin(it)-1.0_8)+ + * Fi2(it)*(rho/rhoin(it)-1.0_8)**2+ + * Fi3(it)*(rho/rhoin(it)-1.0_8)**3 else if (rho .lt. rhoout(it)) then emb=Fm0(it)+ - * Fm1(it)*(rho/rhoe(it)-1.0)+ - * Fm2(it)*(rho/rhoe(it)-1.0)**2+ - * Fm33*(rho/rhoe(it)-1.0)**3 + * Fm1(it)*(rho/rhoe(it)-1.0_8)+ + * Fm2(it)*(rho/rhoe(it)-1.0_8)**2+ + * Fm33*(rho/rhoe(it)-1.0_8)**3 else - emb=Fn(it)*(1.0-fnn(it)*log(rho/rhos(it)))* + emb=Fn(it)*(1.0_8-fnn(it)*log(rho/rhos(it)))* * (rho/rhos(it))**fnn(it) endif return @@ -213,6 +225,8 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc c write out set file. c ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine writeset + implicit real*8 (a-h,o-z) + implicit integer (i-m) character*80 outfile,outelem common /pass1/ re(16),fe(16),rhoe(16),alpha(16), * beta(16),beta1(16),A(16),B(16),cai(16),ramda(16), @@ -220,16 +234,20 @@ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc * Fm0(16),Fm1(16),Fm2(16),Fm3(16),Fm4(16), * fnn(16),Fn(16),rhoin(16),rhoout(16),rhol(16), * rhoh(16),rhos(16) - common /pass2/ ielement(16),amass(16),Fr(5000,16), - * rhor(5000,16),z2r(5000,16,16),ntypes,blat(16), - * nrho,drho,nr,dr,rc,outfile,outelem + common /pass2/ amass(16),Fr(5000,16),rhor(5000,16), + * z2r(5000,16,16),blat(16),drho,dr,rc,outfile,outelem + common /pass3/ ielement(16),ntypes,nrho,nr character*80 struc + character(8) date struc='fcc' - outfile = outfile(1:index(outfile,' ')-1)//'.set' + outfile = outfile(1:index(outfile,' ')-1)//'.eam.alloy' open(unit=1,file=outfile) - write(1,*) - write(1,*) - write(1,*) + call date_and_time(DATE=date) + write(1,*) ' DATE: ',date(1:4),'-',date(5:6),'-',date(7:8),' ', + * 'CONTRIBUTOR: Xiaowang Zhou xzhou@sandia.gov and ', + * 'Lucas Hale lucas.hale@nist.gov ', + * 'CITATION: X. W. Zhou, R. A. Johnson, ', + * 'H. N. G. Wadley, Phys. Rev. B, 69, 144113(2004)' write(1,8)ntypes,outelem 8 format(i5,' ',a24) write(1,9)nrho,drho,nr,dr,rc diff --git a/tools/swig/lammps.i b/tools/swig/lammps.i index 4d0d52f779..fb4322af34 100644 --- a/tools/swig/lammps.i +++ b/tools/swig/lammps.i @@ -156,6 +156,8 @@ extern int lammps_is_running(void *handle); extern void lammps_force_timeout(void *handle); extern int lammps_has_error(void *handle); extern int lammps_get_last_error_message(void *handle, char *buffer, int buf_size); + +extern void lammps_flush_buffers(void *ptr); %} enum _LMP_DATATYPE_CONST { @@ -287,4 +289,6 @@ extern void lammps_force_timeout(void *handle); extern int lammps_has_error(void *handle); extern int lammps_get_last_error_message(void *handle, char *buffer, int buf_size); -/* last revised on 21 July 2021 */ +extern void lammps_flush_buffers(void *ptr); + +/* last revised on 4 February 2022 */ diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index a310b82c07..a166ad792a 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -5,13 +5,15 @@ ######################################## # download and build googletest framework message(STATUS "Downloading and building googletest framework") -set(GTEST_URL "https://github.com/google/googletest/archive/release-1.11.0.tar.gz" CACHE STRING "URL of googletest source") -set(GTEST_MD5 "e8a8df240b6938bb6384155d4c37d937" CACHE STRING "MD5 sum for googletest source") +set(GTEST_URL "https://github.com/google/googletest/archive/43efa0a4efd40c78b9210d15373112081899a97c.tar.gz" CACHE STRING "URL of googletest source") +set(GTEST_MD5 "0259ff833c03cdbbedda4e5d02fbc6bd" CACHE STRING "MD5 sum for googletest source") mark_as_advanced(GTEST_URL) mark_as_advanced(GTEST_MD5) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) include(ExternalCMakeProject) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) +set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) ExternalCMakeProject(googletest ${GTEST_URL} ${GTEST_MD5} googletest . "") add_library(GTest::GTest ALIAS gtest) add_library(GTest::GMock ALIAS gmock) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index ee0bd1f270..9bfea75d40 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -3,6 +3,7 @@ #include "lammps.h" #include "library.h" #include "lmptype.h" +#include "platform.h" #include #include "gmock/gmock.h" @@ -13,6 +14,7 @@ #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val +using ::LAMMPS_NS::platform::path_join; using ::LAMMPS_NS::tagint; using ::testing::HasSubstr; using ::testing::StartsWith; @@ -82,7 +84,7 @@ TEST_F(LibraryProperties, get_mpi_comm) TEST_F(LibraryProperties, natoms) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -92,7 +94,7 @@ TEST_F(LibraryProperties, natoms) TEST_F(LibraryProperties, thermo) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -108,7 +110,7 @@ TEST_F(LibraryProperties, thermo) TEST_F(LibraryProperties, box) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -248,7 +250,7 @@ TEST_F(LibraryProperties, setting) EXPECT_EQ(lammps_extract_setting(lmp, "UNKNOWN"), -1); if (lammps_has_style(lmp, "atom", "full")) { - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); @@ -289,7 +291,7 @@ TEST_F(LibraryProperties, global) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); diff --git a/unittest/c-library/test_library_scatter_gather.cpp b/unittest/c-library/test_library_scatter_gather.cpp index b070bb4ab7..25e3dde787 100644 --- a/unittest/c-library/test_library_scatter_gather.cpp +++ b/unittest/c-library/test_library_scatter_gather.cpp @@ -3,6 +3,7 @@ #include "lammps.h" #include "library.h" #include "lmptype.h" +#include "platform.h" #include #include "gmock/gmock.h" @@ -13,6 +14,7 @@ #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val +using ::LAMMPS_NS::platform::path_join; using ::LAMMPS_NS::bigint; using ::LAMMPS_NS::tagint; using ::testing::HasSubstr; @@ -55,7 +57,7 @@ protected: TEST_F(GatherProperties, gather_bonds_newton_on) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_command(lmp, "newton on on"); lammps_file(lmp, input.c_str()); @@ -95,7 +97,7 @@ TEST_F(GatherProperties, gather_bonds_newton_on) TEST_F(GatherProperties, gather_bonds_newton_off) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); - std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + std::string input = path_join(INPUT_DIR, "in.fourmol"); if (!verbose) ::testing::internal::CaptureStdout(); lammps_command(lmp, "newton off off"); lammps_file(lmp, input.c_str()); diff --git a/unittest/c-library/test_main.h b/unittest/c-library/test_main.h index 567b913d27..9a719e4b88 100644 --- a/unittest/c-library/test_main.h +++ b/unittest/c-library/test_main.h @@ -25,9 +25,3 @@ extern bool verbose; } while (0); #endif - -#if defined _WIN32 -static const char PATH_SEP = '\\'; -#else -static const char PATH_SEP = '/'; -#endif diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 6c733a31e4..4885cffbe2 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -261,13 +261,13 @@ protected: int argc = sizeof(args) / sizeof(char *); // only run this test fixture with kk suffix if KOKKOS package is installed - // also need to figure out a way to find which parallelizations are enabled if (LAMMPS::is_installed_pkg("KOKKOS")) { ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::")); + if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::")); } else GTEST_SKIP(); } diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 8a974a09d2..a617ec1783 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } @@ -112,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("angle_style " + cfg.angle_style); @@ -198,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable angle_style index '" + cfg.angle_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &angle_coeff : cfg.angle_coeff) { @@ -304,6 +300,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) return; } + TEST(AngleStyle, plain) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); @@ -337,29 +334,11 @@ TEST(AngleStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto angle = lmp->force->angle; - auto stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -369,29 +348,8 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = angle->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -407,27 +365,10 @@ TEST(AngleStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 2*epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -437,26 +378,8 @@ TEST(AngleStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = angle->virial; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -470,27 +393,9 @@ TEST(AngleStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("restart_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -500,27 +405,9 @@ TEST(AngleStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("data_stress", angle->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -567,30 +454,11 @@ TEST(AngleStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto angle = lmp->force->angle; - auto stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -600,29 +468,8 @@ TEST(AngleStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = angle->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -641,27 +488,10 @@ TEST(AngleStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - angle = lmp->force->angle; - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", angle->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon); @@ -671,25 +501,8 @@ TEST(AngleStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = angle->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", angle->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 068fee5e82..a851f4341f 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } @@ -112,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("bond_style " + cfg.bond_style); @@ -198,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable bond_style index '" + cfg.bond_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &bond_coeff : cfg.bond_coeff) { @@ -337,29 +333,11 @@ TEST(BondStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto bond = lmp->force->bond; - auto stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -369,29 +347,8 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = bond->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -407,27 +364,10 @@ TEST(BondStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 2 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -437,26 +377,8 @@ TEST(BondStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = bond->virial; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -470,27 +392,10 @@ TEST(BondStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("restart_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -500,27 +405,10 @@ TEST(BondStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("data_stress", bond->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -567,29 +455,11 @@ TEST(BondStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto bond = lmp->force->bond; - auto stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -599,29 +469,8 @@ TEST(BondStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = bond->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -640,27 +489,10 @@ TEST(BondStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - bond = lmp->force->bond; - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", bond->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(bond->energy, test_config.init_energy, epsilon); @@ -670,25 +502,8 @@ TEST(BondStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = bond->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", bond->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 6f525a07eb..0156e8e021 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } @@ -112,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("dihedral_style " + cfg.dihedral_style); @@ -207,7 +203,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable pair_style index 'lj/charmmfsw/coul/charmmfsh 7.0 8.0'"); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &dihedral_coeff : cfg.dihedral_coeff) { @@ -340,29 +336,11 @@ TEST(DihedralStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto dihedral = lmp->force->dihedral; - auto stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -372,29 +350,8 @@ TEST(DihedralStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = dihedral->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -410,27 +367,10 @@ TEST(DihedralStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -440,26 +380,8 @@ TEST(DihedralStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = dihedral->virial; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -473,27 +395,10 @@ TEST(DihedralStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("restart_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -503,27 +408,10 @@ TEST(DihedralStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("data_stress", dihedral->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -570,30 +458,11 @@ TEST(DihedralStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto dihedral = lmp->force->dihedral; - auto stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -603,29 +472,8 @@ TEST(DihedralStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = dihedral->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -644,27 +492,10 @@ TEST(DihedralStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - dihedral = lmp->force->dihedral; - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", dihedral->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(dihedral->energy, test_config.init_energy, epsilon); @@ -674,25 +505,8 @@ TEST(DihedralStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = dihedral->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", dihedral->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index eef928f7e5..fcf6be39d3 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -37,6 +37,7 @@ #include "universe.h" #include "utils.h" #include "variable.h" +#include "platform.h" #include #include @@ -54,16 +55,10 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".restart"); delete lmp; - lmp = nullptr; } LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use_respa = false) @@ -104,7 +99,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use for (auto &pre_command : cfg.pre_commands) command(pre_command); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); lmp->input->file(input_file.c_str()); if (use_respa) command("run_style respa 2 1 bond 1 pair 2"); @@ -287,29 +282,10 @@ TEST(FixTimestep, plain) double epsilon = test_config.epsilon; - auto tag = lmp->atom->tag; - auto x = lmp->atom->x; - auto v = lmp->atom->v; ErrorStats stats; - stats.reset(); - const std::vector &x_ref = test_config.run_pos; - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl; - const std::vector &v_ref = test_config.run_vel; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon); int ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -317,15 +293,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -365,26 +333,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, false, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, verlet: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -392,15 +342,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -429,26 +371,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, true, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, verlet: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -456,15 +380,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -507,26 +423,8 @@ TEST(FixTimestep, plain) // lower required precision by two orders of magnitude to accommodate respa epsilon *= 100.0; - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -534,16 +432,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) - std::cerr << "run_stress normal run, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -571,26 +460,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, false, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -598,15 +469,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -635,26 +498,8 @@ TEST(FixTimestep, plain) restart_lammps(lmp, test_config, true, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, respa: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -662,15 +507,7 @@ TEST(FixTimestep, plain) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -739,29 +576,10 @@ TEST(FixTimestep, omp) double epsilon = test_config.epsilon; - auto tag = lmp->atom->tag; - auto x = lmp->atom->x; - auto v = lmp->atom->v; ErrorStats stats; - stats.reset(); - const std::vector &x_ref = test_config.run_pos; - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl; - const std::vector &v_ref = test_config.run_vel; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon); int ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -769,15 +587,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -817,26 +627,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, false, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, verlet: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -844,15 +636,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -881,26 +665,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, true, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, verlet: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, verlet: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -908,15 +674,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, verlet)", fix->virial, test_config.run_stress, epsilon); } stats.reset(); @@ -958,27 +716,8 @@ TEST(FixTimestep, omp) // lower required precision by two orders of magnitude to accommodate respa epsilon *= 100.0; - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl; - printf("x1\n"); - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -986,16 +725,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) - std::cerr << "run_stress normal run, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (normal run, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -1023,26 +753,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, false, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - tag = lmp->atom->tag; - x = lmp->atom->x; - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, restart, respa: " << stats << std::endl; - - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, restart, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -1050,15 +762,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (restart, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); @@ -1087,26 +791,8 @@ TEST(FixTimestep, omp) restart_lammps(lmp, test_config, true, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - x = lmp->atom->x; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, x_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_pos, rmass, respa: " << stats << std::endl; - - v = lmp->atom->v; - stats.reset(); - ASSERT_EQ(nlocal + 1, v_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "run_vel, rmass, respa: " << stats << std::endl; + EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon); + EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon); ifix = lmp->modify->find_fix("test"); if (ifix < 0) { @@ -1114,15 +800,7 @@ TEST(FixTimestep, omp) } else { Fix *fix = lmp->modify->fix[ifix]; if (fix->thermo_virial) { - stats.reset(); - auto stress = fix->virial; - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 1000 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 1000 * epsilon); - if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl; + EXPECT_STRESS("run_stress (rmass, respa)", fix->virial, test_config.run_stress, 1000 * epsilon); } stats.reset(); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index fdbfda8f7a..49b7d22cad 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -33,6 +33,7 @@ #include "lammps.h" #include "modify.h" #include "universe.h" +#include "platform.h" #include #include @@ -50,16 +51,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; } @@ -112,7 +108,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("improper_style " + cfg.improper_style); @@ -198,7 +194,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable improper_style index '" + cfg.improper_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &improper_coeff : cfg.improper_coeff) { @@ -331,29 +327,11 @@ TEST(ImproperStyle, plain) double epsilon = test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto improper = lmp->force->improper; - auto stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -363,29 +341,8 @@ TEST(ImproperStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = improper->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -401,27 +358,10 @@ TEST(ImproperStyle, plain) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 2 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -431,26 +371,8 @@ TEST(ImproperStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = improper->virial; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -464,27 +386,10 @@ TEST(ImproperStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("restart_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -494,27 +399,10 @@ TEST(ImproperStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("data_stress", improper->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -561,30 +449,11 @@ TEST(ImproperStyle, omp) // relax error a bit for OPENMP package double epsilon = 5.0 * test_config.epsilon; - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto improper = lmp->force->improper; - auto stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -594,29 +463,8 @@ TEST(ImproperStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = improper->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton on)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -635,27 +483,10 @@ TEST(ImproperStyle, omp) // skip over these tests if newton bond is forced to be on if (lmp->force->newton_bond == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - improper = lmp->force->improper; - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", improper->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(improper->energy, test_config.init_energy, epsilon); @@ -665,25 +496,8 @@ TEST(ImproperStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = improper->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 10 * epsilon); + EXPECT_STRESS("run_stress (newton off)", improper->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index 2680804fdf..0fc2fef47d 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -15,10 +15,13 @@ #include "pointers.h" #include "test_config.h" #include "test_config_reader.h" +#include "error_stats.h" #include "utils.h" #include "yaml_writer.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "lammps.h" +#include "atom.h" #include #include @@ -27,8 +30,69 @@ #include #include +using LAMMPS_NS::LAMMPS; +using LAMMPS_NS::Atom; using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::trim; +using LAMMPS_NS::tagint; + +void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon) +{ + SCOPED_TRACE("EXPECT_STRESS: " + name); + ErrorStats stats; + EXPECT_FP_LE_WITH_EPS(stress[0], expected_stress.xx, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], expected_stress.yy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], expected_stress.zz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], expected_stress.xy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], expected_stress.xz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], expected_stress.yz, epsilon); + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} + +void EXPECT_FORCES(const std::string & name, Atom * atom, const std::vector & f_ref, double epsilon) { + SCOPED_TRACE("EXPECT_FORCES: " + name); + double ** f = atom->f; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; + ASSERT_EQ(nlocal + 1, f_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} + +void EXPECT_POSITIONS(const std::string & name, Atom * atom, const std::vector & x_ref, double epsilon) { + SCOPED_TRACE("EXPECT_POSITIONS: " + name); + double ** x = atom->x; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; + ASSERT_EQ(nlocal + 1, x_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(x[i][0], x_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} + +void EXPECT_VELOCITIES(const std::string & name, Atom * atom, const std::vector & v_ref, double epsilon) { + SCOPED_TRACE("EXPECT_VELOCITIES: " + name); + double ** v = atom->v; + tagint * tag = atom->tag; + const int nlocal = atom->nlocal; + ASSERT_EQ(nlocal + 1, v_ref.size()); + ErrorStats stats; + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << name << " stats" << stats << std::endl; +} // common read_yaml_file function bool read_yaml_file(const char *infile, TestConfig &config) diff --git a/unittest/force-styles/test_main.h b/unittest/force-styles/test_main.h index 3a9651e621..ff373e5174 100644 --- a/unittest/force-styles/test_main.h +++ b/unittest/force-styles/test_main.h @@ -15,7 +15,10 @@ #define TEST_MAIN_H #include "test_config.h" +#include "lammps.h" +#include "atom.h" #include +#include extern TestConfig test_config; extern bool print_stats; @@ -34,10 +37,9 @@ void write_yaml_header(class YamlWriter *writer, TestConfig *cfg, const char *ve EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ } while (0); -#if defined _WIN32 -static const char PATH_SEP = '\\'; -#else -static const char PATH_SEP = '/'; -#endif +void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & expected_stress, double epsilon); +void EXPECT_FORCES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & f_ref, double epsilon); +void EXPECT_POSITIONS(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & x_ref, double epsilon); +void EXPECT_VELOCITIES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector & v_ref, double epsilon); #endif diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 898fb8e412..4b1175455f 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -34,6 +34,7 @@ #include "pair.h" #include "universe.h" #include "utils.h" +#include "platform.h" #include #include @@ -51,18 +52,12 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -static void delete_file(const std::string &filename) -{ - remove(filename.c_str()); -}; - void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) { - delete_file(cfg.basename + ".restart"); - delete_file(cfg.basename + ".data"); - delete_file(cfg.basename + "-coeffs.in"); + platform::unlink(cfg.basename + ".restart"); + platform::unlink(cfg.basename + ".data"); + platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; - lmp = nullptr; } LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) @@ -114,7 +109,7 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool new command(pre_command); } - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); command("pair_style " + cfg.pair_style); @@ -212,7 +207,7 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg) command("variable pair_style index '" + cfg.pair_style + "'"); command("variable data_file index " + cfg.basename + ".data"); - std::string input_file = INPUT_FOLDER + PATH_SEP + cfg.input_file; + std::string input_file = platform::path_join(INPUT_FOLDER, cfg.input_file); parse_input_script(input_file); for (auto &pair_coeff : cfg.pair_coeff) { @@ -361,30 +356,12 @@ TEST(PairStyle, plain) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - ErrorStats stats; - stats.reset(); - const std::vector &f_ref = test_config.init_forces; - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, epsilon); + + ErrorStats stats; stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); @@ -394,29 +371,8 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = pair->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -435,27 +391,10 @@ TEST(PairStyle, plain) // skip over these tests if newton pair is forced to be on if (lmp->force->newton_pair == 0) { - - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 3 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 3 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 3 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -466,26 +405,8 @@ TEST(PairStyle, plain) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = pair->virial; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -502,27 +423,10 @@ TEST(PairStyle, plain) restart_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl; + + EXPECT_FORCES("restart_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("restart_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -535,27 +439,10 @@ TEST(PairStyle, plain) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -567,27 +454,9 @@ TEST(PairStyle, plain) data_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl; + EXPECT_FORCES("data_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("data_stress", pair->virial, test_config.init_stress, epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -608,25 +477,8 @@ TEST(PairStyle, plain) pair = lmp->force->pair; if (pair->ncoultablebits) epsilon *= 5.0e6; - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, r-RESPA:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon); - if (print_stats) std::cerr << "run_stress stats, r-RESPA:" << stats << std::endl; + EXPECT_FORCES("run_forces (r-RESPA)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (r-RESPA)", pair->virial, test_config.run_stress, epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -684,29 +536,11 @@ TEST(PairStyle, omp) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; - ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl; - auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl; + ErrorStats stats; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -717,29 +551,8 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - stress = pair->virial; - tag = lmp->atom->tag; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton on: " << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton on: " << stats << std::endl; + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5* epsilon); + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -757,26 +570,10 @@ TEST(PairStyle, omp) lmp = init_lammps(argc, argv, test_config, false); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -787,25 +584,8 @@ TEST(PairStyle, omp) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); id = lmp->modify->find_compute("sum"); @@ -820,27 +600,133 @@ TEST(PairStyle, omp) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; + pair = lmp->force->pair; + + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); + stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, 5 * epsilon); + if (print_stats) std::cerr << "nofdotr_energy stats:" << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +}; + +TEST(PairStyle, kokkos_omp) +{ + if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); + 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"}; + + // cannot run dpd styles with more than 1 thread due to using multiple pRNGs + if (utils::strmatch(test_config.pair_style, "^dpd")) 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); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles with /kk suffix\n" + "are not available in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + // relax error a bit for KOKKOS package + double epsilon = 5.0 * test_config.epsilon; + // relax test precision when using pppm and single precision FFTs +#if defined(FFT_SINGLE) + if (lmp->force->kspace && lmp->force->kspace->compute_flag) + if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; +#endif + auto pair = lmp->force->pair; + ErrorStats stats; + + EXPECT_FORCES("init_forces (newton on)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton on)", pair->virial, test_config.init_stress, 10 * epsilon); + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); + if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + run_lammps(lmp); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + EXPECT_FORCES("run_forces (newton on)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton on)", pair->virial, test_config.run_stress, 10 * epsilon); + + stats.reset(); + int id = lmp->modify->find_compute("sum"); + double energy = lmp->modify->compute[id]->compute_scalar(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton on: " << stats << std::endl; + + // skip over these tests if newton pair is forced to be on + if (lmp->force->newton_pair == 0) { + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + lmp = init_lammps(argc, argv, test_config, false); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + pair = lmp->force->pair; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); + if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl; + + if (!verbose) ::testing::internal::CaptureStdout(); + run_lammps(lmp); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); + + stats.reset(); + id = lmp->modify->find_compute("sum"); + energy = lmp->modify->compute[id]->compute_scalar(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.run_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.run_coul, epsilon); + EXPECT_FP_LE_WITH_EPS((pair->eng_vdwl + pair->eng_coul), energy, epsilon); + if (print_stats) std::cerr << "run_energy stats, newton off:" << stats << std::endl; + } + + if (!verbose) ::testing::internal::CaptureStdout(); + restart_lammps(lmp, test_config, true); + if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); @@ -916,30 +802,11 @@ TEST(PairStyle, gpu) Info::has_accelerator_feature("GPU", "precision", "double")) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - const std::vector &f_ref = test_config.init_forces; - const std::vector &f_run = test_config.run_forces; ErrorStats stats; - - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl; - auto pair = lmp->force->pair; - auto stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl; + + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress (newton off)", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -950,25 +817,8 @@ TEST(PairStyle, gpu) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats, newton off:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats, newton off:" << stats << std::endl; + EXPECT_FORCES("run_forces (newton off)", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress (newton off)", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); auto id = lmp->modify->find_compute("sum"); @@ -1036,29 +886,11 @@ TEST(PairStyle, intel) const int nlocal = lmp->atom->nlocal; ASSERT_EQ(lmp->atom->natoms, nlocal); - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; + auto pair = lmp->force->pair; - Pair *pair = lmp->force->pair; - double *stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_FORCES("init_forces", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1069,29 +901,8 @@ TEST(PairStyle, intel) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = pair->virial; - - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_FORCES("run_forces", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -1149,29 +960,11 @@ TEST(PairStyle, opt) if (lmp->force->kspace && lmp->force->kspace->compute_flag) if (utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; #endif - auto f = lmp->atom->f; - auto tag = lmp->atom->tag; - - const std::vector &f_ref = test_config.init_forces; ErrorStats stats; - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); - } - if (print_stats) std::cerr << "init_forces stats:" << stats << std::endl; + auto pair = lmp->force->pair; - Pair *pair = lmp->force->pair; - double *stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "init_stress stats:" << stats << std::endl; + EXPECT_FORCES("init_forces (newton off)", lmp->atom, test_config.init_forces, epsilon); + EXPECT_STRESS("init_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); @@ -1182,28 +975,8 @@ TEST(PairStyle, opt) run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stress = pair->virial; - const std::vector &f_run = test_config.run_forces; - ASSERT_EQ(nlocal + 1, f_run.size()); - stats.reset(); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_run[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "run_forces stats:" << stats << std::endl; - - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "run_stress stats:" << stats << std::endl; + EXPECT_FORCES("run_forces", lmp->atom, test_config.run_forces, 5 * epsilon); + EXPECT_STRESS("run_stress", pair->virial, test_config.run_stress, 10 * epsilon); stats.reset(); int id = lmp->modify->find_compute("sum"); @@ -1217,27 +990,10 @@ TEST(PairStyle, opt) restart_lammps(lmp, test_config, true); if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, 5 * epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, 5 * epsilon); - } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + + EXPECT_FORCES("nofdotr_forces", lmp->atom, test_config.init_forces, 5 * epsilon); + EXPECT_STRESS("nofdotr_stress", pair->virial, test_config.init_stress, 10 * epsilon); stats.reset(); EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, 5 * epsilon); diff --git a/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml b/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml index 5acd407191..b8d662829b 100644 --- a/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml +++ b/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml @@ -1,6 +1,6 @@ --- lammps_version: 30 Jul 2021 -tags: slow, unstable +tags: slow, unstable, noWindows date_generated: Mon Aug 23 20:32:05 2021 epsilon: 1e-12 skip_tests: diff --git a/unittest/force-styles/tests/kspace-pppm_ad.yaml b/unittest/force-styles/tests/kspace-pppm_ad.yaml index 5eb711c089..0f77e7b208 100644 --- a/unittest/force-styles/tests/kspace-pppm_ad.yaml +++ b/unittest/force-styles/tests/kspace-pppm_ad.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:29 2021 epsilon: 7.5e-14 -skip_tests: gpu +skip_tests: gpu kokkos_omp prerequisites: ! | atom full pair coul/long diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml index a9390a4fd3..34706e4b25 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_mod_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:20 2021 epsilon: 5e-11 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff/mod pre_commands: ! | diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml index 9808d348a7..3d98f221b0 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:20 2021 epsilon: 5e-13 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff pre_commands: ! | diff --git a/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml b/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml index 69b63cf259..1bf994e7b2 100644 --- a/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml +++ b/unittest/force-styles/tests/manybody-pair-tersoff_zbl_shift.yaml @@ -2,7 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:09:21 2021 epsilon: 5e-11 -skip_tests: gpu intel +skip_tests: gpu intel kokkos_omp prerequisites: ! | pair tersoff/zbl pre_commands: ! | diff --git a/unittest/force-styles/tests/mol-pair-coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-coul_dsf.yaml index 9bc59e4431..5e47bd6c79 100644 --- a/unittest/force-styles/tests/mol-pair-coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-coul_dsf.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:42 2021 epsilon: 1e-12 +skip_tests: kokkos_omp prerequisites: ! | atom full pair coul/dsf diff --git a/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml b/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml index 68f23ae526..6559e2d53c 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid-overlay.yaml @@ -1,6 +1,7 @@ --- lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:07 2021 +skip_tests: kokkos_omp epsilon: 5e-13 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml b/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml index e9a036b545..814f3780fe 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid-scaled.yaml @@ -2,7 +2,7 @@ lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:07 2021 epsilon: 5e-14 -skip_tests: gpu intel omp +skip_tests: gpu intel omp kokkos_omp prerequisites: ! | atom full pair lj/cut diff --git a/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml b/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml index 59a5098238..c46ee40b93 100644 --- a/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml +++ b/unittest/force-styles/tests/mol-pair-hybrid_multiple.yaml @@ -2,7 +2,7 @@ lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:08 2021 epsilon: 5e-14 -skip_tests: gpu +skip_tests: gpu kokkos_omp prerequisites: ! | atom full pair lj/cut diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml index 109e347449..1e3e4249a6 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_coul_dsf.yaml @@ -1,6 +1,7 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:48 2021 +skip_tests: kokkos_omp epsilon: 8e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml index d1bed9430b..eaf9bf1a7c 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml @@ -1,7 +1,7 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:49 2021 -epsilon: 1e-13 +epsilon: 5e-12 prerequisites: ! | atom full pair lj/cut/tip4p/long diff --git a/unittest/force-styles/tests/mol-pair-table.yaml b/unittest/force-styles/tests/mol-pair-table.yaml index fb9e647677..1b75119519 100644 --- a/unittest/force-styles/tests/mol-pair-table.yaml +++ b/unittest/force-styles/tests/mol-pair-table.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 tags: slow date_generated: Fri Feb 26 23:08:56 2021 +skip_tests: kokkos_omp epsilon: 5e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-zbl.yaml b/unittest/force-styles/tests/mol-pair-zbl.yaml index 113072816e..2f29826e67 100644 --- a/unittest/force-styles/tests/mol-pair-zbl.yaml +++ b/unittest/force-styles/tests/mol-pair-zbl.yaml @@ -2,6 +2,7 @@ lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:57 2021 epsilon: 1e-12 +skip_tests: kokkos_omp prerequisites: ! | atom full pair zbl diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 9ea1f354f8..a1fcce635c 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -98,14 +98,10 @@ if(Python_EXECUTABLE) WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonCapabilities PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - message(STATUS "Skipping Tests for PyLammps Module: not yet ported to Windows") -else() add_test(NAME PythonPyLammps COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-pylammps.py -v WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonPyLammps PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") -endif() add_test(NAME PythonFormats COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-formats.py -v diff --git a/unittest/python/python-pylammps.py b/unittest/python/python-pylammps.py index 6294972ab4..2b92f82248 100644 --- a/unittest/python/python-pylammps.py +++ b/unittest/python/python-pylammps.py @@ -1,6 +1,13 @@ -import sys,os,unittest +import os,unittest from lammps import PyLammps +try: + import numpy + NUMPY_INSTALLED = True +except ImportError: + NUMPY_INSTALLED = False + +@unittest.skipIf(not NUMPY_INSTALLED, "numpy is not available") class PythonPyLammps(unittest.TestCase): def setUp(self): machine = None @@ -49,8 +56,8 @@ class PythonPyLammps(unittest.TestCase): self.assertEqual(self.pylmp.lmp.create_atoms(2, id=None, type=types, x=x), 2) self.assertEqual(self.pylmp.system.natoms, 2) self.assertEqual(len(self.pylmp.atoms), 2) - self.assertEqual(self.pylmp.atoms[0].position, tuple(x[0:3])) - self.assertEqual(self.pylmp.atoms[1].position, tuple(x[3:6])) + numpy.testing.assert_array_equal(self.pylmp.atoms[0].position, tuple(x[0:3])) + numpy.testing.assert_array_equal(self.pylmp.atoms[1].position, tuple(x[3:6])) self.assertEqual(self.pylmp.last_run, None)