From ba6816d4df177e3610bb1386ebab106188eba018 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 26 Oct 2020 13:14:25 -0500 Subject: [PATCH] Corrections after rebase. --- include/openmc/mesh.h | 18 ++++- src/mesh.cpp | 166 +++++++++++++++++++++--------------------- 2 files changed, 100 insertions(+), 84 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 208399c51f..3f7029b72b 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -222,8 +222,6 @@ public: double negative_grid_boundary(int* ijk, int i) const override; - int n_surface_bins() const override; - std::pair, std::vector> plot(Position plot_ll, Position plot_ur) const override; @@ -294,6 +292,9 @@ public: //! Add a variable to the mesh instance virtual void add_score(const std::string& var_name) = 0; + //! Remove variable from the mesh instance + virtual void remove_score(const std::string& var_name) = 0; + //! Set the value of a bin for a variable on the mesh instance virtual void set_score_data(const std::string& var_name, std::vector values, @@ -324,6 +325,15 @@ public: void to_hdf5(hid_t group) const override; + //! Count number of bank sites in each mesh bin / energy bin + // + //! \param[in] bank Array of bank sites + //! \param[out] Whether any bank sites are outside the mesh + //! \return Array indicating number of sites in each mesh/energy bin + xt::xtensor count_sites(const Particle::Bank* bank, + int64_t length, + bool* outside) const; + // Data members bool output_ {true}; std::string filename_; //!< Path to unstructured mesh file @@ -370,7 +380,7 @@ public: std::vector std_dev) override; //! Remove a score from the mesh instance - void remove_score(std::string score) const; + void remove_score(const std::string& score) override; //! Set data for a score void set_score_data(const std::string& score, @@ -517,6 +527,8 @@ public: void add_score(const std::string& var_name) override; + void remove_score(const std::string& var_name) override; + void set_score_data(const std::string& var_name, std::vector values, std::vector std_dev) override; diff --git a/src/mesh.cpp b/src/mesh.cpp index 7d7ecb6291..27e49107dd 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -162,7 +162,7 @@ UnstructuredMesh::to_hdf5(hid_t group) const write_dataset(mesh_group, "library", this->library()); // write volume of each tet std::vector tet_vols; - xt::xtensor centroids({this->n_bins(), 3}); + xt::xtensor centroids({(size_t)this->n_bins(), 3}); for (int i = 0; i < this->n_bins(); i++) { tet_vols.emplace_back(this->volume(i)); auto c = this->centroid(i); @@ -180,90 +180,90 @@ UnstructuredMesh::to_hdf5(hid_t group) const // RegularMesh implementation //============================================================================== -RegularMesh::RegularMesh(pugi::xml_node node) - : StructuredMesh {node} -{ - // Determine number of dimensions for mesh - if (check_for_node(node, "dimension")) { - shape_ = get_node_xarray(node, "dimension"); - int n = n_dimension_ = shape_.size(); - if (n != 1 && n != 2 && n != 3) { - fatal_error("Mesh must be one, two, or three dimensions."); - } +// RegularMesh::RegularMesh(pugi::xml_node node) +// : StructuredMesh {node} +// { +// // Determine number of dimensions for mesh +// if (check_for_node(node, "dimension")) { +// shape_ = get_node_xarray(node, "dimension"); +// int n = n_dimension_ = shape_.size(); +// if (n != 1 && n != 2 && n != 3) { +// fatal_error("Mesh must be one, two, or three dimensions."); +// } - // Check that dimensions are all greater than zero - if (xt::any(shape_ <= 0)) { - fatal_error("All entries on the element for a tally " - "mesh must be positive."); - } - } +// // Check that dimensions are all greater than zero +// if (xt::any(shape_ <= 0)) { +// fatal_error("All entries on the element for a tally " +// "mesh must be positive."); +// } +// } - // Check for lower-left coordinates - if (check_for_node(node, "lower_left")) { - // Read mesh lower-left corner location - lower_left_ = get_node_xarray(node, "lower_left"); - } else { - fatal_error("Must specify on a mesh."); - } +// // Check for lower-left coordinates +// if (check_for_node(node, "lower_left")) { +// // Read mesh lower-left corner location +// lower_left_ = get_node_xarray(node, "lower_left"); +// } else { +// fatal_error("Must specify on a mesh."); +// } - if (check_for_node(node, "width")) { - // Make sure both upper-right or width were specified - if (check_for_node(node, "upper_right")) { - fatal_error("Cannot specify both and on a mesh."); - } +// if (check_for_node(node, "width")) { +// // Make sure both upper-right or width were specified +// if (check_for_node(node, "upper_right")) { +// fatal_error("Cannot specify both and on a mesh."); +// } - width_ = get_node_xarray(node, "width"); +// width_ = get_node_xarray(node, "width"); - // Check to ensure width has same dimensions - auto n = width_.size(); - if (n != lower_left_.size()) { - fatal_error("Number of entries on must be the same as " - "the number of entries on ."); - } +// // Check to ensure width has same dimensions +// auto n = width_.size(); +// if (n != lower_left_.size()) { +// fatal_error("Number of entries on must be the same as " +// "the number of entries on ."); +// } - // Check for negative widths - if (xt::any(width_ < 0.0)) { - fatal_error("Cannot have a negative on a tally mesh."); - } +// // Check for negative widths +// if (xt::any(width_ < 0.0)) { +// fatal_error("Cannot have a negative on a tally mesh."); +// } - // Set width and upper right coordinate - upper_right_ = xt::eval(lower_left_ + shape_ * width_); +// // Set width and upper right coordinate +// upper_right_ = xt::eval(lower_left_ + shape_ * width_); - } else if (check_for_node(node, "upper_right")) { - upper_right_ = get_node_xarray(node, "upper_right"); +// } else if (check_for_node(node, "upper_right")) { +// upper_right_ = get_node_xarray(node, "upper_right"); - // Check to ensure width has same dimensions - auto n = upper_right_.size(); - if (n != lower_left_.size()) { - fatal_error("Number of entries on must be the " - "same as the number of entries on ."); - } +// // Check to ensure width has same dimensions +// auto n = upper_right_.size(); +// if (n != lower_left_.size()) { +// fatal_error("Number of entries on must be the " +// "same as the number of entries on ."); +// } - // Check that upper-right is above lower-left - if (xt::any(upper_right_ < lower_left_)) { - fatal_error("The coordinates must be greater than " - "the coordinates on a tally mesh."); - } +// // Check that upper-right is above lower-left +// if (xt::any(upper_right_ < lower_left_)) { +// fatal_error("The coordinates must be greater than " +// "the coordinates on a tally mesh."); +// } - // Set width - if (shape_.size() > 0) { - width_ = xt::eval((upper_right_ - lower_left_) / shape_); - } - } else { - fatal_error("Must specify either and on a mesh."); - } +// // Set width +// if (shape_.size() > 0) { +// width_ = xt::eval((upper_right_ - lower_left_) / shape_); +// } +// } else { +// fatal_error("Must specify either and on a mesh."); +// } - // Make sure lower_left and dimension match - if (shape_.size() > 0) { - if (shape_.size() != lower_left_.size()) { - fatal_error("Number of entries on must be the same " - "as the number of entries on ."); - } +// // Make sure lower_left and dimension match +// if (shape_.size() > 0) { +// if (shape_.size() != lower_left_.size()) { +// fatal_error("Number of entries on must be the same " +// "as the number of entries on ."); +// } - // Set volume fraction - volume_frac_ = 1.0/xt::prod(shape_)(); - } -} +// // Set volume fraction +// volume_frac_ = 1.0/xt::prod(shape_)(); +// } +// } void StructuredMesh::get_indices(Position r, int* ijk, bool* in_mesh) const { @@ -2087,7 +2087,7 @@ MOABUnstructuredMesh::add_score(const std::string& score) { auto score_tags = get_score_tags(score); } -void UnstructuredMesh::remove_score(std::string score) const { +void MOABUnstructuredMesh::remove_score(const std::string& score) { auto value_name = score + "_mean"; moab::Tag tag; moab::ErrorCode rval = mbi_->tag_get_handle(value_name.c_str(), tag); @@ -2163,16 +2163,14 @@ MOABUnstructuredMesh::write(std::string base_filename) const { auto msg = fmt::format("Failed to write unstructured mesh {}", id_); warning(msg); } +} -xt::xarray -UnstructuredMesh::count_sites(const std::vector& bank, - bool* outside) const { - xt::array out; +xt::xtensor +UnstructuredMesh::count_sites(const Particle::Bank* bank, + int64_t length, + bool* outside) const { + xt::xtensor out; return out; - } - -double UnstructuredMesh::get_volume_frac(int bin = -1) const { - return 0.0; } #endif @@ -2263,6 +2261,12 @@ LibMesh::add_score(const std::string& var_name) { } } +void +LibMesh::remove_score(const std::string& var_name) { + return; +} + + void LibMesh::set_score_data(const std::string& var_name, std::vector values,