31 #include "EpetraExt_VectorOut.h"
32 #include "EpetraExt_RowMatrixOut.h"
40 bool nonlinear_expansion =
false;
42 bool symmetric =
false;
44 double g_mean_exp = 0.172988;
45 double g_std_dev_exp = 0.0380007;
50 MPI_Init(&argc,&argv);
67 MyPID = globalComm->
MyPID();
71 for (
int i=0; i<num_KL; i++)
76 int sz = basis->size();
78 if (nonlinear_expansion)
79 Cijk = basis->computeTripleProductTensor();
81 Cijk = basis->computeLinearTripleProductTensor();
86 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
89 int num_spatial_procs = -1;
91 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
107 nonlinear_expansion, symmetric));
112 if (!nonlinear_expansion) {
113 sgParams->
set(
"Parameter Expansion Type",
"Linear");
114 sgParams->
set(
"Jacobian Expansion Type",
"Linear");
118 precParams.
set(
"default values",
"SA");
119 precParams.
set(
"ML output", 0);
120 precParams.
set(
"max levels",5);
121 precParams.
set(
"increasing or decreasing",
"increasing");
122 precParams.
set(
"aggregation: type",
"Uncoupled");
123 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
124 precParams.
set(
"smoother: sweeps",2);
125 precParams.
set(
"smoother: pre or post",
"both");
126 precParams.
set(
"coarse: max size", 200);
127 precParams.
set(
"PDE equations",sz);
128 #ifdef HAVE_ML_AMESOS
129 precParams.
set(
"coarse: type",
"Amesos-KLU");
131 precParams.
set(
"coarse: type",
"Jacobi");
138 expansion, sg_parallel_data,
146 basis->evaluateBases(point, basis_vals);
149 for (
int i=0; i<num_KL; i++) {
150 sg_p_poly->
term(i,0)[i] = 0.0;
151 sg_p_poly->
term(i,1)[i] = 1.0 / basis_vals[i+1];
158 sg_x->PutScalar(0.0);
166 Teuchos::rcp(
new ML_Epetra::MultiLevelPreconditioner(*sg_J, precParams,
170 EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->
createInArgs();
171 EpetraExt::ModelEvaluator::OutArgs sg_outArgs = sg_model->
createOutArgs();
172 sg_inArgs.set_p(1, sg_p);
173 sg_inArgs.set_x(sg_x);
174 sg_outArgs.set_f(sg_f);
175 sg_outArgs.set_W(sg_J);
178 sg_model->
evalModel(sg_inArgs, sg_outArgs);
179 sg_M->ComputePreconditioner();
183 sg_f->Norm2(&norm_f);
185 std::cout <<
"\nInitial residual norm = " << norm_f << std::endl;
190 aztec.SetAztecOption(AZ_solver, AZ_cg);
192 aztec.SetAztecOption(AZ_solver, AZ_gmres);
193 aztec.SetAztecOption(AZ_precond, AZ_none);
194 aztec.SetAztecOption(AZ_kspace, 20);
195 aztec.SetAztecOption(AZ_conv, AZ_r0);
196 aztec.SetAztecOption(AZ_output, 1);
197 aztec.SetUserOperator(sg_J.get());
198 aztec.SetPrecOperator(sg_M.get());
199 aztec.SetLHS(sg_dx.get());
200 aztec.SetRHS(sg_f.
get());
203 aztec.Iterate(1000, 1e-12);
206 sg_x->Update(-1.0, *sg_dx, 1.0);
209 EpetraExt::VectorToMatrixMarketFile(
"stochastic_solution_interlaced.mm",
213 EpetraExt::VectorToMatrixMarketFile(
"stochastic_RHS_interlaced.mm",
217 EpetraExt::RowMatrixToMatrixMarketFile(
"stochastic_operator_interlaced.mm",
227 EpetraExt::VectorToMatrixMarketFile(
"mean_gal_interlaced.mm", mean);
228 EpetraExt::VectorToMatrixMarketFile(
"std_dev_gal_interlaced.mm", std_dev);
231 EpetraExt::ModelEvaluator::OutArgs sg_outArgs2 = sg_model->
createOutArgs();
234 sg_f->PutScalar(0.0);
235 sg_outArgs2.set_f(sg_f);
236 sg_outArgs2.set_g(0, sg_g);
237 sg_model->
evalModel(sg_inArgs, sg_outArgs2);
240 sg_f->Norm2(&norm_f);
242 std::cout <<
"\nFinal residual norm = " << norm_f << std::endl;
251 std::cout.precision(16);
255 std::cout << std::endl;
256 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
257 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
261 if (norm_f < 1.0e-10 &&
262 std::abs(g_mean[0]-g_mean_exp) < g_tol &&
263 std::abs(g_std_dev[0]-g_std_dev_exp) < g_tol)
267 std::cout <<
"Example Passed!" << std::endl;
269 std::cout <<
"Example Failed!" << std::endl;
279 catch (std::exception& e) {
280 std::cout << e.what() << std::endl;
282 catch (std::string& s) {
283 std::cout << s << std::endl;
286 std::cout << s << std::endl;
289 std::cout <<
"Caught unknown exception!" << std::endl;
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
void computeStandardDeviation(Epetra_Vector &v) const
Compute standard deviation.
OutArgs createOutArgs() const
Create OutArgs.
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
void computeMean(Epetra_Vector &v) const
Compute mean.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
InArgs createInArgs() const
Create InArgs.
virtual int MyPID() const =0
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.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector 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)
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
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.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on 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< 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< 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.
coeff_type & term(ordinal_type dimension, ordinal_type order)
Get term for dimension dimension and order order.
static void zeroOutTimers()
Nonlinear, stochastic Galerkin ModelEvaluator that constructs a interlaced Jacobian.