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){
|
---|
16 |
|
---|
17 | /*Indexing: */
|
---|
18 | int i,j;
|
---|
19 |
|
---|
20 | /* required input: */
|
---|
21 | int dim;
|
---|
22 | int numberofelements;
|
---|
23 | int numberofvertices;
|
---|
24 | double *elements = NULL;
|
---|
25 | int elements_width;
|
---|
26 |
|
---|
27 | int numberofelements2d;
|
---|
28 | int numberofvertices2d;
|
---|
29 | double* elements2d=NULL;
|
---|
30 |
|
---|
31 | int numberoflayers;
|
---|
32 | int numareas=1;
|
---|
33 |
|
---|
34 | /* output: */
|
---|
35 | int *int_element_partitioning = NULL;
|
---|
36 | int *int_node_partitioning = NULL;
|
---|
37 | double *element_partitioning = NULL;
|
---|
38 | double *node_partitioning = NULL;
|
---|
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: */
|
---|
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"));
|
---|
51 |
|
---|
52 | if (dim==3){
|
---|
53 | FetchData(&numberofelements2d,mxGetAssignedField(MODEL,0,"numberofelements2d"));
|
---|
54 | FetchData(&numberofvertices2d,mxGetAssignedField(MODEL,0,"numberofvertices2d"));
|
---|
55 | FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MODEL,0,"elements2d"));
|
---|
56 | }
|
---|
57 | FetchData(&numberoflayers,mxGetAssignedField(MODEL,0,"numberoflayers"));
|
---|
58 | FetchData(&numareas,NUMAREAS);
|
---|
59 |
|
---|
60 | /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
|
---|
61 | MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
|
---|
62 | numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,dim,numareas);
|
---|
63 |
|
---|
64 | /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
|
---|
65 | element_partitioning=xNew<double>(numberofelements);
|
---|
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 | }
|
---|
69 |
|
---|
70 | node_partitioning=xNew<double>(numberofvertices);
|
---|
71 | for (i=0;i<numberofvertices;i++){
|
---|
72 | node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*Write data:*/
|
---|
76 | WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
|
---|
77 | WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
|
---|
78 |
|
---|
79 | /*Free ressources:*/
|
---|
80 | //don't! let matlab do it.
|
---|
81 |
|
---|
82 | /*end module: */
|
---|
83 | MODULEEND();
|
---|
84 | }
|
---|