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

Consolidate some warning messages #2017

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2540,19 +2540,20 @@ def _validate_2d_geometry_has_2d_medium(cls, val, values):
if val is None:
return val

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

return val

Expand Down
21 changes: 11 additions & 10 deletions tidy3d/components/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,18 @@ def objects_in_sim_bounds(cls, val, values):
# Do a strict check, unless simulation is 0D along a dimension
strict_ineq = [size != 0 and strict_inequality for size in sim_size]

for position_index, geometric_object in enumerate(val):
if not sim_box.intersects(geometric_object.geometry, strict_inequality=strict_ineq):
message = (
f"'simulation.{field_name}[{position_index}]' "
"is outside of the simulation domain."
)
custom_loc = [field_name, position_index]
with log as consolidated_logger:
for position_index, geometric_object in enumerate(val):
if not sim_box.intersects(geometric_object.geometry, strict_inequality=strict_ineq):
message = (
f"'simulation.{field_name}[{position_index}]' "
"is outside of the simulation domain."
)
custom_loc = [field_name, position_index]

if error:
raise SetupError(message)
log.warning(message, custom_loc=custom_loc)
if error:
raise SetupError(message)
consolidated_logger.warning(message, custom_loc=custom_loc)

return val

Expand Down
Loading