19 #include "Ifpack_RCMReordering.h"
44 "hermite",
"legendre",
"clenshaw-curtis",
"gauss-patterson",
"rys",
"jacobi" };
58 "complete",
"tensor",
"total",
"smolyak" };
66 "total",
"lexicographic",
"morton-z" };
74 MPI_Init(&argc,&argv);
80 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
82 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
84 CLP.
setOption(
"order", &p,
"Polynomial order");
85 double drop = 1.0e-12;
86 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
87 std::string file =
"A.mm";
88 CLP.
setOption(
"filename", &file,
"Matrix Market filename");
98 CLP.
setOption(
"product_basis", &prod_basis_type,
101 "Product basis type");
103 CLP.
setOption(
"ordering", &ordering_type,
106 "Product basis ordering");
108 CLP.
setOption(
"alpha", &alpha,
"Jacobi alpha index");
110 CLP.
setOption(
"beta", &beta,
"Jacobi beta index");
112 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
113 bool use_old =
false;
114 CLP.
setOption(
"old",
"new", &use_old,
"Use old or new Cijk algorithm");
116 CLP.
setOption(
"print",
"no-print", &print,
"Print Cijk to screen");
117 bool save_3tensor =
false;
118 CLP.
setOption(
"save_3tensor",
"no-save_3tensor", &save_3tensor,
119 "Save full 3tensor to file");
120 std::string file_3tensor =
"Cijk.dat";
121 CLP.
setOption(
"filename_3tensor", &file_3tensor,
122 "Filename to store full 3-tensor");
124 CLP.
setOption(
"unique",
"no-unique", &unique,
125 "Only save the unique non-zeros");
127 CLP.
setOption(
"rcm",
"no-rcm", &rcm,
"Reorder using RCM");
130 CLP.
parse( argc, argv );
134 for (
int i=0; i<d; i++) {
137 p,
true, growth_type));
140 p,
true, growth_type));
149 else if (basis_type ==
RYS)
151 p, 1.0,
true, growth_type));
152 else if (basis_type ==
JACOBI)
154 p, alpha, beta,
true, growth_type));
163 bases, drop, use_old));
164 else if (prod_basis_type ==
TENSOR) {
178 else if (prod_basis_type ==
TOTAL) {
192 else if (prod_basis_type ==
SMOLYAK) {
197 bases, index_set, drop));
201 bases, index_set, drop));
205 bases, index_set, drop));
212 Cijk = basis->computeTripleProductTensor();
214 Cijk = basis->computeLinearTripleProductTensor();
216 std::cout <<
"basis size = " << basis->size()
217 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
229 Cijk_type::k_iterator k_begin = Cijk->k_begin();
230 Cijk_type::k_iterator k_end = Cijk->k_end();
231 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
233 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
234 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
235 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
237 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
238 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
239 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
242 if (i != 0 || (i == 0 && j == 0 && k == 0))
243 Cijk3->add_term(i, j, k, cijk);
248 Cijk3->fillComplete();
255 Ifpack_RCMReordering ifpack_rcm;
256 ifpack_rcm.SetParameter(
"reorder: root node", basis->size()-1);
257 ifpack_rcm.Compute(mat);
260 Cijk_type::k_iterator k_begin = Cijk->k_begin();
261 Cijk_type::k_iterator k_end = Cijk->k_end();
262 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
263 int k = ifpack_rcm.Reorder(
index(k_it));
264 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
265 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
266 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
267 int j = ifpack_rcm.Reorder(
index(j_it));
268 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
269 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
270 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
271 int i = ifpack_rcm.Reorder(
index(i_it));
273 Cijk2->add_term(i, j, k, cijk);
277 Cijk2->fillComplete();
282 std::cout << *Cijk << std::endl;
290 std::ofstream cijk_file(file_3tensor.c_str());
291 cijk_file.precision(14);
292 cijk_file.setf(std::ios::scientific);
293 cijk_file <<
"i, j, k, cijk" << std::endl;
294 Cijk_type::k_iterator k_begin = Cijk->k_begin();
295 Cijk_type::k_iterator k_end = Cijk->k_end();
296 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
298 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
299 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
300 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
302 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
303 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
304 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
307 if (!unique || ( i >= j && j >= k ))
308 cijk_file << i <<
", "
311 << cijk << std::endl;
321 catch (std::exception& e) {
322 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[]