From 1312a76dec2413ac9cc7643c3bd3e57ad8058cd1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 15:32:19 -0500 Subject: [PATCH 01/16] eliminate use of strtok() by using ValueTokenizer class --- src/MLIAP/mliap_model.cpp | 43 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/MLIAP/mliap_model.cpp b/src/MLIAP/mliap_model.cpp index aa198e6085..882f64263f 100644 --- a/src/MLIAP/mliap_model.cpp +++ b/src/MLIAP/mliap_model.cpp @@ -20,6 +20,7 @@ #include "comm.h" #include "error.h" #include "memory.h" +#include "tokenizer.h" #include @@ -30,7 +31,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -MLIAPModel::MLIAPModel(LAMMPS* lmp, char* coefffilename) : Pointers(lmp) +MLIAPModel::MLIAPModel(LAMMPS *lmp, char *) : Pointers(lmp) { nparams = 0; nelements = 0; @@ -44,7 +45,6 @@ MLIAPModel::~MLIAPModel() { } - /* ---------------------------------------------------------------------- placeholder ------------------------------------------------------------------------- */ @@ -74,7 +74,7 @@ void MLIAPModel::set_ndescriptors(int ndescriptors_in) /* ---------------------------------------------------------------------- */ -MLIAPModelSimple::MLIAPModelSimple(LAMMPS* lmp, char* coefffilename) : MLIAPModel(lmp, coefffilename) +MLIAPModelSimple::MLIAPModelSimple(LAMMPS *lmp, char *coefffilename) : MLIAPModel(lmp, coefffilename) { coeffelem = nullptr; if (coefffilename) read_coeffs(coefffilename); @@ -87,6 +87,7 @@ MLIAPModelSimple::~MLIAPModelSimple() memory->destroy(coeffelem); } +/* ---------------------------------------------------------------------- */ void MLIAPModelSimple::read_coeffs(char *coefffilename) { @@ -130,14 +131,14 @@ void MLIAPModelSimple::read_coeffs(char *coefffilename) // words = ptrs to all words in line // strip single and double quotes from words - char* words[MAXWORD]; - int iword = 0; - words[iword] = strtok(line,"' \t\n\r\f"); - iword = 1; - words[iword] = strtok(nullptr,"' \t\n\r\f"); - - nelements = atoi(words[0]); - nparams = atoi(words[1]); + try { + ValueTokenizer coeffs(line); + nelements = coeffs.next_int(); + nparams = coeffs.next_int(); + } catch (TokenizerException &e) { + error->all(FLERR,fmt::format("Incorrect format in MLIAPModel coefficient " + "file: {}",e.what())); + } // set up coeff lists @@ -157,19 +158,19 @@ void MLIAPModelSimple::read_coeffs(char *coefffilename) MPI_Bcast(&eof,1,MPI_INT,0,world); if (eof) - error->all(FLERR,"Incorrect format in coefficient file"); + error->all(FLERR,"Incorrect format in MLIAPModel coefficient file"); MPI_Bcast(&n,1,MPI_INT,0,world); MPI_Bcast(line,n,MPI_CHAR,0,world); - nwords = utils::trim_and_count_words(line); - if (nwords != 1) - error->all(FLERR,"Incorrect format in coefficient file"); - - iword = 0; - words[iword] = strtok(line,"' \t\n\r\f"); - - coeffelem[ielem][icoeff] = atof(words[0]); - + try { + ValueTokenizer coeffs(utils::trim_comment(line)); + if (coeffs.count() != 1) + throw TokenizerException("Wrong number of items",""); + coeffelem[ielem][icoeff] = coeffs.next_double(); + } catch (TokenizerException &e) { + error->all(FLERR,fmt::format("Incorrect format in MLIAPModel " + "coefficient file: {}",e.what())); + } } } From 461364c0060b7f00b48b17d486a54e629450b7ed Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 15:50:26 -0500 Subject: [PATCH 02/16] silence compiler warnings --- src/MLIAP/mliap_model_python.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MLIAP/mliap_model_python.cpp b/src/MLIAP/mliap_model_python.cpp index 823cee711f..4dda7df357 100644 --- a/src/MLIAP/mliap_model_python.cpp +++ b/src/MLIAP/mliap_model_python.cpp @@ -87,7 +87,7 @@ int MLIAPModelPython::get_nparams() return nparams; } -void MLIAPModelPython::read_coeffs(char * fname) +void MLIAPModelPython::read_coeffs(char *fname) { PyGILState_STATE gstate = PyGILState_Ensure(); @@ -134,7 +134,7 @@ void MLIAPModelPython::connect_param_counts() for each atom beta_i = dE(B_i)/dB_i ---------------------------------------------------------------------- */ -void MLIAPModelPython::compute_gradients(MLIAPData* data) +void MLIAPModelPython::compute_gradients(MLIAPData *data) { if (not model_loaded) { error->all(FLERR,"Model not loaded."); @@ -167,7 +167,7 @@ void MLIAPModelPython::compute_gradients(MLIAPData* data) egradient is derivative of energy w.r.t. parameters ---------------------------------------------------------------------- */ -void MLIAPModelPython::compute_gradgrads(class MLIAPData* data) +void MLIAPModelPython::compute_gradgrads(class MLIAPData *) { error->all(FLERR,"compute_gradgrads not implemented"); } @@ -177,7 +177,7 @@ void MLIAPModelPython::compute_gradgrads(class MLIAPData* data) egradient is derivative of energy w.r.t. parameters ---------------------------------------------------------------------- */ -void MLIAPModelPython::compute_force_gradients(class MLIAPData* data) +void MLIAPModelPython::compute_force_gradients(class MLIAPData *) { error->all(FLERR,"compute_force_gradients not implemented"); } @@ -186,7 +186,7 @@ void MLIAPModelPython::compute_force_gradients(class MLIAPData* data) count the number of non-zero entries in gamma matrix ---------------------------------------------------------------------- */ -int MLIAPModelPython::get_gamma_nnz(class MLIAPData* data) +int MLIAPModelPython::get_gamma_nnz(class MLIAPData *) { // todo: get_gamma_nnz return 0; From a23e45cc0c5f01ac0a051cb2e884b56af8e61923 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 15:50:33 -0500 Subject: [PATCH 03/16] remove dead code --- src/SPIN/pair_spin_exchange_biquadratic.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/SPIN/pair_spin_exchange_biquadratic.cpp b/src/SPIN/pair_spin_exchange_biquadratic.cpp index f2baf1333b..352949e5c3 100644 --- a/src/SPIN/pair_spin_exchange_biquadratic.cpp +++ b/src/SPIN/pair_spin_exchange_biquadratic.cpp @@ -474,7 +474,7 @@ double PairSpinExchangeBiquadratic::compute_energy(int i, int j, double rsq, int *type = atom->type; int itype,jtype; double Jex,Kex,ra,sdots; - double rj,rk,r2j,r2k,ir3j,ir3k; + double rj,rk,r2j,r2k; double energy = 0.0; itype = type[i]; jtype = type[j]; @@ -482,10 +482,8 @@ double PairSpinExchangeBiquadratic::compute_energy(int i, int j, double rsq, ra = sqrt(rsq); rj = ra/J3[itype][jtype]; r2j = rsq/J3[itype][jtype]/J3[itype][jtype]; - ir3j = 1.0/(rj*rj*rj); rk = ra/K3[itype][jtype]; r2k = rsq/K3[itype][jtype]/K3[itype][jtype]; - ir3k = 1.0/(rk*rk*rk); Jex = 4.0*J1_mech[itype][jtype]*r2j; Jex *= (1.0-J2[itype][jtype]*r2j); From 48fa5e6736827c7df7f3dd5398110015af38a6ba Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 15:59:52 -0500 Subject: [PATCH 04/16] fix argument bug --- src/KOKKOS/atom_vec_dpd_kokkos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index 8c1668a411..ad47b6f108 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -784,7 +784,7 @@ struct AtomVecDPDKokkos_PackBorder { _uCond(uCond), _uMech(uMech), _uChem(uChem), - _uCG(uCGnew), + _uCG(uCG), _uCGnew(uCGnew), _dx(dx),_dy(dy),_dz(dz) {} From 72b022c5fab61333ee157635a0ffdefba94ead95 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 16:14:06 -0500 Subject: [PATCH 05/16] make implicit copy contructor explicit and thus silence compiler warnings --- src/USER-REAXC/reaxc_types.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/USER-REAXC/reaxc_types.h b/src/USER-REAXC/reaxc_types.h index f038f00bb0..36678ad2b0 100644 --- a/src/USER-REAXC/reaxc_types.h +++ b/src/USER-REAXC/reaxc_types.h @@ -862,14 +862,23 @@ struct cubic_spline_coef cubic_spline_coef() {} LAMMPS_INLINE - void operator = (const cubic_spline_coef& rhs) { + cubic_spline_coef(const cubic_spline_coef &_c) { + a = _c.a; + b = _c.b; + c = _c.c; + d = _c.d; + } + + LAMMPS_INLINE + void operator=(const cubic_spline_coef &rhs) { a = rhs.a; b = rhs.b; c = rhs.c; d = rhs.d; } + LAMMPS_INLINE - void operator = (const cubic_spline_coef& rhs) volatile { + void operator=(const cubic_spline_coef &rhs) volatile { a = rhs.a; b = rhs.b; c = rhs.c; From 95b445a25ae21fd1c77646a888011387c89869a1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 18:38:33 -0500 Subject: [PATCH 06/16] must initialized has_exceptions to avoid false positives in unit tests --- unittest/python/python-open.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/python/python-open.py b/unittest/python/python-open.py index 6153e032e3..67500ea6fa 100644 --- a/unittest/python/python-open.py +++ b/unittest/python/python-open.py @@ -4,6 +4,7 @@ from lammps import lammps has_mpi=False has_mpi4py=False +has_exceptions=False try: from mpi4py import __version__ as mpi4py_version # tested to work with mpi4py versions 2 and 3 From 0e2b5283512039804461c7ab08f557891c14dc5b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 18:40:24 -0500 Subject: [PATCH 07/16] add additional heuristics to prevent python unit tests from failing on MacOS --- python/lammps/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index fe23fa587c..6c1300ccf2 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -99,6 +99,7 @@ class lammps(object): # so that LD_LIBRARY_PATH does not need to be set for regular install # fall back to loading with a relative path, # typically requires LD_LIBRARY_PATH to be set appropriately + # guess shared library extension based on OS, if not inferred from actual file if any([f.startswith('liblammps') and f.endswith('.dylib') for f in os.listdir(modpath)]): @@ -111,7 +112,13 @@ class lammps(object): lib_ext = ".dll" modpath = winpath else: - lib_ext = ".so" + import platform + if platform.system() == "Darwin": + lib_ext = ".dylib" + elif platform.system() == "Windows": + lib_ext = ".dll" + else: + lib_ext = ".so" if not self.lib: try: From 065c4939ed405cfb888a50c35731533ae8f71336 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 29 Jan 2021 18:48:05 -0500 Subject: [PATCH 08/16] relax some unit test epsilons, so the tests pass on MacOS --- unittest/force-styles/tests/angle-quartic.yaml | 2 +- unittest/force-styles/tests/atomic-pair-reax_c_lgvdw.yaml | 2 +- unittest/force-styles/tests/fix-timestep-momentum.yaml | 2 +- unittest/force-styles/tests/fix-timestep-temp_csvr.yaml | 2 +- unittest/force-styles/tests/mol-pair-tip4p_table.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/unittest/force-styles/tests/angle-quartic.yaml b/unittest/force-styles/tests/angle-quartic.yaml index 1ffa163732..912825d3a2 100644 --- a/unittest/force-styles/tests/angle-quartic.yaml +++ b/unittest/force-styles/tests/angle-quartic.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:35 202 -epsilon: 2.5e-13 +epsilon: 4e-13 prerequisites: ! | atom full angle quartic diff --git a/unittest/force-styles/tests/atomic-pair-reax_c_lgvdw.yaml b/unittest/force-styles/tests/atomic-pair-reax_c_lgvdw.yaml index 90bfd15f3d..db4bb284fa 100644 --- a/unittest/force-styles/tests/atomic-pair-reax_c_lgvdw.yaml +++ b/unittest/force-styles/tests/atomic-pair-reax_c_lgvdw.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:25 202 -epsilon: 1e-10 +epsilon: 2e-10 prerequisites: ! | pair reax/c fix qeq/reax diff --git a/unittest/force-styles/tests/fix-timestep-momentum.yaml b/unittest/force-styles/tests/fix-timestep-momentum.yaml index 884c71785d..96a3e9d4bb 100644 --- a/unittest/force-styles/tests/fix-timestep-momentum.yaml +++ b/unittest/force-styles/tests/fix-timestep-momentum.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:40 202 -epsilon: 4e-14 +epsilon: 5e-14 prerequisites: ! | atom full fix momentum diff --git a/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml b/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml index d4f77f596c..8716de39de 100644 --- a/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml +++ b/unittest/force-styles/tests/fix-timestep-temp_csvr.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:43 202 -epsilon: 2e-14 +epsilon: 3e-14 prerequisites: ! | atom full fix temp/csvr diff --git a/unittest/force-styles/tests/mol-pair-tip4p_table.yaml b/unittest/force-styles/tests/mol-pair-tip4p_table.yaml index 9a1f5fccec..26e60777d2 100644 --- a/unittest/force-styles/tests/mol-pair-tip4p_table.yaml +++ b/unittest/force-styles/tests/mol-pair-tip4p_table.yaml @@ -1,7 +1,7 @@ --- lammps_version: 24 Aug 2020 date_generated: Tue Sep 15 09:44:20 202 -epsilon: 1e-13 +epsilon: 2.5e-13 prerequisites: ! | atom full pair tip4p/long From 4747e0496a55f116e97274b77cc2bab7e246f8dd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 30 Jan 2021 02:22:49 -0500 Subject: [PATCH 09/16] add a bunch of unicode space equivalents --- src/utils.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/utils.cpp b/src/utils.cpp index 80800397d3..44dcc16f0c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -588,6 +588,9 @@ std::string utils::utf8_subst(const std::string &line) // UTF-8 2-byte character if ((in[i] & 0xe0U) == 0xc0U) { if ((i+1) < len) { + // NON-BREAKING SPACE (U+00A0) + if ((in[i] == 0xc2U) && (in[i+1] == 0xa0U)) + out += ' ', ++i; // MODIFIER LETTER PLUS SIGN (U+02D6) if ((in[i] == 0xcbU) && (in[i+1] == 0x96U)) out += '+', ++i; @@ -598,6 +601,48 @@ std::string utils::utf8_subst(const std::string &line) // UTF-8 3-byte character } else if ((in[i] & 0xf0U) == 0xe0U) { if ((i+2) < len) { + // EN QUAD (U+2000) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x80U)) + out += ' ', i += 2; + // EM QUAD (U+2001) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x81U)) + out += ' ', i += 2; + // EN SPACE (U+2002) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x82U)) + out += ' ', i += 2; + // EM SPACE (U+2003) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x83U)) + out += ' ', i += 2; + // THREE-PER-EM SPACE (U+2004) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x84U)) + out += ' ', i += 2; + // FOUR-PER-EM SPACE (U+2005) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x85U)) + out += ' ', i += 2; + // SIX-PER-EM SPACE (U+2006) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x86U)) + out += ' ', i += 2; + // FIGURE SPACE (U+2007) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x87U)) + out += ' ', i += 2; + // PUNCTUATION SPACE (U+2008) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x88U)) + out += ' ', i += 2; + // THIN SPACE (U+2009) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x89U)) + out += ' ', i += 2; + // HAIR SPACE (U+200A) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x8aU)) + out += ' ', i += 2; + // ZERO WIDTH SPACE (U+200B) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0x8bU)) + out += ' ', i += 2; + // NARROW NO-BREAK SPACE (U+202F) + if ((in[i] == 0xe2U) && (in[i+1] == 0x80U) && (in[i+2] == 0xafU)) + out += ' ', i += 2; + // WORD JOINER (U+2060) + if ((in[i] == 0xe2U) && (in[i+1] == 0x81U) && (in[i+2] == 0xa0U)) + out += ' ', i += 2; // INVISIBLE SEPARATOR (U+2063) if ((in[i] == 0xe2U) && (in[i+1] == 0x81U) && (in[i+2] == 0xa3U)) out += ' ', i += 2; @@ -607,6 +652,9 @@ std::string utils::utf8_subst(const std::string &line) // MINUS SIGN (U+2212) if ((in[i] == 0xe2U) && (in[i+1] == 0x88U) && (in[i+2] == 0x92U)) out += '-', i += 2; + // ZERO WIDTH NO-BREAK SPACE (U+FEFF) + if ((in[i] == 0xefU) && (in[i+1] == 0xbbU) && (in[i+2] == 0xbfU)) + out += ' ', i += 2; } // UTF-8 4-byte character } else if ((in[i] & 0xe8U) == 0xf0U) { From 3ce92db405cf31f5ebaaf4c7b37fd7639b0156e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 30 Jan 2021 06:08:17 -0500 Subject: [PATCH 10/16] correct path to CMake preset folder in example command --- doc/src/Python_install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index c12644bf4a..dce19ce2c0 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -69,7 +69,7 @@ this. cd build # configure LAMMPS compilation - cmake -C cmake/presets/minimal.cmake -D BUILD_SHARED_LIBS=on \ + cmake -C ../cmake/presets/minimal.cmake -D BUILD_SHARED_LIBS=on \ -D LAMMPS_EXCEPTIONS=on -D PKG_PYTHON=on ../cmake # compile LAMMPS From aeaaeed70385dbabeb96e00a947c517e5c10c4b8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 30 Jan 2021 06:08:35 -0500 Subject: [PATCH 11/16] clarify and fix typo --- doc/src/Python_install.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index dce19ce2c0..8d7f9ee83e 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -97,10 +97,11 @@ this. For a system-wide installation you need to set ``CMAKE_INSTALL_PREFIX`` to a system folder like ``/usr`` (or - ``/usr/local``). The installation step (**not** the - configuration/compilation) needs to be done with superuser + ``/usr/local``); the default is ``${HOME}/.local``. + The installation step for a system folder installation + (**not** the configuration/compilation) needs to be done with superuser privilege, e.g. by using ``sudo cmake --install .``. The - installation folders will then by changed to: + installation folders will then be changed to (for ``/usr`` as prefix): +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ | File | Location | Notes | From f0e4f906082898120aed33a37072f699fd33e91e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 31 Jan 2021 13:06:10 -0500 Subject: [PATCH 12/16] reformat paragraph --- doc/src/Python_install.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index 8d7f9ee83e..134d3e22d2 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -97,11 +97,12 @@ this. For a system-wide installation you need to set ``CMAKE_INSTALL_PREFIX`` to a system folder like ``/usr`` (or - ``/usr/local``); the default is ``${HOME}/.local``. - The installation step for a system folder installation - (**not** the configuration/compilation) needs to be done with superuser + ``/usr/local``); the default is ``${HOME}/.local``. The + installation step for a system folder installation (**not** the + configuration/compilation) needs to be done with superuser privilege, e.g. by using ``sudo cmake --install .``. The - installation folders will then be changed to (for ``/usr`` as prefix): + installation folders will then be changed to (assuming ``/usr`` as + prefix): +------------------------+---------------------------------------------------------+-------------------------------------------------------------+ | File | Location | Notes | From 829e5a7f85db840358851cc7729d72b08791f85f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 31 Jan 2021 21:06:35 -0500 Subject: [PATCH 13/16] update docs about the organization of sources and relation between classes --- doc/src/Developer_org.rst | 193 ++++++++++++++++++++------------------ 1 file changed, 104 insertions(+), 89 deletions(-) diff --git a/doc/src/Developer_org.rst b/doc/src/Developer_org.rst index c234cd11cc..6ecccf084d 100644 --- a/doc/src/Developer_org.rst +++ b/doc/src/Developer_org.rst @@ -1,68 +1,75 @@ Source files ------------ -The source files of the LAMMPS code are found in two -directories of the distribution: ``src`` and ``lib``. -Most of the code is C++ but there are small numbers of files -in several other languages. +The source files of the LAMMPS code are found in two directories of the +distribution: ``src`` and ``lib``. Most of the code is written in C++ +but there are small a number of files in several other languages like C, +Fortran, Shell script, or Python. -The core of the code is located in the -``src`` folder and its sub-directories. -A sizable number of these files are in the ``src`` directory -itself, but there are plenty of :doc:`packages `, which can be -included or excluded when LAMMPS is built. See the :doc:`Include -packages in build ` section of the manual for more -information about that part of the build process. LAMMPS currently -supports building with :doc:`conventional makefiles ` and -through :doc:`CMake ` which differ in how packages are -enabled or disabled for a LAMMPS binary. The source files for each +The core of the code is located in the ``src`` folder and its +sub-directories. A sizable number of these files are in the ``src`` +directory itself, but there are plenty of :doc:`packages `, +which can be included or excluded when LAMMPS is built. See the +:doc:`Include packages in build ` section of the manual +for more information about that part of the build process. LAMMPS +currently supports building with :doc:`conventional makefiles +` and through :doc:`CMake `. Those procedures +differ in how packages are enabled or disabled for inclusion into a +LAMMPS binary so they cannot be mixed. The source files for each package are in all-uppercase sub-directories of the ``src`` folder, for example ``src/MOLECULE`` or ``src/USER-MISC``. The ``src/STUBS`` sub-directory is not a package but contains a dummy MPI library, that is used when building a serial version of the code. The ``src/MAKE`` -directory contains makefiles with settings and flags for a variety of -configuration and machines for the build process with traditional -makefiles. +directory and its sub-directories contain makefiles with settings and +flags for a variety of configuration and machines for the build process +with traditional makefiles. The ``lib`` directory contains the source code for several supporting libraries or files with configuration settings to use globally installed -libraries, that are required by some of the optional packages. -Each sub-directory, like ``lib/poems`` or ``lib/gpu``, contains the -source files, some of which are in different languages such as Fortran -or CUDA. These libraries are linked to during a LAMMPS build, if the -corresponding package is installed. +libraries, that are required by some of the optional packages. They may +include python scripts that can transparently download additional source +code on request. Each sub-directory, like ``lib/poems`` or ``lib/gpu``, +contains the source files, some of which are in different languages such +as Fortran or CUDA. These libraries included in the LAMMPS build, +if the corresponding package is installed. LAMMPS C++ source files almost always come in pairs, such as ``src/run.cpp`` (implementation file) and ``src/run.h`` (header file). -Each pair of files defines a C++ -class, for example the :cpp:class:`LAMMPS_NS::Run` class which contains -the code invoked by the :doc:`run ` command in a LAMMPS input script. -As this example illustrates, source file and class names often have a -one-to-one correspondence with a command used in a LAMMPS input script. -Some source files and classes do not have a corresponding input script +Each pair of files defines a C++ class, for example the +:cpp:class:`LAMMPS_NS::Run` class which contains the code invoked by the +:doc:`run ` command in a LAMMPS input script. As this example +illustrates, source file and class names often have a one-to-one +correspondence with a command used in a LAMMPS input script. Some +source files and classes do not have a corresponding input script command, e.g. ``src/force.cpp`` and the :cpp:class:`LAMMPS_NS::Force` class. They are discussed in the next section. -A small number of C++ classes and utility functions are implemented with -only a ``.h`` file. Examples are the Pointer class or the MathVec functions. +The names of all source files are in lower case and may use the +underscore character '_' to separate words. Outside of bundled libraries +which may have different conventions, all C and C++ header files have a +``.h`` extension, all C++ files have a ``.cpp`` extension, and C files a +``.c`` extension. A small number of C++ classes and utility functions +are implemented with only a ``.h`` file. Examples are the Pointer class +or the MathVec functions. Class topology -------------- Though LAMMPS has a lot of source files and classes, its class topology -is relative flat, as outlined in the :ref:`class-topology` figure. Each -name refers to a class and has a pair of associated source files in the -``src`` folder, for example the class :cpp:class:`LAMMPS_NS::Memory` -corresponds to the files ``memory.cpp`` and ``memory.h``, or the class -:cpp:class:`LAMMPS_NS::AtomVec` corresponds to the files -``atom_vec.cpp`` and ``atom_vec.h``. Full lines in the figure represent -compositing: that is the class to the left holds a pointer to an -instance of the class to the right. Dashed lines instead represent -inheritance: the class to the right is derived from the class on the -left. Classes with a red boundary are not instantiated directly, but -they represent the base classes for "styles". Those "styles" make up -the bulk of the LAMMPS code and only a few typical examples are included -in the figure for demonstration purposes. +is not very deep, which can be seen from the :ref:`class-topology` +figure. In that figure, each name refers to a class and has a pair of +associated source files in the ``src`` folder, for example the class +:cpp:class:`LAMMPS_NS::Memory` corresponds to the files ``memory.cpp`` +and ``memory.h``, or the class :cpp:class:`LAMMPS_NS::AtomVec` +corresponds to the files ``atom_vec.cpp`` and ``atom_vec.h``. Full +lines in the figure represent compositing: that is the class at the base +of the arrow holds a pointer to an instance of the class at the tip. +Dashed lines instead represent inheritance: the class to the tip of the +arrow is derived from the class at the base. Classes with a red boundary +are not instantiated directly, but they represent the base classes for +"styles". Those "styles" make up the bulk of the LAMMPS code and only +a few representative examples are included in the figure so it remains +readable. .. _class-topology: .. figure:: JPG/lammps-classes.png @@ -82,69 +89,76 @@ in the figure for demonstration purposes. derived classes, which may also hold instances of other classes. The :cpp:class:`LAMMPS_NS::LAMMPS` class is the topmost class and -represents what is referred to an "instance" of LAMMPS. It is a -composite holding references to instances of other core classes +represents what is generally referred to an "instance" of LAMMPS. It is +a composite holding pointers to instances of other core classes providing the core functionality of the MD engine in LAMMPS and through them abstractions of the required operations. The constructor of the LAMMPS class will instantiate those instances, process the command line flags, initialize MPI (if not already done) and set up file pointers for -input and output. The destructor will shut everything down and free all +input and output. The destructor will shut everything down and free all associated memory. Thus code for the standalone LAMMPS executable in ``main.cpp`` simply initializes MPI, instantiates a single instance of -LAMMPS, and passes it the command line flags and input script. It +LAMMPS while passing it the command line flags and input script. It deletes the LAMMPS instance after the method reading the input returns and shuts down the MPI environment before it exits the executable. The :cpp:class:`LAMMPS_NS::Pointers` is not shown in the -:ref:`class-topology` figure, it holds references to members of the -`LAMMPS_NS::LAMMPS`, so that all classes derived from -:cpp:class:`LAMMPS_NS::Pointers` have direct access to those reference. -From the class topology all classes with blue boundary are referenced in -this class and all classes in the second and third columns, that are not -listed as derived classes are instead derived from -:cpp:class:`LAMMPS_NS::Pointers`. +:ref:`class-topology` figure for clarity. It holds references to many +of the members of the `LAMMPS_NS::LAMMPS`, so that all classes derived +from :cpp:class:`LAMMPS_NS::Pointers` have direct access to those +reference. From the class topology all classes with blue boundary are +referenced in the Pointers class and all classes in the second and third +columns, that are not listed as derived classes are instead derived from +:cpp:class:`LAMMPS_NS::Pointers`. To initialize the pointer references +in Pointers, a pointer to the LAMMPS class instance needs to be passed +to the constructor and thus all constructors for classes derived from it +must do so and pass this pointer to the constructor for Pointers. -Since all storage is encapsulated, the LAMMPS class can also be -instantiated multiple times by a calling code, and that can be either -simultaneously or consecutively. When running in parallel with MPI, -care has to be taken, that suitable communicators are used to not -create conflicts between different instances. +Since all storage is supposed to be encapsulated (there are a few +exceptions), the LAMMPS class can also be instantiated multiple times by +a calling code. Outside of the aforementioned exceptions, those LAMMPS +instances can be used alternately. As of the time of this writing +(early 2021) LAMMPS is not yet sufficiently thread-safe for concurrent +execution. When running in parallel with MPI, care has to be taken, +that suitable copies of communicators are used to not create conflicts +between different instances. -The LAMMPS class currently holds instances of 19 classes representing -different core functionalities There are a handful of virtual parent -classes in LAMMPS that define what LAMMPS calls ``styles``. They are -shaded red in the :ref:`class-topology` figure. Each of these are +The LAMMPS class currently (early 2021) holds instances of 19 classes +representing the core functionality. There are a handful of virtual +parent classes in LAMMPS that define what LAMMPS calls ``styles``. They +are shaded red in the :ref:`class-topology` figure. Each of these are parents of a number of child classes that implement the interface defined by the parent class. There are two main categories of these ``styles``: some may only have one instance active at a time (e.g. atom, pair, bond, angle, dihedral, improper, kspace, comm) and there is a -dedicated pointer variable in the composite class that manages them. +dedicated pointer variable for each of them in the composite class. Setups that require a mix of different such styles have to use a -*hybrid* class that manages and forwards calls to the corresponding -sub-styles for the designated subset of atoms or data. or the composite -class may have lists of class instances, e.g. Modify handles lists of -compute and fix styles, while Output handles dumps class instances. +*hybrid* class that takes the place of the one allowed instance and then +manages and forwards calls to the corresponding sub-styles for the +designated subset of atoms or data. The composite class may also have +lists of class instances, e.g. Modify handles lists of compute and fix +styles, while Output handles a list of dump class instances. -The exception to this scheme are the ``command`` style classes. These -implement specific commands that can be invoked before, after, or between -runs or are commands which launch a simulation. For these an instance -of the class is created, its command() method called and then, after -completion, the class instance deleted. Examples for this are the -create_box, create_atoms, minimize, run, or velocity command styles. +The exception to this scheme are the ``command`` style classes. These +implement specific commands that can be invoked before, after, or in +between runs. For these an instance of the class is created, its +command() method called and then, after completion, the class instance +deleted. Examples for this are the create_box, create_atoms, minimize, +run, or velocity command styles. For all those ``styles`` certain naming conventions are employed: for -the fix nve command the class is called FixNVE and the files are +the fix nve command the class is called FixNVE and the source files are ``fix_nve.h`` and ``fix_nve.cpp``. Similarly for fix ave/time we have -FixAveTime and ``fix_ave_time.h`` and ``fix_ave_time.cpp``. Style names +FixAveTime and ``fix_ave_time.h`` and ``fix_ave_time.cpp``. Style names are lower case and without spaces or special characters. A suffix or -multiple appended with a forward slash '/' denotes a variant of the -corresponding class without the suffix. To connect the style name and -the class name, LAMMPS uses macros like the following ATOM\_CLASS, -PAIR\_CLASS, BOND\_CLASS, REGION\_CLASS, FIX\_CLASS, COMPUTE\_CLASS, -or DUMP\_CLASS in the corresponding header file. During compilation -files with the pattern ``style_name.h`` are created that contain include -statements including all headers of all styles of a given type that -are currently active (or "installed). +words are appended with a forward slash '/' which denotes a variant of +the corresponding class without the suffix. To connect the style name +and the class name, LAMMPS uses macros like: ``AtomStyle()``, +``PairStyle()``, ``BondStyle()``, ``RegionStyle()``, and so on in the +corresponding header file. During configuration or compilation files +with the pattern ``style_.h`` are created that consist of a list +of include statements including all headers of all styles of a given +type that are currently active (or "installed). More details on individual classes in the :ref:`class-topology` are as @@ -152,11 +166,11 @@ follows: - The Memory class handles allocation of all large vectors and arrays. -- The Error class prints all error and warning messages. +- The Error class prints all (terminal) error and warning messages. -- The Universe class sets up partitions of processors so that multiple - simulations can be run, each on a subset of the processors allocated - for a run, e.g. by the mpirun command. +- The Universe class sets up one or more partitions of processors so + that one or multiple simulations can be run, on the processors + allocated for a run, e.g. by the mpirun command. - The Input class reads and processes input input strings and files, stores variables, and invokes :doc:`commands `. @@ -241,7 +255,8 @@ follows: .. TODO section on "Spatial decomposition and parallel operations" .. diagram of 3d processor grid, brick vs. tiled. local vs. ghost .. atoms, 6-way communication with pack/unpack functions, -.. PBC as part of the communication +.. PBC as part of the communication, forward and reverse communication +.. rendezvous communication, ring communication. .. TODO section on "Fixes, Computes, and Variables" .. how and when data is computed and provided and how it is From 9a419154fafcf57cc290aeab7962a1f89c02a12c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 1 Feb 2021 10:15:06 -0500 Subject: [PATCH 14/16] whitespace --- src/USER-MISC/pair_agni.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-MISC/pair_agni.h b/src/USER-MISC/pair_agni.h index 4627d79804..58adc2002d 100644 --- a/src/USER-MISC/pair_agni.h +++ b/src/USER-MISC/pair_agni.h @@ -40,7 +40,7 @@ class PairAGNI : public Pair { double *eta,**xU,*alpha; double sigma,lambda,b,gwidth; int numeta,numtrain,ielement; - + }; protected: From 2b44d671283a0ed2b7211dd80c9fff83a8c1d431 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 1 Feb 2021 18:13:00 -0500 Subject: [PATCH 15/16] consistent dependencies for targes in "doc" folder makefile --- doc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 041c7a372a..aad20461ec 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -94,7 +94,7 @@ $(SPHINXCONFIG)/conf.py: $(SPHINXCONFIG)/conf.py.in -e 's,@LAMMPS_PYTHON_DIR@,$(BUILDDIR)/../python,g' \ -e 's,@LAMMPS_DOC_DIR@,$(BUILDDIR),g' $< > $@ -html: xmlgen $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) +html: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) @if [ "$(HAS_BASH)" == "NO" ] ; then echo "bash was not found at $(OSHELL)! Please use: $(MAKE) SHELL=/path/to/bash" 1>&2; exit 1; fi @$(MAKE) $(MFLAGS) -C graphviz all @(\ @@ -118,7 +118,7 @@ html: xmlgen $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) @rm -rf html/PDF/.[sg]* @echo "Build finished. The HTML pages are in doc/html." -spelling: xmlgen $(VENV) $(SPHINXCONFIG)/false_positives.txt +spelling: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(SPHINXCONFIG)/false_positives.txt @if [ "$(HAS_BASH)" == "NO" ] ; then echo "bash was not found at $(OSHELL)! Please use: $(MAKE) SHELL=/path/to/bash" 1>&2; exit 1; fi @(\ . $(VENV)/bin/activate ; env PYTHONWARNINGS= \ From 2ee701f7191b7f84d18adf552fcd86393d279786 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 1 Feb 2021 18:43:42 -0500 Subject: [PATCH 16/16] also flush screen stdio buffer with thermo_modify flush yes --- src/thermo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thermo.cpp b/src/thermo.cpp index 9197f88084..0e9defd165 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -381,6 +381,7 @@ void Thermo::compute(int flag) if (me == 0) { utils::logmesg(lmp,line); + if (screen && flushflag) fflush(screen); if (logfile && flushflag) fflush(logfile); }