From fa191d345638001feba98e49d29c7be2c942c5cb Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Fri, 15 Jan 2016 14:47:56 +0000
Subject: [PATCH] functionObjects/utilities/scalarTransport: Set UName_ during
 construction for boundaryTypes() Resolves bug-report
 http://www.openfoam.org/mantisbt/view.php?id=1972

---
 .../scalarTransport/scalarTransport.C         | 178 ++++++++----------
 .../scalarTransport/scalarTransport.H         |   5 +-
 2 files changed, 83 insertions(+), 100 deletions(-)

diff --git a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C
index b3412b0555c..8e0b2bbfc33 100644
--- a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C
+++ b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2015 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012-2016 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -149,10 +149,9 @@ Foam::scalarTransport::scalarTransport
 :
     name_(name),
     mesh_(refCast<const fvMesh>(obr)),
-    active_(true),
-    phiName_("phi"),
-    UName_("U"),
-    rhoName_("rho"),
+    phiName_(dict.lookupOrDefault<word>("phiName", "phi")),
+    UName_(dict.lookupOrDefault<word>("UName", "U")),
+    rhoName_(dict.lookupOrDefault<word>("rhoName", "rho")),
     DT_(0.0),
     userDT_(false),
     resetOnStartUp_(false),
@@ -193,137 +192,124 @@ Foam::scalarTransport::~scalarTransport()
 
 void Foam::scalarTransport::read(const dictionary& dict)
 {
-    if (active_)
-    {
-        Info<< type() << ":" << nl;
+    Info<< type() << ":" << nl;
 
-        phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
-        UName_ = dict.lookupOrDefault<word>("UName", "U");
-        rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho");
+    phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
+    UName_ = dict.lookupOrDefault<word>("UName", "U");
+    rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho");
 
-        userDT_ = false;
-        if (dict.readIfPresent("DT", DT_))
-        {
-            userDT_ = true;
-        }
+    userDT_ = false;
+    if (dict.readIfPresent("DT", DT_))
+    {
+        userDT_ = true;
+    }
 
-        dict.lookup("resetOnStartUp") >> resetOnStartUp_;
+    dict.lookup("resetOnStartUp") >> resetOnStartUp_;
 
-        dict.readIfPresent("nCorr", nCorr_);
+    dict.readIfPresent("nCorr", nCorr_);
 
-        dict.lookup("autoSchemes") >> autoSchemes_;
+    dict.lookup("autoSchemes") >> autoSchemes_;
 
-        fvOptions_.reset(dict.subDict("fvOptions"));
-    }
+    fvOptions_.reset(dict.subDict("fvOptions"));
 }
 
 
 void Foam::scalarTransport::execute()
 {
-    if (active_)
-    {
-        Info<< type() << " output:" << endl;
+    Info<< type() << " output:" << endl;
 
-        const surfaceScalarField& phi =
-            mesh_.lookupObject<surfaceScalarField>(phiName_);
+    const surfaceScalarField& phi =
+        mesh_.lookupObject<surfaceScalarField>(phiName_);
 
-        // calculate the diffusivity
-        volScalarField DT(this->DT(phi));
+    // calculate the diffusivity
+    volScalarField DT(this->DT(phi));
 
-        // set schemes
-        word schemeVar = T_.name();
-        if (autoSchemes_)
-        {
-            schemeVar = UName_;
-        }
+    // set schemes
+    word schemeVar = T_.name();
+    if (autoSchemes_)
+    {
+        schemeVar = UName_;
+    }
 
-        word divScheme("div(phi," + schemeVar + ")");
-        word laplacianScheme("laplacian(" + DT.name() + "," + schemeVar + ")");
+    word divScheme("div(phi," + schemeVar + ")");
+    word laplacianScheme("laplacian(" + DT.name() + "," + schemeVar + ")");
 
-        // set under-relaxation coeff
-        scalar relaxCoeff = 0.0;
-        if (mesh_.relaxEquation(schemeVar))
-        {
-            relaxCoeff = mesh_.equationRelaxationFactor(schemeVar);
-        }
+    // set under-relaxation coeff
+    scalar relaxCoeff = 0.0;
+    if (mesh_.relaxEquation(schemeVar))
+    {
+        relaxCoeff = mesh_.equationRelaxationFactor(schemeVar);
+    }
 
-        if (phi.dimensions() == dimMass/dimTime)
-        {
-            const volScalarField& rho =
-                mesh_.lookupObject<volScalarField>(rhoName_);
+    if (phi.dimensions() == dimMass/dimTime)
+    {
+        const volScalarField& rho =
+            mesh_.lookupObject<volScalarField>(rhoName_);
 
-            // solve
-            for (label i = 0; i <= nCorr_; i++)
-            {
-                fvScalarMatrix TEqn
-                (
-                    fvm::ddt(rho, T_)
-                  + fvm::div(phi, T_, divScheme)
-                  - fvm::laplacian(DT, T_, laplacianScheme)
-                 ==
-                    fvOptions_(rho, T_)
-                );
+        // solve
+        for (label i = 0; i <= nCorr_; i++)
+        {
+            fvScalarMatrix TEqn
+            (
+                fvm::ddt(rho, T_)
+              + fvm::div(phi, T_, divScheme)
+              - fvm::laplacian(DT, T_, laplacianScheme)
+             ==
+                fvOptions_(rho, T_)
+            );
 
-                TEqn.relax(relaxCoeff);
+            TEqn.relax(relaxCoeff);
 
-                fvOptions_.constrain(TEqn);
+            fvOptions_.constrain(TEqn);
 
-                TEqn.solve(mesh_.solverDict(schemeVar));
-            }
+            TEqn.solve(mesh_.solverDict(schemeVar));
         }
-        else if (phi.dimensions() == dimVolume/dimTime)
+    }
+    else if (phi.dimensions() == dimVolume/dimTime)
+    {
+        // solve
+        for (label i = 0; i <= nCorr_; i++)
         {
-            // solve
-            for (label i = 0; i <= nCorr_; i++)
-            {
-                fvScalarMatrix TEqn
-                (
-                    fvm::ddt(T_)
-                  + fvm::div(phi, T_, divScheme)
-                  - fvm::laplacian(DT, T_, laplacianScheme)
-                 ==
-                    fvOptions_(T_)
-                );
+            fvScalarMatrix TEqn
+            (
+                fvm::ddt(T_)
+              + fvm::div(phi, T_, divScheme)
+              - fvm::laplacian(DT, T_, laplacianScheme)
+             ==
+                fvOptions_(T_)
+            );
 
-                TEqn.relax(relaxCoeff);
+            TEqn.relax(relaxCoeff);
 
-                fvOptions_.constrain(TEqn);
+            fvOptions_.constrain(TEqn);
 
-                TEqn.solve(mesh_.solverDict(schemeVar));
-            }
-        }
-        else
-        {
-            FatalErrorInFunction
-                << "Incompatible dimensions for phi: " << phi.dimensions() << nl
-                << "Dimensions should be " << dimMass/dimTime << " or "
-                << dimVolume/dimTime << endl;
+            TEqn.solve(mesh_.solverDict(schemeVar));
         }
-
-        Info<< endl;
     }
+    else
+    {
+        FatalErrorInFunction
+            << "Incompatible dimensions for phi: " << phi.dimensions() << nl
+            << "Dimensions should be " << dimMass/dimTime << " or "
+            << dimVolume/dimTime << endl;
+    }
+
+    Info<< endl;
 }
 
 
 void Foam::scalarTransport::end()
 {
-    if (active_)
-    {
-        execute();
-    }
+    execute();
 }
 
 
 void Foam::scalarTransport::timeSet()
-{
-    // Do nothing
-}
+{}
 
 
 void Foam::scalarTransport::write()
-{
-    // Do nothing
-}
+{}
 
 
 // ************************************************************************* //
diff --git a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H
index 3006ca197dc..8ba8c9ce2c1 100644
--- a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H
+++ b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H
@@ -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-2016 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -78,9 +78,6 @@ class scalarTransport
         //- Reference to the mesh database
         const fvMesh& mesh_;
 
-        //- On/off switch
-        bool active_;
-
         //- Name of flux field (optional)
         word phiName_;
 
-- 
GitLab