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

cellMDLimitedGrads.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 "cellMDLimitedGrad.H"
00028 #include "gaussGrad.H"
00029 #include "fvMesh.H"
00030 #include "volMesh.H"
00031 #include "surfaceMesh.H"
00032 #include "volFields.H"
00033 #include "fixedValueFvPatchFields.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace fv
00043 {
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 makeFvGradScheme(cellMDLimitedGrad)
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 template<>
00052 tmp<volVectorField> cellMDLimitedGrad<scalar>::grad
00053 (
00054     const volScalarField& vsf
00055 ) const
00056 {
00057     const fvMesh& mesh = vsf.mesh();
00058 
00059     tmp<volVectorField> tGrad = basicGradScheme_().grad(vsf);
00060 
00061     if (k_ < SMALL)
00062     {
00063         return tGrad;
00064     }
00065 
00066     volVectorField& g = tGrad();
00067 
00068     const unallocLabelList& owner = mesh.owner();
00069     const unallocLabelList& neighbour = mesh.neighbour();
00070 
00071     const volVectorField& C = mesh.C();
00072     const surfaceVectorField& Cf = mesh.Cf();
00073 
00074     scalarField maxVsf(vsf.internalField());
00075     scalarField minVsf(vsf.internalField());
00076 
00077     forAll(owner, facei)
00078     {
00079         label own = owner[facei];
00080         label nei = neighbour[facei];
00081 
00082         scalar vsfOwn = vsf[own];
00083         scalar vsfNei = vsf[nei];
00084 
00085         maxVsf[own] = max(maxVsf[own], vsfNei);
00086         minVsf[own] = min(minVsf[own], vsfNei);
00087 
00088         maxVsf[nei] = max(maxVsf[nei], vsfOwn);
00089         minVsf[nei] = min(minVsf[nei], vsfOwn);
00090     }
00091 
00092 
00093     const volScalarField::GeometricBoundaryField& bsf = vsf.boundaryField();
00094 
00095     forAll(bsf, patchi)
00096     {
00097         const fvPatchScalarField& psf = bsf[patchi];
00098 
00099         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00100 
00101         if (psf.coupled())
00102         {
00103             scalarField psfNei = psf.patchNeighbourField();
00104 
00105             forAll(pOwner, pFacei)
00106             {
00107                 label own = pOwner[pFacei];
00108                 scalar vsfNei = psfNei[pFacei];
00109 
00110                 maxVsf[own] = max(maxVsf[own], vsfNei);
00111                 minVsf[own] = min(minVsf[own], vsfNei);
00112             }
00113         }
00114         else
00115         {
00116             forAll(pOwner, pFacei)
00117             {
00118                 label own = pOwner[pFacei];
00119                 scalar vsfNei = psf[pFacei];
00120 
00121                 maxVsf[own] = max(maxVsf[own], vsfNei);
00122                 minVsf[own] = min(minVsf[own], vsfNei);
00123             }
00124         }
00125     }
00126 
00127     maxVsf -= vsf;
00128     minVsf -= vsf;
00129 
00130     if (k_ < 1.0)
00131     {
00132         scalarField maxMinVsf = (1.0/k_ - 1.0)*(maxVsf - minVsf);
00133         maxVsf += maxMinVsf;
00134         minVsf -= maxMinVsf;
00135 
00136         //maxVsf *= 1.0/k_;
00137         //minVsf *= 1.0/k_;
00138     }
00139 
00140 
00141     forAll(owner, facei)
00142     {
00143         label own = owner[facei];
00144         label nei = neighbour[facei];
00145 
00146         // owner side
00147         limitFace
00148         (
00149             g[own],
00150             maxVsf[own],
00151             minVsf[own],
00152             Cf[facei] - C[own]
00153         );
00154 
00155         // neighbour side
00156         limitFace
00157         (
00158             g[nei],
00159             maxVsf[nei],
00160             minVsf[nei],
00161             Cf[facei] - C[nei]
00162         );
00163     }
00164 
00165 
00166     forAll(bsf, patchi)
00167     {
00168         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00169         const vectorField& pCf = Cf.boundaryField()[patchi];
00170 
00171         forAll(pOwner, pFacei)
00172         {
00173             label own = pOwner[pFacei];
00174 
00175             limitFace
00176             (
00177                 g[own],
00178                 maxVsf[own],
00179                 minVsf[own],
00180                 pCf[pFacei] - C[own]
00181             );
00182         }
00183     }
00184 
00185     g.correctBoundaryConditions();
00186     gaussGrad<scalar>::correctBoundaryConditions(vsf, g);
00187 
00188     return tGrad;
00189 }
00190 
00191 
00192 template<>
00193 tmp<volTensorField> cellMDLimitedGrad<vector>::grad
00194 (
00195     const volVectorField& vsf
00196 ) const
00197 {
00198     const fvMesh& mesh = vsf.mesh();
00199 
00200     tmp<volTensorField> tGrad = basicGradScheme_().grad(vsf);
00201 
00202     if (k_ < SMALL)
00203     {
00204         return tGrad;
00205     }
00206 
00207     volTensorField& g = tGrad();
00208 
00209     const unallocLabelList& owner = mesh.owner();
00210     const unallocLabelList& neighbour = mesh.neighbour();
00211 
00212     const volVectorField& C = mesh.C();
00213     const surfaceVectorField& Cf = mesh.Cf();
00214 
00215     vectorField maxVsf(vsf.internalField());
00216     vectorField minVsf(vsf.internalField());
00217 
00218     forAll(owner, facei)
00219     {
00220         label own = owner[facei];
00221         label nei = neighbour[facei];
00222 
00223         const vector& vsfOwn = vsf[own];
00224         const vector& vsfNei = vsf[nei];
00225 
00226         maxVsf[own] = max(maxVsf[own], vsfNei);
00227         minVsf[own] = min(minVsf[own], vsfNei);
00228 
00229         maxVsf[nei] = max(maxVsf[nei], vsfOwn);
00230         minVsf[nei] = min(minVsf[nei], vsfOwn);
00231     }
00232 
00233 
00234     const volVectorField::GeometricBoundaryField& bsf = vsf.boundaryField();
00235 
00236     forAll(bsf, patchi)
00237     {
00238         const fvPatchVectorField& psf = bsf[patchi];
00239         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00240 
00241         if (psf.coupled())
00242         {
00243             vectorField psfNei = psf.patchNeighbourField();
00244 
00245             forAll(pOwner, pFacei)
00246             {
00247                 label own = pOwner[pFacei];
00248                 const vector& vsfNei = psfNei[pFacei];
00249 
00250                 maxVsf[own] = max(maxVsf[own], vsfNei);
00251                 minVsf[own] = min(minVsf[own], vsfNei);
00252             }
00253         }
00254         else
00255         {
00256             forAll(pOwner, pFacei)
00257             {
00258                 label own = pOwner[pFacei];
00259                 const vector& vsfNei = psf[pFacei];
00260 
00261                 maxVsf[own] = max(maxVsf[own], vsfNei);
00262                 minVsf[own] = min(minVsf[own], vsfNei);
00263             }
00264         }
00265     }
00266 
00267     maxVsf -= vsf;
00268     minVsf -= vsf;
00269 
00270     if (k_ < 1.0)
00271     {
00272         vectorField maxMinVsf = (1.0/k_ - 1.0)*(maxVsf - minVsf);
00273         maxVsf += maxMinVsf;
00274         minVsf -= maxMinVsf;
00275 
00276         //maxVsf *= 1.0/k_;
00277         //minVsf *= 1.0/k_;
00278     }
00279 
00280 
00281     forAll(owner, facei)
00282     {
00283         label own = owner[facei];
00284         label nei = neighbour[facei];
00285 
00286         // owner side
00287         limitFace
00288         (
00289             g[own],
00290             maxVsf[own],
00291             minVsf[own],
00292             Cf[facei] - C[own]
00293         );
00294 
00295         // neighbour side
00296         limitFace
00297         (
00298             g[nei],
00299             maxVsf[nei],
00300             minVsf[nei],
00301             Cf[facei] - C[nei]
00302         );
00303     }
00304 
00305 
00306     forAll(bsf, patchi)
00307     {
00308         const unallocLabelList& pOwner = mesh.boundary()[patchi].faceCells();
00309         const vectorField& pCf = Cf.boundaryField()[patchi];
00310 
00311         forAll(pOwner, pFacei)
00312         {
00313             label own = pOwner[pFacei];
00314 
00315             limitFace
00316             (
00317                 g[own],
00318                 maxVsf[own],
00319                 minVsf[own],
00320                 pCf[pFacei] - C[own]
00321             );
00322         }
00323     }
00324 
00325     g.correctBoundaryConditions();
00326     gaussGrad<vector>::correctBoundaryConditions(vsf, g);
00327 
00328     return tGrad;
00329 }
00330 
00331 
00332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00333 
00334 } // End namespace fv
00335 
00336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00337 
00338 } // End namespace Foam
00339 
00340 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd