OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

gaussLaplacianScheme.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "gaussLaplacianScheme.H"
00028 #include "surfaceInterpolate.H"
00029 #include "fvcDiv.H"
00030 #include "fvcGrad.H"
00031 #include "fvMatrices.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace fv
00041 {
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 template<class Type, class GType>
00046 tmp<fvMatrix<Type> >
00047 gaussLaplacianScheme<Type, GType>::fvmLaplacianUncorrected
00048 (
00049     const surfaceScalarField& gammaMagSf,
00050     GeometricField<Type, fvPatchField, volMesh>& vf
00051 )
00052 {
00053     tmp<surfaceScalarField> tdeltaCoeffs =
00054         this->tsnGradScheme_().deltaCoeffs(vf);
00055     const surfaceScalarField& deltaCoeffs = tdeltaCoeffs();
00056 
00057     tmp<fvMatrix<Type> > tfvm
00058     (
00059         new fvMatrix<Type>
00060         (
00061             vf,
00062             deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions()
00063         )
00064     );
00065     fvMatrix<Type>& fvm = tfvm();
00066 
00067     fvm.upper() = deltaCoeffs.internalField()*gammaMagSf.internalField();
00068     fvm.negSumDiag();
00069 
00070     forAll(fvm.psi().boundaryField(), patchI)
00071     {
00072         const fvPatchField<Type>& psf = fvm.psi().boundaryField()[patchI];
00073         const fvsPatchScalarField& patchGamma =
00074             gammaMagSf.boundaryField()[patchI];
00075 
00076         fvm.internalCoeffs()[patchI] = patchGamma*psf.gradientInternalCoeffs();
00077         fvm.boundaryCoeffs()[patchI] = -patchGamma*psf.gradientBoundaryCoeffs();
00078     }
00079 
00080     return tfvm;
00081 }
00082 
00083 
00084 template<class Type, class GType>
00085 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00086 gaussLaplacianScheme<Type, GType>::gammaSnGradCorr
00087 (
00088     const surfaceVectorField& SfGammaCorr,
00089     const GeometricField<Type, fvPatchField, volMesh>& vf
00090 )
00091 {
00092     const fvMesh& mesh = this->mesh();
00093 
00094     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tgammaSnGradCorr
00095     (
00096         new GeometricField<Type, fvsPatchField, surfaceMesh>
00097         (
00098             IOobject
00099             (
00100                 "gammaSnGradCorr("+vf.name()+')',
00101                 vf.instance(),
00102                 mesh,
00103                 IOobject::NO_READ,
00104                 IOobject::NO_WRITE
00105             ),
00106             mesh,
00107             SfGammaCorr.dimensions()
00108            *vf.dimensions()*mesh.deltaCoeffs().dimensions()
00109         )
00110     );
00111 
00112     for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
00113     {
00114         tgammaSnGradCorr().replace
00115         (
00116             cmpt,
00117             SfGammaCorr & fvc::interpolate(fvc::grad(vf.component(cmpt)))
00118         );
00119     }
00120 
00121     return tgammaSnGradCorr;
00122 }
00123 
00124 
00125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00126 
00127 template<class Type, class GType>
00128 tmp<GeometricField<Type, fvPatchField, volMesh> >
00129 gaussLaplacianScheme<Type, GType>::fvcLaplacian
00130 (
00131     const GeometricField<Type, fvPatchField, volMesh>& vf
00132 )
00133 {
00134     const fvMesh& mesh = this->mesh();
00135 
00136     tmp<GeometricField<Type, fvPatchField, volMesh> > tLaplacian
00137     (
00138         fvc::div(this->tsnGradScheme_().snGrad(vf)*mesh.magSf())
00139     );
00140 
00141     tLaplacian().rename("laplacian(" + vf.name() + ')');
00142 
00143     return tLaplacian;
00144 }
00145 
00146 
00147 template<class Type, class GType>
00148 tmp<fvMatrix<Type> >
00149 gaussLaplacianScheme<Type, GType>::fvmLaplacian
00150 (
00151     const GeometricField<GType, fvsPatchField, surfaceMesh>& gamma,
00152     GeometricField<Type, fvPatchField, volMesh>& vf
00153 )
00154 {
00155     const fvMesh& mesh = this->mesh();
00156 
00157     surfaceVectorField Sn = mesh.Sf()/mesh.magSf();
00158 
00159     surfaceVectorField SfGamma = mesh.Sf() & gamma;
00160     GeometricField<scalar, fvsPatchField, surfaceMesh> SfGammaSn = SfGamma & Sn;
00161     surfaceVectorField SfGammaCorr = SfGamma - SfGammaSn*Sn;
00162 
00163     tmp<fvMatrix<Type> > tfvm = fvmLaplacianUncorrected(SfGammaSn, vf);
00164     fvMatrix<Type>& fvm = tfvm();
00165 
00166     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tfaceFluxCorrection
00167         = gammaSnGradCorr(SfGammaCorr, vf);
00168 
00169     if (this->tsnGradScheme_().corrected())
00170     {
00171         tfaceFluxCorrection() +=
00172             SfGammaSn*this->tsnGradScheme_().correction(vf);
00173     }
00174 
00175     fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().internalField();
00176 
00177     if (mesh.fluxRequired(vf.name()))
00178     {
00179         fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
00180     }
00181 
00182     return tfvm;
00183 }
00184 
00185 
00186 template<class Type, class GType>
00187 tmp<GeometricField<Type, fvPatchField, volMesh> >
00188 gaussLaplacianScheme<Type, GType>::fvcLaplacian
00189 (
00190     const GeometricField<GType, fvsPatchField, surfaceMesh>& gamma,
00191     const GeometricField<Type, fvPatchField, volMesh>& vf
00192 )
00193 {
00194     const fvMesh& mesh = this->mesh();
00195 
00196     surfaceVectorField Sn = mesh.Sf()/mesh.magSf();
00197 
00198     surfaceVectorField SfGamma = mesh.Sf() & gamma;
00199     GeometricField<scalar, fvsPatchField, surfaceMesh> SfGammaSn = SfGamma & Sn;
00200     surfaceVectorField SfGammaCorr = SfGamma - SfGammaSn*Sn;
00201 
00202     tmp<GeometricField<Type, fvPatchField, volMesh> > tLaplacian
00203     (
00204         fvc::div
00205         (
00206             SfGammaSn*this->tsnGradScheme_().snGrad(vf)
00207           + gammaSnGradCorr(SfGammaCorr, vf)
00208         )
00209     );
00210 
00211     tLaplacian().rename("laplacian(" + gamma.name() + ',' + vf.name() + ')');
00212 
00213     return tLaplacian;
00214 }
00215 
00216 
00217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00218 
00219 } // End namespace fv
00220 
00221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00222 
00223 } // End namespace Foam
00224 
00225 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd