1#ifndef NONLINEARSOLVER_DEF_hpp
2#define NONLINEARSOLVER_DEF_hpp
16template<
class SC,
class LO,
class GO,
class NO>
17NonLinearSolver<SC,LO,GO,NO>::NonLinearSolver():
22template<
class SC,
class LO,
class GO,
class NO>
23NonLinearSolver<SC,LO,GO,NO>::NonLinearSolver(std::string type):
27template<
class SC,
class LO,
class GO,
class NO>
28NonLinearSolver<SC,LO,GO,NO>::~NonLinearSolver(){
32template<
class SC,
class LO,
class GO,
class NO>
35 if (!type_.compare(
"FixedPoint")) {
36 solveFixedPoint(problem,valuesForExport);
38 else if(!type_.compare(
"Newton")){
39 solveNewton(problem,valuesForExport);
41 else if(!type_.compare(
"FixedPointNewton")){
42 solveFixedPointNewton(problem, valuesForExport);
44 else if(!type_.compare(
"NOX")){
46 solveNOX(problem,valuesForExport);
52template<
class SC,
class LO,
class GO,
class NO>
55 if (!type_.compare(
"FixedPoint")) {
56 solveFixedPoint(problem,time);
58 else if(!type_.compare(
"Newton")){
59 solveNewton(problem,time, valuesForExport);
61 else if(!type_.compare(
"NOX")){
63 solveNOX(problem, valuesForExport);
66 else if(!type_.compare(
"Extrapolation")){
67 solveExtrapolation(problem, time);
72template<
class SC,
class LO,
class GO,
class NO>
75 bool verbose = problem.getVerbose();
76 Teuchos::RCP<NonLinearProblem<SC,LO,GO,NO> > problemPtr = Teuchos::rcpFromRef(problem);
77 Teuchos::RCP<Teuchos::ParameterList> p = sublist(problemPtr->getParameterList(),
"ThyraSolver");
80 problemPtr->getLinearSolverBuilder()->setParameterList(p);
82 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problemPtr->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
87 Teuchos::RCP<Thyra::VectorBase<SC> > initial_guess = problemPtr->getNominalValues().get_x()->clone_v();
88 Thyra::V_S(initial_guess.ptr(),Teuchos::ScalarTraits<SC>::zero());
90 Teuchos::RCP<Thyra::LinearOpBase<SC> > W_op = problemPtr->create_W_op();
91 Teuchos::RCP<Thyra::PreconditionerBase<SC> > W_prec = problemPtr->create_W_prec();
97 Teuchos::RCP<NOX::Thyra::Group> nox_group(
new NOX::Thyra::Group(initial_guess,
98 problemPtr.getConst(),
100 lowsFactory.getConst(),
106 nox_group->computeF();
111 Teuchos::RCP<NOX::StatusTest::NormUpdate> updateTol =
112 Teuchos::rcp(
new NOX::StatusTest::NormUpdate( problemPtr->getParameterList()->sublist(
"Parameter").get(
"updateTol",1.0e-6) ) );
114 Teuchos::RCP<NOX::StatusTest::RelativeNormF> relresid =
115 Teuchos::rcp(
new NOX::StatusTest::RelativeNormF( problemPtr->getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-4) ) );
117 Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms =
118 Teuchos::rcp(
new NOX::StatusTest::NormWRMS(problemPtr->getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-4), problemPtr->getParameterList()->sublist(
"Parameter").get(
"absNonLinTol",1.0e-6)));
120 Teuchos::RCP<NOX::StatusTest::NormF> absRes =
121 Teuchos::rcp(
new NOX::StatusTest::NormF( problemPtr->getParameterList()->sublist(
"Parameter").get(
"absNonLinTol",1.0e-6) ) );
123 Teuchos::RCP<NOX::StatusTest::Combo> converged;
125 if ( !problemPtr->getParameterList()->sublist(
"Parameter").get(
"Combo",
"AND").compare(
"AND") )
126 converged = Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND));
127 else if (!problemPtr->getParameterList()->sublist(
"Parameter").get(
"Combo",
"AND").compare(
"OR") )
128 converged = Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
130 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use rel tol",
true) )
131 converged->addStatusTest(relresid);
132 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use update tol",
false) )
133 converged->addStatusTest(updateTol);
134 if (problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use WRMS",
false))
135 converged->addStatusTest(wrms);
136 if (problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use abs tol",
false))
137 converged->addStatusTest(absRes);
139 Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters =
140 Teuchos::rcp(
new NOX::StatusTest::MaxIters(problemPtr->getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10)));
141 Teuchos::RCP<NOX::StatusTest::FiniteValue> fv =
142 Teuchos::rcp(
new NOX::StatusTest::FiniteValue);
143 Teuchos::RCP<NOX::StatusTest::Combo> combo =
144 Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
145 combo->addStatusTest(fv);
146 combo->addStatusTest(converged);
147 combo->addStatusTest(maxiters);
150 Teuchos::RCP<Teuchos::ParameterList> nl_params = sublist(problemPtr->getParameterList(),
"NOXSolver");
153 Teuchos::RCP<NOX::Solver::Generic> solver = NOX::Solver::buildSolver(nox_group, combo, nl_params);
154 NOX::StatusTest::StatusType solveStatus = solver->solve();
155 double nonLinearIts = solver->getSolverStatistics()->linearSolve.allNonlinearSolves_NumLinearSolves;
156 double linearIts = solver->getSolverStatistics()->linearSolve.allNonlinearSolves_NumLinearIterations;
158 linearIts/=nonLinearIts;
160 std::cout <<
"############################################################" << std::endl;
161 std::cout <<
"### Total nonlinear iterations : " << nonLinearIts <<
" with an average of " << linearIts <<
" linear iterations ###" << std::endl;
162 std::cout <<
"############################################################" << std::endl;
165 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
166 TEUCHOS_TEST_FOR_EXCEPTION((
int)nonLinearIts == problemPtr->getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10) ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
168 nonLinearIts_ = nonLinearIts;
172template<
class SC,
class LO,
class GO,
class NO>
175 bool verbose = problem.getVerbose();
176 Teuchos::RCP<TimeProblem_Type> problemPtr = Teuchos::rcpFromRef(problem);
177 Teuchos::RCP<Teuchos::ParameterList> p = sublist(problemPtr->getParameterList(),
"ThyraSolver");
179 problemPtr->getLinearSolverBuilder()->setParameterList(p);
181 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> >
182 lowsFactory = problemPtr->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
184 TEUCHOS_TEST_FOR_EXCEPTION(problemPtr->getSolution()->getNumVectors()>1, std::runtime_error,
"With the current implementation NOX can only be used with 1 MultiVector column.");
186 Teuchos::RCP<Thyra::VectorBase<SC> > initialGuess = problemPtr->getNominalValues().get_x()->clone_v();
188 Teuchos::RCP<Thyra::ProductVectorBase<SC> > initialGuessProd = Teuchos::rcp_dynamic_cast<Thyra::ProductVectorBase<SC> >(initialGuess);
189 Teuchos::RCP<Thyra::MultiVectorBase<SC> > solMV;
190 if (!initialGuessProd.is_null())
191 solMV = problemPtr->getSolution()->getProdThyraMultiVector();
193 solMV = problemPtr->getSolution()->getThyraMultiVector();
195 Thyra::assign(initialGuess.ptr(), *solMV->col(0));
197 Teuchos::RCP<Thyra::LinearOpBase<SC> > W_op = problemPtr->create_W_op();
198 Teuchos::RCP<Thyra::PreconditionerBase<SC> > W_prec = problemPtr->create_W_prec();
201 Teuchos::RCP<NOX::Thyra::Group> nox_group(
new NOX::Thyra::Group(initialGuess,
202 problemPtr.getConst(),
204 lowsFactory.getConst(),
210 nox_group->computeF();
214 Teuchos::RCP<NOX::StatusTest::NormUpdate> updateTol =
215 Teuchos::rcp(
new NOX::StatusTest::NormUpdate( problemPtr->getParameterList()->sublist(
"Parameter").get(
"updateTol",1.0e-6) ) );
217 Teuchos::RCP<NOX::StatusTest::RelativeNormF> relresid =
218 Teuchos::rcp(
new NOX::StatusTest::RelativeNormF( problemPtr->getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-4) ) );
220 Teuchos::RCP<NOX::StatusTest::NormWRMS> wrms =
221 Teuchos::rcp(
new NOX::StatusTest::NormWRMS(problemPtr->getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-4), problemPtr->getParameterList()->sublist(
"Parameter").get(
"absNonLinTol",1.0e-6)));
223 Teuchos::RCP<NOX::StatusTest::NormF> absRes =
224 Teuchos::rcp(
new NOX::StatusTest::NormF( problemPtr->getParameterList()->sublist(
"Parameter").get(
"absNonLinTol",1.0e-6) ) );
226 Teuchos::RCP<NOX::StatusTest::Combo> converged;
228 if ( !problemPtr->getParameterList()->sublist(
"Parameter").get(
"Combo",
"AND").compare(
"AND") )
229 converged = Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::AND));
230 else if (!problemPtr->getParameterList()->sublist(
"Parameter").get(
"Combo",
"AND").compare(
"OR") )
231 converged = Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
233 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use rel tol",
true) )
234 converged->addStatusTest(relresid);
235 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use update tol",
false) )
236 converged->addStatusTest(updateTol);
237 if (problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use WRMS",
false))
238 converged->addStatusTest(wrms);
239 if (problemPtr->getParameterList()->sublist(
"Parameter").get(
"Use abs tol",
false))
240 converged->addStatusTest(absRes);
242 Teuchos::RCP<NOX::StatusTest::MaxIters> maxiters =
243 Teuchos::rcp(
new NOX::StatusTest::MaxIters(problemPtr->getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10)));
244 Teuchos::RCP<NOX::StatusTest::FiniteValue> fv =
245 Teuchos::rcp(
new NOX::StatusTest::FiniteValue);
246 Teuchos::RCP<NOX::StatusTest::Combo> combo =
247 Teuchos::rcp(
new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
248 combo->addStatusTest(fv);
249 combo->addStatusTest(converged);
250 combo->addStatusTest(maxiters);
253 Teuchos::RCP<Teuchos::ParameterList> nl_params = sublist(problemPtr->getParameterList(),
"NOXSolver");
255 Teuchos::RCP<NOX::Solver::Generic> solver =
256 NOX::Solver::buildSolver(nox_group, combo, nl_params);
257 NOX::StatusTest::StatusType solveStatus = solver->solve();
259 double nonLinearIts = solver->getSolverStatistics()->linearSolve.allNonlinearSolves_NumLinearSolves;
260 double linearIts = solver->getSolverStatistics()->linearSolve.allNonlinearSolves_NumLinearIterations;
262 linearIts/=nonLinearIts;
264 std::cout <<
"############################################################" << std::endl;
265 std::cout <<
"### Total nonlinear iterations : " << nonLinearIts <<
" with an average of " << linearIts <<
" linear iterations ###" << std::endl;
266 std::cout <<
"############################################################" << std::endl;
269 if ( problemPtr->getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
270 TEUCHOS_TEST_FOR_EXCEPTION((
int)nonLinearIts == problemPtr->getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10) ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
273 if (!valuesForExport.is_null()) {
274 if (valuesForExport->size() == 2){
275 (*valuesForExport)[0] = linearIts;
276 (*valuesForExport)[1] = nonLinearIts;
282template<
class SC,
class LO,
class GO,
class NO>
283void NonLinearSolver<SC,LO,GO,NO>::solveFixedPoint(NonLinearProblem_Type &problem,vec_dbl_ptr_Type valuesForExport){
285 bool verbose = problem.getVerbose();
286 TEUCHOS_TEST_FOR_EXCEPTION(problem.getRhs()->getNumVectors()!=1,std::logic_error,
"We need to change the code for numVectors>1.");
290 double gmresIts = 0.;
291 double residual0 = 1.;
292 double residual = 1.;
294 double tol = problem.getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
295 int maxNonLinIts = problem.getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10);
298 double criterionValue = 1.;
299 std::string criterion = problem.getParameterList()->sublist(
"Parameter").get(
"Criterion",
"Residual");
302 while ( nlIts < maxNonLinIts ) {
305 problem.calculateNonLinResidualVec(
"reverse");
308 problem.assemble(
"FixedPoint");
310 problem.setBoundariesSystem();
312 if (criterion==
"Residual")
313 residual = problem.calculateResidualNorm();
316 residual0 = residual;
318 if (criterion==
"Residual"){
319 criterionValue = residual/residual0;
321 std::cout <<
"### Fixed Point iteration : " << nlIts <<
" relative nonlinear residual : " << criterionValue << std::endl;
322 if ( criterionValue < tol )
327 problem.setNonlinearIterationStep(nlIts);
328 gmresIts += problem.solveAndUpdate( criterion, criterionValue );
330 if(criterion==
"Update"){
332 std::cout <<
"### Fixed Point iteration : " << nlIts <<
" residual of update : " << criterionValue << std::endl;
333 if ( criterionValue < tol )
341 std::cout <<
"### Total FPI : " << nlIts <<
" with average gmres its : " << gmresIts << std::endl;
342 if ( problem.getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
343 TEUCHOS_TEST_FOR_EXCEPTION( nlIts == maxNonLinIts ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
348template<
class SC,
class LO,
class GO,
class NO>
349void NonLinearSolver<SC,LO,GO,NO>::solveNewton( NonLinearProblem_Type &problem, vec_dbl_ptr_Type valuesForExport ){
351 bool verbose = problem.getVerbose();
353 TEUCHOS_TEST_FOR_EXCEPTION(problem.getRhs()->getNumVectors()!=1,std::logic_error,
"We need to change the code for numVectors>1.")
357 double gmresIts = 0.;
358 double residual0 = 1.;
359 double residual = 1.;
360 double tol = problem.getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
362 int maxNonLinIts = problem.getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10);
363 double criterionValue = 1.;
364 std::
string criterion = problem.getParameterList()->sublist(
"Parameter").get(
"Criterion",
"Residual");
366 while ( nlIts < maxNonLinIts ) {
369 problem.calculateNonLinResidualVec(
"reverse");
371 if (criterion==
"Residual")
372 residual = problem.calculateResidualNorm();
374 problem.assemble(
"Newton");
376 problem.setBoundariesSystem();
379 residual0 = residual;
381 if (criterion==
"Residual"){
382 criterionValue = residual/residual0;
384 std::cout <<
"### Newton iteration : " << nlIts <<
" relative nonlinear residual : " << criterionValue << std::endl;
385 if ( criterionValue < tol )
390 problem.setNonlinearIterationStep(nlIts);
391 gmresIts += problem.solveAndUpdate( criterion, criterionValue );
393 if(criterion==
"Update"){
395 std::cout <<
"### Newton iteration : " << nlIts <<
" residual of update : " << criterionValue << std::endl;
396 if ( criterionValue < tol )
405 std::cout <<
"### Total Newton iterations : " << nlIts <<
" with average gmres its : " << gmresIts << std::endl;
406 if ( problem.getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
407 TEUCHOS_TEST_FOR_EXCEPTION(nlIts == maxNonLinIts ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
410 if (!valuesForExport.is_null()) {
411 if (valuesForExport->size() == 2){
412 (*valuesForExport)[0] = gmresIts;
413 (*valuesForExport)[1] = nlIts;
423template<
class SC,
class LO,
class GO,
class NO>
424void NonLinearSolver<SC,LO,GO,NO>::solveFixedPointNewton( NonLinearProblem_Type &problem, vec_dbl_ptr_Type valuesForExport ){
426 bool verbose = problem.getVerbose();
428 TEUCHOS_TEST_FOR_EXCEPTION(problem.getRhs()->getNumVectors()!=1,std::logic_error,
"We need to change the code for numVectors>1.")
432 double gmresIts = 0.;
433 double residual0 = 1.;
434 double residual = 1.;
435 double tol = problem.getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
437 int maxNonLinIts = problem.getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10);
438 double criterionValue = 1.;
439 std::
string criterion = problem.getParameterList()->sublist(
"Parameter").get(
"Criterion",
"Residual");
441 std::
string linearization = problem.getParameterList()->sublist(
"General").get(
"Initial_Linearization",
"FixedPoint");
442 Teuchos::RCP<NonLinearProblem<SC,LO,GO,NO> > problemPtr = Teuchos::rcpFromRef(problem);
443 Teuchos::RCP<Teuchos::ParameterList> parameterListGeneral = sublist(problemPtr->getParameterList(),
"General");
444 bool linearizationChanged = false;
448 std::cout <<
"####### Run FixedPoint-Newton Combination with Initial Linearization: " << linearization <<
" ####### " << std::endl;
450 while ( nlIts < maxNonLinIts ) {
453 problem.calculateNonLinResidualVec(
"reverse");
455 if (criterion==
"Residual")
456 residual = problem.calculateResidualNorm();
460 residual0 = residual;
462 if (criterion==
"Residual"){
463 criterionValue = residual/residual0;
465 std::cout <<
"### " << linearization <<
" iteration : " << nlIts <<
" relative nonlinear residual : " << criterionValue << std::endl;
467 if ( criterionValue < tol )
472 linearizationChanged = this->switchingStrategy_(linearization, nlIts, criterionValue, parameterListGeneral);
473 if (linearizationChanged)
476 std::cout <<
"### Switching linearization to " << linearization <<
" in iteration " << nlIts << std::endl;
477 problem.changeAssFELinearization(linearization);
480 problem.assemble(linearization);
483 problem.setBoundariesSystem();
488 problem.setNonlinearIterationStep(nlIts);
489 gmresIts += problem.solveAndUpdate( criterion, criterionValue );
491 if(criterion==
"Update"){
493 std::cout <<
"### " << linearization <<
" iteration : " << nlIts <<
" residual of update : " << criterionValue << std::endl;
494 if ( criterionValue < tol )
503 std::cout <<
"### Total " <<
"nonlinear" <<
" iterations : " << nlIts <<
" with average gmres its : " << gmresIts << std::endl;
504 if ( problem.getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
505 TEUCHOS_TEST_FOR_EXCEPTION(nlIts == maxNonLinIts ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
508 if (!valuesForExport.is_null()) {
509 if (valuesForExport->size() == 2){
510 (*valuesForExport)[0] = gmresIts;
511 (*valuesForExport)[1] = nlIts;
519template<
class SC,
class LO,
class GO,
class NO>
520void NonLinearSolver<SC,LO,GO,NO>::solveFixedPoint(TimeProblem_Type &problem,
double time){
522 bool verbose = problem.getVerbose();
523 problem.setBoundariesRHS(time);
524 TEUCHOS_TEST_FOR_EXCEPTION(problem.getRhs()->getNumVectors()!=1,std::logic_error,
"We need to change the code for numVectors>1.")
529 double gmresIts = 0.;
530 double residual0 = 1.;
531 double residual = 1.;
532 double tol = problem.getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
534 int maxNonLinIts = problem.getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10);
535 double criterionValue = 1.;
536 std::
string criterion = problem.getParameterList()->sublist(
"Parameter").get(
"Criterion",
"Residual");
538 while ( nlIts < maxNonLinIts ) {
540 problem.calculateNonLinResidualVec(
"reverse", time);
542 if (criterion==
"Residual")
543 residual = problem.calculateResidualNorm();
546 residual0 = residual;
550 problem.combineSystems();
552 problem.setBoundariesSystem();
554 if (criterion==
"Residual"){
555 criterionValue = residual/residual0;
557 std::cout <<
"### Fixed Point iteration : " << nlIts <<
" relative nonlinear residual : " << criterionValue << std::endl;
558 if ( criterionValue < tol )
562 gmresIts += problem.solveAndUpdate( criterion, criterionValue );
565 if(criterion==
"Update"){
567 std::cout <<
"### Fixed Point iteration : " << nlIts <<
" residual of update : " << criterionValue << std::endl;
568 if ( criterionValue < tol )
576 std::cout <<
"### Total FPI : " << nlIts <<
" with average gmres its : " << gmresIts << std::endl;
577 if ( problem.getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
578 TEUCHOS_TEST_FOR_EXCEPTION( nlIts == maxNonLinIts ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
584template<
class SC,
class LO,
class GO,
class NO>
585void NonLinearSolver<SC,LO,GO,NO>::solveNewton(TimeProblem_Type &problem,
double time, vec_dbl_ptr_Type valuesForExport ){
587 bool verbose = problem.getVerbose();
588 problem.setBoundariesRHS(time);
591 TEUCHOS_TEST_FOR_EXCEPTION(problem.getRhs()->getNumVectors()!=1,std::logic_error,
"We need to change the code for numVectors>1.")
596 double gmresIts = 0.;
597 double residual0 = 1.;
598 double residual = 1.;
599 double tol = problem.getParameterList()->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
601 int maxNonLinIts = problem.getParameterList()->sublist(
"Parameter").get(
"MaxNonLinIts",10);
602 double criterionValue = 1.;
603 std::
string criterion = problem.getParameterList()->sublist(
"Parameter").get(
"Criterion",
"Residual");
604 std::
string timestepping = problem.getParameterList()->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep");
606 while ( nlIts < maxNonLinIts ) {
607 if (timestepping ==
"External")
608 problem.calculateNonLinResidualVec(
"external", time);
610 problem.calculateNonLinResidualVec(
"reverse", time);
611 if (criterion==
"Residual")
612 residual = problem.calculateResidualNorm();
615 residual0 = residual;
617 if (criterion==
"Residual"){
618 criterionValue = residual/residual0;
621 std::cout <<
"### Newton iteration : " << nlIts <<
" relative nonlinear residual : " << criterionValue << std::endl;
622 if ( criterionValue < tol )
627 problem.assemble(
"Newton");
629 problem.setBoundariesSystem();
632 if (timestepping ==
"External"){
633 gmresIts += problem.solveAndUpdate(
"ResidualAceGen", criterionValue );
639 gmresIts += problem.solveAndUpdate( criterion, criterionValue );
644 if(criterion==
"Update"){
646 std::cout <<
"### Newton iteration : " << nlIts <<
" residual of update : " << criterionValue << std::endl;
647 if ( criterionValue < tol )
656 std::cout <<
"### Total Newton iteration : " << nlIts <<
" with average gmres its : " << gmresIts << std::endl;
657 if ( problem.getParameterList()->sublist(
"Parameter").get(
"Cancel MaxNonLinIts",
false) ) {
658 TEUCHOS_TEST_FOR_EXCEPTION(nlIts == maxNonLinIts ,std::runtime_error,
"Maximum nonlinear Iterations reached. Problem might have converged in the last step. Still we cancel here.");
660 if (!valuesForExport.is_null()) {
661 if (valuesForExport->size() == 2){
662 (*valuesForExport)[0] = gmresIts;
663 (*valuesForExport)[1] = nlIts;
672template<
class SC,
class LO,
class GO,
class NO>
673void NonLinearSolver<SC,LO,GO,NO>::solveExtrapolation(TimeProblem<SC,LO,GO,NO> &problem,
double time){
675 bool verbose = problem.getVerbose();
677 problem.assemble(
"Extrapolation");
679 problem.setBoundaries(time);
681 int gmresIts = problem.solve( );
684 std::cout <<
"### GMRES Its : " << gmresIts << std::endl;
Definition NonLinearSolver_decl.hpp:36
void solve(NonLinearProblem_Type &problem, vec_dbl_ptr_Type valuesForExport=Teuchos::null)
Call for solving a nonlinear problem, depending on linearization solveNOX/solveFixedPoint/solveNewton...
Definition NonLinearSolver_def.hpp:33
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36