wavesolve.FEsolver#
This page contains the documentation for the FEsolver submodule, which functionally defines different kinds of waveguides, enables the creation of custom waveguides, and handles mesh generation for finite element analysis.
Solve#
- wavesolve.FEsolver.solve_waveguide(mesh, wl, IOR_dict, Nmax=6, target_neff=None, solve_mode='sparse')#
given a mesh, propagation wavelength, and refractive index dictionary, solve for the scalar modes.
- Parameters:
mesh – mesh object corresponding to waveguide geometry
wl (float) – wavelength, defined in the same units as mesh point positions
IOR_dict (dict) – a dictionary assigning different named regions of the mesh different refractive index values
Nmax (int) – return only the <Nmax> largest eigenvalue/eigenvector pairs
target_neff (float or None) – search for modes with indices close to but below this value. if None, target_neff is set to the maximum index in the guide.
solve_mode (str) – use ‘sparse’ or ‘dense’ matrices when solving
- Returns:
a tuple containing:
eigvals: array of eigenvalues, descending order
eigvecs: array of corresponding eigenvectors (waveguide modes)
- Return type:
(tuple)
- wavesolve.FEsolver.solve_waveguide_vec(mesh, wl, IOR_dict, Nmax=6, target_neff=None, solve_mode='mixed')#
given a mesh, propagation wavelength, and refractive index dictionary, solve for the vector modes.
- Parameters:
mesh – mesh object corresponding to waveguide geometry
wl (float) – wavelength, defined in the same units as mesh point positions
IOR_dict (dict) – a dictionary assigning different named regions of the mesh different refractive index values
Nmax (int) – return only the <Nmax> largest eigenvalue/eigenvector pairs
target_neff (float or None) – search for modes with indices close to but below this value. if None, target_neff is set to the maximum index in the guide.
solve_mode (str) – ‘mixed’ combines a sparse linear solve and a dense eigensolve. ‘dense’ uses dense matrices for everything; default ‘mixed’
- Returns:
a tuple containing:
eigvals: array of eigenvalues, descending order
eigvecs: array of corresponding eigenvectors (waveguide modes)
- Return type:
(tuple)
Plot#
- wavesolve.FEsolver.plot_scalar_field(mesh, field, show_mesh=False, ax=None, res=100, bounds=None)#
plot a scalar field
- Parameters:
mesh – finite element mesh
field (array) – a 1D array corresponding to a scalar-valued field (e.g. eigenmode)
show_mesh (bool) – set True to additionally plot the mesh geometry
ax (matplotlib.axes or None) – optionally put the plots on an axis. if one axis is given, only the transverse part is plotted. if (ax0,ax1) is given, the longitudinal component is also plotted. if None, axes are made for both.
res (int) – grid resolution, make tuple to set xres and yres separately
bounds – 4-element array [xmin,xmax,ymin,ymax], setting plot boundary.
- wavesolve.FEsolver.plot_vector_field(mesh, field, show_mesh=False, ax=None, arrows=True, res=100, bounds=None, dec_factor=4)#
plot a vector field - transverse and longitudinal components.
- Parameters:
mesh – finite element mesh
field (array) – a 1D array corresponding to a vector-valued field (e.g. eigenmode) which encodes both transverse and longitudinal components
show_mesh (bool) – set True to additionally plot the mesh geometry
ax (matplotlib.axes or None) – optionally put the plots on mpl axis. if one axis is given, only the transverse part is plotted. if (ax0,ax1) is given, the longitudinal component is also plotted. if None, axes are made for both.
arrows (bool) – whether or not to overplot field arrows
res (int) – grid resolution, make tuple to set xres and yres separately
bounds – 4-element array [xmin,xmax,ymin,ymax], setting plot boundary.
dec_factor (int) – decimation factor for arrow plotting
Evaluate#
- wavesolve.FEsolver.evaluate(point, field, mesh)#
evaluate a field sampled over a finite element mesh at a given point.
- Parameters:
point – an [x,y] point, or an Nx2 array of points
field – a real-valued field represented on a finite-element mesh
mesh – the FE mesh, which has been sorted with sort_mesh().
- Returns:
the field evaluated at point(s)
- Return type:
(float or array)
- wavesolve.FEsolver.evaluate_grid(pointsx, pointsy, field, mesh)#
evaluate a field defined over a finite element mesh on a cartesian grid.
- Parameters:
pointsx – a 1D array of x points
pointsy – a 1D array of y points
field – a real-valued field represented on a finite-element mesh
mesh – the FE mesh, which has been sorted with sort_mesh().
- Returns:
a 2D or 3D array corresponding to field (scalar or vectorial), evaluated on the grid.
- Return type:
(array)
Misc.#
- wavesolve.FEsolver.count_modes(w, wl, IOR_dict)#
count the number of guided (non-spurious) modes. This function only works well for weakly guiding waveguides!
- Parameters:
w (array) – array of eigenvalues corresponding to the modes, assumed decreasing.
wl (float) – wavelength
IOR_dict (dict) – a dictionary assigning different named regions of the mesh different refractive index values
- wavesolve.FEsolver.isvectorial(field, mesh)#
determine if field is a vector or scalar field
- Parameters:
field (array) – electric field evaluated on a finite element mesh
mesh – the finite element mesh
- wavesolve.FEsolver.sort_mesh(mesh)#
create a bounding volume hierarchy tree for
meshand pass it into tomesh.tree. this is required for evaluations of fields on meshes. you usually don’t need to call this manually.- Parameters:
mesh – finite element mesh
- wavesolve.FEsolver.get_eff_index(wl, w)#
get effective refractive index from wavelength wl and eigenvlaue w
- Parameters:
wl (float) – wavelength
w (float or array) – eigenvalue(s)
- wavesolve.FEsolver.resample(field, mesh, newmesh)#
resample a finite element field onto a new mesh
- Parameters:
field – the finite element field to be resampled.
mesh – the finite element mesh on which <field> is defined.
newmesh – the new finite element mesh <field> should be sampled on.