clippedLinear.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::clippedLinear
28 
29 Group
30  grpFvSurfaceInterpolationSchemes
31 
32 Description
33  Central-differencing interpolation scheme using clipped-weights to
34  improve stability on meshes with very rapid variations in cell size.
35 
36 SourceFiles
37  clippedLinear.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef clippedLinear_H
42 #define clippedLinear_H
43 
45 #include "volFields.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class clippedLinear Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type>
57 class clippedLinear
58 :
59  public surfaceInterpolationScheme<Type>
60 {
61  // Private data
62 
63  const scalar cellSizeRatio_;
64  scalar wfLimit_;
65 
66 
67  // Private Member Functions
68 
69  void calcWfLimit()
70  {
71  if (cellSizeRatio_ <= 0 || cellSizeRatio_ > 1)
72  {
74  << "Given cellSizeRatio of " << cellSizeRatio_
75  << " is not between 0 and 1"
76  << exit(FatalError);
77  }
78 
79  wfLimit_ = cellSizeRatio_/(1.0 + cellSizeRatio_);
80  }
81 
82 
83  //- No copy assignment
84  void operator=(const clippedLinear&) = delete;
85 
86 
87 public:
88 
89  //- Runtime type information
90  TypeName("clippedLinear");
91 
92 
93  // Constructors
94 
95  //- Construct from mesh and cellSizeRatio
96  clippedLinear(const fvMesh& mesh, const scalar cellSizeRatio)
97  :
99  cellSizeRatio_(cellSizeRatio)
100  {
101  calcWfLimit();
102  }
103 
104  //- Construct from Istream
105  clippedLinear(const fvMesh& mesh, Istream& is)
106  :
108  cellSizeRatio_(readScalar(is))
109  {
110  calcWfLimit();
111  }
112 
113  //- Construct from faceFlux and Istream
115  (
116  const fvMesh& mesh,
117  const surfaceScalarField&,
118  Istream& is
119  )
120  :
122  cellSizeRatio_(readScalar(is))
123  {
124  calcWfLimit();
125  }
126 
127 
128  // Member Functions
129 
130  //- Return the interpolation weighting factors
132  (
134  ) const
135  {
136  const fvMesh& mesh = this->mesh();
137 
138  tmp<surfaceScalarField> tcdWeights
139  (
140  mesh.surfaceInterpolation::weights()
141  );
142  const surfaceScalarField& cdWeights = tcdWeights();
143 
144  tmp<surfaceScalarField> tclippedLinearWeights
145  (
147  (
148  IOobject
149  (
150  "clippedLinearWeights",
151  mesh.time().timeName(),
152  mesh
153  ),
154  mesh,
155  dimless
156  )
157  );
158  surfaceScalarField& clippedLinearWeights =
159  tclippedLinearWeights.ref();
160 
161  clippedLinearWeights.primitiveFieldRef() =
162  max(min(cdWeights.primitiveField(), 1 - wfLimit_), wfLimit_);
163 
164  surfaceScalarField::Boundary& clwbf =
165  clippedLinearWeights.boundaryFieldRef();
166 
167  forAll(mesh.boundary(), patchi)
168  {
169  if (clwbf[patchi].coupled())
170  {
171  clwbf[patchi] =
172  max
173  (
174  min
175  (
176  cdWeights.boundaryField()[patchi],
177  1 - wfLimit_
178  ),
179  wfLimit_
180  );
181  }
182  else
183  {
184  clwbf[patchi] = cdWeights.boundaryField()[patchi];
185  }
186  }
187 
188  return tclippedLinearWeights;
189  }
190 };
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace Foam
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 #endif
200 
201 // ************************************************************************* //
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::clippedLinear
Central-differencing interpolation scheme using clipped-weights to improve stability on meshes with v...
Definition: clippedLinear.H:56
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::clippedLinear::weights
tmp< surfaceScalarField > weights(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the interpolation weighting factors.
Definition: clippedLinear.H:131
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::FatalError
error FatalError
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:685
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:749
Foam::clippedLinear::clippedLinear
clippedLinear(const fvMesh &mesh, Istream &is)
Construct from Istream.
Definition: clippedLinear.H:104
Foam::surfaceInterpolationScheme
Abstract base class for surface interpolation schemes.
Definition: surfaceInterpolationScheme.H:57
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::surfaceInterpolationScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: surfaceInterpolationScheme.H:144
Foam::clippedLinear::TypeName
TypeName("clippedLinear")
Runtime type information.
coupled
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::clippedLinear::clippedLinear
clippedLinear(const fvMesh &mesh, const scalar cellSizeRatio)
Construct from mesh and cellSizeRatio.
Definition: clippedLinear.H:95
surfaceInterpolationScheme.H
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189