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
31#include "pvsproperties.hh"
32
34
35namespace Opm::Properties {
36
37template <class TypeTag, class MyTypeTag>
38struct DiscNewtonMethod;
39
40} // namespace Opm::Properties
41
42namespace Opm {
43
50template <class TypeTag>
51class PvsNewtonMethod : public GetPropType<TypeTag, Properties::DiscNewtonMethod>
52{
61
62 enum { numPhases = FluidSystem::numPhases };
63
64 // primary variable indices
65 enum { pressure0Idx = Indices::pressure0Idx };
66 enum { switch0Idx = Indices::switch0Idx };
67
68public:
69 PvsNewtonMethod(Simulator& simulator) : ParentType(simulator)
70 {}
71
72protected:
74 friend ParentType;
75
80 PrimaryVariables& nextValue,
81 const PrimaryVariables& currentValue,
82 const EqVector& update,
83 const EqVector&)
84 {
85 // normal Newton-Raphson update
86 nextValue = currentValue;
87 nextValue -= update;
88
90 // put crash barriers along the update path
92 // saturations: limit the change of any saturation to at most 20%
93 Scalar sumSatDelta = 0.0;
94 Scalar maxSatDelta = 0.0;
95 for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
96 if (!currentValue.phaseIsPresent(phaseIdx))
97 continue;
98
99 maxSatDelta = std::max(std::abs(update[switch0Idx + phaseIdx]),
100 maxSatDelta);
101 sumSatDelta += update[switch0Idx + phaseIdx];
102 }
103 maxSatDelta = std::max(std::abs(- sumSatDelta), maxSatDelta);
104
105 if (maxSatDelta > 0.2) {
106 Scalar alpha = 0.2/maxSatDelta;
107 for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
108 if (!currentValue.phaseIsPresent(phaseIdx))
109 continue;
110
111 nextValue[switch0Idx + phaseIdx] =
112 currentValue[switch0Idx + phaseIdx]
113 - alpha*update[switch0Idx + phaseIdx];
114 }
115 }
116
117 // limit pressure reference change to 20% of the total value per iteration
118 clampValue_(nextValue[pressure0Idx],
119 currentValue[pressure0Idx]*0.8,
120 currentValue[pressure0Idx]*1.2);
121 }
122
126 void endIteration_(SolutionVector& uCurrentIter,
127 const SolutionVector& uLastIter)
128 {
129 ParentType::endIteration_(uCurrentIter, uLastIter);
130 this->problem().model().switchPrimaryVars_();
131 }
132
133 void clampValue_(Scalar& val, Scalar minVal, Scalar maxVal) const
134 { val = std::max(minVal, std::min(val, maxVal)); }
135};
136} // namespace Opm
137
138#endif
The multi-dimensional Newton method.
Definition: newtonmethod.hh:113
A newton solver which is specific to the compositional multi-phase PVS model.
Definition: pvsnewtonmethod.hh:52
PvsNewtonMethod(Simulator &simulator)
Definition: pvsnewtonmethod.hh:69
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: pvsnewtonmethod.hh:79
void clampValue_(Scalar &val, Scalar minVal, Scalar maxVal) const
Definition: pvsnewtonmethod.hh:133
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: pvsnewtonmethod.hh:126
friend ParentType
Definition: pvsnewtonmethod.hh:74
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
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:242
Declares the properties required for the compositional multi-phase primary variable switching model.