opm-simulators
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 
30 #include <dune/common/classname.hh>
31 #include <dune/common/parallel/mpihelper.hh>
32 
33 #include <dune/istl/istlexception.hh>
34 
35 #include <opm/common/Exceptions.hpp>
36 
37 #include <opm/material/densead/Math.hpp>
38 
40 
41 #include <opm/models/nonlinear/newtonmethodparams.hpp>
42 #include <opm/models/nonlinear/newtonmethodproperties.hh>
44 
47 
49 
50 #include <algorithm>
51 #include <cmath>
52 #include <cstddef>
53 #include <exception>
54 #include <iostream>
55 #include <sstream>
56 #include <string>
57 
58 #include <unistd.h>
59 
60 namespace Opm {
61 
62 // forward declaration of classes
63 template <class TypeTag>
65 
66 }
67 
68 namespace Opm::Properties {
69 
70 namespace TTag {
71 
74 struct NewtonMethod {};
75 
76 } // namespace TTag
77 
78 // set default values for the properties
79 template<class TypeTag>
80 struct NewtonMethod<TypeTag, TTag::NewtonMethod>
82 
83 template<class TypeTag>
84 struct NewtonConvergenceWriter<TypeTag, TTag::NewtonMethod>
86 
87 } // namespace Opm::Properties
88 
89 namespace Opm {
90 
98 template <class TypeTag>
99 class NewtonMethod
100 {
101  using Implementation = GetPropType<TypeTag, Properties::NewtonMethod>;
106 
113  using LinearSolverBackend = GetPropType<TypeTag, Properties::LinearSolverBackend>;
115 
116  using Communicator = typename Dune::MPIHelper::MPICommunicator;
117  using CollectiveCommunication = typename Dune::Communication<typename Dune::MPIHelper::MPICommunicator>;
118 
119 public:
120  explicit NewtonMethod(Simulator& simulator)
121  : simulator_(simulator)
122  , endIterMsgStream_(std::ostringstream::out)
123  , error_(1e100)
124  , lastError_(1e100)
125  , linearSolver_(simulator)
126  , comm_(Dune::MPIHelper::getCommunicator())
127  , convergenceWriter_(asImp_())
128  {
129  params_.read();
130  }
131 
135  static void registerParameters()
136  {
137  LinearSolverBackend::registerParameters();
139  }
140 
147  void finishInit()
148  {}
149 
154  bool converged() const
155  { return error_ <= tolerance(); }
156 
160  Problem& problem()
161  { return simulator_.problem(); }
162 
166  const Problem& problem() const
167  { return simulator_.problem(); }
168 
172  Model& model()
173  { return simulator_.model(); }
174 
178  const Model& model() const
179  { return simulator_.model(); }
180 
185  Scalar tolerance() const
186  { return params_.tolerance_; }
187 
192  void setTolerance(Scalar value)
193  { params_.tolerance_ = value; }
194 
202  void applyUpdate(SolutionVector& nextSolution,
203  const SolutionVector& currentSolution,
204  const GlobalEqVector& solutionUpdate,
205  const GlobalEqVector& currentResidual)
206  {
207  asImp_().update_(nextSolution, currentSolution, solutionUpdate, currentResidual);
208  }
209 
216  bool apply()
217  {
218  const bool istty = isatty(fileno(stdout));
219 
220  // Clear the current line using an ansi escape
221  // sequence. For an explanation see
222  // http://en.wikipedia.org/wiki/ANSI_escape_code
223  const char* clearRemainingLine = "\n";
224  if (istty) {
225  static const char ansiClear[] = { 0x1b, '[', 'K', '\r', 0 };
226  clearRemainingLine = ansiClear;
227  }
228 
229  // make sure all timers are prestine
230  prePostProcessTimer_.halt();
231  linearizeTimer_.halt();
232  solveTimer_.halt();
233  updateTimer_.halt();
234 
235  SolutionVector& nextSolution = model().solution(/*historyIdx=*/0);
236  SolutionVector currentSolution(nextSolution);
237  GlobalEqVector solutionUpdate(nextSolution.size());
238 
239  Linearizer& linearizer = model().linearizer();
240 
241  TimerGuard prePostProcessTimerGuard(prePostProcessTimer_);
242 
243  // tell the implementation that we begin solving
244  prePostProcessTimer_.start();
245  asImp_().begin_(nextSolution);
246  prePostProcessTimer_.stop();
247 
248  try {
249  TimerGuard innerPrePostProcessTimerGuard(prePostProcessTimer_);
250  TimerGuard linearizeTimerGuard(linearizeTimer_);
251  TimerGuard updateTimerGuard(updateTimer_);
252  TimerGuard solveTimerGuard(solveTimer_);
253 
254  // execute the method as long as the implementation thinks
255  // that we should do another iteration
256  while (asImp_().proceed_()) {
257  // linearize the problem at the current solution
258 
259  // notify the implementation that we're about to start
260  // a new iteration
261  prePostProcessTimer_.start();
262  asImp_().beginIteration_();
263  prePostProcessTimer_.stop();
264 
265  // make the current solution to the old one
266  currentSolution = nextSolution;
267 
268  if (asImp_().verbose_()) {
269  std::cout << "Linearize: r(x^k) = dS/dt + div F - q; M = grad r"
270  << clearRemainingLine
271  << std::flush;
272  }
273 
274  // do the actual linearization
275  linearizeTimer_.start();
276  asImp_().linearizeDomain_();
277  asImp_().linearizeAuxiliaryEquations_();
278  linearizeTimer_.stop();
279 
280  solveTimer_.start();
281  auto& residual = linearizer.residual();
282  const auto& jacobian = linearizer.jacobian();
283  linearSolver_.prepare(jacobian, residual);
284  linearSolver_.setResidual(residual);
285  linearSolver_.getResidual(residual);
286  solveTimer_.stop();
287 
288  // The preSolve_() method usually computes the errors, but it can do
289  // something else in addition. TODO: should its costs be counted to
290  // the linearization or to the update?
291  updateTimer_.start();
292  asImp_().preSolve_(currentSolution, residual);
293  updateTimer_.stop();
294 
295  if (!asImp_().proceed_()) {
296  if (asImp_().verbose_() && istty) {
297  std::cout << clearRemainingLine << std::flush;
298  }
299 
300  // tell the implementation that we're done with this iteration
301  prePostProcessTimer_.start();
302  asImp_().endIteration_(nextSolution, currentSolution);
303  prePostProcessTimer_.stop();
304 
305  break;
306  }
307 
308  // solve the resulting linear equation system
309  if (asImp_().verbose_()) {
310  std::cout << "Solve: M deltax^k = r"
311  << clearRemainingLine
312  << std::flush;
313  }
314 
315  solveTimer_.start();
316  // solve A x = b, where b is the residual, A is its Jacobian and x is the
317  // update of the solution
318  linearSolver_.setMatrix(jacobian);
319  solutionUpdate = 0.0;
320  const bool conv = linearSolver_.solve(solutionUpdate);
321  solveTimer_.stop();
322 
323  if (!conv) {
324  solveTimer_.stop();
325  if (asImp_().verbose_()) {
326  std::cout << "Newton: Linear solver did not converge\n" << std::flush;
327  }
328 
329  prePostProcessTimer_.start();
330  asImp_().failed_();
331  prePostProcessTimer_.stop();
332 
333  return false;
334  }
335 
336  // update the solution
337  if (asImp_().verbose_()) {
338  std::cout << "Update: x^(k+1) = x^k - deltax^k"
339  << clearRemainingLine
340  << std::flush;
341  }
342 
343  // update the current solution (i.e. uOld) with the delta
344  // (i.e. u). The result is stored in u
345  updateTimer_.start();
346  asImp_().postSolve_(currentSolution,
347  residual,
348  solutionUpdate);
349  asImp_().update_(nextSolution, currentSolution, solutionUpdate, residual);
350  updateTimer_.stop();
351 
352  if (asImp_().verbose_() && istty) {
353  // make sure that the line currently holding the cursor is prestine
354  std::cout << clearRemainingLine
355  << std::flush;
356  }
357 
358  // tell the implementation that we're done with this iteration
359  prePostProcessTimer_.start();
360  asImp_().endIteration_(nextSolution, currentSolution);
361  prePostProcessTimer_.stop();
362  }
363  }
364  catch (const Dune::Exception& e)
365  {
366  if (asImp_().verbose_()) {
367  std::cout << "Newton method caught exception: \""
368  << e.what() << "\"\n" << std::flush;
369  }
370 
371  prePostProcessTimer_.start();
372  asImp_().failed_();
373  prePostProcessTimer_.stop();
374 
375  return false;
376  }
377  catch (const NumericalProblem& e)
378  {
379  if (asImp_().verbose_()) {
380  std::cout << "Newton method caught exception: \""
381  << e.what() << "\"\n" << std::flush;
382  }
383 
384  prePostProcessTimer_.start();
385  asImp_().failed_();
386  prePostProcessTimer_.stop();
387 
388  return false;
389  }
390 
391  // clear current line on terminal
392  if (asImp_().verbose_() && istty) {
393  std::cout << clearRemainingLine
394  << std::flush;
395  }
396 
397  // tell the implementation that we're done
398  prePostProcessTimer_.start();
399  asImp_().end_();
400  prePostProcessTimer_.stop();
401 
402  // print the timing summary of the time step
403  if (asImp_().verbose_()) {
404  Scalar elapsedTot =
405  linearizeTimer_.realTimeElapsed() +
406  solveTimer_.realTimeElapsed() +
407  updateTimer_.realTimeElapsed();
408  std::cout << "Linearization/solve/update time: "
409  << linearizeTimer_.realTimeElapsed() << "("
410  << 100 * linearizeTimer_.realTimeElapsed() / elapsedTot << "%)/"
411  << solveTimer_.realTimeElapsed() << "("
412  << 100 * solveTimer_.realTimeElapsed() / elapsedTot << "%)/"
413  << updateTimer_.realTimeElapsed() << "("
414  << 100 * updateTimer_.realTimeElapsed() / elapsedTot << "%)"
415  << "\n" << std::flush;
416  }
417 
418 
419  // if we're not converged, tell the implementation that we've failed
420  if (!asImp_().converged()) {
421  prePostProcessTimer_.start();
422  asImp_().failed_();
423  prePostProcessTimer_.stop();
424  return false;
425  }
426 
427  // if we converged, tell the implementation that we've succeeded
428  prePostProcessTimer_.start();
429  asImp_().succeeded_();
430  prePostProcessTimer_.stop();
431 
432  return true;
433  }
434 
443  Scalar suggestTimeStepSize(Scalar oldDt) const
444  {
445  // be aggressive reducing the time-step size but
446  // conservative when increasing it. the rationale is
447  // that we want to avoid failing in the next time
448  // integration which would be quite expensive
449  const int nit = problem().iterationContext().iteration();
450  if (lastSolveFailed_ || nit > params_.targetIterations_) {
451  const int overshoot = lastSolveFailed_ ? params_.targetIterations_ : nit - params_.targetIterations_;
452  Scalar percent = Scalar(overshoot) / params_.targetIterations_;
453  Scalar nextDt = std::max(problem().minTimeStepSize(),
454  oldDt / (Scalar{1.0} + percent));
455  return nextDt;
456  }
457 
458  Scalar percent = Scalar(params_.targetIterations_ - nit) / params_.targetIterations_;
459  Scalar nextDt = std::max(problem().minTimeStepSize(),
460  oldDt*(Scalar{1.0} + percent / Scalar{1.2}));
461  return nextDt;
462  }
463 
468  std::ostringstream& endIterMsg()
469  { return endIterMsgStream_; }
470 
475  void eraseMatrix()
476  { linearSolver_.eraseMatrix(); }
477 
481  LinearSolverBackend& linearSolver()
482  { return linearSolver_; }
483 
487  const LinearSolverBackend& linearSolver() const
488  { return linearSolver_; }
489 
490  const Timer& prePostProcessTimer() const
491  { return prePostProcessTimer_; }
492 
493  const Timer& linearizeTimer() const
494  { return linearizeTimer_; }
495 
496  const Timer& solveTimer() const
497  { return solveTimer_; }
498 
499  const Timer& updateTimer() const
500  { return updateTimer_; }
501 
502 protected:
506  bool verbose_() const
507  { return params_.verbose_ && (comm_.rank() == 0); }
508 
515  void begin_(const SolutionVector&)
516  {
517  lastSolveFailed_ = false;
518 
519  problem().resetIterationForNewTimestep();
520 
521  if (params_.writeConvergence_) {
522  convergenceWriter_.beginTimeStep();
523  }
524  }
525 
530  {
531  // start with a clean message stream
532  endIterMsgStream_.str("");
533  const auto& comm = simulator_.gridView().comm();
534  bool succeeded = true;
535  try {
536  problem().beginIteration();
537  }
538  catch (const std::exception& e) {
539  succeeded = false;
540 
541  std::cout << "rank " << simulator_.gridView().comm().rank()
542  << " caught an exception while pre-processing the problem:" << e.what()
543  << "\n" << std::flush;
544  }
545 
546  succeeded = comm.min(succeeded);
547 
548  if (!succeeded) {
549  throw NumericalProblem("pre processing of the problem failed");
550  }
551 
552  lastError_ = error_;
553  }
554 
560  { model().linearizer().linearizeDomain(); }
561 
562  void linearizeAuxiliaryEquations_()
563  {
564  model().linearizer().linearizeAuxiliaryEquations();
565  model().linearizer().finalize();
566  }
567 
568  void preSolve_(const SolutionVector&,
569  const GlobalEqVector& currentResidual)
570  {
571  const auto& constraintsMap = model().linearizer().constraintsMap();
572  lastError_ = error_;
573  Scalar newtonMaxError = params_.maxError_;
574 
575  // calculate the error as the maximum weighted tolerance of
576  // the solution's residual
577  error_ = 0;
578  for (unsigned dofIdx = 0; dofIdx < currentResidual.size(); ++dofIdx) {
579  // do not consider auxiliary DOFs for the error
580  if (dofIdx >= model().numGridDof() || model().dofTotalVolume(dofIdx) <= 0.0) {
581  continue;
582  }
583 
584  // also do not consider DOFs which are constraint
585  if (enableConstraints_()) {
586  if (constraintsMap.count(dofIdx) > 0) {
587  continue;
588  }
589  }
590 
591  const auto& r = currentResidual[dofIdx];
592  for (unsigned eqIdx = 0; eqIdx < r.size(); ++eqIdx) {
593  error_ = max(std::abs(r[eqIdx] * model().eqWeight(dofIdx, eqIdx)), error_);
594  }
595  }
596 
597  // take the other processes into account
598  error_ = comm_.max(error_);
599 
600  // make sure that the error never grows beyond the maximum
601  // allowed one
602  if (error_ > newtonMaxError) {
603  throw NumericalProblem("Newton: Error " + std::to_string(double(error_)) +
604  " is larger than maximum allowed error of " +
605  std::to_string(double(newtonMaxError)));
606  }
607  }
608 
621  void postSolve_(const SolutionVector&,
622  const GlobalEqVector&,
623  GlobalEqVector& solutionUpdate)
624  {
625  // loop over the auxiliary modules and ask them to post process the solution
626  // vector.
627  const auto& comm = simulator_.gridView().comm();
628  for (unsigned i = 0; i < simulator_.model().numAuxiliaryModules(); ++i) {
629  bool succeeded = true;
630  try {
631  simulator_.model().auxiliaryModule(i)->postSolve(solutionUpdate);
632  }
633  catch (const std::exception& e) {
634  succeeded = false;
635 
636  std::cout << "rank " << simulator_.gridView().comm().rank()
637  << " caught an exception while post processing an auxiliary module:" << e.what()
638  << "\n" << std::flush;
639  }
640 
641  succeeded = comm.min(succeeded);
642 
643  if (!succeeded) {
644  throw NumericalProblem("post processing of an auxilary equation failed");
645  }
646  }
647  }
648 
663  void update_(SolutionVector& nextSolution,
664  const SolutionVector& currentSolution,
665  const GlobalEqVector& solutionUpdate,
666  const GlobalEqVector& currentResidual)
667  {
668  const auto& constraintsMap = model().linearizer().constraintsMap();
669 
670  // first, write out the current solution to make convergence
671  // analysis possible
672  asImp_().writeConvergence_(currentSolution, solutionUpdate);
673 
674  // make sure not to swallow non-finite values at this point
675  if (!std::isfinite(solutionUpdate.one_norm())) {
676  throw NumericalProblem("Non-finite update!");
677  }
678 
679  std::size_t numGridDof = model().numGridDof();
680  for (unsigned dofIdx = 0; dofIdx < numGridDof; ++dofIdx) {
681  if (enableConstraints_()) {
682  if (constraintsMap.count(dofIdx) > 0) {
683  const auto& constraints = constraintsMap.at(dofIdx);
684  asImp_().updateConstraintDof_(dofIdx,
685  nextSolution[dofIdx],
686  constraints);
687  }
688  else {
689  asImp_().updatePrimaryVariables_(dofIdx,
690  nextSolution[dofIdx],
691  currentSolution[dofIdx],
692  solutionUpdate[dofIdx],
693  currentResidual[dofIdx]);
694  }
695  }
696  else {
697  asImp_().updatePrimaryVariables_(dofIdx,
698  nextSolution[dofIdx],
699  currentSolution[dofIdx],
700  solutionUpdate[dofIdx],
701  currentResidual[dofIdx]);
702  }
703  }
704 
705  // update the DOFs of the auxiliary equations
706  std::size_t numDof = model().numTotalDof();
707  for (std::size_t dofIdx = numGridDof; dofIdx < numDof; ++dofIdx) {
708  nextSolution[dofIdx] = currentSolution[dofIdx];
709  nextSolution[dofIdx] -= solutionUpdate[dofIdx];
710  }
711  }
712 
716  void updateConstraintDof_(unsigned,
717  PrimaryVariables& nextValue,
718  const Constraints& constraints)
719  { nextValue = constraints; }
720 
724  void updatePrimaryVariables_(unsigned,
725  PrimaryVariables& nextValue,
726  const PrimaryVariables& currentValue,
727  const EqVector& update,
728  const EqVector&)
729  {
730  nextValue = currentValue;
731  nextValue -= update;
732  }
733 
740  void writeConvergence_(const SolutionVector& currentSolution,
741  const GlobalEqVector& solutionUpdate)
742  {
743  if (params_.writeConvergence_) {
744  convergenceWriter_.beginIteration();
745  convergenceWriter_.writeFields(currentSolution, solutionUpdate);
746  convergenceWriter_.endIteration();
747  }
748  }
749 
756  void endIteration_(const SolutionVector&,
757  const SolutionVector&)
758  {
759  problem().advanceIteration();
760 
761  const auto& comm = simulator_.gridView().comm();
762  bool succeeded = true;
763  try {
764  problem().endIteration();
765  }
766  catch (const std::exception& e) {
767  succeeded = false;
768 
769  std::cout << "rank " << simulator_.gridView().comm().rank()
770  << " caught an exception while letting the problem post-process:" << e.what()
771  << "\n" << std::flush;
772  }
773 
774  succeeded = comm.min(succeeded);
775 
776  if (!succeeded) {
777  throw NumericalProblem("post processing of the problem failed");
778  }
779 
780  if (asImp_().verbose_()) {
781  std::cout << "Newton iteration " << problem().iterationContext().iteration() << ""
782  << " error: " << error_
783  << endIterMsg().str() << "\n" << std::flush;
784  }
785  }
786 
790  bool proceed_() const
791  {
792  if (problem().iterationContext().iteration() < 1) {
793  return true; // we always do at least one full iteration
794  }
795  else if (asImp_().converged()) {
796  // we are below the specified tolerance, so we don't have to
797  // do more iterations
798  return false;
799  }
800  else if (problem().iterationContext().iteration() >= params_.maxIterations_) {
801  // we have exceeded the allowed number of steps. If the
802  // error was reduced by a factor of at least 4,
803  // in the last iterations we proceed even if we are above
804  // the maximum number of steps
805  return error_ * 4.0 < lastError_;
806  }
807 
808  return true;
809  }
810 
815  void end_()
816  {
817  if (params_.writeConvergence_) {
818  convergenceWriter_.endTimeStep();
819  }
820  }
821 
827  void failed_()
828  { lastSolveFailed_ = true; }
829 
835  void succeeded_()
836  {}
837 
838  static bool enableConstraints_()
839  { return getPropValue<TypeTag, Properties::EnableConstraints>(); }
840 
841  Simulator& simulator_;
842 
843  Timer prePostProcessTimer_;
844  Timer linearizeTimer_;
845  Timer solveTimer_;
846  Timer updateTimer_;
847 
848  std::ostringstream endIterMsgStream_;
849 
850  Scalar error_;
851  Scalar lastError_;
852  NewtonMethodParams<Scalar> params_;
853 
854  // Flags that the last solve failed, triggering a timestep reduction.
855  bool lastSolveFailed_ = false;
856  // the linear solver
857  LinearSolverBackend linearSolver_;
858 
859  // the collective communication used by the simulation (i.e. fake
860  // or MPI)
861  CollectiveCommunication comm_;
862 
863  // the object which writes the convergence behaviour of the Newton
864  // method to disk
865  ConvergenceWriter convergenceWriter_;
866 
867 private:
868  Implementation& asImp_()
869  { return *static_cast<Implementation *>(this); }
870 
871  const Implementation& asImp_() const
872  { return *static_cast<const Implementation *>(this); }
873 };
874 
875 } // namespace Opm
876 
877 #endif
void beginIteration_()
Indicates the beginning of a Newton iteration.
Definition: newtonmethod.hh:529
void succeeded_()
Called if the Newton method was successful.
Definition: newtonmethod.hh:835
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: newtonmethod.hh:724
A convergence writer for the Newton method which does nothing.
Definition: nullconvergencewriter.hh:50
void failed_()
Called if the Newton method broke down.
Definition: newtonmethod.hh:827
bool verbose_() const
Returns true if the Newton method ought to be chatty.
Definition: newtonmethod.hh:506
The multi-dimensional Newton method.
Definition: newtonmethod.hh:64
static void registerParameters()
Register all run-time parameters for the Newton method.
Definition: newtonmethod.hh:135
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:233
Specifies the type of the actual Newton method.
Definition: fvbaseproblem.hh:54
const Problem & problem() const
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:166
LinearSolverBackend & linearSolver()
Returns the linear solver backend object for external use.
Definition: newtonmethod.hh:481
void start()
Start counting the time resources used by the simulation.
Definition: timer.cpp:46
void end_()
Indicates that we&#39;re done solving the non-linear system of equations.
Definition: newtonmethod.hh:815
Definition: fvbaseprimaryvariables.hh:161
void endIteration_(const SolutionVector &, const SolutionVector &)
Indicates that one Newton iteration was finished.
Definition: newtonmethod.hh:756
Problem & problem()
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:160
Model & model()
Returns a reference to the numeric model.
Definition: newtonmethod.hh:172
The type tag on which the default properties for the Newton method are attached.
Definition: newtonmethod.hh:74
void begin_(const SolutionVector &)
Called before the Newton method is applied to an non-linear system of equations.
Definition: newtonmethod.hh:515
const LinearSolverBackend & linearSolver() const
Returns the linear solver backend object for external use.
Definition: newtonmethod.hh:487
Scalar suggestTimeStepSize(Scalar oldDt) const
Suggest a new time-step size based on the old time-step size.
Definition: newtonmethod.hh:443
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
static void registerParameters()
Registers the parameters in parameter system.
Definition: newtonmethodparams.cpp:36
Declare the properties used by the infrastructure code of the finite volume discretizations.
A convergence writer for the Newton method which does nothing.
void updateConstraintDof_(unsigned, PrimaryVariables &nextValue, const Constraints &constraints)
Update the primary variables for a degree of freedom which is constraint.
Definition: newtonmethod.hh:716
bool apply()
Run the Newton method.
Definition: newtonmethod.hh:216
Specifies the type of the class which writes out the Newton convergence.
Definition: newtonmethodproperties.hh:40
void linearizeDomain_()
Linearize the global non-linear system of equations associated with the spatial domain.
Definition: newtonmethod.hh:559
Scalar tolerance() const
Return the current tolerance at which the Newton method considers itself to be converged.
Definition: newtonmethod.hh:185
double realTimeElapsed() const
Return the real time [s] elapsed during the periods the timer was active since the last reset...
Definition: timer.cpp:90
void setTolerance(Scalar value)
Set the current tolerance at which the Newton method considers itself to be converged.
Definition: newtonmethod.hh:192
void writeConvergence_(const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate)
Write the convergence behaviour of the newton method to disk.
Definition: newtonmethod.hh:740
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.hpp:45
bool converged() const
Returns true if the error of the solution is below the tolerance.
Definition: newtonmethod.hh:154
void applyUpdate(SolutionVector &nextSolution, const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate, const GlobalEqVector &currentResidual)
Public wrapper for applying a Newton update to a solution vector.
Definition: newtonmethod.hh:202
bool proceed_() const
Returns true iff another Newton iteration should be done.
Definition: newtonmethod.hh:790
const Model & model() const
Returns a reference to the numeric model.
Definition: newtonmethod.hh:178
Provides an encapsulation to measure the system time.
void update_(SolutionVector &nextSolution, const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate, const GlobalEqVector &currentResidual)
Update the current solution with a delta vector.
Definition: newtonmethod.hh:663
void eraseMatrix()
Causes the solve() method to discared the structure of the linear system of equations the next time i...
Definition: newtonmethod.hh:475
std::ostringstream & endIterMsg()
Message that should be printed for the user after the end of an iteration.
Definition: newtonmethod.hh:468
void finishInit()
Finialize the construction of the object.
Definition: newtonmethod.hh:147
A simple class which makes sure that a timer gets stopped if an exception is thrown.
void postSolve_(const SolutionVector &, const GlobalEqVector &, GlobalEqVector &solutionUpdate)
Update the error of the solution given the previous iteration.
Definition: newtonmethod.hh:621
void halt()
Stop the measurement reset all timing values.
Definition: timer.cpp:75
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
double stop()
Stop counting the time resources.
Definition: timer.cpp:52
Definition: blackoilmodel.hh:75
Declares the properties required by the black oil model.