Cardinal
TallyBase.h
Go to the documentation of this file.
1 /********************************************************************/
2 /* SOFTWARE COPYRIGHT NOTIFICATION */
3 /* Cardinal */
4 /* */
5 /* (c) 2021 UChicago Argonne, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by UChicago Argonne, LLC */
9 /* Under Contract No. DE-AC02-06CH11357 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* Prepared by Battelle Energy Alliance, LLC */
13 /* Under Contract No. DE-AC07-05ID14517 */
14 /* With the U. S. Department of Energy */
15 /* */
16 /* See LICENSE for full restrictions */
17 /********************************************************************/
18 
19 #pragma once
20 
21 #include "MooseObject.h"
22 #include "CardinalEnums.h"
23 
24 #include "openmc/tallies/tally.h"
25 #include "xtensor/xview.hpp"
26 
29 class MooseMesh;
30 class AuxiliarySystem;
31 class FilterBase;
32 
33 class TallyBase : public MooseObject
34 {
35 public:
36  static InputParameters validParams();
37 
38  TallyBase(const InputParameters & parameters);
39 
46  virtual std::pair<unsigned int, openmc::Filter *> spatialFilter() = 0;
47 
51  virtual void initializeTally();
52 
56  virtual void resetTally();
57 
69  Real storeResults(const std::vector<unsigned int> & var_numbers,
70  unsigned int local_score,
71  unsigned int global_score,
72  const std::string & output_type);
73 
78  void addScore(const std::string & score);
79 
84  void computeSumAndMean();
85 
106  void relaxAndNormalizeTally(unsigned int local_score, const Real & alpha, const Real & norm);
107 
112  const openmc::Tally * getWrappedTally() const;
113 
117  int32_t getTallyID() const;
118 
123  const std::vector<std::string> & getScores() const { return _tally_score; }
124 
130  int scoreIndex(const std::string & score) const;
131 
138  const std::vector<std::string> & getAuxVarNames() const { return _tally_name; }
139 
145  const std::vector<std::string> & getOutputs() const { return _output_name; }
146 
151  openmc::TallyEstimator getTallyEstimator() const { return _estimator; }
152 
158  const Real & getMean(unsigned int local_score) const { return _local_mean_tally[local_score]; }
159 
165  const Real & getSum(unsigned int local_score) const { return _local_sum_tally[local_score]; }
166 
172  std::vector<std::string> getScoreVars(const std::string & score) const;
173 
179  bool extBinSkipped(unsigned int ext_bin) const { return _ext_bins_to_skip[ext_bin]; }
180 
185  bool hasTrigger() const { return _tally_trigger != nullptr; }
186 
191  bool hasOutputs() const { return _has_outputs; }
192 
198  bool hasScore(const std::string & score) const
199  {
200  return std::find(_tally_score.begin(), _tally_score.end(), score) != _tally_score.end();
201  }
202 
207  bool renamesTallyVars() const { return _renames_tally_vars; }
208 
213  unsigned int numExtFilterBins() const { return _num_ext_filter_bins; }
214 
215 protected:
228  virtual Real storeResultsInner(const std::vector<unsigned int> & var_numbers,
229  unsigned int local_score,
230  unsigned int global_score,
231  std::vector<xt::xtensor<double, 1>> tally_vals,
232  bool norm_by_src_rate = true) = 0;
233 
240  void fillElementalAuxVariable(const unsigned int & var_num,
241  const std::vector<unsigned int> & elem_ids,
242  const Real & value);
243 
248  void applyTriggersToLocalTally(openmc::Tally * tally);
249 
252 
254  MooseMesh & _mesh;
255 
257  AuxiliarySystem & _aux;
258 
260  std::vector<std::shared_ptr<FilterBase>> _ext_filters;
261 
263  openmc::TallyEstimator _estimator;
264 
266  std::vector<std::string> _tally_score;
267 
269  std::vector<std::string> _tally_name;
270 
272  openmc::Tally * _local_tally = nullptr;
273 
275  unsigned int _local_tally_index;
276 
278  unsigned int _filter_index;
279 
281  unsigned int _num_ext_filter_bins = 1;
282 
284  std::vector<Real> _local_sum_tally;
285 
290  std::vector<Real> _local_mean_tally;
291 
298  const MultiMooseEnum * _tally_trigger;
299 
304  std::vector<Real> _tally_trigger_threshold;
305 
310  std::vector<bool> _trigger_ignore_zeros;
311 
320  std::vector<xt::xtensor<double, 1>> _current_tally;
321 
323  std::vector<xt::xtensor<double, 1>> _previous_tally;
324 
326  std::vector<xt::xtensor<double, 1>> _current_raw_tally;
327 
329  std::vector<xt::xtensor<double, 1>> _current_raw_tally_rel_error;
330 
332  std::vector<xt::xtensor<double, 1>> _current_raw_tally_std_dev;
333 
336 
338  const bool _has_outputs;
339 
341  std::vector<std::string> _output_name;
342 
344  const bool _is_adaptive;
345 
347  std::vector<bool> _ext_bins_to_skip;
348 
350  static constexpr Real ZERO_TALLY_THRESHOLD = 1e-12;
351 };
const std::vector< std::string > & getOutputs() const
Definition: TallyBase.h:145
void fillElementalAuxVariable(const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
virtual Real storeResultsInner(const std::vector< unsigned int > &var_numbers, unsigned int local_score, unsigned int global_score, std::vector< xt::xtensor< double, 1 >> tally_vals, bool norm_by_src_rate=true)=0
virtual void initializeTally()
std::vector< xt::xtensor< double, 1 > > _current_tally
Definition: TallyBase.h:320
const Real & getMean(unsigned int local_score) const
Definition: TallyBase.h:158
std::vector< xt::xtensor< double, 1 > > _previous_tally
Previous fixed point iteration tally result (after relaxation)
Definition: TallyBase.h:323
Real storeResults(const std::vector< unsigned int > &var_numbers, unsigned int local_score, unsigned int global_score, const std::string &output_type)
std::vector< std::string > getScoreVars(const std::string &score) const
openmc::TallyEstimator _estimator
The OpenMC estimator to use with this tally.
Definition: TallyBase.h:263
void applyTriggersToLocalTally(openmc::Tally *tally)
static constexpr Real ZERO_TALLY_THRESHOLD
Tolerance for setting zero tally.
Definition: TallyBase.h:350
bool extBinSkipped(unsigned int ext_bin) const
Definition: TallyBase.h:179
std::vector< std::string > _tally_name
Auxiliary variable name(s) for this tally.
Definition: TallyBase.h:269
const MultiMooseEnum * _tally_trigger
Definition: TallyBase.h:298
Definition: OpenMCCellAverageProblem.h:66
virtual void resetTally()
std::vector< Real > _local_mean_tally
Definition: TallyBase.h:290
std::vector< Real > _tally_trigger_threshold
Definition: TallyBase.h:304
const bool _has_outputs
Whether this tally has additional outputs or not.
Definition: TallyBase.h:338
static InputParameters validParams()
unsigned int _num_ext_filter_bins
The number of non-spatial bins in this tally.
Definition: TallyBase.h:281
std::vector< std::string > _output_name
Suffixes to apply to 'tally_name' in order to name the fields in the 'output'.
Definition: TallyBase.h:341
TallyBase(const InputParameters &parameters)
std::vector< std::string > _tally_score
OpenMC tally score(s) to use with this tally.
Definition: TallyBase.h:266
unsigned int _filter_index
The index of the first filter added by this tally.
Definition: TallyBase.h:278
std::vector< xt::xtensor< double, 1 > > _current_raw_tally
Current "raw" tally output from Monte Carlo solution.
Definition: TallyBase.h:326
OpenMCCellAverageProblem & _openmc_problem
The OpenMCCellAverageProblem using the tally system.
Definition: TallyBase.h:251
const bool _renames_tally_vars
Whether this tally stores results in variables names something other than '_tally_score'.
Definition: TallyBase.h:335
Definition: TallyBase.h:33
void addScore(const std::string &score)
const Real & getSum(unsigned int local_score) const
Definition: TallyBase.h:165
MooseMesh & _mesh
The MooseMesh.
Definition: TallyBase.h:254
int scoreIndex(const std::string &score) const
unsigned int numExtFilterBins() const
Definition: TallyBase.h:213
bool renamesTallyVars() const
Definition: TallyBase.h:207
Definition: FilterBase.h:40
int32_t getTallyID() const
std::vector< Real > _local_sum_tally
Sum value of this tally across all bins. Indexed by score.
Definition: TallyBase.h:284
const bool _is_adaptive
Whether the problem uses adaptive mesh refinement or not.
Definition: TallyBase.h:344
void computeSumAndMean()
openmc::TallyEstimator getTallyEstimator() const
Definition: TallyBase.h:151
const openmc::Tally * getWrappedTally() const
virtual std::pair< unsigned int, openmc::Filter * > spatialFilter()=0
openmc::Tally * _local_tally
The OpenMC tally object this class wraps.
Definition: TallyBase.h:272
bool hasOutputs() const
Definition: TallyBase.h:191
std::vector< xt::xtensor< double, 1 > > _current_raw_tally_rel_error
Current "raw" tally relative error.
Definition: TallyBase.h:329
unsigned int _local_tally_index
The index of the OpenMC tally this object wraps.
Definition: TallyBase.h:275
Definition: CardinalEnums.h:156
void relaxAndNormalizeTally(unsigned int local_score, const Real &alpha, const Real &norm)
bool hasTrigger() const
Definition: TallyBase.h:185
std::vector< xt::xtensor< double, 1 > > _current_raw_tally_std_dev
Current "raw" tally standard deviation.
Definition: TallyBase.h:332
AuxiliarySystem & _aux
The aux system.
Definition: TallyBase.h:257
std::vector< bool > _trigger_ignore_zeros
Definition: TallyBase.h:310
const std::vector< std::string > & getScores() const
Definition: TallyBase.h:123
const std::vector< std::string > & getAuxVarNames() const
Definition: TallyBase.h:138
bool hasScore(const std::string &score) const
Definition: TallyBase.h:198
std::vector< bool > _ext_bins_to_skip
External filter bins to skip while computing the tally sum and mean for normalization.
Definition: TallyBase.h:347
std::vector< std::shared_ptr< FilterBase > > _ext_filters
The external filters added in the [Problem/Filters] block.
Definition: TallyBase.h:260