| 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 |
#include "Teuchos_ConfigDefs.hpp" |
| 10 |
#include "Teuchos_UnitTestHarness.hpp" |
| 11 |
|
| 12 |
// NOX Objects |
| 13 |
#include "NOX.H" |
| 14 |
#include "NOX_Thyra.H" |
| 15 |
|
| 16 |
// Trilinos Objects |
| 17 |
#include "Teuchos_Comm.hpp" |
| 18 |
#include "Teuchos_ParameterList.hpp" |
| 19 |
#include "Teuchos_RCP.hpp" |
| 20 |
#include "Teuchos_FancyOStream.hpp" |
| 21 |
|
| 22 |
#include "Tpetra_Core.hpp" |
| 23 |
#include "Tpetra_Vector.hpp" |
| 24 |
|
| 25 |
#include "BelosTypes.hpp" |
| 26 |
#include "Stratimikos_DefaultLinearSolverBuilder.hpp" |
| 27 |
#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp" |
| 28 |
#include "ME_Tpetra_Heq.hpp" |
| 29 |
|
| 30 |
#include "NOX_Thyra_MatrixFreeJacobianOperator.hpp" |
| 31 |
#include "NOX_MatrixFree_ModelEvaluatorDecorator.hpp" |
| 32 |
#include "NOX_Observer_Print.hpp" |
| 33 |
|
| 34 |
#if defined HAVE_TPETRACORE_CUDA |
| 35 |
#define NUM_ELEMENTS 10000 |
| 36 |
#else |
| 37 |
#define NUM_ELEMENTS 100 |
| 38 |
#endif |
| 39 |
|
| 40 |
TEUCHOS_UNIT_TEST(NOX_Tpetra_Heq, AnalyticJacobian_NoPrec) |
| 41 |
{ |
| 42 |
Teuchos::TimeMonitor::zeroOutTimers(); |
| 43 |
|
| 44 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm(); |
| 45 |
|
| 46 |
// Get default Tpetra template types |
| 47 |
typedef Tpetra::Vector<>::scalar_type Scalar; |
| 48 |
typedef Tpetra::Vector<>::local_ordinal_type LO; |
| 49 |
typedef Tpetra::Vector<>::global_ordinal_type GO; |
| 50 |
typedef Tpetra::Vector<>::node_type Node; |
| 51 |
|
| 52 |
// Create the model evaluator object |
| 53 |
Scalar omega = 0.95; |
| 54 |
const Tpetra::global_size_t numGlobalElements = NUM_ELEMENTS; |
| 55 |
Teuchos::RCP<EvaluatorTpetraHeq<Scalar,LO,GO,Node> > model = |
| 56 |
evaluatorTpetraHeq<Scalar,LO,GO,Node>(comm, numGlobalElements, omega); |
| 57 |
|
| 58 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 59 |
|
| 60 |
Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::parameterList(); |
| 61 |
p->set("Linear Solver Type", "Belos"); |
| 62 |
Teuchos::ParameterList& belosList = p->sublist("Linear Solver Types").sublist("Belos"); |
| 63 |
belosList.set("Solver Type", "Pseudo Block GMRES"); |
| 64 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Iterations", numGlobalElements); |
| 65 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Num Blocks", 200); |
| 66 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Restarts", numGlobalElements); |
| 67 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Verbosity", 0x7f); |
| 68 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Output Frequency", 100); |
| 69 |
belosList.sublist("VerboseObject").set("Verbosity Level", "medium"); |
| 70 |
p->set("Preconditioner Type", "None"); |
| 71 |
builder.setParameterList(p); |
| 72 |
|
| 73 |
Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > |
| 74 |
lowsFactory = builder.createLinearSolveStrategy(""); |
| 75 |
|
| 76 |
model->set_W_factory(lowsFactory); |
| 77 |
|
| 78 |
// Create the initial guess |
| 79 |
Teuchos::RCP<Thyra::VectorBase<Scalar> > |
| 80 |
initial_guess = model->getNominalValues().get_x()->clone_v(); |
| 81 |
|
| 82 |
Thyra::V_S(initial_guess.ptr(),Teuchos::ScalarTraits<Scalar>::one()); |
| 83 |
|
| 84 |
Teuchos::RCP<NOX::Thyra::Group> nox_group = |
| 85 |
Teuchos::rcp(new NOX::Thyra::Group(*initial_guess, model, model->create_W_op(), lowsFactory, Teuchos::null, Teuchos::null, Teuchos::null)); |
| 86 |
|
| 87 |
nox_group->computeF(); |
| 88 |
|
| 89 |
// Create the NOX status tests and the solver |
| 90 |
// Create the convergence tests |
| 91 |
Teuchos::RCP<NOX::StatusTest::NormF> absresid = |
| 92 |
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8)); |
| 93 |
Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms = |
| 94 |
Teuchos::rcp(new NOX::StatusTest::NormWRMS(1.0e-2, 1.0e-8)); |
| 95 |
Teuchos::RCP<NOX::StatusTest::Combo> converged = |
| 96 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND)); |
| 97 |
converged->addStatusTest(absresid); |
| 98 |
converged->addStatusTest(wrms); |
| 99 |
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters = |
| 100 |
Teuchos::rcp(new NOX::StatusTest::MaxIters(20)); |
| 101 |
Teuchos::RCP<NOX::StatusTest::FiniteValue> fv = |
| 102 |
Teuchos::rcp(new NOX::StatusTest::FiniteValue); |
| 103 |
Teuchos::RCP<NOX::StatusTest::Combo> combo = |
| 104 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR)); |
| 105 |
combo->addStatusTest(fv); |
| 106 |
combo->addStatusTest(converged); |
| 107 |
combo->addStatusTest(maxiters); |
| 108 |
|
| 109 |
// Create nox parameter list |
| 110 |
Teuchos::RCP<Teuchos::ParameterList> nl_params = Teuchos::parameterList(); |
| 111 |
nl_params->set("Nonlinear Solver", "Line Search Based"); |
| 112 |
nl_params->sublist("Direction").sublist("Newton").sublist("Linear Solver").set("Tolerance", 1.0e-4); |
| 113 |
|
| 114 |
// Set output parameters |
| 115 |
nl_params->sublist("Printing").sublist("Output Information").set("Debug",true); |
| 116 |
nl_params->sublist("Printing").sublist("Output Information").set("Warning",true); |
| 117 |
nl_params->sublist("Printing").sublist("Output Information").set("Error",true); |
| 118 |
nl_params->sublist("Printing").sublist("Output Information").set("Test Details",true); |
| 119 |
nl_params->sublist("Printing").sublist("Output Information").set("Details",true); |
| 120 |
nl_params->sublist("Printing").sublist("Output Information").set("Parameters",true); |
| 121 |
nl_params->sublist("Printing").sublist("Output Information").set("Linear Solver Details",true); |
| 122 |
nl_params->sublist("Printing").sublist("Output Information").set("Inner Iteration",true); |
| 123 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration",true); |
| 124 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration StatusTest",true); |
| 125 |
|
| 126 |
// Create the solver |
| 127 |
Teuchos::RCP<NOX::Solver::Generic> solver = |
| 128 |
NOX::Solver::buildSolver(nox_group, combo, nl_params); |
| 129 |
NOX::StatusTest::StatusType solvStatus = solver->solve(); |
| 130 |
|
| 131 |
TEST_ASSERT(solvStatus == NOX::StatusTest::Converged); |
| 132 |
|
| 133 |
Teuchos::TimeMonitor::summarize(); |
| 134 |
} |
| 135 |
|
| 136 |
TEUCHOS_UNIT_TEST(NOX_Tpetra_Heq, JFNK_NoPrec) |
| 137 |
{ |
| 138 |
Teuchos::TimeMonitor::zeroOutTimers(); |
| 139 |
|
| 140 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm(); |
| 141 |
|
| 142 |
// Get default Tpetra template types |
| 143 |
typedef Tpetra::Vector<>::scalar_type Scalar; |
| 144 |
typedef Tpetra::Vector<>::local_ordinal_type LO; |
| 145 |
typedef Tpetra::Vector<>::global_ordinal_type GO; |
| 146 |
typedef Tpetra::Vector<>::node_type Node; |
| 147 |
|
| 148 |
// Create the model evaluator object |
| 149 |
Scalar omega = 0.9; |
| 150 |
const Tpetra::global_size_t numGlobalElements = NUM_ELEMENTS; |
| 151 |
Teuchos::RCP<EvaluatorTpetraHeq<Scalar,LO,GO,Node> > model = |
| 152 |
evaluatorTpetraHeq<Scalar,LO,GO,Node>(comm, numGlobalElements, omega); |
| 153 |
|
| 154 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 155 |
|
| 156 |
Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::parameterList(); |
| 157 |
p->set("Linear Solver Type", "Belos"); |
| 158 |
Teuchos::ParameterList& belosList = p->sublist("Linear Solver Types").sublist("Belos"); |
| 159 |
belosList.set("Solver Type", "Pseudo Block GMRES"); |
| 160 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Iterations", numGlobalElements); |
| 161 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Num Blocks", 200); |
| 162 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Restarts", numGlobalElements); |
| 163 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Verbosity", 0x7f); |
| 164 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Output Frequency", 100); |
| 165 |
belosList.sublist("VerboseObject").set("Verbosity Level", "medium"); |
| 166 |
p->set("Preconditioner Type", "None"); |
| 167 |
builder.setParameterList(p); |
| 168 |
|
| 169 |
Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > |
| 170 |
lowsFactory = builder.createLinearSolveStrategy(""); |
| 171 |
|
| 172 |
model->set_W_factory(lowsFactory); |
| 173 |
|
| 174 |
// Create the initial guess |
| 175 |
Teuchos::RCP<Thyra::VectorBase<Scalar> > |
| 176 |
initial_guess = model->getNominalValues().get_x()->clone_v(); |
| 177 |
|
| 178 |
Thyra::V_S(initial_guess.ptr(),Teuchos::ScalarTraits<Scalar>::one()); |
| 179 |
|
| 180 |
// Create the JFNK operator |
| 181 |
Teuchos::ParameterList printParams; |
| 182 |
Teuchos::RCP<Teuchos::ParameterList> jfnkParams = Teuchos::parameterList(); |
| 183 |
jfnkParams->set("Difference Type","Forward"); |
| 184 |
jfnkParams->set("Perturbation Algorithm","KSP NOX 2001"); |
| 185 |
jfnkParams->set("lambda",1.0e-4); |
| 186 |
Teuchos::RCP<NOX::Thyra::MatrixFreeJacobianOperator<Scalar> > jfnkOp = |
| 187 |
Teuchos::rcp(new NOX::Thyra::MatrixFreeJacobianOperator<Scalar>(printParams)); |
| 188 |
jfnkOp->setParameterList(jfnkParams); |
| 189 |
jfnkParams->print(out); |
| 190 |
|
| 191 |
// Wrap the model evaluator in a JFNK Model Evaluator |
| 192 |
Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > thyraModel = |
| 193 |
Teuchos::rcp(new NOX::MatrixFreeModelEvaluatorDecorator<Scalar>(model)); |
| 194 |
|
| 195 |
// Create the NOX::Thyra::Group |
| 196 |
Teuchos::RCP<NOX::Thyra::Group> nox_group = |
| 197 |
Teuchos::rcp(new NOX::Thyra::Group(*initial_guess, thyraModel, jfnkOp, lowsFactory, Teuchos::null, Teuchos::null, Teuchos::null)); |
| 198 |
|
| 199 |
nox_group->computeF(); |
| 200 |
|
| 201 |
// VERY IMPORTANT!!! jfnk object needs base evaluation objects. |
| 202 |
// This creates a circular dependency, so use a weak pointer. |
| 203 |
jfnkOp->setBaseEvaluationToNOXGroup(nox_group.create_weak()); |
| 204 |
|
| 205 |
// Create a preconditioner |
| 206 |
|
| 207 |
// Create the NOX status tests and the solver |
| 208 |
// Create the convergence tests |
| 209 |
Teuchos::RCP<NOX::StatusTest::NormF> absresid = |
| 210 |
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8)); |
| 211 |
Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms = |
| 212 |
Teuchos::rcp(new NOX::StatusTest::NormWRMS(1.0e-2, 1.0e-8)); |
| 213 |
Teuchos::RCP<NOX::StatusTest::Combo> converged = |
| 214 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND)); |
| 215 |
converged->addStatusTest(absresid); |
| 216 |
converged->addStatusTest(wrms); |
| 217 |
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters = |
| 218 |
Teuchos::rcp(new NOX::StatusTest::MaxIters(20)); |
| 219 |
Teuchos::RCP<NOX::StatusTest::FiniteValue> fv = |
| 220 |
Teuchos::rcp(new NOX::StatusTest::FiniteValue); |
| 221 |
Teuchos::RCP<NOX::StatusTest::Combo> combo = |
| 222 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR)); |
| 223 |
combo->addStatusTest(fv); |
| 224 |
combo->addStatusTest(converged); |
| 225 |
combo->addStatusTest(maxiters); |
| 226 |
|
| 227 |
// Create nox parameter list |
| 228 |
Teuchos::RCP<Teuchos::ParameterList> nl_params = Teuchos::parameterList(); |
| 229 |
nl_params->set("Nonlinear Solver", "Line Search Based"); |
| 230 |
nl_params->sublist("Direction").sublist("Newton").sublist("Linear Solver").set("Tolerance", 1.0e-4); |
| 231 |
|
| 232 |
// Set output parameters |
| 233 |
nl_params->sublist("Printing").sublist("Output Information").set("Debug",true); |
| 234 |
nl_params->sublist("Printing").sublist("Output Information").set("Warning",true); |
| 235 |
nl_params->sublist("Printing").sublist("Output Information").set("Error",true); |
| 236 |
nl_params->sublist("Printing").sublist("Output Information").set("Test Details",true); |
| 237 |
nl_params->sublist("Printing").sublist("Output Information").set("Details",true); |
| 238 |
nl_params->sublist("Printing").sublist("Output Information").set("Parameters",true); |
| 239 |
nl_params->sublist("Printing").sublist("Output Information").set("Linear Solver Details",true); |
| 240 |
nl_params->sublist("Printing").sublist("Output Information").set("Inner Iteration",true); |
| 241 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration",true); |
| 242 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration StatusTest",true); |
| 243 |
|
| 244 |
// Create the solver |
| 245 |
Teuchos::RCP<NOX::Solver::Generic> solver = |
| 246 |
NOX::Solver::buildSolver(nox_group, combo, nl_params); |
| 247 |
NOX::StatusTest::StatusType solvStatus = solver->solve(); |
| 248 |
|
| 249 |
TEST_ASSERT(solvStatus == NOX::StatusTest::Converged); |
| 250 |
|
| 251 |
Teuchos::TimeMonitor::summarize(); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
TEUCHOS_UNIT_TEST(NOX_Tpetra_Heq, JFNK_UserPrec) |
| 256 |
{ |
| 257 |
Teuchos::TimeMonitor::zeroOutTimers(); |
| 258 |
|
| 259 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm(); |
| 260 |
|
| 261 |
// Get default Tpetra template types |
| 262 |
typedef Tpetra::Vector<>::scalar_type Scalar; |
| 263 |
typedef Tpetra::Vector<>::local_ordinal_type LO; |
| 264 |
typedef Tpetra::Vector<>::global_ordinal_type GO; |
| 265 |
typedef Tpetra::Vector<>::node_type Node; |
| 266 |
|
| 267 |
// Create the model evaluator object |
| 268 |
Scalar omega = 0.9; |
| 269 |
const Tpetra::global_size_t numGlobalElements = NUM_ELEMENTS; |
| 270 |
Teuchos::RCP<EvaluatorTpetraHeq<Scalar,LO,GO,Node> > model = |
| 271 |
evaluatorTpetraHeq<Scalar,LO,GO,Node>(comm, numGlobalElements, omega); |
| 272 |
|
| 273 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 274 |
|
| 275 |
Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::parameterList(); |
| 276 |
p->set("Linear Solver Type", "Belos"); |
| 277 |
Teuchos::ParameterList& belosList = p->sublist("Linear Solver Types").sublist("Belos"); |
| 278 |
belosList.set("Solver Type", "Pseudo Block GMRES"); |
| 279 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Iterations", numGlobalElements); |
| 280 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Num Blocks", 200); |
| 281 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Restarts", numGlobalElements); |
| 282 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Verbosity", 0x7f); |
| 283 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Output Frequency", 100); |
| 284 |
belosList.sublist("VerboseObject").set("Verbosity Level", "medium"); |
| 285 |
p->set("Preconditioner Type", "None"); |
| 286 |
builder.setParameterList(p); |
| 287 |
|
| 288 |
Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > |
| 289 |
lowsFactory = builder.createLinearSolveStrategy(""); |
| 290 |
|
| 291 |
model->set_W_factory(lowsFactory); |
| 292 |
|
| 293 |
// Create the initial guess |
| 294 |
Teuchos::RCP<Thyra::VectorBase<Scalar> > |
| 295 |
initial_guess = model->getNominalValues().get_x()->clone_v(); |
| 296 |
|
| 297 |
Thyra::V_S(initial_guess.ptr(),Teuchos::ScalarTraits<Scalar>::one()); |
| 298 |
|
| 299 |
// Create the JFNK operator |
| 300 |
Teuchos::ParameterList printParams; |
| 301 |
Teuchos::RCP<Teuchos::ParameterList> jfnkParams = Teuchos::parameterList(); |
| 302 |
jfnkParams->set("Difference Type","Forward"); |
| 303 |
jfnkParams->set("Perturbation Algorithm","KSP NOX 2001"); |
| 304 |
jfnkParams->set("lambda",1.0e-4); |
| 305 |
Teuchos::RCP<NOX::Thyra::MatrixFreeJacobianOperator<Scalar> > jfnkOp = |
| 306 |
Teuchos::rcp(new NOX::Thyra::MatrixFreeJacobianOperator<Scalar>(printParams)); |
| 307 |
jfnkOp->setParameterList(jfnkParams); |
| 308 |
jfnkParams->print(out); |
| 309 |
|
| 310 |
// Wrap the model evaluator in a JFNK Model Evaluator |
| 311 |
Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > thyraModel = |
| 312 |
Teuchos::rcp(new NOX::MatrixFreeModelEvaluatorDecorator<Scalar>(model)); |
| 313 |
|
| 314 |
// Create the Preconditioner operator |
| 315 |
Teuchos::RCP<Thyra::PreconditionerBase<Scalar> > precOp = |
| 316 |
thyraModel->create_W_prec(); |
| 317 |
|
| 318 |
// Create the NOX::Thyra::Group |
| 319 |
Teuchos::RCP<NOX::Thyra::Group> nox_group = |
| 320 |
Teuchos::rcp(new NOX::Thyra::Group(*initial_guess, thyraModel, jfnkOp, lowsFactory, precOp, Teuchos::null, Teuchos::null)); |
| 321 |
|
| 322 |
nox_group->computeF(); |
| 323 |
|
| 324 |
// VERY IMPORTANT!!! jfnk object needs base evaluation objects. |
| 325 |
// This creates a circular dependency, so use a weak pointer. |
| 326 |
jfnkOp->setBaseEvaluationToNOXGroup(nox_group.create_weak()); |
| 327 |
|
| 328 |
// Create the NOX status tests and the solver |
| 329 |
// Create the convergence tests |
| 330 |
Teuchos::RCP<NOX::StatusTest::NormF> absresid = |
| 331 |
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8)); |
| 332 |
Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms = |
| 333 |
Teuchos::rcp(new NOX::StatusTest::NormWRMS(1.0e-2, 1.0e-8)); |
| 334 |
Teuchos::RCP<NOX::StatusTest::Combo> converged = |
| 335 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND)); |
| 336 |
converged->addStatusTest(absresid); |
| 337 |
converged->addStatusTest(wrms); |
| 338 |
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters = |
| 339 |
Teuchos::rcp(new NOX::StatusTest::MaxIters(20)); |
| 340 |
Teuchos::RCP<NOX::StatusTest::FiniteValue> fv = |
| 341 |
Teuchos::rcp(new NOX::StatusTest::FiniteValue); |
| 342 |
Teuchos::RCP<NOX::StatusTest::Combo> combo = |
| 343 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR)); |
| 344 |
combo->addStatusTest(fv); |
| 345 |
combo->addStatusTest(converged); |
| 346 |
combo->addStatusTest(maxiters); |
| 347 |
|
| 348 |
// Create nox parameter list |
| 349 |
Teuchos::RCP<Teuchos::ParameterList> nl_params = Teuchos::parameterList(); |
| 350 |
nl_params->set("Nonlinear Solver", "Line Search Based"); |
| 351 |
nl_params->sublist("Direction").sublist("Newton").sublist("Linear Solver").set("Tolerance", 1.0e-4); |
| 352 |
|
| 353 |
// Set output parameters |
| 354 |
nl_params->sublist("Printing").sublist("Output Information").set("Debug",true); |
| 355 |
nl_params->sublist("Printing").sublist("Output Information").set("Warning",true); |
| 356 |
nl_params->sublist("Printing").sublist("Output Information").set("Error",true); |
| 357 |
nl_params->sublist("Printing").sublist("Output Information").set("Test Details",true); |
| 358 |
nl_params->sublist("Printing").sublist("Output Information").set("Details",true); |
| 359 |
nl_params->sublist("Printing").sublist("Output Information").set("Parameters",true); |
| 360 |
nl_params->sublist("Printing").sublist("Output Information").set("Linear Solver Details",true); |
| 361 |
nl_params->sublist("Printing").sublist("Output Information").set("Inner Iteration",true); |
| 362 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration",true); |
| 363 |
nl_params->sublist("Printing").sublist("Output Information").set("Outer Iteration StatusTest",true); |
| 364 |
|
| 365 |
// Create the solver |
| 366 |
Teuchos::RCP<NOX::Solver::Generic> solver = |
| 367 |
NOX::Solver::buildSolver(nox_group, combo, nl_params); |
| 368 |
NOX::StatusTest::StatusType solvStatus = solver->solve(); |
| 369 |
|
| 370 |
TEST_ASSERT(solvStatus == NOX::StatusTest::Converged); |
| 371 |
|
| 372 |
Teuchos::TimeMonitor::summarize(); |
| 373 |
} |
| 374 |
|
| 375 |
TEUCHOS_UNIT_TEST(NOX_Tpetra_Heq, ObserverPrint) |
| 376 |
{ |
| 377 |
Teuchos::TimeMonitor::zeroOutTimers(); |
| 378 |
|
| 379 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm(); |
| 380 |
|
| 381 |
// Get default Tpetra template types |
| 382 |
typedef Tpetra::Vector<>::scalar_type Scalar; |
| 383 |
typedef Tpetra::Vector<>::local_ordinal_type LO; |
| 384 |
typedef Tpetra::Vector<>::global_ordinal_type GO; |
| 385 |
typedef Tpetra::Vector<>::node_type Node; |
| 386 |
|
| 387 |
// Create the model evaluator object |
| 388 |
Scalar omega = 0.95; |
| 389 |
const Tpetra::global_size_t numGlobalElements = NUM_ELEMENTS; |
| 390 |
Teuchos::RCP<EvaluatorTpetraHeq<Scalar,LO,GO,Node> > model = |
| 391 |
evaluatorTpetraHeq<Scalar,LO,GO,Node>(comm, numGlobalElements, omega); |
| 392 |
|
| 393 |
Stratimikos::DefaultLinearSolverBuilder builder; |
| 394 |
|
| 395 |
Teuchos::RCP<Teuchos::ParameterList> p = Teuchos::parameterList(); |
| 396 |
p->set("Linear Solver Type", "Belos"); |
| 397 |
Teuchos::ParameterList& belosList = p->sublist("Linear Solver Types").sublist("Belos"); |
| 398 |
belosList.set("Solver Type", "Pseudo Block GMRES"); |
| 399 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Iterations", numGlobalElements); |
| 400 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Num Blocks", 200); |
| 401 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set<int>("Maximum Restarts", numGlobalElements); |
| 402 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Verbosity", 0); |
| 403 |
belosList.sublist("Solver Types").sublist("Pseudo Block GMRES").set("Output Frequency", 100); |
| 404 |
belosList.sublist("VerboseObject").set("Verbosity Level", "none"); |
| 405 |
p->set("Preconditioner Type", "None"); |
| 406 |
builder.setParameterList(p); |
| 407 |
|
| 408 |
Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > |
| 409 |
lowsFactory = builder.createLinearSolveStrategy(""); |
| 410 |
|
| 411 |
model->set_W_factory(lowsFactory); |
| 412 |
|
| 413 |
// Create the initial guess |
| 414 |
Teuchos::RCP<Thyra::VectorBase<Scalar> > |
| 415 |
initial_guess = model->getNominalValues().get_x()->clone_v(); |
| 416 |
|
| 417 |
Thyra::V_S(initial_guess.ptr(),Teuchos::ScalarTraits<Scalar>::one()); |
| 418 |
|
| 419 |
Teuchos::RCP<NOX::Thyra::Group> nox_group = |
| 420 |
Teuchos::rcp(new NOX::Thyra::Group(*initial_guess, model, model->create_W_op(), lowsFactory, Teuchos::null, Teuchos::null, Teuchos::null)); |
| 421 |
|
| 422 |
nox_group->computeF(); |
| 423 |
|
| 424 |
// Create the NOX status tests and the solver |
| 425 |
// Create the convergence tests |
| 426 |
Teuchos::RCP<NOX::StatusTest::NormF> absresid = |
| 427 |
Teuchos::rcp(new NOX::StatusTest::NormF(1.0e-8)); |
| 428 |
Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms = |
| 429 |
Teuchos::rcp(new NOX::StatusTest::NormWRMS(1.0e-2, 1.0e-8)); |
| 430 |
Teuchos::RCP<NOX::StatusTest::Combo> converged = |
| 431 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND)); |
| 432 |
converged->addStatusTest(absresid); |
| 433 |
converged->addStatusTest(wrms); |
| 434 |
Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters = |
| 435 |
Teuchos::rcp(new NOX::StatusTest::MaxIters(20)); |
| 436 |
Teuchos::RCP<NOX::StatusTest::FiniteValue> fv = |
| 437 |
Teuchos::rcp(new NOX::StatusTest::FiniteValue); |
| 438 |
Teuchos::RCP<NOX::StatusTest::Combo> combo = |
| 439 |
Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR)); |
| 440 |
combo->addStatusTest(fv); |
| 441 |
combo->addStatusTest(converged); |
| 442 |
combo->addStatusTest(maxiters); |
| 443 |
|
| 444 |
// Create nox parameter list |
| 445 |
Teuchos::RCP<Teuchos::ParameterList> nl_params = Teuchos::parameterList(); |
| 446 |
nl_params->set("Nonlinear Solver", "Line Search Based"); |
| 447 |
nl_params->sublist("Direction").sublist("Newton").sublist("Linear Solver").set("Tolerance", 1.0e-4); |
| 448 |
|
| 449 |
// Register Print Observer (and disable normal printing) |
| 450 |
nl_params->sublist("Printing").set("Output Information",NOX::Utils::Error); |
| 451 |
Teuchos::RCP<NOX::Utils> os = Teuchos::rcp(new NOX::Utils(nl_params->sublist("Printing"))); |
| 452 |
Teuchos::RCP<NOX::Observer> printObserver = Teuchos::rcp(new NOX::ObserverPrint(os)); |
| 453 |
nl_params->sublist("Solver Options").set("Observer",printObserver); |
| 454 |
|
| 455 |
os->out() << "\n\nStarting Nonlinear Solve:\n\n"; |
| 456 |
|
| 457 |
// Create the solver |
| 458 |
Teuchos::RCP<NOX::Solver::Generic> solver = |
| 459 |
NOX::Solver::buildSolver(nox_group, combo, nl_params); |
| 460 |
NOX::StatusTest::StatusType solvStatus = solver->solve(); |
| 461 |
|
| 462 |
os->out() << "\n"; |
| 463 |
|
| 464 |
TEST_ASSERT(solvStatus == NOX::StatusTest::Converged); |
| 465 |
|
| 466 |
Teuchos::TimeMonitor::summarize(); |
| 467 |
} |