Merge branch 'release-5-0'
[alexxy/gromacs.git] / src / gromacs / ewald / long-range-correction.c
index a71b031dc5970599868571a681c47c3cb267a1e2..5a5b96ca3458b54180472d98840e99a837d39aa0 100644 (file)
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 
+/* There's nothing special to do here if just masses are perturbed,
+ * but if either charge or type is perturbed then the implementation
+ * requires that B states are defined for both charge and type, and
+ * does not optimize for the cases where only one changes.
+ *
+ * The parameter vectors for B states are left undefined in atoms2md()
+ * when either FEP is inactive, or when there are no mass/charge/type
+ * perturbations. The parameter vectors for LJ-PME are likewise
+ * undefined when LJ-PME is not active. This works because
+ * bHaveChargeOrTypePerturbed handles the control flow. */
 void ewald_LRcorrection(int start, int end,
                         t_commrec *cr, int thread, t_forcerec *fr,
                         real *chargeA, real *chargeB,
                         real *C6A, real *C6B,
                         real *sigmaA, real *sigmaB,
                         real *sigma3A, real *sigma3B,
+                        gmx_bool bHaveChargeOrTypePerturbed,
                         gmx_bool calc_excl_corr,
                         t_blocka *excl, rvec x[],
                         matrix box, rvec mu_tot[],
@@ -76,7 +87,6 @@ void ewald_LRcorrection(int start, int end,
     tensor      dxdf_q, dxdf_lj;
     real        vol = box[XX][XX]*box[YY][YY]*box[ZZ][ZZ];
     real        L1_q, L1_lj, dipole_coeff, qqA, qqB, qqL, vr0_q, vr0_lj = 0;
-    gmx_bool    bFreeEnergy  = (chargeB != NULL);
     gmx_bool    bMolPBC      = fr->bMolPBC;
     gmx_bool    bDoingLBRule = (fr->ljpme_combination_rule == eljpmeLB);
 
@@ -146,7 +156,7 @@ void ewald_LRcorrection(int start, int end,
     {
         clear_mat(dxdf_lj);
     }
-    if ((calc_excl_corr || dipole_coeff != 0) && !bFreeEnergy)
+    if ((calc_excl_corr || dipole_coeff != 0) && !bHaveChargeOrTypePerturbed)
     {
         for (i = start; (i < end); i++)
         {
@@ -473,7 +483,7 @@ void ewald_LRcorrection(int start, int end,
     /* Global corrections only on master process */
     if (MASTER(cr) && thread == 0)
     {
-        for (q = 0; q < (bFreeEnergy ? 2 : 1); q++)
+        for (q = 0; q < (bHaveChargeOrTypePerturbed ? 2 : 1); q++)
         {
             if (calc_excl_corr)
             {
@@ -501,7 +511,7 @@ void ewald_LRcorrection(int start, int end,
             }
         }
     }
-    if (!bFreeEnergy)
+    if (!bHaveChargeOrTypePerturbed)
     {
         *Vcorr_q = Vdipole[0] - Vself_q[0] - Vexcl_q;
         if (EVDW_PME(fr->vdwtype))