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-2019 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_(Zero)
93 {}
94 
95 
98 (
100  const fvPatch& p,
102  const fvPatchFieldMapper& mapper
103 )
104 :
106  outTempType_(ptf.outTempType_),
107  refTempType_(ptf.refTempType_),
108  Tref_(ptf.Tref_)
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.lookupOrDefault
126  (
127  "htcRefTemperature",
128  dict,
129  refTemperatureType::CELL
130  )
131  ),
132  Tref_(Zero)
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_ = dict.get<scalar>("Tref");
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_(ecmpf.outTempType_),
193  refTempType_(ecmpf.refTempType_),
194  Tref_(ecmpf.Tref_)
195 {}
196 
197 
200 (
203 )
204 :
206  outTempType_(ecmpf.outTempType_),
207  refTempType_(ecmpf.refTempType_),
208  Tref_(ecmpf.Tref_)
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  tfluid = tmp<scalarField>::New(size(), Tref_);
274  }
275  else
276  {
277  // Near wall cell temperature
278  tfluid = patchInternalField();
279  }
280 
281  const scalarField Tfluid(tfluid);
282 
283 
284  // Heat transfer coefficient [W/m2/K]
285  const scalarField htc(qDot/(max(Twall - Tfluid), 1e-3));
286 
287  const Field<scalar>& magSf = this->patch().magSf();
288 
289  const UList<scalar>& Tout =
290  (
291  outTempType_ == outputTemperatureType::FLUID
292  ? Tfluid
293  : Twall
294  );
295 
296  forAll(patch(), facei)
297  {
298  os << magSf[facei] << token::SPACE
299  << Tout[facei] << token::SPACE
300  << qDot[facei] << token::SPACE
301  << htc[facei] << nl;
302  }
303 }
304 
305 
307 (
308  Istream& is
309 )
310 {
311  // Assume generic input stream so we can do line-based format and skip
312  // unused columns
313  ISstream& iss = dynamic_cast<ISstream&>(is);
314 
315  string line;
316 
317  forAll(*this, facei)
318  {
319  iss.getLine(line);
320  IStringStream lineStr(line);
321 
322  lineStr
323  >> this->refValue()[facei]
324  >> this->refGrad()[facei]
325  >> this->valueFraction()[facei];
326  }
327 }
328 
329 
331 (
332  Ostream& os
333 ) const
334 {
336  os.writeEntry
337  (
338  "outputTemperature",
339  outputTemperatureNames[outTempType_]
340  );
341  os.writeEntry
342  (
343  "htcRefTemperature",
344  refTemperatureNames[refTempType_]
345  );
346 
347  if (refTempType_ == refTemperatureType::USER)
348  {
349  os.writeEntry("Tref", Tref_);
350  }
351 }
352 
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 namespace Foam
357 {
359  (
362  );
363 }
364 
365 
366 // ************************************************************************* //
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:51
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 into a string function.
Definition: ISstreamI.H:78
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
virtual void writeData(Ostream &os) const
Write data.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:215
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
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::constant::atomic::group
const char *const group
Group name for atomic constants.
Definition: atomicConstants.C:41
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
fvPatchFieldMapper.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::externalCoupledMixedFvPatchField< scalar >
Foam::label
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:62
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:63
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
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:112
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::externalCoupledTemperatureMixedFvPatchScalarField::write
virtual void write(Ostream &os) const
Write.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:331
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:355
externalCoupledTemperatureMixedFvPatchScalarField.H
Foam::externalCoupledTemperatureMixedFvPatchScalarField::readData
virtual void readData(Istream &is)
Read data.
Definition: externalCoupledTemperatureMixedFvPatchScalarField.C:307
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
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::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:219
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:145
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:294
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