Tcl SpiceGenTcl package (v)

FAQTop, Main, Index

The most frequent questions are collected here.

Where to find list of availible arguments for devices, models and analyses?Top, Main, Index

For the selected simulator, you need to open the documentation for the corresponding namespace, such as Ngspice. Then, select the category you are interested in:

Check out ::SpiceGenTcl::Ngspice::BasicDevices::Resistor as an example.

There, you can find a list of all available methods, a description of the arguments, an example of how the element string appears in the netlist, and an example of creating an object of the Resistor class.

How to use different simulators for the same circuit (managing namespaces)?Top, Main, Index

Each supported simulator has its own namespace. For example, ::SpiceGenTcl::Ngspice is used for Ngspice, and ::SpiceGenTcl::Xyce is used for Xyce. Additionally, there is the ::SpiceGenTcl::Common namespace for devices with syntax that is compatible across most simulators.

To use a particular simulator, you can call ::SpiceGenTcl::importNgspice or ::SpiceGenTcl::importXyce to import all command names into the current scope. This approach is convenient because it minimizes code changes. Using full command paths would be more cumbersome. Many elements share the same interface (such as nodes and parameters), so the same code works with different simulators with minimal modifications.

You can also import element commands individually, like this:

namespace import ::SpiceGenTcl::Ngspice::R

This allows you to import the appropriate simulator in conditional statements, depending on a global variable that defines the simulator currently in use.

How to change parameter of existing element?Top, Main, Index

For all elements with parameters you can change parameter value by its name with method ::SpiceGenTcl::Device::setParamValue.

For example here we change the resistance value of basic resistor:

$resistor setParamValue r 100

The name of the parameter can be found in the documentation here. In the parameter table, the option for resistance is labeled -r, so the name used for resistance is 'r'.

Another option is to call the ::SpiceGenTcl::Device::getParams method, which returns a list of all parameters with their values. For example:

# create resistor
set resistor [R new 1 net1 net2 -r 10]
puts [$resistor getParams]

It returns:

r 10

So parameter name is 'r' with value '10'.

Is scaling suffixes allowed?Top, Main, Index

Yes, for numerical values scaling suffixes are allowed, the full list is: f p n u m k meg g t. It must be placed after the numerical value, for example, 10u or 10Meg. Forms 10uV or 1kOhm are not allowed.

How to change node name connected to pin of existing element?Top, Main, Index

For all elements with pins, you can change the connected node's name by using the pin name with the method ::SpiceGenTcl::Device::setPinNodeName.

For example, here we change the node name of the basic resistor's positive pin:

$resistor setPinNodeName np net10

The pin name can be found in the documentation here. In the parameter table, the pins are listed as npNode and nmNode, so the names used for the positive and negative pins are 'np' and 'nm', respectively. This pin_nameNode convention applies to all elements in the package.

Another option is to call the ::SpiceGenTcl::Device::getPins method, which returns a list of all pins with their connected node names. For example:

# create resistor
set resistor [R new 1 net1 net2 -r 10]
puts [$resistor getPins]

It returns:

np net1 nm net2

So pins names are 'np' and 'nm' with connected nets 'net1' and 'net2'.

How to find the list of optional parameters for elements?Top, Main, Index

The list of parameters in the documentation includes descriptions of the mandatory arguments and availible options. But for some elements, especially models, there could be dozens of parameters, and I wanted to avoid cluttering the documentation.

Typically, any optional parameters for elements are also optional in the simulator they relate to, so you can find a list of them in the simulator's manual. The convention for these parameters is -nameOfParam value. For example, for a basic resistor in Ngspice, you can provide values for the temperature coefficients, 'tc1' and 'tc2'. In SpiceGenTcl, these are added during the initialization of the resistor like this:

set resistor [R new 1 net1 net2 -r 10 -tc1 0.1 -tc2 0.4]

Here we provide the mandatory parameters:

As a last resort, you can look directly at the source code in the documentation. Simply open the Show source option, and you'll find an arguments description within the constructor method:

set arguments [argparse -inline {
    -r=
    {-beh -forbid {model} -require {r}}
    {-model= -forbid {beh}}
    {-ac= -forbid {model beh}}
    {-m= -forbid {beh}}
    {-scale= -forbid {beh}}
    {-temp= -forbid {beh dtemp}}
    {-dtemp= -forbid {beh temp}}
    {-tc1= -forbid {model}}
    {-tc2= -forbid {model}}
    {-noisy= -enum {0 1}}
    {-l= -require {model}}
    {-w= -require {model}}
}]

For models the parameters are defined in this list:

set paramsNames [list tc1 tc2 rsh defw narrow short tnom kf af wf lf ef {r res}]

The same applies to all elements (devices and models) in the package.

How to get raw data after simulation?Top, Main, Index

After a successful simulation, an object of the ::SpiceGenTcl::RawFile class is created and attached to the top-level ::SpiceGenTcl::Circuit object. To retrieve the result vectors, simply call the ::SpiceGenTcl::Circuit::getDataDict method on the ::SpiceGenTcl::Circuit object. This method returns the result vectors as a dictionary, with vector names as keys and the vectors themselves as values. You can then access these vectors using the dict get command.

Example:

set data [$circuit getDataDict]
set axisList [dict get $data v(anode)]
set traceList [dict get $data i(va)]  

How to get the names of all vectors in raw file?Top, Main, Index

For this task, you should first retrieve the ::SpiceGenTcl::RawFile object reference from the ::SpiceGenTcl::Circuit object using the configure -Data method. Then, call the ::SpiceGenTcl::RawFile::getVariablesNames method, which returns a list of all variable names.

Example:

set rawFileObj [$circuit configure -Data]
puts [$rawFileObj getVariablesNames]

There are also methods for retrieve all voltages and currents names separated from each other: ::SpiceGenTcl::RawFile::getVoltagesNames and ::SpiceGenTcl::RawFile::getCurrentsNames.

How to get log file after simulation?Top, Main, Index

There is a property method for it in object of ::SpiceGenTcl::Circuit class - configure -Log, it returns string containing log file.

Example:

puts [$circuit configure -Log]