1 | /* |
---|
2 | * EXAMPLE: Fermi-Dirac function in Java. |
---|
3 | * |
---|
4 | * This simple example shows how to use Rappture within a simulator |
---|
5 | * written in Java. |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Ben Rafferty, 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 | |
---|
15 | class Fermi{ |
---|
16 | |
---|
17 | public static void main(String args[]){ |
---|
18 | |
---|
19 | // create a rappture library from the file path |
---|
20 | rappture.Library driver = new rappture.Library(args[0]); |
---|
21 | |
---|
22 | // read the input values and convert to correct units |
---|
23 | String Tstr = driver.get("input.number(temperature).current"); |
---|
24 | double T = Double.valueOf(rappture.Units.convertString(Tstr, "K", false)); |
---|
25 | String Efstr = driver.get("input.number(Ef).current"); |
---|
26 | double Ef = Double.valueOf(rappture.Units.convertString(Efstr, "eV", false)); |
---|
27 | |
---|
28 | // Set the energy range and step size |
---|
29 | double kT = 8.61734E-5 * T; |
---|
30 | double Emin = Ef - 10*kT; |
---|
31 | double Emax = Ef + 10*kT; |
---|
32 | double E = Emin; |
---|
33 | double dE = 0.005*(Emax-Emin); |
---|
34 | |
---|
35 | // Add relevant information to the output curve |
---|
36 | driver.put("output.curve(f12).about.label", "Fermi-Dirac Factor"); |
---|
37 | driver.put("output.curve(f12).xaxis.label", "Fermi-Dirac Factor"); |
---|
38 | driver.put("output.curve(f12).yaxis.label", "Energy"); |
---|
39 | driver.put("output.curve(f12).yaxis.units", "eV"); |
---|
40 | |
---|
41 | // Calculate the Fermi-Dirac function over the energy range |
---|
42 | // Add the results to the output curve |
---|
43 | double f; |
---|
44 | String line; |
---|
45 | while (E < Emax){ |
---|
46 | f = 1.0/(1.0 + Math.exp((E - Ef)/kT)); |
---|
47 | line = String.format("%f %f\n", f, E); |
---|
48 | rappture.Utils.progress((int)((E-Emin)/(Emax-Emin)*100), "Iterating"); |
---|
49 | driver.put("output.curve(f12).component.xy", line, true); |
---|
50 | E = E + dE; |
---|
51 | } |
---|
52 | |
---|
53 | // Finalize the results and inform rappture that the simulation has ended |
---|
54 | driver.result(); |
---|
55 | } |
---|
56 | |
---|
57 | } |
---|
58 | |
---|