Example #1
0
    def check_rotation(self, mat, L, fsrc, zsrc, resolution, tmax, zout, kpred, tol=1.5):
        cell = mp.Vector3(0, 0, L)
        pml_layers = [mp.PML(thickness=1.0, direction=mp.Z)]
        sources = [mp.Source(mp.ContinuousSource(frequency=fsrc),
                             component=mp.Ex, center=mp.Vector3(0, 0, zsrc))]

        self.sim = mp.Simulation(cell_size=cell, geometry=[], sources=sources,
                                 boundary_layers=pml_layers,
                                 default_material=mat, resolution=resolution)

        record_vol = mp.Volume(center=mp.Vector3(0, 0, zout))
        record_Ex, record_Ey, record_t = [], [], []

        def record_ex_ey(sim):
            record_Ex.append(sim.get_array(vol=record_vol, component=mp.Ex))
            record_Ey.append(sim.get_array(vol=record_vol, component=mp.Ey))
            record_t.append(sim.meep_time())

        self.sim.run(mp.after_time(0.5*tmax, mp.at_every(1e-6, record_ex_ey)), until=tmax)

        ex_rel = np.amax(abs(np.fft.fft(record_Ex)))
        ey_rel = np.amax(abs(np.fft.fft(record_Ey)))
        result = np.arctan2(ey_rel, ex_rel) * 180/np.pi

        Ex_theory = np.abs(np.cos(kpred * (zout - zsrc)).real)
        Ey_theory = np.abs(np.sin(kpred * (zout - zsrc)).real)
        expected = np.arctan2(Ey_theory, Ex_theory) * 180/np.pi

        print("Rotation angle (in degrees): {}, expected {}\n".format(result, expected))
        np.testing.assert_allclose(expected, result, atol=tol)
Example #2
0
ml_atom = mp.MultilevelAtom(sigma=1, transitions=transitions, initial_populations=[N0])
two_level = mp.Medium(index=ncav, E_susceptibilities=[ml_atom])

# Specify the cavity geometry:
geometry = [mp.Block(center=mp.Vector3(z=-0.5*sz+0.5*Lcav),
                     size=mp.Vector3(mp.inf,mp.inf,Lcav), material=two_level)]

sim = mp.Simulation(cell_size=cell_size,
                    resolution=resolution,
                    boundary_layers=pml_layers,
                    geometry=geometry,
                    dimensions=dimensions)

sim.init_sim()

def field_func(p):
    return 1 if p.z==-0.5*sz + 0.5*Lcav else 0

sim.fields.initialize_field(mp.Ex, field_func)

# Specify the end time:
endt = 7000
# Note that the total number of time steps run is endt*resolution*2. This is the origin of the extra
# factor of 2 in the definition of dt in fieldfft_meep.m.

def print_field(sim):
    fp = sim.get_field_point(mp.Ex, mp.Vector3(z=(-0.5 * sz) + Lcav + (0.5 * dpad))).real
    print("field:, {}, {}".format(sim.meep_time(), fp))

sim.run(mp.after_time(endt - 250, print_field), until=endt)
sim = mp.Simulation(cell_size=cell_size,
                    resolution=resolution,
                    boundary_layers=pml_layers,
                    geometry=geometry,
                    dimensions=dimensions)

sim.init_sim()


def field_func(p):
    return 1 if p.z == -0.5 * sz + 0.5 * Lcav else 0


sim.fields.initialize_field(mp.Ex, field_func)

# Specify the end time:
endt = 7000
# Note that the total number of time steps run is endt*resolution*2. This is the origin of the extra
# factor of 2 in the definition of dt in fieldfft_meep.m.


def print_field(sim):
    fp = sim.get_field_point(mp.Ex,
                             mp.Vector3(z=(-0.5 * sz) + Lcav +
                                        (0.5 * dpad))).real
    print("field:, {}, {}".format(sim.meep_time(), fp))


sim.run(mp.after_time(endt - 250, print_field), until=endt)