dune-istl 2.12-git
Loading...
Searching...
No Matches
superlu.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_SUPERLU_HH
6#define DUNE_ISTL_SUPERLU_HH
7
8#if HAVE_SUPERLU
9
10#include "superlufunctions.hh"
11#include "solvers.hh"
12#include "supermatrix.hh"
13#include <algorithm>
14#include <functional>
15#include "bcrsmatrix.hh"
16#include "bvector.hh"
17#include "istlexception.hh"
23
24namespace Dune
25{
26
37 template<class M, class T, class TM, class TD, class TA>
38 class SeqOverlappingSchwarz;
39
40 template<class T, bool tag>
41 struct SeqOverlappingSchwarzAssemblerHelper;
42
43 template<class T>
45 {};
46
47 template<class T>
50
51 template<class T>
53 {};
54
55 template<class T>
57 {};
58
59#if __has_include("slu_sdefs.h")
60 template<>
61 struct SuperLUDenseMatChooser<float>
62 {
63 static void create(SuperMatrix *mat, int n, int m, float *dat, int n1,
64 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
65 {
66 sCreate_Dense_Matrix(mat, n, m, dat, n1, stype, dtype, mtype);
67
68 }
69
70 static void destroy(SuperMatrix*)
71 {}
72
73 };
74 template<>
75 struct SuperLUSolveChooser<float>
76 {
77 static void solve(superlu_options_t *options, SuperMatrix *mat, int *perm_c, int *perm_r, int *etree,
78 char *equed, float *R, float *C, SuperMatrix *L, SuperMatrix *U,
79 void *work, int lwork, SuperMatrix *B, SuperMatrix *X,
80 float *rpg, float *rcond, float *ferr, float *berr,
81 mem_usage_t *memusage, SuperLUStat_t *stat, int *info)
82 {
83 GlobalLU_t gLU;
84 sgssvx(options, mat, perm_c, perm_r, etree, equed, R, C,
85 L, U, work, lwork, B, X, rpg, rcond, ferr, berr,
86 &gLU, memusage, stat, info);
87 }
88 };
89
90 template<>
91 struct QuerySpaceChooser<float>
92 {
93 static void querySpace(SuperMatrix* L, SuperMatrix* U, mem_usage_t* memusage)
94 {
95 sQuerySpace(L,U,memusage);
96 }
97 };
98
99#endif
100
101#if __has_include("slu_ddefs.h")
102
103 template<>
104 struct SuperLUDenseMatChooser<double>
105 {
106 static void create(SuperMatrix *mat, int n, int m, double *dat, int n1,
107 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
108 {
109 dCreate_Dense_Matrix(mat, n, m, dat, n1, stype, dtype, mtype);
110
111 }
112
113 static void destroy(SuperMatrix * /* mat */)
114 {}
115 };
116 template<>
117 struct SuperLUSolveChooser<double>
118 {
119 static void solve(superlu_options_t *options, SuperMatrix *mat, int *perm_c, int *perm_r, int *etree,
120 char *equed, double *R, double *C, SuperMatrix *L, SuperMatrix *U,
121 void *work, int lwork, SuperMatrix *B, SuperMatrix *X,
122 double *rpg, double *rcond, double *ferr, double *berr,
123 mem_usage_t *memusage, SuperLUStat_t *stat, int *info)
124 {
125 GlobalLU_t gLU;
126 dgssvx(options, mat, perm_c, perm_r, etree, equed, R, C,
127 L, U, work, lwork, B, X, rpg, rcond, ferr, berr,
128 &gLU, memusage, stat, info);
129 }
130 };
131
132 template<>
133 struct QuerySpaceChooser<double>
134 {
135 static void querySpace(SuperMatrix* L, SuperMatrix* U, mem_usage_t* memusage)
136 {
137 dQuerySpace(L,U,memusage);
138 }
139 };
140#endif
141
142#if __has_include("slu_zdefs.h")
143 template<>
144 struct SuperLUDenseMatChooser<std::complex<double> >
145 {
146 static void create(SuperMatrix *mat, int n, int m, std::complex<double> *dat, int n1,
147 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
148 {
149 zCreate_Dense_Matrix(mat, n, m, reinterpret_cast<doublecomplex*>(dat), n1, stype, dtype, mtype);
150
151 }
152
153 static void destroy(SuperMatrix*)
154 {}
155 };
156
157 template<>
158 struct SuperLUSolveChooser<std::complex<double> >
159 {
160 static void solve(superlu_options_t *options, SuperMatrix *mat, int *perm_c, int *perm_r, int *etree,
161 char *equed, double *R, double *C, SuperMatrix *L, SuperMatrix *U,
162 void *work, int lwork, SuperMatrix *B, SuperMatrix *X,
163 double *rpg, double *rcond, double *ferr, double *berr,
164 mem_usage_t *memusage, SuperLUStat_t *stat, int *info)
165 {
166 GlobalLU_t gLU;
167 zgssvx(options, mat, perm_c, perm_r, etree, equed, R, C,
168 L, U, work, lwork, B, X, rpg, rcond, ferr, berr,
169 &gLU, memusage, stat, info);
170 }
171 };
172
173 template<>
174 struct QuerySpaceChooser<std::complex<double> >
175 {
176 static void querySpace(SuperMatrix* L, SuperMatrix* U, mem_usage_t* memusage)
177 {
178 zQuerySpace(L,U,memusage);
179 }
180 };
181#endif
182
183#if __has_include("slu_cdefs.h")
184 template<>
185 struct SuperLUDenseMatChooser<std::complex<float> >
186 {
187 static void create(SuperMatrix *mat, int n, int m, std::complex<float> *dat, int n1,
188 Stype_t stype, Dtype_t dtype, Mtype_t mtype)
189 {
190 cCreate_Dense_Matrix(mat, n, m, reinterpret_cast< singlecomplex*>(dat), n1, stype, dtype, mtype);
191
192 }
193
194 static void destroy(SuperMatrix* /* mat */)
195 {}
196 };
197
198 template<>
199 struct SuperLUSolveChooser<std::complex<float> >
200 {
201 static void solve(superlu_options_t *options, SuperMatrix *mat, int *perm_c, int *perm_r, int *etree,
202 char *equed, float *R, float *C, SuperMatrix *L, SuperMatrix *U,
203 void *work, int lwork, SuperMatrix *B, SuperMatrix *X,
204 float *rpg, float *rcond, float *ferr, float *berr,
205 mem_usage_t *memusage, SuperLUStat_t *stat, int *info)
206 {
207 GlobalLU_t gLU;
208 cgssvx(options, mat, perm_c, perm_r, etree, equed, R, C,
209 L, U, work, lwork, B, X, rpg, rcond, ferr, berr,
210 &gLU, memusage, stat, info);
211 }
212 };
213
214 template<>
215 struct QuerySpaceChooser<std::complex<float> >
216 {
217 static void querySpace(SuperMatrix* L, SuperMatrix* U, mem_usage_t* memusage)
218 {
219 cQuerySpace(L,U,memusage);
220 }
221 };
222#endif
223
224 namespace Impl
225 {
226 template<class M>
227 struct SuperLUVectorChooser
228 {};
229
230 template<typename T, typename A, int n, int m>
231 struct SuperLUVectorChooser<BCRSMatrix<FieldMatrix<T,n,m>,A > >
232 {
234 using domain_type = BlockVector<
235 FieldVector<T,m>,
236 typename std::allocator_traits<A>::template rebind_alloc<FieldVector<T,m> > >;
238 using range_type = BlockVector<
239 FieldVector<T,n>,
240 typename std::allocator_traits<A>::template rebind_alloc<FieldVector<T,n> > >;
241 };
242
243 template<typename T, typename A>
244 struct SuperLUVectorChooser<BCRSMatrix<T,A> >
245 {
247 using domain_type = BlockVector<T, A>;
249 using range_type = BlockVector<T, A>;
250 };
251 }
252
266 template<typename M,
267 typename Dom = typename Impl::SuperLUVectorChooser<M>::domain_type,
268 typename Ran = typename Impl::SuperLUVectorChooser<M>::range_type>
270 : public InverseOperator<Dom, Ran>
271 {
272 using T = typename M::field_type;
273 public:
275 using Matrix = M;
276 using matrix_type = M;
282 using domain_type = Dom;
284 using range_type = Ran;
285
291
306 explicit SuperLU(const Matrix& matrix, bool verbose=false,
307 bool reusevector=true);
308
309
320 SuperLU(const Matrix& matrix, const ParameterTree& config)
321 : SuperLU(matrix, config.get<bool>("verbose", false), config.get<bool>("reuseVector", true))
322 {}
323
330 SuperLU();
331
332 ~SuperLU();
333
337 void apply(domain_type& x, range_type& b, InverseOperatorResult& res) override;
338
342 void apply (domain_type& x, range_type& b, [[maybe_unused]] double reduction, InverseOperatorResult& res) override
343 {
344 apply(x,b,res);
345 }
346
350 void apply(T* x, T* b);
351
353 void setMatrix(const Matrix& mat);
354
355 typename SuperLUMatrix::size_type nnz() const
356 {
357 return mat.nonzeroes();
358 }
359
360 template<class S>
361 void setSubMatrix(const Matrix& mat, const S& rowIndexSet);
362
363 void setVerbosity(bool v);
364
369 void free();
370
371 const char* name() { return "SuperLU"; }
372 private:
373 template<class Mat,class X, class TM, class TD, class T1>
375 friend struct SeqOverlappingSchwarzAssemblerHelper<SuperLU<Matrix,Dom,Ran>,true>;
376
377 SuperLUMatrix& getInternalMatrix() { return mat; }
378
380 void decompose();
381
383 SuperMatrix L, U, B, X;
384 int *perm_c, *perm_r, *etree;
385 typename GetSuperLUType<T>::float_type *R, *C;
386 T *bstore;
387 superlu_options_t options;
388 char equed;
389 void *work;
390 int lwork;
391 bool first, verbose, reusevector;
392 };
393
394 template<typename M, typename Dom, typename Ran>
395 SuperLU<M,Dom, Ran>
396 ::~SuperLU()
397 {
398 if(mat.N()+mat.M()>0)
399 free();
400 }
401
402 template<typename M, typename Dom, typename Ran>
404 {
405 delete[] perm_c;
406 delete[] perm_r;
407 delete[] etree;
408 delete[] R;
409 delete[] C;
410 if(lwork>=0) {
411 Destroy_SuperNode_Matrix(&L);
412 Destroy_CompCol_Matrix(&U);
413 }
414 lwork=0;
415 if(!first && reusevector) {
416 SUPERLU_FREE(B.Store);
417 SUPERLU_FREE(X.Store);
418 }
419 mat.free();
420 }
421
422 template<typename M, typename Dom, typename Ran>
424 ::SuperLU(const Matrix& mat_, bool verbose_, bool reusevector_)
425 : work(0), lwork(0), first(true), verbose(verbose_),
426 reusevector(reusevector_)
427 {
428 setMatrix(mat_);
429
430 }
431 template<typename M, typename Dom, typename Ran>
433 : work(0), lwork(0),verbose(false),
434 reusevector(false)
435 {}
436 template<typename M, typename Dom, typename Ran>
438 {
439 verbose=v;
440 }
441
442 template<typename M, typename Dom, typename Ran>
444 {
445 if(mat.N()+mat.M()>0) {
446 free();
447 }
448 lwork=0;
449 work=0;
450 //a=&mat_;
451 mat=mat_;
452 decompose();
453 }
454
455 template<typename M, typename Dom, typename Ran>
456 template<class S>
458 const S& mrs)
459 {
460 if(mat.N()>0 or mat.M()>0) {
461 free();
462 }
463 lwork=0;
464 work=0;
465 //a=&mat_;
466 mat.setMatrix(mat_,mrs);
467 decompose();
468 }
469
470 template<typename M, typename Dom, typename Ran>
472 {
473
474 first = true;
475 perm_c = new int[mat.M()];
476 perm_r = new int[mat.N()];
477 etree = new int[mat.M()];
478 R = new typename GetSuperLUType<T>::float_type[mat.N()];
479 C = new typename GetSuperLUType<T>::float_type[mat.M()];
480
481 set_default_options(&options);
482 // Do the factorization
483 B.ncol=0;
484 B.Stype=SLU_DN;
486 B.Mtype= SLU_GE;
487 DNformat fakeFormat;
488 fakeFormat.lda=mat.N();
489 B.Store=&fakeFormat;
490 X.Stype=SLU_DN;
492 X.Mtype= SLU_GE;
493 X.ncol=0;
494 X.Store=&fakeFormat;
495
496 typename GetSuperLUType<T>::float_type rpg, rcond, ferr=1e10, berr=1e10;
497 int info;
498 mem_usage_t memusage;
499 SuperLUStat_t stat;
500
501 StatInit(&stat);
502 SuperLUSolveChooser<T>::solve(&options, &static_cast<SuperMatrix&>(mat), perm_c, perm_r, etree, &equed, R, C,
503 &L, &U, work, lwork, &B, &X, &rpg, &rcond, &ferr,
504 &berr, &memusage, &stat, &info);
505
506 if(verbose) {
507 dinfo<<"LU factorization: dgssvx() returns info "<< info<<std::endl;
508
509 auto nSuperLUCol = static_cast<SuperMatrix&>(mat).ncol;
510
511 if ( info == 0 || info == nSuperLUCol+1 ) {
512
513 if ( options.PivotGrowth )
514 dinfo<<"Recip. pivot growth = "<<rpg<<std::endl;
515 if ( options.ConditionNumber )
516 dinfo<<"Recip. condition number = %e\n"<< rcond<<std::endl;
517 SCformat* Lstore = (SCformat *) L.Store;
518 NCformat* Ustore = (NCformat *) U.Store;
519 dinfo<<"No of nonzeros in factor L = "<< Lstore->nnz<<std::endl;
520 dinfo<<"No of nonzeros in factor U = "<< Ustore->nnz<<std::endl;
521 dinfo<<"No of nonzeros in L+U = "<< Lstore->nnz + Ustore->nnz - nSuperLUCol<<std::endl;
522 QuerySpaceChooser<T>::querySpace(&L, &U, &memusage);
523 dinfo<<"L\\U MB "<<memusage.for_lu/1e6<<" \ttotal MB needed "<<memusage.total_needed/1e6
524 <<" \texpansions ";
525 std::cout<<stat.expansions<<std::endl;
526
527 } else if ( info > 0 && lwork == -1 ) { // Memory allocation failed
528 dinfo<<"** Estimated memory: "<< info - nSuperLUCol<<std::endl;
529 }
530 if ( options.PrintStat ) StatPrint(&stat);
531 }
532 StatFree(&stat);
533 /*
534 NCformat* Ustore = (NCformat *) U.Store;
535 int k=0;
536 dPrint_CompCol_Matrix("U", &U);
537 for(int i=0; i < U.ncol; ++i, ++k){
538 std::cout<<i<<": ";
539 for(int c=Ustore->colptr[i]; c < Ustore->colptr[i+1]; ++c)
540 //if(Ustore->rowind[c]==i)
541 std::cout<<Ustore->rowind[c]<<"->"<<((double*)Ustore->nzval)[c]<<" ";
542 if(k==0){
543 //
544 k=-1;
545 }std::cout<<std::endl;
546 }
547 dPrint_SuperNode_Matrix("L", &L);
548 for(int i=0; i < U.ncol; ++i, ++k){
549 std::cout<<i<<": ";
550 for(int c=Ustore->colptr[i]; c < Ustore->colptr[i+1]; ++c)
551 //if(Ustore->rowind[c]==i)
552 std::cout<<Ustore->rowind[c]<<"->"<<((double*)Ustore->nzval)[c]<<" ";
553 if(k==0){
554 //
555 k=-1;
556 }std::cout<<std::endl;
557 } */
558 options.Fact = FACTORED;
559 }
560
561 template<typename M, typename Dom, typename Ran>
562 void SuperLU<M,Dom,Ran>
564 {
565 if (mat.N() != b.dim())
566 DUNE_THROW(ISTLError, "Size of right-hand-side vector b does not match the number of matrix rows!");
567 if (mat.M() != x.dim())
568 DUNE_THROW(ISTLError, "Size of solution vector x does not match the number of matrix columns!");
569 if (b.size() >= std::numeric_limits<ptrdiff_t>::max())
570 DUNE_THROW(ISTLError, "Size of right-hand-side vector b is too large!");
571 if (x.size() >= std::numeric_limits<ptrdiff_t>::max())
572 DUNE_THROW(ISTLError, "Size of solution vector x is too large!");
573 if (std::distance(b.begin(),b.end())!=static_cast<std::ptrdiff_t>(b.size()))
574 DUNE_THROW(ISTLError, "Vector b is not contiguous!");
575 if (std::distance(x.begin(),x.end())!=static_cast<std::ptrdiff_t>(x.size()))
576 DUNE_THROW(ISTLError, "Vector x is not contiguous!");
577 if (mat.M()+mat.N()==0)
578 DUNE_THROW(ISTLError, "Matrix of SuperLU is null!");
579
580 SuperMatrix* mB = &B;
581 SuperMatrix* mX = &X;
582 SuperMatrix rB, rX;
583 if (reusevector) {
584 if(first) {
585 SuperLUDenseMatChooser<T>::create(&B, (int)mat.N(), 1, reinterpret_cast<T*>(b.data()), (int)mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
586 SuperLUDenseMatChooser<T>::create(&X, (int)mat.N(), 1, reinterpret_cast<T*>(x.data()), (int)mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
587 first=false;
588 }else{
589 ((DNformat*)B.Store)->nzval=b.data();
590 ((DNformat*)X.Store)->nzval=x.data();
591 }
592 } else {
593 SuperLUDenseMatChooser<T>::create(&rB, (int)mat.N(), 1, reinterpret_cast<T*>(b.data()), (int)mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
594 SuperLUDenseMatChooser<T>::create(&rX, (int)mat.N(), 1, reinterpret_cast<T*>(x.data()), (int)mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
595 mB = &rB;
596 mX = &rX;
597 }
598 typename GetSuperLUType<T>::float_type rpg, rcond, ferr=1e10, berr;
599 int info;
600 mem_usage_t memusage;
601 SuperLUStat_t stat;
602 /* Initialize the statistics variables. */
603 StatInit(&stat);
604 /*
605 range_type d=b;
606 a->usmv(-1, x, d);
607
608 double def0=d.two_norm();
609 */
610 options.IterRefine=SLU_DOUBLE;
611
612 SuperLUSolveChooser<T>::solve(&options, &static_cast<SuperMatrix&>(mat), perm_c, perm_r, etree, &equed, R, C,
613 &L, &U, work, lwork, mB, mX, &rpg, &rcond, &ferr, &berr,
614 &memusage, &stat, &info);
615
616 res.iterations=1;
617
618 /*
619 if(options.Equil==YES)
620 // undo scaling of right hand side
621 std::transform(reinterpret_cast<T*>(&b[0]),reinterpret_cast<T*>(&b[0])+mat.M(),
622 C, reinterpret_cast<T*>(&d[0]), std::divides<T>());
623 else
624 d=b;
625 a->usmv(-1, x, d);
626 res.reduction=d.two_norm()/def0;
627 res.conv_rate = res.reduction;
628 res.converged=(res.reduction<1e-10||d.two_norm()<1e-18);
629 */
630 res.converged=true;
631
632 if(verbose) {
633
634 dinfo<<"Triangular solve: dgssvx() returns info "<< info<<std::endl;
635
636 auto nSuperLUCol = static_cast<SuperMatrix&>(mat).ncol;
637
638 if ( info == 0 || info == nSuperLUCol+1 ) {
639
640 if ( options.IterRefine ) {
641 std::cout<<"Iterative Refinement: steps="
642 <<stat.RefineSteps<<" FERR="<<ferr<<" BERR="<<berr<<std::endl;
643 }else
644 std::cout<<" FERR="<<ferr<<" BERR="<<berr<<std::endl;
645 } else if ( info > 0 && lwork == -1 ) { // Memory allocation failed
646 std::cout<<"** Estimated memory: "<< info - nSuperLUCol<<" bytes"<<std::endl;
647 }
648
649 if ( options.PrintStat ) StatPrint(&stat);
650 }
651 StatFree(&stat);
652 if (!reusevector) {
653 SUPERLU_FREE(rB.Store);
654 SUPERLU_FREE(rX.Store);
655 }
656 }
657
658 template<typename M, typename Dom, typename Ran>
660 ::apply(T* x, T* b)
661 {
662 if(mat.N()+mat.M()==0)
663 DUNE_THROW(ISTLError, "Matrix of SuperLU is null!");
664
665 SuperMatrix* mB = &B;
666 SuperMatrix* mX = &X;
667 SuperMatrix rB, rX;
668 if (reusevector) {
669 if(first) {
670 SuperLUDenseMatChooser<T>::create(&B, mat.N(), 1, b, mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
671 SuperLUDenseMatChooser<T>::create(&X, mat.N(), 1, x, mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
672 first=false;
673 }else{
674 ((DNformat*) B.Store)->nzval=b;
675 ((DNformat*)X.Store)->nzval=x;
676 }
677 } else {
678 SuperLUDenseMatChooser<T>::create(&rB, mat.N(), 1, b, mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
679 SuperLUDenseMatChooser<T>::create(&rX, mat.N(), 1, x, mat.N(), SLU_DN, GetSuperLUType<T>::type, SLU_GE);
680 mB = &rB;
681 mX = &rX;
682 }
683
684 typename GetSuperLUType<T>::float_type rpg, rcond, ferr=1e10, berr;
685 int info;
686 mem_usage_t memusage;
687 SuperLUStat_t stat;
688 /* Initialize the statistics variables. */
689 StatInit(&stat);
690
691 options.IterRefine=SLU_DOUBLE;
692
693 SuperLUSolveChooser<T>::solve(&options, &static_cast<SuperMatrix&>(mat), perm_c, perm_r, etree, &equed, R, C,
694 &L, &U, work, lwork, mB, mX, &rpg, &rcond, &ferr, &berr,
695 &memusage, &stat, &info);
696
697 if(verbose) {
698 dinfo<<"Triangular solve: dgssvx() returns info "<< info<<std::endl;
699
700 auto nSuperLUCol = static_cast<SuperMatrix&>(mat).ncol;
701
702 if ( info == 0 || info == nSuperLUCol+1 ) { // Factorization has succeeded
703
704 if ( options.IterRefine ) {
705 dinfo<<"Iterative Refinement: steps="
706 <<stat.RefineSteps<<" FERR="<<ferr<<" BERR="<<berr<<std::endl;
707 }else
708 dinfo<<" FERR="<<ferr<<" BERR="<<berr<<std::endl;
709 } else if ( info > 0 && lwork == -1 ) { // Memory allocation failed
710 dinfo<<"** Estimated memory: "<< info - nSuperLUCol<<" bytes"<<std::endl;
711 }
712 if ( options.PrintStat ) StatPrint(&stat);
713 }
714
715 StatFree(&stat);
716 if (!reusevector) {
717 SUPERLU_FREE(rB.Store);
718 SUPERLU_FREE(rX.Store);
719 }
720 }
723 template<typename T, typename A, typename Dom, typename Ran>
724 struct IsDirectSolver<SuperLU<BCRSMatrix<T,A>, Dom, Ran > >
725 {
726 enum { value=true};
727 };
728
729 template<typename T, typename A, typename Dom, typename Ran>
731 {
732 enum { value = true };
733 };
734
735
737 [](auto opTraits, const auto& op, const Dune::ParameterTree& config)
738 -> std::shared_ptr<typename decltype(opTraits)::solver_type>
739 {
740 using OpTraits = decltype(opTraits);
741 using M = typename OpTraits::matrix_type;
742 using X = typename OpTraits::domain_type;
743 using Y = typename OpTraits::range_type;
744 // works only for sequential operators
745 if constexpr (OpTraits::isParallel){
746 if(opTraits.getCommOrThrow(op).communicator().size() > 1)
747 DUNE_THROW(Dune::InvalidStateException, "SuperLU works only for sequential operators.");
748 }
749 if constexpr (OpTraits::isAssembled &&
750 // check whether the Matrix field_type is double or complex<double>
751 std::is_same_v<typename FieldTraits<M>::real_type, double>){
752 // check if SuperLU<M>* is convertible to
753 // InverseOperator*. This checks compatibility of the
754 // domain and range types
755 if constexpr (std::is_convertible_v<SuperLU<M,X,Y>*,
756 Dune::InverseOperator<typename OpTraits::domain_type,
757 typename OpTraits::range_type>*>
758 ){
759 const auto& A = opTraits.getAssembledOpOrThrow(op);
760 const M& mat = A->getmat();
761 int verbose = config.get("verbose", 0);
762 return std::make_shared<Dune::SuperLU<M,X,Y>>(mat,verbose);
763 }
764 }
766 "Unsupported Type in SuperLU (only double and std::complex<double> supported)");
767 });
768} // end namespace DUNE
769
770// undefine macros from SuperLU's slu_util.h
771#undef FIRSTCOL_OF_SNODE
772#undef NO_MARKER
773#undef NUM_TEMPV
774#undef USER_ABORT
775#undef USER_MALLOC
776#undef SUPERLU_MALLOC
777#undef USER_FREE
778#undef SUPERLU_FREE
779#undef CHECK_MALLOC
780#undef SUPERLU_MAX
781#undef SUPERLU_MIN
782#undef L_SUB_START
783#undef L_SUB
784#undef L_NZ_START
785#undef L_FST_SUPC
786#undef U_NZ_START
787#undef U_SUB
788#undef TRUE
789#undef FALSE
790#undef EMPTY
791#undef NODROP
792#undef DROP_BASIC
793#undef DROP_PROWS
794#undef DROP_COLUMN
795#undef DROP_AREA
796#undef DROP_SECONDARY
797#undef DROP_DYNAMIC
798#undef DROP_INTERP
799#undef MILU_ALPHA
800
801#endif // HAVE_SUPERLU
802#endif // DUNE_SUPERLU_HH
#define DUNE_REGISTER_SOLVER(name,...)
Definition solverregistry.hh:17
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Dune::ParameterTree options
Templates characterizing the type of a solver.
Implementations of the inverse operator interface.
void apply(domain_type &x, range_type &b, InverseOperatorResult &res) override
Apply inverse operator,.
Definition superlu.hh:563
~SuperLU()
Definition superlu.hh:396
void setVerbosity(bool v)
Definition superlu.hh:437
void setMatrix(const Matrix &mat)
Initialize data from given matrix.
Definition superlu.hh:443
void setSubMatrix(const Matrix &mat, const S &rowIndexSet)
Definition superlu.hh:457
void free()
free allocated space.
Definition superlu.hh:403
SuperLU()
Empty default constructor.
Definition superlu.hh:432
Matrix & mat
Definition matrixmatrix.hh:347
STL namespace.
void destroy(pointer p)
static constexpr size_type M()
void solve(V &x, const V &b) const
#define DUNE_THROW(E,...)
void free()
DInfoType dinfo
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:468
A generic dynamic dense matrix.
Definition matrix.hh:561
size_type M() const
Return the number of columns.
Definition matrix.hh:696
size_type N() const
Return the number of rows.
Definition matrix.hh:691
std::string get(const std::string &key, const std::string &defaultValue) 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
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 superlu.hh:45
Definition superlu.hh:49
Definition superlu.hh:53
Definition superlu.hh:57
SuperLu Solver.
Definition superlu.hh:271
M matrix_type
Definition superlu.hh:276
SuperMatrixInitializer< Matrix > MatrixInitializer
Type of an associated initializer class.
Definition superlu.hh:280
M Matrix
The matrix type.
Definition superlu.hh:275
void apply(domain_type &x, range_type &b, double reduction, InverseOperatorResult &res) override
apply inverse operator, with given convergence criteria.
Definition superlu.hh:342
Ran range_type
The type of the range of the solver.
Definition superlu.hh:284
SuperLUMatrix::size_type nnz() const
Definition superlu.hh:355
const char * name()
Definition superlu.hh:371
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition superlu.hh:287
Dom domain_type
The type of the domain of the solver.
Definition superlu.hh:282
Dune::SuperLUMatrix< Matrix > SuperLUMatrix
The corresponding SuperLU Matrix type.
Definition superlu.hh:278
SuperLU(const Matrix &matrix, const ParameterTree &config)
Constructs the SuperLU solver.
Definition superlu.hh:320
Definition supermatrix.hh:132
Utility class for converting an ISTL Matrix into a SuperLU Matrix.
Definition supermatrix.hh:175
Definition supermatrix.hh:179
T distance(T... args)
T endl(T... args)