30 #include "EpetraExt_VectorOut.h"
38 bool nonlinear_expansion =
false;
40 bool symmetric =
false;
42 double g_mean_exp = 0.172988;
43 double g_std_dev_exp = 0.0380007;
48 MPI_Init(&argc,&argv);
65 MyPID = globalComm->
MyPID();
69 for (
int i=0; i<num_KL; i++)
74 int sz = basis->size();
76 if (nonlinear_expansion)
77 Cijk = basis->computeTripleProductTensor();
79 Cijk = basis->computeLinearTripleProductTensor();
84 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
87 int num_spatial_procs = -1;
89 num_spatial_procs = std::atoi(argv[1]);
91 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
107 nonlinear_expansion, symmetric));
113 sgParams->
sublist(
"SG Operator");
115 sgParams->
sublist(
"SG Preconditioner");
116 if (!nonlinear_expansion) {
117 sgParams->
set(
"Parameter Expansion Type",
"Linear");
118 sgParams->
set(
"Jacobian Expansion Type",
"Linear");
120 sgOpParams.
set(
"Operator Method",
"Matrix Free");
121 sgPrecParams.
set(
"Preconditioner Method",
"Mean-based");
124 sgPrecParams.
set(
"Symmetric Gauss-Seidel", symmetric);
125 sgPrecParams.
set(
"Mean Preconditioner Type",
"ML");
127 sgPrecParams.
sublist(
"Mean Preconditioner Parameters");
128 precParams.
set(
"default values",
"SA");
129 precParams.
set(
"ML output", 0);
130 precParams.
set(
"max levels",5);
131 precParams.
set(
"increasing or decreasing",
"increasing");
132 precParams.
set(
"aggregation: type",
"Uncoupled");
133 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
134 precParams.
set(
"smoother: sweeps",2);
135 precParams.
set(
"smoother: pre or post",
"both");
136 precParams.
set(
"coarse: max size", 200);
137 #ifdef HAVE_ML_AMESOS
138 precParams.
set(
"coarse: type",
"Amesos-KLU");
140 precParams.
set(
"coarse: type",
"Jacobi");
146 expansion, sg_parallel_data,
154 basis->evaluateBases(point, basis_vals);
157 for (
int i=0; i<num_KL; i++) {
158 sg_p_poly->
term(i,0)[i] = 0.0;
159 sg_p_poly->
term(i,1)[i] = 1.0 / basis_vals[i+1];
161 std::cout << *sg_p_poly << std::endl;
167 sg_x->PutScalar(0.0);
177 EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->
createInArgs();
178 EpetraExt::ModelEvaluator::OutArgs sg_outArgs = sg_model->
createOutArgs();
179 sg_inArgs.set_p(1, sg_p);
180 sg_inArgs.set_x(sg_x);
181 sg_outArgs.set_f(sg_f);
182 sg_outArgs.set_W(sg_J);
183 sg_outArgs.set_WPrec(sg_M);
186 sg_model->
evalModel(sg_inArgs, sg_outArgs);
190 sg_f->Norm2(&norm_f);
192 std::cout <<
"\nInitial residual norm = " << norm_f << std::endl;
197 aztec.SetAztecOption(AZ_solver, AZ_cg);
199 aztec.SetAztecOption(AZ_solver, AZ_gmres);
200 aztec.SetAztecOption(AZ_precond, AZ_none);
201 aztec.SetAztecOption(AZ_kspace, 20);
202 aztec.SetAztecOption(AZ_conv, AZ_r0);
203 aztec.SetAztecOption(AZ_output, 1);
204 aztec.SetUserOperator(sg_J.get());
205 aztec.SetPrecOperator(sg_M.
get());
206 aztec.SetLHS(sg_dx.get());
207 aztec.SetRHS(sg_f.
get());
210 aztec.Iterate(1000, 1e-12);
213 sg_x->Update(-1.0, *sg_dx, 1.0);
216 EpetraExt::VectorToMatrixMarketFile(
"stochastic_solution.mm", *sg_x);
219 EpetraExt::VectorToMatrixMarketFile(
"stochastic_RHS.mm", *sg_f);
225 EpetraExt::RowMatrixToMatrixMarketFile(
"stochastic_operator.mm",
235 EpetraExt::VectorToMatrixMarketFile(
"mean_gal.mm", mean);
236 EpetraExt::VectorToMatrixMarketFile(
"std_dev_gal.mm", std_dev);
239 EpetraExt::ModelEvaluator::OutArgs sg_outArgs2 = sg_model->
createOutArgs();
242 sg_f->PutScalar(0.0);
243 sg_outArgs2.set_f(sg_f);
244 sg_outArgs2.set_g(0, sg_g);
245 sg_model->
evalModel(sg_inArgs, sg_outArgs2);
248 sg_f->Norm2(&norm_f);
250 std::cout <<
"\nFinal residual norm = " << norm_f << std::endl;
259 std::cout.precision(16);
263 std::cout << std::endl;
264 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
265 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
269 if (norm_f < 1.0e-10 &&
270 std::abs(g_mean[0]-g_mean_exp) < g_tol &&
271 std::abs(g_std_dev[0]-g_std_dev_exp) < g_tol)
275 std::cout <<
"Example Passed!" << std::endl;
277 std::cout <<
"Example Failed!" << std::endl;
287 catch (std::exception& e) {
288 std::cout << e.what() << std::endl;
290 catch (std::string& s) {
291 std::cout << s << std::endl;
294 std::cout << s << std::endl;
297 std::cout <<
"Caught unknown exception!" << std::endl;
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_x_sg(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using x map and owned sg map.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_p_sg(int l, Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using p map.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
void computeStandardDeviation(Epetra_Vector &v) const
Compute standard deviation.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
void computeMean(Epetra_Vector &v) const
Compute mean.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual int MyPID() const =0
Nonlinear, stochastic Galerkin ModelEvaluator.
OutArgs createOutArgs() const
Create OutArgs.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_g_sg(int l, Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using g map.
ModelEvaluator for a linear 2-D diffusion problem.
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)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const
Return response function map.
Legendre polynomial basis.
InArgs createInArgs() const
Create InArgs.
int main(int argc, char **argv)
Teuchos::RCP< const Epetra_Comm > getSpatialComm() const
Get spatial comm.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
coeff_type & term(ordinal_type dimension, ordinal_type order)
Get term for dimension dimension and order order.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner operator.
static void zeroOutTimers()