Moved source codes into new subdirectories to make the organization cleaner. Created new CMakeLists accordingly.

This commit is contained in:
Guilhem Lavaux 2012-10-30 13:55:29 -04:00
parent f6fae36329
commit 4182c30485
13 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,365 @@
#include <healpix_map.h>
#include <healpix_map_fitsio.h>
#include <boost/format.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "generateFromCatalog_conf.h"
#include "contour_pixels.hpp"
#include <netcdfcpp.h>
#include <CosmoTool/fortran.hpp>
using namespace std;
using boost::format;
using namespace CosmoTool;
struct NYU_Data
{
int index;
int sector;
int region;
double ra, dec;
double cz;
double fgotten;
double phi_z;
};
struct Position
{
double xyz[3];
};
struct ParticleData
{
vector<int> id_gal;
int id_mask;
vector<Position> pos;
double box[3][2];
double Lmax;
};
typedef vector<NYU_Data> NYU_VData;
void loadData(const string& fname, NYU_VData & data)
{
ifstream f(fname.c_str());
while (!f.eof())
{
NYU_Data d;
f >> d.index >> d.sector >> d.region >> d.ra >> d.dec >> d.cz >> d.fgotten >> d.phi_z;
data.push_back(d);
}
}
void generateGalaxiesInCube(NYU_VData& data, ParticleData& output_data)
{
double d2r = M_PI/180;
output_data.pos.resize(data.size());
output_data.id_gal.resize(data.size());
for (int j = 0; j < 3; j++)
{
output_data.box[j][0] = -INFINITY;
output_data.box[j][1] = INFINITY;
}
for (int i = 0; i < data.size(); i++)
{
double ra = data[i].ra*d2r, dec = data[i].dec*d2r;
Position& p = output_data.pos[i];
p.xyz[0] = data[i].cz*cos(ra)*cos(dec);
p.xyz[1] = data[i].cz*sin(ra)*cos(dec);
p.xyz[2] = data[i].cz*sin(dec);
output_data.id_gal[i] = data[i].index;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0])
output_data.box[j][0] = p.xyz[j];
if (p.xyz[j] < output_data.box[j][1])
output_data.box[j][1] = p.xyz[j];
}
}
cout << format("Galaxy position generated: %d galaxies") % output_data.pos.size() << endl;
cout << format("box is %g < x < %g; %g < y < %g; %g < z < %g")
% (1e-2*output_data.box[0][1]) % (1e-2*output_data.box[0][0])
% (1e-2*output_data.box[1][1]) % (1e-2*output_data.box[1][0])
% (1e-2*output_data.box[2][1]) % (1e-2*output_data.box[2][0]) << endl;
}
static double cube(double x)
{
return x*x*x;
}
void generateBoxMask(generateFromCatalog_info& args ,
Healpix_Map<float>& mask,
vector<int>& pixel_list,
NYU_VData& data,
ParticleData& output_data)
{
int idx = -1;
int insertion = 0;
double volume = pixel_list.size()*1.0/mask.Npix()*4*M_PI;
int numToInsert;
idx = output_data.id_mask;
cout << "Generate box mask..." << endl;
double Rmax = output_data.Lmax, t = args.box_thickness_arg;
output_data.Lmax += args.box_thickness_arg;
volume *= Rmax*Rmax/1e6 * args.box_thickness_arg;
numToInsert = (int)floor(volume*args.box_density_arg);
for (int i = 0; i < numToInsert; i++)
{
Position p;
bool stop_here;
do
{
int p0 = (int)floor(drand48()*pixel_list.size());
vec3 v = mask.pix2vec(pixel_list[p0]);
double r = Rmax*pow(drand48()*(cube(1+t/Rmax)-1) + 1,1./3);
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
stop_here = true;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0] ||
p.xyz[j] < output_data.box[j][1])
stop_here = false;
}
}
while (!stop_here);
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
insertion++;
}
}
void generateSurfaceMask(generateFromCatalog_info& args ,
Healpix_Map<float>& mask,
vector<int>& pixel_list,
NYU_VData& data,
ParticleData& output_data)
{
// Find the first free index
int idx = -1;
int insertion = 0;
double volume = pixel_list.size()*1.0/mask.Npix()*4*M_PI;
int numToInsert;
for (int i = 0; i < output_data.id_gal.size(); i++)
{
if (idx < output_data.id_gal[i])
idx = output_data.id_gal[i]+1;
}
output_data.id_mask = idx;
cout << "Generate surface mask..." << endl;
double Rmax = -1;
for (int j = 0; j < 3; j++)
{
Rmax = max(Rmax, max(output_data.box[j][0], -output_data.box[j][1]));
}
output_data.Lmax = Rmax;
cout << format("Rmax is %g, surface volume is %g") % (Rmax/100) % (volume/(4*M_PI)) << endl;
volume *= Rmax*Rmax*Rmax/3/1e6;
numToInsert = (int)floor(volume*args.density_fake_arg);
cout << format("3d volume to fill: %g (Mpc/h)^3") % volume << endl;
cout << format("Will insert %d particles") % numToInsert << endl;
double pct = 0;
for (int i = 0; i < numToInsert; i++)
{
double new_pct = i*100./numToInsert;
if (new_pct-pct > 5.)
{
pct = new_pct;
cout << format(" .. %3.0f %%") % pct << endl;
}
Position p;
bool stop_here;
do
{
int p0 = (int)floor(drand48()*pixel_list.size());
vec3 v = mask.pix2vec(pixel_list[p0]);
double r = Rmax*pow(drand48(),1./3);
p.xyz[0] = v.x * r;
p.xyz[1] = v.y * r;
p.xyz[2] = v.z * r;
stop_here = true;
for (int j = 0; j < 3; j++)
{
if (p.xyz[j] > output_data.box[j][0] ||
p.xyz[j] < output_data.box[j][1])
stop_here = false;
}
}
while (!stop_here);
output_data.pos.push_back(p);
output_data.id_gal.push_back(idx);
insertion++;
}
cout << format("Done. Inserted %d particles.") % insertion << endl;
}
void saveData(ParticleData& pdata)
{
NcFile f("particles.nc", NcFile::Replace);
assert(f.is_valid());
NcDim *d = f.add_dim("space", 3);
NcDim *p = f.add_dim("Np", pdata.pos.size());
NcVar *v = f.add_var("particles", ncDouble, d, p);
double *x = new double[pdata.pos.size()];
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < pdata.pos.size(); i++)
x[i] = pdata.pos[i].xyz[j];
v->put_rec(d, x, j);
}
v = f.add_var("id_gal", ncInt, p);
v->put(&pdata.id_gal[0], pdata.id_gal.size());
delete[] x;
}
void saveForZobov(ParticleData& pdata, const string& fname, const string& paramname)
{
UnformattedWrite f(fname);
static const char axis[] = { 'X', 'Y', 'Z' };
double Lmax = pdata.Lmax;
f.beginCheckpoint();
f.writeInt32(pdata.pos.size());
f.endCheckpoint();
for (int j = 0; j < 3; j++)
{
cout << format("Writing %c components...") % axis[j] << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < pdata.pos.size(); i++)
{
f.writeReal32((pdata.pos[i].xyz[j]+Lmax)/(2*Lmax));
}
f.endCheckpoint();
}
NcFile fp(paramname.c_str(), NcFile::Replace);
fp.add_att("range_x_min", -Lmax);
fp.add_att("range_x_max", Lmax);
fp.add_att("range_y_min", -Lmax);
fp.add_att("range_y_max", Lmax);
fp.add_att("range_z_min", -Lmax);
fp.add_att("range_z_max", Lmax);
NcDim *NumPart_dim = fp.add_dim("numpart_dim", pdata.pos.size());
NcVar *v = fp.add_var("particle_ids", ncInt, NumPart_dim);
NcVar *v2 = fp.add_var("expansion", ncDouble, NumPart_dim);
double *expansion_fac = new double[pdata.pos.size()];
for (int i = 0; i < pdata.pos.size(); i++)
expansion_fac[i] = 1.0;
v->put(&pdata.id_gal[0], pdata.id_gal.size());
v2->put(expansion_fac, pdata.pos.size());
delete[] expansion_fac;
}
int main(int argc, char **argv)
{
generateFromCatalog_info args_info;
generateFromCatalog_conf_params args_params;
generateFromCatalog_conf_init(&args_info);
generateFromCatalog_conf_params_init(&args_params);
args_params.check_required = 0;
if (generateFromCatalog_conf_ext (argc, argv, &args_info, &args_params))
return 1;
if (!args_info.configFile_given)
{
if (generateFromCatalog_conf_required (&args_info, GENERATEFROMCATALOG_CONF_PACKAGE))
return 1;
}
else
{
args_params.check_required = 1;
args_params.initialize = 0;
if (generateFromCatalog_conf_config_file (args_info.configFile_arg,
&args_info,
&args_params))
return 1;
}
generateFromCatalog_conf_print_version();
cout << "Loading NYU data..." << endl;
vector<NYU_Data> data;
Healpix_Map<float> o_mask;
vector<int> pixel_list;
ParticleData output_data;
loadData(args_info.catalog_arg, data);
cout << "Loading mask..." << endl;
read_Healpix_map_from_fits(args_info.mask_arg, o_mask);
Healpix_Map<float> mask;
mask.SetNside(128, RING);
mask.Import(o_mask);
computeContourPixels(mask,pixel_list);
// We compute a cube holding all the galaxies + the survey surface mask
generateGalaxiesInCube(data, output_data);
generateSurfaceMask(args_info, mask, pixel_list, data, output_data);
computeFilledPixels(mask,pixel_list);
generateBoxMask(args_info, mask, pixel_list, data, output_data);
saveForZobov(output_data, args_info.output_arg, args_info.params_arg);
// saveData(output_data);
return 0;
}

View file

@ -0,0 +1,14 @@
package "generateFromCatalog"
version "alpha"
option "configFile" - "Configuration filename" string optional
option "catalog" - "Input NYU-VAGC catalog" string required
option "mask" - "Healpix mask of unobserved data (in Equatorial coordinates)" string required
option "density_fake" - "Number density of boundary fake tracers (1 h^3/ Mpc^3)" double optional default="1"
option "output" - "Filename of particle datafile" string required
option "params" - "Output parameters of the datacube" string required
option "box_thickness" - "Thickness of the limiting mask" double optional default="1"
option "box_density" - "Fake Galaxy density on the box" double optional default="1"

View file

@ -0,0 +1,568 @@
#include <cmath>
#include <cassert>
#include <iostream>
#include <fstream>
#include <string>
#include <CosmoTool/loadSimu.hpp>
#include <CosmoTool/loadRamses.hpp>
#include <CosmoTool/loadGadget.hpp>
#include <CosmoTool/loadFlash.hpp>
#include <CosmoTool/interpolate.hpp>
#include <CosmoTool/fortran.hpp>
#include "generateMock_conf.h"
#include "gslIntegrate.hpp"
#include <netcdfcpp.h>
using namespace std;
using namespace CosmoTool;
#define LIGHT_SPEED 299792.458
static double gadgetUnit=1e-3;
SimuData *doLoadRamses(const char *basename, int baseid, int velAxis, bool goRedshift)
{
SimuData *d, *outd;
d = loadRamsesSimu(basename, baseid, -1, true, 0);
outd = new SimuData;
outd->NumPart = d->TotalNumPart;
outd->BoxSize = d->BoxSize;
outd->TotalNumPart = outd->NumPart;
outd->Hubble = d->Hubble;
outd->Omega_Lambda = d->Omega_Lambda;
outd->Omega_M = d->Omega_M;
outd->time = d->time;
for (int k = 0; k < 3; k++)
outd->Pos[k] = new float[outd->NumPart];
outd->Vel[2] = new float[outd->NumPart];
delete d;
int curCpu = 0;
cout << "loading cpu 0 " << endl;
while (d = loadRamsesSimu(basename, baseid, curCpu, true, NEED_POSITION|NEED_VELOCITY|NEED_GADGET_ID))
{
for (int k = 0; k < 3; k++)
for (int i = 0; i < d->NumPart; i++)
{
assert(d->Id[i] >= 1);
assert(d->Id[i] <= outd->TotalNumPart);
outd->Pos[k][d->Id[i]-1] = d->Pos[k][i];
outd->Vel[2][d->Id[i]-1] = d->Vel[velAxis][i];
}
if (goRedshift)
for (int i = 0; i < d->NumPart; i++)
outd->Pos[velAxis][d->Id[i]-1] += d->Vel[velAxis][i]/100.;
delete d;
curCpu++;
cout << "loading cpu " << curCpu << endl;
}
return outd;
}
SimuData *myLoadGadget(const char *fname, int id, int flags)
{
SimuData *sim = loadGadgetMulti(fname, id, flags);
sim->BoxSize *= gadgetUnit*1000;
for (int j = 0; j < 3; j++)
{
if (sim->Pos[j] != 0) {
for (long i = 0; i < sim->NumPart; i++)
sim->Pos[j][i] *= gadgetUnit*1000;
}
}
return sim;
}
SimuData *doLoadSimulation(const char *gadgetname, int velAxis, bool goRedshift, SimuData *(*loadFunction)(const char *fname, int id, int flags))
{
SimuData *d, *outd;
bool singleFile = false;
try
{
d = loadFunction(gadgetname, -1, 0);
singleFile = true;
}
catch (const NoSuchFileException& e)
{
try
{
d = loadFunction(gadgetname, 0, 0);
}
catch(const NoSuchFileException& e)
{
return 0;
}
}
outd = new SimuData;
outd->NumPart = d->TotalNumPart;
outd->BoxSize = d->BoxSize/1000;
outd->TotalNumPart = outd->NumPart;
outd->Hubble = d->Hubble;
outd->Omega_Lambda = d->Omega_Lambda;
outd->Omega_M = d->Omega_M;
outd->time = d->time;
for (int k = 0; k < 3; k++)
outd->Pos[k] = new float[outd->NumPart];
outd->Vel[2] = new float[outd->NumPart];
delete d;
int curCpu = singleFile ? -1 : 0;
cout << "loading file 0 " << endl;
try
{
while (1)
{
d = loadFunction(gadgetname, curCpu, NEED_POSITION|NEED_VELOCITY|NEED_GADGET_ID);
for (int k = 0; k < 3; k++)
for (int i = 0; i < d->NumPart; i++)
{
assert(d->Id[i] >= 1);
assert(d->Id[i] <= outd->TotalNumPart);
outd->Pos[k][d->Id[i]-1] = d->Pos[k][i]/1000;
outd->Vel[2][d->Id[i]-1] = d->Vel[velAxis][i];
}
if (goRedshift)
for (int i = 0; i < d->NumPart; i++)
outd->Pos[velAxis][d->Id[i]-1] += d->Vel[velAxis][i]/100.;
delete d;
if (singleFile)
break;
curCpu++;
cout << "loading file " << curCpu << endl;
}
}
catch (const NoSuchFileException& e)
{
}
return outd;
}
static double cubic(double a)
{
return a*a*a;
}
struct TotalExpansion
{
double Omega_M, Omega_L;
double operator()(double z)
{
return 1/sqrt(Omega_M*cubic(1+z) + Omega_L);
}
};
Interpolate make_cosmological_redshift(double OM, double OL, double z0, double z1, int N = 1000)
{
TotalExpansion e_computer;
double D_tilde, Q, Qprime;
InterpolatePairs pairs;
e_computer.Omega_M = OM;
e_computer.Omega_L = OL;
pairs.resize(N);
ofstream f("comoving_distance.txt");
for (int i = 0; i < N; i++)
{
double z = z0 + (z1-z0)/N*i;
pairs[i].second = z;
pairs[i].first = gslIntegrate(e_computer, 0, z, 1e-3);
f << z << " " << pairs[i].first << endl;
}
return buildFromVector(pairs);
}
void metricTransform(SimuData *data, int axis, bool reshift, bool pecvel, double*& expfact, bool cosmo_flag)
{
int x0, x1, x2;
switch (axis) {
case 0:
x0 = 1; x1 = 2; x2 = 0;
break;
case 1:
x0 = 0; x1 = 2; x2 = 1;
break;
case 2:
x0 = 0; x1 = 1; x2 = 2;
break;
default:
abort();
}
double z0 = 1/data->time - 1;
Interpolate z_vs_D = make_cosmological_redshift(data->Omega_M, data->Omega_Lambda, 0., z0+2*data->BoxSize*100/LIGHT_SPEED); // Redshift 2*z0 should be sufficient ?
double z_base = reshift ? z0 : 0;
TotalExpansion e_computer;
double baseComovingDistance;
float vmax = 0;
expfact = new double[data->NumPart];
cout << "Using base redshift z=" << z0 << endl;
e_computer.Omega_M = data->Omega_M;
e_computer.Omega_L = data->Omega_Lambda;
baseComovingDistance = LIGHT_SPEED/100.* gslIntegrate(e_computer, 0, z0, 1e-3);
cout << "Comoving distance = " << baseComovingDistance << " Mpc/h" << endl;
cout << "Add peculiar velocities ? -> " << (pecvel ? " yes " : " no ") << endl;
for (uint32_t i = 0; i < data->NumPart; i++)
{
float& x = data->Pos[x0][i];
float& y = data->Pos[x1][i];
float& z = data->Pos[x2][i];
float& v = data->Vel[2][i];
float z_old = z;
double reduced_red = (z + baseComovingDistance)*100./LIGHT_SPEED;
try
{
// Distorted redshift
if (reduced_red == 0)
z = 0;
else if (cosmo_flag)
z = (z_vs_D.compute(reduced_red)-z_base)*LIGHT_SPEED/100.;
else
z = reduced_red*LIGHT_SPEED/100.0;
expfact[i] = z / z_old;
// Add peculiar velocity
if (pecvel) {
vmax = std::max(v,vmax);
z += v/100;
}
}
catch(const InvalidRangeException& e) {
cout << "Trying to interpolate out of the tabulated range." << endl;
cout << "The offending value is z=" << reduced_red << endl;
abort();
}
}
cout << "vmax=" << vmax << endl;
}
void generateOutput(SimuData *data, int axis,
const std::string& fname)
{
UnformattedWrite f(fname);
cout << "Generating output particles to " << fname << endl;
int x0, x1, x2;
switch (axis) {
case 0:
x0 = 1; x1 = 2; x2 = 0;
break;
case 1:
x0 = 0; x1 = 2; x2 = 1;
break;
case 2:
x0 = 0; x1 = 1; x2 = 2;
break;
default:
abort();
}
f.beginCheckpoint();
f.writeInt32(data->NumPart);
f.endCheckpoint();
cout << "Writing X components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < data->NumPart; i++)
{
f.writeReal32(data->Pos[x0][i]);
}
f.endCheckpoint();
cout << "Writing Y components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < data->NumPart; i++)
{
f.writeReal32(data->Pos[x1][i]);
}
f.endCheckpoint();
cout << "Writing Z components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < data->NumPart; i++)
{
f.writeReal32(data->Pos[x2][i]);
}
f.endCheckpoint();
}
void makeBoxFromParameter(SimuData *simu, double *efac, SimuData* &boxed, generateMock_info& args_info)
{
NcFile f(args_info.inputParameter_arg);
NcVar *v;
int *particle_id;
double *expansion_fac;
boxed = new SimuData;
boxed->Hubble = simu->Hubble;
boxed->Omega_M = simu->Omega_M;
boxed->Omega_Lambda = simu->Omega_Lambda;
boxed->time = simu->time;
boxed->BoxSize = simu->BoxSize;
NcVar *v_id = f.get_var("particle_ids");
long *edges1;
double ranges[3][2];
double mul[3];
edges1 = v_id->edges();
assert(v_id->num_dims()==1);
boxed->NumPart = edges1[0];
delete[] edges1;
particle_id = new int[boxed->NumPart];
v_id->get(particle_id, boxed->NumPart);
ranges[0][0] = f.get_att("range_x_min")->as_double(0);
ranges[0][1] = f.get_att("range_x_max")->as_double(0);
ranges[1][0] = f.get_att("range_y_min")->as_double(0);
ranges[1][1] = f.get_att("range_y_max")->as_double(0);
ranges[2][0] = f.get_att("range_z_min")->as_double(0);
ranges[2][1] = f.get_att("range_z_max")->as_double(0);
for (int j = 0; j < 3; j++)
{
boxed->Pos[j] = new float[boxed->NumPart];
boxed->Vel[j] = 0;
mul[j] = 1.0/(ranges[j][1] - ranges[j][0]);
}
uint32_t k = 0;
for (uint32_t i = 0; i < boxed->NumPart; i++)
{
int id = particle_id[i];
for (int j = 0; j < 3; j++)
{
boxed->Pos[j][i] = (simu->Pos[j][id]-ranges[j][0])*mul[j];
}
}
delete[] particle_id;
}
void makeBox(SimuData *simu, double *efac, SimuData *&boxed, generateMock_info& args_info)
{
float subsample = args_info.subsample_given ? args_info.subsample_arg : 1.0;
uint32_t goodParticles = 0;
double ranges[3][2] = {
{ args_info.rangeX_min_arg, args_info.rangeX_max_arg },
{ args_info.rangeY_min_arg, args_info.rangeY_max_arg },
{ args_info.rangeZ_min_arg, args_info.rangeZ_max_arg }
};
double mul[3];
float minmax[2][3];
int *particle_id;
bool *random_acceptance = 0;
boxed = new SimuData;
boxed->Hubble = simu->Hubble;
boxed->Omega_M = simu->Omega_M;
boxed->Omega_Lambda = simu->Omega_Lambda;
boxed->time = simu->time;
boxed->BoxSize = simu->BoxSize;
random_acceptance = new bool[simu->NumPart];
for (int j = 0; j < 3; j++) minmax[1][j] = minmax[0][j] = simu->Pos[j][0];
for (uint32_t i = 0; i < simu->NumPart; i++)
{
bool acceptance = true;
for (int j = 0; j < 3; j++) {
acceptance =
acceptance &&
(simu->Pos[j][i] > ranges[j][0]) &&
(simu->Pos[j][i] < ranges[j][1]);
minmax[0][j] = min(simu->Pos[j][i], minmax[0][j]);
minmax[1][j] = max(simu->Pos[j][i], minmax[1][j]);
}
random_acceptance[i] = acceptance && (drand48() <= subsample);
if (random_acceptance[i])
goodParticles++;
}
cout << "Min position = " << minmax[0][0] << " " << minmax[0][1] << " " << minmax[0][2] << endl;
cout << "Max position = " << minmax[1][0] << " " << minmax[1][1] << " " << minmax[1][2] << endl;
for (int j = 0; j < 3; j++)
{
boxed->Pos[j] = new float[goodParticles];
boxed->Vel[j] = 0;
mul[j] = 1.0/(ranges[j][1] - ranges[j][0]);
}
boxed->NumPart = goodParticles;
particle_id = new int[goodParticles];
double *expansion_fac = new double[goodParticles];
uint32_t k = 0;
for (uint32_t i = 0; i < simu->NumPart; i++)
{
bool acceptance = random_acceptance[i];
if (acceptance)
{
for (int j = 0; j < 3; j++)
{
boxed->Pos[j][k] = (simu->Pos[j][i]-ranges[j][0])*mul[j];
assert(boxed->Pos[j][k] > 0);
assert(boxed->Pos[j][k] < 1);
}
particle_id[k] = i;
expansion_fac[k] = efac[i];
k++;
}
}
delete[] random_acceptance;
NcFile f(args_info.outputParameter_arg, NcFile::Replace);
f.add_att("range_x_min", ranges[0][0]);
f.add_att("range_x_max", ranges[0][1]);
f.add_att("range_y_min", ranges[1][0]);
f.add_att("range_y_max", ranges[1][1]);
f.add_att("range_z_min", ranges[2][0]);
f.add_att("range_z_max", ranges[2][1]);
NcDim *NumPart_dim = f.add_dim("numpart_dim", boxed->NumPart);
NcVar *v = f.add_var("particle_ids", ncInt, NumPart_dim);
NcVar *v2 = f.add_var("expansion", ncDouble, NumPart_dim);
v->put(particle_id, boxed->NumPart);
v2->put(expansion_fac, boxed->NumPart);
delete[] particle_id;
delete[] expansion_fac;
}
int main(int argc, char **argv)
{
generateMock_info args_info;
generateMock_conf_params args_params;
SimuData *simu, *simuOut;
generateMock_conf_init(&args_info);
generateMock_conf_params_init(&args_params);
args_params.check_required = 0;
if (generateMock_conf_ext (argc, argv, &args_info, &args_params))
return 1;
if (!args_info.configFile_given)
{
if (generateMock_conf_required (&args_info, GENERATEMOCK_CONF_PACKAGE))
return 1;
}
else
{
args_params.check_required = 1;
args_params.initialize = 0;
if (generateMock_conf_config_file (args_info.configFile_arg,
&args_info,
&args_params))
return 1;
}
generateMock_conf_print_version();
gadgetUnit=args_info.gadgetUnit_arg;
if (args_info.ramsesBase_given || args_info.ramsesId_given)
{
if (args_info.ramsesBase_given && args_info.ramsesId_given)
simu = doLoadRamses(args_info.ramsesBase_arg,
args_info.ramsesId_arg,
args_info.axis_arg, false);
else
{
cerr << "Both ramsesBase and ramsesId are required to be able to load snapshots" << endl;
return 1;
}
if (simu == 0)
{
cerr << "Error while loading" << endl;
return 1;
}
}
else if (args_info.gadget_given || args_info.flash_given)
{
if (args_info.gadget_given && args_info.flash_given)
{
cerr << "Do not know which file to use: Gadget or Flash ?" << endl;
return 1;
}
if (args_info.gadget_given)
simu = doLoadSimulation(args_info.gadget_arg, args_info.axis_arg, false, myLoadGadget);
else
simu = doLoadSimulation(args_info.flash_arg, args_info.axis_arg, false, loadFlashMulti);
if (simu == 0)
{
cerr << "Error while loading " << endl;
return 1;
}
}
else
{
cerr << "Either a ramses snapshot or a gadget snapshot is required." << endl;
return 1;
}
cout << "Hubble = " << simu->Hubble << endl;
cout << "Boxsize = " << simu->BoxSize << endl;
cout << "Omega_M = " << simu->Omega_M << endl;
cout << "Omega_Lambda = " << simu->Omega_Lambda << endl;
double *expfact;
metricTransform(simu, args_info.axis_arg, args_info.preReShift_flag, args_info.peculiarVelocities_flag, expfact, args_info.cosmo_flag);
if (args_info.inputParameter_given)
makeBoxFromParameter(simu, expfact, simuOut, args_info);
else
makeBox(simu, expfact, simuOut, args_info);
delete simu;
generateOutput(simuOut, args_info.axis_arg, args_info.output_arg);
delete simuOut;
return 0;
}

View file

@ -0,0 +1,33 @@
package "generateMock"
version "0"
option "configFile" - "Configuration file path" string optional
# Ramses data
option "ramsesBase" - "Base directory for ramses" string optional
option "ramsesId" - "Ramses snapshot id" int optional
option "gadget" - "Base name of gadget snapshot (without parallel writing extension)" string optional
option "flash" - "Base name for FLASH snapshot" string optional
option "axis" - "Redshift axis (X=0, Y=1, Z=2)" int optional default="2"
option "output" - "Output filename for particles" string required
option "outputParameter" - "Output geometry parameter file for postprocessing" string required
option "rangeX_min" - "Minimum range in X for making the box" double required
option "rangeX_max" - "Maximum range in X for making the box" double required
option "rangeY_min" - "Minimum range in Y for making the box" double required
option "rangeY_max" - "Maximum range in Y for making the box" double required
option "rangeZ_min" - "Minimum range in Z for making the box (after distortion)" double required
option "rangeZ_max" - "Maximum range in Z for making the box (after distortion)" double required
option "preReShift" - "Reshift the zero of the Z axis" flag off
option "peculiarVelocities" - "Added peculiar velocities distortion" flag off
option "cosmo" - "Apply cosmological redshift" flag on
option "subsample" - "Subsample the input simulation by the specified amount" double optional
option "inputParameter" - "Input geometry (optional, warning!)" string optional
option "gadgetUnit" - "Unit of length in gadget file in Mpc/h" double optional default="0.001"

View file

@ -0,0 +1,47 @@
#include <iostream>
#include <cstdlib>
#include <CosmoTool/fortran.hpp>
using namespace CosmoTool;
using namespace std;
#define LX 1.0
#define LY 1.0
#define LZ 1.0
#define NUMPART (16*16*16)
int main(int argc, char **argv)
{
UnformattedWrite f("particles.bin");
f.beginCheckpoint();
f.writeInt32(NUMPART);
f.endCheckpoint();
cout << "Writing X components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < NUMPART; i++)
{
f.writeReal32(drand48()*LX);
}
f.endCheckpoint();
cout << "Writing Y components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < NUMPART; i++)
{
f.writeReal32(drand48()*LY);
}
f.endCheckpoint();
cout << "Writing Z components..." << endl;
f.beginCheckpoint();
for (uint32_t i = 0; i < NUMPART; i++)
{
f.writeReal32(drand48()*LZ);
}
f.endCheckpoint();
return 0;
}