def test_run_te_with_mu_material(self): ms = self.init_solver(geom=False) ms.geometry = [mp.Cylinder(0.2, material=mp.Medium(mu=5))] expected_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.4165291233037574, mp.Vector3(0.5, 0.5, 0.0))), ((0.47328232348733695, mp.Vector3(0.5, 0.0, 0.0)), (0.6699867281290507, mp.Vector3(0.0, 0.0, 0.0))), ((0.6301802646818523, mp.Vector3(0.5, 0.5, 0.0)), (0.8037365323032135, mp.Vector3(0.5, 0.0, 0.0))), ((0.7017932556977557, mp.Vector3(0.5, 0.5, 0.0)), (0.8863448167711359, mp.Vector3(0.5, 0.10000000000000003, 0.0))), ((0.9047498485809726, mp.Vector3(0.5, 0.10000000000000003, 0.0)), (1.0557468193007016, mp.Vector3(0.5, 0.5, 0.0))), ((1.0077925606103986, mp.Vector3(0.2, 0.2, 0.0)), (1.1815403744341757, mp.Vector3(0.0, 0.0, 0.0))), ((1.122424251973878, mp.Vector3(0.20000000000000004, 0.0, 0.0)), (1.2351567679231688, mp.Vector3(0.30000000000000004, 0.30000000000000004, 0.0))), ((1.2059728636717586, mp.Vector3(0.0, 0.0, 0.0)), (1.3135062523646421, mp.Vector3(0.30000000000000004, 0.0, 0.0))), ] ms.run_te() self.check_band_range_data(expected_brd, ms.band_range_data)
def test_sq_rods(self): from mpb_sq_rods import ms ms.deterministic = True ms.filename_prefix = self.filename_prefix ms.tolerance = 1e-12 ms.run_te() expected_te_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.5036058015219026, mp.Vector3(0.5, 0.5, 0.0))), ((0.4446229134706744, mp.Vector3(0.5, 0.0, 0.0)), (0.5943440245519593, mp.Vector3(0.5, 0.5, 0.0))), ((0.5943566394470321, mp.Vector3(0.5, 0.5, 0.0)), (0.7808428121911926, mp.Vector3(0.0, 0.0, 0.0))), ((0.6793887413076383, mp.Vector3(0.5, 0.5, 0.0)), (0.8173893719542897, mp.Vector3(0.30000000000000004, 0.30000000000000004, 0.0))), ((0.83045738223392, mp.Vector3(0.30000000000000004, 0.30000000000000004, 0.0)), (0.9243716830585584, mp.Vector3(0.0, 0.0, 0.0))), ((0.8957817684117546, mp.Vector3(0.5, 0.5, 0.0)), (1.0331104139200438, mp.Vector3(0.5, 0.0, 0.0))), ((0.8957868745330811, mp.Vector3(0.5, 0.5, 0.0)), (1.0958021492221048, mp.Vector3(0.5, 0.0, 0.0))), ((1.097416809585406, mp.Vector3(0.5, 0.0, 0.0)), (1.1280127648119964, mp.Vector3(0.5, 0.5, 0.0))), ] self.check_band_range_data(expected_te_brd, ms.band_range_data) ms.run_tm() expected_tm_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.285905779119655, mp.Vector3(0.5, 0.5, 0.0))), ((0.42065733839975095, mp.Vector3(0.5, 0.0, 0.0)), (0.5503360754831277, mp.Vector3(0.0, 0.0, 0.0))), ((0.5029830978365978, mp.Vector3(0.5, 0.5, 0.0)), (0.5671632878128118, mp.Vector3(0.5, 0.0, 0.0))), ((0.5613397939889757, mp.Vector3(0.0, 0.0, 0.0)), (0.7200918204563993, mp.Vector3(0.5, 0.0, 0.0))), ((0.7472029910480836, mp.Vector3(0.5, 0.0, 0.0)), (0.874359380500508, mp.Vector3(0.5, 0.5, 0.0))), ((0.8404509697526803, mp.Vector3(0.30000000000000004, 0.30000000000000004, 0.0)), (0.8833173725822788, mp.Vector3(0.5, 0.5, 0.0))), ((0.8770118718330763, mp.Vector3(0.5, 0.0, 0.0)), (0.9653253808981632, mp.Vector3(0.0, 0.0, 0.0))), ((0.8929933495598104, mp.Vector3(0.5, 0.5, 0.0)), (1.089377682009333, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_tm_brd, ms.band_range_data)
def test_output_tot_pwr(self): ms = self.init_solver() ms.run_te() mpb.output_tot_pwr(ms, 8) ref_fname = 'tutorial-tot.rpwr.k16.b08.te.h5' ref_path = os.path.join(self.data_dir, ref_fname) res_path = re.sub('tutorial', self.filename_prefix, ref_fname) self.compare_h5_files(ref_path, res_path)
def test_tri_rods(self): from mpb_tri_rods import ms ms.deterministic = True ms.tolerance = 1e-12 ms.filename_prefix = self.filename_prefix ms.run_tm( mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, mpb.output_efield_z)) ref_fn = 'tri-rods-e.k11.b08.z.tm.h5' ref_path = os.path.join(self.data_dir, ref_fn) res_path = re.sub('tri-rods', self.filename_prefix, ref_fn) self.compare_h5_files(ref_path, res_path) ms.run_te() expected_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.49123581186757737, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.4730722390280754, mp.Vector3(0.0, 0.5, 0.0)), (0.5631059378714038, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.5631505198559038, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.7939289395839766, mp.Vector3(0.0, 0.0, 0.0))), ((0.7676614799039024, mp.Vector3(0.0, 0.5, 0.0)), (0.8214230044191525, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.865194814441525, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (1.0334130018594276, mp.Vector3(0.0, 0.0, 0.0))), ((0.8652307994936862, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (1.0334230910419813, mp.Vector3(0.0, 0.0, 0.0))), ((1.021367669109368, mp.Vector3(0.0, 0.5, 0.0)), (1.115966990757518, mp.Vector3(0.0, 0.0, 0.0))), ((1.108662658537423, mp.Vector3(-0.26666666666666666, 0.26666666666666666, 0.0)), (1.1168107191255379, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_brd, ms.band_range_data)
def test_load_and_save_eigenvectors(self): ms = self.init_solver() ms.run_te() fn = self.filename_prefix + '.h5' ev = ms.get_eigenvectors(8, 1) zeros = np.zeros(ev.shape, dtype=np.complex128) ms.set_eigenvectors(zeros, 8) ms.save_eigenvectors(fn) ms.run_te() ms.load_eigenvectors(fn) new_ev = ms.get_eigenvectors(8, 1) self.assertEqual(np.count_nonzero(new_ev), 0)
def test_get_eigenvectors(self): ms = self.init_solver() ms.run_te(mpb.fix_hfield_phase) def compare_eigenvectors(ref_fn, start, cols): with h5py.File(os.path.join(self.data_dir, ref_fn), 'r') as f: expected = f['rawdata'].value # Reshape the last dimension of 2 reals into one complex expected = np.vectorize(complex)(expected[..., 0], expected[..., 1]) ev = ms.get_eigenvectors(start, cols) np.testing.assert_allclose(expected, ev, rtol=1e-3) # Get all columns compare_eigenvectors('tutorial-te-eigenvectors.h5', 1, 8) # Get last column compare_eigenvectors('tutorial-te-eigenvectors-8-1.h5', 8, 1) # Get columns 3,4, and 5 compare_eigenvectors('tutorial-te-eigenvectors-3-3.h5', 3, 3)
def test_subpixel_averaging(self): ms = self.init_solver() ms.run_te() expected_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.49683586474489877, mp.Vector3(0.5, 0.5, 0.0))), ((0.4415884497225449, mp.Vector3(0.5, 0.0, 0.0)), (0.5931405141160885, mp.Vector3(0.5, 0.5, 0.0))), ((0.5931535863117832, mp.Vector3(0.5, 0.5, 0.0)), (0.7732265593069759, mp.Vector3(0.0, 0.0, 0.0))), ((0.6791690130757013, mp.Vector3(0.5, 0.5, 0.0)), (0.80968915516771, mp.Vector3(0.30000000000000004, 0.30000000000000004, 0.0))), ((0.8241814443502151, mp.Vector3(0.5, 0.30000000000000004, 0.0)), (0.9229965195855876, mp.Vector3(0.0, 0.0, 0.0))), ((0.8819770916660669, mp.Vector3(0.5, 0.5, 0.0)), (1.0291597050650205, mp.Vector3(0.5, 0.0, 0.0))), ((0.8819818134421844, mp.Vector3(0.5, 0.5, 0.0)), (1.086072932359415, mp.Vector3(0.5, 0.0, 0.0))), ((1.0878689635052692, mp.Vector3(0.5, 0.0, 0.0)), (1.1119173707556929, mp.Vector3(0.5, 0.5, 0.0))), ] expected_gap_list = [ (0.0022038709776893727, 0.5931405141160885, 0.5931535863117832), (1.7739824912427062, 0.80968915516771, 0.8241814443502151), (0.1652326724344101, 1.086072932359415, 1.0878689635052692) ] ref_fn = 'subpixel_avg-epsilon.h5' ref_path = os.path.join(self.data_dir, ref_fn) res_path = re.sub('subpixel_avg', self.filename_prefix, ref_fn) self.compare_h5_files(ref_path, res_path) self.check_band_range_data(expected_brd, ms.band_range_data) self.check_gap_list(expected_gap_list, ms.gap_list)
def test_set_eigenvectors(self): ms = self.init_solver() def set_H_to_zero_and_check(start, num_bands): ev = ms.get_eigenvectors(start, num_bands) self.assertNotEqual(np.count_nonzero(ev), 0) zeros = np.zeros(ev.shape, dtype=np.complex128) ms.set_eigenvectors(zeros, start) new_ev = ms.get_eigenvectors(start, num_bands) self.assertEqual(np.count_nonzero(new_ev), 0) ms.run_te() set_H_to_zero_and_check(8, 1) ms.run_te() set_H_to_zero_and_check(1, 8) ms.run_te() set_H_to_zero_and_check(3, 3)
def test_tri_holes(self): from mpb_tri_holes import ms ms.deterministic = True ms.filename_prefix = self.filename_prefix ms.tolerance = 1e-12 ms.run_te() expected_te_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.2993049473117476, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.4924342823622065, mp.Vector3(0.0, 0.5, 0.0)), (0.6568362683499375, mp.Vector3(0.0, 0.0, 0.0))), ((0.5269710506448809, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.7156232200212518, mp.Vector3(0.0, 0.0, 0.0))), ((0.6568031427446027, mp.Vector3(0.0, 0.5, 0.0)), (0.7578382217502109, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.7383774303752574, mp.Vector3(0.0, 0.0, 0.0)), (0.7988168792802597, mp.Vector3(0.0, 0.5, 0.0))), ((0.8259787164701536, mp.Vector3(0.0, 0.0, 0.0)), (0.9629215441012396, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.8271634538840886, mp.Vector3(0.0, 0.0, 0.0)), (0.9834563303529568, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.9984200611839882, mp.Vector3(-0.26666666666666666, 0.26666666666666666, 0.0)), (1.0411551252079034, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_te_brd, ms.band_range_data) ms.run_tm() expected_tm_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.28009156817399916, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.28015523913784407, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.3985126081046686, mp.Vector3(0.0, 0.0, 0.0))), ((0.4390817228448606, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.49288810189980625, mp.Vector3(0.0, 0.0, 0.0))), ((0.49336847788268695, mp.Vector3(0.0, 0.0, 0.0)), (0.5808701365268192, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.581035246804371, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.6824860801372987, mp.Vector3(0.0, 0.0, 0.0))), ((0.682531744671499, mp.Vector3(0.0, 0.0, 0.0)), (0.7011061593213783, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.6920145742134771, mp.Vector3(0.0, 0.0, 0.0)), (0.7841042622393081, mp.Vector3(0.0, 0.4, 0.0))), ((0.7980077872594108, mp.Vector3(0.0, 0.4, 0.0)), (0.8982239424823442, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_tm_brd, ms.band_range_data)
def test_honey_rods(self): from mpb_honey_rods import ms ms.deterministic = True ms.filename_prefix = self.filename_prefix ms.tolerance = 1e-12 expected_tm_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.3351167660354989, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.3351850759916969, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.42984811237816406, mp.Vector3(0.0, 0.0, 0.0))), ((0.5751709345431462, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.7255897672261712, mp.Vector3(0.0, 0.0, 0.0))), ((0.6918627724774271, mp.Vector3(0.0, 0.5, 0.0)), (0.747622077830657, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.7443374497087805, mp.Vector3(-0.06666666666666667, 0.06666666666666667, 0.0)), (0.7793792212092525, mp.Vector3(0.0, 0.5, 0.0))), ((0.7852786984418492, mp.Vector3(0.0, 0.0, 0.0)), (0.8193652861712535, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.7856577771856611, mp.Vector3(0.0, 0.0, 0.0)), (0.9122560439014182, mp.Vector3(0.0, 0.5, 0.0))), ((1.0540350508135123, mp.Vector3(0.0, 0.5, 0.0)), (1.1492769389234725, mp.Vector3(0.0, 0.0, 0.0))), ] ms.run_tm() self.check_band_range_data(expected_tm_brd, ms.band_range_data) expected_te_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.5535093489972593, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.5203183590840945, mp.Vector3(0.0, 0.5, 0.0)), (0.7278447515454929, mp.Vector3(0.0, 0.0, 0.0))), ((0.576335859651312, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.7880878930618354, mp.Vector3(0.0, 0.0, 0.0))), ((0.8161730293674944, mp.Vector3(0.0, 0.5, 0.0)), (0.9209611432140968, mp.Vector3(0.0, 0.0, 0.0))), ((0.8385562359606971, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.9220849425898038, mp.Vector3(0.0, 0.0, 0.0))), ((1.0168656683915511, mp.Vector3(0.0, 0.0, 0.0)), (1.1083536673418435, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((1.0184507253059425, mp.Vector3(0.0, 0.0, 0.0)), (1.159370227370719, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((1.1636719050364361, mp.Vector3(-0.2, 0.2, 0.0)), (1.2433411839870618, mp.Vector3(0.0, 0.0, 0.0))), ] ms.run_te() self.check_band_range_data(expected_te_brd, ms.band_range_data)