53 #include "Stratimikos_DefaultLinearSolverBuilder.hpp" 
   54 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp" 
   55 #include "Thyra_PreconditionerBase.hpp" 
   56 #include "Thyra_PreconditionerFactoryBase.hpp" 
   57 #include "Thyra_EpetraThyraWrappers.hpp" 
   58 #include "Thyra_EpetraLinearOp.hpp" 
   68 #include "EpetraExt_VectorOut.h" 
   92 const char *
sg_rf_names[] = { 
"Uniform", 
"CC-Uniform", 
"Rys", 
"Log-Normal" };
 
  100    "Slow Restricted", 
"Moderate Restricted", 
"Unrestricted" };
 
  106   MPI_Init(&argc,&argv);
 
  117   int MyPID = Comm->
MyPID();
 
  124       "This example runs a stochastic collocation method.\n");
 
  127     CLP.
setOption(
"num_mesh", &n, 
"Number of mesh points in each direction");
 
  132       "Random field type");
 
  138     CLP.
setOption(
"std_dev", &sigma, 
"Standard deviation");
 
  140     double weightCut = 1.0;
 
  141     CLP.
setOption(
"weight_cut", &weightCut, 
"Weight cut");
 
  144     CLP.
setOption(
"num_kl", &num_KL, 
"Number of KL terms");
 
  147     CLP.
setOption(
"order", &p, 
"Polynomial order");
 
  149     bool normalize_basis = 
true;
 
  150     CLP.
setOption(
"normalize", 
"unnormalize", &normalize_basis, 
 
  151       "Normalize PC basis");
 
  154     CLP.
setOption(
"krylov_solver", &krylov_solver, 
 
  159     CLP.
setOption(
"krylov_method", &krylov_method, 
 
  164     CLP.
setOption(
"prec_strategy", &precStrategy, 
 
  166       "Preconditioner strategy");
 
  169     CLP.
setOption(
"tol", &tol, 
"Solver tolerance");
 
  174       "Sparse grid growth rule");
 
  176     CLP.
parse( argc, argv );
 
  179       std::cout << 
"Summary of command line options:" << std::endl
 
  180     << 
"\tnum_mesh        = " << n << std::endl
 
  181     << 
"\trand_field      = " << 
sg_rf_names[randField] << std::endl
 
  182     << 
"\tmean            = " << mean << std::endl
 
  183     << 
"\tstd_dev         = " << sigma << std::endl
 
  184     << 
"\tweight_cut      = " << weightCut << std::endl
 
  185     << 
"\tnum_kl          = " << num_KL << std::endl
 
  186     << 
"\torder           = " << p << std::endl
 
  187     << 
"\tnormalize_basis = " << normalize_basis << std::endl
 
  194     << 
"\ttol             = " << tol << std::endl
 
  199     bool nonlinear_expansion = 
false;
 
  201       nonlinear_expansion = 
true;
 
  208     for (
int i=0; i<num_KL; i++) {
 
  212           p, normalize_basis));
 
  217        p, normalize_basis, 
true));
 
  219       else if (randField == 
RYS) {
 
  221           p, weightCut, normalize_basis));
 
  225           p, normalize_basis));
 
  233     int sparse_grid_growth = Pecos::MODERATE_RESTRICTED_GROWTH;
 
  235      sparse_grid_growth = Pecos::SLOW_RESTRICTED_GROWTH;
 
  237      sparse_grid_growth = Pecos::MODERATE_RESTRICTED_GROWTH;
 
  239      sparse_grid_growth = Pecos::UNRESTRICTED_GROWTH;
 
  240     Stokhos::SparseGridQuadrature<int,double> quad(basis,p,1e-12,sg_growth);
 
  242       quad.getQuadPoints();
 
  244       quad.getQuadWeights();
 
  245     int nqp = quad_weights.
size();
 
  249               basis, nonlinear_expansion);
 
  262     EpetraExt::ModelEvaluator::InArgs inArgs = model.
createInArgs();
 
  263     EpetraExt::ModelEvaluator::OutArgs outArgs = model.
createOutArgs();
 
  264     EpetraExt::ModelEvaluator::OutArgs outArgs2 = model.
createOutArgs();
 
  276     if (krylov_solver == 
AZTECOO) {
 
  277       stratParams.
set(
"Linear Solver Type", 
"AztecOO");
 
  279   stratParams.
sublist(
"Linear Solver Types").sublist(
"AztecOO").sublist(
"Forward Solve");
 
  280       aztecParams.
set(
"Max Iterations", 1000);
 
  281       aztecParams.
set(
"Tolerance", tol);
 
  283   aztecParams.
sublist(
"AztecOO Settings");
 
  284       if (krylov_method == 
GMRES)
 
  285   aztecSettings.
set(
"Aztec Solver", 
"GMRES");
 
  286       else if (krylov_method == 
CG)
 
  287   aztecSettings.
set(
"Aztec Solver", 
"CG");
 
  288       aztecSettings.
set(
"Aztec Preconditioner", 
"none");
 
  289       aztecSettings.
set(
"Size of Krylov Subspace", 100);
 
  290       aztecSettings.
set(
"Convergence Test", 
"r0");
 
  291       aztecSettings.
set(
"Output Frequency", 10);
 
  293   stratParams.
sublist(
"Linear Solver Types").sublist(
"AztecOO").sublist(
"VerboseObject");
 
  294       verbParams.
set(
"Verbosity Level", 
"none");
 
  296     else if (krylov_solver == 
BELOS) {
 
  297       stratParams.
set(
"Linear Solver Type", 
"Belos");
 
  299   stratParams.
sublist(
"Linear Solver Types").sublist(
"Belos");
 
  301       if (krylov_method == 
GMRES || krylov_method == 
FGMRES) {
 
  302   belosParams.
set(
"Solver Type",
"Block GMRES");
 
  304     &(belosParams.
sublist(
"Solver Types").sublist(
"Block GMRES"));
 
  305   if (krylov_method == 
FGMRES)
 
  306     belosSolverParams->
set(
"Flexible Gmres", 
true);
 
  308       else if (krylov_method == 
RGMRES) {
 
  309   belosParams.
set(
"Solver Type",
"GCRODR");
 
  311     &(belosParams.
sublist(
"Solver Types").sublist(
"GCRODR"));
 
  312   belosSolverParams->
set(
"Num Recycled Blocks", 10);
 
  314       else if (krylov_method == 
CG) {
 
  315   belosParams.
set(
"Solver Type",
"Block CG");
 
  317     &(belosParams.
sublist(
"Solver Types").sublist(
"Block CG"));
 
  320       belosSolverParams->
set(
"Convergence Tolerance", tol);
 
  321       belosSolverParams->
set(
"Maximum Iterations", 1000);
 
  322       belosSolverParams->
set(
"Num Blocks", 100);
 
  323       belosSolverParams->
set(
"Output Frequency",10);
 
  325       verbParams.
set(
"Verbosity Level", 
"none");
 
  327     stratParams.
set(
"Preconditioner Type", 
"ML");
 
  329       stratParams.
sublist(
"Preconditioner Types").sublist(
"ML").sublist(
"ML Settings");
 
  330     precParams.
set(
"default values", 
"SA");
 
  331     precParams.
set(
"ML output", 0);
 
  332     precParams.
set(
"max levels",5);
 
  333     precParams.
set(
"increasing or decreasing",
"increasing");
 
  334     precParams.
set(
"aggregation: type", 
"Uncoupled");
 
  335     precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
 
  336     precParams.
set(
"smoother: sweeps",2);
 
  337     precParams.
set(
"smoother: pre or post", 
"both");
 
  338     precParams.
set(
"coarse: max size", 200);
 
  339 #ifdef HAVE_ML_AMESOS 
  340     precParams.
set(
"coarse: type",
"Amesos-KLU");
 
  342     precParams.
set(
"coarse: type",
"Jacobi");
 
  346     Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
 
  347     linearSolverBuilder.setParameterList(
Teuchos::rcp(&stratParams, 
false));
 
  352       linearSolverBuilder.createLinearSolveStrategy(
"");   
 
  354       Teuchos::VerboseObjectBase::getDefaultOStream();
 
  355     lowsFactory->setOStream(out);
 
  360       lowsFactory->createOp();
 
  362       lowsFactory->getPreconditionerFactory();
 
  364       precFactory->createPrec();
 
  368       Thyra::epetraLinearOp(A);
 
  370       rcp(
new Thyra::DefaultLinearOpSource<double>(A_thyra));
 
  374     if (!(krylov_solver == 
BELOS && krylov_method == 
CG)) {
 
  376       Thyra::SolveMeasureType solveMeasure(
 
  377   Thyra::SOLVE_MEASURE_NORM_RESIDUAL,
 
  378   Thyra::SOLVE_MEASURE_NORM_INIT_RESIDUAL);
 
  380   Teuchos::rcp(
new Thyra::SolveCriteria<double>(solveMeasure, tol));
 
  384     if (precStrategy == 
MEAN) {
 
  387       precFactory->initializePrec(losb, M_thyra.
get());
 
  388       Thyra::initializePreconditionedOp<double>(
 
  389   *lowsFactory, A_thyra, M_thyra, lows.
ptr());
 
  392     x_mean.PutScalar(0.0);
 
  393     x_var.PutScalar(0.0);
 
  395     for (
int qp=0; qp<nqp; qp++) {
 
  399       for (
int i=0; i<num_KL; i++)
 
  400   (*p)[i] = quad_points[qp][i];
 
  414   Thyra::create_Vector(x, A_thyra->domain());
 
  416   Thyra::create_Vector(f, A_thyra->range());
 
  419       if (precStrategy != 
MEAN) {
 
  421   precFactory->initializePrec(losb, M_thyra.
get());
 
  422   Thyra::initializePreconditionedOp<double>(
 
  423     *lowsFactory, A_thyra, M_thyra, lows.
ptr());
 
  429   Thyra::SolveStatus<double> solveStatus = 
 
  430     lows->solve(Thyra::NOTRANS, *f_thyra, x_thyra.
ptr(),
 
  431           solveCriteria.
ptr());
 
  433     std::cout << 
"Collocation point " << qp+1 <<
'/' << nqp << 
":  " 
  434         << solveStatus.message << std::endl;
 
  442       outArgs2.set_g(0, g);
 
  446       x2.Multiply(1.0, *x, *x, 0.0);
 
  447       g2.Multiply(1.0, *g, *g, 0.0);
 
  448       x_mean.Update(quad_weights[qp], *x, 1.0);
 
  449       x_var.Update(quad_weights[qp], x2, 1.0);
 
  450       g_mean.Update(quad_weights[qp], *g, 1.0);
 
  451       g_var.Update(quad_weights[qp], g2, 1.0);
 
  454     x2.Multiply(1.0, x_mean, x_mean, 0.0);
 
  455     g2.Multiply(1.0, g_mean, g_mean, 0.0);
 
  456     x_var.Update(-1.0, x2, 1.0);
 
  457     g_var.Update(-1.0, g2, 1.0);
 
  460     for (
int i=0; i<x_var.MyLength(); i++)
 
  462     for (
int i=0; i<g_var.MyLength(); i++)
 
  465     std::cout.precision(16);
 
  466     std::cout << 
"\nResponse Mean =      " << std::endl << g_mean << std::endl;
 
  467     std::cout << 
"Response Std. Dev. = " << std::endl << g_var << std::endl;
 
  470     EpetraExt::VectorToMatrixMarketFile(
"mean_col.mm", x_mean);
 
  471     EpetraExt::VectorToMatrixMarketFile(
"std_dev_col.mm", x_var);
 
  480   catch (std::exception& e) {
 
  481     std::cout << e.what() << std::endl;
 
  483   catch (std::string& s) {
 
  484     std::cout << s << std::endl;
 
  487     std::cout << s << std::endl;
 
  490     std::cout << 
"Caught unknown exception!" <<std:: endl;
 
const char * prec_strategy_names[]
 
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
 
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
 
Hermite polynomial basis. 
 
const Krylov_Method krylov_method_values[]
 
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const 
Evaluate model on InArgs. 
 
Teuchos::RCP< Epetra_CrsMatrix > get_mean() const 
Get mean matrix. 
 
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
 
const int num_prec_strategy
 
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
 
const char * krylov_solver_names[]
 
virtual int MyPID() const =0
 
const SG_GROWTH sg_growth_values[]
 
const char * sg_growth_names[]
 
ModelEvaluator for a linear 2-D diffusion problem. 
 
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
 
const int num_krylov_method
 
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 SG_RF sg_rf_values[]
 
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const 
 
const int num_krylov_solver
 
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const 
Return parameter vector map. 
 
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const 
Return response function map. 
 
Legendre polynomial basis. 
 
int main(int argc, char **argv)
 
Teuchos::RCP< Epetra_Operator > create_W() const 
Create W = alpha*M + beta*J matrix. 
 
InArgs createInArgs() const 
Create InArgs. 
 
const char * sg_rf_names[]
 
OutArgs createOutArgs() const 
Create OutArgs. 
 
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
 
Legendre polynomial basis using Clenshaw-Curtis quadrature points. 
 
void setDocString(const char doc_string[])
 
Teuchos::RCP< const Epetra_Map > get_x_map() const 
Return solution vector map. 
 
const PrecStrategy prec_strategy_values[]
 
const Krylov_Solver krylov_solver_values[]
 
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
 
static void zeroOutTimers()
 
Teuchos::RCP< const Epetra_Map > get_f_map() const 
Return residual vector map. 
 
const char * krylov_method_names[]