Prisms#
Polygons can be associated with arbitrarily complex extrusion rules to form 3D Prisms.
import matplotlib.pyplot as plt
import shapely
from meshwell.cad_occ import cad_occ
from meshwell.mesh import mesh
from meshwell.occ_xao_writer import write_xao
from meshwell.polyprism import PolyPrism
from meshwell.visualization import plot3D
/home/runner/work/meshwell/meshwell/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
# We use shapely as an API to enter polygons
# Initialize GMSH and create the mesh
polygon_hull = shapely.Polygon(
[[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]],
)
polygon_hole1 = polygon_hull.buffer(-0.5, join_style="mitre")
polygon = polygon_hull - polygon_hole1
View the polygons:
# Plot the shapely polygons
plt.figure(figsize=(8, 8))
plt.plot(*polygon.exterior.xy, "b-", label="Polygon 1 exterior")
plt.plot(*polygon.interiors[0].xy, "b--", label="Polygon 1 hole")
plt.axis("equal")
plt.title("Shapely Polygons")
plt.legend()
plt.show()
Mesh a prism by combining with buffers
buffers = {0.0: 0.05, 1.0: -0.05}
poly3D = PolyPrism(
polygons=polygon,
buffers=buffers,
physical_name="my_prism1",
)
entities_list = [poly3D]
write_xao(cad_occ(entities_list), "prism.xao")
output_mesh = mesh(
dim=3,
input_file="prism.xao",
output_file="prism.msh",
default_characteristic_length=100,
)
# Read and plot the mesh
Info : Clearing all models and views...
Info : Done clearing all models and views
Info : Reading 'prism.xao'...
Info : Done reading 'prism.xao'
plot3D(output_mesh, title="Interactive 3D Mesh")