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

Last change on this file since 20500 was 20500, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 20497

File size: 3.4 KB
RevLine 
[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]7void 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}/*}}}*/
15WRAPPER(MeshPartition){
[1]16
17 /*Indexing: */
18 int i,j;
19
20 /* required input: */
[17806]21 int meshelementtype;
[16560]22 int numberofelements;
23 int numberofvertices;
24 int *elements = NULL;
25 int elements_width;
[1]26
27 int numberofelements2d;
[10231]28 int numberofvertices2d;
[16137]29 int* elements2d=NULL;
[1]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: */
[16560]47 FetchData(&numberofelements,mxGetAssignedField(MESH,0,"numberofelements"));
48 FetchData(&numberofvertices,mxGetAssignedField(MESH,0,"numberofvertices"));
49 FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MESH,0,"elements"));
[1]50
[17806]51 if(strcmp(mxGetClassName(MESH),"mesh3dprisms")==0){
52 meshelementtype = PentaEnum;
[16560]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"));
[1]57 }
[16560]58 else if(strcmp(mxGetClassName(MESH),"mesh2dhorizontal")==0){
[17806]59 meshelementtype = TriaEnum;
[16560]60 numberoflayers=1;
61 }
62 else if(strcmp(mxGetClassName(MESH),"mesh2dvertical")==0){
[17806]63 meshelementtype = TriaEnum;
[16560]64 numberoflayers=1;
65 }
66 else{
67 _error_("Mesh type "<<mxGetClassName(MESH)<<" not supported yet");
68 }
[11933]69 FetchData(&numareas,NUMAREAS);
[1]70
71 /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
[10231]72 MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
[17806]73 numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,meshelementtype,numareas);
[1]74
75 /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
[13038]76 element_partitioning=xNew<double>(numberofelements);
[1]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 }
[15396]80
[13038]81 node_partitioning=xNew<double>(numberofvertices);
[10231]82 for (i=0;i<numberofvertices;i++){
[1]83 node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
84 }
85
86 /*Write data:*/
[11933]87 WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
88 WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
[15396]89
[1]90 /*Free ressources:*/
[20500]91 xDelete<int>(elements);
92 xDelete<int>( elements2d);
93 xDelete<int>(int_element_partitioning);
94 xDelete<int>(int_node_partitioning);
95 xDelete<double>(element_partitioning);
96 xDelete<double>(node_partitioning);
[1]97
98 /*end module: */
99 MODULEEND();
100}
Note: See TracBrowser for help on using the repository browser.