invDistLeastSquaresVectors.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) 2013-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "leastSquaresVectors.H"
29 #include "volFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(leastSquaresVectors, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
44  pVectors_
45  (
46  IOobject
47  (
48  "LeastSquaresP",
49  mesh_.pointsInstance(),
50  mesh_,
51  IOobject::NO_READ,
52  IOobject::NO_WRITE,
53  false
54  ),
55  mesh_,
57  ),
58  nVectors_
59  (
60  IOobject
61  (
62  "LeastSquaresN",
63  mesh_.pointsInstance(),
64  mesh_,
65  IOobject::NO_READ,
66  IOobject::NO_WRITE,
67  false
68  ),
69  mesh_,
71  )
72 {
73  calcLeastSquaresVectors();
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
78 
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
85 void Foam::leastSquaresVectors::calcLeastSquaresVectors()
86 {
87  if (debug)
88  {
89  InfoInFunction << "Calculating least square gradient vectors" << endl;
90  }
91 
92  const fvMesh& mesh = mesh_;
93 
94  // Set local references to mesh data
95  const labelUList& owner = mesh_.owner();
96  const labelUList& neighbour = mesh_.neighbour();
97 
98  const volVectorField& C = mesh.C();
99 
100  // Set up temporary storage for the dd tensor (before inversion)
101  symmTensorField dd(mesh_.nCells(), Zero);
102 
103  forAll(owner, facei)
104  {
105  label own = owner[facei];
106  label nei = neighbour[facei];
107 
108  vector d = C[nei] - C[own];
109  symmTensor wdd = sqr(d)/magSqr(d);
110  dd[own] += wdd;
111  dd[nei] += wdd;
112  }
113 
114 
115  surfaceVectorField::Boundary& blsP =
116  pVectors_.boundaryField();
117 
118  forAll(blsP, patchi)
119  {
120  const fvsPatchVectorField& patchLsP = blsP[patchi];
121 
122  const fvPatch& p = patchLsP.patch();
123  const labelUList& faceCells = p.patch().faceCells();
124 
125  // Build the d-vectors
126  vectorField pd(p.delta());
127 
128  forAll(pd, patchFacei)
129  {
130  const vector& d = pd[patchFacei];
131 
132  dd[faceCells[patchFacei]] += sqr(d)/magSqr(d);
133  }
134  }
135 
136 
137  // Invert the dd tensor
138  const symmTensorField invDd(inv(dd));
139 
140 
141  // Revisit all faces and calculate the pVectors_ and nVectors_ vectors
142  forAll(owner, facei)
143  {
144  label own = owner[facei];
145  label nei = neighbour[facei];
146 
147  vector d = C[nei] - C[own];
148 
149  pVectors_[facei] = (invDd[own] & d)/magSqr(d);
150  nVectors_[facei] = -(invDd[nei] & d)/magSqr(d);
151  }
152 
153  forAll(blsP, patchi)
154  {
155  fvsPatchVectorField& patchLsP = blsP[patchi];
156 
157  const fvPatch& p = patchLsP.patch();
158  const labelUList& faceCells = p.faceCells();
159 
160  // Build the d-vectors
161  vectorField pd(p.delta());
162 
163  forAll(pd, patchFacei)
164  {
165  const vector& d = pd[patchFacei];
166 
167  patchLsP[patchFacei] = (invDd[faceCells[patchFacei]] & d)/magSqr(d);
168  }
169  }
170 
171  if (debug)
172  {
174  <<"Finished calculating least square gradient vectors" << endl;
175  }
176 }
177 
178 
180 {
181  calcLeastSquaresVectors();
182  return true;
183 }
184 
185 
186 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::leastSquaresVectors::~leastSquaresVectors
virtual ~leastSquaresVectors()
Destructor.
Definition: invDistLeastSquaresVectors.C:79
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::MoveableMeshObject
Definition: MeshObject.H:220
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
leastSquaresVectors.H
C
volScalarField & C
Definition: readThermalProperties.H:102
Foam::leastSquaresVectors::movePoints
virtual bool movePoints()
Delete the least square vectors when the mesh moves.
Definition: invDistLeastSquaresVectors.C:179
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::symmTensorField
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
Definition: primitiveFieldsFwd.H:56
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::label
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:62
Foam::fvsPatchVectorField
fvsPatchField< vector > fvsPatchVectorField
Definition: fvsPatchFieldsFwd.H:48
Foam::leastSquaresVectors::leastSquaresVectors
leastSquaresVectors(const fvMesh &)
Construct given an fvMesh.
Definition: invDistLeastSquaresVectors.C:41
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::symmTensor
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:50
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:358
Foam::leastSquaresVectors
Least-squares gradient scheme vectors.
Definition: leastSquaresVectors.H:52
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned< vector >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:60
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
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:79
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)