1 | /*!\file: MeshPartition.cpp
|
---|
2 | * \brief: partition mesh according to number of areas, using Metis library.
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "./MeshPartition.h"
|
---|
6 |
|
---|
7 | void MeshPartitionUsage(void){/*{{{*/
|
---|
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");
|
---|
14 | }/*}}}*/
|
---|
15 | WRAPPER(MeshPartition_python){
|
---|
16 |
|
---|
17 | /* required input: */
|
---|
18 | int numberofelements;
|
---|
19 | int numberofvertices;
|
---|
20 | int *elements = NULL;
|
---|
21 | int elements_width;
|
---|
22 | int numberofelements2d=0;
|
---|
23 | int numberofvertices2d=0;
|
---|
24 | int* elements2d=NULL;
|
---|
25 | int numberoflayers;
|
---|
26 | int numareas=1;
|
---|
27 |
|
---|
28 | /* output: */
|
---|
29 | int *int_element_partitioning = NULL;
|
---|
30 | int *int_node_partitioning = NULL;
|
---|
31 | double *element_partitioning = NULL;
|
---|
32 | double *node_partitioning = NULL;
|
---|
33 |
|
---|
34 | /*Boot module: */
|
---|
35 | MODULEBOOT();
|
---|
36 |
|
---|
37 | /*checks on arguments on the matlab side: */
|
---|
38 | CHECKARGUMENTS(NLHS,NRHS,&MeshPartitionUsage);
|
---|
39 |
|
---|
40 | /*Fetch data: */
|
---|
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);
|
---|
46 | FetchData(&numareas,NUMAREAS);
|
---|
47 |
|
---|
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 |
|
---|
54 | /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
|
---|
55 | MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
|
---|
56 | numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,meshelementtype,numareas);
|
---|
57 |
|
---|
58 | /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
|
---|
59 | element_partitioning=xNew<double>(numberofelements);
|
---|
60 | for(int i=0;i<numberofelements;i++){
|
---|
61 | element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
62 | }
|
---|
63 |
|
---|
64 | node_partitioning=xNew<double>(numberofvertices);
|
---|
65 | for(int i=0;i<numberofvertices;i++){
|
---|
66 | node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*Write data:*/
|
---|
70 | WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
|
---|
71 | WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
|
---|
72 |
|
---|
73 | /*Free ressources:*/
|
---|
74 | xDelete<int>(elements);
|
---|
75 | xDelete<int>(elements2d);
|
---|
76 | xDelete<int>(int_element_partitioning);
|
---|
77 | xDelete<int>(int_node_partitioning);
|
---|
78 | xDelete<double>(element_partitioning);
|
---|
79 | xDelete<double>(node_partitioning);
|
---|
80 |
|
---|
81 | /*end module: */
|
---|
82 | MODULEEND();
|
---|
83 | }
|
---|