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 -------------------------------------------------------------------------------
11 License
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 
38 const Foam::Enum
39 <
40  Foam::externalCoupledTemperatureMixedFvPatchScalarField::
41  outputTemperatureType
42 >
43 Foam::externalCoupledTemperatureMixedFvPatchScalarField::outputTemperatureNames
44 ({
45  { outputTemperatureType::FLUID, "fluid" },
46  { outputTemperatureType::WALL, "wall" },
47 });
48 
49 
50 const Foam::Enum
51 <
52  Foam::externalCoupledTemperatureMixedFvPatchScalarField::
53  refTemperatureType
54 >
55 Foam::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 
84 (
85  const fvPatch& p,
87 )
88 :
90  outTempType_(outputTemperatureType::WALL),
91  refTempType_(refTemperatureType::CELL),
92  Tref_(nullptr)
93 {}
94 
95 
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 
114 (
115  const fvPatch& p,
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  {
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  {
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 
176 (
177  const externalCoupledTemperatureMixedFvPatchScalarField& rhs
178 )
179 :
180  externalCoupledMixedFvPatchField<scalar>(rhs),
181  outTempType_(rhs.outTempType_),
182  refTempType_(rhs.refTempType_),
183  Tref_(rhs.Tref_.clone())
184 {}
185 
186 
189 (
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 
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  (
218  (
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 
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 
330 (
331  Ostream& os
332 ) const
333 {
335  os.writeEntry
336  (
337  "outputTemperature",
338  outputTemperatureNames[outTempType_]
339  );
340  os.writeEntry
341  (
342  "htcRefTemperature",
343  refTemperatureNames[refTempType_]
344  );
345 
346  if (Tref_)
347  {
348  Tref_->writeData(os);
349  }
350 }
351 
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 namespace Foam
356 {
358  (
360  externalCoupledTemperatureMixedFvPatchScalarField
361  );
362 }
363 
364 
365 // ************************************************************************* //
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: fvPatchField.C:32
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:68
dimensionedScalar sign(const dimensionedScalar &ds)
dictionary dict
Extends the mixed boundary condition with serialisation functions.
const objectRegistry & db() const
The associated objectRegistry.
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:59
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:213
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
externalCoupledTemperatureMixedFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:625
void extrapolateInternal()
Assign the patch field from the internal field.
Definition: fvPatchField.C:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Macros for easy insertion into run-time selection tables.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
virtual Field< scalar > & refValue()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
constexpr const char *const group
Group name for atomic constants.
bool readMixedEntries(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the &#39;refValue&#39;, &#39;refGradient&#39; and &#39;valueFraction&#39; entries into their respective places...
psiReactionThermo & thermo
Definition: createFields.H:28
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
fvPatchField< scalar > fvPatchScalarField
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual scalarField & valueFraction()
A FieldMapper for finite-volume patch fields.
Space [isspace].
Definition: token.H:131
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
This boundary condition provides a temperatue interface to an external application.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
virtual void write(Ostream &) const
Write.
volScalarField & p
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
virtual Field< scalar > & refGrad()
Namespace for OpenFOAM.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127