dune-istl 2.12-git
Loading...
Searching...
No Matches
umfpack.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ISTL_UMFPACK_HH
6#define DUNE_ISTL_UMFPACK_HH
7
8#if HAVE_SUITESPARSE_UMFPACK || defined DOXYGEN
9
10#include<complex>
11#include<type_traits>
12
13#include<umfpack.h>
14
22#include<dune/istl/matrix.hh>
30
31
32
33namespace Dune {
45 // FORWARD DECLARATIONS
46 template<class M, class T, class TM, class TD, class TA>
47 class SeqOverlappingSchwarz;
48
49 template<class T, bool tag>
50 struct SeqOverlappingSchwarzAssemblerHelper;
51
52 // wrapper class for C-Function Calls in the backend. Choose the right function namespace
53 // depending on the template parameter used.
54 template<typename T>
56 {
57 static constexpr bool valid = false ;
58 };
59
60 template<>
61 struct UMFPackMethodChooser<double>
62 {
63 static constexpr bool valid = true ;
64
65 template<typename... A>
66 static void defaults(A... args)
67 {
68 umfpack_dl_defaults(args...);
69 }
70 template<typename... A>
71 static void free_numeric(A... args)
72 {
73 umfpack_dl_free_numeric(args...);
74 }
75 template<typename... A>
76 static void free_symbolic(A... args)
77 {
78 umfpack_dl_free_symbolic(args...);
79 }
80 template<typename... A>
81 static int load_numeric(A... args)
82 {
83 return umfpack_dl_load_numeric(args...);
84 }
85 template<typename... A>
86 static void numeric(A... args)
87 {
88 umfpack_dl_numeric(args...);
89 }
90 template<typename... A>
91 static void report_info(A... args)
92 {
93 umfpack_dl_report_info(args...);
94 }
95 template<typename... A>
96 static void report_status(A... args)
97 {
98 umfpack_dl_report_status(args...);
99 }
100 template<typename... A>
101 static int save_numeric(A... args)
102 {
103 return umfpack_dl_save_numeric(args...);
104 }
105 template<typename... A>
106 static void solve(A... args)
107 {
108 umfpack_dl_solve(args...);
109 }
110 template<typename... A>
111 static void symbolic(A... args)
112 {
113 umfpack_dl_symbolic(args...);
114 }
115 };
116
117 template<>
118 struct UMFPackMethodChooser<std::complex<double> >
119 {
120 static constexpr bool valid = true ;
121 using size_type = SuiteSparse_long;
122
123 template<typename... A>
124 static void defaults(A... args)
125 {
126 umfpack_zl_defaults(args...);
127 }
128 template<typename... A>
129 static void free_numeric(A... args)
130 {
131 umfpack_zl_free_numeric(args...);
132 }
133 template<typename... A>
134 static void free_symbolic(A... args)
135 {
136 umfpack_zl_free_symbolic(args...);
137 }
138 template<typename... A>
139 static int load_numeric(A... args)
140 {
141 return umfpack_zl_load_numeric(args...);
142 }
143 template<typename... A>
144 static void numeric(const size_type* cs, const size_type* ri, const double* val, A... args)
145 {
146 umfpack_zl_numeric(cs,ri,val,NULL,args...);
147 }
148 template<typename... A>
149 static void report_info(A... args)
150 {
151 umfpack_zl_report_info(args...);
152 }
153 template<typename... A>
154 static void report_status(A... args)
155 {
156 umfpack_zl_report_status(args...);
157 }
158 template<typename... A>
159 static int save_numeric(A... args)
160 {
161 return umfpack_zl_save_numeric(args...);
162 }
163 template<typename... A>
164 static void solve(size_type m, const size_type* cs, const size_type* ri, std::complex<double>* val, double* x, const double* b,A... args)
165 {
166 const double* cval = reinterpret_cast<const double*>(val);
167 umfpack_zl_solve(m,cs,ri,cval,NULL,x,NULL,b,NULL,args...);
168 }
169 template<typename... A>
170 static void symbolic(size_type m, size_type n, const size_type* cs, const size_type* ri, const double* val, A... args)
171 {
172 umfpack_zl_symbolic(m,n,cs,ri,val,NULL,args...);
173 }
174 };
175
176 namespace Impl
177 {
178 template<class M, class F = typename Dune::FieldTraits<M>::field_type>
179 requires (std::is_same_v<F, double> || std::is_same_v<F, std::complex<double>>)
180 struct UMFPackVectorChooser : public DefaultMatrixVectorTraits<M> {};
181
183 template<class M> using UMFPackDomainType = typename UMFPackVectorChooser<M>::domain_type;
184
186 template<class M> using UMFPackRangeType = typename UMFPackVectorChooser<M>::range_type;
187
188 // dummy class to represent no BitVector
189 struct NoBitVector
190 {};
191
192
193 }
194
208 template<typename M>
209 class UMFPack : public InverseOperator<Impl::UMFPackDomainType<M>,Impl::UMFPackRangeType<M>>
210 {
211 using T = typename M::field_type;
212
213 public:
214 using size_type = SuiteSparse_long;
215
217 using Matrix = M;
218 using matrix_type = M;
220 using UMFPackMatrix = ISTL::Impl::BCCSMatrix<typename Matrix::field_type, size_type>;
222 using MatrixInitializer = ISTL::Impl::BCCSMatrixInitializer<M, size_type>;
224 using domain_type = Impl::UMFPackDomainType<M>;
226 using range_type = Impl::UMFPackRangeType<M>;
227
233
242 UMFPack(const Matrix& matrix, int verbose=0) : matrixIsLoaded_(false)
243 {
244 //check whether T is a supported type
246 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
247 Caller::defaults(UMF_Control);
248 setVerbosity(verbose);
249 setMatrix(matrix);
250 }
251
260 UMFPack(const Matrix& matrix, int verbose, bool) : matrixIsLoaded_(false)
261 {
262 //check whether T is a supported type
264 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
265 Caller::defaults(UMF_Control);
266 setVerbosity(verbose);
267 setMatrix(matrix);
268 }
269
288 UMFPack(const Matrix& mat_, const ParameterTree& config) : matrixIsLoaded_(false)
289 {
290 //check whether T is a supported type
292 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
293 Caller::defaults(UMF_Control);
294 setVerbosity(config.get<int>("verbose", 0));
295 if (config.hasKey("ordering")) {
296 const auto &ordering = config["ordering"];
297 if (ordering == "cholmod") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_CHOLMOD);
298 else if (ordering == "default") setOption(UMFPACK_ORDERING, UMFPACK_DEFAULT_ORDERING);
299 else if (ordering == "amd") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_AMD);
300 else if (ordering == "metis") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_METIS);
301 else if (ordering == "best") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_BEST);
302 else if (ordering == "none") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_NONE);
303 #if defined(UMFPACK_VER) && (UMFPACK_VER >= UMFPACK_VER_CODE(6, 0))
304 else if (ordering == "metis_guard") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_METIS_GUARD);
305 #endif
306 else DUNE_THROW(Dune::NotImplemented, "The UMFPACK ordering '" << ordering << "' is not implemented");
307 }
308 setMatrix(mat_);
309 }
310
313 UMFPack() : matrixIsLoaded_(false), verbosity_(0)
314 {
315 //check whether T is a supported type
317 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
318 Caller::defaults(UMF_Control);
319 }
320
331 UMFPack(const Matrix& mat_, const char* file, int verbose=0)
332 {
333 //check whether T is a supported type
335 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
336 Caller::defaults(UMF_Control);
337 setVerbosity(verbose);
338 int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
339 if ((errcode == UMFPACK_ERROR_out_of_memory) || (errcode == UMFPACK_ERROR_file_IO))
340 {
341 matrixIsLoaded_ = false;
342 setMatrix(mat_);
343 saveDecomposition(file);
344 }
345 else
346 {
347 matrixIsLoaded_ = true;
348 std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
349 }
350 }
351
358 UMFPack(const char* file, int verbose=0)
359 {
360 //check whether T is a supported type
362 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
363 Caller::defaults(UMF_Control);
364 int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
365 if (errcode == UMFPACK_ERROR_out_of_memory)
366 DUNE_THROW(Dune::Exception, "ran out of memory while loading UMFPack decomposition");
367 if (errcode == UMFPACK_ERROR_file_IO)
368 DUNE_THROW(Dune::Exception, "IO error while loading UMFPack decomposition");
369 matrixIsLoaded_ = true;
370 std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
371 setVerbosity(verbose);
372 }
373
374 virtual ~UMFPack()
375 {
376 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
377 free();
378 }
379
384 {
385 if (umfpackMatrix_.N() != b.dim())
386 DUNE_THROW(Dune::ISTLError, "Size of right-hand-side vector b does not match the number of matrix rows!");
387 if (umfpackMatrix_.M() != x.dim())
388 DUNE_THROW(Dune::ISTLError, "Size of solution vector x does not match the number of matrix columns!");
389 if (b.size() == 0)
390 return;
391
392 // we have to convert x and b into flat structures
393 // however, this is linear in time
394 std::vector<T> xFlat(x.dim()), bFlat(b.dim());
395
396 flatVectorForEach(x, [&](auto&& entry, auto&& offset)
397 {
398 xFlat[ offset ] = entry;
399 });
400
401 flatVectorForEach(b, [&](auto&& entry, auto&& offset)
402 {
403 bFlat[ offset ] = entry;
404 });
405
406 double UMF_Apply_Info[UMFPACK_INFO];
407 Caller::solve(UMFPACK_A,
408 umfpackMatrix_.getColStart(),
409 umfpackMatrix_.getRowIndex(),
410 umfpackMatrix_.getValues(),
411 reinterpret_cast<double*>(&xFlat[0]),
412 reinterpret_cast<double*>(&bFlat[0]),
413 UMF_Numeric,
414 UMF_Control,
415 UMF_Apply_Info);
416
417 // copy back to blocked vector
418 flatVectorForEach(x, [&](auto&& entry, auto offset)
419 {
420 entry = xFlat[offset];
421 });
422
423 //this is a direct solver
424 res.iterations = 1;
425 res.converged = true;
426 res.elapsed = UMF_Apply_Info[UMFPACK_SOLVE_WALLTIME];
427
428 printOnApply(UMF_Apply_Info);
429 }
430
434 void apply (domain_type& x, range_type& b, [[maybe_unused]] double reduction, InverseOperatorResult& res) override
435 {
436 apply(x,b,res);
437 }
438
446 void apply(T* x, T* b)
447 {
448 double UMF_Apply_Info[UMFPACK_INFO];
449 Caller::solve(UMFPACK_A,
450 umfpackMatrix_.getColStart(),
451 umfpackMatrix_.getRowIndex(),
452 umfpackMatrix_.getValues(),
453 x,
454 b,
455 UMF_Numeric,
456 UMF_Control,
457 UMF_Apply_Info);
458 printOnApply(UMF_Apply_Info);
459 }
460
472 void setOption(unsigned int option, double value)
473 {
474 if (option >= UMFPACK_CONTROL)
475 DUNE_THROW(RangeError, "Requested non-existing UMFPack option");
476
477 UMF_Control[option] = value;
478 }
479
483 void saveDecomposition(const char* file)
484 {
485 int errcode = Caller::save_numeric(UMF_Numeric, const_cast<char*>(file));
486 if (errcode != UMFPACK_OK)
487 DUNE_THROW(Dune::Exception,"IO ERROR while trying to save UMFPack decomposition");
488 }
489
499 template<class BitVector = Impl::NoBitVector>
500 void setMatrix(const Matrix& matrix, const BitVector& bitVector = {})
501 {
502 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
503 free();
504 if (matrix.N() == 0 or matrix.M() == 0)
505 return;
506
507 if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
508 umfpackMatrix_.free();
509
510 constexpr bool useBitVector = not std::is_same_v<BitVector,Impl::NoBitVector>;
511
512 // use a dynamic flat vector for the bitset
513 std::vector<bool> flatBitVector;
514 // and a mapping from the compressed indices
515 std::vector<size_type> subIndices;
516
517 [[maybe_unused]] int numberOfIgnoredDofs = 0;
518 int nonZeros = 0;
519
520 if constexpr ( useBitVector )
521 {
522 auto flatSize = flatVectorForEach(bitVector, [](auto&&, auto&&){});
523 flatBitVector.resize(flatSize);
524
525 flatVectorForEach(bitVector, [&](auto&& entry, auto&& offset)
526 {
527 flatBitVector[ offset ] = entry;
528 if ( entry )
529 {
530 numberOfIgnoredDofs++;
531 }
532 });
533 }
534
535 // compute the flat dimension and the number of nonzeros of the matrix
536 auto [flatRows,flatCols] = flatMatrixForEach( matrix, [&](auto&& /*entry*/, auto&& row, auto&& col){
537 // do not count ignored entries
538 if constexpr ( useBitVector )
539 if ( flatBitVector[row] or flatBitVector[col] )
540 return;
541
542 nonZeros++;
543 });
544
545 if constexpr ( useBitVector )
546 {
547 // use the original flatRows!
548 subIndices.resize(flatRows,std::numeric_limits<std::size_t>::max());
549
550 size_type subIndexCounter = 0;
551 for ( size_type i=0; i<size_type(flatRows); i++ )
552 if ( not flatBitVector[ i ] )
553 subIndices[ i ] = subIndexCounter++;
554
555 // update the original matrix size
556 flatRows -= numberOfIgnoredDofs;
557 flatCols -= numberOfIgnoredDofs;
558 }
559
560
561 umfpackMatrix_.setSize(flatRows,flatCols);
562 umfpackMatrix_.Nnz_ = nonZeros;
563
564 // prepare the arrays
565 umfpackMatrix_.colstart = new size_type[flatCols+1];
566 umfpackMatrix_.rowindex = new size_type[nonZeros];
567 umfpackMatrix_.values = new T[nonZeros];
568
569 for ( size_type i=0; i<size_type(flatCols+1); i++ )
570 {
571 umfpackMatrix_.colstart[i] = 0;
572 }
573
574 // at first, we need to compute the column start indices
575 // therefore, we count all entries in each column and in the end we accumulate everything
576 flatMatrixForEach(matrix, [&](auto&& /*entry*/, auto&& flatRowIndex, auto&& flatColIndex)
577 {
578 // do nothing if entry is excluded
579 if constexpr ( useBitVector )
580 if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
581 return;
582
583 // pick compressed or uncompressed index
584 // compiler will hopefully do some constexpr optimization here
585 auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
586
587 umfpackMatrix_.colstart[colIdx+1]++;
588 });
589
590 // now accumulate
591 for ( size_type i=0; i<(size_type)flatCols; i++ )
592 {
593 umfpackMatrix_.colstart[i+1] += umfpackMatrix_.colstart[i];
594 }
595
596 // we need a compressed position counter in each column
597 std::vector<size_type> colPosition(flatCols,0);
598
599 // now we can set the entries: the procedure below works with both row- or column major index ordering
600 flatMatrixForEach(matrix, [&](auto&& entry, auto&& flatRowIndex, auto&& flatColIndex)
601 {
602 // do nothing if entry is excluded
603 if constexpr ( useBitVector )
604 if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
605 return;
606
607 // pick compressed or uncompressed index
608 // compiler will hopefully do some constexpr optimization here
609 auto rowIdx = useBitVector ? subIndices[flatRowIndex] : flatRowIndex;
610 auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
611
612 // the start index of each column is already fixed
613 auto colStart = umfpackMatrix_.colstart[colIdx];
614 // get the current number of picked elements in this column
615 auto colPos = colPosition[colIdx];
616 // assign the corresponding row index and the value of this element
617 umfpackMatrix_.rowindex[ colStart + colPos ] = rowIdx;
618 umfpackMatrix_.values[ colStart + colPos ] = entry;
619 // increase the number of picked elements in this column
620 colPosition[colIdx]++;
621 });
622
623 decompose();
624 }
625
626 // Keep legacy version using a set of scalar indices
627 // The new version using a bitVector type for marking the active matrix indices is
628 // directly given in `setMatrix` with an additional BitVector argument.
629 // The new version is more flexible and allows, e.g., marking single components of a matrix block.
630 void setSubMatrix(const Matrix& _mat, const std::set<typename Matrix::size_type>& rowIndexSet)
631 {
632 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
633 free();
634
635 if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
636 umfpackMatrix_.free();
637
638 umfpackMatrix_.setSize(rowIndexSet.size()*MatrixDimension<Matrix>::rowdim(_mat) / _mat.N(),
639 rowIndexSet.size()*MatrixDimension<Matrix>::coldim(_mat) / _mat.M());
640 ISTL::Impl::BCCSMatrixInitializer<Matrix, SuiteSparse_long> initializer(umfpackMatrix_);
641
642 copyToBCCSMatrix(initializer, ISTL::Impl::MatrixRowSubset<Matrix,std::set<typename Matrix::size_type> >(_mat,rowIndexSet));
643
644 decompose();
645 }
646
654 void setVerbosity(int v)
655 {
656 verbosity_ = v;
657 // set the verbosity level in UMFPack
658 if (verbosity_ == 0)
659 UMF_Control[UMFPACK_PRL] = 1;
660 if (verbosity_ == 1)
661 UMF_Control[UMFPACK_PRL] = 2;
662 if (verbosity_ == 2)
663 UMF_Control[UMFPACK_PRL] = 4;
664 }
665
671 {
672 return UMF_Numeric;
673 }
674
680 {
681 return umfpackMatrix_;
682 }
683
688 void free()
689 {
690 if (!matrixIsLoaded_)
691 {
692 Caller::free_symbolic(&UMF_Symbolic);
693 umfpackMatrix_.free();
694 }
695 Caller::free_numeric(&UMF_Numeric);
696 matrixIsLoaded_ = false;
697 }
698
699 const char* name() { return "UMFPACK"; }
700
701 private:
702 typedef typename Dune::UMFPackMethodChooser<T> Caller;
703
704 template<class Mat,class X, class TM, class TD, class T1>
707
709 void decompose()
710 {
711 double UMF_Decomposition_Info[UMFPACK_INFO];
712 Caller::symbolic(static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
713 static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
714 umfpackMatrix_.getColStart(),
715 umfpackMatrix_.getRowIndex(),
716 reinterpret_cast<double*>(umfpackMatrix_.getValues()),
717 &UMF_Symbolic,
718 UMF_Control,
719 UMF_Decomposition_Info);
720 Caller::numeric(umfpackMatrix_.getColStart(),
721 umfpackMatrix_.getRowIndex(),
722 reinterpret_cast<double*>(umfpackMatrix_.getValues()),
723 UMF_Symbolic,
724 &UMF_Numeric,
725 UMF_Control,
726 UMF_Decomposition_Info);
727 Caller::report_status(UMF_Control,UMF_Decomposition_Info[UMFPACK_STATUS]);
728 if (verbosity_ == 1)
729 {
730 std::cout << "[UMFPack Decomposition]" << std::endl;
731 std::cout << "Wallclock Time taken: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_WALLTIME] << " (CPU Time: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_TIME] << ")" << std::endl;
732 std::cout << "Flops taken: " << UMF_Decomposition_Info[UMFPACK_FLOPS] << std::endl;
733 std::cout << "Peak Memory Usage: " << UMF_Decomposition_Info[UMFPACK_PEAK_MEMORY]*UMF_Decomposition_Info[UMFPACK_SIZE_OF_UNIT] << " bytes" << std::endl;
734 std::cout << "Condition number estimate: " << 1./UMF_Decomposition_Info[UMFPACK_RCOND] << std::endl;
735 std::cout << "Numbers of non-zeroes in decomposition: L: " << UMF_Decomposition_Info[UMFPACK_LNZ] << " U: " << UMF_Decomposition_Info[UMFPACK_UNZ] << std::endl;
736 }
737 if (verbosity_ == 2)
738 {
739 Caller::report_info(UMF_Control,UMF_Decomposition_Info);
740 }
741 }
742
743 void printOnApply(double* UMF_Info)
744 {
745 Caller::report_status(UMF_Control,UMF_Info[UMFPACK_STATUS]);
746 if (verbosity_ > 0)
747 {
748 std::cout << "[UMFPack Solve]" << std::endl;
749 std::cout << "Wallclock Time: " << UMF_Info[UMFPACK_SOLVE_WALLTIME] << " (CPU Time: " << UMF_Info[UMFPACK_SOLVE_TIME] << ")" << std::endl;
750 std::cout << "Flops Taken: " << UMF_Info[UMFPACK_SOLVE_FLOPS] << std::endl;
751 std::cout << "Iterative Refinement steps taken: " << UMF_Info[UMFPACK_IR_TAKEN] << std::endl;
752 std::cout << "Error Estimate: " << UMF_Info[UMFPACK_OMEGA1] << " resp. " << UMF_Info[UMFPACK_OMEGA2] << std::endl;
753 }
754 }
755
756 UMFPackMatrix umfpackMatrix_;
757 bool matrixIsLoaded_;
758 int verbosity_;
759 void *UMF_Symbolic;
760 void *UMF_Numeric;
761 double UMF_Control[UMFPACK_CONTROL];
762 };
763
764 template<typename M>
766 {
767 enum { value=true};
768 };
769
770 template<typename T, typename A>
772 {
773 enum { value = true };
774 };
775
776 template<typename B, typename P, typename A>
778 {
779 enum { value = true };
780 };
781
782 namespace UMFPackImpl {
783 template<class OpTraits, class=void> struct isValidBlock : std::false_type{};
784 template<class OpTraits> struct isValidBlock<OpTraits,
785 std::enable_if_t<
786 std::is_same_v<Impl::UMFPackDomainType<typename OpTraits::matrix_type>, typename OpTraits::domain_type>
787 && std::is_same_v<Impl::UMFPackRangeType<typename OpTraits::matrix_type>, typename OpTraits::range_type>
788 && std::is_same_v<typename FieldTraits<typename OpTraits::domain_type::field_type>::real_type, double>
789 && std::is_same_v<typename FieldTraits<typename OpTraits::range_type::field_type>::real_type, double>
790 >> : std::true_type {};
791 }
793 [](auto opTraits, const auto& op, const Dune::ParameterTree& config)
794 -> std::shared_ptr<typename decltype(opTraits)::solver_type>
795 {
796 using OpTraits = decltype(opTraits);
797 // works only for sequential operators
798 if constexpr (OpTraits::isParallel){
799 if(opTraits.getCommOrThrow(op).communicator().size() > 1)
800 DUNE_THROW(Dune::InvalidStateException, "UMFPack works only for sequential operators.");
801 }
802 if constexpr (OpTraits::isAssembled){
803 using M = typename OpTraits::matrix_type;
804 // check if UMFPack<M>* is convertible to
805 // InverseOperator*. This checks compatibility of the
806 // domain and range types
808 const auto& A = opTraits.getAssembledOpOrThrow(op);
809 const M& mat = A->getmat();
810 return std::make_shared<Dune::UMFPack<M>>(mat, config);
811 }
812 }
814 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
815 return nullptr;
816 });
817} // end namespace Dune
818
819#endif // HAVE_SUITESPARSE_UMFPACK
820
821#endif //DUNE_ISTL_UMFPACK_HH
Some handy generic functions for ISTL matrices.
#define DUNE_REGISTER_SOLVER(name,...)
Definition solverregistry.hh:17
A dynamic dense block matrix class.
Templates characterizing the type of a solver.
Implementations of the inverse operator interface.
void setSubMatrix(const Matrix &_mat, const std::set< typename Matrix::size_type > &rowIndexSet)
Definition umfpack.hh:630
void free()
free allocated space.
Definition umfpack.hh:688
SuiteSparse_long size_type
Definition umfpack.hh:214
static void symbolic(size_type m, size_type n, const size_type *cs, const size_type *ri, const double *val, A... args)
Definition umfpack.hh:170
static void solve(size_type m, const size_type *cs, const size_type *ri, std::complex< double > *val, double *x, const double *b, A... args)
Definition umfpack.hh:164
M matrix_type
Definition umfpack.hh:218
static void numeric(const size_type *cs, const size_type *ri, const double *val, A... args)
Definition umfpack.hh:144
static void report_info(A... args)
Definition umfpack.hh:149
UMFPack(const Matrix &mat_, const ParameterTree &config)
Construct a solver object from a matrix.
Definition umfpack.hh:288
static int load_numeric(A... args)
Definition umfpack.hh:139
static int load_numeric(A... args)
Definition umfpack.hh:81
static void report_status(A... args)
Definition umfpack.hh:96
UMFPack(const Matrix &mat_, const char *file, int verbose=0)
Try loading a decomposition from file and do a decomposition if unsuccessful.
Definition umfpack.hh:331
Impl::UMFPackRangeType< M > range_type
The type of the range of the solver.
Definition umfpack.hh:226
UMFPack()
default constructor
Definition umfpack.hh:313
static void symbolic(A... args)
Definition umfpack.hh:111
static void report_info(A... args)
Definition umfpack.hh:91
static void free_symbolic(A... args)
Definition umfpack.hh:76
static int save_numeric(A... args)
Definition umfpack.hh:159
static void free_numeric(A... args)
Definition umfpack.hh:129
static int save_numeric(A... args)
Definition umfpack.hh:101
static void report_status(A... args)
Definition umfpack.hh:154
Impl::UMFPackDomainType< M > domain_type
The type of the domain of the solver.
Definition umfpack.hh:224
void apply(T *x, T *b)
additional apply method with c-arrays in analogy to superlu
Definition umfpack.hh:446
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition umfpack.hh:229
static void defaults(A... args)
Definition umfpack.hh:124
static void free_numeric(A... args)
Definition umfpack.hh:71
void setVerbosity(int v)
sets the verbosity level for the UMFPack solver
Definition umfpack.hh:654
UMFPack(const char *file, int verbose=0)
try loading a decomposition from file
Definition umfpack.hh:358
static void numeric(A... args)
Definition umfpack.hh:86
void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res) override
apply inverse operator, with given convergence criteria.
Definition umfpack.hh:434
static constexpr bool valid
Definition umfpack.hh:57
virtual ~UMFPack()
Definition umfpack.hh:374
const char * name()
Definition umfpack.hh:699
void setMatrix(const Matrix &matrix, const BitVector &bitVector={})
Initialize data from given matrix.
Definition umfpack.hh:500
void saveDecomposition(const char *file)
saves a decomposition to a file
Definition umfpack.hh:483
UMFPackMatrix & getInternalMatrix()
Return the column compress matrix from UMFPack.
Definition umfpack.hh:679
SuiteSparse_long size_type
Definition umfpack.hh:121
UMFPack(const Matrix &matrix, int verbose=0)
Construct a solver object from a matrix.
Definition umfpack.hh:242
ISTL::Impl::BCCSMatrixInitializer< M, size_type > MatrixInitializer
Type of an associated initializer class.
Definition umfpack.hh:222
ISTL::Impl::BCCSMatrix< typename Matrix::field_type, size_type > UMFPackMatrix
The corresponding (scalar) UMFPack matrix type.
Definition umfpack.hh:220
void setOption(unsigned int option, double value)
Set UMFPack-specific options.
Definition umfpack.hh:472
static void free_symbolic(A... args)
Definition umfpack.hh:134
M Matrix
The matrix type.
Definition umfpack.hh:217
static void defaults(A... args)
Definition umfpack.hh:66
void apply(domain_type &x, range_type &b, InverseOperatorResult &res) override
Apply inverse operator,.
Definition umfpack.hh:383
static void solve(A... args)
Definition umfpack.hh:106
UMFPack(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition umfpack.hh:260
void * getFactorization()
Return the matrix factorization.
Definition umfpack.hh:670
Col col
Definition matrixmatrix.hh:351
Matrix & mat
Definition matrixmatrix.hh:347
STL namespace.
static constexpr size_type M()
#define DUNE_THROW(E,...)
std::pair< std::size_t, std::size_t > flatMatrixForEach(Matrix &&matrix, F &&f, std::size_t rowOffset=0, std::size_t colOffset=0)
Traverse a blocked matrix and call a functor at each scalar entry.
Definition foreach.hh:174
std::size_t flatVectorForEach(Vector &&vector, F &&f, std::size_t offset=0)
Traverse a blocked vector and call a functor at each scalar entry.
Definition foreach.hh:102
Definition matrixutils.hh:221
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:468
Block compressed row storage matrix.
Definition experimental/bcrsmatrix.hh:82
std::string get(const std::string &key, const std::string &defaultValue) const
bool hasKey(const std::string &key) const
derive error class from the base class in common
Definition istlexception.hh:19
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:755
Definition overlappingschwarz.hh:694
Statistics about the application of an inverse operator.
Definition solver.hh:50
double elapsed
Elapsed time in seconds.
Definition solver.hh:84
int iterations
Number of iterations.
Definition solver.hh:69
bool converged
True if convergence criterion has been met.
Definition solver.hh:75
Abstract base class for all solvers.
Definition solver.hh:101
Category
Definition solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25
Definition solverregistry.hh:37
Definition solvertype.hh:16
@ value
Whether this is a direct solver.
Definition solvertype.hh:24
Definition solvertype.hh:30
@ value
whether the solver internally uses column compressed storage
Definition solvertype.hh:36
Definition umfpack.hh:56
The UMFPack direct sparse solver.
Definition umfpack.hh:210
Definition umfpack.hh:783
T endl(T... args)
T resize(T... args)
T size(T... args)