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

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