QGmshRenderer#

class QGmshRenderer(design: MultiPlanar, layer_types: dict | None = None, initiate=True, options: Dict = None)[source]#

Extends QRendererAnalysis class to export designs to Gmsh using the Gmsh python API.

Default Options:
  • x_buffer_width_mm – Buffer between max/min x and edge of ground plane, in mm

  • y_buffer_width_mm – Buffer between max/min y and edge of ground plane, in mm

  • mesh – to define meshing parameters
    • max_size – upper bound for the size of mesh node

    • min_size – lower bound for the size of mesh node

    • max_size_jj – maximum size of mesh nodes at jj

    • smoothing – mesh smoothing value

    • nodes_per_2pi_curve – number of nodes for every 2π radians of curvature

    • algorithm_3d – value to indicate meshing algorithm used by Gmsh

    • num_threads – number of threads for parallel meshing

    • mesh_size_fields – specify mesh size field parameters
      • min_distance_from_edges – min distance for mesh gradient generation

      • max_distance_from_edges – max distance for mesh gradient generation

      • distance_delta – delta change in distance with each consecutive step

      • gradient_delta – delta change in gradient with each consecutive step

  • colors – specify colors for the mesh elements, chips or layers
    • metal – color for metallized entities

    • jj – color for JJs

    • dielectric – color for dielectric entity

Parameters:
  • design ('MultiPlanar') – The design.

  • layer_types (Union[dict, None]) – the type of layer in the format: dict(metal=[…], dielectric=[…]). Defaults to None.

  • initiate (bool) – True to initiate the renderer (Default: False).

  • options (Dict, optional) – Used to override default options. Defaults to None.

Attributes

default_options = {'colors': {'dielectric': (180, 180, 180, 255), 'jj': (84, 140, 168, 150), 'metal': (84, 140, 168, 255)}, 'mesh': {'algorithm_3d': 10, 'max_size': '70um', 'max_size_jj': '5um', 'mesh_size_fields': {'distance_delta': '30um', 'gradient_delta': '3um', 'max_distance_from_edges': '130um', 'min_distance_from_edges': '10um'}, 'min_size': '5um', 'nodes_per_2pi_curve': 90, 'num_threads': 8, 'smoothing': 10}, 'x_buffer_width_mm': 0.2, 'y_buffer_width_mm': 0.2}#
design#

Return a reference to the parent design object.

element_extensions = {}#

Element extensions dictionary

element_table_data = {}#

Element table data.

initialized#

Returns boolean True if initialized successfully. False otherwise.

logger#

Returns the logger.

model#

Returns the name of the current model

modeler#

Returns an instance to the Gmsh modeler

name = 'gmsh'#

Name

options#

Options for the QRenderer.

Methods

add_endcaps(open_pins: list | None = None)[source]#

Create endcaps (rectangular cutouts) for all pins in the list open_pins and add them to layer_subtract_dict. Each element in open_pins takes on the form (component_name, pin_name) and corresponds to a single pin.

Parameters:

open_pins (Union[list, None], optional) – List of tuples of pins that are open. Defaults to None.

add_mesh(dim: int = 3, intelli_mesh: bool = True, custom_mesh_fn: callable | None = None)[source]#

Generate mesh for all geometries.

Parameters:
  • dim (int, optional) – Specify the dimension of mesh. Defaults to 3.

  • intelli_mesh (bool) – Set to mesh the geometries intelligently. True by default.

  • custom_mesh_fn (callable) – Custom meshing function specifying mesh size fields using Gmsh python script (for advanced users only)

add_table_data_to_QDesign(class_name: str)#

During init of renderer, this needs to happen. In particular, each renderer needs to update custom columns and values within QDesign.

Parameters:

class_name (str) – Name from cls.name for each renderer.

apply_changes_for_simulation(ignore_metal_volume: bool, draw_sample_holder: bool)[source]#

This function fragments interfaces to fuse the boundaries and assigns physical groups to be used by an FEM solvers for defining bodies and boundary conditions.

Parameters:
  • ignore_metal_volume (bool, optional) – ignore the volume of metals and replace it with a list of surfaces instead.

  • draw_sample_holder (bool) – To draw the sample holder box.

Raises:

ValueError – raised when self.layer_types isn’t set to a valid dictionary

assign_mesh_color()[source]#

Assign mesh color according to the type of layer specified by self.layer_types and colors taken from self._options as provided by the user.

assign_physical_groups(ignore_metal_volume: bool, draw_sample_holder: bool)[source]#

Assign physical groups to classify different geometries physically.

Parameters:
  • ignore_metal_volume (bool, optional) – ignore the volume of metals and replace it with a list of surfaces instead.

  • draw_sample_holder (bool) – To draw the sample holder box.

Raises:
  • ValueError – if self.layer_types is not a dict

  • ValueError – if layer number is not in self.layer_types

clear_design()[source]#

Clears the design in the current Gmsh model

close()[source]#

Public method to close the Gmsh renderer

define_mesh_properties()[source]#

Define properties for mesh depending on renderer options.

define_mesh_size_fields()[source]#

Define size fields for mesh varying the mesh density across the design.

draw_geometries(draw_sample_holder: bool, selection: list | None = None, open_pins: list | None = None, box_plus_buffer: bool = True, skip_junctions: bool = False, omit_ground_for_layers: list[int] | None = None)[source]#

This function draws the raw geometries in Gmsh as taken from the QGeometry tables and applies thickness depending on the layer-stack.

Parameters:
  • selection (Union[list, None], optional) – List of selected components to render. Defaults to None.

  • open_pins (Union[list, None], optional) – List of open pins to add endcaps. Defaults to None.

  • box_plus_buffer (bool, optional) – Set to True for adding buffer to chip dimensions. Defaults to True.

  • draw_sample_holder (bool) – To draw the sample holder box.

  • skip_junctions (bool, optional) – Set to True to sip rendering the junctions. Defaults to False.

  • omit_ground_for_layers (Optional[list[int]]) – omit rendering the ground plane for specified layers. Defaults to None.

export_geo_unrolled(filepath: str)[source]#

Export the Gmsh geometry as geo_unrolled file. Supported formats: .geo_unrolled

Parameters:

filepath (str) – path of the file to export geometry to

export_mesh(filepath: str, scaling_factor: float = 0.001)[source]#

Export mesh from Gmsh into a file. Supported formats: (.msh, .msh2, .mesh).

Parameters:
  • filepath (str) – path of the file to export mesh to.

  • scaling_factor (float) – specify a scaling factor for the mesh. Defaults to 1e-3.

fragment_interfaces(draw_sample_holder: bool)[source]#

Fragment Gmsh surfaces to ensure consistent tetrahedral meshing across interfaces between different materials.

Parameters:

draw_sample_holder (bool) – To draw the sample holder box.

get_all_metal_surfaces()[source]#
static get_renderer(name: str)#

Returns an already loaded and instantiated renderer.

Parameters:

name (str) – rendering name

Returns:

Renderer with the given name

Return type:

QRenderer

classmethod get_template_options(design: QDesign, render_template: Dict = None, logger_: Logger = None, template_key: str = None) Dict#

Creates template options for the Metal QRenderer class required for the class to function, based on the design template; i.e., be created, made, and rendered. Provides the blank option structure required.

The options can be extended by plugins, such as renderers.

Parameters:
  • design (QDesign) – A design class.

  • render_template (Dict, optional) – Template options to overwrite the class ones. Defaults to None.

  • logger (logging.Logger, optional) – A logger for errors. Defaults to None.

  • template_key (str, optional) – The design.template_options key identifier. If None, then use _get_unique_class_name(). Defaults to None.

Returns:

Dictionary of renderer’s default options based on design.template_options.

Return type:

Dict

get_thickness_for_layer_datatype(layer_num: int, datatype: int = 0) float[source]#

Function to get thickness of a particular layer and datatype from the layer stack.

Parameters:
  • layer_num (int) – layer number in the layer stack

  • datatype (int) – datatype in the layer stack

Returns:

returns the thickness value

Return type:

float

get_thickness_zcoord_for_layer_datatype(layer_num: int, datatype: int = 0) tuple[float, float][source]#

Function to get the thickness and z_coord of a particular layer and datatype from the layer stack.

Parameters:
  • layer_num (int) – layer number in the layer stack

  • datatype (int) – datatype in the layer stack

Returns:

returns the tuple (thickness, z_coord)

Return type:

tuple[float, float]

get_unique_component_ids(highlight_qcomponents: list | None = None) Tuple[list, int]#

Confirm the list doesn’t have names of components repeated. Confirm that the name of component exists in QDesign. If QDesign doesn’t contain any component, or if all components in QDesign are found in highlight_qcomponents, return an empty list; otherwise return a list of unique components to be sent to the renderer. The second returned item, an integer, specifies which of these 3 cases applies.

Parameters:

highlight_qcomponents (Union[list, None], optional) – Components to render. Defaults to None.

Returns:

Tuple: Empty or partial list of components in QDesign.
int: 0 subset selected

1 every component selected 2 invalid

Return type:

Tuple[list, int]

gmsh_occ_synchronize()[source]#

Synchronize Gmsh with the internal OpenCascade graphics engine

import_post_processing_data(filename: str, launch_gui: bool = True, close_gmsh_on_closing_gui: bool = False)[source]#

Import the post processing data for visualization in Gmsh.

Parameters:
  • filename (str) – a target file ending with ‘.msh’ extension

  • launch_gui (bool) – launch the Gmsh GUI. Defaults to True.

  • close_gmsh_on_closing_gui (bool) – finalize gmsh when the GUI is closed. Defaults to True.

Raises:

ValueError – raises when the input file isn’t a .msh file

isometric_projection()[source]#

Set the view in Gmsh to isometric view manually.

launch_gui()[source]#

Launch Gmsh GUI for viewing the model.

classmethod load()#

Load the renderer and register all its extensions. Only performed once.

Once complete, the renderer is added to the class attribute ‘__loaded_renderers__’ of QRenderer

Returns:

True if success, otherwise throws an error.

Return type:

bool

make_general_surface(curves: List[int]) int[source]#

Create a general Gmsh surface.

Parameters:

curves (List[int]) – List of Gmsh curves to make surface

Returns:

tag of created Gmsh surface

Return type:

int

make_poly_surface(points: List[ndarray], chip_z: float) int[source]#

Make a Gmsh surface for creating poly type QGeometries

Parameters:
  • points (List[np.ndarray]) – A list of 3D vectors (np.ndarray) defining polygon

  • chip_z (float) – z-coordinate of the chip

Returns:

tag of the created Gmsh surface

Return type:

int

parse_units_gmsh(_input: int | float | ndarray | list | tuple | str)[source]#

Helper function to parse numbers and units

Parameters:

_input (Union[int, float, np.ndarray, list, tuple, str]) – input to parse

Returns:

parsed input value

Return type:

Union[int, float, np.ndarray, list, tuple, str]

parse_value(value: Any | List | Dict | Iterable) Any#

Same as design.parse_value. See design for help.

Returns:

Parsed value of input.

Return type:

object

classmethod populate_element_extensions()#

Populate cls.element_extensions which will be used to create columns for tables in QGeometry tables.

The structure of cls.element_table_data should be same as cls.element_extensions.

remove_current_model()[source]#

Removes the current Gmsh model

render_component(component)[source]#
render_components(table_type: str)[source]#

Render components by breaking them down into individual elements.

Parameters:

table_type (str) – Table type (poly, path, or junction).

render_design(selection: list | None = None, open_pins: list | None = None, box_plus_buffer: bool = True, draw_sample_holder: bool = True, skip_junctions: bool = False, mesh_geoms: bool = True, ignore_metal_volume: bool = False, omit_ground_for_layers: list[int] | None = None)[source]#

Render the design in Gmsh and apply changes to modify the geometries according to the type of simulation. Simulation parameters provided by the user.

Parameters:
  • selection (Union[list, None], optional) – List of selected components to render. Defaults to None.

  • open_pins (Union[list, None], optional) – List of open pins to add endcaps. Defaults to None.

  • box_plus_buffer (bool, optional) – Set to True for adding buffer to chip dimensions. Defaults to True.

  • draw_sample_holder (bool, optional) – To draw the sample holder box. Defaults to True.

  • skip_junctions (bool, optional) – Set to True to sip rendering the junctions. Defaults to False.

  • mesh_geoms (bool, optional) – Set to True for meshing the geometries. Defaults to True.

  • ignore_metal_volume (bool, optional) – ignore the volume of metals and replace it with a list of surfaces instead. Defaults to False.

  • omit_ground_for_layers (Optional[list[int]]) – omit rendering the ground plane for specified layers. Defaults to None.

render_element(qgeom: Series, table_type: str)[source]#

Render the specified element

Parameters:
  • qgeom (pd.Series) – QGeometry element to be rendered

  • table_type (str) – Table type (poly, path, or junction).

render_element_junction(junc: Series)[source]#

Render an element of type: ‘junction’

Parameters:

junc (pd.Series) – Junction to render.

render_element_path(path: Series)[source]#

Render an element of type: ‘path’

Parameters:

path (pd.Series) – Path to render.

render_element_poly(poly: Series)[source]#

Render an element of type: ‘poly’

Parameters:

poly (pd.Series) – Poly to render.

render_layer(layer_number: int, datatype: int = 0)[source]#

Render the given layer number and datatype.

Parameters:
  • layer_number (int) – number of the layer to render

  • datatype (int) – number of the datatype. Defaults to 0.

Raises:

ValueError – if the required properties are not found in the layer-stack

render_layers(draw_sample_holder: bool, omit_layers: List[int] | None = None, box_plus_buffer: bool = True)[source]#

Render all chips of the design. calls render_chip to render the actual geometries

Parameters:
  • omit_layers (Optional[List[int]]) – List of layers to omit render. Renders all if [] or None is given. Defaults to None.

  • draw_sample_holder (bool) – To draw the sample holder box.

  • box_plus_buffer (bool, optional) – For adding buffer to chip dimensions. Defaults to True.

render_tables(skip_junction: bool = True)[source]#

Render components in design grouped by table type (path, poly, or junction).

save_screenshot(path: str | None = None, show: bool = True)[source]#

Save the screenshot.

Parameters:
  • path (str, optional) – Path to save location. Defaults to None.

  • show (bool, optional) – Whether or not to display the screenshot. Defaults to True.

start(force=False)#

Call any initialization (single run) step required to setup the renderer for the first execution, such as connecting to some API or COM, or importing the correct material libraries, etc.

Parameters:

force (bool) – If True, need to scrap the existing initialization and re-do If False, will start a new one only if none exists. Defaults to False.

Returns:

is the renderer initialized successfully (thus usable?)

Return type:

bool

stop()#

Any calls that one may want to make after a rendering is complete.

subtract_from_layers(omit_layers: list[int] | None = None)[source]#

Subtract the QGeometries in tables from the chip ground plane

Parameters:

omit_layers (Optional[List[int]]) – List of layers to omit render. Renders all if [] or None is given. Defaults to None.

update_options(render_options: Dict | None = None, render_template: Dict | None = None)#

If template options has not been set for this renderer, then gather all the default options for children and add to design. The GUI would use this to store the template options.

Then give the template options to render to store in self.options. Then user can over-ride the render_options.

Parameters:
  • render_options (Dict, optional) – If user wants to over-ride the template options. Defaults to None.

  • render_template (Dict, optional) – All the template options for each child. Defaults to None.