4 #ifndef DUNE_GALERKIN_HH
5 #define DUNE_GALERKIN_HH
9 #include<dune/common/poolallocator.hh>
10 #include<dune/common/enumset.hh>
86 typename M::CreateIterator row_;
88 std::size_t minRowSize_;
90 std::size_t maxRowSize_;
91 std::size_t sumRowSize_;
92 #ifdef DUNE_ISTL_WITH_CHECKING
93 bool diagonalInserted;
108 template<
class M,
class V,
class I,
class O>
110 const I& pinfo,
const O& copy);
131 template<
class M,
class G,
class V,
class Set>
132 M*
build(
const M& fine, G& fineGraph, V& visitedMap,
135 const typename M::size_type& size,
145 template<
class G,
class I,
class Set>
147 buildOverlapVertices(
const G& graph,
const I& pinfo,
150 std::size_t& overlapCount);
177 template<
class M,
class G,
class V,
class Set>
178 M*
build(
const M& fine, G& fineGraph, V& visitedMap,
181 const typename M::size_type& size,
187 template<
class R,
class G,
class V>
196 template<
class R,
class G,
class V>
199 const typename G::VertexDescriptor& seed);
205 template<
class G,
class S,
class V>
231 typedef typename Graph::VertexDescriptor
Vertex;
270 template<
class G,
class T>
273 typedef typename G::VertexDescriptor
Vertex;
275 template<
class V,
class O,
class R>
289 typedef typename G::VertexDescriptor
Vertex;
291 template<
class V,
class R>
302 template<
class M,
class O>
303 static void set(M& coarse,
const T& pinfo,
const O& copy);
309 template<
class M,
class O>
313 template<
class R,
class G,
class V>
316 const typename G::VertexDescriptor& seed)
318 assert(row.index()==aggregates[seed]);
319 row.insert(aggregates[seed]);
321 typedef typename G::VertexDescriptor Vertex;
322 typedef std::allocator<Vertex> Allocator;
323 typedef SLList<Vertex,Allocator> VertexList;
327 aggregates.template breadthFirstSearch<true,false>(seed,aggregates[seed], graph, vlist, dummy,
328 conBuilder, visitedMap);
331 template<
class R,
class G,
class V>
338 const typename G::VertexDescriptor aggregate=*seed->
aggregate;
341 while(seed != overlapEnd && aggregate == *seed->
aggregate){
346 put(visitedMap, seed->
vertex,
true);
352 template<
class G,
class S,
class V>
356 : aggregates_(aggregates), graph_(graph), visitedMap_(visitedMap), connected_(connected)
359 template<
class G,
class S,
class V>
362 typedef typename G::VertexDescriptor
Vertex;
363 const Vertex& vertex = aggregates_[edge.target()];
366 connected_.insert(vertex);
370 template<
class G,
class I,
class Set>
375 std::size_t& overlapCount)
378 typedef typename G::ConstVertexIterator ConstIterator;
379 typedef typename I::GlobalLookupIndexSet GlobalLookup;
380 typedef typename GlobalLookup::IndexPair IndexPair;
382 const ConstIterator end = graph.end();
385 const GlobalLookup& lookup=pinfo.globalLookup();
387 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex){
388 const IndexPair* pair = lookup.pair(*vertex);
390 if(pair!=0 && overlap.contains(pair->local().attribute()))
394 typedef typename G::VertexDescriptor Vertex;
398 return overlapVertices;
402 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex){
403 const IndexPair* pair = lookup.pair(*vertex);
405 if(pair!=0 && overlap.contains(pair->local().attribute())){
406 overlapVertices[overlapCount].
aggregate = &aggregates[pair->local()];
407 overlapVertices[overlapCount].
vertex = pair->local();
412 dverb << overlapCount<<
" overlap vertices"<<std::endl;
414 std::sort(overlapVertices, overlapVertices+overlapCount, OVLess<Vertex>());
417 return overlapVertices;
420 template<
class G,
class T>
421 template<
class V,
class O,
class R>
431 typedef typename T::GlobalLookupIndexSet GlobalLookup;
432 const GlobalLookup& lookup = pinfo.globalLookup();
434 typedef typename G::VertexIterator VertexIterator;
436 VertexIterator vend=graph.end();
438 #ifdef DUNE_ISTL_WITH_CHECKING
439 std::set<Vertex> examined;
445 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex)
446 if(!
get(visitedMap, *vertex)){
448 typedef typename GlobalLookup::IndexPair IndexPair;
449 const IndexPair* pair = lookup.pair(*vertex);
450 if(pair==0 || !overlap.contains(pair->local().attribute())){
451 #ifdef DUNE_ISTL_WITH_CHECKING
452 assert(examined.find(aggregates[*vertex])==examined.end());
453 examined.insert(aggregates[*vertex]);
460 if(overlapVertices != overlapEnd){
472 dvverb<<
"constructed "<<row.index()<<
" non-overlapping rows"<<std::endl;
476 while(overlapVertices != overlapEnd)
479 #ifdef DUNE_ISTL_WITH_CHECKING
480 typedef typename GlobalLookup::IndexPair IndexPair;
481 const IndexPair* pair = lookup.pair(overlapVertices->
vertex);
482 assert(pair!=0 && overlap.contains(pair->local().attribute()));
483 assert(examined.find(aggregates[overlapVertices->
vertex])==examined.end());
484 examined.insert(aggregates[overlapVertices->
vertex]);
494 template<
class V,
class R>
501 typedef typename G::VertexIterator VertexIterator;
503 VertexIterator vend=graph.end();
504 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex){
505 if(!
get(visitedMap, *vertex)){
515 : row_(matrix.createbegin()),
516 minRowSize_(std::numeric_limits<std::size_t>::max()),
517 maxRowSize_(0), sumRowSize_(0)
519 #ifdef DUNE_ISTL_WITH_CHECKING
520 diagonalInserted =
false;
542 sumRowSize_ += row_.size();
543 minRowSize_=std::min(minRowSize_, row_.size());
544 maxRowSize_=std::max(maxRowSize_, row_.size());
546 #ifdef DUNE_ISTL_WITH_CHECKING
547 assert(diagonalInserted);
548 diagonalInserted =
false;
556 #ifdef DUNE_ISTL_WITH_CHECKING
557 diagonalInserted = diagonalInserted || row_.index()==
index;
562 template<
class M,
class G,
class V,
class Set>
566 const typename M::size_type& size,
574 const OverlapVertex* overlapVertices = buildOverlapVertices(fineGraph,
579 M* coarseMatrix =
new M(size, size, M::row_wise);
584 typedef typename G::VertexIterator Vertex;
585 Vertex vend = fineGraph.end();
586 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex){
596 overlapVertices+count,
599 dinfo<<pinfo.communicator().rank()<<
": Matrix ("<<coarseMatrix->N()<<
"x"<<coarseMatrix->M()<<
" row: min="<<sparsityBuilder.
minRowSize()<<
" max="
601 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()
604 delete[] overlapVertices;
611 template<
class M,
class G,
class V,
class Set>
615 const typename M::size_type& size,
618 M* coarseMatrix =
new M(size, size, M::row_wise);
623 typedef typename G::VertexIterator Vertex;
624 Vertex vend = fineGraph.end();
625 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex){
633 aggregates, sparsityBuilder);
634 dinfo<<
"Matrix row: min="<<sparsityBuilder.
minRowSize()<<
" max="
636 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()<<std::endl;
640 template<
class M,
class V,
class P,
class O>
642 const P& pinfo,
const O& copy)
644 coarse =
static_cast<typename M::field_type
>(0);
646 typedef typename M::ConstIterator RowIterator;
647 RowIterator endRow = fine.end();
649 for(RowIterator
row = fine.begin();
row != endRow; ++
row)
652 typedef typename M::ConstColIterator ColIterator;
653 ColIterator endCol =
row->end();
655 for(ColIterator
col =
row->begin();
col != endCol; ++
col)
658 coarse[aggregates[
row.index()]][aggregates[
col.index()]]+=*
col;
663 typedef typename M::block_type BlockType;
664 std::vector<BlockType> rowsize(coarse.N(),BlockType(0));
665 for (RowIterator
row = coarse.begin();
row != coarse.end(); ++
row)
666 rowsize[
row.index()]=coarse[
row.index()][
row.index()];
667 pinfo.copyOwnerToAll(rowsize,rowsize);
668 for (RowIterator
row = coarse.begin();
row != coarse.end(); ++
row)
669 coarse[
row.index()][
row.index()] = rowsize[
row.index()];
680 template<
class M,
class O>
683 typedef typename T::ParallelIndexSet::const_iterator ConstIterator;
684 ConstIterator end = pinfo.indexSet().end();
685 typedef typename M::block_type Block;
686 Block identity=Block(0.0);
687 for(
typename Block::RowIterator b=identity.begin(); b != identity.end(); ++b)
688 b->operator[](b.index())=1.0;
690 for(ConstIterator
index = pinfo.indexSet().begin();
692 if(copy.contains(
index->local().attribute())){
693 typedef typename M::ColIterator ColIterator;
694 typedef typename M::row_type Row;
696 ColIterator cend = row.find(
index->local());
697 ColIterator
col = row.begin();
698 for(; col != cend; ++
col)
706 for(++col; col != cend; ++
col)
712 template<
class M,
class O>