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-2020 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 :
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)
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);
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  {
174  fvPatchField<scalar>::operator=(this->patchInternalField());
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 
187 (
189 )
190 :
192  outTempType_(rhs.outTempType_),
193  refTempType_(rhs.refTempType_),
194  Tref_(rhs.Tref_.clone())
195 {}
196 
197 
200 (
203 )
204 :
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  (
228  IOobject::groupName
229  (
230  turbulenceModel::propertiesName,
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 {
348  os.writeEntry
349  (
350  "outputTemperature",
351  outputTemperatureNames[outTempType_]
352  );
353  os.writeEntry
354  (
355  "htcRefTemperature",
356  refTemperatureNames[refTempType_]
357  );
358 
359  if (Tref_)
360  {
361  Tref_->writeData(os);
362  }
363 }
364 
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 namespace Foam
369 {
371  (
374  );
375 }
376 
377 
378 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFields.H
Foam::fvPatchField::snGrad
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:217
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Foam::constant::atomic::group
constexpr const char *const group
Group name for atomic constants.
Definition: atomicConstants.H:52
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
virtual void writeData(Ostream &os) const
Write data.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:215
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
fvPatchFieldMapper.H
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::externalCoupledMixedFvPatchField< scalar >
Foam::Field< scalar >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:217
Foam::externalCoupledTemperatureMixedFvPatchScalarField::write
virtual void write(Ostream &os) const
Write.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:343
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
externalCoupledTemperatureMixedFvPatchScalarField.H
Foam::externalCoupledTemperatureMixedFvPatchScalarField::readData
virtual void readData(Istream &is)
Read data.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:319
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
Foam::externalCoupledTemperatureMixedFvPatchScalarField::externalCoupledTemperatureMixedFvPatchScalarField
externalCoupledTemperatureMixedFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:84
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeHeader
virtual void writeHeader(Ostream &os) const
Write header.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:65
Foam::line
A line primitive.
Definition: line.H:59
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::externalCoupledTemperatureMixedFvPatchScalarField
This boundary condition provides a temperatue interface to an external application.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.H:149
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::makePatchTypeField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
turbulentFluidThermoModel.H
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Enum.H