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

Last change on this file was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

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