// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER // ensemble_example // // usage: // ensemble_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 using a pseudospectral approach // for computing v via embedded ensemble propagation. #include "Stokhos_Sacado.hpp" #include "Stokhos_Sacado_Kokkos.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 pce_storage_type; typedef Sacado::PCE::OrthogPoly pce_type; // Typename of ensemble scalar type const int EnsembleSize = 8; typedef Stokhos::StaticFixedStorage ensemble_storage_type; typedef Sacado::MP::Vector ensemble_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 using NISP with ensemble propagation // // Extract quadrature data const int pce_size = basis->size(); const int num_quad_points = quad->size(); const Array& quad_weights = quad->getQuadWeights(); const Array< Array >& quad_points = quad->getQuadPoints(); const Array< Array >& quad_values = quad->getBasisAtQuadPoints(); // Loop over quadrature points in blocks of size EnsembleSize pce_type v(expn); ensemble_type u_ensemble; for (int qp_block=0; qp_blocknorm_squared(pc); for (int qp=0; qp