From 0463b16608cf3f216a7ffe9d82740afd743c327b Mon Sep 17 00:00:00 2001
From: sergio <sergio>
Date: Thu, 2 Feb 2012 10:20:33 +0000
Subject: [PATCH] ENH: nutAtmRoughWallFunction for atm boundary layer following
 the U profile described on atmVelocityinlet BC

---
 .../incompressible/RAS/Make/files             |   1 +
 ...tkAtmRoughWallFunctionFvPatchScalarField.C | 220 ++++++++++++++++++
 ...tkAtmRoughWallFunctionFvPatchScalarField.H | 198 ++++++++++++++++
 3 files changed, 419 insertions(+)
 create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.C
 create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.H

diff --git a/src/turbulenceModels/incompressible/RAS/Make/files b/src/turbulenceModels/incompressible/RAS/Make/files
index e28a6859039..d667a8b26ea 100644
--- a/src/turbulenceModels/incompressible/RAS/Make/files
+++ b/src/turbulenceModels/incompressible/RAS/Make/files
@@ -29,6 +29,7 @@ $(nutWallFunctions)/nutUSpaldingWallFunction/nutUSpaldingWallFunctionFvPatchScal
 $(nutWallFunctions)/nutUWallFunction/nutUWallFunctionFvPatchScalarField.C
 $(nutWallFunctions)/nutUTabulatedWallFunction/nutUTabulatedWallFunctionFvPatchScalarField.C
 $(nutWallFunctions)/nutLowReWallFunction/nutLowReWallFunctionFvPatchScalarField.C
+$(nutWallFunctions)/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.C
 
 epsilonWallFunctions = $(wallFunctions)/epsilonWallFunctions
 $(epsilonWallFunctions)/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C
diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.C
new file mode 100644
index 00000000000..2ec45c7f60b
--- /dev/null
+++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.C
@@ -0,0 +1,220 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "nutkAtmRoughWallFunctionFvPatchScalarField.H"
+#include "RASModel.H"
+#include "fvPatchFieldMapper.H"
+#include "volFields.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace incompressible
+{
+namespace RASModels
+{
+
+// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
+
+
+tmp<scalarField> nutkAtmRoughWallFunctionFvPatchScalarField::calcNut() const
+{
+    const label patchI = patch().index();
+
+    const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
+    const scalarField& y = rasModel.y()[patchI];
+    const tmp<volScalarField> tk = rasModel.k();
+    const volScalarField& k = tk();
+    const tmp<volScalarField> tnu = rasModel.nu();
+    const volScalarField& nu = tnu();
+    const scalarField& nuw = nu.boundaryField()[patchI];
+
+    const scalar Cmu25 = pow025(Cmu_);
+
+    tmp<scalarField> tnutw(new scalarField(*this));
+    scalarField& nutw = tnutw();
+
+    forAll(nutw, faceI)
+    {
+        label faceCellI = patch().faceCells()[faceI];
+
+        scalar uStar = Cmu25*sqrt(k[faceCellI]);
+        scalar yPlus = uStar*y[faceI]/nuw[faceI];
+
+        scalar Edash = (y[faceI] + z0_[faceI] - zGround_[faceI])/z0_[faceI];
+
+        scalar limitingNutw = max(nutw[faceI], nuw[faceI]);
+
+        // To avoid oscillations limit the change in the wall viscosity
+        // which is particularly important if it temporarily becomes zero
+        nutw[faceI] =
+            max
+            (
+                min
+                (
+                    nuw[faceI]
+                   *(yPlus*kappa_/log(max(Edash, 1+1e-4)) - 1),
+                    2*limitingNutw
+                ), 0.5*limitingNutw
+            );
+
+        if (debug)
+        {
+            Info<< "yPlus = " << yPlus
+                << ", Edash = " << Edash
+                << ", nutw = " << nutw[faceI]
+                << endl;
+        }
+    }
+
+    return tnutw;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+nutkAtmRoughWallFunctionFvPatchScalarField::
+nutkAtmRoughWallFunctionFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    nutkWallFunctionFvPatchScalarField(p, iF),
+    z0_(p.size(), 0.0),
+    zGround_(p.size(), 0.0)
+{}
+
+
+nutkAtmRoughWallFunctionFvPatchScalarField::
+nutkAtmRoughWallFunctionFvPatchScalarField
+(
+    const nutkAtmRoughWallFunctionFvPatchScalarField& ptf,
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    nutkWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
+    z0_(ptf.z0_, mapper),
+    zGround_(ptf.zGround_, mapper)
+{}
+
+
+nutkAtmRoughWallFunctionFvPatchScalarField::
+nutkAtmRoughWallFunctionFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    nutkWallFunctionFvPatchScalarField(p, iF, dict),
+    z0_("z0", dict, p.size()),
+    zGround_("zGround", dict, p.size())
+{}
+
+
+nutkAtmRoughWallFunctionFvPatchScalarField::
+nutkAtmRoughWallFunctionFvPatchScalarField
+(
+    const nutkAtmRoughWallFunctionFvPatchScalarField& rwfpsf
+)
+:
+    nutkWallFunctionFvPatchScalarField(rwfpsf),
+    z0_(rwfpsf.z0_),
+    zGround_(rwfpsf.zGround_)
+{}
+
+
+nutkAtmRoughWallFunctionFvPatchScalarField::
+nutkAtmRoughWallFunctionFvPatchScalarField
+(
+    const nutkAtmRoughWallFunctionFvPatchScalarField& rwfpsf,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    nutkWallFunctionFvPatchScalarField(rwfpsf, iF),
+    z0_(rwfpsf.z0_),
+    zGround_(rwfpsf.zGround_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void nutkAtmRoughWallFunctionFvPatchScalarField::autoMap
+(
+    const fvPatchFieldMapper& m
+)
+{
+    nutkWallFunctionFvPatchScalarField::autoMap(m);
+    z0_.autoMap(m);
+    zGround_.autoMap(m);
+}
+
+
+void nutkAtmRoughWallFunctionFvPatchScalarField::rmap
+(
+    const fvPatchScalarField& ptf,
+    const labelList& addr
+)
+{
+    nutkWallFunctionFvPatchScalarField::rmap(ptf, addr);
+
+    const nutkAtmRoughWallFunctionFvPatchScalarField& nrwfpsf =
+        refCast<const nutkAtmRoughWallFunctionFvPatchScalarField>(ptf);
+
+    z0_.rmap(nrwfpsf.z0_, addr);
+    zGround_.rmap(nrwfpsf.zGround_, addr);
+}
+
+
+void nutkAtmRoughWallFunctionFvPatchScalarField::write(Ostream& os) const
+{
+    fvPatchField<scalar>::write(os);
+    writeLocalEntries(os);
+    z0_.writeEntry("z0", os);
+    zGround_.writeEntry("zGround", os);
+    writeEntry("value", os);
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+makePatchTypeField
+(
+    fvPatchScalarField,
+    nutkAtmRoughWallFunctionFvPatchScalarField
+);
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace RASModels
+} // End namespace incompressible
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.H
new file mode 100644
index 00000000000..803985ced7e
--- /dev/null
+++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkAtmRoughWallFunction/nutkAtmRoughWallFunctionFvPatchScalarField.H
@@ -0,0 +1,198 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::incompressible::RASModels::
+    nutkAtmRoughWallFunctionFvPatchScalarField
+
+Description
+    Boundary condition for turbulent (kinematic) viscosity for atmospheric
+    velocity profiles.
+    Desinged to be used togheter with atmBoundaryLayerInletVelocity.
+    It follows  U = (Ustar/K) ln((z - zGround + z0)/z0)
+
+    where:
+
+        Ustar is the frictional velocity
+        K is karman's constant
+        z0 is the surface roughness lenght
+        z is the verical coordinate
+        zGround is the minumum coordinate value in z direction.
+
+
+SourceFiles
+    nutkAtmRoughWallFunctionFvPatchScalarField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef nutkAtmRoughWallFunctionFvPatchScalarField_H
+#define nutkAtmRoughWallFunctionFvPatchScalarField_H
+
+#include "nutkWallFunctionFvPatchScalarField.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace incompressible
+{
+namespace RASModels
+{
+
+/*---------------------------------------------------------------------------*\
+           Class nutkAtmRoughWallFunctionFvPatchScalarField Declaration
+\*---------------------------------------------------------------------------*/
+
+class nutkAtmRoughWallFunctionFvPatchScalarField
+:
+    public nutkWallFunctionFvPatchScalarField
+{
+protected:
+
+    // Protected data
+
+        //- Surface roughness lenght
+        scalarField z0_;
+
+        //- Minimum corrdinate value in z direction
+        scalarField zGround_;
+
+
+    // Protected Member Functions
+
+
+        //- Calculate the turbulence viscosity
+        virtual tmp<scalarField> calcNut() const;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("nutkAtmRoughWallFunction");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        nutkAtmRoughWallFunctionFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct from patch, internal field and dictionary
+        nutkAtmRoughWallFunctionFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given
+        //  nutkAtmRoughWallFunctionFvPatchScalarField
+        //  onto a new patch
+        nutkAtmRoughWallFunctionFvPatchScalarField
+        (
+            const nutkAtmRoughWallFunctionFvPatchScalarField&,
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct as copy
+        nutkAtmRoughWallFunctionFvPatchScalarField
+        (
+            const nutkAtmRoughWallFunctionFvPatchScalarField&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchScalarField> clone() const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new nutkAtmRoughWallFunctionFvPatchScalarField(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        nutkAtmRoughWallFunctionFvPatchScalarField
+        (
+            const nutkAtmRoughWallFunctionFvPatchScalarField&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct and return a clone setting internal field reference
+        virtual tmp<fvPatchScalarField> clone
+        (
+            const DimensionedField<scalar, volMesh>& iF
+        ) const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new nutkAtmRoughWallFunctionFvPatchScalarField(*this, iF)
+            );
+        }
+
+
+    // Member functions
+
+        // Acces functions
+
+            // Return z0
+            scalarField& z0()
+            {
+                return z0_;
+            }
+
+
+        // Mapping functions
+
+            //- Map (and resize as needed) from self given a mapping object
+            virtual void autoMap(const fvPatchFieldMapper&);
+
+            //- Reverse map the given fvPatchField onto this fvPatchField
+            virtual void rmap
+            (
+                const fvPatchScalarField&,
+                const labelList&
+            );
+
+
+        // I-O
+
+            //- Write
+            virtual void write(Ostream&) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace RASModels
+} // End namespace incompressible
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab