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

Last change on this file since 1656 was 1656, checked in by dkearney, 14 years ago

removing references to rappture tables, rappture will automagically decide
where to place new table columns, its one less thing for the user to fuss with.
users will reference the connect a TableColumn? variable with the correct name
and populate the TableColumn? in their science code. adding examples for matlab, octave, fixes for other languages.

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"}]
40
41set x1 [Rappture::Interface::connect "Fermi-Dirac Factor"]
42set y1 [Rappture::Interface::connect "Energy"]
43set x2 [Rappture::Interface::connect "Fermi-Dirac Factor * 2"]
44set y2 [Rappture::Interface::connect "Energy * 2"]
45
46if {[Rappture::Interface::error] != 0]} {
47    # there were errors while retrieving input data values
48    # dump the tracepack
49    set o [Rappture::Interface::outcome]
50    puts stderr [$o context]
51    puts stderr [$o remark]
52    exit [Rappture::Interface::error]
53}
54
55# do science calculations
56set nPts 200
57
58set kT [expr {8.61734e-5 * $T}]
59set Emin [expr {$Ef - 10*$kT}]
60set Emax [expr {$Ef + 10*$kT}]
61
62set dE [expr {(1.0/$nPts)*($Emax-$Emin)}]
63
64set E $Emin
65for {set idx 0} {idx < nPts} {incr idx} {
66    set E [expr {$E + $dE}]
67    set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}]
68    lappend fArr $f
69    lappend fArr2 [expr {$f*2}]
70    lappend EArr $E
71    lappend EArr2 [expr {$E*2}]
72    set progress [expr {(($E - $Emin)/($Emax - $Emin)*100)}]
73    Rappture::Utils::progress $progress -mesg "Iterating"
74}
75
76# store results in the results table
77# add data to the table pointed to by the variable result.
78# put the fArr data in the column named "Fermi-Dirac Factor"
79# put the EArr data in the column named "Energy"
80#
81# Rappture::Table Commands:
82# the store command overwrites data that already exists in
83# the column with the new array of data.
84# the append command will append the new array of data onto
85# any previously existing array of data.
86
87$x1 store $fArr
88$y1 store $fArr2
89$x2 store $EArr
90$y2 store $EArr2
91
92Rappture::Interface::close
93
94exit 0
Note: See TracBrowser for help on using the repository browser.