NeoPZ
pzsloan.cpp
Go to the documentation of this file.
1 
6 #include "pzsloan.h"
7 #include "math.h"
8 #include <fstream>
9 using namespace std;
10 
11 #include "pz_pthread.h"
12 
13 TPZSloan::TPZSloan(int NElements, int NNodes) : TPZRenumbering(NElements,NNodes)
14 {
15  fNNodes = NNodes;
16  fNElements = NElements;
17  fMaxNodesElement = 27;
18 }
19 
21 {
22 
23  if(!fNNodes || !fNElements)
24  {
25  std::cout << __PRETTY_FUNCTION__ << " called with fNNodes = " << fNNodes
26  << " and fNElements = " << fNElements << std::endl;
27  return;
28  }
29 
37  //feed npn and xnpn with data from jj and jk
38  int64_t i;
39 // int k=0;
40  int nnodes_per_element=fMaxNodesElement;
41 
42  TPZVec<int64_t> elementgraph(fElementGraph.NElements()+1);
43  TPZVec<int64_t> elementgraphindex(fElementGraphIndex.NElements()+1);
44 
45  int64_t n = fElementGraph.NElements();
46  for (i=0; i<n; i++) {
47  elementgraph[i+1] = fElementGraph[i]+1;
48  }
50  for (i=0; i<n; i++) {
51  elementgraphindex[i+1] = fElementGraphIndex[i]+1;
52  }
53 
54  int64_t iadj = elementgraph.NElements()* nnodes_per_element* (nnodes_per_element-1);
55  TPZVec<int64_t> adj(iadj);
56  TPZVec<int64_t> xadj(fNNodes+2,-1);
57  int nop = 0;
58  int64_t inpn = nnodes_per_element * fNElements;
59 
60  //adjacency list generation
61  //ofstream sai("felementgraph.txt");
62  //fElementGraph.Print(sai);
63  //int *npn = new int [iadj];
64  //npn=fElementGraph;
65  //int *xnpn = new int[iadj];
66  //xnpn=fElementGraphIndex;
67  //int *adj = new int [iadj];
68  //int *xadj = new int[iadj];
69  // Print the element graph
70 #ifdef SLOANDEBUG
71  int iel;
72  for(iel=0; iel<fNElements; iel++)
73  {
74  int firstindex = elementgraphindex[iel+1];
75  int lastindex = elementgraphindex[iel+2];
76  int no;
77  cout << "Element : " << iel+1 << " : ";
78  for(no = firstindex; no<lastindex; no++)
79  {
80  cout << elementgraph[no] << " ";
81  }
82  cout << endl;
83  }
84 #endif
85  static pthread_mutex_t Lock_clindex = PTHREAD_MUTEX_INITIALIZER;
86  PZ_PTHREAD_MUTEX_LOCK(&Lock_clindex,"TPZSloan::Resequence()");
87 // int elementgraph_int = (int)elementgraph[1];
88 // TPZVec<int> elementgraphindex_int = ((TPZVec<int>)elementgraphindex);
89  gegra_(&fNNodes, &fNElements, &inpn, &elementgraph[1], &elementgraphindex[1], &iadj, &adj[0], &xadj[0], &nop);
90 // elementgraph[1] = elementgraph_int;
91 // elementgraphindex[1] = elementgraphindex_int;
92  PZ_PTHREAD_MUTEX_UNLOCK(&Lock_clindex,"TPZSloan::Resequence()");
93  //gegra_(&fNNodes, &fNElements, &inpn, npn, xnpn, &iadj, adj, xadj, &nop);
94 #ifdef SLOANDEBUG
95  cout << "node index vector ";
96  int64_t no;
97  for(no=0; no<xadj.NElements(); no++)
98  {
99  cout << xadj[no] << " ";
100  if(no && !(no%30)) cout << endl;
101 
102  }
103  cout << endl;
104  for(no=0; no<fNNodes; no++)
105  {
106  int firstindex = xadj[no]-1;
107  int lastindex = xadj[no+1]-1;
108  int el;
109  cout << "Node : " << no+1 << " : ";
110  for(el = firstindex; el<lastindex; el++)
111  {
112  cout << adj[el] << " ";
113  }
114  cout << endl;
115  }
116 #endif
117  TPZVec<int64_t> iw(nnodes_per_element*(fNElements+1)*10);
118  //int *iw = new int [nnodes_per_element*(fNElements+1)];
119  int64_t e2 = xadj[fNNodes]-1;
120 
121  //int *NowPw
122  //Where to obtain n_nodes ?
123  //rewriting with new order
124  //array nnn contains the new enumeration (nnn = perm on Metis)
125  int64_t old_profile=0;
126  int64_t new_profile=0;
127  perm.Resize(fNNodes+1);
128 
129  PZ_PTHREAD_MUTEX_LOCK(&Lock_clindex,"TPZSloan::Resequence()");
130  label_(&fNNodes , &e2, &adj[0], &xadj[0], &perm[1], &iw[1], &old_profile, &new_profile);
131  PZ_PTHREAD_MUTEX_UNLOCK(&Lock_clindex,"TPZSloan::Resequence()");
132 
133  //label_(&fNNodes , &e2, adj, xadj, NowPerm, iw, &old_profile, &new_profile);
134  //cout << __PRETTY_FUNCTION__ << " oldprofile " << old_profile << " newprofile " << new_profile << endl;
135  TPZVec <int64_t> aux(perm.NElements());
136  aux = perm;
137  perm.Resize(aux.NElements()-1);
138  for(i=0;i<perm.NElements();i++) perm[i]=aux[i+1]-1;
139  iperm.Resize(perm.NElements());
140  for(i=0;i<perm.NElements();i++) iperm[perm[i]]=i;
141 }
142 
#define PZ_PTHREAD_MUTEX_UNLOCK(mutex, fn)
Definition: pz_pthread.h:79
virtual void Resequence(TPZVec< int64_t > &perm, TPZVec< int64_t > &iperm)
Definition: pzsloan.cpp:20
int label_(int64_t *n, int64_t *e2, int64_t *adj, int64_t *xadj, int64_t *nnn, int64_t *iw, int64_t *oldpro, int64_t *newpro)
Definition: label.cpp:3
TPZVec< int64_t > fElementGraphIndex
Indicates for each element the index of the first entry with fElementGraph for that element The size ...
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
#define PZ_PTHREAD_MUTEX_LOCK(mutex, fn)
Definition: pz_pthread.h:76
This abstract class which defines the behavior which derived classes need to implement for implement...
int fMaxNodesElement
Definition: pzsloan.h:28
int64_t fNElements
Number of elements in the graph.
int64_t fNNodes
Number of nodes in the graph.
TPZVec< int64_t > fElementGraph
Node number of each element.
TPZSloan()
Definition: pzsloan.h:32
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
Contains the TPZSloan class.
int gegra_(int64_t *n, int64_t *ne, int64_t *, int64_t *npn, int64_t *xnpn, int64_t *iadj, int64_t *adj, int64_t *xadj, int *nop)
Purpose: Form adjacency list for a graph corresponding to a finite element mesh.
Definition: gegra.cpp:7