ENH: effectivenessHeatExchangerSource - calculate upstream average temperature by default

This commit is contained in:
Andrew Heather
2016-10-26 15:54:03 +01:00
parent e24917a7af
commit 5488298771
2 changed files with 102 additions and 77 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -52,7 +52,18 @@ namespace fv
void Foam::fv::effectivenessHeatExchangerSource::initialise() void Foam::fv::effectivenessHeatExchangerSource::initialise()
{ {
const faceZone& fZone = mesh_.faceZones()[zoneID_]; const label zoneID = mesh_.faceZones().findZoneID(faceZoneName_);
if (zoneID < 0)
{
FatalErrorInFunction
<< type() << " " << this->name() << ": "
<< " Unknown face zone name: " << faceZoneName_
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< nl << exit(FatalError);
}
const faceZone& fZone = mesh_.faceZones()[zoneID];
faceId_.setSize(fZone.size()); faceId_.setSize(fZone.size());
facePatchId_.setSize(fZone.size()); facePatchId_.setSize(fZone.size());
@ -113,31 +124,6 @@ void Foam::fv::effectivenessHeatExchangerSource::initialise()
faceId_.setSize(count); faceId_.setSize(count);
facePatchId_.setSize(count); facePatchId_.setSize(count);
faceSign_.setSize(count); faceSign_.setSize(count);
calculateTotalArea(faceZoneArea_);
}
void Foam::fv::effectivenessHeatExchangerSource::calculateTotalArea
(
scalar& area
)
{
area = 0;
forAll(faceId_, i)
{
label faceI = faceId_[i];
if (facePatchId_[i] != -1)
{
label patchI = facePatchId_[i];
area += mesh_.magSf().boundaryField()[patchI][faceI];
}
else
{
area += mesh_.magSf()[faceI];
}
}
reduce(area, sumOp<scalar>());
} }
@ -152,28 +138,20 @@ Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource
) )
: :
cellSetOption(name, modelType, dict, mesh), cellSetOption(name, modelType, dict, mesh),
secondaryMassFlowRate_(readScalar(coeffs_.lookup("secondaryMassFlowRate"))), secondaryMassFlowRate_(0),
secondaryInletT_(readScalar(coeffs_.lookup("secondaryInletT"))), secondaryInletT_(0),
primaryInletT_(readScalar(coeffs_.lookup("primaryInletT"))), primaryInletT_(0),
userPrimaryInletT_(false),
eTable_(), eTable_(),
UName_(coeffs_.lookupOrDefault<word>("UName", "U")), UName_("U"),
TName_(coeffs_.lookupOrDefault<word>("TName", "T")), TName_("T"),
phiName_(coeffs_.lookupOrDefault<word>("phiName", "phi")), phiName_("phi"),
faceZoneName_(coeffs_.lookup("faceZone")), faceZoneName_("unknown-faceZone"),
zoneID_(mesh_.faceZones().findZoneID(faceZoneName_)),
faceId_(), faceId_(),
facePatchId_(), facePatchId_(),
faceSign_(), faceSign_()
faceZoneArea_(0)
{ {
if (zoneID_ < 0) read(dict);
{
FatalErrorInFunction
<< type() << " " << this->name() << ": "
<< " Unknown face zone name: " << faceZoneName_
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< nl << exit(FatalError);
}
// Set the field name to that of the energy field from which the temperature // Set the field name to that of the energy field from which the temperature
// is obtained // is obtained
@ -208,35 +186,61 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
const surfaceScalarField& phi = const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_); mesh_.lookupObject<surfaceScalarField>(phiName_);
scalar totalphi = 0; const volScalarField& T = mesh_.lookupObject<volScalarField>(TName_);
const surfaceScalarField Tf(fvc::interpolate(T));
scalar sumPhi = 0;
scalar sumMagPhi = 0;
scalar CpfMean = 0; scalar CpfMean = 0;
scalar primaryInletTfMean = 0;
forAll(faceId_, i) forAll(faceId_, i)
{ {
label faceI = faceId_[i]; label facei = faceId_[i];
if (facePatchId_[i] != -1) if (facePatchId_[i] != -1)
{ {
label patchI = facePatchId_[i]; label patchi = facePatchId_[i];
totalphi += phi.boundaryField()[patchI][faceI]*faceSign_[i]; scalar phii = phi.boundaryField()[patchi][facei]*faceSign_[i];
CpfMean += sumPhi += phii;
Cpf.boundaryField()[patchI][faceI]
*mesh_.magSf().boundaryField()[patchI][faceI]; scalar Cpfi = Cpf.boundaryField()[patchi][facei];
scalar Tfi = Tf.boundaryField()[patchi][facei];
scalar magPhii = mag(phii);
sumMagPhi += magPhii;
CpfMean += Cpfi*magPhii;
primaryInletTfMean += Tfi*magPhii;
} }
else else
{ {
totalphi += phi[faceI]*faceSign_[i]; scalar phii = phi[facei]*faceSign_[i];
CpfMean += Cpf[faceI]*mesh_.magSf()[faceI]; scalar magPhii = mag(phii);
sumPhi += phii;
sumMagPhi += magPhii;
CpfMean += Cpf[facei]*magPhii;
primaryInletTfMean += Tf[facei]*magPhii;
} }
} }
reduce(CpfMean, sumOp<scalar>()); reduce(CpfMean, sumOp<scalar>());
reduce(totalphi, sumOp<scalar>()); reduce(sumPhi, sumOp<scalar>());
reduce(sumMagPhi, sumOp<scalar>());
reduce(primaryInletTfMean, sumOp<scalar>());
primaryInletTfMean /= sumMagPhi;
CpfMean /= sumMagPhi;
scalar primaryInletT = primaryInletT_;
if (!userPrimaryInletT_)
{
primaryInletT = primaryInletTfMean;
}
scalar Qt = scalar Qt =
eTable_()(mag(totalphi), secondaryMassFlowRate_) eTable_()(mag(sumPhi), secondaryMassFlowRate_)
*(secondaryInletT_ - primaryInletT_) *(secondaryInletT_ - primaryInletT)
*(CpfMean/faceZoneArea_)*mag(totalphi); *CpfMean*mag(sumPhi);
const volScalarField& T = mesh_.lookupObject<volScalarField>(TName_);
const scalarField TCells(T, cells_); const scalarField TCells(T, cells_);
scalar Tref = 0; scalar Tref = 0;
if (Qt > 0) if (Qt > 0)
@ -268,7 +272,8 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
scalar sumWeight = 0; scalar sumWeight = 0;
forAll(cells_, i) forAll(cells_, i)
{ {
sumWeight += V[cells_[i]]*mag(U[cells_[i]])*deltaTCells[i]; label celli = cells_[i];
sumWeight += V[celli]*mag(U[celli])*deltaTCells[i];
} }
reduce(sumWeight, sumOp<scalar>()); reduce(sumWeight, sumOp<scalar>());
@ -278,18 +283,19 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup
forAll(cells_, i) forAll(cells_, i)
{ {
heSource[cells_[i]] -= label celli = cells_[i];
Qt*V[cells_[i]]*mag(U[cells_[i]])*deltaTCells[i]/sumWeight; heSource[celli] -=
Qt*V[celli]*mag(U[celli])*deltaTCells[i]/sumWeight;
} }
} }
if (debug && Pstream::master()) if (debug && Pstream::master())
{ {
Info<< indent << "Net mass flux [Kg/s] = " << totalphi << nl; Info<< indent << "Net mass flux [Kg/s] : " << sumPhi << nl;
Info<< indent << "Total energy exchange [W] = " << Qt << nl; Info<< indent << "Total energy exchange [W] : " << Qt << nl;
Info<< indent << "Tref [K] = " << Tref << nl; Info<< indent << "Tref [K] : " << Tref << nl;
Info<< indent << "Efficiency : " Info<< indent << "Efficiency : "
<< eTable_()(mag(totalphi), secondaryMassFlowRate_) << endl; << eTable_()(mag(sumPhi), secondaryMassFlowRate_) << endl;
} }
} }
@ -298,9 +304,28 @@ bool Foam::fv::effectivenessHeatExchangerSource::read(const dictionary& dict)
{ {
if (cellSetOption::read(dict)) if (cellSetOption::read(dict))
{ {
UName_ = coeffs_.lookupOrDefault<word>("UName", "U");
TName_ = coeffs_.lookupOrDefault<word>("TName", "T");
phiName_ = coeffs_.lookupOrDefault<word>("phiName", "phi");
coeffs_.lookup("faceZone") >> faceZoneName_;
coeffs_.lookup("secondaryMassFlowRate") >> secondaryMassFlowRate_; coeffs_.lookup("secondaryMassFlowRate") >> secondaryMassFlowRate_;
coeffs_.lookup("secondaryInletT") >> secondaryInletT_; coeffs_.lookup("secondaryInletT") >> secondaryInletT_;
coeffs_.lookup("primaryInletT") >> primaryInletT_;
if (coeffs_.readIfPresent("primaryInletT", primaryInletT_))
{
Info<< type() << " " << this->name() << ": "
<< "employing user-specified primary flow inlet temperature: "
<< primaryInletT_ << endl;
userPrimaryInletT_ = true;
}
else
{
Info<< type() << " " << this->name() << ": "
<< "employing flux-weighted primary flow inlet temperature"
<< endl;
}
return true; return true;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -78,7 +78,7 @@ Description
secondaryMassFlowRate 1.0; secondaryMassFlowRate 1.0;
secondaryInletT 336; secondaryInletT 336;
primaryInletT 293; // primaryInletT 293; // Constrain to this T if present
faceZone facesZoneInletOriented; faceZone facesZoneInletOriented;
outOfBounds clamp; outOfBounds clamp;
fileName "effTable"; fileName "effTable";
@ -89,16 +89,19 @@ Description
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:
\verbatim
secondary MFR secondary MFR
| 0.1 0.2 0.3 | 0.1 0.2 0.3
-----+----------------- -----+-----------------
0.02 | A B C 0.02 | A B C
primary MFR 0.04 | D E F primary MFR 0.04 | D E F
0.06 | G H I 0.06 | G H I
\endverbatim
Is specified by the following: Is specified by the following:
\verbatim
( (
0.02 0.02
( (
@ -119,7 +122,7 @@ Description
(0.3 I) (0.3 I)
) )
); );
\endverbatim
Note Note
- the table with name "fileName" should have the same units as the - the table with name "fileName" should have the same units as the
@ -170,6 +173,9 @@ protected:
//- Primary air temperature at the heat exchanger inlet [K] //- Primary air temperature at the heat exchanger inlet [K]
scalar primaryInletT_; scalar primaryInletT_;
//- Flag to use a user-specified primary inlet temperature
bool userPrimaryInletT_;
//- 2D look up table efficiency = function of primary and secondary //- 2D look up table efficiency = function of primary and secondary
// mass flow rates [kg/s] // mass flow rates [kg/s]
autoPtr<interpolation2DTable<scalar>> eTable_; autoPtr<interpolation2DTable<scalar>> eTable_;
@ -186,9 +192,6 @@ protected:
//- Name of the faceZone at the heat exchange inlet //- Name of the faceZone at the heat exchange inlet
word faceZoneName_; word faceZoneName_;
//- Id for the face zone
label zoneID_;
//- Local list of face IDs //- Local list of face IDs
labelList faceId_; labelList faceId_;
@ -198,9 +201,6 @@ protected:
//- 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_;
//- Area of the face zone
scalar faceZoneArea_;
private: private: