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 typename X = typename Impl::UMFPackVectorChooser<M>::domain_type,
210 typename Y = typename Impl::UMFPackVectorChooser<M>::range_type>
212 : public InverseOperator<X, Y>
213 {
214 using T = typename M::field_type;
215
216 public:
217 using size_type = SuiteSparse_long;
218
220 using Matrix = M;
221 using matrix_type = M;
223 using UMFPackMatrix = ISTL::Impl::BCCSMatrix<typename Matrix::field_type, size_type>;
225 using MatrixInitializer = ISTL::Impl::BCCSMatrixInitializer<M, size_type>;
227 using domain_type = X;
229 using range_type = Y;
230
236
245 UMFPack(const Matrix& matrix, int verbose=0) : matrixIsLoaded_(false)
246 {
247 //check whether T is a supported type
249 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
250 Caller::defaults(UMF_Control);
251 setVerbosity(verbose);
252 setMatrix(matrix);
253 }
254
263 UMFPack(const Matrix& matrix, int verbose, bool) : matrixIsLoaded_(false)
264 {
265 //check whether T is a supported type
267 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
268 Caller::defaults(UMF_Control);
269 setVerbosity(verbose);
270 setMatrix(matrix);
271 }
272
291 UMFPack(const Matrix& mat_, const ParameterTree& config) : matrixIsLoaded_(false)
292 {
293 //check whether T is a supported type
295 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
296 Caller::defaults(UMF_Control);
297 setVerbosity(config.get<int>("verbose", 0));
298 if (config.hasKey("ordering")) {
299 const auto &ordering = config["ordering"];
300 if (ordering == "cholmod") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_CHOLMOD);
301 else if (ordering == "default") setOption(UMFPACK_ORDERING, UMFPACK_DEFAULT_ORDERING);
302 else if (ordering == "amd") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_AMD);
303 else if (ordering == "metis") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_METIS);
304 else if (ordering == "best") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_BEST);
305 else if (ordering == "none") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_NONE);
306 #if defined(UMFPACK_VER) && (UMFPACK_VER >= UMFPACK_VER_CODE(6, 0))
307 else if (ordering == "metis_guard") setOption(UMFPACK_ORDERING, UMFPACK_ORDERING_METIS_GUARD);
308 #endif
309 else DUNE_THROW(Dune::NotImplemented, "The UMFPACK ordering '" << ordering << "' is not implemented");
310 }
311 setMatrix(mat_);
312 }
313
316 UMFPack() : matrixIsLoaded_(false), verbosity_(0)
317 {
318 //check whether T is a supported type
320 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
321 Caller::defaults(UMF_Control);
322 }
323
334 UMFPack(const Matrix& mat_, const char* file, int verbose=0)
335 {
336 //check whether T is a supported type
338 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
339 Caller::defaults(UMF_Control);
340 setVerbosity(verbose);
341 int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
342 if ((errcode == UMFPACK_ERROR_out_of_memory) || (errcode == UMFPACK_ERROR_file_IO))
343 {
344 matrixIsLoaded_ = false;
345 setMatrix(mat_);
346 saveDecomposition(file);
347 }
348 else
349 {
350 matrixIsLoaded_ = true;
351 std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
352 }
353 }
354
361 UMFPack(const char* file, int verbose=0)
362 {
363 //check whether T is a supported type
365 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
366 Caller::defaults(UMF_Control);
367 int errcode = Caller::load_numeric(&UMF_Numeric, const_cast<char*>(file));
368 if (errcode == UMFPACK_ERROR_out_of_memory)
369 DUNE_THROW(Dune::Exception, "ran out of memory while loading UMFPack decomposition");
370 if (errcode == UMFPACK_ERROR_file_IO)
371 DUNE_THROW(Dune::Exception, "IO error while loading UMFPack decomposition");
372 matrixIsLoaded_ = true;
373 std::cout << "UMFPack decomposition successfully loaded from " << file << std::endl;
374 setVerbosity(verbose);
375 }
376
377 virtual ~UMFPack()
378 {
379 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
380 free();
381 }
382
387 {
388 if (umfpackMatrix_.N() != b.dim())
389 DUNE_THROW(Dune::ISTLError, "Size of right-hand-side vector b does not match the number of matrix rows!");
390 if (umfpackMatrix_.M() != x.dim())
391 DUNE_THROW(Dune::ISTLError, "Size of solution vector x does not match the number of matrix columns!");
392 if (b.size() == 0)
393 return;
394
395 // we have to convert x and b into flat structures
396 // however, this is linear in time
397 std::vector<T> xFlat(x.dim()), bFlat(b.dim());
398 if (xFlat.size() != x.dim())
399 DUNE_THROW(ISTLError, "Vector x is not contiguous!");
400 if (bFlat.size() != b.dim())
401 DUNE_THROW(ISTLError, "Vector b is not contiguous!");
402
403 flatVectorForEach(x, [&](auto&& entry, auto&& offset)
404 {
405 xFlat[ offset ] = entry;
406 });
407
408 flatVectorForEach(b, [&](auto&& entry, auto&& offset)
409 {
410 bFlat[ offset ] = entry;
411 });
412
413 double UMF_Apply_Info[UMFPACK_INFO];
414 Caller::solve(UMFPACK_A,
415 umfpackMatrix_.getColStart(),
416 umfpackMatrix_.getRowIndex(),
417 umfpackMatrix_.getValues(),
418 reinterpret_cast<double*>(xFlat.data()),
419 reinterpret_cast<double const*>(bFlat.data()),
420 UMF_Numeric,
421 UMF_Control,
422 UMF_Apply_Info);
423
424 // copy back to blocked vector
425 flatVectorForEach(x, [&](auto&& entry, auto offset)
426 {
427 entry = xFlat[offset];
428 });
429
430 //this is a direct solver
431 res.iterations = 1;
432 res.converged = true;
433 res.elapsed = UMF_Apply_Info[UMFPACK_SOLVE_WALLTIME];
434
435 printOnApply(UMF_Apply_Info);
436 }
437
441 void apply (domain_type& x, range_type& b, [[maybe_unused]] double reduction, InverseOperatorResult& res) override
442 {
443 apply(x,b,res);
444 }
445
453 void apply(T* x, T* b)
454 {
455 double UMF_Apply_Info[UMFPACK_INFO];
456 Caller::solve(UMFPACK_A,
457 umfpackMatrix_.getColStart(),
458 umfpackMatrix_.getRowIndex(),
459 umfpackMatrix_.getValues(),
460 x,
461 b,
462 UMF_Numeric,
463 UMF_Control,
464 UMF_Apply_Info);
465 printOnApply(UMF_Apply_Info);
466 }
467
479 void setOption(unsigned int option, double value)
480 {
481 if (option >= UMFPACK_CONTROL)
482 DUNE_THROW(RangeError, "Requested non-existing UMFPack option");
483
484 UMF_Control[option] = value;
485 }
486
490 void saveDecomposition(const char* file)
491 {
492 int errcode = Caller::save_numeric(UMF_Numeric, const_cast<char*>(file));
493 if (errcode != UMFPACK_OK)
494 DUNE_THROW(Dune::Exception,"IO ERROR while trying to save UMFPack decomposition");
495 }
496
506 template<class BitVector = Impl::NoBitVector>
507 void setMatrix(const Matrix& matrix, const BitVector& bitVector = {})
508 {
509 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
510 free();
511 if (matrix.N() == 0 or matrix.M() == 0)
512 return;
513
514 if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
515 umfpackMatrix_.free();
516
517 constexpr bool useBitVector = not std::is_same_v<BitVector,Impl::NoBitVector>;
518
519 // use a dynamic flat vector for the bitset
520 std::vector<bool> flatBitVector;
521 // and a mapping from the compressed indices
522 std::vector<size_type> subIndices;
523
524 [[maybe_unused]] int numberOfIgnoredDofs = 0;
525 int nonZeros = 0;
526
527 if constexpr ( useBitVector )
528 {
529 auto flatSize = flatVectorForEach(bitVector, [](auto&&, auto&&){});
530 flatBitVector.resize(flatSize);
531
532 flatVectorForEach(bitVector, [&](auto&& entry, auto&& offset)
533 {
534 flatBitVector[ offset ] = entry;
535 if ( entry )
536 {
537 numberOfIgnoredDofs++;
538 }
539 });
540 }
541
542 // compute the flat dimension and the number of nonzeros of the matrix
543 auto [flatRows,flatCols] = flatMatrixForEach( matrix, [&](auto&& /*entry*/, auto&& row, auto&& col){
544 // do not count ignored entries
545 if constexpr ( useBitVector )
546 if ( flatBitVector[row] or flatBitVector[col] )
547 return;
548
549 nonZeros++;
550 });
551
552 if constexpr ( useBitVector )
553 {
554 // use the original flatRows!
555 subIndices.resize(flatRows,std::numeric_limits<std::size_t>::max());
556
557 size_type subIndexCounter = 0;
558 for ( size_type i=0; i<size_type(flatRows); i++ )
559 if ( not flatBitVector[ i ] )
560 subIndices[ i ] = subIndexCounter++;
561
562 // update the original matrix size
563 flatRows -= numberOfIgnoredDofs;
564 flatCols -= numberOfIgnoredDofs;
565 }
566
567
568 umfpackMatrix_.setSize(flatRows,flatCols);
569 umfpackMatrix_.Nnz_ = nonZeros;
570
571 // prepare the arrays
572 umfpackMatrix_.colstart = new size_type[flatCols+1];
573 umfpackMatrix_.rowindex = new size_type[nonZeros];
574 umfpackMatrix_.values = new T[nonZeros];
575
576 for ( size_type i=0; i<size_type(flatCols+1); i++ )
577 {
578 umfpackMatrix_.colstart[i] = 0;
579 }
580
581 // at first, we need to compute the column start indices
582 // therefore, we count all entries in each column and in the end we accumulate everything
583 flatMatrixForEach(matrix, [&](auto&& /*entry*/, auto&& flatRowIndex, auto&& flatColIndex)
584 {
585 // do nothing if entry is excluded
586 if constexpr ( useBitVector )
587 if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
588 return;
589
590 // pick compressed or uncompressed index
591 // compiler will hopefully do some constexpr optimization here
592 auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
593
594 umfpackMatrix_.colstart[colIdx+1]++;
595 });
596
597 // now accumulate
598 for ( size_type i=0; i<(size_type)flatCols; i++ )
599 {
600 umfpackMatrix_.colstart[i+1] += umfpackMatrix_.colstart[i];
601 }
602
603 // we need a compressed position counter in each column
604 std::vector<size_type> colPosition(flatCols,0);
605
606 // now we can set the entries: the procedure below works with both row- or column major index ordering
607 flatMatrixForEach(matrix, [&](auto&& entry, auto&& flatRowIndex, auto&& flatColIndex)
608 {
609 // do nothing if entry is excluded
610 if constexpr ( useBitVector )
611 if ( flatBitVector[flatRowIndex] or flatBitVector[flatColIndex] )
612 return;
613
614 // pick compressed or uncompressed index
615 // compiler will hopefully do some constexpr optimization here
616 auto rowIdx = useBitVector ? subIndices[flatRowIndex] : flatRowIndex;
617 auto colIdx = useBitVector ? subIndices[flatColIndex] : flatColIndex;
618
619 // the start index of each column is already fixed
620 auto colStart = umfpackMatrix_.colstart[colIdx];
621 // get the current number of picked elements in this column
622 auto colPos = colPosition[colIdx];
623 // assign the corresponding row index and the value of this element
624 umfpackMatrix_.rowindex[ colStart + colPos ] = rowIdx;
625 umfpackMatrix_.values[ colStart + colPos ] = entry;
626 // increase the number of picked elements in this column
627 colPosition[colIdx]++;
628 });
629
630 decompose();
631 }
632
633 // Keep legacy version using a set of scalar indices
634 // The new version using a bitVector type for marking the active matrix indices is
635 // directly given in `setMatrix` with an additional BitVector argument.
636 // The new version is more flexible and allows, e.g., marking single components of a matrix block.
637 void setSubMatrix(const Matrix& _mat, const std::set<typename Matrix::size_type>& rowIndexSet)
638 {
639 if ((umfpackMatrix_.N() + umfpackMatrix_.M() > 0) || matrixIsLoaded_)
640 free();
641
642 if (umfpackMatrix_.N() + umfpackMatrix_.M() + umfpackMatrix_.nonzeroes() != 0)
643 umfpackMatrix_.free();
644
645 umfpackMatrix_.setSize(rowIndexSet.size()*MatrixDimension<Matrix>::rowdim(_mat) / _mat.N(),
646 rowIndexSet.size()*MatrixDimension<Matrix>::coldim(_mat) / _mat.M());
647 ISTL::Impl::BCCSMatrixInitializer<Matrix, SuiteSparse_long> initializer(umfpackMatrix_);
648
649 copyToBCCSMatrix(initializer, ISTL::Impl::MatrixRowSubset<Matrix,std::set<typename Matrix::size_type> >(_mat,rowIndexSet));
650
651 decompose();
652 }
653
661 void setVerbosity(int v)
662 {
663 verbosity_ = v;
664 // set the verbosity level in UMFPack
665 if (verbosity_ == 0)
666 UMF_Control[UMFPACK_PRL] = 1;
667 if (verbosity_ == 1)
668 UMF_Control[UMFPACK_PRL] = 2;
669 if (verbosity_ == 2)
670 UMF_Control[UMFPACK_PRL] = 4;
671 }
672
678 {
679 return UMF_Numeric;
680 }
681
687 {
688 return umfpackMatrix_;
689 }
690
695 void free()
696 {
697 if (!matrixIsLoaded_)
698 {
699 Caller::free_symbolic(&UMF_Symbolic);
700 umfpackMatrix_.free();
701 }
702 Caller::free_numeric(&UMF_Numeric);
703 matrixIsLoaded_ = false;
704 }
705
706 const char* name() { return "UMFPACK"; }
707
708 private:
709 typedef typename Dune::UMFPackMethodChooser<T> Caller;
710
711 template<class Mat,class Domain, class TM, class TD, class T1>
713 friend struct SeqOverlappingSchwarzAssemblerHelper<UMFPack<Matrix,X,Y>,true>;
714
716 void decompose()
717 {
718 double UMF_Decomposition_Info[UMFPACK_INFO];
719 Caller::symbolic(static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
720 static_cast<SuiteSparse_long>(umfpackMatrix_.N()),
721 umfpackMatrix_.getColStart(),
722 umfpackMatrix_.getRowIndex(),
723 reinterpret_cast<double*>(umfpackMatrix_.getValues()),
724 &UMF_Symbolic,
725 UMF_Control,
726 UMF_Decomposition_Info);
727 Caller::numeric(umfpackMatrix_.getColStart(),
728 umfpackMatrix_.getRowIndex(),
729 reinterpret_cast<double*>(umfpackMatrix_.getValues()),
730 UMF_Symbolic,
731 &UMF_Numeric,
732 UMF_Control,
733 UMF_Decomposition_Info);
734 Caller::report_status(UMF_Control,UMF_Decomposition_Info[UMFPACK_STATUS]);
735 if (verbosity_ == 1)
736 {
737 std::cout << "[UMFPack Decomposition]" << std::endl;
738 std::cout << "Wallclock Time taken: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_WALLTIME] << " (CPU Time: " << UMF_Decomposition_Info[UMFPACK_NUMERIC_TIME] << ")" << std::endl;
739 std::cout << "Flops taken: " << UMF_Decomposition_Info[UMFPACK_FLOPS] << std::endl;
740 std::cout << "Peak Memory Usage: " << UMF_Decomposition_Info[UMFPACK_PEAK_MEMORY]*UMF_Decomposition_Info[UMFPACK_SIZE_OF_UNIT] << " bytes" << std::endl;
741 std::cout << "Condition number estimate: " << 1./UMF_Decomposition_Info[UMFPACK_RCOND] << std::endl;
742 std::cout << "Numbers of non-zeroes in decomposition: L: " << UMF_Decomposition_Info[UMFPACK_LNZ] << " U: " << UMF_Decomposition_Info[UMFPACK_UNZ] << std::endl;
743 }
744 if (verbosity_ == 2)
745 {
746 Caller::report_info(UMF_Control,UMF_Decomposition_Info);
747 }
748 }
749
750 void printOnApply(double* UMF_Info)
751 {
752 Caller::report_status(UMF_Control,UMF_Info[UMFPACK_STATUS]);
753 if (verbosity_ > 0)
754 {
755 std::cout << "[UMFPack Solve]" << std::endl;
756 std::cout << "Wallclock Time: " << UMF_Info[UMFPACK_SOLVE_WALLTIME] << " (CPU Time: " << UMF_Info[UMFPACK_SOLVE_TIME] << ")" << std::endl;
757 std::cout << "Flops Taken: " << UMF_Info[UMFPACK_SOLVE_FLOPS] << std::endl;
758 std::cout << "Iterative Refinement steps taken: " << UMF_Info[UMFPACK_IR_TAKEN] << std::endl;
759 std::cout << "Error Estimate: " << UMF_Info[UMFPACK_OMEGA1] << " resp. " << UMF_Info[UMFPACK_OMEGA2] << std::endl;
760 }
761 }
762
763 UMFPackMatrix umfpackMatrix_;
764 bool matrixIsLoaded_;
765 int verbosity_;
766 void *UMF_Symbolic;
767 void *UMF_Numeric;
768 double UMF_Control[UMFPACK_CONTROL];
769 };
770
771 template<typename M, typename X, typename Y>
772 struct IsDirectSolver<UMFPack<M, X, Y>>
773 {
774 enum { value=true};
775 };
776
777 template<typename T, typename A, typename X, typename Y>
779 {
780 enum { value = true };
781 };
782
783 template<typename B, typename P, typename A, typename X, typename Y>
785 {
786 enum { value = true };
787 };
788
789 namespace UMFPackImpl {
790 template<class OpTraits, class=void> struct isValidBlock : std::false_type{};
791 template<class OpTraits> struct isValidBlock<OpTraits,
792 std::enable_if_t<
793 std::is_same_v<typename FieldTraits<typename OpTraits::domain_type::field_type>::real_type, double>
794 && std::is_same_v<typename FieldTraits<typename OpTraits::range_type::field_type>::real_type, double>
795 >> : std::true_type {};
796 }
798 [](auto opTraits, const auto& op, const Dune::ParameterTree& config)
799 -> std::shared_ptr<typename decltype(opTraits)::solver_type>
800 {
801 using OpTraits = decltype(opTraits);
802 // works only for sequential operators
803 if constexpr (OpTraits::isParallel){
804 if(opTraits.getCommOrThrow(op).communicator().size() > 1)
805 DUNE_THROW(Dune::InvalidStateException, "UMFPack works only for sequential operators.");
806 }
807 if constexpr (OpTraits::isAssembled){
808 using M = typename OpTraits::matrix_type;
809 using X = typename OpTraits::domain_type;
810 using Y = typename OpTraits::range_type;
811 // check if UMFPack<M,X,Y>* is convertible to
812 // InverseOperator*. This checks compatibility of the
813 // domain and range types
815 const auto& A = opTraits.getAssembledOpOrThrow(op);
816 const M& mat = A->getmat();
817 return std::make_shared<Dune::UMFPack<M,X,Y>>(mat, config);
818 }
819 }
821 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
822 return nullptr;
823 });
824} // end namespace Dune
825
826#endif // HAVE_SUITESPARSE_UMFPACK
827
828#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.
UMFPack(const Matrix &matrix, int verbose, bool)
Constructor for compatibility with SuperLU standard constructor.
Definition umfpack.hh:263
void setOption(unsigned int option, double value)
Set UMFPack-specific options.
Definition umfpack.hh:479
virtual ~UMFPack()
Definition umfpack.hh:377
void saveDecomposition(const char *file)
saves a decomposition to a file
Definition umfpack.hh:490
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition umfpack.hh:232
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
void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res) override
apply inverse operator, with given convergence criteria.
Definition umfpack.hh:441
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
ISTL::Impl::BCCSMatrixInitializer< M, size_type > MatrixInitializer
Type of an associated initializer class.
Definition umfpack.hh:225
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:291
static int load_numeric(A... args)
Definition umfpack.hh:139
static int load_numeric(A... args)
Definition umfpack.hh:81
Y range_type
The type of the range of the solver.
Definition umfpack.hh:229
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:334
X domain_type
The type of the domain of the solver.
Definition umfpack.hh:227
SuiteSparse_long size_type
Definition umfpack.hh:217
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
static void defaults(A... args)
Definition umfpack.hh:124
static void free_numeric(A... args)
Definition umfpack.hh:71
static void numeric(A... args)
Definition umfpack.hh:86
M matrix_type
Definition umfpack.hh:221
static constexpr bool valid
Definition umfpack.hh:57
void * getFactorization()
Return the matrix factorization.
Definition umfpack.hh:677
const char * name()
Definition umfpack.hh:706
M Matrix
The matrix type.
Definition umfpack.hh:220
UMFPack()
default constructor
Definition umfpack.hh:316
SuiteSparse_long size_type
Definition umfpack.hh:121
void free()
free allocated space.
Definition umfpack.hh:695
void apply(T *x, T *b)
additional apply method with c-arrays in analogy to superlu
Definition umfpack.hh:453
void setMatrix(const Matrix &matrix, const BitVector &bitVector={})
Initialize data from given matrix.
Definition umfpack.hh:507
UMFPack(const Matrix &matrix, int verbose=0)
Construct a solver object from a matrix.
Definition umfpack.hh:245
static void free_symbolic(A... args)
Definition umfpack.hh:134
void setSubMatrix(const Matrix &_mat, const std::set< typename Matrix::size_type > &rowIndexSet)
Definition umfpack.hh:637
ISTL::Impl::BCCSMatrix< typename Matrix::field_type, size_type > UMFPackMatrix
The corresponding (scalar) UMFPack matrix type.
Definition umfpack.hh:223
void setVerbosity(int v)
sets the verbosity level for the UMFPack solver
Definition umfpack.hh:661
static void defaults(A... args)
Definition umfpack.hh:66
UMFPack(const char *file, int verbose=0)
try loading a decomposition from file
Definition umfpack.hh:361
UMFPackMatrix & getInternalMatrix()
Return the column compress matrix from UMFPack.
Definition umfpack.hh:686
static void solve(A... args)
Definition umfpack.hh:106
void apply(domain_type &x, range_type &b, InverseOperatorResult &res) override
Apply inverse operator,.
Definition umfpack.hh:386
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:213
Definition umfpack.hh:790
T data(T... args)
T endl(T... args)
T resize(T... args)
T size(T... args)