00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "turbulentInletFvPatchField.H"
00028
00029
00030
00031 namespace Foam
00032 {
00033
00034
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
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
00179
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 }
00216
00217