Changeset 14009


Ignore:
Timestamp:
11/27/12 11:12:10 (12 years ago)
Author:
Mathieu Morlighem
Message:

NEW: use integers in ElementConnectivity

Location:
issm/trunk-jpl/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp

    r13622 r14009  
    1515#include "../../EnumDefinitions/EnumDefinitions.h"
    1616
    17 int hascommondedge(double* element1,double* element2);
     17int hascommondedge(int* element1,int* element2);
    1818
    19 void    ElementConnectivityx( double** pelementconnectivity, double* elements, int nel, double* nodeconnectivity, int nods, int width){
     19void ElementConnectivityx(int** pelementconnectivity,int* elements, int nels,int* nodeconnectivity, int nods, int width){
    2020
    2121        int i,j,k,n;
     
    2323        /*intermediary: */
    2424        int    maxels;
    25         double element;
    26         double connectedelement;
     25        int  connectedelement;
    2726        int    connectedelementindex;
    2827        int    node;
     
    3029        int    num_elements;
    3130
    32         /*output: */
    33         double* elementconnectivity=NULL;
    34 
    3531        /*maxels: */
    3632        maxels=width-1;
     33
    3734        /*Allocate connectivity: */
    38         elementconnectivity=xNewZeroInit<double>(nel*3);
     35        int* elementconnectivity=xNewZeroInit<int>(nels*3);
    3936
    4037        /*Go through all elements, and for each element, go through its nodes, to get the neighbouring elements.
    4138         * Once we get the neighbouring elements, figure out if they share a segment with the current element. If so,
    4239         * plug them in the connectivity, unless they are already there.: */
     40        for(n=0;n<nels;n++){
    4341
    44         for(n=0;n<nel;n++){
    45 
    46                 element=(double)(n+1); //matlab indexing
     42                //element=n+1; //matlab indexing
    4743
    4844                for(i=0;i<3;i++){
    4945
    50                         node=(int)*(elements+n*3+i); //already matlab indexed, elements comes directly from the workspace.
     46                        node=elements[n*3+i]; //already matlab indexed, elements comes directly from the workspace.
    5147                        index=node-1;
    5248
    53                         num_elements=(int)*(nodeconnectivity+width*index+maxels); //retrieve number of elements already  plugged into the connectivity of this node.
     49                        num_elements=nodeconnectivity[width*index+maxels]; //retrieve number of elements already  plugged into the connectivity of this node.
    5450
    5551                        for(j=0;j<num_elements;j++){
    5652
    5753                                /*for each element connected to node, figure out if it has a commond edge with element: */
    58                                 connectedelement=*(nodeconnectivity+width*index+j);
    59                                 connectedelementindex=(int)(connectedelement-1); //go from matlab indexing to c indexing.
     54                                connectedelement=nodeconnectivity[width*index+j];
     55                                connectedelementindex=connectedelement-1; //go from matlab indexing to c indexing.
    6056
    61                                 if(hascommondedge(elements+n*3+0,elements+connectedelementindex*3+0)){
     57                                if(hascommondedge(&elements[n*3+0],&elements[connectedelementindex*3+0])){
    6258                                        /*Ok, this connected element has a commond edge  with element, plug it into elementconnectivity, unless
    6359                                         *it is already there: */
    6460
    6561                                        for(k=0;k<3;k++){
    66                                                 if (*(elementconnectivity+3*n+k)==0){
    67                                                         *(elementconnectivity+3*n+k)=connectedelement;
     62                                                if(elementconnectivity[3*n+k]==0){
     63                                                        elementconnectivity[3*n+k]=connectedelement;
    6864                                                        break;
    6965                                                }
    7066                                                else{
    71                                                         if(connectedelement==*(elementconnectivity+3*n+k))break;
     67                                                        if(connectedelement==elementconnectivity[3*n+k]) break;
    7268                                                }
    7369                                        }
     
    8177}
    8278
    83 int hascommondedge(double* element1,double* element2){
     79int hascommondedge(int* el1,int* el2){
    8480
    85         int i,j;
    86         int count;
    87 
    88         count=0;
    89         for(i=0;i<3;i++){
    90                 for(j=0;j<3;j++){
    91                         if (*(element1+i)==*(element2+j))count++;
     81        int count=0;
     82        for(int i=0;i<3;i++){
     83                for(int j=0;j<3;j++){
     84                        if(el1[i]==el2[j]) count++;
    9285                }
    9386        }
    94         if (count==2)return 1;
    95         else return 0;
     87        if(count==2)
     88         return 1;
     89        else
     90         return 0;
    9691}
  • issm/trunk-jpl/src/c/modules/ElementConnectivityx/ElementConnectivityx.h

    r13623 r14009  
    77
    88/* local prototypes: */
    9 void    ElementConnectivityx( double** pelementconnectivity, double* elements, int nel, double* nodeconnectivity, int nods, int width);
     9void    ElementConnectivityx(int** pelementconnectivity,int* elements,int nels,int* nodeconnectivity, int nods, int width);
    1010
    1111#endif  /* _ELEMENTCONNECTIVITYX_H */
  • issm/trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.cpp

    r13236 r14009  
    1313
    1414        /*inputs: */
    15         double* elements=NULL;
    16         double* nodeconnectivity=NULL;
    17         int     nel,nods;
    18         int     width;
     15        int* elements=NULL;
     16        int* nodeconnectivity=NULL;
     17        int  nels,nods;
     18        int  width;
    1919
    2020        /*outputs: */
    21         double* elementconnectivity=NULL;
     21        int* elementconnectivity=NULL;
    2222
    2323        /*Boot module: */
     
    2828       
    2929        /*Input datasets: */
    30         FetchData(&elements,&nel,NULL,ELEMENTS);
     30        FetchData(&elements,&nels,NULL,ELEMENTS);
    3131        FetchData(&nodeconnectivity,&nods,&width,NODECONNECTIVITY);
    3232
    3333        /*!Generate internal degree of freedom numbers: */
    34         ElementConnectivityx(&elementconnectivity, elements,nel, nodeconnectivity, nods, width);
     34        ElementConnectivityx(&elementconnectivity,elements,nels,nodeconnectivity,nods,width);
    3535
    3636        /*write output datasets: */
    37         WriteData(ELEMENTCONNECTIVITY,elementconnectivity,nel,3);
     37        WriteData(ELEMENTCONNECTIVITY,elementconnectivity,nels,3);
    3838
    3939        /*end module: */
Note: See TracChangeset for help on using the changeset viewer.