3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/richards/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 *****************************************************************************/
25#ifndef DUMUX_RICHARDS_NEWTON_SOLVER_HH
26#define DUMUX_RICHARDS_NEWTON_SOLVER_HH
27
28#include <algorithm>
29
33
34namespace Dumux {
43template <class Assembler, class LinearSolver>
44class RichardsNewtonSolver : public NewtonSolver<Assembler, LinearSolver>
45{
46 using Scalar = typename Assembler::Scalar;
48 using Indices = typename Assembler::GridVariables::VolumeVariables::Indices;
49 enum { pressureIdx = Indices::pressureIdx };
50
51 using typename ParentType::Backend;
52 using typename ParentType::SolutionVector;
53
54public:
55 using ParentType::ParentType;
56 using typename ParentType::Variables;
57
58private:
59
68 void choppedUpdate_(Variables &varsCurrentIter,
69 const SolutionVector &uLastIter,
70 const SolutionVector &deltaU) final
71 {
72 auto uCurrentIter = uLastIter;
73 uCurrentIter -= deltaU;
74
75 // do not clamp anything after 5 iterations
76 if (this->numSteps_ <= 4)
77 {
78 // clamp saturation change to at most 20% per iteration
79 const auto& gridGeometry = this->assembler().gridGeometry();
80 auto fvGeometry = localView(gridGeometry);
81 for (const auto& element : elements(gridGeometry.gridView()))
82 {
83 fvGeometry.bindElement(element);
84
85 for (auto&& scv : scvs(fvGeometry))
86 {
87 auto dofIdxGlobal = scv.dofIndex();
88
89 // calculate the old wetting phase saturation
90 const auto& spatialParams = this->assembler().problem().spatialParams();
91 const auto elemSol = elementSolution(element, uCurrentIter, gridGeometry);
92
93 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
94 const Scalar pcMin = fluidMatrixInteraction.pc(1.0);
95 const Scalar pw = uLastIter[dofIdxGlobal][pressureIdx];
96 using std::max;
97 const Scalar pn = max(this->assembler().problem().nonwettingReferencePressure(), pw + pcMin);
98 const Scalar pcOld = pn - pw;
99 const Scalar SwOld = max(0.0, fluidMatrixInteraction.sw(pcOld));
100
101 // convert into minimum and maximum wetting phase pressures
102 const Scalar pwMin = pn - fluidMatrixInteraction.pc(SwOld - 0.2);
103 const Scalar pwMax = pn - fluidMatrixInteraction.pc(SwOld + 0.2);
104
105 // clamp the result
106 using std::clamp;
107 uCurrentIter[dofIdxGlobal][pressureIdx] = clamp(uCurrentIter[dofIdxGlobal][pressureIdx], pwMin, pwMax);
108 }
109 }
110 }
111
112 // update the variables
113 this->solutionChanged_(varsCurrentIter, uCurrentIter);
114
115 if (this->enableResidualCriterion())
116 this->computeResidualReduction_(varsCurrentIter);
117 }
118};
119
120} // end namespace Dumux
121
122#endif
Element solution classes and factory functions.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:118
Definition: adapt.hh:29
Detail::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:82
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:216
int numSteps_
actual number of steps done so far
Definition: nonlinear/newtonsolver.hh:917
bool enableResidualCriterion() const
Definition: nonlinear/newtonsolver.hh:907
virtual void solutionChanged_(Variables &vars, const SolutionVector &uCurrentIter)
Update solution-dependent quantities like grid variables after the solution has changed.
Definition: nonlinear/newtonsolver.hh:875
typename Backend::DofVector SolutionVector
Definition: nonlinear/newtonsolver.hh:221
VariablesBackend< typename ParentType::Variables > Backend
Definition: nonlinear/newtonsolver.hh:220
void computeResidualReduction_(const Variables &vars)
Definition: nonlinear/newtonsolver.hh:883
A Richards model specific Newton solver.
Definition: porousmediumflow/richards/newtonsolver.hh:45
Declares all properties used in Dumux.
Reference implementation of a Newton solver.