From 02f16251d41720a6477d211511aa6afc5da81715 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Aug 2024 22:09:11 -0400 Subject: [PATCH 01/44] flag development version --- src/version.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/version.h b/src/version.h index 7ef4ade45e1..9c382b3768f 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1,2 @@ #define LAMMPS_VERSION "29 Aug 2024" +#define LAMMPS_UPDATE "Development" From 6b1aec981e1663184e5ad847ff5df9c18e8638c2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Aug 2024 22:33:40 -0400 Subject: [PATCH 02/44] exceptions are always enabled now --- tools/lammps-gui/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt index 1dfd8f451d1..46f36cdb138 100644 --- a/tools/lammps-gui/CMakeLists.txt +++ b/tools/lammps-gui/CMakeLists.txt @@ -86,9 +86,7 @@ else() add_compile_options(/wd4244) add_compile_options(/wd4267) add_compile_options(/wd4250) - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() From f3f69da328a7a75597894447ffbce59a3c102171 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 10:29:41 -0400 Subject: [PATCH 03/44] expand tests on properties including custom properties --- .../c-library/test_library_properties.cpp | 84 +++++++++++++++++-- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 3d0eeef5ead..1d27075ada4 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -49,6 +49,7 @@ class LibraryProperties : public ::testing::Test { if (verbose) std::cout << output; EXPECT_THAT(output, StartsWith("LAMMPS (")); } + void TearDown() override { ::testing::internal::CaptureStdout(); @@ -470,9 +471,9 @@ TEST_F(LibraryProperties, global) EXPECT_EQ(lammps_extract_global_datatype(lmp, "xlattice"), LAMMPS_DOUBLE); EXPECT_EQ(lammps_extract_global_datatype(lmp, "ylattice"), LAMMPS_DOUBLE); EXPECT_EQ(lammps_extract_global_datatype(lmp, "zlattice"), LAMMPS_DOUBLE); - auto *xlattice = (double *)lammps_extract_global(lmp, "xlattice"); - auto *ylattice = (double *)lammps_extract_global(lmp, "ylattice"); - auto *zlattice = (double *)lammps_extract_global(lmp, "zlattice"); + auto *xlattice = (double *)lammps_extract_global(lmp, "xlattice"); + auto *ylattice = (double *)lammps_extract_global(lmp, "ylattice"); + auto *zlattice = (double *)lammps_extract_global(lmp, "zlattice"); EXPECT_NE(xlattice, nullptr); EXPECT_NE(ylattice, nullptr); EXPECT_NE(zlattice, nullptr); @@ -484,9 +485,9 @@ TEST_F(LibraryProperties, global) lammps_command(lmp, "units real"); lammps_command(lmp, "lattice fcc 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); - xlattice = (double *)lammps_extract_global(lmp, "xlattice"); - ylattice = (double *)lammps_extract_global(lmp, "ylattice"); - zlattice = (double *)lammps_extract_global(lmp, "zlattice"); + xlattice = (double *)lammps_extract_global(lmp, "xlattice"); + ylattice = (double *)lammps_extract_global(lmp, "ylattice"); + zlattice = (double *)lammps_extract_global(lmp, "zlattice"); EXPECT_NE(xlattice, nullptr); EXPECT_NE(ylattice, nullptr); EXPECT_NE(zlattice, nullptr); @@ -695,10 +696,8 @@ class AtomProperties : public ::testing::Test { protected: void *lmp; - AtomProperties() = default; - ; + AtomProperties() = default; ~AtomProperties() override = default; - ; void SetUp() override { @@ -713,11 +712,26 @@ class AtomProperties : public ::testing::Test { if (verbose) std::cout << output; EXPECT_THAT(output, StartsWith("LAMMPS (")); ::testing::internal::CaptureStdout(); + lammps_command(lmp, "fix props all property/atom i_one i2_two 2 d_three d2_four 2"); + lammps_command(lmp, "fix rmass all property/atom mol q rmass ghost yes"); lammps_command(lmp, "region box block 0 2 0 2 0 2"); lammps_command(lmp, "create_box 1 box"); lammps_command(lmp, "mass 1 3.0"); lammps_command(lmp, "create_atoms 1 single 1.0 1.0 1.5"); lammps_command(lmp, "create_atoms 1 single 0.2 0.1 0.1"); + lammps_command(lmp, "set group all mass 2.0"); + lammps_command(lmp, "set atom 1 charge -1"); + lammps_command(lmp, "set atom 2 charge 1"); + lammps_command(lmp, "set atom 1 mol 2"); + lammps_command(lmp, "set atom 2 mol 1"); + lammps_command(lmp, "set atom 1 i_one -3"); + lammps_command(lmp, "set atom 2 i_one 3"); + lammps_command(lmp, "set atom 1 d_three -1.3"); + lammps_command(lmp, "set atom 2 d_three 3.5"); + lammps_command(lmp, "set atom 1 i_two[1] -3"); + lammps_command(lmp, "set atom 2 i_two[2] 3"); + lammps_command(lmp, "set atom * d_four[1] -1.3"); + lammps_command(lmp, "set atom * d_four[2] 3.5"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; } @@ -743,6 +757,29 @@ TEST_F(AtomProperties, mass) auto *mass = (double *)lammps_extract_atom(lmp, "mass"); ASSERT_NE(mass, nullptr); ASSERT_DOUBLE_EQ(mass[1], 3.0); + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "rmass"), LAMMPS_DOUBLE); + mass = (double *)lammps_extract_atom(lmp, "rmass"); + ASSERT_NE(mass, nullptr); + ASSERT_DOUBLE_EQ(mass[0], 2.0); + ASSERT_DOUBLE_EQ(mass[1], 2.0); +} + +TEST_F(AtomProperties, charge) +{ + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "q"), LAMMPS_DOUBLE); + auto *charge = (double *)lammps_extract_atom(lmp, "q"); + ASSERT_NE(charge, nullptr); + ASSERT_DOUBLE_EQ(charge[0], -1.0); + ASSERT_DOUBLE_EQ(charge[1], 1.0); +} + +TEST_F(AtomProperties, molecule) +{ + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "molecule"), LAMMPS_TAGINT); + auto *molecule = (tagint *)lammps_extract_atom(lmp, "molecule"); + ASSERT_NE(molecule, nullptr); + ASSERT_EQ(molecule[0], 2); + ASSERT_EQ(molecule[1], 1); } TEST_F(AtomProperties, id) @@ -776,6 +813,35 @@ TEST_F(AtomProperties, position) EXPECT_DOUBLE_EQ(x[1][2], 0.1); } +TEST_F(AtomProperties, custom) +{ + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i_one"), LAMMPS_INT); + auto *one = (int *)lammps_extract_atom(lmp, "i_one"); + ASSERT_NE(one, nullptr); + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i2_two"), LAMMPS_INT_2D); + auto **two = (int **)lammps_extract_atom(lmp, "i2_two"); + ASSERT_NE(two, nullptr); + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d_three"), LAMMPS_DOUBLE); + auto *three = (double *)lammps_extract_atom(lmp, "d_three"); + ASSERT_NE(three, nullptr); + EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d2_four"), LAMMPS_DOUBLE_2D); + auto **four = (double **)lammps_extract_atom(lmp, "d2_four"); + ASSERT_NE(four, nullptr); + + EXPECT_EQ(one[0], -3); + EXPECT_EQ(one[1], 3); + EXPECT_EQ(two[0][0], -3); + EXPECT_EQ(two[0][1], 0); + EXPECT_EQ(two[1][0], 0); + EXPECT_EQ(two[1][1], 3); + EXPECT_DOUBLE_EQ(three[0], -1.3); + EXPECT_DOUBLE_EQ(three[1], 3.5); + EXPECT_DOUBLE_EQ(four[0][0], -1.3); + EXPECT_DOUBLE_EQ(four[0][1], 3.5); + EXPECT_DOUBLE_EQ(four[1][0], -1.3); + EXPECT_DOUBLE_EQ(four[1][1], 3.5); +} + TEST(SystemSettings, kokkos) { if (!lammps_config_has_package("KOKKOS")) GTEST_SKIP(); From e921af8efa934731edeadb41f30ac283341bc3e3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 10:30:04 -0400 Subject: [PATCH 04/44] fix bug where custom property dimension was not reported --- src/atom.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 52cc2c9bc95..4151074a402 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -3248,14 +3248,16 @@ int Atom::extract_datatype(const char *name) if (!array) index = find_custom(&name[2],flag,cols); else index = find_custom(&name[3],flag,cols); + // consistency checks if (index < 0) return -1; if (which != flag) return -1; if ((!array && cols) || (array && !cols)) return -1; - if (which == 0) return LAMMPS_INT; - else return LAMMPS_DOUBLE; + if (!which && !array) return LAMMPS_INT; + if (which && !array) return LAMMPS_DOUBLE; + if (!which && array) return LAMMPS_INT_2D; + if (which && array) return LAMMPS_DOUBLE_2D; } - return -1; } From 9d9e591b542f104fdccaca51a4378ec32ea55491 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 22:50:42 -0400 Subject: [PATCH 05/44] first try at implementing lammps_extract_atom_size() --- doc/src/Library_atoms.rst | 6 + examples/COUPLE/plugin/liblammpsplugin.c | 1 + examples/COUPLE/plugin/liblammpsplugin.h | 1 + fortran/lammps.f90 | 24 +- python/lammps/core.py | 68 +++-- python/lammps/numpy_wrapper.py | 69 +---- src/atom.cpp | 259 +++++++++++++++++- src/atom.h | 1 + src/library.cpp | 62 ++++- src/library.h | 1 + tools/swig/lammps.i | 2 + .../c-library/test_library_properties.cpp | 19 ++ unittest/python/python-numpy.py | 31 --- 13 files changed, 411 insertions(+), 133 deletions(-) diff --git a/doc/src/Library_atoms.rst b/doc/src/Library_atoms.rst index cebd8f0c2ee..5ebfe04b37b 100644 --- a/doc/src/Library_atoms.rst +++ b/doc/src/Library_atoms.rst @@ -4,6 +4,7 @@ Per-atom properties This section documents the following functions: - :cpp:func:`lammps_extract_atom_datatype` +- :cpp:func:`lammps_extract_atom_size` - :cpp:func:`lammps_extract_atom` ----------------------- @@ -13,6 +14,11 @@ This section documents the following functions: ----------------------- +.. doxygenfunction:: lammps_extract_atom_size + :project: progguide + +----------------------- + .. doxygenfunction:: lammps_extract_atom :project: progguide diff --git a/examples/COUPLE/plugin/liblammpsplugin.c b/examples/COUPLE/plugin/liblammpsplugin.c index 50ad2f51928..c8a38c21e42 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.c +++ b/examples/COUPLE/plugin/liblammpsplugin.c @@ -105,6 +105,7 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib) ADDSYM(map_atom); ADDSYM(extract_atom_datatype); + ADDSYM(extract_atom_size); ADDSYM(extract_atom); ADDSYM(extract_compute); diff --git a/examples/COUPLE/plugin/liblammpsplugin.h b/examples/COUPLE/plugin/liblammpsplugin.h index 556718816c9..b444f752155 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.h +++ b/examples/COUPLE/plugin/liblammpsplugin.h @@ -151,6 +151,7 @@ struct _liblammpsplugin { int (*map_atom)(void *, const void *); int (*extract_atom_datatype)(void *, const char *); + int (*extract_atom_size)(void *, const char *, int); void *(*extract_atom)(void *, const char *); void *(*extract_compute)(void *, const char *, int, int); diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index 1617891b92b..9688dae6381 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -542,6 +542,14 @@ FUNCTION lammps_extract_atom_datatype(handle, name) BIND(C) INTEGER(c_int) :: lammps_extract_atom_datatype END FUNCTION lammps_extract_atom_datatype + FUNCTION lammps_extract_atom_size(handle, name, dtype) BIND(C) + IMPORT :: c_ptr, c_int + IMPLICIT NONE + TYPE(c_ptr), INTENT(IN), VALUE :: handle, name + INTEGER(c_int), INTENT(IN), VALUE :: dtype + INTEGER(c_int) :: lammps_extract_atom_size + END FUNCTION lammps_extract_atom_size + FUNCTION lammps_extract_atom(handle, name) BIND(C) IMPORT :: c_ptr IMPLICIT NONE @@ -1461,21 +1469,12 @@ FUNCTION lmp_extract_atom(self, name) RESULT(peratom_data) ntypes = lmp_extract_setting(self, 'ntypes') Cname = f2c_string(name) datatype = lammps_extract_atom_datatype(self%handle, Cname) + ! Fortran and C/C++ have rows and columns switched + ncols = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_ROWS) + nrows = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_COLS) Cptr = lammps_extract_atom(self%handle, Cname) CALL lammps_free(Cname) - SELECT CASE (name) - CASE ('mass') - ncols = ntypes + 1 - nrows = 1 - CASE ('x','v','f','mu','omega','torque','angmom') - ncols = nmax - nrows = 3 - CASE DEFAULT - ncols = nmax - nrows = 1 - END SELECT - peratom_data%lammps_instance => self SELECT CASE (datatype) CASE (LAMMPS_INT) @@ -1486,6 +1485,7 @@ FUNCTION lmp_extract_atom(self, name) RESULT(peratom_data) CALL C_F_POINTER(Cptr, peratom_data%i64_vec, [ncols]) CASE (LAMMPS_DOUBLE) peratom_data%datatype = DATA_DOUBLE_1D + ! The mass array is allocated from 0, but only used from 1. We also want to use it from 1. IF (name == 'mass') THEN CALL C_F_POINTER(Cptr, dummy, [ncols]) peratom_data%r64_vec(0:) => dummy diff --git a/python/lammps/core.py b/python/lammps/core.py index 9e6329fe3cf..b1907888e3d 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -318,6 +318,8 @@ def __init__(self,name='',cmdargs=None,ptr=None,comm=None): self.lib.lammps_extract_atom.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_atom_datatype.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_atom_datatype.restype = c_int + self.lib.lammps_extract_atom_size.argtypes = [c_void_p, c_char_p, c_int] + self.lib.lammps_extract_atom_size.restype = c_int self.lib.lammps_extract_fix.argtypes = [c_void_p, c_char_p, c_int, c_int, c_int, c_int] @@ -1070,31 +1072,59 @@ def extract_atom_datatype(self, name): else: return None return self.lib.lammps_extract_atom_datatype(self.lmp, newname) + # ------------------------------------------------------------------------- + # extract per-atom info datatype + + def extract_atom_size(self, name, dtype): + """Retrieve per-atom property dimensions from LAMMPS + + This is a wrapper around the :cpp:func:`lammps_extract_atom_size` + function of the C-library interface. Its documentation includes a + list of the supported keywords. + This function returns ``None`` if the keyword is not + recognized. Otherwise it will return an integer value with the size + of the per-atom vector or array. If *name* corresponds to a per-atom + array, the *dtype* keyword must be either LMP_SIZE_ROWS or LMP_SIZE_COLS + from the :ref:`type ` constants defined in the + :py:mod:`lammps` module. The return value is the requested size. + If *name* corresponds to a per-atom vector the *dtype* keyword is ignored. + + :param name: name of the property + :type name: string + :param type: either LMP_SIZE_ROWS or LMP_SIZE_COLS for arrays, otherwise ignored + :type type: int + :return: data type of per-atom property (see :ref:`py_datatype_constants`) + :rtype: int + """ + if name: newname = name.encode() + else: return None + return self.lib.lammps_extract_atom_size(self.lmp, newname, dtype) + # ------------------------------------------------------------------------- # extract per-atom info def extract_atom(self, name, dtype=LAMMPS_AUTODETECT): """Retrieve per-atom properties from LAMMPS - This is a wrapper around the :cpp:func:`lammps_extract_atom` - function of the C-library interface. Its documentation includes a - list of the supported keywords and their data types. - Since Python needs to know the data type to be able to interpret - the result, by default, this function will try to auto-detect the data type - by asking the library. You can also force a specific data type by setting ``dtype`` - to one of the :ref:`data type ` constants defined in the - :py:mod:`lammps` module. - This function returns ``None`` if either the keyword is not - recognized, or an invalid data type constant is used. + This is a wrapper around the :cpp:func:`lammps_extract_atom` function of the + C-library interface. Its documentation includes a list of the supported + keywords and their data types. Since Python needs to know the data type to + be able to interpret the result, by default, this function will try to + auto-detect the data type by asking the library. You can also force a + specific data type by setting ``dtype`` to one of the :ref:`data type + ` constants defined in the :py:mod:`lammps` module. + This function returns ``None`` if either the keyword is not recognized, or + an invalid data type constant is used. .. note:: - While the returned arrays of per-atom data are dimensioned - for the range [0:nmax] - as is the underlying storage - - the data is usually only valid for the range of [0:nlocal], - unless the property of interest is also updated for ghost - atoms. In some cases, this depends on a LAMMPS setting, see - for example :doc:`comm_modify vel yes `. + While the returned vectors or arrays of per-atom data are dimensioned for + the range [0:nmax] - as is the underlying storage - the data is usually + only valid for the range of [0:nlocal], unless the property of interest + is also updated for ghost atoms. In some cases, this depends on a LAMMPS + setting, see for example :doc:`comm_modify vel yes `. + The actual size can be determined by calling + py:meth:`extract_atom_size() `. :param name: name of the property :type name: string @@ -1105,6 +1135,7 @@ def extract_atom(self, name, dtype=LAMMPS_AUTODETECT): ctypes.POINTER(ctypes.c_int64), ctypes.POINTER(ctypes.POINTER(ctypes.c_int64)), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.POINTER(ctypes.c_double)), or NoneType + """ if dtype == LAMMPS_AUTODETECT: dtype = self.extract_atom_datatype(name) @@ -2522,3 +2553,8 @@ def find_compute_neighlist(self, computeid, reqid=0): newcomputeid = computeid.encode() idx = self.lib.lammps_find_compute_neighlist(self.lmp, newcomputeid, reqid) return idx + +# Local Variables: +# fill-column: 80 +# End: + diff --git a/python/lammps/numpy_wrapper.py b/python/lammps/numpy_wrapper.py index 9ab7f538de0..a980a972fd8 100644 --- a/python/lammps/numpy_wrapper.py +++ b/python/lammps/numpy_wrapper.py @@ -54,7 +54,8 @@ def _ctype_to_numpy_int(self, ctype_int): # ------------------------------------------------------------------------- - def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, dim=LAMMPS_AUTODETECT): + def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, + dim=LAMMPS_AUTODETECT): """Retrieve per-atom properties from LAMMPS as NumPy arrays This is a wrapper around the :py:meth:`lammps.extract_atom()` method. @@ -63,16 +64,16 @@ def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, d .. note:: - The returned arrays of per-atom data are by default dimensioned - for the range [0:nlocal] since that data is *always* valid. The - underlying storage for the data, however, is typically allocated - for the range of [0:nmax]. Whether there is valid data in the range - [nlocal:nlocal+nghost] depends on whether the property of interest - is also updated for ghost atoms. This is not often the case. In - some cases, it depends on a LAMMPS setting, see for example - :doc:`comm_modify vel yes `. By using the optional - *nelem* parameter the size of the returned NumPy can be overridden. - There is no check whether the number of elements chosen is valid. + The returned vectors or arrays of per-atom data are dimensioned + according to the return value of :py:meth:`lammps.extract_atom_size()`. + Except for the "mass" property, the underlying storage will always be + dimensioned for the range [0:nmax]. The actual usable data may be + only in the range [0:nlocal] or [0:nlocal][0:dim]. Whether there is + valid data in the range [nlocal:nlocal+nghost] or [nlocal:local+nghost][0:dim] + depends on whether the property of interest is also updated for ghost atoms. + Also the value of *dim* depends on the value of *name*. By using the optional + *nelem* and *dim* parameters the dimensions of the returned NumPy array can + be overridden. There is no check whether the number of elements chosen is valid. :param name: name of the property :type name: string @@ -89,21 +90,10 @@ def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, d dtype = self.lmp.extract_atom_datatype(name) if nelem == LAMMPS_AUTODETECT: - if name == "mass": - nelem = self.lmp.extract_global("ntypes") + 1 - else: - nelem = self.lmp.extract_global("nlocal") + nelem = self.lmp.extract_atom_size(name, LMP_SIZE_ROWS) 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", "csforce", "vforce", "vest"): - dim = 3 - elif name == "smd_data_9": - dim = 9 - elif name == "smd_stress": - dim = 6 - else: - dim = 2 + dim = self.lmp.extract_atom_size(name, LMP_SIZE_COLS) else: dim = 1 @@ -119,37 +109,6 @@ def extract_atom(self, name, dtype=LAMMPS_AUTODETECT, nelem=LAMMPS_AUTODETECT, d # ------------------------------------------------------------------------- - def extract_atom_iarray(self, name, nelem, dim=1): - warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) - - if name in ['id', 'molecule']: - c_int_type = self.lmp.c_tagint - elif name in ['image']: - c_int_type = self.lmp.c_imageint - else: - c_int_type = c_int - - if dim == 1: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT) - else: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_INT_2D) - - return self.iarray(c_int_type, raw_ptr, nelem, dim) - - # ------------------------------------------------------------------------- - - def extract_atom_darray(self, name, nelem, dim=1): - warnings.warn("deprecated, use extract_atom instead", DeprecationWarning) - - if dim == 1: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE) - else: - raw_ptr = self.lmp.extract_atom(name, LAMMPS_DOUBLE_2D) - - return self.darray(raw_ptr, nelem, dim) - - # ------------------------------------------------------------------------- - def extract_compute(self, cid, cstyle, ctype): """Retrieve data from a LAMMPS compute diff --git a/src/atom.cpp b/src/atom.cpp index 4151074a402..4a638652c74 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2739,10 +2739,10 @@ Classes rarely need to check on ghost communication and so `find_custom` is typically preferred to this function. See :doc:`pair amoeba ` for an example where checking ghost communication is necessary. \endverbatim - * \param name Name of the property (w/o a "i_" or "d_" or "i2_" or "d2_" prefix) - * \param &flag Returns data type of property: 0 for int, 1 for double - * \param &cols Returns number of values: 0 for a single value, 1 or more for a vector of values - * \param &ghost Returns whether property is communicated to ghost atoms: 0 for no, 1 for yes + * \param name Name of the property (w/o a "i_" or "d_" or "i2_" or "d2_" prefix) + * \param &flag Returns data type of property: 0 for int, 1 for double + * \param &cols Returns number of values: 0 for a single value, 1 or more for a vector of values + * \param &ghost Returns whether property is communicated to ghost atoms: 0 for no, 1 for yes * \return index of property in the respective list of properties */ int Atom::find_custom_ghost(const char *name, int &flag, int &cols, int &ghost) @@ -2999,11 +2999,13 @@ length of the data area, and a short description. - N double values defined by fix property/atom array name *See also* - :cpp:func:`lammps_extract_atom` + :cpp:func:`lammps_extract_atom`, + :cpp:func:`lammps_extract_atom_datatype`, + :cpp:func:`lammps_extract_atom_size` \endverbatim * - * \sa extract_datatype + * \sa extract_datatype, extract_size * * \param name string with the keyword of the desired property. Typically the name of the pointer variable returned @@ -3142,7 +3144,7 @@ void *Atom::extract(const char *name) \endverbatim * - * \sa extract + * \sa extract extract_size * * \param name string with the keyword of the desired property. * \return data type constant for desired property or -1 */ @@ -3177,10 +3179,14 @@ int Atom::extract_datatype(const char *name) if (strcmp(name,"temperature") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"heatflow") == 0) return LAMMPS_DOUBLE; + // PERI package (and in part MACHDYN) + if (strcmp(name,"vfrac") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"s0") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"x0") == 0) return LAMMPS_DOUBLE_2D; + // AWPMD package (and in part EFF and ELECTRODE) + if (strcmp(name,"espin") == 0) return LAMMPS_INT; if (strcmp(name,"spin") == 0) return LAMMPS_INT; // backwards compatibility if (strcmp(name,"eradius") == 0) return LAMMPS_DOUBLE; @@ -3261,6 +3267,245 @@ int Atom::extract_datatype(const char *name) return -1; } +/** Provide vector or array size info of internal data of the Atom class + * +\verbatim embed:rst + +.. versionadded:: TBD + +\endverbatim + * + * \sa extract extract_datatype + * + * \param name string with the keyword of the desired property. + * \param type either LMP_SIZE_ROWS or LMP_SIZE_COLS for per-atom array or ignored + * \return size of the vector or size of the array for the requested dimension or -1 */ + +int Atom::extract_size(const char *name, int type) +{ + // -------------------------------------------------------------------- + // 6th customization section: customize by adding new variable name + + const auto datatype = extract_datatype(name); + const auto nall = nlocal + nghost; + const auto ghost_vel = comm->ghost_velocity; + + if ((datatype == LAMMPS_DOUBLE_2D) || (datatype == LAMMPS_INT_2D)) { + if (type == LMP_SIZE_ROWS) { + if (strcmp(name,"x") == 0) return nall; + if (strcmp(name,"v") == 0) { + if (ghost_vel) return nall; + else return nlocal; + } + if (strcmp(name,"f") == 0) return nall; + if (strcmp(name,"mu") == 0) return nall; + if (strcmp(name,"omega") == 0) { + if (ghost_vel) return nall; + else return nlocal; + } + if (strcmp(name,"angmom") == 0) { + if (ghost_vel) return nall; + else return nlocal; + } + if (strcmp(name,"torque") == 0) return nlocal; + if (strcmp(name,"quat") == 0) { + if (ghost_vel) return nall; + else return nlocal; + } + + // PERI package + + if (strcmp(name,"x0") == 0) return nall; + + // SPIN package + + if (strcmp(name,"sp") == 0) return nall; + if (strcmp(name,"fm") == 0) return nlocal; + if (strcmp(name,"fm_long") == 0) return nlocal; + + // AWPMD package + + if (strcmp(name,"cs") == 0) { + if (ghost_vel) return nall; + else return nlocal; + } + if (strcmp(name,"csforce") == 0) return nlocal; + if (strcmp(name,"vforce") == 0) return nlocal; + + // SPH package + + if (strcmp(name,"vest") == 0) return nall; + + // MACHDYN package + + if (strcmp(name, "smd_data_9") == 0) return LAMMPS_DOUBLE_2D; + if (strcmp(name, "smd_stress") == 0) return LAMMPS_DOUBLE_2D; + + } else if (type == LMP_SIZE_COLS) { + + if (strcmp(name,"x") == 0) return 3; + if (strcmp(name,"v") == 0) return 3; + if (strcmp(name,"f") == 0) return 3; + if (strcmp(name,"mu") == 0) return 4; + if (strcmp(name,"omega") == 0) return 3; + if (strcmp(name,"angmom") == 0) return 3; + if (strcmp(name,"torque") == 0) return 3; + if (strcmp(name,"quat") == 0) return 4; + + // PERI package + + if (strcmp(name,"x0") == 0) return 3; + + // SPIN package + + if (strcmp(name,"sp") == 0) return 4; + if (strcmp(name,"fm") == 0) return 3; + if (strcmp(name,"fm_long") == 0) return 3; + + // AWPMD package + + if (strcmp(name,"cs") == 0) return 2; + if (strcmp(name,"csforce") == 0) return 2; + if (strcmp(name,"vforce") == 0) return 3; + + // SPH package + + if (strcmp(name,"vest") == 0) return 3; + + // MACHDYN package + + if (strcmp(name, "smd_data_9") == 0) return 9; + if (strcmp(name, "smd_stress") == 0) return 6; + } + + // custom arrays + + if (utils::strmatch(name,"^[id]2_")) { + int which = 0; + if (name[0] == 'd') which = 1; + + int index,flag,cols,ghost; + index = find_custom_ghost(&name[3],flag,cols,ghost); + + // consistency checks + if (index < 0) return -1; + if (which != flag) return -1; + if (!cols) return -1; + + if (type == LMP_SIZE_ROWS) { + if (ghost) return nall; + else return nlocal; + } else if (type == LMP_SIZE_COLS) { + return cols; + } + } + } else { + + if (strcmp(name,"mass") == 0) return ntypes + 1; + + if (strcmp(name,"id") == 0) return nall; + if (strcmp(name,"type") == 0) return nall; + if (strcmp(name,"mask") == 0) return nall; + if (strcmp(name,"image") == 0) return nlocal; + if (strcmp(name,"molecule") == 0) return nall; + if (strcmp(name,"q") == 0) return nall; + if (strcmp(name,"radius") == 0) return nall; + if (strcmp(name,"rmass") == 0) return nall; + + // ASPHERE package + + if (strcmp(name,"ellipsoid") == 0) return nlocal; + + // BODY package + + if (strcmp(name,"line") == 0) return nlocal; + if (strcmp(name,"tri") == 0) return nlocal; + if (strcmp(name,"body") == 0) return nlocal; + + // PERI package (and in part MACHDYN) + + if (strcmp(name,"vfrac") == 0) return nall; + if (strcmp(name,"s0") == 0) return nall; + + // AWPMD package (and in part EFF and ELECTRODE) + + if (strcmp(name,"espin") == 0) return nall; + if (strcmp(name,"spin") == 0) return nall; // backwards compatibility + if (strcmp(name,"eradius") == 0) return nall; + if (strcmp(name,"ervel") == 0) return nlocal; + if (strcmp(name,"erforce") == 0) return nlocal; + if (strcmp(name,"ervelforce") == 0) return nlocal; + if (strcmp(name,"etag") == 0) return nall; + + // CG-DNA package + + if (strcmp(name,"id5p") == 0) return nall; + + // RHEO package + + if (strcmp(name,"temperature") == 0) return nlocal; + if (strcmp(name,"heatflow") == 0) return nlocal; + if (strcmp(name,"rheo_status") == 0) return nall; + if (strcmp(name,"conductivity") == 0) return nlocal; + if (strcmp(name,"pressure") == 0) return nlocal; + if (strcmp(name,"viscosity") == 0) return nlocal; + + // SPH package + + if (strcmp(name,"rho") == 0) return nall; + if (strcmp(name,"drho") == 0) return nlocal; + if (strcmp(name,"esph") == 0) return nall; + if (strcmp(name,"desph") == 0) return nlocal; + if (strcmp(name,"cv") == 0) return nall; + + // MACHDYN package + + if (strcmp(name, "contact_radius") == 0) return nall; + if (strcmp(name, "eff_plastic_strain") == 0) return nlocal; + if (strcmp(name, "eff_plastic_strain_rate") == 0) return nlocal; + if (strcmp(name, "damage") == 0) return nlocal; + + // DPD-REACT package + + if (strcmp(name,"dpdTheta") == 0) return nall; + + // DPD-MESO package + + if (strcmp(name,"edpd_temp") == 0) return nall; + + // DIELECTRIC package + + if (strcmp(name,"area") == 0) return nall; + if (strcmp(name,"ed") == 0) return nall; + if (strcmp(name,"em") == 0) return nall; + if (strcmp(name,"epsilon") == 0) return nall; + if (strcmp(name,"curvature") == 0) return nall; + if (strcmp(name,"q_unscaled") == 0) return nall; + + // end of customization section + // -------------------------------------------------------------------- + + // custom vectors + + if (utils::strmatch(name,"^[id]_")) { + int which = 0; + if (name[0] == 'd') which = 1; + + int index,flag,cols,ghost; + index = find_custom_ghost(&name[2],flag,cols,ghost); + + // consistency checks + if (index < 0) return -1; + if (which != flag) return -1; + if (cols) return -1; + + if (ghost) return nall; + else return nlocal; + } + } + return -1; +} + /* ---------------------------------------------------------------------- return # of bytes of allocated memory call to avec tallies per-atom vectors diff --git a/src/atom.h b/src/atom.h index bd5b352cd0c..c98f06cbe88 100644 --- a/src/atom.h +++ b/src/atom.h @@ -378,6 +378,7 @@ class Atom : protected Pointers { void *extract(const char *); int extract_datatype(const char *); + int extract_size(const char *, int); inline int *get_map_array() { return map_array; }; inline int get_map_size() { return map_tag_max + 1; }; diff --git a/src/library.cpp b/src/library.cpp index 950702c420a..29cec304881 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2087,10 +2087,13 @@ int lammps_map_atom(void *handle, const void *id) .. versionadded:: 18Sep2020 -This function returns an integer that encodes the data type of the per-atom -property with the specified name. See :cpp:enum:`_LMP_DATATYPE_CONST` for valid -values. Callers of :cpp:func:`lammps_extract_atom` can use this information -to then decide how to cast the ``void *`` pointer and access the data. +This function returns an integer that encodes the data type of the +per-atom property with the specified name. See +:cpp:enum:`_LMP_DATATYPE_CONST` for valid values. Callers of +:cpp:func:`lammps_extract_atom` can use this information to decide how +to cast the ``void *`` pointer and access the data. In addition, +:cpp:func:`lammps_extract_atom_size` can be used to get information +about the vector or array dimensions. \endverbatim * @@ -2108,18 +2111,53 @@ int lammps_extract_atom_datatype(void *handle, const char *name) /* ---------------------------------------------------------------------- */ +/** Get dimension info of a LAMMPS per-atom property + * +\verbatim embed:rst + +.. versionadded:: TBD + +This function returns an integer with the size of the per-atom +property with the specified name. This allows to accurately determine +the size of the per-atom data vectors or arrays. For per-atom arrays, +the *type* argument is required to return either the number of rows or the +number of columns. It is ignored for per-atom vectors. + +Callers of :cpp:func:`lammps_extract_atom` can use this information in +combination with the result from :cpp:func:`lammps_extract_atom_datatype` +to decide how to cast the ``void *`` pointer and access the data. + +\endverbatim + * + * \param handle pointer to a previously created LAMMPS instance + * \param name string with the name of the extracted property + * \param type either LMP_SIZE_ROWS or LMP_SIZE_COLS if *name* refers + to a per-atom array otherwise ignored + * \return integer with the size of the vector or array dimension or -1 + * */ + +int lammps_extract_atom_size(void *handle, const char *name, int type) +{ + auto lmp = (LAMMPS *) handle; + return lmp->atom->extract_size(name, type); +} + +/* ---------------------------------------------------------------------- */ + /** Get pointer to a LAMMPS per-atom property. * \verbatim embed:rst -This function returns a pointer to the location of per-atom properties -(and per-atom-type properties in the case of the 'mass' keyword). -Per-atom data is distributed across sub-domains and thus MPI ranks. The -returned pointer is cast to ``void *`` and needs to be cast to a pointer -of data type that the entity represents. +This function returns a pointer to the location of per-atom properties (and +per-atom-type properties in the case of the 'mass' keyword). Per-atom data is +distributed across sub-domains and thus MPI ranks. The returned pointer is cast +to ``void *`` and needs to be cast to a pointer of data type that the entity +represents. You can use the functions :cpp:func:`lammps_extract_atom_datatype` +and :cpp:func:`lammps_extract_atom_size` to determine data type, dimensions and +sizes of the storage pointed to by the returned pointer. -A table with supported keywords is included in the documentation -of the :cpp:func:`Atom::extract() ` function. +A table with supported keywords is included in the documentation of the +:cpp:func:`Atom::extract() ` function. .. warning:: @@ -7027,5 +7065,5 @@ int lammps_python_api_version() { } // Local Variables: -// fill-column: 72 +// fill-column: 80 // End: diff --git a/src/library.h b/src/library.h index ff16aaa0885..dbfd32a542b 100644 --- a/src/library.h +++ b/src/library.h @@ -172,6 +172,7 @@ int lammps_map_atom(void *handle, const void *id); * ---------------------------------------------------------------------- */ int lammps_extract_atom_datatype(void *handle, const char *name); +int lammps_extract_atom_size(void *handle, const char *name, int type); void *lammps_extract_atom(void *handle, const char *name); /* ---------------------------------------------------------------------- diff --git a/tools/swig/lammps.i b/tools/swig/lammps.i index 9bef047da46..11f5a270a17 100644 --- a/tools/swig/lammps.i +++ b/tools/swig/lammps.i @@ -130,6 +130,7 @@ extern void *lammps_extract_pair(void *handle, const char *name); extern int lammps_map_atom(void *handle, const void *id); extern int lammps_extract_atom_datatype(void *handle, const char *name); +extern int lammps_extract_atom_size(void *handle, const char *name, int type); extern void *lammps_extract_atom(void *handle, const char *name); extern void *lammps_extract_compute(void *handle, const char *id, int, int); @@ -319,6 +320,7 @@ extern void *lammps_extract_pair(void *handle, const char *name); extern int lammps_map_atom(void *handle, const void *id); extern int lammps_extract_atom_datatype(void *handle, const char *name); +extern int lammps_extract_atom_size(void *handle, const char *name, int type); extern void *lammps_extract_atom(void *handle, const char *name); extern void *lammps_extract_compute(void *handle, const char *id, int, int); diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 1d27075ada4..737015ccdcd 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -695,6 +695,7 @@ TEST_F(LibraryProperties, has_error) class AtomProperties : public ::testing::Test { protected: void *lmp; + int ntypes, nlocal, nall; AtomProperties() = default; ~AtomProperties() override = default; @@ -732,6 +733,10 @@ class AtomProperties : public ::testing::Test { lammps_command(lmp, "set atom 2 i_two[2] 3"); lammps_command(lmp, "set atom * d_four[1] -1.3"); lammps_command(lmp, "set atom * d_four[2] 3.5"); + ntypes = lammps_extract_setting(lmp, "ntypes"); + nlocal = lammps_extract_setting(lmp, "nlocal"); + nall = lammps_extract_setting(lmp, "nall"); + output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; } @@ -754,10 +759,12 @@ TEST_F(AtomProperties, invalid) TEST_F(AtomProperties, mass) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "mass"), LAMMPS_DOUBLE); + EXPECT_EQ(lammps_extract_atom_size(lmp, "mass", 0), ntypes + 1); auto *mass = (double *)lammps_extract_atom(lmp, "mass"); ASSERT_NE(mass, nullptr); ASSERT_DOUBLE_EQ(mass[1], 3.0); EXPECT_EQ(lammps_extract_atom_datatype(lmp, "rmass"), LAMMPS_DOUBLE); + EXPECT_EQ(lammps_extract_atom_size(lmp, "rmass", 0), nall); mass = (double *)lammps_extract_atom(lmp, "rmass"); ASSERT_NE(mass, nullptr); ASSERT_DOUBLE_EQ(mass[0], 2.0); @@ -767,6 +774,7 @@ TEST_F(AtomProperties, mass) TEST_F(AtomProperties, charge) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "q"), LAMMPS_DOUBLE); + EXPECT_EQ(lammps_extract_atom_size(lmp, "rmass", 0), nall); auto *charge = (double *)lammps_extract_atom(lmp, "q"); ASSERT_NE(charge, nullptr); ASSERT_DOUBLE_EQ(charge[0], -1.0); @@ -776,6 +784,7 @@ TEST_F(AtomProperties, charge) TEST_F(AtomProperties, molecule) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "molecule"), LAMMPS_TAGINT); + EXPECT_EQ(lammps_extract_atom_size(lmp, "molecule", 0), nall); auto *molecule = (tagint *)lammps_extract_atom(lmp, "molecule"); ASSERT_NE(molecule, nullptr); ASSERT_EQ(molecule[0], 2); @@ -785,6 +794,7 @@ TEST_F(AtomProperties, molecule) TEST_F(AtomProperties, id) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "id"), LAMMPS_TAGINT); + EXPECT_EQ(lammps_extract_atom_size(lmp, "id", 0), nall); auto *id = (tagint *)lammps_extract_atom(lmp, "id"); ASSERT_NE(id, nullptr); ASSERT_EQ(id[0], 1); @@ -794,6 +804,7 @@ TEST_F(AtomProperties, id) TEST_F(AtomProperties, type) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "type"), LAMMPS_INT); + EXPECT_EQ(lammps_extract_atom_size(lmp, "type", 0), nall); int *type = (int *)lammps_extract_atom(lmp, "type"); ASSERT_NE(type, nullptr); ASSERT_EQ(type[0], 1); @@ -803,6 +814,8 @@ TEST_F(AtomProperties, type) TEST_F(AtomProperties, position) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "x"), LAMMPS_DOUBLE_2D); + EXPECT_EQ(lammps_extract_atom_size(lmp, "x", LMP_SIZE_ROWS), nall); + EXPECT_EQ(lammps_extract_atom_size(lmp, "x", LMP_SIZE_COLS), 3); auto **x = (double **)lammps_extract_atom(lmp, "x"); ASSERT_NE(x, nullptr); EXPECT_DOUBLE_EQ(x[0][0], 1.0); @@ -816,15 +829,21 @@ TEST_F(AtomProperties, position) TEST_F(AtomProperties, custom) { EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i_one"), LAMMPS_INT); + EXPECT_EQ(lammps_extract_atom_size(lmp, "i_one", 0), nlocal); auto *one = (int *)lammps_extract_atom(lmp, "i_one"); ASSERT_NE(one, nullptr); EXPECT_EQ(lammps_extract_atom_datatype(lmp, "i2_two"), LAMMPS_INT_2D); + EXPECT_EQ(lammps_extract_atom_size(lmp, "i2_two", LMP_SIZE_ROWS), nlocal); + EXPECT_EQ(lammps_extract_atom_size(lmp, "i2_two", LMP_SIZE_COLS), 2); auto **two = (int **)lammps_extract_atom(lmp, "i2_two"); ASSERT_NE(two, nullptr); EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d_three"), LAMMPS_DOUBLE); + EXPECT_EQ(lammps_extract_atom_size(lmp, "d_three", 0), nlocal); auto *three = (double *)lammps_extract_atom(lmp, "d_three"); ASSERT_NE(three, nullptr); EXPECT_EQ(lammps_extract_atom_datatype(lmp, "d2_four"), LAMMPS_DOUBLE_2D); + EXPECT_EQ(lammps_extract_atom_size(lmp, "d2_four", LMP_SIZE_ROWS), nlocal); + EXPECT_EQ(lammps_extract_atom_size(lmp, "d2_four", LMP_SIZE_COLS), 2); auto **four = (double **)lammps_extract_atom(lmp, "d2_four"); ASSERT_NE(four, nullptr); diff --git a/unittest/python/python-numpy.py b/unittest/python/python-numpy.py index 839e5d03af8..b7f1a4eedb1 100644 --- a/unittest/python/python-numpy.py +++ b/unittest/python/python-numpy.py @@ -155,37 +155,6 @@ def testExtractComputeLocalArray(self): self.assertEqual(values[1,0], 1.5) self.assertEqual(values[1,3], 1.5) - def testExtractAtomDeprecated(self): - self.lmp.command("units lj") - self.lmp.command("atom_style atomic") - self.lmp.command("atom_modify map array") - self.lmp.command("region box block 0 2 0 2 0 2") - self.lmp.command("create_box 1 box") - - x = [ - 1.0, 1.0, 1.0, - 1.0, 1.0, 1.5 - ] - - types = [1, 1] - - self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2) - nlocal = self.lmp.extract_global("nlocal", LAMMPS_INT) - self.assertEqual(nlocal, 2) - - ident = self.lmp.numpy.extract_atom_iarray("id", nlocal, dim=1) - self.assertEqual(len(ident), 2) - - ntypes = self.lmp.extract_global("ntypes", LAMMPS_INT) - self.assertEqual(ntypes, 1) - - x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3) - v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3) - self.assertEqual(len(x), 2) - self.assertTrue((x[0] == (1.0, 1.0, 1.0)).all()) - self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all()) - self.assertEqual(len(v), 2) - def testExtractAtom(self): self.lmp.command("units lj") self.lmp.command("atom_style atomic") From 3e7123e21e6f1463200c7cfdebcedff6c3c67013 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 22:51:08 -0400 Subject: [PATCH 06/44] make compatible with comm_modify vel yes --- src/CG-DNA/atom_vec_oxdna.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CG-DNA/atom_vec_oxdna.cpp b/src/CG-DNA/atom_vec_oxdna.cpp index 38f78f94bff..0836e9b47c8 100644 --- a/src/CG-DNA/atom_vec_oxdna.cpp +++ b/src/CG-DNA/atom_vec_oxdna.cpp @@ -37,6 +37,7 @@ AtomVecOxdna::AtomVecOxdna(LAMMPS *lmp) : AtomVec(lmp) fields_grow = {"id5p"}; fields_copy = {"id5p"}; fields_border = {"id5p"}; + fields_border_vel = {"id5p"}; fields_exchange = {"id5p"}; fields_restart = {"id5p"}; fields_data_atom = {"id", "type", "x"}; From b426556632e3235b28baf25922cf274587d1ece4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 22:51:31 -0400 Subject: [PATCH 07/44] replace bogus allocation --- src/ML-QUIP/pair_quip.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ML-QUIP/pair_quip.cpp b/src/ML-QUIP/pair_quip.cpp index a2de4bf38a7..9d18d6bad90 100644 --- a/src/ML-QUIP/pair_quip.cpp +++ b/src/ML-QUIP/pair_quip.cpp @@ -286,7 +286,7 @@ void PairQUIP::coeff(int narg, char **arg) // and returns the necessary size of quip_potential. This behavior // is invoked by setting n_potential_quip to 0. n_quip_potential = 0; - quip_potential = new int[0]; + quip_potential = new int[1]; quip_lammps_potential_initialise(quip_potential, &n_quip_potential, &cutoff, quip_file, &n_quip_file, quip_string, &n_quip_string); delete[] quip_potential; @@ -295,6 +295,7 @@ void PairQUIP::coeff(int narg, char **arg) // the location of the previously initialised potential to the quip_potential // variable, and we will use it as a handle when calling the actual calculation // routine. We return the cutoff as well. + delete[] quip_potential; quip_potential = new int[n_quip_potential]; quip_lammps_potential_initialise(quip_potential, &n_quip_potential, &cutoff, quip_file, &n_quip_file, quip_string, &n_quip_string); From 0cdf8f2658ecc716a44b9385b4bd1c9837d3d6bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 23:16:37 -0400 Subject: [PATCH 08/44] swap rows/cols for less confusion --- fortran/lammps.f90 | 17 ++++++++--------- python/lammps/core.py | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index 9688dae6381..b7ce528b583 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -1469,9 +1469,8 @@ FUNCTION lmp_extract_atom(self, name) RESULT(peratom_data) ntypes = lmp_extract_setting(self, 'ntypes') Cname = f2c_string(name) datatype = lammps_extract_atom_datatype(self%handle, Cname) - ! Fortran and C/C++ have rows and columns switched - ncols = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_ROWS) - nrows = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_COLS) + nrows = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_ROWS) + ncols = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_COLS) Cptr = lammps_extract_atom(self%handle, Cname) CALL lammps_free(Cname) @@ -1479,25 +1478,25 @@ FUNCTION lmp_extract_atom(self, name) RESULT(peratom_data) SELECT CASE (datatype) CASE (LAMMPS_INT) peratom_data%datatype = DATA_INT_1D - CALL C_F_POINTER(Cptr, peratom_data%i32_vec, [ncols]) + CALL C_F_POINTER(Cptr, peratom_data%i32_vec, [nrows]) CASE (LAMMPS_INT64) peratom_data%datatype = DATA_INT64_1D - CALL C_F_POINTER(Cptr, peratom_data%i64_vec, [ncols]) + CALL C_F_POINTER(Cptr, peratom_data%i64_vec, [nrows]) CASE (LAMMPS_DOUBLE) peratom_data%datatype = DATA_DOUBLE_1D ! The mass array is allocated from 0, but only used from 1. We also want to use it from 1. IF (name == 'mass') THEN - CALL C_F_POINTER(Cptr, dummy, [ncols]) + CALL C_F_POINTER(Cptr, dummy, [nrows]) peratom_data%r64_vec(0:) => dummy ELSE - CALL C_F_POINTER(Cptr, peratom_data%r64_vec, [ncols]) + CALL C_F_POINTER(Cptr, peratom_data%r64_vec, [nrows]) END IF CASE (LAMMPS_DOUBLE_2D) peratom_data%datatype = DATA_DOUBLE_2D ! First, we dereference the void** pointer to point to the void* - CALL C_F_POINTER(Cptr, Catomptr, [ncols]) + CALL C_F_POINTER(Cptr, Catomptr, [nrows]) ! Catomptr(1) now points to the first element of the array - CALL C_F_POINTER(Catomptr(1), peratom_data%r64_mat, [nrows,ncols]) + CALL C_F_POINTER(Catomptr(1), peratom_data%r64_mat, [ncols,nrows]) CASE (-1) CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & 'per-atom property ' // name // ' not found in extract_setting') diff --git a/python/lammps/core.py b/python/lammps/core.py index b1907888e3d..788da0116f5 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -2557,4 +2557,3 @@ def find_compute_neighlist(self, computeid, reqid=0): # Local Variables: # fill-column: 80 # End: - From cdd26401010e88a86f93b23c6b074eb40a66c845 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 30 Aug 2024 23:22:29 -0400 Subject: [PATCH 09/44] remove double delete[] --- src/ML-QUIP/pair_quip.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ML-QUIP/pair_quip.cpp b/src/ML-QUIP/pair_quip.cpp index 9d18d6bad90..35ba4ff8e44 100644 --- a/src/ML-QUIP/pair_quip.cpp +++ b/src/ML-QUIP/pair_quip.cpp @@ -295,7 +295,6 @@ void PairQUIP::coeff(int narg, char **arg) // the location of the previously initialised potential to the quip_potential // variable, and we will use it as a handle when calling the actual calculation // routine. We return the cutoff as well. - delete[] quip_potential; quip_potential = new int[n_quip_potential]; quip_lammps_potential_initialise(quip_potential, &n_quip_potential, &cutoff, quip_file, &n_quip_file, quip_string, &n_quip_string); From 35c36bb16ea265f5aeb83a5305c5671d6fd7d237 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 00:55:22 -0400 Subject: [PATCH 10/44] step version number for LAMMPS-GUI --- tools/lammps-gui/CMakeLists.txt | 2 +- tools/lammps-gui/lammps-gui.appdata.xml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt index 46f36cdb138..fc111f5c64c 100644 --- a/tools/lammps-gui/CMakeLists.txt +++ b/tools/lammps-gui/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -project(lammps-gui VERSION 1.6.10 LANGUAGES CXX) +project(lammps-gui VERSION 1.6.11 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) diff --git a/tools/lammps-gui/lammps-gui.appdata.xml b/tools/lammps-gui/lammps-gui.appdata.xml index 66a15223a2c..4c8843957eb 100644 --- a/tools/lammps-gui/lammps-gui.appdata.xml +++ b/tools/lammps-gui/lammps-gui.appdata.xml @@ -54,6 +54,10 @@ + + + + Resolve plugin mode issues. From 70b8b987ca3d1640b352f6ce71eb78345020162e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 00:57:59 -0400 Subject: [PATCH 11/44] add noreturn attribute to templated version of error->one and error->all --- src/error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.h b/src/error.h index 89d168652a3..805bd4cd0db 100644 --- a/src/error.h +++ b/src/error.h @@ -29,14 +29,14 @@ class Error : protected Pointers { [[noreturn]] void all(const std::string &, int, const std::string &); template - void all(const std::string &file, int line, const std::string &format, Args &&...args) + [[noreturn]] void all(const std::string &file, int line, const std::string &format, Args &&...args) { _all(file, line, format, fmt::make_format_args(args...)); } [[noreturn]] void one(const std::string &, int, const std::string &); template - void one(const std::string &file, int line, const std::string &format, Args &&...args) + [[noreturn]] void one(const std::string &file, int line, const std::string &format, Args &&...args) { _one(file, line, format, fmt::make_format_args(args...)); } From abc621ddbd0f8f5449f7595c494d3d2d35ba038a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 04:33:31 -0400 Subject: [PATCH 12/44] Add GitHub workflow to check for variable length arrays --- .github/workflows/check-vla.yml | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/check-vla.yml diff --git a/.github/workflows/check-vla.yml b/.github/workflows/check-vla.yml new file mode 100644 index 00000000000..d79e145352c --- /dev/null +++ b/.github/workflows/check-vla.yml @@ -0,0 +1,82 @@ +# GitHub action to build LAMMPS on Linux with gcc and -Werror=vla +name: "Check for Variable Length Arrays" + +on: + push: + branches: + - develop + - collected-small-changes + pull_request: + branches: + - develop + + workflow_dispatch: + +jobs: + build: + name: Build with -Werror=vla + if: ${{ github.repository == 'lammps/lammps' }} || ${{ github.repository == 'akohlmey/lammps'}} + runs-on: ubuntu-latest + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Install extra packages + run: | + sudo apt-get install -y ccache mold ninja-build + sudo apt-get install -y libeigen3-dev libgsl-dev libcurl4-openssl-dev python3-dev + + - name: Create Build Environment + run: mkdir build + + - name: Set up ccache + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: linux-vla-ccache-${{ github.sha }} + restore-keys: linux-vla-ccache- + + - name: Building LAMMPS via CMake + shell: bash + run: | + ccache -z + python3 -m venv linuxenv + source linuxenv/bin/activate + python3 -m pip install numpy + python3 -m pip install pyyaml + cmake -S cmake -B build \ + -C cmake/presets/most.cmake \ + -D CMAKE_CXX_COMPILER=g++ \ + -D CMAKE_C_COMPILER=gcc \ + -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -D CMAKE_C_COMPILER_LAUNCHER=ccache \ + -D CMAKE_BUILD_TYPE=Debug \ + -D CMAKE_CXX_FLAGS_DEBUG="-Og -g -Werror=vla" \ + -D DOWNLOAD_POTENTIALS=off \ + -D BUILD_MPI=on \ + -D BUILD_TOOLS=off \ + -D ENABLE_TESTING=off \ + -D MLIAP_ENABLE_ACE=on \ + -D MLIAP_ENABLE_PYTHON=off \ + -D PKG_AWPMD=on \ + -D PKG_GPU=on \ + -D GPU_API=opencl \ + -D PKG_LATBOLTZ=on \ + -D PKG_MDI=on \ + -D PKG_MANIFOLD=on \ + -D PKG_ML-PACE=on \ + -D PKG_ML-RANN=off \ + -D PKG_MOLFILE=on \ + -D PKG_RHEO=on \ + -D PKG_PTM=on \ + -D PKG_PYTHON=on \ + -D PKG_QTB=on \ + -D PKG_SMTBQ=on \ + -G Ninja + cmake --build build + ccache -s From fb2c060d63881a5143fb500905cf30bdc225583e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 04:40:25 -0400 Subject: [PATCH 13/44] add unit test run on GitHub with -DLAMMPS_BIGBIG --- .github/workflows/unittest-linux.yml | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/unittest-linux.yml diff --git a/.github/workflows/unittest-linux.yml b/.github/workflows/unittest-linux.yml new file mode 100644 index 00000000000..ab5753b5308 --- /dev/null +++ b/.github/workflows/unittest-linux.yml @@ -0,0 +1,78 @@ +# GitHub action to build LAMMPS on Linux and run standard unit tests +name: "Unittest for Linux /w LAMMPS_BIGBIG" + +on: + push: + branches: + - develop + - collected-small-changes + pull_request: + branches: + - develop + + workflow_dispatch: + +jobs: + build: + name: Linux Unit Test + if: ${{ github.repository == 'lammps/lammps' }} || ${{ github.repository == 'akohlmey/lammps'}} + runs-on: ubuntu-latest + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Install extra packages + run: | + sudo apt-get install -y ccache mold ninja-build + sudo apt-get install -y libeigen3-dev libgsl-dev libcurl4-openssl-dev python3-dev + + - name: Create Build Environment + run: mkdir build + + - name: Set up ccache + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: linux-unit-ccache-${{ github.sha }} + restore-keys: linux-unit-ccache- + + - name: Building LAMMPS via CMake + shell: bash + run: | + ccache -z + python3 -m venv linuxenv + source linuxenv/bin/activate + python3 -m pip install numpy + python3 -m pip install pyyaml + cmake -S cmake -B build \ + -C cmake/presets/gcc.cmake \ + -C cmake/presets/most.cmake \ + -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -D CMAKE_C_COMPILER_LAUNCHER=ccache \ + -D BUILD_SHARED_LIBS=on \ + -D LAMMPS_SIZES=bigbig \ + -D DOWNLOAD_POTENTIALS=off \ + -D ENABLE_TESTING=on \ + -D MLIAP_ENABLE_ACE=on \ + -D MLIAP_ENABLE_PYTHON=off \ + -D PKG_MANIFOLD=on \ + -D PKG_ML-PACE=on \ + -D PKG_ML-RANN=on \ + -D PKG_RHEO=on \ + -D PKG_PTM=on \ + -D PKG_PYTHON=on \ + -D PKG_QTB=on \ + -D PKG_SMTBQ=on \ + -G Ninja + cmake --build build + ccache -s + + - name: Run Tests + working-directory: build + shell: bash + run: ctest -V From e5f8a4bec5c6dffaba07b946aa57f7d392bf71bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 04:47:03 -0400 Subject: [PATCH 14/44] must install mpi for compiling with mpi --- .github/workflows/check-vla.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-vla.yml b/.github/workflows/check-vla.yml index d79e145352c..5e702d3648c 100644 --- a/.github/workflows/check-vla.yml +++ b/.github/workflows/check-vla.yml @@ -28,8 +28,15 @@ jobs: - name: Install extra packages run: | - sudo apt-get install -y ccache mold ninja-build - sudo apt-get install -y libeigen3-dev libgsl-dev libcurl4-openssl-dev python3-dev + sudo apt-get install -y ccache \ + libeigen3-dev \ + libgsl-dev \ + libcurl4-openssl-dev \ + mold \ + mpi-default-bin \ + mpi-default-dev \ + ninja-build \ + python3-dev - name: Create Build Environment run: mkdir build From 6ebdb0b9827e1b0172e386d4dd099dbc3a85a6d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 04:53:09 -0400 Subject: [PATCH 15/44] some more tweaks to the workflows --- .github/workflows/check-vla.yml | 4 ++-- .github/workflows/unittest-linux.yml | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-vla.yml b/.github/workflows/check-vla.yml index 5e702d3648c..26f23cc33f0 100644 --- a/.github/workflows/check-vla.yml +++ b/.github/workflows/check-vla.yml @@ -5,7 +5,6 @@ on: push: branches: - develop - - collected-small-changes pull_request: branches: - develop @@ -15,7 +14,7 @@ on: jobs: build: name: Build with -Werror=vla - if: ${{ github.repository == 'lammps/lammps' }} || ${{ github.repository == 'akohlmey/lammps'}} + if: ${{ github.repository == 'lammps/lammps' }} runs-on: ubuntu-latest env: CCACHE_DIR: ${{ github.workspace }}/.ccache @@ -66,6 +65,7 @@ jobs: -D CMAKE_CXX_FLAGS_DEBUG="-Og -g -Werror=vla" \ -D DOWNLOAD_POTENTIALS=off \ -D BUILD_MPI=on \ + -D BUILD_SHARED_LIBS=off \ -D BUILD_TOOLS=off \ -D ENABLE_TESTING=off \ -D MLIAP_ENABLE_ACE=on \ diff --git a/.github/workflows/unittest-linux.yml b/.github/workflows/unittest-linux.yml index ab5753b5308..366db25a99d 100644 --- a/.github/workflows/unittest-linux.yml +++ b/.github/workflows/unittest-linux.yml @@ -5,7 +5,6 @@ on: push: branches: - develop - - collected-small-changes pull_request: branches: - develop @@ -15,7 +14,7 @@ on: jobs: build: name: Linux Unit Test - if: ${{ github.repository == 'lammps/lammps' }} || ${{ github.repository == 'akohlmey/lammps'}} + if: ${{ github.repository == 'lammps/lammps' }} runs-on: ubuntu-latest env: CCACHE_DIR: ${{ github.workspace }}/.ccache @@ -28,8 +27,13 @@ jobs: - name: Install extra packages run: | - sudo apt-get install -y ccache mold ninja-build - sudo apt-get install -y libeigen3-dev libgsl-dev libcurl4-openssl-dev python3-dev + sudo apt-get install -y ccache \ + libeigen3-dev \ + libgsl-dev \ + libcurl4-openssl-dev \ + mold \ + ninja-build \ + python3-dev - name: Create Build Environment run: mkdir build From 70a62d5ebfb8b9ba32eef1127c6d8124e8b93ac4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 06:20:44 -0400 Subject: [PATCH 16/44] make certain that the mass and mass_setflag arrays are fully initialized (to zero) --- src/atom.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/atom.cpp b/src/atom.cpp index 4a638652c74..f8a9bdd79bc 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1911,7 +1911,11 @@ void Atom::allocate_type_arrays() if (avec->mass_type == AtomVec::PER_TYPE) { mass = new double[ntypes+1]; mass_setflag = new int[ntypes+1]; - for (int itype = 1; itype <= ntypes; itype++) mass_setflag[itype] = 0; + // start loop from 0 to avoid uninitialized access when operating on the whole array + for (int itype = 0; itype <= ntypes; itype++) { + mass_setflag[itype] = 0; + mass[itype] = 0.0; + } } } From 7d176cb66ea4028be2ab8bc371da02fdadc5b664 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 07:01:44 -0400 Subject: [PATCH 17/44] fix logic bug --- src/atom.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index f8a9bdd79bc..e0fceffe9cc 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2752,11 +2752,12 @@ for an example where checking ghost communication is necessary. int Atom::find_custom_ghost(const char *name, int &flag, int &cols, int &ghost) { int i = find_custom(name, flag, cols); + ghost = 0; if (i == -1) return i; if ((flag == 0) && (cols == 0)) ghost = ivghost[i]; else if ((flag == 1) && (cols == 0)) ghost = dvghost[i]; - else if ((flag == 0) && (cols == 1)) ghost = iaghost[i]; - else if ((flag == 1) && (cols == 1)) ghost = daghost[i]; + else if ((flag == 0) && (cols > 0)) ghost = iaghost[i]; + else if ((flag == 1) && (cols > 0)) ghost = daghost[i]; return i; } From 2c05378815934988dfa09559b9af769678d0c36c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 07:03:14 -0400 Subject: [PATCH 18/44] expand python module unit tests for extract_atom() --- unittest/python/python-numpy.py | 96 ++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 14 deletions(-) diff --git a/unittest/python/python-numpy.py b/unittest/python/python-numpy.py index b7f1a4eedb1..4930527a611 100644 --- a/unittest/python/python-numpy.py +++ b/unittest/python/python-numpy.py @@ -160,31 +160,99 @@ def testExtractAtom(self): self.lmp.command("atom_style atomic") self.lmp.command("atom_modify map array") self.lmp.command("region box block 0 2 0 2 0 2") - self.lmp.command("create_box 1 box") + self.lmp.command("create_box 2 box") + + x = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 1.5, 1.0, 1.0 ] + types = [1, 2, 1] + ids = [1, 2, 3] + self.assertEqual(self.lmp.create_atoms(3, id=ids, type=types, x=x), 3) + self.lmp.command("mass * 2.0") + self.lmp.command("pair_style zero 1.1") + self.lmp.command("pair_coeff * *") + self.lmp.command("fix props all property/atom i_one i2_two 2 d_three d2_four 2"); + self.lmp.command("fix rmass all property/atom mol q rmass ghost yes"); + self.lmp.command("fix 1 all nve") + self.lmp.command("run 0 post no") + ntypes = self.lmp.extract_setting("ntypes"); + nlocal = self.lmp.extract_setting("nlocal"); + nall = self.lmp.extract_setting("nall"); + self.assertEqual(nlocal, 3) + self.assertEqual(ntypes, 2) + self.assertEqual(nall, 63) + + self.lmp.command("set atom 1 charge -1"); + self.lmp.command("set atom 2 charge 1"); + self.lmp.command("set atom 3 charge 0"); + self.lmp.command("set atom * mol 2"); + self.lmp.command("set atom 2 mol 1"); + self.lmp.command("set atom 1 i_one -3"); + self.lmp.command("set atom 2 i_one 3"); + self.lmp.command("set atom 2 d_three -1.3"); + self.lmp.command("set atom 3 d_three 3.5"); + self.lmp.command("set atom 1 i_two[1] -3"); + self.lmp.command("set atom 2 i_two[2] 3"); + self.lmp.command("set atom * d_four[1] -1.3"); + self.lmp.command("set atom * d_four[2] 3.5"); + self.lmp.command("run 0 post no") - x = [ - 1.0, 1.0, 1.0, - 1.0, 1.0, 1.5 - ] + mass = self.lmp.numpy.extract_atom("mass") + self.assertEqual(len(mass), ntypes + 1) + self.assertTrue((mass == (0.0, 2.0, 2.0)).all()) - types = [1, 1] + rmass = self.lmp.numpy.extract_atom("rmass") + self.assertEqual(len(rmass), nall) + self.assertTrue((rmass[0:3] == (0.0, 0.0, 0.0)).all()) - self.assertEqual(self.lmp.create_atoms(2, id=None, type=types, x=x), 2) - nlocal = self.lmp.extract_global("nlocal") - self.assertEqual(nlocal, 2) + charge = self.lmp.numpy.extract_atom("q") + self.assertEqual(len(charge), nall) + self.assertTrue((charge[0:3] == (-1.0, 1.0, 0.0)).all()) + + molecule = self.lmp.numpy.extract_atom("molecule") + self.assertEqual(len(molecule), nall) + self.assertTrue((molecule[0:3] == (2, 1, 2)).all()) ident = self.lmp.numpy.extract_atom("id") - self.assertEqual(len(ident), 2) + self.assertEqual(len(ident), nall) + self.assertTrue((ident[0:3] == (1, 2, 3)).all()) - ntypes = self.lmp.extract_global("ntypes") - self.assertEqual(ntypes, 1) + atype = self.lmp.numpy.extract_atom("type") + self.assertEqual(len(atype), nall) + self.assertTrue((atype[0:3] == (1, 2, 1)).all()) x = self.lmp.numpy.extract_atom("x") v = self.lmp.numpy.extract_atom("v") - self.assertEqual(len(x), 2) + self.assertEqual(len(x), nall) + self.assertEqual(len(x[0]), 3) self.assertTrue((x[0] == (1.0, 1.0, 1.0)).all()) self.assertTrue((x[1] == (1.0, 1.0, 1.5)).all()) - self.assertEqual(len(v), 2) + self.assertTrue((x[2] == (1.5, 1.0, 1.0)).all()) + self.assertEqual(len(v), nlocal) + self.assertEqual(len(v[0]), 3) + + self.lmp.command("comm_modify vel yes"); + self.lmp.command("run 0 post no") + + v = self.lmp.numpy.extract_atom("v") + self.assertEqual(len(v), nall) + + one = self.lmp.numpy.extract_atom("i_one") + two = self.lmp.numpy.extract_atom("i2_two") + three = self.lmp.numpy.extract_atom("d_three") + four = self.lmp.numpy.extract_atom("d2_four") + self.assertEqual(len(one), nlocal) + self.assertTrue((one == (-3, 3, 0)).all()) + self.assertEqual(len(two), nlocal) + self.assertEqual(len(two[0]), 2) + self.assertTrue((two[0] == (-3, 0)).all()) + self.assertTrue((two[1] == (0, 3)).all()) + self.assertTrue((two[2] == (0, 0)).all()) + self.assertEqual(len(three), nlocal) + self.assertTrue((three == (0.0, -1.3, 3.5)).all()) + self.assertEqual(len(four), nlocal) + self.assertEqual(len(four[0]), 2) + self.assertTrue((four[0] == (-1.3, 3.5)).all()) + self.assertTrue((four[1] == (-1.3, 3.5)).all()) + self.assertTrue((four[2] == (-1.3, 3.5)).all()) @unittest.skipIf(not has_full,"Gather bonds test") def testGatherBond_newton_on(self): From 84fa26ee2c29f66ede462de76c0e82e24db34e3c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 11:13:53 -0400 Subject: [PATCH 19/44] update test checking tool --- unittest/force-styles/check_tests.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py index 4dba8f9b9ea..7305168ecb6 100755 --- a/unittest/force-styles/check_tests.py +++ b/unittest/force-styles/check_tests.py @@ -88,10 +88,9 @@ def register_style(styles, name, info): style = m[1] if upper.match(style): continue - if style in ['reax/c', 'reax/c/omp', 'reax/c/kk', - 'reax/c/kk/device', 'reax/c/kk/host', - 'reax/c/species', 'reax/c/bonds', - 'reax/c/species/kk', 'reax/c/bonds/kk', 'meam/c']: + if style in ['lj/sdk', 'lj/sdk/coul/long', 'lj/sdk/coul/msm', 'sdk', 'lj/sdk/gpu', + 'lj/sdk/coul/long/gpu', 'lj/sdk/omp', 'lj/sdk/coul/long/omp', 'sdk/omp', + 'lj/sdk/coul/msm/omp', 'lj/sdk/kk', 'lj/sdk/coul/long/kk', 'sdk/kk']: continue # detect, process, and flag suffix styles: @@ -176,11 +175,12 @@ def check_tests(name,styles,yaml,search,skip=()): counter = 0 counter += check_tests('pair',pair,'*-pair-*.yaml', - '.*pair_style:\\s*((\\S+).*)?',skip=('meam','lj/sf')) + '.*pair_style:\\s*((\\S+).*)?', + skip=('lj/sf','lj/sdk', 'lj/sdk/coul/long', 'lj/sdk/coul/msm')) counter += check_tests('bond',bond,'bond-*.yaml', '.*bond_style:\\s*((\\S+).*)?') counter += check_tests('angle',angle,'angle-*.yaml', - '.*angle_style:\\s*((\\S+).*)?') + '.*angle_style:\\s*((\\S+).*)?', skip=('sdk')) counter += check_tests('dihedral',dihedral,'dihedral-*.yaml', '.*dihedral_style:\\s*((\\S+).*)?') counter += check_tests('improper',improper,'improper-*.yaml', From 6f114eddeae799f58a9a4b17263f7d0e5404806c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 30 Aug 2024 23:39:40 -0600 Subject: [PATCH 20/44] Fix typo in CMakeLists.txt --- cmake/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 723015c1f99..67b95c2ab89 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -474,13 +474,13 @@ if(BUILD_OMP) if(CMAKE_VERSION VERSION_LESS 3.28) get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME) if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC")) - set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE} -fopenmp") - set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE} -fopenmp") + set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp") + set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp") endif() else() if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang") - set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE} -fopenmp") - set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE} -fopenmp") + set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp") + set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp") endif() endif() endif() From 78597a9c39aad1da64bef79c5c26dc8dd86d9699 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 12:16:27 -0400 Subject: [PATCH 21/44] add fortran module tests for extracting atom properties with array dimensions --- fortran/lammps.f90 | 1 + unittest/fortran/keepstuff.f90 | 28 ++++++---- .../fortran/test_fortran_extract_atom.f90 | 54 ++++++++++++++++++- unittest/fortran/wrap_extract_atom.cpp | 25 ++++++++- 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index b7ce528b583..6ced71be497 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -1496,6 +1496,7 @@ FUNCTION lmp_extract_atom(self, name) RESULT(peratom_data) ! First, we dereference the void** pointer to point to the void* CALL C_F_POINTER(Cptr, Catomptr, [nrows]) ! Catomptr(1) now points to the first element of the array + ! rows and columns are swapped in Fortran CALL C_F_POINTER(Catomptr(1), peratom_data%r64_mat, [ncols,nrows]) CASE (-1) CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & diff --git a/unittest/fortran/keepstuff.f90 b/unittest/fortran/keepstuff.f90 index 63184e10060..c964c8a9c64 100644 --- a/unittest/fortran/keepstuff.f90 +++ b/unittest/fortran/keepstuff.f90 @@ -4,9 +4,9 @@ MODULE keepstuff TYPE(LAMMPS), SAVE :: lmp INTEGER, SAVE :: mycomm CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: demo_input = & - [ CHARACTER(LEN=40) :: & - 'region box block 0 $x 0 2 0 2', & - 'create_box 1 box', & + [ CHARACTER(LEN=40) :: & + 'region box block 0 $x 0 2 0 2', & + 'create_box 1 box', & 'create_atoms 1 single 1.0 1.0 ${zpos}' ] CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: big_input = & [ CHARACTER(LEN=40) :: & @@ -14,15 +14,26 @@ MODULE keepstuff 'create_box 1 box', & 'create_atoms 1 single 1.0 1.0 ${zpos}' ] CHARACTER(LEN=40), DIMENSION(2), PARAMETER :: cont_input = & - [ CHARACTER(LEN=40) :: & - 'create_atoms 1 single &', & + [ CHARACTER(LEN=40) :: & + 'create_atoms 1 single &', & ' 0.2 0.1 0.1' ] + CHARACTER(LEN=60), DIMENSION(18), PARAMETER :: prop_input = & + [ CHARACTER(LEN=60) :: 'fix 1 all nve', 'mass 1 3.0', & + 'fix 2 all property/atom mol q rmass ghost yes', & + 'fix 3 all property/atom i_one i2_two 2 d_three d2_four 2', & + 'set group all mass 2.0', 'set atom 1 charge -1', & + 'set atom 2 charge 1', 'set atom 1 mol 2', 'set atom 2 mol 1', & + 'set atom 1 i_one -3', 'set atom 2 i_one 3', & + 'set atom 1 d_three -1.3', 'set atom 2 d_three 3.5', & + 'set atom 1 i_two[1] -3', 'set atom 2 i_two[2] 3', & + 'set atom * d_four[1] -1.3', 'set atom * d_four[2] 3.5', & + 'run 0 post no' ] CHARACTER(LEN=40), DIMENSION(1), PARAMETER :: more_input = & [ CHARACTER(LEN=40) :: 'create_atoms 1 single 0.5 0.5 0.5' ] CHARACTER(LEN=40), DIMENSION(3), PARAMETER :: pair_input = & - [ CHARACTER(LEN=40) :: & - 'pair_style lj/cut 2.5', & - 'pair_coeff 1 1 1.0 1.0', & + [ CHARACTER(LEN=40) :: & + 'pair_style lj/cut 2.5', & + 'pair_coeff 1 1 1.0 1.0', & 'mass 1 2.0' ] INTERFACE @@ -63,4 +74,3 @@ END FUNCTION lammps_malloc END FUNCTION f2c_string END MODULE keepstuff - diff --git a/unittest/fortran/test_fortran_extract_atom.f90 b/unittest/fortran/test_fortran_extract_atom.f90 index 262e5de47d4..0c5a52ef253 100644 --- a/unittest/fortran/test_fortran_extract_atom.f90 +++ b/unittest/fortran/test_fortran_extract_atom.f90 @@ -24,12 +24,13 @@ END SUBROUTINE f_lammps_close SUBROUTINE f_lammps_setup_extract_atom() BIND(C) USE LIBLAMMPS - USE keepstuff, ONLY : lmp, big_input, cont_input, pair_input + USE keepstuff, ONLY : lmp, big_input, cont_input, pair_input, prop_input IMPLICIT NONE CALL lmp%commands_list(big_input) CALL lmp%commands_list(cont_input) CALL lmp%commands_list(pair_input) + CALL lmp%commands_list(prop_input) END SUBROUTINE f_lammps_setup_extract_atom FUNCTION f_lammps_extract_atom_mass() BIND(C) @@ -44,6 +45,19 @@ FUNCTION f_lammps_extract_atom_mass() BIND(C) f_lammps_extract_atom_mass = mass(1) END FUNCTION f_lammps_extract_atom_mass +FUNCTION f_lammps_extract_atom_mass_size() BIND(C) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int + USE LIBLAMMPS + USE keepstuff, ONLY : lmp + IMPLICIT NONE + INTEGER(c_int) :: f_lammps_extract_atom_mass_size, ntypes + REAL(c_double), DIMENSION(:), POINTER :: mass => NULL() + + ntypes = lmp%extract_setting('ntypes') + mass = lmp%extract_atom('mass') + f_lammps_extract_atom_mass_size = SIZE(mass) +END FUNCTION f_lammps_extract_atom_mass_size + FUNCTION f_lammps_extract_atom_tag_int(i) BIND(C) USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int USE LIBLAMMPS @@ -83,6 +97,18 @@ FUNCTION f_lammps_extract_atom_type(i) BIND(C) f_lammps_extract_atom_type = atype(i) END FUNCTION f_lammps_extract_atom_type +FUNCTION f_lammps_extract_atom_type_size() BIND(C) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_int + USE LIBLAMMPS + USE keepstuff, ONLY : lmp + IMPLICIT NONE + INTEGER(c_int) :: f_lammps_extract_atom_type_size + INTEGER(c_int), DIMENSION(:), POINTER :: atype => NULL() + + atype = lmp%extract_atom('type') + f_lammps_extract_atom_type_size = size(atype) +END FUNCTION f_lammps_extract_atom_type_size + FUNCTION f_lammps_extract_atom_mask(i) BIND(C) USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_int USE LIBLAMMPS @@ -109,6 +135,19 @@ SUBROUTINE f_lammps_extract_atom_x(i, x) BIND(C) x = xptr(:,i) END SUBROUTINE f_lammps_extract_atom_x +FUNCTION f_lammps_extract_atom_x_size(i) BIND(C) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int + USE LIBLAMMPS + USE keepstuff, ONLY : lmp + IMPLICIT NONE + INTEGER(c_int), INTENT(IN), VALUE :: i + INTEGER(c_int) :: f_lammps_extract_atom_x_size + REAL(c_double), DIMENSION(:,:), POINTER :: xptr => NULL() + + xptr = lmp%extract_atom('x') + f_lammps_extract_atom_x_size = SIZE(xptr, i) +END FUNCTION f_lammps_extract_atom_x_size + SUBROUTINE f_lammps_extract_atom_v(i, v) BIND(C) USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int USE LIBLAMMPS @@ -121,3 +160,16 @@ SUBROUTINE f_lammps_extract_atom_v(i, v) BIND(C) vptr = lmp%extract_atom('v') v = vptr(:,i) END SUBROUTINE f_lammps_extract_atom_v + +FUNCTION f_lammps_extract_atom_v_size(i) BIND(C) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_double, c_int + USE LIBLAMMPS + USE keepstuff, ONLY : lmp + IMPLICIT NONE + INTEGER(c_int), INTENT(IN), VALUE :: i + INTEGER(c_int) :: f_lammps_extract_atom_v_size + REAL(c_double), DIMENSION(:,:), POINTER :: xptr => NULL() + + xptr = lmp%extract_atom('v') + f_lammps_extract_atom_v_size = SIZE(xptr, i) +END FUNCTION f_lammps_extract_atom_v_size diff --git a/unittest/fortran/wrap_extract_atom.cpp b/unittest/fortran/wrap_extract_atom.cpp index 2552d6a10f3..9430959b2b8 100644 --- a/unittest/fortran/wrap_extract_atom.cpp +++ b/unittest/fortran/wrap_extract_atom.cpp @@ -1,6 +1,7 @@ // unit tests for extracting Atom class data from a LAMMPS instance through the // Fortran wrapper +#include "atom.h" #include "lammps.h" #include "library.h" #include @@ -16,12 +17,16 @@ void *f_lammps_with_args(); void f_lammps_close(); void f_lammps_setup_extract_atom(); double f_lammps_extract_atom_mass(); +int f_lammps_extract_atom_mass_size(); int f_lammps_extract_atom_tag_int(int); int64_t f_lammps_extract_atom_tag_int64(int64_t); int f_lammps_extract_atom_type(int); +int f_lammps_extract_atom_type_size(); int f_lammps_extract_atom_mask(int); void f_lammps_extract_atom_x(int, double *); +int f_lammps_extract_atom_x_size(int); void f_lammps_extract_atom_v(int, double *); +int f_lammps_extract_atom_v_size(int); } class LAMMPS_extract_atom : public ::testing::Test { @@ -50,7 +55,9 @@ class LAMMPS_extract_atom : public ::testing::Test { TEST_F(LAMMPS_extract_atom, mass) { f_lammps_setup_extract_atom(); - EXPECT_DOUBLE_EQ(f_lammps_extract_atom_mass(), 2.0); + int ntypes = lmp->atom->ntypes; + EXPECT_DOUBLE_EQ(f_lammps_extract_atom_mass(), 3.0); + EXPECT_EQ(f_lammps_extract_atom_mass_size(), ntypes + 1); }; TEST_F(LAMMPS_extract_atom, tag) @@ -68,8 +75,10 @@ TEST_F(LAMMPS_extract_atom, tag) TEST_F(LAMMPS_extract_atom, type) { f_lammps_setup_extract_atom(); + int nall = lmp->atom->nlocal + lmp->atom->nghost; EXPECT_EQ(f_lammps_extract_atom_type(1), 1); EXPECT_EQ(f_lammps_extract_atom_type(2), 1); + EXPECT_EQ(f_lammps_extract_atom_type_size(), nall); }; TEST_F(LAMMPS_extract_atom, mask) @@ -86,6 +95,7 @@ TEST_F(LAMMPS_extract_atom, mask) TEST_F(LAMMPS_extract_atom, x) { f_lammps_setup_extract_atom(); + int nall = lmp->atom->nlocal + lmp->atom->nghost; double x1[3]; double x2[3]; f_lammps_extract_atom_x(1, x1); @@ -96,11 +106,15 @@ TEST_F(LAMMPS_extract_atom, x) EXPECT_DOUBLE_EQ(x2[0], 0.2); EXPECT_DOUBLE_EQ(x2[1], 0.1); EXPECT_DOUBLE_EQ(x2[2], 0.1); + // in Fortran row and column are swapped + EXPECT_EQ(f_lammps_extract_atom_x_size(1), 3); + EXPECT_EQ(f_lammps_extract_atom_x_size(2), nall); } TEST_F(LAMMPS_extract_atom, v) { f_lammps_setup_extract_atom(); + int nall = lmp->atom->nlocal + lmp->atom->nghost; double v1[3]; double v2[3]; f_lammps_extract_atom_v(1, v1); @@ -117,4 +131,13 @@ TEST_F(LAMMPS_extract_atom, v) EXPECT_DOUBLE_EQ(v1[0], 1.0); EXPECT_DOUBLE_EQ(v1[1], 2.0); EXPECT_DOUBLE_EQ(v1[2], 3.0); + // in Fortran row and column are swapped! + EXPECT_EQ(f_lammps_extract_atom_v_size(1), 3); + EXPECT_EQ(f_lammps_extract_atom_v_size(2), lmp->atom->nlocal); + lammps_command(lmp, "comm_modify vel yes"); + lammps_command(lmp, "run 0 post no"); + EXPECT_EQ(f_lammps_extract_atom_v_size(1), 3); + EXPECT_EQ(f_lammps_extract_atom_v_size(2), nall); } + +// TODO: write tests for custom properties From 55a549a2fba8214184e341da9f035ad4cbc6031d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 12:43:50 -0400 Subject: [PATCH 22/44] try speed up windows compilation with ccache --- .github/workflows/compile-msvc.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 1a0f1ea62f4..94de700bb78 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -1,5 +1,5 @@ # GitHub action to build LAMMPS on Windows with Visual C++ -name: "Native Windows Compilation and Unit Tests" +name: "Windows Unit Tests" on: push: @@ -16,6 +16,8 @@ jobs: name: Windows Compilation Test if: ${{ github.repository == 'lammps/lammps' }} runs-on: windows-latest + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache steps: - name: Checkout repository @@ -23,6 +25,21 @@ jobs: with: fetch-depth: 2 + - name: Install Ccache + run: winget install Ccache.Ccache + + - name: Install MSMPI + run: | + nuget install MSMPIsdk + nuget install MSMPIDIST + + - name: Set up ccache + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: win-unit-ccache-${{ github.sha }} + restore-keys: win-unit-ccache- + - name: Select Python version uses: actions/setup-python@v5 with: @@ -31,20 +48,21 @@ jobs: - name: Building LAMMPS via CMake shell: bash run: | + ccache -z python3 -m pip install numpy python3 -m pip install pyyaml - nuget install MSMPIsdk - nuget install MSMPIDIST cmake -C cmake/presets/windows.cmake \ + -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -D CMAKE_C_COMPILER_LAUNCHER=ccache \ -D DOWNLOAD_POTENTIALS=off \ -D PKG_PYTHON=on \ -D WITH_PNG=off \ -D WITH_JPEG=off \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ - -D LAMMPS_EXCEPTIONS=on \ -D ENABLE_TESTING=on cmake --build build --config Release --parallel 2 + ccache -s - name: Run LAMMPS executable shell: bash From 0d7305672b101fed03b9d29bb6379fcec6b946c8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 12:48:09 -0400 Subject: [PATCH 23/44] use chocolatey instead of winget --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 94de700bb78..3ce8c1f25b9 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -26,7 +26,7 @@ jobs: fetch-depth: 2 - name: Install Ccache - run: winget install Ccache.Ccache + run: choco install ccache - name: Install MSMPI run: | From 72acea291afab90d82ef08c39fde25f74b98e1d9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 13:42:55 -0400 Subject: [PATCH 24/44] switch to ninja-build and single configuration setup --- .github/workflows/compile-msvc.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 3ce8c1f25b9..813579174ef 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -26,7 +26,9 @@ jobs: fetch-depth: 2 - name: Install Ccache - run: choco install ccache + run: | + choco install ccache + choco install ninja - name: Install MSMPI run: | @@ -52,25 +54,26 @@ jobs: python3 -m pip install numpy python3 -m pip install pyyaml cmake -C cmake/presets/windows.cmake \ - -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -D CMAKE_C_COMPILER_LAUNCHER=ccache \ + -D CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -D CMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ -D DOWNLOAD_POTENTIALS=off \ -D PKG_PYTHON=on \ -D WITH_PNG=off \ -D WITH_JPEG=off \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ - -D ENABLE_TESTING=on - cmake --build build --config Release --parallel 2 + -D ENABLE_TESTING=on \ + -G Ninja + cmake --build build ccache -s - name: Run LAMMPS executable shell: bash run: | - ./build/Release/lmp.exe -h - ./build/Release/lmp.exe -in bench/in.lj + ./build/lmp.exe -h + ./build/lmp.exe -in bench/in.lj - name: Run Unit Tests working-directory: build shell: bash - run: ctest -V -C Release -E FixTimestep:python_move_nve + run: ctest -V -E FixTimestep:python_move_nve From 2998d88edb6b4ee74cfdfed1708e93e0792a8e46 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 13:48:10 -0400 Subject: [PATCH 25/44] prefer MSVC++ over MinGW --- .github/workflows/compile-msvc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 813579174ef..6d77e694efc 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -54,6 +54,8 @@ jobs: python3 -m pip install numpy python3 -m pip install pyyaml cmake -C cmake/presets/windows.cmake \ + -D CMAKE_CXX_COMPILER=cl.exe \ + -D CMAKE_C_COMPILER=cl.exe \ -D CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -D CMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ -D DOWNLOAD_POTENTIALS=off \ From 6c40e8dc799482f5d7b80873278daf3bfe5c2886 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 13:57:54 -0400 Subject: [PATCH 26/44] revert back to MSBuild and report launcher, if active --- .github/workflows/compile-msvc.yml | 6 +----- cmake/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 6d77e694efc..3de6a46c7cd 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -28,7 +28,6 @@ jobs: - name: Install Ccache run: | choco install ccache - choco install ninja - name: Install MSMPI run: | @@ -54,8 +53,6 @@ jobs: python3 -m pip install numpy python3 -m pip install pyyaml cmake -C cmake/presets/windows.cmake \ - -D CMAKE_CXX_COMPILER=cl.exe \ - -D CMAKE_C_COMPILER=cl.exe \ -D CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -D CMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ -D DOWNLOAD_POTENTIALS=off \ @@ -64,8 +61,7 @@ jobs: -D WITH_JPEG=off \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ - -D ENABLE_TESTING=on \ - -G Ninja + -D ENABLE_TESTING=on cmake --build build ccache -s diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 67b95c2ab89..1c41191ec89 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -973,6 +973,9 @@ message(STATUS "<<< Compilers and Flags: >>> C++ Standard: ${CMAKE_CXX_STANDARD} C++ Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}} Defines: ${DEFINES}") +if(CMAKE_CXX_COMPILER_LAUNCHER) + message(STATUS, " Launcher: ${CMAKE_CXX_COMPILER_LAUNCHER}") +endif() get_target_property(OPTIONS lammps COMPILE_OPTIONS) if(OPTIONS) message(" Options: ${OPTIONS}") @@ -991,6 +994,9 @@ if(_index GREATER -1) Type: ${CMAKE_C_COMPILER_ID} Version: ${CMAKE_C_COMPILER_VERSION} C Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BTYPE}}") + if(CMAKE_C_COMPILER_LAUNCHER) + message(STATUS, " Launcher: ${CMAKE_C_COMPILER_LAUNCHER}") + endif() endif() message(STATUS "<<< Linker flags: >>>") message(STATUS "Executable name: ${LAMMPS_BINARY}") From 6d55da72078e744255a9f94cc45bed5df6327c2b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:00:51 -0400 Subject: [PATCH 27/44] bring back multi-config --- .github/workflows/compile-msvc.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 3de6a46c7cd..941dd11d0f7 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -62,16 +62,15 @@ jobs: -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ -D ENABLE_TESTING=on - cmake --build build - ccache -s + cmake --build build --config Release --parallel 2 - name: Run LAMMPS executable shell: bash run: | - ./build/lmp.exe -h - ./build/lmp.exe -in bench/in.lj + ./build/Release/lmp.exe -h + ./build/Release/lmp.exe -in bench/in.lj - name: Run Unit Tests working-directory: build shell: bash - run: ctest -V -E FixTimestep:python_move_nve + run: ctest -V -C Release -E FixTimestep:python_move_nve From 6e612f68c2a688e0f1844bba0620b463c0fb9f43 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:09:47 -0400 Subject: [PATCH 28/44] remove misplaced comma --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1c41191ec89..9c5ba9095a8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -974,7 +974,7 @@ message(STATUS "<<< Compilers and Flags: >>> C++ Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}} Defines: ${DEFINES}") if(CMAKE_CXX_COMPILER_LAUNCHER) - message(STATUS, " Launcher: ${CMAKE_CXX_COMPILER_LAUNCHER}") + message(STATUS " Launcher: ${CMAKE_CXX_COMPILER_LAUNCHER}") endif() get_target_property(OPTIONS lammps COMPILE_OPTIONS) if(OPTIONS) @@ -995,7 +995,7 @@ if(_index GREATER -1) Version: ${CMAKE_C_COMPILER_VERSION} C Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BTYPE}}") if(CMAKE_C_COMPILER_LAUNCHER) - message(STATUS, " Launcher: ${CMAKE_C_COMPILER_LAUNCHER}") + message(STATUS " Launcher: ${CMAKE_C_COMPILER_LAUNCHER}") endif() endif() message(STATUS "<<< Linker flags: >>>") From d85380476db063e21394c5e08fc46da5a91f4e48 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:38:12 -0400 Subject: [PATCH 29/44] alternate approach for using ninja with MSVC++ --- .github/workflows/compile-msvc.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 941dd11d0f7..e2d9a3628ad 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -22,12 +22,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + uses: ilammy/msvc-dev-cmd@v1 with: fetch-depth: 2 - name: Install Ccache run: | choco install ccache + choco install ninja - name: Install MSMPI run: | @@ -47,7 +49,6 @@ jobs: python-version: '3.11' - name: Building LAMMPS via CMake - shell: bash run: | ccache -z python3 -m pip install numpy @@ -61,16 +62,15 @@ jobs: -D WITH_JPEG=off \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ - -D ENABLE_TESTING=on - cmake --build build --config Release --parallel 2 + -D ENABLE_TESTING=on \ + -D Ninja + cmake --build build --parallel 2 - name: Run LAMMPS executable - shell: bash run: | - ./build/Release/lmp.exe -h - ./build/Release/lmp.exe -in bench/in.lj + ./build/lmp.exe -h + ./build/lmp.exe -in bench/in.lj - name: Run Unit Tests working-directory: build - shell: bash - run: ctest -V -C Release -E FixTimestep:python_move_nve + run: ctest -V -E FixTimestep:python_move_nve From 73fdd66f039767a6f4ecccb47345915dbe381393 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:40:31 -0400 Subject: [PATCH 30/44] correct syntax issue --- .github/workflows/compile-msvc.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index e2d9a3628ad..c33b632ee75 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -21,8 +21,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 - uses: ilammy/msvc-dev-cmd@v1 + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - uses: actions/checkout@v4 with: fetch-depth: 2 From 11172b1c6248bf93f80b557d91eb7062d1ac9e5d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:42:50 -0400 Subject: [PATCH 31/44] use different structure --- .github/workflows/compile-msvc.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index c33b632ee75..0a5fbb96854 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -21,13 +21,15 @@ jobs: steps: - name: Checkout repository - - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - uses: actions/checkout@v4 + uses: actions/checkout@v4 with: fetch-depth: 2 + - name: Enable MSVC++ + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - name: Install Ccache run: | choco install ccache From b890aee7de124d7f6a4595667fedbc45b7da704a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:55:01 -0400 Subject: [PATCH 32/44] update alternate action from GitHub marketplace --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 0a5fbb96854..1596ec09942 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -26,7 +26,7 @@ jobs: fetch-depth: 2 - name: Enable MSVC++ - uses: ilammy/msvc-dev-cmd@v1 + uses: TheMrMilchmann/setup-msvc-dev@v3 with: arch: x64 From 34bd2c4f2ad7e55951056eac49c297947e4fdf3d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 14:58:46 -0400 Subject: [PATCH 33/44] use our own fork --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 1596ec09942..a8b2398cc53 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -26,7 +26,7 @@ jobs: fetch-depth: 2 - name: Enable MSVC++ - uses: TheMrMilchmann/setup-msvc-dev@v3 + uses: lammps/setup-msvc-dev@v3 with: arch: x64 From 06bee65a1aee07254201e62170e31a4c1010dfe8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:10:11 -0400 Subject: [PATCH 34/44] use windows style pathnames --- .github/workflows/compile-msvc.yml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index a8b2398cc53..c5a40dec455 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -57,23 +57,13 @@ jobs: ccache -z python3 -m pip install numpy python3 -m pip install pyyaml - cmake -C cmake/presets/windows.cmake \ - -D CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ - -D CMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ - -D DOWNLOAD_POTENTIALS=off \ - -D PKG_PYTHON=on \ - -D WITH_PNG=off \ - -D WITH_JPEG=off \ - -S cmake -B build \ - -D BUILD_SHARED_LIBS=on \ - -D ENABLE_TESTING=on \ - -D Ninja + cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -G Ninja cmake --build build --parallel 2 - name: Run LAMMPS executable run: | - ./build/lmp.exe -h - ./build/lmp.exe -in bench/in.lj + build\lmp.exe -h + build\lmp.exe -in bench\in.lj - name: Run Unit Tests working-directory: build From b372aa0bdcf357dd2d93970d6c1d1a5bc897417d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:18:27 -0400 Subject: [PATCH 35/44] try to skip using Fortran --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index c5a40dec455..b2d07f084da 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -57,7 +57,7 @@ jobs: ccache -z python3 -m pip install numpy python3 -m pip install pyyaml - cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -G Ninja + cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_Fortran_COMPILER="" -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -G Ninja cmake --build build --parallel 2 - name: Run LAMMPS executable From 0b7ba6f8c15dd252abf1e96dbe8cc7ff5d55291c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:23:55 -0400 Subject: [PATCH 36/44] let ninja decide how many processes to launch --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index b2d07f084da..2cc4da1e9af 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -58,7 +58,7 @@ jobs: python3 -m pip install numpy python3 -m pip install pyyaml cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_Fortran_COMPILER="" -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -G Ninja - cmake --build build --parallel 2 + cmake --build build - name: Run LAMMPS executable run: | From 80230746508ea589c4765a840b2640aa15898c7b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:30:40 -0400 Subject: [PATCH 37/44] build release version --- .github/workflows/compile-msvc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 2cc4da1e9af..fb702b9d157 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -57,7 +57,7 @@ jobs: ccache -z python3 -m pip install numpy python3 -m pip install pyyaml - cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_Fortran_COMPILER="" -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -G Ninja + cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_Fortran_COMPILER="" -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -D CMAKE_BUILD_TYPE=Release -G Ninja cmake --build build - name: Run LAMMPS executable From debda721700d44d45e0b2eaf64a615c367e31940 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:51:52 -0400 Subject: [PATCH 38/44] print ccache statistics after compilation again --- .github/workflows/compile-msvc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index fb702b9d157..63b81325923 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -59,6 +59,7 @@ jobs: python3 -m pip install pyyaml cmake -C cmake\presets\windows.cmake -D CMAKE_CXX_COMPILER=cl -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER=cl -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_Fortran_COMPILER="" -D DOWNLOAD_POTENTIALS=off -D PKG_PYTHON=on -D WITH_PNG=off -D WITH_JPEG=off -S cmake -B build -D BUILD_SHARED_LIBS=on -D ENABLE_TESTING=on -D CMAKE_BUILD_TYPE=Release -G Ninja cmake --build build + ccache -s - name: Run LAMMPS executable run: | From 2e58e4c4284172e4a0e67e8354bc657b48073b71 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 31 Aug 2024 15:57:34 -0400 Subject: [PATCH 39/44] Simplify some more. don't install undetected MPI. --- .github/workflows/compile-msvc.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 63b81325923..e384f191e53 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -32,13 +32,7 @@ jobs: - name: Install Ccache run: | - choco install ccache - choco install ninja - - - name: Install MSMPI - run: | - nuget install MSMPIsdk - nuget install MSMPIDIST + choco install ccache ninja -y - name: Set up ccache uses: actions/cache@v4 From 93d11c376d0eccde167e304b0aa1971bd28b518d Mon Sep 17 00:00:00 2001 From: EiPi Fun Date: Sun, 1 Sep 2024 15:47:46 +0800 Subject: [PATCH 40/44] Fix small typo and errors, unifiy example inputs --- doc/src/pair_hbond_dreiding.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/src/pair_hbond_dreiding.rst b/doc/src/pair_hbond_dreiding.rst index 7e73f23b083..185da8b90ec 100644 --- a/doc/src/pair_hbond_dreiding.rst +++ b/doc/src/pair_hbond_dreiding.rst @@ -18,28 +18,27 @@ Syntax .. code-block:: LAMMPS - pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutof + pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff * style = *hbond/dreiding/lj* or *hbond/dreiding/morse* -* n = cosine angle periodicity +* N = power of angle cosine (integer) * inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) * outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) -* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor -* interactions (degrees) +* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) Examples """""""" .. code-block:: LAMMPS - pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/lj 4 9.0 11.0 90 + pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/lj 4 9.0 11.0 90.0 pair_coeff 1 2 hbond/dreiding/lj 3 i 9.5 2.75 4 9.0 11.0 90.0 - pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/morse 2 9.0 11.0 90 - pair_coeff 1 2 hbond/dreiding/morse 3 i 3.88 1.7241379 2.9 2 9 11 90 + pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/morse 2 9.0 11.0 90.0 + pair_coeff 1 2 hbond/dreiding/morse 3 i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 labelmap atom 1 C 2 O 3 H - pair_coeff C O hbond/dreiding/morse H i 3.88 1.7241379 2.9 2 9 11 90 + pair_coeff C O hbond/dreiding/morse H i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 Description """"""""""" @@ -65,7 +64,7 @@ force field, given by: where :math:`r_{\rm in}` is the inner spline distance cutoff, :math:`r_{\rm out}` is the outer distance cutoff, :math:`\theta_c` is -the angle cutoff, and *n* is the cosine periodicity. +the angle cutoff, and *n* is the power of angle cosine. Here, *r* is the radial distance between the donor (D) and acceptor (A) atoms and :math:`\theta` is the bond angle between the acceptor, the From a143e0a1830914236cfd2fdf28300e405eaa6b2e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 1 Sep 2024 08:15:26 -0400 Subject: [PATCH 41/44] small corrections --- doc/src/pair_hbond_dreiding.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/pair_hbond_dreiding.rst b/doc/src/pair_hbond_dreiding.rst index 185da8b90ec..ce19ff9e38f 100644 --- a/doc/src/pair_hbond_dreiding.rst +++ b/doc/src/pair_hbond_dreiding.rst @@ -21,7 +21,7 @@ Syntax pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff * style = *hbond/dreiding/lj* or *hbond/dreiding/morse* -* N = power of angle cosine (integer) +* N = power of cosine of angle theta (integer) * inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) * outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) * angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) @@ -64,7 +64,8 @@ force field, given by: where :math:`r_{\rm in}` is the inner spline distance cutoff, :math:`r_{\rm out}` is the outer distance cutoff, :math:`\theta_c` is -the angle cutoff, and *n* is the power of angle cosine. +the angle cutoff, and :math:`n` is the power of the cosine of the angle +:math:`\theta`. Here, *r* is the radial distance between the donor (D) and acceptor (A) atoms and :math:`\theta` is the bond angle between the acceptor, the @@ -216,7 +217,8 @@ These pair styles do not support the :doc:`pair_modify ` tail option for adding long-range tail corrections to energy and pressure. -These pair styles do not write their information to :doc:`binary restart files `, so pair_style and pair_coeff commands need to be +These pair styles do not write their information to :doc:`binary restart +files `, so pair_style and pair_coeff commands need to be re-specified in an input script that reads a restart file. These pair styles can only be used via the *pair* keyword of the From 1b5413189dd19961a74620a473ffa796ef355f0b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 1 Sep 2024 08:15:58 -0400 Subject: [PATCH 42/44] Add more details to documentation of GitHub CLI "gh" --- doc/src/Build_development.rst | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 9cd938280b4..f315569b247 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -630,11 +630,35 @@ The following target are available for both, GNU make and CMake: GitHub command line interface ----------------------------- -GitHub is developing a `tool for the command line -`_ that interacts with the GitHub website via a -command called ``gh``. This can be extremely convenient when working -with a Git repository hosted on GitHub (like LAMMPS). It is thus highly -recommended to install it when doing LAMMPS development. - -The capabilities of the ``gh`` command is continually expanding, so -please see the documentation at https://cli.github.com/manual/ +GitHub has developed a `command line tool `_ +to interact with the GitHub website via a command called ``gh``. +This is extremely convenient when working with a Git repository hosted +on GitHub (like LAMMPS). It is thus highly recommended to install it +when doing LAMMPS development. To use ``gh`` you must be within a git +checkout of a repository and you must obtain an authentication token +to connect your checkout with a GitHub user. This is done with the +command: ``gh auth login`` where you then have to follow the prompts. +Here are some examples: + +.. list-table:: + :header-rows: 1 + :widths: 34 66 + + * - Command + - Description + * - ``gh pr list`` + - List currently open pull requests + * - ``gh pr checks 404`` + - Shows the status of all checks for pull request #404 + * - ``gh pr view 404`` + - Shows the description and recent comments for pull request #404 + * - ``gh co 404`` + - Check out the branch from pull request #404; set up for pushing changes + * - ``gh issue list`` + - List currently open issues + * - ``gh issue view 430 --comments`` + - Shows the description and all comments for issue #430 + +The capabilities of the ``gh`` command are continually expanding, so +for more details please see the documentation at https://cli.github.com/manual/ +or use ``gh --help`` or ``gh --help`` for embedded help. From 7c80b00f2389350686ab699fdadff3161f741f52 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 06:26:27 -0400 Subject: [PATCH 43/44] small corrections in the DIFFRACTION package, mostly cosmetic --- src/DIFFRACTION/compute_saed.cpp | 12 ++++++------ src/DIFFRACTION/compute_xrd.cpp | 12 ++++++------ src/DIFFRACTION/fix_saed_vtk.cpp | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/DIFFRACTION/compute_saed.cpp b/src/DIFFRACTION/compute_saed.cpp index 1350257910c..e2a7bb33d95 100644 --- a/src/DIFFRACTION/compute_saed.cpp +++ b/src/DIFFRACTION/compute_saed.cpp @@ -401,7 +401,7 @@ void ComputeSAED::compute_vector() // Setting up OMP #if defined(_OPENMP) - if (me == 0 && echo) utils::logmesg(lmp," using {}OMP threads\n",comm->nthreads); + if (me == 0 && echo) utils::logmesg(lmp," using {} OMP thread(s)\n",comm->nthreads); #endif if (me == 0 && echo) utils::logmesg(lmp,"\n"); @@ -478,7 +478,7 @@ void ComputeSAED::compute_vector() } } } // End of pragma omp for region - delete [] f; + delete[] f; } auto scratch = new double[2*nRows]; @@ -499,10 +499,10 @@ void ComputeSAED::compute_vector() utils::logmesg(lmp," 100% \nTime elapsed during compute_saed = {:.2f} sec " "using {:.2f} Mbytes/processor\n-----\n", t2-t0, bytes/1024.0/1024.0); - delete [] xlocal; - delete [] typelocal; - delete [] scratch; - delete [] Fvec; + delete[] xlocal; + delete[] typelocal; + delete[] scratch; + delete[] Fvec; } /* ---------------------------------------------------------------------- diff --git a/src/DIFFRACTION/compute_xrd.cpp b/src/DIFFRACTION/compute_xrd.cpp index 11e0bb9a9ff..a769be7d4f1 100644 --- a/src/DIFFRACTION/compute_xrd.cpp +++ b/src/DIFFRACTION/compute_xrd.cpp @@ -332,7 +332,7 @@ void ComputeXRD::compute_array() // Setting up OMP #if defined(_OPENMP) - if ((me == 0) && echo) utils::logmesg(lmp," using {} OMP threads\n",comm->nthreads); + if ((me == 0) && echo) utils::logmesg(lmp," using {} OMP thread(s)\n",comm->nthreads); #endif if ((me == 0) && echo) { @@ -482,7 +482,7 @@ void ComputeXRD::compute_array() } } // End of pragma omp for region } // End of if LP=1 check - delete [] f; + delete[] f; } // End of pragma omp parallel region auto scratch = new double[2*size_array_rows]; @@ -503,10 +503,10 @@ void ComputeXRD::compute_array() utils::logmesg(lmp," 100% \nTime elapsed during compute_xrd = {:.2f} sec " "using {:.2f} Mbytes/processor\n-----\n", t2-t0, bytes/1024.0/1024.0); - delete [] scratch; - delete [] Fvec; - delete [] xlocal; - delete [] typelocal; + delete[] scratch; + delete[] Fvec; + delete[] xlocal; + delete[] typelocal; } /* ---------------------------------------------------------------------- diff --git a/src/DIFFRACTION/fix_saed_vtk.cpp b/src/DIFFRACTION/fix_saed_vtk.cpp index b3f6693e9e5..693bb925b6f 100644 --- a/src/DIFFRACTION/fix_saed_vtk.cpp +++ b/src/DIFFRACTION/fix_saed_vtk.cpp @@ -114,6 +114,7 @@ FixSAEDVTK::FixSAEDVTK(LAMMPS *lmp, int narg, char **arg) : memory->create(vector_total,nrows,"saed/vtk:vector_total"); vector_flag = 1; + extvector = 0; size_vector = nrows; if (nOutput == 0) { @@ -248,8 +249,8 @@ FixSAEDVTK::FixSAEDVTK(LAMMPS *lmp, int narg, char **arg) : FixSAEDVTK::~FixSAEDVTK() { - delete [] filename; - delete [] ids; + delete[] filename; + delete[] ids; memory->destroy(vector); memory->destroy(vector_total); if (fp && comm->me == 0) fclose(fp); From 731847b4dccddc6fa22a31839e60155a294626e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 21:21:14 -0400 Subject: [PATCH 44/44] report proper style name in error messages --- src/MOLECULE/pair_hbond_dreiding_lj.cpp | 10 +++++----- src/MOLECULE/pair_hbond_dreiding_morse.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index 274f8bc2a3a..4536cc8e05c 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -396,14 +396,14 @@ void PairHbondDreidingLJ::init_style() // and computing forces on A,H which may be on different procs if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + error->all(FLERR,"Pair style hbond/dreiding/lj requires molecular system"); if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + error->all(FLERR,"Pair style hbond/dreiding/lj requires atom IDs"); if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + error->all(FLERR,"Pair style hbond/dreiding/lj requires an atom map, " "see atom_modify"); if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + error->all(FLERR,"Pair style hbond/dreiding/lj requires newton pair on"); // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor @@ -419,7 +419,7 @@ void PairHbondDreidingLJ::init_style() acceptor[j] = 1; } - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/lj coefficients set"); // set additional param values // offset is for LJ only, angle term is not included diff --git a/src/MOLECULE/pair_hbond_dreiding_morse.cpp b/src/MOLECULE/pair_hbond_dreiding_morse.cpp index c8bc0a627d1..d976b66460c 100644 --- a/src/MOLECULE/pair_hbond_dreiding_morse.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_morse.cpp @@ -323,14 +323,14 @@ void PairHbondDreidingMorse::init_style() // and computing forces on A,H which may be on different procs if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + error->all(FLERR,"Pair style hbond/dreiding/morse requires molecular system"); if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + error->all(FLERR,"Pair style hbond/dreiding/morse requires atom IDs"); if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + error->all(FLERR,"Pair style hbond/dreiding/morse requires an atom map, " "see atom_modify"); if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + error->all(FLERR,"Pair style hbond/dreiding/morse requires newton pair on"); // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor @@ -346,7 +346,7 @@ void PairHbondDreidingMorse::init_style() acceptor[j] = 1; } - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/morse coefficients set"); // set additional param values // offset is for Morse only, angle term is not included