mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 13:15:39 -04:00
Added xtensor read_dataset
This commit is contained in:
parent
af54b60c2e
commit
3cfd9dff9d
2 changed files with 34 additions and 15 deletions
|
|
@ -271,6 +271,34 @@ void read_dataset(hid_t obj_id, const char* name, xt::xarray<T>& arr, bool indep
|
|||
close_dataset(dset);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void read_dataset(hid_t obj_id, const char* name, xt::xtensor<T, N>& arr, bool indep=false)
|
||||
{
|
||||
// Open dataset and read array
|
||||
hid_t dset = open_dataset(obj_id, name);
|
||||
|
||||
// Get shape of dataset
|
||||
std::vector<hsize_t> hsize_t_shape = object_shape(dset);
|
||||
close_dataset(dset);
|
||||
|
||||
// cast from hsize_t to size_t
|
||||
std::vector<size_t> shape(hsize_t_shape.size());
|
||||
for (int i = 0; i < shape.size(); i++) {
|
||||
shape[i] = static_cast<size_t>(hsize_t_shape[i]);
|
||||
}
|
||||
|
||||
// Allocate new xarray to read data into
|
||||
xt::xarray<T> xarr(shape);
|
||||
|
||||
// Read data from the dataset
|
||||
read_dataset(obj_id, name, xarr);
|
||||
|
||||
// Copy into xtensor
|
||||
arr = xarr;
|
||||
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void read_dataset_as_shape(hid_t obj_id, const char* name,
|
||||
xt::xtensor<T, N>& arr, bool indep=false)
|
||||
|
|
|
|||
21
src/urr.cpp
21
src/urr.cpp
|
|
@ -18,23 +18,14 @@ UrrData::UrrData(hid_t group_id)
|
|||
read_attribute(group_id, "multiply_smooth", temp_multiply_smooth);
|
||||
multiply_smooth_ = (temp_multiply_smooth == 1);
|
||||
|
||||
// read the enrgies at which tables exist
|
||||
hid_t dset = open_dataset(group_id, "energy");
|
||||
hsize_t dims[1];
|
||||
get_shape(dset, dims);
|
||||
close_dataset(dset);
|
||||
n_energy_ = static_cast<int>(dims[0]);
|
||||
energy_ = xt::xtensor<double, 1>({dims[0]}, 0.);
|
||||
read_dataset_as_shape(group_id, "energy", energy_);
|
||||
// read the energies at which tables exist
|
||||
read_dataset(group_id, "energy", energy_);
|
||||
|
||||
// Set n_energy_
|
||||
n_energy_ = energy_.shape()[0];
|
||||
|
||||
// Read URR tables
|
||||
dset = open_dataset(group_id, "table");
|
||||
hsize_t dims3[3];
|
||||
get_shape(dset, dims3);
|
||||
close_dataset(dset);
|
||||
xt::xarray<double> temp_arr({dims3[0], dims3[1], dims3[2]}, 0.);
|
||||
read_dataset(group_id, "table", temp_arr);
|
||||
prob_ = temp_arr;
|
||||
read_dataset(group_id, "table", prob_);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue