51 #include "Ifpack_RCMReordering.h"
76 "hermite",
"legendre",
"clenshaw-curtis",
"gauss-patterson",
"rys",
"jacobi" };
90 "complete",
"tensor",
"total",
"smolyak" };
98 "total",
"lexicographic",
"morton-z" };
106 MPI_Init(&argc,&argv);
112 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
114 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
116 CLP.
setOption(
"order", &p,
"Polynomial order");
117 double drop = 1.0e-12;
118 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
119 std::string file =
"A.mm";
120 CLP.
setOption(
"filename", &file,
"Matrix Market filename");
130 CLP.
setOption(
"product_basis", &prod_basis_type,
133 "Product basis type");
135 CLP.
setOption(
"ordering", &ordering_type,
138 "Product basis ordering");
140 CLP.
setOption(
"alpha", &alpha,
"Jacobi alpha index");
142 CLP.
setOption(
"beta", &beta,
"Jacobi beta index");
144 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
145 bool use_old =
false;
146 CLP.
setOption(
"old",
"new", &use_old,
"Use old or new Cijk algorithm");
148 CLP.
setOption(
"print",
"no-print", &print,
"Print Cijk to screen");
149 bool save_3tensor =
false;
150 CLP.
setOption(
"save_3tensor",
"no-save_3tensor", &save_3tensor,
151 "Save full 3tensor to file");
152 std::string file_3tensor =
"Cijk.dat";
153 CLP.
setOption(
"filename_3tensor", &file_3tensor,
154 "Filename to store full 3-tensor");
156 CLP.
setOption(
"unique",
"no-unique", &unique,
157 "Only save the unique non-zeros");
159 CLP.
setOption(
"rcm",
"no-rcm", &rcm,
"Reorder using RCM");
162 CLP.
parse( argc, argv );
166 for (
int i=0; i<d; i++) {
169 p,
true, growth_type));
172 p,
true, growth_type));
181 else if (basis_type ==
RYS)
183 p, 1.0,
true, growth_type));
184 else if (basis_type ==
JACOBI)
186 p, alpha, beta,
true, growth_type));
195 bases, drop, use_old));
196 else if (prod_basis_type ==
TENSOR) {
210 else if (prod_basis_type ==
TOTAL) {
224 else if (prod_basis_type ==
SMOLYAK) {
229 bases, index_set, drop));
233 bases, index_set, drop));
237 bases, index_set, drop));
244 Cijk = basis->computeTripleProductTensor();
246 Cijk = basis->computeLinearTripleProductTensor();
248 std::cout <<
"basis size = " << basis->size()
249 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
261 Cijk_type::k_iterator k_begin = Cijk->k_begin();
262 Cijk_type::k_iterator k_end = Cijk->k_end();
263 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
265 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
266 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
267 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
269 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
270 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
271 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
274 if (i != 0 || (i == 0 && j == 0 && k == 0))
275 Cijk3->add_term(i, j, k, cijk);
280 Cijk3->fillComplete();
287 Ifpack_RCMReordering ifpack_rcm;
288 ifpack_rcm.SetParameter(
"reorder: root node", basis->size()-1);
289 ifpack_rcm.Compute(mat);
292 Cijk_type::k_iterator k_begin = Cijk->k_begin();
293 Cijk_type::k_iterator k_end = Cijk->k_end();
294 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
295 int k = ifpack_rcm.Reorder(
index(k_it));
296 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
297 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
298 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
299 int j = ifpack_rcm.Reorder(
index(j_it));
300 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
301 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
302 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
303 int i = ifpack_rcm.Reorder(
index(i_it));
305 Cijk2->add_term(i, j, k, cijk);
309 Cijk2->fillComplete();
314 std::cout << *Cijk << std::endl;
322 std::ofstream cijk_file(file_3tensor.c_str());
323 cijk_file.precision(14);
324 cijk_file.setf(std::ios::scientific);
325 cijk_file <<
"i, j, k, cijk" << std::endl;
326 Cijk_type::k_iterator k_begin = Cijk->k_begin();
327 Cijk_type::k_iterator k_end = Cijk->k_end();
328 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
330 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
331 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
332 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
334 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
335 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
336 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
339 if (!unique || ( i >= j && j >= k ))
340 cijk_file << i <<
", "
343 << cijk << std::endl;
353 catch (std::exception& e) {
354 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[]
void sparse3Tensor2MatrixMarket(const Stokhos::OrthogPolyBasis< ordinal_type, value_type > &basis, const Stokhos::Sparse3Tensor< ordinal_type, value_type > &Cijk, const Epetra_Comm &comm, const std::string &file)
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
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
int FillComplete(bool OptimizeDataStorage=true)
int PutScalar(double ScalarConstant)
Legendre polynomial basis using Gauss-Patterson quadrature points.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
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
const Stokhos::GrowthPolicy growth_type_values[]
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
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.
A comparison functor implementing a strict weak ordering based Morton Z-ordering. ...
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
Teuchos::RCP< Epetra_CrsGraph > sparse3Tensor2CrsGraph(const Stokhos::OrthogPolyBasis< ordinal_type, value_type > &basis, const Stokhos::Sparse3Tensor< ordinal_type, value_type > &Cijk, const Epetra_Comm &comm)
Build an Epetra_CrsGraph from a sparse 3 tensor.
void setDocString(const char doc_string[])
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
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[]