def main(): # Run even and odd bands, outputting fields only at the K point: if loweps == 1.0: # we only have even/odd classification for symmetric structure ms.run_zeven(mpb.output_at_kpoint(K, mpb.output_hfield_z)) ms.run_zodd(mpb.output_at_kpoint(K, mpb.output_dfield_z)) else: ms.run(mpb.output_at_kpoint(K, mpb.output_hfield_z), mpb.display_zparities) ms.display_eigensolver_stats()
def test_diamond(self): from mpb_diamond import ms ms.deterministic = True ms.filename_prefix = self.filename_prefix ms.tolerance = 1e-12 ms.run( mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), mpb.fix_dfield_phase, mpb.output_dpwr)) expected_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.39455107895905156, mp.Vector3(0.25, 0.75, 0.5))), ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.3967658014080592, mp.Vector3(0.29999999999999993, 0.75, 0.45000000000000007))), ((0.4423707668172989, mp.Vector3(0.0, 0.5, 0.0)), (0.5955899630254676, mp.Vector3(0.0, 0.0, 0.0))), ((0.44355516512198145, mp.Vector3(0.0, 0.5, 0.0)), (0.5958191312898851, mp.Vector3(0.0, 0.0, 0.0))), ((0.5030135895148902, mp.Vector3(0.0, 0.6, 0.4)), (0.5958386856926985, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_brd, ms.band_range_data) ref_fn = 'diamond-dpwr.k06.b05.h5' ref_path = os.path.join(self.data_dir, ref_fn) res_path = re.sub('diamond', self.filename_prefix, ref_fn) self.compare_h5_files(ref_path, res_path)
def main(): # Compute the TM modes, outputting the Ez field in the *middle* of the # band. (In general, the guided mode in such an air defect may have # exited the gap by the time it reaches the edge of the Brillouin # zone at K_prime.) ms.run_tm(mpb.output_at_kpoint(k_points[len(k_points) // 2]), ms.fix_efield_phase, mpb.output_efield_z)
def diamond(): dpwr = [] def get_dpwr(ms, band): dpwr.append(ms.get_dpwr(band)) d_ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), get_dpwr)) md = mpb.MPBData(rectify=True, periods=2, resolution=32) converted_dpwr = [md.convert(d) for d in dpwr]
def diamond(): # Import the ModeSolver from the mpb_diamond.py example from mpb_diamond import ms as d_ms dpwr = [] def get_dpwr(ms, band): dpwr.append(ms.get_dpwr(band)) d_ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), get_dpwr)) md = mpb.MPBData(rectify=True, periods=2, resolution=32) converted_dpwr = [md.convert(d) for d in dpwr]
def test_line_defect(self): from mpb_line_defect import ms, k_points ms.deterministic = True ms.filename_prefix = self.filename_prefix ms.tolerance = 1e-12 ms.run_tm(mpb.output_at_kpoint(k_points[len(k_points) // 2]), mpb.fix_efield_phase, mpb.output_efield_z) ref_fn = 'line-defect-e.k04.b12.z.tm.h5' ref_path = os.path.join(self.data_dir, ref_fn) res_path = re.sub('line-defect', self.filename_prefix, ref_fn) self.compare_h5_files(ref_path, res_path)
def test_tri_rods(self): from mpb_tri_rods import ms ms.deterministic = True ms.tolerance = 1e-12 ms.filename_prefix = self.filename_prefix ms.run_tm( mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, mpb.output_efield_z)) ref_fn = 'tri-rods-e.k11.b08.z.tm.h5' ref_path = os.path.join(self.data_dir, ref_fn) res_path = re.sub('tri-rods', self.filename_prefix, ref_fn) self.compare_h5_files(ref_path, res_path) ms.run_te() expected_brd = [ ((0.0, mp.Vector3(0.0, 0.0, 0.0)), (0.49123581186757737, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.4730722390280754, mp.Vector3(0.0, 0.5, 0.0)), (0.5631059378714038, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.5631505198559038, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (0.7939289395839766, mp.Vector3(0.0, 0.0, 0.0))), ((0.7676614799039024, mp.Vector3(0.0, 0.5, 0.0)), (0.8214230044191525, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0))), ((0.865194814441525, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (1.0334130018594276, mp.Vector3(0.0, 0.0, 0.0))), ((0.8652307994936862, mp.Vector3(-0.3333333333333333, 0.3333333333333333, 0.0)), (1.0334230910419813, mp.Vector3(0.0, 0.0, 0.0))), ((1.021367669109368, mp.Vector3(0.0, 0.5, 0.0)), (1.115966990757518, mp.Vector3(0.0, 0.0, 0.0))), ((1.108662658537423, mp.Vector3(-0.26666666666666666, 0.26666666666666666, 0.0)), (1.1168107191255379, mp.Vector3(0.0, 0.0, 0.0))), ] self.check_band_range_data(expected_brd, ms.band_range_data)
def tri_rods(): # Import the ModeSolver defined in the mpb_tri_rods.py example from mpb_tri_rods import ms as tr_ms efields = [] # Band function to collect the efields def get_efields(tr_ms, band): efields.append(tr_ms.get_efield(band)) tr_ms.run_tm( mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, get_efields)) # Create an MPBData instance to transform the efields md = mpb.MPBData(rectify=True, resolution=32, periods=3) converted = [] for f in efields: # Get just the z component of the efields f = f[..., 0, 2] converted.append(md.convert(f)) tr_ms.run_te() eps = tr_ms.get_epsilon() plt.imshow(eps.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() md = mpb.MPBData(rectify=True, resolution=32, periods=3) rectangular_data = md.convert(eps) plt.imshow(rectangular_data.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() for i, f in enumerate(converted): plt.subplot(331 + i) plt.contour(rectangular_data.T, cmap='binary') plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9) plt.axis('off') plt.show()
def tri_rods(): # Import the ModeSolver defined in the mpb_tri_rods.py example from mpb_tri_rods import ms as tr_ms efields = [] # Band function to collect the efields def get_efields(tr_ms, band): efields.append(tr_ms.get_efield(band)) tr_ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, get_efields)) # Create an MPBData instance to transform the efields md = mpb.MPBData(rectify=True, resolution=32, periods=3) converted = [] for f in efields: # Get just the z component of the efields f = f[..., 0, 2] converted.append(md.convert(f)) tr_ms.run_te() eps = tr_ms.get_epsilon() plt.imshow(eps.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() md = mpb.MPBData(rectify=True, resolution=32, periods=3) rectangular_data = md.convert(eps) plt.imshow(rectangular_data.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() for i, f in enumerate(converted): plt.subplot(331 + i) plt.contour(rectangular_data.T, cmap='binary') plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9) plt.axis('off') plt.show()
def main(): efields = [] # Band function to collect the efields def get_efields(ms, band): efields.append(ms.get_efield(band, output=True)) ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, get_efields)) # Create an MPBData instance to transform the efields md = mpb.MPBData(ms.get_lattice(), rectify=True, resolution=32, periods=3) converted = [] for f in efields: # Get just the z component of the efields f = f[:, :, 2] converted.append(md.convert(f, ms.k_points[10])) ms.run_te() eps = ms.get_epsilon() plt.imshow(eps.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() md = mpb.MPBData(ms.get_lattice(), rectify=True, resolution=32, periods=3) rectangular_data = md.convert(eps) plt.imshow(rectangular_data.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() for i, f in enumerate(converted): plt.subplot(331 + i) plt.contour(rectangular_data.T, cmap='binary') plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9) plt.axis('off') plt.show()
# ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, # mpb.output_efield_z)) ms.run_te() md = mpb.MPBData(rectify=True, periods=3, resolution=32) eps = ms.get_epsilon() converted_eps = md.convert(eps) efields = [] def get_efields(ms, band): efields.append(ms.get_efield(band, bloch_phase=True)) ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, get_efields)) # Create an MPBData instance to transform the efields md = mpb.MPBData(rectify=True, resolution=32, periods=3) converted = [] for f in efields: # Get just the z component of the efields f = f[..., 0, 2] converted.append(md.convert(f)) smooth_eps = gaussian_filter(converted_eps.T, sigma=1) for i, f in enumerate(converted): plt.subplot(331 + i) plt.contour(smooth_eps, levels=[0,1,2,3], cmap='binary') plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9)
def main(): # run calculation, outputting electric_field energy density at the U point: ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), mpb.output_dpwr)) ms.display_kpoint_data("./mpb_diamond", ms.band_range_data) plt.show()
k_points=k_points, geometry=geometry, geometry_lattice=geometry_lattice, resolution=resolution) print_heading("Square lattice of rods: TE bands") ms.run_te() print_heading("Square lattice of rods: TM bands") ms.run_tm() print_heading("Square lattice of rods: TM, w/efield") ms.run_tm(mpb.output_efield_z) print_heading("Square lattice of rods: TE, w/hfield & dpwr") ms.run_te(mpb.output_at_kpoint(mp.Vector3(0.5), mpb.output_hfield_z, mpb.output_dpwr)) # Bands of a Triangular Lattice print_heading("Triangular lattice of rods in air") ms.geometry_lattice = mp.Lattice(size=mp.Vector3(1, 1), basis1=mp.Vector3(math.sqrt(3) / 2, 0.5), basis2=mp.Vector3(math.sqrt(3) / 2, -0.5)) ms.k_points = [mp.Vector3(), # Gamma mp.Vector3(y=0.5), # M mp.Vector3(-1 / 3, 1 / 3), # K mp.Vector3()] # Gamma ms.k_points = mp.interpolate(4, k_points)
def main(): # run calculation, outputting electric_field energy density at the U point: ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), mpb.output_dpwr))
k_points = [ mp.Vector3(-1. / 3, 1. / 3), # K mp.Vector3(), # Gamma mp.Vector3(y=0.5), # M mp.Vector3(-1. / 3, 1. / 3) # K ] k_points = mp.interpolate(50, k_points) ms = mpb.ModeSolver(geometry=geometry, geometry_lattice=geometry_lattice, k_points=k_points, resolution=resolution, num_bands=num_bands) ms.run_tm( mpb.output_at_kpoint(mp.Vector3(-1. / 3, 1. / 3), mpb.fix_efield_phase, mpb.output_efield_z)) tm_freqs = ms.all_freqs tm_gaps = ms.gap_list ms.run_te() te_freqs = ms.all_freqs te_gaps = ms.gap_list md = mpb.MPBData(rectify=True, periods=3, resolution=32) eps = ms.get_epsilon() converted_eps = md.convert(eps) plt.imshow(converted_eps.T, interpolation='spline36', cmap='binary') plt.axis('off') plt.show() pltd(tm_freqs, te_freqs, tm_gaps, te_gaps)
] #how many points to solve for between each specified point above k_points = mp.interpolate(kpt_resolution, k_points) #geometry_center #ModeSolver documentation: https://mpb.readthedocs.io/en/latest/Python_User_Interface/ ms = mpb.ModeSolver( geometry=geometry, geometry_lattice=geometry_lattice, k_points=k_points, resolution=resolution, num_bands=num_bands, ) #https://mpb.readthedocs.io/en/latest/Python_User_Interface/ ms.run_yeven(mpb.output_at_kpoint(mp.Vector3(0.5,0,0), mpb.fix_efield_phase, mpb.output_efield_z)) #This will output the electric field at the xpoint only tm_freqs = ms.all_freqs tm_gaps = ms.gap_list ms.run_yodd() te_freqs = ms.all_freqs te_gaps = ms.gap_list ###plot geom md = mpb.MPBData(rectify=True, periods=1, resolution=resolution) eps = ms.get_epsilon() converted_eps = md.convert(eps) print(np.shape(converted_eps)) np_converted_eps = np.array(converted_eps)
geometry=geometry, geometry_lattice=geometry_lattice, resolution=resolution) print_heading("Square lattice of rods: TE bands") ms.run_te() print_heading("Square lattice of rods: TM bands") ms.run_tm() print_heading("Square lattice of rods: TM, w/efield") ms.run_tm(mpb.output_efield_z) print_heading("Square lattice of rods: TE, w/hfield & dpwr") ms.run_te( mpb.output_at_kpoint(mp.Vector3(0.5), mpb.output_hfield_z, mpb.output_dpwr)) # Bands of a Triangular Lattice print_heading("Triangular lattice of rods in air") ms.geometry_lattice = mp.Lattice(size=mp.Vector3(1, 1), basis1=mp.Vector3(math.sqrt(3) / 2, 0.5), basis2=mp.Vector3(math.sqrt(3) / 2, -0.5)) ms.k_points = [ mp.Vector3(), # Gamma mp.Vector3(y=0.5), # M mp.Vector3(-1 / 3, 1 / 3), # K mp.Vector3() ] # Gamma
def main(): ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase, mpb.output_efield_z)) ms.run_te()
def main(): ms.run_tm( mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), ms.fix_efield_phase, mpb.output_efield_z)) ms.run_te()
resolution = 32 target_freq = (0.229 + 0.307) / 2 ms = mpb.ModeSolver(num_bands=num_bands, k_points=k_points, geometry=geometry, geometry_lattice=geometry_lattice, resolution=resolution, default_material=default_material, ) efields = [] def get_efields(ms, band): efields.append(ms.get_efield(band, bloch_phase=False)) ms.run_tm(mpb.output_at_kpoint(k_points[0]), mpb.fix_efield_phase, get_efields) defect_modes_idx = [] for i, freq in enumerate(ms.get_freqs()): if 0.229 < freq < 0.307: defect_modes_idx.append(i) ms.get_dfield(i+1, bloch_phase=False) ms.compute_field_energy() energy = ms.compute_energy_in_objects([defect]) energy2 = ms.compute_energy_in_dielectric(11, 13) print(i, freq, energy, energy2) """ D-energy-components:, 1, 25, 0, 0, 1 25 0.23522156656345886 0.028740036937926903