I keep track of the models used by all devices in an instance of Elements.

Because Ngspice is based on a program about four decades old, there is one huge stupidness this has to deal with: Model names are always global.

Class Variable suffixes A dict of uniquifying integer suffixes of model names, keyed by prefix.
Instance Variable devices A dict of reference designators of the first device to use each model, keyed by model name.
Instance Variable modelNames A set of model names that have been defined with a .MODEL statement.
Method __init__ Undocumented
Class Method autoName Returns a name starting with prefix that is unique across all instances of me.
Method modelName Returns a unique model name, based on how many models have been defined in my models set via calls to modelDefined.
Method modelDefined Returns True if the named model has already been defined, which happens when Elements.fixDeferredAVs calls Elements.processArgs.
Method addDevForModel Registers a device with refDes as using the named model. The first device registered for a given model name will be the one used to alterparams of that model.
Method setForModel Sets up the supplied AV object av to represent a parameter of a model with the reference designator model.
suffixes =
A dict of uniquifying integer suffixes of model names, keyed by prefix.
devices =
A dict of reference designators of the first device to use each model, keyed by model name.
modelNames =
A set of model names that have been defined with a .MODEL statement.
def __init__(self):
Undocumented
@classmethod
def autoName(cls, prefix):

Returns a name starting with prefix that is unique across all instances of me.

If the prefix is a Wrapper instance, its name is used as the prefix.

def modelName(self, prefix='psm'):

Returns a unique model name, based on how many models have been defined in my models set via calls to modelDefined.

If you supply a prefix, the model name will begin with that, or with its name if it's a Wrapper. Otherwise, the prefix will be "psm".

def modelDefined(self, model):

Returns True if the named model has already been defined, which happens when Elements.fixDeferredAVs calls Elements.processArgs.

def addDevForModel(self, model, refDes):

Registers a device with refDes as using the named model. The first device registered for a given model name will be the one used to alterparams of that model.

Repeated calls with the same model name are only for keeping track of which kind of model a device uses, for NodeTracker.

Raises an exception if model hasn't been defined yet.

def setForModel(self, av, model):

Sets up the supplied AV object av to represent a parameter of a model with the reference designator model.

For example, the following lines define a MOSFET whose model has an alterable parameter KP, with a value between 10^-10 and 10^-3:

   mosfet = f.MODEL(
       'mosfet', 'nmos', level=1, KP=f.av('kp', -10, -3, 'log'))
   f.M(nc, 130, na, na, mosfet)

The first call to f gets a unique name for the model and creates a placeholder list for the first device that will use the model. The second call to f creates a reference designator for the MOSFET and, since there is no entry for the value of the mosfet variable in my devices dict yet, sets it as the first device defined for that model.

Note that the MODEL call has to come first so you get a unique model name. Unfortunately, Ngspice treats all model names as global, even if defined inside a subcircuit!

You must do the .MODEL call before any calls for device using that model. Only the first device call will affect me.

API Documentation for pingspice, generated by pydoctor at 2021-09-18 08:41:11.