blackoilnewtonmethod.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  Copyright (C) 2008-2014 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef EWOMS_BLACK_OIL_NEWTON_METHOD_HH
27 #define EWOMS_BLACK_OIL_NEWTON_METHOD_HH
28 
29 #include "blackoilproperties.hh"
30 
31 namespace Ewoms {
32 
38 template <class TypeTag>
39 class BlackOilNewtonMethod : public GET_PROP_TYPE(TypeTag, DiscNewtonMethod)
40 {
41  typedef typename GET_PROP_TYPE(TypeTag, DiscNewtonMethod) ParentType;
42  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
43  typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
44  typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
45  typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
46  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
47  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
48  typedef typename GET_PROP_TYPE(TypeTag, Linearizer) Linearizer;
49 
50  static const int numEq = GET_PROP_VALUE(TypeTag, NumEq);
51 
52 public:
53  BlackOilNewtonMethod(Simulator &simulator) : ParentType(simulator)
54  { numChoppedIterations_ = EWOMS_GET_PARAM(TypeTag, int, BlackoilNumChoppedIterations); }
55 
59  static void registerParameters()
60  {
61  ParentType::registerParameters();
62 
63  EWOMS_REGISTER_PARAM(TypeTag, int, BlackoilNumChoppedIterations,
64  "Number of Newton-Raphson iterations for which the update gets"
65  " limited");
66  }
67 
68 
69  // HACK which is necessary because GCC 4.4 does not support
70  // being a friend of typedefs
71 /*
72 protected:
73  friend class NewtonMethod<TypeTag>;
74  friend class ParentType;
75 */
76 
80  void endIteration_(SolutionVector &uCurrentIter,
81  const SolutionVector &uLastIter)
82  {
83  ParentType::endIteration_(uCurrentIter, uLastIter);
84  this->problem().model().switchPrimaryVars_();
85  }
86 
90  void updatePrimaryVariables_(int globalDofIdx,
91  PrimaryVariables& nextValue,
92  const PrimaryVariables& currentValue,
93  const EqVector& update,
94  const EqVector& currentResidual)
95  {
96  for (int eqIdx = 0; eqIdx < numEq; ++eqIdx) {
97  // calculate the update of the current primary variable. For the
98  // black-oil model we limit the pressure and saturation updates, but do
99  // we not clamp anything after the specified number of iterations was
100  // reached
101  Scalar delta = update[eqIdx];
102  if (this->numIterations_ < numChoppedIterations_) {
103  // limit changes in pressure to 20% of the pressure value at the
104  // beginning of the current iteration
105  if (eqIdx == Indices::gasPressureIdx
106  && std::abs(delta/currentValue[eqIdx]) > 0.2)
107  {
108  delta /= std::abs(delta/(0.2*currentValue[eqIdx]));
109  }
110  // limit changes in saturation to 20%
111  else if ((eqIdx == Indices::waterSaturationIdx ||
112  (eqIdx == Indices::switchIdx
113  && currentValue.switchingVarMeaning() == PrimaryVariables::GasSaturation))
114  && std::abs(delta) > 0.2)
115  {
116  delta /= std::abs(delta/0.2);
117  }
118 
119  }
120 
121  // do the actual update
122  nextValue[eqIdx] = currentValue[eqIdx] - delta;
123  }
124  }
125 
126 private:
127  int numChoppedIterations_;
128 };
129 } // namespace Ewoms
130 
131 #endif
void updatePrimaryVariables_(int globalDofIdx, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &currentResidual)
Update a single primary variables object.
Definition: blackoilnewtonmethod.hh:90
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: blackoilnewtonmethod.hh:59
Declares the properties required by the black oil model.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition: blackoilnewtonmethod.hh:80
Definition: baseauxiliarymodule.hh:35
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
A newton solver which is specific to the black oil model.
Definition: blackoilnewtonmethod.hh:39
BlackOilNewtonMethod(Simulator &simulator)
Definition: blackoilnewtonmethod.hh:53
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95