-
Notifications
You must be signed in to change notification settings - Fork 644
XDGMesh Object
#3889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
XDGMesh Object
#3889
Changes from all commits
a291953
d85fd1f
612c891
e860ea9
f3603fc
36dc4ac
2ec0d47
645c97f
1b3a9a2
028a9ad
380b81b
ca5bd5a
8c178fd
ab9b610
6cfde21
1584b93
fe27f04
443290a
9c959ea
b0fbd79
4ca53f2
19ba002
1bc11f5
cbff2ad
da34bf6
d3a9268
a892100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| get_filename_component(OpenMC_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) | ||
|
|
||
| # Compute the install prefix from this file's location | ||
| get_filename_component(_OPENMC_PREFIX "${OpenMC_CMAKE_DIR}/../../.." ABSOLUTE) | ||
| include(CMakeFindDependencyMacro) | ||
|
|
||
| find_package(fmt CONFIG REQUIRED HINTS ${_OPENMC_PREFIX}) | ||
| find_package(pugixml CONFIG REQUIRED HINTS ${_OPENMC_PREFIX}) | ||
| if(@OPENMC_USE_DAGMC@) | ||
| find_package(DAGMC REQUIRED HINTS @DAGMC_DIR@) | ||
| if(@OPENMC_USE_XDG@) | ||
| if(NOT TARGET xdg::xdg) | ||
| find_dependency(XDG CONFIG REQUIRED HINTS "@XDG_DIR@") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(@OPENMC_USE_LIBMESH@) | ||
|
|
@@ -16,18 +15,40 @@ if(@OPENMC_USE_LIBMESH@) | |
| pkg_check_modules(LIBMESH REQUIRED @LIBMESH_PC_FILE@>=1.7.0 IMPORTED_TARGET) | ||
| endif() | ||
|
|
||
| find_package(PNG) | ||
| if(@OPENMC_USE_DAGMC@) | ||
| if(NOT TARGET dagmc-shared) | ||
| find_dependency(DAGMC REQUIRED HINTS "@DAGMC_DIR@") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(NOT TARGET OpenMC::libopenmc) | ||
| include("${OpenMC_CMAKE_DIR}/OpenMCTargets.cmake") | ||
| if(NOT TARGET fmt::fmt) | ||
| find_dependency(fmt CONFIG REQUIRED) | ||
| endif() | ||
|
|
||
| if(NOT TARGET pugixml::pugixml AND NOT TARGET pugixml) | ||
| find_dependency(pugixml CONFIG REQUIRED) | ||
| endif() | ||
|
|
||
| if(@PNG_FOUND@) | ||
| if(NOT TARGET PNG::PNG) | ||
| find_dependency(PNG REQUIRED) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(@OPENMC_USE_MPI@) | ||
| find_package(MPI REQUIRED) | ||
| if(NOT TARGET MPI::MPI_CXX) | ||
| find_dependency(MPI REQUIRED) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(@OPENMC_USE_OPENMP@) | ||
| find_package(OpenMP REQUIRED) | ||
| if(NOT TARGET OpenMP::OpenMP_CXX) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that #3653 is merged, you'll need to update this file. One difference between #3653 and what you have here is that you also have the calls to |
||
| find_dependency(OpenMP REQUIRED) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(NOT TARGET OpenMC::libopenmc) | ||
| include("${OpenMC_CMAKE_DIR}/OpenMCTargets.cmake") | ||
| endif() | ||
|
|
||
| if(@OPENMC_USE_UWUW@ AND NOT ${DAGMC_BUILD_UWUW}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,12 @@ namespace openmc { | |
|
|
||
| enum class ElementType { UNSUPPORTED = -1, LINEAR_TET, LINEAR_HEX }; | ||
|
|
||
| struct NextMeshCell { | ||
| double distance {INFTY}; | ||
| int face_idx {-1}; | ||
| std::array<int, 3> next_ijk; | ||
| }; | ||
|
Comment on lines
+50
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only used by |
||
|
|
||
| //============================================================================== | ||
| // Global variables | ||
| //============================================================================== | ||
|
|
@@ -771,6 +777,9 @@ class UnstructuredMesh : public Mesh { | |
| //! Get the library used for this unstructured mesh | ||
| virtual std::string library() const = 0; | ||
|
|
||
| //! Get the mesh filename | ||
| virtual const std::string& filename() const { return filename_; } | ||
|
|
||
| // Data members | ||
| bool output_ { | ||
| true}; //!< Write tallies onto the unstructured mesh at the end of a run | ||
|
|
@@ -797,7 +806,36 @@ class UnstructuredMesh : public Mesh { | |
| //! \param[in] coords Coordinates of the tetrahedron | ||
| //! \param[in] seed Random number generation seed | ||
| //! \return Sampled position within the tetrahedron | ||
| Position sample_tet(std::array<Position, 4> coords, uint64_t* seed) const; | ||
| template<typename V> | ||
| Position sample_tet(span<V> coords, uint64_t* seed) const | ||
| { | ||
| // Uniform distribution | ||
| double s = prn(seed); | ||
| double t = prn(seed); | ||
| double u = prn(seed); | ||
|
|
||
| // From PyNE implementation of moab tet sampling C. Rocchini & P. Cignoni | ||
| // (2000) Generating Random Points in a Tetrahedron, Journal of Graphics | ||
| // Tools, 5:4, 9-12, DOI: 10.1080/10867651.2000.10487528 | ||
| if (s + t > 1) { | ||
| s = 1.0 - s; | ||
| t = 1.0 - t; | ||
| } | ||
| if (s + t + u > 1) { | ||
| if (t + u > 1) { | ||
| double old_t = t; | ||
| t = 1.0 - u; | ||
| u = 1.0 - s - old_t; | ||
| } else if (t + u <= 1) { | ||
| double old_s = s; | ||
| s = 1.0 - t - u; | ||
| u = old_s + t + u - 1; | ||
| } | ||
| } | ||
| V result = s * (coords[1] - coords[0]) + t * (coords[2] - coords[0]) + | ||
| u * (coords[3] - coords[0]) + coords[0]; | ||
| return {result[0], result[1], result[2]}; | ||
| } | ||
|
|
||
| // Data members | ||
| double length_multiplier_ { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #ifndef OPENMC_XDG_H | ||
| #define OPENMC_XDG_H | ||
|
|
||
| namespace openmc { | ||
| extern "C" const bool XDG_ENABLED; | ||
| } | ||
|
|
||
| #ifdef OPENMC_XDG_ENABLED | ||
|
|
||
| #include "xdg/xdg.h" | ||
|
|
||
| #include "openmc/mesh.h" | ||
| #include "openmc/position.h" | ||
| #include "openmc/xml_interface.h" | ||
|
|
||
| namespace openmc { | ||
|
|
||
| class XDGMesh : public UnstructuredMesh { | ||
|
|
||
| public: | ||
| //---------------------------------------------------------------------------- | ||
| // Constructors | ||
| XDGMesh() = default; | ||
| XDGMesh(pugi::xml_node node); | ||
| XDGMesh(hid_t group); | ||
| XDGMesh(const std::string& filename, double length_multiplier = 1.0); | ||
| XDGMesh(std::shared_ptr<xdg::XDG> external_xdg); | ||
|
|
||
| static const std::string mesh_lib_type; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| // Methods | ||
|
|
||
| //! Get the underlying XDG instance | ||
| //! | ||
| //! \return Shared pointer to the XDG instance | ||
| const std::shared_ptr<xdg::XDG>& xdg_instance() const { return xdg_; } | ||
|
|
||
| //! Check whether a bin index is valid | ||
| //! | ||
| //! \param[in] bin Bin index to check | ||
| //! \return True if the bin index is in [0, n_bins()) | ||
| bool bin_is_valid(int bin) const { return bin >= 0 && bin < n_bins(); } | ||
|
|
||
| //! Convert a mesh bin index to an XDG MeshID | ||
| //! | ||
| //! \param[in] bin Bin index to convert | ||
| //! \return XDG MeshID corresponding to the bin | ||
| xdg::MeshID bin_to_mesh_id(int bin) const; | ||
|
|
||
| //! Convert an XDG MeshID to a mesh bin index | ||
| //! | ||
| //! \param[in] id XDG MeshID to convert | ||
| //! \return Bin index corresponding to the MeshID, or -1 if invalid | ||
| int mesh_id_to_bin(xdg::MeshID id) const; | ||
|
|
||
| //! Get the name of the underlying mesh library | ||
| //! | ||
| //! \return Name of the mesh library ("moab" or "libmesh") | ||
| std::string mesh_library() const; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| // Overridden Methods | ||
|
|
||
| //! Perform any preparation needed to support use in mesh filters | ||
| void prepare_for_point_location() override; | ||
|
|
||
| Position sample_element(int32_t bin, uint64_t* seed) const override; | ||
|
|
||
| void bins_crossed(Position r0, Position r1, const Direction& u, | ||
| vector<int>& bins, vector<double>& lengths) const override; | ||
|
|
||
| int get_bin(Position r) const override; | ||
|
|
||
| int n_bins() const override; | ||
|
|
||
| int n_surface_bins() const override; | ||
|
|
||
| std::pair<vector<double>, vector<double>> plot( | ||
| Position plot_ll, Position plot_ur) const override; | ||
|
|
||
| std::string library() const override; | ||
|
|
||
| //! Add a score to the mesh instance | ||
| void add_score(const std::string& score) override {}; | ||
|
|
||
| //! Remove all scores from the mesh instance | ||
| void remove_scores() override {}; | ||
|
|
||
| //! Set data for a score | ||
| void set_score_data(const std::string& score, const vector<double>& values, | ||
| const vector<double>& std_dev) override {}; | ||
|
|
||
| //! Write the mesh with any current tally data | ||
| void write(const std::string& base_filename) const override; | ||
|
|
||
| Position centroid(int bin) const override; | ||
|
|
||
| int n_vertices() const override; | ||
|
|
||
| Position vertex(int id) const override; | ||
|
|
||
| std::vector<int> connectivity(int id) const override; | ||
|
|
||
| //! Get the volume of a mesh bin | ||
| // | ||
| //! \param[in] bin Bin to return the volume for | ||
| //! \return Volume of the bin | ||
| double volume(int bin) const override; | ||
|
|
||
| //! Get the distance to the nearest boundary for a given position and | ||
| //! direction \param[in] g GeometryState object containing position and | ||
| //! direction \return NextMeshCell struct containing distance, face index, and | ||
| //! next indices | ||
| NextMeshCell distance_to_bin_boundary(GeometryState& g) const; | ||
|
|
||
| //! Get the distance to the nearest boundary for a given position and | ||
| //! direction \param[in] r Position to check \param[in] u Direction to check | ||
| //! \return Distance to the nearest boundary | ||
| NextMeshCell distance_to_bin_boundary( | ||
| int bin, const Position& r, const Direction& u) const; | ||
|
Comment on lines
+111
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not defined/used |
||
|
|
||
| private: | ||
| void initialize() override; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| // Private data members | ||
| std::shared_ptr<xdg::XDG> xdg_; //!< XDG instance | ||
| xdg::MeshLibrary mesh_library_ { | ||
| xdg::MeshLibrary::LIBMESH}; //!< Mesh library type | ||
| }; | ||
|
|
||
| } // namespace openmc | ||
|
|
||
| #endif // OPENMC_XDG_ENABLED | ||
|
|
||
| #endif // OPENMC_XDG_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if maybe we should just have a single configuration that covers DAGMC, libMesh, and XDG. Do you see any downside of that?