Update requirements. Split HDF5 compilation into its own virtual target.

This commit is contained in:
Guilhem Lavaux 2017-12-08 11:11:50 +01:00
parent 1d261c6251
commit aa42376cbe
9 changed files with 60 additions and 30 deletions

View file

@ -1,7 +1,8 @@
set(CMAKE_SHARED_MODULE_PREFIX)
include_directories(${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/python)
set(PYTHON_INCLUDES ${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/python)
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
IF(CYTHON)
add_custom_command(
@ -37,7 +38,11 @@ add_library(_cosmo_power MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_power.cpp)
add_library(_cosmo_cic MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_cic.cpp)
add_library(_fast_interp MODULE ${CMAKE_CURRENT_BINARY_DIR}/_fast_interp.cpp)
add_library(_project MODULE ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp)
target_include_directories(_cosmotool PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_cosmo_power PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_cosmo_cic PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_fast_interp PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_project PRIVATE ${PYTHON_INCLUDES})
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Bsymbolic-functions")

View file

@ -515,7 +515,7 @@ def writeGadget(str filename, object simulation):
cxx_writeGadget(filename, &simdata)
def loadRamses(str basepath, int snapshot_id, int cpu_id, bool doublePrecision = False, bool loadPosition = True, bool loadVelocity = False, bool loadId = False):
def loadRamses(str basepath, int snapshot_id, int cpu_id, bool doublePrecision = False, bool loadPosition = True, bool loadVelocity = False, bool loadId = False, bool loadMass = 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 otherwise the loading will fail. There is no way of auto-detecting properly the precision of the snapshot file.
@ -528,7 +528,8 @@ def loadRamses(str basepath, int snapshot_id, int cpu_id, bool doublePrecision =
doublePrecision (bool): By default it is False, thus singlePrecision
loadPosition (bool): Whether to load positions
loadVelocity (bool): Whether to load velocities
loadId (bol): Whether to load identifiers
loadId (bool): Whether to load identifiers
loadMass (bool): Whether to load mass value
Returns:
An object derived from PySimulationBase_.
@ -544,13 +545,16 @@ def loadRamses(str basepath, int snapshot_id, int cpu_id, bool doublePrecision =
flags |= NEED_VELOCITY
if loadId:
flags |= NEED_GADGET_ID
if loadMass:
flags |= NEED_MASS
encpath = basepath.encode('utf-8')
try:
data = loadRamsesSimu(basepath, snapshot_id, cpu_id, doublePrecision, flags)
data = loadRamsesSimu(encpath, snapshot_id, cpu_id, doublePrecision, flags)
if data == <SimuData*>0:
return None
except RuntimeError as e:
raise RuntimeError(e.message + ' (check the float precision in snapshot)')
raise RuntimeError(str(e) + ' (check the float precision in snapshot)')
return PySimulationAdaptor(wrap_simudata(data, flags))

View file

@ -19,7 +19,7 @@ class CubeFT(object):
self.align = pyfftw.simd_alignment
self.L = float(L)
self.max_cpu = multiprocessing.cpu_count() if max_cpu < 0 else max_cpu
self._dhat = pyfftw.n_byte_align_empty((self.N,self.N,self.N/2+1), self.align, dtype=fourier_type)
self._dhat = pyfftw.n_byte_align_empty((self.N,self.N,self.N//2+1), self.align, dtype=fourier_type)
self._density = pyfftw.n_byte_align_empty((self.N,self.N,self.N), self.align, dtype=real_type)
self._irfft = pyfftw.FFTW(self._dhat, self._density, axes=(0,1,2), direction='FFTW_BACKWARD', threads=self.max_cpu)#, normalize_idft=False)
self._rfft = pyfftw.FFTW(self._density, self._dhat, axes=(0,1,2), threads=self.max_cpu) #, normalize_idft=False)

View file

@ -15,16 +15,22 @@ def readGrafic(filename):
* the mean matter density :math:`\Omega_\mathrm{m}`
* the dark energy density :math:`\Omega_\Lambda`
* the hubble constant, relative to 100 km/s/Mpc
* xoffset
* yoffset
* zoffset
"""
with file(filename, mode="rb") as f:
with open(filename, mode="rb") as f:
p = struct.unpack("IIIIffffffffI", f.read(4*11 + 2*4))
checkPoint0, Nx, Ny, Nz, delta, _, _, _, scalefac, omega0, omegalambda0, h, checkPoint1 = p
checkPoint0, Nx, Ny, Nz, delta, xoff, yoff, zoff, scalefac, omega0, omegalambda0, h, checkPoint1 = p
if checkPoint0 != checkPoint1 or checkPoint0 != 4*11:
raise ValueError("Invalid unformatted access")
a = np.empty((Nx,Ny,Nz), dtype=np.float32)
BoxSize = delta * Nx * h
xoff *= h
yoff *= h
zoff *= h
checkPoint = 4*Ny*Nz
for i in range(Nx):
@ -38,11 +44,11 @@ def readGrafic(filename):
if checkPoint != 4*Ny*Nz:
raise ValueError("Invalid unformatted access")
return a, BoxSize, scalefac, omega0, omegalambda0, h
return a, BoxSize, scalefac, omega0, omegalambda0, h, xoff, yoff,zoff
def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
with file(filename, mode="wb") as f:
with open(filename, mode="wb") as f:
checkPoint = 4*11
Nx,Ny,Nz = field.shape
@ -65,7 +71,7 @@ def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
def writeWhitePhase(filename, field):
with file(filename, mode="wb") as f:
with open(filename, mode="wb") as f:
Nx,Ny,Nz = field.shape
checkPoint = 4*4
@ -80,7 +86,7 @@ def writeWhitePhase(filename, field):
def readWhitePhase(filename):
with file(filename, mode="rb") as f:
with open(filename, mode="rb") as f:
_, Nx, Ny, Nz, _, _ = struct.unpack("IIIIII", f.read(4*4+2*4))
a = np.empty((Nx,Ny,Nz), dtype=np.float32)