def test_get_array_output(self): sim = self.init_simple_simulation() sim.use_output_directory(self.temp_dir) sim.symmetries = [] sim.geometry = [mp.Cylinder(0.2, material=mp.Medium(index=3))] sim.filename_prefix = 'test_get_array_output' sim.run(until=20) mp.output_epsilon(sim) mp.output_efield_z(sim) mp.output_tot_pwr(sim) mp.output_efield(sim) eps_arr = sim.get_epsilon() efield_z_arr = sim.get_efield_z() energy_arr = sim.get_tot_pwr() efield_arr = sim.get_efield() fname_fmt = os.path.join(self.temp_dir, 'test_get_array_output-{}-000020.00.h5') with h5py.File(fname_fmt.format('eps'), 'r') as f: eps = f['eps'][()] with h5py.File(fname_fmt.format('ez'), 'r') as f: efield_z = f['ez'][()] with h5py.File(fname_fmt.format('energy'), 'r') as f: energy = f['energy'][()] with h5py.File(fname_fmt.format('e'), 'r') as f: ex = f['ex'][()] ey = f['ey'][()] ez = f['ez'][()] efield = np.stack([ex, ey, ez], axis=-1) np.testing.assert_allclose(eps, eps_arr) np.testing.assert_allclose(efield_z, efield_z_arr) np.testing.assert_allclose(energy, energy_arr) np.testing.assert_allclose(efield, efield_arr)
def test_get_array_output(self): sim = self.init_simple_simulation() sim.symmetries = [] sim.geometry = [mp.Cylinder(0.2, material=mp.Medium(index=3))] sim.filename_prefix = 'test_get_array_output' sim.run(until=20) mp.output_epsilon(sim) mp.output_efield_z(sim) mp.output_tot_pwr(sim) mp.output_efield(sim) eps_arr = sim.get_epsilon() efield_z_arr = sim.get_efield_z() energy_arr = sim.get_tot_pwr() efield_arr = sim.get_efield() fname_fmt = "test_get_array_output-{}-000020.00.h5" with h5py.File(fname_fmt.format('eps'), 'r') as f: eps = f['eps'][()] with h5py.File(fname_fmt.format('ez'), 'r') as f: efield_z = f['ez'][()] with h5py.File(fname_fmt.format('energy'), 'r') as f: energy = f['energy'][()] with h5py.File(fname_fmt.format('e'), 'r') as f: ex = f['ex'][()] ey = f['ey'][()] ez = f['ez'][()] efield = np.stack([ex, ey, ez], axis=-1) np.testing.assert_allclose(eps, eps_arr) np.testing.assert_allclose(efield_z, efield_z_arr) np.testing.assert_allclose(energy, energy_arr) np.testing.assert_allclose(efield, efield_arr)