temperatureCoupledBase.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2022 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
30#include "volFields.H"
31#include "fluidThermo.H"
32#include "solidThermo.H"
35
36// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
37
38const Foam::Enum
39<
41>
43{
44 { KMethodType::mtFluidThermo, "fluidThermo" },
45 { KMethodType::mtSolidThermo, "solidThermo" },
46 { KMethodType::mtDirectionalSolidThermo, "directionalSolidThermo" },
47 { KMethodType::mtLookup, "lookup" },
48 { KMethodType::mtFunction, "function" }
49};
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
55(
56 const fvPatch& patch,
57 const word& calculationType,
58 const word& kappaName,
59 const word& alphaAniName,
60 const word& alphaName
61)
62:
63 patch_(patch),
64 method_(KMethodTypeNames_[calculationType]),
65 kappaName_(kappaName),
66 alphaAniName_(alphaAniName),
67 alphaName_(alphaName)
68{}
69
70
72(
73 const fvPatch& patch,
74 const dictionary& dict
75)
76:
77 patch_(patch),
78 method_(KMethodTypeNames_.get("kappaMethod", dict)),
79 kappaName_(dict.getOrDefault<word>("kappa", word::null)),
80 alphaAniName_(dict.getOrDefault<word>("alphaAni", word::null)),
81 alphaName_(dict.getOrDefault<word>("alpha", word::null))
82{
83 switch (method_)
84 {
86 {
87 if (!dict.found("alphaAni"))
88 {
90 << "Did not find entry 'alphaAni'"
91 " required for 'kappaMethod' "
94 }
95
96 break;
97 }
98
99 case mtLookup:
100 {
101 if (!dict.found("kappa"))
102 {
104 << "Did not find entry 'kappa'"
105 " required for 'kappaMethod' "
107 << " Please set 'kappa' to the name of a volScalarField"
108 " or volSymmTensorField"
109 << exit(FatalIOError);
110 }
111
112 break;
113 }
114
115 case mtFunction:
116 {
118 (
119 patch.patch(),
120 "kappaValue",
121 dict
122 );
124 (
125 patch.patch(),
126 "alphaValue",
127 dict
128 );
129 }
130
131 default:
132 {
133 break;
134 }
135 }
136}
137
138
140(
141 const temperatureCoupledBase& base
142)
143:
144 patch_(base.patch_),
145 method_(base.method_),
146 kappaName_(base.kappaName_),
147 alphaAniName_(base.alphaAniName_),
148 alphaName_(base.alphaName_),
149 kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
150 alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
151{}
152
153
155(
156 const fvPatch& patch,
157 const temperatureCoupledBase& base
158)
159:
160 patch_(patch),
161 method_(base.method_),
162 kappaName_(base.kappaName_),
163 alphaAniName_(base.alphaAniName_),
164 alphaName_(base.alphaName_),
165 kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
166 alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
167{}
168
169
170// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171
173(
174 const fvPatchFieldMapper& mapper
175)
176{
177 if (kappaFunction1_)
178 {
179 kappaFunction1_().autoMap(mapper);
180 }
181 if (alphaFunction1_)
182 {
183 alphaFunction1_().autoMap(mapper);
184 }
185}
186
187
189(
190 const fvPatchField<scalar>& ptf,
191 const labelList& addr
192)
193{
194 const auto* tcb = isA<temperatureCoupledBase>(ptf);
195
196 if (tcb)
197 {
198 if (kappaFunction1_)
199 {
200 kappaFunction1_().rmap(tcb->kappaFunction1_(), addr);
201 }
202 if (alphaFunction1_)
203 {
204 alphaFunction1_().rmap(tcb->alphaFunction1_(), addr);
205 }
206 }
207}
208
209
211(
212 const scalarField& Tp
213) const
214{
215 const fvMesh& mesh = patch_.boundaryMesh().mesh();
216 const label patchi = patch_.index();
217
218 switch (method_)
219 {
220 case mtFluidThermo:
221 {
223
224 {
225 const auto* ptr =
227 (
229 );
230
231 if (ptr)
232 {
233 return ptr->kappaEff(patchi);
234 }
235 }
236
237 {
238 const auto* ptr =
240
241 if (ptr)
242 {
243 return ptr->kappa(patchi);
244 }
245 }
246
247 {
248 const auto* ptr =
250
251 if (ptr)
252 {
253 return ptr->kappa(patchi);
254 }
255 }
256
257 {
258 const auto* ptr =
260 (
262 );
263
264 if (ptr)
265 {
266 return ptr->kappaEff(patchi);
267 }
268 }
269
271 << "Using kappaMethod " << KMethodTypeNames_[method_]
272 << ", but thermo package not available\n"
273 << exit(FatalError);
274
275 break;
276 }
277
278 case mtSolidThermo:
279 {
280 const solidThermo& thermo =
282
283 return thermo.kappa(patchi);
284 break;
285 }
286
287 case mtDirectionalSolidThermo:
288 {
289 const solidThermo& thermo =
291
292 const symmTensorField& alphaAni =
293 patch_.lookupPatchField<volSymmTensorField, scalar>
294 (
295 alphaAniName_
296 );
297
298 const scalarField& pp = thermo.p().boundaryField()[patchi];
299
300 const symmTensorField kappa(alphaAni*thermo.Cp(pp, Tp, patchi));
301
302 const vectorField n(patch_.nf());
303
304 return n & kappa & n;
305 }
306
307 case mtLookup:
308 {
309 if (mesh.foundObject<volScalarField>(kappaName_))
310 {
311 return patch_.lookupPatchField<volScalarField, scalar>
312 (
313 kappaName_
314 );
315 }
316 else if (mesh.foundObject<volSymmTensorField>(kappaName_))
317 {
318 const symmTensorField& KWall =
319 patch_.lookupPatchField<volSymmTensorField, scalar>
320 (
321 kappaName_
322 );
323
324 const vectorField n(patch_.nf());
325
326 return n & KWall & n;
327 }
328 else
329 {
331 << "Did not find field " << kappaName_
332 << " on mesh " << mesh.name() << " patch " << patch_.name()
333 << nl
334 << " Please set 'kappa' to the name of a volScalarField"
335 << " or volSymmTensorField."
336 << exit(FatalError);
337 }
338 break;
339 }
340
341 case KMethodType::mtFunction:
342 {
343 const auto& tm = patch_.patch().boundaryMesh().mesh().time();
344 return kappaFunction1_->value(tm.timeOutputValue());
345 break;
346 }
347
348 default:
349 {
351 << "Unimplemented method " << KMethodTypeNames_[method_] << nl
352 << "Please set 'kappaMethod' to one of "
353 << flatOutput(KMethodTypeNames_.sortedToc()) << nl
354 << "and 'kappa' to the name of the volScalar"
355 << " or volSymmTensor field (if kappaMethod=lookup)"
356 << exit(FatalError);
357
358 break;
359 }
360 }
361
362 return scalarField();
363}
364
365
367(
368 const scalarField& Tp
369) const
370{
371 const fvMesh& mesh = patch_.boundaryMesh().mesh();
372 const label patchi = patch_.index();
373
374 switch (method_)
375 {
376 case mtFluidThermo:
377 {
379
380 {
381 const auto* ptr =
383 (
385 );
386
387 if (ptr)
388 {
389 return ptr->alphaEff(patchi);
390 }
391 }
392
393 {
394 const auto* ptr =
396
397 if (ptr)
398 {
399 return ptr->alpha(patchi);
400 }
401 }
402
403 {
404 const auto* ptr =
406
407 if (ptr)
408 {
409 return ptr->alpha(patchi);
410 }
411 }
412
413 {
414 const auto* ptr =
415 mesh.cfindObject<basicThermo>("phaseProperties");
416
417 if (ptr)
418 {
419 return ptr->alpha(patchi);
420 }
421 }
422
424 << "Using kappaMethod " << KMethodTypeNames_[method_]
425 << ", but thermo package not available\n"
426 << exit(FatalError);
427
428 break;
429 }
430
431 case mtSolidThermo:
432 {
433 const solidThermo& thermo =
435
436 return thermo.alpha(patchi);
437 break;
438 }
439
440 case mtDirectionalSolidThermo:
441 {
442 const symmTensorField& alphaAni =
443 patch_.lookupPatchField<volSymmTensorField, scalar>
444 (
445 alphaAniName_
446 );
447
448 const vectorField n(patch_.nf());
449
450 return n & alphaAni & n;
451 }
452
453 case mtLookup:
454 {
455 if (mesh.foundObject<volScalarField>(alphaName_))
456 {
457 return
458 patch_.lookupPatchField<volScalarField, scalar>
459 (
460 alphaName_
461 );
462 }
463 else if (mesh.foundObject<volSymmTensorField>(alphaName_))
464 {
465 const symmTensorField& alphaWall =
466 patch_.lookupPatchField<volSymmTensorField, scalar>
467 (
468 alphaName_
469 );
470
471 const vectorField n(patch_.nf());
472
473 return n & alphaWall & n;
474 }
475 else
476 {
478 << "Did not find field " << alphaName_
479 << " on mesh " << mesh.name() << " patch " << patch_.name()
480 << nl
481 << "Please set 'kappaMethod' to one of "
482 << flatOutput(KMethodTypeNames_.sortedToc()) << nl
483 << "and 'alpha' to the name of the volScalar"
484 << " or volSymmTensor field (if kappaMethod=lookup)"
485 << exit(FatalError);
486 }
487
488 break;
489 }
490
491 case KMethodType::mtFunction:
492 {
493 const auto& tm = patch_.patch().boundaryMesh().mesh().time();
494 return alphaFunction1_->value(tm.timeOutputValue());
495 break;
496 }
497
498 default:
499 {
501 << "Unimplemented method " << KMethodTypeNames_[method_] << nl
502 << "Please set 'kappaMethod' to one of "
503 << flatOutput(KMethodTypeNames_.sortedToc()) << nl
504 << "and 'alpha' to the name of the volScalar"
505 << " or volSymmTensor field (if kappaMethod=lookup)"
506 << exit(FatalError);
507
508 break;
509 }
510 }
511
512 return scalarField();
513}
514
515
517{
518 os.writeEntry("kappaMethod", KMethodTypeNames_[method_]);
519 if (!kappaName_.empty())
520 {
521 os.writeEntry("kappa", kappaName_);
522 }
523 if (!alphaAniName_.empty())
524 {
525 os.writeEntry("alphaAni", alphaAniName_);
526 }
527 if (!alphaName_.empty())
528 {
529 os.writeEntry("alpha", alphaName_);
530 }
531 if (kappaFunction1_)
532 {
533 kappaFunction1_->writeData(os);
534 }
535 if (alphaFunction1_)
536 {
537 alphaFunction1_->writeData(os);
538 }
539}
540
541
542// ************************************************************************* //
label n
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
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
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:66
virtual tmp< volScalarField > kappa() const =0
Thermal diffusivity for temperature of mixture [J/m/s/K].
static const word dictName
Definition: basicThermo.H:256
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:634
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
Fundamental fluid thermodynamic properties.
Definition: fluidThermo.H:56
virtual bool write()
Write the output fields.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const word & name() const
Return reference to name.
Definition: fvMesh.H:310
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
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
static const word phasePropertiesName
Default name of the phase properties dictionary.
virtual tmp< volScalarField > kappaEff(const volScalarField &kappat) const
Effective thermal diffusivity for temperature.
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
const Type & lookupObject(const word &name, const bool recursive=false) const
const polyMesh & mesh() const noexcept
Return the mesh reference.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
Fundamental solid thermodynamic properties.
Definition: solidThermo.H:55
Common functions used in temperature coupled boundaries.
autoPtr< PatchFunction1< scalar > > alphaFunction1_
Function1 for alpha.
virtual void autoMap(const fvPatchFieldMapper &)=0
Map (and resize as needed) from self given a mapping object.
KMethodType
Type of supplied Kappa.
virtual void rmap(const fvPatchField< scalar > &, const labelList &)=0
Reverse map the given fvPatchField onto this fvPatchField.
static const Enum< KMethodType > KMethodTypeNames_
const KMethodType method_
How to get K.
autoPtr< PatchFunction1< scalar > > kappaFunction1_
Function1 for kappa.
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
Abstract base class for turbulence models (RAS, LES and laminar).
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:82
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
IOerror FatalIOError
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:86
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