nidn.trcwa package
Subpackages
Submodules
nidn.trcwa.compute_spectrum module
nidn.trcwa.compute_target_frequencies module
- nidn.trcwa.compute_target_frequencies.compute_target_frequencies(min_physical_wl: float, max_physical_wl: float, N_freq: int, distribution: str)
Computes the target frequencies for a given set of physical frequencies.
- Parameters
min_physical_wl (float) – Minimum physical frequency in the target spectrum.
max_physical_wl (float) – Maximum physical frequency in the target spectrum.
N_freq (int) – The number of target frequencies.
distribution (str) – The distribution of the target frequencies. Either linear or log.
- Returns
Corresponding target frequencies
- Return type
np.array
nidn.trcwa.constants module
nidn.trcwa.init_trcwa module
nidn.trcwa.load_material_data module
nidn.trcwa.trcwa module
- nidn.trcwa.trcwa.GetSMatrix(indi, indj, q_list, phi_list, kp_list, thickness_list)
Gets the S matrices, S_ij: size 4n*4n.
- Parameters
indi (int) – Start layer index.
indj (int) – End layer index. Must be >= indi.
() (thickness_list) –
() –
() –
() – List of thicknesses for each layer in the stack.
- Returns
S11, S12, S21, S22
- Return type
torch.tensor, torch.tensor, torch.tensor, torch.tensor
- nidn.trcwa.trcwa.GetZPoyntingFlux(ai, bi, omega, kp, phi, q, byorder=0)
Returns 2S_z/A, following Victor Liu’s notation.
- Parameters
() (q) –
() –
omega (float) – The angular frequency.
() –
() –
() –
byorder (int, optional) – If the Poynting flux is to be given for each order (byorder > 0) or summed (= 0). Defaults to 0.
- Returns
The Poynting flux in the forward and backward direction, given as a number or a list of numbers
- Return type
torch.tensor, torch.tensor
- nidn.trcwa.trcwa.Gmeshgrid(x)
.
- Parameters
() (x) –
- Returns
qi, qj
- Return type
torch.tensor, torch.tensor
- nidn.trcwa.trcwa.MakeKPMatrix(omega, layer_type, epinv, kx, ky)
Makes KP matrix.
- Parameters
omega (float) – The angular frequency.
layer_type (int) – Uniform or patterned layer. Set to 0 for uniform layers and >0 for patterned.
() (ky) –
() –
() –
- Return type
torch.tensor
- nidn.trcwa.trcwa.Matrix_zintegral(q, thickness, shift=1e-12)
Generate matrix for z-integral.
- Parameters
() (q) –
thickness (float) – Thickness of the layer of interest.
shift (float, optional) – . Defaults to 1e-12.
- Returns
Matrix for z-integral
- Return type
torch.tensor
- nidn.trcwa.trcwa.SolveExterior(a0, bN, q_list, phi_list, kp_list, thickness_list)
Given a0, bN, solve for b0, aN.
- Parameters
() (thickness_list) –
() –
() –
() –
() –
() – List of thicknesses for each layer in the stack.
- Returns
aN, b0
- Return type
torch.tensor, torch.tensor
- nidn.trcwa.trcwa.SolveInterior(which_layer, a0, bN, q_list, phi_list, kp_list, thickness_list)
Given a0, bN, solve for ai, bi
- Parameters
which_layer (int) – The layer to solve for. Layer numbering starts from 0.
() (thickness_list) –
() –
() –
() –
() –
() – List of thicknesses for each layer in the stack.
- Returns
ai, bi
- Return type
torch.tensor, torch.tensor
- nidn.trcwa.trcwa.SolveLayerEigensystem(omega, kx, ky, kp, ep2)
Solves the eigensystem.
- Parameters
omega (float) – The angular frequency. Unused (from GRCWA).
() (ep2) –
() –
() –
() –
- Returns
q, phi
- Return type
torch.tensor, torch.tensor
- nidn.trcwa.trcwa.SolveLayerEigensystem_uniform(omega, kx, ky, epsilon)
Solves the eigensystem for uniform layers.
- Parameters
omega (float) – The angular frequency.
() (epsilon) –
() –
() –
- Returns
q, phi
- Return type
torch.tensor, torch.tensor
- class nidn.trcwa.trcwa.TRCWA(nG, L1, L2, freq, theta, phi, verbose=1)
Bases:
object
- Add_LayerFourier(thickness, params)
- Add_LayerGrid(thickness, Nx, Ny)
- Add_LayerUniform(thickness, epsilon)
- GetAmplitudes(which_layer, z_offset)
To get the Fourier amplitude of the eigenvectors at some layer and at some zoffset. Returns the raw mode amplitudes within a particular layer. For uniform (unpatterned) layers, the modes are simply the diffracted orders The first value is guaranteed to be the straight transmitted or specularly reflected diffraction order. For patterned layers, there is typically no meaningful information in these amplitudes.
- Parameters
which_layer (int) – Which layer to return the Fourier amplitude from.
z_offset (float) – The z-offset at which to obtain the mode amplitudes. Must be 0 < z_offset < layer thickness.
- Returns
ai, bi; containing the complex amplitudes of each forward and backward mode
- Return type
torch.tensor
- GetAmplitudes_noTranslate(which_layer)
To get the amplitude of the eigenvectors at some layer.
- Parameters
which_layer (int) – Which layer to return the Fourier amplitude from.
- Returns
ai, bi; each containing the complex amplitudes of each forward and backward mode
- Return type
torch.tensor
- GridLayer_geteps(ep_all)
Fourier transform + eigenvalue for grid layer.
- Parameters
ep_all (torch.tensor) – A tensor containing all epsilon values.
- Init_Setup(Pscale=1.0, Gmethod=0)
Set up the reciprocal lattice, compute eigenvalues for uniform layers, and initialize vectors for patterned layers.
- Parameters
Pscale (float, optional) – To scale the periodicity in both lateral directions simultaneously (as an autogradable parameter). Period will be Pscale*Lx and Pscale*Ly.
Gmethod (int, optional) – Fourier space truncation scheme; 0 for circular, 1 for rectangular.
- MakeExcitationPlanewave(p_amp, p_phase, s_amp, s_phase, order=0, direction='forward')
Sets the excitation to be a planewave incident upon the front (first layer specified) or back of the structure. If both tilt angles are specified to be zero, then the planewave is normally incident with the electric field polarized along the x-axis for the p-polarization. The phase of each polarization is defined at the origin (z = 0).
- Parameters
p_amp (complex float) – The electric field amplitude of the p-polarizations of the planewave. Is a complex number with absolute value between 0 and 1.
p_phase (float) – Phase of the p-polarized part of the light.
s_amp (complex float) – The electric field amplitude of the s-polarizations of the planewave. Is a complex number with absolute value between 0 and 1.
s_phase (float) – Phase of the s-polarized part of the light.
order (int, optional) – A positive integer specifying which order (mode index) to excite. Defaults to 0.
direction (string, optional) – The direction of the planewave (forward is incident upon the front). Defaults to “forward”.
- RT_Solve(normalize=0, byorder=0)
Reflection and transmission power computation. Returns 2R and 2T, following Victor Liu’s notation (https://web.stanford.edu/group/fan/S4/python_api.html?highlight=power#S4.Simulation.GetPowerFlux).
- Parameters
normalize (int, optional) – To normalize the output when the 0-th media is not vacuum, or for oblique incidence. If normalize = 1, the output will be divided by n[0]*cos(theta). Defaults to 0.
byorder (int, optional) – To get Poynting flux by order. If 0, the total power is computed. Defaults to 0.
- Returns
Reflection power, Transmission power
- Return type
torch.tensor
- Return_eps(which_layer, Nx, Ny, component='xx')
Used to get real-space epsilon profile reconstructured from the truncated Fourier orders.
- Parameters
which_layer (int) – Which layer to return the epsilon values from.
Nx (int) – Grid points within the unit cell in the x direction.
Ny (int) – Grid points within the unit cell in the y direction.
component (string, optional) – For patterned layer, component = ‘xx’,’xy’,’yx’,’yy’,’zz’. For uniform layer, currently it’s assumed to be isotropic. Defaults to “xx”.
- Returns
Real-space epsilon profile
- Return type
torch.tensor
- Solve_FieldFourier(which_layer, z_offset)
Returns the field amplitude in Fourier space: [Ex,Ey,Ez], [Hx,Hy,Hz] :param which_layer: Which layer to return the field amplitude from. :type which_layer: int :param z_offset: The z-offset at which to obtain the field amplitude. Must be 0 < z_offset < layer thickness. Can be a single number or a list of numbers. :type z_offset: torch.tensor
- Returns
Tensors containing the field amplitudes [Ex,Ey,Ez], [Hx,Hy,Hz] in Fourier space
- Return type
torch.tensor
- Solve_FieldOnGrid(which_layer, z_offset, Nxy=None)
To get fields in real space on grid points. If single z_offset, the output is [[Ex,Ey,Ez], [Hx,Hy,Hz]]. If z_offset is a list, the output os [[[Ex1,Ey1,Ez1],[Hx1,Hy1,Hz1]], [[Ex2,Ey2,Ez2],[Hx2,Hy2,Hz2]], …].
- Parameters
which_layer (int) – Which layer to return the field amplitude from.
z_offset (torch.tensor) – The z-offset at which to obtain the field amplitude. Must be 0 < z_offset < layer thickness. Can be a single number or a list of numbers.
Nxy (torch.tensor, optional) – Nxy = [Nx,Ny], if not supplied, will use the number in patterned layer.
- Returns
Tensor containing the field amplitudes [[Ex,Ey,Ez], [Hx,Hy,Hz]] in Fourier space for each z-offset
- Return type
torch.tensor
- Solve_ZStressTensorIntegral(which_layer)
To compute the Maxwell stress tensor, integrated over the z-plane. Returns the integral of the electromagnetic stress tensor over a unit cell surface normal to the z-direction. Returns 2F_x,2F_y,2F_z, integrated over the z-plane.
- Parameters
which_layer (int) – The layer in which the integration surface lies.
- Returns
The real and imaginary parts of the x-, y-, and z-components of the stress tensor integrated over the specified surface, assuming a unit normal vector in the +z direction.
- Return type
torch.tensor
- Volume_integral(which_layer, Mx, My, Mz, normalize=0)
To get volume integration with respect to some convolution matrix M defined for 3 directions, respectively. Returns the volume integral of a particular density over a unit cell throughout the entire thickness of a layer. Mxyz is the convolution matrix. This function computes 1/Aint_V Mx|Ex|^2+My|Ey|^2+Mz|Ez|^2. To be consistent with Poynting vector defintion here, the absorbed power will be just omega*output.
- Parameters
which_layer (int) – Which layer to get the volume integral from.
() (Mz) – Some convolution matrix M defined for the x-direction.
() – Some convolution matrix M defined for the y-direction.
() – Some convolution matrix M defined for the z-direction.
normalize (int, optional) – If 1, the return value is normalized according to self.normalization. Defaults to 0.
- Returns
Integration value.
- Return type
float
- nidn.trcwa.trcwa.TranslateAmplitudes(q, thickness, dz, ai, bi)
- Parameters
() (bi) – q for the layer of interest.
thickness (float) – The thickness of the layer of interest.
dz (float) – The z-offset at which to translate the amplitudes.
() –
() –
- Returns
aim, bim
- Return type
torch.tensor, torch.tensor