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