Merge branch 'master' of bitbucket.org:glavaux/cosmotool

This commit is contained in:
Guilhem Lavaux 2015-02-26 10:39:49 +01:00
commit 8bef99b742
4 changed files with 92 additions and 60 deletions

View File

@ -124,6 +124,8 @@ double CosmoPower::powerEfstathiou(double k)
void CosmoPower::updateHuWigglesConsts() void CosmoPower::updateHuWigglesConsts()
{ {
double f_b = OMEGA_B / OMEGA_0;
double f_c = OMEGA_C / OMEGA_0;
double k_silk = 1.6 * pow(OMEGA_B * h * h, 0.52) * pow(OmegaEff, 0.73) * (1 + pow(10.4 * OmegaEff, -0.95)); double k_silk = 1.6 * pow(OMEGA_B * h * h, 0.52) * pow(OmegaEff, 0.73) * (1 + pow(10.4 * OmegaEff, -0.95));
double z_eq = 2.50e4 * OmegaEff * pow(Theta_27, -4); double z_eq = 2.50e4 * OmegaEff * pow(Theta_27, -4);
@ -141,14 +143,14 @@ void CosmoPower::updateHuWigglesConsts()
double a1 = pow(46.9 * OmegaEff, 0.670) * (1 + pow(32.1 * OmegaEff, -0.532)); double a1 = pow(46.9 * OmegaEff, 0.670) * (1 + pow(32.1 * OmegaEff, -0.532));
double a2 = pow(12.0 * OmegaEff, 0.424) * (1 + pow(45.0 * OmegaEff, -0.582)); double a2 = pow(12.0 * OmegaEff, 0.424) * (1 + pow(45.0 * OmegaEff, -0.582));
double alpha_c = pow(a1, -OMEGA_B/ OMEGA_0) * pow(a2, -pow(OMEGA_B / OMEGA_0, 3)); double alpha_c = pow(a1, -f_b) * pow(a2, -pow(f_b, 3));
double b1_betac = 0.944 * 1/(1 + pow(458 * OmegaEff, -0.708)); double b1_betac = 0.944 * 1/(1 + pow(458 * OmegaEff, -0.708));
double b2_betac = pow(0.395 * OmegaEff, -0.0266); double b2_betac = pow(0.395 * OmegaEff, -0.0266);
double beta_c = 1/ ( 1 + b1_betac * (pow(OMEGA_C / OMEGA_0, b2_betac) - 1) ); double beta_c = 1/ ( 1 + b1_betac * (pow(f_c, b2_betac) - 1) );
double alpha_b = 2.07 * k_eq * s * pow(1 + R_d, -0.75) * powG((1 + z_eq)/(1 + z_d)); double alpha_b = 2.07 * k_eq * s * pow(1 + R_d, -0.75) * powG((1 + z_eq)/(1 + z_d));
double beta_b = 0.5 + OMEGA_B / OMEGA_0 + (3 - 2 * OMEGA_B / OMEGA_0) * sqrt(pow(17.2 * OmegaEff, 2) + 1); double beta_b = 0.5 + f_b + (3 - 2 * f_b) * sqrt(pow(17.2 * OmegaEff, 2) + 1);
double beta_node = 8.41 * pow(OmegaEff, 0.435); double beta_node = 8.41 * pow(OmegaEff, 0.435);
ehu.k_silk = k_silk; ehu.k_silk = k_silk;

View File

@ -38,6 +38,8 @@ knowledge of the CeCILL license and that you accept its terms.
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include "load_data.hpp" #include "load_data.hpp"
#include "loadGadget.hpp" #include "loadGadget.hpp"
#include "fortran.hpp" #include "fortran.hpp"
@ -65,6 +67,13 @@ void loadGadgetHeader(UnformattedRead *f, GadgetHeader& h, SimuData *data, int i
data->Omega_M = h.Omega0 = f->readReal64(); data->Omega_M = h.Omega0 = f->readReal64();
data->Omega_Lambda = h.OmegaLambda = f->readReal64(); data->Omega_Lambda = h.OmegaLambda = f->readReal64();
data->Hubble = h.HubbleParam = f->readReal64(); data->Hubble = h.HubbleParam = f->readReal64();
(int)f->readInt32(); // stellarage
(int)f->readInt32(); // metals
for (int i = 0; i < 6; i++)
h.npartTotal[i] |= ((unsigned long)f->readInt32()) << 32;
(int)f->readInt32(); // entropy instead of u
h.flag_doubleprecision = f->readInt32();
f->endCheckpoint(true); f->endCheckpoint(true);
ssize_t NumPart = 0, NumPartTotal = 0; ssize_t NumPart = 0, NumPartTotal = 0;
@ -77,6 +86,12 @@ void loadGadgetHeader(UnformattedRead *f, GadgetHeader& h, SimuData *data, int i
data->TotalNumPart = NumPartTotal; data->TotalNumPart = NumPartTotal;
} }
template<typename T>
T myRead64(UnformattedRead *f) { return f->readReal64(); }
template<typename T>
T myRead32(UnformattedRead *f) { return f->readReal32(); }
SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
int loadflags, int GadgetFormat, int loadflags, int GadgetFormat,
SimuFilter filter) SimuFilter filter)
@ -86,6 +101,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
UnformattedRead *f; UnformattedRead *f;
GadgetHeader h; GadgetHeader h;
float velmul; float velmul;
boost::function0<double> readToDouble;
boost::function0<float> readToSingle;
long float_size;
if (id >= 0) { if (id >= 0) {
int k = snprintf(0, 0, "%s.%d", fname, id)+1; int k = snprintf(0, 0, "%s.%d", fname, id)+1;
@ -127,6 +145,15 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
abort(); abort();
} }
if (h.flag_doubleprecision) {
readToDouble = boost::bind(myRead64<double>, f);
readToSingle = boost::bind(myRead64<float>, f);
float_size = sizeof(double);
} else {
readToDouble = boost::bind(myRead32<double>, f);
readToSingle = boost::bind(myRead32<float>, f);
float_size = sizeof(float);
}
NumPart = data->NumPart; NumPart = data->NumPart;
NumPartTotal = data->TotalNumPart; NumPartTotal = data->TotalNumPart;
} }
@ -163,9 +190,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
f->beginCheckpoint(); f->beginCheckpoint();
for(int k = 0, p = 0; k < 6; k++) { for(int k = 0, p = 0; k < 6; k++) {
for(int n = 0; n < h.npart[k]; n++) { for(int n = 0; n < h.npart[k]; n++) {
data->Pos[0][p] = f->readReal32(); data->Pos[0][p] = readToSingle();
data->Pos[1][p] = f->readReal32(); data->Pos[1][p] = readToSingle();
data->Pos[2][p] = f->readReal32(); data->Pos[2][p] = readToSingle();
p++; p++;
} }
} }
@ -180,8 +207,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
} }
} else { } else {
long float_size = (h.flag_doubleprecision) ? sizeof(double) : sizeof(float);
// Skip positions // Skip positions
f->skip(NumPart * 3 * sizeof(float) + 2*4); f->skip(NumPart * 3 * float_size + 2*4);
} }
if (loadflags & NEED_VELOCITY) { if (loadflags & NEED_VELOCITY) {
@ -202,9 +230,9 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
for(int k = 0, p = 0; k < 6; k++) { for(int k = 0, p = 0; k < 6; k++) {
for(int n = 0; n < h.npart[k]; n++) { for(int n = 0; n < h.npart[k]; n++) {
// THIS IS GADGET 1 // THIS IS GADGET 1
data->Vel[0][p] = f->readReal32()*velmul; data->Vel[0][p] = readToSingle()*velmul;
data->Vel[1][p] = f->readReal32()*velmul; data->Vel[1][p] = readToSingle()*velmul;
data->Vel[2][p] = f->readReal32()*velmul; data->Vel[2][p] = readToSingle()*velmul;
p++; p++;
} }
} }
@ -222,7 +250,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
/// // TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!! /// // TODO: FIX THE UNITS OF THESE FUNKY VELOCITIES !!!
} else { } else {
// Skip velocities // Skip velocities
f->skip(NumPart*3*sizeof(float)+2*4); f->skip(NumPart*3*float_size+2*4);
} }
// Skip ids // Skip ids
@ -280,7 +308,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
if (h.mass[k] == 0) { if (h.mass[k] == 0) {
for(int n = 0; n < h.npart[k]; n++) for(int n = 0; n < h.npart[k]; n++)
{ {
data->Mass[l++] = f->readReal32(); data->Mass[l++] = readToSingle();
} }
} else { } else {
for(int n = 0; n < h.npart[k]; n++) for(int n = 0; n < h.npart[k]; n++)

View File

@ -46,6 +46,7 @@ namespace CosmoTool
static const int NEED_VELOCITY = 4; static const int NEED_VELOCITY = 4;
static const int NEED_TYPE = 8; static const int NEED_TYPE = 8;
static const int NEED_MASS = 16; static const int NEED_MASS = 16;
static const int NEED_DOUBLE_PRECISION = 32;
struct SimuParticle struct SimuParticle
{ {
@ -89,8 +90,7 @@ namespace CosmoTool
~SimuData() ~SimuData()
{ {
if (!noAuto) { if (!noAuto) {
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++) {
{
if (Pos[j]) if (Pos[j])
delete[] Pos[j]; delete[] Pos[j];
if (Vel[j]) if (Vel[j])
@ -105,8 +105,7 @@ namespace CosmoTool
} }
for (AttributeMap::iterator i = attributes.begin(); for (AttributeMap::iterator i = attributes.begin();
i != attributes.end(); i != attributes.end();
++i) ++i) {
{
if (i->second.second) if (i->second.second)
i->second.second(i->second.first); i->second.second(i->second.first);
} }
@ -125,8 +124,7 @@ namespace CosmoTool
void new_attribute(const std::string& n, void *p, FreeFunction free_func) void new_attribute(const std::string& n, void *p, FreeFunction free_func)
{ {
AttributeMap::iterator i = attributes.find(n); AttributeMap::iterator i = attributes.find(n);
if (i != attributes.end()) if (i != attributes.end()) {
{
if (i->second.second) if (i->second.second)
i->second.second(i->second.first); i->second.second(i->second.first);
} }

View File

@ -55,7 +55,11 @@ namespace CosmoTool {
double Omega0; double Omega0;
double OmegaLambda; double OmegaLambda;
double HubbleParam; double HubbleParam;
char fill[256- 6*4- 6*8- 2*8- 2*4- 6*4- 2*4 - 4*8]; /* fills to 256 Bytes */ int flag_doubleprecision;
int flag_ic_info;
float lpt_scalingfactor;
char fill[18]; /*!< fills to 256 Bytes */
char names[15][2];
}; };
struct ParticleState struct ParticleState