// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER // pce_example // // usage: // pce_example // // output: // prints the Hermite Polynomial Chaos Expansion of the simple function // // v = 1/(log(u)^2+1) // // where u = 1 + 0.1*x_1 + 0.05*x_2 + 0.01*x_3 x1,x2,x3 are zero-mean // unit-variance Gaussian random variables. #include "Stokhos_Sacado.hpp" // The function to compute the polynomial chaos expansion of, // written as a template function template ScalarType simple_function(const ScalarType& u) { ScalarType z = std::log(u); return 1.0/(z*z + 1.0); } int main(int argc, char **argv) { // Typename of Polynomial Chaos scalar type typedef Stokhos::StandardStorage storage_type; typedef Sacado::PCE::OrthogPoly pce_type; // Short-hand for several classes used below using Teuchos::Array; using Teuchos::RCP; using Teuchos::rcp; using Stokhos::OneDOrthogPolyBasis; using Stokhos::HermiteBasis; using Stokhos::CompletePolynomialBasis; using Stokhos::Quadrature; using Stokhos::TensorProductQuadrature; using Stokhos::Sparse3Tensor; using Stokhos::QuadOrthogPolyExpansion; try { // Basis of dimension 3, order 4 const int d = 3; const int p = 4; Array< RCP > > bases(d); for (int i=0; i(p)); } RCP > basis = rcp(new CompletePolynomialBasis(bases)); // Quadrature method RCP > quad = rcp(new TensorProductQuadrature(basis)); // Triple product tensor RCP > Cijk = basis->computeTripleProductTensor(); // Expansion method RCP > expn = rcp(new QuadOrthogPolyExpansion(basis, Cijk, quad)); // Polynomial expansion of u pce_type u(expn); u.term(0,0) = 1.0; // zeroth order term u.term(0,1) = 0.1; // first order term for dimension 0 u.term(1,1) = 0.05; // first order term for dimension 1 u.term(2,1) = 0.01; // first order term for dimension 2 // Compute PCE expansion of function pce_type v = simple_function(u); // Print u and v std::cout << "\tu = "; u.print(std::cout); std::cout << "\tv = "; v.print(std::cout); // Compute moments double mean = v.mean(); double std_dev = v.standard_deviation(); // Evaluate PCE and function at a point = 0.25 in each dimension Teuchos::Array pt(d); for (int i=0; i