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-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 \*---------------------------------------------------------------------------*/
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  )
62 {
63  calcSkewCorrectionVectors();
64 }
65 
66 
68 {}
69 
70 
71 void Foam::skewCorrectionVectors::calcSkewCorrectionVectors()
72 {
73  if (debug)
74  {
75  InfoInFunction << "Calculating skew correction vectors" << endl;
76  }
77 
78  // Set local references to mesh data
79  const volVectorField& C = mesh().C();
80  const surfaceVectorField& Cf = mesh().Cf();
81  const surfaceVectorField& Sf = mesh().Sf();
82 
83  const labelUList& owner = mesh().owner();
84  const labelUList& neighbour = mesh().neighbour();
85 
86  forAll(owner, facei)
87  {
88  label own = owner[facei];
89  label nei = neighbour[facei];
90 
91  vector d = C[nei] - C[own];
92  vector Cpf = Cf[facei] - C[own];
93 
94  skewCorrectionVectors_[facei] =
95  Cpf - ((Sf[facei] & Cpf)/(Sf[facei] & d))*d;
96  }
97 
98  surfaceVectorField::Boundary& skewCorrVecsBf =
99  skewCorrectionVectors_.boundaryFieldRef();
100 
101  forAll(skewCorrVecsBf, patchi)
102  {
103  fvsPatchVectorField& patchSkewCorrVecs = skewCorrVecsBf[patchi];
104 
105  if (!patchSkewCorrVecs.coupled())
106  {
107  patchSkewCorrVecs = Zero;
108  }
109  else
110  {
111  const fvPatch& p = patchSkewCorrVecs.patch();
112  const labelUList& faceCells = p.faceCells();
113  const vectorField& patchFaceCentres = Cf.boundaryField()[patchi];
114  const vectorField& patchSf = Sf.boundaryField()[patchi];
115  const vectorField patchD(p.delta());
116 
117  forAll(p, patchFacei)
118  {
119  vector Cpf =
120  patchFaceCentres[patchFacei] - C[faceCells[patchFacei]];
121 
122  patchSkewCorrVecs[patchFacei] =
123  Cpf
124  - (
125  (patchSf[patchFacei] & Cpf)/
126  (patchSf[patchFacei] & patchD[patchFacei])
127  )*patchD[patchFacei];
128  }
129  }
130  }
131 
132  scalar skewCoeff = 0.0;
133 
134  if (Sf.primitiveField().size())
135  {
136  skewCoeff =
137  max(mag(skewCorrectionVectors_)*mesh().deltaCoeffs()).value();
138  }
139 
140  if (debug)
141  {
142  InfoInFunction << "skew coefficient = " << skewCoeff << endl;
143  }
144 
145  if (skewCoeff < 1e-5)
146  {
147  skew_ = false;
148  }
149  else
150  {
151  skew_ = true;
152  }
153 
154  if (debug)
155  {
156  Info<< " Finished constructing skew correction vectors" << endl;
157  }
158 }
159 
160 
162 {
163  calcSkewCorrectionVectors();
164  return true;
165 }
166 
167 
168 // ************************************************************************* //
static const Foam::dimensionedScalar C("C", Foam::dimTemperature, 234.5)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
GeometricBoundaryField< Type, PatchField, GeoMesh > 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:101
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)
label patchi
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
const doubleScalar e
Definition: doubleScalar.H:105
VolField< vector > volVectorField
Definition: volFieldsFwd.H:62
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:251
const dimensionSet dimless
messageStream Info
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
SurfaceField< vector > surfaceVectorField
UList< label > labelUList
Definition: UList.H:65
fvsPatchField< vector > fvsPatchVectorField
volScalarField & p