static void __destory_object_type_file(object_type_file *file)
{
	if (file == NULL) {
		return;
	}
	
	delete file->object_type_list;
	delete file->object_type_exists;
	close(file->fd);
	inter_free(file);
}
Beispiel #2
0
void process_ce_data(int col, char *input, char *output)
{
	int i;
	struct istruct data;

	double d =
	    read_value("device.inp", 0, 12) + read_value("device.inp", 0, 39);
	double area =
	    read_value("device.inp", 0, 21) * read_value("device.inp", 0, 23);

	double cap = read_value("blom_bulk.inp", 0, 84) * epsilon0 * area / d;
	double capq = 0.0;

	double dt = 0.0;

	int x = 0;

	FILE *out = fopen(output, "w");

	for (x = 0; x < col; x++) {
		printf("loading.... %d\n", x);
		inter_load_by_col(&data, input, x);

		double tot = 0.0;

		for (i = 1; i < data.len - 1; i++) {
			//if ((data.x[i]>1e-6)&&(data.x[i]<1e-5))
			{
				dt = (data.x[i + 1] - data.x[i - 1]) / 2.0;
				tot += data.data[i] * dt;
			}
		}

		capq = (data.x[0] * cap) / Q;	//charge on capasitor
		capq /= area;
		capq /= d;

		tot /= area;
		tot /= d;
		tot /= Q;

		fprintf(out, "%e %e\n", data.data[0], tot - capq);
		inter_free(&data);
	}
//getchar();

	fclose(out);

}
static object_type_file *__init_object_type_file(const char *dir_path)
{
	int fd = open_file(dir_path, "object_types.dat");
	object_type_file *file = (object_type_file *)inter_malloc(sizeof(object_type_file));
	
	if (fd < 0) {
		// should not be happened
		err_code = MS_ERRC_OE_FILE_OPEN_FAIL;
		goto init_fail;
	} else {
		struct stat st = {0};
		if (fstat(fd, &st) == -1) {
			err_code = MS_ERRC_OE_FILE_SIZE_FAIL;
			goto init_fail;
		} else {
			file->fd = fd;
			file->fs = st.st_size;
			
			if (st.st_size > 0) {
				void *buff = inter_mmap(NULL, (size_t)st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
				if (buff == MAP_FAILED) {
					__malloc_printf("fail to mmap, %s", strerror(errno));
					err_code = MS_ERRC_OE_FILE_MMAP_FAIL;
					goto init_fail;
				} else {
					file->object_type_list = new sb_tree<object_type>(1 << 10, __object_types_reallocator, __object_types_deallocator, buff, (size_t)st.st_size, file);
				}
			} else {
				file->object_type_list = new sb_tree<object_type>(1 << 10, __object_types_reallocator, __object_types_deallocator,NULL, 0, file);
			}
		}
	}
	file->object_type_exists = new sb_tree<uintptr_t>(1 << 10);
	return file;
	
init_fail:
	if (fd >= 0) close(fd);
	inter_free(file);
	return NULL;
}
Beispiel #4
0
void dump_dynamic_free(struct dynamic_store *store)
{
	if (get_dump_status(dump_dynamic) == TRUE) {
		inter_free(&(store->charge_change));
		inter_free(&(store->jout));
		inter_free(&(store->jn_avg));
		inter_free(&(store->jp_avg));
		inter_free(&(store->dynamic_jn));
		inter_free(&(store->dynamic_jp));
		inter_free(&(store->jnout_mid));
		inter_free(&(store->jpout_mid));
		inter_free(&(store->iout));
		inter_free(&(store->iout_left));
		inter_free(&(store->iout_right));
		inter_free(&(store->gexout));
		inter_free(&(store->nfree_to_ptrap));
		inter_free(&(store->pfree_to_ntrap));
		inter_free(&(store->Rnout));
		inter_free(&(store->Rpout));
		inter_free(&(store->nrelax_out));
		inter_free(&(store->prelax_out));
		inter_free(&(store->ntrap));
		inter_free(&(store->ptrap));
		inter_free(&(store->ntrap_delta_out));
		inter_free(&(store->ptrap_delta_out));
		inter_free(&(store->nfree));
		inter_free(&(store->pfree));
		inter_free(&(store->nfree_delta_out));
		inter_free(&(store->pfree_delta_out));
		inter_free(&(store->tpc_filledn));
		inter_free(&(store->Rnpout));
		inter_free(&(store->tpc_filledp));
		inter_free(&(store->tpc_mue));
		inter_free(&(store->tpc_muh));
		inter_free(&(store->tpc_mu_avg));
		inter_free(&(store->only_n));
		inter_free(&(store->only_p));
		inter_free(&(store->dynamic_np));
		inter_free(&(store->E_field));
		inter_free(&(store->dynamic_Vapplied));
		inter_free(&(store->dynamic_charge_tot));
		inter_free(&(store->dynamic_pl));
		inter_free(&(store->dynamic_jn_drift));
		inter_free(&(store->dynamic_jn_diffusion));
		inter_free(&(store->dynamic_jp_drift));
		inter_free(&(store->dynamic_jp_diffusion));
		inter_free(&(store->dynamic_qe));

		inter_free(&(store->srh_n_r1));
		inter_free(&(store->srh_n_r2));
		inter_free(&(store->srh_n_r3));
		inter_free(&(store->srh_n_r4));

		inter_free(&(store->srh_p_r1));
		inter_free(&(store->srh_p_r2));
		inter_free(&(store->srh_p_r3));
		inter_free(&(store->srh_p_r4));

		inter_free(&(store->band_bend));

		free(store->band_snapshot);
	}
}
Beispiel #5
0
void dump_dynamic_save(char *outputpath, struct dynamic_store *store)
{
	int i;
	int sub = TRUE;
	char temp[200];
	struct buffer buf;
	buffer_init(&buf);

	if (get_dump_status(dump_dynamic) == TRUE) {

		if (get_dump_status(dump_norm_time_to_one) == TRUE) {
			buf.norm_x_axis = TRUE;
		}

		if (get_dump_status(dump_norm_y_axis) == TRUE) {
			buf.norm_y_axis = TRUE;
		}

		char out_dir[1000];
		sprintf(out_dir, "%s/dynamic/", outputpath);
		struct stat st = { 0 };

		if (stat(out_dir, &st) == -1) {
			mkdir(out_dir, 0700);
		}

		char outpath[200];

		sprintf(outpath, "%s%s", out_dir, "dynamic_jn_mid.dat");
		inter_save(&(store->jnout_mid), outpath);

		struct istruct one;
		inter_copy(&one, &(store->jnout_mid), TRUE);
		inter_deriv(&one, &(store->jnout_mid));
		sprintf(outpath, "%s%s", out_dir, "dynamic_djn.dat");
		inter_save(&one, outpath);
		inter_free(&one);

		sprintf(outpath, "%s%s", out_dir, "dynamic_jp_mid.dat");
		inter_save(&(store->jpout_mid), outpath);

		inter_copy(&one, &(store->jpout_mid), TRUE);
		inter_deriv(&one, &(store->jpout_mid));
		sprintf(outpath, "%s%s", out_dir, "dynamic_djp.dat");
		inter_save(&one, outpath);
		inter_free(&one);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Hole drift plus diffusion current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);

		for (i = 0; i < (store->dynamic_jp_drift).len; i++) {
			sprintf(temp, "%e %e\n", (store->dynamic_jp_drift).x[i],
				(store->dynamic_jp_drift).data[i] +
				(store->dynamic_jp_diffusion).data[i]);
			buffer_add_string(&buf, temp);
		}
		buffer_dump_path(out_dir, "dynamic_jp_drift_plus_diffusion.dat",
				 &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Electron drift plus diffusion current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		for (i = 0; i < (store->dynamic_jn_drift).len; i++) {
			sprintf(temp, "%e %e\n", (store->dynamic_jn_drift).x[i],
				(store->dynamic_jn_drift).data[i] +
				(store->dynamic_jn_diffusion).data[i]);
			buffer_add_string(&buf, temp);
		}
		buffer_dump_path(out_dir, "dynamic_jn_drift_plus_diffusion.dat",
				 &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Current density at contacts");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		if (sub == TRUE) {
			inter_sub_double(&(store->jout), (store->jout).data[0]);
			inter_mul(&(store->jout), -1.0);
		}
		buffer_add_xy_data(&buf, (store->jout).x, (store->jout).data,
				   (store->jout).len);
		buffer_dump_path(out_dir, "dynamic_j.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Change in charge distribution");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "percent");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$\\%$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->charge_change).x,
				   (store->charge_change).data,
				   (store->charge_change).len);
		buffer_dump_path(out_dir, "dynamic_charge_change.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Drift current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jn_drift).x,
				   (store->dynamic_jn_drift).data,
				   (store->dynamic_jn_drift).len);
		buffer_dump_path(out_dir, "dynamic_jn_drift.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Diffusion current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jn_diffusion).x,
				   (store->dynamic_jn_diffusion).data,
				   (store->dynamic_jn_diffusion).len);
		buffer_dump_path(out_dir, "dynamic_jn_diffusion.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Drift current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jp_drift).x,
				   (store->dynamic_jp_drift).data,
				   (store->dynamic_jp_drift).len);
		buffer_dump_path(out_dir, "dynamic_jp_drift.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Diffusion current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jp_diffusion).x,
				   (store->dynamic_jp_diffusion).data,
				   (store->dynamic_jp_diffusion).len);
		buffer_dump_path(out_dir, "dynamic_jp_diffusion.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Jn contacts");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jn).x,
				   (store->dynamic_jn).data,
				   (store->dynamic_jn).len);
		buffer_dump_path(out_dir, "dynamic_jn_contacts.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Jp contacts");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole current density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$A m^{-2}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_jp).x,
				   (store->dynamic_jp).data,
				   (store->dynamic_jp).len);
		buffer_dump_path(out_dir, "dynamic_jp_contacts.dat", &buf);
		buffer_free(&buf);

		sprintf(outpath, "%s%s", out_dir, "dynamic_jn_avg.dat");
		inter_save(&(store->jn_avg), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_jp_avg.dat");
		inter_save(&(store->jp_avg), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "External Current");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Current");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$Amps$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->iout).x, (store->iout).data,
				   (store->iout).len);
		buffer_dump_path(out_dir, "dynamic_i.dat", &buf);
		buffer_free(&buf);

		sprintf(outpath, "%s%s", out_dir, "dynamic_i_left.dat");
		inter_save(&(store->iout_left), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_i_right.dat");
		inter_save(&(store->iout_right), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free carrier generation rate");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Generation rate");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->gexout).x,
				   (store->gexout).data, (store->gexout).len);
		buffer_dump_path(out_dir, "dynamic_gex.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Dynamic quantum efficency");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Percent");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$\%$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_qe).x,
				   (store->dynamic_qe).data,
				   (store->dynamic_qe).len);
		buffer_dump_path(out_dir, "dynamic_qe.dat", &buf);
		buffer_free(&buf);

		double sum = inter_intergrate(&(store->nfree_to_ptrap));
		FILE *out = fopen("dynamic_Rn_int.dat", "w");
		fprintf(out, "%le", sum);
		fclose(out);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free hole recombination");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Recombination");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->pfree_to_ntrap).x,
				   (store->pfree_to_ntrap).data,
				   (store->pfree_to_ntrap).len);
		buffer_dump_path(out_dir, "dynamic_pf_to_nt.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free electron recombination");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Recombination");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->nfree_to_ptrap).x,
				   (store->nfree_to_ptrap).data,
				   (store->nfree_to_ptrap).len);
		buffer_dump_path(out_dir, "dynamic_nf_to_pt.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free electron loss - time");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Free electron loss");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->Rnout).x, (store->Rnout).data,
				   (store->Rnout).len);
		buffer_dump_path(out_dir, "dynamic_Rn.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free hole loss - time");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Free hole loss");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->Rpout).x, (store->Rpout).data,
				   (store->Rpout).len);
		buffer_dump_path(out_dir, "dynamic_Rp.dat", &buf);
		buffer_free(&buf);

		sum = inter_intergrate(&(store->pfree_to_ntrap));
		out = fopen("dynamic_Rp_int.dat", "w");
		fprintf(out, "%le", sum);
		fclose(out);

		inter_make_cumulative(&(store->nfree_to_ptrap));
		//inter_div_double(&nfree_to_ptrap,in->stark_den);
		sprintf(outpath, "%s%s", out_dir, "dynamic_Rn_cumulative.dat");
		inter_save(&(store->nfree_to_ptrap), outpath);

		inter_make_cumulative(&(store->pfree_to_ntrap));
		//inter_div_double(&pfree_to_ntrap,in->stark_den);
		sprintf(outpath, "%s%s", out_dir, "dynamic_Rp_cumulative.dat");
		inter_save(&(store->pfree_to_ntrap), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Electron relaxation");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Relaxation");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->nrelax_out).x,
				   (store->nrelax_out).data,
				   (store->nrelax_out).len);
		buffer_dump_path(out_dir, "dynamic_nrelax.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "Hole relaxation");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Relaxation");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "$m^{-3}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->prelax_out).x,
				   (store->prelax_out).data,
				   (store->prelax_out).len);
		buffer_dump_path(out_dir, "dynamic_prelax.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Trapped electron density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->ntrap).x, (store->ntrap).data,
				   (store->ntrap).len);
		buffer_dump_path(out_dir, "dynamic_nt.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Trapped hole density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->ptrap).x, (store->ptrap).data,
				   (store->ptrap).len);
		buffer_dump_path(out_dir, "dynamic_pt.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free electron density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->nfree).x, (store->nfree).data,
				   (store->nfree).len);
		buffer_dump_path(out_dir, "dynamic_nf.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Free hole density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->pfree).x, (store->pfree).data,
				   (store->pfree).len);
		buffer_dump_path(out_dir, "dynamic_pf.dat", &buf);
		buffer_free(&buf);

		sprintf(outpath, "%s%s", out_dir, "dynamic_nfree_delta.dat");
		inter_save(&(store->nfree_delta_out), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_pfree_delta.dat");
		inter_save(&(store->pfree_delta_out), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_ntrap_delta.dat");
		inter_save(&(store->ntrap_delta_out), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_ptrap_delta.dat");
		inter_save(&(store->ptrap_delta_out), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_filledn.dat");
		inter_save(&(store->tpc_filledn), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_Rn-p.dat");
		inter_save(&(store->Rnpout), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_filledp.dat");
		inter_save(&(store->tpc_filledp), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Electron mobility");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Mobility");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{2}V^{-1}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->tpc_mue).x,
				   (store->tpc_mue).data, (store->tpc_mue).len);
		buffer_dump_path(out_dir, "dynamic_mue.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Hole mobility");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Mobility");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{2}V^{-1}s^{-1}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->tpc_muh).x,
				   (store->tpc_muh).data, (store->tpc_muh).len);
		buffer_dump_path(out_dir, "dynamic_muh.dat", &buf);
		buffer_free(&buf);

		sprintf(outpath, "%s%s", out_dir, "dynamic_mu_avg.dat");
		inter_save(&(store->tpc_mu_avg), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Total electron density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Electron density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->only_n).x,
				   (store->only_n).data, (store->only_n).len);
		buffer_dump_path(out_dir, "dynamic_n.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Total hole density");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Hole density");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$m^{-3}$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->only_p).x,
				   (store->only_p).data, (store->only_p).len);
		buffer_dump_path(out_dir, "dynamic_p.dat", &buf);
		buffer_free(&buf);

		//inter_sub_double(&dynamic_np,dynamic_np.data[0]);
		sprintf(outpath, "%s%s", out_dir, "dynamic_np.dat");
		inter_save(&(store->dynamic_np), outpath);

		inter_norm(&(store->dynamic_np), 1.0);
		sprintf(outpath, "%s%s", out_dir, "dynamic_np_norm.dat");
		inter_save(&(store->dynamic_np), outpath);

		sprintf(outpath, "%s%s", out_dir, "dynamic_E_field.dat");
		inter_div_double(&(store->E_field), (store->E_field).data[0]);
		inter_save(&(store->E_field), outpath);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1e6;
		strcpy(buf.title, "Voltage applied to diode");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "Voltage");
		strcpy(buf.x_units, "$\\mu s$");
		strcpy(buf.y_units, "$V$");
		buf.logscale_x = 0;
		buf.logscale_y = 0;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_Vapplied).x,
				   (store->dynamic_Vapplied).data,
				   (store->dynamic_Vapplied).len);
		buffer_dump_path(out_dir, "dynamic_Vapplied.dat", &buf);
		buffer_free(&buf);

		sprintf(outpath, "%s%s", out_dir, "dynamic_charge_tot.dat");
		inter_sub_double(&(store->dynamic_charge_tot),
				 (store->dynamic_charge_tot).data[0]);
		inter_save(&(store->dynamic_charge_tot), outpath);

		inter_chop(&(store->dynamic_pl), 1.0e-9, 1.0);
		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "PL intensity");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "PL Intensity");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "au");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_pl).x,
				   (store->dynamic_pl).data,
				   (store->dynamic_pl).len);
		buffer_dump_path(out_dir, "dynamic_pl.dat", &buf);
		buffer_free(&buf);

		double max = inter_get_max(&(store->dynamic_pl));
		inter_div_double(&(store->dynamic_pl), max);
		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "PL intensity normalized");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "PL Intensity");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "au");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->dynamic_pl).x,
				   (store->dynamic_pl).data,
				   (store->dynamic_pl).len);
		buffer_dump_path(out_dir, "dynamic_pl_norm.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_n_r1");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_n_r1");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3} s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_n_r1).x,
				   (store->srh_n_r1).data,
				   (store->srh_n_r1).len);
		buffer_dump_path(out_dir, "dynamic_srh_n_r1.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_n_r2");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_n_r2");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_n_r2).x,
				   (store->srh_n_r2).data,
				   (store->srh_n_r2).len);
		buffer_dump_path(out_dir, "dynamic_srh_n_r2.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_n_r3");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_n_r3");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_n_r3).x,
				   (store->srh_n_r3).data,
				   (store->srh_n_r3).len);
		buffer_dump_path(out_dir, "dynamic_srh_n_r3.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_n_r4");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_n_r4");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_n_r4).x,
				   (store->srh_n_r4).data,
				   (store->srh_n_r4).len);
		buffer_dump_path(out_dir, "dynamic_srh_n_r4.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_p_r1");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_p_r1");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_p_r1).x,
				   (store->srh_p_r1).data,
				   (store->srh_p_r1).len);
		buffer_dump_path(out_dir, "dynamic_srh_p_r1.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_p_r2");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_p_r2");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_p_r2).x,
				   (store->srh_p_r2).data,
				   (store->srh_p_r2).len);
		buffer_dump_path(out_dir, "dynamic_srh_p_r2.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_p_r3");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_p_r3");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_p_r3).x,
				   (store->srh_p_r3).data,
				   (store->srh_p_r3).len);
		buffer_dump_path(out_dir, "dynamic_srh_p_r3.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. srh_p_r4");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "srh_p_r4");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "m^{-3}s^{-1}");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->srh_p_r4).x,
				   (store->srh_p_r4).data,
				   (store->srh_p_r4).len);
		buffer_dump_path(out_dir, "dynamic_srh_p_r4.dat", &buf);
		buffer_free(&buf);

		buffer_malloc(&buf);
		buf.y_mul = 1.0;
		buf.x_mul = 1.0;
		strcpy(buf.title, "time v.s. band bend (percent)");
		strcpy(buf.type, "xy");
		strcpy(buf.x_label, "Time");
		strcpy(buf.y_label, "band bend");
		strcpy(buf.x_units, "s");
		strcpy(buf.y_units, "percent");
		buf.logscale_x = 1;
		buf.logscale_y = 1;
		buffer_add_info(&buf);
		buffer_add_xy_data(&buf, (store->band_bend).x,
				   (store->band_bend).data,
				   (store->band_bend).len);
		buffer_dump_path(out_dir, "dynamic_band_bend.dat", &buf);
		buffer_free(&buf);
	}

}
Beispiel #6
0
void sim_pulse(struct device *in)
{
	struct buffer buf;
	buffer_init(&buf);

	struct dynamic_store store;
	dump_dynamic_init(&store, in);

	struct istruct out_i;
	inter_init(&out_i);

	struct istruct out_v;
	inter_init(&out_v);

	struct istruct out_G;
	inter_init(&out_G);

	struct istruct lost_charge;
	inter_init(&lost_charge);

	char config_file_name[200];

	if (find_config_file
	    (config_file_name, in->inputpath, in->simmode, "pulse") != 0) {
		ewe("%s %s %s\n", _("no pulse config file found"),
		    in->inputpath, in->simmode);
	}

	printf("%s\n", config_file_name);

	pulse_load_config(&pulse_config, in, config_file_name);
	int number = strextract_int(config_file_name);
	ntricks_externv_set_load(pulse_config.pulse_Rload);

	in->go_time = FALSE;

	in->time = 0.0;

	time_init(in);
//time_load_mesh(in,number);

	time_load_mesh(in, number);
//time_mesh_save();
//getchar();
//struct istruct pulseout;
//inter_init(&pulseout);

	int ittr = 0;

	int step = 0;
	in->Psun = time_get_sun();
	light_solve_and_update(in, &(in->mylight), time_get_sun(),
			       time_get_laser());

	double V = 0.0;

	if (pulse_config.pulse_sim_mode == pulse_load) {
		sim_externalv(in, time_get_voltage());
		ntricks_externv_newton(in, time_get_voltage(), FALSE);
	} else if (pulse_config.pulse_sim_mode == pulse_open_circuit) {
		in->Vapplied = in->Vbi;
		pulse_newton_sim_voc(in);
		pulse_newton_sim_voc_fast(in, FALSE);
	} else {
		ewe(_("pulse mode not known\n"));
	}

	device_timestep(in);

	in->go_time = TRUE;

	double extracted_through_contacts = 0.0;
	double i0 = 0;
	carrier_count_reset(in);
	reset_np_save(in);
	do {
		in->Psun = time_get_sun();
		light_solve_and_update(in, &(in->mylight), time_get_sun(),
				       time_get_laser() + time_get_fs_laser());
		dump_dynamic_add_data(&store, in, in->time);

		if (pulse_config.pulse_sim_mode == pulse_load) {
			i0 = ntricks_externv_newton(in, time_get_voltage(),
						    TRUE);
		} else if (pulse_config.pulse_sim_mode == pulse_open_circuit) {
			V = in->Vapplied;
			pulse_newton_sim_voc_fast(in, TRUE);
		} else {
			ewe(_("pulse mode not known\n"));
		}

		if (get_dump_status(dump_print_text) == TRUE) {
			printf_log("%s=%e %s=%d %.1e ", _("pulse time"),
				   in->time, _("step"), step, in->last_error);
			printf_log("Vtot=%lf %s = %e mA (%e A/m^2)\n", V,
				   _("current"), get_I(in) / 1e-3, get_J(in));
		}

		ittr++;

		gui_send_data("pulse");
		dump_write_to_disk(in);

		plot_now(in, "pulse.plot");

		inter_append(&out_i, in->time, i0);
		inter_append(&out_v, in->time, V);
		inter_append(&out_G, in->time, in->Gn[0]);
		inter_append(&lost_charge, in->time,
			     extracted_through_contacts -
			     fabs(get_extracted_n(in) +
				  get_extracted_p(in)) / 2.0);

		device_timestep(in);
		step++;

		if (time_run() == FALSE)
			break;
		//getchar();

	} while (1);

	struct istruct out_flip;

	dump_dynamic_save(in->outputpath, &store);
	dump_dynamic_free(&store);

	buffer_malloc(&buf);
	buf.y_mul = 1e3;
	buf.x_mul = 1e6;
	strcpy(buf.title, _("Time - current"));
	strcpy(buf.type, _("xy"));
	strcpy(buf.x_label, _("Time"));
	strcpy(buf.y_label, _("Current"));
	strcpy(buf.x_units, _("us"));
	strcpy(buf.y_units, _("m"));
	buf.logscale_x = 0;
	buf.logscale_y = 0;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf, out_i.x, out_i.data, out_i.len);
	buffer_dump_path(in->outputpath, "pulse_i.dat", &buf);
	buffer_free(&buf);

	inter_copy(&out_flip, &out_i, TRUE);
	inter_mul(&out_flip, -1.0);

	buffer_malloc(&buf);
	buf.y_mul = 1e3;
	buf.x_mul = 1e6;
	strcpy(buf.title, _("Time - -current"));
	strcpy(buf.type, _("xy"));
	strcpy(buf.x_label, _("Time"));
	strcpy(buf.y_label, _("-Current"));
	strcpy(buf.x_units, _("us"));
	strcpy(buf.y_units, _("mA"));
	buf.logscale_x = 0;
	buf.logscale_y = 0;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf, out_flip.x, out_flip.data, out_flip.len);
	buffer_dump_path(in->outputpath, "pulse_i_pos.dat", &buf);
	buffer_free(&buf);

	inter_free(&out_flip);

	buffer_malloc(&buf);
	buf.y_mul = 1.0;
	buf.x_mul = 1e6;
	strcpy(buf.title, _("Time - Voltage"));
	strcpy(buf.type, _("xy"));
	strcpy(buf.x_label, _("Time"));
	strcpy(buf.y_label, _("Volts"));
	strcpy(buf.x_units, _("us"));
	strcpy(buf.y_units, _("Voltage"));
	buf.logscale_x = 0;
	buf.logscale_y = 0;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf, out_v.x, out_v.data, out_v.len);
	buffer_dump_path(in->outputpath, "pulse_v.dat", &buf);
	buffer_free(&buf);

	buffer_malloc(&buf);
	buf.y_mul = 1.0;
	buf.x_mul = 1e6;
	strcpy(buf.title, _("Time - Photogeneration rate"));
	strcpy(buf.type, _("xy"));
	strcpy(buf.x_label, _("Time"));
	strcpy(buf.y_label, _("Generation rate"));
	strcpy(buf.x_units, _("s"));
	strcpy(buf.y_units, _("m^{-3} s^{-1}"));
	buf.logscale_x = 0;
	buf.logscale_y = 0;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf, out_G.x, out_G.data, out_G.len);
	buffer_dump_path(in->outputpath, "pulse_G.dat", &buf);
	buffer_free(&buf);

//sprintf(outpath,"%s%s",in->outputpath,"pulse_lost_charge.dat");
//inter_save(&lost_charge,outpath);

	in->go_time = FALSE;

	inter_free(&out_G);
	inter_free(&out_i);
	inter_free(&out_v);
	time_memory_free();
}
Beispiel #7
0
void exp_cal_emission(struct simulation *sim,int number,struct device *in)
{

double Re_h=0.0;
double Re_e=0.0;
double Rh_e=0.0;
double Rh_h=0.0;

double dEe_e=0.0;
double dEe_h=0.0;
double dEh_e=0.0;
double dEh_h=0.0;
char name[100];
char out_dir[400];

int x;
int y;
int z;

int band;
struct buffer buf;
char temp[200];
int mat=0;
double pl_fe_fh=0.0;
double pl_fe_te=0.0;
double pl_te_fh=0.0;
double pl_th_fe=0.0;
double pl_ft_th=0.0;
int pl_enabled=0;
char snapshot_dir[200];
char sim_name[200];

double Vexternal=get_equiv_V(sim,in);
//char zip_file_name[400];

buffer_init(&buf);
//sprintf(zip_file_name,"%s/snapshots.zip",get_output_path(sim));
//buffer_zip_set_name(&buf,zip_file_name);

struct istruct fe_to_fh;
struct istruct fe_to_te;
struct istruct te_to_fh;
struct istruct fh_to_th;
struct istruct th_to_fe;

double max_Eg=0.0;
for (z=0;z<in->zmeshpoints;z++)
{
	for (x=0;x<in->xmeshpoints;x++)
	{
		for (y=0;y<in->ymeshpoints;y++)
		{

			if (in->Eg[z][x][y]>max_Eg)
			{
				max_Eg=in->Eg[z][x][y];
			}
		}
	}
}

//inter_init_mesh(&photons,40,0.0,2.254);

inter_init(&fe_to_fh);
inter_init(&fe_to_te);
inter_init(&te_to_fh);
inter_init(&fh_to_th);
inter_init(&th_to_fe);


//double Re_e=0.0;
int pl_data_added=FALSE;
for (z=0;z<in->zmeshpoints;z++)
{
	for (x=0;x<in->xmeshpoints;x++)
	{
		for (y=0;y<in->ymeshpoints;y++)
		{
			mat=in->imat[z][x][y];
			pl_fe_fh=get_pl_fe_fh(in,mat);
			pl_fe_te=get_pl_fe_te(in,mat);
			pl_te_fh=get_pl_te_fh(in,mat);
			pl_th_fe=get_pl_th_fe(in,mat);
			pl_ft_th=get_pl_ft_th(in,mat);
			pl_enabled=get_pl_enabled(in,mat);

				if (pl_enabled==TRUE)
				{
					pl_data_added=TRUE;
					inter_append(&fe_to_fh,in->Eg[z][x][y],in->Rfree[z][x][y]*pl_fe_fh);

					for (band=0;band<in->srh_bands;band++)
					{
						//electrons
						dEe_e= -dos_get_band_energy_n(in,band,mat);
						Re_e=(in->nt_r1[z][x][y][band]-in->nt_r2[z][x][y][band])*pl_fe_te;	//electron capture - electron emission for an electron trap
						inter_append(&fe_to_te,dEe_e,Re_e);

						dEe_h=get_dos_Eg(in,mat)-dEe_e;
						Re_h=(in->nt_r3[z][x][y][band]-in->nt_r4[z][x][y][band])*pl_te_fh;	//hole capture-hole emission for an electron trap
						inter_append(&te_to_fh,dEe_h,Re_h);

						//holes
						dEh_e=get_dos_Eg(in,mat)-dEh_h;
						Rh_e=(in->pt_r3[z][x][y][band]-in->pt_r4[z][x][y][band])*pl_th_fe;	//electron capture - electron emission for a hole trap
						inter_append(&th_to_fe,dEh_e,Rh_e);

						dEh_h= -dos_get_band_energy_p(in,band,mat);
						Rh_h=(in->pt_r1[z][x][y][band]-in->pt_r2[z][x][y][band])*pl_ft_th;	//hole capture - hole emission for a hole trap
						inter_append(&fh_to_th,dEh_h,Rh_h);


					}

				}
		}
	}
}

inter_mul(&fe_to_fh,in->ylen/((double)in->ymeshpoints));
inter_mul(&fe_to_te,in->ylen/((double)in->ymeshpoints));
inter_mul(&te_to_fh,in->ylen/((double)in->ymeshpoints));
inter_mul(&th_to_fe,in->ylen/((double)in->ymeshpoints));
inter_mul(&fh_to_th,in->ylen/((double)in->ymeshpoints));

sprintf(temp,"%d",number);

strextract_name(sim_name,in->simmode);
sprintf(snapshot_dir,"snapshots");

join_path(3,out_dir,get_output_path(sim),snapshot_dir,temp);



//inter_dump(&fe_to_fh);
//inter_sort(&fe_to_fh);
if (pl_data_added==TRUE)
{
	inter_sort(&fe_to_te);
	inter_sort(&te_to_fh);
	inter_sort(&th_to_fe);
	inter_sort(&fh_to_th);

	inter_join_bins(&fe_to_fh,0.01);
	inter_join_bins(&fe_to_te,0.01);
	inter_join_bins(&te_to_fh,0.01);
	inter_join_bins(&th_to_fe,0.01);
	inter_join_bins(&fh_to_th,0.01);

	light_energy=0.0;

	light_energy+=calculate_photon_energy(&fe_to_fh)*in->area;
	light_energy+=calculate_photon_energy(&fe_to_te)*in->area;
	light_energy+=calculate_photon_energy(&te_to_fh)*in->area;
	light_energy+=calculate_photon_energy(&th_to_fe)*in->area;
	light_energy+=calculate_photon_energy(&fh_to_th)*in->area;

	buffer_malloc(&buf);
	sprintf(name,"%s","fe_to_fh.dat");
	buf.y_mul=1.0;
	buf.x_mul=1e9;
	strcpy(buf.title,"PL Spectra Free electron to free hole");
	strcpy(buf.type,"xy");
	strcpy(buf.x_label,"Energy");
	strcpy(buf.y_label,"Intensity");
	strcpy(buf.x_units,"eV");
	strcpy(buf.y_units,"m^{-3}s^{-1}");
	buf.logscale_x=0;
	buf.logscale_y=0;
	buf.time=in->time;
	buf.Vexternal=Vexternal;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf,fe_to_fh.x, fe_to_fh.data, fe_to_fh.len);
	buffer_dump_path(out_dir,name,&buf);
	buffer_free(&buf);

	buffer_malloc(&buf);
	sprintf(name,"%s","te_to_fh.dat");
	buf.y_mul=1.0;
	buf.x_mul=1e9;
	strcpy(buf.title,"PL Spectra Free hole to trapped electron");
	strcpy(buf.type,"xy");
	strcpy(buf.x_label,"Energy");
	strcpy(buf.y_label,"Intensity");
	strcpy(buf.x_units,"eV");
	strcpy(buf.y_units,"m^{-3}s^{-1}");
	buf.logscale_x=0;
	buf.logscale_y=0;
	buf.time=in->time;
	buf.Vexternal=Vexternal;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf,te_to_fh.x, te_to_fh.data, te_to_fh.len);
	buffer_dump_path(out_dir,name,&buf);
	buffer_free(&buf);

	buffer_malloc(&buf);
	sprintf(name,"%s","fe_to_te.dat");
	buf.y_mul=1.0;
	buf.x_mul=1e9;
	strcpy(buf.title,"PL Spectra free electron to trapped electron");
	strcpy(buf.type,"xy");
	strcpy(buf.x_label,"Energy");
	strcpy(buf.y_label,"Intensity");
	strcpy(buf.x_units,"eV");
	strcpy(buf.y_units,"m^{-3}s^{-1}");
	buf.logscale_x=0;
	buf.logscale_y=0;
	buf.time=in->time;
	buf.Vexternal=Vexternal;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf,fe_to_te.x, fe_to_te.data, fe_to_te.len);
	buffer_dump_path(out_dir,name,&buf);
	buffer_free(&buf);


	buffer_malloc(&buf);
	sprintf(name,"%s","th_to_fe.dat");
	buf.y_mul=1.0;
	buf.x_mul=1e9;
	strcpy(buf.title,"PL Spectra Free electron to trapped hole");
	strcpy(buf.type,"xy");
	strcpy(buf.x_label,"Energy");
	strcpy(buf.y_label,"Intensity");
	strcpy(buf.x_units,"eV");
	strcpy(buf.y_units,"m^{-3}s^{-1}");
	buf.logscale_x=0;
	buf.logscale_y=0;
	buf.time=in->time;
	buf.Vexternal=Vexternal;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf,th_to_fe.x, th_to_fe.data, th_to_fe.len);
	buffer_dump_path(out_dir,name,&buf);
	buffer_free(&buf);


	buffer_malloc(&buf);
	sprintf(name,"%s","fh_to_th.dat");
	buf.y_mul=1.0;
	buf.x_mul=1e9;
	strcpy(buf.title,"PL Spectra free hole to trapped hole");
	strcpy(buf.type,"xy");
	strcpy(buf.x_label,"Energy");
	strcpy(buf.y_label,"Intensity");
	strcpy(buf.x_units,"eV");
	strcpy(buf.y_units,"m^{-3}s^{-1}");
	buf.logscale_x=0;
	buf.logscale_y=0;
	buf.time=in->time;
	buf.Vexternal=Vexternal;
	buffer_add_info(&buf);
	buffer_add_xy_data(&buf,fh_to_th.x, fh_to_th.data, fh_to_th.len);
	buffer_dump_path(out_dir,name,&buf);
	buffer_free(&buf);

}

inter_free(&fe_to_fh);
inter_free(&fe_to_te);
inter_free(&te_to_fh);
inter_free(&th_to_fe);
inter_free(&fh_to_th);


return;
}