Skip to content

Commit

Permalink
Merge branch 'DEV' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghakim committed Oct 3, 2022
2 parents fc56304 + 72894db commit 8450c79
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 156 deletions.
60 changes: 32 additions & 28 deletions JLAB/run_metasurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class RetiMeent:
def __init__(self, grating_type, n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, wls, fourier_order,
def __init__(self, grating_type, n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, ucell, wls, fourier_order,
period):

self.grating_type = grating_type
Expand All @@ -20,20 +20,22 @@ def __init__(self, grating_type, n_air, n_si, n_glass, theta, phi, pol, thicknes
self.thickness = thickness
self.deflected_angle = deflected_angle
self.pattern = pattern
self.ucell = ucell
self.wls = wls
self.fourier_order = fourier_order
self.period = period

def acs_run_meent(self):
patterns = [[self.n_si, self.n_air, self.pattern]]
# 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=patterns, thickness=self.thickness)
patterns=pattern, ucell=self.ucell, thickness=self.thickness)

poi, refl, tran = meent.reproduce_acs(patterns)
# poi, refl, tran = meent.reproduce_acs(patterns)
poi, refl, tran = meent.reproduce_acs_cell(self.n_si, self.n_air)

return poi, refl, tran

Expand All @@ -51,27 +53,27 @@ def acs_run_reti(self):

return poi, refl, tran

def make_spectrum(self):

textures = profile = None

reti = Reticolo(grating_type=self.grating_type,
n_I=self.n_air, n_II=self.n_glass, theta=self.theta, phi=self.phi, fourier_order=self.fourier_order, period=self.period,
wls=self.wls, pol=self.pol,
textures=textures, profile=profile, thickness=self.thickness, deflected_angle=self.deflected_angle,
engine_type='octave')

reti.run_acs_loop_wavelength(self.pattern, self.deflected_angle, n_si=self.n_si)

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=patterns, thickness=self.thickness)

meent.reproduce_acs_loop_wavelength(patterns, self.deflected_angle)
# def make_spectrum(self):
#
# textures = profile = None
#
# reti = Reticolo(grating_type=self.grating_type,
# n_I=self.n_air, n_II=self.n_glass, theta=self.theta, phi=self.phi, fourier_order=self.fourier_order, period=self.period,
# wls=self.wls, pol=self.pol,
# textures=textures, profile=profile, thickness=self.thickness, deflected_angle=self.deflected_angle,
# engine_type='octave')
#
# reti.run_acs_loop_wavelength(self.pattern, self.deflected_angle, n_si=self.n_si)
#
# 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=patterns, thickness=self.thickness)
#
# meent.reproduce_acs_loop_wavelength(patterns, self.deflected_angle)

def fourier_order_sweep(self, fourier_array):

Expand Down Expand Up @@ -157,11 +159,12 @@ def fourier_order_sweep_meent_2d(self, fourier_array):
# 1D
grating_type = 0

fourier_order = 5
fourier_order = 40
period = abs(wls / np.sin(deflected_angle / 180 * np.pi))
pattern = np.array([1., 1., 1., -1., -1., -1., -1., -1., -1., -1.])
ucell = np.array([[pattern]])

AA = RetiMeent(grating_type, n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, wls, fourier_order,
AA = RetiMeent(grating_type, n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, ucell, wls, fourier_order,
period)

reti_abseff, reti_ref, reti_tra = AA.acs_run_reti()
Expand Down Expand Up @@ -206,11 +209,12 @@ def fourier_order_sweep_meent_2d(self, fourier_array):
[1., 1., 1., -1., -1., -1., -1., -1., -1., -1.],
[1., 1., 1., -1., -1., -1., -1., -1., -1., -1.]
])
ucell = np.array([pattern])

period = [abs(wls / np.sin(deflected_angle / 180 * np.pi)),
abs(wls / np.sin(deflected_angle / 180 * np.pi))]

AA = RetiMeent(grating_type,n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, wls, fourier_order,
AA = RetiMeent(grating_type,n_air, n_si, n_glass, theta, phi, pol, thickness, deflected_angle, pattern, ucell, wls, fourier_order,
period)

abseff, de_ri, de_ti = AA.acs_run_meent()
Expand Down
160 changes: 74 additions & 86 deletions JLAB/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,66 @@
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
from meent.on_numpy.convolution_matrix import put_n_ridge_in_pattern, to_conv_mat, find_n_index


class JLABCode(RCWA):
def __init__(self, grating_type=0, n_I=1.45, n_II=1., theta=0, phi=0, psi=0, fourier_order=40, period=100,
wls=np.linspace(900, 900, 1), pol=1, patterns=None, thickness=(325,), algo='TMM'):
wls=np.linspace(900, 900, 1), pol=1, patterns=None, ucell=None, thickness=(325,), algo='TMM'):

super().__init__(0, grating_type, n_I, n_II, theta, phi, psi, fourier_order, period, wls, pol, patterns,
super().__init__(0, grating_type, n_I, n_II, theta, phi, psi, fourier_order, period, wls, pol, patterns, ucell,
thickness, algo)

def permittivity_mapping_acs(self, wl):
pattern = put_n_ridge_in_pattern(self.patterns, wl)
# def permittivity_mapping_acs(self, wl):
# pattern = put_n_ridge_in_pattern(self.patterns, wl)
#
# if self.grating_type == 2:
# resolutions = pattern[0][2].shape
# ucell = np.zeros((len(pattern), *resolutions), dtype='complex')
# else:
# resolution = len(pattern[0][2])
# ucell = np.zeros((len(pattern), 1, resolution), dtype='complex')
#
# for i, (n_ridge, n_groove, pixel_map) in enumerate(pattern):
# pixel_map = np.array(pixel_map, dtype='complex')
# pixel_map = (pixel_map + 1) / 2
# pixel_map = pixel_map * (n_ridge ** 2 - n_groove ** 2) + n_groove ** 2
# ucell[i] = pixel_map
#
# e_conv_all = to_conv_mat(ucell, self.fourier_order)
# o_e_conv_all = to_conv_mat(1 / ucell, self.fourier_order)
#
# return e_conv_all, o_e_conv_all

# def reproduce_acs(self, pattern_pixel):
# self.patterns = pattern_pixel
#
# e_conv_all, o_e_conv_all = self.permittivity_mapping_acs(self.wls)
#
# de_ri, de_ti = self.solve(self.wls, e_conv_all, o_e_conv_all)
# if self.grating_type == 0:
# center = de_ti.shape[0] // 2
# tran_cut = de_ti[center - 1:center + 2][::-1]
# refl_cut = de_ri[center - 1:center + 2][::-1]
# else:
# x_c, y_c = np.array(de_ti.shape) // 2
# tran_cut = de_ti[x_c - 1:x_c + 2, y_c - 1:y_c + 2][::-1, ::-1]
# refl_cut = de_ri[x_c - 1:x_c + 2, y_c - 1:y_c + 2][::-1, ::-1]
#
# return tran_cut.flatten()[-1], refl_cut, tran_cut

def reproduce_acs_cell(self, n_ridge, n_groove):

if type(n_ridge) == str:
n_ridge = find_n_index(n_ridge, self.wls)

# self.ucell = np.array([[self.patterns]])

self.ucell = (self.ucell + 1) / 2
self.ucell = self.ucell * (n_ridge ** 2 - n_groove ** 2) + n_groove ** 2

de_ri, de_ti = self.run_ucell()

if self.grating_type == 2:
resolutions = pattern[0][2].shape
ucell = np.zeros((len(pattern), *resolutions), dtype='complex')
else:
resolution = len(pattern[0][2])
ucell = np.zeros((len(pattern), 1, resolution), dtype='complex')

for i, (n_ridge, n_groove, pixel_map) in enumerate(pattern):
pixel_map = np.array(pixel_map, dtype='complex')
pixel_map = (pixel_map + 1) / 2
pixel_map = pixel_map * (n_ridge ** 2 - n_groove ** 2) + n_groove ** 2
ucell[i] = pixel_map

e_conv_all = to_conv_mat(ucell, self.fourier_order)
o_e_conv_all = to_conv_mat(1 / ucell, self.fourier_order)

return e_conv_all, o_e_conv_all

def reproduce_acs(self, pattern_pixel):
self.patterns = pattern_pixel

e_conv_all, o_e_conv_all = self.permittivity_mapping_acs(self.wls)

de_ri, de_ti = self.solve(self.wls, e_conv_all, o_e_conv_all)
if self.grating_type == 0:
center = de_ti.shape[0] // 2
tran_cut = de_ti[center - 1:center + 2][::-1]
Expand All @@ -50,61 +73,26 @@ def reproduce_acs(self, pattern_pixel):

return tran_cut.flatten()[-1], refl_cut, tran_cut

def reproduce_acs_loop_wavelength(self, pattern, trans_angle, wls=None):
if wls is None:
wls = self.wls
else:
self.wls = wls
self.init_spectrum_array()

# self.patterns = [['SILICON', 1, pattern]] # n_ridge, n_groove, pattern_pixel
self.thickness = [325]

self.pol = 1

for i, wl in enumerate(wls):
self.period = [abs(wl / np.sin(trans_angle / 180 * np.pi))]

e_conv_all, o_e_conv_all = self.permittivity_mapping_acs(wl)

de_ri, de_ti = self.solve_1d(wl, e_conv_all, o_e_conv_all)

self.save_spectrum_array(de_ri, de_ti, i)

return self.spectrum_r, self.spectrum_t


if __name__ == '__main__':

n_air = 1
n_si = 3.5
n_glass = 1.45
theta = 0
phi = 0

pol = 1

thickness = [325]

deflected_angle = 60
pattern = 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., 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.])

patterns = [[n_si, n_air, pattern]]

wls = np.linspace(900, 900, 1)
fourier_order = 40
period = abs(wls / np.sin(deflected_angle / 180 * np.pi))

meent = JLABCode(grating_type=0,
n_I=n_glass, n_II=n_air, theta=theta, phi=phi,
fourier_order=fourier_order, period=period,
wls=wls, pol=pol,
patterns=patterns, thickness=thickness)
abseff, refl, tran = meent.reproduce_acs(patterns)
# def reproduce_acs_loop_wavelength(self, pattern, trans_angle, wls=None):
# if wls is None:
# wls = self.wls
# else:
# self.wls = wls
# self.init_spectrum_array()
#
# # self.patterns = [['SILICON', 1, pattern]] # n_ridge, n_groove, pattern_pixel
# self.thickness = [325]
#
# self.pol = 1
#
# for i, wl in enumerate(wls):
# self.period = [abs(wl / np.sin(trans_angle / 180 * np.pi))]
#
# e_conv_all, o_e_conv_all = self.permittivity_mapping_acs(wl)
#
# de_ri, de_ti = self.solve_1d(wl, e_conv_all, o_e_conv_all)
#
# self.save_spectrum_array(de_ri, de_ti, i)
#
# return self.spectrum_r, self.spectrum_t

print(abseff)
print(refl)
print(tran)
8 changes: 4 additions & 4 deletions examples/ex1_get_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

from meent.rcwa import call_solver

grating_type = 2 # 0: 1D, 1: 1D conical, 2:2D.
grating_type = 0 # 0: 1D, 1: 1D conical, 2:2D.
pol = 1 # 0: TE, 1: TM

n_I = 1 # n_incidence
n_II = 1 # n_transmission

theta = 0 # in degree, notation from Moharam paper
phi = 30 # in degree, notation from Moharam paper
phi = 0 # in degree, notation from Moharam paper
psi = 0 if pol else 90 # in degree, notation from Moharam paper

wls = np.linspace(500, 1200, 100) # wavelength
wls = np.linspace(500, 2300, 100) # wavelength

if grating_type in (0, 1):
period = [700]
fourier_order = 2
fourier_order = 20
patterns = [[3.48, 1, 0.3], [3.48, 1, 0.3]] # n_ridge, n_groove, fill_factor

else:
Expand Down
62 changes: 62 additions & 0 deletions examples/ex2_ucell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import time
import numpy as np

from meent.on_numpy.rcwa import RCWALight as RCWA


grating_type = 2 # 0: 1D, 1: 1D conical, 2:2D.
pol = 1 # 0: TE, 1: TM

n_I = 1 # n_incidence
n_II = 1 # n_transmission

theta = 0 # in degree, notation from Moharam paper
phi = 0 # in degree, notation from Moharam paper
psi = 0 if pol else 90 # in degree, notation from Moharam paper

wls = np.linspace(900, 900, 1) # wavelength

if grating_type in (0, 1):
period = [1400]
fourier_order = 20

else:
period = [700, 700]
fourier_order = 3

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, 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],
],
# [
# [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)
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()

3 changes: 2 additions & 1 deletion meent/on_numpy/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, thickness=None, algo='TMM'):
patterns=None, ucell=None, thickness=None, algo='TMM'):
super().__init__(grating_type)

self.grating_type = grating_type # 1D=0, 1D_conical=1, 2D=2
Expand Down Expand Up @@ -108,6 +108,7 @@ def __init__(self, grating_type, n_I=1., n_II=1., theta=0., phi=0., psi=0., four
self.wls = wls

self.patterns = patterns
self.ucell = ucell
self.thickness = thickness

self.algo = algo
Expand Down
Loading

0 comments on commit 8450c79

Please sign in to comment.