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

advectiveFvPatchField.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 "advectiveFvPatchField.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "fvPatchFieldMapper.H"
00030 #include "volFields.H"
00031 #include "EulerDdtScheme.H"
00032 #include "CrankNicholsonDdtScheme.H"
00033 #include "backwardDdtScheme.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 template<class Type>
00043 advectiveFvPatchField<Type>::advectiveFvPatchField
00044 (
00045     const fvPatch& p,
00046     const DimensionedField<Type, volMesh>& iF
00047 )
00048 :
00049     mixedFvPatchField<Type>(p, iF),
00050     phiName_("phi"),
00051     rhoName_("rho"),
00052     fieldInf_(pTraits<Type>::zero),
00053     lInf_(0.0)
00054 {
00055     this->refValue() = pTraits<Type>::zero;
00056     this->refGrad() = pTraits<Type>::zero;
00057     this->valueFraction() = 0.0;
00058 }
00059 
00060 
00061 template<class Type>
00062 advectiveFvPatchField<Type>::advectiveFvPatchField
00063 (
00064     const advectiveFvPatchField& ptf,
00065     const fvPatch& p,
00066     const DimensionedField<Type, volMesh>& iF,
00067     const fvPatchFieldMapper& mapper
00068 )
00069 :
00070     mixedFvPatchField<Type>(ptf, p, iF, mapper),
00071     phiName_(ptf.phiName_),
00072     rhoName_(ptf.rhoName_),
00073     fieldInf_(ptf.fieldInf_),
00074     lInf_(ptf.lInf_)
00075 {}
00076 
00077 
00078 template<class Type>
00079 advectiveFvPatchField<Type>::advectiveFvPatchField
00080 (
00081     const fvPatch& p,
00082     const DimensionedField<Type, volMesh>& iF,
00083     const dictionary& dict
00084 )
00085 :
00086     mixedFvPatchField<Type>(p, iF),
00087     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
00088     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
00089     fieldInf_(pTraits<Type>::zero),
00090     lInf_(0.0)
00091 {
00092     if (dict.found("value"))
00093     {
00094         fvPatchField<Type>::operator=
00095         (
00096             Field<Type>("value", dict, p.size())
00097         );
00098     }
00099     else
00100     {
00101         fvPatchField<Type>::operator=(this->patchInternalField());
00102     }
00103 
00104     this->refValue() = *this;
00105     this->refGrad() = pTraits<Type>::zero;
00106     this->valueFraction() = 0.0;
00107 
00108     if (dict.readIfPresent("lInf", lInf_))
00109     {
00110         dict.lookup("fieldInf") >> fieldInf_;
00111 
00112         if (lInf_ < 0.0)
00113         {
00114             FatalIOErrorIn
00115             (
00116                 "advectiveFvPatchField<Type>::"
00117                 "advectiveFvPatchField"
00118                 "(const fvPatch&, const Field<Type>&, const dictionary&)",
00119                 dict
00120             )   << "unphysical lInf specified (lInf < 0)\n"
00121                 << "    on patch " << this->patch().name()
00122                 << " of field " << this->dimensionedInternalField().name()
00123                 << " in file " << this->dimensionedInternalField().objectPath()
00124                 << exit(FatalIOError);
00125         }
00126     }
00127 }
00128 
00129 
00130 template<class Type>
00131 advectiveFvPatchField<Type>::advectiveFvPatchField
00132 (
00133     const advectiveFvPatchField& ptpsf
00134 )
00135 :
00136     mixedFvPatchField<Type>(ptpsf),
00137     phiName_(ptpsf.phiName_),
00138     rhoName_(ptpsf.rhoName_),
00139     fieldInf_(ptpsf.fieldInf_),
00140     lInf_(ptpsf.lInf_)
00141 {}
00142 
00143 
00144 template<class Type>
00145 advectiveFvPatchField<Type>::advectiveFvPatchField
00146 (
00147     const advectiveFvPatchField& ptpsf,
00148     const DimensionedField<Type, volMesh>& iF
00149 )
00150 :
00151     mixedFvPatchField<Type>(ptpsf, iF),
00152     phiName_(ptpsf.phiName_),
00153     rhoName_(ptpsf.rhoName_),
00154     fieldInf_(ptpsf.fieldInf_),
00155     lInf_(ptpsf.lInf_)
00156 {}
00157 
00158 
00159 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00160 
00161 template<class Type>
00162 tmp<scalarField> advectiveFvPatchField<Type>::advectionSpeed() const
00163 {
00164     const surfaceScalarField& phi =
00165         this->db().objectRegistry::lookupObject<surfaceScalarField>(phiName_);
00166 
00167     fvsPatchField<scalar> phip = this->patch().lookupPatchField
00168     (
00169         phiName_,
00170         reinterpret_cast<const surfaceScalarField*>(0),
00171         reinterpret_cast<const scalar*>(0)
00172     );
00173 
00174     if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00175     {
00176         const fvPatchScalarField& rhop = this->patch().lookupPatchField
00177         (
00178             rhoName_,
00179             reinterpret_cast<const volScalarField*>(0),
00180             reinterpret_cast<const scalar*>(0)
00181         );
00182 
00183         return phip/(rhop*this->patch().magSf());
00184     }
00185     else
00186     {
00187         return phip/this->patch().magSf();
00188     }
00189 }
00190 
00191 
00192 template<class Type>
00193 void advectiveFvPatchField<Type>::updateCoeffs()
00194 {
00195     if (this->updated())
00196     {
00197         return;
00198     }
00199 
00200     word ddtScheme
00201     (
00202         this->dimensionedInternalField().mesh()
00203        .ddtScheme(this->dimensionedInternalField().name())
00204     );
00205     scalar deltaT = this->db().time().deltaT().value();
00206 
00207     const GeometricField<Type, fvPatchField, volMesh>& field =
00208         this->db().objectRegistry::
        lookupObject<GeometricField<Type, fvPatchField, volMesh> >
00209         (
00210             this->dimensionedInternalField().name()
00211         );
00212 
00213     // Calculate the advection speed of the field wave
00214     // If the wave is incoming set the speed to 0.
00215     scalarField w = Foam::max(advectionSpeed(), scalar(0));
00216 
00217     // Calculate the field wave coefficient alpha (See notes)
00218     scalarField alpha = w*deltaT*this->patch().deltaCoeffs();
00219 
00220     label patchi = this->patch().index();
00221 
00222     // Non-reflecting outflow boundary
00223     // If lInf_ defined setup relaxation to the value fieldInf_.
00224     if (lInf_ > SMALL)
00225     {
00226         // Calculate the field relaxation coefficient k (See notes)
00227         scalarField k = w*deltaT/lInf_;
00228 
00229         if
00230         (
00231             ddtScheme == fv::EulerDdtScheme<scalar>::typeName
00232          || ddtScheme == fv::CrankNicholsonDdtScheme<scalar>::typeName
00233         )
00234         {
00235             this->refValue() =
00236             (
00237                 field.oldTime().boundaryField()[patchi] + k*fieldInf_
00238             )/(1.0 + k);
00239 
00240             this->valueFraction() = (1.0 + k)/(1.0 + alpha + k);
00241         }
00242         else if (ddtScheme == fv::backwardDdtScheme<scalar>::typeName)
00243         {
00244             this->refValue() =
00245             (
00246                 2.0*field.oldTime().boundaryField()[patchi]
00247               - 0.5*field.oldTime().oldTime().boundaryField()[patchi]
00248               + k*fieldInf_
00249             )/(1.5 + k);
00250 
00251             this->valueFraction() = (1.5 + k)/(1.5 + alpha + k);
00252         }
00253         else
00254         {
00255             FatalErrorIn
00256             (
00257                 "advectiveFvPatchField<Type>::updateCoeffs()"
00258             )   << "    Unsupported temporal differencing scheme : "
00259                 << ddtScheme
00260                 << "\n    on patch " << this->patch().name()
00261                 << " of field " << this->dimensionedInternalField().name()
00262                 << " in file " << this->dimensionedInternalField().objectPath()
00263                 << exit(FatalError);
00264         }
00265     }
00266     else
00267     {
00268         if
00269         (
00270             ddtScheme == fv::EulerDdtScheme<scalar>::typeName
00271          || ddtScheme == fv::CrankNicholsonDdtScheme<scalar>::typeName
00272         )
00273         {
00274             this->refValue() = field.oldTime().boundaryField()[patchi];
00275 
00276             this->valueFraction() = 1.0/(1.0 + alpha);
00277         }
00278         else if (ddtScheme == fv::backwardDdtScheme<scalar>::typeName)
00279         {
00280             this->refValue() =
00281             (
00282                 2.0*field.oldTime().boundaryField()[patchi]
00283               - 0.5*field.oldTime().oldTime().boundaryField()[patchi]
00284             )/1.5;
00285 
00286             this->valueFraction() = 1.5/(1.5 + alpha);
00287         }
00288         else
00289         {
00290             FatalErrorIn
00291             (
00292                 "advectiveFvPatchField<Type>::updateCoeffs()"
00293             )   << "    Unsupported temporal differencing scheme : "
00294                 << ddtScheme
00295                 << "\n    on patch " << this->patch().name()
00296                 << " of field " << this->dimensionedInternalField().name()
00297                 << " in file " << this->dimensionedInternalField().objectPath()
00298                 << exit(FatalError);
00299         }
00300     }
00301 
00302     mixedFvPatchField<Type>::updateCoeffs();
00303 }
00304 
00305 
00306 template<class Type>
00307 void advectiveFvPatchField<Type>::write(Ostream& os) const
00308 {
00309     fvPatchField<Type>::write(os);
00310 
00311     if (phiName_ != "phi")
00312     {
00313         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
00314     }
00315     if (rhoName_ != "rho")
00316     {
00317         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
00318     }
00319 
00320     if (lInf_ > SMALL)
00321     {
00322         os.writeKeyword("fieldInf") << fieldInf_
00323             << token::END_STATEMENT << nl;
00324         os.writeKeyword("lInf") << lInf_
00325             << token::END_STATEMENT << nl;
00326     }
00327 
00328     this->writeEntry("value", os);
00329 }
00330 
00331 
00332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00333 
00334 } // End namespace Foam
00335 
00336 // ************************************************************************* //
00337 
Copyright © 2000-2009 OpenCFD Ltd