1 | # ----------------------------------------------------------------------
|
---|
2 | # EXAMPLE: Fermi-Dirac function in Perl.
|
---|
3 | #
|
---|
4 | # This simple example shows how to use Rappture within a simulator
|
---|
5 | # written in Perl.
|
---|
6 | # ======================================================================
|
---|
7 | # AUTHOR: Nicholas J. Kisseberth, 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 | # ======================================================================
|
---|
13 |
|
---|
14 | use Rappture;
|
---|
15 |
|
---|
16 | # open the XML file containing the run parameters
|
---|
17 |
|
---|
18 | $driver = Rappture::RpLibrary->new($ARGV[0]);
|
---|
19 |
|
---|
20 | $Tstr = $driver->get("input.(temperature).current");
|
---|
21 | $T = Rappture::RpUnits::convert($Tstr, "K", "off");
|
---|
22 |
|
---|
23 | $Efstr = $driver->get("input.(Ef).current");
|
---|
24 | $Ef = Rappture::RpUnits::convert($Efstr, "eV", "off");
|
---|
25 |
|
---|
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);
|
---|
32 |
|
---|
33 | # Label the output graph with a title, x-axis label,
|
---|
34 | # y-axis label, y-axis units.
|
---|
35 |
|
---|
36 | $driver->put("output.curve(f12).about.label","Fermi-Dirac Factor",0);
|
---|
37 | $driver->put("output.curve(f12).xaxis.label","Fermi-Dirac Factor",0);
|
---|
38 | $driver->put("output.curve(f12).yaxis.label","Energy",0);
|
---|
39 | $driver->put("output.curve(f12).yaxis.units","eV",0);
|
---|
40 |
|
---|
41 | while( $E < $Emax ) {
|
---|
42 | $f = 1.0 / ( 1.0 + exp(($E - $Ef) / $kT));
|
---|
43 | Rappture::Utils::progress((($E-$Emin)/($Emax-$Emin)*100),"Iterating");
|
---|
44 | $driver->put("output.curve(f12).component.xy", "$f $E\n", 1);
|
---|
45 | $E = $E + $dE;
|
---|
46 | }
|
---|
47 |
|
---|
48 | $driver->result();
|
---|