Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 40 additions & 38 deletions src/ANCREC.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ int record::IsSetAny(
}
} // record::IsSetAny
//-----------------------------------------------------------------------------
int record::IsValAll(
int record::IsValAll( // check for resolved (non-expression) values
int fn, ...) const // 0 terminated fn list (don't forget the 0!)
// return 1 iff all fields have values
{ va_list ap;
Expand Down Expand Up @@ -365,23 +365,49 @@ o what );
} // record::classObjTx
//=============================================================================

//***************************************************************************************************************************
///////////////////////////////////////////////////////////////////////////////
// public helper functions
///////////////////////////////////////////////////////////////////////////////
RC ArrayStatus( // count/check status of ARRAY elements
const UCH* _sstat0, // status array
int count, // # of values to check (dimension of array
int& nSet, // returned: # of array elements set (FsSet)
int& nVal) // returned: # of array elements with value (FsVAL)
// re checking of ARRAY input
// returns RCOK on success
// RCBAD iff malformed (impossible unless bug?)
{
RC rc = RCOK;
int n0 = 0; // # of 0 status
nSet = nVal = 0;
for (int fn=0; fn < count; fn++)
{ int stat = _sstat0[ fn];
if (stat == 0)
n0++;
else
{ if (n0)
rc = RCBAD; // 0 followed by non-0
if (stat & FsSET)
nSet++;
if (stat & FsVAL)
nVal++;
}
}
return rc;
} // ::ArrayStatus
//=============================================================================

//*****************************************************************************
// class basAnc: base class for application record anchors.
//***************************************************************************************************************************
//*****************************************************************************

//--- variables re "anchor numbers". ancBase.ancN contains #.
#if defined( ANC_DTOR)
const int MAXANCS = 200; // Maximum number of basAncs supported
// actual required = ~65 12-20-2012
static BP ancs[ MAXANCS]; // table of pointers to contructed basAncs
// persists for entire session re multiple DLL cse() calls
// "big enuf" static array simplifies persistence
static int Nanc = -1; // # of entries in anc[] (-1 = unintialized) (see regis())
#else
LOCAL BP * NEAR ancs = NULL; // dm array of NEAR ptrs to basAncs by #. excludes b.tyB's (not regis'd by cul.cpp).
LOCAL USI NEAR Nanc = 0; // max ancN in use (0 unused)
LOCAL USI NEAR ancNal = 0; // ancs size: # #'s allocated
#endif
//---------------------------------------------------------------------------------------
basAnc::basAnc() // default c'tor (for derived copy c'tor
{
Expand All @@ -405,16 +431,13 @@ basAnc::basAnc( USI _flags, SFIR * _fir, USI _nFlds, char * _what, USI _eSz, RCT
//--------------------------------------------------------------------------------------------------------------
/*virtual*/ basAnc::~basAnc() // d'tor
{
#if defined( ANC_DTOR)
if (flags & RFTYS)
dmfree( DMPP( what));
#endif
} // basAnc::~basAnc
//---------------------------------------------------------------------------------------------------------------------------
void FC basAnc::regis() // "register" anchor for nextAnc() iteration. Constructor helper.
{
int an;
#if defined( ANC_DTOR)
if (Nanc < 0) // if not initialized
{ VZero( ancs, MAXANCS);
Nanc = 0;
Expand All @@ -423,12 +446,6 @@ void FC basAnc::regis() // "register" anchor for nextAnc() iteration. Constr
; // (or one already set for this anc: reconstr insurance)
if (an >= MAXANCS)
err( PABT, "Insufficient anc[] space");
#else
if (!ancs || ancNal < Nanc + 2) // if necessary
dmral( DMPP( ancs), (ancNal += 32) * sizeof(BP), DMZERO|ABT); // enlarge array of pointers
for (an = 1; ancs[an] && ancs[an] != this; an++) // find free pointer
; // (or one already set for this anc: reconstr insurance)
#endif
ancs[an] = this; // set pointer in static array
Nanc = max( Nanc, an);
ancN = an; // set index in anchor
Expand All @@ -452,30 +469,15 @@ void FC cleanBasAncs( // destroy/free all basAnc records, and delete subsidiary
if (!b)
continue; // skip (unexpected) NULL pointer
b->free(); // destroy b's records, free record memory unless static, clear flags
#if defined( ANC_DTOR)
delete b->tyB;
b->tyB = NULL;
#else
if (b->tyB) // if b has a subsidiary "types" ancRec (not registered; in heap)
{
b->tyB->free(); // destroy/free its records (believed redundant)
dmfree( DMPP( b->tyB->what)); // free its "what" string if non-NULL, set pointer NULL
delete (basAnc *)b->tyB; // destroy types basAnc and free its memory. cast makes ptr pointer.
b->tyB = 0; // 16-bit-NULL tyB pointer
}
#endif
}

if (cs == DONE || cs == CRASH)
{
#if !defined( ANC_DTOR)
Nanc = 0;
ancNal = 0;
dmfree( DMPP( ancs));
#endif
}
// else
// ancs[] is built by c'tor, thus must persist from entry to entry (all non-tyB ancRecs believed static).
// if (cs == DONE || cs == CRASH)
// { // nothing to do
// }
// else
// ancs[] is built by c'tor, thus must persist from entry to entry (all non-tyB ancRecs believed static).

clearFileIxs(); // clear file names referenced by record.fileIx members
} // cleanBasAncs
Expand Down
7 changes: 1 addition & 6 deletions src/ANCREC.H
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,8 @@ x n = nAl = 0; // say no records in use, none allocated: insurance
// if this anchor has user language subsidiary 'type' records anchor, destroy it and its records
if (tyB) // .tyB is basAnc *
{
#if defined( ANC_DTOR)
delete tyB;
tyB = NULL;
#else
dmfree( DMPP( tyB->what)); // free its "what" string if non-NULL, set ptr NULL
delete (basAnc *)tyB; // basAnc d'tor is virtual, so this should call here to destroy records.
tyB = 0; // insurance. ...10-93 need to be sure all rec d'tors free all heap ptrs!
#endif
}
} // anc<T>::~anc
//-------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -429,6 +423,7 @@ template <class T> T* anc<T>::GetAt( int i) const
///////////////////////////////////////////////////////////////////////////////
// ancrec.cpp non-member fcn declarations
//-----------------------------------------------------------------------------
RC ArrayStatus( const UCH* _sstat0, int count, int& nSet, int& nVal);
void FC cleanBasAncs( CLEANCASE cs); // destroy/free all basAnc records, and delete subsidiary "types" basAncs (.tyB)

// functions for saving file names for record.fileIx 2-94
Expand Down
6 changes: 4 additions & 2 deletions src/CNCULT.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ CULT()


//===================================== GAIN command for ZONE ============================================
LOCAL RC FC gnStarCkf( CULT* c, /*PVARRAY* */ void *p, void *p2, void *p3)
LOCAL RC FC gnStarCkf( CULT* c, /*GAIN* */ void *p, void *p2, void *p3)
// called at end of GAIN input, to get messages near source of error.
{
return ((GAIN*)p)->gn_CkF( 0);
Expand Down Expand Up @@ -1966,6 +1966,7 @@ LOCAL RC FC pvStarCkf( CULT* c, /*PVARRAY* */ void *p, void *p2, void *p3)
return ((PVARRAY*)p)->pv_CkF();
} // pvStarCkf
//=============================================================================
#define PVG( m) (PVARRAY_G+SURFGEOM_##m)
static CULT pvArrT[] = //------ PVARRAY cmd RAT Entry table, used from cnTopCult
{
// id cs fn f uc evf ty b dfls p2 ckf
Expand All @@ -1986,6 +1987,7 @@ CULT( "pvDCtoACRatio", DAT, PVARRAY_DCACRAT, 0, 0, VEOI, TYFL, 0,
CULT( "pvInverterEff", DAT, PVARRAY_INVEFF, 0, 0, VEOI, TYFL, 0, 0.96f, N, N),
CULT( "pvSysLosses", DAT, PVARRAY_SYSLOSS, 0, 0, VHRLY, TYFL, 0, 0.14f, N, N),
CULT( "pvUsePVWatts", DAT, PVARRAY_USEPVWATTSDLL, 0, 0, VEOI, TYCH, 0, C_NOYESCH_NO, N, N),
CULT( "pvVertices", DAT, PVG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v DIM_POLYGONXYZ, N),
CULT( "endPVARRAY", ENDER, 0, 0, 0, 0, 0, 0, 0.f, N, N),
CULT()
}; // pvArrT
Expand Down Expand Up @@ -2030,7 +2032,7 @@ static CULT shadexT[] = //------ SHADEX cmd RAT Entry table, used from cnTopCult
// id cs fn f uc evf ty b dfls p2 ckf
//----------------- ----- --------------- ------- -- ------ ----- ------ ------ ---- ----
CULT( "*", STAR, 0, 0, 0, 0, 0, 0, 0.f, N, shStarCkf),
CULT( "sxVertices", DAT, SXG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v 22, N),
CULT( "sxVertices", DAT, SXG( VRTINP), ARRAY, 0, VEOI, TYFL, 0, 0.f, v DIM_POLYGONXYZ, N),
CULT( "endXSHADE", ENDER, 0, 0, 0, 0, 0, 0, 0.f, N, N),
CULT()
}; // shadeT
Expand Down
13 changes: 10 additions & 3 deletions src/CNDEFNS.H
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@

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

#define ANC_DTOR // define to better use basAnc etc. destructors

#undef AUSZ_REPORTS // define to enable hourly reports during autosizing
// Note: crude at best, use for testing only, 12-31-2012

Expand Down Expand Up @@ -135,7 +133,16 @@

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

#undef COMFORT_MODEL
#undef COMFORT_MODEL // define to include comfort model
// calculation of PPD and PMV

// initial geometry implementation, 2-2017
// fixed size polygons as input convenience
// using ARRAY mechanism
// Note limit is due to ARRAY input only.
#define MAX_POLYGONVERTICES 9 // maximum number of input polygon vertices
#define DIM_POLYGONXYZ 28 // input arrays dimension
// = MAX_POLYLPVERTICIES*3 + 1

#endif // ifndef _CNEDEFNS_H

Expand Down
29 changes: 21 additions & 8 deletions src/CNRECS.DEF
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,26 @@ RECORD WFDATA "weather" *RAT // hourly weather data, one static instance "Wthr",
//========================================================================================================
RECORD SURFGEOM "surfgeom sub" *SUBSTRUCT // surface geometry substructure
*prefix gx_
*i *ARRAY 22 FLOAT gx_vrtInp // input vertices (x, y, z)
// max 7 points (3*7)+1 (for cul)
// = octagon is largest polygon supported
*END // SURFGEOP


*declare "SURFGEOM();"
*declare "~SURFGEOM();"
*declare "void gx_Init( record* pParent, int options=0);"
*declare "void gx_CopySubObjects();"
*declare "RC gx_CheckAndMakePolygon( int phase, int fn);"

*declare "record* gx_pParent;" // pointer to parent record
// (SHADEX, PVARRAY, ...)
*declare "class CPolygon3D* gx_polygon;" // derived polygon

*i *ARRAY DIM_POLYGONXYZ FLOAT gx_vrtInp // input vertices (x, y, z)
*END // SURFGEOM
//========================================================================================================
RECORD SHADEX "shadex" *RAT // shade object (polygon that can shade surfaces)
RECORD SHADEX "SHADEX" *RAT // shade object (polygon that can shade surfaces)

*prefix sx_
*excon
*ovrcopy
*declare "void FixUp();" // virtual fixup after basAnc reAl
// .ownTi (base class) is zone subscript
*declare "RC sx_CkF();"

*i *nest SURFGEOM sx_g;
Expand Down Expand Up @@ -3557,8 +3567,10 @@ RECORD DHWUSE "DHWUse" *RAT // input / runtime DHW single draw
//=============================================================================
RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array
*prefix pv_

*excon
*exdes // define destructor in pvwatts.cpp to free SSC data container
*ovrcopy
*declare "void FixUp();" // virtual fixup after basAnc reAl
*declare "RC pv_CkF();"
*declare "virtual RC RunDup( const record* pSrc, int options=0);"
*declare "RC pv_Init();"
Expand All @@ -3573,6 +3585,7 @@ RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array
*declare "MTR* pv_pMtrElec;"
*declare "void* pv_ssc_data;"

*i *nest SURFGEOM pv_g; // array geometry (re shading)
*i TI pv_elecMtri; // meter for system electricity production
*f ENDUSECH pv_endUse // end use of energy. defataults to "PV"
*i FLOAT_GEZ pv_dcCap // system capacity/size (DC nameplate), kW
Expand Down
21 changes: 21 additions & 0 deletions src/PVCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ XPVWATTS PVWATTS; // public PVWATTS Library object
static const float airRefrInd = 1.f;
static const float glRefrInd = 1.526f;

PVARRAY::PVARRAY( basAnc *b, TI i, SI noZ /*=0*/)
: record( b, i, noZ)
{
FixUp();
} // PVARRAY::PVARRAY

PVARRAY::~PVARRAY()
{
if (pv_usePVWattsDLL == C_NOYESCH_YES) {
PVWATTS.xp_ClearData(this);
}
} // PVARRAY::~PVARRAY

/*virtual*/ void PVARRAY::FixUp() // set parent linkage
{ pv_g.gx_Init( this);
}

void PVARRAY::Copy( const record* pSrc, int options/*=0*/)
{ // bitwise copy of record
record::Copy( pSrc, options); // calls FixUp()
// copy SURFGEOM heap subobjects
pv_g.gx_CopySubObjects();
} // PVARRAY::Copy

RC PVARRAY::pv_CkF()
{
RC rc = RCOK;
Expand Down Expand Up @@ -76,6 +93,10 @@ RC PVARRAY::pv_CkF()
rc |= oWarn("Temperature coefficient (%0.4f) is positive. Values are typically negative.", pv_tempCoeff);
}
}

// check geometry
rc |= pv_g.gx_CheckAndMakePolygon( 0, PVARRAY_G);

return rc;

} // PVARRAY::pv_CkF
Expand Down
Loading