Cardinal
Loading...
Searching...
No Matches
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
29class MooseMesh;
30class AuxiliarySystem;
31class FilterBase;
32
33typedef openmc::tensor::Tensor<double> OMCTensor;
34
35class TallyBase : public MooseObject
36{
37public:
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 virtual void setRelaxation(relaxation::RelaxationEnum relaxation_type,
85 const Real & relaxation_factor);
86
92
96 virtual void gatherLinkedSum();
97
102
121
126 void addLinkedTally(const TallyBase * other);
127
132 const openmc::Tally * getWrappedTally() const;
133
138 const openmc::Tally * getWrappedGlobalTally() const;
139
143 int32_t getTallyID() const;
144
148 int32_t getGlobalTallyID() const;
149
154 const std::vector<std::string> & getScores() const { return _tally_score; }
155
161 int scoreIndex(const std::string & score) const;
162
169 const std::vector<std::string> & getAuxVarNames() const { return _tally_name; }
170
176 const std::vector<std::string> & getOutputs() const { return _output_name; }
177
182 openmc::TallyEstimator getTallyEstimator() const { return _estimator; }
183
189 const Real & getMean(unsigned int local_score) const { return _local_mean_tally[local_score]; }
190
196 const Real & getSum(unsigned int local_score) const { return _local_sum_tally[local_score]; }
197
203 std::vector<std::string> getScoreVars(const std::string & score) const;
204
210 bool extBinSkipped(unsigned int ext_bin) const { return _ext_bins_to_skip[ext_bin]; }
211
216 bool hasTrigger() const { return _tally_trigger != nullptr; }
217
222 bool hasOutputs() const { return _has_outputs; }
223
229 bool hasScore(const std::string & score) const
230 {
231 return std::find(_tally_score.begin(), _tally_score.end(), score) != _tally_score.end();
232 }
233
238 bool renamesTallyVars() const { return _renames_tally_vars; }
239
244 unsigned int numExtFilterBins() const { return _num_ext_filter_bins; }
245
250 const std::set<SubdomainID> & getBlocks() const { return _tally_blocks; }
251
256 virtual bool addingGlobalTally() const { return _needs_global_tally; }
257
262 const std::vector<const TallyBase *> & linkedTallies() const { return _linked_tallies; }
263
264protected:
275 virtual Real storeResultsInner(const std::vector<unsigned int> & var_numbers,
276 unsigned int local_score,
277 const std::vector<OMCTensor> & tally_vals,
278 bool norm_by_src_rate = true) = 0;
279
286 void fillElementalAuxVariable(const unsigned int & var_num,
287 const std::vector<unsigned int> & elem_ids,
288 const Real & value);
289
294 void applyTriggersToLocalTally(openmc::Tally * tally);
295
301 Real tallyNormalization(unsigned int score) const;
302
307 void checkTallySum(const unsigned int & score) const;
308
315 void checkNormalization(const Real & sum, unsigned int score) const;
316
319
321 MooseMesh & _mesh;
322
324 AuxiliarySystem & _aux;
325
327 std::vector<std::shared_ptr<FilterBase>> _ext_filters;
328
330 openmc::TallyEstimator _estimator;
331
333 std::vector<std::string> _tally_score;
334
336 std::vector<std::string> _tally_name;
337
339 openmc::Tally * _local_tally = nullptr;
340
342 unsigned int _local_tally_index;
343
348 openmc::Tally * _global_tally = nullptr;
349
352
354 unsigned int _filter_index;
355
357 unsigned int _num_ext_filter_bins = 1;
358
360 std::vector<Real> _local_sum_tally;
361
367 std::vector<Real> _global_sum_tally;
368
375 std::vector<Real> _local_mean_tally;
376
378 std::vector<Real> _linked_local_sum_tally;
379
386 const MultiMooseEnum * _tally_trigger;
387
392 std::vector<Real> _tally_trigger_threshold;
393
398 std::vector<bool> _trigger_ignore_zeros;
399
408 std::vector<OMCTensor> _current_tally;
409
411 std::vector<OMCTensor> _previous_tally;
412
414 std::vector<OMCTensor> _current_raw_tally;
415
417 std::vector<OMCTensor> _current_raw_tally_rel_error;
418
420 std::vector<OMCTensor> _current_raw_tally_std_dev;
421
442
457
459 const Real & _tally_sum_tol;
460
466
469
471 const bool _has_outputs;
472
474 std::vector<std::string> _output_name;
475
477 const bool _is_adaptive;
478
480 std::vector<bool> _ext_bins_to_skip;
481
483 std::set<SubdomainID> _tally_blocks;
484
486 std::vector<const TallyBase *> _linked_tallies;
487
490
493
495 static constexpr Real ZERO_TALLY_THRESHOLD = 1e-12;
496};
openmc::tensor::Tensor< double > OMCTensor
Definition TallyBase.h:33
Definition FilterBase.h:41
Definition OpenMCCellAverageProblem.h:68
Definition TallyBase.h:36
unsigned int _global_tally_index
The index of the global OpenMC tally this object wraps.
Definition TallyBase.h:351
Real tallyNormalization(unsigned int score) const
unsigned int _local_tally_index
The index of the OpenMC tally this object wraps.
Definition TallyBase.h:342
std::vector< std::shared_ptr< FilterBase > > _ext_filters
The external filters added in the [Problem/Filters] block.
Definition TallyBase.h:327
const bool _check_tally_sum
Definition TallyBase.h:456
int scoreIndex(const std::string &score) const
const std::vector< const TallyBase * > & linkedTallies() const
Definition TallyBase.h:262
const std::vector< std::string > & getAuxVarNames() const
Definition TallyBase.h:169
const bool _is_adaptive
Whether the problem uses adaptive mesh refinement or not.
Definition TallyBase.h:477
const Real & _tally_sum_tol
Relative tolerance for erroring on local vs. global conservation of the tally.
Definition TallyBase.h:459
unsigned int numExtFilterBins() const
Definition TallyBase.h:244
openmc::TallyEstimator getTallyEstimator() const
Definition TallyBase.h:182
const bool _has_outputs
Whether this tally has additional outputs or not.
Definition TallyBase.h:471
const bool _renames_tally_vars
Whether this tally stores results in variables names something other than '_tally_score'.
Definition TallyBase.h:468
std::vector< Real > _global_sum_tally
Definition TallyBase.h:367
virtual void renormalizeLinkedTallies()
const bool _needs_global_tally
Definition TallyBase.h:465
bool hasOutputs() const
Definition TallyBase.h:222
int32_t getGlobalTallyID() const
std::vector< const TallyBase * > _linked_tallies
Other tallies linked for normalization.
Definition TallyBase.h:486
std::vector< Real > _local_sum_tally
Sum value of this tally across all bins. Indexed by score.
Definition TallyBase.h:360
bool renamesTallyVars() const
Definition TallyBase.h:238
const openmc::Tally * getWrappedTally() const
std::vector< Real > _tally_trigger_threshold
Definition TallyBase.h:392
const std::vector< std::string > & getOutputs() const
Definition TallyBase.h:176
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
openmc::Tally * _local_tally
The OpenMC tally object this class wraps.
Definition TallyBase.h:339
const MultiMooseEnum * _tally_trigger
Definition TallyBase.h:386
virtual void setRelaxation(relaxation::RelaxationEnum relaxation_type, const Real &relaxation_factor)
unsigned int _filter_index
The index of the first filter added by this tally.
Definition TallyBase.h:354
virtual std::pair< unsigned int, openmc::Filter * > spatialFilter()=0
std::vector< Real > _local_mean_tally
Definition TallyBase.h:375
bool extBinSkipped(unsigned int ext_bin) const
Definition TallyBase.h:210
const std::vector< std::string > & getScores() const
Definition TallyBase.h:154
static InputParameters validParams()
unsigned int _num_ext_filter_bins
The number of non-spatial bins in this tally.
Definition TallyBase.h:357
std::vector< OMCTensor > _current_raw_tally_rel_error
Current "raw" tally relative error.
Definition TallyBase.h:417
Real storeResults(const std::vector< unsigned int > &var_numbers, unsigned int local_score, const std::string &output_type)
const Real & getMean(unsigned int local_score) const
Definition TallyBase.h:189
std::vector< OMCTensor > _current_raw_tally_std_dev
Current "raw" tally standard deviation.
Definition TallyBase.h:420
void checkNormalization(const Real &sum, unsigned int score) const
void fillElementalAuxVariable(const unsigned int &var_num, const std::vector< unsigned int > &elem_ids, const Real &value)
virtual bool addingGlobalTally() const
Definition TallyBase.h:256
Real _relaxation_factor
The relaxation factor this tally should use (for constant relaxation).
Definition TallyBase.h:492
void computeSumAndMean()
relaxation::RelaxationEnum _relaxation_type
The type of relaxation this tally should employ.
Definition TallyBase.h:489
std::vector< bool > _ext_bins_to_skip
External filter bins to skip while computing the tally sum and mean for normalization.
Definition TallyBase.h:480
bool hasTrigger() const
Definition TallyBase.h:216
const Real & getSum(unsigned int local_score) const
Definition TallyBase.h:196
void checkTallySum(const unsigned int &score) const
int32_t getTallyID() const
openmc::Tally * _global_tally
Definition TallyBase.h:348
OpenMCCellAverageProblem & _openmc_problem
The OpenMCCellAverageProblem using the tally system.
Definition TallyBase.h:318
AuxiliarySystem & _aux
The aux system.
Definition TallyBase.h:324
virtual void resetTally()
std::vector< Real > _linked_local_sum_tally
Linked sum value across all bins. Indexed by score.
Definition TallyBase.h:378
std::vector< bool > _trigger_ignore_zeros
Definition TallyBase.h:398
std::vector< OMCTensor > _current_raw_tally
Current "raw" tally output from Monte Carlo solution.
Definition TallyBase.h:414
std::set< SubdomainID > _tally_blocks
Blocks for which to add tallies.
Definition TallyBase.h:483
std::vector< std::string > _tally_name
Auxiliary variable name(s) for this tally.
Definition TallyBase.h:336
std::vector< std::string > _output_name
Suffixes to apply to 'tally_name' in order to name the fields in the 'output'.
Definition TallyBase.h:474
const openmc::Tally * getWrappedGlobalTally() const
static constexpr Real ZERO_TALLY_THRESHOLD
Tolerance for setting zero tally.
Definition TallyBase.h:495
void applyTriggersToLocalTally(openmc::Tally *tally)
std::vector< std::string > _tally_score
OpenMC tally score(s) to use with this tally.
Definition TallyBase.h:333
std::vector< OMCTensor > _current_tally
Definition TallyBase.h:408
openmc::TallyEstimator _estimator
The OpenMC estimator to use with this tally.
Definition TallyBase.h:330
void addScore(const std::string &score)
void addLinkedTally(const TallyBase *other)
const std::set< SubdomainID > & getBlocks() const
Definition TallyBase.h:250
TallyBase(const InputParameters &parameters)
void relaxAndNormalizeTally()
const bool _normalize_by_global
Definition TallyBase.h:441
virtual void gatherLinkedSum()
std::vector< std::string > getScoreVars(const std::string &score) const
virtual void initializeTally()
std::vector< OMCTensor > _previous_tally
Previous fixed point iteration tally result (after relaxation)
Definition TallyBase.h:411
MooseMesh & _mesh
The MooseMesh.
Definition TallyBase.h:321
bool hasScore(const std::string &score) const
Definition TallyBase.h:229
RelaxationEnum
Type of relaxation.
Definition CardinalEnums.h:275
Definition CardinalEnums.h:159