Resistor example 1D - DC solve explanation

From Flooxs
Revision as of 19:17, 4 November 2010 by Nrowsey (talk | contribs)
Jump to navigation Jump to search

This page explains the following code snipped from the 1D Resistor example:

DC solve / plot I-V as output

set Win [CreateGraphWindow]
set bias 0.0
for {set bias 0.0} {$bias < 1.01} {set bias [expr $bias+0.1]} {
	contact name=VSS supply = $bias
	device
	set cur [expr abs([contact name=VSS sol=Elec flux] - [contact name=VSS sol=Hole flux])]
	AddtoLine $Win I $bias $cur
}

tcl channels

This line is rather complicated in floods:

set Win [CreateGraphWindow]

The command "CreateGraphWindow" opens a new window for plotting (it'll be a blank set of axes until you write to it). The [] brackets around the [CreateGraphWindow] command mean, "execute this command now." The CreateGraphWindow command actually returns a channel number that you don't see and stores it in the tcl variable "Win". This is so that, in the future, when you want to send data to your plot, you can send it through the channel named "Win".

"Ramping," or consecutive DC solves

Please note from this line:

set bias 0.0

that "bias" is a tcl variable, and not some complex thing that floods already knows about. The "for" loop you see above is how you write a for loop in tcl. The [] brackets mean "evaluate this now and put the result here," and the "$" means "access this string and put what's stored in it here," just like in the rest of our tcl code.

contact name=VSS supply = $bias

is an alagator command, and is being used the same way the it was used in the initial guess section. This line:

set cur [expr abs([contact name=VSS sol=Elec flux] - [contact name=VSS sol=Hole flux])]

retrieves flux of Elec or Hole through the VSS contact from the parameter database,

contact name=VSS sol=Elec flux
contact name=VSS sol=Hole flux

subtracts and takes the absolute value using expr, then stores that number in the tcl variable "cur". "AddtoLine" is a specific command for the "CreateGraphWindow" graphing method:

AddtoLine $Win I $bias $cur

It sends a point through channel $Win with x and y values $bias and $cur, to the line named "I". See the plotting explanation section for more information on plotting.