Fix indexing bug in electric field module
authorPaul Bauer <paul.bauer.q@gmail.com>
Wed, 9 Dec 2020 14:45:51 +0000 (14:45 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 9 Dec 2020 14:45:51 +0000 (14:45 +0000)
Improper refactoring in c8eca5d1f27cc34903718ade7d44527c22ec3d93 lead to
the module using the wrong maximum atom index for applying the electric
field forces to atoms.

Fixes #3800

docs/release-notes/2020/2020.5.rst
src/gromacs/applied_forces/electricfield.cpp

index d169b4fbb6198718b212f06034a3786a2606b7c0..b7966f176e782a171fdc7968c2f1ee7d3df62c66 100644 (file)
@@ -89,6 +89,24 @@ with an error about a too long pull distance in angle and dihedral geometries.
 
 :issue:`3613`
 
+Fix incorrect electric field strength with applied electric field
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+The electric field generated by the electric field module would be incorrect when
+used together with domain decomposition due to an error with indexing the field
+to all atoms instead of just those on the current domain.
+
+In overlap regions between domains, which have the thickness of the pairlist
+cut-off distance, the electric field would be doubled (or more with 2D or
+3D domain decomposition).
+
+To validate if a simulation has been affected by the issue, users should calculate
+the actual potential across the simulation box using the Poisson equation.
+If this potential agrees with the one provided as the input, a simulation was not affected.
+
+
+:issue:`3800`
+
 Fixes for ``gmx`` tools
 ^^^^^^^^^^^^^^^^^^^^^^^
 
index 5bc278142d330498555d45d9a2f2e26e8992a80d..08072556fcab9c54a1888dd9d3a926214fee105e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,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.
@@ -310,7 +310,7 @@ void ElectricField::calculateForces(const ForceProviderInput& forceProviderInput
             if (fieldStrength != 0)
             {
                 // TODO: Check parallellism
-                for (index i = 0; i != ssize(f); ++i)
+                for (int i = 0; i < mdatoms.homenr; ++i)
                 {
                     // NOTE: Not correct with perturbed charges
                     f[i][m] += mdatoms.chargeA[i] * fieldStrength;