From f9eadacf6dc21a0bc6609d90e47bf65ad7aed855 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jan 2024 11:48:58 -0500 Subject: [PATCH 01/12] correct factor 2 force error for m=1 in angle style cosine/periodic --- src/EXTRA-MOLECULE/angle_cosine_periodic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-MOLECULE/angle_cosine_periodic.cpp b/src/EXTRA-MOLECULE/angle_cosine_periodic.cpp index 34a8e9d8e5..245a7b8d58 100644 --- a/src/EXTRA-MOLECULE/angle_cosine_periodic.cpp +++ b/src/EXTRA-MOLECULE/angle_cosine_periodic.cpp @@ -120,7 +120,7 @@ void AngleCosinePeriodic::compute(int eflag, int vflag) tn = 1.0; tn_1 = 1.0; tn_2 = 0.0; - un = 1.0; + un = (m==1) ? 2.0 : 1.0; un_1 = 2.0; un_2 = 0.0; From 6329d491dc4c81a7891606aa769726c67157085b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jan 2024 18:40:30 -0500 Subject: [PATCH 02/12] correct factor 2 force error for m=1 in angle style cosine/periodic --- src/OPENMP/angle_cosine_periodic_omp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OPENMP/angle_cosine_periodic_omp.cpp b/src/OPENMP/angle_cosine_periodic_omp.cpp index 43b3a54a47..48532c8f6c 100644 --- a/src/OPENMP/angle_cosine_periodic_omp.cpp +++ b/src/OPENMP/angle_cosine_periodic_omp.cpp @@ -140,7 +140,7 @@ void AngleCosinePeriodicOMP::eval(int nfrom, int nto, ThrData * const thr) tn = 1.0; tn_1 = 1.0; tn_2 = 0.0; - un = 1.0; + un = (m==1) ? 2.0 : 1.0; un_1 = 2.0; un_2 = 0.0; From 7a7492b7571e1b112a5224140e616c2ac94273e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jan 2024 18:42:16 -0500 Subject: [PATCH 03/12] cosmetic --- unittest/force-styles/test_main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unittest/force-styles/test_main.cpp b/unittest/force-styles/test_main.cpp index 80f1ca4e30..1cf428eee4 100644 --- a/unittest/force-styles/test_main.cpp +++ b/unittest/force-styles/test_main.cpp @@ -47,7 +47,7 @@ void EXPECT_STRESS(const std::string &name, double *stress, const stress_t &expe EXPECT_FP_LE_WITH_EPS(stress[3], expected_stress.xy, epsilon); EXPECT_FP_LE_WITH_EPS(stress[4], expected_stress.xz, epsilon); EXPECT_FP_LE_WITH_EPS(stress[5], expected_stress.yz, epsilon); - if (print_stats) std::cerr << name << " stats" << stats << std::endl; + if (print_stats) std::cerr << name << " stats: " << stats << std::endl; } void EXPECT_FORCES(const std::string &name, Atom *atom, const std::vector &f_ref, @@ -64,7 +64,7 @@ void EXPECT_FORCES(const std::string &name, Atom *atom, const std::vector &x_ref, @@ -81,7 +81,7 @@ void EXPECT_POSITIONS(const std::string &name, Atom *atom, const std::vector &v_ref, @@ -98,7 +98,7 @@ void EXPECT_VELOCITIES(const std::string &name, Atom *atom, const std::vector Date: Fri, 12 Jan 2024 18:43:19 -0500 Subject: [PATCH 04/12] update unit test data for corrected angle style cosine/periodic --- .../tests/angle-cosine_periodic.yaml | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/unittest/force-styles/tests/angle-cosine_periodic.yaml b/unittest/force-styles/tests/angle-cosine_periodic.yaml index 84d8ff1194..5c8227fcbd 100644 --- a/unittest/force-styles/tests/angle-cosine_periodic.yaml +++ b/unittest/force-styles/tests/angle-cosine_periodic.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 8 Apr 2021 -date_generated: Thu Apr 8 09:28:11 2021 +lammps_version: 21 Nov 2023 +date_generated: Fri Jan 12 18:39:55 2024 epsilon: 2.5e-13 prerequisites: ! | atom full @@ -10,77 +10,77 @@ post_commands: ! "" input_file: in.fourmol angle_style: cosine/periodic angle_coeff: ! | - 1 75.0 1 2 - 2 45.0 -1 2 + 1 75.0 1 1 + 2 45.0 1 2 3 50.0 -1 3 4 100.0 -1 4 -equilibrium: 4 3.141592653589793 1.5707963267948966 2.0943951023931957 2.356194490192345 +equilibrium: 4 3.141592653589793 3.141592653589793 2.0943951023931957 2.356194490192345 extract: ! "" natoms: 29 -init_energy: 605.3643061001458 -init_stress: ! |- - -1.7082420754402889e+01 -7.3281097507808681e+00 2.4410530505183818e+01 8.5827033671406951e+01 1.4260977966148616e+02 4.1579557432232576e+01 +init_energy: 1178.5476942873006 +init_stress: ! |2- + 2.7790958427902001e+02 -2.3729473006795436e+02 -4.0614854211065634e+01 2.9034222204142930e+02 1.4123449070173780e+02 2.0504975338277421e+02 init_forces: ! |2 1 7.9609486050127529e+00 -3.9274211736421961e+01 -3.8917410871887981e+01 2 4.6997439470662350e+00 3.8052682089524090e+01 3.0599010994189470e+01 - 3 -7.1532072701475698e+01 9.6873528247272844e+01 7.3410935137796983e+01 - 4 3.1784763224659116e+01 -4.4133218046130608e+01 -6.2234613362865147e+01 - 5 5.8817481848549889e+01 -2.5112568523390145e+01 3.9611729278121981e+00 - 6 -8.7258065964885336e+00 -4.2663580774228997e+01 -1.6819642012415606e+01 + 3 -4.4330179925982058e+01 -1.6514501437366098e+00 1.9894582317318523e+01 + 4 1.1465928779203908e+01 -7.1462736556935234e+00 -1.8983545733370338e+01 + 5 2.7634466780141157e+01 1.5504150132065057e+01 1.0078115065618357e+01 + 6 2.2512674572611367e+01 -5.4260358088923418e+01 -6.0646506351853276e+01 7 -1.5578858996464229e+01 1.3895348629116569e+01 -3.3939856789628062e+00 - 8 -1.6678237064738614e+01 -2.6557373913973738e+01 8.7708427797183326e+00 - 9 -9.4419020144376677e+00 1.3812152922900303e+01 -1.2280697239365450e+00 - 10 1.0844630504236606e+02 1.9274264686364820e+01 1.2594098114786526e+01 - 11 -1.1888648487599809e+01 1.7288532453781471e+00 1.8714004234488471e+00 - 12 9.7432958614920665e+01 1.1284647087939499e+02 -1.3445218835244805e+02 - 13 -2.2887258478933525e+01 -5.9815335453575649e+01 4.1237962971772127e+01 - 14 -4.6498844054867675e+01 -3.0251289808967520e+01 1.5556535565006259e+01 - 15 -5.3477741242848616e+01 -1.7885978453267143e+01 4.6284681424489207e+01 - 16 -7.3215663693592745e+01 1.7514552522777997e+01 7.4857846653898914e+00 + 8 -6.7011983808365656e+01 -2.4458090084467077e+01 1.7084632474743671e+02 + 9 9.4419020144376677e+00 -1.3812152922900303e+01 1.2280697239365450e+00 + 10 1.3360859023844577e+02 1.1499274633292617e+02 -1.0838863098947982e+02 + 11 1.1888648487599809e+01 -1.7288532453781471e+00 -1.8714004234488471e+00 + 12 2.9260930345940537e+01 -9.2146025429432186e+00 -8.5323421000107373e+01 + 13 -4.6656310032990458e+00 -1.2502935413462930e+01 1.4918864440944628e+01 + 14 -2.1383527724886850e+01 -9.3422692044635554e+00 7.5125645645164223e+00 + 15 -8.0644375221897171e+00 -2.6783296801963008e+00 6.9267625241565547e+00 + 16 -1.1822204683814408e+02 2.1928896047729104e+01 4.0247121672886962e+01 17 2.0782832048872386e+01 -2.8304296512773977e+01 1.5273484998106287e+01 - 18 1.6481336531704756e+00 1.7222946144801426e+01 -6.9896289164966490e+01 - 19 -2.0180190840279820e+01 -2.5140421523544326e+01 2.9933594625645306e+01 - 20 1.8532057187109345e+01 7.9174753787429015e+00 3.9962694539321184e+01 - 21 1.6243294930835876e+01 2.0333921382774719e+01 -6.0768622624445221e+01 - 22 -2.8924589352090472e+01 -1.9720769613680826e+01 2.1482552755004811e+01 - 23 1.2681294421254595e+01 -6.1315176909389102e-01 3.9286069869440411e+01 - 24 -1.5837796600466618e+01 6.1562453937228881e+01 -3.6651923703785549e+01 - 25 -1.2704181131223443e+01 -4.2563815285902912e+01 6.9610494863238124e+00 - 26 2.8541977731690061e+01 -1.8998638651325965e+01 2.9690874217461737e+01 - 27 -8.7971258084923178e+00 7.2217511410368814e+01 -2.4599681382405976e+01 - 28 -1.9235439225569891e+01 -4.3179911322776611e+01 1.0030656861974458e+00 - 29 2.8032565034062209e+01 -2.9037600087592210e+01 2.3596615696208531e+01 -run_energy: 603.8182365368202 -run_stress: ! |- - -1.6098625319219664e+01 -7.7961962067566510e+00 2.3894821525976329e+01 8.7036156470651477e+01 1.4262918929621054e+02 4.2523803236880880e+01 + 18 5.2071052608093424e+00 5.4414090328604708e+01 -2.2082998810309599e+02 + 19 -6.3757194500832497e+01 -7.9428522633699004e+01 9.4572049876109048e+01 + 20 5.8550089240023155e+01 2.5014432305094296e+01 1.2625793822698694e+02 + 21 5.6300281919954635e+01 7.0478650499360143e+01 -2.1062786831190908e+02 + 22 -1.0025444602684506e+02 -6.8353427900946826e+01 7.4459879083463136e+01 + 23 4.3954164106890424e+01 -2.1252225984133197e+00 1.3616798922844595e+02 + 24 -4.9480288140032329e+01 1.9233281221276744e+02 -1.1450757902121047e+02 + 25 -3.9690277556511717e+01 -1.3297745247110566e+02 2.1747642240220362e+01 + 26 8.9170565696544045e+01 -5.9355359741661772e+01 9.2759936780990117e+01 + 27 -2.6339504856062320e+01 2.1622670107205670e+02 -7.3653991239272059e+01 + 28 -5.7592895215991106e+01 -1.2928512206483205e+02 3.0032824456190355e+00 + 29 8.3932400072053426e+01 -8.6941579007224647e+01 7.0650708793653024e+01 +run_energy: 1174.6225600630123 +run_stress: ! |2- + 2.7658169122411005e+02 -2.3743377487623573e+02 -3.9147916347874407e+01 2.9007767114801470e+02 1.4053974438881829e+02 2.0434258995590761e+02 run_forces: ! |2 - 1 8.1036664069391833e+00 -3.9279459516104339e+01 -3.8959949625007155e+01 - 2 4.6488532958171156e+00 3.7987813821226069e+01 3.0712083303318757e+01 - 3 -7.1419656269516480e+01 9.7015207052323333e+01 7.3123837986656483e+01 - 4 3.1774739774255771e+01 -4.4324760214341296e+01 -6.1918121921961003e+01 - 5 5.8630133295649813e+01 -2.5003101567718115e+01 3.8957656941403842e+00 - 6 -8.6686835699933500e+00 -4.2717543793109854e+01 -1.6944132920021204e+01 - 7 -1.5605967450730276e+01 1.3924972058096937e+01 -3.4081311693274161e+00 - 8 -1.6735469954990947e+01 -2.6654949908594496e+01 8.9412902423392993e+00 - 9 -9.4705763934675620e+00 1.3861186924074314e+01 -1.2218212802251793e+00 - 10 1.0864309846473817e+02 1.9311615651482960e+01 1.2534898619395602e+01 - 11 -1.1889594908454491e+01 1.6849924892427488e+00 1.9039966312260486e+00 - 12 9.6643785665770423e+01 1.1329932305772147e+02 -1.3435213826206018e+02 - 13 -2.2815824864999897e+01 -5.9701629573330088e+01 4.1148977584672039e+01 - 14 -4.6226658006998740e+01 -3.0469540424436548e+01 1.5534272011399247e+01 - 15 -5.3141801628038777e+01 -1.8156497866651446e+01 4.6272398149175629e+01 - 16 -7.3254211788300807e+01 1.7569251761827239e+01 7.4522974142679850e+00 - 17 2.0784167932320894e+01 -2.8346879951708846e+01 1.5284477542010659e+01 - 18 1.7456021018344252e+00 1.7528557172698406e+01 -7.0852460721917453e+01 - 19 -2.0389936120749365e+01 -2.5462340563923114e+01 3.0421727677614534e+01 - 20 1.8644334018914940e+01 7.9337833912247095e+00 4.0430733044302912e+01 - 21 1.6517268317097550e+01 2.0531536618559141e+01 -6.1717967915716365e+01 - 22 -2.9293957935776255e+01 -1.9905577364456363e+01 2.1870035659045151e+01 - 23 1.2776689618678706e+01 -6.2595925410277875e-01 3.9847932256671214e+01 - 24 -1.6067082221526842e+01 6.2373469754139357e+01 -3.7096821397423525e+01 - 25 -1.2753486814048248e+01 -4.3101082367336026e+01 7.0662489242667057e+00 - 26 2.8820569035575090e+01 -1.9272387386803331e+01 3.0030572473156820e+01 - 27 -8.9233162938210242e+00 7.2669056612963558e+01 -2.4610439704365813e+01 - 28 -1.9256705992379011e+01 -4.3442840232212284e+01 9.5666525994413210e-01 - 29 2.8180022286200035e+01 -2.9226216380751275e+01 2.3653774444421682e+01 + 1 8.0595702750384035e+00 -3.9275884134753326e+01 -3.8921834417294036e+01 + 2 4.6450877605699539e+00 3.7989319483282912e+01 3.0709930248716290e+01 + 3 -4.4176357886610745e+01 -1.3121510542286003e+00 1.9849684676752698e+01 + 4 1.1432955202502885e+01 -7.3978491141098957e+00 -1.8963452056001909e+01 + 5 2.7565769767176914e+01 1.5533965780817836e+01 1.0064393045239932e+01 + 6 2.2440837721485856e+01 -5.4307979505823312e+01 -6.0734450726614625e+01 + 7 -1.5580688823052480e+01 1.3904189059068386e+01 -3.4017896378595758e+00 + 8 -6.6989876135866879e+01 -2.4455457095150752e+01 1.7071695622632274e+02 + 9 9.4762227087055635e+00 -1.3904425552883753e+01 1.2252549039361496e+00 + 10 1.3329492642527092e+02 1.1514887273699682e+02 -1.0807688660290995e+02 + 11 1.1927511834955308e+01 -1.7182396158290132e+00 -1.8914765821083073e+00 + 12 2.9230443011207992e+01 -9.0747074093425084e+00 -8.5406656692466896e+01 + 13 -4.6010476121847610e+00 -1.2371262892106342e+01 1.4758380429325644e+01 + 14 -2.1309655373546295e+01 -9.6560166053345498e+00 7.4826455796077642e+00 + 15 -8.0586553706859778e+00 -2.8089895416921884e+00 7.1963114045665719e+00 + 16 -1.1814487049351524e+02 2.2070805476502699e+01 4.0103979455896329e+01 + 17 2.0787826988548556e+01 -2.8364190015414366e+01 1.5289010744891176e+01 + 18 5.4411962659043454e+00 5.4597888596162299e+01 -2.2067472725627243e+02 + 19 -6.3374090856904559e+01 -7.9190934240040519e+01 9.4782037192716302e+01 + 20 5.7932894591000213e+01 2.4593045643878220e+01 1.2589269006355613e+02 + 21 5.6478944470524624e+01 7.0203094061683373e+01 -2.1102883364979709e+02 + 22 -9.9996788696603545e+01 -6.7985401318866863e+01 7.4849357252797518e+01 + 23 4.3517844226078921e+01 -2.2176927428165065e+00 1.3617947639699958e+02 + 24 -4.9663522759553963e+01 1.9280842870258854e+02 -1.1467096111871800e+02 + 25 -3.9280982289108742e+01 -1.3314956089589265e+02 2.1920816048609726e+01 + 26 8.8944505048662705e+01 -5.9658867806695888e+01 9.2750145070108275e+01 + 27 -2.6592186096443989e+01 2.1652356998534560e+02 -7.3330722990707770e+01 + 28 -5.7218787679563256e+01 -1.2939713888992102e+02 2.9266537226802889e+00 + 29 8.3810973776007245e+01 -8.7126431095424564e+01 7.0404069268027484e+01 ... From e51a44862c1f373a5896b587b32a4a7264bf9b4e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jan 2024 18:59:43 -0500 Subject: [PATCH 05/12] add fix numdiff test to check consistency between energy and force for bonded interactions --- unittest/force-styles/test_angle_style.cpp | 54 ++++++++++++++++++ unittest/force-styles/test_bond_style.cpp | 55 +++++++++++++++++++ unittest/force-styles/test_dihedral_style.cpp | 55 +++++++++++++++++++ unittest/force-styles/test_improper_style.cpp | 54 ++++++++++++++++++ 4 files changed, 218 insertions(+) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 3476ae8dde..65e1699a85 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -27,6 +27,7 @@ #include "atom.h" #include "compute.h" #include "exceptions.h" +#include "fix.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -528,6 +529,59 @@ TEST(AngleStyle, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); }; +TEST(AngleStyle, numdiff) +{ + if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP(); + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + + ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(args, test_config, true); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("fix diff all numdiff 2 6.05504e-6"); + lmp->input->one("run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + Fix *ifix = lmp->modify->get_fix_by_id("diff"); + if (ifix) { + double epsilon = test_config.epsilon * 1.0e7; + ErrorStats stats; + double **f1 = lmp->atom->f; + double **f2 = ifix->array_atom; + SCOPED_TRACE("EXPECT FORCES: numdiff"); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f1[i][0], f2[i][0], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][1], f2[i][1], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][2], f2[i][2], epsilon); + } + if (print_stats) + std::cerr << "numdiff stats: " << stats << " epsilon: " << epsilon << std::endl; + } + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +} + TEST(AngleStyle, single) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index f7ecd835b0..6efb9978d1 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -27,6 +27,7 @@ #include "bond.h" #include "compute.h" #include "exceptions.h" +#include "fix.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -530,6 +531,60 @@ TEST(BondStyle, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); }; + +TEST(BondStyle, numdiff) +{ + if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP(); + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; + + ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(args, test_config, true); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("fix diff all numdiff 2 6.05504e-6"); + lmp->input->one("run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + Fix *ifix = lmp->modify->get_fix_by_id("diff"); + if (ifix) { + double epsilon = test_config.epsilon * 1.0e7; + ErrorStats stats; + double **f1 = lmp->atom->f; + double **f2 = ifix->array_atom; + SCOPED_TRACE("EXPECT FORCES: numdiff"); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f1[i][0], f2[i][0], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][1], f2[i][1], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][2], f2[i][2], epsilon); + } + if (print_stats) + std::cerr << "numdiff stats: " << stats << " epsilon: " << epsilon << std::endl; + } + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +} + TEST(BondStyle, single) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 662d63909d..74ba3779c8 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -27,6 +27,7 @@ #include "compute.h" #include "dihedral.h" #include "exceptions.h" +#include "fix.h" #include "fmt/format.h" #include "force.h" #include "info.h" @@ -531,3 +532,57 @@ TEST(DihedralStyle, omp) cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; + + +TEST(DihedralStyle, numdiff) +{ + if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP(); + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; + + ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(args, test_config, true); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("fix diff all numdiff 2 6.05504e-6"); + lmp->input->one("run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + Fix *ifix = lmp->modify->get_fix_by_id("diff"); + if (ifix) { + double epsilon = test_config.epsilon * 1.0e7; + ErrorStats stats; + double **f1 = lmp->atom->f; + double **f2 = ifix->array_atom; + SCOPED_TRACE("EXPECT FORCES: numdiff"); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f1[i][0], f2[i][0], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][1], f2[i][1], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][2], f2[i][2], epsilon); + } + if (print_stats) + std::cerr << "numdiff stats: " << stats << " epsilon: " << epsilon << std::endl; + } + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +} diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index dc1b846b5a..7eaa72f67e 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -26,6 +26,7 @@ #include "atom.h" #include "compute.h" #include "exceptions.h" +#include "fix.h" #include "fmt/format.h" #include "force.h" #include "improper.h" @@ -524,3 +525,56 @@ TEST(ImproperStyle, omp) cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); }; + +TEST(ImproperStyle, numdiff) +{ + if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP(); + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; + + ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(args, test_config, true); + + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto &prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + EXPECT_THAT(output, StartsWith("LAMMPS (")); + EXPECT_THAT(output, HasSubstr("Loop time")); + + // abort if running in parallel and not all atoms are local + const int nlocal = lmp->atom->nlocal; + ASSERT_EQ(lmp->atom->natoms, nlocal); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("fix diff all numdiff 2 6.05504e-6"); + lmp->input->one("run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + Fix *ifix = lmp->modify->get_fix_by_id("diff"); + if (ifix) { + double epsilon = test_config.epsilon * 1.0e7; + ErrorStats stats; + double **f1 = lmp->atom->f; + double **f2 = ifix->array_atom; + SCOPED_TRACE("EXPECT FORCES: numdiff"); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f1[i][0], f2[i][0], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][1], f2[i][1], epsilon); + EXPECT_FP_LE_WITH_EPS(f1[i][2], f2[i][2], epsilon); + } + if (print_stats) + std::cerr << "numdiff stats: " << stats << " epsilon: " << epsilon << std::endl; + } + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +} From c340accb0a32c28bcfcbb95b40cde5ba25ed6487 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Jan 2024 19:00:07 -0500 Subject: [PATCH 06/12] skip numdiff tests for linear tables (for now?) --- unittest/force-styles/tests/angle-table_linear.yaml | 2 +- unittest/force-styles/tests/bond-table_linear.yaml | 2 +- unittest/force-styles/tests/dihedral-table_cut_linear.yaml | 2 +- unittest/force-styles/tests/dihedral-table_linear.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unittest/force-styles/tests/angle-table_linear.yaml b/unittest/force-styles/tests/angle-table_linear.yaml index 58e676e8d5..7c0d532782 100644 --- a/unittest/force-styles/tests/angle-table_linear.yaml +++ b/unittest/force-styles/tests/angle-table_linear.yaml @@ -2,7 +2,7 @@ lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:52 2022 epsilon: 5e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full angle table diff --git a/unittest/force-styles/tests/bond-table_linear.yaml b/unittest/force-styles/tests/bond-table_linear.yaml index 2776121733..008742357a 100644 --- a/unittest/force-styles/tests/bond-table_linear.yaml +++ b/unittest/force-styles/tests/bond-table_linear.yaml @@ -2,7 +2,7 @@ lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:51 2022 epsilon: 2.5e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full bond table diff --git a/unittest/force-styles/tests/dihedral-table_cut_linear.yaml b/unittest/force-styles/tests/dihedral-table_cut_linear.yaml index 5c8f53e31f..aa3bbd8ff3 100644 --- a/unittest/force-styles/tests/dihedral-table_cut_linear.yaml +++ b/unittest/force-styles/tests/dihedral-table_cut_linear.yaml @@ -3,7 +3,7 @@ lammps_version: 17 Feb 2022 tags: unstable date_generated: Fri Mar 18 22:18:02 2022 epsilon: 1e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full dihedral table/cut diff --git a/unittest/force-styles/tests/dihedral-table_linear.yaml b/unittest/force-styles/tests/dihedral-table_linear.yaml index 30ac6b7f6d..de46cae001 100644 --- a/unittest/force-styles/tests/dihedral-table_linear.yaml +++ b/unittest/force-styles/tests/dihedral-table_linear.yaml @@ -3,7 +3,7 @@ lammps_version: 22 Dec 2022 tags: unstable date_generated: Mon Dec 26 16:49:31 2022 epsilon: 7.5e-14 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full dihedral table From 0d64aa375d6450aebc5c9abdea1ebcdbb2b0f2c0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jan 2024 04:05:34 -0500 Subject: [PATCH 07/12] tweak epsilon to pass numdiff tests --- unittest/force-styles/tests/angle-gaussian.yaml | 2 +- unittest/force-styles/tests/angle-mm3.yaml | 2 +- unittest/force-styles/tests/dihedral-charmmfsw.yaml | 2 +- unittest/force-styles/tests/dihedral-table_cut_spline.yaml | 2 +- unittest/force-styles/tests/dihedral-table_spline.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/unittest/force-styles/tests/angle-gaussian.yaml b/unittest/force-styles/tests/angle-gaussian.yaml index 0022862384..f8155fea72 100644 --- a/unittest/force-styles/tests/angle-gaussian.yaml +++ b/unittest/force-styles/tests/angle-gaussian.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:52 2022 -epsilon: 2.5e-13 +epsilon: 7.5e-12 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/angle-mm3.yaml b/unittest/force-styles/tests/angle-mm3.yaml index 731ca836cc..171f29715c 100644 --- a/unittest/force-styles/tests/angle-mm3.yaml +++ b/unittest/force-styles/tests/angle-mm3.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:52 2022 -epsilon: 2.5e-13 +epsilon: 1.5e-10 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-charmmfsw.yaml b/unittest/force-styles/tests/dihedral-charmmfsw.yaml index fa8e706578..ad9c5ca959 100644 --- a/unittest/force-styles/tests/dihedral-charmmfsw.yaml +++ b/unittest/force-styles/tests/dihedral-charmmfsw.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:02 2022 -epsilon: 2.5e-13 +epsilon: 2.5e-10 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-table_cut_spline.yaml b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml index be637652a0..61b3f04329 100644 --- a/unittest/force-styles/tests/dihedral-table_cut_spline.yaml +++ b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:02 2022 -epsilon: 2.5e-13 +epsilon: 2.5e-12 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-table_spline.yaml b/unittest/force-styles/tests/dihedral-table_spline.yaml index bb38760762..d5441c13d7 100644 --- a/unittest/force-styles/tests/dihedral-table_spline.yaml +++ b/unittest/force-styles/tests/dihedral-table_spline.yaml @@ -1,7 +1,7 @@ --- lammps_version: 22 Dec 2022 date_generated: Mon Dec 26 16:49:37 2022 -epsilon: 1e-13 +epsilon: 5.0e-12 skip_tests: prerequisites: ! | atom full From f93032b903180288780f83410a7a2cdc6006808d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jan 2024 04:26:08 -0500 Subject: [PATCH 08/12] skip failing numdiff tests for now --- unittest/force-styles/tests/angle-cosine_delta.yaml | 2 +- unittest/force-styles/tests/angle-fourier_simple.yaml | 1 + unittest/force-styles/tests/dihedral-charmm.yaml | 2 +- unittest/force-styles/tests/improper-cossq.yaml | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/unittest/force-styles/tests/angle-cosine_delta.yaml b/unittest/force-styles/tests/angle-cosine_delta.yaml index e56a51c9f0..ed2337e935 100644 --- a/unittest/force-styles/tests/angle-cosine_delta.yaml +++ b/unittest/force-styles/tests/angle-cosine_delta.yaml @@ -2,7 +2,7 @@ lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:51 2022 epsilon: 5e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full angle cosine/delta diff --git a/unittest/force-styles/tests/angle-fourier_simple.yaml b/unittest/force-styles/tests/angle-fourier_simple.yaml index 8fcecf85ad..e1a394ee3a 100644 --- a/unittest/force-styles/tests/angle-fourier_simple.yaml +++ b/unittest/force-styles/tests/angle-fourier_simple.yaml @@ -5,6 +5,7 @@ epsilon: 2.5e-13 prerequisites: ! | atom full angle fourier/simple +skip_tests: numdiff pre_commands: ! "" post_commands: ! "" input_file: in.fourmol diff --git a/unittest/force-styles/tests/dihedral-charmm.yaml b/unittest/force-styles/tests/dihedral-charmm.yaml index ddba14cb4f..cf407709b0 100644 --- a/unittest/force-styles/tests/dihedral-charmm.yaml +++ b/unittest/force-styles/tests/dihedral-charmm.yaml @@ -2,7 +2,7 @@ lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:01 2022 epsilon: 2.5e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full dihedral charmm diff --git a/unittest/force-styles/tests/improper-cossq.yaml b/unittest/force-styles/tests/improper-cossq.yaml index d52c50c517..4faaa2214a 100644 --- a/unittest/force-styles/tests/improper-cossq.yaml +++ b/unittest/force-styles/tests/improper-cossq.yaml @@ -2,7 +2,7 @@ lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:02 2022 epsilon: 2.5e-13 -skip_tests: +skip_tests: numdiff prerequisites: ! | atom full improper cossq From 9587e92a3c919f9e3e923eb9e8e03d2de3172e60 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Jan 2024 10:33:13 -0500 Subject: [PATCH 09/12] increase numdiff fudge factor so that individual epsilons need to be changed less --- unittest/force-styles/test_angle_style.cpp | 2 +- unittest/force-styles/test_bond_style.cpp | 2 +- unittest/force-styles/test_dihedral_style.cpp | 2 +- unittest/force-styles/test_improper_style.cpp | 2 +- unittest/force-styles/tests/angle-gaussian.yaml | 2 +- unittest/force-styles/tests/angle-mm3.yaml | 2 +- unittest/force-styles/tests/dihedral-charmmfsw.yaml | 2 +- unittest/force-styles/tests/dihedral-table_cut_spline.yaml | 2 +- unittest/force-styles/tests/dihedral-table_spline.yaml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 65e1699a85..010fabd6e2 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -564,7 +564,7 @@ TEST(AngleStyle, numdiff) if (!verbose) ::testing::internal::GetCapturedStdout(); Fix *ifix = lmp->modify->get_fix_by_id("diff"); if (ifix) { - double epsilon = test_config.epsilon * 1.0e7; + double epsilon = test_config.epsilon * 5.0e8; ErrorStats stats; double **f1 = lmp->atom->f; double **f2 = ifix->array_atom; diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 6efb9978d1..185d28089e 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -567,7 +567,7 @@ TEST(BondStyle, numdiff) if (!verbose) ::testing::internal::GetCapturedStdout(); Fix *ifix = lmp->modify->get_fix_by_id("diff"); if (ifix) { - double epsilon = test_config.epsilon * 1.0e7; + double epsilon = test_config.epsilon * 5.0e8; ErrorStats stats; double **f1 = lmp->atom->f; double **f2 = ifix->array_atom; diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 74ba3779c8..efc37b9e03 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -569,7 +569,7 @@ TEST(DihedralStyle, numdiff) if (!verbose) ::testing::internal::GetCapturedStdout(); Fix *ifix = lmp->modify->get_fix_by_id("diff"); if (ifix) { - double epsilon = test_config.epsilon * 1.0e7; + double epsilon = test_config.epsilon * 5.0e8; ErrorStats stats; double **f1 = lmp->atom->f; double **f2 = ifix->array_atom; diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 7eaa72f67e..ba3618d3dc 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -561,7 +561,7 @@ TEST(ImproperStyle, numdiff) if (!verbose) ::testing::internal::GetCapturedStdout(); Fix *ifix = lmp->modify->get_fix_by_id("diff"); if (ifix) { - double epsilon = test_config.epsilon * 1.0e7; + double epsilon = test_config.epsilon * 5.0e8; ErrorStats stats; double **f1 = lmp->atom->f; double **f2 = ifix->array_atom; diff --git a/unittest/force-styles/tests/angle-gaussian.yaml b/unittest/force-styles/tests/angle-gaussian.yaml index f8155fea72..0022862384 100644 --- a/unittest/force-styles/tests/angle-gaussian.yaml +++ b/unittest/force-styles/tests/angle-gaussian.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:52 2022 -epsilon: 7.5e-12 +epsilon: 2.5e-13 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/angle-mm3.yaml b/unittest/force-styles/tests/angle-mm3.yaml index 171f29715c..9fb9460183 100644 --- a/unittest/force-styles/tests/angle-mm3.yaml +++ b/unittest/force-styles/tests/angle-mm3.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:17:52 2022 -epsilon: 1.5e-10 +epsilon: 2.5e-12 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-charmmfsw.yaml b/unittest/force-styles/tests/dihedral-charmmfsw.yaml index ad9c5ca959..6d2035acc5 100644 --- a/unittest/force-styles/tests/dihedral-charmmfsw.yaml +++ b/unittest/force-styles/tests/dihedral-charmmfsw.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:02 2022 -epsilon: 2.5e-10 +epsilon: 5.0e-12 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-table_cut_spline.yaml b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml index 61b3f04329..be637652a0 100644 --- a/unittest/force-styles/tests/dihedral-table_cut_spline.yaml +++ b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml @@ -1,7 +1,7 @@ --- lammps_version: 17 Feb 2022 date_generated: Fri Mar 18 22:18:02 2022 -epsilon: 2.5e-12 +epsilon: 2.5e-13 skip_tests: prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/dihedral-table_spline.yaml b/unittest/force-styles/tests/dihedral-table_spline.yaml index d5441c13d7..10e56e4a6d 100644 --- a/unittest/force-styles/tests/dihedral-table_spline.yaml +++ b/unittest/force-styles/tests/dihedral-table_spline.yaml @@ -1,7 +1,7 @@ --- lammps_version: 22 Dec 2022 date_generated: Mon Dec 26 16:49:37 2022 -epsilon: 5.0e-12 +epsilon: 1.0e-13 skip_tests: prerequisites: ! | atom full From b6b2c029b6ce96fcee41ce43ddad60f33291c4e1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 14 Jan 2024 07:33:31 -0500 Subject: [PATCH 10/12] improve description of testing --- doc/src/Build_development.rst | 61 ++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index c674b2c258..36772c13f2 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -122,32 +122,39 @@ Code Coverage and Unit Testing (CMake only) ------------------------------------------- The LAMMPS code is subject to multiple levels of automated testing -during development: integration testing (i.e. whether the code compiles -on various platforms and with a variety of settings), unit testing -(i.e. whether certain individual parts of the code produce the expected -results for given inputs), run testing (whether selected complete input -decks run without crashing for multiple configurations), and regression -testing (i.e. whether selected input examples reproduce the same -results over a given number of steps and operations within a given -error margin). The status of this automated testing can be viewed on -`https://ci.lammps.org `_. +during development: + +- Integration testing (i.e. whether the code compiles + on various platforms and with a variety of compilers and settings), +- Unit testing (i.e. whether certain functions or classes of the code + produce the expected results for given inputs), +- Run testing (i.e. whether selected input decks can run to completion + without crashing for multiple configurations), +- Regression testing (i.e. whether selected input examples reproduce the + same results over a given number of steps and operations within a + given error margin). + +The status of this automated testing can be viewed on `https://ci.lammps.org +`_. The scripts and inputs for integration, run, and regression testing are maintained in a `separate repository `_ -of the LAMMPS project on GitHub. +of the LAMMPS project on GitHub. A few tests are also run as GitHub +Actions and their configuration files are in the ``.github/workflows/`` +folder of the LAMMPS git tree. -The unit testing facility is integrated into the CMake build process -of the LAMMPS source code distribution itself. It can be enabled by +The unit testing facility is integrated into the CMake build process of +the LAMMPS source code distribution itself. It can be enabled by setting ``-D ENABLE_TESTING=on`` during the CMake configuration step. -It requires the `YAML `_ library and development -headers (if those are not found locally a recent version will be -downloaded and compiled along with LAMMPS and the test program) to -compile and will download and compile a specific recent version of the -`Googletest `_ C++ test framework -for implementing the tests. +It requires the `YAML `_ library and matching +development headers to compile (if those are not found locally a recent +version of that library will be downloaded and compiled along with +LAMMPS and the test programs) and will download and compile a specific +version of the `GoogleTest `_ C++ +test framework that is used to implement the tests. -.. admonition:: Software version requirements for testing +.. admonition:: Software version and LAMMPS configuration requirements :class: note The compiler and library version requirements for the testing @@ -155,7 +162,7 @@ for implementing the tests. example the default GNU C++ and Fortran compilers of RHEL/CentOS 7.x (version 4.8.x) are not sufficient. The CMake configuration will try to detect incompatible versions and either skip incompatible tests or - stop with an error. Also the number of tests will depend on + stop with an error. Also the number of available tests will depend on installed LAMMPS packages, development environment, operating system, and configuration settings. @@ -234,12 +241,14 @@ will be skipped if prerequisite features are not available in LAMMPS. time. Preference is given to parts of the code base that are easy to test or commonly used. -Tests for styles of the same kind of style (e.g. pair styles or bond -styles) are performed with the same test executable using different -input files in YAML format. So to add a test for another style of the -same kind it may be sufficient to add a suitable YAML file. -:doc:`Detailed instructions for adding tests ` are -provided in the Programmer Guide part of the manual. +Many tests have special test programs that test individual functions or +classes. There are also special cases for the Fortran and Python +module. Tests for force computing or modifying styles (e.g. pair styles +or bond styles) are performed with the same test executable using input +files in YAML format. So to add a test for another style of this kind +it may be sufficient to add a suitable YAML file. :doc:`Detailed +instructions for adding tests ` are provided in the +Programmer Guide part of the manual. Unit tests for force styles ^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 0bb6be5dd9e439c8f06f1fe51939c48422b7548d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Feb 2024 11:37:41 -0500 Subject: [PATCH 11/12] provide a more detailed description of the bundled tests --- doc/src/Build_development.rst | 31 ++++++++++++++++----- doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 36772c13f2..ec2468d54e 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -241,14 +241,31 @@ will be skipped if prerequisite features are not available in LAMMPS. time. Preference is given to parts of the code base that are easy to test or commonly used. -Many tests have special test programs that test individual functions or -classes. There are also special cases for the Fortran and Python -module. Tests for force computing or modifying styles (e.g. pair styles -or bond styles) are performed with the same test executable using input -files in YAML format. So to add a test for another style of this kind -it may be sufficient to add a suitable YAML file. :doc:`Detailed +Tests as shown by the ``ctest`` program are command lines defined in the +``CMakeLists.txt`` files in the ``unittest`` directory tree. A few +tests simply execute LAMMPS with specific command line flags and check +the output to the screen for expected content. A large number of unit +tests are special tests programs using the `GoogleTest framework +`_ and linked to the LAMMPS +library that test individual functions or create a LAMMPS class +instance, execute one or more commands and check data inside the LAMMPS +class hierarchy. There are also tests for the C-library, Fortran, and +Python module interfaces to LAMMPS. The Python tests use the Python +"unittest" module in a similar fashion than the others use `GoogleTest`. +These special test programs are structured to have perform multiple +individual tests internally and each of those contains several checks +(aka assertions) for internal data being changed as expected. + +Tests for force computing or modifying styles (e.g. styles for non-bonded +and bonded interactions and selected fixes) are run by using a more generic +test program that reads its input from files in YAML format. The YAML file +provides the information on how to customized the test program to test +a specific style and - if needed - with specific settings. +To add a test for another, similar style (e.g. a new pair style) it is +usually sufficient to add a suitable YAML file. :doc:`Detailed instructions for adding tests ` are provided in the -Programmer Guide part of the manual. +Programmer Guide part of the manual. A description of what happens +during the tests is given below. Unit tests for force styles ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index c74e2a79f3..4f5fe6fdaf 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3797,6 +3797,7 @@ unimodal uninstall unitarg unitless +unittest Universite unix unmaintained From e95d52780c634a50c6285b3dbf315c112d8e1723 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Feb 2024 11:47:58 -0500 Subject: [PATCH 12/12] fix grammar error --- doc/src/Build_development.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index ec2468d54e..4d8bf0d07f 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -252,7 +252,7 @@ instance, execute one or more commands and check data inside the LAMMPS class hierarchy. There are also tests for the C-library, Fortran, and Python module interfaces to LAMMPS. The Python tests use the Python "unittest" module in a similar fashion than the others use `GoogleTest`. -These special test programs are structured to have perform multiple +These special test programs are structured to perform multiple individual tests internally and each of those contains several checks (aka assertions) for internal data being changed as expected.