initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / finiteVolume / laplacianSchemes / gaussLaplacianScheme / gaussLaplacianScheme.C
blob1df55b7e17b8be53c0c950a885143b0e9d6bec80
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
29 #include "fvcDiv.H"
30 #include "fvcGrad.H"
31 #include "fvMatrices.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace fv
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 template<class Type, class GType>
46 tmp<fvMatrix<Type> >
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
58     (
59         new fvMatrix<Type>
60         (
61             vf,
62             deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions()
63         )
64     );
65     fvMatrix<Type>& fvm = tfvm();
67     fvm.upper() = deltaCoeffs.internalField()*gammaMagSf.internalField();
68     fvm.negSumDiag();
70     forAll(fvm.psi().boundaryField(), patchI)
71     {
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();
78     }
80     return tfvm;
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
95     (
96         new GeometricField<Type, fvsPatchField, surfaceMesh>
97         (
98             IOobject
99             (
100                 "gammaSnGradCorr("+vf.name()+')',
101                 vf.instance(),
102                 mesh,
103                 IOobject::NO_READ,
104                 IOobject::NO_WRITE
105             ),
106             mesh,
107             SfGammaCorr.dimensions()
108            *vf.dimensions()*mesh.deltaCoeffs().dimensions()
109         )
110     );
112     for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
113     {
114         tgammaSnGradCorr().replace
115         (
116             cmpt,
117             SfGammaCorr & fvc::interpolate(fvc::grad(vf.component(cmpt)))
118         );
119     }
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
137     (
138         fvc::div(this->tsnGradScheme_().snGrad(vf)*mesh.magSf())
139     );
141     tLaplacian().rename("laplacian(" + vf.name() + ')');
143     return tLaplacian;
147 template<class Type, class GType>
148 tmp<fvMatrix<Type> >
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())
170     {
171         tfaceFluxCorrection() +=
172             SfGammaSn*this->tsnGradScheme_().correction(vf);
173     }
175     fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().internalField();
177     if (mesh.fluxRequired(vf.name()))
178     {
179         fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
180     }
182     return tfvm;
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
203     (
204         fvc::div
205         (
206             SfGammaSn*this->tsnGradScheme_().snGrad(vf)
207           + gammaSnGradCorr(SfGammaCorr, vf)
208         )
209     );
211     tLaplacian().rename("laplacian(" + gamma.name() + ',' + vf.name() + ')');
213     return tLaplacian;
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace fv
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 } // End namespace Foam
225 // ************************************************************************* //