Skip to content

Commit 1a48f58

Browse files
authored
Merge pull request #9 from cse-sim/shading
SHADEX and PVARRAY vertex input.
2 parents 35afaa1 + 86c7bda commit 1a48f58

File tree

8 files changed

+192
-59
lines changed

8 files changed

+192
-59
lines changed

src/ANCREC.CPP

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int record::IsSetAny(
271271
}
272272
} // record::IsSetAny
273273
//-----------------------------------------------------------------------------
274-
int record::IsValAll(
274+
int record::IsValAll( // check for resolved (non-expression) values
275275
int fn, ...) const // 0 terminated fn list (don't forget the 0!)
276276
// return 1 iff all fields have values
277277
{ va_list ap;
@@ -365,23 +365,49 @@ o what );
365365
} // record::classObjTx
366366
//=============================================================================
367367

368-
//***************************************************************************************************************************
368+
///////////////////////////////////////////////////////////////////////////////
369+
// public helper functions
370+
///////////////////////////////////////////////////////////////////////////////
371+
RC ArrayStatus( // count/check status of ARRAY elements
372+
const UCH* _sstat0, // status array
373+
int count, // # of values to check (dimension of array
374+
int& nSet, // returned: # of array elements set (FsSet)
375+
int& nVal) // returned: # of array elements with value (FsVAL)
376+
// re checking of ARRAY input
377+
// returns RCOK on success
378+
// RCBAD iff malformed (impossible unless bug?)
379+
{
380+
RC rc = RCOK;
381+
int n0 = 0; // # of 0 status
382+
nSet = nVal = 0;
383+
for (int fn=0; fn < count; fn++)
384+
{ int stat = _sstat0[ fn];
385+
if (stat == 0)
386+
n0++;
387+
else
388+
{ if (n0)
389+
rc = RCBAD; // 0 followed by non-0
390+
if (stat & FsSET)
391+
nSet++;
392+
if (stat & FsVAL)
393+
nVal++;
394+
}
395+
}
396+
return rc;
397+
} // ::ArrayStatus
398+
//=============================================================================
399+
400+
//*****************************************************************************
369401
// class basAnc: base class for application record anchors.
370-
//***************************************************************************************************************************
402+
//*****************************************************************************
371403

372404
//--- variables re "anchor numbers". ancBase.ancN contains #.
373-
#if defined( ANC_DTOR)
374405
const int MAXANCS = 200; // Maximum number of basAncs supported
375406
// actual required = ~65 12-20-2012
376407
static BP ancs[ MAXANCS]; // table of pointers to contructed basAncs
377408
// persists for entire session re multiple DLL cse() calls
378409
// "big enuf" static array simplifies persistence
379410
static int Nanc = -1; // # of entries in anc[] (-1 = unintialized) (see regis())
380-
#else
381-
LOCAL BP * NEAR ancs = NULL; // dm array of NEAR ptrs to basAncs by #. excludes b.tyB's (not regis'd by cul.cpp).
382-
LOCAL USI NEAR Nanc = 0; // max ancN in use (0 unused)
383-
LOCAL USI NEAR ancNal = 0; // ancs size: # #'s allocated
384-
#endif
385411
//---------------------------------------------------------------------------------------
386412
basAnc::basAnc() // default c'tor (for derived copy c'tor
387413
{
@@ -405,16 +431,13 @@ basAnc::basAnc( USI _flags, SFIR * _fir, USI _nFlds, char * _what, USI _eSz, RCT
405431
//--------------------------------------------------------------------------------------------------------------
406432
/*virtual*/ basAnc::~basAnc() // d'tor
407433
{
408-
#if defined( ANC_DTOR)
409434
if (flags & RFTYS)
410435
dmfree( DMPP( what));
411-
#endif
412436
} // basAnc::~basAnc
413437
//---------------------------------------------------------------------------------------------------------------------------
414438
void FC basAnc::regis() // "register" anchor for nextAnc() iteration. Constructor helper.
415439
{
416440
int an;
417-
#if defined( ANC_DTOR)
418441
if (Nanc < 0) // if not initialized
419442
{ VZero( ancs, MAXANCS);
420443
Nanc = 0;
@@ -423,12 +446,6 @@ void FC basAnc::regis() // "register" anchor for nextAnc() iteration. Constr
423446
; // (or one already set for this anc: reconstr insurance)
424447
if (an >= MAXANCS)
425448
err( PABT, "Insufficient anc[] space");
426-
#else
427-
if (!ancs || ancNal < Nanc + 2) // if necessary
428-
dmral( DMPP( ancs), (ancNal += 32) * sizeof(BP), DMZERO|ABT); // enlarge array of pointers
429-
for (an = 1; ancs[an] && ancs[an] != this; an++) // find free pointer
430-
; // (or one already set for this anc: reconstr insurance)
431-
#endif
432449
ancs[an] = this; // set pointer in static array
433450
Nanc = max( Nanc, an);
434451
ancN = an; // set index in anchor
@@ -452,30 +469,15 @@ void FC cleanBasAncs( // destroy/free all basAnc records, and delete subsidiary
452469
if (!b)
453470
continue; // skip (unexpected) NULL pointer
454471
b->free(); // destroy b's records, free record memory unless static, clear flags
455-
#if defined( ANC_DTOR)
456472
delete b->tyB;
457473
b->tyB = NULL;
458-
#else
459-
if (b->tyB) // if b has a subsidiary "types" ancRec (not registered; in heap)
460-
{
461-
b->tyB->free(); // destroy/free its records (believed redundant)
462-
dmfree( DMPP( b->tyB->what)); // free its "what" string if non-NULL, set pointer NULL
463-
delete (basAnc *)b->tyB; // destroy types basAnc and free its memory. cast makes ptr pointer.
464-
b->tyB = 0; // 16-bit-NULL tyB pointer
465-
}
466-
#endif
467474
}
468475

469-
if (cs == DONE || cs == CRASH)
470-
{
471-
#if !defined( ANC_DTOR)
472-
Nanc = 0;
473-
ancNal = 0;
474-
dmfree( DMPP( ancs));
475-
#endif
476-
}
477-
// else
478-
// ancs[] is built by c'tor, thus must persist from entry to entry (all non-tyB ancRecs believed static).
476+
// if (cs == DONE || cs == CRASH)
477+
// { // nothing to do
478+
// }
479+
// else
480+
// ancs[] is built by c'tor, thus must persist from entry to entry (all non-tyB ancRecs believed static).
479481

480482
clearFileIxs(); // clear file names referenced by record.fileIx members
481483
} // cleanBasAncs

src/ANCREC.H

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,8 @@ x n = nAl = 0; // say no records in use, none allocated: insurance
361361
// if this anchor has user language subsidiary 'type' records anchor, destroy it and its records
362362
if (tyB) // .tyB is basAnc *
363363
{
364-
#if defined( ANC_DTOR)
365364
delete tyB;
366365
tyB = NULL;
367-
#else
368-
dmfree( DMPP( tyB->what)); // free its "what" string if non-NULL, set ptr NULL
369-
delete (basAnc *)tyB; // basAnc d'tor is virtual, so this should call here to destroy records.
370-
tyB = 0; // insurance. ...10-93 need to be sure all rec d'tors free all heap ptrs!
371-
#endif
372366
}
373367
} // anc<T>::~anc
374368
//-------------------------------------------------------------------------------------------------------------------------
@@ -429,6 +423,7 @@ template <class T> T* anc<T>::GetAt( int i) const
429423
///////////////////////////////////////////////////////////////////////////////
430424
// ancrec.cpp non-member fcn declarations
431425
//-----------------------------------------------------------------------------
426+
RC ArrayStatus( const UCH* _sstat0, int count, int& nSet, int& nVal);
432427
void FC cleanBasAncs( CLEANCASE cs); // destroy/free all basAnc records, and delete subsidiary "types" basAncs (.tyB)
433428

434429
// functions for saving file names for record.fileIx 2-94

src/CNCULT.CPP

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ CULT()
10211021

10221022

10231023
//===================================== GAIN command for ZONE ============================================
1024-
LOCAL RC FC gnStarCkf( CULT* c, /*PVARRAY* */ void *p, void *p2, void *p3)
1024+
LOCAL RC FC gnStarCkf( CULT* c, /*GAIN* */ void *p, void *p2, void *p3)
10251025
// called at end of GAIN input, to get messages near source of error.
10261026
{
10271027
return ((GAIN*)p)->gn_CkF( 0);
@@ -1966,6 +1966,7 @@ LOCAL RC FC pvStarCkf( CULT* c, /*PVARRAY* */ void *p, void *p2, void *p3)
19661966
return ((PVARRAY*)p)->pv_CkF();
19671967
} // pvStarCkf
19681968
//=============================================================================
1969+
#define PVG( m) (PVARRAY_G+SURFGEOM_##m)
19691970
static CULT pvArrT[] = //------ PVARRAY cmd RAT Entry table, used from cnTopCult
19701971
{
19711972
// id cs fn f uc evf ty b dfls p2 ckf
@@ -1986,6 +1987,7 @@ CULT( "pvDCtoACRatio", DAT, PVARRAY_DCACRAT, 0, 0, VEOI, TYFL, 0,
19861987
CULT( "pvInverterEff", DAT, PVARRAY_INVEFF, 0, 0, VEOI, TYFL, 0, 0.96f, N, N),
19871988
CULT( "pvSysLosses", DAT, PVARRAY_SYSLOSS, 0, 0, VHRLY, TYFL, 0, 0.14f, N, N),
19881989
CULT( "pvUsePVWatts", DAT, PVARRAY_USEPVWATTSDLL, 0, 0, VEOI, TYCH, 0, C_NOYESCH_NO, N, N),
1990+
CULT( "pvVertices", DAT, PVG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v DIM_POLYGONXYZ, N),
19891991
CULT( "endPVARRAY", ENDER, 0, 0, 0, 0, 0, 0, 0.f, N, N),
19901992
CULT()
19911993
}; // pvArrT
@@ -2030,7 +2032,7 @@ static CULT shadexT[] = //------ SHADEX cmd RAT Entry table, used from cnTopCult
20302032
// id cs fn f uc evf ty b dfls p2 ckf
20312033
//----------------- ----- --------------- ------- -- ------ ----- ------ ------ ---- ----
20322034
CULT( "*", STAR, 0, 0, 0, 0, 0, 0, 0.f, N, shStarCkf),
2033-
CULT( "sxVertices", DAT, SXG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v 22, N),
2035+
CULT( "sxVertices", DAT, SXG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v DIM_POLYGONXYZ, N),
20342036
CULT( "endXSHADE", ENDER, 0, 0, 0, 0, 0, 0, 0.f, N, N),
20352037
CULT()
20362038
}; // shadeT

src/CNDEFNS.H

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979

8080
#define USE_STDLIB // re conversion to non-MFC containers
8181

82-
#define ANC_DTOR // define to better use basAnc etc. destructors
83-
8482
#undef AUSZ_REPORTS // define to enable hourly reports during autosizing
8583
// Note: crude at best, use for testing only, 12-31-2012
8684

@@ -135,7 +133,16 @@
135133

136134
#define DETAILED_TIMING // define to enable fine-grain timing
137135

138-
#undef COMFORT_MODEL
136+
#undef COMFORT_MODEL // define to include comfort model
137+
// calculation of PPD and PMV
138+
139+
// initial geometry implementation, 2-2017
140+
// fixed size polygons as input convenience
141+
// using ARRAY mechanism
142+
// Note limit is due to ARRAY input only.
143+
#define MAX_POLYGONVERTICES 9 // maximum number of input polygon vertices
144+
#define DIM_POLYGONXYZ 28 // input arrays dimension
145+
// = MAX_POLYLPVERTICIES*3 + 1
139146

140147
#endif // ifndef _CNEDEFNS_H
141148

src/CNRECS.DEF

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,26 @@ RECORD WFDATA "weather" *RAT // hourly weather data, one static instance "Wthr",
743743
//========================================================================================================
744744
RECORD SURFGEOM "surfgeom sub" *SUBSTRUCT // surface geometry substructure
745745
*prefix gx_
746-
*i *ARRAY 22 FLOAT gx_vrtInp // input vertices (x, y, z)
747-
// max 7 points (3*7)+1 (for cul)
748-
// = octagon is largest polygon supported
749-
*END // SURFGEOP
750-
751-
746+
*declare "SURFGEOM();"
747+
*declare "~SURFGEOM();"
748+
*declare "void gx_Init( record* pParent, int options=0);"
749+
*declare "void gx_CopySubObjects();"
750+
*declare "RC gx_CheckAndMakePolygon( int phase, int fn);"
751+
752+
*declare "record* gx_pParent;" // pointer to parent record
753+
// (SHADEX, PVARRAY, ...)
754+
*declare "class CPolygon3D* gx_polygon;" // derived polygon
755+
756+
*i *ARRAY DIM_POLYGONXYZ FLOAT gx_vrtInp // input vertices (x, y, z)
757+
*END // SURFGEOM
752758
//========================================================================================================
753-
RECORD SHADEX "shadex" *RAT // shade object (polygon that can shade surfaces)
759+
RECORD SHADEX "SHADEX" *RAT // shade object (polygon that can shade surfaces)
754760

755761
*prefix sx_
762+
*excon
763+
*ovrcopy
764+
*declare "void FixUp();" // virtual fixup after basAnc reAl
765+
// .ownTi (base class) is zone subscript
756766
*declare "RC sx_CkF();"
757767

758768
*i *nest SURFGEOM sx_g;
@@ -3557,8 +3567,10 @@ RECORD DHWUSE "DHWUse" *RAT // input / runtime DHW single draw
35573567
//=============================================================================
35583568
RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array
35593569
*prefix pv_
3560-
3570+
*excon
35613571
*exdes // define destructor in pvwatts.cpp to free SSC data container
3572+
*ovrcopy
3573+
*declare "void FixUp();" // virtual fixup after basAnc reAl
35623574
*declare "RC pv_CkF();"
35633575
*declare "virtual RC RunDup( const record* pSrc, int options=0);"
35643576
*declare "RC pv_Init();"
@@ -3573,6 +3585,7 @@ RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array
35733585
*declare "MTR* pv_pMtrElec;"
35743586
*declare "void* pv_ssc_data;"
35753587

3588+
*i *nest SURFGEOM pv_g; // array geometry (re shading)
35763589
*i TI pv_elecMtri; // meter for system electricity production
35773590
*f ENDUSECH pv_endUse // end use of energy. defataults to "PV"
35783591
*i FLOAT_GEZ pv_dcCap // system capacity/size (DC nameplate), kW

src/PVCalc.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,30 @@ XPVWATTS PVWATTS; // public PVWATTS Library object
2323
static const float airRefrInd = 1.f;
2424
static const float glRefrInd = 1.526f;
2525

26+
PVARRAY::PVARRAY( basAnc *b, TI i, SI noZ /*=0*/)
27+
: record( b, i, noZ)
28+
{
29+
FixUp();
30+
} // PVARRAY::PVARRAY
31+
2632
PVARRAY::~PVARRAY()
2733
{
2834
if (pv_usePVWattsDLL == C_NOYESCH_YES) {
2935
PVWATTS.xp_ClearData(this);
3036
}
3137
} // PVARRAY::~PVARRAY
3238

39+
/*virtual*/ void PVARRAY::FixUp() // set parent linkage
40+
{ pv_g.gx_Init( this);
41+
}
42+
43+
void PVARRAY::Copy( const record* pSrc, int options/*=0*/)
44+
{ // bitwise copy of record
45+
record::Copy( pSrc, options); // calls FixUp()
46+
// copy SURFGEOM heap subobjects
47+
pv_g.gx_CopySubObjects();
48+
} // PVARRAY::Copy
49+
3350
RC PVARRAY::pv_CkF()
3451
{
3552
RC rc = RCOK;
@@ -76,6 +93,10 @@ RC PVARRAY::pv_CkF()
7693
rc |= oWarn("Temperature coefficient (%0.4f) is positive. Values are typically negative.", pv_tempCoeff);
7794
}
7895
}
96+
97+
// check geometry
98+
rc |= pv_g.gx_CheckAndMakePolygon( 0, PVARRAY_G);
99+
79100
return rc;
80101

81102
} // PVARRAY::pv_CkF

0 commit comments

Comments
 (0)