Ice Sheet System Model  4.18
Code documentation
ElementConnectivityx.cpp
Go to the documentation of this file.
1 
10 #include "./ElementConnectivityx.h"
11 
12 #include "../../shared/shared.h"
13 #include "../../toolkits/toolkits.h"
14 
15 int hascommondedge(int* element1,int* element2);
16 
17 void ElementConnectivityx(int** pelementconnectivity,int* elements, int nels,int* nodeconnectivity, int nods, int width){
18 
19  int i,j,k,n;
20 
21  /*intermediary: */
22  int maxels;
23  int connectedelement;
24  int connectedelementindex;
25  int node;
26  int index;
27  int num_elements;
28 
29  /*maxels: */
30  maxels=width-1;
31 
32  /*Allocate connectivity: */
33  int* elementconnectivity=xNewZeroInit<int>(nels*3);
34 
35  /*Go through all elements, and for each element, go through its nodes, to get the neighbouring elements.
36  * Once we get the neighbouring elements, figure out if they share a segment with the current element. If so,
37  * plug them in the connectivity, unless they are already there.: */
38  for(n=0;n<nels;n++){
39 
40  //element=n+1; //matlab indexing
41 
42  for(i=0;i<3;i++){
43 
44  node=elements[n*3+i]; //already matlab indexed, elements comes directly from the workspace.
45  index=node-1;
46 
47  num_elements=nodeconnectivity[width*index+maxels]; //retrieve number of elements already plugged into the connectivity of this node.
48 
49  for(j=0;j<num_elements;j++){
50 
51  /*for each element connected to node, figure out if it has a commond edge with element: */
52  connectedelement=nodeconnectivity[width*index+j];
53  connectedelementindex=connectedelement-1; //go from matlab indexing to c indexing.
54 
55  if(hascommondedge(&elements[n*3+0],&elements[connectedelementindex*3+0])){
56  /*Ok, this connected element has a commond edge with element, plug it into elementconnectivity, unless
57  *it is already there: */
58 
59  for(k=0;k<3;k++){
60  if(elementconnectivity[3*n+k]==0){
61  elementconnectivity[3*n+k]=connectedelement;
62  break;
63  }
64  else{
65  if(connectedelement==elementconnectivity[3*n+k]) break;
66  }
67  }
68  }
69  }
70  }
71  }
72 
73  /*Assign output pointers: */
74  *pelementconnectivity=elementconnectivity;
75 }
76 
77 int hascommondedge(int* el1,int* el2){
78 
79  int count=0;
80  for(int i=0;i<3;i++){
81  for(int j=0;j<3;j++){
82  if(el1[i]==el2[j]) count++;
83  }
84  }
85  if(count==2)
86  return 1;
87  else
88  return 0;
89 }
ElementConnectivityx
void ElementConnectivityx(int **pelementconnectivity, int *elements, int nels, int *nodeconnectivity, int nods, int width)
Definition: ElementConnectivityx.cpp:17
hascommondedge
int hascommondedge(int *element1, int *element2)
Definition: ElementConnectivityx.cpp:77
ElementConnectivityx.h
header file for element connectivity computation