Cleanup C++ tallies work

This commit is contained in:
Sterling Harper 2019-02-11 20:22:48 -05:00
parent a8a7d9112f
commit 49daad3f94
7 changed files with 25 additions and 42 deletions

View file

@ -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};

View file

@ -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

View file

@ -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.

View file

@ -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
! =======================================================================

View file

@ -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();}

View file

@ -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

View file

@ -23,7 +23,7 @@ namespace settings {
}
//==============================================================================
// Non-memeber functions
// Non-member functions
//==============================================================================
static std::pair<double, double>
@ -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()