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 -------------------------------------------------------------------------------
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 "gaussGrad.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 <
37  <
41  >
42 >
44 (
45  const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
46  const word& name
47 )
48 {
49  typedef typename outerProduct<vector, Type>::type GradType;
50 
51  const fvMesh& mesh = ssf.mesh();
52 
53  tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
54  (
55  new GeometricField<GradType, fvPatchField, volMesh>
56  (
57  IOobject
58  (
59  name,
60  ssf.instance(),
61  mesh,
62  IOobject::NO_READ,
63  IOobject::NO_WRITE
64  ),
65  mesh,
66  dimensioned<GradType>(ssf.dimensions()/dimLength, Zero),
67  extrapolatedCalculatedFvPatchField<GradType>::typeName
68  )
69  );
70  GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad.ref();
71 
72  const labelUList& owner = mesh.owner();
73  const labelUList& neighbour = mesh.neighbour();
74  const vectorField& Sf = mesh.Sf();
75 
76  Field<GradType>& igGrad = gGrad;
77  const Field<Type>& issf = ssf;
78 
79  forAll(owner, facei)
80  {
81  GradType Sfssf = Sf[facei]*issf[facei];
82 
83  igGrad[owner[facei]] += Sfssf;
84  igGrad[neighbour[facei]] -= Sfssf;
85  }
86 
87  forAll(mesh.boundary(), patchi)
88  {
89  const labelUList& pFaceCells =
90  mesh.boundary()[patchi].faceCells();
91 
92  const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
93 
94  const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
95 
96  forAll(mesh.boundary()[patchi], facei)
97  {
98  igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
99  }
100  }
101 
102  igGrad /= mesh.V();
103 
104  gGrad.correctBoundaryConditions();
105 
106  return tgGrad;
107 }
108 
109 
110 template<class Type>
111 Foam::tmp
112 <
114  <
118  >
119 >
121 (
122  const GeometricField<Type, fvPatchField, volMesh>& vsf,
123  const word& name
124 ) const
125 {
126  typedef typename outerProduct<vector, Type>::type GradType;
127 
128  tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
129  (
130  gradf(tinterpScheme_().interpolate(vsf), name)
131  );
132  GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad.ref();
133 
134  correctBoundaryConditions(vsf, gGrad);
135 
136  return tgGrad;
137 }
138 
139 
140 template<class Type>
142 (
145  <
147  >& gGrad
148 )
149 {
150  typename GeometricField
151  <
153  >::Boundary& gGradbf = gGrad.boundaryFieldRef();
154 
155  forAll(vsf.boundaryField(), patchi)
156  {
157  if (!vsf.boundaryField()[patchi].coupled())
158  {
159  const vectorField n
160  (
161  vsf.mesh().Sf().boundaryField()[patchi]
162  / vsf.mesh().magSf().boundaryField()[patchi]
163  );
164 
165  gGradbf[patchi] += n *
166  (
167  vsf.boundaryField()[patchi].snGrad()
168  - (n & gGradbf[patchi])
169  );
170  }
171  }
172 }
173 
174 
175 // ************************************************************************* //
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::fv::gaussGrad::gradf
static tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > gradf(const GeometricField< Type, fvsPatchField, surfaceMesh > &, const word &name)
Return the gradient of the given field.
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: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
Return the gradient of the given field to the gradScheme::grad.
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
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 > &)
Correct the boundary values of the gradient using the patchField.
Definition: gaussGrad.C:142
correctBoundaryConditions
cellMask correctBoundaryConditions()
n
label n
Definition: TABSMDCalcMethod2.H:31
gaussGrad.H
Foam::Field< vector >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
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