### Add Layers and Setup Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Adds uniform or patterned layers to the object and initializes the setup. ```python obj.Add_LayerUniform(thick0,ep0) # uniform slab obj.Add_LayerGrid(thickp,Nx,Ny) # patterned layer # after add all layers: obj.Init_Setup() ``` -------------------------------- ### Set up virtual environment and install Source: https://grcwa.readthedocs.io/en/latest/contributing.html Set up a virtual environment using virtualenvwrapper and install the local copy of grcwa in development mode. ```bash $ mkvirtualenv grcwa $ cd grcwa/ $ python setup.py develop ``` -------------------------------- ### Install grcwa from source Source: https://grcwa.readthedocs.io/en/latest/_sources/installation.rst.txt Run this command after downloading the source code to install the package. ```console $ python setup.py install ``` -------------------------------- ### Install GRCWA Source: https://grcwa.readthedocs.io/en/latest/_sources/readme.rst.txt Installation methods for the GRCWA package. ```console $ pip install grcwa ``` ```console $ git clone git://github.com/weiliangjinca/grcwa $ pip install . ``` -------------------------------- ### Install grcwa from source Source: https://grcwa.readthedocs.io/en/latest/readme.html Clone the grcwa repository from GitHub and install it locally. This is useful for development or if you need the latest unreleased version. ```bash $ git clone git://github.com/weiliangjinca/grcwa $ pip install . ``` -------------------------------- ### GRCWA Initialization and Setup Source: https://grcwa.readthedocs.io/en/latest/usage.html Demonstrates how to initialize the GRCWA object with basic parameters and set up the simulation environment, including options for autograd, periodicity scaling, and Fourier space truncation. ```APIDOC ## GRCWA Initialization and Setup ### Description This section covers the initialization of the GRCWA object and the various setup options available. ### Method Python ### Endpoint N/A (Library Usage) ### Parameters #### Initialization Parameters - **nG** (int) - Number of Fourier orders. - **L1** (float) - Periodicity in the x-direction. - **L2** (float) - Periodicity in the y-direction. - **freq** (float) - Frequency of the incident light. - **theta** (float) - Angle of incidence in the xz-plane. - **phi** (float) - Angle of incidence in the yz-plane. - **verbose** (int) - Verbosity level (0 for silent, 1 for output nG). #### Setup Parameters (Optional) - **Pscale** (float) - Scales the periodicity in both lateral directions simultaneously. Defaults to 1.0. - **Gmethod** (int) - Method for Fourier space truncation: 0 for circular, 1 for rectangular. Defaults to 0. ### Request Example ```python import grcwa # Initialize with basic parameters obj = grcwa.obj(nG=10, L1=1.0, L2=1.0, freq=1.0, theta=0.0, phi=0.0, verbose=0) # Initialize with additional setup options obj.Init_Setup(Pscale=1.2, Gmethod=1) ``` ### Response N/A (Library Usage) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Install grcwa via pip Source: https://grcwa.readthedocs.io/en/latest/_sources/installation.rst.txt Use this command to install the most recent stable release of grcwa. ```console $ pip install grcwa ``` -------------------------------- ### Layer Definition and Initialization Source: https://grcwa.readthedocs.io/en/latest/usage.html Explains how to add uniform and patterned layers to the GRCWA object and finalize the layer setup. ```APIDOC ## Layer Definition and Initialization ### Description This section details how to define and add layers to the GRCWA simulation, including uniform slabs and patterned layers. ### Method Python ### Endpoint N/A (Library Usage) ### Parameters #### Add_LayerUniform Parameters - **thick** (float) - Thickness of the uniform layer. - **epsilon** (complex) - Permittivity of the uniform layer. #### Add_LayerGrid Parameters - **thick** (float) - Thickness of the patterned layer. - **Nx** (int) - Number of grid points in the x-direction. - **Ny** (int) - Number of grid points in the y-direction. ### Request Example ```python # Add a uniform layer obj.Add_LayerUniform(thick0=0.5, ep0=1.0) # Add a patterned layer obj.Add_LayerGrid(thickp=0.3, Nx=32, Ny=32) # Finalize layer setup obj.Init_Setup() ``` ### Response N/A (Library Usage) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Run linters and tests Source: https://grcwa.readthedocs.io/en/latest/contributing.html Check that your changes pass flake8 and the tests, including testing other Python versions with tox. Ensure flake8 and tox are installed in your virtualenv. ```bash $ flake8 grcwa tests $ python setup.py test or pytest $ tox ``` -------------------------------- ### Get Reflection and Transmission by Order Source: https://grcwa.readthedocs.io/en/latest/usage.html Obtain reflection (Ri) and transmission (Ti) coefficients for each order using RT_Solve with byorder=1. Ri and Ti have a length of obj.nG. ```python Ri, Ti = obj.RT_Solve(byorder=1) # Ri(Ti) has length obj.nG, too see which order, check obj.G; too see which kx,ky, check obj.kx obj.ky ``` -------------------------------- ### Get Eigenvector Amplitudes Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Retrieves amplitudes of eigenvectors at a specific layer and offset. ```python ai,bi = obj.GetAmplitudes(which_layer,z_offset) ``` -------------------------------- ### Enable Autograd Backend Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Configures the library to use the autograd backend. ```python grcwa.set_backend('autograd') ``` -------------------------------- ### Initialize RCWA object Source: https://grcwa.readthedocs.io/en/latest/readme.html Set up the RCWA object with lattice constants, truncation order, frequency, and incident light angle. Ensure the backend (e.g., autograd) is set if needed. ```python import grcwa import numpy as np grcwa.set_backend('autograd') # if autograd needed # lattice constants L1 = [0.2,0] L2 = [0,0.2] # Truncation order (actual number might be smaller) nG = 101 # frequency freq = 1. # angle theta = np.pi/10 phi = 0. # setup RCWA obj = grcwa.obj(nG,L1,L2,freq,theta,phi,verbose=1) ``` -------------------------------- ### Define incident light and solve for R and T Source: https://grcwa.readthedocs.io/en/latest/readme.html Specify the polarization and amplitude of the incident plane wave. Then, solve for the reflection (R) and transmission (T) coefficients. The 'normalize=1' argument ensures results are normalized. ```python planewave={'p_amp':0,'s_amp':1,'p_phase':0,'s_phase':0} obj.MakeExcitationPlanewave(planewave['p_amp'],planewave['p_phase'],planewave['s_amp'],planewave['s_phase'],order = 0) # solve for R and T R,T= obj.RT_Solve(normalize=1) ``` -------------------------------- ### Deploying grcwa Source: https://grcwa.readthedocs.io/en/latest/contributing.html Deploy grcwa by committing changes, updating HISTORY.rst, and then running bump2version. Ensure all changes are committed before deploying. ```bash $ bump2version patch # possible: major / minor / patch $ git push $ git push --tags ``` -------------------------------- ### Define Planewave Excitation Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Sets up planewave excitation parameters. ```python obj.MakeExcitationPlanewave(p_amp,p_phase,s_amp,s_phase,order = 0) ``` -------------------------------- ### Create a new branch for development Source: https://grcwa.readthedocs.io/en/latest/contributing.html Create a new branch for your bug fix or feature development. ```bash $ git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Excitation Definition Source: https://grcwa.readthedocs.io/en/latest/usage.html Shows how to define different types of light excitation, including plane waves and arbitrary incident fields. ```APIDOC ## Excitation Definition ### Description This section covers the methods for defining the incident light source for the GRCWA simulation. ### Method Python ### Endpoint N/A (Library Usage) ### Parameters #### MakeExcitationPlanewave Parameters - **p_amp** (complex) - Amplitude of the p-polarized component. - **p_phase** (float) - Phase of the p-polarized component. - **s_amp** (complex) - Amplitude of the s-polarized component. - **s_phase** (float) - Phase of the s-polarized component. - **order** (int) - Specifies the order of the plane wave. Defaults to 0. #### Arbitrary Incidence Parameters - **a0** (numpy.ndarray) - Forward-propagating wave coefficients. Length should be 2*obj.nG. - **bN** (numpy.ndarray) - Backward-propagating wave coefficients. Length should be 2*obj.nG. ### Request Example ```python # Define a plane wave excitation obj.MakeExcitationPlanewave(p_amp=1.0, p_phase=0.0, s_amp=0.0, s_phase=0.0, order=0) # Define arbitrary incidence (example for forward wave) a0_coeffs = np.zeros(2 * obj.nG) a0_coeffs[0] = 1.0 # Example coefficient obj.a0 = a0_coeffs # Define arbitrary incidence (example for backward wave) bN_coeffs = np.zeros(2 * obj.nG) bN_coeffs[1] = 0.5 # Example coefficient obj.bN = bN_coeffs ``` ### Response N/A (Library Usage) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Initialize RCWA Object Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Creates the main RCWA object with specified parameters. ```python obj = grcwa.obj(nG,L1,L2,freq,theta,phi,verbose=0) # verbose=1 for output the actual nG ``` -------------------------------- ### Commit and push changes Source: https://grcwa.readthedocs.io/en/latest/contributing.html Commit your changes locally and push your branch to GitHub. ```bash $ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Clone grcwa repository Source: https://grcwa.readthedocs.io/en/latest/contributing.html Clone your forked grcwa repository locally to begin development. ```bash $ git clone git@github.com:your_name_here/grcwa.git ``` -------------------------------- ### Import grcwa Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Basic import statement for the library. ```python import grcwa ``` -------------------------------- ### Clone grcwa repository Source: https://grcwa.readthedocs.io/en/latest/_sources/installation.rst.txt Download the source code by cloning the public repository from GitHub. ```console $ git clone git://github.com/weiliangjinca/grcwa ``` -------------------------------- ### Reconstruct Epsilon Profile Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Reconstructs the real-space epsilon profile from truncated Fourier orders. ```python ep = obj.Return_eps(which_layer,Nx,Ny,component='xx') # For patterned layer component = 'xx','xy','yx','yy','zz'; For uniform layer, currently it's assumed to be isotropic ``` -------------------------------- ### Patterned Layer Epsilon Profile Source: https://grcwa.readthedocs.io/en/latest/usage.html Details how to provide the epsilon profile for a patterned layer using a flattened 1D array. ```APIDOC ## Patterned Layer Epsilon Profile ### Description This section describes how to feed the epsilon profile for a patterned layer into the GRCWA object. ### Method Python ### Endpoint N/A (Library Usage) ### Parameters #### GridLayer_geteps Parameters - **x** (numpy.ndarray) - A 1D array containing the flattened epsilon values for the patterned layer. This should be a concatenation of epsilon grids if multiple patterned layers exist. ### Request Example ```python # Assuming epgrid1 and epgrid2 are 2D numpy arrays representing epsilon profiles # For a single patterned layer: x = epgrid1.flatten() obj.GridLayer_geteps(x) # For multiple patterned layers: x = np.concatenate((epgrid1.flatten(), epgrid2.flatten())) obj.GridLayer_geteps(x) ``` ### Response N/A (Library Usage) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Run a subset of tests Source: https://grcwa.readthedocs.io/en/latest/contributing.html To run a specific subset of tests, use the pytest command with the test module. ```bash $ pytest tests.test_grcwa ``` -------------------------------- ### Set Fourier Truncation Method Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Configures the truncation method for Fourier space. ```python obj.Init_Setup(Gmethod=0) # 0 for circular, 1 for rectangular ``` -------------------------------- ### Solving and Retrieving Results Source: https://grcwa.readthedocs.io/en/latest/usage.html Details on how to solve the RCWA problem and retrieve various optical quantities such as reflection, transmission, field amplitudes, and epsilon profiles. ```APIDOC ## Solving and Retrieving Results ### Description This section explains how to compute the optical response of the defined structure and extract detailed results. ### Method Python ### Endpoint N/A (Library Usage) ### Parameters #### RT_Solve Parameters - **normalize** (int) - Normalization flag. Set to 1 if the 0-th media is not vacuum or for oblique incidence. Defaults to 0. - **byorder** (int) - Flag to retrieve results by order. Set to 1 to get results per Fourier order. Defaults to 0. #### GetAmplitudes Parameters - **which_layer** (int) - The index of the layer for which to get amplitudes. - **z_offset** (float) - The z-offset within the layer. #### Return_eps Parameters - **which_layer** (int) - The index of the layer. - **Nx** (int) - Number of grid points in x for reconstruction. - **Ny** (int) - Number of grid points in y for reconstruction. - **component** (str) - For patterned layers, specifies the permittivity component ('xx', 'xy', 'yx', 'yy', 'zz'). For uniform layers, assumed isotropic. #### Solve_FieldFourier Parameters - **which_layer** (int) - The index of the layer. - **z_offset** (float) - The z-offset within the layer. #### Solve_FieldOnGrid Parameters - **which_layer** (int) - The index of the layer. - **z_offset** (float) - The z-offset within the layer. #### Volume_integral Parameters - **which_layer** (int) - The index of the layer. - **Mx** (numpy.ndarray) - Convolution matrix for the x-direction. - **My** (numpy.ndarray) - Convolution matrix for the y-direction. - **Mz** (numpy.ndarray) - Convolution matrix for the z-direction. - **normalize** (int) - Normalization flag. Defaults to 0. #### Solve_ZStressTensorIntegral Parameters - **which_layer** (int) - The index of the layer. ### Request Example ```python # Solve for Reflection and Transmission R, T = obj.RT_Solve(normalize=1) # Solve and get results by order Ri, Ti = obj.RT_Solve(byorder=1) # Get amplitudes at a specific layer and z-offset ai, bi = obj.GetAmplitudes(which_layer=1, z_offset=0.1) # Get reconstructed epsilon profile for a patterned layer ep_xx = obj.Return_eps(which_layer=1, Nx=64, Ny=64, component='xx') # Get Fourier amplitude of fields E_fourier, H_fourier = obj.Solve_FieldFourier(which_layer=1, z_offset=0.1) # Get fields in real space on grid points E_grid, H_grid = obj.Solve_FieldOnGrid(which_layer=1, z_offset=0.1) # Compute volume integral # Assuming Mx, My, Mz are defined convolution matrices # val = obj.Volume_integral(which_layer=1, Mx=Mx, My=My, Mz=Mz, normalize=1) # Compute Maxwell stress tensor Tx, Ty, Tz = obj.Solve_ZStressTensorIntegral(which_layer=1) ``` ### Response #### Success Response (200) - **R, T** (tuple of numpy.ndarray) - Reflection and Transmission coefficients. - **Ri, Ti** (tuple of numpy.ndarray) - Reflection and Transmission coefficients per order. - **ai, bi** (tuple of numpy.ndarray) - Amplitudes of forward and backward waves. - **ep** (numpy.ndarray) - Reconstructed epsilon profile. - **E, H** (tuple of numpy.ndarray) - Electric and Magnetic field components (Fourier or real space). - **val** (float) - Result of the volume integral. - **Tx, Ty, Tz** (tuple of numpy.ndarray) - Components of the Maxwell stress tensor. #### Response Example ```json { "R": [0.1, 0.2, ...], "T": [0.8, 0.7, ...] } ``` ``` -------------------------------- ### Download grcwa tarball Source: https://grcwa.readthedocs.io/en/latest/_sources/installation.rst.txt Download the source code as a tarball using curl. ```console $ curl -OJL https://github.com/weiliangjinca/grcwa/tarball/master ``` -------------------------------- ### Feed Epsilon Profile Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Provides the epsilon profile for a patterned layer. ```python # x is a 1D array: np.concatenate((epgrid1.flatten(),epgrid2.flatten(),...)) obj.GridLayer_geteps(x) ``` -------------------------------- ### Solve Reflectance and Transmittance Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Computes R and T values, with options for normalization and order-based output. ```python R, T = obj.RT_Solve(normalize = 1) ``` ```python Ri, Ti = obj.RT_Solve(byorder=1) # Ri(Ti) has length obj.nG, too see which order, check obj.G; too see which kx,ky, check obj.kx obj.ky ``` -------------------------------- ### Solve Fields in Fourier Space Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Computes field components in Fourier space. ```python E,H = obj.Solve_FieldFourier(which_layer,z_offset) #E = [Ex,Ey,Ez], H = [Hx,Hy,Hz] ``` -------------------------------- ### Normalize Output for RT Solve Source: https://grcwa.readthedocs.io/en/latest/usage.html Normalize the output of RT_Solve when the 0-th media is not vacuum or for oblique incidence by setting normalize=1. ```python R, T = obj.RT_Solve(normalize = 1) ``` -------------------------------- ### Solve Fields on Grid Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Computes field components on real-space grid points. ```python E,H = obj.Solve_FieldOnGrid(which_layer,z_offset) # #E = [Ex,Ey,Ez], H = [Hx,Hy,Hz] ``` -------------------------------- ### Add layers to RCWA object Source: https://grcwa.readthedocs.io/en/latest/readme.html Define the structure of the optical device by adding uniform and patterned layers to the RCWA object. Specify layer thicknesses, dielectric constants, and grid resolutions for patterned layers. ```python Np = 2 # number of patterned layers Nx = 100 Ny = 100 thick0 = 0.1 pthick = [0.2,0.3] thickN = 0.4 ep0 = 2. epN = 3. obj.Add_LayerUniform(thick0,ep0) for i in range(Np): obj.Add_LayerGrid(pthick[i],Nx,Ny) obj.Add_LayerUniform(thickN,epN) obj.Init_Setup() ``` -------------------------------- ### Define Non-Planewave Incidence Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Manually sets forward and backward incidence fields. ```python obj.a0 = ... # forward obj.bN = ... # backward, each have a length 2*obj.nG, for the 2 lateral directions ``` -------------------------------- ### Compute Volume Integration Source: https://grcwa.readthedocs.io/en/latest/_sources/usage.rst.txt Performs volume integration using a convolution matrix. ```python val = obj.Volume_integral(which_layer,Mx,My,Mz,normalize=1) ``` -------------------------------- ### Define patterned layer geometry Source: https://grcwa.readthedocs.io/en/latest/readme.html Create dielectric constant grids for patterned layers, defining shapes like circular or square holes. The grids are then flattened and passed to the RCWA object. ```python radius = 0.5 a = 0.5 ep1 = 4. ep2 = 6. epbkg = 1. # coordinate x0 = np.linspace(0,1.,Nx) y0 = np.linspace(0,1.,Ny) x, y = np.meshgrid(x0,y0,indexing='ij') # layer 1 epgrid1 = np.ones((Nx,Ny))*ep1 ind = (x-.5)**2+(y-.5)**2