Call C++ code by default in F90 CppTallyFilters

This commit is contained in:
Sterling Harper 2018-10-07 11:43:46 -04:00
parent 64bd9af4ce
commit cf1e9204f6
5 changed files with 56 additions and 112 deletions

View file

@ -25,9 +25,6 @@ module tally_filter_cell
type(DictIntInt) :: map
contains
procedure :: from_xml
procedure :: get_all_bins => get_all_bins_cell
procedure :: to_statepoint => to_statepoint_cell
procedure :: text_label => text_label_cell
procedure :: initialize => initialize_cell
end type CellFilter
@ -39,7 +36,7 @@ contains
integer :: n
call this % from_xml_c(node)
call this % from_xml_cpp_inner(node)
! Determine how many bins were given
n = node_word_count(node, "bins")
@ -50,31 +47,13 @@ contains
call get_node_array(node, "bins", this % cells)
end subroutine from_xml
subroutine get_all_bins_cell(this, p, estimator, match)
class(CellFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
call this % get_all_bins_c(p, estimator, match)
end subroutine get_all_bins_cell
subroutine to_statepoint_cell(this, filter_group)
class(CellFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group
call this % to_statepoint_c(filter_group)
end subroutine to_statepoint_cell
subroutine initialize_cell(this)
class(CellFilter), intent(inout) :: this
integer :: i, id
integer :: val
call this % initialize_c()
call this % initialize_cpp_inner()
! Convert ids to indices.
do i = 1, this % n_bins
@ -94,14 +73,6 @@ contains
end do
end subroutine initialize_cell
function text_label_cell(this, bin) result(label)
class(CellFilter), intent(in) :: this
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
label = this % text_label_c(bin)
end function text_label_cell
!===============================================================================
! C API FUNCTIONS
!===============================================================================

View file

@ -2,16 +2,7 @@ module tally_filter_cellfrom
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 tally_filter_header
use tally_filter_cell
use xml_interface
implicit none
private
@ -22,39 +13,6 @@ module tally_filter_cellfrom
!===============================================================================
type, public, extends(CellFilter) :: CellFromFilter
contains
! Inherit from_xml from CellFilter
procedure :: get_all_bins => get_all_bins_cell_from
procedure :: to_statepoint => to_statepoint_cell_from
procedure :: text_label => text_label_cell_from
end type CellFromFilter
contains
subroutine get_all_bins_cell_from(this, p, estimator, match)
class(CellFromFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
call this % get_all_bins_c(p, estimator, match)
end subroutine get_all_bins_cell_from
subroutine to_statepoint_cell_from(this, filter_group)
class(CellFromFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group
call this % to_statepoint_c(filter_group)
end subroutine to_statepoint_cell_from
function text_label_cell_from(this, bin) result(label)
class(CellFromFilter), intent(in) :: this
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
label = this % text_label_c(bin)
end function text_label_cell_from
end module tally_filter_cellfrom

View file

@ -130,11 +130,16 @@ module tally_filter_header
type, public, abstract, extends(TallyFilter) :: CppTallyFilter
type(C_PTR) :: ptr
contains
procedure :: from_xml_c
procedure :: get_all_bins_c
procedure :: to_statepoint_c
procedure :: text_label_c
procedure :: initialize_c
procedure :: from_xml_cpp_inner
procedure :: get_all_bins_cpp_inner
procedure :: to_statepoint_cpp_inner
procedure :: text_label_cpp_inner
procedure :: initialize_cpp_inner
procedure :: from_xml => from_xml_cpp_default
procedure :: get_all_bins => get_all_bins_cpp_default
procedure :: to_statepoint => to_statepoint_cpp_default
procedure :: text_label => text_label_cpp_default
procedure :: initialize => initialize_cpp_default
end type CppTallyFilter
!===============================================================================
@ -280,7 +285,7 @@ contains
!===============================================================================
subroutine from_xml_c(this, node)
subroutine from_xml_cpp_inner(this, node)
class(CppTallyFilter), intent(inout) :: this
class(XMLNode), intent(in) :: node
interface
@ -291,9 +296,9 @@ contains
end subroutine filter_from_xml
end interface
call filter_from_xml(this % ptr, node % ptr)
end subroutine from_xml_c
end subroutine from_xml_cpp_inner
subroutine get_all_bins_c(this, p, estimator, match)
subroutine get_all_bins_cpp_inner(this, p, estimator, match)
class(CppTallyFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
@ -308,9 +313,9 @@ contains
end subroutine filter_get_all_bins
end interface
call filter_get_all_bins(this % ptr, p, estimator, match % ptr)
end subroutine get_all_bins_c
end subroutine get_all_bins_cpp_inner
subroutine to_statepoint_c(this, filter_group)
subroutine to_statepoint_cpp_inner(this, filter_group)
class(CppTallyFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group
interface
@ -321,9 +326,9 @@ contains
end subroutine filter_to_statepoint
end interface
call filter_to_statepoint(this % ptr, filter_group)
end subroutine to_statepoint_c
end subroutine to_statepoint_cpp_inner
function text_label_c(this, bin) result(label)
function text_label_cpp_inner(this, bin) result(label)
class(CppTallyFilter), intent(in) :: this
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
@ -343,9 +348,9 @@ contains
if (label_(i) == C_NULL_CHAR) exit
label(i:i) = label_(i)
end do
end function text_label_c
end function text_label_cpp_inner
subroutine initialize_c(this)
subroutine initialize_cpp_inner(this)
class(CppTallyFilter), intent(inout) :: this
interface
subroutine filter_initialize(filt) bind(C)
@ -354,7 +359,39 @@ contains
end subroutine filter_initialize
end interface
call filter_initialize(this % ptr)
end subroutine initialize_c
end subroutine initialize_cpp_inner
subroutine from_xml_cpp_default(this, node)
class(CppTallyFilter), intent(inout) :: this
type(XMLNode), intent(in) :: node
call this % from_xml_cpp_inner(node)
end subroutine from_xml_cpp_default
subroutine get_all_bins_cpp_default(this, p, estimator, match)
class(CppTallyFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
call this % get_all_bins_cpp_inner(p, estimator, match)
end subroutine get_all_bins_cpp_default
subroutine to_statepoint_cpp_default(this, filter_group)
class(CppTallyFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group
call this % to_statepoint_cpp_inner(filter_group)
end subroutine to_statepoint_cpp_default
function text_label_cpp_default(this, bin) result(label)
class(CppTallyFilter), intent(in) :: this
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
label = this % text_label_cpp_inner(bin)
end function text_label_cpp_default
subroutine initialize_cpp_default(this)
class(CppTallyFilter), intent(inout) :: this
call this % initialize_cpp_inner()
end subroutine initialize_cpp_default
!===============================================================================
! FREE_MEMORY_TALLY_FILTER deallocates global arrays defined in this module

View file

@ -27,7 +27,6 @@ module tally_filter_mesh
integer :: mesh
contains
procedure :: from_xml
procedure :: get_all_bins => get_all_bins_mesh
procedure :: to_statepoint => to_statepoint_mesh
procedure :: text_label => text_label_mesh
end type MeshFilter
@ -44,7 +43,7 @@ contains
integer(C_INT) :: err
type(RegularMesh) :: m
call this % from_xml_c(node)
call this % from_xml_cpp_inner(node)
n = node_word_count(node, "bins")
@ -69,16 +68,6 @@ contains
end do
end subroutine from_xml
subroutine get_all_bins_mesh(this, p, estimator, match)
class(MeshFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
call this % get_all_bins_c(p, estimator, match)
end subroutine get_all_bins_mesh
subroutine to_statepoint_mesh(this, filter_group)
class(MeshFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group

View file

@ -26,7 +26,6 @@ module tally_filter_meshsurface
integer :: mesh
contains
procedure :: from_xml
procedure :: get_all_bins
procedure :: to_statepoint
procedure :: text_label
end type MeshSurfaceFilter
@ -43,7 +42,7 @@ contains
integer(C_INT) :: err
type(RegularMesh) :: m
call this % from_xml_c(node)
call this % from_xml_cpp_inner(node)
n = node_word_count(node, "bins")
@ -68,16 +67,6 @@ contains
end do
end subroutine from_xml
subroutine get_all_bins(this, p, estimator, match)
class(MeshSurfaceFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
call this % get_all_bins_c(p, estimator, match)
end subroutine get_all_bins
subroutine to_statepoint(this, filter_group)
class(MeshSurfaceFilter), intent(in) :: this
integer(HID_T), intent(in) :: filter_group