Beispiel #1
0
/*===========================================================================
* create a timeline for current cosmological model
*===========================================================================*/
void create_timeline2(double a_init, double a_fin, tlptr timeline)
{
   int    iloop;
   double a,t,omega,lambda,rhoc,hubble;
   
   for(iloop=0; iloop<MAXTIME2; iloop++)
     {
      a      = ((double)iloop+1.0)/(double)MAXTIME2 * (a_fin-a_init) + a_init;
      t      = calc_t(a);
      omega  = calc_omega(a);
      lambda = calc_lambda(a);
      hubble = H0    * sqrt(
                            simu.lambda0 * (1.-1./pow2(a))         +
                            simu.omega0  * (1./pow3(a)-1./pow2(a)) + 1./pow2(a));
      rhoc   = rhoc0 *     (
                            simu.lambda0*(1.-1./pow2(a))           +
                            simu.omega0*(1./pow3(a)-1./pow2(a))    + 1./pow2(a));
      
      timeline->a[iloop]      = a;
      timeline->t[iloop]      = t;
      timeline->omega[iloop]  = omega;
      timeline->lambda[iloop] = lambda;
      timeline->hubble[iloop] = hubble;
      timeline->age[iloop]    = t*Mpc/H0/Gyr;
      timeline->virial[iloop] = calc_virial(a);
     }
}
Beispiel #2
0
int main()
{
   int     no_outputs, i;
   double  zred, z_init, z_final, a_init, a_final, a;
   
   printf("============================\n");
   printf(" calculate age of Universe\n");
   printf("============================\n");
   printf("please give omega0:       ");
   scanf("%lf",&simu.omega0);
   printf("please give lambda0:      ");
   scanf("%lf",&simu.lambda0);
   printf("please give redshift z:   ");
   scanf("%lf",&zred);
   printf("\n");
   
   z_init  = 100.;
   z_final = 0.;
   a_init  = 1.0/(1.0+z_init);
   a_final = 1.0/(1.0+z_final);
   
   create_timeline2(a_init, a_final, &simu.timeline);
   
   
   a = 1./(1.+zred);
   printf("age = %lf/h Gyr\n",calc_t(a)*Mpc/H0/Gyr);
}
Beispiel #3
0
void testCalculate() {
	char str[64];
	int len=0, i, k=0;
	DParam dp;
	char strbuff[256] = "f(x)=-x^2";
	Function *f = NULL;
	double val[1];

	dp.values = val;

	f = (Function*)malloc(sizeof(Function));
	f->prefix = NULL;
	f->domain = NULL;
	f->criterias = NULL;
	f->str = NULL;
	f->len = 0;
	f->variableNode = NULL;
	f->numVarNode = 0;
	f->valLen = 0;

	//printf("Input function: ");
	//scanf("%s", &strbuff);
	len = strlen(strbuff);
	parseFunction(strbuff, len, f);
	if(getErrorCode() != NMATH_NO_ERROR) {
		printError(getErrorColumn(), getErrorCode());
		releaseFunct(f);
		free(f);
		return;
	} 

	if( f->valLen==0 ) {
		printf("This expression is not a function due to variables not determined.\n");
	}

		
	dp.error = NMATH_NO_ERROR;
	dp.t = f->prefix->list[0];
	dp.variables[0] = 'x';
	dp.values[0] = 2;
	//reduce_t(&dp);
	calc_t(&dp);
	if(dp.error == NMATH_NO_ERROR) {
		k = 0;
		printNMAST(dp.t, 0);
		printf("\n");
		toString(dp.t, str, &k, 64);
		f->prefix->list[0] = dp.t;
		printf("Calculating result: %lf\n", dp.retv);
	}

	//release token list

	releaseFunct(f);
	clearPool();
	free(f);
}
Beispiel #4
0
/*==================================================================================================
 * read_zred:
 *
 *     read a file than contains the redshifts of the _halos files used with MergerRates
 *     simultaneously calculates the corresponding age of the universe
 *
 *==================================================================================================*/
void read_zred(char zredfile[MAXSTRING], int nFiles, int need_simuparams)
{
  FILE *fpin;
  char  line[MAXSTRING];
  int   nzred;
  float fdummy;
  
  fpin = fopen(zredfile,"r");
  if(fpin == NULL) {
    fprintf(stderr,"Could not open %s.\nABORTING\n",zredfile);
    exit(0);
  }
  
  
  zred  = NULL;
  tage  = NULL;
  nzred = 0;
  
  fgets(line,MAXSTRING,fpin);
  while(!feof(fpin)) {
    if (strncmp(line,"#",1) != 0) {
      nzred++;
      zred          = (float *) realloc(zred, nzred*sizeof(float));
      tage          = (float *) realloc(tage, nzred*sizeof(float));
      
      if(need_simuparams == TRUE) {
        sscanf(line,"%f", &(zred[nzred-1]) );
        tage[nzred-1] = calc_t(1./(1.+zred[nzred-1])) * Mpc/H0/Gyr / hubble; // in [Gyr]
      }
      else {
        sscanf(line,"%f %f %f", &(zred[nzred-1]),fdummy, &(tage[nzred-1]));
      }
    }
    
    fgets(line,MAXSTRING,fpin);
  }
  
  // some sanity check
  if(nzred != nFiles) {
    fprintf(stderr,"you did not provide the correct number of redshifts:\n");
    fprintf(stderr,"  there are %d redshifts in %s\n",nzred,zredfile);
    fprintf(stderr,"  but there are %d redshifts needed!\nABORTING\n",nFiles);
    exit(0);
  }
  
  // in any case, add one final entry to zred[] and tage[] with zero in it to allow easier calcuation of dz and dt
  zred          = (float *) realloc(zred, (nzred+1)*sizeof(float));
  tage          = (float *) realloc(tage, (nzred+1)*sizeof(float));
  zred[nzred]   = 0.0;
  tage[nzred]   = 0.0;
  
  fclose(fpin);
}
Beispiel #5
0
/*==========================================================================
* calc_virial: calculates the virial overdensity
*==========================================================================*/
double calc_virial(double a)
{
  double virial, age, omega_ta, eta, reduce, t1, t2;
  
  /* Check for a manual overdensity and return it if specified. Nothing else to do here then. */
  if(simu.UserDvir > 0)
    virial = (double)(simu.UserDvir);
  else
   {
#ifdef DARK_ENERGY
	/* Calculation of STH collapse is NOT implemented for Dark Energy models. Print a warning message, here or somewhere else */
	fprintf(stderr, "Warning: the calculation of the virial overdensity in dynamical dark energy cosmologies is NOT implemented in AHF.\n");
#else
    /* Figure out how old the universe is */
    age      = calc_t(a);
    
    /*  Figure out how much overdensity we need to reach maximum expansion by
     half the age of the universe.  The overdense expansion factor is defined
     to be 1 at maximum. */
    omega_ta = collapse(age/(double)2., (double)1.e-8);
    
    
    /* Figure out how far an object collapses to Virial equilibrium. */
    eta      = (double)2.*simu.lambda0/omega_ta; ///pow3(a); this obscure a^3 factor will prevent virial to approach the SCDM value of 178 at high redshift; not sure why it was there in the first place!
    
    if (eta < ZERO)
     {
      reduce = 0.5;
     }
    else
     {
      t1      = 2.*eta;
      t2      = -(2. + eta);
      reduce  = cubic(t1, (double)0., t2, (double)1.);
     }
    
    /* as found in M.A.K. Gross' original version */
    virial = pow3(a) * omega_ta/simu.omega0/pow3(reduce);

    /* check whether we want virial in terms of RhoCrit */
    if(simu.UseRhoBack == FALSE)
      virial *= calc_omega(a);
    
#endif
   }

  return (virial);
}
Beispiel #6
0
/*====================================================================================================
 * startrun()
 *====================================================================================================*/
extern void startrun(char *paramfile, double *timecounter, double *timestep, int32_t *no_first_timestep)
{
	/* Read the parameters */
	local_startrunParams(paramfile);


  /* Now set up the logging */
	local_startrunLog();
	io_logging_part(global_io.log, "Setting up the run");
  
	/* FIXME Do some glueing FIXME */
	io.logfile = global_io.log->logfile;
  
	/* Open the file */
	local_startrunFopen();
  
	/* Set global_info */
	global_info.fst_part = NULL;
	global_info.no_part = UINT64_C(0);
#	ifdef WITH_MPI
	global_info.loadbal = loadbalance_new(global_io.log,
	                                      LOADBALANCE_EQUALPART,
	                                      SFC_CURVE_HILBERT,
                                        //	                                      LOADBALANCE_DOMAIN_LEVEL,
	                                      global_io.params->lb_level,
	                                      global_mpi.size);
#	endif
  
	/* Now read the initial conditions (sets the rest of global_info) */
	local_startrunRead();
  
	/* Load the dark energy tables for interpolation if DE is defined */
#ifdef DARK_ENERGY
	read_dark_energy_table(global_io.params->defile_name);
#endif

	/* Set the simulation parameters */
	local_startrunSimparams();
  
	/* Now set the returned simulation counter stuff thingies */
	local_startrunRetset(timecounter, timestep, no_first_timestep);
  
	/* Set global time counter */
	global.super_t = *timecounter;                      
	global.a       = calc_super_a(global.super_t);   
	global.t       = calc_t(global.a);            
	global.z       = 1./global.a - 1.;
  
#ifdef NO_EXPANSION
  global.a       = 1.0;
  global.t       = *timecounter;
  global.z       = 0.0;
  global.super_t = -1.;
#endif
  
	/* And now lets be so nice and close the file... */
	io_logging_section(global_io.log, "Tidying");
	io_file_close(global_io.log, &(global_io.file));


  
  write_parameterfile();
  
	return;
}
Beispiel #7
0
static void
local_startrunSimparams()
{
	io_logging_section(global_io.log, "Setting simulation parameter");
  
	io_logging_subsection(global_io.log, "Information from file");
#	ifdef WITH_MPI
	if (global_mpi.rank != 0) {
		io_logging_msg(global_io.log, INT32_C(4), "Not setting up myself, will receive.");
    fflush(NULL);
	} else {
#	else
   {
#	endif
		int32_t no_timestep;
    
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_BOXSIZE, (void *)&(simu.boxsize));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_OMEGA0, (void *)&(simu.omega0));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_OMEGAL, (void *)&(simu.lambda0));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_PMASS, (void *)&(simu.pmass));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_NOPART, (void *)&(simu.no_part));
#		ifdef MULTIMASS
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_NOVPART, (void *)&(simu.no_vpart));
#		else
		simu.no_vpart = (double)(simu.no_part);
#		endif
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_NOSPECIES, (void *)&(simu.no_species));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_AINITIAL, (void *)&(simu.a_initial));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_DOUBLE, (void *)&(simu.double_precision));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_MMASS, (void *)&(simu.multi_mass));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_MINWEIGHT, (void *)&(simu.min_weight));
		io_file_get(global_io.log, global_io.file, IO_FILE_GET_MAXWEIGHT, (void *)&(simu.max_weight));
    
		/* Copy over the information contained in the parameter file */
		simu.NGRID_DOM     = global_io.params->NGRID_DOM;
		simu.NGRID_MIN     = simu.NGRID_DOM;
		simu.Nth_dom       = global_io.params->Nth_dom;
		simu.Nth_ref       = global_io.params->Nth_ref;
    simu.lb_level      = global_io.params->lb_level;
    
    //fprintf(stderr,"simu.lb_level=%d global_io.params->lb_level=%d\n",simu.lb_level,global_io.params->lb_level);
    
    simu.MaxGatherRad  = global_io.params->MaxGatherRad;
    simu.UserDvir      = global_io.params->UserDvir;
    simu.UseRhoBack    = global_io.params->UseRhoBack;
		simu.NGRID_MAX     = global_io.params->NGRID_MAX;
		simu.AHF_MINPART   = global_io.params->AHF_MINPART;
		simu.AHF_VTUNE     = global_io.params->AHF_VTUNE;
    
    simu.GADGET_m2Msunh= global_io.params->GADGET_m2Msunh;
    simu.GADGET_l2Mpch = global_io.params->GADGET_l2Mpch;

#		ifdef AHF_LRSI
		simu.lrsi_beta     = global_io.params->lrsi_beta;
		simu.lrsi_r_s      = global_io.params->lrsi_r_s;
#		endif

#if (defined AHFmixHaloIDandSnapID || defined SUSSING2013)
    simu.isnap         = global_io.params->isnap;
#endif
    
		/* Set quantities given by constants */
#		ifdef NP_LIMIT
		simu.np_limit = TRUE;
#		else
		simu.np_limit = FALSE;
#		endif
		simu.mean_dens = (double) 1.0;
    
#ifdef MULTIMASS
    simu.multi_mass = 1;
#endif
    
		simu.mmfocus  = 0;
		simu.hydro    = 0;
		simu.magneto  = 0;
    
		/* Set the time unit */
		simu.t_unit = 1/H0; // we assume that we only ever deal with
		                    // cosmological simulations...
    
		/* Set derived quantities */
		simu.SHIFT     = ((double)0.5000000/(double) simu.NGRID_DOM);
		simu.z_initial = (double)1.0/simu.a_initial - (double)1.0;
		simu.a_final   = (double)1.0/((double)1.0 + simu.z_final);
		simu.FourPiG   = 1.5*simu.omega0;
    
		/* Do some sanity checks */
		io_file_get(global_io.log, global_io.file,
		            IO_FILE_GET_NOTSTEP, (void *)&(no_timestep));
    
		if ( isless(fabs(simu.a_initial-simu.a_final), ZERO) ) {
			io_logging_warn(global_io.log, INT32_C(3),
			                "Since a_initial = %g is equal to "
			                "a_final = %g, create_timeline will not "
			                "function correctly, setting "
			                "a_initial = .1 * a_final = %g",
			                simu.a_initial, simu.a_final,
			                simu.a_final / 10.0);
			simu.a_initial = simu.a_final / 10.0;
		}
		if ( simu.a_initial > simu.a_final ) {
			io_logging_warn(global_io.log, INT32_C(3),
			                "Since a_initial = %g is greater than "
			                "a_final = %g, create_timeline will not "
			                "function correctly, setting "
			                "a_initial = 0.001",
			                simu.a_initial, simu.a_final);
			simu.a_initial = 0.001;
      simu.z_initial = 1./simu.a_initial - 1.;
		}
   } /* End of stuff done solely by process 0 */
    
    io_logging_subsection(global_io.log, "Gathering from reading processes");
#	ifdef WITH_MPI
    io_logging_msg(global_io.log, INT32_C(4), "Broadcast of simulation parameters!");
    MPI_Bcast(&simu, sizeof(struct param_simu),
              MPI_BYTE,
              0,
              MPI_COMM_WORLD);
    io_logging_msg(global_io.log, INT32_C(4), "Broadcast done.");
#	endif
    
    
    /* Create timeline */
    io_logging_subsection(global_io.log, "Local setup");
    io_logging_msg(global_io.log, INT32_C(2), "Creating timeline from a = %g to a = %g",
                   simu.a_initial/10., simu.a_final);
    create_timeline(simu.a_initial/10., simu.a_final, &simu.timeline);
    io_logging_msg(global_io.log, INT32_C(2), "Timeline created");
    
    /* Set the SFC information */
    io_logging_msg(global_io.log, INT32_C(2), "Setting volume boundaries");
#	ifdef AHFrestart
    if(global_io.params->ic_filetype != IO_FILE_ARES)
     {
      fprintf(stderr,"AHFrestart only works together with ic_filetype=5\nPlease make sure that your input file is of this type and adjust AHF.input\nExiting now!\n");
      exit(0);
     }
    global_info.minkey = (sfc_key_t)( ((io_ares_t)(global_io.file))->header->minkey);
    global_info.maxkey = (sfc_key_t)( ((io_ares_t)(global_io.file))->header->maxkey);
    global_info.level = ((io_ares_t)(global_io.file))->header->lb_level;
#	else
    //    global_info.level = LOADBALANCE_DOMAIN_LEVEL;
    global_info.level = global_io.params->lb_level;
    global_info.minkey = (sfc_key_t)0;
    global_info.maxkey = (sfc_key_t)((1<<(3*global_info.level))-1);
#	endif
    global_info.ctype = SFC_CURVE_HILBERT;
    io_logging_msg(global_io.log, INT32_C(2),  "  minkey: %"SFC_PRIkey, global_info.minkey);
    io_logging_msg(global_io.log, INT32_C(2),  "  maxkey: %"SFC_PRIkey, global_info.maxkey);
    io_logging_msg(global_io.log, INT32_C(2),  "  level : %i", global_info.level);
    io_logging_msg(global_io.log, INT32_C(2),  "  ctype : %s", sfc_curve_typestr(global_info.ctype));
    
    /* Now that we have the timeline, set the time variables */
    simu.super_t_initial = calc_super_t(simu.a_initial);
    simu.super_t_final   = calc_super_t(simu.a_final);
    simu.t_initial       = calc_t(simu.a_initial);
    simu.t_final         = calc_t(simu.a_final);
    
    
    /* FIXME
     * Not set or not properly set simu-structure members:
     *
     * Hydro variables:
     * gamma
     * omegab
     * omegaDM
     * f_b
     * H_frac
     * T_init
     * e_init
     * med_weight
     * l_unit
     * m_unit
     *
     * AHF variable:
     * no_halos
     *
     * Unkown:
     * ifdef GAS_PARTICLES: no_gas
     * ifdef GADGET: no_stars
     *
     */
    /* Will use dummy values */
    simu.gamma    = 0.0;
    simu.omegab   = 0.0;
    simu.omegaDM  = simu.omega0;
    simu.f_b      = 0.0;
    simu.H_frac   = 0.0;
    simu.T_init   = 0.0;
    simu.B_init   = 0.0;
    simu.e_init   = 0.0;
    simu.no_halos = 0;
    simu.med_weight = simu.max_weight; // TODO: this is very conservative yet leads to more credible halos
    simu.l_unit = 0.0;
    simu.m_unit = 0.0;
    simu.no_gas   = 0;
    simu.no_stars = 0;
    
    //#	ifdef VERBOSE
    /* Be so kind and write everything to the logfile */
    io_logging_subsection(global_io.log, "Used simulation parameters");
    io_logging_msg(global_io.log, INT32_C(5), "simu.omega0          :  %g", simu.omega0);
    io_logging_msg(global_io.log, INT32_C(5), "simu.lambda0         :  %g", simu.lambda0);
    io_logging_msg(global_io.log, INT32_C(5), "simu.boxsize         :  %g", simu.boxsize);
    io_logging_msg(global_io.log, INT32_C(5), "simu.a_initial       :  %g", simu.a_initial);
    io_logging_msg(global_io.log, INT32_C(5), "simu.a_final         :  %g", simu.a_final);
    io_logging_msg(global_io.log, INT32_C(5), "simu.z_initial       :  %g", simu.z_initial);
    io_logging_msg(global_io.log, INT32_C(5), "simu.z_final         :  %g", simu.z_final);
    io_logging_msg(global_io.log, INT32_C(5), "simu.t_initial       :  %g", simu.t_initial);
    io_logging_msg(global_io.log, INT32_C(5), "simu.t_final         :  %g", simu.t_final);
    io_logging_msg(global_io.log, INT32_C(5), "simu.super_t_initial :  %g", simu.super_t_initial);
    io_logging_msg(global_io.log, INT32_C(5), "simu.super_t_final   :  %g", simu.super_t_final);
    io_logging_msg(global_io.log, INT32_C(5), "simu.mean_dens       :  %g", simu.mean_dens);
    io_logging_msg(global_io.log, INT32_C(5), "simu.FourPiG         :  %g", simu.FourPiG);
    io_logging_msg(global_io.log, INT32_C(5), "simu.pmass           :  %g", simu.pmass);
    io_logging_msg(global_io.log, INT32_C(5), "simu.t_unit          :  %g", simu.t_unit);
    io_logging_msg(global_io.log, INT32_C(5), "simu.gamma           :  %g", simu.gamma);
    io_logging_msg(global_io.log, INT32_C(5), "simu.timeline (ptr)  :  %p", (void*)&(simu.timeline));
    io_logging_msg(global_io.log, INT32_C(5), "simu.no_part         :  %lu", simu.no_part);
    io_logging_msg(global_io.log, INT32_C(5), "simu.no_vpart        :  %g", simu.no_vpart);
    io_logging_msg(global_io.log, INT32_C(5), "simu.no_species      :  %i", simu.no_species);
    io_logging_msg(global_io.log, INT32_C(5), "simu.no_halos        :  %lu", simu.no_halos);
    io_logging_msg(global_io.log, INT32_C(5), "simu.NGRID_DOM       :  %i", simu.NGRID_DOM);
    io_logging_msg(global_io.log, INT32_C(5), "simu.NGRID_MIN       :  %i", simu.NGRID_MIN);
    io_logging_msg(global_io.log, INT32_C(5), "simu.NGRID_MAX       :  %i", simu.NGRID_MAX);
    io_logging_msg(global_io.log, INT32_C(5), "simu.Nth_dom         :  %g", simu.Nth_dom);
    io_logging_msg(global_io.log, INT32_C(5), "simu.Nth_ref         :  %g", simu.Nth_ref);
    io_logging_msg(global_io.log, INT32_C(5), "simu.MaxGatherRad    :  %g", simu.MaxGatherRad);
    io_logging_msg(global_io.log, INT32_C(5), "simu.lb_level        :  %d", simu.lb_level);
    io_logging_msg(global_io.log, INT32_C(5), "simu.min_weight      :  %g", simu.min_weight);
    io_logging_msg(global_io.log, INT32_C(5), "simu.max_weight      :  %g", simu.max_weight);
    io_logging_msg(global_io.log, INT32_C(5), "simu.np_limit        :  %i", simu.np_limit);
    io_logging_msg(global_io.log, INT32_C(5), "simu.mmfocus         :  %i", simu.mmfocus);
    io_logging_msg(global_io.log, INT32_C(5), "simu.multi_mass      :  %i", simu.multi_mass);
    io_logging_msg(global_io.log, INT32_C(5), "simu.double_precision:  %i", simu.double_precision);
    //#	endif /* VERBOSE */
    
    
    //fprintf(stderr,"simu.lb_level=%d global_io.params->lb_level=%d\n",simu.lb_level,global_io.params->lb_level);

    
    return;
  }
  
  static void
  local_startrunRetset(double *timecounter,
                       double *timestep,
                       int32_t *no_first_timestep)
 {
	io_logging_subsection(global_io.log, "Setting time counter");
  
#	ifdef WITH_MPI
	if (global_mpi.rank == 0) {
#	else
   {
#	endif
		double a_current;
    
		io_file_get(global_io.log, global_io.file,
		            IO_FILE_GET_NOTSTEP, (void *)no_first_timestep);
		io_file_get(global_io.log, global_io.file,
		            IO_FILE_GET_TSTEP, (void *)timestep);
		io_file_get(global_io.log, global_io.file,
		            IO_FILE_GET_A, (void *)&a_current);
		*timecounter = calc_super_t(a_current);
   }
    
#	ifdef WITH_MPI
    MPI_Bcast(timecounter, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    MPI_Bcast(timestep, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    MPI_Bcast(no_first_timestep, 1, MPI_INT, 0, MPI_COMM_WORLD);
#	endif
    
    return;
  }
Beispiel #8
0
/*===========================================================================
* create a timeline for current cosmological model
*===========================================================================*/
void create_timeline(double a_init, double a_fin, tlptr timeline)
{
   int    iloop, iwrite_cosmo;
   double a,t,omega,lambda,rhoc,hubble,super_t,virial,growth,age,dummy,zred;
   
   FILE  *fpcosmo;
   char   cosmo_file[MAXSTRING], string[MAXSTRING];


#ifdef COSMOLOGY
   if(global_io.params->outfile_prefix != NULL)
     {
      strcpy(cosmo_file, global_io.params->outfile_prefix);
      strcat(cosmo_file,"cosmology");
      /*---------------------------------------------
         * check if there is already a .cosmology file
         *---------------------------------------------*/
      if( (fpcosmo = fopen(cosmo_file,"r")) == NULL )
        {
         iwrite_cosmo = TRUE;
        }
      else
        {
         iwrite_cosmo = FALSE;
         fclose(fpcosmo);
        }
     }
   else
      iwrite_cosmo = FALSE;

#else
   /*---------------------------------------------
    * do not write the .cosmology file whatsoever
    *---------------------------------------------*/
   iwrite_cosmo = FALSE;
#endif /* COSMOLOGY */

   /*------------------------------
    * create timeline from scratch
    *------------------------------*/
#ifndef WITH_MPI
   if(io.logfile != NULL)
     {
      fprintf(io.logfile,"\ncreating timeline from a=%g to a=%g (MAXTIME=%d) ... ",a_init,a_fin,MAXTIME);
      fflush(io.logfile);
     }
#endif
      
#ifdef WITH_OPENMP
#pragma omp parallel private(iloop, a, t, super_t, omega, lambda, hubble, rhoc) shared(timeline, simu, a_fin, a_init)
#pragma omp for schedule(static)
#endif
   for(iloop=0; iloop<MAXTIME; iloop++)
     {
      a       = ((double)iloop)/(double)(MAXTIME-1) * (a_fin-a_init) + a_init;
      t       = calc_t(a);
      super_t = calc_super_t(a);
      omega   = calc_omega(a);
      lambda  = calc_lambda(a);
      hubble  = calc_Hubble(a);
      rhoc    = rhoc0 *     (
                             simu.lambda0*(1.-1./pow2(a))           +
                             simu.omega0*(1./pow3(a)-1./pow2(a))    + 1./pow2(a));
      
      timeline->a[iloop]       = a;
      timeline->t[iloop]       = t;
      timeline->super_t[iloop] = super_t;      
      timeline->omega[iloop]   = omega;
      timeline->lambda[iloop]  = lambda;
      timeline->hubble[iloop]  = hubble;
      timeline->rhoc[iloop]    = rhoc;
      timeline->age[iloop]     = t * simu.t_unit*Mpc/Gyr;
      timeline->growth[iloop]  = calc_growth(a);
      
      // do >>not<< call calc_virial() here when using OpenMP as calc_virial() abuses simu.omega0!!!
      
     }
   
   if(iwrite_cosmo)
     {
     fpcosmo = fopen(cosmo_file,"w");
     fprintf(fpcosmo,"#     z(1)           a(2)    t[h^-1 Gyr](3)  Omega(4)    lambda(5)   hubble(6)   RhoCrit(7)     virial(8)      growth(9)        q(10)   super_t(11)\n");
     
     for(iloop=0; iloop<MAXTIME; iloop++)
        {
        /* calc_virial() temporarily changes simu.omega0 */
        timeline->virial[iloop] = calc_virial(timeline->a[iloop]);
          
        fprintf(fpcosmo,"%10.4f %16.10f %12.6f %12.6f %12.6f %12.4f %12.6g %12.6g %12.6g %12.6g  %12.6g\n",
                1.0/timeline->a[iloop]-1,
                timeline->a[iloop],
                timeline->t[iloop] * simu.t_unit*Mpc/Gyr,
                timeline->omega[iloop],
                timeline->lambda[iloop],
                timeline->hubble[iloop],
                timeline->rhoc[iloop],
                timeline->virial[iloop],
                timeline->growth[iloop],
                calc_q(timeline->a[iloop]),
                timeline->super_t[iloop]);
        fflush(fpcosmo);        
        }

      fclose(fpcosmo);
     }
     
#ifndef WITH_MPI
   if(io.logfile != NULL)
     {
      fprintf(io.logfile,"done\n\n");
      fflush(io.logfile);      
     }
#endif
   
#ifdef DEBUG_SUPERCOMOVING
   {
      double a_prev, t_prev, super_t_prev, a_mid;
      double dtc, dTc;
      
      iloop        = 0;
      a_prev       = ((double)iloop)/(double)(MAXTIME-1) * (a_fin-a_init) + a_init;
      t_prev       = calc_t(a_prev);
      super_t_prev = calc_super_t(a_prev);

      for(iloop=1; iloop<MAXTIME; iloop++)
        {
         a       = ((double)iloop)/(double)(MAXTIME-1) * (a_fin-a_init) + a_init;
         t       = calc_t(a);
         super_t = calc_super_t(a);
         
         dtc     = t       - t_prev;
         dTc     = super_t - super_t_prev;
         
         a_mid   = (a+a_prev)/2;
         
         fprintf(stderr,"z=%12.4f  a=%20.10f   t=%20.10f  super_t=%20.10f  dtc=%20.10f   dTc=%20.10f    dTc(dtc)=%20.10f  a=%20.10f     err=%g\n",
                 1./a-1.,a,t,super_t,dtc,dTc,dtc/(pow2(a_mid)),calc_super_a(super_t),fabs(dTc-dtc/(pow2(a_mid))));
         
         a_prev       = a;
         t_prev       = t;
         super_t_prev = super_t;
        }
   }
#endif

#ifdef COSMOLOGY_TERM
   exit(0);
#endif   

}
Beispiel #9
0
void interpfield_(float ***oldf, float ***newf, bool extend,
    int on1, float oo1, float od1,  /* old */
    int on2, float oo2, float od2,
    int on3, float oo3, float od3,
    int nn1, float no1, float nd1,  /* new */
    int nn2, float no2, float nd2,
    int nn3, float no3, float nd3)
{
  float *x1 = sf_floatalloc(nn1);
  float *x2 = sf_floatalloc(nn2);
  float *x3 = sf_floatalloc(nn3);
  int b1 = nn1;
  int b2 = nn2;
  int b3 = nn3;
  int e1 = 0;
  int e2 = 0;
  int e3 = 0;
  int ns = gs_ns;

  memset(newf[0][0], 0, sizeof(float)*nn1*nn2*nn3);

  x_b_e(on1, oo1, od1, nn1, no1, nd1, x1, &b1, &e1);
  x_b_e(on2, oo2, od2, nn2, no2, nd2, x2, &b2, &e2);
  x_b_e(on3, oo3, od3, nn3, no3, nd3, x3, &b3, &e3);

  /*sf_warning("b1,b2,b3: %d, %d, %d", b1, b2, b3);*/
  /*sf_warning("e1,e2,e3: %d, %d, %d", e1, e2, e3);*/
  /*for (int i = 0; i < nn3; i++) {*/
    /*sf_warning("%f", x3[i]);*/
  /*}*/

  int *k1  = sf_intalloc(nn1); assert(k1);
  int *k2  = sf_intalloc(nn2);
  int *k3  = sf_intalloc(nn3);
  int *t1    = sf_intalloc(nn1);
  int *t2    = sf_intalloc(nn2);
  int *t3    = sf_intalloc(nn3);
  int **c1 = sf_intalloc2(ns, nn1);
  int **c2 = sf_intalloc2(ns, nn2);
  int **c3 = sf_intalloc2(ns, nn3);

  calc_t(x1, k1, t1, nn1, gs_npts);
  calc_t(x2, k2, t2, nn2, gs_npts);
  calc_t(x3, k3, t3, nn3, gs_npts);


  up_clip(t1, nn1, gs_npts - 1);
  up_clip(t2, nn2, gs_npts - 1);
  up_clip(t3, nn3, gs_npts - 1);

  /*sf_warning("sumk1, sumk2, sumk3: %d, %d, %d", isum1(k1,nn1), isum1(k2,nn2), isum1(k3, nn3));*/
  /*sf_warning("sumt1, sumt2, sumt3: %d, %d, %d", isum1(t1,nn1), isum1(t2,nn2), isum1(t3, nn3));*/

  for (int is = 0; is < ns; is++) {
    for (int i1 = 0; i1 < nn1; i1++) {
      c1[i1][is] = k1[i1] - 4 + is;
    }
    for (int i2 = 0; i2 < nn2; i2++) {
      c2[i2][is] = k2[i2] - 4 + is;
    }
    for (int i3 = 0; i3 < nn3; i3++) {
      c3[i3][is] = k3[i3] - 4 + is;
    }
  }

  updown_cip(c1, ns, nn1, 0, on1-1);
  updown_cip(c2, ns, nn2, 0, on2-1);
  updown_cip(c3, ns, nn3, 0, on3-1);

  /*for (int i = 0; i < ns; i++) {*/
    /*sf_warning("c1[0][%d]: %d", i, c1[0][i]);*/
  /*}*/
  /*sf_warning("write c1, c2, c3");*/
  /*write2di("c1.rsf", c1, ns, nn1);*/
  /*write2di("c2.rsf", c2, ns, nn2);*/
  /*write2di("c3.rsf", c3, ns, nn3);*/

  /*write1di("t1.rsf", t1, nn1);*/
  /*exit(0);*/

  if (extend) {
    /*sf_warning("computation of interpolation with extend = true");*/
#ifdef _OPENMP
#pragma omp parallel for
#endif
    for (int i3 = 0; i3 < nn3; i3++) {
      for (int i2 = 0; i2 < nn2; i2++) {
        for (int i1 = 0; i1 < nn1; i1++) {
          for (int ic = 0; ic < ns; ic++) {
            for (int ib = 0; ib < ns; ib++) {
              for (int ia = 0; ia < ns; ia++) {
                newf[i3][i2][i1] +=
                  oldf[c3[i3][ic]][c2[i2][ib]][c1[i1][ia]] *
                  gs_sinc_table[t1[i1]][ia] *
                  gs_sinc_table[t2[i2]][ib] *
                  gs_sinc_table[t3[i3]][ic];
              }
            }
          }
        }
      }
    }
  } else {
    /*sf_warning("computation of interpolation without extend");*/
#ifdef _OPENMP
#pragma omp parallel for
#endif
    for (int i3 = b3; i3 <= e3; i3++) {
      for (int i2 = b2; i2 <= e2; i2++) {
        for (int i1 = b1; i1 <= e1; i1++) {
          for (int ic = 0; ic < ns; ic++) {
            for (int ib = 0; ib < ns; ib++) {
              for (int ia = 0; ia < ns; ia++) {
                newf[i3][i2][i1] +=
                  oldf[c3[i3][ic]][c2[i2][ib]][c1[i1][ia]] *
                  gs_sinc_table[t1[i1]][ia] *
                  gs_sinc_table[t2[i2]][ib] *
                  gs_sinc_table[t3[i3]][ic];
              }
            }
          }
        }
      }
    }

  }
  free(x1); free(x2); free(x3);
  free(k1); free(k2); free(k3);
  free(t1); free(t2); free(t3);
  free(*c1); free(*c2); free(*c3);
  free(c1); free(c2); free(c3);
}