Move Cell % universe to C++

This commit is contained in:
Sterling Harper 2018-02-03 21:19:46 -05:00
parent 42df6d37a6
commit 3b5c8495e1
7 changed files with 108 additions and 45 deletions

View file

@ -1,6 +1,7 @@
#include "cell.h"
#include <sstream>
#include <string>
#include "error.h"
#include "hdf5_interface.h"
@ -28,40 +29,31 @@ Cell::Cell(pugi::xml_node cell_node)
if (check_for_node(cell_node, "name")) {
name = get_node_value(cell_node, "name");
}
if (check_for_node(cell_node, "universe")) {
universe = stoi(get_node_value(cell_node, "universe"));
} else {
universe = 0;
}
}
void
Cell::to_hdf5(hid_t group_id) const
//Cell::to_hdf5(hid_t group_id) const
Cell::to_hdf5(hid_t cell_group) const
{
/*
std::string group_name {"surface "};
group_name += std::to_string(id);
hid_t surf_group = create_group(group_id, group_name);
switch(bc) {
case BC_TRANSMIT :
write_string(surf_group, "boundary_type", "transmission");
break;
case BC_VACUUM :
write_string(surf_group, "boundary_type", "vacuum");
break;
case BC_REFLECT :
write_string(surf_group, "boundary_type", "reflective");
break;
case BC_PERIODIC :
write_string(surf_group, "boundary_type", "periodic");
break;
}
// std::string group_name {"surface "};
// group_name += std::to_string(id);
//
// hid_t surf_group = create_group(group_id, group_name);
if (!name.empty()) {
write_string(surf_group, "name", name);
write_string(cell_group, "name", name);
}
to_hdf5_inner(surf_group);
//TODO: Lookup universe id in universe_dict
//write_int(cell_group, "universe", universe);
close_group(surf_group);
*/
// close_group(cell_group);
}
//==============================================================================

View file

@ -38,6 +38,7 @@ class Cell
public:
int32_t id; //!< Unique ID
std::string name{""}; //!< User-defined name
int32_t universe; //!< Universe # this cell is in
explicit Cell(pugi::xml_node cell_node);
@ -58,6 +59,13 @@ extern "C" int32_t cell_id(Cell *c) {return c->id;}
extern "C" void cell_set_id(Cell *c, int32_t id) {c->id = id;}
extern "C" int32_t cell_universe(Cell *c) {return c->universe;}
extern "C" void cell_set_universe(Cell *c, int32_t universe)
{c->universe = universe;}
extern "C" void cell_to_hdf5(Cell *c, hid_t group) {c->to_hdf5(group);}
//extern "C" void free_memory_cells_c()
//{
// delete cells_c;

View file

@ -223,7 +223,7 @@ contains
if (use_search_cells) then
i_cell = search_cells(i)
! check to make sure search cell is in same universe
if (cells(i_cell) % universe /= i_universe) cycle
if (cells(i_cell) % universe() /= i_universe) cycle
else
i_cell = universes(i_universe) % cells(i)
end if

View file

@ -1,6 +1,7 @@
module geometry_header
use, intrinsic :: ISO_C_BINDING
use hdf5
use algorithm, only: find
use constants, only: HALF, TWO, THREE, INFINITY, K_BOLTZMANN, &
@ -35,6 +36,30 @@ module geometry_header
type(C_PTR), intent(in), value :: cell_ptr
integer(C_INT32_T), intent(in), value :: id
end subroutine cell_set_id_c
function cell_universe_c(cell_ptr) bind(C, name='cell_universe') &
result(universe)
use ISO_C_BINDING
implicit none
type(C_PTR), intent(in), value :: cell_ptr
integer(C_INT32_T) :: universe
end function cell_universe_c
subroutine cell_set_universe_c(cell_ptr, universe) &
bind(C, name='cell_set_universe')
use ISO_C_BINDING
implicit none
type(C_PTR), intent(in), value :: cell_ptr
integer(C_INT32_T), intent(in), value :: universe
end subroutine cell_set_universe_c
subroutine cell_to_hdf5_c(cell_ptr, group) bind(C, name='cell_to_hdf5')
use ISO_C_BINDING
use hdf5
implicit none
type(C_PTR), intent(in), value :: cell_ptr
integer(HID_T), intent(in), value :: group
end subroutine cell_to_hdf5_c
end interface
!===============================================================================
@ -150,10 +175,8 @@ module geometry_header
type Cell
type(C_PTR) :: ptr
character(len=104) :: name = "" ! User-defined name
integer :: type ! Type of cell (normal, universe,
! lattice)
integer :: universe ! universe # this cell is in
integer :: fill ! universe # filling this cell
integer :: instances ! number of instances of this cell in
! the geom
@ -183,6 +206,9 @@ module geometry_header
procedure :: id => cell_id
procedure :: set_id => cell_set_id
procedure :: universe => cell_universe
procedure :: set_universe => cell_set_universe
procedure :: to_hdf5 => cell_to_hdf5
end type Cell
@ -385,6 +411,24 @@ contains
call cell_set_id_c(this % ptr, id)
end subroutine cell_set_id
function cell_universe(this) result(universe)
class(Cell), intent(in) :: this
integer(C_INT32_T) :: universe
universe = cell_universe_c(this % ptr)
end function cell_universe
subroutine cell_set_universe(this, universe)
class(Cell), intent(in) :: this
integer(C_INT32_T), intent(in) :: universe
call cell_set_universe_c(this % ptr, universe)
end subroutine cell_set_universe
subroutine cell_to_hdf5(this, group)
class(Cell), intent(in) :: this
integer(HID_T), intent(in) :: group
call cell_to_hdf5_c(this % ptr, group)
end subroutine cell_to_hdf5
!===============================================================================
! GET_TEMPERATURES returns a list of temperatures that each nuclide/S(a,b) table
! appears at in the model. Later, this list is used to determine the actual

View file

@ -43,6 +43,36 @@ close_group(hid_t group_id)
}
inline void
write_int(hid_t group_id, char const *name, int32_t buffer)
{
hid_t dataspace = H5Screate(H5S_SCALAR);
hid_t dataset = H5Dcreate(group_id, name, H5T_NATIVE_INT32, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset, H5T_NATIVE_INT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
H5Sclose(dataspace);
H5Dclose(dataset);
}
//inline void
//write_double(hid_t group_id, char const *name, double buffer)
//{
// hid_t dataspace = H5Screate(H5S_SCALAR);
//
// hid_t dataset = H5Dcreate(group_id, name, H5T_NATIVE_DOUBLE, dataspace,
// H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//
// H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
//
// H5Sclose(dataspace);
// H5Dclose(dataset);
//}
template<std::size_t array_len> inline void
write_double_1D(hid_t group_id, char const *name,
std::array<double, array_len> &buffer)

View file

@ -1029,16 +1029,6 @@ contains
! Get pointer to i-th cell node
node_cell = node_cell_list(i)
! Copy cell name
if (check_for_node(node_cell, "name")) then
call get_node_value(node_cell, "name", c % name)
end if
if (check_for_node(node_cell, "universe")) then
call get_node_value(node_cell, "universe", c % universe)
else
c % universe = 0
end if
if (check_for_node(node_cell, "fill")) then
call get_node_value(node_cell, "fill", c % fill)
if (find(fill_univ_ids, c % fill) == -1) &
@ -1249,7 +1239,7 @@ contains
! For cells, we also need to check if there's a new universe --
! also for every cell add 1 to the count of cells for the
! specified universe
univ_id = c % universe
univ_id = c % universe()
if (.not. cells_in_univ_dict % has(univ_id)) then
n_universes = n_universes + 1
n_cells_in_univ = 1
@ -1623,7 +1613,7 @@ contains
do i = 1, n_cells
! Get index in universes array
j = universe_dict % get(cells(i) % universe)
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
@ -4406,9 +4396,9 @@ contains
! ADJUST UNIVERSE INDEX FOR EACH CELL
associate (c => cells(i))
id = c % universe
id = c % universe()
if (universe_dict % has(id)) then
c % universe = universe_dict % get(id)
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())))

View file

@ -147,11 +147,10 @@ contains
c => cells(i)
cell_group = create_group(cells_group, "cell " // trim(to_str(c%id())))
! Write name for this cell
call write_dataset(cell_group, "name", c%name)
call c % to_hdf5(cell_group)
! Write universe for this cell
call write_dataset(cell_group, "universe", universes(c%universe)%id)
call write_dataset(cell_group, "universe", universes(c%universe())%id)
! Write information on what fills this cell
select case (c%type)