OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

filteredLinear2.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::filteredLinear2Limiter
00027 
00028 Description
00029     Class to generate weighting factors for the filteredLinear2
00030     differencing scheme.
00031 
00032     The aim is to remove high-frequency modes with "staggering"
00033     characteristics by comparing the face gradient with both neighbouring
00034     cell gradients and introduce small amounts of upwind in order to damp
00035     these modes.
00036 
00037     Used in conjunction with the template class LimitedScheme.
00038 
00039 SourceFiles
00040     filteredLinear2.C
00041 
00042 \*---------------------------------------------------------------------------*/
00043 
00044 #ifndef filteredLinear2_H
00045 #define filteredLinear2_H
00046 
00047 #include "vector.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 /*---------------------------------------------------------------------------*\
00055                      Class filteredLinear2Limiter Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 template<class LimiterFunc>
00059 class filteredLinear2Limiter
00060 :
00061     public LimiterFunc
00062 {
00063     // Private data
00064 
00065         // Scaling corefficient for the gradient ratio,
00066         // 0 = linear
00067         // 1 = fully limited
00068         scalar k_;
00069 
00070         // Maximum allowed overshoot/undershoot relative to the difference
00071         // across the face.
00072         // On input:
00073         //     0 = no overshoot/undershoot
00074         //     1 = overshoot/undershoot equal to the difference across the face
00075         // Note: After input 1 is added to l_
00076         scalar l_;
00077 
00078 
00079 public:
00080 
00081     filteredLinear2Limiter(Istream& is)
00082     :
00083         k_(readScalar(is)),
00084         l_(readScalar(is))
00085     {
00086         if (k_ < 0 || k_ > 1)
00087         {
00088             FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is)
00089                 << "coefficient = " << k_
00090                 << " should be >= 0 and <= 1"
00091                 << exit(FatalIOError);
00092         }
00093 
00094         if (l_ < 0 || l_ > 1)
00095         {
00096             FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is)
00097                 << "coefficient = " << l_
00098                 << " should be >= 0 and <= 1"
00099                 << exit(FatalIOError);
00100         }
00101 
00102         l_ += 1.0;
00103     }
00104 
00105     scalar limiter
00106     (
00107         const scalar cdWeight,
00108         const scalar faceFlux,
00109         const typename LimiterFunc::phiType& phiP,
00110         const typename LimiterFunc::phiType& phiN,
00111         const typename LimiterFunc::gradPhiType& gradcP,
00112         const typename LimiterFunc::gradPhiType& gradcN,
00113         const vector& d
00114     ) const
00115     {
00116         // Difference across face
00117         scalar df = phiN - phiP;
00118 
00119         // Twice the differences across face-neighbour cells
00120         scalar tdcP = 2*(d & gradcP);
00121         scalar tdcN = 2*(d & gradcN);
00122 
00123         // Calculate the limiter according to the sign of the face difference
00124         scalar limiter;
00125 
00126         if (df > 0)
00127         {
00128             limiter = l_
00129                 - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
00130                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
00131         }
00132         else
00133         {
00134             limiter = l_
00135                 - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
00136                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL);
00137         }
00138 
00139         // Limit the limiter between linear and upwind
00140         return max(min(limiter, 1), 0);
00141     }
00142 };
00143 
00144 
00145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00146 
00147 } // End namespace Foam
00148 
00149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00150 
00151 #endif
00152 
00153 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd