Merge pull request #3988 from akohlmey/collected-small-changes

Collected small changes and fixes
This commit is contained in:
Axel Kohlmeyer
2023-11-27 21:41:03 -05:00
committed by GitHub
31 changed files with 130 additions and 102 deletions

View File

@ -59,16 +59,13 @@ jobs:
-D BUILD_SHARED_LIBS=on \
-D LAMMPS_SIZES=SMALLBIG \
-D LAMMPS_EXCEPTIONS=off \
-D PKG_MESSAGE=on \
-D PKG_MPIIO=on \
-D PKG_ATC=on \
-D PKG_AWPMD=on \
-D PKG_BOCS=on \
-D PKG_EFF=on \
-D PKG_H5MD=on \
-D PKG_INTEL=on \
-D PKG_LATBOLTZ=on \
-D PKG_MANIFOLD=on \
-D PKG_MDI=on \
-D PKG_MGPT=on \
-D PKG_ML-PACE=on \
-D PKG_ML-RANN=on \
@ -77,7 +74,6 @@ jobs:
-D PKG_PTM=on \
-D PKG_QTB=on \
-D PKG_SMTBQ=on \
-D PKG_TALLY=on \
../cmake
- name: Run Coverity Scan

View File

@ -6,6 +6,8 @@ set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_CUDA ON CACHE BOOL "" FORCE)
set(Kokkos_ARCH_PASCAL60 ON CACHE BOOL "" FORCE)
set(BUILD_OMP ON CACHE BOOL "" FORCE)
get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokkos/bin/nvcc_wrapper ABSOLUTE)
set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE)
# hide deprecation warnings temporarily for stable release
set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE)

View File

@ -180,19 +180,11 @@ discarded but by setting the verbose flag (via setting the ``TEST_ARGS``
environment variable, ``TEST_ARGS=-v``) it can be printed and used to
understand why tests fail unexpectedly.
Another complexity of these tests stems from the need to capture
situations where LAMMPS will stop with an error, i.e. handle so-called
"death tests". Here the LAMMPS code will operate differently depending
on whether it was configured to throw C++ exceptions on errors or call
either ``exit()`` or ``MPI_Abort()``. In the latter case, the test code
also needs to detect whether LAMMPS was compiled with the OpenMPI
library, as OpenMPI is **only** compatible the death test options of the
GoogleTest library when C++ exceptions are enabled; otherwise those
"death tests" must be skipped to avoid reporting bogus failures. The
specifics of this step are implemented in the ``TEST_FAILURE()``
macro. These tests operate by capturing the screen output when executing
the failing command and then comparing that with a provided regular
expression string pattern. Example:
The specifics of so-called "death tests", i.e. conditions where LAMMPS
should fail and throw an exception, are implemented in the
``TEST_FAILURE()`` macro. These tests operate by capturing the screen
output when executing the failing command and then comparing that with a
provided regular expression string pattern. Example:
.. code-block:: c++

View File

@ -3038,14 +3038,6 @@ Procedures Bound to the :f:type:`lammps` Derived Type
This function can be used to query if an error inside of LAMMPS
has thrown a :ref:`C++ exception <exceptions>`.
.. note::
This function will always report "no error" when the LAMMPS library
has been compiled without ``-DLAMMPS_EXCEPTIONS``, which turns fatal
errors aborting LAMMPS into C++ exceptions. You can use the library
function :cpp:func:`lammps_config_has_exceptions` to check if this is
the case.
:to: :cpp:func:`lammps_has_error`
:r has_error: ``.TRUE.`` if there is an error.
:rtype has_error: logical
@ -3068,13 +3060,6 @@ Procedures Bound to the :f:type:`lammps` Derived Type
would happen only in a single MPI rank and thus may not be recoverable, as
other MPI ranks may be waiting on the failing MPI rank(s) to send messages.
.. note::
This function will do nothing when the LAMMPS library has been
compiled without ``-DLAMMPS_EXCEPTIONS``, which turns errors aborting
LAMMPS into C++ exceptions. You can use the function
:f:func:`config_has_exceptions` to check whether this is the case.
:p character(len=\*) buffer: string buffer to copy the error message into
:o integer(c_int) status [optional]: 1 when all ranks had the error,
2 on a single-rank error.

View File

@ -80,13 +80,15 @@ run LAMMPS in serial mode.
:class: note
If the LAMMPS executable encounters an error condition, it will abort
after printing an error message. For a library interface this is
usually not desirable. Thus LAMMPS can be compiled to to :ref:`throw
a C++ exception <exceptions>` instead. If enabled, the library
functions will catch those exceptions and return. The error status
:cpp:func:`can be queried <lammps_has_error>` and an :cpp:func:`error
message retrieved <lammps_get_last_error_message>`. We thus
recommend enabling C++ exceptions when using the library interface,
after printing an error message. It does so by catching the
exceptions that LAMMPS could throw. For a C library interface this
is usually not desirable since the calling code might lack the
ability to catch such exceptions. Thus, the library functions will
catch those exceptions and return from the affected functions. The
error status :cpp:func:`can be queried <lammps_has_error>` and an
:cpp:func:`error message retrieved <lammps_get_last_error_message>`.
This is, for example used by the :doc:`LAMMPS python module
<Python_module>` and then a suitable Python exception is thrown.
.. admonition:: Using the C library interface as a plugin
:class: note

View File

@ -15,9 +15,7 @@ Python exception handling mechanism.
try:
# LAMMPS will normally terminate itself and the running process if an error
# occurs. This would kill the Python interpreter. To avoid this, make sure to
# compile with LAMMPS_EXCEPTIONS enabled. This ensures the library API calls
# will not terminate the parent process. Instead, the library wrapper will
# occurs. This would kill the Python interpreter. The library wrapper will
# detect that an error has occured and throw a Python exception
lmp.command('unknown')

View File

@ -5,8 +5,7 @@ The LAMMPS Python module enables calling the :ref:`LAMMPS C library API
<lammps_c_api>` from Python by dynamically loading functions in the
LAMMPS shared library through the Python `ctypes <ctypes_>`_
module. Because of the dynamic loading, it is required that LAMMPS is
compiled in :ref:`"shared" mode <exe>`. It is also recommended to
compile LAMMPS with :ref:`C++ exceptions <exceptions>` enabled.
compiled in :ref:`"shared" mode <exe>`.
Two components are necessary for Python to be able to invoke LAMMPS code:

View File

@ -307,7 +307,9 @@ the :doc:`run <run>` command. This fix is not invoked during
Restrictions
""""""""""""
none
The keyword "scale yes" is not supported for scaling per-atom parameters
diameter and change. You can use :doc:`fix adapt <fix_adapt>` for those.
Related commands
""""""""""""""""

View File

@ -181,6 +181,12 @@ This fix is part of the MC package. It is only enabled if LAMMPS was
built with that package. See the :doc:`Build package <Build_package>`
doc page for more info.
This fix cannot be used with systems that do not have per-type masses
(e.g. atom style sphere) since the implemented algorithm pre-computes
velocity rescaling factors from per-type masses and ignores any per-atom
masses, if present. In case both, per-type and per-atom masses are
present, a warning is printed.
Related commands
""""""""""""""""

View File

@ -706,6 +706,8 @@ library. Ceil() is the smallest integer not less than its argument.
Floor() if the largest integer not greater than its argument. Round()
is the nearest integer to its argument.
.. versionadded:: TBD
The ternary(x,y,z) function is the equivalent of the ternary operator
(? and :) in C or C++. It takes 3 arguments. The first argument is a
conditional. The result of the function is y if x evaluates to true
@ -1042,10 +1044,9 @@ to built-in commands. For all of these styles except *command*,
appending of active suffixes is also tried before reporting failure.
The *feature* category checks the availability of the following
compile-time enabled features: GZIP support, PNG support, JPEG
support, FFMPEG support, and C++ exceptions for error
handling. Corresponding names are *gzip*, *png*, *jpeg*, *ffmpeg* and
*exceptions*\ .
compile-time enabled features: GZIP support, PNG support, JPEG support,
FFMPEG support, and C++ exceptions for error handling. Corresponding
names are *gzip*, *png*, *jpeg*, *ffmpeg* and *exceptions*\ .
Example: Only dump in a given format if the compiled binary supports it.

View File

@ -63,13 +63,20 @@ int FixMvvDPD::setmask()
void FixMvvDPD::init()
{
if (!atom->vest_flag)
error->all(FLERR,"Fix mvv/dpd requires atom attribute vest");
error->all(FLERR,"Fix mvv/dpd requires atom attribute vest e.g. from atom style mdpd");
if (!force->pair_match("^mdpd",0) && !force->pair_match("^dpd",0)) {
if (force->pair_match("^hybrid",0)) {
if (!(force->pair_match("^mdpd",0,1) || force->pair_match("^dpd",0),1)) {
error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd");
}
} else {
error->all(FLERR, "Must use a dpd or mdpd pair style with fix mvv/dpd");
}
}
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
if (!force->pair_match("^edpd",0) && !force->pair_match("^dpd",0))
error->all(FLERR, "Must use a dpd or edpd pair style with fix mvv/edpd");
}
/* ----------------------------------------------------------------------

View File

@ -71,11 +71,20 @@ int FixMvvEDPD::setmask()
void FixMvvEDPD::init()
{
if (!atom->edpd_flag) error->all(FLERR,"Fix mvv/edpd requires atom style edpd");
if (!force->pair_match("^edpd",0)) {
if (force->pair_match("^hybrid",0)) {
if (!force->pair_match("^edpd",0,1)) {
error->all(FLERR, "Must use pair style edpd with fix mvv/edpd");
}
} else {
error->all(FLERR, "Must use pair style edpd with fix mvv/edpd");
}
}
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
if (!force->pair_match("^edpd",0))
error->all(FLERR, "Must use pair style edpd with fix mvv/edpd");
}
/* ----------------------------------------------------------------------

View File

@ -69,10 +69,20 @@ int FixMvvTDPD::setmask()
void FixMvvTDPD::init()
{
if (!atom->tdpd_flag) error->all(FLERR,"Fix mvv/tdpd requires atom style tdpd");
if (!force->pair_match("^tdpd",0)) {
if (force->pair_match("^hybrid",0)) {
if (!force->pair_match("^tdpd",0,1)) {
error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd");
}
} else {
error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd");
}
}
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
if (!force->pair_match("^tdpd",0))
error->all(FLERR, "Must use pair style tdpd with fix mvv/tdpd");
}
/* ----------------------------------------------------------------------

View File

@ -40,8 +40,8 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
enum{PAIR,KSPACE,ATOM};
enum{DIAMETER,CHARGE};
enum{PAIR, KSPACE, ATOM};
enum{DIAMETER, CHARGE};
/* ---------------------------------------------------------------------- */
@ -165,21 +165,21 @@ FixAdaptFEP::FixAdaptFEP(LAMMPS *lmp, int narg, char **arg) :
FixAdaptFEP::~FixAdaptFEP()
{
for (int m = 0; m < nadapt; m++) {
delete [] adapt[m].var;
delete[] adapt[m].var;
if (adapt[m].which == PAIR) {
delete [] adapt[m].pstyle;
delete [] adapt[m].pparam;
delete[] adapt[m].pstyle;
delete[] adapt[m].pparam;
memory->destroy(adapt[m].array_orig);
}
}
delete [] adapt;
delete[] adapt;
// check nfix in case all fixes have already been deleted
if (id_fix_diam && modify->nfix) modify->delete_fix(id_fix_diam);
if (id_fix_chg && modify->nfix) modify->delete_fix(id_fix_chg);
delete [] id_fix_diam;
delete [] id_fix_chg;
delete[] id_fix_diam;
delete[] id_fix_chg;
}
/* ---------------------------------------------------------------------- */
@ -434,6 +434,8 @@ void FixAdaptFEP::change_settings()
} else if (ad->which == ATOM) {
if (scaleflag)
error->all(FLERR, "Keyword 'scale yes' is not supported with fix adapt/fep for 'atom'");
// reset radius from diameter
// also scale rmass to new value

View File

@ -68,7 +68,9 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
int me = 0;
MPI_Comm_rank(world,&me);
if (me == 0) error->message(FLERR,"KOKKOS mode is enabled");
if (me == 0)
error->message(FLERR,"KOKKOS mode with Kokkos version {}.{}.{} is enabled",
KOKKOS_VERSION / 10000, (KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100);
// process any command-line args that invoke Kokkos settings

View File

@ -360,7 +360,7 @@ double AngleLepton::single(int type, int i1, int i2, int i3)
if (c < -1.0) c = -1.0;
double dtheta = acos(c) - theta0[type];
auto expr = expressions[type2expression[type]];
const auto &expr = expressions[type2expression[type]];
auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp));
auto anglepot = parsed.createCompiledExpression();
anglepot.getVariableReference("theta") = dtheta;

View File

@ -298,7 +298,7 @@ double BondLepton::single(int type, double rsq, int /*i*/, int /*j*/, double &ff
const double r = sqrt(rsq);
const double dr = r - r0[type];
auto expr = expressions[type2expression[type]];
const auto &expr = expressions[type2expression[type]];
auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp));
auto bondpot = parsed.createCompiledExpression();
auto bondforce = parsed.differentiate("r").createCompiledExpression();

View File

@ -423,7 +423,7 @@ void PairLepton::write_data_all(FILE *fp)
double PairLepton::single(int /* i */, int /* j */, int itype, int jtype, double rsq,
double /* factor_coul */, double factor_lj, double &fforce)
{
auto expr = expressions[type2expression[itype][jtype]];
const auto &expr = expressions[type2expression[itype][jtype]];
auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions);
auto pairpot = parsed.createCompiledExpression();
auto pairforce = parsed.differentiate("r").createCompiledExpression();

View File

@ -242,7 +242,7 @@ void PairLeptonCoul::read_restart_settings(FILE *fp)
double PairLeptonCoul::single(int i, int j, int itype, int jtype, double rsq, double factor_coul,
double /* factor_lj */, double &fforce)
{
auto expr = expressions[type2expression[itype][jtype]];
const auto &expr = expressions[type2expression[itype][jtype]];
auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions);
auto pairpot = parsed.createCompiledExpression();
auto pairforce = parsed.differentiate("r").createCompiledExpression();

View File

@ -205,7 +205,7 @@ void PairLeptonSphere::read_restart_settings(FILE *fp)
double PairLeptonSphere::single(int i, int j, int itype, int jtype, double rsq,
double /* factor_coul */, double factor_lj, double &fforce)
{
auto expr = expressions[type2expression[itype][jtype]];
const auto &expr = expressions[type2expression[itype][jtype]];
auto parsed = Lepton::Parser::parse(LeptonUtils::substitute(expr, lmp), functions);
auto pairpot = parsed.createCompiledExpression();
auto pairforce = parsed.differentiate("r").createCompiledExpression();

View File

@ -203,6 +203,10 @@ int FixAtomSwap::setmask()
void FixAtomSwap::init()
{
if (!atom->mass) error->all(FLERR, "Fix atom/swap requires per atom type masses");
if (atom->rmass_flag && (comm->me == 0))
error->warning(FLERR, "Fix atom/swap will use per-type masses for velocity rescaling");
c_pe = modify->get_compute_by_id("thermo_pe");
int *type = atom->type;

View File

@ -177,7 +177,7 @@ int FitPOD::read_data_file(double *fitting_weights, std::string &file_format,
if (words.size() == 0) continue;
auto keywd = words[0];
const auto &keywd = words[0];
if (words.size() != 2)
error->one(FLERR,"Improper POD file.", utils::getsyserror());

View File

@ -328,7 +328,7 @@ void MLPOD::read_pod(const std::string &pod_file)
if (words.size() == 0) continue;
auto keywd = words[0];
const auto &keywd = words[0];
if (keywd == "species") {
pod.nelements = words.size()-1;

View File

@ -354,6 +354,9 @@ namespace ReaxFF {
// Need to wait for all indices and tmp arrays accumulated.
#if defined(_OPENMP)
#pragma omp barrier
{
;
}
#endif
#if defined(_OPENMP)

View File

@ -260,7 +260,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR, "Compute {} compute {} array is accessed out-of-range", style, val.id);
} else if (input_mode == LOCAL) {
if (!val.val.c->peratom_flag)
if (!val.val.c->local_flag)
error->all(FLERR, "Compute {} compute {} does not calculate local values", style, val.id);
if (val.argindex == 0 && val.val.c->size_local_cols != 0)
error->all(FLERR, "Compute {} compute {} does not calculate a local vector", style, val.id);

View File

@ -134,13 +134,9 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
}
char *fixID = nullptr;
thetastr = phistr = nullptr;
cflag = STATIC;
cx = cy = cz = 0.5;
cxstr = cystr = czstr = nullptr;
upxstr = upystr = upzstr = nullptr;
zoomstr = nullptr;
boxflag = YES;
boxdiam = 0.02;
axesflag = NO;
@ -487,6 +483,16 @@ DumpImage::~DumpImage()
memory->destroy(bufcopy);
memory->destroy(gbuf);
delete[] upxstr;
delete[] upystr;
delete[] upzstr;
delete[] zoomstr;
delete[] thetastr;
delete[] phistr;
delete[] cxstr;
delete[] cystr;
delete[] czstr;
delete[] id_grid_compute;
delete[] id_grid_fix;
}

View File

@ -39,8 +39,8 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
enum{PAIR,KSPACE,ATOM,BOND,ANGLE};
enum{DIAMETER,CHARGE};
enum{PAIR, KSPACE, ATOM, BOND, ANGLE};
enum{DIAMETER, CHARGE};
/* ---------------------------------------------------------------------- */

View File

@ -1225,6 +1225,10 @@ std::string Info::get_accelerator_info(const std::string &package)
if (has_accelerator_feature("KOKKOS","precision","single")) mesg += " single";
if (has_accelerator_feature("KOKKOS","precision","mixed")) mesg += " mixed";
if (has_accelerator_feature("KOKKOS","precision","double")) mesg += " double";
#if LMP_KOKKOS
mesg += fmt::format("\nKokkos library version: {}.{}.{}", KOKKOS_VERSION / 10000,
(KOKKOS_VERSION % 10000) / 100, KOKKOS_VERSION % 100);
#endif
mesg += "\n";
}
if ((package.empty() || (package == "OPENMP")) && has_package("OPENMP")) {
@ -1235,6 +1239,9 @@ std::string Info::get_accelerator_info(const std::string &package)
if (has_accelerator_feature("OPENMP","precision","single")) mesg += " single";
if (has_accelerator_feature("OPENMP","precision","mixed")) mesg += " mixed";
if (has_accelerator_feature("OPENMP","precision","double")) mesg += " double";
#if defined(_OPENMP)
mesg += "\nOpenMP standard: " + platform::openmp_standard();
#endif
mesg += "\n";
}
if ((package.empty() || (package == "INTEL")) && has_package("INTEL")) {

View File

@ -481,7 +481,7 @@ void lammps_error(void *handle, int error_type, const char *error_text)
}
END_CAPTURE
// with enabled exceptions the above code will simply throw an
// in case of an error the above code will simply throw an
// exception and record the error message. So we have to explicitly
// stop here like we do in main.cpp
if (lammps_has_error(handle)) {
@ -6608,13 +6608,6 @@ has thrown a :ref:`C++ exception <exceptions>`.
instance, but instead would check the global error buffer of the
library interface.
.. note::
This function will always report "no error" when the LAMMPS library
has been compiled without ``-DLAMMPS_EXCEPTIONS``, which turns fatal
errors aborting LAMMPS into C++ exceptions. You can use the library
function :cpp:func:`lammps_config_has_exceptions` to check whether this is
the case.
\endverbatim
*
* \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL
@ -6663,12 +6656,6 @@ the failing MPI ranks to send messages.
The *buffer* pointer may be ``NULL``. This will clear any error
status without copying the error message.
.. note::
This function will do nothing when the LAMMPS library has been
compiled without ``-DLAMMPS_EXCEPTIONS``, which turns errors aborting
LAMMPS into C++ exceptions. You can use the library function
:cpp:func:`lammps_config_has_exceptions` to check whether this is the case.
\endverbatim
*
* \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL.

View File

@ -391,8 +391,16 @@ std::string platform::openmp_standard()
// Supported OpenMP version corresponds to the release date of the
// specifications as posted at https://www.openmp.org/specifications/
#if _OPENMP > 202011
return "OpenMP newer than version 5.1";
#if _OPENMP > 202411
return "OpenMP newer than version 6.0";
#elif _OPENMP == 202411
return "OpenMP 6.0";
#elif _OPENMP == 202311
return "OpenMP 6.0 preview 2";
#elif _OPENMP == 202211
return "OpenMP 6.0 preview 1";
#elif _OPENMP == 202111
return "OpenMP 5.2";
#elif _OPENMP == 202011
return "OpenMP 5.1";
#elif _OPENMP == 201811
@ -1058,7 +1066,7 @@ FILE *platform::compressed_read(const std::string &file)
FILE *fp = nullptr;
#if defined(LAMMPS_GZIP)
auto compress = find_compress_type(file);
const auto &compress = find_compress_type(file);
if (compress.style == ::compress_info::NONE) return nullptr;
if (find_exe_path(compress.command).size())
@ -1077,7 +1085,7 @@ FILE *platform::compressed_write(const std::string &file)
FILE *fp = nullptr;
#if defined(LAMMPS_GZIP)
auto compress = find_compress_type(file);
const auto &compress = find_compress_type(file);
if (compress.style == ::compress_info::NONE) return nullptr;
if (find_exe_path(compress.command).size())

View File

@ -1505,7 +1505,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
// equal-style or immediate variable is being evaluated
if ((style[ivar] == EQUAL) || (ivar < 0)) {
if ((ivar < 0) || (style[ivar] == EQUAL)) {
// c_ID = scalar from global scalar
@ -1773,7 +1773,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
// equal-style or immediate variable is being evaluated
if ((style[ivar] == EQUAL) || (ivar < 0)) {
if ((ivar < 0) || (style[ivar] == EQUAL)) {
// f_ID = scalar from global scalar