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

UpwindFitScheme.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-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 Class
00026     Foam::UpwindFitScheme
00027 
00028 Description
00029     Upwind biased fit surface interpolation scheme that applies an explicit
00030     correction to linear.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #ifndef UpwindFitScheme_H
00035 #define UpwindFitScheme_H
00036 
00037 #include "UpwindFitData.H"
00038 #include "linear.H"
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace Foam
00043 {
00044 
00045 /*---------------------------------------------------------------------------*\
00046                            Class UpwindFitScheme Declaration
00047 \*---------------------------------------------------------------------------*/
00048 
00049 template<class Type, class Polynomial, class Stencil>
00050 class UpwindFitScheme
00051 :
00052     public linear<Type>
00053 {
00054     // Private Data
00055 
00056         //- Reference to the surface flux used to choose upwind direction
00057         const surfaceScalarField& faceFlux_;
00058 
00059         //- Factor the fit is allowed to deviate from linear.
00060         //  This limits the amount of high-order correction and increases
00061         //  stability on bad meshes
00062         const scalar linearLimitFactor_;
00063 
00064         //- Weights for central stencil
00065         const scalar centralWeight_;
00066 
00067 
00068     // Private Member Functions
00069 
00070         //- Disallow default bitwise copy construct
00071         UpwindFitScheme(const UpwindFitScheme&);
00072 
00073         //- Disallow default bitwise assignment
00074         void operator=(const UpwindFitScheme&);
00075 
00076 
00077 public:
00078 
00079     //- Runtime type information
00080     TypeName("UpwindFitScheme");
00081 
00082 
00083     // Constructors
00084 
00085         //- Construct from mesh and Istream
00086         //  The name of the flux field is read from the Istream and looked-up
00087         //  from the mesh objectRegistry
00088         UpwindFitScheme(const fvMesh& mesh, Istream& is)
00089         :
00090             linear<Type>(mesh),
00091             faceFlux_(mesh.lookupObject<surfaceScalarField>(word(is))),
00092             linearLimitFactor_(readScalar(is)),
00093             centralWeight_(1000)
00094         {}
00095 
00096 
00097         //- Construct from mesh, faceFlux and Istream
00098         UpwindFitScheme
00099         (
00100             const fvMesh& mesh,
00101             const surfaceScalarField& faceFlux,
00102             Istream& is
00103         )
00104         :
00105             linear<Type>(mesh),
00106             faceFlux_(faceFlux),
00107             linearLimitFactor_(readScalar(is)),
00108             centralWeight_(1000)
00109         {}
00110 
00111 
00112     // Member Functions
00113 
00114         //- Return true if this scheme uses an explicit correction
00115         virtual bool corrected() const
00116         {
00117             return true;
00118         }
00119 
00120         //- Return the explicit correction to the face-interpolate
00121         virtual tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00122         correction
00123         (
00124             const GeometricField<Type, fvPatchField, volMesh>& vf
00125         ) const
00126         {
00127             const fvMesh& mesh = this->mesh();
00128 
00129             const extendedUpwindCellToFaceStencil& stencil = Stencil::New
00130             (
00131                 mesh,
00132                 false,          //pureUpwind
00133                 scalar(0.5)
00134             );
00135 
00136             const UpwindFitData<Polynomial>& ufd =
00137             UpwindFitData<Polynomial>::New
00138             (
00139                 mesh,
00140                 stencil,
00141                 true,           //calculate as offset to linear
00142                 linearLimitFactor_,
00143                 centralWeight_
00144             );
00145 
00146             const List<scalarList>& fo = ufd.owncoeffs();
00147             const List<scalarList>& fn = ufd.neicoeffs();
00148 
00149             return stencil.weightedSum(faceFlux_, vf, fo, fn);
00150         }
00151 };
00152 
00153 
00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00155 
00156 } // End namespace Foam
00157 
00158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00159 
00160 // Add the patch constructor functions to the hash tables
00161 
00162 #define makeUpwindFitSurfaceInterpolationTypeScheme(SS, POLYNOMIAL, STENCIL, TYPE) \
00163                                                                               \
00164 typedef UpwindFitScheme<TYPE, POLYNOMIAL, STENCIL>                            \
00165     UpwindFitScheme##TYPE##POLYNOMIAL##STENCIL##_;                            \
00166 defineTemplateTypeNameAndDebugWithName                                        \
00167     (UpwindFitScheme##TYPE##POLYNOMIAL##STENCIL##_, #SS, 0);                  \
00168                                                                               \
00169 surfaceInterpolationScheme<TYPE>::addMeshConstructorToTable                   \
00170 <UpwindFitScheme<TYPE, POLYNOMIAL, STENCIL> >                                 \
00171     add##SS##STENCIL##TYPE##MeshConstructorToTable_;                          \
00172                                                                               \
00173 surfaceInterpolationScheme<TYPE>::addMeshFluxConstructorToTable               \
00174 <UpwindFitScheme<TYPE, POLYNOMIAL, STENCIL> >                                 \
00175     add##SS##STENCIL##TYPE##MeshFluxConstructorToTable_;
00176 
00177 #define makeUpwindFitSurfaceInterpolationScheme(SS, POLYNOMIAL, STENCIL)      \
00178                                                                               \
00179 makeUpwindFitSurfaceInterpolationTypeScheme(SS,POLYNOMIAL,STENCIL,scalar)     \
00180 makeUpwindFitSurfaceInterpolationTypeScheme(SS,POLYNOMIAL,STENCIL,vector)     \
00181 makeUpwindFitSurfaceInterpolationTypeScheme(SS,POLYNOMIAL,STENCIL,sphericalTensor) \
00182 makeUpwindFitSurfaceInterpolationTypeScheme(SS,POLYNOMIAL,STENCIL,symmTensor) \
00183 makeUpwindFitSurfaceInterpolationTypeScheme(SS,POLYNOMIAL,STENCIL,tensor)
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 #endif
00189 
00190 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd