From fc4de936c2278bcf059df7752d18ace6b5f36c7f Mon Sep 17 00:00:00 2001
From: henry <Henry Weller h.weller@opencfd.co.uk>
Date: Thu, 11 Sep 2008 15:36:03 +0100
Subject: [PATCH] Added Hilary's quadratic variant of filteretLinear2.

---
 src/finiteVolume/Make/files                   |   1 +
 .../filteredLinear3/filteredLinear3.C         |  48 +++++++
 .../filteredLinear3/filteredLinear3.H         | 120 +++++++++++++++++
 .../filteredLinear3/filteredLinear3V.H        | 123 ++++++++++++++++++
 4 files changed, 292 insertions(+)
 create mode 100644 src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.C
 create mode 100644 src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H
 create mode 100644 src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H

diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files
index 83dff1819d9..64565a192f0 100644
--- a/src/finiteVolume/Make/files
+++ b/src/finiteVolume/Make/files
@@ -186,6 +186,7 @@ $(limitedSchemes)/MC/MC.C
 $(limitedSchemes)/Phi/Phi.C
 $(limitedSchemes)/filteredLinear/filteredLinear.C
 $(limitedSchemes)/filteredLinear2/filteredLinear2.C
+$(limitedSchemes)/filteredLinear3/filteredLinear3.C
 
 multivariateSchemes = $(surfaceInterpolation)/multivariateSchemes
 $(multivariateSchemes)/multivariateSurfaceInterpolationScheme/multivariateSurfaceInterpolationSchemes.C
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.C b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.C
new file mode 100644
index 00000000000..e1da4b71066
--- /dev/null
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.C
@@ -0,0 +1,48 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "LimitedScheme.H"
+#include "filteredLinear3.H"
+#include "filteredLinear3V.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    makeLimitedSurfaceInterpolationScheme
+    (
+        filteredLinear3,
+        filteredLinear3Limiter
+    )
+
+    makeLimitedVSurfaceInterpolationScheme
+    (
+        filteredLinear3V,
+        filteredLinear3VLimiter
+    )
+}
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H
new file mode 100644
index 00000000000..b368192b310
--- /dev/null
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3.H
@@ -0,0 +1,120 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::filteredLinear3Limiter
+
+Description
+    Class to generate weighting factors for the filtered-linear-3
+    differencing scheme.
+
+    The aim is to remove high-frequency modes with "staggering"
+    characteristics by comparing the face gradient with both neighbouring
+    cell gradients and introduce small amounts of upwind in order to damp
+    these modes.
+
+    Used in conjunction with the template class LimitedScheme.
+
+SourceFiles
+    filteredLinear3.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef filteredLinear3_H
+#define filteredLinear3_H
+
+#include "vector.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                     Class filteredLinear3Limiter Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class LimiterFunc>
+class filteredLinear3Limiter
+:
+    public LimiterFunc
+{
+    // Private data
+
+        // Scaling corefficient for the gradient ratio,
+        // 0 = linear
+        // 1 = fully limited
+        scalar k_;
+
+public:
+
+    filteredLinear3Limiter(Istream& is)
+    :
+        k_(readScalar(is))
+    {
+        if (k_ < 0 || k_ > 1)
+        {
+            FatalIOErrorIn("filteredLinear3Limiter(Istream& is)", is)
+                << "coefficient = " << k_
+                << " should be >= 0 and <= 1"
+                << exit(FatalIOError);
+        }    
+    }
+
+    scalar limiter
+    (
+        const scalar cdWeight,
+        const scalar faceFlux,
+        const typename LimiterFunc::phiType& phiP,
+        const typename LimiterFunc::phiType& phiN,
+        const typename LimiterFunc::gradPhiType& gradcP,
+        const typename LimiterFunc::gradPhiType& gradcN,
+        const vector& d
+    ) const
+    {
+        // Difference across face
+        scalar df = phiN - phiP;
+
+        // Twice the differences across face-neighbour cells
+        scalar dP = 2*(d & gradcP);
+        scalar dN = 2*(d & gradcN);
+
+        // Calculate the limiter
+        scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), SMALL);
+
+        // Limit the limiter between linear and upwind
+        return max(min(limiter, 1), 0);
+    }
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H
new file mode 100644
index 00000000000..e44c334a1a7
--- /dev/null
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/filteredLinear3/filteredLinear3V.H
@@ -0,0 +1,123 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     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 2 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, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::filteredLinear3VLimiter
+
+Description
+    Class to generate weighting factors for the filteredLinear3V differencing
+    scheme.  The aim is to remove high-frequency modes with "staggering"
+    characteristics from vector fields by comparing the face gradient in the
+    direction of maximum gradient with both neighbouring cell gradients and
+    introduce small amounts of upwind in order to damp these modes.
+
+    Used in conjunction with the template class LimitedScheme.
+
+SourceFiles
+    filteredLinear3V.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef filteredLinear3V_H
+#define filteredLinear3V_H
+
+#include "vector.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                 Class filteredLinear3VLimiter Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class LimiterFunc>
+class filteredLinear3VLimiter
+:
+    public LimiterFunc
+{
+    // Private data
+
+        // Scaling corefficient for the gradient ratio,
+        // 0 = linear
+        // 1 = fully limited
+        scalar k_;
+
+public:
+
+    filteredLinear3VLimiter(Istream& is)
+    :
+        k_(readScalar(is))
+    {
+        if (k_ < 0 || k_ > 1)
+        {
+            FatalIOErrorIn("filteredLinear3VLimiter(Istream& is)", is)
+                << "coefficient = " << k_
+                << " should be >= 0 and <= 1"
+                << exit(FatalIOError);
+        }    
+    }
+
+    scalar limiter
+    (
+        const scalar cdWeight,
+        const scalar faceFlux,
+        const typename LimiterFunc::phiType& phiP,
+        const typename LimiterFunc::phiType& phiN,
+        const typename LimiterFunc::gradPhiType& gradcP,
+        const typename LimiterFunc::gradPhiType& gradcN,
+        const vector& d
+    ) const
+    {
+        // Difference across face
+        vector dfV = phiN - phiP;
+
+        // Scalar difference across the face
+        // in the direction in which the difference is largest
+        scalar df = dfV & dfV;
+
+        // Twice differences across face-neighbour cells
+        // in the direction in which the face-difference is largest
+        scalar dP = 2*(dfV & (d & gradcP));
+        scalar dN = 2*(dfV & (d & gradcN));
+
+        // Calculate the limiter
+        scalar limiter = 1 - k_*(dN - df)*(dP - df)/max(sqr(dN + dP), SMALL);
+
+        // Limit the limiter between linear and upwind
+        return max(min(limiter, 1), 0);
+    }
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab