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) 2011 OpenFOAM Foundation
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 
43 #include "gradScheme.H"
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  //- Return the gradient of the given field to the gradScheme::grad
120  // for optional caching
121  virtual tmp
122  <
125  > calcGrad
126  (
128  const word& name
129  ) const;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 template<>
137 (
138  vector& g,
139  const scalar& maxDelta,
140  const scalar& minDelta,
141  const vector& dcf
142 )
143 {
144  scalar extrapolate = dcf & g;
145 
146  if (extrapolate > maxDelta)
147  {
148  g = g + dcf*(maxDelta - extrapolate)/magSqr(dcf);
149  }
150  else if (extrapolate < minDelta)
151  {
152  g = g + dcf*(minDelta - extrapolate)/magSqr(dcf);
153  }
154 }
155 
156 
157 template<class Type>
159 (
161  const Type& maxDelta,
162  const Type& minDelta,
163  const vector& dcf
164 )
165 {
166  for (direction cmpt=0; cmpt<Type::nComponents; cmpt++)
167  {
168  vector gi(g[cmpt], g[cmpt+3], g[cmpt+6]);
170  (
171  gi,
172  maxDelta.component(cmpt),
173  minDelta.component(cmpt),
174  dcf
175  );
176  g[cmpt] = gi.x();
177  g[cmpt+3] = gi.y();
178  g[cmpt+6] = gi.z();
179  }
180 }
181 
182 
183 // * * * * * * * * Template Member Function Specialisations * * * * * * * * //
184 
185 template<>
187 (
188  const volScalarField& vsf,
189  const word& name
190 ) const;
191 
192 
193 template<>
195 (
196  const volVectorField& vsf,
197  const word& name
198 ) const;
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace fv
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 } // End namespace Foam
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #endif
212 
213 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
unsigned char direction
Definition: direction.H:43
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:75
dimensioned< scalar > magSqr(const dimensioned< Type > &)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Abstract base class for gradient schemes.
Definition: gradScheme.H:60
TypeName("cellMDLimited")
RunTime type information.
static void limitFace(typename outerProduct< vector, Type >::type &g, const Type &maxDelta, const Type &minDelta, const vector &dcf)
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const fvMesh & mesh() const
Return mesh reference.
Definition: gradScheme.H:122
Namespace for OpenFOAM.
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
const Cmpt & y() const
Definition: VectorI.H:71
IOerror FatalIOError
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
const Cmpt & x() const
Definition: VectorI.H:65
const Cmpt & z() const
Definition: VectorI.H:77
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
Generic GeometricField class.
const dimensionedVector & g
labelList fv(nPoints)
cellMDLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
A class for managing temporary objects.
Definition: PtrList.H:118
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:34