|
| 1 | +#ifndef OPENMC_XDG_H |
| 2 | +#define OPENMC_XDG_H |
| 3 | + |
| 4 | +namespace openmc { |
| 5 | +extern "C" const bool XDG_ENABLED; |
| 6 | +} |
| 7 | + |
| 8 | +#ifdef OPENMC_XDG_ENABLED |
| 9 | + |
| 10 | +#include "xdg/xdg.h" |
| 11 | + |
| 12 | +#include "openmc/mesh.h" |
| 13 | +#include "openmc/position.h" |
| 14 | +#include "openmc/xml_interface.h" |
| 15 | + |
| 16 | +namespace openmc { |
| 17 | + |
| 18 | +class XDGMesh : public UnstructuredMesh { |
| 19 | + |
| 20 | +public: |
| 21 | + //---------------------------------------------------------------------------- |
| 22 | + // Constructors |
| 23 | + XDGMesh() = default; |
| 24 | + XDGMesh(pugi::xml_node node); |
| 25 | + XDGMesh(hid_t group); |
| 26 | + XDGMesh(const std::string& filename, double length_multiplier = 1.0); |
| 27 | + XDGMesh(std::shared_ptr<xdg::XDG> external_xdg); |
| 28 | + |
| 29 | + static const std::string mesh_interface; |
| 30 | + |
| 31 | + //---------------------------------------------------------------------------- |
| 32 | + // Methods |
| 33 | + |
| 34 | + //! Get the underlying XDG instance |
| 35 | + //! |
| 36 | + //! \return Shared pointer to the XDG instance |
| 37 | + const std::shared_ptr<xdg::XDG>& xdg_instance() const { return xdg_; } |
| 38 | + |
| 39 | + //! Check whether a bin index is valid |
| 40 | + //! |
| 41 | + //! \param[in] bin Bin index to check |
| 42 | + //! \return True if the bin index is in [0, n_bins()) |
| 43 | + bool bin_is_valid(int bin) const { return bin >= 0 && bin < n_bins(); } |
| 44 | + |
| 45 | + //! Convert a mesh bin index to an XDG MeshID |
| 46 | + //! |
| 47 | + //! \param[in] bin Bin index to convert |
| 48 | + //! \return XDG MeshID corresponding to the bin |
| 49 | + xdg::MeshID bin_to_mesh_id(int bin) const; |
| 50 | + |
| 51 | + //! Convert an XDG MeshID to a mesh bin index |
| 52 | + //! |
| 53 | + //! \param[in] id XDG MeshID to convert |
| 54 | + //! \return Bin index corresponding to the MeshID, or -1 if invalid |
| 55 | + int mesh_id_to_bin(xdg::MeshID id) const; |
| 56 | + |
| 57 | + //! Get the name of the underlying mesh library |
| 58 | + //! |
| 59 | + //! \return Name of the mesh library being used in XDG |
| 60 | + std::string library() const override; |
| 61 | + |
| 62 | + //---------------------------------------------------------------------------- |
| 63 | + // Overridden Methods |
| 64 | + |
| 65 | + //! Perform any preparation needed to support use in mesh filters |
| 66 | + void prepare_for_point_location() override; |
| 67 | + |
| 68 | + Position sample_element(int32_t bin, uint64_t* seed) const override; |
| 69 | + |
| 70 | + void bins_crossed(Position r0, Position r1, const Direction& u, |
| 71 | + vector<int>& bins, vector<double>& lengths) const override; |
| 72 | + |
| 73 | + int get_bin(Position r) const override; |
| 74 | + |
| 75 | + int n_bins() const override; |
| 76 | + |
| 77 | + int n_surface_bins() const override; |
| 78 | + |
| 79 | + std::pair<vector<double>, vector<double>> plot( |
| 80 | + Position plot_ll, Position plot_ur) const override; |
| 81 | + |
| 82 | + //! Add a score to the mesh instance |
| 83 | + void add_score(const std::string& score) override {}; |
| 84 | + |
| 85 | + //! Remove all scores from the mesh instance |
| 86 | + void remove_scores() override {}; |
| 87 | + |
| 88 | + //! Set data for a score |
| 89 | + void set_score_data(const std::string& score, const vector<double>& values, |
| 90 | + const vector<double>& std_dev) override {}; |
| 91 | + |
| 92 | + //! Write the mesh with any current tally data |
| 93 | + void write(const std::string& base_filename) const override; |
| 94 | + |
| 95 | + Position centroid(int bin) const override; |
| 96 | + |
| 97 | + int n_vertices() const override; |
| 98 | + |
| 99 | + Position vertex(int id) const override; |
| 100 | + |
| 101 | + std::vector<int> connectivity(int id) const override; |
| 102 | + |
| 103 | + //! Get the volume of a mesh bin |
| 104 | + // |
| 105 | + //! \param[in] bin Bin to return the volume for |
| 106 | + //! \return Volume of the bin |
| 107 | + double volume(int bin) const override; |
| 108 | + |
| 109 | +private: |
| 110 | + void initialize() override; |
| 111 | + |
| 112 | + int n_surface_bins_ {0}; //!< Number of surface bins in the mesh |
| 113 | + |
| 114 | + //---------------------------------------------------------------------------- |
| 115 | + // Private data members |
| 116 | + std::shared_ptr<xdg::XDG> xdg_; //!< XDG instance |
| 117 | + xdg::MeshLibrary mesh_library_ { |
| 118 | + xdg::MeshLibrary::LIBMESH}; //!< Mesh library type |
| 119 | +}; |
| 120 | + |
| 121 | +} // namespace openmc |
| 122 | + |
| 123 | +#endif // OPENMC_XDG_ENABLED |
| 124 | + |
| 125 | +#endif // OPENMC_XDG_H |
0 commit comments