From c76c4668ea234d3ee1a5de1d4ed6447f9930f933 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Mon, 26 Jul 2021 10:47:19 +0200 Subject: [PATCH] Simplify short-circuit logic in grompp This is simpler to understand, and also prepares for a future change that removes bB while improving performance. --- src/gromacs/gmxpreprocess/toppush.cpp | 67 +++++++++++++-------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index dd9dcead98..9aae7a3926 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -1813,17 +1813,7 @@ static std::vector::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::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 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 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 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 defaultParam = foundBParameter->forceParam(); + for (int j = NRFPA(ftype); (j < NRFP(ftype)); j++) + { + param.setForceParameter(j, defaultParam[j]); + } + bFoundB = true; + } + } } else if (ftype == F_LJ14) { -- 2.22.0