Skip to content

Commit 3bace3b

Browse files
committed
Design day weather
1 parent 30319b8 commit 3bace3b

File tree

12 files changed

+201
-88
lines changed

12 files changed

+201
-88
lines changed

src/ANCREC.CPP

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ record::record( BP _b, TI i, SI noZ/*=0*/) // construct record i of basAnc b,
9393
b->n++ : additional record in static array.
9494
CAUTION can be called from statSetup (til eliminated). */
9595

96-
_b->validate("record::record"); // abort if base bad -- we depend on it for size
97-
if (!noZ) // can be suppressed for data-init (static) records
96+
_b->validate("record::record"); // abort if base bad -- we depend on it for size
97+
if (!noZ) // can be suppressed for data-init (static) records
9898
memset( (char *)this+SZVFTP, 0, _b->eSz-SZVFTP); /* zero all members of DERIVED CLASS record
9999
except virtFcnTblPtr in 1st 2 or 4 bytes (ancrec.h define) */
100100
b = _b;
@@ -685,9 +685,9 @@ SI FC basAnc::ancNext( USI &an, BP * _b) // (registered) record anchor iterator
685685
//---------------------------------------------------------------------------------------------------------------------------
686686
RC basAnc::validate( // validate an anchor: check self-consistency of anchor and its entry 0
687687

688-
char *fcnName, // calling fcn name, for err msgs.
689-
int erOp /*=ABT*/, // reporting control. ABT-->PABT, WRN-->PWRN here.
690-
SI noStat /*=0*/ ) // 0: caller's action OK on static-storage anchor. nz: not ok.
688+
const char* fcnName, // calling fcn name, for err msgs.
689+
int erOp /*=ABT*/, // reporting control. ABT-->PABT, WRN-->PWRN here.
690+
SI noStat /*=0*/ ) // 0: caller's action OK on static-storage anchor. nz: not ok.
691691

692692
// if error, issues message, returns non-RCOK if not ABT
693693
{

src/ANCREC.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
108108
static BP FC anc4n( USI an, int erOp=ABT); // access anchor by anchor #
109109
static RC FC findAnchorByNm( char *what, BP *b);
110110
static SI FC ancNext( USI &an, BP *_b); // iterate anchors
111-
RC validate( char *fcnName, int erOp=ABT, SI noStat=0); // check for valid anchor
111+
RC validate( const char* fcnName, int erOp=ABT, SI noStat=0); // check for valid anchor
112112
RC findRecByNm1( const char* _name, TI *_i, record **_r); // find record by 1st match on name
113113
RC findRecByNmU( const char* _name, TI *_i, record **_r); // find record by unique name match
114114
RC findRecByNmO( const char* _name, TI ownTi, TI *_i, record **_r); // find record by name and owner subscript

src/CGWTHR.CPP

Lines changed: 116 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,33 @@ void FC cgWthrClean( // cgwthr overall init/cleanup routine
5454
cgWfDone(); // close any open weather file
5555

5656
// init weather file info record
57-
Wfile.wf_Init(); // mbr function in wfpak.cpp sets record to say no file open
58-
Wthr.wd_Init(); // mbr function in wfpak.cpp clears record
59-
WthrNxHr.wd_Init(); // mbr function in wfpak.cpp clears record
57+
Wfile.wf_Init(); // sets record to say no file open
58+
Wthr.wd_Init(); // clears record
59+
WthrNxHr.wd_Init(); // clears record
6060

6161
// add any other init/cleanup found necessary or desirable
6262

6363
} // cgWthrClean
6464
//---------------------------------------------------------------------------
65-
RC TOPRAT::tp_WfInit() // Initialize weather file. Displays any error messages.
66-
// also uses: Top.tp_wfName [,.isDT]
65+
RC TOPRAT::tp_WthrInit() // Initialize weather data/ display any error messages.
66+
// also uses: tp_wfName, tp_TDVfName, [,.isDT]
6767
// returns non-RCOK if error, message already issued.
6868
{
6969
RC rc = Wfile.wf_Open( tp_wfName, tp_TDVfName); // open wthr file and option TDV file
7070
// init WFILE object, msg if error.
7171
if (!rc)
72-
rc = Wfile.wf_FillWDYEAR( WRN);
72+
rc = Wfile.wf_FillWDYEAR( WRN); // read/cache entire weather file
73+
// TODO: handle partial years
74+
75+
// design conditions
76+
// set any derived values
77+
// WHY here: location dependence, call after locinit
78+
DESCOND* pDC;
79+
RLUP( DcR, pDC)
80+
rc |= pDC->dc_RunInit();
81+
7382
return rc;
74-
} // TOPRAT::tp_WfInit
83+
} // TOPRAT::tp_WthrInit
7584
//---------------------------------------------------------------------------
7685
RC TOPRAT::tp_WthrBegHour() // start-hour weather stuff: read file, set up public Wthr and Top members.
7786
// tp_WthrBegSubhr must also be called, after this function.
@@ -432,7 +441,7 @@ RC WDHR::wd_WfReader( // read an hour's weather data and make adjustments
432441
if (Top.tp_AuszWthrSource() == TOPRAT_COOLDSCOND)
433442
{ // DSCOND design day: overwrite/adjust weather file values with generated
434443
int iDC = Top.tp_coolDsCond[ Top.tp_dsDayI-1];
435-
const DESCOND& DC = DCiB[ iDC];
444+
const DESCOND& DC = DcR[ iDC];
436445
wd_FillFromDESCOND( DC, iHrST);
437446
}
438447
}
@@ -517,7 +526,7 @@ RC WDHR::wd_WfReader( // read an hour's weather data and make adjustments
517526
rc = pWF->wf_Read( jDayST, iHrST, this, WRN|wfOp); // Read hour's data from weather file
518527
if (Top.tp_AuszWthrSource() == TOPRAT_COOLDSCOND)
519528
{ int iDC = Top.tp_coolDsCond[ Top.tp_dsDayI-1];
520-
const DESCOND& DC = DCiB[ iDC];
529+
const DESCOND& DC = DcR[ iDC];
521530
DC.dc_GenerateTemps( iHrST, this);
522531
523532
}
@@ -611,11 +620,12 @@ void WDHR::wd_FillFromDESCOND( // overwrite/adjust hourly data for design condi
611620
wd_taDbAvg14 += dbAvgDiff / 14.f;
612621
wd_taDbAvg31 += dbAvgDiff / 31.f;
613622

614-
615623
wd_wndSpd = dc.dc_wndSpd;
616624
wd_wndDir = 0.f;
617625

618-
if (wd_sunup)
626+
// derive irradiance
627+
// note: tauB/tauD both 0 -> no solar
628+
if (wd_sunup && dc.dc_tauB > 0.f && dc.dc_tauD > 0.f)
619629
wd_glrad = slASHRAETauModel(
620630
kPiOver2 - wd_slAlt,
621631
dc.dc_tauB, dc.dc_tauD,
@@ -636,17 +646,107 @@ void WDHR::wd_FillFromDESCOND( // overwrite/adjust hourly data for design condi
636646
/////////////////////////////////////////////////////////////////////////////
637647
RC DESCOND::dc_CkF() // check after input
638648
{ RC rc = RCOK;
639-
if (dc_MCWB > dc_DB)
640-
rc |= oer( "dcMCWB (%g) must be <= dcDB (%g)", dc_MCWB, dc_DB);
641649
return rc;
642650
} // DESCOND::dc_CkF
643651
//-----------------------------------------------------------------------------
644-
DOY DESCOND::dc_GetDOY() const
652+
#if defined( _DEBUG)
653+
static void DCTauTest( int doy)
645654
{
646-
return dc_day;
655+
float ebnlist[] = { 150.f, 200.f, 250.f, 300.f, -1.f };
656+
float edflist[] = { 20.f, 30.f, 40.f };
657+
658+
DESCOND dc( &DcR, 1);
659+
dc.dc_doy = doy;
660+
strcpy( dc.name, "Test");
661+
662+
for (int ib=0; ebnlist[ ib]>=0.f; ib++)
663+
{ dc.dc_ebnSlrNoon = ebnlist[ ib];
664+
for (int id=0; edflist[ id]>=0.f; id++)
665+
{ dc.dc_edhSlrNoon = edflist[ id];
666+
dc.dc_CheckFixSolar( 0);
667+
}
668+
}
669+
} // DCTauTest
670+
#endif
671+
//------------------------------------------------------------------------------
672+
RC DESCOND::dc_RunInit() // init for run
673+
// call after all input-time expressions have been evaluated
674+
// call after locInit (re latitude dependency)
675+
{
676+
#if defined( _DEBUG)
677+
static int tested = 0;
678+
if (!tested)
679+
{ DCTauTest( dc_doy);
680+
tested++;
681+
}
682+
#endif
647683

648-
} // DESCOND::dc_GetDOY
684+
RC rc = RCOK;
685+
686+
if (dc_MCWB > dc_DB)
687+
rc |= oer( "dcMCWB (%g) must be <= dcDB (%g)", dc_MCWB, dc_DB);
649688

689+
// if any solar values given, check and cross-derive
690+
// else leave all 0 = no solar
691+
if (dc_tauB + dc_tauD + dc_ebnSlrNoon + dc_edhSlrNoon > 0.f)
692+
{ int nTau = IsSetCount( DESCOND_TAUB, DESCOND_TAUD, 0);
693+
int nE = IsSetCount( DESCOND_EBNSLRNOON, DESCOND_EDHSLRNOON, 0);
694+
if (nTau == 0)
695+
rc |= dc_CheckFixSolar( 0); // derive tauB / tauD
696+
else if (nE == 0)
697+
rc |= dc_CheckFixSolar( 1); // derive Ebn / Edh
698+
else
699+
rc |= oer( "must give either dcTauB/dcTauD and"
700+
" not dcEbnSlrNoon/dcEdhSlrNoon or vice-versa");
701+
}
702+
else
703+
oInfo( "no irradiance due to dcTauB/dcTauD/dcEbnSlrNoon/dcEdhSlrNoon all 0");
704+
705+
return rc;
706+
} // DESCOND::dc_RunInit
707+
//-----------------------------------------------------------------------------
708+
RC DESCOND::dc_CheckFixSolar(
709+
int options) // option bits
710+
// 0: derive tau from solar noon
711+
// 1: derive solar noon from tau
712+
{
713+
RC rc = RCOK;
714+
715+
// solar noon angles
716+
slday( dc_doy, SLTMSOLAR, 1);
717+
float sunAlt, sunAzm;
718+
slaltazm( 12.f, &sunAlt, &sunAzm);
719+
float sunZen = kPiOver2 - sunAlt;
720+
721+
if (options & 1)
722+
{ rc |= limitCheck( DESCOND_TAUB, .08, 1.)
723+
| limitCheck( DESCOND_TAUD, 1.2, 3.2);
724+
if (!rc)
725+
slASHRAETauModel( sunZen, dc_tauB, dc_tauD,
726+
dc_ebnSlrNoon, dc_edhSlrNoon);
727+
}
728+
else
729+
{ rc |= limitCheck( DESCOND_EBNSLRNOON, 0., 370.)
730+
| limitCheck( DESCOND_EDHSLRNOON, 0., 110.);
731+
if (!rc)
732+
{ bool ret = slASHRAETauModelInv( sunZen, dc_ebnSlrNoon, dc_edhSlrNoon,
733+
dc_tauB, dc_tauD);
734+
if (!ret)
735+
rc = oer( "failed to derive dcTauB and dcTauD."
736+
" Check dcEbnSlrNoon and dcEdhSlrNoon input values.");
737+
#if defined( _DEBUG)
738+
else
739+
{ float ebn, edh;
740+
float egl = slASHRAETauModel( sunZen, dc_tauB, dc_tauD, ebn, edh);
741+
if (frDiff( ebn, dc_ebnSlrNoon) > .01f
742+
|| frDiff( edh, dc_edhSlrNoon) > .01f)
743+
oWarn( "ebn/edh mismatch");
744+
}
745+
#endif
746+
}
747+
}
748+
return rc;
749+
} // DESCOND::dc_CheckFixSolar
650750
//-----------------------------------------------------------------------------
651751
void DESCOND::dc_GenerateTemps(
652752
int iHr, // hour of day (0 - 23)

src/CNAUSZ.CPP

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const char* TOPRAT::tp_AuszDoing() const // current autosizing activity
105105
else
106106
{ int auszDoy;
107107
if (iAWS == TOPRAT_COOLDSCOND)
108-
auszDoy = DCiB[ tp_coolDsCond[ iDs]].dc_GetDOY();
108+
auszDoy = DcR[ tp_coolDsCond[ iDs]].dc_GetDOY();
109109
else if (iAWS == TOPRAT_COOLDSDAY)
110110
auszDoy = tp_coolDsDay[ iDs];
111111
if (auszDoy > 0)
@@ -232,7 +232,7 @@ x tp_dsDay = 1 + (tp_dsDayI != 0); // 1st desDay is heating (1), others coolin
232232
auszMon = tp_date.month;
233233
}
234234
else if (tp_AuszWthrSource() == TOPRAT_COOLDSCOND)
235-
{ const DESCOND* pDC = DCiB.GetAtSafe( tp_coolDsCond[ tp_dsDayI-1]);
235+
{ const DESCOND* pDC = DcR.GetAtSafe( tp_coolDsCond[ tp_dsDayI-1]);
236236
jDay = pDC->dc_GetDOY();
237237
tddyi( tp_date, jDay);
238238
auszMon = tp_date.month;

src/CNCULT.CPP

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ makAncRI2(XiB,"export"); // EXPORT input info
117117
makAncCOL(RcoliB); // REPORTCOL input info for UDT reports
118118
makAncCOL2(XcoliB,"exportCol"); // EXPORTCOL input info for UDT exports
119119
makAncIMPF(ImpfiB); // IMPORTFILE input info, 2-94
120-
// holidays
120+
121121
makAncHDAY(HdayiB); // HDAY input info
122122
makAncDESCOND(DCiB); // DESCOND input info
123123

@@ -2433,15 +2433,19 @@ static CULT dcT[] =
24332433
//---------- ----- --------------- ------- -- ------ ------ ---- ---------- ---- ----
24342434
CULT( "*", STAR, 0, 0, 0, 0, 0, 0, 0.f, N, dcStarCkf),
24352435

2436-
CULT( "dcDay", DAT, DESCOND_DAY, RQD, 0, VEOI, TYDOY, 0, 200, N, N),
2436+
CULT( "dcDay", DAT, DESCOND_DOY, RQD, 0, VEOI, TYDOY, 0, 200, N, N),
24372437

24382438
CULT( "dcDB", DAT, DESCOND_DB, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
24392439
CULT( "dcMCDBR", DAT, DESCOND_MCDBR, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
24402440
CULT( "dcMCWB", DAT, DESCOND_MCWB, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
24412441
CULT( "dcMCWBR", DAT, DESCOND_MCWBR, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
24422442
CULT( "dcWindSpeed",DAT, DESCOND_WNDSPD, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
2443-
CULT( "dcTauB", DAT, DESCOND_TAUB, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
2444-
CULT( "dcTauD", DAT, DESCOND_TAUD, RQD, 0, VEOI, TYFL, 0, 0.f, N, N),
2443+
// Taub/Taud and Ebn/Ebh interact, see dc_TopDC
2444+
CULT( "dcTauB", DAT, DESCOND_TAUB, 0, 0, VEOI, TYFL, 0, 0.f, N, N),
2445+
CULT( "dcTauD", DAT, DESCOND_TAUD, 0, 0, VEOI, TYFL, 0, 0.f, N, N),
2446+
CULT( "dcEbnSlrNoon",DAT, DESCOND_EBNSLRNOON,0, 0, VEOI, TYFL, 0, 0.f, N, N),
2447+
CULT( "dcEdhSlrNoon",DAT, DESCOND_EDHSLRNOON,0, 0, VEOI, TYFL, 0, 0.f, N, N),
2448+
24452449

24462450
CULT( "endDesCond", ENDER, 0, 0, 0, 0, 0, 0, 0.f, N, N),
24472451
CULT()

src/CNCULT2.CPP

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,8 @@ const char* TOPRAT::When( IVLCH ivl) const // date / time doc for error message
815815
return s;
816816
} // TOPRAT::When
817817
//-----------------------------------------------------------------------------
818-
LOCAL RC topDC() // finalize DESCONDs
819-
{ RC rc = RCOK;
820-
// input records used at runtime, nothing to do
818+
LOCAL RC topDC() // copy input DESCONDs to run records
819+
{ RC rc = DcR.RunDup( DCiB);
821820
return rc;
822821
} // topDC
823822
//-----------------------------------------------------------------------------

src/CNGUTS.CPP

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void FC runFazDataFree()
208208

209209
// Note: entries are put into most of these in input code in cncult2.cpp:topCkf and its subfcns.
210210

211-
ZrB.free(); // Zones runtime info. basAnc::free is in lib\ancrec.cpp.
211+
ZrB.free(); // Zones runtime info
212212
ZnresB.free(); // zone simulation results
213213
RSysResR.free(); // RSYS results
214214
IzxR.free(); // interzone transfers
@@ -925,9 +925,10 @@ RC FC cgRddInit( // Perform initialization common to main simulation run and eac
925925
// inits Locsolar (comments below)
926926
// EF: return RCBAD on any non-RCOK return.
927927

928-
// Set up weather file
929-
// do each phase, allowing name to change. Messages errors.
930-
EF( Top.tp_WfInit() ) // also uses Top .tp_wfName, .skyModel [,.isDT]. EF: return RCBAD if error.
928+
// Set up weather file, TDV file, and DESCONDs
929+
// Do each phase, allowing file or location changes.
930+
// Messages errors.
931+
EF( Top.tp_WthrInit() ) // also uses Top .tp_wfName, .skyModel [,.isDT]
931932

932933
// Open import files used in this run, if any
933934
EF( impfStart() ) // impf.cpp. related code: cncult4.cpp, cuparse.cpp.
@@ -2503,7 +2504,7 @@ LOCAL void FC NEAR binResInit( int isAusz) // initialize & open binary results (
25032504
/* ***** TEMPORARY weather file info for initial DL test graphs ***** 9-4-94
25042505
Make names match values passed to setHourInfo() in doIvlAccum()!
25052506
Expect will depend on wf type.
2506-
Coordinate via tp_WfInit (xxx called in this fcn about 100 lines up) ***** */
2507+
Coordinate via tp_WthrInit(xxx called in this fcn about 100 lines up) ***** */
25072508
#ifdef TWOWV // bfr.h 9-94
25082509
2, "Est Direct", "Est Diffuse" ) ) // # dl weather vbls and their names. Estimated from CEC wthr file for now.
25092510
#else
@@ -2555,15 +2556,15 @@ static SLLOCDAT* NEAR Locsolar = NULL; /* Ptr to solar info structure (slpak.h)
25552556
Daily info set by slpak:slday from cgwthr.cpp and cgsolar.cpp at least, 1-95. */
25562557
//------------------------------------------------------------------------
25572558
LOCAL RC FC NEAR locInit() // location-initializer for cne
2558-
// inits lib\slpak.cpp using location info in Top members (gotten weather file and/or user input in cncultx.cpp)
2559+
// inits slpak.cpp using location info in Top members (gotten weather file and/or user input in cncultx.cpp)
25592560
// returns RCOK if ok, else message already issued.
25602561
{
2561-
/* init lib\slpak.cpp: alloc SLLOCDAT (slpak.h) and init for location.
2562-
More of Locsolar is set each day by slday(). It is used by most other slpak calls.
2563-
slpak remembers its location internally. */
2562+
// init slpak.cpp: alloc SLLOCDAT (slpak.h) and init for location.
2563+
// More of Locsolar is set each day by slday(). It is used by most other slpak calls.
2564+
// slpak remembers its location internally.
25642565

25652566
Locsolar = slinit( RAD( Top.latitude), // latitude (to radians)
2566-
RAD( Top.longitude), // longitude
2567+
RAD( Top.longitude), // longitude
25672568
Top.timeZone, // time zone
25682569
Top.elevation ); // site altitude (ft)
25692570
return RCOK;

src/CNGUTS.H

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ extern anc<WFDATA> WthrR; // basAnc for hour's weather data record. Runtime onl
113113
extern WFDATA Wthr; // the one static WFDATA record containing unpacked & adjusted data for hour 1-94
114114
extern anc<WFDATA> WthrNxHrR; // basAnc for next hour's weather data record ("weatherNextHour")
115115
extern WFDATA WthrNxHr; // static record for next hour's unpacked & adjusted data for cgwthr.cpp read-ahead
116-
117-
extern anc<DESCOND> DCiB; // design conditions (input records only)
116+
extern anc<DESCOND> DcR; // design conditions
118117

119118
extern anc<ZNR> ZrB; // zones runtime info
120119
extern anc<ZNRES> ZnresB; // Zones simulation results info

0 commit comments

Comments
 (0)