STYLE: effectivenessHeatExchangerSource: modernise code

- removed redundant protected scope
- removed undefined 'calculateTotalArea' function
- reordered the constructor list

DOC: effectivenessHeatExchangerSource: improve header documentation
This commit is contained in:
Kutalmis Bercin 2022-03-29 14:39:33 +01:00 committed by Andrew Heather
parent 5bcf9b7997
commit a2959b7586
2 changed files with 165 additions and 165 deletions

View File

@ -75,7 +75,7 @@ void Foam::fv::effectivenessHeatExchangerSource::initialise()
label count = 0; label count = 0;
forAll(fZone, i) forAll(fZone, i)
{ {
label facei = fZone[i]; const label facei = fZone[i];
label faceId = -1; label faceId = -1;
label facePatchId = -1; label facePatchId = -1;
if (mesh_.isInternalFace(facei)) if (mesh_.isInternalFace(facei))
@ -156,8 +156,8 @@ Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource
: :
fv::cellSetOption(name, modelType, dict, mesh), fv::cellSetOption(name, modelType, dict, mesh),
writeFile(mesh, name, modelType, coeffs_), writeFile(mesh, name, modelType, coeffs_),
secondaryMassFlowRate_(0), userPrimaryInletT_(false),
secondaryInletT_(0), targetQdotActive_(false),
secondaryCpPtr_ secondaryCpPtr_
( (
Function1<scalar>::NewIfPresent Function1<scalar>::NewIfPresent
@ -168,13 +168,13 @@ Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource
&mesh &mesh
) )
), ),
primaryInletT_(0),
userPrimaryInletT_(false),
targetQdotActive_(false),
targetQdot_(0),
targetQdotCalcInterval_(5),
targetQdotRelax_(0.5),
eTable_(), eTable_(),
targetQdotCalcInterval_(5),
secondaryMassFlowRate_(0),
secondaryInletT_(0),
primaryInletT_(0),
targetQdot_(0),
targetQdotRelax_(0.5),
UName_("U"), UName_("U"),
TName_("T"), TName_("T"),
phiName_("phi"), phiName_("phi"),
@ -212,12 +212,10 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
) )
{ {
const auto& thermo = mesh_.lookupObject<basicThermo>(basicThermo::dictName); const auto& thermo = mesh_.lookupObject<basicThermo>(basicThermo::dictName);
const auto& phi = mesh_.lookupObject<surfaceScalarField>(phiName_);
const auto& T = mesh_.lookupObject<volScalarField>(TName_);
const surfaceScalarField Cpf(fvc::interpolate(thermo.Cp())); const surfaceScalarField Cpf(fvc::interpolate(thermo.Cp()));
const auto& phi = mesh_.lookupObject<surfaceScalarField>(phiName_);
const auto& T = mesh_.lookupObject<volScalarField>(TName_);
const surfaceScalarField Tf(fvc::interpolate(T)); const surfaceScalarField Tf(fvc::interpolate(T));
scalar sumPhi = 0; scalar sumPhi = 0;
@ -226,29 +224,30 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
scalar primaryInletTfMean = 0; scalar primaryInletTfMean = 0;
forAll(faceId_, i) forAll(faceId_, i)
{ {
label facei = faceId_[i]; const label facei = faceId_[i];
if (facePatchId_[i] != -1) if (facePatchId_[i] != -1)
{ {
label patchi = facePatchId_[i]; const label patchi = facePatchId_[i];
scalar phii = phi.boundaryField()[patchi][facei]*faceSign_[i]; const scalar phii = phi.boundaryField()[patchi][facei]*faceSign_[i];
const scalar magPhii = mag(phii);
sumPhi += phii; sumPhi += phii;
scalar Cpfi = Cpf.boundaryField()[patchi][facei];
scalar Tfi = Tf.boundaryField()[patchi][facei];
scalar magPhii = mag(phii);
sumMagPhi += magPhii; sumMagPhi += magPhii;
const scalar Cpfi = Cpf.boundaryField()[patchi][facei];
const scalar Tfi = Tf.boundaryField()[patchi][facei];
CpfMean += Cpfi*magPhii; CpfMean += Cpfi*magPhii;
primaryInletTfMean += Tfi*magPhii; primaryInletTfMean += Tfi*magPhii;
} }
else else
{ {
scalar phii = phi[facei]*faceSign_[i]; const scalar phii = phi[facei]*faceSign_[i];
scalar magPhii = mag(phii); const scalar magPhii = mag(phii);
sumPhi += phii; sumPhi += phii;
sumMagPhi += magPhii; sumMagPhi += magPhii;
CpfMean += Cpf[facei]*magPhii; CpfMean += Cpf[facei]*magPhii;
primaryInletTfMean += Tf[facei]*magPhii; primaryInletTfMean += Tf[facei]*magPhii;
} }
@ -265,9 +264,9 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
primaryInletT = primaryInletTfMean/(sumMagPhi + ROOTVSMALL); primaryInletT = primaryInletTfMean/(sumMagPhi + ROOTVSMALL);
} }
const scalar alpha = const scalar effectiveness = eTable_()(mag(sumPhi), secondaryMassFlowRate_);
eTable_()(mag(sumPhi), secondaryMassFlowRate_)
*CpfMean*mag(sumPhi); const scalar alpha = effectiveness*CpfMean*mag(sumPhi);
const scalar Qt = alpha*(secondaryInletT_ - primaryInletT); const scalar Qt = alpha*(secondaryInletT_ - primaryInletT);
@ -277,7 +276,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
&& (mesh_.time().timeIndex() % targetQdotCalcInterval_ == 0) && (mesh_.time().timeIndex() % targetQdotCalcInterval_ == 0)
) )
{ {
scalar dT = (targetQdot_ - Qt)/(alpha + ROOTVSMALL); const scalar dT = (targetQdot_ - Qt)/(alpha + ROOTVSMALL);
secondaryInletT_ += targetQdotRelax_*dT; secondaryInletT_ += targetQdotRelax_*dT;
} }
@ -289,7 +288,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
Tref = gMax(TCells); Tref = gMax(TCells);
forAll(deltaTCells, i) forAll(deltaTCells, i)
{ {
deltaTCells[i] = max(Tref - TCells[i], 0.0); deltaTCells[i] = max(Tref - TCells[i], scalar(0));
} }
} }
else else
@ -297,7 +296,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
Tref = gMin(TCells); Tref = gMin(TCells);
forAll(deltaTCells, i) forAll(deltaTCells, i)
{ {
deltaTCells[i] = max(TCells[i] - Tref, 0.0); deltaTCells[i] = max(TCells[i] - Tref, scalar(0));
} }
} }
@ -307,7 +306,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
scalar sumWeight = 0; scalar sumWeight = 0;
forAll(cells_, i) forAll(cells_, i)
{ {
label celli = cells_[i]; const label celli = cells_[i];
sumWeight += V[celli]*mag(U[celli])*deltaTCells[i]; sumWeight += V[celli]*mag(U[celli])*deltaTCells[i];
} }
reduce(sumWeight, sumOp<scalar>()); reduce(sumWeight, sumOp<scalar>());
@ -318,21 +317,21 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
forAll(cells_, i) forAll(cells_, i)
{ {
label celli = cells_[i]; const label celli = cells_[i];
heSource[celli] -= heSource[celli] -=
Qt*V[celli]*mag(U[celli])*deltaTCells[i] Qt*V[celli]*mag(U[celli])*deltaTCells[i]
/(sumWeight + ROOTVSMALL); /(sumWeight + ROOTVSMALL);
} }
} }
Info<< nl Log << nl
<< type() << ": " << name() << nl << incrIndent << type() << ": " << name() << nl << incrIndent
<< indent << "Net mass flux [Kg/s] : " << sumPhi << nl << indent << "Net mass flux [kg/s] : " << sumPhi << nl
<< indent << "Total heat exchange [W] : " << Qt << nl << indent << "Total heat exchange [W] : " << Qt << nl
<< indent << "Secondary inlet T [K] : " << secondaryInletT_ << nl << indent << "Secondary inlet T [K] : " << secondaryInletT_ << nl
<< indent << "Tref [K] : " << Tref << nl << indent << "Tref [K] : " << Tref << nl
<< indent << "Effectiveness : " << indent << "Effectiveness : " << effectiveness
<< eTable_()(mag(sumPhi), secondaryMassFlowRate_) << decrIndent; << decrIndent;
if (Pstream::master()) if (Pstream::master())
{ {
@ -343,7 +342,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
<< tab << Qt << tab << Qt
<< tab << secondaryInletT_ << tab << secondaryInletT_
<< tab << Tref << tab << Tref
<< tab << eTable_()(mag(sumPhi), secondaryMassFlowRate_); << tab << effectiveness;
if (secondaryCpPtr_) if (secondaryCpPtr_)
{ {
@ -352,7 +351,7 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
const scalar secondaryOutletT = const scalar secondaryOutletT =
Qt/(secondaryMassFlowRate_*secondaryCp) + secondaryInletT_; Qt/(secondaryMassFlowRate_*secondaryCp) + secondaryInletT_;
Info<< nl << incrIndent << indent Log << nl << incrIndent << indent
<< "Secondary outlet T [K] : " << secondaryOutletT << "Secondary outlet T [K] : " << secondaryOutletT
<< decrIndent; << decrIndent;
@ -367,55 +366,55 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
bool Foam::fv::effectivenessHeatExchangerSource::read(const dictionary& dict) bool Foam::fv::effectivenessHeatExchangerSource::read(const dictionary& dict)
{ {
if (fv::cellSetOption::read(dict) && writeFile::read(dict)) if (!(fv::cellSetOption::read(dict) && writeFile::read(dict)))
{ {
UName_ = coeffs_.getOrDefault<word>("U", "U"); return false;
TName_ = coeffs_.getOrDefault<word>("T", "T");
phiName_ = coeffs_.getOrDefault<word>("phi", "phi");
coeffs_.readEntry("faceZone", faceZoneName_);
coeffs_.readEntry("secondaryMassFlowRate", secondaryMassFlowRate_);
coeffs_.readEntry("secondaryInletT", secondaryInletT_);
if (coeffs_.readIfPresent("primaryInletT", primaryInletT_))
{
userPrimaryInletT_ = true;
Info<< type() << " " << this->name() << ": " << indent << nl
<< "employing user-specified primary flow inlet temperature: "
<< primaryInletT_ << endl;
}
else
{
Info<< type() << " " << this->name() << ": " << indent << nl
<< "employing flux-weighted primary flow inlet temperature"
<< endl;
}
if (coeffs_.readIfPresent("targetQdot", targetQdot_))
{
targetQdotActive_ = true;
Info<< indent << "employing target heat rejection of "
<< targetQdot_ << nl;
coeffs_.readIfPresent
(
"targetQdotCalcInterval",
targetQdotCalcInterval_
);
Info<< indent << "updating secondary inlet temperature every "
<< targetQdotCalcInterval_ << " iterations" << nl;
coeffs_.readIfPresent("targetQdotRelax", targetQdotRelax_);
Info<< indent << "temperature relaxation: "
<< targetQdotRelax_ << endl;
}
return true;
} }
return false; coeffs_.readEntry("secondaryMassFlowRate", secondaryMassFlowRate_);
coeffs_.readEntry("secondaryInletT", secondaryInletT_);
if (coeffs_.readIfPresent("primaryInletT", primaryInletT_))
{
userPrimaryInletT_ = true;
Info<< type() << " " << this->name() << ": " << indent << nl
<< "employing user-specified primary flow inlet temperature: "
<< primaryInletT_ << endl;
}
else
{
Info<< type() << " " << this->name() << ": " << indent << nl
<< "employing flux-weighted primary flow inlet temperature"
<< endl;
}
if (coeffs_.readIfPresent("targetQdot", targetQdot_))
{
targetQdotActive_ = true;
Info<< indent << "employing target heat rejection of "
<< targetQdot_ << nl;
coeffs_.readIfPresent
(
"targetQdotCalcInterval",
targetQdotCalcInterval_
);
Info<< indent << "updating secondary inlet temperature every "
<< targetQdotCalcInterval_ << " iterations" << nl;
coeffs_.readIfPresent("targetQdotRelax", targetQdotRelax_);
Info<< indent << "temperature relaxation: "
<< targetQdotRelax_ << endl;
}
UName_ = coeffs_.getOrDefault<word>("U", "U");
TName_ = coeffs_.getOrDefault<word>("T", "T");
phiName_ = coeffs_.getOrDefault<word>("phi", "phi");
coeffs_.readEntry("faceZone", faceZoneName_);
return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2017 OpenFOAM Foundation Copyright (C) 2013-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,8 +31,8 @@ Group
grpFvOptionsSources grpFvOptionsSources
Description Description
Heat exchanger source model for compressible flows, in which the heat Heat exchanger source model for compressible flows, where the heat
exchanger is defined as an energy source using a selection of cells. exchanger is modelled as an energy source using a selection of cells.
The total heat exchange source is given by: The total heat exchange source is given by:
\f[ \f[
@ -41,13 +41,13 @@ Description
where: where:
\vartable \vartable
Q_t | total heat source Q_t | Total heat exchange source [J/s]
e(\phi,\dot{m}_2) | effectivenes table e(\phi,\dot{m}_2) | Effectivenes table [-]
\phi | net mass flux entering heat exchanger [kg/s] \phi | Net mass flux entering heat exchanger [kg/s]
\dot{m}_2 | secondary mass flow rate [kg/s] \dot{m}_2 | Secondary flow mass flow rate [kg/s]
T_1 | primary inlet temperature [K] T_1 | Primary flow inlet temperature [K]
T_2 | secondary inlet temperature [K] T_2 | Secondary flow inlet temperature [K]
c_p | specific heat capacity [J/kg/K] c_p | Primary flow specific heat capacity [J/kg/K]
\endvartable \endvartable
@ -58,11 +58,11 @@ Description
where: where:
\vartable \vartable
Q_c | source for cell Q_c | Source for cell
V_c | volume of the cell [m3] V_c | Volume of the cell [m3]
U_c | local cell velocity [m/s] U_c | Local cell velocity [m/s]
T_c | local call temperature [K] T_c | Local cell temperature [K]
T_{ref} | min or max(T) in cell zone depending on the sign of Q_t [K] T_{ref} | Min or max(T) in cell zone depending on the sign of Qt [K]
\endvartable \endvartable
Sources applied to either of the below, if exist: Sources applied to either of the below, if exist:
@ -83,63 +83,69 @@ Usage
\verbatim \verbatim
effectivenessHeatExchangerSource1 effectivenessHeatExchangerSource1
{ {
// Mandatory entries (unmodifiable) // Mandatory entries
type effectivenessHeatExchangerSource; type effectivenessHeatExchangerSource;
// Mandatory entries (runtime modifiable)
faceZone <faceZoneName>; faceZone <faceZoneName>;
secondaryMassFlowRate 1.0; secondaryMassFlowRate <scalar>;
secondaryInletT 336; secondaryInletT <scalar>;
file "effectivenessTable";
outOfBounds clamp; outOfBounds clamp;
file "effTable";
// Optional entries (runtime modifiable) // Optional entries
primaryInletT 293; U <word>;
targetQdot 1500; T <word>;
U <Uname>; phi <word>;
T <Tname>;
phi <phiName>;
// Conditional optional entries (runtime modifiable) // Conditional optional entries
// when the entry "targetQdot" is present // when the total heat exchange is calculated with primary inlet T
targetQdotCalcInterval 1; primaryInletT <scalar>;
targetQdotRelax 1.0;
// Mandatory/Optional (inherited) entries // when the total heat exchange is calculated with a given target
targetQdot <scalar>;
targetQdotCalcInterval <label>;
targetQdotRelax <scalar>;
// when secondary outlet temperature is requested
secondaryCp <Function1<scalar>>;
// Inherited entries
... ...
} }
\endverbatim \endverbatim
where the entries mean: where the entries mean:
\table \table
Property | Description | Type | Reqd | Dflt Property | Description | Type | Reqd | Deflt
type | Type name: effectivenessHeatExchangerSource <!-- type | Type name: effectivenessHeatExchangerSource <!--
--> | word | yes | - --> | word | yes | -
secondaryMassFlowRate | Secondary flow mass rate [kg/s] <!-- secondaryMassFlowRate | Secondary flow mass rate [kg/s] <!--
--> | scalar | yes | - --> | scalar | yes | -
secondaryInletT | Inlet secondary temperature [K] <!-- secondaryInletT | Secondary flow inlet temperature [K] <!--
--> | scalar | yes | - --> | scalar | yes | -
faceZone | Name of the faceZone at the heat exchange inlet <!-- faceZone | Name of the faceZone at the heat exchanger inlet <!--
--> | word | yes | - --> | word | yes | -
file | 2D look up table efficiency = function of primary <!-- file | 2D effectiveness table = function of primary <!--
--> and secondary mass flow rates [kg/s] | file | yes | - --> and secondary mass flow rates [kg/s] | file | yes | -
primaryInletT | Primary air temperature at the heat exchanger inlet <!-- primaryInletT | Primary flow temperature at the heat exchanger inlet <!--
--> | scalar | no | - --> | scalar | no | -
targetQdot | Target heat rejection | scalar | no | - targetQdot | Target heat rejection | scalar | no | -
targetQdotCalcInterval | Target heat rejection calculation interval <!-- targetQdotCalcInterval | Target heat rejection calculation interval <!--
--> | label | no | - --> | label | no | -
targetQdotRelax | Target heat rejection temperature <!-- targetQdotRelax | Target heat rejection temperature <!--
--> under-relaxation coefficient | scalar | no | - --> under-relaxation coefficient | scalar | no | -
U | Name of operand velocity field | word | no | U secondaryCp | Secondary flow specific heat capacity <!--
T | Name of operand temperature field | word | no | T --> | Function1\<scalar\> | no | -
phi | Name of operand flux field | word | no | phi U | Name of operand velocity field | word | no | U
T | Name of operand temperature field | word | no | T
phi | Name of operand flux field | word | no | phi
\endtable \endtable
The inherited entries are elaborated in: The inherited entries are elaborated in:
- \link fvOption.H \endlink - \link fvOption.H \endlink
- \link cellSetOption.H \endlink - \link cellSetOption.H \endlink
- \link writeFile.H \endlink
- \link Function1.H \endlink
The effectiveness table is described in terms of the primary and secondary The effectiveness table is described in terms of the primary and secondary
mass flow rates. For example, the table: mass flow rates. For example, the table:
@ -185,13 +191,15 @@ Usage
\endverbatim \endverbatim
Note Note
- Primary flow indicates the CFD flow region and
secondary flow the non-CFD-model region.
- The table with name \c file should have the same units as the - The table with name \c file should have the same units as the
secondary mass flow rate and kg/s for \c phi. secondary mass flow rate and kg/s for \c phi.
- \c faceZone is the faces at the inlet of the \c cellZone, it needs to be - \c faceZone is the faces at the inlet of the \c cellZone, it needs to be
created with flip map flags. It is used to integrate the net mass flow created with flip map flags. It is used to integrate the net mass flow
rate into the heat exchanger. rate into the heat exchanger.
- \c primaryInletT sets the primary inlet temperature. If not set, the - \c primaryInletT sets the primary inlet temperature. If not set, the
flux-averaged temperature is used. flux-averaged temperature is used.
SourceFiles SourceFiles
effectivenessHeatExchangerSource.C effectivenessHeatExchangerSource.C
@ -223,73 +231,66 @@ class effectivenessHeatExchangerSource
public fv::cellSetOption, public fv::cellSetOption,
public functionObjects::writeFile public functionObjects::writeFile
{ {
protected: // Private Data
// Protected Data //- Flag to use a user-specified primary flow inlet temperature
//- Secondary flow mass rate [kg/s]
scalar secondaryMassFlowRate_;
//- Inlet secondary temperature [K]
scalar secondaryInletT_;
//- Secondary specific heat capacity [J/kg/K]
autoPtr<Function1<scalar>> secondaryCpPtr_;
//- Primary air temperature at the heat exchanger inlet [K]
scalar primaryInletT_;
//- Flag to use a user-specified primary inlet temperature
bool userPrimaryInletT_; bool userPrimaryInletT_;
//- Flag to use target heat rejection //- Flag to use target heat rejection
bool targetQdotActive_; bool targetQdotActive_;
//- Target heat rejection //- Secondary flow specific heat capacity [J/kg/K]
scalar targetQdot_; autoPtr<Function1<scalar>> secondaryCpPtr_;
//- 2D effectiveness table = function of primary and secondary
//- mass flow rates [kg/s]
autoPtr<interpolation2DTable<scalar>> eTable_;
//- Target heat rejection calculation interval //- Target heat rejection calculation interval
label targetQdotCalcInterval_; label targetQdotCalcInterval_;
//- Secondary flow mass rate [kg/s]
scalar secondaryMassFlowRate_;
//- Secondary flow inlet temperature [K]
scalar secondaryInletT_;
//- Primary flow temperature at the heat exchanger inlet [K]
scalar primaryInletT_;
//- Target heat rejection
scalar targetQdot_;
//- Target heat rejection temperature under-relaxation coefficient //- Target heat rejection temperature under-relaxation coefficient
scalar targetQdotRelax_; scalar targetQdotRelax_;
//- 2D look up table efficiency = function of primary and secondary //- Name of operand velocity field
//- mass flow rates [kg/s]
autoPtr<interpolation2DTable<scalar>> eTable_;
//- Name of velocity field; default = U
word UName_; word UName_;
//- Name of temperature field; default = T //- Name of operand temperature field
word TName_; word TName_;
//- Name of the flux //- Name of operand flux field
word phiName_; word phiName_;
//- Name of the faceZone at the heat exchange inlet //- Name of the faceZone at the heat exchanger inlet
word faceZoneName_; word faceZoneName_;
//- Local list of face IDs //- Local list of face IDs
labelList faceId_; labelList faceId_;
//- Local list of patch ID per face //- Local list of patch IDs per face
labelList facePatchId_; labelList facePatchId_;
//- List of +1/-1 representing face flip map (1 use as is, -1 negate) //- List of +1/-1 representing face flip map (1 use as is, -1 negate)
labelList faceSign_; labelList faceSign_;
private:
// Private Member Functions // Private Member Functions
//- Initialise heat exchanger source model //- Initialise heat exchanger source model
void initialise(); void initialise();
//- Calculate total area of faceZone across processors
void calculateTotalArea(scalar& area);
//- Output file header information //- Output file header information
virtual void writeFileHeader(Ostream& os); virtual void writeFileHeader(Ostream& os);
@ -347,7 +348,7 @@ public:
); );
// IO // I-O
//- Read dictionary //- Read dictionary
virtual bool read(const dictionary& dict); virtual bool read(const dictionary& dict);