Remove Universe type from Fortran

This commit is contained in:
Sterling Harper 2018-08-21 12:10:01 -04:00
parent 8bb17a481e
commit 7b31853066
9 changed files with 66 additions and 66 deletions

View file

@ -182,6 +182,28 @@ generate_rpn(int32_t cell_id, std::vector<int32_t> infix)
return rpn;
}
//==============================================================================
// Universe implementation
//==============================================================================
void
Universe::to_hdf5(hid_t universes_group) const
{
// Create a group for this universe.
std::stringstream group_name;
group_name << "universe " << id;
auto group = create_group(universes_group, group_name);
// Write the contained cells.
if (cells.size() > 0) {
std::vector<int32_t> cell_ids;
for (auto i_cell : cells) cell_ids.push_back(global_cells[i_cell]->id);
write_dataset(group, "cells", cell_ids);
}
close_group(group);
}
//==============================================================================
// Cell implementation
//==============================================================================
@ -704,6 +726,11 @@ extern "C" {
}
n_cells = global_cells.size();
}
int32_t universe_id(int i_univ) {return global_universes[i_univ]->id;}
void universes_to_hdf5(hid_t universes_group)
{for (Universe* u : global_universes) u->to_hdf5(universes_group);}
}

View file

@ -55,7 +55,10 @@ class Universe
public:
int32_t id; //!< Unique ID
std::vector<int32_t> cells; //!< Cells within this universe
//double x0, y0, z0; //!< Translation coordinates.
//! \brief Write universe information to an HDF5 group.
//! \param group_id An HDF5 group id.
void to_hdf5(hid_t group_id) const;
};
//==============================================================================

View file

@ -16,6 +16,12 @@ module geometry_header
implicit none
interface
function universe_id(universe_ind) bind(C) result(id)
import C_INT, C_INT32_T
integer(C_INT), intent(in), value :: universe_ind
integer(C_INT32_T) :: id
end function universe_id
function cell_pointer(cell_ind) bind(C) result(ptr)
import C_PTR, C_INT32_T
integer(C_INT32_T), intent(in), value :: cell_ind
@ -177,15 +183,6 @@ module geometry_header
end subroutine extend_cells_c
end interface
!===============================================================================
! UNIVERSE defines a geometry that fills all phase space
!===============================================================================
type Universe
integer :: id ! Unique ID
integer, allocatable :: cells(:) ! List of cells within
end type Universe
!===============================================================================
! LATTICE abstract type for ordered array of universes.
!===============================================================================
@ -260,7 +257,6 @@ module geometry_header
integer(C_INT32_T), bind(C) :: n_universes ! # of universes
type(Cell), allocatable, target :: cells(:)
type(Universe), allocatable, target :: universes(:)
type(LatticeContainer), allocatable, target :: lattices(:)
! Dictionaries which map user IDs to indices in the global arrays
@ -483,7 +479,6 @@ contains
n_universes = 0
if (allocated(cells)) deallocate(cells)
if (allocated(universes)) deallocate(universes)
if (allocated(lattices)) deallocate(lattices)
call cell_dict % clear()

View file

@ -36,7 +36,13 @@ bool using_mpio_device(hid_t obj_id);
//==============================================================================
hid_t create_group(hid_t parent_id, const std::string& name);
inline hid_t create_group(hid_t parent_id, const std::stringstream& name)
{return create_group(parent_id, name.str());}
hid_t file_open(const std::string& filename, char mode, bool parallel=false);
void write_string(hid_t group_id, const char* name, const std::string& buffer,
bool indep);
@ -314,6 +320,13 @@ write_dataset(hid_t obj_id, const char* name, const std::array<T, N>& buffer)
write_dataset(obj_id, 1, dims, name, H5TypeMap<T>::type_id, buffer.data(), false);
}
template<typename T> inline void
write_dataset(hid_t obj_id, const char* name, const std::vector<T>& buffer)
{
hsize_t dims[] {buffer.size()};
write_dataset(obj_id, 1, dims, name, H5TypeMap<T>::type_id, buffer.data(), false);
}
inline void
write_dataset(hid_t obj_id, const char* name, Position r)
{

View file

@ -1002,7 +1002,7 @@ contains
subroutine read_geometry_xml()
integer :: i, j
integer :: i
integer :: n, n_rlats, n_hlats
integer :: univ_id
integer :: n_cells_in_univ
@ -1205,30 +1205,8 @@ contains
! SETUP UNIVERSES
! Allocate universes, universe cell arrays, and assign base universe
allocate(universes(n_universes))
do i = 1, n_universes
associate (u => universes(i))
u % id = univ_ids % data(i)
! Allocate cell list
n_cells_in_univ = cells_in_univ_dict % get(u % id)
allocate(u % cells(n_cells_in_univ))
u % cells(:) = 0
end associate
end do
root_universe = find_root_universe() + 1
do i = 1, n_cells
! Get index in universes array
j = universe_dict % get(cells(i) % universe())
! Set the first zero entry in the universe cells array to the index in the
! global cells array
associate (u => universes(j))
u % cells(find(u % cells, 0)) = i
end associate
end do
! Clear dictionary
call cells_in_univ_dict%clear()

View file

@ -211,7 +211,6 @@ contains
integer :: i ! index for coordinate levels
type(Cell), pointer :: c
type(Universe), pointer :: u
class(Lattice), pointer :: l
! display type of particle
@ -239,8 +238,8 @@ contains
! Print universe for this level
if (p % coord(i) % universe /= NONE) then
u => universes(p % coord(i) % universe)
write(ou,*) ' Universe = ' // trim(to_str(u % id))
write(ou,*) ' Universe = ' &
// trim(to_str(universe_id(p % coord(i) % universe-1)))
end if
! Print information on lattice

View file

@ -163,16 +163,22 @@ contains
integer :: i, j, cell_fill
integer, allocatable :: cell_materials(:)
integer, allocatable :: cell_ids(:)
real(8), allocatable :: cell_temperatures(:)
integer(HID_T) :: geom_group
integer(HID_T) :: cells_group, cell_group
integer(HID_T) :: surfaces_group
integer(HID_T) :: universes_group, univ_group
integer(HID_T) :: universes_group
integer(HID_T) :: lattices_group
type(Cell), pointer :: c
class(Lattice), pointer :: lat
interface
subroutine universes_to_hdf5(universes_group) bind(C)
import HID_T
integer(HID_T), intent(in), value :: universes_group
end subroutine universes_to_hdf5
end interface
! Use H5LT interface to write number of geometry objects
geom_group = create_group(file_id, "geometry")
call write_attribute(geom_group, "n_cells", n_cells)
@ -254,29 +260,8 @@ contains
! ==========================================================================
! WRITE INFORMATION ON UNIVERSES
! Create universes group (nothing directly written here) then close
universes_group = create_group(geom_group, "universes")
! Write information on each universe
UNIVERSE_LOOP: do i = 1, n_universes
associate (u => universes(i))
univ_group = create_group(universes_group, "universe " // &
trim(to_str(u%id)))
! Write list of cells in this universe
if (size(u % cells) > 0) then
allocate(cell_ids(size(u % cells)))
do j = 1, size(u % cells)
cell_ids(j) = cells(u % cells(j)) % id()
end do
call write_dataset(univ_group, "cells", cell_ids)
deallocate(cell_ids)
end if
call close_group(univ_group)
end associate
end do UNIVERSE_LOOP
call universes_to_hdf5(universes_group)
call close_group(universes_group)
! ==========================================================================

View file

@ -78,7 +78,7 @@ contains
allocate(universe_ids(size(this % universes)))
do i = 1, size(this % universes)
universe_ids(i) = universes(this % universes(i)) % id
universe_ids(i) = universe_id(this % universes(i)-1)
end do
call write_dataset(filter_group, "bins", universe_ids)
end subroutine to_statepoint_universe
@ -112,7 +112,7 @@ contains
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
label = "Universe " // to_str(universes(this % universes(bin)) % id)
label = "Universe " // to_str(universe_id(this % universes(bin)-1))
end function text_label_universe
end module tally_filter_universe

View file

@ -9,7 +9,7 @@ module volume_calc
use constants
use error, only: write_message
use geometry, only: find_cell
use geometry_header, only: universes, cells
use geometry_header, only: cells, universe_id
use hdf5_interface, only: file_open, file_close, write_attribute, &
create_group, close_group, write_dataset, HID_T
use output, only: header, time_stamp
@ -216,7 +216,7 @@ contains
elseif (this % domain_type == FILTER_UNIVERSE) then
do level = 1, p % n_coord
do i_domain = 1, size(this % domain_id)
if (universes(p % coord(level) % universe) % id == &
if (universe_id(p % coord(level) % universe - 1) == &
this % domain_id(i_domain)) then
i_material = p % material
call check_hit(i_domain, i_material, indices, hits, n_mat)