FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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