From 9e61f4095f51b7856ad7c68d2e4babdc42b76077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Thu, 29 Oct 2015 18:50:24 +0100
Subject: [PATCH] wallHeatFlux switches to Boussinesq when thermo package not
 found

---
 .../postProcessing/wall/wallHeatFlux/Make/options  |   5 +
 .../wall/wallHeatFlux/createFields.H               | 141 +++++++++++++++++----
 .../wall/wallHeatFlux/wallHeatFlux.C               |  44 +++++--
 3 files changed, 157 insertions(+), 33 deletions(-)

diff --git a/applications/utilities/postProcessing/wall/wallHeatFlux/Make/options b/applications/utilities/postProcessing/wall/wallHeatFlux/Make/options
index fdcd3d7..b134db7 100644
--- a/applications/utilities/postProcessing/wall/wallHeatFlux/Make/options
+++ b/applications/utilities/postProcessing/wall/wallHeatFlux/Make/options
@@ -1,6 +1,9 @@
 EXE_INC = \
     -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
+    -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
     -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
+    -I$(LIB_SRC)/transportModels \
+    -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \
     -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
     -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
     -I$(LIB_SRC)/transportModels/compressible/lnInclude \
@@ -11,6 +14,8 @@ EXE_INC = \
 
 EXE_LIBS = \
     -lturbulenceModels \
+    -lincompressibleTransportModels \
+    -lincompressibleTurbulenceModels \
     -lcompressibleTurbulenceModels \
     -lreactionThermophysicalModels \
     -lgenericPatchFields \
diff --git a/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H b/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
index 02043ef..7d8ee10 100644
--- a/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
+++ b/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
@@ -1,28 +1,14 @@
-autoPtr<basicThermo> thermo
-(
-    basicThermo::New(mesh)
-);
+autoPtr<surfaceScalarField> heatFlux;
 
-const volScalarField& h = thermo->he();
-
-// Register copy of thermo density
-volScalarField rho
+autoPtr<basicThermo> thermo
 (
-    IOobject
-    (
-        "rho",
-        runTime.timeName(),
-        mesh
-    ),
-    thermo->rho()
+    basicThermo::NewIfPresent(mesh,word::null,false)
 );
 
-// Construct turbulence model (if fluid)
 autoPtr<volVectorField> UPtr;
 autoPtr<surfaceScalarField> phiPtr;
-autoPtr<compressible::turbulenceModel> turbulence;
 
-if (isA<fluidThermo>(thermo()))
+if( (!thermo.valid()) || isA<fluidThermo>(thermo()) )
 {
     UPtr.reset
     (
@@ -39,22 +25,133 @@ if (isA<fluidThermo>(thermo()))
             mesh
         )
     );
-    const volVectorField& U = UPtr();
+}
+
+// Construct turbulence model (if fluid)
+autoPtr<volScalarField> rhoPtr;
+autoPtr<compressible::turbulenceModel> compressibleTurbulence;
+
+if (thermo.valid() && isA<fluidThermo>(thermo()))
+{
+    // Register copy of thermo density
+    rhoPtr.reset
+    (
+        new volScalarField
+        (
+            IOobject
+            (
+                "rho",
+                runTime.timeName(),
+                mesh
+            ),
+            thermo->rho()
+        )
+    );
+
+    const volScalarField rho = rhoPtr();
+    const volVectorField U = UPtr();
 
     #include "compressibleCreatePhi.H"
     // Copy phi to autoPtr. Rename to make sure copy is now registered as 'phi'.
     phi.rename("phiFluid");
     phiPtr.reset(new surfaceScalarField("phi", phi));
 
-    turbulence = compressible::turbulenceModel::New
+    compressibleTurbulence = compressible::turbulenceModel::New
     (
-        rho,
-        U,
+        rhoPtr(),
+        UPtr(),
         phiPtr(),
         refCast<const fluidThermo>(thermo())
     );
 }
 
+//If thermo package not found try Boussinesq
+autoPtr<volScalarField> T;
+autoPtr<volScalarField> alphat;
+autoPtr<volScalarField> rhok;
+
+autoPtr<incompressible::turbulenceModel> incompressibleTurbulence;
+autoPtr<singlePhaseTransportModel> laminarTransport;
+
+dimensionedScalar Pr("Pr", dimless, 1);
+dimensionedScalar rhoRef("rhoRef", dimDensity, 0);
+dimensionedScalar CpRef("CpRef", dimSpecificHeatCapacity, 0);
+
+if(!thermo.valid())
+{
+    T.reset
+    (
+        new volScalarField
+        (
+            IOobject
+            (
+                "T",
+                runTime.timeName(),
+                mesh,
+                IOobject::MUST_READ,
+                IOobject::NO_WRITE
+            ),
+            mesh
+        )
+    );
+
+    alphat.reset
+    (
+        new volScalarField
+        (
+            IOobject
+            (
+                "alphat",
+                runTime.timeName(),
+                mesh,
+                IOobject::MUST_READ,
+                IOobject::NO_WRITE
+            ),
+            mesh
+        )
+    );
+
+    rhok.reset
+    (
+        new volScalarField
+        (
+            IOobject
+            (
+                "rhok",
+                runTime.timeName(),
+                mesh,
+                IOobject::READ_IF_PRESENT,
+                IOobject::NO_WRITE
+            ),
+            mesh,
+            dimensionedScalar("rhok",dimless,1.0)
+        )
+    );
+
+    const volVectorField U = UPtr();
+
+    #include "createPhi.H"
+
+    phi.rename("phiFluid");
+    phiPtr.reset(new surfaceScalarField("phi", phi));
+
+    laminarTransport.reset
+    ( 
+        new singlePhaseTransportModel(UPtr(), phiPtr())
+    );
+
+    incompressibleTurbulence = incompressible::turbulenceModel::New
+    (
+        UPtr(), 
+        phiPtr(), 
+        laminarTransport()
+    );
+
+    laminarTransport().lookup("Pr") >> Pr;
+    laminarTransport().lookup("rhoRef") >> rhoRef;
+    laminarTransport().lookup("CpRef") >> CpRef;
+}
+
 //Read radiative heat flux if available
 volScalarField Qr
 (
diff --git a/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C b/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
index b087331..096b5bf 100644
--- a/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
+++ b/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
@@ -33,6 +33,8 @@ Description
 
 #include "fvCFD.H"
 #include "turbulentFluidThermoModel.H"
+#include "turbulentTransportModel.H"
+#include "singlePhaseTransportModel.H"
 #include "solidThermo.H"
 #include "wallFvPatch.H"
 
@@ -55,20 +57,40 @@ int main(int argc, char *argv[])
 
         #include "createFields.H"
 
-        surfaceScalarField heatFlux
-        (
-            fvc::interpolate
+        if(thermo.valid())
+        {
+            heatFlux.reset
             (
+                new surfaceScalarField
                 (
-                    turbulence.valid()
-                  ? turbulence->alphaEff()()
-                  : thermo->alpha()
+                    fvc::interpolate
+                    (
+                        (
+                            compressibleTurbulence.valid()
+                          ? compressibleTurbulence->alphaEff()()
+                          : thermo->alpha()
+                        )
+                    )*fvc::snGrad(thermo->he())
                 )
-            )*fvc::snGrad(h)
-        );
+            );
+        }
+        else
+        {
+            heatFlux.reset
+            (
+                new surfaceScalarField
+                (
+                    CpRef*rhoRef*
+                    fvc::interpolate
+                    (
+                        rhok()*(incompressibleTurbulence->nu()/Pr + alphat())
+                    )*fvc::snGrad(T())
+                )
+            );
+        }
 
         const surfaceScalarField::GeometricBoundaryField& patchHeatFlux =
-            heatFlux.boundaryField();
+            heatFlux().boundaryField();
 
         const volScalarField::GeometricBoundaryField& patchRadHeatFlux =
             Qr.boundaryField();
@@ -102,7 +124,7 @@ int main(int argc, char *argv[])
                 mesh
             ),
             mesh,
-            dimensionedScalar("wallHeatFlux", heatFlux.dimensions(), 0.0)
+            dimensionedScalar("wallHeatFlux", heatFlux().dimensions(), 0.0)
         );
 
         forAll(wallHeatFlux.boundaryField(), patchi)
@@ -123,7 +145,7 @@ int main(int argc, char *argv[])
                     mesh
                 ),
                 mesh,
-                dimensionedScalar("totalWallHeatFlux", heatFlux.dimensions(), 0.0)
+                dimensionedScalar("totalWallHeatFlux", heatFlux().dimensions(), 0.0)
             );
 
             forAll(totalWallHeatFlux.boundaryField(), patchi)
-- 
1.9.1

