2018-08-08 13:36:42 -05:00
|
|
|
#ifndef OPENMC_GEOMETRY_H
|
|
|
|
|
#define OPENMC_GEOMETRY_H
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2019-03-21 07:43:42 -05:00
|
|
|
#include <cmath>
|
2018-08-14 16:22:40 -04:00
|
|
|
#include <cstdint>
|
2026-07-06 12:47:22 -05:00
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
2018-08-14 16:22:40 -04:00
|
|
|
|
2021-04-22 16:46:23 -04:00
|
|
|
#include "openmc/array.h"
|
2021-04-16 15:35:33 -04:00
|
|
|
#include "openmc/constants.h"
|
2026-07-06 12:47:22 -05:00
|
|
|
#include "openmc/random_ray/source_region.h" // For hash_combine
|
2021-04-22 16:46:23 -04:00
|
|
|
#include "openmc/vector.h"
|
2020-01-14 19:30:18 +00:00
|
|
|
|
2018-06-25 21:00:59 -05:00
|
|
|
namespace openmc {
|
|
|
|
|
|
2021-04-16 15:35:33 -04:00
|
|
|
class BoundaryInfo;
|
2024-01-16 10:35:57 -06:00
|
|
|
class GeometryState;
|
2021-04-16 15:35:33 -04:00
|
|
|
|
2026-07-06 12:47:22 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
//! OverlapKey to store cell and universe data of a single overlap, along with
|
|
|
|
|
//! a functor for hashing an OverlapKey into an unordered_map.
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
|
|
struct OverlapKey {
|
|
|
|
|
int universe_id;
|
|
|
|
|
int cell1_id;
|
|
|
|
|
int cell2_id;
|
|
|
|
|
|
|
|
|
|
bool operator==(const OverlapKey& other) const
|
|
|
|
|
{
|
|
|
|
|
return universe_id == other.universe_id && cell1_id == other.cell1_id &&
|
|
|
|
|
cell2_id == other.cell2_id;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct OverlapKeyHash {
|
|
|
|
|
std::size_t operator()(const OverlapKey& k) const
|
|
|
|
|
{
|
|
|
|
|
size_t seed = 0;
|
|
|
|
|
hash_combine(seed, k.universe_id);
|
|
|
|
|
hash_combine(seed, k.cell1_id);
|
|
|
|
|
hash_combine(seed, k.cell2_id);
|
|
|
|
|
return seed;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-27 17:07:22 -04:00
|
|
|
//==============================================================================
|
|
|
|
|
// Global variables
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2018-11-08 13:41:23 -06:00
|
|
|
namespace model {
|
|
|
|
|
|
2019-03-18 12:26:53 -05:00
|
|
|
extern int root_universe; //!< Index of root universe
|
2020-09-02 15:41:03 -05:00
|
|
|
extern "C" int n_coord_levels; //!< Number of CSG coordinate levels
|
2018-07-06 06:36:05 -05:00
|
|
|
|
2021-04-22 16:46:23 -04:00
|
|
|
extern vector<int64_t> overlap_check_count;
|
2018-08-14 16:22:40 -04:00
|
|
|
|
2026-07-06 12:47:22 -05:00
|
|
|
// Overlap data structures get cleared every slice_data run
|
|
|
|
|
extern vector<OverlapKey> overlap_keys;
|
|
|
|
|
extern std::unordered_map<OverlapKey, int, OverlapKeyHash> overlap_key_index;
|
|
|
|
|
|
2018-11-08 13:41:23 -06:00
|
|
|
} // namespace model
|
|
|
|
|
|
2019-04-01 09:44:57 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
//! Check two distances by coincidence tolerance
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2019-04-03 13:51:35 -05:00
|
|
|
inline bool coincident(double d1, double d2)
|
|
|
|
|
{
|
|
|
|
|
return std::abs(d1 - d2) < FP_COINCIDENT;
|
|
|
|
|
}
|
2019-04-01 09:44:57 -05:00
|
|
|
|
2018-08-20 12:24:08 -04:00
|
|
|
//==============================================================================
|
2018-08-20 22:45:28 -04:00
|
|
|
//! Check for overlapping cells at a particle's position.
|
2018-08-20 12:24:08 -04:00
|
|
|
//==============================================================================
|
2026-07-06 12:47:22 -05:00
|
|
|
int check_cell_overlap(GeometryState& p, bool error = true);
|
2018-08-20 12:24:08 -04:00
|
|
|
|
2021-07-05 12:35:14 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
//! Get the cell instance for a particle at the specified universe level
|
|
|
|
|
//!
|
|
|
|
|
//! \param p A particle for which to compute the instance using
|
2021-08-02 16:39:10 -05:00
|
|
|
//! its coordinates
|
2021-07-05 12:35:14 -05:00
|
|
|
//! \param level The level (zero indexed) of the geometry where the instance
|
|
|
|
|
//! should be computed. \return The instance of the cell at the specified level.
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2024-01-16 10:35:57 -06:00
|
|
|
int cell_instance_at_level(const GeometryState& p, int level);
|
2021-07-05 12:35:14 -05:00
|
|
|
|
2018-08-20 12:24:08 -04:00
|
|
|
//==============================================================================
|
2018-08-20 22:45:28 -04:00
|
|
|
//! Locate a particle in the geometry tree and set its geometry data fields.
|
2018-08-27 17:07:22 -04:00
|
|
|
//!
|
|
|
|
|
//! \param p A particle to be located. This function will populate the
|
|
|
|
|
//! geometry-dependent data fields of the particle.
|
|
|
|
|
//! \return True if the particle's location could be found and ascribed to a
|
|
|
|
|
//! valid geometry coordinate stack.
|
2018-08-20 12:24:08 -04:00
|
|
|
//==============================================================================
|
2024-01-16 10:35:57 -06:00
|
|
|
bool exhaustive_find_cell(GeometryState& p, bool verbose = false);
|
|
|
|
|
bool neighbor_list_find_cell(
|
|
|
|
|
GeometryState& p, bool verbose = false); // Only usable on surface crossings
|
2018-08-20 12:24:08 -04:00
|
|
|
|
2018-08-20 22:45:28 -04:00
|
|
|
//==============================================================================
|
|
|
|
|
//! Move a particle into a new lattice tile.
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2024-01-16 10:35:57 -06:00
|
|
|
void cross_lattice(
|
|
|
|
|
GeometryState& p, const BoundaryInfo& boundary, bool verbose = false);
|
2018-08-20 22:45:28 -04:00
|
|
|
|
2018-08-21 11:02:14 -04:00
|
|
|
//==============================================================================
|
|
|
|
|
//! Find the next boundary a particle will intersect.
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2024-01-16 10:35:57 -06:00
|
|
|
BoundaryInfo distance_to_boundary(GeometryState& p);
|
2018-08-21 11:02:14 -04:00
|
|
|
|
2018-06-25 21:00:59 -05:00
|
|
|
} // namespace openmc
|
|
|
|
|
|
2018-08-08 13:36:42 -05:00
|
|
|
#endif // OPENMC_GEOMETRY_H
|