Merge commit d30f2cb6 from release-2020 into master
[alexxy/gromacs.git] / src / gromacs / applied_forces / densityfittingforceprovider.cpp
index 106831562de37c10b3d9e98faf16e22a6ffdee99..57f9e5a6a962d167d81cb120578fd0bd6f0bb7c7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -188,11 +188,6 @@ void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput
 
     state_.stepsSinceLastCalculation_ = 1;
 
-    // do nothing if there are no density fitting atoms on this node
-    if (localAtomSet_.numAtomsLocal() == 0)
-    {
-        return;
-    }
     transformedCoordinates_.resize(localAtomSet_.numAtomsLocal());
     // pick and copy atom coordinates
     std::transform(std::cbegin(localAtomSet_.localIndex()), std::cend(localAtomSet_.localIndex()),
@@ -223,7 +218,7 @@ void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput
     if (parameters_.normalizeDensities_)
     {
         real sum = std::accumulate(std::begin(amplitudes), std::end(amplitudes), 0.);
-        if (PAR(&forceProviderInput.cr_))
+        if (havePPDomainDecomposition(&forceProviderInput.cr_))
         {
             gmx_sum(1, &sum, &forceProviderInput.cr_);
         }
@@ -242,7 +237,7 @@ void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput
     }
 
     // communicate grid
-    if (PAR(&forceProviderInput.cr_))
+    if (havePPDomainDecomposition(&forceProviderInput.cr_))
     {
         // \todo update to real once GaussTransform class returns real
         gmx_sumf(gaussTransform_.view().mapping().required_span_size(),
@@ -272,10 +267,13 @@ void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput
         ++densityForceIterator;
     }
 
-    // calculate corresponding potential energy
     const float similarity = measure_.similarity(gaussTransform_.constView());
-    const real energy = -similarity * parameters_.forceConstant_ * state_.adaptiveForceConstantScale_;
-    forceProviderOutput->enerd_.term[F_DENSITYFITTING] += energy;
+    if (MASTER(&(forceProviderInput.cr_)))
+    {
+        // calculate corresponding potential energy
+        const real energy = -similarity * parameters_.forceConstant_ * state_.adaptiveForceConstantScale_;
+        forceProviderOutput->enerd_.term[F_DENSITYFITTING] += energy;
+    }
 
     if (expAverageSimilarity_.has_value())
     {
@@ -287,7 +285,8 @@ void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput
         }
         else
         {
-            state_.adaptiveForceConstantScale_ *= 1._real + expAverageSimilarity_->inverseTimeConstant();
+            state_.adaptiveForceConstantScale_ *=
+                    1._real + 2 * expAverageSimilarity_->inverseTimeConstant();
         }
     }
 }