opm-simulators
Toggle main menu visibility
Loading...
Searching...
No Matches
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 <
opm/models/common/multiphasebaseproperties.hh
>
32
#include <
opm/models/nonlinear/newtonmethod.hh
>
33
34
#include <algorithm>
35
#include <cmath>
36
37
namespace
Opm::Properties {
38
39
template
<
class
TypeTag,
class
MyTypeTag>
40
struct
DiscNewtonMethod
;
41
42
}
// namespace Opm::Properties
43
44
namespace
Opm
{
45
52
template
<
class
TypeTag>
53
class
PvsNewtonMethod :
public
GetPropType
<TypeTag, Properties::DiscNewtonMethod>
54
{
55
using
ParentType =
GetPropType<TypeTag, Properties::DiscNewtonMethod>
;
56
using
Simulator =
GetPropType<TypeTag, Properties::Simulator>
;
57
using
SolutionVector =
GetPropType<TypeTag, Properties::SolutionVector>
;
58
using
PrimaryVariables =
GetPropType<TypeTag, Properties::PrimaryVariables>
;
59
using
EqVector =
GetPropType<TypeTag, Properties::EqVector>
;
60
using
Scalar =
GetPropType<TypeTag, Properties::Scalar>
;
61
using
Indices =
GetPropType<TypeTag, Properties::Indices>
;
62
using
FluidSystem =
GetPropType<TypeTag, Properties::FluidSystem>
;
63
64
enum
{ numPhases = FluidSystem::numPhases };
65
66
// primary variable indices
67
enum
{ pressure0Idx = Indices::pressure0Idx };
68
enum
{ switch0Idx = Indices::switch0Idx };
69
70
public
:
71
explicit
PvsNewtonMethod(Simulator& simulator) : ParentType(simulator)
72
{}
73
74
protected
:
75
friend
NewtonMethod<TypeTag>
;
76
friend
ParentType;
77
81
void
updatePrimaryVariables_
(
unsigned
,
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
133
void
endIteration_
(SolutionVector& uCurrentIter,
134
const
SolutionVector& uLastIter)
135
{
136
ParentType::endIteration_(uCurrentIter, uLastIter);
137
this->problem().model().switchPrimaryVars_();
138
}
139
};
140
141
}
// namespace Opm
142
143
#endif
Opm::NewtonMethod
The multi-dimensional Newton method.
Definition
newtonmethod.hh:100
Opm::PvsNewtonMethod::updatePrimaryVariables_
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables ¤tValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition
pvsnewtonmethod.hh:81
Opm::PvsNewtonMethod::endIteration_
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition
pvsnewtonmethod.hh:133
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition
blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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
newtonmethod.hh
The multi-dimensional Newton method.
Opm::Properties::DiscNewtonMethod
The discretization specific part of he implementing the Newton algorithm.
Definition
fvbasenewtonmethod.hh:55
opm
models
pvs
pvsnewtonmethod.hh
Generated by
1.17.0