4#ifndef DUNE_GALERKIN_HH
5#define DUNE_GALERKIN_HH
72 void insert(
const typename M::size_type& index);
76 std::size_t minRowSize();
78 std::size_t maxRowSize();
80 std::size_t sumRowSize();
87 typename M::CreateIterator row_;
89 std::size_t minRowSize_;
91 std::size_t maxRowSize_;
92 std::size_t sumRowSize_;
93#ifdef DUNE_ISTL_WITH_CHECKING
94 bool diagonalInserted;
98 class BaseGalerkinProduct
109 template<
class M,
class V,
class I,
class O>
111 const I& pinfo,
const O& copy);
116 class GalerkinProduct
117 :
public BaseGalerkinProduct
120 typedef T ParallelInformation;
131 template<
class G,
class V,
class Set>
132 typename G::MutableMatrix* build(G& fineGraph, V& visitedMap,
133 const ParallelInformation& pinfo,
135 const typename G::Matrix::size_type& size,
145 template<
class G,
class I,
class Set>
146 const OverlapVertex<typename G::VertexDescriptor>*
147 buildOverlapVertices(
const G& graph,
const I& pinfo,
150 std::size_t& overlapCount);
155 bool operator()(
const OverlapVertex<A>& o1,
const OverlapVertex<A>& o2)
157 return *o1.aggregate < *o2.aggregate;
163 class GalerkinProduct<SequentialInformation>
164 :
public BaseGalerkinProduct
176 template<
class G,
class V,
class Set>
177 typename G::MutableMatrix* build(G& fineGraph, V& visitedMap,
178 const SequentialInformation& pinfo,
179 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
180 const typename G::Matrix::size_type& size,
184 struct BaseConnectivityConstructor
186 template<
class R,
class G,
class V>
187 static void constructOverlapConnectivity(R& row, G& graph, V& visitedMap,
188 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
189 const OverlapVertex<typename G::VertexDescriptor>*& seed,
190 const OverlapVertex<typename G::VertexDescriptor>* overlapEnd);
195 template<
class R,
class G,
class V>
196 static void constructNonOverlapConnectivity(R& row, G& graph, V& visitedMap,
197 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
198 const typename G::VertexDescriptor& seed);
204 template<
class G,
class S,
class V>
230 typedef typename Graph::VertexDescriptor
Vertex;
269 template<
class G,
class T>
270 struct ConnectivityConstructor :
public BaseConnectivityConstructor
272 typedef typename G::VertexDescriptor Vertex;
274 template<
class V,
class O,
class R>
275 static void examine(G& graph,
280 const OverlapVertex<Vertex>* overlapVertices,
281 const OverlapVertex<Vertex>* overlapEnd,
286 struct ConnectivityConstructor<G,SequentialInformation> :
public BaseConnectivityConstructor
288 typedef typename G::VertexDescriptor Vertex;
290 template<
class V,
class R>
291 static void examine(G& graph,
293 const SequentialInformation& pinfo,
294 const AggregatesMap<Vertex>& aggregates,
299 struct DirichletBoundarySetter
301 template<
class M,
class O>
302 static void set(M& coarse,
const T& pinfo,
const O& copy);
306 struct DirichletBoundarySetter<SequentialInformation>
308 template<
class M,
class O>
309 static void set(M& coarse,
const SequentialInformation& pinfo,
const O& copy);
312 template<
class R,
class G,
class V>
313 void BaseConnectivityConstructor::constructNonOverlapConnectivity(R& row, G& graph, V& visitedMap,
315 const typename G::VertexDescriptor& seed)
317 assert(row.index()==aggregates[seed]);
318 row.insert(aggregates[seed]);
320 typedef typename G::VertexDescriptor Vertex;
321 typedef std::allocator<Vertex> Allocator;
326 aggregates.template breadthFirstSearch<true,false>(seed,aggregates[seed], graph, vlist, dummy,
327 conBuilder, visitedMap);
330 template<
class R,
class G,
class V>
331 void BaseConnectivityConstructor::constructOverlapConnectivity(R& row, G& graph, V& visitedMap,
333 const OverlapVertex<typename G::VertexDescriptor>*& seed,
334 const OverlapVertex<typename G::VertexDescriptor>* overlapEnd)
336 ConnectedBuilder<G,R,V> conBuilder(aggregates, graph, visitedMap, row);
337 const typename G::VertexDescriptor aggregate=*seed->aggregate;
339 if (row.index()==*seed->aggregate) {
340 while(seed != overlapEnd && aggregate == *seed->aggregate) {
341 row.insert(*seed->aggregate);
345 put(visitedMap, seed->vertex,
true);
351 template<
class G,
class S,
class V>
355 : aggregates_(aggregates), graph_(graph), visitedMap_(visitedMap), connected_(connected)
358 template<
class G,
class S,
class V>
361 typedef typename G::VertexDescriptor
Vertex;
362 const Vertex& vertex = aggregates_[edge.target()];
365 connected_.insert(vertex);
369 template<
class G,
class I,
class Set>
370 const OverlapVertex<typename G::VertexDescriptor>*
371 GalerkinProduct<T>::buildOverlapVertices(
const G& graph,
const I& pinfo,
374 std::size_t& overlapCount)
377 typedef typename G::ConstVertexIterator ConstIterator;
378 typedef typename I::GlobalLookupIndexSet GlobalLookup;
379 typedef typename GlobalLookup::IndexPair
IndexPair;
381 const ConstIterator end = graph.end();
384 const GlobalLookup& lookup=pinfo.globalLookup();
386 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex) {
387 const IndexPair* pair = lookup.pair(*vertex);
389 if(pair!=0 && overlap.contains(pair->
local().attribute()))
393 typedef typename G::VertexDescriptor Vertex;
395 OverlapVertex<Vertex>* overlapVertices =
new OverlapVertex<Vertex>[overlapCount=0 ? 1 : overlapCount];
397 return overlapVertices;
401 for(ConstIterator vertex=graph.begin(); vertex != end; ++vertex) {
402 const IndexPair* pair = lookup.pair(*vertex);
404 if(pair!=0 && overlap.contains(pair->
local().attribute())) {
405 overlapVertices[overlapCount].aggregate = &aggregates[pair->
local()];
406 overlapVertices[overlapCount].vertex = pair->
local();
411 dverb << overlapCount<<
" overlap vertices"<<std::endl;
413 std::sort(overlapVertices, overlapVertices+overlapCount, OVLess<Vertex>());
416 return overlapVertices;
419 template<
class G,
class T>
420 template<
class V,
class O,
class R>
421 void ConnectivityConstructor<G,T>::examine(G& graph,
424 const AggregatesMap<Vertex>& aggregates,
426 const OverlapVertex<Vertex>* overlapVertices,
427 const OverlapVertex<Vertex>* overlapEnd,
430 typedef typename T::GlobalLookupIndexSet GlobalLookup;
431 const GlobalLookup& lookup = pinfo.globalLookup();
433 typedef typename G::VertexIterator VertexIterator;
435 VertexIterator vend=graph.end();
437#ifdef DUNE_ISTL_WITH_CHECKING
438 std::set<Vertex> examined;
444 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex)
445 if(!get(visitedMap, *vertex)) {
447 typedef typename GlobalLookup::IndexPair IndexPair;
448 const IndexPair* pair = lookup.pair(*vertex);
449 if(pair==0 || !overlap.contains(pair->local().attribute())) {
450#ifdef DUNE_ISTL_WITH_CHECKING
451 assert(examined.find(aggregates[*vertex])==examined.end());
452 examined.insert(aggregates[*vertex]);
454 constructNonOverlapConnectivity(row, graph, visitedMap, aggregates, *vertex);
459 if(overlapVertices != overlapEnd) {
461 constructOverlapConnectivity(row, graph, visitedMap, aggregates, 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]);
486 constructOverlapConnectivity(row, graph, visitedMap, aggregates, overlapVertices, overlapEnd);
494 template<
class V,
class R>
495 void ConnectivityConstructor<G,SequentialInformation>::examine(G& graph,
497 const SequentialInformation& pinfo,
498 const AggregatesMap<Vertex>& aggregates,
502 typedef typename G::VertexIterator VertexIterator;
504 VertexIterator vend=graph.end();
505 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex) {
506 if(!get(visitedMap, *vertex)) {
507 constructNonOverlapConnectivity(row, graph, visitedMap, aggregates, *vertex);
516 : row_(matrix.createbegin()),
517 minRowSize_(
std::numeric_limits<
std::size_t>::max()),
518 maxRowSize_(0), sumRowSize_(0)
520#ifdef DUNE_ISTL_WITH_CHECKING
521 diagonalInserted =
false;
530 std::size_t SparsityBuilder<M>::minRowSize()
536 std::size_t SparsityBuilder<M>::sumRowSize()
541 void SparsityBuilder<M>::operator++()
543 sumRowSize_ += row_.size();
544 minRowSize_=std::min(minRowSize_, row_.size());
545 maxRowSize_=std::max(maxRowSize_, row_.size());
547#ifdef DUNE_ISTL_WITH_CHECKING
548 assert(diagonalInserted);
549 diagonalInserted =
false;
554 void SparsityBuilder<M>::insert(
const typename M::size_type& index)
557#ifdef DUNE_ISTL_WITH_CHECKING
558 diagonalInserted = diagonalInserted || row_.index()==index;
563 template<
class G,
class V,
class Set>
564 typename G::MutableMatrix*
565 GalerkinProduct<T>::build(G& fineGraph, V& visitedMap,
566 const ParallelInformation& pinfo,
568 const typename G::Matrix::size_type& size,
571 typedef OverlapVertex<typename G::VertexDescriptor> OverlapVertex;
575 const OverlapVertex* overlapVertices = buildOverlapVertices(fineGraph,
580 typedef typename G::MutableMatrix M;
581 M* coarseMatrix =
new M(size, size, M::row_wise);
586 typedef typename G::VertexIterator Vertex;
587 Vertex vend = fineGraph.end();
588 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex) {
593 typedef typename G::MutableMatrix M;
596 ConnectivityConstructor<G,T>::examine(fineGraph, visitedMap, pinfo,
599 overlapVertices+count,
602 dinfo<<pinfo.communicator().rank()<<
": Matrix ("<<coarseMatrix->N()<<
"x"<<coarseMatrix->M()<<
" row: min="<<sparsityBuilder.minRowSize()<<
" max="
603 <<sparsityBuilder.maxRowSize()<<
" avg="
604 <<
static_cast<double>(sparsityBuilder.sumRowSize())/coarseMatrix->N()
607 delete[] overlapVertices;
612 template<
class G,
class V,
class Set>
613 typename G::MutableMatrix*
614 GalerkinProduct<SequentialInformation>::build(G& fineGraph, V& visitedMap,
615 const SequentialInformation& pinfo,
617 const typename G::Matrix::size_type& size,
621 typedef typename G::MutableMatrix M;
622 M* coarseMatrix =
new M(size, size, M::row_wise);
627 typedef typename G::VertexIterator Vertex;
628 Vertex vend = fineGraph.end();
629 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex) {
636 ConnectivityConstructor<G,SequentialInformation>::examine(fineGraph, visitedMap, pinfo,
637 aggregates, sparsityBuilder);
638 dinfo<<
"Matrix row: min="<<sparsityBuilder.minRowSize()<<
" max="
639 <<sparsityBuilder.maxRowSize()<<
" average="
640 <<
static_cast<double>(sparsityBuilder.sumRowSize())/coarseMatrix->N()<<std::endl;
644 template<
class M,
class V,
class P,
class O>
645 void BaseGalerkinProduct::calculate(
const M& fine,
const AggregatesMap<V>& aggregates, M& coarse,
646 const P& pinfo,
const O& copy)
649 coarse =
static_cast<typename M::field_type
>(0);
651 typedef typename M::ConstIterator RowIterator;
652 RowIterator endRow = fine.end();
654 for(RowIterator row = fine.begin(); row != endRow; ++row)
657 typedef typename M::ConstColIterator ColIterator;
658 ColIterator endCol = row->end();
660 for(ColIterator col = row->begin(); col != endCol; ++col)
663 coarse[aggregates[row.index()]][aggregates[col.index()]]+=*col;
668 typedef typename M::block_type BlockType;
669 std::vector<BlockType> rowsize(coarse.N(),BlockType(0));
670 for (RowIterator row = coarse.begin(); row != coarse.end(); ++row)
671 rowsize[row.index()]=coarse[row.index()][row.index()];
672 pinfo.copyOwnerToAll(rowsize,rowsize);
673 for (RowIterator row = coarse.begin(); row != coarse.end(); ++row)
674 coarse[row.index()][row.index()] = rowsize[row.index()];
685 template<
class M,
class O>
686 void DirichletBoundarySetter<T>::set(M& coarse,
const T& pinfo,
const O& copy)
688 typedef typename T::ParallelIndexSet::const_iterator ConstIterator;
689 ConstIterator end = pinfo.indexSet().end();
690 typedef typename M::block_type Block;
691 Block identity=Block(0.0);
692 for(
typename Block::RowIterator b=identity.begin(); b != identity.end(); ++b)
693 b->operator[](b.index())=1.0;
695 for(ConstIterator index = pinfo.indexSet().begin();
696 index != end; ++index) {
697 if(copy.contains(index->local().attribute())) {
698 typedef typename M::ColIterator ColIterator;
699 typedef typename M::row_type Row;
700 Row row = coarse[index->local()];
701 ColIterator cend = row.find(index->local());
702 ColIterator col = row.begin();
703 for(; col != cend; ++col)
711 for(++col; col != cend; ++col)
717 template<
class M,
class O>
718 void DirichletBoundarySetter<SequentialInformation>::set(M& coarse,
719 const SequentialInformation& pinfo,
Provides classes for the Coloring process of AMG.
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:498
Visitor for identifying connected aggregates during a breadthFirstSearch.
Definition: galerkin.hh:206
Functor for building the sparsity pattern of the matrix using examineConnectivity.
Definition: galerkin.hh:63
A pair consisting of a global and local index.
Definition: indexset.hh:85
A single linked list.
Definition: sllist.hh:43
Classes for building sets out of enumeration values.
LocalIndex & local()
Get the local index.
G Graph
The type of the graph.
Definition: galerkin.hh:211
void operator()(const ConstEdgeIterator &edge)
Process an edge pointing to another aggregate.
Definition: galerkin.hh:359
T Aggregate
The aggregate descriptor.
Definition: galerkin.hh:37
SparsityBuilder(M &matrix)
Constructor.
Definition: galerkin.hh:515
ConnectedBuilder(const AggregatesMap< Vertex > &aggregates, Graph &graph, VisitedMap &visitedMap, Set &connected)
Constructor.
Definition: galerkin.hh:352
Graph::ConstEdgeIterator ConstEdgeIterator
The constant edge iterator.
Definition: galerkin.hh:215
T Vertex
The vertex descriptor.
Definition: galerkin.hh:42
V VisitedMap
The type of the map for marking vertices as visited.
Definition: galerkin.hh:225
int visitNeighbours(const G &graph, const typename G::VertexDescriptor &vertex, V &visitor)
Visit all neighbour vertices of a vertex in a graph.
static const Vertex ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:509
S Set
The type of the connected set.
Definition: galerkin.hh:220
Aggregate * aggregate
The aggregate the vertex belongs to.
Definition: galerkin.hh:47
Vertex vertex
The vertex descriptor.
Definition: galerkin.hh:52
Graph::VertexDescriptor Vertex
The vertex descriptor of the graph.
Definition: galerkin.hh:230
void calculate(const M &fine, const AggregatesMap< V > &aggregates, M &coarse, const I &pinfo, const O ©)
Calculate the galerkin product.
DVVerbType dvverb(std::cout)
stream for very verbose output.
Definition: stdstreams.hh:94
DInfoType dinfo(std::cout)
Stream for informative output.
Definition: stdstreams.hh:139
DVerbType dverb(std::cout)
Singleton of verbose debug stream.
Definition: stdstreams.hh:115
Dune namespace.
Definition: alignment.hh:14
An stl-compliant pool allocator.
@ nonoverlapping
Category for on overlapping solvers.
Definition: solvercategory.hh:24
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18