PreconditionerFactory.hpp
Go to the documentation of this file.
1
2/*
3 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
4 Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
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 3 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*/
21
22#ifndef OPM_PRECONDITIONERFACTORY_HEADER
23#define OPM_PRECONDITIONERFACTORY_HEADER
24#include <opm/common/TimingMacros.hpp>
26
27#include <dune/istl/paamg/aggregates.hh>
28#include <dune/istl/paamg/matrixhierarchy.hh>
29
30#include <cstddef>
31#include <map>
32#include <memory>
33#include <limits>
34#include <string>
35
36namespace Opm
37{
38
39class PropertyTree;
40
41template <class Operator, class Comm, class Matrix, class Vector>
43{
44 using PrecPtr = std::shared_ptr<Dune::PreconditionerWithUpdate<Vector, Vector>>;
46 = Dune::Amg::AggregationCriterion<Dune::Amg::SymmetricDependency<Matrix, Dune::Amg::FirstDiagonal>>;
47 using Criterion = Dune::Amg::CoarsenCriterion<CriterionBase>;
48
49 static Criterion criterion(const PropertyTree& prm);
50
51 template <class Smoother>
52 static PrecPtr makeAmgPreconditioner(const Operator& op,
53 const PropertyTree& prm,
54 bool useKamg = false);
55};
56
62template <class Operator, class Comm>
64{
65public:
67 using Matrix = typename Operator::matrix_type;
68 using Vector = typename Operator::domain_type; // Assuming symmetry: that domain and range types are the same.
69
71 using PrecPtr = std::shared_ptr<Dune::PreconditionerWithUpdate<Vector, Vector>>;
72
74 using Creator = std::function<PrecPtr(const Operator&, const PropertyTree&,
75 const std::function<Vector()>&, std::size_t)>;
76 using ParCreator = std::function<PrecPtr(const Operator&, const PropertyTree&,
77 const std::function<Vector()>&, std::size_t, const Comm&)>;
78
84 static PrecPtr create(const Operator& op, const PropertyTree& prm,
85 const std::function<Vector()>& weightsCalculator = {},
86 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
87
94 static PrecPtr create(const Operator& op, const PropertyTree& prm,
95 const std::function<Vector()>& weightsCalculator, const Comm& comm,
96 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
97
103 static PrecPtr create(const Operator& op, const PropertyTree& prm, const Comm& comm,
104 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
105
113 static void addCreator(const std::string& type, Creator creator);
114
122 static void addCreator(const std::string& type, ParCreator creator);
123
125 = Dune::Amg::AggregationCriterion<Dune::Amg::SymmetricDependency<Matrix, Dune::Amg::FirstDiagonal>>;
126 using Criterion = Dune::Amg::CoarsenCriterion<CriterionBase>;
127
128
129private:
130 // The method that implements the singleton pattern,
131 // using the Meyers singleton technique.
132 static PreconditionerFactory& instance();
133
134 // Private constructor, to keep users from creating a PreconditionerFactory.
136
137 // Actually creates the product object.
138 PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
139 const std::function<Vector()> weightsCalculator,
140 std::size_t pressureIndex);
141
142 PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
143 const std::function<Vector()> weightsCalculator,
144 std::size_t pressureIndex, const Comm& comm);
145
146 // Actually adds the creator.
147 void doAddCreator(const std::string& type, Creator c);
148
149 // Actually adds the creator.
150 void doAddCreator(const std::string& type, ParCreator c);
151
152 // This map contains the whole factory, i.e. all the Creators.
153 std::map<std::string, Creator> creators_;
154 std::map<std::string, ParCreator> parallel_creators_;
155 bool defAdded_= false;
156};
157
158} // namespace Dune
159
160#endif // OPM_PRECONDITIONERFACTORY_HEADER
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:270
Definition: PreconditionerFactory.hpp:64
Dune::Amg::AggregationCriterion< Dune::Amg::SymmetricDependency< Matrix, Dune::Amg::FirstDiagonal > > CriterionBase
Definition: PreconditionerFactory.hpp:125
static PrecPtr create(const Operator &op, const PropertyTree &prm, const std::function< Vector()> &weightsCalculator={}, std::size_t pressureIndex=std::numeric_limits< std::size_t >::max())
Definition: PreconditionerFactory_impl.hpp:702
std::function< PrecPtr(const Operator &, const PropertyTree &, const std::function< Vector()> &, std::size_t, const Comm &)> ParCreator
Definition: PreconditionerFactory.hpp:77
typename Operator::domain_type Vector
Definition: PreconditionerFactory.hpp:68
std::function< PrecPtr(const Operator &, const PropertyTree &, const std::function< Vector()> &, std::size_t)> Creator
The type of creator functions passed to addCreator().
Definition: PreconditionerFactory.hpp:75
static void addCreator(const std::string &type, Creator creator)
Definition: PreconditionerFactory_impl.hpp:734
std::shared_ptr< Dune::PreconditionerWithUpdate< Vector, Vector > > PrecPtr
The type of pointer returned by create().
Definition: PreconditionerFactory.hpp:71
typename Operator::matrix_type Matrix
Linear algebra types.
Definition: PreconditionerFactory.hpp:67
Dune::Amg::CoarsenCriterion< CriterionBase > Criterion
Definition: PreconditionerFactory.hpp:126
Definition: PropertyTree.hpp:37
Definition: BlackoilPhases.hpp:27
Definition: PreconditionerFactory.hpp:43
Dune::Amg::CoarsenCriterion< CriterionBase > Criterion
Definition: PreconditionerFactory.hpp:47
static Criterion criterion(const PropertyTree &prm)
Definition: PreconditionerFactory_impl.hpp:112
std::shared_ptr< Dune::PreconditionerWithUpdate< Vector, Vector > > PrecPtr
Definition: PreconditionerFactory.hpp:44
static PrecPtr makeAmgPreconditioner(const Operator &op, const PropertyTree &prm, bool useKamg=false)
Definition: PreconditionerFactory_impl.hpp:139
Dune::Amg::AggregationCriterion< Dune::Amg::SymmetricDependency< Matrix, Dune::Amg::FirstDiagonal > > CriterionBase
Definition: PreconditionerFactory.hpp:46