source: issm/trunk/src/wrappers/MeshPartition/MeshPartition.cpp@ 16560

Last change on this file since 16560 was 16560, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 16554

File size: 3.2 KB
Line 
1/*!\file: MeshPartition.cpp
2 * \brief: partition mesh according to number of areas, using Metis library.
3*/
4
5#include "./MeshPartition.h"
6
7void 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}/*}}}*/
15WRAPPER(MeshPartition){
16
17 /*Indexing: */
18 int i,j;
19
20 /* required input: */
21 int meshtype;
22 int numberofelements;
23 int numberofvertices;
24 int *elements = NULL;
25 int elements_width;
26
27 int numberofelements2d;
28 int numberofvertices2d;
29 int* 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(&numberofelements,mxGetAssignedField(MESH,0,"numberofelements"));
48 FetchData(&numberofvertices,mxGetAssignedField(MESH,0,"numberofvertices"));
49 FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MESH,0,"elements"));
50
51 if(strcmp(mxGetClassName(MESH),"mesh3d")==0){
52 meshtype = Mesh3DEnum;
53 FetchData(&numberofelements2d,mxGetAssignedField(MESH,0,"numberofelements2d"));
54 FetchData(&numberofvertices2d,mxGetAssignedField(MESH,0,"numberofvertices2d"));
55 FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MESH,0,"elements2d"));
56 FetchData(&numberoflayers,mxGetAssignedField(MESH,0,"numberoflayers"));
57 }
58 else if(strcmp(mxGetClassName(MESH),"mesh2dhorizontal")==0){
59 meshtype = Mesh2DhorizontalEnum;
60 numberoflayers=1;
61 }
62 else if(strcmp(mxGetClassName(MESH),"mesh2dvertical")==0){
63 meshtype = Mesh2DverticalEnum;
64 numberoflayers=1;
65 }
66 else{
67 _error_("Mesh type "<<mxGetClassName(MESH)<<" not supported yet");
68 }
69 FetchData(&numareas,NUMAREAS);
70
71 /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
72 MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
73 numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,meshtype,numareas);
74
75 /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
76 element_partitioning=xNew<double>(numberofelements);
77 for (i=0;i<numberofelements;i++){
78 element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
79 }
80
81 node_partitioning=xNew<double>(numberofvertices);
82 for (i=0;i<numberofvertices;i++){
83 node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
84 }
85
86 /*Write data:*/
87 WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
88 WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
89
90 /*Free ressources:*/
91 //don't! let matlab do it.
92
93 /*end module: */
94 MODULEEND();
95}
Note: See TracBrowser for help on using the repository browser.