Debian Codegraph @

packages/nox/test/epetra/Thyra/Thyra_Rosenbrock_AndersonAcceleration.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // NOX: An Object-Oriented Nonlinear Solver Package
4 //
5 // Copyright 2002 NTESS and the NOX contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include <Teuchos_ConfigDefs.hpp>
11 #include <Teuchos_UnitTestHarness.hpp>
12 #include <Teuchos_TimeMonitor.hpp>
13
14 // NOX Objects
15 #include "NOX.H"
16 #include "NOX_Thyra.H"
17
18 // Trilinos Objects
19 #ifdef HAVE_MPI
20 #include "Epetra_MpiComm.h"
21 #else
22 #include "Epetra_SerialComm.h"
23 #endif
24 #include "Epetra_Map.h"
25 #include "Epetra_Vector.h"
26 #include "Epetra_RowMatrix.h"
27 #include "Epetra_CrsMatrix.h"
28 #include "Epetra_Map.h"
29 #include "Epetra_LinearProblem.h"
30 #include "AztecOO.h"
31
32 #include "Teuchos_ParameterList.hpp"
33 #include "Teuchos_Assert.hpp"
34
35 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
36 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
37 #include "Thyra_ScaledModelEvaluator.hpp"
38 #include "ModelEvaluatorRosenbrock.hpp"
39 #include "Observer_PrintTest.hpp"
40 #include "Thyra_SpmdVectorBase.hpp"
41 #include "Thyra_DefaultSpmdVectorSpace.hpp"
42
43 #include "NOX_PrePostOperator_RowSumScaling.H"
44 #include "Thyra_VectorBase.hpp"
45
46 using namespace std;
47
48 TEUCHOS_UNIT_TEST(AndersonAcceleration, AA_Rosenbrock)
49 {
50 int status = 0;
51
52 // Create a communicator for Epetra objects
53 #ifdef HAVE_MPI
54 Epetra_MpiComm Comm( MPI_COMM_WORLD );
55 #else
56 Epetra_SerialComm Comm;
57 #endif
58
59 TEST_ASSERT(Comm.NumProc() == 1);
60
61 ::Stratimikos::DefaultLinearSolverBuilder builder;
62
63 Teuchos::RCP<Teuchos::ParameterList> p =
64 Teuchos::rcp(new Teuchos::ParameterList);
65 {
66 p->set("Linear Solver Type", "AztecOO");
67 //p->set("Preconditioner Type", "Ifpack");
68 p->set("Preconditioner Type", "None");
69 Teuchos::ParameterList& az = p->sublist("Linear Solver Types").sublist("AztecOO");
70 az.sublist("Forward Solve").sublist("AztecOO Settings").set("Output Frequency", 1);
71 az.sublist("VerboseObject").set("Verbosity Level", "high");
72 Teuchos::ParameterList& ip = p->sublist("Preconditioner Types").sublist("Ifpack");
73 ip.sublist("VerboseObject").set("Verbosity Level", "high");
74 }
75
76 builder.setParameterList(p);
77
78 Teuchos::RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
79 lowsFactory = builder.createLinearSolveStrategy("");
80
81 Teuchos::RCP<RosenbrockModelEvaluator> thyraModel =
82 Teuchos::rcp(new RosenbrockModelEvaluator(Teuchos::rcp(&Comm,false)));
83
84 thyraModel->set_W_factory(lowsFactory);
85
86 // Create nox parameter list
87 Teuchos::RCP<Teuchos::ParameterList> nl_params =
88 Teuchos::rcp(new Teuchos::ParameterList);
89 nl_params->set("Nonlinear Solver", "Anderson Accelerated Fixed-Point");
90 nl_params->sublist("Anderson Parameters").set("Storage Depth", 2);
91 nl_params->sublist("Anderson Parameters").set("Mixing Parameter", 1.0);
92 nl_params->sublist("Anderson Parameters").set("Acceleration Start Iteration", 1);
93 nl_params->sublist("Anderson Parameters").set("Adjust Matrix for Condition Number", false);
94 nl_params->sublist("Anderson Parameters").sublist("Preconditioning").set("Precondition", false);
95
96 Teuchos::ParameterList& printParams = nl_params->sublist("Printing");
97 printParams.set("Output Information",
98 NOX::Utils::OuterIteration +
99 NOX::Utils::OuterIterationStatusTest +
100 NOX::Utils::InnerIteration +
101 NOX::Utils::LinearSolverDetails +
102 NOX::Utils::Parameters +
103 NOX::Utils::Details +
104 NOX::Utils::Warning +
105 NOX::Utils::Debug +
106 NOX::Utils::TestDetails +
107 NOX::Utils::Error);
108
109 nl_params->sublist("Solver Options").set("Status Test Check Type", "Complete");
110
111 // Enable row sum scaling
112 nl_params->sublist("Thyra Group Options").set("Function Scaling", "Row Sum");
113
114 Teuchos::RCP<NOX::Abstract::PrePostOperator> observer;
115 {
116 NOX::Utils utils(printParams);
117 observer = Teuchos::rcp(new ObserverPrintTest(utils));
118 nl_params->sublist("Solver Options").set("User Defined Pre/Post Operator",observer);
119 }
120
121 // Create Status Tests
122 {
123 Teuchos::ParameterList& st = nl_params->sublist("Status Tests");
124 st.set("Test Type", "Combo");
125 st.set("Combo Type", "OR");
126 st.set("Number of Tests", 3);
127
128 {
129 Teuchos::ParameterList& conv = st.sublist("Test 0");
130 conv.set("Test Type", "Combo");
131 conv.set("Combo Type", "AND");
132 conv.set("Number of Tests", 2);
133
134 Teuchos::ParameterList& normF_rel = conv.sublist("Test 0");
135 normF_rel.set("Test Type", "NormF");
136 normF_rel.set("Tolerance", 1.0e-8);
137
138 Teuchos::ParameterList& normWRMS = conv.sublist("Test 1");
139 normWRMS.set("Test Type", "NormWRMS");
140 normWRMS.set("Absolute Tolerance", 1.0e-8);
141 normWRMS.set("Relative Tolerance", 1.0e-5);
142 normWRMS.set("Tolerance", 1.0);
143 normWRMS.set("BDF Multiplier", 1.0);
144 normWRMS.set("Alpha", 1.0);
145 normWRMS.set("Beta", 0.5);
146 normWRMS.set("Disable Implicit Weighting", true);
147 }
148
149 {
150 Teuchos::ParameterList& fv = st.sublist("Test 1");
151 fv.set("Test Type", "FiniteValue");
152 fv.set("Vector Type", "F Vector");
153 fv.set("Norm Type", "Two Norm");
154 }
155
156 {
157 Teuchos::ParameterList& maxiters = st.sublist("Test 2");
158 maxiters.set("Test Type", "MaxIters");
159 maxiters.set("Maximum Iterations", 100);
160 }
161
162 }
163
164 // Create a Thyra nonlinear solver
165 Teuchos::RCP< ::Thyra::NonlinearSolverBase<double> > solver =
166 Teuchos::rcp(new ::Thyra::NOXNonlinearSolver);
167
168 solver->setParameterList(nl_params);
169 solver->setModel(thyraModel);
170
171 Teuchos::RCP< ::Thyra::VectorBase<double> >
172 initial_guess = thyraModel->getNominalValues().get_x()->clone_v();
173
174 ::Thyra::SolveCriteria<double> solve_criteria;
175 ::Thyra::SolveStatus<double> solve_status;
176
177 solve_status = solver->solve(initial_guess.get(), &solve_criteria);
178
179
180 Teuchos::RCP< ::Thyra::NOXNonlinearSolver> thyra_nox_solver =
181 Teuchos::rcp_dynamic_cast< ::Thyra::NOXNonlinearSolver>(solver);
182 TEST_EQUALITY(thyra_nox_solver->getNOXSolver()->getNumIterations(), 6);
183
184 Teuchos::RCP<const Epetra_Vector> x_analytic = thyraModel->get_analytic_solution();
185
186 Teuchos::RCP<const NOX::Abstract::Vector> x = thyra_nox_solver->getNOXSolver()->getSolutionGroup().getXPtr();
187
188 Teuchos::RCP<const NOX::Thyra::Vector> nox_thyra_x =
189 Teuchos::rcp_dynamic_cast<const NOX::Thyra::Vector>(x,true);
190
191 Teuchos::RCP<const Thyra::SpmdVectorBase<double> > spmd_x =
192 Teuchos::rcp_dynamic_cast<const Thyra::SpmdVectorBase<double> >(nox_thyra_x->getThyraRCPVector(),true);
193
194 Teuchos::ArrayRCP<const double> local_values;
195 spmd_x->getLocalData(outArg(local_values));
196
197 double tol = 1.0e-7;
198 TEST_FLOATING_EQUALITY((*x_analytic)[0],local_values[0],tol);
199 TEST_FLOATING_EQUALITY((*x_analytic)[1],local_values[1],tol);
200
201 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPreIterateCalls(),6);
202 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPostIterateCalls(),6);
203 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPreSolveCalls(),1);
204 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPostSolveCalls(),1);
205
206 if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_CONVERGED)
207 std::cout << "Test passed!" << std::endl;
208
209 // std::cout << *p << std::endl;
210
211 Teuchos::TimeMonitor::summarize();
212
213 // Final return value (0 = successfull, non-zero = failure)
214 TEST_ASSERT(status == 0);
215 }
216
217 // Same test as above but uses the ill-conditioned R matrix monitoring
218 // to drop the oldest vector. This uses a larger space than what is
219 // normally allowed, so we have to disable the default checking.
220
221 TEUCHOS_UNIT_TEST(AndersonAcceleration, AA_IllConditionedQRMonitoring)
222 {
223 int status = 0;
224
225 // Create a communicator for Epetra objects
226 #ifdef HAVE_MPI
227 Epetra_MpiComm Comm( MPI_COMM_WORLD );
228 #else
229 Epetra_SerialComm Comm;
230 #endif
231
232 TEST_ASSERT(Comm.NumProc() == 1);
233
234 ::Stratimikos::DefaultLinearSolverBuilder builder;
235
236 Teuchos::RCP<Teuchos::ParameterList> p =
237 Teuchos::rcp(new Teuchos::ParameterList);
238 {
239 p->set("Linear Solver Type", "AztecOO");
240 //p->set("Preconditioner Type", "Ifpack");
241 p->set("Preconditioner Type", "None");
242 Teuchos::ParameterList& az = p->sublist("Linear Solver Types").sublist("AztecOO");
243 az.sublist("Forward Solve").sublist("AztecOO Settings").set("Output Frequency", 1);
244 az.sublist("VerboseObject").set("Verbosity Level", "high");
245 Teuchos::ParameterList& ip = p->sublist("Preconditioner Types").sublist("Ifpack");
246 ip.sublist("VerboseObject").set("Verbosity Level", "high");
247 }
248
249 builder.setParameterList(p);
250
251 Teuchos::RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
252 lowsFactory = builder.createLinearSolveStrategy("");
253
254 Teuchos::RCP<RosenbrockModelEvaluator> thyraModel =
255 Teuchos::rcp(new RosenbrockModelEvaluator(Teuchos::rcp(&Comm,false)));
256
257 thyraModel->set_W_factory(lowsFactory);
258
259 // Create nox parameter list
260 Teuchos::RCP<Teuchos::ParameterList> nl_params =
261 Teuchos::rcp(new Teuchos::ParameterList);
262 nl_params->set("Nonlinear Solver", "Anderson Accelerated Fixed-Point");
263 nl_params->sublist("Anderson Parameters").set("Storage Depth", 3); // should normally get error
264 nl_params->sublist("Anderson Parameters").set("Disable Checks for Unit Testing", true); // should normally get error
265 nl_params->sublist("Anderson Parameters").set("Mixing Parameter", 1.0);
266 nl_params->sublist("Anderson Parameters").set("Acceleration Start Iteration", 1);
267 nl_params->sublist("Anderson Parameters").set("Adjust Matrix for Condition Number", true);
268 nl_params->sublist("Anderson Parameters").sublist("Preconditioning").set("Precondition", false);
269
270 Teuchos::ParameterList& printParams = nl_params->sublist("Printing");
271 printParams.set("Output Information",
272 NOX::Utils::OuterIteration +
273 NOX::Utils::OuterIterationStatusTest +
274 NOX::Utils::InnerIteration +
275 NOX::Utils::LinearSolverDetails +
276 NOX::Utils::Parameters +
277 NOX::Utils::Details +
278 NOX::Utils::Warning +
279 NOX::Utils::Debug +
280 NOX::Utils::TestDetails +
281 NOX::Utils::Error);
282
283 nl_params->sublist("Solver Options").set("Status Test Check Type", "Complete");
284
285 // Enable row sum scaling
286 nl_params->sublist("Thyra Group Options").set("Function Scaling", "Row Sum");
287
288 // Create Status Tests
289 {
290 Teuchos::ParameterList& st = nl_params->sublist("Status Tests");
291 st.set("Test Type", "Combo");
292 st.set("Combo Type", "OR");
293 st.set("Number of Tests", 3);
294
295 {
296 Teuchos::ParameterList& conv = st.sublist("Test 0");
297 conv.set("Test Type", "Combo");
298 conv.set("Combo Type", "AND");
299 conv.set("Number of Tests", 2);
300
301 Teuchos::ParameterList& normF_rel = conv.sublist("Test 0");
302 normF_rel.set("Test Type", "NormF");
303 normF_rel.set("Tolerance", 1.0e-8);
304
305 Teuchos::ParameterList& normWRMS = conv.sublist("Test 1");
306 normWRMS.set("Test Type", "NormWRMS");
307 normWRMS.set("Absolute Tolerance", 1.0e-8);
308 normWRMS.set("Relative Tolerance", 1.0e-5);
309 normWRMS.set("Tolerance", 1.0);
310 normWRMS.set("BDF Multiplier", 1.0);
311 normWRMS.set("Alpha", 1.0);
312 normWRMS.set("Beta", 0.5);
313 normWRMS.set("Disable Implicit Weighting", true);
314 }
315
316 {
317 Teuchos::ParameterList& fv = st.sublist("Test 1");
318 fv.set("Test Type", "FiniteValue");
319 fv.set("Vector Type", "F Vector");
320 fv.set("Norm Type", "Two Norm");
321 }
322
323 {
324 Teuchos::ParameterList& maxiters = st.sublist("Test 2");
325 maxiters.set("Test Type", "MaxIters");
326 maxiters.set("Maximum Iterations", 100);
327 }
328
329 }
330
331 // Create a Thyra nonlinear solver
332 Teuchos::RCP< ::Thyra::NonlinearSolverBase<double> > solver =
333 Teuchos::rcp(new ::Thyra::NOXNonlinearSolver);
334
335 solver->setParameterList(nl_params);
336 solver->setModel(thyraModel);
337
338 Teuchos::RCP< ::Thyra::VectorBase<double> >
339 initial_guess = thyraModel->getNominalValues().get_x()->clone_v();
340
341 ::Thyra::SolveCriteria<double> solve_criteria;
342 ::Thyra::SolveStatus<double> solve_status;
343
344 solve_status = solver->solve(initial_guess.get(), &solve_criteria);
345
346
347 Teuchos::RCP< ::Thyra::NOXNonlinearSolver> thyra_nox_solver =
348 Teuchos::rcp_dynamic_cast< ::Thyra::NOXNonlinearSolver>(solver);
349 TEST_EQUALITY(thyra_nox_solver->getNOXSolver()->getNumIterations(), 6);
350
351 Teuchos::RCP<const Epetra_Vector> x_analytic = thyraModel->get_analytic_solution();
352
353 Teuchos::RCP<const NOX::Abstract::Vector> x = thyra_nox_solver->getNOXSolver()->getSolutionGroup().getXPtr();
354
355 Teuchos::RCP<const NOX::Thyra::Vector> nox_thyra_x =
356 Teuchos::rcp_dynamic_cast<const NOX::Thyra::Vector>(x,true);
357
358 Teuchos::RCP<const Thyra::SpmdVectorBase<double> > spmd_x =
359 Teuchos::rcp_dynamic_cast<const Thyra::SpmdVectorBase<double> >(nox_thyra_x->getThyraRCPVector(),true);
360
361 Teuchos::ArrayRCP<const double> local_values;
362 spmd_x->getLocalData(outArg(local_values));
363
364 double tol = 1.0e-7;
365 TEST_FLOATING_EQUALITY((*x_analytic)[0],local_values[0],tol);
366 TEST_FLOATING_EQUALITY((*x_analytic)[1],local_values[1],tol);
367
368 if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_CONVERGED)
369 std::cout << "Test passed!" << std::endl;
370
371 // std::cout << *p << std::endl;
372
373 Teuchos::TimeMonitor::summarize();
374
375 // Final return value (0 = successfull, non-zero = failure)
376 TEST_ASSERT(status == 0);
377 }
378
379 TEUCHOS_UNIT_TEST(AndersonAcceleration, AA_Rosenbrock_LineSearch)
380 {
381 int status = 0;
382
383 // Create a communicator for Epetra objects
384 #ifdef HAVE_MPI
385 Epetra_MpiComm Comm( MPI_COMM_WORLD );
386 #else
387 Epetra_SerialComm Comm;
388 #endif
389
390 TEST_ASSERT(Comm.NumProc() == 1);
391
392 ::Stratimikos::DefaultLinearSolverBuilder builder;
393
394 Teuchos::RCP<Teuchos::ParameterList> p =
395 Teuchos::rcp(new Teuchos::ParameterList);
396 {
397 p->set("Linear Solver Type", "AztecOO");
398 //p->set("Preconditioner Type", "Ifpack");
399 p->set("Preconditioner Type", "None");
400 Teuchos::ParameterList& az = p->sublist("Linear Solver Types").sublist("AztecOO");
401 az.sublist("Forward Solve").sublist("AztecOO Settings").set("Output Frequency", 1);
402 az.sublist("VerboseObject").set("Verbosity Level", "high");
403 Teuchos::ParameterList& ip = p->sublist("Preconditioner Types").sublist("Ifpack");
404 ip.sublist("VerboseObject").set("Verbosity Level", "high");
405 }
406
407 builder.setParameterList(p);
408
409 Teuchos::RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
410 lowsFactory = builder.createLinearSolveStrategy("");
411
412 Teuchos::RCP<RosenbrockModelEvaluator> thyraModel =
413 Teuchos::rcp(new RosenbrockModelEvaluator(Teuchos::rcp(&Comm,false)));
414
415 thyraModel->set_W_factory(lowsFactory);
416
417 // Create nox parameter list
418 Teuchos::RCP<Teuchos::ParameterList> nl_params =
419 Teuchos::rcp(new Teuchos::ParameterList);
420 nl_params->set("Nonlinear Solver", "Anderson Accelerated Fixed-Point");
421 nl_params->sublist("Anderson Parameters").set("Storage Depth", 2);
422 nl_params->sublist("Anderson Parameters").set("Mixing Parameter", 1.0);
423 nl_params->sublist("Anderson Parameters").set("Acceleration Start Iteration", 1);
424 nl_params->sublist("Anderson Parameters").set("Adjust Matrix for Condition Number", false);
425 nl_params->sublist("Anderson Parameters").sublist("Preconditioning").set("Precondition", false);
426 nl_params->sublist("Line Search").set("Method", "Safeguarded Step");
427 Teuchos::RCP< ::Thyra::VectorBase<double> > updateLimits = ::Thyra::createMember<double>(thyraModel->get_x_space());
428 ::Thyra::put_scalar(Teuchos::ScalarTraits<double>::rmax(),updateLimits.ptr());
429 ::Thyra::set_ele(0,2.0,updateLimits.ptr());
430 ::Thyra::set_ele(1,2.0,updateLimits.ptr());
431 Teuchos::RCP<NOX::Abstract::Vector> noxUpdateLimits = Teuchos::rcp(new NOX::Thyra::Vector(updateLimits));
432 nl_params->sublist("Line Search").sublist("Safeguarded Step").set("Update Limit Vector",noxUpdateLimits);
433
434 Teuchos::ParameterList& printParams = nl_params->sublist("Printing");
435 printParams.set("Output Information",
436 NOX::Utils::OuterIteration +
437 NOX::Utils::OuterIterationStatusTest +
438 NOX::Utils::InnerIteration +
439 NOX::Utils::LinearSolverDetails +
440 NOX::Utils::Parameters +
441 NOX::Utils::Details +
442 NOX::Utils::Warning +
443 NOX::Utils::Debug +
444 NOX::Utils::TestDetails +
445 NOX::Utils::Error);
446
447 nl_params->sublist("Solver Options").set("Status Test Check Type", "Complete");
448
449 // Enable row sum scaling
450 nl_params->sublist("Thyra Group Options").set("Function Scaling", "Row Sum");
451
452 Teuchos::RCP<NOX::Abstract::PrePostOperator> observer;
453 {
454 NOX::Utils utils(printParams);
455 observer = Teuchos::rcp(new ObserverPrintTest(utils));
456 nl_params->sublist("Solver Options").set("User Defined Pre/Post Operator",observer);
457 }
458
459 // Create Status Tests
460 {
461 Teuchos::ParameterList& st = nl_params->sublist("Status Tests");
462 st.set("Test Type", "Combo");
463 st.set("Combo Type", "OR");
464 st.set("Number of Tests", 3);
465
466 {
467 Teuchos::ParameterList& conv = st.sublist("Test 0");
468 conv.set("Test Type", "Combo");
469 conv.set("Combo Type", "AND");
470 conv.set("Number of Tests", 2);
471
472 Teuchos::ParameterList& normF_rel = conv.sublist("Test 0");
473 normF_rel.set("Test Type", "NormF");
474 normF_rel.set("Tolerance", 1.0e-8);
475
476 Teuchos::ParameterList& normWRMS = conv.sublist("Test 1");
477 normWRMS.set("Test Type", "NormWRMS");
478 normWRMS.set("Absolute Tolerance", 1.0e-8);
479 normWRMS.set("Relative Tolerance", 1.0e-5);
480 normWRMS.set("Tolerance", 1.0);
481 normWRMS.set("BDF Multiplier", 1.0);
482 normWRMS.set("Alpha", 1.0);
483 normWRMS.set("Beta", 0.5);
484 normWRMS.set("Disable Implicit Weighting", true);
485 }
486
487 {
488 Teuchos::ParameterList& fv = st.sublist("Test 1");
489 fv.set("Test Type", "FiniteValue");
490 fv.set("Vector Type", "F Vector");
491 fv.set("Norm Type", "Two Norm");
492 }
493
494 {
495 Teuchos::ParameterList& maxiters = st.sublist("Test 2");
496 maxiters.set("Test Type", "MaxIters");
497 maxiters.set("Maximum Iterations", 100);
498 }
499
500 }
501
502 // Create a Thyra nonlinear solver
503 Teuchos::RCP< ::Thyra::NonlinearSolverBase<double> > solver =
504 Teuchos::rcp(new ::Thyra::NOXNonlinearSolver);
505
506 solver->setParameterList(nl_params);
507 solver->setModel(thyraModel);
508
509 Teuchos::RCP< ::Thyra::VectorBase<double> >
510 initial_guess = thyraModel->getNominalValues().get_x()->clone_v();
511
512 ::Thyra::SolveCriteria<double> solve_criteria;
513 ::Thyra::SolveStatus<double> solve_status;
514
515 solve_status = solver->solve(initial_guess.get(), &solve_criteria);
516
517
518 Teuchos::RCP< ::Thyra::NOXNonlinearSolver> thyra_nox_solver =
519 Teuchos::rcp_dynamic_cast< ::Thyra::NOXNonlinearSolver>(solver);
520 TEST_EQUALITY(thyra_nox_solver->getNOXSolver()->getNumIterations(), 9);
521
522 Teuchos::RCP<const Epetra_Vector> x_analytic = thyraModel->get_analytic_solution();
523
524 Teuchos::RCP<const NOX::Abstract::Vector> x = thyra_nox_solver->getNOXSolver()->getSolutionGroup().getXPtr();
525
526 Teuchos::RCP<const NOX::Thyra::Vector> nox_thyra_x =
527 Teuchos::rcp_dynamic_cast<const NOX::Thyra::Vector>(x,true);
528
529 Teuchos::RCP<const Thyra::SpmdVectorBase<double> > spmd_x =
530 Teuchos::rcp_dynamic_cast<const Thyra::SpmdVectorBase<double> >(nox_thyra_x->getThyraRCPVector(),true);
531
532 Teuchos::ArrayRCP<const double> local_values;
533 spmd_x->getLocalData(outArg(local_values));
534
535 double tol = 1.0e-7;
536 TEST_FLOATING_EQUALITY((*x_analytic)[0],local_values[0],tol);
537 TEST_FLOATING_EQUALITY((*x_analytic)[1],local_values[1],tol);
538
539 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPreIterateCalls(),9);
540 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPostIterateCalls(),9);
541 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPreSolveCalls(),1);
542 TEST_EQUALITY(Teuchos::rcp_dynamic_cast<ObserverPrintTest>(observer)->getNumPostSolveCalls(),1);
543
544 if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_CONVERGED)
545 std::cout << "Test passed!" << std::endl;
546
547 // std::cout << *p << std::endl;
548
549 Teuchos::TimeMonitor::summarize();
550
551 // Final return value (0 = successfull, non-zero = failure)
552 TEST_ASSERT(status == 0);
553 }