NeoPZ
TPZSloanRenumbering.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 
3 #ifndef TPZSloanRenumberingH
4 #define TPZSloanRenumberingH
5 
6 #include "TPZRenumbering.h"
7 #include <map>
8 #include "pzmanvector.h"
9 #include <list>
10 #include "pzstack.h"
11 
12 //#define _OPTSET4History_
14 
15 {
16 
17 private:
18 
19  //Auxiliary structure: a list without duplicates and with control of history
20  struct SList{
21  //it stores the elements of the list
23 
24  //actual size of the list
25  int64_t fSize;
26 
27  //history: stores every element that has been in the list ever
28 #ifdef _OPTSET4History_
29  std::set<int64_t> fHistory;
30 #else
32 #endif
33 
34  SList(int64_t nnodes){
35  fList.Resize(nnodes);
36 #ifndef _OPTSET4History_
37  fHistory.Resize(nnodes);
38  fHistory.Fill(0);
39 #endif
40  fSize = 0;
41  }
42  ~SList(){
43  //nothing here
44  }
45 
46 
47  void Reset(){
48 #ifdef _OPTSET4History_
49  fHistory.clear();
50 #else
51  fHistory.Fill(0);
52 #endif
53  fSize = 0;
54  }
55 
56  //returns true if object is inserted or false otherwise (i.e. already existed)
57  bool push_back(int64_t val){
58 #ifdef _OPTSET4History_
59  if( (fHistory.insert(val)).second == true){
60 #else
61  if( fHistory[val] == 0 ){
62  fHistory[val] = 1;
63 #endif
64  fList[fSize] = val;
65  fSize++;
66  return true;
67  }
68  else return false;
69  }
70 
71  void remove(int64_t index){
72  fList[index] = fList[fSize-1];
73  fSize--;
74  }
75 
76  //Find the element and remove it. Returns true if element val was found or false otherwise
77  bool FindAndRemove(int64_t val){
78  for(int64_t i = 0; i < fSize; i++){
79  if(fList[i] == val){
80  this->remove(i);
81  return true;
82  }
83  }
84  return false;
85  }//method
86  };
87 
88 
89  int64_t W1() const{ return 1; }
90  int64_t W2() const{ return 2; }
91 
93  {
94  EInactive = 0,
96  EActive = 2,
98  };
99 
100  int64_t FindHighestPriority(const SList &Q,const TPZVec<int64_t> &priority, int64_t &Qindex) const;
101 
102  struct TNo
103  {
106 
107  int64_t fIndex;
109 
111  int fStatus;
112 
113  TNo() : fprev(0),fnext(0),fIndex(-1),fSequenceNumber(-1),fPriority(-1),fStatus(EInactive)
114  {
115 
116  }
117  };
118 
119  std::map<int, TNo *> fActive;
120 
122 
123  void InsertNode(TNo *node)
124  {
125  if( fActive.find(node->fPriority) == fActive.end())
126  {
127  node->fprev = 0;
128  node->fnext = 0;
129  fActive[node->fPriority] = node;
130  }
131  else
132  {
133  TNo *first = fActive[node->fPriority];
134  TNo *second = first->fnext;
135  first->fnext = node;
136  node->fprev = first;
137  node->fnext = second;
138  if(second) second->fprev = node;
139  }
140  }
141 
143  {
144 #ifdef PZDEBUG
145  if(fActive.size() == 0) DebugStop();
146 #endif
147  TNo* result = fActive.rbegin()->second;
148  int priority = fActive.rbegin()->first;
149  TNo* next = result->fnext;
150  if(! next)
151  {
152  fActive.erase(priority);
153  } else{
154  next->fprev = result->fprev;
155  if(next->fprev) next->fprev->fnext = next;
156  fActive[priority] = next;
157  }
158  result->fprev = 0;
159  result->fnext = 0;
160  return result;
161  }
162 
163  void TransferPriority(TNo *no, int newpriority)
164  {
165  int priority = no->fPriority;
166 #ifdef PZDEBUG
167  if(fActive.find(priority) == fActive.end()) DebugStop();
168  if(no->fPriority == newpriority) DebugStop();
169 #endif
170  TNo *first = fActive[priority];
171  if(no == first)
172  {
173  first = no->fnext;
174  if(!first )
175  {
176  fActive.erase(priority);
177  }
178  else
179  {
180  first->fprev = no->fprev;
181  if(no->fprev) no->fprev->fnext = first;
182  fActive[priority] = first;
183  }
184  }
185  else
186  {
187  TNo *prev = no->fprev;
188  TNo *next = no->fnext;
189  if(prev) prev->fnext = next;
190  if(next) next->fprev = prev;
191  }
192  no->fprev = 0;
193  no->fnext = 0;
194  no->fPriority = newpriority;
195  InsertNode(no);
196  }
197 
198  public:
199 
200 
201  virtual void Resequence(TPZVec<int64_t> &permGather, TPZVec<int64_t> &permScatter);
202 
203  virtual void Resequence2(TPZVec<int64_t> &permGather, TPZVec<int64_t> &permScatter);
204 
205 
206  TPZSloanRenumbering(int64_t NElements, int64_t NNodes);
207 
209 
210  virtual ~TPZSloanRenumbering();
211 
212  };
213 #endif
std::map< int, TNo * > fActive
int64_t FindHighestPriority(const SList &Q, const TPZVec< int64_t > &priority, int64_t &Qindex) const
virtual void Resequence2(TPZVec< int64_t > &permGather, TPZVec< int64_t > &permScatter)
Contains the TPZRenumbering class which defines the behavior to implementing node sequence numbering ...
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
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...
Definition: pzvec.h:373
This abstract class which defines the behavior which derived classes need to implement for implement...
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
virtual void clear()
Empty the vector, make its size zero.
Definition: pzvec.h:444
Free store vector implementation.
void TransferPriority(TNo *no, int newpriority)
void InsertNode(TNo *node)
virtual void Resequence(TPZVec< int64_t > &permGather, TPZVec< int64_t > &permScatter)
A simple stack.
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460