pyxfem.core.finite_volume_2d module
Created on Thu Mar 7 11:17:17 2024 @author: nchevaug 2D Explicit Lagrangian Finite Volume Solver (GLACE Scheme).
Philosophy & Architecture: This module implements the Godunov-type Lagrangian Scheme for Compressible Euler equations (GLACE). It computes the evolution of a fluid on an unstructured 2D triangular mesh moving with the fluid velocity (Lagrangian framework).
The solver features a dual-execution architecture: 1. Pure NumPy (Fallback): Fully vectorized array operations. 2. Numba JIT (HPC Mode): Aggressively optimized loop-level parallelism
(prange), avoiding heap allocations and leveraging hardware registers for the nodal Riemann solver.
- pyxfem.core.finite_volume_2d.Cjr_triangle(xy0: Tuple[float64, float64], xy1: Tuple[float64, float64], xy2: Tuple[float64, float64])[source]
Computes the surface area and corner normal vectors (C_jr) for a single 2D triangle.
This function is optimized for Numba JIT compilation. It performs computations using primitive types and returns tuples to ensure zero-allocation overhead when called inside high-performance loops (like prange).
- xy0tuple of float or array-like
The (x, y) coordinates of the 0-th vertex of the triangle.
- xy1tuple of float or array-like
The (x, y) coordinates of the 1-st vertex of the triangle.
- xy2tuple of float or array-like
The (x, y) coordinates of the 2computeCjr_triangles_numba(mesh)
- def computeCjr_triangles(F, outMeas, outC, outnormC, outN):
-nd vertex of the triangle.
- Sfloat
The surface area of the triangle.
- Cj0tuple of float
A tuple (x, y) representing the corner normal vector associated with vertex 0.
- Cj1tuple of float
A tuple (x, y) representing the corner normal vector associated with vertex 1.
- Cj2tuple of float
A tuple (x, y) representing the corner normal vector associated with vertex 2.
- class pyxfem.core.finite_volume_2d.ConservativeLawManager(nbdata, U_shapes, U_indexes, W_shapes, W_indexes)[source]
Bases:
object
- class pyxfem.core.finite_volume_2d.GELEES_MeshStruct(ncells: int, nverts: int, t2v: Annotated[NDArray[int64], 'Shape(N, 3)'], v2t_index: NDArray[int64], v2t_tris: NDArray[int64], v2t_v: NDArray[int64], xy: NDArray[float64], cell_meas: NDArray[float64], C: NDArray[float64], nC: NDArray[float64], N: NDArray[float64])[source]
Bases:
NamedTupleA structured container for the 2D Lagrangian mesh topology, geometry, and inverse connectivities.
This NamedTuple holds all the static and dynamically updated arrays required for the finite volume solver, designed to be easily passed into Numba JIT-compiled functions.
- ncells
The total number of triangular cells in the mesh.
- Type:
int
- nverts
The total number of vertices (nodes) in the mesh.
- Type:
int
- t2v
2D array of shape (ncells, 3). The cell-to-vertex connectivity matrix mapping each triangle to its 3 defining vertex indices.
- Type:
IndexArray
- v2t_index
1D array of shape (nverts + 1,). The index pointer array for the CSR-like inverse connectivity (vertices-to-cells).
- Type:
IndexArray
- v2t_tris
1D array containing the flattened cell indices surrounding each vertex. Sliced using v2t_index.
- Type:
IndexArray
- v2t_v
1D array containing the local vertex index (0, 1, or 2) within the corresponding cell in v2t_tris. Sliced using v2t_index.
- Type:
IndexArray
- xy
2D array of shape (nverts, 2). The physical (x, y) coordinates of each vertex. This array is updated at each time step.
- Type:
FloatArray
- S
1D array of shape (ncells,). The surface area of each triangular cell.
- Type:
FloatArray
- C
3D array of shape (ncells, 3, 2). The corner normal vectors (C_jr) for each vertex of each cell.
- Type:
FloatArray
- nC
2D array of shape (ncells, 3). The Euclidean norms (magnitudes) of the corner normal vectors.
- Type:
FloatArray
- N
3D array of shape (ncells, 3, 2). The normalized unit direction vectors of the corner normals.
- Type:
FloatArray
- C: NDArray[float64]
Alias for field number 8
- N: NDArray[float64]
Alias for field number 10
- cell_meas: NDArray[float64]
Alias for field number 7
- nC: NDArray[float64]
Alias for field number 9
- ncells: int
Alias for field number 0
- nverts: int
Alias for field number 1
- t2v: Annotated[NDArray[int64], 'Shape(N, 3)']
Alias for field number 2
- v2t_index: NDArray[int64]
Alias for field number 3
- v2t_tris: NDArray[int64]
Alias for field number 4
- v2t_v: NDArray[int64]
Alias for field number 5
- xy: NDArray[float64]
Alias for field number 6
- class pyxfem.core.finite_volume_2d.GlaceExplicitLagrangianBaseSolver(conservation_law: ConservativeLawManager, mesh: GELEES_MeshStruct)[source]
Bases:
object
- pyxfem.core.finite_volume_2d.allocate_Cjr(nc: int)[source]
Allocates memory for the geometric properties of the mesh cells.
This function initializes empty NumPy arrays required to store the surface areas and the corner normal vectors (and their properties) for a 2D triangular mesh.
- Parameters:
nc (int) – The total number of triangular cells in the mesh.
- Returns:
S (ndarray) – 1D array of shape (nc,) and type float64. Allocated to store the surface area of each triangular cell.
C (ndarray) – 3D array of shape (nc, 3, 2) and type float64. Allocated to store the corner normal vectors (C_jr) for the 3 vertices of each cell in 2D space (x, y).
normC (ndarray) – 2D array of shape (nc, 3) and type float64. Allocated to store the Euclidean norms (magnitudes) of the C_jr vectors.
- pyxfem.core.finite_volume_2d.computeCjr_triangles(mesh: GELEES_MeshStruct)[source]
- pyxfem.core.finite_volume_2d.computeCjr_triangles_numba(mesh)[source]
Computes and updates the geometric properties of all triangular cells in the mesh using Numba parallelization.
This function iterates over all cells concurrently, calculates the surface area and the corner normal vectors (C_jr) for each triangle based on its current vertex coordincomputeCjr_triangles_numba(mesh)
- Parameters:
mesh (NamedTuple (e.g., GELEES_MeshStruct)) – A structured object containing the mesh data. It must provide: - mesh.ncells (int): The total number of cells. - mesh.S (ndarray): 1D array of shape (ncells,) to store updated areas. - mesh.C (ndarray): 3D array of shape (ncells, 3, 2) to store updated corner normal vectors. - Connectivity and coordinate data required by get_trixy.
- Returns:
The function does not return any value. The mesh.S and mesh.C arrays are modified in-place for maximum performance.
- Return type:
None
- pyxfem.core.finite_volume_2d.t_tangentmap(tris_coord, out: NDArray[float64] | None = None)[source]
return the “tangent map” The F tensor between reference element and each of the elment in tris_coord
- pyxfem.core.finite_volume_2d.update_MeshStruct(xy, mesh: GELEES_MeshStruct)[source]