|
1 | 1 | """Test near field to far field transformations."""
|
2 | 2 |
|
3 | 3 | import numpy as np
|
| 4 | +import pydantic.v1 as pydantic |
4 | 5 | import pytest
|
5 | 6 | import tidy3d as td
|
6 | 7 | from tidy3d.components.field_projection import FieldProjector
|
@@ -597,6 +598,50 @@ def test_2d_proj_clientside():
|
597 | 598 | make_2d_proj(plane)
|
598 | 599 |
|
599 | 600 |
|
| 601 | +def test_2d_sim_with_proj_monitors_near(): |
| 602 | + """Creates near-field projection monitors by modifying proj_distance and far_field_approx.""" |
| 603 | + center = [0, 0, 0] |
| 604 | + freqs = 1e13 |
| 605 | + monitor_size = (0, 2, td.inf) |
| 606 | + plane = "xy" |
| 607 | + f0 = 1e13 |
| 608 | + sim_size = (5, 5, 0) |
| 609 | + # boundary conditions |
| 610 | + boundary_conds = td.BoundarySpec( |
| 611 | + x=td.Boundary.pml(), |
| 612 | + y=td.Boundary.pml(), |
| 613 | + z=td.Boundary.periodic(), |
| 614 | + ) |
| 615 | + |
| 616 | + monitors = make_2d_proj_monitors(center, monitor_size, freqs, plane) |
| 617 | + |
| 618 | + # Modify only proj_distance and far_field_approx |
| 619 | + proj_monitors_near = [ |
| 620 | + monitor.__class__( |
| 621 | + proj_distance=R_FAR / 50, # Adjust projection distance |
| 622 | + far_field_approx=False, # Disable far-field approximation |
| 623 | + **{ |
| 624 | + k: v |
| 625 | + for k, v in monitor.__dict__.items() |
| 626 | + if k not in ["proj_distance", "far_field_approx"] |
| 627 | + }, |
| 628 | + ) |
| 629 | + for monitor in monitors |
| 630 | + ] |
| 631 | + |
| 632 | + with pytest.raises( |
| 633 | + pydantic.ValidationError, |
| 634 | + match="Exact far-field projection for 2D simulations is not yet available", |
| 635 | + ): |
| 636 | + _ = td.Simulation( |
| 637 | + size=sim_size, |
| 638 | + grid_spec=td.GridSpec.auto(wavelength=td.C_0 / f0), |
| 639 | + boundary_spec=boundary_conds, |
| 640 | + monitors=proj_monitors_near, |
| 641 | + run_time=1e-12, |
| 642 | + ) |
| 643 | + |
| 644 | + |
600 | 645 | @pytest.mark.parametrize(
|
601 | 646 | "array, pts, axes, expected",
|
602 | 647 | [
|
|
0 commit comments