Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer to keep dict #215

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions gplugins/gmsh/get_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,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 @@ -126,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 @@ -135,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
8 changes: 7 additions & 1 deletion gplugins/gmsh/uz_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ 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,
background_padding: Sequence[float, float, float, float, float, float] = (2.0,) * 6,
background_mesh_order: int | float = 2**63 - 1,
global_scaling: float = 1,
global_scaling_premesh: float = 1,
global_2D_algorithm: int = 6,
Expand All @@ -219,12 +221,15 @@ 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
default_resolution_max (float): gmsh maximal edge length
background_tag (str): name of the background layer to add (default: no background added)
background_padding (Tuple): [xleft, ydown, xright, yup] distances to add to the components and to fill with background_tag
background_mesh_order (int, float): mesh order to assign to the background
filename (str, path): where to save the .msh file
global_meshsize_array: np array [x,y,z,lc] to parametrize the mesh
global_meshsize_interpolant_func: interpolating function for global_meshsize_array
Expand Down Expand Up @@ -280,6 +285,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 All @@ -306,7 +312,7 @@ def uz_xsection_mesh(
},
dimension=2,
model=model,
mesh_order=np.inf,
mesh_order=background_mesh_order,
physical_name=background_tag,
)
polysurfaces_list.append(background_box)
Expand Down
8 changes: 7 additions & 1 deletion gplugins/gmsh/xy_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ 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,
background_padding: tuple[float, float, float, float, float, float] = (2.0,) * 6,
background_mesh_order: int | float = 2**63 - 1,
global_scaling: float = 1,
global_scaling_premesh: float = 1,
global_2D_algorithm: int = 6,
Expand All @@ -80,12 +82,15 @@ 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
default_resolution_max (float): gmsh maximal edge length
background_tag (str): name of the background layer to add (default: no background added)
background_padding (Tuple): [xleft, ydown, xright, yup] distances to add to the components and to fill with background_tag
background_mesh_order (int, float): mesh order to assign to the background
filename (str, path): where to save the .msh file
global_meshsize_array: np array [x,y,z,lc] to parametrize the mesh
global_meshsize_interpolant_func: interpolating function for global_meshsize_array
Expand Down Expand Up @@ -138,7 +143,7 @@ def xy_xsection_mesh(
* global_scaling_premesh,
zmin=(zmin - background_padding[2]) * global_scaling_premesh,
material=background_tag,
mesh_order=2**63 - 1,
mesh_order=background_mesh_order,
)
}
)
Expand All @@ -152,6 +157,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
13 changes: 11 additions & 2 deletions 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: map layer names 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,10 +138,12 @@ 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,
background_padding: tuple[float, float, float, float, float, float] = (2.0,) * 6,
background_mesh_order: int | float = 2**63 - 1,
global_scaling: float = 1,
global_scaling_premesh: float = 1,
global_2D_algorithm: int = 6,
Expand All @@ -157,10 +162,13 @@ def xyz_mesh(
Args:
component: gdsfactory component to mesh
layer_stack: 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: Pairs {"layername": {"resolution": float, "distance": "float}} to roughly control mesh refinement
default_characteristic_length: gmsh maximum edge length
background_tag: name of the background layer to add (default: no background added). This will be used as the material as well.
background_padding: [-x, -y, -z, +x, +y, +z] distances to add to the components and to fill with ``background_tag``
background_mesh_order (int, float): mesh order to assign to the background
global_scaling: factor to scale all mesh coordinates by (e.g. 1E-6 to go from um to m)
global_scaling_premesh: factor to scale all mesh coordinates by (e.g. 1E-6 to go from um to m).
Instead of using a gmsh-option which is only applied to meshes, this parameter can scale cad-exported files, e.g. .step files
Expand Down Expand Up @@ -246,7 +254,7 @@ def xyz_mesh(
* global_scaling_premesh,
zmin=(zmin - background_padding[2]) * global_scaling_premesh,
material=background_tag,
mesh_order=2**63 - 1,
mesh_order=background_mesh_order,
)
}
)
Expand All @@ -260,6 +268,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
Loading