source: issm/trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp@ 16334

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

CHG: adding case mesh2dvertical

File size: 5.2 KB
Line 
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
17void ElementsAndVerticesPartitioning(bool** pmy_elements, int** pmy_vertices, IoModel* iomodel){
18
19 int i;
20
21 int my_rank;
22 int num_procs;
23 int numberofelements2d;
24 int numberofvertices2d;
25 int numlayers;
26 int numrifts;
27 int numvertex_pairing;
28
29 /*output: */
30 bool *my_elements = NULL;
31 int *my_vertices = NULL;
32
33 /*intermediary: */
34 int *epart = NULL; //element partitioning.
35 int *npart = NULL; //node partitioning.
36 int elements_width; //number of columns in elements (2d->3, 3d->6)
37 int el1,el2;
38 int *elements2d = NULL;
39 int *vertex_pairing = NULL;
40 IssmDouble *riftinfo = NULL;
41
42 /*Get my_rank:*/
43 my_rank = IssmComm::GetRank();
44 num_procs = IssmComm::GetSize();
45
46 /*Fetch parameters: */
47
48 iomodel->Constant(&numrifts,RiftsNumriftsEnum);
49
50 /*First, check that partitioning has not yet been carryed out. Just check whether my_elements pointers is not already assigned a value: */
51 if (*pmy_elements)return;
52
53 /*Number of vertices per elements, needed to correctly retrieve data: */
54 /*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
55 switch(iomodel->meshtype){
56 case Mesh2DhorizontalEnum:
57 elements_width=3;
58 numberofelements2d = 0;
59 numberofvertices2d = 0;
60 numlayers = 0;
61 break;
62 case Mesh2DverticalEnum:
63 elements_width=3;
64 numberofelements2d = 0;
65 numberofvertices2d = 0;
66 numlayers = 0;
67 break;
68 case Mesh3DEnum:
69 elements_width=6; //penta elements
70 iomodel->FetchData(&elements2d,NULL,NULL,MeshElements2dEnum);
71 iomodel->Constant(&numberofelements2d,MeshNumberofelements2dEnum);
72 iomodel->Constant(&numberofvertices2d,MeshNumberofvertices2dEnum);
73 iomodel->Constant(&numlayers,MeshNumberoflayersEnum);
74 break;
75 default:
76 _error_("mesh not supported yet");
77 }
78
79 MeshPartitionx(&epart,&npart,iomodel->numberofelements,iomodel->numberofvertices,iomodel->elements,numberofelements2d,numberofvertices2d,elements2d,numlayers,elements_width,iomodel->meshtype,num_procs);
80
81 /*Free elements2d: */
82 xDelete<int>(elements2d);
83
84 /*Deal with rifts, they have to be included into one partition only, not several: */
85 if(numrifts){
86 iomodel->FetchData(&riftinfo,&numrifts,NULL,RiftsRiftstructEnum);
87 for(i=0;i<numrifts;i++){
88 el1=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+2))-1; //matlab indexing to c indexing
89 el2=reCast<int>(*(riftinfo+RIFTINFOSIZE*i+3))-1; //matlab indexing to c indexing
90 epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
91 }
92 iomodel->DeleteData(riftinfo,RiftsRiftstructEnum);
93 }
94
95 /*Used later on: */
96 my_vertices=xNewZeroInit<int>(iomodel->numberofvertices);
97 my_elements=xNewZeroInit<bool>(iomodel->numberofelements);
98
99 /*Start figuring out, out of the partition, which elements belong to this cpu: */
100 for (i=0;i<iomodel->numberofelements;i++){
101
102 /*!All elements have been partitioned above, only deal with elements for this cpu: */
103 if(my_rank==epart[i]){
104
105 my_elements[i]=true;
106
107 /*Now that we are here, we can also start building the list of vertices belonging to this cpu partition: we use
108 *the element index to do this. For each element n, we know index[n][0:2] holds the indices (matlab indexing)
109 into the vertices coordinates. If we start plugging 1 into my_vertices for each index[n][i] (i=0:2), then my_vertices
110 will hold which vertices belong to this partition*/
111 my_vertices[iomodel->elements[elements_width*i+0]-1]=1;
112 my_vertices[iomodel->elements[elements_width*i+1]-1]=1;
113 my_vertices[iomodel->elements[elements_width*i+2]-1]=1;
114
115 if(elements_width==6){
116 my_vertices[iomodel->elements[elements_width*i+3]-1]=1;
117 my_vertices[iomodel->elements[elements_width*i+4]-1]=1;
118 my_vertices[iomodel->elements[elements_width*i+5]-1]=1;
119 }
120 }
121 }
122
123 /*We might have vertex_pairing in which case, some vertices have to be cloned:
124 * penpair has 2 nodes that are poointing toward 2 vertices.
125 * The 2 vertices must be in the same cpu as the penpair*/
126 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,StressbalanceVertexPairingEnum);
127 for(i=0;i<numvertex_pairing;i++){
128 if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
129 my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
130 }
131 }
132 xDelete<int>(vertex_pairing);
133 iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,MasstransportVertexPairingEnum);
134 for(i=0;i<numvertex_pairing;i++){
135 if(my_vertices[vertex_pairing[2*i+0]-1] && !my_vertices[vertex_pairing[2*i+1]-1]){
136 my_vertices[vertex_pairing[2*i+1]-1]=2; //to know that these elements are not on the partition
137 }
138 }
139 xDelete<int>(vertex_pairing);
140
141 /*Free ressources:*/
142 xDelete<int>(npart);
143 xDelete<int>(epart);
144
145 /*Assign output pointers:*/
146 *pmy_elements=my_elements;
147 *pmy_vertices=my_vertices;
148}
Note: See TracBrowser for help on using the repository browser.