source: trunk/examples/objects/app-fermi/tcl/ex3/fermi.tcl @ 1655

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

examples of using a view in tcl and c, update tcl and c view apis

File size: 3.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# initialize the global interface
16Rappture::Interface $argv fermi_io
17
18# check the global interface for errors
19if {[Rappture::Interface::error] != 0} {
20    # there were errors while setting up the inteface
21    # dump the traceback
22    set o [Rappture::Interface::outcome]
23    puts stderr [$o context]
24    puts stderr [$o remark]
25    exit [Rappture::Interface::error]
26}
27
28# connect variables to the interface
29# look in the global interface for an object named
30# "temperature, convert its value to Kelvin, and
31# store the value into the address of T.
32# look in the global interface for an object named
33# "Ef", convert its value to electron Volts and store
34# the value into the address of Ef
35# look in the global interface for an object named
36# factorsTable and set the variable result to
37# point to it.
38set T [Rappture::Interface::connect "temperature" -hints {"units=K"}]
39set Ef [Rappture::Interface::connect "Ef" -hints {"units=eV"}]
40set result [Rappture::Interface::connect "factorsTable"]
41
42if {[Rappture::Interface::error] != 0]} {
43    # there were errors while retrieving input data values
44    # dump the tracepack
45    set o [Rappture::Interface::outcome]
46    puts stderr [$o context]
47    puts stderr [$o remark]
48    exit [Rappture::Interface::error]
49}
50
51# do science calculations
52set nPts 200
53
54set kT [expr {8.61734e-5 * $T}]
55set Emin [expr {$Ef - 10*$kT}]
56set Emax [expr {$Ef + 10*$kT}]
57
58set dE [expr {(1.0/$nPts)*($Emax-$Emin)}]
59
60set E $Emin
61for {set idx 0} {idx < nPts} {incr idx} {
62    set E [expr {$E + $dE}]
63    set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}]
64    lappend fArr $f
65    lappend fArr2 [expr {$f*2}]
66    lappend EArr $E
67    lappend EArr2 [expr {$E*2}]
68    set progress [expr {(($E - $Emin)/($Emax - $Emin)*100)}]
69    Rappture::Utils::progress $progress -mesg "Iterating"
70}
71
72# store results in the results table
73# add data to the table pointed to by the variable result.
74# put the fArr data in the column named "Fermi-Dirac Factor"
75# put the EArr data in the column named "Energy"
76#
77# Rappture::Table Commands:
78# the store command overwrites data that already exists in
79# the column with the new array of data.
80# the append command will append the new array of data onto
81# any previously existing array of data.
82
83$result store "Fermi-Dirac Factor" $fArr
84$result store "Fermi-Dirac Factor * 2" $fArr2
85$result store "Energy" $EArr
86$result store "Energy * 2" $EArr2
87
88Rappture::Interface::close
89
90exit 0
Note: See TracBrowser for help on using the repository browser.