pub struct NumericMnaSystem {
pub a: Matrix<f64>,
pub k: Matrix<f64>,
pub b: Matrix<f64>,
pub unknowns: Vec<String>,
pub inputs: Vec<String>,
pub input_values: Vec<f64>,
pub u: Vec<f64>,
}Expand description
Numerically evaluated descriptor system.
Fields§
§a: Matrix<f64>Memoryless matrix.
k: Matrix<f64>Storage matrix.
b: Matrix<f64>Independent-source incidence matrix.
unknowns: Vec<String>Unknown names.
inputs: Vec<String>Input names.
input_values: Vec<f64>Source values in inputs order, evaluated the same way a/k/b are. Unlike
crate::MnaSystem::u (baked once, symbolically, at build time from each netlist
source’s literal value), this is recomputed by every MnaSystem::evaluate call —
which matters for a source whose value genuinely changes between evaluations, such as
a piecewise-linear device’s Norton-equivalent current ({name}_Ioff), rather than a
netlist-declared V/I source whose value never changes after parsing.
Evaluating an input’s value is best-effort, not required: a source whose symbol has no
entry in values (e.g. a duty ratio or Vin a caller only cares about symbolically,
while evaluating unrelated structural matrices) gets f64::NAN here rather than
failing the whole MnaSystem::evaluate call, matching this method’s existing
behavior for a/k/b requiring only the symbols the caller actually supplied. u
below treats a NAN input as contributing 0.0, not NAN, to every row.
u: Vec<f64>The expanded right-hand side B * input_values, in unknown order — the numeric twin
of crate::MnaSystem::u, computed fresh from input_values above rather than from
the netlist’s original (possibly stale) literal values. Rows depending only on inputs
that evaluated successfully are exact; see input_values above for the unresolved case.
Implementations§
Source§impl NumericMnaSystem
impl NumericMnaSystem
Sourcepub fn to_state_space(
&self,
tolerance: f64,
) -> Result<NumericStateSpace, StateSpaceError>
pub fn to_state_space( &self, tolerance: f64, ) -> Result<NumericStateSpace, StateSpaceError>
Eliminates algebraic variables with a Schur complement.
Dynamic variables are the MNA indices whose row in K is nonzero.
This matches capacitor-node voltages and inductor branch currents for
the linear stamps produced by this crate.
Examples found in repository?
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let netlist = "V1 in 0 1\nR1 in out R\nC1 out 0 C";
8 let symbolic = MnaBuilder::new(Dialect::Ngspice).build_fragment(netlist)?;
9
10 println!("unknowns: {:?}", symbolic.unknowns);
11 println!("A: {:?}", symbolic.to_string_system().a);
12 println!("K: {:?}", symbolic.to_string_system().k);
13
14 let values = BTreeMap::from([("R".into(), 1_000.0), ("C".into(), 1e-6)]);
15 let state_space = symbolic.evaluate(&values)?.to_state_space(1e-12)?;
16 println!("states: {:?}", state_space.states);
17 println!("state A: {:?}", state_space.a.as_slice());
18 println!("state B: {:?}", state_space.b.as_slice());
19 Ok(())
20}