3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_PNM_NEWTON_SOLVER_HH
25#define DUMUX_PNM_NEWTON_SOLVER_HH
26
29
30namespace Dumux::PoreNetwork {
39template<class Assembler, class LinearSolver,
40 template<class, class> class NewtonConsistencyChecks = TwoPNewtonConsistencyChecks>
41class TwoPNewtonSolver : public Dumux::NewtonSolver<Assembler, LinearSolver>
42{
44 using SolutionVector = typename Assembler::ResidualType;
45
46public:
47 using ParentType::ParentType;
48
55 void newtonEndStep(SolutionVector &uCurrentIter,
56 const SolutionVector &uLastIter) final
57 {
58 // call the method of the base class
59 ParentType::newtonEndStep(uCurrentIter, uLastIter);
60
61 auto& gridVariables = this->assembler().gridVariables();
62 auto& invasionState = gridVariables.gridFluxVarsCache().invasionState();
63 switchedInLastIteration_ = invasionState.update(uCurrentIter, gridVariables.curGridVolVars(), gridVariables.gridFluxVarsCache());
64
65 // If the solution is about to be accepted, check for accuracy and trigger a retry
66 // with a decreased time step size if necessary.
67 if (newtonConverged())
68 {
69 NewtonConsistencyChecks<typename Assembler::GridVariables, SolutionVector> checks;
70 checks.performChecks(gridVariables, uCurrentIter, this->assembler().prevSol());
71 }
72 }
73
79 bool newtonConverged() const final
80 {
81 if (switchedInLastIteration_)
82 return false;
83
85 }
86
92 {
94 auto& gridVariables = this->assembler().gridVariables();
95 gridVariables.gridFluxVarsCache().invasionState().reset();
96 }
97
102 void newtonSucceed() final
103 {
104 auto& gridVariables = this->assembler().gridVariables();
105 gridVariables.gridFluxVarsCache().invasionState().advance();
106 }
107
108private:
109 bool switchedInLastIteration_{false};
110};
111
112} // end namespace Dumux::PoreNetwork
113
114#endif
Definition: discretization/porenetwork/fvelementgeometry.hh:34
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:216
virtual void newtonFail(Variables &u)
Called if the Newton method broke down. This method is called after newtonEnd()
Definition: nonlinear/newtonsolver.hh:735
virtual void newtonEndStep(Variables &vars, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: nonlinear/newtonsolver.hh:638
typename Backend::DofVector SolutionVector
Definition: nonlinear/newtonsolver.hh:221
virtual bool newtonConverged() const
Returns true if the error of the solution is below the tolerance.
Definition: nonlinear/newtonsolver.hh:685
A two-phase PNM specific newton solver.
Definition: porenetwork/2p/newtonsolver.hh:42
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:79
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:91
void newtonSucceed() final
Called if the Newton method ended successfully This method is called after newtonEnd() and advances t...
Definition: porenetwork/2p/newtonsolver.hh:102
void newtonEndStep(SolutionVector &uCurrentIter, const SolutionVector &uLastIter) final
Called after each Newton update.
Definition: porenetwork/2p/newtonsolver.hh:55
Reference implementation of a Newton solver.