cellLimitedGrad.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::cellLimitedGrad
28 
29 Group
30  grpFvGradSchemes
31 
32 Description
33  cellLimitedGrad gradient scheme applied to a runTime selected base gradient
34  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 all components of the gradient.
39 
40 SourceFiles
41  cellLimitedGrad.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef cellLimitedGrad_H
46 #define cellLimitedGrad_H
47 
48 #include "gradScheme.H"
49 #include "Field.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 namespace fv
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class cellLimitedGrad Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class Type, class Limiter>
64 class cellLimitedGrad
65 :
66  public fv::gradScheme<Type>,
67  public Limiter
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  void limitGradient
80  (
81  const Field<scalar>& limiter,
82  Field<vector>& gIf
83  ) const;
84 
85  void limitGradient
86  (
87  const Field<vector>& limiter,
88  Field<tensor>& gIf
89  ) const;
90 
91  //- No copy construct
92  cellLimitedGrad(const cellLimitedGrad&) = delete;
93 
94  //- No copy assignment
95  void operator=(const cellLimitedGrad&) = delete;
96 
97 
98 public:
99 
100  //- RunTime type information
101  TypeName("cellLimited");
102 
103 
104  // Constructors
105 
106  //- Construct from mesh and schemeData
107  cellLimitedGrad(const fvMesh& mesh, Istream& schemeData)
108  :
109  gradScheme<Type>(mesh),
110  Limiter(schemeData),
111  basicGradScheme_(fv::gradScheme<Type>::New(mesh, schemeData)),
112  k_(readScalar(schemeData))
113  {
114  if (k_ < 0 || k_ > 1)
115  {
116  FatalIOErrorInFunction(schemeData)
117  << "coefficient = " << k_
118  << " should be >= 0 and <= 1"
119  << exit(FatalIOError);
120  }
121  }
122 
123 
124  // Member Functions
125 
126  inline void limitFaceCmpt
127  (
128  scalar& limiter,
129  const scalar maxDelta,
130  const scalar minDelta,
131  const scalar extrapolate
132  ) const;
133 
134  inline void limitFace
135  (
136  Type& limiter,
137  const Type& maxDelta,
138  const Type& minDelta,
139  const Type& extrapolate
140  ) const;
141 
142  //- Return the gradient of the given field to the gradScheme::grad
143  // for optional caching
144  virtual tmp
145  <
148  > calcGrad
149  (
151  const word& name
152  ) const;
153 };
154 
155 
156 // * * * * * * * * * * * * Inline Member Function * * * * * * * * * * * * * //
157 
158 template<class Type, class Limiter>
160 (
161  scalar& limiter,
162  const scalar maxDelta,
163  const scalar minDelta,
164  const scalar extrapolate
165 ) const
166 {
167  scalar r = 1;
168 
169  if (extrapolate > SMALL)
170  {
171  r = maxDelta/extrapolate;
172  }
173  else if (extrapolate < -SMALL)
174  {
175  r = minDelta/extrapolate;
176  }
177  else
178  {
179  return;
180  }
181 
183 }
184 
185 
186 template<class Type, class Limiter>
188 (
189  Type& limiter,
190  const Type& maxDelta,
191  const Type& minDelta,
192  const Type& extrapolate
193 ) const
194 {
195  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
196  {
197  limitFaceCmpt
198  (
199  setComponent(limiter, cmpt),
200  component(maxDelta, cmpt),
201  component(minDelta, cmpt),
202  component(extrapolate, cmpt)
203  );
204  }
205 }
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace fv
211 
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #ifdef NoRepository
217  #include "cellLimitedGrad.C"
218 #endif
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #endif
223 
224 // ************************************************************************* //
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::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:123
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
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::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
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::fv::cellLimitedGrad::limitFaceCmpt
void limitFaceCmpt(scalar &limiter, const scalar maxDelta, const scalar minDelta, const scalar extrapolate) const
Definition: cellLimitedGrad.H:159
Foam::Field< scalar >
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::cellLimitedGrad::TypeName
TypeName("cellLimited")
RunTime type information.
Field.H
Foam::fv::gradScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: gradScheme.H:124
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
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fv::cellLimitedGrad::limitFace
void limitFace(Type &limiter, const Type &maxDelta, const Type &minDelta, const Type &extrapolate) const
Definition: cellLimitedGrad.H:187
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::fv::cellLimitedGrad::cellLimitedGrad
cellLimitedGrad(const fvMesh &mesh, Istream &schemeData)
Construct from mesh and schemeData.
Definition: cellLimitedGrad.H:106
cellLimitedGrad.C
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::fv::cellLimitedGrad::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.
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::limiter
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition: faNVDscheme.C:37
Foam::fv::cellLimitedGrad
cellLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
Definition: cellLimitedGrad.H:63