Skip to content

Commit

Permalink
Merge pull request #462 from cse-sim/setpoint-error-check
Browse files Browse the repository at this point in the history
Setpoint error check
  • Loading branch information
nealkruis authored Feb 5, 2024
2 parents ec95afb + 3688671 commit 4bbe1bd
Show file tree
Hide file tree
Showing 30 changed files with 638 additions and 724 deletions.
2 changes: 1 addition & 1 deletion doc/src/records/terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Air heating thermostat set point; implies *set temperature* air capability. May

**tuTC=*float***

Air cooling thermostat set point; implies *set temperature*air capability. May be scheduled as desired; to disable at certain times, schedule an extreme temperature such as 199.
Air cooling thermostat set point; implies *set temperature* air capability. May be scheduled as desired; to disable at certain times, schedule an extreme temperature such as 199.

<%= member_table(
units: "^o^F",
Expand Down
28 changes: 14 additions & 14 deletions doc/src/records/zone.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,41 +169,41 @@ Zone shade closure. Determines insolation through windows (see WINDOW members *w

**znTH=*float***

Heating set point for znModel=CZM.
Heating set point used (and required) when znModel=CZM and zone has no terminals.

<%= member_table(
units: "^o^F",
legal_range: "x $\\geq$ 0",
legal_range: "0 < znTH < znTC",
default: "*none*",
required: "No",
required: "Per above",
variability: "subhourly")
%>

**znTD=*float***

Desired set point (temperature maintained with ventilation if possible) for znModel=CZM
Desired set point (temperature maintained with ventilation if possible) for znModel=CZM. Must be specified when zone ventilation is active.

<%= member_table(
units: "^o^F",
legal_range: "x $\\geq$ 0",
legal_range: "x > 0; znTH < znTD < znTC",
default: "*none*",
required: "No",
required: "if venting",
variability: "subhourly")
%>

**znTC=*float***

Cooling set point for znModel=CZM.
Cooling set point used (and required) when znModel=CZM and zone has no terminals.

<%= member_table(
units: "^o^F",
legal_range: "x $\\geq$ 0",
legal_range: "0 < znTC > znTH",
default: "*none*",
required: "No",
required: "Per above",
variability: "subhourly")
%>

CZM zone heating and cooling is provided either via an RSYS HVAC system or by "magic" heat transfers specified by znQxxx items.
znModel = CZM zone heating and cooling is provided either via an RSYS HVAC system, by "magic" heat transfers specified by znQxxx items, or via TERMINAL (s). One of these must be defined.

**znRSys=*rsysName***

Expand Down Expand Up @@ -270,7 +270,7 @@ The following provide parameters for comfort calculations

**znComfClo=*float***

Occupant clothing resistance
Occupant clothing resistance, used only when a comfort model is enabled.

<%= member_table(
units: "clo",
Expand All @@ -282,7 +282,7 @@ Occupant clothing resistance

**znComfMet=*float***

Occupant metabolic rate
Occupant metabolic rate, used only when a comfort model is enabled.

<%= member_table(
units: "met",
Expand All @@ -294,7 +294,7 @@ Occupant metabolic rate

**znComfAirV=*float***

Nominal air velocity used for comfort model
Nominal air velocity used for comfort model, used only when a comfort model is enabled.

<%= member_table(
units: "",
Expand All @@ -306,7 +306,7 @@ Nominal air velocity used for comfort model

**znComfRh=*float***

Nominal zone relative humidity used for comfort model
Nominal zone relative humidity used for comfort model, used only when a comfort model is enabled.

<%= member_table(
units: "",
Expand Down
18 changes: 7 additions & 11 deletions src/CNRECS.DEF
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ RECORD TOPRAT "top" *RAT /* top level RAT: contains control info and all once-on
*i SI tp_terrainClass // terrain class (1-5) re wind speed adjustment
*i FLOAT_GEZ radBeamF // Beam radiation fctr. appl sees ANISO( <fileVal>) * radBeamF. cgwthr.cpp.
*i FLOAT_GEZ radDiffF // Diffuse radiation fctr. appl sees ANISO( <fileVal>) * radDiffF.
*h VENTAVAILVC tp_ventAvail // all-zone ventilation availability (default=C_VENTAVAILCH_WHOLEHOUSE)
*h VENTAVAILVC tp_ventAvail // all-zone ventilation availability (default=C_VENTAVAILCH_WHOLEBLDG)
// C_VENTAVAILCH_NONE: none
// C_VENTAVAILCH_WHOLEHOUSE: airnet windows / fans
// C_VENTAVAILCH_WHOLEBLDG: airnet windows / fans
// C_VENTAVAILCH_ZONAL: airnet windows / fans (controlled by zone)
// C_VENTAVAILCH_RSYSOAV: RSYS outside air vent (central mechanical)
*declare "int tp_GetVentAvail() const { return CHN( tp_ventAvail); }"
Expand Down Expand Up @@ -1322,7 +1322,6 @@ RECORD SFI "surface" *RAT // opaque surface / door / window input info RAT
*excon // explicit constructor
*exdes // explicit d'tor
*ovrcopy
*declare "virtual SFI& CopyFrom( const record* src, int copyName=1, int dupPtrs=0);"
*declare "RC sf_TopSf1();"
*declare "RC sf_CkfSURF( int options);"
*declare "RC sf_CkfSURFGround( int options);"
Expand Down Expand Up @@ -1742,7 +1741,6 @@ RECORD COL "reportCol" *RAT // holds info for columns in user-defined table repo
*excon
*exdes
*ovrcopy
*declare "virtual record& CopyFrom( const record *src, int copyName=1, int dupPtrs=0);"
*declare "virtual RC Validate( int options=0);"

//input .ownTi is RI subscript of owning report/export. Column order is order of input.
Expand Down Expand Up @@ -2114,8 +2112,8 @@ RECORD ZNISUB "zone sub" *SUBSTRUCT
// zone input info substruct, used in ZNR and ZNI
*declare "bool IsCountable( int options) const { return options==0 || options==znModel; }"
*declare "float zn_HeightZ( float f) const;"
*declare "int zn_IsConvRad() const { return znModel >= C_ZNMODELCH_CZM; }"
*declare "int zn_IsUZ() const { return znModel >= C_ZNMODELCH_UZM; }"
*declare "bool zn_IsConvRad() const { return znModel >= C_ZNMODELCH_CZM; }"
*declare "bool zn_IsUZ() const { return znModel >= C_ZNMODELCH_UZM; }"

// ZNISUB general user inputs
*i ZNMODELCH znModel // zone model (CNE, CSE, CZM, UZM, UZX)
Expand Down Expand Up @@ -2246,6 +2244,8 @@ RECORD ZNR "zone" *RAT // zone runtime info RAT. Set mainly from separate ZNI
*declare "bool zn_HasAirTerminal() const { return zn_airTerminalCount > 0; }"
*declare "bool zn_HasRSYS() const { return i.zn_rsi != 0; }"
*declare "bool zn_HasAirHVAC() const { return zn_HasRSYS() || zn_HasAirTerminal(); }"
*declare "bool zn_HasMagicHVAC() const { return IsSet( ZNI_I + ZNISUB_ZNQMXH) || IsSet( ZNI_I + ZNISUB_ZNQMXC); }"
*declare "bool zn_UsesZoneSetpoints() const { return i.znModel == C_ZNMODELCH_CZM && !zn_HasTerminal(); }"
*declare "RSYS* zn_GetRSYS();"
*declare "const RSYS* zn_GetRSYS() const;"
*declare "int zn_IsHCAvail( int what) const;"
Expand Down Expand Up @@ -2294,7 +2294,7 @@ RECORD ZNR "zone" *RAT // zone runtime info RAT. Set mainly from separate ZNI
*declare "BOO nxZhxSt( ZHX *&x);"
*declare "bool IsCountable( int options) const { return i.IsCountable( options); }"
*declare "int zn_IsConvRad() const { return i.zn_IsConvRad(); }"
*declare "int zn_IsUZ() const { return i.zn_IsUZ(); }"
*declare "bool zn_IsUZ() const { return i.zn_IsUZ(); }"
*declare "int zn_IsSFModelSupported( int sfModel) const;"
*declare "void zn_SGClearTots();"
*declare "void zn_SGCavAbs();"
Expand Down Expand Up @@ -4132,7 +4132,6 @@ RECORD DHWSYS "DHWSYS" *RAT // input / runtime DHW system
*prefix ws_
*exdes
*ovrcopy
*declare "virtual DHWSYS& CopyFrom( const record* src, int copyName=1, int dupPtrs=0);"
*declare "RC ws_CkF();"
*declare "RC ws_CheckVals( int erOp);"
*declare "RC ws_CheckSubObject( record* r);"
Expand Down Expand Up @@ -4554,7 +4553,6 @@ RECORD DHWHEATER "DHWHeater" *RAT // input / runtime DHW heater
*excon // explicit constructor
*exdes // explicit ~DHWHEATER()
*ovrcopy // overide Copy()
*declare "virtual DHWHEATER& CopyFrom( const record* pSrc, int copyName=1, int dupPtrs=0);"

*declare "RC wh_CkF();"
*declare "virtual RC RunDup( const record* pSrc, int options=0);"
Expand Down Expand Up @@ -5170,7 +5168,6 @@ RECORD DHWSOLARSYS "DHWSolarSys" *RAT // input / runtime DHW solar system
*prefix sw_
*exdes
*ovrcopy // overide Copy()
*declare "virtual DHWSOLARSYS& CopyFrom( const record *src, int copyName=1, int dupPtrs=0);"
*declare "virtual void ReceiveRuntimeMessage(const char* msg);"
*declare "RC sw_CkF();"
*declare "RC sw_Init();"
Expand Down Expand Up @@ -5361,7 +5358,6 @@ RECORD PVARRAY "PVArray" *RAT // input / runtime photovoltaics array
*prefix pv_
*excon
*ovrcopy
*declare "virtual PVARRAY& CopyFrom( const record* src, int copyName=1, int dupPtrs=0);"
*declare "void FixUp();" // virtual fixup after basAnc reAl
*declare "RC Validate( int options=0);"
*declare "RC pv_CkF();"
Expand Down
110 changes: 36 additions & 74 deletions src/ancrec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "cnglob.h"
#include "ancrec.h"
#include "cse.h"
#include "msghans.h" // MH_X0050
#include "msghans.h"
#include "messages.h" // msgIsHan
#include "exman.h"
#include "cvpak.h"
Expand Down Expand Up @@ -124,83 +124,45 @@ int record::IsNameMatch( const char* _name) const
return !_stricmp( _name, Name());
} // record::IsNameMatch
//-----------------------------------------------------------------------------
/*virtual*/ record& record::CopyFrom(
const record* src,
int copyName/*=1*/,
[[maybe_unused]] int dupPtrs/*=0*/)

// copy user and ul data from another record or init data to already-constructed record

// copies user language overhead, and ownTi, and, unless suppressed, name.
// Does not copy ancrec internal overhead except 'gud'

/* "dupPtrs" is for poss future use duplicating heap pointers in derived classes
(in present uses (input to run rat copies) ptrs are not currenly being dup'd 2-92)
(7-92: converting to dup'd ptrs with explicit derived class CopyFrom's and destructors.
"dupPtrs" would shorten code; table bit or different field ty needed to say which ptrs to dup (some CHP's don't get dup'd). */
{
// error if not init (can't constr here: need b, ss). (if needed, do a "copyTo" or a "copy(b,i1,i2)" that constructs dest.)
if (!b) // (or gud? wd error here if init then destroyed)
err( PABT, (char *)MH_X0050); // error msg "record::CopyFrom: unconstructed destination (b is 0)" and abort program.
#ifdef DEBUG2 // message not occuring (1-95) so omit from release version.
b->validate("record::CopyFrom"); // abort if record 'this' not associated with valid anchor
((record *)src)->Validate();
#endif

// use shorter record length
int eSz = b->eSz; // get dest derived class rec length from anchor
if ( src->b && src->b->rt==src->rt // if source has anchor (could be just init data)
&& eSz != src->b->eSz ) // and source record length is different
eSz = min( b->sOff, src->b->sOff); // use the shorter length and do not copy status bytes (3-12-92).
// calls exist (ZNI->ZNR) where source is start of dest record (ug!)
// add logic to copy status bytes to correct place if need found

// copy data after front (bitwise)
// copy start offset: do not copy base class except ownTi and optionally name
int offBeg = offsetof(record, ownTi);
memcpy( (char *)this + offBeg, (char *)src + offBeg, eSz - offBeg );

if (copyName)
name.Set(src->name);

// copy user language front members. another arg option?
li = src->li; // if nz, is subscript of entry it is LIKE
ty = src->ty; // if nz, may be TYPE subscript (future)
fileIx = src->fileIx; // if nz, is index of object input fileName
line = src->line; // if nz, is object input file line

// copy internal good-record flag with possible future user bits
gud = src->gud; // 0 = free, > 0 = in use, sign bit = bad (poss future use).

FixUp(); // virtual: record can e.g. fix ptrs
#if defined( _DEBUG)
Validate(); // virtual
#endif
return *this;
} // record::CopyFrom
//---------------------------------------------------------------------------------------------------------------------------
/*virtual*/ void record::Copy( // copy user and ul data and 'gud' from another record of same type
const record* pSrc,
int options/*=0*/)
const record* pSrc, // source record
int options/*=0*/) // rcoLEAVENAME: do NOT copy name
{
options;

// this implementation requires records already constructed (can't construct here without knowning b, ss).
if (!b) // (or gud? wd error here if init then destroyed)
err( PABT, (char *)MH_X0051); // err msg "record::operator=(): unconstructed destination (b is 0)" and abort program
if (b->rt != pSrc->b->rt) // check for same rt (same derived class)
err( PABT, (char *)MH_X0052); // err msg "record::operator=(): records not same type" and abort program
b->validate("left arg to record::operator="); // abort if records not well anchored
#ifdef DEBUG2
pSrc->b->validate("right arg to record::operator=");
// records must already be constructed (can't construct here without knowning b, ss).
if (!b || !pSrc) // (or gud? wd error here if init then destroyed)
err( PABT, (char *)MH_X0051); // err msg "record::Copy(): unconstructed destination or !pSrc"
#if defined( _DEBUG)
b->validate("Copy() dest"); // abort if records not well anchored
pSrc->b->validate("Copy() src");
#endif
name.Release(); // memcpy will overwrite with pSrc.name
// copy start offset: don't copy internal members

// bitwise copy members preceding name (not including internal members)
int offBeg = offsetof(record, gud);
memcpy((char *)this + offBeg, (char *)pSrc + offBeg, b->eSz - offBeg);
name.FixAfterCopy();
int offEnd = offsetof(record, name);
memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, offEnd - offBeg);

// conditionally copy name
if (!(options & rcoLEAVENAME))
name = pSrc->name;

// bitwisecopy remainder (ownTi, record data, and status array)
offBeg = offsetof(record, ownTi);
if (b->rt == pSrc->b->rt)
{ // same type: single memcpy()
memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, b->eSz - offBeg);
}
else
{ // partial copy (e.g. ZNI->ZNR)
if (pSrc->b->sOff > b->sOff)
err(PABT, (char*)MH_X0052);
else
{ memcpy((char*)this + offBeg, (const char*)pSrc + offBeg, pSrc->b->sOff - offBeg);
memcpy((char*)this + b->sOff, (const char*)pSrc + pSrc->b->sOff, pSrc->b->nFlds);
}
}

FixUp(); // virtual: record can e.g. fix ptrs

#if defined( _DEBUG)
Validate(); // virtual
#endif
Expand Down Expand Up @@ -349,7 +311,7 @@ o what );
// else if it has file and line, optionally show them
if (op)
if (fileIx)
return strtprintf("%s [%s(%d)]", what, getFileName( fileIx), line);
return strtprintf("%s [%s(%d)]", what, getFileName( fileIx), inputLineNo);

// else just class name
return what;
Expand Down Expand Up @@ -1047,7 +1009,7 @@ RC FC basAnc::del( TI i, int erOp/*=ABT*/) // delete (squeeze out) ith record
{
if (!dest.gud)
conRec(i); // construct destination if nec to insure vftp, rt, b, ss set.
dest.CopyFrom(&src); // copy record i+1 to i without dup'ing heap ptrs
dest.Copy( &src); // copy record i+1 to i without dup'ing heap ptrs
// tentatively no destroy: does nothing in base class, and deriv class might delete heap ptrs we did not dup.
#if defined( _DEBUG)
dest.Validate();
Expand Down
25 changes: 12 additions & 13 deletions src/ancrec.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class basAnc // base class for record anchors: basAnc<recordName>
SFIR* fir; // pointer to record type's "small fields-in-record table" (in srfd.cpp)
USI nFlds; // number of fields excluding base-class members (front overhead)
const char* what; // name of the record group (for probes, error messages)
USI eSz; // record size
USI eSz; // overall record size (including overhead and status byte array)
USI sOff; // offset in record to "status byte" array at end
USI ancN; // anchor number
RCT rt; // record type (from rcdef.exe); now mainly for internal checks
Expand Down Expand Up @@ -138,19 +138,19 @@ const UCH FsFROZ= 128; // value cannot be changed (spec'd in type)
//***************************************************************************************************************************
class record // base class for records
{ public:
// overhead members set by constructor or ancrec.cpp. CAUTION check operator= if changed. CAUTION code assumes order of members.
RCT rt; // record type (from rcdef.exe); now mainly for internal checks
TI ss; // record subscript
BP b; // pointer to record's anchor; 0 may indicate unconstructed record space.
// overhead members set by constructor or ancrec.cpp. CAUTION Copy() if order changes; code assumes member order
RCT rt; // record type (from rcdef.exe); now mainly for internal checks
TI ss; // record subscript
BP b; // pointer to record's anchor; 0 may indicate unconstructed record space.
SI gud; // 0: free; > 0: good record; [<0, skip/retain]. bits 0x7ffe avail to appl.
// overhead members for appl user language (ul). CAUTION check record::CopyFrom if these members changed.
// overhead members for appl user language (ul). CAUTION check record::Copy if these members changed.
TI ty, li; // 0 or user language TYPE and LIKE subscripts
int fileIx; // 0 or source file name index: see ancrecs:getFileName and getFileIx. 2-94.
int line; // 0 or 1-based file line # of object definition (for err msgs)
int inputLineNo; // 0 or 1-based file line # of object definition (for err msgs)
// base class user members
// rcdef.exe generates table entries and defines for the following as for derived class members;
// they are here for uniformity & access via base class ptrs. CHANGE from old ratpak 2-92: all records have name, ownTi:
// CAUTION check record::CopyFrom if these members changed.
// they are here for uniformity & access via base class ptrs.
// CAUTION check record::Copy if these members changed.
CULSTR name; // user-specified object name
TI ownTi; // 0 or subscript of owning object in anchor b->ownB

Expand Down Expand Up @@ -230,11 +230,10 @@ class record // base class for records
{ return (fStat( fn)&FsAS) != 0; }
template <typename T> inline bool IsSetNotAusz(T fn) const
{ return (fStat(fn) & (FsSET | FsAS)) == FsSET; }
// override following for records with specific copying req'ts eg heap pointers to dup (dupPtrs does nothing here in base).
// CAUTION dest's (this) must be init.
virtual record& CopyFrom( const record* src, int copyName=1, int dupPtrs=0); // copy user/ul data from another record or data
record& Copy( const record& d) { Copy( &d); return *this; }
record& operator=( const record& d) { Copy( &d); return *this; }
// override following for records with non-memcpy()able members (e.g. CULSTRs, heap pointers)
// CAUTION dest's (this) must be init.
enum { rcoLEAVENAME=1 };
virtual void Copy( const record* pSrc, int options=0);
virtual bool IsCountable(int /*options*/) const { return true; }
virtual void FixUp() { }; // optional fixup after reAl()
Expand Down
Loading

0 comments on commit 4bbe1bd

Please sign in to comment.