Skip to content

Fix AirTerminal:SingleDuct:UserDefined crash (accessing uninitialized but unneeded AirDistUnit array)#11223

Merged
mitchute merged 10 commits intodevelopfrom
fix-airterminal-userdefined
Oct 24, 2025
Merged

Fix AirTerminal:SingleDuct:UserDefined crash (accessing uninitialized but unneeded AirDistUnit array)#11223
mitchute merged 10 commits intodevelopfrom
fix-airterminal-userdefined

Conversation

@tanaya-mankad
Copy link
Collaborator

Pull request overview

Description of the purpose of this PR

Two user-defined types were being initialized in the same function, GetUserDefinedComponents. This conflation led to AirTerminal objects having ZoneHVAC objects' needs being applied to them, when their members hadn't yet been sized. A solution was to pull the "Get" methods into two separate methods, fixing a copy-paste typo along the way. Also, since so many of the objects in UserDefinedComponents are wholesale duplication of code, we could consolidate a bit using a base struct. (However, most of the duplication has been left alone.)

The issue seems to have been exposed due to a test file containing both types of user-defined air objects. Existing IDF test files that only contain one or the other seem to simulate normally.

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@tanaya-mankad tanaya-mankad added the Defect Includes code to repair a defect in EnergyPlus label Sep 22, 2025
@tanaya-mankad tanaya-mankad self-assigned this Sep 22, 2025
@tanaya-mankad tanaya-mankad marked this pull request as ready for review October 2, 2025 18:58
@mitchute mitchute requested review from mitchute and rraustad October 8, 2025 18:25
// one assumes if there isn't one assigned, it's an error?
if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ADUNum == 0) {
ShowSevereError(state,
format("GetUserDefinedComponents: No matching Air Distribution Unit for {} = {}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hate to do this but you renamed this function to GetUserDefinedAirTerminal. And yes, this is an error , the AirTerminal is specified in an ADU. That's the only place this object is listed as allowed. So this AirTerminal must not be listed in an ADU and therefore is an orphan object.

ZoneHVAC:AirDistributionUnit,
   \memo Central air system air distribution unit, serves as a wrapper for a specific type of
   \memo air terminal unit. This object is referenced in a ZoneHVAC:EquipmentList.
   \min-fields 4
A1 , \field Name
   \required-field
   \reference ZoneEquipmentNames
A2 , \field Air Distribution Unit Outlet Node Name
   \required-field
   \type node
A3 , \field Air Terminal Object Type
   \type choice
   \key AirTerminal:DualDuct:ConstantVolume
   \key AirTerminal:DualDuct:VAV
   \key AirTerminal:SingleDuct:ConstantVolume:Reheat
   \key AirTerminal:SingleDuct:ConstantVolume:NoReheat
   \key AirTerminal:SingleDuct:ConstantVolume:FourPipeBeam
   \key AirTerminal:SingleDuct:VAV:Reheat
   \key AirTerminal:SingleDuct:VAV:NoReheat
   \key AirTerminal:SingleDuct:SeriesPIU:Reheat
   \key AirTerminal:SingleDuct:ParallelPIU:Reheat
   \key AirTerminal:SingleDuct:ConstantVolume:FourPipeInduction
   \key AirTerminal:SingleDuct:VAV:Reheat:VariableSpeedFan
   \key AirTerminal:SingleDuct:VAV:HeatAndCool:Reheat
   \key AirTerminal:SingleDuct:VAV:HeatAndCool:NoReheat
   \key AirTerminal:SingleDuct:ConstantVolume:CooledBeam
   \key AirTerminal:DualDuct:VAV:OutdoorAir
   \key AirTerminal:SingleDuct:UserDefined
   \key AirTerminal:SingleDuct:Mixer
   \required-field

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops.
What do you think of GetUserDefinedAirComponent, or GetUserDefinedZoneAirComponent?

"There are only two hard things in Computer Science: cache invalidation and naming things."
-- Phil Karlton

state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ADUNum = ADUNum;
if (state.dataUserDefinedComponents->NumUserAirTerminals > 0) { // Skip this code if the only User Defined type is ZoneHVAC
int ADUNum = 0;
for (ADUNum = 1; ADUNum <= (int)state.dataDefineEquipment->AirDistUnit.size(); ++ADUNum) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wasn't going to say anything since this was existing but you might as well fix this one while your in here, for( int ADUNum, line 2113 isn't needed.

if (state.dataUserDefinedComponents->GetPlantCompInput) {
GetUserDefinedPlantComponents(state);
state.dataUserDefinedComponents->GetPlantCompInput = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really do hurt ourselves by the choice of our example files. This is a good fix. So would be init_state.

Copy link
Collaborator

@rraustad rraustad left a comment

Choose a reason for hiding this comment

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

@mitchute this looks good to go with a simple change.

@mitchute
Copy link
Collaborator

mitchute commented Oct 9, 2025

Thanks @rraustad. I'll kick it back to @tanaya-mankad for now, but feel free to ping me when ready and we'll get it in.

@mitchute
Copy link
Collaborator

This is looking ready. We'll let CI finish then merge this.

@mitchute mitchute added this to the EnergyPlus 25.2 milestone Oct 23, 2025
@mitchute mitchute merged commit bb1a22d into develop Oct 24, 2025
8 checks passed
@mitchute mitchute deleted the fix-airterminal-userdefined branch October 24, 2025 03:02
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AirTerminal:SingleDuct:UserDefined cannot find matching outlet node in ZoneHVAC:AirDistributionUnit

5 participants