kqcircuits.simulations.export.elmer.gui_layout_export
Export a manually drawn KLayout layout as an Elmer simulation.
These helpers back the export_elmer.lym macro. They walk the element hierarchy of a top cell, place
simulation ports at launchers and qubit junctions, work out the simulation box from the launcher positions,
and hand the result to export_elmer(). The logic lives here, separate from the macro, so it can be
exercised without the KLayout GUI.
Elements are identified both from live PCell data (the usual case when a design is open in the GUI) and, as a fallback, from the cell name when the layout has been flattened or loaded from a file without PCell context.
- kqcircuits.simulations.export.elmer.gui_layout_export.default_workflow()[source]
Return the default Elmer workflow used by the GUI export.
- kqcircuits.simulations.export.elmer.gui_layout_export.default_mesh_size()[source]
Return the default mesh size dictionary, refined at the metal edges.
- kqcircuits.simulations.export.elmer.gui_layout_export.default_wave_equation_solution(target_frequency=5.0, mesh_size=None)[source]
Return the default Elmer wave equation solution used by the GUI export.
A first order basis is used because the GUI models are large.
mesh_sizedefaults todefault_mesh_size().- Parameters:
target_frequency – solver frequency in GHz.
mesh_size – Gmsh mesh size dictionary, defaults to
default_mesh_size().
- kqcircuits.simulations.export.elmer.gui_layout_export.collect_ports(top_cell)[source]
Walk
top_celland build the simulation ports from launchers and qubits.Returns a tuple
(ports, edge_directions, edge_footprints).portsis the list ofPort.edge_directionsmaps each EdgePort number to its outwardpya.DVector, used to place that port on the box edge.edge_footprintsmaps each EdgePort number to that launcher’s global bounding box (pya.DBox), used to check the box edge still passes through the launcher. Launchers and qubits are treated as leaves, every other instance is descended into so elements nested in sub designs are still found.
- kqcircuits.simulations.export.elmer.gui_layout_export.simulation_box(top_cell, ports, edge_directions, edge_footprints, margin=100.0)[source]
Return the simulation box as a
pya.DBoxand place the edge ports on its rim.The box starts from the cell bounding box grown by
margin. Each side that faces a launcher is moved to the EdgePort closest to the centre on that side, so the launcher nearest the design sits exactly on the rim. Launchers further out then stick partially outside the box, which is fine as long as the rim still crosses the launcher, so a point inside it lands on the box. Every EdgePort on a side is then projected onto that side. Manual placement is rarely pixel perfect, so this projection is what guarantees each EdgePort sits on the box rim, which the Elmer export requires.A clear error is raised when the launcher positions do not admit a valid box: when a side has no room against the opposite side, when the rim cannot pass through a launcher because it sits too far out relative to its neighbour on the same side or when the horizontal and vertical launchers do not agree on one box, so a launcher falls past a box corner and has no point on the finite rim.
The
signal_locationof the affected EdgePorts is updated in place.
- kqcircuits.simulations.export.elmer.gui_layout_export.export_open_layout_to_elmer(top_cell, path, name='gui_simulation', target_frequency=5.0, mesh_size=None, solution=None, workflow=None, margin=100.0)[source]
Export the geometry in
top_cellas an Elmer wave equation simulation.- Parameters:
top_cell – the top cell whose geometry is exported. The cell is modified, so the macro passes a copy.
path – directory the simulation files are written to. Must not already exist.
name – simulation name, also the file name stem.
target_frequency – solver frequency in GHz, used for the default solution.
mesh_size – Gmsh mesh size dictionary for the default solution, defaults to
default_mesh_size().solution – Elmer solution object, defaults to
default_wave_equation_solution()built fromtarget_frequencyandmesh_size.workflow – Elmer workflow dictionary, defaults to
default_workflow().margin – distance in micrometers added around the geometry on sides without a launcher.
- Returns:
Path to the written simulation directory.
- Raises:
FileExistsError – if
pathalready exists, so an earlier export is not overwritten silently.