Skip to main content

NumericMnaSystem

Struct NumericMnaSystem 

Source
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

Source

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?
examples/rc_state_space.rs (line 15)
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}

Trait Implementations§

Source§

impl Clone for NumericMnaSystem

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NumericMnaSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for NumericMnaSystem

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NumericMnaSystem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.