diff --git a/JLAB/run_metasurface.py b/JLAB/run_metasurface.py index 6af2a2a..27f12f9 100644 --- a/JLAB/run_metasurface.py +++ b/JLAB/run_metasurface.py @@ -25,6 +25,12 @@ def __init__(self, grating_type, n_air, n_si, n_glass, theta, phi, pol, thicknes self.fourier_order = fourier_order self.period = period + self.fourier_array = [] + self.reti_r = [] + self.reti_t = [] + self.meent_r = [] + self.meent_t = [] + def acs_run_meent(self): # patterns = [[self.n_si, self.n_air, self.pattern]] @@ -32,7 +38,7 @@ def acs_run_meent(self): n_I=self.n_glass, n_II=self.n_air, theta=self.theta, phi=self.phi, fourier_order=self.fourier_order, period=self.period, wls=self.wls, pol=self.pol, - patterns=pattern, ucell=self.ucell, thickness=self.thickness) + patterns=self.pattern, ucell=self.ucell, thickness=self.thickness) # poi, refl, tran = meent.reproduce_acs(patterns) poi, refl, tran = meent.reproduce_acs_cell(self.n_si, self.n_air) @@ -53,7 +59,7 @@ def acs_run_reti(self): return poi, refl, tran - def fourier_order_sweep(self, fourier_array): + def fourier_order_sweep_(self, fourier_array): reti_r, reti_t, meent_r, meent_t = [], [], [], [] @@ -94,6 +100,63 @@ def fourier_order_sweep(self, fourier_array): plt.title('histogram of errors') plt.show() + def fourier_order_sweep(self, fourier_array): + + self.reti_r, self.reti_t, self.meent_r, self.meent_t = [], [], [], [] + self.fourier_array = fourier_array + + fourier_order = self.fourier_order + + for f_order in self.fourier_array: + self.fourier_order = f_order + a = self.acs_run_reti() + b = self.acs_run_meent() + + self.reti_r.append(a[1]) + self.reti_t.append(a[2]) + self.meent_r.append(b[1]) + self.meent_t.append(b[2]) + + self.fourier_order = fourier_order + + self.reti_r = np.array(self.reti_r) + self.reti_t = np.array(self.reti_t) + self.meent_r = np.array(self.meent_r) + self.meent_t = np.array(self.meent_t) + + return self.reti_r, self.reti_t, self.meent_r, self.meent_t + + def fourier_order_sweep_plot(self): + cut = 40 + + figs, axes = plt.subplots(1, 3) + + axes[0].axvline(cut, c='r') + axes[1].axvline(cut, c='r') + axes[2].axvline(cut, c='r') + + axes[0].plot(self.fourier_array, self.reti_r[:, 0], marker='X') + axes[0].plot(self.fourier_array, self.meent_r[:, 0], marker='.', linestyle='dashed') + axes[1].plot(self.fourier_array, self.reti_r[:, 1], marker='X') + axes[1].plot(self.fourier_array, self.meent_r[:, 1], marker='.', linestyle='dashed') + axes[2].plot(self.fourier_array, self.reti_r[:, 2], marker='X') + axes[2].plot(self.fourier_array, self.meent_r[:, 2], marker='.', linestyle='dashed') + plt.show() + + figs, axes = plt.subplots(1, 3) + + axes[0].axvline(cut, c='r') + axes[1].axvline(cut, c='r') + axes[2].axvline(cut, c='r') + + axes[0].plot(self.fourier_array, self.reti_t[:, 0], marker='X') + axes[0].plot(self.fourier_array, self.meent_t[:, 0], marker='.', linestyle='dashed') + axes[1].plot(self.fourier_array, self.reti_t[:, 1], marker='X') + axes[1].plot(self.fourier_array, self.meent_t[:, 1], marker='.', linestyle='dashed') + axes[2].plot(self.fourier_array, self.reti_t[:, 2], marker='X') + axes[2].plot(self.fourier_array, self.meent_t[:, 2], marker='.', linestyle='dashed') + plt.show() + def fourier_order_sweep_meent_2d(self, fourier_array): meent_r, meent_t = [], [] diff --git a/JLAB/solver.py b/JLAB/solver.py index 2c0b6c7..dc330c9 100644 --- a/JLAB/solver.py +++ b/JLAB/solver.py @@ -2,7 +2,7 @@ import numpy as np from meent.on_numpy.rcwa import RCWALight as RCWA -from meent.on_numpy.convolution_matrix import put_n_ridge_in_pattern, to_conv_mat, find_n_index +from meent.on_numpy.convolution_matrix import put_n_ridge_in_pattern_fill_factor, to_conv_mat, find_n_index class JLABCode(RCWA): diff --git a/QA/run_test2.py b/QA/run_test2.py index 4b7c431..47ff0a9 100644 --- a/QA/run_test2.py +++ b/QA/run_test2.py @@ -1,6 +1,6 @@ import numpy as np -from meent.rcwa import call_solver +from meent.rcwa import call_solver, sweep_wavelength pol = 1 # 0: TE, 1: TM @@ -23,54 +23,61 @@ ucell = np.array([ [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], ]) +ucell_materials = ['SILICON', 1] + AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) +# de_ri, de_ti = AA.loop_wavelength_ucell() +# AA.plot() ucell = np.array([ [ - [n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ], ]) +ucell_materials = ['SILICON', 1, n_I, n_II] thickness = [200, 460, 660, 200] wls = np.linspace(900, 900, 1) # wavelength AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) +# de_ri, de_ti = AA.loop_wavelength_ucell() +# AA.plot() # 1D conical case period = [700] @@ -79,55 +86,57 @@ ucell = np.array([ [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], ]) +ucell_materials = ['SILICON', 1] wls = np.linspace(900, 900, 1) # wavelength AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) ucell = np.array([ [ - [n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ], ]) +ucell_materials = ['SILICON', 1, n_I, n_II] thickness = [200, 460, 660, 200] wls = np.linspace(900, 900, 1) # wavelength AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) # 2D case @@ -137,52 +146,54 @@ ucell = np.array([ [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], ]) +ucell_materials = ['SILICON', 1] wls = np.linspace(900, 900, 1) # wavelength AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) ucell = np.array([ [ - [n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I], - [n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I], - [n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I, n_I], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], + [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II], - [n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II], - [n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II, n_II], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], + [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ], ]) +ucell_materials = ['SILICON', 1, n_I, n_II] thickness = [200, 460, 660, 200] @@ -190,12 +201,11 @@ wls = np.linspace(900, 900, 1) # wavelength AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) -wls = np.linspace(500, 1000, 100) -AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +AA = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) \ No newline at end of file diff --git a/benchmark/__init__.py b/benchmark/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/benchmark/interface/Reticolo.py b/benchmark/interface/Reticolo.py index 8be945f..9eb85ee 100644 --- a/benchmark/interface/Reticolo.py +++ b/benchmark/interface/Reticolo.py @@ -66,8 +66,8 @@ def run(self): return self.spectrum_r, self.spectrum_t - def run_acs(self, pattern, n_si='n_si'): - if type(n_si) == str and n_si.upper() == 'N_SI': + def run_acs(self, pattern, n_si='SILICON'): + if type(n_si) == str and n_si.upper() == 'SILICON': n_si = find_n_index(n_si, self.wls) abseff, effi_r, effi_t = self.eng.Eval_Eff_1D(pattern, self.wls, self.deflected_angle, self.fourier_order, @@ -76,13 +76,13 @@ def run_acs(self, pattern, n_si='n_si'): return abseff, effi_r, effi_t - def run_acs_loop_wavelength(self, pattern, deflected_angle, wls=None, n_si='Silicon'): + def run_acs_loop_wavelength(self, pattern, deflected_angle, wls=None, n_si='SILICON'): if wls is None: wls = self.wls else: self.wls = wls # TODO: handle better. - if type(n_si) == str and n_si.upper() == 'Silicon': + if type(n_si) == str and n_si.upper() == 'SILICON': n_si = find_n_index(n_si, self.wls) self.init_spectrum_array() diff --git a/examples/ex1_get_spectrum.py b/examples/ex1_get_spectrum.py index 74a095b..5ab3944 100644 --- a/examples/ex1_get_spectrum.py +++ b/examples/ex1_get_spectrum.py @@ -13,7 +13,7 @@ phi = 0 # in degree, notation from Moharam paper psi = 0 if pol else 90 # in degree, notation from Moharam paper -wls = np.linspace(500, 2300, 100) # wavelength +wls = np.linspace(500, 1000, 100) # wavelength if grating_type in (0, 1): period = [700] diff --git a/examples/ex2_ucell.py b/examples/ex2_ucell.py index 1baebd4..204a048 100644 --- a/examples/ex2_ucell.py +++ b/examples/ex2_ucell.py @@ -2,6 +2,7 @@ import numpy as np from meent.on_numpy.rcwa import RCWALight as RCWA +from meent.rcwa import call_solver, sweep_wavelength grating_type = 2 # 0: 1D, 1: 1D conical, 2:2D. @@ -27,36 +28,30 @@ thickness = [460, 660] ucell = np.array([ - # [ - # [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - # [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - # [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - # ], + [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], [ - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48**2, 3.48**2, 3.48**2, 1, 1, 1, 1], - [1, 1, 1, 3.48 ** 2, 3.48 ** 2, 3.48 ** 2, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], ], - # [ - # [12, 12, 12, 12, 12, 12, 12, 12, 12, 12], - # [12, 12, 12, 12, 12, 12, 12, 12, 12, 12], - # [12, 12, 12, 12, 12, 12, 12, 12, 12, 12], - # ], ]) -AA = RCWA(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) +ucell_materials = ['SILICON', 1] + +AA = call_solver(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, ucell_materials=ucell_materials, + thickness=thickness) de_ri, de_ti = AA.run_ucell() print(de_ri, de_ti) -wls = np.linspace(500, 2300, 100) -AA = RCWA(mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, ucell=ucell, thickness=thickness) -de_ri, de_ti = AA.loop_wavelength_ucell() -AA.plot() +wls = np.linspace(500, 1000, 100) + +a, b = sweep_wavelength(wls, mode=0, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, + fourier_order=fourier_order, period=period, ucell=ucell, ucell_materials=ucell_materials, thickness=thickness) +print(a) diff --git a/meent/on_numpy/_base.py b/meent/on_numpy/_base.py index b8faba9..e77b1a3 100644 --- a/meent/on_numpy/_base.py +++ b/meent/on_numpy/_base.py @@ -80,7 +80,7 @@ def plot(self, title=None, marker=None): class _BaseRCWA(Base): def __init__(self, grating_type, n_I=1., n_II=1., theta=0., phi=0., psi=0., fourier_order=10, period=0.7, wls=np.linspace(0.5, 2.3, 400), pol=0, - patterns=None, ucell=None, thickness=None, algo='TMM'): + patterns=None, ucell=None, ucell_materials=None, thickness=None, algo='TMM'): super().__init__(grating_type) self.grating_type = grating_type # 1D=0, 1D_conical=1, 2D=2 @@ -109,6 +109,7 @@ def __init__(self, grating_type, n_I=1., n_II=1., theta=0., phi=0., psi=0., four self.patterns = patterns self.ucell = ucell + self.ucell_materials = ucell_materials self.thickness = thickness self.algo = algo diff --git a/meent/on_numpy/convolution_matrix.py b/meent/on_numpy/convolution_matrix.py index 9ef6d19..a98f214 100644 --- a/meent/on_numpy/convolution_matrix.py +++ b/meent/on_numpy/convolution_matrix.py @@ -6,7 +6,7 @@ from pathlib import Path -def put_n_ridge_in_pattern(pattern_all, wl): +def put_n_ridge_in_pattern_fill_factor(pattern_all, wl): pattern_all = copy.deepcopy(pattern_all) @@ -19,6 +19,23 @@ def put_n_ridge_in_pattern(pattern_all, wl): return pattern_all +def put_permittivity_in_ucell(ucell, mat_list, wl): + # mat_list = ['SILICON', 1] + + res = np.zeros(ucell.shape, dtype='complex') + + for z in range(ucell.shape[0]): + for y in range(ucell.shape[1]): + for x in range(ucell.shape[2]): + material = mat_list[ucell[z, y, x]] + if type(material) == str: + res[z, y, x] = find_n_index(material, wl) ** 2 + else: + res[z, y, x] = material ** 2 + + return res + + def find_n_index(material, wl): # TODO: where put this to? nk_path = str(Path(__file__).resolve().parent.parent.parent) + '/nk_data/p_Si.mat' # TODO: organize @@ -34,7 +51,7 @@ def find_n_index(material, wl): def fill_factor_to_ucell(patterns_fill_factor, wl, grating_type): - pattern_fill_factor = put_n_ridge_in_pattern(patterns_fill_factor, wl) + pattern_fill_factor = put_n_ridge_in_pattern_fill_factor(patterns_fill_factor, wl) ucell = draw_fill_factor(pattern_fill_factor, grating_type) return ucell diff --git a/meent/on_numpy/rcwa.py b/meent/on_numpy/rcwa.py index 4ccb13c..7928c40 100644 --- a/meent/on_numpy/rcwa.py +++ b/meent/on_numpy/rcwa.py @@ -2,14 +2,14 @@ import numpy as np from ._base import _BaseRCWA -from .convolution_matrix import to_conv_mat, find_n_index, fill_factor_to_ucell +from .convolution_matrix import to_conv_mat, find_n_index, fill_factor_to_ucell, put_permittivity_in_ucell class RCWALight(_BaseRCWA): def __init__(self, mode=0, grating_type=0, n_I=1., n_II=1., theta=0, phi=0, psi=0, fourier_order=40, period=(100,), - wls=np.linspace(900, 900, 1), pol=0, patterns=None, ucell=None, thickness=None, algo='TMM'): + wls=np.linspace(900, 900, 1), pol=0, patterns=None, ucell=None, ucell_materials=None, thickness=None, algo='TMM'): - super().__init__(grating_type, n_I, n_II, theta, phi, psi, fourier_order, period, wls, pol, patterns, ucell, + super().__init__(grating_type, n_I, n_II, theta, phi, psi, fourier_order, period, wls, pol, patterns, ucell, ucell_materials, thickness, algo) self.mode = mode @@ -49,25 +49,26 @@ def loop_wavelength_fill_factor(self, wavelength_array=None): return self.spectrum_r, self.spectrum_t - def loop_wavelength_ucell(self): - - for i, wl in enumerate(self.wls): - # for material, z_begin, z_end, y_begin, y_end, x_begin, x_end in [si, ox]: - # n_index = find_n_index(material, wl) if type(material) == str else material - # cell[z_begin:z_end, y_begin:y_end, x_begin:x_end] = n_index ** 2 - - e_conv_all = to_conv_mat(self.ucell, self.fourier_order) - o_e_conv_all = to_conv_mat(1 / self.ucell, self.fourier_order) - - de_ri, de_ti = self.solve(wl, e_conv_all, o_e_conv_all) - - self.spectrum_r[i] = de_ri - self.spectrum_t[i] = de_ti - - return self.spectrum_r, self.spectrum_t + # def loop_wavelength_ucell(self): + # wls = self.wls + # ucell = self.ucell + # + # for i, wl in enumerate(self.wls): + # self.wls = np.array(wl) + # de_ri, de_ti = self.run_ucell() + # + # self.spectrum_r[i] = de_ri + # self.spectrum_t[i] = de_ti + # self.ucell = ucell + # + # self.wls = wls + # + # return self.spectrum_r, self.spectrum_t def run_ucell(self): + self.ucell = put_permittivity_in_ucell(self.ucell, self.ucell_materials, self.wls) + e_conv_all = to_conv_mat(self.ucell, self.fourier_order) o_e_conv_all = to_conv_mat(1 / self.ucell, self.fourier_order) diff --git a/meent/rcwa.py b/meent/rcwa.py index 9a24694..ad1653d 100644 --- a/meent/rcwa.py +++ b/meent/rcwa.py @@ -15,60 +15,67 @@ def call_solver(mode=0, *args, **kwargs): return RCWA -if __name__ == '__main__': - grating_type = 0 - pol = 0 - - n_I = 1 - n_II = 1 - - theta = 0 - phi = 0 - psi = 0 if pol else 90 - - wls = np.linspace(500, 1300, 100) - # wls = np.linspace(600, 800, 3) - - if grating_type in (0, 1): - period = [700] - patterns = [[3.48, 1, 0.1], [3.48, 1, 0.1]] # n_ridge, n_groove, fill_factor - fourier_order = 40 - - elif grating_type == 2: - period = [700, 700] - patterns = [[3.48, 1, [0.3, 1]], [3.48, 1, [0.3, 1]]] # n_ridge, n_groove, fill_factor[x, y] - fourier_order = 2 - else: - raise ValueError - - thickness = [460, 660] - - mode = 0 # 0: light mode; 1: backprop mode; - - # AA = call_solver(mode=mode, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - # fourier_order=fourier_order, wls=wls, period=period, patterns=patterns, thickness=thickness) - # t0 = time.perf_counter() - # - # a, b = AA.loop_wavelength_fill_factor() - # AA.plot() - # print(time.perf_counter() - t0) - - ucell = np.array( - [ - [ - [3.48 ** 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], - ], - [ - [3.48 ** 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], - ], - ] - ) - - AA = call_solver(mode=mode, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, - fourier_order=fourier_order, wls=wls, period=period, patterns=patterns, ucell = ucell, thickness=thickness) - t0 = time.perf_counter() - - a, b = AA.loop_wavelength_ucell() - AA.plot() - - print(time.perf_counter() - t0) +def sweep_wavelength(wls, *args, **kwargs): + # wls = np.linspace(500, 1000, 10) + spectrum_r = [] + spectrum_t = [] + + for i, wl in enumerate(wls): + wl = np.array([wl]) + solver = call_solver(wls=wl, *args, **kwargs) + de_ri, de_ti = solver.run_ucell() + spectrum_r.append(de_ri) + spectrum_t.append(de_ti) + + return spectrum_r, spectrum_t + + +# if __name__ == '__main__': +# grating_type = 0 +# pol = 0 +# +# n_I = 1 +# n_II = 1 +# +# theta = 0 +# phi = 0 +# psi = 0 if pol else 90 +# +# wls = np.linspace(500, 1300, 100) +# # wls = np.linspace(600, 800, 3) +# +# if grating_type in (0, 1): +# period = [700] +# patterns = [[3.48, 1, 0.1], [3.48, 1, 0.1]] # n_ridge, n_groove, fill_factor +# fourier_order = 40 +# +# elif grating_type == 2: +# period = [700, 700] +# patterns = [[3.48, 1, [0.3, 1]], [3.48, 1, [0.3, 1]]] # n_ridge, n_groove, fill_factor[x, y] +# fourier_order = 2 +# else: +# raise ValueError +# +# thickness = [460, 660] +# +# mode = 0 # 0: light mode; 1: backprop mode; +# +# ucell = np.array( +# [ +# [ +# [3.48 ** 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], +# ], +# [ +# [3.48 ** 2, 1, 1, 1, 1, 1, 1, 1, 1, 1], +# ], +# ] +# ) +# +# AA = call_solver(mode=mode, grating_type=grating_type, pol=pol, n_I=n_I, n_II=n_II, theta=theta, phi=phi, psi=psi, +# fourier_order=fourier_order, wls=wls, period=period, patterns=patterns, ucell = ucell, thickness=thickness) +# t0 = time.perf_counter() +# +# a, b = AA.loop_wavelength_ucell() +# AA.plot() +# +# print(time.perf_counter() - t0) diff --git a/setup.py b/setup.py index 124543f..10240be 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='meent', - version='0.3.4', + version='0.3.5', url='https://github.com/kc-ml2/meent', author='KC ML2', author_email='yongha@kc-ml2.com',