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>
34template<
typename Scalar>
38using ParResComm = Dune::OwnerOverlapCopyCommunication<int, int>;
39template<
typename Scalar>
53template <
class Scalar,
class ResOp,
class ResComm = Dune::Amg::SequentialInformation>
57 static constexpr bool isParallel = !std::is_same_v<ResComm, Dune::Amg::SequentialInformation>;
63 static constexpr auto _0 = Dune::Indices::_0;
64 static constexpr auto _1 = Dune::Indices::_1;
73 , pressureIndex_(pressureIndex)
75 initSubSolvers(prm, weightsCalculator);
84 const ResComm& resComm)
88 , pressureIndex_(pressureIndex)
90 initSubSolvers(prm, weightsCalculator);
102 Dune::SolverCategory::Category
category()
const override
105 return Dune::SolverCategory::overlapping;
107 return Dune::SolverCategory::sequential;
112 resSolver_->preconditioner().update();
113 resSmoother_->preconditioner().update();
114 wellSolver_->preconditioner().update();
119 resSolver_->preconditioner().update();
120 resSmoother_->preconditioner().update();
122 resizeWellWorkVectors();
142 const auto& A = S_[
_0][
_0];
143 const auto& C = S_[
_0][
_1];
144 const auto& B = S_[
_1][
_0];
145 const auto& D = S_[
_1][
_1];
156 tmp_resRes_ = resRes_;
157 syncResVector(tmp_resRes_);
158 resSolver_->apply(dresSol_, tmp_resRes_, res_result);
161 A.mmv(dresSol_, resRes_);
163 B.mmv(dresSol_, wRes_);
171 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
174 C.mmv(dwSol_, resRes_);
176 D.mmv(dwSol_, wRes_);
180 tmp_resRes_ = resRes_;
181 syncResVector(tmp_resRes_);
182 resSmoother_->apply(dresSol_, tmp_resRes_, res_result);
185 B.mmv(dresSol_, wRes_);
193 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
197 syncResVector(resSol_);
204 const ResComm* resComm_ =
nullptr;
205 int pressureIndex_ = 0;
206 static constexpr int dummyWellPressureIndex = std::numeric_limits<int>::min();
209 std::unique_ptr<ResOp> rop_;
210 std::unique_ptr<WellOperator> wop_;
211 std::unique_ptr<ResFlexibleSolverType> resSolver_;
212 std::unique_ptr<ResFlexibleSolverType> resSmoother_;
213 std::unique_ptr<WellFlexibleSolverType> wellSolver_;
227 resComm_->copyOwnerToAll(v, v);
231 void initWellSolver()
233 wop_ = std::make_unique<WellOperator>(S_[
_1][
_1]);
234 std::function<WellVector<Scalar>()> weightsCalculatorWell;
235 wellSolver_ = std::make_unique<WellFlexibleSolverType>(
236 *wop_, wellprm_, weightsCalculatorWell, dummyWellPressureIndex);
240 const std::function<ResVector<Scalar>()>& weightsCalculator)
242 auto resprm = prm.
get_child(
"reservoir_solver");
243 auto resprmsmoother = prm.
get_child(
"reservoir_smoother");
247 rop_ = std::make_unique<ResOp>(S_[
_0][
_0], *resComm_);
248 resSolver_ = std::make_unique<ResFlexibleSolverType>(
249 *rop_, *resComm_, resprm, weightsCalculator, pressureIndex_);
250 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
251 *rop_, *resComm_, resprmsmoother, weightsCalculator, pressureIndex_);
253 rop_ = std::make_unique<ResOp>(S_[
_0][
_0]);
254 resSolver_ = std::make_unique<ResFlexibleSolverType>(
255 *rop_, resprm, weightsCalculator, pressureIndex_);
256 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
257 *rop_, resprmsmoother, weightsCalculator, pressureIndex_);
263 void initWorkVectors()
265 resizeReservoirWorkVectors();
266 resizeWellWorkVectors();
269 void resizeReservoirWorkVectors()
271 const auto numRes = S_[
_0][
_0].
N();
272 resSol_.resize(numRes);
273 dresSol_.resize(numRes);
274 tmp_resRes_.resize(numRes);
275 resRes_.resize(numRes);
278 void resizeWellWorkVectors()
280 const auto numWell = S_[
_1][
_1].
N();
281 wSol_.resize(numWell);
282 dwSol_.resize(numWell);
283 tmp_wRes_.resize(numWell);
284 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:55
bool hasPerfectUpdate() const override
Definition: SystemPreconditioner.hpp:125
SystemPreconditioner(const SystemMatrix< Scalar > &S, const std::function< ResVector< Scalar >()> &weightsCalculator, int pressureIndex, const Opm::PropertyTree &prm)
Definition: SystemPreconditioner.hpp:67
void post(SystemVector< Scalar > &) override
Definition: SystemPreconditioner.hpp:98
void pre(SystemVector< Scalar > &, SystemVector< Scalar > &) override
Definition: SystemPreconditioner.hpp:94
Dune::SolverCategory::Category category() const override
Definition: SystemPreconditioner.hpp:102
void updateForChangedWellStructure()
Definition: SystemPreconditioner.hpp:117
static constexpr auto _0
Definition: SystemPreconditioner.hpp:63
static constexpr auto _1
Definition: SystemPreconditioner.hpp:64
Dune::MatrixAdapter< WWMatrix< Scalar >, WellVector< Scalar >, WellVector< Scalar > > WellOperator
Definition: SystemPreconditioner.hpp:60
static constexpr bool isParallel
Definition: SystemPreconditioner.hpp:57
SystemPreconditioner(const SystemMatrix< Scalar > &S, const std::function< ResVector< Scalar >()> &weightsCalculator, int pressureIndex, const Opm::PropertyTree &prm, const ResComm &resComm)
Definition: SystemPreconditioner.hpp:80
void update() override
Definition: SystemPreconditioner.hpp:110
void apply(SystemVector< Scalar > &v, const SystemVector< Scalar > &d) override
Definition: SystemPreconditioner.hpp:139
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:40
Dune::OwnerOverlapCopyCommunication< int, int > ParResComm
Definition: SystemPreconditioner.hpp:38
Dune::MatrixAdapter< RRMatrix< Scalar >, ResVector< Scalar >, ResVector< Scalar > > SeqResOperator
Definition: SystemPreconditioner.hpp:35
Dune::BlockVector< Dune::FieldVector< Scalar, numResDofs > > ResVector
Definition: SystemTypes.hpp:55
Dune::BlockVector< Dune::FieldVector< Scalar, numWellDofs > > WellVector
Definition: SystemTypes.hpp:57