Skip to content

Commit 244582e

Browse files
committed
AFMETER rework re +/- flows
1 parent 9afe55b commit 244582e

File tree

5 files changed

+97
-89
lines changed

5 files changed

+97
-89
lines changed

src/CGCOMP.CPP

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -309,48 +309,50 @@ RC AFMTR::amt_CkF()
309309
//-----------------------------------------------------------------------------
310310
RC AFMTR::amt_BegSubhr() // init at beg of subhr
311311
{
312-
S.amt_Clear();
312+
S[ 0].amt_Clear();
313+
S[ 1].amt_Clear();
313314
return RCOK;
314315
} // AFMTR::amt_BegSubhr
315316
//-----------------------------------------------------------------------------
316317
void AFMTR::amt_AccumCat( // accumulate air flow value for current subhour
317318
AFCAT afCat, // air flow category
318319
float amf) // air mass flow, lbm/sec
319320
{
320-
if (amf > 0.f) // record only flow into zone
321-
{ // convert lbm/s -> cfm std air
322-
S.amt_AccumCat(afCat, AMFtoAVF2( amf));
323-
}
321+
int iNeg = amf < 0.f;
322+
S[ iNeg].amt_AccumCat(afCat, AMFtoAVF2(amf));
324323
} // AFMTR::amt_AccumCat
325324
//-----------------------------------------------------------------------------
325+
AFMTR_IVL* AFMTR::amt_GetAFMTR_IVL(
326+
IVLCH ivl, // interval
327+
int iPN /*=0*/) // flow direction 0: pos (in), 1: neg (out)
328+
{
329+
return Y + 2 * (ivl - C_IVLCH_Y) + iPN;
330+
}
331+
//-----------------------------------------------------------------------------
326332
void AFMTR::amt_Accum(
327333
IVLCH ivl, // destination interval: hour/day/month/year
328334
// Accumulates from subhour/day/month. Not Top.ivl!
329335
int firstFlg, // iff TRUE, destination will be initialized before values are accumulated into it
330336
int lastFlg) // iff TRUE, destination averages will be computed as needed
331337
{
332-
AFMTR_IVL* dIvl = &Y + (ivl - C_IVLCH_Y); // point destination substruct for interval
333-
// ASSUMES interval members ordered like DTIVLCH choices
334-
AFMTR_IVL* sIvl = dIvl + 1; // source: next shorter interval
338+
AFMTR_IVL* dIvl0 = amt_GetAFMTR_IVL( ivl); // point destination substruct for interval
339+
// ASSUMES interval members ordered like DTIVLCH choices
340+
AFMTR_IVL* sIvl0 = amt_GetAFMTR_IVL(ivl + 1); // source: next shorter interval
335341

336342
int options = 0; // default: track average
337-
#if 0
338-
if (amt_IsSumOf())
339-
{ if (ivl < C_IVLCH_H)
340-
options = 2;
341-
}
342-
else
343-
#endif
344-
if (ivl == C_IVLCH_Y)
343+
344+
if (ivl == C_IVLCH_Y)
345345
options = 1; // average by day for non-sum-of year values
346346
// handles diffs due to month length
347-
dIvl->amt_Accum(sIvl, firstFlg, lastFlg, options);
347+
for (int iPN=0; iPN<2; iPN++)
348+
dIvl0[ iPN].amt_Accum(sIvl0+iPN, firstFlg, lastFlg, options);
348349

349350
if (lastFlg)
350351
{
351-
AFMTR* pAM = AfMtrR.p + AfMtrR.n;
352-
AFMTR_IVL* dIvlSum = &pAM->Y + (ivl - C_IVLCH_Y);
353-
dIvlSum->amt_Accum(dIvl, ss == 1, 0);
352+
AFMTR* pAMSum = AfMtrR.p + AfMtrR.n;
353+
AFMTR_IVL* dIvlSum0 = pAMSum->amt_GetAFMTR_IVL( ivl);
354+
for (int iPN = 0; iPN < 2; iPN++)
355+
dIvlSum0[ iPN].amt_Accum(dIvl0+iPN, ss == 1, 0);
354356
}
355357
} // AFMTR::amt_Accum
356358
//=============================================================================
@@ -1053,20 +1055,28 @@ void IZXRAT::iz_SetupAfMtrs()
10531055

10541056
// AFMTR ptrs: NULL if no meter specified -> no air flow accounting
10551057
// one pointer for positive flows, one for negative
1056-
const ZNR* zp;
1057-
iz_pPosAfMtr = iz_pNegAfMtr = NULL; // insurance
1058-
if (iz_zi1 > 0)
1059-
{ zp = ZrB.GetAt(iz_zi1);
1060-
iz_pPosAfMtr = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
1061-
}
1062-
1063-
if (iz_zi2 > 0)
1064-
{ // interzone transfers recorded iff to a different meter
1065-
zp = ZrB.GetAt(iz_zi2);
1066-
AFMTR* pAM = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
1067-
if (pAM && pAM != iz_pPosAfMtr)
1068-
iz_pNegAfMtr = pAM; // z2 meter specified and differs from z1
1058+
iz_pAfMtr1 = iz_pAfMtr2 = NULL; // insurance
1059+
if (iz_afCat > 0)
1060+
{ // set up ptrs to AFMTR(s)
1061+
const ZNR* zp;
1062+
if (iz_zi1 > 0)
1063+
{ zp = ZrB.GetAt(iz_zi1);
1064+
iz_pAfMtr1 = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
1065+
}
1066+
if (iz_zi2 > 0)
1067+
{ // interzone transfers recorded iff to a different meter
1068+
zp = ZrB.GetAt(iz_zi2);
1069+
AFMTR* pAM = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
1070+
if (pAM == iz_pAfMtr1)
1071+
iz_pAfMtr1 = NULL; // same meter on both sides of IZ
1072+
// don't record IZ within meter
1073+
else
1074+
iz_pAfMtr2 = pAM; // z2 meter specified and differs from z1
1075+
}
10691076
}
1077+
iz_doingAfMtr // say this IZXRAT has AFMTR (speedier test)
1078+
= iz_pAfMtr1 != NULL || iz_pAfMtr2 != NULL;
1079+
10701080
} // IZXRAT::iz_SetupAfMtrs
10711081
//-----------------------------------------------------------------------------
10721082
AFCAT IZXRAT::iz_AfCatDefault() const
@@ -1085,8 +1095,10 @@ AFCAT IZXRAT::iz_AfCatDefault() const
10851095
else
10861096
{ if (iz_IsFixedFlow())
10871097
afCat = C_AFCAT_FANIZ;
1088-
else
1098+
else if (iz_IsAirNet())
10891099
afCat = C_AFCAT_INFILIZ;
1100+
else
1101+
afCat = 0;
10901102
}
10911103

10921104
return afCat;
@@ -1529,14 +1541,12 @@ RC IZXRAT::iz_EndSubhr() // end-of-subhour vent calcs
15291541
if (iz_nvcntrl == C_IZNVTYCH_ANHORIZ)
15301542
iz_amfNom
15311543
+= (1.f - fVent)*iz_ad[0].ad_mdotB + fVent * iz_ad[1].ad_mdotB;
1532-
if (iz_amfNom > 0.f)
1533-
{ if (iz_pPosAfMtr)
1534-
iz_pPosAfMtr->amt_AccumCat(iz_afCat, iz_amfNom);
1535-
}
1536-
else if (iz_amfNom < 0.f)
1537-
{ // flow is out of zn1 = into zn2
1538-
if (iz_pNegAfMtr)
1539-
iz_pNegAfMtr->amt_AccumCat(iz_afCat, -iz_amfNom);
1544+
if (iz_doingAfMtr && iz_amfNom != 0.f)
1545+
{ if (iz_pAfMtr1)
1546+
iz_pAfMtr1->amt_AccumCat(iz_afCat, iz_amfNom);
1547+
if (iz_pAfMtr2)
1548+
// flow is opposite direction from z2 POV
1549+
iz_pAfMtr2->amt_AccumCat(iz_afCat, -iz_amfNom);
15401550
}
15411551

15421552
return RCOK;

src/CGRESULT.CPP

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ static COLDEF wMtrColdef[] =
235235
#undef oWMtr
236236

237237
// columns definition for "Airflow meter" (AFMTR) report/export
238-
#define oAFMtr(m) offsetof( AFMTR_IVL, m)
239-
#define D 3 // decimal digits
238+
#define oAFMt0(m) offsetof( AFMTR_IVL, m)
239+
#define oAFMt1(m) (offsetof( AFMTR_IVL, m)+sizeof( AFMTR_IVL))
240+
#define D 1 // decimal digits
240241
static COLDEF afMtrColdef[] =
241242
/* max offset cvflag */
242243
/* colhd flags wid dfw (cnguts.h) (above) */
@@ -247,21 +248,31 @@ static COLDEF afMtrColdef[] =
247248
{ "Day", 8 | 4, 2, 0, USE_NEXT_ARG, CVI },
248249
{ "Hr", 8 | 4, 2, 0, USE_NEXT_ARG, CVI },
249250
{ "Subhr", 8 | 4, 1, 0, USE_NEXT_ARG, CVS }, // ..
250-
{ "Total", 0, 7, D, oAFMtr(amt_total), CV1 },
251-
{ "Unknown", 0, 7, D, oAFMtr(amt_unknown),CV1 },
252-
{ "InfilEx", 0, 7, D, oAFMtr(amt_infilEx),CV1 },
253-
{ "VentEx", 0, 7, D, oAFMtr(amt_ventEx), CV1 },
254-
{ "FanEx", 0, 7, D, oAFMtr(amt_fanEx), CV1 },
255-
{ "InfilIz", 0, 7, D, oAFMtr(amt_infilIz),CV1 },
256-
{ "VentIz", 0, 7, D, oAFMtr(amt_ventIz), CV1 },
257-
{ "FanIz", 0, 7, D, oAFMtr(amt_fanIz), CV1 },
258-
{ "DuctLk", 0, 7, D, oAFMtr(amt_ductLk), CV1 },
259-
{ "HVAC", 0, 7, D, oAFMtr(amt_hvac), CV1 },
251+
{ "Tot+", 0, 5, D, oAFMt0(amt_total), CV1 },
252+
{ "Unkn+", 0, 5, D, oAFMt0(amt_unknown),CV1 },
253+
{ "InfX+", 0, 5, D, oAFMt0(amt_infilEx),CV1 },
254+
{ "VntX+", 0, 5, D, oAFMt0(amt_ventEx), CV1 },
255+
{ "FanX+", 0, 5, D, oAFMt0(amt_fanEx), CV1 },
256+
{ "InfZ+", 0, 5, D, oAFMt0(amt_infilIz),CV1 },
257+
{ "VntZ+", 0, 5, D, oAFMt0(amt_ventIz), CV1 },
258+
{ "FanZ+", 0, 5, D, oAFMt0(amt_fanIz), CV1 },
259+
{ "Duct+", 0, 5, D, oAFMt0(amt_ductLk), CV1 },
260+
{ "HVAC+", 0, 5, D, oAFMt0(amt_hvac), CV1 },
261+
{ "Tot-", 0, 5, D, oAFMt1(amt_total), CV1 },
262+
{ "Unkn-", 0, 5, D, oAFMt1(amt_unknown),CV1 },
263+
{ "InfX-", 0, 5, D, oAFMt1(amt_infilEx),CV1 },
264+
{ "VntX-", 0, 5, D, oAFMt1(amt_ventEx), CV1 },
265+
{ "FanX-", 0, 5, D, oAFMt1(amt_fanEx), CV1 },
266+
{ "InfZ-", 0, 5, D, oAFMt1(amt_infilIz),CV1 },
267+
{ "VntZ-", 0, 5, D, oAFMt1(amt_ventIz), CV1 },
268+
{ "FanZ-", 0, 5, D, oAFMt1(amt_fanIz), CV1 },
269+
{ "Duct-", 0, 5, D, oAFMt1(amt_ductLk), CV1 },
270+
{ "HVAC-", 0, 5, D, oAFMt1(amt_hvac), CV1 },
260271
{ 0, 0, 0, 0, 0, CV1 }
261272
};
262273
#undef D
263-
#undef oAFMtr
264-
274+
#undef oAFMt0
275+
#undef oAFMt1
265276

266277
// columns definition for "air handler" (AH) report/export
267278
#define oAhr(m) offsetof( AHRES_IVL_SUB, m)
@@ -1258,10 +1269,10 @@ o && dvrip->rpDayEnd >= Top.tp_endDay ) <--- new year's bug! 2-94
12581269
vpRxRow( dvrip, &rxt, pIvl, shortIvlTexts[rxt.fq]); // do DHWMTR rpt row. Uses rxt.flags, colDef.
12591270
}
12601271

1261-
else if (dvrip->rpTy == C_RPTYCH_AFMTR) // if AFDHW meter report
1272+
else if (dvrip->rpTy == C_RPTYCH_AFMTR) // if AFMETER report
12621273
{
12631274
TI afMtri = dvrip->dv_afMtri > 0 ? dvrip->dv_afMtri : AfMtrR.n; // subscript
1264-
AFMTR_IVL* pIvl = &AfMtrR[afMtri].Y + (rxt.fq - 1); // .M is after .Y, etc
1275+
AFMTR_IVL* pIvl = AfMtrR[afMtri].amt_GetAFMTR_IVL( rxt.fq);
12651276
rxt.colDef = afMtrColdef; // columns definition table for vpRxRow
12661277
vpRxRow(dvrip, &rxt, pIvl, shortIvlTexts[rxt.fq]); // do DHWMTR rpt row. Uses rxt.flags, colDef.
12671278
}
@@ -1490,7 +1501,7 @@ void DVRI::dv_vpAfMtrRow(RXPORTINFO *rxt, TI afMtri /*=-1*/)
14901501
if (afMtri == TI_SUM)
14911502
afMtri = AfMtrR.n; // handle "sum"
14921503
AFMTR* pM = AfMtrR.GetAt(afMtri); // record
1493-
AFMTR_IVL* pIvl = (&pM->Y) + (rxt->fq - 1); // interval
1504+
AFMTR_IVL* pIvl = pM->amt_GetAFMTR_IVL( rxt->fq); // interval
14941505
14951506
vpRxRow(this, rxt, pIvl, rxt->col1, pM->name, &rxt->xebM, &rxt->xebD, &rxt->xebH, rxt->xebS);
14961507
} // dv_vpDHWMtrRow

src/CNGUTS.CPP

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,19 +1563,12 @@ LOCAL void FC NEAR doIvlAccum()
15631563

15641564
AFMTR* pAMSum = AfMtrR.p + AfMtrR.n;
15651565
AFMTR* pAM;
1566-
int iM = 0;
15671566
RLUP(AfMtrR, pAM) // loop AFMTRs
15681567
{
1569-
if (++iM != pAM->ss)
1570-
printf("\nMismatch");
15711568
if (pAM->ss < AfMtrR.n)
1572-
{
1573-
pAMSum->S.amt_Accum(&pAM->S, pAM->ss == 1, pAM->ss == AfMtrR.n - 1);
1574-
if (iM != pAM->ss)
1575-
printf("\nMismatch");
1569+
{ pAMSum->S[0].amt_Accum(pAM->S, pAM->ss == 1, pAM->ss == AfMtrR.n - 1);
1570+
pAMSum->S[1].amt_Accum(pAM->S+1, pAM->ss == 1, pAM->ss == AfMtrR.n - 1);
15761571
pAM->amt_Accum(C_IVLCH_H, Top.isBegHour, Top.isEndHour);
1577-
if (iM != pAM->ss)
1578-
printf("\nMismatch");
15791572
}
15801573
}
15811574

@@ -2064,15 +2057,9 @@ LOCAL void FC NEAR mtrsAccum( // Accumulate metered results: add interval to ne
20642057

20652058
// AFMETERs
20662059
AFMTR* pAM;
2067-
int iM = 0;
20682060
RLUP(AfMtrR, pAM)
2069-
{
2070-
if (++iM != pAM->ss)
2071-
printf("\nMismatch");
2072-
if (pAM->ss < AfMtrR.n)
2061+
{ if (pAM->ss < AfMtrR.n)
20732062
pAM->amt_Accum(ivl, firstflg, lastflg);
2074-
if (iM != pAM->ss)
2075-
printf("\nMismatch");
20762063
}
20772064
} // mtrsAccum
20782065
//-----------------------------------------------------------------------------------------------------------

src/CNRECS.DEF

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,14 +2827,13 @@ RECORD IZXRAT "izXfer" *RAT // interzone heat transfers: conductive and/or vent.
28272827
// C_IZNVTYCH_ANSYSAIR: system air flow
28282828
// C_IZNVTYCH_ANOAVRLF: RSYS OAV relief air
28292829
// ( = interzone hole sized per flow)
2830-
*r AFCAT iz_afCat // air flow category (accounting only)
2831-
// C_AFCAT_xxx
2830+
*r AFCAT iz_afCat // air flow category (accounting only) C_AFCAT_xxx
2831+
28322832
// AFMTR pointers, derived from zone zn_afMtri
2833-
// one for pos flows, one for neg
2834-
// WHY: AFMTRs track flow into zone
2835-
// IZ transfers have different zones per size
2836-
*declare "AFMTR* iz_pPosAfMtr;"
2837-
*declare "AFMTR* iz_pNegAfMtr;"
2833+
// NULL if not specified or same on both sides of IZ type
2834+
*declare "AFMTR* iz_pAfMtr1;" // for iz_zn1
2835+
*declare "AFMTR* iz_pAfMtr2;" // for iz_zn2
2836+
*declare "bool iz_doingAfMtr;" // true iff iz_pAfMtr1 or iz_pAfMtr2 != NULL
28382837

28392838
*h AREA_GEZ iz_a1 // vent area 1, ft2
28402839
// _TWOWAY = low vent area
@@ -3428,22 +3427,24 @@ RECORD AFMTR_IVL "Airflow meter interval sub" *SUBSTRUCT // interval substruct
34283427
*END // AFMTR_IVL
34293428
//=============================================================================
34303429
RECORD AFMTR "AFMETER" *RAT // Airflow meter
3431-
3430+
*prefix amt_
34323431
*declare "RC amt_CkF();"
34333432
// *declare "void amt_Clear();"
34343433
*declare "bool amt_IsSumOf() const { return ss == b->n; }"
34353434
*declare "RC amt_BegSubhr();"
34363435
*declare "void amt_AccumCat( AFCAT afCat, float amf);"
34373436
*declare "void amt_Accum( IVLCH ivl, int firstflg, int lastFlg);"
3437+
*declare "AFMTR_IVL* amt_GetAFMTR_IVL( IVLCH ivl, int iPN=0);"
3438+
34383439

34393440
// results: average cfm std air
34403441
// for each interval (member here), usage by end use (substruct member):
34413442
// CAUTION: ordered for subscripting by IVLCH-1.
3442-
*y *e *nest AFMTR_IVL Y // run (aka year or annual)
3443-
*m *e *nest AFMTR_IVL M // month
3444-
*d *e *nest AFMTR_IVL D // day
3445-
*h *e *nest AFMTR_IVL H // hour
3446-
*s *e *nest AFMTR_IVL S // subhour
3443+
*y *e *array 2 *nest AFMTR_IVL Y // run (aka year or annual)
3444+
*m *e *array 2 *nest AFMTR_IVL M // month
3445+
*d *e *array 2 *nest AFMTR_IVL D // day
3446+
*h *e *array 2 *nest AFMTR_IVL H // hour
3447+
*s *e *array 2 *nest AFMTR_IVL S // subhour
34473448
*END // AFMETER
34483449
//=============================================================================
34493450
RECORD DHWMTR_IVL "DHW meter interval sub" *SUBSTRUCT // interval substruct for DHW meter

src/CSE.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "cnglob.h"
5858

5959
#include <process.h> // exit
60-
#include <setjmp.h> // jmp_buf setjmp longjmp
6160

6261
#include <ancrec.h> // record: base class for rccn.h classes
6362
#include <rccn.h> // TOPRATstr

0 commit comments

Comments
 (0)