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

CrankNicholsonDdtScheme.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::fv::CrankNicholsonDdtScheme
00026 
00027 Description
00028     Second-oder CrankNicholson implicit ddt using the current and
00029     previous time-step fields as well as the previous time-step ddt.
00030 
00031 SourceFiles
00032     CrankNicholsonDdtScheme.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef CrankNicholsonDdtScheme_H
00037 #define CrankNicholsonDdtScheme_H
00038 
00039 #include <finiteVolume/ddtScheme.H>
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace Foam
00044 {
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace fv
00049 {
00050 
00051 /*---------------------------------------------------------------------------*\
00052                        Class CrankNicholsonDdtScheme Declaration
00053 \*---------------------------------------------------------------------------*/
00054 
00055 template<class Type>
00056 class CrankNicholsonDdtScheme
00057 :
00058     public fv::ddtScheme<Type>
00059 {
00060     // Private Data
00061 
00062         //- Class to store the ddt0 fields on the objectRegistry for use in the
00063         //  next time-step.  The start-time index of the CN scheme is also
00064         //  stored to help handle the transition from Euler to CN
00065         template<class GeoField>
00066         class DDt0Field
00067         :
00068             public GeoField
00069         {
00070             label startTimeIndex_;
00071 
00072         public:
00073 
00074             //- Constructor from file for restart.
00075             DDt0Field
00076             (
00077                 const IOobject& io,
00078                 const fvMesh& mesh
00079             );
00080 
00081             //- Constructor from components, initisalised to zero with given
00082             //  dimensions.
00083             DDt0Field
00084             (
00085                 const IOobject& io,
00086                 const fvMesh& mesh,
00087                 const dimensioned<typename GeoField::value_type>& dimType
00088             );
00089 
00090             //- Return the start-time index
00091             label startTimeIndex() const;
00092             
00093             //- Cast to the underlying GeoField
00094             GeoField& operator()();
00095 
00096             //- Assignment to a GeoField
00097             void operator=(const GeoField& gf);
00098         };
00099 
00100 
00101         //- Off-centering coefficient, 1 -> CN, less than one blends with EI
00102         scalar ocCoeff_;
00103 
00104 
00105     // Private Member Functions
00106 
00107         //- Disallow default bitwise copy construct
00108         CrankNicholsonDdtScheme(const CrankNicholsonDdtScheme&);
00109 
00110         //- Disallow default bitwise assignment
00111         void operator=(const CrankNicholsonDdtScheme&);
00112 
00113         template<class GeoField>
00114         DDt0Field<GeoField>& ddt0_
00115         (
00116             const word& name,
00117             const dimensionSet& dims
00118         );
00119 
00120         //- Check if the ddt0 needs to be evaluated for this time-step
00121         template<class GeoField>
00122         bool evaluate(const DDt0Field<GeoField>& ddt0) const;
00123 
00124         //- Return the coefficient for Euler scheme for the first time-step
00125         //  for and CN thereafter
00126         template<class GeoField>
00127         scalar coef_(const DDt0Field<GeoField>&) const;
00128 
00129         //- Return the old time-step coefficient for Euler scheme for the
00130         //  second time-step and for CN thereafter
00131         template<class GeoField>
00132         scalar coef0_(const DDt0Field<GeoField>&) const;
00133 
00134         //- Return the reciprocal time-step coefficient for Euler for the
00135         //  first time-step and CN thereafter
00136         template<class GeoField>
00137         dimensionedScalar rDtCoef_(const DDt0Field<GeoField>&) const;
00138 
00139         //- Return the reciprocal old time-step coefficient for Euler for the
00140         //  second time-step and CN thereafter
00141         template<class GeoField>
00142         dimensionedScalar rDtCoef0_(const DDt0Field<GeoField>&) const;
00143 
00144         //- Return ddt0 multiplied by the off-centreing coefficient
00145         template<class GeoField>
00146         tmp<GeoField> offCentre_(const GeoField& ddt0) const;
00147 
00148 
00149 public:
00150 
00151     //- Runtime type information
00152     TypeName("CrankNicholson");
00153 
00154 
00155     // Constructors
00156 
00157         //- Construct from mesh
00158         CrankNicholsonDdtScheme(const fvMesh& mesh)
00159         :
00160             ddtScheme<Type>(mesh),
00161             ocCoeff_(1.0)
00162         {}
00163 
00164         //- Construct from mesh and Istream
00165         CrankNicholsonDdtScheme(const fvMesh& mesh, Istream& is)
00166         :
00167             ddtScheme<Type>(mesh, is),
00168             ocCoeff_(readScalar(is))
00169         {
00170             if (ocCoeff_ < 0 || ocCoeff_ > 1)
00171             {
00172                 FatalIOErrorIn
00173                 (
00174                     "CrankNicholsonDdtScheme(const fvMesh& mesh, Istream& is)",
00175                     is
00176                 )   << "coefficient = " << ocCoeff_
00177                     << " should be >= 0 and <= 1"
00178                     << exit(FatalIOError);
00179             }
00180         }
00181 
00182 
00183     // Member Functions
00184 
00185         //- Return mesh reference
00186         const fvMesh& mesh() const
00187         {
00188             return fv::ddtScheme<Type>::mesh();
00189         }
00190 
00191         tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDdt
00192         (
00193             const dimensioned<Type>&
00194         );
00195 
00196         tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDdt
00197         (
00198             const GeometricField<Type, fvPatchField, volMesh>&
00199         );
00200 
00201         tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDdt
00202         (
00203             const dimensionedScalar&,
00204             const GeometricField<Type, fvPatchField, volMesh>&
00205         );
00206 
00207         tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDdt
00208         (
00209             const volScalarField&,
00210             const GeometricField<Type, fvPatchField, volMesh>&
00211         );
00212 
00213         tmp<fvMatrix<Type> > fvmDdt
00214         (
00215             GeometricField<Type, fvPatchField, volMesh>&
00216         );
00217 
00218         tmp<fvMatrix<Type> > fvmDdt
00219         (
00220             const dimensionedScalar&,
00221             GeometricField<Type, fvPatchField, volMesh>&
00222         );
00223 
00224         tmp<fvMatrix<Type> > fvmDdt
00225         (
00226             const volScalarField&,
00227             GeometricField<Type, fvPatchField, volMesh>&
00228         );
00229 
00230         typedef typename ddtScheme<Type>::fluxFieldType fluxFieldType;
00231 
00232         tmp<fluxFieldType> fvcDdtPhiCorr
00233         (
00234             const volScalarField& rA,
00235             const GeometricField<Type, fvPatchField, volMesh>& U,
00236             const fluxFieldType& phi
00237         );
00238 
00239         tmp<fluxFieldType> fvcDdtPhiCorr
00240         (
00241             const volScalarField& rA,
00242             const volScalarField& rho,
00243             const GeometricField<Type, fvPatchField, volMesh>& U,
00244             const fluxFieldType& phi
00245         );
00246 
00247 
00248         tmp<surfaceScalarField> meshPhi
00249         (
00250             const GeometricField<Type, fvPatchField, volMesh>&
00251         );
00252 };
00253 
00254 
00255 template<>
00256 tmp<surfaceScalarField> CrankNicholsonDdtScheme<scalar>::fvcDdtPhiCorr
00257 (
00258     const volScalarField& rA,
00259     const volScalarField& U,
00260     const surfaceScalarField& phi
00261 );
00262 
00263 
00264 template<>
00265 tmp<surfaceScalarField> CrankNicholsonDdtScheme<scalar>::fvcDdtPhiCorr
00266 (
00267     const volScalarField& rA,
00268     const volScalarField& rho,
00269     const volScalarField& U,
00270     const surfaceScalarField& phi
00271 );
00272 
00273 
00274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00275 
00276 } // End namespace fv
00277 
00278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00279 
00280 } // End namespace Foam
00281 
00282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00283 
00284 #ifdef NoRepository
00285 #   include <finiteVolume/CrankNicholsonDdtScheme.C>
00286 #endif
00287 
00288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00289 
00290 #endif
00291 
00292 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines