Merge branch 'master' of bitbucket.org:glavaux/cosmotool
This commit is contained in:
commit
4f250969ac
32
external/external_build.cmake
vendored
32
external/external_build.cmake
vendored
@ -5,8 +5,8 @@ OPTION(ENABLE_OPENMP "Set to Yes if Healpix and/or you need openMP" OFF)
|
||||
SET(FFTW_URL "http://www.fftw.org/fftw-3.3.3.tar.gz" CACHE URL "URL to download FFTW from")
|
||||
SET(EIGEN_URL "http://bitbucket.org/eigen/eigen/get/3.2.10.tar.gz" CACHE URL "URL to download Eigen from")
|
||||
SET(GENGETOPT_URL "ftp://ftp.gnu.org/gnu/gengetopt/gengetopt-2.22.5.tar.gz" CACHE STRING "URL to download gengetopt from")
|
||||
SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.gz" CACHE STRING "URL to download HDF5 from")
|
||||
SET(NETCDF_URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.4.1.1.tar.gz" CACHE STRING "URL to download NetCDF from")
|
||||
SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.bz2" CACHE STRING "URL to download HDF5 from")
|
||||
SET(NETCDF_URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.5.0.tar.gz" CACHE STRING "URL to download NetCDF from")
|
||||
SET(NETCDFCXX_URL "https://github.com/Unidata/netcdf-cxx4/archive/v4.3.0.tar.gz" CACHE STRING "URL to download NetCDF-C++ from")
|
||||
SET(BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz/download" CACHE STRING "URL to download Boost from")
|
||||
SET(GSL_URL "ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz" CACHE STRING "URL to download GSL from ")
|
||||
@ -52,11 +52,14 @@ SET(CONFIGURE_LDFLAGS "")
|
||||
|
||||
if (ENABLE_SHARP)
|
||||
SET(DEP_BUILD ${BUILD_PREFIX}/sharp-prefix/src/sharp/auto)
|
||||
IF(NOT ENABLE_OPENMP)
|
||||
SET(SHARP_OPENMP --disable-openmp)
|
||||
ENDIF()
|
||||
ExternalProject_Add(sharp
|
||||
URL ${CMAKE_SOURCE_DIR}/external/libsharp-6077806.tar.gz
|
||||
PREFIX ${BUILD_PREFIX}/sharp-prefix
|
||||
BUILD_IN_SOURCE 1
|
||||
CONFIGURE_COMMAND autoconf && ./configure "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" --prefix=${DEP_BUILD}
|
||||
CONFIGURE_COMMAND autoconf && ./configure "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" --prefix=${DEP_BUILD} ${SHARP_OPENMP}
|
||||
BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}
|
||||
INSTALL_COMMAND echo "No install"
|
||||
)
|
||||
@ -78,6 +81,7 @@ if (INTERNAL_HDF5)
|
||||
ExternalProject_Add(hdf5
|
||||
PREFIX ${BUILD_PREFIX}/hdf5-prefix
|
||||
URL ${HDF5_URL}
|
||||
URL_HASH MD5=29117bf488887f89888f9304c8ebea0b
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX=${EXT_INSTALL}
|
||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
@ -93,9 +97,11 @@ if (INTERNAL_HDF5)
|
||||
SET(HDF5_ROOTDIR ${HDF5_BIN_DIR})
|
||||
SET(CONFIGURE_LDFLAGS "${CONFIGURE_LDFLAGS} -L${HDF5_BIN_DIR}/lib")
|
||||
SET(CONFIGURE_LIBS "${CONFIGURE_LIBS} -ldl")
|
||||
set(HDF5_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5.a CACHE STRING "HDF5 lib" FORCE)
|
||||
set(HDF5_HL_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5_hl.a CACHE STRING "HDF5 HL lib" FORCE)
|
||||
set(HDF5_CXX_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5_cpp.a CACHE STRING "HDF5 C++ lib" FORCE)
|
||||
set(HDF5_C_STATIC_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5-static.a)
|
||||
set(HDF5_HL_STATIC_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5_hl-static.a)
|
||||
set(HDF5_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5-static.a CACHE STRING "HDF5 lib" FORCE)
|
||||
set(HDF5_HL_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5_hl-static.a CACHE STRING "HDF5 HL lib" FORCE)
|
||||
set(HDF5_CXX_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5_cpp-static.a CACHE STRING "HDF5 C++ lib" FORCE)
|
||||
SET(HDF5_INCLUDE_DIRS ${HDF5_BIN_DIR}/include CACHE STRING "HDF5 include path" FORCE)
|
||||
mark_as_advanced(HDF5_LIBRARIES HDF5_CXX_LIBRARIES HDF5_INCLUDE_DIRS)
|
||||
|
||||
@ -114,6 +120,7 @@ else (INTERNAL_HDF5)
|
||||
cmessage(STATUS "HDF5 lib: ${HDF5_LIBRARIES}")
|
||||
cmessage(STATUS "HDF5 includes: ${HDF5_INCLUDE_DIRS}")
|
||||
cmessage(STATUS "HDF5 C lib: ${HDF5_C_LIBRARY}")
|
||||
cmessage(STATUS "HDF5 HL lib: ${HDF5_HL_LIBRARY}")
|
||||
cmessage(STATUS "HDF5 BIN: ${HDF5_BIN_DIR}")
|
||||
foreach(hdf5lib IN LISTS HDF5_LIBRARIES)
|
||||
if (${hdf5lib} MATCHES "(hdf5)|(HDF5)")
|
||||
@ -165,8 +172,13 @@ if (INTERNAL_NETCDF)
|
||||
-DBUILD_TESTING=OFF
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DENABLE_NETCDF4=ON
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DENABLE_DAP=OFF
|
||||
-DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR}
|
||||
-DHDF5_C_LIBRARY=${HDF5_C_STATIC_LIBRARY}
|
||||
-DHDF5_HL_LIBRARY=${HDF5_HL_STATIC_LIBRARY}
|
||||
-DHDF5_INCLUDE_DIR=${HDF5_INCLUDE_DIRS}
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
)
|
||||
|
||||
SET(NETCDFCXX_SOURCE_DIR ${BUILD_PREFIX}/netcdf-c++-prefix/src/netcdf-c++)
|
||||
@ -178,13 +190,17 @@ if (INTERNAL_NETCDF)
|
||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DBUILD_TESTING=OFF
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR}
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
)
|
||||
# SET(CONFIGURE_CPP_LDFLAGS "${CONFIGURE_LDFLAGS}")
|
||||
# SET(EXTRA_NC_FLAGS CPPFLAGS=${CONFIGURE_CPP_FLAGS} LDFLAGS=${CONFIGURE_CPP_LDFLAGS})
|
||||
SET(cosmotool_DEPS ${cosmotool_DEPS} netcdf netcdf-c++)
|
||||
# find_library(NETCDF_LIBRARY netcdf NO_DEFAULT_PATH HINTS ${NETCDF_BIN_DIR}/lib ${NETCDF_BIN_DIR}/lib32 ${NETCDF_BIN_DIR}/lib64)
|
||||
# find_library(NETCDFCPP_LIBRARY netcdf-cxx4 NO_DEFAULT_PATH HINTS ${NETCDF_BIN_DIR}/lib ${NETCDF_BIN_DIR}/lib32 ${NETCDF_BIN_DIR}/lib64)
|
||||
SET(NETCDF_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf.a CACHE STRING "NetCDF lib" FORCE)
|
||||
SET(NETCDFCPP_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf-cxx4.a CACHE STRING "NetCDF-C++ lib" FORCE)
|
||||
SET(NETCDF_INCLUDE_PATH ${NETCDF_BIN_DIR}/include CACHE STRING "NetCDF include" FORCE)
|
||||
@ -321,9 +337,11 @@ IF (INTERNAL_EIGEN)
|
||||
SET(EIGEN3_INCLUDE_DIRS ${EXT_INSTALL}/include/eigen3)
|
||||
|
||||
ELSE (INTERNAL_EIGEN)
|
||||
pkg_check_modules(EIGEN3 QUIET eigen3 )
|
||||
pkg_check_modules(EIGEN3 eigen3 )
|
||||
if (NOT EIGEN3_FOUND)
|
||||
cmessage(CWARNING "Eigen library not found")
|
||||
else()
|
||||
cmessage(STATUS "Found EIGEN3 in ${EIGEN3_INCLUDE_DIRS}")
|
||||
endif()
|
||||
ENDIF(INTERNAL_EIGEN)
|
||||
|
||||
|
@ -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")
|
||||
@ -95,10 +100,12 @@ if (WIN32 AND NOT CYGWIN)
|
||||
SET_TARGET_PROPERTIES(_cosmotool PROPERTIES SUFFIX ".pyd")
|
||||
endif (WIN32 AND NOT CYGWIN)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cosmotool/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/cosmotool/config.py @ONLY)
|
||||
|
||||
INSTALL(TARGETS
|
||||
${ct_TARGETS}
|
||||
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/cosmotool
|
||||
)
|
||||
|
||||
INSTALL(DIRECTORY cosmotool DESTINATION ${PYTHON_SITE_PACKAGES}
|
||||
INSTALL(DIRECTORY cosmotool ${CMAKE_CURRENT_BINARY_DIR}/cosmotool DESTINATION ${PYTHON_SITE_PACKAGES}
|
||||
FILES_MATCHING PATTERN "*.py")
|
||||
|
@ -452,7 +452,7 @@ def loadParallelGadget(object filename_list, int gadgetFormat = 1, bool loadPosi
|
||||
filenames.resize(num_files)
|
||||
data = alloc_simudata(num_files)
|
||||
for i,l in enumerate(filename_list):
|
||||
filenames[i] = l
|
||||
filenames[i] = l.encode('utf-8')
|
||||
|
||||
with nogil:
|
||||
for i in prange(num_files):
|
||||
@ -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))
|
||||
|
||||
|
@ -15,6 +15,7 @@ except:
|
||||
from .simu import loadRamsesAll, simpleWriteGadget, SimulationBare
|
||||
from .timing import time_block, timeit, timeit_quiet
|
||||
from .bispectrum import bispectrum, powerspectrum
|
||||
from .smooth import smooth_particle_density
|
||||
|
||||
try:
|
||||
from .fftw import CubeFT
|
||||
|
1
python/cosmotool/config.py.in
Normal file
1
python/cosmotool/config.py.in
Normal file
@ -0,0 +1 @@
|
||||
install_prefix="@CMAKE_INSTALL_PREFIX@"
|
@ -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)
|
||||
|
105
python/cosmotool/smooth.py
Normal file
105
python/cosmotool/smooth.py
Normal file
@ -0,0 +1,105 @@
|
||||
from .config import install_prefix
|
||||
import subprocess
|
||||
import os
|
||||
from tempfile import TemporaryDirectory
|
||||
import h5py as h5
|
||||
import numpy as np
|
||||
import weakref
|
||||
|
||||
def smooth_particle_density(
|
||||
position,
|
||||
velocities=None,
|
||||
radius=1e6,
|
||||
boxsize=None,
|
||||
resolution=128,
|
||||
center=None, tmpprefix=None ):
|
||||
"""Use adaptive smoothing to produce density and momentum fields.
|
||||
The algorithm is originally described in [1].
|
||||
|
||||
Parameters:
|
||||
position : numpy array NxQ
|
||||
the particle positions
|
||||
if Q==3, only positions. Q==6 means full space phase
|
||||
velocities : Optional numpy array Nx3.
|
||||
It is only optional if the above Q is 6.
|
||||
radius : float
|
||||
Maximum radius to which we need to compute fields
|
||||
boxsize : float
|
||||
Size of the box for the generated fields
|
||||
resolution : int
|
||||
Resolution of the output boxes
|
||||
center : list of 3 floats
|
||||
Center of the new box. It depends on the convention
|
||||
for particles. If those are between [0, L], then [0,0,0]
|
||||
is correct. If those are [-L/2,L/2] then you should set
|
||||
[L/2,L/2,L/2].
|
||||
tmpprefix : string
|
||||
prefix of the temporary directory that will be used.
|
||||
It needs to have a lot of space available. By default
|
||||
'/tmp/ will be typically used.
|
||||
|
||||
|
||||
Returns
|
||||
-------
|
||||
dictionnary
|
||||
The dict has two entries: 'rho' for the density, and 'p' for the momenta.
|
||||
Once the dictionary is garbage collected all temporary files and directories
|
||||
will be cleared automatically.
|
||||
|
||||
|
||||
Raises
|
||||
------
|
||||
ValueError
|
||||
if arguments are invalid
|
||||
|
||||
|
||||
.. [1] S. Colombi, M. Chodorowski,
|
||||
"Cosmic velocity-gravity in redshift space", MNRAS, 2007, 375, 1
|
||||
"""
|
||||
if len(position.shape) != 2:
|
||||
raise ValueError("Invalid position array shape")
|
||||
|
||||
if velocities is None:
|
||||
if position.shape[1] != 6:
|
||||
raise ValueError("Position must be phase space if no velocities are given")
|
||||
|
||||
|
||||
if boxsize is None:
|
||||
raise ValueError("Need a boxsize")
|
||||
|
||||
cx,cy,cz=center
|
||||
tmpdir = TemporaryDirectory(prefix=tmpprefix)
|
||||
h5_file = os.path.join(tmpdir.name, 'particles.h5')
|
||||
with h5.File(h5_file, mode="w") as f:
|
||||
data = f.create_dataset('particles', shape=(position.shape[0],7), dtype=np.float32)
|
||||
data[:,:3] = position[:,:3]
|
||||
if velocities is not None:
|
||||
data[:,3:6] = velocities[:,:3]
|
||||
else:
|
||||
data[:,3:6] = position[:,3:]
|
||||
data[:,6] = 1
|
||||
|
||||
|
||||
ret = \
|
||||
subprocess.run([
|
||||
os.path.join(install_prefix,'bin','simple3DFilter'),
|
||||
h5_file,
|
||||
str(radius),
|
||||
str(boxsize),
|
||||
str(resolution),
|
||||
str(cx), str(cy), str(cz)
|
||||
], cwd=tmpdir.name)
|
||||
|
||||
|
||||
f0 = h5.File(os.path.join(tmpdir.name,'fields.h5'), mode="r")
|
||||
def cleanup_f0():
|
||||
f0.close()
|
||||
tmpdir.cleanup()
|
||||
|
||||
class Dict(dict):
|
||||
pass
|
||||
|
||||
t = Dict(rho=f0['density'], p=[f0['p0'], f0['p1'], f0['p2']])
|
||||
t._tmpdir_=tmpdir
|
||||
weakref.finalize(t, cleanup_f0)
|
||||
return t
|
@ -68,7 +68,9 @@ if (ENABLE_SHARP AND SHARP_LIBRARY AND SHARP_INCLUDE_PATH AND EIGEN3_FOUND)
|
||||
include_directories(${SHARP_INCLUDE_PATH})
|
||||
add_executable(test_healpix_calls test_healpix_calls.cpp)
|
||||
target_link_libraries(test_healpix_calls ${tolink} ${SHARP_LIBRARIES})
|
||||
if (ENABLE_OPENMP)
|
||||
set_target_properties(test_healpix_calls PROPERTIES COMPILE_FLAGS "${OpenMP_CXX_FLAGS}" LINK_FLAGS "${OpenMP_CXX_FLAGS}")
|
||||
endif()
|
||||
add_dependencies(test_healpix_calls sharp)
|
||||
endif (ENABLE_SHARP AND SHARP_LIBRARY AND SHARP_INCLUDE_PATH AND EIGEN3_FOUND)
|
||||
|
||||
@ -82,10 +84,16 @@ if (Boost_FOUND)
|
||||
add_executable(testSmooth testSmooth.cpp)
|
||||
target_link_libraries(testSmooth ${tolink})
|
||||
|
||||
add_executable(simple3DFilter simple3DFilter.cpp)
|
||||
target_link_libraries(simple3DFilter ${tolink})
|
||||
ENDIF (YORICK_SUPPORT)
|
||||
if (HDF5_FOUND)
|
||||
add_executable(simple3DFilter simple3DFilter.cpp)
|
||||
target_link_libraries(simple3DFilter ${tolink})
|
||||
|
||||
install(TARGETS simple3DFilter
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
add_executable(gadgetToArray gadgetToArray.cpp)
|
||||
target_link_libraries(gadgetToArray ${tolink})
|
||||
|
||||
|
@ -34,12 +34,13 @@ ENDIF(YORICK_SUPPORT)
|
||||
|
||||
|
||||
if (HDF5_FOUND)
|
||||
set(CosmoTool_SRCS ${CosmoTool_SRCS}
|
||||
add_library(CosmoHDF5 OBJECT
|
||||
h5_readFlash.cpp
|
||||
loadFlash.cpp
|
||||
)
|
||||
target_include_directories(CosmoHDF5 BEFORE PRIVATE ${HDF5_INCLUDE_DIR})
|
||||
else(HDF5_FOUND)
|
||||
set(CosmoTool_SRCS ${CosmoTool_SRCS}
|
||||
add_library(CosmoHdf5 OBJECT
|
||||
loadFlash_dummy.cpp
|
||||
)
|
||||
endif (HDF5_FOUND)
|
||||
@ -78,22 +79,23 @@ endif(YORICK_SUPPORT)
|
||||
|
||||
if (HDF5_FOUND)
|
||||
set(CosmoTool_LIBS ${CosmoTool_LIBS} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} ${HDF5_CXX_LIBRARIES} ${ZLIB})
|
||||
include_directories(${HDF5_INCLUDE_DIR})
|
||||
message(STATUS "CosmoTool_LIBS: ${CosmoTool_LIBS}")
|
||||
endif (HDF5_FOUND)
|
||||
|
||||
set(CosmoTool_LIBS ${CosmoTool_LIBS} PARENT_SCOPE)
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
add_library(CosmoTool SHARED ${CosmoTool_SRCS})
|
||||
add_library(CosmoTool SHARED ${CosmoTool_SRCS} $<TARGET_OBJECTS:CosmoHDF5>)
|
||||
target_link_libraries(CosmoTool ${CosmoTool_LIBS})
|
||||
if (BUILD_STATIC_LIBS)
|
||||
add_library(CosmoTool_static STATIC ${CosmoTool_SRCS})
|
||||
set_target_properties(CosmoTool_static PROPERTIES COMPILE_FLAGS "${CMAKE_C_COMPILE_OPTIONS_PIC}")
|
||||
add_library(CosmoTool_static STATIC ${CosmoTool_SRCS} $<TARGET_OBJECTS:CosmoHDF5>)
|
||||
target_link_libraries(CosmoTool_static)
|
||||
set_property(TARGET CosmoTool_static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif(BUILD_STATIC_LIBS)
|
||||
else (BUILD_SHARED_LIBS)
|
||||
add_library(CosmoTool STATIC ${CosmoTool_SRCS})
|
||||
set_target_properties(CosmoTool PROPERTIES COMPILE_FLAGS "${CMAKE_C_COMPILE_OPTIONS_PIC}")
|
||||
add_library(CosmoTool STATIC ${CosmoTool_SRCS} $<TARGET_OBJECTS:CosmoHDF5>)
|
||||
target_link_libraries(CosmoTool)
|
||||
set_property(TARGET CosmoTool PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif (BUILD_SHARED_LIBS)
|
||||
|
||||
install(TARGETS CosmoTool
|
||||
|
@ -51,6 +51,7 @@ UnformattedRead::UnformattedRead(const string& fname)
|
||||
swapOrdering = false;
|
||||
cSize = Check_32bits;
|
||||
checkPointRef = checkPointAccum = 0;
|
||||
recordBuffer = 0;
|
||||
}
|
||||
|
||||
UnformattedRead::UnformattedRead(const char *fname)
|
||||
@ -130,6 +131,7 @@ void UnformattedRead::beginCheckpoint(bool bufferRecord)
|
||||
throw EndOfFileException();
|
||||
|
||||
if (bufferRecord) {
|
||||
std::cout << "Use fast I/O mode" << std::endl;
|
||||
recordBuffer = new uint8_t[checkPointRef];
|
||||
f->read(reinterpret_cast<char *>(recordBuffer), checkPointRef);
|
||||
}
|
||||
|
@ -51,6 +51,11 @@ knowledge of the CeCILL license and that you accept its terms.
|
||||
#include <H5Cpp.h>
|
||||
|
||||
namespace CosmoTool {
|
||||
#if (H5_VERS_MAJOR == 1) && (H5_VERS_MINOR <= 8)
|
||||
typedef H5::CommonFG H5_CommonFileGroup;
|
||||
#else
|
||||
typedef H5::Group H5_CommonFileGroup;
|
||||
#endif
|
||||
|
||||
//!_______________________________________________________________________________________
|
||||
//!
|
||||
@ -129,7 +134,7 @@ namespace CosmoTool {
|
||||
//!
|
||||
//!_______________________________________________________________________________________
|
||||
template<typename ArrayType, typename hdf5_data_type>
|
||||
void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
void hdf5_write_array(H5_CommonFileGroup& fg, const std::string& data_set_name,
|
||||
const ArrayType& data,
|
||||
const hdf5_data_type& datatype,
|
||||
const std::vector<hsize_t>& dimensions,
|
||||
@ -156,7 +161,7 @@ namespace CosmoTool {
|
||||
|
||||
|
||||
template<typename ArrayType, typename hdf5_data_type>
|
||||
void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
void hdf5_write_array(H5_CommonFileGroup& fg, const std::string& data_set_name,
|
||||
const ArrayType& data,
|
||||
const hdf5_data_type& datatype,
|
||||
bool doCreate = true,
|
||||
@ -255,7 +260,7 @@ namespace CosmoTool {
|
||||
};
|
||||
|
||||
template<typename ArrayType>
|
||||
void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name, const ArrayType& data )
|
||||
void hdf5_write_array(H5_CommonFileGroup& fg, const std::string& data_set_name, const ArrayType& data )
|
||||
{
|
||||
typedef typename ArrayType::element T;
|
||||
get_hdf5_data_type<T> hdf_data_type;
|
||||
@ -341,7 +346,7 @@ namespace CosmoTool {
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
template<typename ArrayType, typename hdf5_data_type>
|
||||
void hdf5_read_array_typed(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
void hdf5_read_array_typed(H5_CommonFileGroup& fg, const std::string& data_set_name,
|
||||
ArrayType& data,
|
||||
const hdf5_data_type& datatype, bool auto_resize = true, bool useBases = false)
|
||||
{
|
||||
@ -377,7 +382,7 @@ namespace CosmoTool {
|
||||
}
|
||||
|
||||
template<typename ArrayType>
|
||||
void hdf5_read_array(H5::CommonFG& fg, const std::string& data_set_name, ArrayType& data, bool auto_resize = true,
|
||||
void hdf5_read_array(H5_CommonFileGroup& fg, const std::string& data_set_name, ArrayType& data, bool auto_resize = true,
|
||||
bool useBases = false )
|
||||
{
|
||||
typedef typename ArrayType::element T;
|
||||
|
@ -417,6 +417,9 @@ CosmoTool::SimuData *CosmoTool::loadRamsesSimu(const char *basename, int outputI
|
||||
data->Vel[1] = new float[nPar];
|
||||
data->Vel[2] = new float[nPar];
|
||||
}
|
||||
if (flags & NEED_MASS) {
|
||||
data->Mass = new float[nPar];
|
||||
}
|
||||
if (flags & NEED_GADGET_ID)
|
||||
{
|
||||
data->Id = new int64_t[nPar];
|
||||
@ -455,9 +458,10 @@ CosmoTool::SimuData *CosmoTool::loadRamsesSimu(const char *basename, int outputI
|
||||
|
||||
float minMass = INFINITY;
|
||||
infile.beginCheckpoint();
|
||||
for (uint32_t i = nPar; i > 0; i--)
|
||||
{
|
||||
for (uint32_t i = 0; i < nPar; i++) {
|
||||
float dummyF = dp ? infile.readReal64() : infile.readReal32();
|
||||
if (flags & NEED_MASS)
|
||||
data->Mass[i] = dummyF;
|
||||
if (dummyF < minMass) minMass = dummyF;
|
||||
}
|
||||
infile.endCheckpoint();
|
||||
|
Loading…
Reference in New Issue
Block a user