source: trunk/tester/example/fermi_broken.tcl @ 2087

Last change on this file since 2087 was 2087, checked in by braffert, 13 years ago

tester: added progress bar when running test

File size: 2.4 KB
Line 
1# ----------------------------------------------------------------------
2#  This is a modifed version of the Tcl app-fermi example which has been
3#  purposely broken for testing the Rappture regression testing tool.
4#  Incorrect results are given whenever temperature is set to 300K (room
5#  temperature), and an error is thrown when the temperature is 4.2K
6#  AND the energy level is 1eV.
7# ======================================================================
8#  AUTHOR:  Ben Rafferty, Purdue University
9#  Copyright (c) 2004-2007  Purdue Research Foundation
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14package require Rappture
15
16# open the XML file containing the run parameters
17set driver [Rappture::library [lindex $argv 0]]
18
19set T [$driver get input.(temperature).current]
20set T [Rappture::Units::convert $T -to K -units off]
21set Ef [$driver get input.(Ef).current]
22set Ef [Rappture::Units::convert $Ef -to eV -units off]
23
24set kT [expr {8.61734e-5 * $T}]
25set Emin [expr {$Ef - 10*$kT}]
26set Emax [expr {$Ef + 10*$kT}]
27
28set E $Emin
29set dE [expr {0.005*($Emax-$Emin)}]
30
31# take a while and give some output along the way
32Rappture::Utils::progress 0 -mesg "Starting..."
33puts "Taking a while to run..."
34after 1000
35puts "making some progress"
36after 1000
37puts "done"
38Rappture::Utils::progress 10 -mesg "Starting, for real now."
39after 1000
40
41# Label output graph with title, x-axis label,
42# y-axis lable, and y-axis units
43$driver put -append no output.curve(f12).about.label "Fermi-Dirac Factor"
44$driver put -append no output.curve(f12).xaxis.label "Fermi-Dirac Factor"
45$driver put -append no output.curve(f12).yaxis.label "Energy"
46$driver put -append no output.curve(f12).yaxis.units "eV"
47
48# Error if T = 4.2 and Ef = 1eV
49if {$T == 4.2 && $Ef == 1} {
50    error "Purposely throwing an error for this input combination."
51}
52
53# Produce bad results whenever T = 300K
54if {$T == 300} {
55    set kT [expr $kT * 2]
56}
57
58while {$E < $Emax} {
59    set f [expr {1.0/(1.0 + exp(($E - $Ef)/$kT))}]
60    set progress [expr {(($E - $Emin)/($Emax - $Emin)*100)}]
61    Rappture::Utils::progress $progress -mesg "Iterating"
62    $driver put -append yes output.curve(f12).component.xy "$f $E\n"
63    set E [expr {$E + $dE}]
64}
65
66# save the updated XML describing the run...
67Rappture::result $driver
68exit 0
Note: See TracBrowser for help on using the repository browser.