Commit 38d13f41 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Added new heat transfer coefficient function object

Computes the heat transfer coefficient [W/m2/K] using a run-time
selectable model:
- ReynoldsAnalogy
- fixedReferenceTemperature
- localReferenceTemperature
parent b85a38dc
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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 "heatTransferCoeff.H"
#include "dictionary.H"
#include "heatTransferCoeffModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(heatTransferCoeff, 0);
addToRunTimeSelectionTable(functionObject, heatTransferCoeff, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::heatTransferCoeff::calc()
{
volScalarField& htc = mesh_.lookupObjectRef<volScalarField>(resultName_);
htcModelPtr_->calc(htc);
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::heatTransferCoeff::heatTransferCoeff
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict),
htcModelPtr_()
{
read(dict);
setResultName(typeName, name + ":htc:" + htcModelPtr_->type());
volScalarField* heatTransferCoeffPtr
(
new volScalarField
(
IOobject
(
resultName_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimPower/dimArea/dimTemperature, 0.0)
)
);
mesh_.objectRegistry::store(heatTransferCoeffPtr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::heatTransferCoeff::~heatTransferCoeff()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::heatTransferCoeff::read(const dictionary& dict)
{
if (fieldExpression::read(dict))
{
htcModelPtr_ = heatTransferCoeffModel::New(dict, mesh_, fieldName_);
htcModelPtr_->read(dict);
return true;
}
return false;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Class
Foam::functionObjects::heatTransferCoeff
Group
grpFieldFunctionObjects
Description
This function object calculates and writes the heat transfer coefficient
as a volScalarField for a set of patches.
The field is stored on the mesh database so that it can be retrieved and
used for other applications. Heat transfer coefficient, htc [W/m2/K]
can be evaluated using one of the following modes:
- ReynoldsAnalogy: Reynold's analogy
- localReferenceTemperature: local reference temperature
- fixedReferenceTemperature: specified reference temperature
Usage
Example usage for mode 'ReynoldsAnalogy' for incompressible case
\verbatim
htc
{
type heatTransferCoeff;
libs ("libfieldFunctionObjects.so");
field T;
patches ("walls.*");
htcModel ReynoldsAnalogy;
UInf (20 0 0);
Cp CpInf;
CpInf 1000;
rho rhoInf;
rhoInf 1.2;
}
\endverbatim
Example usage for mode 'ReynoldsAnalogy' for compressible case
\verbatim
htc
{
type heatTransferCoeff;
libs ("libfieldFunctionObjects.so");
field T;
patches ("walls.*");
htcModel ReynoldsAnalogy;
UInf (20 0 0);
}
\endverbatim
Example usage for mode 'localReferenceTemperature' for compressible case
\verbatim
htc
{
type heatTransferCoeff;
libs ("libfieldFunctionObjects.so");
field T;
patches ("walls.*");
htcModel local;
}
\endverbatim
Example usage for mode 'fixedReferenceTemperature' for compressible case
\verbatim
htc
{
type heatTransferCoeff;
libs ("libfieldFunctionObjects.so");
field T;
patches ("walls.*");
htcModel local;
TRef 300;
}
\endverbatim
See also
Foam::functionObjects::fieldExpression
Foam::heatTransferCoeffModels::fixedReferenceTemperature
Foam::heatTransferCoeffModels::localReferenceTemperature
SourceFiles
heatTransferCoeff.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_heatTransferCoeff_H
#define functionObjects_heatTransferCoeff_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class heatTransferCoeffModel;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class heatTransferCoeff Declaration
\*---------------------------------------------------------------------------*/
class heatTransferCoeff
:
public fieldExpression
{
private:
// Private data
//- Heat transfer coefficient model
autoPtr<heatTransferCoeffModel> htcModelPtr_;
// Private Member Functions
//- Disallow default bitwise copy construct
heatTransferCoeff(const heatTransferCoeff&) = delete;
//- Disallow default bitwise assignment
void operator=(const heatTransferCoeff&) = delete;
protected:
//- Calculate the heat transfer coefficient field and return true
// if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("heatTransferCoeff");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
heatTransferCoeff
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~heatTransferCoeff();
// Member Functions
//- Read the heatTransferCoeff data
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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 "ReynoldsAnalogy.H"
#include "fluidThermo.H"
#include "turbulentTransportModel.H"
#include "turbulentFluidThermoModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace heatTransferCoeffModels
{
defineTypeNameAndDebug(ReynoldsAnalogy, 0);
addToRunTimeSelectionTable
(
heatTransferCoeffModel,
ReynoldsAnalogy,
dictionary
);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::heatTransferCoeffModels::ReynoldsAnalogy::rho(const label patchi) const
{
if (rhoName_ == "rhoInf")
{
const label n = mesh_.boundary()[patchi].size();
return tmp<Field<scalar>>(new Field<scalar>(n, rhoRef_));
}
else if (mesh_.foundObject<volScalarField>(rhoName_, false))
{
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);
return rho.boundaryField()[patchi];
}
else
{
FatalErrorInFunction
<< "Unable to set rho for patch " << patchi
<< exit(FatalError);
}
return tmp<Field<scalar>>(nullptr);
}
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::heatTransferCoeffModels::ReynoldsAnalogy::Cp(const label patchi) const
{
if (CpName_ == "CpInf")
{
const label n = mesh_.boundary()[patchi].size();
return tmp<Field<scalar>>(new Field<scalar>(n, CpRef_));
}
else if (mesh_.foundObject<fluidThermo>(fluidThermo::typeName))
{
const fluidThermo& thermo =
mesh_.lookupObject<fluidThermo>(fluidThermo::typeName);
const scalarField& pp = thermo.p().boundaryField()[patchi];
const scalarField& Tp = thermo.T().boundaryField()[patchi];
return thermo.Cp(pp, Tp, patchi);
}
else
{
FatalErrorInFunction
<< "Unable to set Cp for patch " << patchi
<< exit(FatalError);
}
return tmp<Field<scalar>>(nullptr);
}
Foam::tmp<Foam::volSymmTensorField>
Foam::heatTransferCoeffModels::ReynoldsAnalogy::devReff() const
{
typedef compressible::turbulenceModel cmpTurbModel;
typedef incompressible::turbulenceModel icoTurbModel;
if (mesh_.foundObject<cmpTurbModel>(cmpTurbModel::propertiesName))
{
const cmpTurbModel& turb =
mesh_.lookupObject<cmpTurbModel>(cmpTurbModel::propertiesName);
return turb.devRhoReff()/turb.rho();
}
else if (mesh_.foundObject<icoTurbModel>(icoTurbModel::propertiesName))
{
const incompressible::turbulenceModel& turb =
mesh_.lookupObject<icoTurbModel>(icoTurbModel::propertiesName);
return turb.devReff();
}
else if (mesh_.foundObject<fluidThermo>(fluidThermo::dictName))
{
const fluidThermo& thermo =
mesh_.lookupObject<fluidThermo>(fluidThermo::dictName);
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
return -thermo.nu()*dev(twoSymm(fvc::grad(U)));
}
else if (mesh_.foundObject<transportModel>("transportProperties"))
{
const transportModel& laminarT =
mesh_.lookupObject<transportModel>("transportProperties");
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
return -laminarT.nu()*dev(twoSymm(fvc::grad(U)));
}
else if (mesh_.foundObject<dictionary>("transportProperties"))
{
const dictionary& transportProperties =
mesh_.lookupObject<dictionary>("transportProperties");
dimensionedScalar nu(transportProperties.lookup("nu"));
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
return -nu*dev(twoSymm(fvc::grad(U)));
}
else
{
FatalErrorInFunction
<< "No valid model for viscous stress calculation"
<< exit(FatalError);
return volSymmTensorField::null();
}
}
Foam::tmp<Foam::FieldField<Foam::Field, Foam::scalar>>
Foam::heatTransferCoeffModels::ReynoldsAnalogy::Cf() const
{
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
const volVectorField::Boundary& Ubf = U.boundaryField();
tmp<FieldField<Field, scalar>> tCf
(
new FieldField<Field, scalar>(Ubf.size())
);
FieldField<Field, scalar>& Cf = tCf.ref();
forAll(Cf, patchi)
{
Cf.set(patchi, new Field<scalar>(Ubf[patchi].size(), 0));
}
const volSymmTensorField R(devReff());
const volSymmTensorField::Boundary& Rbf = R.boundaryField();
for (label patchi : patchSet_)
{
const fvPatchVectorField& Up = Ubf[patchi];
const symmTensorField& Rp = Rbf[patchi];
const vectorField nHat(Up.patch().nf());
const scalarField tauByRhop(mag(nHat & Rp));
Cf[patchi] = 2*tauByRhop/magSqr(URef_);
}
return tCf;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::heatTransferCoeffModels::ReynoldsAnalogy::ReynoldsAnalogy
(
const dictionary& dict,
const fvMesh& mesh,
const word& TName
)
:
heatTransferCoeffModel(dict, mesh, TName),
UName_("U"),
URef_(vector::zero),
rhoName_("rho"),
rhoRef_(0.0),
CpName_("Cp"),
CpRef_(0.0)
{
read(dict);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::heatTransferCoeffModels::ReynoldsAnalogy::read
(
const dictionary& dict
)
{
if (heatTransferCoeffModel::read(dict))
{
dict.lookup("UInf") >> URef_;
dict.readIfPresent("Cp", CpName_);
if (CpName_ == "CpInf")
{
dict.lookup("CpInf") >> CpRef_;
}
dict.readIfPresent("rho", rhoName_);
if (rhoName_ == "rhoInf")
{
dict.lookup("rhoInf") >> rhoRef_;
}
return true;
}
return false;
}
void Foam::heatTransferCoeffModels::ReynoldsAnalogy::htc(volScalarField& htc)
{
const FieldField<Field, scalar> CfBf(Cf());
const scalar magU = mag(URef_);
volScalarField::Boundary& htcBf = htc.boundaryFieldRef();
forAllConstIters(patchSet_, iter)
{
label patchi = iter.key();
const scalarField rhop(rho(patchi));
const scalarField Cpp(Cp(patchi));
htcBf[patchi] = 0.5*rhop*Cpp*magU*CfBf[patchi];
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |