1 | /*!\file: ElementsAndVerticesPartitioning.cpp
|
---|
2 | * \brief: partition elements and nodes and vertices
|
---|
3 | */
|
---|
4 |
|
---|
5 | #ifdef HAVE_CONFIG_H
|
---|
6 | #include <config.h>
|
---|
7 | #else
|
---|
8 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | #include <string.h>
|
---|
12 | #include "../../classes/classes.h"
|
---|
13 | #include "../../shared/shared.h"
|
---|
14 | #include "../MeshPartitionx/MeshPartitionx.h"
|
---|
15 | #include "../ModelProcessorx/ModelProcessorx.h"
|
---|
16 |
|
---|
17 | void ElementsAndVerticesPartitioning(IoModel* iomodel){
|
---|
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 | /*Partition and free resouces*/
|
---|
63 | MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshelementtype,num_procs);
|
---|
64 | xDelete<int>(elements2d);
|
---|
65 | xDelete<int>(npart);
|
---|
66 |
|
---|
67 | /*Deal with rifts, they have to be included into one partition only, not several: */
|
---|
68 | int numrifts;
|
---|
69 | iomodel->FindConstant(&numrifts,"md.rifts.numrifts");
|
---|
70 | if(numrifts){
|
---|
71 | IssmDouble *riftinfo = NULL;
|
---|
72 | iomodel->FetchData(&riftinfo,&numrifts,NULL,"md.rifts.riftstruct");
|
---|
73 | for(int i=0;i<numrifts;i++){
|
---|
74 | const int RIFTINFOSIZE = 12;
|
---|
75 | int el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
|
---|
76 | int el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
|
---|
77 | epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
|
---|
78 | }
|
---|
79 | iomodel->DeleteData(riftinfo,"md.rifts.riftstruct");
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*Create my_elements, used by each partition */
|
---|
83 | bool *my_elements = xNewZeroInit<bool>(iomodel->numberofelements);
|
---|
84 |
|
---|
85 | /*Start figuring out, out of the partition, which elements belong to this cpu: */
|
---|
86 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
87 |
|
---|
88 | /*!All elements have been partitioned above, only deal with elements for this cpu: */
|
---|
89 | if(my_rank==epart[i]) my_elements[i]=true;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /*Assign pointers to iomodel*/
|
---|
93 | iomodel->epart =epart;
|
---|
94 | iomodel->my_elements=my_elements;
|
---|
95 | }
|
---|