source: trunk/examples/app-fermi/cee/fermi.c @ 665

Last change on this file since 665 was 665, checked in by dkearney, 18 years ago

Updates to Rappture::Utils::progress for all languages
removed the dependancy on Rappture.Units from within number.py, it should only depend on Rappture which will include Rappture.Units
added Rappture.Units as a module to load when people import Rappture in python.
added -V pbs variable to queue.py to include qsub environment variables in the submitted job.
updated setup.py.in to install Rappture.Utils
added progress bar to all app-fermi examples showing how to use the Rappture::Utils::progress function in all languages.
added destructor definitions to Node classes in src2/core

File size: 2.7 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 C.
6// ======================================================================
7//  AUTHOR:  Derrick Kearney, Purdue University
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.
12// ======================================================================
13
14#include "rappture.h"
15
16#include <stdlib.h>
17#include <stdio.h>
18#include <math.h>
19#include <unistd.h>
20
21int main(int argc, char * argv[]) {
22
23    RpLibrary* lib    = NULL;
24
25    const char* data  = NULL;
26    char line[100];
27
28    double T          = 0.0;
29    double Ef         = 0.0;
30    double E          = 0.0;
31    double dE         = 0.0;
32    double kT         = 0.0;
33    double Emin       = 0.0;
34    double Emax       = 0.0;
35    double f          = 0.0;
36
37    int err           = 0;
38
39    // create a rappture library from the file filePath
40    lib = rpLibrary(argv[1]);
41
42    if (lib == NULL) {
43        // cannot open file or out of memory
44        printf("FAILED creating Rappture Library\n");
45        return(1);
46    }
47
48
49    rpGetString(lib,"input.(temperature).current",&data);
50    T = rpConvertDbl(data, "K", &err);
51    if (err) {
52        printf ("Error while retrieving input.(temperature).current\n");
53        return(1);
54    }
55
56
57    rpGetString(lib,"input.(Ef).current",&data);
58    Ef = rpConvertDbl(data, "eV", &err);
59    if (err) {
60        printf ("Error while retrieving input.(Ef).current\n");
61        return(1);
62    }
63
64    kT = 8.61734e-5 * T;
65    Emin = Ef - 10*kT;
66    Emax = Ef + 10*kT;
67
68    E = Emin;
69    dE = 0.005*(Emax-Emin);
70
71    rpPutString (   lib,
72                    "output.curve(f12).about.label",
73                    "Fermi-Dirac Factor",
74                    RPLIB_OVERWRITE );
75    rpPutString (   lib,
76                    "output.curve(f12).xaxis.label",
77                    "Fermi-Dirac Factor",
78                    RPLIB_OVERWRITE );
79    rpPutString (   lib,
80                    "output.curve(f12).yaxis.label",
81                    "Energy",
82                    RPLIB_OVERWRITE );
83    rpPutString (   lib,
84                    "output.curve(f12).yaxis.units",
85                    "eV",
86                    RPLIB_OVERWRITE );
87
88    while (E < Emax) {
89        f = 1.0/(1.0 + exp((E - Ef)/kT));
90        sprintf(line,"%f %f\n",f, E);
91        rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
92        rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND);
93        E = E + dE;
94    }
95
96    rpResult(lib);
97    return 0;
98}
Note: See TracBrowser for help on using the repository browser.