Move tally filter IDs to C++

This commit is contained in:
Sterling Harper 2019-02-12 13:14:39 -05:00
parent 08e50977f0
commit b350e7dcd6
4 changed files with 33 additions and 6 deletions

View file

@ -72,6 +72,8 @@ public:
virtual void initialize() {}
int32_t id_;
int n_bins_;
};

View file

@ -90,7 +90,7 @@ contains
! Write IDs of filters
allocate(id_array(n_filters))
do i = 1, n_filters
id_array(i) = filters(i) % obj % id
id_array(i) = filters(i) % obj % id()
end do
call write_attribute(filters_group, "ids", id_array)
deallocate(id_array)
@ -98,7 +98,7 @@ contains
! Write filter information
FILTER_LOOP: do i = 1, n_filters
filter_group = create_group(filters_group, "filter " // &
trim(to_str(filters(i) % obj % id)))
trim(to_str(filters(i) % obj % id())))
call filters(i) % obj % to_statepoint(filter_group)
call close_group(filter_group)
end do FILTER_LOOP
@ -145,7 +145,7 @@ contains
! Write IDs of filters
allocate(id_array(tally % n_filters()))
do j = 1, tally % n_filters()
id_array(j) = filters(tally % filter(j) + 1) % obj % id
id_array(j) = filters(tally % filter(j) + 1) % obj % id()
end do
call write_dataset(tally_group, "filters", id_array)
deallocate(id_array)

View file

@ -104,6 +104,10 @@ extern "C" {
return model::tally_filters.back().get();
}
int32_t filter_get_id(Filter* filt) {return filt->id_;}
void filter_set_id(Filter* filt, int32_t id) {filt->id_ = id;}
void filter_from_xml(Filter* filt, pugi::xml_node* node)
{filt->from_xml(*node);}

View file

@ -27,10 +27,10 @@ module tally_filter_header
!===============================================================================
type, public, abstract :: TallyFilter
integer :: id
integer :: n_bins = 0
type(C_PTR) :: ptr
contains
procedure :: id => filter_get_id_f90
procedure :: from_xml
procedure :: to_statepoint
procedure :: initialize
@ -128,6 +128,19 @@ contains
! TallyFilter implementation
!===============================================================================
function filter_get_id_f90(this) result(id)
class(TallyFilter) :: this
integer(C_INT32_T) :: id
interface
function filter_get_id(filt) result(id) bind(C)
import C_PTR, C_INT32_T
type(C_PTR), value :: filt
integer(C_INT32_T) :: id
end function
end interface
id = filter_get_id(this % ptr)
end function
subroutine from_xml(this, node)
class(TallyFilter), intent(inout) :: this
type(XMLNode), intent(in) :: node
@ -285,7 +298,7 @@ contains
integer(C_INT) :: err
if (index >= 1 .and. index <= n_filters) then
id = filters(index) % obj % id
id = filters(index) % obj % id()
err = 0
else
err = E_OUT_OF_BOUNDS
@ -300,9 +313,17 @@ contains
integer(C_INT32_T), value, intent(in) :: id
integer(C_INT) :: err
interface
subroutine filter_set_id(filt, id) bind(C)
import C_PTR, C_INT32_T
type(C_PTR), value :: filt
integer(C_INT32_T), value :: id
end subroutine
end interface
if (index >= 1 .and. index <= n_filters) then
if (allocated(filters(index) % obj)) then
filters(index) % obj % id = id
call filter_set_id(filters(index) % obj % ptr, id)
call filter_dict % set(id, index)
if (id > largest_filter_id) largest_filter_id = id