3 #ifndef DUNE_GALERKIN_HH
4 #define DUNE_GALERKIN_HH
8 #include <dune/common/poolallocator.hh>
9 #include <dune/common/enumset.hh>
10 #include <dune/common/unused.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);
130 template<
class G,
class V,
class Set>
131 typename G::MutableMatrix*
build(G& fineGraph, V& visitedMap,
132 const ParallelInformation& pinfo,
134 const typename G::Matrix::size_type& size,
144 template<
class G,
class I,
class Set>
146 buildOverlapVertices(
const G& graph,
const I& pinfo,
149 std::size_t& overlapCount);
175 template<
class G,
class V,
class Set>
176 typename G::MutableMatrix*
build(G& fineGraph, V& visitedMap,
179 const typename G::Matrix::size_type& size,
185 template<
class R,
class G,
class V>
194 template<
class R,
class G,
class V>
197 const typename G::VertexDescriptor& seed);
203 template<
class G,
class S,
class V>
229 typedef typename Graph::VertexDescriptor
Vertex;
239 VisitedMap& visitedMap, Set& connected);
245 void operator()(
const ConstEdgeIterator& edge);
258 VisitedMap& visitedMap_;
268 template<
class G,
class T>
271 typedef typename G::VertexDescriptor
Vertex;
273 template<
class V,
class O,
class R>
287 typedef typename G::VertexDescriptor
Vertex;
289 template<
class V,
class R>
300 template<
class M,
class O>
301 static void set(M& coarse,
const T& pinfo,
const O& copy);
307 template<
class M,
class O>
311 template<
class R,
class G,
class V>
314 const typename G::VertexDescriptor& seed)
316 assert(row.index()==aggregates[seed]);
317 row.insert(aggregates[seed]);
319 typedef typename G::VertexDescriptor Vertex;
320 typedef std::allocator<Vertex> Allocator;
321 typedef SLList<Vertex,Allocator> VertexList;
325 aggregates.template breadthFirstSearch<true,false>(seed,aggregates[seed], graph, vlist, dummy,
326 conBuilder, visitedMap);
329 template<
class R,
class G,
class V>
336 const typename G::VertexDescriptor aggregate=*seed->
aggregate;
339 while(seed != overlapEnd && aggregate == *seed->
aggregate) {
344 put(visitedMap, seed->
vertex,
true);
350 template<
class G,
class S,
class V>
354 : aggregates_(aggregates), graph_(graph), visitedMap_(visitedMap), connected_(connected)
357 template<
class G,
class S,
class V>
360 typedef typename G::VertexDescriptor
Vertex;
361 const Vertex& vertex = aggregates_[edge.target()];
364 connected_.insert(vertex);
368 template<
class G,
class I,
class Set>
373 std::size_t& overlapCount)
376 typedef typename G::ConstVertexIterator ConstIterator;
377 typedef typename I::GlobalLookupIndexSet GlobalLookup;
378 typedef typename GlobalLookup::IndexPair IndexPair;
380 const ConstIterator end = graph.end();
383 const GlobalLookup& lookup=pinfo.globalLookup();
385 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex) {
386 const IndexPair* pair = lookup.pair(*vertex);
388 if(pair!=0 && overlap.contains(pair->local().attribute()))
392 typedef typename G::VertexDescriptor Vertex;
396 return overlapVertices;
400 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex) {
401 const IndexPair* pair = lookup.pair(*vertex);
403 if(pair!=0 && overlap.contains(pair->local().attribute())) {
404 overlapVertices[overlapCount].
aggregate = &aggregates[pair->local()];
405 overlapVertices[overlapCount].
vertex = pair->local();
410 dverb << overlapCount<<
" overlap vertices"<<std::endl;
412 std::sort(overlapVertices, overlapVertices+overlapCount, OVLess<Vertex>());
415 return overlapVertices;
418 template<
class G,
class T>
419 template<
class V,
class O,
class R>
429 typedef typename T::GlobalLookupIndexSet GlobalLookup;
430 const GlobalLookup& lookup = pinfo.globalLookup();
432 typedef typename G::VertexIterator VertexIterator;
434 VertexIterator vend=graph.end();
436 #ifdef DUNE_ISTL_WITH_CHECKING
437 std::set<Vertex> examined;
443 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex)
444 if(!
get(visitedMap, *vertex)) {
446 typedef typename GlobalLookup::IndexPair IndexPair;
447 const IndexPair* pair = lookup.pair(*vertex);
448 if(pair==0 || !overlap.contains(pair->local().attribute())) {
449 #ifdef DUNE_ISTL_WITH_CHECKING
450 assert(examined.find(aggregates[*vertex])==examined.end());
451 examined.insert(aggregates[*vertex]);
458 if(overlapVertices != overlapEnd) {
471 dvverb<<
"constructed "<<row.index()<<
" non-overlapping rows"<<std::endl;
475 while(overlapVertices != overlapEnd)
478 #ifdef DUNE_ISTL_WITH_CHECKING
479 typedef typename GlobalLookup::IndexPair IndexPair;
480 const IndexPair* pair = lookup.pair(overlapVertices->
vertex);
481 assert(pair!=0 && overlap.contains(pair->local().attribute()));
482 assert(examined.find(aggregates[overlapVertices->
vertex])==examined.end());
483 examined.insert(aggregates[overlapVertices->
vertex]);
493 template<
class V,
class R>
500 DUNE_UNUSED_PARAMETER(pinfo);
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 G,
class V,
class Set>
563 typename G::MutableMatrix*
567 const typename G::Matrix::size_type& size,
574 const OverlapVertex* overlapVertices = buildOverlapVertices(fineGraph,
579 typedef typename G::MutableMatrix M;
580 M* coarseMatrix =
new M(size, size, M::row_wise);
585 typedef typename G::VertexIterator Vertex;
586 Vertex vend = fineGraph.end();
587 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex) {
592 typedef typename G::MutableMatrix M;
598 overlapVertices+count,
601 dinfo<<pinfo.communicator().rank()<<
": Matrix ("<<coarseMatrix->N()<<
"x"<<coarseMatrix->M()<<
" row: min="<<sparsityBuilder.
minRowSize()<<
" max="
603 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()
606 delete[] overlapVertices;
611 template<
class G,
class V,
class Set>
612 typename G::MutableMatrix*
616 const typename G::Matrix::size_type& size,
619 DUNE_UNUSED_PARAMETER(overlap);
620 typedef typename G::MutableMatrix M;
621 M* coarseMatrix =
new M(size, size, M::row_wise);
626 typedef typename G::VertexIterator Vertex;
627 Vertex vend = fineGraph.end();
628 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex) {
636 aggregates, sparsityBuilder);
637 dinfo<<
"Matrix row: min="<<sparsityBuilder.
minRowSize()<<
" max="
639 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()<<std::endl;
643 template<
class M,
class V,
class P,
class O>
645 const P& pinfo,
const O& copy)
647 DUNE_UNUSED_PARAMETER(copy);
648 coarse =
static_cast<typename M::field_type
>(0);
650 typedef typename M::ConstIterator RowIterator;
651 RowIterator endRow = fine.end();
653 for(RowIterator
row = fine.begin();
row != endRow; ++
row)
656 typedef typename M::ConstColIterator ColIterator;
657 ColIterator endCol =
row->end();
659 for(ColIterator
col =
row->begin();
col != endCol; ++
col)
662 coarse[aggregates[
row.index()]][aggregates[
col.index()]]+=*
col;
667 typedef typename M::block_type BlockType;
668 std::vector<BlockType> rowsize(coarse.N(),BlockType(0));
669 for (RowIterator
row = coarse.begin();
row != coarse.end(); ++
row)
670 rowsize[
row.index()]=coarse[
row.index()][
row.index()];
671 pinfo.copyOwnerToAll(rowsize,rowsize);
672 for (RowIterator
row = coarse.begin();
row != coarse.end(); ++
row)
673 coarse[
row.index()][
row.index()] = rowsize[
row.index()];
684 template<
class M,
class O>
687 typedef typename T::ParallelIndexSet::const_iterator ConstIterator;
688 ConstIterator end = pinfo.indexSet().end();
689 typedef typename M::block_type Block;
690 Block identity=Block(0.0);
691 for(
typename Block::RowIterator b=identity.begin(); b != identity.end(); ++b)
692 b->operator[](b.index())=1.0;
694 for(ConstIterator index = pinfo.indexSet().begin();
695 index != end; ++index) {
696 if(copy.contains(index->local().attribute())) {
697 typedef typename M::ColIterator ColIterator;
698 typedef typename M::row_type Row;
699 Row
row = coarse[index->local()];
700 ColIterator cend = row.find(index->local());
701 ColIterator
col = row.begin();
702 for(; col != cend; ++
col)
710 for(++col; col != cend; ++
col)
716 template<
class M,
class O>
Definition: galerkin.hh:115
std::size_t index()
Definition: galerkin.hh:80
Vertex vertex
The vertex descriptor.
Definition: galerkin.hh:51
static void examine(G &graph, V &visitedMap, const T &pinfo, const AggregatesMap< Vertex > &aggregates, const O &overlap, const OverlapVertex< Vertex > *overlapVertices, const OverlapVertex< Vertex > *overlapEnd, R &row)
Definition: galerkin.hh:420
Row row
Definition: matrixmatrix.hh:345
Graph::VertexDescriptor Vertex
The vertex descriptor of the graph.
Definition: galerkin.hh:229
V VisitedMap
The type of the map for marking vertices as visited.
Definition: galerkin.hh:224
void insert(const typename M::size_type &index)
Definition: galerkin.hh:553
Definition: basearray.hh:19
Graph::ConstEdgeIterator ConstEdgeIterator
The constant edge iterator.
Definition: galerkin.hh:214
Definition: galerkin.hh:269
std::size_t maxRowSize()
Definition: galerkin.hh:524
G::VertexDescriptor Vertex
Definition: galerkin.hh:287
T Aggregate
The aggregate descriptor.
Definition: galerkin.hh:36
Col col
Definition: matrixmatrix.hh:347
Definition: galerkin.hh:97
static void constructOverlapConnectivity(R &row, G &graph, V &visitedMap, const AggregatesMap< typename G::VertexDescriptor > &aggregates, const OverlapVertex< typename G::VertexDescriptor > *&seed, const OverlapVertex< typename G::VertexDescriptor > *overlapEnd)
Definition: galerkin.hh:330
ConnectedBuilder(const AggregatesMap< Vertex > &aggregates, Graph &graph, VisitedMap &visitedMap, Set &connected)
Constructor.
Definition: galerkin.hh:351
Visitor for identifying connected aggregates during a breadthFirstSearch.
Definition: galerkin.hh:204
Aggregate * aggregate
The aggregate the vertex belongs to.
Definition: galerkin.hh:46
Definition: galerkin.hh:298
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:542
bool operator()(const OverlapVertex< A > &o1, const OverlapVertex< A > &o2)
Definition: galerkin.hh:154
void operator()(const ConstEdgeIterator &edge)
Process an edge pointing to another aggregate.
Definition: galerkin.hh:358
G::MutableMatrix * build(G &fineGraph, V &visitedMap, const ParallelInformation &pinfo, AggregatesMap< typename G::VertexDescriptor > &aggregates, const typename G::Matrix::size_type &size, const Set ©)
Calculates the coarse matrix via a Galerkin product.
Definition: galerkin.hh:564
static void constructNonOverlapConnectivity(R &row, G &graph, V &visitedMap, const AggregatesMap< typename G::VertexDescriptor > &aggregates, const typename G::VertexDescriptor &seed)
Construct the connectivity of an aggregate in the overlap.
Definition: galerkin.hh:312
void operator++()
Definition: galerkin.hh:540
std::size_t count
Definition: matrixmatrix.hh:215
T ParallelInformation
Definition: galerkin.hh:119
Definition: galerkin.hh:31
Category for on overlapping solvers.
Definition: solvercategory.hh:23
Definition: galerkin.hh:183
G Graph
The type of the graph.
Definition: galerkin.hh:210
S Set
The type of the connected set.
Definition: galerkin.hh:219
SparsityBuilder(M &matrix)
Constructor.
Definition: galerkin.hh:514
int visitNeighbours(const G &graph, const typename G::VertexDescriptor &vertex, V &visitor)
Visit all neighbour vertices of a vertex in a graph.
static void set(M &coarse, const T &pinfo, const O ©)
Definition: galerkin.hh:685
Provides classes for the Coloring process of AMG.
T Vertex
The vertex descriptor.
Definition: galerkin.hh:41
std::size_t sumRowSize()
Definition: galerkin.hh:535
G::VertexDescriptor Vertex
Definition: galerkin.hh:271
void calculate(const M &fine, const AggregatesMap< V > &aggregates, M &coarse, const I &pinfo, const O ©)
Calculate the galerkin product.
std::size_t minRowSize()
Definition: galerkin.hh:529
Functor for building the sparsity pattern of the matrix using examineConnectivity.
Definition: galerkin.hh:61