electrostatics.solver — the linear solve
tempura/electrostatics/solver.py is the sparse linear-algebra core. It is
deliberately independent of geometry: given the finalized system matrix and the
region indices, it builds the right-hand sides, applies the Dirichlet
constraints, and factors the system once with MUMPS for reuse across many
solves.
The discrete system
pescado discretizes the Poisson problem into a sparse linear system
where \(A\) is the finalized capacitance_matrix and \(x\) is the potential at the
mesh sites. For a fixed device \(A\) is built once; different gate voltages change
only the right-hand side \(b\). That single observation is what makes the
gate-basis solve cheap (see _pescado_solve).
Symmetry-preserving Dirichlet elimination
Gate and boundary nodes are Dirichlet-constrained: their potentials are prescribed, not solved for. Naively striking those rows would break the symmetry of \(A\) and prevent a symmetric factorization. Instead Tempura rewrites the system into an equivalent symmetric form. For the Dirichlet index set \(D\) with prescribed values \(x_D\):
In words: zero the Dirichlet rows and columns, put \(1\) on their diagonal, and move the removed coupling \(\sum_{j \in D} A_{ij} x_j\) into the right-hand side. The solution of \(\tilde A\,x = \tilde b\) matches the constrained problem while keeping \(\tilde A\) symmetric.
Factor once, solve many
setup_solver(...) factors \(\tilde A\) with MUMPS (optionally with block
low-rank compression), and solve_linear_system(...) reuses that factorization
for each right-hand side. build_rhs_vectors(...) assembles the multi-column
RHS for a set of gates: without a distributed charge term each column is a
sparse indicator on one gate's nodes; with a charge term the interior rows carry
the charge and the result is dense. This is the machinery the gate-basis solve
drives in blocks.
Optional dependency
The solve path requires python-mumps. The helpers raise a clear error if
it is unavailable.
API
solver
Linear-system helpers for Tempura electrostatics.
This module is intentionally independent from Tempura's geometry assembly. It contains the sparse constrained-system helpers used for the Poisson basis solves. Self-consistent Thomas-Fermi workflows should use Pescado directly with the finalized problem returned by Tempura's public electrostatics workflow.
build_rhs_vectors(region_inds, gate_names, *, size=None, charge=None, dtype=DTYPE)
Build the multi-RHS matrix for the ordered gate basis solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region_inds
|
IndexMap
|
Mapping of region name to solver indices. |
required |
gate_names
|
list[str]
|
Gate names in the solve order to encode into the RHS. |
required |
size
|
int | None
|
Optional total row count. When omitted, it is inferred from the largest region index. |
None
|
charge
|
ndarray | None
|
Optional distributed charge term added to the interior rows. |
None
|
dtype
|
DTypeLike
|
Numeric dtype used for the returned matrix. |
DTYPE
|
Returns:
| Type | Description |
|---|---|
csc_matrix | ndarray
|
Sparse CSC gate-basis RHS when |
csc_matrix | ndarray
|
|
csc_matrix | ndarray
|
terms. |
Source code in tempura/electrostatics/solver.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
setup_solver(matrix, *, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, symmetric=False)
Create and factor a MUMPS solver for a sparse linear system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Real-valued system matrix to factor. |
required |
dtype
|
DTypeLike
|
Real numeric dtype used to cast |
DTYPE
|
blr
|
bool
|
Whether to enable MUMPS block low-rank factorization. |
BLR
|
eps_blr
|
float
|
BLR compression threshold used when |
EPS_BLR
|
symmetric
|
bool
|
Whether |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Factored MUMPS context that can be reused across solves. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in tempura/electrostatics/solver.py
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 | |
solve_linear_system(matrix, rhs, *, solver=None, dtype=DTYPE, blr=BLR, eps_blr=EPS_BLR, symmetric=False)
Solve matrix x = rhs with a factored MUMPS solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Real-valued system matrix to solve. |
required |
rhs
|
Any
|
Dense or sparse right-hand side array. |
required |
solver
|
Any | None
|
Optional existing factored MUMPS context to reuse. |
None
|
dtype
|
DTypeLike
|
Real numeric dtype used to cast the matrix and RHS. Tempura's electrostatics solve path does not preserve imaginary components. |
DTYPE
|
blr
|
bool
|
Whether to enable MUMPS block low-rank factorization. |
BLR
|
eps_blr
|
float
|
BLR compression threshold used when |
EPS_BLR
|
symmetric
|
bool
|
Whether |
False
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, Any]
|
Tuple of |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in tempura/electrostatics/solver.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |