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

turbulentInletFvPatchField.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 "turbulentInletFvPatchField.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
00038 (
00039     const fvPatch& p,
00040     const DimensionedField<Type, volMesh>& iF
00041 )
00042 :
00043     fixedValueFvPatchField<Type>(p, iF),
00044     ranGen_(label(0)),
00045     fluctuationScale_(pTraits<Type>::zero),
00046     referenceField_(p.size()),
00047     alpha_(0.1),
00048     curTimeIndex_(-1)
00049 {}
00050 
00051 
00052 template<class Type>
00053 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
00054 (
00055     const turbulentInletFvPatchField<Type>& ptf,
00056     const fvPatch& p,
00057     const DimensionedField<Type, volMesh>& iF,
00058     const fvPatchFieldMapper& mapper
00059 )
00060 :
00061     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
00062     ranGen_(label(0)),
00063     fluctuationScale_(ptf.fluctuationScale_),
00064     referenceField_(ptf.referenceField_, mapper),
00065     alpha_(ptf.alpha_),
00066     curTimeIndex_(-1)
00067 {}
00068 
00069 
00070 template<class Type>
00071 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
00072 (
00073     const fvPatch& p,
00074     const DimensionedField<Type, volMesh>& iF,
00075     const dictionary& dict
00076 )
00077 :
00078     fixedValueFvPatchField<Type>(p, iF),
00079     ranGen_(label(0)),
00080     fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))),
00081     referenceField_("referenceField", dict, p.size()),
00082     alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
00083     curTimeIndex_(-1)
00084 {
00085     if (dict.found("value"))
00086     {
00087         fixedValueFvPatchField<Type>::operator==
00088         (
00089             Field<Type>("value", dict, p.size())
00090         );
00091     }
00092     else
00093     {
00094         fixedValueFvPatchField<Type>::operator==(referenceField_);
00095     }
00096 }
00097 
00098 
00099 template<class Type>
00100 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
00101 (
00102     const turbulentInletFvPatchField<Type>& ptf
00103 )
00104 :
00105     fixedValueFvPatchField<Type>(ptf),
00106     ranGen_(ptf.ranGen_),
00107     fluctuationScale_(ptf.fluctuationScale_),
00108     referenceField_(ptf.referenceField_),
00109     alpha_(ptf.alpha_),
00110     curTimeIndex_(-1)
00111 {}
00112 
00113 
00114 template<class Type>
00115 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
00116 (
00117     const turbulentInletFvPatchField<Type>& ptf,
00118     const DimensionedField<Type, volMesh>& iF
00119 )
00120 :
00121     fixedValueFvPatchField<Type>(ptf, iF),
00122     ranGen_(ptf.ranGen_),
00123     fluctuationScale_(ptf.fluctuationScale_),
00124     referenceField_(ptf.referenceField_),
00125     alpha_(ptf.alpha_),
00126     curTimeIndex_(-1)
00127 {}
00128 
00129 
00130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00131 
00132 template<class Type>
00133 void turbulentInletFvPatchField<Type>::autoMap
00134 (
00135     const fvPatchFieldMapper& m
00136 )
00137 {
00138     fixedValueFvPatchField<Type>::autoMap(m);
00139     referenceField_.autoMap(m);
00140 }
00141 
00142 
00143 template<class Type>
00144 void turbulentInletFvPatchField<Type>::rmap
00145 (
00146     const fvPatchField<Type>& ptf,
00147     const labelList& addr
00148 )
00149 {
00150     fixedValueFvPatchField<Type>::rmap(ptf, addr);
00151 
00152     const turbulentInletFvPatchField<Type>& tiptf =
00153         refCast<const turbulentInletFvPatchField<Type> >(ptf);
00154 
00155     referenceField_.rmap(tiptf.referenceField_, addr);
00156 }
00157 
00158 
00159 template<class Type>
00160 void turbulentInletFvPatchField<Type>::updateCoeffs()
00161 {
00162     if (this->updated())
00163     {
00164         return;
00165     }
00166 
00167     if (curTimeIndex_ != this->db().time().timeIndex())
00168     {
00169         Field<Type>& patchField = *this;
00170 
00171         Field<Type> randomField(this->size());
00172 
00173         forAll(patchField, facei)
00174         {
00175             ranGen_.randomise(randomField[facei]);
00176         }
00177 
00178         // Correction-factor to compensate for the loss of RMS fluctuation
00179         // due to the temporal correlation introduced by the alpha parameter.
00180         scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;
00181 
00182         patchField =
00183             (1 - alpha_)*patchField
00184           + alpha_*
00185             (
00186                 referenceField_
00187               + rmsCorr*cmptMultiply
00188                 (
00189                     randomField - 0.5*pTraits<Type>::one,
00190                     fluctuationScale_
00191                 )*mag(referenceField_)
00192             );
00193 
00194         curTimeIndex_ = this->db().time().timeIndex();
00195     }
00196 
00197     fixedValueFvPatchField<Type>::updateCoeffs();
00198 }
00199 
00200 
00201 template<class Type>
00202 void turbulentInletFvPatchField<Type>::write(Ostream& os) const
00203 {
00204     fvPatchField<Type>::write(os);
00205     os.writeKeyword("fluctuationScale")
00206         << fluctuationScale_ << token::END_STATEMENT << nl;
00207     referenceField_.writeEntry("referenceField", os);
00208     os.writeKeyword("alpha") << alpha_ << token::END_STATEMENT << nl;
00209     this->writeEntry("value", os);
00210 }
00211 
00212 
00213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00214 
00215 } // End namespace Foam
00216 
00217 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd