Decouple update group handling from domain decomposition module
[alexxy/gromacs.git] / src / gromacs / mdlib / tests / updategroups.cpp
index 4b75b16a99971991a73a105afdf7c6c4e10de37e..8934d0b74bcc6ff352639348ddf74aedf3195603 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "gromacs/topology/topology.h"
 
+#include "testutils/loggertest.h"
 #include "testutils/testasserts.h"
 
 namespace gmx
@@ -57,6 +58,17 @@ namespace
 
 /* TODO: Actually initialize moltype.atoms.atom when this is converted to C++ */
 
+/*! \brief Returns a flexible ethane united-atom molecule */
+gmx_moltype_t flexibleEthaneUA()
+{
+    gmx_moltype_t moltype = {};
+
+    moltype.atoms.nr              = 2;
+    moltype.ilist[F_BONDS].iatoms = { 0, 0, 1 };
+
+    return moltype;
+}
+
 /*! \brief Returns an ethane united-atom molecule */
 gmx_moltype_t ethaneUA()
 {
@@ -92,7 +104,7 @@ gmx_moltype_t ethane()
     return moltype;
 }
 
-/*! \brief Returns a butane united-atom molecule */
+/*! \brief Returns a butane fully-constrained united-atom molecule */
 gmx_moltype_t butaneUA()
 {
     gmx_moltype_t moltype = {};
@@ -153,6 +165,8 @@ public:
     gmx_mtop_t mtop_;
     //! Default temperature for tests
     real temperature_ = 298;
+    //! Logger to use in tests
+    test::LoggerTestHelper logHelper_;
 };
 
 TEST_F(UpdateGroupsTest, WithEthaneUA)
@@ -171,6 +185,10 @@ TEST_F(UpdateGroupsTest, WithEthaneUA)
 
     real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
     EXPECT_FLOAT_EQ(maxRadius, 0.3 / 2);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 TEST_F(UpdateGroupsTest, WithMethane)
@@ -189,7 +207,12 @@ TEST_F(UpdateGroupsTest, WithMethane)
 
     real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
     EXPECT_FLOAT_EQ(maxRadius, 0.14);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
+
 TEST_F(UpdateGroupsTest, WithEthane)
 {
     mtop_.moltype.emplace_back(ethane());
@@ -208,6 +231,10 @@ TEST_F(UpdateGroupsTest, WithEthane)
 
     real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
     EXPECT_FLOAT_EQ(maxRadius, 0.094746813);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 TEST_F(UpdateGroupsTest, CheckRadiusCalculationAtDifferentTemperaturesWithEthane)
@@ -239,7 +266,7 @@ TEST_F(UpdateGroupsTest, CheckRadiusCalculationAtDifferentTemperaturesWithEthane
     EXPECT_FLOAT_EQ(maxRadius, 0.125);
 }
 
-TEST_F(UpdateGroupsTest, WithButaneUA)
+TEST_F(UpdateGroupsTest, WithButaneUALogsThatUnsuitableForUpdateGroups)
 {
     mtop_.moltype.emplace_back(butaneUA());
     {
@@ -251,6 +278,15 @@ TEST_F(UpdateGroupsTest, WithButaneUA)
     auto updateGroupingsPerMoleculeType = gmx::makeUpdateGroupingsPerMoleculeType(mtop_);
 
     EXPECT_EQ(updateGroupingsPerMoleculeType.size(), 0);
+
+    real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
+    EXPECT_FLOAT_EQ(maxRadius, 0.0);
+
+    logHelper_.expectEntryMatchingRegex(
+            MDLogger::LogLevel::Info,
+            "At least one moleculetype does not conform to the requirements");
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 TEST_F(UpdateGroupsTest, WithWaterThreeSite)
@@ -269,6 +305,10 @@ TEST_F(UpdateGroupsTest, WithWaterThreeSite)
 
     real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
     EXPECT_FLOAT_EQ(maxRadius, 0.083887339);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 // Tests update group with virtual site
@@ -287,17 +327,38 @@ TEST_F(UpdateGroupsTest, WithWaterFourSite)
 
     ASSERT_EQ(updateGroupingsPerMoleculeType.size(), 1);
     EXPECT_EQ(updateGroupingsPerMoleculeType[0].numBlocks(), 1);
+
+    real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
+    EXPECT_FLOAT_EQ(maxRadius, 0.083887339);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 TEST_F(UpdateGroupsTest, WithFourAtomsWithSettle)
 {
     mtop_.moltype.emplace_back(waterThreeSite());
     mtop_.moltype.back().atoms.nr = 4;
+    {
+        t_iparams iparams[2];
+        iparams[0].settle = { 0.1, 0.1633 };
+        iparams[1].vsite  = { 0.128, 0.128 };
+        mtop_.ffparams.iparams.push_back(iparams[0]);
+        mtop_.ffparams.iparams.push_back(iparams[1]);
+    }
 
     auto updateGroupingsPerMoleculeType = gmx::makeUpdateGroupingsPerMoleculeType(mtop_);
 
     ASSERT_EQ(updateGroupingsPerMoleculeType.size(), 1);
     EXPECT_EQ(updateGroupingsPerMoleculeType[0].numBlocks(), 2);
+
+    real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
+    EXPECT_FLOAT_EQ(maxRadius, 0.083887339);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 // Tests groups with two constraints and an angle potential
@@ -319,6 +380,10 @@ TEST_F(UpdateGroupsTest, WithWaterFlexAngle)
 
     real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
     EXPECT_FLOAT_EQ(maxRadius, 0.090824135);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
 }
 
 TEST_F(UpdateGroupsTest, CheckRadiusCalculationAtDifferentTemperaturesWithWaterFlexAngle)
@@ -367,8 +432,55 @@ TEST_F(UpdateGroupsTest, WithTwoMoltypes)
     ASSERT_EQ(updateGroupingsPerMoleculeType.size(), 2);
     EXPECT_EQ(updateGroupingsPerMoleculeType[0].numBlocks(), 1);
     EXPECT_EQ(updateGroupingsPerMoleculeType[1].numBlocks(), 1);
+
+    real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
+    EXPECT_FLOAT_EQ(maxRadius, 0.14);
+
+    logHelper_.expectNoEntries(MDLogger::LogLevel::Info);
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, true, 1e6_real);
+}
+
+TEST_F(UpdateGroupsTest, LogsWhenSizesAreInvalid)
+{
+    mtop_.moltype.emplace_back(methane());
+    {
+        t_iparams iparams;
+        iparams.constr = { 0.1, 0.1 };
+        mtop_.ffparams.iparams.push_back(iparams);
+    }
+
+    auto updateGroupingsPerMoleculeType = gmx::makeUpdateGroupingsPerMoleculeType(mtop_);
+    logHelper_.expectEntryMatchingRegex(MDLogger::LogLevel::Info,
+                                        "The combination of rlist and box size prohibits");
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), 1e9_real, true, true, 1e6_real);
 }
 
+TEST_F(UpdateGroupsTest, LogsWhenUpdateGroupsAreNotUseful)
+{
+    mtop_.moltype.emplace_back(flexibleEthaneUA());
+    {
+        t_iparams iparams;
+        iparams.harmonic = { 0.1, 10.0, 0.1, 10.0 };
+        mtop_.ffparams.iparams.push_back(iparams);
+    }
+
+    auto updateGroupingsPerMoleculeType = gmx::makeUpdateGroupingsPerMoleculeType(mtop_);
+
+    ASSERT_EQ(updateGroupingsPerMoleculeType.size(), 1);
+    EXPECT_EQ(updateGroupingsPerMoleculeType[0].numBlocks(), 2);
+
+    real maxRadius = computeMaxUpdateGroupRadius(mtop_, updateGroupingsPerMoleculeType, temperature_);
+    EXPECT_FLOAT_EQ(maxRadius, 0);
+
+    logHelper_.expectEntryMatchingRegex(MDLogger::LogLevel::Info,
+                                        "No constraints or virtual sites are in use");
+    UpdateGroups updateGroups = makeUpdateGroups(
+            logHelper_.logger(), std::move(updateGroupingsPerMoleculeType), maxRadius, true, false, 1e6_real);
+}
+
+
 } // namespace
 
 } // namespace gmx