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-2018 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 {
33  defineTypeNameAndDebug(skewCorrectionVectors, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
42  skew_(false),
43  skewCorrectionVectors_
44  (
45  IOobject
46  (
47  "skewCorrectionVectors",
48  mesh_.pointsInstance(),
49  mesh_,
50  IOobject::NO_READ,
51  IOobject::NO_WRITE,
52  false
53  ),
54  mesh_,
55  dimless
56  )
57 {
58  calcSkewCorrectionVectors();
59 }
60 
61 
63 {}
64 
65 
66 void Foam::skewCorrectionVectors::calcSkewCorrectionVectors()
67 {
68  if (debug)
69  {
70  InfoInFunction << "Calculating skew correction vectors" << endl;
71  }
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  if (debug)
136  {
137  InfoInFunction << "skew coefficient = " << skewCoeff << endl;
138  }
139 
140  if (skewCoeff < 1e-5)
141  {
142  skew_ = false;
143  }
144  else
145  {
146  skew_ = true;
147  }
148 
149  if (debug)
150  {
151  Info<< " Finished constructing skew correction vectors" << endl;
152  }
153 }
154 
155 
157 {
158  calcSkewCorrectionVectors();
159  return true;
160 }
161 
162 
163 // ************************************************************************* //
Graphite solid properties.
Definition: C.H:48
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const surfaceVectorField & Sf() const
Return cell face area vectors.
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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
const surfaceVectorField & Cf() const
Return face centres as surfaceVectorField.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
skewCorrectionVectors(const fvMesh &mesh)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
const dimensionSet dimless
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:284
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
dynamicFvMesh & mesh
virtual bool coupled() const
Return true if this patch field is coupled.
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:99
static const zero Zero
Definition: zero.H:97
virtual bool movePoints()
Update the correction vectors when the mesh moves.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
defineTypeNameAndDebug(combustionModel, 0)
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:278
const fvPatch & patch() const
Return patch.
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
Skew-correction vectors for the skewness-corrected interpolation scheme.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual ~skewCorrectionVectors()
Destructor.
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
const volVectorField & C() const
Return cell centres as volVectorField.
volScalarField & p
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
virtual tmp< vectorField > delta() const
Return cell-centre to face-centre vector.
Definition: fvPatch.C:148
const surfaceScalarField & deltaCoeffs() const
Return reference to cell-centre difference coefficients.
Namespace for OpenFOAM.
#define InfoInFunction
Report an information message using Foam::Info.