1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "gaussGrad.H"
28 #include "zeroGradientFvPatchField.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
52 const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
55 typedef typename outerProduct<vector, Type>::type GradType;
57 const fvMesh& mesh = ssf.mesh();
59 tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
61 new GeometricField<GradType, fvPatchField, volMesh>
65 "grad("+ssf.name()+')',
75 ssf.dimensions()/dimLength,
76 pTraits<GradType>::zero
78 zeroGradientFvPatchField<GradType>::typeName
81 GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
83 const unallocLabelList& owner = mesh.owner();
84 const unallocLabelList& neighbour = mesh.neighbour();
85 const vectorField& Sf = mesh.Sf();
87 Field<GradType>& igGrad = gGrad;
88 const Field<Type>& issf = ssf;
92 GradType Sfssf = Sf[facei]*issf[facei];
94 igGrad[owner[facei]] += Sfssf;
95 igGrad[neighbour[facei]] -= Sfssf;
98 forAll(mesh.boundary(), patchi)
100 const unallocLabelList& pFaceCells =
101 mesh.boundary()[patchi].faceCells();
103 const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
105 const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
107 forAll(mesh.boundary()[patchi], facei)
109 igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
115 gGrad.correctBoundaryConditions();
126 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
129 gaussGrad<Type>::grad
131 const GeometricField<Type, fvPatchField, volMesh>& vsf
134 typedef typename outerProduct<vector, Type>::type GradType;
136 tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
138 grad(tinterpScheme_().interpolate(vsf))
140 GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();
142 gGrad.rename("grad(" + vsf.name() + ')');
143 correctBoundaryConditions(vsf, gGrad);
150 void gaussGrad<Type>::correctBoundaryConditions
152 const GeometricField<Type, fvPatchField, volMesh>& vsf,
155 typename outerProduct<vector, Type>::type, fvPatchField, volMesh
159 forAll(vsf.boundaryField(), patchi)
161 if (!vsf.boundaryField()[patchi].coupled())
164 vsf.mesh().Sf().boundaryField()[patchi]
165 /vsf.mesh().magSf().boundaryField()[patchi];
167 gGrad.boundaryField()[patchi] += n *
169 vsf.boundaryField()[patchi].snGrad()
170 - (n & gGrad.boundaryField()[patchi])
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace fv
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace Foam
185 // ************************************************************************* //