FreeFOAM The Cross-Platform CFD Toolkit
cellMDLimitedGrad.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::fv::cellMDLimitedGrad
26 
27 Description
28  cellMDLimitedGrad gradient scheme applied to a runTime selected base
29  gradient scheme.
30 
31  The scalar limiter based on limiting the extrapolated face values
32  between the maximum and minimum cell and cell neighbour values and is
33  applied to the gradient in each face direction separately.
34 
35 SourceFiles
36  cellMDLimitedGrad.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef cellMDLimitedGrad_H
41 #define cellMDLimitedGrad_H
42 
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace fv
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class cellMDLimitedGrad Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type>
61 :
62  public fv::gradScheme<Type>
63 {
64  // Private Data
65 
66  tmp<fv::gradScheme<Type> > basicGradScheme_;
67 
68  //- Limiter coefficient
69  const scalar k_;
70 
71 
72  // Private Member Functions
73 
74  //- Disallow default bitwise copy construct
76 
77  //- Disallow default bitwise assignment
78  void operator=(const cellMDLimitedGrad&);
79 
80 
81 public:
82 
83  //- RunTime type information
84  TypeName("cellMDLimited");
85 
86 
87  // Constructors
88 
89  //- Construct from mesh and schemeData
90  cellMDLimitedGrad(const fvMesh& mesh, Istream& schemeData)
91  :
92  gradScheme<Type>(mesh),
93  basicGradScheme_(fv::gradScheme<Type>::New(mesh, schemeData)),
94  k_(readScalar(schemeData))
95  {
96  if (k_ < 0 || k_ > 1)
97  {
99  (
100  "cellMDLimitedGrad(const fvMesh&, Istream& schemeData)",
101  schemeData
102  ) << "coefficient = " << k_
103  << " should be >= 0 and <= 1"
104  << exit(FatalIOError);
105  }
106  }
107 
108 
109  // Member Functions
110 
111  static inline void limitFace
112  (
114  const Type& maxDelta,
115  const Type& minDelta,
116  const vector& dcf
117  );
118 
119  tmp
120  <
123  > grad
124  (
126  ) const;
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 template<>
134 (
135  vector& g,
136  const scalar& maxDelta,
137  const scalar& minDelta,
138  const vector& dcf
139 )
140 {
141  scalar extrapolate = dcf & g;
142 
143  if (extrapolate > maxDelta)
144  {
145  g = g + dcf*(maxDelta - extrapolate)/magSqr(dcf);
146  }
147  else if (extrapolate < minDelta)
148  {
149  g = g + dcf*(minDelta - extrapolate)/magSqr(dcf);
150  }
151 }
152 
153 
154 template<class Type>
156 (
158  const Type& maxDelta,
159  const Type& minDelta,
160  const vector& dcf
161 )
162 {
163  for(direction cmpt=0; cmpt<Type::nComponents; cmpt++)
164  {
165  vector gi(g[cmpt], g[cmpt+3], g[cmpt+6]);
167  (
168  gi,
169  maxDelta.component(cmpt),
170  minDelta.component(cmpt),
171  dcf
172  );
173  g[cmpt] = gi.x();
174  g[cmpt+3] = gi.y();
175  g[cmpt+6] = gi.z();
176  }
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace fv
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************ vim: set sw=4 sts=4 et: ************************ //