Esempio n. 1
0
def main(args):

    n = 3.4  # index of waveguide
    w = 1.0  # width of waveguide
    r = 1.0  # inner radius of ring

    pad = 4  # padding between waveguide and edge of PML
    dpml = 2  # thickness of PML

    sxy = 2.0 * (r + w + pad + dpml)  # cell size
    resolution = 10.0

    gv = mp.voltwo(sxy, sxy, resolution)
    gv.center_origin()

    sym = mp.mirror(mp.Y, gv)

    # exploit the mirror symmetry in structure+source:
    the_structure = mp.structure(gv, dummy_eps, mp.pml(dpml), sym)

    # Create a ring waveguide by two overlapping cylinders - later objects
    # take precedence over earlier objects, so we put the outer cylinder first.
    # and the inner (air) cylinder second.

    objects = []
    n2 = n * n
    dielectric = gm.Medium(epsilon_diag=gm.Vector3(n2, n2, n2))
    objects.append(gm.Cylinder(r + w, material=dielectric))
    objects.append(gm.Cylinder(r))

    mp.set_materials_from_geometry(the_structure, objects)
    f = mp.fields(the_structure)

    # If we don't want to excite a specific mode symmetry, we can just
    # put a single point source at some arbitrary place, pointing in some
    # arbitrary direction.  We will only look for TM modes (E out of the plane).
    fcen = 0.15  # pulse center frequency
    df = 0.1
    src = GaussianSource(fcen, df)
    v = mp.volume(mp.vec(r + 0.1, 0.0), mp.vec(0.0, 0.0))
    f.add_volume_source(mp.Ez, src, v)

    T = 300.0
    stop_time = f.last_source_time() + T
    while f.round_time() < stop_time:
        f.step()

    # TODO: translate call to harminv
    # int bands = do_harminv (... Ez, vec3(r+0.1), fcen, df)

    # Output fields for one period at the end.  (If we output
    # at a single time, we might accidentally catch the Ez field
    # when it is almost zero and get a distorted view.)
    DeltaT = 1.0 / (20 * fcen)
    NextOutputTime = f.round_time() + DeltaT
    while f.round_time() < 1.0 / fcen:
        f.step()
        if f.round_time() >= NextOutputTime:
            f.output_hdf5(mp.Ez, f.total_volume())
            NextOutputTime += DeltaT
 def make_fields(self):
     if self.gridSizeZ == None:
         self.meep_space = voltwo(self.gridSizeX,self.gridSizeY,self.res)
     else:
         self.meep_space = vol3d(self.gridSizeX,self.gridSizeY,self.gridSizeZ,self.res)
     material = epsilon(self.my_structure)
     set_EPS_Callback(material.__disown__())
     
     
     if self.symmetry_direction == None:
         sym = identity()
     else:
         sym = mirror(self.symmetry_direction,self.meep_space)*self.symmetry_val
         
     self.meep_structure = structure(self.meep_space, EPS, self.boundary_conditions,sym)
     
     
     the_fields = fields(self.meep_structure)
     
     for direc in self.periodic_directions:
         the_fields.set_boundary(Low,direc,Periodic)
         the_fields.set_boundary(High,direc,Periodic)
     
     
     the_fields.use_bloch(self.bloch)
     
     if self.my_source is not None:
         self.my_source.add_to_fields(the_fields)
  
     for f in self.fluxes:
         f.add_to_fields(the_fields)
     
     self.meep_fields = the_fields
     return the_fields
Esempio n. 3
0
    def test_radiating_2d(self):

        xmax = 8.0

        # grid_volume
        self.gv = mp.voltwo(xmax, self.ymax, self.a)

        self.pnt_src_vec = mp.vec(xmax / 2 - self.dx, self.ymax / 2)
        self.p1 = mp.vec(xmax / 2 + 0 * self.dx, self.ymax / 2)
        self.p2 = mp.vec(xmax / 2 + 1 * self.dx, self.ymax / 2)

        self.radiating_base(True)
Esempio n. 4
0
    def setUp(self):
        def dummy_eps(v):
            return 1.0

        gv = mp.voltwo(16, 16, 10)
        gv.center_origin()
        sym = mp.mirror(mp.Y, gv)
        the_structure = mp.structure(gv, dummy_eps, mp.pml(2), sym)
        objects = []
        objects.append(Cylinder(1))
        mp.set_materials_from_geometry(the_structure, objects)
        self.f = mp.fields(the_structure)
        self.v = mp.volume(mp.vec(1.1, 0.0), mp.vec(0.0, 0.0))
Esempio n. 5
0
    def setUp(self):

        def dummy_eps(v):
            return 1.0

        gv = mp.voltwo(16, 16, 10)
        gv.center_origin()
        sym = mp.mirror(mp.Y, gv)
        the_structure = mp.structure(gv, dummy_eps, mp.pml(2), sym)
        objects = []
        objects.append(Cylinder(1))
        mp.set_materials_from_geometry(the_structure, objects)
        self.f = mp.fields(the_structure)
        self.v = mp.volume(mp.vec(1.1, 0.0), mp.vec(0.0, 0.0))
Esempio n. 6
0
def bend_flux(no_bend):

    sx = 16.0  # size of cell in X direction
    sy = 32.0  # size of cell in Y direction
    pad = 4.0  # padding distance between waveguide and cell edge
    w = 1.0  # width of waveguide
    resolution = 10  # (set-param! resolution 10)

    gv = mp.voltwo(sx, sy, resolution)
    gv.center_origin()
    the_structure = mp.structure(gv, dummy_eps, mp.pml(1.0))

    wvg_ycen = -0.5 * (sy - w - 2.0 * pad)  # y center of horiz. wvg
    wvg_xcen = 0.5 * (sx - w - 2.0 * pad)  # x center of vert. wvg

    e1 = gm.Vector3(1.0, 0.0, 0.0)
    e2 = gm.Vector3(0.0, 1.0, 0.0)
    e3 = gm.Vector3(0.0, 0.0, 1.0)

    dielectric = gm.Medium(epsilon_diag=gm.Vector3(12, 12, 12))
    if no_bend:
        center = gm.Vector3(y=wvg_ycen)
        size = gm.Vector3(float('inf'), w, float('inf'))
        objects = [
            gm.Block(size, e1, e2, e3, material=dielectric, center=center)
        ]
        mp.set_materials_from_geometry(the_structure, objects)
    else:
        objects = []
        center = gm.Vector3(-0.5 * pad, wvg_ycen)
        size = gm.Vector3(sx - pad, w, float('inf'))
        objects.append(
            gm.Block(size, e1, e2, e3, material=dielectric, center=center))

        center = gm.Vector3(wvg_xcen, 0.5 * pad)
        size = gm.Vector3(w, sy - pad, float('inf'))
        objects.append(
            gm.Block(size, e1, e2, e3, material=dielectric, center=center))
        mp.set_materials_from_geometry(the_structure, objects)

    f = mp.fields(the_structure)

    fcen = 0.15  # pulse center frequency
    df = 0.1
    src = GaussianSource(fcen, df)
    v = mp.volume(mp.vec(1.0 - 0.5 * sx, wvg_ycen), mp.vec(0.0, w))
    f.add_volume_source(mp.Ez, src, v)

    f_start = fcen - 0.5 * df
    f_end = fcen + 0.5 * df
    nfreq = 100  # number of frequencies at which to compute flux

    if no_bend:
        trans_volume = mp.volume(mp.vec(0.5 * sx - 1.5, wvg_ycen),
                                 mp.vec(0.0, 2.0 * w))
    else:
        trans_volume = mp.volume(mp.vec(wvg_xcen, 0.5 * sy - 1.5),
                                 mp.vec(2.0 * w, 0.0))

    trans_vl = mp.volume_list(trans_volume, mp.Sz)
    trans = f.add_dft_flux(trans_vl, f_start, f_end, nfreq)

    refl_volume = mp.volume(mp.vec(-0.5 * sx + 1.5, wvg_ycen),
                            mp.vec(0.0, 2.0 * w))
    refl_vl = mp.volume_list(refl_volume, mp.Sz)
    refl = f.add_dft_flux(refl_vl, f_start, f_end, nfreq)

    dataname = "refl-flux"
    if not no_bend:
        refl.load_hdf5(f, dataname)
        refl.scale_dfts(-1.0)

    eval_point = mp.vec(0.5 * sx - 1.5, wvg_ycen) if no_bend else mp.vec(
        wvg_xcen, 0.5 * sy - 1.5)
    deltaT = 50.0
    next_check_time = f.round_time() + deltaT
    tol = 1.0e-3
    max_abs = 0.0
    cur_max = 0.0
    done = False

    while not done:
        f.step()

        # manually check fields-decayed condition
        absEz = abs(f.get_field(mp.Ez, eval_point))
        cur_max = max(cur_max, absEz)
        if f.round_time() >= next_check_time:
            next_check_time += deltaT
            max_abs = max(max_abs, cur_max)
            if max_abs > 0.0 and cur_max < tol * max_abs:
                done = True
            cur_max = 0.0

        # printf("%.2e %.2e %.2e %.2e\n",f.round_time(),absEz,max_abs,cur_max)

    if no_bend:
        refl.save_hdf5(f, dataname)

    print("{}\t\t | {}\t\t | {}".format("Time", "trans flux", "refl flux"))
    f0 = fcen - 0.5 * df
    fstep = df / (nfreq - 1)
    trans_flux = trans.flux()
    refl_flux = refl.flux()
    for nf in range(nfreq):
        print("{}\t\t | {}\t\t | {}".format(f0 + nf * fstep, trans_flux[nf],
                                            refl_flux[nf]))