|
24 | 24 | StructureStructureInterface, |
25 | 25 | ) |
26 | 26 | from tidy3d.components.geometry.base import Box |
| 27 | +from tidy3d.components.geometry.primitives import Cylinder |
| 28 | +from tidy3d.components.geometry.utils import traverse_geometries |
27 | 29 | from tidy3d.components.material.tcad.charge import ( |
28 | 30 | ChargeConductorMedium, |
29 | 31 | SemiconductorMedium, |
|
127 | 129 | # define some limits for transient heat simulations |
128 | 130 | TRANSIENT_HEAT_MAX_STEPS = 1000 |
129 | 131 |
|
| 132 | +# Minimum radius for gmsh meshing (OpenCASCADE tolerance) |
| 133 | +MIN_GMSH_RADIUS = 1e-6 |
| 134 | + |
130 | 135 |
|
131 | 136 | class TCADAnalysisTypes(str, Enum): |
132 | 137 | """Enumeration of the types of simulations currently supported""" |
@@ -363,6 +368,42 @@ def check_unsupported_geometries(cls, val): |
363 | 368 | ) |
364 | 369 | return val |
365 | 370 |
|
| 371 | + @pd.validator("structures", always=True) |
| 372 | + def _warn_small_cylinder_radius(cls, val): |
| 373 | + """Warn if any Cylinder geometry has radius too small for meshing.""" |
| 374 | + for structure in val: |
| 375 | + for geometry in traverse_geometries(structure.geometry): |
| 376 | + if isinstance(geometry, Cylinder): |
| 377 | + r_bottom = geometry.radius_bottom |
| 378 | + r_top = geometry.radius_top |
| 379 | + is_tapered = r_bottom != r_top |
| 380 | + |
| 381 | + # Compute minimum allowed radius (matches backend heat_mesh.py logic) |
| 382 | + min_radius = max(MIN_GMSH_RADIUS, 0.01 * max(abs(r_bottom), abs(r_top))) |
| 383 | + |
| 384 | + # Warn if radii are below minimum |
| 385 | + if is_tapered: |
| 386 | + if r_bottom < min_radius: |
| 387 | + log.warning( |
| 388 | + f"Cylinder 'radius_bottom' ({r_bottom:.3e}) is below the minimum " |
| 389 | + f"radius for meshing ({min_radius:.3e}). The sidewall angle may be " |
| 390 | + f"too steep. During meshing, this will be clamped to {min_radius:.3e}." |
| 391 | + ) |
| 392 | + if r_top < min_radius: |
| 393 | + log.warning( |
| 394 | + f"Cylinder 'radius_top' ({r_top:.3e}) is below the minimum " |
| 395 | + f"radius for meshing ({min_radius:.3e}). The sidewall angle may be " |
| 396 | + f"too steep. During meshing, this will be clamped to {min_radius:.3e}." |
| 397 | + ) |
| 398 | + else: |
| 399 | + if r_bottom < min_radius: |
| 400 | + log.warning( |
| 401 | + f"Cylinder 'radius' ({r_bottom:.3e}) is below the minimum " |
| 402 | + f"radius for meshing ({min_radius:.3e}). " |
| 403 | + f"During meshing, this will be clamped to {min_radius:.3e}." |
| 404 | + ) |
| 405 | + return val |
| 406 | + |
366 | 407 | @staticmethod |
367 | 408 | def _check_cross_solids(objs: tuple[Box, ...], values: dict) -> tuple[int, ...]: |
368 | 409 | """Given model dictionary ``values``, check whether objects in list ``objs`` cross |
|
0 commit comments