From 108c2a2f35c846c32f3d29afd28d42e77f85d53e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Jul 2020 18:26:21 -0500 Subject: [PATCH] Adding surface and cell offsets to the DAGUniverse to recover surface and cell indices. --- include/openmc/cell.h | 3 +++ src/cell.cpp | 7 ++++++- src/dagmc.cpp | 6 ++++-- src/particle.cpp | 36 ++++++++++++++++++------------------ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 0aa14e523..f87e594ea 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -63,6 +63,7 @@ namespace model { class Universe { public: + int32_t id_; //!< Unique ID vector cells_; //!< Cells within this universe @@ -88,6 +89,8 @@ public: // Data Members std::string filename_; std::shared_ptr dagmc_instance_; //! DAGMC Instance for this universe + int32_t cell_idx_offset_; + int32_t surf_idx_offset_; }; #endif diff --git a/src/cell.cpp b/src/cell.cpp index ffbb7dae7..3fb2050d1 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -793,6 +793,11 @@ DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) cons p->last_dir() = u; } + const auto& univ = model::universes[p->coord_[p->n_coord_ - 1].universe]; + + DAGUniverse* dag_univ = static_cast(univ.get()); + if (!dag_univ) fatal_error("DAGMC call made for particle in a non-DAGMC universe"); + moab::ErrorCode rval; moab::EntityHandle vol = dagmc_ptr_->entity_by_index(3, dag_index_); moab::EntityHandle hit_surf; @@ -803,7 +808,7 @@ DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) cons MB_CHK_ERR_CONT(rval); int surf_idx; if (hit_surf != 0) { - surf_idx = dagmc_ptr_->index_by_handle(hit_surf); + surf_idx = dag_univ->surf_idx_offset_ + dagmc_ptr_->index_by_handle(hit_surf); } else { // indicate that particle is lost surf_idx = -1; diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 93d9b222a..f79215c11 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -171,7 +171,7 @@ DAGUniverse::DAGUniverse(pugi::xml_node node) { initialize(); } -DAGUniverse::DAGUniverse(const std::string& filename) : filename_(filename) { +DAGUniverse::DAGUniverse(const std::string& filename): filename_(filename) { // determine the next universe id int32_t next_univ_id = 0; for (const auto& u : model::universes) { @@ -192,6 +192,7 @@ void DAGUniverse::initialize() { for (const auto& c : model::cells) { if (c->id_ > next_cell_id) next_cell_id = c->id_; } + cell_idx_offset_ = model::cells.size(); next_cell_id++; // determine the next surface id @@ -199,6 +200,7 @@ void DAGUniverse::initialize() { for (const auto& s : model::surfaces) { if (s->id_ > next_surf_id) next_surf_id = s->id_; } + surf_idx_offset_ = model::surfaces.size(); next_surf_id++; // create a new DAGMC instance @@ -367,7 +369,7 @@ void DAGUniverse::initialize() { // add to global array and map model::surfaces.emplace_back(s); -// model::surface_map[s->id_] = model::surfaces.size() - 1; + model::surface_map[s->id_] = model::surfaces.size() - 1; } } diff --git a/src/particle.cpp b/src/particle.cpp index fe2579593..755330808 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -386,24 +386,24 @@ Particle::cross_surface() // ========================================================================== // SEARCH NEIGHBOR LISTS FOR NEXT CELL -#ifdef DAGMC - if (settings::dagmc) { - auto cellp = dynamic_cast(model::cells[cell_last(0)].get()); - // TODO: off-by-one - auto surfp = - dynamic_cast(model::surfaces[std::abs(surface()) - 1].get()); - int32_t i_cell = next_cell(cellp, surfp) - 1; - // save material and temp - material_last() = material(); - sqrtkT_last() = sqrtkT(); - // set new cell value - coord(0).cell = i_cell; - cell_instance() = 0; - material() = model::cells[i_cell]->material_[0]; - sqrtkT() = model::cells[i_cell]->sqrtkT_[0]; - return; - } -#endif + +// #ifdef DAGMC +// if (settings::dagmc) { +// auto cellp = dynamic_cast(model::cells[cell_last_[0]].get()); +// // TODO: off-by-one +// auto surfp = dynamic_cast(model::surfaces[std::abs(surface_) - 1].get()); +// int32_t i_cell = next_cell(cellp, surfp) - 1; +// // save material and temp +// material_last_ = material_; +// sqrtkT_last_ = sqrtkT_; +// // set new cell value +// coord_[0].cell = i_cell; +// cell_instance_ = 0; +// material_ = model::cells[i_cell]->material_[0]; +// sqrtkT_ = model::cells[i_cell]->sqrtkT_[0]; +// return; +// } +// #endif if (neighbor_list_find_cell(*this)) return;