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 radiating_base(self, sq_ratio, solve_cw=True): w = 0.30 s = mp.structure(self.gv, one, mp.pml(self.ymax / 3.0)) f = mp.fields(s) src = ContinuousSource(w) f.add_point_source(mp.Ez, src, self.pnt_src_vec) # let the source reach steady state if solve_cw: f.solve_cw(1e-6) else: while f.time() < 400: f.step() # amp1 and amp2 are of type complex amp1 = f.get_field(mp.Ez, self.p1) amp2 = f.get_field(mp.Ez, self.p2) ratio = abs(amp1) / abs(amp2) if self.gv.dim == mp.D2: ratio = ratio**2 # in 2d, decay is ~1/sqrt(r), so square to get 1/r print("Ratio is {} from ({} {}) and ({} {})".format( ratio, amp1.real, amp1, amp2.real, amp2)) fail_fmt = "Failed: amp1 = ({}, {}), amp2 = ({}, {})\nabs(amp1/amp2){} = {}, too far from 2.0" fail_msg = fail_fmt.format(amp1.real, amp1, amp2.real, amp2, "^2" if sq_ratio else "", ratio) self.assertTrue(ratio <= 2.12 and ratio >= 1.88, fail_msg)
def __init__(self, thickness, direction=mp.ALL, side=mp.ALL, R_asymptotic=1e-15, mean_stretch=1.0, pml_profile=lambda u: u * u): self.thickness = thickness self.direction = direction self.side = side self.R_asymptotic = R_asymptotic self.mean_stretch = mean_stretch self.pml_profile = pml_profile if direction == mp.ALL and side == mp.ALL: self.swigobj = mp.pml(thickness, R_asymptotic, mean_stretch) elif direction == mp.ALL: self.swigobj = mp.pml(thickness, side, R_asymptotic, mean_stretch) else: self.swigobj = mp.pml(thickness, direction, side, R_asymptotic, mean_stretch)
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))
LOG.debug("Meep node %i -Defining structure..." % (self.node_nr)) symmetry_object = Meep.identity() if (self.symmY): LOG.debug("Meep node %i -Using y symmetry!" % (self.node_nr)) symmetry_object = Meep.mirror(Meep.Y, self.meepVol) symmetry_object = symmetry_object * complex(1.0, 0.0) # When there is a certain PML direction, use that one. if isinstance(landscape.pml_direction, str): dirint = 'XYZ'.rfind(str.upper(landscape.pml_direction)) assert dirint <= 0, 'PML direction should be either X, Y or Z' if dirint == 0: direction = Meep.X if dirint == 1: direction = Meep.Y if dirint == 2: direction = Meep.Z pml = Meep.pml(landscape.pml_thickness, direction) else: pml = Meep.pml(landscape.pml_thickness) self.structure = Meep.structure(self.meepVol, Meep.EPS, pml, symmetry=symmetry_object) if self.is_nonlinear: LOG.debug("Meep node %i, setting chi3" % (self.node_nr)) self.chi3 = MeepChi3_2D(landscape.simulation_volume, self.meepVol) Meep.set_CHI3_Callback(self.chi3.__disown__()) self.structure.set_chi3(CHI3) LOG.debug("Meep node %i -Defining fields..." % (self.node_nr)) self.meep_fields = Meep.fields(self.structure)
def __init__(self,gridSizeX,gridSizeY,res,f,df,n_freqs = 1000,boundary_conditions = pml(1.0,Y),periodic_directions = [],bloch = vec(0.0,0.0),symmetry_direction = None,symmetry_val = complex(1.0),gridSizeZ = None): self.gridSizeX = gridSizeX self.gridSizeY = gridSizeY self.gridSizeZ = gridSizeZ self.res = res self.boundary_conditions = boundary_conditions self.fluxes = [] self.f = f self.df = df self.n_freqs = n_freqs self.symmetry_direction = symmetry_direction self.symmetry_val = symmetry_val self.periodic_directions = periodic_directions self.bloch = bloch self.my_source = None
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]))