Skip to content

Commit

Permalink
improve femwell plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Apr 10, 2024
1 parent bf17a75 commit ac0d984
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
11 changes: 8 additions & 3 deletions gplugins/femwell/mode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ def compute_component_slice_modes(
wavelength: float = 1.55,
num_modes: int = 4,
order: int = 1,
radius: float = np.inf,
wafer_padding: float = 2.0,
radius: float = np.inf,
metallic_boundaries: bool = False,
n_guess: float | None = None,
solver: str = "scipy",
**kwargs,
) -> Modes:
Expand All @@ -109,8 +111,10 @@ def compute_component_slice_modes(
wavelength: wavelength (um).
num_modes: number of modes to return.
order: order of the mesh elements. 1: linear, 2: quadratic.
radius: bend radius of the cross-section.
wafer_padding: padding beyond bbox to add to WAFER layers.
radius: bend radius of the cross-section.
metallic_boundaries: if True, will set the boundaries to be metallic.
n_guess: initial guess for the effective index.
solver: can be slepc or scipy.
Keyword Args:
Expand Down Expand Up @@ -160,14 +164,15 @@ def compute_component_slice_modes(
order=order,
radius=radius,
solver=solver,
n_guess=n_guess,
metallic_boundaries=metallic_boundaries,
)


if __name__ == "__main__":
import matplotlib.pyplot as plt

start = time.time()

filtered_layer_stack = LayerStack(
layers={
k: get_layer_stack().layers[k]
Expand Down
32 changes: 16 additions & 16 deletions gplugins/gmsh/get_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,27 @@ def get_mesh(

# 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
layer_physical_map = {
layer_name: layer_name for layer_name in layer_stack.layers.keys()
}
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

# 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
layer_meshbool_map = {
layer_name: True for layer_name in layer_stack.layers.keys()
}
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(
'For xy-meshing, a z-value must be provided via the float argument "z".'
)

return xy_xsection_mesh(
if type == "3D":
return xyz_mesh(
component=padded_component,
z=z,
layer_stack=layer_stack,
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
Expand All @@ -136,9 +130,15 @@ def get_mesh(
background_remeshing_file=background_remeshing_file,
**kwargs,
)
elif type == "3D":
return xyz_mesh(
elif type == "xy":
if z is None:
raise ValueError(
'For xy-meshing, a z-value must be provided via the float argument "z".'
)

return xy_xsection_mesh(
component=padded_component,
z=z,
layer_stack=layer_stack,
default_characteristic_length=default_characteristic_length,
resolutions=new_resolutions,
Expand Down
45 changes: 37 additions & 8 deletions notebooks/femwell_01_modes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
" \"clad\",\n",
" \"slab90\",\n",
" \"box\",\n",
" \"substrate\",\n",
" )\n",
" }\n",
")\n",
Expand All @@ -74,10 +75,10 @@
"].thickness = 0.09 # Perturb the layer_stack before simulating\n",
"\n",
"resolutions = {\n",
" \"core\": {\"resolution\": 0.02, \"distance\": 2},\n",
" \"clad\": {\"resolution\": 0.2, \"distance\": 1},\n",
" \"box\": {\"resolution\": 0.2, \"distance\": 1},\n",
" \"slab90\": {\"resolution\": 0.05, \"distance\": 1},\n",
" \"core\": {\"resolution\": 0.02, \"distance\": 1, \"SizeMax\": 0.2},\n",
" # \"clad\": {\"resolution\": 0.2, \"distance\": 1},\n",
" # \"box\": {\"resolution\": 0.2, \"distance\": 1},\n",
" # \"slab90\": {\"resolution\": 0.05, \"distance\": 1},\n",
"}"
]
},
Expand All @@ -92,8 +93,9 @@
" cross_section=rib(width=0.6),\n",
" layer_stack=filtered_layer_stack,\n",
" wavelength=1.55,\n",
" num_modes=4,\n",
" num_modes=1,\n",
" resolutions=resolutions,\n",
" n_guess=2.630929889650573,\n",
")"
]
},
Expand Down Expand Up @@ -137,17 +139,27 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"print(modes[0].n_eff)"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"## Sweep waveguide width"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"id": "10",
"metadata": {
"lines_to_next_cell": 2
},
Expand Down Expand Up @@ -176,7 +188,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"id": "11",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -196,6 +208,23 @@
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ac0d984

Please sign in to comment.