3#ifndef DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
4#define DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
10#include <dune/common/dynmatrix.hh>
11#include <dune/common/sllist.hh>
12#include <dune/common/unused.hh>
35 template<
class M,
class X,
class TM,
class TD,
class TA>
36 class SeqOverlappingSchwarz;
41 template<
class I,
class S,
class D>
50 typedef typename AtomInitializer::Matrix
Matrix;
51 typedef typename Matrix::const_iterator
Iter;
78 typedef std::map<size_type,size_type> Map;
79 typedef typename Map::iterator iterator;
80 typedef typename Map::const_iterator const_iterator;
92 const_iterator
begin()
const;
96 const_iterator
end()
const;
99 std::map<size_type,size_type> map_;
104 typedef typename InitializerList::iterator InitIterator;
105 typedef typename IndexSet::const_iterator IndexIteratur;
108 mutable std::vector<IndexMap> indexMaps;
135 template<
class M,
class X,
class Y>
139 template<
class K,
int n,
class Al,
class X,
class Y>
161 assert(A.rows() <= v.size());
162 assert(A.cols() <= v.size());
163 size_t sz = A.rows();
167 v.resize(v.capacity());
168 d.resize(
d.capacity());
183 typedef typename S::const_iterator
SIter;
194 for (
size_t i=0; i<n; i++)
196 for (
size_t j=0; j<n; j++)
208 template<
typename T,
bool tag>
216 template<
class K,
int n,
class Al,
class X,
class Y>
245 void resetIndexForNextDomain();
302 std::size_t maxlength_;
305#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
306 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
335 void resetIndexForNextDomain();
386 std::size_t maxlength_;
391 template<
class M,
class X,
class Y>
474 template<
class M,
class X,
class Y>
493 template<
class M,
class X,
class Y>
511 template<
typename S,
typename T>
515 template<
typename S,
typename T,
typename A,
int n>
531 template<
typename S,
typename T>
535 template<
typename S,
typename T,
typename A,
int n>
559 template<
typename T,
class X,
class S>
563 template<
class X,
class S>
569 template<
class X,
class S>
575 template<
class X,
class S>
592 template<
typename T1,
typename T2,
bool forward>
620 template<
typename T1,
typename T2>
668 template<
class M,
class X,
class TD,
class TA>
681 template<
class T,
bool tag>
688 template<
class K,
int n,
class Al,
class X,
class Y>
692 template<
class RowToDomain,
class Solvers,
class SubDomains>
698 template<
template<
class>
class S,
typename T,
typename A,
int m,
int n>
702 template<
class RowToDomain,
class Solvers,
class SubDomains>
708 template<
class M,
class X,
class Y>
712 template<
class RowToDomain,
class Solvers,
class SubDomains>
718 template<
class M,
class X,
class Y>
723 template<
class M,
class X,
class Y>
779 typedef std::set<size_type, std::less<size_type>,
784 typedef std::vector<subdomain_type, typename TA::template rebind<subdomain_type>::other>
subdomain_vector;
790 typedef std::vector<subdomain_list, typename TA::template rebind<subdomain_list>::other >
rowtodomain_vector;
796 typedef std::vector<slu, typename TA::template rebind<slu>::other>
slu_vector;
838 virtual void pre (X& x, X& b)
861 template<
bool forward>
870 typename M::size_type maxlength;
877 template<
class I,
class S,
class D>
881 : initializers(&
il), indices(&
idx), indexMaps(
il.size()), domains(
domains_)
885 template<
class I,
class S,
class D>
888 typedef typename IndexSet::value_type::const_iterator iterator;
889 for(iterator
domain=(*indices)[row.index()].begin();
domain != (*indices)[row.index()].end(); ++
domain) {
890 (*initializers)[*
domain].addRowNnz(row, domains[*
domain]);
891 indexMaps[*
domain].insert(row.index());
895 template<
class I,
class S,
class D>
898 std::for_each(initializers->begin(), initializers->end(),
899 std::mem_fun_ref(&AtomInitializer::allocateMatrixStorage));
900 std::for_each(initializers->begin(), initializers->end(),
901 std::mem_fun_ref(&AtomInitializer::allocateMarker));
904 template<
class I,
class S,
class D>
907 typedef typename IndexSet::value_type::const_iterator iterator;
908 for(iterator
domain=(*indices)[row.index()].begin();
domain != (*indices)[row.index()].end(); ++
domain) {
909 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*
domain].find(
col.index());
910 if(v!= indexMaps[*
domain].end()) {
911 (*initializers)[*
domain].countEntries(indexMaps[*
domain].find(
col.index())->second);
916 template<
class I,
class S,
class D>
919 std::for_each(initializers->begin(), initializers->end(),
920 std::mem_fun_ref(&AtomInitializer::calcColstart));
923 template<
class I,
class S,
class D>
926 typedef typename IndexSet::value_type::const_iterator iterator;
927 for(iterator
domain=(*indices)[row.index()].begin();
domain!= (*indices)[row.index()].end(); ++
domain) {
928 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*
domain].find(
col.index());
929 if(v!= indexMaps[*
domain].end()) {
931 (*initializers)[*
domain].copyValue(
col, indexMaps[*
domain].find(row.index())->second,
937 template<
class I,
class S,
class D>
940 std::vector<IndexMap>().swap(indexMaps);
941 std::for_each(initializers->begin(), initializers->end(),
942 std::mem_fun_ref(&AtomInitializer::createMatrix));
945 template<
class I,
class S,
class D>
950 template<
class I,
class S,
class D>
954 map_.insert(std::make_pair(
grow, row++));
957 template<
class I,
class S,
class D>
958 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
961 return map_.find(
grow);
964 template<
class I,
class S,
class D>
965 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
968 return map_.find(
grow);
971 template<
class I,
class S,
class D>
972 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
978 template<
class I,
class S,
class D>
979 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
985 template<
class I,
class S,
class D>
986 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
992 template<
class I,
class S,
class D>
993 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
999 template<
class M,
class X,
class TM,
class TD,
class TA>
1002 :
mat(
mat_), relax(relaxationFactor), onTheFly(
fly)
1006#ifdef DUNE_ISTL_WITH_CHECKING
1018 domains=std::max(domains, *
d);
1021 solvers.resize(domains);
1022 subDomains.resize(domains);
1028 subDomains[*
d].insert(row);
1030#ifdef DUNE_ISTL_WITH_CHECKING
1032 typedef typename subdomain_vector::const_iterator iterator;
1033 for(iterator
iter=subDomains.begin();
iter != subDomains.end(); ++
iter) {
1046 template<
class M,
class X,
class TM,
class TD,
class TA>
1051 :
mat(
mat_), solvers(
sd.size()), subDomains(
sd), relax(relaxationFactor),
1054 typedef typename subdomain_vector::const_iterator
DomainIterator;
1056#ifdef DUNE_ISTL_WITH_CHECKING
1062 typedef typename DomainIterator::value_type::const_iterator
entry_iterator;
1078 typedef typename subdomain_type::const_iterator iterator;
1079 for(iterator row=
domain->begin(); row !=
domain->end(); ++row)
1096 template<
typename T,
typename A,
int n,
int m>
1099 template<
class Domain>
1107 template<
class K,
int n,
class Al,
class X,
class Y>
1108 template<
class RowToDomain,
class Solvers,
class SubDomains>
1122 std::size_t maxlength = 0;
1127 maxlength=std::max(maxlength,
domain->size());
1133#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1134 template<
template<
class>
class S,
typename T,
typename A,
int m,
int n>
1135 template<
class RowToDomain,
class Solvers,
class SubDomains>
1146 std::size_t maxlength = 0;
1150 maxlength=std::max(maxlength,
domain->size());
1157 std::vector<MatrixInitializer> initializers(subDomains.size());
1180 maxlength = std::max(maxlength,
solverIt->getInternalMatrix().N());
1188 template<
class M,
class X,
class Y>
1189 template<
class RowToDomain,
class Solvers,
class SubDomains>
1199 std::size_t maxlength = 0;
1203 maxlength=std::max(maxlength,
domain->size());
1210 maxlength=std::max(maxlength,
domain->size());
1219 template<
class M,
class X,
class TM,
class TD,
class TA>
1225 template<
class M,
class X,
class TM,
class TD,
class TA>
1226 template<
bool forward>
1242 Adder adder(v, x, assigner, relax);
1246 std::for_each(
domain->begin(),
domain->end(), assigner);
1247 assigner.resetIndexForNextDomain();
1253 sdsolver.apply(assigner.lhs(), assigner.rhs());
1255 solver->apply(assigner.lhs(), assigner.rhs());
1261 assigner.resetIndexForNextDomain();
1266 assigner.deallocate();
1269 template<
class K,
int n,
class Al,
class X,
class Y>
1272 const X&
b_,
Y& x_) :
1279 maxlength_(maxlength)
1282 template<
class K,
int n,
class Al,
class X,
class Y>
1291 template<
class K,
int n,
class Al,
class X,
class Y>
1294 ::resetIndexForNextDomain()
1299 template<
class K,
int n,
class Al,
class X,
class Y>
1307 template<
class K,
int n,
class Al,
class X,
class Y>
1315 template<
class K,
int n,
class Al,
class X,
class Y>
1323 template<
class K,
int n,
class Al,
class X,
class Y>
1342 (*col).mv((*x)[
col.index()],
tmp);
1361 rhs()[i]-=(*col)[j][k] * (*x)[
col.index()][k];
1368 template<
class K,
int n,
class Al,
class X,
class Y>
1380#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1382 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1384 ::OverlappingAssignerHelper(std::size_t maxlength,
1390 x(&x_), i(0), maxlength_(maxlength)
1397 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1404 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1422 (*col).mv((*x)[
col.index()],
tmp);
1433 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1443 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1453 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1459 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1466 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1475 template<
class M,
class X,
class Y>
1484 rhs_=
new Y(maxlength);
1485 lhs_ =
new X(maxlength);
1488 template<
class M,
class X,
class Y>
1495 template<
class M,
class X,
class Y>
1501 typedef typename matrix_type::ConstColIterator
col_iterator;
1505 (*col).mmv((*x)[
col.index()], (*rhs_)[i]);
1511 template<
class M,
class X,
class Y>
1517 template<
class M,
class X,
class Y>
1523 template<
class M,
class X,
class Y>
1529 template<
class M,
class X,
class Y>
1535 template<
class M,
class X,
class Y>
1541 template<
typename S,
typename T,
typename A,
int n>
1549 template<
typename S,
typename T,
typename A,
int n>
1557 template<
typename S,
typename T,
typename A,
int n>
1565 template<
typename S,
typename T,
typename A,
int n>
1576 template<
typename S,
typename T,
typename A,
int n>
1580 assigner->relaxResult(relax);
1585 template<
typename S,
typename T,
typename A,
int n>
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Various local subdomain solvers based on ILU for SeqOverlappingSchwarz.
Define general preconditioner interface.
Templates characterizing the type of a solver.
Classes for using SuperLU with ISTL matrices.
Classes for using UMFPack with ISTL matrices.
Col col
Definition matrixmatrix.hh:347
Matrix & mat
Definition matrixmatrix.hh:343
void addRowNnz(const Iter &row)
Definition overlappingschwarz.hh:886
void apply(X &v, const X &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition overlappingschwarz.hh:1227
X & lhs()
Get the local left hand side.
Definition overlappingschwarz.hh:1524
void calcColstart() const
Definition overlappingschwarz.hh:917
Y & rhs()
Get the local right hand side.
Definition overlappingschwarz.hh:1530
iterator end()
Definition overlappingschwarz.hh:980
void resetIndexForNextDomain()
Resets the local index to zero.
Definition overlappingschwarz.hh:1536
void copyValue(const Iter &row, const CIter &col) const
Definition overlappingschwarz.hh:924
void createMatrix() const
Definition overlappingschwarz.hh:938
iterator begin()
Definition overlappingschwarz.hh:994
OverlappingSchwarzInitializer(InitializerList &il, const IndexSet &indices, const subdomain_vector &domains)
Definition overlappingschwarz.hh:878
IndexMap()
Definition overlappingschwarz.hh:946
virtual void apply(X &v, const X &d)
Apply the precondtioner.
Definition overlappingschwarz.hh:1220
OverlappingAssignerILUBase(std::size_t maxlength, const M &mat, const Y &b, X &x)
Constructor.
Definition overlappingschwarz.hh:1476
const_iterator find(size_type grow) const
Definition overlappingschwarz.hh:959
void operator()(const size_type &domain)
calculate one entry of the local defect.
Definition overlappingschwarz.hh:1496
SeqOverlappingSchwarz(const matrix_type &mat, const subdomain_vector &subDomains, field_type relaxationFactor=1, bool onTheFly_=true)
Construct the overlapping Schwarz method.
Definition overlappingschwarz.hh:1047
void allocate()
Definition overlappingschwarz.hh:896
void deallocate()
Deallocates memory of the local vector.
Definition overlappingschwarz.hh:1489
void insert(size_type grow)
Definition overlappingschwarz.hh:951
void countEntries(const Iter &row, const CIter &col) const
Definition overlappingschwarz.hh:905
static std::size_t assembleLocalProblems(const RowToDomain &rowToDomain, const matrix_type &mat, Solvers &solvers, const SubDomains &domains, bool onTheFly)
Definition overlappingschwarz.hh:1190
void relaxResult(field_type relax)
relax the result.
Definition overlappingschwarz.hh:1512
void assignResult(block_type &res)
Assigns the block to the current local index. At the same time the local defect is calculated for the...
Definition overlappingschwarz.hh:1518
SeqOverlappingSchwarz(const matrix_type &mat, const rowtodomain_vector &rowToDomain, field_type relaxationFactor=1, bool onTheFly_=true)
Definition overlappingschwarz.hh:1000
Definition basearray.hh:19
void copyToColCompMatrix(F &initializer, const MRS &mrs)
Definition colcompmatrix.hh:428
Iterator implementation class
Definition basearray.hh:84
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:412
A::size_type size_type
The type for the index access and the size.
Definition bcrsmatrix.hh:446
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition bvector.hh:273
A vector of blocks with memory management.
Definition bvector.hh:309
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:742
X::field_type field_type
The field type of the preconditioner.
Definition overlappingschwarz.hh:770
@ category
The category the precondtioner is part of.
Definition overlappingschwarz.hh:800
M matrix_type
The type of the matrix to precondition.
Definition overlappingschwarz.hh:747
TM Mode
The mode (additive or multiplicative) of the Schwarz method.
Definition overlappingschwarz.hh:765
X range_type
The range type of the preconditioner.
Definition overlappingschwarz.hh:757
X domain_type
The domain type of the preconditioner.
Definition overlappingschwarz.hh:752
TD slu
The type for the subdomain solver in use.
Definition overlappingschwarz.hh:793
virtual void pre(X &x, X &b)
Prepare the preconditioner.
Definition overlappingschwarz.hh:838
virtual void post(X &x)
Postprocess the preconditioner.
Definition overlappingschwarz.hh:856
std::vector< subdomain_type, typename TA::template rebind< subdomain_type >::other > subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition overlappingschwarz.hh:784
TA allocator
The allocator to use.
Definition overlappingschwarz.hh:776
SLList< size_type, typename TA::template rebind< size_type >::other > subdomain_list
The type for the row to subdomain mapping.
Definition overlappingschwarz.hh:787
std::vector< subdomain_list, typename TA::template rebind< subdomain_list >::other > rowtodomain_vector
The vector type containing the row index to subdomain mapping.
Definition overlappingschwarz.hh:790
std::vector< slu, typename TA::template rebind< slu >::other > slu_vector
The vector type containing subdomain solvers.
Definition overlappingschwarz.hh:796
matrix_type::size_type size_type
The return type of the size method.
Definition overlappingschwarz.hh:773
std::set< size_type, std::less< size_type >, typename TA::template rebind< size_type >::other > subdomain_type
The type for the subdomain to row index mapping.
Definition overlappingschwarz.hh:781
Definition overlappingschwarz.hh:683
Exact subdomain solver using ILU(p) with appropriate p.
Definition ilusubdomainsolver.hh:75
Definition ilusubdomainsolver.hh:108
RowIterator begin()
Get iterator to first row.
Definition matrix.hh:609
Definition matrixutils.hh:25
Initializer for SuperLU Matrices representing the subdomains.
Definition overlappingschwarz.hh:43
Matrix::row_type::const_iterator CIter
Definition overlappingschwarz.hh:52
S IndexSet
Definition overlappingschwarz.hh:54
Matrix::const_iterator Iter
Definition overlappingschwarz.hh:51
IndexSet::size_type size_type
Definition overlappingschwarz.hh:55
I InitializerList
Definition overlappingschwarz.hh:48
AtomInitializer::Matrix Matrix
Definition overlappingschwarz.hh:50
InitializerList::value_type AtomInitializer
Definition overlappingschwarz.hh:49
D subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition overlappingschwarz.hh:46
Tag that the tells the schwarz method to be additive.
Definition overlappingschwarz.hh:116
Tag that tells the Schwarz method to be multiplicative.
Definition overlappingschwarz.hh:122
Tag that tells the Schwarz method to be multiplicative and symmetric.
Definition overlappingschwarz.hh:129
Exact subdomain solver using Dune::DynamicMatrix<T>::solve.
Definition overlappingschwarz.hh:136
void setSubMatrix(const M &BCRS, S &rowset)
Set the data of the local problem.
Definition overlappingschwarz.hh:179
std::remove_const< M >::type matrix_type
The matrix type the preconditioner is for.
Definition overlappingschwarz.hh:145
Y range_type
The range type of the preconditioner.
Definition overlappingschwarz.hh:151
X domain_type
The domain type of the preconditioner.
Definition overlappingschwarz.hh:149
std::remove_const< M >::type rilu_type
Definition overlappingschwarz.hh:147
K field_type
Definition overlappingschwarz.hh:146
void apply(DynamicVector< field_type > &v, DynamicVector< field_type > &d)
Apply the subdomain solver.
Definition overlappingschwarz.hh:157
Definition overlappingschwarz.hh:210
Y range_type
Definition overlappingschwarz.hh:222
K field_type
Definition overlappingschwarz.hh:221
BCRSMatrix< FieldMatrix< K, n, n >, Al > matrix_type
Definition overlappingschwarz.hh:220
range_type::block_type block_type
Definition overlappingschwarz.hh:223
matrix_type::size_type size_type
Definition overlappingschwarz.hh:224
S< BCRSMatrix< FieldMatrix< T, n, m >, A > >::range_type range_type
Definition overlappingschwarz.hh:310
matrix_type::size_type size_type
Definition overlappingschwarz.hh:314
BCRSMatrix< FieldMatrix< T, n, m >, A > matrix_type
Definition overlappingschwarz.hh:309
range_type::field_type field_type
Definition overlappingschwarz.hh:311
range_type::block_type block_type
Definition overlappingschwarz.hh:312
Definition overlappingschwarz.hh:393
matrix_type::size_type size_type
Definition overlappingschwarz.hh:401
Y::block_type block_type
Definition overlappingschwarz.hh:399
M::field_type field_type
Definition overlappingschwarz.hh:397
M matrix_type
Definition overlappingschwarz.hh:395
OverlappingAssignerHelper(std::size_t maxlength, const M &mat, const Y &b, X &x)
Constructor.
Definition overlappingschwarz.hh:486
OverlappingAssignerHelper(std::size_t maxlength, const M &mat, const Y &b, X &x)
Constructor.
Definition overlappingschwarz.hh:505
Definition overlappingschwarz.hh:513
A::size_type size_type
Definition overlappingschwarz.hh:518
Definition overlappingschwarz.hh:533
A::size_type size_type
Definition overlappingschwarz.hh:538
template meta program for choosing how to add the correction.
Definition overlappingschwarz.hh:561
AdditiveAdder< S, X > Adder
Definition overlappingschwarz.hh:566
MultiplicativeAdder< S, X > Adder
Definition overlappingschwarz.hh:572
MultiplicativeAdder< S, X > Adder
Definition overlappingschwarz.hh:578
Helper template meta program for application of overlapping schwarz.
Definition overlappingschwarz.hh:594
static solver_iterator begin(solver_vector &sv)
Definition overlappingschwarz.hh:600
solver_vector::iterator solver_iterator
Definition overlappingschwarz.hh:596
static domain_iterator end(const subdomain_vector &sv)
Definition overlappingschwarz.hh:614
subdomain_vector::const_iterator domain_iterator
Definition overlappingschwarz.hh:598
T1 solver_vector
Definition overlappingschwarz.hh:595
static domain_iterator begin(const subdomain_vector &sv)
Definition overlappingschwarz.hh:609
T2 subdomain_vector
Definition overlappingschwarz.hh:597
static solver_iterator end(solver_vector &sv)
Definition overlappingschwarz.hh:605
T2 subdomain_vector
Definition overlappingschwarz.hh:625
static solver_iterator end(solver_vector &sv)
Definition overlappingschwarz.hh:633
solver_vector::reverse_iterator solver_iterator
Definition overlappingschwarz.hh:624
subdomain_vector::const_reverse_iterator domain_iterator
Definition overlappingschwarz.hh:626
static solver_iterator begin(solver_vector &sv)
Definition overlappingschwarz.hh:628
T1 solver_vector
Definition overlappingschwarz.hh:623
static domain_iterator begin(const subdomain_vector &sv)
Definition overlappingschwarz.hh:637
static domain_iterator end(const subdomain_vector &sv)
Definition overlappingschwarz.hh:642
Helper template meta program for application of overlapping schwarz.
Definition overlappingschwarz.hh:658
smoother::range_type range_type
Definition overlappingschwarz.hh:660
T smoother
Definition overlappingschwarz.hh:659
static void apply(smoother &sm, range_type &v, const range_type &b)
Definition overlappingschwarz.hh:662
static void apply(smoother &sm, range_type &v, const range_type &b)
Definition overlappingschwarz.hh:674
SeqOverlappingSchwarz< M, X, SymmetricMultiplicativeSchwarzMode, TD, TA > smoother
Definition overlappingschwarz.hh:671
smoother::range_type range_type
Definition overlappingschwarz.hh:672
BCRSMatrix< FieldMatrix< K, n, n >, Al > matrix_type
Definition overlappingschwarz.hh:691
BCRSMatrix< FieldMatrix< T, m, n >, A > matrix_type
Definition overlappingschwarz.hh:701
Definition overlappingschwarz.hh:710
M matrix_type
Definition overlappingschwarz.hh:711
Definition overlappingschwarz.hh:1094
static int size(const Domain &d)
Definition overlappingschwarz.hh:1100
Base class for matrix free definition of preconditioners.
Definition preconditioner.hh:26
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:21