コード例 #1
0
    def verify_output_and_slice(self, material, frequency):
        # Since the slice routines average the diagonals, we need to do that too:
        chi1 = material.epsilon(frequency).astype(np.complex128)
        chi1inv = np.linalg.inv(chi1)
        chi1inv = np.diag(chi1inv)
        N = chi1inv.size
        n = np.sqrt(N / np.sum(chi1inv))

        sim = mp.Simulation(cell_size=mp.Vector3(2, 2, 2),
                            default_material=material,
                            resolution=20,
                            eps_averaging=False)
        sim.use_output_directory(self.temp_dir)
        sim.init_sim()

        # Check to make sure the get_slice routine is working with frequency
        n_slice = np.sqrt(np.max(sim.get_epsilon(frequency)))
        self.assertAlmostEqual(n, n_slice, places=4)

        # Check to make sure h5 output is working with frequency
        filename = os.path.join(self.temp_dir,
                                'dispersive_eigenmode-eps-000000.00.h5')
        mp.output_epsilon(sim, frequency=frequency)
        n_h5 = 0
        mp.all_wait()
        with h5py.File(filename, 'r') as f:
            n_h5 = np.sqrt(
                np.max(mp.complexarray(f['eps.r'][()], f['eps.i'][()])))
        self.assertAlmostEqual(n, n_h5, places=4)
コード例 #2
0
    def verify_output_and_slice(self, material, omega):
        # Since the slice routines average the diagonals, we need to do that too:
        chi1 = material.epsilon(omega).astype(np.complex128)
        if np.any(np.imag(chi1) != 0):
            chi1 = np.square(np.real(np.sqrt(chi1)))
        chi1inv = np.linalg.inv(chi1)
        chi1inv = np.diag(chi1inv)
        N = chi1inv.size
        n = np.sqrt(N / np.sum(chi1inv))

        sim = mp.Simulation(cell_size=mp.Vector3(2, 2, 2),
                            default_material=material,
                            resolution=20,
                            eps_averaging=False)
        sim.init_sim()

        # Check to make sure the get_slice routine is working with omega
        n_slice = np.sqrt(np.max(sim.get_epsilon(omega)))
        self.assertAlmostEqual(n, n_slice, places=4)

        # Check to make sure h5 output is working with omega
        filename = 'dispersive_eigenmode-eps-000000.00.h5'
        mp.output_epsilon(sim, omega=omega)
        n_h5 = 0
        mp.all_wait()
        with h5py.File(filename, 'r') as f:
            n_h5 = np.sqrt(np.mean(f['eps'][()]))
        self.assertAlmostEqual(n, n_h5, places=4)
コード例 #3
0
ファイル: simulation.py プロジェクト: zzzzz9527/meep
    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)
コード例 #4
0
ファイル: simulation.py プロジェクト: stevengj/meep
    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)
コード例 #5
0
ファイル: coupler.py プロジェクト: mynanoweb/meep
sources = [
    mp.EigenModeSource(src=mp.GaussianSource(fcen, fwidth=df_source),
                       size=src_size,
                       center=src_center,
                       eig_band=mode_num)
]

sim = mp.Simulation(resolution=resolution,
                    cell_size=cell_size,
                    boundary_layers=[mp.PML(dpml)],
                    sources=sources,
                    geometry=geometry)

sim.init_sim()
mp.output_epsilon(sim)

p1_region = mp.FluxRegion(center=p1_center, size=p1_size)
flux1 = sim.add_flux(fcen, df_flux, nfreq, p1_region)

p2_region = mp.FluxRegion(center=p2_center, size=p2_size)
flux2 = sim.add_flux(fcen, df_flux, nfreq, p2_region)

p3_region = mp.FluxRegion(center=p3_center, size=p3_size)
flux3 = sim.add_flux(fcen, df_flux, nfreq, p3_region)

p4_region = mp.FluxRegion(center=p4_center, size=p4_size)
flux4 = sim.add_flux(fcen, df_flux, nfreq, p4_region)

sim.run(until_after_sources=mp.stop_when_fields_decayed(
    25, mp.Ez, p3_center, 1e-8))