[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 | }/*}}}*/
|
---|
[21341] | 15 | WRAPPER(MeshPartition_python){
|
---|
[1] | 16 |
|
---|
| 17 | /* required input: */
|
---|
[16560] | 18 | int numberofelements;
|
---|
| 19 | int numberofvertices;
|
---|
[22758] | 20 | int *elements = NULL;
|
---|
[16560] | 21 | int elements_width;
|
---|
[22758] | 22 | int numberofelements2d=0;
|
---|
| 23 | int numberofvertices2d=0;
|
---|
[16137] | 24 | int* elements2d=NULL;
|
---|
[10231] | 25 | int numberoflayers;
|
---|
[1] | 26 | int numareas=1;
|
---|
| 27 |
|
---|
| 28 | /* output: */
|
---|
[10231] | 29 | int *int_element_partitioning = NULL;
|
---|
| 30 | int *int_node_partitioning = NULL;
|
---|
| 31 | double *element_partitioning = NULL;
|
---|
| 32 | double *node_partitioning = NULL;
|
---|
[1] | 33 |
|
---|
| 34 | /*Boot module: */
|
---|
| 35 | MODULEBOOT();
|
---|
| 36 |
|
---|
| 37 | /*checks on arguments on the matlab side: */
|
---|
[22758] | 38 | CHECKARGUMENTS(NLHS,NRHS,&MeshPartitionUsage);
|
---|
[1] | 39 |
|
---|
| 40 | /*Fetch data: */
|
---|
[22758] | 41 | FetchData(&numberofvertices,NUMBEROFVERTICES);
|
---|
| 42 | FetchData(&elements,&numberofelements,&elements_width,ELEMENTS);
|
---|
| 43 | FetchData(&numberofvertices2d,NUMBEROFVERTICES2D);
|
---|
| 44 | FetchData(&elements2d,&numberofelements2d,NULL,ELEMENTS2D);
|
---|
| 45 | FetchData(&numberoflayers,NUMBEROFLAYERS);
|
---|
[11933] | 46 | FetchData(&numareas,NUMAREAS);
|
---|
[1] | 47 |
|
---|
[22758] | 48 | /*Get mesh element type and convert to Enum*/
|
---|
| 49 | char* meshtype_str = NULL;
|
---|
| 50 | FetchData(&meshtype_str,MESHELEMENTTYPE);
|
---|
| 51 | int meshelementtype = StringToEnumx(meshtype_str);
|
---|
| 52 | xDelete<char>(meshtype_str);
|
---|
| 53 |
|
---|
[1] | 54 | /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
|
---|
[10231] | 55 | MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
|
---|
[17806] | 56 | numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,meshelementtype,numareas);
|
---|
[1] | 57 |
|
---|
| 58 | /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
|
---|
[13038] | 59 | element_partitioning=xNew<double>(numberofelements);
|
---|
[22758] | 60 | for(int i=0;i<numberofelements;i++){
|
---|
[1] | 61 | element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
| 62 | }
|
---|
[15396] | 63 |
|
---|
[13038] | 64 | node_partitioning=xNew<double>(numberofvertices);
|
---|
[22758] | 65 | for(int i=0;i<numberofvertices;i++){
|
---|
[1] | 66 | node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /*Write data:*/
|
---|
[11933] | 70 | WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
|
---|
| 71 | WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
|
---|
[15396] | 72 |
|
---|
[1] | 73 | /*Free ressources:*/
|
---|
[20500] | 74 | xDelete<int>(elements);
|
---|
[22758] | 75 | xDelete<int>(elements2d);
|
---|
[20500] | 76 | xDelete<int>(int_element_partitioning);
|
---|
| 77 | xDelete<int>(int_node_partitioning);
|
---|
| 78 | xDelete<double>(element_partitioning);
|
---|
| 79 | xDelete<double>(node_partitioning);
|
---|
[1] | 80 |
|
---|
| 81 | /*end module: */
|
---|
| 82 | MODULEEND();
|
---|
| 83 | }
|
---|