From 3e41c1004e119e0776912a2e8e5e96f2e627f494 Mon Sep 17 00:00:00 2001
From: Kutalmis Bercin <kutalmis.bercin@esi-group.com>
Date: Fri, 28 Aug 2020 11:06:45 +0100
Subject: [PATCH] ENH: yPlus: add option to disable wall function contributions
 (#1773)

  DOC: yPlus: add mathematical expressions
  TUT: yPlus: add the option example to pisoFoam/RAS/cavity
---
 src/functionObjects/field/yPlus/yPlus.C       | 19 +++++--
 src/functionObjects/field/yPlus/yPlus.H       | 49 ++++++++++++++++---
 .../pisoFoam/RAS/cavity/system/FOyPlus        |  3 ++
 3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/src/functionObjects/field/yPlus/yPlus.C b/src/functionObjects/field/yPlus/yPlus.C
index 8fc394738e7..745b10808dc 100644
--- a/src/functionObjects/field/yPlus/yPlus.C
+++ b/src/functionObjects/field/yPlus/yPlus.C
@@ -70,7 +70,8 @@ Foam::functionObjects::yPlus::yPlus
 )
 :
     fvMeshFunctionObject(name, runTime, dict),
-    writeFile(obr_, name, typeName, dict)
+    writeFile(obr_, name, typeName, dict),
+    useWallFunction_(true)
 {
     read(dict);
 
@@ -101,10 +102,14 @@ Foam::functionObjects::yPlus::yPlus
 
 bool Foam::functionObjects::yPlus::read(const dictionary& dict)
 {
-    fvMeshFunctionObject::read(dict);
-    writeFile::read(dict);
+    if (fvMeshFunctionObject::read(dict) && writeFile::read(dict))
+    {
+        useWallFunction_ = dict.getOrDefault<bool>("useWallFunction", true);
 
-    return true;
+        return true;
+    }
+
+    return false;
 }
 
 
@@ -139,7 +144,11 @@ bool Foam::functionObjects::yPlus::execute()
         {
             const fvPatch& patch = patches[patchi];
 
-            if (isA<nutWallFunctionFvPatchScalarField>(nutBf[patchi]))
+            if
+            (
+                isA<nutWallFunctionFvPatchScalarField>(nutBf[patchi])
+             && useWallFunction_
+            )
             {
                 const nutWallFunctionFvPatchScalarField& nutPf =
                     dynamic_cast<const nutWallFunctionFvPatchScalarField&>
diff --git a/src/functionObjects/field/yPlus/yPlus.H b/src/functionObjects/field/yPlus/yPlus.H
index 6614ef33ff2..67dc199c969 100644
--- a/src/functionObjects/field/yPlus/yPlus.H
+++ b/src/functionObjects/field/yPlus/yPlus.H
@@ -31,7 +31,27 @@ Group
     grpFieldFunctionObjects
 
 Description
-    Computes the near wall \f$y_1^+\f$ for turbulence models.
+    Computes the near wall \f$y_1^+\f$.
+
+    \f[
+        y_1^+ = \frac{u_* \, y_1}{\nu}
+    \f]
+
+    \f[
+        y_1^+ =
+            \frac{y_1 \sqrt{\nu_{eff} \, |\vec n \cdot \nabla \vec u_p| } }{\nu}
+    \f]
+
+    where
+    \vartable
+      y_1^+  | Wall-normal height of the first cell centre in wall units [-]
+      u_*    | Friction velocity                                         [m/s]
+      y_1    | Wall-normal height of the first cell centre               [m]
+      \nu    | Kinematic viscosity of fluid                              [m2/s]
+      \nu_{eff} | Effective patch kinematic viscosity                    [m2/s]
+      \vec n | Patch normal unit vector (into the domain)                [-]
+      \vec u_p | Patch velocity field                                    [m/s]
+    \endvartable
 
     Operands:
     \table
@@ -47,8 +67,11 @@ Usage
     yPlus1
     {
         // Mandatory entries (unmodifiable)
-        type        yPlus;
-        libs        (fieldFunctionObjects);
+        type               yPlus;
+        libs               (fieldFunctionObjects);
+
+        // Optional entries (runtime modifiable)
+        useWallFunction    true;
 
         // Optional (inherited) entries
         ...
@@ -57,9 +80,13 @@ Usage
 
     where the entries mean:
     \table
-      Property   | Description                        | Type | Req'd | Dflt
-      type       | Type name: yPlus                   | word |  yes  | -
-      libs       | Library name: fieldFunctionObjects | word |  yes  | -
+      Property   | Description                        | Type | Reqd | Dflt
+      type       | Type name: yPlus                   | word | yes  | -
+      libs       | Library name: fieldFunctionObjects | word | yes  | -
+      useWallFunction   | Flag to use the local expressions of <!--
+                      --> the selected wall function to compute yPlus, <!--
+                      --> otherwise directly compute yPlus from flow field <!--
+                      -->                             | bool | no   | true
     \endtable
 
     The inherited entries are elaborated in:
@@ -71,6 +98,10 @@ Usage
         <solver> -postProcess -func yPlus
     \endverbatim
 
+Note
+    - \c yPlus function object operates only
+    on either wall patches or patches using a \c nutWallFunction.
+
 See also
     - Foam::functionObject
     - Foam::functionObjects::fvMeshFunctionObject
@@ -106,6 +137,12 @@ class yPlus
     public fvMeshFunctionObject,
     public writeFile
 {
+    // Private Data
+
+        //- Flag to use the wall function expressions to compute yPlus
+        bool useWallFunction_;
+
+
     // Private Member Functions
 
         //- File header information
diff --git a/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOyPlus b/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOyPlus
index f18aeee4102..fee3a7cbbb7 100644
--- a/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOyPlus
+++ b/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOyPlus
@@ -12,6 +12,9 @@ yPlus1
     type            yPlus;
     libs            (fieldFunctionObjects);
 
+    // Optional entries
+    useWallFunction true;
+
     // Optional (inherited) entries
     writePrecision  10;
     writeToFile     true;
-- 
GitLab