Ice Sheet System Model  4.18
Code documentation
Functions
ElementConnectivityx.h File Reference

header file for element connectivity computation More...

Go to the source code of this file.

Functions

void ElementConnectivityx (int **pelementconnectivity, int *elements, int nels, int *nodeconnectivity, int nods, int width)
 

Detailed Description

header file for element connectivity computation

Definition in file ElementConnectivityx.h.

Function Documentation

◆ ElementConnectivityx()

void ElementConnectivityx ( int **  pelementconnectivity,
int *  elements,
int  nels,
int *  nodeconnectivity,
int  nods,
int  width 
)

Definition at line 17 of file ElementConnectivityx.cpp.

17  {
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 }
hascommondedge
int hascommondedge(int *element1, int *element2)
Definition: ElementConnectivityx.cpp:77