3.1-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
31
32namespace Dumux {
43template <class Assembler, class LinearSolver>
44class RichardsNewtonSolver : public NewtonSolver<Assembler, LinearSolver>
45{
46 using Scalar = typename Assembler::Scalar;
48 using SolutionVector = typename Assembler::ResidualType;
49
50 using MaterialLaw = typename Assembler::Problem::SpatialParams::MaterialLaw;
52 enum { pressureIdx = Indices::pressureIdx };
53
54public:
55 using ParentType::ParentType;
56
57private:
58
67 void choppedUpdate_(SolutionVector &uCurrentIter,
68 const SolutionVector &uLastIter,
69 const SolutionVector &deltaU) final
70 {
71 uCurrentIter = uLastIter;
72 uCurrentIter -= deltaU;
73
74 // do not clamp anything after 5 iterations
75 if (this->numSteps_ <= 4)
76 {
77 // clamp saturation change to at most 20% per iteration
78 const auto& gridGeometry = this->assembler().gridGeometry();
79 for (const auto& element : elements(gridGeometry.gridView()))
80 {
81 auto fvGeometry = localView(gridGeometry);
82 fvGeometry.bindElement(element);
83
84 for (auto&& scv : scvs(fvGeometry))
85 {
86 auto dofIdxGlobal = scv.dofIndex();
87
88 // calculate the old wetting phase saturation
89 const auto& spatialParams = this->assembler().problem().spatialParams();
90 const auto elemSol = elementSolution(element, uCurrentIter, gridGeometry);
91 const auto& materialLawParams = spatialParams.materialLawParams(element, scv, elemSol);
92 const Scalar pcMin = MaterialLaw::pc(materialLawParams, 1.0);
93 const Scalar pw = uLastIter[dofIdxGlobal][pressureIdx];
94 using std::max;
95 const Scalar pn = max(this->assembler().problem().nonWettingReferencePressure(), pw + pcMin);
96 const Scalar pcOld = pn - pw;
97 const Scalar SwOld = max(0.0, MaterialLaw::sw(materialLawParams, pcOld));
98
99 // convert into minimum and maximum wetting phase
100 // pressures
101 const Scalar pwMin = pn - MaterialLaw::pc(materialLawParams, SwOld - 0.2);
102 const Scalar pwMax = pn - MaterialLaw::pc(materialLawParams, SwOld + 0.2);
103
104 // clamp the result
105 using std::min; using std::max;
106 uCurrentIter[dofIdxGlobal][pressureIdx] = max(pwMin, min(uCurrentIter[dofIdxGlobal][pressureIdx], pwMax));
107 }
108 }
109 }
110
111 if (this->enableResidualCriterion())
112 this->computeResidualReduction_(uCurrentIter);
113
114 else
115 {
116 // If we get here, the convergence criterion does not require
117 // additional residual evalutions. Thus, the grid variables have
118 // not yet been updated to the new uCurrentIter.
119 this->assembler().updateGridVariables(uCurrentIter);
120 }
121 }
122};
123
124} // end namespace Dumux
125
126#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==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Property tag Indices
Definition: porousmediumflow/sequential/properties.hh:59
A high-level interface for a PDESolver.
Definition: common/pdesolver.hh:46
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:83
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:90
int numSteps_
actual number of steps done so far
Definition: nonlinear/newtonsolver.hh:795
bool enableResidualCriterion() const
Definition: nonlinear/newtonsolver.hh:733
void computeResidualReduction_(const SolutionVector &uCurrentIter)
Definition: nonlinear/newtonsolver.hh:726
A Richards model specific Newton solver.
Definition: porousmediumflow/richards/newtonsolver.hh:45
Declares all properties used in Dumux.
Reference implementation of the Newton solver.