From fe6fba2954372bf7deb3bdc34e51bf44be830df7 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sat, 26 Jan 2019 14:03:30 -0500 Subject: [PATCH] Use 0-based indexing for tally derivatives --- include/openmc/tallies/tally.h | 2 +- src/input_xml.F90 | 11 +++++------ src/output.F90 | 4 ++-- src/state_point.F90 | 8 ++++---- src/tallies/tally.F90 | 18 +++++++++--------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 77e5958ef..e67ebb784 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -39,7 +39,7 @@ public: int surface_filter_ {C_NONE}; int mesh_filter_ {C_NONE}; - int deriv_ {F90_NONE}; //!< Index of a TallyDerivative object for diff tallies. + int deriv_ {C_NONE}; //!< Index of a TallyDerivative object for diff tallies. private: std::vector filters_; //!< Filter indices in global filters array diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 87eeac6c3..5972f3057 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -1004,9 +1004,8 @@ contains call read_tally_derivatives(root % ptr) - call get_node_list(root, "derivative", node_deriv_list) - do i = 1, size(node_deriv_list) - deriv => tally_deriv_c(i - 1) + do i = 0, n_tally_derivs() - 1 + deriv => tally_deriv_c(i) call tally_deriv_dict % set(deriv % id, i) end do @@ -1599,8 +1598,8 @@ contains call get_node_value(node_tal, "derivative", deriv_id) ! Find the derivative with the given id, and store it's index. - do j = 1, n_tally_derivs() - deriv => tally_deriv_c(j - 1) + do j = 0, n_tally_derivs() - 1 + deriv => tally_deriv_c(j) if (deriv % id == deriv_id) then call t % set_deriv(j) ! Only analog or collision estimators are supported for differential @@ -1618,7 +1617,7 @@ contains end if end do - deriv => tally_deriv_c(t % deriv() - 1) + deriv => tally_deriv_c(t % deriv()) if (deriv % variable == DIFF_NUCLIDE_DENSITY & .or. deriv % variable == DIFF_TEMPERATURE) then if (any(t % nuclide_bins == -1)) then diff --git a/src/output.F90 b/src/output.F90 index 04e35c17d..248715358 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -531,9 +531,9 @@ contains endif ! Write derivative information. - if (t % deriv() /= NONE) then + if (t % deriv() /= C_NONE) then !associate(deriv => tally_derivs(t % deriv())) - deriv => tally_deriv_c(t % deriv() - 1) + deriv => tally_deriv_c(t % deriv()) select case (deriv % variable) case (DIFF_DENSITY) write(unit=unit_tally, fmt="(' Density derivative Material ',A)") & diff --git a/src/state_point.F90 b/src/state_point.F90 index f9fde0191..5dd98b3ea 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -177,9 +177,9 @@ contains ! Write information for derivatives. if (n_tally_derivs() > 0) then derivs_group = create_group(tallies_group, "derivatives") - do i = 1, n_tally_derivs() + do i = 0, n_tally_derivs() - 1 !associate(deriv => tally_derivs(i)) - deriv => tally_deriv_c(i - 1) + deriv => tally_deriv_c(i) deriv_group = create_group(derivs_group, "derivative " & // trim(to_str(deriv % id))) select case (deriv % variable) @@ -305,8 +305,8 @@ contains deallocate(str_array) ! Write derivative information. - if (tally % deriv() /= NONE) then - deriv => tally_deriv_c(tally % deriv() - 1) + if (tally % deriv() /= C_NONE) then + deriv => tally_deriv_c(tally % deriv()) call write_dataset(tally_group, "derivative", & deriv % id) end if diff --git a/src/tallies/tally.F90 b/src/tallies/tally.F90 index 3122bf866..d3ad9877f 100644 --- a/src/tallies/tally.F90 +++ b/src/tallies/tally.F90 @@ -1184,7 +1184,7 @@ contains !######################################################################### ! Add derivative information on score for differential tallies. - if (t % deriv() /= NONE) then + if (t % deriv() /= C_NONE) then call apply_derivative_to_score(p, t, i_nuclide, atom_density, & score_bin, score) end if @@ -2375,7 +2375,7 @@ contains ! Add derivative information for differential tallies. Note that the ! i_nuclide and atom_density arguments do not matter since this is an ! analog estimator. - if (t % deriv() /= NONE) then + if (t % deriv() /= C_NONE) then call apply_derivative_to_score(p, t, 0, ZERO, SCORE_NU_FISSION, score) end if @@ -3006,7 +3006,7 @@ contains ! perturbated variable. !associate(deriv => tally_derivs(t % deriv())) - deriv => tally_deriv_c(t % deriv() - 1) + deriv => tally_deriv_c(t % deriv()) flux_deriv = deriv % flux_deriv !select case (tally_derivs(t % deriv()) % variable) @@ -3568,9 +3568,9 @@ contains ! A void material cannot be perturbed so it will not affect flux derivatives if (p % material == MATERIAL_VOID) return - do i = 1, n_tally_derivs() + do i = 0, n_tally_derivs() - 1 !associate(deriv => tally_derivs(i)) - deriv => tally_deriv_c(i - 1) + deriv => tally_deriv_c(i) select case (deriv % variable) case (DIFF_DENSITY) @@ -3644,9 +3644,9 @@ contains ! A void material cannot be perturbed so it will not affect flux derivatives if (p % material == MATERIAL_VOID) return - do i = 1, n_tally_derivs() + do i = 0, n_tally_derivs() - 1 !associate(deriv => tally_derivs(i)) - deriv => tally_deriv_c(i - 1) + deriv => tally_deriv_c(i) select case (deriv % variable) case (DIFF_DENSITY) @@ -3720,8 +3720,8 @@ contains subroutine zero_flux_derivs() integer :: i type(TallyDerivative), pointer :: deriv - do i = 1, n_tally_derivs() - deriv => tally_deriv_c(i - 1) + do i = 0, n_tally_derivs() - 1 + deriv => tally_deriv_c(i) deriv % flux_deriv = ZERO end do end subroutine zero_flux_derivs