pub struct SpiceRunner { /* private fields */ }Expand description
Runner for ngspice simulations.
Implementations§
Source§impl SpiceRunner
impl SpiceRunner
Sourcepub fn new(config: SpiceConfig) -> Self
pub fn new(config: SpiceConfig) -> Self
Create a new SPICE runner with the given configuration.
Sourcepub fn check_ngspice() -> Result<String, SpiceError>
pub fn check_ngspice() -> Result<String, SpiceError>
Check if ngspice is available.
Sourcepub fn simulate(
&self,
circuit_path: impl AsRef<Path>,
input: &[f64],
output_node: &str,
) -> Result<Vec<f64>, SpiceError>
pub fn simulate( &self, circuit_path: impl AsRef<Path>, input: &[f64], output_node: &str, ) -> Result<Vec<f64>, SpiceError>
Sourcepub fn config(&self) -> &SpiceConfig
pub fn config(&self) -> &SpiceConfig
Get the configuration.
Sourcepub fn decimate_to_base(&self, internal: &[f64]) -> Vec<f64>
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).
Sourcepub fn simulate_settled_window(
&self,
circuit_path: impl AsRef<Path>,
input_internal: &[f64],
output_node: &str,
settle_s: f64,
) -> Result<Vec<f64>, SpiceError>
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
impl SpiceRunner
Sourcepub fn operating_point(
&self,
circuit_path: impl AsRef<Path>,
) -> Result<SpiceOpSnapshot, SpiceError>
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.