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

fixed meshing issues: issue #150 | discussion #156 #159

Merged
merged 12 commits into from
May 28, 2024
25 changes: 13 additions & 12 deletions femwell/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
initial_settings = np.seterr() # remove when shapely updated to more recent geos


def break_line_(line, other_line):
def break_line_(line, other_line, snap_tol = 0.1):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def break_line_(line, other_line, snap_tol = 0.1):
def break_line_(line, other_line, snap_tol):

Let's not assume a default value, we can let the program crash if this is called without a value

np.seterr(invalid="ignore")
intersections = line.intersection(other_line)
np.seterr(**initial_settings)
Expand All @@ -31,7 +31,7 @@ def break_line_(line, other_line):
):
# if type == "", intersection.type != 'Point':
if intersection.geom_type == "Point":
line = snap(line, intersection, 0.1)
line = snap(line, intersection, snap_tol)
else:
new_coords_start, new_coords_end = intersection.boundary.geoms
line = linemerge(split(line, new_coords_start))
Expand Down Expand Up @@ -204,7 +204,8 @@ def mesh_from_OrderedDict(
gmsh.option.setNumber("Mesh.Algorithm", gmsh_algorithm)

model = geometry

meshtracker = MeshTracker(model=model)

# Break up shapes in order so that plane is tiled with non-overlapping layers, overriding shapes according to an order
shapes_tiled_dict = OrderedDict()
for lower_index, (lower_name, lower_shape) in reversed(
Expand Down Expand Up @@ -250,8 +251,8 @@ def mesh_from_OrderedDict(
else second_shape
)
first_exterior_line = break_line_(
first_exterior_line, second_exterior_line
)
first_exterior_line, second_exterior_line,
snap_tol = meshtracker.atol)
# Second line interiors
for second_interior_line in (
second_shape.interiors
Expand All @@ -260,8 +261,8 @@ def mesh_from_OrderedDict(
):
second_interior_line = LineString(second_interior_line)
first_exterior_line = break_line_(
first_exterior_line, second_interior_line
)
first_exterior_line, second_interior_line,
snap_tol = meshtracker.atol)
# First line interiors
if first_shape.geom_type in ["Polygon", "MultiPolygon"]:
first_shape_interiors = []
Expand All @@ -286,8 +287,8 @@ def mesh_from_OrderedDict(
else second_shape
)
first_interior_line = break_line_(
first_interior_line, second_exterior_line
)
first_interior_line, second_exterior_line,
snap_tol = meshtracker.atol)
# Interiors
for second_interior_line in (
second_shape.interiors
Expand All @@ -301,8 +302,8 @@ def mesh_from_OrderedDict(
)
np.seterr(**initial_settings)
first_interior_line = break_line_(
first_interior_line, second_interior_line
)
first_interior_line, second_interior_line,
snap_tol = meshtracker.atol)
first_shape_interiors.append(first_interior_line)
if first_shape.geom_type in ["Polygon", "MultiPolygon"]:
broken_shapes.append(Polygon(first_exterior_line, holes=first_shape_interiors))
Expand All @@ -318,7 +319,7 @@ def mesh_from_OrderedDict(
)

# Add lines, reusing line segments
meshtracker = MeshTracker(model=model)

for line_name, line in lines_broken_dict.items():
meshtracker.add_get_xy_line(line, line_name)

Expand Down