3#ifndef DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
4#define DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
35 template<
class M,
class X,
class TM,
class TD,
class TA>
36 class SeqOverlappingSchwarz;
41 template<
class I,
class S,
class D>
48 typedef I InitializerList;
49 typedef typename InitializerList::value_type AtomInitializer;
50 typedef typename AtomInitializer::Matrix Matrix;
51 typedef typename Matrix::const_iterator Iter;
55 typedef typename IndexSet::size_type size_type;
58 const IndexSet& indices,
62 void addRowNnz(
const Iter& row);
66 void countEntries(
const Iter& row,
const CIter& col)
const;
68 void calcColstart()
const;
70 void copyValue(
const Iter& row,
const CIter& col)
const;
72 void createMatrix()
const;
77 typedef typename S::size_type size_type;
78 typedef std::map<size_type,size_type> Map;
79 typedef typename Map::iterator iterator;
80 typedef typename Map::const_iterator const_iterator;
84 void insert(size_type grow);
86 const_iterator find(size_type grow)
const;
88 iterator find(size_type grow);
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;
106 InitializerList* initializers;
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>
145 typedef typename std::remove_const<M>::type matrix_type;
146 typedef K field_type;
147 typedef typename std::remove_const<M>::type rilu_type;
149 typedef X domain_type;
151 typedef Y range_type;
159 assert(v.size() > 0);
160 assert(v.size() == d.size());
161 assert(A.rows() <= v.size());
162 assert(A.cols() <= v.size());
163 size_t sz = A.rows();
179 void setSubMatrix(
const M& BCRS, S& rowset)
181 size_t sz = rowset.size();
183 typedef typename S::const_iterator SIter;
185 for(SIter rowIdx = rowset.begin(), rowEnd=rowset.end();
186 rowIdx!= rowEnd; ++rowIdx, r++)
189 for(SIter colIdx = rowset.begin(), colEnd=rowset.end();
190 colIdx!= colEnd; ++colIdx, c++)
192 if (BCRS[*rowIdx].find(*colIdx) == BCRS[*rowIdx].end())
194 for (
size_t i=0; i<n; i++)
196 for (
size_t j=0; j<n; j++)
198 A[r*n+i][c*n+j] = BCRS[*rowIdx][*colIdx][i][j];
208 template<
typename T,
bool tag>
209 class OverlappingAssignerHelper
213 using OverlappingAssigner = OverlappingAssignerHelper<T, Dune::StoresColumnCompressed<T>::value>;
216 template<
class K,
int n,
class Al,
class X,
class Y>
217 class OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,false>
220 typedef BCRSMatrix< FieldMatrix<K,n,n>, Al> matrix_type;
221 typedef K field_type;
222 typedef Y range_type;
223 typedef typename range_type::block_type block_type;
224 typedef typename matrix_type::size_type size_type;
233 OverlappingAssignerHelper(std::size_t maxlength,
const BCRSMatrix<FieldMatrix<K,n,n>, Al>& mat_,
const X& b_, Y& x_);
245 void resetIndexForNextDomain();
252 DynamicVector<K> & lhs();
259 DynamicVector<K> & rhs();
266 void relaxResult(field_type relax);
272 void operator()(
const size_type& domainIndex);
282 void assignResult(block_type& res);
288 const matrix_type* mat;
291 DynamicVector<field_type> * rhs_;
294 DynamicVector<field_type> * lhs_;
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>
307 struct OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>, A> >, true>
309 typedef BCRSMatrix<FieldMatrix<T,n,m>, A> matrix_type;
310 typedef typename S<BCRSMatrix<FieldMatrix<T,n,m>, A> >::range_type range_type;
311 typedef typename range_type::field_type field_type;
312 typedef typename range_type::block_type block_type;
314 typedef typename matrix_type::size_type size_type;
323 OverlappingAssignerHelper(std::size_t maxlength,
const matrix_type& mat,
324 const range_type& b, range_type& x);
335 void resetIndexForNextDomain();
353 void relaxResult(field_type relax);
359 void operator()(
const size_type& domain);
368 void assignResult(block_type& res);
374 const matrix_type* mat;
386 std::size_t maxlength_;
391 template<
class M,
class X,
class Y>
392 class OverlappingAssignerILUBase
395 typedef M matrix_type;
397 typedef typename M::field_type field_type;
399 typedef typename Y::block_type block_type;
401 typedef typename matrix_type::size_type size_type;
409 OverlappingAssignerILUBase(std::size_t maxlength,
const M& mat,
421 void resetIndexForNextDomain();
439 void relaxResult(field_type relax);
445 void operator()(
const size_type& domain);
454 void assignResult(block_type& res);
474 template<
class M,
class X,
class Y>
475 class OverlappingAssignerHelper<ILU0SubdomainSolver<M,X,Y>, false>
476 :
public OverlappingAssignerILUBase<M,X,Y>
486 OverlappingAssignerHelper(std::size_t maxlength,
const M& mat,
488 : OverlappingAssignerILUBase<M,X,Y>(maxlength, mat,b,x)
493 template<
class M,
class X,
class Y>
494 class OverlappingAssignerHelper<ILUNSubdomainSolver<M,X,Y>,false>
495 :
public OverlappingAssignerILUBase<M,X,Y>
505 OverlappingAssignerHelper(std::size_t maxlength,
const M& mat,
507 : OverlappingAssignerILUBase<M,X,Y>(maxlength, mat,b,x)
511 template<
typename S,
typename T>
515 template<
typename S,
typename T,
typename A,
int n>
516 struct AdditiveAdder<S, BlockVector<FieldVector<T,n>,A> >
518 typedef typename A::size_type size_type;
519 AdditiveAdder(BlockVector<FieldVector<T,n>,A>& v, BlockVector<FieldVector<T,n>,A>& x,
520 OverlappingAssigner<S>& assigner,
const T& relax_);
521 void operator()(
const size_type& domain);
525 BlockVector<FieldVector<T,n>,A>* v;
526 BlockVector<FieldVector<T,n>,A>* x;
527 OverlappingAssigner<S>* assigner;
531 template<
typename S,
typename T>
532 struct MultiplicativeAdder
535 template<
typename S,
typename T,
typename A,
int n>
536 struct MultiplicativeAdder<S, BlockVector<FieldVector<T,n>,A> >
538 typedef typename A::size_type size_type;
539 MultiplicativeAdder(BlockVector<FieldVector<T,n>,A>& v, BlockVector<FieldVector<T,n>,A>& x,
540 OverlappingAssigner<S>& assigner_,
const T& relax_);
541 void operator()(
const size_type& domain);
545 BlockVector<FieldVector<T,n>,A>* x;
546 OverlappingAssigner<S>* assigner;
559 template<
typename T,
class X,
class S>
563 template<
class X,
class S>
566 typedef AdditiveAdder<S,X> Adder;
569 template<
class X,
class S>
570 struct AdderSelector<MultiplicativeSchwarzMode,X,S>
572 typedef MultiplicativeAdder<S,X> Adder;
575 template<
class X,
class S>
576 struct AdderSelector<SymmetricMultiplicativeSchwarzMode,X,S>
578 typedef MultiplicativeAdder<S,X> Adder;
592 template<
typename T1,
typename T2,
bool forward>
595 typedef T1 solver_vector;
596 typedef typename solver_vector::iterator solver_iterator;
597 typedef T2 subdomain_vector;
598 typedef typename subdomain_vector::const_iterator domain_iterator;
600 static solver_iterator begin(solver_vector& sv)
605 static solver_iterator end(solver_vector& sv)
609 static domain_iterator begin(
const subdomain_vector& sv)
614 static domain_iterator end(
const subdomain_vector& sv)
620 template<
typename T1,
typename T2>
623 typedef T1 solver_vector;
624 typedef typename solver_vector::reverse_iterator solver_iterator;
625 typedef T2 subdomain_vector;
626 typedef typename subdomain_vector::const_reverse_iterator domain_iterator;
628 static solver_iterator begin(solver_vector& sv)
633 static solver_iterator end(solver_vector& sv)
637 static domain_iterator begin(
const subdomain_vector& sv)
642 static domain_iterator end(
const subdomain_vector& sv)
660 typedef typename smoother::range_type range_type;
662 static void apply(smoother& sm, range_type& v,
const range_type& b)
664 sm.template apply<true>(v, b);
668 template<
class M,
class X,
class TD,
class TA>
672 typedef typename smoother::range_type range_type;
674 static void apply(smoother& sm, range_type& v,
const range_type& b)
676 sm.template apply<true>(v, b);
677 sm.template apply<false>(v, b);
681 template<
class T,
bool tag>
682 struct SeqOverlappingSchwarzAssemblerHelper
686 using SeqOverlappingSchwarzAssembler = SeqOverlappingSchwarzAssemblerHelper<T,Dune::StoresColumnCompressed<T>::value>;
688 template<
class K,
int n,
class Al,
class X,
class Y>
689 struct SeqOverlappingSchwarzAssemblerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,false>
691 typedef BCRSMatrix< FieldMatrix<K,n,n>, Al> matrix_type;
692 template<
class RowToDomain,
class Solvers,
class SubDomains>
693 static std::size_t assembleLocalProblems(
const RowToDomain& rowToDomain,
const matrix_type& mat,
694 Solvers& solvers,
const SubDomains& domains,
698 template<
template<
class>
class S,
typename T,
typename A,
int m,
int n>
699 struct SeqOverlappingSchwarzAssemblerHelper<S<BCRSMatrix<FieldMatrix<T,m,n>,A> >,true>
701 typedef BCRSMatrix<FieldMatrix<T,m,n>,A> matrix_type;
702 template<
class RowToDomain,
class Solvers,
class SubDomains>
703 static std::size_t assembleLocalProblems(
const RowToDomain& rowToDomain,
const matrix_type& mat,
704 Solvers& solvers,
const SubDomains& domains,
708 template<
class M,
class X,
class Y>
709 struct SeqOverlappingSchwarzAssemblerILUBase
711 typedef M matrix_type;
712 template<
class RowToDomain,
class Solvers,
class SubDomains>
713 static std::size_t assembleLocalProblems(
const RowToDomain& rowToDomain,
const matrix_type& mat,
714 Solvers& solvers,
const SubDomains& domains,
718 template<
class M,
class X,
class Y>
719 struct SeqOverlappingSchwarzAssemblerHelper<ILU0SubdomainSolver<M,X,Y>,false>
720 :
public SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>
723 template<
class M,
class X,
class Y>
724 struct SeqOverlappingSchwarzAssemblerHelper<ILUNSubdomainSolver<M,X,Y>,false>
725 :
public SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>
738 template<
class M,
class X,
class TM=AdditiveSchwarzMode,
739 class TD=ILU0SubdomainSolver<M,X,X>,
class TA=std::allocator<X> >
779 typedef std::set<size_type, std::less<size_type>,
780 typename TA::template rebind<size_type>::other>
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;
817 field_type relaxationFactor=1,
bool onTheFly_=
true);
831 field_type relaxationFactor=1,
bool onTheFly_=
true);
838 virtual void pre (X& x, X& b)
849 virtual void apply (X& v,
const X& d);
861 template<
bool forward>
870 typename M::size_type maxlength;
877 template<
class I,
class S,
class D>
880 const subdomain_vector& domains_)
881 : initializers(&il), indices(&idx), indexMaps(il.size()), domains(domains_)
885 template<
class I,
class S,
class D>
886 void OverlappingSchwarzInitializer<I,S,D>::addRowNnz(
const Iter& row)
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>
896 void OverlappingSchwarzInitializer<I,S,D>::allocate()
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>
905 void OverlappingSchwarzInitializer<I,S,D>::countEntries(
const Iter& row,
const CIter& col)
const
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>
917 void OverlappingSchwarzInitializer<I,S,D>::calcColstart()
const
919 std::for_each(initializers->begin(), initializers->end(),
920 std::mem_fun_ref(&AtomInitializer::calcColstart));
923 template<
class I,
class S,
class D>
924 void OverlappingSchwarzInitializer<I,S,D>::copyValue(
const Iter& row,
const CIter& col)
const
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()) {
930 assert(indexMaps[*domain].end()!=indexMaps[*domain].find(row.index()));
931 (*initializers)[*domain].copyValue(col, indexMaps[*domain].find(row.index())->second,
937 template<
class I,
class S,
class D>
938 void OverlappingSchwarzInitializer<I,S,D>::createMatrix()
const
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>
946 OverlappingSchwarzInitializer<I,S,D>::IndexMap::IndexMap()
950 template<
class I,
class S,
class D>
951 void OverlappingSchwarzInitializer<I,S,D>::IndexMap::insert(size_type grow)
953 assert(map_.find(grow)==map_.end());
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
959 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
const
961 return map_.find(grow);
964 template<
class I,
class S,
class D>
965 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
966 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
968 return map_.find(grow);
971 template<
class I,
class S,
class D>
972 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
973 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
const
978 template<
class I,
class S,
class D>
979 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
980 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
985 template<
class I,
class S,
class D>
986 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
987 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
const
992 template<
class I,
class S,
class D>
993 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
994 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
999 template<
class M,
class X,
class TM,
class TD,
class TA>
1002 : mat(mat_), relax(relaxationFactor), onTheFly(fly)
1004 typedef typename rowtodomain_vector::const_iterator RowDomainIterator;
1006#ifdef DUNE_ISTL_WITH_CHECKING
1007 assert(rowToDomain.size()==mat.N());
1008 assert(rowToDomain.size()==mat.M());
1010 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1011 assert(iter->size()>0);
1016 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1017 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
1018 domains=std::max(domains, *d);
1021 solvers.resize(domains);
1022 subDomains.resize(domains);
1026 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter, ++row)
1027 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
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) {
1034 typedef typename subdomain_type::const_iterator entry_iterator;
1036 for(entry_iterator entry = iter->begin(); entry != iter->end(); ++entry) {
1042 maxlength = SeqOverlappingSchwarzAssembler<slu>
1043 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
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
1059 for(DomainIterator d=sd.
begin(); d != sd.
end(); ++d,++i) {
1061 assert(d->size()>0);
1062 typedef typename DomainIterator::value_type::const_iterator entry_iterator;
1064 for(entry_iterator entry = d->
begin(); entry != d->
end(); ++entry) {
1077 for(DomainIterator domain=sd.begin(); domain != sd.end(); ++domain, ++domainId) {
1078 typedef typename subdomain_type::const_iterator iterator;
1079 for(iterator row=domain->begin(); row != domain->end(); ++row)
1080 rowToDomain[*row].push_back(domainId);
1083 maxlength = SeqOverlappingSchwarzAssembler<slu>
1084 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
1096 template<
typename T,
typename A,
int n,
int m>
1099 template<
class Domain>
1100 static int size(
const Domain & d)
1107 template<
class K,
int n,
class Al,
class X,
class Y>
1108 template<
class RowToDomain,
class Solvers,
class SubDomains>
1110 SeqOverlappingSchwarzAssemblerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>::
1111 assembleLocalProblems(
const RowToDomain& rowToDomain,
1112 const matrix_type& mat,
1114 const SubDomains& subDomains,
1121 typedef typename SubDomains::const_iterator DomainIterator;
1122 std::size_t maxlength = 0;
1126 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
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>
1136 std::size_t SeqOverlappingSchwarzAssemblerHelper<S<BCRSMatrix<FieldMatrix<T,m,n>,A> >,
true>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1137 const matrix_type& mat,
1139 const SubDomains& subDomains,
1142 typedef typename S<BCRSMatrix<FieldMatrix<T,m,n>,A> >::MatrixInitializer MatrixInitializer;
1143 typedef typename std::vector<MatrixInitializer>::iterator InitializerIterator;
1144 typedef typename SubDomains::const_iterator DomainIterator;
1145 typedef typename Solvers::iterator SolverIterator;
1146 std::size_t maxlength = 0;
1149 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1150 maxlength=std::max(maxlength, domain->size());
1151 maxlength*=mat[0].
begin()->
N();
1154 DomainIterator domain=subDomains.begin();
1157 std::vector<MatrixInitializer> initializers(subDomains.size());
1159 SolverIterator solver=solvers.begin();
1160 for(InitializerIterator initializer=initializers.begin(); initializer!=initializers.end();
1161 ++initializer, ++solver, ++domain) {
1162 solver->getInternalMatrix().N_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1163 solver->getInternalMatrix().M_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1165 *initializer=MatrixInitializer(solver->getInternalMatrix());
1169 typedef OverlappingSchwarzInitializer<std::vector<MatrixInitializer>,
1170 RowToDomain, SubDomains> Initializer;
1172 Initializer initializer(initializers, rowToDomain, subDomains);
1173 copyToColCompMatrix(initializer, mat);
1176 std::for_each(solvers.begin(), solvers.end(), std::mem_fun_ref(&S<BCRSMatrix<FieldMatrix<T,m,n>,A> >::decompose));
1177 for (SolverIterator solverIt = solvers.begin(); solverIt != solvers.end(); ++solverIt)
1179 assert(solverIt->getInternalMatrix().N() == solverIt->getInternalMatrix().M());
1180 maxlength = std::max(maxlength, solverIt->getInternalMatrix().N());
1188 template<
class M,
class X,
class Y>
1189 template<
class RowToDomain,
class Solvers,
class SubDomains>
1190 std::size_t SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1191 const matrix_type& mat,
1193 const SubDomains& subDomains,
1197 typedef typename SubDomains::const_iterator DomainIterator;
1198 typedef typename Solvers::iterator SolverIterator;
1199 std::size_t maxlength = 0;
1202 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1203 maxlength=std::max(maxlength, domain->size());
1206 SolverIterator solver=solvers.begin();
1207 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end();
1208 ++domain, ++solver) {
1209 solver->setSubMatrix(mat, *domain);
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>
1229 typedef slu_vector solver_vector;
1230 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::solver_iterator iterator;
1231 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::domain_iterator
1234 OverlappingAssigner<TD> assigner(maxlength, mat, b, x);
1242 Adder adder(v, x, assigner, relax);
1246 std::for_each(domain->begin(), domain->end(), assigner);
1247 assigner.resetIndexForNextDomain();
1251 sdsolver.setSubMatrix(mat, *domain);
1253 sdsolver.apply(assigner.lhs(), assigner.rhs());
1255 solver->apply(assigner.lhs(), assigner.rhs());
1260 std::for_each(domain->begin(), domain->end(), adder);
1261 assigner.resetIndexForNextDomain();
1266 assigner.deallocate();
1269 template<
class K,
int n,
class Al,
class X,
class Y>
1270 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1272 const X& b_, Y& x_) :
1279 maxlength_(maxlength)
1282 template<
class K,
int n,
class Al,
class X,
class Y>
1284 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1291 template<
class K,
int n,
class Al,
class X,
class Y>
1293 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1294 ::resetIndexForNextDomain()
1299 template<
class K,
int n,
class Al,
class X,
class Y>
1301 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1307 template<
class K,
int n,
class Al,
class X,
class Y>
1309 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1315 template<
class K,
int n,
class Al,
class X,
class Y>
1317 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1318 ::relaxResult(field_type relax)
1323 template<
class K,
int n,
class Al,
class X,
class Y>
1325 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1326 ::operator()(
const size_type& domainIndex)
1331 for(size_type j=0; j<n; ++j, ++i) {
1332 assert(i<maxlength_);
1333 rhs()[i]=(*b)[domainIndex][j];
1340 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1341 block_type tmp(0.0);
1342 (*col).mv((*x)[col.index()], tmp);
1344 for(size_type j=0; j<n; ++j, ++i) {
1345 assert(i<maxlength_);
1351 for(size_type j=0; j<n; ++j, ++i) {
1352 assert(i<maxlength_);
1353 rhs()[i]=(*b)[domainIndex][j];
1359 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1360 for(size_type k=0; k<n; ++k) {
1361 rhs()[i]-=(*col)[j][k] * (*x)[col.index()][k];
1368 template<
class K,
int n,
class Al,
class X,
class Y>
1370 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1371 ::assignResult(block_type& res)
1374 for(size_type j=0; j<n; ++j, ++i) {
1375 assert(i<maxlength_);
1380#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1382 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1383 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>
1384 ::OverlappingAssignerHelper(std::size_t maxlength,
1386 const range_type& b_,
1390 x(&x_), i(0), maxlength_(maxlength)
1392 rhs_ =
new field_type[maxlength];
1393 lhs_ =
new field_type[maxlength];
1397 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1398 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::deallocate()
1404 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1405 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::operator()(
const size_type& domainIndex)
1410 for(size_type j=0; j<n; ++j, ++i) {
1411 assert(i<maxlength_);
1412 rhs_[i]=(*b)[domainIndex][j];
1420 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1422 (*col).mv((*x)[col.index()], tmp);
1424 for(size_type j=0; j<n; ++j, ++i) {
1425 assert(i<maxlength_);
1433 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1434 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::relaxResult(field_type relax)
1436 for(size_type j=i+n; i<j; ++i) {
1437 assert(i<maxlength_);
1443 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1444 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::assignResult(block_type& res)
1447 for(size_type j=0; j<n; ++j, ++i) {
1448 assert(i<maxlength_);
1453 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1454 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::resetIndexForNextDomain()
1459 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1460 typename OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::field_type*
1461 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::lhs()
1466 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1467 typename OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::field_type*
1468 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::rhs()
1475 template<
class M,
class X,
class Y>
1476 OverlappingAssignerILUBase<M,X,Y>::OverlappingAssignerILUBase(std::size_t maxlength,
1484 rhs_=
new Y(maxlength);
1485 lhs_ =
new X(maxlength);
1488 template<
class M,
class X,
class Y>
1489 void OverlappingAssignerILUBase<M,X,Y>::deallocate()
1495 template<
class M,
class X,
class Y>
1496 void OverlappingAssignerILUBase<M,X,Y>::operator()(
const size_type& domainIndex)
1498 (*rhs_)[i]=(*b)[domainIndex];
1501 typedef typename matrix_type::ConstColIterator col_iterator;
1504 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1505 (*col).mmv((*x)[col.index()], (*rhs_)[i]);
1511 template<
class M,
class X,
class Y>
1512 void OverlappingAssignerILUBase<M,X,Y>::relaxResult(field_type relax)
1517 template<
class M,
class X,
class Y>
1518 void OverlappingAssignerILUBase<M,X,Y>::assignResult(block_type& res)
1523 template<
class M,
class X,
class Y>
1524 X& OverlappingAssignerILUBase<M,X,Y>::lhs()
1529 template<
class M,
class X,
class Y>
1530 Y& OverlappingAssignerILUBase<M,X,Y>::rhs()
1535 template<
class M,
class X,
class Y>
1536 void OverlappingAssignerILUBase<M,X,Y>::resetIndexForNextDomain()
1541 template<
typename S,
typename T,
typename A,
int n>
1544 OverlappingAssigner<S>& assigner_,
1546 : v(&v_), x(&x_), assigner(&assigner_), relax(relax_)
1549 template<
typename S,
typename T,
typename A,
int n>
1550 void AdditiveAdder<S,BlockVector<FieldVector<T,n>,A> >::operator()(
const size_type& domainIndex)
1553 assigner->assignResult((*v)[domainIndex]);
1557 template<
typename S,
typename T,
typename A,
int n>
1558 void AdditiveAdder<S,BlockVector<FieldVector<T,n>,A> >::axpy()
1565 template<
typename S,
typename T,
typename A,
int n>
1566 MultiplicativeAdder<S,BlockVector<FieldVector<T,n>,A> >
1567 ::MultiplicativeAdder(BlockVector<FieldVector<T,n>,A>& v_,
1568 BlockVector<FieldVector<T,n>,A>& x_,
1569 OverlappingAssigner<S>& assigner_,
const T& relax_)
1570 : x(&x_), assigner(&assigner_), relax(relax_)
1576 template<
typename S,
typename T,
typename A,
int n>
1577 void MultiplicativeAdder<S,BlockVector<FieldVector<T,n>,A> >::operator()(
const size_type& domainIndex)
1580 assigner->relaxResult(relax);
1581 assigner->assignResult((*x)[domainIndex]);
1585 template<
typename S,
typename T,
typename A,
int n>
1586 void MultiplicativeAdder<S,BlockVector<FieldVector<T,n>,A> >::axpy()
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:423
row_type::ConstIterator ConstColIterator
Const iterator to the entries of a row.
Definition: bcrsmatrix.hh:700
A vector of blocks with memory management.
Definition: bvector.hh:313
Iterator begin()
begin iterator
Definition: densevector.hh:308
Iterator end()
end iterator
Definition: densevector.hh:314
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:334
Exact subdomain solver using Dune::DynamicMatrix<T>::solve.
Definition: overlappingschwarz.hh:136
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: dynvector.hh:133
A dense n x m matrix.
Definition: fmatrix.hh:68
Index Set Interface base class.
Definition: indexidset.hh:76
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:609
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:43
D subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition: overlappingschwarz.hh:46
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:26
A constant iterator for the SLList.
Definition: sllist.hh:369
A single linked list.
Definition: sllist.hh:42
Sequential overlapping Schwarz preconditioner.
Definition: overlappingschwarz.hh:742
X::field_type field_type
The field type of the preconditioner.
Definition: overlappingschwarz.hh:770
void apply(X &v, const X &d)
Apply one step of the preconditioner to the system A(v)=d.
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
@ category
The category the precondtioner is part of.
Definition: overlappingschwarz.hh:800
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
RealIterator< const B > const_iterator
iterator class for sequential access
Definition: basearray.hh:204
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:277
This file implements a dense matrix with dynamic numbers of rows and columns.
virtual void apply(X &v, const X &d)
Apply the precondtioner.
Definition: overlappingschwarz.hh:1220
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
SeqOverlappingSchwarz(const matrix_type &mat, const rowtodomain_vector &rowToDomain, field_type relaxationFactor=1, bool onTheFly_=true)
Definition: overlappingschwarz.hh:1000
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:93
Various local subdomain solvers based on ILU for SeqOverlappingSchwarz.
Dune namespace.
Definition: alignment.hh:11
Define general preconditioner interface.
Implements a singly linked list together with the necessary iterators.
Templates characterizing the type of a solver.
template meta program for choosing how to add the correction.
Definition: overlappingschwarz.hh:561
Tag that the tells the schwarz method to be additive.
Definition: overlappingschwarz.hh:116
Helper template meta program for application of overlapping schwarz.
Definition: overlappingschwarz.hh:594
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:122
Helper template meta program for application of overlapping schwarz.
Definition: overlappingschwarz.hh:658
Definition: overlappingschwarz.hh:1094
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:21
Tag that tells the Schwarz method to be multiplicative and symmetric.
Definition: overlappingschwarz.hh:129
Classes for using SuperLU with ISTL matrices.
Classes for using UMFPack with ISTL matrices.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:18