cubic.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-2025 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::cubic
26 
27 Description
28  Cubic interpolation scheme class derived from linear and returns
29  linear weighting factors but also applies an explicit correction.
30 
31 SourceFiles
32  cubic.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef cubic_H
37 #define cubic_H
38 
39 #include "linear.H"
40 #include "gradScheme.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class cubic Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Type>
52 class cubic
53 :
54  public linear<Type>
55 {
56  // Private Data
57 
58  word gradSchemeName_;
59 
60 
61 public:
62 
63  //- Runtime type information
64  TypeName("cubic");
65 
66 
67  // Constructors
68 
69  //- Construct from mesh
70  cubic(const fvMesh& mesh)
71  :
72  linear<Type>(mesh),
73  gradSchemeName_("grad")
74  {}
75 
76  //- Construct from mesh and Istream
77  cubic
78  (
79  const fvMesh& mesh,
80  Istream& schemeData
81  )
82  :
83  linear<Type>(mesh),
84  gradSchemeName_(schemeData)
85  {}
86 
87  //- Construct from mesh, faceFlux and Istream
88  cubic
89  (
90  const fvMesh& mesh,
91  const surfaceScalarField&,
92  Istream& schemeData
93  )
94  :
95  linear<Type>(mesh),
96  gradSchemeName_(schemeData)
97  {}
98 
99  //- Disallow default bitwise copy construction
100  cubic(const cubic&) = delete;
101 
102 
103  // Member Functions
104 
105  //- Return true if this scheme uses an explicit correction
106  virtual bool corrected() const
107  {
108  return true;
109  }
110 
111  //- Return the explicit correction to the face-interpolate
113  correction
114  (
115  const VolField<Type>& vf
116  ) const
117  {
118  const fvMesh& mesh = this->mesh();
119 
120  // calculate the appropriate interpolation factors
122 
123  const surfaceScalarField kSc
124  (
125  lambda*(scalar(1) - lambda*(scalar(3) - scalar(2)*lambda))
126  );
127 
128  const surfaceScalarField kVecN(-sqr(scalar(1) - lambda)*lambda);
129  const surfaceScalarField kVecP(sqr(lambda)*(scalar(1) - lambda));
130 
131  tmp<SurfaceField<Type>> tsfCorr
132  (
134  (
135  "cubic::correction(" + vf.name() +')',
137  )
138  );
139  SurfaceField<Type>& sfCorr =
140  tsfCorr.ref();
141 
142  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
143  {
144  sfCorr.replace
145  (
146  cmpt,
147  sfCorr.component(cmpt)
148  + (
150  <
151  typename outerProduct
152  <
153  vector,
154  typename pTraits<Type>::cmptType
155  >::type
156  >::interpolate
157  (
159  New
160  (
161  mesh,
162  mesh.schemes().grad(gradSchemeName_)
163  )().grad(vf.component(cmpt)),
164  kVecP,
165  kVecN
166  ) & mesh.delta()
167  )
168  );
169  }
170 
171  typename SurfaceField<Type>::
172  Boundary& sfCorrbf = sfCorr.boundaryFieldRef();
173 
174  forAll(sfCorrbf, pi)
175  {
176  if (!sfCorrbf[pi].coupled())
177  {
178  sfCorrbf[pi] = Zero;
179  }
180  }
181 
182  return tsfCorr;
183  }
184 
185 
186  // Member Operators
187 
188  //- Disallow default bitwise assignment
189  void operator=(const cubic&) = delete;
190 };
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace Foam
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 #endif
200 
201 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Generic GeometricField class.
tmp< GeometricField< cmptType, GeoMesh, Field > > component(const direction) const
Return a component of the field.
void replace(const direction, const GeometricField< cmptType, GeoMesh, PrimitiveField2 > &)
Replace a component field of the field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const word & name() const
Return name.
Definition: IOobject.H:307
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Cubic interpolation scheme class derived from linear and returns linear weighting factors but also ap...
Definition: cubic.H:54
virtual bool corrected() const
Return true if this scheme uses an explicit correction.
Definition: cubic.H:105
TypeName("cubic")
Runtime type information.
void operator=(const cubic &)=delete
Disallow default bitwise assignment.
cubic(const fvMesh &mesh)
Construct from mesh.
Definition: cubic.H:69
virtual tmp< SurfaceField< Type > > correction(const VolField< Type > &vf) const
Return the explicit correction to the face-interpolate.
Definition: cubic.H:113
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1792
tmp< surfaceVectorField > delta() const
Return face deltas as surfaceVectorField.
ITstream & grad(const word &name) const
Definition: fvSchemes.C:416
Abstract base class for gradient schemes.
Definition: gradScheme.H:63
Centred interpolation interpolation scheme class.
Definition: linear.H:53
Traits class for primitives.
Definition: pTraits.H:53
Abstract base class for surface interpolation schemes.
const fvMesh & mesh() const
Return mesh reference.
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &, const tmp< surfaceScalarField > &, const tmp< surfaceScalarField > &)
Return the face-interpolate of the given cell field.
static tmp< surfaceInterpolationScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
const surfaceScalarField & weights() const
Return reference to linear difference weighting factors.
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:197
A class for handling words, derived from string.
Definition: word.H:63
dimensionedScalar lambda(viscosity->lookup("lambda"))
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
uint8_t direction
Definition: direction.H:45
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488