3#ifndef DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
4#define DUNE_ISTL_OVERLAPPINGSCHWARZ_HH
36 template<
class M,
class X,
class TM,
class TD,
class TA>
37 class SeqOverlappingSchwarz;
42 template<
class I,
class S,
class D>
49 typedef I InitializerList;
50 typedef typename InitializerList::value_type AtomInitializer;
51 typedef typename AtomInitializer::Matrix Matrix;
52 typedef typename Matrix::const_iterator Iter;
53 typedef typename Matrix::row_type::const_iterator CIter;
56 typedef typename IndexSet::size_type size_type;
59 const IndexSet& indices,
63 void addRowNnz(
const Iter& row);
67 void countEntries(
const Iter& row,
const CIter& col)
const;
69 void calcColstart()
const;
71 void copyValue(
const Iter& row,
const CIter& col)
const;
73 void createMatrix()
const;
78 typedef typename S::size_type size_type;
79 typedef std::map<size_type,size_type> Map;
80 typedef typename Map::iterator iterator;
81 typedef typename Map::const_iterator const_iterator;
85 void insert(size_type grow);
87 const_iterator find(size_type grow)
const;
89 iterator find(size_type grow);
93 const_iterator begin()
const;
97 const_iterator end()
const;
100 std::map<size_type,size_type> map_;
105 typedef typename InitializerList::iterator InitIterator;
106 typedef typename IndexSet::const_iterator IndexIteratur;
107 InitializerList* initializers;
109 mutable std::vector<IndexMap> indexMaps;
136 template<
class M,
class X,
class Y>
140 template<
class K,
class Al,
class X,
class Y>
146 typedef typename std::remove_const<M>::type matrix_type;
147 typedef typename X::field_type field_type;
148 typedef typename std::remove_const<M>::type rilu_type;
150 typedef X domain_type;
152 typedef Y range_type;
153 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<K>()))>::rows;
161 assert(v.size() > 0);
162 assert(v.size() == d.size());
163 assert(A.rows() <= v.size());
164 assert(A.cols() <= v.size());
165 size_t sz = A.rows();
181 void setSubMatrix(
const M& BCRS, S& rowset)
183 size_t sz = rowset.size();
185 typedef typename S::const_iterator SIter;
187 for(SIter rowIdx = rowset.begin(), rowEnd=rowset.end();
188 rowIdx!= rowEnd; ++rowIdx, r++)
191 for(SIter colIdx = rowset.begin(), colEnd=rowset.end();
192 colIdx!= colEnd; ++colIdx, c++)
194 if (BCRS[*rowIdx].find(*colIdx) == BCRS[*rowIdx].end())
196 for (
size_t i=0; i<n; i++)
198 for (
size_t j=0; j<n; j++)
200 A[r*n+i][c*n+j] = Impl::asMatrix(BCRS[*rowIdx][*colIdx])[i][j];
210 template<
typename T,
bool tag>
211 class OverlappingAssignerHelper
215 using OverlappingAssigner = OverlappingAssignerHelper<T, Dune::StoresColumnCompressed<T>::value>;
218 template<
class K,
class Al,
class X,
class Y>
219 class OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix<K, Al>, X, Y >,false>
222 typedef BCRSMatrix< K, Al> matrix_type;
223 typedef typename X::field_type field_type;
224 typedef Y range_type;
225 typedef typename range_type::block_type block_type;
226 typedef typename matrix_type::size_type size_type;
227 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<K>()))>::rows;
235 OverlappingAssignerHelper(std::size_t maxlength,
const BCRSMatrix<K, Al>& mat_,
const X& b_, Y& x_);
247 void resetIndexForNextDomain();
254 DynamicVector<field_type> & lhs();
261 DynamicVector<field_type> & rhs();
268 void relaxResult(field_type relax);
274 void operator()(
const size_type& domainIndex);
284 void assignResult(block_type& res);
290 const matrix_type* mat;
293 DynamicVector<field_type> * rhs_;
296 DynamicVector<field_type> * lhs_;
304 std::size_t maxlength_;
307#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
308 template<
template<
class>
class S,
typename T,
typename A>
309 struct OverlappingAssignerHelper<S<BCRSMatrix<T, A>>, true>
311 typedef BCRSMatrix<T, A> matrix_type;
312 typedef typename S<BCRSMatrix<T, A>>::range_type range_type;
313 typedef typename range_type::field_type field_type;
314 typedef typename range_type::block_type block_type;
316 typedef typename matrix_type::size_type size_type;
318 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<T>()))>::rows;
319 static constexpr size_t m = std::decay_t<decltype(Impl::asMatrix(std::declval<T>()))>::cols;
327 OverlappingAssignerHelper(std::size_t maxlength,
const matrix_type& mat,
328 const range_type& b, range_type& x);
339 void resetIndexForNextDomain();
357 void relaxResult(field_type relax);
363 void operator()(
const size_type& domain);
372 void assignResult(block_type& res);
378 const matrix_type* mat;
390 std::size_t maxlength_;
395 template<
class M,
class X,
class Y>
396 class OverlappingAssignerILUBase
399 typedef M matrix_type;
401 typedef typename Y::field_type field_type;
403 typedef typename Y::block_type block_type;
405 typedef typename matrix_type::size_type size_type;
413 OverlappingAssignerILUBase(std::size_t maxlength,
const M& mat,
425 void resetIndexForNextDomain();
443 void relaxResult(field_type relax);
449 void operator()(
const size_type& domain);
458 void assignResult(block_type& res);
478 template<
class M,
class X,
class Y>
479 class OverlappingAssignerHelper<ILU0SubdomainSolver<M,X,Y>, false>
480 :
public OverlappingAssignerILUBase<M,X,Y>
490 OverlappingAssignerHelper(std::size_t maxlength,
const M& mat,
492 : OverlappingAssignerILUBase<M,X,Y>(maxlength, mat,b,x)
497 template<
class M,
class X,
class Y>
498 class OverlappingAssignerHelper<ILUNSubdomainSolver<M,X,Y>,false>
499 :
public OverlappingAssignerILUBase<M,X,Y>
509 OverlappingAssignerHelper(std::size_t maxlength,
const M& mat,
511 : OverlappingAssignerILUBase<M,X,Y>(maxlength, mat,b,x)
515 template<
typename S,
typename T>
519 template<
typename S,
typename T,
typename A>
520 struct AdditiveAdder<S, BlockVector<T,A> >
522 typedef typename A::size_type size_type;
523 typedef typename std::decay_t<decltype(Impl::asVector(std::declval<T>()))>::field_type field_type;
524 AdditiveAdder(BlockVector<T,A>& v, BlockVector<T,A>& x,
525 OverlappingAssigner<S>& assigner,
const field_type& relax_);
526 void operator()(
const size_type& domain);
528 static constexpr size_t n = std::decay_t<decltype(Impl::asVector(std::declval<T>()))>::dimension;
533 OverlappingAssigner<S>* assigner;
537 template<
typename S,
typename T>
538 struct MultiplicativeAdder
541 template<
typename S,
typename T,
typename A>
542 struct MultiplicativeAdder<S, BlockVector<T,A> >
544 typedef typename A::size_type size_type;
545 typedef typename std::decay_t<decltype(Impl::asVector(std::declval<T>()))>::field_type field_type;
546 MultiplicativeAdder(BlockVector<T,A>& v, BlockVector<T,A>& x,
547 OverlappingAssigner<S>& assigner_,
const field_type& relax_);
548 void operator()(
const size_type& domain);
550 static constexpr size_t n = std::decay_t<decltype(Impl::asVector(std::declval<T>()))>::dimension;
554 OverlappingAssigner<S>* assigner;
567 template<
typename T,
class X,
class S>
571 template<
class X,
class S>
574 typedef AdditiveAdder<S,X> Adder;
577 template<
class X,
class S>
578 struct AdderSelector<MultiplicativeSchwarzMode,X,S>
580 typedef MultiplicativeAdder<S,X> Adder;
583 template<
class X,
class S>
584 struct AdderSelector<SymmetricMultiplicativeSchwarzMode,X,S>
586 typedef MultiplicativeAdder<S,X> Adder;
600 template<
typename T1,
typename T2,
bool forward>
603 typedef T1 solver_vector;
604 typedef typename solver_vector::iterator solver_iterator;
605 typedef T2 subdomain_vector;
606 typedef typename subdomain_vector::const_iterator domain_iterator;
608 static solver_iterator begin(solver_vector& sv)
613 static solver_iterator end(solver_vector& sv)
617 static domain_iterator begin(
const subdomain_vector& sv)
622 static domain_iterator end(
const subdomain_vector& sv)
628 template<
typename T1,
typename T2>
631 typedef T1 solver_vector;
632 typedef typename solver_vector::reverse_iterator solver_iterator;
633 typedef T2 subdomain_vector;
634 typedef typename subdomain_vector::const_reverse_iterator domain_iterator;
636 static solver_iterator begin(solver_vector& sv)
641 static solver_iterator end(solver_vector& sv)
645 static domain_iterator begin(
const subdomain_vector& sv)
650 static domain_iterator end(
const subdomain_vector& sv)
668 typedef typename smoother::range_type range_type;
670 static void apply(smoother& sm, range_type& v,
const range_type& b)
672 sm.template apply<true>(v, b);
676 template<
class M,
class X,
class TD,
class TA>
680 typedef typename smoother::range_type range_type;
682 static void apply(smoother& sm, range_type& v,
const range_type& b)
684 sm.template apply<true>(v, b);
685 sm.template apply<false>(v, b);
689 template<
class T,
bool tag>
690 struct SeqOverlappingSchwarzAssemblerHelper
694 using SeqOverlappingSchwarzAssembler = SeqOverlappingSchwarzAssemblerHelper<T,Dune::StoresColumnCompressed<T>::value>;
696 template<
class K,
class Al,
class X,
class Y>
697 struct SeqOverlappingSchwarzAssemblerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,false>
699 typedef BCRSMatrix< K, Al> matrix_type;
700 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<K>()))>::rows;
701 template<
class RowToDomain,
class Solvers,
class SubDomains>
702 static std::size_t assembleLocalProblems(
const RowToDomain& rowToDomain,
const matrix_type& mat,
703 Solvers& solvers,
const SubDomains& domains,
707 template<
template<
class>
class S,
typename T,
typename A>
708 struct SeqOverlappingSchwarzAssemblerHelper<S<BCRSMatrix<T,A>>,true>
710 typedef BCRSMatrix<T,A> matrix_type;
711 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<T>()))>::rows;
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 SeqOverlappingSchwarzAssemblerILUBase
721 typedef M matrix_type;
722 template<
class RowToDomain,
class Solvers,
class SubDomains>
723 static std::size_t assembleLocalProblems(
const RowToDomain& rowToDomain,
const matrix_type& mat,
724 Solvers& solvers,
const SubDomains& domains,
728 template<
class M,
class X,
class Y>
729 struct SeqOverlappingSchwarzAssemblerHelper<ILU0SubdomainSolver<M,X,Y>,false>
730 :
public SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>
733 template<
class M,
class X,
class Y>
734 struct SeqOverlappingSchwarzAssemblerHelper<ILUNSubdomainSolver<M,X,Y>,false>
735 :
public SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>
748 template<
class M,
class X,
class TM=AdditiveSchwarzMode,
749 class TD=ILU0SubdomainSolver<M,X,X>,
class TA=std::allocator<X> >
789 typedef std::set<size_type, std::less<size_type>,
790 typename std::allocator_traits<TA>::template rebind_alloc<size_type> >
794 typedef std::vector<subdomain_type, typename std::allocator_traits<TA>::template rebind_alloc<subdomain_type> >
subdomain_vector;
800 typedef std::vector<subdomain_list, typename std::allocator_traits<TA>::template rebind_alloc<subdomain_list> >
rowtodomain_vector;
806 typedef std::vector<slu, typename std::allocator_traits<TA>::template rebind_alloc<slu> >
slu_vector;
822 field_type relaxationFactor=1,
bool onTheFly_=
true);
836 field_type relaxationFactor=1,
bool onTheFly_=
true);
843 virtual void pre (X& x, X& b)
854 virtual void apply (X& v,
const X& d);
866 template<
bool forward>
881 typename M::size_type maxlength;
888 template<
class I,
class S,
class D>
889 OverlappingSchwarzInitializer<I,S,D>::OverlappingSchwarzInitializer(InitializerList& il,
891 const subdomain_vector& domains_)
892 : initializers(&il), indices(&idx), indexMaps(il.size()), domains(domains_)
896 template<
class I,
class S,
class D>
897 void OverlappingSchwarzInitializer<I,S,D>::addRowNnz(
const Iter& row)
899 typedef typename IndexSet::value_type::const_iterator iterator;
900 for(iterator domain=(*indices)[row.index()].begin(); domain != (*indices)[row.index()].end(); ++domain) {
901 (*initializers)[*domain].addRowNnz(row, domains[*domain]);
902 indexMaps[*domain].insert(row.index());
906 template<
class I,
class S,
class D>
907 void OverlappingSchwarzInitializer<I,S,D>::allocate()
909 for(
auto&& i: *initializers)
910 i.allocateMatrixStorage();
911 for(
auto&& i: *initializers)
915 template<
class I,
class S,
class D>
916 void OverlappingSchwarzInitializer<I,S,D>::countEntries(
const Iter& row,
const CIter& col)
const
918 typedef typename IndexSet::value_type::const_iterator iterator;
919 for(iterator domain=(*indices)[row.index()].begin(); domain != (*indices)[row.index()].end(); ++domain) {
920 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*domain].
find(col.index());
921 if(v!= indexMaps[*domain].end()) {
922 (*initializers)[*domain].countEntries(indexMaps[*domain].find(col.index())->second);
927 template<
class I,
class S,
class D>
928 void OverlappingSchwarzInitializer<I,S,D>::calcColstart()
const
930 for(
auto&& i : *initializers)
934 template<
class I,
class S,
class D>
935 void OverlappingSchwarzInitializer<I,S,D>::copyValue(
const Iter& row,
const CIter& col)
const
937 typedef typename IndexSet::value_type::const_iterator iterator;
938 for(iterator domain=(*indices)[row.index()].begin(); domain!= (*indices)[row.index()].end(); ++domain) {
939 typename std::map<size_type,size_type>::const_iterator v = indexMaps[*domain].find(col.index());
940 if(v!= indexMaps[*domain].end()) {
941 assert(indexMaps[*domain].end()!=indexMaps[*domain].find(row.index()));
942 (*initializers)[*domain].copyValue(col, indexMaps[*domain].find(row.index())->second,
948 template<
class I,
class S,
class D>
949 void OverlappingSchwarzInitializer<I,S,D>::createMatrix()
const
951 std::vector<IndexMap>().swap(indexMaps);
952 for(
auto&& i: *initializers)
956 template<
class I,
class S,
class D>
957 OverlappingSchwarzInitializer<I,S,D>::IndexMap::IndexMap()
961 template<
class I,
class S,
class D>
962 void OverlappingSchwarzInitializer<I,S,D>::IndexMap::insert(size_type grow)
964 assert(map_.find(grow)==map_.end());
965 map_.insert(std::make_pair(grow, row++));
968 template<
class I,
class S,
class D>
969 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
970 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
const
972 return map_.find(grow);
975 template<
class I,
class S,
class D>
976 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
977 OverlappingSchwarzInitializer<I,S,D>::IndexMap::find(size_type grow)
979 return map_.find(grow);
982 template<
class I,
class S,
class D>
983 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
984 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
const
989 template<
class I,
class S,
class D>
990 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
991 OverlappingSchwarzInitializer<I,S,D>::IndexMap::end()
996 template<
class I,
class S,
class D>
997 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::const_iterator
998 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
const
1000 return map_.begin();
1003 template<
class I,
class S,
class D>
1004 typename OverlappingSchwarzInitializer<I,S,D>::IndexMap::iterator
1005 OverlappingSchwarzInitializer<I,S,D>::IndexMap::begin()
1007 return map_.begin();
1010 template<
class M,
class X,
class TM,
class TD,
class TA>
1013 : mat(mat_), relax(relaxationFactor), onTheFly(fly)
1015 typedef typename rowtodomain_vector::const_iterator RowDomainIterator;
1017#ifdef DUNE_ISTL_WITH_CHECKING
1018 assert(rowToDomain.size()==mat.N());
1019 assert(rowToDomain.size()==mat.M());
1021 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1022 assert(iter->size()>0);
1027 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter)
1028 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
1032 solvers.resize(domains);
1033 subDomains.resize(domains);
1037 for(RowDomainIterator iter=rowToDomain.begin(); iter != rowToDomain.end(); ++iter, ++row)
1038 for(DomainIterator d=iter->
begin(); d != iter->
end(); ++d)
1039 subDomains[*d].insert(row);
1041#ifdef DUNE_ISTL_WITH_CHECKING
1043 typedef typename subdomain_vector::const_iterator iterator;
1044 for(iterator iter=subDomains.begin(); iter != subDomains.end(); ++iter) {
1045 typedef typename subdomain_type::const_iterator entry_iterator;
1047 for(entry_iterator entry = iter->begin(); entry != iter->end(); ++entry) {
1053 maxlength = SeqOverlappingSchwarzAssembler<slu>
1054 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
1057 template<
class M,
class X,
class TM,
class TD,
class TA>
1062 : mat(mat_), solvers(sd.size()), subDomains(sd), relax(relaxationFactor),
1065 typedef typename subdomain_vector::const_iterator DomainIterator;
1067#ifdef DUNE_ISTL_WITH_CHECKING
1070 for(DomainIterator d=sd.
begin(); d != sd.
end(); ++d,++i) {
1072 assert(d->size()>0);
1073 typedef typename DomainIterator::value_type::const_iterator entry_iterator;
1075 for(entry_iterator entry = d->
begin(); entry != d->
end(); ++entry) {
1088 for(DomainIterator domain=sd.begin(); domain != sd.end(); ++domain, ++domainId) {
1089 typedef typename subdomain_type::const_iterator iterator;
1090 for(iterator row=domain->begin(); row != domain->end(); ++row)
1091 rowToDomain[*row].push_back(domainId);
1094 maxlength = SeqOverlappingSchwarzAssembler<slu>
1095 ::assembleLocalProblems(rowToDomain, mat, solvers, subDomains, onTheFly);
1107 template<
typename T,
typename A>
1110 static constexpr size_t n = std::decay_t<decltype(Impl::asMatrix(std::declval<T>()))>::rows;
1111 static constexpr size_t m = std::decay_t<decltype(Impl::asMatrix(std::declval<T>()))>::cols;
1112 template<
class Domain>
1113 static int size(
const Domain & d)
1120 template<
class K,
class Al,
class X,
class Y>
1121 template<
class RowToDomain,
class Solvers,
class SubDomains>
1123 SeqOverlappingSchwarzAssemblerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>::
1124 assembleLocalProblems(
const RowToDomain& rowToDomain,
1125 const matrix_type& mat,
1127 const SubDomains& subDomains,
1134 typedef typename SubDomains::const_iterator DomainIterator;
1135 std::size_t maxlength = 0;
1139 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1140 maxlength=
std::max(maxlength, domain->size());
1146#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1147 template<
template<
class>
class S,
typename T,
typename A>
1148 template<
class RowToDomain,
class Solvers,
class SubDomains>
1149 std::size_t SeqOverlappingSchwarzAssemblerHelper<S<BCRSMatrix<T,A>>,
true>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1150 const matrix_type& mat,
1152 const SubDomains& subDomains,
1155 typedef typename S<BCRSMatrix<T,A>>::MatrixInitializer MatrixInitializer;
1156 typedef typename std::vector<MatrixInitializer>::iterator InitializerIterator;
1157 typedef typename SubDomains::const_iterator DomainIterator;
1158 typedef typename Solvers::iterator SolverIterator;
1159 std::size_t maxlength = 0;
1162 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1163 maxlength=
std::max(maxlength, domain->size());
1164 maxlength*=Impl::asMatrix(*mat[0].begin()).N();
1167 DomainIterator domain=subDomains.begin();
1170 std::vector<MatrixInitializer> initializers(subDomains.size());
1172 SolverIterator solver=solvers.begin();
1173 for(InitializerIterator initializer=initializers.begin(); initializer!=initializers.end();
1174 ++initializer, ++solver, ++domain) {
1175 solver->getInternalMatrix().N_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1176 solver->getInternalMatrix().M_=SeqOverlappingSchwarzDomainSize<matrix_type>::size(*domain);
1178 *initializer=MatrixInitializer(solver->getInternalMatrix());
1182 typedef OverlappingSchwarzInitializer<std::vector<MatrixInitializer>,
1183 RowToDomain, SubDomains> Initializer;
1185 Initializer initializer(initializers, rowToDomain, subDomains);
1186 copyToColCompMatrix(initializer, mat);
1189 for(
auto&& s: solvers)
1191 for (SolverIterator solverIt = solvers.begin(); solverIt != solvers.end(); ++solverIt)
1193 assert(solverIt->getInternalMatrix().N() == solverIt->getInternalMatrix().M());
1194 maxlength =
std::max(maxlength, solverIt->getInternalMatrix().N());
1202 template<
class M,
class X,
class Y>
1203 template<
class RowToDomain,
class Solvers,
class SubDomains>
1204 std::size_t SeqOverlappingSchwarzAssemblerILUBase<M,X,Y>::assembleLocalProblems(
const RowToDomain& rowToDomain,
1205 const matrix_type& mat,
1207 const SubDomains& subDomains,
1211 typedef typename SubDomains::const_iterator DomainIterator;
1212 typedef typename Solvers::iterator SolverIterator;
1213 std::size_t maxlength = 0;
1216 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end(); ++domain)
1217 maxlength=
std::max(maxlength, domain->size());
1220 SolverIterator solver=solvers.begin();
1221 for(DomainIterator domain=subDomains.begin(); domain!=subDomains.end();
1222 ++domain, ++solver) {
1223 solver->setSubMatrix(mat, *domain);
1224 maxlength=
std::max(maxlength, domain->size());
1233 template<
class M,
class X,
class TM,
class TD,
class TA>
1239 template<
class M,
class X,
class TM,
class TD,
class TA>
1240 template<
bool forward>
1243 typedef slu_vector solver_vector;
1244 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::solver_iterator iterator;
1245 typedef typename IteratorDirectionSelector<solver_vector,subdomain_vector,forward>::domain_iterator
1248 OverlappingAssigner<TD> assigner(maxlength, mat, b, x);
1256 Adder adder(v, x, assigner, relax);
1260 std::for_each(domain->begin(), domain->end(), assigner);
1261 assigner.resetIndexForNextDomain();
1265 sdsolver.setSubMatrix(mat, *domain);
1267 sdsolver.apply(assigner.lhs(), assigner.rhs());
1269 solver->apply(assigner.lhs(), assigner.rhs());
1274 std::for_each(domain->begin(), domain->end(), adder);
1275 assigner.resetIndexForNextDomain();
1280 assigner.deallocate();
1283 template<
class K,
class Al,
class X,
class Y>
1284 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1286 const X& b_, Y& x_) :
1293 maxlength_(maxlength)
1296 template<
class K,
class Al,
class X,
class Y>
1298 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1305 template<
class K,
class Al,
class X,
class Y>
1307 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1308 ::resetIndexForNextDomain()
1313 template<
class K,
class Al,
class X,
class Y>
1315 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1321 template<
class K,
class Al,
class X,
class Y>
1323 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1329 template<
class K,
class Al,
class X,
class Y>
1331 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1332 ::relaxResult(field_type relax)
1337 template<
class K,
class Al,
class X,
class Y>
1339 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1340 ::operator()(
const size_type& domainIndex)
1345 for(size_type j=0; j<n; ++j, ++i) {
1346 assert(i<maxlength_);
1347 rhs()[i]=(*b)[domainIndex][j];
1354 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1355 block_type tmp(0.0);
1356 (*col).mv((*x)[col.index()], tmp);
1358 for(size_type j=0; j<n; ++j, ++i) {
1359 assert(i<maxlength_);
1365 for(size_type j=0; j<n; ++j, ++i) {
1366 assert(i<maxlength_);
1367 rhs()[i]=Impl::asVector((*b)[domainIndex])[j];
1373 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1374 for(size_type k=0; k<n; ++k) {
1375 rhs()[i]-=Impl::asMatrix(*col)[j][k] * Impl::asVector((*x)[col.index()])[k];
1382 template<
class K,
class Al,
class X,
class Y>
1384 OverlappingAssignerHelper< DynamicMatrixSubdomainSolver< BCRSMatrix< K, Al>, X, Y >,
false>
1385 ::assignResult(block_type& res)
1388 for(size_type j=0; j<n; ++j, ++i) {
1389 assert(i<maxlength_);
1390 Impl::asVector(res)[j]+=lhs()[i];
1394#if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK
1396 template<
template<
class>
class S,
typename T,
typename A>
1397 OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>
1398 ::OverlappingAssignerHelper(std::size_t maxlength,
1400 const range_type& b_,
1404 x(&x_), i(0), maxlength_(maxlength)
1406 rhs_ =
new field_type[maxlength];
1407 lhs_ =
new field_type[maxlength];
1411 template<
template<
class>
class S,
typename T,
typename A>
1412 void OverlappingAssignerHelper<S<BCRSMatrix<T,A> >,
true>::deallocate()
1418 template<
template<
class>
class S,
typename T,
typename A>
1419 void OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::operator()(
const size_type& domainIndex)
1424 for(size_type j=0; j<n; ++j, ++i) {
1425 assert(i<maxlength_);
1426 rhs_[i]=Impl::asVector((*b)[domainIndex])[j];
1434 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1436 Impl::asMatrix(*col).mv((*x)[col.index()], tmp);
1438 for(size_type j=0; j<n; ++j, ++i) {
1439 assert(i<maxlength_);
1440 rhs_[i]-=Impl::asVector(tmp)[j];
1447 template<
template<
class>
class S,
typename T,
typename A>
1448 void OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::relaxResult(field_type relax)
1450 for(size_type j=i+n; i<j; ++i) {
1451 assert(i<maxlength_);
1457 template<
template<
class>
class S,
typename T,
typename A>
1458 void OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::assignResult(block_type& res)
1461 for(size_type j=0; j<n; ++j, ++i) {
1462 assert(i<maxlength_);
1463 Impl::asVector(res)[j]+=lhs_[i];
1467 template<
template<
class>
class S,
typename T,
typename A>
1468 void OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::resetIndexForNextDomain()
1473 template<
template<
class>
class S,
typename T,
typename A>
1474 typename OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::field_type*
1475 OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::lhs()
1480 template<
template<
class>
class S,
typename T,
typename A>
1481 typename OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::field_type*
1482 OverlappingAssignerHelper<S<BCRSMatrix<T,A>>,
true>::rhs()
1489 template<
class M,
class X,
class Y>
1490 OverlappingAssignerILUBase<M,X,Y>::OverlappingAssignerILUBase(std::size_t maxlength,
1498 rhs_=
new Y(maxlength);
1499 lhs_ =
new X(maxlength);
1502 template<
class M,
class X,
class Y>
1503 void OverlappingAssignerILUBase<M,X,Y>::deallocate()
1509 template<
class M,
class X,
class Y>
1510 void OverlappingAssignerILUBase<M,X,Y>::operator()(
const size_type& domainIndex)
1512 (*rhs_)[i]=(*b)[domainIndex];
1515 typedef typename matrix_type::ConstColIterator col_iterator;
1518 for(col_iterator col=(*mat)[domainIndex].begin(); col!=(*mat)[domainIndex].end(); ++col) {
1519 Impl::asMatrix(*col).mmv((*x)[col.index()], (*rhs_)[i]);
1525 template<
class M,
class X,
class Y>
1526 void OverlappingAssignerILUBase<M,X,Y>::relaxResult(field_type relax)
1531 template<
class M,
class X,
class Y>
1532 void OverlappingAssignerILUBase<M,X,Y>::assignResult(block_type& res)
1537 template<
class M,
class X,
class Y>
1538 X& OverlappingAssignerILUBase<M,X,Y>::lhs()
1543 template<
class M,
class X,
class Y>
1544 Y& OverlappingAssignerILUBase<M,X,Y>::rhs()
1549 template<
class M,
class X,
class Y>
1550 void OverlappingAssignerILUBase<M,X,Y>::resetIndexForNextDomain()
1555 template<
typename S,
typename T,
typename A>
1558 OverlappingAssigner<S>& assigner_,
1559 const field_type& relax_)
1560 : v(&v_), x(&x_), assigner(&assigner_), relax(relax_)
1563 template<
typename S,
typename T,
typename A>
1564 void AdditiveAdder<S,BlockVector<T,A> >::operator()(
const size_type& domainIndex)
1567 assigner->assignResult((*v)[domainIndex]);
1571 template<
typename S,
typename T,
typename A>
1572 void AdditiveAdder<S,BlockVector<T,A> >::axpy()
1579 template<
typename S,
typename T,
typename A>
1580 MultiplicativeAdder<S,BlockVector<T,A> >
1581 ::MultiplicativeAdder(BlockVector<T,A>& v_,
1582 BlockVector<T,A>& x_,
1583 OverlappingAssigner<S>& assigner_,
const field_type& relax_)
1584 : x(&x_), assigner(&assigner_), relax(relax_)
1590 template<
typename S,
typename T,
typename A>
1591 void MultiplicativeAdder<S,BlockVector<T,A> >::operator()(
const size_type& domainIndex)
1594 assigner->relaxResult(relax);
1595 assigner->assignResult((*x)[domainIndex]);
1599 template<
typename S,
typename T,
typename A>
1600 void MultiplicativeAdder<S,BlockVector<T,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:426
row_type::ConstIterator ConstColIterator
Const iterator to the entries of a row.
Definition: bcrsmatrix.hh:700
Iterator begin()
begin iterator
Definition: densevector.hh:348
Iterator end()
end iterator
Definition: densevector.hh:354
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:374
Exact subdomain solver using Dune::DynamicMatrix<T>::solve.
Definition: overlappingschwarz.hh:137
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: dynvector.hh:135
Index Set Interface base class.
Definition: indexidset.hh:76
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:44
D subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition: overlappingschwarz.hh:47
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:752
X::field_type field_type
The field type of the preconditioner.
Definition: overlappingschwarz.hh:780
void apply(X &v, const X &d)
Apply one step of the preconditioner to the system A(v)=d.
SLList< size_type, typename std::allocator_traits< TA >::template rebind_alloc< size_type > > subdomain_list
The type for the row to subdomain mapping.
Definition: overlappingschwarz.hh:797
std::vector< slu, typename std::allocator_traits< TA >::template rebind_alloc< slu > > slu_vector
The vector type containing subdomain solvers.
Definition: overlappingschwarz.hh:806
M matrix_type
The type of the matrix to precondition.
Definition: overlappingschwarz.hh:757
TM Mode
The mode (additive or multiplicative) of the Schwarz method.
Definition: overlappingschwarz.hh:775
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:767
std::set< size_type, std::less< size_type >, typename std::allocator_traits< TA >::template rebind_alloc< size_type > > subdomain_type
The type for the subdomain to row index mapping.
Definition: overlappingschwarz.hh:791
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:762
TD slu
The type for the subdomain solver in use.
Definition: overlappingschwarz.hh:803
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: overlappingschwarz.hh:870
virtual void pre(X &x, X &b)
Prepare the preconditioner.
Definition: overlappingschwarz.hh:843
virtual void post(X &x)
Postprocess the preconditioner.
Definition: overlappingschwarz.hh:861
TA allocator
The allocator to use.
Definition: overlappingschwarz.hh:786
std::vector< subdomain_type, typename std::allocator_traits< TA >::template rebind_alloc< subdomain_type > > subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition: overlappingschwarz.hh:794
std::vector< subdomain_list, typename std::allocator_traits< TA >::template rebind_alloc< subdomain_list > > rowtodomain_vector
The vector type containing the row index to subdomain mapping.
Definition: overlappingschwarz.hh:800
matrix_type::size_type size_type
The return type of the size method.
Definition: overlappingschwarz.hh:783
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:46
#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:1234
SeqOverlappingSchwarz(const matrix_type &mat, const subdomain_vector &subDomains, field_type relaxationFactor=1, bool onTheFly_=true)
Construct the overlapping Schwarz method.
Definition: overlappingschwarz.hh:1058
SeqOverlappingSchwarz(const matrix_type &mat, const rowtodomain_vector &rowToDomain, field_type relaxationFactor=1, bool onTheFly_=true)
Definition: overlappingschwarz.hh:1011
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
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:14
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:569
Tag that the tells the Schwarz method to be additive.
Definition: overlappingschwarz.hh:117
Helper template meta program for application of overlapping Schwarz.
Definition: overlappingschwarz.hh:602
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:123
Helper template meta program for application of overlapping Schwarz.
Definition: overlappingschwarz.hh:666
Definition: overlappingschwarz.hh:1105
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:130
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.