import meep as mp
from meep import mpb
import numpy as np
from matplotlib import pyplot as plt
# Then the wavelength
omega = 1/0.78
material_SiN=mp.Medium(index=2.02)
width_guide=0.65
height_guide=0.25
resolution=200
size_cal_y=2
size_cal_z=2
geometry = [mp.Block(material=material_SiN,
size=mp.Vector3(mp.inf,width_guide, height_guide),
center=mp.Vector3(0, 0, height_guide/2))]
geometry_lattice = mp.Lattice(size=mp.Vector3(0, size_cal_y, size_cal_z))
num_modes = 4
ms = mpb.ModeSolver(
geometry_lattice = geometry_lattice,
geometry = geometry,
resolution = resolution,
num_bands = num_modes
)
E = []
store_fields = lambda ms_temp, mode: E.append(ms_temp.get_efield(which_band=mode,bloch_phase=False))
k = ms.find_k(
mp.NO_PARITY,
omega, # omega
1, # band_min
num_modes, # band_max
mp.Vector3(1,0,0), # korig_and_kdir
1e-4, # tol
omega * 2, # kmag_guess
omega * 0.1, # kmag_min
omega * 2, # kmag_max
store_fields, # band_funcs
)
neff=k[0]/omega
eps = ms.get_epsilon()
eps_arr=np.transpose(np.array(eps))
Initializing eigensolver data Computing 4 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 4 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<2.564102564102564, 0.0, 0.0> elapsed time for initialization: 0.14168453216552734 solve_kpoint (2.5641,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3, band 4 Solving for bands 1 to 4... near maximum in trace linmin: converged after 8 iterations. iteration 1: trace = 123.8236841562834 (198.109% change) linmin: converged after 8 iterations. iteration 2: trace = 22.1922958630927 (139.206% change) linmin: converged after 6 iterations. iteration 3: trace = 13.14670269403391 (51.1933% change) linmin: converged after 9 iterations. iteration 4: trace = 10.93982990832828 (18.3245% change) linmin: converged after 5 iterations. iteration 5: trace = 10.32095280136335 (5.82177% change) linmin: converged after 4 iterations. iteration 6: trace = 10.11720834355889 (1.99377% change) linmin: converged after 3 iterations. iteration 7: trace = 10.05301450594007 (0.636521% change) linmin: converged after 3 iterations. iteration 8: trace = 10.02997188847071 (0.229474% change) linmin: converged after 4 iterations. iteration 9: trace = 10.02241002050792 (0.0754211% change) linmin: converged after 4 iterations. iteration 10: trace = 10.0204260481583 (0.0197973% change) linmin: converged after 4 iterations. iteration 11: trace = 10.01979200852422 (0.00632767% change) linmin: converged after 2 iterations. iteration 12: trace = 10.01960397508262 (0.00187664% change) linmin: converged after 2 iterations. iteration 13: trace = 10.01955723518683 (0.000466486% change) linmin: converged after 2 iterations. iteration 14: trace = 10.01954390889984 (0.000133003% change) linmin: converged after 2 iterations. iteration 15: trace = 10.01954110433259 (2.7991e-05% change) linmin: converged after 2 iterations. iteration 16: trace = 10.01954031838549 (7.84414e-06% change) Finished solving for bands 1 to 4 after 16 iterations. freqs:, 1, 2.5641, 0, 0, 2.5641, 1.473, 1.57, 1.60949, 1.67167 elapsed time for k point: 8.525080442428589 total elapsed time for run: 8.667009353637695 done find-k 4 at 2.564102564102564: 0.38961425712951425 Initializing eigensolver data Computing 4 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 4 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Solving for band polarization: . 1 k-points Vector3<1.6085836858086868, 0.0, 0.0> elapsed time for initialization: 0.10355925559997559 solve_kpoint (1.60858,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3, band 4 Solving for bands 1 to 4... linmin: converged after 4 iterations. iteration 1: trace = 5.620515954264453 (5.21607% change) linmin: converged after 4 iterations. iteration 2: trace = 5.593641260671144 (0.479299% change) linmin: converged after 4 iterations. iteration 3: trace = 5.589678066488134 (0.0708769% change) linmin: converged after 2 iterations. iteration 4: trace = 5.58917700162418 (0.00896451% change) linmin: converged after 3 iterations. iteration 5: trace = 5.589105113672728 (0.00128621% change) linmin: converged after 2 iterations. iteration 6: trace = 5.58908564930478 (0.000348256% change) linmin: converged after 2 iterations. iteration 7: trace = 5.589081742743058 (6.98963e-05% change) linmin: converged after 2 iterations. iteration 8: trace = 5.589081072564559 (1.19909e-05% change) linmin: converged after 2 iterations. iteration 9: trace = 5.589080992867364 (1.42594e-06% change) Finished solving for bands 1 to 4 after 9 iterations. freqs:, 1, 1.60858, 0, 0, 1.60858, 1.03742, 1.16614, 1.21892, 1.2912 elapsed time for k point: 4.006057024002075 total elapsed time for run: 4.1098034381866455 done find-k 4 at 1.6085836858086868: 0.009146029919003595 Initializing eigensolver data Computing 4 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 4 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Solving for band polarization: . 1 k-points Vector3<1.5855976788130137, 0.0, 0.0> elapsed time for initialization: 0.09824061393737793 solve_kpoint (1.5856,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3, band 4 Solving for bands 1 to 4... linmin: converged after 2 iterations. iteration 1: trace = 5.49916716623316 (0.00739343% change) linmin: converged after 2 iterations. iteration 2: trace = 5.499126734330409 (0.00073524% change) linmin: converged after 2 iterations. iteration 3: trace = 5.499120792596848 (0.000108049% change) linmin: converged after 2 iterations. iteration 4: trace = 5.499120123555256 (1.21663e-05% change) linmin: converged after 2 iterations. iteration 5: trace = 5.499120034302638 (1.62303e-06% change) Finished solving for bands 1 to 4 after 5 iterations. freqs:, 1, 1.5856, 0, 0, 1.5856, 1.02707, 1.15633, 1.20976, 1.28204 elapsed time for k point: 2.365442991256714 total elapsed time for run: 2.4638683795928955 done find-k 4 at 1.5855976788130137: -1.1605675625636636e-05 find-k 3 at 1.5855976788130137: -0.07229303800579956 (cached) Initializing eigensolver data Computing 3 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 3 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<1.7668680765778708, 0.0, 0.0> elapsed time for initialization: 0.13820791244506836 solve_kpoint (1.76687,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3 Solving for bands 1 to 3... near maximum in trace linmin: converged after 7 iterations. iteration 1: trace = 50.77168867738905 (198.965% change) linmin: converged after 8 iterations. iteration 2: trace = 8.920812348584601 (140.222% change) linmin: converged after 8 iterations. iteration 3: trace = 5.682360689460086 (44.3527% change) linmin: converged after 8 iterations. iteration 4: trace = 4.80493231868268 (16.7332% change) linmin: converged after 5 iterations. iteration 5: trace = 4.613078128814662 (4.0742% change) linmin: converged after 4 iterations. iteration 6: trace = 4.555763442860966 (1.25021% change) linmin: converged after 4 iterations. iteration 7: trace = 4.515287213824982 (0.892426% change) linmin: converged after 5 iterations. iteration 8: trace = 4.464593417027181 (1.12905% change) linmin: converged after 5 iterations. iteration 9: trace = 4.419306878843305 (1.01952% change) linmin: converged after 4 iterations. iteration 10: trace = 4.401123514211577 (0.412301% change) linmin: converged after 3 iterations. iteration 11: trace = 4.39570284591592 (0.123241% change) linmin: converged after 3 iterations. iteration 12: trace = 4.394279968980154 (0.032375% change) linmin: converged after 4 iterations. iteration 13: trace = 4.393926677414402 (0.00804013% change) linmin: converged after 2 iterations. iteration 14: trace = 4.393822214996916 (0.00237746% change) linmin: converged after 2 iterations. iteration 15: trace = 4.393789685024521 (0.00074036% change) linmin: converged after 2 iterations. iteration 16: trace = 4.393780502372781 (0.000208992% change) linmin: converged after 2 iterations. iteration 17: trace = 4.393777975784976 (5.75037e-05% change) linmin: converged after 2 iterations. iteration 18: trace = 4.393777215244546 (1.73095e-05% change) linmin: converged after 2 iterations. iteration 19: trace = 4.393776792077595 (9.63105e-06% change) Finished solving for bands 1 to 3 after 19 iterations. freqs:, 1, 1.76687, 0, 0, 1.76687, 1.10883, 1.23313, 1.28206 elapsed time for k point: 5.638807773590088 total elapsed time for run: 5.77721381187439 done find-k 3 at 1.7668680765778708: 8.034289205260947e-06 find-k 2 at 1.7668680765778708: -0.04892332545745148 (cached) Initializing eigensolver data Computing 2 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 2 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<1.883034741981684, 0.0, 0.0> elapsed time for initialization: 0.1282651424407959 solve_kpoint (1.88303,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2 Solving for bands 1 to 2... near maximum in trace linmin: converged after 7 iterations. iteration 1: trace = 39.92962801489121 (198.785% change) linmin: converged after 9 iterations. iteration 2: trace = 6.239805624940822 (145.94% change) linmin: converged after 8 iterations. iteration 3: trace = 3.353883266937967 (60.1629% change) linmin: converged after 5 iterations. iteration 4: trace = 3.082347003401539 (8.43774% change) linmin: converged after 3 iterations. iteration 5: trace = 3.031963597855756 (1.64805% change) linmin: converged after 3 iterations. iteration 6: trace = 3.009263085375187 (0.75152% change) linmin: converged after 4 iterations. iteration 7: trace = 3.001635429228531 (0.253794% change) linmin: converged after 4 iterations. iteration 8: trace = 2.997581145733743 (0.13516% change) linmin: converged after 4 iterations. iteration 9: trace = 2.994701135141014 (0.096124% change) linmin: converged after 4 iterations. iteration 10: trace = 2.993425742637689 (0.0425974% change) linmin: converged after 4 iterations. iteration 11: trace = 2.992762203088572 (0.022169% change) linmin: converged after 4 iterations. iteration 12: trace = 2.992426078620459 (0.0112319% change) linmin: converged after 2 iterations. iteration 13: trace = 2.992352814075972 (0.00244836% change) linmin: converged after 2 iterations. iteration 14: trace = 2.992332730104535 (0.000671179% change) linmin: converged after 2 iterations. iteration 15: trace = 2.992325052943611 (0.000256561% change) linmin: converged after 2 iterations. iteration 16: trace = 2.992323586537159 (4.90056e-05% change) linmin: converged after 2 iterations. iteration 17: trace = 2.992323305017691 (9.40806e-06% change) Finished solving for bands 1 to 2 after 17 iterations. freqs:, 1, 1.88303, 0, 0, 1.88303, 1.16142, 1.28196 elapsed time for k point: 4.557207345962524 total elapsed time for run: 4.685705184936523 done find-k 2 at 1.883034741981684: -8.652802266162496e-05 Initializing eigensolver data Computing 2 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 2 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Solving for band polarization: . 1 k-points Vector3<1.8832408018035474, 0.0, 0.0> elapsed time for initialization: 0.10942387580871582 solve_kpoint (1.88324,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2 Solving for bands 1 to 2... linmin: converged after 2 iterations. iteration 1: trace = 2.992762167827654 (1.52054e-06% change) Finished solving for bands 1 to 2 after 1 iterations. freqs:, 1, 1.88324, 0, 0, 1.88324, 1.16151, 1.28205 elapsed time for k point: 0.4207158088684082 total elapsed time for run: 0.5303900241851807 done find-k 2 at 1.8832408018035474: -9.201315043227964e-09 find-k 1 at 2.564102564102564: 0.19094603989606806 (cached) Initializing eigensolver data Computing 1 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 1 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<2.150178660181947, 0.0, 0.0> elapsed time for initialization: 0.12140369415283203 solve_kpoint (2.15018,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1 Solving for bands 1 to 1... near maximum in trace linmin: converged after 8 iterations. iteration 1: trace = 25.22521061540375 (198.48% change) linmin: converged after 9 iterations. iteration 2: trace = 4.32810355628151 (141.42% change) linmin: converged after 8 iterations. iteration 3: trace = 2.29368538441669 (61.4462% change) linmin: converged after 7 iterations. iteration 4: trace = 1.891852360526365 (19.201% change) linmin: converged after 6 iterations. iteration 5: trace = 1.71181419123749 (9.99194% change) linmin: converged after 5 iterations. iteration 6: trace = 1.664165749529034 (2.82279% change) linmin: converged after 4 iterations. iteration 7: trace = 1.650163075661886 (0.844978% change) linmin: converged after 3 iterations. iteration 8: trace = 1.647018000559876 (0.190774% change) linmin: converged after 4 iterations. iteration 9: trace = 1.646350503407761 (0.0405358% change) linmin: converged after 4 iterations. iteration 10: trace = 1.646121106442472 (0.0139346% change) linmin: converged after 2 iterations. iteration 11: trace = 1.646062502264618 (0.0035602% change) linmin: converged after 2 iterations. iteration 12: trace = 1.646052302163168 (0.000619669% change) linmin: converged after 2 iterations. iteration 13: trace = 1.646050008696941 (0.000139331% change) linmin: converged after 2 iterations. iteration 14: trace = 1.646049179301168 (5.0387e-05% change) linmin: converged after 2 iterations. iteration 15: trace = 1.646048855719127 (1.96581e-05% change) linmin: converged after 2 iterations. iteration 16: trace = 1.646048792973986 (3.81186e-06% change) Finished solving for bands 1 to 1 after 16 iterations. freqs:, 1, 2.15018, 0, 0, 2.15018, 1.28298 elapsed time for k point: 2.4967117309570312 total elapsed time for run: 2.6183736324310303 done find-k 1 at 2.150178660181947: 0.0009330487080536631 Initializing eigensolver data Computing 1 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 1 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Solving for band polarization: . 1 k-points Vector3<2.1481355705124185, 0.0, 0.0> elapsed time for initialization: 0.1273045539855957 solve_kpoint (2.14814,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1 Solving for bands 1 to 1... linmin: converged after 2 iterations. iteration 1: trace = 1.643655557254352 (2.46194e-05% change) linmin: converged after 1 iterations. iteration 2: trace = 1.643655542756779 (8.82032e-07% change) Finished solving for bands 1 to 1 after 2 iterations. freqs:, 1, 2.14814, 0, 0, 2.14814, 1.28205 elapsed time for k point: 0.38402462005615234 total elapsed time for run: 0.5115735530853271 done find-k 1 at 2.1481355705124185: 2.064950255231679e-08 Initializing eigensolver data Computing 1 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 1 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Solving for band polarization: . 1 k-points Vector3<2.148135525294045, 0.0, 0.0> elapsed time for initialization: 0.125685453414917 solve_kpoint (2.14814,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1 Solving for bands 1 to 1... linmin: converged after 2 iterations. iteration 1: trace = 1.64365548756432 (1.36588e-07% change) Finished solving for bands 1 to 1 after 1 iterations. freqs:, 1, 2.14814, 0, 0, 2.14814, 1.28205 elapsed time for k point: 0.22940921783447266 total elapsed time for run: 0.38521337509155273 done Initializing eigensolver data Computing 2 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 2 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<1.883240823715691, 0.0, 0.0> elapsed time for initialization: 0.16054463386535645 solve_kpoint (1.88324,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2 Solving for bands 1 to 2... near maximum in trace linmin: converged after 7 iterations. iteration 1: trace = 37.94487296954814 (198.844% change) linmin: converged after 9 iterations. iteration 2: trace = 6.778541581288811 (139.374% change) linmin: converged after 5 iterations. iteration 3: trace = 3.860182586071177 (54.863% change) linmin: converged after 5 iterations. iteration 4: trace = 3.146405014617289 (20.3745% change) linmin: converged after 4 iterations. iteration 5: trace = 3.057946464808898 (2.8515% change) linmin: converged after 3 iterations. iteration 6: trace = 3.025047826851377 (1.08166% change) linmin: converged after 3 iterations. iteration 7: trace = 3.010637461589048 (0.477506% change) linmin: converged after 3 iterations. iteration 8: trace = 3.004579953637398 (0.201406% change) linmin: converged after 3 iterations. iteration 9: trace = 2.998160213746782 (0.213894% change) linmin: converged after 3 iterations. iteration 10: trace = 2.994400698378714 (0.125473% change) linmin: converged after 4 iterations. iteration 11: trace = 2.993204363481516 (0.0399604% change) linmin: converged after 4 iterations. iteration 12: trace = 2.992834872512641 (0.0123451% change) linmin: converged after 2 iterations. iteration 13: trace = 2.992775677379295 (0.00197791% change) linmin: converged after 2 iterations. iteration 14: trace = 2.992766349731989 (0.000311673% change) linmin: converged after 2 iterations. iteration 15: trace = 2.992763802627669 (8.51087e-05% change) linmin: converged after 2 iterations. iteration 16: trace = 2.992762756206634 (3.4965e-05% change) linmin: converged after 2 iterations. iteration 17: trace = 2.992762296027167 (1.53764e-05% change) linmin: converged after 2 iterations. iteration 18: trace = 2.992762207729719 (2.95037e-06% change) Finished solving for bands 1 to 2 after 18 iterations. freqs:, 1, 1.88324, 0, 0, 1.88324, 1.16151, 1.28205 elapsed time for k point: 5.051982879638672 total elapsed time for run: 5.242172956466675 done Initializing eigensolver data Computing 3 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 3 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<1.7668479781029456, 0.0, 0.0> elapsed time for initialization: 0.16875815391540527 solve_kpoint (1.76685,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3 Solving for bands 1 to 3... near maximum in trace linmin: converged after 7 iterations. iteration 1: trace = 48.94944154456752 (199.003% change) linmin: converged after 8 iterations. iteration 2: trace = 8.896484416282034 (138.482% change) linmin: converged after 5 iterations. iteration 3: trace = 5.514742304148349 (46.9321% change) linmin: converged after 9 iterations. iteration 4: trace = 4.638735125552603 (17.2553% change) linmin: converged after 4 iterations. iteration 5: trace = 4.48761024124924 (3.31184% change) linmin: converged after 4 iterations. iteration 6: trace = 4.446201346889611 (0.927015% change) linmin: converged after 4 iterations. iteration 7: trace = 4.420838844393151 (0.572062% change) linmin: converged after 4 iterations. iteration 8: trace = 4.404877332480305 (0.361705% change) linmin: converged after 3 iterations. iteration 9: trace = 4.396759965953082 (0.184451% change) linmin: converged after 3 iterations. iteration 10: trace = 4.394382572200556 (0.0540861% change) linmin: converged after 2 iterations. iteration 11: trace = 4.39387123150108 (0.0116369% change) linmin: converged after 2 iterations. iteration 12: trace = 4.393762694741326 (0.00247022% change) linmin: converged after 2 iterations. iteration 13: trace = 4.393730176976127 (0.000740092% change) linmin: converged after 2 iterations. iteration 14: trace = 4.39371870333676 (0.000261137% change) linmin: converged after 2 iterations. iteration 15: trace = 4.393715944962316 (6.278e-05% change) linmin: converged after 2 iterations. iteration 16: trace = 4.393715119395464 (1.87897e-05% change) linmin: converged after 2 iterations. iteration 17: trace = 4.393714928292733 (4.34946e-06% change) Finished solving for bands 1 to 3 after 17 iterations. freqs:, 1, 1.76685, 0, 0, 1.76685, 1.10882, 1.23312, 1.28205 elapsed time for k point: 4.447287559509277 total elapsed time for run: 4.634722709655762 done Initializing eigensolver data Computing 4 bands with 1e-07 tolerance Working in 3 dimensions. Grid size is 1 x 400 x 400. Solving for 4 bands at a time. Creating Maxwell data... Mesh size is 3. Lattice vectors: (1, 0, 0) (0, 2, 0) (0, 0, 2) Cell volume = 4 Reciprocal lattice vectors (/ 2 pi): (1, -0, 0) (-0, 0.5, -0) (0, -0, 0.5) Geometric objects: block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects) Initializing epsilon function... Allocating fields... Solving for band polarization: . Initializing fields to random numbers... 1 k-points Vector3<1.5856267714077628, 0.0, 0.0> elapsed time for initialization: 0.15445685386657715 solve_kpoint (1.58563,0,0): freqs:, k index, k1, k2, k3, kmag/2pi, band 1, band 2, band 3, band 4 Solving for bands 1 to 4... near maximum in trace linmin: converged after 7 iterations. iteration 1: trace = 55.7643588457486 (199.145% change) linmin: converged after 8 iterations. iteration 2: trace = 9.792654661877407 (140.25% change) linmin: converged after 6 iterations. iteration 3: trace = 6.469050983268636 (40.8764% change) linmin: converged after 6 iterations. iteration 4: trace = 5.763998594183863 (11.527% change) linmin: converged after 4 iterations. iteration 5: trace = 5.578503085870132 (3.2708% change) linmin: converged after 4 iterations. iteration 6: trace = 5.520616850529097 (1.04308% change) linmin: converged after 4 iterations. iteration 7: trace = 5.504189547781465 (0.298006% change) linmin: converged after 4 iterations. iteration 8: trace = 5.500322161137438 (0.0702873% change) linmin: converged after 4 iterations. iteration 9: trace = 5.499468539851861 (0.0155207% change) linmin: converged after 2 iterations. iteration 10: trace = 5.499286533980837 (0.00330957% change) linmin: converged after 2 iterations. iteration 11: trace = 5.499243020179187 (0.000791266% change) linmin: converged after 2 iterations. iteration 12: trace = 5.499235310382385 (0.000140198% change) linmin: converged after 2 iterations. iteration 13: trace = 5.499233865572055 (2.62729e-05% change) linmin: converged after 2 iterations. iteration 14: trace = 5.499233551765768 (5.70636e-06% change) Finished solving for bands 1 to 4 after 14 iterations. freqs:, 1, 1.58563, 0, 0, 1.58563, 1.02709, 1.15634, 1.20977, 1.28205 elapsed time for k point: 5.2234861850738525 total elapsed time for run: 5.395794630050659 done kvals:, 1.282051282051282, 1, 4, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.148135525294045, 1.883240823715691, 1.7668479781029456, 1.5856267714077628 epsilon: 1-4.0804, mean 1.12514, harm. mean 1.03219, 4.17563% > 1, 4.0625% "fill"
# %%
x_list=np.linspace(-size_cal_y/2,size_cal_y/2,resolution*2)
y_list=np.linspace(-size_cal_z/2,size_cal_z/2,resolution*2)
x_grid,y_grid=np.meshgrid(x_list,y_list)
plt.figure(figsize=(12,4))
# Plot the E fields
for mode in range(num_modes):
Ex=np.squeeze(E[mode][:,:,0,1]).transpose()
print('Current band: {}'.format(mode+1))
plt.subplot(1,num_modes,1+mode)
plt.pcolormesh(x_grid,y_grid,eps.transpose(), cmap='binary')
plt.pcolormesh(x_grid,y_grid,np.abs(Ex), cmap='jet', alpha=0.9)
plt.axis('off')
st_title='Ex of mode '+str(mode+1)+' from MPB neff=' +str('%.2f' %(k[mode]/omega))
plt.title(st_title)
plt.tight_layout()
plt.savefig('SimulatedFieldMPB.png')
plt.show()
Current band: 1 Current band: 2 Current band: 3 Current band: 4
<ipython-input-10-f30ee5293a99>:12: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolormesh(x_grid,y_grid,eps.transpose(), cmap='binary') <ipython-input-10-f30ee5293a99>:13: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolormesh(x_grid,y_grid,np.abs(Ex), cmap='jet', alpha=0.9)
and the effective index is as follows
neff=np.array(k)/omega
print(neff)
we can also simualte the mode profile in meep by creating a simulation project. The geometery can be the same
import meep as mp
from meep import mpb
import numpy as np
from matplotlib import pyplot as plt
#Then the wavelength
omega = 1/0.78
material_SiN=mp.Medium(index=2.02)
width_guide=0.65
height_guide=0.25
resolution=200
size_cal_y=2
size_cal_z=2
geometry = [mp.Block(material=material_SiN,
size=mp.Vector3(mp.inf,width_guide, height_guide),
center=mp.Vector3(0, 0, height_guide/2))]
geometry_lattice = mp.Lattice(size=mp.Vector3(0, size_cal_y, size_cal_z))
num_modes = 4
dpml = 0.5
pml_layers = [mp.PML(dpml)]
sim = mp.Simulation(cell_size=mp.Vector3(0,size_cal_y+dpml*2,size_cal_z+dpml*2),
resolution=resolution,
geometry=geometry,
boundary_layers=pml_layers,)
sim.init_sim()
where = mp.Volume(center=mp.Vector3(), size=mp.Vector3(0,size_cal_y,size_cal_y))
direction = mp.X
kpoint = mp.Vector3(1,0,0)
x_list=np.linspace(-size_cal_y/2,size_cal_y/2,resolution*2)
y_list=np.linspace(-size_cal_z/2,size_cal_z/2,resolution*2)
x_grid,y_grid=np.meshgrid(x_list,y_list)
pos_extract=mp.Vector3(np.ravel(x_grid)*0,np.ravel(x_grid),np.ravel(y_grid))
Ex_mp=np.zeros((resolution*2,resolution*2,num_modes),dtype=complex)
# Extract the field in a loop
num_modes=4
k_meep=np.zeros(num_modes)
for mode in range(num_modes):
print('Simultion Mode'+str(mode+1))
ed = sim.get_eigenmode(omega, direction, where, mode+1, kpoint, eig_vol=None, match_frequency=True,
parity=mp.NO_PARITY, resolution=resolution, eigensolver_tol=1e-12)
k_meep[mode]=ed.k[0]
for l in range(resolution*2):
for m in range(resolution*2):
Ex_mp[l,m,mode]=ed.amplitude(mp.Vector3(0,x_list[m],y_list[l]),1)
----------- Initializing structure... time for choose_chunkdivision = 0.000433207 s Working in 3D dimensions. Computational cell is 0.005 x 3 x 3 with resolution 200 block, center = (0,0,0.125) size (1e+20,0.65,0.25) axes (1,0,0), (0,1,0), (0,0,1) dielectric constant epsilon diagonal = (4.0804,4.0804,4.0804) time for set_epsilon = 1.30244 s ----------- Simultion Mode1 MPB solved for frequency_1(1,0,0) = 0.762832 after 18 iters MPB solved for frequency_1(2.12344,0,0) = 1.27078 after 10 iters MPB solved for frequency_1(2.14814,0,0) = 1.28205 after 8 iters MPB solved for frequency_1(2.14813,0,0) = 1.28205 after 2 iters Dominant planewave for band 1: (2.148132,-0.000000,0.000000) Simultion Mode2 MPB solved for frequency_2(1,0,0) = 0.88031 after 26 iters MPB solved for frequency_2(1.70554,0,0) = 1.20726 after 12 iters MPB solved for frequency_2(1.88255,0,0) = 1.28176 after 11 iters MPB solved for frequency_2(1.88324,0,0) = 1.28205 after 6 iters MPB solved for frequency_2(1.88324,0,0) = 1.28205 after 1 iters Dominant planewave for band 2: (1.883241,-0.000000,0.000000) Simultion Mode3 MPB solved for frequency_3(1,0,0) = 0.955496 after 27 iters MPB solved for frequency_3(1.61528,0,0) = 1.2216 after 13 iters MPB solved for frequency_3(1.76695,0,0) = 1.2821 after 11 iters MPB solved for frequency_3(1.76683,0,0) = 1.28205 after 5 iters MPB solved for frequency_3(1.76683,0,0) = 1.28205 after 1 iters Dominant planewave for band 3: (1.766830,-1.000000,0.000000) Simultion Mode4 MPB solved for frequency_4(1,0,0) = 1.01268 after 59 iters MPB solved for frequency_4(1.28506,0,0) = 1.15812 after 91 iters MPB solved for frequency_4(1.57064,0,0) = 1.27606 after 13 iters MPB solved for frequency_4(1.58562,0,0) = 1.28205 after 10 iters MPB solved for frequency_4(1.58564,0,0) = 1.28205 after 3 iters Dominant planewave for band 4: (1.585638,1.000000,0.000000)
Be careful that we need extract the field properties via some methods.
plt.figure(figsize=(14,4))
for mode in range(num_modes):
print('Current band: {}'.format(mode+1))
plt.subplot(1,num_modes,1+mode)
plt.pcolormesh(x_grid,y_grid,np.abs(Ex_mp[:,:,mode]), cmap='jet', alpha=0.9)
plt.axis('off')
st_title='Ex of mode '+str(mode+1)+' from MEEP neff=' +str('%.2f' %(k_meep[mode]/omega))
plt.title(st_title)
plt.tight_layout()
plt.savefig('SimulatedFieldMeep.png')
plt.show()
Current band: 1 Current band: 2 Current band: 3 Current band: 4
<ipython-input-7-fbaa5e69185e>:5: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolormesh(x_grid,y_grid,np.abs(Ex_mp[:,:,mode]), cmap='jet', alpha=0.9)
plt.figure(figsize=(12,8))
for mode in range(num_modes):
print('Current band: {}'.format(mode+1))
plt.subplot(2,num_modes,1+mode)
plt.pcolormesh(x_grid,y_grid,np.abs(Ex_mp[:,:,mode]), cmap='jet', alpha=0.9)
plt.axis('off')
st_title='Ex of mode '+str(mode+1)+' from MEEP neff=' +str('%.2f' %(k_meep[mode]/omega))
plt.title(st_title)
for mode in range(num_modes):
Ex=np.squeeze(E[mode][:,:,0,1]).transpose()
print('Current band: {}'.format(mode+1))
plt.subplot(2,num_modes,1+mode+num_modes)
plt.pcolormesh(x_grid,y_grid,np.abs(Ex), cmap='jet', alpha=0.9)
plt.axis('off')
st_title='Ex of mode '+str(mode+1)+' from MPB neff=' +str('%.2f' %(k[mode]/omega))
plt.title(st_title)
plt.tight_layout()
plt.savefig('SimulatedFieldCompare.png')
plt.show()
Current band: 1 Current band: 2 Current band: 3 Current band: 4 Current band: 1 Current band: 2 Current band: 3
<ipython-input-12-1a0f972779f9>:5: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolormesh(x_grid,y_grid,np.abs(Ex_mp[:,:,mode]), cmap='jet', alpha=0.9) <ipython-input-12-1a0f972779f9>:13: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. plt.pcolormesh(x_grid,y_grid,np.abs(Ex), cmap='jet', alpha=0.9)
Current band: 4
We can see that the results agrees well with each other. We can choose different methods to simulate the mode profiles. This is just a simple step for us to simulate the mode profile and effective index.