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
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
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
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)).
Implementations§
Source§impl TransientFunction
impl TransientFunction
Sourcepub const FUNCTION_NAMES: [&'static str; 5]
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.
Sourcepub fn value_at(&self, t: f64) -> f64
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.
Sourcepub fn is_function_name(name: &str) -> bool
pub fn is_function_name(name: &str) -> bool
Whether name (compared case-insensitively) is one of Self::FUNCTION_NAMES.
Sourcepub fn find_call(tokens: &[String]) -> Option<(usize, usize)>
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.
Sourcepub fn parse_params(tokens: &[String]) -> Option<TransientFunction>
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.
Sourcepub fn parse(tokens: &[String]) -> Option<TransientFunction>
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
impl Clone for TransientFunction
Source§fn clone(&self) -> TransientFunction
fn clone(&self) -> TransientFunction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more