Linear Algebra¶
The voids.linalg sub-package handles matrix assembly, linear-system solving,
boundary-condition imposition, and solver diagnostics.
Assembly¶
voids.linalg.assemble
¶
assemble_pressure_system
¶
Assemble the pore-pressure matrix for steady single-phase flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network defining the pore-throat topology. |
required |
throat_conductance
|
ndarray
|
Conductance array with shape |
required |
Returns:
| Type | Description |
|---|---|
csr_matrix
|
Symmetric matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conductance array has the wrong shape or contains negative entries. |
Notes
The assembled matrix is the conductance-weighted graph Laplacian. For a
throat with conductance g_t connecting pores i and j, the local
contribution is
A[i, i] += g_t
A[j, j] += g_t
A[i, j] -= g_t
A[j, i] -= g_t
Source code in src/voids/linalg/assemble.py
Solvers¶
voids.linalg.solve
¶
solve_linear_system
¶
Solve a sparse linear system with one of the supported SciPy backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
csr_matrix
|
Sparse system matrix. |
required |
b
|
ndarray
|
Right-hand-side vector. |
required |
method
|
str
|
Solver backend. Supported values are |
'direct'
|
solver_parameters
|
SolverParameters | None
|
Optional backend-specific solver options. For SciPy Krylov methods this
maps directly to supported keyword arguments such as |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Solution vector. |
dict[str, Any]
|
Solver metadata containing the method name and the iterative solver
status code |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
The "pardiso" method uses the Intel MKL PARDISO solver via the
pypardiso package. This is typically only available on Linux systems
and may provide better performance for large systems compared to the
default SciPy direct solver.
Source code in src/voids/linalg/solve.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
Boundary Conditions¶
voids.linalg.bc
¶
apply_dirichlet_rowcol
¶
Apply Dirichlet conditions by row and column elimination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
csr_matrix
|
System matrix with shape |
required |
b
|
ndarray
|
Right-hand-side vector with shape |
required |
values
|
ndarray
|
Full-length vector of prescribed values. Only entries selected by
|
required |
mask
|
ndarray
|
Boolean array selecting the Dirichlet degrees of freedom. |
required |
Returns:
| Type | Description |
|---|---|
csr_matrix
|
Modified system matrix in CSR format. |
ndarray
|
Modified right-hand-side vector. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
For each constrained degree of freedom k, the routine enforces
A[k, :] = 0
A[:, k] = 0
A[k, k] = 1
b[k] = values[k]
after first subtracting the eliminated column contribution from the
unconstrained rows of b.
Source code in src/voids/linalg/bc.py
Backends¶
voids.linalg.backends
¶
SciPyBackend
dataclass
¶
Namespace collecting SciPy sparse constructors and solvers.
Attributes:
| Name | Type | Description |
|---|---|---|
coo_matrix, csr_matrix |
Sparse matrix constructors. |
|
spsolve, cg, gmres |
Direct and iterative sparse linear solvers used by the package. |
Source code in src/voids/linalg/backends.py
Diagnostics¶
voids.linalg.diagnostics
¶
residual_norm
¶
Return the Euclidean norm of the linear-system residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
csr_matrix
|
System matrix. |
required |
x
|
ndarray
|
Trial or converged solution vector. |
required |
b
|
ndarray
|
Right-hand-side vector. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Value of |