Simplify short-circuit logic in grompp
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 26 Jul 2021 08:47:19 +0000 (10:47 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 30 Jul 2021 09:26:51 +0000 (09:26 +0000)
This is simpler to understand, and also prepares for a future
change that removes bB while improving performance.

src/gromacs/gmxpreprocess/toppush.cpp

index dd9dcead983a6a085ddebc2dc9c8c68b438e7abc..9aae7a3926705bd525f38d24f7f0ff7cf57255b5 100644 (file)
@@ -1813,17 +1813,7 @@ static std::vector<InteractionOfType>::iterator defaultInteractionsOfType(int ft
                                                                           bool bB,
                                                                           int* nparam_def)
 {
-    int nparam_found;
-    int nrfpA = interaction_function[ftype].nrfpA;
-    int nrfpB = interaction_function[ftype].nrfpB;
-
-    if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
-    {
-        return bt[ftype].interactionTypes.end();
-    }
-
-
-    nparam_found = 0;
+    int nparam_found = 0;
     if (ftype == F_PDIHS || ftype == F_RBDIHS || ftype == F_IDIHS || ftype == F_PIDIHS)
     {
         int nmatch_max = -1;
@@ -2048,40 +2038,47 @@ void push_bond(Directive                         d,
     std::vector<InteractionOfType>::iterator foundBParameter = bondtype[ftype].interactionTypes.end();
     if (bBonded)
     {
-        foundAParameter =
-                defaultInteractionsOfType(ftype, bondtype, at, atypes, param, FALSE, &nparam_defA);
-        if (foundAParameter != bondtype[ftype].interactionTypes.end())
-        {
-            /* Copy the A-state and B-state default parameters. */
-            GMX_ASSERT(NRFPA(ftype) + NRFPB(ftype) <= MAXFORCEPARAM,
-                       "Bonded interactions may have at most 12 parameters");
-            gmx::ArrayRef<const real> defaultParam = foundAParameter->forceParam();
-            for (int j = 0; (j < NRFPA(ftype) + NRFPB(ftype)); j++)
-            {
-                param.setForceParameter(j, defaultParam[j]);
-            }
-            bFoundA = true;
-        }
-        else if (NRFPA(ftype) == 0)
+        if (NRFPA(ftype) == 0)
         {
             bFoundA = true;
         }
-        foundBParameter =
-                defaultInteractionsOfType(ftype, bondtype, at, atypes, param, TRUE, &nparam_defB);
-        if (foundBParameter != bondtype[ftype].interactionTypes.end())
+        else
         {
-            /* Copy only the B-state default parameters */
-            gmx::ArrayRef<const real> defaultParam = foundBParameter->forceParam();
-            for (int j = NRFPA(ftype); (j < NRFP(ftype)); j++)
+            foundAParameter =
+                    defaultInteractionsOfType(ftype, bondtype, at, atypes, param, FALSE, &nparam_defA);
+            if (foundAParameter != bondtype[ftype].interactionTypes.end())
             {
-                param.setForceParameter(j, defaultParam[j]);
+                /* Copy the A-state and B-state default parameters. */
+                GMX_ASSERT(NRFPA(ftype) + NRFPB(ftype) <= MAXFORCEPARAM,
+                           "Bonded interactions may have at most 12 parameters");
+                gmx::ArrayRef<const real> defaultParam = foundAParameter->forceParam();
+                for (int j = 0; (j < NRFPA(ftype) + NRFPB(ftype)); j++)
+                {
+                    param.setForceParameter(j, defaultParam[j]);
+                }
+                bFoundA = true;
             }
-            bFoundB = true;
         }
-        else if (NRFPB(ftype) == 0)
+
+        if (NRFPB(ftype) == 0)
         {
             bFoundB = true;
         }
+        else
+        {
+            foundBParameter =
+                    defaultInteractionsOfType(ftype, bondtype, at, atypes, param, TRUE, &nparam_defB);
+            if (foundBParameter != bondtype[ftype].interactionTypes.end())
+            {
+                /* Copy only the B-state default parameters */
+                gmx::ArrayRef<const real> defaultParam = foundBParameter->forceParam();
+                for (int j = NRFPA(ftype); (j < NRFP(ftype)); j++)
+                {
+                    param.setForceParameter(j, defaultParam[j]);
+                }
+                bFoundB = true;
+            }
+        }
     }
     else if (ftype == F_LJ14)
     {