turbulentInletFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const fvPatch& p,
35 )
36 :
38  ranGen_(label(0)),
39  fluctuationScale_(Zero),
40  referenceField_(p.size()),
41  alpha_(0.1),
42  curTimeIndex_(-1)
43 {}
44 
45 
46 template<class Type>
48 (
49  const fvPatch& p,
51  const dictionary& dict
52 )
53 :
54  fixedValueFvPatchField<Type>(p, iF, dict, false),
55  ranGen_(label(0)),
56  fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))),
57  referenceField_("referenceField", dict, p.size()),
58  alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
59  curTimeIndex_(-1)
60 {
61  if (dict.found("value"))
62  {
64  (
65  Field<Type>("value", dict, p.size())
66  );
67  }
68  else
69  {
71  }
72 }
73 
74 
75 template<class Type>
77 (
79  const fvPatch& p,
81  const fvPatchFieldMapper& mapper
82 )
83 :
84  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
85  ranGen_(label(0)),
86  fluctuationScale_(ptf.fluctuationScale_),
87  referenceField_(mapper(ptf.referenceField_)),
88  alpha_(ptf.alpha_),
89  curTimeIndex_(-1)
90 {}
91 
92 
93 template<class Type>
95 (
98 )
99 :
101  ranGen_(ptf.ranGen_),
102  fluctuationScale_(ptf.fluctuationScale_),
103  referenceField_(ptf.referenceField_),
104  alpha_(ptf.alpha_),
105  curTimeIndex_(-1)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Type>
113 (
114  const fvPatchFieldMapper& m
115 )
116 {
118  m(referenceField_, referenceField_);
119 }
120 
121 
122 template<class Type>
124 (
125  const fvPatchField<Type>& ptf,
126  const labelList& addr
127 )
128 {
130 
131  const turbulentInletFvPatchField<Type>& tiptf =
132  refCast<const turbulentInletFvPatchField<Type>>(ptf);
133 
134  referenceField_.rmap(tiptf.referenceField_, addr);
135 }
136 
137 
138 template<class Type>
140 {
141  if (this->updated())
142  {
143  return;
144  }
145 
146  if (curTimeIndex_ != this->db().time().timeIndex())
147  {
148  Field<Type>& patchField = *this;
149 
150  Field<Type> randomField(this->size());
151 
152  forAll(patchField, facei)
153  {
154  randomField[facei] = ranGen_.sample01<Type>();
155  }
156 
157  // Correction-factor to compensate for the loss of RMS fluctuation
158  // due to the temporal correlation introduced by the alpha parameter.
159  scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;
160 
161  patchField =
162  (1 - alpha_)*patchField
163  + alpha_*
164  (
165  referenceField_
166  + rmsCorr*cmptMultiply
167  (
168  randomField - 0.5*pTraits<Type>::one,
169  fluctuationScale_
170  )*mag(referenceField_)
171  );
172 
173  curTimeIndex_ = this->db().time().timeIndex();
174  }
175 
177 }
178 
179 
180 template<class Type>
182 {
184  writeEntry(os, "fluctuationScale", fluctuationScale_);
185  writeEntry(os, "referenceField", referenceField_);
186  writeEntry(os, "alpha", alpha_);
187  writeEntry(os, "value", *this);
188 }
189 
190 
191 // ************************************************************************* //
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
dimensionedScalar sqrt(const dimensionedScalar &ds)
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual void write(Ostream &) const
Write.
Pre-declare SubField and related Field type.
Definition: Field.H:56
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
turbulentInletFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
This boundary condition generates a fluctuating inlet condition by adding a random component to a ref...
Foam::fvPatchFieldMapper.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
static const zero Zero
Definition: zero.H:97
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
label timeIndex
Definition: getTimeIndex.H:4
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p