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 "openmc/tensor.h"
26 
29 class MooseMesh;
30 class AuxiliarySystem;
31 class FilterBase;
32 
33 typedef openmc::tensor::Tensor<double> OMCTensor;
34 
35 class TallyBase : public MooseObject
36 {
37 public:
38  static InputParameters validParams();
39 
40  TallyBase(const InputParameters & parameters);
41 
48  virtual std::pair<unsigned int, openmc::Filter *> spatialFilter() = 0;
49 
53  virtual void initializeTally();
54 
58  virtual void resetTally();
59 
69  Real storeResults(const std::vector<unsigned int> & var_numbers,
70  unsigned int local_score,
71  const std::string & output_type);
72 
77  void addScore(const std::string & score);
78 
84  void setRelaxation(relaxation::RelaxationEnum relaxation_type, const Real & relaxation_factor);
85 
90  void computeSumAndMean();
91 
95  virtual void gatherLinkedSum();
96 
100  virtual void renormalizeLinkedTallies();
101 
119  void relaxAndNormalizeTally();
120 
125  void addLinkedTally(const TallyBase * other);
126 
131  const openmc::Tally * getWrappedTally() const;
132 
137  const openmc::Tally * getWrappedGlobalTally() const;
138 
142  int32_t getTallyID() const;
143 
147  int32_t getGlobalTallyID() const;
148 
153  const std::vector<std::string> & getScores() const { return _tally_score; }
154 
160  int scoreIndex(const std::string & score) const;
161 
168  const std::vector<std::string> & getAuxVarNames() const { return _tally_name; }
169 
175  const std::vector<std::string> & getOutputs() const { return _output_name; }
176 
181  openmc::TallyEstimator getTallyEstimator() const { return _estimator; }
182 
188  const Real & getMean(unsigned int local_score) const { return _local_mean_tally[local_score]; }
189 
195  const Real & getSum(unsigned int local_score) const { return _local_sum_tally[local_score]; }
196 
202  std::vector<std::string> getScoreVars(const std::string & score) const;
203 
209  bool extBinSkipped(unsigned int ext_bin) const { return _ext_bins_to_skip[ext_bin]; }
210 
215  bool hasTrigger() const { return _tally_trigger != nullptr; }
216 
221  bool hasOutputs() const { return _has_outputs; }
222 
228  bool hasScore(const std::string & score) const
229  {
230  return std::find(_tally_score.begin(), _tally_score.end(), score) != _tally_score.end();
231  }
232 
237  bool renamesTallyVars() const { return _renames_tally_vars; }
238 
243  unsigned int numExtFilterBins() const { return _num_ext_filter_bins; }
244 
249  const std::set<SubdomainID> & getBlocks() const { return _tally_blocks; }
250 
255  virtual bool addingGlobalTally() const { return _needs_global_tally; }
256 
261  const std::vector<const TallyBase *> & linkedTallies() const { return _linked_tallies; }
262 
263 protected:
274  virtual Real storeResultsInner(const std::vector<unsigned int> & var_numbers,
275  unsigned int local_score,
276  const std::vector<OMCTensor> & tally_vals,
277  bool norm_by_src_rate = true) = 0;
278 
285  void fillElementalAuxVariable(const unsigned int & var_num,
286  const std::vector<unsigned int> & elem_ids,
287  const Real & value);
288 
293  void applyTriggersToLocalTally(openmc::Tally * tally);
294 
300  Real tallyNormalization(unsigned int score) const;
301 
306  void checkTallySum(const unsigned int & score) const;
307 
314  void checkNormalization(const Real & sum, unsigned int score) const;
315 
318 
320  MooseMesh & _mesh;
321 
323  AuxiliarySystem & _aux;
324 
326  std::vector<std::shared_ptr<FilterBase>> _ext_filters;
327 
329  openmc::TallyEstimator _estimator;
330 
332  std::vector<std::string> _tally_score;
333 
335  std::vector<std::string> _tally_name;
336 
338  openmc::Tally * _local_tally = nullptr;
339 
341  unsigned int _local_tally_index;
342 
347  openmc::Tally * _global_tally = nullptr;
348 
350  unsigned int _global_tally_index;
351 
353  unsigned int _filter_index;
354 
356  unsigned int _num_ext_filter_bins = 1;
357 
359  std::vector<Real> _local_sum_tally;
360 
366  std::vector<Real> _global_sum_tally;
367 
374  std::vector<Real> _local_mean_tally;
375 
377  std::vector<Real> _linked_local_sum_tally;
378 
385  const MultiMooseEnum * _tally_trigger;
386 
391  std::vector<Real> _tally_trigger_threshold;
392 
397  std::vector<bool> _trigger_ignore_zeros;
398 
407  std::vector<OMCTensor> _current_tally;
408 
410  std::vector<OMCTensor> _previous_tally;
411 
413  std::vector<OMCTensor> _current_raw_tally;
414 
416  std::vector<OMCTensor> _current_raw_tally_rel_error;
417 
419  std::vector<OMCTensor> _current_raw_tally_std_dev;
420 
441 
455  const bool _check_tally_sum;
456 
462 
465 
467  const bool _has_outputs;
468 
470  std::vector<std::string> _output_name;
471 
473  const bool _is_adaptive;
474 
476  std::vector<bool> _ext_bins_to_skip;
477 
479  std::set<SubdomainID> _tally_blocks;
480 
482  std::vector<const TallyBase *> _linked_tallies;
483 
486 
489 
491  static constexpr Real ZERO_TALLY_THRESHOLD = 1e-12;
492 };
const std::set< SubdomainID > & getBlocks() const
Definition: TallyBase.h:249
const std::vector< std::string > & getOutputs() const
Definition: TallyBase.h:175
Real tallyNormalization(unsigned int score) const
openmc::tensor::Tensor< double > OMCTensor
Definition: TallyBase.h:31
std::vector< OMCTensor > _current_raw_tally_rel_error
Current "raw" tally relative error.
Definition: TallyBase.h:416
void fillElementalAuxVariable(const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
virtual void initializeTally()
std::vector< OMCTensor > _previous_tally
Previous fixed point iteration tally result (after relaxation)
Definition: TallyBase.h:410
const Real & getMean(unsigned int local_score) const
Definition: TallyBase.h:188
std::vector< std::string > getScoreVars(const std::string &score) const
openmc::TallyEstimator _estimator
The OpenMC estimator to use with this tally.
Definition: TallyBase.h:329
void applyTriggersToLocalTally(openmc::Tally *tally)
relaxation::RelaxationEnum _relaxation_type
The type of relaxation this tally should employ.
Definition: TallyBase.h:485
static constexpr Real ZERO_TALLY_THRESHOLD
Tolerance for setting zero tally.
Definition: TallyBase.h:491
bool extBinSkipped(unsigned int ext_bin) const
Definition: TallyBase.h:209
std::vector< std::string > _tally_name
Auxiliary variable name(s) for this tally.
Definition: TallyBase.h:335
const bool _normalize_by_global
Definition: TallyBase.h:440
const MultiMooseEnum * _tally_trigger
Definition: TallyBase.h:385
Definition: OpenMCCellAverageProblem.h:66
const bool _check_tally_sum
Definition: TallyBase.h:455
virtual void resetTally()
std::vector< Real > _local_mean_tally
Definition: TallyBase.h:374
std::vector< Real > _tally_trigger_threshold
Definition: TallyBase.h:391
const bool _has_outputs
Whether this tally has additional outputs or not.
Definition: TallyBase.h:467
static InputParameters validParams()
std::vector< OMCTensor > _current_raw_tally_std_dev
Current "raw" tally standard deviation.
Definition: TallyBase.h:419
const std::vector< const TallyBase * > & linkedTallies() const
Definition: TallyBase.h:261
const openmc::Tally * getWrappedGlobalTally() const
unsigned int _num_ext_filter_bins
The number of non-spatial bins in this tally.
Definition: TallyBase.h:356
std::vector< std::string > _output_name
Suffixes to apply to 'tally_name' in order to name the fields in the 'output'.
Definition: TallyBase.h:470
Real _relaxation_factor
The relaxation factor this tally should use (for constant relaxation).
Definition: TallyBase.h:488
TallyBase(const InputParameters &parameters)
std::vector< std::string > _tally_score
OpenMC tally score(s) to use with this tally.
Definition: TallyBase.h:332
unsigned int _filter_index
The index of the first filter added by this tally.
Definition: TallyBase.h:353
RelaxationEnum
Type of relaxation.
Definition: CardinalEnums.h:273
virtual void renormalizeLinkedTallies()
std::vector< Real > _linked_local_sum_tally
Linked sum value across all bins. Indexed by score.
Definition: TallyBase.h:377
OpenMCCellAverageProblem & _openmc_problem
The OpenMCCellAverageProblem using the tally system.
Definition: TallyBase.h:317
const bool _renames_tally_vars
Whether this tally stores results in variables names something other than '_tally_score'.
Definition: TallyBase.h:464
Definition: TallyBase.h:35
virtual bool addingGlobalTally() const
Definition: TallyBase.h:255
void addScore(const std::string &score)
std::vector< OMCTensor > _current_raw_tally
Current "raw" tally output from Monte Carlo solution.
Definition: TallyBase.h:413
openmc::Tally * _global_tally
Definition: TallyBase.h:347
void relaxAndNormalizeTally()
void setRelaxation(relaxation::RelaxationEnum relaxation_type, const Real &relaxation_factor)
const Real & getSum(unsigned int local_score) const
Definition: TallyBase.h:195
virtual Real storeResultsInner(const std::vector< unsigned int > &var_numbers, unsigned int local_score, const std::vector< OMCTensor > &tally_vals, bool norm_by_src_rate=true)=0
MooseMesh & _mesh
The MooseMesh.
Definition: TallyBase.h:320
int scoreIndex(const std::string &score) const
unsigned int numExtFilterBins() const
Definition: TallyBase.h:243
void checkNormalization(const Real &sum, unsigned int score) const
bool renamesTallyVars() const
Definition: TallyBase.h:237
void addLinkedTally(const TallyBase *other)
const bool _needs_global_tally
Definition: TallyBase.h:461
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:359
unsigned int _global_tally_index
The index of the global OpenMC tally this object wraps.
Definition: TallyBase.h:350
const bool _is_adaptive
Whether the problem uses adaptive mesh refinement or not.
Definition: TallyBase.h:473
void computeSumAndMean()
std::vector< OMCTensor > _current_tally
Definition: TallyBase.h:407
openmc::TallyEstimator getTallyEstimator() const
Definition: TallyBase.h:181
std::set< SubdomainID > _tally_blocks
Blocks for which to add tallies.
Definition: TallyBase.h:479
void checkTallySum(const unsigned int &score) const
const openmc::Tally * getWrappedTally() const
std::vector< Real > _global_sum_tally
Definition: TallyBase.h:366
virtual std::pair< unsigned int, openmc::Filter * > spatialFilter()=0
Real storeResults(const std::vector< unsigned int > &var_numbers, unsigned int local_score, const std::string &output_type)
int32_t getGlobalTallyID() const
openmc::Tally * _local_tally
The OpenMC tally object this class wraps.
Definition: TallyBase.h:338
bool hasOutputs() const
Definition: TallyBase.h:221
unsigned int _local_tally_index
The index of the OpenMC tally this object wraps.
Definition: TallyBase.h:341
Definition: CardinalEnums.h:157
std::vector< const TallyBase * > _linked_tallies
Other tallies linked for normalization.
Definition: TallyBase.h:482
bool hasTrigger() const
Definition: TallyBase.h:215
AuxiliarySystem & _aux
The aux system.
Definition: TallyBase.h:323
std::vector< bool > _trigger_ignore_zeros
Definition: TallyBase.h:397
const std::vector< std::string > & getScores() const
Definition: TallyBase.h:153
const std::vector< std::string > & getAuxVarNames() const
Definition: TallyBase.h:168
bool hasScore(const std::string &score) const
Definition: TallyBase.h:228
virtual void gatherLinkedSum()
std::vector< bool > _ext_bins_to_skip
External filter bins to skip while computing the tally sum and mean for normalization.
Definition: TallyBase.h:476
std::vector< std::shared_ptr< FilterBase > > _ext_filters
The external filters added in the [Problem/Filters] block.
Definition: TallyBase.h:326