Stokhos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
example
simple
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
55
enum
BasisType
{
HERMITE
,
LEGENDRE
,
CC_LEGENDRE
,
GP_LEGENDRE
,
RYS
,
JACOBI
};
56
const
int
num_basis_types
= 6;
57
const
BasisType
basis_type_values
[] = {
58
HERMITE
,
LEGENDRE
,
CC_LEGENDRE
,
GP_LEGENDRE
,
RYS
,
JACOBI
};
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;
64
const
Stokhos::GrowthPolicy
growth_type_values
[] = {
65
Stokhos::SLOW_GROWTH
,
Stokhos::MODERATE_GROWTH
};
66
const
char
*
growth_type_names
[] = {
"slow"
,
"moderate"
};
67
68
// Product Basis types
69
enum
ProductBasisType
{
COMPLETE
,
TENSOR
,
TOTAL
,
SMOLYAK
};
70
const
int
num_prod_basis_types
= 4;
71
const
ProductBasisType
prod_basis_type_values
[] = {
72
COMPLETE
,
TENSOR
,
TOTAL
,
SMOLYAK
};
73
const
char
*
prod_basis_type_names
[] = {
74
"complete"
,
"tensor"
,
"total"
,
"smolyak"
};
75
76
// Ordering types
77
enum
OrderingType
{
TOTAL_ORDERING
,
LEXICOGRAPHIC_ORDERING
,
MORTON_Z_ORDERING
};
78
const
int
num_ordering_types
= 3;
79
const
OrderingType
ordering_type_values
[] = {
80
TOTAL_ORDERING
,
LEXICOGRAPHIC_ORDERING
,
MORTON_Z_ORDERING
};
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
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"
);
98
BasisType
basis_type
=
LEGENDRE
;
99
CLP
.setOption(
"basis"
, &
basis_type
,
100
num_basis_types
,
basis_type_values
,
basis_type_names
,
101
"Basis type"
);
102
Stokhos::GrowthPolicy
growth_type =
Stokhos::SLOW_GROWTH
;
103
CLP
.setOption(
"growth"
, &growth_type,
104
num_growth_types
,
growth_type_values
,
growth_type_names
,
105
"Growth type"
);
106
ProductBasisType
prod_basis_type =
COMPLETE
;
107
CLP
.setOption(
"product_basis"
, &prod_basis_type,
108
num_prod_basis_types
,
prod_basis_type_values
,
109
prod_basis_type_names
,
110
"Product basis type"
);
111
OrderingType
ordering_type =
TOTAL_ORDERING
;
112
CLP
.setOption(
"ordering"
, &ordering_type,
113
num_ordering_types
,
ordering_type_values
,
114
ordering_type_names
,
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] =
135
Teuchos::rcp(
new
Stokhos::ClenshawCurtisLegendreBasis<int,double>
(
136
p,
true
));
137
else
if
(
basis_type
==
GP_LEGENDRE
)
138
bases[i] =
139
Teuchos::rcp(
new
Stokhos::GaussPattersonLegendreBasis<int,double>
(
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;
149
typedef
Stokhos::TotalOrderLess< Stokhos::MultiIndex<int>
> total_less;
150
typedef
Stokhos::LexographicLess< Stokhos::MultiIndex<int>
> lexo_less;
151
typedef
Stokhos::MortonZLess< Stokhos::MultiIndex<int>
> z_less;
152
if
(prod_basis_type ==
COMPLETE
)
153
basis =
154
Teuchos::rcp(
new
Stokhos::CompletePolynomialBasis<int,double>
(
155
bases, drop));
156
else
if
(prod_basis_type ==
TENSOR
) {
157
if
(ordering_type ==
TOTAL_ORDERING
)
158
basis =
159
Teuchos::rcp(
new
Stokhos::TensorProductBasis<int,double,total_less>
(
160
bases, drop));
161
else
if
(ordering_type ==
LEXICOGRAPHIC_ORDERING
)
162
basis =
163
Teuchos::rcp(
new
Stokhos::TensorProductBasis<int,double,lexo_less>
(
164
bases, drop));
165
else
if
(ordering_type ==
MORTON_Z_ORDERING
)
166
basis =
167
Teuchos::rcp(
new
Stokhos::TensorProductBasis<int,double,z_less>
(
168
bases, drop));
169
}
170
else
if
(prod_basis_type ==
TOTAL
) {
171
if
(ordering_type ==
TOTAL_ORDERING
)
172
basis =
173
Teuchos::rcp(
new
Stokhos::TotalOrderBasis<int,double,total_less>
(
174
bases, drop));
175
else
if
(ordering_type ==
LEXICOGRAPHIC_ORDERING
)
176
basis =
177
Teuchos::rcp(
new
Stokhos::TotalOrderBasis<int,double,lexo_less>
(
178
bases, drop));
179
else
if
(ordering_type ==
MORTON_Z_ORDERING
)
180
basis =
181
Teuchos::rcp(
new
Stokhos::TotalOrderBasis<int,double,z_less>
(
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 =
188
Teuchos::rcp(
new
Stokhos::SmolyakBasis<int,double,total_less>
(
189
bases, index_set, drop));
190
else
if
(ordering_type ==
LEXICOGRAPHIC_ORDERING
)
191
basis =
192
Teuchos::rcp(
new
Stokhos::SmolyakBasis<int,double,lexo_less>
(
193
bases, index_set, drop));
194
else
if
(ordering_type ==
MORTON_Z_ORDERING
)
195
basis =
196
Teuchos::rcp(
new
Stokhos::SmolyakBasis<int,double,z_less>
(
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
}
Stokhos.hpp
argv
char * argv[]
Definition
Stokhos_HouseTriDiagUnitTest.cpp:286
main
int main(int argc, char **argv)
Definition
basis.cpp:84
basis_type_values
const BasisType basis_type_values[]
Definition
cijk_nonzeros.cpp:70
num_basis_types
const int num_basis_types
Definition
cijk_nonzeros.cpp:69
num_growth_types
const int num_growth_types
Definition
cijk_nonzeros.cpp:76
basis_type_names
const char * basis_type_names[]
Definition
cijk_nonzeros.cpp:72
num_prod_basis_types
const int num_prod_basis_types
Definition
cijk_nonzeros.cpp:83
prod_basis_type_names
const char * prod_basis_type_names[]
Definition
cijk_nonzeros.cpp:86
prod_basis_type_values
const ProductBasisType prod_basis_type_values[]
Definition
cijk_nonzeros.cpp:84
growth_type_names
const char * growth_type_names[]
Definition
cijk_nonzeros.cpp:79
growth_type_values
const Stokhos::GrowthPolicy growth_type_values[]
Definition
cijk_nonzeros.cpp:77
BasisType
BasisType
Definition
cijk_nonzeros.cpp:68
JACOBI
@ JACOBI
Definition
cijk_nonzeros.cpp:68
CC_LEGENDRE
@ CC_LEGENDRE
Definition
cijk_nonzeros.cpp:68
LEGENDRE
@ LEGENDRE
Definition
cijk_nonzeros.cpp:68
HERMITE
@ HERMITE
Definition
cijk_nonzeros.cpp:68
RYS
@ RYS
Definition
cijk_nonzeros.cpp:68
GP_LEGENDRE
@ GP_LEGENDRE
Definition
cijk_nonzeros.cpp:68
ProductBasisType
ProductBasisType
Definition
cijk_nonzeros.cpp:82
COMPLETE
@ COMPLETE
Definition
cijk_nonzeros.cpp:82
SMOLYAK
@ SMOLYAK
Definition
cijk_nonzeros.cpp:82
TOTAL
@ TOTAL
Definition
cijk_nonzeros.cpp:82
TENSOR
@ TENSOR
Definition
cijk_nonzeros.cpp:82
OrderingType
OrderingType
Definition
cijk_partition.cpp:91
LEXICOGRAPHIC_ORDERING
@ LEXICOGRAPHIC_ORDERING
Definition
cijk_partition.cpp:91
TOTAL_ORDERING
@ TOTAL_ORDERING
Definition
cijk_partition.cpp:91
num_ordering_types
const int num_ordering_types
Definition
cijk_partition.cpp:92
ordering_type_names
const char * ordering_type_names[]
Definition
cijk_partition.cpp:95
ordering_type_values
const OrderingType ordering_type_values[]
Definition
cijk_partition.cpp:93
Stokhos::ClenshawCurtisLegendreBasis
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
Definition
Stokhos_ClenshawCurtisLegendreBasis.hpp:58
Stokhos::CompletePolynomialBasis
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Definition
Stokhos_CompletePolynomialBasis.hpp:74
Stokhos::GaussPattersonLegendreBasis
Legendre polynomial basis using Gauss-Patterson quadrature points.
Definition
Stokhos_GaussPattersonLegendreBasis.hpp:58
Stokhos::HermiteBasis
Hermite polynomial basis.
Definition
Stokhos_HermiteBasis.hpp:68
Stokhos::JacobiBasis
Jacobi polynomial basis.
Definition
Stokhos_JacobiBasis.hpp:95
Stokhos::LegendreBasis
Legendre polynomial basis.
Definition
Stokhos_LegendreBasis.hpp:68
Stokhos::LexographicLess
A comparison functor implementing a strict weak ordering based lexographic ordering.
Definition
Stokhos_ProductBasisUtils.hpp:799
Stokhos::MortonZLess
A comparison functor implementing a strict weak ordering based Morton Z-ordering.
Definition
Stokhos_ProductBasisUtils.hpp:902
Stokhos::RysBasis
Rys polynomial basis.
Definition
Stokhos_RysBasis.hpp:66
Stokhos::SmolyakBasis
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Definition
Stokhos_SmolyakBasis.hpp:63
Stokhos::SmolyakSparseGridQuadrature
Defines quadrature for a tensor product basis by Smolyak sparse grids.
Definition
Stokhos_SmolyakSparseGridQuadrature.hpp:64
Stokhos::TensorProductBasis
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials.
Definition
Stokhos_TensorProductBasis.hpp:70
Stokhos::TotalOrderBasis
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
Definition
Stokhos_TotalOrderBasis.hpp:69
Stokhos::TotalOrderIndexSet
An isotropic total order index set.
Definition
Stokhos_ProductBasisUtils.hpp:215
Stokhos::TotalOrderLess
A comparison functor implementing a strict weak ordering based total-order ordering,...
Definition
Stokhos_ProductBasisUtils.hpp:849
CLP
@ CLP
Definition
gram_schmidt_example3.cpp:87
basis_type
Stokhos::LegendreBasis< int, double > basis_type
Definition
gram_schmidt_example.cpp:52
Stokhos::GrowthPolicy
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
Definition
Stokhos_RecurrenceBasis.hpp:50
Stokhos::SLOW_GROWTH
@ SLOW_GROWTH
Definition
Stokhos_RecurrenceBasis.hpp:51
Stokhos::MODERATE_GROWTH
@ MODERATE_GROWTH
Definition
Stokhos_RecurrenceBasis.hpp:52
MORTON_Z_ORDERING
@ MORTON_Z_ORDERING
Definition
sparsity_example.cpp:93
Generated by
1.17.0