Loading...
Searching...
No Matches
PreconditionerFactory.hpp
/*
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_PRECONDITIONERFACTORY_HEADER
#define OPM_PRECONDITIONERFACTORY_HEADER
#include <opm/common/TimingMacros.hpp>
#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
#include <dune/istl/paamg/aggregates.hh>
#include <dune/istl/paamg/matrixhierarchy.hh>
#include <cstddef>
#include <map>
#include <memory>
#include <limits>
#include <string>
namespace Opm
{
class PropertyTree;
template <class Operator, class Comm, class Matrix, class Vector>
struct AMGHelper
{
using PrecPtr = std::shared_ptr<Dune::PreconditionerWithUpdate<Vector, Vector>>;
using CriterionBase
= Dune::Amg::AggregationCriterion<Dune::Amg::SymmetricDependency<Matrix, Dune::Amg::FirstDiagonal>>;
using Criterion = Dune::Amg::CoarsenCriterion<CriterionBase>;
static Criterion criterion(const PropertyTree& prm);
template <class Smoother>
static PrecPtr makeAmgPreconditioner(const Operator& op,
const PropertyTree& prm,
bool useKamg = false);
};
template <class Operator, class Comm>
class PreconditionerFactory
{
public:
using Matrix = typename Operator::matrix_type;
using Vector = typename Operator::domain_type; // Assuming symmetry: that domain and range types are the same.
using PrecPtr = std::shared_ptr<Dune::PreconditionerWithUpdate<Vector, Vector>>;
using Creator = std::function<PrecPtr(const Operator&, const PropertyTree&,
const std::function<Vector()>&, std::size_t)>;
using ParCreator = std::function<PrecPtr(const Operator&, const PropertyTree&,
const std::function<Vector()>&, std::size_t, const Comm&)>;
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());
static PrecPtr create(const Operator& op, const PropertyTree& prm,
const std::function<Vector()>& weightsCalculator, const Comm& comm,
std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
static PrecPtr create(const Operator& op, const PropertyTree& prm, const Comm& comm,
std::size_t pressureIndex = std::numeric_limits<std::size_t>::max());
static void addCreator(const std::string& type, Creator creator);
static void addCreator(const std::string& type, ParCreator creator);
using CriterionBase
= Dune::Amg::AggregationCriterion<Dune::Amg::SymmetricDependency<Matrix, Dune::Amg::FirstDiagonal>>;
using Criterion = Dune::Amg::CoarsenCriterion<CriterionBase>;
private:
// The method that implements the singleton pattern,
// using the Meyers singleton technique.
static PreconditionerFactory& instance();
// Private constructor, to keep users from creating a PreconditionerFactory.
PreconditionerFactory();
// Actually creates the product object.
PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
const std::function<Vector()> weightsCalculator,
std::size_t pressureIndex);
PrecPtr doCreate(const Operator& op, const PropertyTree& prm,
const std::function<Vector()> weightsCalculator,
std::size_t pressureIndex, const Comm& comm);
// Actually adds the creator.
void doAddCreator(const std::string& type, Creator c);
// Actually adds the creator.
void doAddCreator(const std::string& type, ParCreator c);
// This map contains the whole factory, i.e. all the Creators.
std::map<std::string, Creator> creators_;
std::map<std::string, ParCreator> parallel_creators_;
bool defAdded_= false;
};
} // namespace Dune
#endif // OPM_PRECONDITIONERFACTORY_HEADER
Opm::PreconditionerFactory::addCreator
static void addCreator(const std::string &type, ParCreator creator)
Add a creator for a parallel preconditioner to the PreconditionerFactory.
Definition PreconditionerFactory_impl.hpp:193
Opm::PreconditionerFactory< OperatorType, Communication >::PrecPtr
std::shared_ptr< Dune::PreconditionerWithUpdate< Vector, Vector > > PrecPtr
Definition PreconditionerFactory.hpp:71
Opm::PreconditionerFactory::create
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())
Create a new serial preconditioner and return a pointer to it.
Definition PreconditionerFactory_impl.hpp:154
Opm::PreconditionerFactory::create
static PrecPtr create(const Operator &op, const PropertyTree &prm, const Comm &comm, std::size_t pressureIndex=std::numeric_limits< std::size_t >::max())
Create a new parallel preconditioner and return a pointer to it.
Definition PreconditionerFactory_impl.hpp:176
Opm::PreconditionerFactory::addCreator
static void addCreator(const std::string &type, Creator creator)
Add a creator for a serial preconditioner to the PreconditionerFactory.
Definition PreconditionerFactory_impl.hpp:186
Opm::PreconditionerFactory< OperatorType, Communication >::Creator
std::function< PrecPtr(const OperatorType &, const PropertyTree &, const std::function< Vector()> &, std::size_t)> Creator
Definition PreconditionerFactory.hpp:74
Opm::PreconditionerFactory::create
static PrecPtr create(const Operator &op, const PropertyTree &prm, const std::function< Vector()> &weightsCalculator, const Comm &comm, std::size_t pressureIndex=std::numeric_limits< std::size_t >::max())
Create a new parallel preconditioner and return a pointer to it.
Definition PreconditionerFactory_impl.hpp:164
Opm::PreconditionerFactory< OperatorType, Communication >::Matrix
typename OperatorType::matrix_type Matrix
Definition PreconditionerFactory.hpp:67
Opm::PropertyTree
Hierarchical collection of key/value pairs.
Definition PropertyTree.hpp:39
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::AMGHelper
Definition PreconditionerFactory.hpp:43