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 | Copyright (C) 2013 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 "leastSquaresVectors.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(leastSquaresVectors, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
42  pVectors_
43  (
44  IOobject
45  (
46  "LeastSquaresP",
47  mesh_.pointsInstance(),
48  mesh_,
49  IOobject::NO_READ,
50  IOobject::NO_WRITE,
51  false
52  ),
53  mesh_,
55  ),
56  nVectors_
57  (
58  IOobject
59  (
60  "LeastSquaresN",
61  mesh_.pointsInstance(),
62  mesh_,
63  IOobject::NO_READ,
64  IOobject::NO_WRITE,
65  false
66  ),
67  mesh_,
69  )
70 {
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  if (debug)
86  {
87  Info<< "leastSquaresVectors::calcLeastSquaresVectors() :"
88  << "Calculating least square gradient vectors"
89  << 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(), symmTensor::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 
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  {
173  Info<< "leastSquaresVectors::calcLeastSquaresVectors() :"
174  << "Finished calculating least square gradient vectors"
175  << endl;
176  }
177 }
178 
179 
181 {
182  calcLeastSquaresVectors();
183  return true;
184 }
185 
186 
187 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::SymmTensor< scalar >
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
p
p
Definition: pEqn.H:62
Foam::leastSquaresVectors::~leastSquaresVectors
virtual ~leastSquaresVectors()
Destructor.
Definition: invDistLeastSquaresVectors.C:77
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
Foam::MoveableMeshObject
Definition: MeshObject.H:238
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
leastSquaresVectors.H
Foam::leastSquaresVectors::movePoints
virtual bool movePoints()
Delete the least square vectors when the mesh moves.
Definition: invDistLeastSquaresVectors.C:180
Foam::leastSquaresVectors::calcLeastSquaresVectors
void calcLeastSquaresVectors()
Construct Least-squares gradient vectors.
Definition: invDistLeastSquaresVectors.C:83
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:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::leastSquaresVectors::leastSquaresVectors
leastSquaresVectors(const fvMesh &)
Construct given an fvMesh.
Definition: invDistLeastSquaresVectors.C:39
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::Info
messageStream Info
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::leastSquaresVectors
Least-squares gradient scheme vectors.
Definition: leastSquaresVectors.H:50
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::SymmTensor< scalar >::zero
static const SymmTensor zero
Definition: SymmTensor.H:77
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:369
Foam::fvsPatchField::patch
const fvPatch & patch() const
Return patch.
Definition: fvsPatchField.H:278
Foam::Vector< scalar >
Foam::UList
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
patchi
label patchi
Definition: getPatchFieldScalar.H:1
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:81
Foam::C
Graphite solid properties.
Definition: C.H:57
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::GeometricField::GeometricBoundaryField
Definition: GeometricField.H:105
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::zero
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47