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
21 changes: 19 additions & 2 deletions src/EnergyPlus/General.cc
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,25 @@ std::string CreateSysTimeIntervalString(EnergyPlusData &state)
// ActualTimeS=INT(CurrentTime)+(SysTimeElapsed+(CurrentTime - INT(CurrentTime)))
// CR6902 ActualTimeS=INT(CurrentTime-TimeStepZone)+SysTimeElapsed
// [DC] TODO: Improve display accuracy up to fractional seconds using hh:mm:ss.0 format
Real64 ActualTimeS = state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone + SysTimeElapsed;
Real64 ActualTimeE = ActualTimeS + TimeStepSys;

// NOTE: SysTimeElapsed is updated at the END of the HVAC time step (loop), so it's current value is
// the end of the last HVAC time step not the end of the current HVAC time step. The other
// conditions below are for when we are in the zone heat balance (SysTimeElapsed = 0) or after
// we have finished the last HVAC time step.

Real64 ActualTimeS;
Real64 ActualTimeE;
Real64 constexpr toleranceTime = 0.0001; // less than 1 second (to avoid comparisons that are not exactly identical but are essentially the same
if (SysTimeElapsed == 0.0) {
ActualTimeE = state.dataGlobal->CurrentTime;
ActualTimeS = ActualTimeE - state.dataGlobal->TimeStepZone;
} else if (std::abs(state.dataGlobal->TimeStepZone - SysTimeElapsed) <= toleranceTime) {
ActualTimeE = state.dataGlobal->CurrentTime;
ActualTimeS = ActualTimeE - TimeStepSys;
} else {
ActualTimeS = state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone + SysTimeElapsed;
ActualTimeE = ActualTimeS + TimeStepSys;
}
Copy link
Member

Choose a reason for hiding this comment

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

@RKStrand what an exciting PR! I appreciate your efforts and @rraustad scrutinizing this. I'm glad CI is coming out so clean with only a few unit test fixups.

int ActualTimeHrS = int(ActualTimeS);
// ActualTimeHrE=INT(ActualTimeE)
int ActualTimeMinS = nint((ActualTimeS - ActualTimeHrS) * FracToMin);
Expand Down
55 changes: 55 additions & 0 deletions tst/EnergyPlus/unit/General.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,59 @@ TEST_F(EnergyPlusFixture, General_findReportPeriodIdx)
EXPECT_FALSE(reportPeriodFlags(1));
EXPECT_FALSE(reportPeriodFlags(2));
}

TEST_F(EnergyPlusFixture, General_CreateSysTimeIntervalString_Test)
{
// Unit test created as part of fix for Issue #10801
auto &dHVACG = state->dataHVACGlobal;
auto &dGlo = state->dataGlobal;
std::string resultingString;
std::string expectedString;

// NOTE: SysTimeElapsed is updated at the END of the HVAC time step (loop), so it's current value is
// the end of the last HVAC time step not the end of the current HVAC time step. The other
// conditions below are for when we are in the zone heat balance (SysTimeElapsed = 0) or after
// we have finished the last HVAC time step.

// Test 1: Middle of the day/middle of zone timestep (system time step less than zone timestep)
dHVACG->SysTimeElapsed = 0.10;
dHVACG->TimeStepSys = 0.05;
dGlo->CurrentTime = 10.6;
dGlo->TimeStepZone = 0.2;
expectedString = "10:30 - 10:33";
Copy link
Collaborator

Choose a reason for hiding this comment

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

CurrentTime = 10.6 or 10:36 and TimeStepZone = 0.2 or 12 minutes, so at zone level this is time 10:24 - 10:36.
TimeStepSys = 0.05 or 3 minutes and SysTimeElapsed = 0.1 or 6 minutes. So I would expect this to be the 2nd of 4 system time steps. With those 4 time periods being: 10:24 - 10:27, 10:27 - 10:30, 10:30 - 10:33, and 10:33 - 10:36. So why is the unit test showing the 3rd of 4 time periods? Is SysTimeElapsed showing what has already been simulated (your answer would be right where start time = 10:30)? or what is being simulated (then something is wrong where start time would be 10:27)?

This relates to the else. It may be that ActualTimeS is really ActualTimeE and then ActualTimeS = ActualTimeE - TimeStepSys;

} else {
    ActualTimeS = state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone + SysTimeElapsed;
    ActualTimeE = ActualTimeS + TimeStepSys;
}

I would think this would show up the the csv and edd so you could quickly find out which is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm not sure why the comments I just made at the line are not showing up here...or why only half of your comment here shows up at the comment at Line 714. I'll paste in here and then respond to the second half of your comment about the else statement.


SysTimeElapsed gets updated at the end of the system time step. So, during a particular HVAC time step, while it is still simulating something, SysTimeElapsed is the time elapsed to the end of the last time step. So, in this case, because SysTimeElapsed is set to 0.1 and is not equal to the TimeStepZone, we are still simulating HVAC time steps, we have finished the time step that ends at SysTimeElapsed, and we are now in the NEXT HVAC time step. So, we have already simulated through 10:30 and are now in the 10:30-10:33 time frame. Does that make sense?

Now, what I'm not sure about is why when unix runs this that it thinks the answer should be 10:33-10:36. I think maybe because I used abs rather than std::abs, but that seems like a stretch. In any case, I did correct that and make another commit. Guess we'll see what comes back. So far, in the last hour+, I'm not getting any reports that the unit test is failing so I'm slightly hopeful.


Whew...unit test on unix is now coming back all green. Good thing because I had absolutely no other explanation as to why it would come back different on different operating systems. 😳😂


Ok, now about your else comment in the second half. The else condition is identical to what is being used in develop and I believe that is what we want. There weren't problems in develop with error messages so it seemed right to leave that as-is (this was a backtrack from the first version I committed after thinking this through again at your suggestion). And I believe that it is actually correct because SysTimeElapsed is not the end of the current HVAC time step but rather the previous one because it gets updated at the end of the HVAC time step. This hopefully gets rid of the .err file errors that showed up after the first commit where error messages that use this time stamp routine were shifted. That's not what we wanted, I think.


resultingString = CreateSysTimeIntervalString(*state);
EXPECT_EQ(resultingString, expectedString);

// Test 2: Beginning of the day/hour/timestep
dHVACG->SysTimeElapsed = 0.10;
dHVACG->TimeStepSys = 0.10;
dGlo->CurrentTime = 0.10;
dGlo->TimeStepZone = 0.10;
expectedString = "00:00 - 00:06";

resultingString = CreateSysTimeIntervalString(*state);
EXPECT_EQ(resultingString, expectedString);

// Test 3: End of the day/hour/timestep
dHVACG->SysTimeElapsed = 0.2;
dHVACG->TimeStepSys = 0.2;
dGlo->CurrentTime = 24.0;
dGlo->TimeStepZone = 0.2;
expectedString = "23:48 - 24:00";

resultingString = CreateSysTimeIntervalString(*state);
EXPECT_EQ(resultingString, expectedString);

// Test 4: SysTimeElapsed zero -- before HVAC simulation sets it
dHVACG->SysTimeElapsed = 0.0;
dHVACG->TimeStepSys = 0.1;
dGlo->CurrentTime = 10.9;
dGlo->TimeStepZone = 0.1;
expectedString = "10:48 - 10:54";

resultingString = CreateSysTimeIntervalString(*state);
EXPECT_EQ(resultingString, expectedString);
}

} // namespace EnergyPlus
2 changes: 1 addition & 1 deletion tst/EnergyPlus/unit/MixedAir.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6619,7 +6619,7 @@ TEST_F(EnergyPlusFixture, CO2ControlDesignOARateTest)
" ** ~~~ ** This may be overriding desired ventilation controls. Check inputs for Minimum Outdoor Air Flow Rate, Minimum Outdoor Air "
"Schedule Name and Controller:MechanicalVentilation",
" ** ~~~ ** Minimum OA fraction = 2.9412E-003, Mech Vent OA fraction = 1.5603E-003",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:15",
});

EXPECT_TRUE(compare_err_stream_substring(error_string, true));
Expand Down
2 changes: 1 addition & 1 deletion tst/EnergyPlus/unit/OutdoorAirUnit.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ TEST_F(EnergyPlusFixture, OutdoorAirUnit_AutoSize)
" ** ~~~ ** Air mass balance is required by other outdoor air units: Fan:ZoneExhaust, ZoneMixing, ZoneCrossMixing, or other air flow "
"control inputs.",
" ** ~~~ ** The outdoor mass flow rate = 0.602 and the exhaust mass flow rate = 0.000.",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:15",
});

EXPECT_TRUE(compare_err_stream(error_string, true));
Expand Down
16 changes: 14 additions & 2 deletions tst/EnergyPlus/unit/WaterThermalTanks.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3775,6 +3775,12 @@ TEST_F(EnergyPlusFixture, MixedTank_WarnPotentialFreeze)
// zero source mass flow rate
Tank.SourceMassFlowRate = 0.0;

// set time in simulation for time stamp in error message
state->dataHVACGlobal->SysTimeElapsed = 0.5;
state->dataHVACGlobal->TimeStepSys = 0.5;
state->dataGlobal->CurrentTime = 24.0;
state->dataGlobal->TimeStepZone = 0.5;

// Calls CalcWaterThermalTankMixed
Tank.CalcWaterThermalTank(*state);

Expand All @@ -3791,7 +3797,7 @@ TEST_F(EnergyPlusFixture, MixedTank_WarnPotentialFreeze)
" ** ~~~ ** Schedule will not be validated.",
" ** Warning ** CalcWaterThermalTankMixed: WaterHeater:Mixed = 'CHILLEDWATERTANK': "
"Temperature of tank < 2C indicates of possibility of freeze. Tank Temperature = 1.95 C.",
" ** ~~~ ** Environment=, at Simulation time= 00:-1 - 00:00"});
" ** ~~~ ** Environment=, at Simulation time= 23:30 - 24:00"});
EXPECT_TRUE(compare_err_stream(error_string, true));
}

Expand Down Expand Up @@ -3886,6 +3892,12 @@ TEST_F(EnergyPlusFixture, StratifiedTank_WarnPotentialFreeze)
// zero source mass flow rate
Tank.SourceMassFlowRate = 0.0;

// set time in simulation for time stamp in error message
state->dataHVACGlobal->SysTimeElapsed = 0.1;
state->dataHVACGlobal->TimeStepSys = 0.1;
state->dataGlobal->CurrentTime = 0.1;
state->dataGlobal->TimeStepZone = 0.1;

// Calls CalcWaterThermalTankStratified
Tank.CalcWaterThermalTank(*state);

Expand All @@ -3907,7 +3919,7 @@ TEST_F(EnergyPlusFixture, StratifiedTank_WarnPotentialFreeze)
" ** ~~~ ** Schedule will not be validated.",
" ** Warning ** CalcWaterThermalTankStratified: WaterHeater:Stratified = 'STRATIFIED CHILLEDWATERTANK': Temperature of "
"tank < 2C indicates of possibility of freeze. Tank Temperature = 1.75 C.",
" ** ~~~ ** Environment=, at Simulation time= 00:-1 - 00:00"});
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:06"});
EXPECT_TRUE(compare_err_stream(error_string, true));
}

Expand Down
6 changes: 3 additions & 3 deletions tst/EnergyPlus/unit/WaterUse.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ TEST_F(EnergyPlusFixture, WaterUse_WaterTempWarnings)
std::string const error_string1 = delimited_string({
" ** Warning ** CalcEquipmentFlowRates: \"CORE_ZN WATER EQUIPMENT\" - Hot water temperature is less than the cold water temperature by "
"(5.00 C)",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:15",
" ** ~~~ ** ...hot water temperature = 10.00 C",
" ** ~~~ ** ...cold water temperature = 15.00 C",
" ** ~~~ ** ...Hot water temperature should be greater than or equal to the cold water temperature. Verify temperature setpoints and "
Expand All @@ -478,7 +478,7 @@ TEST_F(EnergyPlusFixture, WaterUse_WaterTempWarnings)
std::string const error_string2 = delimited_string({
" ** Warning ** CalcEquipmentFlowRates: \"CORE_ZN WATER EQUIPMENT\" - Target water temperature is greater than the hot water temperature "
"by (6.70 C)",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:15",
" ** ~~~ ** ...target water temperature = 50.00 C",
" ** ~~~ ** ...hot water temperature = 43.30 C",
" ** ~~~ ** ...Target water temperature should be less than or equal to the hot water temperature. Verify temperature setpoints and "
Expand All @@ -496,7 +496,7 @@ TEST_F(EnergyPlusFixture, WaterUse_WaterTempWarnings)
std::string const error_string3 = delimited_string({
" ** Warning ** CalcEquipmentFlowRates: \"CORE_ZN WATER EQUIPMENT\" - Target water temperature is less than the cold water temperature "
"by (15.00 C)",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00",
" ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:15",
" ** ~~~ ** ...target water temperature = 0.00 C",
" ** ~~~ ** ...cold water temperature = 15.00 C",
" ** ~~~ ** ...Target water temperature should be greater than or equal to the cold water temperature. Verify temperature setpoints "
Expand Down
Loading