https://mooseframework.inl.gov
SobolReporter.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 "SobolCalculators.h"
15 
16 class SobolSampler;
17 template <typename InType, typename OutType>
19 
24 {
25 public:
28 
29  virtual void initialSetup() override {}
30  virtual void initialize() override;
31  virtual void execute() override {}
32  virtual void finalize() override {}
33 
34  virtual void store(nlohmann::json & json) const override;
35 
36 private:
42  template <typename InType>
43  void declareValueHelper(const ReporterName & r_name);
44 
47 
49  const std::vector<Real> & _ci_levels;
50 
52  const unsigned int & _ci_replicates;
53 
55  const unsigned int & _ci_seed;
56 
59 };
60 
61 template <typename OutType>
62 using SobolState = std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>>;
63 
64 template <typename InType, typename OutType>
65 class SobolReporterContext : public ReporterGeneralContext<SobolState<OutType>>
66 {
67 public:
69  const MooseObject & producer,
71  const InType & data,
72  const ReporterProducerEnum & mode,
73  const SobolSampler & sampler);
74 
76  const MooseObject & producer,
78  const InType & data,
79  const ReporterProducerEnum & mode,
80  const SobolSampler & sampler,
81  const MooseEnum & ci_method,
82  const std::vector<Real> & ci_levels,
83  unsigned int ci_replicates,
84  unsigned int ci_seed);
85 
86  virtual void finalize() override;
87  virtual std::string type() const override
88  {
89  return "SobolIndices<" + MooseUtils::prettyCppType<OutType>() + ">";
90  }
91  static void
92  storeSobol(nlohmann::json & json, const SobolState<OutType> & val, unsigned int nparam);
93 
94 protected:
95  virtual void store(nlohmann::json & json) const override;
96 
97 private:
99  const InType & _data;
100 
103 
106 
109 
111  std::unique_ptr<StochasticTools::BootstrapCalculator<std::vector<InType>, std::vector<OutType>>>
112  _ci_calc_ptr = nullptr;
113 };
A class used to perform Monte Carlo sampling for performing Sobol sensitivity analysis.
Definition: SobolSampler.h:23
const SobolSampler & _sobol_sampler
The sampler that generated the samples that produced results for the _results_vectors.
Definition: SobolReporter.h:46
virtual void execute() override
Definition: SobolReporter.h:31
const ReporterState< SobolState< OutType > > & state() const
std::unique_ptr< StochasticTools::BootstrapCalculator< std::vector< InType >, std::vector< OutType > > > _ci_calc_ptr
Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) ...
const SobolSampler & _sampler
Sobol sampler to get info on number of matrices and whatnot.
void declareValueHelper(const ReporterName &r_name)
Helper for adding Sobol reporter values.
const std::vector< Real > & _ci_levels
CI levels to be computed.
Definition: SobolReporter.h:49
virtual void initialSetup() override
Definition: SobolReporter.h:29
static void storeSobol(nlohmann::json &json, const SobolState< OutType > &val, unsigned int nparam)
const unsigned int & _ci_seed
Random seed for producing CI replicates.
Definition: SobolReporter.h:55
std::pair< std::vector< OutType >, std::vector< std::vector< OutType > >> SobolState
Definition: SobolReporter.h:62
virtual void finalize() override
bool _initialized
Whether or not initialize() has been called for reporter value declaration.
Definition: SobolReporter.h:58
const InType & _data
Data used for the statistic calculation.
Definition: SobolReporter.h:99
const unsigned int & _ci_replicates
Number of CI replicates to use in Bootstrap methods.
Definition: SobolReporter.h:52
SobolReporter(const InputParameters &parameters)
Definition: SobolReporter.C:56
virtual void initialize() override
Definition: SobolReporter.C:81
virtual void store(nlohmann::json &json) const override
virtual void store(nlohmann::json &json) const override
const ReporterProducerEnum & _data_mode
Mode in which the above data was produced.
static InputParameters validParams()
Definition: SobolReporter.C:27
StochasticTools::SobolCalculator< InType, OutType > _calc
Storage for the SobolCalculator object, this is created in constructor.
const InputParameters & parameters() const
virtual std::string type() const override
Definition: SobolReporter.h:87
SobolReporterContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< SobolState< OutType >> &state, const InType &data, const ReporterProducerEnum &mode, const SobolSampler &sampler)
Computes Sobol sensitivity indices, see SobolCalculators.
Definition: SobolReporter.h:23
Calculator for computing Sobol sensitivity indices according to the paper by Saltelli (2002) https://...
virtual void finalize() override
Definition: SobolReporter.h:32