Skip to content

Gap automeshing #2390

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

Open
wants to merge 4 commits into
base: daniil/min_size_autodetect
Choose a base branch
from

Conversation

dbochkov-flexcompute
Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute commented Apr 17, 2025

Integrated gap meshing in an iterative way. Now LayerRefinementSpec has two additional parameters:

  • gap_meshing_iters: NonNegativeInt = 1 to set the number of iteration to perform for attempting resolving all gaps
  • dl_min_from_gap_width: bool = True whether or not to reduce dl_min reduce to the minimal detected gap width.

A few of points to discuss:

  • Doing just one iterations seems to be performing quite well, so that could be a good default. But maybe we should switch to a higher number and just let it iterate until no multiple crossings are detected in a single cell?
  • Currently it does not distinguish between thin gaps and thin strips. Do we want to control mesher behavior for the two types
  • while we use snapping planes for achieving the desired result, we currently do not store them, and, as a consequence, we cannot plot them. Should we worry about that?

examples of meshing thin strips and gaps:
Screenshot_20250417_231504
Screenshot_20250417_231652

@dbochkov-flexcompute
Copy link
Contributor Author

one more point:

  • currently we also take into account all structures. Should we worry about making it work for a selected set of structures in this PR?

@weiliangjin2021
Copy link
Collaborator

Thanks for this great feature!

Doing just one iterations seems to be performing quite well, so that could be a good default. But maybe we should switch to a higher number and just let it iterate until no multiple crossings are detected in a single cell?

Agree that we can set 1 as default if ti works quite well already. Then we can add an option like inf or a string to indicate it will iterate until no crossings are detected?

Currently it does not distinguish between thin gaps and thin strips. Do we want to control mesher behavior for the two types

Right now, we don't have good conformal scheme for thin strips, so probably no need right now.

while we use snapping planes for achieving the desired result, we currently do not store them, and, as a consequence, we cannot plot them. Should we worry about that?

Not too concerned, but I wonder that it's not hard to store them?

currently we also take into account all structures. Should we worry about making it work for a selected set of structures in this PR?

My understanding is that metallic structures are more of a concern. So we probably only need to distinguish between metallic (PEC, lossyMetal) and dielectric.

Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 left a comment

Choose a reason for hiding this comment

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

Half way through the code. Looks quite nice, although taking quite a bit efforts in understanding the logic. Some high-level description in each function will be very helpful. Some minor comments so far:

"The underlying algorithm detects gaps contained in a single cell and places a snapping plane at the gaps's centers.",
)

dl_min_from_gap_width: bool = pd.Field(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we have dl_min from quite a few places: gap refinement, corner refinement, thickness refinement, and minimal feature, shall we allow controling them individually and combine them into a new class?

cells_ij = []
cells_dy = []
h_inds = np.argmax(x[:, None] > vertices[None, :, 0], axis=0)
h_inds[vertices[:, 0] > x[-1]] = len(x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

More informative variable name for h_inds

cells_dy = []
h_inds = np.argmax(x[:, None] > vertices[None, :, 0], axis=0)
h_inds[vertices[:, 0] > x[-1]] = len(x)
for ind_beg, ind_end, v_beg, v_end in zip(
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a comment that beg and end refers to the two vertices on the edge of the polygon

if ind_beg > ind_end:
ind_beg, ind_end, v_beg, v_end = ind_end, ind_beg, v_end, v_beg

if ind_end > ind_beg:
Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 Apr 22, 2025

Choose a reason for hiding this comment

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

clearer with if ind_end == ind_beg: continue, and undent the rest? This brings up the question on how the close-to-vertical polygon edge is handled. I guess they are handled when looking at horizontal intersection?

"""Detect intersection points of single polygon and grid lines."""
v_cells_ij, v_cells_dy = self._find_vertical_intersections(x, y, vertices)
# reuse the same command but flip dimensions
h_cells_ij, h_cells_dx = self._find_vertical_intersections(y, x, vertices[:, [1, 0]])
Copy link
Collaborator

Choose a reason for hiding this comment

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

use np.flip?

# reuse the same command but flip dimensions
h_cells_ij, h_cells_dx = self._find_vertical_intersections(y, x, vertices[:, [1, 0]])
if len(h_cells_ij) > 0:
h_cells_ij = np.roll(h_cells_ij, axis=1, shift=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

more explanation here?

min_gap_width = min(min_gap_width, gap_width)

if len(new_snapping_lines) == 0:
log.info("Grid is no longer changing. Stopping recursive refinement.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

include the information on the number of iteration where it stops.

@dbochkov-flexcompute
Copy link
Contributor Author

sprinkled around some more comments in the code, had to recall myself what I was doing 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants