// getDumpStatus(fsName); // Calls get_Dump_Status JNIEXPORT jobjectArray JNICALL Java_com_sun_netstorage_samqfs_mgmt_fs_Restore_getDumpStatus__Lcom_sun_netstorage_samqfs_mgmt_Ctx_2Ljava_lang_String_2_3Ljava_lang_String_2 (JNIEnv *env, jclass cls /*ARGSUSED*/, jobject ctx, jstring fsname, jobjectArray dumps) { sqm_lst_t *statuslst = NULL; jobjectArray newArr; jboolean isCopy; char *cstr = GET_STR(fsname, isCopy); PTRACE(1, "jni:Restore_getDumpStatus() entry"); if (-1 == get_dump_status(CTX, cstr, jarray2lst(env, dumps, "java/lang/String", String2charr), &statuslst)) { REL_STR(fsname, cstr, isCopy); ThrowEx(env); return (NULL); } REL_STR(fsname, cstr, isCopy); newArr = lst2jarray(env, statuslst, "java/lang/String", charr2String); lst_free_deep(statuslst); PTRACE(1, "jni:Restore_getDumpStatus() done"); return (newArr); }
samrpc_result_t * samrpc_get_dump_status_4_svr( string_strlst_arg_t *arg, struct svc_req *req /* ARGSUSED */ ) { int ret = -1; sqm_lst_t *lst = NULL; Trace(TR_DEBUG, "Get dump status for fsname[%s]", arg->str); /* free previous result */ xdr_free(xdr_samrpc_result_t, (char *)&rpc_result); SAMRPC_CHECK_TIMESTAMP(arg->ctx->handle->timestamp); Trace(TR_DEBUG, "Calling native library to get dumps status"); /* set the tail on the list received over RPC */ SET_LIST_TAIL(arg->strlst); ret = get_dump_status(arg->ctx, arg->str, arg->strlst, &lst); SAMRPC_SET_RESULT(ret, SAM_STRING_LIST, lst); Trace(TR_DEBUG, "Get dump status return [%d] with [%d] status", ret, (lst != NULL) ? lst->length : -1); return (&rpc_result); }
double pulse_newton_sim_voc(struct device *in) { printf_log("Looking for Voc\n"); double C = in->C; double clamp = 0.1; double step = 0.01; double e0; double e1; double i0; double i1; double deriv; double Rdrain = pulse_config.pulse_Rload + in->Rcontact; solve_all(in); i0 = get_I(in); e0 = fabs(i0 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); in->Vapplied += step; solve_all(in); i1 = get_I(in); e1 = fabs(i1 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); deriv = (e1 - e0) / step; step = -e1 / deriv; step = step / (1.0 + fabs(step / clamp)); in->Vapplied += step; int count = 0; int max = 200; do { e0 = e1; solve_all(in); i1 = get_I(in); e1 = fabs(i1 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); deriv = (e1 - e0) / step; step = -e1 / deriv; step = step / (1.0 + fabs(step / clamp)); in->Vapplied += step; if (get_dump_status(dump_print_text) == TRUE) { printf_log ("%d pulse voc find Voc Vapplied=%lf step=%le error=%le\n", count, in->Vapplied, step, e1); } if (count > max) break; count++; } while (e1 > 1e-12); double ret = in->Vapplied - C * (i1 - in->Ilast) / in->dt; return ret; }
EXPORT int light_dll_solve_lam_slice(struct simulation *sim,struct light *in,int lam) { if (get_dump_status(sim,dump_optics)==TRUE) { char one[100]; sprintf(one,"Solve light optical slice at %Lf nm\n",in->l[lam]*1e9); //printf("%s\n",one); waveprint(sim,one,in->l[lam]*1e9); } int i; gdouble complex n0=0.0+0.0*I; //complex gdouble r=0.0+0.0*I; complex gdouble t=0.0+0.0*I; gdouble complex beta0=0.0+0.0*I; complex gdouble Ep=in->sun_E[lam]+0.0*I; complex gdouble En=0.0+0.0*I; gdouble dx=in->x[1]-in->x[0]; for (i=0;i<in->points;i++) { n0=in->nbar[lam][i]; beta0=(2*PI*n0/in->l[lam]); if ((in->x[i]>in->device_start) &&(in->x[i]<in->device_ylen+in->device_start)) { beta0=creal(beta0)+I*0; } Ep=Ep*cexp(-beta0*dx*I); //r=in->r[lam][i]; t=in->t[lam][i]; //if ((in->n[lam][i]!=in->n[lam][i+1])||(in->alpha[lam][i]!=in->alpha[lam][i+1])) //{ // En=Ep*r; //} in->Ep[lam][i]=creal(Ep); in->Epz[lam][i]=cimag(Ep); in->En[lam][i]=creal(En); in->Enz[lam][i]=cimag(En); if ((in->n[lam][i]!=in->n[lam][i+1])||(in->alpha[lam][i]!=in->alpha[lam][i+1])) { Ep=Ep*t; } } return 0; }
void load_dos_file(struct dos *mydos, char *file) { #ifndef dos_bin double srh_r1 = 0.0; double srh_r2 = 0.0; double srh_r3 = 0.0; double srh_r4 = 0.0; double srh_c = 0.0; double w0; double n; #endif mydos->used = TRUE; mydos->used = TRUE; if (get_dump_status(dump_print_text) == TRUE) printf_log("%s %s\n", _("Loading file"), file); #ifdef dos_bin gzFile in; #else FILE *in; #endif /*FILE *rt; #ifdef dos_bin if (strcmp(file,"dosn.dat")==0) { rt = fopen("rtbinn.inp", "w"); }else { rt = fopen("rtbinp.inp", "w"); } #else if (strcmp(file,"dosn.dat")==0) { rt = fopen("rtnormn.inp", "w"); }else { rt = fopen("rtnormp.inp", "w"); } #endif */ #ifdef dos_bin int len; //in = fopen(file, "rb"); FILE *tl = fopen(file, "rb"); fseek(tl, -4, SEEK_END); if (fread((char *)&len, 4, 1, tl) == 0) { ewe("Error in reading file\n"); } //fscanf(tl,"%x",&a);//=ftell(in); fclose(tl); //printf("here '%ld'\n",len); //getchar(); in = gzopen(file, "rb"); if (in == Z_NULL) { ewe(_("DOS file not found\n")); } //fseek(in, 0, SEEK_END); //len=ftell(in); //fseek(in, 0, SEEK_SET); //long moved=gzseek(in, 0, SEEK_END); //len = (long)gztell(in); //z_off_t fileSize //printf("here %ld %s %ld %ld\n",len,file,moved,in); //getchar(); //gzseek(in, 0, SEEK_SET); int buf_len = len / sizeof(double); double *buf = (double *)malloc(sizeof(double) * buf_len); int buf_pos = 0; gzread(in, (char *)buf, len); gzclose(in); #else in = fopen(file, "r"); if (in == NULL) { ewe(_("DoS n file not found\n")); } #endif int t = 0; int x = 0; int srh_band = 0; #ifdef dos_bin mydos->xlen = (int)buf[buf_pos++]; mydos->tlen = (int)buf[buf_pos++]; mydos->srh_bands = (int)buf[buf_pos++]; mydos->config.epsilonr = buf[buf_pos++]; mydos->config.doping = buf[buf_pos++]; mydos->config.mu = buf[buf_pos++]; mydos->config.srh_vth = buf[buf_pos++]; mydos->config.srh_sigman = buf[buf_pos++]; mydos->config.srh_sigmap = buf[buf_pos++]; mydos->config.Nc = buf[buf_pos++]; mydos->config.Nv = buf[buf_pos++]; mydos->config.Eg = buf[buf_pos++]; mydos->config.Xi = buf[buf_pos++]; mydos->config.pl_fe_fh = buf[buf_pos++]; mydos->config.pl_trap = buf[buf_pos++]; mydos->config.pl_recom = buf[buf_pos++]; mydos->config.pl_enabled = (int)buf[buf_pos++]; mydos->config.B = buf[buf_pos++]; #else fscanf(in, "%d %d %d %le %le %le %le %le %le %le %le %le %le %le %le %le %d %le\n", &(mydos->xlen), &(mydos->tlen), &(mydos->srh_bands), &(mydos->config.epsilonr), &(mydos->config.doping), &(mydos->config.mu), &(mydos->config.srh_vth), &(mydos->config.srh_sigman), &(mydos->config.srh_sigmap), &(mydos->config.Nc), &(mydos->config.Nv), &(mydos->config.Eg), &(mydos->config.Xi), &(mydos->config.pl_fe_fh), &(mydos->config.pl_trap), &(mydos->config.pl_recom), &(mydos->config.pl_enabled), &(mydos->config.B)); #endif //fprintf(rt,"%d %d %d %lf %le %le %le %le %le %le\n",(mydos->xlen),(mydos->tlen),(mydos->srh_bands),(mydos->config.sigma),(mydos->config.mu),(mydos->config.srh_vth),(mydos->config.srh_sigman),(mydos->config.srh_sigmap),(mydos->config.Nc),(mydos->config.Nv)); double xsteps = mydos->xlen; double tsteps = mydos->tlen; mydos->x = (double *)malloc(sizeof(double) * (int)xsteps); mydos->t = (double *)malloc(sizeof(double) * (int)tsteps); mydos->srh_E = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_den = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r1 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r2 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r3 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r4 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_c = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->w = (double **)malloc(sizeof(double **) * (int)mydos->tlen); mydos->c = (double **)malloc(sizeof(double *) * (int)mydos->tlen); for (t = 0; t < tsteps; t++) { mydos->c[t] = (double *)malloc(sizeof(double) * (int)xsteps); mydos->w[t] = (double *)malloc(sizeof(double) * (int)xsteps); mydos->srh_r1[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r2[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r3[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r4[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_c[t] = (double **)malloc(sizeof(double *) * (int)xsteps); for (x = 0; x < xsteps; x++) { mydos->srh_r1[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r2[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r3[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r4[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_c[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); } } for (x = 0; x < xsteps; x++) { #ifdef dos_bin mydos->x[x] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->x[x])); #endif //fprintf(rt,"%le\n",(mydos->x[x])); } for (t = 0; t < tsteps; t++) { #ifdef dos_bin mydos->t[t] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->t[t])); #endif //fprintf(rt,"%le\n",(mydos->t[t])); } for (srh_band = 0; srh_band < (mydos->srh_bands); srh_band++) { #ifdef dos_bin mydos->srh_E[srh_band] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->srh_E[srh_band])); #endif //fprintf(rt,"%le\n",(mydos->srh_E[srh_band])); } for (srh_band = 0; srh_band < (mydos->srh_bands); srh_band++) { #ifdef dos_bin mydos->srh_den[srh_band] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->srh_den[srh_band])); #endif //fprintf(rt,"%le\n",(mydos->srh_den[srh_band])); } for (t = 0; t < tsteps; t++) { for (x = 0; x < xsteps; x++) { #ifdef dos_bin mydos->c[t][x] = buf[buf_pos++]; mydos->w[t][x] = buf[buf_pos++]; #else fscanf(in, "%le %le ", &n, &w0); mydos->c[t][x] = n; mydos->w[t][x] = w0; #endif //fprintf(rt,"%.20le %.20le ",mydos->c[t][x],mydos->w[t][x]); for (srh_band = 0; srh_band < mydos->srh_bands; srh_band++) { #ifdef dos_bin mydos->srh_r1[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r2[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r3[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r4[t][x][srh_band] = buf[buf_pos++]; mydos->srh_c[t][x][srh_band] = buf[buf_pos++]; //printf("%le\n",mydos->srh_c[t][x][srh_band]); #else fscanf(in, "%le %le %le %le %le ", &srh_r1, &srh_r2, &srh_r3, &srh_r4, &srh_c); mydos->srh_r1[t][x][srh_band] = srh_r1; mydos->srh_r2[t][x][srh_band] = srh_r2; mydos->srh_r3[t][x][srh_band] = srh_r3; mydos->srh_r4[t][x][srh_band] = srh_r4; mydos->srh_c[t][x][srh_band] = srh_c; #endif //fprintf(rt,"%.20le %.20le %.20le %.20le %.20le",mydos->srh_r1[t][x][srh_band],mydos->srh_r2[t][x][srh_band],mydos->srh_r3[t][x][srh_band],mydos->srh_r4[t][x][srh_band],mydos->srh_c[t][x][srh_band]); } //fprintf(rt,"\n"); } } #ifdef dos_bin free(buf); #else fclose(in); #endif //fclose(rt); }
int run_simulation(struct simulation *sim) { struct device cell; log_clear(sim); printf_log(sim,_("Run_simulation\n")); device_init(&cell); cell.onlypos=FALSE; dump_init(sim,&cell); set_dump_status(sim,dump_stop_plot, FALSE); set_dump_status(sim,dump_print_text, TRUE); char temp[1000]; cell.kl_in_newton=FALSE; //if (strcmp(outputpath,"")!=0) strcpy(get_output_path(sim),outputpath); //if (strcmp(inputpath,"")!=0) strcpy(get_input_path(sim),inputpath); dump_load_config(sim,&cell); int i; int z; int x; int y; join_path(2,temp,get_output_path(sim),"error.dat"); remove(temp); join_path(2,temp,get_output_path(sim),"equilibrium"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"snapshots"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"light_dump"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"dynamic"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"frequency"); remove_dir(sim,temp); load_config(sim,&cell); if (strcmp(sim->force_sim_mode,"")!=0) { strcpy(cell.simmode,sim->force_sim_mode); } if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { solver_init(sim,cell.solver_name); newton_init(sim,cell.newton_name); printf_log(sim,_("Loading DoS for %d layers\n"),cell.my_epitaxy.electrical_layers); char tempn[100]; char tempp[100]; i=0; for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_init(&cell,i); printf_log(sim,"Load DoS %d/%d\n",i,cell.my_epitaxy.electrical_layers); sprintf(tempn,"%s_dosn.dat",cell.my_epitaxy.dos_file[i]); sprintf(tempp,"%s_dosp.dat",cell.my_epitaxy.dos_file[i]); load_dos(sim,&cell,tempn,tempp,i); } device_alloc_traps(&cell); if (get_dump_status(sim,dump_write_converge)==TRUE) { sim->converge = fopena(get_output_path(sim),"converge.dat","w"); fclose(sim->converge); sim->tconverge=fopena(get_output_path(sim),"tconverge.dat","w"); fclose(sim->tconverge); } mesh_cal_layer_widths(&cell); long double depth=0.0; long double percent=0.0; long double value=0.0; for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { depth=cell.ymesh[y]-cell.layer_start[cell.imat[z][x][y]]; percent=depth/cell.layer_width[cell.imat[z][x][y]]; cell.Nad[z][x][y]=get_dos_doping_start(&cell,cell.imat[z][x][y])+(get_dos_doping_stop(&cell,cell.imat[z][x][y])-get_dos_doping_start(&cell,cell.imat[z][x][y]))*percent; } } } init_mat_arrays(&cell); for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { cell.phi[z][x][y]=0.0; cell.R[z][x][y]=0.0; cell.n[z][x][y]=0.0; } } } contacts_load(sim,&cell); cell.C=cell.xlen*cell.zlen*epsilon0*cell.epsilonr[0][0][0]/(cell.ylen+cell.other_layers); if (get_dump_status(sim,dump_print_text)==TRUE) printf_log(sim,"C=%Le\n",cell.C); cell.A=cell.xlen*cell.zlen; cell.Vol=cell.xlen*cell.zlen*cell.ylen; ///////////////////////light model char old_model[100]; gdouble old_Psun=0.0; old_Psun=light_get_sun(&cell.mylight); light_init(&cell.mylight); light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]); light_load_config(sim,&cell.mylight); if (cell.led_on==TRUE) { strcpy(old_model,cell.mylight.mode); strcpy(cell.mylight.mode,"ray"); } light_load_dlls(sim,&cell.mylight); light_setup_ray(sim,&cell,&cell.mylight); if (cell.led_on==TRUE) { cell.mylight.force_update=TRUE; light_set_sun(&(cell.mylight),1.0); light_set_sun_delta_at_wavelength(&(cell.mylight),cell.led_wavelength); light_solve_all(sim,&(cell.mylight)); cell.mylight.force_update=FALSE; strcpy(cell.mylight.mode,old_model); light_set_sun(&(cell.mylight),old_Psun); light_free_dlls(sim,&cell.mylight); light_load_dlls(sim,&cell.mylight); } /////////////////////// //update_arrays(&cell); contact_set_all_voltages(sim,&cell,0.0); get_initial(sim,&cell); remesh_shrink(&cell); if (cell.math_enable_pos_solver==TRUE) { for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { solve_pos(sim,&cell,z,x); } } } time_init(sim,&cell); cell.N=0; cell.M=0; solver_realloc(sim,&cell); plot_open(sim); cell.go_time=FALSE; plot_now(sim,"plot"); //set_solver_dump_every_matrix(1); find_n0(sim,&cell); //set_solver_dump_every_matrix(0); draw_gaus(&cell); if (cell.onlypos==TRUE) { join_path(2,temp,get_output_path(sim),"equilibrium"); dump_1d_slice(sim,&cell,temp); device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); return 0; } } //Load the dll if (is_domain(cell.simmode)!=0) { char gussed_full_mode[200]; if (guess_whole_sim_name(sim,gussed_full_mode,get_input_path(sim),cell.simmode)==0) { printf_log(sim,"I guess we are using running %s\n",gussed_full_mode); strcpy(cell.simmode,gussed_full_mode); }else { ewe(sim,"I could not guess which simulation to run from the mode %s\n",cell.simmode); } } run_electrical_dll(sim,&cell,strextract_domain(cell.simmode)); if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); plot_close(sim); for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_free(&cell,i); } solver_free_memory(sim,&cell); newton_interface_free(sim); light_free(sim,&cell.mylight); } return cell.odes; }
void dump_write_to_disk(struct simulation *sim,struct device* in) { char temp[200]; char postfix[100]; char snapshots_dir[PATH_MAX]; char out_dir[PATH_MAX]; char slice_info_file[PATH_MAX]; char snapshot_dir[PATH_MAX]; char sim_name[PATH_MAX]; strextract_name(sim_name,in->simmode); sprintf(snapshot_dir,"snapshots"); int dumped=FALSE; FILE* out; struct stat st = {0}; sprintf(postfix,"%d",dump_number); if ((get_dump_status(sim,dump_pl)==TRUE)||(get_dump_status(sim,dump_energy_slice_switch)==TRUE)||(get_dump_status(sim,dump_1d_slices)==TRUE)||(get_dump_status(sim,dump_optical_probe_spectrum)==TRUE)) { join_path(2,snapshots_dir,get_output_path(sim),snapshot_dir); if (stat(snapshots_dir, &st) == -1) { mkdir(snapshots_dir, 0700); } join_path(2,temp,snapshots_dir,"snapshots.inp"); out=fopen(temp,"w"); fprintf(out,"#end"); fclose(out); join_path(2,out_dir,snapshots_dir,postfix); if (stat(out_dir, &st) == -1) { mkdir(out_dir, 0700); } join_path(2,slice_info_file,out_dir,"snapshot_info.dat"); out=fopen(slice_info_file,"w"); if (out!=NULL) { fprintf(out,"#dump_voltage\n"); fprintf(out,"%Lf\n",get_equiv_V(sim,in)); fprintf(out,"#dump_time\n"); fprintf(out,"%Lf\n",in->time); fprintf(out,"#ver\n"); fprintf(out,"1.0\n"); fprintf(out,"#end\n"); fclose(out); }else { ewe(sim,"Can't write to file %s\n",slice_info_file); } } if (get_dump_status(sim,dump_optical_probe_spectrum)==TRUE) { dump_probe_spectrum(sim,in,out_dir,dump_number); dumped=TRUE; } if (get_dump_status(sim,dump_1d_slices)==TRUE) { dump_1d_slice(sim,in,out_dir); dump_device_map(out_dir,in); dumped=TRUE; } if (get_dump_status(sim,dump_energy_slice_switch)==TRUE) { dump_energy_slice(out_dir,in); dumped=TRUE; } if (get_dump_status(sim,dump_pl)==TRUE) { exp_cal_emission(sim,dump_number,in); dumped=TRUE; } if (dumped==TRUE) { dump_number++; } }
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); } }
void dump_dynamic_init(struct dynamic_store *store, struct device *in) { int i = 0; if (get_dump_status(dump_dynamic) == TRUE) { inter_init(&(store->charge_change)); inter_init(&(store->jout)); inter_init(&(store->jn_avg)); inter_init(&(store->jp_avg)); inter_init(&(store->dynamic_jn)); inter_init(&(store->dynamic_jp)); inter_init(&(store->jnout_mid)); inter_init(&(store->jpout_mid)); inter_init(&(store->iout)); inter_init(&(store->iout_left)); inter_init(&(store->iout_right)); inter_init(&(store->gexout)); inter_init(&(store->ntrap)); inter_init(&(store->ptrap)); inter_init(&(store->ntrap_delta_out)); inter_init(&(store->ptrap_delta_out)); inter_init(&(store->nfree)); inter_init(&(store->pfree)); inter_init(&(store->nfree_delta_out)); inter_init(&(store->pfree_delta_out)); inter_init(&(store->Rnpout)); inter_init(&(store->nfree_to_ptrap)); inter_init(&(store->pfree_to_ntrap)); inter_init(&(store->Rnout)); inter_init(&(store->Rpout)); inter_init(&(store->nrelax_out)); inter_init(&(store->prelax_out)); inter_init(&(store->tpc_mue)); inter_init(&(store->tpc_muh)); inter_init(&(store->tpc_mu_avg)); inter_init(&(store->tpc_filledn)); inter_init(&(store->tpc_filledp)); inter_init(&(store->dynamic_np)); inter_init(&(store->only_n)); inter_init(&(store->only_p)); inter_init(&(store->E_field)); inter_init(&(store->dynamic_Vapplied)); inter_init(&(store->dynamic_charge_tot)); inter_init(&(store->dynamic_pl)); inter_init(&(store->dynamic_jn_drift)); inter_init(&(store->dynamic_jn_diffusion)); inter_init(&(store->dynamic_jp_drift)); inter_init(&(store->dynamic_jp_diffusion)); inter_init(&(store->dynamic_qe)); inter_init(&(store->srh_n_r1)); inter_init(&(store->srh_n_r2)); inter_init(&(store->srh_n_r3)); inter_init(&(store->srh_n_r4)); inter_init(&(store->srh_p_r1)); inter_init(&(store->srh_p_r2)); inter_init(&(store->srh_p_r3)); inter_init(&(store->srh_p_r4)); inter_init(&(store->band_bend)); store->band_snapshot = malloc(sizeof(double) * in->ymeshpoints); for (i = 0; i < in->ymeshpoints; i++) { store->band_snapshot[i] = in->phi[i]; } } }
void init_dump(struct simulation *sim,struct device *in) { struct buffer buf; char out_dir[400]; char name[400]; if (get_dump_status(sim,dump_iodump)==TRUE) { strcpy(out_dir,""); buffer_init(&buf); buffer_malloc(&buf); sprintf(name,"%s","init_Fi.dat"); buf.y_mul=1.0; buf.x_mul=1e9; strcpy(buf.title,_("Equilibrium Fermi-level - position")); strcpy(buf.type,_("xy")); strcpy(buf.x_label,_("Position")); strcpy(buf.y_label,_("Fi")); strcpy(buf.x_units,_("nm")); strcpy(buf.y_units,_("eV")); strcpy(buf.section_one,_("1D position space output")); strcpy(buf.section_two,_("Transport")); buf.logscale_x=0; buf.logscale_y=0; buf.time=in->time; buf.Vexternal=0.0; buffer_add_info(&buf); buffer_add_3d_device_data(&buf,in, in->Fi); buffer_dump_path(out_dir,name,&buf); buffer_free(&buf); buffer_malloc(&buf); sprintf(name,"%s","init_Ec.dat"); buf.y_mul=1.0; buf.x_mul=1e9; strcpy(buf.title,_("LUMO - position")); strcpy(buf.type,_("xy")); strcpy(buf.x_label,_("Position")); strcpy(buf.y_label,_("E_{c}")); strcpy(buf.x_units,_("nm")); strcpy(buf.y_units,_("eV")); strcpy(buf.section_one,_("1D position space output")); strcpy(buf.section_two,_("Transport")); buf.logscale_x=0; buf.logscale_y=0; buf.time=in->time; buf.Vexternal=0.0; buffer_add_info(&buf); buffer_add_3d_device_data(&buf,in, in->Ec); buffer_dump_path(out_dir,name,&buf); buffer_free(&buf); buffer_malloc(&buf); sprintf(name,"%s","init_Ev.dat"); buf.y_mul=1.0; buf.x_mul=1e9; strcpy(buf.title,_("H**O - position")); strcpy(buf.type,_("xy")); strcpy(buf.x_label,_("Position")); strcpy(buf.y_label,_("E_{v}")); strcpy(buf.x_units,_("nm")); strcpy(buf.y_units,_("eV")); strcpy(buf.section_one,_("1D position space output")); strcpy(buf.section_two,_("Transport")); buf.logscale_x=0; buf.logscale_y=0; buf.time=in->time; buf.Vexternal=0.0; buffer_add_info(&buf); buffer_add_3d_device_data(&buf,in, in->Ev); buffer_dump_path(out_dir,name,&buf); buffer_free(&buf); buffer_malloc(&buf); sprintf(name,"%s","init_n.dat"); buf.y_mul=1.0; buf.x_mul=1e9; strcpy(buf.title,_("Electron density - position")); strcpy(buf.type,_("xy")); strcpy(buf.x_label,_("Position")); strcpy(buf.y_label,_("n")); strcpy(buf.x_units,_("nm")); strcpy(buf.y_units,_("m^{-3}")); strcpy(buf.section_one,_("1D position space output")); strcpy(buf.section_two,_("Transport")); buf.logscale_x=0; buf.logscale_y=0; buf.time=in->time; buf.Vexternal=0.0; buffer_add_info(&buf); buffer_add_3d_device_data(&buf,in, in->n); buffer_dump_path(out_dir,name,&buf); buffer_free(&buf); buffer_malloc(&buf); sprintf(name,"%s","init_p.dat"); buf.y_mul=1.0; buf.x_mul=1e9; strcpy(buf.title,_("Hole density - position")); strcpy(buf.type,_("xy")); strcpy(buf.x_label,_("Position")); strcpy(buf.y_label,_("n")); strcpy(buf.x_units,_("nm")); strcpy(buf.y_units,_("m^{-3}")); strcpy(buf.section_one,_("1D position space output")); strcpy(buf.section_two,_("Transport")); buf.logscale_x=0; buf.logscale_y=0; buf.time=in->time; buf.Vexternal=0.0; buffer_add_info(&buf); buffer_add_3d_device_data(&buf,in, in->p); buffer_dump_path(out_dir,name,&buf); buffer_free(&buf); } }
void get_initial(struct simulation *sim,struct device *in) { int i; int z; int x; int y; gdouble Ef=0.0; gdouble phi_ramp=0.0; gdouble Eg=0.0; gdouble Xi=0.0; gdouble charge_left=0.0; gdouble charge_right=0.0; gdouble top_l=0.0; gdouble top_r=0.0; Ef=0.0; phi_ramp=0.0; Eg=in->Eg[0][0][0]; Xi=in->Xi[0][0][0]; charge_left=in->lcharge; charge_right=in->rcharge; top_l=0.0; top_r=0.0; if (in->interfaceleft==TRUE) { top_l=in->phibleft-Eg; }else { if (in->lr_pcontact==LEFT) { top_l=get_top_from_p(in,charge_left,in->Te[0][0][0],in->imat[0][0][0]); }else { top_l= -(in->Eg[0][0][0]+get_top_from_n(in,charge_left,in->Te[0][0][0],in->imat[0][0][0])); } } if (in->interfaceright==TRUE) { top_r= -in->phibright; }else { if (in->lr_pcontact==LEFT) { top_r=get_top_from_n(in,charge_right,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); }else { top_r= -(Eg+get_top_from_p(in,charge_right,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1])); } } if (get_dump_status(sim,dump_info_text)==TRUE) { printf_log(sim,"check1= %Le %Le\n",get_p_den(in,top_l,in->Te[0][0][0],in->imat[0][0][0]),charge_left); printf_log(sim,"check2= %Le %Le\n",get_n_den(in,top_r,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]),charge_right); } gdouble delta_phi=top_l+top_r+in->Eg[0][0][0]+in->Xi[0][0][0]-in->Xi[0][0][in->ymeshpoints-1]; gdouble test_l= -in->Xi[0][0][0]+top_r; gdouble test_r= -in->Xi[0][0][0]-in->Eg[0][0][0]-top_l; in->vbi=delta_phi; if (get_dump_status(sim,dump_print_text)==TRUE) { printf_log(sim,"delta=%Le\n",delta_phi); printf_log(sim,">>>>top_l= %Le\n",top_l+Eg); printf_log(sim,">>>>top_r= %Le\n",-top_r); printf_log(sim,"left= %Le right = %Le %Le %Le\n",test_l,test_r,test_r-test_l,delta_phi); printf_log(sim,"%Le %Le %Le %Le %Le\n",top_l,top_r,Eg,delta_phi,in->phi[0][0][0]); } Ef= -(top_l+Xi+Eg); gdouble Lp=get_p_den(in,(-in->Xi[0][0][0]-in->phi[0][0][0]-Eg)-Ef,in->Th[0][0][0],in->imat[0][0][0]); gdouble Ln=get_n_den(in,Ef-(-in->Xi[0][0][0]-in->phi[0][0][0]),in->Te[0][0][0],in->imat[0][0][0]); gdouble Rp=get_p_den(in,(-in->Xi[0][0][in->ymeshpoints-1]-delta_phi-Eg)-Ef,in->Th[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); gdouble Rn=get_n_den(in,Ef-(-in->Xi[0][0][in->ymeshpoints-1]-delta_phi),in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); in->l_electrons=Ln; in->l_holes=Lp; in->r_electrons=Rn; in->r_holes=Rp; if (get_dump_status(sim,dump_built_in_voltage)==TRUE) { printf_log(sim,"Ef=%Le\n",Ef); printf_log(sim,"Holes on left contact = %Le\n", Lp); printf_log(sim,"Electrons on left contact = %Le\n", Ln); printf_log(sim,"Holes on right contact = %Le\n", Rp); printf_log(sim,"Electrons on right contact = %Le\n", Rn); FILE *contacts=fopena(get_output_path(sim),"initial.dat","w"); fprintf (contacts,"#left_holes\n"); fprintf (contacts,"%Le\n", Lp); fprintf (contacts,"#left_electrons\n"); fprintf (contacts,"%Le\n", Ln); fprintf (contacts,"#right_holes\n"); fprintf (contacts,"%Le\n", Rp); fprintf (contacts,"#right_electrons\n"); fprintf (contacts,"%Le\n", Rn); fprintf (contacts,"#Vbi\n"); fprintf (contacts,"%Le\n", in->vbi); fprintf (contacts,"#end\n"); fclose(contacts); } int band; for (z=0;z<in->zmeshpoints;z++) { for (x=0;x<in->xmeshpoints;x++) { for (y=0;y<in->ymeshpoints;y++) { phi_ramp=delta_phi*(in->ymesh[y]/in->ymesh[in->ymeshpoints-1]); in->Fi[z][x][y]=Ef; in->Fn[z][x][y]=Ef; in->Fp[z][x][y]=Ef; in->phi[z][x][y]=phi_ramp; in->x[z][x][y]=in->phi[z][x][y]+in->Fn[z][x][y]; in->xp[z][x][y]= -(in->phi[z][x][y]+in->Fp[z][x][y]); in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; if (in->Ec[z][x][y]<in->Fi[z][x][y]) { in->phi[z][x][y]= -(in->Fi[z][x][y]+in->Xi[z][x][y]); in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; } in->Ev[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]; if (in->Ev[z][x][y]>in->Fi[z][x][y]) { in->phi[z][x][y]= -(in->Fi[z][x][y]+in->Xi[z][x][y]+in->Eg[z][x][y]); in->Ev[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]; in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; } gdouble t=in->Fi[z][x][y]-in->Ec[z][x][y]; gdouble tp=in->Ev[z][x][y]-in->Fi[z][x][y]; in->n[z][x][y]=in->Nc[z][x][y]*exp(((t)*Q)/(kb*in->Te[z][x][y])); in->p[z][x][y]=in->Nv[z][x][y]*exp(((tp)*Q)/(kb*in->Th[z][x][y])); //printf("%Le %Le\n",t,tp); //getchar(); in->mun[z][x][y]=get_n_mu(in,in->imat[z][x][y]); in->mup[z][x][y]=get_p_mu(in,in->imat[z][x][y]); for (band=0;band<in->srh_bands;band++) { in->Fnt[z][x][y][band]= -in->phi[z][x][y]-in->Xi[z][x][y]+dos_srh_get_fermi_n(in,in->n[z][x][y], in->p[z][x][y],band,in->imat[z][x][y],in->Te[z][x][y]); in->Fpt[z][x][y][band]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]-dos_srh_get_fermi_p(in,in->n[z][x][y], in->p[z][x][y],band,in->imat[z][x][y],in->Th[z][x][y]); in->xt[z][x][y][band]=in->phi[z][x][y]+in->Fnt[z][x][y][band]; in->nt[z][x][y][band]=get_n_pop_srh(sim,in,in->xt[z][x][y][band]+in->tt[z][x][y],in->Te[z][x][y],band,in->imat[z][x][y]); in->dnt[z][x][y][band]=get_dn_pop_srh(sim,in,in->xt[z][x][y][band]+in->tt[z][x][y],in->Te[z][x][y],band,in->imat[z][x][y]); in->xpt[z][x][y][band]= -(in->phi[z][x][y]+in->Fpt[z][x][y][band]); in->pt[z][x][y][band]=get_p_pop_srh(sim,in,in->xpt[z][x][y][band]-in->tpt[z][x][y],in->Th[z][x][y],band,in->imat[z][x][y]); in->dpt[z][x][y][band]=get_dp_pop_srh(sim,in,in->xpt[z][x][y][band]-in->tpt[z][x][y],in->Th[z][x][y],band,in->imat[z][x][y]); } } } } in->Vl=0.0; in->Vr=delta_phi; in->Vbi=delta_phi; init_dump(sim,in); //getchar(); if (in->stoppoint==1) exit(0); return; }
gdouble newton_sim_voc(struct simulation *sim, struct device *in) { printf_log(sim,"Looking for Voc\n"); gdouble C=in->C; gdouble clamp=0.1; gdouble step=0.01; gdouble e0; gdouble e1; gdouble i0; gdouble i1; gdouble deriv; gdouble Rdrain=in->Rload+in->Rcontact; gdouble Vapplied=0.0; gdouble Vapplied_last=0.0; Vapplied=contact_get_voltage(sim,in,0); Vapplied_last=contact_get_voltage_last(sim,in,0); solve_all(sim,in); i0=get_I(in); e0=fabs(i0+Vapplied*(1.0/in->Rshunt-1.0/Rdrain)); Vapplied+=step; contact_set_voltage(sim,in,0,Vapplied); solve_all(sim,in); i1=get_I(in); e1=fabs(i1+Vapplied*(1.0/in->Rshunt-1.0/Rdrain)); deriv=(e1-e0)/step; step=-e1/deriv; step=step/(1.0+fabs(step/clamp)); Vapplied+=step; contact_set_voltage(sim,in,0,Vapplied); int count=0; int max=200; do { e0=e1; solve_all(sim,in); i1=get_I(in); e1=fabs(i1+Vapplied*(1.0/in->Rshunt-1.0/Rdrain)); deriv=(e1-e0)/step; step=-e1/deriv; step=step/(1.0+fabs(step/clamp)); Vapplied+=step; contact_set_voltage(sim,in,0,Vapplied); if (get_dump_status(sim,dump_print_text)==TRUE) { printf_log(sim,"%d voc find Voc Vapplied=%Lf step=%Le error=%Le\n",count,Vapplied,step,e1); } if (count>max) break; count++; }while(e1>1e-12); gdouble ret=Vapplied-C*(i1-in->Ilast)/in->dt; return ret; }
int solve_cur(struct device *in) { double error; int ittr = 0; if (get_dump_status(dump_print_newtonerror) == TRUE) { printf("Solve cur\n"); } #ifdef only only_update_thermal = FALSE; #endif //in->enable_back=FALSE; int stop = FALSE; int thermalrun = 0; double check[10]; int cpos = 0; int i = 0; //for (i=0;i<in->ymeshpoints;i++) //{ // printf("Rod ------- nt= %d %le\n",i,in->Gn[i]); //} do { fill_matrix(in); //dump_for_plot(in); //plot_now(in,"plot"); //solver_dump_matrix(in->M,in->N,in->Ti,in->Tj, in->Tx,in->b); //getchar(); if (in->stop == TRUE) { break; } solver(in->M, in->N, in->Ti, in->Tj, in->Tx, in->b); int propper = TRUE; update_solver_vars(in, TRUE); //printf("Going to clamp=%d\n",propper); //solver_dump_matrix(in->M,in->N,in->Ti,in->Tj, in->Tx,in->b); //printf("%d\n"); //getchar(); error = get_cur_error(in); //thermalrun++; if (thermalrun == 40) thermalrun = 0; //update(in); //getchar(); if (get_dump_status(dump_print_newtonerror) == TRUE) { printf("%d Cur error = %e %le I=%le", ittr, error, in->Vapplied, get_I(in)); printf("\n"); } in->last_error = error; in->last_ittr = ittr; ittr++; if (get_dump_status(dump_write_converge) == TRUE) { in->converge = fopena(in->outputpath, "converge.dat", "a"); fprintf(in->converge, "%e\n", error); fclose(in->converge); } stop = TRUE; if (ittr < in->max_electrical_itt) { if (error > in->min_cur_error) { stop = FALSE; } } if (ittr < in->newton_min_itt) { stop = FALSE; } if (in->newton_clever_exit == TRUE) { check[cpos] = error; cpos++; if (cpos > 10) { cpos = 0; } if (ittr >= in->newton_min_itt) { if ((check[0] < error) || (check[1] < error)) { stop = TRUE; } } } } while (stop == FALSE); in->newton_last_ittr = ittr; if (error > 1e-3) { printf_log ("warning: The solver has not converged very well.\n"); } //getchar(); if (get_dump_status(dump_newton) == TRUE) { dump_1d_slice(in, in->outputpath); } //plot_now(in,"plot"); //getchar(); in->odes += in->M; //getchar(); return 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(); }
int solve_pos(struct device *in) { if (get_dump_status(dump_iodump) == TRUE) printf_log("Solve pos\n"); int i; int N = in->ymeshpoints * 3 - 2; int M = in->ymeshpoints; int *Ti = malloc(N * sizeof(int)); int *Tj = malloc(N * sizeof(int)); double *Tx = malloc(N * sizeof(double)); double *b = malloc(M * sizeof(double)); double phil; double phic; double phir; double yl; double yc; double yr; double dyl; double dyr; double dyc = 0.0; int ittr = 0; int pos = 0; double error = 1000; double el = 0.0; double ec = 0.0; double er = 0.0; double e0 = 0.0; double e1 = 0.0; int pos_max_ittr = 250; int quit = FALSE; int adv_step = 0; int adv = FALSE; int band; double kTq = (in->Te[0] * kb / Q); do { if (in->interfaceleft == TRUE) { in->phi[0] = in->Vl; } if (in->interfaceright == TRUE) { in->phi[in->ymeshpoints - 1] = in->Vr; } pos = 0; for (i = 0; i < in->ymeshpoints; i++) { if (i == 0) { phil = in->Vl; el = in->epsilonr[0] * epsilon0; yl = in->ymesh[0] - (in->ymesh[1] - in->ymesh[0]); } else { el = in->epsilonr[i - 1] * epsilon0; phil = in->phi[i - 1]; yl = in->ymesh[i - 1]; } if (i == (in->ymeshpoints - 1)) { phir = in->Vr; er = in->epsilonr[i] * epsilon0; yr = in->ymesh[i] + (in->ymesh[i] - in->ymesh[i - 1]); } else { er = in->epsilonr[i + 1] * epsilon0; phir = in->phi[i + 1]; yr = in->ymesh[i + 1]; } yc = in->ymesh[i]; dyl = yc - yl; dyr = yr - yc; dyc = (dyl + dyr) / 2.0; ec = in->epsilonr[i] * epsilon0; e0 = (el + ec) / 2.0; e1 = (ec + er) / 2.0; phic = in->phi[i]; double dphidn = 0.0; if (adv == FALSE) { dphidn = (Q / (kb * in->Tl[i])) * in->Nc[i] * exp(((in->Fi[i] - (-in->phi[i] - in->Xi[i]))) / (kTq)); } else { dphidn = get_dn_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); } double dphidp = 0.0; if (adv == FALSE) { dphidp = -(Q / (kb * in->Tl[i])) * in->Nv[i] * exp((((-in->phi[i] - in->Xi[i] - in->Eg[i]) - in->Fi[i])) / (kTq)); } else { dphidp = -get_dp_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); } double dphil = e0 / dyl / dyc; double dphic = -(e0 / dyl / dyc + e1 / dyr / dyc); double dphir = e1 / dyr / dyc; double dphil_d = dphil; double dphic_d = dphic; double dphir_d = dphir; if (in->interfaceleft == TRUE) { if (i == 1) { dphil_d = 0.0; phil = in->Vl; } if (i == 0) { dphil_d = 0.0; dphic_d = 1e-6; dphir_d = 0.0; } } if (in->interfaceright == TRUE) { if (i == in->ymeshpoints - 2) { dphir_d = 0.0; phir = in->Vr; } if (i == in->ymeshpoints - 1) { dphil_d = 0.0; dphic_d = 1e-6; dphir_d = 0.0; } } double dphi = dphil * phil + dphic * phic + dphir * phir; dphic_d += -Q * (dphidn - dphidp); // just put in the _d to get it working again. //if (adv==TRUE) //{ // for (band=0;band<in->srh_bands;band++) // { // dphic_d+=(-q*(in->dnt[i][band]-in->dpt[i][band])); // } //} if (i != 0) { Ti[pos] = i; Tj[pos] = i - 1; Tx[pos] = dphil_d; pos++; } Ti[pos] = i; Tj[pos] = i; Tx[pos] = dphic_d; pos++; if (i != (in->ymeshpoints - 1)) { Ti[pos] = i; Tj[pos] = i + 1; Tx[pos] = dphir_d; pos++; } if ((in->interfaceleft == TRUE) && (i == 0)) { b[i] = -0.0; } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { b[i] = -0.0; } else { b[i] = -(dphi - Q * (in->n[i] - in->p[i] - in->Nad[i])); // if (adv == TRUE) { for (band = 0; band < in->srh_bands; band++) { b[i] += -(-Q * (in->nt[i][band] - in->pt[i][band])); } } } //in->n[i]=in->Nc[i]*exp(((in->Fi[i]-in->Ec[i])*q)/(kb*in->Tl[i])); } error = get_p_error(in, b); solver(M, N, Ti, Tj, Tx, b); for (i = 0; i < in->ymeshpoints; i++) { if ((in->interfaceleft == TRUE) && (i == 0)) { } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { } else { double update; //printf("%d\n",get_clamp_state()); double clamp_temp = 300.0; update = b[i] / (1.0 + fabs(b[i] / in->posclamp / (clamp_temp * kb / Q))); in->phi[i] += update; //printf("%le %le\n",i,b[i]); } } //getchar(); for (i = 0; i < in->ymeshpoints; i++) { in->Ec[i] = -in->phi[i] - in->Xi[i]; in->Ev[i] = -in->phi[i] - in->Xi[i] - in->Eg[i]; if (adv == FALSE) { in->n[i] = in->Nc[i] * exp(((in->Fi[i] - in->Ec[i]) * Q) / (kb * in->Tl[i])); in->dn[i] = (Q / (kb * in->Tl[i])) * in->Nc[i] * exp((Q * (in->Fi[i] - in->Ec[i])) / (kb * in->Tl[i])); } else { in->n[i] = get_n_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); in->dn[i] = get_dn_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); } in->Fn[i] = in->Fi[i]; in->Fp[i] = in->Fi[i]; in->x[i] = in->phi[i] + in->Fn[i]; in->xp[i] = -(in->phi[i] + in->Fp[i]); if (adv == FALSE) { in->p[i] = in->Nv[i] * exp(((in->xp[i] - in->tp[i]) * Q) / (kb * in->Tl[i])); in->dp[i] = (Q / (kb * in->Tl[i])) * in->Nv[i] * exp(((in->xp[i] - in->tp[i]) * Q) / (kb * in->Tl[i])); } else { in->p[i] = get_p_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); in->dp[i] = get_dp_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); } for (band = 0; band < in->srh_bands; band++) { //printf("%lf %lf\n",in->xpt[i][band],in->Fpt[i][band]); //getchar(); in->Fnt[i][band] = -in->phi[i] - in->Xi[i] + dos_srh_get_fermi_n(in->n[i], in->p[i], band, in->imat[i], in->Te[i]); in->Fpt[i][band] = -in->phi[i] - in->Xi[i] - in->Eg[i] - dos_srh_get_fermi_p(in->n[i], in->p[i], band, in->imat[i], in->Th[i]); in->xt[i][band] = in->phi[i] + in->Fnt[i][band]; in->nt[i][band] = get_n_pop_srh(in->xt[i][band] + in->tt[i], in->Te[i], band, in->imat[i]); in->dnt[i][band] = get_dn_pop_srh(in->xt[i][band] + in->tt[i], in->Te[i], band, in->imat[i]); in->xpt[i][band] = -(in->phi[i] + in->Fpt[i][band]); in->pt[i][band] = get_p_pop_srh(in->xpt[i][band] - in->tpt[i], in->Th[i], band, in->imat[i]); in->dpt[i][band] = get_dp_pop_srh(in->xpt[i][band] - in->tpt[i], in->Th[i], band, in->imat[i]); } } update_arrays(in); in->xnl_left = in->x[0]; in->xpl_left = in->xp[0]; if (error < 1) { adv = TRUE; } //#ifdef print_newtonerror if (get_dump_status(dump_print_pos_error) == TRUE) printf_log("%d Pos error = %e %d\n", ittr, error, adv); //#endif #ifdef dump_converge /*in->converge=fopena(in->outputpath,"converge.dat","a"); fprintf(in->converge,"%e\n",error); fclose(in->converge); */ #endif //double N=2.0*pow(((2.0*pi*kb*in->Tl[0]*in->me[0]*m0)/(hp*hp)),1.5); //double test=N*exp((-3.000000e-03*Q)/(kb*in->Tl[0])); //printf("Check now %e %e\n",get_n_den(-3.000000e-03,in->Tl[0],in->me[0],in->dostype[0],dos_all),test); //getchar(); //getchar(); ittr++; if (adv == TRUE) { adv_step++; } if (ittr > pos_max_ittr) { quit = TRUE; } if ((error < min_pos_error) && (adv_step > 3)) { quit = TRUE; } } while (quit == FALSE); //getchar(); pos_dump(in); update_arrays(in); if (in->srh_sim == TRUE) { time_init(in); } in->odes += in->ymeshpoints; for (i = 0; i < in->ymeshpoints; i++) { in->nf_save[i] = in->n[i]; in->pf_save[i] = in->p[i]; in->nt_save[i] = 0.0; //in->nt[i]; in->pt_save[i] = 0.0; //in->pt[i]; } free(Ti); free(Tj); free(Tx); free(b); printf_log("Solved pos\n"); printf_log("Vl=%le Vr=%le phi_mid=%le\n", in->Vl, in->Vr, in->phi[in->ymeshpoints / 2]); return 0; }
void pos_dump(struct device *in) { if (get_dump_status(dump_first_guess) == TRUE) { char out_dir[1000]; join_path(2, out_dir, in->outputpath, "equilibrium"); struct buffer buf; buffer_init(&buf); char name[200]; int band = 0; int i = 0; FILE *out; out = fopena(in->outputpath, "first_guess.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e %e\n", in->ymesh[i], in->Fn[i], in->Fp[i]); } fclose(out); out = fopena(in->outputpath, "first_guess_Fi.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e\n", in->ymesh[i], in->Fi[i]); } fclose(out); buffer_malloc(&buf); sprintf(name, "%s%s", "first_guess_Ec", ".dat"); buf.y_mul = 1.0; buf.x_mul = 1e9; strcpy(buf.title, "LUMO energy - position"); strcpy(buf.type, "xy"); strcpy(buf.x_label, "Position"); strcpy(buf.y_label, "LUMO"); strcpy(buf.x_units, "nm"); strcpy(buf.y_units, "$E_{LUMO}$"); buf.logscale_x = 0; buf.logscale_y = 0; buffer_add_info(&buf); buffer_add_xy_data(&buf, in->ymesh, in->Ec, in->ymeshpoints); buffer_dump_path(out_dir, name, &buf); buffer_free(&buf); buffer_malloc(&buf); sprintf(name, "%s%s", "first_guess_Ev", ".dat"); buf.y_mul = 1.0; buf.x_mul = 1e9; strcpy(buf.title, "H**O energy - position"); strcpy(buf.type, "xy"); strcpy(buf.x_label, "Position"); strcpy(buf.y_label, "LUMO"); strcpy(buf.x_units, "nm"); strcpy(buf.y_units, "$E_{H**O}$"); buf.logscale_x = 0; buf.logscale_y = 0; buffer_add_info(&buf); buffer_add_xy_data(&buf, in->ymesh, in->Ev, in->ymeshpoints); buffer_dump_path(out_dir, name, &buf); buffer_free(&buf); out = fopena(in->outputpath, "first_guess_n.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e\n", in->ymesh[i], in->n[i]); } fclose(out); out = fopena(in->outputpath, "first_guess_p.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e\n", in->ymesh[i], in->p[i]); } fclose(out); out = fopena(in->outputpath, "first_guess_phi.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e\n", in->ymesh[i], in->phi[i]); } fclose(out); out = fopena(in->outputpath, "first_guess_np.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e %e %e\n", in->ymesh[i], in->n[i], in->p[i]); } fclose(out); out = fopena(in->outputpath, "first_guess_np_trap.dat", "w"); for (i = 0; i < in->ymeshpoints; i++) { fprintf(out, "%e ", in->ymesh[i]); for (band = 0; band < in->srh_bands; band++) { fprintf(out, "%e %e ", in->nt[i][band], in->pt[i][band]); } fprintf(out, "\n"); } fclose(out); } }
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); } }