19#ifndef OPM_SYSTEMPRECONDITIONER_IMPL_HEADER_INCLUDED
20#define OPM_SYSTEMPRECONDITIONER_IMPL_HEADER_INCLUDED
24#include <dune/istl/operators.hh>
26#include <opm/common/ErrorMacros.hpp>
32template <
class Scalar,
class ResOp,
class ResComm>
39 , pressureIndex_(pressureIndex)
41 initSubSolvers(prm, weightsCalculator);
45template <
class Scalar,
class ResOp,
class ResComm>
51 const ResComm& resComm)
requires (isParallel)
54 , pressureIndex_(pressureIndex)
56 initSubSolvers(prm, weightsCalculator);
60template <
class Scalar,
class ResOp,
class ResComm>
66 weights_ = weightsCalculator_();
67 cprwStage_->update(weights_);
69 resSolver_->preconditioner().update();
71 resSmoother_->preconditioner().update();
72 wellSolver_->preconditioner().update();
75template <
class Scalar,
class ResOp,
class ResComm>
83 weights_ = weightsCalculator_();
84 cprwStage_->buildStructure(weights_);
86 resSolver_->preconditioner().update();
88 resSmoother_->preconditioner().update();
90 resizeWellWorkVectors();
93template <
class Scalar,
class ResOp,
class ResComm>
99 const auto& A = S_[_0][_0];
100 const auto& C = S_[_0][_1];
101 const auto& B = S_[_1][_0];
102 const auto& D = S_[_1][_1];
115 tmp_resRes_ = resRes_;
116 syncResVector(tmp_resRes_);
117 cprwStage_->apply(tmp_resRes_, wRes_, weights_, dresSol_, dwSol_);
120 A.mmv(dresSol_, resRes_);
122 B.mmv(dresSol_, wRes_);
123 if (cprwStage_->prolongatesWellPressure()) {
126 C.mmv(dwSol_, resRes_);
127 D.mmv(dwSol_, wRes_);
132 tmp_resRes_ = resRes_;
133 syncResVector(tmp_resRes_);
134 resSolver_->apply(dresSol_, tmp_resRes_, res_result);
137 A.mmv(dresSol_, resRes_);
139 B.mmv(dresSol_, wRes_);
147 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
150 C.mmv(dwSol_, resRes_);
152 D.mmv(dwSol_, wRes_);
156 tmp_resRes_ = resRes_;
157 syncResVector(tmp_resRes_);
158 resSmoother_->apply(dresSol_, tmp_resRes_, res_result);
161 B.mmv(dresSol_, wRes_);
169 wellSolver_->apply(dwSol_, tmp_wRes_, well_result);
173 syncResVector(resSol_);
178template <
class Scalar,
class ResOp,
class ResComm>
183 if constexpr (isParallel) {
184 resComm_->copyOwnerToAll(v, v);
188template <
class Scalar,
class ResOp,
class ResComm>
190SystemPreconditioner<Scalar,ResOp,ResComm>::
193 wop_ = std::make_unique<WellOperator>(S_[_1][_1]);
194 std::function<WellVector<Scalar>()> weightsCalculatorWell;
195 wellSolver_ = std::make_unique<WellFlexibleSolverType>(
196 *wop_, wellprm_, weightsCalculatorWell, dummyWellPressureIndex);
199template <
class Scalar,
class ResOp,
class ResComm>
201SystemPreconditioner<Scalar,ResOp,ResComm>::
203 const std::function<SystemVector<Scalar>()>& weightsCalculator)
205 auto resprm = prm.
get_child(
"reservoir_solver");
206 auto resprmsmoother = prm.
get_child(
"reservoir_smoother");
212 const bool addWells = resprm.
get(
"preconditioner.add_wells",
false);
216 std::function<ResVector<Scalar>()> resWeightCalc;
217 if (weightsCalculator) {
218 resWeightCalc = [weightsCalculator]() {
219 return weightsCalculator()[_0];
223 if constexpr (isParallel) {
224 rop_ = std::make_unique<ResOp>(S_[_0][_0], *resComm_);
225 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
226 *rop_, *resComm_, resprmsmoother, resWeightCalc, pressureIndex_);
228 rop_ = std::make_unique<ResOp>(S_[_0][_0]);
229 resSmoother_ = std::make_unique<ResFlexibleSolverType>(
230 *rop_, resprmsmoother, resWeightCalc, pressureIndex_);
234 if (!weightsCalculator) {
235 OPM_THROW(std::invalid_argument,
236 "The CPRW pressure stage (add_wells) needs a weights calculator, but "
237 "none was configured. Set reservoir_solver.preconditioner.weight_type.");
239 weightsCalculator_ = weightsCalculator;
240 weights_ = weightsCalculator_();
242 auto coarseprm = resprm.get_child_optional(
"preconditioner.coarsesolver")
243 ? resprm.get_child(
"preconditioner.coarsesolver")
248 prm.
get(
"well_transfer", std::string{
"classic"}));
250 prm.
get(
"well_coarse_diagonal", std::string{
"contract_d"}));
251 cprwStage_ = std::make_unique<CprwStage>(S_, coarseprm, pressureIndex_,
252 wellTransfer, resComm_, diagonal,
253 prm.
get(
"verbosity", 0));
254 cprwStage_->buildStructure(weights_);
256 if constexpr (isParallel) {
257 resSolver_ = std::make_unique<ResFlexibleSolverType>(
258 *rop_, *resComm_, resprm, resWeightCalc, pressureIndex_);
260 resSolver_ = std::make_unique<ResFlexibleSolverType>(
261 *rop_, resprm, resWeightCalc, pressureIndex_);
268template <
class Scalar,
class ResOp,
class ResComm>
270SystemPreconditioner<Scalar,ResOp,ResComm>::
273 resizeReservoirWorkVectors();
274 resizeWellWorkVectors();
277template <
class Scalar,
class ResOp,
class ResComm>
279SystemPreconditioner<Scalar,ResOp,ResComm>::
280resizeReservoirWorkVectors()
282 const auto numRes = S_[_0][_0].N();
283 resSol_.resize(numRes);
284 dresSol_.resize(numRes);
285 tmp_resRes_.resize(numRes);
286 resRes_.resize(numRes);
289template <
class Scalar,
class ResOp,
class ResComm>
291SystemPreconditioner<Scalar,ResOp,ResComm>::
292resizeWellWorkVectors()
294 const auto numWell = S_[_1][_1].N();
295 wSol_.resize(numWell);
296 dwSol_.resize(numWell);
297 tmp_wRes_.resize(numWell);
298 wRes_.resize(numWell);
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
T get(const std::string &key) const
PropertyTree get_child(const std::string &key) const
Definition: SystemTypes.hpp:176
Definition: SystemPreconditioner.hpp:47
void updateForChangedWellStructure()
Definition: SystemPreconditioner_impl.hpp:78
SystemPreconditioner(const SystemMatrix< Scalar > &S, const std::function< SystemVector< Scalar >()> &weightsCalculator, int pressureIndex, const Opm::PropertyTree &prm)
Definition: SystemPreconditioner_impl.hpp:34
void update() override
Definition: SystemPreconditioner_impl.hpp:63
void apply(SystemVector< Scalar > &v, const SystemVector< Scalar > &d) override
Definition: SystemPreconditioner_impl.hpp:96
Definition: blackoilbioeffectsmodules.hh:45
Dune::MultiTypeBlockVector< ResVector< Scalar >, WellVector< Scalar > > SystemVector
Definition: SystemTypes.hpp:65
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
WellCoarseDiagonal wellCoarseDiagonalFromString(const std::string &name)
Definition: SystemCprwPressureStage.hpp:102
Dune::BlockVector< Dune::FieldVector< Scalar, numResDofs > > ResVector
Definition: SystemTypes.hpp:61
WellTransfer wellTransferFromString(const std::string &name)
Definition: SystemCprwPressureStage.hpp:112