19#ifndef OPM_ISTLSOLVERSYSTEM_HEADER_INCLUDED
20#define OPM_ISTLSOLVERSYSTEM_HEADER_INCLUDED
32template <
class TypeTag>
39 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
46 static_assert(Indices::numEq == 3,
47 "ISTLSolverSystem (with system_cpr preconditioner) only supports "
48 "3-equation blackoil models. This model has different equation count.");
51 = Indices::pressureSwitchIdx;
63 static constexpr auto _0 = Dune::Indices::_0;
64 static constexpr auto _1 = Dune::Indices::_1;
69 bool forceSerial =
false)
70 :
Parent(simulator, parameters, forceSerial)
81 OPM_TIMEBLOCK(istlSolverPrepare);
83 prepareSystemSolver();
88 OPM_TIMEBLOCK(istlSolverPrepare);
90 prepareSystemSolver();
95 OPM_TIMEBLOCK(istlSolverSolve);
101 sysX_[
_0].resize(numRes);
103 sysX_[
_1].resize(numWell);
106 sysRhs_[
_0].resize(numRes);
108 sysRhs_[
_1].resize(numWell);
112 sysSolver_->apply(sysX_, sysRhs_, result);
121 bool sysInitialized_ =
false;
125 std::vector<WRMatrix<Scalar>> wellBMatrices_;
126 std::vector<RWMatrix<Scalar>> wellCMatrices_;
127 std::vector<WWMatrix<Scalar>> wellDMatrices_;
140 std::unique_ptr<SystemSeqOp<Scalar>> sysOp_;
141 std::unique_ptr<Dune::FlexibleSolver<SystemSeqOp<Scalar>>> sysFlexSolverSeq_;
146 std::unique_ptr<WellComm> wellComm_;
147 std::unique_ptr<SystemComm> systemComm_;
148 std::unique_ptr<SystemParOp<Scalar>> sysOpPar_;
149 std::unique_ptr<Dune::FlexibleSolver<SystemParOp<Scalar>>> sysFlexSolverPar_;
158 SysSolverType* sysSolver_ =
nullptr;
159 SysPrecondType* sysPrecond_ =
nullptr;
161 void prepareSystemSolver()
163 OPM_TIMEBLOCK(flexibleSolverPrepare);
165 wellBMatrices_.clear();
166 wellCMatrices_.clear();
167 wellDMatrices_.clear();
170 this->
simulator_.problem().wellModel().addBCDMatrix(
171 wellBMatrices_, wellCMatrices_, wellDMatrices_, wellCells_);
174 Parent::matrix_->N(), wellBMatrices_, wellCMatrices_, wellDMatrices_, wellCells_);
176 const bool localStructureChanged = !sysInitialized_
177 || !merger.hasSameStructure(cachedWellStructure_);
183 const bool globalStructureChanged = this->
comm_->communicator().max(
184 static_cast<int>(localStructureChanged)) > 0;
186 const bool globalStructureChanged = localStructureChanged;
188 const bool needStructureRefresh = !sysInitialized_ || globalStructureChanged;
192 if (needStructureRefresh) {
193 OPM_TIMEBLOCK(flexibleSolverCreate);
194 merger.buildMatrices(mergedB_, mergedC_, mergedD_);
196 sysMatrix_.
B = &mergedB_;
197 sysMatrix_.
C = &mergedC_;
198 sysMatrix_.
D = &mergedD_;
199 cachedWellStructure_ = merger.buildStructure();
201 refreshSystemSolverForChangedWellStructure(prm);
202 sysInitialized_ =
true;
204 OPM_TIMEBLOCK(flexibleSolverUpdate);
207 merger.updateValues(mergedB_, mergedC_, mergedD_);
211 sysMatrix_.
B = &mergedB_;
212 sysMatrix_.
C = &mergedC_;
213 sysMatrix_.
D = &mergedD_;
214 sysPrecond_->update();
220 if (!sysInitialized_ || !sysPrecond_) {
221 createSystemSolver(prm);
226 if (this->
comm_->communicator().size() > 1) {
227 if (
auto* precond =
dynamic_cast<ParSysPrecondType*
>(sysPrecond_)) {
228 precond->updateForChangedWellStructure();
231 createSystemSolver(prm);
237 if (
auto* precond =
dynamic_cast<SeqSysPrecondType*
>(sysPrecond_)) {
238 precond->updateForChangedWellStructure();
241 createSystemSolver(prm);
248 auto resSolverPrm = prm.
get_child(
"preconditioner.reservoir_solver");
249 std::function<ResVector<Scalar>()> resWeightCalc
252 std::function<SystemVector<Scalar>()> sysWeightCalc;
254 sysWeightCalc = [resWeightCalc]() {
255 SystemVector<Scalar> w;
256 w[
_0] = resWeightCalc();
262 const bool is_parallel = this->
comm_->communicator().size() > 1;
264 wellComm_ = std::make_unique<WellComm>();
265 systemComm_ = std::make_unique<SystemComm>(*(this->
comm_), *wellComm_);
267 sysOpPar_ = std::make_unique<SystemParOp<Scalar>>(sysMatrix_, *systemComm_);
269 sysFlexSolverPar_ = std::make_unique<Dune::FlexibleSolver<SystemParOp<Scalar>>>(
270 *sysOpPar_, *systemComm_, prm, sysWeightCalc,
pressureIndex);
272 sysSolver_ = sysFlexSolverPar_.get();
273 sysPrecond_ = &sysFlexSolverPar_->preconditioner();
278 sysOp_ = std::make_unique<SystemSeqOp<Scalar>>(sysMatrix_);
280 sysFlexSolverSeq_ = std::make_unique<Dune::FlexibleSolver<SystemSeqOp<Scalar>>>(
283 sysSolver_ = sysFlexSolverSeq_.get();
284 sysPrecond_ = &sysFlexSolverSeq_->preconditioner();
Definition: MultiComm.hpp:74
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:34
Definition: ISTLSolver.hpp:152
std::shared_ptr< CommunicationType > comm_
Definition: ISTLSolver.hpp:678
typename SparseMatrixAdapter::IstlMatrix Matrix
Definition: ISTLSolver.hpp:161
int solveCount_
Definition: ISTLSolver.hpp:658
Matrix & getMatrix()
Definition: ISTLSolver.hpp:646
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: ISTLSolver.hpp:156
Dune::OwnerOverlapCopyCommunication< int, int > CommunicationType
Definition: ISTLSolver.hpp:177
Matrix * matrix_
Definition: ISTLSolver.hpp:662
bool checkConvergence(const Dune::InverseOperatorResult &result) const
Definition: ISTLSolver.hpp:476
GetPropType< TypeTag, Properties::GlobalEqVector > Vector
Definition: ISTLSolver.hpp:157
void initPrepare(const Matrix &M, Vector &b)
Definition: ISTLSolver.hpp:348
std::function< Vector()> getWeightsCalculator(const PropertyTree &prm, const Matrix &matrix, std::size_t pressIndex) const
Definition: ISTLSolver.hpp:579
int iterations_
Definition: ISTLSolver.hpp:657
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: ISTLSolver.hpp:160
Vector * rhs_
Definition: ISTLSolver.hpp:663
int activeSolverNum_
Definition: ISTLSolver.hpp:665
GetPropType< TypeTag, Properties::Indices > Indices
Definition: ISTLSolver.hpp:158
const Simulator & simulator_
Definition: ISTLSolver.hpp:656
std::vector< PropertyTree > prm_
Definition: ISTLSolver.hpp:676
Definition: ISTLSolverSystem.hpp:34
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Definition: ISTLSolverSystem.hpp:79
@ enablePolymerMolarWeight
Definition: ISTLSolverSystem.hpp:53
static constexpr auto _1
Definition: ISTLSolverSystem.hpp:64
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: ISTLSolverSystem.hpp:36
static constexpr std::size_t pressureIndex
Definition: ISTLSolverSystem.hpp:51
ISTLSolverSystem(const Simulator &simulator, const FlowLinearSolverParameters ¶meters, bool forceSerial=false)
Definition: ISTLSolverSystem.hpp:67
static constexpr bool isIncompatibleWithCprw
Definition: ISTLSolverSystem.hpp:54
static constexpr auto _0
Definition: ISTLSolverSystem.hpp:63
ISTLSolverSystem(const Simulator &simulator)
Definition: ISTLSolverSystem.hpp:74
void prepare(const Matrix &M, Vector &b) override
Definition: ISTLSolverSystem.hpp:86
bool solve(Vector &x) override
Definition: ISTLSolverSystem.hpp:93
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
PropertyTree get_child(const std::string &key) const
Definition: SystemTypes.hpp:77
const WRMatrix< Scalar > * B
Definition: SystemTypes.hpp:88
const RWMatrix< Scalar > * C
Definition: SystemTypes.hpp:87
const RRMatrix< Scalar > * A
Definition: SystemTypes.hpp:86
const WWMatrix< Scalar > * D
Definition: SystemTypes.hpp:89
Definition: SystemPreconditioner.hpp:57
Definition: WellMatrixMerger.hpp:164
Definition: blackoilbioeffectsmodules.hh:45
Dune::MultiTypeBlockVector< ResVector< Scalar >, WellVector< Scalar > > SystemVector
Definition: SystemTypes.hpp:59
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numWellDofs > > WWMatrix
Definition: SystemTypes.hpp:52
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numResDofs, numWellDofs > > RWMatrix
Definition: SystemTypes.hpp:48
Dune::OwnerOverlapCopyCommunication< int, int > ParResComm
Definition: SystemPreconditioner.hpp:40
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numResDofs > > WRMatrix
Definition: SystemTypes.hpp:50
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition: FlowLinearSolverParameters.hpp:98
Definition: WellMatrixMerger.hpp:66
std::size_t totalWellBlocks
Definition: WellMatrixMerger.hpp:68