https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Private Attributes | Friends | List of all members
PolynomialChaos Class Reference

#include <PolynomialChaos.h>

Inheritance diagram for PolynomialChaos:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 PolynomialChaos (const InputParameters &parameters)
 
virtual Real evaluate (const std::vector< Real > &x) const override
 Evaluate surrogate model given a row of parameters. More...
 
std::size_t getNumberOfParameters () const
 Access number of dimensions/parameters. More...
 
std::size_t getNumberofCoefficients () const
 Number of terms in expansion. More...
 
const std::vector< Real > & getCoefficients () const
 Access computed expansion coefficients. More...
 
virtual Real computeMean () const
 Evaluate mean: = E[u]. More...
 
virtual Real computeStandardDeviation () const
 Evaluate standard deviation: = sqrt(E[(u-)^2]) More...
 
Real powerExpectation (const unsigned int n) const
 Compute expectation of a certain power of the QoI: E[(u-)^n]. More...
 
Real computeDerivative (const unsigned int dim, const std::vector< Real > &x) const
 Evaluates partial derivative of expansion: du(x)/dx_dim. More...
 
Real computePartialDerivative (const std::vector< unsigned int > &dim, const std::vector< Real > &x) const
 Evaluates sum of partial derivative of expansion. More...
 
Real computeSobolIndex (const std::set< unsigned int > &ind) const
 Computes Sobol sensitivities S_{i_1,i_2,...,i_s}, where ind = i_1,i_2,...,i_s. More...
 
Real computeSobolTotal (const unsigned int dim) const
 
void store (nlohmann::json &json) const
 
virtual Real evaluate (const std::vector< Real > &x) const
 Evaluate surrogate model given a row of parameters. More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y) const
 Various evaluate methods that can be overriden. More...
 
virtual Real evaluate (const std::vector< Real > &x, Real &std) const
 Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y, std::vector< Real > &) const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
const std::string & modelMetaDataName () const
 Accessor for the name of the model meta data. More...
 
const FileName & getModelDataFileName () const
 Get the associated filename. More...
 
bool hasModelData () const
 Check if we need to load model data (if the filename parameter is used) More...
 
const std::vector< std::vector< unsigned int > > & getPolynomialOrders () const
 Access polynomial orders from tuple /. More...
 
unsigned int getPolynomialOrder (const unsigned int dim, const unsigned int i) const
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y) const
 Various evaluate methods that can be overriden. More...
 
virtual Real evaluate (const std::vector< Real > &x, Real &std) const
 Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y, std::vector< Real > &) const
 
template<typename T = SurrogateModel>
T & getSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainerByName (const UserObjectName &name) const
 
template<typename T , typename... Args>
T & declareModelData (const std::string &data_name, Args &&... args)
 Declare model data for loading from file as well as restart. More...
 
template<typename T , typename... Args>
const T & getModelData (const std::string &data_name, Args &&... args) const
 Retrieve model data from the interface. More...
 

Static Public Member Functions

static InputParameters validParams ()
 
static MooseEnum defaultPredictorTypes ()
 
static MooseEnum defaultResponseTypes ()
 

Public Attributes

const ConsoleStream _console
 

Protected Attributes

const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const Parallel::Communicator & _communicator
 

Private Attributes

const unsigned int_order
 Maximum polynomial order. The sum of 1D polynomial orders does not go above this value. More...
 
const unsigned int_ndim
 Total number of parameters/dimensions. More...
 
const std::size_t & _ncoeff
 Total number of coefficient (defined by size of _tuple) More...
 
const std::vector< std::vector< unsigned int > > & _tuple
 A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order. More...
 
const std::vector< Real > & _coeff
 These are the coefficients we are after in the PC expansion. More...
 
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
 The distributions used for sampling. More...
 

Friends

void to_json (nlohmann::json &json, const PolynomialChaos *const &pc)
 
dof_id_type _n_local_coeff = std::numeric_limits<dof_id_type>::max()
 Variables calculation and for looping over the computed coefficients in parallel. More...
 
dof_id_type _local_coeff_begin = 0
 
dof_id_type _local_coeff_end = 0
 
void linearPartitionCoefficients () const
 

Detailed Description

Definition at line 19 of file PolynomialChaos.h.

Constructor & Destructor Documentation

◆ PolynomialChaos()

PolynomialChaos::PolynomialChaos ( const InputParameters parameters)

Definition at line 24 of file PolynomialChaos.C.

26  _order(getModelData<unsigned int>("_order")),
27  _ndim(getModelData<unsigned int>("_ndim")),
28  _ncoeff(getModelData<std::size_t>("_ncoeff")),
29  _tuple(getModelData<std::vector<std::vector<unsigned int>>>("_tuple")),
30  _coeff(getModelData<std::vector<Real>>("_coeff")),
31  _poly(
32  getModelData<std::vector<std::unique_ptr<const PolynomialQuadrature::Polynomial>>>("_poly"))
33 {
34 }
const T & getModelData(const std::string &data_name, Args &&... args) const
Retrieve model data from the interface.
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
const unsigned int & _order
Maximum polynomial order. The sum of 1D polynomial orders does not go above this value.
const InputParameters & parameters() const
SurrogateModel(const InputParameters &parameters)
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
const unsigned int & _ndim
Total number of parameters/dimensions.

Member Function Documentation

◆ computeDerivative()

Real PolynomialChaos::computeDerivative ( const unsigned int  dim,
const std::vector< Real > &  x 
) const

Evaluates partial derivative of expansion: du(x)/dx_dim.

Definition at line 139 of file PolynomialChaos.C.

Referenced by PolynomialChaosReporter::computeLocalSensitivity().

140 {
141  return computePartialDerivative({dim}, x);
142 }
unsigned int dim
Real computePartialDerivative(const std::vector< unsigned int > &dim, const std::vector< Real > &x) const
Evaluates sum of partial derivative of expansion.
const std::vector< double > x

◆ computeMean()

Real PolynomialChaos::computeMean ( ) const
virtual

Evaluate mean: = E[u].

Definition at line 79 of file PolynomialChaos.C.

Referenced by computeSobolIndex().

80 {
81  mooseAssert(_coeff.size() > 0, "The coefficient matrix is empty.");
82  return _coeff[0];
83 }
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.

◆ computePartialDerivative()

Real PolynomialChaos::computePartialDerivative ( const std::vector< unsigned int > &  dim,
const std::vector< Real > &  x 
) const

Evaluates sum of partial derivative of expansion.

Example: computeGradient({0, 2, 3}, x) = du(x)/dx_0dx_2dx_3

Definition at line 145 of file PolynomialChaos.C.

Referenced by computeDerivative().

147 {
148  mooseAssert(x.size() == _ndim, "Number of inputted parameters does not match PC model.");
149 
150  std::vector<unsigned int> grad(_ndim);
151  for (const auto & d : dim)
152  {
153  mooseAssert(d < _ndim, "Specified dimension is greater than total number of parameters.");
154  grad[d]++;
155  }
156 
157  DenseMatrix<Real> poly_val(_ndim, _order);
158 
159  // Evaluate polynomials to avoid duplication
160  for (unsigned int d = 0; d < _ndim; ++d)
161  for (unsigned int i = 0; i < _order; ++i)
162  poly_val(d, i) = _poly[d]->computeDerivative(i, x[d], grad[d]);
163 
164  Real val = 0;
165  for (std::size_t i = 0; i < _ncoeff; ++i)
166  {
167  Real tmp = _coeff[i];
168  for (unsigned int d = 0; d < _ndim; ++d)
169  tmp *= poly_val(d, _tuple[i][d]);
170  val += tmp;
171  }
172 
173  return val;
174 }
const std::vector< double > x
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
std::string grad(const std::string &var)
Definition: NS.h:91
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int & _order
Maximum polynomial order. The sum of 1D polynomial orders does not go above this value.
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ computeSobolIndex()

Real PolynomialChaos::computeSobolIndex ( const std::set< unsigned int > &  ind) const

Computes Sobol sensitivities S_{i_1,i_2,...,i_s}, where ind = i_1,i_2,...,i_s.

Definition at line 177 of file PolynomialChaos.C.

178 {
180 
181  // If set is empty, compute mean
182  if (ind.empty())
183  return computeMean();
184 
185  // Do some sanity checks in debug
186  mooseAssert(ind.size() <= _ndim, "Number of indices is greater than number of parameters.");
187  mooseAssert(*ind.rbegin() < _ndim, "Maximum index provided exceeds number of parameters.");
188 
189  Real val = 0.0;
191  {
192  Real tmp = _coeff[i] * _coeff[i];
193  for (unsigned int d = 0; d < _ndim; ++d)
194  {
195  if ((ind.find(d) != ind.end() && _tuple[i][d] > 0) ||
196  (ind.find(d) == ind.end() && _tuple[i][d] == 0))
197  {
198  tmp *= _poly[d]->innerProduct(_tuple[i][d]);
199  }
200  else
201  {
202  tmp = 0.0;
203  break;
204  }
205  }
206  val += tmp;
207  }
208 
209  return val;
210 }
virtual Real computeMean() const
Evaluate mean: = E[u].
dof_id_type _local_coeff_begin
dof_id_type _local_coeff_end
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void linearPartitionCoefficients() const
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
uint8_t dof_id_type
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ computeSobolTotal()

Real PolynomialChaos::computeSobolTotal ( const unsigned int  dim) const

Definition at line 213 of file PolynomialChaos.C.

214 {
216 
217  // Do some sanity checks in debug
218  mooseAssert(dim < _ndim, "Requested dimension is greater than number of parameters.");
219 
220  Real val = 0.0;
222  if (_tuple[i][dim] > 0)
223  val += _coeff[i] * _coeff[i] * _poly[dim]->innerProduct(_tuple[i][dim]);
224 
225  return val;
226 }
dof_id_type _local_coeff_begin
unsigned int dim
dof_id_type _local_coeff_end
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void linearPartitionCoefficients() const
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
uint8_t dof_id_type
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ computeStandardDeviation()

Real PolynomialChaos::computeStandardDeviation ( ) const
virtual

Evaluate standard deviation: = sqrt(E[(u-)^2])

Definition at line 86 of file PolynomialChaos.C.

87 {
88  Real var = 0;
89  for (std::size_t i = 1; i < _ncoeff; ++i)
90  {
91  Real norm = 1.0;
92  for (std::size_t d = 0; d < _ndim; ++d)
93  norm *= _poly[d]->innerProduct(_tuple[i][d]);
94  var += _coeff[i] * _coeff[i] * norm;
95  }
96 
97  return std::sqrt(var);
98 }
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
auto norm(const T &a) -> decltype(std::abs(a))
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ declareModelData()

template<typename T , typename... Args>
T & RestartableModelInterface::declareModelData ( const std::string &  data_name,
Args &&...  args 
)
inherited

Declare model data for loading from file as well as restart.

Definition at line 78 of file RestartableModelInterface.h.

79 {
80  return _model_restartable.declareRestartableData<T>(data_name, std::forward<Args>(args)...);
81 }
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ defaultPredictorTypes()

static MooseEnum SurrogateModel::defaultPredictorTypes ( )
inlinestaticinherited

Definition at line 27 of file SurrogateModel.h.

27 { return MooseEnum("real"); }

◆ defaultResponseTypes()

static MooseEnum SurrogateModel::defaultResponseTypes ( )
inlinestaticinherited

Definition at line 28 of file SurrogateModel.h.

Referenced by EvaluateSurrogate::validParams().

28 { return MooseEnum("real vector_real"); }

◆ evaluate() [1/8]

virtual Real SurrogateModel::evaluate
inline

Evaluate surrogate model given a row of parameters.

Definition at line 33 of file SurrogateModel.h.

34  {
35  evaluateError(x, Real());
36  return 0.0;
37  };
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ evaluate() [2/8]

virtual void SurrogateModel::evaluate
inline

Various evaluate methods that can be overriden.

Definition at line 43 of file SurrogateModel.h.

44  {
45  evaluateError(x, y);
46  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [3/8]

virtual Real SurrogateModel::evaluate
inline

Evaluate methods that also return predicted standard deviation (see GaussianProcess.h)

Definition at line 53 of file SurrogateModel.h.

54  {
55  evaluateError(x, std, true);
56  return 0.0;
57  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x

◆ evaluate() [4/8]

virtual void SurrogateModel::evaluate
inline

Definition at line 59 of file SurrogateModel.h.

60  {
61  evaluateError(x, y, true);
62  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [5/8]

Real PolynomialChaos::evaluate ( const std::vector< Real > &  x) const
overridevirtual

Evaluate surrogate model given a row of parameters.

Reimplemented from SurrogateModel.

Definition at line 37 of file PolynomialChaos.C.

Referenced by PolynomialChaosReporter::computeLocalSensitivity().

38 {
39  mooseAssert(x.size() == _ndim, "Number of inputted parameters does not match PC model.");
40 
41  DenseMatrix<Real> poly_val(_ndim, _order);
42 
43  // Evaluate polynomials to avoid duplication
44  for (unsigned int d = 0; d < _ndim; ++d)
45  for (unsigned int i = 0; i < _order; ++i)
46  poly_val(d, i) = _poly[d]->compute(i, x[d], /*normalize =*/false);
47 
48  Real val = 0;
49  for (std::size_t i = 0; i < _ncoeff; ++i)
50  {
51  Real tmp = _coeff[i];
52  for (unsigned int d = 0; d < _ndim; ++d)
53  tmp *= poly_val(d, _tuple[i][d]);
54  val += tmp;
55  }
56 
57  return val;
58 }
const std::vector< double > x
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int & _order
Maximum polynomial order. The sum of 1D polynomial orders does not go above this value.
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ evaluate() [6/8]

virtual void SurrogateModel::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y 
) const
inlinevirtualinherited

Various evaluate methods that can be overriden.

Reimplemented in GaussianProcessSurrogate, PolynomialRegressionSurrogate, and NearestPointSurrogate.

Definition at line 43 of file SurrogateModel.h.

44  {
45  evaluateError(x, y);
46  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [7/8]

virtual Real SurrogateModel::evaluate ( const std::vector< Real > &  x,
Real std 
) const
inlinevirtualinherited

Evaluate methods that also return predicted standard deviation (see GaussianProcess.h)

Reimplemented in GaussianProcessSurrogate.

Definition at line 53 of file SurrogateModel.h.

54  {
55  evaluateError(x, std, true);
56  return 0.0;
57  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x

◆ evaluate() [8/8]

virtual void SurrogateModel::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y,
std::vector< Real > &   
) const
inlinevirtualinherited

Reimplemented in GaussianProcessSurrogate.

Definition at line 59 of file SurrogateModel.h.

60  {
61  evaluateError(x, y, true);
62  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ getCoefficients()

const std::vector< Real > & PolynomialChaos::getCoefficients ( ) const

Access computed expansion coefficients.

Definition at line 73 of file PolynomialChaos.C.

Referenced by store().

74 {
75  return _coeff;
76 }
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.

◆ getModelData()

template<typename T , typename... Args>
const T & RestartableModelInterface::getModelData ( const std::string &  data_name,
Args &&...  args 
) const
inherited

Retrieve model data from the interface.

Definition at line 85 of file RestartableModelInterface.h.

86 {
87  return _model_restartable.getRestartableData<T>(data_name, std::forward<Args>(args)...);
88 }
const T & getRestartableData(const std::string &data_name) const
Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but retu...
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ getModelDataFileName()

const FileName & RestartableModelInterface::getModelDataFileName ( ) const
inherited

Get the associated filename.

Definition at line 33 of file RestartableModelInterface.C.

34 {
35  return _model_object.getParam<FileName>("filename");
36 }
const T & getParam(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ getNumberofCoefficients()

std::size_t PolynomialChaos::getNumberofCoefficients ( ) const
inline

Number of terms in expansion.

Definition at line 31 of file PolynomialChaos.h.

Referenced by store().

31 { return _tuple.size(); }
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.

◆ getNumberOfParameters()

std::size_t PolynomialChaos::getNumberOfParameters ( ) const
inline

Access number of dimensions/parameters.

Definition at line 28 of file PolynomialChaos.h.

Referenced by store().

28 { return _poly.size(); }
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.

◆ getPolynomialOrder()

unsigned PolynomialChaos::getPolynomialOrder ( const unsigned int  dim,
const unsigned int  i 
) const

Definition at line 67 of file PolynomialChaos.C.

68 {
69  return _tuple[i][dim];
70 }
unsigned int dim
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.

◆ getPolynomialOrders()

const std::vector< std::vector< unsigned int > > & PolynomialChaos::getPolynomialOrders ( ) const

Access polynomial orders from tuple /.

Definition at line 61 of file PolynomialChaos.C.

Referenced by store().

62 {
63  return _tuple;
64 }
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.

◆ getSurrogateModel() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Definition at line 46 of file SurrogateModelInterface.C.

47 {
48  return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModel() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Get a SurrogateModel/Trainer with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 81 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainer::initialize().

82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModelByName() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Definition at line 31 of file SurrogateModelInterface.C.

32 {
33  std::vector<SurrogateModel *> models;
35  .query()
36  .condition<AttribName>(name)
37  .condition<AttribSystem>("SurrogateModel")
38  .queryInto(models);
39  if (models.empty())
40  mooseError("Unable to find a SurrogateModel object with the name '" + name + "'");
41  return *(models[0]);
42 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateModelByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 88 of file SurrogateModelInterface.h.

Referenced by CrossValidationScores::CrossValidationScores(), EvaluateSurrogate::EvaluateSurrogate(), and InverseMapping::initialSetup().

89 {
90  std::vector<T *> models;
92  .query()
93  .condition<AttribName>(name)
94  .condition<AttribSystem>("SurrogateModel")
95  .queryInto(models);
96  if (models.empty())
97  mooseError("Unable to find a SurrogateModel object of type " + std::string(typeid(T).name()) +
98  " with the name '" + name + "'");
99  return *(models[0]);
100 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateTrainer() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 104 of file SurrogateModelInterface.h.

105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainer() [2/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 60 of file SurrogateModelInterface.C.

61 {
62  return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainerByName() [1/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 53 of file SurrogateModelInterface.C.

54 {
56 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
This is the base trainer class whose main functionality is the API for declaring model data...

◆ getSurrogateTrainerByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 111 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainerOutput::output().

112 {
113  SurrogateTrainerBase * base_ptr =
115  T * obj_ptr = dynamic_cast<T *>(base_ptr);
116  if (!obj_ptr)
117  mooseError("Failed to find a SurrogateTrainer object of type " + std::string(typeid(T).name()) +
118  " with the name '",
119  name,
120  "' for the desired type.");
121  return *obj_ptr;
122 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
const THREAD_ID _smi_tid
Thread ID.
This is the base trainer class whose main functionality is the API for declaring model data...

◆ hasModelData()

bool RestartableModelInterface::hasModelData ( ) const
inherited

Check if we need to load model data (if the filename parameter is used)

Definition at line 39 of file RestartableModelInterface.C.

40 {
41  return _model_object.isParamValid("filename");
42 }
bool isParamValid(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ linearPartitionCoefficients()

void PolynomialChaos::linearPartitionCoefficients ( ) const
private

Definition at line 229 of file PolynomialChaos.C.

Referenced by computeSobolIndex(), and computeSobolTotal().

230 {
231  if (_n_local_coeff == std::numeric_limits<dof_id_type>::max())
233  n_processors(),
234  processor_id(),
238 }
dof_id_type _local_coeff_begin
void linearPartitionItems(dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
dof_id_type _local_coeff_end
processor_id_type n_processors() const
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
dof_id_type _n_local_coeff
Variables calculation and for looping over the computed coefficients in parallel. ...
processor_id_type processor_id() const

◆ modelMetaDataName()

const std::string& RestartableModelInterface::modelMetaDataName ( ) const
inlineinherited

Accessor for the name of the model meta data.

Definition at line 47 of file RestartableModelInterface.h.

Referenced by SurrogateTrainerOutput::output(), and MappingOutput::output().

47 { return _model_meta_data_name; }
const std::string _model_meta_data_name
The model meta data name.

◆ powerExpectation()

Real PolynomialChaos::powerExpectation ( const unsigned int  n) const

Compute expectation of a certain power of the QoI: E[(u-)^n].

Definition at line 101 of file PolynomialChaos.C.

102 {
103  std::vector<StochasticTools::WeightedCartesianProduct<unsigned int, Real>> order;
104  order.reserve(_ndim);
105  std::vector<std::vector<Real>> c_1d(n, std::vector<Real>(_coeff.begin() + 1, _coeff.end()));
106  for (unsigned int d = 0; d < _ndim; ++d)
107  {
108  std::vector<std::vector<unsigned int>> order_1d(n, std::vector<unsigned int>(_ncoeff - 1));
109  for (std::size_t i = 1; i < _ncoeff; ++i)
110  for (unsigned int m = 0; m < n; ++m)
111  order_1d[m][i - 1] = _tuple[i][d];
112  order.push_back(StochasticTools::WeightedCartesianProduct<unsigned int, Real>(order_1d, c_1d));
113  }
114 
115  dof_id_type n_local, st_local, end_local;
117  order[0].numRows(), n_processors(), processor_id(), n_local, st_local, end_local);
118 
119  Real val = 0;
120  for (dof_id_type i = st_local; i < end_local; ++i)
121  {
122  Real tmp = order[0].computeWeight(i);
123  for (unsigned int d = 0; d < _ndim; ++d)
124  {
125  if (MooseUtils::absoluteFuzzyEqual(tmp, 0.0))
126  break;
127  std::vector<unsigned int> comb(n);
128  for (unsigned int m = 0; m < n; ++m)
129  comb[m] = order[d].computeValue(i, m);
130  tmp *= _poly[d]->productIntegral(comb);
131  }
132  val += tmp;
133  }
134 
135  return val;
136 }
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
void linearPartitionItems(dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
processor_id_type n_processors() const
const std::size_t & _ncoeff
Total number of coefficient (defined by size of _tuple)
const std::vector< std::vector< unsigned int > > & _tuple
A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.
const std::vector< Real > & _coeff
These are the coefficients we are after in the PC expansion.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
processor_id_type processor_id() const
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.
uint8_t dof_id_type
const unsigned int & _ndim
Total number of parameters/dimensions.

◆ store()

void PolynomialChaos::store ( nlohmann::json &  json) const

Definition at line 241 of file PolynomialChaos.C.

Referenced by to_json().

242 {
243  json["order"] = _order;
244  json["ndim"] = getNumberOfParameters();
245  json["ncoeff"] = getNumberofCoefficients();
246  json["tuple"] = getPolynomialOrders();
247  json["coeff"] = getCoefficients();
248  for (const auto & p : _poly)
249  {
250  nlohmann::json jsonp;
251  p->store(jsonp);
252  json["poly"].push_back(jsonp);
253  }
254 }
std::size_t getNumberOfParameters() const
Access number of dimensions/parameters.
std::size_t getNumberofCoefficients() const
Number of terms in expansion.
const std::vector< std::vector< unsigned int > > & getPolynomialOrders() const
Access polynomial orders from tuple /.
const unsigned int & _order
Maximum polynomial order. The sum of 1D polynomial orders does not go above this value.
const std::vector< Real > & getCoefficients() const
Access computed expansion coefficients.
const std::vector< std::unique_ptr< const PolynomialQuadrature::Polynomial > > & _poly
The distributions used for sampling.

◆ validParams()

InputParameters PolynomialChaos::validParams ( )
static

Definition at line 17 of file PolynomialChaos.C.

18 {
20  params.addClassDescription("Computes and evaluates polynomial chaos surrogate model.");
21  return params;
22 }
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)

Friends And Related Function Documentation

◆ to_json

void to_json ( nlohmann::json &  json,
const PolynomialChaos *const &  pc 
)
friend

Definition at line 150 of file PolynomialChaosReporter.C.

151 {
152  pc->store(json);
153 }
void store(nlohmann::json &json) const

Member Data Documentation

◆ _coeff

const std::vector<Real>& PolynomialChaos::_coeff
private

These are the coefficients we are after in the PC expansion.

Definition at line 97 of file PolynomialChaos.h.

Referenced by computeMean(), computePartialDerivative(), computeSobolIndex(), computeSobolTotal(), computeStandardDeviation(), evaluate(), getCoefficients(), and powerExpectation().

◆ _local_coeff_begin

dof_id_type PolynomialChaos::_local_coeff_begin = 0
mutableprivate

◆ _local_coeff_end

dof_id_type PolynomialChaos::_local_coeff_end = 0
mutableprivate

◆ _n_local_coeff

dof_id_type PolynomialChaos::_n_local_coeff = std::numeric_limits<dof_id_type>::max()
mutableprivate

Variables calculation and for looping over the computed coefficients in parallel.

The various utility methods in this class require the coefficients be partitioned in parallel, but the data being partitioned is loaded from the trainer so it might not be available. Thus, the partitioning is done on demand, if needed.

The methods are marked const because they do not modify the loaded data, to keep this interface the partitioning uses mutable variables.

Definition at line 76 of file PolynomialChaos.h.

Referenced by linearPartitionCoefficients().

◆ _ncoeff

const std::size_t& PolynomialChaos::_ncoeff
private

Total number of coefficient (defined by size of _tuple)

Definition at line 91 of file PolynomialChaos.h.

Referenced by computePartialDerivative(), computeStandardDeviation(), evaluate(), linearPartitionCoefficients(), and powerExpectation().

◆ _ndim

const unsigned int& PolynomialChaos::_ndim
private

Total number of parameters/dimensions.

Definition at line 88 of file PolynomialChaos.h.

Referenced by computePartialDerivative(), computeSobolIndex(), computeSobolTotal(), computeStandardDeviation(), evaluate(), and powerExpectation().

◆ _order

const unsigned int& PolynomialChaos::_order
private

Maximum polynomial order. The sum of 1D polynomial orders does not go above this value.

Definition at line 85 of file PolynomialChaos.h.

Referenced by computePartialDerivative(), evaluate(), and store().

◆ _poly

const std::vector<std::unique_ptr<const PolynomialQuadrature::Polynomial> >& PolynomialChaos::_poly
private

◆ _tuple

const std::vector<std::vector<unsigned int> >& PolynomialChaos::_tuple
private

A _ndim-by-_ncoeff matrix containing the appropriate one-dimensional polynomial order.

Definition at line 94 of file PolynomialChaos.h.

Referenced by computePartialDerivative(), computeSobolIndex(), computeSobolTotal(), computeStandardDeviation(), evaluate(), getNumberofCoefficients(), getPolynomialOrder(), getPolynomialOrders(), and powerExpectation().


The documentation for this class was generated from the following files: