mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
135 lines
4.2 KiB
C++
135 lines
4.2 KiB
C++
//! \file mesh.h
|
|
//! \brief Mesh types used for tallies, Shannon entropy, CMFD, etc.
|
|
|
|
#ifndef OPENMC_MESH_H
|
|
#define OPENMC_MESH_H
|
|
|
|
#include <memory> // for unique_ptr
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
#include "hdf5.h"
|
|
#include "pugixml.hpp"
|
|
#include "xtensor/xarray.hpp"
|
|
|
|
#include "openmc/particle.h"
|
|
#include "openmc/position.h"
|
|
|
|
namespace openmc {
|
|
|
|
//==============================================================================
|
|
// Global variables
|
|
//==============================================================================
|
|
|
|
class RegularMesh;
|
|
|
|
namespace model {
|
|
|
|
extern std::vector<std::unique_ptr<RegularMesh>> meshes;
|
|
extern std::unordered_map<int32_t, int32_t> mesh_map;
|
|
|
|
} // namespace model
|
|
|
|
//==============================================================================
|
|
//! Tessellation of n-dimensional Euclidean space by congruent squares or cubes
|
|
//==============================================================================
|
|
|
|
class RegularMesh {
|
|
public:
|
|
// Constructors
|
|
RegularMesh() = default;
|
|
RegularMesh(pugi::xml_node node);
|
|
|
|
// Methods
|
|
|
|
//! Determine which bins were crossed by a particle
|
|
//!
|
|
//! \param[in] p Particle to check
|
|
//! \param[out] bins Bins that were crossed
|
|
//! \param[out] lengths Fraction of tracklength in each bin
|
|
void bins_crossed(const Particle* p, std::vector<int>& bins,
|
|
std::vector<double>& lengths) const;
|
|
|
|
//! 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<int>& bins) const;
|
|
|
|
//! Get bin at a given position in space
|
|
//!
|
|
//! \param[in] r Position to get bin for
|
|
//! \return Mesh bin
|
|
int get_bin(Position r) const;
|
|
|
|
//! Get bin given mesh indices
|
|
//!
|
|
//! \param[in] Array of mesh indices
|
|
//! \return Mesh bin
|
|
int get_bin_from_indices(const int* ijk) const;
|
|
|
|
//! Get mesh indices given a position
|
|
//!
|
|
//! \param[in] r Position to get indices for
|
|
//! \param[out] ijk Array of mesh indices
|
|
//! \param[out] in_mesh Whether position is in mesh
|
|
void get_indices(Position r, int* ijk, bool* in_mesh) const;
|
|
|
|
//! Get mesh indices corresponding to a mesh bin
|
|
//!
|
|
//! \param[in] bin Mesh bin
|
|
//! \param[out] ijk Mesh indices
|
|
void get_indices_from_bin(int bin, int* ijk) const;
|
|
|
|
//! Check if a line connected by two points intersects the mesh
|
|
//!
|
|
//! \param[in] r0 Starting position
|
|
//! \param[in] r1 Ending position
|
|
//! \return Whether line connecting r0 and r1 intersects mesh
|
|
bool intersects(Position r0, Position r1) const;
|
|
|
|
//! Write mesh data to an HDF5 group
|
|
//!
|
|
//! \param[in] group HDF5 group
|
|
void to_hdf5(hid_t group) const;
|
|
|
|
//! Count number of bank sites in each mesh bin / energy bin
|
|
//!
|
|
//! \param[in] n Number of bank sites
|
|
//! \param[in] bank Array of bank sites
|
|
//! \param[in] n_energy Number of energies
|
|
//! \param[in] energies Array of energies
|
|
//! \param[out] Whether any bank sites are outside the mesh
|
|
//! \return Array indicating number of sites in each mesh/energy bin
|
|
xt::xarray<double> count_sites(int64_t n, const Bank* bank,
|
|
int n_energy, const double* energies, bool* outside) const;
|
|
|
|
int id_ {-1}; //!< User-specified ID
|
|
int n_dimension_; //!< Number of dimensions
|
|
double volume_frac_; //!< Volume fraction of each mesh element
|
|
xt::xarray<int> shape_; //!< Number of mesh elements in each dimension
|
|
xt::xarray<double> lower_left_; //!< Lower-left coordinates of mesh
|
|
xt::xarray<double> upper_right_; //!< Upper-right coordinates of mesh
|
|
xt::xarray<double> width_; //!< Width of each mesh element
|
|
|
|
private:
|
|
bool intersects_1d(Position r0, Position r1) const;
|
|
bool intersects_2d(Position r0, Position r1) const;
|
|
bool intersects_3d(Position r0, Position r1) const;
|
|
};
|
|
|
|
//==============================================================================
|
|
// Non-member functions
|
|
//==============================================================================
|
|
|
|
//! Read meshes from either settings/tallies
|
|
//! \param[in] root XML node
|
|
extern "C" void read_meshes(pugi::xml_node* root);
|
|
|
|
//! Write mesh data to an HDF5 group
|
|
//! \param[in] group HDF5 group
|
|
extern "C" void meshes_to_hdf5(hid_t group);
|
|
|
|
} // namespace openmc
|
|
|
|
#endif // OPENMC_MESH_H
|