Added support for ramses in _cosmotool. Fixlet in gadget

This commit is contained in:
Guilhem Lavaux 2014-05-30 11:39:13 +02:00
parent 9223ddbc3c
commit bf4977721f
2 changed files with 34 additions and 8 deletions

View File

@ -31,6 +31,8 @@ cdef extern from "loadGadget.hpp" namespace "CosmoTool":
SimuData *loadGadgetMulti(const char *fname, int id, int flags) except +
cdef extern from "loadRamses.hpp" namespace "CosmoTool":
SimuData *loadRamsesSimu(const char *basename, int id, int cpuid, bool dp, int flags) except +
cdef class Simulation:
@ -120,7 +122,18 @@ cdef object wrap_float_array(float *p, np.uint64_t s):
return ndarray
def loadGadget(str filename, int snapshot_id, bool loadPosition = True, bool loadVelocity = True):
cdef object wrap_simudata(SimuData *data, int flags):
cdef Simulation simu
simu = Simulation()
simu.data = data
if flags & NEED_POSITION:
simu.positions = [wrap_float_array(data.Pos[i], data.NumPart) for i in xrange(3)]
if flags & NEED_VELOCITY:
simu.velocities = [wrap_float_array(data.Vel[i], data.NumPart) for i in xrange(3)]
return simu
def loadGadget(str filename, int snapshot_id, bool loadPosition = True, bool loadVelocity = False):
cdef int flags
cdef SimuData *data
@ -136,11 +149,24 @@ def loadGadget(str filename, int snapshot_id, bool loadPosition = True, bool loa
if data == <SimuData*>0:
return None
simu = Simulation()
simu.data = data
if loadPosition:
simu.positions = [wrap_float_array(data.Pos[i], data.NumPart) for i in xrange(3)]
if loadVelocity:
simu.velocities = [wrap_float_array(data.Vel[i], data.NumPart) for i in xrange(3)]
return wrap_simudata(data, flags)
return simu
def loadRamses(str basepath, int snapshot_id, int cpu_id, bool doublePrecision = False, bool loadPosition = True, bool loadVelocity = False):
""" loadRamses(basepath, snapshot_id, cpu_id, doublePrecision=False, loadPosition=True, loadVelocity=False)
Loads the indicated snapshot based on the cpu id, snapshot id and basepath. It is important to specify the correct precision in doublePrecision.
"""
cdef int flags
cdef SimuData *data
cdef Simulation simu
flags = 0
if loadPosition:
flags |= NEED_POSITION
if loadVelocity:
flags |= NEED_VELOCITY
data = loadRamsesSimu(basepath, snapshot_id, cpu_id, doublePrecision, flags)
if data == <SimuData*>0:
return None
return wrap_simudata(data, flags)

View File

@ -96,7 +96,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
if (f == 0)
return 0;
delete out_fname;
delete[] out_fname;
} else {