31 #include "EpetraExt_VectorOut.h"
49 const char *
sg_rf_names[] = {
"Uniform",
"CC-Uniform",
"Rys",
"Log-Normal" };
63 "Slow Restricted",
"Moderate Restricted",
"Unrestricted" };
69 MPI_Init(&argc,&argv);
80 int MyPID = Comm->
MyPID();
87 "This example runs a stochastic collocation method.\n");
90 CLP.
setOption(
"num_mesh", &n,
"Number of mesh points in each direction");
101 CLP.
setOption(
"std_dev", &sigma,
"Standard deviation");
103 double weightCut = 1.0;
104 CLP.
setOption(
"weight_cut", &weightCut,
"Weight cut");
107 CLP.
setOption(
"num_kl", &num_KL,
"Number of KL terms");
110 CLP.
setOption(
"order", &p,
"Polynomial order");
112 bool normalize_basis =
true;
113 CLP.
setOption(
"normalize",
"unnormalize", &normalize_basis,
114 "Normalize PC basis");
117 CLP.
setOption(
"krylov_method", &krylov_method,
122 CLP.
setOption(
"prec_strategy", &precStrategy,
124 "Preconditioner strategy");
127 CLP.
setOption(
"tol", &tol,
"Solver tolerance");
129 #ifdef HAVE_STOKHOS_DAKOTA
134 CLP.
setOption(
"quadrature", &quad_method,
141 "Sparse grid growth rule");
143 CLP.
parse( argc, argv );
146 std::cout <<
"Summary of command line options:" << std::endl
147 <<
"\tnum_mesh = " << n << std::endl
148 <<
"\trand_field = " <<
sg_rf_names[randField] << std::endl
149 <<
"\tmean = " << mean << std::endl
150 <<
"\tstd_dev = " << sigma << std::endl
151 <<
"\tnum_kl = " << num_KL << std::endl
152 <<
"\torder = " << p << std::endl
153 <<
"\tnormalize_basis = " << normalize_basis << std::endl
158 <<
"\ttol = " << tol << std::endl
165 bool nonlinear_expansion =
false;
167 nonlinear_expansion =
true;
174 for (
int i=0; i<num_KL; i++) {
178 p, normalize_basis));
183 p, normalize_basis,
true));
185 else if (randField ==
RYS) {
187 p, weightCut, normalize_basis));
191 p, normalize_basis));
201 #ifdef HAVE_STOKHOS_DAKOTA
202 int sparse_grid_growth = Pecos::MODERATE_RESTRICTED_GROWTH;
204 sparse_grid_growth = Pecos::SLOW_RESTRICTED_GROWTH;
206 sparse_grid_growth = Pecos::MODERATE_RESTRICTED_GROWTH;
208 sparse_grid_growth = Pecos::UNRESTRICTED_GROWTH;
209 quad =
Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(
210 basis,p,1e-12,sparse_grid_growth));
213 true, std::logic_error,
214 "Sparse grids require building with Dakota support!");
217 else if (quad_method ==
TENSOR) {
222 quad->getQuadPoints();
224 int nqp = quad_weights.
size();
228 basis, nonlinear_expansion);
241 EpetraExt::ModelEvaluator::InArgs inArgs = model.
createInArgs();
242 EpetraExt::ModelEvaluator::OutArgs outArgs = model.
createOutArgs();
243 EpetraExt::ModelEvaluator::OutArgs outArgs2 = model.
createOutArgs();
255 precParams.
set(
"default values",
"SA");
256 precParams.
set(
"ML output", 0);
257 precParams.
set(
"max levels",5);
258 precParams.
set(
"increasing or decreasing",
"increasing");
259 precParams.
set(
"aggregation: type",
"Uncoupled");
260 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
261 precParams.
set(
"smoother: sweeps",2);
262 precParams.
set(
"smoother: pre or post",
"both");
263 precParams.
set(
"coarse: max size", 200);
264 #ifdef HAVE_ML_AMESOS
265 precParams.
set(
"coarse: type",
"Amesos-KLU");
267 precParams.
set(
"coarse: type",
"Jacobi");
269 bool checkFiltering =
false;
270 if (precStrategy ==
REUSE) {
271 checkFiltering =
true;
272 precParams.
set(
"reuse: enable",
true);
275 Teuchos::rcp(
new ML_Epetra::MultiLevelPreconditioner(*A, precParams,
277 if (precStrategy ==
MEAN) {
280 M->ComputePreconditioner();
285 if (krylov_method ==
GMRES)
286 aztec.SetAztecOption(AZ_solver, AZ_gmres);
287 else if (krylov_method ==
CG)
288 aztec.SetAztecOption(AZ_solver, AZ_cg);
289 aztec.SetAztecOption(AZ_precond, AZ_none);
290 aztec.SetAztecOption(AZ_kspace, 100);
291 aztec.SetAztecOption(AZ_conv, AZ_r0);
292 aztec.SetAztecOption(AZ_output, 0);
293 aztec.SetUserOperator(A.get());
294 aztec.SetPrecOperator(M.
get());
295 aztec.SetLHS(x.get());
296 aztec.SetRHS(f.get());
298 x_mean.PutScalar(0.0);
299 x_var.PutScalar(0.0);
301 for (
int qp=0; qp<nqp; qp++) {
304 if (qp%100 == 0 || qp == nqp-1)
305 std::cout <<
"Collocation point " << qp+1 <<
'/' << nqp <<
"\n";
308 for (
int i=0; i<num_KL; i++)
309 (*p)[i] = quad_points[qp][i];
323 if (precStrategy !=
MEAN) {
325 M->ComputePreconditioner(checkFiltering);
331 aztec.Iterate(1000, tol);
335 outArgs2.set_g(0, g);
339 x2.Multiply(1.0, *x, *x, 0.0);
340 g2.Multiply(1.0, *g, *g, 0.0);
341 x_mean.Update(quad_weights[qp], *x, 1.0);
342 x_var.Update(quad_weights[qp], x2, 1.0);
343 g_mean.Update(quad_weights[qp], *g, 1.0);
344 g_var.Update(quad_weights[qp], g2, 1.0);
347 x2.Multiply(1.0, x_mean, x_mean, 0.0);
348 g2.Multiply(1.0, g_mean, g_mean, 0.0);
349 x_var.Update(-1.0, x2, 1.0);
350 g_var.Update(-1.0, g2, 1.0);
353 for (
int i=0; i<x_var.MyLength(); i++)
355 for (
int i=0; i<g_var.MyLength(); i++)
358 std::cout.precision(16);
359 std::cout <<
"\nResponse Mean = " << std::endl << g_mean << std::endl;
360 std::cout <<
"Response Std. Dev. = " << std::endl << g_var << std::endl;
363 EpetraExt::VectorToMatrixMarketFile(
"mean_col.mm", x_mean);
364 EpetraExt::VectorToMatrixMarketFile(
"std_dev_col.mm", x_var);
373 catch (std::exception& e) {
374 std::cout << e.what() << std::endl;
376 catch (std::string& s) {
377 std::cout << s << std::endl;
380 std::cout << s << std::endl;
383 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.
const SG_Quad sg_quad_values[]
Teuchos::RCP< Epetra_CrsMatrix > get_mean() const
Get mean matrix.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const int num_prec_strategy
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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[]
const char * sg_quad_names[]
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
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[]
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
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[]