diff --git a/src/cell.cpp b/src/cell.cpp index 136f36e06c..ed16a566a3 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -294,8 +294,8 @@ Cell::to_hdf5(hid_t cell_group) const write_string(cell_group, "name", name); } - //TODO: Lookup universe id in universe_dict - //write_int(cell_group, "universe", universe); + //TODO: Fix the off-by-one indexing. + write_int(cell_group, "universe", universes_c[universe-1]->id); // Write the region specification. if (!region.empty()) { @@ -428,6 +428,24 @@ read_cells(pugi::xml_node *node) } } +extern "C" void +adjust_indices_c() +{ + // Change cell.universe values from IDs to indices. + for (Cell *c : cells_c) { + auto it = universe_dict.find(c->universe); + if (it != universe_dict.end()) { + //TODO: Remove this off-by-one indexing. + c->universe = it->second + 1; + } else { + std::stringstream err_msg; + err_msg << "Could not find universe " << c->universe + << " specified on cell " << c->id; + fatal_error(err_msg); + } + } +} + //============================================================================== // Fortran compatibility functions //============================================================================== diff --git a/src/cell.h b/src/cell.h index 8b540be35a..99ca2caf4a 100644 --- a/src/cell.h +++ b/src/cell.h @@ -73,7 +73,8 @@ public: //! Simple cells can be evaluated with short circuit evaluation, i.e., as soon //! as we know that one half-space is not satisfied, we can exit. This //! provides a performance benefit for the common case. In - //! contains_complex, we evaluate the RPN expression using a stack, similar to //! how a RPN calculator would work. + //! contains_complex, we evaluate the RPN expression using a stack, similar to + //! how a RPN calculator would work. //! @param xyz[3] The 3D Cartesian coordinate to check. //! @param uvw[3] A direction used to "break ties" the coordinates are very //! close to a surface. diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 78dd0bb877..6457f587cc 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -49,6 +49,11 @@ module input_xml save interface + subroutine adjust_indices_c() bind(C) + use ISO_C_BINDING + implicit none + end subroutine adjust_indices_c + subroutine read_surfaces(node_ptr) bind(C) use ISO_C_BINDING implicit none @@ -4263,18 +4268,10 @@ contains integer :: id ! user-specified id class(Lattice), pointer :: lat => null() - do i = 1, n_cells - ! ======================================================================= - ! ADJUST UNIVERSE INDEX FOR EACH CELL - associate (c => cells(i)) + call adjust_indices_c() - id = c % universe() - if (universe_dict % has(id)) then - call c % set_universe(universe_dict % get(id)) - else - call fatal_error("Could not find universe " // trim(to_str(id)) & - &// " specified on cell " // trim(to_str(c % id()))) - end if + do i = 1, n_cells + associate (c => cells(i)) ! ======================================================================= ! ADJUST MATERIAL/FILL POINTERS FOR EACH CELL diff --git a/src/summary.F90 b/src/summary.F90 index 59bb904475..e2ef1a2c14 100644 --- a/src/summary.F90 +++ b/src/summary.F90 @@ -148,9 +148,6 @@ contains call c % to_hdf5(cell_group) - ! Write universe for this cell - call write_dataset(cell_group, "universe", universes(c%universe())%id) - ! Write information on what fills this cell select case (c%type) case (FILL_MATERIAL)