def test_solve_whole_matrix(self): with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl.solver = 'matrix' qcl.populate_x() qcl.solve_whole() # 0.264 is approximately 4.7um self.assertAlmostEqual(qcl.eigenEs[41] - qcl.eigenEs[31], 0.264, 2) qcl.period_recognize() qcl.period_map_build() self.assertAlmostEqual(qcl.eigenEs[41] - qcl.eigenEs[31], 0.26, 2) for i, j in ((25, 41), (24, 40), (26, 42), (31, 49)): self.assertEqual(qcl.periodMap[i][1], 1) self.assertEqual(qcl.periodIdx[qcl.periodMap[i][0]], j) np.testing.assert_almost_equal(qcl.psi_overlap(44, j, 1), qcl.psi_overlap(44, i), decimal=6) self.assertAlmostEqual(qcl._dipole(44, j, 1), qcl._dipole(44, i), 3) self.assertAlmostEqual(qcl._lo_transition(44, j, 1), qcl._lo_transition(44, i), 4) self.assertAlmostEqual(qcl._ifr_transition(44, j, 1), qcl._ifr_transition(44, i), 5) # Test overlapping np.testing.assert_almost_equal(qcl.psi_overlap(41, 49, 1), qcl.psi_overlap(41, 31), decimal=6)
def test_cache_consistency(self): with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl.includeIFR = True qcl.mtrlIFRLambda = [5.0] * 2 qcl.mtrlIFRDelta = [5.0] * 2 qcl.repeats = 4 qcl.populate_x() qcl.solve_whole() self.assertFalse(hasattr(qcl, 'periodMap')) self.assertEqual(qcl.status, 'solved') taulo = qcl.lo_lifetime(33) tauifr = qcl.ifr_lifetime(33) tau = qcl.lifetime(33) gamma = qcl.ifr_broadening(31, 21) qcl.period_recognize() qcl.period_map_build() qcl.full_population() self.assertEqual(qcl.status, 'solved-full') self.assertTrue(hasattr(qcl, 'periodMap')) # A different cache is used self.assertNotEqual(taulo, qcl.lo_lifetime(33), 4) self.assertNotEqual(tauifr, qcl.ifr_lifetime(33), 4) self.assertNotEqual(tau, qcl.lifetime(33), 4) self.assertNotEqual(gamma, qcl.ifr_broadening(39, 31), 9) # But result should be approximately same self.assertAlmostEqual(taulo, qcl.lo_lifetime(33), 4) self.assertAlmostEqual(tauifr, qcl.ifr_lifetime(33), 4) self.assertAlmostEqual(tau, qcl.lifetime(33), 4) self.assertAlmostEqual(gamma, qcl.ifr_broadening(31, 21), 0)
def test_solve_basis(self): with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl.populate_x() qcl.solve_basis() self.assertAlmostEqual(qcl.eigenEs[32] - qcl.eigenEs[31], 0.27, 2) self.assertEqual(qcl.eigenEs.shape, (96, )) self.assertEqual(qcl.psis.shape, (96, 1384))
def test_revert_layer(self): with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl.solver = 'matrix' qcl.repeats = 2 qcl.xres = 0.02 qcl.populate_x() e1 = qcl.solve_whole() - np.min(qcl.xVc) qcl.invert_layer() qcl.EField = -qcl.EField qcl.populate_x() e2 = qcl.solve_whole() - np.min(qcl.xVc) np.testing.assert_almost_equal(e1, e2, decimal=3)
def test_solve_whole_ode(self): with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl.solver = 'ODE' qcl.populate_x() qcl.solve_whole() # 0.264 is approximately 4.7um self.assertAlmostEqual(qcl.eigenEs[31] - qcl.eigenEs[21], 0.264, 2) qcl.period_recognize() qcl.period_map_build() for i, j in ((21, 39), (14, 30), (15, 31)): self.assertEqual(qcl.periodMap[i][1], 1) self.assertEqual(qcl.periodIdx[qcl.periodMap[i][0]], j) np.testing.assert_almost_equal(qcl.psi_overlap(33, j, 1), qcl.psi_overlap(33, i), decimal=6) self.assertAlmostEqual(qcl._dipole(33, j, 1), qcl._dipole(33, i), 2)
#!/usr/bin/env python3 # -*- coding:utf-8 -*- from context import * # type: ignore # noqa: F401, F403 from ErwinJr2 import SaveLoad from ErwinJr2.OptStrata import OptStrata import numpy as np import matplotlib import matplotlib.pyplot as plt matplotlib.rcParams.update({'font.size': 12}) with open("../ErwinJr2/example/PQLiu.json", 'r') as f: strata = SaveLoad.optLoad(f) strata = OptStrata( wl=8.0, materials=[ "Air", "InP", "InP", "InP", "InP", "InxGa1-xAs", "Active Core", "InxGa1-xAs", "InP", "InP" ], moleFracs=[0.0, 0.0, 0.0, 0.0, 0.0, 0.53, 0.53, 0.53, 0.53, 0.0], dopings=[0.0, 1000.0, 80.0, 2.0, 1.0, 0.5, 0, 0.5, 0, 0.0], Ls=[1.0, 0.01, 0.35, 0.5, 2.5, 0.5, 2.0895, 0.5, 5.0, 1.0], # the properties for the active core cstmIndx={"Active Core": 3.28 + 0j}, cstmPrd={"Active Core": [597.0, 35]}, cstmGain={"Active Core": 39.6}) beta = strata.boundModeTM() xs = np.linspace(-1, sum(strata.Ls[1:]), 5000) nx = strata.populateIndices(xs) Ey, _, _ = strata.populateMode(beta, xs)
#!/usr/bin/env python3 # -*- coding:utf-8 -*- from context import * # type: ignore # noqa: F401, F403 from ErwinJr2 import SaveLoad from ErwinJr2.QCPlotter import plotPotential, plotWF from ErwinJr2.QCLayers import QCLayers import matplotlib.pyplot as plt with open("../ErwinJr2/example/PQLiu.json") as f: qcl = SaveLoad.qclLoad(f) qcl = QCLayers( substrate='InP', EField=51.0, wl=8.0, layerWidths=[ 34.0, 14.0, 33.0, 13.0, 32.0, 15.0, 31.0, 19.0, 29.0, 23.0, 27.0, 25.0, 27.0, 44.0, 18.0, 9.0, 57.0, 11.0, 54.0, 12.0, 45.0, 25.0], layerMtrls=[ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], layerDopings=[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], layerARs=[ False, False, False, False, False, False, False, False, False, False, False, False, False, True, True, True, True, True, True, True, True, False], mtrlIFRDelta=[1.2, 1.2], mtrlIFRLambda=[90.0, 90.0] ) qcl.includeIFR = True
axes.set_ylabel('Energy (eV)', fontsize=fsize) axes.plot(qcLayers.xPoints, qcLayers.xVc, 'k', linewidth=1) # for xv, conf in ((qcLayers.xVL, 'g--'), # (qcLayers.xVX, 'm-.'), # (qcLayers.xVLH, 'k'), # (qcLayers.xVSO, 'r--')): # axes.plot(qcLayers.xPoints, xv, conf, linewidth=1) if hasattr(qcLayers, 'xlayerSelected'): axes.plot(qcLayers.xPoints, qcLayers.xlayerSelected, 'b', linewidth=1) if hasattr(qcLayers, 'eigenEs'): for n in range(qcLayers.eigenEs.size): psi = qcLayers.psis[n, :]**2 tol = 1e-6 start = np.argmax(psi > tol) end = len(psi) - np.argmax(psi[::-1] > tol) axes.plot(qcLayers.xPoints[start:end], 5 * psi[start:end] + qcLayers.eigenEs[n]) if __name__ == '__main__': with open("../example/new16umgaas-cladding.json") as f: qcl = SaveLoad.qclLoad(f) qcl.populate_x() qcl.solve_whole() axes = plt.axes() plot_band(axes, qcl) plt.show()