gaussGrad.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2021 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 "gaussGrad.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 <
38  <
42  >
43 >
45 (
46  const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
47  const word& name
48 )
49 {
50  typedef typename outerProduct<vector, Type>::type GradType;
51  typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
52 
53  const fvMesh& mesh = ssf.mesh();
54 
55  tmp<GradFieldType> tgGrad
56  (
57  new GradFieldType
58  (
59  IOobject
60  (
61  name,
62  ssf.instance(),
63  mesh,
64  IOobject::NO_READ,
65  IOobject::NO_WRITE
66  ),
67  mesh,
68  dimensioned<GradType>(ssf.dimensions()/dimLength, Zero),
69  extrapolatedCalculatedFvPatchField<GradType>::typeName
70  )
71  );
72  GradFieldType& gGrad = tgGrad.ref();
73 
74  const labelUList& owner = mesh.owner();
75  const labelUList& neighbour = mesh.neighbour();
76  const vectorField& Sf = mesh.Sf();
77 
78  Field<GradType>& igGrad = gGrad;
79  const Field<Type>& issf = ssf;
80 
81  forAll(owner, facei)
82  {
83  const GradType Sfssf = Sf[facei]*issf[facei];
84 
85  igGrad[owner[facei]] += Sfssf;
86  igGrad[neighbour[facei]] -= Sfssf;
87  }
88 
89  forAll(mesh.boundary(), patchi)
90  {
91  const labelUList& pFaceCells =
92  mesh.boundary()[patchi].faceCells();
93 
94  const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
95 
96  const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
97 
98  forAll(mesh.boundary()[patchi], facei)
99  {
100  igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
101  }
102  }
103 
104  igGrad /= mesh.V();
105 
106  gGrad.correctBoundaryConditions();
107 
108  return tgGrad;
109 }
110 
111 
112 template<class Type>
113 Foam::tmp
114 <
116  <
120  >
121 >
123 (
124  const GeometricField<Type, fvPatchField, volMesh>& vsf,
125  const word& name
126 ) const
127 {
128  typedef typename outerProduct<vector, Type>::type GradType;
129  typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
130 
131  tmp<GradFieldType> tgGrad
132  (
133  gradf(tinterpScheme_().interpolate(vsf), name)
134  );
135  GradFieldType& gGrad = tgGrad.ref();
136 
137  correctBoundaryConditions(vsf, gGrad);
138 
139  return tgGrad;
140 }
141 
142 
143 template<class Type>
145 (
148  <
150  >& gGrad
151 )
152 {
153  typename GeometricField
154  <
156  >::Boundary& gGradbf = gGrad.boundaryFieldRef();
157 
158  forAll(vsf.boundaryField(), patchi)
159  {
160  if (!vsf.boundaryField()[patchi].coupled())
161  {
162  const vectorField n
163  (
164  vsf.mesh().Sf().boundaryField()[patchi]
165  / vsf.mesh().magSf().boundaryField()[patchi]
166  );
167 
168  gGradbf[patchi] += n *
169  (
170  vsf.boundaryField()[patchi].snGrad()
171  - (n & gGradbf[patchi])
172  );
173  }
174  }
175 }
176 
177 
178 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::fv::gaussGrad::gradf
static tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > gradf(const GeometricField< Type, fvsPatchField, surfaceMesh > &, const word &name)
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
extrapolatedCalculatedFvPatchField.H
Foam::fv::gaussGrad::calcGrad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:51
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::fv::gaussGrad::correctBoundaryConditions
static void correctBoundaryConditions(const GeometricField< Type, fvPatchField, volMesh > &, GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > &)
Definition: gaussGrad.C:145
correctBoundaryConditions
cellMask correctBoundaryConditions()
n
label n
Definition: TABSMDCalcMethod2.H:31
gaussGrad.H
Foam::Field< vector >
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::fac::interpolate
static tmp< GeometricField< Type, faePatchField, edgeMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &tvf, const edgeScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62