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

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