https://mooseframework.inl.gov
StatisticsReporter.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "GeneralReporter.h"
13 #include "VectorCalculators.h"
14 
15 #include "nlohmann/json.h"
16 
20 template <typename InType, typename OutType>
22  : public ReporterGeneralContext<std::pair<OutType, std::vector<OutType>>>
23 {
24 public:
26  const MooseObject & producer,
27  ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
28  const InType & data,
29  const ReporterProducerEnum & mode,
30  const MooseEnumItem & stat);
31 
33  const MooseObject & producer,
34  ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
35  const InType & data,
36  const ReporterProducerEnum & mode,
37  const MooseEnumItem & stat,
38  const MooseEnum & ci_method,
39  const std::vector<Real> & ci_levels,
40  unsigned int ci_replicates,
41  unsigned int ci_seed);
42 
43  virtual void finalize() override;
44  virtual void storeInfo(nlohmann::json & json) const override;
45 
46 private:
48  const InType & _data;
49 
52 
54  std::unique_ptr<StochasticTools::Calculator<InType, OutType>> _calc_ptr;
55 
57  std::unique_ptr<StochasticTools::BootstrapCalculator<InType, OutType>> _ci_calc_ptr = nullptr;
58 };
59 
60 template <typename InType, typename OutType>
62  const libMesh::ParallelObject & other,
63  const MooseObject & producer,
64  ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
65  const InType & data,
66  const ReporterProducerEnum & mode,
67  const MooseEnumItem & stat)
68  : ReporterGeneralContext<std::pair<OutType, std::vector<OutType>>>(other, producer, state),
69  _data(data),
70  _data_mode(mode),
71  _calc_ptr(StochasticTools::makeCalculator<InType, OutType>(stat, other))
72 {
73 }
74 
75 template <typename InType, typename OutType>
77  const libMesh::ParallelObject & other,
78  const MooseObject & producer,
79  ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
80  const InType & data,
81  const ReporterProducerEnum & mode,
82  const MooseEnumItem & stat,
83  const MooseEnum & ci_method,
84  const std::vector<Real> & ci_levels,
85  unsigned int ci_replicates,
86  unsigned int ci_seed)
87  : ReporterStatisticsContext<InType, OutType>(other, producer, state, data, mode, stat)
88 {
89  _ci_calc_ptr = StochasticTools::makeBootstrapCalculator<InType, OutType>(
90  ci_method, other, ci_levels, ci_replicates, ci_seed, *_calc_ptr);
91 }
92 
93 template <typename InType, typename OutType>
94 void
96 {
97  if (_data_mode == REPORTER_MODE_DISTRIBUTED || this->processor_id() == 0)
98  {
99  this->_state.value().first = _calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED);
100 
101  if (_ci_calc_ptr)
102  this->_state.value().second =
103  _ci_calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED);
104  }
105 
107 }
108 
109 template <typename InType, typename OutType>
110 void
112 {
114  json["stat"] = _calc_ptr->name();
115 }
116 
125 {
126 public:
127  static InputParameters validParams();
129 
136  virtual void initialize() final;
137 
139  virtual void execute() final{};
140  virtual void finalize() final{};
141  virtual void store(nlohmann::json & json) const override;
142 
143 private:
144  // Statistics to be computed
146 
147  // CI Method to be computed (optional)
149 
150  // CI levels to be computed
151  const std::vector<Real> & _ci_levels;
152 
153  // Number of CI replicates to use in Bootstrap methods
154  const unsigned int & _ci_replicates;
155 
156  // Random seed for producing CI replicates
157  const unsigned int & _ci_seed;
158 
161 
167  template <typename InType, typename OutType>
168  void declareValueHelper(const ReporterName & r_name);
169 };
virtual void finalize() final
const ReporterProducerEnum & _data_mode
Mode in which the above data was produced.
StatisticsReporter(const InputParameters &parameters)
const InType & _data
Data used for the statistic calculation.
virtual void storeInfo(nlohmann::json &json) const override
const ReporterState< std::pair< OutType, std::vector< OutType > > > & state() const
ReporterContext that utilizes a Calculator object to compute its value and confidence levels...
const unsigned int & _ci_seed
Compute several metrics for supplied data.
void declareValueHelper(const ReporterName &r_name)
Helper for adding statistic reporter values.
virtual void execute() final
Not used; all operations are wrapped in the ReporterStatisticsContext.
virtual void store(nlohmann::json &json) const override
const std::vector< Real > & _ci_levels
std::unique_ptr< StochasticTools::BootstrapCalculator< InType, OutType > > _ci_calc_ptr
Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) ...
const unsigned int & _ci_replicates
std::unique_ptr< Calculator< InType, OutType > > makeCalculator(const MooseEnumItem &item, const libMesh::ParallelObject &other)
Definition: Calculators.h:335
Enum for batch type in stochastic tools MultiApp.
bool _initialized
Whether or not initialize() has been called for reporter value declaration.
ReporterStatisticsContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::pair< OutType, std::vector< OutType >>> &state, const InType &data, const ReporterProducerEnum &mode, const MooseEnumItem &stat)
static InputParameters validParams()
const ReporterMode REPORTER_MODE_DISTRIBUTED
virtual void finalize() override
const MooseEnum & _ci_method
std::unique_ptr< StochasticTools::Calculator< InType, OutType > > _calc_ptr
Storage for the Calculator object for the desired stat, this is created in constructor.
virtual void initialize() final
This is where the reporter values are declared Note: unfortunetly this cannot be in the constructor s...
const InputParameters & parameters() const
const MultiMooseEnum & _compute_stats