version 3.8
porenetwork/2p/newtonsolver.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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PNM_NEWTON_SOLVER_HH
13#define DUMUX_PNM_NEWTON_SOLVER_HH
14
17
18namespace Dumux::PoreNetwork {
27template<class Assembler, class LinearSolver,
28 template<class, class> class NewtonConsistencyChecks = TwoPNewtonConsistencyChecks>
29class TwoPNewtonSolver : public Dumux::NewtonSolver<Assembler, LinearSolver>
30{
33
34public:
35 using ParentType::ParentType;
36
43 void newtonEndStep(SolutionVector &uCurrentIter,
44 const SolutionVector &uLastIter) final
45 {
46 // call the method of the base class
47 ParentType::newtonEndStep(uCurrentIter, uLastIter);
48
49 auto& gridVariables = this->assembler().gridVariables();
50 auto& invasionState = gridVariables.gridFluxVarsCache().invasionState();
51 switchedInLastIteration_ = invasionState.update(uCurrentIter, gridVariables.curGridVolVars(), gridVariables.gridFluxVarsCache());
52
53 // If the solution is about to be accepted, check for accuracy and trigger a retry
54 // with a decreased time step size if necessary.
55 if (newtonConverged())
56 {
57 NewtonConsistencyChecks<typename Assembler::GridVariables, SolutionVector> checks;
58 checks.performChecks(gridVariables, uCurrentIter, this->assembler().prevSol());
59 }
60 }
61
67 bool newtonConverged() const final
68 {
69 if (switchedInLastIteration_)
70 return false;
71
73 }
74
80 {
82 auto& gridVariables = this->assembler().gridVariables();
83 gridVariables.gridFluxVarsCache().invasionState().reset();
84 }
85
90 void newtonSucceed() final
91 {
92 auto& gridVariables = this->assembler().gridVariables();
93 gridVariables.gridFluxVarsCache().invasionState().advance();
94 }
95
96private:
97 bool switchedInLastIteration_{false};
98};
99
100} // end namespace Dumux::PoreNetwork
101
102#endif
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:181
virtual void newtonFail(Variables &u)
Called if the Newton method broke down. This method is called after newtonEnd()
Definition: nonlinear/newtonsolver.hh:701
virtual void newtonEndStep(Variables &vars, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: nonlinear/newtonsolver.hh:604
typename Backend::DofVector SolutionVector
Definition: nonlinear/newtonsolver.hh:186
virtual bool newtonConverged() const
Returns true if the error of the solution is below the tolerance.
Definition: nonlinear/newtonsolver.hh:651
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
A two-phase PNM specific newton solver.
Definition: porenetwork/2p/newtonsolver.hh:30
bool newtonConverged() const final
Returns true if the current solution can be considered to be accurate enough. We enforce an additiona...
Definition: porenetwork/2p/newtonsolver.hh:67
void newtonFail(SolutionVector &u) final
Called if the Newton method broke down. This method is called after newtonEnd() and resets the invasi...
Definition: porenetwork/2p/newtonsolver.hh:79
void newtonSucceed() final
Called if the Newton method ended successfully This method is called after newtonEnd() and advances t...
Definition: porenetwork/2p/newtonsolver.hh:90
void newtonEndStep(SolutionVector &uCurrentIter, const SolutionVector &uLastIter) final
Called after each Newton update.
Definition: porenetwork/2p/newtonsolver.hh:43
Definition: discretization/porenetwork/fvelementgeometry.hh:24
Reference implementation of a Newton solver.