Newer
Older
Henry Weller
committed
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "temperatureCoupledBase.H"
#include "volFields.H"
andy
committed
#include "fluidThermo.H"
#include "solidThermo.H"
#include "turbulentFluidThermoModel.H"
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
const Foam::Enum
<
Foam::temperatureCoupledBase::KMethodType
>
Foam::temperatureCoupledBase::KMethodTypeNames_
{ KMethodType::mtFluidThermo, "fluidThermo" },
{ KMethodType::mtSolidThermo, "solidThermo" },
{ KMethodType::mtDirectionalSolidThermo, "directionalSolidThermo" },
{ KMethodType::mtLookup, "lookup" },
{ KMethodType::mtFunction, "function" }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const fvPatch& patch,
const word& calculationType,
const word& kappaName,
const word& alphaAniName,
const word& alphaName
)
:
patch_(patch),
method_(KMethodTypeNames_[calculationType]),
kappaName_(kappaName),
alphaAniName_(alphaAniName),
alphaName_(alphaName)
{}
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const fvPatch& patch,
const dictionary& dict
)
:
patch_(patch),
method_(KMethodTypeNames_.get("kappaMethod", dict)),
kappaName_(dict.getOrDefault<word>("kappa", word::null)),
alphaAniName_(dict.getOrDefault<word>("alphaAni", word::null)),
alphaName_(dict.getOrDefault<word>("alpha", word::null))
Henry Weller
committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
switch (method_)
{
case mtDirectionalSolidThermo:
{
if (!dict.found("alphaAni"))
{
FatalIOErrorInFunction(dict)
<< "Did not find entry 'alphaAni'"
" required for 'kappaMethod' "
<< KMethodTypeNames_[method_]
<< exit(FatalIOError);
}
break;
}
case mtLookup:
{
if (!dict.found("kappa"))
{
FatalIOErrorInFunction(dict)
<< "Did not find entry 'kappa'"
" required for 'kappaMethod' "
<< KMethodTypeNames_[method_] << nl
<< " Please set 'kappa' to the name of a volScalarField"
" or volSymmTensorField"
<< exit(FatalIOError);
}
break;
}
case mtFunction:
{
kappaFunction1_ = PatchFunction1<scalar>::New
(
patch.patch(),
"kappaValue",
dict
);
alphaFunction1_ = PatchFunction1<scalar>::New
(
patch.patch(),
"alphaValue",
dict
);
}
Henry Weller
committed
default:
{
break;
}
}
}
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const temperatureCoupledBase& base
)
:
patch_(base.patch_),
method_(base.method_),
kappaName_(base.kappaName_),
alphaAniName_(base.alphaAniName_),
alphaName_(base.alphaName_),
kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
{}
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const fvPatch& patch,
const temperatureCoupledBase& base
)
:
patch_(patch),
method_(base.method_),
kappaName_(base.kappaName_),
alphaAniName_(base.alphaAniName_),
alphaName_(base.alphaName_),
kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::temperatureCoupledBase::autoMap
(
const fvPatchFieldMapper& mapper
)
{
if (kappaFunction1_)
{
kappaFunction1_().autoMap(mapper);
}
if (alphaFunction1_)
{
alphaFunction1_().autoMap(mapper);
}
}
void Foam::temperatureCoupledBase::rmap
(
const fvPatchField<scalar>& ptf,
const labelList& addr
)
{
const auto* tcb = isA<temperatureCoupledBase>(ptf);
if (tcb)
if (kappaFunction1_)
{
kappaFunction1_().rmap(tcb->kappaFunction1_(), addr);
}
if (alphaFunction1_)
{
alphaFunction1_().rmap(tcb->alphaFunction1_(), addr);
}
Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::kappa
(
const scalarField& Tp
) const
{
const fvMesh& mesh = patch_.boundaryMesh().mesh();
const label patchi = patch_.index();
switch (method_)
{
andy
committed
case mtFluidThermo:
andy
committed
typedef compressible::turbulenceModel turbulenceModel;
{
const auto* ptr =
mesh.cfindObject<turbulenceModel>
(
turbulenceModel::propertiesName
);
andy
committed
if (ptr)
{
return ptr->kappaEff(patchi);
}
andy
committed
}
const auto* ptr =
mesh.cfindObject<fluidThermo>(basicThermo::dictName);
if (ptr)
{
return ptr->kappa(patchi);
}
const auto* ptr =
mesh.cfindObject<basicThermo>(basicThermo::dictName);
if (ptr)
{
return ptr->kappa(patchi);
}
andy
committed
{
const auto* ptr =
mesh.cfindObject<basicThermo>("phaseProperties");
if (ptr)
{
return ptr->kappa(patchi);
}
andy
committed
}
FatalErrorInFunction
<< "Using kappaMethod " << KMethodTypeNames_[method_]
<< ", but thermo package not available\n"
<< exit(FatalError);
andy
committed
break;
andy
committed
case mtSolidThermo:
const solidThermo& thermo =
mesh.lookupObject<solidThermo>(basicThermo::dictName);
andy
committed
return thermo.kappa(patchi);
andy
committed
break;
andy
committed
case mtDirectionalSolidThermo:
const solidThermo& thermo =
mesh.lookupObject<solidThermo>(basicThermo::dictName);
andy
committed
const symmTensorField& alphaAni =
patch_.lookupPatchField<volSymmTensorField, scalar>
(
alphaAniName_
);
const scalarField& pp = thermo.p().boundaryField()[patchi];
const symmTensorField kappa(alphaAni*thermo.Cp(pp, Tp, patchi));
const vectorField n(patch_.nf());
return n & kappa & n;
andy
committed
case mtLookup:
andy
committed
if (mesh.foundObject<volScalarField>(kappaName_))
andy
committed
return patch_.lookupPatchField<volScalarField, scalar>
(
kappaName_
);
andy
committed
else if (mesh.foundObject<volSymmTensorField>(kappaName_))
{
const symmTensorField& KWall =
andy
committed
patch_.lookupPatchField<volSymmTensorField, scalar>
(
kappaName_
);
const vectorField n(patch_.nf());
return n & KWall & n;
}
else
{
<< "Did not find field " << kappaName_
<< " on mesh " << mesh.name() << " patch " << patch_.name()
andy
committed
<< nl
Henry Weller
committed
<< " Please set 'kappa' to the name of a volScalarField"
<< " or volSymmTensorField."
<< exit(FatalError);
}
andy
committed
case KMethodType::mtFunction:
{
const auto& tm = patch_.patch().boundaryMesh().mesh().time();
return kappaFunction1_->value(tm.timeOutputValue());
break;
}
default:
{
FatalErrorInFunction
<< "Unimplemented method " << KMethodTypeNames_[method_] << nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'kappa' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< exit(FatalError);
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
break;
}
}
return scalarField();
}
Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::alpha
(
const scalarField& Tp
) const
{
const fvMesh& mesh = patch_.boundaryMesh().mesh();
const label patchi = patch_.index();
switch (method_)
{
case mtFluidThermo:
{
typedef compressible::turbulenceModel turbulenceModel;
{
const auto* ptr =
mesh.cfindObject<turbulenceModel>
(
turbulenceModel::propertiesName
);
if (ptr)
{
return ptr->alphaEff(patchi);
}
}
{
const auto* ptr =
mesh.cfindObject<fluidThermo>(basicThermo::dictName);
if (ptr)
{
return ptr->alpha(patchi);
}
}
{
const auto* ptr =
mesh.cfindObject<basicThermo>(basicThermo::dictName);
if (ptr)
{
return ptr->alpha(patchi);
}
}
{
const auto* ptr =
mesh.cfindObject<basicThermo>("phaseProperties");
if (ptr)
{
return ptr->alpha(patchi);
}
}
FatalErrorInFunction
<< "Using kappaMethod " << KMethodTypeNames_[method_]
<< ", but thermo package not available\n"
<< exit(FatalError);
break;
}
case mtSolidThermo:
{
const solidThermo& thermo =
mesh.lookupObject<solidThermo>(basicThermo::dictName);
return thermo.alpha(patchi);
break;
}
case mtDirectionalSolidThermo:
{
const symmTensorField& alphaAni =
patch_.lookupPatchField<volSymmTensorField, scalar>
(
alphaAniName_
);
const vectorField n(patch_.nf());
return n & alphaAni & n;
}
case mtLookup:
{
if (mesh.foundObject<volScalarField>(alphaName_))
{
return
patch_.lookupPatchField<volScalarField, scalar>
(
alphaName_
);
}
else if (mesh.foundObject<volSymmTensorField>(alphaName_))
{
const symmTensorField& alphaWall =
patch_.lookupPatchField<volSymmTensorField, scalar>
(
alphaName_
);
const vectorField n(patch_.nf());
return n & alphaWall & n;
}
else
{
FatalErrorInFunction
<< "Did not find field " << alphaName_
<< " on mesh " << mesh.name() << " patch " << patch_.name()
<< nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'alpha' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< exit(FatalError);
}
andy
committed
break;
case KMethodType::mtFunction:
{
const auto& tm = patch_.patch().boundaryMesh().mesh().time();
return alphaFunction1_->value(tm.timeOutputValue());
break;
}
andy
committed
<< "Unimplemented method " << KMethodTypeNames_[method_] << nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'alpha' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< exit(FatalError);
andy
committed
return scalarField();
}
void Foam::temperatureCoupledBase::write(Ostream& os) const
{
os.writeEntry("kappaMethod", KMethodTypeNames_[method_]);
if (!kappaName_.empty())
{
os.writeEntry("kappa", kappaName_);
}
if (!alphaAniName_.empty())
{
os.writeEntry("alphaAni", alphaAniName_);
}
if (!alphaName_.empty())
{
os.writeEntry("alpha", alphaName_);
}
if (kappaFunction1_)
{
kappaFunction1_->writeData(os);
}
if (alphaFunction1_)
{
alphaFunction1_->writeData(os);
}