GMSHmaker#

class zeroheliumkit.fem.gmsher.GMSHmaker(extrude: ExtrudeSettings, surfaces: SurfaceSettings = None, pecs: PECSettings = None, pmcs: PMCSetting = None, mesh: MeshSettings = None, save: dict = {'dir': 'dump', 'filename': 'device'}, open_gmsh: bool = False, debug_mode: bool = False)[source]#

Bases: object

GMSHmaker class constructs 3D geometry and mesh using GMSH Python API.

Parameters:
  • layout (Structure | Entity) – geometry design

  • extrude_config (dict) – configuration for extruding 2D polygons into 3D volumes

  • electrodes_config (dict) – configuration for defining physical surfaces for electrodes

  • mesh_params (tuple) – parameters for mesh generation

  • additional_surfaces (dict, optional) – additional surfaces to be included in the geometry. Defaults to None.

  • savedir (str, optional) – directory to save the mesh file. Defaults to “dump”.

  • configdir (str, optional) – directory to save the configuration file. Defaults to “config”.

  • filename (str, optional) – name of the mesh file. Defaults to “device”.

Methods

build_additional_gmsh_surfaces()

Adds additional surfaces to the Gmsh model based on the provided surface configurations.

build_gmsh_lines(point_ids, closed)

Creates Gmsh lines connecting the given point IDs.

build_gmsh_points(coordinates[, meshSize])

Creates Gmsh points based on the given coordinates.

build_gmsh_surface(base_polygon, base_z)

Creates a Gmsh surface based on the given base_polygon and z-coordinate.

build_gmsh_volume(base_polygon, base_z, height)

Creates 3D gmsh Volume by extruding shapely Polygon.

build_gmsh_volumes_from_plan(plan, ...[, ...])

Build multiple Gmsh volumes and register them in the volume registry.

create_PhysicalSurfaces()

Defines the physical Surfaces, where voltages will be applied.

create_PhysicalSurfaces_for_pmcs()

Defines the physical Surfaces for PMC boundaries.

create_PhysicalVolumes(volumes)

Tags Volumes to Physical Volumes.

create_geo()

create_gmsh_objects()

Main 3D gmsh constructor function.

create_mesh([dim])

Generates a mesh using Gmsh and saves it to the specified directory.

disable_consoleOutput()

Disables console output in GMSH by setting the 'General.Terminal' option to 0.

export_config()

Exports the current GMSH configuration to a YAML file.

fragmentation(volume_registry)

Gluing all Volumes together.

get_gmsh_cut_entities(cut_layer_names, ...)

Collects Gmsh 3D entities (dim=3) from specified layers to be used as cutting tools.

get_surfaces_onEdges(Btype)

launch_gmsh_gui()

Opens the Gmsh graphical user interface with customized color options for geometry points and text.

make_box_field_mesh(boxes)

Creates box fields for mesh refinement in Gmsh.

make_distance_threshold_field_mesh(distances)

Creates distance and threshold fields for mesh refinement in Gmsh.

make_mesh()

Creates the mesh using GMSH.

make_plan()

Prepares four lists of gmsh layer names defining the order of 3D gmsh construction

print_physical()

Prints tables of physical volumes and surfaces with their corresponding group IDs.

settings_initialize()

Initializes the settings for PECs, surfaces, and PMCs by clearing any existing tags and prepared polygons.

setup_distance_field_mesh(lines, base_z[, ...])

Sets up a distance field mesh in GMSH.

setup_mesh_fields()

Build and set the background mesh field.

setup_threshold_field_mesh(...)

Sets up a threshold field mesh in GMSH.

settings_initialize()[source]#

Initializes the settings for PECs, surfaces, and PMCs by clearing any existing tags and prepared polygons.

make_mesh()[source]#

Creates the mesh using GMSH.

Raises:

e – Exception raised during mesh creation.

build_gmsh_points(coordinates: list[tuple[float, float, float]], meshSize: float = 0.0) list[int][source]#

Creates Gmsh points based on the given coordinates.

Parameters:
  • coordinates (list[tuple[float, float, float]]) – List of (x, y, z) tuples defining the points.

  • meshSize (float, optional) – Mesh size at the points. Defaults to 0.0.

Returns:

List of IDs of the created Gmsh points.

Return type:

list[int]

build_gmsh_lines(point_ids: list[int], closed: bool) list[int][source]#

Creates Gmsh lines connecting the given point IDs.

Parameters:
  • point_ids (list[int]) – List of Gmsh point IDs.

  • closed (bool) – Whether to close the loop (connect last point to first).

Returns:

List of IDs of the created Gmsh lines.

Return type:

list[int]

build_gmsh_surface(base_polygon: Polygon, base_z: float) int[source]#

Creates a Gmsh surface based on the given base_polygon and z-coordinate.

Parameters:
  • base_polygon (Polygon) – Shapely polygon defining the shape of the surface.

  • base_z (float) – The z-coordinate of the surface.

Returns:

The ID of the created Gmsh surface.

Return type:

int

build_gmsh_volume(base_polygon: Polygon, base_z: float, height: float)[source]#

Creates 3D gmsh Volume by extruding shapely Polygon.

Parameters:
  • base_polygon (Polygon) – shapely Polygon

  • base_z (float) – staring z-coordinate

  • height (float) – height of the Volume

Returns:

gmsh Volume tag

build_gmsh_volumes_from_plan(plan: list[tuple], volume_registry: dict, plan_id: int, tool_registry: dict = None) dict[source]#

Build multiple Gmsh volumes and register them in the volume registry. Populates predefined ‘volumes’ dict with gmsh 3D objects. 3D object is created by extruding shapely Polygons.

Parameters:
  • plan (list) – list of tuples with (gmsh layer name, cut_info)

  • volume_registry (dict) – volumes database

  • plan_id (int) – defines the construction logic

  • tool_registry (dict, optional) – volumes database for cutting tools. Defaults to None.

Returns:

updated volume registry containing built Gmsh volume IDs.

Return type:

dict

get_gmsh_cut_entities(cut_layer_names: tuple, volume_registry: dict) list[source]#

Collects Gmsh 3D entities (dim=3) from specified layers to be used as cutting tools.

Parameters:
  • cut_layer_names (tuple) – Names of layers whose volumes will be used for cutting.

  • volume_registry (dict) – volumes database, from which gmsh Volumes will be selected

Returns:

List of (dimension, tag) pairs representing Gmsh volumes to cut with.

Return type:

list

build_additional_gmsh_surfaces()[source]#

Adds additional surfaces to the Gmsh model based on the provided surface configurations.

Each entry in self.surfaces must define:
  • geometry (Polygon or MultiPolygon)

  • z (float): the z-coordinate of the surface

The generated Gmsh surface IDs are appended to config.index.

make_plan() BuildPlan[source]#

Prepares four lists of gmsh layer names defining the order of 3D gmsh construction

Construction logic 1. build_1 - contains a list of gmsh layer names, which will be constructed first by extruding polygons 2. build_2 - contains a list of gmsh layer names,

which will be temporarely constructed and but not present in the end geometry

  1. build_3 - temporarely constructed, not present in the end geometry

    contains cut_info, which is the list of gmsh layers to be cutted

  2. build_4 - list of gmsh layer to be constructed the last

    contains cut_info, which could be gmsh layer names from ‘build_1’, ‘build_2’ and ‘build_3’ lists

Returns:

4 lists with gmsh layer names with or without cut_info

Return type:

BuildPlan

create_gmsh_objects() dict[source]#

Main 3D gmsh constructor function.

Returns:

configuration about gmsh layers and constructed Volumes contained in these layers.

Return type:

dict

fragmentation(volume_registry: dict) list[source]#

Gluing all Volumes together. Handles correctly the shared surfaces between Volumes.

Parameters:

volume_registry (dict) – dict with gmsh layer and corresponding volumes.

Returns:

list of reconfigured Volumes

Return type:

list

create_PhysicalVolumes(volumes: dict) dict[source]#

Tags Volumes to Physical Volumes.

Parameters:

volumes (dict) – dict with gmsh layer and corresponding volumes.

Returns:

key - physical volume names; value - list of Volumes.

Return type:

dict

create_PhysicalSurfaces() dict[source]#

Defines the physical Surfaces, where voltages will be applied.

Returns:

populated electrodes config dict

Return type:

dict

create_PhysicalSurfaces_for_pmcs() dict[source]#

Defines the physical Surfaces for PMC boundaries.

make_box_field_mesh(boxes: list[BoxFieldMeshSettings]) list[int][source]#

Creates box fields for mesh refinement in Gmsh.

Parameters:

boxes (list[BoxFieldMeshSettings]) – List of box field configurations.

Returns:

List of box field IDs created in Gmsh.

Return type:

list

setup_distance_field_mesh(lines: list[LineString], base_z: float, sampling: int = 300) int[source]#

Sets up a distance field mesh in GMSH.

Parameters:
  • lines (list[LineString]) – List of shapely LineStrings defining the lines for the distance field.

  • base_z (float) – The base Z-coordinate for the distance field.

  • sampling (int, optional) – Number of sampling points along the lines. Defaults to 300.

Returns:

The ID of the created distance field.

Return type:

int

setup_threshold_field_mesh(distance_field_id: int, SizeMin: float, SizeMax: float, DistMin: float, DistMax: float) int[source]#

Sets up a threshold field mesh in GMSH.

Parameters:
  • distance_field_id (int) – The ID of the distance field to base the threshold on.

  • SizeMin (float) – Minimum mesh size.

  • SizeMax (float) – Maximum mesh size.

  • DistMin (float) – Minimum distance for mesh size transition.

  • DistMax (float) – Maximum distance for mesh size transition.

Returns:

The ID of the created threshold field.

Return type:

int

make_distance_threshold_field_mesh(distances: list[DistanceFieldMeshSettings]) list[int][source]#

Creates distance and threshold fields for mesh refinement in Gmsh.

Parameters:

distances (list[DistanceFieldMeshSettings]) – List of distance field configurations.

Returns:

List of threshold field IDs created in Gmsh.

Return type:

list (int)

setup_mesh_fields()[source]#

Build and set the background mesh field.

  • Iterates over self.mesh.fields (name -> config)

  • For each recognized field name, calls the corresponding builder

(e.g., self.make_box_field_mesh). - If multiple fields are created, combines them with a “Min” field. - Sets the resulting field as the background mesh.

create_mesh(dim=2)[source]#

Generates a mesh using Gmsh and saves it to the specified directory.

Parameters:

dim (str, optional) – The dimension of the mesh to generate (‘2’ or ‘3’). Defaults to ‘2’.

Raises:

KeyboardInterrupt – If the mesh generation is interrupted by the user.

launch_gmsh_gui()[source]#

Opens the Gmsh graphical user interface with customized color options for geometry points and text.

disable_consoleOutput()[source]#

Disables console output in GMSH by setting the ‘General.Terminal’ option to 0. This method suppresses terminal messages from GMSH, which can be useful for running scripts in environments where console output is not desired.

export_config()[source]#

Exports the current GMSH configuration to a YAML file. The configuration includes the save directory, mesh file name, extrusion settings, and mappings of physical surfaces and volumes to their group IDs.

print_physical()[source]#

Prints tables of physical volumes and surfaces with their corresponding group IDs.