Skip to content

Commit

Permalink
Add draft support for system timestep
Browse files Browse the repository at this point in the history
Added logging of system time step updates.  reworked how zone timesteps
are filled.  seems to be working
  • Loading branch information
EnergyArchmage committed Jan 29, 2015
1 parent 515edf9 commit 9e6a87a
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/EnergyPlus/EnergyPlusPgm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ EnergyPlusPgm( std::string const & filepath )
#endif
#endif

#ifdef _WIN32
SetErrorMode(SEM_NOGPFAULTERRORBOX);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
#endif
// _WIN32
// SetErrorMode(SEM_NOGPFAULTERRORBOX);
// _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
// _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
//#endif

// Locals
// PROGRAM PARAMETER DEFINITIONS:
Expand Down
11 changes: 11 additions & 0 deletions src/EnergyPlus/HVACManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <ZoneContaminantPredictorCorrector.hh>
#include <ZoneEquipmentManager.hh>
#include <ZoneTempPredictorCorrector.hh>
#include <HVACSizingSimulationManager.hh>

namespace EnergyPlus {

Expand Down Expand Up @@ -224,6 +225,10 @@ namespace HVACManager {
using ManageElectricPower::ManageElectricLoadCenters;
using InternalHeatGains::UpdateInternalGainValues;
using ZoneEquipmentManager::CalcAirFlowSimple;
using namespace HVACSizingSimulationManagerNamespace;
using DataGlobals::KindOfSim;
using DataGlobals::ksHVACSizeDesignDay;
using DataGlobals::ksHVACSizeRunPeriodDesign;

// Locals
// SUBROUTINE ARGUMENT DEFINITIONS:
Expand Down Expand Up @@ -448,6 +453,9 @@ namespace HVACManager {
if ( DoOutputReporting ) {
ReportMaxVentilationLoads();
UpdateDataandReport( HVACTSReporting );
if ( KindOfSim == ksHVACSizeDesignDay || KindOfSim == ksHVACSizeRunPeriodDesign ){
UpdateSizingLogsSystemStep();
}
UpdateTabularReports( HVACTSReporting );
}
if ( ZoneSizingCalc ) {
Expand All @@ -474,6 +482,9 @@ namespace HVACManager {
}
CalcMoreNodeInfo();
UpdateDataandReport( HVACTSReporting );
if ( KindOfSim == ksHVACSizeDesignDay || KindOfSim == ksHVACSizeRunPeriodDesign ){
UpdateSizingLogsSystemStep();
}
} else if ( UpdateDataDuringWarmupExternalInterface ) { // added for FMI
if ( BeginDayFlag && ! PrintEnvrnStampWarmupPrinted ) {
PrintEnvrnStampWarmup = true;
Expand Down
1 change: 1 addition & 0 deletions src/EnergyPlus/HVACManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// EnergyPlus Headers
#include <EnergyPlus.hh>
#include <HVACSizingSimulationManager.hh>

namespace EnergyPlus {

Expand Down
11 changes: 7 additions & 4 deletions src/EnergyPlus/HVACSizingSimulationManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace EnergyPlus {

void HVACSizingSimulationManager::setupSizingAnalyses(){

for ( auto &P : this -> PlantCoincAnalyObjs ) {
for ( auto &P : PlantCoincAnalyObjs ) {
//call setup routine for each coincident plant analysis object
P.LogIndex = SizingLogger.SetupVariableSizingLog( P.SupplySideInletNodeNum );
}
Expand All @@ -115,7 +115,8 @@ namespace EnergyPlus {
//first pass through coincident plant objects to check new sizes and see if more iteration needed
PlantCoinAnalyRequestsAnotherIteration = false;
for ( auto &P : PlantCoincAnalyObjs ) {
SizingLogger.logObjs[ P.LogIndex ].ProcessRunningAverage( P.NumTimeStepsInAvg );
SizingLogger.logObjs[ P.LogIndex ].AverageSysTimeSteps();
SizingLogger.logObjs[ P.LogIndex ].ProcessRunningAverage( P.NumTimeStepsInAvg );
P.newFoundMassFlowRateTimeStamp = SizingLogger.logObjs[ P.LogIndex ].GetLogVariableDataMax( );
P.ResolveDesignFlowRate( HVACSizingIterCount );
if ( P.AnotherIterationDesired ){
Expand Down Expand Up @@ -362,9 +363,11 @@ namespace EnergyPlus {
}

void UpdateSizingLogsZoneStep (){

//SizingLogger.
SizeSimManagerObj.SizingLogger.UpdateSizingLogValuesZoneStep();
}

void UpdateSizingLogsSystemStep() {
SizeSimManagerObj.SizingLogger.UpdateSizingLogValuesSystemStep();
}
}
}
2 changes: 2 additions & 0 deletions src/EnergyPlus/HVACSizingSimulationManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace EnergyPlus {

void UpdateSizingLogsZoneStep();

void UpdateSizingLogsSystemStep();

}

}
Expand Down
132 changes: 118 additions & 14 deletions src/EnergyPlus/SizingAnalysisObjects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,106 @@ namespace EnergyPlus {
using DataLoopNode::Node;
int index(0);

index = this -> getZtStepIndex( tmpztStepStamp );
index = getZtStepIndex( tmpztStepStamp );

ztStepObj[index] = tmpztStepStamp;
// no we can no longer do this because need to keep system step data already in object
//ztStepObj[ index ] = tmpztStepStamp;

ztStepObj[ index ].KindofSim = tmpztStepStamp.KindofSim;
ztStepObj[ index ].EnvrnNum = tmpztStepStamp.EnvrnNum;
ztStepObj[ index ].DesignDayNum = tmpztStepStamp.DesignDayNum;
ztStepObj[ index ].DayOfSim = tmpztStepStamp.DayOfSim;
ztStepObj[ index ].HourOfDay = tmpztStepStamp.HourOfDay;
ztStepObj[ index ].ztStepsIntoPeriod = tmpztStepStamp.ztStepsIntoPeriod;
ztStepObj[ index ].stepStartMinute = tmpztStepStamp.stepStartMinute;
ztStepObj[ index ].stepEndMinute = tmpztStepStamp.stepEndMinute;
ztStepObj[ index ].TimeStepDuration = tmpztStepStamp.TimeStepDuration;

//hardcode until pointers
ztStepObj[index].LogDataValue = Node( NodeNum ).MassFlowRate;
ztStepObj[ index ].LogDataValue = Node( NodeNum ).MassFlowRate;


}

void SizingLog::fillSysStep(
int SizingLog::GetSysStepZtStepIndex(
zoneTimestepObject tmpztStepStamp
) {
int LastZnStepIndex( 0 );
int ZnStepIndex( -1 );

LastZnStepIndex = getZtStepIndex( tmpztStepStamp );
ZnStepIndex = LastZnStepIndex + 1;
//check if at the end of an environment
for ( auto & E : EnvrnStartZtStepIndex) {
if (E == ZnStepIndex ) { // don't kick over into the next environment
ZnStepIndex = LastZnStepIndex;
}
}

if ( ZnStepIndex >= NumOfStepsInLogSet ) ZnStepIndex = NumOfStepsInLogSet - 1;

return ZnStepIndex;
}

void SizingLog::fillSysStep(
zoneTimestepObject tmpztStepStamp ,
systemTimestepObject tmpSysStepStamp
){
using DataLoopNode::Node;
int LastZnStepIndex( 0 );
int ztIndex( 0 );
int systIndex ( 0 );
int oldNumSubSteps;
int newNumSubSteps;
Real64 const MinutesPerHour( 60.0 );
Real64 StartDiff; //in fractional hours
Real64 ZoneStepStartMinutes;

ztIndex = GetSysStepZtStepIndex(tmpztStepStamp);
oldNumSubSteps = ztStepObj[ ztIndex ].NumSubSteps;
newNumSubSteps = round ( tmpztStepStamp.TimeStepDuration / tmpSysStepStamp.TimeStepDuration ) ;
if ( newNumSubSteps > oldNumSubSteps ) {
ztStepObj[ ztIndex ].subSteps.resize( newNumSubSteps );
ztStepObj[ ztIndex ].NumSubSteps = newNumSubSteps;
}

if (ztStepObj[ ztIndex ].NumSubSteps > 0 ) {
// figure out which index this substep needs to go into
// the zone step level data are not yet available for minute, but we can get the previous zone step data...
LastZnStepIndex = (ztIndex - 1);
for ( auto & E : EnvrnStartZtStepIndex) {
if (E == ztIndex ) { // don't kick over into the previous environment
LastZnStepIndex = ztIndex;
}
}
ZoneStepStartMinutes = ztStepObj[LastZnStepIndex].stepEndMinute;
if ( ZoneStepStartMinutes == 60.0 ) ZoneStepStartMinutes = 0.0;
tmpSysStepStamp.stStepsIntoZoneStep = round(
(( ( tmpSysStepStamp.CurMinuteStart - ZoneStepStartMinutes ) / MinutesPerHour)
/ tmpSysStepStamp.TimeStepDuration) ) ;

ztStepObj[ ztIndex ].subSteps[ tmpSysStepStamp.stStepsIntoZoneStep ] = tmpSysStepStamp;
ztStepObj[ ztIndex ].subSteps[ tmpSysStepStamp.stStepsIntoZoneStep ].LogDataValue = Node( NodeNum ).MassFlowRate;
}


//TODO
}

void SizingLog::AverageSysTimeSteps( ){

std::vector< systemTimestepObject >::iterator pos;
Real64 RunningSum;

for ( auto &Zt : ztStepObj ){
if ( Zt.NumSubSteps > 0) {
RunningSum = 0.0;
for ( auto &SysT : Zt.subSteps ) {
RunningSum += SysT.LogDataValue;
}
Zt.LogDataValue = RunningSum / double( Zt.NumSubSteps );
}
}

}

void SizingLog::ProcessRunningAverage (
Expand Down Expand Up @@ -123,7 +205,7 @@ namespace EnergyPlus {
void SizingLog::ReInitLogForIteration(){
zoneTimestepObject tmpNullztStepObj;

for ( auto &Zt : this -> ztStepObj ){
for ( auto &Zt : ztStepObj ){
Zt = tmpNullztStepObj;
}
}
Expand Down Expand Up @@ -188,47 +270,69 @@ namespace EnergyPlus {

}

void SizingLoggerFramework::UpdateSizingLogValuesZoneStep(){
zoneTimestepObject SizingLoggerFramework::PrepareZoneTimestepStamp() {
//prepare current timing data once and then pass into fill routines
//function used by both zone and system frequency log updates

using DataGlobals::KindOfSim;
using DataGlobals::DayOfSim;
using DataGlobals::HourOfDay;
using DataGlobals::NumOfTimeStepInHour;
using namespace WeatherManager;
using namespace OutputProcessor;

int const ZoneIndex ( 1 );
Real64 const MinutesPerHour( 60.0 );
int const HoursPerDay( 24 );


//prepare current timing data once and then pass into fill routines
zoneTimestepObject tmpztStepStamp;

tmpztStepStamp.KindofSim = KindOfSim;
tmpztStepStamp.EnvrnNum = Envrn;
tmpztStepStamp.DesignDayNum = Environment( Envrn ).DesignDayNum;
tmpztStepStamp.DayOfSim = DayOfSim;
tmpztStepStamp.HourOfDay = HourOfDay;
tmpztStepStamp.stepEndMinute = TimeValue( ZoneIndex ).CurMinute;
tmpztStepStamp.stepEndMinute = TimeValue( ZoneIndex ).CurMinute;
if ( tmpztStepStamp.stepEndMinute == 0.0 ) {tmpztStepStamp.stepEndMinute = MinutesPerHour ; }
tmpztStepStamp.stepStartMinute = tmpztStepStamp.stepEndMinute - TimeValue( ZoneIndex ).TimeStep * MinutesPerHour;
tmpztStepStamp.TimeStepDuration = TimeValue( ZoneIndex ).TimeStep;

tmpztStepStamp.ztStepsIntoPeriod = ((tmpztStepStamp.DayOfSim - 1) * (HoursPerDay * NumOfTimeStepInHour) ) + //multiple days
((tmpztStepStamp.HourOfDay-1) * NumOfTimeStepInHour ) + //so far this day's hours
round( (tmpztStepStamp.stepStartMinute / MinutesPerHour)/(tmpztStepStamp.TimeStepDuration) ); // into current hour
return tmpztStepStamp;
}

void SizingLoggerFramework::UpdateSizingLogValuesZoneStep(){

zoneTimestepObject tmpztStepStamp;

tmpztStepStamp.NumSubSteps = 0;
tmpztStepStamp = PrepareZoneTimestepStamp();

for ( auto &L : logObjs ) {
L.fillZoneStep(tmpztStepStamp);
}
}

void SizingLoggerFramework::UpdateSizingLogValuesSystemStep() {
int const SysIndex ( 2 );
Real64 const MinutesPerHour( 60.0 );
int const HoursPerDay( 24 );
using namespace OutputProcessor;
zoneTimestepObject tmpztStepStamp;
systemTimestepObject tmpSysStepStamp;

for ( auto &L : this -> logObjs ) {
tmpztStepStamp = PrepareZoneTimestepStamp();

//pepare system timestep stamp
tmpSysStepStamp.CurMinuteEnd = TimeValue( SysIndex ).CurMinute;
if ( tmpSysStepStamp.CurMinuteEnd == 0.0 ) { tmpSysStepStamp.CurMinuteEnd = MinutesPerHour; }
tmpSysStepStamp.CurMinuteStart = tmpSysStepStamp.CurMinuteEnd - TimeValue( SysIndex ).TimeStep * MinutesPerHour;
tmpSysStepStamp.TimeStepDuration = TimeValue( SysIndex ).TimeStep;

L.fillZoneStep(tmpztStepStamp);
for ( auto &L : logObjs ) {
L.fillSysStep(tmpztStepStamp, tmpSysStepStamp);
}

}

void SizingLoggerFramework::IncrementSizingPeriodSet(
Expand Down
18 changes: 16 additions & 2 deletions src/EnergyPlus/SizingAnalysisObjects.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public:

Real64 LogDataValue = 0.0;
Real64 RunningAvgDataValue = 0.0;
int NumSubSteps;
bool HasSystemSubSteps = false;
int NumSubSteps = 0;
std::vector< systemTimestepObject > subSteps; //nested object array for system timesteps inside here.

};
Expand Down Expand Up @@ -73,7 +74,16 @@ public:
zoneTimestepObject tmpztStepStamp
);

void fillSysStep( zoneTimestepObject tmpztStepStamp );
int GetSysStepZtStepIndex(
zoneTimestepObject tmpztStepStamp
);

void fillSysStep(
zoneTimestepObject tmpztStepStamp ,
systemTimestepObject tmpSysStepStamp
);

void AverageSysTimeSteps();

void ProcessRunningAverage(
int const TimeStepsInAverage
Expand Down Expand Up @@ -102,8 +112,12 @@ public:
int const SupplySideInletNodeNum //change to pointers for generality later
);

zoneTimestepObject PrepareZoneTimestepStamp ();

void UpdateSizingLogValuesZoneStep();

void UpdateSizingLogValuesSystemStep();

void IncrementSizingPeriodSet(
int const HVACSizingIterCount
);
Expand Down

7 comments on commit 9e6a87a

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - x86_64-MacOS-10.9-clang: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - x86_64-Linux-Ubuntu-14.04-gcc-4.8: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - x86_64-Linux-Ubuntu-14.04-cppcheck-1.61: OK (0 of 0 tests passed)

Build Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-UnitTestsCoverage-Debug: OK (599 of 599 tests passed)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - i386-Windows-7-VisualStudio-12: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-IntegrationCoverage-Debug: OK (1072 of 1098 tests passed)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HVACSizingSim_CoincidentPlant (EnergyArchmage) - Win64-Windows-7-VisualStudio-12: Tests Failed

Build Badge Test Badge

Please sign in to comment.