Array Shapes and Data Structures¶
This document describes the shapes and roles of the key arrays used in the simulation. Understanding these structures is essential for development and debugging.
Notation¶
Throughout this document:
n_nodes: Number of nodes in a phasen_gauss: Number of Gauss points in a domainn_gauss_b: Number of Gauss points on a boundaryn_cells: Number of cells (voxels)n_nnz: Number of non-zero entries in a sparse matrixdim: Spatial dimension (3 for 3D)basis: Polynomial basis size (4 for linear 3D: [1, x, y, z])
Node Arrays¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Node coordinates [x, y, z] in electrolyte phase |
|
|
Node coordinates [x, y, z] in electrode phase |
|
|
Node coordinates [x, y, z] in pore phase |
|
|
All nodes in the domain (union of all phases) |
|
|
Grain/phase ID for each node |
Cell Connectivity Arrays¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
x-coordinates of 8 vertices for each electrolyte cell |
|
|
y-coordinates of 8 vertices for each electrolyte cell |
|
|
z-coordinates of 8 vertices for each electrolyte cell |
Boundary cell arrays have 4 vertices per face:
Array Name |
Shape |
Description |
|---|---|---|
|
|
x-coords of boundary face vertices |
|
|
Interface cell vertex coordinates |
Gauss Point Arrays¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Gauss point coordinates [x, y, z] |
|
|
det(J) × Gauss weight at each point |
|
|
Boundary Gauss point coordinates |
|
|
Phase ID at each Gauss point |
For 3D hexahedral integration with 2×2×2 Gauss points:
n_gauss = n_cells * 8
For 2D boundary integration with 2x2 Gauss points:
n_gauss_b = n_faces * 4
Moment Matrices¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Moment matrix at each Gauss point (3D case) |
|
|
Partial derivative of M w.r.t. x |
|
|
Partial derivative of M w.r.t. y |
|
|
Partial derivative of M w.r.t. z |
The moment matrix for 3D linear basis is 4×4:
For 2D problems, the shape is (n_gauss, 3, 3).
Kernel Sparse Arrays¶
The kernel values φ are stored in COO format for sparse matrix construction:
Array Name |
Shape |
Description |
|---|---|---|
|
|
Gauss point indices (row indices) |
|
|
Node indices (column indices) |
|
|
Kernel values φ(z) |
|
|
∂φ/∂x values |
|
|
∂φ/∂y values |
|
|
∂φ/∂z values |
These arrays are used to construct sparse matrices:
phi_sparse = csr_array((phi_data, (row_indices, col_indices)),
shape=(n_gauss, n_nodes))
Shape Function Sparse Matrices¶
Matrix Name |
Shape |
Description |
|---|---|---|
|
|
Shape functions Ψ_I(x_g) |
|
|
Ψ × det(J) × w |
|
|
∂Ψ/∂x |
|
|
∂Ψ/∂y |
|
|
∂Ψ/∂z |
|
|
∂Ψ/∂* × det(J) × w |
Typical sparsity:
Each Gauss point interacts with ~20-50 nodes (depending on support size),
so the fill ratio is approximately 30/n_nodes.
Stiffness Matrices¶
Matrix Name |
Shape |
Description |
|---|---|---|
|
|
Diffusion stiffness for electrolyte |
|
|
Diffusion stiffness for electrode |
|
|
Diffusion stiffness for pore |
|
|
Mechanical stiffness (3 DOF per node) |
The mechanical stiffness is assembled as a 3×3 block matrix:
where each block is (n_nodes, n_nodes).
Elasticity Tensor¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Voigt elasticity tensor at Gauss points |
|
|
Individual tensor components |
Voigt notation mapping (3D):
Index 1: σ_xx, ε_xx
Index 2: σ_yy, ε_yy
Index 3: σ_zz, ε_zz
Index 4: σ_yz, 2ε_yz
Index 5: σ_xz, 2ε_xz
Index 6: σ_xy, 2ε_xy
Solution Vectors¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Ionic potential in electrolyte |
|
|
Electronic potential in electrode |
|
|
Gas concentration in pores |
|
|
Displacement [u_x, u_y, u_z] stacked |
Force Vectors¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
RHS for electrolyte diffusion |
|
|
RHS for mechanical problem |
|
|
Electrochemical source values |
|
|
Interface reaction source |
Boundary Arrays¶
Array Name |
Shape |
Description |
|---|---|---|
|
|
Prescribed boundary values |
|
|
Nitsche penalty parameter |
|
|
x-component of outward normal |
|
|
y-component of outward normal |
|
|
z-component of outward normal |
Gauss Integration Reference¶
3D Cube (8 Gauss points):
The Gauss points are located at ξ = ±1/√3 in each direction:
X_G_CUBE coordinates: (+-0.577, +-0.577, +-0.577)
Shape: (8, 3)
WEIGHT_G_CUBE = [1, 1, 1, 1, 1, 1, 1, 1] # Shape: (8,)
2D Rectangle (4 Gauss points):
X_G_REC coordinates: (+-0.577, +-0.577)
Shape: (4, 2)
WEIGHT_G_REC = [1, 1, 1, 1] # Shape: (4,)