20#ifndef OPM_OWNINGTWOLEVELPRECONDITIONER_HEADER_INCLUDED
21#define OPM_OWNINGTWOLEVELPRECONDITIONER_HEADER_INCLUDED
23#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
24#include <opm/simulators/linalg/PressureSolverPolicy.hpp>
27#include <opm/common/ErrorMacros.hpp>
29#include <dune/common/fmatrix.hh>
30#include <dune/istl/bcrsmatrix.hh>
31#include <dune/istl/paamg/amg.hh>
42template <
class Operator,
class Comm = Dune::Amg::SequentialInformation>
43class PreconditionerFactory;
51template <
class Operator>
54template <
typename T,
typename A,
int i>
55std::ostream& operator<<(std::ostream& out,
56 const BlockVector< FieldVector< T, i >, A >& vector)
58 Dune::writeMatrixMarket(vector, out);
62 template <
typename T,
typename A,
int i>
63 std::istream& operator>>(std::istream& input,
64 BlockVector< FieldVector< T, i >, A >& vector)
66 Dune::readMatrixMarket(vector, input);
74template <
class OperatorType,
76 class LevelTransferPolicy,
77 class Communication = Dune::Amg::SequentialInformation>
81 using MatrixType =
typename OperatorType::matrix_type;
83 using AbstractOperatorType = Dune::AssembledLinearOperator<MatrixType, VectorType, VectorType>;
86 const std::function<VectorType()> weightsCalculator,
87 std::size_t pressureIndex)
88 : linear_operator_(linearoperator)
90 prm.get_child_optional(
"finesmoother") ?
92 std::function<VectorType()>(), pressureIndex))
94 , weightsCalculator_(weightsCalculator)
95 , weights_(weightsCalculator())
96 , levelTransferPolicy_(dummy_comm_, weights_, prm, pressureIndex)
97 , coarseSolverPolicy_(prm.get_child_optional(
"coarsesolver") ? prm.get_child(
"coarsesolver") :
Opm::PropertyTree())
98 , twolevel_method_(linearoperator,
100 levelTransferPolicy_,
102 prm.get<
int>(
"pre_smooth", 0),
103 prm.get<
int>(
"post_smooth", 1))
106 if (prm.get<
int>(
"verbosity", 0) > 10) {
107 std::string filename = prm.get<std::string>(
"weights_filename",
"impes_weights.txt");
108 std::ofstream outfile(filename);
110 OPM_THROW(std::ofstream::failure,
111 "Could not write weights to file " + filename +
".");
113 Dune::writeMatrixMarket(weights_, outfile);
118 const std::function<VectorType()> weightsCalculator,
119 std::size_t pressureIndex,
const Communication& comm)
120 : linear_operator_(linearoperator)
122 prm.get_child_optional(
"finesmoother") ?
124 std::function<VectorType()>(),
125 comm, pressureIndex))
127 , weightsCalculator_(weightsCalculator)
128 , weights_(weightsCalculator())
129 , levelTransferPolicy_(*comm_, weights_, prm, pressureIndex)
130 , coarseSolverPolicy_(prm.get_child_optional(
"coarsesolver") ? prm.get_child(
"coarsesolver") :
Opm::PropertyTree())
131 , twolevel_method_(linearoperator,
133 levelTransferPolicy_,
135 prm.get<
int>(
"pre_smooth", 0),
136 prm.get<
int>(
"post_smooth", 1))
139 if (prm.get<
int>(
"verbosity", 0) > 10 && comm.communicator().rank() == 0) {
140 auto filename = prm.get<std::string>(
"weights_filename",
"impes_weights.txt");
141 std::ofstream outfile(filename);
143 OPM_THROW(std::ofstream::failure,
144 "Could not write weights to file " + filename +
".");
146 Dune::writeMatrixMarket(weights_, outfile);
150 virtual void pre(VectorType& x, VectorType& b)
override
152 twolevel_method_.pre(x, b);
155 virtual void apply(VectorType& v,
const VectorType& d)
override
157 twolevel_method_.apply(v, d);
160 virtual void post(VectorType& x)
override
162 twolevel_method_.post(x);
165 virtual void update()
override
167 weights_ = weightsCalculator_();
171 virtual Dune::SolverCategory::Category category()
const override
173 return linear_operator_.category();
177 using CoarseOperator =
typename LevelTransferPolicy::CoarseOperator;
180 LevelTransferPolicy>;
185 template <
class Comm>
186 void updateImpl(
const Comm*)
189 auto child = prm_.get_child_optional(
"finesmoother");
191 twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
194 void updateImpl(
const Dune::Amg::SequentialInformation*)
197 auto child = prm_.get_child_optional(
"finesmoother");
199 twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
202 const OperatorType& linear_operator_;
203 std::shared_ptr<Dune::Preconditioner<VectorType, VectorType>> finesmoother_;
204 const Communication* comm_;
205 std::function<VectorType()> weightsCalculator_;
207 LevelTransferPolicy levelTransferPolicy_;
211 Communication dummy_comm_;
A solver class that encapsulates all needed objects for a linear solver (operator,...
Definition: FlexibleSolver.hpp:45
A version of the two-level preconditioner that is:
Definition: OwningTwoLevelPreconditioner.hpp:79
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:32
This is an object factory for creating preconditioners.
Definition: PreconditionerFactory.hpp:64
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:486
Definition: PropertyTree.hpp:37
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Algebraic twolevel methods.