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

CrankNicholsonDdtScheme.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "CrankNicholsonDdtScheme.H"
00028 #include "surfaceInterpolate.H"
00029 #include "fvcDiv.H"
00030 #include "fvMatrices.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 namespace fv
00040 {
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 template<class Type>
00045 template<class GeoField>
00046 CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>::DDt0Field
00047 (
00048     const IOobject& io,
00049     const fvMesh& mesh
00050 )
00051 :
00052     GeoField(io, mesh),
00053     startTimeIndex_(-2) // This field is for a restart and thus correct so set
00054                         // the start time-index to corespond to a previous run
00055 {
00056     // Set the time-index to the beginning of the run to ensure the field
00057     // is updated during the first time-step
00058     this->timeIndex() = mesh.time().startTimeIndex();
00059 }
00060 
00061 
00062 template<class Type>
00063 template<class GeoField>
00064 CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>::DDt0Field
00065 (
00066     const IOobject& io,
00067     const fvMesh& mesh,
00068     const dimensioned<typename GeoField::value_type>& dimType
00069 )
00070 :
00071     GeoField(io, mesh, dimType),
00072     startTimeIndex_(mesh.time().timeIndex())
00073 {}
00074 
00075 
00076 template<class Type>
00077 template<class GeoField>
00078 label CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>::
00079 startTimeIndex() const
00080 {
00081     return startTimeIndex_;
00082 }
00083 
00084 
00085 template<class Type>
00086 template<class GeoField>
00087 GeoField& CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>::
00088 operator()()
00089 {
00090     return *this;
00091 }
00092 
00093 
00094 template<class Type>
00095 template<class GeoField>
00096 void CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>::
00097 operator=(const GeoField& gf)
00098 {
00099     GeoField::operator=(gf);
00100 }
00101 
00102 
00103 template<class Type>
00104 template<class GeoField>
00105 CrankNicholsonDdtScheme<Type>::DDt0Field<GeoField>&
00106 CrankNicholsonDdtScheme<Type>::ddt0_
00107 (
00108     const word& name,
00109     const dimensionSet& dims
00110 )
00111 {
00112     if (!mesh().objectRegistry::foundObject<GeoField>(name))
00113     {
00114         const Time& runTime = mesh().time();
00115         word startTimeName = runTime.timeName(runTime.startTime().value());
00116 
00117         if
00118         (
00119             (
00120                 runTime.timeIndex() == runTime.startTimeIndex()
00121              || runTime.timeIndex() == runTime.startTimeIndex() + 1
00122             )
00123          && IOobject
00124             (
00125                 name,
00126                 startTimeName,
00127                 mesh()
00128             ).headerOk()
00129         )
00130         {
00131             regIOobject::store
00132             (
00133                 new DDt0Field<GeoField>
00134                 (
00135                     IOobject
00136                     (
00137                         name,
00138                         startTimeName,
00139                         mesh(),
00140                         IOobject::MUST_READ,
00141                         IOobject::AUTO_WRITE
00142                     ),
00143                     mesh()
00144                 )
00145             );
00146         }
00147         else
00148         {
00149             regIOobject::store
00150             (
00151                 new DDt0Field<GeoField>
00152                 (
00153                     IOobject
00154                     (
00155                         name,
00156                         mesh().time().timeName(),
00157                         mesh(),
00158                         IOobject::NO_READ,
00159                         IOobject::AUTO_WRITE
00160                     ),
00161                     mesh(),
00162                     dimensioned<typename GeoField::value_type>
00163                     (
00164                         "0",
00165                         dims/dimTime,
00166                         pTraits<typename GeoField::value_type>::zero
00167                     )
00168                 )
00169             );
00170         }
00171     }
00172 
00173     DDt0Field<GeoField>& ddt0 = static_cast<DDt0Field<GeoField>&>
00174     (
00175         const_cast<GeoField&>
00176         (
00177             mesh().objectRegistry::lookupObject<GeoField>(name)
00178         )
00179     );
00180 
00181     return ddt0;
00182 }
00183 
00184 
00185 template<class Type>
00186 template<class GeoField>
00187 bool CrankNicholsonDdtScheme<Type>::evaluate
00188 (
00189     const DDt0Field<GeoField>& ddt0
00190 ) const
00191 {
00192     return ddt0.timeIndex() != mesh().time().timeIndex();
00193 }
00194 
00195 template<class Type>
00196 template<class GeoField>
00197 scalar CrankNicholsonDdtScheme<Type>::coef_
00198 (
00199     const DDt0Field<GeoField>& ddt0
00200 ) const
00201 {
00202     if (mesh().time().timeIndex() - ddt0.startTimeIndex() > 0)
00203     {
00204         return 1.0 + ocCoeff_;
00205     }
00206     else
00207     {
00208         return 1.0;
00209     }
00210 }
00211 
00212 
00213 template<class Type>
00214 template<class GeoField>
00215 scalar CrankNicholsonDdtScheme<Type>::coef0_
00216 (
00217     const DDt0Field<GeoField>& ddt0
00218 ) const
00219 {
00220     if (mesh().time().timeIndex() - ddt0.startTimeIndex() > 1)
00221     {
00222         return 1.0 + ocCoeff_;
00223     }
00224     else
00225     {
00226         return 1.0;
00227     }
00228 }
00229 
00230 
00231 template<class Type>
00232 template<class GeoField>
00233 dimensionedScalar CrankNicholsonDdtScheme<Type>::rDtCoef_
00234 (
00235     const DDt0Field<GeoField>& ddt0
00236 ) const
00237 {
00238     return coef_(ddt0)/mesh().time().deltaT();
00239 }
00240 
00241 
00242 template<class Type>
00243 template<class GeoField>
00244 dimensionedScalar CrankNicholsonDdtScheme<Type>::rDtCoef0_
00245 (
00246     const DDt0Field<GeoField>& ddt0
00247 ) const
00248 {
00249     return coef0_(ddt0)/mesh().time().deltaT0();
00250 }
00251 
00252 
00253 template<class Type>
00254 template<class GeoField>
00255 tmp<GeoField> CrankNicholsonDdtScheme<Type>::offCentre_
00256 (
00257     const GeoField& ddt0
00258 ) const
00259 {
00260     if (ocCoeff_ < 1.0)
00261     {
00262         return ocCoeff_*ddt0;
00263     }
00264     else
00265     {
00266         return ddt0;
00267     }
00268 }
00269 
00270 
00271 template<class Type>
00272 const FieldField<fvPatchField, Type>& ff
00273 (
00274     const FieldField<fvPatchField, Type>& bf
00275 )
00276 {
00277     return bf;
00278 }
00279 
00280 
00281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00282 
00283 template<class Type>
00284 tmp<GeometricField<Type, fvPatchField, volMesh> >
00285 CrankNicholsonDdtScheme<Type>::fvcDdt
00286 (
00287     const dimensioned<Type>& dt
00288 )
00289 {
00290     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00291         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00292         (
00293             "ddt0(" + dt.name() + ')',
00294             dt.dimensions()
00295         );
00296 
00297     IOobject ddtIOobject
00298     (
00299         "ddt(" + dt.name() + ')',
00300         mesh().time().timeName(),
00301         mesh()
00302     );
00303 
00304     tmp<GeometricField<Type, fvPatchField, volMesh> > tdtdt
00305     (
00306         new GeometricField<Type, fvPatchField, volMesh>
00307         (
00308             ddtIOobject,
00309             mesh(),
00310             dimensioned<Type>
00311             (
00312                 "0",
00313                 dt.dimensions()/dimTime,
00314                 pTraits<Type>::zero
00315             )
00316         )
00317     );
00318 
00319     dimensionedScalar rDtCoef = rDtCoef_(ddt0);
00320 
00321     if (mesh().moving())
00322     {
00323         if (evaluate(ddt0))
00324         {
00325             dimensionedScalar rDtCoef0 = rDtCoef0_(ddt0);
00326 
00327             ddt0.dimensionedInternalField() =
00328             (
00329                 (rDtCoef0*dt)*(mesh().V0() - mesh().V00())
00330               - mesh().V00()*offCentre_(ddt0.dimensionedInternalField())
00331             )/mesh().V0();
00332         }
00333 
00334         tdtdt().dimensionedInternalField() =
00335         (
00336             (rDtCoef*dt)*(mesh().V() - mesh().V0())
00337           - mesh().V0()*offCentre_(ddt0.dimensionedInternalField())
00338         )/mesh().V();
00339     }
00340 
00341     return tdtdt;
00342 }
00343 
00344 
00345 template<class Type>
00346 tmp<GeometricField<Type, fvPatchField, volMesh> >
00347 CrankNicholsonDdtScheme<Type>::fvcDdt
00348 (
00349     const GeometricField<Type, fvPatchField, volMesh>& vf
00350 )
00351 {
00352     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00353         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00354         (
00355             "ddt0(" + vf.name() + ')',
00356             vf.dimensions()
00357         );
00358 
00359     IOobject ddtIOobject
00360     (
00361         "ddt(" + vf.name() + ')',
00362         mesh().time().timeName(),
00363         mesh()
00364     );
00365 
00366     dimensionedScalar rDtCoef = rDtCoef_(ddt0);
00367 
00368     if (mesh().moving())
00369     {
00370         if (evaluate(ddt0))
00371         {
00372             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00373 
00374             ddt0.internalField() =
00375             (
00376                 rDtCoef0*
00377                 (
00378                     mesh().V0()*vf.oldTime().internalField()
00379                   - mesh().V00()*vf.oldTime().oldTime().internalField()
00380                 ) - mesh().V00()*offCentre_(ddt0.internalField())
00381             )/mesh().V0();
00382 
00383             ddt0.boundaryField() =
00384             (
00385                 rDtCoef0*
00386                 (
00387                     vf.oldTime().boundaryField()
00388                   - vf.oldTime().oldTime().boundaryField()
00389                 ) - offCentre_(ff(ddt0.boundaryField()))
00390             );
00391         }
00392 
00393         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00394         (
00395             new GeometricField<Type, fvPatchField, volMesh>
00396             (
00397                 ddtIOobject,
00398                 mesh(),
00399                 rDtCoef.dimensions()*vf.dimensions(),
00400                 (
00401                     rDtCoef.value()*
00402                     (
00403                         mesh().V()*vf.internalField()
00404                       - mesh().V0()*vf.oldTime().internalField()
00405                     ) - mesh().V0()*offCentre_(ddt0.internalField())
00406                 )/mesh().V(),
00407                 rDtCoef.value()*
00408                 (
00409                     vf.boundaryField() - vf.oldTime().boundaryField()
00410                 ) - offCentre_(ff(ddt0.boundaryField()))
00411             )
00412         );
00413     }
00414     else
00415     {
00416         if (evaluate(ddt0))
00417         {
00418             ddt0 = rDtCoef0_(ddt0)*(vf.oldTime() - vf.oldTime().oldTime())
00419                  - offCentre_(ddt0());
00420         }
00421 
00422         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00423         (
00424             new GeometricField<Type, fvPatchField, volMesh>
00425             (
00426                 ddtIOobject,
00427                 rDtCoef*(vf - vf.oldTime()) - offCentre_(ddt0())
00428             )
00429         );
00430     }
00431 }
00432 
00433 
00434 template<class Type>
00435 tmp<GeometricField<Type, fvPatchField, volMesh> >
00436 CrankNicholsonDdtScheme<Type>::fvcDdt
00437 (
00438     const dimensionedScalar& rho,
00439     const GeometricField<Type, fvPatchField, volMesh>& vf
00440 )
00441 {
00442     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00443         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00444         (
00445             "ddt0(" + rho.name() + ',' + vf.name() + ')',
00446             rho.dimensions()*vf.dimensions()
00447         );
00448 
00449     IOobject ddtIOobject
00450     (
00451         "ddt(" + rho.name() + ',' + vf.name() + ')',
00452         mesh().time().timeName(),
00453         mesh()
00454     );
00455 
00456     dimensionedScalar rDtCoef = rDtCoef_(ddt0);
00457 
00458     if (mesh().moving())
00459     {
00460         if (evaluate(ddt0))
00461         {
00462             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00463 
00464             ddt0.internalField() =
00465             (
00466                 rDtCoef0*rho.value()*
00467                 (
00468                     mesh().V0()*vf.oldTime().internalField()
00469                   - mesh().V00()*vf.oldTime().oldTime().internalField()
00470                 ) - mesh().V00()*offCentre_(ddt0.internalField())
00471             )/mesh().V0();
00472 
00473             ddt0.boundaryField() =
00474             (
00475                 rDtCoef0*rho.value()*
00476                 (
00477                     vf.oldTime().boundaryField()
00478                   - vf.oldTime().oldTime().boundaryField()
00479                 ) - offCentre_(ff(ddt0.boundaryField()))
00480             );
00481         }
00482 
00483         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00484         (
00485             new GeometricField<Type, fvPatchField, volMesh>
00486             (
00487                 ddtIOobject,
00488                 mesh(),
00489                 rDtCoef.dimensions()*rho.dimensions()*vf.dimensions(),
00490                 (
00491                     rDtCoef.value()*rho.value()*
00492                     (
00493                         mesh().V()*vf.internalField()
00494                       - mesh().V0()*vf.oldTime().internalField()
00495                     ) - mesh().V0()*offCentre_(ddt0.internalField())
00496                 )/mesh().V(),
00497                 rDtCoef.value()*rho.value()*
00498                 (
00499                     vf.boundaryField() - vf.oldTime().boundaryField()
00500                 ) - offCentre_(ff(ddt0.boundaryField()))
00501             )
00502         );
00503     }
00504     else
00505     {
00506         if (evaluate(ddt0))
00507         {
00508             ddt0 = rDtCoef0_(ddt0)*rho*(vf.oldTime() - vf.oldTime().oldTime())
00509                  - offCentre_(ddt0());
00510         }
00511 
00512         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00513         (
00514             new GeometricField<Type, fvPatchField, volMesh>
00515             (
00516                 ddtIOobject,
00517                 rDtCoef*rho*(vf - vf.oldTime()) - offCentre_(ddt0())
00518             )
00519         );
00520     }
00521 }
00522 
00523 
00524 template<class Type>
00525 tmp<GeometricField<Type, fvPatchField, volMesh> >
00526 CrankNicholsonDdtScheme<Type>::fvcDdt
00527 (
00528     const volScalarField& rho,
00529     const GeometricField<Type, fvPatchField, volMesh>& vf
00530 )
00531 {
00532     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00533         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00534         (
00535             "ddt0(" + rho.name() + ',' + vf.name() + ')',
00536             rho.dimensions()*vf.dimensions()
00537         );
00538 
00539     IOobject ddtIOobject
00540     (
00541         "ddt(" + rho.name() + ',' + vf.name() + ')',
00542         mesh().time().timeName(),
00543         mesh()
00544     );
00545 
00546     dimensionedScalar rDtCoef = rDtCoef_(ddt0);
00547 
00548     if (mesh().moving())
00549     {
00550         if (evaluate(ddt0))
00551         {
00552             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00553 
00554             ddt0.internalField() =
00555             (
00556                 rDtCoef0*
00557                 (
00558                     mesh().V0()*rho.oldTime().internalField()
00559                    *vf.oldTime().internalField()
00560                   - mesh().V00()*rho.oldTime().oldTime().internalField()
00561                    *vf.oldTime().oldTime().internalField()
00562                 ) - mesh().V00()*offCentre_(ddt0.internalField())
00563             )/mesh().V0();
00564 
00565             ddt0.boundaryField() =
00566             (
00567                 rDtCoef0*
00568                 (
00569                     rho.oldTime().boundaryField()
00570                    *vf.oldTime().boundaryField()
00571                   - rho.oldTime().oldTime().boundaryField()
00572                    *vf.oldTime().oldTime().boundaryField()
00573                 ) - offCentre_(ff(ddt0.boundaryField()))
00574             );
00575         }
00576 
00577         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00578         (
00579             new GeometricField<Type, fvPatchField, volMesh>
00580             (
00581                 ddtIOobject,
00582                 mesh(),
00583                 rDtCoef.dimensions()*rho.dimensions()*vf.dimensions(),
00584                 (
00585                     rDtCoef.value()*
00586                     (
00587                         mesh().V()*rho.internalField()*vf.internalField()
00588                       - mesh().V0()*rho.oldTime().internalField()
00589                        *vf.oldTime().internalField()
00590                     ) - mesh().V00()*offCentre_(ddt0.internalField())
00591                 )/mesh().V(),
00592                 rDtCoef.value()*
00593                 (
00594                     rho.boundaryField()*vf.boundaryField()
00595                   - rho.oldTime().boundaryField()*vf.oldTime().boundaryField()
00596                 ) - offCentre_(ff(ddt0.boundaryField()))
00597             )
00598         );
00599     }
00600     else
00601     {
00602         if (evaluate(ddt0))
00603         {
00604             ddt0 = rDtCoef0_(ddt0)*
00605             (
00606                 rho.oldTime()*vf.oldTime()
00607               - rho.oldTime().oldTime()*vf.oldTime().oldTime()
00608             ) - offCentre_(ddt0());
00609         }
00610 
00611         return tmp<GeometricField<Type, fvPatchField, volMesh> >
00612         (
00613             new GeometricField<Type, fvPatchField, volMesh>
00614             (
00615                 ddtIOobject,
00616                 rDtCoef*(rho*vf - rho.oldTime()*vf.oldTime())
00617               - offCentre_(ddt0())
00618             )
00619         );
00620     }
00621 }
00622 
00623 
00624 template<class Type>
00625 tmp<fvMatrix<Type> >
00626 CrankNicholsonDdtScheme<Type>::fvmDdt
00627 (
00628     GeometricField<Type, fvPatchField, volMesh>& vf
00629 )
00630 {
00631     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00632         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00633         (
00634             "ddt0(" + vf.name() + ')',
00635             vf.dimensions()
00636         );
00637 
00638     tmp<fvMatrix<Type> > tfvm
00639     (
00640         new fvMatrix<Type>
00641         (
00642             vf,
00643             vf.dimensions()*dimVol/dimTime
00644         )
00645     );
00646 
00647     fvMatrix<Type>& fvm = tfvm();
00648 
00649     scalar rDtCoef = rDtCoef_(ddt0).value();
00650 
00651     fvm.diag() = rDtCoef*mesh().V();
00652 
00653     vf.oldTime().oldTime();
00654 
00655     if (mesh().moving())
00656     {
00657         if (evaluate(ddt0))
00658         {
00659             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00660 
00661             ddt0.internalField() =
00662             (
00663                 rDtCoef0*
00664                 (
00665                     mesh().V0()*vf.oldTime().internalField()
00666                   - mesh().V00()*vf.oldTime().oldTime().internalField()
00667                 )
00668               - mesh().V00()*offCentre_(ddt0.internalField())
00669             )/mesh().V0();
00670 
00671             ddt0.boundaryField() =
00672             (
00673                 rDtCoef0*
00674                 (
00675                     vf.oldTime().boundaryField()
00676                   - vf.oldTime().oldTime().boundaryField()
00677                 )
00678               - offCentre_(ff(ddt0.boundaryField()))
00679             );
00680         }
00681 
00682         fvm.source() =
00683         (
00684             rDtCoef*vf.oldTime().internalField()
00685           + offCentre_(ddt0.internalField())
00686         )*mesh().V0();
00687     }
00688     else
00689     {
00690         if (evaluate(ddt0))
00691         {
00692             ddt0 = rDtCoef0_(ddt0)*(vf.oldTime() - vf.oldTime().oldTime())
00693                  - offCentre_(ddt0());
00694         }
00695 
00696         fvm.source() =
00697         (
00698             rDtCoef*vf.oldTime().internalField()
00699           + offCentre_(ddt0.internalField())
00700         )*mesh().V();
00701     }
00702 
00703     return tfvm;
00704 }
00705 
00706 
00707 template<class Type>
00708 tmp<fvMatrix<Type> >
00709 CrankNicholsonDdtScheme<Type>::fvmDdt
00710 (
00711     const dimensionedScalar& rho,
00712     GeometricField<Type, fvPatchField, volMesh>& vf
00713 )
00714 {
00715     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00716         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00717         (
00718             "ddt0(" + rho.name() + ',' + vf.name() + ')',
00719             rho.dimensions()*vf.dimensions()
00720         );
00721 
00722     tmp<fvMatrix<Type> > tfvm
00723     (
00724         new fvMatrix<Type>
00725         (
00726             vf,
00727             rho.dimensions()*vf.dimensions()*dimVol/dimTime
00728         )
00729     );
00730     fvMatrix<Type>& fvm = tfvm();
00731 
00732     scalar rDtCoef = rDtCoef_(ddt0).value();
00733     fvm.diag() = rDtCoef*rho.value()*mesh().V();
00734 
00735     vf.oldTime().oldTime();
00736 
00737     if (mesh().moving())
00738     {
00739         if (evaluate(ddt0))
00740         {
00741             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00742 
00743             ddt0.internalField() =
00744             (
00745                 rDtCoef0*rho.value()*
00746                 (
00747                     mesh().V0()*vf.oldTime().internalField()
00748                   - mesh().V00()*vf.oldTime().oldTime().internalField()
00749                 )
00750               - mesh().V00()*offCentre_(ddt0.internalField())
00751             )/mesh().V0();
00752 
00753             ddt0.boundaryField() =
00754             (
00755                 rDtCoef0*rho.value()*
00756                 (
00757                     vf.oldTime().boundaryField()
00758                   - vf.oldTime().oldTime().boundaryField()
00759                 )
00760               - offCentre_(ff(ddt0.boundaryField()))
00761             );
00762         }
00763 
00764         fvm.source() =
00765         (
00766             rDtCoef*rho.value()*vf.oldTime().internalField()
00767           + offCentre_(ddt0.internalField())
00768         )*mesh().V0();
00769     }
00770     else
00771     {
00772         if (evaluate(ddt0))
00773         {
00774             ddt0 = rDtCoef0_(ddt0)*rho*(vf.oldTime() - vf.oldTime().oldTime())
00775                  - offCentre_(ddt0());
00776         }
00777 
00778         fvm.source() =
00779         (
00780             rDtCoef*rho.value()*vf.oldTime().internalField()
00781           + offCentre_(ddt0.internalField())
00782         )*mesh().V();
00783     }
00784 
00785     return tfvm;
00786 }
00787 
00788 
00789 template<class Type>
00790 tmp<fvMatrix<Type> >
00791 CrankNicholsonDdtScheme<Type>::fvmDdt
00792 (
00793     const volScalarField& rho,
00794     GeometricField<Type, fvPatchField, volMesh>& vf
00795 )
00796 {
00797     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& ddt0 =
00798         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00799         (
00800             "ddt0(" + rho.name() + ',' + vf.name() + ')',
00801             rho.dimensions()*vf.dimensions()
00802         );
00803 
00804     tmp<fvMatrix<Type> > tfvm
00805     (
00806         new fvMatrix<Type>
00807         (
00808             vf,
00809             rho.dimensions()*vf.dimensions()*dimVol/dimTime
00810         )
00811     );
00812     fvMatrix<Type>& fvm = tfvm();
00813 
00814     scalar rDtCoef = rDtCoef_(ddt0).value();
00815     fvm.diag() = rDtCoef*rho.internalField()*mesh().V();
00816 
00817     vf.oldTime().oldTime();
00818     rho.oldTime().oldTime();
00819 
00820     if (mesh().moving())
00821     {
00822         if (evaluate(ddt0))
00823         {
00824             scalar rDtCoef0 = rDtCoef0_(ddt0).value();
00825 
00826             ddt0.internalField() =
00827             (
00828                 rDtCoef0*
00829                 (
00830                     mesh().V0()*rho.oldTime().internalField()
00831                    *vf.oldTime().internalField()
00832                   - mesh().V00()*rho.oldTime().oldTime().internalField()
00833                    *vf.oldTime().oldTime().internalField()
00834                 )
00835               - mesh().V00()*offCentre_(ddt0.internalField())
00836             )/mesh().V0();
00837 
00838             ddt0.boundaryField() =
00839             (
00840                 rDtCoef0*
00841                 (
00842                     rho.oldTime().boundaryField()
00843                    *vf.oldTime().boundaryField()
00844                   - rho.oldTime().oldTime().boundaryField()
00845                    *vf.oldTime().oldTime().boundaryField()
00846                 )
00847               - offCentre_(ff(ddt0.boundaryField()))
00848             );
00849         }
00850 
00851         fvm.source() =
00852         (
00853             rDtCoef*rho.internalField()*vf.oldTime().internalField()
00854           + offCentre_(ddt0.internalField())
00855         )*mesh().V0();
00856     }
00857     else
00858     {
00859         if (evaluate(ddt0))
00860         {
00861             ddt0 = rDtCoef0_(ddt0)*
00862             (
00863                 rho.oldTime()*vf.oldTime()
00864               - rho.oldTime().oldTime()*vf.oldTime().oldTime()
00865             ) - offCentre_(ddt0());
00866         }
00867 
00868         fvm.source() =
00869         (
00870             rDtCoef*rho.oldTime().internalField()*vf.oldTime().internalField()
00871           + offCentre_(ddt0.internalField())
00872         )*mesh().V();
00873     }
00874 
00875     return tfvm;
00876 }
00877 
00878 
00879 
00880 template<class Type>
00881 tmp<typename CrankNicholsonDdtScheme<Type>::fluxFieldType>
00882 CrankNicholsonDdtScheme<Type>::fvcDdtPhiCorr
00883 (
00884     const volScalarField& rA,
00885     const GeometricField<Type, fvPatchField, volMesh>& U,
00886     const fluxFieldType& phi
00887 )
00888 {
00889     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& dUdt0 =
00890         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00891         (
00892             "ddt0(" + U.name() + ')',
00893             U.dimensions()
00894         );
00895 
00896     DDt0Field<fluxFieldType>& dphidt0 =
00897         ddt0_<fluxFieldType>
00898         (
00899             "ddt0(" + phi.name() + ')',
00900             phi.dimensions()
00901         );
00902 
00903     IOobject ddtIOobject
00904     (
00905         "ddtPhiCorr(" + rA.name() + ',' + U.name() + ',' + phi.name() + ')',
00906         mesh().time().timeName(),
00907         mesh()
00908     );
00909 
00910     dimensionedScalar rDtCoef = rDtCoef_(dUdt0);
00911 
00912     if (mesh().moving())
00913     {
00914         return tmp<fluxFieldType>
00915         (
00916             new fluxFieldType
00917             (
00918                 ddtIOobject,
00919                 mesh(),
00920                 dimensioned<typename flux<Type>::type>
00921                 (
00922                     "0",
00923                     rDtCoef.dimensions()*rA.dimensions()*phi.dimensions(),
00924                     pTraits<typename flux<Type>::type>::zero
00925                 )
00926             )
00927         );
00928     }
00929     else
00930     {
00931         if (evaluate(dUdt0))
00932         {
00933             dUdt0 =
00934                 rDtCoef0_(dUdt0)*(U.oldTime() - U.oldTime().oldTime())
00935               - offCentre_(dUdt0());
00936         }
00937 
00938         if (evaluate(dphidt0))
00939         {
00940             dphidt0 =
00941                 rDtCoef0_(dphidt0)*(phi.oldTime() - phi.oldTime().oldTime())
00942               - offCentre_(dphidt0());
00943         }
00944 
00945         return tmp<fluxFieldType>
00946         (
00947             new fluxFieldType
00948             (
00949                 ddtIOobject,
00950                 fvcDdtPhiCoeff(U.oldTime(), phi.oldTime())
00951                *fvc::interpolate(rA)
00952                *(
00953                     (rDtCoef*phi.oldTime() + offCentre_(dphidt0()))
00954                   - (
00955                         fvc::interpolate
00956                         (
00957                             (rDtCoef*U.oldTime() + offCentre_(dUdt0()))
00958                         ) & mesh().Sf()
00959                     )
00960                 )
00961             )
00962         );
00963     }
00964 }
00965 
00966 
00967 template<class Type>
00968 tmp<typename CrankNicholsonDdtScheme<Type>::fluxFieldType>
00969 CrankNicholsonDdtScheme<Type>::fvcDdtPhiCorr
00970 (
00971     const volScalarField& rA,
00972     const volScalarField& rho,
00973     const GeometricField<Type, fvPatchField, volMesh>& U,
00974     const fluxFieldType& phi
00975 )
00976 {
00977     DDt0Field<GeometricField<Type, fvPatchField, volMesh> >& dUdt0 =
00978         ddt0_<GeometricField<Type, fvPatchField, volMesh> >
00979         (
00980             "ddt0(" + U.name() + ')',
00981             U.dimensions()
00982         );
00983 
00984     DDt0Field<fluxFieldType>& dphidt0 =
00985         ddt0_<fluxFieldType>
00986         (
00987             "ddt0(" + phi.name() + ')',
00988             U.dimensions()*dimArea
00989         );
00990 
00991     IOobject ddtIOobject
00992     (
00993         "ddtPhiCorr("
00994       + rA.name() + ',' + rho.name() + ',' + U.name() + ',' + phi.name() + ')',
00995         mesh().time().timeName(),
00996         mesh()
00997     );
00998 
00999     dimensionedScalar rDtCoef = rDtCoef_(dUdt0);
01000 
01001     if (mesh().moving())
01002     {
01003         return tmp<fluxFieldType>
01004         (
01005             new fluxFieldType
01006             (
01007                 ddtIOobject,
01008                 mesh(),
01009                 dimensioned<typename flux<Type>::type>
01010                 (
01011                     "0",
01012                     rA.dimensions()*rho.dimensions()*phi.dimensions()/dimTime,
01013                     pTraits<typename flux<Type>::type>::zero
01014                 )
01015             )
01016         );
01017     }
01018     else
01019     {
01020         if
01021         (
01022             U.dimensions() == dimVelocity
01023          && phi.dimensions() == dimVelocity*dimArea
01024         )
01025         {
01026             if (evaluate(dUdt0))
01027             {
01028                 dUdt0 = rDtCoef0_(dUdt0)*
01029                 (
01030                     U.oldTime() - U.oldTime().oldTime()
01031                 ) - offCentre_(dUdt0());
01032             }
01033 
01034             if (evaluate(dphidt0))
01035             {
01036                 dphidt0 = rDtCoef0_(dphidt0)*
01037                 (
01038                     phi.oldTime()
01039                   - fvc::interpolate(rho.oldTime().oldTime()/rho.oldTime())
01040                    *phi.oldTime().oldTime()
01041                 ) - offCentre_(dphidt0());
01042             }
01043 
01044             return tmp<fluxFieldType>
01045             (
01046                 new fluxFieldType
01047                 (
01048                     ddtIOobject,
01049                     fvcDdtPhiCoeff(U.oldTime(), phi.oldTime())*
01050                     (
01051                         fvc::interpolate(rA*rho.oldTime())
01052                        *(rDtCoef*phi.oldTime() + offCentre_(dphidt0()))
01053                       - (
01054                             fvc::interpolate
01055                             (
01056                                 rA*rho.oldTime()
01057                                *(rDtCoef*U.oldTime() + offCentre_(dUdt0()))
01058                             ) & mesh().Sf()
01059                         )
01060                     )
01061                 )
01062             );
01063         }
01064         else if
01065         (
01066             U.dimensions() == dimVelocity
01067          && phi.dimensions() == rho.dimensions()*dimVelocity*dimArea
01068         )
01069         {
01070             if (evaluate(dUdt0))
01071             {
01072                 dUdt0 = rDtCoef0_(dUdt0)*
01073                 (
01074                     U.oldTime() - U.oldTime().oldTime()
01075                 ) - offCentre_(dUdt0());
01076             }
01077 
01078             if (evaluate(dphidt0))
01079             {
01080                 dphidt0 = rDtCoef0_(dphidt0)*
01081                 (
01082                     phi.oldTime()
01083                    /fvc::interpolate(rho.oldTime())
01084                   - phi.oldTime().oldTime()
01085                    /fvc::interpolate(rho.oldTime().oldTime())
01086                 ) - offCentre_(dphidt0());
01087             }
01088 
01089             return tmp<fluxFieldType>
01090             (
01091                 new fluxFieldType
01092                 (
01093                     ddtIOobject,
01094                     fvcDdtPhiCoeff
01095                     (
01096                         U.oldTime(),
01097                         phi.oldTime()/fvc::interpolate(rho.oldTime())
01098                     )
01099                    *(
01100                         fvc::interpolate(rA*rho.oldTime())
01101                        *(
01102                            rDtCoef*phi.oldTime()/fvc::interpolate(rho.oldTime())
01103                          + offCentre_(dphidt0())
01104                         )
01105                       - (
01106                             fvc::interpolate
01107                             (
01108                                 rA*rho.oldTime()
01109                                *(rDtCoef*U.oldTime() + offCentre_(dUdt0()))
01110                             ) & mesh().Sf()
01111                         )
01112                     )
01113                 )
01114             );
01115         }
01116         else if
01117         (
01118             U.dimensions() == rho.dimensions()*dimVelocity
01119          && phi.dimensions() == rho.dimensions()*dimVelocity*dimArea
01120         )
01121         {
01122             if (evaluate(dUdt0))
01123             {
01124                 dUdt0 = rDtCoef0_(dUdt0)*
01125                 (
01126                     U.oldTime() - U.oldTime().oldTime()
01127                 ) - offCentre_(dUdt0());
01128             }
01129 
01130             if (evaluate(dphidt0))
01131             {
01132                 dphidt0 = rDtCoef0_(dphidt0)*
01133                 (
01134                     phi.oldTime() - phi.oldTime().oldTime()
01135                 ) - offCentre_(dphidt0());
01136             }
01137 
01138             return tmp<fluxFieldType>
01139             (
01140                 new fluxFieldType
01141                 (
01142                     ddtIOobject,
01143                     fvcDdtPhiCoeff(rho.oldTime(), U.oldTime(), phi.oldTime())*
01144                     (
01145                         fvc::interpolate(rA)
01146                        *(rDtCoef*phi.oldTime() + offCentre_(dphidt0()))
01147                       - (
01148                             fvc::interpolate
01149                             (
01150                                 rA*(rDtCoef*U.oldTime() + offCentre_(dUdt0()))
01151                             ) & mesh().Sf()
01152                         )
01153                     )
01154                 )
01155             );
01156         }
01157         else
01158         {
01159             FatalErrorIn
01160             (
01161                 "CrankNicholsonDdtScheme<Type>::fvcDdtPhiCorr"
01162             )   << "dimensions of phi are not correct"
01163                 << abort(FatalError);
01164 
01165             return fluxFieldType::null();
01166         }
01167     }
01168 }
01169 
01170 
01171 template<class Type>
01172 tmp<surfaceScalarField> CrankNicholsonDdtScheme<Type>::meshPhi
01173 (
01174     const GeometricField<Type, fvPatchField, volMesh>& vf
01175 )
01176 {
01177     DDt0Field<surfaceScalarField>& meshPhi0 = ddt0_<surfaceScalarField>
01178     (
01179         "meshPhiCN_0",
01180         dimVolume
01181     );
01182 
01183     if (evaluate(meshPhi0))
01184     {
01185         meshPhi0 =
01186             coef0_(meshPhi0)*mesh().phi().oldTime() - offCentre_(meshPhi0());
01187     }
01188 
01189     return coef_(meshPhi0)*mesh().phi() - offCentre_(meshPhi0());
01190 }
01191 
01192 
01193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
01194 
01195 } // End namespace fv
01196 
01197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
01198 
01199 } // End namespace Foam
01200 
01201 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd