Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
Henry Weller
committed
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "externalWallHeatFluxTemperatureFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
Henry Weller
committed
#include "physicoChemicalConstants.H"
using Foam::constant::physicoChemical::sigma;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
const char*
NamedEnum
<
externalWallHeatFluxTemperatureFvPatchScalarField::operationMode,
3
>::names[] =
{
Henry Weller
committed
"power",
"flux",
"coefficient"
Henry Weller
committed
}
const Foam::NamedEnum
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::operationMode,
3
> Foam::externalWallHeatFluxTemperatureFvPatchScalarField::operationModeNames;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::
externalWallHeatFluxTemperatureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase(patch(), "undefined", "undefined", "undefined-K"),
Henry Weller
committed
mode_(fixedHeatFlux),
Q_(0),
Henry Weller
committed
relaxation_(1),
emissivity_(0),
Henry Weller
committed
qrRelaxation_(1),
qrName_("undefined-qr"),
Sergio Ferraris
committed
thicknessLayers_(),
kappaLayers_()
Henry Weller
committed
refValue() = 0;
refGrad() = 0;
valueFraction() = 1;
}
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::
externalWallHeatFluxTemperatureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase(patch(), dict),
Henry Weller
committed
mode_(operationModeNames.read(dict.lookup("mode"))),
Q_(0),
Henry Weller
committed
relaxation_(dict.lookupOrDefault<scalar>("relaxation", 1)),
emissivity_(dict.lookupOrDefault<scalar>("emissivity", 0)),
Henry Weller
committed
qrRelaxation_(dict.lookupOrDefault<scalar>("qrRelaxation", 1)),
qrName_(dict.lookupOrDefault<word>("qr", "none")),
Sergio Ferraris
committed
thicknessLayers_(),
kappaLayers_()
Henry Weller
committed
switch (mode_)
Henry Weller
committed
case fixedPower:
Sergio Ferraris
committed
{
Henry Weller
committed
dict.lookup("Q") >> Q_;
break;
}
case fixedHeatFlux:
{
q_ = scalarField("q", dict, p.size());
break;
}
case fixedHeatTransferCoeff:
{
h_ = scalarField("h", dict, p.size());
Ta_ = scalarField("Ta", dict, p.size());
if (dict.found("thicknessLayers"))
{
dict.lookup("thicknessLayers") >> thicknessLayers_;
dict.lookup("kappaLayers") >> kappaLayers_;
}
break;
Sergio Ferraris
committed
}
}
fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
Henry Weller
committed
if (qrName_ != "none")
Henry
committed
{
Henry Weller
committed
if (dict.found("qrPrevious"))
{
qrPrevious_ = scalarField("qrPrevious", dict, p.size());
}
else
{
qrPrevious_.setSize(p.size(), 0);
}
Henry
committed
}
if (dict.found("refValue"))
{
// Full restart
refValue() = scalarField("refValue", dict, p.size());
refGrad() = scalarField("refGradient", dict, p.size());
valueFraction() = scalarField("valueFraction", dict, p.size());
}
else
{
// Start from user entered data. Assume fixedValue.
refValue() = *this;
Henry Weller
committed
refGrad() = 0;
valueFraction() = 1;
}
}
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::
externalWallHeatFluxTemperatureFvPatchScalarField
(
const externalWallHeatFluxTemperatureFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
mixedFvPatchScalarField(ptf, p, iF, mapper),
temperatureCoupledBase(patch(), ptf),
mode_(ptf.mode_),
Q_(ptf.Q_),
Henry Weller
committed
relaxation_(ptf.relaxation_),
emissivity_(ptf.emissivity_),
Henry Weller
committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
qrRelaxation_(ptf.qrRelaxation_),
qrName_(ptf.qrName_),
thicknessLayers_(ptf.thicknessLayers_),
kappaLayers_(ptf.kappaLayers_)
{
switch (mode_)
{
case fixedPower:
{
break;
}
case fixedHeatFlux:
{
q_.autoMap(mapper);
break;
}
case fixedHeatTransferCoeff:
{
h_.autoMap(mapper);
Ta_.autoMap(mapper);
break;
}
}
if (qrName_ != "none")
{
qrPrevious_.autoMap(mapper);
}
}
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::
externalWallHeatFluxTemperatureFvPatchScalarField
(
const externalWallHeatFluxTemperatureFvPatchScalarField& tppsf
)
:
mixedFvPatchScalarField(tppsf),
temperatureCoupledBase(tppsf),
Henry Weller
committed
Q_(tppsf.Q_),
Sergio Ferraris
committed
Ta_(tppsf.Ta_),
Henry Weller
committed
relaxation_(tppsf.relaxation_),
emissivity_(tppsf.emissivity_),
Henry Weller
committed
qrPrevious_(tppsf.qrPrevious_),
qrRelaxation_(tppsf.qrRelaxation_),
qrName_(tppsf.qrName_),
Sergio Ferraris
committed
thicknessLayers_(tppsf.thicknessLayers_),
kappaLayers_(tppsf.kappaLayers_)
{}
Foam::externalWallHeatFluxTemperatureFvPatchScalarField::
externalWallHeatFluxTemperatureFvPatchScalarField
(
const externalWallHeatFluxTemperatureFvPatchScalarField& tppsf,
const DimensionedField<scalar, volMesh>& iF
)
:
mixedFvPatchScalarField(tppsf, iF),
temperatureCoupledBase(patch(), tppsf),
Henry Weller
committed
Q_(tppsf.Q_),
Sergio Ferraris
committed
Ta_(tppsf.Ta_),
Henry Weller
committed
relaxation_(tppsf.relaxation_),
emissivity_(tppsf.emissivity_),
Henry Weller
committed
qrPrevious_(tppsf.qrPrevious_),
qrRelaxation_(tppsf.qrRelaxation_),
qrName_(tppsf.qrName_),
Sergio Ferraris
committed
thicknessLayers_(tppsf.thicknessLayers_),
kappaLayers_(tppsf.kappaLayers_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::autoMap
(
const fvPatchFieldMapper& m
)
{
mixedFvPatchScalarField::autoMap(m);
Henry Weller
committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
switch (mode_)
{
case fixedPower:
{
break;
}
case fixedHeatFlux:
{
q_.autoMap(m);
break;
}
case fixedHeatTransferCoeff:
{
h_.autoMap(m);
Ta_.autoMap(m);
break;
}
}
if (qrName_ != "none")
{
qrPrevious_.autoMap(m);
}
}
void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::rmap
(
const fvPatchScalarField& ptf,
const labelList& addr
)
{
mixedFvPatchScalarField::rmap(ptf, addr);
const externalWallHeatFluxTemperatureFvPatchScalarField& tiptf =
refCast<const externalWallHeatFluxTemperatureFvPatchScalarField>(ptf);
Henry Weller
committed
switch (mode_)
{
case fixedPower:
{
break;
}
case fixedHeatFlux:
{
q_.rmap(tiptf.q_, addr);
break;
}
case fixedHeatTransferCoeff:
{
h_.rmap(tiptf.h_, addr);
Ta_.rmap(tiptf.Ta_, addr);
break;
}
}
if (qrName_ != "none")
{
qrPrevious_.rmap(tiptf.qrPrevious_, addr);
}
void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::updateCoeffs()
{
if (updated())
{
return;
}
Henry Weller
committed
const scalarField& Tp(*this);
Henry Weller
committed
scalarField qr(Tp.size(), 0);
if (qrName_ != "none")
Henry Weller
committed
qr =
qrRelaxation_
*patch().lookupPatchField<volScalarField, scalar>(qrName_)
+ (1 - qrRelaxation_)*qrPrevious_;
Henry
committed
Henry Weller
committed
qrPrevious_ = qr;
Henry Weller
committed
case fixedPower:
{
refGrad() = (Q_/gSum(patch().magSf()) + qr)/kappa(Tp);
refValue() = 0;
valueFraction() = 0;
break;
}
Henry Weller
committed
refGrad() = (q_ + qr)/kappa(Tp);
refValue() = 0;
valueFraction() = 0;
break;
}
case fixedHeatTransferCoeff:
{
Henry Weller
committed
scalar totalSolidRes = 0;
if (thicknessLayers_.size())
Sergio Ferraris
committed
{
forAll(thicknessLayers_, iLayer)
Sergio Ferraris
committed
{
const scalar l = thicknessLayers_[iLayer];
Henry Weller
committed
if (kappaLayers_[iLayer] > 0)
Sergio Ferraris
committed
{
totalSolidRes += l/kappaLayers_[iLayer];
Sergio Ferraris
committed
}
}
}
Henry Weller
committed
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
scalarField hp(1/(1/h_ + totalSolidRes));
scalarField hpTa(hp*Ta_);
if (emissivity_ > 0)
{
// Evaluate the radiative flux to the environment
// from the surface temperature ...
if (totalSolidRes > 0)
{
// ... including the effect of the solid wall thermal
// resistance
scalarField TpLambda(h_/(h_ + 1/totalSolidRes));
scalarField Ts(TpLambda*Tp + (1 - TpLambda)*Ta_);
scalarField lambdaTa4(pow4((1 - TpLambda)*Ta_));
hp += emissivity_*sigma.value()*(pow4(Ts) - lambdaTa4)/Tp;
hpTa += sigma.value()*(emissivity_*lambdaTa4 + pow4(Ta_));
}
else
{
// ... if there is no solid wall thermal resistance use
// the current wall temperature
hp += emissivity_*sigma.value()*pow3(Tp);
hpTa += sigma.value()*pow4(Ta_);
}
}
const scalarField kappaDeltaCoeffs
(
this->kappa(Tp)*patch().deltaCoeffs()
);
Henry Weller
committed
refGrad() = 0;
Henry Weller
committed
forAll(Tp, i)
{
if (qr[i] < 0)
{
const scalar hpmqr = hp[i] - qr[i]/Tp[i];
refValue()[i] = hpTa[i]/hpmqr;
valueFraction()[i] = hpmqr/(hpmqr + kappaDeltaCoeffs[i]);
}
else
{
refValue()[i] = (hpTa[i] + qr[i])/hp[i];
valueFraction()[i] = hp[i]/(hp[i] + kappaDeltaCoeffs[i]);
}
}
Henry Weller
committed
valueFraction() = relaxation_*valueFraction() + (1 - relaxation_);
refValue() = relaxation_*refValue() + (1 - relaxation_)*Tp;
mixedFvPatchScalarField::updateCoeffs();
if (debug)
{
Henry Weller
committed
const scalar Q = gSum(kappa(Tp)*patch().magSf()*snGrad());
Info<< patch().boundaryMesh().mesh().name() << ':'
<< patch().name() << ':'
<< this->internalField().name() << " :"
<< " heat transfer rate:" << Q
<< " walltemperature "
<< " min:" << gMin(*this)
<< " max:" << gMax(*this)
<< " avg:" << gAverage(*this)
<< endl;
}
}
void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::write
(
Ostream& os
) const
{
Henry Weller
committed
fvPatchScalarField::write(os);
Henry
committed
Henry Weller
committed
os.writeKeyword("mode")
<< operationModeNames[mode_] << token::END_STATEMENT << nl;
temperatureCoupledBase::write(os);
Sergio Ferraris
committed
andy
committed
{
Henry Weller
committed
case fixedPower:
{
os.writeKeyword("Q")
<< Q_ << token::END_STATEMENT << nl;
Henry Weller
committed
break;
}
andy
committed
case fixedHeatFlux:
{
q_.writeEntry("q", os);
Henry Weller
committed
andy
committed
break;
}
case fixedHeatTransferCoeff:
{
h_.writeEntry("h", os);
Ta_.writeEntry("Ta", os);
Henry Weller
committed
Henry Weller
committed
if (relaxation_ < 1)
{
os.writeKeyword("relaxation")
<< relaxation_ << token::END_STATEMENT << nl;
}
if (emissivity_ > 0)
{
os.writeKeyword("emissivity")
<< emissivity_ << token::END_STATEMENT << nl;
}
Henry Weller
committed
if (thicknessLayers_.size())
{
thicknessLayers_.writeEntry("thicknessLayers", os);
kappaLayers_.writeEntry("kappaLayers", os);
}
andy
committed
break;
}
}
Henry Weller
committed
os.writeKeyword("qr")<< qrName_ << token::END_STATEMENT << nl;
if (qrName_ != "none")
{
os.writeKeyword("qrRelaxation")
<< qrRelaxation_ << token::END_STATEMENT << nl;
Henry Weller
committed
qrPrevious_.writeEntry("qrPrevious", os);
Henry Weller
committed
}
refValue().writeEntry("refValue", os);
refGrad().writeEntry("refGradient", os);
valueFraction().writeEntry("valueFraction", os);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
externalWallHeatFluxTemperatureFvPatchScalarField
);
}
// ************************************************************************* //