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

Last change on this file since 4462 was 4462, checked in by ldelgass, 6 years ago

Remove svn keywords from app-fermi python example. The other lang examples
don't do this and it just creates spurious diffs when merging.

  • Property svn:keywords set to Date Rev URL
File size: 1.6 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
20Tstr = driver.get('input.(temperature).current')
21T = Rappture.Units.convert(Tstr, to="K", units="off")
22
23Efstr = driver.get('input.(Ef).current')
24Ef = Rappture.Units.convert(Efstr, to="eV", units="off")
25
26kT = 8.61734e-5 * T
27Emin = Ef - 10*kT
28Emax = Ef + 10*kT
29
30E = Emin
31dE = 0.005*(Emax-Emin)
32
33# Label the output graph with a title, x-axis label,
34# y-axis label, and y-axis units
35driver.put('output.curve(f12).about.label','Fermi-Dirac Factor',append=0)
36driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor',append=0)
37driver.put('output.curve(f12).yaxis.label','Energy',append=0)
38driver.put('output.curve(f12).yaxis.units','eV',append=0)
39
40while E < Emax:
41    f = 1.0/(1.0 + exp((E - Ef)/kT))
42    line = "%g %g\n" % (f, E)
43    Rappture.Utils.progress(((E-Emin)/(Emax-Emin)*100),"Iterating")
44    driver.put('output.curve(f12).component.xy', line, append=1)
45    E = E + dE
46
47Rappture.result(driver)
48sys.exit()
Note: See TracBrowser for help on using the repository browser.