nidn.trcwa.utils package
Submodules
nidn.trcwa.utils.fft_funs module
- nidn.trcwa.utils.fft_funs.Epsilon_fft(dN, eps_grid, G)
dN = 1/Nx/Ny For now, assume epsilon is diagonal; if epsilon has xz,yz component, just simply add them to off-diagonal eps2
- eps_grid is (1) for isotropic, a numpy 2d array in the format of (Nx,Ny),
for anisotropic, a list of numpy 2d array [(Nx,Ny),(Nx,Ny),(Nx,Ny)]
- nidn.trcwa.utils.fft_funs.get_conv(dN, s_in, G)
Attain convolution matrix dN = 1/Nx/Ny s_in: np.array of length Nx*Ny G: shape (nG,2), 2 for Lk1,Lk2 s_out: 1/N sum a_m exp(-2pi i mk/n), shape (nGx*nGy)
- nidn.trcwa.utils.fft_funs.get_fft(dN, s_in, G)
FFT to get Fourier components
s_in: np.2d array of size (Nx,Ny) G: shape (nG,2), 2 for Gx,Gy s_out: 1/N sum a_m exp(-2pi i mk/n), shape (nGx*nGy)
- nidn.trcwa.utils.fft_funs.get_ifft(Nx, Ny, s_in, G)
Reconstruct real-space fields
nidn.trcwa.utils.kbloch module
- nidn.trcwa.utils.kbloch.Gsel_circular(nG, Lk1, Lk2)
From Liu’s gsel.c. NG * abs(u x v) is approximately the area in k-space we will need cover with a circular disc. (u and v are the 2 shortest lattice vectors) From the area, we can find the radius (and round it up). Then, we can find the minimum extends in each of the two lattice directions.
- nidn.trcwa.utils.kbloch.Gsel_parallelogramic(nG, Lk1, Lk2)
From Liu’s gsel.c
- nidn.trcwa.utils.kbloch.Lattice_Reciprocate(L1, L2)
Given two lattice vectors L1,L2 in the form of (Lx,Ly), returns the reciprocate vectors Lk/(2*pi)
- nidn.trcwa.utils.kbloch.Lattice_SetKs(G, kx0, ky0, Lk1, Lk2)
Construct kx,ky including all relevant orders, given initial scalar kx,ky 2pi factor is now included in the returned kx,ky
- nidn.trcwa.utils.kbloch.Lattice_getG(nG, Lk1, Lk2, method=0)
The G is defined to produce the following reciprocal vector: k = G[:,0] Lk1 + G[:,1] Lk2 (both k and Lk don’t include the 2pi factor)
method:0 for circular truncation, 1 for parallelogramic truncation
nidn.trcwa.utils.torch_functions module
Utility functions to make torch operations compatible with numpy syntax.
- nidn.trcwa.utils.torch_functions.torch_dot(a, b)
Computes a dot product in torch that is compatible with numpy style syntax.
- Parameters
a (torch.tensor) – Tensor a in the dot product of a and b.
b (torch.tensor) – Tensor b in the dot product of a and b.
- Returns
Dot product of a and b
- Return type
torch.tensor
- nidn.trcwa.utils.torch_functions.torch_eye(size, dtype=None)
Implementation of torch.eye that returns a complex tensor. Else falls back on torch.eye.
- Parameters
shape (list) – Shape vector for identity matrix.
dtype (dtype) – Requested datatype.
- Returns
Initialized tensor with real part of the diagonal set to one and imaginary part of the diagonal set to zero, and zeros elsewhere
- Return type
torch.tensor
- nidn.trcwa.utils.torch_functions.torch_transpose(n_dimensional_tensor)
Custom transpose for torch as torch.transpose diverges from numpy, see https://github.com/pytorch/pytorch/issues/51280
- Parameters
n_dimensional_tensor (torch.tensor) – Tensor to transpose.
- Returns
Transposed tensor
- Return type
torch.tensor
- nidn.trcwa.utils.torch_functions.torch_zeros(shape, dtype)
Implementation of torch.zeros that returns a complex tensor. Else falls back on torch.zeros.
- Parameters
shape (list) – Shape vector for zeros tensor.
dtype (dtype) – Requested datatype.
- Returns
Initialized tensor with real and imaginary part set to zero
- Return type
torch.tensor