예제 #1
0
/* grab-bag for random initializations, etc (as 'begrun' from main code) */
void setup_lineofsight_overhead(void)
{
	set_sph_kernel();
	InitCool();
	set_All_struct_terms();
}
예제 #2
0
void init_SN(void)
{
  int i, j, guess_on_Nsteps;

  double astep, meanweight;

  char buf[200], buffer[200], mode[2];

#if defined(LT_METAL_COOLING_WAL)
  double Redshift;
#endif
  
#if defined (UM_CHEMISTRY) && defined (UM_METAL_COOLING)
  um_FillEl_mu = 40.0;
#endif

  /* : ....................... : */
  if(ThisTask == 0)		/* :[ open some output file ]: */
    {
       printf("Initializing SN\n");

      if(RestartFlag == 0)
	strcpy(mode, "w");
      else
	strcpy(mode, "a");

      sprintf(buf, "%s%s", All.OutputDir, "sn_init.txt");	/*   this will list all the fundamental data */
      if((FdSnInit = fopen(buf, mode)) == 0x0)	/*   about supernonave                       */
	{
	  printf("error in opening file '%s'\n", buf);
	  endrun(1);
	}

      if(strcmp(mode, "a") == 0x0)
	fprintf(FdSnInit, "========================================\n" "restarting from a= %g\n\n", All.Time);

#ifdef LT_SEv_INFO_DETAILS
      sprintf(buf, "%s%s", All.OutputDir, "sn_details.dat");	/*   this file will contain all the details */
      /*   about all the sn evolution steps       */
      if((FdSnDetails = fopen(buf, mode)) == 0x0)
	{
	  printf("error in opening file '%s'\n", buf);
	  endrun(1);
	}
#endif
      sprintf(buf, "%s%s", All.OutputDir, "warnings.txt");	/*   this file will store all warnings      */
      if((FdWarn = fopen(buf, mode)) == 0x0)
	{
	  printf("error in opening file '%s'\n", buf);
	  endrun(1);
	}
    }

  UnitMassFact = All.UnitMass_in_g / SOLAR_MASS;

  /* : ................ : */
  /* :[ metals StartUp ]: */
  read_metals();

  /* : ................................ : */
  /* :[ allocate integration workspace ]: */
  w = gsl_integration_workspace_alloc(gsl_ws_dim);
  old_error_handler = gsl_set_error_handler(&fsolver_error_handler);
  /* : ................... : */
  /* :[ start the cooling ]: */

  All.Time = All.TimeBegin;
  set_cosmo_factors_for_current_time();
  InitCool();
#ifdef LT_METAL_COOLING_WAL
  WalCool_tables_load(0);                                                /* use z=0 tables for initializing */
#endif
  
  /* : ............................... :    */
  /* :[ start the IMF  and SF StartUp ]:    */
  
#ifndef LT_METAL_COOLING
  ZBins = 1;
  ThInst_onset = (double *) mymalloc("ThInst_onset", 1 * sizeof(double));
  ThInst_onset[0] = 5;
#endif

  allocate_IMF_integration_space();	/*    allocate memory for IMF integration */
  load_SFs_IMFs();		/*    load IMF and SF files               */
  All.Generations = 0;

  for(i = 0; i < IMFs_dim; i++)	/*    normalize IMFs by mass if they are not */
    {
      if(IMFs[i].NParams > 0 || IMFs[i].timedep)
	IMFs[i].getp(i, IMFs[i].Params, All.Time);	/*    get parameters for a (time-dependent) IMF */

      IMFs[i].Atot = 1.0 / IntegrateIMF_byMass(IMFs[i].Mm, IMFs[i].MU, &IMFs[i], INC_BH);
      if(IMFs[i].NSlopes == 1)
	IMFs[i].A[0] = IMFs[i].Atot;
    }

  for(i = 0; i < SFs_dim; i++)
    if(SFs[i].Generations > All.Generations)
      All.Generations = SFs[i].Generations;	/*    set All.Generations to the maximum */

  if(ThisTask == 0)
    for(i = 0; i < SFs_dim; i++)
      if(All.Generations % SFs[i].Generations != 0)
	{
	  printf("!!!! max # of generations %d is not an integer multiple of the # of gen. for SF %d\n",
		 All.Generations, i);
	  endrun(99119911);
	}

  for(All.StarBits = 0; All.Generations > (1 << All.StarBits); All.StarBits++);

  if(ThisTask == 0)		/*    write infos about IMFs */
    {
      for(i = 0; i < IMFs_dim; i++)
	write_IMF_info(i, stdout);
      for(i = 0; i < IMFs_dim; i++)
	write_IMF_info(i, FdSnInit);
      for(i = 0; i < IMFs_dim; i++)
	print_IMF(i, All.IMFfilename);

      for(i = 0; i < SFs_dim; i++)
	write_SF_info(i, stdout);
      for(i = 0; i < SFs_dim; i++)
	write_SF_info(i, FdSnInit);
    }
  /* : .................................. : */
  /* :[ initialize the packing stricture ]: */

#ifdef LT_TRACK_CONTRIBUTES
  init_packing();
#endif

  if(strcasecmp(All.SnIaDataFile, "none") == 0 || All.Ia_Nset_ofYields == 0)
    UseSnIa = 0;
  else
    UseSnIa = 1;

  if(strcasecmp(All.SnIIDataFile, "none") == 0 || All.II_Nset_ofYields == 0)
    UseSnII = 0;
  else
    UseSnII = 1;

  if(strcasecmp(All.AGBDataFile, "none") == 0 || All.AGB_Nset_ofYields == 0)
    UseAGB = 0;
  else
    UseAGB = 1;

  /* : ............................................... : */
  /* :[ initialize time scales for stellar evolutions ]: */
  initialize_star_lifetimes();

  if(ThisTask == 0)
    {
      fprintf(FdSnInit, "[stellar evolution initialization - lifetimes]");
      fprintf(FdSnInit, "\nstellar lifetimes: mean (%5.4g Msun) = %g Gyrs\n", All.Mup, All.mean_lifetime);
      for(i = 0; i < IMFs_dim; i++)
	fprintf(FdSnInit, "   IMF %3d         inf (%5.4g Msun) = %g Gyrs\n"
		"                   sup (%5.4g Msun) = %g Gyrs\n",
		i, IMFs[i].MU, IMFs[i].inf_lifetime, min(IMFs[i].Mm, All.MBms), IMFs[i].sup_lifetime);
    }

  /* : ............ : */
  /* :[ Sn StartUp ]: */

  /*    reading yields */

  ReadYields(1, 1, 1);
  /* : ............ : */
  /* :[ SF StartUp ]: */


  /* Set some SF-related Units (old set_units_sfr) */
  meanweight = 4 / (1 + 3 * HYDROGEN_MASSFRAC);	/* note: assuming NEUTRAL GAS */

  All.EgySpecCold = 1 / meanweight * (1.0 / GAMMA_MINUS1) * (BOLTZMANN / PROTONMASS) * All.TempClouds;
  All.EgySpecCold *= All.UnitMass_in_g / All.UnitEnergy_in_cgs;

  meanweight = 4 / (8 - 5 * (1 - HYDROGEN_MASSFRAC));	/* note: assuming FULL ionization */

  All.OverDensThresh =
    All.CritOverDensity * All.OmegaBaryon * 3 * All.Hubble * All.Hubble / (8 * M_PI * All.G);

#ifdef INTERNAL_CRIT_DENSITY
  All.PhysDensThresh = All.CritPhysDensity;
#else
  All.PhysDensThresh = All.CritPhysDensity * PROTONMASS / HYDROGEN_MASSFRAC / All.UnitDensity_in_cgs /
    (All.HubbleParam * All.HubbleParam);
#endif
#ifdef LT_STARBURSTS
  if(All.StarBurstCondition == SB_DENSITY)
    All.SB_Density_Thresh *= PROTONMASS / HYDROGEN_MASSFRAC / All.UnitDensity_in_cgs /
      (All.HubbleParam * All.HubbleParam);
#endif

  /* ----------- */

  SnII_ShortLiv_Yields = (double ***) mymalloc("SnII_ShortLiv_Yields", sizeof(double **) * SFs_dim);

  for(i = 0; i < SFs_dim; i++)
    {
      if(All.PhysDensThresh > 0 && SFs[i].PhysDensThresh[0] == 0)
	SFs[i].PhysDensThresh[0] = All.PhysDensThresh;
      else
	/* Phys Dens Thresh is supposed to be in hydrogen number density cm^-3 */
	SFs[i].PhysDensThresh[0] *= PROTONMASS / HYDROGEN_MASSFRAC / All.UnitDensity_in_cgs /
	  (All.HubbleParam * All.HubbleParam);
      if(All.egyIRA_ThMass > 0)
	SFs[i].egyShortLiv_MassTh = All.egyIRA_ThMass;
      if(All.metIRA_ThMass > 0)
	SFs[i].metShortLiv_MassTh = All.metIRA_ThMass;
      if(All.WindEfficiency > 0)
	SFs[i].WindEfficiency = All.WindEfficiency;
      if(All.WindEnergyFraction > 0)
	SFs[i].WindEnergyFraction = All.WindEnergyFraction;

      setup_SF_related(i);

      /* ................::................... */

      SFs[i].ShortLiv_MassTh = max(SFs[i].metShortLiv_MassTh, SFs[i].egyShortLiv_MassTh);
      SFs[i].ShortLiv_TimeTh = min(SFs[i].metShortLiv_TimeTh, SFs[i].egyShortLiv_TimeTh);

    }


#ifdef LT_METAL_COOLING_WAL
  Redshift = 1.0 / All.Time - 1.0;
  set_cooltable_index(-1);
  WalCool_tables_load(Redshift);
#endif
  
  /* ...........: initialize stepping :...................... */

  ShortLiv_Nsteps = (int *) mymalloc("ShortLiv_Nsteps", SFs_dim * sizeof(int));

  LongLiv_Nsteps = (int *) mymalloc("LongLiv_Nsteps", SFs_dim * sizeof(int));

  Nsteps = (int *) mymalloc("Nsteps", SFs_dim * sizeof(int));
  SNtimesteps = (double ***) mymalloc("SNtimesteps", SFs_dim * sizeof(double *));

  for(i = 0; i < SFs_dim; i++)
    {
      if(UseSnII)
	guess_on_Nsteps = (int) (1.3 / All.SnII_Step_Prec);
      else
	guess_on_Nsteps = 0;


      if(!IMFs[SFs[i].IMFi].timedep)
	ShortLiv_Nsteps[i] = guess_on_Nsteps;
      else
	ShortLiv_Nsteps[i] = 0;

      if(UseSnIa || UseAGB)
	guess_on_Nsteps = (int) (1.3 / All.LLv_Step_Prec);
      else
	guess_on_Nsteps = 0;

      if(!IMFs[SFs[i].IMFi].timedep)
	LongLiv_Nsteps[i] = guess_on_Nsteps;
      else
	LongLiv_Nsteps[i] = 0;


      Nsteps[i] = ShortLiv_Nsteps[i] + LongLiv_Nsteps[i];
      sprintf(buffer, "SNtimesteps_imf_%02d", i);
      SNtimesteps[i] = (double **) mymalloc(buffer, 2 * sizeof(double *));

      sprintf(buffer, "SNtimesteps_timebins_imf_%02d", i);
      SNtimesteps[i][0] = (double *) mymalloc(buffer, Nsteps[i] * sizeof(double));
      memset(SNtimesteps[i][0], 0, Nsteps[i] * sizeof(double));

      sprintf(buffer, "SNtimesteps_timedelta_imf_%02d", i);
      SNtimesteps[i][1] = (double *) mymalloc(buffer, Nsteps[i] * sizeof(double));
      memset(SNtimesteps[i][1], 0, Nsteps[i] * sizeof(double));

      build_SN_Stepping(i);

      /* ...........: write the SNtimestep table :................... */

      if(ThisTask == 0)
	{
	  fprintf(FdSnInit, "\n[time stepping :: %d]\n" "%10s\t%20s\n", i, "time (Gyr)", "timestep (Gyr)");
	  for(j = 0; j < Nsteps[i]; j++)
	    fprintf(FdSnInit, "%8.5lg \t%8.5lg\n", SNtimesteps[i][0][j], SNtimesteps[i][1][j]);
	  fflush(FdSnInit);
	}
    }

  /* ...........: build arrays to interpolate a vs t :................... */

  accel = gsl_interp_accel_alloc();
  spline = gsl_spline_alloc(gsl_interp_cspline, TIME_INTERP_SIZE);

  astep = pow(10, log10(1.0 / 0.001) / TIME_INTERP_SIZE);
  aarray[0] = 0.001;
  tarray[0] = 0;
  cosmic_time = get_age(0.001);

  for(i = 1; i < TIME_INTERP_SIZE; i++)
    {
      aarray[i] = aarray[i - 1] * astep;
      tarray[i] = cosmic_time - get_age(aarray[i]);
    }
  gsl_spline_init(spline, tarray, aarray, TIME_INTERP_SIZE);

  /* */

  if(ThisTask == 0)
    fflush(stdout);

  /* ....... */

#ifdef LT_SEvDbg
  do_spread_dbg_list = (int *) mymalloc("do_spread_dbg_list", NTask * sizeof(int));
#endif

#ifdef LT_SEv_INFO
  Zmass = (double *) mymalloc("Zmass", SFs_dim * (SPECIES * 2) * LT_NMet * 4 * sizeof(double));
  memset(Zmass, 0, SFs_dim * (SPECIES * 2) * LT_NMet * 4 * sizeof(double));
  tot_Zmass = Zmass + SFs_dim * (SPECIES * 2) * LT_NMet;
  SNdata = tot_Zmass + SFs_dim * (SPECIES * 2) * LT_NMet;
  tot_SNdata = SNdata + SFs_dim * (SPECIES * 2) * LT_NMet;
#endif

  sfrrates = (double *) mymalloc("sfrrates", sizeof(double) * SFs_dim);
  totsfrrates = (double *) mymalloc("ttosfrrates", sizeof(double) * SFs_dim);

  sum_sm = (double *) mymalloc("sum_sm", SFs_dim * 4 * sizeof(double));
  memset(sum_sm, 0, SFs_dim * sizeof(double));

  total_sm = sum_sm + SFs_dim;
  sum_mass_stars = total_sm + SFs_dim;
  total_sum_mass_stars = sum_mass_stars + SFs_dim;

  return;
}