Geometry & Meshing#
PalaceToolkit uses Gmsh with its OpenCASCADE kernel to create parametric 3D finite-element meshes entirely from Python scripts.
The Entity abstraction#
Every geometric region — conductors, dielectrics, air boxes, ports — is
represented as an Entity:
from palacetoolkit.mesh import Entity, run_meshing_pipeline
conductor = Entity(name="conductor", dim=3, mesh_order=0, tags=[1])
dielectric = Entity(name="dielectric", dim=3, mesh_order=1, tags=[2])
air = Entity(name="air", dim=3, mesh_order=2, tags=[3])
Parameter |
Description |
|---|---|
|
Becomes the physical group label that Palace references. |
|
Geometric dimension (3 = volume, 2 = surface, …). |
|
Priority for the boolean pipeline (lower = higher priority). |
|
Gmsh geometry tags returned by |
Boolean pipeline#
After defining entities, call run_meshing_pipeline to perform automatic
priority-based cuts and fragmentation:
run_meshing_pipeline([conductor, dielectric, air])
The pipeline:
Groups entities by dimension (3 → 0).
Sorts within each dimension by
mesh_order(ascending = higher priority).Cuts each entity against all previously processed entities in the same dimension (
removeObject=True,removeTool=False).Fragments lower-dimensional entities against higher-dimensional ones so that boundary surfaces are shared.
Assigns physical groups — volumes get their entity name; surfaces at material interfaces are auto-labelled (e.g.
"conductor__dielectric").
Tip
The mesh_order controls which material wins at overlapping regions.
Think of it as a z-index: small number = highest priority = never cut.
Mesh generation#
After the pipeline runs, generate the mesh and write it to disk:
import gmsh
gmsh.model.mesh.generate(3)
gmsh.write("my_model.msh")
gmsh.finalize()
Mesh topology verification#
Before running Palace, verify the mesh is valid:
from palacetoolkit.verify_topology import analyse_mesh
analyse_mesh("my_model.msh")
This checks that:
Every boundary element maps to an existing volume face (totality).
No two boundary elements map to the same face (injectivity).
Mesh visualisation#
from palacetoolkit.viz import view_mesh
view_mesh("my_model.msh")
view_mesh() uses PyVista’s interactive notebook backend when executed in
Jupyter, so the mesh remains pan/zoom/rotate capable in rendered docs.