Skip to content

Commit 7ce1c66

Browse files
authored
Merge pull request #105 from cse-sim/solarinterp
Solarinterp
2 parents 56b9888 + 134503c commit 7ce1c66

35 files changed

+34181
-17800
lines changed

src/CGCOMP.CPP

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,10 @@ const double G0STDX = g0Std; // CSE accel. of gravity, ft/sec2
508508
// class ANDAT -- airnet data
509509
void ANDAT::ad_ClearResults()
510510
{
511-
ad_delP = 0.;
511+
ad_delP = ad_dmdp = 0.;
512512
ad_mdotP = ad_mdotB = ad_mdotX = 0.;
513-
ad_dmdp = 0.;
514-
ad_xDelpF = 0.;
515-
ad_xMbm = 0.;
516-
ad_tdFan = 0.;
517-
ad_pFan = 0.;
513+
// ad_xDelpF = ad_xMbm = 0.; do not clear (values retained throughout hour)
514+
ad_tdFan = ad_pFan = 0.;
518515

519516
} // ANDAT::ad_ClearResults
520517
//-----------------------------------------------------------------------------

src/CGSOLAR.CPP

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,9 @@ void FC makHrSgt( // make solar tables for an hour for current month
418418
// Re-initialize slpak for current day as assumed by cgwfread() called from cnguts.cpp each hour b4 this fcn.
419419
// Don't know a) if other parts of program depend on it (else do in wswfread each call)
420420
// b) if would be faster to push & pop the data it sets.
421-
slday( Top.jDayST, // julian date of simulation (standard time), cnguts.cpp. Use of ST matches call in cgwthr.cpp.
422-
SLTMLST ); // say use local standard time
421+
slday(Top.jDayST, // julian date of simulation (standard time), cnguts.cpp. Use of ST matches call in cgwthr.cpp.
422+
SLTMLST, // say use local standard time
423+
1); // skip if no day change
423424
// slpak.cpp: set up curr SLLOCDAT struct (which is cse.cpp:Locsolar) for given day:
424425
// sets info re declination of earth's axis, hourly sunupf[], dircos[], slazm[], etc.
425426
// Used by most other slpak calls.
@@ -873,7 +874,7 @@ void SgThruWin::tw_Doit()
873874

874875
// target gain for SGDISTs
875876

876-
for (sgi = 0; sgi < tw_xr->x.nsgdist; sgi++) // explicit user-entered targets
877+
for (int sgi = 0; sgi < tw_xr->x.nsgdist; sgi++) // explicit user-entered targets
877878
{
878879
SGDIST* sgd = tw_xr->x.sgdist + sgi; // point to sgdist
879880
if (sgd->sd_targTy == SGDTTSURFI || sgd->sd_targTy == SGDTTSURFO)

src/CGWTHR.CPP

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ RC TOPRAT::tp_WthrInit() // Initialize weather data/ display any error message
8181
return rc;
8282
} // TOPRAT::tp_WthrInit
8383
//---------------------------------------------------------------------------
84+
RC TOPRAT::tp_WthrBegDay()
85+
{
86+
RC rc = RCOK;
87+
rc = Wfile.wf_UpSampleDay(jDay);
88+
89+
return rc;
90+
} // TOPRAT::tp_WthrBegDay
91+
//---------------------------------------------------------------------------
8492
RC TOPRAT::tp_WthrBegHour() // start-hour weather stuff: read file, set up public Wthr and Top members.
8593
// tp_WthrBegSubhr must also be called, after this function.
8694

@@ -259,6 +267,16 @@ o else { aes = 0.f; bes = 1.5f - g; ces = g - .5f; }
259267
radBeamShAv = (a * radBeamPvHrAv + b * radBeamHrAv + c * radBeamNxHrAv) * beamAdj;
260268
radDiffShAv = (a * radDiffPvHrAv + b * radDiffHrAv + c * radDiffNxHrAv) * diffAdj;
261269

270+
#if 0
271+
float radBeamX, radDiffX;
272+
Wfile.wf_GetSubhrSolar(iHr, iSubhr, radBeamX, radDiffX);
273+
if (frDiff(radBeamShAv, radBeamX) > .001f || frDiff(radDiffShAv, radDiffX) > .001f)
274+
{
275+
printf("\nSolar mismatch");
276+
Wfile.wf_UpSampleDay(jDay);
277+
}
278+
#endif
279+
262280
// Interpolate end-subhour instantaneous values for same data
263281

264282
#ifdef SOLAVNEND // undef in cndefns.h
@@ -396,31 +414,46 @@ RC WDHR::wd_WfReader( // read an hour's weather data and make adjustments
396414
rc = pWF->wf_Read( this, jDayST, iHrST, WRN|wfOp); // Read hour's data from weather file
397415
break;
398416
}
399-
if (rc) // if wfRead failed, eg date not in file or type without design days
400-
return rc;
401-
402-
// Optional anisotropic sky adjustment
403-
// Do NOT adjust wd_DNI, wd_DHI
404-
if (Top.skyModel==C_SKYMODCH_ANISO)
405-
slaniso( &wd_bmrad, &wd_dfrad, iHrST); // adjust data in place to approx model sky brighter
406-
// near sun, etc, while still computing with sun's
407-
// beam and isotropic diffuse radiation. slpak.cpp. */
417+
#if defined( SOLARFIX)
418+
#if defined( _DEBUG)
419+
float bmrad = wd_DNI;
420+
float dfrad = wd_DHI;
421+
if (Top.skyModel == C_SKYMODCH_ANISO)
422+
slaniso(&bmrad, &dfrad,iHrST);
423+
if (frDiff(bmrad, wd_bmrad) > .0001f
424+
|| frDiff(dfrad, wd_dfrad) > 0.0001f)
425+
printf("\nDiff");
426+
#endif
427+
#else
428+
if (!rc) // if wfRead failed, eg date not in file or type without design days
429+
wd_Adjust(iHrST);
430+
#endif
431+
432+
return rc;
433+
} // WDHR::wd_WfReader
434+
//-----------------------------------------------------------------------------
435+
void WDHR::wd_Adjust( // apply adjustments to weather data
436+
int iHrST) // standard time hour of day (0-23)
437+
{
408438

409-
// other adjustments
410-
wd_bmrad *= Top.radBeamF; // Adjust radiation values for possible user input factors, defaults 1.0.
411-
wd_dfrad *= Top.radDiffF; // ..
412-
wd_wndSpd = Top.windF * max( wd_wndSpd, Top.windSpeedMin);
413-
// apply wind speed min (user input, default = .5)
414-
// and adjust by factor (per user input, default .25)
439+
// Optional anisotropic sky adjustment
440+
// Do NOT adjust wd_DNI, wd_DHI
441+
if (Top.skyModel == C_SKYMODCH_ANISO)
442+
slaniso(&wd_bmrad, &wd_dfrad, iHrST); // adjust data in place to approx model sky brighter
443+
// near sun, etc, while still computing with sun's
444+
// beam and isotropic diffuse radiation. slpak.cpp. */
415445

416-
// Ensure solar data values are not negative (as found in some CSW files)
417-
wd_bmrad = max(wd_bmrad, 0.f);
418-
wd_dfrad = max(wd_dfrad, 0.f);
419-
wd_glrad = max(wd_glrad, 0.f);
446+
// other solar adjustments
447+
// ensure solar data values are not negative (as found in some CSW files)
448+
wd_bmrad = max( Top.radBeamF*wd_bmrad, 0.f); // Adjust radiation values by possible user input factors, defaults 1.0.
449+
wd_dfrad = max( Top.radDiffF*wd_dfrad, 0.f); // ..
450+
wd_glrad = max(wd_glrad, 0.f); // TODO: re-derive from adjusted wd_bmrad and wd_dfrad?
420451

452+
wd_wndSpd = Top.windF * max(wd_wndSpd, Top.windSpeedMin);
453+
// apply wind speed min (user input, default = .5)
454+
// and adjust by factor (per user input, default .25)
421455

422-
return rc;
423-
} // WDHR::wd_WfReader
456+
} // WDHR::wd_Adjust
424457
//---------------------------------------------------------------------------
425458
void FC cgWfDone() // Close, clean up hourly simulator weather file
426459
{

src/CNDEFNS.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@
132132
#define DIM_POLYGONXYZ 37 // input arrays dimension
133133
// = MAX_POLYLPVERTICIES*3 + 1
134134

135-
#undef SOLARFIX // define to correct timing of slday() calls
135+
#define SOLARFIX // define to correct timing of slday() calls
136136
// and definition of HA, 10-25-2017
137-
137+
// plus add'l changes, 8-2020
138138
#endif // ifndef _CNEDEFNS_H
139139

140140
// cndefns.h end

src/CNGUTS.CPP

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ LOCAL RC FC NEAR doBegIvl() // simulation run start-of-interval processing: init
504504
Top.tp_DoDateDowStuff();
505505
// CAUTION: Top.iHr may be --'d or ++'d in tp_DoDTStuff in C_IVLCH_H case if DT starts or ends.
506506
Top.isSolarCalcDay = Top.isBegMonth; // do solar calcs on warmup/run/mon 1st day and dsn day 1st rep.
507+
Top.tp_WthrBegDay();
507508
cgReportsDaySetup(); // init zones & Top re date-dependent reports and exports.
508509
// set zp-> lists; may print heads. Uses jDay. cgresult.cpp.
509510

src/CNRECS.DEF

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,17 @@ RECORD TOPRAT "top" *RAT /* top level RAT: contains control info and all once-on
517517
*s POWER radBeamShAv // .. current beam subhour average power, interpolated, Btuh/ft2
518518
#ifdef SOLAVNEND // cndefns.h (via cnglob.h) 1-18-94: only if computing & using end-ivl as well as ivl avg solar values
519519
o *s POWER radBeamSh // .. end subhour instantaneous value, interpolated
520-
#else
521-
FLOAT radBeamShSpare
522520
#endif
523521
*h POWER radDiffHrAv // diffuse irradiance on horizontal surface, hour energy = average power, from weather file
524522
*h POWER radDiffPvHrAv // .. flavors as for radBeam
525523
*h POWER radDiffNxHrAv // ..
526524
*s POWER radDiffShAv // .. current diffuse subhour power, interpolated by cgwthr.cpp, Btuh/ft2
527525
#ifdef SOLAVNEND // cndefns.h
528526
o *s POWER radDiffSh // .. end subhour instantaneous value, interpolated
529-
#else
530-
FLOAT radDiffShSpare
531527
#endif
532528

533529
// other weather: weather file contains instantaneous values for END OF HOUR; program needs only end-interval values.
530+
*declare "RC tp_WthrBegDay();"
534531
*declare "RC tp_WthrBegHour();"
535532
*declare "RC tp_WthrBegSubhr();"
536533
*h TEMP tDbOHr // outdoor dry bulb temp at end of hour, from wthr file, deg F.
@@ -690,6 +687,8 @@ RECORD WFILE "weatherFile" *RAT // weather file info, one static instance "Wfile
690687
*declare "RC wf_EtDecodeHdr( char* hdr, int erOp, float* clrnss, float* turbid, float* atmois);"
691688
*declare "RC wf_DecodeHdrFields( char* hdr, struct WFHTAB* wfht0, int erOp);"
692689
*declare "RC wf_FillWDYEAR( int erOp=WRN);"
690+
*declare "RC wf_UpSampleDay( int jDay);"
691+
*declare "void wf_GetSubhrSolar( int iHr, int iSh, float& radBeam, float& radDiff) const;"
693692
*declare "RC wf_Read( WDHR* pWd, int jDay, int iHr, int erOp = WRN);"
694693
*declare "USI* wf_PackedHrRead( int jDay, int iHr, int erOp = WRN);"
695694
*declare "LI wf_PackedHrOffset( int jDay, int iHr, int erOp = WRN);"
@@ -769,6 +768,7 @@ RECORD WDHR "wfdata sub" *SUBSTRUCT // hourly data substructure for WFDATA
769768
*declare "void wd_Init( int options=0);"
770769
*declare "WDHR& Copy( const WDHR& wd, int options=0);"
771770
*declare "RC wd_WfReader( BOO nextHour, WFILE* pWF);"
771+
*declare "void wd_Adjust( int iHrST);"
772772
*declare "RC wd_Unpack( int iH, USI* pHour, int wFileFormat=ET1);"
773773
*declare "RC wd_EstimateMissingET1( int iHr);"
774774
*declare "float wd_CalcSkyTemp( int skyModelLW, int iHr);"

src/SLPAK.CPP

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ void FC slday( // set up daily data in current SLLOCDAT
352352
if ((options & 1) && slloccur->doy == doy && slloccur->timetype == timetype)
353353
return; // already set for doy
354354

355-
#if 0 && defined(_DEBUG)
356-
printf("\nslday %d %d", doy, timetype);
357-
#endif
358-
359355
slloccur->doy = doy;
360356

361357
float dec;
@@ -746,35 +742,35 @@ void FC slaltazm(/* Calculate solar altitude and azimuth for hour */
746742
} /* slaltazm */
747743
//======================================================================
748744
void FC slaniso(/* Adjust beam and diffuse radiation values
749-
according to Hay anisotropic sky model */
750-
751-
float *pbeam, /* Pointer to beam value (Btu/sf): used/replaced. */
752-
float *pdiff, /* Pointer to diffuse value (Btu/sf): used/replaced.*/
753-
SI ihr) /* Hour of day (0 - 23, 0 = midnight to 1 AM).
754-
Meaning of hour (LST, solar time, etc.)
755-
depends on how SLLOCDAT was set up by slday(). */
756-
757-
/* must call slday() for day first (uses slloccur members) */
758-
759-
/* Adjusted values of beam and diffuse *REPLACE* the current values */
760-
761-
/* Story: Code assumes sky is modelled as istropic (uniform) hemisphere of
762-
sky radiation plus direct sun beam. But actually, sky is brighter
763-
near sun, near horizon, etc. Hay model approximates reality better
764-
with old code by increasing beam to approximate some of the extra sky
765-
brightness near sun. Rob per Chip, 12-89. */
766-
767-
/* Recoded 2-10-89 based on cp4sim equivalent function. Features --
768-
1. Doesn't bother unless there is a little beam
769-
2. Constrains fb to be .8 max. This prevents wild values from
770-
early morning observations.
771-
3. Derives fd (diffuse factor) from fb rather than from basic
772-
Hay formula, giving same result unless fb hit .8 limit. In all
773-
cases, total horiz is preserved */
745+
according to Hay anisotropic sky model */
746+
747+
float *pbeam, /* Pointer to beam value (Btu/sf): used/replaced. */
748+
float *pdiff, /* Pointer to diffuse value (Btu/sf): used/replaced.*/
749+
SI ihr) /* Hour of day (0 - 23, 0 = midnight to 1 AM).
750+
Meaning of hour (LST, solar time, etc.)
751+
depends on how SLLOCDAT was set up by slday(). */
752+
753+
/* must call slday() for day first (uses slloccur members) */
754+
755+
/* Adjusted values of beam and diffuse *REPLACE* the current values */
756+
757+
/* Story: Code assumes sky is modelled as istropic (uniform) hemisphere of
758+
sky radiation plus direct sun beam. But actually, sky is brighter
759+
near sun, near horizon, etc. Hay model approximates reality better
760+
with old code by increasing beam to approximate some of the extra sky
761+
brightness near sun. Rob per Chip, 12-89. */
762+
763+
/* Recoded 2-10-89 based on cp4sim equivalent function. Features --
764+
1. Doesn't bother unless there is a little beam
765+
2. Constrains fb to be .8 max. This prevents wild values from
766+
early morning observations.
767+
3. Derives fd (diffuse factor) from fb rather than from basic
768+
Hay formula, giving same result unless fb hit .8 limit. In all
769+
cases, total horiz is preserved */
774770
{
775-
SI pos1, pos2;
776-
SI ihx;
777-
float c1, c2, cosi, f, fb, fd;
771+
SI pos1, pos2;
772+
SI ihx;
773+
float c1, c2, cosi, f, fb, fd;
778774

779775
if (*pbeam > 5.f) /* if a little beam */
780776
{

0 commit comments

Comments
 (0)