version 3.8
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
21
22namespace Dumux {
31template <class Assembler, class LinearSolver>
32class RichardsNewtonSolver : public NewtonSolver<Assembler, LinearSolver>
33{
34 using Scalar = typename Assembler::Scalar;
36 using Indices = typename Assembler::GridVariables::VolumeVariables::Indices;
37 enum { pressureIdx = Indices::pressureIdx };
38
39 using typename ParentType::Backend;
40 using typename ParentType::SolutionVector;
41 using typename ParentType::ResidualVector;
42
43public:
44 using ParentType::ParentType;
45 using typename ParentType::Variables;
46
47private:
48
57 void choppedUpdate_(Variables &varsCurrentIter,
58 const SolutionVector &uLastIter,
59 const ResidualVector &deltaU) final
60 {
61 auto uCurrentIter = uLastIter;
62 Backend::axpy(-1.0, deltaU, uCurrentIter);
63
64 // do not clamp anything after 5 iterations
65 if (this->numSteps_ <= 4)
66 {
67 // clamp saturation change to at most 20% per iteration
68 const auto& gridGeometry = this->assembler().gridGeometry();
69 auto fvGeometry = localView(gridGeometry);
70 for (const auto& element : elements(gridGeometry.gridView()))
71 {
72 fvGeometry.bindElement(element);
73
74 for (auto&& scv : scvs(fvGeometry))
75 {
76 auto dofIdxGlobal = scv.dofIndex();
77
78 // calculate the old wetting phase saturation
79 const auto& spatialParams = this->assembler().problem().spatialParams();
80 const auto elemSol = elementSolution(element, uCurrentIter, gridGeometry);
81
82 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
83 const Scalar pcMin = fluidMatrixInteraction.pc(1.0);
84 const Scalar pw = uLastIter[dofIdxGlobal][pressureIdx];
85 using std::max;
86 const Scalar pn = max(this->assembler().problem().nonwettingReferencePressure(), pw + pcMin);
87 const Scalar pcOld = pn - pw;
88 const Scalar SwOld = max(0.0, fluidMatrixInteraction.sw(pcOld));
89
90 // convert into minimum and maximum wetting phase pressures
91 const Scalar pwMin = pn - fluidMatrixInteraction.pc(SwOld - 0.2);
92 const Scalar pwMax = pn - fluidMatrixInteraction.pc(SwOld + 0.2);
93
94 // clamp the result
95 using std::clamp;
96 uCurrentIter[dofIdxGlobal][pressureIdx] = clamp(uCurrentIter[dofIdxGlobal][pressureIdx], pwMin, pwMax);
97 }
98 }
99 }
100
101 // update the variables
102 this->solutionChanged_(varsCurrentIter, uCurrentIter);
103
104 if (this->enableResidualCriterion())
105 this->computeResidualReduction_(varsCurrentIter);
106 }
107};
108
109} // end namespace Dumux
110
111#endif
An implementation of a Newton solver.
Definition: nonlinear/newtonsolver.hh:181
typename Assembler::ResidualType ResidualVector
Definition: nonlinear/newtonsolver.hh:187
int numSteps_
actual number of steps done so far
Definition: nonlinear/newtonsolver.hh:873
bool enableResidualCriterion() const
Definition: nonlinear/newtonsolver.hh:863
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
void computeResidualReduction_(const Variables &vars)
Definition: nonlinear/newtonsolver.hh:849
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:33
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.