gaussFaGrad.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 -------------------------------------------------------------------------------
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 "gaussFaGrad.H"
30 #include "facGrad.H"
31 #include "areaFields.H"
32 #include "edgeFields.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace fa
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 template<class Type>
47 tmp
48 <
49  GeometricField
50  <
52  faPatchField,
53  areaMesh
54  >
55 >
57 (
58  const GeometricField<Type, faePatchField, edgeMesh>& ssf,
59  const word& name
60 )
61 {
62  const areaVectorField &n = ssf.mesh().faceAreaNormals();
63  typedef typename outerProduct<vector,Type>::type GradType;
64 
65  tmp<GeometricField<GradType, faPatchField, areaMesh>> tgGrad =
66  fac::edgeIntegrate(ssf.mesh().Sf()*ssf);
67 
68  GeometricField<GradType, faPatchField, areaMesh>& gGrad = tgGrad.ref();
69 
70  gGrad -= n*(n & gGrad);
71  gGrad.correctBoundaryConditions();
72 
73  return tgGrad;
74 }
75 
76 
77 template<class Type>
78 tmp
79 <
80  GeometricField
81  <
83  faPatchField,
84  areaMesh
85  >
86 >
88 (
89  const GeometricField<Type, faPatchField, areaMesh>& vsf,
90  const word& name
91 ) const
92 {
93  typedef typename outerProduct<vector, Type>::type GradType;
94  typedef GeometricField<GradType, faPatchField, areaMesh> GradFieldType;
95 
96  tmp<GradFieldType> tgGrad
97  (
99  (
100  vsf.mesh().Le()
101  *tinterpScheme_().interpolate(vsf)
102  )
103  );
104  GradFieldType& gGrad = tgGrad.ref();
105 
106  gGrad.correctBoundaryConditions();
107  gGrad.rename(name);
108 
109  correctBoundaryConditions(vsf, gGrad);
111  return tgGrad;
112 }
113 
114 
115 template<class Type>
117 (
120  <
122  >& gGrad
123 )
124 {
125  forAll(vsf.boundaryField(), patchI)
126  {
127  if (!vsf.boundaryField()[patchI].coupled())
128  {
129  const vectorField m
130  (
131  vsf.mesh().Le().boundaryField()[patchI]/
132  vsf.mesh().magLe().boundaryField()[patchI]
133  );
134 
135  gGrad.boundaryFieldRef()[patchI] += m*
136  (
137  vsf.boundaryField()[patchI].snGrad()
138  - (m & gGrad.boundaryField()[patchI])
139  );
140  }
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace fa
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // ************************************************************************* //
cellMask correctBoundaryConditions()
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Calculate the gradient of the given field.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const Mesh & mesh() const noexcept
Return mesh.
tmp< GeometricField< Type, faPatchField, areaMesh > > edgeIntegrate(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
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.
Mesh data needed to do the Finite Area discretisation.
Definition: areaFaMesh.H:47
static tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > gradf(const GeometricField< Type, faePatchField, edgeMesh > &, const word &name)
Return the gradient of the given field calculated using Gauss&#39; theorem on the given surface field...
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.
Definition: gaussFaGrad.C:110
label n
GeometricField< vector, faPatchField, areaMesh > areaVectorField
Definition: areaFieldsFwd.H:81
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
Namespace for OpenFOAM.