Skip to content

Commit f0e563c

Browse files
committed
Consolidate some warning messages
1 parent ac60dfe commit f0e563c

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

tidy3d/components/simulation.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,19 +2540,20 @@ def _validate_2d_geometry_has_2d_medium(cls, val, values):
25402540
if val is None:
25412541
return val
25422542

2543-
for i, structure in enumerate(val):
2544-
if isinstance(structure.medium, Medium2D):
2545-
continue
2546-
for geom in flatten_groups(structure.geometry):
2547-
zero_dims = geom.zero_dims
2548-
if len(zero_dims) > 0:
2549-
log.warning(
2550-
f"Structure at 'structures[{i}]' has geometry with zero size along "
2551-
f"dimensions {zero_dims}, and with a medium that is not a 'Medium2D'. "
2552-
"This is probably not correct, since the resulting simulation will "
2553-
"depend on the details of the numerical grid. Consider either "
2554-
"giving the geometry a nonzero thickness or using a 'Medium2D'."
2555-
)
2543+
with log as consolidated_logger:
2544+
for i, structure in enumerate(val):
2545+
if isinstance(structure.medium, Medium2D):
2546+
continue
2547+
for geom in flatten_groups(structure.geometry):
2548+
zero_dims = geom.zero_dims
2549+
if len(zero_dims) > 0:
2550+
consolidated_logger.warning(
2551+
f"Structure at 'structures[{i}]' has geometry with zero size along "
2552+
f"dimensions {zero_dims}, and with a medium that is not a 'Medium2D'. "
2553+
"This is probably not correct, since the resulting simulation will "
2554+
"depend on the details of the numerical grid. Consider either "
2555+
"giving the geometry a nonzero thickness or using a 'Medium2D'."
2556+
)
25562557

25572558
return val
25582559

tidy3d/components/validators.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,18 @@ def objects_in_sim_bounds(cls, val, values):
177177
# Do a strict check, unless simulation is 0D along a dimension
178178
strict_ineq = [size != 0 and strict_inequality for size in sim_size]
179179

180-
for position_index, geometric_object in enumerate(val):
181-
if not sim_box.intersects(geometric_object.geometry, strict_inequality=strict_ineq):
182-
message = (
183-
f"'simulation.{field_name}[{position_index}]' "
184-
"is outside of the simulation domain."
185-
)
186-
custom_loc = [field_name, position_index]
180+
with log as consolidated_logger:
181+
for position_index, geometric_object in enumerate(val):
182+
if not sim_box.intersects(geometric_object.geometry, strict_inequality=strict_ineq):
183+
message = (
184+
f"'simulation.{field_name}[{position_index}]' "
185+
"is outside of the simulation domain."
186+
)
187+
custom_loc = [field_name, position_index]
187188

188-
if error:
189-
raise SetupError(message)
190-
log.warning(message, custom_loc=custom_loc)
189+
if error:
190+
raise SetupError(message)
191+
consolidated_logger.warning(message, custom_loc=custom_loc)
191192

192193
return val
193194

0 commit comments

Comments
 (0)