-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalInfo.cc
More file actions
428 lines (372 loc) · 11.4 KB
/
localInfo.cc
File metadata and controls
428 lines (372 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/* attach information local to each entity */
#include <stdio.h>
#include <map>
#include "func.h"
#include "parallel.h"
#include "bits.h"
#ifdef SIM
#include "SimModel.h"
#endif
#include "MeshSimInternal.h"
#include "phParAdapt.h"
using namespace std;
/*********************************************************************
* allocate and initialize a local information array to each entity *
* in the mesh *
**********************************************************************/
//#ifdef __cplusplus
//extern "C" {
//#endif
// local information consists of:
// globalP for each entity
// the mesh is local to the calling proc
extern int globalP;
pMeshDataId MYCTID;
pMeshDataId NDOFID;
pMeshDataId POLYID;
pMeshDataId RNENID;
pMeshDataId ibcid;
pMeshDataId switid;
extern int isReorder;
extern int numParts;
extern int numTotParts;
// only in parallel
// replaces previous MeshSim functions
// declared in SimPMesh.h at least up to
// release 5.3-040830
void PMU_commuArr(void **s, int *ns, void **r, int *nr, MPI_Datatype type,
int mult)
{
int i, m, tag = 0;
MPI_Request* req = new MPI_Request[2*(PMU_size()-1)];
MPI_Status* stat= new MPI_Status[2*(PMU_size()-1)];
for (m=0, i=0; i < PMU_size(); i++) {
if (i != PMU_rank()) {
if (nr[i] > 0)
MPI_Irecv(r[i], mult*nr[i], type, i, tag, MPI_COMM_WORLD, &req[m++]);
if (ns[i] > 0)
MPI_Isend(s[i], mult*ns[i], type, i, tag, MPI_COMM_WORLD, &req[m++]);
}
}
MPI_Waitall(m, req, stat);
delete [] req;
delete [] stat;
}
void PMU_commuArr(void ***s, int **ns, void ***r, int **nr, map<int,int> *nsmap,
map<int,int> *nrmap, MPI_Datatype type, int mult)
{
int i, j, ipart, m, tag = 0, RequstSize =0;
for(m=0,ipart=0;ipart<numParts;ipart++)
RequstSize += nsmap[ipart].size() + nrmap[ipart].size();
MPI_Request* req = new MPI_Request[RequstSize];
MPI_Status* stat= new MPI_Status[RequstSize];
std::map<int,int>::iterator nsiter, nriter;
for(m=0,ipart=0;ipart<numParts;ipart++) {
for (nsiter=nsmap[ipart].begin();nsiter!=nsmap[ipart].end();nsiter++) {
i = nsiter -> first;
j = nsiter -> second;
if(ns[ipart][j]>0) {
int destID = i/numParts;
tag = i - numParts*destID;
MPI_Isend(s[ipart][j], mult*ns[ipart][j], type, destID, tag, MPI_COMM_WORLD, &req[m++]);
}
}
for (nriter=nrmap[ipart].begin();nriter!=nrmap[ipart].end();nriter++) {
i = nriter -> first;
j = nriter -> second;
if (nr[ipart][j] > 0)
MPI_Irecv(r[ipart][j], mult*nr[ipart][j], type, i/numParts, ipart, MPI_COMM_WORLD, &req[m++]);
}
}
MPI_Waitall(m, req, stat);
delete [] req;
delete [] stat;
}
//keep this function for now, just in case it is called by other functions. Take
//care of this later. Min Zhou
void PMU_commuInt(int *ns, int *nr)
{
MPI_Request* req = new MPI_Request[2*(PMU_size()-1)];
MPI_Status* stat= new MPI_Status[2*(PMU_size()-1)];
int i, m, tag = 0;
for (m=0, i=0; i < PMU_size(); i++) {
if (i != PMU_rank()) {
MPI_Irecv(nr+i, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &req[m++]);
MPI_Isend(ns+i, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &req[m++]);
}
}
MPI_Waitall(m, req, stat);
delete [] req;
delete [] stat;
}
void PMU_commuInt(int **ns, int **nr, map<int,int> *nsmap, map<int,int> *nrmap)
{
int i, m, j, ipart, tag = 0;
int RequstSize = 0;
std::map<int,int>::iterator nsiter, nriter;
map<int,int>::iterator iter1, iter2;
for(ipart=0; ipart<numParts; ipart++)
RequstSize += nsmap[ipart].size() + nrmap[ipart].size();
MPI_Request* req = new MPI_Request[RequstSize];
MPI_Status* stat= new MPI_Status[RequstSize];
for(m=0,ipart=0;ipart<numParts;ipart++) {
for (nsiter=nsmap[ipart].begin();nsiter!=nsmap[ipart].end();nsiter++) {
i = nsiter->first;
j = nsiter->second;
int destID = i/numParts;
tag = i - destID*numParts;
MPI_Isend(ns[ipart]+j, 1, MPI_INT, destID, tag, MPI_COMM_WORLD, &req[m++]);
}
for (nriter=nrmap[ipart].begin();nriter!=nrmap[ipart].end();nriter++) {
i = nriter->first;
j = nriter->second;
tag = ipart;
int fromID = i/numParts;
MPI_Irecv(nr[ipart]+j, 1, MPI_INT, fromID, tag, MPI_COMM_WORLD, &req[m++]);
}
}
MPI_Waitall(m, req, stat);
delete [] req;
delete [] stat;
}
int periocheck(pEntity ent, globalInfo *info)
{
pMatch ment;
// isPeriodic declared in setPeriodic.cc
if (isPeriodic(ent, &ment)) {
if (isOnThisProc(ment)) {
// ent is slave with master is on same proc and owner by proc
if (EN_isOwnerProc(ent)) {
return 1;
} else {
// ent is slave with master is on same proc but owner by another proc
return 3;
}
}
// ent is slave with master on another proc
PList_append(info->perSlv, ent);
PList_append(info->perMst, ment);
return 0;
}
// ent is not a periodic slave
return 2;
}
//////////////////////////////////////////////////////////////////////////////
// called in mdb2phasta
//////////////////////////////////////////////////////////////////////////////
#ifdef PARALLEL
void initLocalInfo(std::vector<pParMesh> pmesh, globalInfo **info)
#else
void initLocalInfo(pMesh mesh, globalInfo* ginfo)
#endif
{
pVertex vertex;
pEdge edge;
pFace face;
pRegion region;
pEntity ent;
VIter vIter;
EIter eIter;
FIter fIter;
RIter rIter;
int Biggest,i,j,tbit;
int localP, nen;
int p; /* typing saver for global/localP */
int ndof;
int mybig;
void *tmp;
int ipart;
int gid, pid, count, pc;
MYCTID = MD_newMeshDataId("MYCT");
NDOFID = MD_newMeshDataId("NDOF");
POLYID = MD_newMeshDataId("POLY");
RNENID = MD_newMeshDataId("RNEN");
ibcid = MD_newMeshDataId("ibc ");
switid = MD_newMeshDataId("swit");
for(ipart=0; ipart<numParts; ipart++) {
globalInfo *ginfo= info[ipart];
pMesh mesh;
#ifdef FMDB
mesh = pmesh[ipart];
#else
mesh = PM_mesh(pmesh[0], ipart);
#endif
count = 0;
if(isReorder){
ginfo->nshg = M_numVertices(mesh);
// ginfo->nshgOwn = ginfo->nshg-numVerticesNotOwn;
V_reordering(mesh, ginfo, ipart);
}
/* initializing the edge /face/ region mode info */
ginfo->edgeson =0;
ginfo->faceson =0;
ginfo->regnson =0;
ginfo->nshg = 0;
ginfo->nshgOwn = 0;
/*******************************************************************/
/* allocate and attach a local information structure to each */
/* entity in the mesh */
//
// what exactly is done here?
/*******************************************************************/
/* vertices */
vIter = M_vertexIter(mesh);
while (vertex = VIter_next(vIter)) {
/* setting the number of dofs based on localP */
localP = globalP;
EN_attachDataInt(vertex,POLYID,localP);
EN_attachDataInt(vertex,NDOFID,1);
if(!isReorder)
EN_attachDataInt(vertex,MYCTID,count++);
ginfo->nshg++;
}//while (vertex
VIter_delete(vIter);
/* edges */
eIter = M_edgeIter(mesh);
while (edge = EIter_next(eIter)) {
localP = globalP; /* P-change */
ndof = (localP) - 1;
if (localP > 1) ginfo->edgeson=1;// edgemodes only for globalP=2 and higher
EN_attachDataInt(edge,POLYID,localP);
if (ndof) {
EN_attachDataInt(edge,NDOFID,ndof);
EN_attachDataInt(edge,MYCTID,count);
count += ndof;
ginfo->nshg += ndof;
}//ndof!=0
}
EIter_delete(eIter);
/* faces */
fIter = M_faceIter(mesh);
while (face = FIter_next(fIter)) {
localP = globalP; /* P-change */
switch(F_numEdges(face)){
case 3: /* Tri Face */
if (localP > 2) {
ginfo->faceson = 1; // facemodes only for globalP=3 and higher
ndof = ((localP - 1)*(localP - 2))/2;
} else {
ndof = 0;
}
break;
case 4: /* Quad Face */
if (localP > 3) {
ginfo->faceson = 1;
ndof = ((localP - 3)*(localP - 2))/2;
} else {
ndof = 0;
}
break;
default:
fprintf(stderr,"Face with neither 3 nor 4 edges \n");
exit(1);
}
EN_attachDataInt(face,POLYID,localP);
if (ndof) {
EN_attachDataInt(face,NDOFID,ndof);
EN_attachDataInt(face,MYCTID,count);
count += ndof;
}
}
FIter_delete(fIter);
/* regions */
Biggest = 0;
rIter = M_regionIter(mesh);
while (region =RIter_next(rIter)) {
localP = globalP; /* P-change, has to be replaced with a
function which returns the maximum polynomial
order of the all the enclosed entities */
switch(topology(region)){
case 1: /* tets */
nen = 4;
Biggest = setbit(Biggest, 0);
if ((p = localP) > 3)// region modes only for globalP=4 and higher
ndof = (p-1)*(p-2)*(p-3)/6;
else ndof = 0;
break;
case 5: /* Pyramids */
nen = 5;
Biggest = setbit(Biggest, 1);
if ((p = localP) > 5)
ndof = (p-3)*(p-4)*(p-5)/6;
else ndof = 0;
break;
case 3: /* Wedges */
nen = 6;
Biggest = setbit(Biggest, 2);
if ((p = localP) > 4)
ndof = (p-2)*(p-3)*(p-4)/6;
else ndof = 0;
break;
case 2: /* Hexes */
nen = 8;
Biggest = setbit(Biggest, 3);
if ((p = localP) > 5)
ndof =(p-3)*(p-4)*(p-5)/6;
else ndof = 0;
break;
default:
fprintf(stderr,"Unknown Element type in LocalInfo\n");
exit(-1);
}
EN_attachDataInt(region,RNENID,nen);
if (ndof) ginfo->regnson = 1;
EN_attachDataInt(region,POLYID,localP);
if (ndof) {
EN_attachDataInt(region,NDOFID,ndof);
EN_attachDataInt(region,MYCTID,count);
count += ndof;
ginfo->nshg += ndof;
}
}
RIter_delete(rIter);
//suppose there is only one topology, This is not going to be right if there are
//mixed topologies. Need to come back to this later. Min Zhou
#ifdef PARALLEL
mybig = Biggest;
MPI_Allreduce(&mybig, &Biggest, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
#endif
tbit = 0;
i = 3;
while (!(tbit = getbit(Biggest,i--)) && (i >= 0));
if (!tbit) {
fprintf(stderr," Bit test for Topology has problems \n");
fprintf(stderr," Please stop in func initlocalinfo for debugging \n");
exit(1);
} else { tbit = ++i ;}
switch(tbit){
case 0: /* tets */
ginfo->nen = 4;
ginfo->nenb = 3;
ginfo->nedges = 6;
ginfo->nfaces = 4;
break;
case 1: /* Pyramids */
ginfo->nen = 5;
ginfo->nenb = 4; /* should not matter, we never let Pyramids
get on the boundaries */
ginfo->nedges = 8;
ginfo->nfaces = 5;
break;
case 2: /* Wedges */
ginfo->nen = 6;
ginfo->nenb = 4; /* wedge can also have Tri Boundary face,
keep this in mind */
ginfo->nedges = 9;
ginfo->nfaces = 5;
break;
case 3: /* Hexes */
ginfo->nen = 8;
ginfo->nenb = 4;
ginfo->nedges = 12;
ginfo->nfaces = 6;
break;
default:
fprintf(stderr,"Unknown Element type in LocalInfo\n");
exit(-1);
}
}
}
//#ifdef __cplusplus
//}
//#endif