NewtonSolver.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2015 SINTEF ICT, Applied Mathematics.
3  Copyright 2015 Statoil ASA.
4 
5  This file is part of the Open Porous Media project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef OPM_NEWTONSOLVER_HEADER_INCLUDED
22 #define OPM_NEWTONSOLVER_HEADER_INCLUDED
23 
25 #include <opm/core/utility/parameters/ParameterGroup.hpp>
26 #include <memory>
27 
28 namespace Opm {
29 
30 
32  template <class PhysicalModel>
34  {
35  public:
36  // --------- Types and enums ---------
38  typedef ADB::V V;
39  typedef ADB::M M;
40 
41  // The Newton relaxation scheme type
42  enum RelaxType { DAMPEN, SOR };
43 
44  // Solver parameters controlling nonlinear Newton process.
46  {
48  double relax_max_;
51  int max_iter_; // max newton iterations
52  int min_iter_; // min newton iterations
53 
54  explicit SolverParameters( const parameter::ParameterGroup& param );
56 
57  void reset();
58  };
59 
60  // Forwarding types from PhysicalModel.
61  typedef typename PhysicalModel::ReservoirState ReservoirState;
62  typedef typename PhysicalModel::WellState WellState;
63 
64  // --------- Public methods ---------
65 
73  explicit NewtonSolver(const SolverParameters& param,
74  std::unique_ptr<PhysicalModel> model);
75 
82  int
83  step(const double dt,
84  ReservoirState& reservoir_state,
85  WellState& well_state);
86 
88  unsigned int newtonIterations() const;
89 
91  unsigned int linearIterations() const;
92 
94  unsigned int newtonIterationsLastStep() const;
95 
97  unsigned int linearIterationsLastStep() const;
98 
99  private:
100  // --------- Data members ---------
101  SolverParameters param_;
102  std::unique_ptr<PhysicalModel> model_;
103  unsigned int newtonIterations_;
104  unsigned int linearIterations_;
105  unsigned int newtonIterationsLast_;
106  unsigned int linearIterationsLast_;
107 
108  // --------- Private methods ---------
109  enum RelaxType relaxType() const { return param_.relax_type_; }
110  double relaxMax() const { return param_.relax_max_; }
111  double relaxIncrement() const { return param_.relax_increment_; }
112  double relaxRelTol() const { return param_.relax_rel_tol_; }
113  double maxIter() const { return param_.max_iter_; }
114  double minIter() const { return param_.min_iter_; }
115  void detectNewtonOscillations(const std::vector<std::vector<double>>& residual_history,
116  const int it, const double relaxRelTol,
117  bool& oscillate, bool& stagnate) const;
118  void stabilizeNewton(V& dx, V& dxOld, const double omega, const RelaxType relax_type) const;
119  };
120 } // namespace Opm
121 
122 #include "NewtonSolver_impl.hpp"
123 
124 #endif // OPM_NEWTONSOLVER_HEADER_INCLUDED
int min_iter_
Definition: NewtonSolver.hpp:52
int max_iter_
Definition: NewtonSolver.hpp:51
PhysicalModel::ReservoirState ReservoirState
Definition: NewtonSolver.hpp:61
Eigen::Array< double, Eigen::Dynamic, 1 > V
Underlying type for values.
Definition: AutoDiffBlock.hpp:98
int step(const double dt, ReservoirState &reservoir_state, WellState &well_state)
Definition: NewtonSolver_impl.hpp:56
Definition: AdditionalObjectDeleter.hpp:22
void reset()
Definition: NewtonSolver_impl.hpp:137
PhysicalModel::WellState WellState
Definition: NewtonSolver.hpp:62
double relax_rel_tol_
Definition: NewtonSolver.hpp:50
unsigned int newtonIterations() const
Number of Newton iterations used in all calls to step().
Definition: NewtonSolver_impl.hpp:41
double relax_max_
Definition: NewtonSolver.hpp:48
NewtonSolver(const SolverParameters &param, std::unique_ptr< PhysicalModel > model)
Definition: NewtonSolver_impl.hpp:31
RelaxType
Definition: NewtonSolver.hpp:42
Definition: NewtonSolver.hpp:42
double relax_increment_
Definition: NewtonSolver.hpp:49
A Newton solver class suitable for general fully-implicit models.
Definition: NewtonSolver.hpp:33
unsigned int linearIterationsLastStep() const
Number of linear solver iterations used in the last call to step().
ADB::M M
Definition: NewtonSolver.hpp:39
Definition: AutoDiffMatrix.hpp:43
unsigned int newtonIterationsLastStep() const
Number of linear solver iterations used in the last call to step().
AutoDiffBlock< double > ADB
Definition: NewtonSolver.hpp:37
SolverParameters()
Definition: NewtonSolver_impl.hpp:150
enum RelaxType relax_type_
Definition: NewtonSolver.hpp:47
unsigned int linearIterations() const
Number of linear solver iterations used in all calls to step().
Definition: NewtonSolver_impl.hpp:47
Definition: NewtonSolver.hpp:45
Definition: NewtonSolver.hpp:42
ADB::V V
Definition: NewtonSolver.hpp:38