15 #include "NOX_Epetra.H"
37 MPI_Init(&argc,&argv);
51 MyPID = globalComm->
MyPID();
59 int sz = basis->size();
61 Cijk = basis->computeTripleProductTensor();
66 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
69 int num_spatial_procs = -1;
71 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
87 sgParams->
set(
"Jacobian Method",
"Matrix Free");
88 sgParams->
set(
"Mean Preconditioner Type",
"Ifpack");
93 expansion, sg_parallel_data,
101 x_init_sg->
init(0.0);
102 (*x_init_sg)[0] = *(model->get_x_init());
111 p_init_sg->
init(0.0);
112 (*p_init_sg)[0] = *(model->get_p_init(0));
113 for (
int i=0; i<model->get_p_map(0)->NumMyElements(); i++)
114 (*p_init_sg)[i+1][i] = 1.0;
116 std::cout <<
"Stochatic Galerkin parameter expansion = " << std::endl
117 << *p_init_sg << std::endl;
124 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
128 printParams.
set(
"MyPID", MyPID);
129 printParams.
set(
"Output Precision", 3);
130 printParams.
set(
"Output Processor", 0);
131 printParams.
set(
"Output Information",
132 NOX::Utils::OuterIteration +
133 NOX::Utils::OuterIterationStatusTest +
134 NOX::Utils::InnerIteration +
137 NOX::Utils::LinearSolverDetails +
138 NOX::Utils::Warning +
142 NOX::Utils utils(printParams);
146 searchParams.
set(
"Method",
"Full Step");
150 dirParams.
set(
"Method",
"Newton");
152 newtonParams.
set(
"Forcing Term Method",
"Constant");
156 lsParams.
set(
"Aztec Solver",
"GMRES");
157 lsParams.
set(
"Max Iterations", 100);
158 lsParams.
set(
"Size of Krylov Subspace", 100);
159 lsParams.
set(
"Tolerance", 1e-4);
160 lsParams.
set(
"Output Frequency", 10);
161 lsParams.
set(
"Preconditioner",
"Ifpack");
165 statusParams.
set(
"Test Type",
"Combo");
166 statusParams.
set(
"Number of Tests", 2);
167 statusParams.
set(
"Combo Type",
"OR");
169 normF.
set(
"Test Type",
"NormF");
170 normF.
set(
"Tolerance", 1e-10);
171 normF.
set(
"Scale Type",
"Scaled");
173 maxIters.
set(
"Test Type",
"MaxIters");
174 maxIters.
set(
"Maximum Iterations", 10);
178 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(sg_model));
188 lsParams.
set(
"Preconditioner",
"User Defined");
190 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
199 Teuchos::rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
203 NOX::StatusTest::buildStatusTests(statusParams, utils);
207 NOX::Solver::buildSolver(grp, statusTests, noxParams);
210 NOX::StatusTest::StatusType status = solver->solve();
213 const NOX::Epetra::Group& finalGroup =
214 dynamic_cast<const NOX::Epetra::Group&
>(solver->getSolutionGroup());
216 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
222 utils.out() <<
"Final Solution (block vector) = " << std::endl;
223 std::cout << finalSolution << std::endl;
224 utils.out() <<
"Final Solution (polynomial) = " << std::endl;
225 std::cout << *x_sg << std::endl;
227 if (status == NOX::StatusTest::Converged && MyPID == 0)
228 utils.out() <<
"Example Passed!" << std::endl;
232 catch (std::exception& e) {
233 std::cout << e.what() << std::endl;
235 catch (std::string& s) {
236 std::cout << s << std::endl;
239 std::cout << s << std::endl;
242 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 EpetraExt::MultiComm > getMultiComm() const
Get global comm.
void init(const value_type &val)
Initialize coefficients.
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
void set_p_sg_init(int i, const Stokhos::EpetraVectorOrthogPoly &p_sg_in)
Set initial parameter polynomial.
Legendre polynomial basis.
void set_x_sg_init(const Stokhos::EpetraVectorOrthogPoly &x_sg_in)
Set initial solution polynomial.
int main(int argc, char **argv)
Teuchos::RCP< const Epetra_Comm > getSpatialComm() const
Get spatial comm.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner operator.