version 3.10-dev
Dumux::RichardsNewtonSolver< Assembler, LinearSolver, Reassembler, Comm > Class Template Reference

A Richards model specific Newton solver. More...

#include <dumux/porousmediumflow/richards/newtonsolver.hh>

Inheritance diagram for Dumux::RichardsNewtonSolver< Assembler, LinearSolver, Reassembler, Comm >:

Description

template<class Assembler, class LinearSolver, class Reassembler = PartialReassembler<Assembler>, class Comm = Dune::Communication<Dune::MPIHelper::MPICommunicator>>
class Dumux::RichardsNewtonSolver< Assembler, LinearSolver, Reassembler, Comm >

This solver 'knows' what a 'physically meaningful' solution is and can thus do update smarter than the plain Newton solver.

Public Types

using Communication = Dune::Communication< Dune::MPIHelper::MPICommunicator >
 
using Assembler = Assembler
 export the assembler and linear solver types More...
 
using LinearSolver = LinearSolver
 
using Variables = Detail::PDESolver::AssemblerVariables< Assembler >
 export the type of variables that represent a numerical solution More...
 

Public Member Functions

const Communicationcomm () const
 the communicator for parallel runs More...
 
void setMaxRelativeShift (Scalar tolerance)
 Set the maximum acceptable difference of any primary variable between two iterations for declaring convergence. More...
 
void setMaxAbsoluteResidual (Scalar tolerance)
 Set the maximum acceptable absolute residual for declaring convergence. More...
 
void setResidualReduction (Scalar tolerance)
 Set the maximum acceptable residual norm reduction. More...
 
void setTargetSteps (int targetSteps)
 Set the number of iterations at which the Newton method should aim at. More...
 
void setMinSteps (int minSteps)
 Set the number of minimum iterations for the Newton method. More...
 
void setMaxSteps (int maxSteps)
 Set the number of iterations after which the Newton method gives up. More...
 
void solve (Variables &vars, TimeLoop &timeLoop) override
 Run the Newton method to solve a non-linear system. Does time step control when the Newton fails to converge. More...
 
void solve (Variables &vars) override
 Run the Newton method to solve a non-linear system. The solver is responsible for all the strategic decisions. More...
 
bool apply (Variables &vars) override
 Run the Newton method to solve a non-linear system. The solver is responsible for all the strategic decisions. More...
 
virtual void newtonBegin (Variables &initVars)
 Called before the Newton method is applied to an non-linear system of equations. More...
 
virtual bool newtonProceed (const Variables &varsCurrentIter, bool converged)
 Returns true if another iteration should be done. More...
 
virtual void newtonBeginStep (const Variables &vars)
 Indicates the beginning of a Newton iteration. More...
 
virtual void assembleLinearSystem (const Variables &vars)
 Assemble the linear system of equations \(\mathbf{A}x - b = 0\). More...
 
void solveLinearSystem (ResidualVector &deltaU)
 Solve the linear system of equations \(\mathbf{A}x - b = 0\). More...
 
void newtonUpdate (Variables &vars, const SolutionVector &uLastIter, const ResidualVector &deltaU)
 Update the current solution with a delta vector. More...
 
virtual void newtonEndStep (Variables &vars, const SolutionVector &uLastIter)
 Indicates that one Newton iteration was finished. More...
 
virtual void newtonEnd ()
 Called if the Newton method ended (not known yet if we failed or succeeded) More...
 
virtual bool newtonConverged () const
 Returns true if the error of the solution is below the tolerance. More...
 
virtual void newtonFail (Variables &u)
 Called if the Newton method broke down. This method is called after newtonEnd() More...
 
virtual void newtonSucceed ()
 Called if the Newton method ended successfully This method is called after newtonEnd() More...
 
void report (std::ostream &sout=std::cout) const
 output statistics / report More...
 
void resetReport ()
 reset the statistics More...
 
void reportParams (std::ostream &sout=std::cout) const
 Report the options and parameters this Newton is configured with. More...
 
Scalar suggestTimeStepSize (Scalar oldTimeStep) const
 Suggest a new time-step size based on the old time-step size. More...
 
void setVerbosity (int val)
 Specify the verbosity level. More...
 
int verbosity () const
 Return the verbosity level. More...
 
void setUseLineSearch (bool val=true)
 Specify whether line search is enabled or not. More...
 
bool useLineSearch () const
 Return whether line search is enabled or not. More...
 
const std::string & paramGroup () const
 Returns the parameter group. More...
 
void attachConvergenceWriter (std::shared_ptr< ConvergenceWriter > convWriter)
 Attach a convergence writer to write out intermediate results after each iteration. More...
 
void detachConvergenceWriter ()
 Detach the convergence writer to stop the output. More...
 
Scalar retryTimeStepReductionFactor () const
 Return the factor for reducing the time step after a Newton iteration has failed. More...
 
void setRetryTimeStepReductionFactor (const Scalar factor)
 Set the factor for reducing the time step after a Newton iteration has failed. More...
 
const Assemblerassembler () const
 Access the assembler. More...
 
Assemblerassembler ()
 Access the assembler. More...
 
const LinearSolverlinearSolver () const
 Access the linear solver. More...
 

Protected Types

using LinearAlgebraNativeBackend = VariablesBackend< ResidualVector >
 

Protected Member Functions

virtual void solutionChanged_ (Variables &vars, const SolutionVector &uCurrentIter)
 Update solution-dependent quantities like grid variables after the solution has changed. More...
 
void computeResidualReduction_ (const Variables &vars)
 
bool enableResidualCriterion () const
 
LinearSolverlinearSolver ()
 Access the linear solver. More...
 
bool checkSizesOfSubMatrices (const Dune::MultiTypeBlockMatrix< FirstRow, Args... > &matrix) const
 Helper function to assure the MultiTypeBlockMatrix's sub-blocks have the correct sizes. More...
 
bool checkSizesOfSubMatrices (const M &) const
 Default implementation for any matrix type. More...
 

Protected Attributes

int targetSteps_
 optimal number of iterations we want to achieve More...
 
int minSteps_
 minimum number of iterations we do More...
 
int maxSteps_
 maximum number of iterations we do before giving up More...
 
int numSteps_
 actual number of steps done so far More...
 
Scalar reduction_
 
Scalar residualNorm_
 
Scalar lastReduction_
 
Scalar initialResidual_
 
Scalar shift_
 
Scalar lastShift_
 
std::ostringstream endIterMsgStream_
 message stream to be displayed at the end of iterations More...
 

Member Typedef Documentation

◆ Assembler

using Dumux::PDESolver< Assembler , LinearSolver >::Assembler = Assembler
inherited

◆ Communication

using Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::Communication = Dune::Communication< Dune::MPIHelper::MPICommunicator >
inherited

◆ LinearAlgebraNativeBackend

using Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::LinearAlgebraNativeBackend = VariablesBackend<ResidualVector>
protectedinherited

◆ LinearSolver

using Dumux::PDESolver< Assembler , LinearSolver >::LinearSolver = LinearSolver
inherited

◆ Variables

Member Function Documentation

◆ apply()

bool Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::apply ( Variables vars)
inlineoverridevirtualinherited
Parameters
varsThe variables object representing the current state of the numerical solution (primary and possibly secondary variables).
Postcondition
If converged, the Variables will represent the solution. If convergence fails, they are in some intermediate, undefined state.

Implements Dumux::PDESolver< Assembler, LinearSolver >.

◆ assembleLinearSystem()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::assembleLinearSystem ( const Variables vars)
inlinevirtualinherited
Parameters
varsThe current iteration's variables

◆ assembler() [1/2]

Assembler & Dumux::PDESolver< Assembler , LinearSolver >::assembler ( )
inlineinherited

◆ assembler() [2/2]

const Assembler & Dumux::PDESolver< Assembler , LinearSolver >::assembler ( ) const
inlineinherited

◆ attachConvergenceWriter()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::attachConvergenceWriter ( std::shared_ptr< ConvergenceWriter convWriter)
inlineinherited

◆ checkSizesOfSubMatrices() [1/2]

bool Dumux::PDESolver< Assembler , LinearSolver >::checkSizesOfSubMatrices ( const Dune::MultiTypeBlockMatrix< FirstRow, Args... > &  matrix) const
inlineprotectedinherited

◆ checkSizesOfSubMatrices() [2/2]

bool Dumux::PDESolver< Assembler , LinearSolver >::checkSizesOfSubMatrices ( const M &  ) const
inlineprotectedinherited

◆ comm()

const Communication & Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::comm ( ) const
inlineinherited

◆ computeResidualReduction_()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::computeResidualReduction_ ( const Variables vars)
inlineprotectedinherited

◆ detachConvergenceWriter()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::detachConvergenceWriter ( )
inlineinherited

◆ enableResidualCriterion()

bool Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::enableResidualCriterion ( ) const
inlineprotectedinherited

◆ linearSolver() [1/2]

LinearSolver & Dumux::PDESolver< Assembler , LinearSolver >::linearSolver ( )
inlineprotectedinherited

◆ linearSolver() [2/2]

const LinearSolver & Dumux::PDESolver< Assembler , LinearSolver >::linearSolver ( ) const
inlineinherited

◆ newtonBegin()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonBegin ( Variables initVars)
inlinevirtualinherited
Parameters
initVarsThe variables representing the initial solution

◆ newtonBeginStep()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonBeginStep ( const Variables vars)
inlinevirtualinherited

◆ newtonConverged()

virtual bool Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonConverged ( ) const
inlinevirtualinherited

◆ newtonEnd()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonEnd ( )
inlinevirtualinherited

◆ newtonEndStep()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonEndStep ( Variables vars,
const SolutionVector uLastIter 
)
inlinevirtualinherited
Parameters
varsThe variables after the current Newton iteration
uLastIterThe solution at the beginning of the current Newton iteration

◆ newtonFail()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonFail ( Variables u)
inlinevirtualinherited

◆ newtonProceed()

virtual bool Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonProceed ( const Variables varsCurrentIter,
bool  converged 
)
inlinevirtualinherited
Parameters
varsCurrentIterThe variables of the current Newton iteration
convergedif the Newton method's convergence criterion was met in this step

◆ newtonSucceed()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonSucceed ( )
inlinevirtualinherited

◆ newtonUpdate()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::newtonUpdate ( Variables vars,
const SolutionVector uLastIter,
const ResidualVector deltaU 
)
inlineinherited

The error estimates required for the newtonConverged() and newtonProceed() methods should be updated inside this method.

Different update strategies, such as line search and chopped updates can be implemented. The default behavior is just to subtract deltaU from uLastIter, i.e.

\[ u^{k+1} = u^k - \Delta u^k \]

Parameters
varsThe variables after the current iteration
uLastIterThe solution vector after the last iteration
deltaUThe delta as calculated from solving the linear system of equations. This parameter also stores the updated solution.

◆ paramGroup()

const std::string & Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::paramGroup ( ) const
inlineinherited

◆ report()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::report ( std::ostream &  sout = std::cout) const
inlineinherited

◆ reportParams()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::reportParams ( std::ostream &  sout = std::cout) const
inlineinherited

◆ resetReport()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::resetReport ( )
inlineinherited

◆ retryTimeStepReductionFactor()

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::retryTimeStepReductionFactor ( ) const
inlineinherited

◆ setMaxAbsoluteResidual()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setMaxAbsoluteResidual ( Scalar  tolerance)
inlineinherited
Parameters
toleranceThe maximum absolute residual at which the scheme is considered finished

◆ setMaxRelativeShift()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setMaxRelativeShift ( Scalar  tolerance)
inlineinherited
Parameters
toleranceThe maximum relative shift between two Newton iterations at which the scheme is considered finished

◆ setMaxSteps()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setMaxSteps ( int  maxSteps)
inlineinherited
Parameters
maxStepsNumber of iterations after we give up

◆ setMinSteps()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setMinSteps ( int  minSteps)
inlineinherited
Parameters
minStepsMinimum number of iterations

◆ setResidualReduction()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setResidualReduction ( Scalar  tolerance)
inlineinherited
Parameters
toleranceThe maximum reduction of the residual norm at which the scheme is considered finished

◆ setRetryTimeStepReductionFactor()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setRetryTimeStepReductionFactor ( const Scalar  factor)
inlineinherited

◆ setTargetSteps()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setTargetSteps ( int  targetSteps)
inlineinherited

This is used to control the time-step size. The heuristic used is to scale the last time-step size by the deviation of the number of iterations used from the target steps.

Parameters
targetStepsNumber of iterations which are considered "optimal"

◆ setUseLineSearch()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setUseLineSearch ( bool  val = true)
inlineinherited

◆ setVerbosity()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::setVerbosity ( int  val)
inlineinherited

◆ solutionChanged_()

virtual void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::solutionChanged_ ( Variables vars,
const SolutionVector uCurrentIter 
)
inlineprotectedvirtualinherited

◆ solve() [1/2]

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::solve ( Variables vars)
inlineoverridevirtualinherited
Parameters
varsThe variables object representing the current state of the numerical solution (primary and possibly secondary variables).

Implements Dumux::PDESolver< Assembler, LinearSolver >.

◆ solve() [2/2]

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::solve ( Variables vars,
TimeLoop timeLoop 
)
inlineoverridevirtualinherited
Parameters
varsThe variables object representing the current state of the numerical solution (primary and possibly secondary variables).
timeLoopThe time loop.

Reimplemented from Dumux::PDESolver< Assembler, LinearSolver >.

◆ solveLinearSystem()

void Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::solveLinearSystem ( ResidualVector deltaU)
inlineinherited

Throws Dumux::NumericalProblem if the linear solver didn't converge.

If the linear solver doesn't accept multitype matrices we copy the matrix into a 1x1 block BCRS matrix for solving.

Parameters
deltaUThe difference between the current and the next solution

◆ suggestTimeStepSize()

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::suggestTimeStepSize ( Scalar  oldTimeStep) const
inlineinherited

The default behavior is to suggest the old time-step size scaled by the ratio between the target iterations and the iterations required to actually solve the last time-step.

◆ useLineSearch()

bool Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::useLineSearch ( ) const
inlineinherited

◆ verbosity()

int Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::verbosity ( ) const
inlineinherited

Member Data Documentation

◆ endIterMsgStream_

std::ostringstream Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::endIterMsgStream_
protectedinherited

◆ initialResidual_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::initialResidual_
protectedinherited

◆ lastReduction_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::lastReduction_
protectedinherited

◆ lastShift_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::lastShift_
protectedinherited

◆ maxSteps_

int Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::maxSteps_
protectedinherited

◆ minSteps_

int Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::minSteps_
protectedinherited

◆ numSteps_

int Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::numSteps_
protectedinherited

◆ reduction_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::reduction_
protectedinherited

◆ residualNorm_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::residualNorm_
protectedinherited

◆ shift_

Scalar Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::shift_
protectedinherited

◆ targetSteps_

int Dumux::NewtonSolver< Assembler, LinearSolver, PartialReassembler< Assembler > , Dune::Communication< Dune::MPIHelper::MPICommunicator > >::targetSteps_
protectedinherited

The documentation for this class was generated from the following file: