// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "Teuchos_Assert.hpp" #include "Stokhos_BasisFactory.hpp" #include "Stokhos_QuadratureFactory.hpp" #include "Stokhos_AlgebraicOrthogPolyExpansion.hpp" #include "Stokhos_QuadOrthogPolyExpansion.hpp" #include "Stokhos_ForUQTKOrthogPolyExpansion.hpp" //#include "Stokhos_DerivOrthogPolyExpansion.hpp" #include "Stokhos_CompletePolynomialBasis.hpp" #include "Stokhos_PseudoSpectralOrthogPolyExpansion.hpp" #include "Stokhos_PseudoSpectralOperatorFactory.hpp" template Teuchos::RCP > Stokhos::ExpansionFactory:: create(Teuchos::ParameterList& sgParams) { // Check if expansion is already there Teuchos::ParameterList& expParams = sgParams.sublist("Expansion"); Teuchos::RCP< Stokhos::OrthogPolyExpansion > expansion = expParams.template get< Teuchos::RCP< Stokhos::OrthogPolyExpansion > >("Stochastic Galerkin Expansion", Teuchos::null); if (expansion != Teuchos::null) return expansion; // Get basis Teuchos::ParameterList& basisParams = sgParams.sublist("Basis"); Teuchos::RCP< const Stokhos::OrthogPolyBasis > basis; if (basisParams.template isType< Teuchos::RCP< const Stokhos::OrthogPolyBasis > >("Stochastic Galerkin Basis")) basis = basisParams.template get< Teuchos::RCP > >("Stochastic Galerkin Basis"); else { basis = Stokhos::BasisFactory::create(sgParams); basisParams.set("Stochastic Galerkin Basis", basis); } // Get 3-tensor Teuchos::RCP > Cijk; if (sgParams.template isType > >("Triple Product Tensor")) Cijk = sgParams.template get > >("Triple Product Tensor"); else { std::string tp_type = sgParams.get("Triple Product Size", "Full"); TEUCHOS_TEST_FOR_EXCEPTION( tp_type != "Full" && tp_type != "Linear", Teuchos::Exceptions::InvalidParameter, std::endl << "Invalid triple product expansion type " << tp_type << std::endl); if (tp_type == "Full") Cijk = basis->computeTripleProductTensor(); else Cijk = basis->computeLinearTripleProductTensor(); sgParams.set("Triple Product Tensor", Cijk); } // Create expansion std::string exp_type = expParams.get("Type", "Algebraic"); if (exp_type == "Algebraic") expansion = Teuchos::rcp(new Stokhos::AlgebraicOrthogPolyExpansion(basis, Cijk, Teuchos::rcp(&expParams,false))); else if (exp_type == "Quadrature") { Teuchos::ParameterList& quadParams = sgParams.sublist("Quadrature"); Teuchos::RCP > quad; if (quadParams.template isType > >("Stochastic Galerkin Quadrature")) quad = quadParams.template get > >("Stochastic Galerkin Quadrature"); else { quad = Stokhos::QuadratureFactory::create(sgParams); quadParams.set("Stochastic Galerkin Quadrature", quad); } expansion = Teuchos::rcp(new Stokhos::QuadOrthogPolyExpansion(basis, Cijk, quad, Teuchos::rcp(&expParams,false))); } else if (exp_type == "For UQTK") { #ifdef HAVE_STOKHOS_FORUQTK typename Stokhos::ForUQTKOrthogPolyExpansion::EXPANSION_METHOD method = expParams.get("ForUQTK Expansion Method", Stokhos::ForUQTKOrthogPolyExpansion::TAYLOR); value_type rtol = expParams.get("ForUQTK Expansion Tolerance", 1e-12); expansion = Teuchos::rcp(new Stokhos::ForUQTKOrthogPolyExpansion(basis, Cijk, method, rtol)); #else TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, std::endl << "Error! Stokhos::ExpansionFactory::create(): " << "ForUQTK expansion requires ForUQTK!" << std::endl); #endif } /* else if (exp_type == "Derivative") { Teuchos::RCP > deriv_basis = Teuchos::rcp_dynamic_cast >(basis, true); Teuchos::RCP > Bij; if (sgParams.template isType > >("Derivative Double Product Tensor")) Bij = sgParams.template get > >("Derivative Double Product Tensor"); else { Bij = deriv_basis->computeDerivDoubleProductTensor(); sgParams.set("Derivative Double Product Tensor", Bij); } Teuchos::RCP > Dijk; if (sgParams.template isType > >("Derivative Triple Product Tensor")) Dijk = sgParams.template get > >("Derivative Triple Product Tensor"); else { Dijk = deriv_basis->computeDerivTripleProductTensor(Bij, Cijk); sgParams.set("Derivative Triple Product Tensor", Dijk); } expansion = Teuchos::rcp(new Stokhos::DerivOrthogPolyExpansion( deriv_basis, Bij, Cijk, Dijk)); } */ else if (exp_type == "Pseudospectral") { typedef Stokhos::PseudoSpectralOperator psop_type; Teuchos::ParameterList& psopParams = sgParams.sublist("Pseudospectral Operator"); Teuchos::RCP psop; if (psopParams.template isType >( "Stochastic Galerkin Pseudospectral Operator")) psop = psopParams.template get >( "Stochastic Galerkin Pseudospectral Operator"); else { psop = Stokhos::PseudoSpectralOperatorFactory::create(sgParams); psopParams.set("Stochastic Galerkin Pseudospectral Operator", psop); } expansion = Teuchos::rcp(new Stokhos::PseudoSpectralOrthogPolyExpansion(basis, Cijk, psop, Teuchos::rcp(&expParams,false))); } else TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, std::endl << "Error! Stokhos::ExpansionFactory::create(): " << "Invalid expansion type " << exp_type << std::endl); expParams.set("Stochastic Galerkin Expansion", expansion); return expansion; }