My Project
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  virtual std::size_t operator[](std::size_t i) const
78  {
79  return i;
80  }
81 };
82 
83 struct RealReorderer : public Reorderer
84 {
85  RealReorderer(const std::vector<std::size_t>& ordering)
86  : ordering_(&ordering)
87  {}
88  virtual std::size_t operator[](std::size_t i) const
89  {
90  return (*ordering_)[i];
91  }
92  const std::vector<std::size_t>* ordering_;
93 };
94 
95 
96 template<class M>
97 using FieldFunct = std::function<typename M::field_type(const typename M::field_type&)>;
98 
99 template <typename M>
100 void milu0_decomposition(M& A, FieldFunct<M> absFunctor = signFunctor<typename M::field_type>,
101  FieldFunct<M> signFunctor = oneFunctor<typename M::field_type>,
102  std::vector<typename M::block_type>* diagonal = nullptr);
103 
104 template<class M>
105 void milu0_decomposition(M& A, std::vector<typename M::block_type>* diagonal)
106 {
107  milu0_decomposition(A, identityFunctor<typename M::field_type>, oneFunctor<typename M::field_type>, diagonal);
108 }
109 
110 
111 template<class M>
112 void milun_decomposition(const M& A, int n, MILU_VARIANT milu, M& ILU,
113  Reorderer& ordering, Reorderer& inverseOrdering);
114 
115 } // end namespace details
116 
117 } // end namespace Opm
118 
119 #endif
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
MILU_VARIANT
Definition: MILU.hpp:34
@ MILU_1
sum(dropped entries)
@ MILU_2
sum(dropped entries)
@ MILU_3
sum(|dropped entries|)
@ MILU_4
sum(dropped entries)
@ ILU
Do not perform modified ILU.
Definition: MILU.hpp:76
Definition: MILU.hpp:84
Definition: MILU.hpp:70