Skip to main content

Circuit

Struct Circuit 

Source
pub struct Circuit {
    pub title: String,
    /* private fields */
}
Expand description

A circuit under construction. Analyses live in analysis/ (Phase 1: Circuit::op).

Cloning copies the element specs, .nodesets and .ics; the clone never shares a Session’s warm-start state.

Fields§

§title: String

Implementations§

Source§

impl Circuit

Source

pub fn ac( &self, opts: &Options, sweep: AcSweep, points: usize, fstart: f64, fstop: f64, ) -> Result<Ac, Error>

Run .ac DEC|OCT|LIN N FSTART FSTOP.

Source§

impl Circuit

Source

pub fn new(title: impl Into<String>) -> Self

Source

pub fn add(&mut self, spec: impl Into<Spec>) -> Result<(), Error>

Add one device. Names and nodes are case-insensitive (the 3f5 lowercases the whole deck).

Source

pub fn nodeset(&mut self, node: impl Into<String>, value: f64)

.nodeset v(node) = value.

Source

pub fn ic(&mut self, node: impl Into<String>, value: f64)

.ic v(node) = value (enforced at the transient operating point; .tran … UIC ignores it in favor of device ICs).

Source§

impl Circuit

Source

pub fn dc(&self, opts: &Options, sweeps: &[DcSweep]) -> Result<Dc, Error>

Run a DC transfer-curve analysis over one or two sweep variables: V/I sources, resistors or temp (°C).

Source§

impl Circuit

Source

pub fn disto( &self, opts: &Options, sweep: AcSweep, points: usize, fstart: f64, fstop: f64, f2overf1: Option<f64>, ) -> Result<Disto, Error>

Run .disto DEC|OCT|LIN NP FSTART FSTOP <F2OVERF1> (DISTOan). The sources’ DISTOF1/DISTOF2 values drive the first-order kernels; their AC values play no part.

Source§

impl Circuit

Source

pub fn from_netlist(nl: &Netlist) -> Result<(Circuit, Vec<String>), Error>

Build a circuit from a parsed (and already subcircuit- expanded) netlist. notes collects remarks worth printing; anything the engine cannot represent faithfully is an error.

Source§

impl Circuit

Source

pub fn noise( &self, opts: &Options, output: &OutputVar, src: &str, sweep: AcSweep, points: usize, fstart: f64, fstop: f64, pts_per_summary: Option<usize>, ) -> Result<Noise, Error>

Run .noise V(OUT<,REF>) SRC DEC|OCT|LIN PTS FSTART FSTOP <PTS_PER_SUMMARY>.

output must be an OutputVar::Voltage: the 3f5’s .noise takes only V(OUTPUT<,REF>) (spice.txt), so a current output is an Error::Build.

Source§

impl Circuit

Source

pub fn op(&self, opts: &Options) -> Result<Op, Error>

Compute the operating point.

Source§

impl Circuit

Source

pub fn pss(&self, opts: &Options, p: &PssParams) -> Result<Pss, Error>

Run .pss: the periodic steady state of the circuit driven at the fundamental p.freq (or the one its sources share), by shooting–Newton with matrix-free GMRES on the period map (see the module docs). Fails with Error::PssConvergence when p.max_iter shooting iterations do not bring the period mismatch within tolerance.

Source§

impl Circuit

Source

pub fn pz( &self, opts: &Options, nodes: [&str; 4], input: PzInput, which: PzWhich, ) -> Result<Pz, Error>

Run .pz NODE1 NODE2 NODE3 NODE4 CUR|VOL POL|ZER|PZ.

Source§

impl Circuit

Source

pub fn run( &self, analysis: &Analysis, opts: &Options, ) -> Result<(Vec<Solution>, Vec<String>), Error>

Run one analysis card (.op, .dc, .tran, .ac, .pz, .noise, .disto, .tf, .sens, ngspice’s .sp, and .pss) as spice3 -b (ngspice -b for .sp) would.

Returns the plots in rawfile order with their 3f5/ngspice plotnames — one for most analyses; .noise gives the density plot plus, when the band has more than one frequency, the integrated totals; .disto gives 2 or 3 plots; .pss the period and its harmonics — and the analysis’ notes (non-fatal remarks the caller may show). This is Circuit::run_card with the .pss result reduced to its plots (CardOutput::into_plots).

A .tf/.sens output that is not V(..)/I(..) is an Error::Build; engine failures pass through unchanged.

Source

pub fn run_card( &self, analysis: &Analysis, opts: &Options, ) -> Result<CardOutput, Error>

Run one analysis card as Circuit::run does, keeping a .pss result whole (CardOutput::Pss: period, t0 and the shooting history besides the plots). The card’s parameters are read here and only here — for .pss, the PssParams of the card (ngspice’s integer truncation of the counts, the defaults of PssParams::default for what it omits).

Source§

impl Circuit

Source

pub fn sens( &self, opts: &Options, output: &OutputVar, filters: &[String], ac: Option<SensAc>, ) -> Result<Sens, Error>

Run .sens OUTVAR [FILTER…] [AC DEC|OCT|LIN N FSTART FSTOP] (filters empty: every parameter).

Source§

impl Circuit

Source

pub fn alter( &mut self, refdes: &str, param: &str, value: impl Into<AlterValue>, ) -> Result<(), Error>

Change one parameter of element refdes in place — the spice3/ngspice alter command. The next analysis sees the circuit exactly as if the deck had been written with the new value (same spec field, same unit as the card).

refdes is the element name (case-insensitive; subcircuit instances by their expanded name, e.g. r.x1.r1). param is the ngspice parameter name, "" for the element’s principal value:

elementparam ("" →)value
Rresistance (r)ohms, nonzero
C / Lcapacitance (c) / inductance (l), icF / H; IC in V / A
V / Idc, acmag, acphase (degrees)V or A
V / Ipulse, sin, exp, pwl, sffm, trnoise, trrandomAlterValue::List: the card’s arguments; replaces the transient function
E F G Hgainas on the card
MOS (all levels, BSIM)w, lmeters, positive
MOS 1/2/3/6, D, Q, Jtemp°C, like TEMP= on the card
D, Q, J, Zareapositive

Altering acmag/acphase of a source without an AC specification gives it one (the other half 0), as the card AC 0 <phase> would. Inductor values also move the coupling of their K elements (MUTfactor is recomputed at each run). Topology never changes, so an altered circuit keeps its unknowns and output vectors. The circuit-wide temperature is an option: Session::set_temp.

Errors (Error::Build): unknown element, a parameter the element does not have (the message lists the valid ones), a non-finite value, a zero resistance, a nonpositive W/L/ area, a number where a list is due or vice versa.

Source

pub fn param( &self, refdes: &str, param: &str, ) -> Result<Option<AlterValue>, Error>

The current value of an alterable parameter (same names and units as Circuit::alter), e.g. to seed a slider. A value the element never got — a MOS W left to .options defw, a source without AC — reads as None; a source without a transient function reads None for pulse and friends, and only the function the source has reads Some.

Source

pub fn alterable(&self, refdes: &str) -> Result<&'static [&'static str], Error>

The parameter names Circuit::alter accepts for refdes (empty for an element with none).

Source§

impl Circuit

Source

pub fn sp( &self, opts: &Options, sweep: AcSweep, points: usize, fstart: f64, fstop: f64, donoise: bool, ) -> Result<Sp, Error>

Run .sp DEC|OCT|LIN N FSTART FSTOP <DONOISE> over the circuit’s RF ports (V sources with crate::RfPort); at least two ports are required.

Source§

impl Circuit

Source

pub fn tf( &self, opts: &Options, output: &OutputVar, insrc: &str, ) -> Result<Tf, Error>

Run .tf OUTVAR INSRC.

Source§

impl Circuit

Source

pub fn tran( &self, opts: &Options, tstep: f64, tstop: f64, tstart: f64, tmax: Option<f64>, uic: bool, ) -> Result<Tran, Error>

Run .tran TSTEP TSTOP <TSTART <TMAX>> <UIC>.

Trait Implementations§

Source§

impl Clone for Circuit

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 Default for Circuit

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn by_ref(&self) -> &T

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> Imply<T> for U
where T: ?Sized, U: ?Sized,

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.