Loading...
Searching...
No Matches
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 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "LeastSquaresGrad.H"
30#include "LeastSquaresVectors.H"
31#include "gaussGrad.H"
32#include "fvMesh.H"
33#include "volMesh.H"
35
36// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37
38template<class Type, class Stencil>
40(
42 <
46 >& lsGrad,
48) const
49{
50 typedef typename outerProduct<vector, Type>::type GradType;
51
52 const fvMesh& mesh = vtf.mesh();
53
54 // Get reference to least square vectors
56 (
57 mesh
58 );
59
61 Field<GradType>& lsGradIf = lsGrad;
62
63 const extendedCentredCellToCellStencil& stencil = lsv.stencil();
64 const List<List<label>>& stencilAddr = stencil.stencil();
65 const List<List<vector>>& lsvs = lsv.vectors();
66
67 // Construct flat version of vtf
68 // including all values referred to by the stencil
69 List<Type> flatVtf(stencil.map().constructSize(), Zero);
70
71 // Insert internal values
72 forAll(vtf, celli)
73 {
74 flatVtf[celli] = vtf[celli];
75 }
76
77 // Insert boundary values
78 forAll(vtf.boundaryField(), patchi)
79 {
80 const fvPatchField<Type>& ptf = vtf.boundaryField()[patchi];
81
82 label nCompact =
83 ptf.patch().start()
84 - mesh.nInternalFaces()
85 + mesh.nCells();
86
87 forAll(ptf, i)
88 {
89 flatVtf[nCompact++] = ptf[i];
90 }
91 }
92
93 // Do all swapping to complete flatVtf
94 stencil.map().distribute(flatVtf);
95
96 // Accumulate the cell-centred gradient from the
97 // weighted least-squares vectors and the flattened field values
98 forAll(stencilAddr, celli)
99 {
100 const labelList& compactCells = stencilAddr[celli];
101 const List<vector>& lsvc = lsvs[celli];
102
103 forAll(compactCells, i)
104 {
105 lsGradIf[celli] += lsvc[i]*flatVtf[compactCells[i]];
106 }
107 }
108
109 // Correct the boundary conditions
110 lsGrad.correctBoundaryConditions();
112}
113
114
115template<class Type, class Stencil>
117<
119 <
123 >
124>
126(
128 const word& name
129) const
130{
131 typedef typename outerProduct<vector, Type>::type GradType;
133
134 const fvMesh& mesh = vtf.mesh();
135
136 tmp<GradFieldType> tlsGrad
137 (
138 new GradFieldType
139 (
141 (
142 name,
143 vtf.instance(),
144 mesh,
147 ),
148 mesh,
149 vtf.dimensions()/dimLength,
151 )
152 );
153 GradFieldType& lsGrad = tlsGrad.ref();
154
155 calcGrad(lsGrad, vtf);
156
157 return tlsGrad;
158}
159
160
161// ************************************************************************* //
const Mesh & mesh() const noexcept
Return const reference to mesh.
const dimensionSet & dimensions() const noexcept
Return dimensions.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
Generic GeometricField class.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
static FOAM_NO_DANGLING_REFERENCE const LeastSquaresVectors< Stencil > & New(const fvMesh &mesh, Args &&... args)
Generic dimensioned Type class.
const mapDistribute & map() const
Return reference to the parallel distribution map.
const labelListList & stencil() const
Return reference to the stencil.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const fvPatch & patch() const noexcept
Return the patch.
static const word & extrapolatedCalculatedType() noexcept
The type name for extrapolatedCalculated patch fields combines zero-gradient and calculated.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
label start() const noexcept
The patch start within the polyMesh face list.
Definition fvPatch.H:226
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 for optional caching.
Least-squares gradient scheme vectors.
const extendedCentredCellToCellStencil & stencil() const
Return const reference to the stencil.
const List< List< vector > > & vectors() const
Return const reference to the least square vectors.
static void correctBoundaryConditions(const GeometricField< Type, fvPatchField, volMesh > &, GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > &)
Correct the boundary values of the gradient using the patchField snGrad functions.
Definition gaussGrad.C:199
const fvMesh & mesh() const
Return const reference to mesh.
Definition gradScheme.H:138
label constructSize() const noexcept
Constructed data size.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A class for managing temporary objects.
Definition tmp.H:75
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
Mesh data needed to do the Finite Volume discretisation.
Definition volMesh.H:47
A class for handling words, derived from Foam::string.
Definition word.H:66
List< label > labelList
A List of labels.
Definition List.H:62
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299