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> 34 #include <type_traits> 42 template <
class Operator,
class Comm = Dune::Amg::SequentialInformation>
51 template <
class Operator>
54 template <
typename T,
typename A,
int i>
55 std::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);
74 template <
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)
92 std::function<VectorType()>(), pressureIndex))
94 , weightsCalculator_(weightsCalculator)
95 , weights_(weightsCalculator())
96 , levelTransferPolicy_(dummy_comm_, weights_, prm, pressureIndex)
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 +
".");
114 writeMatrixMarket(weights_, outfile);
119 const std::function<VectorType()> weightsCalculator,
120 std::size_t pressureIndex,
const Communication& comm)
121 : linear_operator_(linearoperator)
125 std::function<VectorType()>(),
126 comm, pressureIndex))
128 , weightsCalculator_(weightsCalculator)
129 , weights_(weightsCalculator())
130 , levelTransferPolicy_(*comm_, weights_, prm, pressureIndex)
132 , twolevel_method_(linearoperator,
134 levelTransferPolicy_,
136 prm.
get<
int>(
"pre_smooth", 0),
137 prm.
get<
int>(
"post_smooth", 1))
140 if (prm.
get<
int>(
"verbosity", 0) > 10 && comm.communicator().rank() == 0) {
141 auto filename = prm.
get<std::string>(
"weights_filename",
"impes_weights.txt");
142 std::ofstream outfile(filename);
144 OPM_THROW(std::ofstream::failure,
145 "Could not write weights to file " + filename +
".");
148 writeMatrixMarket(weights_, outfile);
152 virtual void pre(VectorType& x, VectorType& b)
override 154 twolevel_method_.pre(x, b);
157 virtual void apply(VectorType& v,
const VectorType& d)
override 159 twolevel_method_.apply(v, d);
162 virtual void post(VectorType& x)
override 164 twolevel_method_.post(x);
167 virtual void update()
override 169 weights_ = weightsCalculator_();
173 virtual Dune::SolverCategory::Category category()
const override 175 return linear_operator_.category();
178 virtual bool hasPerfectUpdate()
const override {
179 return twolevel_method_.hasPerfectUpdate();
183 using CoarseOperator =
typename LevelTransferPolicy::CoarseOperator;
186 LevelTransferPolicy>;
191 template <
class Comm>
192 void updateImpl(
const Comm*)
195 twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
198 void updateImpl(
const Dune::Amg::SequentialInformation*)
201 twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
204 const OperatorType& linear_operator_;
205 std::shared_ptr<PreconditionerWithUpdate<VectorType, VectorType>> finesmoother_;
206 const Communication* comm_;
207 std::function<VectorType()> weightsCalculator_;
209 LevelTransferPolicy levelTransferPolicy_;
213 Communication dummy_comm_;
221 #endif // OPM_OWNINGTWOLEVELPRECONDITIONER_HEADER_INCLUDED PropertyTree get_child(const std::string &key) const
Retrieve copy of sub tree rooted at node.
Definition: PropertyTree.cpp:82
T get(const std::string &key) const
Retrieve property value given hierarchical property key.
Definition: PropertyTree.cpp:59
Definition: fvbaseprimaryvariables.hh:161
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.
Definition: FlexibleSolver.hpp:43
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:33
std::optional< PropertyTree > get_child_optional(const std::string &key) const
Retrieve copy of sub tree rooted at node.
Definition: PropertyTree.cpp:90
Algebraic twolevel methods.
A version of the two-level preconditioner that is:
Definition: OwningTwoLevelPreconditioner.hpp:78
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
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:38
This is an object factory for creating preconditioners.
Definition: OwningTwoLevelPreconditioner.hpp:43