Merge branch release-2021
[alexxy/gromacs.git] / src / programs / mdrun / tests / simulator.cpp
index b8aec654a78a12053311487a1d886cd8c35283ca..65418e8c899d2245f58ac6c5bf867691e1d606c5 100644 (file)
@@ -110,6 +110,14 @@ TEST_P(SimulatorComparisonTest, WithinTolerances)
         return;
     }
 
+    const std::string envVariableModSimOn  = "GMX_USE_MODULAR_SIMULATOR";
+    const std::string envVariableModSimOff = "GMX_DISABLE_MODULAR_SIMULATOR";
+
+    GMX_RELEASE_ASSERT(
+            environmentVariable == envVariableModSimOn || environmentVariable == envVariableModSimOff,
+            ("Expected tested environment variable to be " + envVariableModSimOn + " or " + envVariableModSimOff)
+                    .c_str());
+
     const auto hasConservedField = !(tcoupling == "no" && pcoupling == "no");
 
     SCOPED_TRACE(formatString(
@@ -126,8 +134,8 @@ TEST_P(SimulatorComparisonTest, WithinTolerances)
             simulationName.c_str(), integrator.c_str(), tcoupling.c_str(), pcoupling.c_str());
 
     EnergyTermsToCompare energyTermsToCompare{ {
-            { interaction_function[F_EPOT].longname, relativeToleranceAsPrecisionDependentUlp(10.0, 100, 80) },
-            { interaction_function[F_EKIN].longname, relativeToleranceAsPrecisionDependentUlp(60.0, 100, 80) },
+            { interaction_function[F_EPOT].longname, relativeToleranceAsPrecisionDependentUlp(60.0, 200, 160) },
+            { interaction_function[F_EKIN].longname, relativeToleranceAsPrecisionDependentUlp(60.0, 200, 160) },
             { interaction_function[F_PRES].longname,
               relativeToleranceAsPrecisionDependentFloatingPoint(10.0, 0.01, 0.001) },
     } };
@@ -185,16 +193,18 @@ TEST_P(SimulatorComparisonTest, WithinTolerances)
     runner_.useStringAsMdpFile(prepareMdpFileContents(mdpFieldValues));
     runGrompp(&runner_);
 
-    // Backup current state of environment variable and unset it
-    const char* environmentVariableBackup = getenv(environmentVariable.c_str());
-    gmxUnsetenv(environmentVariable.c_str());
+    // Backup current state of both environment variables and unset them
+    const char* environmentVariableBackupOn  = getenv(envVariableModSimOn.c_str());
+    const char* environmentVariableBackupOff = getenv(envVariableModSimOff.c_str());
+    gmxUnsetenv(envVariableModSimOn.c_str());
+    gmxUnsetenv(envVariableModSimOff.c_str());
 
     // Do first mdrun
     runner_.fullPrecisionTrajectoryFileName_ = simulator1TrajectoryFileName;
     runner_.edrFileName_                     = simulator1EdrFileName;
     runMdrun(&runner_);
 
-    // Set environment variable
+    // Set tested environment variable
     const int overWriteEnvironmentVariable = 1;
     gmxSetenv(environmentVariable.c_str(), "ON", overWriteEnvironmentVariable);
 
@@ -203,16 +213,16 @@ TEST_P(SimulatorComparisonTest, WithinTolerances)
     runner_.edrFileName_                     = simulator2EdrFileName;
     runMdrun(&runner_);
 
-    // Reset or unset environment variable to leave further tests undisturbed
-    if (environmentVariableBackup != nullptr)
+    // Unset tested environment variable
+    gmxUnsetenv(environmentVariable.c_str());
+    // Reset both environment variables to leave further tests undisturbed
+    if (environmentVariableBackupOn != nullptr)
     {
-        // set environment variable
-        gmxSetenv(environmentVariable.c_str(), environmentVariableBackup, overWriteEnvironmentVariable);
+        gmxSetenv(environmentVariable.c_str(), environmentVariableBackupOn, overWriteEnvironmentVariable);
     }
-    else
+    if (environmentVariableBackupOff != nullptr)
     {
-        // unset environment variable
-        gmxUnsetenv(environmentVariable.c_str());
+        gmxSetenv(environmentVariable.c_str(), environmentVariableBackupOff, overWriteEnvironmentVariable);
     }
 
     // Compare simulation results