81 using MatrixType =
typename OperatorType::matrix_type;
83 using AbstractOperatorType = Dune::AssembledLinearOperator<MatrixType, VectorType, VectorType>;
85 OwningTwoLevelPreconditioner(
const OperatorType& linearoperator,
const Opm::PropertyTree& prm,
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);
118 OwningTwoLevelPreconditioner(
const OperatorType& linearoperator,
const Opm::PropertyTree& prm,
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_;
210 CoarseSolverPolicy coarseSolverPolicy_;
211 TwoLevelMethod twolevel_method_;
213 Communication dummy_comm_;