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

Fan:SystemModel with discrete speed flow fractions crashes when speeds >= 2 #10846

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
55 changes: 34 additions & 21 deletions src/EnergyPlus/HVACVariableRefrigerantFlow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4380,21 +4380,11 @@ void GetVRFInputData(EnergyPlusData &state, bool &ErrorsFound)
vrfTU.NumOfSpeedCooling = fanSystem->numSpeeds;
vrfTU.CoolVolumeFlowRate.resize(fanSystem->numSpeeds + 1);
vrfTU.CoolMassFlowRate.resize(fanSystem->numSpeeds + 1);
if (vrfTU.MaxCoolAirVolFlow != DataSizing::AutoSize) {
for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
vrfTU.CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
}
}
Copy link
Contributor Author

@rraustad rraustad Dec 5, 2024

Choose a reason for hiding this comment

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

Crashes in these places in VRF GetInput because massFlowAtSpeed is allocated in the fan's set_size function and that has not been called yet.

}
if (vrfTU.DXHeatCoilType_Num == HVAC::CoilVRF_Heating) {
vrfTU.NumOfSpeedHeating = fanSystem->numSpeeds;
vrfTU.HeatVolumeFlowRate.resize(fanSystem->numSpeeds + 1);
vrfTU.HeatMassFlowRate.resize(fanSystem->numSpeeds + 1);
if (vrfTU.MaxHeatAirVolFlow != DataSizing::AutoSize) {
for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
vrfTU.HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
}
}
}
ShowWarningError(state,
cCurrentModuleObject + " = " + thisVrfTU.Name + " with Fan:SystemModel is used in " + cAlphaArgs(8) + "\"");
Expand Down Expand Up @@ -6421,8 +6411,32 @@ void InitVRF(EnergyPlusData &state, int const VRFTUNum, int const ZoneNum, bool
// one-time checks of flow rate vs fan flow rate
if (state.dataHVACVarRefFlow->MyVRFFlag(VRFTUNum)) {
if (!state.dataGlobal->ZoneSizingCalc && !state.dataGlobal->SysSizingCalc) {
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanPlace != HVAC::FanPlace::Invalid) { // was > 0 (is 0 invalid?)
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate != AutoSize) {
auto &vrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
if (vrfTU.fanPlace != HVAC::FanPlace::Invalid) { // was > 0 (is 0 invalid?)
if (vrfTU.ActualFanVolFlowRate != AutoSize) {

if (vrfTU.fanType == HVAC::FanType::SystemModel) {
auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(vrfTU.FanIndex));
if (fanSystem->speedControl == Fans::SpeedControl::Discrete &&
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex < 0) {
if (fanSystem->numSpeeds > 1) {
if (vrfTU.DXCoolCoilType_Num == HVAC::CoilVRF_Cooling) {
if (vrfTU.MaxCoolAirVolFlow != DataSizing::AutoSize) {
for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
vrfTU.CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
}
}
}
if (vrfTU.DXHeatCoilType_Num == HVAC::CoilVRF_Heating) {
if (vrfTU.MaxHeatAirVolFlow != DataSizing::AutoSize) {
for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
vrfTU.HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
}
}
}
}
}
}
Copy link
Contributor Author

@rraustad rraustad Dec 5, 2024

Choose a reason for hiding this comment

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

So moved these initializations to Init where the code waits for the fan to size before setting up air flow variables.


if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow >
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
Expand Down Expand Up @@ -7351,11 +7365,10 @@ void InitVRF(EnergyPlusData &state, int const VRFTUNum, int const ZoneNum, bool
SetAverageAirFlow(state, VRFTUNum, 0.0, OnOffAirFlowRatio);

if (ErrorsFound) {
ShowFatalError(
state,
format(
"{}: Errors found in getting ZoneHVAC:TerminalUnit:VariableRefrigerantFlow system input. Preceding condition(s) causes termination.",
RoutineName));
ShowFatalError(state,
format("{}: Errors found in getting ZoneHVAC:TerminalUnit:VariableRefrigerantFlow system input. Preceding condition(s) "
"causes termination.",
RoutineName));
}
}

Expand Down Expand Up @@ -7728,7 +7741,7 @@ void SizeVRF(EnergyPlusData &state, int const VRFTUNum)
} else {
auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
assert(fanSystem != nullptr);
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0) {
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just in case the fan has not yet been sized.

state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
Expand Down Expand Up @@ -7814,7 +7827,7 @@ void SizeVRF(EnergyPlusData &state, int const VRFTUNum)
} else {
auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
assert(fanSystem != nullptr);
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0) {
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
Expand Down Expand Up @@ -7978,7 +7991,7 @@ void SizeVRF(EnergyPlusData &state, int const VRFTUNum)
} else {
auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
assert(fanSystem != nullptr);
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0) {
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
Expand Down Expand Up @@ -8017,7 +8030,7 @@ void SizeVRF(EnergyPlusData &state, int const VRFTUNum)
} else {
auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
assert(fanSystem != nullptr);
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0) {
if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
Expand Down
Loading
Loading