intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / turbulentInlet / turbulentInletFvPatchField.C
blob1846ada328e389e97412dc809b36f6e7e1c691f1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 template<class Type>
37 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
39     const fvPatch& p,
40     const DimensionedField<Type, volMesh>& iF
43     fixedValueFvPatchField<Type>(p, iF),
44     ranGen_(label(0)),
45     fluctuationScale_(pTraits<Type>::zero),
46     referenceField_(p.size()),
47     alpha_(0.1),
48     curTimeIndex_(-1)
52 template<class Type>
53 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
55     const turbulentInletFvPatchField<Type>& ptf,
56     const fvPatch& p,
57     const DimensionedField<Type, volMesh>& iF,
58     const fvPatchFieldMapper& mapper
61     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
62     ranGen_(label(0)),
63     fluctuationScale_(ptf.fluctuationScale_),
64     referenceField_(ptf.referenceField_, mapper),
65     alpha_(ptf.alpha_),
66     curTimeIndex_(-1)
70 template<class Type>
71 turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
73     const fvPatch& p,
74     const DimensionedField<Type, volMesh>& iF,
75     const dictionary& dict
78     fixedValueFvPatchField<Type>(p, iF),
79     ranGen_(label(0)),
80     fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))),
81     referenceField_("referenceField", dict, p.size()),
82     alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
83     curTimeIndex_(-1)
85     if (dict.found("value"))
86     {
87         fixedValueFvPatchField<Type>::operator==
88         (
89             Field<Type>("value", dict, p.size())
90         );
91     }
92     else
93     {
94         fixedValueFvPatchField<Type>::operator==(referenceField_);
95     }
99 template<class Type>
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_),
109     alpha_(ptf.alpha_),
110     curTimeIndex_(-1)
114 template<class Type>
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_),
125     alpha_(ptf.alpha_),
126     curTimeIndex_(-1)
130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
132 template<class Type>
133 void turbulentInletFvPatchField<Type>::autoMap
135     const fvPatchFieldMapper& m
138     fixedValueFvPatchField<Type>::autoMap(m);
139     referenceField_.autoMap(m);
143 template<class Type>
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);
159 template<class Type>
160 void turbulentInletFvPatchField<Type>::updateCoeffs()
162     if (this->updated())
163     {
164         return;
165     }
167     if (curTimeIndex_ != this->db().time().timeIndex())
168     {
169         Field<Type>& patchField = *this;
171         Field<Type> randomField(this->size());
173         forAll(patchField, facei)
174         {
175             ranGen_.randomise(randomField[facei]);
176         }
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_;
183         patchField =
184             (1 - alpha_)*patchField
185           + alpha_*
186             (
187                 referenceField_
188               + rmsCorr*cmptMultiply
189                 (
190                     randomField - 0.5*pTraits<Type>::one,
191                     fluctuationScale_
192                 )*mag(referenceField_)
193             );
195         curTimeIndex_ = this->db().time().timeIndex();
196     }
198     fixedValueFvPatchField<Type>::updateCoeffs();
202 template<class Type>
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     this->writeEntry("value", os);
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace Foam
217 // ************************************************************************* //