[1] | 1 | /*!\file: MeshPartition.cpp
|
---|
| 2 | * \brief: partition mesh according to number of areas, using Metis library.
|
---|
| 3 | */
|
---|
[15396] | 4 |
|
---|
[1] | 5 | #include "./MeshPartition.h"
|
---|
| 6 |
|
---|
[13236] | 7 | void MeshPartitionUsage(void){/*{{{*/
|
---|
[15396] | 8 | _printf_(" usage:\n");
|
---|
| 9 | _printf_(" [element_partitioning,node_partitioning]=MeshPartition(md.mesh,numpartitions)");
|
---|
| 10 | _printf_(" where:\n");
|
---|
| 11 | _printf_(" element_partitioning is a vector of partitioning area numbers, for every element.\n");
|
---|
| 12 | _printf_(" node_partitioning is a vector of partitioning area numbers, for every node.\n");
|
---|
| 13 | _printf_("\n");
|
---|
[13236] | 14 | }/*}}}*/
|
---|
| 15 | WRAPPER(MeshPartition){
|
---|
[1] | 16 |
|
---|
| 17 | /*Indexing: */
|
---|
| 18 | int i,j;
|
---|
| 19 |
|
---|
| 20 | /* required input: */
|
---|
[10231] | 21 | int dim;
|
---|
| 22 | int numberofelements;
|
---|
| 23 | int numberofvertices;
|
---|
| 24 | double *elements = NULL;
|
---|
[1] | 25 | int elements_width;
|
---|
| 26 |
|
---|
| 27 | int numberofelements2d;
|
---|
[10231] | 28 | int numberofvertices2d;
|
---|
[1] | 29 | double* elements2d=NULL;
|
---|
| 30 |
|
---|
[10231] | 31 | int numberoflayers;
|
---|
[1] | 32 | int numareas=1;
|
---|
| 33 |
|
---|
| 34 | /* output: */
|
---|
[10231] | 35 | int *int_element_partitioning = NULL;
|
---|
| 36 | int *int_node_partitioning = NULL;
|
---|
| 37 | double *element_partitioning = NULL;
|
---|
| 38 | double *node_partitioning = NULL;
|
---|
[1] | 39 |
|
---|
| 40 | /*Boot module: */
|
---|
| 41 | MODULEBOOT();
|
---|
| 42 |
|
---|
| 43 | /*checks on arguments on the matlab side: */
|
---|
| 44 | CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&MeshPartitionUsage);
|
---|
| 45 |
|
---|
| 46 | /*Fetch data: */
|
---|
[11933] | 47 | FetchData(&dim,mxGetAssignedField(MODEL,0,"dimension"));
|
---|
| 48 | FetchData(&numberofelements,mxGetAssignedField(MODEL,0,"numberofelements"));
|
---|
| 49 | FetchData(&numberofvertices,mxGetAssignedField(MODEL,0,"numberofvertices"));
|
---|
| 50 | FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MODEL,0,"elements"));
|
---|
[1] | 51 |
|
---|
[4103] | 52 | if (dim==3){
|
---|
[11933] | 53 | FetchData(&numberofelements2d,mxGetAssignedField(MODEL,0,"numberofelements2d"));
|
---|
| 54 | FetchData(&numberofvertices2d,mxGetAssignedField(MODEL,0,"numberofvertices2d"));
|
---|
| 55 | FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MODEL,0,"elements2d"));
|
---|
[1] | 56 | }
|
---|
[11933] | 57 | FetchData(&numberoflayers,mxGetAssignedField(MODEL,0,"numberoflayers"));
|
---|
| 58 | FetchData(&numareas,NUMAREAS);
|
---|
[1] | 59 |
|
---|
| 60 | /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
|
---|
[10231] | 61 | MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
|
---|
| 62 | numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,dim,numareas);
|
---|
[1] | 63 |
|
---|
| 64 | /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
|
---|
[13038] | 65 | element_partitioning=xNew<double>(numberofelements);
|
---|
[1] | 66 | for (i=0;i<numberofelements;i++){
|
---|
| 67 | element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
| 68 | }
|
---|
[15396] | 69 |
|
---|
[13038] | 70 | node_partitioning=xNew<double>(numberofvertices);
|
---|
[10231] | 71 | for (i=0;i<numberofvertices;i++){
|
---|
[1] | 72 | node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /*Write data:*/
|
---|
[11933] | 76 | WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
|
---|
| 77 | WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
|
---|
[15396] | 78 |
|
---|
[1] | 79 | /*Free ressources:*/
|
---|
| 80 | //don't! let matlab do it.
|
---|
| 81 |
|
---|
| 82 | /*end module: */
|
---|
| 83 | MODULEEND();
|
---|
| 84 | }
|
---|