5#ifndef DUNE_GALERKIN_HH
6#define DUNE_GALERKIN_HH
10#include <dune/common/poolallocator.hh>
11#include <dune/common/enumset.hh>
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;
109 template<
class M,
class V,
class I,
class O>
111 const I& pinfo,
const O& copy);
131 template<
class G,
class V,
class Set>
132 typename G::MutableMatrix*
build(G& fineGraph, V& visitedMap,
135 const typename G::Matrix::size_type& size,
145 template<
class G,
class I,
class Set>
147 buildOverlapVertices(
const G& graph,
const I& pinfo,
150 std::size_t& overlapCount);
176 template<
class G,
class V,
class Set>
177 typename G::MutableMatrix*
build(G& fineGraph, V& visitedMap,
180 const typename G::Matrix::size_type& size,
186 template<
class R,
class G,
class V>
195 template<
class R,
class G,
class V>
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>
272 typedef typename G::VertexDescriptor
Vertex;
274 template<
class V,
class O,
class R>
288 typedef typename G::VertexDescriptor
Vertex;
290 template<
class V,
class R>
301 template<
class M,
class O>
302 static void set(M& coarse,
const T& pinfo,
const O& copy);
308 template<
class M,
class O>
312 template<
class R,
class G,
class V>
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;
322 typedef SLList<Vertex,Allocator> VertexList;
326 aggregates.template breadthFirstSearch<true,false>(seed,aggregates[seed], graph, vlist, dummy,
327 conBuilder, visitedMap);
330 template<
class R,
class G,
class V>
337 const typename G::VertexDescriptor aggregate=*seed->
aggregate;
340 while(seed != overlapEnd && aggregate == *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 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 typedef typename G::VertexIterator VertexIterator;
502 VertexIterator vend=graph.end();
503 for(VertexIterator vertex = graph.begin(); vertex != vend; ++vertex) {
504 if(!
get(visitedMap, *vertex)) {
514 : row_(matrix.createbegin()),
515 minRowSize_(
std::numeric_limits<
std::size_t>::max()),
516 maxRowSize_(0), sumRowSize_(0)
518#ifdef DUNE_ISTL_WITH_CHECKING
519 diagonalInserted =
false;
541 sumRowSize_ += row_.size();
542 minRowSize_=std::min(minRowSize_, row_.size());
543 maxRowSize_=std::max(maxRowSize_, row_.size());
545#ifdef DUNE_ISTL_WITH_CHECKING
546 assert(diagonalInserted);
547 diagonalInserted =
false;
555#ifdef DUNE_ISTL_WITH_CHECKING
556 diagonalInserted = diagonalInserted || row_.index()==index;
561 template<
class G,
class V,
class Set>
562 typename G::MutableMatrix*
566 const typename G::Matrix::size_type& size,
573 const OverlapVertex* overlapVertices = buildOverlapVertices(fineGraph,
578 typedef typename G::MutableMatrix M;
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) {
591 typedef typename G::MutableMatrix M;
597 overlapVertices+count,
600 dinfo<<pinfo.communicator().rank()<<
": Matrix ("<<coarseMatrix->N()<<
"x"<<coarseMatrix->M()<<
" row: min="<<sparsityBuilder.
minRowSize()<<
" max="
602 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()
605 delete[] overlapVertices;
610 template<
class G,
class V,
class Set>
611 typename G::MutableMatrix*
615 const typename G::Matrix::size_type& size,
616 [[maybe_unused]]
const Set& overlap)
618 typedef typename G::MutableMatrix M;
619 M* coarseMatrix =
new M(size, size, M::row_wise);
624 typedef typename G::VertexIterator Vertex;
625 Vertex vend = fineGraph.end();
626 for(Vertex vertex = fineGraph.begin(); vertex != vend; ++vertex) {
634 aggregates, sparsityBuilder);
635 dinfo<<
"Matrix row: min="<<sparsityBuilder.
minRowSize()<<
" max="
637 <<
static_cast<double>(sparsityBuilder.
sumRowSize())/coarseMatrix->N()<<std::endl;
641 template<
class M,
class V,
class P,
class O>
643 const P& pinfo, [[maybe_unused]]
const O& copy)
645 coarse =
static_cast<typename M::field_type
>(0);
647 typedef typename M::ConstIterator RowIterator;
648 RowIterator endRow = fine.end();
650 for(RowIterator row = fine.begin(); row != endRow; ++row)
653 typedef typename M::ConstColIterator ColIterator;
654 ColIterator endCol = row->end();
656 for(ColIterator
col = row->begin();
col != endCol; ++
col)
659 coarse[aggregates[row.index()]][aggregates[
col.index()]]+=*
col;
664 typedef typename M::block_type BlockType;
665 std::vector<BlockType> rowsize(coarse.N(),BlockType(0));
666 for (RowIterator row = coarse.begin(); row != coarse.end(); ++row)
667 rowsize[row.index()]=coarse[row.index()][row.index()];
668 pinfo.copyOwnerToAll(rowsize,rowsize);
669 for (RowIterator row = coarse.begin(); row != coarse.end(); ++row)
670 coarse[row.index()][row.index()] = rowsize[row.index()];
681 template<
class M,
class O>
684 typedef typename T::ParallelIndexSet::const_iterator ConstIterator;
685 ConstIterator end = pinfo.indexSet().end();
686 typedef typename M::block_type Block;
687 Block identity=Block(0.0);
688 for(
typename Block::RowIterator b=identity.begin(); b != identity.end(); ++b)
689 b->operator[](b.index())=1.0;
691 for(ConstIterator index = pinfo.indexSet().begin();
692 index != end; ++index) {
693 if(copy.contains(index->local().attribute())) {
694 typedef typename M::ColIterator ColIterator;
695 typedef typename M::row_type Row;
696 Row row = coarse[index->local()];
697 ColIterator cend = row.find(index->local());
698 ColIterator
col = row.begin();
713 template<
class M,
class O>
Provides classes for the Coloring process of AMG.
Col col
Definition: matrixmatrix.hh:351
bool operator()(const OverlapVertex< A > &o1, const OverlapVertex< A > &o2)
Definition: galerkin.hh:155
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:313
G Graph
The type of the graph.
Definition: galerkin.hh:211
void operator++()
Definition: galerkin.hh:539
void operator()(const ConstEdgeIterator &edge)
Process an edge pointing to another aggregate.
Definition: galerkin.hh:359
void insert(const typename M::size_type &index)
Definition: galerkin.hh:552
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:331
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:563
std::size_t index()
Definition: galerkin.hh:81
T ParallelInformation
Definition: galerkin.hh:120
G::VertexDescriptor Vertex
Definition: galerkin.hh:272
T Aggregate
The aggregate descriptor.
Definition: galerkin.hh:37
SparsityBuilder(M &matrix)
Constructor.
Definition: galerkin.hh:513
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
G::VertexDescriptor Vertex
Definition: galerkin.hh:288
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
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.
S Set
The type of the connected set.
Definition: galerkin.hh:220
Aggregate * aggregate
The aggregate the vertex belongs to.
Definition: galerkin.hh:47
std::size_t sumRowSize()
Definition: galerkin.hh:534
Vertex vertex
The vertex descriptor.
Definition: galerkin.hh:52
std::size_t minRowSize()
Definition: galerkin.hh:528
static void set(M &coarse, const T &pinfo, const O ©)
Definition: galerkin.hh:682
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.
std::size_t maxRowSize()
Definition: galerkin.hh:523
Definition: allocator.hh:11
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get(const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition: dependency.hh:293
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:560
Definition: galerkin.hh:33
Functor for building the sparsity pattern of the matrix using examineConnectivity.
Definition: galerkin.hh:63
Definition: galerkin.hh:99
Definition: galerkin.hh:118
Definition: galerkin.hh:185
Visitor for identifying connected aggregates during a breadthFirstSearch.
Definition: galerkin.hh:206
Definition: galerkin.hh:271
Definition: galerkin.hh:300
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:27
static Category category(const OP &op, decltype(op.category()) *=nullptr)
Helperfunction to extract the solver category either from an enum, or from the newly introduced virtu...
Definition: solvercategory.hh:34