source: issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.cpp@ 3570

Last change on this file since 3570 was 3570, checked in by Mathieu Morlighem, 15 years ago

removed exprintf of all ISSMERROR (not needed anymore)
Fixed Discontinuous Galerkin (missing thickness in inflow BC)"

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