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

LimitedScheme.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 "volFields.H"
00028 #include "surfaceFields.H"
00029 #include "fvcGrad.H"
00030 #include "coupledFvPatchFields.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 template<class Type, class Limiter, template<class> class LimitFunc>
00040 tmp<surfaceScalarField> LimitedScheme<Type, Limiter, LimitFunc>::limiter
00041 (
00042     const GeometricField<Type, fvPatchField, volMesh>& phi
00043 ) const
00044 {
00045     const fvMesh& mesh = this->mesh();
00046 
00047     tmp<surfaceScalarField> tLimiter
00048     (
00049         new surfaceScalarField
00050         (
00051             IOobject
00052             (
00053                 type() + "Limiter(" + phi.name() + ')',
00054                 mesh.time().timeName(),
00055                 mesh
00056             ),
00057             mesh,
00058             dimless
00059         )
00060     );
00061     surfaceScalarField& lim = tLimiter();
00062 
00063     tmp<GeometricField<typename Limiter::phiType, fvPatchField, volMesh> >
00064         tlPhi = LimitFunc<Type>()(phi);
00065 
00066     const GeometricField<typename Limiter::phiType, fvPatchField, volMesh>&
00067         lPhi = tlPhi();
00068 
00069     GeometricField<typename Limiter::gradPhiType, fvPatchField, volMesh>
00070         gradc(fvc::grad(lPhi));
00071 
00072     const surfaceScalarField& CDweights = mesh.surfaceInterpolation::weights();
00073 
00074     const unallocLabelList& owner = mesh.owner();
00075     const unallocLabelList& neighbour = mesh.neighbour();
00076 
00077     const vectorField& C = mesh.C();
00078 
00079     scalarField& pLim = lim.internalField();
00080 
00081     forAll(pLim, face)
00082     {
00083         label own = owner[face];
00084         label nei = neighbour[face];
00085 
00086         pLim[face] = Limiter::limiter
00087         (
00088             CDweights[face],
00089             this->faceFlux_[face],
00090             lPhi[own],
00091             lPhi[nei],
00092             gradc[own],
00093             gradc[nei],
00094             C[nei] - C[own]
00095         );
00096     }
00097 
00098     surfaceScalarField::GeometricBoundaryField& bLim = lim.boundaryField();
00099 
00100     forAll(bLim, patchi)
00101     {
00102         scalarField& pLim = bLim[patchi];
00103 
00104         if (bLim[patchi].coupled())
00105         {
00106             const scalarField& pCDweights = CDweights.boundaryField()[patchi];
00107             const scalarField& pFaceFlux =
00108                 this->faceFlux_.boundaryField()[patchi];
00109             Field<typename Limiter::phiType> plPhiP =
00110                 lPhi.boundaryField()[patchi].patchInternalField();
00111             Field<typename Limiter::phiType> plPhiN =
00112                 lPhi.boundaryField()[patchi].patchNeighbourField();
00113             Field<typename Limiter::gradPhiType> pGradcP =
00114                 gradc.boundaryField()[patchi].patchInternalField();
00115             Field<typename Limiter::gradPhiType> pGradcN =
00116                 gradc.boundaryField()[patchi].patchNeighbourField();
00117 
00118             // Build the d-vectors
00119             vectorField pd = 
00120                 mesh.Sf().boundaryField()[patchi]
00121                /(
00122                    mesh.magSf().boundaryField()[patchi]
00123                   *mesh.deltaCoeffs().boundaryField()[patchi]
00124                 );
00125 
00126             if (!mesh.orthogonal())
00127             {
00128                 pd -= mesh.correctionVectors().boundaryField()[patchi]
00129                     /mesh.deltaCoeffs().boundaryField()[patchi];
00130             }
00131 
00132             forAll(pLim, face)
00133             {
00134                 pLim[face] = Limiter::limiter
00135                 (
00136                     pCDweights[face],
00137                     pFaceFlux[face],
00138                     plPhiP[face],
00139                     plPhiN[face],
00140                     pGradcP[face],
00141                     pGradcN[face],
00142                     pd[face]
00143                 );
00144             }
00145         }
00146         else
00147         {
00148             pLim = 1.0;
00149         }
00150     }
00151 
00152     return tLimiter;
00153 }
00154 
00155 
00156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00157 
00158 } // End namespace Foam
00159 
00160 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd