Unverified Commit 4b7356f5 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add support for testing virial contributions from fixes (as an option)

parent f1da1ed1
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -294,14 +294,18 @@ YAML format test inputs.
- The fix to be tested must be specified in the ``post_commands:``
  section with the fix-ID ``test``.  This section may contain other
  commands and other fixes (e.g. an instance of fix nve for testing
  thermostat or force manipulation fixes)
  a thermostat or force manipulation fix)
- For fixes that can tally contributions to the global virial, the
  line ``fix_modify test virial yes`` should be included in the
  ``post_commands:`` section of the test input.
- For thermostat fixes the target temperature should be ramped from
  an arbitrary value (e.g. 50K) to a pre-defined target temperature
  entered as ``${t_target}``.
- For fixes that may or may not do thermostatting depending on
  the flags in use (e.g. fix rigid), the ``post_commands:`` section
  should contain ``variable t_target delete`` to disable the target
  temperature ramp check in case the thermostat is not enabled
- For fixes that have thermostatting support included, but do not
  have it enabled in the input (e.g. fix rigid with default settings),
  the ``post_commands:`` section should contain the line
  ``variable t_target delete`` to disable the target temperature ramp
  check to avoid false positives.

Use custom linker for faster link times when ENABLE_TESTING is active
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+153 −1
Original line number Diff line number Diff line
@@ -239,6 +239,15 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
    } else {
        Fix *fix = lmp->modify->fix[ifix];

        // run_stress, if enabled
        if (fix->thermo_virial) {
            auto stress = fix->virial;
            block       = fmt::format("{:23.16e} {:23.16e} {:23.16e} "
                                "{:23.16e} {:23.16e} {:23.16e}",
                                stress[0], stress[1], stress[2], stress[3], stress[4], stress[5]);
            writer.emit_block("run_stress", block);
        }

        // global scalar
        if (fix->scalar_flag) {
            double value = fix->compute_scalar();
@@ -338,8 +347,19 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl;
        }

        stats.reset();
        // global scalar
        if (fix->scalar_flag) {
            double value = fix->compute_scalar();
@@ -402,6 +422,18 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -453,6 +485,18 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -510,6 +554,18 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress normal run, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -561,6 +617,18 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -612,6 +680,18 @@ TEST(FixTimestep, plain)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -701,6 +781,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress normal run, verlet: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -765,6 +857,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress restart, verlet: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -816,6 +920,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress rmass, verlet: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -873,6 +989,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress normal run, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -924,6 +1052,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress restart, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
@@ -975,6 +1115,18 @@ TEST(FixTimestep, omp)
        FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];
        if (fix->thermo_virial) {
            stats.reset();
            auto stress = fix->virial;
            EXPECT_FP_LE_WITH_EPS(stress[0], test_config.run_stress.xx, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[1], test_config.run_stress.yy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[2], test_config.run_stress.zz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
            EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
            if (print_stats) std::cerr << "run_stress rmass, respa: " << stats << std::endl;
        }

        stats.reset();

        // global scalar
+4 −1
Original line number Diff line number Diff line
---
lammps_version: 21 Jul 2020
date_generated: Sun Aug  9 13:57:28 202
date_generated: Sun Aug  9 16:30:21 202
epsilon: 1e-14
prerequisites: ! |
  atom full
@@ -9,8 +9,11 @@ pre_commands: ! ""
post_commands: ! |
  fix move all nve
  fix test solvent rattle 1.0e-5 20 4 b 5 a 1
  fix_modify test virial yes
input_file: in.fourmol
natoms: 29
run_stress: ! |-
  -6.7489444076122581e+01 -3.6466857275816793e+01 -4.1453650662488030e+01 -3.0881715538687999e+01 -2.8271646386126275e+01  1.8512924155867125e-01
run_pos: ! |2
    1 -2.7045559935221097e-01  2.4912159904412490e+00 -1.6695851634760922e-01
    2  3.1004029578877490e-01  2.9612354630874571e+00 -8.5466363025011627e-01
+4 −1
Original line number Diff line number Diff line
---
lammps_version: 21 Jul 2020
date_generated: Sun Aug  9 13:57:18 202
date_generated: Sun Aug  9 16:30:21 202
epsilon: 1e-14
prerequisites: ! |
  atom full
@@ -9,8 +9,11 @@ pre_commands: ! ""
post_commands: ! |
  fix move all nve
  fix test solute rattle 1.0e-5 20 4 m 4.00794
  fix_modify test virial yes
input_file: in.fourmol
natoms: 29
run_stress: ! |2-
   3.9891557115890999e+00  3.7983351717152480e+00  7.6152694943743228e+01  5.7163462651523300e-01  3.0839737670745507e+01  3.0066936263232019e+01
run_pos: ! |2
    1 -2.6863205200662160e-01  2.4924200251053037e+00 -1.6940797171640173e-01
    2  3.0314855494325726e-01  2.9555142432096928e+00 -8.4661597718762538e-01
+4 −1
Original line number Diff line number Diff line
---
lammps_version: 21 Jul 2020
date_generated: Sun Aug  9 07:12:15 202
date_generated: Sun Aug  9 16:30:21 202
epsilon: 2.5e-13
prerequisites: ! |
  atom full
@@ -9,8 +9,11 @@ pre_commands: ! ""
post_commands: ! |
  variable t_target delete
  fix test all rigid group 2 solute solvent
  fix_modify test virial yes
input_file: in.fourmol
natoms: 29
run_stress: ! |-
  -1.4245356937318927e+03 -1.4496493315649675e+03 -3.6144360984224963e+03  8.4840626828643849e+02  2.0318336761611764e+02 -6.0622397707969685e+02
global_scalar: 15.7115214231781
run_pos: ! |2
    1 -2.7899546863891622e-01  2.4731857340328216e+00 -1.7290667740241872e-01
Loading