Skip to content

Commit 7083c34

Browse files
authored
Check overlap of SolidModel physical groups (#64)
* Add method to check overlap between physical groups * Add test for check_overlap with incorrect strict kw * Remove strict argument and output overlapping groups * Address PR feedback * Fix typo * Fix formatting
1 parent 75d8484 commit 7083c34

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/solidmodels/postrender.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,33 @@ function remove_group!(group::PhysicalGroup; recursive=true, remove_entities=fal
992992
return Tuple{Int32, Int32}[]
993993
end
994994

995+
"""
996+
check_overlap(sm::SolidModel)
997+
998+
Check for overlap/intersections between SolidModel groups of the same dimension.
999+
Intersections (if any) for entities of dimension dim should have dim-1. Otherwise it means there is overlap.
1000+
1001+
Return the overlapping groups as a vector of `(group1, group2, dimension)` `Tuple`s.
1002+
"""
1003+
function check_overlap(sm::SolidModel)
1004+
overlapping_groups = Tuple{String, String, Int}[]
1005+
for dim = 1:3
1006+
for (name1, _) in SolidModels.dimgroupdict(sm, dim)
1007+
for (name2, _) in SolidModels.dimgroupdict(sm, dim)
1008+
name1 >= name2 && continue
1009+
intersections = intersect_geom!(sm, name1, name2, dim, dim)
1010+
for intersection in intersections
1011+
if intersection[1] > dim - 1
1012+
@warn "Overlap of SolidModel groups $name1 and $name2 of dimension $dim."
1013+
push!(overlapping_groups, (name1, name2, dim))
1014+
end
1015+
end
1016+
end
1017+
end
1018+
end
1019+
return overlapping_groups
1020+
end
1021+
9951022
"""
9961023
staple_bridge_postrendering(; levels=[], base, bridge, bridge_height=1μm, output="bridge_metal")
9971024

test/test_solidmodel.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ import DeviceLayout.SolidModels.STP_UNIT
10031003
cs = CoordinateSystem("test", nm)
10041004
place!(cs, centered(Rectangle(500μm, 100μm)), :l1)
10051005
postrender_ops = [("ext", SolidModels.extrude_z!, (:l1, 20μm))]
1006-
sm = SolidModel("test"; overwrite=true)
1006+
sm = test_sm()
10071007
zmap = (m) -> (0μm)
10081008
render!(sm, cs, zmap=zmap, postrender_ops=postrender_ops)
10091009
sm["Xmin"] = SolidModels.get_boundary(sm["ext", 3]; direction="X", position="min")
@@ -1024,6 +1024,30 @@ import DeviceLayout.SolidModels.STP_UNIT
10241024
periodic_tags = SolidModels.set_periodic!(sm["Xmin", 2], sm["Xmax", 2])
10251025
@test !isempty(periodic_tags)
10261026

1027+
# check_overlap
1028+
cs = CoordinateSystem("test", nm)
1029+
r1 = Rectangle(2μm, 2μm)
1030+
r2 = translate(r1, Point(1μm, 0μm))
1031+
r3 = translate(r1, Point(2μm, 0μm))
1032+
place!(cs, r1, SemanticMeta(Symbol("r1")))
1033+
place!(cs, r2, SemanticMeta(Symbol("r2")))
1034+
sm = test_sm()
1035+
render!(sm, cs)
1036+
@test @test_logs (:warn, "Overlap of SolidModel groups r1 and r2 of dimension 2.") SolidModels.check_overlap(
1037+
sm
1038+
) == [(
1039+
"r1",
1040+
"r2",
1041+
2
1042+
)]
1043+
1044+
cs = CoordinateSystem("test", nm)
1045+
place!(cs, r1, SemanticMeta(Symbol("r1")))
1046+
place!(cs, r3, SemanticMeta(Symbol("r3")))
1047+
sm = test_sm()
1048+
render!(sm, cs)
1049+
@test isempty(SolidModels.check_overlap(sm))
1050+
10271051
# TODO: Composing OptionalStyle
10281052

10291053
# Explicitly MeshSized Path.

0 commit comments

Comments
 (0)