mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Move lattice outer to C++
This commit is contained in:
parent
42e1148fa6
commit
1dfa82530d
5 changed files with 98 additions and 72 deletions
|
|
@ -258,14 +258,14 @@ contains
|
|||
|
||||
else
|
||||
! Particle is outside the lattice.
|
||||
if (lat % outer == NO_OUTER_UNIVERSE) then
|
||||
if (lat % outer() == NO_OUTER_UNIVERSE) then
|
||||
call warning("Particle " // trim(to_str(p %id)) &
|
||||
// " is outside lattice " // trim(to_str(lat % id())) &
|
||||
// " but the lattice has no defined outer universe.")
|
||||
found = .false.
|
||||
return
|
||||
else
|
||||
p % coord(j + 1) % universe = lat % outer
|
||||
p % coord(j + 1) % universe = lat % outer() + 1
|
||||
end if
|
||||
end if
|
||||
end associate
|
||||
|
|
|
|||
|
|
@ -141,11 +141,12 @@ module geometry_header
|
|||
integer(HID_T), intent(in), value :: group
|
||||
end subroutine lattice_to_hdf5_c
|
||||
|
||||
subroutine extend_cells_c(n) bind(C)
|
||||
import C_INT32_t
|
||||
implicit none
|
||||
integer(C_INT32_T), intent(in), value :: n
|
||||
end subroutine extend_cells_c
|
||||
function lattice_outer_c(lat_ptr) bind(C, name='lattice_outer') &
|
||||
result(outer)
|
||||
import C_PTR, C_INT32_T
|
||||
type(C_PTR), intent(in), value :: lat_ptr
|
||||
integer(C_INT32_T) :: outer
|
||||
end function lattice_outer_c
|
||||
|
||||
function lattice_universe_c(lat_ptr, i_xyz) &
|
||||
bind(C, name='lattice_universe') result(univ)
|
||||
|
|
@ -155,6 +156,12 @@ module geometry_header
|
|||
integer(C_INT), intent(in) :: i_xyz(3)
|
||||
integer(C_INT32_T) :: univ
|
||||
end function lattice_universe_c
|
||||
|
||||
subroutine extend_cells_c(n) bind(C)
|
||||
import C_INT32_t
|
||||
implicit none
|
||||
integer(C_INT32_T), intent(in), value :: n
|
||||
end subroutine extend_cells_c
|
||||
end interface
|
||||
|
||||
!===============================================================================
|
||||
|
|
@ -177,8 +184,6 @@ module geometry_header
|
|||
type, abstract :: Lattice
|
||||
type(C_PTR) :: ptr
|
||||
|
||||
integer :: outside ! Material to fill area outside
|
||||
integer :: outer ! universe to tile outside the lat
|
||||
logical :: is_3d ! Lattice has cells on z axis
|
||||
integer, allocatable :: offset(:,:,:,:) ! Distribcell offsets
|
||||
contains
|
||||
|
|
@ -189,6 +194,7 @@ module geometry_header
|
|||
procedure :: get => lattice_get
|
||||
procedure :: get_indices => lattice_get_indices
|
||||
procedure :: get_local_xyz => lattice_get_local_xyz
|
||||
procedure :: outer => lattice_outer
|
||||
procedure :: to_hdf5 => lattice_to_hdf5
|
||||
end type Lattice
|
||||
|
||||
|
|
@ -323,6 +329,12 @@ contains
|
|||
call lattice_get_local_xyz_c(this % ptr, global_xyz, i_xyz, local_xyz)
|
||||
end function lattice_get_local_xyz
|
||||
|
||||
function lattice_outer(this) result(outer)
|
||||
class(Lattice), intent(in) :: this
|
||||
integer(C_INT32_T) :: outer
|
||||
outer = lattice_outer_c(this % ptr)
|
||||
end function lattice_outer
|
||||
|
||||
subroutine lattice_to_hdf5(this, group)
|
||||
class(Lattice), intent(in) :: this
|
||||
integer(HID_T), intent(in) :: group
|
||||
|
|
|
|||
|
|
@ -1315,19 +1315,10 @@ contains
|
|||
end do
|
||||
|
||||
! Read outer universe for area outside lattice.
|
||||
lat % outer = NO_OUTER_UNIVERSE
|
||||
if (check_for_node(node_lat, "outer")) then
|
||||
call get_node_value(node_lat, "outer", lat % outer)
|
||||
if (find(fill_univ_ids, lat % outer) == -1) &
|
||||
call fill_univ_ids % push_back(lat % outer)
|
||||
end if
|
||||
|
||||
! Check for 'outside' nodes which are no longer supported.
|
||||
if (check_for_node(node_lat, "outside")) then
|
||||
call fatal_error("The use of 'outside' in lattices is no longer &
|
||||
&supported. Instead, use 'outer' which defines a universe rather &
|
||||
&than a material. The utility openmc/src/utils/update_inputs.py &
|
||||
&can be used automatically replace 'outside' with 'outer'.")
|
||||
call get_node_value(node_lat, "outer", univ_id)
|
||||
if (find(fill_univ_ids, univ_id) == -1) &
|
||||
call fill_univ_ids % push_back(univ_id)
|
||||
end if
|
||||
|
||||
! Add lattice to dictionary
|
||||
|
|
@ -1379,19 +1370,10 @@ contains
|
|||
end do
|
||||
|
||||
! Read outer universe for area outside lattice.
|
||||
lat % outer = NO_OUTER_UNIVERSE
|
||||
if (check_for_node(node_lat, "outer")) then
|
||||
call get_node_value(node_lat, "outer", lat % outer)
|
||||
if (find(fill_univ_ids, lat % outer) == -1) &
|
||||
call fill_univ_ids % push_back(lat % outer)
|
||||
end if
|
||||
|
||||
! Check for 'outside' nodes which are no longer supported.
|
||||
if (check_for_node(node_lat, "outside")) then
|
||||
call fatal_error("The use of 'outside' in lattices is no longer &
|
||||
&supported. Instead, use 'outer' which defines a universe rather &
|
||||
&than a material. The utility openmc/src/utils/update_inputs.py &
|
||||
&can be used automatically replace 'outside' with 'outer'.")
|
||||
call get_node_value(node_lat, "outer", univ_id)
|
||||
if (find(fill_univ_ids, univ_id) == -1) &
|
||||
call fill_univ_ids % push_back(univ_id)
|
||||
end if
|
||||
|
||||
! Add lattice to dictionary
|
||||
|
|
@ -3875,7 +3857,6 @@ contains
|
|||
integer :: j ! index for various purposes
|
||||
integer :: lid ! lattice IDs
|
||||
integer :: id ! user-specified id
|
||||
class(Lattice), pointer :: lat => null()
|
||||
|
||||
call adjust_indices_c()
|
||||
|
||||
|
|
@ -3916,24 +3897,6 @@ contains
|
|||
end associate
|
||||
end do
|
||||
|
||||
! ==========================================================================
|
||||
! ADJUST UNIVERSE INDICES FOR EACH LATTICE
|
||||
|
||||
do i = 1, n_lattices
|
||||
lat => lattices(i) % obj
|
||||
|
||||
if (lat % outer /= NO_OUTER_UNIVERSE) then
|
||||
if (universe_dict % has(lat % outer)) then
|
||||
lat % outer = universe_dict % get(lat % outer)
|
||||
else
|
||||
call fatal_error("Invalid universe number " &
|
||||
&// trim(to_str(lat % outer)) &
|
||||
&// " specified on lattice " // trim(to_str(lat % id())))
|
||||
end if
|
||||
end if
|
||||
|
||||
end do
|
||||
|
||||
end subroutine adjust_indices
|
||||
|
||||
!===============================================================================
|
||||
|
|
|
|||
|
|
@ -50,13 +50,29 @@ Lattice::Lattice(pugi::xml_node lat_node)
|
|||
}
|
||||
|
||||
void
|
||||
Lattice::to_hdf5(hid_t lat_group) const
|
||||
Lattice::to_hdf5(hid_t lattices_group) const
|
||||
{
|
||||
// Make a group for the lattice.
|
||||
std::string group_name {"lattice "};
|
||||
group_name += std::to_string(id);
|
||||
hid_t lat_group = create_group(lattices_group, group_name);
|
||||
|
||||
// Write the name and outer universe.
|
||||
if (!name.empty()) {
|
||||
write_string(lat_group, "name", name, false);
|
||||
}
|
||||
|
||||
if (outer != NO_OUTER_UNIVERSE) {
|
||||
int32_t outer_id = universes_c[outer]->id;
|
||||
write_int(lat_group, 0, nullptr, "outer", &outer_id, false);
|
||||
} else {
|
||||
write_int(lat_group, 0, nullptr, "outer", &outer, false);
|
||||
}
|
||||
|
||||
// Call subclass-overriden function to fill in other details.
|
||||
to_hdf5_inner(lat_group);
|
||||
|
||||
close_group(lat_group);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -150,6 +166,7 @@ RectLattice::operator[](const int i_xyz[3])
|
|||
void
|
||||
RectLattice::adjust_indices()
|
||||
{
|
||||
// Adjust the indices for the universes array.
|
||||
int nx = n_cells[0];
|
||||
int ny = n_cells[1];
|
||||
int nz = n_cells[2];
|
||||
|
|
@ -157,10 +174,32 @@ RectLattice::adjust_indices()
|
|||
for (int iy = 0; iy < ny; iy++) {
|
||||
for (int ix = 0; ix < nx; ix++) {
|
||||
int indx = nx*ny*iz + nx*iy + ix;
|
||||
universes[indx] = universe_dict[universes[indx]];
|
||||
int uid = universes[indx];
|
||||
auto search = universe_dict.find(uid);
|
||||
if (search != universe_dict.end()) {
|
||||
universes[indx] = search->second;
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "Invalid universe number " << uid << " specified on "
|
||||
"lattice " << id;
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust the index for the outer universe.
|
||||
if (outer != NO_OUTER_UNIVERSE) {
|
||||
auto search = universe_dict.find(outer);
|
||||
if (search != universe_dict.end()) {
|
||||
outer = search->second;
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "Invalid universe number " << outer << " specified on "
|
||||
"lattice " << id;
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -493,6 +532,7 @@ HexLattice::operator[](const int i_xyz[3])
|
|||
void
|
||||
HexLattice::adjust_indices()
|
||||
{
|
||||
// Adjust the indices for the universes array.
|
||||
for (int iz = 0; iz < n_axial; iz++) {
|
||||
for (int ia = 0; ia < 2*n_rings-1; ia++) {
|
||||
for (int ix = 0; ix < 2*n_rings-1; ix++) {
|
||||
|
|
@ -501,11 +541,33 @@ HexLattice::adjust_indices()
|
|||
int indx = (2*n_rings-1)*(2*n_rings-1) * iz
|
||||
+ (2*n_rings-1) * ia
|
||||
+ ix;
|
||||
universes[indx] = universe_dict[universes[indx]];
|
||||
int uid = universes[indx];
|
||||
auto search = universe_dict.find(uid);
|
||||
if (search != universe_dict.end()) {
|
||||
universes[indx] = search->second;
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "Invalid universe number " << uid << " specified on "
|
||||
"lattice " << id;
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust the index for the outer universe.
|
||||
if (outer != NO_OUTER_UNIVERSE) {
|
||||
auto search = universe_dict.find(outer);
|
||||
if (search != universe_dict.end()) {
|
||||
outer = search->second;
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "Invalid universe number " << outer << " specified on "
|
||||
"lattice " << id;
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -824,6 +886,8 @@ extern "C" {
|
|||
local_xyz[2] = xyz[2];
|
||||
}
|
||||
|
||||
int32_t lattice_outer(Lattice *lat) {return lat->outer;}
|
||||
|
||||
void lattice_to_hdf5(Lattice *lat, hid_t group) {lat->to_hdf5(group);}
|
||||
|
||||
int32_t lattice_universe(Lattice *lat, const int i_xyz[3])
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ contains
|
|||
integer(HID_T) :: cells_group, cell_group
|
||||
integer(HID_T) :: surfaces_group
|
||||
integer(HID_T) :: universes_group, univ_group
|
||||
integer(HID_T) :: lattices_group, lattice_group
|
||||
integer(HID_T) :: lattices_group
|
||||
type(Cell), pointer :: c
|
||||
class(Lattice), pointer :: lat
|
||||
|
||||
|
|
@ -293,25 +293,12 @@ contains
|
|||
! ==========================================================================
|
||||
! WRITE INFORMATION ON LATTICES
|
||||
|
||||
! Create lattices group (nothing directly written here) then close
|
||||
lattices_group = create_group(geom_group, "lattices")
|
||||
|
||||
! Write information on each lattice
|
||||
LATTICE_LOOP: do i = 1, n_lattices
|
||||
do i = 1, n_lattices
|
||||
lat => lattices(i)%obj
|
||||
lattice_group = create_group(lattices_group, "lattice " // trim(to_str(lat%id())))
|
||||
|
||||
call lat % to_hdf5(lattice_group)
|
||||
|
||||
! Write name, pitch, and outer universe
|
||||
if (lat % outer > 0) then
|
||||
call write_dataset(lattice_group, "outer", universes(lat % outer) % id)
|
||||
else
|
||||
call write_dataset(lattice_group, "outer", lat % outer)
|
||||
end if
|
||||
|
||||
call close_group(lattice_group)
|
||||
end do LATTICE_LOOP
|
||||
call lat % to_hdf5(lattices_group)
|
||||
end do
|
||||
|
||||
call close_group(lattices_group)
|
||||
call close_group(geom_group)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue