[10] | 1 | # ---------------------------------------------------------------------- |
---|
[66] | 2 | # EXAMPLE: Fermi-Dirac function in Tcl. |
---|
[10] | 3 | # |
---|
[66] | 4 | # This simple example shows how to use Rappture within a simulator |
---|
| 5 | # written in Tcl. |
---|
[10] | 6 | # ====================================================================== |
---|
| 7 | # AUTHOR: Michael McLennan, Purdue University |
---|
[115] | 8 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
| 9 | # |
---|
| 10 | # See the file "license.terms" for information on usage and |
---|
| 11 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
[10] | 12 | # ====================================================================== |
---|
| 13 | package require Rappture |
---|
| 14 | |
---|
| 15 | # open the XML file containing the run parameters |
---|
[30] | 16 | set driver [Rappture::library [lindex $argv 0]] |
---|
[10] | 17 | |
---|
[30] | 18 | set T [$driver get input.(temperature).current] |
---|
| 19 | set T [Rappture::Units::convert $T -to K -units off] |
---|
| 20 | set Ef [$driver get input.(Ef).current] |
---|
| 21 | set Ef [Rappture::Units::convert $Ef -to eV -units off] |
---|
[10] | 22 | |
---|
| 23 | set kT [expr {8.61734e-5 * $T}] |
---|
| 24 | set Emin [expr {$Ef - 10*$kT}] |
---|
| 25 | set Emax [expr {$Ef + 10*$kT}] |
---|
| 26 | |
---|
| 27 | set E $Emin |
---|
| 28 | set dE [expr {0.005*($Emax-$Emin)}] |
---|
[555] | 29 | |
---|
| 30 | # Label output graph with title, x-axis label, |
---|
| 31 | # y-axis lable, and y-axis units |
---|
| 32 | $driver put -append no output.curve(f12).about.label "Fermi-Dirac Factor" |
---|
| 33 | $driver put -append no output.curve(f12).xaxis.label "Fermi-Dirac Factor" |
---|
| 34 | $driver put -append no output.curve(f12).yaxis.label "Energy" |
---|
| 35 | $driver put -append no output.curve(f12).yaxis.units "eV" |
---|
| 36 | |
---|
[10] | 37 | while {$E < $Emax} { |
---|
| 38 | set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}] |
---|
[66] | 39 | $driver put -append yes output.curve(f12).component.xy "$f $E\n" |
---|
[10] | 40 | set E [expr {$E + $dE}] |
---|
| 41 | } |
---|
| 42 | |
---|
[66] | 43 | # save the updated XML describing the run... |
---|
[57] | 44 | Rappture::result $driver |
---|
| 45 | exit 0 |
---|