geossm.covmodel.FEMSolver¶
- class geossm.covmodel.FEMSolver(meshio_obj, domain=None, verbose=True, stats=True)[source]¶
Bases:
objectLow-level finite-element engine behind spdeAppoxCov.
Wraps a triangular mesh (e.g. built by buildMesh2d) in an MFEM order-1 \(H^1\) finite element space, and assembles the sparse mass and stiffness matrices that spdeAppoxCov.precision combines into the SPDE precision matrix. It also classifies mesh vertices as “inner” (covered by domain, the region of scientific interest) or “outer” (part of the surrounding buffer, whose role is only to push the FEM’s Neumann boundary effects away from domain), evaluates basis functions at arbitrary points (getBasis), and reports mesh quality diagnostics (compute_stats, summary).
Most users go through spdeAppoxCov instead, which builds and owns a FEMSolver internally in spdeAppoxCov.setup(). FEMSolver is exposed directly (e.g. via spdeAppoxCov.fem_solver) for lower-level access to the mesh, the assembled matrices, and mesh diagnostics.
Notes
Internally, the input meshio.Mesh is converted to an mfem.Mesh via meshio_to_mfem_mesh (2D triangular meshes only); vertices and elements are kept in the order given by the mesh, with no reordering or optimisation performed by this class.
Methods
The three interior angles (degrees) of a single triangle.
Area of a single triangle (shoelace formula).
Interior angles and areas of every mesh triangle (via compute_angles/compute_area); used by __init__ (when
stats=True) to populate angles/areas and warn about poor-quality (small-angle) meshes.Check that the mesh covers the FEM computational domain Ω.
Alias for get_distance.
Build the (label, value) rows shown by summary, as two lists of
(str, [str])pairs (left and right columns).Evaluate the FE basis functions at a set of physical points.
Flat Euclidean pairwise distance between points and the mesh vertex coordinates (or between mesh vertices and themselves).
Classify vertices as inner or outer with respect to domain.
Plot the mesh: all triangle edges, inner/outer vertices, boundary edges (dashed red), and the domain polygon(s) (orange outline).
Print msg prefixed with a UTC timestamp.
Return a statsmodels.iolib.summary.Summary table of mesh/FE diagnostics (vertex/element counts, angle & area ranges, DOFs, matrix shapes, ...); also backs __str__.
Attributes
Total number of vector DOFs in fespace (ndofs * fespace_order).
(nelements, 3) ndarray of the triangles' interior angles (degrees), or None if __init__ was called with
stats=False.(nelements,) ndarray of triangle areas, or None if __init__ was called with
stats=False.(nbElements, 2) ndarray of int -- vertex-index pairs of the boundary elements (see nbElements).
Mesh bounding box as
[minx, miny, maxx, maxy](rounded to 2 decimals).region(s) of scientific interest used to classify vertices as inner/outer (see _validate_domain / isinner).
Convex hull of the union of domain -- see _domain_hull.
Return the effective number of DOFs (associated with vertices)
(nelements, 3) ndarray of int -- vertex indices (into vertex) making up each mesh triangle.
Return the finite elment space
Vector dimension of fespace (1 for the scalar H1 space used here).
MFEM geometry type of the mesh elements (e.g. triangle).
(nbElements, 2) ndarray of int -- vertex-index pairs for each boundary edge.
Boolean array, one entry per vertex, True where the vertex is classified as inner (covered by domain); see isinner.
Return the point of the grid
Sparse (diagonal, lumped) mass matrix \(C\), shape (effective_dofs, effective_dofs).
The underlying mfem.Mesh (converted from the input meshio.Mesh).
Return the point of the grid
Return the number of the boundary point of the grid
Return the total point number of the grid
Total number of mesh edges.
Number of boundary elements (edges, for a 2D mesh).
Number of scalar degrees of freedom in fespace (all mesh vertices, before cutting to effective_dofs).
Get the number of discretisation elements (like the number of triangle)
Number of mesh vertices (= effective_dofs).
Return the boundary point of the grid
Tuple (nvertex, nelements, nbElements).
Sparse stiffness matrix \(G\) (the <grad(phi_i), grad(phi_j)> FEM Laplacian term), shape (effective_dofs, effective_dofs).
Return the total point (inner + boundary) of the grid (same as vertex)
Returns the coordinates of mesh vertices that have a DOF associated with them in the given H1_FECollection(1, dim) finite element space.
- property mesh¶
The underlying mfem.Mesh (converted from the input meshio.Mesh).
- property inner¶
Boolean array, one entry per vertex, True where the vertex is classified as inner (covered by domain); see isinner.
- isinner(points=None)[source]¶
Classify vertices as inner or outer with respect to domain.
A point is inner if it is covered by any single polygon in domain – each polygon is tested on its own (not on the convex hull of their union), so for a multi-polygon domain (e.g. Sicily, Sardinia, mainland Italy) a mesh vertex sitting between two landmasses, inside their shared convex hull but outside every individual polygon, is classified as outer.
- getBasis(phy_points=None)[source]¶
Evaluate the FE basis functions at a set of physical points.
For each point, locates the mesh element that contains it and evaluates every basis function of that element there, giving a sparse “observation” matrix H such that
H @ field_at_verticesinterpolates the FEM field at phy_points.- Parameters:
phy_points (
(p,2) array_like, optional) – Physical-space points to evaluate the basis at. Defaults to the mesh vertices (vertex), giving the identity-like mapping used e.g. to sanity-check the FE space.- Returns:
count (
int) – Number of points for which a containing mesh element was found (see mfem.Mesh.FindPoints).notfindInx (
ndarrayofint) – Indices (into phy_points) of points for which no containing element could be found – point search is not guaranteed to succeed even for points that do lie inside the mesh.H (
scipy.sparse.csr_matrix,shape (p,effective_dofs)) – Basis functions evaluated at each point, one row per point and one column per (inner + outer) mesh vertex/DOF. Rows for points in notfindInx are all zero. Entries below 1e-8 are zeroed out for numerical stability.
- plot_mesh(ax=None, figsize=(10, 8), title='Title', alpha_vertex=1, alpha_triangle=0.5, alpha_border=0.5)[source]¶
Plot the mesh: all triangle edges, inner/outer vertices, boundary edges (dashed red), and the domain polygon(s) (orange outline).
- Parameters:
ax (
matplotlib.axes.Axes, optional) – Axes to draw on. A new figure/axes is created if not given.figsize (
tupleoffloat, default(10,8)) – Figure size, only used when ax is not given.title (
str, default"Title") – Plot title.alpha_vertex (
float, default1) – Transparency of the inner/outer vertex markers.alpha_triangle (
float, optional) – Unused (kept for interface compatibility); triangle edges are always drawn with a fixed alpha of 0.5.alpha_border (
float, default0.5) – Transparency of the dashed boundary-edge lines.
- Returns:
matplotlib.axes.Axes
- get_distance(points=None)[source]¶
Flat Euclidean pairwise distance between points and the mesh vertex coordinates (or between mesh vertices and themselves).
- Parameters:
points (
(p,2) array_like, optional) – Query points. Defaults to vertex, giving the full vertex-to-vertex distance matrix.- Returns:
ndarray,shape (nvertex,nvertex)or(p,nvertex)
- property vertex¶
Returns the coordinates of mesh vertices that have a DOF associated with them in the given H1_FECollection(1, dim) finite element space.
- property nvertex¶
Number of mesh vertices (= effective_dofs).
- property nelements¶
Get the number of discretisation elements (like the number of triangle)
- property elements¶
(nelements, 3) ndarray of int – vertex indices (into vertex) making up each mesh triangle.
- property box¶
Mesh bounding box as
[minx, miny, maxx, maxy](rounded to 2 decimals).
- property domain¶
region(s) of scientific interest used to classify vertices as inner/outer (see _validate_domain / isinner).
- Type:
Tuple of shapely.geometry.Polygon
- property domain_hull¶
Convex hull of the union of domain – see _domain_hull.
- covers_domain()[source]¶
Check that the mesh covers the FEM computational domain Ω.
Simple necessary (not sufficient) check: whether the convex hull of the mesh vertices covers domain_hull, the convex hull of the union of domain. Does not check the mesh’s actual (possibly non-convex) boundary shape, only its convex extent.
- property nbElements¶
Number of boundary elements (edges, for a 2D mesh).
- property nbEdges¶
Total number of mesh edges.
- property geoshape¶
MFEM geometry type of the mesh elements (e.g. triangle).
- property getBoundaryEdge¶
(nbElements, 2) ndarray of int – vertex-index pairs for each boundary edge.
- property boundary_vertex¶
(nbElements, 2) ndarray of int – vertex-index pairs of the boundary elements (see nbElements).
- property fespace¶
Return the finite elment space
- property fespace_order¶
Vector dimension of fespace (1 for the scalar H1 space used here).
- property ndofs¶
Number of scalar degrees of freedom in fespace (all mesh vertices, before cutting to effective_dofs).
- property effective_dofs¶
Return the effective number of DOFs (associated with vertices)
- property GetVSize¶
Total number of vector DOFs in fespace (ndofs * fespace_order).
- property stiff¶
Sparse stiffness matrix \(G\) (the <grad(phi_i), grad(phi_j)> FEM Laplacian term), shape (effective_dofs, effective_dofs).
- property mass¶
Sparse (diagonal, lumped) mass matrix \(C\), shape (effective_dofs, effective_dofs).
- property inner_points¶
Return the point of the grid
- property n_inner_points¶
Return the point of the grid
- property outer_points¶
Return the boundary point of the grid
- property n_outer_points¶
Return the number of the boundary point of the grid
- property totpoints¶
Return the total point (inner + boundary) of the grid (same as vertex)
- property n_totpoints¶
Return the total point number of the grid
- property shape¶
Tuple (nvertex, nelements, nbElements).
- compute_angles(vertex, triangle)[source]¶
The three interior angles (degrees) of a single triangle.
- Parameters:
vertex (
(n,2) array_like) – Vertex coordinates array to index into.triangle (
array_likeofint,length 3) – Indices (into vertex) of the triangle’s three corners.
- Returns:
ndarray,shape (3,)– Angles at each of the three corners, in the same order as triangle.
- compute_area(vertex, triangle)[source]¶
Area of a single triangle (shoelace formula).
- Parameters:
vertex (
(n,2) array_like) – Vertex coordinates array to index into.triangle (
array_likeofint,length 3) – Indices (into vertex) of the triangle’s three corners.
- Returns:
float
- compute_stats()[source]¶
Interior angles and areas of every mesh triangle (via compute_angles/compute_area); used by __init__ (when
stats=True) to populate angles/areas and warn about poor-quality (small-angle) meshes.- Returns:
angles (
(nelements,3) ndarray) – Interior angles (degrees) of each triangle.areas (
(nelements,) ndarray) – Area of each triangle.
- property angles¶
(nelements, 3) ndarray of the triangles’ interior angles (degrees), or None if __init__ was called with
stats=False.
- property areas¶
(nelements,) ndarray of triangle areas, or None if __init__ was called with
stats=False.
- generate_summary()[source]¶
Build the (label, value) rows shown by summary, as two lists of
(str, [str])pairs (left and right columns).