https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
16class SobolSampler;
17template <typename InType, typename OutType>
19
24{
25public:
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
36private:
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
61template <typename OutType>
62using SobolState = std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>>;
63
64template <typename InType, typename OutType>
65class SobolReporterContext : public ReporterGeneralContext<SobolState<OutType>>
66{
67public:
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
94protected:
95 virtual void store(nlohmann::json & json) const override;
96
97private:
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};
std::pair< std::vector< OutType >, std::vector< std::vector< OutType > > > SobolState
const InputParameters & parameters() const
const ReporterState< T > & state() const
virtual void finalize() override
const InType & _data
Data used for the statistic calculation.
static void storeSobol(nlohmann::json &json, const SobolState< OutType > &val, unsigned int nparam)
StochasticTools::SobolCalculator< InType, OutType > _calc
Storage for the SobolCalculator object, this is created in constructor.
virtual std::string type() const override
const SobolSampler & _sampler
Sobol sampler to get info on number of matrices and whatnot.
virtual void store(nlohmann::json &json) const override
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 ReporterProducerEnum & _data_mode
Mode in which the above data was produced.
Computes Sobol sensitivity indices, see SobolCalculators.
bool _initialized
Whether or not initialize() has been called for reporter value declaration.
const unsigned int & _ci_replicates
Number of CI replicates to use in Bootstrap methods.
virtual void initialize() override
const unsigned int & _ci_seed
Random seed for producing CI replicates.
virtual void execute() override
virtual void store(nlohmann::json &json) const override
virtual void initialSetup() override
virtual void finalize() override
static InputParameters validParams()
const std::vector< Real > & _ci_levels
CI levels to be computed.
void declareValueHelper(const ReporterName &r_name)
Helper for adding Sobol reporter values.
const SobolSampler & _sobol_sampler
The sampler that generated the samples that produced results for the _results_vectors.
A class used to perform Monte Carlo sampling for performing Sobol sensitivity analysis.
Calculator for computing Sobol sensitivity indices according to the paper by Saltelli (2002) https://...