47 #include "NOX_Epetra.H"
69 MPI_Init(&argc,&argv);
83 MyPID = globalComm->
MyPID();
91 int sz = basis->size();
93 Cijk = basis->computeTripleProductTensor();
98 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
101 int num_spatial_procs = -1;
103 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
119 sgParams->
set(
"Jacobian Method",
"Matrix Free");
120 sgParams->
set(
"Mean Preconditioner Type",
"Ifpack");
125 expansion, sg_parallel_data,
133 x_init_sg->
init(0.0);
134 (*x_init_sg)[0] = *(model->get_x_init());
143 p_init_sg->
init(0.0);
144 (*p_init_sg)[0] = *(model->get_p_init(0));
145 for (
int i=0; i<model->get_p_map(0)->NumMyElements(); i++)
146 (*p_init_sg)[i+1][i] = 1.0;
148 std::cout <<
"Stochatic Galerkin parameter expansion = " << std::endl
149 << *p_init_sg << std::endl;
156 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
160 printParams.
set(
"MyPID", MyPID);
161 printParams.
set(
"Output Precision", 3);
162 printParams.
set(
"Output Processor", 0);
163 printParams.
set(
"Output Information",
164 NOX::Utils::OuterIteration +
165 NOX::Utils::OuterIterationStatusTest +
166 NOX::Utils::InnerIteration +
169 NOX::Utils::LinearSolverDetails +
170 NOX::Utils::Warning +
174 NOX::Utils utils(printParams);
178 searchParams.
set(
"Method",
"Full Step");
182 dirParams.
set(
"Method",
"Newton");
184 newtonParams.
set(
"Forcing Term Method",
"Constant");
188 lsParams.
set(
"Aztec Solver",
"GMRES");
189 lsParams.
set(
"Max Iterations", 100);
190 lsParams.
set(
"Size of Krylov Subspace", 100);
191 lsParams.
set(
"Tolerance", 1e-4);
192 lsParams.
set(
"Output Frequency", 10);
193 lsParams.
set(
"Preconditioner",
"Ifpack");
197 statusParams.
set(
"Test Type",
"Combo");
198 statusParams.
set(
"Number of Tests", 2);
199 statusParams.
set(
"Combo Type",
"OR");
201 normF.
set(
"Test Type",
"NormF");
202 normF.
set(
"Tolerance", 1e-10);
203 normF.
set(
"Scale Type",
"Scaled");
205 maxIters.
set(
"Test Type",
"MaxIters");
206 maxIters.
set(
"Maximum Iterations", 10);
210 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(sg_model));
220 lsParams.
set(
"Preconditioner",
"User Defined");
222 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
231 Teuchos::rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
235 NOX::StatusTest::buildStatusTests(statusParams, utils);
239 NOX::Solver::buildSolver(grp, statusTests, noxParams);
242 NOX::StatusTest::StatusType status = solver->solve();
245 const NOX::Epetra::Group& finalGroup =
246 dynamic_cast<const NOX::Epetra::Group&
>(solver->getSolutionGroup());
248 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
254 utils.out() <<
"Final Solution (block vector) = " << std::endl;
255 std::cout << finalSolution << std::endl;
256 utils.out() <<
"Final Solution (polynomial) = " << std::endl;
257 std::cout << *x_sg << std::endl;
259 if (status == NOX::StatusTest::Converged && MyPID == 0)
260 utils.out() <<
"Example Passed!" << std::endl;
264 catch (std::exception& e) {
265 std::cout << e.what() << std::endl;
267 catch (std::string& s) {
268 std::cout << s << std::endl;
271 std::cout << s << std::endl;
274 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.
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.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
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.