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 #4544 - CoilCoolingDX::clone crashes when called with another model #4576

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/model/CoilCoolingDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace model {
std::vector<ModelObject> result;

// This is a ResourceObject, so it shouldn't really be a child except for OS App / IG
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the strategy over in the App if performance objects are no longer children? Is there a corresponding change to App to specialize the IG for this type? Or maybe instead it is just ok to not show the performance data? I'm just asking out of curiousity. I agree that the main impact of this PR pertains to the App's inspector.

result.push_back(performanceObject());
// result.push_back(performanceObject());

std::vector<AirflowNetworkEquivalentDuct> myAFNItems =
getObject<ModelObject>().getModelObjectSources<AirflowNetworkEquivalentDuct>(AirflowNetworkEquivalentDuct::iddObjectType());
Expand Down
4 changes: 2 additions & 2 deletions src/model/CoilCoolingDXCurveFitOperatingMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ namespace model {

std::vector<ModelObject> CoilCoolingDXCurveFitOperatingMode_Impl::children() const {
// These are ResourceObjects, so they shouldn't really be children except for OS App / IG
std::vector<ModelObject> result = subsetCastVector<ModelObject>(speeds());

// std::vector<ModelObject> result = subsetCastVector<ModelObject>(speeds());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just remove this line instead of a comment?

std::vector<ModelObject> result;
return result;
}

Expand Down
14 changes: 7 additions & 7 deletions src/model/CoilCoolingDXCurveFitPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ namespace model {
std::vector<ModelObject> result;

// These are ResourceObjects, so they shouldn't really be children except for OS App / IG
result.push_back(baseOperatingMode());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I rebased the change(s) onto my codebase and rebuild and cause the failure of serveral tests.

[  FAILED  ] 3 tests, listed below:
[  FAILED  ] ModelFixture.CoilCoolingDX_clone
[  FAILED  ] ModelFixture.CoilCoolingDXCurveFitPerformance_clone
[  FAILED  ] ModelFixture.CoilCoolingDXCurveFitOperatingMode_clone

Do you mind review the tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'm still not sure how to fix it properly. I need to revisit this at some point.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I deep dived into the unittests and find the issue is happening in

  EXPECT_EQ(0u, model.getConcreteModelObjects<CoilCoolingDXCurveFitOperatingMode>().size());

Which the model.getConcreteModelObjects<CoilCoolingDXCurveFitOperatingMode>().size()'s value is 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.

I have access to Jenkins FYI, so I have access to the failed runs to see the failures.

The solution to having both clone to same model and clone to another is not trivial though. I'll eventually get back to this PR, it's a minor bug with a rather expensive solution: one that requires reimplementing or overriding the internals of ResourceObject and ParentObject (getRecursiveResources / getRecursiveChildren) and how things are added at Workspace level (addObjects). That portion of the sdk is complicated and finicky.
I've converted the PR to draft in the meantime for clarity.

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 someone is burning to fix this though please go ahead. I think I have a jupyter notebook somewhere where I've rewritten the getRecursiveXXX stuff to be able to test changes, I could try to locate it.

if (auto _mode = alternativeOperatingMode1()) {
result.push_back(_mode.get());
}
if (auto _mode = alternativeOperatingMode2()) {
result.push_back(_mode.get());
}
// result.push_back(baseOperatingMode());
// if (auto _mode = alternativeOperatingMode1()) {
// result.push_back(_mode.get());
// }
// if (auto _mode = alternativeOperatingMode2()) {
// result.push_back(_mode.get());
// }

return result;
}
Expand Down
26 changes: 26 additions & 0 deletions src/model/test/CoilCoolingDX_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,29 @@ TEST_F(ModelFixture, CoilCoolingDX_cloneParent) {
EXPECT_EQ(dx, unitary.coolingCoil().get());
EXPECT_NE(dx, unitaryClone.coolingCoil().get());
}

TEST_F(ModelFixture, CoilCoolingDX_cloneOtherModel) {
Model model;

CoilCoolingDXCurveFitOperatingMode operatingMode(model);
CoilCoolingDXCurveFitPerformance performance(model, operatingMode);
CoilCoolingDX dx(model, performance);

EXPECT_EQ(performance, dx.performanceObject());
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDX>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDXCurveFitPerformance>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDXCurveFitOperatingMode>().size());

Model model2;
auto dxClone = dx.clone(model2).cast<CoilCoolingDX>();
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDX>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDXCurveFitPerformance>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<CoilCoolingDXCurveFitOperatingMode>().size());

EXPECT_EQ(1u, model2.getConcreteModelObjects<CoilCoolingDX>().size());
EXPECT_EQ(1u, model2.getConcreteModelObjects<CoilCoolingDXCurveFitPerformance>().size());
EXPECT_EQ(1u, model2.getConcreteModelObjects<CoilCoolingDXCurveFitOperatingMode>().size());

EXPECT_EQ(performance, dx.performanceObject());
EXPECT_NE(performance, dxClone.performanceObject());
}