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 "gaussLaplacianScheme.H"
28 #include "surfaceInterpolate.H"
31 #include "fvMatrices.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 template<class Type, class GType>
47 gaussLaplacianScheme<Type, GType>::fvmLaplacianUncorrected
49 const surfaceScalarField& gammaMagSf,
50 GeometricField<Type, fvPatchField, volMesh>& vf
53 tmp<surfaceScalarField> tdeltaCoeffs =
54 this->tsnGradScheme_().deltaCoeffs(vf);
55 const surfaceScalarField& deltaCoeffs = tdeltaCoeffs();
57 tmp<fvMatrix<Type> > tfvm
62 deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions()
65 fvMatrix<Type>& fvm = tfvm();
67 fvm.upper() = deltaCoeffs.internalField()*gammaMagSf.internalField();
70 forAll(fvm.psi().boundaryField(), patchI)
72 const fvPatchField<Type>& psf = fvm.psi().boundaryField()[patchI];
73 const fvsPatchScalarField& patchGamma =
74 gammaMagSf.boundaryField()[patchI];
76 fvm.internalCoeffs()[patchI] = patchGamma*psf.gradientInternalCoeffs();
77 fvm.boundaryCoeffs()[patchI] = -patchGamma*psf.gradientBoundaryCoeffs();
84 template<class Type, class GType>
85 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
86 gaussLaplacianScheme<Type, GType>::gammaSnGradCorr
88 const surfaceVectorField& SfGammaCorr,
89 const GeometricField<Type, fvPatchField, volMesh>& vf
92 const fvMesh& mesh = this->mesh();
94 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tgammaSnGradCorr
96 new GeometricField<Type, fvsPatchField, surfaceMesh>
100 "gammaSnGradCorr("+vf.name()+')',
107 SfGammaCorr.dimensions()
108 *vf.dimensions()*mesh.deltaCoeffs().dimensions()
112 for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
114 tgammaSnGradCorr().replace
117 SfGammaCorr & fvc::interpolate(fvc::grad(vf.component(cmpt)))
121 return tgammaSnGradCorr;
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 template<class Type, class GType>
128 tmp<GeometricField<Type, fvPatchField, volMesh> >
129 gaussLaplacianScheme<Type, GType>::fvcLaplacian
131 const GeometricField<Type, fvPatchField, volMesh>& vf
134 const fvMesh& mesh = this->mesh();
136 tmp<GeometricField<Type, fvPatchField, volMesh> > tLaplacian
138 fvc::div(this->tsnGradScheme_().snGrad(vf)*mesh.magSf())
141 tLaplacian().rename("laplacian(" + vf.name() + ')');
147 template<class Type, class GType>
149 gaussLaplacianScheme<Type, GType>::fvmLaplacian
151 const GeometricField<GType, fvsPatchField, surfaceMesh>& gamma,
152 GeometricField<Type, fvPatchField, volMesh>& vf
155 const fvMesh& mesh = this->mesh();
157 surfaceVectorField Sn = mesh.Sf()/mesh.magSf();
159 surfaceVectorField SfGamma = mesh.Sf() & gamma;
160 GeometricField<scalar, fvsPatchField, surfaceMesh> SfGammaSn = SfGamma & Sn;
161 surfaceVectorField SfGammaCorr = SfGamma - SfGammaSn*Sn;
163 tmp<fvMatrix<Type> > tfvm = fvmLaplacianUncorrected(SfGammaSn, vf);
164 fvMatrix<Type>& fvm = tfvm();
166 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tfaceFluxCorrection
167 = gammaSnGradCorr(SfGammaCorr, vf);
169 if (this->tsnGradScheme_().corrected())
171 tfaceFluxCorrection() +=
172 SfGammaSn*this->tsnGradScheme_().correction(vf);
175 fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().internalField();
177 if (mesh.fluxRequired(vf.name()))
179 fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
186 template<class Type, class GType>
187 tmp<GeometricField<Type, fvPatchField, volMesh> >
188 gaussLaplacianScheme<Type, GType>::fvcLaplacian
190 const GeometricField<GType, fvsPatchField, surfaceMesh>& gamma,
191 const GeometricField<Type, fvPatchField, volMesh>& vf
194 const fvMesh& mesh = this->mesh();
196 surfaceVectorField Sn = mesh.Sf()/mesh.magSf();
198 surfaceVectorField SfGamma = mesh.Sf() & gamma;
199 GeometricField<scalar, fvsPatchField, surfaceMesh> SfGammaSn = SfGamma & Sn;
200 surfaceVectorField SfGammaCorr = SfGamma - SfGammaSn*Sn;
202 tmp<GeometricField<Type, fvPatchField, volMesh> > tLaplacian
206 SfGammaSn*this->tsnGradScheme_().snGrad(vf)
207 + gammaSnGradCorr(SfGammaCorr, vf)
211 tLaplacian().rename("laplacian(" + gamma.name() + ',' + vf.name() + ')');
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace fv
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 } // End namespace Foam
225 // ************************************************************************* //