Пример #1
0
/* =============================================================================
 * ud_input_set_file() - Set buffer as input.
 * =============================================================================
 */
extern void 
ud_set_input_file(register struct ud* u, FILE* f)
{
  u->inp_hook = inp_file_hook;
  u->inp_file = f;
  inp_init(u);
}
Пример #2
0
/* =============================================================================
 * ud_inp_set_buffer() - Set buffer as input.
 * =============================================================================
 */
extern void 
ud_set_input_buffer(register struct ud* u, uint8_t* buf, size_t len)
{
  u->inp_hook = inp_buff_hook;
  u->inp_buff = buf;
  u->inp_buff_end = buf + len;
  inp_init(u);
}
Пример #3
0
void encrypt_load()
{
	struct inp_file inp;
	inp_init(&inp);
	if (inp_load(&inp,"crypto.inp")!=0)
	{
		printf("can't find file crypto.inp");
		exit(0);
	}

	inp_check(&inp,1.0);
	inp_search_string(&inp,iv_text,"#iv");
	inp_search_string(&inp,key_text,"#key");
	inp_free(&inp);
}
Пример #4
0
int light_load_laser(struct simulation *sim, struct light *in,char *name)
{
    char pwd[1000];
    char file_name[255];
    struct inp_file inp;
    int ret=0;

    if (getcwd(pwd,1000)==NULL)
    {
        ewe(sim,"IO error\n");
    }

    ret=search_for_token(sim,file_name,pwd,"#laser_name",name);

    if (ret==0)
    {
        inp_init(sim,&inp);
        inp_load_from_path(sim,&inp,get_input_path(sim),file_name);
        inp_check(sim,&inp,1.0);

        inp_search_gdouble(sim,&inp,&in->laser_wavelength,"#laserwavelength");
        in->laser_pos=(int)((in->laser_wavelength-in->lstart)/in->dl);

        inp_search_gdouble(sim,&inp,&in->spotx,"#spotx");

        inp_search_gdouble(sim,&inp,&in->spoty,"#spoty");

        inp_search_gdouble(sim,&inp,&in->pulseJ,"#pulseJ");

        inp_search_gdouble(sim,&inp,&in->pulse_width,"#laser_pulse_width");

        inp_free(sim,&inp);
        printf_log(sim,"Loaded laser\n");
    } else
    {
        ewe(sim,"laser name not found\n");
    }
    return 0;
}
Пример #5
0
void pulse_load_config(struct pulse *in, struct device *dev,
		       char *config_file_name)
{

	char name[200];
	struct inp_file inp;
	inp_init(&inp);
	inp_load_from_path(&inp, dev->inputpath, config_file_name);
	inp_check(&inp, 1.25);

	inp_search_double(&inp, &(in->Rshort_pulse), "#Rshort_pulse");
	inp_search_double(&inp, &(in->pulse_laser_power), "#pulse_laser_power");
	inp_search_double(&inp, &(in->pulse_shift), "#pulse_shift");
	inp_search_string(&inp, name, "#pulse_sim_mode");
	inp_search_double(&inp, &(in->pulse_L), "#pulse_L");
	inp_search_double(&inp, &(in->pulse_Rload), "#Rload");

	in->pulse_sim_mode = english_to_bin(name);

	inp_free(&inp);

}
Пример #6
0
/* =============================================================================
 * ud_inp_set_hook() - Sets input hook.
 * =============================================================================
 */
extern void 
ud_set_input_hook(register struct ud* u, int (*hook)(struct ud*))
{
  u->inp_hook = hook;
  inp_init(u);
}
Пример #7
0
void dumpfiles_load(struct simulation* sim)
{
	int dump;
	struct inp_file inp;
	inp_init(sim,&inp);
	char file[100];
	int dump_file=0;
	int norm_y=0;
	char *line;
	int ret=0;
	int pos=0;
	if (inp_load_from_path(sim,&inp,get_input_path(sim),"dump_file.inp")!=0)
	{
		ewe(sim,"Error opening dump_file.inp");
	}

	sim->dumpfiles=inp_count_hash_tags(sim,&inp)-1;
	printf("files=%d\n",sim->dumpfiles);

	if (sim->dumpfiles<=0)
	{
		ewe(sim,"Error reading dump_file.inp");
	}

	sim->dumpfile=(struct dumpfiles_struct*)malloc(sizeof(struct dumpfiles_struct)*sim->dumpfiles);

	inp_reset_read(sim,&inp);

	do
	{
		line  = inp_get_string(sim,&inp);

		if (line==NULL)
		{
			break;
		}

		if (strcmp(line,"#end")==0)
		{
			break;
		}

		strcpy(sim->dumpfile[pos].filename,(line+1));


		line  = inp_get_string(sim,&inp);

		if (line==NULL)
		{
			break;
		}

		sim->dumpfile[pos].dump=english_to_bin(sim, line);


		line  = inp_get_string(sim,&inp);

		if (line==NULL)
		{
			break;
		}

		sim->dumpfile[pos].ynorm=english_to_bin(sim, line);
		//printf("%s %d\n",sim->dumpfile[pos].filename,sim->dumpfile[pos].ynorm);
		pos++;


	}while(1);


	inp_free(sim,&inp);


}
Пример #8
0
void light_init(struct light *in, struct device *cell, char *output_path)
{
	printf_log(_("Light initialization\n"));
	in->pulse_width = 0.0;
	strcpy(in->output_path, output_path);
	strcpy(in->input_path, cell->inputpath);

	char lib_path[200];
	double ver;
	double temp;
	in->disable_transfer_to_electrical_mesh = FALSE;
	struct inp_file inp;
	inp_init(&inp);
	inp_load_from_path(&inp, cell->inputpath, "light.inp");
	inp_check(&inp, 1.25);

	inp_search_double(&inp, &(temp), "#Psun");
	cell->Psun = fabs(temp);

	inp_search_string(&inp, in->mode, "#light_model");

	inp_search_double(&inp, &(in->Dphotoneff), "#Dphotoneff");
	in->Dphotoneff = fabs(in->Dphotoneff);

	inp_search_double(&inp, &(in->ND), "#NDfilter");

	inp_search_double(&inp, &(temp), "#high_sun_scale");

	cell->Psun *= fabs(temp);

	inp_search_double(&inp, &(ver), "#ver");

	inp_free(&inp);

	char lib_name[100];
	sprintf(lib_name, "%s.so", in->mode);

	join_path(2, lib_path, get_light_path(), lib_name);
	printf_log("I want to open %s %s %s\n", lib_path, get_light_path(),
		   lib_name);

	char *error;

	in->lib_handle = dlopen(lib_path, RTLD_LAZY);

	if (!in->lib_handle) {
		fprintf(stderr, "%s\n", dlerror());
		exit(0);
	}

	in->fn_init = dlsym(in->lib_handle, "light_dll_init");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	in->fn_solve_and_update =
	    dlsym(in->lib_handle, "light_dll_solve_and_update");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	in->fn_free = dlsym(in->lib_handle, "light_dll_free");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	in->fn_solve_lam_slice =
	    dlsym(in->lib_handle, "light_dll_solve_lam_slice");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	in->light_ver = dlsym(in->lib_handle, "light_dll_ver");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	in->fn_fixup = dlsym(in->lib_handle, "light_dll_fixup");
	if ((error = dlerror()) != NULL) {
		fprintf(stderr, "%s\n", error);
		exit(0);
	}

	(*in->fn_fixup) ("waveprint", &waveprint);
	(*in->fn_fixup) ("get_dump_status", &get_dump_status);
	(*in->fn_fixup) ("light_dump_1d", &light_dump_1d);
	(*in->fn_fixup) ("light_solve_optical_problem",
			 &light_solve_optical_problem);
	(*in->fn_fixup) ("light_free_memory", &light_free_memory);
	(*in->fn_fixup) ("light_transfer_gen_rate_to_device",
			 &light_transfer_gen_rate_to_device);
	(*in->fn_fixup) ("complex_solver", &complex_solver);
	(*in->fn_fixup) ("printf_log", &printf_log);
	(*in->light_ver) ();
	(*in->fn_init) ();
}
Пример #9
0
int main(int argc, char *argv[])
{
    cal_path();
    setlocale(LC_MESSAGES, "");
    bindtextdomain("opvdm", get_lang_path());
    textdomain("opvdm");

    timer_init(0);
    timer_init(1);
    dbus_init();
    set_ewe_lock_file("", "");
    cell.onlypos = FALSE;

    char pwd[1000];
    if (getcwd(pwd, 1000) == NULL) {
        ewe("IO error\n");
    }

    dump_init(&cell);
    dump_load_config(&cell);

    remove("snapshots.zip");
    remove("light_dump.zip");

    hard_limit_init();

//char path[PATH_MAX];
//char dest[PATH_MAX];
//pid_t pid = getpid();
//sprintf(path, "/proc/%d/exe", pid);

//if (readlink(path, dest, PATH_MAX) == -1)
//{
//      printf("error\n");
//      exit(1);
//}
//  char *base = strrchr(dest, '/');
//*base='/';
//*(base+1)=0;
    set_plot_script_dir(pwd);

//set_plot_script_dir(char * in)
    if (scanarg(argv, argc, "--help") == TRUE) {
        printf("opvdm_core - Organic Photovoltaic Device Model\n");
        printf(copyright);
        printf("\n");
        printf("Usage: opvdm_core [options]\n");
        printf("\n");
        printf("Options:\n");
        printf("\n");
        printf("\t--outputpath\toutput data path");
        printf("\t--inputpath\t sets the input path\n");
        printf("\t--version\tdisplays the current version\n");
        printf("\t--zip_results\t zip the results\n");
        printf("\t--optics\t runs only optical simulation\n");
        printf("\t--cpus\t sets the number of CPUs\n");
        printf("\n");
        printf
        ("Additional information about opvdm is available at www.opvdm.com.\n");
        printf("\n");
        printf
        ("Report bugs to: [email protected]\n\n");
        exit(0);
    }
    if (scanarg(argv, argc, "--version") == TRUE) {
        printf("opvdm_core, Version %s\n", opvdm_ver);
        printf(copyright);
        printf(this_is_free_software);
        printf
        ("There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or\n");
        printf("FITNESS FOR A PARTICULAR PURPOSE.\n");
        printf("\n");
        exit(0);
    }

    if (geteuid() == 0) {
        ewe("Don't run me as root!\n");
    }

    set_dump_status(dump_stop_plot, FALSE);
    set_dump_status(dump_print_text, TRUE);

    set_io_dump(FALSE);
    srand(time(0));
    textcolor(fg_green);
    randomprint(_("Organic Photovoltaic Device Model (www.opvdm.com)\n"));
    randomprint(_
                ("You should have received a copy of the GNU General Public License\n"));
    randomprint(_
                ("along with this software.  If not, see www.gnu.org/licenses/.\n"));
    randomprint("\n");
    randomprint(_
                ("If you wish to collaborate in anyway please get in touch:\n"));
    randomprint(_("[email protected]\n"));
    randomprint(_("www.roderickmackenzie.eu/contact.html\n"));
    randomprint("\n");
    textcolor(fg_reset);

    globalserver.on = FALSE;
    globalserver.cpus = 1;
    globalserver.readconfig = TRUE;

    if (scanarg(argv, argc, "--outputpath") == TRUE) {
        strcpy(sim_output_path(),
               get_arg_plusone(argv, argc, "--outputpath"));
    } else {
        strcpy(sim_output_path(), pwd);
    }

    if (scanarg(argv, argc, "--inputpath") == TRUE) {
        strcpy(sim_input_path(),
               get_arg_plusone(argv, argc, "--inputpath"));
    } else {
        strcpy(sim_input_path(), sim_output_path());
    }

    dump_load_config(&cell);

    if (scanarg(argv, argc, "--onlypos") == TRUE) {
        cell.onlypos = TRUE;
    }

    char name[200];
    struct inp_file inp;
    inp_init(&inp);
    inp_load_from_path(&inp, sim_input_path(), "ver.inp");
    inp_check(&inp, 1.0);
    inp_search_string(&inp, name, "#core");
    inp_free(&inp);

    if (strcmp(name, opvdm_ver) != 0) {
        printf
        ("Software is version %s and the input files are version %s\n",
         opvdm_ver, name);
        exit(0);
    }

    gui_start();
    if (scanarg(argv, argc, "--optics") == FALSE)
        server_init(&globalserver);

    if (scanarg(argv, argc, "--lock") == TRUE) {
        server_set_dbus_finish_signal(&globalserver,
                                      get_arg_plusone(argv, argc,
                                              "--lock"));
    }

    int ret = 0;

    int do_fit = FALSE;

    if (scanarg(argv, argc, "--fit") == TRUE)
        do_fit = TRUE;

    FILE *f = fopen("fit.inp", "r");
    if (f != NULL) {
        fclose(f);
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "fit.inp");
        int fit_temp;
        inp_search_int(&inp, &fit_temp, "#do_fit");
        if (fit_temp == 1) {
            do_fit = TRUE;
        }

        inp_free(&inp);
    }

    if (do_fit == TRUE) {
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_print_text, FALSE);
        set_dump_status(dump_iodump, FALSE);
        set_dump_status(dump_optics, FALSE);
        set_dump_status(dump_newton, FALSE);
        set_dump_status(dump_plot, FALSE);
        set_dump_status(dump_stop_plot, FALSE);
        set_dump_status(dump_opt_for_fit, FALSE);
        set_dump_status(dump_print_newtonerror, FALSE);
        set_dump_status(dump_print_converge, FALSE);
        set_dump_status(dump_print_pos_error, FALSE);
        set_dump_status(dump_lock, TRUE);
    }
#include "main_args.c"
    if (scanarg(argv, argc, "--optics") == TRUE) {
        gui_start();
        struct light two;
        light_init(&two, &cell, pwd);
        //light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]);
        light_load_config(&two);
        two.disable_transfer_to_electrical_mesh = TRUE;
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_optics, TRUE);
        set_dump_status(dump_optics_verbose, TRUE);
        double Psun;
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "light.inp");
        inp_search_double(&inp, &(Psun), "#Psun");
        Psun = 1.0;	//fabs(Psun);
        inp_free(&inp);

        light_solve_and_update(&cell, &two, Psun, 0.0);
        light_dump(&two);
        light_free(&two);
        complex_solver_free();
    } else {
        gen_dos_fd_gaus_fd();

        server_add_job(&globalserver, cell.outputpath, cell.inputpath);
        print_jobs(&globalserver);
        ret = server_run_jobs(&globalserver);

    }

    server_shut_down(&globalserver);

    if (scanarg(argv, argc, "--zip_results") == TRUE) {
        printf("zipping results\n");
        int ret;
        char temp[200];
        DIR *dir = opendir("snapshots");
        if (dir) {
            closedir(dir);
            ret =
                system("zip -r -j -q snapshots.zip ./snapshots/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "snapshots");
            remove_dir(temp);

        }

        dir = opendir("light_dump");
        if (dir) {
            closedir(dir);
            ret =
                system
                ("zip -r -j -q light_dump.zip ./light_dump/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "light_dump");
            remove_dir(temp);

        }

    }

    hard_limit_free();
    if (ret != 0) {
        return 1;
    }
    return 0;
}