From 49daad3f949819867279169618cd7cbca30980d7 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Mon, 11 Feb 2019 20:22:48 -0500 Subject: [PATCH] Cleanup C++ tallies work --- include/openmc/tallies/tally.h | 6 +++--- include/openmc/tallies/tally_scoring.h | 11 ++++++++--- include/openmc/tallies/trigger.h | 6 +++--- src/input_xml.F90 | 3 ++- src/tallies/tally.cpp | 19 ++++++------------- src/tallies/tally_header.F90 | 16 ---------------- src/tallies/trigger.cpp | 6 +++--- 7 files changed, 25 insertions(+), 42 deletions(-) diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 11ad1124be..0bb2127c0e 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -50,11 +50,11 @@ public: //---------------------------------------------------------------------------- // Major public data members. - int id_; //!< user-defined identifier + int id_; //!< User-defined identifier - std::string name_; //!< user-defined name + std::string name_; //!< User-defined name - int type_ {TALLY_VOLUME}; //!< volume, surface current + int type_ {TALLY_VOLUME}; //!< e.g. volume, surface current //! Event type that contributes to this tally int estimator_ {ESTIMATOR_TRACKLENGTH}; diff --git a/include/openmc/tallies/tally_scoring.h b/include/openmc/tallies/tally_scoring.h index 0db43f08c6..ea415c514b 100644 --- a/include/openmc/tallies/tally_scoring.h +++ b/include/openmc/tallies/tally_scoring.h @@ -12,16 +12,21 @@ namespace openmc { //! This iterator handles two distinct tasks. First, it maps the N-dimensional //! space created by the indices of N filters onto a 1D sequence. In other //! words, it provides a single number that uniquely identifies a combination of -//! bins for many filters. Second, it handles the task of finding each all -//! valid combinations of filter bins given that each filter can have 1 or 2 or -//! many bins that are valid for the current tally event. +//! bins for many filters. Second, it handles the task of finding each valid +//! combination of filter bins given that each filter can have 1 or 2 or many +//! bins that are valid for the current tally event. //============================================================================== class FilterBinIter { public: + + //! Construct an iterator over bins that match a given particle's state. FilterBinIter(const Tally& tally, Particle* p); + //! Construct an iterator over all filter bin combinations. + // + //! \param end if true, the returned iterator indicates the end of a loop. FilterBinIter(const Tally& tally, bool end); bool operator==(const FilterBinIter& other) const diff --git a/include/openmc/tallies/trigger.h b/include/openmc/tallies/trigger.h index f4f44e20ad..e670297ed1 100644 --- a/include/openmc/tallies/trigger.h +++ b/include/openmc/tallies/trigger.h @@ -19,9 +19,9 @@ enum class TriggerMetric { struct Trigger { - TriggerMetric metric; - double threshold; //!< uncertainty value below which trigger is satisfied - int score_index; //!< index of the relevant score in the tally's arrays + TriggerMetric metric; //!< The type of uncertainty (e.g. std dev) measured + double threshold; //!< Uncertainty value below which trigger is satisfied + int score_index; //!< Index of the relevant score in the tally's arrays }; //! Stops the simulation early if a desired k-effective uncertainty is reached. diff --git a/src/input_xml.F90 b/src/input_xml.F90 index ec4440a127..40795200d8 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -828,7 +828,8 @@ contains ! If settings.xml trigger is turned on, create tally triggers if (trigger_on) then - call tally_init_triggers(t % ptr, i_start + i - 1, node_tal % ptr) + !TODO: off-by-one + call tally_init_triggers(t % ptr, i_start + i - 1 - 1, node_tal % ptr) end if ! ======================================================================= diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 5f6287b890..e9bee044df 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -478,25 +478,20 @@ Tally::init_triggers(pugi::xml_node node, int i_tally) trigger_scores.push_back("all"); } - //TODO: change this when tally scores are moved to C++ - // Get access to the tally's scores. - int* tally_scores; - int n_tally_scores; - auto err = openmc_tally_get_scores(i_tally, &tally_scores, &n_tally_scores); - // Parse the trigger scores and populate the triggers_ vector. + const auto& tally {*model::tallies[i_tally]}; for (auto score_str : trigger_scores) { if (score_str == "all") { - triggers_.reserve(triggers_.size() + n_tally_scores); - for (auto i_score = 0; i_score < n_tally_scores; ++i_score) { + triggers_.reserve(triggers_.size() + tally.scores_.size()); + for (auto i_score = 0; i_score < tally.scores_.size(); ++i_score) { triggers_.push_back({metric, threshold, i_score}); } } else { int i_score = 0; - for (; i_score < n_tally_scores; ++i_score) { - if (reaction_name(tally_scores[i_score]) == score_str) break; + for (; i_score < tally.scores_.size(); ++i_score) { + if (reaction_name(tally.scores_[i_score]) == score_str) break; } - if (i_score == n_tally_scores) { + if (i_score == tally.scores_.size()) { std::stringstream msg; msg << "Could not find the score \"" << score_str << "\" in tally " << id_ << " but it was listed in a trigger on that tally"; @@ -902,8 +897,6 @@ extern "C" { int32_t tally_get_filter_c(Tally* tally, int i) {return tally->filters(i);} - int32_t tally_get_stride_c(Tally* tally, int i) {return tally->strides(i);} - int32_t tally_get_n_filter_bins_c(Tally* tally) {return tally->n_filter_bins();} diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 8784b63b43..14ac94107f 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -125,7 +125,6 @@ module tally_header procedure :: score_bins => tally_get_score_bin procedure :: n_filters => tally_get_n_filters procedure :: filter => tally_get_filter - procedure :: stride => tally_get_stride procedure :: n_filter_bins => tally_get_n_filter_bins procedure :: n_nuclide_bins => tally_get_n_nuclide_bins procedure :: nuclide_bins => tally_get_nuclide_bins @@ -437,21 +436,6 @@ contains filt = tally_get_filter_c(this % ptr, i-1) end function - function tally_get_stride(this, i) result(stride) - class(TallyObject) :: this - integer(C_INT) :: i - integer(C_INT32_T) :: stride - interface - function tally_get_stride_c(tally, i) result(stride) bind(C) - import C_PTR, C_INT, C_INT32_T - type(C_PTR), value :: tally - integer(C_INT), value :: i - integer(C_INT32_T) :: stride - end function - end interface - stride = tally_get_stride_c(this % ptr, i-1) - end function - function tally_get_n_filter_bins(this) result(n_filter_bins) class(TallyObject) :: this integer(C_INT32_T) :: n_filter_bins diff --git a/src/tallies/trigger.cpp b/src/tallies/trigger.cpp index 25bb0c8c04..6cd99f1330 100644 --- a/src/tallies/trigger.cpp +++ b/src/tallies/trigger.cpp @@ -23,7 +23,7 @@ namespace settings { } //============================================================================== -// Non-memeber functions +// Non-member functions //============================================================================== static std::pair @@ -44,7 +44,7 @@ get_tally_uncertainty(int i_tally, int score_index, int filter_index) return {std_dev, rel_err}; } -//! Finds the limiting limiting tally trigger. +//! Find the limiting limiting tally trigger. // //! param[out] ratio The uncertainty/threshold ratio for the most limiting //! tally trigger @@ -107,7 +107,7 @@ check_tally_triggers(double& ratio, int& tally_id, int& score) } } -//! Computes the uncertainty/threshold ratio for the eigenvalue trigger. +//! Compute the uncertainty/threshold ratio for the eigenvalue trigger. double check_keff_trigger()