Ice Sheet System Model  4.18
Code documentation
Functions
ElementsAndVerticesPartitioning.cpp File Reference

: partition elements and nodes and vertices More...

#include <string.h>
#include "../../classes/classes.h"
#include "../../shared/shared.h"
#include "../MeshPartitionx/MeshPartitionx.h"
#include "../ModelProcessorx/ModelProcessorx.h"

Go to the source code of this file.

Functions

void ElementsAndVerticesPartitioning (IoModel *iomodel)
 

Detailed Description

: partition elements and nodes and vertices

Definition in file ElementsAndVerticesPartitioning.cpp.

Function Documentation

◆ ElementsAndVerticesPartitioning()

void ElementsAndVerticesPartitioning ( IoModel iomodel)

All elements have been partitioned above, only deal with elements for this cpu:

Definition at line 17 of file ElementsAndVerticesPartitioning.cpp.

17  {
18 
19  int numberofelements2d;
20  int numberofvertices2d;
21  int numlayers;
22 
23  /*intermediary: */
24  int *epart = NULL; //element partitioning.
25  int *npart = NULL; //node partitioning.
26  int elements_width; //number of columns in elements (2d->3, 3d->6)
27  int *elements2d = NULL;
28 
29  /*Get my_rank:*/
30  int my_rank = IssmComm::GetRank();
31  int num_procs = IssmComm::GetSize();
32 
33  /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
34  if(iomodel->my_elements) return;
35 
36  /*Number of vertices per elements, needed to correctly retrieve data: */
37  /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
38  switch(iomodel->meshelementtype){
39  case TriaEnum:
40  elements_width=3;
41  numberofelements2d = 0;
42  numberofvertices2d = 0;
43  numlayers = 0;
44  break;
45  case TetraEnum:
46  elements_width=4;
47  numberofelements2d = 0;
48  numberofvertices2d = 0;
49  numlayers = 0;
50  break;
51  case PentaEnum:
52  elements_width=6;
53  iomodel->FetchData(&elements2d,NULL,NULL,"md.mesh.elements2d");
54  iomodel->FindConstant(&numberofelements2d,"md.mesh.numberofelements2d");
55  iomodel->FindConstant(&numberofvertices2d,"md.mesh.numberofvertices2d");
56  iomodel->FindConstant(&numlayers,"md.mesh.numberoflayers");
57  break;
58  default:
59  _error_("mesh elements "<< EnumToStringx(iomodel->meshelementtype) <<" not supported yet");
60  }
61 
62  /*Use ice levelset for weights*/
63  int fordan = 0;
64  int* weights = NULL;
65  if(fordan){
66  IssmDouble* icelevelset = NULL;
67  iomodel->FetchData(&icelevelset,NULL,NULL,"md.mask.ice_levelset");
68 
69  weights = xNew<int>(iomodel->numberofvertices);
70  for(int i=0;i<iomodel->numberofvertices;i++){
71  if(icelevelset[i]>=0) weights[i] = 1;
72  if(icelevelset[i]<0) weights[i] = 100;
73  }
74  xDelete<IssmDouble>(icelevelset);
75  }
76 
77  /*Partition and free resouces*/
78  MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,weights,numlayers,elements_width,iomodel->meshelementtype,num_procs);
79  xDelete<int>(elements2d);
80  xDelete<int>(npart);
81  xDelete<int>(weights);
82 
83  if(fordan){
84  for(int i=0;i<IssmComm::GetSize();i++){
85  if(i==IssmComm::GetRank()){
86  int temp =0;
87  for(int j=0;j<iomodel->numberofelements;j++) if(epart[j]==i) temp++;
88  _printf_("Partition #"<<i<<" number of elements: "<<temp<<"\n");
89  }
91  }
92  }
93 
94  /*Deal with rifts, they have to be included into one partition only, not several: */
95  int numrifts;
96  iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
97  if(numrifts){
98  IssmDouble *riftinfo = NULL;
99  iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct");
100  for(int i=0;i<numrifts;i++){
101  const int RIFTINFOSIZE = 12;
102  int el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
103  int el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
104  epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
105  }
106  iomodel->DeleteData(riftinfo,"md.rifts.riftstruct");
107  }
108 
109  /*Create my_elements, used by each partition */
110  bool *my_elements = xNewZeroInit<bool>(iomodel->numberofelements);
111 
112  /*Start figuring out, out of the partition, which elements belong to this cpu: */
113  for(int i=0;i<iomodel->numberofelements;i++){
114 
116  if(my_rank==epart[i]) my_elements[i]=true;
117  }
118 
119  /*Assign pointers to iomodel*/
120  iomodel->epart =epart;
121  iomodel->my_elements=my_elements;
122 }
IssmDouble
double IssmDouble
Definition: types.h:37
TetraEnum
@ TetraEnum
Definition: EnumDefinitions.h:1300
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
IoModel::my_elements
bool * my_elements
Definition: IoModel.h:66
IoModel::numberofvertices
int numberofvertices
Definition: IoModel.h:99
IoModel::DeleteData
void DeleteData(int num,...)
Definition: IoModel.cpp:500
IoModel::numberofelements
int numberofelements
Definition: IoModel.h:96
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
IssmComm::GetSize
static int GetSize(void)
Definition: IssmComm.cpp:46
IoModel::FindConstant
void FindConstant(bool *pvalue, const char *constant_name)
Definition: IoModel.cpp:2362
IoModel::FetchData
void FetchData(bool *pboolean, const char *data_name)
Definition: IoModel.cpp:933
MeshPartitionx
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: MeshPartitionx.h:12
IssmComm::GetRank
static int GetRank(void)
Definition: IssmComm.cpp:34
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
PentaEnum
@ PentaEnum
Definition: EnumDefinitions.h:1231
ISSM_MPI_Barrier
int ISSM_MPI_Barrier(ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:148
IoModel::epart
int * epart
Definition: IoModel.h:74
IoModel::elements
int * elements
Definition: IoModel.h:79
IoModel::meshelementtype
int meshelementtype
Definition: IoModel.h:91
TriaEnum
@ TriaEnum
Definition: EnumDefinitions.h:1318