Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
cmake_minimum_required (VERSION 3.13)

project(HemeLB)

option(USE_HDF5 "Enable HDF5 support" ON)
message(STATUS "USE_HDF5 = ${USE_HDF5}")
set(HEMELB_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)

list(INSERT CMAKE_MODULE_PATH 0 "${HEMELB_ROOT_DIR}/CMake")
Expand Down Expand Up @@ -84,10 +85,18 @@ find_hemelb_dependency(ZLIB REQUIRED)
link_libraries(MPI::MPI_CXX)
link_libraries(Boost::headers)

if(HEMELB_BUILD_RBC)
# Work around some installs of HDF5 having proper targets and others
# not...
# if(HEMELB_BUILD_RBC)
# # Work around some installs of HDF5 having proper targets and others
# # not...
# include(UseHDF5)
# find_hemelb_dependency(VTK REQUIRED)
# endif()
if(USE_HDF5)
include(UseHDF5)
add_definitions(-DUSE_HDF5)
endif()

if(HEMELB_BUILD_RBC)
find_hemelb_dependency(VTK REQUIRED)
endif()

Expand Down
6 changes: 5 additions & 1 deletion Code/configuration/SimConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ namespace hemelb::configuration
}

propertyoutputEl.GetAttributeOrThrow("period", file.frequency);

// attend to find property "format", if exists, read it
// otherwise default to "xdr"
file.format = propertyoutputEl.GetAttributeMaybe("format").value_or("xdr");


io::xml::Element geometryEl = propertyoutputEl.GetChildOrThrow("geometry");
auto type = geometryEl.GetAttributeOrThrow("type");

Expand Down
10 changes: 5 additions & 5 deletions Code/configuration/SimConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ namespace hemelb::configuration
};

struct IoletConfigBase {
PhysicalPosition position;
util::Vector3D<double> normal;
std::optional<std::uint64_t> warmup_steps;
std::optional<FlowExtensionConfig> flow_extension;
std::vector<CellInserterConfig> cell_inserters;
PhysicalPosition position{}; // make sure position is initialized to zero
util::Vector3D<double> normal{};
std::optional<std::uint64_t> warmup_steps = std::nullopt; // initialized to no warmup steps
std::optional<FlowExtensionConfig> flow_extension = std::nullopt; // initialized to no flow extension
std::vector<CellInserterConfig> cell_inserters;
};

// Consider removing
Expand Down
53 changes: 48 additions & 5 deletions Code/extraction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,52 @@
# file AUTHORS. This software is provided under the terms of the
# license in the file LICENSE.

add_library(hemelb_extraction OBJECT

set(EXTRACTION_SOURCES
GeometrySelector.cc
StraightLineGeometrySelector.cc LocalPropertyOutput.cc
IterableDataSource.cc PlaneGeometrySelector.cc PropertyActor.cc
PropertyWriter.cc WholeGeometrySelector.cc LbDataSourceIterator.cc
GeometrySurfaceSelector.cc SurfacePointSelector.cc LocalDistributionInput.cc)
StraightLineGeometrySelector.cc
IterableDataSource.cc
PlaneGeometrySelector.cc
PropertyActor.cc
PropertyWriter.cc
WholeGeometrySelector.cc
LbDataSourceIterator.cc
GeometrySurfaceSelector.cc
SurfacePointSelector.cc
LocalDistributionInput.cc

# reconstructed base class from the original class
LocalPropertyOutput.cc
# subclass for original XDR functionality
XdrPropertyOutput.cc
)

# new source files for HDF5 support
# only include these if USE_HDF5 is enabled
if(USE_HDF5)
list(APPEND EXTRACTION_SOURCES
LocalPropertyHdf5Output.cc
)
endif()

# use the list of sources to create the hemelb_extraction library
add_library(hemelb_extraction OBJECT
${EXTRACTION_SOURCES}
)

# new CMake module for HDF5 support
# only include this if USE_HDF5 is enabled
if(USE_HDF5)
# include the HDF5 module into hemelb_extraction module's list of dependencies
# PUBLIC makes the include directories and libraries available to consumers of hemelb_extraction
target_include_directories(hemelb_extraction PUBLIC
${HDF5_INCLUDE_DIRS}
)

# link the hemelb_extraction library with HDF5
target_link_libraries(hemelb_extraction PUBLIC
HDF5::HDF5
)
# define a preprocessor macro to indicate that HDF5 is being used
target_compile_definitions(hemelb_extraction PUBLIC USE_HDF5)
endif()
79 changes: 79 additions & 0 deletions Code/extraction/LoacalPropertyHdf5Output.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// LocalPropertyHdf5Output.cc
#include "LocalPropertyHdf5Output.h"
#ifdef USE_HDF5
#include <vector>
#include <cassert>

namespace hemelb::io {

#pragma pack(push,1)
struct PointRec
{
uint32_t x, y, z;
double pressure;
};
#pragma pack(pop)

LocalPropertyHdf5Output::LocalPropertyHdf5Output(IterableDataSource& src,
const PropertyOutputFile& spec,
const net::IOCommunicator& comms)
: LocalPropertyOutputBase(src, spec, comms),
comm_(comms.GetCommunicator())
{
// ---- 定义 compound datatype ----
memType_ = H5Tcreate(H5T_COMPOUND, sizeof(PointRec));
H5Tinsert(memType_, "x", HOFFSET(PointRec, x), H5T_NATIVE_UINT32);
H5Tinsert(memType_, "y", HOFFSET(PointRec, y), H5T_NATIVE_UINT32);
H5Tinsert(memType_, "z", HOFFSET(PointRec, z), H5T_NATIVE_UINT32);
H5Tinsert(memType_, "p", HOFFSET(PointRec, pressure), H5T_NATIVE_DOUBLE);
}

void LocalPropertyHdf5Output::StartFile(const std::string& fn)
{
hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(fapl, comm_, MPI_INFO_NULL);
file_ = H5Fcreate(fn.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
H5Pclose(fapl);

const hsize_t global = globalSiteCount; // 这个成员继承自基类
fileSpace_ = H5Screate_simple(1, &global, nullptr);
dset_ = H5Dcreate(file_, "points", memType_, fileSpace_,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}

void LocalPropertyHdf5Output::Write(unsigned long /*ts*/, unsigned long /*total*/)
{
std::vector<PointRec> buf;
buf.reserve(localSiteCount);

while (dataSource.ReadNext()) {
const auto& pos = dataSource.GetPosition();
buf.push_back({pos.x, pos.y, pos.z, dataSource.GetPressure()});
}
assert(buf.size() == localSiteCount);

// 选择 hyperslab
const hsize_t start = localSiteStartRow;
const hsize_t count = localSiteCount;
H5Sselect_hyperslab(fileSpace_, H5S_SELECT_SET, &start, nullptr, &count, nullptr);

hid_t memSpace = H5Screate_simple(1, &count, nullptr);
hid_t xfer = H5Pcreate(H5P_DATASET_XFER);
H5Pset_dxpl_mpio(xfer, H5FD_MPIO_COLLECTIVE);

H5Dwrite(dset_, memType_, memSpace, fileSpace_, xfer, buf.data());

H5Sclose(memSpace);
H5Pclose(xfer);
}

void LocalPropertyHdf5Output::Close()
{
if (dset_ >= 0) H5Dclose(dset_);
if (fileSpace_ >= 0) H5Sclose(fileSpace_);
if (memType_ >= 0) H5Tclose(memType_);
if (file_ >= 0) H5Fclose(file_);
}

} // namespace hemelb::io
#endif // USE_HDF5
Loading