mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-24 20:15:26 -04:00
Call HDF5 routines from C++ side for voxel plots
This commit is contained in:
parent
279562c32a
commit
3acec3c093
4 changed files with 91 additions and 29 deletions
42
src/plot.cpp
Normal file
42
src/plot.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "plot.h"
|
||||
|
||||
namespace openmc {
|
||||
|
||||
void
|
||||
voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset,
|
||||
hid_t* memspace)
|
||||
{
|
||||
// Create dataspace/dataset for voxel data
|
||||
*dspace = H5Screate_simple(3, dims, nullptr);
|
||||
*dset = H5Dcreate(file_id, "data", H5T_NATIVE_INT, *dspace, H5P_DEFAULT,
|
||||
H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
// Create dataspace for a slice of the voxel
|
||||
hsize_t dims_slice[2] {dims[1], dims[2]};
|
||||
*memspace = H5Screate_simple(2, dims_slice, nullptr);
|
||||
|
||||
// Select hyperslab in dataspace
|
||||
hsize_t start[3] {0, 0, 0};
|
||||
hsize_t count[3] {1, dims[1], dims[2]};
|
||||
H5Sselect_hyperslab(*dspace, H5S_SELECT_SET, start, nullptr, count, nullptr);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf)
|
||||
{
|
||||
hssize_t offset[3] {x - 1, 0, 0};
|
||||
H5Soffset_simple(dspace, offset);
|
||||
H5Dwrite(dset, H5T_NATIVE_INT, memspace, dspace, H5P_DEFAULT, buf);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace)
|
||||
{
|
||||
H5Dclose(dset);
|
||||
H5Sclose(dspace);
|
||||
H5Sclose(memspace);
|
||||
}
|
||||
|
||||
} // namespace openmc
|
||||
Loading…
Add table
Add a link
Reference in a new issue