source: trunk/examples/objects/app-fermi/tcl/fermi4.tcl @ 1620

Last change on this file since 1620 was 1620, checked in by dkearney, 11 years ago

rewriting some language bindings examples to incorporate feedback from meetings

File size: 2.0 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Fermi-Dirac function in Tcl.
3#
4#  This simple example shows how to use Rappture within a simulator
5#  written in Tcl.
6# ======================================================================
7#  AUTHOR:  Derrick Kearney, Purdue University
8#  Copyright (c) 2005-2009  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.
12# ======================================================================
13package require Rappture
14
15# open the XML file containing the run parameters
16set lib [Rappture::Library]
17
18$lib loadFile [lindex $argv 0]
19
20if {[$lib error] != 0} {
21    # cannot open file or out of memory
22    set o [$lib outcome]
23    puts stderr [$o context]
24    puts stderr [$o remark]
25    exit [$lib error]
26}
27
28set T [Rappture::Connect $lib "temperature"]
29set Ef [$lib value "Ef" "units eV"]
30
31if {[$lib error != 0]} {
32    # there were errors while retrieving input data values
33    # dump the tracepack
34    set o [$lib outcome]
35    puts stderr [$o context]
36    puts stderr [$o remark]
37    exit [$lib error]
38}
39
40set nPts 200
41
42set kT [expr {8.61734e-5 * [$T value "K"]}]
43set Emin [expr {$Ef - 10*$kT}]
44set Emax [expr {$Ef + 10*$kT}]
45
46set dE [expr {(1.0/$nPts)*($Emax-$Emin)}]
47
48set E $Emin
49for {set idx 0} {idx < nPts} {incr idx} {
50    set E [expr {$E + $dE}]
51    set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}]
52    lappend fArr $f
53    lappend Err $E
54    set progress [expr {(($E - $Emin)/($Emax - $Emin)*100)}]
55    Rappture::Utils::progress $progress -mesg "Iterating"
56}
57
58# do it the easy way,
59# create a plot to add to the library
60# plot is registered with lib upon object creation
61# p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
62
63set p1 [Rappture::Plot $lib]
64$p1 add $fArr $EArr -name "fdfactor"
65$p1 propstr "label" "Fermi-Dirac Curve"
66$p1 propstr "desc" "Plot of Fermi-Dirac Calculation"
67$p1 propstr "xlabel" "Fermi-Dirac Factor"
68$p1 propstr "ylabel" "Energy"
69$p1 propstr "yunits" "eV"
70
71$lib result
72
73exit 0
Note: See TracBrowser for help on using the repository browser.