Esempio n. 1
0
void
predefinedLIMEGrid(inputPars *par, struct grid *g){
  FILE *fp;
  int i;
  double x,y,z,scale,abun;
	
  fp=fopen(par->pregridLIME,"r");
  par->ncell=par->pIntensity+par->sinkPoints;

  /* read in the grid file, which includes all the sink points so we don't need to generate them */
  for(i=0;i<par->ncell;i++){
    fscanf(fp,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %d\n", &g[i].x[0], &g[i].x[1], &g[i].x[2], &g[i].dens[0], &g[i].t[0], &g[i].t[1], &g[i].abun[0], &g[i].vel[0], &g[i].vel[1], &g[i].vel[2], &g[i].dopb, &g[i].sink);
    g[i].id=i;
	g[i].nmol[0]=g[i].abun[0]*g[i].dens[0];

	// This next step needs to be done, even though it looks stupid
	g[i].dir=malloc(sizeof(point)*1);
	g[i].ds =malloc(sizeof(double)*1);
	g[i].neigh =malloc(sizeof(int)*1);
	if(!silent) progressbar((double) i/((double)par->ncell-1), 4);	
  }

  fclose(fp);

  qhull(par,g);
  distCalc(par,g);
//  getArea(par,g, ran);
//  getMass(par,g, ran);
  getVelosplines_lin(par,g);
  if(par->gridfile) write_VTK_unstructured_Points(par, g);
}
Esempio n. 2
0
void
popsin(inputPars *par, struct grid **g, molData **m, int *popsdone){
  FILE *fp;
  int i,j,k;
  double dummy;

  if((fp=fopen(par->restart, "rb"))==NULL){
    if(!silent) bail_out("Error reading binary output populations file!");
    exit(1);
  }

  par->collPart=1;
  fread(&par->radius,   sizeof(double), 1, fp);
  fread(&par->ncell,    sizeof(int), 1, fp);
  fread(&par->nSpecies, sizeof(int), 1, fp);
  if( par->nSpecies < 0 || par->nSpecies > MAX_NSPECIES )
    {
      if(!silent) bail_out("Error reading binary output populations file : is this really a binary output file generated by lime ?");
      exit(1);
    }

  *m=realloc(*m, sizeof(molData)*par->nSpecies);

  for(i=0;i<par->nSpecies;i++){
    (*m)[i].lcl = NULL;
    (*m)[i].lcu = NULL;
    (*m)[i].up = NULL;
    (*m)[i].down = NULL;
    (*m)[i].eterm = NULL;
    (*m)[i].gstat = NULL;
    (*m)[i].cmb = NULL;
    fread(&(*m)[i].nlev,  sizeof(int),        1,fp);
    fread(&(*m)[i].nline, sizeof(int),        1,fp);
    fread(&(*m)[i].npart, sizeof(int),        1,fp);
    (*m)[i].ntrans=malloc(sizeof(int)*(*m)[i].npart);
    for(j=0;j<(*m)[i].npart;j++) fread(&(*m)[i].ntrans[j], sizeof(int), 1,fp);
    (*m)[i].lal=malloc(sizeof(int)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].lal[j],    sizeof(int), 1,fp);
    (*m)[i].lau=malloc(sizeof(int)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].lau[j],    sizeof(int), 1,fp);
    (*m)[i].aeinst=malloc(sizeof(double)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].aeinst[j], sizeof(double), 1,fp);
    (*m)[i].freq=malloc(sizeof(double)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].freq[j],   sizeof(double), 1,fp);
    (*m)[i].beinstl=malloc(sizeof(double)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].beinstl[j],sizeof(double), 1,fp);
    (*m)[i].beinstu=malloc(sizeof(double)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].beinstu[j],sizeof(double), 1,fp);
    (*m)[i].local_cmb = malloc(sizeof(double)*(*m)[i].nline);
    for(j=0;j<(*m)[i].nline;j++) fread(&(*m)[i].local_cmb[j],sizeof(double), 1,fp);
    fread(&(*m)[i].norm, sizeof(double),      1,fp);
    fread(&(*m)[i].norminv, sizeof(double),   1,fp);
  }

  *g=malloc(sizeof(struct grid)*par->ncell);

  for(i=0;i<par->ncell;i++){
    (*g)[i].a0 = NULL;
    (*g)[i].a1 = NULL;
    (*g)[i].a2 = NULL;
    (*g)[i].a3 = NULL;
    (*g)[i].a4 = NULL;
    (*g)[i].dens = NULL;
    (*g)[i].abun = NULL;
    (*g)[i].nmol = NULL;
    (*g)[i].dir = NULL;
    (*g)[i].neigh = NULL;
    (*g)[i].w = NULL;
    (*g)[i].ds = NULL;
    fread(&(*g)[i].id, sizeof (*g)[i].id, 1, fp);
    fread(&(*g)[i].x, sizeof (*g)[i].x, 1, fp);
    fread(&(*g)[i].vel, sizeof (*g)[i].vel, 1, fp);
    fread(&(*g)[i].sink, sizeof (*g)[i].sink, 1, fp);
    (*g)[i].nmol=malloc(par->nSpecies*sizeof(double));
    for(j=0;j<par->nSpecies;j++) fread(&(*g)[i].nmol[j], sizeof(double), 1, fp);
    fread(&(*g)[i].dopb, sizeof (*g)[i].dopb, 1, fp);
    (*g)[i].mol=malloc(par->nSpecies*sizeof(struct populations));
    for(j=0;j<par->nSpecies;j++){
      (*g)[i].mol[j].pops=malloc(sizeof(double)*(*m)[j].nlev);
      for(k=0;k<(*m)[j].nlev;k++) fread(&(*g)[i].mol[j].pops[k], sizeof(double), 1, fp);
      (*g)[i].mol[j].knu=malloc(sizeof(double)*(*m)[j].nline);
      for(k=0;k<(*m)[j].nline;k++) fread(&(*g)[i].mol[j].knu[k], sizeof(double), 1, fp);
      (*g)[i].mol[j].dust=malloc(sizeof(double)*(*m)[j].nline);
      for(k=0;k<(*m)[j].nline;k++) fread(&(*g)[i].mol[j].dust[k],sizeof(double), 1, fp);
      fread(&(*g)[i].mol[j].dopb,sizeof(double), 1, fp);
      fread(&(*g)[i].mol[j].binv,sizeof(double), 1, fp);
      (*g)[i].mol[j].partner=NULL;
    }
    fread(&dummy, sizeof(double), 1, fp);
    fread(&dummy, sizeof(double), 1, fp);
    fread(&dummy, sizeof(double), 1, fp);
  }
  fclose(fp);

  qhull(par, *g);
  distCalc(par, *g);
  getVelosplines(par,*g);
  *popsdone=1;
}
Esempio n. 3
0
void
predefinedGrid(inputPars *par, struct grid *g){
  FILE *fp;
  int i;
  double x,y,z,scale;
  gsl_rng *ran = gsl_rng_alloc(gsl_rng_ranlxs2);
#ifdef TEST
  gsl_rng_set(ran,6611304);
#else
  gsl_rng_set(ran,time(0));
#endif
	
  fp=fopen(par->pregrid,"r");
  par->ncell=par->pIntensity+par->sinkPoints;

  for(i=0;i<par->pIntensity;i++){
    //    fscanf(fp,"%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n", &g[i].id, &g[i].x[0], &g[i].x[1], &g[i].x[2],  &g[i].dens[0], &g[i].t[0], &abun, &g[i].dopb, &g[i].vel[0], &g[i].vel[1], &g[i].vel[2]);
    //    fscanf(fp,"%d %lf %lf %lf %lf %lf %lf %lf\n", &g[i].id, &g[i].x[0], &g[i].x[1], &g[i].x[2],  &g[i].dens[0], &g[i].t[0], &abun, &g[i].dopb);
    int nRead = fscanf(fp,"%d %lf %lf %lf %lf %lf %lf %lf %lf\n", &g[i].id, &g[i].x[0], &g[i].x[1], &g[i].x[2],  &g[i].dens[0], &g[i].t[0], &g[i].vel[0], &g[i].vel[1], &g[i].vel[2]);
    if( nRead != 9 || g[i].id < 0 || g[i].id > par->ncell)
      {
        if(!silent) bail_out("Reading Grid File error");
        exit(0);
      }

    g[i].dopb=200;
    g[i].abun[0]=1e-9;


    g[i].sink=0;
	g[i].t[1]=g[i].t[0];
	g[i].nmol[0]=g[i].abun[0]*g[i].dens[0];
		
	/* This next step needs to be done, even though it looks stupid */
	g[i].dir=malloc(sizeof(point)*1);
	g[i].ds =malloc(sizeof(double)*1);
	g[i].neigh =malloc(sizeof(struct grid *)*1);
	if(!silent) progressbar((double) i/((double)par->pIntensity-1), 4);	
  }

  for(i=par->pIntensity;i<par->ncell;i++){
    x=2*gsl_rng_uniform(ran)-1.;
    y=2*gsl_rng_uniform(ran)-1.;
    z=2*gsl_rng_uniform(ran)-1.;
    if(x*x+y*y+z*z<1){
      scale=par->radius*sqrt(1/(x*x+y*y+z*z));
      g[i].id=i;
      g[i].x[0]=scale*x;
      g[i].x[1]=scale*y;
      g[i].x[2]=scale*z;
      g[i].sink=1;
      g[i].abun[0]=0;
      g[i].dens[0]=1e-30;
      g[i].t[0]=par->tcmb;
      g[i].t[1]=par->tcmb;
      g[i].dopb=0.;
    } else i--;
  }
  fclose(fp);

  qhull(par,g);
  distCalc(par,g);
  //  getArea(par,g, ran);
  //  getMass(par,g, ran);
  getVelosplines_lin(par,g);
  if(par->gridfile) write_VTK_unstructured_Points(par, g);
  gsl_rng_free(ran);
}
Esempio n. 4
0
/* Based on Lloyds Algorithm (Lloyd, S. IEEE, 1982) */	
void
smooth(configInfo *par, struct grid *gp){
  double mindist;	/* Distance to closest neighbor				*/
  int k=0,j,i;		/* counters									*/
  int sg;		/* counter for smoothing the grid			*/
  int cn;
  double move[3];	/* Auxillary array for smoothing the grid	*/
  double dist;		/* Distance to a neighbor					*/
  struct cell *dc=NULL; /* Not used at present. */
  unsigned long numCells;

  for(sg=0;sg<N_SMOOTH_ITERS;sg++){
    delaunay(DIM, gp, (unsigned long)par->ncell, 0, 0, &dc, &numCells);
    distCalc(par, gp);

    for(i=0;i<par->pIntensity;i++){
      mindist=1e30;
      cn=-1;
      for(k=0;k<gp[i].numNeigh;k++){
        if(gp[i].neigh[k]->sink==0){
          if(gp[i].ds[k]<mindist){
            mindist=gp[i].ds[k];
            cn=k;
          }
        }
      }

      if(par->radius-sqrt(gp[i].x[0]*gp[i].x[0] + gp[i].x[1]*gp[i].x[1] + gp[i].x[2]*gp[i].x[2])<mindist) cn=-1;

      if(cn>-1) {
        for(k=0;k<DIM;k++){
          move[k] = gp[i].x[k] - gp[i].dir[cn].x[k]*0.20;
        }			  
        if((move[0]*move[0]+move[1]*move[1]+move[2]*move[2])<par->radiusSqu &&
           (move[0]*move[0]+move[1]*move[1]+move[2]*move[2])>par->minScaleSqu){
          for(k=0;k<DIM;k++) gp[i].x[k]=move[k];
        }
      }
    }
		
    for(i=par->pIntensity;i<par->ncell;i++){
      mindist=1e30;
      cn=-1;
      for(k=0;k<gp[i].numNeigh;k++){
        if(gp[i].neigh[k]->sink==1){
          if(gp[i].ds[k]<mindist){
            mindist=gp[i].ds[k];
            cn=k;
          }
        }
      }
      j=gp[i].neigh[cn]->id;
      for(k=0;k<DIM;k++){
        gp[i].x[k] = gp[i].x[k] - (gp[j].x[k]-gp[i].x[k]) * 0.15;
      }			
      dist=par->radius/sqrt(gp[i].x[0]*gp[i].x[0] + gp[i].x[1]*gp[i].x[1] + gp[i].x[2]*gp[i].x[2]);	
      for(k=0;k<DIM;k++){
        gp[i].x[k] *= dist;
      }	
    }
		
    if(!silent) progressbar((double)(sg+1)/(double)N_SMOOTH_ITERS, 5);	
    free(dc);
  }	
}