54 #include "NOX_Epetra.H"
63 #include "EpetraExt_VectorOut.h"
71 bool nonlinear_expansion =
false;
73 bool matrix_free =
true;
74 bool symmetric =
false;
76 double g_mean_exp = 0.172988;
77 double g_std_dev_exp = 0.0380007;
82 MPI_Init(&argc,&argv);
99 MyPID = globalComm->
MyPID();
103 for (
int i=0; i<num_KL; i++)
107 int sz = basis->size();
109 if (nonlinear_expansion)
110 Cijk = basis->computeTripleProductTensor();
112 Cijk = basis->computeLinearTripleProductTensor();
117 std::cout <<
"Stochastic Galerkin expansion size = " << sz << std::endl;
120 int num_spatial_procs = -1;
122 num_spatial_procs = std::atoi(argv[1]);
124 parallelParams.
set(
"Number of Spatial Processors", num_spatial_procs);
136 nonlinear_expansion, symmetric));
142 sgParams->
sublist(
"SG Operator");
144 sgParams->
sublist(
"SG Preconditioner");
145 if (!nonlinear_expansion) {
146 sgParams->
set(
"Parameter Expansion Type",
"Linear");
147 sgParams->
set(
"Jacobian Expansion Type",
"Linear");
150 sgOpParams.
set(
"Operator Method",
"Matrix Free");
151 sgPrecParams.
set(
"Preconditioner Method",
"Approximate Gauss-Seidel");
152 sgPrecParams.
set(
"Symmetric Gauss-Seidel", symmetric);
153 sgPrecParams.
set(
"Mean Preconditioner Type",
"ML");
155 sgPrecParams.
sublist(
"Mean Preconditioner Parameters");
156 precParams.
set(
"default values",
"SA");
157 precParams.
set(
"ML output", 0);
158 precParams.
set(
"max levels",5);
159 precParams.
set(
"increasing or decreasing",
"increasing");
160 precParams.
set(
"aggregation: type",
"Uncoupled");
161 precParams.
set(
"smoother: type",
"ML symmetric Gauss-Seidel");
162 precParams.
set(
"smoother: sweeps",2);
163 precParams.
set(
"smoother: pre or post",
"both");
164 precParams.
set(
"coarse: max size", 200);
165 #ifdef HAVE_ML_AMESOS
166 precParams.
set(
"coarse: type",
"Amesos-KLU");
168 precParams.
set(
"coarse: type",
"Jacobi");
172 sgOpParams.
set(
"Operator Method",
"Fully Assembled");
173 sgPrecParams.
set(
"Preconditioner Method",
"None");
179 expansion, sg_parallel_data,
187 basis->evaluateBases(point, basis_vals);
190 for (
int i=0; i<num_KL; i++) {
191 sg_p_init->
term(i,0)[i] = 0.0;
192 sg_p_init->
term(i,1)[i] = 1.0 / basis_vals[i+1];
199 sg_x_init->
init(0.0);
207 noxParams->
set(
"Nonlinear Solver",
"Line Search Based");
211 printParams.
set(
"MyPID", MyPID);
212 printParams.
set(
"Output Precision", 3);
213 printParams.
set(
"Output Processor", 0);
214 printParams.
set(
"Output Information",
215 NOX::Utils::OuterIteration +
216 NOX::Utils::OuterIterationStatusTest +
217 NOX::Utils::InnerIteration +
218 NOX::Utils::LinearSolverDetails +
219 NOX::Utils::Warning +
223 NOX::Utils utils(printParams);
227 searchParams.
set(
"Method",
"Full Step");
231 dirParams.
set(
"Method",
"Newton");
233 newtonParams.
set(
"Forcing Term Method",
"Constant");
238 lsParams.
set(
"Aztec Solver",
"CG");
240 lsParams.
set(
"Aztec Solver",
"GMRES");
241 lsParams.
set(
"Max Iterations", 1000);
242 lsParams.
set(
"Size of Krylov Subspace", 100);
243 lsParams.
set(
"Tolerance", 1e-12);
244 lsParams.
set(
"Output Frequency", 1);
246 lsParams.
set(
"Preconditioner",
"User Defined");
248 lsParams.
set(
"Preconditioner",
"ML");
251 ML_Epetra::SetDefaults(
"DD", precParams);
252 lsParams.
set(
"Write Linear System",
false);
257 statusParams.
set(
"Test Type",
"Combo");
258 statusParams.
set(
"Number of Tests", 2);
259 statusParams.
set(
"Combo Type",
"OR");
261 normF.
set(
"Test Type",
"NormF");
262 normF.
set(
"Tolerance", 1e-10);
263 normF.
set(
"Scale Type",
"Scaled");
265 maxIters.
set(
"Test Type",
"MaxIters");
266 maxIters.
set(
"Maximum Iterations", 1);
270 Teuchos::rcp(
new NOX::Epetra::ModelEvaluatorInterface(sg_model));
282 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
288 Teuchos::rcp(
new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
295 Teuchos::rcp(
new NOX::Epetra::Group(printParams, iReq, *u, linsys));
299 NOX::StatusTest::buildStatusTests(statusParams, utils);
303 NOX::Solver::buildSolver(grp, statusTests, noxParams);
306 NOX::StatusTest::StatusType status = solver->solve();
309 const NOX::Epetra::Group& finalGroup =
310 dynamic_cast<const NOX::Epetra::Group&
>(solver->getSolutionGroup());
312 (
dynamic_cast<const NOX::Epetra::Vector&
>(finalGroup.getX())).getEpetraVector();
315 EpetraExt::VectorToMatrixMarketFile(
"nox_stochastic_solution.mm",
325 EpetraExt::VectorToMatrixMarketFile(
"mean_gal.mm", mean);
326 EpetraExt::VectorToMatrixMarketFile(
"std_dev_gal.mm", std_dev);
329 EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->
createInArgs();
330 EpetraExt::ModelEvaluator::OutArgs sg_outArgs =
335 sg_inArgs.set_p(1, sg_p);
337 sg_outArgs.set_g(0, sg_g);
338 sg_model->
evalModel(sg_inArgs, sg_outArgs);
347 std::cout.precision(16);
351 std::cout << std::endl;
352 std::cout <<
"Response Mean = " << std::endl << g_mean << std::endl;
353 std::cout <<
"Response Std. Dev. = " << std::endl << g_std_dev << std::endl;
357 if (status == NOX::StatusTest::Converged &&
358 std::abs(g_mean[0]-g_mean_exp) < g_tol &&
359 std::abs(g_std_dev[0]-g_std_dev_exp) < g_tol)
363 std::cout <<
"Example Passed!" << std::endl;
365 std::cout <<
"Example Failed!" << std::endl;
375 catch (std::exception& e) {
376 std::cout << e.what() << std::endl;
378 catch (std::string& s) {
379 std::cout << s << std::endl;
382 std::cout << s << std::endl;
385 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.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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="")
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()