Adding surface and cell offsets to the DAGUniverse to recover surface and cell indices.

This commit is contained in:
Patrick Shriwise 2020-07-09 18:26:21 -05:00
parent a736756d9b
commit 108c2a2f35
4 changed files with 31 additions and 21 deletions

View file

@ -63,6 +63,7 @@ namespace model {
class Universe
{
public:
int32_t id_; //!< Unique ID
vector<int32_t> cells_; //!< Cells within this universe
@ -88,6 +89,8 @@ public:
// Data Members
std::string filename_;
std::shared_ptr<moab::DagMC> dagmc_instance_; //! DAGMC Instance for this universe
int32_t cell_idx_offset_;
int32_t surf_idx_offset_;
};
#endif

View file

@ -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<DAGUniverse*>(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;

View file

@ -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;
}
}

View file

@ -386,24 +386,24 @@ Particle::cross_surface()
// ==========================================================================
// SEARCH NEIGHBOR LISTS FOR NEXT CELL
#ifdef DAGMC
if (settings::dagmc) {
auto cellp = dynamic_cast<DAGCell*>(model::cells[cell_last(0)].get());
// TODO: off-by-one
auto surfp =
dynamic_cast<DAGSurface*>(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<DAGCell*>(model::cells[cell_last_[0]].get());
// // TODO: off-by-one
// auto surfp = dynamic_cast<DAGSurface*>(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;