Skip to content

Commit 941c022

Browse files
committed
ACCUMULATOR refinements; improved test accumulator.cse
1 parent e699a30 commit 941c022

File tree

7 files changed

+2169
-217
lines changed

7 files changed

+2169
-217
lines changed

doc/src/records/accumulator.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ ACCUMULATOR results must be reported using user-defined REPORTs or EXPORTs. For
88

99
REPORT rpType=UDT rpFreq=Month rpDayBeg=Jan 1 rpDayEnd=Dec 31
1010
REPORTCOL colHead="mon" colVal=$Month colWid=3
11-
REPORTCOL colHead="Total" colVal=@Accumulator[ 1].M.acmSum colDec=0 colWid=10
11+
REPORTCOL colHead=" Sum" colVal=@Accumulator[ 1].M.acmSum colDec=0 colWid=10
1212
REPORTCOL colHead="Average" colVal=@Accumulator[ 1].M.acmMean colDec=0 colWid=10
1313

14+
(Note use of colHead=" Sum" (not colHead="Sum") to avoid a CSE parsing quirk. See REPORTCOL.)
1415

1516
**acmName**
1617

doc/src/records/exportcol.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Value to show in this position in each row of export.
4646

4747
Text used for field name in export header.
4848

49+
Note: Due to quirk (or bug?) in CSE parsing, setting *colHead* equal to "sum", "all", or "all_but" (case-insensitive) will trigger an error message along the lines of "'SUM' cannot be used here." Adding a space avoids this issue. For example, colHead = " Sum" is accepted.
50+
4951
<%= member_table(
5052
units: "",
5153
legal_range: "",

doc/src/records/reportcol.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Value to show in this column of report.
4141

4242
Text used for column head.
4343

44+
Note: Due to quirk (or bug?) in CSE parsing, setting *colHead* equal to "sum", "all", or "all_but" (case-insensitive) will trigger an error message along the lines of "'SUM' cannot be used here." Adding a space avoids this issue. For example, colHead = " Sum" is accepted.
45+
4446
<%= member_table(
4547
units: "",
4648
legal_range: "",

src/CNRECS.DEF

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5551,23 +5551,31 @@ RECORD ACCUMULATOR_IVL "accumulator interval sub" *SUBSTRUCT // substruct for o
55515551
*declare "void acm_PopulateSubhr( float value);"
55525552
*declare "void acm_Accum( const ACCUMULATOR_IVL* sIvl, bool firstFlg, bool lastFlg, int options=0);"
55535553

5554-
// NOTE: visible prefix used, not *prefix
5555-
// WHY: the name "sum" is treated as reserved and rejected.
5556-
// Visible "acm" prefixes solve avoid that
5557-
INT acmCount // total # of subhrs included
5558-
5559-
FLOAT acmMin // min value seen in interval
5560-
FLOAT acmMean // mean value seen in interval
5561-
FLOAT acmMax // max value seen in interval
5562-
FLOAT acmSum // sum of values in interval
5563-
5564-
SI acmMinDayOfYear // day of year on which min occurs, 1-365
5565-
SI acmMinHour // hour of day at which min occurs, 1-24
5566-
SI acmMinSubhour // subhour within hour at which min occurs, 1-Top.tp_nSubSteps
5567-
5568-
SI acmMaxDayOfYear // day of year on which min occurs, 1-365
5569-
SI acmMaxHour // hour of day at which min occurs, 1-24
5570-
SI acmMaxSubhour // subhour within hour at which min occurs, 1-Top.tp_nSubSteps
5554+
// NOTE: visible prefix used, not *prefix
5555+
// WHY: the name "sum" is treated as reserved and rejected.
5556+
// Visible "acm" prefixes solve avoid that
5557+
INT acmCount // total # of subhrs included
5558+
5559+
FLOAT acmMin // min value seen in interval
5560+
FLOAT acmMean // mean value seen in interval
5561+
FLOAT acmMax // max value seen in interval
5562+
DBL acmSum // sum of values in interval
5563+
5564+
SI acmMinDayOfYear // day of year on which min occurs, 1-365
5565+
SI acmMinDayOfYearST // day of year (standard time) on which min occurs, 1-365
5566+
// can differ from acmMinDayOfYear iff Top.DT=Yes
5567+
SI acmMinHour // hour of day at which min occurs, 1-24
5568+
SI acmMinHourST // hour of day (standard time) at which min occurs, 1-24
5569+
// can differ from acmMinHour iff Top.DT=Yes
5570+
SI acmMinSubhour // subhour within hour at which min occurs, 1-Top.tp_nSubSteps
5571+
5572+
SI acmMaxDayOfYear // day of year on which min occurs, 1-365
5573+
SI acmMaxDayOfYearST // day of year (standard time) on which max occurs, 1-365
5574+
// can differ from acmMaxDayOfYear iff Top.DT=Yes
5575+
SI acmMaxHour // hour of day at which min occurs, 1-24
5576+
SI acmMaxHourST // hour of day (standard time) at which max occurs, 1-24
5577+
// can differ from acmMaxHour iff Top.DT=Yes
5578+
SI acmMaxSubhour // subhour within hour at which min occurs, 1-Top.tp_nSubSteps
55715579

55725580
*END // ACCUMULATOR_IVL
55735581
//=============================================================================

src/cnguts.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,10 +2160,16 @@ void LOCAL accumulatorsAccum(
21602160
ACCUMULATOR_IVL* pSrc = pDst + 1; // source: next shorter interval
21612161

21622162
if (ivl == C_IVLCH_H)
2163-
{
2163+
{ // construct temporary subhour ACCUMULATOR_IVL
21642164
ACCUMULATOR_IVL tempSubhr;
21652165
tempSubhr.acm_PopulateSubhr(pACM->acmValue);
21662166
pDst->acm_Accum(&tempSubhr, firstFlg, lastFlg);
2167+
#if 0 && defined( _DEBUG)
2168+
// re lagged value investigation
2169+
// print value actually used
2170+
if (strMatch(pACM->Name(), "AccumQSrf") && Top.jDay == 67)
2171+
printf("\nAccum %d %d %d %0.2f", Top.jDay, Top.iHr, Top.iSubhr, pACM->acmValue);
2172+
#endif
21672173
}
21682174
else
21692175
{
@@ -2192,9 +2198,13 @@ void ACCUMULATOR_IVL::acm_Copy( // copy to this
21922198
void ACCUMULATOR_IVL::acm_PopulateSubhr( // make full subhr object
21932199
float value)
21942200
{
2195-
acmMin = acmMax = acmMean = acmSum = value;
2201+
acmMin = acmMax = acmMean = value;
2202+
acmSum = double(value); // acmSum uses double
2203+
// (truncation error insurance)
21962204
acmMinDayOfYear = acmMaxDayOfYear = Top.jDay;
2205+
acmMinDayOfYearST = acmMaxDayOfYearST = Top.jDayST;
21972206
acmMinHour = acmMaxHour = Top.iHr;
2207+
acmMinHourST = acmMaxHourST = Top.iHrST;
21982208
acmMinSubhour = acmMaxSubhour = Top.iSubhr;
21992209
acmCount = 1;
22002210

@@ -2217,14 +2227,18 @@ void ACCUMULATOR_IVL::acm_Accum( // accumulate to this
22172227
{
22182228
acmMin = pSrc->acmMin;
22192229
acmMinDayOfYear = pSrc->acmMinDayOfYear;
2230+
acmMinDayOfYearST = pSrc->acmMinDayOfYearST;
22202231
acmMinHour = pSrc->acmMinHour;
2232+
acmMinHourST = pSrc->acmMinHourST;
22212233
acmMinSubhour = pSrc->acmMinSubhour;
22222234
}
22232235
if (pSrc->acmMax > acmMax)
22242236
{
22252237
acmMax = pSrc->acmMax;
22262238
acmMaxDayOfYear = pSrc->acmMaxDayOfYear;
2239+
acmMaxDayOfYearST = pSrc->acmMaxDayOfYearST;
22272240
acmMaxHour = pSrc->acmMaxHour;
2241+
acmMaxHourST = pSrc->acmMaxHourST;
22282242
acmMaxSubhour = pSrc->acmMaxSubhour;
22292243
}
22302244
acmSum += pSrc->acmSum;

test/accumulator.cse

Lines changed: 92 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
wfName = "CA_SACRAMENTO-EXECUTIVE-AP_724830S_STYP20.epw"
44
nSubSteps = 10
5+
DT = NO // first run w/o daylight savings
56

6-
ACCUMULATOR MyAccum acmValue = 1
7-
ACCUMULATOR WthrAccum acmValue = @Top.radBeamShAv
8-
ACCUMULATOR WthrAccum2 acmValue = @weather.db
7+
// trivial test case: accumulate constant 1
8+
ACCUMULATOR Accum1 acmValue = 1
9+
10+
// accumulate subhour beam solar: good test cuz it varies within hour
11+
ACCUMULATOR AccumBeam acmValue = @Top.radBeamShAv
12+
13+
// accumulate subhour surface heat flow: tests for lag
14+
ACCUMULATOR AccumQSrf acmValue = @xsurf[ "South Vertical Wall"].sbcO.qSrf
15+
16+
// accumulate from znres
17+
ACCUMULATOR AccumQsMech acmValue = @znRes[ "Main"].S.qsMech
918

1019
// Constructions
1120
MATERIAL "Plasterboard" matCond = 0.09 matSpHt = 0.2 matDens = 59
@@ -210,56 +219,95 @@ Reportcol colVal="Yr" colWid=2
210219
ZNCOLS(1, Y)
211220
#endif
212221

213-
#define CSEBtuSF 1000
222+
223+
224+
214225
#define ACCOLS( A, X) \
215226
Reportcol colVal=@Accumulator[A].X.acmCount colHead="Count" colWid=8 colDec=0 \
216-
Reportcol colVal=@Accumulator[A].X.acmMin colHead="Min" colWid=8 colDec=2 \
217-
Reportcol colVal=@Accumulator[A].X.acmMinDayOfYear colHead="MinDOY" colWid=6 \
218-
Reportcol colVal=@Accumulator[A].X.acmMinHour colHead="MinHr" colWid=5 \
219-
Reportcol colVal=@Accumulator[A].X.acmMinSubhour colHead="MinSH" colWid=5 \
220-
Reportcol colVal=@Accumulator[A].X.acmMean colHead="Mean" colWid=8 colDec=2 \
221-
Reportcol colVal=@Accumulator[A].X.acmMax colHead="Max" colWid = 8 colDec=2 \
222-
Reportcol colVal=@Accumulator[A].X.acmMaxDayOfYear colHead="MaxDOY" colWid=6 \
223-
Reportcol colVal=@Accumulator[A].X.acmMaxHour colHead="MaxHr" colWid=5 \
224-
Reportcol colVal=@Accumulator[A].X.acmMaxSubhour colHead="MaxSH" colWid=5 \
225-
Reportcol colVal=@Accumulator[A].X.acmSum colHead=" Sum" colWid = 8 colDec=2
227+
Reportcol colVal=@Accumulator[A].X.acmMin colHead="Min" colGap=4 colWid=8 colDec=2 \
228+
Reportcol colVal=@Accumulator[A].X.acmMinDayOfYear colHead="MinDOY" colWid=8 \
229+
Reportcol colVal=@Accumulator[A].X.acmMinDayOfYear colHead="MinDOYST" colWid=8 \
230+
Reportcol colVal=@Accumulator[A].X.acmMinHour colHead="MinHr" colWid=8 \
231+
Reportcol colVal=@Accumulator[A].X.acmMinHour colHead="MinHrST" colWid=8 \
232+
Reportcol colVal=@Accumulator[A].X.acmMinSubhour colHead="MinSH" colWid=8 \
233+
Reportcol colVal=@Accumulator[A].X.acmMean colHead="Mean" colGap=4 colWid=8 colDec=2 \
234+
Reportcol colVal=@Accumulator[A].X.acmMax colHead="Max" colGap=4 colWid = 8 colDec=2 \
235+
Reportcol colVal=@Accumulator[A].X.acmMaxDayOfYear colHead="MaxDOY" colWid=8 \
236+
Reportcol colVal=@Accumulator[A].X.acmMaxDayOfYear colHead="MaxDOYST" colWid=8 \
237+
Reportcol colVal=@Accumulator[A].X.acmMaxHour colHead="MaxHr" colWid=8 \
238+
Reportcol colVal=@Accumulator[A].X.acmMaxHour colHead="MaxHrST" colWid=8 \
239+
Reportcol colVal=@Accumulator[A].X.acmMaxSubhour colHead="MaxSH" colWid=8 \
240+
Reportcol colVal=@Accumulator[A].X.acmSum colHead=" Sum" colGap=4 colWid = 8 colDec=2
226241

227242
// Monthly
228-
#define ACMON( A) \
229-
Report rpType=UDT rpFreq=Month rpCPL=-1 \
243+
#define ACMON( NM, A) \
244+
Report NM rpType=UDT rpFreq=Month rpCPL=-1 \
230245
rpTitle=concat("Monthly data for ", A) \
231246
Reportcol colVal=$month colHead="mo" colWid=2 \
232247
ACCOLS( A, M) \
233-
Report rpType=UDT rpFreq=Year rpHeader=No rpCPL=-1 \
248+
Report concat( NM,"_Y") rpType=UDT rpFreq=Year rpHeader=No rpCPL=-1 \
234249
Reportcol colVal="Yr" colWid=2 \
235250
ACCOLS(A, Y)
236251

252+
// daily
253+
#define ACDAY( NM, A, dayB, dayE) \
254+
Report NM rpType=UDT rpFreq=Day rpCPL=-1 rpDayBeg = dayB rpDayEnd=dayE \
255+
rpTitle=concat( "Day results for ACCCUMULATOR ", A) \
256+
Reportcol colVal=$dayofyear colHead="DOY" colWid=4 \
257+
ACCOLS( A, D)
258+
259+
237260
// hourly
238-
#define ACHOUR( A, dayX) \
239-
Report rpType=UDT rpFreq=Hour rpCPL=-1 rpDayBeg = dayX \
261+
#define ACHOUR( NM, A, dayX) \
262+
Report NM rpType=UDT rpFreq=Hour rpCPL=-1 rpDayBeg = dayX \
240263
rpTitle=concat("Hour results for ACCUMULATOR ", A) \
241264
Reportcol colVal=$hour colHead="hr" colWid=3 \
242265
ACCOLS( A, H) \
243-
Report rpType=UDT rpFreq=Day rpCPL=-1 rpHeader = No rpDayBeg = dayX \
266+
Report concat( NM, "_D") rpType=UDT rpFreq=Day rpCPL=-1 rpHeader = No rpDayBeg = dayX \
244267
Reportcol colVal="Day" colWid=3 \
245268
ACCOLS( A, D)
246269

247-
// daily
248-
#define ACDAY( A, dayB, dayE) \
249-
Report rpType=UDT rpFreq=Day rpCPL=-1 rpDayBeg = dayB rpDayEnd=dayE \
250-
rpTitle=concat( "Day results for ACCCUMULATOR ", A) \
251-
Reportcol colVal=$dayofyear colHead="DOY" colWid=4 \
252-
ACCOLS( A, D)
253270

254-
ACHOUR( "MyAccum", Feb 1)
271+
ACHOUR( "H1", "Accum1", Feb 1)
255272

256-
ACDAY( "MyAccum", Feb 1, Feb 28)
273+
ACDAY( "D1", "Accum1", Feb 1, Feb 28)
257274

258-
ACMON("MyAccum")
275+
ACMON( "M1", "Accum1")
259276

260-
ACMON("WthrAccum")
277+
#define SHREP1(xdb, xde) REPORT rpType=UDT rpFreq=SUBHOUR rpDayBeg=xdb rpDayEnd=xde rpCPL=-1 \
278+
REPORTCOL colHead="Mon" colVal=$month colWid=3 \
279+
REPORTCOL colHead="Day" colVal=$dayOfMonth colWid=3 \
280+
REPORTCOL colHead="DOY" colVal=$dayOfYear colWid=5 \
281+
REPORTCOL colHead="DOYST" [email protected] colWid=5 \
282+
REPORTCOL colHead="Hr0" [email protected] colWid=3 \
283+
REPORTCOL colHead="Hr0ST" [email protected] colWid=4 \
284+
REPORTCOL colHead="DT" colVal=$IsDT colWid=2 \
285+
REPORTCOL colHead="Subhr0" [email protected] colWid=3 \
286+
REPORTCOL colHead="Beam" colVal= @Top.radBeamShAv colWid=7 colDec=2 \
287+
REPORTCOL colHead="BeamAc" colVal= @ACCUMULATOR["AccumBeam"].acmValue colWid=7 colDec=2 \
288+
REPORTCOL colHead="QSrf" colVal= @xsurf["South Vertical Wall"].sbcO.qSrf colWid=7 colDec=2 \
289+
REPORTCOL colHead="QSrfAc" colVal= @ACCUMULATOR["AccumQSrf"].acmValue colWid=7 colDec=2 \
290+
REPORTCOL colHead="ZnQsM" colVal= @znRes[ "Main"].S.qsMech colWid=7 colDec=2 \
291+
REPORTCOL colHead="ZnQsMAc" colVal= @ACCUMULATOR["AccumQsMech"].acmValue colWid=7 colDec=2
292+
293+
294+
295+
SHREP1( mar 7, mar 9)
296+
297+
ACHOUR( "BH", "AccumBeam", mar 8)
298+
299+
ACDAY( "BD", "AccumBeam", mar 1, mar 31)
300+
301+
ACMON("BM", "AccumBeam")
302+
303+
ACHOUR( "QH", "AccumQSrf", mar 8)
261304

262-
ACMON("WthrAccum2")
305+
ACDAY( "QD", "AccumQSrf", mar 1, mar 31)
306+
307+
ACMON("QM", "AccumQSrf")
308+
309+
// accumulate subhour surface heat flow: tests for lag
310+
// ACCUMULATOR AccumQSrf acmValue = @xsurf[ "South Vertical Wall"].sbcO.qSrf
263311

264312

265313

@@ -478,4 +526,17 @@ RUN
478526

479527
RUN
480528

529+
UNSET DT
530+
DT = YES
531+
532+
DELETE REPORT "H1"
533+
DELETE REPORT "H1_D"
534+
535+
DELETE REPORT "D1"
536+
537+
DELETE REPORT "M1"
538+
DELETE REPORT "M1_Y"
539+
540+
RUN
541+
481542

0 commit comments

Comments
 (0)