[66] | 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 |
---|
[115] | 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. |
---|
[66] | 12 | # ====================================================================== |
---|
| 13 | import Rappture |
---|
| 14 | import sys |
---|
| 15 | from math import * |
---|
| 16 | |
---|
| 17 | # open the XML file containing the run parameters |
---|
| 18 | driver = Rappture.library(sys.argv[1]) |
---|
| 19 | |
---|
[667] | 20 | driver.put("tool.version.application.date", "$Date: 2007-04-13 03:56:02 +0000 (Fri, 13 Apr 2007) $") |
---|
| 21 | driver.put("tool.version.application.rev", "$LastChangedRev$") |
---|
| 22 | driver.put("tool.version.application.url", "$URL: trunk/examples/app-fermi/python/fermi.py $") |
---|
[540] | 23 | |
---|
[66] | 24 | Tstr = driver.get('input.(temperature).current') |
---|
[71] | 25 | T = Rappture.Units.convert(Tstr, to="K", units="off") |
---|
[66] | 26 | |
---|
| 27 | Efstr = driver.get('input.(Ef).current') |
---|
[71] | 28 | Ef = Rappture.Units.convert(Efstr, to="eV", units="off") |
---|
[66] | 29 | |
---|
| 30 | kT = 8.61734e-5 * T |
---|
| 31 | Emin = Ef - 10*kT |
---|
| 32 | Emax = Ef + 10*kT |
---|
| 33 | |
---|
| 34 | E = Emin |
---|
| 35 | dE = 0.005*(Emax-Emin) |
---|
[555] | 36 | |
---|
| 37 | # Label the output graph with a title, x-axis label, |
---|
| 38 | # y-axis label, and y-axis units |
---|
| 39 | driver.put('output.curve(f12).about.label','Fermi-Dirac Factor',append=0) |
---|
| 40 | driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor',append=0) |
---|
| 41 | driver.put('output.curve(f12).yaxis.label','Energy',append=0) |
---|
| 42 | driver.put('output.curve(f12).yaxis.units','eV',append=0) |
---|
| 43 | |
---|
[66] | 44 | while E < Emax: |
---|
| 45 | f = 1.0/(1.0 + exp((E - Ef)/kT)) |
---|
| 46 | line = "%g %g\n" % (f, E) |
---|
[665] | 47 | Rappture.Utils.progress(((E-Emin)/(Emax-Emin)*100),"Iterating") |
---|
[66] | 48 | driver.put('output.curve(f12).component.xy', line, append=1) |
---|
| 49 | E = E + dE |
---|
| 50 | |
---|
| 51 | Rappture.result(driver) |
---|
[73] | 52 | sys.exit() |
---|