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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::fv::cellLimitedGrad
28
29Group
30 grpFvGradSchemes
31
32Description
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
40SourceFiles
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
53namespace Foam
54{
55
56namespace fv
57{
58
59/*---------------------------------------------------------------------------*\
60 Class cellLimitedGrad Declaration
61\*---------------------------------------------------------------------------*/
62
63template<class Type, class Limiter>
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 (
82 Field<vector>& gIf
83 ) const;
84
85 void limitGradient
86 (
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
98public:
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
158template<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
182 limiter = min(limiter, Limiter::limiter(r));
183}
184
185
186template<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// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
Generic GeometricField class.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
cellLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
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.
void limitFace(Type &limiter, const Type &maxDelta, const Type &minDelta, const Type &extrapolate) const
void limitFaceCmpt(scalar &limiter, const scalar maxDelta, const scalar minDelta, const scalar extrapolate) const
TypeName("cellLimited")
RunTime type information.
cellLimitedGrad(const fvMesh &mesh, Istream &schemeData)
Construct from mesh and schemeData.
Abstract base class for gradient schemes.
Definition: gradScheme.H:66
const fvMesh & mesh() const
Return const reference to mesh.
Definition: gradScheme.H:126
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:37
A class for managing temporary objects.
Definition: tmp.H:65
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:54
type
Volume classification types.
Definition: volumeType.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Namespace for OpenFOAM.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
Definition: label.H:123
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
uint8_t direction
Definition: direction.H:56
IOerror FatalIOError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition: faNVDscheme.C:38
labelList fv(nPoints)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73