22 "Tool for extracting data from PolynomialChaos surrogates and computing statistics.");
24 "pc_name",
"Name(s) of PolynomialChaos surrogate object(s).");
25 params.
addParam<
bool>(
"include_data",
27 "True to output information on the polynomial chaos model, including " 28 "polynomial types, orders, and coefficients.");
31 params.
addParam<
bool>(
"include_sobol",
false,
"True to compute Sobol indices.");
32 params.
addParam<std::vector<std::vector<Real>>>(
33 "local_sensitivity_points",
34 std::vector<std::vector<Real>>(0),
35 "Points for each polynomial chaos surrogate specifying desired location of sensitivity " 37 params.
addParam<std::vector<SamplerName>>(
38 "local_sensitivity_sampler",
39 std::vector<SamplerName>(0),
40 "Sampler for each polynomial chaos surrogate specifying desired location of sensitivity " 48 _loc_point(getParam<
std::vector<
std::vector<
Real>>>(
"local_sensitivity_points"))
50 for (
const auto & sn :
getParam<std::vector<SamplerName>>(
"local_sensitivity_sampler"))
53 for (
const auto & nm :
getParam<std::vector<UserObjectName>>(
"pc_name"))
56 _pc.push_back(&getSurrogateModelByName<PolynomialChaos>(nm));
58 if (getParam<bool>(
"include_data"))
64 for (
const auto & stat : getParam<MultiMooseEnum>(
"statistics"))
68 if (getParam<bool>(
"include_sobol"))
76 "There must be a set of points for each inputted polynomial chaos model.");
85 "There must be a sampler for each inputted polynomial chaos model.");
102 const auto & pc = *
_pc[i];
103 const auto nparam = pc.getNumberOfParameters();
106 if (
_loc_point[i].size() % pc.getNumberOfParameters() != 0)
108 "Number of values must be divisible by number of parameters in " 109 "Polynomial Chaos model.");
111 const auto npoint =
_loc_point[i].size() / nparam;
115 const std::vector<Real> data(
_loc_point[i].begin() + p * nparam,
124 "local_sensitivity_sampler",
127 " does not have the same number of columns as the number of dimensions in model ",
140 const std::vector<Real> & data)
142 std::vector<Real> sense(data.size());
155 template <
typename OutType>
159 ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
168 template <
typename OutType>
173 OutType sig = OutType();
174 if (_stat ==
"stddev" || _stat ==
"skewness" || _stat ==
"kurtosis")
175 sig = _pc.computeStandardDeviation();
177 OutType & val = this->_state.value().first;
180 if (_stat ==
"mean" && this->processor_id() == 0)
181 val = _pc.computeMean();
183 else if (_stat ==
"stddev" && this->processor_id() == 0)
186 else if (_stat ==
"skewness")
187 val = _pc.powerExpectation(3) / (sig * sig * sig);
189 else if (_stat ==
"kurtosis")
190 val = _pc.powerExpectation(4) / (sig * sig * sig * sig);
191 this->_communicator.sum(val);
196 template <
typename OutType>
201 json[
"stat"] = _stat.name();
204 template <
typename OutType>
208 ReporterState<std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>>> & state,
211 other, producer, state),
216 template <
typename OutType>
220 const unsigned int nparam = _pc.getNumberOfParameters();
221 std::vector<OutType> & val = this->_state.value().first;
225 auto var = _pc.computeStandardDeviation();
230 val.push_back(_pc.computeSobolIndex({i}) / var);
233 val.push_back(_pc.computeSobolTotal(i) / var);
237 val.push_back(_pc.computeSobolIndex({i, j}) / var);
240 template <
typename OutType>
245 json, this->_state.value(), _pc.getNumberOfParameters());
PCSobolContext is almost identical to SobolReporterContext with InType == Outype. ...
T & declareValueByName(const ReporterValueName &value_name, Args &&... args)
T & getSamplerByName(const SamplerName &name)
PCSobolContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::pair< std::vector< OutType >, std::vector< std::vector< OutType >>>> &state, const PolynomialChaos &pc)
virtual void store(nlohmann::json &json) const override
const ReporterMode REPORTER_MODE_ROOT
virtual void finalize() override
virtual void execute() override
static InputParameters validParams()
PCStatisticsContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< std::pair< OutType, std::vector< OutType >>> &state, const PolynomialChaos &pc, const MooseEnumItem &stat)
std::vector< std::vector< std::vector< Real > > * > _loc_sampler_sense
Local sensitivity from sampled points.
void store(nlohmann::json &json) const
static InputParameters validParams()
virtual const std::string & name() const
std::vector< std::vector< std::vector< Real > > * > _loc_point_sense
Local sensitivity from specified points.
PCStatisticsContext is almost identical to ReporterStatisticsContext with InType == Outype...
const std::vector< std::vector< Real > > & _loc_point
Points for local sensitivity calculation.
virtual void finalize() override
std::vector< const PolynomialChaos * > _pc
Polynomial chaos models.
const T & getParam(const std::string &name) const
static std::vector< Real > computeLocalSensitivity(const PolynomialChaos &pc, const std::vector< Real > &data)
Helper function for computing local sensitivity from a polynomial chaos model.
void paramError(const std::string ¶m, Args... args) const
Real computeDerivative(const unsigned int dim, const std::vector< Real > &x) const
Evaluates partial derivative of expansion: du(x)/dx_dim.
PolynomialChaosReporter(const InputParameters ¶meters)
virtual Real evaluate(const std::vector< Real > &x) const override
Evaluate surrogate model given a row of parameters.
std::vector< Sampler * > _loc_sampler
Samplers for local sensitivity calculation.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface for objects that need to use samplers.
IntRange< T > make_range(T beg, T end)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
virtual void storeInfo(nlohmann::json &json) const override
auto index_range(const T &sizable)
void to_json(nlohmann::json &json, const PolynomialChaos *const &pc)
registerMooseObject("StochasticToolsApp", PolynomialChaosReporter)