openseespy_solvers.hybrid¶
Hybrid linear solver constructor.
hybrid() reuses a direct factorization (from a solver such as spsolve()) as a GMRES preconditioner. It is useful for
analyses where the tangent changes slowly and a full refactorization at every step is
unnecessarily expensive.
Solving Linear Problems¶
| Constructor | Description |
|---|---|
hybrid |
Direct factorization reused as a GMRES preconditioner |
Usage¶
from openseespy_solvers import hybrid
from openseespy_solvers.scipy import spsolve
solver = hybrid(spsolve(), rtol=1e-6, restart=50)
ops.system("PythonSparse", solver.to_openseespy())
Function Reference¶
Hybrid direct-iterative linear solvers for OpenSeesPy.
hybrid
¶
hybrid(direct: LinearSolver, *, rtol: float = 1e-06, atol: float = 0.0, restart: int | None = None, maxiter: int | None = None, x0: Any = None, refresh_every: int | None = None, debug: bool = False) -> _Hybrid
Configure a hybrid direct-iterative solver for OpenSees PythonSparse.
On the first solve (or when the number of equations changes), the inner
direct solver builds and factorizes the matrix and returns a direct
solution. On later solves with the same system size, the cached
factorization is kept frozen and used as a GMRES preconditioner while the
current matrix coefficients are applied to A. The factorization is
refreshed when:
- the number of equations changes,
- GMRES fails to converge,
refresh_everysteps elapse (if set).
The frozen factorization lives on the Python solver object, not inside
OpenSees. Reuse the same solver instance across wipeAnalysis()
or wipe()/model rebuilds (for example multiple ground motions with the
same mesh): as long as num_eqn is unchanged, the first run's
factorization is reused even when OpenSees reports
matrix_status='STRUCTURE_CHANGED'. Creating a new hybrid(...) or
copy.copy(solver) starts with an empty factorization cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direct
|
LinearSolver
|
Inner direct solver from :func: |
required |
rtol
|
float
|
GMRES convergence tolerances. Defaults are |
1e-06
|
atol
|
float
|
GMRES convergence tolerances. Defaults are |
1e-06
|
restart
|
int
|
GMRES restart length. |
None
|
maxiter
|
int
|
Maximum GMRES iterations. |
None
|
x0
|
ndarray
|
Initial guess for GMRES. When omitted, the previous solution is reused when the system size is unchanged. |
None
|
refresh_every
|
int
|
Force a factorization refresh every this many solves. Default is
|
None
|
debug
|
bool
|
Re-raise exceptions instead of returning a failure code. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
solver |
_Hybrid
|
Solver object for :meth: |
Examples:
>>> from openseespy_solvers import hybrid
>>> from openseespy_solvers.scipy import spsolve
>>> solver = hybrid(spsolve(), rtol=1e-6, restart=50)
>>> solver.backend
'scipy'
Source code in src/openseespy_solvers/_hybrid.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 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 | |