def test_source_frequency(self): g_src = GaussianSource(10) c_src = ContinuousSource(10) self.assertEqual(10, g_src.frequency) self.assertEqual(10, c_src.frequency) with self.assertRaises(ValueError): GaussianSource() with self.assertRaises(ValueError): ContinuousSource()
def radiating_base(self, sq_ratio, solve_cw=True): w = 0.30 s = mp.structure(self.gv, one, mp.pml(self.ymax / 3.0)) f = mp.fields(s) src = ContinuousSource(w) f.add_point_source(mp.Ez, src, self.pnt_src_vec) # let the source reach steady state if solve_cw: f.solve_cw(1e-6) else: while f.time() < 400: f.step() # amp1 and amp2 are of type complex amp1 = f.get_field(mp.Ez, self.p1) amp2 = f.get_field(mp.Ez, self.p2) ratio = abs(amp1) / abs(amp2) if self.gv.dim == mp.D2: ratio = ratio**2 # in 2d, decay is ~1/sqrt(r), so square to get 1/r print("Ratio is {} from ({} {}) and ({} {})".format( ratio, amp1.real, amp1, amp2.real, amp2)) fail_fmt = "Failed: amp1 = ({}, {}), amp2 = ({}, {})\nabs(amp1/amp2){} = {}, too far from 2.0" fail_msg = fail_fmt.format(amp1.real, amp1, amp2.real, amp2, "^2" if sq_ratio else "", ratio) self.assertTrue(ratio <= 2.12 and ratio >= 1.88, fail_msg)
def test_eig_lattice_defaults(self): src = ContinuousSource(5.0) center = Vector3() default_lattice = EigenModeSource(src, center) self.assertEqual(default_lattice.eig_lattice_size, Vector3()) self.assertEqual(default_lattice.eig_lattice_center, Vector3()) elc = Vector3(1, 1, 1) els = Vector3(1, 1, 1) custom_lattice = EigenModeSource(src, center, eig_lattice_center=elc, eig_lattice_size=els) self.assertEqual(custom_lattice.eig_lattice_size, els) self.assertEqual(custom_lattice.eig_lattice_center, elc)
def test_source_wavelength(self): g_src = GaussianSource(wavelength=10) c_src = ContinuousSource(wavelength=10) self.assertAlmostEqual(1. / 10., g_src.frequency) self.assertAlmostEqual(1. / 10., c_src.frequency)