Skip to content

feat: warning about excessive refinement from gap meshing (FXC-3919)#3206

Open
dbochkov-flexcompute wants to merge 1 commit intodevelopfrom
daniil/FXC-3919-Warnings-if-excessively-small-grid-is-created-from-gap-refinement
Open

feat: warning about excessive refinement from gap meshing (FXC-3919)#3206
dbochkov-flexcompute wants to merge 1 commit intodevelopfrom
daniil/FXC-3919-Warnings-if-excessively-small-grid-is-created-from-gap-refinement

Conversation

@dbochkov-flexcompute
Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute commented Jan 27, 2026

Warn if automatically calculated dl from gap meshing is less than 0.1 x (current min mesh size). Threshold (0.1) is somewhat random, we could adjust if needed


Note

Adds a warning during auto grid generation to flag potentially excessive refinement from gap meshing.

  • Introduces warning when LayerRefinementSpec.dl_min_from_gaps is < 0.1 × the smallest lateral grid size
  • Extracts magic number 0.45 to DL_MIN_FROM_GAPS_FRACTION and adds GAP_REFINEMENT_WARNING_THRESH
  • Replaces inline 0.45 * min_gap_width with DL_MIN_FROM_GAPS_FRACTION * min_gap_width
  • Adds tests covering: very small gap (warning), larger gap (no warning), and dl_min_from_gap_width=False (no warning)
  • Updates CHANGELOG.md under Unreleased

Written by Cursor Bugbot for commit 9786431. This will update automatically on new commits. Configure here.

Greptile Overview

Greptile Summary

This PR adds a warning to alert users when gap meshing creates excessively fine mesh refinement. It introduces two new constants (DL_MIN_FROM_GAPS_FRACTION and GAP_REFINEMENT_WARNING_THRESH) and refactors existing code to use the named constant instead of a magic number.

Key changes:

  • Extracts hardcoded value 0.45 into DL_MIN_FROM_GAPS_FRACTION constant
  • Adds warning logic that triggers when calculated dl_min_from_gaps is less than 10% of the smallest lateral grid size
  • Includes comprehensive test coverage with three scenarios: small gap (warning triggered), large gap (no warning), and disabled feature (no warning)

Minor issue:

  • Missing CHANGELOG.md entry (required by custom instruction a109c62a-aa8c-4cc4-b515-0ad947c47929)

Confidence Score: 4/5

  • This PR is safe to merge with minor style improvements recommended
  • The implementation adds a helpful warning for users and includes thorough test coverage. The logic is sound and uses appropriate threshold values. The only issues are a missing CHANGELOG entry and a minor formatting inconsistency in the warning message (backticks vs single quotes). No functional bugs or security issues were detected.
  • No files require special attention - the changes are straightforward and well-tested

Important Files Changed

Filename Overview
tidy3d/components/grid/grid_spec.py Added warning logic for excessive gap refinement with new constants; replaced magic number with named constant
tests/test_components/test_layerrefinement.py Added comprehensive test for gap meshing warning with three test cases (small gap, large gap, disabled feature)

Sequence Diagram

sequenceDiagram
    participant User
    participant GridSpec
    participant LayerRefinementSpec
    participant Logger

    User->>GridSpec: Create simulation with gap meshing enabled
    GridSpec->>GridSpec: _make_grid_multiple_iterations()
    
    loop For each gap meshing iteration
        GridSpec->>LayerRefinementSpec: _resolve_gaps(old_grid, merged_geos)
        LayerRefinementSpec-->>GridSpec: (snapping_lines, gap_width)
        
        alt dl_min_from_gap_width enabled
            GridSpec->>GridSpec: Update min_gap_width
            
            alt gap_width < inf
                GridSpec->>GridSpec: Calculate lateral_grid_sizes
                GridSpec->>GridSpec: Find min_lateral_grid_size
                GridSpec->>GridSpec: Calculate dl_min_from_gaps = 0.45 * gap_width
                
                alt dl_min_from_gaps < 0.1 * min_lateral_grid_size
                    GridSpec->>Logger: log.warning("detected a very small gap width...")
                    Logger-->>User: Display warning about excessive refinement
                end
            end
        end
        
        GridSpec->>GridSpec: _make_grid_one_iteration() with dl_min_from_gaps
    end
    
    GridSpec-->>User: Return final grid with refined gaps
Loading

Context used:

  • Rule from dashboard - Update the CHANGELOG.md file when making changes that affect user-facing functionality or fix bugs. (source)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@dbochkov-flexcompute dbochkov-flexcompute force-pushed the daniil/FXC-3919-Warnings-if-excessively-small-grid-is-created-from-gap-refinement branch from ca91176 to 9786431 Compare January 27, 2026 01:56
@github-actions
Copy link
Contributor

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/components/grid/grid_spec.py (100%)

Summary

  • Total: 11 lines
  • Missing: 0 lines
  • Coverage: 100%

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.

1 participant