Skip to main content

TransientFunction

Enum TransientFunction 

Source
pub enum TransientFunction {
    Sin {
        v0: f64,
        va: f64,
        freq: f64,
        td: f64,
        theta: f64,
        phase: f64,
    },
    Pulse {
        v1: f64,
        v2: f64,
        td: f64,
        tr: f64,
        tf: f64,
        pw: f64,
        per: f64,
    },
    Exp {
        v1: f64,
        v2: f64,
        td1: f64,
        tau1: f64,
        td2: f64,
        tau2: f64,
    },
    Pwl(PwlPoints),
    Sffm {
        v0: f64,
        va: f64,
        fc: f64,
        mdi: f64,
        fs: f64,
    },
}
Expand description

One parsed transient-function call, in the same field order and names ngspice/Xyce use.

Variants§

§

Sin

SIN(V0 VA FREQ TD THETA PHASE) — a damped sinusoid superimposed on an offset, starting flat at V0 until TD, then V0 + VA*sin(2*pi*FREQ*(t-TD) + PHASE) * exp(-(t-TD)*THETA) (THETA=0 is a plain undamped sinusoid; FREQ in Hz, PHASE in degrees, matching every SPICE dialect’s own convention for this source).

Fields

§v0: f64

Offset value held before td and added under the sinusoid afterward.

§va: f64

Sinusoid amplitude.

§freq: f64

Sinusoid frequency in Hz.

§td: f64

Delay, in seconds, before the sinusoid starts.

§theta: f64

Exponential damping factor (0 = undamped).

§phase: f64

Phase offset in degrees.

§

Pulse

PULSE(V1 V2 TD TR TF PW PER) — a periodic trapezoid: V1 until TD, linear ramp to V2 over TR, hold at V2 for PW, linear ramp back to V1 over TF, hold at V1 for the remainder of one period PER, repeating. TR/TF of exactly 0 are treated as instantaneous edges (division by a real, if tiny, ramp time is what every real SPICE implementation does instead; 0 is special-cased here to avoid dividing by zero).

Fields

§v1: f64

Initial (and final, between periods) value.

§v2: f64

Pulsed value.

§td: f64

Delay, in seconds, before the first pulse starts.

§tr: f64

Rise time from v1 to v2; 0 is treated as an instantaneous edge.

§tf: f64

Fall time from v2 back to v1; 0 is treated as an instantaneous edge.

§pw: f64

Duration held at v2.

§per: f64

Total period; the remainder after td + tr + pw + tf is held at v1.

§

Exp

EXP(V1 V2 TD1 TAU1 TD2 TAU2) — flat at V1 until TD1, exponential transition toward V2 with time constant TAU1 starting at TD1, exponential transition back toward V1 with time constant TAU2 starting at TD2.

Fields

§v1: f64

Initial value, held until td1.

§v2: f64

Value the first exponential transition rises or decays toward.

§td1: f64

Delay, in seconds, before the transition toward v2 starts.

§tau1: f64

Time constant of the transition toward v2.

§td2: f64

Delay, in seconds, before the transition back toward v1 starts.

§tau2: f64

Time constant of the transition back toward v1.

§

Pwl(PwlPoints)

PWL(t1 v1 t2 v2 ...) — linearly interpolated between explicit (time, value) breakpoints (unlike dae_runtime::block_graph::BlockKind::Pwl, which is piecewise-constant — this is real SPICE PWL, piecewise-linear, matching the source syntax’s own name). Held at the first point’s value before the first breakpoint, and at the last point’s value after the last one.

§

Sffm

SFFM(V0 VA FC MDI FS) — single-frequency FM: V0 + VA*sin(2*pi*FC*t + MDI*sin(2*pi*FS*t)).

Fields

§v0: f64

Offset value.

§va: f64

Carrier amplitude.

§fc: f64

Carrier frequency in Hz.

§mdi: f64

Modulation index.

§fs: f64

Signal (modulating) frequency in Hz.

Implementations§

Source§

impl TransientFunction

Source

pub const FUNCTION_NAMES: [&'static str; 5]

The names of the five transient-function forms this type implements, uppercase, in the order they are declared above, and exactly the set Self::parse’s own match arms cover (a unit test below asserts that, so the two cannot drift). Self::parse_params scans for these names, and builder.rs’s device-card validation rejects a misspelled one (SNI(...)) by asking whether the name is in here rather than by writing the list out a second time.

Source

pub fn value_at(&self, t: f64) -> f64

Evaluates this source at time t (seconds), per the standard SPICE definition for its own function form.

Source

pub fn is_function_name(name: &str) -> bool

Whether name (compared case-insensitively) is one of Self::FUNCTION_NAMES.

Source

pub fn find_call(tokens: &[String]) -> Option<(usize, usize)>

The token range of the first transient-function call inside an independent source’s parameter list, as (first, last) inclusive indices into tokens, or None if the list contains no recognized call.

Needed because the call is not always the first parameter: V1 1 0 DC 0 SIN(0 1 1k) is ordinary SPICE, and scanning only tokens[0] (which is all Self::parse does, by design — it takes a slice that already starts at the call) silently dropped the whole waveform and simulated a flat 0 V source instead. The end index is the token carrying the closing ), since general-spice-core splits SIN(0 10 1000) across three tokens.

Source

pub fn parse_params(tokens: &[String]) -> Option<TransientFunction>

Parses the first transient-function call appearing anywhere in an independent source’s parameter list, or None when it contains none.

This is what a caller holding a whole V/I card’s raw_params wants; Self::parse is the narrower primitive that assumes the slice already begins at the call. See Self::find_call for why the difference matters.

Source

pub fn parse(tokens: &[String]) -> Option<TransientFunction>

Detects and parses one of the five transient-function forms from an already-tokenized parameter list (as general-spice-core hands back — see the module doc comment for exactly how mangled that tokenization is: parentheses stuck to whichever token they landed on). Returns None if tokens doesn’t start with a recognized function name, so the caller can fall back to treating the source as an ordinary static value.

Trait Implementations§

Source§

impl Clone for TransientFunction

Source§

fn clone(&self) -> TransientFunction

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 TransientFunction

Source§

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

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

impl PartialEq for TransientFunction

Source§

fn eq(&self, other: &TransientFunction) -> 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 TransientFunction

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.