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 
118  const std::vector<std::string> & getScores() const { return _tally_score; }
119 
126  const std::vector<std::string> & getAuxVarNames() const { return _tally_name; }
127 
133  const std::vector<std::string> & getOutputs() const { return _output_name; }
134 
139  openmc::TallyEstimator getTallyEstimator() const { return _estimator; }
140 
146  const Real & getMean(unsigned int local_score) const { return _local_mean_tally[local_score]; }
147 
153  const Real & getSum(unsigned int local_score) const { return _local_sum_tally[local_score]; }
154 
159  bool hasTrigger() const { return _tally_trigger != nullptr; }
160 
165  bool hasOutputs() const { return _has_outputs; }
166 
171  bool renamesTallyVars() const { return _renames_tally_vars; }
172 
177  unsigned int numExtFilterBins() const { return _num_ext_filter_bins; }
178 
179 protected:
191  virtual Real storeResultsInner(const std::vector<unsigned int> & var_numbers,
192  unsigned int local_score,
193  unsigned int global_score,
194  std::vector<xt::xtensor<double, 1>> tally_vals) = 0;
195 
202  void fillElementalAuxVariable(const unsigned int & var_num,
203  const std::vector<unsigned int> & elem_ids,
204  const Real & value);
205 
210  void applyTriggersToLocalTally(openmc::Tally * tally);
211 
214 
216  MooseMesh & _mesh;
217 
219  AuxiliarySystem & _aux;
220 
222  std::vector<std::shared_ptr<FilterBase>> _ext_filters;
223 
225  openmc::TallyEstimator _estimator;
226 
228  std::vector<std::string> _tally_score;
229 
231  std::vector<std::string> _tally_name;
232 
234  openmc::Tally * _local_tally = nullptr;
235 
237  unsigned int _local_tally_index;
238 
240  unsigned int _filter_index;
241 
243  unsigned int _num_ext_filter_bins = 1;
244 
246  std::vector<Real> _local_sum_tally;
247 
252  std::vector<Real> _local_mean_tally;
253 
260  const MultiMooseEnum * _tally_trigger;
261 
266  std::vector<Real> _tally_trigger_threshold;
267 
272  std::vector<bool> _trigger_ignore_zeros;
273 
282  std::vector<xt::xtensor<double, 1>> _current_tally;
283 
285  std::vector<xt::xtensor<double, 1>> _previous_tally;
286 
288  std::vector<xt::xtensor<double, 1>> _current_raw_tally;
289 
291  std::vector<xt::xtensor<double, 1>> _current_raw_tally_std_dev;
292 
295 
297  const bool _has_outputs;
298 
300  std::vector<std::string> _output_name;
301 
303  static constexpr Real ZERO_TALLY_THRESHOLD = 1e-12;
304 };
const std::vector< std::string > & getOutputs() const
Definition: TallyBase.h:133
void fillElementalAuxVariable(const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
virtual void initializeTally()
std::vector< xt::xtensor< double, 1 > > _current_tally
Definition: TallyBase.h:282
const Real & getMean(unsigned int local_score) const
Definition: TallyBase.h:146
std::vector< xt::xtensor< double, 1 > > _previous_tally
Previous fixed point iteration tally result (after relaxation)
Definition: TallyBase.h:285
Real storeResults(const std::vector< unsigned int > &var_numbers, unsigned int local_score, unsigned int global_score, const std::string &output_type)
openmc::TallyEstimator _estimator
The OpenMC estimator to use with this tally.
Definition: TallyBase.h:225
void applyTriggersToLocalTally(openmc::Tally *tally)
static constexpr Real ZERO_TALLY_THRESHOLD
Tolerance for setting zero tally.
Definition: TallyBase.h:303
std::vector< std::string > _tally_name
Auxiliary variable name(s) for this tally.
Definition: TallyBase.h:231
const MultiMooseEnum * _tally_trigger
Definition: TallyBase.h:260
Tally/filter includes.
Definition: OpenMCCellAverageProblem.h:64
virtual void resetTally()
std::vector< Real > _local_mean_tally
Definition: TallyBase.h:252
std::vector< Real > _tally_trigger_threshold
Definition: TallyBase.h:266
const bool _has_outputs
Whether this tally has additional outputs or not.
Definition: TallyBase.h:297
static InputParameters validParams()
unsigned int _num_ext_filter_bins
The number of non-spatial bins in this tally.
Definition: TallyBase.h:243
std::vector< std::string > _output_name
Suffixes to apply to 'tally_name' in order to name the fields in the 'output'.
Definition: TallyBase.h:300
TallyBase(const InputParameters &parameters)
std::vector< std::string > _tally_score
OpenMC tally score(s) to use with this tally.
Definition: TallyBase.h:228
unsigned int _filter_index
The index of the first filter added by this tally.
Definition: TallyBase.h:240
std::vector< xt::xtensor< double, 1 > > _current_raw_tally
Current "raw" tally output from Monte Carlo solution.
Definition: TallyBase.h:288
OpenMCCellAverageProblem & _openmc_problem
The OpenMCCellAverageProblem using the tally system.
Definition: TallyBase.h:213
const bool _renames_tally_vars
Whether this tally stores results in variables names something other than '_tally_score'.
Definition: TallyBase.h:294
Definition: TallyBase.h:33
void addScore(const std::string &score)
const Real & getSum(unsigned int local_score) const
Definition: TallyBase.h:153
MooseMesh & _mesh
The MooseMesh.
Definition: TallyBase.h:216
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)=0
unsigned int numExtFilterBins() const
Definition: TallyBase.h:177
bool renamesTallyVars() const
Definition: TallyBase.h:171
Definition: FilterBase.h:40
std::vector< Real > _local_sum_tally
Sum value of this tally across all bins. Indexed by score.
Definition: TallyBase.h:246
void computeSumAndMean()
openmc::TallyEstimator getTallyEstimator() const
Definition: TallyBase.h:139
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:234
bool hasOutputs() const
Definition: TallyBase.h:165
unsigned int _local_tally_index
The index of the OpenMC tally this object wraps.
Definition: TallyBase.h:237
Definition: CardinalEnums.h:129
void relaxAndNormalizeTally(unsigned int local_score, const Real &alpha, const Real &norm)
bool hasTrigger() const
Definition: TallyBase.h:159
std::vector< xt::xtensor< double, 1 > > _current_raw_tally_std_dev
Current "raw" tally standard deviation.
Definition: TallyBase.h:291
AuxiliarySystem & _aux
The aux system.
Definition: TallyBase.h:219
std::vector< bool > _trigger_ignore_zeros
Definition: TallyBase.h:272
const std::vector< std::string > & getScores() const
Definition: TallyBase.h:118
const std::vector< std::string > & getAuxVarNames() const
Definition: TallyBase.h:126
std::vector< std::shared_ptr< FilterBase > > _ext_filters
The external filters added in the [Problem/Filters] block.
Definition: TallyBase.h:222