All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
33 namespace Ewoms {
34 
41 template <class TypeTag>
42 class PvsNewtonMethod : public GET_PROP_TYPE(TypeTag, DiscNewtonMethod)
43 {
44  typedef typename GET_PROP_TYPE(TypeTag, DiscNewtonMethod) ParentType;
45  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
46  typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
47  typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
48  typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
49  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
50  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
51  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
52 
53  enum { numPhases = FluidSystem::numPhases };
54 
55  // primary variable indices
56  enum { pressure0Idx = Indices::pressure0Idx };
57  enum { switch0Idx = Indices::switch0Idx };
58 
59 public:
60  PvsNewtonMethod(Simulator& simulator) : ParentType(simulator)
61  {}
62 
63 protected:
64  friend NewtonMethod<TypeTag>;
65  friend ParentType;
66 
70  void updatePrimaryVariables_(unsigned globalDofIdx OPM_UNUSED,
71  PrimaryVariables& nextValue,
72  const PrimaryVariables& currentValue,
73  const EqVector& update,
74  const EqVector& currentResidual OPM_UNUSED)
75  {
76  // normal Newton-Raphson update
77  nextValue = currentValue;
78  nextValue -= update;
79 
81  // put crash barriers along the update path
83  // saturations: limit the change of any saturation to at most 20%
84  Scalar sumSatDelta = 0.0;
85  Scalar maxSatDelta = 0.0;
86  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
87  if (!currentValue.phaseIsPresent(phaseIdx))
88  continue;
89 
90  maxSatDelta = std::max(std::abs(update[switch0Idx + phaseIdx]),
91  maxSatDelta);
92  sumSatDelta += update[switch0Idx + phaseIdx];
93  }
94  maxSatDelta = std::max(std::abs(- sumSatDelta), maxSatDelta);
95 
96  if (maxSatDelta > 0.2) {
97  Scalar alpha = 0.2/maxSatDelta;
98  for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
99  if (!currentValue.phaseIsPresent(phaseIdx))
100  continue;
101 
102  nextValue[switch0Idx + phaseIdx] =
103  currentValue[switch0Idx + phaseIdx]
104  - alpha*update[switch0Idx + phaseIdx];
105  }
106  }
107 
108  // limit pressure reference change to 20% of the total value per iteration
109  clampValue_(nextValue[pressure0Idx],
110  currentValue[pressure0Idx]*0.8,
111  currentValue[pressure0Idx]*1.2);
112  }
113 
117  void endIteration_(SolutionVector& uCurrentIter,
118  const SolutionVector& uLastIter)
119  {
120  ParentType::endIteration_(uCurrentIter, uLastIter);
121  this->problem().model().switchPrimaryVars_();
122  }
123 
124  void clampValue_(Scalar& val, Scalar minVal, Scalar maxVal) const
125  { val = std::max(minVal, std::min(val, maxVal)); }
126 };
127 } // namespace Ewoms
128 
129 #endif
void updatePrimaryVariables_(unsigned globalDofIdx OPM_UNUSED, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &currentResidual OPM_UNUSED)
Update a single primary variables object.
Definition: pvsnewtonmethod.hh:70
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
The multi-dimensional Newton method.
Definition: newtonmethod.hh:56
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: pvsnewtonmethod.hh:117
A newton solver which is specific to the compositional multi-phase PVS model.
Definition: pvsnewtonmethod.hh:42
Declares the properties required for the compositional multi-phase primary variable switching model...
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75