2010-11-29 22:27:26 +00:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// EXAMPLE: Fermi-Dirac function in C.
|
|
|
|
//
|
|
|
|
// This simple example shows how to use Rappture within a simulator
|
|
|
|
// written in C.
|
|
|
|
// ======================================================================
|
|
|
|
// AUTHOR: Derrick Kearney, Purdue University
|
|
|
|
// Copyright (c) 2004-2008 Purdue Research Foundation
|
|
|
|
//
|
|
|
|
// See the file "license.terms" for information on usage and
|
|
|
|
// redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
// ======================================================================
|
|
|
|
|
2010-12-06 03:06:31 +00:00
|
|
|
#include "rappture.h"
|
2010-11-29 22:27:26 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2010-11-29 22:51:24 +00:00
|
|
|
#ifndef _WIN32
|
2010-11-29 22:27:26 +00:00
|
|
|
#include <unistd.h>
|
2010-11-29 22:51:24 +00:00
|
|
|
#endif
|
2010-11-29 22:27:26 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "boinc_api.h"
|
2010-11-29 22:51:24 +00:00
|
|
|
#include "str_util.h"
|
2010-11-30 05:27:05 +00:00
|
|
|
#include "filesys.h"
|
2010-11-29 22:27:26 +00:00
|
|
|
#include "wrappture.h"
|
|
|
|
|
|
|
|
int main(int argc, char * argv[]) {
|
2010-12-06 03:10:01 +00:00
|
|
|
char buf[256];
|
2010-11-29 22:27:26 +00:00
|
|
|
|
|
|
|
RpLibrary* lib = NULL;
|
|
|
|
|
|
|
|
const char* data = NULL;
|
|
|
|
|
|
|
|
double T = 0.0;
|
|
|
|
double Ef = 0.0;
|
|
|
|
double E = 0.0;
|
|
|
|
double dE = 0.0;
|
|
|
|
double kT = 0.0;
|
|
|
|
double Emin = 0.0;
|
|
|
|
double Emax = 0.0;
|
|
|
|
double f = 0.0;
|
|
|
|
|
|
|
|
int err = 0;
|
|
|
|
|
2010-12-06 03:10:01 +00:00
|
|
|
boinc_resolve_filename("driver.xml", buf, sizeof(buf));
|
|
|
|
lib = rpLibrary(buf);
|
2010-11-29 22:27:26 +00:00
|
|
|
|
|
|
|
if (lib == NULL) {
|
|
|
|
// cannot open file or out of memory
|
|
|
|
printf("FAILED creating Rappture Library\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rpGetString(lib,"input.number(temperature).current",&data);
|
|
|
|
T = rpConvertDbl(data, "K", &err);
|
|
|
|
if (err) {
|
|
|
|
printf ("Error while retrieving input.number(temperature).current\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rpGetString(lib,"input.number(Ef).current",&data);
|
|
|
|
Ef = rpConvertDbl(data, "eV", &err);
|
|
|
|
if (err) {
|
|
|
|
printf ("Error while retrieving input.number(Ef).current\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
kT = 8.61734e-5 * T;
|
|
|
|
Emin = Ef - 10*kT;
|
|
|
|
Emax = Ef + 10*kT;
|
|
|
|
|
|
|
|
E = Emin;
|
|
|
|
dE = 0.005*(Emax-Emin);
|
|
|
|
|
|
|
|
rpPutString ( lib,
|
|
|
|
"output.curve(f12).about.label",
|
|
|
|
"Fermi-Dirac Factor",
|
|
|
|
RPLIB_OVERWRITE );
|
|
|
|
rpPutString ( lib,
|
|
|
|
"output.curve(f12).xaxis.label",
|
|
|
|
"Fermi-Dirac Factor",
|
|
|
|
RPLIB_OVERWRITE );
|
|
|
|
rpPutString ( lib,
|
|
|
|
"output.curve(f12).yaxis.label",
|
|
|
|
"Energy",
|
|
|
|
RPLIB_OVERWRITE );
|
|
|
|
rpPutString ( lib,
|
|
|
|
"output.curve(f12).yaxis.units",
|
|
|
|
"eV",
|
|
|
|
RPLIB_OVERWRITE );
|
|
|
|
|
2010-11-30 05:27:05 +00:00
|
|
|
// Run core simulator
|
|
|
|
sprintf(buf, "%g %g", T, Ef);
|
|
|
|
int retval = boinc_run_rappture_app("fermi", buf);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "boinc_run_rappture_app(): %d\n", retval);
|
2010-11-29 22:27:26 +00:00
|
|
|
boinc_finish(EXIT_CHILD_FAILED);
|
|
|
|
}
|
2010-11-30 05:27:05 +00:00
|
|
|
|
|
|
|
// Read resulting output file
|
|
|
|
FILE* file;
|
|
|
|
if (!(file = boinc_fopen("fermi_out.dat", "r"))) {
|
|
|
|
fprintf(stderr, "Unable to open data file\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), file)) {
|
|
|
|
rpPutString(lib, "output.curve(f12).component.xy", buf, RPLIB_APPEND);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
// Finish
|
|
|
|
rpResult(lib);
|
|
|
|
boinc_finish(0);
|
2010-11-29 22:27:26 +00:00
|
|
|
}
|
2010-11-29 22:51:24 +00:00
|
|
|
|
2010-11-30 05:27:05 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
|
|
|
|
LPSTR command_line;
|
|
|
|
char* argv[100];
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
command_line = GetCommandLine();
|
|
|
|
argc = parse_command_line(command_line, argv);
|
|
|
|
return main(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|