newtonmethod.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef EWOMS_NEWTON_METHOD_HH
28#define EWOMS_NEWTON_METHOD_HH
29
31
33
34#include <opm/common/Exceptions.hpp>
35
36#include <opm/material/densead/Math.hpp>
37
41
43
44#include <dune/istl/istlexception.hh>
45#include <dune/common/classname.hh>
46#include <dune/common/parallel/mpihelper.hh>
47
48#include <iostream>
49#include <sstream>
50
51#include <unistd.h>
52
53namespace Opm {
54// forward declaration of classes
55template <class TypeTag>
56class NewtonMethod;
57}
58
59namespace Opm {
60// forward declaration of property tags
61} // namespace Opm
62
63namespace Opm::Properties {
64
65namespace TTag {
66
69struct NewtonMethod {};
70
71} // namespace TTag
72
73// set default values for the properties
74template<class TypeTag>
75struct NewtonMethod<TypeTag, TTag::NewtonMethod> { using type = ::Opm::NewtonMethod<TypeTag>; };
76template<class TypeTag>
78template<class TypeTag>
79struct NewtonWriteConvergence<TypeTag, TTag::NewtonMethod> { static constexpr bool value = false; };
80template<class TypeTag>
81struct NewtonVerbose<TypeTag, TTag::NewtonMethod> { static constexpr bool value = true; };
82template<class TypeTag>
83struct NewtonTolerance<TypeTag, TTag::NewtonMethod>
84{
86 static constexpr type value = 1e-8;
87};
88// set the abortion tolerace to some very large value. if not
89// overwritten at run-time this basically disables abortions
90template<class TypeTag>
91struct NewtonMaxError<TypeTag, TTag::NewtonMethod>
92{
94 static constexpr type value = 1e100;
95};
96template<class TypeTag>
97struct NewtonTargetIterations<TypeTag, TTag::NewtonMethod> { static constexpr int value = 10; };
98template<class TypeTag>
99struct NewtonMaxIterations<TypeTag, TTag::NewtonMethod> { static constexpr int value = 20; };
100
101} // namespace Opm::Properties
102
103namespace Opm {
111template <class TypeTag>
113{
119
128
129 using Communicator = typename Dune::MPIHelper::MPICommunicator;
130 using CollectiveCommunication = typename Dune::Communication<typename Dune::MPIHelper::MPICommunicator>;
131
132public:
133 NewtonMethod(Simulator& simulator)
134 : simulator_(simulator)
135 , endIterMsgStream_(std::ostringstream::out)
136 , linearSolver_(simulator)
137 , comm_(Dune::MPIHelper::getCommunicator())
138 , convergenceWriter_(asImp_())
139 {
140 lastError_ = 1e100;
141 error_ = 1e100;
142 tolerance_ = Parameters::get<TypeTag, Properties::NewtonTolerance>();
143
144 numIterations_ = 0;
145 }
146
150 static void registerParameters()
151 {
152 LinearSolverBackend::registerParameters();
153
154 Parameters::registerParam<TypeTag, Properties::NewtonVerbose>
155 ("Specify whether the Newton method should inform "
156 "the user about its progress or not");
157 Parameters::registerParam<TypeTag, Properties::NewtonWriteConvergence>
158 ("Write the convergence behaviour of the Newton "
159 "method to a VTK file");
160 Parameters::registerParam<TypeTag, Properties::NewtonTargetIterations>
161 ("The 'optimum' number of Newton iterations per time step");
162 Parameters::registerParam<TypeTag, Properties::NewtonMaxIterations>
163 ("The maximum number of Newton iterations per time step");
164 Parameters::registerParam<TypeTag, Properties::NewtonTolerance>
165 ("The maximum raw error tolerated by the Newton"
166 "method for considering a solution to be converged");
167 Parameters::registerParam<TypeTag, Properties::NewtonMaxError>
168 ("The maximum error tolerated by the Newton "
169 "method to which does not cause an abort");
170 }
171
179 { }
180
185 bool converged() const
186 { return error_ <= tolerance(); }
187
191 Problem& problem()
192 { return simulator_.problem(); }
193
197 const Problem& problem() const
198 { return simulator_.problem(); }
199
203 Model& model()
204 { return simulator_.model(); }
205
209 const Model& model() const
210 { return simulator_.model(); }
211
216 int numIterations() const
217 { return numIterations_; }
218
226 void setIterationIndex(int value)
227 { numIterations_ = value; }
228
233 Scalar tolerance() const
234 { return tolerance_; }
235
240 void setTolerance(Scalar value)
241 { tolerance_ = value; }
242
249 bool apply()
250 {
251 // Clear the current line using an ansi escape
252 // sequence. For an explanation see
253 // http://en.wikipedia.org/wiki/ANSI_escape_code
254 const char *clearRemainingLine = "\n";
255 if (isatty(fileno(stdout))) {
256 static const char blubb[] = { 0x1b, '[', 'K', '\r', 0 };
257 clearRemainingLine = blubb;
258 }
259
260 // make sure all timers are prestine
265
266 SolutionVector& nextSolution = model().solution(/*historyIdx=*/0);
267 SolutionVector currentSolution(nextSolution);
268 GlobalEqVector solutionUpdate(nextSolution.size());
269
270 Linearizer& linearizer = model().linearizer();
271
272 TimerGuard prePostProcessTimerGuard(prePostProcessTimer_);
273
274 // tell the implementation that we begin solving
276 asImp_().begin_(nextSolution);
278
279 try {
280 TimerGuard innerPrePostProcessTimerGuard(prePostProcessTimer_);
281 TimerGuard linearizeTimerGuard(linearizeTimer_);
282 TimerGuard updateTimerGuard(updateTimer_);
283 TimerGuard solveTimerGuard(solveTimer_);
284
285 // execute the method as long as the implementation thinks
286 // that we should do another iteration
287 while (asImp_().proceed_()) {
288 // linearize the problem at the current solution
289
290 // notify the implementation that we're about to start
291 // a new iteration
293 asImp_().beginIteration_();
295
296 // make the current solution to the old one
297 currentSolution = nextSolution;
298
299 if (asImp_().verbose_()) {
300 std::cout << "Linearize: r(x^k) = dS/dt + div F - q; M = grad r"
301 << clearRemainingLine
302 << std::flush;
303 }
304
305 // do the actual linearization
307 asImp_().linearizeDomain_();
308 asImp_().linearizeAuxiliaryEquations_();
310
312 auto& residual = linearizer.residual();
313 const auto& jacobian = linearizer.jacobian();
314 linearSolver_.prepare(jacobian, residual);
315 linearSolver_.setResidual(residual);
316 linearSolver_.getResidual(residual);
318
319 // The preSolve_() method usually computes the errors, but it can do
320 // something else in addition. TODO: should its costs be counted to
321 // the linearization or to the update?
323 asImp_().preSolve_(currentSolution, residual);
325
326 if (!asImp_().proceed_()) {
327 if (asImp_().verbose_() && isatty(fileno(stdout)))
328 std::cout << clearRemainingLine
329 << std::flush;
330
331 // tell the implementation that we're done with this iteration
333 asImp_().endIteration_(nextSolution, currentSolution);
335
336 break;
337 }
338
339 // solve the resulting linear equation system
340 if (asImp_().verbose_()) {
341 std::cout << "Solve: M deltax^k = r"
342 << clearRemainingLine
343 << std::flush;
344 }
345
347 // solve A x = b, where b is the residual, A is its Jacobian and x is the
348 // update of the solution
349 linearSolver_.setMatrix(jacobian);
350 solutionUpdate = 0.0;
351 bool converged = linearSolver_.solve(solutionUpdate);
353
354 if (!converged) {
356 if (asImp_().verbose_())
357 std::cout << "Newton: Linear solver did not converge\n" << std::flush;
358
360 asImp_().failed_();
362
363 return false;
364 }
365
366 // update the solution
367 if (asImp_().verbose_()) {
368 std::cout << "Update: x^(k+1) = x^k - deltax^k"
369 << clearRemainingLine
370 << std::flush;
371 }
372
373 // update the current solution (i.e. uOld) with the delta
374 // (i.e. u). The result is stored in u
376 asImp_().postSolve_(currentSolution,
377 residual,
378 solutionUpdate);
379 asImp_().update_(nextSolution, currentSolution, solutionUpdate, residual);
381
382 if (asImp_().verbose_() && isatty(fileno(stdout)))
383 // make sure that the line currently holding the cursor is prestine
384 std::cout << clearRemainingLine
385 << std::flush;
386
387 // tell the implementation that we're done with this iteration
389 asImp_().endIteration_(nextSolution, currentSolution);
391 }
392 }
393 catch (const Dune::Exception& e)
394 {
395 if (asImp_().verbose_())
396 std::cout << "Newton method caught exception: \""
397 << e.what() << "\"\n" << std::flush;
398
400 asImp_().failed_();
402
403 return false;
404 }
405 catch (const NumericalProblem& e)
406 {
407 if (asImp_().verbose_())
408 std::cout << "Newton method caught exception: \""
409 << e.what() << "\"\n" << std::flush;
410
412 asImp_().failed_();
414
415 return false;
416 }
417
418 // clear current line on terminal
419 if (asImp_().verbose_() && isatty(fileno(stdout)))
420 std::cout << clearRemainingLine
421 << std::flush;
422
423 // tell the implementation that we're done
425 asImp_().end_();
427
428 // print the timing summary of the time step
429 if (asImp_().verbose_()) {
430 Scalar elapsedTot =
434 std::cout << "Linearization/solve/update time: "
436 << 100 * linearizeTimer_.realTimeElapsed()/elapsedTot << "%)/"
437 << solveTimer_.realTimeElapsed() << "("
438 << 100 * solveTimer_.realTimeElapsed()/elapsedTot << "%)/"
439 << updateTimer_.realTimeElapsed() << "("
440 << 100 * updateTimer_.realTimeElapsed()/elapsedTot << "%)"
441 << "\n" << std::flush;
442 }
443
444
445 // if we're not converged, tell the implementation that we've failed
446 if (!asImp_().converged()) {
448 asImp_().failed_();
450 return false;
451 }
452
453 // if we converged, tell the implementation that we've succeeded
455 asImp_().succeeded_();
457
458 return true;
459 }
460
469 Scalar suggestTimeStepSize(Scalar oldDt) const
470 {
471 // be aggressive reducing the time-step size but
472 // conservative when increasing it. the rationale is
473 // that we want to avoid failing in the next time
474 // integration which would be quite expensive
476 Scalar percent = Scalar(numIterations_ - targetIterations_())/targetIterations_();
477 Scalar nextDt = std::max(problem().minTimeStepSize(),
478 oldDt/(1.0 + percent));
479 return nextDt;
480 }
481
482 Scalar percent = Scalar(targetIterations_() - numIterations_)/targetIterations_();
483 Scalar nextDt = std::max(problem().minTimeStepSize(),
484 oldDt*(1.0 + percent/1.2));
485 return nextDt;
486 }
487
492 std::ostringstream& endIterMsg()
493 { return endIterMsgStream_; }
494
500 { linearSolver_.eraseMatrix(); }
501
505 LinearSolverBackend& linearSolver()
506 { return linearSolver_; }
507
511 const LinearSolverBackend& linearSolver() const
512 { return linearSolver_; }
513
515 { return prePostProcessTimer_; }
516
517 const Timer& linearizeTimer() const
518 { return linearizeTimer_; }
519
520 const Timer& solveTimer() const
521 { return solveTimer_; }
522
523 const Timer& updateTimer() const
524 { return updateTimer_; }
525
526protected:
530 bool verbose_() const
531 {
532 return Parameters::get<TypeTag, Properties::NewtonVerbose>() && (comm_.rank() == 0);
533 }
534
541 void begin_(const SolutionVector&)
542 {
543 numIterations_ = 0;
544
545 if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>())
546 convergenceWriter_.beginTimeStep();
547 }
548
553 {
554 // start with a clean message stream
555 endIterMsgStream_.str("");
556 const auto& comm = simulator_.gridView().comm();
557 bool succeeded = true;
558 try {
559 problem().beginIteration();
560 }
561 catch (const std::exception& e) {
562 succeeded = false;
563
564 std::cout << "rank " << simulator_.gridView().comm().rank()
565 << " caught an exception while pre-processing the problem:" << e.what()
566 << "\n" << std::flush;
567 }
568
569 succeeded = comm.min(succeeded);
570
571 if (!succeeded)
572 throw NumericalProblem("pre processing of the problem failed");
573
575 }
576
582 {
583 model().linearizer().linearizeDomain();
584 }
585
587 {
588 model().linearizer().linearizeAuxiliaryEquations();
589 model().linearizer().finalize();
590 }
591
592 void preSolve_(const SolutionVector&,
593 const GlobalEqVector& currentResidual)
594 {
595 const auto& constraintsMap = model().linearizer().constraintsMap();
597 Scalar newtonMaxError = Parameters::get<TypeTag, Properties::NewtonMaxError>();
598
599 // calculate the error as the maximum weighted tolerance of
600 // the solution's residual
601 error_ = 0;
602 for (unsigned dofIdx = 0; dofIdx < currentResidual.size(); ++dofIdx) {
603 // do not consider auxiliary DOFs for the error
604 if (dofIdx >= model().numGridDof() || model().dofTotalVolume(dofIdx) <= 0.0)
605 continue;
606
607 // also do not consider DOFs which are constraint
608 if (enableConstraints_()) {
609 if (constraintsMap.count(dofIdx) > 0)
610 continue;
611 }
612
613 const auto& r = currentResidual[dofIdx];
614 for (unsigned eqIdx = 0; eqIdx < r.size(); ++eqIdx)
615 error_ = max(std::abs(r[eqIdx] * model().eqWeight(dofIdx, eqIdx)), error_);
616 }
617
618 // take the other processes into account
619 error_ = comm_.max(error_);
620
621 // make sure that the error never grows beyond the maximum
622 // allowed one
623 if (error_ > newtonMaxError)
624 throw NumericalProblem("Newton: Error "+std::to_string(double(error_))
625 + " is larger than maximum allowed error of "
626 + std::to_string(double(newtonMaxError)));
627 }
628
641 void postSolve_(const SolutionVector&,
642 const GlobalEqVector&,
643 GlobalEqVector& solutionUpdate)
644 {
645 // loop over the auxiliary modules and ask them to post process the solution
646 // vector.
647 auto& model = simulator_.model();
648 const auto& comm = simulator_.gridView().comm();
649 for (unsigned i = 0; i < model.numAuxiliaryModules(); ++i) {
650 auto& auxMod = *model.auxiliaryModule(i);
651
652 bool succeeded = true;
653 try {
654 auxMod.postSolve(solutionUpdate);
655 }
656 catch (const std::exception& e) {
657 succeeded = false;
658
659 std::cout << "rank " << simulator_.gridView().comm().rank()
660 << " caught an exception while post processing an auxiliary module:" << e.what()
661 << "\n" << std::flush;
662 }
663
664 succeeded = comm.min(succeeded);
665
666 if (!succeeded)
667 throw NumericalProblem("post processing of an auxilary equation failed");
668 }
669 }
670
685 void update_(SolutionVector& nextSolution,
686 const SolutionVector& currentSolution,
687 const GlobalEqVector& solutionUpdate,
688 const GlobalEqVector& currentResidual)
689 {
690 const auto& constraintsMap = model().linearizer().constraintsMap();
691
692 // first, write out the current solution to make convergence
693 // analysis possible
694 asImp_().writeConvergence_(currentSolution, solutionUpdate);
695
696 // make sure not to swallow non-finite values at this point
697 if (!std::isfinite(solutionUpdate.one_norm()))
698 throw NumericalProblem("Non-finite update!");
699
700 size_t numGridDof = model().numGridDof();
701 for (unsigned dofIdx = 0; dofIdx < numGridDof; ++dofIdx) {
702 if (enableConstraints_()) {
703 if (constraintsMap.count(dofIdx) > 0) {
704 const auto& constraints = constraintsMap.at(dofIdx);
705 asImp_().updateConstraintDof_(dofIdx,
706 nextSolution[dofIdx],
707 constraints);
708 }
709 else
710 asImp_().updatePrimaryVariables_(dofIdx,
711 nextSolution[dofIdx],
712 currentSolution[dofIdx],
713 solutionUpdate[dofIdx],
714 currentResidual[dofIdx]);
715 }
716 else
717 asImp_().updatePrimaryVariables_(dofIdx,
718 nextSolution[dofIdx],
719 currentSolution[dofIdx],
720 solutionUpdate[dofIdx],
721 currentResidual[dofIdx]);
722 }
723
724 // update the DOFs of the auxiliary equations
725 size_t numDof = model().numTotalDof();
726 for (size_t dofIdx = numGridDof; dofIdx < numDof; ++dofIdx) {
727 nextSolution[dofIdx] = currentSolution[dofIdx];
728 nextSolution[dofIdx] -= solutionUpdate[dofIdx];
729 }
730 }
731
735 void updateConstraintDof_(unsigned,
736 PrimaryVariables& nextValue,
737 const Constraints& constraints)
738 { nextValue = constraints; }
739
744 PrimaryVariables& nextValue,
745 const PrimaryVariables& currentValue,
746 const EqVector& update,
747 const EqVector&)
748 {
749 nextValue = currentValue;
750 nextValue -= update;
751 }
752
759 void writeConvergence_(const SolutionVector& currentSolution,
760 const GlobalEqVector& solutionUpdate)
761 {
762 if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>()) {
763 convergenceWriter_.beginIteration();
764 convergenceWriter_.writeFields(currentSolution, solutionUpdate);
765 convergenceWriter_.endIteration();
766 }
767 }
768
775 void endIteration_(const SolutionVector&,
776 const SolutionVector&)
777 {
779
780 const auto& comm = simulator_.gridView().comm();
781 bool succeeded = true;
782 try {
783 problem().endIteration();
784 }
785 catch (const std::exception& e) {
786 succeeded = false;
787
788 std::cout << "rank " << simulator_.gridView().comm().rank()
789 << " caught an exception while letting the problem post-process:" << e.what()
790 << "\n" << std::flush;
791 }
792
793 succeeded = comm.min(succeeded);
794
795 if (!succeeded)
796 throw NumericalProblem("post processing of the problem failed");
797
798 if (asImp_().verbose_()) {
799 std::cout << "Newton iteration " << numIterations_ << ""
800 << " error: " << error_
801 << endIterMsg().str() << "\n" << std::flush;
802 }
803 }
804
808 bool proceed_() const
809 {
810 if (asImp_().numIterations() < 1)
811 return true; // we always do at least one full iteration
812 else if (asImp_().converged()) {
813 // we are below the specified tolerance, so we don't have to
814 // do more iterations
815 return false;
816 }
817 else if (asImp_().numIterations() >= asImp_().maxIterations_()) {
818 // we have exceeded the allowed number of steps. If the
819 // error was reduced by a factor of at least 4,
820 // in the last iterations we proceed even if we are above
821 // the maximum number of steps
822 return error_ * 4.0 < lastError_;
823 }
824
825 return true;
826 }
827
832 void end_()
833 {
834 if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>())
835 convergenceWriter_.endTimeStep();
836 }
837
843 void failed_()
845
852 {}
853
854 // optimal number of iterations we want to achieve
856 { return Parameters::get<TypeTag, Properties::NewtonTargetIterations>(); }
857 // maximum number of iterations we do before giving up
858 int maxIterations_() const
859 { return Parameters::get<TypeTag, Properties::NewtonMaxIterations>(); }
860
861 static bool enableConstraints_()
862 { return getPropValue<TypeTag, Properties::EnableConstraints>(); }
863
864 Simulator& simulator_;
865
870
871 std::ostringstream endIterMsgStream_;
872
873 Scalar error_;
876
877 // actual number of iterations done so far
879
880 // the linear solver
881 LinearSolverBackend linearSolver_;
882
883 // the collective communication used by the simulation (i.e. fake
884 // or MPI)
885 CollectiveCommunication comm_;
886
887 // the object which writes the convergence behaviour of the Newton
888 // method to disk
889 ConvergenceWriter convergenceWriter_;
890
891private:
892 Implementation& asImp_()
893 { return *static_cast<Implementation *>(this); }
894 const Implementation& asImp_() const
895 { return *static_cast<const Implementation *>(this); }
896};
897
898} // namespace Opm
899
900#endif
The multi-dimensional Newton method.
Definition: newtonmethod.hh:113
bool verbose_() const
Returns true if the Newton method ought to be chatty.
Definition: newtonmethod.hh:530
Timer linearizeTimer_
Definition: newtonmethod.hh:867
void end_()
Indicates that we're done solving the non-linear system of equations.
Definition: newtonmethod.hh:832
const Timer & updateTimer() const
Definition: newtonmethod.hh:523
const Timer & linearizeTimer() const
Definition: newtonmethod.hh:517
Timer solveTimer_
Definition: newtonmethod.hh:868
const Timer & solveTimer() const
Definition: newtonmethod.hh:520
bool proceed_() const
Returns true iff another Newton iteration should be done.
Definition: newtonmethod.hh:808
int numIterations() const
Returns the number of iterations done since the Newton method was invoked.
Definition: newtonmethod.hh:216
static bool enableConstraints_()
Definition: newtonmethod.hh:861
const LinearSolverBackend & linearSolver() const
Returns the linear solver backend object for external use.
Definition: newtonmethod.hh:511
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: newtonmethod.hh:743
Scalar tolerance_
Definition: newtonmethod.hh:875
void setTolerance(Scalar value)
Set the current tolerance at which the Newton method considers itself to be converged.
Definition: newtonmethod.hh:240
int maxIterations_() const
Definition: newtonmethod.hh:858
std::ostringstream & endIterMsg()
Message that should be printed for the user after the end of an iteration.
Definition: newtonmethod.hh:492
static void registerParameters()
Register all run-time parameters for the Newton method.
Definition: newtonmethod.hh:150
Timer prePostProcessTimer_
Definition: newtonmethod.hh:866
int targetIterations_() const
Definition: newtonmethod.hh:855
void postSolve_(const SolutionVector &, const GlobalEqVector &, GlobalEqVector &solutionUpdate)
Update the error of the solution given the previous iteration.
Definition: newtonmethod.hh:641
const Timer & prePostProcessTimer() const
Definition: newtonmethod.hh:514
Scalar lastError_
Definition: newtonmethod.hh:874
bool apply()
Run the Newton method.
Definition: newtonmethod.hh:249
void writeConvergence_(const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate)
Write the convergence behaviour of the newton method to disk.
Definition: newtonmethod.hh:759
Scalar error_
Definition: newtonmethod.hh:873
void begin_(const SolutionVector &)
Called before the Newton method is applied to an non-linear system of equations.
Definition: newtonmethod.hh:541
void failed_()
Called if the Newton method broke down.
Definition: newtonmethod.hh:843
void update_(SolutionVector &nextSolution, const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate, const GlobalEqVector &currentResidual)
Update the current solution with a delta vector.
Definition: newtonmethod.hh:685
void preSolve_(const SolutionVector &, const GlobalEqVector &currentResidual)
Definition: newtonmethod.hh:592
Timer updateTimer_
Definition: newtonmethod.hh:869
const Model & model() const
Returns a reference to the numeric model.
Definition: newtonmethod.hh:209
int numIterations_
Definition: newtonmethod.hh:878
LinearSolverBackend linearSolver_
Definition: newtonmethod.hh:881
void succeeded_()
Called if the Newton method was successful.
Definition: newtonmethod.hh:851
Scalar tolerance() const
Return the current tolerance at which the Newton method considers itself to be converged.
Definition: newtonmethod.hh:233
LinearSolverBackend & linearSolver()
Returns the linear solver backend object for external use.
Definition: newtonmethod.hh:505
void linearizeDomain_()
Linearize the global non-linear system of equations associated with the spatial domain.
Definition: newtonmethod.hh:581
const Problem & problem() const
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:197
Scalar suggestTimeStepSize(Scalar oldDt) const
Suggest a new time-step size based on the old time-step size.
Definition: newtonmethod.hh:469
bool converged() const
Returns true if the error of the solution is below the tolerance.
Definition: newtonmethod.hh:185
CollectiveCommunication comm_
Definition: newtonmethod.hh:885
Problem & problem()
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:191
void eraseMatrix()
Causes the solve() method to discared the structure of the linear system of equations the next time i...
Definition: newtonmethod.hh:499
void updateConstraintDof_(unsigned, PrimaryVariables &nextValue, const Constraints &constraints)
Update the primary variables for a degree of freedom which is constraint.
Definition: newtonmethod.hh:735
std::ostringstream endIterMsgStream_
Definition: newtonmethod.hh:871
ConvergenceWriter convergenceWriter_
Definition: newtonmethod.hh:889
NewtonMethod(Simulator &simulator)
Definition: newtonmethod.hh:133
void finishInit()
Finialize the construction of the object.
Definition: newtonmethod.hh:178
void linearizeAuxiliaryEquations_()
Definition: newtonmethod.hh:586
Model & model()
Returns a reference to the numeric model.
Definition: newtonmethod.hh:203
Simulator & simulator_
Definition: newtonmethod.hh:864
void beginIteration_()
Indicates the beginning of a Newton iteration.
Definition: newtonmethod.hh:552
void endIteration_(const SolutionVector &, const SolutionVector &)
Indicates that one Newton iteration was finished.
Definition: newtonmethod.hh:775
void setIterationIndex(int value)
Set the index of current iteration.
Definition: newtonmethod.hh:226
A convergence writer for the Newton method which does nothing.
Definition: nullconvergencewriter.hh:51
A simple class which makes sure that a timer gets stopped if an exception is thrown.
Definition: timerguard.hh:41
Provides an encapsulation to measure the system time.
Definition: timer.hh:49
void start()
Start counting the time resources used by the simulation.
Definition: timer.hh:62
void halt()
Stop the measurement reset all timing values.
Definition: timer.hh:99
double realTimeElapsed() const
Return the real time [s] elapsed during the periods the timer was active since the last reset.
Definition: timer.hh:121
double stop()
Stop counting the time resources.
Definition: timer.hh:73
Declare the properties used by the infrastructure code of the finite volume discretizations.
Declares the properties required by the black oil model.
Definition: fvbaseprimaryvariables.hh:141
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:242
Specifies the type of the class which writes out the Newton convergence.
Definition: newtonmethodproperties.hh:44
GetPropType< TypeTag, Scalar > type
Definition: newtonmethod.hh:93
Definition: newtonmethodproperties.hh:68
Number of maximum iterations for the Newton method.
Definition: newtonmethodproperties.hh:83
Specifies the type of the actual Newton method.
Definition: newtonmethodproperties.hh:32
The number of iterations at which the Newton method should aim at.
Definition: newtonmethodproperties.hh:79
GetPropType< TypeTag, Scalar > type
Definition: newtonmethod.hh:85
The value for the error below which convergence is declared.
Definition: newtonmethodproperties.hh:63
Specifies whether the Newton method should print messages or not.
Definition: newtonmethodproperties.hh:40
Definition: newtonmethodproperties.hh:49
Definition: newtonmethod.hh:69