opm-simulators
MILU.hpp
1 /*
2  Copyright 2015, 2022 Dr. Blatt - HPC-Simulation-Software & Services
3  Copyright 2015 Statoil AS
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 #ifndef OPM_MILU_HEADER_INCLUDED
21 #define OPM_MILU_HEADER_INCLUDED
22 
23 #include <cmath>
24 #include <cstddef>
25 #include <functional>
26 #include <string>
27 #include <vector>
28 
29 
30 
31 namespace Opm
32 {
33 
34 enum class MILU_VARIANT{
36  ILU = 0,
38  MILU_1 = 1,
40  MILU_2 = 2,
42  MILU_3 = 3,
44  MILU_4 = 4
45 };
46 
47 MILU_VARIANT convertString2Milu(const std::string& milu);
48 
49 
50 namespace detail
51 {
52 
53 template <typename T>
54 T identityFunctor(const T&);
55 
56 template <typename T>
57 T oneFunctor(const T&);
58 
59 template <typename T>
60 T signFunctor(const T&);
61 
62 template <typename T>
63 T isPositiveFunctor(const T&);
64 
65 template <typename T>
66 T absFunctor(const T&);
67 
68 
69 struct Reorderer
70 {
71  virtual std::size_t operator[](std::size_t i) const = 0;
72  virtual ~Reorderer() {}
73 };
74 
75 struct NoReorderer : public Reorderer
76 {
77  std::size_t operator[](std::size_t i) const override
78  {
79  return i;
80  }
81 };
82 
83 struct RealReorderer : public Reorderer
84 {
85  explicit RealReorderer(const std::vector<std::size_t>& ordering)
86  : ordering_(&ordering)
87  {}
88 
89  std::size_t operator[](std::size_t i) const override
90  {
91  return (*ordering_)[i];
92  }
93 
94  const std::vector<std::size_t>* ordering_;
95 };
96 
97 
98 template<class M>
99 using FieldFunct = std::function<typename M::field_type(const typename M::field_type&)>;
100 
101 template <typename M>
102 void milu0_decomposition(M& A, FieldFunct<M> absFunctor = signFunctor<typename M::field_type>,
103  FieldFunct<M> signFunctor = oneFunctor<typename M::field_type>,
104  std::vector<typename M::block_type>* diagonal = nullptr);
105 
106 template<class M>
107 void milu0_decomposition(M& A, std::vector<typename M::block_type>* diagonal)
108 {
109  milu0_decomposition(A, identityFunctor<typename M::field_type>, oneFunctor<typename M::field_type>, diagonal);
110 }
111 
112 
113 template<class M>
114 void milun_decomposition(const M& A, int n, MILU_VARIANT milu, M& ILU,
115  Reorderer& ordering, Reorderer& inverseOrdering);
116 
117 } // end namespace details
118 
119 } // end namespace Opm
120 
121 #endif
MILU_VARIANT
Definition: MILU.hpp:34
Do not perform modified ILU.
Definition: MILU.hpp:83
Definition: MILU.hpp:75
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
sum(dropped entries)
sum(|dropped entries|)
Definition: MILU.hpp:69
sum(dropped entries)
sum(dropped entries)