1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
//! The shifted DAE operator: `(A − σI)⁻¹`, without ever forming `A`.
//!
//! [`smallsignal::analyze`](super::smallsignal::analyze) eliminates the
//! algebraic block by brute force — one solve per state column, then a dense
//! `n_x × n_x` matrix and a dense eigen-decomposition. That is right up to a
//! couple of thousand states and hopeless past it: the reduction alone is
//! `O(n_x²·n_net)`, and a four-thousand-bus case has twenty thousand states.
//!
//! A sparse eigensolver does not need `A`. It needs to *apply* something, and
//! for the modes anyone asks about — the poorly damped ones, in a named
//! frequency band — the thing to apply is the shift-invert operator
//! `(A − σI)⁻¹`, whose largest eigenvalues are the eigenvalues of `A` nearest
//! `σ`. This module provides exactly that, matrix-free.
//!
//! # The pencil
//!
//! Write the linearized DAE as a generalized eigenproblem rather than a reduced
//! one:
//!
//! ```text
//! ⎡ A_x A_v ⎤ ⎡x⎤ ⎡ I 0 ⎤ ⎡x⎤
//! ⎣ C_x C_v ⎦ ⎣v⎦ = λ ⎣ 0 0 ⎦ ⎣v⎦
//! J E
//! ```
//!
//! Its finite eigenvalues are exactly those of the reduced `A`. The bottom
//! block-row carries no `λ` — `E`'s lower block is zero — so it reads
//! `C_x x + C_v v = 0` whatever `λ` is, giving `v = −C_v⁻¹C_x x`, and the top
//! row then becomes `A x = λ x`. Nothing is approximated by working with the
//! pencil; it is the same problem written without performing the elimination.
//!
//! # The operator
//!
//! For `b` in the state space, define
//!
//! ```text
//! S(b) = the leading n_x entries of (J − σE)⁻¹ [b; 0]
//! ```
//!
//! By the Schur-complement identity `(K⁻¹)₁₁ = (P − Q T⁻¹ R)⁻¹` applied to
//! `K = J − σE`, this **is** `(A − σI)⁻¹ b`, exactly. The Krylov space lives in
//! `C^{n_x}`; the cost per application is one sparse solve on the bordered
//! `(n_x + 2·n_bus)` system, against a factorization computed once per shift.
//!
//! # Why the shift is free
//!
//! [`DaePattern::fill`](super::dae::DaePattern::fill) at `h·a = 1` writes
//!
//! ```text
//! M = ⎡ I − A_x −A_v ⎤
//! ⎣ C_x C_v ⎦
//! ```
//!
//! and `J − σE` is that with the top `n_x` rows **negated** and `(1 − σ)` added
//! on the state diagonal: `−(I − A_x) + (1 − σ)I = A_x − σI`, `−(−A_v) = A_v`,
//! and the bottom rows are already what they should be. The state diagonal is
//! structurally present — `DaePattern::analyze` emits a *dense* `∂f/∂x` block
//! per device — so a shift adds no fill-in and changes no pattern. The same
//! property that makes every event in a run value-only makes every shift
//! value-only here.
//!
//! # Arithmetic
//!
//! Complex, because the question is. A real shift can only aim at a point on
//! the real axis; naming a frequency band — *the inter-area modes near 0.5 Hz*
//! — needs `σ = α + jβ`, and targeting a region of the complex plane is the
//! whole reason to use this method rather than the dense one.
//!
//! The price is that the five pluggable
//! [`LinearSolver`](crate::solver::LinearSolver) backends are real-only and do
//! not apply here; `sparse::ComplexSparseSystem` serves, whose
//! factorize-once/solve-many contract is exactly what an Arnoldi iteration
//! wants. That is the same position the Y-bus's own complex solves are already
//! in, and it is recorded rather than worked around.
use Complex;
use crateComplexSparseSystem;
use DynamicSystem;
use fill_at_equilibrium;
/// A factorization of `J − σE` for one shift, and the operator it provides.
///
/// Built once per shift and applied many times — a hundred or more, across an
/// Arnoldi run and its adjoint. Both directions share this one factorization.
/// Why a shifted operator could not be built.