63 #include "EpetraExt_VectorOut.h"
64 #include "EpetraExt_RowMatrixOut.h"
72 bool nonlinear_expansion =
false;
74 bool symmetric =
false;
76 double g_mean_exp = 0.172988;
77 double g_std_dev_exp = 0.0380007;
82 MPI_Init(&argc,&argv);
99 MyPID = globalComm->
MyPID();
103 for (
int i=0; i<num_KL; i++)
108 int sz = basis->size();
110 if (nonlinear_expansion)
111 Cijk = basis->computeTripleProductTensor();
113 Cijk = basis->computeLinearTripleProductTensor();
118 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
121 int num_spatial_procs = -1;
123 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
139 nonlinear_expansion, symmetric));
144 if (!nonlinear_expansion) {
145 sgParams->
set(
"Parameter Expansion Type",
"Linear");
146 sgParams->
set(
"Jacobian Expansion Type",
"Linear");
150 precParams.
set(
"default values",
"SA");
151 precParams.
set(
"ML output", 0);
152 precParams.
set(
"max levels",5);
153 precParams.
set(
"increasing or decreasing",
"increasing");
154 precParams.
set(
"aggregation: type",
"Uncoupled");
155 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
156 precParams.
set(
"smoother: sweeps",2);
157 precParams.
set(
"smoother: pre or post",
"both");
158 precParams.
set(
"coarse: max size", 200);
159 precParams.
set(
"PDE equations",sz);
160 #ifdef HAVE_ML_AMESOS
161 precParams.
set(
"coarse: type",
"Amesos-KLU");
163 precParams.
set(
"coarse: type",
"Jacobi");
170 expansion, sg_parallel_data,
178 basis->evaluateBases(point, basis_vals);
181 for (
int i=0; i<num_KL; i++) {
182 sg_p_poly->
term(i,0)[i] = 0.0;
183 sg_p_poly->
term(i,1)[i] = 1.0 / basis_vals[i+1];
190 sg_x->PutScalar(0.0);
198 Teuchos::rcp(
new ML_Epetra::MultiLevelPreconditioner(*sg_J, precParams,
202 EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->
createInArgs();
203 EpetraExt::ModelEvaluator::OutArgs sg_outArgs = sg_model->
createOutArgs();
204 sg_inArgs.set_p(1, sg_p);
205 sg_inArgs.set_x(sg_x);
206 sg_outArgs.set_f(sg_f);
207 sg_outArgs.set_W(sg_J);
210 sg_model->
evalModel(sg_inArgs, sg_outArgs);
211 sg_M->ComputePreconditioner();
215 sg_f->Norm2(&norm_f);
217 std::cout <<
"\nInitial residual norm = " << norm_f << std::endl;
222 aztec.SetAztecOption(AZ_solver, AZ_cg);
224 aztec.SetAztecOption(AZ_solver, AZ_gmres);
225 aztec.SetAztecOption(AZ_precond, AZ_none);
226 aztec.SetAztecOption(AZ_kspace, 20);
227 aztec.SetAztecOption(AZ_conv, AZ_r0);
228 aztec.SetAztecOption(AZ_output, 1);
229 aztec.SetUserOperator(sg_J.get());
230 aztec.SetPrecOperator(sg_M.get());
231 aztec.SetLHS(sg_dx.get());
232 aztec.SetRHS(sg_f.
get());
235 aztec.Iterate(1000, 1e-12);
238 sg_x->Update(-1.0, *sg_dx, 1.0);
241 EpetraExt::VectorToMatrixMarketFile(
"stochastic_solution_interlaced.mm",
245 EpetraExt::VectorToMatrixMarketFile(
"stochastic_RHS_interlaced.mm",
249 EpetraExt::RowMatrixToMatrixMarketFile(
"stochastic_operator_interlaced.mm",
259 EpetraExt::VectorToMatrixMarketFile(
"mean_gal_interlaced.mm", mean);
260 EpetraExt::VectorToMatrixMarketFile(
"std_dev_gal_interlaced.mm", std_dev);
263 EpetraExt::ModelEvaluator::OutArgs sg_outArgs2 = sg_model->
createOutArgs();
266 sg_f->PutScalar(0.0);
267 sg_outArgs2.set_f(sg_f);
268 sg_outArgs2.set_g(0, sg_g);
269 sg_model->
evalModel(sg_inArgs, sg_outArgs2);
272 sg_f->Norm2(&norm_f);
274 std::cout <<
"\nFinal residual norm = " << norm_f << std::endl;
283 std::cout.precision(16);
287 std::cout << std::endl;
288 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
289 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
293 if (norm_f < 1.0e-10 &&
294 std::abs(g_mean[0]-g_mean_exp) < g_tol &&
295 std::abs(g_std_dev[0]-g_std_dev_exp) < g_tol)
299 std::cout <<
"Example Passed!" << std::endl;
301 std::cout <<
"Example Failed!" << std::endl;
311 catch (std::exception& e) {
312 std::cout << e.what() << std::endl;
314 catch (std::string& s) {
315 std::cout << s << std::endl;
318 std::cout << s << std::endl;
321 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.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void computeMean(Epetra_Vector &v) const
Compute mean.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
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.