LeastSquaresVectors.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) 2013-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 "LeastSquaresVectors.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Stencil>
32 (
33  const fvMesh& mesh
34 )
35 :
37  <
38  fvMesh,
41  >(mesh),
42  vectors_(mesh.nCells())
43 {
44  calcLeastSquaresVectors();
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
49 
50 template<class Stencil>
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 
57 template<class Stencil>
59 {
60  if (debug)
61  {
62  InfoInFunction << "Calculating least square gradient vectors" << endl;
63  }
64 
65  const fvMesh& mesh = this->mesh();
66  const extendedCentredCellToCellStencil& stencil = this->stencil();
67 
68  stencil.collectData(mesh.C(), vectors_);
69 
70  // Create the base form of the dd-tensor
71  // including components for the "empty" directions
72  symmTensor dd0(sqr((Vector<label>::one - mesh.geometricD())/2));
73 
74  forAll(vectors_, i)
75  {
76  List<vector>& lsvi = vectors_[i];
77  symmTensor dd(dd0);
78 
79  // The current cell is 0 in the stencil
80  // Calculate the deltas and sum the weighted dd
81  for (label j=1; j<lsvi.size(); j++)
82  {
83  lsvi[j] = lsvi[j] - lsvi[0];
84  scalar magSqrLsvi = magSqr(lsvi[j]);
85  dd += sqr(lsvi[j])/magSqrLsvi;
86  lsvi[j] /= magSqrLsvi;
87  }
88 
89  // Invert dd
90  dd = inv(dd);
91 
92  // Remove the components corresponding to the empty directions
93  dd -= dd0;
94 
95  // Finalise the gradient weighting vectors
96  lsvi[0] = Zero;
97  for (label j=1; j<lsvi.size(); j++)
98  {
99  lsvi[j] = dd & lsvi[j];
100  lsvi[0] -= lsvi[j];
101  }
102  }
103 
104  if (debug)
105  {
107  << "Finished calculating least square gradient vectors" << endl;
108  }
109 }
110 
111 
112 template<class Stencil>
114 {
115  calcLeastSquaresVectors();
116  return true;
117 }
118 
119 
120 // ************************************************************************* //
#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...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:60
void collectData(const VolField< Type > &fld, List< List< Type >> &stencilFld) const
Use map to get the data into stencil order.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
const volVectorField & C() const
Return cell centres.
Least-squares gradient scheme vectors.
virtual bool movePoints()
Update the least square vectors when the mesh moves.
LeastSquaresVectors(const fvMesh &)
Construct given an fvMesh and the minimum determinant criterion.
virtual ~LeastSquaresVectors()
Destructor.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
Definition: polyMesh.C:1043
#define InfoInFunction
Report an information message using Foam::Info.
static const zero Zero
Definition: zero.H:97
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensioned< scalar > magSqr(const dimensioned< Type > &)