@@ -265,27 +265,40 @@ float TOPRAT::tp_WindPresV( // wind velocity pressure
265265// NAFCATS s/b same as AFCAT choices + 1 (for total)
266266static_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// -----------------------------------------------------------------------------
274280void 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// ------------------------------------------------------------------------------
540559void 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// -----------------------------------------------------------------------------
0 commit comments