Added graficToDensity conversion. Added missing getBoxsize() method. Fixed grafic generation

This commit is contained in:
Guilhem Lavaux 2014-06-02 10:34:20 +02:00
parent 688e4e20de
commit 1aaf5f4a13
5 changed files with 85 additions and 4 deletions

View File

@ -123,6 +123,9 @@ class _PySimulationAdaptor(PySimulationBase):
def __init__(self,sim):
self.simu = sim
def getBoxsize(self):
return self.simu.BoxSize
def getPositions(self):
return self.simu.positions

View File

@ -7,7 +7,7 @@ def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
checkPoint = 4*11
Nx,Ny,Nz = field.shape
delta = BoxSize/Nx
delta = BoxSize/Nx/cosmo['h']
bad = 0.0
f.write(struct.pack("IIIIffffffffI", checkPoint,

View File

@ -49,13 +49,16 @@ def run_generation(input_borg, a_borg, a_ic, **cosmo):
# Generate vel
vel.append((psi*velmul).astype(np.float32))
return posx,vel,N,L,a_ic
density = np.fft.irfftn(density_hat*D1_0)*(N/L)**3
return posx,vel,density,N,L,a_ic
def write_icfiles(*generated_ic, **cosmo):
"""Write the initial conditions from the tuple returned by run_generation"""
posx,vel,N,L,a_ic = generated_ic
posx,vel,density,N,L,a_ic = generated_ic
ct.simpleWriteGadget("borg.gad", posx, velocities=vel, boxsize=L, Hubble=cosmo['h'], Omega_M=cosmo['omega_M_0'], time=a_ic)
for i,c in enumerate(['x','y','z']):
ct.writeGrafic("borg.ic_velc%s" % c, vel[i].reshape((N,N,N)), L, a_ic, **cosmo)
ct.writeGrafic("ic_velc%s" % c, vel[i].reshape((N,N,N)), L, a_ic, **cosmo)
ct.writeGrafic("ic_deltab", density, L, a_ic, **cosmo)

View File

@ -42,6 +42,8 @@ if (HDF5_FOUND)
add_executable(gadgetToArray gadgetToArray.cpp)
target_link_libraries(gadgetToArray ${tolink})
add_executable(graficToDensity graficToDensity.cpp)
target_link_libraries(graficToDensity ${tolink})
endif (HDF5_FOUND)
@ -88,3 +90,4 @@ endif (Boost_FOUND)
add_executable(gadgetToDensity gadgetToDensity.cpp)
target_link_libraries(gadgetToDensity ${tolink})

View File

@ -0,0 +1,72 @@
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <boost/multi_array.hpp>
#include <H5Cpp.h>
#include "hdf5_array.hpp"
#include "miniargs.hpp"
#include "fortran.hpp"
using namespace std;
using namespace CosmoTool;
//#define GRAFIC_GUILHEM
int main(int argc, char **argv)
{
uint32_t res;
char *fname;
int id;
MiniArgDesc desc[] = {
{ "GRAFIC", &fname, MINIARG_STRING },
{ 0, 0, MINIARG_NULL }
};
if (!parseMiniArgs(argc, argv, desc))
return 1;
UnformattedRead ur(fname);
ur.beginCheckpoint();
int32_t nx = ur.readInt32();
int32_t ny = ur.readInt32();
int32_t nz = ur.readInt32();
float dx = ur.readReal32();
float xo = ur.readReal32();
float yo = ur.readReal32();
float zo = ur.readReal32();
float astart = ur.readReal32();
float omega_m = ur.readReal32();
float omega_nu = ur.readReal32();
float h0 = ur.readReal32();
#ifdef GRAFIC_GUILHEM
float w0 = ur.readReal32();
#endif
ur.endCheckpoint();
cout << "Grafic file: Nx=" << nx << " Ny=" << ny << " Nz=" << nz << endl;
cout << "a_start = " << astart << endl;
cout << "z_start = " << 1/astart - 1 << endl;
cout << "L = " << nx*dx << endl;
boost::multi_array<float, 3> density(boost::extents[nx][ny][nz]);
for (int32_t iz = 0; iz < nz; iz++)
{
ur.beginCheckpoint();
for (int32_t iy = 0; iy < ny; iy++)
{
for (int32_t ix = 0; ix < nx; ix++)
{
density[ix][iy][iz] = ur.readReal32();
}
}
ur.endCheckpoint();
}
H5::H5File f("density.h5", H5F_ACC_TRUNC);
hdf5_write_array(f, "density", density);
return 0;
}