24 static LoggerPtr logger(Logger::getLogger(
"pz.renumbering"));
32 int64_t nod,last = elgraphindex[fNElements];
33 for(nod = 0; nod<last; nod++) {
34 nelcon[elgraph[nod]]++;
36 nodtoelgraphindex = nelcon;
38 for(nod=fNNodes; nod>0; nod--) nodtoelgraphindex[nod] = nodtoelgraphindex[nod-1];
39 nodtoelgraphindex[0] = 0;
40 for(nod=1;nod<=fNNodes;nod++) nodtoelgraphindex[nod] += nodtoelgraphindex[nod-1];
42 nodtoelgraph.
Resize(nodtoelgraphindex[fNNodes]);
43 nodtoelgraph.
Fill (-1);
48 for(el=0; el<fNElements; el++) {
49 int64_t firstnode = elgraphindex[el];
50 int64_t lastnode = elgraphindex[el+1];
51 for(nod=firstnode;nod<lastnode;nod++) {
52 int64_t gnod = elgraph[nod];
53 nodtoelgraph[nodtoelgraphposition[gnod]] = el;
54 nodtoelgraphposition[gnod]++;
56 if (nodtoelgraphposition[gnod] > nodtoelgraphindex[gnod+1]) {
57 PZError << __PRETTY_FUNCTION__ <<
" wrong data structure\n";
76 TPZTimer convert(
"Converting graph ");
82 NodeToElGraph(elgraph, elgraphindex, nodtoelgraph, nodtoelgraphindex);
84 nodegraphindex.
Resize(fNNodes + 1);
85 nodegraphindex.
Fill(0);
87 int64_t nodegraphincrement = 100000;
88 nodegraph.
Resize(nodegraphincrement);
89 int64_t nextfreeindex = 0;
90 for (nod = 0; nod < fNNodes; nod++) {
91 int64_t firstel = nodtoelgraphindex[nod];
92 int64_t lastel = nodtoelgraphindex[nod + 1];
93 std::set<int64_t> nodecon;
94 for (el = firstel; el < lastel; el++) {
95 int64_t gel = nodtoelgraph[el];
96 int64_t firstelnode = elgraphindex[gel];
97 int64_t lastelnode = elgraphindex[gel + 1];
98 nodecon.insert(&elgraph[firstelnode], &elgraph[(lastelnode - 1)] + 1);
101 while (nextfreeindex + nodecon.size() >= nodegraph.
size()) nodegraph.
Resize(nodegraph.
NElements() + nodegraphincrement,0);
102 std::set<int64_t>::iterator it;
103 for (it = nodecon.begin(); it != nodecon.end(); it++) nodegraph[nextfreeindex++] = *it;
105 nodegraphindex[nod + 1] = nextfreeindex;
112 fNElements = NElements;
117 return Hash(
"TPZRenumbering");
121 buf.
Read(&fHDivPermute);
122 buf.
Read(&fNElements);
124 buf.
Read(fNodeWeights);
125 buf.
Read(fElementGraph);
126 buf.
Read(fElementGraphIndex);
130 buf.
Write(&fHDivPermute);
131 buf.
Write(&fNElements);
133 buf.
Write(fNodeWeights);
134 buf.
Write(fElementGraph);
135 buf.
Write(fElementGraphIndex);
142 cout <<
"TPZRenumbering::ColorNodes inconsistent input parameters" << std::endl;
145 int64_t nnodes = nodegraphindex.
NElements() - 1;
148 int current_family = 0;
149 int64_t nodeshandled = 0;
151 while (nodeshandled < nnodes) {
155 for (nod = 0; nod < nnodes; nod++) {
156 int64_t firstnod = nodegraphindex[nod];
157 int64_t lastnod = nodegraphindex[nod + 1];
159 for (int64_t ind = firstnod; ind < lastnod; ind++) {
160 int64_t nodcon = nodegraph[ind];
161 if (family[nodcon] != current_family)
continue;
162 if (colors[nodcon] != -1) usedcolors[colors[nodcon]] = 1;
165 for (ic = 0; ic < usedcolors.
NElements(); ic++){
166 if (usedcolors[ic] != 1){
184 const int64_t n_connects = cmesh->
NConnects();
186 const int64_t nel_to_be_colored = elementIndices.
size();
188 if (nel == 0 || nel_to_be_colored == 0)
return 0;
190 elementColors.
Resize(nel_to_be_colored);
191 elementColors.
Fill(-1);
192 int64_t n_colors = 0;
193 int64_t next_color_initial_index = 0;
194 std::function<void(int64_t,int64_t,TPZTaskGroup *)> color = [n_connects, nel_to_be_colored, &elementIndices, &elementColors, cmesh, &color, &n_colors, &next_color_initial_index](int64_t initial_index, int64_t currentColor,
TPZTaskGroup *group) {
197 bool created_new_color =
false;
200 for (int64_t iel = initial_index; iel < nel_to_be_colored; ++iel) {
201 auto elindex = elementIndices[iel];
203 if (elementColors[iel] == -1) {
204 auto cel = cmesh->Element(elindex);
207 cel->BuildConnectList(connectlist);
208 bool skip_element =
false;
209 for (
auto connect : connectlist) {
210 if (std::find(connects_this_color.
begin(), connects_this_color.
end(), connect) != connects_this_color.
end()) {
216 if (!created_new_color) {
219 created_new_color =
true;
221 if (next_color_initial_index == -1) {
222 next_color_initial_index = iel;
224 next_color_initial_index = std::min(next_color_initial_index, iel);
230 for (
auto connect : connectlist) {
233 elementColors[iel] = currentColor;
238 int64_t initial_index = next_color_initial_index;
239 next_color_initial_index = -1;
243 }
while (next_color_initial_index != -1);
245 #define CHECK_COLORING 246 #ifdef CHECK_COLORING 247 for (
unsigned int color = 0; color < n_colors; ++color) {
249 for (int64_t iel = 0; iel < nel_to_be_colored; ++iel) {
250 auto elindex = elementIndices[iel];
251 if (elementColors[iel] == color) {
252 auto cel = cmesh->Element(elindex);
255 cel->BuildConnectList(connectlist);
256 for (
auto connect : connectlist) {
257 if (color_connect[connect]) {
261 for (
auto connect : connectlist) {
262 color_connect[connect] =
true;
264 }
else if (elementColors[iel] == -1){
265 auto cel = cmesh->Element(elindex);
276 out <<
"Graph: " << name << endl;
277 for (int64_t i = 0; i < graphindex.
NElements() - 1; i++) {
278 out <<
"Graph item: " << i <<
"\t";
279 for (int64_t j = graphindex[i]; j < graphindex[i + 1]; j++) {
281 out <<
"wrong graphindex graph.NElements = " << graph.
NElements() <<
" i = " << i <<
"graphindex[i] = " << graphindex[i] <<
" " << graphindex[i + 1] << endl;
284 out << graph[j] <<
"\t";
297 int nnode = gel->
NNodes();
298 REAL distmin = 1.e10;
300 cout <<
"Geometric element without nodes??? \n";
305 distmin = gn->
Coord(0)*normal[0]+ gn->
Coord(1)*normal[1]+ gn->
Coord(2)*normal[2];
307 for(in=0; in<nnode; in++) {
310 distmin = distmin < dist ? distmin :
dist;
318 multimap<REAL, TPZCompEl *> elmap;
321 for(iel=0; iel<nelem; iel++) {
327 elmap.insert(pair<REAL,TPZCompEl *>(dist,cel));
330 multimap<REAL, TPZCompEl *>::iterator it;
333 while(it != elmap.
end()) {
337 for(ic=0; ic<nc; ic++) {
339 if(Permute[seqnum] == -1) Permute[seqnum] = iseq++;
357 NodeToElGraph(elgraph,elgraphindex,nodegraph,nodegraphindex);
359 int64_t nelements = elgraphindex.
NElements()-1;
360 eltoelgraphindex.
Resize(nelements+1);
361 eltoelgraphindex[0] = 0;
363 eltoelweight.
Resize(1000);
365 for(iel=0; iel<nelements; iel++)
367 map<int64_t,int> elset;
368 int64_t firstnodeindex = elgraphindex[iel];
369 int64_t lastnodeindex = elgraphindex[iel+1];
371 for(nodeindex = firstnodeindex; nodeindex< lastnodeindex; nodeindex++)
373 int64_t node = elgraph[nodeindex];
374 int64_t firstelindex = nodegraphindex[node];
375 int64_t lastelindex = nodegraphindex[node+1];
377 for(elindex = firstelindex; elindex < lastelindex; elindex++)
379 int64_t element = nodegraph[elindex];
383 if(node < fNodeWeights.NElements()) nweight = fNodeWeights[node];
384 elset[element] += nweight;
388 int64_t eltoelsize = eltoelgraph.
NElements();
389 if(eltoelgraphindex[iel]+elset.
size() >= eltoelsize)
391 eltoelgraph.
Resize(eltoelsize+elset.size()+1000);
394 int64_t count = eltoelgraphindex[iel];
395 map<int64_t,int>::iterator it;
396 for(it=elset.begin(); it != elset.end(); it++,count++)
398 eltoelgraph[count] = it->first;
399 eltoelweight[count] = it->second;
401 eltoelgraphindex[iel+1] = count;
403 eltoelgraph.
Resize(eltoelgraphindex[nelements]);
409 Print(elgraph, elgraphindex,
"original element graph", cout);
411 fElementGraph = elgraph;
412 fElementGraphIndex = elgraphindex;
416 fNodeWeights.Resize(0);
417 fElementGraph.Resize(0);
418 fElementGraphIndex.Resize(0);
431 NodeToElGraph(fElementGraph,fElementGraphIndex,nodtoelgraph,nodtoelgraphindex);
433 int64_t nelem = fElementGraphIndex.NElements()-1;
434 if (nelconsider > nelem) {
438 for (element=0; element < nelconsider; element++)
440 int64_t firstindex = fElementGraphIndex[element];
441 int64_t lastindex = fElementGraphIndex[element+1];
442 if (firstindex == lastindex) {
446 std::set<int64_t> elcornernodes;
450 std::multimap<int64_t,std::pair<int64_t,std::set<int64_t> > > connectivities;
451 typedef std::multimap<int64_t,std::pair<int64_t,std::set<int64_t> > > map_type;
453 int64_t maxelcon = 0;
454 for (ind=firstindex; ind<lastindex; ind++) {
455 int64_t node = fElementGraph[ind];
456 int64_t firstelind = nodtoelgraphindex[node];
457 int64_t lastelind = nodtoelgraphindex[node+1];
458 std::set<int64_t> elcon;
459 elcon.insert(&nodtoelgraph[firstelind],(&nodtoelgraph[lastelind-1])+1);
460 maxelcon = maxelcon < elcon.
size() ? elcon.size() : maxelcon;
461 connectivities.insert(map_type::value_type(elcon.size(), std::pair<int64_t, std::set<int64_t> >(node,elcon)));
464 map_type::reverse_iterator it = connectivities.rbegin();
466 int64_t maxconnect = it->first;
467 std::pair<map_type::const_iterator, map_type::const_iterator> p = connectivities.equal_range(it->first);
468 map_type::const_iterator ithead;
469 for (ithead = p.first; ithead != p.second; ithead++)
471 int64_t seqnum = ithead->second.first;
472 if (eligible.find(seqnum) != eligible.end()) {
473 corners.
Push(seqnum);
474 cornernodes.insert(seqnum);
475 elcornernodes.insert(seqnum);
480 std::stringstream sout;
481 sout <<
"Element " << element <<
" First stage corner nodes " << corners;
482 if (logger->isDebugEnabled())
489 map_type::iterator itf = connectivities.begin();
490 for (itf=connectivities.begin(); itf != connectivities.end(); itf++)
492 map_type::reverse_iterator it = connectivities.rbegin();
493 while (it->first > itf->first && it!=connectivities.rend())
495 std::set<int64_t>::iterator smallsetbeg, smallsetend, largesetbeg, largesetend;
496 smallsetbeg = itf->second.second.begin();
497 smallsetend = itf->second.second.end();
498 largesetbeg = it->second.second.begin();
499 largesetend = it->second.second.end();
501 if (includes(largesetbeg,largesetend,smallsetbeg,smallsetend)) {
508 if (it->first == itf->first && it->first != maxconnect) {
509 int64_t seqnum = itf->second.first;
510 if (eligible.find(seqnum) != eligible.end())
512 corners.
Push(seqnum);
513 cornernodes.insert(seqnum);
514 elcornernodes.insert(seqnum);
520 std::stringstream sout;
521 sout <<
"Element " << element <<
" cornernodes.size " << elcornernodes.size() <<
" Second stage corner nodes " << corners;
522 if (logger->isDebugEnabled())
528 if (elcornernodes.size() < mincorners) {
529 it = connectivities.rbegin();
530 int64_t numelconnected = it->first-1;
532 while (numelconnected > 1 && ncorners < mincorners) {
533 std::pair<map_type::const_iterator, map_type::const_iterator> p = connectivities.equal_range(numelconnected);
534 map_type::const_iterator ithead;
535 for (ithead = p.first; ithead != p.second; ithead++)
537 int64_t seqnum = ithead->second.first;
538 if (eligible.find(seqnum) != eligible.end())
540 corners.
Push(seqnum);
541 cornernodes.insert(seqnum);
542 elcornernodes.insert(seqnum);
544 ncorners = elcornernodes.size();
550 for (ieq=0; ieq<corners.
NElements(); ieq++) {
551 if (cornernodes.find(corners[ieq]) == cornernodes.end()) {
557 std::stringstream sout;
558 sout <<
"Element " << element <<
" sub " << sub <<
" Final stage corner nodes " << corners;
559 if (logger->isDebugEnabled())
int64_t NElements() const
Number of computational elements allocated.
The timer class. Utility.
void SetElementGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex)
This method declares the element graph to the object.
TPZGeoNode * NodePtr(int i) const
Returns a pointer to the ith node of the element.
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.
Timing class. Absolutely copied from GNU time. Take a look at
void ConvertGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex, TPZManVector< int64_t > &nodegraph, TPZManVector< int64_t > &nodegraphindex)
Will convert an element graph defined by elgraph and elgraphindex into a node graph defined by nodegr...
Contains declaration of TPZGeoNode class which defines a geometrical node.
REAL Coord(int i) const
Returns i-th coordinate of the current node.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Templated vector implementation.
Contains the TPZRenumbering class which defines the behavior to implementing node sequence numbering ...
static TPZThreadPool & globalInstance()
int64_t NElements() const
Access method to query the number of elements of the vector.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
int ClassId() const override
Define the class id associated with the class.
std::shared_future< void > run(const int priority, TPZAutoPointer< std::packaged_task< void(void) > > &task, TPZTaskGroup *taskGroup=NULL)
submits a task to be executed by TPZThreadPool
int64_t size() const
Returns the number of elements of the vector.
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...
int64_t SequenceNumber() const
Returns the Sequence number of the connect object.
void Push(const T object)
Pushes a copy of the object on the stack.
void start()
Turns the timer on.
virtual void Write(const bool val)
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
#define DebugStop()
Returns a message to user put a breakpoint in.
void CornerEqs(unsigned int mincorners, int64_t nelconsider, std::set< int > &eligible, std::set< int > &cornernodes)
Analyzes the graph, finds the corner nodes Number of elements which should be considered for determi...
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
void ConvertToElementoToElementGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex, TPZVec< int64_t > &eltotelgraph, TPZVec< int > &eltoelweight, TPZVec< int64_t > &eltoelgraphindex)
Convert a traditional elgraph to an element to element graph.
void Read(TPZStream &buf, void *context) override
read objects from the stream
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
int64_t NConnects() const
Number of connects allocated including free nodes.
T * begin() const
Casting operator. Returns The fStore pointer.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
void Print(TPZVec< int64_t > &grapho, TPZVec< int64_t > &graphoindex, const char *name=0, std::ostream &out=std::cout)
Prints graph.
virtual TPZConnect & Connect(int i) const
Returns a pointer to the ith node.
int32_t Hash(std::string str)
static int64_t ColorElements(const TPZCompMesh *cmesh, const TPZVec< int64_t > &elementIndices, TPZVec< int64_t > &elementColors)
Assigns a color to the elements in the elementIndices list such that two elements that share a connec...
virtual int NNodes() const =0
Returns the number of nodes of the element.
virtual int NConnects() const =0
Returns the number of nodes of the element.
virtual void ClearDataStructures()
This will reset all datastructures the object may contain.
virtual void CleanUpUnconnectedNodes()
Delete the nodes which have no elements connected to them.
REAL dist(TPZVec< T1 > &vec1, TPZVec< T1 > &vec2)
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Implements a geometric node in the pz environment. Geometry.
void NodeToElGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex, TPZVec< int64_t > &nodetoelgraph, TPZVec< int64_t > &nodetoelgraphindex)
Stores the graph of nodes to elements.
Implements computational mesh. Computational Mesh.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
void Fill(const T ©, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
Defines the interface for saving and reading data. Persistency.
void stop()
Turns the timer off, and computes the elapsed time.
int64_t NElements() const
Returns the number of elements of the vector.
static REAL XMin(TPZGeoEl *gel, const TPZVec< REAL > &normal)
virtual void Print(std::ostream &out=std::cout)
Print all relevant data of the element to cout.
Defines the interface of a computational element. Computational Element.
void push_back(const T object)
int64_t ColorNodes(TPZVec< int64_t > &nodegraph, TPZVec< int64_t > &nodegraphindex, TPZVec< int > &family, TPZVec< int > &colors)
Will assign a color to the nodes in the graph such that no two connected nodes have the same color th...
void ResequenceByGeometry(TPZCompMesh *cmesh, const TPZVec< REAL > &normal)
Makes resequence to renumbering.
T * end() const
Returns a pointer to the last+1 element.
Implements an interface to register a class id and a restore function. Persistence.
#define PZError
Defines the output device to error messages and the DebugStop() function.
virtual void Read(bool &val)
void Permute(TPZVec< int64_t > &permute)
Permute the sequence number of the connect objects It is a permute gather operation.