weiliangjinca / grcwa

Python implementation of rigorous coupled wave analysis, autograd supported for optimization purpose
Other
63 stars 28 forks source link

the results are inconsistent with lumerical #3

Closed saiGo1992 closed 6 months ago

saiGo1992 commented 2 years ago

Description

I use grcwa to simulate a structure which has been optimized, so the geometry is complicated. In order to make sure the results are reliable, I also simulated it in lumerical FDTD module. However, the E field and P field of grcwa can not match with lumerical. I wonder is there any limitation in grcwa ? Because my simulation wave lengths are 450nm and the dimension of structure is 2um x 2um (polarization in Ex direction). The attach files are the structure I simulate, abs(Ex) and abs(Ey) profile of grcwa and lumerical for 450 nm, abs(Pz) profile of grcwa and lumerical for 450 nm.

Hope to get response soon, thanks in advences!

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

abs(Ex)_grcwa abs(Ex)_lumerical abs(Ey)_grcwa abs(Ey)_lumerical structure

rafael-fuente commented 2 years ago

RCWA scales poorly compared with FDTD for large-scale simulations since you need a high truncation order to get convergence. Can you share your code to take a look at what you have done?

saiGo1992 commented 2 years ago

RCWA scales poorly compared with FDTD for large-scale simulations since you need a high truncation order to get convergence. Can you share your code to take a look at what you have done?

Sure, my code as follow:

from matplotlib import pyplot as plt
import numpy as np
import grcwa
import autograd.numpy as npa

## Truncation order (actual number might be smaller)
nG = 501
## lattice constants
L1 = [2.,0]
L2 = [0,2.]

theta = 0.
phi = 0.
Qabs = np.inf 

## simulation data
sim_datas = [
               {'freq':[1/0.45*(1+1j/2/Qabs)],
                 'ep0':[                   1],
                 'ep1':[             2.05**2],
                 'ep2':[             1.47**2],
                 'epN':[                   1]}
            ]

## planewave excitation
planewave = {'p_amp': 1, 's_amp': 0, 'p_phase': 0, 's_phase': 0}

## the patterned layer has a griding: Nx*Ny
Np = 2 # number of patterned layers
Resolution = 200
Nx = Resolution
Ny = Resolution
interal = int(Resolution/2)

thick0 = 1. # thickness for vacuum layer 1
pthick = [0.6,5] # thickness of patterned layer
thickN = 1.

## coordinate
x0 = np.linspace(0,1.,Nx)
y0 = np.linspace(0,1.,Ny)
x, y = np.meshgrid(x0,y0,indexing='ij')

## planewave excitation
planewave = {'p_amp': 1, 's_amp': 0, 'p_phase': 0, 's_phase': 0}

binary_file = 'eps-288beta-166.587890625.txt'
binary = np.loadtxt(binary_file,delimiter=',')

plt.pcolor(x, y, binary,cmap = 'Greys_r')
plt.xticks([])
plt.yticks([])
plt.colorbar()
Pz_Ratio = 0

for i in range(len(sim_datas)):
    for j in range(len(sim_datas[i]['freq'])):
        ######## setting up RCWA
        obj = grcwa.obj(nG, L1, L2, sim_datas[i]['freq'][j], theta, phi, verbose=1)
        obj.Add_LayerUniform(thick0, sim_datas[i]['ep0'][j])
        for k in range(Np):
            obj.Add_LayerGrid(pthick[k], Nx, Ny)
        obj.Add_LayerUniform(thickN, sim_datas[i]['epN'][j])
        obj.Init_Setup()
        obj.MakeExcitationPlanewave(planewave['p_amp'], planewave['p_phase'], planewave['s_amp'], planewave['s_phase'],order=0)
        # combine epsilon of all layers
        eps = sim_datas[i]['ep0'][j] + (sim_datas[i]['ep1'][j] - sim_datas[i]['ep0'][j]) * binary  
        epgrid2 = npa.ones((Nx, Ny)) * sim_datas[i]['ep2'][j]
        epgrid = npa.concatenate((eps.flatten(), epgrid2.flatten()))
        obj.GridLayer_geteps(epgrid)
        # calcalate E, H, R and T
        E, H = obj.Solve_FieldOnGrid(2, 5)  # E = [Ex,Ey,Ez], H = [Hx,Hy,Hz]
        R, T = obj.RT_Solve(normalize=1)

        #abs(Ex) and abs(Ey) 
        plt.figure()
        plt.pcolor(x, y, abs(E[0]), cmap='jet')
        plt.colorbar()

        plt.figure()
        plt.pcolor(x, y, abs(E[1]), cmap='jet')
        plt.colorbar()

plt.show()

The txt file I use in code also have uploaded here.

eps-288beta-166.587890625.txt

weiliangjinca commented 2 years ago

RCWA scales poorly compared with FDTD for large-scale simulations since you need a high truncation order to get convergence. Can you share your code to take a look at what you have done?

Yes, RCWA needs a very high nG to converge for this kind of structure where you have a period/wavelength>1. In your case, the ratio is 4. So I feel the result at this level of nG looks quite look already. Another point is that far-field computation tends to converge much faster than near-field components in RCWA.