Board::Board(QWidget *parent) : QFrame(parent) { is_game_on = false; clear_arrays(); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update_arrays())); }
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 fill_matrix(struct device *in) { //double offset=-0.5; int band = 0; update_arrays(in); //FILE *file_j =fopen("myj.dat","w"); //getchar(); double phil; double phic; double phir; double yl; double yc; double yr; double dyl; double dyr; double ddh = 0.0; //double dh; int pos = 0; double Ecl = 0.0; double Ecr = 0.0; double Ecc = 0.0; double Evl = 0.0; double Evr = 0.0; double Evc = 0.0; double Tel = 0.0; //double Tec=0.0; double Ter = 0.0; double Thl = 0.0; //double Thc=0.0; double Thr = 0.0; double xnr; double tnr; double xnl; double tnl; double xpr; double tpr; double xpl; double tpl; //double exl; //double exr; //double exc; //double Dexl; //double Dexc; //double Dexr; //double R; double epr; double epc; double epl; //double G; double Gn; double Gp; int i; double dJdxipc = 0.0; double dJpdxic = 0.0; double e0 = 0.0; double e1 = 0.0; double dphil = 0.0; double dphic = 0.0; double dphir = 0.0; double deriv = 0.0; //double kll=0.0; //double klc=0.0; //double klr=0.0; //double kl0=0.0; //double kl1=0.0; double one = 0.0; double one0_l = 0.0; double one0_r = 0.0; double Rtrapn = 0.0; double Rtrapp = 0.0; double dJdphil_leftl = 0.0; double dJdphil_leftc = 0.0; double dJpdphil_leftl = 0.0; double dJpdphil_leftc = 0.0; double dphil_left = 0.0; double dJdxil_leftc = 0.0; double dJpdxipl_leftc = 0.0; double dJdxic_rightc = 0.0; double dJpdxipc_rightc = 0.0; double dJpdphi_rightc = 0.0; double dJdphi_rightc = 0.0; double Bfree = 0.0; double nceq = 0.0; double pceq = 0.0; double Rfree = 0.0; double nc0_l = 0.0; //double dnc0_l=0.0; //double pc0_l=0.0; //double dpc0_l=0.0; double nc0_r = 0.0; //double dnc0_r=0.0; //double pc0_r=0.0; //double dpc0_r=0.0; double dJnldxil_l = 0.0; double dJnldxil_c = 0.0; double dJnrdxir_c = 0.0; double dJnrdxir_r = 0.0; double dJpldxipl_l = 0.0; double dJpldxipl_c = 0.0; double dJprdxipr_c = 0.0; double dJprdxipr_r = 0.0; double i0 = 0.0; double didv = 0.0; //not a function double diphic = 0.0; //could be a function double didxic = 0.0; double didxipc = 0.0; double didphir = 0.0; double didxir = 0.0; double didxipr = 0.0; //double dylh_left=0.0; //double dyrh_left=0.0; //double dncdphic=0.0; //double dpcdphic=0.0; if (in->kl_in_newton == FALSE) { if (in->interfaceleft == TRUE) { in->phi[0] = in->Vapplied; } } if (in->interfaceright == TRUE) { in->phi[in->ymeshpoints - 1] = in->Vr; } pos = 0; for (i = 0; i < in->ymeshpoints; i++) { if (i == 0) { // exl=0.0; // Dexl=in->Dex[0]; phil = in->Vapplied; yl = in->ymesh[0] - (in->ymesh[1] - in->ymesh[0]); // Tll=in->Tll; Tel = in->Tll; Thl = in->Tll; Ecl = -in->Xi[0] - phil; Evl = -in->Xi[0] - phil - in->Eg[0]; epl = in->epsilonr[0] * epsilon0; xnl = in->Fi[0]; tnl = in->Xi[0]; one = xnl + tnl; nl = get_n_den(one, Tel, in->imat[i]); dnl = get_dn_den(one, Tel, in->imat[i]); wnl = get_n_w(one, Tel, in->imat[i]); munl = in->mun[0]; xpl = -in->Fi[0]; tpl = in->Xi[0] + in->Eg[0]; one = xpl - tpl; pl = get_p_den(one, Thl, in->imat[i]); dpl = get_dp_den(one, Thl, in->imat[i]); wpl = get_p_w(one, Thl, in->imat[i]); mupl = in->mup[0]; //printf("left n= %e p= %e \n",nl,pl); // kll=in->kl[i]; } else { // Dexl=in->Dex[i-1]; // exl=in->ex[i-1]; phil = in->phi[i - 1]; yl = in->ymesh[i - 1]; // Tll=in->Tl[i-1]; Tel = in->Te[i - 1]; Thl = in->Th[i - 1]; Ecl = in->Ec[i - 1]; Evl = in->Ev[i - 1]; nl = in->n[i - 1]; dnl = in->dn[i - 1]; wnl = in->wn[i - 1]; wpl = in->wp[i - 1]; pl = in->p[i - 1]; dpl = in->dp[i - 1]; munl = in->mun[i - 1]; mupl = in->mup[i - 1]; epl = in->epsilonr[i - 1] * epsilon0; // kll=in->kl[i-1]; } Ecc = -in->Xi[i] - in->phi[i]; Evc = -in->Xi[i] - in->phi[i] - in->Eg[i]; if (i == (in->ymeshpoints - 1)) { // Dexr=in->Dex[i]; // exr=0.0; //phir=in->Vr; phir = in->Vr; yr = in->ymesh[i] + (in->ymesh[i] - in->ymesh[i - 1]); // Tlr=in->Tlr; Ter = in->Tlr; Thr = in->Tlr; Ecr = -in->Xi[i] - phir; Evr = -in->Xi[i] - phir - in->Eg[i]; xnr = in->Vr + in->Fi[i]; tnr = in->Xi[i]; one = xnr + tnr; nr = get_n_den(one, Ter, in->imat[i]); dnr = get_dn_den(one, Ter, in->imat[i]); wnr = get_n_w(one, Ter, in->imat[i]); xpr = -(in->Vr + in->Fi[i]); tpr = in->Xi[i] + in->Eg[i]; one = xpr - tpr; pr = get_p_den(one, Thr, in->imat[i]); dpr = get_dp_den(one, Thr, in->imat[i]); wpr = get_p_w(one, Thr, in->imat[i]); munr = in->mun[i]; mupr = in->mup[i]; //printf("right n= %e p= %e \n",nr,pr); epr = in->epsilonr[i] * epsilon0; // klr=in->kl[i]; } else { // Dexr=in->Dex[i+1]; // exr=in->ex[i+1]; phir = in->phi[i + 1]; yr = in->ymesh[i + 1]; // Tlr=in->Tl[i+1]; Ter = in->Te[i + 1]; Thr = in->Th[i + 1]; Ecr = in->Ec[i + 1]; Evr = in->Ev[i + 1]; nr = in->n[i + 1]; dnr = in->dn[i + 1]; wnr = in->wn[i + 1]; wpr = in->wp[i + 1]; pr = in->p[i + 1]; dpr = in->dp[i + 1]; munr = in->mun[i + 1]; mupr = in->mup[i + 1]; epr = in->epsilonr[i + 1] * epsilon0; // klr=in->kl[i+1]; } dJdxipc = 0.0; dJpdxic = 0.0; epc = in->epsilonr[i] * epsilon0; // exc=in->ex[i]; // Dexc=in->Dex[i]; yc = in->ymesh[i]; dyl = yc - yl; dyr = yr - yc; ddh = (dyl + dyr) / 2.0; double dylh = dyl / 2.0; double dyrh = dyr / 2.0; // dh=(dyl+dyr); phic = in->phi[i]; // Tlc=in->Tl[i]; // Tec=in->Te[i]; // Thc=in->Th[i]; munc = in->mun[i]; mupc = in->mup[i]; wnc = in->wn[i]; wpc = in->wp[i]; Dnl = munl * (2.0 / 3.0) * wnl / Q; Dpl = mupl * (2.0 / 3.0) * wpl / Q; Dnc = munc * (2.0 / 3.0) * wnc / Q; Dpc = mupc * (2.0 / 3.0) * wpc / Q; in->Dn[i] = Dnc; in->Dp[i] = Dnc; Dnr = munr * (2.0 / 3.0) * wnr / Q; Dpr = mupr * (2.0 / 3.0) * wpr / Q; Dnl = (Dnl + Dnc) / 2.0; Dnr = (Dnr + Dnc) / 2.0; Dpl = (Dpl + Dpc) / 2.0; Dpr = (Dpr + Dpc) / 2.0; munl = (munl + munc) / 2.0; munr = (munr + munc) / 2.0; mupl = (mupl + mupc) / 2.0; mupr = (mupr + mupc) / 2.0; nc = in->n[i]; pc = in->p[i]; dnc = in->dn[i]; dpc = in->dp[i]; // dncdphic=in->dndphi[i]; // dpcdphic=in->dpdphi[i]; Bfree = in->B[i]; nceq = in->nfequlib[i]; pceq = in->pfequlib[i]; Rfree = Bfree * (nc * pc - nceq * pceq); in->Rfree[i] = Rfree; //if (in->ymeshpoints*(1)+i==31) printf("Rod -- %d %le %le %le \n",in->ymeshpoints*(1)+i,Rfree,nceq,pceq); // klc=in->kl[i]; // R=in->R[i]; Gn = in->Gn[i]; Gp = in->Gp[i]; e0 = (epl + epc) / 2.0; e1 = (epc + epr) / 2.0; // kl0=(klc+kll)/2.0; // kl1=(klr+klc)/2.0; dphil = -e0 / dyl / ddh; dphic = e0 / dyl / ddh + e1 / dyr / ddh; dphir = -e1 / dyr / ddh; double dphil_d = dphil; double dphic_d = dphic; double dphir_d = dphir; //if (i==in->ymeshpoints-1) //{ //printf("%le\n",phir); // //} deriv = phil * dphil + phic * dphic + phir * dphir; dphidxic = Q * (dnc); dphidxipc = -Q * (dpc); if (((in->interfaceleft == TRUE) && (i == 0)) || ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1))) { dphidxic = 0.0; dphidxipc = 0.0; } if (in->ntrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { dphidntrap[band] = Q * (in->dnt[i][band]); if ((in->interfaceleft == TRUE) && (i == 0)) dphidntrap[band] = 0.0; if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) dphidntrap[band] = 0.0; } } if (in->ptrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { dphidptrap[band] = -Q * (in->dpt[i][band]); if ((in->interfaceleft == TRUE) && (i == 0)) dphidptrap[band] = 0.0; if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) dphidptrap[band] = 0.0; //dphidxipc+=-Q*(in->dpt[i]); } } // G=in->G[i]; xil = Q * 2.0 * (3.0 / 2.0) * (Ecc - Ecl) / ((wnc + wnl)); xir = Q * 2.0 * (3.0 / 2.0) * (Ecr - Ecc) / ((wnr + wnc)); //double dxil=-Q*2.0*(3.0/2.0)*(Ecc-Ecl)/pow((wnc+wnl),2.0); //double dxir=-Q*2.0*(3.0/2.0)*(Ecr-Ecc)/pow((wnr+wnc),2.0); xipl = Q * 2.0 * (3.0 / 2.0) * (Evc - Evl) / (wpc + wpl); xipr = Q * 2.0 * (3.0 / 2.0) * (Evr - Evc) / (wpr + wpc); dJdxil = 0.0; dJdxic = 0.0; dJdxir = 0.0; dJpdxipl = 0.0; dJpdxipc = 0.0; dJpdxipr = 0.0; dJdphil = 0.0; dJdphic = 0.0; dJdphir = 0.0; dJpdphil = 0.0; dJpdphic = 0.0; dJpdphir = 0.0; Jnl = (Dnl / dyl) * (B(-xil) * nc - B(xil) * nl); dJnldxil_l = -(Dnl / dyl) * (B(xil) * dnl); dJnldxil_c = (Dnl / dyl) * B(-xil) * dnc; double dJnldphi_l = -(munl / dyl) * (dB(-xil) * nc + dB(xil) * nl); double dJnldphi_c = (munl / dyl) * (dB(-xil) * nc + dB(xil) * nl); Jnr = (Dnr / dyr) * (B(-xir) * nr - B(xir) * nc); dJnrdxir_c = -(Dnr / dyr) * (B(xir) * dnc); dJnrdxir_r = (Dnr / dyr) * (B(-xir) * dnr); double dJnrdphi_c = (munr / dyr) * (-dB(-xir) * nr - dB(xir) * nc); double dJnrdphi_r = (munr / dyr) * (dB(-xir) * nr + dB(xir) * nc); Jpl = (Dpl / dyl) * (B(-xipl) * pl - B(xipl) * pc); dJpldxipl_l = (Dpl / dyl) * (B(-xipl) * dpl); dJpldxipl_c = -(Dpl / dyl) * B(xipl) * dpc; double dJpldphi_l = -((mupl) / dyl) * (dB(-xipl) * pl + dB(xipl) * pc); double dJpldphi_c = ((mupl) / dyl) * (dB(-xipl) * pl + dB(xipl) * pc); Jpr = (Dpr / dyr) * (B(-xipr) * pc - B(xipr) * pr); dJprdxipr_c = (Dpr / dyr) * (B(-xipr) * dpc); dJprdxipr_r = -(Dpr / dyr) * (B(xipr) * dpr); double dJprdphi_c = -(mupr / dyr) * (dB(-xipr) * pc + dB(xipr) * pr); double dJprdphi_r = (mupr / dyr) * (dB(-xipr) * pc + dB(xipr) * pr); if (i == 0) { //printf("%le %le %le %le\n",in->vl*(nc-nc0_l),Jnl,-in->vl*(pc-pc0_l),Jpl); //getchar(); in->Jnleft = Jnl; in->Jpleft = Jpl; } if (i == in->ymeshpoints - 1) { //printf("%le %le %le %le\n",in->vr*(nc-nc0_r),Jnr,in->vr*(pc-pc0_r),Jpr); in->Jnright = Jnr; in->Jpright = Jpr; } //printf("----------\n"); //printf("%le %le\n",Jnl,Jpl); //printf("%le %le\n",Jnr,Jpr); in->Jn[i] = Q * (Jnl + Jnr) / 2.0; in->Jp[i] = Q * (Jpl + Jpr) / 2.0; dJdxil += -dJnldxil_l / (dylh + dyrh); dJdxic += (-dJnldxil_c + dJnrdxir_c) / (dylh + dyrh); dJdxir += dJnrdxir_r / (dylh + dyrh); dJpdxipl += -dJpldxipl_l / (dylh + dyrh); dJpdxipc += (-dJpldxipl_c + dJprdxipr_c) / (dylh + dyrh); dJpdxipr += dJprdxipr_r / (dylh + dyrh); dJdphil += -dJnldphi_l / (dylh + dyrh); dJdphic += (-dJnldphi_c + dJnrdphi_c) / (dylh + dyrh); dJdphir += dJnrdphi_r / (dylh + dyrh); dJpdphil += -dJpldphi_l / (dylh + dyrh); dJpdphic += (-dJpldphi_c + dJprdphi_c) / (dylh + dyrh); dJpdphir += dJprdphi_r / (dylh + dyrh); if (Bfree != 0.0) { dJdxic += -Bfree * (dnc * pc); dJdxipc += -Bfree * (nc * dpc); dJpdxipc += Bfree * (nc * dpc); dJpdxic += Bfree * (dnc * pc); if ((in->interfaceleft == TRUE) && (i == 0)) { } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { } else { dJdphic += -Bfree * (dnc * pc); dJpdphic += Bfree * (nc * dpc); } } if (i == 0) { dJdphil_leftl = dJnldphi_l; dJdphil_leftc = dJnldphi_c; dJpdphil_leftl = dJpldphi_l; dJpdphil_leftc = dJpldphi_c; //printf("%le %le\n",dpc,dnc); dphil_left = -e0 / dyl / ddh; dJdxil_leftc = dJnldxil_c; dJpdxipl_leftc = dJpldxipl_c; //dylh_left=dylh; //dyrh_left=dyrh; } if (i == in->ymeshpoints - 1) { dJdxic_rightc = dJnrdxir_c; dJpdxipc_rightc = dJprdxipr_c; dJdphi_rightc = -dJnrdphi_r; dJpdphi_rightc = dJprdphi_c; } Rtrapn = 0.0; Rtrapp = 0.0; in->nrelax[i] = 0.0; in->ntrap_to_p[i] = 0.0; in->prelax[i] = 0.0; in->ptrap_to_n[i] = 0.0; if (in->ntrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { dJdtrapn[band] = 0.0; dJpdtrapn[band] = 0.0; dntrap[band] = nc * in->srh_n_r1[i][band] - in->srh_n_r2[i][band] - pc * in->srh_n_r3[i][band] + in->srh_n_r4[i][band]; dntrapdntrap[band] = nc * in->dsrh_n_r1[i][band] - in->dsrh_n_r2[i][band] - pc * in->dsrh_n_r3[i][band] + in->dsrh_n_r4[i][band]; dntrapdn[band] = dnc * in->srh_n_r1[i][band]; dntrapdp[band] = -dpc * in->srh_n_r3[i][band]; Rtrapn += nc * in->srh_n_r1[i][band] - in->srh_n_r2[i][band]; dJdxic -= dnc * in->srh_n_r1[i][band]; dJdtrapn[band] -= nc * in->dsrh_n_r1[i][band] - in->dsrh_n_r2[i][band]; Rtrapp += -(-pc * in->srh_n_r3[i][band] + in->srh_n_r4[i][band]); dJpdxipc += -(-dpc * in->srh_n_r3[i][band]); dJpdtrapn[band] = -(-pc * in->dsrh_n_r3[i][band] + in->dsrh_n_r4[i][band]); in->nrelax[i] += nc * in->srh_n_r1[i][band] - in->srh_n_r2[i][band]; in->ntrap_to_p[i] += -(-pc * in->srh_n_r3[i][band] + in->srh_n_r4[i][band]); in->nt_r1[i][band] = nc * in->srh_n_r1[i][band]; in->nt_r2[i][band] = in->srh_n_r2[i][band]; in->nt_r3[i][band] = pc * in->srh_n_r3[i][band]; in->nt_r4[i][band] = in->srh_n_r4[i][band]; } } //band=0; //printf("heren %le %le %le %le\n",in->Vapplied,nc*in->srh_n_r1[i][band]-in->srh_n_r2[i][band]-pc*in->srh_n_r3[i][band]+in->srh_n_r4[i][band],nc*in->srh_n_r1[i][band]-in->srh_n_r2[i][band],-pc*in->srh_n_r3[i][band]+in->srh_n_r4[i][band]); if (in->ptrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { //dJdtrapn[band]=0.0; dJpdtrapp[band] = 0.0; dJdtrapp[band] = 0.0; dptrap[band] = pc * in->srh_p_r1[i][band] - in->srh_p_r2[i][band] - nc * in->srh_p_r3[i][band] + in->srh_p_r4[i][band]; dptrapdptrap[band] = pc * in->dsrh_p_r1[i][band] - in->dsrh_p_r2[i][band] - nc * in->dsrh_p_r3[i][band] + in->dsrh_p_r4[i][band]; dptrapdp[band] = dpc * in->srh_p_r1[i][band]; dptrapdn[band] = -dnc * in->srh_p_r3[i][band]; Rtrapp += pc * in->srh_p_r1[i][band] - in->srh_p_r2[i][band]; dJpdxipc += dpc * in->srh_p_r1[i][band]; dJpdtrapp[band] += pc * in->dsrh_p_r1[i][band] - in->dsrh_p_r2[i][band]; Rtrapn += -(-nc * in->srh_p_r3[i][band] + in->srh_p_r4[i][band]); dJdxic -= -(-dnc * in->srh_p_r3[i][band]); dJdtrapp[band] -= -(-nc * in->dsrh_p_r3[i][band] + in->dsrh_p_r4[i][band]); in->prelax[i] += pc * in->srh_p_r1[i][band] - in->srh_p_r2[i][band]; in->ptrap_to_n[i] += -(-nc * in->srh_p_r3[i][band] + in->srh_p_r4[i][band]); in->pt_r1[i][band] = pc * in->srh_p_r1[i][band]; in->pt_r2[i][band] = in->srh_p_r2[i][band]; in->pt_r3[i][band] = nc * in->srh_p_r3[i][band]; in->pt_r4[i][band] = in->srh_p_r4[i][band]; } } //band=0; //printf("hereh %le %le %le %le\n",in->Vapplied,pc*in->srh_p_r1[i][band]-in->srh_p_r2[i][band]-nc*in->srh_p_r3[i][band]+in->srh_p_r4[i][band],pc*in->srh_p_r1[i][band]-in->srh_p_r2[i][band],-nc*in->srh_p_r3[i][band]+in->srh_p_r4[i][band]); in->Rn[i] = Rtrapn; in->Rp[i] = Rtrapp; //Rtrapp=1e24; //Rtrapn=1e24; if (i != 0) { in->Ti[pos] = i; in->Tj[pos] = i - 1; in->Tx[pos] = dphil_d; pos++; //electron in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1) + i - 1; in->Tx[pos] = dJdxil; pos++; in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = i - 1; in->Tx[pos] = dJdphil; pos++; //hole in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i - 1; in->Tx[pos] = dJpdxipl; pos++; in->Ti[pos] = i + in->ymeshpoints * (1 + 1); in->Tj[pos] = i - 1; in->Tx[pos] = dJpdphil; pos++; } if ((in->kl_in_newton == TRUE) && (in->interfaceleft == TRUE) && (i == 0)) { //printf("%d\n",i); //getchar(); } else { //phi in->Ti[pos] = i; in->Tj[pos] = i; in->Tx[pos] = dphic_d; pos++; } in->Ti[pos] = i; in->Tj[pos] = i + in->ymeshpoints * (1); in->Tx[pos] = dphidxic; pos++; in->Ti[pos] = i; in->Tj[pos] = i + in->ymeshpoints * (1 + 1); in->Tx[pos] = dphidxipc; pos++; //electron in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1) + i; in->Tx[pos] = dJdxic; pos++; in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i; in->Tx[pos] = dJdxipc; pos++; in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = i; in->Tx[pos] = dJdphic; pos++; //hole in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i; in->Tx[pos] = dJpdxipc; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1) + i; in->Tx[pos] = dJpdxic; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = i; in->Tx[pos] = dJpdphic; pos++; if (in->ntrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tx[pos] = dntrapdntrap[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tj[pos] = in->ymeshpoints * 1 + i; in->Tx[pos] = dntrapdn[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i; in->Tx[pos] = dntrapdp[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tx[pos] = dJdtrapn[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tx[pos] = dJpdtrapn[band]; pos++; in->Ti[pos] = i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + band) + i; in->Tx[pos] = dphidntrap[band]; pos++; } } if (in->ptrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tx[pos] = dptrapdptrap[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i; in->Tx[pos] = dptrapdp[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tj[pos] = in->ymeshpoints * (1) + i; in->Tx[pos] = dptrapdn[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tx[pos] = dJpdtrapp[band]; pos++; in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tx[pos] = dJdtrapp[band]; pos++; in->Ti[pos] = i; in->Tj[pos] = in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i; in->Tx[pos] = dphidptrap[band]; pos++; } } if (i != (in->ymeshpoints - 1)) { if ((in->kl_in_newton == TRUE) && (in->interfaceleft == TRUE) && (i == 0)) { //printf("%d\n",i); //getchar(); } else { //phi in->Ti[pos] = i; in->Tj[pos] = i + 1; in->Tx[pos] = dphir_d; pos++; } //electron in->Ti[pos] = in->ymeshpoints * (1) + i; in->Tj[pos] = in->ymeshpoints * (1) + i + 1; in->Tx[pos] = dJdxir; pos++; in->Ti[pos] = i + in->ymeshpoints * (1); in->Tj[pos] = i + 1; in->Tx[pos] = dJdphir; pos++; //hole in->Ti[pos] = in->ymeshpoints * (1 + 1) + i; in->Tj[pos] = in->ymeshpoints * (1 + 1) + i + 1; in->Tx[pos] = dJpdxipr; pos++; in->Ti[pos] = i + in->ymeshpoints * (1 + 1); in->Tj[pos] = i + 1; in->Tx[pos] = dJpdphir; pos++; } //Possion if ((in->interfaceleft == TRUE) && (i == 0)) { in->b[i] = -0.0; } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { in->b[i] = -0.0; } else { in->b[i] = -(deriv); in->b[i] += -(-Q * (in->p[i] - in->n[i])); for (band = 0; band < in->srh_bands; band++) { in->b[i] += -(-Q * (in->pt[i][band] - in->nt[i][band])); } in->b[i] += -(-Q * in->Nad[i]); } in->b[in->ymeshpoints * (1) + i] = -((Jnr - Jnl) / (dylh + dyrh) - Rtrapn - Rfree); //getchar(); in->b[in->ymeshpoints * (1) + i] -= Gn; //hole in->b[in->ymeshpoints * (1 + 1) + i] = -((Jpr - Jpl) / (dylh + dyrh) + Rtrapp + Rfree); //printf("%le %le\n",Rtrapn,Rtrapp); in->b[in->ymeshpoints * (1 + 1) + i] -= -Gp; if (in->ntrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { in->b[in->ymeshpoints * (1 + 1 + 1 + band) + i] = -(dntrap[band]); } } if (in->ptrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { in->b[in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i] = -(dptrap[band]); } } } if (pos > in->N) { ewe("Error %d %d %d\n", pos, in->N, in->kl_in_newton); } //solver_dump_matrix(in->M,pos,in->Ti,in->Tj, in->Tx,in->b); //fclose(file_j); //printf("Check J file\n"); //getchar(); }
/** * Compute derived GL state. * If __GLcontextRec::NewState is non-zero then this function \b must * be called before rendering anything. * * Calls dd_function_table::UpdateState to perform any internal state * management necessary. * * \sa _mesa_update_modelview_project(), _mesa_update_texture(), * _mesa_update_buffer_bounds(), * _mesa_update_lighting() and _mesa_update_tnl_spaces(). */ void _mesa_update_state_locked( GLcontext *ctx ) { GLbitfield new_state = ctx->NewState; GLbitfield prog_flags = _NEW_PROGRAM; GLbitfield new_prog_state = 0x0; if (new_state == _NEW_CURRENT_ATTRIB) goto out; if (MESA_VERBOSE & VERBOSE_STATE) _mesa_print_state("_mesa_update_state", new_state); /* Determine which state flags effect vertex/fragment program state */ if (ctx->FragmentProgram._MaintainTexEnvProgram) { prog_flags |= (_NEW_TEXTURE | _NEW_FOG | _DD_NEW_SEPARATE_SPECULAR | _NEW_ARRAY); } if (ctx->VertexProgram._MaintainTnlProgram) { prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX | _NEW_TRANSFORM | _NEW_POINT | _NEW_FOG | _NEW_LIGHT | _MESA_NEW_NEED_EYE_COORDS); } /* * Now update derived state info */ if (new_state & prog_flags) update_program_enables( ctx ); if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION)) _mesa_update_modelview_project( ctx, new_state ); if (new_state & (_NEW_PROGRAM|_NEW_TEXTURE|_NEW_TEXTURE_MATRIX)) _mesa_update_texture( ctx, new_state ); if (new_state & _NEW_BUFFERS) _mesa_update_framebuffer(ctx); if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT)) _mesa_update_draw_buffer_bounds( ctx ); if (new_state & _NEW_POLYGON) update_polygon( ctx ); if (new_state & _NEW_LIGHT) _mesa_update_lighting( ctx ); if (new_state & (_NEW_STENCIL | _NEW_BUFFERS)) _mesa_update_stencil( ctx ); #if FEATURE_pixel_transfer if (new_state & _MESA_NEW_TRANSFER_STATE) _mesa_update_pixel( ctx, new_state ); #endif if (new_state & _DD_NEW_SEPARATE_SPECULAR) update_separate_specular( ctx ); if (new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT)) update_arrays( ctx ); if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT)) update_viewport_matrix(ctx); if (new_state & _NEW_MULTISAMPLE) update_multisample( ctx ); if (new_state & _NEW_COLOR) update_color( ctx ); #if 0 if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT | _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR)) update_tricaps( ctx, new_state ); #endif /* ctx->_NeedEyeCoords is now up to date. * * If the truth value of this variable has changed, update for the * new lighting space and recompute the positions of lights and the * normal transform. * * If the lighting space hasn't changed, may still need to recompute * light positions & normal transforms for other reasons. */ if (new_state & _MESA_NEW_NEED_EYE_COORDS) _mesa_update_tnl_spaces( ctx, new_state ); if (new_state & prog_flags) { /* When we generate programs from fixed-function vertex/fragment state * this call may generate/bind a new program. If so, we need to * propogate the _NEW_PROGRAM flag to the driver. */ new_prog_state |= update_program( ctx ); } out: new_prog_state |= update_program_constants(ctx); /* * Give the driver a chance to act upon the new_state flags. * The driver might plug in different span functions, for example. * Also, this is where the driver can invalidate the state of any * active modules (such as swrast_setup, swrast, tnl, etc). * * Set ctx->NewState to zero to avoid recursion if * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?) */ new_state = ctx->NewState | new_prog_state; ctx->NewState = 0; ctx->Driver.UpdateState(ctx, new_state); ctx->Array.NewState = 0; }
void update_solver_vars(struct device *in, int clamp) { int i; int band = 0; double clamp_temp = 300.0; double update = 0.0; for (i = 0; i < in->ymeshpoints; i++) { update = in->b[i]; if ((in->interfaceleft == TRUE) && (i == 0)) { } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { } else { if (clamp == TRUE) { in->phi[i] += update / (1.0 + fabs(update / in->electrical_clamp / (clamp_temp * kb / Q))); } else { in->phi[i] += update; } } update = (in->b[in->ymeshpoints * (1) + i]); if (clamp == TRUE) { in->x[i] += update / (1.0 + fabs(update / in->electrical_clamp / (clamp_temp * kb / Q))); } else { in->x[i] += update; } update = (in->b[in->ymeshpoints * (1 + 1) + i]); if (clamp == TRUE) { in->xp[i] += update / (1.0 + fabs(update / in->electrical_clamp / (clamp_temp * kb / Q))); // } else { in->xp[i] += update; } if (in->ntrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { update = (in-> b[in->ymeshpoints * (1 + 1 + 1 + band) + i]); if (clamp == TRUE) { in->xt[i][band] += update / (1.0 + fabs(update / in-> electrical_clamp / (clamp_temp * kb / Q))); } else { in->xt[i][band] += update; } } } if (in->ptrapnewton == TRUE) { for (band = 0; band < in->srh_bands; band++) { update = (in-> b[in->ymeshpoints * (1 + 1 + 1 + in->srh_bands + band) + i]); if (clamp == TRUE) { in->xpt[i][band] += update / (1.0 + fabs(update / in-> electrical_clamp / (clamp_temp * kb / Q))); } else { in->xpt[i][band] += update; } } } } update_arrays(in); }