2019-05-20 06:23:57 -05:00
|
|
|
/*
|
2020-06-17 14:07:13 -05:00
|
|
|
Copyright 2019, 2020 SINTEF Digital, Mathematics and Cybernetics.
|
|
|
|
Copyright 2020 Equinor.
|
2019-05-20 06:23:57 -05:00
|
|
|
|
|
|
|
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_FLEXIBLE_SOLVER_HEADER_INCLUDED
|
|
|
|
#define OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
|
|
|
|
|
2020-06-17 06:03:57 -05:00
|
|
|
#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
|
2021-06-09 03:35:22 -05:00
|
|
|
#include <opm/simulators/linalg/PropertyTree.hpp>
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2020-06-19 09:37:43 -05:00
|
|
|
#include <dune/istl/solver.hh>
|
2020-04-02 10:10:43 -05:00
|
|
|
#include <dune/istl/paamg/pinfo.hh>
|
2019-05-20 06:23:57 -05:00
|
|
|
|
|
|
|
namespace Dune
|
|
|
|
{
|
|
|
|
|
2019-06-11 02:14:40 -05:00
|
|
|
/// A solver class that encapsulates all needed objects for a linear solver
|
|
|
|
/// (operator, scalar product, iterative solver and preconditioner) and sets
|
|
|
|
/// them up based on runtime parameters, using the PreconditionerFactory for
|
|
|
|
/// setting up preconditioners.
|
2021-01-04 08:18:23 -06:00
|
|
|
template <class Operator>
|
|
|
|
class FlexibleSolver : public Dune::InverseOperator<typename Operator::domain_type,
|
|
|
|
typename Operator::range_type>
|
2019-05-20 06:23:57 -05:00
|
|
|
{
|
|
|
|
public:
|
2021-01-04 08:18:23 -06:00
|
|
|
using VectorType = typename Operator::domain_type; // Assuming symmetry: domain == range
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2020-06-19 09:45:34 -05:00
|
|
|
/// Base class type of the contained preconditioner.
|
|
|
|
using AbstractPrecondType = Dune::PreconditionerWithUpdate<VectorType, VectorType>;
|
|
|
|
|
2019-05-20 07:31:36 -05:00
|
|
|
/// Create a sequential solver.
|
2021-01-04 08:18:23 -06:00
|
|
|
FlexibleSolver(Operator& op,
|
2021-06-09 03:35:22 -05:00
|
|
|
const Opm::PropertyTree& prm,
|
2021-06-08 14:51:34 -05:00
|
|
|
const std::function<VectorType()>& weightsCalculator,
|
|
|
|
std::size_t pressureIndex);
|
2019-05-20 07:31:36 -05:00
|
|
|
|
|
|
|
/// Create a parallel solver (if Comm is e.g. OwnerOverlapCommunication).
|
|
|
|
template <class Comm>
|
2021-01-04 08:18:23 -06:00
|
|
|
FlexibleSolver(Operator& op,
|
2020-06-17 02:31:19 -05:00
|
|
|
const Comm& comm,
|
2021-06-09 03:35:22 -05:00
|
|
|
const Opm::PropertyTree& prm,
|
2021-06-08 14:51:34 -05:00
|
|
|
const std::function<VectorType()>& weightsCalculator,
|
|
|
|
std::size_t pressureIndex);
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2020-06-10 13:54:16 -05:00
|
|
|
virtual void apply(VectorType& x, VectorType& rhs, Dune::InverseOperatorResult& res) override;
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2020-06-10 13:54:16 -05:00
|
|
|
virtual void apply(VectorType& x, VectorType& rhs, double reduction, Dune::InverseOperatorResult& res) override;
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2019-06-11 02:14:40 -05:00
|
|
|
/// Access the contained preconditioner.
|
2020-06-10 13:54:16 -05:00
|
|
|
AbstractPrecondType& preconditioner();
|
2019-05-20 07:31:36 -05:00
|
|
|
|
2020-06-10 13:54:16 -05:00
|
|
|
virtual Dune::SolverCategory::Category category() const override;
|
2019-05-20 06:23:57 -05:00
|
|
|
|
|
|
|
private:
|
2019-05-20 07:31:36 -05:00
|
|
|
using AbstractScalarProductType = Dune::ScalarProduct<VectorType>;
|
|
|
|
using AbstractSolverType = Dune::InverseOperator<VectorType, VectorType>;
|
|
|
|
|
|
|
|
// Machinery for making sequential or parallel operators/preconditioners/scalar products.
|
|
|
|
template <class Comm>
|
2021-01-04 08:18:23 -06:00
|
|
|
void initOpPrecSp(Operator& op, const Opm::PropertyTree& prm,
|
2021-06-08 14:51:34 -05:00
|
|
|
const std::function<VectorType()> weightsCalculator, const Comm& comm,
|
|
|
|
std::size_t pressureIndex);
|
2019-06-06 03:36:17 -05:00
|
|
|
|
2021-01-04 08:18:23 -06:00
|
|
|
void initOpPrecSp(Operator& op, const Opm::PropertyTree& prm,
|
2021-06-08 14:51:34 -05:00
|
|
|
const std::function<VectorType()> weightsCalculator, const Dune::Amg::SequentialInformation&,
|
|
|
|
std::size_t pressureIndex);
|
2019-05-20 06:23:57 -05:00
|
|
|
|
2021-06-09 03:35:22 -05:00
|
|
|
void initSolver(const Opm::PropertyTree& prm, const bool is_iorank);
|
2019-05-20 07:31:36 -05:00
|
|
|
|
|
|
|
// Main initialization routine.
|
|
|
|
// Call with Comm == Dune::Amg::SequentialInformation to get a serial solver.
|
|
|
|
template <class Comm>
|
2021-01-04 08:18:23 -06:00
|
|
|
void init(Operator& op,
|
2020-06-17 02:31:19 -05:00
|
|
|
const Comm& comm,
|
2021-06-09 03:35:22 -05:00
|
|
|
const Opm::PropertyTree& prm,
|
2021-06-08 14:51:34 -05:00
|
|
|
const std::function<VectorType()> weightsCalculator,
|
|
|
|
std::size_t pressureIndex);
|
2019-05-20 07:31:36 -05:00
|
|
|
|
2021-01-04 08:18:23 -06:00
|
|
|
Operator* linearoperator_for_solver_;
|
2019-05-20 07:31:36 -05:00
|
|
|
std::shared_ptr<AbstractPrecondType> preconditioner_;
|
|
|
|
std::shared_ptr<AbstractScalarProductType> scalarproduct_;
|
|
|
|
std::shared_ptr<AbstractSolverType> linsolver_;
|
2019-05-20 06:23:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Dune
|
|
|
|
|
2022-05-19 04:35:11 -05:00
|
|
|
//#include <opm/simulators/linalg/FlexibleSolver_impl.hpp>
|
2019-05-20 06:23:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
#endif // OPM_FLEXIBLE_SOLVER_HEADER_INCLUDED
|