Line data Source code
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 : 17 : class MorrisReporter : public GeneralReporter 18 : { 19 : public: 20 : static InputParameters validParams(); 21 : MorrisReporter(const InputParameters & parameters); 22 : 23 : virtual void initialize() override final; 24 : 25 64 : virtual void execute() override final {} 26 64 : virtual void finalize() override final {} 27 : virtual void store(nlohmann::json & json) const override; 28 : 29 : private: 30 : /** 31 : * Helper for adding Morris reporter values 32 : */ 33 : template <typename DataType> 34 : void declareValueHelper(const ReporterName & r_name); 35 : 36 : /// Morris sampler (don't need any specific functions, but should be this type) 37 : Sampler & _sampler; 38 : 39 : /// CI levels to be computed 40 : const std::vector<Real> & _ci_levels; 41 : 42 : /// Number of CI replicates to use in Bootstrap methods 43 : const unsigned int & _ci_replicates; 44 : 45 : /// Random seed for producing CI replicates 46 : const unsigned int & _ci_seed; 47 : 48 : /// Whether or not initialize() has been called for reporter value declaration 49 : bool _initialized; 50 : }; 51 : 52 : template <typename DataType> 53 : using MorrisState = 54 : std::map<std::string, std::pair<std::vector<DataType>, std::vector<std::vector<DataType>>>>; 55 : 56 : template <typename DataType> 57 : class MorrisReporterContext : public ReporterGeneralContext<MorrisState<DataType>> 58 : { 59 : public: 60 : MorrisReporterContext(const libMesh::ParallelObject & other, 61 : const MooseObject & producer, 62 : ReporterState<MorrisState<DataType>> & state, 63 : Sampler & sampler, 64 : const std::vector<DataType> & data); 65 : 66 : MorrisReporterContext(const libMesh::ParallelObject & other, 67 : const MooseObject & producer, 68 : ReporterState<MorrisState<DataType>> & state, 69 : Sampler & sampler, 70 : const std::vector<DataType> & data, 71 : const MooseEnum & ci_method, 72 : const std::vector<Real> & ci_levels, 73 : unsigned int ci_replicates, 74 : unsigned int ci_seed); 75 : 76 : virtual void finalize() override; 77 80 : virtual std::string type() const override 78 : { 79 160 : return "MorrisSensitivity<" + MooseUtils::prettyCppType<DataType>() + ">"; 80 : } 81 : 82 : private: 83 : /** 84 : * Function for computing elementary effects for a single set of trajectories 85 : * This is meant to be specialized for different data types 86 : */ 87 : std::vector<DataType> computeElementaryEffects(const RealEigenMatrix & x, 88 : const std::vector<DataType> & y) const; 89 : 90 : /// Morris sampler (don't need any specific functions, but should be this type) 91 : Sampler & _sampler; 92 : 93 : /// Data used for the statistic calculation 94 : const std::vector<DataType> & _data; 95 : 96 : /// Storage for the Calculator object for the desired stat, this is created in constructor 97 : std::unique_ptr<StochasticTools::Calculator<std::vector<DataType>, DataType>> _mu_calc; 98 : std::unique_ptr<StochasticTools::Calculator<std::vector<DataType>, DataType>> _mustar_calc; 99 : std::unique_ptr<StochasticTools::Calculator<std::vector<DataType>, DataType>> _sig_calc; 100 : 101 : /// Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) 102 : std::unique_ptr<StochasticTools::BootstrapCalculator<std::vector<DataType>, DataType>> 103 : _ci_mu_calc; 104 : std::unique_ptr<StochasticTools::BootstrapCalculator<std::vector<DataType>, DataType>> 105 : _ci_mustar_calc; 106 : std::unique_ptr<StochasticTools::BootstrapCalculator<std::vector<DataType>, DataType>> 107 : _ci_sig_calc; 108 : };