File size: 34,881 Bytes
5a600cf | 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 | /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 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/>.
\*---------------------------------------------------------------------------*/
#include "InteractionLists.H"
#include "globalIndexAndTransform.H"
#include "indexedOctree.H"
#include "treeDataFace.H"
#include "treeDataCell.H"
#include "volFields.H"
#include "meshTools.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::buildInteractionLists()
{
Info<< "Building InteractionLists with interaction distance "
<< maxDistance_ << endl;
const vector interactionVec = maxDistance_*vector::one;
treeBoundBox procBb(treeBoundBox(mesh_.points()));
treeBoundBox extendedProcBb
(
procBb.min() - interactionVec,
procBb.max() + interactionVec
);
treeBoundBoxList allExtendedProcBbs(Pstream::nProcs());
allExtendedProcBbs[Pstream::myProcNo()] = extendedProcBb;
Pstream::gatherList(allExtendedProcBbs);
Pstream::scatterList(allExtendedProcBbs);
List<treeBoundBox> extendedProcBbsInRange;
List<label> extendedProcBbsTransformIndex;
List<label> extendedProcBbsOrigProc;
findExtendedProcBbsInRange
(
procBb,
allExtendedProcBbs,
mesh_.globalData().globalTransforms(),
extendedProcBbsInRange,
extendedProcBbsTransformIndex,
extendedProcBbsOrigProc
);
treeBoundBoxList cellBbs(mesh_.nCells());
forAll(cellBbs, celli)
{
cellBbs[celli] = treeBoundBox
(
mesh_.cells()[celli].points
(
mesh_.faces(),
mesh_.points()
)
);
}
const globalIndexAndTransform& globalTransforms =
mesh_.globalData().globalTransforms();
// Recording which cells are in range of an extended boundBox, as
// only these cells will need to be tested to determine which
// referred cells that they interact with.
PackedBoolList cellInRangeOfCoupledPatch(mesh_.nCells(), false);
// IAndT: index (=local cell index) and transform (from
// globalIndexAndTransform)
DynamicList<labelPair> cellIAndTToExchange;
DynamicList<treeBoundBox> cellBbsToExchange;
DynamicList<label> procToDistributeCellTo;
forAll(extendedProcBbsInRange, ePBIRI)
{
const treeBoundBox& otherExtendedProcBb =
extendedProcBbsInRange[ePBIRI];
label transformIndex = extendedProcBbsTransformIndex[ePBIRI];
label origProc = extendedProcBbsOrigProc[ePBIRI];
forAll(cellBbs, celli)
{
const treeBoundBox& cellBb = cellBbs[celli];
if (cellBb.overlaps(otherExtendedProcBb))
{
// This cell is in range of the Bb of the other
// processor Bb, and so needs to be referred to it
cellInRangeOfCoupledPatch[celli] = true;
cellIAndTToExchange.append
(
globalTransforms.encode(celli, transformIndex)
);
cellBbsToExchange.append(cellBb);
procToDistributeCellTo.append(origProc);
}
}
}
buildMap(cellMapPtr_, procToDistributeCellTo);
// Needed for reverseDistribute
label preDistributionCellMapSize = procToDistributeCellTo.size();
cellMap().distribute(cellBbsToExchange);
cellMap().distribute(cellIAndTToExchange);
// Determine labelList specifying only cells that are in range of
// a coupled boundary to build an octree limited to these cells.
DynamicList<label> coupledPatchRangeCells;
forAll(cellInRangeOfCoupledPatch, celli)
{
if (cellInRangeOfCoupledPatch[celli])
{
coupledPatchRangeCells.append(celli);
}
}
treeBoundBox procBbRndExt
(
treeBoundBox(mesh_.points()).extend(1e-4)
);
indexedOctree<treeDataCell> coupledPatchRangeTree
(
treeDataCell(true, mesh_, coupledPatchRangeCells),
procBbRndExt,
8, // maxLevel,
10, // leafSize,
100.0 // duplicity
);
ril_.setSize(cellBbsToExchange.size());
// This needs to be a boolList, not PackedBoolList if
// reverseDistribute is called.
boolList cellBbRequiredByAnyCell(cellBbsToExchange.size(), false);
Info<< " Building referred interaction lists" << endl;
forAll(cellBbsToExchange, bbI)
{
const labelPair& ciat = cellIAndTToExchange[bbI];
const transformer& transform = globalTransforms.transform
(
globalTransforms.transformIndex(ciat)
);
treeBoundBox tempTransformedBb
(
transform.invTransformPosition(cellBbsToExchange[bbI].points())()
);
treeBoundBox extendedBb
(
tempTransformedBb.min() - interactionVec,
tempTransformedBb.max() + interactionVec
);
// Find all elements intersecting box.
labelList interactingElems
(
coupledPatchRangeTree.findBox(extendedBb)
);
if (!interactingElems.empty())
{
cellBbRequiredByAnyCell[bbI] = true;
}
ril_[bbI].setSize(interactingElems.size(), -1);
forAll(interactingElems, i)
{
label elemI = interactingElems[i];
// Here, a more detailed geometric test could be applied,
// i.e. a more accurate bounding volume like a OBB or
// convex hull or an exact geometrical test.
label c = coupledPatchRangeTree.shapes().cellLabels()[elemI];
ril_[bbI][i] = c;
}
}
// Perform subset of ril_, to remove any referred cells that do
// not interact. They will not be sent from originating
// processors. This assumes that the disappearance of the cell
// from the sending list of the source processor, simply removes
// the referred cell from the ril_, all of the subsequent indices
// shuffle down one, but the order and structure is preserved,
// i.e. it, is as if the cell had never been referred in the first
// place.
inplaceSubset(cellBbRequiredByAnyCell, ril_);
// Send information about which cells are actually required back
// to originating processors.
// At this point, cellBbsToExchange does not need to be maintained
// or distributed as it is not longer needed.
cellBbsToExchange.setSize(0);
cellMap().reverseDistribute
(
preDistributionCellMapSize,
cellBbRequiredByAnyCell
);
cellMap().reverseDistribute
(
preDistributionCellMapSize,
cellIAndTToExchange
);
// Perform ordering of cells to send, this invalidates the
// previous value of preDistributionCellMapSize.
preDistributionCellMapSize = -1;
// Move all of the used cells to refer to the start of the list
// and truncate it
inplaceSubset(cellBbRequiredByAnyCell, cellIAndTToExchange);
inplaceSubset(cellBbRequiredByAnyCell, procToDistributeCellTo);
preDistributionCellMapSize = procToDistributeCellTo.size();
// Rebuild distributionMap with only required referred cells
buildMap(cellMapPtr_, procToDistributeCellTo);
// Store cellIndexAndTransformToDistribute
cellIndexAndTransformToDistribute_.transfer(cellIAndTToExchange);
// Determine inverse addressing for referred cells
rilInverse_.setSize(mesh_.nCells());
// Temporary Dynamic lists for accumulation
List<DynamicList<label>> rilInverseTemp(rilInverse_.size());
// Loop over all referred cells
forAll(ril_, refCelli)
{
const labelList& realCells = ril_[refCelli];
// Loop over all real cells in that the referred cell is to
// supply interactions to and record the index of this
// referred cell in the real cells entry in rilInverse
forAll(realCells, realCelli)
{
rilInverseTemp[realCells[realCelli]].append(refCelli);
}
}
forAll(rilInverse_, celli)
{
rilInverse_[celli].transfer(rilInverseTemp[celli]);
}
// Determine which wall faces to refer
// The referring of wall patch data relies on patches having the same
// index on each processor.
mesh_.boundary().checkParallelSync(true);
// Determine the index of all of the wall faces on this processor
DynamicList<label> localWallFaces;
forAll(mesh_.boundary(), patchi)
{
const polyPatch& patch = mesh_.boundary()[patchi];
if (isA<wallPolyPatch>(patch))
{
localWallFaces.append(identityMap(patch.start(), patch.size()));
}
}
treeBoundBoxList wallFaceBbs(localWallFaces.size());
forAll(wallFaceBbs, i)
{
wallFaceBbs[i] = treeBoundBox
(
mesh_.faces()[localWallFaces[i]].points(mesh_.points())
);
}
// IAndT: index and transform
DynamicList<labelPair> wallFaceIAndTToExchange;
DynamicList<treeBoundBox> wallFaceBbsToExchange;
DynamicList<label> procToDistributeWallFaceTo;
forAll(extendedProcBbsInRange, ePBIRI)
{
const treeBoundBox& otherExtendedProcBb =
extendedProcBbsInRange[ePBIRI];
label transformIndex = extendedProcBbsTransformIndex[ePBIRI];
label origProc = extendedProcBbsOrigProc[ePBIRI];
forAll(wallFaceBbs, i)
{
const treeBoundBox& wallFaceBb = wallFaceBbs[i];
if (wallFaceBb.overlaps(otherExtendedProcBb))
{
// This wall face is in range of the Bb of the other
// processor Bb, and so needs to be referred to it
label wallFacei = localWallFaces[i];
wallFaceIAndTToExchange.append
(
globalTransforms.encode(wallFacei, transformIndex)
);
wallFaceBbsToExchange.append(wallFaceBb);
procToDistributeWallFaceTo.append(origProc);
}
}
}
buildMap(wallFaceMapPtr_, procToDistributeWallFaceTo);
// Needed for reverseDistribute
label preDistributionWallFaceMapSize = procToDistributeWallFaceTo.size();
wallFaceMap().distribute(wallFaceBbsToExchange);
wallFaceMap().distribute(wallFaceIAndTToExchange);
indexedOctree<treeDataCell> allCellsTree
(
treeDataCell(true, mesh_),
procBbRndExt,
8, // maxLevel,
10, // leafSize,
100.0 // duplicity
);
rwfil_.setSize(wallFaceBbsToExchange.size());
// This needs to be a boolList, not PackedBoolList if
// reverseDistribute is called.
boolList wallFaceBbRequiredByAnyCell(wallFaceBbsToExchange.size(), false);
forAll(wallFaceBbsToExchange, bbI)
{
const labelPair& wfiat = wallFaceIAndTToExchange[bbI];
const transformer& transform = globalTransforms.transform
(
globalTransforms.transformIndex(wfiat)
);
treeBoundBox tempTransformedBb
(
transform.invTransformPosition
(
wallFaceBbsToExchange[bbI].points()
)()
);
treeBoundBox extendedBb
(
tempTransformedBb.min() - interactionVec,
tempTransformedBb.max() + interactionVec
);
// Find all elements intersecting box.
labelList interactingElems
(
coupledPatchRangeTree.findBox(extendedBb)
);
if (!interactingElems.empty())
{
wallFaceBbRequiredByAnyCell[bbI] = true;
}
rwfil_[bbI].setSize(interactingElems.size(), -1);
forAll(interactingElems, i)
{
label elemI = interactingElems[i];
// Here, a more detailed geometric test could be applied,
// i.e. a more accurate bounding volume like a OBB or
// convex hull or an exact geometrical test.
label c = coupledPatchRangeTree.shapes().cellLabels()[elemI];
rwfil_[bbI][i] = c;
}
}
// Perform subset of rwfil_, to remove any referred wallFaces that do
// not interact. They will not be sent from originating
// processors. This assumes that the disappearance of the wallFace
// from the sending list of the source processor, simply removes
// the referred wallFace from the rwfil_, all of the subsequent indices
// shuffle down one, but the order and structure is preserved,
// i.e. it, is as if the wallFace had never been referred in the first
// place.
inplaceSubset(wallFaceBbRequiredByAnyCell, rwfil_);
// Send information about which wallFaces are actually required
// back to originating processors.
// At this point, wallFaceBbsToExchange does not need to be
// maintained or distributed as it is not longer needed.
wallFaceBbsToExchange.setSize(0);
wallFaceMap().reverseDistribute
(
preDistributionWallFaceMapSize,
wallFaceBbRequiredByAnyCell
);
wallFaceMap().reverseDistribute
(
preDistributionWallFaceMapSize,
wallFaceIAndTToExchange
);
// Perform ordering of wallFaces to send, this invalidates the
// previous value of preDistributionWallFaceMapSize.
preDistributionWallFaceMapSize = -1;
// Move all of the used wallFaces to refer to the start of the
// list and truncate it
inplaceSubset(wallFaceBbRequiredByAnyCell, wallFaceIAndTToExchange);
inplaceSubset(wallFaceBbRequiredByAnyCell, procToDistributeWallFaceTo);
preDistributionWallFaceMapSize = procToDistributeWallFaceTo.size();
// Rebuild distributionMap with only required referred wallFaces
buildMap(wallFaceMapPtr_, procToDistributeWallFaceTo);
// Store wallFaceIndexAndTransformToDistribute
wallFaceIndexAndTransformToDistribute_.transfer(wallFaceIAndTToExchange);
// Determine inverse addressing for referred wallFaces
rwfilInverse_.setSize(mesh_.nCells());
// Temporary Dynamic lists for accumulation
List<DynamicList<label>> rwfilInverseTemp(rwfilInverse_.size());
// Loop over all referred wall faces
forAll(rwfil_, refWallFacei)
{
const labelList& realCells = rwfil_[refWallFacei];
// Loop over all real cells in that the referred wall face is
// to supply interactions to and record the index of this
// referred wall face in the real cells entry in rwfilInverse
forAll(realCells, realCelli)
{
rwfilInverseTemp[realCells[realCelli]].append(refWallFacei);
}
}
forAll(rwfilInverse_, celli)
{
rwfilInverse_[celli].transfer(rwfilInverseTemp[celli]);
}
// Refer wall faces to the appropriate processor
referredWallFaces_.setSize(wallFaceIndexAndTransformToDistribute_.size());
forAll(referredWallFaces_, rWFI)
{
const labelPair& wfiat = wallFaceIndexAndTransformToDistribute_[rWFI];
label wallFaceIndex = globalTransforms.index(wfiat);
const transformer& transform = globalTransforms.transform
(
globalTransforms.transformIndex(wfiat)
);
const face& f = mesh_.faces()[wallFaceIndex];
label patchi = mesh_.boundary().patchIndices()
[
wallFaceIndex - mesh_.nInternalFaces()
];
referredWallFaces_[rWFI] = referredWallFace
(
face(identityMap(f.size())),
transform.invTransformPosition(f.points(mesh_.points())),
patchi
);
}
wallFaceMap().distribute(referredWallFaces_);
if (writeCloud_)
{
writeReferredWallFaces();
}
// Direct interaction list and direct wall faces
Info<< " Building direct interaction lists" << endl;
indexedOctree<treeDataFace> wallFacesTree
(
treeDataFace(true, mesh_, localWallFaces),
procBbRndExt,
8, // maxLevel,
10, // leafSize,
100.0
);
dil_.setSize(mesh_.nCells());
dwfil_.setSize(mesh_.nCells());
forAll(cellBbs, celli)
{
const treeBoundBox& cellBb = cellBbs[celli];
treeBoundBox extendedBb
(
cellBb.min() - interactionVec,
cellBb.max() + interactionVec
);
// Find all cells intersecting extendedBb
labelList interactingElems(allCellsTree.findBox(extendedBb));
// Reserve space to avoid multiple resizing
DynamicList<label> cellDIL(interactingElems.size());
forAll(interactingElems, i)
{
label elemI = interactingElems[i];
label c = allCellsTree.shapes().cellLabels()[elemI];
// Here, a more detailed geometric test could be applied,
// i.e. a more accurate bounding volume like a OBB or
// convex hull, or an exact geometrical test.
// The higher index cell is added to the lower index
// cell's DIL. A cell is not added to its own DIL.
if (c > celli)
{
cellDIL.append(c);
}
}
dil_[celli].transfer(cellDIL);
// Find all wall faces intersecting extendedBb
interactingElems = wallFacesTree.findBox(extendedBb);
dwfil_[celli].setSize(interactingElems.size(), -1);
forAll(interactingElems, i)
{
label elemI = interactingElems[i];
label f = wallFacesTree.shapes().faceLabels()[elemI];
dwfil_[celli][i] = f;
}
}
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::findExtendedProcBbsInRange
(
const treeBoundBox& procBb,
const List<treeBoundBox>& allExtendedProcBbs,
const globalIndexAndTransform& globalTransforms,
List<treeBoundBox>& extendedProcBbsInRange,
List<label>& extendedProcBbsTransformIndex,
List<label>& extendedProcBbsOrigProc
)
{
extendedProcBbsInRange.setSize(0);
extendedProcBbsTransformIndex.setSize(0);
extendedProcBbsOrigProc.setSize(0);
DynamicList<treeBoundBox> tmpExtendedProcBbsInRange;
DynamicList<label> tmpExtendedProcBbsTransformIndex;
DynamicList<label> tmpExtendedProcBbsOrigProc;
label nTrans = globalTransforms.nIndependentTransforms();
forAll(allExtendedProcBbs, proci)
{
List<label> permutationIndices(nTrans, 0);
if (nTrans == 0 && proci != Pstream::myProcNo())
{
treeBoundBox extendedReferredProcBb = allExtendedProcBbs[proci];
if (procBb.overlaps(extendedReferredProcBb))
{
tmpExtendedProcBbsInRange.append(extendedReferredProcBb);
// Dummy index, there are no transforms, so there will
// be no resultant transform when this is decoded.
tmpExtendedProcBbsTransformIndex.append(0);
tmpExtendedProcBbsOrigProc.append(proci);
}
}
else if (nTrans == 3)
{
label& i = permutationIndices[0];
label& j = permutationIndices[1];
label& k = permutationIndices[2];
for (i = -1; i <= 1; i++)
{
for (j = -1; j <= 1; j++)
{
for (k = -1; k <= 1; k++)
{
if
(
i == 0
&& j == 0
&& k == 0
&& proci == Pstream::myProcNo()
)
{
// Skip this processor's extended boundBox
// when it has no transformation
continue;
}
label transI = globalTransforms.encodeTransformIndex
(
permutationIndices
);
const transformer& transform =
globalTransforms.transform(transI);
treeBoundBox extendedReferredProcBb
(
transform.transformPosition
(
allExtendedProcBbs[proci].points()
)()
);
if (procBb.overlaps(extendedReferredProcBb))
{
tmpExtendedProcBbsInRange.append
(
extendedReferredProcBb
);
tmpExtendedProcBbsTransformIndex.append(transI);
tmpExtendedProcBbsOrigProc.append(proci);
}
}
}
}
}
else if (nTrans == 2)
{
label& i = permutationIndices[0];
label& j = permutationIndices[1];
for (i = -1; i <= 1; i++)
{
for (j = -1; j <= 1; j++)
{
if (i == 0 && j == 0 && proci == Pstream::myProcNo())
{
// Skip this processor's extended boundBox
// when it has no transformation
continue;
}
label transI = globalTransforms.encodeTransformIndex
(
permutationIndices
);
const transformer& transform =
globalTransforms.transform(transI);
treeBoundBox extendedReferredProcBb
(
transform.transformPosition
(
allExtendedProcBbs[proci].points()
)()
);
if (procBb.overlaps(extendedReferredProcBb))
{
tmpExtendedProcBbsInRange.append
(
extendedReferredProcBb
);
tmpExtendedProcBbsTransformIndex.append(transI);
tmpExtendedProcBbsOrigProc.append(proci);
}
}
}
}
else if (nTrans == 1)
{
label& i = permutationIndices[0];
for (i = -1; i <= 1; i++)
{
if (i == 0 && proci == Pstream::myProcNo())
{
// Skip this processor's extended boundBox when it
// has no transformation
continue;
}
label transI = globalTransforms.encodeTransformIndex
(
permutationIndices
);
const transformer& transform =
globalTransforms.transform(transI);
treeBoundBox extendedReferredProcBb
(
transform.transformPosition
(
allExtendedProcBbs[proci].points()
)()
);
if (procBb.overlaps(extendedReferredProcBb))
{
tmpExtendedProcBbsInRange.append
(
extendedReferredProcBb
);
tmpExtendedProcBbsTransformIndex.append(transI);
tmpExtendedProcBbsOrigProc.append(proci);
}
}
}
}
extendedProcBbsInRange = move(tmpExtendedProcBbsInRange);
extendedProcBbsTransformIndex = move(tmpExtendedProcBbsTransformIndex);
extendedProcBbsOrigProc = move(tmpExtendedProcBbsOrigProc);
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::buildMap
(
autoPtr<distributionMap>& mapPtr,
const List<label>& toProc
)
{
// Determine send map
// ~~~~~~~~~~~~~~~~~~
// 1. Count
labelList nSend(Pstream::nProcs(), 0);
forAll(toProc, i)
{
label proci = toProc[i];
nSend[proci]++;
}
// 2. Size sendMap
labelListList sendMap(Pstream::nProcs());
forAll(nSend, proci)
{
sendMap[proci].setSize(nSend[proci]);
nSend[proci] = 0;
}
// 3. Fill sendMap
forAll(toProc, i)
{
label proci = toProc[i];
sendMap[proci][nSend[proci]++] = i;
}
// 4. Send over how many I need to receive
labelList recvSizes;
Pstream::exchangeSizes(sendMap, recvSizes);
// Determine receive map
// ~~~~~~~~~~~~~~~~~~~~~
labelListList constructMap(Pstream::nProcs());
// Local transfers first
constructMap[Pstream::myProcNo()] = identityMap
(
sendMap[Pstream::myProcNo()].size()
);
label constructSize = constructMap[Pstream::myProcNo()].size();
forAll(constructMap, proci)
{
if (proci != Pstream::myProcNo())
{
label nRecv = recvSizes[proci];
constructMap[proci].setSize(nRecv);
for (label i = 0; i < nRecv; i++)
{
constructMap[proci][i] = constructSize++;
}
}
}
mapPtr.reset
(
new distributionMap
(
constructSize,
move(sendMap),
move(constructMap)
)
);
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::prepareParticlesToRefer
(
const List<DynamicList<ParticleType*>>& cellOccupancy
)
{
const globalIndexAndTransform& globalTransforms =
mesh_.globalData().globalTransforms();
referredParticles_.setSize(cellIndexAndTransformToDistribute_.size());
// Clear all existing referred particles
forAll(referredParticles_, i)
{
referredParticles_[i].clear();
}
// Clear all particles that may have been populated into the cloud
cloud_.clear();
forAll(cellIndexAndTransformToDistribute_, i)
{
const labelPair ciat = cellIndexAndTransformToDistribute_[i];
label cellIndex = globalTransforms.index(ciat);
List<ParticleType*> realParticles = cellOccupancy[cellIndex];
IDLList<ParticleType>& particlesToRefer = referredParticles_[i];
forAll(realParticles, rM)
{
const ParticleType& particle = *realParticles[rM];
particlesToRefer.append(particle.clone().ptr());
prepareParticleToBeReferred(particlesToRefer.last(), ciat);
}
}
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::prepareParticleToBeReferred
(
ParticleType* particle,
labelPair ciat
)
{
const globalIndexAndTransform& globalTransforms =
mesh_.globalData().globalTransforms();
const transformer& transform = globalTransforms.transform
(
globalTransforms.transformIndex(ciat)
);
particle->prepareForInteractionListReferral(mesh_, transform);
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::fillReferredParticleCloud()
{
if (writeCloud_)
{
forAll(referredParticles_, refCelli)
{
const IDLList<ParticleType>& refCell =
referredParticles_[refCelli];
forAllConstIter(typename IDLList<ParticleType>, refCell, iter)
{
cloud_.addParticle
(
static_cast<ParticleType*>(iter().clone().ptr())
);
}
}
}
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::prepareWallDataToRefer()
{
const globalIndexAndTransform& globalTransforms =
mesh_.globalData().globalTransforms();
referredWallData_.setSize
(
wallFaceIndexAndTransformToDistribute_.size()
);
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
forAll(referredWallData_, rWVI)
{
const labelPair& wfiat = wallFaceIndexAndTransformToDistribute_[rWVI];
label wallFaceIndex = globalTransforms.index(wfiat);
const transformer& transform = globalTransforms.transform
(
globalTransforms.transformIndex(wfiat)
);
label patchi = mesh_.boundary().patchIndices()
[
wallFaceIndex - mesh_.nInternalFaces()
];
label patchFacei =
wallFaceIndex
- mesh_.boundary()[patchi].start();
// Need to transform velocity when tensor transforms are
// supported
referredWallData_[rWVI] = U.boundaryField()[patchi][patchFacei];
if (transform.transforms())
{
referredWallData_[rWVI] =
transform.invTransform(referredWallData_[rWVI]);
}
}
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::writeReferredWallFaces() const
{
if (referredWallFaces_.empty())
{
return;
}
fileName objDir = mesh_.time().timePath()/lagrangian::cloud::prefix;
mkDir(objDir);
fileName objFileName = "referredWallFaces.obj";
OFstream str(objDir/objFileName);
Info<< " Writing "
<< mesh_.time().name()/lagrangian::cloud::prefix/objFileName
<< endl;
label offset = 1;
forAll(referredWallFaces_, rWFI)
{
const referredWallFace& rwf = referredWallFaces_[rWFI];
forAll(rwf, fPtI)
{
meshTools::writeOBJ(str, rwf.points()[rwf[fPtI]]);
}
str<< 'f';
forAll(rwf, fPtI)
{
str<< ' ' << fPtI + offset;
}
str<< nl;
offset += rwf.size();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
Foam::InteractionLists<ParticleType>::InteractionLists(const polyMesh& mesh)
:
mesh_(mesh),
cloud_(mesh_, "nullptr_Cloud", IDLList<ParticleType>()),
writeCloud_(false),
cellMapPtr_(),
wallFaceMapPtr_(),
maxDistance_(0.0),
dil_(),
dwfil_(),
ril_(),
rilInverse_(),
cellIndexAndTransformToDistribute_(),
wallFaceIndexAndTransformToDistribute_(),
referredWallFaces_(),
UName_("unknown_U"),
referredWallData_(),
referredParticles_()
{}
template<class ParticleType>
Foam::InteractionLists<ParticleType>::InteractionLists
(
const polyMesh& mesh,
scalar maxDistance,
Switch writeCloud,
const word& UName
)
:
mesh_(mesh),
cloud_(mesh_, "referredParticleCloud", IDLList<ParticleType>()),
writeCloud_(writeCloud),
cellMapPtr_(),
wallFaceMapPtr_(),
maxDistance_(maxDistance),
dil_(),
dwfil_(),
ril_(),
rilInverse_(),
cellIndexAndTransformToDistribute_(),
wallFaceIndexAndTransformToDistribute_(),
referredWallFaces_(),
UName_(UName),
referredWallData_(),
referredParticles_()
{
buildInteractionLists();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ParticleType>
Foam::InteractionLists<ParticleType>::~InteractionLists()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::sendReferredData
(
const List<DynamicList<ParticleType*>>& cellOccupancy,
PstreamBuffers& pBufs
)
{
if (mesh_.changing())
{
WarningInFunction
<< "Mesh changing, rebuilding InteractionLists form scratch."
<< endl;
buildInteractionLists();
}
prepareWallDataToRefer();
prepareParticlesToRefer(cellOccupancy);
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& subMap = cellMap().subMap()[domain];
if (subMap.size())
{
UOPstream toDomain(domain, pBufs);
UIndirectList<IDLList<ParticleType>> subMappedParticles
(
referredParticles_,
subMap
);
forAll(subMappedParticles, i)
{
toDomain << subMappedParticles[i];
}
}
}
// Using the distributionMap to start sending and receiving the
// buffer but not block, i.e. it is calling
// pBufs.finishedSends(false);
wallFaceMap().send(pBufs, referredWallData_);
}
template<class ParticleType>
void Foam::InteractionLists<ParticleType>::receiveReferredData
(
PstreamBuffers& pBufs,
const label startOfRequests
)
{
Pstream::waitRequests(startOfRequests);
referredParticles_.setSize(cellMap().constructSize());
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& constructMap = cellMap().constructMap()[domain];
if (constructMap.size())
{
UIPstream str(domain, pBufs);
forAll(constructMap, i)
{
referredParticles_[constructMap[i]] =
IDLList<ParticleType>(str);
}
}
}
forAll(referredParticles_, refCelli)
{
IDLList<ParticleType>& refCell = referredParticles_[refCelli];
forAllIter(typename IDLList<ParticleType>, refCell, iter)
{
iter().correctAfterInteractionListReferral
(
mesh_,
ril_[refCelli][0]
);
}
}
fillReferredParticleCloud();
wallFaceMap().receive(pBufs, referredWallData_);
}
// ************************************************************************* //
|