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

Fix Elmer & Palace tests #195

Merged
merged 4 commits into from
Oct 17, 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
1 change: 0 additions & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ execute:
- "*03_numerical_implantation*"
- "*02_model_extraction*"
- "*palace*"
- "*elmer_01_electrostatic*"
- "*fdtdz*"
# - "*sax_01_sax*"
# - "*20_schematic_driven_layout*"
Expand Down
3 changes: 1 addition & 2 deletions docs/notebooks/elmer_01_electrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
c.add_ports(cap.ports)
substrate = gf.components.bbox(bbox=simulation_box, layer=LAYER.WAFER)
c << substrate
c = c.flatten()
c.plot()

# %% [markdown]
Expand Down Expand Up @@ -135,7 +134,7 @@
"resolution": 40,
},
**{
f"bw{port}": {
f"bw__{port}": { # `__` is used as the layer–port delimiter for Elmer
"resolution": 20,
"DistMax": 30,
"DistMin": 10,
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/palace_01_electrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
c.add_ports(cap.ports)
substrate = gf.components.bbox(bbox=simulation_box, layer=LAYER.WAFER)
c << substrate
c.flatten()
c.plot()

# %% [markdown]
# ## Running the simulation
Expand Down Expand Up @@ -132,7 +132,7 @@
"resolution": 40,
},
**{
f"bw{port}": {
f"bw__{port}": { # `__` is used as the layer–port delimiter for Palace
"resolution": 20,
"DistMax": 30,
"DistMin": 10,
Expand Down
1 change: 0 additions & 1 deletion docs/notebooks/palace_02_fullwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@

substrate = gf.components.bbox(bbox=simulation_box, layer=LAYER.WAFER)
c << substrate
c.flatten()
c.show()

# %% [markdown]
Expand Down
6 changes: 2 additions & 4 deletions gplugins/elmer/get_capacitance.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def run_capacitive_simulation_elmer(
simulation_folder = Path(simulation_folder or temp_dir.name)
simulation_folder.mkdir(exist_ok=True, parents=True)

port_delimiter = "__" # won't cause trouble unlike #
filename = component.name + ".msh"
if mesh_file:
shutil.copyfile(str(mesh_file), str(simulation_folder / filename))
Expand All @@ -225,7 +226,7 @@ def run_capacitive_simulation_elmer(
type="3D",
filename=simulation_folder / filename,
layer_stack=layer_stack,
**(mesh_parameters or {}),
**((mesh_parameters or {}) | {"layer_port_delimiter": port_delimiter}),
)

# `interruptible` works on gmsh versions >= 4.11.2
Expand All @@ -248,9 +249,6 @@ def run_capacitive_simulation_elmer(
next(k for k, v in layer_stack.layers.items() if v.layer == port.layer)
for port in component.get_ports()
} # ports allowed only on metal
# TODO infer port delimiter from somewhere
# TODO raise error for port delimiters not supported by Elmer MATC or find how to escape
port_delimiter = "__"
metal_surfaces = [
e for e in mesh_surface_entities if any(ground in e for ground in ground_layers)
]
Expand Down
5 changes: 1 addition & 4 deletions gplugins/elmer/tests/test_elmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def get_reasonable_mesh_parameters(c: Component):
)


@pytest.mark.skip(reason="FIXME")
def test_elmer_capacitance_simulation_runs(geometry) -> None:
c = geometry
run_capacitive_simulation_elmer(
Expand All @@ -91,8 +90,7 @@ def test_elmer_capacitance_simulation_runs(geometry) -> None:
)


@pytest.mark.skip(reason="FIXME")
@pytest.mark.parametrize("n_processes", [(1), (2), (4)])
@pytest.mark.parametrize("n_processes", [(1), (2)])
def test_elmer_capacitance_simulation_n_processes(geometry, n_processes):
c = geometry
run_capacitive_simulation_elmer(
Expand All @@ -104,7 +102,6 @@ def test_elmer_capacitance_simulation_n_processes(geometry, n_processes):
)


@pytest.mark.skip(reason="FIXME")
@pytest.mark.parametrize("element_order", [(1), (2), (3)])
def test_elmer_capacitance_simulation_element_order(geometry, element_order) -> None:
c = geometry
Expand Down
3 changes: 3 additions & 0 deletions gplugins/gmsh/xy_xsection_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def xy_xsection_mesh(
n_threads: int = get_number_of_cores(),
port_names: list[str] | None = None,
gmsh_version: float | None = None,
layer_port_delimiter: str | None = None,
):
"""Mesh xy cross-section of component at height z.

Expand All @@ -93,6 +94,7 @@ def xy_xsection_mesh(
round_tol: during gds --> mesh conversion cleanup, number of decimal points at which to round the gdsfactory/shapely points before introducing to gmsh
simplify_tol: during gds --> mesh conversion cleanup, shapely "simplify" tolerance (make it so all points are at least separated by this amount)
atol: tolerance used to establish equivalency between vertices
layer_port_delimiter: Delimiter to use for new layers generated for ports: "layer{delimiter}port_name".
"""
if port_names:
mesh_component = gf.Component()
Expand All @@ -102,6 +104,7 @@ def xy_xsection_mesh(
component=mesh_component,
port_names=port_names,
layer_stack=layer_stack,
**(dict(delimiter=layer_port_delimiter) if layer_port_delimiter else {}),
)

# Fuse and cleanup polygons of same layer in case user overlapped them
Expand Down
3 changes: 3 additions & 0 deletions gplugins/gmsh/xyz_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def xyz_mesh(
port_names: List[str] | None = None,
edge_ports: List[str] | None = None,
gmsh_version: float | None = None,
layer_port_delimiter: str | None = None,
) -> bool:
"""Full 3D mesh of component.

Expand Down Expand Up @@ -184,6 +185,7 @@ def xyz_mesh(
}
gmsh_version: Gmsh mesh format version. For example, Palace requires an older version of 2.2,
see https://mfem.org/mesh-formats/#gmsh-mesh-formats.
layer_port_delimiter: Delimiter to use for new layers generated for ports: "layer{delimiter}port_name".
"""
if port_names:
mesh_component = gf.Component()
Expand All @@ -193,6 +195,7 @@ def xyz_mesh(
component=mesh_component,
port_names=port_names,
layer_stack=layer_stack,
**(dict(delimiter=layer_port_delimiter) if layer_port_delimiter else {}),
)

# Fuse and cleanup polygons of same layer in case user overlapped them
Expand Down
5 changes: 2 additions & 3 deletions gplugins/palace/get_capacitance.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def run_capacitive_simulation_palace(
simulation_folder = Path(simulation_folder or temp_dir.name)
simulation_folder.mkdir(exist_ok=True, parents=True)

port_delimiter = "__" # won't cause trouble unlike #
filename = component.name + ".msh"
if mesh_file:
shutil.copyfile(str(mesh_file), str(simulation_folder / filename))
Expand All @@ -244,7 +245,7 @@ def run_capacitive_simulation_palace(
layer_stack=layer_stack,
n_threads=n_processes,
gmsh_version=2.2, # see https://mfem.org/mesh-formats/#gmsh-mesh-formats
**(mesh_parameters or {}),
**((mesh_parameters or {}) | {"layer_port_delimiter": port_delimiter}),
)

# re-read the mesh
Expand All @@ -267,8 +268,6 @@ def run_capacitive_simulation_palace(
next(k for k, v in layer_stack.layers.items() if v.layer == port.layer)
for port in component.get_ports()
} # ports allowed only on metal
# TODO infer port delimiter from somewhere
port_delimiter = "__"
metal_surfaces = [
e for e in mesh_surface_entities if any(ground in e for ground in ground_layers)
]
Expand Down