| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
#ifndef DUNE_AMG_GRAPHCREATOR_HH |
| 6 |
#define DUNE_AMG_GRAPHCREATOR_HH |
| 7 |
|
| 8 |
#include <tuple> |
| 9 |
|
| 10 |
#include "graph.hh" |
| 11 |
#include "dependency.hh" |
| 12 |
#include "pinfo.hh" |
| 13 |
#include <dune/istl/operators.hh> |
| 14 |
#include <dune/istl/bcrsmatrix.hh> |
| 15 |
|
| 16 |
namespace Dune |
| 17 |
{ |
| 18 |
namespace Amg |
| 19 |
{ |
| 20 |
template<class M, class PI> |
| 21 |
struct PropertiesGraphCreator |
| 22 |
{ |
| 23 |
typedef typename M::matrix_type Matrix; |
| 24 |
typedef Dune::Amg::MatrixGraph<const Matrix> MatrixGraph; |
| 25 |
typedef Dune::Amg::SubGraph<MatrixGraph, |
| 26 |
std::vector<bool> > SubGraph; |
| 27 |
typedef Dune::Amg::PropertiesGraph<SubGraph, |
| 28 |
VertexProperties, |
| 29 |
EdgeProperties, |
| 30 |
IdentityMap, |
| 31 |
typename SubGraph::EdgeIndexMap> |
| 32 |
PropertiesGraph; |
| 33 |
|
| 34 |
typedef std::tuple<MatrixGraph*,PropertiesGraph*,SubGraph*> GraphTuple; |
| 35 |
|
| 36 |
template<class OF, class T> |
| 37 |
static GraphTuple create(const M& matrix, T& excluded, |
| 38 |
PI& pinfo, const OF& of) |
| 39 |
{ |
| 40 |
MatrixGraph* mg = new MatrixGraph(matrix.getmat()); |
| 41 |
typedef typename PI::ParallelIndexSet ParallelIndexSet; |
| 42 |
typedef typename ParallelIndexSet::const_iterator IndexIterator; |
| 43 |
IndexIterator iend = pinfo.indexSet().end(); |
| 44 |
|
| 45 |
for(IndexIterator index = pinfo.indexSet().begin(); index != iend; ++index) |
| 46 |
excluded[index->local()] = of.contains(index->local().attribute()); |
| 47 |
|
| 48 |
SubGraph* sg= new SubGraph(*mg, excluded); |
| 49 |
PropertiesGraph* pg = new PropertiesGraph(*sg, IdentityMap(), sg->getEdgeIndexMap()); |
| 50 |
return GraphTuple(mg,pg,sg); |
| 51 |
} |
| 52 |
|
| 53 |
static void free(GraphTuple& graphs) |
| 54 |
{ |
| 55 |
delete std::get<2>(graphs); |
| 56 |
delete std::get<1>(graphs); |
| 57 |
} |
| 58 |
}; |
| 59 |
|
| 60 |
template<class M> |
| 61 |
struct PropertiesGraphCreator<M,SequentialInformation> |
| 62 |
{ |
| 63 |
typedef typename M::matrix_type Matrix; |
| 64 |
|
| 65 |
typedef Dune::Amg::MatrixGraph<const Matrix> MatrixGraph; |
| 66 |
|
| 67 |
typedef Dune::Amg::PropertiesGraph<MatrixGraph, |
| 68 |
VertexProperties, |
| 69 |
EdgeProperties, |
| 70 |
IdentityMap, |
| 71 |
IdentityMap> PropertiesGraph; |
| 72 |
|
| 73 |
typedef std::tuple<MatrixGraph*,PropertiesGraph*> GraphTuple; |
| 74 |
|
| 75 |
template<class OF, class T> |
| 76 |
static GraphTuple create([[maybe_unused]] const M& matrix, |
| 77 |
[[maybe_unused]] T& excluded, |
| 78 |
[[maybe_unused]] const SequentialInformation& pinfo, |
| 79 |
const OF&) |
| 80 |
{ |
| 81 |
MatrixGraph* mg = new MatrixGraph(matrix.getmat()); |
| 82 |
PropertiesGraph* pg = new PropertiesGraph(*mg, IdentityMap(), IdentityMap()); |
| 83 |
return GraphTuple(mg,pg); |
| 84 |
} |
| 85 |
|
| 86 |
static void free(GraphTuple& graphs) |
| 87 |
{ |
| 88 |
delete std::get<1>(graphs); |
| 89 |
} |
| 90 |
|
| 91 |
}; |
| 92 |
|
| 93 |
} //namespace Amg |
| 94 |
} // namespace Dune |
| 95 |
#endif |