Skip to content

mesh

Thermal cross-section mesher: every layer a Region, named Window edges.

Builds the 2D triangle mesh a thermal solve runs on, from a plane section of a component through its layer stack:

  • every stack layer the plane cuts becomes a Region named after the layer — heaters, metals and vias included (Conductor model = Region), so they can carry a heat source and their own conductivity;
  • the full-width stack slabs the component does not draw (substrate, BOX, cladding) are laid across the Window and grouped by their material, as the Palace native-2D mesher does, and any area nothing claims becomes a background group ("air" by default);
  • the substrate is meshed to a Modelled depth below the rest of the stack, which is the solver's choice and not the wafer's thickness;
  • the four Window edges are named 1D groups bottom, top, left and right for the heat-sink and top/side boundary conditions;
  • sizes are capped per Region (fine in small drawn features, coarse in the slabs) and graded away from the drawn features, so a Window hundreds of microns deep stays at thousands, not millions, of triangles.

The mesh is written as msh 2.2 (the format the Palace pipeline writes), so the femwell adapter loads it too and the same mesher builds the optical Window of a thermo-optic solve. :func:build_cross_section_mesh returns it already loaded as a :class:CrossSectionMesh on skfem.MeshTri; scikit-fem is the optional femwell extra.

Classes:

Functions:

Attributes:

BOUNDARY_GROUPS module-attribute

BOUNDARY_GROUPS: tuple[str, ...] = ('bottom', 'top', 'left', 'right')

Names of the 1D groups on the four Window edges.

CrossSectionMesh dataclass

CrossSectionMesh(
    mesh: MeshTri,
    element_region: NDArray[str_],
    region_material: dict[str, str],
    boundary_facets: dict[str, NDArray[int64]],
    msh_path: Path,
    plane: str,
    window: tuple[float, float],
    z_range: tuple[float, float],
)

A meshed Cross-section, loaded and ready for a 2D solve.

Coordinates are in um: mesh.p[0] is the in-plane axis (y for an "x=..." plane, x for a "y=..." plane) and mesh.p[1] is the vertical z.

Attributes:

  • mesh (MeshTri) –

    The triangle mesh, in the msh file's triangle order.

  • element_region (NDArray[str_]) –

    Region name of every triangle.

  • region_material (dict[str, str]) –

    Stack material of every Region.

  • boundary_facets (dict[str, NDArray[int64]]) –

    Facet indices (into mesh.facets) of each Window edge, keyed bottom/top/left/right.

  • msh_path (Path) –

    The msh 2.2 file the mesh was read from.

  • plane (str) –

    The plane spec the section was cut at, e.g. "x=0".

  • window (tuple[float, float]) –

    In-plane extent (min, max) of the meshed Window (um).

  • z_range (tuple[float, float]) –

    Vertical extent (zmin, zmax) of the meshed Window (um).

Methods:

  • plot –

    Draw the triangles, coloured by Region, with a legend.

  • region_area –

    Total area of one Region in um^2.

  • region_mask –

    Boolean mask over the triangles of one Region.

regions property

regions: tuple[str, ...]

Names of the Regions on the mesh, sorted.

plot

plot(
    ax: Any = None,
    *,
    xlim: tuple[float, float] | None = None,
    zlim: tuple[float, float] | None = None,
) -> Any

Draw the triangles, coloured by Region, with a legend.

Parameters:

  • ax (Any, default: None ) –

    Matplotlib axes to draw on; a new figure when None.

  • xlim (tuple[float, float] | None, default: None ) –

    In-plane range (min, max) to show (um), e.g. to zoom on the heater; the whole Window when None.

  • zlim (tuple[float, float] | None, default: None ) –

    Height range (min, max) to show (um); the whole Window when None.

Returns:

  • Any –

    The matplotlib axes.

region_area

region_area(name: str) -> float

Total area of one Region in um^2.

Parameters:

  • name (str) –

    Region name.

Returns:

  • float –

    The summed area of the Region's triangles.

Raises:

  • ValueError –

    When the mesh has no Region of that name.

region_mask

region_mask(name: str) -> NDArray[bool_]

Boolean mask over the triangles of one Region.

Parameters:

  • name (str) –

    Region name.

Returns:

  • NDArray[bool_] –

    True for every triangle of the Region, in element order.

Raises:

  • ValueError –

    When the mesh has no Region of that name.

build_cross_section_mesh

build_cross_section_mesh(
    component: Component,
    stack: LayerStack,
    plane: str,
    *,
    window: tuple[float, float] | None = None,
    z_range: tuple[float, float] | None = None,
    depth: float | None = None,
    max_size: Mapping[str, float] | None = None,
    default_max_size: float | None = None,
    background: str = "air",
    output: Path | None = None,
    verbose: bool = False,
) -> CrossSectionMesh

Mesh a Cross-section of a component for a 2D thermal (or optical) solve.

Parameters:

  • component (Component) –

    The gdsfactory component to cut.

  • stack (LayerStack) –

    Layer stack giving each layer's z extent and material, and the full-width slabs (stack.dielectrics).

  • plane (str) –

    Plane spec, "x=<value>" or "y=<value>".

  • window (tuple[float, float] | None, default: None ) –

    In-plane (min, max) of the Window in um. Defaults to the drawn section's extent plus 20 um on each side.

  • z_range (tuple[float, float] | None, default: None ) –

    Vertical (zmin, zmax) of the Window in um. Defaults to the Modelled depth below the substrate top up to the top of the stack; give it to clip a small (e.g. optical) Window, whose edges then cut through the slabs.

  • depth (float | None, default: None ) –

    Modelled depth of the substrate in um, measured down from the bottom of the rest of the stack. Defaults to the thickness of the stack's substrate slab, or 100 um when the stack has none (a silicon substrate is then synthesised, with a warning).

  • max_size (Mapping[str, float] | None, default: None ) –

    Maximum element size in um per Region name, overriding the defaults.

  • default_max_size (float | None, default: None ) –

    Coarse element size in um for the slabs and the background, and the size the grading grows towards. Defaults to a tenth of the Window's larger dimension. Drawn Regions default to a quarter of their smallest feature, slabs to half their thickness, both capped by this.

  • background (str, default: 'air' ) –

    Region name and material of any Window area no layer or slab claims.

  • output (Path | None, default: None ) –

    Path of the msh 2.2 file to write. Defaults to a file in a new temporary directory.

  • verbose (bool, default: False ) –

    Print gmsh's meshing progress.

Returns:

  • CrossSectionMesh –

    The loaded mesh with its Regions, materials and Window edges.

Raises:

  • ValueError –

    When the plane is not an x/y plane, the plane cuts no drawn layer, or the Window is empty.

  • ImportError –

    When scikit-fem (the femwell extra) is missing.