padne.mesh ========== .. py:module:: padne.mesh Attributes ---------- .. autoapisummary:: padne.mesh.index_type padne.mesh.PolyBoundaryDistanceMap padne.mesh.CGALPolygon Exceptions ---------- .. autoapisummary:: padne.mesh.MeshingException Classes ------- .. autoapisummary:: padne.mesh.HasIndex padne.mesh.Vector padne.mesh.Point padne.mesh.Vertex padne.mesh.HalfEdge padne.mesh.Face padne.mesh.IndexStore padne.mesh.Mesh padne.mesh.ZeroForm padne.mesh.OneForm padne.mesh.TwoForm padne.mesh.Mesher Module Contents --------------- .. py:data:: index_type .. py:class:: HasIndex Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. py:attribute:: i :type: index_type .. py:class:: Vector .. py:attribute:: dx :type: float .. py:attribute:: dy :type: float .. py:method:: dot(other: Vector) -> float .. py:class:: Point .. py:attribute:: x :type: float .. py:attribute:: y :type: float .. py:method:: distance(other: Point) -> float .. py:method:: to_shapely() -> shapely.geometry.Point Convert this Point to a shapely.geometry.Point. Returns: A shapely Point with the same coordinates .. py:class:: Vertex .. py:attribute:: p :type: Point .. py:attribute:: out :type: Optional[HalfEdge] :value: None .. py:attribute:: i :type: index_type .. py:method:: orbit() -> Iterator[HalfEdge] .. py:class:: HalfEdge .. py:attribute:: origin :type: Vertex .. py:attribute:: twin :type: Optional[HalfEdge] :value: None .. py:attribute:: next :type: Optional[HalfEdge] :value: None .. py:attribute:: prev :type: Optional[HalfEdge] :value: None .. py:attribute:: face :type: Optional[Face] :value: None .. py:attribute:: i :type: index_type .. py:property:: is_boundary :type: bool .. py:method:: connect(e1: HalfEdge, e2: HalfEdge) -> None :staticmethod: .. py:method:: walk() -> Iterator[HalfEdge] .. py:method:: cotan() -> float Compute the cotangent weight for this half-edge. .. py:class:: Face .. py:attribute:: edge :type: HalfEdge :value: None .. py:attribute:: is_boundary :type: bool :value: False .. py:attribute:: i :type: index_type .. py:property:: edges .. py:property:: vertices .. py:property:: centroid :type: Point Compute the centroid of the face using the average of vertex coordinates. .. py:property:: area :type: float Compute the area using the shoelace formula. Returns the absolute value to ensure positive area regardless of vertex order. .. py:class:: IndexStore[T: HasIndex] A simple class that stores objects with indices. .. py:property:: next_index :type: index_type Get the next available index without adding an object. .. py:method:: add(obj: T) -> None .. py:method:: to_index(obj: T) -> index_type Get the index of an object. This is for backwards compatibility, otherwise use obj.i directly. .. py:method:: to_object(idx: int | index_type) -> T Get the object at a given index. .. py:method:: items() -> Iterator[tuple[index_type, T]] .. py:class:: Mesh .. py:attribute:: vertices .. py:attribute:: halfedges .. py:attribute:: faces .. py:attribute:: boundaries .. py:method:: make_vertex(p: Point) -> Vertex .. py:method:: connect_vertices(v1: Vertex, v2: Vertex) -> HalfEdge Return a half-edge between the two vertices v1 and v2. If the half edge does not exist, create it. The twin half-edge is also created. .. py:method:: euler_characteristic() -> int .. py:method:: from_triangle_soup(points: list[Point], triangles: list[tuple[int, int, int]]) -> Mesh :classmethod: .. py:class:: ZeroForm .. py:attribute:: mesh :type: Mesh .. py:attribute:: values :type: numpy.ndarray .. py:method:: d() -> OneForm Compute the exterior derivative (gradient) of this 0-form. For a function f on vertices, the exterior derivative df is a 1-form where: (df)[edge] = f(target_vertex) - f(source_vertex) Returns: A OneForm representing the gradient of this function .. py:class:: OneForm A discrete 1-form defined on the (h)edges of a mesh. .. py:attribute:: mesh :type: Mesh .. py:attribute:: values :type: numpy.ndarray .. py:class:: TwoForm A discrete 2-form defined on the faces of a mesh. .. py:attribute:: mesh :type: Mesh .. py:attribute:: values :type: numpy.ndarray .. py:data:: PolyBoundaryDistanceMap .. py:data:: CGALPolygon .. py:exception:: MeshingException Bases: :py:obj:`RuntimeError` Exception raised when CGAL mesh generation fails due to invalid geometry. This includes cases such as: - Self-intersecting polygons with unauthorized constraint intersections - Degenerate edges that are too short (near-duplicate vertices) - Other geometric degeneracies that prevent mesh generation With CGAL_DEBUG enabled, these issues are detected early through CGAL's internal precondition checking, preventing crashes and providing clear error messages. .. py:class:: Mesher(config: Optional[Mesher] = None) This class is responsible for generating a mesh from a Shapely polygon. Works through the triangle library. .. py:class:: Config Configuration parameters for mesh generation. .. py:attribute:: minimum_angle :type: float :value: 20.0 .. py:attribute:: maximum_size :type: float :value: 0.6 .. py:attribute:: variable_density_min_distance :type: float :value: 0.5 .. py:attribute:: variable_density_max_distance :type: float :value: 3.0 .. py:attribute:: variable_size_maximum_factor :type: float :value: 3.0 .. py:attribute:: distance_map_quantization :type: float :value: 1.0 .. py:attribute:: RELAXED :value: None .. py:property:: is_variable_density :type: bool Return True if variable density meshing is enabled. .. py:attribute:: config .. py:method:: poly_to_mesh(poly: shapely.geometry.Polygon, seed_points: list[Point] = []) -> Mesh Convert a Shapely polygon to a triangular mesh. Args: poly: A Shapely polygon, potentially with holes Returns: A Mesh object representing the triangulated polygon