Skip to content

Commit 9afe55b

Browse files
committed
AFMETER WIP
1 parent 53f4063 commit 9afe55b

File tree

6 files changed

+95
-43
lines changed

6 files changed

+95
-43
lines changed

src/CGCOMP.CPP

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,40 @@ float TOPRAT::tp_WindPresV( // wind velocity pressure
265265
// NAFCATS s/b same as AFCAT choices + 1 (for total)
266266
static_assert(AFMTR_IVL::NAFCATS == C_AFCAT_COUNT+1, "Inconsistent AFMTR constants");
267267
//-----------------------------------------------------------------------------
268-
void AFMTR_IVL::amt_Copy(
269-
const AFMTR_IVL* s)
268+
void AFMTR_IVL::amt_Copy( // copy
269+
const AFMTR_IVL* sIvl, // source
270+
float mult /*=1.f*/) // optional multiplier
270271
{
271-
memcpy(this, s, sizeof(AFMTR_IVL));
272+
if (mult == 1.f)
273+
memcpy(this, sIvl, sizeof(AFMTR_IVL));
274+
else
275+
{ amt_count = sIvl->amt_count;
276+
VCopy(&amt_total, NAFCATS, &sIvl->amt_total, double(mult));
277+
}
272278
} // AFMTR_IVL::amt_Copy
273279
//-----------------------------------------------------------------------------
274280
void AFMTR_IVL::amt_Accum( // accumulate
275281
const AFMTR_IVL* sIvl, // source
276282
int firstFlg, // true iff first accum into this (beg of ivl)
277-
int lastFlg) // true iff last accum into this (end of ivl)
278-
283+
int lastFlg, // true iff last accum into this (end of ivl)
284+
int options /*=0*/) // option bits
285+
// 1: use sIvl.amt_count to scale totals
286+
// effectively averages by day for annual values
287+
// 2: sum only (do not average)
279288
{
289+
int count = (options & 1) ? sIvl->amt_count : 1;
280290
if (firstFlg)
281-
{ amt_Copy(sIvl);
282-
amt_count = 1;
291+
{ amt_Copy(sIvl, float( count));
292+
amt_count = count;
283293
}
284294
else
285-
{ VAccum(&amt_total, NAFCATS, &sIvl->amt_total);
286-
amt_count++;
295+
{ VAccum(&amt_total, NAFCATS, &sIvl->amt_total, float( count));
296+
amt_count += count;
287297
}
288-
if (lastFlg)
298+
299+
// average unless caller says don't
300+
// Note: VMul1() nops if amt_count==1
301+
if (lastFlg && !(options & 2))
289302
VMul1(&amt_total, NAFCATS, 1.f / amt_count);
290303
} // AFMTR_IVL
291304
//-----------------------------------------------------------------------------
@@ -320,9 +333,25 @@ void AFMTR::amt_Accum(
320333
// ASSUMES interval members ordered like DTIVLCH choices
321334
AFMTR_IVL* sIvl = dIvl + 1; // source: next shorter interval
322335

323-
// accumulate: copy on first call (in lieu of 0'ing dIvl).
324-
// Note: amt_Init() call in doBegIvl 0s H values
325-
dIvl->amt_Accum(sIvl, firstFlg, lastFlg);
336+
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)
345+
options = 1; // average by day for non-sum-of year values
346+
// handles diffs due to month length
347+
dIvl->amt_Accum(sIvl, firstFlg, lastFlg, options);
348+
349+
if (lastFlg)
350+
{
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);
354+
}
326355
} // AFMTR::amt_Accum
327356
//=============================================================================
328357

@@ -518,23 +547,13 @@ double ZNR::zn_Rho0() const // zone air density
518547
// returns moist air density lb/ft3 at nominal z=0 for current zone conditions
519548
// Note: not *dry* air
520549
{
521-
#if 1 // air density rework, 10-18-2012
522550
double rho = psyDenMoistAir( tz, wz, LbSfToInHg( zn_pz0));
523551
if (rho < .0001)
524552
{ err( WRN, "Zone '%s', %s: moist air density <= 0\n",
525553
name, Top.When( C_IVLCH_S));
526554
rho = 0.01; // set to small but physically possible value
527555
}
528556
return rho;
529-
#elif 1
530-
x double rho1 = psyDenMoistAir( tz, wz, LbSfToInHg( zn_pz0));
531-
x double rho2 = psyDensity( tz, wz, LbSfToInHg( zn_pz0));
532-
x if (FEQX( rho1, rho2) > .001)
533-
x printf( "Mismatch\n");
534-
x return rho2;
535-
#else
536-
x return psyDensity( tz, wz, LbSfToInHg( zn_pz0));
537-
#endif
538557
} // ZNR::zn_Rho0
539558
//------------------------------------------------------------------------------
540559
void ZNR::zn_AccumAirFlow( // accumulate zone bal values due to air flow
@@ -1035,13 +1054,18 @@ void IZXRAT::iz_SetupAfMtrs()
10351054
// AFMTR ptrs: NULL if no meter specified -> no air flow accounting
10361055
// one pointer for positive flows, one for negative
10371056
const ZNR* zp;
1057+
iz_pPosAfMtr = iz_pNegAfMtr = NULL; // insurance
10381058
if (iz_zi1 > 0)
10391059
{ zp = ZrB.GetAt(iz_zi1);
10401060
iz_pPosAfMtr = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
10411061
}
1062+
10421063
if (iz_zi2 > 0)
1043-
{ zp = ZrB.GetAt(iz_zi2);
1044-
iz_pNegAfMtr = AfMtrR.GetAtSafe(zp->i.zn_afMtri);
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
10451069
}
10461070
} // IZXRAT::iz_SetupAfMtrs
10471071
//-----------------------------------------------------------------------------

src/CGRESULT.CPP

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,9 @@ o && dvrip->rpDayEnd >= Top.tp_endDay ) <--- new year's bug! 2-94
12581258
vpRxRow( dvrip, &rxt, pIvl, shortIvlTexts[rxt.fq]); // do DHWMTR rpt row. Uses rxt.flags, colDef.
12591259
}
12601260

1261-
else if (dvrip->rpTy == C_RPTYCH_AFMTR) // if DHW meter report
1261+
else if (dvrip->rpTy == C_RPTYCH_AFMTR) // if AFDHW meter report
12621262
{
1263-
TI afMtri = dvrip->dv_afMtri; // subscript
1263+
TI afMtri = dvrip->dv_afMtri > 0 ? dvrip->dv_afMtri : AfMtrR.n; // subscript
12641264
AFMTR_IVL* pIvl = &AfMtrR[afMtri].Y + (rxt.fq - 1); // .M is after .Y, etc
12651265
rxt.colDef = afMtrColdef; // columns definition table for vpRxRow
12661266
vpRxRow(dvrip, &rxt, pIvl, shortIvlTexts[rxt.fq]); // do DHWMTR rpt row. Uses rxt.flags, colDef.
@@ -1487,6 +1487,8 @@ void DVRI::dv_vpAfMtrRow(RXPORTINFO *rxt, TI afMtri /*=-1*/)
14871487
{
14881488
if (afMtri < 0)
14891489
afMtri = dv_afMtri;
1490+
if (afMtri == TI_SUM)
1491+
afMtri = AfMtrR.n; // handle "sum"
14901492
AFMTR* pM = AfMtrR.GetAt(afMtri); // record
14911493
AFMTR_IVL* pIvl = (&pM->Y) + (rxt->fq - 1); // interval
14921494

src/CNCULT4.CPP

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,7 @@ badZn4ty:
695695
// check meter reference or ALL or SUM
696696

697697
if (mtri > 0) // if specific meter given (error'd above if omitted when rqd)
698-
{
699-
if (ckRefPt( &MtrB, mtri, isEx ? "exMeter" : "rpMeter" ) )
698+
{ if (ckRefPt( &MtrB, mtri, isEx ? "exMeter" : "rpMeter" ) )
700699
return RCBAD;
701700
}
702701
else // no meter given, or ALL or SUM.
@@ -769,10 +768,15 @@ badDHWMtr4ty:
769768
{
770769
char *mtrTx /*=""*/;
771770
if (ri_afMtri == TI_SUM)
772-
{
773-
mtrTx = "sum";
774-
goto badAFMtr4ty;
775-
}
771+
switch (rpTy)
772+
{
773+
case 0: // rpTy 0: not set, no message here
774+
case C_RPTYCH_AFMTR:
775+
break; // AFMTR (air flow meter): SUM allowed.
776+
default:
777+
mtrTx = "sum";
778+
goto badAFMtr4ty;
779+
}
776780
else if (ri_afMtri == TI_ALL)
777781
switch (rpTy)
778782
{

src/CNGUTS.CPP

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,13 @@ LOCAL RC FC NEAR doBegIvl() // simulation run start-of-interval processing: init
547547
EF( Top.tp_ExshBegHour()); // Penumbra external shading: sets sun position
548548

549549
default: // case C_IVLCH_S: // at start of each subhour, incl longer intervals (fall in)
550+
Top.isEndHour = (Top.iSubhr + 1 >= Top.nSubSteps); // set flag if last subHour of hour
551+
550552
#if defined( DEBUGDUMP)
551553
DbDo( dbdSTARTSTEP); // nothing yet debug-printed for this subhour
552554
// (sets flag re on-demand heading printing
553555
#endif
554556
EF( Top.tp_WthrBegSubhr() ); // set Top subhourly weather members, eg tDbOSh. Mostly interpolated. cgwthr.cpp.
555-
Top.isEndHour = (Top.iSubhr + 1 >= Top.nSubSteps); // set flag if last subHour of hour
556557

557558
// clear subhour values in air flow meters
558559
AFMTR* pAM;
@@ -1562,10 +1563,20 @@ LOCAL void FC NEAR doIvlAccum()
15621563

15631564
AFMTR* pAMSum = AfMtrR.p + AfMtrR.n;
15641565
AFMTR* pAM;
1566+
int iM = 0;
15651567
RLUP(AfMtrR, pAM) // loop AFMTRs
1566-
{ if (pAM->ss < AfMtrR.n)
1568+
{
1569+
if (++iM != pAM->ss)
1570+
printf("\nMismatch");
1571+
if (pAM->ss < AfMtrR.n)
1572+
{
15671573
pAMSum->S.amt_Accum(&pAM->S, pAM->ss == 1, pAM->ss == AfMtrR.n - 1);
1568-
pAM->amt_Accum( C_IVLCH_H, Top.isBegHour, Top.isEndHour);
1574+
if (iM != pAM->ss)
1575+
printf("\nMismatch");
1576+
pAM->amt_Accum(C_IVLCH_H, Top.isBegHour, Top.isEndHour);
1577+
if (iM != pAM->ss)
1578+
printf("\nMismatch");
1579+
}
15691580
}
15701581

15711582
if (Top.ivl > C_IVLCH_H) // if subhour call, done
@@ -1724,8 +1735,8 @@ LOCAL void FC NEAR doIvlAccum()
17241735
RLUP(WsResR, pWSR) // loop DHWSYS simulation results incl sum_of.
17251736
pWSR->M.wsr_Accum(&pWSR->D, Top.isBegMonth, Top.isEndMonth); // accumulate month from day
17261737
RLUP( AhresB, ahres) // loop air handers sim results
1727-
accumAhr( &ahres->D, &ahres->M, Top.isBegMonth, Top.isEndMonth); // accumulate day ah results to month
1728-
mtrsAccum( C_IVLCH_M, Top.isBegMonth, Top.isEndMonth); // accum metered energy: day to month. local,below.
1738+
accumAhr( &ahres->D, &ahres->M, Top.isBegMonth, Top.isEndMonth); // accumulate day ah results to month
1739+
mtrsAccum( C_IVLCH_M, Top.isBegMonth, Top.isEndMonth); // accum METERs, DHWMETERs, AFMETERS: day to month
17291740
#ifdef BINRES
17301741
if (brf) // if outputting binary results for this run
17311742
//if (!Top.tp_autoSizing) // not for ausz yet 6-95: tested above, and brf is off.
@@ -2053,8 +2064,16 @@ LOCAL void FC NEAR mtrsAccum( // Accumulate metered results: add interval to ne
20532064

20542065
// AFMETERs
20552066
AFMTR* pAM;
2067+
int iM = 0;
20562068
RLUP(AfMtrR, pAM)
2057-
pAM->amt_Accum(ivl, firstflg, lastflg);
2069+
{
2070+
if (++iM != pAM->ss)
2071+
printf("\nMismatch");
2072+
if (pAM->ss < AfMtrR.n)
2073+
pAM->amt_Accum(ivl, firstflg, lastflg);
2074+
if (iM != pAM->ss)
2075+
printf("\nMismatch");
2076+
}
20582077
} // mtrsAccum
20592078
//-----------------------------------------------------------------------------------------------------------
20602079
LOCAL void FC NEAR mtrsFinalize( // Finalize meters (after post-stage calcs e.g. battery)

src/CNRECS.DEF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,9 +3403,9 @@ RECORD AFMTR_IVL "Airflow meter interval sub" *SUBSTRUCT // interval substruct
34033403

34043404
*prefix amt_
34053405
*declare "void amt_Clear() { memset( this, 0, sizeof( AFMTR_IVL));}"
3406-
*declare "void amt_Copy( const AFMTR_IVL* s);"
3406+
*declare "void amt_Copy( const AFMTR_IVL* sIvl, float mult=1.f);"
34073407
*declare "void amt_AccumCat( AFCAT cat, FLOAT v) { (&amt_unknown)[ cat] += v; amt_total += v; }"
3408-
*declare "void amt_Accum( const AFMTR_IVL* sIvl, int firstFlg, int lastFlg);"
3408+
*declare "void amt_Accum( const AFMTR_IVL* sIvl, int firstFlg, int lastFlg, int options=0);"
34093409

34103410
*declare "static const int NAFCATS;"
34113411

@@ -3430,6 +3430,8 @@ RECORD AFMTR_IVL "Airflow meter interval sub" *SUBSTRUCT // interval substruct
34303430
RECORD AFMTR "AFMETER" *RAT // Airflow meter
34313431

34323432
*declare "RC amt_CkF();"
3433+
// *declare "void amt_Clear();"
3434+
*declare "bool amt_IsSumOf() const { return ss == b->n; }"
34333435
*declare "RC amt_BegSubhr();"
34343436
*declare "void amt_AccumCat( AFCAT afCat, float amf);"
34353437
*declare "void amt_Accum( IVLCH ivl, int firstflg, int lastFlg);"

src/VECPAK.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ template< typename T1, typename T2> void VMul1( // vector * constant
336336
T1* v, // vector
337337
int n, // dim of v
338338
T2 f) // factor
339-
{ for (int i=0; i < n; i++)
340-
v[ i] = T1( v[ i] * f);
339+
{ if (f != T2( 1))
340+
for (int i=0; i < n; i++)
341+
v[ i] = T1( v[ i] * f);
341342
} // VMul1< T1, T2>
342343
//-------------------------------------------------------------------------
343344
template< typename T> T DotProd3( // 3-vector dot product

0 commit comments

Comments
 (0)