diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 56994a48da..57a8f8063d 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -126,18 +126,7 @@ public: virtual void get_indices_from_bin(int bin, int* ijk) const = 0; //! Get a label for the mesh bin - std::string bin_label(int bin) const override { - std::vector ijk(n_dimension_); - get_indices_from_bin(bin, ijk.data()); - - if (n_dim > 2) { - return fmt::format("Mesh Index ({}, {}, {})", ijk[0], ijk[1], ijk[2]); - } else if (n_dim > 1) { - return fmt::format("Mesh Index ({}, {})", ijk[0], ijk[1]); - } else { - return fmt::format("Mesh Index ({})", ijk[0]) ; - } - } + std::string bin_label(int bin) const override; // Data members xt::xtensor lower_left_; //!< Lower-left coordinates of mesh @@ -398,8 +387,8 @@ public: //! Set data for a score void set_score_data(const std::string& score, - xt::xtensor values, - xt::xtensor sum_sq) const; + xt::xarray values, + xt::xarray sum_sq) const; //! Write the mesh with any current tally data void write(std::string base_filename) const; diff --git a/src/mesh.cpp b/src/mesh.cpp index f16523b8de..cf9df61791 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -3,6 +3,7 @@ #include // for copy, equal, min, min_element #include // for size_t #include // for ceil +#include // for fmt #include // for allocator #include @@ -81,6 +82,24 @@ Mesh::Mesh(pugi::xml_node node) { } } +//============================================================================== +// Structured Mesh implementation +//============================================================================== + +std::string +StructuredMesh::bin_label(int bin) const { + std::vector ijk(n_dimension_); + get_indices_from_bin(bin, ijk.data()); + + if (n_dimension_ > 2) { + return fmt::format("Mesh Index ({}, {}, {})", ijk[0], ijk[1], ijk[2]); + } else if (n_dimension_ > 1) { + return fmt::format("Mesh Index ({}, {})", ijk[0], ijk[1]); + } else { + return fmt::format("Mesh Index ({})", ijk[0]) ; + } +} + //============================================================================== // RegularMesh implementation //============================================================================== @@ -131,7 +150,7 @@ RegularMesh::RegularMesh(pugi::xml_node node) fatal_error("Cannot have a negative on a tally mesh."); } - // Set width and upper right coordinate + // Setwidth and upper right coordinate upper_right_ = xt::eval(lower_left_ + shape_ * width_); } else if (check_for_node(node, "upper_right")) { @@ -1869,13 +1888,14 @@ UnstructuredMesh::to_hdf5(hid_t group) const // write volume of each tet std::vector tet_vols; - xt::xtensor centroids({n_bins(), 3}); + xt::xtensor centroids({ehs_.size(), 3}); for (int i = 0; i < ehs_.size(); i++) { const auto& eh = ehs_[i]; tet_vols.emplace_back(tet_volume(eh)); Position c = centroid(eh); xt::view(centroids, i, xt::all()) = xt::xarray({c.x, c.y, c.z}); } + write_dataset(mesh_group, "volumes", tet_vols); write_dataset(mesh_group, "centroids", centroids); @@ -2061,8 +2081,8 @@ UnstructuredMesh::add_score(std::string score) const { void UnstructuredMesh::set_score_data(const std::string& score, - xt::xtensor values, - xt::xtensor sum_sq) const { + xt::xarray values, + xt::xarray sum_sq) const { auto score_tags = get_score_tags(score); moab::ErrorCode rval; diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index f05b38801f..f173b5a098 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -844,8 +844,8 @@ void Tally::accumulate() umesh->add_score(std::to_string(score)); for (int i = 0; i < results_.shape()[0]; i++) { umesh->set_score_data(std::to_string(score), - xt::view(results_, xt::all(), 0, RESULT_SUM), - xt::view(results_, xt::all(), 0, RESULT_SUM_SQ)); + xt::view(results_, xt::all(), 0, TallyResult::VALUE), + xt::view(results_, xt::all(), 0, TallyResult::SUM_SQ)); } } std::stringstream output_filename;