Debian Codegraph @

packages/nox/test/epetra/Thyra/Thyra_PseudoTransient.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 "Thyra_SpmdVectorBase.hpp"
40 #include "Thyra_DefaultSpmdVectorSpace.hpp"
41
42 #include "NOX_PrePostOperator_RowSumScaling.H"
43 #include "Thyra_VectorBase.hpp"
44
45 using namespace std;
46
47 TEUCHOS_UNIT_TEST(dimension, default)
48 {
49 int status = 0;
50
51 // Create a communicator for Epetra objects
52 #ifdef HAVE_MPI
53 Epetra_MpiComm Comm( MPI_COMM_WORLD );
54 #else
55 Epetra_SerialComm Comm;
56 #endif
57
58 TEST_ASSERT(Comm.NumProc() == 1);
59
60 ::Stratimikos::DefaultLinearSolverBuilder builder;
61
62 Teuchos::RCP<Teuchos::ParameterList> p =
63 Teuchos::rcp(new Teuchos::ParameterList);
64 {
65 p->set("Linear Solver Type", "AztecOO");
66 //p->set("Preconditioner Type", "Ifpack");
67 p->set("Preconditioner Type", "None");
68 Teuchos::ParameterList& az = p->sublist("Linear Solver Types").sublist("AztecOO");
69 az.sublist("Forward Solve").sublist("AztecOO Settings").set("Output Frequency", 1);
70 az.sublist("VerboseObject").set("Verbosity Level", "high");
71 Teuchos::ParameterList& ip = p->sublist("Preconditioner Types").sublist("Ifpack");
72 ip.sublist("VerboseObject").set("Verbosity Level", "high");
73 }
74
75 builder.setParameterList(p);
76
77 Teuchos::RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
78 lowsFactory = builder.createLinearSolveStrategy("");
79
80 Teuchos::RCP<RosenbrockModelEvaluator> thyraModel =
81 Teuchos::rcp(new RosenbrockModelEvaluator(Teuchos::rcp(&Comm,false)));
82
83 thyraModel->set_W_factory(lowsFactory);
84
85 // Create nox parameter list
86 Teuchos::RCP<Teuchos::ParameterList> nl_params =
87 Teuchos::rcp(new Teuchos::ParameterList);
88 //nl_params->set("Nonlinear Solver", "Line Search Based");
89 nl_params->set("Nonlinear Solver", "Pseudo-Transient");
90 nl_params->sublist("Pseudo-Transient").set("deltaInit",1.0e-1);
91 nl_params->sublist("Pseudo-Transient").set<int>("Maximum Number of Pseudo-Transient Iterations",10);
92 nl_params->sublist("Line Search").set("Method", "Full Step");
93
94 Teuchos::ParameterList& printParams = nl_params->sublist("Printing");
95 printParams.set("Output Information",
96 NOX::Utils::OuterIteration +
97 NOX::Utils::OuterIterationStatusTest +
98 NOX::Utils::InnerIteration +
99 NOX::Utils::LinearSolverDetails +
100 NOX::Utils::Parameters +
101 NOX::Utils::Details +
102 NOX::Utils::Warning +
103 NOX::Utils::Debug +
104 NOX::Utils::TestDetails +
105 NOX::Utils::Error);
106
107 nl_params->sublist("Solver Options").set("Status Test Check Type", "Complete");
108
109 // Enable row sum scaling
110 nl_params->sublist("Thyra Group Options").set("Function Scaling", "Row Sum");
111
112 // Create Status Tests
113 {
114 Teuchos::ParameterList& st = nl_params->sublist("Status Tests");
115 st.set("Test Type", "Combo");
116 st.set("Combo Type", "OR");
117 st.set("Number of Tests", 3);
118
119 {
120 Teuchos::ParameterList& conv = st.sublist("Test 0");
121 conv.set("Test Type", "Combo");
122 conv.set("Combo Type", "AND");
123 conv.set("Number of Tests", 2);
124
125 Teuchos::ParameterList& normF_rel = conv.sublist("Test 0");
126 normF_rel.set("Test Type", "NormF");
127 normF_rel.set("Tolerance", 1.0e-8);
128
129 Teuchos::ParameterList& normWRMS = conv.sublist("Test 1");
130 normWRMS.set("Test Type", "NormWRMS");
131 normWRMS.set("Absolute Tolerance", 1.0e-8);
132 normWRMS.set("Relative Tolerance", 1.0e-5);
133 normWRMS.set("Tolerance", 1.0);
134 normWRMS.set("BDF Multiplier", 1.0);
135 normWRMS.set("Alpha", 1.0);
136 normWRMS.set("Beta", 0.5);
137 normWRMS.set("Disable Implicit Weighting", true);
138 }
139
140 {
141 Teuchos::ParameterList& fv = st.sublist("Test 1");
142 fv.set("Test Type", "FiniteValue");
143 fv.set("Vector Type", "F Vector");
144 fv.set("Norm Type", "Two Norm");
145 }
146
147 {
148 Teuchos::ParameterList& maxiters = st.sublist("Test 2");
149 maxiters.set("Test Type", "MaxIters");
150 maxiters.set("Maximum Iterations", 20);
151 }
152
153 }
154
155 // Create a Thyra nonlinear solver
156 Teuchos::RCP< ::Thyra::NonlinearSolverBase<double> > solver =
157 Teuchos::rcp(new ::Thyra::NOXNonlinearSolver);
158
159 solver->setParameterList(nl_params);
160 solver->setModel(thyraModel);
161
162 Teuchos::RCP< ::Thyra::VectorBase<double> >
163 initial_guess = thyraModel->getNominalValues().get_x()->clone_v();
164
165 ::Thyra::SolveCriteria<double> solve_criteria;
166 ::Thyra::SolveStatus<double> solve_status;
167
168 solve_status = solver->solve(initial_guess.get(), &solve_criteria);
169
170
171 Teuchos::RCP< ::Thyra::NOXNonlinearSolver> thyra_nox_solver =
172 Teuchos::rcp_dynamic_cast< ::Thyra::NOXNonlinearSolver>(solver);
173 TEST_EQUALITY(thyra_nox_solver->getNOXSolver()->getNumIterations(), 13);
174
175 Teuchos::RCP<const Epetra_Vector> x_analytic = thyraModel->get_analytic_solution();
176
177 Teuchos::RCP<const NOX::Abstract::Vector> x = thyra_nox_solver->getNOXSolver()->getSolutionGroup().getXPtr();
178
179 Teuchos::RCP<const NOX::Thyra::Vector> nox_thyra_x =
180 Teuchos::rcp_dynamic_cast<const NOX::Thyra::Vector>(x,true);
181
182 Teuchos::RCP<const Thyra::SpmdVectorBase<double> > spmd_x =
183 Teuchos::rcp_dynamic_cast<const Thyra::SpmdVectorBase<double> >(nox_thyra_x->getThyraRCPVector(),true);
184
185 Teuchos::ArrayRCP<const double> local_values;
186 spmd_x->getLocalData(outArg(local_values));
187
188 double tol = 1.0e-8;
189 TEST_FLOATING_EQUALITY((*x_analytic)[0],local_values[0],tol);
190 TEST_FLOATING_EQUALITY((*x_analytic)[1],local_values[1],tol);
191
192 if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_CONVERGED)
193 std::cout << "Test passed!" << std::endl;
194
195 // std::cout << *p << std::endl;
196
197 Teuchos::TimeMonitor::summarize();
198
199 // Final return value (0 = successfull, non-zero = failure)
200 TEST_ASSERT(status == 0);
201 }