5#ifndef DUNE_ISTL_GSETC_HH
6#define DUNE_ISTL_GSETC_HH
14#include <dune/common/hybridutilities.hh>
16#include "multitypeblockvector.hh"
17#include "multitypeblockmatrix.hh"
19#include "istlexception.hh"
46 enum {recursion_level = l};
68 template<
int I, WithDiagType diag, WithRelaxType relax>
69 struct algmeta_btsolve {
70 template<
class M,
class X,
class Y,
class K>
71 static void bltsolve (
const M& A, X& v,
const Y& d,
const K& w)
74 typedef typename M::ConstRowIterator rowiterator;
75 typedef typename M::ConstColIterator coliterator;
76 typedef typename Y::block_type bblock;
79 rowiterator endi=A.end();
80 for (rowiterator i=A.begin(); i!=endi; ++i)
82 bblock rhs(d[i.index()]);
84 for (j=(*i).begin(); j.index()<i.index(); ++j)
85 (*j).mmv(v[j.index()],rhs);
89 template<
class M,
class X,
class Y,
class K>
90 static void butsolve (
const M& A, X& v,
const Y& d,
const K& w)
93 typedef typename M::ConstRowIterator rowiterator;
94 typedef typename M::ConstColIterator coliterator;
95 typedef typename Y::block_type bblock;
98 rowiterator rendi=A.beforeBegin();
99 for (rowiterator i=A.beforeEnd(); i!=rendi; --i)
101 bblock rhs(d[i.index()]);
103 for (j=(*i).beforeEnd(); j.index()>i.index(); --j)
104 (*j).mmv(v[j.index()],rhs);
112 struct algmeta_btsolve<0,withdiag,withrelax> {
113 template<
class M,
class X,
class Y,
class K>
114 static void bltsolve (
const M& A, X& v,
const Y& d,
const K& w)
119 template<
class M,
class X,
class Y,
class K>
120 static void butsolve (
const M& A, X& v,
const Y& d,
const K& w)
127 struct algmeta_btsolve<0,withdiag,norelax> {
128 template<
class M,
class X,
class Y,
class K>
129 static void bltsolve (
const M& A, X& v,
const Y& d,
const K& )
133 template<
class M,
class X,
class Y,
class K>
134 static void butsolve (
const M& A, X& v,
const Y& d,
const K& )
140 struct algmeta_btsolve<0,nodiag,withrelax> {
141 template<
class M,
class X,
class Y,
class K>
142 static void bltsolve (
const M& , X& v,
const Y& d,
const K& w)
147 template<
class M,
class X,
class Y,
class K>
148 static void butsolve (
const M& , X& v,
const Y& d,
const K& w)
155 struct algmeta_btsolve<0,nodiag,norelax> {
156 template<
class M,
class X,
class Y,
class K>
157 static void bltsolve (
const M& , X& v,
const Y& d,
const K& )
161 template<
class M,
class X,
class Y,
class K>
162 static void butsolve (
const M& , X& v,
const Y& d,
const K& )
174 template<
class M,
class X,
class Y>
177 typename X::field_type w=1;
181 template<
class M,
class X,
class Y,
class K>
182 void bltsolve (
const M& A, X& v,
const Y& d,
const K& w)
187 template<
class M,
class X,
class Y>
190 typename X::field_type w=1;
194 template<
class M,
class X,
class Y,
class K>
195 void ubltsolve (
const M& A, X& v,
const Y& d,
const K& w)
201 template<
class M,
class X,
class Y>
204 typename X::field_type w=1;
208 template<
class M,
class X,
class Y,
class K>
209 void butsolve (
const M& A, X& v,
const Y& d,
const K& w)
214 template<
class M,
class X,
class Y>
217 typename X::field_type w=1;
221 template<
class M,
class X,
class Y,
class K>
222 void ubutsolve (
const M& A, X& v,
const Y& d,
const K& w)
230 template<
class M,
class X,
class Y,
int l>
233 typename X::field_type w=1;
237 template<
class M,
class X,
class Y,
class K,
int l>
243 template<
class M,
class X,
class Y,
int l>
246 typename X::field_type w=1;
250 template<
class M,
class X,
class Y,
class K,
int l>
257 template<
class M,
class X,
class Y,
int l>
260 typename X::field_type w=1;
264 template<
class M,
class X,
class Y,
class K,
int l>
270 template<
class M,
class X,
class Y,
int l>
273 typename X::field_type w=1;
277 template<
class M,
class X,
class Y,
class K,
int l>
293 template<
int I, WithRelaxType relax>
294 struct algmeta_bdsolve {
295 template<
class M,
class X,
class Y,
class K>
296 static void bdsolve (
const M& A, X& v,
const Y& d,
const K& w)
299 typedef typename M::ConstRowIterator rowiterator;
300 typedef typename M::ConstColIterator coliterator;
303 rowiterator rendi=A.beforeBegin();
304 for (rowiterator i=A.beforeEnd(); i!=rendi; --i)
306 coliterator ii=(*i).find(i.index());
314 struct algmeta_bdsolve<0,withrelax> {
315 template<
class M,
class X,
class Y,
class K>
316 static void bdsolve (
const M& A, X& v,
const Y& d,
const K& w)
323 struct algmeta_bdsolve<0,norelax> {
324 template<
class M,
class X,
class Y,
class K>
325 static void bdsolve (
const M& A, X& v,
const Y& d,
const K& )
336 template<
class M,
class X,
class Y>
339 typename X::field_type w=1;
343 template<
class M,
class X,
class Y,
class K>
344 void bdsolve (
const M& A, X& v,
const Y& d,
const K& w)
352 template<
class M,
class X,
class Y,
int l>
355 typename X::field_type w=1;
359 template<
class M,
class X,
class Y,
class K,
int l>
374 template<
int I,
typename M>
375 struct algmeta_itsteps {
377 template<
class X,
class Y,
class K>
378 static void dbgs (
const M& A, X& x,
const Y& b,
const K& w)
380 typedef typename M::ConstRowIterator rowiterator;
381 typedef typename M::ConstColIterator coliterator;
382 typedef typename Y::block_type bblock;
387 rowiterator endi=A.end();
388 for (rowiterator i=A.begin(); i!=endi; ++i)
391 coliterator endj=(*i).end();
392 coliterator j=(*i).begin();
393 if constexpr (IsNumber<typename M::block_type>())
395 for (; j.index()<i.index(); ++j)
396 rhs -= (*j) * x[j.index()];
397 coliterator diag=j++;
398 for (; j != endj; ++j)
399 rhs -= (*j) * x[j.index()];
400 x[i.index()] = rhs / (*diag);
404 for (; j.index()<i.index(); ++j)
405 (*j).mmv(x[j.index()],rhs);
406 coliterator diag=j++;
407 for (; j != endj; ++j)
408 (*j).mmv(x[j.index()],rhs);
417 template<
class X,
class Y,
class K>
418 static void bsorf (
const M& A, X& x,
const Y& b,
const K& w)
420 typedef typename M::ConstRowIterator rowiterator;
421 typedef typename M::ConstColIterator coliterator;
422 typedef typename Y::block_type bblock;
423 typedef typename X::block_type xblock;
427 rowiterator endi=A.end();
428 for (rowiterator i=A.begin(); i!=endi; ++i)
431 coliterator endj=(*i).end();
432 coliterator j=(*i).begin();
433 if constexpr (IsNumber<typename M::block_type>())
435 for (; j.index()<i.index(); ++j)
436 rhs -= (*j) * x[j.index()];
439 rhs -= (*j) * x[j.index()];
445 for (; j.index()<i.index(); ++j)
446 (*j).mmv(x[j.index()],rhs);
449 (*j).mmv(x[j.index()],rhs);
452 x[i.index()].axpy(w,v);
457 template<
class X,
class Y,
class K>
458 static void bsorb (
const M& A, X& x,
const Y& b,
const K& w)
460 typedef typename M::ConstRowIterator rowiterator;
461 typedef typename M::ConstColIterator coliterator;
462 typedef typename Y::block_type bblock;
463 typedef typename X::block_type xblock;
467 rowiterator endi=A.beforeBegin();
468 for (rowiterator i=A.beforeEnd(); i!=endi; --i)
471 coliterator endj=(*i).end();
472 coliterator j=(*i).begin();
473 if constexpr (IsNumber<typename M::block_type>())
475 for (; j.index()<i.index(); ++j)
476 rhs -= (*j) * x[j.index()];
479 rhs -= (*j) * x[j.index()];
485 for (; j.index()<i.index(); ++j)
486 j->mmv(x[j.index()],rhs);
489 j->mmv(x[j.index()],rhs);
492 x[i.index()].axpy(w,v);
497 template<
class X,
class Y,
class K>
498 static void dbjac (
const M& A, X& x,
const Y& b,
const K& w)
500 typedef typename M::ConstRowIterator rowiterator;
501 typedef typename M::ConstColIterator coliterator;
502 typedef typename Y::block_type bblock;
507 rowiterator endi=A.end();
508 for (rowiterator i=A.begin(); i!=endi; ++i)
511 coliterator endj=(*i).end();
512 coliterator j=(*i).begin();
513 if constexpr (IsNumber<typename M::block_type>())
515 for (; j.index()<i.index(); ++j)
516 rhs -= (*j) * x[j.index()];
519 rhs -= (*j) * x[j.index()];
520 v[i.index()] = rhs / (*diag);
524 for (; j.index()<i.index(); ++j)
525 j->mmv(x[j.index()],rhs);
528 j->mmv(x[j.index()],rhs);
537 struct algmeta_itsteps<0,M> {
538 template<
class X,
class Y,
class K>
539 static void dbgs (
const M& A, X& x,
const Y& b,
const K& )
543 template<
class X,
class Y,
class K>
544 static void bsorf (
const M& A, X& x,
const Y& b,
const K& )
548 template<
class X,
class Y,
class K>
549 static void bsorb (
const M& A, X& x,
const Y& b,
const K& )
553 template<
class X,
class Y,
class K>
554 static void dbjac (
const M& A, X& x,
const Y& b,
const K& )
560 template<
int I,
typename T1,
typename... MultiTypeMatrixArgs>
561 struct algmeta_itsteps<I,MultiTypeBlockMatrix<T1, MultiTypeMatrixArgs...>> {
563 typename... MultiTypeVectorArgs,
565 static void dbgs (
const MultiTypeBlockMatrix<T1, MultiTypeMatrixArgs...>& A,
566 MultiTypeBlockVector<MultiTypeVectorArgs...>& x,
567 const MultiTypeBlockVector<MultiTypeVectorArgs...>& b,
575 typename... MultiTypeVectorArgs,
577 static void bsorf (
const MultiTypeBlockMatrix<T1, MultiTypeMatrixArgs...>& A,
578 MultiTypeBlockVector<MultiTypeVectorArgs...>& x,
579 const MultiTypeBlockVector<MultiTypeVectorArgs...>& b,
587 typename... MultiTypeVectorArgs,
589 static void bsorb (
const MultiTypeBlockMatrix<T1, MultiTypeMatrixArgs...>& A,
590 MultiTypeBlockVector<MultiTypeVectorArgs...>& x,
591 const MultiTypeBlockVector<MultiTypeVectorArgs...>& b,
599 typename... MultiTypeVectorArgs,
602 static void dbjac (
const MultiTypeBlockMatrix<T1, MultiTypeMatrixArgs...>& A,
603 MultiTypeBlockVector<MultiTypeVectorArgs...>& x,
604 const MultiTypeBlockVector<MultiTypeVectorArgs...>& b,
615 template<
class M,
class X,
class Y,
class K>
616 void dbgs (
const M& A, X& x,
const Y& b,
const K& w)
621 template<
class M,
class X,
class Y,
class K,
int l>
622 void dbgs (
const M& A, X& x,
const Y& b,
const K& w,
BL<l> )
627 template<
class M,
class X,
class Y,
class K>
628 void bsorf (
const M& A, X& x,
const Y& b,
const K& w)
633 template<
class M,
class X,
class Y,
class K,
int l>
634 void bsorf (
const M& A, X& x,
const Y& b,
const K& w,
BL<l> )
639 template<
class M,
class X,
class Y,
class K>
640 void bsorb (
const M& A, X& x,
const Y& b,
const K& w)
645 template<
class M,
class X,
class Y,
class K,
int l>
646 void bsorb (
const M& A, X& x,
const Y& b,
const K& w,
BL<l> )
648 algmeta_itsteps<l,typename std::remove_cv<M>::type>
::bsorb(A,x,b,w);
651 template<
class M,
class X,
class Y,
class K>
652 void dbjac (
const M& A, X& x,
const Y& b,
const K& w)
657 template<
class M,
class X,
class Y,
class K,
int l>
658 void dbjac (
const M& A, X& x,
const Y& b,
const K& w,
BL<l> )
static void dbjac(const TMatrix &A, TVector &x, const TVector &b, const K &w)
Definition: multitypeblockmatrix.hh:584
static void dbgs(const TMatrix &A, TVector &x, const TVector &b, const K &w)
Definition: multitypeblockmatrix.hh:500
static void bsorb(const TMatrix &A, TVector &x, const TVector &b, const K &w)
Definition: multitypeblockmatrix.hh:556
static constexpr size_type N()
Return the number of matrix rows.
Definition: multitypeblockmatrix.hh:84
static void bsorf(const TMatrix &A, TVector &x, const TVector &b, const K &w)
Definition: multitypeblockmatrix.hh:529
void butsolve(const M &A, X &v, const Y &d, const K &w, BL< l >)
relaxed block upper triangular solve
Definition: gsetc.hh:265
void bltsolve(const M &A, X &v, const Y &d)
block lower triangular solve
Definition: gsetc.hh:175
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:640
void ubltsolve(const M &A, X &v, const Y &d)
unit block lower triangular solve
Definition: gsetc.hh:188
void dbjac(const M &A, X &x, const Y &b, const K &w)
Jacobi step.
Definition: gsetc.hh:652
void dbgs(const M &A, X &x, const Y &b, const K &w)
GS step.
Definition: gsetc.hh:616
void bsorf(const M &A, X &x, const Y &b, const K &w, BL< l >)
SOR step.
Definition: gsetc.hh:634
void dbjac(const M &A, X &x, const Y &b, const K &w, BL< l >)
Jacobi step.
Definition: gsetc.hh:658
void dbgs(const M &A, X &x, const Y &b, const K &w, BL< l >)
GS step.
Definition: gsetc.hh:622
void bltsolve(const M &A, X &v, const Y &d, const K &w, BL< l >)
relaxed block lower triangular solve
Definition: gsetc.hh:238
void bdsolve(const M &A, X &v, const Y &d)
block diagonal solve, no relaxation
Definition: gsetc.hh:337
void bsorb(const M &A, X &x, const Y &b, const K &w, BL< l >)
Backward SOR step.
Definition: gsetc.hh:646
void bdsolve(const M &A, X &v, const Y &d, const K &w, BL< l >)
block diagonal solve, with relaxation
Definition: gsetc.hh:360
void butsolve(const M &A, X &v, const Y &d)
block upper triangular solve
Definition: gsetc.hh:202
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:628
void ubutsolve(const M &A, X &v, const Y &d)
unit block upper triangular solve
Definition: gsetc.hh:215
Dune namespace
Definition: alignedallocator.hh:13
compile-time parameter for block recursion depth
Definition: gsetc.hh:45