From ff19bedbc3221036206b6a6cf4cfaf789586cbde Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 12 Feb 2020 16:52:17 +0000
Subject: [PATCH] BUG: SPDP mode: guaranteeing initial value. Fixes #1590.

In differing precisions the PrecisionAdaptor will copy
the input array element by element and this can trigger
NaN detection.
---
 .../primitiveMesh/primitiveMeshCellCentresAndVols.C   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C
index c7d4b1bd055..70c9afd550a 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C
@@ -82,15 +82,18 @@ void Foam::primitiveMesh::makeCellCentresAndVols
 {
     typedef Vector<solveScalar> solveVector;
 
+    // Clear the fields for accumulation. Note1: we're doing this before
+    // any precision conversion since this might complain about illegal numbers.
+    // Note2: zero is a special value which is perfectly converted into zero
+    //        in the new precision
+    cellCtrs_s = Zero;
+    cellVols_s = 0.0;
+
     PrecisionAdaptor<solveVector, vector> tcellCtrs(cellCtrs_s);
     Field<solveVector>& cellCtrs = tcellCtrs.ref();
     PrecisionAdaptor<solveScalar, scalar> tcellVols(cellVols_s);
     Field<solveScalar>& cellVols = tcellVols.ref();
 
-    // Clear the fields for accumulation
-    cellCtrs = Zero;
-    cellVols = 0.0;
-
     const labelList& own = faceOwner();
     const labelList& nei = faceNeighbour();
 
-- 
GitLab