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 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Stokhos.hpp"
44 
45 // basis
46 //
47 // usage:
48 // basis [options]
49 //
50 // output:
51 // prints the dimensionality and corresponding sparse-grid size for
52 // various multi-variate basis choices.
53 
54 // Basis types
56 const int num_basis_types = 6;
59 const char *basis_type_names[] = {
60  "hermite", "legendre", "clenshaw-curtis", "gauss-patterson", "rys", "jacobi" };
61 
62 // Growth policies
63 const int num_growth_types = 2;
66 const char *growth_type_names[] = { "slow", "moderate" };
67 
68 // Product Basis types
70 const int num_prod_basis_types = 4;
73 const char *prod_basis_type_names[] = {
74  "complete", "tensor", "total", "smolyak" };
75 
76 // Ordering types
78 const int num_ordering_types = 3;
81 const char *ordering_type_names[] = {
82  "total", "lexicographic", "morton-z" };
83 
84 int main(int argc, char **argv)
85 {
86  try {
87 
88  // Setup command line options
90  CLP.setDocString(
91  "This example prints out the dimensionality of various basis choices.\n");
92  int d = 3;
93  CLP.setOption("dimension", &d, "Stochastic dimension");
94  int p = 5;
95  CLP.setOption("order", &p, "Polynomial order");
96  double drop = 1.0e-12;
97  CLP.setOption("drop", &drop, "Drop tolerance");
99  CLP.setOption("basis", &basis_type,
101  "Basis type");
103  CLP.setOption("growth", &growth_type,
105  "Growth type");
106  ProductBasisType prod_basis_type = COMPLETE;
107  CLP.setOption("product_basis", &prod_basis_type,
110  "Product basis type");
111  OrderingType ordering_type = TOTAL_ORDERING;
112  CLP.setOption("ordering", &ordering_type,
115  "Product basis ordering");
116  double alpha = 1.0;
117  CLP.setOption("alpha", &alpha, "Jacobi alpha index");
118  double beta = 1.0;
119  CLP.setOption("beta", &beta, "Jacobi beta index");
120 
121  // Parse arguments
122  CLP.parse( argc, argv );
123 
124  // Basis
126  for (int i=0; i<d; i++) {
127  if (basis_type == HERMITE)
129  p, true, growth_type));
130  else if (basis_type == LEGENDRE)
132  p, true, growth_type));
133  else if (basis_type == CC_LEGENDRE)
134  bases[i] =
136  p, true));
137  else if (basis_type == GP_LEGENDRE)
138  bases[i] =
140  p, true));
141  else if (basis_type == RYS)
143  p, 1.0, true, growth_type));
144  else if (basis_type == JACOBI)
146  p, alpha, beta, true, growth_type));
147  }
152  if (prod_basis_type == COMPLETE)
153  basis =
155  bases, drop));
156  else if (prod_basis_type == TENSOR) {
157  if (ordering_type == TOTAL_ORDERING)
158  basis =
160  bases, drop));
161  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
162  basis =
164  bases, drop));
165  else if (ordering_type == MORTON_Z_ORDERING)
166  basis =
168  bases, drop));
169  }
170  else if (prod_basis_type == TOTAL) {
171  if (ordering_type == TOTAL_ORDERING)
172  basis =
174  bases, drop));
175  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
176  basis =
178  bases, drop));
179  else if (ordering_type == MORTON_Z_ORDERING)
180  basis =
182  bases, drop));
183  }
184  else if (prod_basis_type == SMOLYAK) {
185  Stokhos::TotalOrderIndexSet<int> index_set(d, p);
186  if (ordering_type == TOTAL_ORDERING)
187  basis =
189  bases, index_set, drop));
190  else if (ordering_type == LEXICOGRAPHIC_ORDERING)
191  basis =
193  bases, index_set, drop));
194  else if (ordering_type == MORTON_Z_ORDERING)
195  basis =
197  bases, index_set, drop));
198  }
199 
200  Stokhos::TotalOrderIndexSet<int> index_set(d, p);
203 
204  std::cout << "order = " << p << " dim = " << d
205  << " basis size = " << basis->size()
206  << " sparse grid size = " << quad->size()
207  << std::endl;
208  }
209  catch (std::exception& e) {
210  std::cout << e.what() << std::endl;
211  }
212 
213  return 0;
214 }
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[]