Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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"
43#include "Teuchos_CommandLineProcessor.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
56const int num_basis_types = 6;
59const char *basis_type_names[] = {
60 "hermite", "legendre", "clenshaw-curtis", "gauss-patterson", "rys", "jacobi" };
61
62// Growth policies
63const int num_growth_types = 2;
66const char *growth_type_names[] = { "slow", "moderate" };
67
68// Product Basis types
73const char *prod_basis_type_names[] = {
74 "complete", "tensor", "total", "smolyak" };
75
76// Ordering types
78const int num_ordering_types = 3;
81const char *ordering_type_names[] = {
82 "total", "lexicographic", "morton-z" };
83
84int main(int argc, char **argv)
85{
86 try {
87
88 // Setup command line options
89 Teuchos::CommandLineProcessor CLP;
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
125 Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d);
126 for (int i=0; i<d; i++) {
127 if (basis_type == HERMITE)
128 bases[i] = Teuchos::rcp(new Stokhos::HermiteBasis<int,double>(
129 p, true, growth_type));
130 else if (basis_type == LEGENDRE)
131 bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<int,double>(
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)
142 bases[i] = Teuchos::rcp(new Stokhos::RysBasis<int,double>(
143 p, 1.0, true, growth_type));
144 else if (basis_type == JACOBI)
145 bases[i] = Teuchos::rcp(new Stokhos::JacobiBasis<int,double>(
146 p, alpha, beta, true, growth_type));
147 }
148 Teuchos::RCP<const Stokhos::ProductBasis<int,double> > basis;
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);
201 Teuchos::RCP<const Stokhos::Quadrature<int,double> > quad =
202 Teuchos::rcp(new Stokhos::SmolyakSparseGridQuadrature<int,double>(basis, index_set));
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}
int main(int argc, char **argv)
Definition: basis.cpp:84
@ MORTON_Z_ORDERING
Definition: basis.cpp:77
@ LEXICOGRAPHIC_ORDERING
Definition: basis.cpp:77
@ TOTAL_ORDERING
Definition: basis.cpp:77
const int num_ordering_types
Definition: basis.cpp:78
const BasisType basis_type_values[]
Definition: basis.cpp:57
const char * ordering_type_names[]
Definition: basis.cpp:81
const OrderingType ordering_type_values[]
Definition: basis.cpp:79
const int num_basis_types
Definition: basis.cpp:56
const int num_growth_types
Definition: basis.cpp:63
const char * basis_type_names[]
Definition: basis.cpp:59
const int num_prod_basis_types
Definition: basis.cpp:70
const char * prod_basis_type_names[]
Definition: basis.cpp:73
const ProductBasisType prod_basis_type_values[]
Definition: basis.cpp:71
const char * growth_type_names[]
Definition: basis.cpp:66
const Stokhos::GrowthPolicy growth_type_values[]
Definition: basis.cpp:64
@ JACOBI
Definition: basis.cpp:55
@ CC_LEGENDRE
Definition: basis.cpp:55
@ LEGENDRE
Definition: basis.cpp:55
@ HERMITE
Definition: basis.cpp:55
@ RYS
Definition: basis.cpp:55
@ GP_LEGENDRE
Definition: basis.cpp:55
@ COMPLETE
Definition: basis.cpp:69
@ SMOLYAK
Definition: basis.cpp:69
@ TOTAL
Definition: basis.cpp:69
@ TENSOR
Definition: basis.cpp:69
BasisType
ProductBasisType
OrderingType
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Legendre polynomial basis using Gauss-Patterson quadrature points.
Hermite polynomial basis.
Jacobi polynomial basis.
Legendre polynomial basis.
A comparison functor implementing a strict weak ordering based lexographic ordering.
A comparison functor implementing a strict weak ordering based Morton Z-ordering.
Rys polynomial basis.
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Defines quadrature for a tensor product basis by Smolyak sparse grids.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
An isotropic total order index set.
A comparison functor implementing a strict weak ordering based total-order ordering,...
GrowthPolicy
Enumerated type for determining Smolyak growth policies.