Loading...
Searching...
No Matches
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>
64class 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 (
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 //- Calculate the grad of the given field into supplied field
155 virtual void calcGrad
160 ) const;
161};
162
163
164// * * * * * * * * * * * * Inline Member Function * * * * * * * * * * * * * //
166template<class Type, class Limiter>
168(
169 scalar& limiter,
170 const scalar maxDelta,
171 const scalar minDelta,
172 const scalar extrapolate
173) const
174{
175 scalar r = 1;
176
177 if (extrapolate > SMALL)
178 {
179 r = maxDelta/extrapolate;
180 }
181 else if (extrapolate < -SMALL)
182 {
183 r = minDelta/extrapolate;
184 }
185 else
186 {
187 return;
188 }
189
190 limiter = min(limiter, Limiter::limiter(r));
191}
192
193
194template<class Type, class Limiter>
196(
197 Type& limiter,
198 const Type& maxDelta,
199 const Type& minDelta,
200 const Type& extrapolate
201) const
202{
203 for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; ++cmpt)
204 {
206 (
207 setComponent(limiter, cmpt),
208 component(maxDelta, cmpt),
209 component(minDelta, cmpt),
210 component(extrapolate, cmpt)
211 );
212 }
213}
214
215
216// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217
218} // End namespace fv
219
220} // End namespace Foam
221
222// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223
224#ifdef NoRepository
225 #include "cellLimitedGrad.C"
226#endif
227
228// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229
230#endif
231
232// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
Generic GeometricField class.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
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.
virtual void calcGrad(GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > &res, const GeometricField< Type, fvPatchField, volMesh > &) const
Calculate the grad of the given field into supplied field.
Abstract base class for gradient schemes.
Definition gradScheme.H:62
const fvMesh & mesh() const
Return const reference to mesh.
Definition gradScheme.H:138
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition gradScheme.C:30
scalar limiter(const scalar r) const
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A class for managing temporary objects.
Definition tmp.H:75
Mesh data needed to do the Finite Volume discretisation.
Definition volMesh.H:47
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
Namespace for finite-volume.
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:160
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
uint8_t direction
Definition direction.H:49
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition faNVDscheme.C:31
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68