version 3.7
istlsolvers.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_LINEAR_ISTL_SOLVERS_HH
13#define DUMUX_LINEAR_ISTL_SOLVERS_HH
14
15#include <memory>
16#include <variant>
17
18#include <dune/common/exceptions.hh>
19#include <dune/common/shared_ptr.hh>
20#include <dune/common/parallel/indexset.hh>
21#include <dune/common/parallel/mpicommunication.hh>
22#include <dune/grid/common/capabilities.hh>
23#include <dune/istl/solvers.hh>
24#include <dune/istl/solverfactory.hh>
25#include <dune/istl/owneroverlapcopy.hh>
26#include <dune/istl/scalarproducts.hh>
27#include <dune/istl/paamg/amg.hh>
28#include <dune/istl/paamg/pinfo.hh>
29
39
41
48template<class M>
49constexpr std::size_t preconditionerBlockLevel() noexcept
50{
52}
53
54template<template<class,class,class,int> class Preconditioner, int blockLevel = 1>
56{
57public:
58 template<class TL, class M>
59 auto operator() (TL typeList, const M& matrix, const Dune::ParameterTree& config)
60 {
61 using Matrix = typename Dune::TypeListElement<0, decltype(typeList)>::type;
62 using Domain = typename Dune::TypeListElement<1, decltype(typeList)>::type;
63 using Range = typename Dune::TypeListElement<2, decltype(typeList)>::type;
64 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner
65 = std::make_shared<Preconditioner<Matrix, Domain, Range, blockLevel>>(matrix, config);
66 return preconditioner;
67 }
68};
69
70template<template<class,class,class> class Preconditioner>
72{
73 template<class TL, class M>
74 auto operator() (TL typeList, const M& matrix, const Dune::ParameterTree& config)
75 {
76 using Matrix = typename Dune::TypeListElement<0, decltype(typeList)>::type;
77 using Domain = typename Dune::TypeListElement<1, decltype(typeList)>::type;
78 using Range = typename Dune::TypeListElement<2, decltype(typeList)>::type;
79 std::shared_ptr<Dune::Preconditioner<Domain, Range>> preconditioner
80 = std::make_shared<Preconditioner<Matrix, Domain, Range>>(matrix, config);
81 return preconditioner;
82 }
83};
84
85using IstlAmgPreconditionerFactory = Dune::AMGCreator;
86
87template<class M, bool convert = false>
88struct MatrixForSolver { using type = M; };
89
90template<class M>
91struct MatrixForSolver<M, true>
92{ using type = std::decay_t<decltype(MatrixConverter<M>::multiTypeToBCRSMatrix(std::declval<M>()))>; };
93
94template<class V, bool convert = false>
95struct VectorForSolver { using type = V; };
96
97template<class V>
98struct VectorForSolver<V, true>
99{ using type = std::decay_t<decltype(VectorConverter<V>::multiTypeToBlockVector(std::declval<V>()))>; };
100
101template<class LSTraits, class LATraits, bool convert, bool parallel = LSTraits::canCommunicate>
103
104template<class LSTraits, class LATraits, bool convert>
105struct MatrixOperator<LSTraits, LATraits, convert, true>
106{
109#if HAVE_MPI
110 using type = std::variant<
111 std::shared_ptr<typename LSTraits::template Sequential<M, V>::LinearOperator>,
112 std::shared_ptr<typename LSTraits::template ParallelOverlapping<M, V>::LinearOperator>,
113 std::shared_ptr<typename LSTraits::template ParallelNonoverlapping<M, V>::LinearOperator>
114 >;
115#else
116 using type = std::variant<
117 std::shared_ptr<typename LSTraits::template Sequential<M, V>::LinearOperator>
118 >;
119#endif
120};
121
122template<class LSTraits, class LATraits, bool convert>
123struct MatrixOperator<LSTraits, LATraits, convert, false>
124{
127 using type = std::variant<
128 std::shared_ptr<typename LSTraits::template Sequential<M, V>::LinearOperator>
129 >;
130};
131
132} // end namespace Dumux::Detail::IstlSolvers
133
134namespace Dumux::Detail {
135
136struct IstlSolverResult : public Dune::InverseOperatorResult
137{
138 IstlSolverResult() = default;
141
142 IstlSolverResult(const Dune::InverseOperatorResult& o) : InverseOperatorResult(o) {}
143 IstlSolverResult(Dune::InverseOperatorResult&& o) : InverseOperatorResult(std::move(o)) {}
144
145 operator bool() const { return this->converged; }
146};
147
152template<class LinearSolverTraits, class LinearAlgebraTraits,
153 class InverseOperator, class PreconditionerFactory,
154 bool convertMultiTypeLATypes = false>
156{
157 using Matrix = typename LinearAlgebraTraits::Matrix;
158 using XVector = typename LinearAlgebraTraits::Vector;
159 using BVector = typename LinearAlgebraTraits::Vector;
160 using Scalar = typename InverseOperator::real_type;
161
162 using ScalarProduct = Dune::ScalarProduct<typename InverseOperator::domain_type>;
163
164 static constexpr bool convertMultiTypeVectorAndMatrix
165 = convertMultiTypeLATypes && isMultiTypeBlockVector<XVector>::value;
169 // a variant type that can hold sequential, overlapping, and non-overlapping operators
170 using MatrixOperatorHolder = typename Detail::IstlSolvers::MatrixOperator<
171 LinearSolverTraits, LinearAlgebraTraits, convertMultiTypeVectorAndMatrix
172 >::type;
173
174#if HAVE_MPI
175 using Comm = Dune::OwnerOverlapCopyCommunication<Dune::bigunsignedint<96>, int>;
177#endif
178
179 using ParameterInitializer = std::variant<std::string, Dune::ParameterTree>;
180public:
181
185 IstlIterativeLinearSolver(const ParameterInitializer& params = "")
186 {
187 if (Dune::MPIHelper::getCommunication().size() > 1)
188 DUNE_THROW(Dune::InvalidStateException, "Using sequential constructor for parallel run. Use signature with gridView and dofMapper!");
189
190 initializeParameters_(params);
191 solverCategory_ = Dune::SolverCategory::sequential;
192 scalarProduct_ = std::make_shared<ScalarProduct>();
193 }
194
198 template <class GridView, class DofMapper>
199 IstlIterativeLinearSolver(const GridView& gridView,
200 const DofMapper& dofMapper,
201 const ParameterInitializer& params = "")
202 {
203 initializeParameters_(params);
204#if HAVE_MPI
205 solverCategory_ = Detail::solverCategory<LinearSolverTraits>(gridView);
207 {
208
209 if (solverCategory_ != Dune::SolverCategory::sequential)
210 {
211 parallelHelper_ = std::make_shared<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper);
212 communication_ = std::make_shared<Comm>(gridView.comm(), solverCategory_);
213 scalarProduct_ = Dune::createScalarProduct<XVector>(*communication_, solverCategory_);
214 parallelHelper_->createParallelIndexSet(*communication_);
215 }
216 else
217 scalarProduct_ = std::make_shared<ScalarProduct>();
218 }
219 else
220 scalarProduct_ = std::make_shared<ScalarProduct>();
221#else
222 solverCategory_ = Dune::SolverCategory::sequential;
223 scalarProduct_ = std::make_shared<ScalarProduct>();
224#endif
225 }
226
227#if HAVE_MPI
231 template <class GridView, class DofMapper>
232 IstlIterativeLinearSolver(std::shared_ptr<Comm> communication,
233 std::shared_ptr<ScalarProduct> scalarProduct,
234 const GridView& gridView,
235 const DofMapper& dofMapper,
236 const ParameterInitializer& params = "")
237 {
238 initializeParameters_(params);
239 solverCategory_ = Detail::solverCategory(gridView);
240 scalarProduct_ = scalarProduct;
241 communication_ = communication;
243 {
244 if (solverCategory_ != Dune::SolverCategory::sequential)
245 {
246 parallelHelper_ = std::make_shared<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper);
247 parallelHelper_->createParallelIndexSet(communication);
248 }
249 }
250 }
251#endif
252
256 IstlSolverResult solve(Matrix& A, XVector& x, BVector& b)
257 { return solveSequentialOrParallel_(A, x, b); }
258
262 void setMatrix(std::shared_ptr<Matrix> A)
263 {
264 linearOperator_ = makeParallelOrSequentialLinearOperator_(std::move(A));
265 solver_ = constructPreconditionedSolver_(linearOperator_);
266 }
267
272 void setMatrix(Matrix& A)
273 { setMatrix(Dune::stackobject_to_shared_ptr(A)); }
274
278 IstlSolverResult solve(XVector& x, BVector& b) const
279 {
280 if (!solver_)
281 DUNE_THROW(Dune::InvalidStateException, "Called solve(x, b) but no linear operator has been set");
282
283 return solveSequentialOrParallel_(x, b, *solver_);
284 }
285
289 Scalar norm(const XVector& x) const
290 {
291#if HAVE_MPI
293 {
294 if (solverCategory_ == Dune::SolverCategory::nonoverlapping)
295 {
296 auto y(x); // make a copy because the vector needs to be made consistent
297 using GV = typename LinearSolverTraits::GridView;
298 using DM = typename LinearSolverTraits::DofMapper;
299 ParallelVectorHelper<GV, DM, LinearSolverTraits::dofCodim> vectorHelper(parallelHelper_->gridView(), parallelHelper_->dofMapper());
300 vectorHelper.makeNonOverlappingConsistent(y);
301 return scalarProduct_->norm(y);
302 }
303 }
304#endif
305 if constexpr (convertMultiTypeVectorAndMatrix)
306 {
308 return scalarProduct_->norm(y);
309 }
310 else
311 return scalarProduct_->norm(x);
312 }
313
317 const std::string& name() const
318 {
319 return name_;
320 }
321
325 void setResidualReduction(double residReduction)
326 {
327 params_["reduction"] = std::to_string(residReduction);
328
329 // reconstruct the solver with new parameters
330 if (solver_)
331 solver_ = constructPreconditionedSolver_(linearOperator_);
332 }
333
337 void setMaxIter(std::size_t maxIter)
338 {
339 params_["maxit"] = std::to_string(maxIter);
340
341 // reconstruct the solver with new parameters
342 if (solver_)
343 solver_ = constructPreconditionedSolver_(linearOperator_);
344 }
345
351 void setParams(const ParameterInitializer& params)
352 {
353 initializeParameters_(params);
354
355 // reconstruct the solver with new parameters
356 if (solver_)
357 solver_ = constructPreconditionedSolver_(linearOperator_);
358 }
359
360private:
361
362 void initializeParameters_(const ParameterInitializer& params)
363 {
364 if (std::holds_alternative<std::string>(params))
365 params_ = Dumux::LinearSolverParameters<LinearSolverTraits>::createParameterTree(std::get<std::string>(params));
366 else
367 params_ = std::get<Dune::ParameterTree>(params);
368 }
369
370 MatrixOperatorHolder makeSequentialLinearOperator_(std::shared_ptr<Matrix> A)
371 {
372 using SequentialTraits = typename LinearSolverTraits::template Sequential<MatrixForSolver, XVectorForSolver>;
373 if constexpr (convertMultiTypeVectorAndMatrix)
374 {
375 // create the BCRS matrix the IterativeSolver backend can handle
376 auto M = std::make_shared<MatrixForSolver>(MatrixConverter<Matrix>::multiTypeToBCRSMatrix(*A));
377 return std::make_shared<typename SequentialTraits::LinearOperator>(M);
378 }
379 else
380 {
381 return std::make_shared<typename SequentialTraits::LinearOperator>(A);
382 }
383 }
384
385 template<class ParallelTraits>
386 MatrixOperatorHolder makeParallelLinearOperator_(std::shared_ptr<Matrix> A, ParallelTraits = {})
387 {
388#if HAVE_MPI
389 // make matrix consistent
390 prepareMatrixParallel<LinearSolverTraits, ParallelTraits>(*A, *parallelHelper_);
391 return std::make_shared<typename ParallelTraits::LinearOperator>(std::move(A), *communication_);
392#else
393 DUNE_THROW(Dune::InvalidStateException, "Calling makeParallelLinearOperator for sequential run");
394#endif
395 }
396
397 MatrixOperatorHolder makeParallelOrSequentialLinearOperator_(std::shared_ptr<Matrix> A)
398 {
399 return executeSequentialOrParallel_(
400 [&]{ return makeSequentialLinearOperator_(std::move(A)); },
401 [&](auto traits){ return makeParallelLinearOperator_(std::move(A), traits); }
402 );
403 }
404
405 MatrixOperatorHolder makeSequentialLinearOperator_(Matrix& A)
406 { return makeSequentialLinearOperator_(Dune::stackobject_to_shared_ptr<Matrix>(A)); }
407
408 MatrixOperatorHolder makeParallelOrSequentialLinearOperator_(Matrix& A)
409 { return makeParallelOrSequentialLinearOperator_(Dune::stackobject_to_shared_ptr<Matrix>(A)); }
410
411 template<class ParallelTraits>
412 MatrixOperatorHolder makeParallelLinearOperator_(Matrix& A, ParallelTraits = {})
413 { return makeParallelLinearOperator_<ParallelTraits>(Dune::stackobject_to_shared_ptr<Matrix>(A)); }
414
415 IstlSolverResult solveSequential_(Matrix& A, XVector& x, BVector& b)
416 {
417 // construct solver from linear operator
418 auto linearOperatorHolder = makeSequentialLinearOperator_(A);
419 auto solver = constructPreconditionedSolver_(linearOperatorHolder);
420
421 return solveSequential_(x, b, *solver);
422 }
423
424 IstlSolverResult solveSequential_(XVector& x, BVector& b, InverseOperator& solver) const
425 {
426 Dune::InverseOperatorResult result;
427 if constexpr (convertMultiTypeVectorAndMatrix)
428 {
429 // create the vector the IterativeSolver backend can handle
430 BVectorForSolver bTmp = VectorConverter<BVector>::multiTypeToBlockVector(b);
431
432 // create a block vector to which the linear solver writes the solution
433 XVectorForSolver y(bTmp.size());
434
435 // solve linear system
436 solver.apply(y, bTmp, result);
437
438 // copy back the result y into x
439 if (result.converged)
441 }
442 else
443 {
444 // solve linear system
445 solver.apply(x, b, result);
446 }
447
448 return result;
449 }
450
451 IstlSolverResult solveSequentialOrParallel_(Matrix& A, XVector& x, BVector& b)
452 {
453 return executeSequentialOrParallel_(
454 [&]{ return solveSequential_(A, x, b); },
455 [&](auto traits){ return solveParallel_(A, x, b, traits); }
456 );
457 }
458
459 IstlSolverResult solveSequentialOrParallel_(XVector& x, BVector& b, InverseOperator& solver) const
460 {
461 return executeSequentialOrParallel_(
462 [&]{ return solveSequential_(x, b, solver); },
463 [&](auto traits){ return solveParallel_(x, b, solver, traits); }
464 );
465 }
466
467 template<class ParallelTraits>
468 IstlSolverResult solveParallel_(Matrix& A, XVector& x, BVector& b, ParallelTraits = {})
469 {
470 // construct solver from linear operator
471 auto linearOperatorHolder = makeParallelLinearOperator_<ParallelTraits>(A);
472 auto solver = constructPreconditionedSolver_(linearOperatorHolder);
473 return solveParallel_<ParallelTraits>(x, b, *solver);
474 }
475
476 template<class ParallelTraits>
477 IstlSolverResult solveParallel_(XVector& x, BVector& b, InverseOperator& solver, ParallelTraits = {}) const
478 {
479#if HAVE_MPI
480 // make right hand side consistent
481 prepareVectorParallel<LinearSolverTraits, ParallelTraits>(b, *parallelHelper_);
482
483 // solve linear system
484 Dune::InverseOperatorResult result;
485 solver.apply(x, b, result);
486 return result;
487#else
488 DUNE_THROW(Dune::InvalidStateException, "Calling makeParallelLinearOperator for sequential run");
489#endif
490 }
491
492
493 std::shared_ptr<InverseOperator> constructPreconditionedSolver_(MatrixOperatorHolder& ops)
494 {
495 return std::visit([&](auto&& op)
496 {
497 using LinearOperator = typename std::decay_t<decltype(op)>::element_type;
498 const auto& params = params_.sub("preconditioner");
499 using Prec = Dune::Preconditioner<typename LinearOperator::domain_type, typename LinearOperator::range_type>;
500 using TL = Dune::TypeList<typename LinearOperator::matrix_type, typename LinearOperator::domain_type, typename LinearOperator::range_type>;
501 std::shared_ptr<Prec> prec = PreconditionerFactory{}(TL{}, op, params);
502
503#if HAVE_MPI
504 if (prec->category() != op->category() && prec->category() == Dune::SolverCategory::sequential)
505 prec = Dune::wrapPreconditioner4Parallel(prec, op);
506#endif
507 return std::make_shared<InverseOperator>(op, scalarProduct_, prec, params_);
508 }, ops);
509 }
510
511 template<class Seq, class Par>
512 decltype(auto) executeSequentialOrParallel_(Seq&& sequentialAction, Par&& parallelAction) const
513 {
514#if HAVE_MPI
515 // For Dune::MultiTypeBlockMatrix there is currently no generic way
516 // of handling parallelism, we therefore can only solve these types of systems sequentially
517 if constexpr (isMultiTypeBlockMatrix<Matrix>::value || !LinearSolverTraits::canCommunicate)
518 return sequentialAction();
519 else
520 {
521 switch (solverCategory_)
522 {
523 case Dune::SolverCategory::sequential:
524 return sequentialAction();
525 case Dune::SolverCategory::nonoverlapping:
526 using NOTraits = typename LinearSolverTraits::template ParallelNonoverlapping<Matrix, XVector>;
527 return parallelAction(NOTraits{});
528 case Dune::SolverCategory::overlapping:
529 using OTraits = typename LinearSolverTraits::template ParallelOverlapping<Matrix, XVector>;
530 return parallelAction(OTraits{});
531 default: DUNE_THROW(Dune::InvalidStateException, "Unknown solver category");
532 }
533 }
534#else
535 return sequentialAction();
536#endif
537 }
538
539#if HAVE_MPI
540 std::shared_ptr<const ParallelHelper> parallelHelper_;
541 std::shared_ptr<Comm> communication_;
542#endif
543
544 Dune::SolverCategory::Category solverCategory_;
545 std::shared_ptr<ScalarProduct> scalarProduct_;
546
547 // for stored solvers (reuse matrix)
548 MatrixOperatorHolder linearOperator_;
549 // for stored solvers (reuse matrix)
550 std::shared_ptr<InverseOperator> solver_;
551
552 Dune::ParameterTree params_;
553 std::string name_;
554};
555
556} // end namespace Dumux::Detail
557
558namespace Dumux {
559
576template<class LSTraits, class LATraits>
578 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
579 Dune::BiCGSTABSolver<typename LATraits::SingleTypeVector>,
581 // the Dune::ILU preconditioners don't accept multi-type matrices
582 /*convert multi-type istl types?*/ true
583 >;
584
601template<class LSTraits, class LATraits>
603 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
604 Dune::RestartedGMResSolver<typename LATraits::SingleTypeVector>,
606 // the Dune::ILU preconditioners don't accept multi-type matrices
607 /*convert multi-type istl types?*/ true
608 >;
609
627template<class LSTraits, class LATraits>
629 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
630 Dune::BiCGSTABSolver<typename LATraits::Vector>,
632 >;
633
650template<class LSTraits, class LATraits>
652 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
653 Dune::CGSolver<typename LATraits::Vector>,
655 >;
656
670template<class LSTraits, class LATraits>
672 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
673 Dune::BiCGSTABSolver<typename LATraits::SingleTypeVector>,
675 // the AMG preconditioner doesn't accept multi-type matrices
676 /*convert multi-type istl types?*/ true
677 >;
678
691template<class LSTraits, class LATraits>
693 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
694 Dune::CGSolver<typename LATraits::SingleTypeVector>,
696 // the AMG preconditioner doesn't accept multi-type matrices
697 /*convert multi-type istl types?*/ true
698 >;
699
714template<class LSTraits, class LATraits>
716 Detail::IstlIterativeLinearSolver<LSTraits, LATraits,
717 Dune::BiCGSTABSolver<typename LATraits::Vector>,
719 >;
720
721} // end namespace Dumux
722
723namespace Dumux::Detail {
724
729template<class LSTraits, class LATraits, template<class M> class Solver>
731{
732 using Matrix = typename LATraits::Matrix;
733 using XVector = typename LATraits::Vector;
734 using BVector = typename LATraits::Vector;
735
736 static constexpr bool convertMultiTypeVectorAndMatrix = isMultiTypeBlockVector<XVector>::value;
740 using InverseOperator = Dune::InverseOperator<XVectorForSolver, BVectorForSolver>;
741public:
743
747 IstlSolverResult solve(const Matrix& A, XVector& x, const BVector& b)
748 {
749 return solve_(A, x, b);
750 }
751
755 IstlSolverResult solve(XVector& x, const BVector& b)
756 {
757 if (!solver_)
758 DUNE_THROW(Dune::InvalidStateException, "Called solve(x, b) but no linear operator has been set");
759
760 return solve_(x, b, *solver_);
761 }
762
766 void setMatrix(std::shared_ptr<Matrix> A)
767 {
768 if constexpr (convertMultiTypeVectorAndMatrix)
769 matrix_ = std::make_shared<MatrixForSolver>(MatrixConverter<Matrix>::multiTypeToBCRSMatrix(A));
770 else
771 matrix_ = A;
772
773 solver_ = std::make_shared<Solver<MatrixForSolver>>(*matrix_);
774 }
775
780 void setMatrix(Matrix& A)
781 { setMatrix(Dune::stackobject_to_shared_ptr(A)); }
782
786 std::string name() const
787 {
788 return "Direct solver";
789 }
790
791private:
792 IstlSolverResult solve_(const Matrix& A, XVector& x, const BVector& b)
793 {
794 // support dune-istl multi-type block vector/matrix by copying
795 if constexpr (isMultiTypeBlockVector<BVector>())
796 {
798 Solver<MatrixForSolver> solver(AA, this->verbosity() > 0);
799 return solve_(x, b, solver);
800 }
801 else
802 {
803 Solver<MatrixForSolver> solver(A, this->verbosity() > 0);
804 return solve_(x, b, solver);
805 }
806 }
807
808 IstlSolverResult solve_(XVector& x, const BVector& b, InverseOperator& solver) const
809 {
810 static_assert(isBCRSMatrix<MatrixForSolver>::value, "Direct solver only works with BCRS matrices!");
811 static_assert(MatrixForSolver::block_type::rows == MatrixForSolver::block_type::cols, "Matrix block must be quadratic!");
812
813 Dune::InverseOperatorResult result;
814 if constexpr (isMultiTypeBlockVector<BVector>())
815 {
817 XVectorForSolver xx(bb.size());
818 solver.apply(xx, bb, result);
819 checkResult_(xx, result);
820 if (result.converged)
822 return result;
823 }
824 else
825 {
826 BVectorForSolver bTmp(b);
827 solver.apply(x, bTmp, result);
828 checkResult_(x, result);
829 return result;
830 }
831 }
832
833 void checkResult_(const XVectorForSolver& x, Dune::InverseOperatorResult& result) const
834 {
835 int size = x.size();
836 for (int i = 0; i < size; i++)
837 {
838 for (int j = 0; j < x[i].size(); j++)
839 {
840 using std::isnan;
841 using std::isinf;
842 if (isnan(x[i][j]) || isinf(x[i][j]))
843 {
844 result.converged = false;
845 break;
846 }
847 }
848 }
849 }
850
852 std::shared_ptr<MatrixForSolver> matrix_;
854 std::shared_ptr<InverseOperator> solver_;
855};
856
857} // end namespace Dumux::Detail
858
859#if HAVE_SUPERLU
860#include <dune/istl/superlu.hh>
861
862namespace Dumux {
863
872template<class LSTraits, class LATraits>
873using SuperLUIstlSolver = Detail::DirectIstlSolver<LSTraits, LATraits, Dune::SuperLU>;
874
875} // end namespace Dumux
876
877#endif // HAVE_SUPERLU
878
879#if HAVE_UMFPACK
880#include <dune/istl/umfpack.hh>
881
882namespace Dumux {
883
892template<class LSTraits, class LATraits>
893using UMFPackIstlSolver = Detail::DirectIstlSolver<LSTraits, LATraits, Dune::UMFPack>;
894
895} // end namespace Dumux
896
897#endif // HAVE_UMFPACK
898
899#endif
Direct dune-istl linear solvers.
Definition: istlsolvers.hh:731
IstlSolverResult solve(const Matrix &A, XVector &x, const BVector &b)
Solve the linear system Ax = b.
Definition: istlsolvers.hh:747
void setMatrix(std::shared_ptr< Matrix > A)
Set the matrix A of the linear system Ax = b for reuse.
Definition: istlsolvers.hh:766
IstlSolverResult solve(XVector &x, const BVector &b)
Solve the linear system Ax = b using the matrix set with setMatrix.
Definition: istlsolvers.hh:755
void setMatrix(Matrix &A)
Set the matrix A of the linear system Ax = b for reuse.
Definition: istlsolvers.hh:780
std::string name() const
name of the linear solver
Definition: istlsolvers.hh:786
Standard dune-istl iterative linear solvers.
Definition: istlsolvers.hh:156
IstlIterativeLinearSolver(const ParameterInitializer &params="")
Constructor for sequential solvers.
Definition: istlsolvers.hh:185
void setMatrix(Matrix &A)
Set the matrix A of the linear system Ax = b for reuse.
Definition: istlsolvers.hh:272
void setResidualReduction(double residReduction)
Set the residual reduction tolerance.
Definition: istlsolvers.hh:325
void setMaxIter(std::size_t maxIter)
Set the maximum number of linear solver iterations.
Definition: istlsolvers.hh:337
IstlIterativeLinearSolver(const GridView &gridView, const DofMapper &dofMapper, const ParameterInitializer &params="")
Constructor for parallel and sequential solvers.
Definition: istlsolvers.hh:199
const std::string & name() const
The name of the linear solver.
Definition: istlsolvers.hh:317
void setParams(const ParameterInitializer &params)
Set the linear solver parameters.
Definition: istlsolvers.hh:351
IstlSolverResult solve(Matrix &A, XVector &x, BVector &b)
Solve the linear system Ax = b.
Definition: istlsolvers.hh:256
void setMatrix(std::shared_ptr< Matrix > A)
Set the matrix A of the linear system Ax = b for reuse.
Definition: istlsolvers.hh:262
IstlSolverResult solve(XVector &x, BVector &b) const
Solve the linear system Ax = b where A has been set with setMatrix.
Definition: istlsolvers.hh:278
IstlIterativeLinearSolver(std::shared_ptr< Comm > communication, std::shared_ptr< ScalarProduct > scalarProduct, const GridView &gridView, const DofMapper &dofMapper, const ParameterInitializer &params="")
Constructor with custom scalar product and communication.
Definition: istlsolvers.hh:232
Scalar norm(const XVector &x) const
Compute the 2-norm of vector x.
Definition: istlsolvers.hh:289
auto operator()(TL typeList, const M &matrix, const Dune::ParameterTree &config)
Definition: istlsolvers.hh:59
Definition: parallelhelpers.hh:29
Base class for linear solvers.
Definition: solver.hh:27
LinearSolver(const std::string &paramGroup="")
Construct the solver.
Definition: solver.hh:43
int verbosity() const
the verbosity level
Definition: solver.hh:82
static Dune::ParameterTree createParameterTree(const std::string &paramGroup="")
Create a tree containing parameters required for the linear solvers and precondioners of the Dune IST...
Definition: linearsolverparameters.hh:47
A helper class that converts a Dune::MultiTypeBlockMatrix into a plain Dune::BCRSMatrix TODO: allow b...
Definition: matrixconverter.hh:35
static auto multiTypeToBCRSMatrix(const MultiTypeBlockMatrix &A)
Converts the matrix to a type the IterativeSolverBackend can handle.
Definition: matrixconverter.hh:46
Definition: parallelhelpers.hh:476
void makeNonOverlappingConsistent(Dune::BlockVector< Block, Alloc > &v) const
Make a vector consistent for non-overlapping domain decomposition methods.
Definition: parallelhelpers.hh:484
static void retrieveValues(MultiTypeBlockVector &x, const BlockVector &y)
Copies the entries of a Dune::BlockVector to a Dune::MultiTypeBlockVector.
Definition: matrixconverter.hh:229
static auto multiTypeToBlockVector(const MultiTypeBlockVector &b)
Converts a Dune::MultiTypeBlockVector to a plain 1x1 Dune::BlockVector.
Definition: matrixconverter.hh:203
constexpr std::size_t preconditionerBlockLevel() noexcept
Returns the block level for the preconditioner for a given matrix.
Definition: istlsolvers.hh:49
Define traits for linear algebra backends.
Generates a parameter tree required for the linear solvers and precondioners of the Dune ISTL.
Type traits to be used with matrix types.
A helper class that converts a Dune::MultiTypeBlockMatrix into a plain Dune::BCRSMatrix.
Definition: istlsolvers.hh:40
Dune::AMGCreator IstlAmgPreconditionerFactory
Definition: istlsolvers.hh:85
Distance implementation details.
Definition: cvfelocalresidual.hh:25
static constexpr bool canCommunicate
Definition: gridcapabilities.hh:51
Dune::SolverCategory::Category solverCategory(const GridView &gridView)
Definition: solvercategory.hh:15
Definition: adapt.hh:17
LinearSolverTraitsImpl< GridGeometry, typename GridGeometry::DiscretizationMethod > LinearSolverTraits
The type traits required for using the IstlFactoryBackend.
Definition: linearsolvertraits.hh:37
Provides a helper class for nonoverlapping decomposition.
Dumux preconditioners for iterative solvers.
Base class for linear solvers.
Definition: istlsolvers.hh:137
IstlSolverResult(IstlSolverResult &&)=default
IstlSolverResult(const Dune::InverseOperatorResult &o)
Definition: istlsolvers.hh:142
IstlSolverResult(Dune::InverseOperatorResult &&o)
Definition: istlsolvers.hh:143
IstlSolverResult(const IstlSolverResult &)=default
std::decay_t< decltype(MatrixConverter< M >::multiTypeToBCRSMatrix(std::declval< M >()))> type
Definition: istlsolvers.hh:92
Definition: istlsolvers.hh:88
M type
Definition: istlsolvers.hh:88
typename VectorForSolver< typename LATraits::Vector, convert >::type V
Definition: istlsolvers.hh:126
std::variant< std::shared_ptr< typename LSTraits::template Sequential< M, V >::LinearOperator > > type
Definition: istlsolvers.hh:129
typename MatrixForSolver< typename LATraits::Matrix, convert >::type M
Definition: istlsolvers.hh:125
std::variant< std::shared_ptr< typename LSTraits::template Sequential< M, V >::LinearOperator >, std::shared_ptr< typename LSTraits::template ParallelOverlapping< M, V >::LinearOperator >, std::shared_ptr< typename LSTraits::template ParallelNonoverlapping< M, V >::LinearOperator > > type
Definition: istlsolvers.hh:114
typename VectorForSolver< typename LATraits::Vector, convert >::type V
Definition: istlsolvers.hh:108
typename MatrixForSolver< typename LATraits::Matrix, convert >::type M
Definition: istlsolvers.hh:107
Definition: istlsolvers.hh:102
std::decay_t< decltype(VectorConverter< V >::multiTypeToBlockVector(std::declval< V >()))> type
Definition: istlsolvers.hh:99
Definition: istlsolvers.hh:95
V type
Definition: istlsolvers.hh:95
Definition: linearalgebratraits.hh:51
V Vector
Definition: linearalgebratraits.hh:53
M Matrix
Definition: linearalgebratraits.hh:52
Helper type to determine whether a given type is a Dune::MultiTypeBlockMatrix.
Definition: matrix.hh:37
Helper type to determine whether a given type is a Dune::MultiTypeBlockVector.
Definition: vector.hh:22
Type traits to be used with vector types.