A Newton method for models using a finite volume discretization. More...

#include <fvbasenewtonmethod.hh>

Inheritance diagram for Ewoms::FvBaseNewtonMethod< TypeTag >:
Inheritance graph

Public Member Functions

 FvBaseNewtonMethod (Simulator &simulator)
 
bool converged () const
 Returns true if the error of the solution is below the tolerance. More...
 
Problem & problem ()
 Returns a reference to the object describing the current physical problem. More...
 
const Problem & problem () const
 Returns a reference to the object describing the current physical problem. More...
 
Model & model ()
 Returns a reference to the numeric model. More...
 
const Model & model () const
 Returns a reference to the numeric model. More...
 
int numIterations () const
 Returns the number of iterations done since the Newton method was invoked. More...
 
Scalar tolerance () const
 Return the current tolerance at which the Newton method considers itself to be converged. More...
 
void setTolerance (Scalar value)
 Set the current tolerance at which the Newton method considers itself to be converged. More...
 
bool apply ()
 Run the Newton method. More...
 
Scalar linearizeTime () const
 Returns the wall time spend so far for linearizing the non-linear system for all iterations of the current time step. More...
 
Scalar solveTime () const
 Returns the wall time spend so far for solving the linear systems for all iterations of the current time step. More...
 
Scalar updateTime () const
 Returns the wall time spend so far for updating the iterative solutions of the non-linear system for all iterations of the current time step. More...
 
Scalar suggestTimeStepSize (Scalar oldTimeStep) const
 Suggest a new time-step size based on the old time-step size. More...
 
std::ostringstream & endIterMsg ()
 Message that should be printed for the user after the end of an iteration. More...
 

Static Public Member Functions

static void registerParameters ()
 Register all run-time parameters for the Newton method. More...
 

Protected Member Functions

void update_ (SolutionVector &nextSolution, const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate, const GlobalEqVector &currentResidual)
 Update the current solution with a delta vector. More...
 
void beginIteration_ ()
 Indicates the beginning of a Newton iteration. More...
 
void failed_ ()
 Called if the Newton method broke down. More...
 
void succeeded_ ()
 Called when the Newton method was successful. More...
 
Model & model_ ()
 Returns a reference to the model. More...
 
const Model & model_ () const
 Returns a reference to the model. More...
 
bool verbose_ () const
 Returns true if the Newton method ought to be chatty. More...
 
void begin_ (const SolutionVector &u)
 Called before the Newton method is applied to an non-linear system of equations. More...
 
void linearize_ ()
 Linearize the global non-linear system of equations. More...
 
bool solveLinear_ (const JacobianMatrix &A, GlobalEqVector &x, GlobalEqVector &b)
 Solve the linear system of equations $\mathbf{A}x - b = 0$. More...
 
void updateError_ (const SolutionVector &nextSolution, const SolutionVector &currentSolution, const GlobalEqVector &currentResidual, const GlobalEqVector &solutionUpdate)
 Update the error of the solution given the previous iteration. More...
 
void updatePrimaryVariables_ (int globalDofIdx, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &currentResidual)
 Update a single primary variables object. More...
 
void writeConvergence_ (const SolutionVector &currentSolution, const GlobalEqVector &solutionUpdate)
 Write the convergence behaviour of the newton method to disk. More...
 
void endIteration_ (const SolutionVector &nextSolution, const SolutionVector &currentSolution)
 Indicates that one Newton iteration was finished. More...
 
bool proceed_ () const
 Returns true iff another Newton iteration should be done. More...
 
void end_ ()
 Indicates that we're done solving the non-linear system of equations. More...
 
int targetIterations_ () const
 
int maxIterations_ () const
 

Protected Attributes

Simulatorsimulator_
 
Ewoms::Timer linearizeTimer_
 
Ewoms::Timer solveTimer_
 
Ewoms::Timer updateTimer_
 
Scalar linearizeTime_
 
Scalar solveTime_
 
Scalar updateTime_
 
std::ostringstream endIterMsgStream_
 
Scalar error_
 
Scalar lastError_
 
Scalar tolerance_
 
int numIterations_
 
LinearSolverBackend linearSolver_
 
CollectiveCommunication comm_
 
ConvergenceWriter convergenceWriter_
 

Friends

class Ewoms::NewtonMethod< TypeTag >
 

Detailed Description

template<class TypeTag>
class Ewoms::FvBaseNewtonMethod< TypeTag >

A Newton method for models using a finite volume discretization.

This class is sufficient for most models which use an Element or a Vertex Centered Finite Volume discretization.

Constructor & Destructor Documentation

template<class TypeTag >
Ewoms::FvBaseNewtonMethod< TypeTag >::FvBaseNewtonMethod ( Simulator simulator)
inline

Member Function Documentation

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::begin_ ( const SolutionVector &  u)
inlineprotectedinherited

Called before the Newton method is applied to an non-linear system of equations.

Parameters
uThe initial solution

References Ewoms::NewtonMethod< TypeTag >::convergenceWriter_, EWOMS_GET_PARAM, and Ewoms::NewtonMethod< TypeTag >::numIterations_.

template<class TypeTag >
void Ewoms::FvBaseNewtonMethod< TypeTag >::beginIteration_ ( )
inlineprotected

Indicates the beginning of a Newton iteration.

References Ewoms::NewtonMethod< TypeTag >::beginIteration_(), and Ewoms::FvBaseNewtonMethod< TypeTag >::model_().

template<class TypeTag >
bool Ewoms::NewtonMethod< TypeTag >::converged ( ) const
inlineinherited

Returns true if the error of the solution is below the tolerance.

References Ewoms::NewtonMethod< TypeTag >::error_, and Ewoms::NewtonMethod< TypeTag >::tolerance().

Referenced by Ewoms::NewtonMethod< TypeTag >::apply(), and Ewoms::NewtonMethod< TypeTag >::proceed_().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::end_ ( )
inlineprotectedinherited

Indicates that we're done solving the non-linear system of equations.

References Ewoms::NewtonMethod< TypeTag >::convergenceWriter_, and EWOMS_GET_PARAM.

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::endIteration_ ( const SolutionVector &  nextSolution,
const SolutionVector &  currentSolution 
)
inlineprotectedinherited

Indicates that one Newton iteration was finished.

Parameters
nextSolutionThe solution after the current Newton iteration
currentSolutionThe solution at the beginning of the current Newton iteration

References Ewoms::NewtonMethod< TypeTag >::endIterMsg(), Ewoms::NewtonMethod< TypeTag >::endIterMsgStream_, Ewoms::NewtonMethod< TypeTag >::error_, Ewoms::NewtonMethod< TypeTag >::numIterations_, Ewoms::NewtonMethod< TypeTag >::problem(), and Ewoms::NewtonMethod< TypeTag >::verbose_().

template<class TypeTag >
std::ostringstream& Ewoms::NewtonMethod< TypeTag >::endIterMsg ( )
inlineinherited

Message that should be printed for the user after the end of an iteration.

References Ewoms::NewtonMethod< TypeTag >::endIterMsgStream_.

Referenced by Ewoms::NewtonMethod< TypeTag >::endIteration_().

template<class TypeTag >
void Ewoms::FvBaseNewtonMethod< TypeTag >::failed_ ( )
inlineprotected

Called if the Newton method broke down.

References Ewoms::NewtonMethod< TypeTag >::failed_(), and Ewoms::FvBaseNewtonMethod< TypeTag >::model_().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::linearize_ ( )
inlineprotectedinherited

Linearize the global non-linear system of equations.

References Ewoms::NewtonMethod< TypeTag >::model().

template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::linearizeTime ( ) const
inlineinherited

Returns the wall time spend so far for linearizing the non-linear system for all iterations of the current time step.

References Ewoms::NewtonMethod< TypeTag >::linearizeTime_.

Referenced by Ewoms::FvBaseProblem< TypeTag >::timeIntegration().

template<class TypeTag >
int Ewoms::NewtonMethod< TypeTag >::maxIterations_ ( ) const
inlineprotectedinherited
template<class TypeTag >
const Model& Ewoms::NewtonMethod< TypeTag >::model ( ) const
inlineinherited

Returns a reference to the numeric model.

References Ewoms::Simulator< TypeTag >::model(), and Ewoms::NewtonMethod< TypeTag >::simulator_.

template<class TypeTag >
Model& Ewoms::FvBaseNewtonMethod< TypeTag >::model_ ( )
inlineprotected
template<class TypeTag >
const Model& Ewoms::FvBaseNewtonMethod< TypeTag >::model_ ( ) const
inlineprotected

Returns a reference to the model.

References Ewoms::NewtonMethod< TypeTag >::model().

template<class TypeTag >
int Ewoms::NewtonMethod< TypeTag >::numIterations ( ) const
inlineinherited

Returns the number of iterations done since the Newton method was invoked.

References Ewoms::NewtonMethod< TypeTag >::numIterations_.

Referenced by Ewoms::NewtonMethod< TypeTag >::proceed_().

template<class TypeTag >
const Problem& Ewoms::NewtonMethod< TypeTag >::problem ( ) const
inlineinherited

Returns a reference to the object describing the current physical problem.

References Ewoms::Simulator< TypeTag >::problem(), and Ewoms::NewtonMethod< TypeTag >::simulator_.

template<class TypeTag >
bool Ewoms::NewtonMethod< TypeTag >::proceed_ ( ) const
inlineprotectedinherited
template<class TypeTag >
static void Ewoms::NewtonMethod< TypeTag >::registerParameters ( )
inlinestaticinherited

Register all run-time parameters for the Newton method.

References EWOMS_REGISTER_PARAM.

Referenced by Ewoms::FvBaseDiscretization< TypeTag >::registerParameters().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::setTolerance ( Scalar  value)
inlineinherited

Set the current tolerance at which the Newton method considers itself to be converged.

References Ewoms::NewtonMethod< TypeTag >::tolerance_.

template<class TypeTag >
bool Ewoms::NewtonMethod< TypeTag >::solveLinear_ ( const JacobianMatrix &  A,
GlobalEqVector &  x,
GlobalEqVector &  b 
)
inlineprotectedinherited

Solve the linear system of equations $\mathbf{A}x - b = 0$.

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

Parameters
AThe matrix of the linear system of equations
xThe vector which solves the linear system
bThe right hand side of the linear system

References Ewoms::NewtonMethod< TypeTag >::linearSolver_.

template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::solveTime ( ) const
inlineinherited

Returns the wall time spend so far for solving the linear systems for all iterations of the current time step.

References Ewoms::NewtonMethod< TypeTag >::solveTime_.

Referenced by Ewoms::FvBaseProblem< TypeTag >::timeIntegration().

template<class TypeTag >
void Ewoms::FvBaseNewtonMethod< TypeTag >::succeeded_ ( )
inlineprotected

Called when the Newton method was successful.

References Ewoms::FvBaseNewtonMethod< TypeTag >::model_(), and Ewoms::NewtonMethod< TypeTag >::succeeded_().

template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::suggestTimeStepSize ( Scalar  oldTimeStep) const
inlineinherited

Suggest a new time-step size based on the old time-step size.

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.

References Ewoms::NewtonMethod< TypeTag >::numIterations_, and Ewoms::NewtonMethod< TypeTag >::targetIterations_().

template<class TypeTag >
int Ewoms::NewtonMethod< TypeTag >::targetIterations_ ( ) const
inlineprotectedinherited
template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::tolerance ( ) const
inlineinherited

Return the current tolerance at which the Newton method considers itself to be converged.

References Ewoms::NewtonMethod< TypeTag >::tolerance_.

Referenced by Ewoms::NewtonMethod< TypeTag >::converged().

template<class TypeTag >
void Ewoms::FvBaseNewtonMethod< TypeTag >::update_ ( SolutionVector &  nextSolution,
const SolutionVector &  currentSolution,
const GlobalEqVector &  solutionUpdate,
const GlobalEqVector &  currentResidual 
)
inlineprotected

Update the current solution with a delta vector.

The error estimates required for the converged() and proceed() 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
nextSolutionThe solution vector at the end of the current iteration
currentSolutionThe solution vector at the beginning of the current iteration
solutionUpdateThe delta as calculated by solving the linear system of equations. This parameter also stores the updated solution.
currentResidualThe residual (i.e., right-hand-side) of the current solution.

References Ewoms::NewtonMethod< TypeTag >::model(), and Ewoms::NewtonMethod< TypeTag >::writeConvergence_().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::updateError_ ( const SolutionVector &  nextSolution,
const SolutionVector &  currentSolution,
const GlobalEqVector &  currentResidual,
const GlobalEqVector &  solutionUpdate 
)
inlineprotectedinherited

Update the error of the solution given the previous iteration.

For our purposes, the error of a solution is defined as the maximum of the weighted residual of a given solution.

Parameters
nextSolutionThe solution after the current iteration
currentSolutionThe solution at the beginning the current iteration
currentResidualThe residual (i.e., right-hand-side) of the current iteration's solution.
solutionUpdateThe difference between the current and the next solution

References Ewoms::NewtonMethod< TypeTag >::comm_, Ewoms::NewtonMethod< TypeTag >::error_, EWOMS_GET_PARAM, Ewoms::NewtonMethod< TypeTag >::lastError_, and Ewoms::NewtonMethod< TypeTag >::model().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::updatePrimaryVariables_ ( int  globalDofIdx,
PrimaryVariables &  nextValue,
const PrimaryVariables &  currentValue,
const EqVector &  update,
const EqVector &  currentResidual 
)
inlineprotectedinherited

Update a single primary variables object.

template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::updateTime ( ) const
inlineinherited

Returns the wall time spend so far for updating the iterative solutions of the non-linear system for all iterations of the current time step.

References Ewoms::NewtonMethod< TypeTag >::updateTime_.

Referenced by Ewoms::FvBaseProblem< TypeTag >::timeIntegration().

template<class TypeTag >
bool Ewoms::NewtonMethod< TypeTag >::verbose_ ( ) const
inlineprotectedinherited

Returns true if the Newton method ought to be chatty.

References Ewoms::NewtonMethod< TypeTag >::comm_, and EWOMS_GET_PARAM.

Referenced by Ewoms::NewtonMethod< TypeTag >::apply(), and Ewoms::NewtonMethod< TypeTag >::endIteration_().

template<class TypeTag >
void Ewoms::NewtonMethod< TypeTag >::writeConvergence_ ( const SolutionVector &  currentSolution,
const GlobalEqVector &  solutionUpdate 
)
inlineprotectedinherited

Write the convergence behaviour of the newton method to disk.

This method is called as part of the update proceedure.

References Ewoms::NewtonMethod< TypeTag >::convergenceWriter_, and EWOMS_GET_PARAM.

Referenced by Ewoms::FvBaseNewtonMethod< TypeTag >::update_().

Friends And Related Function Documentation

template<class TypeTag >
friend class Ewoms::NewtonMethod< TypeTag >
friend

Member Data Documentation

template<class TypeTag >
CollectiveCommunication Ewoms::NewtonMethod< TypeTag >::comm_
protectedinherited
template<class TypeTag >
ConvergenceWriter Ewoms::NewtonMethod< TypeTag >::convergenceWriter_
protectedinherited
template<class TypeTag >
std::ostringstream Ewoms::NewtonMethod< TypeTag >::endIterMsgStream_
protectedinherited
template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::linearizeTime_
protectedinherited
template<class TypeTag >
Ewoms::Timer Ewoms::NewtonMethod< TypeTag >::linearizeTimer_
protectedinherited
template<class TypeTag >
LinearSolverBackend Ewoms::NewtonMethod< TypeTag >::linearSolver_
protectedinherited
template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::solveTime_
protectedinherited
template<class TypeTag >
Ewoms::Timer Ewoms::NewtonMethod< TypeTag >::solveTimer_
protectedinherited
template<class TypeTag >
Scalar Ewoms::NewtonMethod< TypeTag >::updateTime_
protectedinherited
template<class TypeTag >
Ewoms::Timer Ewoms::NewtonMethod< TypeTag >::updateTimer_
protectedinherited

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