From a10429f7fa6e666cac85766eddc3d6a707205dba Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 10 May 2019 11:20:42 -0500 Subject: [PATCH] Adding to mesh abstraction to support other operations external to the mesh source files. --- include/openmc/mesh.h | 39 ++++++++++++++++++++++++++++++-- src/eigenvalue.cpp | 4 ++++ src/mesh.cpp | 44 ++++++++++++++++++++++++++++++++++++- src/tallies/filter_mesh.cpp | 1 + 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 112931b60c..ebfa083d0d 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -27,13 +27,11 @@ namespace openmc { // Global variables //============================================================================== - class Mesh; namespace model { extern std::vector> meshes; - extern std::unordered_map mesh_map; } // namespace model @@ -58,12 +56,31 @@ public: //! \param[in] group HDF5 group virtual void to_hdf5(hid_t group) const = 0; + //! Determine which surface bins were crossed by a particle + // + //! \param[in] p Particle to check + //! \param[out] bins Surface bins that were crossed + virtual void + surface_bins_crossed(const Particle* p, std::vector& bins) const = 0; + //! Get bin at a given position in space // //! \param[in] r Position to get bin for //! \return Mesh bin virtual int get_bin(Position r) const = 0; + virtual std::string get_label_for_bin(int bin) const = 0; + + //! 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 + virtual xt::xarray + count_sites(const std::vector& bank, bool* outside) const = 0; + + virtual double get_volume_frac(int bin = -1) = 0; + int id_ {-1}; //!< User-specified ID int n_dimension_; //!< Number of dimensions }; @@ -206,6 +223,11 @@ public: bool* outside) const; // Data members + + //std::string get_label_for_bin(int bin) const; + + //double get_volume_frac(int bin = -1) const; + double volume_frac_; //!< Volume fraction of each mesh element xt::xtensor shape_; //!< Number of mesh elements in each dimension xt::xtensor width_; //!< Width of each mesh element @@ -282,6 +304,12 @@ public: bool intersects(Position& r0, Position r1, int* ijk); + //! Determine which surface bins were crossed by a particle + // + //! \param[in] p Particle to check + //! \param[out] bins Surface bins that were crossed + void surface_bins_crossed(const Particle* p, std::vector& bins) const; + bool point_in_tet(const Position& r, moab::EntityHandle tet) const; //! Write mesh data to an HDF5 group @@ -305,6 +333,13 @@ public: void build_tree(const moab::Range& all_tets); + std::string get_label_for_bin(int bin) const; + + xt::xarray + count_sites(const std::vector& bank, bool* outside) const; + + double get_volume_frac(int bin = -1) const; + private: std::string filename_; moab::Range ehs_; diff --git a/src/eigenvalue.cpp b/src/eigenvalue.cpp index f02a96e7ac..b8305672b7 100644 --- a/src/eigenvalue.cpp +++ b/src/eigenvalue.cpp @@ -538,9 +538,12 @@ void ufs_count_sites() // distributed so that effectively the production of fission sites is not // biased + std::size_t n = simulation::ufs_mesh->n_bins(); double vol_frac = simulation::ufs_mesh->volume_frac_; simulation::source_frac = xt::xtensor({n}, vol_frac); + // auto s = xt::view(simulation::source_frac, xt::all()); + // s = m->get_volume_frac(); } else { // count number of source sites in each ufs mesh cell @@ -583,6 +586,7 @@ double ufs_get_weight(const Particle* p) if (simulation::source_frac(mesh_bin) != 0.0) { return simulation::ufs_mesh->volume_frac_ / simulation::source_frac(mesh_bin); + // return m->get_volume_frac() / simulation::source_frac(mesh_bin); } else { return 1.0; } diff --git a/src/mesh.cpp b/src/mesh.cpp index 74034fc839..7a70080e92 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -5,6 +5,7 @@ #include // for ceil #include // for allocator #include +#include #ifdef OPENMC_MPI #include "mpi.h" @@ -32,7 +33,6 @@ namespace openmc { namespace model { - std::vector> meshes; std::unordered_map mesh_map; @@ -848,6 +848,23 @@ RegularMesh::count_sites(const Particle::Bank* bank, int64_t length, return counts; } +std::string RegularMesh::get_label_for_bin(int bin) const { + int ijk[n_dimension_]; + get_indices_from_bin(bin, ijk); + + std::stringstream out; + out << "Mesh Index (" << ijk[0]; + if (n_dimension_ > 1) out << ", " << ijk[1]; + if (n_dimension_ > 2) out << ", " << ijk[2]; + out << ")"; + + return out.str(); +} + +double RegularMesh::get_volume_frac(int bin) const { + return volume_frac_; +} + //============================================================================== // RectilinearMesh implementation //============================================================================== @@ -1643,6 +1660,20 @@ UnstructuredMesh::get_tet(Position r) const { return 0; } + +//! Determine which surface bins were crossed by a particle +// +//! \param[in] p Particle to check +//! \param[out] bins Surface bins that were crossed +void UnstructuredMesh::surface_bins_crossed(const Particle* p, std::vector& bins) const { + return; +} + +std::string UnstructuredMesh::get_label_for_bin(int bin) { + std::string s; + return s; +} + int UnstructuredMesh::get_bin(Position r) const { moab::EntityHandle tet = get_tet(r); @@ -1727,6 +1758,17 @@ UnstructuredMesh::get_ent_handle_from_bin(int bin) const { return ehs_[bin]; } +xt::xarray +UnstructuredMesh::count_sites(const std::vector& bank, + bool* outside) const { + xt::array out; + return out; + } + +double UnstructuredMesh::get_volume_frac(int bin = -1) const { + return 0.0; +} + #endif diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 6c2cc8bd12..837b425c4a 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -55,6 +55,7 @@ std::string MeshFilter::text_label(int bin) const { auto& mesh = *model::meshes[mesh_]; + int n_dim = mesh.n_dimension_; std::vector ijk(n_dim);