Skip to content

Commit

Permalink
Merge pull request #5154 from openstudiocoalition/fix_5153
Browse files Browse the repository at this point in the history
Preserve SubSurface Outside Boundary Condition Object in ModelMerger
  • Loading branch information
jmarrec authored Apr 19, 2024
2 parents 9e8871e + 5d3c826 commit 969f480
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/model/ModelMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,29 @@ namespace model {
}
}
}

// setAdjacentSurface resets the AdjacentSubSurface on all child subsurfaces
for (const auto& newSubSurface : newSurface.subSurfaces()) {
// for performance reasons, only find matching subsurfaces if there is an AdjacentSubSurface
boost::optional<SubSurface> newAdjacentSubSurface = newSubSurface.adjacentSubSurface();
if (newAdjacentSubSurface) {
for (auto& cloneSubSurface : clone.subSurfaces()) {
if (circularEqual(newSubSurface.vertices(), cloneSubSurface.vertices(), 0.01)) {
// only subsurfaces with an AdjacentSubSurface will be added to the handle mapping
m_currentToNewHandleMapping[cloneSubSurface.handle()] = newSubSurface.handle();
m_newToCurrentHandleMapping[newSubSurface.handle()] = cloneSubSurface.handle();
boost::optional<UUID> currentAdjacentSubSurfaceHandle = getCurrentModelHandle(newAdjacentSubSurface->handle());
if (currentAdjacentSubSurfaceHandle) {
boost::optional<SubSurface> currentAdjacentSubSurface = m_currentModel.getModelObject<SubSurface>(*currentAdjacentSubSurfaceHandle);
if (currentAdjacentSubSurface) {
cloneSubSurface.setAdjacentSubSurface(*currentAdjacentSubSurface);
}
}
break;
}
}
}
}
}

// add new shadingSurfaceGroups
Expand Down
82 changes: 82 additions & 0 deletions src/model/test/ModelMerger_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,85 @@ TEST_F(ModelFixture, ModelMerger_ClimateZones_4166) {
EXPECT_EQ(ClimateZones::ashraeInstitutionName(), model1.getOptionalUniqueModelObject<ClimateZones>()->climateZones()[0].institution());
EXPECT_FALSE(model2.getOptionalUniqueModelObject<ClimateZones>());
}

TEST_F(ModelFixture, ModelMerger_Issue_5153) {

Model model1;
Model model2;
std::map<UUID, UUID> handleMapping;

// first model is empty

// second model has two spaces with adjacency

// object#_model#
std::vector<Point3d> floorprint1_2{
{0, 5, 0},
{5, 5, 0},
{5, 0, 0},
{0, 0, 0},
};

std::vector<Point3d> floorprint2_2{
{5, 5, 0},
{10, 5, 0},
{10, 0, 0},
{5, 0, 0},
};

// set up model 2
boost::optional<Space> space1_2 = Space::fromFloorPrint(floorprint1_2, 3, model2);
ASSERT_TRUE(space1_2);
space1_2->setName("Space 1 - Model 2");
EXPECT_EQ(6u, space1_2->surfaces().size());
EXPECT_EQ(4u, setWWR(*space1_2, 0.3));

boost::optional<Space> space2_2 = Space::fromFloorPrint(floorprint2_2, 3, model2);
ASSERT_TRUE(space2_2);
space2_2->setName("Space 2 - Model 2");
EXPECT_EQ(6u, space2_2->surfaces().size());
EXPECT_EQ(4u, setWWR(*space2_2, 0.3));

space1_2->matchSurfaces(*space2_2);

auto testModel = [](const Model& model) {

unsigned numOutdoorSurfaces = 0;
unsigned numGroundSurfaces = 0;
unsigned numAdjacentSurfaces = 0;
unsigned numOutdoorSubSurfaces = 0;
unsigned numAdjacentSubSurfaces = 0;

for (const auto& surface : model.getConcreteModelObjects<Surface>()) {
if (surface.outsideBoundaryCondition() == "Outdoors") {
++numOutdoorSurfaces;
} else if (surface.outsideBoundaryCondition() == "Ground") {
++numGroundSurfaces;
} else if (surface.outsideBoundaryCondition() == "Surface") {
++numAdjacentSurfaces;
}

for (const auto& subSurface : surface.subSurfaces()) {
if (subSurface.adjacentSubSurface()) {
++numAdjacentSubSurfaces;
} else {
++numOutdoorSubSurfaces;
}
}
}

EXPECT_EQ(8u, numOutdoorSurfaces);
EXPECT_EQ(2u, numGroundSurfaces);
EXPECT_EQ(2u, numAdjacentSurfaces);
EXPECT_EQ(6u, numOutdoorSubSurfaces);
EXPECT_EQ(2u, numAdjacentSubSurfaces);
};

testModel(model2);

// do merge
ModelMerger mm;
mm.mergeModels(model1, model2, handleMapping);

testModel(model1);
}

0 comments on commit 969f480

Please sign in to comment.