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