source: issm/trunk-jpl/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp@ 14960

Last change on this file since 14960 was 14960, checked in by Mathieu Morlighem, 12 years ago

CHG: moved EnumDefinitions to src/c/shared/Enum

File size: 2.6 KB
RevLine 
[1105]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
[3913]15#include "../../shared/shared.h"
16#include "../../toolkits/toolkits.h"
[14960]17#include "../../shared/Enum/Enum.h"
[1105]18
[14016]19void NodeConnectivityx(int** pconnectivity,int* pwidth,int* elements, int nels, int nods){
[1105]20
21 int i,j,n;
[14302]22 const int maxels=50;
[1105]23 const int width=maxels+1;
24
25 /*intermediary: */
26 int node;
27 int index;
28 int num_elements;
29 int already_plugged=0;
[14016]30 int element;
[1105]31
32 /*Allocate connectivity: */
[14016]33 int* connectivity=xNewZeroInit<int>(nods*width);
[1105]34
35 /*Go through all elements, and for each elements, plug into the connectivity, all the nodes.
36 * If nodes are already plugged into the connectivity, skip them.: */
[14016]37 for(n=0;n<nels;n++){
[1105]38
[14016]39 element=n+1; //matlab indexing
[1105]40
41 for(i=0;i<3;i++){
[13622]42
[14016]43 node=elements[n*3+i]; //already matlab indexed, elements comes directly from the workspace.
[1105]44 index=node-1;
45
[14016]46 num_elements=connectivity[width*index+maxels]; //retrieve number of elements already plugged into the connectivity of this node.
[13622]47
[1105]48 already_plugged=0;
49 for(j=0;j<num_elements;j++){
50 if (element==*(connectivity+width*index+j)){
51 already_plugged=1;
52 break;
53 }
54 }
55 if(already_plugged)break;
56
57 /*this elements is not yet plugged into the connectivity for this node, do it, and increase counter: */
[14016]58 connectivity[width*index+num_elements]=element;
59 connectivity[width*index+maxels]=num_elements+1;
[13622]60
[1105]61 }
62 }
63
64 /*Last check: is the number of elements on last column of the connectivity superior to maxels? If so, then error out and
65 * warn the user to increase the connectivity width: */
66 for(i=0;i<nods;i++){
[14016]67 if (*(connectivity+width*i+maxels)>maxels)
68 _error_("max connectivity width reached (" << *(connectivity+width*i+maxels) << ")! increase width of connectivity table");
[1105]69 }
70
71 /*Assign output pointers: */
72 *pconnectivity=connectivity;
73 *pwidth=width;
74}
Note: See TracBrowser for help on using the repository browser.