From df4e94d173fef902b73ee740620b2fe6d3b19d5a Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 13 Nov 2020 16:38:26 +0000 Subject: [PATCH] fvOptions::effectivenessHeatExchangerSource: Updated to use Function2 --- .../interpolation2DTable.C | 436 ------------------ .../interpolation2DTable.H | 174 ------- .../effectivenessHeatExchangerSource.C | 20 +- .../effectivenessHeatExchangerSource.H | 97 ++-- .../constantHeatTransfer.H | 10 +- .../variableHeatTransfer.H | 10 +- 6 files changed, 43 insertions(+), 704 deletions(-) delete mode 100644 src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C delete mode 100644 src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H diff --git a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C deleted file mode 100644 index 76c09514f4..0000000000 --- a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.C +++ /dev/null @@ -1,436 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 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 . - -\*---------------------------------------------------------------------------*/ - -#include "FoamTableReader.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::interpolation2DTable::interpolation2DTable() -: - List>>>(), - boundsHandling_(interpolation2DTable::WARN), - fileName_(fileName::null), - reader_(nullptr) -{} - - -template -Foam::interpolation2DTable::interpolation2DTable -( - const List>>>& values, - const boundsHandling bounds, - const fileName& fName -) -: - List>>>(values), - boundsHandling_(bounds), - fileName_(fName), - reader_(nullptr) -{} - - -template -Foam::interpolation2DTable::interpolation2DTable(const fileName& fName) -: - List>>>(), - boundsHandling_(interpolation2DTable::WARN), - fileName_(fName), - reader_(new TableReaders::Foam(dictionary())) -{ - reader_()(fileName_, *this); - checkOrder(); -} - - -template -Foam::interpolation2DTable::interpolation2DTable(const dictionary& dict) -: - List>>>(), - boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))), - fileName_(dict.lookup("file")), - reader_(new TableReaders::Foam(dictionary())) -{ - reader_()(fileName_, *this); - checkOrder(); -} - - -template -Foam::interpolation2DTable::interpolation2DTable -( - const interpolation2DTable& interpTable -) -: - List>>>(interpTable), - boundsHandling_(interpTable.boundsHandling_), - fileName_(interpTable.fileName_) -{} - - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -Type Foam::interpolation2DTable::interpolateValue -( - const List>& data, - const scalar lookupValue -) const -{ - label n = data.size(); - - scalar minLimit = data.first().first(); - scalar maxLimit = data.last().first(); - - if (lookupValue < minLimit) - { - switch (boundsHandling_) - { - case interpolation2DTable::ERROR: - { - FatalErrorInFunction - << "value (" << lookupValue << ") less than lower " - << "bound (" << minLimit << ")" << nl - << exit(FatalError); - break; - } - case interpolation2DTable::WARN: - { - WarningInFunction - << "value (" << lookupValue << ") less than lower " - << "bound (" << minLimit << ")" << nl - << " Continuing with the first entry" - << endl; - // fall-through to 'CLAMP' - [[fallthrough]]; - } - case interpolation2DTable::CLAMP: - { - return data.first().second(); - break; - } - } - } - else if (lookupValue >= maxLimit) - { - switch (boundsHandling_) - { - case interpolation2DTable::ERROR: - { - FatalErrorInFunction - << "value (" << lookupValue << ") greater than upper " - << "bound (" << maxLimit << ")" << nl - << exit(FatalError); - break; - } - case interpolation2DTable::WARN: - { - WarningInFunction - << "value (" << lookupValue << ") greater than upper " - << "bound (" << maxLimit << ")" << nl - << " Continuing with the last entry" - << endl; - // fall-through to 'CLAMP' - [[fallthrough]]; - } - case interpolation2DTable::CLAMP: - { - return data.last().second(); - break; - } - } - } - - // look for the correct range in X - label lo = 0; - label hi = 0; - - for (label i = 0; i < n; ++i) - { - if (lookupValue >= data[i].first()) - { - lo = hi = i; - } - else - { - hi = i; - break; - } - } - - if (lo == hi) - { - return data[lo].second(); - } - else - { - Type m = - (data[hi].second() - data[lo].second()) - /(data[hi].first() - data[lo].first()); - - // normal interpolation - return data[lo].second() + m*(lookupValue - data[lo].first()); - } -} - - -template -template -Foam::label Foam::interpolation2DTable::Xi -( - const BinaryOp& bop, - const scalar valueX, - const bool reverse -) const -{ - const table& t = *this; - - label limitI = 0; - if (reverse) - { - limitI = t.size() - 1; - } - - if (bop(valueX, t[limitI].first())) - { - switch (boundsHandling_) - { - case interpolation2DTable::ERROR: - { - FatalErrorInFunction - << "value (" << valueX << ") out of bounds" - << exit(FatalError); - break; - } - case interpolation2DTable::WARN: - { - WarningInFunction - << "value (" << valueX << ") out of bounds" - << endl; - // fall-through to 'CLAMP' - [[fallthrough]]; - } - case interpolation2DTable::CLAMP: - { - return limitI; - } - default: - { - FatalErrorInFunction - << "Un-handled enumeration " << boundsHandling_ - << abort(FatalError); - } - } - } - - label i = 0; - if (reverse) - { - label nX = t.size(); - i = 0; - while ((i < nX) && (valueX > t[i].first())) - { - i++; - } - } - else - { - i = t.size() - 1; - while ((i > 0) && (valueX < t[i].first())) - { - i--; - } - } - - return i; -} - - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template -Type Foam::interpolation2DTable::operator() -( - const scalar valueX, - const scalar valueY -) const -{ - // Considers all of the list in Y being equal - label nX = this->size(); - - const table& t = *this; - - if (nX == 0) - { - WarningInFunction - << "cannot interpolate a zero-sized table - returning zero" << endl; - - return Zero; - } - else if (nX == 1) - { - // only 1 column (in X) - interpolate to find Y value - return interpolateValue(t.first().second(), valueY); - } - else - { - // have 2-D data, interpolate - - // find low and high indices in the X range that bound valueX - label x0i = Xi(lessOp(), valueX, false); - label x1i = Xi(greaterOp(), valueX, true); - - if (x0i == x1i) - { - return interpolateValue(t[x0i].second(), valueY); - } - else - { - Type y0(interpolateValue(t[x0i].second(), valueY)); - Type y1(interpolateValue(t[x1i].second(), valueY)); - - // gradient in X - scalar x0 = t[x0i].first(); - scalar x1 = t[x1i].first(); - Type mX = (y1 - y0)/(x1 - x0); - - // interpolate - return y0 + mX*(valueX - x0); - } - } -} - - -template -Foam::word Foam::interpolation2DTable::boundsHandlingToWord -( - const boundsHandling& bound -) const -{ - word enumName("warn"); - - switch (bound) - { - case interpolation2DTable::ERROR: - { - enumName = "error"; - break; - } - case interpolation2DTable::WARN: - { - enumName = "warn"; - break; - } - case interpolation2DTable::CLAMP: - { - enumName = "clamp"; - break; - } - } - - return enumName; -} - - -template -typename Foam::interpolation2DTable::boundsHandling -Foam::interpolation2DTable::wordToBoundsHandling -( - const word& bound -) const -{ - if (bound == "error") - { - return interpolation2DTable::ERROR; - } - else if (bound == "warn") - { - return interpolation2DTable::WARN; - } - else if (bound == "clamp") - { - return interpolation2DTable::CLAMP; - } - else - { - WarningInFunction - << "bad outOfBounds specifier " << bound << " using 'warn'" << endl; - - return interpolation2DTable::WARN; - } -} - - -template -typename Foam::interpolation2DTable::boundsHandling -Foam::interpolation2DTable::outOfBounds -( - const boundsHandling& bound -) -{ - boundsHandling prev = boundsHandling_; - boundsHandling_ = bound; - return prev; -} - - -template -void Foam::interpolation2DTable::checkOrder() const -{ - label n = this->size(); - const table& t = *this; - - scalar prevValue = t[0].first(); - - for (label i=1; i -void Foam::interpolation2DTable::write(Ostream& os) const -{ - writeEntry(os, "file", fileName_); - writeEntry(os, "outOfBounds", boundsHandlingToWord(boundsHandling_)); - reader_.write(os); - - *this >> os; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H b/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H deleted file mode 100644 index ba08dd8fb2..0000000000 --- a/src/OpenFOAM/interpolations/interpolation2DTable/interpolation2DTable.H +++ /dev/null @@ -1,174 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 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 . - -Class - Foam::interpolation2DTable - -Description - 2D table interpolation. The data must be in ascending order in both - dimensions x and y. - -SourceFiles - interpolation2DTable.C - -\*---------------------------------------------------------------------------*/ - -#ifndef interpolation2DTable_H -#define interpolation2DTable_H - -#include "List.H" -#include "Tuple2.H" -#include "TableReader.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class interpolation2DTable Declaration -\*---------------------------------------------------------------------------*/ - -template -class interpolation2DTable -: - public List>>> -{ -public: - - // Public data types - - //- Enumeration for handling out-of-bound values - enum boundsHandling - { - ERROR, //!< Exit with a FatalError - WARN, //!< Issue warning and clamp value (default) - CLAMP //!< Clamp value to the start/end value - }; - - //- Cconvenience typedef - typedef List>>> table; - - -private: - - // Private Data - - //- Enumeration for handling out-of-bound values - boundsHandling boundsHandling_; - - //- File name - fileName fileName_; - - //- The reader - autoPtr> reader_; - - - // Private Member Functions - - //- Return interpolated value in List - Type interpolateValue - ( - const List>& data, - const scalar - ) const; - - //- Return an X index from the matrix - template - label Xi - ( - const BinaryOp& bop, - const scalar valueX, - const bool reverse - ) const; - - -public: - - // Constructors - - //- Construct null - interpolation2DTable(); - - //- Construct from components - interpolation2DTable - ( - const List>>>& values, - const boundsHandling bounds, - const fileName& fName - ); - - //- Construct given the name of the file containing the table of data - interpolation2DTable(const fileName& fName); - - //- Construct by reading the fileName and boundsHandling from dictionary - interpolation2DTable(const dictionary& dict); - - //- Construct copy - interpolation2DTable(const interpolation2DTable& interpTable); - - - // Member Functions - - //- Return the out-of-bounds handling as a word - word boundsHandlingToWord(const boundsHandling& bound) const; - - //- Return the out-of-bounds handling as an enumeration - boundsHandling wordToBoundsHandling(const word& bound) const; - - //- Set the out-of-bounds handling from enum, return previous setting - boundsHandling outOfBounds(const boundsHandling& bound); - - //- Check that list is monotonically increasing - // Exit with a FatalError if there is a problem - void checkOrder() const; - - //- Write - void write(Ostream& os) const; - - - // Member Operators - - //- Return an element of constant Tuple2 - const List>& operator[](const label) const; - - //- Return an interpolated value - Type operator()(const scalar, const scalar) const; -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "interpolation2DTable.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.C b/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.C index 354e6c0bb8..0197418ce3 100644 --- a/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.C +++ b/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.C @@ -24,12 +24,10 @@ License \*---------------------------------------------------------------------------*/ #include "effectivenessHeatExchangerSource.H" -#include "fvMesh.H" #include "fvMatrix.H" -#include "addToRunTimeSelectionTable.H" #include "basicThermo.H" -#include "coupledPolyPatch.H" #include "surfaceInterpolate.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -61,7 +59,7 @@ void Foam::fv::effectivenessHeatExchangerSource::initialise() label count = 0; forAll(fZone, i) { - label facei = fZone[i]; + const label facei = fZone[i]; label faceId = -1; label facePatchId = -1; if (mesh_.isInternalFace(facei)) @@ -126,7 +124,7 @@ void Foam::fv::effectivenessHeatExchangerSource::calculateTotalArea area = 0; forAll(faceId_, i) { - label facei = faceId_[i]; + const label facei = faceId_[i]; if (facePatchId_[i] != -1) { label patchi = facePatchId_[i]; @@ -155,7 +153,7 @@ Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource secondaryMassFlowRate_(coeffs_.lookup("secondaryMassFlowRate")), secondaryInletT_(coeffs_.lookup("secondaryInletT")), primaryInletT_(coeffs_.lookup("primaryInletT")), - eTable_(), + eTable_(Function2::New("effectiveness", coeffs_)), UName_(coeffs_.lookupOrDefault("U", "U")), TName_(coeffs_.lookupOrDefault("T", "T")), phiName_(coeffs_.lookupOrDefault("phi", "phi")), @@ -185,8 +183,6 @@ Foam::fv::effectivenessHeatExchangerSource::effectivenessHeatExchangerSource applied_.setSize(1, false); - eTable_.reset(new interpolation2DTable(coeffs_)); - initialise(); } @@ -231,8 +227,8 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup reduce(CpfMean, sumOp()); reduce(totalphi, sumOp()); - scalar Qt = - eTable_()(mag(totalphi), secondaryMassFlowRate_) + const scalar Qt = + eTable_->value(mag(totalphi), secondaryMassFlowRate_) *(secondaryInletT_ - primaryInletT_) *(CpfMean/faceZoneArea_)*mag(totalphi); @@ -291,8 +287,8 @@ void Foam::fv::effectivenessHeatExchangerSource::addSup Info<< indent << "Net mass flux [Kg/s] = " << totalphi << nl; Info<< indent << "Total energy exchange [W] = " << Qt << nl; Info<< indent << "Tref [K] = " << Tref << nl; - Info<< indent << "Efficiency : " - << eTable_()(mag(totalphi), secondaryMassFlowRate_) << endl; + Info<< indent << "Effectiveness : " + << eTable_->value(mag(totalphi), secondaryMassFlowRate_) << endl; } } diff --git a/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.H b/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.H index bbaf88e750..7fd26ebecd 100644 --- a/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.H +++ b/src/fvOptions/sources/derived/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.H @@ -74,48 +74,18 @@ Usage secondaryInletT 336; primaryInletT 293; faceZone facesZoneInletOriented; - outOfBounds clamp; - file "effTable"; + effectiveness ; } \endverbatim - The effectiveness table is described in terms of the primary and secondary - mass flow rates. For example, the table: - - secondary MFR - | 0.1 0.2 0.3 - -----+----------------- - 0.02 | A B C - primary MFR 0.04 | D E F - 0.06 | G H I - - - Is specified by the following: - - ( - 0.02 - ( - (0.1 A) - (0.2 B) - (0.3 C) - ), - 0.04 - ( - (0.1 D) - (0.2 E) - (0.3 F) - ), - 0.06 - ( - (0.1 G) - (0.2 H) - (0.3 I) - ) - ); + The effectiveness Function2 is described in terms of the primary and + secondary mass flow rates and has the same units as the secondary mass flow + rate and kg/s for phi. Note - - the table with name "file" should have the same units as the - secondary mass flow rate and kg/s for phi + - The effectiveness Function2 is described in terms of the primary and + secondary mass flow rates and has the same units as the secondary mass + flow rate and kg/s for phi. - faceZone is the faces at the inlet of the cellzone, it needs to be created with flip map flags. It is used to integrate the net mass flow rate into the heat exchanger @@ -129,8 +99,7 @@ SourceFiles #define effectivenessHeatExchangerSource_H #include "cellSetOption.H" -#include "autoPtr.H" -#include "interpolation2DTable.H" +#include "Function2.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -161,9 +130,9 @@ protected: //- Primary air temperature at the heat exchanger inlet [K] scalar primaryInletT_; - //- 2D look up table efficiency = function of primary and secondary - // mass flow rates [kg/s] - autoPtr> eTable_; + //- 2D function for effectiveness [kg/s] + // function of primary and secondary mass flow rates [kg/s] + autoPtr> eTable_; //- Name of velocity field; default = U word UName_; @@ -235,34 +204,26 @@ public: // Member Functions - // Explicit and implicit source + //- Explicit and implicit source + virtual void addSup + ( + fvMatrix& eqn, + const label fieldi + ) const + { + NotImplemented; + } - //- Scalar - virtual void addSup - ( - fvMatrix& eqn, - const label fieldi - ) const - { - NotImplemented; - } + //- Explicit and implicit source for compressible equation + virtual void addSup + ( + const volScalarField& rho, + fvMatrix& eqn, + const label fieldi + ) const; - - // Explicit and implicit source for compressible equation - - //- Scalar - virtual void addSup - ( - const volScalarField& rho, - fvMatrix& eqn, - const label fieldi - ) const; - - - // IO - - //- Read dictionary - virtual bool read(const dictionary& dict); + //- Read dictionary + virtual bool read(const dictionary& dict); // Member Operators diff --git a/src/fvOptions/sources/interRegion/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.H b/src/fvOptions/sources/interRegion/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.H index f8cff50a05..fa729637b5 100644 --- a/src/fvOptions/sources/interRegion/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.H +++ b/src/fvOptions/sources/interRegion/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.H @@ -34,7 +34,6 @@ Description #define constantHeatTransfer_H #include "interRegionHeatTransferModel.H" -#include "autoPtr.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -82,16 +81,13 @@ public: virtual ~constantHeatTransfer(); - // Public Functions + // Member Functions //- Calculate the heat transfer coefficient virtual void calculateHtc() const; - - // IO - - //- Read dictionary - virtual bool read(const dictionary& dict); + //- Read dictionary + virtual bool read(const dictionary& dict); }; diff --git a/src/fvOptions/sources/interRegion/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.H b/src/fvOptions/sources/interRegion/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.H index b15edf45b7..eb99c4917c 100644 --- a/src/fvOptions/sources/interRegion/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.H +++ b/src/fvOptions/sources/interRegion/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.H @@ -44,7 +44,6 @@ Description #define variableHeatTransfer_H #include "interRegionHeatTransferModel.H" -#include "autoPtr.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -103,16 +102,13 @@ public: virtual ~variableHeatTransfer(); - // Public Functions + // Member Functions //- Calculate the heat transfer coefficient virtual void calculateHtc() const; - - // IO - - //- Read dictionary - virtual bool read(const dictionary& dict) ; + //- Read dictionary + virtual bool read(const dictionary& dict) ; };