circuit
An electrical circuit simulated by ngspice 47 (the open-source SPICE; built from its pinned source tarball by install.sh): what reaches a load over time. The circuit is a small JSON netlist (named nodes; resistors, capacitors, inductors, diodes from a small library or with stated model parameters, timed switches, voltage and current sources as DC, sine, pulse, piecewise-linear or a sampled waveform from a CSV file of an earlier run; raw SPICE lines as an escape). Analyses: operating point, transient (duration and step), AC sweep. Measures, named by the caller (measures.<name>): a node's voltage, a part's current or power (every part is sensed by a 0 V source in series), as mean, RMS, peak, min, max, final, value at a time, time to reach a level, integral (energy); AC: peak, peak frequency, -3 dB bandwidth, Q. A criterion on one measure gives the verdict. Transients carry an energy balance (net source energy against dissipated plus stored). Files: waveforms.csv (every node voltage and part current; envelope-decimated when long), plot.png, deck.cir (the SPICE deck as run).
- Field
- Waves, optics and circuits
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 5 s
Compiled from source: run sh packs/install.sh once before admitting it.
A real run
- v at one time constant
- 0.6321 V
- time to 0.9 V
- 2.303 ms
- energy lost in R
- 0.5 µJ
- simulator
- ngspice-47
Known answers it must pass
r0001divider operating point: 10 V over 1 kohm + 3 kohm gives 7.5 V, 2.5 mA, 18.75 mW in the 3 kohm, -25 mW in the source (Ohm's law; to 1e-9)passed
measures.v_mid{"value": 7.5, "rel_tol": 1e-09}measures.i_r1{"value": 0.0025, "rel_tol": 1e-09}measures.p_r2{"value": 0.01875, "rel_tol": 1e-09}measures.p_v1{"value": -0.025, "rel_tol": 1e-09}r0002RC step, 1 kohm, 1 uF, 1 V from empty: v(tau) = 1 - 1/e, time to 0.9 V = tau ln 10, source energy C V^2 (1 - e^-5) over 5 tau (closed forms; 1e-5, 1e-5, 1e-4), energy balance to 1e-5, criterion metpassed
measures.v_tau{"value": 0.6321205588285577, "rel_tol": 1e-05}measures.t_90{"value": 0.002302585092994046, "rel_tol": 1e-05}measures.e_source{"value": -9.932620530009146e-07, "rel_tol": 0.0001}energy_balance_error≤ 1e-051.25408e-07lockedinside the rangeok= truetruelockedexact matchr0003series RLC, 10 ohm, 10 mH, 1 uF, AC sweep of the current: resonance 1/(2 pi sqrt(LC)) = 1591.549 Hz (1e-5), peak 1/R (1e-5), Q = sqrt(L/C)/R = 10 and -3 dB bandwidth R/(2 pi L) (5e-4: the -3 dB points are interpolated between sweep points 0.23 % apart)passed
measures.f0{"value": 1591.5494309189535, "rel_tol": 1e-05}measures.ipk{"value": 0.1, "rel_tol": 1e-05}measures.q{"value": 10.0, "rel_tol": 0.0005}measures.bw{"value": 159.15494309189535, "rel_tol": 0.0005}r0004half-wave rectifier, 1000 V peak, ideal diode, 10 kohm: mean output Vp/pi (closed form; 5e-4: the ideal-enough diode drops about 0.03 V at 0.1 A)passed
measures.vmean{"value": 318.3098861837907, "rel_tol": 0.0005}energy_balance_error≤ 1e-064.08579e-15lockedinside the ranger0005full-wave bridge, 1000 V peak, four ideal diodes, 10 kohm: mean output 2 Vp/pi (closed form; 5e-4, two diode drops)passed
measures.vmean{"value": 636.6197723675814, "rel_tol": 0.0005}r0006half-wave rectifier with a smoothing capacitor, 100 V peak at 50 Hz, 100 uF, 10 kohm: ripple against the standard approximation Vp/(f R C) = 2.0 V (6 %: the approximation lets the capacitor discharge for a whole period at constant current; it recharges for about 3 % of it and decays exponentially, so it runs about 4 % high), energy balance to 1e-4passed
measures.ripple{"value": 2.0, "rel_tol": 0.06}energy_balance_error≤ 0.00011.40112e-06lockedinside the ranger0007piezoelectric source into a full-bridge rectifier at half its open-circuit voltage: 0.1 mA sine at 100 Hz beside 1 nF, ideal diodes, into a 79.6 V store: power f Ip^2/(w^2 Cp) = 2.533 mW (Shu and Lien 2006, Smart Mater. Struct. 15 1499, eq. for the standard interface; 2e-3: two diode drops against 80 V)passed
measures.p_store{"value": 0.002533029591058444, "rel_tol": 0.002}energy_balance_error≤ 1e-054.10749e-10lockedinside the ranger0008PWL ramp 0 to 1 V in 1 ms across 1 uF draws C dV/dt = 1 mA (1e-6); a 1 uF capacitor charged to 1 V (ic) switched at 1 ms onto 1 kohm is at 1/e at 2 ms (1e-5); energy balance 1e-5passed
measures.i_ramp{"value": 0.001, "rel_tol": 1e-06}measures.v_b_2ms{"value": 0.36787944117144233, "rel_tol": 1e-05}energy_balance_error≤ 1e-051.46135e-07lockedinside the range
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
circuit | The netlist: {ground?: "0", parts: [...]}. Nodes are named (letters, digits, _; "0" or "gnd" is ground; SPICE ignores case). Parts, each with a unique name: {type: resistor|capacitor|inductor, between: [n1, n2], value (ohm, F, H), ic? (V or A, starting value)}; {type: diode, anode, cathode, part: ideal|BAS70 or model: {IS, N, RS, CJO, VJ, M, BV, IBV, TT, EG, XTI, ISR, NR...} with source: where the figures come from, leak_ohm?: a resistor across it}; {type: switch, between, closed: [[t_on, t_off], ...] or wave (closed while > 0.5), r_on? 1e-3, r_off? 1e12}; {type: voltage_source, plus, minus, wave, ac?}; {type: current_source, from, to, wave, ac?} (pushes current into node 'to'); {type: spice, lines: [raw SPICE]} (escape hatch: parts and models only). Waves: {dc: x}, {sine: {amplitude, frequency_Hz, offset?, phase_deg?, delay_s?}}, {pulse: {low, high, width_s, period_s?, delay_s?, rise_s?, fall_s?}}, {pwl: [[t, x], ...], repeat?}, {csv: {time: column, value: column, scale?, time_from_zero?, repeat?}} (file: wave_file). Every number may be a string naming a params entry or an expression over them. Plain numbers only: 1e-6, never 1u (SPICE suffixes are not read; M would be milli). | ||
circuit_file | The netlist as a JSON file instead of circuit. | ||
wave_file | A CSV file for a source with wave {csv: {time, value}} (e.g. an earlier run's history.csv). | ||
params | {} | Named numbers (or expressions over earlier ones) that the netlist, the analysis and the criterion may use: {"Vs": 3.0, "Ip": "2 * Vs / 1e6"}. Sweep them with bench sweep --grid=params.Vs=... | |
analysis | Default {type: op}. {type: op} | {type: tran, duration_s, step_s (print step and default largest step), max_step_s?, start?: auto|op|zero (zero: everything starts empty unless it has ic; auto: zero when any part has ic, else from the operating point), save_from_s?} | {type: ac, from_Hz, to_Hz, points_per_decade? 100} | ||
measures | Default none (an operating point still lists every node voltage and part current in op). [{name, of: v(node) | v(a,b) | i(part) | p(part), stat, ...}]. Transient stats: mean, rms, max, min, peak (largest |x|), peak_to_peak, final, initial, change (end of the window minus its start), at (time_s), time_to (level, direction rise|fall|either, after_s), integral (J for p()); window from_s/to_s or last_s. AC (magnitude): peak, peak_frequency, bandwidth, q, at (frequency_Hz), phase_at. Op: value. i(part) is the current into the part's first terminal (between[0], anode, plus, from); p(part) the power it absorbs (sources delivering: negative). | ||
criterion | A test on one measure for the verdict: {measure, at_least? | at_most? | within?: [lo, hi], text?: "reaches 1.8 V within 60 s"}. A level never reached (null) fails. | ||
options | {} | Simulator options: reltol (1e-3), abstol (1e-12 A), vntol (1e-6 V), gmin (1e-12 S: lower it, e.g. 1e-15, when pA leakage matters), chgtol, itl4, method (trap|gear). | |
temperature_C | Circuit temperature (SPICE temp; models are given at 27 degC). Diode leakage grows fast with it. | ||
energy_balance | true | Transient energy balance (needs every vector saved: off when keep is measured). | |
keep | all | Which vectors the simulator saves: all, or only what measures and plot need (long runs). | |
plot | Quantities to plot (default: those the measures use), e.g. ["v(out)", "i(RL)"]. | ||
title | The plot's title. | ||
csv_max_rows | 20000 | Rows of waveforms.csv before it is envelope-decimated. | |
timeout_s | s | 3000 | Wall time allowed to ngspice. |
Readings
| Name | Unit | Meaning |
|---|---|---|
measures | ||
measure_units | ||
figures | ||
ok | ||
criterion | ||
criterion_value | ||
energy_balance | ||
energy_balance_error | ||
op | ||
points | ||
duration_s | s | |
parts | ||
warnings | ||
waveforms.csv | ||
plot.png | ||
deck.cir |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.