Loading...
Searching...
No Matches
leastSquaresFaGrad.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) 2016-2017 Wikki Ltd
9 Copyright (C) 2023 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 "leastSquaresFaGrad.H"
31#include "gaussFaGrad.H"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35namespace Foam
36{
37
38// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39
40namespace fa
41{
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44template<class Type>
45tmp
46<
48 <
52 >
53>
55(
57 const word& name
58) const
59{
60 typedef typename outerProduct<vector, Type>::type GradType;
61
62 const faMesh& mesh = vsf.mesh();
63
65 (
67 (
69 (
70 name,
71 vsf.instance(),
72 vsf.db(),
75 ),
76 mesh,
79 )
80 );
82
83 // Get reference to least square vectors
85
86 const edgeVectorField& ownLs = lsv.pVectors();
87 const edgeVectorField& neiLs = lsv.nVectors();
88
89 const labelUList& own = mesh.owner();
90 const labelUList& nei = mesh.neighbour();
91
92 forAll(own, edgei)
93 {
94 const label ownEdgeI = own[edgei];
95 const label neiEdgeI = nei[edgei];
96
97 const Type deltaVsf(vsf[neiEdgeI] - vsf[ownEdgeI]);
98
99 lsGrad[ownEdgeI] += ownLs[edgei]*deltaVsf;
100 lsGrad[neiEdgeI] -= neiLs[edgei]*deltaVsf;
101 }
102
103 // Boundary edges
104 forAll(vsf.boundaryField(), patchi)
105 {
106 const faPatchField<Type>& bf = vsf.boundaryField()[patchi];
107
108 tmp<Field<Type>> tvsfp(bf);
109
110 if (bf.coupled())
111 {
112 tvsfp = bf.patchNeighbourField();
113 }
114 const auto& vsfp = tvsfp();
115
116 const faePatchVectorField& ownLsp = ownLs.boundaryField()[patchi];
117 const labelUList& edgeFaces =
118 lsGrad.boundaryField()[patchi].patch().edgeFaces();
119
120 forAll(vsfp, pEdgei)
121 {
122 lsGrad[edgeFaces[pEdgei]] +=
123 ownLsp[pEdgei]*(vsfp[pEdgei] - vsf[edgeFaces[pEdgei]]);
124 }
125 }
126
127 // Remove component of gradient normal to surface (area)
129
131
132 return tlsGrad;
133}
134
135
136// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137
138} // End namespace fa
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141
142} // End namespace Foam
143
144// ************************************************************************* //
const Mesh & mesh() const noexcept
Return const reference to mesh.
const dimensionSet & dimensions() const noexcept
Return dimensions.
Generic GeometricField class.
void correctBoundaryConditions()
Correct boundary field.
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 objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition IOobject.C:450
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
static FOAM_NO_DANGLING_REFERENCE const leastSquaresFaVectors & New(const faMesh &mesh, Args &&... args)
Mesh data needed to do the Finite Area discretisation.
Definition areaFaMesh.H:50
Generic dimensioned Type class.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
virtual bool coupled() const
True if the patch field is coupled.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
static void correctBoundaryConditions(const GeometricField< Type, faPatchField, areaMesh > &, GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > &)
Correct the boundary values of the gradient using the patchField.
const faMesh & mesh() const noexcept
Return mesh reference.
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > calcGrad(const GeometricField< Type, faPatchField, areaMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad for optional caching.
Least-squares gradient scheme vectors for the Finite Area method.
const edgeVectorField & pVectors() const
Return reference to owner least square vectors.
const edgeVectorField & nVectors() const
Return reference to neighbour least square vectors.
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
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for finite-area.
Definition limitHeight.C:30
Namespace for OpenFOAM.
GeometricField< vector, faePatchField, edgeMesh > edgeVectorField
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
faePatchField< vector > faePatchVectorField
UList< label > labelUList
A UList of labels.
Definition UList.H:75
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299