46 #include "NOX_Epetra.H"
72 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
76 printParams.
set(
"MyPID", MyPID);
77 printParams.
set(
"Output Precision", 3);
78 printParams.
set(
"Output Processor", 0);
79 printParams.
set(
"Output Information",
80 NOX::Utils::OuterIteration +
81 NOX::Utils::OuterIterationStatusTest +
82 NOX::Utils::InnerIteration +
85 NOX::Utils::LinearSolverDetails +
91 searchParams.
set(
"Method",
"Full Step");
95 dirParams.
set(
"Method",
"Newton");
97 newtonParams.
set(
"Forcing Term Method",
"Constant");
101 lsParams.
set(
"Aztec Solver",
"GMRES");
102 lsParams.
set(
"Max Iterations", 100);
103 lsParams.
set(
"Size of Krylov Subspace", 100);
104 lsParams.
set(
"Tolerance", 1e-4);
105 lsParams.
set(
"Output Frequency", 10);
106 lsParams.
set(
"Preconditioner",
"Ifpack");
110 statusParams.
set(
"Test Type",
"Combo");
111 statusParams.
set(
"Number of Tests", 2);
112 statusParams.
set(
"Combo Type",
"OR");
114 normF.
set(
"Test Type",
"NormF");
115 normF.
set(
"Tolerance", 1e-10);
116 normF.
set(
"Scale Type",
"Scaled");
118 maxIters.
set(
"Test Type",
"MaxIters");
119 maxIters.
set(
"Maximum Iterations", 10);
135 ParameterList& printParams = noxParams->sublist(
"Printing");
136 NOX::Utils utils(printParams);
139 RCP<NOX::Epetra::ModelEvaluatorInterface> nox_interface =
140 rcp(
new NOX::Epetra::ModelEvaluatorInterface(sg_model));
143 RCP<const Epetra_Vector> u = sg_model->get_x_init();
144 RCP<Epetra_Operator>
A = sg_model->create_W();
145 RCP<NOX::Epetra::Interface::Required> iReq = nox_interface;
146 RCP<NOX::Epetra::Interface::Jacobian> iJac = nox_interface;
147 RCP<NOX::Epetra::LinearSystemAztecOO> linsys;
148 RCP<Epetra_Operator> M = sg_model->create_WPrec()->PrecOp;
149 RCP<NOX::Epetra::Interface::Preconditioner> iPrec = nox_interface;
150 ParameterList& dirParams = noxParams->sublist(
"Direction");
151 ParameterList& newtonParams = dirParams.sublist(
"Newton");
152 ParameterList& lsParams = newtonParams.sublist(
"Linear Solver");
153 lsParams.set(
"Preconditioner",
"User Defined");
154 linsys =
rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
155 iJac, A, iPrec, M, *u));
158 RCP<NOX::Epetra::Group> grp =
159 rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
162 ParameterList& statusParams = noxParams->sublist(
"Status Tests");
163 RCP<NOX::StatusTest::Generic> statusTests =
164 NOX::StatusTest::buildStatusTests(statusParams, utils);
167 RCP<NOX::Solver::Generic> solver =
168 NOX::Solver::buildSolver(grp, statusTests, noxParams);
174 const NOX::Epetra::Group& finalGroup =
175 dynamic_cast<const NOX::Epetra::Group&
>(solver.getSolutionGroup());
177 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
178 return finalSolution;
203 RCP<const Epetra_Comm> globalComm;
209 MyPID = globalComm->MyPID();
213 Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(1);
214 bases[0] =
rcp(
new LegendreBasis<int,double>(p));
215 RCP<const CompletePolynomialBasis<int,double> > basis =
216 rcp(
new CompletePolynomialBasis<int,double>(bases));
217 RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
218 basis->computeTripleProductTensor();
219 RCP<OrthogPolyExpansion<int,double> > expansion =
220 rcp(
new AlgebraicOrthogPolyExpansion<int,double>(basis, Cijk));
223 int num_spatial_procs = -1;
224 ParameterList parallelParams;
225 parallelParams.set(
"Number of Spatial Processors", num_spatial_procs);
226 RCP<ParallelData> sg_parallel_data =
227 rcp(
new ParallelData(basis, Cijk, globalComm, parallelParams));
228 RCP<const Epetra_Comm> app_comm = sg_parallel_data->getSpatialComm();
231 RCP<EpetraExt::ModelEvaluator> model =
rcp(
new SimpleME(app_comm));
234 RCP<ParameterList> sgParams =
rcp(
new ParameterList);
235 ParameterList& sgPrecParams = sgParams->sublist(
"SG Preconditioner");
236 sgPrecParams.set(
"Preconditioner Method",
"Mean-based");
239 sgPrecParams.set(
"Mean Preconditioner Type",
"Ifpack");
242 RCP<SGModelEvaluator> sg_model =
244 sg_parallel_data, sgParams));
249 RCP<EpetraVectorOrthogPoly> x_init_sg = sg_model->create_x_sg();
250 x_init_sg->init(0.0);
251 (*x_init_sg)[0] = *(model->get_x_init());
252 sg_model->set_x_sg_init(*x_init_sg);
258 RCP<EpetraVectorOrthogPoly> p_init_sg = sg_model->create_p_sg(0);
259 p_init_sg->init(0.0);
260 (*p_init_sg)[0] = *(model->get_p_init(0));
261 for (
int i=0; i<model->get_p_map(0)->NumMyElements(); i++)
262 (*p_init_sg)[i+1][i] = 1.0;
263 sg_model->set_p_sg_init(0, *p_init_sg);
264 std::cout <<
"Stochatic Galerkin parameter expansion = " << std::endl
265 << *p_init_sg << std::endl;
271 NOX::StatusTest::StatusType status = solver->solve();
277 RCP<Stokhos::EpetraVectorOrthogPoly> x_sg =
278 sg_model->create_x_sg(
View, &finalSolution);
281 std::cout <<
"Final Solution = " << std::endl;
282 std::cout << *x_sg << std::endl;
284 if (status != NOX::StatusTest::Converged)
289 if (success && MyPID == 0)
290 std::cout <<
"Example Passed!" << std::endl;
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Orthogonal polynomial expansions limited to algebraic operations.
Nonlinear, stochastic Galerkin ModelEvaluator.
Teuchos::RCP< Teuchos::ParameterList > create_nox_parameter_list(int MyPID)
Abstract base class for orthogonal polynomial-based expansions.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const Epetra_Vector & get_final_solution(const NOX::Solver::Generic &solver)
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Legendre polynomial basis.
int main(int argc, char **argv)
Abstract base class for 1-D orthogonal polynomials.
Teuchos::RCP< NOX::Solver::Generic > create_nox_solver(int MyPID, const Teuchos::RCP< EpetraExt::ModelEvaluator > &sg_model)