From c0bae49956c8c0a94093533392ddbe5ee2900958 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Feb 2022 07:28:59 -0500 Subject: [PATCH 1/8] simplify with new API and address coverity scan warning --- src/EXTRA-FIX/fix_numdiff.cpp | 7 +++---- src/EXTRA-FIX/fix_numdiff_virial.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/EXTRA-FIX/fix_numdiff.cpp b/src/EXTRA-FIX/fix_numdiff.cpp index 97067d316b..7265ec0b79 100644 --- a/src/EXTRA-FIX/fix_numdiff.cpp +++ b/src/EXTRA-FIX/fix_numdiff.cpp @@ -41,7 +41,7 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixNumDiff::FixNumDiff(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), temp_f(nullptr) + Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), numdiff_forces(nullptr), temp_x(nullptr), temp_f(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix numdiff command"); @@ -109,9 +109,8 @@ void FixNumDiff::init() // check for PE compute - int icompute = modify->find_compute(id_pe); - if (icompute < 0) error->all(FLERR, "Compute ID for fix numdiff does not exist"); - pe = modify->compute[icompute]; + pe = modify->get_compute_by_id(id_pe); + if (!pe) error->all(FLERR, "PE compute ID for fix numdiff does not exist"); if (force->pair && force->pair->compute_flag) pair_compute_flag = 1; diff --git a/src/EXTRA-FIX/fix_numdiff_virial.cpp b/src/EXTRA-FIX/fix_numdiff_virial.cpp index ac7654e166..2cb144d889 100644 --- a/src/EXTRA-FIX/fix_numdiff_virial.cpp +++ b/src/EXTRA-FIX/fix_numdiff_virial.cpp @@ -41,7 +41,7 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ FixNumDiffVirial::FixNumDiffVirial(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg), id_pe(nullptr), temp_x(nullptr), temp_f(nullptr) + Fix(lmp, narg, arg), id_pe(nullptr), pe(nullptr), temp_x(nullptr), temp_f(nullptr) { if (narg < 5) error->all(FLERR, "Illegal fix numdiff/virial command"); if (igroup) error->all(FLERR, "Compute numdiff/virial must use group all"); @@ -121,9 +121,8 @@ void FixNumDiffVirial::init() { // check for PE compute - int icompute = modify->find_compute(id_pe); - if (icompute < 0) error->all(FLERR, "Compute ID for fix numdiff does not exist"); - pe = modify->compute[icompute]; + pe = modify->get_compute_by_id(id_pe); + if (!pe) error->all(FLERR, "PE compute ID for fix numdiff/virial does not exist"); if (force->pair && force->pair->compute_flag) pair_compute_flag = 1; From 59def25eb6e26eb63f1eb2cfff042078a7c7a50f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 Feb 2022 16:08:43 -0500 Subject: [PATCH 2/8] tweak test epsilon for portability --- unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml index d1bed9430b..eaf9bf1a7c 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml @@ -1,7 +1,7 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:49 2021 -epsilon: 1e-13 +epsilon: 5e-12 prerequisites: ! | atom full pair lj/cut/tip4p/long From 8209ae95136996d89544b6778e2bf2814e68908b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 Feb 2022 17:01:13 -0500 Subject: [PATCH 3/8] fix optional argument parsing bug --- src/PHONON/third_order.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PHONON/third_order.cpp b/src/PHONON/third_order.cpp index 7bc03aaf6f..3c196d3731 100644 --- a/src/PHONON/third_order.cpp +++ b/src/PHONON/third_order.cpp @@ -232,6 +232,7 @@ void ThirdOrder::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR, "Illegal third_order command"); filename = arg[iarg + 1]; file_flag = 1; + iarg += 2; } else if (strcmp(arg[iarg],"fold") == 0) { if (iarg+2 > narg) error->all(FLERR, "Illegal Third Order command"); if (strcmp(arg[iarg+1],"yes") == 0) { From 2548c498767cdd2fa1f27951544c4f74658748d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 Feb 2022 17:01:47 -0500 Subject: [PATCH 4/8] use fmtlib for formatted output --- src/PHONON/dynamical_matrix.cpp | 9 ++++---- src/PHONON/third_order.cpp | 41 +++++++++++---------------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/PHONON/dynamical_matrix.cpp b/src/PHONON/dynamical_matrix.cpp index 3a596bfd05..11dc5625b9 100644 --- a/src/PHONON/dynamical_matrix.cpp +++ b/src/PHONON/dynamical_matrix.cpp @@ -282,10 +282,11 @@ void DynamicalMatrix::calculateMatrix() dynmat_clear(dynmat); if (me == 0 && screen) { - fprintf(screen,"Calculating Dynamical Matrix ...\n"); - fprintf(screen," Total # of atoms = " BIGINT_FORMAT "\n", natoms); - fprintf(screen," Atoms in group = " BIGINT_FORMAT "\n", gcount); - fprintf(screen," Total dynamical matrix elements = " BIGINT_FORMAT "\n", (dynlen*dynlen) ); + fputs("Calculating Dynamical Matrix ...\n", screen); + fmt::print(screen," Total # of atoms = {}\n" + " Atoms in group = {}\n" + " Total dynamical matrix elements = {}\n", + natoms, gcount, dynlen*dynlen); } // emit dynlen rows of dimalpha*dynlen*dimbeta elements diff --git a/src/PHONON/third_order.cpp b/src/PHONON/third_order.cpp index 3c196d3731..0f70a591d8 100644 --- a/src/PHONON/third_order.cpp +++ b/src/PHONON/third_order.cpp @@ -301,11 +301,11 @@ void ThirdOrder::calculateMatrix() getNeighbortags(); if (comm->me == 0 && screen) { - fprintf(screen, "Calculating Third Order ...\n"); - fprintf(screen, " Total # of atoms = " BIGINT_FORMAT "\n", natoms); - fprintf(screen, " Atoms in group = " BIGINT_FORMAT "\n", gcount); - fprintf(screen, " Total third order elements = " - BIGINT_FORMAT "\n", (dynlen * dynlen * dynlen)); + fputs("Calculating Third Order ...\n", screen); + fmt::print(screen," Total # of atoms = {}\n" + " Atoms in group = {}\n" + " Total third order elements = {}\n", + natoms, gcount, dynlen*dynlen*dynlen); } update->nsteps = 0; @@ -437,31 +437,19 @@ void ThirdOrder::writeMatrix(double *dynmat, bigint i, int a, bigint j, int b) clearerr(fp); if (folded){ for (int k = 0; k < atom->natoms; k++){ - norm = square(dynmat[k*3])+ - square(dynmat[k*3+1])+ - square(dynmat[k*3+2]); + norm = square(dynmat[k*3])+square(dynmat[k*3+1])+square(dynmat[k*3+2]); if (norm > 1.0e-16) - fprintf(fp, - BIGINT_FORMAT " %d " BIGINT_FORMAT " %d " BIGINT_FORMAT - " %7.8f %7.8f %7.8f\n", - i+1, a + 1, j+1, b + 1, k+1, - dynmat[k*3] * conversion, - dynmat[k*3+1] * conversion, - dynmat[k*3+2] * conversion); + fmt::print(fp, "{} {} {} {} {} {:17.8f} {:17.8f} {:17.8f}\n", + i+1, a+1, j+1, b+1, k+1, dynmat[k*3] * conversion, + dynmat[k*3+1] * conversion, dynmat[k*3+2] * conversion); } } else { for (int k = 0; k < gcount; k++){ - norm = square(dynmat[k*3])+ - square(dynmat[k*3+1])+ - square(dynmat[k*3+2]); + norm = square(dynmat[k*3])+square(dynmat[k*3+1])+square(dynmat[k*3+2]); if (norm > 1.0e-16) - fprintf(fp, - BIGINT_FORMAT " %d " BIGINT_FORMAT " %d " BIGINT_FORMAT - " %7.8f %7.8f %7.8f\n", - i+1, a + 1, j+1, b + 1, groupmap[k]+1, - dynmat[k*3] * conversion, - dynmat[k*3+1] * conversion, - dynmat[k*3+2] * conversion); + fmt::print(fp, "{} {} {} {} {} {:17.8f} {:17.8f} {:17.8f}\n", + i+1, a+1, j+1, b+1, groupmap[k]+1, dynmat[k*3] * conversion, + dynmat[k*3+1] * conversion, dynmat[k*3+2] * conversion); } } } else if (binaryflag && fp) { @@ -673,8 +661,7 @@ void ThirdOrder::create_groupmap() } //combine subgroup maps into total temporary groupmap - MPI_Allgatherv(sub_groupmap,gid,MPI_LMP_BIGINT, - temp_groupmap,recv,displs,MPI_LMP_BIGINT,world); + MPI_Allgatherv(sub_groupmap,gid,MPI_LMP_BIGINT,temp_groupmap,recv,displs,MPI_LMP_BIGINT,world); std::sort(temp_groupmap,temp_groupmap+gcount); //populate member groupmap based on temp groupmap From 044ada9f2b84eee61f10e72548c57b6ab9e6f346 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 7 Feb 2022 16:46:32 -0500 Subject: [PATCH 5/8] update googletest library to current snapshot --- unittest/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index a310b82c07..b5843f0735 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -5,8 +5,8 @@ ######################################## # download and build googletest framework message(STATUS "Downloading and building googletest framework") -set(GTEST_URL "https://github.com/google/googletest/archive/release-1.11.0.tar.gz" CACHE STRING "URL of googletest source") -set(GTEST_MD5 "e8a8df240b6938bb6384155d4c37d937" CACHE STRING "MD5 sum for googletest source") +set(GTEST_URL "https://github.com/google/googletest/archive/43efa0a4efd40c78b9210d15373112081899a97c.tar.gz" CACHE STRING "URL of googletest source") +set(GTEST_MD5 "0259ff833c03cdbbedda4e5d02fbc6bd" CACHE STRING "MD5 sum for googletest source") mark_as_advanced(GTEST_URL) mark_as_advanced(GTEST_MD5) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) From 8e2581042eebcc2559a869924ccfc52da812a48d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 7 Feb 2022 20:30:36 -0500 Subject: [PATCH 6/8] remove unused local variables --- src/CG-DNA/pair_oxdna2_coaxstk.cpp | 4 ++-- src/CG-DNA/pair_oxdna_coaxstk.cpp | 2 +- src/CG-DNA/pair_oxdna_excv.cpp | 2 +- src/CG-DNA/pair_oxdna_hbond.cpp | 4 ++-- src/CG-DNA/pair_oxdna_xstk.cpp | 4 ++-- src/CG-DNA/pair_oxrna2_xstk.cpp | 4 ++-- src/EXTRA-FIX/fix_numdiff_virial.cpp | 1 - 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/CG-DNA/pair_oxdna2_coaxstk.cpp b/src/CG-DNA/pair_oxdna2_coaxstk.cpp index 8b3609983b..1b71d84696 100644 --- a/src/CG-DNA/pair_oxdna2_coaxstk.cpp +++ b/src/CG-DNA/pair_oxdna2_coaxstk.cpp @@ -119,8 +119,8 @@ void PairOxdna2Coaxstk::compute(int eflag, int vflag) double rb_cs[3],rb_cst[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; diff --git a/src/CG-DNA/pair_oxdna_coaxstk.cpp b/src/CG-DNA/pair_oxdna_coaxstk.cpp index 49b25bb81b..6df434c012 100644 --- a/src/CG-DNA/pair_oxdna_coaxstk.cpp +++ b/src/CG-DNA/pair_oxdna_coaxstk.cpp @@ -130,7 +130,7 @@ void PairOxdnaCoaxstk::compute(int eflag, int vflag) double rb_cs[3],rb_cst[3]; // Cartesian unit vectors in lab frame double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; diff --git a/src/CG-DNA/pair_oxdna_excv.cpp b/src/CG-DNA/pair_oxdna_excv.cpp index ae5752028a..f47f92d63c 100644 --- a/src/CG-DNA/pair_oxdna_excv.cpp +++ b/src/CG-DNA/pair_oxdna_excv.cpp @@ -143,7 +143,7 @@ void PairOxdnaExcv::compute(int eflag, int vflag) AtomVecEllipsoid::Bonus *bonus = avec->bonus; int *ellipsoid = atom->ellipsoid; - int n,a,b,in,ia,ib,anum,bnum,atype,btype; + int a,b,in,ia,ib,anum,bnum,atype,btype; evdwl = 0.0; ev_init(eflag,vflag); diff --git a/src/CG-DNA/pair_oxdna_hbond.cpp b/src/CG-DNA/pair_oxdna_hbond.cpp index 3d2e803aa8..926e9207a0 100644 --- a/src/CG-DNA/pair_oxdna_hbond.cpp +++ b/src/CG-DNA/pair_oxdna_hbond.cpp @@ -149,8 +149,8 @@ void PairOxdnaHbond::compute(int eflag, int vflag) // vectors COM-h-bonding site in lab frame double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; diff --git a/src/CG-DNA/pair_oxdna_xstk.cpp b/src/CG-DNA/pair_oxdna_xstk.cpp index 61dc1a8100..ffaeacc137 100644 --- a/src/CG-DNA/pair_oxdna_xstk.cpp +++ b/src/CG-DNA/pair_oxdna_xstk.cpp @@ -126,8 +126,8 @@ void PairOxdnaXstk::compute(int eflag, int vflag) // vectors COM-h-bonding site in lab frame double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; diff --git a/src/CG-DNA/pair_oxrna2_xstk.cpp b/src/CG-DNA/pair_oxrna2_xstk.cpp index 1f069e6b2f..ee14103dca 100644 --- a/src/CG-DNA/pair_oxrna2_xstk.cpp +++ b/src/CG-DNA/pair_oxrna2_xstk.cpp @@ -121,8 +121,8 @@ void PairOxrna2Xstk::compute(int eflag, int vflag) double ra_chb[3],rb_chb[3]; // Cartesian unit vectors in lab frame - double ax[3],ay[3],az[3]; - double bx[3],by[3],bz[3]; + double ax[3],az[3]; + double bx[3],bz[3]; double **x = atom->x; double **f = atom->f; diff --git a/src/EXTRA-FIX/fix_numdiff_virial.cpp b/src/EXTRA-FIX/fix_numdiff_virial.cpp index 2cb144d889..f2226f4a59 100644 --- a/src/EXTRA-FIX/fix_numdiff_virial.cpp +++ b/src/EXTRA-FIX/fix_numdiff_virial.cpp @@ -209,7 +209,6 @@ void FixNumDiffVirial::calculate_virial() // loop over 6 strain directions // compute a finite difference force in each dimension - int flag, allflag; double nktv2p = force->nktv2p; double inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd); From 75727ed5af2a9bca1ab7879414bddd12a3132980 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 7 Feb 2022 20:52:12 -0500 Subject: [PATCH 7/8] comment out minimal run test outside of CMake/CTest --- .github/workflows/compile-msvc.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 75d531d9af..15ba770869 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -28,11 +28,11 @@ jobs: -D ENABLE_TESTING=on cmake --build build --config Release - - name: Run LAMMPS executable - shell: bash - run: | - ./build/Release/lmp.exe -h - ./build/Release/lmp.exe -in bench/in.lj +# - name: Run LAMMPS executable +# shell: bash +# run: | +# ./build/Release/lmp.exe -h +# ./build/Release/lmp.exe -in bench/in.lj - name: Run Unit Tests working-directory: build From 861195130ce24d6b8866505e1816081c627e1024 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 8 Feb 2022 10:06:30 -0500 Subject: [PATCH 8/8] incorporate suggested changes to github action from @rbberger --- .github/workflows/compile-msvc.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 15ba770869..35ec32e544 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -17,9 +17,15 @@ jobs: with: fetch-depth: 2 + - name: Select Python version + uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Building LAMMPS via CMake shell: bash run: | + python3 -m pip install numpy cmake -C cmake/presets/windows.cmake \ -D PKG_PYTHON=on \ -S cmake -B build \ @@ -28,11 +34,11 @@ jobs: -D ENABLE_TESTING=on cmake --build build --config Release -# - name: Run LAMMPS executable -# shell: bash -# run: | -# ./build/Release/lmp.exe -h -# ./build/Release/lmp.exe -in bench/in.lj + - name: Run LAMMPS executable + shell: bash + run: | + ./build/Release/lmp.exe -h + ./build/Release/lmp.exe -in bench/in.lj - name: Run Unit Tests working-directory: build