Skip to content

Eliminate spurious and duplicate DHWSYS energy balance errors #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CNRECS.DEF
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,10 @@ RECORD DHWSYSRES_IVL "DHWSYSRES interval sub" *SUBSTRUCT // interval substruct
RECORD DHWSYSRES "DHWSYSRES" *RAT // DHWSYSRES: interval results for DHWSYS

*declare "RC wsr_Init( IVLCH ivl=-1);"
*declare "const DHWSYS* wsr_GetDHWSYS() const;"
*declare "bool wsr_IsSumOf() const { return ss == b->n; }"
*declare "enum WSRCHK { wsrchkCHILD=1, wsrchkSUMOF, wsrchkLOOSE, wsrchkTIGHT };"
*declare "WSRCHK wsr_BalChkCase() const;"
#if 0
*declare "void wsr_Accum( IVLCH ivl, int firstflg);"
#endif
Expand Down
40 changes: 28 additions & 12 deletions src/cgenbal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,39 @@ void cgenbal( // Check energy balances; issue warning message if out of toleran
// Known causes:
// 1) instantaneous DHWHEATER load carry-forward
// 2) HPWH internal balance errors (?)

if (ivl <= C_IVLCH_H) // if hour or longer
{
float tolDHWSYS{ 0.01f };
float absTolDHWSYS{ 20.f };
if (ivl == C_IVLCH_H)
{ // short-interval errors common, use sloppy tolerences
tolDHWSYS = 0.10;
absTolDHWSYS = 100.f;
}
DHWSYSRES* pWS;
RLUP(WsResR, pWS)
static constexpr float fTol[] = { 0.01f, 0.10f };
static constexpr float absTol[] = { 20.f, 100.f };

int checkCount = 0; // count of checks performed
int iTol{ 0 }; // tolerance idx 0=tight, 1=loose
// prior iteration needed for SUMOF
DHWSYSRES* pWSR;
RLUP(WsResR, pWSR)
{
const DHWSYSRES_IVL* pWSL = &pWS->Y + ivl - 1;
// eyeball current situation -- avoid duplicate and spurious msgs
DHWSYSRES::WSRCHK balChkCase = pWSR->wsr_BalChkCase();
if (balChkCase == DHWSYSRES::wsrchkCHILD
|| (balChkCase == DHWSYSRES::wsrchkSUMOF && checkCount <= 1))
continue; // no check if child (no DHWHEATER, check not meaningful)
// no check if sum_of with single source (sum_of record identical to source)

++checkCount;

// iTol: 0=tight, 1=loose
// loose for PreRun and C_IVLCH_H (bigger errors common)
// tight for Simulate and daily/month/year
// use prior value for SUMOF
if (balChkCase != DHWSYSRES::wsrchkSUMOF)
iTol = balChkCase == DHWSYSRES::wsrchkLOOSE || ivl == C_IVLCH_H;

const DHWSYSRES_IVL* pWSL = &pWSR->Y + ivl - 1;
double wsTot = pWSL->wsr_SumAbs();
double wsNet = pWSL->qBal;
cgecheck(wsNet, wsTot, tolDHWSYS, absTolDHWSYS, "DHWSYS '%s'", pWS->Name(), ivl,
pWS->wsr_ebErrCount);
cgecheck(wsNet, wsTot, fTol[ iTol], absTol[ iTol], "DHWSYS '%s'", pWSR->Name(), ivl,
pWSR->wsr_ebErrCount);
}
}
#endif // SUPPRESS_ENBAL_CHECKS
Expand Down
29 changes: 27 additions & 2 deletions src/dhwcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,31 @@ RC DHWSYSRES::wsr_Init( // init (set to 0)
return rc;
} // DHWSYSRES::wsr_Init
//-----------------------------------------------------------------------------
const DHWSYS* DHWSYSRES::wsr_GetDHWSYS() const
{ return WsR.GetAtSafe(ss);
} // DHWSYSRES::wsr_GetDHWSYS
//-----------------------------------------------------------------------------
DHWSYSRES::WSRCHK DHWSYSRES::wsr_BalChkCase() const // how to balance check this DHWSYSRES
// returns wsrchkSUMOF: sum-of record, special case
// wsrchkCHILD: child DHWSYS (no heater), no check
// wsrchkLOOSE: pre-run underway, use loose tolerance
// wsrchkTIGHT: simulation underway, use tight tolerance

{
WSRCHK ret{ wsrchkTIGHT };
const DHWSYS* pWS = wsr_GetDHWSYS();
if (!pWS)
{
assert(wsr_IsSumOf());
ret = wsrchkSUMOF;
}
else if (pWS->ws_HasCentralDHWSYS())
ret = wsrchkCHILD;
else if (pWS->ws_calcMode!=C_WSCALCMODECH_SIM)
ret = wsrchkLOOSE;
return ret;
} // wsr_BalChkCase
//-----------------------------------------------------------------------------
#if 0
void DHWSYSRES::wsr_Accum(
IVLCH ivl, // destination interval: hour/day/month/year.
Expand Down Expand Up @@ -3875,7 +3900,7 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
#else
WStr s("mon,day,hr,");
s += csvGen.cg_Hdgs(dumpUx);
// hw_pHPWH->WriteCSVHeading(hw_pFCSV, s.c_str(), nTCouples, hpwhOptions);
hw_pHPWH->writeCSVHeading(*hw_pFCSV, s.c_str(), nTCouples, hpwhOptions);
#endif
}
}
Expand All @@ -3887,7 +3912,7 @@ RC HPWHLINK::hw_DoSubhrTick( // calcs for 1 tick
WStr s = strtprintf("%d,%d,%d,",
Top.tp_date.month, Top.tp_date.mday, Top.iHr + 1);
s += csvGen.cg_Values(dumpUx);
//hw_pHPWH->WriteCSVRow(*hw_pFCSV, s.c_str(), nTCouples, hpwhOptions);
hw_pHPWH->writeCSVRow(*hw_pFCSV, s.c_str(), nTCouples, hpwhOptions);
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/HPWHsim