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
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:
90 outTempType_(outputTemperatureType::WALL),
91 refTempType_(refTemperatureType::CELL),
92 Tref_(nullptr)
93{}
94
95
96Foam::externalCoupledTemperatureMixedFvPatchScalarField::
97externalCoupledTemperatureMixedFvPatchScalarField
98(
100 const fvPatch& p,
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,
117 const dictionary& dict
118)
119:
120 //externalCoupledMixedFvPatchField<scalar>(p, iF, dict)
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 {
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 (dict.found("refValue"))
153 {
154 // Initialise same way as mixed
155 this->refValue() = scalarField("refValue", dict, p.size());
156 this->refGrad() = scalarField("refGradient", dict, p.size());
157 this->valueFraction() = scalarField("valueFraction", dict, p.size());
158
159 evaluate();
160 }
161 else
162 {
163 // For convenience: initialise as fixedValue with either read value
164 // or extrapolated value
165 if (dict.found("value"))
166 {
168 (
169 scalarField("value", dict, p.size())
170 );
171 }
172 else
173 {
175 }
176
177 // Initialise as a fixed value
178 this->refValue() = *this;
179 this->refGrad() = Zero;
180 this->valueFraction() = 1.0;
181 }
182}
183
184
185Foam::externalCoupledTemperatureMixedFvPatchScalarField::
186externalCoupledTemperatureMixedFvPatchScalarField
187(
189)
190:
192 outTempType_(rhs.outTempType_),
193 refTempType_(rhs.refTempType_),
194 Tref_(rhs.Tref_.clone())
195{}
196
197
198Foam::externalCoupledTemperatureMixedFvPatchScalarField::
199externalCoupledTemperatureMixedFvPatchScalarField
200(
203)
204:
205 externalCoupledMixedFvPatchField<scalar>(rhs, iF),
206 outTempType_(rhs.outTempType_),
207 refTempType_(rhs.refTempType_),
208 Tref_(rhs.Tref_.clone())
209{}
210
211
212// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
213
215(
216 Ostream& os
217) const
218{
219 const label patchi = patch().index();
220
221 // Heat flux [W/m2]
222 scalarField qDot(this->patch().size(), Zero);
223
224 typedef compressible::turbulenceModel cmpTurbModelType;
225
226 static word turbName
227 (
229 (
231 internalField().group()
232 )
233 );
234
235 static word thermoName("thermophysicalProperties");
236
237 if (db().foundObject<cmpTurbModelType>(turbName))
238 {
239 const cmpTurbModelType& turbModel =
240 db().lookupObject<cmpTurbModelType>(turbName);
241
242 const basicThermo& thermo = turbModel.transport();
243
244 const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
245
246 qDot = turbModel.alphaEff(patchi)*hep.snGrad();
247 }
248 else if (db().foundObject<basicThermo>(thermoName))
249 {
250 const basicThermo& thermo = db().lookupObject<basicThermo>(thermoName);
251
252 const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
253
254 qDot = thermo.alpha().boundaryField()[patchi]*hep.snGrad();
255 }
256 else
257 {
259 << "Condition requires either compressible turbulence and/or "
260 << "thermo model to be available" << exit(FatalError);
261 }
262
263
264 // Wall temperature [K]
265 const scalarField& Twall = *this;
266
267 // Fluid temperature [K]
268 tmp<scalarField> tfluid;
269
270 if (refTempType_ == refTemperatureType::USER)
271 {
272 // User-specified reference temperature
273 const scalar currTref =
274 Tref_->value(this->db().time().timeOutputValue());
275
276 tfluid = tmp<scalarField>::New(size(), currTref);
277 }
278 else
279 {
280 // Near wall cell temperature
281 tfluid = patchInternalField();
282 }
283
284 const scalarField Tfluid(tfluid);
285
286 // Heat transfer coefficient [W/m2/K]
287 // This htc needs to be always larger or equal to zero
288 //const scalarField htc(qDot/max(Twall - Tfluid, 1e-3));
289 scalarField htc(qDot.size(), Zero);
290 forAll(qDot, i)
291 {
292 const scalar deltaT = mag(Twall[i] - Tfluid[i]);
293 if (deltaT > 1e-3)
294 {
295 htc[i] = sign(qDot[i])*qDot[i]/deltaT;
296 }
297 }
298
299 const Field<scalar>& magSf = this->patch().magSf();
300
301 const UList<scalar>& Tout =
302 (
303 outTempType_ == outputTemperatureType::FLUID
304 ? Tfluid
305 : Twall
306 );
307
308 forAll(patch(), facei)
309 {
310 os << magSf[facei] << token::SPACE
311 << Tout[facei] << token::SPACE
312 << qDot[facei] << token::SPACE
313 << htc[facei] << nl;
314 }
315}
316
317
319(
320 Istream& is
321)
322{
323 // Assume generic input stream so we can do line-based format and skip
324 // unused columns
325 ISstream& iss = dynamic_cast<ISstream&>(is);
326
327 string line;
328
329 forAll(*this, facei)
330 {
331 iss.getLine(line);
332 IStringStream lineStr(line);
333
334 lineStr
335 >> this->refValue()[facei]
336 >> this->refGrad()[facei]
337 >> this->valueFraction()[facei];
338 }
339}
340
341
343(
344 Ostream& os
345) const
346{
349 (
350 "outputTemperature",
351 outputTemperatureNames[outTempType_]
352 );
354 (
355 "htcRefTemperature",
356 refTemperatureNames[refTempType_]
357 );
358
359 if (Tref_)
360 {
361 Tref_->writeData(os);
362 }
363}
364
365
366// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367
368namespace Foam
369{
371 (
374 );
375}
376
377
378// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
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:61
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:75
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:112
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Extends the mixed boundary condition with serialisation functions.
This boundary condition provides a temperatue interface to an external application.
virtual bool write()
Write the output fields.
A FieldMapper for finite-volume patch fields.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: fvPatchField.C:237
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:229
const objectRegistry & db() const
Return local objectRegistry.
Definition: fvPatchField.C:210
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:408
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
A line primitive.
Definition: line.H:68
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual Field< Type > & refGrad()
virtual Field< Type > & refValue()
virtual scalarField & valueFraction()
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for managing temporary objects.
Definition: tmp.H:65
@ SPACE
Space [isspace].
Definition: token.H:125
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define makePatchTypeField(PatchTypeField, typePatchTypeField)
Definition: fvPatchField.H:676
#define WarningInFunction
Report a warning using Foam::Warning.
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:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333