-
Notifications
You must be signed in to change notification settings - Fork 122
/
extrudeToRegionMesh.C
2855 lines (2446 loc) · 79.2 KB
/
extrudeToRegionMesh.C
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
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
extrudeToRegionMesh
Description
Extrude faceZones (internal or boundary faces) or faceSets (boundary faces
only) into a separate mesh (as a different region).
- used to e.g. extrude baffles (extrude internal faces) or create
liquid film regions.
- if extruding internal faces:
- create baffles in original mesh with mappedWall patches
- if extruding boundary faces:
- convert boundary faces to mappedWall patches
- extrude edges of faceZone as a \<zone\>_sidePatch
- extrude edges inbetween different faceZones as a
(nonuniformTransform)cyclic \<zoneA\>_\<zoneB\>
- extrudes into master direction (i.e. away from the owner cell
if flipMap is false)
\verbatim
Internal face extrusion
-----------------------
+-------------+
| |
| |
+---AAAAAAA---+
| |
| |
+-------------+
AAA=faceZone to extrude.
For the case of no flipMap the extrusion starts at owner and extrudes
into the space of the neighbour:
+CCCCCCC+
| | <= extruded mesh
+BBBBBBB+
+-------------+
| |
| (neighbour) |
|___CCCCCCC___| <= original mesh (with 'baffles' added)
| BBBBBBB |
|(owner side) |
| |
+-------------+
BBB=mapped between owner on original mesh and new extrusion.
(zero offset)
CCC=mapped between neighbour on original mesh and new extrusion
(offset due to the thickness of the extruded mesh)
For the case of flipMap the extrusion is the other way around: from the
neighbour side into the owner side.
Boundary face extrusion
-----------------------
+--AAAAAAA--+
| |
| |
+-----------+
AAA=faceZone to extrude. E.g. slave side is owner side (no flipmap)
becomes
+CCCCCCC+
| | <= extruded mesh
+BBBBBBB+
+--BBBBBBB--+
| | <= original mesh
| |
+-----------+
BBB=mapped between original mesh and new extrusion
CCC=polypatch
Notes:
- when extruding cyclics with only one cell inbetween it does not
detect this as a cyclic since the face is the same face. It will
only work if the coupled edge extrudes a different face so if there
are more than 1 cell inbetween.
\endverbatim
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "fvMesh.H"
#include "polyTopoChange.H"
#include "OFstream.H"
#include "meshTools.H"
#include "mappedWallPolyPatch.H"
#include "createShellMesh.H"
#include "syncTools.H"
#include "cyclicPolyPatch.H"
#include "wedgePolyPatch.H"
#include "nonuniformTransformCyclicPolyPatch.H"
#include "extrudeModel.H"
#include "globalIndex.H"
#include "faceSet.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
//#include "ReadFields.H"
#include "fvMeshTools.H"
#include "OBJstream.H"
#include "PatchTools.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
label findPatchID(const List<polyPatch*>& newPatches, const word& name)
{
forAll(newPatches, i)
{
if (newPatches[i]->name() == name)
{
return i;
}
}
return -1;
}
template<class PatchType>
label addPatch
(
const polyBoundaryMesh& patches,
const word& patchName,
DynamicList<polyPatch*>& newPatches
)
{
label patchi = findPatchID(newPatches, patchName);
if (patchi != -1)
{
if (isA<PatchType>(*newPatches[patchi]))
{
// Already there
return patchi;
}
else
{
FatalErrorInFunction
<< "Already have patch " << patchName
<< " but of type " << newPatches[patchi]->type()
<< exit(FatalError);
}
}
patchi = newPatches.size();
label startFacei = 0;
if (patchi > 0)
{
const polyPatch& pp = *newPatches.last();
startFacei = pp.start()+pp.size();
}
newPatches.append
(
polyPatch::New
(
PatchType::typeName,
patchName,
0, // size
startFacei, // nFaces
patchi,
patches
).ptr()
);
return patchi;
}
template<class PatchType>
label addPatch
(
const polyBoundaryMesh& patches,
const word& patchName,
const dictionary& dict,
DynamicList<polyPatch*>& newPatches
)
{
label patchi = findPatchID(newPatches, patchName);
if (patchi != -1)
{
if (isA<PatchType>(*newPatches[patchi]))
{
// Already there
return patchi;
}
else
{
FatalErrorInFunction
<< "Already have patch " << patchName
<< " but of type " << newPatches[patchi]->type()
<< exit(FatalError);
}
}
patchi = newPatches.size();
label startFacei = 0;
if (patchi > 0)
{
const polyPatch& pp = *newPatches.last();
startFacei = pp.start()+pp.size();
}
dictionary patchDict(dict);
patchDict.set("type", PatchType::typeName);
patchDict.set("nFaces", 0);
patchDict.set("startFace", startFacei);
newPatches.append
(
polyPatch::New
(
patchName,
patchDict,
patchi,
patches
).ptr()
);
return patchi;
}
// Remove zero-sized patches
void deleteEmptyPatches(fvMesh& mesh)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
wordList masterNames;
if (Pstream::master())
{
masterNames = patches.names();
}
Pstream::scatter(masterNames);
labelList oldToNew(patches.size(), -1);
label usedI = 0;
label notUsedI = patches.size();
// Add all the non-empty, non-processor patches
forAll(masterNames, masterI)
{
label patchi = patches.findPatchID(masterNames[masterI]);
if (patchi != -1)
{
if (isA<processorPolyPatch>(patches[patchi]))
{
// Similar named processor patch? Not 'possible'.
if (patches[patchi].size() == 0)
{
Pout<< "Deleting processor patch " << patchi
<< " name:" << patches[patchi].name()
<< endl;
oldToNew[patchi] = --notUsedI;
}
else
{
oldToNew[patchi] = usedI++;
}
}
else
{
// Common patch.
if (returnReduce(patches[patchi].size(), sumOp<label>()) == 0)
{
Pout<< "Deleting patch " << patchi
<< " name:" << patches[patchi].name()
<< endl;
oldToNew[patchi] = --notUsedI;
}
else
{
oldToNew[patchi] = usedI++;
}
}
}
}
// Add remaining patches at the end
forAll(patches, patchi)
{
if (oldToNew[patchi] == -1)
{
// Unique to this processor. Note: could check that these are
// only processor patches.
if (patches[patchi].size() == 0)
{
Pout<< "Deleting processor patch " << patchi
<< " name:" << patches[patchi].name()
<< endl;
oldToNew[patchi] = --notUsedI;
}
else
{
oldToNew[patchi] = usedI++;
}
}
}
fvMeshTools::reorderPatches(mesh, oldToNew, usedI, true);
}
void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
{
// Create dummy system/fv*
{
IOobject io
(
"fvSchemes",
mesh.time().system(),
regionName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
Info<< "Testing:" << io.objectPath() << endl;
if (!io.typeHeaderOk<IOdictionary>(true))
{
Info<< "Writing dummy " << regionName/io.name() << endl;
dictionary dummyDict;
dictionary divDict;
dummyDict.add("divSchemes", divDict);
dictionary gradDict;
dummyDict.add("gradSchemes", gradDict);
dictionary laplDict;
dummyDict.add("laplacianSchemes", laplDict);
IOdictionary(io, dummyDict).regIOobject::write();
}
}
{
IOobject io
(
"fvSolution",
mesh.time().system(),
regionName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
if (!io.typeHeaderOk<IOdictionary>(true))
{
Info<< "Writing dummy " << regionName/io.name() << endl;
dictionary dummyDict;
IOdictionary(io, dummyDict).regIOobject::write();
}
}
}
// Check zone either all internal or all external faces
void checkZoneInside
(
const polyMesh& mesh,
const wordList& zoneNames,
const labelList& zoneID,
const labelList& extrudeMeshFaces,
const boolList& isInternal
)
{
forAll(zoneNames, i)
{
if (isInternal[i])
{
Info<< "Zone " << zoneNames[i] << " has internal faces" << endl;
}
else
{
Info<< "Zone " << zoneNames[i] << " has boundary faces" << endl;
}
}
forAll(extrudeMeshFaces, i)
{
label facei = extrudeMeshFaces[i];
label zoneI = zoneID[i];
if (isInternal[zoneI] != mesh.isInternalFace(facei))
{
FatalErrorInFunction
<< "Zone " << zoneNames[zoneI]
<< " is not consistently all internal or all boundary faces."
<< " Face " << facei << " at " << mesh.faceCentres()[facei]
<< " is the first occurrence."
<< exit(FatalError);
}
}
}
// To combineReduce a labelList. Filters out duplicates.
class uniqueEqOp
{
public:
void operator()(labelList& x, const labelList& y) const
{
if (x.empty())
{
if (y.size())
{
x = y;
}
}
else
{
forAll(y, yi)
{
if (findIndex(x, y[yi]) == -1)
{
label sz = x.size();
x.setSize(sz+1);
x[sz] = y[yi];
}
}
}
}
};
// Calculate global pp faces per pp edge.
labelListList globalEdgeFaces
(
const polyMesh& mesh,
const globalIndex& globalFaces,
const primitiveFacePatch& pp,
const labelList& ppMeshEdges
)
{
// From mesh edge to global pp face labels.
labelListList globalEdgeFaces(ppMeshEdges.size());
const labelListList& edgeFaces = pp.edgeFaces();
forAll(edgeFaces, edgeI)
{
const labelList& eFaces = edgeFaces[edgeI];
// Store pp face and processor as unique tag.
labelList& globalEFaces = globalEdgeFaces[edgeI];
globalEFaces.setSize(eFaces.size());
forAll(eFaces, i)
{
globalEFaces[i] = globalFaces.toGlobal(eFaces[i]);
}
}
// Synchronise across coupled edges.
syncTools::syncEdgeList
(
mesh,
ppMeshEdges,
globalEdgeFaces,
uniqueEqOp(),
labelList() // null value
);
return globalEdgeFaces;
}
// Find a patch face that is not extruded. Return -1 if not found.
label findUncoveredPatchFace
(
const fvMesh& mesh,
const UIndirectList<label>& extrudeMeshFaces,// mesh faces that are extruded
const label meshEdgeI // mesh edge
)
{
// Make set of extruded faces.
labelHashSet extrudeFaceSet(extrudeMeshFaces.size());
forAll(extrudeMeshFaces, i)
{
extrudeFaceSet.insert(extrudeMeshFaces[i]);
}
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelList& eFaces = mesh.edgeFaces()[meshEdgeI];
forAll(eFaces, i)
{
label facei = eFaces[i];
label patchi = pbm.whichPatch(facei);
if
(
patchi != -1
&& !pbm[patchi].coupled()
&& !extrudeFaceSet.found(facei)
)
{
return facei;
}
}
return -1;
}
// Same as findUncoveredPatchFace, except explicitly checks for cyclic faces
label findUncoveredCyclicPatchFace
(
const fvMesh& mesh,
const UIndirectList<label>& extrudeMeshFaces,// mesh faces that are extruded
const label meshEdgeI // mesh edge
)
{
// Make set of extruded faces.
labelHashSet extrudeFaceSet(extrudeMeshFaces.size());
forAll(extrudeMeshFaces, i)
{
extrudeFaceSet.insert(extrudeMeshFaces[i]);
}
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelList& eFaces = mesh.edgeFaces()[meshEdgeI];
forAll(eFaces, i)
{
label facei = eFaces[i];
label patchi = pbm.whichPatch(facei);
if
(
patchi != -1
&& isA<cyclicPolyPatch>(pbm[patchi])
&& !extrudeFaceSet.found(facei)
)
{
return facei;
}
}
return -1;
}
// Calculate per edge min and max zone
void calcEdgeMinMaxZone
(
const fvMesh& mesh,
const primitiveFacePatch& extrudePatch,
const labelList& extrudeMeshEdges,
const labelList& zoneID,
const mapDistribute& extrudeEdgeFacesMap,
const labelListList& extrudeEdgeGlobalFaces,
labelList& minZoneID,
labelList& maxZoneID
)
{
// Get zoneIDs in extrudeEdgeGlobalFaces order
labelList mappedZoneID(zoneID);
extrudeEdgeFacesMap.distribute(mappedZoneID);
// Get min and max zone per edge
minZoneID.setSize(extrudeEdgeGlobalFaces.size(), labelMax);
maxZoneID.setSize(extrudeEdgeGlobalFaces.size(), labelMin);
forAll(extrudeEdgeGlobalFaces, edgeI)
{
const labelList& eFaces = extrudeEdgeGlobalFaces[edgeI];
if (eFaces.size())
{
forAll(eFaces, i)
{
label zoneI = mappedZoneID[eFaces[i]];
minZoneID[edgeI] = min(minZoneID[edgeI], zoneI);
maxZoneID[edgeI] = max(maxZoneID[edgeI], zoneI);
}
}
}
syncTools::syncEdgeList
(
mesh,
extrudeMeshEdges,
minZoneID,
minEqOp<label>(),
labelMax // null value
);
syncTools::syncEdgeList
(
mesh,
extrudeMeshEdges,
maxZoneID,
maxEqOp<label>(),
labelMin // null value
);
}
// Count the number of faces in patches that need to be created. Calculates:
// zoneSidePatch[zoneI] : the number of side faces to be created
// zoneZonePatch[zoneA,zoneB] : the number of faces inbetween zoneA and B
// Since this only counts we're not taking the processor patches into
// account.
void countExtrudePatches
(
const fvMesh& mesh,
const label nZones,
const primitiveFacePatch& extrudePatch,
const labelList& extrudeMeshFaces,
const labelList& extrudeMeshEdges,
const labelListList& extrudeEdgeGlobalFaces,
const labelList& minZoneID,
const labelList& maxZoneID,
labelList& zoneSidePatch,
labelList& zoneZonePatch
)
{
// Check on master edge for use of zones. Since we only want to know
// whether they are being used at all no need to accurately count on slave
// edge as well. Just add all together at the end of this routine so it
// gets detected at least.
forAll(extrudePatch.edgeFaces(), edgeI)
{
const labelList& eFaces = extrudePatch.edgeFaces()[edgeI];
if (eFaces.size() == 2)
{
// Internal edge - check if inbetween different zones.
if (minZoneID[edgeI] != maxZoneID[edgeI])
{
zoneZonePatch[minZoneID[edgeI]*nZones+maxZoneID[edgeI]]++;
}
}
else if
(
eFaces.size() == 1
&& extrudeEdgeGlobalFaces[edgeI].size() == 2
)
{
// Coupled edge - check if inbetween different zones.
if (minZoneID[edgeI] != maxZoneID[edgeI])
{
const edge& e = extrudePatch.edges()[edgeI];
const pointField& pts = extrudePatch.localPoints();
WarningInFunction
<< "Edge " << edgeI
<< "at " << pts[e[0]] << pts[e[1]]
<< " is a coupled edge and inbetween two different zones "
<< minZoneID[edgeI] << " and " << maxZoneID[edgeI] << endl
<< " This is currently not supported." << endl;
zoneZonePatch[minZoneID[edgeI]*nZones+maxZoneID[edgeI]]++;
}
}
else
{
// One or more than two edge-faces.
// Check whether we are on a mesh edge with external patches. If
// so choose any uncovered one. If none found put face in
// undetermined zone 'side' patch
label facei = findUncoveredPatchFace
(
mesh,
UIndirectList<label>(extrudeMeshFaces, eFaces),
extrudeMeshEdges[edgeI]
);
if (facei == -1)
{
zoneSidePatch[minZoneID[edgeI]]++;
}
}
}
// Synchronise decistion. Actual numbers are not important, just make
// sure that they're > 0 on all processors.
Pstream::listCombineGather(zoneSidePatch, plusEqOp<label>());
Pstream::listCombineScatter(zoneSidePatch);
Pstream::listCombineGather(zoneZonePatch, plusEqOp<label>());
Pstream::listCombineScatter(zoneZonePatch);
}
void addCouplingPatches
(
const fvMesh& mesh,
const word& regionName,
const word& shellRegionName,
const wordList& zoneNames,
const wordList& zoneShadowNames,
const boolList& isInternal,
const labelList& zoneIDs,
DynamicList<polyPatch*>& newPatches,
labelList& interRegionTopPatch,
labelList& interRegionBottomPatch
)
{
Pout<< "Adding coupling patches:" << nl << nl
<< "patchID\tpatch\ttype" << nl
<< "-------\t-----\t----"
<< endl;
interRegionTopPatch.setSize(zoneNames.size(), -1);
interRegionBottomPatch.setSize(zoneNames.size(), -1);
label nOldPatches = newPatches.size();
forAll(zoneNames, zoneI)
{
word interName
(
regionName
+"_to_"
+shellRegionName
+'_'
+zoneNames[zoneI]
);
if (isInternal[zoneI])
{
interRegionTopPatch[zoneI] = addPatch<mappedWallPolyPatch>
(
mesh.boundaryMesh(),
interName + "_top",
newPatches
);
Pout<< interRegionTopPatch[zoneI]
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->type()
<< nl;
interRegionBottomPatch[zoneI] = addPatch<mappedWallPolyPatch>
(
mesh.boundaryMesh(),
interName + "_bottom",
newPatches
);
Pout<< interRegionBottomPatch[zoneI]
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->type()
<< nl;
}
else if (zoneShadowNames.size() == 0)
{
interRegionTopPatch[zoneI] = addPatch<polyPatch>
(
mesh.boundaryMesh(),
zoneNames[zoneI] + "_top",
newPatches
);
Pout<< interRegionTopPatch[zoneI]
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->type()
<< nl;
interRegionBottomPatch[zoneI] = addPatch<mappedWallPolyPatch>
(
mesh.boundaryMesh(),
interName,
newPatches
);
Pout<< interRegionBottomPatch[zoneI]
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->type()
<< nl;
}
else //patch using shadow face zones.
{
interRegionTopPatch[zoneI] = addPatch<mappedWallPolyPatch>
(
mesh.boundaryMesh(),
zoneShadowNames[zoneI] + "_top",
newPatches
);
Pout<< interRegionTopPatch[zoneI]
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionTopPatch[zoneI]]->type()
<< nl;
interRegionBottomPatch[zoneI] = addPatch<mappedWallPolyPatch>
(
mesh.boundaryMesh(),
interName,
newPatches
);
Pout<< interRegionBottomPatch[zoneI]
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->name()
<< '\t' << newPatches[interRegionBottomPatch[zoneI]]->type()
<< nl;
}
}
Pout<< "Added " << newPatches.size()-nOldPatches
<< " inter-region patches." << nl
<< endl;
}
// Sets sidePatch[edgeI] to interprocessor or cyclic patch. Adds any
// coupled patches if necessary.
void addCoupledPatches
(
const fvMesh& mesh,
const primitiveFacePatch& extrudePatch,
const labelList& extrudeMeshFaces,
const labelList& extrudeMeshEdges,
const mapDistribute& extrudeEdgeFacesMap,
const labelListList& extrudeEdgeGlobalFaces,
labelList& sidePatchID,
DynamicList<polyPatch*>& newPatches
)
{
// Calculate opposite processor for coupled edges (only if shared by
// two procs). Note: could have saved original globalEdgeFaces structure.
// Get procID in extrudeEdgeGlobalFaces order
labelList procID(extrudeEdgeGlobalFaces.size(), Pstream::myProcNo());
extrudeEdgeFacesMap.distribute(procID);
labelList minProcID(extrudeEdgeGlobalFaces.size(), labelMax);
labelList maxProcID(extrudeEdgeGlobalFaces.size(), labelMin);
forAll(extrudeEdgeGlobalFaces, edgeI)
{
const labelList& eFaces = extrudeEdgeGlobalFaces[edgeI];
if (eFaces.size())
{
forAll(eFaces, i)
{
label proci = procID[eFaces[i]];
minProcID[edgeI] = min(minProcID[edgeI], proci);
maxProcID[edgeI] = max(maxProcID[edgeI], proci);
}
}
}
syncTools::syncEdgeList
(
mesh,
extrudeMeshEdges,
minProcID,
minEqOp<label>(),
labelMax // null value
);
syncTools::syncEdgeList
(
mesh,
extrudeMeshEdges,
maxProcID,
maxEqOp<label>(),
labelMin // null value
);
Pout<< "Adding processor or cyclic patches:" << nl << nl
<< "patchID\tpatch" << nl
<< "-------\t-----"
<< endl;
label nOldPatches = newPatches.size();
sidePatchID.setSize(extrudePatch.edgeFaces().size(), -1);
forAll(extrudePatch.edgeFaces(), edgeI)
{
const labelList& eFaces = extrudePatch.edgeFaces()[edgeI];
if
(
eFaces.size() == 1
&& extrudeEdgeGlobalFaces[edgeI].size() == 2
)
{
// coupled boundary edge. Find matching patch.
label nbrProci = minProcID[edgeI];
if (nbrProci == Pstream::myProcNo())
{
nbrProci = maxProcID[edgeI];
}
if (nbrProci == Pstream::myProcNo())
{
// Cyclic patch since both procs the same. This cyclic should
// already exist in newPatches so no adding necessary.
label facei = findUncoveredCyclicPatchFace
(
mesh,
UIndirectList<label>(extrudeMeshFaces, eFaces),
extrudeMeshEdges[edgeI]
);
if (facei != -1)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
label newPatchi = findPatchID
(
newPatches,
patches[patches.whichPatch(facei)].name()
);
sidePatchID[edgeI] = newPatchi;
}
else
{
FatalErrorInFunction
<< "Unable to determine coupled patch addressing"
<< abort(FatalError);
}
}
else
{
// Processor patch
word name
(
processorPolyPatch::newName(Pstream::myProcNo(), nbrProci)
);
sidePatchID[edgeI] = findPatchID(newPatches, name);
if (sidePatchID[edgeI] == -1)
{
dictionary patchDict;
patchDict.add("myProcNo", Pstream::myProcNo());
patchDict.add("neighbProcNo", nbrProci);
sidePatchID[edgeI] = addPatch<processorPolyPatch>
(
mesh.boundaryMesh(),
name,
patchDict,
newPatches
);
Pout<< sidePatchID[edgeI] << '\t' << name
<< nl;
}
}
}
}
Pout<< "Added " << newPatches.size()-nOldPatches
<< " coupled patches." << nl
<< endl;
}
void addZoneSidePatches
(
const fvMesh& mesh,
const wordList& zoneNames,
const word& oneDPolyPatchType,
DynamicList<polyPatch*>& newPatches,
labelList& zoneSidePatch
)