Skip to content

Commit

Permalink
developing ucell drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghakim committed Oct 7, 2022
1 parent 3cc1605 commit e076355
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 173 deletions.
67 changes: 65 additions & 2 deletions JLAB/run_metasurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ 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]]

meent = JLABCode(grating_type=self.grating_type,
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)
Expand All @@ -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 = [], [], [], []

Expand Down Expand Up @@ -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 = [], []
Expand Down
2 changes: 1 addition & 1 deletion JLAB/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
134 changes: 72 additions & 62 deletions QA/run_test2.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -137,65 +146,66 @@

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]


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)
Empty file added benchmark/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions benchmark/interface/Reticolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/ex1_get_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading

0 comments on commit e076355

Please sign in to comment.