OpenFOAM logo
Open Source CFD Toolkit

linearUpwindV.H

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-2005 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 Class
00026     linearUpwindV
00027 
00028 Description
00029     linearUpwindV interpolation scheme class derived from upwind and returns
00030     upwind weighting factors but also applies an explicit correction.
00031 
00032 SourceFiles
00033     linearUpwindV.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef linearUpwindV_H
00038 #define linearUpwindV_H
00039 
00040 #include "upwind.H"
00041 #include "gaussGrad.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 /*---------------------------------------------------------------------------*\
00049                            Class linearUpwindV Declaration
00050 \*---------------------------------------------------------------------------*/
00051 
00052 template<class Type>
00053 class linearUpwindV
00054 :
00055     public upwind<Type>
00056 {
00057     // Private Data
00058 
00059         tmp<fv::gradScheme<Type> > gradScheme_;
00060 
00061 
00062     // Private Member Functions
00063 
00064         //- Disallow default bitwise copy construct
00065         linearUpwindV(const linearUpwindV&);
00066 
00067         //- Disallow default bitwise assignment
00068         void operator=(const linearUpwindV&);
00069 
00070 
00071 public:
00072 
00073     //- Runtime type information
00074     TypeName("linearUpwindV");
00075 
00076 
00077     // Constructors
00078 
00079         //- Construct from faceFlux
00080         linearUpwindV
00081         (
00082             const fvMesh& mesh,
00083             const surfaceScalarField& faceFlux
00084         )
00085         :
00086             upwind<Type>(mesh, faceFlux),
00087             gradScheme_
00088             (
00089                 new fv::gaussGrad<Type>(mesh)
00090             )
00091         {}
00092 
00093         //- Construct from Istream. 
00094         //  The name of the flux field is read from the Istream and looked-up
00095         //  from the mesh objectRegistry
00096         linearUpwindV
00097         (
00098             const fvMesh& mesh,
00099             Istream& schemeData
00100         )
00101         :
00102             upwind<Type>(mesh, schemeData),
00103             gradScheme_
00104             (
00105                 fv::gradScheme<Type>::New
00106                 (
00107                     mesh,
00108                     schemeData
00109                 )
00110             )
00111         {}
00112 
00113         //- Construct from faceFlux and Istream
00114         linearUpwindV
00115         (
00116             const fvMesh& mesh,
00117             const surfaceScalarField& faceFlux,
00118             Istream& schemeData
00119         )
00120         :
00121             upwind<Type>(mesh, faceFlux, schemeData),
00122             gradScheme_
00123             (
00124                 fv::gradScheme<Type>::New
00125                 (
00126                     mesh,
00127                     schemeData
00128                 )
00129             )
00130         {}
00131 
00132 
00133     // Member Functions
00134 
00135         //- Return true if this scheme uses an explicit correction
00136         virtual bool corrected() const
00137         {
00138             return true;
00139         }
00140 
00141         //- Return the explicit correction to the face-interpolate
00142         virtual tmp<GeometricField<Type, fvPatchField, surfaceMesh> >
00143         correction
00144         (
00145             const GeometricField<Type, fvPatchField, volMesh>& vf
00146         ) const
00147         {
00148             const fvMesh& mesh = this->mesh();
00149 
00150             tmp<GeometricField<Type, fvPatchField, surfaceMesh> > tsfCorr
00151             (
00152                 new GeometricField<Type, fvPatchField, surfaceMesh>
00153                 (
00154                     IOobject
00155                     (
00156                         vf.name(),
00157                         mesh.time().timeName(),
00158                         mesh
00159                     ),
00160                     mesh,
00161                     dimensioned<Type>
00162                     (
00163                         vf.name(),
00164                         vf.dimensions(),
00165                         pTraits<Type>::zero
00166                     )
00167                 )
00168             );
00169 
00170             GeometricField<Type, fvPatchField, surfaceMesh>& sfCorr = tsfCorr();
00171 
00172             const surfaceScalarField& faceFlux = this->faceFlux_;
00173             const  surfaceScalarField& w = mesh.weights();
00174 
00175             const labelList& own = mesh.owner();
00176             const labelList& nei = mesh.neighbour();
00177 
00178             const vectorField& C = mesh.C();
00179             const vectorField& Cf = mesh.Cf();
00180 
00181             GeometricField
00182             <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
00183                 gradVf = gradScheme_().grad(vf);
00184 
00185             forAll(faceFlux, facei)
00186             {
00187                 vector maxCorr;
00188 
00189                 if (faceFlux[facei] > 0.0)
00190                 {
00191                     maxCorr =
00192                         (1.0 - w[facei])*(vf[nei[facei]] - vf[own[facei]]);
00193 
00194                     sfCorr[facei] = 
00195                         (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
00196                 }
00197                 else
00198                 {
00199                     maxCorr =
00200                         w[facei]*(vf[own[facei]] - vf[nei[facei]]);
00201 
00202                     sfCorr[facei] = 
00203                         (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
00204                 }
00205 
00206                 scalar sfCorrs = magSqr(sfCorr[facei]);
00207                 scalar maxCorrs = sfCorr[facei] & maxCorr;
00208 
00209                 if (sfCorrs > 0)
00210                 {
00211                     if (maxCorrs < 0)
00212                     {
00213                         sfCorr[facei] = vector::zero;
00214                     }
00215                     else if (sfCorrs > maxCorrs)
00216                     {
00217                         sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
00218                     }
00219                 }
00220                 else if (sfCorrs < 0)
00221                 {
00222                     if (maxCorrs > 0)
00223                     {
00224                         sfCorr[facei] = vector::zero;
00225                     }
00226                     else if (sfCorrs < maxCorrs)
00227                     {
00228                         sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
00229                     }
00230                 }
00231             }
00232 
00233             return tsfCorr;
00234         }
00235 };
00236 
00237 
00238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00239 
00240 } // End namespace Foam
00241 
00242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00243 
00244 #endif
00245 
00246 // ************************************************************************* //
For further information go to www.openfoam.org