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

filteredLinear2V.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::filteredLinear2VLimiter
00027 
00028 Description
00029     Class to generate weighting factors for the filteredLinear2V
00030     differencing scheme.
00031 
00032     The aim is to remove high-frequency modes with "staggering"
00033     characteristics from vector fields by comparing the face gradient in
00034     the direction of maximum gradient with both neighbouring cell gradients
00035     and introduce small amounts of upwind in order to damp these modes.
00036 
00037     Used in conjunction with the template class LimitedScheme.
00038 
00039 SourceFiles
00040     filteredLinear2V.C
00041 
00042 \*---------------------------------------------------------------------------*/
00043 
00044 #ifndef filteredLinear2V_H
00045 #define filteredLinear2V_H
00046 
00047 #include "vector.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 /*---------------------------------------------------------------------------*\
00055                  Class filteredLinear2VLimiter Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 template<class LimiterFunc>
00059 class filteredLinear2VLimiter
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     filteredLinear2VLimiter(Istream& is)
00082     :
00083         k_(readScalar(is)),
00084         l_(readScalar(is))
00085     {
00086         if (k_ < 0 || k_ > 1)
00087         {
00088             FatalIOErrorIn("filteredLinear2VLimiter(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("filteredLinear2VLimiter(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         vector dfV = phiN - phiP;
00118 
00119         // Scalar difference across the face
00120         // in the direction in which the difference is largest
00121         scalar df = dfV & dfV;
00122 
00123         // Twice differences across face-neighbour cells
00124         // in the direction in which the face-difference is largest
00125         scalar tdcP = 2*(dfV & (d & gradcP));
00126         scalar tdcN = 2*(dfV & (d & gradcN));
00127 
00128         // Calculate the limiter according to the sign of the face difference
00129         scalar limiter;
00130 
00131         if (df > 0)
00132         {
00133             limiter = l_
00134                 - k_*min(max(df - tdcP, 0), max(df - tdcN, 0))
00135                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + VSMALL);
00136         }
00137         else
00138         {
00139             limiter = l_
00140                 - k_*min(max(tdcP - df, 0), max(tdcN - df, 0))
00141                 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + VSMALL);
00142         }
00143 
00144         // Limit the limiter between linear and upwind
00145         return max(min(limiter, 1), 0);
00146     }
00147 };
00148 
00149 
00150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00151 
00152 } // End namespace Foam
00153 
00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00155 
00156 #endif
00157 
00158 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd