00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::filteredLinear2Limiter 00026 00027 Description 00028 Class to generate weighting factors for the filteredLinear2 00029 differencing scheme. 00030 00031 The aim is to remove high-frequency modes with "staggering" 00032 characteristics by comparing the face gradient with both neighbouring 00033 cell gradients and introduce small amounts of upwind in order to damp 00034 these modes. 00035 00036 Used in conjunction with the template class LimitedScheme. 00037 00038 SourceFiles 00039 filteredLinear2.C 00040 00041 \*---------------------------------------------------------------------------*/ 00042 00043 #ifndef filteredLinear2_H 00044 #define filteredLinear2_H 00045 00046 #include <OpenFOAM/vector.H> 00047 00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00049 00050 namespace Foam 00051 { 00052 00053 /*---------------------------------------------------------------------------*\ 00054 Class filteredLinear2Limiter Declaration 00055 \*---------------------------------------------------------------------------*/ 00056 00057 template<class LimiterFunc> 00058 class filteredLinear2Limiter 00059 : 00060 public LimiterFunc 00061 { 00062 // Private data 00063 00064 // Scaling corefficient for the gradient ratio, 00065 // 0 = linear 00066 // 1 = fully limited 00067 scalar k_; 00068 00069 // Maximum allowed overshoot/undershoot relative to the difference 00070 // across the face. 00071 // On input: 00072 // 0 = no overshoot/undershoot 00073 // 1 = overshoot/undershoot equal to the difference across the face 00074 // Note: After input 1 is added to l_ 00075 scalar l_; 00076 00077 00078 public: 00079 00080 filteredLinear2Limiter(Istream& is) 00081 : 00082 k_(readScalar(is)), 00083 l_(readScalar(is)) 00084 { 00085 if (k_ < 0 || k_ > 1) 00086 { 00087 FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is) 00088 << "coefficient = " << k_ 00089 << " should be >= 0 and <= 1" 00090 << exit(FatalIOError); 00091 } 00092 00093 if (l_ < 0 || l_ > 1) 00094 { 00095 FatalIOErrorIn("filteredLinearV2Limiter(Istream& is)", is) 00096 << "coefficient = " << l_ 00097 << " should be >= 0 and <= 1" 00098 << exit(FatalIOError); 00099 } 00100 00101 l_ += 1.0; 00102 } 00103 00104 scalar limiter 00105 ( 00106 const scalar cdWeight, 00107 const scalar faceFlux, 00108 const typename LimiterFunc::phiType& phiP, 00109 const typename LimiterFunc::phiType& phiN, 00110 const typename LimiterFunc::gradPhiType& gradcP, 00111 const typename LimiterFunc::gradPhiType& gradcN, 00112 const vector& d 00113 ) const 00114 { 00115 // Difference across face 00116 scalar df = phiN - phiP; 00117 00118 // Twice the differences across face-neighbour cells 00119 scalar tdcP = 2*(d & gradcP); 00120 scalar tdcN = 2*(d & gradcN); 00121 00122 // Calculate the limiter according to the sign of the face difference 00123 scalar limiter; 00124 00125 if (df > 0) 00126 { 00127 limiter = l_ 00128 - k_*min(max(df - tdcP, 0), max(df - tdcN, 0)) 00129 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL); 00130 } 00131 else 00132 { 00133 limiter = l_ 00134 - k_*min(max(tdcP - df, 0), max(tdcN - df, 0)) 00135 /(max(mag(df), max(mag(tdcP), mag(tdcN))) + SMALL); 00136 } 00137 00138 // Limit the limiter between linear and upwind 00139 return max(min(limiter, 1), 0); 00140 } 00141 }; 00142 00143 00144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00145 00146 } // End namespace Foam 00147 00148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00149 00150 #endif 00151 00152 // ************************ vim: set sw=4 sts=4 et: ************************ //