Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
basis.cpp
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 "Stokhos.hpp"
12 
13 // basis
14 //
15 // usage:
16 // basis [options]
17 //
18 // output:
19 // prints the dimensionality and corresponding sparse-grid size for
20 // various multi-variate basis choices.
21 
22 // Basis types
24 const int num_basis_types = 6;
27 const char *basis_type_names[] = {
28  "hermite", "legendre", "clenshaw-curtis", "gauss-patterson", "rys", "jacobi" };
29 
30 // Growth policies
31 const int num_growth_types = 2;
34 const char *growth_type_names[] = { "slow", "moderate" };
35 
36 // Product Basis types
38 const int num_prod_basis_types = 4;
41 const char *prod_basis_type_names[] = {
42  "complete", "tensor", "total", "smolyak" };
43 
44 // Ordering types
46 const int num_ordering_types = 3;
49 const char *ordering_type_names[] = {
50  "total", "lexicographic", "morton-z" };
51 
52 int main(int argc, char **argv)
53 {
54  try {
55 
56  // Setup command line options
58  CLP.setDocString(
59  "This example prints out the dimensionality of various basis choices.\n");
60  int d = 3;
61  CLP.setOption("dimension", &d, "Stochastic dimension");
62  int p = 5;
63  CLP.setOption("order", &p, "Polynomial order");
64  double drop = 1.0e-12;
65  CLP.setOption("drop", &drop, "Drop tolerance");
67  CLP.setOption("basis", &basis_type,
69  "Basis type");
71  CLP.setOption("growth", &growth_type,
73  "Growth type");
74  ProductBasisType prod_basis_type = COMPLETE;
75  CLP.setOption("product_basis", &prod_basis_type,
78  "Product basis type");
79  OrderingType ordering_type = TOTAL_ORDERING;
80  CLP.setOption("ordering", &ordering_type,
83  "Product basis ordering");
84  double alpha = 1.0;
85  CLP.setOption("alpha", &alpha, "Jacobi alpha index");
86  double beta = 1.0;
87  CLP.setOption("beta", &beta, "Jacobi beta index");
88 
89  // Parse arguments
90  CLP.parse( argc, argv );
91 
92  // Basis
94  for (int i=0; i<d; i++) {
95  if (basis_type == HERMITE)
97  p, true, growth_type));
98  else if (basis_type == LEGENDRE)
100  p, true, growth_type));
101  else if (basis_type == CC_LEGENDRE)
102  bases[i] =
104  p, true));
105  else if (basis_type == GP_LEGENDRE)
106  bases[i] =
108  p, true));
109  else if (basis_type == RYS)
111  p, 1.0, true, growth_type));
112  else if (basis_type == JACOBI)
114  p, alpha, beta, true, growth_type));
115  }
120  if (prod_basis_type == COMPLETE)
121  basis =
123  bases, drop));
124  else if (prod_basis_type == TENSOR) {
125  if (ordering_type == TOTAL_ORDERING)
126  basis =
128  bases, drop));
129  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
130  basis =
132  bases, drop));
133  else if (ordering_type == MORTON_Z_ORDERING)
134  basis =
136  bases, drop));
137  }
138  else if (prod_basis_type == TOTAL) {
139  if (ordering_type == TOTAL_ORDERING)
140  basis =
142  bases, drop));
143  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
144  basis =
146  bases, drop));
147  else if (ordering_type == MORTON_Z_ORDERING)
148  basis =
150  bases, drop));
151  }
152  else if (prod_basis_type == SMOLYAK) {
153  Stokhos::TotalOrderIndexSet<int> index_set(d, p);
154  if (ordering_type == TOTAL_ORDERING)
155  basis =
157  bases, index_set, drop));
158  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
159  basis =
161  bases, index_set, drop));
162  else if (ordering_type == MORTON_Z_ORDERING)
163  basis =
165  bases, index_set, drop));
166  }
167 
168  Stokhos::TotalOrderIndexSet<int> index_set(d, p);
171 
172  std::cout << "order = " << p << " dim = " << d
173  << " basis size = " << basis->size()
174  << " sparse grid size = " << quad->size()
175  << std::endl;
176  }
177  catch (std::exception& e) {
178  std::cout << e.what() << std::endl;
179  }
180 
181  return 0;
182 }
const ProductBasisType prod_basis_type_values[]
Hermite polynomial basis.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
const char * basis_type_names[]
const BasisType basis_type_values[]
const int num_prod_basis_types
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
const char * growth_type_names[]
const OrderingType ordering_type_values[]
const int num_ordering_types
Defines quadrature for a tensor product basis by Smolyak sparse grids.
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
OrderingType
Legendre polynomial basis using Gauss-Patterson quadrature points.
ProductBasisType
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Rys polynomial basis.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
const int num_growth_types
Jacobi polynomial basis.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
BasisType
const Stokhos::GrowthPolicy growth_type_values[]
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.
int main(int argc, char **argv)
An isotropic total order index set.
A comparison functor implementing a strict weak ordering based Morton Z-ordering. ...
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
void setDocString(const char doc_string[])
A comparison functor implementing a strict weak ordering based lexographic ordering.
const int num_basis_types
const char * ordering_type_names[]
const char * prod_basis_type_names[]