54 #include "NOX_Epetra.H"
55 #include "NOX_Epetra_LinearSystem_Stratimikos.H"
56 #include "BelosTypes.hpp"
66 #include "EpetraExt_VectorOut.h"
67 #include "EpetraExt_BlockUtility.h"
75 bool nonlinear_expansion =
false;
77 bool symmetric =
true;
78 bool use_solver =
true;
79 std::string solver_type =
"RGMRES";
83 MPI_Init(&argc,&argv);
90 Epetra_Object::SetTracebackMode(1);
102 MyPID = globalComm->
MyPID();
106 for (
int i=0; i<num_KL; i++)
114 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis));
116 quad->getQuadPoints();
119 quad->getBasisAtQuadPoints();
120 int sz = basis->size();
121 int num_mp = quad_weights.
size();
123 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
126 int num_spatial_procs = -1;
128 num_spatial_procs = std::atoi(argv[1]);
142 detPrecParams->
set(
"Preconditioner Type",
"ML");
144 detPrecParams->
sublist(
"Preconditioner Parameters");
145 precParams.
set(
"default values",
"SA");
146 precParams.
set(
"ML output", 0);
147 precParams.
set(
"max levels",5);
148 precParams.
set(
"increasing or decreasing",
"increasing");
149 precParams.
set(
"aggregation: type",
"Uncoupled");
150 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
151 precParams.
set(
"smoother: sweeps",2);
152 precParams.
set(
"smoother: pre or post",
"both");
153 precParams.
set(
"coarse: max size", 200);
154 #ifdef HAVE_ML_AMESOS
155 precParams.
set(
"coarse: type",
"Amesos-KLU");
157 precParams.
set(
"coarse: type",
"Jacobi");
163 nonlinear_expansion, symmetric,
170 mpParams->
sublist(
"MP Preconditioner");
171 mpPrecParams.
set(
"Preconditioner Method",
"Block Diagonal");
172 mpPrecParams.
set(
"MP Preconditioner Type",
"ML");
174 mpPrecParams.
sublist(
"MP Preconditioner Parameters");
175 pointPrecParams = precParams;
180 mp_block_map, mpParams));
185 int my_mp_begin = mp_block_map->
MinMyGID();
186 for (
int j=0;
j<num_my_mp;
j++) {
187 for (
int i=0; i<num_KL; i++) {
188 (*mp_p_init)[
j][i] = quad_points[
j+my_mp_begin][i];
196 mp_x_init->
init(0.0);
204 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
208 printParams.
set(
"MyPID", MyPID);
209 printParams.
set(
"Output Precision", 3);
210 printParams.
set(
"Output Processor", 0);
211 printParams.
set(
"Output Information",
212 NOX::Utils::OuterIteration +
213 NOX::Utils::OuterIterationStatusTest +
214 NOX::Utils::InnerIteration +
215 NOX::Utils::LinearSolverDetails +
216 NOX::Utils::Warning +
220 NOX::Utils utils(printParams);
224 searchParams.
set(
"Method",
"Full Step");
228 dirParams.
set(
"Method",
"Newton");
230 newtonParams.
set(
"Forcing Term Method",
"Constant");
235 stratLinSolParams.
sublist(
"Stratimikos");
238 stratParams.
set(
"Linear Solver Type",
"Belos");
240 stratParams.
sublist(
"Linear Solver Types").sublist(
"Belos");
242 if (solver_type ==
"GMRES") {
243 belosParams.
set(
"Solver Type",
"Block GMRES");
245 &(belosParams.
sublist(
"Solver Types").sublist(
"Block GMRES"));
247 else if (solver_type ==
"CG") {
248 belosParams.
set(
"Solver Type",
"Block CG");
250 &(belosParams.
sublist(
"Solver Types").sublist(
"Block CG"));
252 else if (solver_type ==
"RGMRES") {
253 belosParams.
set(
"Solver Type",
"GCRODR");
255 &(belosParams.
sublist(
"Solver Types").sublist(
"GCRODR"));
256 belosSolverParams->
set(
"Num Recycled Blocks", 20);
258 else if (solver_type ==
"RCG") {
259 belosParams.
set(
"Solver Type",
"RCG");
261 &(belosParams.
sublist(
"Solver Types").sublist(
"RCG"));
264 belosSolverParams->
set(
"Num Recycled Blocks", 10);
268 "Unknown solver type " << solver_type);
269 belosSolverParams->
set(
"Convergence Tolerance", 1e-12);
270 belosSolverParams->
set(
"Maximum Iterations", 1000);
271 if (solver_type !=
"CG")
272 belosSolverParams->
set(
"Num Blocks", 100);
273 belosSolverParams->
set(
"Block Size", 1);
274 belosSolverParams->
set(
"Output Frequency",1);
275 belosSolverParams->
set(
"Output Style",1);
277 belosSolverParams->
set(
"Verbosity",
280 Belos::StatusTestDetails);
281 stratLinSolParams.
set(
"Preconditioner",
"User Defined");
283 belosParams.
sublist(
"VerboseObject");
284 verboseParams.
set(
"Verbosity Level",
"medium");
288 statusParams.
set(
"Test Type",
"Combo");
289 statusParams.
set(
"Number of Tests", 2);
290 statusParams.
set(
"Combo Type",
"OR");
292 normF.
set(
"Test Type",
"NormF");
293 normF.
set(
"Tolerance", 1e-10);
294 normF.
set(
"Scale Type",
"Scaled");
296 maxIters.
set(
"Test Type",
"MaxIters");
297 maxIters.
set(
"Maximum Iterations", 1);
301 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(mp_model));
314 newtonParams.
sublist(
"Linear Solver");
315 outerSolParams.
sublist(
"Deterministic Solver Parameters") =
317 outerSolParams.
set(
"Preconditioner Strategy",
"Mean");
321 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(model));
333 inner_iJac, inner_A, inner_iPrec, inner_M,
336 Teuchos::rcp(
new NOX::Epetra::LinearSystemMPBD(printParams,
343 newtonParams.
sublist(
"Stratimikos Linear Solver") = stratLinSolParams;
345 Teuchos::rcp(
new NOX::Epetra::LinearSystemStratimikos(printParams,
353 Teuchos::rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
357 NOX::StatusTest::buildStatusTests(statusParams, utils);
361 NOX::Solver::buildSolver(grp, statusTests, noxParams);
364 NOX::StatusTest::StatusType status = solver->solve();
367 const NOX::Epetra::Group& finalGroup =
368 dynamic_cast<const NOX::Epetra::Group&
>(solver->getSolutionGroup());
370 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
378 EpetraExt::ModelEvaluator::InArgs mp_inArgs = mp_model->
createInArgs();
379 EpetraExt::ModelEvaluator::OutArgs mp_outArgs = mp_model->
createOutArgs();
380 mp_inArgs.set_x(mp_x);
381 mp_inArgs.set_p(1, mp_p);
382 mp_outArgs.set_g(0, mp_g);
383 mp_model->
evalModel(mp_inArgs, mp_outArgs);
390 *(model->
get_x_map()), *mp_local_map, *globalComm));
393 *(model->
get_g_map(0)), *mp_local_map, *globalComm));
398 mp_local_x.Import(*mp_x, mp_x_importer,
Add);
399 mp_local_g.Import(*mp_g, mp_g_importer,
Add);
406 multi_comm,
View, mp_local_x);
411 multi_comm, View, mp_local_g);
418 for (
int i=0; i<sz; i++) {
419 sg_x[i].PutScalar(0.0);
420 sg_g[i].PutScalar(0.0);
421 for (
int j=0;
j<num_mp;
j++) {
422 sg_x[i].Update(quad_weights[
j]*quad_values[
j][i], mp_x_vec[
j], 1.0);
423 sg_g[i].Update(quad_weights[j]*quad_values[j][i], mp_g_vec[j], 1.0);
428 EpetraExt::VectorToMatrixMarketFile(
"ni_stochastic_solution.mm",
429 *(sg_x.getBlockVector()));
434 sg_x.computeMean(mean);
435 sg_x.computeStandardDeviation(std_dev);
436 EpetraExt::VectorToMatrixMarketFile(
"mean_gal.mm", mean);
441 sg_g.computeMean(g_mean);
442 sg_g.computeStandardDeviation(g_std_dev);
446 std::cout << std::endl;
447 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
448 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
450 if (status == NOX::StatusTest::Converged && MyPID == 0)
451 utils.out() <<
"Example Passed!" << std::endl;
460 catch (std::exception& e) {
461 std::cout << e.what() << std::endl;
463 catch (std::string& s) {
464 std::cout << s << std::endl;
467 std::cout << s << std::endl;
470 std::cout <<
"Caught unknown exception!" <<std:: endl;
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Teuchos::RCP< const Epetra_Comm > getStochasticComm(const Teuchos::RCP< const EpetraExt::MultiComm > &globalMultiComm)
void set_x_mp_init(const Stokhos::ProductEpetraVector &x_mp_in)
Set initial multi-point solution.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void init(const value_type &val)
Initialize coefficients.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< Stokhos::ProductEpetraVector > create_x_mp(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create multi-point vector using x map and owned mp map.
Multi-point model evaluator.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
Teuchos::RCP< const EpetraExt::MultiComm > buildMultiComm(const Epetra_Comm &globalComm, int num_global_stochastic_blocks, int num_spatial_procs=-1)
virtual int MyPID() const =0
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner operator.
int NumMyElements() const
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)
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
virtual const Epetra_BlockMap & Map() const =0
A container class for products of Epetra_Vector's.
OutArgs createOutArgs() const
Create OutArgs.
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.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner for W.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
InArgs createInArgs() const
Create InArgs.
Teuchos::RCP< const Epetra_Comm > getSpatialComm(const Teuchos::RCP< const EpetraExt::MultiComm > &globalMultiComm)
void set_p_mp_init(int i, const Stokhos::ProductEpetraVector &p_mp_in)
Set initial multi-point parameter.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
static void zeroOutTimers()
Teuchos::RCP< Stokhos::ProductEpetraVector > create_p_mp(int l, Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create multi-point vector using p map.