ISTLSolver.hpp
Go to the documentation of this file.
1/*
2 Copyright 2016 IRIS AS
3 Copyright 2019, 2020 Equinor ASA
4 Copyright 2020 SINTEF Digital, Mathematics and Cybernetics
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef OPM_ISTLSOLVER_HEADER_INCLUDED
23#define OPM_ISTLSOLVER_HEADER_INCLUDED
24
25#include <dune/istl/owneroverlapcopy.hh>
26#include <dune/istl/solver.hh>
27
28#include <opm/common/CriticalError.hpp>
29#include <opm/common/ErrorMacros.hpp>
30#include <opm/common/Exceptions.hpp>
31#include <opm/common/TimingMacros.hpp>
32
33#include <opm/grid/utility/ElementChunks.hpp>
34
54
55#include <fmt/format.h>
56
57#include <any>
58#include <cstddef>
59#include <functional>
60#include <memory>
61#include <set>
62#include <sstream>
63#include <string>
64#include <tuple>
65#include <vector>
66
67namespace Opm::Properties {
68
69namespace TTag {
71 using InheritsFrom = std::tuple<FlowIstlSolverParams>;
72};
73}
74
75template <class TypeTag, class MyTypeTag>
76struct WellModel;
77
80template<class TypeTag>
81struct SparseMatrixAdapter<TypeTag, TTag::FlowIstlSolver>
82{
83private:
85 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
87
88public:
90};
91
92} // namespace Opm::Properties
93
94namespace Opm
95{
96
97
98namespace detail
99{
100
101template<class Matrix, class Vector, class Comm>
103{
104 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
105 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
107
108 void create(const Matrix& matrix,
109 bool parallel,
110 const PropertyTree& prm,
111 std::size_t pressureIndex,
112 std::function<Vector()> weightCalculator,
113 const bool forceSerial,
114 Comm* comm);
115
116 std::unique_ptr<AbstractSolverType> solver_;
117 std::unique_ptr<AbstractOperatorType> op_;
118 std::unique_ptr<LinearOperatorExtra<Vector,Vector>> wellOperator_;
120 std::size_t interiorCellNum_ = 0;
121};
122
123
124#ifdef HAVE_MPI
126void copyParValues(std::any& parallelInformation, std::size_t size,
127 Dune::OwnerOverlapCopyCommunication<int,int>& comm);
128#endif
129
132template<class Matrix>
133void makeOverlapRowsInvalid(Matrix& matrix,
134 const std::vector<int>& overlapRows);
135
138template<class Matrix, class Grid>
139std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
140 const std::vector<int>& cell_part,
141 std::size_t nonzeroes,
142 const std::vector<std::set<int>>& wellConnectionsGraph);
143}
144
149 template <class TypeTag>
150 class ISTLSolver : public AbstractISTLSolver<GetPropType<TypeTag, Properties::SparseMatrixAdapter>,
151 GetPropType<TypeTag, Properties::GlobalEqVector>>
152 {
153 protected:
161 using Matrix = typename SparseMatrixAdapter::IstlMatrix;
164 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
165 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
169 using ElementChunksType = ElementChunks<GridView, Dune::Partitions::All>;
170
172
173 static constexpr bool enablePolymerMolarWeight = getPropValue<TypeTag, Properties::EnablePolymerMW>();
175
176#if HAVE_MPI
177 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int,int>;
178#else
179 using CommunicationType = Dune::Communication<int>;
180#endif
181
182 public:
183 using AssembledLinearOperatorType = Dune::AssembledLinearOperator< Matrix, Vector, Vector >;
184
185 static void registerParameters()
186 {
188 }
189
197 ISTLSolver(const Simulator& simulator,
198 const FlowLinearSolverParameters& parameters,
199 bool forceSerial = false)
200 : simulator_(simulator),
201 iterations_( 0 ),
202 matrix_(nullptr),
203 parameters_{parameters},
204 forceSerial_(forceSerial)
205 {
206 initialize();
207 }
208
211 explicit ISTLSolver(const Simulator& simulator)
212 : simulator_(simulator),
213 iterations_( 0 ),
214 solveCount_(0),
215 matrix_(nullptr)
216 {
217 parameters_.resize(1);
218 parameters_[0].init(simulator_.vanguard().eclState().getSimulationConfig().useCPR());
219 initialize();
220 }
221
223 {
224 OPM_TIMEBLOCK(IstlSolver);
225
227 // Polymer injectivity is incompatible with the CPRW linear solver.
228 // Instead of aborting the run, emit a warning and fall back to ILU0
229 // so that polymer injectivity cases work with default parameters.
230 if (parameters_[0].linsolver_ == "cprw" || parameters_[0].linsolver_ == "hybrid") {
231 const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
232 const std::string msg =
233 fmt::format("The polymer injectivity model is incompatible with the '{}' "
234 "linear solver. Falling back to --linear-solver=ilu0.",
235 parameters_[0].linsolver_);
236 if (on_io_rank) {
237 OpmLog::warning(msg);
238 }
239 parameters_[0].linsolver_ = "ilu0";
240 }
241 }
242
243 if (parameters_[0].linsolver_ == "hybrid") {
244 // Experimental hybrid configuration.
245 // When chosen, will set up two solvers, one with CPRW
246 // and the other with ILU0 preconditioner. More general
247 // options may be added later.
248 prm_.clear();
249 parameters_.clear();
250 {
252 para.init(false);
253 para.linsolver_ = "cprw";
254 parameters_.push_back(para);
256 Parameters::IsSet<Parameters::LinearSolverMaxIter>(),
257 Parameters::IsSet<Parameters::LinearSolverReduction>()));
258 }
259 {
261 para.init(false);
262 para.linsolver_ = "ilu0";
263 parameters_.push_back(para);
265 Parameters::IsSet<Parameters::LinearSolverMaxIter>(),
266 Parameters::IsSet<Parameters::LinearSolverReduction>()));
267 }
268 // ------------
269 } else {
270 assert(parameters_.size() == 1);
271 assert(prm_.empty());
272
273 // Do a normal linear solver setup.
274 if (parameters_[0].is_nldd_local_solver_) {
276 Parameters::IsSet<Parameters::NlddLocalLinearSolverMaxIter>(),
277 Parameters::IsSet<Parameters::NlddLocalLinearSolverReduction>()));
278 }
279 else {
281 Parameters::IsSet<Parameters::LinearSolverMaxIter>(),
282 Parameters::IsSet<Parameters::LinearSolverReduction>()));
283 }
284 }
285 flexibleSolver_.resize(prm_.size());
286
287 const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
288#if HAVE_MPI
289 comm_.reset( new CommunicationType( simulator_.vanguard().grid().comm() ) );
290#endif
292
293 // For some reason simulator_.model().elementMapper() is not initialized at this stage
294 //const auto& elemMapper = simulator_.model().elementMapper(); //does not work.
295 // Set it up manually
296 ElementMapper elemMapper(simulator_.vanguard().gridView(), Dune::mcmgElementLayout());
298 useWellConn_ = Parameters::Get<Parameters::MatrixAddWellContributions>();
299 const bool ownersFirst = Parameters::Get<Parameters::OwnerCellsFirst>();
300 if (!ownersFirst) {
301 const std::string msg = "The linear solver no longer supports --owner-cells-first=false.";
302 if (on_io_rank) {
303 OpmLog::error(msg);
304 }
305 OPM_THROW_NOLOG(std::runtime_error, msg);
306 }
307
308 const int interiorCellNum_ = detail::numMatrixRowsToUseInSolver(simulator_.vanguard().grid(), true);
309 for (auto& f : flexibleSolver_) {
310 f.interiorCellNum_ = interiorCellNum_;
311 }
312
313#if HAVE_MPI
314 if (isParallel()) {
315 const std::size_t size = simulator_.vanguard().grid().leafGridView().size(0);
317 }
318#endif
319
320 // Print parameters to PRT/DBG logs.
322
323 element_chunks_ = std::make_unique<ElementChunksType>(simulator_.vanguard().gridView(), Dune::Partitions::all, ThreadManager::maxThreads());
324 }
325
326 // Drop the cached matrix pointer so initPrepare() sees the next matrix
327 // as a new object. Callers that rebuild the linear system mid-run rely
328 // on this - opm-flowgeomechanics does it from FlowProblemMech when
329 // fracture connections change.
330 void eraseMatrix() override
331 {
332 matrix_ = nullptr;
333 }
334
335 void setActiveSolver(const int num) override
336 {
337 if (num > static_cast<int>(prm_.size()) - 1) {
338 OPM_THROW(std::logic_error, "Solver number " + std::to_string(num) + " not available.");
339 }
340 activeSolverNum_ = num;
341 if (simulator_.gridView().comm().rank() == 0) {
342 OpmLog::debug("Active solver = " + std::to_string(activeSolverNum_)
343 + " (" + parameters_[activeSolverNum_].linsolver_ + ")");
344 }
345 }
346
347 int numAvailableSolvers() const override
348 {
349 return flexibleSolver_.size();
350 }
351
352 void initPrepare(const Matrix& M, Vector& b)
353 {
354 // matrix_ starts out null, so this also covers the first call.
355 const bool matrix_changed = &M != matrix_;
356
357 if (matrix_changed) {
358 // The matrix object is no longer the one the solver was built
359 // for, so the solver has to be rebuilt rather than updated.
360 force_recreate_ = true;
361
362 // model will not change the matrix object. Hence simply store a pointer
363 // to the original one with a deleter that does nothing.
364 // Outch! We need to be able to scale the linear system! Hence const_cast
365 matrix_ = const_cast<Matrix*>(&M);
366
367 useWellConn_ = Parameters::Get<Parameters::MatrixAddWellContributions>();
368 // setup sparsity pattern for jacobi matrix for preconditioner (only used for openclSolver)
369 }
370 rhs_ = &b;
371
372 // TODO: check all solvers, not just one.
373 // We use lower case as the internal canonical representation of solver names
374 std::string type = prm_[activeSolverNum_].template get<std::string>("preconditioner.type", "paroverilu0");
375 std::ranges::transform(type, type.begin(), ::tolower);
376 if (isParallel() && type != "paroverilu0") {
378 }
379 }
380
381 void prepare(const SparseMatrixAdapter& M, Vector& b) override
382 {
383 prepare(M.istlMatrix(), b);
384 }
385
386 void prepare(const Matrix& M, Vector& b) override
387 {
388 OPM_TIMEBLOCK(istlSolverPrepare);
389 try {
390 initPrepare(M,b);
391
393 }
394 catch (const Dune::MatrixBlockError&) {
395 // A singular matrix block found while building the
396 // preconditioner is recoverable: rethrow it unchanged so that
397 // the adaptive time stepping can chop the time step instead of
398 // aborting the run.
399 throw;
400 }
401 OPM_CATCH_AND_RETHROW_AS_CRITICAL_ERROR("This is likely due to a faulty linear solver JSON specification. Check for errors related to missing nodes.");
402 }
403
404
405 void setResidual(Vector& /* b */) override
406 {
407 // rhs_ = &b; // Must be handled in prepare() instead.
408 }
409
410 void getResidual(Vector& b) const override
411 {
412 b = *rhs_;
413 }
414
415 void setMatrix(const SparseMatrixAdapter& /* M */) override
416 {
417 // matrix_ = &M.istlMatrix(); // Must be handled in prepare() instead.
418 }
419
420 int getSolveCount() const override {
421 return solveCount_;
422 }
423
425 solveCount_ = 0;
426 }
427
428 bool solve(Vector& x) override
429 {
430 OPM_TIMEBLOCK(istlSolverSolve);
431 ++solveCount_;
432 // Write linear system if asked for.
433 const int verbosity = prm_[activeSolverNum_].get("verbosity", 0);
434 const bool write_matrix = verbosity > 10;
435 if (write_matrix) {
436 Helper::writeSystem(simulator_, //simulator is only used to get names
437 getMatrix(),
438 *rhs_,
439 comm_.get());
440 }
441
442 // Solve system.
444 {
445 OPM_TIMEBLOCK(flexibleSolverApply);
446 assert(flexibleSolver_[activeSolverNum_].solver_);
447 flexibleSolver_[activeSolverNum_].solver_->apply(x, *rhs_, result);
448 }
449
450 iterations_ = result.iterations;
451
452 // Check convergence, iterations etc.
453 return checkConvergence(result);
454 }
455
456
462
464 int iterations () const override { return iterations_; }
465
467 const std::any& parallelInformation() const { return parallelInformation_; }
468
469 const CommunicationType* comm() const override { return comm_.get(); }
470
471 void setDomainIndex(const int index)
472 {
473 domainIndex_ = index;
474 }
475
476 bool isNlddLocalSolver() const
477 {
478 return parameters_[activeSolverNum_].is_nldd_local_solver_;
479 }
480
481 protected:
482#if HAVE_MPI
483 using Comm = Dune::OwnerOverlapCopyCommunication<int, int>;
484#endif
485
487 {
489 }
490
491 bool isParallel() const {
492#if HAVE_MPI
493 return !forceSerial_ && comm_->communicator().size() > 1;
494#else
495 return false;
496#endif
497 }
498
500 {
501 OPM_TIMEBLOCK(flexibleSolverPrepare);
502 if (shouldCreateSolver()) {
503 if (!useWellConn_) {
504 if (isNlddLocalSolver()) {
505 auto wellOp = std::make_unique<DomainWellModelAsLinearOperator<WellModel, Vector, Vector>>(simulator_.problem().wellModel());
506 wellOp->setDomainIndex(domainIndex_);
507 flexibleSolver_[activeSolverNum_].wellOperator_ = std::move(wellOp);
508 }
509 else {
510 auto wellOp = std::make_unique<WellModelOperator>(simulator_.problem().wellModel());
511 flexibleSolver_[activeSolverNum_].wellOperator_ = std::move(wellOp);
512 }
513 }
514 std::function<Vector()> weightCalculator = this->getWeightsCalculator(prm_[activeSolverNum_], getMatrix(), pressureIndex);
515 OPM_TIMEBLOCK(flexibleSolverCreate);
517 isParallel(),
520 weightCalculator,
522 comm_.get());
524 }
525 else
526 {
527 OPM_TIMEBLOCK(flexibleSolverUpdate);
528 flexibleSolver_[activeSolverNum_].pre_->update();
529 }
530 }
531
532
535 {
536 return useWellConn_
537 ? 0
538 : simulator_.problem().wellModel().numLocalWellsEnd();
539 }
540
544 {
545 // Decide if we should recreate the solver or just do
546 // a minimal preconditioner update.
547 if (force_recreate_) {
548 force_recreate_ = false; // one-shot trigger set by initPrepare
549 return true;
550 }
551
552 if (flexibleSolver_.empty()) {
553 return true;
554 }
555
556 if (!flexibleSolver_[activeSolverNum_].solver_) {
557 return true;
558 }
559
560 // The CPRW coarse system reserves a row per well, so its size is
561 // fixed when the solver is built. A well drilled by an ACTIONX
562 // block changes the well count mid-run; updating in place would
563 // then write past the end of the coarse matrix.
564 if (this->numWellEquations() != numWellEquations_) {
565 return true;
566 }
567
568 if (flexibleSolver_[activeSolverNum_].pre_->hasPerfectUpdate()) {
569 return false;
570 }
571
572 // For AMG based preconditioners, the hierarchy depends on the matrix values
573 // so it is recreated at certain intervals
574 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 0) {
575 // Always recreate solver.
576 return true;
577 }
578 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 1) {
579 // Recreate solver on the first iteration of every timestep.
580 return this->simulator_.problem().iterationContext().isFirstGlobalIteration();
581 }
582 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 2) {
583 // Recreate solver if the last solve used more than 10 iterations.
584 return this->iterations() > 10;
585 }
586 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 3) {
587 // Never recreate the solver
588 return false;
589 }
590 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 4) {
591 // Recreate solver every 'step' solve calls.
592 const int step = this->parameters_[activeSolverNum_].cpr_reuse_interval_;
593 const bool create = ((solveCount_ % step) == 0);
594 return create;
595 }
596 // If here, we have an invalid parameter.
597 const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
598 std::string msg = "Invalid value: " + std::to_string(this->parameters_[activeSolverNum_].cpr_reuse_setup_)
599 + " for --cpr-reuse-setup parameter, run with --help to see allowed values.";
600 if (on_io_rank) {
601 OpmLog::error(msg);
602 }
603 throw std::runtime_error(msg);
604
605 return false;
606 }
607
608
609 // Weights to make approximate pressure equations.
610 // Calculated from the storage terms (only) of the
611 // conservation equations, ignoring all other terms.
612 std::function<Vector()> getWeightsCalculator(const PropertyTree& prm,
613 const Matrix& matrix,
614 std::size_t pressIndex) const
615 {
616 std::function<Vector()> weightsCalculator;
617
618 using namespace std::string_literals;
619
620 auto preconditionerType = prm.get("preconditioner.type"s, "cpr"s);
621 // We use lower case as the internal canonical representation of solver names
622 std::ranges::transform(preconditionerType, preconditionerType.begin(), ::tolower);
623 if (preconditionerType == "cpr" || preconditionerType == "cprt"
624 || preconditionerType == "cprw" || preconditionerType == "cprwt") {
625 const bool transpose = preconditionerType == "cprt" || preconditionerType == "cprwt";
626 const bool enableThreadParallel = this->parameters_[0].cpr_weights_thread_parallel_;
627 const auto weightsType = prm.get("preconditioner.weight_type"s, "quasiimpes"s);
628 if (weightsType == "quasiimpes") {
629 // weights will be created as default in the solver
630 // assignment p = pressureIndex prevent compiler warning about
631 // capturing variable with non-automatic storage duration
632 weightsCalculator = [matrix, transpose, pressIndex, enableThreadParallel]() {
633 return Amg::getQuasiImpesWeights<Matrix, Vector>(matrix,
634 pressIndex,
635 transpose,
636 enableThreadParallel);
637 };
638 } else if ( weightsType == "trueimpes" ) {
639 weightsCalculator =
640 [this, pressIndex, enableThreadParallel]
641 {
642 Vector weights(rhs_->size());
643 ElementContext elemCtx(simulator_);
644 Amg::getTrueImpesWeights(pressIndex,
645 weights,
646 elemCtx,
647 simulator_.model(),
649 enableThreadParallel
650 );
651 return weights;
652 };
653 } else if (weightsType == "trueimpesanalytic" ) {
654 weightsCalculator =
655 [this, pressIndex, enableThreadParallel]
656 {
657 Vector weights(rhs_->size());
658 ElementContext elemCtx(simulator_);
660 weights,
661 elemCtx,
662 simulator_.model(),
664 enableThreadParallel
665 );
666 return weights;
667 };
668 } else {
669 OPM_THROW(std::invalid_argument,
670 "Weights type " + weightsType +
671 "not implemented for cpr."
672 " Please use quasiimpes, trueimpes or trueimpesanalytic.");
673 }
674 }
675 return weightsCalculator;
676 }
677
678
680 {
681 return *matrix_;
682 }
683
684 const Matrix& getMatrix() const
685 {
686 return *matrix_;
687 }
688
690 mutable int iterations_;
691 mutable int solveCount_;
693
694 // non-const to be able to scale the linear system
697
699 std::vector<detail::FlexibleSolverInfo<Matrix,Vector,CommunicationType>> flexibleSolver_;
700 std::vector<int> overlapRows_;
701 std::vector<int> interiorRows_;
702
703 int domainIndex_ = -1;
704
705 // Number of well equations the current solver was built for, or -1 if
706 // no solver has been built yet. See shouldCreateSolver().
708
710
711 std::vector<FlowLinearSolverParameters> parameters_;
712 bool forceSerial_ = false;
713 std::vector<PropertyTree> prm_;
714
715 std::shared_ptr< CommunicationType > comm_;
716 std::unique_ptr<ElementChunksType> element_chunks_;
717 // set when initPrepare detects a different matrix object; cleared by
718 // shouldCreateSolver() (hence mutable in an otherwise const query)
719 mutable bool force_recreate_ = false;
720 }; // end ISTLSolver
721
722} // namespace Opm
723
724#endif // OPM_ISTLSOLVER_HEADER_INCLUDED
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:394
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:34
Abstract interface for ISTL solvers.
Definition: AbstractISTLSolver.hpp:45
static bool checkConvergence(const Dune::InverseOperatorResult &result, const FlowLinearSolverParameters &parameters)
Check the convergence of the linear solver.
Definition: AbstractISTLSolver.hpp:192
Definition: ISTLSolver.hpp:152
void getResidual(Vector &b) const override
Definition: ISTLSolver.hpp:410
void initialize()
Definition: ISTLSolver.hpp:222
const Matrix & getMatrix() const
Definition: ISTLSolver.hpp:684
ElementChunks< GridView, Dune::Partitions::All > ElementChunksType
Definition: ISTLSolver.hpp:169
ISTLSolver(const Simulator &simulator, const FlowLinearSolverParameters &parameters, bool forceSerial=false)
Definition: ISTLSolver.hpp:197
void setDomainIndex(const int index)
Definition: ISTLSolver.hpp:471
int iterations() const override
Definition: ISTLSolver.hpp:464
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: ISTLSolver.hpp:155
bool force_recreate_
Definition: ISTLSolver.hpp:719
std::shared_ptr< CommunicationType > comm_
Definition: ISTLSolver.hpp:715
static constexpr bool isIncompatibleWithCprw
Definition: ISTLSolver.hpp:174
std::vector< FlowLinearSolverParameters > parameters_
Definition: ISTLSolver.hpp:711
void setActiveSolver(const int num) override
Set the active solver by its index.
Definition: ISTLSolver.hpp:335
GetPropType< TypeTag, Properties::GridView > GridView
Definition: ISTLSolver.hpp:154
Dune::InverseOperator< Vector, Vector > AbstractSolverType
Definition: ISTLSolver.hpp:164
void setMatrix(const SparseMatrixAdapter &) override
Definition: ISTLSolver.hpp:415
void prepare(const Matrix &M, Vector &b) override
Definition: ISTLSolver.hpp:386
typename SparseMatrixAdapter::IstlMatrix Matrix
Definition: ISTLSolver.hpp:161
int numWellEquations() const
Number of extra equations the well operator contributes.
Definition: ISTLSolver.hpp:534
GetPropType< TypeTag, Properties::WellModel > WellModel
Definition: ISTLSolver.hpp:159
int solveCount_
Definition: ISTLSolver.hpp:691
bool isNlddLocalSolver() const
Definition: ISTLSolver.hpp:476
Matrix & getMatrix()
Definition: ISTLSolver.hpp:679
int numAvailableSolvers() const override
Get the number of available solvers.
Definition: ISTLSolver.hpp:347
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: ISTLSolver.hpp:156
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Definition: ISTLSolver.hpp:381
Dune::OwnerOverlapCopyCommunication< int, int > CommunicationType
Definition: ISTLSolver.hpp:177
int getSolveCount() const override
Get the count of how many times the solver has been called.
Definition: ISTLSolver.hpp:420
Matrix * matrix_
Definition: ISTLSolver.hpp:695
bool useWellConn_
Definition: ISTLSolver.hpp:709
bool shouldCreateSolver() const
Definition: ISTLSolver.hpp:543
bool checkConvergence(const Dune::InverseOperatorResult &result) const
Definition: ISTLSolver.hpp:486
static constexpr std::size_t pressureIndex
Definition: ISTLSolver.hpp:171
void prepareFlexibleSolver()
Definition: ISTLSolver.hpp:499
GetPropType< TypeTag, Properties::ThreadManager > ThreadManager
Definition: ISTLSolver.hpp:162
GetPropType< TypeTag, Properties::ElementMapper > ElementMapper
Definition: ISTLSolver.hpp:168
void resetSolveCount()
Definition: ISTLSolver.hpp:424
GetPropType< TypeTag, Properties::GlobalEqVector > Vector
Definition: ISTLSolver.hpp:157
const std::any & parallelInformation() const
Definition: ISTLSolver.hpp:467
void initPrepare(const Matrix &M, Vector &b)
Definition: ISTLSolver.hpp:352
std::vector< detail::FlexibleSolverInfo< Matrix, Vector, CommunicationType > > flexibleSolver_
Definition: ISTLSolver.hpp:699
void eraseMatrix() override
Signals that the memory for the matrix internally in the solver could be erased.
Definition: ISTLSolver.hpp:330
Dune::AssembledLinearOperator< Matrix, Vector, Vector > AbstractOperatorType
Definition: ISTLSolver.hpp:165
std::function< Vector()> getWeightsCalculator(const PropertyTree &prm, const Matrix &matrix, std::size_t pressIndex) const
Definition: ISTLSolver.hpp:612
Dune::AssembledLinearOperator< Matrix, Vector, Vector > AssembledLinearOperatorType
Definition: ISTLSolver.hpp:183
ISTLSolver(const Simulator &simulator)
Definition: ISTLSolver.hpp:211
int iterations_
Definition: ISTLSolver.hpp:690
int domainIndex_
Definition: ISTLSolver.hpp:703
std::any parallelInformation_
Definition: ISTLSolver.hpp:692
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: ISTLSolver.hpp:160
Vector * rhs_
Definition: ISTLSolver.hpp:696
int activeSolverNum_
Definition: ISTLSolver.hpp:698
std::vector< int > overlapRows_
Definition: ISTLSolver.hpp:700
std::unique_ptr< ElementChunksType > element_chunks_
Definition: ISTLSolver.hpp:716
GetPropType< TypeTag, Properties::Indices > Indices
Definition: ISTLSolver.hpp:158
static constexpr bool enablePolymerMolarWeight
Definition: ISTLSolver.hpp:173
const Simulator & simulator_
Definition: ISTLSolver.hpp:689
std::vector< int > interiorRows_
Definition: ISTLSolver.hpp:701
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: ISTLSolver.hpp:483
bool forceSerial_
Definition: ISTLSolver.hpp:712
bool solve(Vector &x) override
Definition: ISTLSolver.hpp:428
int numWellEquations_
Definition: ISTLSolver.hpp:707
static void registerParameters()
Definition: ISTLSolver.hpp:185
std::vector< PropertyTree > prm_
Definition: ISTLSolver.hpp:713
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: ISTLSolver.hpp:163
void setResidual(Vector &) override
Definition: ISTLSolver.hpp:405
const CommunicationType * comm() const override
Get the communication object used by the solver.
Definition: ISTLSolver.hpp:469
bool isParallel() const
Definition: ISTLSolver.hpp:491
A sparse matrix interface backend for BCRSMatrix from dune-istl.
Definition: istlsparsematrixadapter.hh:43
Definition: matrixblock.hh:256
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
T get(const std::string &key) const
static unsigned maxThreads()
Return the maximum number of threads of the current process.
Definition: threadmanager.hpp:66
Definition: WellOperators.hpp:70
Declare the properties used by the infrastructure code of the finite volume discretizations.
Defines the common properties required by the porous medium multi-phase models.
void getTrueImpesWeights(int pressureVarIndex, Vector &weights, const ElementContext &elemCtx, const Model &model, const ElementChunksType &element_chunks, bool enable_thread_parallel)
Definition: getQuasiImpesWeights.hpp:165
void getTrueImpesWeightsAnalytic(int, Vector &weights, const ElementContext &elemCtx, const Model &model, const ElementChunksType &element_chunks, bool enable_thread_parallel)
Definition: getQuasiImpesWeights.hpp:260
void writeSystem(const SimulatorType &simulator, const MatrixType &matrix, const VectorType &rhs, const std::string &sysName, const Communicator *comm)
Definition: WriteSystemMatrixHelper.hpp:197
Definition: blackoilmodel.hh:74
std::unique_ptr< Matrix > blockJacobiAdjacency(const Grid &grid, const std::vector< int > &cell_part, std::size_t nonzeroes, const std::vector< std::set< int > > &wellConnectionsGraph)
void copyParValues(std::any &parallelInformation, std::size_t size, Dune::OwnerOverlapCopyCommunication< int, int > &comm)
Copy values in parallel.
std::size_t numMatrixRowsToUseInSolver(const Grid &grid, bool ownerFirst)
If ownerFirst=true, returns the number of interior cells in grid, else just numCells().
Definition: findOverlapRowsAndColumns.hpp:122
void makeOverlapRowsInvalid(Matrix &matrix, const std::vector< int > &overlapRows)
void findOverlapAndInterior(const Grid &grid, const Mapper &mapper, std::vector< int > &overlapRows, std::vector< int > &interiorRows)
Find the rows corresponding to overlap cells.
Definition: findOverlapRowsAndColumns.hpp:92
void printLinearSolverParameters(const FlowLinearSolverParameters &parameters, const VectorOrSingle &prm, const Comm &comm)
Print the linear solver parameters to the log if requested.
Definition: printlinearsolverparameter.hpp:61
Definition: blackoilbioeffectsmodules.hh:45
Dune::InverseOperatorResult InverseOperatorResult
Definition: GpuBridge.hpp:32
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
void extractParallelGridInformationToISTL(const Dune::CpGrid &grid, std::any &anyComm)
Extracts the information about the data decomposition from the grid for dune-istl.
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
PropertyTree setupPropertyTree(FlowLinearSolverParameters p, bool linearSolverMaxIterSet, bool linearSolverReductionSet, bool tpsaSetup=false)
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition: FlowLinearSolverParameters.hpp:98
void init(bool cprRequestedInDataFile)
std::string linsolver_
Definition: FlowLinearSolverParameters.hpp:113
typename Linear::IstlSparseMatrixAdapter< Block > type
Definition: ISTLSolver.hpp:89
The class that allows to manipulate sparse matrices.
Definition: linalgproperties.hh:50
Definition: ISTLSolver.hpp:70
std::tuple< FlowIstlSolverParams > InheritsFrom
Definition: ISTLSolver.hpp:71
Definition: FlowBaseProblemProperties.hpp:99
Definition: ISTLSolver.hpp:103
std::unique_ptr< AbstractSolverType > solver_
Definition: ISTLSolver.hpp:116
std::size_t interiorCellNum_
Definition: ISTLSolver.hpp:120
Dune::InverseOperator< Vector, Vector > AbstractSolverType
Definition: ISTLSolver.hpp:104
AbstractPreconditionerType * pre_
Definition: ISTLSolver.hpp:119
Dune::AssembledLinearOperator< Matrix, Vector, Vector > AbstractOperatorType
Definition: ISTLSolver.hpp:105
void create(const Matrix &matrix, bool parallel, const PropertyTree &prm, std::size_t pressureIndex, std::function< Vector()> weightCalculator, const bool forceSerial, Comm *comm)
std::unique_ptr< LinearOperatorExtra< Vector, Vector > > wellOperator_
Definition: ISTLSolver.hpp:118
std::unique_ptr< AbstractOperatorType > op_
Definition: ISTLSolver.hpp:117