clippedLinear.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::clippedLinear
26 
27 Description
28  Centred interpolation interpolation scheme using clipped-weights to
29  improve stability on meshes with very rapid variations in cell size.
30 
31 SourceFiles
32  clippedLinear.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef clippedLinear_H
37 #define clippedLinear_H
38 
40 #include "volFields.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class clippedLinear Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Type>
52 class clippedLinear
53 :
54  public surfaceInterpolationScheme<Type>
55 {
56  // Private Data
57 
58  const scalar cellSizeRatio_;
59  scalar wfLimit_;
60 
61 
62  // Private Member Functions
63 
64  void calcWfLimit()
65  {
66  if (cellSizeRatio_ <= 0 || cellSizeRatio_ > 1)
67  {
69  << "Given cellSizeRatio of " << cellSizeRatio_
70  << " is not between 0 and 1"
71  << exit(FatalError);
72  }
73 
74  wfLimit_ = cellSizeRatio_/(1.0 + cellSizeRatio_);
75  }
76 
77 
78 public:
79 
80  //- Runtime type information
81  TypeName("clippedLinear");
82 
83 
84  // Constructors
85 
86  //- Construct from mesh and cellSizeRatio
87  clippedLinear(const fvMesh& mesh, const scalar cellSizeRatio)
88  :
90  cellSizeRatio_(cellSizeRatio)
91  {
92  calcWfLimit();
93  }
94 
95  //- Construct from Istream
96  clippedLinear(const fvMesh& mesh, Istream& is)
97  :
99  cellSizeRatio_(readScalar(is))
100  {
101  calcWfLimit();
102  }
103 
104  //- Construct from faceFlux and Istream
106  (
107  const fvMesh& mesh,
108  const surfaceScalarField&,
109  Istream& is
110  )
111  :
113  cellSizeRatio_(readScalar(is))
114  {
115  calcWfLimit();
116  }
117 
118 
119  // Member Functions
120 
121  //- Return the interpolation weighting factors
123  (
124  const VolField<Type>&
125  ) const
126  {
127  const fvMesh& mesh = this->mesh();
128 
129  tmp<surfaceScalarField> tcdWeights
130  (
131  mesh.surfaceInterpolation::weights()
132  );
133  const surfaceScalarField& cdWeights = tcdWeights();
134 
135  tmp<surfaceScalarField> tclippedLinearWeights
136  (
138  (
139  "clippedLinearWeights",
140  mesh,
141  dimless
142  )
143  );
144  surfaceScalarField& clippedLinearWeights =
145  tclippedLinearWeights.ref();
146 
147  clippedLinearWeights.primitiveFieldRef() =
148  max(min(cdWeights.primitiveField(), 1 - wfLimit_), wfLimit_);
149 
151  clippedLinearWeights.boundaryFieldRef();
152 
154  {
155  if (clwbf[patchi].coupled())
156  {
157  clwbf[patchi] =
158  max
159  (
160  min
161  (
162  cdWeights.boundaryField()[patchi],
163  1 - wfLimit_
164  ),
165  wfLimit_
166  );
167  }
168  else
169  {
170  clwbf[patchi] = cdWeights.boundaryField()[patchi];
171  }
172  }
173 
174  return tclippedLinearWeights;
175  }
176 
177 
178  // Member Operators
179 
180  //- Disallow default bitwise assignment
181  void operator=(const clippedLinear&) = delete;
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #endif
192 
193 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Generic GeometricBoundaryField class.
Generic GeometricField class.
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Internal &, const PtrList< PatchField< Type >> &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Centred interpolation interpolation scheme using clipped-weights to improve stability on meshes with ...
Definition: clippedLinear.H:54
tmp< surfaceScalarField > weights(const VolField< Type > &) const
Return the interpolation weighting factors.
TypeName("clippedLinear")
Runtime type information.
clippedLinear(const fvMesh &mesh, const scalar cellSizeRatio)
Construct from mesh and cellSizeRatio.
Definition: clippedLinear.H:86
void operator=(const clippedLinear &)=delete
Disallow default bitwise assignment.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:857
Abstract base class for surface interpolation schemes.
const fvMesh & mesh() const
Return mesh reference.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet dimless
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
error FatalError