pvsnewtonmethod.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_PVS_NEWTON_METHOD_HH
29#define EWOMS_PVS_NEWTON_METHOD_HH
30
33
34#include <algorithm>
35#include <cmath>
36
37namespace Opm::Properties {
38
39template <class TypeTag, class MyTypeTag>
40struct DiscNewtonMethod;
41
42} // namespace Opm::Properties
43
44namespace Opm {
45
52template <class TypeTag>
53class PvsNewtonMethod : public GetPropType<TypeTag, Properties::DiscNewtonMethod>
54{
63
64 enum { numPhases = FluidSystem::numPhases };
65
66 // primary variable indices
67 enum { pressure0Idx = Indices::pressure0Idx };
68 enum { switch0Idx = Indices::switch0Idx };
69
70public:
71 explicit PvsNewtonMethod(Simulator& simulator) : ParentType(simulator)
72 {}
73
74protected:
76 friend ParentType;
77
82 PrimaryVariables& nextValue,
83 const PrimaryVariables& currentValue,
84 const EqVector& update,
85 const EqVector&)
86 {
87 // normal Newton-Raphson update
88 nextValue = currentValue;
89 nextValue -= update;
90
92 // put crash barriers along the update path
94 // saturations: limit the change of any saturation to at most 20%
95 Scalar sumSatDelta = 0.0;
96 Scalar maxSatDelta = 0.0;
97 for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
98 if (!currentValue.phaseIsPresent(phaseIdx)) {
99 continue;
100 }
101
102 maxSatDelta = std::max(std::abs(update[switch0Idx + phaseIdx]),
103 maxSatDelta);
104 sumSatDelta += update[switch0Idx + phaseIdx];
105 }
106 maxSatDelta = std::max(std::abs(-sumSatDelta), maxSatDelta);
107
108 if (maxSatDelta > 0.2) {
109 const Scalar alpha = 0.2 / maxSatDelta;
110 for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
111 if (!currentValue.phaseIsPresent(phaseIdx)) {
112 continue;
113 }
114
115 nextValue[switch0Idx + phaseIdx] =
116 currentValue[switch0Idx + phaseIdx] -
117 alpha * update[switch0Idx + phaseIdx];
118 }
119 }
120
121 // limit pressure reference change to 20% of the total value per iteration
122 nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
123 currentValue[pressure0Idx] * 0.8,
124 currentValue[pressure0Idx] * 1.2);
125 }
126
130 void endIteration_(SolutionVector& uCurrentIter,
131 const SolutionVector& uLastIter)
132 {
133 ParentType::endIteration_(uCurrentIter, uLastIter);
134 this->problem().model().switchPrimaryVars_();
135 }
136};
137
138} // namespace Opm
139
140#endif
The multi-dimensional Newton method.
Definition: newtonmethod.hh:100
A newton solver which is specific to the compositional multi-phase PVS model.
Definition: pvsnewtonmethod.hh:54
PvsNewtonMethod(Simulator &simulator)
Definition: pvsnewtonmethod.hh:71
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: pvsnewtonmethod.hh:81
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: pvsnewtonmethod.hh:130
friend ParentType
Definition: pvsnewtonmethod.hh:76
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilmodel.hh:79
Definition: blackoilboundaryratevector.hh:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233