Ice Sheet System Model  4.18
Code documentation
Functions
MeshPartitionx.h File Reference

header file for partitioning module. More...

#include "../../shared/shared.h"

Go to the source code of this file.

Functions

template<class doubletype >
int MeshPartitionx (int **pepart, int **pnpart, int numberofelements, int numberofnodes, int *elements, int numberofelements2d, int numberofnodes2d, doubletype *elements2d, int *vweights, int numlayers, int elements_width, int meshelementtype, int num_procs)
 

Detailed Description

header file for partitioning module.

Definition in file MeshPartitionx.h.

Function Documentation

◆ MeshPartitionx()

template<class doubletype >
int MeshPartitionx ( int **  pepart,
int **  pnpart,
int  numberofelements,
int  numberofnodes,
int *  elements,
int  numberofelements2d,
int  numberofnodes2d,
doubletype *  elements2d,
int *  vweights,
int  numlayers,
int  elements_width,
int  meshelementtype,
int  num_procs 
)

Definition at line 12 of file MeshPartitionx.h.

13  {
14 
15  int noerr=1;
16  int i,j;
17 
18  /*Metis partitioning: */
19  int* epart=NULL;
20  int* npart=NULL;
21  int* index=NULL;
22 
23  int* epart2d=NULL;
24  int* npart2d=NULL;
25  int* index2d=NULL;
26  int count=0;
27 
28 
29  switch(meshelementtype){
30  case TriaEnum:
31  case TetraEnum:
32  epart=xNew<int>(numberofelements);
33  npart=xNew<int>(numberofnodes);
34  index=xNew<int>(elements_width*numberofelements);
35  for (i=0;i<numberofelements;i++){
36  for (j=0;j<elements_width;j++){
37  *(index+elements_width*i+j)=(*(elements+elements_width*i+j))-1; //-1 for C indexing in Metis
38  }
39  }
40 
41  /*Partition using Metis:*/
42  if (num_procs>1){
43 #ifdef _HAVE_METIS_
44  METIS_PartMeshNodalPatch(numberofelements,numberofnodes,index,vweights,num_procs,epart, npart);
45 #else
46  _error_("metis has not beed installed. Cannot run with more than 1 cpu");
47 #endif
48  }
49  else if (num_procs==1){
50  /*METIS does not know how to deal with one cpu only!*/
51  for (i=0;i<numberofelements;i++) epart[i]=0;
52  for (i=0;i<numberofnodes;i++) npart[i]=0;
53  }
54  else _error_("At least one processor is required");
55  break;
56  case PentaEnum:
57  /*We have a 3d mesh, made of a regularly extruded 2d mesh. We first partition the 2d mesh, then we extrude the partition: */
58 
59  /*First build concatenated 2d mesh from 2d_coll and 2d_noncoll: */
60  epart2d=xNew<int>(numberofelements2d);
61  npart2d=xNew<int>(numberofnodes2d);
62  index2d=xNew<int>(3*numberofelements2d);
63 
64  for (i=0;i<numberofelements2d;i++){
65  for (j=0;j<3;j++){
66  *(index2d+3*i+j)=reCast<int>(*(elements2d+3*i+j))-1; //-1 for C indexing in Metis
67  }
68  }
69 
70  /*Partition using Metis:*/
71  if (num_procs>1){
72 #ifdef _HAVE_METIS_
73  METIS_PartMeshNodalPatch(numberofelements2d,numberofnodes2d,index2d,vweights,num_procs,epart2d,npart2d);
74 #else
75  _error_("metis has not beed installed. Cannot run with more than 1 cpu");
76 #endif
77  }
78  else if (num_procs==1){
79  /*METIS does not know how to deal with one cpu only!*/
80  for (i=0;i<numberofelements2d;i++) epart2d[i]=0;
81  for (i=0;i<numberofnodes2d;i++) npart2d[i]=0;
82  }
83  else _error_("At least one processor is required");
84 
85  /*Extrude epart2d to epart, using numlayers: */
86  epart=xNew<int>(numberofelements);
87 
88  count=0;
89  for(i=0;i<(numlayers-1);i++){
90  for(j=0;j<numberofelements2d;j++){
91  epart[count]=epart2d[j];
92  count++;
93  }
94  }
95 
96  /*Extrude npart2d to npart, using numlayers: */
97  npart=xNew<int>(numberofnodes);
98 
99  count=0;
100  for(i=0;i<(numlayers);i++){
101  for(j=0;j<numberofnodes2d;j++){
102  npart[count]=npart2d[j];
103  count++;
104  }
105  }
106  break;
107  default:
108  _error_("mesh type "<<EnumToStringx(meshelementtype)<<" not supported yet");
109  }
110 
111  /*Assign output pointer:*/
112  *pepart=epart;
113  *pnpart=npart;
114 
115  /*Free ressources: */
116  xDelete<int>(index);
117  xDelete<int>(epart2d);
118  xDelete<int>(npart2d);
119  xDelete<int>(index2d);
120  return noerr;
121 }
TetraEnum
@ TetraEnum
Definition: EnumDefinitions.h:1300
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
METIS_PartMeshNodalPatch
void METIS_PartMeshNodalPatch(int numberofelements, int numberofnodes, int *index, int *vweights, int num_procs, int *epart, int *npart)
Definition: METIS_PartMeshNodalPatch.cpp:20
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
PentaEnum
@ PentaEnum
Definition: EnumDefinitions.h:1231
TriaEnum
@ TriaEnum
Definition: EnumDefinitions.h:1318