LeastSquaresVectors.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  Copyright (C) 2020-2021 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 "LeastSquaresVectors.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Stencil>
35 (
36  const fvMesh& mesh
37 )
38 :
40  vectors_(mesh.nCells())
41 {
42  calcLeastSquaresVectors();
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
48 template<class Stencil>
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class Stencil>
57 {
58  DebugInFunction << "Calculating least square gradient vectors" << nl;
59 
60  const fvMesh& mesh = this->mesh_;
61  const extendedCentredCellToCellStencil& stencil = this->stencil();
62 
63  stencil.collectData(mesh.C(), vectors_);
64 
65  // Create the base form of the dd-tensor
66  // including components for the "empty" directions
67  const symmTensor dd0(sqr((Vector<label>::one - mesh.geometricD())/2));
68 
69  forAll(vectors_, i)
70  {
71  List<vector>& lsvi = vectors_[i];
72  symmTensor dd(dd0);
73 
74  // The current cell is 0 in the stencil
75  // Calculate the deltas and sum the weighted dd
76  for (label j = 1; j < lsvi.size(); ++j)
77  {
78  lsvi[j] = lsvi[j] - lsvi[0];
79  const scalar magSqrLsvi = magSqr(lsvi[j]);
80  dd += sqr(lsvi[j])/magSqrLsvi;
81  lsvi[j] /= magSqrLsvi;
82  }
83 
84  // Invert dd
85  dd = inv(dd);
86 
87  // Remove the components corresponding to the empty directions
88  dd -= dd0;
89 
90  // Finalize the gradient weighting vectors
91  lsvi[0] = Zero;
92  for (label j = 1; j < lsvi.size(); ++j)
93  {
94  lsvi[j] = dd & lsvi[j];
95  lsvi[0] -= lsvi[j];
96  }
97  }
98 
99  DebugInfo
100  << "Finished calculating least square gradient vectors" << endl;
101 }
102 
103 
104 template<class Stencil>
106 {
107  calcLeastSquaresVectors();
108  return true;
109 }
110 
111 
112 // ************************************************************************* //
Foam::SymmTensor< scalar >
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fv::LeastSquaresVectors::movePoints
virtual bool movePoints()
Update the least square vectors when the mesh moves.
Definition: LeastSquaresVectors.C:105
LeastSquaresVectors.H
Foam::extendedCentredCellToCellStencil
Definition: extendedCentredCellToCellStencil.H:52
Foam::fv::LeastSquaresVectors::~LeastSquaresVectors
virtual ~LeastSquaresVectors()
Destructor.
Definition: LeastSquaresVectors.C:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::extendedCentredCellToCellStencil::collectData
void collectData(const GeometricField< Type, fvPatchField, volMesh > &fld, List< List< Type >> &stencilFld) const
Use map to get the data into stencil order.
Definition: extendedCentredCellToCellStencil.H:105
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::List< vector >
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::fv::LeastSquaresVectors
Least-squares gradient scheme vectors.
Definition: LeastSquaresVectors.H:61
Foam::fv::LeastSquaresVectors::LeastSquaresVectors
LeastSquaresVectors(const fvMesh &)
Construct given an fvMesh and the minimum determinant criterion.
Definition: LeastSquaresVectors.C:35