-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdistribute.cpp
More file actions
2636 lines (2271 loc) · 68.5 KB
/
distribute.cpp
File metadata and controls
2636 lines (2271 loc) · 68.5 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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
// SPDX-License-Identifier: BSD-3-Clause
// The code here replicates the Fortran code in DISTRIBUTE.f.
#include "distribute.h"
#include "all_fun.h"
#include "ComMod.h"
#include "consts.h"
#include "nn.h"
#include "utils.h"
#include "CmMod.h"
#include "mpi.h"
#include <iostream>
#include <math.h>
extern "C" {
int split_(int *nElptr, int *eNoNptr, int *eNoNbptr, int *IEN, int *nPartsPtr, int *iElmdist, float *iWgt, int *part);
};
/// @brief Partition and distribute data across processors.
///
/// This function replicates the Fortran 'SUBROUTINE DISTRIBUTE' in DISTRIBUTE.f.
//
void distribute(Simulation* simulation)
{
auto& cm_mod = simulation->cm_mod;
auto& chnl_mod = simulation->chnl_mod;
auto& com_mod = simulation->com_mod;
auto& cm = com_mod.cm;
#define n_debug_distribute
#ifdef debug_distribute
DebugMsg dmsg(__func__, com_mod.cm.idcm());
dmsg.banner();
dmsg << " com_mod.resetSim: " << com_mod.resetSim;
#endif
if (!com_mod.resetSim) {
cm.bcast(cm_mod, &chnl_mod.pClr);
cm.bcast(cm_mod, chnl_mod.appPath);
#ifdef debug_distribute
dmsg << " chnl_mod.pClr: " << chnl_mod.pClr;
dmsg << " chnl_mod.appPath: " << chnl_mod.appPath;
#endif
//[TODO:Davep] add this?
//CALL cm%bcast(wrn%oTS)
//wrn%oTF = wrn%oTS
// Constructing data structures one by one
cm.bcast(cm_mod, &com_mod.nMsh);
cm.bcast(cm_mod, &com_mod.nsd);
cm.bcast(cm_mod, &com_mod.rmsh.isReqd);
}
cm.bcast(cm_mod, &com_mod.gtnNo);
if (cm.slv(cm_mod)) {
com_mod.msh.resize(com_mod.nMsh);
#ifdef debug_distribute
dmsg << "slave process " << "";
#endif
} else {
#ifdef debug_distribute
dmsg << "master process " << "";
#endif
}
#ifdef debug_distribute
dmsg << "nMsh: " << com_mod.nMsh;
dmsg << "gtnNo: " << com_mod.gtnNo;
dmsg << "nsd: " << com_mod.nsd;
#endif
// wgt and wrk are the assigned portion of each mesh to the each
// processor.
//
int nMsh = com_mod.nMsh;
int num_proc = cm.np();
Array<double> wgt(nMsh, num_proc);
Vector<double> wrk(nMsh);
// Here is rough estimation of how each mesh should be splited
// between processors
//
//wrk = REAL(msh%gnNo, KIND=RKIND)/REAL(gtnNo, KIND=RKIND)
//
#ifdef debug_distribute
dmsg << "Rough estimation of how each mesh split ..." << " ";
#endif
for (int i = 0; i < com_mod.msh.size(); i++) {
wrk[i] = static_cast<double>(com_mod.msh[i].gnNo) / com_mod.gtnNo;
#ifdef debug_distribute
dmsg << "---------- i " << i;
dmsg << "msh[i].name: " << com_mod.msh[i].name;
dmsg << "msh[i].gnNo: " << com_mod.msh[i].gnNo;
dmsg << "com_mod.gtnNo: " << com_mod.gtnNo;
dmsg << "msh[i].nNo: " << com_mod.msh[i].nNo;
dmsg << "msh[i].msh.nEl: " << com_mod.msh[i].nEl;
dmsg << "wrk[i]: " << wrk[i];
#endif
}
cm.bcast(cm_mod, wrk);
int task_id = com_mod.cm.idcm();
all_fun::split_jobs(task_id, nMsh, num_proc, wgt, wrk);
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Split jobs .. " << " ";
dmsg << "wrk: " << wrk;
dmsg << "wgt: " << wgt;
#endif
// First partitioning the meshes
// gmtl: gtnNo --> tnNo
//
#ifdef debug_distribute
dmsg << "Partition meshes " << " ...";
#endif
com_mod.tnNo = 0;
if (cm.seq()) {
com_mod.tnNo = com_mod.gtnNo;
com_mod.ltg.resize(com_mod.tnNo);
for (int a = 0; a < com_mod.tnNo; a++) {
com_mod.ltg[a] = a;
}
}
Vector<int> gmtl(com_mod.gtnNo);
Vector<float> iWgt(num_proc);
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "wgt: " << wgt;
#endif
// Need the ris flag here
cm.bcast(cm_mod, &com_mod.risFlag);
// Communicating RIS info
if (com_mod.risFlag) {
dist_ris(com_mod, cm_mod, cm);
}
// Need the uris flag here
cm.bcast(cm_mod, &com_mod.urisFlag);
if (com_mod.urisFlag) {
dist_uris(com_mod, cm_mod, cm);
}
int risProc = -1;
int jM = 0;
for (int iM = 0; iM < nMsh; iM++) {
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Partitioning mesh: " << iM;
#endif
auto sum = wgt.sum_row(iM);
for (int i = 0; i < num_proc; i++) {
iWgt[i] = wgt(iM,i) / sum;
}
#ifdef debug_distribute
dmsg << "iWgt: " << iWgt;
#endif
if (com_mod.risFlag) {
for (int iProj = 0; iProj < com_mod.ris.nbrRIS; iProj++) {
// Find the adjacent mesh
if (com_mod.ris.lst(0,0,iProj) == iM) {
jM = com_mod.ris.lst(1,0,iProj);
} else if (com_mod.ris.lst(1,0,iProj) == iM) {
jM = com_mod.ris.lst(0,0,iProj);
} else {
continue;
}
// Right now just assign all nodes to the same proc
risProc = -1;
for (int e = 0; e < com_mod.msh[jM].gnEl; e++) {
if (com_mod.msh[jM].eRIS(e)) {
risProc = com_mod.msh[jM].partRIS(e);
break;
}
}
if (risProc != -1) {
for (int e = 0; e < com_mod.msh[iM].gnEl; e++) {
if (com_mod.msh[iM].eRIS(e)) {
com_mod.msh[iM].partRIS(e) = risProc;
}
}
}
}
}
part_msh(simulation, iM, com_mod.msh[iM], gmtl, num_proc, iWgt);
}
// Setting gtl pointer in case that it is needed and mapping IEN.
//
int tnNo = com_mod.tnNo;
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Setting gtl pointer " << " ...";
dmsg << "tnNo: " << tnNo;
#endif
for (int iM = 0; iM < nMsh; iM++) {
auto& msh = com_mod.msh[iM];
msh.lN.resize(tnNo);
#ifdef debug_distribute
dmsg << "---------- iM " << iM;
dmsg << "msh.gnNo: " << msh.gnNo;
dmsg << "msh.nNo: " << msh.nNo;
dmsg << "msh.nEl: " << msh.nEl;
#endif
for (int a = 0; a < msh.nNo; a++) {
int Ac = msh.gN[a];
msh.lN[Ac] = a;
}
for (int e = 0; e < msh.nEl; e++) {
for (int a = 0; a < msh.eNoN; a++) {
int Ac = msh.IEN(a,e);
msh.IEN(a,e) = msh.gN[Ac];
}
}
}
// Rearrange body force structure, if necessary
//
if (cm.seq()) {
for (int iEq = 0; iEq < com_mod.nEq; iEq++) {
auto& eq = com_mod.eq[iEq];
for (int iBf = 0; iBf < eq.nBf; iBf++) {
auto& bf = eq.bf[iBf];
if (bf.bx.size() != 0) {
int i = bf.dof;
int iM = bf.iM;
auto& msh = com_mod.msh[iM];
Array<double> tmpX(bf.bx);
bf.bx.resize(i, msh.nNo);
for (int a = 0; a < msh.nNo; a++) {
int Ac = msh.gN[a];
bf.bx.set_col(a, tmpX.col(Ac));
}
} else if (bf.bm.defined()) {
int i = bf.bm.dof;
int a = bf.bm.nTP;
int iM = bf.iM;
auto tmpD = bf.bm.d;
bf.bm.d.resize(i,com_mod.msh[iM].nNo,a);
for (int i = 0; i < bf.bm.nTP; i++) {
for (int a = 0; a < com_mod.msh[iM].nNo; a++) {
int Ac = com_mod.msh[iM].gN[a];
for (int j = 0; j < bf.bm.dof; j++) {
bf.bm.d(j,a,i) = tmpD(j,Ac,i);
}
}
}
}
}
}
return;
}
// Partitioning the faces
//
// tMs is a temporary variable to keep fa%gN of the old meshes.
//
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Partitioning the faces" << " ...";
#endif
std::vector<mshType> tMs(nMsh);
for (int iM = 0; iM < nMsh; iM++) {
auto& msh = com_mod.msh[iM];
tMs[iM].fa.resize(msh.nFa);
for (int iFa = 0; iFa < msh.nFa; iFa++) {
auto& face = msh.fa[iFa];
part_face(simulation, msh, face, tMs[iM].fa[iFa], gmtl);
}
}
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Sending data read by master to slaves " << " ...";
#endif
if (!com_mod.resetSim) {
cm.bcast(cm_mod, &com_mod.nsymd);
cm.bcast(cm_mod, com_mod.stopTrigName);
cm.bcast(cm_mod, com_mod.iniFilePath);
cm.bcast(cm_mod, com_mod.stFileName);
cm.bcast(cm_mod, &com_mod.stFileFlag);
cm.bcast(cm_mod, &com_mod.stFileIncr);
cm.bcast(cm_mod, &com_mod.stFileRepl);
cm.bcast(cm_mod, &com_mod.saveIncr);
cm.bcast(cm_mod, &com_mod.saveATS);
cm.bcast(cm_mod, &com_mod.saveAve);
cm.bcast(cm_mod, &com_mod.saveVTK);
cm.bcast(cm_mod, &com_mod.bin2VTK);
cm.bcast(cm_mod, &com_mod.mvMsh);
cm.bcast(cm_mod, &com_mod.nITs);
cm.bcast(cm_mod, &com_mod.nTS);
cm.bcast(cm_mod, &com_mod.startTS);
cm.bcast(cm_mod, &com_mod.nEq);
cm.bcast(cm_mod, &com_mod.dt);
cm.bcast(cm_mod, &com_mod.precompDt);
cm.bcast(cm_mod, &com_mod.zeroAve);
cm.bcast(cm_mod, &com_mod.cmmInit);
cm.bcast(cm_mod, &com_mod.cmmVarWall);
cm.bcast(cm_mod, &com_mod.shlEq);
cm.bcast(cm_mod, &com_mod.pstEq);
cm.bcast(cm_mod, &com_mod.sstEq);
cm.bcast(cm_mod, &simulation->cep_mod.cepEq);
cm.bcast(cm_mod, &com_mod.risFlag);
cm.bcast(cm_mod, &com_mod.ris0DFlag);
cm.bcast(cm_mod, &com_mod.urisFlag);
cm.bcast(cm_mod, &com_mod.urisActFlag);
cm.bcast(cm_mod, &com_mod.urisRes);
cm.bcast(cm_mod, &com_mod.urisResClose);
cm.bcast(cm_mod, &com_mod.usePrecomp);
if (com_mod.rmsh.isReqd) {
auto& rmsh = com_mod.rmsh;
cm.bcast_enum(cm_mod, &rmsh.method);
cm.bcast(cm_mod, &rmsh.freq);
cm.bcast(cm_mod, &rmsh.cpVar);
if (cm.slv(cm_mod)) {
rmsh.maxEdgeSize.resize(com_mod.nMsh);
rmsh.minDihedAng = 0.0;
rmsh.maxRadRatio = 0.0;
}
cm.bcast(cm_mod, rmsh.maxEdgeSize);
}
cm.bcast(cm_mod, &com_mod.iCntct);
if (com_mod.iCntct) {
cm.bcast_enum(cm_mod, &com_mod.cntctM.cType);
cm.bcast(cm_mod, &com_mod.cntctM.k);
cm.bcast(cm_mod, &com_mod.cntctM.c);
cm.bcast(cm_mod, &com_mod.cntctM.h);
cm.bcast(cm_mod, &com_mod.cntctM.al);
}
cm.bcast(cm_mod, &com_mod.ibFlag);
cm.bcast(cm_mod, &simulation->cep_mod.nXion);
}
// Distributing X to processors
//
#ifdef debug_distribute
dmsg << " " << " ";
dmsg << "Distributing X to processors " << " ...";
#endif
Array<double> tmpX;
if (cm.mas(cm_mod)) {
tmpX.resize(com_mod.nsd, com_mod.gtnNo);
tmpX = com_mod.x;
com_mod.x.clear();
}
com_mod.x.resize(com_mod.nsd, com_mod.tnNo);
com_mod.x = all_fun::local(com_mod, cm_mod, cm, tmpX);
// Distributing lM%dmnId if present to processors
//
bool flag = (com_mod.dmnId.size() != 0);
cm.bcast(cm_mod, &flag);
Vector<int> part;
#ifdef debug_distribute
dmsg << "dmnId.size(): " << com_mod.dmnId.size();
dmsg << "flag: " << flag;
#endif
if (flag) {
#ifdef debug_distribute
dmsg << "Distributing dmnId " << " ... ";
#endif
if (cm.mas(cm_mod)) {
part.resize(com_mod.gtnNo);
part = com_mod.dmnId;
com_mod.dmnId.clear();
} else {
part.clear();
}
com_mod.dmnId.resize(com_mod.tnNo);
com_mod.dmnId = all_fun::local(com_mod, cm_mod, cm, part);
part.clear();
}
// Distribute prestress (pS0) to processors.
//
// pS0 is set in read_msh() and for CMM.
//
flag = (com_mod.pS0.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
if (cm.mas(cm_mod)) {
tmpX.resize(com_mod.nsymd, com_mod.gtnNo);
tmpX = com_mod.pS0;
com_mod.pS0.clear();
} else {
tmpX.clear();
}
com_mod.pS0.resize(com_mod.nsymd, com_mod.tnNo);
com_mod.pS0 = all_fun::local(com_mod, cm_mod, cm, tmpX);
tmpX.clear();
}
// Distribute initial flow quantities to processors
//
// Distribute Pinit (set in read_msh()).
//
flag = (com_mod.Pinit.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
if (cm.mas(cm_mod)) {
tmpX.resize(1, com_mod.gtnNo);
for (int i = 0; i < tmpX.ncols(); i++) {
tmpX(0,i) = com_mod.Pinit[i];
}
com_mod.Pinit.clear();
} else {
tmpX.clear();
}
wgt.resize(1, com_mod.tnNo);
com_mod.Pinit.resize(com_mod.tnNo);
wgt = all_fun::local(com_mod, cm_mod, cm, tmpX);
for (int i = 0; i < wgt.ncols(); i++) {
com_mod.Pinit[i] = wgt(0,i);
}
tmpX.clear();
wgt.clear();
}
// Distribute Vinit
//
flag = (com_mod.Vinit.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
if (cm.mas(cm_mod)) {
tmpX.resize(com_mod.nsd, com_mod.gtnNo);
tmpX = com_mod.Vinit;
com_mod.Vinit.clear();
} else {
tmpX.clear();
}
com_mod.Vinit.resize(com_mod.nsd, com_mod.tnNo);
com_mod.Vinit = all_fun::local(com_mod, cm_mod, cm, tmpX);
tmpX.clear();
}
// Distribute Dinit
//
flag = (com_mod.Dinit.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
if (cm.mas(cm_mod)) {
tmpX.resize(com_mod.nsd, com_mod.gtnNo);
tmpX = com_mod.Dinit;
com_mod.Dinit.clear();
} else {
tmpX.clear();
}
com_mod.Dinit.resize(com_mod.nsd, com_mod.tnNo);
com_mod.Dinit = all_fun::local(com_mod, cm_mod, cm, tmpX);
tmpX.clear();
}
// And distributing eq to processors
//
if (cm.slv(cm_mod)) {
com_mod.eq.resize(com_mod.nEq);
}
auto& cep_mod = simulation->cep_mod;
for (int iEq = 0; iEq < com_mod.nEq; iEq++) {
auto& eq = com_mod.eq[iEq];
dist_eq(com_mod, cm_mod, cm, tMs, gmtl, cep_mod, eq);
}
// For CMM initialization
//
flag = (com_mod.cmmBdry.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
Vector<int> part;
if (cm.mas(cm_mod)) {
part.resize(com_mod.gtnNo);
part = com_mod.cmmBdry;
}
com_mod.cmmBdry.resize(com_mod.tnNo);
com_mod.cmmBdry = all_fun::local(com_mod, cm_mod, cm, part);
}
// For CMM variable wall properties
//
flag = (com_mod.varWallProps.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
Array<double> tmpX;
if (cm.mas(cm_mod)) {
tmpX.resize(2, com_mod.gtnNo);
tmpX = com_mod.varWallProps;
com_mod.varWallProps.clear();
}
com_mod.varWallProps.resize(2, com_mod.tnNo);
com_mod.varWallProps = all_fun::local(com_mod, cm_mod, cm, tmpX);
}
// Communicating cplBC data
//
auto& cplBC = com_mod.cplBC;
cm.bcast(cm_mod, &cplBC.nFa);
cm.bcast_enum(cm_mod, &cplBC.schm);
cm.bcast(cm_mod, &cplBC.useGenBC);
cm.bcast(cm_mod, &cplBC.useSvZeroD);
if (cplBC.useGenBC) {
if (cm.slv(cm_mod)) {
cplBC.nX = 0;
cplBC.xo.resize(cplBC.nX);
}
} else if (cplBC.useSvZeroD) {
if (cm.slv(cm_mod)) {
cplBC.nX = 0;
cplBC.xo.resize(cplBC.nX);
}
} else {
cm.bcast(cm_mod, &cplBC.nX);
if (cplBC.xo.size() == 0) {
cplBC.xo.resize(cplBC.nX);
}
if (cplBC.nX != 0) {
cm.bcast(cm_mod, cplBC.xo);
}
}
cm.bcast(cm_mod, &cplBC.initRCR);
if (com_mod.risFlag) {
for (int iProj = 0; iProj < com_mod.ris.nbrRIS; iProj++) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < com_mod.risMapList[iProj].map.ncols(); j++) {
int tmp = gmtl(com_mod.grisMapList[iProj].map(i,j));
if (tmp != -1) {
com_mod.risMapList[iProj].map(i,j) = com_mod.msh[i].lN(tmp);
} else {
com_mod.risMapList[iProj].map(i,j) = -1;
}
com_mod.grisMapList[iProj].map(i,j) = tmp;
}
}
}
}
}
void dist_bc(ComMod& com_mod, const CmMod& cm_mod, const cmType& cm, bcType& lBc, const std::vector<mshType>& tMs,
const Vector<int>& gmtl)
{
using namespace consts;
#define n_debug_dist_bc
#ifdef debug_dist_bc
DebugMsg dmsg(__func__, com_mod.cm.idcm());
dmsg.banner();
#endif
int task_id = cm.idcm();
bool is_slave = cm.slv(cm_mod);
cm.bcast(cm_mod, &lBc.cplBCptr);
cm.bcast(cm_mod, &lBc.bType);
cm.bcast(cm_mod, &lBc.clsFlgRis);
int nsd = com_mod.nsd;
#ifdef debug_dist_bc
dmsg << "nsd: " << nsd;
dmsg << "lBc.bType: " << lBc.bType;
dmsg << "is_slave: " << is_slave;
#endif
if (is_slave) {
lBc.eDrn.resize(nsd);
lBc.h.resize(nsd);
}
cm.bcast(cm_mod, lBc.eDrn);
cm.bcast(cm_mod, &lBc.iFa);
cm.bcast(cm_mod, &lBc.iM);
cm.bcast(cm_mod, &lBc.r);
cm.bcast(cm_mod, &lBc.g);
cm.bcast(cm_mod, lBc.h);
cm.bcast(cm_mod, &lBc.weakDir);
cm.bcast(cm_mod, lBc.tauB);
cm.bcast(cm_mod, &lBc.flwP);
if (utils::btest(lBc.bType, static_cast<int>(BoundaryConditionType::bType_RCR))) {
cm.bcast(cm_mod, &lBc.RCR.Rp);
cm.bcast(cm_mod, &lBc.RCR.C);
cm.bcast(cm_mod, &lBc.RCR.Rd);
cm.bcast(cm_mod, &lBc.RCR.Pd);
cm.bcast(cm_mod, &lBc.RCR.Xo);
}
// Communicating time-dependent BC data
//
// lBc.gt is declare ALLOCATABLE in MOD.f but we don't
// want to use pointers so use the define() method
// to check if it has data define.
//
bool flag = lBc.gt.defined();
cm.bcast(cm_mod, &flag);
if (flag) {
if (is_slave) {
// [NOTE] This is allocated in ComMod.
//lBc.gt = new fcType;
}
cm.bcast(cm_mod, &lBc.gt.lrmp);
cm.bcast(cm_mod, &lBc.gt.d);
cm.bcast(cm_mod, &lBc.gt.n);
int j = lBc.gt.d;
int i = lBc.gt.n;
if (is_slave) {
lBc.gt.qi.resize(j);
lBc.gt.qs.resize(j);
lBc.gt.r.resize(j,i);
lBc.gt.i.resize(j,i);
}
cm.bcast(cm_mod, &lBc.gt.ti);
cm.bcast(cm_mod, &lBc.gt.T);
cm.bcast(cm_mod, lBc.gt.qi);
cm.bcast(cm_mod, lBc.gt.qs);
cm.bcast(cm_mod, lBc.gt.r);
cm.bcast(cm_mod, lBc.gt.i);
}
// Communicating moving BC data
flag = lBc.gm.defined();
cm.bcast(cm_mod, &flag);
if (flag) {
if (is_slave) {
//lBc.gm = new MBType;
}
cm.bcast(cm_mod, &lBc.gm.period);
// Communication the .t data
cm.bcast(cm_mod, &lBc.gm.nTP);
cm.bcast(cm_mod, &lBc.gm.dof);
int nTp = lBc.gm.nTP;
int iDof = lBc.gm.dof;
if (is_slave) {
lBc.gm.t.resize(nTp);
}
cm.bcast(cm_mod, lBc.gm.t);
int nNo = tMs[lBc.iM].fa[lBc.iFa].nNo;
int a = nTp*iDof*nNo;
// Allocating the container and copying the nodes which belong to
// this processor
//
Vector<double> tmp(a);
if (!is_slave) {
// Copy data row-wise to tmp.
int n = 0;
for (int k = 0; k < lBc.gm.d.nslices(); k++) {
for (int j = 0; j < lBc.gm.d.ncols(); j++) {
for (int i = 0; i < lBc.gm.d.nrows(); i++) {
tmp[n] = lBc.gm.d(i,j,k);
n += 1;
}
}
}
}
cm.bcast(cm_mod, tmp);
// This is the new number of nodes
a = com_mod.msh[lBc.iM].fa[lBc.iFa].nNo;
lBc.gm.d.resize(iDof, a, nTp);
int b = 0;
for (int a = 0; a < nNo; a++) {
int Ac = tMs[lBc.iM].fa[lBc.iFa].gN[a];
Ac = gmtl[Ac];
if (Ac != -1) {
for (int i = 0; i < nTp; i++) {
int j = iDof * (i*nNo + a);
for (int k = 0; k < iDof; k++) {
lBc.gm.d(k,b,i) = tmp[k+j];
}
}
b = b + 1;
}
}
}
// Communicating profile data
//
flag = (lBc.gx.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
int nNo = tMs[lBc.iM].fa[lBc.iFa].nNo;
Vector<double> tmp(nNo);
if (!is_slave) {
tmp = lBc.gx;
lBc.gx.clear();
}
cm.bcast(cm_mod, tmp);
// This is the new number of nodes
int a = com_mod.msh[lBc.iM].fa[lBc.iFa].nNo;
lBc.gx.resize(a);
int b = 0;
for (int a = 0; a < nNo; a++) {
int Ac = tMs[lBc.iM].fa[lBc.iFa].gN[a];
Ac = gmtl[Ac];
if (Ac != -1) {
lBc.gx[b] = tmp[a];
b = b + 1;
}
}
}
// Communicating Robin BC
//
bool has_robin_bc = lBc.robin_bc.is_initialized();
cm.bcast(cm_mod, &has_robin_bc); // Master process broadcasts the flag to all processes
if (has_robin_bc) {
lBc.robin_bc.distribute(com_mod, cm_mod, cm, com_mod.msh[lBc.iM].fa[lBc.iFa]);
}
// Communicating and reordering master node data for
// undeforming Neumann BC faces.
//
if (utils::btest(lBc.bType, static_cast<int>(BoundaryConditionType::bType_undefNeu))) {
cm.bcast(cm_mod, &lBc.masN);
int iM = lBc.iM;
int iFa = lBc.iFa;
int nNo = com_mod.msh[iM].fa[iFa].nNo;
bool flag = (nNo != 0);
// Action performed only on the processes that share the face
//
if (flag) {
int Ac = lBc.masN;
int a = gmtl[Ac];
// The process that owns the node is set to be master. For other
// processes that share the face but do not own the node, we add
// this node as a ghost master node. ltg pointer is reset.
//
if (a != 0) {
lBc.masN = a;
} else {
nNo = com_mod.tnNo;
com_mod.tnNo = com_mod.tnNo + 1;
// Remap ltg
//
Vector<int> tmpI(nNo);
tmpI = com_mod.ltg;
com_mod.ltg.resize(com_mod.tnNo);
for (int i = 0; i < nNo; i++) {
com_mod.ltg[i] = tmpI[i];
}
com_mod.ltg[com_mod.tnNo] = Ac;
lBc.masN = com_mod.tnNo;
// Add the ghost master node to the face data structure
//
nNo = com_mod.msh[iM].fa[iFa].nNo;
com_mod.msh[iM].fa[iFa].nNo = nNo + 1;
tmpI.resize(nNo);
for (int i = 0; i < nNo; i++) {
tmpI[i] = com_mod.msh[iM].fa[iFa].gN[i];
}
com_mod.msh[iM].fa[iFa].gN.resize(com_mod.msh[iM].fa[iFa].nNo);
for (int i = 0; i < nNo; i++) {
com_mod.msh[iM].fa[iFa].gN[i] = tmpI[i];
}
com_mod.msh[iM].fa[iFa].gN[nNo] = com_mod.tnNo;
}
// Zero out master node if not part of the face
} else {
lBc.masN = 0;
}
} else {
lBc.masN = 0;
}
}
//---------
// dist_bf
//---------
//
void dist_bf(ComMod& com_mod, const CmMod& cm_mod, const cmType& cm, bfType& lBf)
{
using namespace consts;
#define n_dist_bf
#ifdef dist_bf
DebugMsg dmsg(__func__, com_mod.cm.idcm());
dmsg.banner();
dmsg << "cm.seq(): " << cm.seq();
#endif
bool is_slave = cm.slv(cm_mod);
cm.bcast(cm_mod, &lBf.bType);
cm.bcast(cm_mod, &lBf.dof);
cm.bcast(cm_mod, &lBf.iM);
int iM = lBf.iM;
// Steady value
//
bool flag = (lBf.b.size() != 0);
cm.bcast(cm_mod, &flag);
if (flag) {
if (is_slave) {
lBf.b.resize(lBf.dof);
}
cm.bcast(cm_mod, lBf.b);
}
// Communicating spatially dependent BF
//
flag = (lBf.bx.size() != 0);
cm.bcast(cm_mod, &flag);
Array<double> tmpX;
Array3<double> tmpD;
if (flag) {
if (!is_slave) {
tmpX.resize(lBf.dof, com_mod.gtnNo);
tmpX = lBf.bx;
lBf.bx.clear();
}
lBf.bx.resize(lBf.dof, com_mod.tnNo);
lBf.bx = all_fun::local(com_mod, cm_mod, cm, tmpX);
tmpX.resize(lBf.dof, com_mod.tnNo);
tmpX = lBf.bx;
lBf.bx.clear();
lBf.bx.resize(lBf.dof, com_mod.msh[iM].nNo);
for (int a = 0; a < com_mod.msh[iM].nNo; a++) {
int Ac = com_mod.msh[iM].gN[a];
lBf.bx.set_col(a, tmpX.col(Ac));
}
}
// Communicating time-dependent BF data
flag = lBf.bt.defined();
cm.bcast(cm_mod, &flag);
if (flag) {
if (is_slave) {
//ALLOCATE(lBf.bt)
}
cm.bcast(cm_mod, &lBf.bt.lrmp);
cm.bcast(cm_mod, &lBf.bt.d);
cm.bcast(cm_mod, &lBf.bt.n);
if (is_slave) {
int j = lBf.bt.d;
int i = lBf.bt.n;
lBf.bt.qi.resize(j);
lBf.bt.qs.resize(j);
lBf.bt.r.resize(j,i);
lBf.bt.i.resize(j,i);
}
cm.bcast(cm_mod, &lBf.bt.ti);
cm.bcast(cm_mod, &lBf.bt.T);
cm.bcast(cm_mod, lBf.bt.qi);
cm.bcast(cm_mod, lBf.bt.qs);
cm.bcast(cm_mod, lBf.bt.r);
cm.bcast(cm_mod, lBf.bt.i);
}
// Communicating moving BF data
//
flag = lBf.bm.defined();
cm.bcast(cm_mod, &flag);
if (flag) {
if (is_slave) {
//ALLOCATE(lBf.bm)
}
cm.bcast(cm_mod, &lBf.bm.period);
cm.bcast(cm_mod, &lBf.bm.nTP);
cm.bcast(cm_mod, &lBf.bm.dof);
int nTP = lBf.bm.nTP;
int idof = lBf.bm.dof;
if (is_slave) {
lBf.bm.t.resize(nTP);
}
cm.bcast(cm_mod, lBf.bm.t);
if (!is_slave) {
tmpD.resize(lBf.bm.dof, com_mod.gtnNo, lBf.bm.nTP);
tmpD = lBf.bm.d;
lBf.bm.d.clear();
}
tmpX.resize(lBf.bm.dof, com_mod.tnNo);
lBf.bm.d.resize(lBf.bm.dof, com_mod.msh[iM].nNo, lBf.bm.nTP);
for (int i = 0; i < lBf.bm.nTP; i++) {
// [NOTE] This is a big hack because tmpD can have 0 size
// for a slave process.
Array<double> tmpX_slice(lBf.bm.dof, com_mod.msh[iM].nNo);
if (tmpD.size() != 0) {
tmpX_slice = tmpD.slice(i);
}
tmpX = all_fun::local(com_mod, cm_mod, cm, tmpX_slice);
for (int a = 0; a < com_mod.msh[iM].nNo; a++) {
int Ac = com_mod.msh[iM].gN[a];
for (int j = 0; j < lBf.bm.d.nrows(); j++) {
lBf.bm.d(j,a,i) = tmpX(j,Ac);
}
}
}
}
}
//---------
// dist_ris
//---------
/// @brief This rountine distributes data structures for RIS
void dist_ris(ComMod& com_mod, const CmMod& cm_mod, const cmType& cm)
{
using namespace consts;
#define n_debug_dist_ris
#ifdef debug_dist_ris
DebugMsg dmsg(__func__, com_mod.cm.idcm());
dmsg.banner();
#endif