Skip to content

Commit

Permalink
layer_meshbool_map to define cad entities that don't get meshed
Browse files Browse the repository at this point in the history
  • Loading branch information
simbilod committed Oct 31, 2023
2 parents 4c8ffc8 + f5bf7a6 commit f443f20
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gplugins/gmsh/define_polysurfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def define_polysurfaces(
polygons_dict: dict,
layer_stack: LayerStack,
layer_physical_map: dict,
layer_meshbool_map: dict,
model: Any,
resolutions: dict,
scale_factor: float = 1,
Expand Down Expand Up @@ -36,6 +37,9 @@ def define_polysurfaces(
physical_name=layer_physical_map[layername]
if layername in layer_physical_map
else layername,
mesh_bool=layer_meshbool_map[layername]
if layername in layer_meshbool_map
else True,
)
)

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 @@ -23,6 +23,7 @@ def get_mesh(
type: str,
layer_stack: LayerStack,
layer_physical_map: dict | None = None,
layer_meshbool_map: dict | None = None,
z: float | None = None,
xsection_bounds=None,
wafer_padding: float = 0.0,
Expand All @@ -37,6 +38,7 @@ def get_mesh(
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.
layer_meshbool_map: by default, all polygons on layer_stack layers are meshed; this dict allows you set True of False to the meshing of given layers.
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 @@ -85,6 +87,16 @@ def get_mesh(
if layer_name not in layer_physical_map.keys():
layer_physical_map[layer_name] = layer_name

# Default meshing flags (all True)
if layer_meshbool_map is None:
layer_meshbool_map = {}
for layer_name in layer_stack.layers.keys():
layer_meshbool_map[layer_name] = True
else:
for layer_name in layer_stack.layers.keys():
if layer_name not in layer_physical_map.keys():
layer_meshbool_map[layer_name] = True

if type == "xy":
if z is None:
raise ValueError(
Expand All @@ -98,6 +110,7 @@ def get_mesh(
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
**kwargs,
)
elif type == "uz":
Expand All @@ -114,6 +127,7 @@ def get_mesh(
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
**kwargs,
)
elif type == "3D":
Expand All @@ -123,6 +137,7 @@ def get_mesh(
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
**kwargs,
)
else:
Expand Down
4 changes: 4 additions & 0 deletions gplugins/gmsh/uz_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def uz_xsection_mesh(
xsection_bounds: tuple[tuple[float, float], tuple[float, float]],
layer_stack: LayerStack,
layer_physical_map: dict,
layer_meshbool_map: dict,
resolutions: dict | None = None,
default_characteristic_length: float = 0.5,
background_tag: str | None = None,
Expand All @@ -219,6 +220,8 @@ def uz_xsection_mesh(
component (Component): gdsfactory component to mesh
xsection_bounds (Tuple): Tuple [[x1,y1] , [x2,y2]] parametrizing the line u
layer_stack (LayerStack): gdsfactory LayerStack to parse
layer_physical_map: map layer names to physical names
layer_meshbool_map: map layer names to mesh_bool (True: mesh the prisms, False: don't mesh)
resolutions (Dict): Pairs {"layername": {"resolution": float, "distance": "float}} to roughly control mesh refinement
mesh_scaling_factor (float): factor multiply mesh geometry by
default_resolution_min (float): gmsh minimal edge length
Expand Down Expand Up @@ -280,6 +283,7 @@ def uz_xsection_mesh(
scale_factor=global_scaling_premesh,
resolutions=resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
)

# Add background polygon
Expand Down
4 changes: 4 additions & 0 deletions gplugins/gmsh/xy_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def xy_xsection_mesh(
z: float,
layer_stack: LayerStack,
layer_physical_map: dict,
layer_meshbool_map: dict,
resolutions: dict | None = None,
default_characteristic_length: float = 0.5,
background_tag: str | None = None,
Expand All @@ -80,6 +81,8 @@ def xy_xsection_mesh(
component (Component): gdsfactory component to mesh
z (float): z-coordinate at which to sample the LayerStack
layer_stack (LayerStack): gdsfactory LayerStack to parse
layer_physical_map: map layer names to physical names
layer_meshbool_map: map layer names to mesh_bool (True: mesh the prisms, False: don't mesh)
resolutions (Dict): Pairs {"layername": {"resolution": float, "distance": "float}} to roughly control mesh refinement
mesh_scaling_factor (float): factor multiply mesh geometry by
default_resolution_min (float): gmsh minimal edge length
Expand Down Expand Up @@ -152,6 +155,7 @@ def xy_xsection_mesh(
scale_factor=global_scaling_premesh,
resolutions=resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
)

# Mesh
Expand Down
7 changes: 6 additions & 1 deletion gplugins/gmsh/xyz_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def define_prisms(
layer_polygons_dict: dict,
layer_stack: LayerStack,
layer_physical_map: dict,
layer_meshbool_map: dict,
model: Any,
resolutions: dict,
scale_factor: float = 1,
Expand All @@ -85,7 +86,6 @@ def define_prisms(
Args:
layer_polygons_dict: dictionary of polygons for each layer
layer_stack: gdsfactory LayerStack to parse
layer_physical_map: dict mapping layernames to physical_names
model: meshwell Model object
resolutions: Pairs {"layername": {"resolution": float, "distance": "float}} to roughly control mesh refinement.
scale_factor: scaling factor to apply to the polygons (default: 1)
Expand Down Expand Up @@ -125,6 +125,9 @@ def define_prisms(
physical_name=layer_physical_map[layername]
if layername in layer_physical_map
else layername,
mesh_bool=layer_meshbool_map[layername]
if layername in layer_meshbool_map
else True,
)
)

Expand All @@ -135,6 +138,7 @@ def xyz_mesh(
component: ComponentOrReference,
layer_stack: LayerStack,
layer_physical_map: dict,
layer_meshbool_map: dict,
resolutions: dict | None = None,
default_characteristic_length: float = 0.5,
background_tag: str | None = None,
Expand Down Expand Up @@ -260,6 +264,7 @@ def xyz_mesh(
scale_factor=global_scaling_premesh,
resolutions=resolutions,
layer_physical_map=layer_physical_map,
layer_meshbool_map=layer_meshbool_map,
)

# Add edgeports
Expand Down

0 comments on commit f443f20

Please sign in to comment.