Skip to content

Commit

Permalink
Added a validator to enable FieldProjectionCartesianMonitor for 2D si…
Browse files Browse the repository at this point in the history
…mulations
  • Loading branch information
QimingFlex committed Aug 1, 2024
1 parent 46bd3ef commit 4dcfaf7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ def propagation_factor(dist: Union[float, None], k: complex, is_2d_simulation: b
return 1.0

if is_2d_simulation:
return -np.exp(1j * k * dist) * np.sqrt(1j * k / (8 * np.pi * dist))
return np.exp(1j * k * dist) * np.sqrt(-1j * k / (8 * np.pi * dist))

return -1j * k * np.exp(1j * k * dist) / (4 * np.pi * dist)

Expand Down
65 changes: 56 additions & 9 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2716,20 +2716,67 @@ def _projection_monitors_2d(cls, val, values):
f"Monitor '{monitor.name}' is not supported in 1D simulations."
)

if isinstance(
monitor, (FieldProjectionCartesianMonitor, FieldProjectionKSpaceMonitor)
):
if isinstance(monitor, (FieldProjectionKSpaceMonitor)):
raise SetupError(
f"Monitor '{monitor.name}' in 2D simulations is coming soon. "
"Please use 'FieldProjectionAngleMonitor' instead."
"Please use 'FieldProjectionAngleMonitor' or 'FieldProjectionCartesianMonitor' instead."
)

if not monitor.far_field_approx:
raise SetupError(
"Exact far field projection in 2D simulations is coming soon."
"Please set 'far_field_approx = True'."
)

if isinstance(monitor, FieldProjectionCartesianMonitor):
if plane == "y-z":
if monitor.proj_axis == 0:
raise SetupError(
"For a 2D simulation in the y-z plane, the 'proj_axis' of "
f"monitor '{monitor.name}' should be set to '1' or '2'."
)
elif monitor.proj_axis in (1, 2) and (
len(monitor.x) != 1 or monitor.x[0] != 0
):
raise SetupError(
"For a 2D simulation in the y-z plane with "
f"'proj_axis = {monitor.proj_axis}', 'x' of monitor "
f"'{monitor.name}' should be set to 0."
)
elif plane == "x-z":
if monitor.proj_axis == 1:
raise SetupError(
"For a 2D simulation in the x-z plane, the 'proj_axis' of "
f"monitor '{monitor.name}' should be set to '0' or '2'."
)
elif monitor.proj_axis == 0 and (len(monitor.x) != 1 or monitor.x[0] != 0):
raise SetupError(
"For a 2D simulation in the x-z plane with "
f"'proj_axis = {monitor.proj_axis}', 'x' of monitor "
f"'{monitor.name}' should be set to 0."
)
elif monitor.proj_axis == 2 and (len(monitor.y) != 1 or monitor.y[0] != 0):
raise SetupError(
"For a 2D simulation in the x-z plane with "
f"'proj_axis = {monitor.proj_axis}', 'y' of monitor "
f"'{monitor.name}' should be set to 0."
)
elif plane == "x-y":
if monitor.proj_axis == 2:
raise SetupError(
"For a 2D simulation in the x-y plane, the 'proj_axis' of "
f"monitor '{monitor.name}' should be set to '0' or '1'."
)
elif monitor.proj_axis in (0, 1) and (
len(monitor.y) != 1 or monitor.y[0] != 0
):
raise SetupError(
"For a 2D simulation in the x-y plane with "
f"'proj_axis = {monitor.proj_axis}', 'y' of monitor "
f"'{monitor.name}' should be set to 0."
)

if isinstance(monitor, FieldProjectionAngleMonitor):
if not monitor.far_field_approx:
raise SetupError(
"Exact far field projection in 2D simulations is coming soon."
"Please set 'far_field_approx = True'."
)
if plane == "y-z" and (len(monitor.phi) != 1 or monitor.phi[0] != phi_value):
raise SetupError(
"For a 2D simulation in the y-z plane, the observation angle 'phi' "
Expand Down

0 comments on commit 4dcfaf7

Please sign in to comment.