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

Last change on this file since 2263 was 2263, checked in by Eric.Larour, 15 years ago

Increased size of max connectivity.

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