def test_hABY(self): params = self.params.copy() wg = pymwm.create(params) wr = 3.0 * np.pi wi = -0.002 w = wr + wi * 1j hs1 = np.array([wg.beta(w, alpha) for alpha in wg.alpha_all]) As1, Bs1 = wg.coefs_numpy(hs1, w) Y1 = wg.Ys(w, hs1, As1, Bs1) hs2, As2, Bs2, Y2 = wg.hABY(w) self.assertTrue(np.allclose(As1, As2)) self.assertTrue(np.allclose(Bs1, Bs2)) self.assertTrue(np.allclose(Y1, Y2)) params['clad'] = {'model': 'pec'} wg = pymwm.create(params) hs1 = np.array([wg.beta(w, alpha) for alpha in wg.alpha_all]) As1, Bs1 = wg.coefs_numpy(hs1, w) Y1 = wg.Ys(w, hs1, As1, Bs1) hs2, As2, Bs2, Y2 = wg.hABY(w) self.assertTrue(np.allclose(As1, As2)) self.assertTrue(np.allclose(Bs1, Bs2)) self.assertTrue(np.allclose(Y1, Y2))
def test_Yab_no_loss(self): params = self.params.copy() params['clad'] = {'model': 'gold_dl', 'im_factor': 0.0} wg = pymwm.create(params) w = 2 * np.pi / 2.0 alpha1 = ('E', 1, 1) h1 = wg.beta(w, alpha1) a1, b1 = wg.coef(h1, w, alpha1) alpha2 = ('M', 1, 1) h2 = wg.beta(w, alpha2) a2, b2 = wg.coef(h2, w, alpha2) s1 = 0 s2 = 1 l1 = l2 = 0 n1 = n2 = 1 m1 = m2 = 1 print(a1, b1, a2, b2) self.assertAlmostEqual(wg.norm(w, h1, alpha1, a1, b1), 1.0) self.assertAlmostEqual(wg.norm(w, h2, alpha2, a2, b2), 1.0) self.assertAlmostEqual( wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h1, s1, l1, n1, m1, a1, b1), wg.Y(w, h1, alpha1, a1, b1)) self.assertAlmostEqual( wg.Yab(w, h2, s2, l2, n2, m2, a2, b2, h2, s2, l2, n2, m2, a2, b2), wg.Y(w, h2, alpha2, a2, b2)) print(wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h2, s2, l2, n2, m2, a2, b2)) self.assertAlmostEqual( wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h2, s2, l2, n2, m2, a2, b2), 0.0)
def test_attributes(): wg = pymwm.create(params) assert wg.r == 0.15 w = 2 * np.pi / 5.0 assert wg.fill(w) == 1.0 drude_lorentz = -1272.37592771801 + 351.25089220304176j npt.assert_almost_equal(wg.clad(w), drude_lorentz)
def test_Yab_pec(self): params = self.params.copy() params['clad'] = {'model': 'pec'} wg = pymwm.create(params) w = 2 * np.pi / 5.0 alpha1 = ('E', 1, 1) h1 = wg.beta(w, alpha1) a1, b1 = wg.coef(h1, w, alpha1) alpha2 = ('M', 1, 1) h2 = wg.beta(w, alpha2) a2, b2 = wg.coef(h2, w, alpha2) s1 = 0 s2 = 1 l1 = l2 = 0 n1 = n2 = 1 m1 = m2 = 1 self.assertEqual(wg.norm(w, h1, alpha1, a1, b1), 1.0) self.assertEqual(wg.norm(w, h2, alpha2, a2, b2), 1.0) self.assertEqual(wg.Y(w, h1, alpha1, a1, b1), h1 / w) self.assertEqual(wg.Y(w, h2, alpha2, a2, b2), w / h2) self.assertEqual( wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h1, s1, l1, n1, m1, a1, b1), h1 / w) self.assertEqual( wg.Yab(w, h2, s2, l2, n2, m2, a2, b2, h2, s2, l2, n2, m2, a2, b2), w / h2) self.assertEqual( wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h2, s2, l2, n2, m2, a2, b2), 0.0)
def test_attributes(self): params = self.params.copy() wg = pymwm.create(params) self.assertEqual(wg.r, 0.15) w = 2 * np.pi / 5.0 self.assertEqual(wg.fill(w), 1.0) drude_lorentz = -1272.37592771801+351.25089220304176j self.assertAlmostEqual(wg.clad(w), drude_lorentz)
def test_norm(self): params = self.params.copy() wg = pymwm.create(params) wr = 3.0 * np.pi wi = -0.002 w = complex(wr, wi) hs = np.array([wg.beta(w, alpha) for alpha in wg.alpha_all]) As, Bs = wg.coefs_numpy(hs, w) for h, a, b, s, n, m in zip(hs, As, Bs, wg.s_all, wg.n_all, wg.m_all): pol = 'E' if s == 0 else 'M' norm = wg.norm(w, h, (pol, n, m), a, b) self.assertAlmostEqual(norm, 1.0) params['clad'] = {'model': 'pec'} wg = pymwm.create(params) hs = np.array([wg.beta(w, alpha) for alpha in wg.alpha_all]) As, Bs = wg.coefs_numpy(hs, w) for h, a, b, s, n, m in zip(hs, As, Bs, wg.s_all, wg.n_all, wg.m_all): pol = 'E' if s == 0 else 'M' norm = wg.norm(w, h, (pol, n, m), a, b) self.assertAlmostEqual(norm, 1.0)
def test_coefs(self): params = self.params.copy() wg = pymwm.create(params) wr = 2.0 * np.pi wi = -0.002 w = wr + wi * 1j alpha_all = wg.alpha_all hs = np.array([wg.beta(w, alpha) for alpha in alpha_all]) As1, Bs1 = wg.coefs_numpy(hs, w) As2, Bs2 = wg.coefs(hs, w) print(As1, As2) self.assertTrue(np.allclose(As1, As2)) self.assertTrue(np.allclose(Bs1, Bs2)) params['clad'] = {'model': 'pec'} wg = pymwm.create(params) alpha_all = wg.alpha_all hs = np.array([wg.beta(w, alpha) for alpha in alpha_all]) As1, Bs1 = wg.coefs_numpy(hs, w) As2, Bs2 = wg.coefs(hs, w) print(As1, As2) self.assertTrue(np.allclose(As1, As2)) self.assertTrue(np.allclose(Bs1, Bs2))
def test_Yaa_and_Y(self): params = self.params.copy() wg = pymwm.create(params) w = 2 * np.pi / 0.575 for i, alpha in enumerate(wg.alpha_all): h = wg.beta(w, alpha) a, b = wg.coef(h, w, alpha) s = wg.s_all[i] l = wg.l_all[i] n = wg.n_all[i] m = wg.m_all[i] Yab = wg.Yab(w, h, s, l, n, m, a, b, h, s, l, n, m, a, b) Y = wg.Y(w, h, alpha, a, b) print(Yab) print(Y) self.assertAlmostEqual(Yab, Y)
def test_Yab_with_loss(self): params = self.params.copy() wg = pymwm.create(params) w = 2 * np.pi / 2.0 alpha1 = ('E', 1, 1) h1 = wg.beta(w, alpha1) a1, b1 = wg.coef(h1, w, alpha1) alpha2 = ('M', 1, 1) h2 = wg.beta(w, alpha2) a2, b2 = wg.coef(h2, w, alpha2) s1 = 0 s2 = 1 l1 = l2 = 0 n1 = n2 = 1 m1 = m2 = 1 self.assertAlmostEqual(wg.norm(w, h1, alpha1, a1, b1), 1.0) self.assertAlmostEqual(wg.norm(w, h2, alpha2, a2, b2), 1.0) print(wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h2, s2, l2, n2, m2, a2, b2)) self.assertEqual( wg.Yab(w, h1, s1, l1, n1, m1, a1, b1, h2, s2, l2, n2, m2, a2, b2), 0.0)