source: branches/blt4/examples/app-fermi/python/fermi.py @ 3957

Last change on this file since 3957 was 3957, checked in by gah, 11 years ago

sync with trunk

  • Property svn:keywords set to Date Rev URL
File size: 1.8 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-2012  HUBzero Foundation, LLC
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 sys
15from math import *
16
17# open the XML file containing the run parameters
18driver = Rappture.library(sys.argv[1])
19
20driver.put("tool.version.application.date", "$Date: 2013-09-24 23:40:58 +0000 (Tue, 24 Sep 2013) $")
21driver.put("tool.version.application.rev", "$LastChangedRevision: 3957 $")
22driver.put("tool.version.application.url", "$URL: branches/blt4/examples/app-fermi/python/fermi.py $")
23
24Tstr = driver.get('input.(temperature).current')
25T = Rappture.Units.convert(Tstr, to="K", units="off")
26
27Efstr = driver.get('input.(Ef).current')
28Ef = Rappture.Units.convert(Efstr, to="eV", units="off")
29
30kT = 8.61734e-5 * T
31Emin = Ef - 10*kT
32Emax = Ef + 10*kT
33
34E = Emin
35dE = 0.005*(Emax-Emin)
36
37# Label the output graph with a title, x-axis label,
38# y-axis label, and y-axis units
39driver.put('output.curve(f12).about.label','Fermi-Dirac Factor',append=0)
40driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor',append=0)
41driver.put('output.curve(f12).yaxis.label','Energy',append=0)
42driver.put('output.curve(f12).yaxis.units','eV',append=0)
43
44while E < Emax:
45    f = 1.0/(1.0 + exp((E - Ef)/kT))
46    line = "%g %g\n" % (f, E)
47    Rappture.Utils.progress(((E-Emin)/(Emax-Emin)*100),"Iterating")
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.