26#ifndef DUMUX_SCOTCH_BACKEND_HH
27#define DUMUX_SCOTCH_BACKEND_HH
33#include <dune/common/exceptions.hh>
45#warning "PTSCOTCH was not found on your system. Dumux::ScotchBackend won't do anything."
56template<
class IndexType =
int>
61 using Graph = std::vector<std::vector<IndexType>>;
63 ScotchGraph(
const Graph& graph)
66 const SCOTCH_Num numNodes = graph.size();
70 vertTab_.reserve(numNodes + 1);
71 edgeTab_.reserve(20*numNodes);
76 SCOTCH_Num numEdges = 0;
77 vertTab_.push_back(0);
78 for (
auto vertex = graph.begin(); vertex != graph.end(); ++vertex)
80 numEdges +=
vertex->size();
81 vertTab_.push_back(vertTab_.back() +
vertex->size());
82 edgeTab_.insert(edgeTab_.end(),
vertex->begin(),
vertex->end());
86 vertTab_.shrink_to_fit();
87 edgeTab_.shrink_to_fit();
89 if (SCOTCH_graphInit(&scotchGraph_) != 0)
90 DUNE_THROW(Dune::Exception,
"Error initializing SCOTCH graph!");
93 if (SCOTCH_graphCheck(&scotchGraph_) != 0)
94 DUNE_THROW(Dune::Exception,
"Error within SCOTCH graph's consistency!");
97 const SCOTCH_Num baseValue = 0;
98 if (SCOTCH_graphBuild(&scotchGraph_, baseValue, numNodes, vertTab_.data(), vertTab_.data()+1, NULL, NULL, numEdges, edgeTab_.data(), NULL))
99 DUNE_THROW(Dune::Exception,
"Error building SCOTCH graph!");
105 SCOTCH_graphExit(&scotchGraph_);
110 {
return &scotchGraph_; }
113 SCOTCH_Graph scotchGraph_;
115 std::vector<SCOTCH_Num> vertTab_;
116 std::vector<SCOTCH_Num> edgeTab_;
123class ScotchGraphOrderStrategy
126 ScotchGraphOrderStrategy(
const std::string& strategy =
"")
128 if (SCOTCH_stratInit(&strategy_) != 0)
129 DUNE_THROW(Dune::Exception,
"Error initializing SCOTCH strategy!");
132 if (!strategy.empty())
133 SCOTCH_stratGraphOrder(&strategy_, strategy.c_str());
137 ~ScotchGraphOrderStrategy()
139 SCOTCH_stratExit(&strategy_);
144 {
return &strategy_; }
147 SCOTCH_Strat strategy_;
157template<
class IndexType>
162 using Graph = std::vector<std::vector<IndexType>>;
167 std::size_t numPasses = 5)
170 std::string strategy =
"g{pass= " + std::to_string(numPasses) +
"}";
176 std::string scotchStrategy =
"")
178 std::vector<int> permutation, inversePermutation;
185 std::vector<int>& permutation,
186 std::vector<int>& inversePermutation,
187 std::string scotchStrategy =
"")
190 ScotchGraph<IndexType> scotchGraph(graph);
191 ScotchGraphOrderStrategy strategy(scotchStrategy);
194 const auto graphSize = graph.size();
195 std::vector<SCOTCH_Num> permutationIndices(graphSize);
196 std::vector<SCOTCH_Num> inversePermutationIndices(graphSize);
199 SCOTCH_randomReset();
202 if (SCOTCH_graphOrder(
203 scotchGraph.data(), strategy.data(), permutationIndices.data(),
204 inversePermutationIndices.data(), NULL, NULL, NULL
206 DUNE_THROW(Dune::Exception,
"Error reordering SCOTCH graph!");
209 permutation.resize(graphSize);
210 inversePermutation.resize(graphSize);
211 std::copy(permutationIndices.begin(), permutationIndices.end(),
212 permutation.begin());
213 std::copy(inversePermutationIndices.begin(), inversePermutationIndices.end(),
214 inversePermutation.begin());
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A reordering backend using the scotch library.
Definition: scotchbackend.hh:159
static std::vector< int > computeReordering(const Graph &graph, std::string scotchStrategy="")
Compute graph re-ordering.
Definition: scotchbackend.hh:175
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchbackend.hh:162
static std::vector< int > computeGPSReordering(const Graph &graph, std::size_t numPasses=5)
Definition: scotchbackend.hh:166
static void computeReordering(const Graph &graph, std::vector< int > &permutation, std::vector< int > &inversePermutation, std::string scotchStrategy="")
Compute graph re-ordering.
Definition: scotchbackend.hh:184