Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_ExpansionFactoryImp.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_Assert.hpp"
11 
12 #include "Stokhos_BasisFactory.hpp"
17 //#include "Stokhos_DerivOrthogPolyExpansion.hpp"
21 
22 template <typename ordinal_type, typename value_type>
26 {
27  // Check if expansion is already there
28  Teuchos::ParameterList& expParams = sgParams.sublist("Expansion");
29  Teuchos::RCP< Stokhos::OrthogPolyExpansion<ordinal_type,value_type> > expansion = expParams.template get< Teuchos::RCP< Stokhos::OrthogPolyExpansion<ordinal_type,value_type> > >("Stochastic Galerkin Expansion", Teuchos::null);
30  if (expansion != Teuchos::null)
31  return expansion;
32 
33  // Get basis
34  Teuchos::ParameterList& basisParams = sgParams.sublist("Basis");
36  if (basisParams.template isType< Teuchos::RCP< const Stokhos::OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis"))
37  basis = basisParams.template get< Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis");
38  else {
40  basisParams.set("Stochastic Galerkin Basis", basis);
41  }
42 
43  // Get 3-tensor
45  if (sgParams.template isType<Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type,value_type> > >("Triple Product Tensor"))
46  Cijk = sgParams.template get<Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type,value_type> > >("Triple Product Tensor");
47  else {
48  std::string tp_type = sgParams.get("Triple Product Size", "Full");
50  tp_type != "Full" && tp_type != "Linear",
52  std::endl << "Invalid triple product expansion type " << tp_type <<
53  std::endl);
54 
55  if (tp_type == "Full")
56  Cijk = basis->computeTripleProductTensor();
57  else
58  Cijk = basis->computeLinearTripleProductTensor();
59 
60  sgParams.set("Triple Product Tensor", Cijk);
61  }
62 
63  // Create expansion
64  std::string exp_type = expParams.get("Type", "Algebraic");
65  if (exp_type == "Algebraic")
66  expansion =
68 
69  else if (exp_type == "Quadrature") {
70  Teuchos::ParameterList& quadParams = sgParams.sublist("Quadrature");
72  if (quadParams.template isType<Teuchos::RCP<const Stokhos::Quadrature<ordinal_type,value_type> > >("Stochastic Galerkin Quadrature"))
73  quad = quadParams.template get<Teuchos::RCP<const Stokhos::Quadrature<ordinal_type,value_type> > >("Stochastic Galerkin Quadrature");
74  else {
75  quad =
77  quadParams.set("Stochastic Galerkin Quadrature", quad);
78  }
79  expansion =
81  }
82 
83  else if (exp_type == "For UQTK") {
84 #ifdef HAVE_STOKHOS_FORUQTK
85  typename Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>::EXPANSION_METHOD method =
86  expParams.get("ForUQTK Expansion Method",
87  Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>::TAYLOR);
88  value_type rtol = expParams.get("ForUQTK Expansion Tolerance", 1e-12);
89  expansion =
90  Teuchos::rcp(new Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>(basis, Cijk, method, rtol));
91 #else
93  std::endl <<
94  "Error! Stokhos::ExpansionFactory::create(): " <<
95  "ForUQTK expansion requires ForUQTK!" << std::endl);
96 #endif
97  }
98 
99  /*
100  else if (exp_type == "Derivative") {
101  Teuchos::RCP<const Stokhos::DerivBasis<ordinal_type,value_type> > deriv_basis = Teuchos::rcp_dynamic_cast<const Stokhos::DerivBasis<ordinal_type,value_type> >(basis, true);
102  Teuchos::RCP<Teuchos::SerialDenseMatrix<ordinal_type,value_type> > Bij;
103  if (sgParams.template isType<Teuchos::RCP<const Teuchos::SerialDenseMatrix<ordinal_type,value_type> > >("Derivative Double Product Tensor"))
104  Bij = sgParams.template get<const Teuchos::RCP<Teuchos::SerialDenseMatrix<ordinal_type,value_type> > >("Derivative Double Product Tensor");
105  else {
106  Bij = deriv_basis->computeDerivDoubleProductTensor();
107  sgParams.set("Derivative Double Product Tensor", Bij);
108  }
109  Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > Dijk;
110  if (sgParams.template isType<Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > >("Derivative Triple Product Tensor"))
111  Dijk = sgParams.template get<Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > >("Derivative Triple Product Tensor");
112  else {
113  Dijk = deriv_basis->computeDerivTripleProductTensor(Bij, Cijk);
114  sgParams.set("Derivative Triple Product Tensor", Dijk);
115  }
116  expansion =
117  Teuchos::rcp(new
118  Stokhos::DerivOrthogPolyExpansion<ordinal_type,value_type>(
119  deriv_basis, Bij, Cijk, Dijk));
120  }
121  */
122 
123  else if (exp_type == "Pseudospectral") {
125  Teuchos::ParameterList& psopParams =
126  sgParams.sublist("Pseudospectral Operator");
128  if (psopParams.template isType<Teuchos::RCP<const psop_type> >(
129  "Stochastic Galerkin Pseudospectral Operator"))
130  psop = psopParams.template get<Teuchos::RCP<const psop_type> >(
131  "Stochastic Galerkin Pseudospectral Operator");
132  else {
133  psop =
135  psopParams.set("Stochastic Galerkin Pseudospectral Operator", psop);
136  }
137  expansion =
139  }
140 
141  else
143  std::endl <<
144  "Error! Stokhos::ExpansionFactory::create(): " <<
145  "Invalid expansion type " << exp_type << std::endl);
146 
147  expParams.set("Stochastic Galerkin Expansion", expansion);
148  return expansion;
149 }
static Teuchos::RCP< const psop_type > create(Teuchos::ParameterList &sgParams)
Generate pseudospectral operator object.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
T & get(ParameterList &l, const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
An operator interface for building pseudo-spectral approximations.
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Orthogonal polynomial expansions limited to algebraic operations.
static Teuchos::RCP< Stokhos::OrthogPolyExpansion< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate expansion.
Abstract base class for multivariate orthogonal polynomials.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class for quadrature methods.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.
static Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate quadrature object.
Orthogonal polynomial expansions based on numerical quadrature.
Orthogonal polynomial expansions based on numerical quadrature.