2010-07-02 20:49:30 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
general.hh - This file is part of MUSIC -
|
|
|
|
a code to generate multi-scale initial conditions
|
|
|
|
for cosmological simulations
|
|
|
|
|
|
|
|
Copyright (C) 2010 Oliver Hahn
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GENERAL_HH
|
|
|
|
#define __GENERAL_HH
|
|
|
|
|
2010-08-15 03:19:48 +02:00
|
|
|
#include "log.hh"
|
2010-07-02 20:49:30 +02:00
|
|
|
|
2010-11-13 00:05:45 +01:00
|
|
|
#include <cassert>
|
2010-07-02 20:49:30 +02:00
|
|
|
#include <omp.h>
|
|
|
|
|
|
|
|
#ifdef WITH_MPI
|
|
|
|
#ifdef MANNO
|
|
|
|
#include <mpi.h>
|
|
|
|
#else
|
|
|
|
#include <mpi++.h>
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
2010-10-26 20:37:31 +02:00
|
|
|
#ifdef FFTW3
|
|
|
|
#include <fftw3.h>
|
|
|
|
#if defined(SINGLE_PRECISION)
|
|
|
|
typedef float fftw_real;
|
|
|
|
#else
|
|
|
|
typedef double fftw_real;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
#if defined(SINGLE_PRECISION) and not defined(SINGLETHREAD_FFTW)
|
|
|
|
#include <srfftw.h>
|
|
|
|
#include <srfftw_threads.h>
|
|
|
|
#elif defined(SINGLE_PRECISION) and defined(SINGLETHREAD_FFTW)
|
|
|
|
#include <srfftw.h>
|
|
|
|
#elif not defined(SINGLE_PRECISION) and not defined(SINGLETHREAD_FFTW)
|
|
|
|
#include <drfftw.h>
|
|
|
|
#include <drfftw_threads.h>
|
|
|
|
#elif not defined(SINGLE_PRECISION) and defined(SINGLETHREAD_FFTW)
|
|
|
|
#include <drfftw.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SINGLE_PRECISION
|
|
|
|
typedef float real_t;
|
|
|
|
#else
|
|
|
|
typedef double real_t;
|
2010-07-02 20:49:30 +02:00
|
|
|
#endif
|
|
|
|
|
2010-10-26 20:37:31 +02:00
|
|
|
|
2010-07-02 20:49:30 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2010-11-13 00:05:45 +01:00
|
|
|
#include "config_file.hh"
|
|
|
|
//#include "mesh.hh"
|
2010-07-02 20:49:30 +02:00
|
|
|
|
2010-10-05 03:57:24 +02:00
|
|
|
|
2010-07-02 20:49:30 +02:00
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! compute square of argument
|
2010-07-02 20:49:30 +02:00
|
|
|
template< typename T >
|
|
|
|
inline T SQR( T a ){
|
|
|
|
return a*a;
|
|
|
|
}
|
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! compute cube of argument
|
2010-07-02 20:49:30 +02:00
|
|
|
template< typename T >
|
|
|
|
inline T CUBE( T a ){
|
|
|
|
return a*a*a;
|
|
|
|
}
|
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! compute 4th power of argument
|
2010-07-02 20:49:30 +02:00
|
|
|
template< typename T >
|
|
|
|
inline T POW4( T a ){
|
2010-09-01 06:59:31 +02:00
|
|
|
return SQR(SQR(a));
|
|
|
|
//return a*a*a*a;
|
2010-07-02 20:49:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! structure for cosmological parameters
|
2010-07-02 20:49:30 +02:00
|
|
|
typedef struct cosmology{
|
|
|
|
double
|
2010-09-01 06:59:31 +02:00
|
|
|
Omega_m, //!< baryon+dark matter density
|
|
|
|
Omega_b, //!< baryon matter density
|
|
|
|
Omega_L, //!< dark energy density
|
|
|
|
H0, //!< Hubble constant
|
|
|
|
nspect, //!< long-wave spectral index (scale free is nspect=1)
|
|
|
|
sigma8, //!< power spectrum normalization
|
|
|
|
//Gamma, //!< shape parameter (of historical interest, as a free parameter)
|
|
|
|
//fnl, //!< non-gaussian contribution parameter
|
|
|
|
//w0, //!< dark energy equation of state parameter (not implemented, i.e. =1 at the moment)
|
|
|
|
//wa, //!< dark energy equation of state parameter (not implemented, i.e. =1 at the moment)
|
|
|
|
dplus, //!< linear perturbation growth factor
|
|
|
|
pnorm, //!< actual power spectrum normalisation factor
|
|
|
|
vfact, //!< velocity<->displacement conversion factor in Zel'dovich approx.
|
|
|
|
WDMmass, //!< Warm DM particle mass
|
|
|
|
WDMg_x, //!< Warm DM particle degrees of freedom
|
|
|
|
astart; //!< expansion factor a for which to generate initial conditions
|
2010-11-13 00:05:45 +01:00
|
|
|
|
|
|
|
cosmology( config_file cf )
|
|
|
|
{
|
|
|
|
double zstart = cf.getValue<double>( "setup", "zstart" );
|
|
|
|
|
|
|
|
astart = 1.0/(1.0+zstart);
|
|
|
|
Omega_b = cf.getValue<double>( "cosmology", "Omega_b" );
|
|
|
|
Omega_m = cf.getValue<double>( "cosmology", "Omega_m" );
|
|
|
|
Omega_L = cf.getValue<double>( "cosmology", "Omega_L" );
|
|
|
|
H0 = cf.getValue<double>( "cosmology", "H0" );
|
|
|
|
sigma8 = cf.getValue<double>( "cosmology", "sigma_8" );
|
|
|
|
nspect = cf.getValue<double>( "cosmology", "nspec" );
|
|
|
|
WDMg_x = cf.getValueSafe<double>( "cosmology", "WDMg_x", 1.5 );
|
|
|
|
WDMmass = cf.getValueSafe<double>( "cosmology", "WDMmass", 0.0 );
|
|
|
|
|
|
|
|
dplus = 0.0;
|
|
|
|
pnorm = 0.0;
|
|
|
|
vfact = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cosmology( void )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2010-07-02 20:49:30 +02:00
|
|
|
}Cosmology;
|
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! basic box/grid/refinement structure parameters
|
2010-07-02 20:49:30 +02:00
|
|
|
typedef struct {
|
|
|
|
unsigned levelmin, levelmax;
|
|
|
|
double boxlength;
|
|
|
|
std::vector<unsigned> offx,offy,offz,llx,lly,llz;
|
|
|
|
}Parameters;
|
|
|
|
|
2010-09-01 06:59:31 +02:00
|
|
|
//! measure elapsed wallclock time
|
2010-07-02 20:49:30 +02:00
|
|
|
inline double time_seconds( void )
|
|
|
|
{
|
|
|
|
#ifdef WITH_MPI
|
|
|
|
return MPI_Wtime();
|
|
|
|
#else
|
|
|
|
return ((double) clock()) / CLOCKS_PER_SEC;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-17 01:41:40 +01:00
|
|
|
|
|
|
|
inline bool is_number(const std::string& s)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < s.length(); i++)
|
|
|
|
if (!std::isdigit(s[i])&&s[i]!='-' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-02 20:49:30 +02:00
|
|
|
#endif
|