Changeset 5411
- Timestamp:
- May 4, 2015, 5:13:22 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/examples/app-fermi/python/fermi.py
r4463 r5411 6 6 # ====================================================================== 7 7 # AUTHOR: Michael McLennan, Purdue University 8 # Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 # Martin Hunt, Purdue University 9 # Copyright (c) 2004-2015 HUBzero Foundation, LLC 9 10 # 10 11 # See the file "license.terms" for information on usage and … … 13 14 import Rappture 14 15 import sys 15 from math import * 16 import numpy as np 17 18 # Uncomment these lines to redirect 19 # python output and errors to files 20 # for easier debugging. 21 # sys.stderr = open('fermi.err', 'w') 22 # sys.stdout = open('fermi.out', 'w') 16 23 17 24 # open the XML file containing the run parameters 18 driver = Rappture.library(sys.argv[1])25 rx = Rappture.PyXml(sys.argv[1]) 19 26 20 Tstr = driver.get('input.(temperature).current') 21 T = Rappture.Units.convert(Tstr, to="K", units="off")27 temp_str = rx['input.(temperature).current'].value 28 temp = Rappture.Units.convert(temp_str, to='K', units='off') 22 29 23 Efstr = driver.get('input.(Ef).current') 24 Ef = Rappture.Units.convert(Efstr, to="eV", units="off")30 ef_str = rx['input.(Ef).current'].value 31 ef = Rappture.Units.convert(ef_str, to='eV', units='off') 25 32 26 kT = 8.61734e-5 * T 27 Emin = Ef - 10*kT 28 Emax = Ef + 10*kT 29 30 E = Emin 31 dE = 0.005*(Emax-Emin) 33 kt = 8.61734e-5 * temp 34 emin = ef - 10*kt 35 emax = ef + 10*kt 32 36 33 37 # Label the output graph with a title, x-axis label, 34 38 # y-axis label, and y-axis units 35 driver.put('output.curve(f12).about.label','Fermi-Dirac Factor',append=0) 36 driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor',append=0) 37 driver.put('output.curve(f12).yaxis.label','Energy',append=0) 38 driver.put('output.curve(f12).yaxis.units','eV',append=0) 39 f12 = rx['output.curve(f12)'] # a shortcut to save typing 40 f12['label'] = 'Fermi-Dirac Factor' 41 f12['xaxis.label'] = 'Fermi-Dirac Factor' 42 f12['yaxis.label'] = 'Energy' 43 f12['yaxis.units'] = 'eV' 39 44 40 while 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 45 # How many points to use to define our curve 46 numpts = 200 46 47 47 Rappture.result(driver) 48 sys.exit() 48 # The normal python approach would be to simply do this: 49 # energy = np.linspace(emin, emax, numpts) 50 # f = 1.0/(1.0 + np.exp((energy - ef)/kt)) 51 # f12['component.xy'] = np.column_stack((f, energy)) 52 # rx.close() 53 54 # But we want to show how to use the progress bar, 55 # so lets do things slowly and iteratively... 56 57 import time 58 energy = [] 59 fermi = [] 60 for i, e in enumerate(np.linspace(emin, emax, numpts)): 61 f = 1.0/(1.0 + np.exp((e - ef)/kt)) 62 energy.append(e) 63 fermi.append(f) 64 Rappture.Utils.progress(i*100.0/numpts, "Iterating") 65 time.sleep(0.01) 66 f12['component.xy'] = (fermi, energy) 67 rx.close()
Note: See TracChangeset
for help on using the changeset viewer.