version 3.9
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_RICHARDS_NEWTON_SOLVER_HH
14#define DUMUX_RICHARDS_NEWTON_SOLVER_HH
15
16#include <algorithm>
17
18#include <dune/common/parallel/communication.hh>
19#include <dune/common/parallel/mpihelper.hh>
20
25
26namespace Dumux {
35template <class Assembler, class LinearSolver,
36 class Reassembler = PartialReassembler<Assembler>,
37 class Comm = Dune::Communication<Dune::MPIHelper::MPICommunicator> >
38class RichardsNewtonSolver : public NewtonSolver<Assembler, LinearSolver, Reassembler, Comm>
39{
40 using Scalar = typename Assembler::Scalar;
42 using Indices = typename Assembler::GridVariables::VolumeVariables::Indices;
43 enum { pressureIdx = Indices::pressureIdx };
44
45 using typename ParentType::Backend;
46 using typename ParentType::SolutionVector;
47 using typename ParentType::ResidualVector;
48
49public:
51 using typename ParentType::Variables;
52
53private:
54
63 void choppedUpdate_(Variables &varsCurrentIter,
64 const SolutionVector &uLastIter,
65 const ResidualVector &deltaU) final
66 {
67 auto uCurrentIter = uLastIter;
68 Backend::axpy(-1.0, deltaU, uCurrentIter);
69
70 // do not clamp anything after 5 iterations
71 if (this->numSteps_ <= 4)
72 {
73 // clamp saturation change to at most 20% per iteration
74 const auto& gridGeometry = this->assembler().gridGeometry();
75 auto fvGeometry = localView(gridGeometry);
76 for (const auto& element : elements(gridGeometry.gridView()))
77 {
78 fvGeometry.bindElement(element);
79
80 for (auto&& scv : scvs(fvGeometry))
81 {
82 auto dofIdxGlobal = scv.dofIndex();
83
84 // calculate the old wetting phase saturation
85 const auto& spatialParams = this->assembler().problem().spatialParams();
86 const auto elemSol = elementSolution(element, uCurrentIter, gridGeometry);
87
88 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
89 const Scalar pcMin = fluidMatrixInteraction.pc(1.0);
90 const Scalar pw = uLastIter[dofIdxGlobal][pressureIdx];
91 using std::max;
92 const Scalar pn = max(this->assembler().problem().nonwettingReferencePressure(), pw + pcMin);
93 const Scalar pcOld = pn - pw;
94 const Scalar SwOld = max(0.0, fluidMatrixInteraction.sw(pcOld));
95
96 // convert into minimum and maximum wetting phase pressures
97 const Scalar pwMin = pn - fluidMatrixInteraction.pc(SwOld - 0.2);
98 const Scalar pwMax = pn - fluidMatrixInteraction.pc(SwOld + 0.2);
99
100 // clamp the result
101 using std::clamp;
102 uCurrentIter[dofIdxGlobal][pressureIdx] = clamp(uCurrentIter[dofIdxGlobal][pressureIdx], pwMin, pwMax);
103 }
104 }
105 }
106
107 // update the variables
108 this->solutionChanged_(varsCurrentIter, uCurrentIter);
109
110 if (this->enableResidualCriterion())
111 this->computeResidualReduction_(varsCurrentIter);
112 }
113};
114
115} // end namespace Dumux
116
117#endif
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:181
typename Assembler::ResidualType ResidualVector
Definition: nonlinear/newtonsolver.hh:187
virtual void solutionChanged_(Variables &vars, const SolutionVector &uCurrentIter)
Update solution-dependent quantities like grid variables after the solution has changed.
Definition: nonlinear/newtonsolver.hh:841
typename Backend::DofVector SolutionVector
Definition: nonlinear/newtonsolver.hh:186
VariablesBackend< typename ParentType::Variables > Backend
Definition: nonlinear/newtonsolver.hh:185
const Assembler & assembler() const
Access the assembler.
Definition: common/pdesolver.hh:121
Detail::PDESolver::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:71
A Richards model specific Newton solver.
Definition: porousmediumflow/richards/newtonsolver.hh:39
Defines all properties used in Dumux.
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:26
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
Definition: adapt.hh:17
Reference implementation of a Newton solver.
Detects which entries in the Jacobian have to be recomputed.