Tcl NgspiceTclBridge package (v0.1)

::ngspicetclbridgeTop, Main, Index

CommandsTop, Main, Index

abort [::ngspicetclbridge]Top, Main, Index

Sets an internal abort flag and wake any waiters (useful to force waitevent to return). This does not free the instance.

abort

asyncvector [::ngspicetclbridge]Top, Main, Index

Fetches the current values of a named vector on demand via ngspice ngGet_Vec_Info. Works after the simulation has produced any data (not necessarily the complete vector). By addding -info switch, vector metadata is provided, i.e. type of the vector (current, voltage, time, etc), type of the numbers (complex or real), and length of the vector.

asyncvector ?-info? name
Parameters
nameName of the vector.
-infoIf this switch is provided, commands return dictionary with vector metadata.
Description

Example:

$sim initvectors
$sim asyncvector out
# -> {0.0 0.066666... 0.133333... ...}

$sim asyncvector V(9)
# -> {{0.01 0.00} {0.02 0.00} ...}   ;# if complex
Return value

real vectors as a flat list of doubles, complex vectors as a list of {re im} pairs. Error if vector does not exists.

circuit [::ngspicetclbridge]Top, Main, Index

Sends an circuit to Ngspice in form of the list, each element is the lineof the netlist.

circuit list
Parameters
listList of string.
Description

Example:

set resDivCircuit {
    Resistor divider
    v1 in 0 1
    r1 in out 1e3
    r2 out 0 2e3
    .dc v1 0 5 0.1
    .save all
    .end
}
$sim circuit [split $resDivCircuit \n]
$sim command bg_run
Return value

Ngspice result code

command [::ngspicetclbridge]Top, Main, Index

Sends an arbitrary Ngspice command line (e.g., bg_run, circbyline ..., .save, .tran, .dc). If we provide -capture switch, it returns not only the result code, but also the next message from stdout of Ngspice. Also, if command is send in the moment background thread is starting or stopping, it will be deferred to the time is could be safely sent, and in that case -capture message and command results code are not availaible as a return of command.

command string
Parameters
stringCommand string.
Description

Example:

$sim command {circbyline v1 in 0 1}
$sim command bg_run
Return value

Ngspice result code, or dictionary with result code and the message

destroy [::ngspicetclbridge]Top, Main, Index

Deletes the instance command. In details:

destroy
Description

eventcounts [::ngspicetclbridge]Top, Main, Index

Gets or reset the cumulative event counters for this simulator instance.

eventcounts ?-clear?
Parameters
-clearZeros all counts and returns nothing.
Description

Example:

$sim eventcounts
# -> send_char N  send_stat N  controlled_exit N send_data N  send_init_data N  bg_running N
Return value

returns a dict with keys as events names, and counts for each event as a value

getCircuit [::ngspicetclbridge]Top, Main, Index

Gets list with currently loaded circuit (its listing) in the form specified by the switch.

getCircuit ?-logical|-physical|-deck|-expand|-runnable|-param? sim
Parameters
-deckJust like the physical listing, except without the line numbers it recreates the input file verbatim (except that it does not preserve case)
-expandThe circuit is printed with all subcircuits expanded.
-logicalThe circuit is with all continuation lines collapsed into one line.
-paramPrinting all parameters and their actual values.
-physicalThe circuits lines are printed out as they were found in the file.
-runnableCircuit netlist expanded, but without additional line numbers, ready to be sourced again and run in ngspice. Default version if no witch is provided.
simSimulator handler that is returned by ngspicetclbridge::new
Return value

list with listing lines

getCircuitTitle [::ngspicetclbridge]Top, Main, Index

Gets title of the current circuit (first line of circuits netlist).

getCircuitTitle sim
Parameters
simNot documented.
Return value

title

getPlotDate [::ngspicetclbridge]Top, Main, Index

Gets time stamp of current plot generation.

getPlotDate sim
Parameters
simNot documented.
Return value

time stamp

getPlotName [::ngspicetclbridge]Top, Main, Index

Gets name of the current plot, i.e. Operating Point, AC Analysis, etc.

getPlotName sim
Parameters
simNot documented.
Return value

name of the plot

getScaleInfo [::ngspicetclbridge]Top, Main, Index

Gets dictionary with information about current scale vector.

getScaleInfo sim
Parameters
simNot documented.
Return value

dictionary with the information

initvectors [::ngspicetclbridge]Top, Main, Index

Returns held initial vector metadata (built from send_init_data) in a dict. dict with initial vector metadata saved in internal structure

initvectors ?-clear?
Parameters
-clearEmpties the internal memory structure and returns nothing.
Description

Example:

$sim initvectors
# -> out {number 1 real 1} in {number 2 real 1} v-sweep {number 3 real 1}

Warning: accumulation of data do not continues after call bg_run, new metadata replace the old one in the storage.

Return value

Returns held initial vector metadata (built from send_init_data) in a dict. dict with initial vector metadata saved in internal structure

inputpath [::ngspicetclbridge]Top, Main, Index

Returns current path for XSPICE code models if -current switch is provided, or set current path to value provided. current path

inputpath -current
inputpath path
Parameters
-currentSwitch to return current path.
pathFull path to desired location.
Return value

Returns current path for XSPICE code models if -current switch is provided, or set current path to value provided. current path

isrunning [::ngspicetclbridge]Top, Main, Index

Calls asynchronously to check if background thread is running.

isrunning
Return value

1 if thread is running, 0 otherwise.

messages [::ngspicetclbridge]Top, Main, Index

Queues of textual messages captured from Ngspice (stdout/stderr) and bridge status lines.

messages ?-clear?
Parameters
-clearEmpties the internal queue structure and returns nothing.
Description

Example:

join [$sim messages] \n
# stdout ******
# stdout ** ngspice-44.x shared library
# ...
# # status[0]: --ready--

Warning: accumulation of messages continues even if you run new circuit or analysis until you explicitly clear the data storage.

Return value

list of messages

new [::ngspicetclbridge]Top, Main, Index

Load dynamic library, path should be provided in native form for target OS. Every ::ngspicetclbridge::new returns a command (e.g. ::ngspicetclbridge::s1). The following subcommands operate on that instance. Optionally the spinit and/or spiceinit initialization files could be forbidden for loading.

new ?-nospinit|nospiceinit|noinit? libpath
Parameters
-noinitInhibit both spinit and spiceinit.
-nospiceinitInhibits spiceinit.
-nospinitInhibits spinit.
libpathAbsolute full path to dynamic library.
Description

Example:

set sim [::ngspicetclbridge::new /usr/local/lib/libngspice.so]
Return value

command name to work with Ngspice instance

plot [::ngspicetclbridge]Top, Main, Index

Returns current plot name if no arguments provided, names of all plots or all vectors names that belongs to name of the provided plot. current plot, or list of all plots, or list of all vectors

plot -all
plot -vecs name
Parameters
-allSwitch to return all plots names.
-vecs plotnameSwitch with argument to get all vectors names belonging to name plot.
Return value

Returns current plot name if no arguments provided, names of all plots or all vectors names that belongs to name of the provided plot. current plot, or list of all plots, or list of all vectors

readVecsAsync [::ngspicetclbridge]Top, Main, Index

Reads all availible vectors of the current plot asynchronously and return dictionary with vector name as a key, and data as a value. If -info switch is provided, command returns information about each availiable vector.

readVecsAsync ?-info? sim
Parameters
-infoIf provided, metainfo about vectors is returned instead of the data.
simSimulator handler that is returned by ngspicetclbridge::new
Return value

dictionary

run [::ngspicetclbridge]Top, Main, Index

Runs simulation in background thread, waits for the completion, process event in the queue and returns

run sim
Parameters
simSimulator handler that is returned by ngspicetclbridge::new
Return value

vectors [::ngspicetclbridge]Top, Main, Index

Returns held synchronously accumulated vector values (built from send_data events) in a dict. dict with vectors values accumulated up to this point in internal structure

vectors ?-clear?
Parameters
-clearEmpties the internal memory structure and returns nothing.
Description

Example:

$sim vectors
# -> v(out) {0.0 0.1 0.2 ...} v(in) {...} v-sweep {...}

$sim vectors -clear
# -> (no result; succeeds)
Return value

Returns held synchronously accumulated vector values (built from send_data events) in a dict. dict with vectors values accumulated up to this point in internal structure

waitevent [::ngspicetclbridge]Top, Main, Index

Blocks until a named event is observed n number of times (or once), the instance is aborted/destroyed, or the timeout expires (if provided).

waitevent ?args?
Parameters
-n NNumber of events that should happend for termination after waiting is started.
nameName of the event.
timeout_msTimeout in miliseconds, optional.
Description

Event nameNgspice callback function nameWhen it is called
send_charSendCharWhenever Ngspice produces a line of text on stdout or stderr.
send_statSendStatWhen Ngspice’s simulation status changes (e.g., --ready--, tran 50.1%, convergence messages).
controlled_exitControlledExitWhen Ngspice exits, either due to an error or after a quit command from Tcl/Ngspice.
send_dataSendDataDuring an analysis, whenever Ngspice sends a row of vector values (time step or sweep point) to the callback.
send_init_dataSendInitDataAt the start of a run, when Ngspice sends metadata for all vectors in the current plot (names, types, indexes, real/complex).
bg_runningBGThreadRunningWhen the Ngspice background thread changes state: running=false means it just started running, running=true means it has stopped.

TimeTcl Script ActionNgspice Core ActivityBridge Callback FiredTcl Event Name Seen
t0set s [..::new ..]Library loaded(none)(none)
t1$sinit Initialization completed(none)(none)
t2cirPass …Parses circuit linesend_char("...")send_char
t3(more circbyline calls)Parses circuit linesend_char("...")send_char
t4$scommand bg_runStart background simulationbg_running(false)bg_running
t5(analysis setup)Build vector tablesend_init_data()send_init_data
t6(analysis running)First data pointsend_data(...)send_data
t7(analysis running)More pointssend_data(...)send_data
t8(analysis running)Status changesend_stat("...")send_stat
t9(analysis completed)Simulation readysend_stat("--ready--")send_stat
t10(BG thread exits)Background thread exitsbg_running(true)bg_running
t11$scommand quitngspice quitscontrolled_exit(...)controlled_exit
t12$sdestroyTeardown(no further calls)(command removed)

Return value

dictionary with information about event