19#ifndef OPM_SYSTEMPRECONDITIONER_HEADER_INCLUDED
20#define OPM_SYSTEMPRECONDITIONER_HEADER_INCLUDED
28#include <dune/istl/operators.hh>
29#include <dune/istl/paamg/pinfo.hh>
36template<
typename Scalar>
40using ParResComm = Dune::OwnerOverlapCopyCommunication<int, int>;
41template<
typename Scalar>
55template <
class Scalar,
class ResOp,
class ResComm = Dune::Amg::SequentialInformation>
59 static constexpr bool isParallel = !std::is_same_v<ResComm, Dune::Amg::SequentialInformation>;
65 static constexpr auto _0 = Dune::Indices::_0;
66 static constexpr auto _1 = Dune::Indices::_1;
75 , pressureIndex_(pressureIndex)
77 initSubSolvers(prm, weightsCalculator);
86 const ResComm& resComm)
90 , pressureIndex_(pressureIndex)
92 initSubSolvers(prm, weightsCalculator);
104 Dune::SolverCategory::Category
category()
const override
107 return Dune::SolverCategory::overlapping;
109 return Dune::SolverCategory::sequential;
114 resSolver_->preconditioner().update();
115 resSmoother_->preconditioner().update();
116 wellSolver_->preconditioner().update();
121 resSolver_->preconditioner().update();
122 resSmoother_->preconditioner().update();
124 resizeWellWorkVectors();
144 const auto& A = S_[
_0][
_0];
145 const auto& C = S_[
_0][
_1];
146 const auto& B = S_[
_1][
_0];
147 const auto& D = S_[
_1][
_1];
158 tmp_resRes_ = resRes_;
159 syncResVector(tmp_resRes_);
160 resSolver_->apply(dresSol_, tmp_resRes_, res_result);
163 A.mmv(dresSol_, resRes_);
165 B.mmv(dresSol_, wRes_);
173 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
176 C.mmv(dwSol_, resRes_);
178 D.mmv(dwSol_, wRes_);
182 tmp_resRes_ = resRes_;
183 syncResVector(tmp_resRes_);
184 resSmoother_->apply(dresSol_, tmp_resRes_, res_result);
187 B.mmv(dresSol_, wRes_);
195 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
199 syncResVector(resSol_);
206 const ResComm* resComm_ =
nullptr;
207 int pressureIndex_ = 0;
208 static constexpr int dummyWellPressureIndex = std::numeric_limits<int>::min();
211 std::unique_ptr<ResOp> rop_;
212 std::unique_ptr<WellOperator> wop_;
213 std::unique_ptr<ResFlexibleSolverType> resSolver_;
214 std::unique_ptr<ResFlexibleSolverType> resSmoother_;
215 std::unique_ptr<WellFlexibleSolverType> wellSolver_;
229 resComm_->copyOwnerToAll(v, v);
233 void initWellSolver()
235 wop_ = std::make_unique<WellOperator>(S_[
_1][
_1]);
236 std::function<WellVector<Scalar>()> weightsCalculatorWell;
237 wellSolver_ = std::make_unique<WellFlexibleSolverType>(
238 *wop_, wellprm_, weightsCalculatorWell, dummyWellPressureIndex);
242 const std::function<ResVector<Scalar>()>& weightsCalculator)
244 auto resprm = prm.
get_child(
"reservoir_solver");
245 auto resprmsmoother = prm.
get_child(
"reservoir_smoother");
249 rop_ = std::make_unique<ResOp>(S_[
_0][
_0], *resComm_);
250 resSolver_ = std::make_unique<ResFlexibleSolverType>(
251 *rop_, *resComm_, resprm, weightsCalculator, pressureIndex_);
252 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
253 *rop_, *resComm_, resprmsmoother, weightsCalculator, pressureIndex_);
255 rop_ = std::make_unique<ResOp>(S_[
_0][
_0]);
256 resSolver_ = std::make_unique<ResFlexibleSolverType>(
257 *rop_, resprm, weightsCalculator, pressureIndex_);
258 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
259 *rop_, resprmsmoother, weightsCalculator, pressureIndex_);
265 void initWorkVectors()
267 resizeReservoirWorkVectors();
268 resizeWellWorkVectors();
271 void resizeReservoirWorkVectors()
273 const auto numRes = S_[
_0][
_0].
N();
274 resSol_.resize(numRes);
275 dresSol_.resize(numRes);
276 tmp_resRes_.resize(numRes);
277 resRes_.resize(numRes);
280 void resizeWellWorkVectors()
282 const auto numWell = S_[
_1][
_1].
N();
283 wSol_.resize(numWell);
284 dwSol_.resize(numWell);
285 tmp_wRes_.resize(numWell);
286 wRes_.resize(numWell);
Definition: FlexibleSolver.hpp:45
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:34
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
PropertyTree get_child(const std::string &key) const
Definition: SystemTypes.hpp:77
static constexpr size_type N()
Definition: SystemTypes.hpp:82
Definition: SystemPreconditioner.hpp:57
bool hasPerfectUpdate() const override
Definition: SystemPreconditioner.hpp:127
SystemPreconditioner(const SystemMatrix< Scalar > &S, const std::function< ResVector< Scalar >()> &weightsCalculator, int pressureIndex, const Opm::PropertyTree &prm)
Definition: SystemPreconditioner.hpp:69
void post(SystemVector< Scalar > &) override
Definition: SystemPreconditioner.hpp:100
void pre(SystemVector< Scalar > &, SystemVector< Scalar > &) override
Definition: SystemPreconditioner.hpp:96
Dune::SolverCategory::Category category() const override
Definition: SystemPreconditioner.hpp:104
void updateForChangedWellStructure()
Definition: SystemPreconditioner.hpp:119
static constexpr auto _0
Definition: SystemPreconditioner.hpp:65
static constexpr auto _1
Definition: SystemPreconditioner.hpp:66
Dune::MatrixAdapter< WWMatrix< Scalar >, WellVector< Scalar >, WellVector< Scalar > > WellOperator
Definition: SystemPreconditioner.hpp:62
static constexpr bool isParallel
Definition: SystemPreconditioner.hpp:59
SystemPreconditioner(const SystemMatrix< Scalar > &S, const std::function< ResVector< Scalar >()> &weightsCalculator, int pressureIndex, const Opm::PropertyTree &prm, const ResComm &resComm)
Definition: SystemPreconditioner.hpp:82
void update() override
Definition: SystemPreconditioner.hpp:112
void apply(SystemVector< Scalar > &v, const SystemVector< Scalar > &d) override
Definition: SystemPreconditioner.hpp:141
Definition: blackoilbioeffectsmodules.hh:45
Dune::MultiTypeBlockVector< ResVector< Scalar >, WellVector< Scalar > > SystemVector
Definition: SystemTypes.hpp:59
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
Dune::OverlappingSchwarzOperator< RRMatrix< Scalar >, ResVector< Scalar >, ResVector< Scalar >, ParResComm > ParResOperator
Definition: SystemPreconditioner.hpp:42
Dune::OwnerOverlapCopyCommunication< int, int > ParResComm
Definition: SystemPreconditioner.hpp:40
Dune::MatrixAdapter< RRMatrix< Scalar >, ResVector< Scalar >, ResVector< Scalar > > SeqResOperator
Definition: SystemPreconditioner.hpp:37
Dune::BlockVector< Dune::FieldVector< Scalar, numResDofs > > ResVector
Definition: SystemTypes.hpp:55
Dune::BlockVector< Dune::FieldVector< Scalar, numWellDofs > > WellVector
Definition: SystemTypes.hpp:57