From 47185ee83095d1b05fe8e5c3a605a5ac2f5d40a6 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Tue, 18 Aug 2015 12:13:09 +0100
Subject: [PATCH] functionObjects/fvTools/calcFvcGrad: Avoid clash with cached
 gradient field Resolves bug-report
 http://www.openfoam.org/mantisbt/view.php?id=1828

---
 .../fvTools/calcFvcGrad/calcFvcGradTemplates.C     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/postProcessing/functionObjects/fvTools/calcFvcGrad/calcFvcGradTemplates.C b/src/postProcessing/functionObjects/fvTools/calcFvcGrad/calcFvcGradTemplates.C
index c028628e370..89589a0c454 100644
--- a/src/postProcessing/functionObjects/fvTools/calcFvcGrad/calcFvcGradTemplates.C
+++ b/src/postProcessing/functionObjects/fvTools/calcFvcGrad/calcFvcGradTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2013 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012-2015 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -26,6 +26,8 @@ License
 #include "fvMesh.H"
 #include "fvcGrad.H"
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
 template<class Type>
 Foam::GeometricField
 <
@@ -35,6 +37,8 @@ Foam::GeometricField
 >&
 Foam::calcFvcGrad::gradField(const word& gradName, const dimensionSet& dims)
 {
+    Info<< "gradField" << endl;
+
     typedef typename outerProduct<vector, Type>::type gradType;
     typedef GeometricField<gradType, fvPatchField, volMesh> vfGradType;
 
@@ -73,8 +77,6 @@ Foam::calcFvcGrad::gradField(const word& gradName, const dimensionSet& dims)
 }
 
 
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
 template<class Type>
 void Foam::calcFvcGrad::calcGrad
 (
@@ -98,7 +100,8 @@ void Foam::calcFvcGrad::calcGrad
 
         vfGradType& field = gradField<Type>(resultName, vf.dimensions());
 
-        field = fvc::grad(vf);
+        // De-reference the tmp to avoid a clash with the cached grad field
+        field = fvc::grad(vf)();
 
         processed = true;
     }
@@ -108,7 +111,8 @@ void Foam::calcFvcGrad::calcGrad
 
         vfGradType& field = gradField<Type>(resultName, sf.dimensions());
 
-        field = fvc::grad(sf);
+        // De-reference the tmp to avoid a clash with the cached grad field
+        field = fvc::grad(sf)();
 
         processed = true;
     }
-- 
GitLab