From 94c209c6d6bbc51139d3884a698e0c0a387dcfa1 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Fri, 3 Mar 2017 22:03:29 +0000
Subject: [PATCH] CrankNicolsonDdtScheme, backwardDdtScheme: Ensure the V00
 field is cached

---
 .../CrankNicolsonDdtScheme.C                  | 52 +++++++++----------
 .../CrankNicolsonDdtScheme.H                  | 10 +++-
 .../backwardDdtScheme/backwardDdtScheme.H     | 12 +++--
 3 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C
index 21e1ace876c..956898e4bd8 100644
--- a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C
+++ b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -200,11 +200,11 @@ scalar CrankNicolsonDdtScheme<Type>::coef_
 {
     if (mesh().time().timeIndex() - ddt0.startTimeIndex() > 0)
     {
-        return 1.0 + ocCoeff_;
+        return 1 + ocCoeff_;
     }
     else
     {
-        return 1.0;
+        return 1;
     }
 }
 
@@ -218,11 +218,11 @@ scalar CrankNicolsonDdtScheme<Type>::coef0_
 {
     if (mesh().time().timeIndex() - ddt0.startTimeIndex() > 1)
     {
-        return 1.0 + ocCoeff_;
+        return 1 + ocCoeff_;
     }
     else
     {
-        return 1.0;
+        return 1;
     }
 }
 
@@ -256,7 +256,7 @@ tmp<GeoField> CrankNicolsonDdtScheme<Type>::offCentre_
     const GeoField& ddt0
 ) const
 {
-    if (ocCoeff_ < 1.0)
+    if (ocCoeff_ < 1)
     {
         return ocCoeff_*ddt0;
     }
@@ -368,7 +368,7 @@ CrankNicolsonDdtScheme<Type>::fvcDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -456,7 +456,7 @@ CrankNicolsonDdtScheme<Type>::fvcDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -546,7 +546,7 @@ CrankNicolsonDdtScheme<Type>::fvcDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -647,7 +647,7 @@ CrankNicolsonDdtScheme<Type>::fvcDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -773,7 +773,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
 
     fvMatrix<Type>& fvm = tfvm.ref();
 
-    scalar rDtCoef = rDtCoef_(ddt0).value();
+    const scalar rDtCoef = rDtCoef_(ddt0).value();
     fvm.diag() = rDtCoef*mesh().V();
 
     vf.oldTime().oldTime();
@@ -782,7 +782,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -855,7 +855,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     );
     fvMatrix<Type>& fvm = tfvm.ref();
 
-    scalar rDtCoef = rDtCoef_(ddt0).value();
+    const scalar rDtCoef = rDtCoef_(ddt0).value();
     fvm.diag() = rDtCoef*rho.value()*mesh().V();
 
     vf.oldTime().oldTime();
@@ -864,7 +864,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -937,7 +937,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     );
     fvMatrix<Type>& fvm = tfvm.ref();
 
-    scalar rDtCoef = rDtCoef_(ddt0).value();
+    const scalar rDtCoef = rDtCoef_(ddt0).value();
     fvm.diag() = rDtCoef*rho.primitiveField()*mesh().V();
 
     vf.oldTime().oldTime();
@@ -947,7 +947,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -1028,7 +1028,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     );
     fvMatrix<Type>& fvm = tfvm.ref();
 
-    scalar rDtCoef = rDtCoef_(ddt0).value();
+    const scalar rDtCoef = rDtCoef_(ddt0).value();
     fvm.diag() = rDtCoef*alpha.primitiveField()*rho.primitiveField()*mesh().V();
 
     vf.oldTime().oldTime();
@@ -1039,7 +1039,7 @@ CrankNicolsonDdtScheme<Type>::fvmDdt
     {
         if (evaluate(ddt0))
         {
-            scalar rDtCoef0 = rDtCoef0_(ddt0).value();
+            const scalar rDtCoef0 = rDtCoef0_(ddt0).value();
 
             ddt0.primitiveFieldRef() =
             (
@@ -1124,14 +1124,14 @@ CrankNicolsonDdtScheme<Type>::fvcDdtUfCorr
     DDt0Field<GeometricField<Type, fvPatchField, volMesh>>& ddt0 =
         ddt0_<GeometricField<Type, fvPatchField, volMesh>>
         (
-            "ddt0(" + U.name() + ')',
+            "ddtCorrDdt0(" + U.name() + ')',
             U.dimensions()
         );
 
     DDt0Field<GeometricField<Type, fvsPatchField, surfaceMesh>>& dUfdt0 =
         ddt0_<GeometricField<Type, fvsPatchField, surfaceMesh>>
         (
-            "ddt0(" + Uf.name() + ')',
+            "ddtCorrDdt0(" + Uf.name() + ')',
             Uf.dimensions()
         );
 
@@ -1185,14 +1185,14 @@ CrankNicolsonDdtScheme<Type>::fvcDdtPhiCorr
     DDt0Field<GeometricField<Type, fvPatchField, volMesh>>& ddt0 =
         ddt0_<GeometricField<Type, fvPatchField, volMesh>>
         (
-            "ddt0(" + U.name() + ')',
+            "ddtCorrDdt0(" + U.name() + ')',
             U.dimensions()
         );
 
     DDt0Field<fluxFieldType>& dphidt0 =
         ddt0_<fluxFieldType>
         (
-            "ddt0(" + phi.name() + ')',
+            "ddtCorrDdt0(" + phi.name() + ')',
             phi.dimensions()
         );
 
@@ -1254,14 +1254,14 @@ CrankNicolsonDdtScheme<Type>::fvcDdtUfCorr
         DDt0Field<GeometricField<Type, fvPatchField, volMesh>>& ddt0 =
             ddt0_<GeometricField<Type, fvPatchField, volMesh>>
             (
-                "ddt0(" + rho.name() + ',' + U.name() + ')',
+                "ddtCorrDdt0(" + rho.name() + ',' + U.name() + ')',
                 U.dimensions()
             );
 
         DDt0Field<GeometricField<Type, fvsPatchField, surfaceMesh>>& dUfdt0 =
             ddt0_<GeometricField<Type, fvsPatchField, surfaceMesh>>
             (
-                "ddt0(" + Uf.name() + ')',
+                "ddtCorrDdt0(" + Uf.name() + ')',
                 Uf.dimensions()
             );
 
@@ -1349,14 +1349,14 @@ CrankNicolsonDdtScheme<Type>::fvcDdtPhiCorr
         DDt0Field<GeometricField<Type, fvPatchField, volMesh>>& ddt0 =
             ddt0_<GeometricField<Type, fvPatchField, volMesh>>
             (
-                "ddt0(" + rho.name() + ',' + U.name() + ')',
+                "ddtCorrDdt0(" + rho.name() + ',' + U.name() + ')',
                 U.dimensions()
             );
 
         DDt0Field<fluxFieldType>& dphidt0 =
             ddt0_<fluxFieldType>
             (
-                "ddt0(" + phi.name() + ')',
+                "ddtCorrDdt0(" + phi.name() + ')',
                 phi.dimensions()
             );
 
diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.H b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.H
index 62d6778f0c9..42fc3328ccb 100644
--- a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.H
+++ b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -198,7 +198,10 @@ public:
         :
             ddtScheme<Type>(mesh),
             ocCoeff_(1.0)
-        {}
+        {
+            // Ensure the old-old-time cell volumes are available
+            mesh.V00();
+        }
 
         //- Construct from mesh and Istream
         CrankNicolsonDdtScheme(const fvMesh& mesh, Istream& is)
@@ -215,6 +218,9 @@ public:
                     << " should be >= 0 and <= 1"
                     << exit(FatalIOError);
             }
+
+            // Ensure the old-old-time cell volumes are available
+            mesh.V00();
         }
 
 
diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/backwardDdtScheme/backwardDdtScheme.H b/src/finiteVolume/finiteVolume/ddtSchemes/backwardDdtScheme/backwardDdtScheme.H
index 0833cda7a4b..0b9c82b6dc4 100644
--- a/src/finiteVolume/finiteVolume/ddtSchemes/backwardDdtScheme/backwardDdtScheme.H
+++ b/src/finiteVolume/finiteVolume/ddtSchemes/backwardDdtScheme/backwardDdtScheme.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -89,13 +89,19 @@ public:
         backwardDdtScheme(const fvMesh& mesh)
         :
             ddtScheme<Type>(mesh)
-        {}
+        {
+            // Ensure the old-old-time cell volumes are available
+            mesh.V00();
+        }
 
         //- Construct from mesh and Istream
         backwardDdtScheme(const fvMesh& mesh, Istream& is)
         :
             ddtScheme<Type>(mesh, is)
-        {}
+        {
+            // Ensure the old-old-time cell volumes are available
+            mesh.V00();
+        }
 
 
     // Member Functions
-- 
GitLab