Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BasisFactoryImp.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 <sstream>
11 #include "Teuchos_Assert.hpp"
12 #include "Teuchos_Array.hpp"
13 
17 #include "Stokhos_HermiteBasis.hpp"
18 #include "Stokhos_JacobiBasis.hpp"
19 #include "Stokhos_RysBasis.hpp"
23 #include "Stokhos_SmolyakBasis.hpp"
24 
25 template <typename ordinal_type, typename value_type>
29 {
30  Teuchos::ParameterList& basisParams = sgParams.sublist("Basis");
31 
32  // Check if basis is already there
34  = basisParams.template get< Teuchos::RCP< const OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis", Teuchos::null);
35  if (basis != Teuchos::null)
36  return basis;
37 
38  ordinal_type dimension = basisParams.get("Dimension", 1);
39  bool isotropic = basisParams.get("Isotropic", false);
40 
42  for (ordinal_type i=0; i<dimension; i++) {
43  if (isotropic)
44  bases[i] = create1DBasis(basisParams);
45  else {
46  std::ostringstream ss;
47  ss << "Basis " << i;
48  Teuchos::ParameterList& bp = basisParams.sublist(ss.str());
49  bases[i] = create1DBasis(bp);
50  }
51  }
52 
53  std::string type = basisParams.get("Multivariate Type", "Complete");
54  value_type drop = basisParams.get("Cijk Drop Tolerance", 1e-12);
55  std::string ordering = basisParams.get("Coefficient Ordering", "Total");
56 
57  if (type == "Complete") {
58  bool use_old = basisParams.get("Use Old Cijk Algorithm", false);
59  basis =
61  bases, drop, use_old));
62  }
63 
64  else if (type == "Tensor Product") {
65  if (ordering == "Total")
66  basis =
68  else if (ordering == "Lexicographical")
69  basis =
71  else
74  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
75  }
76 
77  else if (type == "Total Order") {
78  if (ordering == "Total")
79  basis =
81  else if (ordering == "Lexicographical")
82  basis =
84  else
87  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
88  }
89 
90  else if (type == "Smolyak") {
91  ordinal_type order = basisParams.template get<ordinal_type>("Order");
92  TotalOrderIndexSet<ordinal_type> index_set(dimension, order);
93  if (ordering == "Total")
94  basis =
96  else if (ordering == "Lexicographical")
97  basis =
99  else
102  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
103  }
104 
105  else
108  std::endl << "Invalid multivariate basis type " << type << std::endl);
109 
110 
111  basisParams.set("Stochastic Galerkin Basis", basis);
112 
113  return basis;
114 }
115 
116 template <typename ordinal_type, typename value_type>
120 {
122 
123  std::string type = bp.get("Type","Legendre");
124  ordinal_type order = bp.get("Order", 3);
125  bool normalize = bp.get("Normalize", false);
126  bool isotropic = bp.get("Isotropic", false);
127 
128  std::string growth_string = bp.get("Growth Policy", "Slow");
129  GrowthPolicy growth;
130  if (growth_string == "Slow")
131  growth = SLOW_GROWTH;
132  else if (growth_string == "Moderate")
133  growth = MODERATE_GROWTH;
134  else
137  std::endl << "Invalid growth policy " << growth_string << std::endl);
138 
139  if (type == "Legendre")
140  basis = Teuchos::rcp(new LegendreBasis<ordinal_type,value_type>(order, normalize, growth));
141  else if (type == "Clenshaw-Curtis") {
142  basis = Teuchos::rcp(new ClenshawCurtisLegendreBasis<ordinal_type,value_type>(order, normalize, isotropic));
143  }
144  else if (type == "Gauss-Patterson") {
145  basis = Teuchos::rcp(new GaussPattersonLegendreBasis<ordinal_type,value_type>(order, normalize, isotropic));
146  }
147  else if (type == "Hermite")
148  basis = Teuchos::rcp(new HermiteBasis<ordinal_type,value_type>(order, normalize, growth));
149  else if (type == "Jacobi") {
150  value_type alpha = bp.get<value_type>("Jacobi Alpha");
151  value_type beta = bp.get<value_type>("Jacobi Beta");
152  basis = Teuchos::rcp(new JacobiBasis<ordinal_type,value_type>(order, alpha, beta, normalize, growth));
153  }
154  else if (type == "Rys") {
155  value_type cut = bp.get("Weight Cut", 1.0);
156  basis = Teuchos::rcp(new RysBasis<ordinal_type,value_type>(order, cut, normalize, growth));
157  }
158  else
161  std::endl << "Invalid basis type " << type << std::endl);
162 
163  return basis;
164 }
Hermite polynomial basis.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
T & get(ParameterList &l, const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
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)
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
Legendre polynomial basis using Gauss-Patterson quadrature points.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Rys polynomial basis.
Jacobi polynomial basis.
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Legendre polynomial basis.
An isotropic total order index set.
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
static Teuchos::RCP< const Stokhos::OneDOrthogPolyBasis< ordinal_type, value_type > > create1DBasis(Teuchos::ParameterList &params)
Generate 1-D basis.
A comparison functor implementing a strict weak ordering based lexographic ordering.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.