1 | /*!\file NodeConnectivityx
|
---|
2 | * \brief: compute node connectivity table, using elements connectivity table.
|
---|
3 | *
|
---|
4 | * For each node, we want to know how many elements are connected to this element, and which they are.
|
---|
5 | * Given that the 2d meshes we create in ISSM are triangular for now, and they are delaunay conforming,
|
---|
6 | * each triangle has a minimum angle of 30 degrees, which implies a connectivity <=6. We therefore return
|
---|
7 | * a nods x 7 connectivity table, with the 7'th column giving us the number of elements connected to each
|
---|
8 | * row node, and the first 6 columns giving us the elements numbers.
|
---|
9 | * Amend that: sounds like some triangles get up to 9 connectivity. Take 10 to be on the safe side.
|
---|
10 | * In order to be compatible with matlab output, the connectivity table is given in matlab indexing (starts at 1).
|
---|
11 | */
|
---|
12 |
|
---|
13 | #include "./NodeConnectivityx.h"
|
---|
14 |
|
---|
15 | #include "../../shared/shared.h"
|
---|
16 | #include "../../toolkits/toolkits.h"
|
---|
17 |
|
---|
18 | void NodeConnectivityx(int** pconnectivity,int* pwidth,int* elements, int nels, int nods){
|
---|
19 |
|
---|
20 | int i,j,n;
|
---|
21 | const int maxels=100;
|
---|
22 | const int width=maxels+1;
|
---|
23 |
|
---|
24 | /*intermediary: */
|
---|
25 | int node;
|
---|
26 | int index;
|
---|
27 | int num_elements;
|
---|
28 | int already_plugged=0;
|
---|
29 | int element;
|
---|
30 |
|
---|
31 | /*Allocate connectivity: */
|
---|
32 | int* connectivity=xNewZeroInit<int>(nods*width);
|
---|
33 |
|
---|
34 | /*Go through all elements, and for each elements, plug into the connectivity, all the nodes.
|
---|
35 | * If nodes are already plugged into the connectivity, skip them.: */
|
---|
36 | for(n=0;n<nels;n++){
|
---|
37 |
|
---|
38 | element=n+1; //matlab indexing
|
---|
39 |
|
---|
40 | for(i=0;i<3;i++){
|
---|
41 |
|
---|
42 | node=elements[n*3+i]; //already matlab indexed, elements comes directly from the workspace.
|
---|
43 | index=node-1;
|
---|
44 |
|
---|
45 | num_elements=connectivity[width*index+maxels]; //retrieve number of elements already plugged into the connectivity of this node.
|
---|
46 |
|
---|
47 | already_plugged=0;
|
---|
48 | for(j=0;j<num_elements;j++){
|
---|
49 | if (element==*(connectivity+width*index+j)){
|
---|
50 | already_plugged=1;
|
---|
51 | break;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | if(already_plugged)break;
|
---|
55 |
|
---|
56 | /*this elements is not yet plugged into the connectivity for this node, do it, and increase counter: */
|
---|
57 | connectivity[width*index+num_elements]=element;
|
---|
58 | connectivity[width*index+maxels]=num_elements+1;
|
---|
59 |
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*Last check: is the number of elements on last column of the connectivity superior to maxels? If so, then error out and
|
---|
64 | * warn the user to increase the connectivity width: */
|
---|
65 | for(i=0;i<nods;i++){
|
---|
66 | if (*(connectivity+width*i+maxels)>maxels)
|
---|
67 | _error_("max connectivity width reached (" << *(connectivity+width*i+maxels) << ")! increase width of connectivity table");
|
---|
68 | }
|
---|
69 |
|
---|
70 | /*Assign output pointers: */
|
---|
71 | *pconnectivity=connectivity;
|
---|
72 | *pwidth=width;
|
---|
73 | }
|
---|