Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7711 - Fix crash when using both WaterHeat:HeatPump:PumpedCondenser and WaterHeater:HeatPump:WrappedCondenser #7717

Merged
merged 8 commits into from
Feb 12, 2020
18 changes: 13 additions & 5 deletions src/EnergyPlus/WaterThermalTanks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ namespace WaterThermalTanks {
int nNumPossibleNumericArgs; // the number of possible numeric arguments in the idd
int nNumPossibleAlphaArgs; // the number of possible numeric arguments in the idd

// For looking up in IDF/epJSON, you need the index that corresponds to the actual object type (Pumped or Wrapped)
int HPWaterHeaterNumOfSpecificType;

for (int HPWaterHeaterNum = 1; HPWaterHeaterNum <= numHeatPumpWaterHeater; ++HPWaterHeaterNum) {

// Create reference to current HPWH object in array.
Expand All @@ -1043,25 +1046,30 @@ namespace WaterThermalTanks {
// Initialize the offsets to zero
nAlphaOffset = 0;
nNumericOffset = 0;

if (HPWaterHeaterNum <= NumPumpedCondenser) {
// Pumped Condenser
DataIPShortCuts::cCurrentModuleObject = cHPWHPumpedCondenser;
HPWH.TypeNum = DataPlant::TypeOf_HeatPumpWtrHeaterPumped;
nNumPossibleAlphaArgs = 29;
nNumPossibleNumericArgs = 9;
// Actual index of Pumped type
HPWaterHeaterNumOfSpecificType = HPWaterHeaterNum;
} else {
// Wrapped Condenser
DataIPShortCuts::cCurrentModuleObject = cHPWHWrappedCondenser;
HPWH.TypeNum = DataPlant::TypeOf_HeatPumpWtrHeaterWrapped;
nNumPossibleAlphaArgs = 27;
nNumPossibleNumericArgs = 10;
// Actual index of Wrapped type
HPWaterHeaterNumOfSpecificType = HPWaterHeaterNum - NumPumpedCondenser;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual fix basically.

Container HPWaterHeater stores both HPWH:Pumped and HPWH:Wrapped in that order. Before fix if you had 1 HPWH:Pumped and one HPWH:Wrapped it would call getObjectItem for the wrapped one passing an index of 2, which doesn't exist in InputProcessor since there's only one object of type HPWH:WrappedCondenser, so it would crash hard.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmarrec thanks for the fix. Having just worked through the refactor on this file, I can attest that there are several things like this in here that need to get cleaned up.

}

int NumAlphas;
int NumNums;
int IOStat;
inputProcessor->getObjectItem(DataIPShortCuts::cCurrentModuleObject,
HPWaterHeaterNum,
HPWaterHeaterNumOfSpecificType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has to be an index specific to the type of object you want to get.

DataIPShortCuts::cAlphaArgs,
NumAlphas,
DataIPShortCuts::rNumericArgs,
Expand Down Expand Up @@ -11337,7 +11345,7 @@ namespace WaterThermalTanks {

// PURPOSE OF THIS SUBROUTINE:
// Calculates the water heater standard ratings, such as Energy Factor and Recovery Efficiency. Results are written
// to the EIO file. Standard ratings are not calculated for storage-only tanks, i.e., MaxCapacity = 0.
// to the EIO file. Standard ratings are not calculated for storage-only tanks, i.e., MaxCapacity = 0, nor for Integrated Heat Pumps

// METHODOLOGY EMPLOYED:
// Water heater inputs are set to the specified test conditions. For HPWHs, the heating capacity and COP are assumed
Expand Down Expand Up @@ -11378,7 +11386,6 @@ namespace WaterThermalTanks {
FirstTimeFlag = true;

int TimeStepPerHour = int(1.0 / DataHVACGlobals::TimeStepSys);
int HPNum = 0;
// Simulate 24 hour test
for (int Step = 1; Step <= TimeStepPerHour * 24; ++Step) {

Expand Down Expand Up @@ -11417,7 +11424,7 @@ namespace WaterThermalTanks {

} else {

HPNum = this->HeatPumpNum;
int HPNum = this->HeatPumpNum; // Convenience variable
Real64 AmbientHumRat = 0.00717; // Humidity ratio at 67.5 F / 50% RH

// set the heat pump air- and water-side mass flow rate
Expand Down Expand Up @@ -11679,7 +11686,8 @@ namespace WaterThermalTanks {
} else {
RecoveryEfficiency = 0.0;
EnergyFactor = 0.0;
if (HPWaterHeater.empty() || !HPWaterHeater(HPNum).bIsIHP) {
// If this a regular tank, or an HPWH that's not an Integrated one
if ((this->HeatPumpNum == 0) || !HPWaterHeater(this->HeatPumpNum).bIsIHP) {
ShowWarningError("Water heater = " + this->Name +
": Recovery Efficiency and Energy Factor could not be calculated during the test for standard ratings");
ShowContinueError("Setpoint was never recovered and/or heater never turned on");
Expand Down
Loading