3#ifndef DUNE_GALERKIN_HH
4#define DUNE_GALERKIN_HH
71 void insert(
const typename M::size_type& index);
75 std::size_t minRowSize();
77 std::size_t maxRowSize();
79 std::size_t sumRowSize();
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;
97 class BaseGalerkinProduct
108 template<
class M,
class V,
class I,
class O>
110 const I& pinfo,
const O& copy);
115 class GalerkinProduct
116 :
public BaseGalerkinProduct
119 typedef T ParallelInformation;
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>
145 const OverlapVertex<typename G::VertexDescriptor>*
146 buildOverlapVertices(
const G& graph,
const I& pinfo,
149 std::size_t& overlapCount);
154 bool operator()(
const OverlapVertex<A>& o1,
const OverlapVertex<A>& o2)
156 return *o1.aggregate < *o2.aggregate;
162 class GalerkinProduct<SequentialInformation>
163 :
public BaseGalerkinProduct
175 template<
class G,
class V,
class Set>
176 typename G::MutableMatrix* build(G& fineGraph, V& visitedMap,
177 const SequentialInformation& pinfo,
178 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
179 const typename G::Matrix::size_type& size,
183 struct BaseConnectivityConstructor
185 template<
class R,
class G,
class V>
186 static void constructOverlapConnectivity(R& row, G& graph, V& visitedMap,
187 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
188 const OverlapVertex<typename G::VertexDescriptor>*& seed,
189 const OverlapVertex<typename G::VertexDescriptor>* overlapEnd);
194 template<
class R,
class G,
class V>
195 static void constructNonOverlapConnectivity(R& row, G& graph, V& visitedMap,
196 const AggregatesMap<typename G::VertexDescriptor>& aggregates,
197 const typename G::VertexDescriptor& seed);
203 template<
class G,
class S,
class V>
229 typedef typename Graph::VertexDescriptor
Vertex;
268 template<
class G,
class T>
269 struct ConnectivityConstructor :
public BaseConnectivityConstructor
271 typedef typename G::VertexDescriptor Vertex;
273 template<
class V,
class O,
class R>
274 static void examine(G& graph,
279 const OverlapVertex<Vertex>* overlapVertices,
280 const OverlapVertex<Vertex>* overlapEnd,
285 struct ConnectivityConstructor<G,SequentialInformation> :
public BaseConnectivityConstructor
287 typedef typename G::VertexDescriptor Vertex;
289 template<
class V,
class R>
290 static void examine(G& graph,
292 const SequentialInformation& pinfo,
293 const AggregatesMap<Vertex>& aggregates,
298 struct DirichletBoundarySetter
300 template<
class M,
class O>
301 static void set(M& coarse,
const T& pinfo,
const O& copy);
305 struct DirichletBoundarySetter<SequentialInformation>
307 template<
class M,
class O>
308 static void set(M& coarse,
const SequentialInformation& pinfo,
const O& copy);
311 template<
class R,
class G,
class V>
312 void BaseConnectivityConstructor::constructNonOverlapConnectivity(R& row, G& graph, V& visitedMap,
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;
325 aggregates.template breadthFirstSearch<true,false>(seed,aggregates[seed], graph, vlist, dummy,
326 conBuilder, visitedMap);
329 template<
class R,
class G,
class V>
330 void BaseConnectivityConstructor::constructOverlapConnectivity(R& row, G& graph, V& visitedMap,
332 const OverlapVertex<typename G::VertexDescriptor>*& seed,
333 const OverlapVertex<typename G::VertexDescriptor>* overlapEnd)
335 ConnectedBuilder<G,R,V> conBuilder(aggregates, graph, visitedMap, row);
336 const typename G::VertexDescriptor aggregate=*seed->aggregate;
338 if (row.index()==*seed->aggregate) {
339 while(seed != overlapEnd && aggregate == *seed->aggregate) {
340 row.insert(*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;
364 connected_.insert(
vertex);
368 template<
class G,
class I,
class Set>
369 const OverlapVertex<typename G::VertexDescriptor>*
370 GalerkinProduct<T>::buildOverlapVertices(
const G& graph,
const I& pinfo,
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();
388 if(pair!=0 && overlap.contains(pair->
local().attribute()))
392 typedef typename G::VertexDescriptor Vertex;
394 OverlapVertex<Vertex>* overlapVertices =
new OverlapVertex<Vertex>[overlapCount=0 ? 1 : overlapCount];
396 return overlapVertices;
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>
420 void ConnectivityConstructor<G,T>::examine(G& graph,
423 const AggregatesMap<Vertex>& aggregates,
425 const OverlapVertex<Vertex>* overlapVertices,
426 const OverlapVertex<Vertex>* overlapEnd,
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;
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]);
453 constructNonOverlapConnectivity(row, graph, visitedMap, aggregates, *
vertex);
458 if(overlapVertices != overlapEnd) {
460 constructOverlapConnectivity(row, graph, visitedMap, aggregates, 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]);
485 constructOverlapConnectivity(row, graph, visitedMap, aggregates, overlapVertices, overlapEnd);
493 template<
class V,
class R>
494 void ConnectivityConstructor<G,SequentialInformation>::examine(G& graph,
496 const SequentialInformation& pinfo,
497 const AggregatesMap<Vertex>& aggregates,
501 typedef typename G::VertexIterator VertexIterator;
503 VertexIterator vend=graph.end();
505 if(!get(visitedMap, *
vertex)) {
506 constructNonOverlapConnectivity(row, graph, visitedMap, aggregates, *
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;
529 std::size_t SparsityBuilder<M>::minRowSize()
535 std::size_t SparsityBuilder<M>::sumRowSize()
540 void SparsityBuilder<M>::operator++()
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;
553 void SparsityBuilder<M>::insert(
const typename M::size_type& index)
556#ifdef DUNE_ISTL_WITH_CHECKING
557 diagonalInserted = diagonalInserted || row_.index()==index;
562 template<
class G,
class V,
class Set>
563 typename G::MutableMatrix*
564 GalerkinProduct<T>::build(G& fineGraph, V& visitedMap,
565 const ParallelInformation& pinfo,
567 const typename G::Matrix::size_type& size,
570 typedef OverlapVertex<typename G::VertexDescriptor> OverlapVertex;
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();
592 typedef typename G::MutableMatrix M;
595 ConnectivityConstructor<G,T>::examine(fineGraph, visitedMap, pinfo,
598 overlapVertices+count,
601 dinfo<<pinfo.communicator().rank()<<
": Matrix ("<<coarseMatrix->N()<<
"x"<<coarseMatrix->M()<<
" row: min="<<sparsityBuilder.minRowSize()<<
" max="
602 <<sparsityBuilder.maxRowSize()<<
" avg="
603 <<
static_cast<double>(sparsityBuilder.sumRowSize())/coarseMatrix->N()
606 delete[] overlapVertices;
611 template<
class G,
class V,
class Set>
612 typename G::MutableMatrix*
613 GalerkinProduct<SequentialInformation>::build(G& fineGraph, V& visitedMap,
614 const SequentialInformation& pinfo,
616 const typename G::Matrix::size_type& size,
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();
635 ConnectivityConstructor<G,SequentialInformation>::examine(fineGraph, visitedMap, pinfo,
636 aggregates, sparsityBuilder);
637 dinfo<<
"Matrix row: min="<<sparsityBuilder.minRowSize()<<
" max="
638 <<sparsityBuilder.maxRowSize()<<
" average="
639 <<
static_cast<double>(sparsityBuilder.sumRowSize())/coarseMatrix->N()<<std::endl;
643 template<
class M,
class V,
class P,
class O>
644 void BaseGalerkinProduct::calculate(
const M& fine,
const AggregatesMap<V>& aggregates, M& coarse,
645 const P& pinfo,
const O& 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>
685 void DirichletBoundarySetter<T>::set(M& coarse,
const T& pinfo,
const O& copy)
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>
717 void DirichletBoundarySetter<SequentialInformation>::set(M& coarse,
718 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:556
Visitor for identifying connected aggregates during a breadthFirstSearch.
Definition: galerkin.hh:205
Functor for building the sparsity pattern of the matrix using examineConnectivity.
Definition: galerkin.hh:62
A pair consisting of a global and local index.
Definition: indexset.hh:84
A single linked list.
Definition: sllist.hh:42
Classes for building sets out of enumeration values.
LocalIndex & local()
Get the local index.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:797
G Graph
The type of the graph.
Definition: galerkin.hh:210
void operator()(const ConstEdgeIterator &edge)
Process an edge pointing to another aggregate.
Definition: galerkin.hh:358
T Aggregate
The aggregate descriptor.
Definition: galerkin.hh:36
SparsityBuilder(M &matrix)
Constructor.
Definition: galerkin.hh:514
ConnectedBuilder(const AggregatesMap< Vertex > &aggregates, Graph &graph, VisitedMap &visitedMap, Set &connected)
Constructor.
Definition: galerkin.hh:351
Graph::ConstEdgeIterator ConstEdgeIterator
The constant edge iterator.
Definition: galerkin.hh:214
T Vertex
The vertex descriptor.
Definition: galerkin.hh:41
V VisitedMap
The type of the map for marking vertices as visited.
Definition: galerkin.hh:224
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:567
S Set
The type of the connected set.
Definition: galerkin.hh:219
Aggregate * aggregate
The aggregate the vertex belongs to.
Definition: galerkin.hh:46
Vertex vertex
The vertex descriptor.
Definition: galerkin.hh:51
Graph::VertexDescriptor Vertex
The vertex descriptor of the graph.
Definition: galerkin.hh:229
void calculate(const M &fine, const AggregatesMap< V > &aggregates, M &coarse, const I &pinfo, const O ©)
Calculate the galerkin product.
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
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
DInfoType dinfo(std::cout)
Stream for informative output.
Definition: stdstreams.hh:138
DVerbType dverb(std::cout)
Singleton of verbose debug stream.
Definition: stdstreams.hh:114
Dune namespace.
Definition: alignedallocator.hh:14
An stl-compliant pool allocator.
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
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:32
Definition of the DUNE_UNUSED macro for the case that config.h is not available.