Some additions/improvements after the rebase.

This commit is contained in:
Patrick Shriwise 2020-02-18 15:20:06 -06:00
parent da9b713adb
commit dc7bc30b88
3 changed files with 29 additions and 20 deletions

View file

@ -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<int> 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<double, 1> 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<double, 1> values,
xt::xtensor<double, 1> sum_sq) const;
xt::xarray<double> values,
xt::xarray<double> sum_sq) const;
//! Write the mesh with any current tally data
void write(std::string base_filename) const;

View file

@ -3,6 +3,7 @@
#include <algorithm> // for copy, equal, min, min_element
#include <cstddef> // for size_t
#include <cmath> // for ceil
#include <fmt/core.h> // for fmt
#include <memory> // for allocator
#include <string>
@ -81,6 +82,24 @@ Mesh::Mesh(pugi::xml_node node) {
}
}
//==============================================================================
// Structured Mesh implementation
//==============================================================================
std::string
StructuredMesh::bin_label(int bin) const {
std::vector<int> 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 <width> 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<double> tet_vols;
xt::xtensor<double, 2> centroids({n_bins(), 3});
xt::xtensor<double, 2> 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<double>({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<double, 1> values,
xt::xtensor<double, 1> sum_sq) const {
xt::xarray<double> values,
xt::xarray<double> sum_sq) const {
auto score_tags = get_score_tags(score);
moab::ErrorCode rval;

View file

@ -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;