# Multi-Physics

### FEM

Calculate the waveguide modes with the full-vector finite-element method. Requires a ‘3D’ license. The cross-section is meshed with triangles that follow every material interface, and the mesh is refined where the modes are under-resolved, as set by the `fem_*` settings in `settings()`. The saved fields, effective indices, losses and TE fractions are the same quantities, with the same normalization, as described under `FDM()`, so `get()`, `get_fields()`, `report()`, `plot()` and `EME()` work the same way. Calling `FEM()` sets the profile’s `solver` setting to ‘FEM’.

All `boundary_condition` values, PMLs, expansion regions, bends, lossy and anisotropic materials (including crystals tilted out of the cross-section with `theta`), and `heat()` and `electrostatic()` perturbations are supported. A symmetric or antisymmetric boundary on an axis whose mirror a crystal’s orientation breaks raises an error, since it would describe a different structure. Field plots sample the FEM solution at `x_resolution` and `y_resolution`, and `plot(mesh_display=True)` shows the triangle mesh.

The mesh is built by EMode’s own mesher, so a mesh, and every number solved on it, is the same on Windows, Linux and both kinds of Mac. Circles and ellipses are meshed to the true curve rather than to the polygon the FDM sees, and refinement adds its new boundary points on the curve. `fem_min_angle` (no triangle has an angle below it) and each shape’s `fem_resolution` (the largest triangle edge in that shape) keep their meaning.

With the default settings (3 points per wavelength, a 30 degree angle bound, three smoothing passes and three refinement passes), an effective index is within about 1e-4 of the converged value and a loss within about 1e-4 of its converged value, relatively, in a second or two for a typical cross-section. For more, set `fem_max_refinements='converge'`: the mesh is refined until every mode’s extrapolated effective index changes by less than 1e-8, which takes 20 s to a minute on a silicon or silicon nitride waveguide, and `get('resolution_report')` gives each mode’s estimated error. A round core converges more slowly, because its circle is meshed with straight edges between points on the curve, and stops near 1e-8 at about a million unknowns. The heat and electrostatic solves use first-order elements, so a quantity derived from them converges more slowly: the Phase Shifter example’s `V_pi L` changes by about 4e-4 between an eighth of its mesh sizes and the converged value.

* **Parameters:**
  * **profile** (*str* *or* *int*) – the stored profile to solve, in place (one saved with `label_profile()`), the same one `get(profile=...)` reads. An unknown name raises an error listing the stored profiles. To save a solve under a new name, call `label_profile()` after it. With `section`, the name the solved slice is stored under. Default: ‘_default’
  * **section** (*str*) – name of an EME section to solve a slice from, instead of the profile’s own settings/shapes, default: None
  * **propagation_distance** (*float*) – [nm] where along `section` to take the cross-section, default: None
  * **include_heat** (*bool*) – whether to include the temperature change from the most recent `heat()` solve, default: True
  * **include_static** (*bool*) – whether to apply the electro-optic (Pockels) permittivity perturbation from the most recent `electrostatic()` solve, default: True
  * **verbose** (*bool*) – print progress, default: True
  * **simulation_name** (*str*) – simulation name, default: ‘emode’
* **Returns:**
  a dict with `n_eff_tilde`, `TE_fraction`, `TE_indices`, `TM_indices`, `PML_indices` and `refinement` (`n_eff_history`, `num_dofs` and `num_elements` per refinement level, and `stopped_by`, the rule that ended refinement). The fields and the mesh are not part of the return value, since they run to tens of MB for many modes. Read the fields with `get()` or `get_fields()`, and draw them and the mesh with `plot()` (`mesh_display=True`). For a multi-wavelength profile, a `WavelengthDict` of these dicts, one per wavelength, indexable like a `dict[float, dict]`.

### heat

Run a steady-state thermal simulation of a waveguide cross-section. Requires a ‘3D’ license.

#### NOTE
Each `shape()` now accepts an input parameter called `heat_only` (default: False), which can be used to set additional shapes on top or bottom of the photonic layer stack. For example, common `heat_only` shapes are the substrate and metal heater layers.

Each `shape()` also now accepts an input parameter called `fem_resolution` (default: 500), which is used to refine the triangular mesh within certain shapes.

Every material carries `thermal_conductivity` (W/m·K), `resistivity` (Ohm·nm), `dn_dT` (1/K), and `eps_r_dc`. The defaults are `1e-10`, infinity, `0`, and `1.0` where no reliable published value has been entered. `dn_dT` and `eps_r_dc` are one value for every axis or three for the crystal’s x, y and z axes, and each principal index shifts by its own `dn_dT`. The mesh covers the shapes, so a region the shapes enclose without covering takes the background material’s properties. See the [Material Database](materials.md) page for values and sources.

* **Parameters:**
  * **min_angle** (*float*) – Smallest angle allowed in the triangle mesh, in degrees, at most 34. A larger value gives better-shaped triangles, and more of them. Default: 30.
  * **boundary_temperature** (*float*) – Fixed temperature boundary condition in ‘K’ set along each perimeter indicated by `boundaries`. Default: 298.
  * **boundaries** (*list* *[**str* *]*) – ‘top’, ‘bottom’, ‘left’, or ‘right’. Indicates which boundaries are set to the fixed temperature `boundary_temperature`. Default: [‘bottom’].
  * **verbose** (*bool*) – Control the display of the progress bar. Default: True.
  * **simulation_name** (*str*) – Simulation name. Default: ‘emode’.
* **Returns:**
  A dictionary/struct with the mesh points (`p`), mesh triangles (`t`), `temperature`, `thermal_conductivity`, and `heat_generation` arrays. It also includes the `boundary_temperature` and `boundaries` settings.

### electrostatic

Run a steady-state electrostatic simulation of a waveguide cross-section. Requires a ‘3D’ license.

#### NOTE
Each `shape()` also now accepts an input parameter called `voltage` (default: None), which is set to create electric field sources. Shapes with `voltage` left as None do not get a voltage boundary condition applied.

Each `shape()` also now accepts an input parameter called `fem_resolution` (default: 500), which is used to refine the triangular mesh within certain shapes.

Each material in the EMode material database now has `eps_r_dc` (relative permittivity at ~1 kHz), one value or three for the crystal’s x, y and z axes. The solve uses the in-plane (x, y) block of each material’s turned `eps_r_dc` tensor.

The DC field derived here perturbs the permittivity through each material’s linear electro-optic (Pockels) tensor `r` (`get('<material>')['r']`, m/V): $\Delta(1/n^2)_{ij} = \sum_k r_{ijk} E_k$, then $\Delta\varepsilon = -\varepsilon \cdot \Delta(1/n^2) \cdot \varepsilon$. `FDM()` applies this automatically on the next solve (`include_static=False` to skip it), the same way `heat()`’s temperature field perturbs the permittivity through `dn_dT`.

* **Parameters:**
  * **min_angle** (*float*) – Smallest angle allowed in the triangle mesh, in degrees, at most 34. A larger value gives better-shaped triangles, and more of them. Default: 30.
  * **verbose** (*bool*) – Control the display of the progress bar. Default: True.
  * **simulation_name** (*str*) – Simulation name. Default: ‘emode’.
* **Returns:**
  A dictionary/struct with the mesh points (`p`), mesh triangles (`t`), `voltage`, `eps_dc_grid` (the in-plane DC permittivity of each element, shape (2, 2, number of elements)), the per-element electric field (`Ex`, `Ey`, in V/nm), and `centroids` (element centers, in the optical window’s frame).
