73 "hermite",
"legendre",
"clenshaw-curtis",
"gauss-patterson",
"rys",
"jacobi" };
87 "complete",
"tensor",
"total",
"smolyak" };
107 const std::pair<int,int>& b)
const {
108 return (a.second == b.second) ? (a.first < b.first) : (a.second > b.second);
118 MPI_Init(&argc,&argv);
124 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
126 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
128 CLP.
setOption(
"order", &p,
"Polynomial order");
129 double drop = 1.0e-12;
130 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
131 std::string file =
"A.mm";
132 CLP.
setOption(
"filename", &file,
"Matrix Market filename");
142 CLP.
setOption(
"product_basis", &prod_basis_type,
145 "Product basis type");
147 CLP.
setOption(
"alpha", &alpha,
"Jacobi alpha index");
149 CLP.
setOption(
"beta", &beta,
"Jacobi beta index");
151 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
152 bool use_old =
false;
153 CLP.
setOption(
"old",
"new", &use_old,
"Use old or new Cijk algorithm");
155 CLP.
setOption(
"tile_size", &tile_size,
"Tile size");
158 CLP.
parse( argc, argv );
162 for (
int i=0; i<d; i++) {
165 p,
true, growth_type));
168 p,
true, growth_type));
177 else if (basis_type ==
RYS)
179 p, 1.0,
true, growth_type));
180 else if (basis_type ==
JACOBI)
182 p, alpha, beta,
true, growth_type));
188 bases, drop, use_old));
189 else if (prod_basis_type ==
TENSOR)
193 else if (prod_basis_type ==
TOTAL)
197 else if (prod_basis_type ==
SMOLYAK) {
201 bases, index_set, drop));
208 Cijk = basis->computeTripleProductTensor();
210 Cijk = basis->computeLinearTripleProductTensor();
212 int sz = basis->size();
213 std::cout <<
"basis size = " << sz
214 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
223 k_sz = basis->dimension()+1;
224 int nj_tiles = j_sz / tile_size;
225 int nk_tiles = k_sz / tile_size;
226 if (j_sz - nj_tiles*tile_size > 0)
228 if (k_sz - nk_tiles*tile_size > 0)
231 for (
int i=0; i<sz; ++i) {
233 nz[i].nz_tiles.
resize(nj_tiles);
234 for (
int j=0;
j<nj_tiles; ++
j)
235 nz[i].nz_tiles[
j].resize(nk_tiles);
239 Cijk_type::k_iterator k_begin = Cijk->k_begin();
240 Cijk_type::k_iterator k_end = Cijk->k_end();
241 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
243 int k_tile = k / tile_size;
244 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
245 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
246 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
248 int j_tile = j / tile_size;
249 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
250 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
251 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
254 ++nz[i].nz_tiles[j_tile][k_tile];
266 for (
int i=0; i<nz.
size(); ++i) {
268 std::cout << std::setw(w_index) << idx <<
" "
269 << basis->term(idx) <<
": "
270 << std::setw(w_nz) << nz[i].total_nz
272 for (
int j=0;
j<nj_tiles; ++
j)
273 for (
int k=0; k<nk_tiles; ++k)
274 std::cout << std::setw(w_tile) << nz[i].nz_tiles[
j][k] <<
" ";
275 std::cout << std::endl;
281 for (
int j=0;
j<nj_tiles; ++
j)
282 total_nz_tiles[
j].resize(nk_tiles);
283 for (
int i=0; i<nz.
size(); ++i) {
284 total_nz += nz[i].total_nz;
285 for (
int j=0;
j<nj_tiles; ++
j)
286 for (
int k=0; k<nk_tiles; ++k)
287 total_nz_tiles[
j][k] += nz[i].nz_tiles[
j][k];
289 int w_total = (w_index+1) + (2*basis->dimension()+5) + w_nz;
290 std::cout << std::endl << std::setw(w_total) << total_nz <<
", ";
291 for (
int j=0;
j<nj_tiles; ++
j)
292 for (
int k=0; k<nk_tiles; ++k)
293 std::cout << std::setw(w_tile) << total_nz_tiles[
j][k] <<
" ";
294 std::cout << std::endl;
298 for (
int j=0;
j<nj_tiles; ++
j) {
300 for (
int k=0; k<nk_tiles; ++k)
301 Cijk_tile[
j][k] =
rcp(
new Cijk_type);
303 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
305 int k_tile = k / tile_size;
306 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
307 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
308 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
310 int j_tile = j / tile_size;
311 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
312 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
313 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
315 double c =
value(i_it);
316 Cijk_tile[j_tile][k_tile]->add_term(i,j,k,c);
320 for (
int j=0;
j<nj_tiles; ++
j)
321 for (
int k=0; k<nk_tiles; ++k)
322 Cijk_tile[
j][k]->fillComplete();
327 for (
int j_tile=0; j_tile<nj_tiles; ++j_tile) {
328 nz_tile[j_tile].
resize(nk_tiles);
329 sorted_nz_tile[j_tile].
resize(nk_tiles);
330 for (
int k_tile=0; k_tile<nk_tiles; ++k_tile) {
333 Cijk_type::k_iterator k_begin = Cijk_tile[j_tile][k_tile]->k_begin();
334 Cijk_type::k_iterator k_end = Cijk_tile[j_tile][k_tile]->k_end();
335 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
337 Cijk_type::kj_iterator j_begin =
338 Cijk_tile[j_tile][k_tile]->j_begin(k_it);
339 Cijk_type::kj_iterator j_end =
340 Cijk_tile[j_tile][k_tile]->j_end(k_it);
341 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
343 Cijk_type::kji_iterator i_begin =
344 Cijk_tile[j_tile][k_tile]->i_begin(j_it);
345 Cijk_type::kji_iterator i_end =
346 Cijk_tile[j_tile][k_tile]->i_end(j_it);
347 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it){
349 if (nz_tile[j_tile][k_tile].count(i) == 0)
350 nz_tile[j_tile][k_tile][i] = 1;
352 ++(nz_tile[j_tile][k_tile][i]);
358 sorted_nz_tile[j_tile][k_tile].
resize(nz_tile[j_tile][k_tile].size());
360 for (std::map<int,int>::iterator it = nz_tile[j_tile][k_tile].begin();
361 it != nz_tile[j_tile][k_tile].
end(); ++it) {
362 sorted_nz_tile[j_tile][k_tile][idx] =
363 std::make_pair(it->first, it->second);
366 std::sort( sorted_nz_tile[j_tile][k_tile].begin(),
367 sorted_nz_tile[j_tile][k_tile].end(),
371 std::cout << std::endl
372 <<
"Tile (" << j_tile <<
", " << k_tile <<
"):" << std::endl;
373 for (
int i=0; i<sorted_nz_tile[j_tile][k_tile].
size(); ++i) {
374 int idx = sorted_nz_tile[j_tile][k_tile][i].first;
375 std::cout << std::setw(w_index) << idx <<
" "
376 << basis->term(idx) <<
": "
377 << std::setw(w_nz) << sorted_nz_tile[j_tile][k_tile][i].second
380 std::cout << std::endl;
386 catch (std::exception& e) {
387 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[]