gaussGrad.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "gaussGrad.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 <
35  <
36  typename Foam::outerProduct<Foam::vector, Type>::type,
37  Foam::fvPatchField,
39  >
40 >
42 (
43  const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
44  const word& name
45 )
46 {
47  typedef typename outerProduct<vector, Type>::type GradType;
48 
49  const fvMesh& mesh = ssf.mesh();
50 
51  tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
52  (
53  new GeometricField<GradType, fvPatchField, volMesh>
54  (
55  IOobject
56  (
57  name,
58  ssf.instance(),
59  mesh,
60  IOobject::NO_READ,
61  IOobject::NO_WRITE
62  ),
63  mesh,
64  dimensioned<GradType>
65  (
66  "0",
67  ssf.dimensions()/dimLength,
68  Zero
69  ),
70  extrapolatedCalculatedFvPatchField<GradType>::typeName
71  )
72  );
73  GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad.ref();
74 
75  const labelUList& owner = mesh.owner();
76  const labelUList& neighbour = mesh.neighbour();
77  const vectorField& Sf = mesh.Sf();
78 
79  Field<GradType>& igGrad = gGrad;
80  const Field<Type>& issf = ssf;
81 
82  forAll(owner, facei)
83  {
84  GradType Sfssf = Sf[facei]*issf[facei];
85 
86  igGrad[owner[facei]] += Sfssf;
87  igGrad[neighbour[facei]] -= Sfssf;
88  }
89 
90  forAll(mesh.boundary(), patchi)
91  {
92  const labelUList& pFaceCells =
93  mesh.boundary()[patchi].faceCells();
94 
95  const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
96 
97  const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
98 
99  forAll(mesh.boundary()[patchi], facei)
100  {
101  igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
102  }
103  }
104 
105  igGrad /= mesh.V();
106 
107  gGrad.correctBoundaryConditions();
108 
109  return tgGrad;
110 }
111 
112 
113 template<class Type>
114 Foam::tmp
115 <
117  <
118  typename Foam::outerProduct<Foam::vector, Type>::type,
119  Foam::fvPatchField,
121  >
122 >
124 (
125  const GeometricField<Type, fvPatchField, volMesh>& vsf,
126  const word& name
127 ) const
128 {
129  typedef typename outerProduct<vector, Type>::type GradType;
130 
131  tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
132  (
133  gradf(tinterpScheme_().interpolate(vsf), name)
134  );
135  GeometricField<GradType, fvPatchField, volMesh>& 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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
type
Types of root.
Definition: Roots.H:52
const Boundary & boundaryField() const
Return const-reference to the boundary field.
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.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
volVectorField vectorField(fieldObject, mesh)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Generic GeometricField class.
UList< label > labelUList
Definition: UList.H:64
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.
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:53
dynamicFvMesh & mesh
static const zero Zero
Definition: zero.H:97
U 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:145
const Mesh & mesh() const
Return mesh.
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
label patchi
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
label n
A class for managing temporary objects.
Definition: PtrList.H:53