Skip to content

Simulation Calculator

The Simulation Calculator provides a powerful Python-based environment to evaluate expressions, plot waveforms, and manipulate simulation data generated by OpenS.

Overview

The Calculator uses an embedded Python execution environment. It automatically extracts vectors and variables from your simulation results when run (e.g., Transient, AC, DC, and Operating Point analyses). Any valid Python script can be evaluated here, and the results can be plotted to the Waveform Viewer or displayed in the Results dialog as scalars.

[!NOTE] All NumPy functions are available natively via the np variable, which is automatically imported into your script's scope.


Signal Fetching Functions

The Calculator provides built-in helper functions to easily fetch signals, arrays, and scalars from your simulation raw plots.

General Fetcher

  • v(name, plot=None): The generic voltage fetcher. It automatically tries to find the signal in your Transient, DC, AC, and Operating Point analyses consecutively.

Transient Analysis

  • vt(name, plot=None) or st(name, plot=None): Fetch a transient voltage signal array by name.
  • it(name, plot=None): Fetch a transient current signal array by name.
  • t: The default time array (numpy.ndarray) for the current transient analysis.

AC Analysis (Frequency Domain)

  • vf(name, plot=None) or sf(name, plot=None): Fetch an AC voltage signal array (complex numbers) by name.
  • ifc(name, plot=None): Fetch an AC current signal array (complex numbers) by name.
  • f: The default frequency array (numpy.ndarray) for the current AC analysis.

DC Sweep Analysis

  • vdc(name, plot=None) or sdc(name, plot=None): Fetch a DC sweep voltage signal array by name.

Operating Point Analysis

  • op(name, plot=None) or sop(name, plot=None): Fetch a scalar operating point value (voltage or current) by node name.

Math & Measurement Functions

You can analyze and process arrays returned by the fetcher functions.

[!TIP] If a parameter like t_start or t_stop is omitted, the measurement applies to the entire array.

  • mean(x, y, t_start=None, t_stop=None): Calculates the mean/average of y over the interval [t_start, t_stop] in x.
  • rms(x, y, t_start=None, t_stop=None): Calculates the Root Mean Square (RMS) of y over the interval [t_start, t_stop] in x.
  • p2p(x, y, t_start=None, t_stop=None): Calculates the Peak-to-Peak difference of y over the interval [t_start, t_stop].
  • value(x, y, at): Interpolates the value of y at the precise x coordinate specified by at.
  • f3db(result_array, plot_name=None): Calculates the 3dB frequency (bandwidth) of a complex AC array.
  • mag(x): Returns the absolute magnitude of a complex/real array (equivalent to np.abs(x)).
  • db(x) / dB(x): Converts an array to decibels (\(20 \times \log_{10}(|x|)\)).
  • ph(x): Returns the phase angle in degrees (np.angle(x, deg=True)).

Plotting & Visualization

The calculator integrates seamlessly into the Waveform Viewer to plot your Python expressions.

  • plot(x, y=None, label=None, title=None): Renders a standard 2D plot of y over x. If y is evaluated implicitly (e.g., just evaluating an array), the calculator defaults to using the t or f arrays as x.
  • bode(target, plot=None): Renders a Bode plot. Target can be either the name of an AC signal (e.g., 'vout') or an evaluated complex NumPy array from an AC analysis. It automatically handles plotting both magnitude (in dB) and phase (in degrees).
  • subaxis(nrows, idx) / subfigure(nrows, idx): Tools to divide the Waveform Viewer into horizontal subplots natively from scripts.

Special Context Variables

  • np: Provides full access to the numpy library (e.g., np.sin(t), np.max(vt('out'))).
  • plots: A dictionary containing raw Spice results covering all nodes.

Examples

Measuring the 3dB cutoff of vout:

bw = f3db(vf('vout'))

Plotting a signal in Decibels:

plot(f, dB(vf('out')), label="Vout (dB)")

Plotting power dissipated by a resistor:

v_resistor = vt('N_1') - vt('N_2')
i_resistor = it('R1')
plot(t, v_resistor * i_resistor, label="Power (W)")