22 #include "NOX_Epetra.H"
31 #include "EpetraExt_VectorOut.h"
39 bool nonlinear_expansion =
false;
41 bool matrix_free =
true;
42 bool symmetric =
false;
44 double g_mean_exp = 0.172988;
45 double g_std_dev_exp = 0.0380007;
50 MPI_Init(&argc,&argv);
67 MyPID = globalComm->
MyPID();
71 for (
int i=0; i<num_KL; i++)
75 int sz = basis->size();
77 if (nonlinear_expansion)
78 Cijk = basis->computeTripleProductTensor();
80 Cijk = basis->computeLinearTripleProductTensor();
85 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
88 int num_spatial_procs = -1;
90 num_spatial_procs = std::atoi(argv[1]);
92 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
104 nonlinear_expansion, symmetric));
110 sgParams->
sublist(
"SG Operator");
112 sgParams->
sublist(
"SG Preconditioner");
113 if (!nonlinear_expansion) {
114 sgParams->
set(
"Parameter Expansion Type",
"Linear");
115 sgParams->
set(
"Jacobian Expansion Type",
"Linear");
118 sgOpParams.
set(
"Operator Method",
"Matrix Free");
119 sgPrecParams.
set(
"Preconditioner Method",
"Approximate Gauss-Seidel");
120 sgPrecParams.
set(
"Symmetric Gauss-Seidel", symmetric);
121 sgPrecParams.
set(
"Mean Preconditioner Type",
"ML");
123 sgPrecParams.
sublist(
"Mean Preconditioner Parameters");
124 precParams.
set(
"default values",
"SA");
125 precParams.
set(
"ML output", 0);
126 precParams.
set(
"max levels",5);
127 precParams.
set(
"increasing or decreasing",
"increasing");
128 precParams.
set(
"aggregation: type",
"Uncoupled");
129 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
130 precParams.
set(
"smoother: sweeps",2);
131 precParams.
set(
"smoother: pre or post",
"both");
132 precParams.
set(
"coarse: max size", 200);
133 #ifdef HAVE_ML_AMESOS
134 precParams.
set(
"coarse: type",
"Amesos-KLU");
136 precParams.
set(
"coarse: type",
"Jacobi");
140 sgOpParams.
set(
"Operator Method",
"Fully Assembled");
141 sgPrecParams.
set(
"Preconditioner Method",
"None");
147 expansion, sg_parallel_data,
155 basis->evaluateBases(point, basis_vals);
158 for (
int i=0; i<num_KL; i++) {
159 sg_p_init->
term(i,0)[i] = 0.0;
160 sg_p_init->
term(i,1)[i] = 1.0 / basis_vals[i+1];
167 sg_x_init->
init(0.0);
175 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
179 printParams.
set(
"MyPID", MyPID);
180 printParams.
set(
"Output Precision", 3);
181 printParams.
set(
"Output Processor", 0);
182 printParams.
set(
"Output Information",
183 NOX::Utils::OuterIteration +
184 NOX::Utils::OuterIterationStatusTest +
185 NOX::Utils::InnerIteration +
186 NOX::Utils::LinearSolverDetails +
187 NOX::Utils::Warning +
191 NOX::Utils utils(printParams);
195 searchParams.
set(
"Method",
"Full Step");
199 dirParams.
set(
"Method",
"Newton");
201 newtonParams.
set(
"Forcing Term Method",
"Constant");
206 lsParams.
set(
"Aztec Solver",
"CG");
208 lsParams.
set(
"Aztec Solver",
"GMRES");
209 lsParams.
set(
"Max Iterations", 1000);
210 lsParams.
set(
"Size of Krylov Subspace", 100);
211 lsParams.
set(
"Tolerance", 1e-12);
212 lsParams.
set(
"Output Frequency", 1);
214 lsParams.
set(
"Preconditioner",
"User Defined");
216 lsParams.
set(
"Preconditioner",
"ML");
219 ML_Epetra::SetDefaults(
"DD", precParams);
220 lsParams.
set(
"Write Linear System",
false);
225 statusParams.
set(
"Test Type",
"Combo");
226 statusParams.
set(
"Number of Tests", 2);
227 statusParams.
set(
"Combo Type",
"OR");
229 normF.
set(
"Test Type",
"NormF");
230 normF.
set(
"Tolerance", 1e-10);
231 normF.
set(
"Scale Type",
"Scaled");
233 maxIters.
set(
"Test Type",
"MaxIters");
234 maxIters.
set(
"Maximum Iterations", 1);
238 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(sg_model));
250 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
256 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
263 Teuchos::rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
267 NOX::StatusTest::buildStatusTests(statusParams, utils);
271 NOX::Solver::buildSolver(grp, statusTests, noxParams);
274 NOX::StatusTest::StatusType status = solver->solve();
277 const NOX::Epetra::Group& finalGroup =
278 dynamic_cast<const NOX::Epetra::Group&
>(solver->getSolutionGroup());
280 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
283 EpetraExt::VectorToMatrixMarketFile(
"nox_stochastic_solution.mm",
293 EpetraExt::VectorToMatrixMarketFile(
"mean_gal.mm", mean);
294 EpetraExt::VectorToMatrixMarketFile(
"std_dev_gal.mm", std_dev);
297 EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->
createInArgs();
298 EpetraExt::ModelEvaluator::OutArgs sg_outArgs =
303 sg_inArgs.set_p(1, sg_p);
305 sg_outArgs.set_g(0, sg_g);
306 sg_model->
evalModel(sg_inArgs, sg_outArgs);
315 std::cout.precision(16);
319 std::cout << std::endl;
320 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
321 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
325 if (status == NOX::StatusTest::Converged &&
326 std::abs(g_mean[0]-g_mean_exp) < g_tol &&
327 std::abs(g_std_dev[0]-g_std_dev_exp) < g_tol)
331 std::cout <<
"Example Passed!" << std::endl;
333 std::cout <<
"Example Failed!" << std::endl;
343 catch (std::exception& e) {
344 std::cout << e.what() << std::endl;
346 catch (std::string& s) {
347 std::cout << s << std::endl;
350 std::cout << s << std::endl;
353 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.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
void computeStandardDeviation(Epetra_Vector &v) const
Compute standard deviation.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
void computeMean(Epetra_Vector &v) const
Compute mean.
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.
OutArgs createOutArgs() const
Create OutArgs.
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.
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< 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.
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.
InArgs createInArgs() const
Create InArgs.
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< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
coeff_type & term(ordinal_type dimension, ordinal_type order)
Get term for dimension dimension and order order.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner operator.
static void zeroOutTimers()