Skip to content

Commit

Permalink
set Courant factor using analytic expression involving bfast_k_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Nov 25, 2023
1 parent ee61528 commit 685d9bd
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions python/tests/test_refl_angular.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def setUpClass(cls):
cls.n1 = 1.4 # refractive index of medium 1
cls.n2 = 3.5 # refractive index of medium 2

cls.dpml = 1.0
cls.dz = 7.0
cls.size_z = cls.dz + 2 * cls.dpml
cls.t_pml = 1.0
cls.length_z = 7.0
cls.size_z = cls.length_z + 2 * cls.t_pml

cls.wavelength_min = 0.4
cls.wavelength_max = 0.8
Expand Down Expand Up @@ -49,16 +49,14 @@ def reflectance_angular(
if need_bfast:
bfast_k_bar = (self.n1 * np.sin(theta_rad), 0, 0)

k = mp.Vector3()

if theta_deg > 40.0:
Courant = 0.05
else:
Courant = 0.1
Courant = (1 - bfast_k_bar[0]) / 3**0.5

k = mp.Vector3()
else:
bfast_k_bar = (0, 0, 0)

Courant = 0.5

# Wavevector in source medium with refractive index n1.
# Plane of incidence is XZ. Rotation is counter clockwise about
# Y axis. A rotation angle of zero is the +Z axis.
Expand All @@ -68,11 +66,9 @@ def reflectance_angular(
.scale(self.n1 * self.frequency_min)
)

Courant = 0.5

dimensions = 1 if theta_deg == 0 else 3
cell_size = mp.Vector3(z=self.size_z)
pml_layers = [mp.PML(self.dpml)]
pml_layers = [mp.PML(self.t_pml)]

# P polarization.
source_component = mp.Ex
Expand All @@ -81,7 +77,7 @@ def reflectance_angular(
mp.Source(
mp.GaussianSource(self.frequency_center, fwidth=self.frequency_width),
component=source_component,
center=mp.Vector3(z=-0.5 * self.size_z + self.dpml),
center=mp.Vector3(z=-0.5 * self.size_z + self.t_pml),
)
]

Expand All @@ -98,7 +94,7 @@ def reflectance_angular(
Courant=Courant,
)

monitor_point = -0.5 * self.size_z + self.dpml + 0.25 * self.dz
monitor_point = -0.5 * self.size_z + self.t_pml + 0.25 * self.length_z
monitor_region = mp.FluxRegion(center=mp.Vector3(z=monitor_point))
flux_monitor = sim.add_flux(
self.frequency_center, self.frequency_width, self.num_freq, monitor_region
Expand Down Expand Up @@ -159,9 +155,7 @@ def reflectance_angular(

return freqs, theta_in_rad, reflectance

@parameterized.parameterized.expand(
[(0, False), (20.6, False), (0, True), (35.7, True)]
)
@parameterized.parameterized.expand([(0, False), (20.6, False), (35.7, True)])
def test_reflectance_angular(self, theta_deg: float, need_bfast: bool):
(
frequency_meep,
Expand Down Expand Up @@ -212,7 +206,7 @@ def test_reflectance_angular(self, theta_deg: float, need_bfast: bool):
)
)

tol = 0.02
tol = 0.03
self.assertClose(reflectance_meep, reflectance_analytic, epsilon=tol)


Expand Down

0 comments on commit 685d9bd

Please sign in to comment.