Adjust cell universe indices from C++

This commit is contained in:
Sterling Harper 2018-04-29 15:39:14 -04:00
parent a69baeaed5
commit 735c59650b
4 changed files with 30 additions and 17 deletions

View file

@ -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
//==============================================================================

View file

@ -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.

View file

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

View file

@ -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)