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 | Copyright (C) 2011 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  pTraits<GradType>::zero
69  ),
70  zeroGradientFvPatchField<GradType>::typeName
71  )
72  );
73  GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
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();
136 
137  correctBoundaryConditions(vsf, gGrad);
138 
139  return tgGrad;
140 }
141 
142 
143 template<class Type>
145 (
148  <
150  >& gGrad
151 )
152 {
153  forAll(vsf.boundaryField(), patchi)
154  {
155  if (!vsf.boundaryField()[patchi].coupled())
156  {
157  const vectorField n
158  (
159  vsf.mesh().Sf().boundaryField()[patchi]
160  / vsf.mesh().magSf().boundaryField()[patchi]
161  );
162 
163  gGrad.boundaryField()[patchi] += n *
164  (
165  vsf.boundaryField()[patchi].snGrad()
166  - (n & gGrad.boundaryField()[patchi])
167  );
168  }
169  }
170 }
171 
172 
173 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
UList< label > labelUList
Definition: UList.H:63
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.
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
tmp< surfaceScalarField > interpolate(const RhoType &rho)
const Mesh & mesh() const
Return mesh.
dynamicFvMesh & mesh
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
label n
volVectorField vectorField(fieldObject, mesh)
#define forAll(list, i)
Definition: UList.H:421
label patchi
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
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Generic GeometricField class.
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.
U correctBoundaryConditions()
A class for managing temporary objects.
Definition: PtrList.H:118