mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Finish moving CellFilter implementation to C++
This commit is contained in:
parent
e82f526771
commit
2ce911977a
3 changed files with 20 additions and 60 deletions
|
|
@ -22,6 +22,7 @@ public:
|
|||
from_xml(pugi::xml_node node) override
|
||||
{
|
||||
cells_ = get_node_array<int32_t>(node, "bins");
|
||||
n_bins_ = cells_.size();
|
||||
}
|
||||
|
||||
virtual void
|
||||
|
|
@ -61,7 +62,7 @@ public:
|
|||
to_statepoint(hid_t filter_group) const override
|
||||
{
|
||||
write_dataset(filter_group, "type", "cell");
|
||||
write_dataset(filter_group, "n_bins", cells_.size());
|
||||
write_dataset(filter_group, "n_bins", n_bins_);
|
||||
std::vector<int32_t> cell_ids;
|
||||
for (auto c : cells_) cell_ids.push_back(cells[c]->id_);
|
||||
write_dataset(filter_group, "bins", cell_ids);
|
||||
|
|
@ -73,7 +74,6 @@ public:
|
|||
return "Cell " + std::to_string(cells[cells_[bin-1]]->id_);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<int32_t> cells_;
|
||||
std::unordered_map<int32_t, int> map_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -118,6 +118,13 @@ extern "C" {
|
|||
|
||||
int filter_n_bins(TallyFilter* filt) {return filt->n_bins_;}
|
||||
|
||||
void
|
||||
cell_filter_get_bins(CellFilter* filt, int32_t** cells, int32_t* n)
|
||||
{
|
||||
*cells = filt->cells_.data();
|
||||
*n = filt->cells_.size();
|
||||
}
|
||||
|
||||
int mesh_filter_get_mesh(MeshFilter* filt) {return filt->mesh_;}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -2,15 +2,8 @@ module tally_filter_cell
|
|||
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
||||
use constants, only: ONE, MAX_LINE_LEN
|
||||
use dict_header, only: EMPTY
|
||||
use error, only: fatal_error
|
||||
use hdf5_interface
|
||||
use geometry_header
|
||||
use particle_header, only: Particle
|
||||
use string, only: to_str
|
||||
use error
|
||||
use tally_filter_header
|
||||
use xml_interface
|
||||
|
||||
implicit none
|
||||
private
|
||||
|
|
@ -21,58 +14,10 @@ module tally_filter_cell
|
|||
!===============================================================================
|
||||
|
||||
type, public, extends(CppTallyFilter) :: CellFilter
|
||||
integer(C_INT32_T), allocatable :: cells(:)
|
||||
type(DictIntInt) :: map
|
||||
contains
|
||||
procedure :: from_xml
|
||||
procedure :: initialize => initialize_cell
|
||||
end type CellFilter
|
||||
|
||||
contains
|
||||
|
||||
subroutine from_xml(this, node)
|
||||
class(CellFilter), intent(inout) :: this
|
||||
type(XMLNode), intent(in) :: node
|
||||
|
||||
integer :: n
|
||||
|
||||
call this % from_xml_cpp_inner(node)
|
||||
|
||||
! Determine how many bins were given
|
||||
n = node_word_count(node, "bins")
|
||||
|
||||
! Allocate and store bins
|
||||
this % n_bins = n
|
||||
allocate(this % cells(n))
|
||||
call get_node_array(node, "bins", this % cells)
|
||||
end subroutine from_xml
|
||||
|
||||
subroutine initialize_cell(this)
|
||||
class(CellFilter), intent(inout) :: this
|
||||
|
||||
integer :: i, id
|
||||
integer :: val
|
||||
|
||||
call this % initialize_cpp_inner()
|
||||
|
||||
! Convert ids to indices.
|
||||
do i = 1, this % n_bins
|
||||
id = this % cells(i)
|
||||
val = cell_dict % get(id)
|
||||
if (val /= EMPTY) then
|
||||
this % cells(i) = val
|
||||
else
|
||||
call fatal_error("Could not find cell " // trim(to_str(id)) &
|
||||
&// " specified on tally filter.")
|
||||
end if
|
||||
end do
|
||||
|
||||
! Generate mapping from cell indices to filter bins.
|
||||
do i = 1, this % n_bins
|
||||
call this % map % set(this % cells(i), i)
|
||||
end do
|
||||
end subroutine initialize_cell
|
||||
|
||||
!===============================================================================
|
||||
! C API FUNCTIONS
|
||||
!===============================================================================
|
||||
|
|
@ -84,12 +29,20 @@ contains
|
|||
integer(C_INT32_T), intent(out) :: n
|
||||
integer(C_INT) :: err
|
||||
|
||||
interface
|
||||
subroutine cell_filter_get_bins(filt, cells, n) bind(C)
|
||||
import C_PTR, C_INT
|
||||
type(C_PTR), intent(in), value :: filt
|
||||
type(C_PTR), intent(out) :: cells
|
||||
integer(C_INT), intent(out) :: n
|
||||
end subroutine cell_filter_get_bins
|
||||
end interface
|
||||
|
||||
err = verify_filter(index)
|
||||
if (err == 0) then
|
||||
select type (f => filters(index) % obj)
|
||||
type is (CellFilter)
|
||||
cells = C_LOC(f % cells)
|
||||
n = size(f % cells)
|
||||
call cell_filter_get_bins(f % ptr, cells, n)
|
||||
class default
|
||||
err = E_INVALID_TYPE
|
||||
call set_errmsg("Tried to get cells from a non-cell filter.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue