source: trunk/examples/app-fermi/python/fermi.py @ 555

Last change on this file since 555 was 555, checked in by dkearney, 15 years ago

updated examples removing output sections from tool.xml files and making the example code generate the output section using the rappture library put command. this change is made in the example files to help curb people from defining output sections in their tool.xml files. the output sections should really be created inside the program when the output data is ready to be entered.

  • Property svn:keywords set to Date Rev URL
File size: 1.7 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Fermi-Dirac function in Python.
3#
4#  This simple example shows how to use Rappture within a simulator
5#  written in Python.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2005  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# ======================================================================
13import Rappture
14import Rappture.Units
15import sys
16from math import *
17
18# open the XML file containing the run parameters
19driver = Rappture.library(sys.argv[1])
20
21driver.put("tool.repository.application.date", "$Date: 2006-12-09 09:33:35 +0000 (Sat, 09 Dec 2006) $")
22driver.put("tool.repository.application.rev", "$Rev: 555 $")
23driver.put("tool.repository.application.url", "$URL: trunk/examples/app-fermi/python/fermi.py $")
24
25Tstr = driver.get('input.(temperature).current')
26T = Rappture.Units.convert(Tstr, to="K", units="off")
27
28Efstr = driver.get('input.(Ef).current')
29Ef = Rappture.Units.convert(Efstr, to="eV", units="off")
30
31kT = 8.61734e-5 * T
32Emin = Ef - 10*kT
33Emax = Ef + 10*kT
34
35E = Emin
36dE = 0.005*(Emax-Emin)
37
38# Label the output graph with a title, x-axis label,
39# y-axis label, and y-axis units
40driver.put('output.curve(f12).about.label','Fermi-Dirac Factor',append=0)
41driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor',append=0)
42driver.put('output.curve(f12).yaxis.label','Energy',append=0)
43driver.put('output.curve(f12).yaxis.units','eV',append=0)
44
45while E < Emax:
46    f = 1.0/(1.0 + exp((E - Ef)/kT))
47    line = "%g %g\n" % (f, E)
48    driver.put('output.curve(f12).component.xy', line, append=1)
49    E = E + dE
50
51Rappture.result(driver)
52sys.exit()
Note: See TracBrowser for help on using the repository browser.