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)
89 , finesmoother_(PrecFactory::create(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)
121 , finesmoother_(PrecFactory::create(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");
190 finesmoother_ = PrecFactory::create(linear_operator_, child ? *child :
Opm::PropertyTree(), *comm_);
191 twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
194 void updateImpl(
const Dune::Amg::SequentialInformation*)
197 auto child = prm_.get_child_optional(
"finesmoother");
198 finesmoother_ = PrecFactory::create(linear_operator_, child ? *child :
Opm::PropertyTree());
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_;