Skip to content

Commit 31e45f4

Browse files
committed
DR cleanup
1 parent d834614 commit 31e45f4

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/CNRECS.DEF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3921,7 +3921,8 @@ RECORD DHWHEATER "DHWHeater" *RAT // input / runtime DHW heater
39213921
*declare "int wh_ReportBalErrorsIf() const;"
39223922
*declare "virtual void ReceiveRuntimeMessage( const char* msg);"
39233923
*declare "RC wh_HPWHInit();"
3924-
*declare "static int wh_MapDRSigToDRModeHPWH( DHWDRSIG drSig);"
3924+
*declare "static void wh_DRMapValidate();"
3925+
*declare "static int wh_DRMapSigToDRMode( DHWDRSIG drSig);"
39253926

39263927
*r FLOAT_GEZ wh_mult; // count of identical water heaters (default 1)
39273928
// models as if repeated identical input

src/DHWCalc.cpp

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ RC DHWSYS::ws_DoHour( // hourly calcs
12071207
if (!ws_HasCentralDHWSYS())
12081208
{ int drSig = CHN(ws_drSignal); // decode variable choice
12091209
ws_drModeHPWH = ws_drMethod == C_DHWDRMETH_SCHED
1210-
? DHWHEATER::wh_MapDRSigToDRModeHPWH( drSig)
1210+
? DHWHEATER::wh_DRMapSigToDRMode( drSig)
12111211
: HPWH::DR_ALLOW;
12121212
}
12131213
else
@@ -2793,28 +2793,26 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
27932793

27942794
bool bDoMix = tMix > 0.f;
27952795

2796-
// draw components
2797-
double drawUse; // use draw
2796+
// draw components for tick
2797+
double drawUse; // use draw, gal
27982798
double drawLoss;// pseudo-draw (gal) to represent e.g. central system branch losses
2799-
double drawRL; // loop flow vol for tick
2800-
double tRL; // loop return temp
2799+
double drawRL; // loop flow vol for tick, gal
2800+
double tRL; // loop return temp, F
2801+
double drawForTick; // total draw, gal
28012802
if (bDoMix)
28022803
{ double scaleX = scaleWH * hw_fMixUse;
28032804
drawUse = tk.wtk_whUse*scaleX;
28042805
drawLoss = tk.wtk_qLossNoRL*scaleX / (waterRhoCp * max(1., tMix - tMains));
28052806
tk.wtk_volIn += (drawUse + drawLoss) / scaleWH;
28062807
drawRL = tk.wtk_volRL * scaleWH * hw_fMixRL;
2808+
drawForTick = drawUse + drawLoss + drawRL;
28072809
tRL = tk.wtk_tRL;
28082810
}
28092811
else
2810-
{ drawUse = tk.wtk_volIn * scaleWH; // multipliers??
2812+
{ drawForTick = drawUse = tk.wtk_volIn * scaleWH; // multipliers??
28112813
drawLoss = drawRL = tRL = 0.f;
28122814
}
28132815

2814-
double drawForTick = drawUse + drawLoss + drawRL;
2815-
2816-
hw_pHPWH->setInletT(DegFtoC(tInlet)); // mixed inlet temp
2817-
28182816
// extra tank heat: passed to HPWH as vector<double>* (or NULL)
28192817
// used to model e.g. heat addition via solar DHW heat exchanger
28202818
std::vector< double>* pNPX = NULL;
@@ -3591,22 +3589,19 @@ RC DHWHEATER::wh_HPWHInit() // initialize HPWH model
35913589
pWS->ignore(fn,
35923590
strtprintf("-- HPWH '%s' has a fixed setpoint.", name));
35933591
}
3594-
wh_MapDRSigToDRModeHPWH(-1); // validate DRMODE mapping
3592+
wh_DRMapValidate(); // validate DRMODE mapping (ABT if bad)
35953593
}
35963594
return rc;
35973595
} // DHWHEATER::wh_HPWHInit
3596+
35983597
//-----------------------------------------------------------------------------
3599-
/* static*/ int DHWHEATER::wh_MapDRSigToDRModeHPWH(
3600-
DHWDRSIG drSig) // CSE DR choice value
3601-
// -1: validate table
3602-
// returns HPWH-compatible DRMODES value corresponding to CSE choice
3603-
{
3598+
// Demand reduction (DR) stuff
36043599
struct DRMAP
3605-
{ int drSig;
3606-
int drModeHPWH;
3600+
{ DHWDRSIG drSig; // CSE signal choice
3601+
int drModeHPWH; // corresponding HPWH drMode
36073602
};
36083603
static const DRMAP drMap[] =
3609-
{ C_DHWDRSIG_ON, HPWH::DR_ALLOW,
3604+
{ C_DHWDRSIG_ON, HPWH::DR_ALLOW,
36103605
C_DHWDRSIG_TOO, HPWH::DR_TOO,
36113606
C_DHWDRSIG_TXO, HPWH::DR_TOO | HPWH::DR_LOR,
36123607
C_DHWDRSIG_TOT, HPWH::DR_TOT,
@@ -3616,29 +3611,37 @@ static const DRMAP drMap[] =
36163611
C_DHWDRSIG_LOX, HPWH::DR_LOR | HPWH::DR_LOC,
36173612
-1, -1
36183613
};
3619-
3620-
if (drSig < 0)
3621-
{ // validate table
3622-
// correct table allows access by idx, avoids search
3623-
bool bMunge = false;
3624-
int ix;
3625-
for (ix = 0; !bMunge && drMap[ix].drSig >= 0; ix++)
3626-
{ if (drMap[ix].drSig != ix + C_DHWDRSIG_ON)
3627-
bMunge = true;
3628-
}
3629-
if (bMunge || ix != C_DHWDRSIG_COUNT - C_DHWDRSIG_ON)
3630-
// table out of order or wrong # of entries
3631-
errCrit(PABT, "DHWHEATER::wh_MapDRSigToDRModeHPWH() validation failure.");
3632-
return 0;
3614+
//-----------------------------------------------------------------------------
3615+
/* static*/ void DHWHEATER::wh_DRMapValidate() // one-time DRMAP checks
3616+
// Detects misconfigured code
3617+
// Aborts execution on fail
3618+
{
3619+
// correct table allows access by idx, avoids search
3620+
bool bMunge = false;
3621+
int ix;
3622+
for (ix = 0; !bMunge && drMap[ix].drSig >= 0; ix++)
3623+
{
3624+
if (drMap[ix].drSig != ix + C_DHWDRSIG_ON)
3625+
bMunge = true;
36333626
}
3627+
if (bMunge || ix != C_DHWDRSIG_COUNT - C_DHWDRSIG_ON)
3628+
// table out of order or wrong # of entries
3629+
errCrit(PABT, "DHWHEATER::wh_DRMapValidate() failure.");
36343630

3631+
} // DHWHEATER::wh_DRMapValidate
3632+
//-----------------------------------------------------------------------------
3633+
/* static*/ int DHWHEATER::wh_DRMapSigToDRMode(
3634+
DHWDRSIG drSig) // CSE DR choice value
3635+
// -1: validate table
3636+
// returns HPWH-compatible DRMODES value corresponding to CSE choice
3637+
{
36353638
int ixDrSig = drSig - C_DHWDRSIG_ON; // choice values assigned sequencially
36363639

36373640
int drMode = drMap[ixDrSig].drModeHPWH;
36383641

36393642
return drMode;
36403643

3641-
} // DHWHEATER::wh_MapDRSigToDRModeHPWH
3644+
} // DHWHEATER::wh_DRMapSigToDRMode
36423645
//-----------------------------------------------------------------------------
36433646
RC DHWHEATER::wh_DoSubhrStart()
36443647
{

0 commit comments

Comments
 (0)