skewCorrectionVectors.C
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-2026 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 \*---------------------------------------------------------------------------*/
25 
26 #include "skewCorrectionVectors.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
42  <
43  fvMesh,
46  >(mesh),
47  skew_(false),
48  skewCorrectionVectors_
49  (
50  IOobject
51  (
52  "skewCorrectionVectors",
53  mesh.pointsInstance(),
54  mesh,
55  IOobject::NO_READ,
56  IOobject::NO_WRITE,
57  false
58  ),
59  mesh,
60  dimless,
61  fvsPatchField<vector>::calculatedType()
62  )
63 {
64  calcSkewCorrectionVectors();
65 }
66 
67 
69 {}
70 
71 
72 void Foam::skewCorrectionVectors::calcSkewCorrectionVectors()
73 {
74  if (debug)
75  {
76  InfoInFunction << "Calculating skew correction vectors" << endl;
77  }
78 
79  // Set local references to mesh data
80  const volVectorField& C = mesh().C();
81  const surfaceVectorField& Cf = mesh().Cf();
82  const surfaceVectorField& Sf = mesh().Sf();
83 
84  const labelUList& owner = mesh().owner();
85  const labelUList& neighbour = mesh().neighbour();
86 
87  forAll(owner, facei)
88  {
89  label own = owner[facei];
90  label nei = neighbour[facei];
91 
92  vector d = C[nei] - C[own];
93  vector Cpf = Cf[facei] - C[own];
94 
95  skewCorrectionVectors_[facei] =
96  Cpf - ((Sf[facei] & Cpf)/(Sf[facei] & d))*d;
97  }
98 
99  surfaceVectorField::Boundary& skewCorrVecsBf =
100  skewCorrectionVectors_.boundaryFieldRef();
101 
102  forAll(skewCorrVecsBf, patchi)
103  {
104  fvsPatchVectorField& patchSkewCorrVecs = skewCorrVecsBf[patchi];
105 
106  if (!patchSkewCorrVecs.coupled())
107  {
108  patchSkewCorrVecs = Zero;
109  }
110  else
111  {
112  const fvPatch& p = patchSkewCorrVecs.patch();
113  const labelUList& faceCells = p.faceCells();
114  const vectorField& patchFaceCentres = Cf.boundaryField()[patchi];
115  const vectorField& patchSf = Sf.boundaryField()[patchi];
116  const vectorField patchD(p.delta());
117 
118  forAll(p, patchFacei)
119  {
120  vector Cpf =
121  patchFaceCentres[patchFacei] - C[faceCells[patchFacei]];
122 
123  patchSkewCorrVecs[patchFacei] =
124  Cpf
125  - (
126  (patchSf[patchFacei] & Cpf)/
127  (patchSf[patchFacei] & patchD[patchFacei])
128  )*patchD[patchFacei];
129  }
130  }
131  }
132 
133  scalar skewCoeff = 0.0;
134 
135  if (Sf.primitiveField().size())
136  {
137  skewCoeff =
138  max(mag(skewCorrectionVectors_)*mesh().deltaCoeffs()).value();
139  }
140 
141  if (debug)
142  {
143  InfoInFunction << "skew coefficient = " << skewCoeff << endl;
144  }
145 
146  if (skewCoeff < 1e-5)
147  {
148  skew_ = false;
149  }
150  else
151  {
152  skew_ = true;
153  }
154 
155  if (debug)
156  {
157  Info<< " Finished constructing skew correction vectors" << endl;
158  }
159 }
160 
161 
163 {
164  calcSkewCorrectionVectors();
165  return true;
166 }
167 
168 
169 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
GeometricBoundaryField< Type, GeoMesh, PrimitiveField > Boundary
Type of the boundary field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const volVectorField & C() const
Return cell centres.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:490
const surfaceVectorField & Cf() const
Return face centres.
const surfaceVectorField & Sf() const
Return cell face area vectors.
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:496
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:86
Skew-correction vectors for the skewness-corrected interpolation scheme.
virtual bool movePoints()
Update the correction vectors when the mesh moves.
virtual ~skewCorrectionVectors()
Destructor.
skewCorrectionVectors(const fvMesh &mesh)
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
#define InfoInFunction
Report an information message using Foam::Info.
const dimensionSet dimless
static const coefficient C("C", dimTemperature, 234.5)
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
const doubleScalar e
Definition: doubleScalar.H:106
VolField< vector > volVectorField
Definition: volFieldsFwd.H:63
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Field< vector > vectorField
Specialisation of Field<T> for vector.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
SurfaceField< vector > surfaceVectorField
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
UList< label > labelUList
Definition: UList.H:65
fvsPatchField< vector > fvsPatchVectorField
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
volScalarField & p