1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "turbulentInletFvPatchField.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
40 const DimensionedField<Type, volMesh>& iF
43 fixedValueFvPatchField<Type>(p, iF),
45 fluctuationScale_(pTraits<Type>::zero),
46 referenceField_(p.size()),
53 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
55 const turbulentInletFvPatchField<Type>& ptf,
57 const DimensionedField<Type, volMesh>& iF,
58 const fvPatchFieldMapper& mapper
61 fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
63 fluctuationScale_(ptf.fluctuationScale_),
64 referenceField_(ptf.referenceField_, mapper),
71 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
74 const DimensionedField<Type, volMesh>& iF,
75 const dictionary& dict
78 fixedValueFvPatchField<Type>(p, iF),
80 fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))),
81 referenceField_("referenceField", dict, p.size()),
82 alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
85 if (dict.found("value"))
87 fixedValueFvPatchField<Type>::operator==
89 Field<Type>("value", dict, p.size())
94 fixedValueFvPatchField<Type>::operator==(referenceField_);
100 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
102 const turbulentInletFvPatchField<Type>& ptf
105 fixedValueFvPatchField<Type>(ptf),
106 ranGen_(ptf.ranGen_),
107 fluctuationScale_(ptf.fluctuationScale_),
108 referenceField_(ptf.referenceField_),
115 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
117 const turbulentInletFvPatchField<Type>& ptf,
118 const DimensionedField<Type, volMesh>& iF
121 fixedValueFvPatchField<Type>(ptf, iF),
122 ranGen_(ptf.ranGen_),
123 fluctuationScale_(ptf.fluctuationScale_),
124 referenceField_(ptf.referenceField_),
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 void turbulentInletFvPatchField<Type>::autoMap
135 const fvPatchFieldMapper& m
138 fixedValueFvPatchField<Type>::autoMap(m);
139 referenceField_.autoMap(m);
144 void turbulentInletFvPatchField<Type>::rmap
146 const fvPatchField<Type>& ptf,
147 const labelList& addr
150 fixedValueFvPatchField<Type>::rmap(ptf, addr);
152 const turbulentInletFvPatchField<Type>& tiptf =
153 refCast<const turbulentInletFvPatchField<Type> >(ptf);
155 referenceField_.rmap(tiptf.referenceField_, addr);
160 void turbulentInletFvPatchField<Type>::updateCoeffs()
167 if (curTimeIndex_ != this->db().time().timeIndex())
169 Field<Type>& patchField = *this;
171 Field<Type> randomField(this->size());
173 forAll(patchField, facei)
175 ranGen_.randomise(randomField[facei]);
178 // Correction-factor proposed by Yi Wang to compensate for the loss
179 // of RMS fluctuation due to the temporal correlation introduced by
180 // the alpha parameter.
181 scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;
184 (1 - alpha_)*patchField
188 + rmsCorr*cmptMultiply
190 randomField - 0.5*pTraits<Type>::one,
192 )*mag(referenceField_)
195 curTimeIndex_ = this->db().time().timeIndex();
198 fixedValueFvPatchField<Type>::updateCoeffs();
203 void turbulentInletFvPatchField<Type>::write(Ostream& os) const
205 fvPatchField<Type>::write(os);
206 os.writeKeyword("fluctuationScale")
207 << fluctuationScale_ << token::END_STATEMENT << nl;
208 referenceField_.writeEntry("referenceField", os);
209 os.writeKeyword("alpha") << alpha_ << token::END_STATEMENT << nl;
210 this->writeEntry("value", os);
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 } // End namespace Foam
218 // ************************************************************************* //