source: trunk/examples/objects/app-fermi/tcl/ex2/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 fdfPlot [Rappture::Interface::connect "fdfPlot"]
41set fdfPlot2 [Rappture::Interface::connect "fdfPlot2"]
42
43if {[Rappture::Interface::error] != 0]} {
44    # there were errors while retrieving input data values
45    # dump the tracepack
46    set o [Rappture::Interface::outcome]
47    puts stderr [$o context]
48    puts stderr [$o remark]
49    exit [Rappture::Interface::error]
50}
51
52# do science calculations
53set nPts 200
54
55set kT [expr {8.61734e-5 * $T}]
56set Emin [expr {$Ef - 10*$kT}]
57set Emax [expr {$Ef + 10*$kT}]
58
59set dE [expr {(1.0/$nPts)*($Emax-$Emin)}]
60
61set E $Emin
62for {set idx 0} {idx < nPts} {incr idx} {
63    set E [expr {$E + $dE}]
64    set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}]
65    lappend fArr $f
66    lappend Err $E
67    set progress [expr {(($E - $Emin)/($Emax - $Emin)*100)}]
68    Rappture::Utils::progress $progress -mesg "Iterating"
69}
70
71# set up the curves for the plot by using the add command
72# add <name> <xdata> <ydata> -format <fmt>
73#
74# to group curves on the same plot, just keep adding curves
75# to save space, X array values are compared between curves.
76# the the X arrays contain the same values, we only store
77# one version in the internal data table, otherwise a new
78# column is created for the array. for big arrays this may take
79# some time, we should benchmark to see if this can be done
80# efficiently.
81
82$fdfPlot add "fdfCurve1" $fArr $EArr -format "g:o"
83
84$fdfPlot2 add "fdfCurve2" $fArr $EArr -format "b-o"
85$fdfPlot2 add "fdfCurve3" $fArr $EArr -format "p--"
86
87Rappture::Interface::close
88
89exit 0
Note: See TracBrowser for help on using the repository browser.