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

linearUpwind.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 "linearUpwind.H"
00028 #include "fvMesh.H"
00029 #include "zeroGradientFvPatchField.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
00035 Foam::linearUpwind<Type>::correction
00036 (
00037     const GeometricField<Type, fvPatchField, volMesh>& vf
00038 ) const
00039 {
00040     const fvMesh& mesh = this->mesh();
00041 
00042     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
00043     (
00044         new GeometricField<Type, fvsPatchField, surfaceMesh>
00045         (
00046             IOobject
00047             (
00048                 "linearUpwindCorrection(" + vf.name() + ')',
00049                 mesh.time().timeName(),
00050                 mesh,
00051                 IOobject::NO_READ,
00052                 IOobject::NO_WRITE,
00053                 false
00054             ),
00055             mesh,
00056             dimensioned<Type>(vf.name(), vf.dimensions(), pTraits<Type>::zero)
00057         )
00058     );
00059 
00060     GeometricField<Type, fvsPatchField, surfaceMesh>& sfCorr = tsfCorr();
00061 
00062     const surfaceScalarField& faceFlux = this->faceFlux_;
00063 
00064     const labelList& owner = mesh.owner();
00065     const labelList& neighbour = mesh.neighbour();
00066 
00067     const volVectorField& C = mesh.C();
00068     const surfaceVectorField& Cf = mesh.Cf();
00069 
00070     GeometricField
00071         <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
00072         gradVf = gradScheme_().grad(vf);
00073 
00074     forAll(faceFlux, facei)
00075     {
00076         if (faceFlux[facei] > 0)
00077         {
00078             label own = owner[facei];
00079             sfCorr[facei] = (Cf[facei] - C[own]) & gradVf[own];
00080         }
00081         else
00082         {
00083             label nei = neighbour[facei];
00084             sfCorr[facei] = (Cf[facei] - C[nei]) & gradVf[nei];
00085         }
00086     }
00087 
00088 
00089     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
00090         GeometricBoundaryField& bSfCorr = sfCorr.boundaryField();
00091 
00092     forAll(bSfCorr, patchi)
00093     {
00094         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
00095 
00096         if (pSfCorr.coupled())
00097         {
00098             const unallocLabelList& pOwner = 
00099                 mesh.boundary()[patchi].faceCells();
00100 
00101             const vectorField& pCf = Cf.boundaryField()[patchi];
00102 
00103             const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
00104 
00105             Field<typename outerProduct<vector, Type>::type> pGradVfNei =
00106                 gradVf.boundaryField()[patchi].patchNeighbourField();
00107 
00108             // Build the d-vectors
00109             vectorField pd = 
00110                 mesh.Sf().boundaryField()[patchi]
00111                /(
00112                    mesh.magSf().boundaryField()[patchi]
00113                   *mesh.deltaCoeffs().boundaryField()[patchi]
00114                 );
00115 
00116             if (!mesh.orthogonal())
00117             {
00118                 pd -= mesh.correctionVectors().boundaryField()[patchi]
00119                     /mesh.deltaCoeffs().boundaryField()[patchi];
00120             }
00121 
00122             forAll(pOwner, facei)
00123             {
00124                 label own = pOwner[facei];
00125 
00126                 if (pFaceFlux[facei] > 0)
00127                 {
00128                     pSfCorr[facei] = (pCf[facei] - C[own]) & gradVf[own];
00129                 }
00130                 else
00131                 {
00132                     pSfCorr[facei] = 
00133                         (pCf[facei] - pd[facei] - C[own]) & pGradVfNei[facei];
00134                 }
00135             }
00136         }
00137     }
00138 
00139     return tsfCorr;
00140 }
00141 
00142 
00143 namespace Foam
00144 {
00145     //makelimitedSurfaceInterpolationScheme(linearUpwind)
00146     makelimitedSurfaceInterpolationTypeScheme(linearUpwind, scalar)
00147     makelimitedSurfaceInterpolationTypeScheme(linearUpwind, vector)
00148 }
00149 
00150 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd