Loading...
Searching...
No Matches
externalCoupledTemperatureMixedFvPatchScalarField.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
32#include "fvPatchFieldMapper.H"
33#include "volFields.H"
34#include "Enum.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38const Foam::Enum
39<
40 Foam::externalCoupledTemperatureMixedFvPatchScalarField::
41 outputTemperatureType
42>
43Foam::externalCoupledTemperatureMixedFvPatchScalarField::outputTemperatureNames
44({
45 { outputTemperatureType::FLUID, "fluid" },
46 { outputTemperatureType::WALL, "wall" },
47});
48
49
50const Foam::Enum
51<
52 Foam::externalCoupledTemperatureMixedFvPatchScalarField::
53 refTemperatureType
54>
55Foam::externalCoupledTemperatureMixedFvPatchScalarField::refTemperatureNames
56({
57 { refTemperatureType::CELL, "cell" },
58 { refTemperatureType::USER, "user" },
59});
60
61
62// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
63
64void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeHeader
65(
66 Ostream& os
67) const
68{
69 if (outTempType_ == outputTemperatureType::WALL)
70 {
71 os << "# Values: area Twall qDot htc" << endl;
72 }
73 else
74 {
75 os << "# Values: area Tfluid qDot htc" << endl;
76 }
77}
78
79
80// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81
82Foam::externalCoupledTemperatureMixedFvPatchScalarField::
83externalCoupledTemperatureMixedFvPatchScalarField
84(
85 const fvPatch& p,
87)
88:
89 externalCoupledMixedFvPatchField<scalar>(p, iF),
90 outTempType_(outputTemperatureType::WALL),
91 refTempType_(refTemperatureType::CELL),
92 Tref_(nullptr)
93{}
94
95
96Foam::externalCoupledTemperatureMixedFvPatchScalarField::
97externalCoupledTemperatureMixedFvPatchScalarField
98(
100 const fvPatch& p,
101 const DimensionedField<scalar, volMesh>& iF,
102 const fvPatchFieldMapper& mapper
103)
104:
105 externalCoupledMixedFvPatchField<scalar>(rhs, p, iF, mapper),
106 outTempType_(rhs.outTempType_),
107 refTempType_(rhs.refTempType_),
108 Tref_(rhs.Tref_.clone())
109{}
110
111
112Foam::externalCoupledTemperatureMixedFvPatchScalarField::
113externalCoupledTemperatureMixedFvPatchScalarField
114(
115 const fvPatch& p,
116 const DimensionedField<scalar, volMesh>& iF,
117 const dictionary& dict
118)
119:
120 //externalCoupledMixedFvPatchField<scalar>(p, iF, dict)
121 externalCoupledMixedFvPatchField<scalar>(p, iF),
122 outTempType_(outputTemperatureType::WALL),
123 refTempType_
124 (
125 refTemperatureNames.getOrDefault
126 (
127 "htcRefTemperature",
128 dict,
129 refTemperatureType::CELL
130 )
131 ),
132 Tref_(nullptr)
133{
134 if (dict.found("outputTemperature"))
135 {
136 outTempType_ = outputTemperatureNames.get("outputTemperature", dict);
137 }
138 else
139 {
140 WarningInFunction
141 << "outputTemperature not specified "
142 << flatOutput(outputTemperatureNames) << nl
143 << "using 'wall' as compatibility default" << nl
144 << endl;
145 }
146
147 if (refTempType_ == refTemperatureType::USER)
148 {
149 Tref_ = Function1<scalar>::New("Tref", dict, &db());
150 }
151
152 if (this->readMixedEntries(dict))
153 {
154 // Initialise same way as mixed
155 evaluate();
156 }
157 else
158 {
159 // For convenience: initialise as fixedValue with either read value
160 // or extrapolated value
161 if (!this->readValueEntry(dict))
162 {
163 fvPatchField<scalar>::extrapolateInternal();
164 }
165
166 // Initialise as a fixed value
167 this->refValue() = *this;
168 this->refGrad() = Zero;
169 this->valueFraction() = 1.0;
170 }
171}
172
173
174Foam::externalCoupledTemperatureMixedFvPatchScalarField::
175externalCoupledTemperatureMixedFvPatchScalarField
176(
178)
179:
180 externalCoupledMixedFvPatchField<scalar>(rhs),
181 outTempType_(rhs.outTempType_),
182 refTempType_(rhs.refTempType_),
183 Tref_(rhs.Tref_.clone())
184{}
185
186
187Foam::externalCoupledTemperatureMixedFvPatchScalarField::
188externalCoupledTemperatureMixedFvPatchScalarField
189(
191 const DimensionedField<scalar, volMesh>& iF
192)
193:
194 externalCoupledMixedFvPatchField<scalar>(rhs, iF),
195 outTempType_(rhs.outTempType_),
196 refTempType_(rhs.refTempType_),
197 Tref_(rhs.Tref_.clone())
198{}
199
200
201// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202
203void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
204(
205 Ostream& os
206) const
207{
208 const label patchi = patch().index();
209
210 // Heat flux [W/m2]
211 scalarField qDot(this->patch().size(), Zero);
212
213 typedef compressible::turbulenceModel cmpTurbModelType;
214
215 static word turbName
216 (
217 IOobject::groupName
218 (
219 turbulenceModel::propertiesName,
220 internalField().group()
221 )
222 );
223
224 static word thermoName("thermophysicalProperties");
225
226 if (db().foundObject<cmpTurbModelType>(turbName))
227 {
228 const cmpTurbModelType& turbModel =
229 db().lookupObject<cmpTurbModelType>(turbName);
230
231 const basicThermo& thermo = turbModel.transport();
232
233 const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
234
235 qDot = turbModel.alphaEff(patchi)*hep.snGrad();
236 }
237 else if (db().foundObject<basicThermo>(thermoName))
238 {
239 const basicThermo& thermo = db().lookupObject<basicThermo>(thermoName);
240
241 const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
242
243 qDot = thermo.alpha().boundaryField()[patchi]*hep.snGrad();
244 }
245 else
246 {
248 << "Condition requires either compressible turbulence and/or "
249 << "thermo model to be available" << exit(FatalError);
250 }
251
252
253 // Wall temperature [K]
254 const scalarField& Twall = *this;
255
256 // Fluid temperature [K]
257 scalarField Tfluid(size());
258
259 if (refTempType_ == refTemperatureType::USER)
260 {
261 // User-specified reference temperature
262 const scalar currTref =
263 Tref_->value(this->db().time().timeOutputValue());
264
265 Tfluid = currTref;
266 }
267 else
268 {
269 // Near wall cell temperature
270 this->patchInternalField(Tfluid);
271 }
272
273 // Heat transfer coefficient [W/m2/K]
274 // This htc needs to be always larger or equal to zero
275 //const scalarField htc(qDot/max(Twall - Tfluid, 1e-3));
276 scalarField htc(qDot.size(), Zero);
277 forAll(qDot, i)
278 {
279 const scalar deltaT = mag(Twall[i] - Tfluid[i]);
280 if (deltaT > 1e-3)
281 {
282 htc[i] = sign(qDot[i])*qDot[i]/deltaT;
283 }
284 }
285
286 const Field<scalar>& magSf = this->patch().magSf();
287
288 const UList<scalar>& Tout =
289 (
290 outTempType_ == outputTemperatureType::FLUID
291 ? Tfluid
292 : Twall
293 );
294
295 forAll(patch(), facei)
296 {
297 os << magSf[facei] << token::SPACE
298 << Tout[facei] << token::SPACE
299 << qDot[facei] << token::SPACE
300 << htc[facei] << nl;
301 }
302}
303
304
305void Foam::externalCoupledTemperatureMixedFvPatchScalarField::readData
306(
307 Istream& is
308)
309{
310 // Assume generic input stream so we can do line-based format and skip
311 // unused columns
312 ISstream& iss = dynamic_cast<ISstream&>(is);
313
314 string line;
315
316 forAll(*this, facei)
317 {
318 iss.getLine(line);
319 IStringStream lineStr(line);
320
321 lineStr
322 >> this->refValue()[facei]
323 >> this->refGrad()[facei]
324 >> this->valueFraction()[facei];
325 }
326}
327
328
329void Foam::externalCoupledTemperatureMixedFvPatchScalarField::write
330(
331 Ostream& os
332) const
333{
336 (
337 "outputTemperature",
338 outputTemperatureNames[outTempType_]
339 );
341 (
342 "htcRefTemperature",
343 refTemperatureNames[refTempType_]
344 );
345
346 if (Tref_)
347 {
348 Tref_->writeData(os);
349 }
351
352
353// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354
355namespace Foam
356{
358 (
361 );
362}
363
364
365// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
if(patchID !=-1)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Generic input stream using a standard (STL) stream.
Definition ISstream.H:54
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition Ostream.H:331
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
A line primitive.
Definition line.H:180
virtual void write(Ostream &) const
Write.
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
virtual tmp< fvPatchField< scalar > > clone() const
Return a clone.
externalCoupledTemperatureMixedFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Define a concrete fvPatchField type and add to run-time tables Example, (fvPatchScalarField,...
const std::string patch
OpenFOAM patch number as a std::string.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
Namespace for OpenFOAM.
dimensionedScalar sign(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
fvPatchField< scalar > fvPatchScalarField
dictionary dict
psiReactionThermo & thermo
volScalarField & e
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299