limitedSnGrad.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::limitedSnGrad
28 
29 Group
30  grpFvSnGradSchemes
31 
32 Description
33  Run-time selected snGrad scheme with limited non-orthogonal correction.
34 
35  The limiter is controlled by a coefficient with a value between 0 and 1
36  which when 0 switches the correction off and the scheme behaves as
37  uncorrectedSnGrad, when set to 1 the full correction of the selected scheme
38  is used and when set to 0.5 the limiter is calculated such that the
39  non-orthogonal contribution does not exceed the orthogonal part.
40 
41  Format:
42  limited <corrected scheme> <coefficient>;
43 
44  or
45 
46  limited <coefficient>; // Backward compatibility
47 
48 SourceFiles
49  limitedSnGrad.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef limitedSnGrad_H
54 #define limitedSnGrad_H
55 
56 #include "correctedSnGrad.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace fv
66 {
67 
68 /*---------------------------------------------------------------------------*\
69  Class limitedSnGrad Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 template<class Type>
73 class limitedSnGrad
74 :
75  public snGradScheme<Type>
76 {
77  // Private data
78 
79  tmp<snGradScheme<Type>> correctedScheme_;
80 
81  scalar limitCoeff_;
82 
83 
84  // Private Member Functions
85 
86  //- No copy assignment
87  void operator=(const limitedSnGrad&) = delete;
88 
89  //- Lookup function for the corrected to support backward compatibility
90  // of dictionary specification
91  tmp<snGradScheme<Type>> lookupCorrectedScheme(Istream& schemeData)
92  {
93  token nextToken(schemeData);
94 
95  if (nextToken.isNumber())
96  {
97  limitCoeff_ = nextToken.number();
99  (
100  new correctedSnGrad<Type>(this->mesh())
101  );
102  }
103  else
104  {
105  schemeData.putBack(nextToken);
106  tmp<snGradScheme<Type>> tcorrectedScheme
107  (
108  fv::snGradScheme<Type>::New(this->mesh(), schemeData)
109  );
110 
111  schemeData >> limitCoeff_;
112 
113  return tcorrectedScheme;
114  }
115  }
116 
117 
118 public:
119 
120  //- Runtime type information
121  TypeName("limited");
122 
123 
124  // Constructors
125 
126  //- Construct from mesh
127  limitedSnGrad(const fvMesh& mesh)
128  :
129  snGradScheme<Type>(mesh),
130  correctedScheme_(new correctedSnGrad<Type>(this->mesh())),
131  limitCoeff_(1)
132  {}
133 
134 
135  //- Construct from mesh and data stream
136  limitedSnGrad(const fvMesh& mesh, Istream& schemeData)
137  :
138  snGradScheme<Type>(mesh),
139  correctedScheme_(lookupCorrectedScheme(schemeData))
140  {
141  if (limitCoeff_ < 0 || limitCoeff_ > 1)
142  {
143  FatalIOErrorInFunction(schemeData)
144  << "limitCoeff is specified as " << limitCoeff_
145  << " but should be >= 0 && <= 1"
146  << exit(FatalIOError);
147  }
148  }
149 
150 
151  //- Destructor
152  virtual ~limitedSnGrad();
153 
154 
155  // Member Functions
156 
157  //- Return the interpolation weighting factors for the given field
159  (
161  ) const
162  {
163  return this->mesh().nonOrthDeltaCoeffs();
164  }
165 
166  //- Return true if this scheme uses an explicit correction
167  virtual bool corrected() const
168  {
169  return true;
170  }
171 
172  //- Return the explicit correction to the limitedSnGrad
173  // for the given field
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace fv
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #ifdef NoRepository
190  #include "limitedSnGrad.C"
191 #endif
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
Foam::surfaceInterpolation::nonOrthDeltaCoeffs
virtual const surfaceScalarField & nonOrthDeltaCoeffs() const
Return reference to non-orthogonal cell-centre difference.
Definition: surfaceInterpolation.C:125
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::fv::limitedSnGrad::TypeName
TypeName("limited")
Runtime type information.
Foam::fv::limitedSnGrad::correction
virtual tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > correction(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the explicit correction to the limitedSnGrad.
Definition: limitedSnGrad.C:57
Foam::token::isNumber
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
Definition: tokenI.H:561
limitedSnGrad.C
Foam::token::number
scalar number() const
Return label, float or double value.
Definition: tokenI.H:567
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::fv::limitedSnGrad::limitedSnGrad
limitedSnGrad(const fvMesh &mesh, Istream &schemeData)
Construct from mesh and data stream.
Definition: limitedSnGrad.H:135
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::limitedSnGrad::~limitedSnGrad
virtual ~limitedSnGrad()
Destructor.
Definition: limitedSnGrad.C:48
correctedSnGrad.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::fv::snGradScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: snGradScheme.H:128
Foam::fv::limitedSnGrad
Run-time selected snGrad scheme with limited non-orthogonal correction.
Definition: limitedSnGrad.H:72
Foam::fv::limitedSnGrad::corrected
virtual bool corrected() const
Return true if this scheme uses an explicit correction.
Definition: limitedSnGrad.H:166
Foam::Istream::putBack
void putBack(const token &tok)
Put back token.
Definition: Istream.C:53
Foam::fv::correctedSnGrad
Simple central-difference snGrad scheme with non-orthogonal correction.
Definition: correctedSnGrad.H:59
Foam::fv::snGradScheme
Abstract base class for snGrad schemes.
Definition: snGradScheme.H:65
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::fv::limitedSnGrad::limitedSnGrad
limitedSnGrad(const fvMesh &mesh)
Construct from mesh.
Definition: limitedSnGrad.H:126
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::fv::limitedSnGrad::deltaCoeffs
virtual tmp< surfaceScalarField > deltaCoeffs(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the interpolation weighting factors for the given field.
Definition: limitedSnGrad.H:158