Skip to content

Add PlantLocation Shortcuts for Streamlined Access to Underlying Data#11428

Merged
mitchute merged 5 commits intodevelopfrom
PlantShortcut2
Feb 24, 2026
Merged

Add PlantLocation Shortcuts for Streamlined Access to Underlying Data#11428
mitchute merged 5 commits intodevelopfrom
PlantShortcut2

Conversation

@amirroth
Copy link
Collaborator

Pull request overview

Description of the purpose of this PR

This PR propagates the pattern of using direct links in the PlantLocation object (i.e., loop, side, branch, comp) instead of location indices (i.e., LoopNum, LoopSideNum, BranchNum, CompNum) to about 220 places in the code, specifically those the use the plant location object to access a loop's FluidProperties object. A number of places in the code (and in a few unit tests) had to be updated to populate this link information.

Pull Request Author

There is one failing unit test SQLiteFixture.OutputReportTabularAnnual_CurlyBraces but it fails for a completely independent reason (there is an arithmetic underflow when a number set to maxVal is subtracted from minVal in the table binning routine) and needs its own PR to resolve.

@amirroth amirroth self-assigned this Feb 23, 2026
@amirroth amirroth added DoNotPublish Includes changes that shouldn't be reported in the changelog Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring labels Feb 23, 2026
@amirroth amirroth added this to the EnergyPlus 26.1 milestone Feb 23, 2026
@amirroth amirroth requested a review from mitchute February 23, 2026 17:26
Copy link
Collaborator Author

@amirroth amirroth left a comment

Choose a reason for hiding this comment

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

Straightforward code review. Not much to this PR.


auto &this_comp(branch.Comp(CompCounter));
PlantLocation this_plantLoc = {this->plantLoc.loopNum, this->plantLoc.loopSideNum, BranchCounter, CompCounter};
this_plantLoc.loop = &state.dataPlnt->PlantLoop(this_plantLoc.loopNum);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update plantLoc struct to include direct pointers to loop, side, branch, and comp objects.

Copy link
Collaborator

@rraustad rraustad Feb 23, 2026

Choose a reason for hiding this comment

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

I was curious of the white space failure in code integrity (1733 and 1734):

Image

WaterCoils::SimulateWaterCoilComponents(state, CompName, FirstHVACIteration, this->m_HeatCoilNum);
Real64 const CoilMaxVolFlowRate = WaterCoils::GetCoilMaxWaterFlowRate(state, "Coil:Heating:Water", CompName, ErrorsFound);
rho = state.dataPlnt->PlantLoop(this->HWPlantLoc.loopNum).glycol->getDensity(state, Constant::HWInitConvTemp, RoutineName);
rho = this->HWPlantLoc.loop->glycol->getDensity(state, Constant::HWInitConvTemp, 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.

This is the standard simplification, just use the direct pointer rather than the lookup index. You will see this another 200 times.

plantLoc.side = &plantLoc.loop->LoopSide(LoopSideNum);
plantLoc.branch = &plantLoc.side->Branch(BranchNum);
plantLoc.comp = &plantLoc.branch->Comp(CompNum);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sure these pointers are initialized.

state->dataPlnt->PlantLoop(1).FluidIndex = 1;
state->dataPlnt->PlantLoop(1).glycol = Fluid::GetWater(*state);

state->dataWaterCoils->WaterCoil(1).WaterPlantLoc.loopNum = 1;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unit tests have to be updated to to perform these initializations, especially if they do not use IDF snippets and init_state.

@mitchute
Copy link
Collaborator

There is one failing unit test SQLiteFixture.OutputReportTabularAnnual_CurlyBraces but it fails for a completely independent reason (there is an arithmetic underflow when a number set to maxVal is subtracted from minVal in the table binning routine) and needs its own PR to resolve.

This one is on me. I'm working on a fix.

if (fanCoil.HCoilType_Num == HCoil::Water) {
Real64 rho =
state.dataPlnt->PlantLoop(fanCoil.HeatCoilPlantLoc.loopNum).glycol->getDensity(state, Constant::HWInitConvTemp, RoutineName);
Real64 rho = fanCoil.HeatCoilPlantLoc.loop->glycol->getDensity(state, Constant::HWInitConvTemp, RoutineName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm...how did this happen?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see. Nevermind.

@rraustad
Copy link
Collaborator

This looks good.

Copy link
Collaborator

@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.

Looks good. Let me know if you want me to handle the the code integrity failure.

@mitchute mitchute changed the title Plant shortcut2 Add PlantLocation Shortcuts for Streamlined Access to Underlying Data Feb 24, 2026
@mitchute
Copy link
Collaborator

This is ready. Merging.

@mitchute mitchute merged commit ee54360 into develop Feb 24, 2026
13 of 14 checks passed
@mitchute mitchute deleted the PlantShortcut2 branch February 24, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DoNotPublish Includes changes that shouldn't be reported in the changelog 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.

4 participants