Move tally id to C++

This commit is contained in:
Sterling Harper 2019-02-04 22:32:00 -05:00
parent 1ee3224ac1
commit 391c7536d4
7 changed files with 59 additions and 30 deletions

View file

@ -42,6 +42,8 @@ public:
//----------------------------------------------------------------------------
// Major public data members.
int id_; //!< user-defined identifier
int type_ {TALLY_VOLUME}; //!< volume, surface current
//! Event type that contributes to this tally

View file

@ -1133,7 +1133,7 @@ contains
else
call fatal_error("Could not find filter " &
// trim(to_str(temp_filter(j))) // " specified on tally " &
// trim(to_str(t % id)))
// trim(to_str(t % id())))
end if
! Store the index of the filter
@ -1230,7 +1230,7 @@ contains
if (.not. nuclide_dict % has(word)) then
call fatal_error("Could not find the nuclide " &
// trim(word) // " specified in tally " &
// trim(to_str(t % id)) // " in any material.")
// trim(to_str(t % id())) // " in any material.")
end if
! Set bin to index in nuclides array
@ -1526,7 +1526,7 @@ contains
if (t % score_bins(j) == t % score_bins(k)) then
call fatal_error("Duplicate score of type '" // trim(&
reaction_name(t % score_bins(j))) // "' found in tally " &
// trim(to_str(t % id)))
// trim(to_str(t % id())))
end if
end do
end do
@ -1573,7 +1573,7 @@ contains
end if
else
call fatal_error("No <scores> specified on tally " &
// trim(to_str(t % id)) // ".")
// trim(to_str(t % id())) // ".")
end if
! Check for a tally derivative.
@ -1596,7 +1596,7 @@ contains
if (j == n_tally_derivs()) then
call fatal_error("Could not find derivative " &
// trim(to_str(deriv_id)) // " specified on tally " &
// trim(to_str(t % id)))
// trim(to_str(t % id())))
end if
end do
@ -1605,7 +1605,7 @@ contains
.or. deriv % variable == DIFF_TEMPERATURE) then
do j = 1, t % n_nuclide_bins()
if (has_energyout .and. t % nuclide_bins(j) == -1) then
call fatal_error("Error on tally " // trim(to_str(t % id)) &
call fatal_error("Error on tally " // trim(to_str(t % id())) &
// ": Cannot use a 'nuclide_density' or 'temperature' &
&derivative on a tally with an outgoing energy filter and &
&'total' nuclide rate. Instead, tally each nuclide in the &
@ -1640,7 +1640,7 @@ contains
! tally needs post-collision information
if (t % estimator() == ESTIMATOR_ANALOG) then
call fatal_error("Cannot use track-length estimator for tally " &
// to_str(t % id))
// to_str(t % id()))
end if
! Set estimator to track-length estimator
@ -1651,7 +1651,7 @@ contains
! tally needs post-collision information
if (t % estimator() == ESTIMATOR_ANALOG) then
call fatal_error("Cannot use collision estimator for tally " &
// to_str(t % id))
// to_str(t % id()))
end if
! Set estimator to collision estimator
@ -1659,7 +1659,7 @@ contains
case default
call fatal_error("Invalid estimator '" // trim(temp_str) &
// "' on tally " // to_str(t % id))
// "' on tally " // to_str(t % id()))
end select
end if

View file

@ -522,9 +522,9 @@ contains
! Write header block
if (t % name == "") then
call header("TALLY " // trim(to_str(t % id)), 1, unit=unit_tally)
call header("TALLY " // trim(to_str(t % id())), 1, unit=unit_tally)
else
call header("TALLY " // trim(to_str(t % id)) // ": " &
call header("TALLY " // trim(to_str(t % id())) // ": " &
// trim(t % name), 1, unit=unit_tally)
endif
@ -546,7 +546,7 @@ contains
&A)") to_str(deriv % diff_material)
case default
call fatal_error("Differential tally dependent variable for tally "&
// trim(to_str(t % id)) // " not defined in output.F90.")
// trim(to_str(t % id())) // " not defined in output.F90.")
end select
!end associate
end if

View file

@ -238,7 +238,7 @@ contains
! Write array of tally IDs
allocate(id_array(n_tallies))
do i = 1, n_tallies
id_array(i) = tallies(i) % obj % id
id_array(i) = tallies(i) % obj % id()
end do
call write_attribute(tallies_group, "ids", id_array)
deallocate(id_array)
@ -249,7 +249,7 @@ contains
! Get pointer to tally
associate (tally => tallies(i) % obj)
tally_group = create_group(tallies_group, "tally " // &
trim(to_str(tally % id)))
trim(to_str(tally % id())))
! Write the name for this tally
call write_dataset(tally_group, "name", tally % name)
@ -357,7 +357,7 @@ contains
associate (tally => tallies(i) % obj)
! Write sum and sum_sq for each bin
tally_group = open_group(tallies_group, "tally " &
// to_str(tally % id))
// to_str(tally % id()))
call tally % write_results_hdf5(tally_group)
call close_group(tally_group)
end associate
@ -560,7 +560,7 @@ contains
associate (t => tallies(i) % obj)
! Read sum, sum_sq, and N for each bin
tally_group = open_group(tallies_group, "tally " // &
trim(to_str(t % id)))
trim(to_str(t % id())))
call t % read_results_hdf5(tally_group)
call read_dataset(t % n_realizations, tally_group, &
"n_realizations")

View file

@ -1212,7 +1212,7 @@ contains
else
call fatal_error("Invalid score type on tally " &
// to_str(t % id) // ".")
// to_str(t % id()) // ".")
end if
end if
@ -2367,7 +2367,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case (ESTIMATOR_COLLISION)
@ -2388,7 +2388,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case default
@ -2438,7 +2438,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case (ESTIMATOR_COLLISION)
@ -2525,7 +2525,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case default
@ -2678,7 +2678,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case (ESTIMATOR_COLLISION)
@ -2867,7 +2867,7 @@ contains
case default
call fatal_error('Tally derivative not defined for a score on &
&tally ' // trim(to_str(t % id)))
&tally ' // trim(to_str(t % id())))
end select
case default

View file

@ -236,10 +236,6 @@ Tally::set_filters(const int32_t filter_indices[], int n)
void
Tally::init_triggers(pugi::xml_node node, int i_tally)
{
//TODO: use id_ attribute when it's available in C++
int id_;
auto err = openmc_tally_get_id(i_tally, &id_);
for (auto trigger_node: node.children("trigger")) {
// Read the trigger type.
TriggerMetric metric;
@ -943,6 +939,10 @@ extern "C" {
int active_surface_tallies_size()
{return model::active_surface_tallies.size();}
int tally_get_id_c(Tally* tally) {return tally->id_;}
void tally_set_id_c(Tally* tally, int id) {tally->id_ = id;}
int tally_get_type_c(Tally* tally) {return tally->type_;}
void tally_set_type_c(Tally* tally, int type) {tally->type_ = type;}

View file

@ -95,7 +95,6 @@ module tally_header
! Basic data
integer :: id ! user-defined identifier
character(len=104) :: name = "" ! user-defined name
real(8) :: volume ! volume of region
logical :: depletion_rx = .false. ! has depletion reactions, e.g. (n,2n)
@ -120,6 +119,8 @@ module tally_header
procedure :: allocate_results => tally_allocate_results
procedure :: read_results_hdf5 => tally_read_results_hdf5
procedure :: write_results_hdf5 => tally_write_results_hdf5
procedure :: id => tally_get_id
procedure :: set_id => tally_set_id
procedure :: type => tally_get_type
procedure :: set_type => tally_set_type
procedure :: estimator => tally_get_estimator
@ -300,6 +301,32 @@ contains
end subroutine tally_allocate_results
function tally_get_id(this) result(t)
class(TallyObject) :: this
integer(C_INT) :: t
interface
function tally_get_id_c(tally) result(t) bind(C)
import C_PTR, C_INT
type(C_PTR), value :: tally
integer(C_INT) :: t
end function
end interface
t = tally_get_id_c(this % ptr)
end function
subroutine tally_set_id(this, t)
class(TallyObject) :: this
integer(C_INT) :: t
interface
subroutine tally_set_id_c(tally, t) bind(C)
import C_PTR, C_INT
type(C_PTR), value :: tally
integer(C_INT), value :: t
end subroutine
end interface
call tally_set_id_c(this % ptr, t)
end subroutine
function tally_get_type(this) result(t)
class(TallyObject) :: this
integer(C_INT) :: t
@ -669,7 +696,7 @@ contains
integer(C_INT) :: err
if (index >= 1 .and. index <= size(tallies)) then
id = tallies(index) % obj % id
id = tallies(index) % obj % id()
err = 0
else
err = E_OUT_OF_BOUNDS
@ -812,7 +839,7 @@ contains
// to_str(id))
err = E_INVALID_ID
else
tallies(index) % obj % id = id
call tallies(index) % obj % set_id(id)
call tally_dict % set(id, index)
if (id > largest_tally_id) largest_tally_id = id