39 "hermite",
"legendre",
"clenshaw-curtis",
"gauss-patterson",
"rys",
"jacobi" };
53 "complete",
"tensor",
"total",
"smolyak" };
73 const std::pair<int,int>& b)
const {
74 return (a.second == b.second) ? (a.first < b.first) : (a.second > b.second);
84 MPI_Init(&argc,&argv);
90 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
92 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
94 CLP.
setOption(
"order", &p,
"Polynomial order");
95 double drop = 1.0e-12;
96 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
97 std::string file =
"A.mm";
98 CLP.
setOption(
"filename", &file,
"Matrix Market filename");
108 CLP.
setOption(
"product_basis", &prod_basis_type,
111 "Product basis type");
113 CLP.
setOption(
"alpha", &alpha,
"Jacobi alpha index");
115 CLP.
setOption(
"beta", &beta,
"Jacobi beta index");
117 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
118 bool use_old =
false;
119 CLP.
setOption(
"old",
"new", &use_old,
"Use old or new Cijk algorithm");
121 CLP.
setOption(
"tile_size", &tile_size,
"Tile size");
124 CLP.
parse( argc, argv );
128 for (
int i=0; i<d; i++) {
131 p,
true, growth_type));
134 p,
true, growth_type));
143 else if (basis_type ==
RYS)
145 p, 1.0,
true, growth_type));
146 else if (basis_type ==
JACOBI)
148 p, alpha, beta,
true, growth_type));
154 bases, drop, use_old));
155 else if (prod_basis_type ==
TENSOR)
159 else if (prod_basis_type ==
TOTAL)
163 else if (prod_basis_type ==
SMOLYAK) {
167 bases, index_set, drop));
174 Cijk = basis->computeTripleProductTensor();
176 Cijk = basis->computeLinearTripleProductTensor();
178 int sz = basis->size();
179 std::cout <<
"basis size = " << sz
180 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
189 k_sz = basis->dimension()+1;
190 int nj_tiles = j_sz / tile_size;
191 int nk_tiles = k_sz / tile_size;
192 if (j_sz - nj_tiles*tile_size > 0)
194 if (k_sz - nk_tiles*tile_size > 0)
197 for (
int i=0; i<sz; ++i) {
199 nz[i].nz_tiles.
resize(nj_tiles);
200 for (
int j=0;
j<nj_tiles; ++
j)
201 nz[i].nz_tiles[
j].resize(nk_tiles);
205 Cijk_type::k_iterator k_begin = Cijk->k_begin();
206 Cijk_type::k_iterator k_end = Cijk->k_end();
207 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
209 int k_tile = k / tile_size;
210 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
211 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
212 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
214 int j_tile = j / tile_size;
215 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
216 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
217 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
220 ++nz[i].nz_tiles[j_tile][k_tile];
232 for (
int i=0; i<nz.
size(); ++i) {
234 std::cout << std::setw(w_index) << idx <<
" "
235 << basis->term(idx) <<
": "
236 << std::setw(w_nz) << nz[i].total_nz
238 for (
int j=0;
j<nj_tiles; ++
j)
239 for (
int k=0; k<nk_tiles; ++k)
240 std::cout << std::setw(w_tile) << nz[i].nz_tiles[
j][k] <<
" ";
241 std::cout << std::endl;
247 for (
int j=0;
j<nj_tiles; ++
j)
248 total_nz_tiles[
j].resize(nk_tiles);
249 for (
int i=0; i<nz.
size(); ++i) {
250 total_nz += nz[i].total_nz;
251 for (
int j=0;
j<nj_tiles; ++
j)
252 for (
int k=0; k<nk_tiles; ++k)
253 total_nz_tiles[
j][k] += nz[i].nz_tiles[
j][k];
255 int w_total = (w_index+1) + (2*basis->dimension()+5) + w_nz;
256 std::cout << std::endl << std::setw(w_total) << total_nz <<
", ";
257 for (
int j=0;
j<nj_tiles; ++
j)
258 for (
int k=0; k<nk_tiles; ++k)
259 std::cout << std::setw(w_tile) << total_nz_tiles[
j][k] <<
" ";
260 std::cout << std::endl;
264 for (
int j=0;
j<nj_tiles; ++
j) {
266 for (
int k=0; k<nk_tiles; ++k)
267 Cijk_tile[
j][k] =
rcp(
new Cijk_type);
269 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
271 int k_tile = k / tile_size;
272 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
273 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
274 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
276 int j_tile = j / tile_size;
277 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
278 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
279 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
281 double c =
value(i_it);
282 Cijk_tile[j_tile][k_tile]->add_term(i,j,k,c);
286 for (
int j=0;
j<nj_tiles; ++
j)
287 for (
int k=0; k<nk_tiles; ++k)
288 Cijk_tile[
j][k]->fillComplete();
293 for (
int j_tile=0; j_tile<nj_tiles; ++j_tile) {
294 nz_tile[j_tile].
resize(nk_tiles);
295 sorted_nz_tile[j_tile].
resize(nk_tiles);
296 for (
int k_tile=0; k_tile<nk_tiles; ++k_tile) {
299 Cijk_type::k_iterator k_begin = Cijk_tile[j_tile][k_tile]->k_begin();
300 Cijk_type::k_iterator k_end = Cijk_tile[j_tile][k_tile]->k_end();
301 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
303 Cijk_type::kj_iterator j_begin =
304 Cijk_tile[j_tile][k_tile]->j_begin(k_it);
305 Cijk_type::kj_iterator j_end =
306 Cijk_tile[j_tile][k_tile]->j_end(k_it);
307 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
309 Cijk_type::kji_iterator i_begin =
310 Cijk_tile[j_tile][k_tile]->i_begin(j_it);
311 Cijk_type::kji_iterator i_end =
312 Cijk_tile[j_tile][k_tile]->i_end(j_it);
313 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it){
315 if (nz_tile[j_tile][k_tile].count(i) == 0)
316 nz_tile[j_tile][k_tile][i] = 1;
318 ++(nz_tile[j_tile][k_tile][i]);
324 sorted_nz_tile[j_tile][k_tile].
resize(nz_tile[j_tile][k_tile].size());
326 for (std::map<int,int>::iterator it = nz_tile[j_tile][k_tile].begin();
327 it != nz_tile[j_tile][k_tile].
end(); ++it) {
328 sorted_nz_tile[j_tile][k_tile][idx] =
329 std::make_pair(it->first, it->second);
332 std::sort( sorted_nz_tile[j_tile][k_tile].begin(),
333 sorted_nz_tile[j_tile][k_tile].end(),
337 std::cout << std::endl
338 <<
"Tile (" << j_tile <<
", " << k_tile <<
"):" << std::endl;
339 for (
int i=0; i<sorted_nz_tile[j_tile][k_tile].
size(); ++i) {
340 int idx = sorted_nz_tile[j_tile][k_tile][i].first;
341 std::cout << std::setw(w_index) << idx <<
" "
342 << basis->term(idx) <<
": "
343 << std::setw(w_nz) << sorted_nz_tile[j_tile][k_tile][i].second
346 std::cout << std::endl;
352 catch (std::exception& e) {
353 std::cout << e.what() << std::endl;
const ProductBasisType prod_basis_type_values[]
Hermite polynomial basis.
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
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[]
bool operator()(const CijkNonzeros &a, const CijkNonzeros &b) const
bool operator()(const std::pair< int, int > &a, const std::pair< int, int > &b) const
Legendre polynomial basis using Gauss-Patterson quadrature points.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
const int num_growth_types
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
void resize(size_type new_size, const value_type &x=value_type())
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.
Stokhos::Sparse3Tensor< int, double > Cijk_type
int main(int argc, char **argv)
An isotropic total order index set.
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
void setDocString(const char doc_string[])
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
const int num_basis_types
Array< Array< int > > nz_tiles
const char * prod_basis_type_names[]