LeastSquaresGrad.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 "LeastSquaresGrad.H"
29 #include "LeastSquaresVectors.H"
30 #include "gaussGrad.H"
31 #include "fvMesh.H"
32 #include "volMesh.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 template<class Type, class Stencil>
39 <
41  <
45  >
46 >
48 (
49  const GeometricField<Type, fvPatchField, volMesh>& vtf,
50  const word& name
51 ) const
52 {
53  typedef typename outerProduct<vector, Type>::type GradType;
54 
55  const fvMesh& mesh = vtf.mesh();
56 
57  // Get reference to least square vectors
58  const LeastSquaresVectors<Stencil>& lsv = LeastSquaresVectors<Stencil>::New
59  (
60  mesh
61  );
62 
63  tmp<GeometricField<GradType, fvPatchField, volMesh>> tlsGrad
64  (
65  new GeometricField<GradType, fvPatchField, volMesh>
66  (
67  IOobject
68  (
69  name,
70  vtf.instance(),
71  mesh,
72  IOobject::NO_READ,
73  IOobject::NO_WRITE
74  ),
75  mesh,
76  dimensioned<GradType>(vtf.dimensions()/dimLength, Zero),
77  extrapolatedCalculatedFvPatchField<GradType>::typeName
78  )
79  );
80  GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad.ref();
81  Field<GradType>& lsGradIf = lsGrad;
82 
83  const extendedCentredCellToCellStencil& stencil = lsv.stencil();
84  const List<List<label>>& stencilAddr = stencil.stencil();
85  const List<List<vector>>& lsvs = lsv.vectors();
86 
87  // Construct flat version of vtf
88  // including all values referred to by the stencil
89  List<Type> flatVtf(stencil.map().constructSize(), Zero);
90 
91  // Insert internal values
92  forAll(vtf, celli)
93  {
94  flatVtf[celli] = vtf[celli];
95  }
96 
97  // Insert boundary values
98  forAll(vtf.boundaryField(), patchi)
99  {
100  const fvPatchField<Type>& ptf = vtf.boundaryField()[patchi];
101 
102  label nCompact =
103  ptf.patch().start()
104  - mesh.nInternalFaces()
105  + mesh.nCells();
106 
107  forAll(ptf, i)
108  {
109  flatVtf[nCompact++] = ptf[i];
110  }
111  }
112 
113  // Do all swapping to complete flatVtf
114  stencil.map().distribute(flatVtf);
115 
116  // Accumulate the cell-centred gradient from the
117  // weighted least-squares vectors and the flattened field values
118  forAll(stencilAddr, celli)
119  {
120  const labelList& compactCells = stencilAddr[celli];
121  const List<vector>& lsvc = lsvs[celli];
122 
123  forAll(compactCells, i)
124  {
125  lsGradIf[celli] += lsvc[i]*flatVtf[compactCells[i]];
126  }
127  }
128 
129  // Correct the boundary conditions
130  lsGrad.correctBoundaryConditions();
132 
133  return tlsGrad;
134 }
135 
136 
137 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::fv::LeastSquaresGrad::calcGrad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
extrapolatedCalculatedFvPatchField.H
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
volMesh.H
LeastSquaresVectors.H
LeastSquaresGrad.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
correctBoundaryConditions
cellMask correctBoundaryConditions()
gaussGrad.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
fvMesh.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53