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;
52 typedef typename Matrix::row_type::const_iterator CIter;
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;
812 field_type relaxationFactor=1,
bool onTheFly_=
true);
826 field_type relaxationFactor=1,
bool onTheFly_=
true);
833 virtual void pre (X& x, X& b)
844 virtual void apply (X& v,
const X& d);
856 template<
bool forward>
871 typename M::size_type maxlength;
878 template<
class I,
class S,
class D>
879 OverlappingSchwarzInitializer<I,S,D>::OverlappingSchwarzInitializer(InitializerList& il,
881 const subdomain_vector& domains_)
882 : initializers(&il), indices(&idx), indexMaps(il.size()), domains(domains_)
886 template<
class I,
class S,
class D>
887 void OverlappingSchwarzInitializer<I,S,D>::addRowNnz(
const Iter& row)
889 typedef typename IndexSet::value_type::const_iterator iterator;
890 for(iterator domain=(*indices)[row.index()].begin(); domain != (*indices)[row.index()].end(); ++domain) {
891 (*initializers)[*domain].addRowNnz(row, domains[*domain]);
892 indexMaps[*domain].insert(row.index());
896 template<
class I,
class S,
class D>
897 void OverlappingSchwarzInitializer<I,S,D>::allocate()
899 for(
auto&& i: *initializers)
900 i.allocateMatrixStorage();
901 for(
auto&& i: *initializers)
905 template<
class I,
class S,
class D>
906 void OverlappingSchwarzInitializer<I,S,D>::countEntries(
const Iter& row,
const CIter& col)
const
908 typedef typename IndexSet::value_type::const_iterator iterator;
909 for(iterator domain=(*indices)[row.index()].begin(); domain != (*indices)[row.index()].end(); ++domain) {
910 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*domain].
find(col.index());
911 if(v!= indexMaps[*domain].end()) {
912 (*initializers)[*domain].countEntries(indexMaps[*domain].find(col.index())->second);
917 template<
class I,
class S,
class D>
918 void OverlappingSchwarzInitializer<I,S,D>::calcColstart()
const
920 for(
auto&& i : *initializers)
924 template<
class I,
class S,
class D>
925 void OverlappingSchwarzInitializer<I,S,D>::copyValue(
const Iter& row,
const CIter& col)
const
927 typedef typename IndexSet::value_type::const_iterator iterator;
928 for(iterator domain=(*indices)[row.index()].begin(); domain!= (*indices)[row.index()].end(); ++domain) {
929 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*domain].find(col.index());
930 if(v!= indexMaps[*domain].end()) {
931 assert(indexMaps[*domain].end()!=indexMaps[*domain].find(row.index()));
932 (*initializers)[*domain].copyValue(col, indexMaps[*domain].find(row.index())->second,
938 template<
class I,
class S,
class D>
939 void OverlappingSchwarzInitializer<I,S,D>::createMatrix()
const
941 std::vector<IndexMap>().swap(indexMaps);
942 for(
auto&& i: *initializers)
946 template<
class I,
class S,
class D>
947 OverlappingSchwarzInitializer<I,S,D>::IndexMap::IndexMap()
951 template<
class I,
class S,
class D>
952 void OverlappingSchwarzInitializer<I,S,D>::IndexMap::insert(size_type grow)
954 assert(map_.find(grow)==map_.end());
955 map_.insert(std::make_pair(grow, row++));
958 template<
class I,
class S,
class D>
959 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
960 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
const
962 return map_.find(grow);
965 template<
class I,
class S,
class D>
966 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
967 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
969 return map_.find(grow);
972 template<
class I,
class S,
class D>
973 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
974 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
const
979 template<
class I,
class S,
class D>
980 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
981 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
986 template<
class I,
class S,
class D>
987 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
988 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
const
993 template<
class I,
class S,
class D>
994 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
995 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
1000 template<
class M,
class X,
class TM,
class TD,
class TA>
1003 : mat(mat_), relax(relaxationFactor), onTheFly(fly)
1005 typedef typename rowtodomain_vector::const_iterator RowDomainIterator;
1007#ifdef DUNE_ISTL_WITH_CHECKING
1008 assert(rowToDomain.size()==mat.N());
1009 assert(rowToDomain.size()==mat.M());
1011 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1012 assert(iter->size()>0);
1017 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1018 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
1019 domains=std::max(domains, *d);
1022 solvers.resize(domains);
1023 subDomains.resize(domains);
1027 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter, ++row)
1028 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
1029 subDomains[*d].insert(row);
1031#ifdef DUNE_ISTL_WITH_CHECKING
1033 typedef typename subdomain_vector::const_iterator iterator;
1034 for(iterator iter=subDomains.begin(); iter != subDomains.end(); ++iter) {
1035 typedef typename subdomain_type::const_iterator entry_iterator;
1037 for(entry_iterator entry = iter->begin(); entry != iter->end(); ++entry) {
1043 maxlength = SeqOverlappingSchwarzAssembler<slu>
1044 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
1047 template<
class M,
class X,
class TM,
class TD,
class TA>
1052 : mat(mat_), solvers(sd.size()), subDomains(sd), relax(relaxationFactor),
1055 typedef typename subdomain_vector::const_iterator DomainIterator;
1057#ifdef DUNE_ISTL_WITH_CHECKING
1060 for(DomainIterator d=sd.
begin(); d != sd.
end(); ++d,++i) {
1062 assert(d->size()>0);
1063 typedef typename DomainIterator::value_type::const_iterator entry_iterator;
1065 for(entry_iterator entry = d->
begin(); entry != d->
end(); ++entry) {
1078 for(DomainIterator domain=sd.begin(); domain != sd.end(); ++domain, ++domainId) {
1079 typedef typename subdomain_type::const_iterator iterator;
1080 for(iterator row=domain->begin(); row != domain->end(); ++row)
1081 rowToDomain[*row].push_back(domainId);
1084 maxlength = SeqOverlappingSchwarzAssembler<slu>
1085 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
1097 template<
typename T,
typename A,
int n,
int m>
1100 template<
class Domain>
1101 static int size(
const Domain & d)
1108 template<
class K,
int n,
class Al,
class X,
class Y>
1109 template<
class RowToDomain,
class Solvers,
class SubDomains>
1111 SeqOverlappingSchwarzAssemblerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>::
1112 assembleLocalProblems(
const RowToDomain& rowToDomain,
1113 const matrix_type& mat,
1115 const SubDomains& subDomains,
1122 typedef typename SubDomains::const_iterator DomainIterator;
1123 std::size_t maxlength = 0;
1127 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1128 maxlength=std::max(maxlength, domain->size());
1134#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1135 template<
template<
class>
class S,
typename T,
typename A,
int m,
int n>
1136 template<
class RowToDomain,
class Solvers,
class SubDomains>
1137 std::size_t SeqOverlappingSchwarzAssemblerHelper<S<BCRSMatrix<FieldMatrix<T,m,n>,A> >,
true>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1138 const matrix_type& mat,
1140 const SubDomains& subDomains,
1143 typedef typename S<BCRSMatrix<FieldMatrix<T,m,n>,A> >::MatrixInitializer MatrixInitializer;
1144 typedef typename std::vector<MatrixInitializer>::iterator InitializerIterator;
1145 typedef typename SubDomains::const_iterator DomainIterator;
1146 typedef typename Solvers::iterator SolverIterator;
1147 std::size_t maxlength = 0;
1150 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1151 maxlength=std::max(maxlength, domain->size());
1152 maxlength*=mat[0].
begin()->N();
1155 DomainIterator domain=subDomains.begin();
1158 std::vector<MatrixInitializer> initializers(subDomains.size());
1160 SolverIterator solver=solvers.begin();
1161 for(InitializerIterator initializer=initializers.begin(); initializer!=initializers.end();
1162 ++initializer, ++solver, ++domain) {
1163 solver->getInternalMatrix().N_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1164 solver->getInternalMatrix().M_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1166 *initializer=MatrixInitializer(solver->getInternalMatrix());
1170 typedef OverlappingSchwarzInitializer<std::vector<MatrixInitializer>,
1171 RowToDomain, SubDomains> Initializer;
1173 Initializer initializer(initializers, rowToDomain, subDomains);
1174 copyToColCompMatrix(initializer, mat);
1177 for(
auto&& s: solvers)
1179 for (SolverIterator solverIt = solvers.begin(); solverIt != solvers.end(); ++solverIt)
1181 assert(solverIt->getInternalMatrix().N() == solverIt->getInternalMatrix().M());
1182 maxlength = std::max(maxlength, solverIt->getInternalMatrix().N());
1190 template<
class M,
class X,
class Y>
1191 template<
class RowToDomain,
class Solvers,
class SubDomains>
1192 std::size_t SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1193 const matrix_type& mat,
1195 const SubDomains& subDomains,
1199 typedef typename SubDomains::const_iterator DomainIterator;
1200 typedef typename Solvers::iterator SolverIterator;
1201 std::size_t maxlength = 0;
1204 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1205 maxlength=std::max(maxlength, domain->size());
1208 SolverIterator solver=solvers.begin();
1209 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end();
1210 ++domain, ++solver) {
1211 solver->setSubMatrix(mat, *domain);
1212 maxlength=std::max(maxlength, domain->size());
1221 template<
class M,
class X,
class TM,
class TD,
class TA>
1227 template<
class M,
class X,
class TM,
class TD,
class TA>
1228 template<
bool forward>
1231 typedef slu_vector solver_vector;
1232 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::solver_iterator iterator;
1233 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::domain_iterator
1236 OverlappingAssigner<TD> assigner(maxlength, mat, b, x);
1244 Adder adder(v, x, assigner, relax);
1248 std::for_each(domain->begin(), domain->end(), assigner);
1249 assigner.resetIndexForNextDomain();
1253 sdsolver.setSubMatrix(mat, *domain);
1255 sdsolver.apply(assigner.lhs(), assigner.rhs());
1257 solver->apply(assigner.lhs(), assigner.rhs());
1262 std::for_each(domain->begin(), domain->end(), adder);
1263 assigner.resetIndexForNextDomain();
1268 assigner.deallocate();
1271 template<
class K,
int n,
class Al,
class X,
class Y>
1272 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1274 const X& b_, Y& x_) :
1281 maxlength_(maxlength)
1284 template<
class K,
int n,
class Al,
class X,
class Y>
1286 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1293 template<
class K,
int n,
class Al,
class X,
class Y>
1295 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1296 ::resetIndexForNextDomain()
1301 template<
class K,
int n,
class Al,
class X,
class Y>
1303 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1309 template<
class K,
int n,
class Al,
class X,
class Y>
1311 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1317 template<
class K,
int n,
class Al,
class X,
class Y>
1319 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1320 ::relaxResult(field_type relax)
1325 template<
class K,
int n,
class Al,
class X,
class Y>
1327 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1328 ::operator()(
const size_type& domainIndex)
1333 for(size_type j=0; j<n; ++j, ++i) {
1334 assert(i<maxlength_);
1335 rhs()[i]=(*b)[domainIndex][j];
1342 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1343 block_type tmp(0.0);
1344 (*col).mv((*x)[col.index()], tmp);
1346 for(size_type j=0; j<n; ++j, ++i) {
1347 assert(i<maxlength_);
1353 for(size_type j=0; j<n; ++j, ++i) {
1354 assert(i<maxlength_);
1355 rhs()[i]=(*b)[domainIndex][j];
1361 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1362 for(size_type k=0; k<n; ++k) {
1363 rhs()[i]-=(*col)[j][k] * (*x)[col.index()][k];
1370 template<
class K,
int n,
class Al,
class X,
class Y>
1372 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< FieldMatrix<K,n,n>, Al>, X, Y >,
false>
1373 ::assignResult(block_type& res)
1376 for(size_type j=0; j<n; ++j, ++i) {
1377 assert(i<maxlength_);
1382#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1384 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1385 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>
1386 ::OverlappingAssignerHelper(std::size_t maxlength,
1388 const range_type& b_,
1392 x(&x_), i(0), maxlength_(maxlength)
1394 rhs_ =
new field_type[maxlength];
1395 lhs_ =
new field_type[maxlength];
1399 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1400 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::deallocate()
1406 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1407 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::operator()(
const size_type& domainIndex)
1412 for(size_type j=0; j<n; ++j, ++i) {
1413 assert(i<maxlength_);
1414 rhs_[i]=(*b)[domainIndex][j];
1422 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1424 (*col).mv((*x)[col.index()], tmp);
1426 for(size_type j=0; j<n; ++j, ++i) {
1427 assert(i<maxlength_);
1435 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1436 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::relaxResult(field_type relax)
1438 for(size_type j=i+n; i<j; ++i) {
1439 assert(i<maxlength_);
1445 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1446 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::assignResult(block_type& res)
1449 for(size_type j=0; j<n; ++j, ++i) {
1450 assert(i<maxlength_);
1455 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1456 void OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::resetIndexForNextDomain()
1461 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1462 typename OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::field_type*
1463 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::lhs()
1468 template<
template<
class>
class S,
int n,
int m,
typename T,
typename A>
1469 typename OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::field_type*
1470 OverlappingAssignerHelper<S<BCRSMatrix<FieldMatrix<T,n,m>,A> >,
true>::rhs()
1477 template<
class M,
class X,
class Y>
1478 OverlappingAssignerILUBase<M,X,Y>::OverlappingAssignerILUBase(std::size_t maxlength,
1486 rhs_=
new Y(maxlength);
1487 lhs_ =
new X(maxlength);
1490 template<
class M,
class X,
class Y>
1491 void OverlappingAssignerILUBase<M,X,Y>::deallocate()
1497 template<
class M,
class X,
class Y>
1498 void OverlappingAssignerILUBase<M,X,Y>::operator()(
const size_type& domainIndex)
1500 (*rhs_)[i]=(*b)[domainIndex];
1503 typedef typename matrix_type::ConstColIterator col_iterator;
1506 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1507 (*col).mmv((*x)[col.index()], (*rhs_)[i]);
1513 template<
class M,
class X,
class Y>
1514 void OverlappingAssignerILUBase<M,X,Y>::relaxResult(field_type relax)
1519 template<
class M,
class X,
class Y>
1520 void OverlappingAssignerILUBase<M,X,Y>::assignResult(block_type& res)
1525 template<
class M,
class X,
class Y>
1526 X& OverlappingAssignerILUBase<M,X,Y>::lhs()
1531 template<
class M,
class X,
class Y>
1532 Y& OverlappingAssignerILUBase<M,X,Y>::rhs()
1537 template<
class M,
class X,
class Y>
1538 void OverlappingAssignerILUBase<M,X,Y>::resetIndexForNextDomain()
1543 template<
typename S,
typename T,
typename A,
int n>
1546 OverlappingAssigner<S>& assigner_,
1548 : v(&v_), x(&x_), assigner(&assigner_), relax(relax_)
1551 template<
typename S,
typename T,
typename A,
int n>
1552 void AdditiveAdder<S,BlockVector<FieldVector<T,n>,A> >::operator()(
const size_type& domainIndex)
1555 assigner->assignResult((*v)[domainIndex]);
1559 template<
typename S,
typename T,
typename A,
int n>
1560 void AdditiveAdder<S,BlockVector<FieldVector<T,n>,A> >::axpy()
1567 template<
typename S,
typename T,
typename A,
int n>
1568 MultiplicativeAdder<S,BlockVector<FieldVector<T,n>,A> >
1569 ::MultiplicativeAdder(BlockVector<FieldVector<T,n>,A>& v_,
1570 BlockVector<FieldVector<T,n>,A>& x_,
1571 OverlappingAssigner<S>& assigner_,
const T& relax_)
1572 : x(&x_), assigner(&assigner_), relax(relax_)
1578 template<
typename S,
typename T,
typename A,
int n>
1579 void MultiplicativeAdder<S,BlockVector<FieldVector<T,n>,A> >::operator()(
const size_type& domainIndex)
1582 assigner->relaxResult(relax);
1583 assigner->assignResult((*x)[domainIndex]);
1587 template<
typename S,
typename T,
typename A,
int n>
1588 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:317
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:135
A dense n x m matrix.
Definition: fmatrix.hh:68
vector space out of a tensor product of fields.
Definition: fvector.hh:93
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:30
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 SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: overlappingschwarz.hh:860
virtual void pre(X &x, X &b)
Prepare the preconditioner.
Definition: overlappingschwarz.hh:833
virtual void post(X &x)
Postprocess the preconditioner.
Definition: overlappingschwarz.hh:851
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
This file implements a dense matrix with dynamic numbers of rows and columns.
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
virtual void apply(X &v, const X &d)
Apply the precondtioner.
Definition: overlappingschwarz.hh:1222
SeqOverlappingSchwarz(const matrix_type &mat, const subdomain_vector &subDomains, field_type relaxationFactor=1, bool onTheFly_=true)
Construct the overlapping Schwarz method.
Definition: overlappingschwarz.hh:1048
SeqOverlappingSchwarz(const matrix_type &mat, const rowtodomain_vector &rowToDomain, field_type relaxationFactor=1, bool onTheFly_=true)
Definition: overlappingschwarz.hh:1001
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: alignedallocator.hh:10
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:1095
Category
Definition: solvercategory.hh:21
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
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.