예제 #1
0
파일: dump.c 프로젝트: jasonlarkin/disorder
void g95_dump(g95_namespace *ns) {

    if (dump_file == NULL && getenv("G95_DUMP") != NULL)
	init_dump();

    if (dump_file != NULL)
	dump_ns(ns);
}
예제 #2
0
void evolve_network(network *net) {
  FILE *fh, *fhtime;
  char msg[1024], outdir[1024], msg2[80];
  double dx = 1000./(net->npcent);
  double dt = dx/(net->c);  			// physical time-step (seconds)
  int n_steps = round((net->tmax)/dt);
  //int n_steps = 4;
  int n_skip = net->nskip;
  //int n_skip = 1;
  int n_curr = 0;
  printf("Simulating network for %f hours\nTime step is %f (in secs)\nTotal steps %d\n", (net->tmax)/3600., dt, n_steps);
  
  init_dump(net);
  
  while (1) {
#if NOISE
    split_step2(net, dx, n_curr*dt);  // note (dx = dtau)
    //printf("Uncomment to run with noise\n"); exit(1);	
#else
    memcpy(p_prev, net->link[0]->p, (net->link[0]->N)*sizeof(double));
    split_step2nonoise(net, dx, n_curr*dt);  // note (dx = dtau)
#endif
    if (ADIABATIC) adiabatic_rk4(net->link[0]->fx, dt);
    n_curr++;
    
    if (n_curr % n_skip == 0) {
      printf("t = %.8e min\n", n_curr*dt/60.);
      dump_current(net, n_curr*dt);
      save_adiabatic();

      if (ADIABATIC_SAVE) save_adiabatic_temporal();
      if (PIPE_SAVE) {	
        for (int n = 0; n < net->nlinks; n++){ 
          sprintf(msg, "%s/pipe_%03d/%s_%03d.txt", net->current_dir, n, net->dname, n_curr/n_skip);
          fh = fopen(msg, "w");
	  save_data(fh, net->link[n], net, n_curr*dt);
          fclose(fh);         
        }
        /*if (net->mglf != 0) {
          sprintf(outdir, "%s/network", net->current_dir);
          sprintf(msg, "%s/%s_%03d.png", outdir, net->dname, n_curr/n_skip);
          sprintf(msg2, "t = %.3f sec", n_curr*dt);
          mgl_draw_network(net, msg, msg2);
        }*/
      }
    }
    if (n_curr == n_steps) break; 
  }
  printf("t = %.8e min\n", n_curr*dt/60.);
  fhtime = fopen("params.txt", "a");
  fprintf(fhtime, "%e\t%e\t%e\n", n_curr*dt/3600., ((net->knot[1])->P)*0.000001, ovsq2*((net->link[0])->W_l - (net->link[0])->Wb_l)/(net->c) );
  fclose(fhtime);
}
예제 #3
0
파일: cli.c 프로젝트: yur4ek/chan_ss7
static int cmd_dump_start(int fd, int argc, argv_type argv) {
  int in, out;
  int i;
  int fisu,lssu,msu;

  if(argc < 4) {
    return RESULT_SHOWUSAGE;
  }

  if(argc == 4) {
    in = 1;
    out = 1;
  } else {
    if(0 == strcasecmp(argv[4], "in")) {
      in = 1;
      out = 0;
    } else if(0 == strcasecmp(argv[4], "out")) {
      in = 0;
      out = 1;
    } else if(0 == strcasecmp(argv[4], "both")) {
      in = 1;
      out = 1;
    } else {
      return RESULT_SHOWUSAGE;
    }
  }

  if(argc <= 5) {
    fisu = 0;
    lssu = 0;
    msu = 1;
  } else {
    fisu = 0;
    lssu = 0;
    msu = 0;
    for(i = 5; i < argc; i++) {
      if(0 == strcasecmp(argv[i], "fisu")) {
        fisu = 1;
      } else if(0 == strcasecmp(argv[i], "lssu")) {
        lssu = 1;
      } else if(0 == strcasecmp(argv[i], "msu")) {
        msu = 1;
      } else {
        return RESULT_SHOWUSAGE;
      }
    }
  }
  init_dump(fd, argv[3], in, out, fisu, lssu, msu);
  return RESULT_SUCCESS;
}
예제 #4
0
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;
}