Skip to main content

SpiceRunner

Struct SpiceRunner 

Source
pub struct SpiceRunner { /* private fields */ }
Expand description

Runner for ngspice simulations.

Implementations§

Source§

impl SpiceRunner

Source

pub fn new(config: SpiceConfig) -> Self

Create a new SPICE runner with the given configuration.

Source

pub fn check_ngspice() -> Result<String, SpiceError>

Check if ngspice is available.

Source

pub fn simulate( &self, circuit_path: impl AsRef<Path>, input: &[f64], output_node: &str, ) -> Result<Vec<f64>, SpiceError>

Run a SPICE simulation with the given input signal.

§Arguments
  • circuit_path - Path to the .spice circuit file
  • input - Input signal samples at internal_rate
  • output_node - Node name to measure (e.g., “v_out”)
§Returns

Output signal resampled to sample_rate

Source

pub fn config(&self) -> &SpiceConfig

Get the configuration.

Source

pub fn decimate_to_base(&self, internal: &[f64]) -> Vec<f64>

Decimate an internal-rate signal (sample_rate × oversample) down to the base sample_rate by taking every oversample-th sample.

[simulate] returns at the INTERNAL rate (to match the oversampled main runner). The standalone *_spice.rs tests instead compare against a WDF processor compiled at the BASE sample_rate, so their golden must be at the base rate too — otherwise a 1 kHz golden tone carries oversample× the samples-per-period of the WDF tone and the 1:1 comparison lines up two signals at different rates (the bug this fixes).

Source

pub fn simulate_settled_window( &self, circuit_path: impl AsRef<Path>, input_internal: &[f64], output_node: &str, settle_s: f64, ) -> Result<Vec<f64>, SpiceError>

Run a SETTLED steady-state simulation and return the MEASUREMENT window at the base sample_rate.

input_internal is the full stimulus at the internal rate covering settle_s + measure_s seconds. The circuit is simulated over that whole span so coupling caps / bias networks reach steady state; the first settle_s is then discarded and the remaining tail is decimated to the base sample_rate. The settle boundary is floored to a multiple of oversample so the decimated grid stays phase-aligned with a WDF processor warmed up by the same settle_s.

The returned golden is at the base sample_rate: len ≈ measure_s × sample_rate, and a tone of frequency f has sample_rate / f samples per period.

Source§

impl SpiceRunner

Source

pub fn operating_point( &self, circuit_path: impl AsRef<Path>, ) -> Result<SpiceOpSnapshot, SpiceError>

Run ngspice .op on a standalone deck and capture the DC operating point.

Composes the deck the same way Self::simulate does (stripping standalone control/analysis directives), injects a quiescent VIN v_in 0 DC 0 source, and runs an .op followed by show (per-device params) and print all (node voltages). The show table is parsed into SpiceDeviceOp records (vce = vbe − vbc, ic from the row).

This is read-only and ngspice-derived — the resulting snapshot is the golden the WDF DC bias is graded against.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more