GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porenetwork/2p/newtonsolver.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 10 10 100.0%
Branches: 9 12 75.0%

Line Branch Exec Source
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 //
7 /*!
8 * \file
9 * \ingroup PNMTwoPModel
10 * \copydoc Dumux::PoreNetwork::TwoPNewtonSolver
11 */
12 #ifndef DUMUX_PNM_NEWTON_SOLVER_HH
13 #define DUMUX_PNM_NEWTON_SOLVER_HH
14
15 #include <dumux/nonlinear/newtonsolver.hh>
16 #include "newtonconsistencychecks.hh"
17
18 namespace Dumux::PoreNetwork {
19 /*!
20 * \ingroup PNMTwoPModel
21 * \brief A two-phase PNM specific newton solver.
22 *
23 * This controller 'knows' what a 'physically meaningful' solution is
24 * which allows the newton method to abort quicker if the solution is
25 * way out of bounds.
26 */
27 template<class Assembler, class LinearSolver,
28 template<class, class> class NewtonConsistencyChecks = TwoPNewtonConsistencyChecks>
29
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 class TwoPNewtonSolver : public Dumux::NewtonSolver<Assembler, LinearSolver>
30 {
31 using ParentType = Dumux::NewtonSolver<Assembler, LinearSolver>;
32 using SolutionVector = typename ParentType::SolutionVector;
33
34 public:
35
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
4 using ParentType::ParentType;
36
37 /*!
38 * \brief Called after each Newton update
39 *
40 * \param uCurrentIter The current global solution vector
41 * \param uLastIter The previous global solution vector
42 */
43 1632 void newtonEndStep(SolutionVector &uCurrentIter,
44 const SolutionVector &uLastIter) final
45 {
46 // call the method of the base class
47 1632 ParentType::newtonEndStep(uCurrentIter, uLastIter);
48
49 3238 auto& gridVariables = this->assembler().gridVariables();
50 3238 auto& invasionState = gridVariables.gridFluxVarsCache().invasionState();
51 4857 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 3024 if (newtonConverged())
56 {
57 NewtonConsistencyChecks<typename Assembler::GridVariables, SolutionVector> checks;
58 902 checks.performChecks(gridVariables, uCurrentIter, this->assembler().prevSol());
59 }
60 1619 }
61
62 /*!
63 * \brief Returns true if the current solution can be considered to
64 * be accurate enough. We enforce an additional Newton iteration if the invasion
65 * switch was triggered in the last iteration.
66 */
67 2072 bool newtonConverged() const final
68 {
69
4/4
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 232 times.
✓ Branch 2 taken 1405 times.
✓ Branch 3 taken 214 times.
3691 if (switchedInLastIteration_)
70 return false;
71
72
2/2
✓ Branch 0 taken 451 times.
✓ Branch 1 taken 954 times.
3245 return ParentType::newtonConverged();
73 }
74
75 /*!
76 * \brief Called if the Newton method broke down.
77 * This method is called _after_ newtonEnd() and resets the invasion state.
78 */
79 36 void newtonFail(SolutionVector& u) final
80 {
81 36 ParentType::newtonFail(u);
82 72 auto& gridVariables = this->assembler().gridVariables();
83 108 gridVariables.gridFluxVarsCache().invasionState().reset();
84 36 }
85
86 /*!
87 * \brief Called if the Newton method ended successfully
88 * This method is called _after_ newtonEnd() and advances the invasion state.
89 */
90 432 void newtonSucceed() final
91 {
92 864 auto& gridVariables = this->assembler().gridVariables();
93 1296 gridVariables.gridFluxVarsCache().invasionState().advance();
94 432 }
95
96 private:
97 bool switchedInLastIteration_{false};
98 };
99
100 } // end namespace Dumux::PoreNetwork
101
102 #endif
103