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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::fv::cellMDLimitedGrad
28 
29 Group
30  grpFvGradSchemes
31 
32 Description
33  cellMDLimitedGrad gradient scheme applied to a runTime selected base
34  gradient scheme.
35 
36  The scalar limiter based on limiting the extrapolated face values
37  between the maximum and minimum cell and cell neighbour values and is
38  applied to the gradient in each face direction separately.
39 
40 SourceFiles
41  cellMDLimitedGrad.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef cellMDLimitedGrad_H
46 #define cellMDLimitedGrad_H
47 
48 #include "gradScheme.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace fv
58 {
59 
60 /*---------------------------------------------------------------------------*\
61  Class cellMDLimitedGrad Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class Type>
66 :
67  public fv::gradScheme<Type>
68 {
69  // Private Data
70 
71  tmp<fv::gradScheme<Type>> basicGradScheme_;
72 
73  //- Limiter coefficient
74  const scalar k_;
75 
76 
77  // Private Member Functions
78 
79  //- No copy construct
80  cellMDLimitedGrad(const cellMDLimitedGrad&) = delete;
81 
82  //- No copy assignment
83  void operator=(const cellMDLimitedGrad&) = delete;
84 
85 
86 public:
87 
88  //- RunTime type information
89  TypeName("cellMDLimited");
90 
91 
92  // Constructors
93 
94  //- Construct from mesh and schemeData
95  cellMDLimitedGrad(const fvMesh& mesh, Istream& schemeData)
96  :
97  gradScheme<Type>(mesh),
98  basicGradScheme_(fv::gradScheme<Type>::New(mesh, schemeData)),
99  k_(readScalar(schemeData))
100  {
101  if (k_ < 0 || k_ > 1)
102  {
103  FatalIOErrorInFunction(schemeData)
104  << "coefficient = " << k_
105  << " should be >= 0 and <= 1"
106  << exit(FatalIOError);
107  }
108  }
109 
110 
111  // Member Functions
112 
113  static inline void limitFace
114  (
116  const Type& maxDelta,
117  const Type& minDelta,
118  const vector& dcf
119  );
120 
121  //- Return the gradient of the given field to the gradScheme::grad
122  // for optional caching
123  virtual tmp
124  <
127  > calcGrad
128  (
130  const word& name
131  ) const;
132 };
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 template<>
139 (
140  vector& g,
141  const scalar& maxDelta,
142  const scalar& minDelta,
143  const vector& dcf
144 )
145 {
146  scalar extrapolate = dcf & g;
147 
148  if (extrapolate > maxDelta)
149  {
150  g = g + dcf*(maxDelta - extrapolate)/magSqr(dcf);
151  }
152  else if (extrapolate < minDelta)
153  {
154  g = g + dcf*(minDelta - extrapolate)/magSqr(dcf);
155  }
156 }
157 
158 
159 template<class Type>
161 (
163  const Type& maxDelta,
164  const Type& minDelta,
165  const vector& dcf
166 )
167 {
168  for (direction cmpt=0; cmpt<Type::nComponents; cmpt++)
169  {
170  vector gi(g[cmpt], g[cmpt+3], g[cmpt+6]);
172  (
173  gi,
174  maxDelta.component(cmpt),
175  minDelta.component(cmpt),
176  dcf
177  );
178  g[cmpt] = gi.x();
179  g[cmpt+3] = gi.y();
180  g[cmpt+6] = gi.z();
181  }
182 }
183 
184 
185 // * * * * * * * * Template Member Function Specialisations * * * * * * * * //
186 
187 template<>
189 (
190  const volScalarField& vsf,
191  const word& name
192 ) const;
193 
194 
195 template<>
197 (
198  const volVectorField& vsf,
199  const word& name
200 ) const;
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace fv
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 } // End namespace Foam
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::VectorSpace::component
const Cmpt & component(const direction) const
Definition: VectorSpaceI.H:87
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::FatalIOError
IOerror FatalIOError
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::fv::gradScheme::New
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:37
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::cellMDLimitedGrad::TypeName
TypeName("cellMDLimited")
RunTime type information.
Foam::fv::gradScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: gradScheme.H:124
Foam::fv::cellMDLimitedGrad::cellMDLimitedGrad
cellMDLimitedGrad(const fvMesh &mesh, Istream &schemeData)
Construct from mesh and schemeData.
Definition: cellMDLimitedGrad.H:94
gradScheme.H
Foam::fv::gradScheme
Abstract base class for gradient schemes.
Definition: gradScheme.H:62
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:24
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::fv::cellMDLimitedGrad::calcGrad
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.
Foam::Vector< scalar >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::fv::cellMDLimitedGrad
cellMDLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
Definition: cellMDLimitedGrad.H:64
Foam::fv::cellMDLimitedGrad::limitFace
static void limitFace(typename outerProduct< vector, Type >::type &g, const Type &maxDelta, const Type &minDelta, const vector &dcf)
Definition: cellMDLimitedGrad.H:160
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53