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
85 static PrecPtr create(const Operator& op, const PropertyTree& prm,
86 const std::function<Vector()>& weightsCalculator = {},
87 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
88
96 static PrecPtr create(const Operator& op, const PropertyTree& prm,
97 const std::function<Vector()>& weightsCalculator, const Comm& comm,
98 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
99
106 static PrecPtr create(const Operator& op, const PropertyTree& prm, const Comm& comm,
107 std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
108
116 static void addCreator(const std::string& type, Creator creator);
117
125 static void addCreator(const std::string& type, ParCreator creator);
126
128 = Dune::Amg::AggregationCriterion<Dune::Amg::SymmetricDependency<Matrix, Dune::Amg::FirstDiagonal>>;
129 using Criterion = Dune::Amg::CoarsenCriterion<CriterionBase>;
130
131
132private:
133 // The method that implements the singleton pattern,
134 // using the Meyers singleton technique.
135 static PreconditionerFactory& instance();
136
137 // Private constructor, to keep users from creating a PreconditionerFactory.
139
140 // Actually creates the product object.
141 PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
142 const std::function<Vector()> weightsCalculator,
143 std::size_t pressureIndex);
144
145 PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
146 const std::function<Vector()> weightsCalculator,
147 std::size_t pressureIndex, const Comm& comm);
148
149 // Actually adds the creator.
150 void doAddCreator(const std::string& type, Creator c);
151
152 // Actually adds the creator.
153 void doAddCreator(const std::string& type, ParCreator c);
154
155 // This map contains the whole factory, i.e. all the Creators.
156 std::map<std::string, Creator> creators_;
157 std::map<std::string, ParCreator> parallel_creators_;
158 bool defAdded_= false;
159};
160
161} // namespace Dune
162
163#endif // OPM_PRECONDITIONERFACTORY_HEADER
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:304
Definition: PreconditionerFactory.hpp:64
Dune::Amg::AggregationCriterion< Dune::Amg::SymmetricDependency< Matrix, Dune::Amg::FirstDiagonal > > CriterionBase
Definition: PreconditionerFactory.hpp:128
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:154
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:186
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:129
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
Definition: blackoilboundaryratevector.hh:39
Definition: PreconditionerFactory.hpp:43
Dune::Amg::CoarsenCriterion< CriterionBase > Criterion
Definition: PreconditionerFactory.hpp:47
static Criterion criterion(const PropertyTree &prm)
Definition: StandardPreconditioners_mpi.hpp:83
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: StandardPreconditioners_mpi.hpp:110
Dune::Amg::AggregationCriterion< Dune::Amg::SymmetricDependency< Matrix, Dune::Amg::FirstDiagonal > > CriterionBase
Definition: PreconditionerFactory.hpp:46