From 73b9727f1ef44925e902ca722c9f75c307de1423 Mon Sep 17 00:00:00 2001 From: eckertben Date: Mon, 8 Jun 2026 12:13:49 -0500 Subject: [PATCH] User option on collision cap & minor debugging --- include/openmc/dagmc.h | 10 ++++++++-- src/dagmc.cpp | 21 +++++++++++++-------- src/geometry.cpp | 2 +- src/particle.cpp | 8 +++++++- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 805960253..75987ea5d 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -106,13 +106,15 @@ public: //! \param[in] auto_geom_ids Whether or not to automatically assign cell and //! surface IDs \param[in] auto_mat_ids Whether or not to automatically assign //! material IDs + //! \param[in] use_collision_distance_cap Whether or not to cap the distance to + //! boundaries to the collision distance when finding the next boundary explicit DAGUniverse(const std::string& filename, bool auto_geom_ids = false, - bool auto_mat_ids = false); + bool auto_mat_ids = false, bool use_collision_distance_cap = false); //! Alternative DAGMC universe constructor for external DAGMC instance explicit DAGUniverse(std::shared_ptr external_dagmc_ptr, const std::string& filename = "", bool auto_geom_ids = false, - bool auto_mat_ids = false); + bool auto_mat_ids = false, bool use_collision_distance_cap = false); //! Initialize the DAGMC accel. data structures, indices, material //! assignments, etc. @@ -191,6 +193,7 @@ public: // Accessors moab::DagMC* dagmc_ptr() const { return dagmc_instance_.get(); } bool has_graveyard() const { return has_graveyard_; } + bool use_collision_distance_cap() const { return use_collision_distance_cap_; } private: void set_id(); //!< Deduce the universe id from model::universes @@ -212,6 +215,9 @@ private: //!< generate new material IDs for the universe bool has_graveyard_; //!< Indicates if the DAGMC geometry has a "graveyard" //!< volume + bool use_collision_distance_cap_; //!< Indicates whether or not to cap the + //!< distance to boundaries to the collision + //!< distance when finding the next boundary }; //============================================================================== diff --git a/src/dagmc.cpp b/src/dagmc.cpp index fb0847114..996907fbd 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -80,6 +80,11 @@ DAGUniverse::DAGUniverse(pugi::xml_node node) adjust_material_ids_ = get_node_value_bool(node, "auto_mat_ids"); } + use_collision_distance_cap_ = false; + if (check_for_node(node, "use_collision_distance_cap")) { + use_collision_distance_cap_ = get_node_value_bool(node, "use_collision_distance_cap"); + } + // Get material assignment overrides from nested DAGMC cell elements. if (node.child("cell")) { for (pugi::xml_node cell_node : node.children("cell")) { @@ -154,18 +159,18 @@ DAGUniverse::DAGUniverse(pugi::xml_node node) } DAGUniverse::DAGUniverse( - const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) + const std::string& filename, bool auto_geom_ids, bool auto_mat_ids, bool use_collision_distance_cap) : filename_(filename), adjust_geometry_ids_(auto_geom_ids), - adjust_material_ids_(auto_mat_ids) + adjust_material_ids_(auto_mat_ids), use_collision_distance_cap_(use_collision_distance_cap) { set_id(); initialize(); } DAGUniverse::DAGUniverse(std::shared_ptr dagmc_ptr, - const std::string& filename, bool auto_geom_ids, bool auto_mat_ids) + const std::string& filename, bool auto_geom_ids, bool auto_mat_ids, bool use_collision_distance_cap) : dagmc_instance_(dagmc_ptr), filename_(filename), - adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids) + adjust_geometry_ids_(auto_geom_ids), adjust_material_ids_(auto_mat_ids), use_collision_distance_cap_(use_collision_distance_cap) { MaterialOverrides material_overrides; TemperatureOverrides temperature_overrides; @@ -829,7 +834,7 @@ std::pair DAGCell::distance(Position r, Direction u, // surface idx of 1 and distance of infinity occur when no previous collisions // recorded int surf_idx = -1; - double dist = max_distance; + double dist = INFTY; moab::EntityHandle vol = dagmc_ptr_->entity_by_index(3, dag_index_); moab::EntityHandle hit_surf; @@ -838,12 +843,12 @@ std::pair DAGCell::distance(Position r, Direction u, double pnt[3] = {r.x, r.y, r.z}; double dir[3] = {u.x, u.y, u.z}; MB_CHK_ERR_CONT( - dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist, &p->history())); + dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist, &p->history(), max_distance)); if (hit_surf != 0) { surf_idx = dag_univ->surf_idx_offset_ + dagmc_ptr_->index_by_handle(hit_surf); - } else if (dist == INFTY && !dagmc_ptr_->is_implicit_complement(vol) || - is_root_universe(dag_univ->id_)) { + } else if (max_distance == INFTY && (!dagmc_ptr_->is_implicit_complement(vol) || + is_root_universe(dag_univ->id_))) { // surface boundary conditions are ignored for projection plotting, meaning // that the particle may move through the graveyard (bounding) volume and // into the implicit complement on the other side where no intersection will diff --git a/src/geometry.cpp b/src/geometry.cpp index 785b1809f..8330e1298 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -374,7 +374,7 @@ BoundaryInfo distance_to_boundary(GeometryState& p, double max_distance) Cell& c {*model::cells[coord.cell()]}; // Find the oncoming surface in this cell and the distance to it. - auto surface_distance = c.distance(r, u, p.surface(), &p); + auto surface_distance = c.distance(r, u, p.surface(), &p, max_distance); d_surf = surface_distance.first; level_surf_cross = surface_distance.second; diff --git a/src/particle.cpp b/src/particle.cpp index 4a43a85d2..0b20469ad 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -284,7 +284,13 @@ void Particle::event_advance() // Find distance to nearest boundary; // cap bvh traversal distance to collision distance - double max_distance = std::min(collision_distance(), distance_cutoff); + double max_distance = INFTY; + const auto& univ = model::universes[lowest_coord().universe()]; + if (auto* dag_univ = dynamic_cast(univ.get())) { + if (dag_univ->use_collision_distance_cap()) { + max_distance = std::min(collision_distance(), distance_cutoff); + } + } boundary() = distance_to_boundary(*this, max_distance); // Select smaller of the three distances