@@ -1561,61 +1561,58 @@ def test_mode_solver_pec_boundary_truncation():
15611561 # Get the mode solver data
15621562 data = ms .data
15631563
1564- # Get simulation grid boundaries
1564+ # Get simulation boundaries
15651565 sim_bounds = simulation .bounds
15661566 sim_x_min , sim_x_max = sim_bounds [0 ][0 ], sim_bounds [1 ][0 ]
15671567 sim_z_min , sim_z_max = sim_bounds [0 ][2 ], sim_bounds [1 ][2 ]
15681568
1569- # Get solver grid boundaries (may extend beyond simulation)
1570- solver_grid = ms ._solver_grid
1571- solver_x = solver_grid .boundaries .x
1572- solver_z = solver_grid .boundaries .z
1573-
1574- # Check if the solver grid extends beyond simulation bounds
1575- grid_extends_x_min = solver_x [0 ] < sim_x_min - fp_eps
1576- grid_extends_x_max = solver_x [- 1 ] > sim_x_max + fp_eps
1577- grid_extends_z_min = solver_z [0 ] < sim_z_min - fp_eps
1578- grid_extends_z_max = solver_z [- 1 ] > sim_z_max + fp_eps
1579-
15801569 # Test 1: Fields outside simulation boundaries should be exactly 0 (zero-padded)
15811570 for field_name in ("Ex" , "Ey" , "Ez" , "Hx" , "Hy" , "Hz" ):
15821571 field = data .field_components [field_name ]
15831572 field_coords_x = field .coords ["x" ].values
15841573 field_coords_z = field .coords ["z" ].values
15851574
15861575 # Check fields at x positions outside simulation
1587- if grid_extends_x_min :
1588- x_outside_min = field_coords_x [field_coords_x < sim_x_min - fp_eps ]
1589- if len (x_outside_min ) > 0 :
1590- field_outside = field .sel (x = x_outside_min )
1591- assert np .all (field_outside .values == 0.0 ), (
1592- f"{ field_name } should be exactly 0 outside x_min boundary, got { np .max (np .abs (field_outside .values ))} "
1593- )
1594-
1595- if grid_extends_x_max :
1596- x_outside_max = field_coords_x [field_coords_x > sim_x_max + fp_eps ]
1597- if len (x_outside_max ) > 0 :
1598- field_outside = field .sel (x = x_outside_max )
1599- assert np .all (field_outside .values == 0.0 ), (
1600- f"{ field_name } should be exactly 0 outside x_max boundary, got { np .max (np .abs (field_outside .values ))} "
1601- )
1576+ x_outside_min = field_coords_x [
1577+ (field_coords_x < sim_x_min )
1578+ & ~ np .isclose (field_coords_x , sim_x_min , rtol = fp_eps , atol = fp_eps )
1579+ ]
1580+ if len (x_outside_min ) > 0 :
1581+ field_outside = field .sel (x = x_outside_min )
1582+ assert np .all (field_outside .values == 0.0 ), (
1583+ f"{ field_name } should be exactly 0 outside x_min boundary, got { np .max (np .abs (field_outside .values ))} "
1584+ )
1585+
1586+ x_outside_max = field_coords_x [
1587+ (field_coords_x > sim_x_max )
1588+ & ~ np .isclose (field_coords_x , sim_x_max , rtol = fp_eps , atol = fp_eps )
1589+ ]
1590+ if len (x_outside_max ) > 0 :
1591+ field_outside = field .sel (x = x_outside_max )
1592+ assert np .all (field_outside .values == 0.0 ), (
1593+ f"{ field_name } should be exactly 0 outside x_max boundary, got { np .max (np .abs (field_outside .values ))} "
1594+ )
16021595
16031596 # Check fields at z positions outside simulation
1604- if grid_extends_z_min :
1605- z_outside_min = field_coords_z [field_coords_z < sim_z_min - fp_eps ]
1606- if len (z_outside_min ) > 0 :
1607- field_outside = field .sel (z = z_outside_min )
1608- assert np .all (field_outside .values == 0.0 ), (
1609- f"{ field_name } should be exactly 0 outside z_min boundary, got { np .max (np .abs (field_outside .values ))} "
1610- )
1611-
1612- if grid_extends_z_max :
1613- z_outside_max = field_coords_z [field_coords_z > sim_z_max + fp_eps ]
1614- if len (z_outside_max ) > 0 :
1615- field_outside = field .sel (z = z_outside_max )
1616- assert np .all (field_outside .values == 0.0 ), (
1617- f"{ field_name } should be exactly 0 outside z_max boundary, got { np .max (np .abs (field_outside .values ))} "
1618- )
1597+ z_outside_min = field_coords_z [
1598+ (field_coords_z < sim_z_min )
1599+ & ~ np .isclose (field_coords_z , sim_z_min , rtol = fp_eps , atol = fp_eps )
1600+ ]
1601+ if len (z_outside_min ) > 0 :
1602+ field_outside = field .sel (z = z_outside_min )
1603+ assert np .all (field_outside .values == 0.0 ), (
1604+ f"{ field_name } should be exactly 0 outside z_min boundary, got { np .max (np .abs (field_outside .values ))} "
1605+ )
1606+
1607+ z_outside_max = field_coords_z [
1608+ (field_coords_z > sim_z_max )
1609+ & ~ np .isclose (field_coords_z , sim_z_max , rtol = fp_eps , atol = fp_eps )
1610+ ]
1611+ if len (z_outside_max ) > 0 :
1612+ field_outside = field .sel (z = z_outside_max )
1613+ assert np .all (field_outside .values == 0.0 ), (
1614+ f"{ field_name } should be exactly 0 outside z_max boundary, got { np .max (np .abs (field_outside .values ))} "
1615+ )
16191616
16201617 # Test 2: Tangential E-fields at PEC boundaries should be exactly 0
16211618 # At x boundaries: Ey and Ez are tangential
@@ -1626,8 +1623,8 @@ def test_mode_solver_pec_boundary_truncation():
16261623 field = data .field_components [field_name ]
16271624 field_coords_x = field .coords ["x" ].values
16281625 # Find coordinates exactly at boundaries
1629- x_at_min = field_coords_x [np .isclose (field_coords_x , sim_x_min , atol = fp_eps )]
1630- x_at_max = field_coords_x [np .isclose (field_coords_x , sim_x_max , atol = fp_eps )]
1626+ x_at_min = field_coords_x [np .isclose (field_coords_x , sim_x_min , rtol = fp_eps , atol = fp_eps )]
1627+ x_at_max = field_coords_x [np .isclose (field_coords_x , sim_x_max , rtol = fp_eps , atol = fp_eps )]
16311628
16321629 if len (x_at_min ) > 0 :
16331630 field_at_boundary = field .sel (x = x_at_min [0 ])
@@ -1645,8 +1642,8 @@ def test_mode_solver_pec_boundary_truncation():
16451642 field = data .field_components [field_name ]
16461643 field_coords_z = field .coords ["z" ].values
16471644 # Find coordinates exactly at boundaries
1648- z_at_min = field_coords_z [np .isclose (field_coords_z , sim_z_min , atol = fp_eps )]
1649- z_at_max = field_coords_z [np .isclose (field_coords_z , sim_z_max , atol = fp_eps )]
1645+ z_at_min = field_coords_z [np .isclose (field_coords_z , sim_z_min , rtol = fp_eps , atol = fp_eps )]
1646+ z_at_max = field_coords_z [np .isclose (field_coords_z , sim_z_max , rtol = fp_eps , atol = fp_eps )]
16501647
16511648 if len (z_at_min ) > 0 :
16521649 field_at_boundary = field .sel (z = z_at_min [0 ])
@@ -1665,8 +1662,8 @@ def test_mode_solver_pec_boundary_truncation():
16651662 # At z boundaries: Hz is normal
16661663 field = data .field_components ["Hx" ]
16671664 field_coords_x = field .coords ["x" ].values
1668- x_at_min = field_coords_x [np .isclose (field_coords_x , sim_x_min , atol = fp_eps )]
1669- x_at_max = field_coords_x [np .isclose (field_coords_x , sim_x_max , atol = fp_eps )]
1665+ x_at_min = field_coords_x [np .isclose (field_coords_x , sim_x_min , rtol = fp_eps , atol = fp_eps )]
1666+ x_at_max = field_coords_x [np .isclose (field_coords_x , sim_x_max , rtol = fp_eps , atol = fp_eps )]
16701667
16711668 if len (x_at_min ) > 0 :
16721669 field_at_boundary = field .sel (x = x_at_min [0 ])
@@ -1682,8 +1679,8 @@ def test_mode_solver_pec_boundary_truncation():
16821679
16831680 field = data .field_components ["Hz" ]
16841681 field_coords_z = field .coords ["z" ].values
1685- z_at_min = field_coords_z [np .isclose (field_coords_z , sim_z_min , atol = fp_eps )]
1686- z_at_max = field_coords_z [np .isclose (field_coords_z , sim_z_max , atol = fp_eps )]
1682+ z_at_min = field_coords_z [np .isclose (field_coords_z , sim_z_min , rtol = fp_eps , atol = fp_eps )]
1683+ z_at_max = field_coords_z [np .isclose (field_coords_z , sim_z_max , rtol = fp_eps , atol = fp_eps )]
16871684
16881685 if len (z_at_min ) > 0 :
16891686 field_at_boundary = field .sel (z = z_at_min [0 ])
0 commit comments