12 #include <boost/graph/properties.hpp> 13 #include <boost/graph/compressed_sparse_row_graph.hpp> 19 static LoggerPtr logger(Logger::getLogger(
"pz.external.boostgraph"));
22 using namespace boost;
25 TPZBoostGraph::TPZBoostGraph(int64_t NElements, int64_t NNodes) :
TPZRenumbering(NElements,NNodes),fGType(Sloan)
31 TPZBoostGraph::~TPZBoostGraph()
37 void TPZBoostGraph::ClearDataStructures()
48 if (this->fNNodes == 0)
55 typedef boost::compressed_sparse_row_graph<boost::directedS> BoostGraph;
62 NodeToElGraph(fElementGraph,fElementGraphIndex,nodtoelgraph,nodtoelgraphindex);
64 std::vector<std::pair<std::size_t, std::size_t> > edges;
66 size_t maxsize = 100000;
68 edges.reserve(1000000);
70 for(nod=0; nod<fNNodes; nod++)
72 int64_t firstel = nodtoelgraphindex[nod];
73 int64_t lastel = nodtoelgraphindex[nod+1];
74 std::set<int64_t> nodecon;
75 for(el=firstel; el<lastel; el++)
77 int64_t gel = nodtoelgraph[el];
78 int64_t firstelnode = fElementGraphIndex[gel];
79 int64_t lastelnode = fElementGraphIndex[gel+1];
80 nodecon.insert(&fElementGraph[firstelnode],&fElementGraph[(lastelnode-1)]+1);
84 std::set<int64_t>::iterator it;
85 for(it = nodecon.begin(); it!= nodecon.end(); it++)
87 edges.push_back(std::make_pair(nod, *it));
88 edges.push_back(std::make_pair(*it, nod));
89 if (edges.size() > (edges.size()+maxsize*resize_times)) {
90 edges.reserve(edges.size()+maxsize*(++resize_times));
95 BoostGraph G(boost::edges_are_unsorted_multi_pass, edges.begin(), edges.end(), fNNodes);
97 boost::property_map<BoostGraph, boost::vertex_index_t>::type boost_index_map;
98 boost_index_map =
get(boost::vertex_index, G);
101 std::vector<std::size_t> inv_perm(fNNodes);
103 boost::cuthill_mckee_ordering(G, inv_perm.begin());
106 inverseperm.
Resize(fNNodes);
108 for (std::size_t i = 0; i < fNNodes; ++i)
110 perm[inv_perm[i]] = i;
111 inverseperm[i]=inv_perm[i];
118 if (logger->isDebugEnabled())
120 std::stringstream sout;
121 sout <<
"TPZBoostGraph::Resequence started \n";
122 Print(fElementGraph,fElementGraphIndex,
"Element graph when entering Resequence",sout);
123 LOG4CXX_DEBUG(logger,sout.str());
126 if (this->fNNodes == 0) {
133 size_type elgraphsize = fElementGraphIndex.NElements()-1;
136 for(i=0; i < elgraphsize; i++)
138 int64_t
first, second;
139 first = fElementGraphIndex[i];
140 second = fElementGraphIndex[i+1];
142 for(j=first; j< second; j++)
144 for(k=j+1; k<second; k++)
146 add_edge(fElementGraph[j],fElementGraph[k],G);
147 nconnects[fElementGraph[j]]++;
152 for(i=0; i< (size_type)nconnects.size(); i++)
160 graph_traits<Graph>::vertex_iterator ui, ui_end;
162 property_map<Graph,vertex_degree_t>::type deg =
get(vertex_degree, G);
163 for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
164 deg[*ui] =
degree(*ui, G);
167 if (logger->isDebugEnabled())
169 std::stringstream sout;
170 sout <<
"NNodes " << fNNodes << std::endl;
171 sout <<
"NElements " << fNElements << std::endl;
173 sout <<
"Original Bandwidth: " << bandwidth(G) << std::endl;
174 sout <<
" Original profile: " 191 int64_t nVertices = num_vertices(G);
195 for(size_type i = 0; i < (size_type)l_perm.size(); i++) l_perm[i]=-1;
196 for(size_type i = 0; i < (size_type)l_perm.size(); i++) inv_perm[i]=0;
204 Vertex s = vertex(0, G);
206 cuthill_mckee_ordering(G, s, inv_perm.begin(),
get(vertex_color, G),
207 get(vertex_degree, G));
209 if(logger->isDebugEnabled())
211 LOGPZ_DEBUG(logger,
"Reverse Cuthill-McKee ordering:")
220 cuthill_mckee_ordering(G, inv_perm.begin(),
get(vertex_color, G),
221 get(vertex_degree, G));
223 if (logger->isDebugEnabled()) {
224 LOGPZ_DEBUG(logger,
"Reverse Expensive Cuthill-McKee ordering:")
233 if (logger->isDebugEnabled()) {
239 Vertex s = vertex(0, G);
243 Vertex e = pseudo_peripheral_pair(G, s, ecc,
get(vertex_color, G),
get(vertex_degree, G) );
245 if (logger->isDebugEnabled())
247 std::stringstream sout;
248 sout <<
"Sloan Starting vertex: " << s << endl;
249 sout <<
"Sloan Pseudoperipheral vertex: " << e << endl;
250 sout <<
"Sloan Pseudoperipheral radius: " << ecc << endl << endl;
255 sloan_ordering(G, s, e, inv_perm.begin(),
get(vertex_color, G),
256 get(vertex_degree, G),
get(vertex_priority, G));
262 for (size_type c = 0; c != (size_type)inv_perm.size(); ++c)
264 l_perm[inv_perm[c]] = c;
308 perm.
Resize(l_perm.size());
309 inverseperm.
Resize(inv_perm.size());
310 for(i=0; i<(size_type)l_perm.size(); i++)
313 inverseperm[i] = inv_perm[i];
316 if (logger->isDebugEnabled()) {
317 LOGPZ_DEBUG(logger,
"TPZBoostGraph::Resequence finished")
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
virtual void resize(const int64_t newsize)
void degree(int root, int adj_num, int adj_row[], int adj[], int mask[], int deg[], int *iccsze, int ls[], int node_num)
void profile(double *ara, double *arb, double *arc, unsigned sz, unsigned num_threads, void *(*fun)(void *), ElapsedTimeRunStat &et, RunStatsTable &rst)
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Contains the TPZBoostGraph class which implements an interface to the BGL for graph operations...
This abstract class which defines the behavior which derived classes need to implement for implement...
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Free store vector implementation.
virtual void ClearDataStructures()
This will reset all datastructures the object may contain.