Skip to content

Commit

Permalink
layernames to physical labels dict
Browse files Browse the repository at this point in the history
  • Loading branch information
simbilod committed Oct 9, 2023
1 parent 746eecc commit 15d9b80
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 3 deletions.
5 changes: 4 additions & 1 deletion gplugins/gmsh/define_polysurfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def define_polysurfaces(
polygons_dict: dict,
layer_stack: LayerStack,
layer_physical_map: dict,
model: Any,
resolutions: dict,
scale_factor: float = 1,
Expand All @@ -32,7 +33,9 @@ def define_polysurfaces(
model=model,
resolution=resolutions.get(layername, None),
mesh_order=layer_stack.layers.get(layername).mesh_order,
physical_name=layername,
physical_name=layer_physical_map[layername]
if layername in layer_physical_map
else layername,
)
)

Expand Down
15 changes: 15 additions & 0 deletions gplugins/gmsh/get_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_mesh(
component: ComponentSpec,
type: str,
layer_stack: LayerStack,
layer_physical_map: dict | None = None,
z: float | None = None,
xsection_bounds=None,
wafer_padding: float = 0.0,
Expand All @@ -35,6 +36,7 @@ def get_mesh(
component: component
type: one of "xy", "uz", or "3D". Determines the type of mesh to return.
layer_stack: LayerStack object containing layer information.
layer_physical_map: by default, physical are tagged with layername; this dict allows you to specify custom mappings.
z: used to define z-slice for xy meshing.
xsection_bounds: used to define in-plane line for uz meshing.
wafer_padding: padding beyond bbox to add to WAFER layers.
Expand Down Expand Up @@ -73,6 +75,16 @@ def get_mesh(
else:
new_resolutions = None

# Default layer labels
if layer_physical_map is None:
layer_physical_map = {}
for layer_name in layer_stack.layers.keys():
layer_physical_map[layer_name] = layer_name
else:
for layer_name in layer_stack.layers.keys():
if layer_name not in layer_physical_map.keys():
layer_physical_map[layer_name] = layer_name

if type == "xy":
if z is None:
raise ValueError(
Expand All @@ -85,6 +97,7 @@ def get_mesh(
layer_stack=layer_stack,
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
**kwargs,
)
elif type == "uz":
Expand All @@ -100,6 +113,7 @@ def get_mesh(
layer_stack=layer_stack,
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
**kwargs,
)
elif type == "3D":
Expand All @@ -108,6 +122,7 @@ def get_mesh(
layer_stack=layer_stack,
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
**kwargs,
)
else:
Expand Down
112 changes: 112 additions & 0 deletions gplugins/gmsh/tests/test_custom_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from __future__ import annotations

import gdsfactory as gf
from gdsfactory.pdk import get_layer_stack
from gdsfactory.technology import LayerStack

from gplugins.gmsh.get_mesh import get_mesh


def test_custom_physical_uz() -> None:
waveguide = gf.components.straight_pin(length=10, taper=None)

filtered_layer_stack = LayerStack(
layers={
k: get_layer_stack().layers[k]
for k in (
"slab90",
"core",
"via_contact",
)
}
)

layer_physical_map = {
"slab90": "silicon",
"core": "silicon",
"via_contact": "metal",
}

mesh = get_mesh(
type="uz",
component=waveguide,
xsection_bounds=[(4, -15), (4, 15)],
layer_stack=filtered_layer_stack,
layer_physical_map=layer_physical_map,
background_tag="Oxide",
filename="uzmesh_ref.msh",
)

for value in layer_physical_map.values():
assert value in mesh.cell_sets_dict.keys()


def test_custom_physical_xy() -> None:
waveguide = gf.components.straight_pin(length=10, taper=None)

filtered_layer_stack = LayerStack(
layers={
k: get_layer_stack().layers[k]
for k in (
"slab90",
"core",
"via_contact",
)
}
)

layer_physical_map = {
"slab90": "silicon",
"core": "silicon",
"via_contact": "metal",
}

mesh = get_mesh(
type="xy",
component=waveguide,
z=0.09,
layer_stack=filtered_layer_stack,
layer_physical_map=layer_physical_map,
background_tag="Oxide",
filename="xymesh.msh",
)

for value in layer_physical_map.values():
assert value in mesh.cell_sets_dict.keys()


def test_custom_physical_xyz() -> None:
waveguide = gf.components.straight_pin(length=10, taper=None)

filtered_layer_stack = LayerStack(
layers={
k: get_layer_stack().layers[k]
for k in (
"slab90",
"core",
"via_contact",
)
}
)

layer_physical_map = {
"slab90": "silicon",
"core": "silicon",
"via_contact": "metal",
}

mesh = get_mesh(
type="3D",
component=waveguide,
layer_stack=filtered_layer_stack,
layer_physical_map=layer_physical_map,
background_tag="Oxide",
filename="xyzmesh.msh",
)

for value in layer_physical_map.values():
assert value in mesh.cell_sets_dict.keys()


if __name__ == "__main__":
test_custom_physical_uz()
5 changes: 3 additions & 2 deletions gplugins/gmsh/tests/test_meshing_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from gdsfactory.pdk import get_layer_stack
from gdsfactory.technology import LayerStack

from gplugins.gmsh.xyz_mesh import xyz_mesh
from gplugins.gmsh.get_mesh import get_mesh


def test_gmsh_xyz_mesh() -> None:
Expand Down Expand Up @@ -43,7 +43,8 @@ def test_gmsh_xyz_mesh() -> None:
resolutions = {
"core": {"resolution": 0.3},
}
xyz_mesh(
get_mesh(
type="3D",
component=c,
layer_stack=filtered_layer_stack,
resolutions=resolutions,
Expand Down
2 changes: 2 additions & 0 deletions gplugins/gmsh/uz_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def uz_xsection_mesh(
component: ComponentOrReference,
xsection_bounds: tuple[tuple[float, float], tuple[float, float]],
layer_stack: LayerStack,
layer_physical_map: dict,
resolutions: dict | None = None,
default_characteristic_length: float = 0.5,
background_tag: str | None = None,
Expand Down Expand Up @@ -278,6 +279,7 @@ def uz_xsection_mesh(
model=model,
scale_factor=global_scaling_premesh,
resolutions=resolutions,
layer_physical_map=layer_physical_map,
)

# Add background polygon
Expand Down
2 changes: 2 additions & 0 deletions gplugins/gmsh/xy_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def xy_xsection_mesh(
component: ComponentOrReference,
z: float,
layer_stack: LayerStack,
layer_physical_map: dict,
resolutions: dict | None = None,
default_characteristic_length: float = 0.5,
background_tag: str | None = None,
Expand Down Expand Up @@ -150,6 +151,7 @@ def xy_xsection_mesh(
model=model,
scale_factor=global_scaling_premesh,
resolutions=resolutions,
layer_physical_map=layer_physical_map,
)

# Mesh
Expand Down

0 comments on commit 15d9b80

Please sign in to comment.