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

Fix Integrated Heat Pump Output Variable Setup #9249

Merged
merged 12 commits into from
Mar 2, 2022
Merged

Conversation

mitchute
Copy link
Collaborator

Pull request overview

@mitchute mitchute added Defect Includes code to repair a defect in EnergyPlus Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring labels Jan 25, 2022
@mitchute mitchute requested a review from mjwitte January 25, 2022 20:55
@mitchute mitchute self-assigned this Jan 25, 2022
Comment on lines 1972 to 1978
if (ErrorsFound) {
ShowFatalError(state,
std::string{RoutineName} + "Errors found in getting " + CurrentModuleObject +
" input. Preceding condition(s) causes termination.");
} else {
// set up output variables, not reported in the individual coil models
SetupOutputVariable(state,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this chunk into the for loop. The rest is indentation formatting.

Copy link
Contributor

Choose a reason for hiding this comment

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

So E+ will fatal out on the first IHP with an input error? i.e., ErrorsFound will be true for that IHP and the rest will not be read in. We typically loop through all instances of an equipment type to allow the warnings to print to the error file so the user can fix all at once instead of one at a time. It would be better to move this back and for loop inside the else to set up report vars for all IHPs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, @rraustad. I moved the fatal error call outside of the get input and SetupOutputVars now happens all at once after that.

Copy link
Collaborator Author

@mitchute mitchute left a comment

Choose a reason for hiding this comment

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

@Myoldmopar @rraustad @mjwitte I'd be interested to have your comments on this commit (4af38ce).

Sizing of the various variable speed coils in here was doing some weird stuff with showing an error message and then setting the error flag to false. I'm pretty sure most of the error messages in here were unreachable. I think I "fixed" it, although I'm pretty sure this is going to cause at least one unit test failure that will have to be handled if we keep this in.

@rraustad
Copy link
Contributor

rraustad commented Feb 2, 2022

The ErrorsFound flag (the king) is the getInput function flag for any errors found and should terminate the program after processing all objects. The local errFlag (the soldier) is used for the mining calls where some mining calls use to set errFlag false inside the mining function and then set back to true if an issue was found, I think we got rid of all those, so the King could get reset to false, part way through getInput, if it were used. So to be safe, a local errFlag is set to false before calling a mining function, because it could have been set to true from a previous mining call, and then if there is an error inside the mining function (i.e., errFlag = true for this call) then a warning is issued and ErrorsFound is set true.

Copy link
Collaborator Author

@mitchute mitchute left a comment

Choose a reason for hiding this comment

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

The scope blew up well beyond the original issue, but this seems like a good set of cleanups.

Comment on lines +74 to +75
Real64 constexpr WaterDensity(986.0); // standard water density at 60 C

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was hardcoded into a couple of functions. I just pulled it up here and made it constexpr

state.dataIntegratedHP->GetCoilsInputFlag = false;
}

if (CompIndex == 0) {
DXCoilNum = UtilityRoutines::FindItemInList(CompName, state.dataIntegratedHP->IntegratedHeatPumps);
if (DXCoilNum == 0) {
ShowFatalError(state, "Integrated Heat Pump not found=" + std::string{CompName});
ShowFatalError(state, format("Integrated Heat Pump not found={}", CompName));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

format all the things.

@@ -138,21 +137,22 @@ void SimIHP(EnergyPlusData &state,
}
};

if (!state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum).IHPCoilsSized) SizeIHP(state, DXCoilNum);
auto &ihp = state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using auto &iph = ... everywhere to shorten lines.

Comment on lines -1164 to +1165
int DXCoilNum; // No of IHP DX system
int NumASIHPs; // Counter for air-source integrated heat pumps

int NumAlphas; // Number of variables in String format
int NumNums; // Number of variables in Numeric format
int NumParams; // Total number of input fields
int MaxNums(0); // Maximum number of numeric input fields
int MaxAlphas(0); // Maximum number of alpha input fields
std::string CoilName; // Name of the Coil
std::string Coiltype; // type of coil
std::string InNodeName; // Name of coil inlet node
std::string OutNodeName; // Name of coil outlet node

int NumAlphas; // Number of variables in String format
int NumNums; // Number of variables in Numeric format
int NumParams; // Total number of input fields
int MaxNums(0); // Maximum number of numeric input fields
int MaxAlphas(0); // Maximum number of alpha input fields
std::string InNodeName; // Name of coil inlet node
std::string OutNodeName; // Name of coil outlet node
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rescope or eliminate local vars where possible.

Comment on lines +1775 to +1778
// why was this here
// state.dataVariableSpeedCoils->VarSpeedCoil(ihp.SHDWHWHCoilIndex).AirInletNodeNum = InNode;
// state.dataVariableSpeedCoils->VarSpeedCoil(ihp.SHDWHWHCoilIndex).AirOutletNodeNum = OutNode;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The coil inlet and outlet node nums were begin set here, but as far as I can tell they should have already been set elsewhere. I'm not seeing any diffs currently by leaving this out, but I left it commented out in case someone needs to do a forensics deep-dive on this code later.

Comment on lines -73 to +81
IdleMode,
SCMode,
SHMode,
DWHMode,
SCWHMatchSCMode,
SCWHMatchWHMode,
SCDWHMode,
SHDWHElecHeatOffMode,
SHDWHElecHeatOnMode,
Idle,
SpaceClg, // Space Cooling
SpaceHtg, // Space Heating
DedicatedWaterHtg, // Dedicated Water Heating
SCWHMatchSC, // Space Cooling Water Heating
SCWHMatchWH,
SpaceClgDedicatedWaterHtg,
SHDWHElecHeatOff,
SHDWHElecHeatOn,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove Mode and rename so the values are somewhat intelligible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should rename the remaining values to be somewhat intelligible too. I know SpaceHtgDedicatedWaterHtgElecHeatOff is long, but it's still better than SHDWHElecHeatOff. These long acronyms are crazy making.

Comment on lines +3831 to +3835
ErrorsFound = false;
SizeVarSpeedCoil(state, DXCoilNum, ErrorsFound);
if (ErrorsFound) {
ShowFatalError(state, format("{}: Failed to size variable speed coil.", RoutineName));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Better sizing error handling here.

Comment on lines +3879 to +3883
ErrorsFound = false;
SizeVarSpeedCoil(state, DXCoilNum, ErrorsFound);
if (ErrorsFound) {
ShowFatalError(state, format("{}: Failed to size variable speed coil.", RoutineName));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same

@@ -4440,7 +4447,7 @@ namespace VariableSpeedCoils {
state.dataHeatBal->HeatReclaimVS_DXCoil(DXCoilNum).AvailCapacity = 0.0;
}

void SizeVarSpeedCoil(EnergyPlusData &state, int const DXCoilNum)
void SizeVarSpeedCoil(EnergyPlusData &state, int const DXCoilNum, bool &ErrorsFound)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let SizeVarSpeedCoil propagate its errors back up to the caller.

Comment on lines -10142 to 10153
if (this->WaterThermalTankType == DataPlant::PlantEquipmentType::WtrHeaterMixed) {
switch (this->WaterThermalTankType) {
case DataPlant::PlantEquipmentType::WtrHeaterMixed:
this->CalcWaterThermalTankMixed(state);
} else if (this->WaterThermalTankType == DataPlant::PlantEquipmentType::WtrHeaterStratified) {
break;
case DataPlant::PlantEquipmentType::WtrHeaterStratified:
this->CalcWaterThermalTankStratified(state);
} else {
break;
default:
assert(false);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if/else to switch/case here, and below.

@mitchute
Copy link
Collaborator Author

mitchute commented Feb 3, 2022

The Windows build here looks like a fluke since it failed in the Transition project. I've built and run unit tests locally and it's looking just like the results from the other platforms.

@mjwitte mjwitte added this to the EnergyPlus 22.1 milestone Feb 8, 2022
@Myoldmopar
Copy link
Member

@mitchute so there seems to be something up with that failing unit test. I think it's the one that occasionally fails on Mac, but now it's failing across the board, so that's new. I remember talking with you about some of this PR, but I can't remember if that aspect was part of it. Let me know if you want me to run it to reproduce and/or find the issue so that I can get this in. Thanks!

@mitchute
Copy link
Collaborator Author

mitchute commented Feb 11, 2022

@Myoldmopar SizeVarSpeedCoil wasn't propagating its errors back up to the caller. Now that it is, that unit test fails because that sizing function fails.

auto &ihp = state.dataIntegratedHP->IntegratedHeatPumps(CoilCounter);

ihp.Name = AlphArray(1);
ihp.IHPtype = "AIRSOURCE_IHP";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be an enum that can be converted to string for display purposes using a constexpr std::array<std::string_view>.

state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum).SCCoilName = AlphArray(3);
Coiltype = state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum).SCCoilType;
CoilName = state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum).SCCoilName;
ihp.SCCoilType = "COIL:COOLING:DX:VARIABLESPEED";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a need to store this string? Will it ever be used other than in the ValidateComponent call below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm working more on further propagating the component type enum around. These will eventually go away.

if (IsCallbyWH) // process when called from water loop
{
SimVariableSpeedCoils(state,
std::string(),
state.dataIntegratedHP->IntegratedHeatPumps(DXCoilNum).SCDWHCoolCoilIndex,
ihp.SCDWHCoolCoilIndex,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may be able to make these into a loop using the enum OperationMode as the index.

@mjwitte
Copy link
Contributor

mjwitte commented Feb 28, 2022

@mitchute Is this ready for final review? It's a ways behind develop, so please merge it up.

@mitchute
Copy link
Collaborator Author

@mjwitte @Myoldmopar done. There's one failing unit test - see here: #9249 (comment)

IMO, that unit test has some deeper issues that this work exposed. So, we either hold this up and address that first or disable the unit test and figure it out after.

@Myoldmopar
Copy link
Member

Thanks @mitchute. I'm not a fan of disabling tests willy-nilly, but this fix needs to get in, and your work here just revealed that the test shouldn't have been passing. No big deal, sometime I'll get some energy to re-enable any disabled unit tests and figure out why they aren't working. Assuming this continues to be clean I'll merge it tonight.

@Myoldmopar
Copy link
Member

Tested with latest develop, no problems. Love these fast running unit test suites..... :) Anyway, all good here, thanks @mitchute , merging.

@Myoldmopar Myoldmopar merged commit 1cb2067 into develop Mar 2, 2022
@Myoldmopar Myoldmopar deleted the ihp-output-vars branch March 2, 2022 18:35
@nealkruis
Copy link
Member

@mitchute, I am making changes that impact the IDF snippets for the test disabled here. I am going to leave this alone for now, but I imagine we should make a new issue to make sure we don't lose track of re-enabling the test down the road.

@mitchute
Copy link
Collaborator Author

mitchute commented May 3, 2023

@nealkruis good idea. I don't remember the particulars here but feel free to make an issue so we don't lose track of it.

@nealkruis
Copy link
Member

@mitchute I don't really know the context here or why the test had to be disabled. I just noticed that there was an intention to follow up, but it might have been lost. I'll let you and @Myoldmopar sort out how to follow up on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrated Heat Pump Outputs Vars Only Being Set for Last Instance