Merge branch 'collected-small-changes' into variable-vector-wildcard

This commit is contained in:
Axel Kohlmeyer
2022-04-26 17:26:17 -04:00
12 changed files with 503 additions and 18 deletions

View File

@ -21,12 +21,13 @@ Examples
.. code-block:: LAMMPS
units real
compute cos all viscosity/cos
variable V equal c_cos[7]
variable A equal 0.02E-5
variable A equal 0.02E-5 # A/fs^2
variable density equal density
variable lz equal lz
variable reciprocalViscosity equal v_V/${A}/v_density*39.4784/v_lz/v_lz*100
variable reciprocalViscosity equal v_V/${A}/v_density*39.4784/v_lz/v_lz*100 # 1/(Pa*s)
Description
"""""""""""

View File

@ -13,7 +13,7 @@ Syntax
* ID, group-ID are documented in :doc:`fix <fix>` command
* accelerate/cos = style name of this fix command
* value = amplitude of acceleration (in unit of force/mass)
* value = amplitude of acceleration (in unit of velocity/time)
Examples

View File

@ -31,17 +31,17 @@ done
if (test $1 = 1) then
CONFIGSCRIPT=none
if ( test `which adios2-config 2>> /dev/null` ) then
if ( type adios2-config > /dev/null 2>&1 ) then
CONFIGSCRIPT=adios2-config
elif ( ! test -z "$ADIOS2_DIR" ) then
if ( test `which $ADIOS2_DIR/bin/adios2-config` ) then
if ( type $ADIOS2_DIR/bin/adios2-config > /dev/null 2>&1 ) then
CONFIGSCRIPT=$ADIOS2_DIR/bin/adios2-config
else
echo "ERROR: ADIOS2_DIR environment variable is set but" \
"\$ADIOS2_DIR/bin/adios2-config does not exist"
fi
elif ( ! test -z "$ADIOS_DIR" ) then
if ( test `which $ADIOS_DIR/bin/adios2-config` ) then
if ( type $ADIOS_DIR/bin/adios2-config > /dev/null 2>&1 ) then
CONFIGSCRIPT=$ADIOS_DIR/bin/adios2-config
else
echo "ERROR: ADIOS_DIR environment variable is set but" \

View File

@ -46,7 +46,7 @@ action mliap_model_python_couple.pyx python_impl.cpp
# edit 2 Makefile.package files to include/exclude package info
if (test $1 = 1) then
if (test "$(type cythonize 2> /dev/null)" != "" && test -e ../python_impl.cpp) then
if (type cythonize > /dev/null 2>&1 && test -e ../python_impl.cpp) then
if (test -e ../Makefile.package) then
sed -i -e 's|^PKG_INC =[ \t]*|&-DMLIAP_PYTHON |' ../Makefile.package
fi
@ -69,7 +69,7 @@ elif (test $1 = 0) then
sed -i -e '/^include.*python.*mliap_python.*$/d' ../Makefile.package.settings
elif (test $1 = 2) then
if (type cythonize 2>&1 > /dev/null && test -e ../python_impl.cpp) then
if (type cythonize > /dev/null 2>&1 && test -e ../python_impl.cpp) then
if (test -e ../Makefile.package) then
sed -i -e 's/[^ \t]*-DMLIAP_PYTHON[^ \t]* //g' ../Makefile.package
fi

View File

@ -1195,11 +1195,9 @@ void Input::shell()
if (me == 0) {
for (int i = 1; i < narg; i++) {
rv = (platform::mkdir(arg[i]) < 0) ? errno : 0;
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);
errno = err;
if (err != 0)
error->warning(FLERR, "Shell command 'mkdir {}' failed with error '{}'",
arg[i],utils::getsyserror());
if (rv != 0)
error->warning(FLERR, "Shell command 'mkdir {}' failed with error '{}'", arg[i],
utils::getsyserror());
}
}
} else if (strcmp(arg[0],"mv") == 0) {

View File

@ -56,8 +56,7 @@ namespace utils {
* \param cmd name of the failing command
* \param error pointer to Error class instance (for abort) or nullptr */
[[noreturn]] void missing_cmd_args(const std::string &file, int line, const std::string &cmd,
Error *error);
void missing_cmd_args(const std::string &file, int line, const std::string &cmd, Error *error);
/* Internal function handling the argument list for logmesg(). */

View File

@ -0,0 +1,125 @@
BootStrap: docker
From: fedora:36
%post
dnf -y update
dnf -y install vim-enhanced git file make cmake patch which file Lmod \
ninja-build clang clang-tools-extra libomp-devel libubsan libasan libtsan \
diffutils dos2unix findutils rsync python-devel libjpeg-devel libpng-devel \
ccache gcc-c++ gcc-gfortran gdb valgrind eigen3-devel openblas-devel \
openmpi-devel mpich-devel fftw-devel voro++-devel gsl-devel hdf5-devel \
netcdf-devel netcdf-cxx-devel netcdf-mpich-devel netcdf-openmpi-devel \
readline-devel python3-pyyaml python3-Cython \
mingw-filesystem-base mingw32-nsis mingw-binutils-generic \
mingw32-filesystem mingw32-pkg-config \
mingw64-filesystem mingw64-pkg-config \
mingw32-crt mingw32-headers mingw32-binutils \
mingw64-crt mingw64-headers mingw64-binutils \
mingw32-cpp mingw32-gcc mingw32-gcc-gfortran mingw32-gcc-c++ \
mingw64-cpp mingw64-gcc mingw64-gcc-gfortran mingw64-gcc-c++ \
mingw32-libgomp mingw64-libgomp \
mingw32-winpthreads mingw64-winpthreads \
mingw32-eigen3 mingw64-eigen3 \
mingw32-fftw mingw64-fftw \
mingw32-libjpeg-turbo mingw64-libjpeg-turbo \
mingw32-libpng mingw64-libpng \
mingw32-python3 mingw64-python3 \
mingw32-python3-numpy mingw64-python3-numpy \
mingw32-python3-pyyaml mingw64-python3-pyyaml \
mingw32-python3-setuptools mingw64-python3-setuptools \
mingw32-readline mingw64-readline \
mingw32-termcap mingw64-termcap \
mingw32-zlib mingw64-zlib \
mingw32-zstd mingw64-zstd \
enchant python3-virtualenv doxygen latexmk \
texlive-latex-fonts texlive-pslatex texlive-collection-latexrecommended \
texlive-latex texlive-latexconfig doxygen-latex texlive-collection-latex \
texlive-latex-bin texlive-lualatex-math texlive-fncychap texlive-tabulary \
texlive-framed texlive-wrapfig texlive-upquote texlive-capt-of \
texlive-needspace texlive-titlesec texlive-anysize texlive-dvipng texlive-xindy \
blas-devel lapack-devel libyaml-devel openkim-models kim-api-devel \
zstd libzstd-devel yaml-cpp-devel
dnf clean all
# enable Lmod and load MPI
source /usr/share/lmod/lmod/init/profile
module purge
module load mpi
# manually install Plumed
mkdir plumed
cd plumed
version=2.7.4
curl -L -o plumed.tar.gz https://github.com/plumed/plumed2/releases/download/v${version}/plumed-src-${version}.tgz
tar -xzf plumed.tar.gz
cd plumed-${version}
./configure --disable-doc --prefix=/usr
make
make install
# fix up installation for CentOS and Fedora
mv -v /usr/lib64/pkgconfig/plumed* /usr/share/pkgconfig/
cd ../../
rm -rvf plumed
# create missing termcap pkgconfig files
cat > /usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/termcap.pc <<EOF
prefix=/usr/i686-w64-mingw32/sys-root/mingw
exec_prefix=/usr/i686-w64-mingw32/sys-root/mingw
libdir=/usr/i686-w64-mingw32/sys-root/mingw/lib
includedir=/usr/i686-w64-mingw32/sys-root/mingw/include
Name: Termcap
Description: GNU/MinGW terminal feature database
URL: ftp://ftp.gnu.org/gnu/termcap/
Version: 1.3
Libs: -L\${libdir} -ltermcap
Cflags:
EOF
cat > /usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/termcap.pc <<EOF
prefix=/usr/x86_64-w64-mingw32/sys-root/mingw
exec_prefix=/usr/x86_64-w64-mingw32/sys-root/mingw
libdir=/usr/x86_64-w64-mingw32/sys-root/mingw/lib
includedir=/usr/x86_64-w64-mingw32/sys-root/mingw/include
Name: Termcap
Description: GNU/MinGW terminal feature database
URL: ftp://ftp.gnu.org/gnu/termcap/
Version: 1.3
Libs: -L\${libdir} -ltermcap
Cflags:
EOF
# set custom prompt indicating the container name
CUSTOM_PROMPT_ENV=/.singularity.d/env/99-zz_custom_prompt.sh
cat >$CUSTOM_PROMPT_ENV <<EOF
#!/bin/bash
PS1="[fedora36:\u@\h] \W> "
EOF
chmod 755 $CUSTOM_PROMPT_ENV
%environment
# we need to reset any module variables
# inherited from the host.
unset __LMOD_REF_COUNT__LMFILES_
unset __LMOD_REF_COUNT_PATH
unset __LMOD_REF_COUNT_LD_LIBRARY_PATH
unset __LMOD_REF_COUNT_MANPATH
unset __LMOD_REF_COUNT_MODULEPATH
unset __LMOD_REF_COUNT_LOADEDMODULES
unset _LMFILES_
unset MODULEPATH
unset MODULESHOME
unset MODULEPATH_ROOT
unset LOADEDMODULES
unset LMOD_SYSTEM_DEFAULT_MODULES
# load MPI by default
. /etc/profile
module load mpi
# tell OpenMPI to not try using Infiniband
OMPI_MCA_btl="^openib"
# do not warn about unused components as this messes up testing
OMPI_MCA_btl_base_warn_component_unused="0"
export OMPI_MCA_btl OMPI_MCA_btl_base_warn_component_unused
%labels
Author akohlmey, rbberger

View File

@ -0,0 +1,149 @@
BootStrap: docker
From: ubuntu:22.04
%post
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install --no-install-recommends -y software-properties-common
# add-apt-repository ppa:openkim/latest
apt-get update
apt-get upgrade --no-install-recommends -y
apt-get install --no-install-recommends -y \
bc \
build-essential \
ccache \
clang \
cmake \
cmake-curses-gui \
curl \
doxygen \
enchant-2 \
g++ \
gcc \
gfortran \
git \
hdf5-tools \
less \
libblas-dev \
libeigen3-dev \
libenchant-2-dev \
libfftw3-dev \
libgsl-dev \
libhdf5-serial-dev \
libhwloc-dev \
libjpeg-dev \
liblapack-dev \
libnetcdf-dev \
libomp-dev \
libopenblas-dev \
libnuma-dev \
libpng-dev \
libproj-dev \
libreadline-dev \
libvtk9-dev \
libyaml-dev \
libzstd-dev \
make \
mpi-default-bin \
mpi-default-dev \
ninja-build \
python3-dev \
python3-pip \
python3-pkg-resources \
python3-setuptools \
python3-virtualenv \
python3-venv \
rsync \
ssh \
texlive \
texlive-latex-recommended \
texlive-formats-extra \
texlive-pictures \
texlive-publishers \
texlive-science \
dvipng \
latexmk \
xindy \
vim-nox \
virtualenv \
voro++-dev \
wget \
xxd \
valgrind \
gdb \
zstd \
libyaml-cpp-dev \
libkim-api-dev \
gpg-agent \
# openkim-models
# ###########################################################################
# # KIM-API
# ###########################################################################
#
# # workaround for installing files in /usr/share/doc inside of a container
# sed -i 's/path-exclude=\/usr\/share\/doc/#path-exclude=\/usr\/share\/doc/g' /etc/dpkg/dpkg.cfg.d/excludes
# apt-get install -y libkim-api-doc
# sed -i 's/#path-exclude=\/usr\/share\/doc/path-exclude=\/usr\/share\/doc/g' /etc/dpkg/dpkg.cfg.d/excludes
#
# # install KIM models
# KIM_API_EXAMPLES=/usr/share/doc/libkim-api-dev/examples
# gunzip $KIM_API_EXAMPLES/portable-models/LennardJones612_UniversalShifted__MO_959249795837_003/LennardJones612_UniversalShifted.params.gz
# gunzip $KIM_API_EXAMPLES/model-drivers/ex_model_driver_P_LJ/ex_model_driver_P_LJ.f90.gz
#
# kim-api-collections-management install system $KIM_API_EXAMPLES/model-drivers/LennardJones612__MD_414112407348_003
# kim-api-collections-management install system $KIM_API_EXAMPLES/model-drivers/ex_model_driver_P_LJ
# kim-api-collections-management install system $KIM_API_EXAMPLES/portable-models/LennardJones_Ar
# kim-api-collections-management install system $KIM_API_EXAMPLES/portable-models/ex_model_Ar_P_LJ
# kim-api-collections-management install system $KIM_API_EXAMPLES/portable-models/LennardJones612_UniversalShifted__MO_959249795837_003
# kim-api-collections-management install system $KIM_API_EXAMPLES/simulator-models/Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu
###########################################################################
# Plumed
###########################################################################
export PLUMED_PKG_VERSION=2.7.4
mkdir plumed
cd plumed
curl -L -o plumed.tar.gz https://github.com/plumed/plumed2/releases/download/v${PLUMED_PKG_VERSION}/plumed-src-${PLUMED_PKG_VERSION}.tgz
tar -xzf plumed.tar.gz
cd plumed-${PLUMED_PKG_VERSION}
./configure --disable-doc --prefix=/usr
make
make install
cd ../../
rm -rvf plumed
###########################################################################
# Customizations
###########################################################################
# set custom prompt indicating the container name
CUSTOM_PROMPT_ENV=/.singularity.d/env/99-zz_custom_prompt.sh
cat >$CUSTOM_PROMPT_ENV <<EOF
#!/bin/bash
PS1="[ubuntu22.04:\u@\h] \W> "
EOF
chmod 755 $CUSTOM_PROMPT_ENV
###########################################################################
# Cleanup
###########################################################################
# clean cache
rm -rf /var/lib/apt/lists/*
%environment
LC_ALL=C
export LC_ALL
export PATH=/usr/lib/ccache:$PATH
# tell OpenMPI to not try using Infiniband
OMPI_MCA_btl="^openib"
# do not warn about unused components as this messes up testing
OMPI_MCA_btl_base_warn_component_unused="0"
export OMPI_MCA_btl OMPI_MCA_btl_base_warn_component_unused
%labels
Author akohlmey, rbberger

View File

@ -8,6 +8,10 @@ add_executable(test_input_class test_input_class.cpp)
target_link_libraries(test_input_class PRIVATE lammps GTest::GTestMain)
add_test(NAME InputClass COMMAND test_input_class)
add_executable(test_advanced_utils test_advanced_utils.cpp)
target_link_libraries(test_advanced_utils PRIVATE lammps GTest::GMock)
add_test(NAME AdvancedUtils COMMAND test_advanced_utils)
add_executable(test_error_class test_error_class.cpp)
target_link_libraries(test_error_class PRIVATE lammps GTest::GMock)
add_test(NAME ErrorClass COMMAND test_error_class)

View File

@ -0,0 +1,204 @@
// unit tests for utils:: functions requiring a LAMMPS
#include "error.h"
#include "input.h"
#include "lammps.h"
#include "memory.h"
#include "utils.h"
#include "../testing/core.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
namespace LAMMPS_NS {
class Advanced_utils : public LAMMPSTest {
protected:
Error *error;
void SetUp() override
{
testbinary = "AdvancedUtils";
LAMMPSTest::SetUp();
error = lmp->error;
}
void atomic_system()
{
BEGIN_HIDE_OUTPUT();
command("units real");
command("lattice sc 1.0 origin 0.125 0.125 0.125");
command("region box block -2 2 -2 2 -2 2");
command("create_box 8 box");
command("create_atoms 1 box");
command("pair_style zero 3.5");
command("pair_coeff * *");
command("mass * 1.0");
command("region left block -2.0 -1.0 INF INF INF INF");
command("region right block 0.5 2.0 INF INF INF INF");
command("region top block INF INF -2.0 -1.0 INF INF");
command("set region left type 2");
command("set region right type 3");
END_HIDE_OUTPUT();
}
};
TEST_F(Advanced_utils, missing_cmd_args)
{
auto output = CAPTURE_OUTPUT([&] {
utils::missing_cmd_args(FLERR, "dummy", nullptr);
});
EXPECT_EQ(output, "");
TEST_FAILURE("ERROR: Illegal dummy command: missing argument",
utils::missing_cmd_args(FLERR, "dummy", error););
};
TEST_F(Advanced_utils, logmesg)
{
auto output = CAPTURE_OUTPUT([&] {
utils::logmesg(lmp, "test message");
});
EXPECT_EQ(output, "test message");
output = CAPTURE_OUTPUT([&] {
utils::logmesg(lmp, "test message from test {}", testbinary);
});
EXPECT_EQ(output, "test message from test " + testbinary);
};
// death tests only. the other cases are tested in the basic utils unit tester
TEST_F(Advanced_utils, bounds_int_fail)
{
int nlo, nhi;
TEST_FAILURE("ERROR: Invalid range string: 1x ",
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: -1 ",
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\+1 ",
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 1:3 ",
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\? ",
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 3\\*:2 ",
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, error););
}
TEST_F(Advanced_utils, bounds_bigint_fail)
{
bigint nlo, nhi;
TEST_FAILURE("ERROR: Invalid range string: 1x ",
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: -1 ",
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\+1 ",
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 1:3 ",
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\? ",
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 3\\*:2 ",
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, error););
}
TEST_F(Advanced_utils, expand_args)
{
atomic_system();
BEGIN_CAPTURE_OUTPUT();
command("compute temp all temp");
command("variable temp vector c_temp");
command("variable step equal step");
command("variable pe equal pe");
command("variable pe equal pe");
command("variable epair equal epair");
command("compute gofr all rdf 20 1 1 1 2");
command("fix 1 all ave/time 1 1 1 v_step v_pe v_epair");
command("fix 2 all nve");
command("run 1 post no");
auto output = END_CAPTURE_OUTPUT();
char **args, **earg;
constexpr int oarg = 9;
args = new char *[oarg];
args[0] = utils::strdup("v_step");
args[1] = utils::strdup("c_temp");
args[2] = utils::strdup("f_1[2*]");
args[3] = utils::strdup("c_temp[2*4]");
args[4] = utils::strdup("v_temp[*4]");
args[5] = utils::strdup("c_rdf[*]");
args[6] = utils::strdup("c_rdf[1][*]");
args[7] = utils::strdup("c_rdf[*][2]");
args[8] = utils::strdup("c_rdf[*][*]");
auto narg = utils::expand_args(FLERR, oarg, args, 0, earg, lmp);
EXPECT_EQ(narg, 12);
EXPECT_STREQ(earg[0], "v_step");
EXPECT_STREQ(earg[1], "c_temp");
EXPECT_STREQ(earg[2], "f_1[2]");
EXPECT_STREQ(earg[3], "f_1[3]");
EXPECT_STREQ(earg[4], "c_temp[2]");
EXPECT_STREQ(earg[5], "c_temp[3]");
EXPECT_STREQ(earg[6], "c_temp[4]");
EXPECT_STREQ(earg[7], "v_temp[*4]");
EXPECT_STREQ(earg[8], "c_rdf[*]");
EXPECT_STREQ(earg[9], "c_rdf[1][*]");
EXPECT_STREQ(earg[10], "c_rdf[*][2]");
EXPECT_STREQ(earg[11], "c_rdf[*][*]");
for (int i = 0; i < narg; ++i)
delete[] earg[i];
lmp->memory->sfree(earg);
narg = utils::expand_args(FLERR, oarg, args, 1, earg, lmp);
EXPECT_EQ(narg, oarg);
EXPECT_NE(args, earg);
EXPECT_STREQ(earg[0], "v_step");
EXPECT_STREQ(earg[1], "c_temp");
EXPECT_STREQ(earg[2], "f_1[2*]");
EXPECT_STREQ(earg[3], "c_temp[2*4]");
EXPECT_STREQ(earg[4], "v_temp[*4]");
EXPECT_STREQ(earg[5], "c_rdf[*]");
EXPECT_STREQ(earg[6], "c_rdf[1][*]");
EXPECT_STREQ(earg[7], "c_rdf[*][2]");
EXPECT_STREQ(earg[8], "c_rdf[*][*]");
for (int i = 0; i < oarg; ++i)
delete[] args[i];
delete[] args;
for (int i = 0; i < narg; ++i)
delete[] earg[i];
lmp->memory->sfree(earg);
}
} // namespace LAMMPS_NS
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -1,4 +1,4 @@
// unit tests for issuing command to a LAMMPS instance through the Input class
// unit tests for public member functions of the Error class
#include "error.h"
#include "info.h"
@ -129,8 +129,7 @@ int main(int argc, char **argv)
::testing::InitGoogleMock(&argc, argv);
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {

View File

@ -746,6 +746,12 @@ TEST(Utils, boundsbig_case3)
ASSERT_EQ(nhi, -1);
}
TEST(Utils, errorurl)
{
auto errmesg = utils::errorurl(10);
ASSERT_THAT(errmesg, Eq("\nFor more information see https://docs.lammps.org/err0010"));
}
TEST(Utils, getsyserror)
{
#if defined(__linux__)