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 rhs_ = nullptr;
334 iterations_ = 0;
335 solveCount_ = 0;
336
337 for (auto& solverInfo : flexibleSolver_) {
338 solverInfo.pre_ = nullptr;
339 solverInfo.solver_.reset();
340 solverInfo.op_.reset();
341 }
342 }
343
344 void setActiveSolver(const int num) override
345 {
346 if (num > static_cast<int>(prm_.size()) - 1) {
347 OPM_THROW(std::logic_error, "Solver number " + std::to_string(num) + " not available.");
348 }
349 activeSolverNum_ = num;
350 if (simulator_.gridView().comm().rank() == 0) {
351 OpmLog::debug("Active solver = " + std::to_string(activeSolverNum_)
352 + " (" + parameters_[activeSolverNum_].linsolver_ + ")");
353 }
354 }
355
356 int numAvailableSolvers() const override
357 {
358 return flexibleSolver_.size();
359 }
360
361 void initPrepare(const Matrix& M, Vector& b)
362 {
363 // matrix_ starts out null, so this also covers the first call.
364 const bool matrix_changed = &M != matrix_;
365
366 if (matrix_changed) {
367 // The matrix object is no longer the one the solver was built
368 // for, so the solver has to be rebuilt rather than updated.
369 force_recreate_ = true;
370
371 // model will not change the matrix object. Hence simply store a pointer
372 // to the original one with a deleter that does nothing.
373 // Outch! We need to be able to scale the linear system! Hence const_cast
374 matrix_ = const_cast<Matrix*>(&M);
375
376 useWellConn_ = Parameters::Get<Parameters::MatrixAddWellContributions>();
377 // setup sparsity pattern for jacobi matrix for preconditioner (only used for openclSolver)
378 }
379 rhs_ = &b;
380
381 // TODO: check all solvers, not just one.
382 // We use lower case as the internal canonical representation of solver names
383 std::string type = prm_[activeSolverNum_].template get<std::string>("preconditioner.type", "paroverilu0");
384 std::ranges::transform(type, type.begin(), ::tolower);
385 if (isParallel() && type != "paroverilu0") {
387 }
388 }
389
390 void prepare(const SparseMatrixAdapter& M, Vector& b) override
391 {
392 prepare(M.istlMatrix(), b);
393 }
394
395 void prepare(const Matrix& M, Vector& b) override
396 {
397 OPM_TIMEBLOCK(istlSolverPrepare);
398 try {
399 initPrepare(M,b);
400
402 }
403 catch (const Dune::MatrixBlockError&) {
404 // A singular matrix block found while building the
405 // preconditioner is recoverable: rethrow it unchanged so that
406 // the adaptive time stepping can chop the time step instead of
407 // aborting the run.
408 throw;
409 }
410 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.");
411 }
412
413
414 void setResidual(Vector& /* b */) override
415 {
416 // rhs_ = &b; // Must be handled in prepare() instead.
417 }
418
419 void getResidual(Vector& b) const override
420 {
421 b = *rhs_;
422 }
423
424 void setMatrix(const SparseMatrixAdapter& /* M */) override
425 {
426 // matrix_ = &M.istlMatrix(); // Must be handled in prepare() instead.
427 }
428
429 int getSolveCount() const override {
430 return solveCount_;
431 }
432
434 solveCount_ = 0;
435 }
436
437 bool solve(Vector& x) override
438 {
439 OPM_TIMEBLOCK(istlSolverSolve);
440 ++solveCount_;
441 // Write linear system if asked for.
442 const int verbosity = prm_[activeSolverNum_].get("verbosity", 0);
443 const bool write_matrix = verbosity > 10;
444 if (write_matrix) {
445 Helper::writeSystem(simulator_, //simulator is only used to get names
446 getMatrix(),
447 *rhs_,
448 comm_.get());
449 }
450
451 // Solve system.
453 {
454 OPM_TIMEBLOCK(flexibleSolverApply);
455 assert(flexibleSolver_[activeSolverNum_].solver_);
456 flexibleSolver_[activeSolverNum_].solver_->apply(x, *rhs_, result);
457 }
458
459 iterations_ = result.iterations;
460
461 // Check convergence, iterations etc.
462 return checkConvergence(result);
463 }
464
465
471
473 int iterations () const override { return iterations_; }
474
476 const std::any& parallelInformation() const { return parallelInformation_; }
477
478 const CommunicationType* comm() const override { return comm_.get(); }
479
480 void setDomainIndex(const int index)
481 {
482 domainIndex_ = index;
483 }
484
485 bool isNlddLocalSolver() const
486 {
487 return parameters_[activeSolverNum_].is_nldd_local_solver_;
488 }
489
490 protected:
491#if HAVE_MPI
492 using Comm = Dune::OwnerOverlapCopyCommunication<int, int>;
493#endif
494
496 {
498 }
499
500 bool isParallel() const {
501#if HAVE_MPI
502 return !forceSerial_ && comm_->communicator().size() > 1;
503#else
504 return false;
505#endif
506 }
507
509 {
510 OPM_TIMEBLOCK(flexibleSolverPrepare);
511 if (shouldCreateSolver()) {
512 if (!useWellConn_) {
513 if (isNlddLocalSolver()) {
514 auto wellOp = std::make_unique<DomainWellModelAsLinearOperator<WellModel, Vector, Vector>>(simulator_.problem().wellModel());
515 wellOp->setDomainIndex(domainIndex_);
516 flexibleSolver_[activeSolverNum_].wellOperator_ = std::move(wellOp);
517 }
518 else {
519 auto wellOp = std::make_unique<WellModelOperator>(simulator_.problem().wellModel());
520 flexibleSolver_[activeSolverNum_].wellOperator_ = std::move(wellOp);
521 }
522 }
523 std::function<Vector()> weightCalculator = this->getWeightsCalculator(prm_[activeSolverNum_], getMatrix(), pressureIndex);
524 OPM_TIMEBLOCK(flexibleSolverCreate);
526 isParallel(),
529 weightCalculator,
531 comm_.get());
533 }
534 else
535 {
536 OPM_TIMEBLOCK(flexibleSolverUpdate);
537 flexibleSolver_[activeSolverNum_].pre_->update();
538 }
539 }
540
541
544 {
545 return useWellConn_
546 ? 0
547 : simulator_.problem().wellModel().numLocalWellsEnd();
548 }
549
553 {
554 // Decide if we should recreate the solver or just do
555 // a minimal preconditioner update.
556 if (force_recreate_) {
557 force_recreate_ = false; // one-shot trigger set by initPrepare
558 return true;
559 }
560
561 if (flexibleSolver_.empty()) {
562 return true;
563 }
564
565 if (!flexibleSolver_[activeSolverNum_].solver_) {
566 return true;
567 }
568
569 // The CPRW coarse system reserves a row per well, so its size is
570 // fixed when the solver is built. A well drilled by an ACTIONX
571 // block changes the well count mid-run; updating in place would
572 // then write past the end of the coarse matrix.
573 if (this->numWellEquations() != numWellEquations_) {
574 return true;
575 }
576
577 if (flexibleSolver_[activeSolverNum_].pre_->hasPerfectUpdate()) {
578 return false;
579 }
580
581 // For AMG based preconditioners, the hierarchy depends on the matrix values
582 // so it is recreated at certain intervals
583 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 0) {
584 // Always recreate solver.
585 return true;
586 }
587 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 1) {
588 // Recreate solver on the first iteration of every timestep.
589 return this->simulator_.problem().iterationContext().isFirstGlobalIteration();
590 }
591 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 2) {
592 // Recreate solver if the last solve used more than 10 iterations.
593 return this->iterations() > 10;
594 }
595 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 3) {
596 // Never recreate the solver
597 return false;
598 }
599 if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 4) {
600 // Recreate solver every 'step' solve calls.
601 const int step = this->parameters_[activeSolverNum_].cpr_reuse_interval_;
602 const bool create = ((solveCount_ % step) == 0);
603 return create;
604 }
605 // If here, we have an invalid parameter.
606 const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
607 std::string msg = "Invalid value: " + std::to_string(this->parameters_[activeSolverNum_].cpr_reuse_setup_)
608 + " for --cpr-reuse-setup parameter, run with --help to see allowed values.";
609 if (on_io_rank) {
610 OpmLog::error(msg);
611 }
612 throw std::runtime_error(msg);
613
614 return false;
615 }
616
617
618 // Weights to make approximate pressure equations.
619 // Calculated from the storage terms (only) of the
620 // conservation equations, ignoring all other terms.
621 std::function<Vector()> getWeightsCalculator(const PropertyTree& prm,
622 const Matrix& matrix,
623 std::size_t pressIndex) const
624 {
625 std::function<Vector()> weightsCalculator;
626
627 using namespace std::string_literals;
628
629 auto preconditionerType = prm.get("preconditioner.type"s, "cpr"s);
630 // We use lower case as the internal canonical representation of solver names
631 std::ranges::transform(preconditionerType, preconditionerType.begin(), ::tolower);
632 if (preconditionerType == "cpr" || preconditionerType == "cprt"
633 || preconditionerType == "cprw" || preconditionerType == "cprwt") {
634 const bool transpose = preconditionerType == "cprt" || preconditionerType == "cprwt";
635 const bool enableThreadParallel = this->parameters_[0].cpr_weights_thread_parallel_;
636 const auto weightsType = prm.get("preconditioner.weight_type"s, "quasiimpes"s);
637 if (weightsType == "quasiimpes") {
638 // weights will be created as default in the solver
639 // assignment p = pressureIndex prevent compiler warning about
640 // capturing variable with non-automatic storage duration
641 weightsCalculator = [matrix, transpose, pressIndex, enableThreadParallel]() {
642 return Amg::getQuasiImpesWeights<Matrix, Vector>(matrix,
643 pressIndex,
644 transpose,
645 enableThreadParallel);
646 };
647 } else if ( weightsType == "trueimpes" ) {
648 weightsCalculator =
649 [this, pressIndex, enableThreadParallel]
650 {
651 Vector weights(rhs_->size());
652 ElementContext elemCtx(simulator_);
653 Amg::getTrueImpesWeights(pressIndex,
654 weights,
655 elemCtx,
656 simulator_.model(),
658 enableThreadParallel
659 );
660 return weights;
661 };
662 } else if (weightsType == "trueimpesanalytic" ) {
663 weightsCalculator =
664 [this, pressIndex, enableThreadParallel]
665 {
666 Vector weights(rhs_->size());
667 ElementContext elemCtx(simulator_);
669 weights,
670 elemCtx,
671 simulator_.model(),
673 enableThreadParallel
674 );
675 return weights;
676 };
677 } else {
678 OPM_THROW(std::invalid_argument,
679 "Weights type " + weightsType +
680 "not implemented for cpr."
681 " Please use quasiimpes, trueimpes or trueimpesanalytic.");
682 }
683 }
684 return weightsCalculator;
685 }
686
687
689 {
690 return *matrix_;
691 }
692
693 const Matrix& getMatrix() const
694 {
695 return *matrix_;
696 }
697
699 mutable int iterations_;
700 mutable int solveCount_;
702
703 // non-const to be able to scale the linear system
706
708 std::vector<detail::FlexibleSolverInfo<Matrix,Vector,CommunicationType>> flexibleSolver_;
709 std::vector<int> overlapRows_;
710 std::vector<int> interiorRows_;
711
712 int domainIndex_ = -1;
713
714 // Number of well equations the current solver was built for, or -1 if
715 // no solver has been built yet. See shouldCreateSolver().
717
719
720 std::vector<FlowLinearSolverParameters> parameters_;
721 bool forceSerial_ = false;
722 std::vector<PropertyTree> prm_;
723
724 std::shared_ptr< CommunicationType > comm_;
725 std::unique_ptr<ElementChunksType> element_chunks_;
726 // set when initPrepare detects a different matrix object; cleared by
727 // shouldCreateSolver() (hence mutable in an otherwise const query)
728 mutable bool force_recreate_ = false;
729 }; // end ISTLSolver
730
731} // namespace Opm
732
733#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:419
void initialize()
Definition: ISTLSolver.hpp:222
const Matrix & getMatrix() const
Definition: ISTLSolver.hpp:693
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:480
int iterations() const override
Definition: ISTLSolver.hpp:473
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: ISTLSolver.hpp:155
bool force_recreate_
Definition: ISTLSolver.hpp:728
std::shared_ptr< CommunicationType > comm_
Definition: ISTLSolver.hpp:724
static constexpr bool isIncompatibleWithCprw
Definition: ISTLSolver.hpp:174
std::vector< FlowLinearSolverParameters > parameters_
Definition: ISTLSolver.hpp:720
void setActiveSolver(const int num) override
Set the active solver by its index.
Definition: ISTLSolver.hpp:344
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:424
void prepare(const Matrix &M, Vector &b) override
Definition: ISTLSolver.hpp:395
typename SparseMatrixAdapter::IstlMatrix Matrix
Definition: ISTLSolver.hpp:161
int numWellEquations() const
Number of extra equations the well operator contributes.
Definition: ISTLSolver.hpp:543
GetPropType< TypeTag, Properties::WellModel > WellModel
Definition: ISTLSolver.hpp:159
int solveCount_
Definition: ISTLSolver.hpp:700
bool isNlddLocalSolver() const
Definition: ISTLSolver.hpp:485
Matrix & getMatrix()
Definition: ISTLSolver.hpp:688
int numAvailableSolvers() const override
Get the number of available solvers.
Definition: ISTLSolver.hpp:356
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: ISTLSolver.hpp:156
void prepare(const SparseMatrixAdapter &M, Vector &b) override
Definition: ISTLSolver.hpp:390
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:429
Matrix * matrix_
Definition: ISTLSolver.hpp:704
bool useWellConn_
Definition: ISTLSolver.hpp:718
bool shouldCreateSolver() const
Definition: ISTLSolver.hpp:552
bool checkConvergence(const Dune::InverseOperatorResult &result) const
Definition: ISTLSolver.hpp:495
static constexpr std::size_t pressureIndex
Definition: ISTLSolver.hpp:171
void prepareFlexibleSolver()
Definition: ISTLSolver.hpp:508
GetPropType< TypeTag, Properties::ThreadManager > ThreadManager
Definition: ISTLSolver.hpp:162
GetPropType< TypeTag, Properties::ElementMapper > ElementMapper
Definition: ISTLSolver.hpp:168
void resetSolveCount()
Definition: ISTLSolver.hpp:433
GetPropType< TypeTag, Properties::GlobalEqVector > Vector
Definition: ISTLSolver.hpp:157
const std::any & parallelInformation() const
Definition: ISTLSolver.hpp:476
void initPrepare(const Matrix &M, Vector &b)
Definition: ISTLSolver.hpp:361
std::vector< detail::FlexibleSolverInfo< Matrix, Vector, CommunicationType > > flexibleSolver_
Definition: ISTLSolver.hpp:708
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:621
Dune::AssembledLinearOperator< Matrix, Vector, Vector > AssembledLinearOperatorType
Definition: ISTLSolver.hpp:183
ISTLSolver(const Simulator &simulator)
Definition: ISTLSolver.hpp:211
int iterations_
Definition: ISTLSolver.hpp:699
int domainIndex_
Definition: ISTLSolver.hpp:712
std::any parallelInformation_
Definition: ISTLSolver.hpp:701
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: ISTLSolver.hpp:160
Vector * rhs_
Definition: ISTLSolver.hpp:705
int activeSolverNum_
Definition: ISTLSolver.hpp:707
std::vector< int > overlapRows_
Definition: ISTLSolver.hpp:709
std::unique_ptr< ElementChunksType > element_chunks_
Definition: ISTLSolver.hpp:725
GetPropType< TypeTag, Properties::Indices > Indices
Definition: ISTLSolver.hpp:158
static constexpr bool enablePolymerMolarWeight
Definition: ISTLSolver.hpp:173
const Simulator & simulator_
Definition: ISTLSolver.hpp:698
std::vector< int > interiorRows_
Definition: ISTLSolver.hpp:710
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: ISTLSolver.hpp:492
bool forceSerial_
Definition: ISTLSolver.hpp:721
bool solve(Vector &x) override
Definition: ISTLSolver.hpp:437
int numWellEquations_
Definition: ISTLSolver.hpp:716
static void registerParameters()
Definition: ISTLSolver.hpp:185
std::vector< PropertyTree > prm_
Definition: ISTLSolver.hpp:722
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: ISTLSolver.hpp:163
void setResidual(Vector &) override
Definition: ISTLSolver.hpp:414
const CommunicationType * comm() const override
Get the communication object used by the solver.
Definition: ISTLSolver.hpp:478
bool isParallel() const
Definition: ISTLSolver.hpp:500
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