skewCorrectionVectors.C
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  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "skewCorrectionVectors.H"
30 #include "volFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(skewCorrectionVectors, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
45  skew_(false),
46  skewCorrectionVectors_
47  (
48  IOobject
49  (
50  "skewCorrectionVectors",
51  mesh_.pointsInstance(),
52  mesh_,
53  IOobject::NO_READ,
54  IOobject::NO_WRITE,
55  false
56  ),
57  mesh_,
58  dimless
59  )
60 {
61  calcSkewCorrectionVectors();
62 }
63 
64 
66 {}
67 
68 
69 void Foam::skewCorrectionVectors::calcSkewCorrectionVectors()
70 {
71  DebugInFunction << "Calculating skew correction vectors" << nl;
72 
73  // Set local references to mesh data
74  const volVectorField& C = mesh_.C();
75  const surfaceVectorField& Cf = mesh_.Cf();
76  const surfaceVectorField& Sf = mesh_.Sf();
77 
78  const labelUList& owner = mesh_.owner();
79  const labelUList& neighbour = mesh_.neighbour();
80 
81  forAll(owner, facei)
82  {
83  label own = owner[facei];
84  label nei = neighbour[facei];
85 
86  vector d = C[nei] - C[own];
87  vector Cpf = Cf[facei] - C[own];
88 
89  skewCorrectionVectors_[facei] =
90  Cpf - ((Sf[facei] & Cpf)/(Sf[facei] & d))*d;
91  }
92 
93  surfaceVectorField::Boundary& skewCorrVecsBf =
94  skewCorrectionVectors_.boundaryFieldRef();
95 
96  forAll(skewCorrVecsBf, patchi)
97  {
98  fvsPatchVectorField& patchSkewCorrVecs = skewCorrVecsBf[patchi];
99 
100  if (!patchSkewCorrVecs.coupled())
101  {
102  patchSkewCorrVecs = Zero;
103  }
104  else
105  {
106  const fvPatch& p = patchSkewCorrVecs.patch();
107  const labelUList& faceCells = p.faceCells();
108  const vectorField& patchFaceCentres = Cf.boundaryField()[patchi];
109  const vectorField& patchSf = Sf.boundaryField()[patchi];
110  const vectorField patchD(p.delta());
111 
112  forAll(p, patchFacei)
113  {
114  vector Cpf =
115  patchFaceCentres[patchFacei] - C[faceCells[patchFacei]];
116 
117  patchSkewCorrVecs[patchFacei] =
118  Cpf
119  - (
120  (patchSf[patchFacei] & Cpf)/
121  (patchSf[patchFacei] & patchD[patchFacei])
122  )*patchD[patchFacei];
123  }
124  }
125  }
126 
127  scalar skewCoeff = 0.0;
128 
129  if (Sf.primitiveField().size())
130  {
131  skewCoeff =
132  max(mag(skewCorrectionVectors_)*mesh_.deltaCoeffs()).value();
133  }
134 
135  DebugInFunction << "skew coefficient = " << skewCoeff << nl;
136 
137  if (skewCoeff < 1e-5)
138  {
139  skew_ = false;
140  }
141  else
142  {
143  skew_ = true;
144  }
145 
146  if (debug)
147  {
148  Info<< " Finished constructing skew correction vectors" << endl;
149  }
150 }
151 
152 
154 {
155  calcSkewCorrectionVectors();
156  return true;
157 }
158 
159 
160 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
skewCorrectionVectors.H
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::skewCorrectionVectors::~skewCorrectionVectors
virtual ~skewCorrectionVectors()
Destructor.
Definition: skewCorrectionVectors.C:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::GeometricField::primitiveField
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Definition: GeometricFieldI.H:53
Foam::MoveableMeshObject
Definition: MeshObject.H:220
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::skewCorrectionVectors::skewCorrectionVectors
skewCorrectionVectors(const fvMesh &mesh)
Definition: skewCorrectionVectors.C:42
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::fvsPatchVectorField
fvsPatchField< vector > fvsPatchVectorField
Definition: fvsPatchFieldsFwd.H:48
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::C::C
C()
Construct null.
Definition: C.C:43
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::skewCorrectionVectors
Skew-correction vectors for the skewness-corrected interpolation scheme.
Definition: skewCorrectionVectors.H:54
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::skewCorrectionVectors::movePoints
virtual bool movePoints()
Update the correction vectors when the mesh moves.
Definition: skewCorrectionVectors.C:153
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::UList< label >
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
Foam::C
Graphite solid properties.
Definition: C.H:50
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189