From 9c46acfd625bb27d2aed2692d9dfb0a15e5d2779 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 24 Apr 2022 23:23:01 -0400 Subject: [PATCH 01/16] fix parallel processing bug with shell mkdir command --- src/input.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 6c4fc56776..a28bd48296 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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) { From 28900925f4eebb5e98ed7c0774c2e87e695eeb62 Mon Sep 17 00:00:00 2001 From: Zheng GONG Date: Mon, 25 Apr 2022 05:59:41 +0200 Subject: [PATCH 02/16] Fix the unit for fix/accelerate/cos --- doc/src/fix_accelerate_cos.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_accelerate_cos.rst b/doc/src/fix_accelerate_cos.rst index 46e08e68b4..904e853ad8 100644 --- a/doc/src/fix_accelerate_cos.rst +++ b/doc/src/fix_accelerate_cos.rst @@ -13,7 +13,7 @@ Syntax * ID, group-ID are documented in :doc:`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 From a5cd95d6c661f23ea798ad3e46dd1f8f2a94e676 Mon Sep 17 00:00:00 2001 From: Zheng GONG Date: Mon, 25 Apr 2022 06:23:54 +0200 Subject: [PATCH 03/16] Add comment for the units in compute/viscosity --- doc/src/compute_viscosity_cos.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_viscosity_cos.rst b/doc/src/compute_viscosity_cos.rst index d08217a590..2f7a09924c 100644 --- a/doc/src/compute_viscosity_cos.rst +++ b/doc/src/compute_viscosity_cos.rst @@ -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 """"""""""" From 8679266db845eb374b2eea9de11fc71e2001b6fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 25 Apr 2022 13:05:43 -0400 Subject: [PATCH 04/16] add container definitions for Fedora 36 and Ubuntu 22.04LTS --- tools/singularity/fedora36_mingw.def | 125 ++++++++++++++++++++++ tools/singularity/ubuntu22.04.def | 149 +++++++++++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 tools/singularity/fedora36_mingw.def create mode 100644 tools/singularity/ubuntu22.04.def diff --git a/tools/singularity/fedora36_mingw.def b/tools/singularity/fedora36_mingw.def new file mode 100644 index 0000000000..79213e9e92 --- /dev/null +++ b/tools/singularity/fedora36_mingw.def @@ -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 < /usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/termcap.pc <$CUSTOM_PROMPT_ENV <$CUSTOM_PROMPT_ENV < Date: Mon, 25 Apr 2022 16:23:48 -0400 Subject: [PATCH 05/16] remove invalid [[noreturn]] attribute --- src/utils.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils.h b/src/utils.h index f7f269a97d..6726240d0d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -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(). */ From bb8e953fb5137663a2c5af46bf4e6d410f9ee680 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 25 Apr 2022 15:43:08 -0600 Subject: [PATCH 06/16] add support for wildcards in variable vectors --- doc/src/fix_ave_correlate.rst | 30 ++++++++---- doc/src/fix_ave_histo.rst | 49 ++++++++++++------- doc/src/fix_ave_time.rst | 31 ++++++++---- doc/src/thermo_style.rst | 31 +++++++----- .../ELASTIC_T/BORN_MATRIX/Silicon/output.in | 3 +- src/utils.cpp | 28 +++++++++-- 6 files changed, 117 insertions(+), 55 deletions(-) diff --git a/doc/src/fix_ave_correlate.rst b/doc/src/fix_ave_correlate.rst index 23086d465f..d2e9599374 100644 --- a/doc/src/fix_ave_correlate.rst +++ b/doc/src/fix_ave_correlate.rst @@ -25,7 +25,7 @@ Syntax f_ID = global scalar calculated by a fix with ID f_ID[I] = Ith component of global vector calculated by a fix with ID, I can include wildcard (see below) v_name = global value calculated by an equal-style variable with name - v_name[I] = Ith component of a vector-style variable with name + v_name[I] = Ith component of a vector-style variable with name, I can include wildcard (see below) * zero or more keyword/arg pairs may be appended * keyword = *type* or *ave* or *start* or *prefactor* or *file* or *overwrite* or *title1* or *title2* or *title3* @@ -105,15 +105,17 @@ individual fixes for info on which ones produce such values. ones that can be used with this fix. Variables of style *atom* cannot be used, since they produce per-atom values. -Note that for values from a compute or fix, the bracketed index I can -be specified using a wildcard asterisk with the index to effectively -specify multiple values. This takes the form "\*" or "\*n" or "n\*" or -"m\*n". If N = the size of the vector (for *mode* = scalar) or the -number of columns in the array (for *mode* = vector), then an asterisk -with no numeric values means all indices from 1 to N. A leading -asterisk means all indices from 1 to n (inclusive). A trailing -asterisk means all indices from n to N (inclusive). A middle asterisk -means all indices from m to n (inclusive). +---------- + +For input values from a compute or fix or variable , the bracketed +index I can be specified using a wildcard asterisk with the index to +effectively specify multiple values. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = +scalar) or the number of columns in the array (for *mode* = vector), +then an asterisk with no numeric values means all indices from 1 to N. +A leading asterisk means all indices from 1 to n (inclusive). A +trailing asterisk means all indices from n to N (inclusive). A middle +asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector had been listed one by one. E.g. these 2 fix ave/correlate @@ -128,6 +130,14 @@ values. c_myPress[1] c_myPress[2] c_myPress[3] & c_myPress[4] c_myPress[5] c_myPress[6] +.. note:: + + For a vector-style variable, only the wildcard forms "\*n" or + "m\*n" are allowed. You must specify the upper bound, because + vector-style variable lengths are not determined until the variable + is evaluated. If n is specified larger than the vector length + turns out to be, zeroes are output for missing vector values. + ---------- The *Nevery*, *Nrepeat*, and *Nfreq* arguments specify on what diff --git a/doc/src/fix_ave_histo.rst b/doc/src/fix_ave_histo.rst index 05c63a6faf..3cd1bdf4db 100644 --- a/doc/src/fix_ave_histo.rst +++ b/doc/src/fix_ave_histo.rst @@ -32,7 +32,7 @@ Syntax f_ID = scalar or vector calculated by a fix with ID f_ID[I] = Ith component of vector or Ith column of array calculated by a fix with ID, I can include wildcard (see below) v_name = value(s) calculated by an equal-style or vector-style or atom-style variable with name - v_name[I] = value calculated by a vector-style variable with name + v_name[I] = value calculated by a vector-style variable with name, I can include wildcard (see below) * zero or more keyword/arg pairs may be appended * keyword = *mode* or *file* or *ave* or *start* or *beyond* or *overwrite* or *title1* or *title2* or *title3* @@ -120,15 +120,27 @@ If *mode* = vector, then the input values must be vectors, or arrays with a bracketed term appended, indicating the Ith column of the array is used. -Note that for values from a compute or fix, the bracketed index I can -be specified using a wildcard asterisk with the index to effectively -specify multiple values. This takes the form "\*" or "\*n" or "n\*" or -"m\*n". If N = the size of the vector (for *mode* = scalar) or the -number of columns in the array (for *mode* = vector), then an asterisk -with no numeric values means all indices from 1 to N. A leading -asterisk means all indices from 1 to n (inclusive). A trailing -asterisk means all indices from n to N (inclusive). A middle asterisk -means all indices from m to n (inclusive). +If the fix ave/histo/weight command is used, exactly two values must +be specified. If the values are vectors, they must be the same +length. The first value (a scalar or vector) is what is histogrammed +into bins, in the same manner the fix ave/histo command operates. The +second value (a scalar or vector) is used as a "weight". This means +that instead of each value tallying a "1" to its bin, the +corresponding weight is tallied. E.g. The Nth entry (weight) in the +second vector is tallied to the bin corresponding to the Nth entry in +the first vector. + +---------- + +For input values from a compute or fix or variable, the bracketed +index I can be specified using a wildcard asterisk with the index to +effectively specify multiple values. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = +scalar) or the number of columns in the array (for *mode* = vector), +then an asterisk with no numeric values means all indices from 1 to N. +A leading asterisk means all indices from 1 to n (inclusive). A +trailing asterisk means all indices from n to N (inclusive). A middle +asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector or columns of the array had been listed one by one. E.g. these @@ -141,15 +153,14 @@ vector or columns of the array had been listed one by one. E.g. these fix 1 all ave/histo 100 1 100 -10.0 10.0 100 c_myCOM[*] file tmp1.com mode vector fix 2 all ave/histo 100 1 100 -10.0 10.0 100 c_myCOM[1] c_myCOM[2] c_myCOM[3] file tmp2.com mode vector -If the fix ave/histo/weight command is used, exactly two values must -be specified. If the values are vectors, they must be the same -length. The first value (a scalar or vector) is what is histogrammed -into bins, in the same manner the fix ave/histo command operates. The -second value (a scalar or vector) is used as a "weight". This means -that instead of each value tallying a "1" to its bin, the -corresponding weight is tallied. E.g. The Nth entry (weight) in the -second vector is tallied to the bin corresponding to the Nth entry in -the first vector. +.. note:: + + For a vector-style variable, only the wildcard forms "\*n" or + "m\*n" are allowed. You must specify the upper bound, because + vector-style variable lengths are not determined until the variable + is evaluated. If n is specified larger than the vector length"\*n" + or "n\*" or "m\*n". turns out to be, zeroes are output for missing + vector values. ---------- diff --git a/doc/src/fix_ave_time.rst b/doc/src/fix_ave_time.rst index dfa385ea46..f2d634ca75 100644 --- a/doc/src/fix_ave_time.rst +++ b/doc/src/fix_ave_time.rst @@ -25,7 +25,7 @@ Syntax f_ID = global scalar or vector calculated by a fix with ID f_ID[I] = Ith component of global vector or Ith column of global array calculated by a fix with ID, I can include wildcard (see below) v_name = value(s) calculated by an equal-style or vector-style variable with name - v_name[I] = value calculated by a vector-style variable with name + v_name[I] = value calculated by a vector-style variable with name, I can include wildcard (see below) * zero or more keyword/arg pairs may be appended * keyword = *mode* or *file* or *ave* or *start* or *off* or *overwrite* or *title1* or *title2* or *title3* @@ -113,15 +113,17 @@ with a bracketed term appended, indicating the Ith column of the array is used. All vectors must be the same length, which is the length of the vector or number of rows in the array. -Note that for values from a compute or fix, the bracketed index I can -be specified using a wildcard asterisk with the index to effectively -specify multiple values. This takes the form "\*" or "\*n" or "n\*" or -"m\*n". If N = the size of the vector (for *mode* = scalar) or the -number of columns in the array (for *mode* = vector), then an asterisk -with no numeric values means all indices from 1 to N. A leading -asterisk means all indices from 1 to n (inclusive). A trailing -asterisk means all indices from n to N (inclusive). A middle asterisk -means all indices from m to n (inclusive). +---------- + +For input values from a compute or fix or variable, the bracketed +index I can be specified using a wildcard asterisk with the index to +effectively specify multiple values. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = +scalar) or the number of columns in the array (for *mode* = vector), +then an asterisk with no numeric values means all indices from 1 to N. +A leading asterisk means all indices from 1 to n (inclusive). A +trailing asterisk means all indices from n to N (inclusive). A middle +asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector or columns of the array had been listed one by one. E.g. these @@ -134,6 +136,15 @@ with 3 columns, each of length 50: fix 1 all ave/time 100 1 100 c_myRDF[*] file tmp1.rdf mode vector fix 2 all ave/time 100 1 100 c_myRDF[1] c_myRDF[2] c_myRDF[3] file tmp2.rdf mode vector +.. note:: + + For a vector-style variable, only the wildcard forms "\*n" or + "m\*n" are allowed. You must specify the upper bound, because + vector-style variable lengths are not determined until the variable + is evaluated. If n is specified larger than the vector length"\*n" + or "n\*" or "m\*n". turns out to be, zeroes are output for missing + vector values. + ---------- The *Nevery*, *Nrepeat*, and *Nfreq* arguments specify on what diff --git a/doc/src/thermo_style.rst b/doc/src/thermo_style.rst index 5d63ed81b6..38f832ba98 100644 --- a/doc/src/thermo_style.rst +++ b/doc/src/thermo_style.rst @@ -85,7 +85,7 @@ Syntax f_ID[I] = Ith component of global vector calculated by a fix with ID, I can include wildcard (see below) f_ID[I][J] = I,J component of global array calculated by a fix with ID v_name = value calculated by an equal-style variable with name - v_name[I] = value calculated by a vector-style variable with name + v_name[I] = value calculated by a vector-style variable with name, I can include wildcard (see below) Examples """""""" @@ -348,16 +348,16 @@ dimensions *lx*, *ly*, *lz*, *yz*, *xz*, *xy*\ . ---------- -For output values from a compute or fix, the bracketed index I used to -index a vector, as in *c_ID[I]* or *f_ID[I]*, can be specified -using a wildcard asterisk with the index to effectively specify -multiple values. This takes the form "\*" or "\*n" or "n\*" or "m\*n". -If N = the size of the vector (for *mode* = scalar) or the number of -columns in the array (for *mode* = vector), then an asterisk with no -numeric values means all indices from 1 to N. A leading asterisk -means all indices from 1 to n (inclusive). A trailing asterisk means -all indices from n to N (inclusive). A middle asterisk means all -indices from m to n (inclusive). +For output values from a compute or fix or variable, the bracketed +index I used to index a vector, as in *c_ID[I]* or *f_ID[I]* or +*v_name[I]*, can be specified using a wildcard asterisk with the index +to effectively specify multiple values. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = +scalar) or the number of columns in the array (for *mode* = vector), +then an asterisk with no numeric values means all indices from 1 to N. +A leading asterisk means all indices from 1 to n (inclusive). A +trailing asterisk means all indices from n to N (inclusive). A middle +asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector had been listed one by one. E.g. these 2 thermo_style commands @@ -372,6 +372,15 @@ creates a global vector with 6 values. c_myTemp[1] c_myTemp[2] c_myTemp[3] & c_myTemp[4] c_myTemp[5] c_myTemp[6] + +.. note:: + + For a vector-style variable, only the wildcard forms "\*n" or + "m\*n" are allowed. You must specify the upper bound, because + vector-style variable lengths are not determined until the variable + is evaluated. If n is specified larger than the vector length + turns out to be, zeroes are output for missing vector values. + ---------- The *c_ID* and *c_ID[I]* and *c_ID[I][J]* keywords allow global values diff --git a/examples/ELASTIC_T/BORN_MATRIX/Silicon/output.in b/examples/ELASTIC_T/BORN_MATRIX/Silicon/output.in index d6a89cff6a..05e007fab6 100644 --- a/examples/ELASTIC_T/BORN_MATRIX/Silicon/output.in +++ b/examples/ELASTIC_T/BORN_MATRIX/Silicon/output.in @@ -136,5 +136,6 @@ variable C46 equal v_F46+v_B[20] variable C56 equal v_F56+v_B[21] thermo ${nthermo} -thermo_style custom step temp pe press density f_avt f_avp f_avpe v_F11 v_F22 v_F33 v_F44 v_F55 v_F66 v_F12 v_F13 v_F23 v_B[1] v_B[2] v_B[3] v_B[4] v_B[5] v_B[6] v_B[7] v_B[8] v_B[12] +thermo_style custom step temp pe press density f_avt f_avp f_avpe v_F11 v_F22 v_F33 v_F44 v_F55 v_F66 v_F12 v_F13 v_F23 v_B[*8] v_B[12] + thermo_modify norm no diff --git a/src/utils.cpp b/src/utils.cpp index 3bc8c761c6..690bb10b2b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -19,11 +19,13 @@ #include "error.h" #include "fix.h" #include "fmt/chrono.h" +#include "input.h" #include "memory.h" #include "modify.h" #include "text_file_reader.h" #include "universe.h" #include "update.h" +#include "variable.h" #include #include @@ -631,7 +633,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // match compute, fix, or custom property array reference with a '*' wildcard // number range in the first pair of square brackets - if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]") || + if (strmatch(word, "^[cfv]_\\w+\\[\\d*\\*\\d*\\]") || strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) { // split off the compute/fix/property ID, the wildcard and trailing text @@ -669,7 +671,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod } } - // fix + // fix } else if (word[0] == 'f') { auto fix = lmp->modify->get_fix_by_id(id); @@ -692,8 +694,25 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod } } - // only match custom array reference with a '*' wildcard - // number range in the first pair of square brackets + // vector variable + + } else if (word[0] == 'v') { + int index = lmp->input->variable->find(id.c_str()); + + // check for global vector/array, peratom array, local array + + if (index >= 0) { + if (mode == 0 && lmp->input->variable->vectorstyle(index)) { + utils::bounds(file, line, wc, 1, MAXSMALLINT, nlo, nhi, lmp->error); + if (nhi < MAXSMALLINT) { + nmax = nhi; + expandflag = 1; + } + } + } + + // only match custom array reference with a '*' wildcard + // number range in the first pair of square brackets } else if ((word[0] == 'i') || (word[0] == 'd')) { int flag, cols; @@ -716,6 +735,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod if (expandflag) { // expand wild card string to nlo/nhi numbers + utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error); if (newarg + nhi - nlo + 1 > maxarg) { From 65978c33b604eb5a4a21a5847a4ca5a9ec2b2e86 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 25 Apr 2022 16:06:52 -0600 Subject: [PATCH 07/16] 2 more doc pages --- doc/src/fix_ave_histo.rst | 10 +++++----- doc/src/fix_ave_time.rst | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/src/fix_ave_histo.rst b/doc/src/fix_ave_histo.rst index 3cd1bdf4db..5d36a372c3 100644 --- a/doc/src/fix_ave_histo.rst +++ b/doc/src/fix_ave_histo.rst @@ -144,8 +144,9 @@ asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector or columns of the array had been listed one by one. E.g. these -2 fix ave/histo commands are equivalent, since the :doc:`compute com/chunk ` command creates a global array with -3 columns: +2 fix ave/histo commands are equivalent, since the :doc:`compute +com/chunk ` command creates a global array with 3 +columns: .. code-block:: LAMMPS @@ -158,9 +159,8 @@ vector or columns of the array had been listed one by one. E.g. these For a vector-style variable, only the wildcard forms "\*n" or "m\*n" are allowed. You must specify the upper bound, because vector-style variable lengths are not determined until the variable - is evaluated. If n is specified larger than the vector length"\*n" - or "n\*" or "m\*n". turns out to be, zeroes are output for missing - vector values. + is evaluated. If n is specified larger than the vector length + turns out to be, zeroes are output for missing vector values. ---------- diff --git a/doc/src/fix_ave_time.rst b/doc/src/fix_ave_time.rst index f2d634ca75..2836e11fd0 100644 --- a/doc/src/fix_ave_time.rst +++ b/doc/src/fix_ave_time.rst @@ -127,8 +127,9 @@ asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector or columns of the array had been listed one by one. E.g. these -2 fix ave/time commands are equivalent, since the :doc:`compute rdf ` command creates, in this case, a global array -with 3 columns, each of length 50: +2 fix ave/time commands are equivalent, since the :doc:`compute rdf +` command creates, in this case, a global array with 3 +columns, each of length 50: .. code-block:: LAMMPS @@ -141,9 +142,8 @@ with 3 columns, each of length 50: For a vector-style variable, only the wildcard forms "\*n" or "m\*n" are allowed. You must specify the upper bound, because vector-style variable lengths are not determined until the variable - is evaluated. If n is specified larger than the vector length"\*n" - or "n\*" or "m\*n". turns out to be, zeroes are output for missing - vector values. + is evaluated. If n is specified larger than the vector length + turns out to be, zeroes are output for missing vector values. ---------- @@ -180,9 +180,12 @@ asterisk to effectively specify multiple values. Note that there is a :doc:`compute reduce ` command which can sum per-atom quantities into a global scalar or vector which can thus be accessed by fix ave/time. Or it can be a compute defined -not in your input script, but by :doc:`thermodynamic output ` or other fixes such as :doc:`fix nvt ` or :doc:`fix temp/rescale `. See -the doc pages for these commands which give the IDs of these computes. -Users can also write code for their own compute styles and :doc:`add them to LAMMPS `. +not in your input script, but by :doc:`thermodynamic output +` or other fixes such as :doc:`fix nvt ` or +:doc:`fix temp/rescale `. See the doc pages for +these commands which give the IDs of these computes. Users can also +write code for their own compute styles and :doc:`add them to LAMMPS +`. If a value begins with "f\_", a fix ID must follow which has been previously defined in the input script. If *mode* = scalar, then if From e7a9073ccda9f821b5f4d27fe75decf8bb3a32d5 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 25 Apr 2022 17:01:15 -0600 Subject: [PATCH 08/16] remove discussion of mode --- doc/src/thermo_style.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/src/thermo_style.rst b/doc/src/thermo_style.rst index 38f832ba98..a5a8935dc4 100644 --- a/doc/src/thermo_style.rst +++ b/doc/src/thermo_style.rst @@ -352,10 +352,9 @@ For output values from a compute or fix or variable, the bracketed index I used to index a vector, as in *c_ID[I]* or *f_ID[I]* or *v_name[I]*, can be specified using a wildcard asterisk with the index to effectively specify multiple values. This takes the form "\*" or -"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = -scalar) or the number of columns in the array (for *mode* = vector), -then an asterisk with no numeric values means all indices from 1 to N. -A leading asterisk means all indices from 1 to n (inclusive). A +"\*n" or "n\*" or "m\*n". If N = the size of the vector, then an +asterisk with no numeric values means all indices from 1 to N. A +leading asterisk means all indices from 1 to n (inclusive). A trailing asterisk means all indices from n to N (inclusive). A middle asterisk means all indices from m to n (inclusive). From fdb7dfdea7a95da2967bbe2bf118141d249ceb03 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 25 Apr 2022 17:04:04 -0600 Subject: [PATCH 09/16] also remove mode from fix ave/correlate --- doc/src/fix_ave_correlate.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/doc/src/fix_ave_correlate.rst b/doc/src/fix_ave_correlate.rst index d2e9599374..6653b91d91 100644 --- a/doc/src/fix_ave_correlate.rst +++ b/doc/src/fix_ave_correlate.rst @@ -110,17 +110,16 @@ be used, since they produce per-atom values. For input values from a compute or fix or variable , the bracketed index I can be specified using a wildcard asterisk with the index to effectively specify multiple values. This takes the form "\*" or -"\*n" or "n\*" or "m\*n". If N = the size of the vector (for *mode* = -scalar) or the number of columns in the array (for *mode* = vector), -then an asterisk with no numeric values means all indices from 1 to N. -A leading asterisk means all indices from 1 to n (inclusive). A +"\*n" or "n\*" or "m\*n". If N = the size of the vector, then an +asterisk with no numeric values means all indices from 1 to N. A +leading asterisk means all indices from 1 to n (inclusive). A trailing asterisk means all indices from n to N (inclusive). A middle asterisk means all indices from m to n (inclusive). Using a wildcard is the same as if the individual elements of the vector had been listed one by one. E.g. these 2 fix ave/correlate -commands are equivalent, since the :doc:`compute pressure ` command creates a global vector with 6 -values. +commands are equivalent, since the :doc:`compute pressure +` command creates a global vector with 6 values. .. code-block:: LAMMPS From ba02d90bf1796e549b3f2cba1079ded26ecaa6b6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 09:29:57 -0400 Subject: [PATCH 10/16] add test for new errorurl() utility function --- unittest/utils/test_utils.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 900ce6814c..5967ac087a 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -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__) From 4691ff06b5a4463ea230ff2a01d9c1af9025e436 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 09:30:10 -0400 Subject: [PATCH 11/16] format --- unittest/cplusplus/test_error_class.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/unittest/cplusplus/test_error_class.cpp b/unittest/cplusplus/test_error_class.cpp index 27318646be..a94e6a3e41 100644 --- a/unittest/cplusplus/test_error_class.cpp +++ b/unittest/cplusplus/test_error_class.cpp @@ -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")) { From 837f9040d848738df2ba8ebd31c57b4f3d22f434 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 09:30:34 -0400 Subject: [PATCH 12/16] add tests for advanced utility functions that require a LAMMPS instance --- unittest/cplusplus/CMakeLists.txt | 4 + unittest/cplusplus/test_advanced_utils.cpp | 194 +++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 unittest/cplusplus/test_advanced_utils.cpp diff --git a/unittest/cplusplus/CMakeLists.txt b/unittest/cplusplus/CMakeLists.txt index 88f082a204..9199e20792 100644 --- a/unittest/cplusplus/CMakeLists.txt +++ b/unittest/cplusplus/CMakeLists.txt @@ -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) diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp new file mode 100644 index 0000000000..3e5a846914 --- /dev/null +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -0,0 +1,194 @@ +// unit tests for utils:: functions requiring a LAMMPS + +#include "error.h" +#include "input.h" +#include "lammps.h" +#include "utils.h" + +#include "../testing/core.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + +// 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; + } +}; + +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); +}; + +TEST_F(Advanced_utils, bounds_case1) +{ + int nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 9); + ASSERT_EQ(nhi, 9); + utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 1); + ASSERT_EQ(nhi, 1); + utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +TEST_F(Advanced_utils, bounds_case2) +{ + int nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 0); + ASSERT_EQ(nhi, 10); + utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -10); + ASSERT_EQ(nhi, 5); + utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +TEST_F(Advanced_utils, bounds_case3) +{ + int nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 2); + ASSERT_EQ(nhi, 10); + utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 3); + ASSERT_EQ(nhi, 5); + utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +TEST_F(Advanced_utils, boundsbig_case1) +{ + bigint nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 9); + ASSERT_EQ(nhi, 9); + utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 1); + ASSERT_EQ(nhi, 1); + utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); + utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +TEST_F(Advanced_utils, boundsbig_case2) +{ + bigint nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 0); + ASSERT_EQ(nhi, 10); + utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -10); + ASSERT_EQ(nhi, 5); + utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +TEST_F(Advanced_utils, boundsbig_case3) +{ + bigint nlo, nhi; + + nlo = nhi = -1; + utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 2); + ASSERT_EQ(nhi, 10); + utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, 3); + ASSERT_EQ(nhi, 5); + utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr); + ASSERT_EQ(nlo, -1); + ASSERT_EQ(nhi, -1); +} + +} // 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 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; +} From 7663fc62563f47071ac985052ebef36d1a1c2ba6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 11:08:31 -0400 Subject: [PATCH 13/16] correctly use "type" to detect executables/scripts --- src/ADIOS/Install.sh | 6 +++--- src/ML-IAP/Install.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ADIOS/Install.sh b/src/ADIOS/Install.sh index ddca8c6efe..bd0acb1414 100644 --- a/src/ADIOS/Install.sh +++ b/src/ADIOS/Install.sh @@ -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" \ diff --git a/src/ML-IAP/Install.sh b/src/ML-IAP/Install.sh index 753dfae358..3a1a7493aa 100755 --- a/src/ML-IAP/Install.sh +++ b/src/ML-IAP/Install.sh @@ -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 From 7eb6c2652f43711da97ad0da5ca3861b02bb90ea Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 16:16:44 -0400 Subject: [PATCH 14/16] update advanced utils tests. include test for expand args --- unittest/cplusplus/test_advanced_utils.cpp | 213 +++++++++++---------- 1 file changed, 113 insertions(+), 100 deletions(-) diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp index 3e5a846914..8c9bb6ea19 100644 --- a/unittest/cplusplus/test_advanced_utils.cpp +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -3,6 +3,7 @@ #include "error.h" #include "input.h" #include "lammps.h" +#include "memory.h" #include "utils.h" #include "../testing/core.h" @@ -26,6 +27,25 @@ protected: 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) @@ -52,118 +72,111 @@ TEST_F(Advanced_utils, logmesg) EXPECT_EQ(output, "test message from test " + testbinary); }; -TEST_F(Advanced_utils, bounds_case1) +// death tests only. the other cases are tested in the basic utils unit tester +TEST_F(Advanced_utils, bounds_int_fail) { int nlo, nhi; - - nlo = nhi = -1; - utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 9); - ASSERT_EQ(nhi, 9); - utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 1); - ASSERT_EQ(nhi, 1); - utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); + 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_case2) -{ - int nlo, nhi; - - nlo = nhi = -1; - utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 0); - ASSERT_EQ(nhi, 10); - utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -10); - ASSERT_EQ(nhi, 5); - utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); -} - -TEST_F(Advanced_utils, bounds_case3) -{ - int nlo, nhi; - - nlo = nhi = -1; - utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 2); - ASSERT_EQ(nhi, 10); - utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 3); - ASSERT_EQ(nhi, 5); - utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); -} - -TEST_F(Advanced_utils, boundsbig_case1) +TEST_F(Advanced_utils, bounds_bigint_fail) { bigint nlo, nhi; - - nlo = nhi = -1; - utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 9); - ASSERT_EQ(nhi, 9); - utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 1); - ASSERT_EQ(nhi, 1); - utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); - utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); + 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, boundsbig_case2) +TEST_F(Advanced_utils, expand_args) { - bigint nlo, nhi; + 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(); - nlo = nhi = -1; - utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 0); - ASSERT_EQ(nhi, 10); - utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -10); - ASSERT_EQ(nhi, 5); - utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); -} + char **args, **earg; + args = new char *[9]; + args[0] = utils::strdup("v_step"); + args[1] = utils::strdup("c_temp"); + args[2] = utils::strdup("f_1[*]"); + args[3] = utils::strdup("c_temp[*]"); + args[4] = utils::strdup("v_temp[*]"); + 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[*][*]"); -TEST_F(Advanced_utils, boundsbig_case3) -{ - bigint nlo, nhi; + auto narg = utils::expand_args(FLERR, 9, args, 0, earg, lmp); + EXPECT_EQ(narg, 16); + EXPECT_STREQ(earg[0], "v_step"); + EXPECT_STREQ(earg[1], "c_temp"); + EXPECT_STREQ(earg[2], "f_1[1]"); + EXPECT_STREQ(earg[3], "f_1[2]"); + EXPECT_STREQ(earg[4], "f_1[3]"); + EXPECT_STREQ(earg[5], "c_temp[1]"); + EXPECT_STREQ(earg[6], "c_temp[2]"); + EXPECT_STREQ(earg[7], "c_temp[3]"); + EXPECT_STREQ(earg[8], "c_temp[4]"); + EXPECT_STREQ(earg[9], "c_temp[5]"); + EXPECT_STREQ(earg[10], "c_temp[6]"); + EXPECT_STREQ(earg[11], "v_temp[*]"); + EXPECT_STREQ(earg[12], "c_rdf[*]"); + EXPECT_STREQ(earg[13], "c_rdf[1][*]"); + EXPECT_STREQ(earg[14], "c_rdf[*][2]"); + EXPECT_STREQ(earg[15], "c_rdf[*][*]"); - nlo = nhi = -1; - utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 2); - ASSERT_EQ(nhi, 10); - utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, 3); - ASSERT_EQ(nhi, 5); - utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr); - ASSERT_EQ(nlo, -1); - ASSERT_EQ(nhi, -1); + for (int i = 0; i < narg; ++i) + delete[] earg[i]; + lmp->memory->sfree(earg); + + narg = utils::expand_args(FLERR, 9, args, 1, earg, lmp); + EXPECT_EQ(narg, 9); + EXPECT_NE(args, earg); + EXPECT_STREQ(earg[0], "v_step"); + EXPECT_STREQ(earg[1], "c_temp"); + EXPECT_STREQ(earg[2], "f_1[*]"); + EXPECT_STREQ(earg[3], "c_temp[*]"); + EXPECT_STREQ(earg[4], "v_temp[*]"); + 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 < 9; ++i) + delete[] args[i]; + delete[] args; + for (int i = 0; i < narg; ++i) + delete[] earg[i]; + lmp->memory->sfree(earg); } } // namespace LAMMPS_NS From 64fff417c37e40c6fc1828f22a40d1acaf0dd995 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 17:25:27 -0400 Subject: [PATCH 15/16] test more bound variants --- unittest/cplusplus/test_advanced_utils.cpp | 49 ++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp index 8c9bb6ea19..ee39f67f34 100644 --- a/unittest/cplusplus/test_advanced_utils.cpp +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -124,54 +124,51 @@ TEST_F(Advanced_utils, expand_args) auto output = END_CAPTURE_OUTPUT(); char **args, **earg; - args = new char *[9]; + 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[*]"); - args[3] = utils::strdup("c_temp[*]"); - args[4] = utils::strdup("v_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, 9, args, 0, earg, lmp); - EXPECT_EQ(narg, 16); + 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[1]"); - EXPECT_STREQ(earg[3], "f_1[2]"); - EXPECT_STREQ(earg[4], "f_1[3]"); - EXPECT_STREQ(earg[5], "c_temp[1]"); - EXPECT_STREQ(earg[6], "c_temp[2]"); - EXPECT_STREQ(earg[7], "c_temp[3]"); - EXPECT_STREQ(earg[8], "c_temp[4]"); - EXPECT_STREQ(earg[9], "c_temp[5]"); - EXPECT_STREQ(earg[10], "c_temp[6]"); - EXPECT_STREQ(earg[11], "v_temp[*]"); - EXPECT_STREQ(earg[12], "c_rdf[*]"); - EXPECT_STREQ(earg[13], "c_rdf[1][*]"); - EXPECT_STREQ(earg[14], "c_rdf[*][2]"); - EXPECT_STREQ(earg[15], "c_rdf[*][*]"); + 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, 9, args, 1, earg, lmp); - EXPECT_EQ(narg, 9); + 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[*]"); - EXPECT_STREQ(earg[3], "c_temp[*]"); - EXPECT_STREQ(earg[4], "v_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 < 9; ++i) + for (int i = 0; i < oarg; ++i) delete[] args[i]; delete[] args; for (int i = 0; i < narg; ++i) From d8e98cb99db77d4d3b33d610ce4a587ef0caef57 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 26 Apr 2022 17:53:47 -0400 Subject: [PATCH 16/16] make tests more complex and add vector variable expansion --- unittest/cplusplus/test_advanced_utils.cpp | 103 +++++++++++++++------ 1 file changed, 73 insertions(+), 30 deletions(-) diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp index ee39f67f34..46da2d5d4b 100644 --- a/unittest/cplusplus/test_advanced_utils.cpp +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -125,55 +125,98 @@ TEST_F(Advanced_utils, expand_args) 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[*][*]"); + args = new char *[oarg]; + args[0] = utils::strdup("v_step"); + args[1] = utils::strdup("c_temp"); + args[2] = utils::strdup("f_1[*]"); + args[3] = utils::strdup("c_temp[2*4]"); + args[4] = utils::strdup("v_temp[*4]"); + args[5] = utils::strdup("c_gofr[3*]"); + args[6] = utils::strdup("c_gofr[1][*]"); + args[7] = utils::strdup("c_gofr[*2][2]"); + args[8] = utils::strdup("c_gofr[*][*]"); auto narg = utils::expand_args(FLERR, oarg, args, 0, earg, lmp); - EXPECT_EQ(narg, 12); + EXPECT_EQ(narg, 16); 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[*][*]"); + EXPECT_STREQ(earg[2], "f_1[1]"); + EXPECT_STREQ(earg[3], "f_1[2]"); + EXPECT_STREQ(earg[4], "f_1[3]"); + EXPECT_STREQ(earg[5], "c_temp[2]"); + EXPECT_STREQ(earg[6], "c_temp[3]"); + EXPECT_STREQ(earg[7], "c_temp[4]"); + EXPECT_STREQ(earg[8], "v_temp[1]"); + EXPECT_STREQ(earg[9], "v_temp[2]"); + EXPECT_STREQ(earg[10], "v_temp[3]"); + EXPECT_STREQ(earg[11], "v_temp[4]"); + EXPECT_STREQ(earg[12], "c_gofr[3*]"); + EXPECT_STREQ(earg[13], "c_gofr[1][*]"); + EXPECT_STREQ(earg[14], "c_gofr[*2][2]"); + EXPECT_STREQ(earg[15], "c_gofr[*][*]"); 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_EQ(narg, 16); 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[2], "f_1[*]"); 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[*][*]"); + EXPECT_STREQ(earg[5], "c_gofr[3]"); + EXPECT_STREQ(earg[6], "c_gofr[4]"); + EXPECT_STREQ(earg[7], "c_gofr[5]"); + EXPECT_STREQ(earg[8], "c_gofr[1][*]"); + EXPECT_STREQ(earg[9], "c_gofr[1][2]"); + EXPECT_STREQ(earg[10], "c_gofr[2][2]"); + EXPECT_STREQ(earg[11], "c_gofr[1][*]"); + EXPECT_STREQ(earg[12], "c_gofr[2][*]"); + EXPECT_STREQ(earg[13], "c_gofr[3][*]"); + EXPECT_STREQ(earg[14], "c_gofr[4][*]"); + EXPECT_STREQ(earg[15], "c_gofr[5][*]"); - 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); + + args[3][9] = '9'; + TEST_FAILURE("ERROR: Numeric index 9 is out of bounds \\(1-6\\).*", + utils::expand_args(FLERR, oarg, args, 0, earg, lmp);); + + args[3][9] = '4'; + args[5][7] = '9'; + TEST_FAILURE("ERROR: Numeric index 9 is out of bounds \\(1-5\\).*", + utils::expand_args(FLERR, oarg, args, 1, earg, lmp);); + + args[5][7] = '3'; + delete[] args[4]; + args[4] = utils::strdup("v_temp[2*]"); + narg = utils::expand_args(FLERR, oarg, args, 0, earg, lmp); + EXPECT_EQ(narg, 13); + EXPECT_STREQ(earg[0], "v_step"); + EXPECT_STREQ(earg[1], "c_temp"); + EXPECT_STREQ(earg[2], "f_1[1]"); + EXPECT_STREQ(earg[3], "f_1[2]"); + EXPECT_STREQ(earg[4], "f_1[3]"); + EXPECT_STREQ(earg[5], "c_temp[2]"); + EXPECT_STREQ(earg[6], "c_temp[3]"); + EXPECT_STREQ(earg[7], "c_temp[4]"); + EXPECT_STREQ(earg[8], "v_temp[2*]"); + EXPECT_STREQ(earg[9], "c_gofr[3*]"); + EXPECT_STREQ(earg[10], "c_gofr[1][*]"); + EXPECT_STREQ(earg[11], "c_gofr[*2][2]"); + EXPECT_STREQ(earg[12], "c_gofr[*][*]"); + + for (int i = 0; i < narg; ++i) + delete[] earg[i]; + lmp->memory->sfree(earg); + for (int i = 0; i < oarg; ++i) + delete[] args[i]; + delete[] args; } } // namespace LAMMPS_NS