37 #include <vtkAppendFilter.h> 38 #include <vtkCellData.h> 39 #include <vtkCleanPolyData.h> 40 #include <vtkEdgeTable.h> 41 #include <vtkGenericCell.h> 42 #include <vtkPointData.h> 43 #include <vtkPointLocator.h> 44 #include <vtkUnstructuredGrid.h> 51 #include <unordered_set> 63 class RocPartCommGenRunner {
77 RocPartCommGenRunner(
const std::string &volname,
const std::string &surfname,
79 ~RocPartCommGenRunner();
84 void execute(
int numPartitions);
86 void extractPatches();
88 void AddGlobalCellIds(std::shared_ptr<meshBase>
mesh)
const;
90 void getGhostInformation(
int me,
bool vol);
93 void getGlobalIdsAndMaps(
int numPartitions,
bool vol);
96 void getVirtualCells(
int me,
int you,
bool vol);
98 void getSharedPatchInformation();
116 void writeVolCgns(
const std::string &prefix,
int proc,
int type);
118 void writeSurfCgns(
const std::string &prefix,
int proc);
120 void writeVolCellFaces(
const std::string &prefix,
int proc,
int type)
const;
125 void mapWriter()
const;
127 void cmpWriter(
int proc,
int nCells)
const;
129 void comWriter(
int proc)
const;
131 void dimWriter(
int proc, std::shared_ptr<meshBase> realMB,
132 std::shared_ptr<meshBase> totalMB)
const;
134 void dimSurfWriter(
int proc,
const std::vector<cgsize_t> &cgConnReal,
135 const std::vector<cgsize_t> &cgConnVirtual,
int patchNo);
136 void dimSurfWriter(
int proc)
const;
137 void dimSurfSort(
int proc)
const;
139 void txtWriter()
const;
145 std::shared_ptr<meshBase>
mesh;
162 std::vector<std::map<int, std::shared_ptr<meshBase>>>
167 std::vector<std::map<int, std::shared_ptr<meshBase>>>
170 std::vector<std::map<int, std::shared_ptr<meshBase>>>
173 std::vector<std::map<int, std::map<int, std::shared_ptr<meshBase>>>>
201 std::map<int, std::map<int, std::unordered_set<int>>>
sentNodes;
203 std::map<int, std::map<int, std::unordered_set<int>>>
sentCells;
227 std::vector<std::map<int, std::map<int, std::map<int, std::vector<int>>>>>
263 int writeSharedToPconn(
int proc,
const std::string &type);
266 void writeSharedToPconn(
int proc);
269 void writeSentToPconn(
int proc,
const std::string &type,
bool nodeOrCell);
272 void writeReceivedToPconn(
int proc,
const std::string &type,
bool nodeOrCell);
275 void getGhostInformation(
int me,
int you,
bool hasShared,
bool vol,
276 vtkSmartPointer<vtkIdList> cellIdsList,
277 vtkSmartPointer<vtkGenericCell> genCell);
279 void restructurePconn(std::vector<int> &pconnVec,
int proc,
int volOrSurf,
280 const std::map<int, int> &old2New,
int &nGhost);
282 void mapOld2NewPointData(std::vector<double> &pointData,
283 const std::map<int, int> &new2Old)
const;
285 void swapTriOrdering(std::vector<cgsize_t> &connVec)
const;
310 void clearPconnVectors();
311 void clearBorderVector();
323 vtkSmartPointer<vtkPolyData> deleteInterPartitionSurface(
324 std::shared_ptr<meshBase> fullSurf,
325 vtkSmartPointer<vtkDataSet> partSurf)
const;
326 vtkSmartPointer<vtkEdgeTable> createPartitionEdgeTable(
int i)
const;
329 std::string getPatchType(
int patchNo)
const;
371 RocPartCommGenRunner::RocPartCommGenRunner(
const std::string &volname,
372 const std::string &surfname,
374 std::cout <<
"RocPartCommGenRunner created" << std::endl;
380 this->
base_t =
"00.000000";
383 this->execute(numPartitions);
386 void RocPartCommGenRunner::execute(
int numPartitions) {
387 std::cout <<
"executing" << std::endl;
393 std::vector<std::string> paneDataAndGlobalCellIds = {
394 "patchNo",
"bcflag",
"cnstr_type",
"GlobalCellIds"};
397 vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid;
405 std::cout <<
"getting maps" << std::endl;
406 this->getGlobalIdsAndMaps(numPartitions,
true);
414 for (
int i = 0; i < numPartitions; ++i) {
415 vtkSmartPointer<vtkAppendFilter> appendFilter =
417 appendFilter->AddInputData(deleteInterPartitionSurface(
419 appendFilter->Update();
422 unstructuredGrid = appendFilter->GetOutput();
423 std::string basename(
prefixPath +
"surfacePartition");
424 basename += std::to_string(i);
440 "Consistent Interpolation");
441 transfer->transferCellData(paneDataAndGlobalCellIds,
447 this->getGhostInformation(i,
true);
450 std::string type(
"01");
452 this->writeSentToPconn(i, type,
true);
453 this->writeReceivedToPconn(i, type,
true);
454 this->writeSentToPconn(i, type,
false);
455 this->writeReceivedToPconn(i, type,
false);
456 this->comWriter(i + 1);
460 for (
int j = 0; j < numPartitions; ++j) this->getVirtualCells(i, j,
true);
463 this->writeVolCgns(
"fluid", i, 1);
464 this->clearPconnVectors();
468 this->cmpWriter(0, this->
mesh->getDataSet()->GetNumberOfCells());
470 this->dimWriter(0, this->
mesh, this->
mesh);
473 this->getGlobalIdsAndMaps(numPartitions,
false);
474 for (
int i = 0; i < numPartitions; ++i) {
476 this->getGhostInformation(i,
false);
478 for (
int j = 0; j < numPartitions; ++j) {
479 this->getVirtualCells(i, j,
false);
485 this->extractPatches();
491 this->getSharedPatchInformation();
498 std::map<int, int> surfZoneNumbersMap;
499 for (
int iProc = 0; iProc < numPartitions; ++iProc) {
501 surfZoneNumbersMap.clear();
505 surfZoneNumbersMap[it->first] = zoneCounter;
511 for (
int i = 0; i < numPartitions; ++i) {
512 this->writeSharedToPconn(i);
513 std::cout <<
"writing rocflu ifluid_b cgns files" << std::endl;
514 this->writeSurfCgns(
"ifluid_b", i);
515 std::cout <<
"writing rocflu ifluid_ni cgns files" << std::endl;
516 this->writeSurfCgns(
"ifluid_ni", i);
517 std::cout <<
"writing rocflu ifluid_nb cgns files" << std::endl;
518 this->writeSurfCgns(
"ifluid_nb", i);
519 std::cout <<
"writing rocburn burn cgns files" << std::endl;
520 this->writeSurfCgns(
"burn", i);
521 std::cout <<
"writing rocburn iburn_all files" << std::endl;
522 this->writeSurfCgns(
"iburn_all", i);
525 this->dimSurfWriter(0);
526 for (
int i = 0; i < numPartitions; ++i) {
527 this->dimSurfSort(i);
536 this->getGlobalIdsAndMaps(numPartitions,
true);
537 for (
int i = 0; i < numPartitions; ++i) {
539 this->writeVolCellFaces(
"fluid", i, 1);
546 void RocPartCommGenRunner::AddGlobalCellIds(
547 std::shared_ptr<meshBase> _mesh)
const {
550 globalCellIds->SetName(
"GlobalCellIds");
551 globalCellIds->SetNumberOfComponents(1);
552 globalCellIds->SetNumberOfTuples(_mesh->getNumberOfCells());
553 for (
int i = 0; i < _mesh->getNumberOfCells(); ++i)
554 globalCellIds->SetTuple1(i, i);
555 _mesh->getDataSet()->GetCellData()->AddArray(globalCellIds);
558 void RocPartCommGenRunner::getGlobalIdsAndMaps(
int numPartitions,
bool vol) {
565 this->globalCellIds.clear();
573 this->globalCellIds.resize(numPartitions);
577 for (
int i = 0; i < numPartitions; ++i) {
584 this->globalCellIds[i] =
590 for (
int i = 0; i < numPartitions; ++i) {
595 int globNodeId =
static_cast<int>(globalNodeIds->GetTuple1(j));
599 vtkSmartPointer<vtkDataArray> globalCellIds =
603 int globCellId =
static_cast<int>(globalCellIds->GetTuple1(j));
607 this->globalNodeIds[i] =
609 this->globalCellIds[i] =
615 int RocPartCommGenRunner::writeSharedToPconn(
int proc,
616 const std::string &type) {
618 while (sharedItr != this->
sharedNodes[proc].end()) {
619 if (sharedItr->second.size() != 0) {
623 std::stringstream ss;
624 ss << sharedItr->first + 1 << type;
627 this->
volPconns[proc].push_back(std::stoi(ss.str()));
630 this->
volPconns[proc].push_back(sharedItr->second.size());
633 std::vector<int> tmpInd;
634 for (
int i = 0; i < sharedItr->second.size(); ++i) {
635 this->
volPconns[proc].push_back(sharedItr->second[i] + 1);
636 tmpInd.push_back(sharedItr->second[i] + 1);
645 void RocPartCommGenRunner::writeSharedToPconn(
int proc) {
648 auto it1 = it->second.begin();
649 while (it1 != it->second.end()) {
650 auto it2 = it1->second.begin();
651 while (it2 != it1->second.end()) {
652 if (it2->second.size() > 0) {
653 this->
surfPconns[proc][it->first].push_back(1);
655 std::stringstream ss;
656 ss << it1->first + 1 << ((it->first + 1) < 10 ?
"0" :
"")
658 this->
surfPconns[proc][it->first].push_back(std::stoi(ss.str()));
660 if (it2->second.size() > 0) {
662 this->
surfPconns[proc][it->first].push_back(it2->second.size());
663 for (
int k = 0; k < it2->second.size(); ++k) {
664 this->
surfPconns[proc][it->first].push_back(it2->second[k] + 1);
667 this->
surfPconns[proc][it->first].push_back(0);
678 void RocPartCommGenRunner::writeSentToPconn(
int proc,
const std::string &type,
680 std::map<int, std::unordered_set<int>>::iterator sentItr;
681 std::map<int, std::unordered_set<int>>::iterator end;
690 std::vector<int> tmpInd;
691 while (sentItr != end) {
692 if (sentItr->second.size() != 0) {
696 std::stringstream ss;
697 ss << sentItr->first + 1 << type;
700 this->
volPconns[proc].push_back(std::stoi(ss.str()));
703 this->
volPconns[proc].push_back(sentItr->second.size());
708 std::vector<std::pair<int, int>> sentNodesIdPairs;
709 for (
auto itr = sentItr->second.begin(); itr != sentItr->second.end();
711 sentNodesIdPairs.push_back(
714 std::sort(sentNodesIdPairs.begin(), sentNodesIdPairs.end());
715 std::vector<int> sentNodesSorted;
716 for (
auto itr = sentNodesIdPairs.begin(); itr != sentNodesIdPairs.end();
718 sentNodesSorted.push_back((*itr).second);
721 auto tmpIt = sentNodesSorted.begin();
723 while (tmpIt != sentNodesSorted.end()) {
724 this->
volPconns[proc].push_back(*tmpIt + 1);
725 tmpInd.push_back(*tmpIt + 1);
732 std::vector<std::pair<int, int>> sentCellsIdPairs;
733 for (
auto itr = sentItr->second.begin(); itr != sentItr->second.end();
735 sentCellsIdPairs.push_back(
738 std::sort(sentCellsIdPairs.begin(), sentCellsIdPairs.end());
739 std::vector<int> sentCellsSorted;
740 for (
auto itr = sentCellsIdPairs.begin(); itr != sentCellsIdPairs.end();
742 sentCellsSorted.push_back((*itr).second);
745 auto tmpIt = sentCellsSorted.begin();
747 while (tmpIt != sentCellsSorted.end()) {
748 this->
volPconns[proc].push_back(*tmpIt + 1);
749 tmpInd.push_back(*tmpIt + 1);
764 void RocPartCommGenRunner::writeReceivedToPconn(
int proc,
765 const std::string &type,
767 std::map<int, std::unordered_set<int>>::iterator receivedItr;
768 std::map<int, std::unordered_set<int>>::iterator end;
776 offset =
partitions[proc]->getNumberOfPoints();
782 offset =
partitions[proc]->getNumberOfCells();
786 int numPrevReceived = 0;
788 std::vector<int> tmpInd;
793 std::map<int, int> receivedNodeMap;
795 while (receivedItr != end) {
796 if (receivedItr->second.size() != 0) {
799 std::stringstream ss;
800 ss << receivedItr->first + 1 << type;
803 this->
volPconns[proc].push_back(std::stoi(ss.str()));
807 int numDuplicates = 0;
808 this->
volPconns[proc].push_back(receivedItr->second.size());
811 for (
auto itr = (receivedItr->second).begin();
812 itr != (receivedItr->second).end(); ++itr) {
813 if (receivedNodeMap.find(*itr) == receivedNodeMap.end()) {
814 receivedNodeMap[*itr] =
815 offset + numPrevReceived +
816 std::distance((receivedItr->second).begin(), itr) + 1 -
819 offset + numPrevReceived +
820 std::distance((receivedItr->second).begin(), itr) + 1 -
822 tmpInd.push_back(offset + numPrevReceived +
823 std::distance((receivedItr->second).begin(), itr) +
827 this->
volPconns[proc].push_back(receivedNodeMap[*itr]);
828 tmpInd.push_back(receivedNodeMap[*itr]);
837 numPrevReceived += numReceived;
843 void RocPartCommGenRunner::getVirtualCells(
int me,
int you,
bool vol) {
845 std::vector<nemId_t> virtuals(
receivedCells[me][you].begin(),
850 std::stringstream ss;
853 <<
"Of" << me <<
"from" << you <<
".vtu";
862 std::stringstream ss;
865 <<
"Of" << me <<
"from" << you <<
".vtu";
871 void RocPartCommGenRunner::getGhostInformation(
int me,
bool volOrSurf) {
874 vtkSmartPointer<vtkGenericCell> genCell =
878 for (
int you = 0; you <
partitions.size(); ++you) {
880 this->getGhostInformation(me, you,
false, volOrSurf, cellIdsList,
882 this->getGhostInformation(you, me,
true, volOrSurf, cellIdsList, genCell);
887 void RocPartCommGenRunner::getGhostInformation(
888 int me,
int you,
bool hasShared,
bool vol,
889 vtkSmartPointer<vtkIdList> cellIdsList,
890 vtkSmartPointer<vtkGenericCell> genCell) {
893 vtkSmartPointer<vtkIdList> volCellIdsList;
905 std::vector<int> tmpVec;
906 std::set_intersection(globalNodeIds[me].begin(), globalNodeIds[me].end(),
907 globalNodeIds[you].begin(), globalNodeIds[you].end(),
908 std::back_inserter(tmpVec));
921 for (
int j = 0; j < tmpVec.size(); ++j) {
940 cellIdsList->Reset();
943 meMesh->
getDataSet()->GetPointCells(localPntId, cellIdsList);
946 std::vector<int> notSharedCellNodes;
949 std::vector<int> notSharedWithVolSurfNodes;
954 vtkSmartPointer<vtkPointLocator> pointLocator =
958 for (
int k = 0; k < cellIdsList->GetNumberOfIds(); ++k) {
960 int localCellId = cellIdsList->GetId(k);
963 meMesh->
getDataSet()->GetCell(localCellId, genCell);
965 int numSharedInCell = 0;
966 vtkSmartPointer<vtkPolyData> virtualNodesSet =
968 std::vector<int> virtualNodesIdList;
973 vtkSmartPointer<vtkIdList> cellPoints =
975 vtkSmartPointer<vtkPoints> virtualNodesList =
979 for (
auto itr =
sentCells[me][you].begin();
980 itr !=
sentCells[me][you].end(); ++itr) {
981 meVolMesh->
getDataSet()->GetCellPoints((*itr), cellPoints);
982 for (
int ipt = 0; ipt < cellPoints->GetNumberOfIds(); ipt++) {
983 virtualNodesList->InsertNextPoint(
984 meVolMesh->
getDataSet()->GetPoint(cellPoints->GetId(ipt)));
985 virtualNodesIdList.push_back(cellPoints->GetId(ipt));
988 virtualNodesSet->SetPoints(virtualNodesList);
992 notSharedCellNodes.clear();
993 notSharedWithVolSurfNodes.clear();
997 std::vector<int> virtVolCellIds;
998 virtVolCellIds.clear();
1000 for (
int l = 0; l < genCell->GetNumberOfPoints(); ++l) {
1002 int pntId = genCell->GetPointId(l);
1007 if (std::find(tmpVec.begin(), tmpVec.end(), globPntId) ==
1010 notSharedCellNodes.push_back(pntId);
1012 double *pntCoor = meMesh->
getDataSet()->GetPoint(pntId);
1013 if (virtualNodesSet->GetNumberOfPoints() > 0) {
1014 pointLocator->SetDataSet(virtualNodesSet);
1015 pointLocator->AutomaticOn();
1016 pointLocator->BuildLocator();
1021 if (result->GetNumberOfIds()) {
1030 std::vector<int> virtVolCellIdsTmp;
1031 virtVolCellIdsTmp.clear();
1032 for (
int i = 0; i < result->GetNumberOfIds(); i++) {
1033 vtkSmartPointer<vtkIdList> myList =
1036 virtualNodesIdList[result->GetId(i)], myList);
1037 for (
int i = 0; i < myList->GetNumberOfIds(); i++) {
1038 virtVolCellIdsTmp.push_back(myList->GetId(i));
1043 sort(virtVolCellIdsTmp.begin(), virtVolCellIdsTmp.end());
1044 virtVolCellIdsTmp.erase(
1045 unique(virtVolCellIdsTmp.begin(), virtVolCellIdsTmp.end()),
1046 virtVolCellIdsTmp.end());
1047 for (
int &itr : virtVolCellIdsTmp) {
1048 virtVolCellIds.push_back(itr);
1052 notSharedWithVolSurfNodes.push_back(pntId);
1056 numSharedInCell += 1;
1059 double *pntCoor = meMesh->
getDataSet()->GetPoint(pntId);
1060 if (virtualNodesSet->GetNumberOfPoints() > 0) {
1061 pointLocator->SetDataSet(virtualNodesSet);
1062 pointLocator->AutomaticOn();
1063 pointLocator->BuildLocator();
1068 if (result->GetNumberOfIds()) {
1077 std::vector<int> virtVolCellIdsTmp;
1078 virtVolCellIdsTmp.clear();
1079 for (
int i = 0; i < result->GetNumberOfIds(); i++) {
1080 vtkSmartPointer<vtkIdList> myList =
1083 virtualNodesIdList[result->GetId(i)], myList);
1084 for (
int i = 0; i < myList->GetNumberOfIds(); i++) {
1085 virtVolCellIdsTmp.push_back(myList->GetId(i));
1089 sort(virtVolCellIdsTmp.begin(), virtVolCellIdsTmp.end());
1090 virtVolCellIdsTmp.erase(
1091 unique(virtVolCellIdsTmp.begin(), virtVolCellIdsTmp.end()),
1092 virtVolCellIdsTmp.end());
1093 for (
int &itr : virtVolCellIdsTmp) {
1094 virtVolCellIds.push_back(itr);
1098 notSharedWithVolSurfNodes.push_back(pntId);
1102 if (vol && numSharedInCell >= 3) {
1104 for (
auto itr = notSharedCellNodes.begin();
1105 itr != notSharedCellNodes.end(); itr++) {
1123 std::sort(virtVolCellIds.begin(), virtVolCellIds.end());
1125 std::vector<int> virtVolCellIdsTmp;
1126 for (
auto itr = virtVolCellIds.begin(); itr != virtVolCellIds.end();
1130 virtVolCellIdsTmp.push_back(*itr);
1133 virtVolCellIds = virtVolCellIdsTmp;
1135 for (
auto itr = virtVolCellIds.begin(); itr != virtVolCellIds.end();
1137 if (*itr != currId) {
1142 if (accum > accumMax) {
1147 if (vol && numSharedInCell >= 3) {
1149 this->
sentCells[me][you].insert(localCellId);
1156 }
else if (!vol && numSharedInCell >= 2 &&
1157 notSharedWithVolSurfNodes.empty() && accumMax == 3) {
1173 vtkSmartPointer<vtkEdgeTable> eTab = createPartitionEdgeTable(you);
1175 std::cerr <<
"Problem in building partition edge table." << std::endl;
1178 std::vector<int> rmvLst;
1179 for (
auto icId =
sentCells[me][you].begin();
1180 icId !=
sentCells[me][you].end(); icId++) {
1183 std::map<nemId_t, std::vector<double>> cellPntIdCrd =
1188 for (
auto iid1 = cellPntIdCrd.begin(); iid1 != cellPntIdCrd.end();
1190 for (
auto iid2 = std::next(iid1, 1); iid2 != cellPntIdCrd.end();
1200 if (nShrEdg < 3) rmvLst.push_back(*icId);
1204 for (
auto icId = rmvLst.begin(); icId != rmvLst.end(); icId++) {
1214 bool inRmvCell, inSentCell;
1215 std::vector<int> rmvNodeLst;
1216 for (
auto inId =
sentNodes[me][you].begin();
1217 inId !=
sentNodes[me][you].end(); inId++) {
1220 for (
auto icId = rmvLst.begin(); icId != rmvLst.end(); icId++) {
1221 vtkSmartPointer<vtkIdList> cellPtIds =
1223 cellPtIds =
partitions[me]->getDataSet()->GetCell(*icId)->GetPointIds();
1224 int numCellPts = cellPtIds->GetNumberOfIds();
1225 for (
int i = 0; i < numCellPts; ++i) {
1226 int ptId = cellPtIds->GetId(i);
1227 if (ptId == *inId) {
1232 for (
auto icId =
sentCells[me][you].begin();
1233 icId !=
sentCells[me][you].end(); icId++) {
1234 vtkSmartPointer<vtkIdList> cellPtIds =
1236 cellPtIds =
partitions[me]->getDataSet()->GetCell(*icId)->GetPointIds();
1237 int numCellPts = cellPtIds->GetNumberOfIds();
1238 for (
int i = 0; i < numCellPts; ++i) {
1239 int ptId = cellPtIds->GetId(i);
1240 if (ptId == *inId) {
1245 if (inRmvCell && !inSentCell) {
1246 rmvNodeLst.push_back(*inId);
1251 for (
auto inId = rmvNodeLst.begin(); inId != rmvNodeLst.end(); inId++) {
1260 vtkSmartPointer<vtkEdgeTable> RocPartCommGenRunner::createPartitionEdgeTable(
1263 std::cerr <<
"Wrong partition number, there are " <<
partitions.size()
1264 <<
" partitions exisiting." << std::endl;
1270 eTab->InitEdgeInsertion(
partitions[iPart]->getNumberOfPoints());
1278 std::map<nemId_t, std::vector<double>> cellPntIdCrd =
1282 for (
auto iid1 = cellPntIdCrd.begin(); iid1 != cellPntIdCrd.end(); iid1++)
1283 for (
auto iid2 = std::next(iid1, 1); iid2 != cellPntIdCrd.end(); iid2++)
1284 eTab->InsertEdge(iid1->first, iid2->first);
1289 void RocPartCommGenRunner::getSharedPatchInformation() {
1291 std::map<int, std::map<int, std::map<int, int>>> patchProcGlobToPartNodeMaps;
1292 std::map<int, std::map<int, std::map<int, int>>> patchProcPartToGlobNodeMaps;
1293 std::map<int, std::map<int, std::vector<int>>> patchProcGlobNodeIdsMaps;
1299 vtkSmartPointer<vtkDataArray> vtkGlobPatchNodeIds =
1300 it->second->getDataSet()->GetPointData()->GetArray(
"GlobalNodeIds");
1301 std::map<int, int> patchGlobToPartNodeMap;
1302 std::map<int, int> patchPartToGlobNodeMap;
1303 for (
int j = 0; j < vtkGlobPatchNodeIds->GetNumberOfTuples(); ++j) {
1304 int globNodeId =
static_cast<int>(vtkGlobPatchNodeIds->GetTuple1(j));
1305 patchGlobToPartNodeMap[globNodeId] = j;
1306 patchPartToGlobNodeMap[j] = globNodeId;
1308 patchProcGlobToPartNodeMaps[it->first][i] = patchGlobToPartNodeMap;
1309 patchProcPartToGlobNodeMaps[it->first][i] = patchPartToGlobNodeMap;
1310 patchProcGlobNodeIdsMaps[it->first][i] =
1318 if (!(patchProcGlobNodeIdsMaps[it->first].find(me) ==
1319 patchProcGlobNodeIdsMaps[it->first].end())) {
1323 if (!(patchProcGlobNodeIdsMaps[it1->first].find(you) ==
1324 patchProcGlobNodeIdsMaps[it1->first].end())) {
1325 if (!(you == me && it->first == it1->first)) {
1326 std::vector<int> tmpVec;
1327 std::set_intersection(
1328 patchProcGlobNodeIdsMaps[it->first][me].begin(),
1329 patchProcGlobNodeIdsMaps[it->first][me].end(),
1330 patchProcGlobNodeIdsMaps[it1->first][you].begin(),
1331 patchProcGlobNodeIdsMaps[it1->first][you].end(),
1332 std::back_inserter(tmpVec));
1333 if (tmpVec.size()) {
1338 for (
int i = 0; i < tmpVec.size(); ++i) {
1340 patchProcGlobToPartNodeMaps[it->first][me][tmpVec[i]];
1344 patchProcGlobToPartNodeMaps[it1->first][you][tmpVec[i]];
1360 vtkSmartPointer<vtkPolyData> RocPartCommGenRunner::deleteInterPartitionSurface(
1361 std::shared_ptr<meshBase> fullSurf,
1362 vtkSmartPointer<vtkDataSet> _partSurf)
const {
1363 vtkSmartPointer<vtkPolyData> partSurf = vtkPolyData::SafeDownCast(_partSurf);
1366 vtkSmartPointer<vtkStaticCellLocator> fullSurfCellLocator =
1367 fullSurf->buildStaticCellLocator();
1370 partSurf->BuildLinks();
1373 vtkSmartPointer<vtkGenericCell> genCell =
1375 vtkSmartPointer<vtkGenericCell> genCell1 =
1378 std::unordered_set<int> cellsToDelete;
1379 std::unordered_set<int> pointsToDelete;
1380 int numToDelete = 0;
1382 for (
int i = 0; i < partSurf->GetNumberOfCells(); ++i) {
1384 double center[3] = {0., 0., 0.};
1385 partSurf->GetCell(i, genCell);
1386 for (
int j = 0; j < genCell->GetNumberOfPoints(); ++j) {
1388 genCell->GetPoints()->GetPoint(j, point);
1389 for (
int k = 0; k < 3; ++k) center[k] += point[k] / 3.;
1393 double closestPoint[3];
1399 fullSurfCellLocator->FindClosestPoint(center, closestPoint, genCell,
id,
1402 cellsToDelete.insert(i);
1403 partSurf->GetCellPoints(i, cellPointIds);
1404 for (
int l = 0; l < cellPointIds->GetNumberOfIds(); ++l) {
1405 int pntId =
static_cast<int>(cellPointIds->GetId(l));
1406 pointsToDelete.insert(pntId);
1408 cellPointIds->Reset();
1412 std::unordered_set<int>::iterator it = pointsToDelete.begin();
1413 while (it != pointsToDelete.end()) {
1414 partSurf->DeletePoint(*it);
1417 it = cellsToDelete.begin();
1418 while (it != cellsToDelete.end()) {
1419 partSurf->DeleteCell(*it);
1422 partSurf->RemoveDeletedCells();
1425 vtkSmartPointer<vtkCleanPolyData> cleanPolyData =
1427 cleanPolyData->SetInputData(partSurf);
1428 cleanPolyData->Update();
1429 return cleanPolyData->GetOutput();
1432 void RocPartCommGenRunner::extractPatches() {
1436 std::map<int, std::vector<nemId_t>> patchPartitionCellMap;
1437 vtkSmartPointer<vtkDataArray> patchNumbers =
1440 for (
int j = 0; j < patchNumbers->GetNumberOfTuples(); ++j) {
1441 int patchNo =
static_cast<int>(patchNumbers->GetTuple1(j));
1442 patchPartitionCellMap[patchNo].push_back(j);
1444 auto it = patchPartitionCellMap.begin();
1445 while (it != patchPartitionCellMap.end()) {
1450 std::stringstream ss;
1451 ss <<
prefixPath +
"extractedPatch" << it->first <<
"OfProc" << i
1465 std::map<int, std::vector<nemId_t>> virtualPatchPartitionCellMap;
1466 vtkSmartPointer<vtkDataArray> virtualPatchNumbers =
1467 it->second->getDataSet()->GetCellData()->GetArray(
"patchNo");
1468 for (
int j = 0; j < virtualPatchNumbers->GetNumberOfTuples(); ++j) {
1469 int patchNo =
static_cast<int>(virtualPatchNumbers->GetTuple1(j));
1470 virtualPatchPartitionCellMap[patchNo].push_back(j);
1472 auto it1 = virtualPatchPartitionCellMap.begin();
1473 while (it1 != virtualPatchPartitionCellMap.end()) {
1479 std::stringstream ss;
1480 ss <<
prefixPath +
"extractedVirtualPatch" << it1->first <<
"Of" << i
1481 <<
"FromProc" << it->first <<
".vtu";
1493 RocPartCommGenRunner::~RocPartCommGenRunner() {
1494 std::cout <<
"RocPartCommGenRunner destroyed" << std::endl;
1497 void RocPartCommGenRunner::writeSurfCgns(
const std::string &prefix,
int me) {
1499 std::stringstream ss;
1501 << (me < 1000 ? (me < 100 ? (me < 10 ?
"_000" :
"_00") :
"_0") :
"_") << me
1503 std::string cgFname(ss.str());
1504 std::unique_ptr<cgnsWriter> writer =
1505 std::unique_ptr<cgnsWriter>(
new cgnsWriter(cgFname, prefix, 2, 3, 0));
1508 writer->setFluidUnitsMap();
1509 writer->setFluidDimMap();
1510 writer->setFluidMagMap();
1511 writer->setiFluidUnitsMap();
1512 writer->setiFluidDimMap();
1513 writer->setiFluidMagMap();
1514 writer->setBurnUnitsMap();
1515 writer->setBurnDimMap();
1516 writer->setBurnMagMap();
1522 writer->setUnits(CGNS_ENUMV(Kilogram), CGNS_ENUMV(Meter), CGNS_ENUMV(Second),
1523 CGNS_ENUMV(Kelvin), CGNS_ENUMV(Degree));
1526 writer->setBaseItrData(
"TimeIterValues", 1, std::stod(this->
trimmed_base_t));
1529 writer->writeGridToFile();
1530 std::string grdpntr(
"Grid");
1532 std::string flowsolpntr(
"NodeData");
1536 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
1538 std::string winName(
"WinData");
1540 writer->setIntData(winName, 1);
1541 writer->writeWinToFile();
1546 vtkSmartPointer<vtkPointLocator> pointLocator =
1549 for (vtkIdType i = 0; i <
procVolMesh[me]->getDataSet()->GetNumberOfPoints();
1551 myPoints->InsertNextPoint(
procVolMesh[me]->getDataSet()->GetPoint(i));
1552 vtkSmartPointer<vtkPolyData> myPointsData =
1554 myPointsData->SetPoints(myPoints);
1555 pointLocator->SetDataSet(myPointsData);
1556 pointLocator->AutomaticOn();
1557 pointLocator->BuildLocator();
1561 int patchesFound = 0;
1564 if (prefix == this->getPatchType(it->first) ||
1565 ((prefix ==
"burn" || prefix ==
"iburn_all") &&
1566 (this->getPatchType(it->first) ==
"ifluid_b"))) {
1568 int numVirtualCells = 0;
1571 writer->setZoneItrData(
"ZoneIterativeData", grdpntr, flowsolpntr);
1575 ss << ((me + 1) >= 10 ?
"" :
"0") << me + 1 << (it->first < 10 ?
"0" :
"")
1580 std::vector<std::shared_ptr<meshBase>>
1581 patchOfPartitionWithAllVirtualCells;
1584 std::vector<std::shared_ptr<meshBase>> patchOfPartition;
1587 patchOfPartitionWithAllVirtualCells.push_back(it->second);
1588 patchOfPartition.push_back(it->second);
1594 auto virtItr1 = virtItr->second.begin();
1595 while (virtItr1 != virtItr->second.end()) {
1597 if (it->first == virtItr1->first)
1598 if (virtItr1->second->getNumberOfCells()) {
1600 patchOfPartitionWithAllVirtualCells.push_back(virtItr1->second);
1601 numVirtualCells += virtItr1->second->getNumberOfCells();
1609 std::shared_ptr<meshBase> patchOfPartitionWithRealMesh =
1613 std::shared_ptr<meshBase> patchOfPartitionWithVirtualMesh =
1617 writer->setZone(ss.str(), CGNS_ENUMV(Unstructured));
1620 writer->setPconnGhostDescriptor(0);
1623 writer->setNVrtx(it->second->getNumberOfPoints());
1626 writer->setNCell(it->second->getNumberOfCells());
1629 std::vector<std::vector<double>> coords;
1631 coords = patchOfPartitionWithVirtualMesh->getVertCrds();
1633 std::vector<nemId_t> cgConnReal_nemId_t(it->second->getConnectivities());
1636 std::vector<cgsize_t> cgConnReal(cgConnReal_nemId_t.begin(),
1637 cgConnReal_nemId_t.end());
1638 for (
auto &tmpit : cgConnReal) tmpit += 1;
1641 std::vector<nemId_t> cgConnVirtual_nemId_t(
1642 patchOfPartitionWithVirtualMesh->getConnectivities());
1644 std::vector<cgsize_t> cgConnVirtual(cgConnVirtual_nemId_t.begin(),
1645 cgConnVirtual_nemId_t.end());
1647 cgConnVirtual.erase(cgConnVirtual.begin(),
1648 cgConnVirtual.begin() + cgConnReal.size());
1649 for (
auto &tmpit : cgConnVirtual) tmpit += 1;
1653 this->swapTriOrdering(cgConnReal);
1654 this->swapTriOrdering(cgConnVirtual);
1660 std::vector<int> cgConnRealGlobal1;
1661 std::vector<int> cgConnRealGlobal2;
1662 std::vector<int> cgConnRealGlobal3;
1663 std::vector<int> cgConnVirtualGlobal1;
1664 std::vector<int> cgConnVirtualGlobal2;
1665 std::vector<int> cgConnVirtualGlobal3;
1668 std::map<int, int> loc2Glob;
1669 std::map<int, int> glob2Loc;
1673 for (
auto itr = cgConnReal.begin(); itr != cgConnReal.end(); ++itr) {
1676 pntCoor[0] = coords[0][*itr - 1];
1677 pntCoor[1] = coords[1][*itr - 1];
1678 pntCoor[2] = coords[2][*itr - 1];
1679 foundId = pointLocator->FindClosestPoint(pntCoor);
1681 loc2Glob[*itr] = foundId + 1;
1682 glob2Loc[foundId + 1] = *itr;
1685 pntCoor[0] = coords[0][*itr - 1];
1686 pntCoor[1] = coords[1][*itr - 1];
1687 pntCoor[2] = coords[2][*itr - 1];
1688 foundId = pointLocator->FindClosestPoint(pntCoor);
1689 loc2Glob[*itr] = foundId + 1;
1690 glob2Loc[foundId + 1] = *itr;
1693 pntCoor[0] = coords[0][*itr - 1];
1694 pntCoor[1] = coords[1][*itr - 1];
1695 pntCoor[2] = coords[2][*itr - 1];
1696 foundId = pointLocator->FindClosestPoint(pntCoor);
1697 loc2Glob[*itr] = foundId + 1;
1698 glob2Loc[foundId + 1] = *itr;
1702 if (numVirtualCells) {
1703 for (
auto itr = cgConnVirtual.begin(); itr != cgConnVirtual.end();
1705 pntCoor[0] = coords[0][*itr - 1];
1706 pntCoor[1] = coords[1][*itr - 1];
1707 pntCoor[2] = coords[2][*itr - 1];
1708 foundId = pointLocator->FindClosestPoint(pntCoor);
1709 if (loc2Glob.find(*itr) == loc2Glob.end()) {
1710 loc2Glob[*itr] = foundId + 1;
1711 glob2Loc[foundId + 1] = *itr;
1715 pntCoor[0] = coords[0][*itr - 1];
1716 pntCoor[1] = coords[1][*itr - 1];
1717 pntCoor[2] = coords[2][*itr - 1];
1718 foundId = pointLocator->FindClosestPoint(pntCoor);
1719 if (loc2Glob.find(*itr) == loc2Glob.end()) {
1720 loc2Glob[*itr] = foundId + 1;
1721 glob2Loc[foundId + 1] = *itr;
1725 pntCoor[0] = coords[0][*itr - 1];
1726 pntCoor[1] = coords[1][*itr - 1];
1727 pntCoor[2] = coords[2][*itr - 1];
1728 foundId = pointLocator->FindClosestPoint(pntCoor);
1729 if (loc2Glob.find(*itr) == loc2Glob.end()) {
1730 loc2Glob[*itr] = foundId + 1;
1731 glob2Loc[foundId + 1] = *itr;
1737 std::vector<std::vector<double>> coordsTmp;
1738 std::vector<double> coordsXTmp;
1739 std::vector<double> coordsYTmp;
1740 std::vector<double> coordsZTmp;
1744 for (
auto itr = glob2Loc.begin(); itr != glob2Loc.end(); ++itr) {
1747 coordsXTmp.push_back(coords[0][lId - 1]);
1748 coordsYTmp.push_back(coords[1][lId - 1]);
1749 coordsZTmp.push_back(coords[2][lId - 1]);
1751 coordsTmp.push_back(coordsXTmp);
1752 coordsTmp.push_back(coordsYTmp);
1753 coordsTmp.push_back(coordsZTmp);
1759 std::vector<std::vector<double>> realCoords;
1760 std::vector<std::vector<double>> virtCoords;
1763 std::vector<double> realCoordsX(
1765 coords[0].begin() + it->second->getNumberOfPoints());
1766 std::vector<double> realCoordsY(
1768 coords[1].begin() + it->second->getNumberOfPoints());
1769 std::vector<double> realCoordsZ(
1771 coords[2].begin() + it->second->getNumberOfPoints());
1772 std::vector<double> virtCoordsX(
1773 coords[0].begin() + it->second->getNumberOfPoints(), coords[0].end());
1774 std::vector<double> virtCoordsY(
1775 coords[1].begin() + it->second->getNumberOfPoints(), coords[1].end());
1776 std::vector<double> virtCoordsZ(
1777 coords[2].begin() + it->second->getNumberOfPoints(), coords[2].end());
1778 realCoords.push_back(realCoordsX);
1779 realCoords.push_back(realCoordsY);
1780 realCoords.push_back(realCoordsZ);
1781 virtCoords.push_back(virtCoordsX);
1782 virtCoords.push_back(virtCoordsY);
1783 virtCoords.push_back(virtCoordsZ);
1786 std::vector<std::vector<double>> realVirtCoordsTmp;
1787 std::vector<double> realCoordsTmpX;
1788 std::vector<double> realCoordsTmpY;
1789 std::vector<double> realCoordsTmpZ;
1790 std::vector<double> virtCoordsTmpX;
1791 std::vector<double> virtCoordsTmpY;
1792 std::vector<double> virtCoordsTmpZ;
1795 for (
int i = 0; i < coordsTmp[0].size(); i++) {
1796 for (
int j = 0; j < realCoords[0].size(); j++) {
1797 if (coordsTmp[0][i] == realCoords[0][j] &&
1798 coordsTmp[1][i] == realCoords[1][j] &&
1799 coordsTmp[2][i] == realCoords[2][j]) {
1800 realCoordsTmpX.push_back(coordsTmp[0][i]);
1801 realCoordsTmpY.push_back(coordsTmp[1][i]);
1802 realCoordsTmpZ.push_back(coordsTmp[2][i]);
1805 for (
int j = 0; j < virtCoords[0].size(); j++) {
1806 if (coordsTmp[0][i] == virtCoords[0][j] &&
1807 coordsTmp[1][i] == virtCoords[1][j] &&
1808 coordsTmp[2][i] == virtCoords[2][j]) {
1809 virtCoordsTmpX.push_back(coordsTmp[0][i]);
1810 virtCoordsTmpY.push_back(coordsTmp[1][i]);
1811 virtCoordsTmpZ.push_back(coordsTmp[2][i]);
1817 realCoordsTmpX.insert(realCoordsTmpX.end(), virtCoordsTmpX.begin(),
1818 virtCoordsTmpX.end());
1819 realVirtCoordsTmp.push_back(realCoordsTmpX);
1820 realCoordsTmpY.insert(realCoordsTmpY.end(), virtCoordsTmpY.begin(),
1821 virtCoordsTmpY.end());
1822 realVirtCoordsTmp.push_back(realCoordsTmpY);
1823 realCoordsTmpZ.insert(realCoordsTmpZ.end(), virtCoordsTmpZ.begin(),
1824 virtCoordsTmpZ.end());
1825 realVirtCoordsTmp.push_back(realCoordsTmpZ);
1829 std::map<int, int> loc2GlobReal;
1830 std::map<int, int> glob2LocReal;
1831 std::map<int, int> loc2GlobVirt;
1832 std::map<int, int> glob2LocVirt;
1833 for (
int i = 0; i < coords[0].size(); i++) {
1834 for (
int j = 0; j < realVirtCoordsTmp[0].size(); j++) {
1835 if (coords[0][i] == realVirtCoordsTmp[0][j] &&
1836 coords[1][i] == realVirtCoordsTmp[1][j] &&
1837 coords[2][i] == realVirtCoordsTmp[2][j]) {
1838 if (j < it->second->getNumberOfPoints()) {
1839 glob2LocReal[loc2Glob[i + 1]] = j + 1;
1840 loc2GlobReal[j + 1] = loc2Glob[i + 1];
1842 glob2LocVirt[loc2Glob[i + 1]] = j + 1;
1843 loc2GlobVirt[j + 1 - it->second->getNumberOfPoints()] =
1851 coords = realVirtCoordsTmp;
1855 for (
auto itr = cgConnReal.begin(); itr != cgConnReal.end(); ++itr) {
1856 cgConnRealGlobal1.push_back(
1857 loc2GlobReal[*itr]);
1859 cgConnRealGlobal2.push_back(loc2GlobReal[*itr]);
1861 cgConnRealGlobal3.push_back(loc2GlobReal[*itr]);
1865 if (numVirtualCells) {
1866 for (
auto itr = cgConnVirtual.begin(); itr != cgConnVirtual.end();
1868 cgConnVirtualGlobal1.push_back(loc2GlobVirt[*itr]);
1870 cgConnVirtualGlobal2.push_back(loc2GlobVirt[*itr]);
1872 cgConnVirtualGlobal3.push_back(loc2GlobVirt[*itr]);
1875 cgConnVirtualGlobal1.push_back(0);
1876 cgConnVirtualGlobal2.push_back(0);
1877 cgConnVirtualGlobal3.push_back(0);
1885 std::map<int, int> old2New;
1886 std::map<int, int> new2Old;
1889 std::vector<cgsize_t> cgConnRealTmp;
1890 std::vector<int> cgConnRealGlobal1Tmp;
1891 std::vector<int> cgConnRealGlobal2Tmp;
1892 std::vector<int> cgConnRealGlobal3Tmp;
1897 for (
auto itr = cgConnReal.begin(); itr != cgConnReal.end(); ++itr) {
1899 newLid = std::distance(glob2LocReal.begin(),
1900 glob2LocReal.find(loc2Glob[*itr])) +
1902 old2New[oldLid] = newLid;
1903 new2Old[newLid] = oldLid;
1904 cgConnRealTmp.push_back(newLid);
1905 cgConnRealGlobal1Tmp.push_back(loc2Glob[oldLid]);
1909 newLid = std::distance(glob2LocReal.begin(),
1910 glob2LocReal.find(loc2Glob[*itr])) +
1912 old2New[oldLid] = newLid;
1913 new2Old[newLid] = oldLid;
1914 cgConnRealTmp.push_back(newLid);
1915 cgConnRealGlobal2Tmp.push_back(loc2Glob[oldLid]);
1919 newLid = std::distance(glob2LocReal.begin(),
1920 glob2LocReal.find(loc2Glob[*itr])) +
1922 old2New[oldLid] = newLid;
1923 new2Old[newLid] = oldLid;
1924 cgConnRealTmp.push_back(newLid);
1925 cgConnRealGlobal3Tmp.push_back(loc2Glob[oldLid]);
1929 std::vector<cgsize_t> cgConnVirtualTmp;
1930 std::vector<int> cgConnVirtualGlobal1Tmp;
1931 std::vector<int> cgConnVirtualGlobal2Tmp;
1932 std::vector<int> cgConnVirtualGlobal3Tmp;
1936 if (numVirtualCells) {
1938 for (
auto itr = cgConnVirtual.begin(); itr != cgConnVirtual.end();
1941 if (glob2LocVirt.find(loc2Glob[*itr]) != glob2LocVirt.end()) {
1942 newLid = std::distance(glob2LocVirt.begin(),
1943 glob2LocVirt.find(loc2Glob[*itr])) +
1944 1 + it->second->getNumberOfPoints();
1946 newLid = std::distance(glob2LocReal.begin(),
1947 glob2LocReal.find(loc2Glob[*itr])) +
1950 old2New[oldLid] = newLid;
1951 new2Old[newLid] = oldLid;
1952 cgConnVirtualTmp.push_back(newLid);
1953 cgConnVirtualGlobal1Tmp.push_back(loc2Glob[oldLid]);
1957 if (glob2LocVirt.find(loc2Glob[*itr]) != glob2LocVirt.end()) {
1958 newLid = std::distance(glob2LocVirt.begin(),
1959 glob2LocVirt.find(loc2Glob[*itr])) +
1960 1 + it->second->getNumberOfPoints();
1962 newLid = std::distance(glob2LocReal.begin(),
1963 glob2LocReal.find(loc2Glob[*itr])) +
1966 old2New[oldLid] = newLid;
1967 new2Old[newLid] = oldLid;
1968 cgConnVirtualTmp.push_back(newLid);
1969 cgConnVirtualGlobal2Tmp.push_back(loc2Glob[oldLid]);
1973 if (glob2LocVirt.find(loc2Glob[*itr]) != glob2LocVirt.end()) {
1974 newLid = std::distance(glob2LocVirt.begin(),
1975 glob2LocVirt.find(loc2Glob[*itr])) +
1976 1 + it->second->getNumberOfPoints();
1978 newLid = std::distance(glob2LocReal.begin(),
1979 glob2LocReal.find(loc2Glob[*itr])) +
1982 old2New[oldLid] = newLid;
1983 new2Old[newLid] = oldLid;
1984 cgConnVirtualTmp.push_back(newLid);
1985 cgConnVirtualGlobal3Tmp.push_back(loc2Glob[oldLid]);
1990 cgConnReal = cgConnRealTmp;
1993 cgConnRealGlobal1 = cgConnRealGlobal1Tmp;
1994 cgConnRealGlobal2 = cgConnRealGlobal2Tmp;
1995 cgConnRealGlobal3 = cgConnRealGlobal3Tmp;
1998 if (numVirtualCells) {
1999 cgConnVirtual = cgConnVirtualTmp;
2000 cgConnVirtualGlobal1 = cgConnVirtualGlobal1Tmp;
2001 cgConnVirtualGlobal2 = cgConnVirtualGlobal2Tmp;
2002 cgConnVirtualGlobal3 = cgConnVirtualGlobal3Tmp;
2005 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2007 writer->setCoordRind(
2008 patchOfPartitionWithVirtualMesh->getNumberOfPoints() -
2009 it->second->getNumberOfPoints());
2012 writer->setNVrtx(it->second->getNumberOfPoints());
2015 writer->setGridXYZ(coords[0], coords[1], coords[2]);
2017 coords[0].resize(it->second->getNumberOfPoints());
2018 coords[1].resize(it->second->getNumberOfPoints());
2019 coords[2].resize(it->second->getNumberOfPoints());
2022 writer->setGridXYZ(coords[0], coords[1], coords[2]);
2025 writer->setNVrtx(it->second->getNumberOfPoints());
2028 writer->setSection(
":t3:real", CGNS_ENUMV(TRI_3), cgConnReal);
2031 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2034 vtkSmartPointer<vtkDataArray> patchNos =
2035 patchOfPartitionWithRealMesh->getDataSet()->GetCellData()->GetArray(
2038 patchNos->GetTuple(0, patchNo);
2041 this->dimSurfWriter(me + 1, cgConnReal, cgConnVirtual,
2042 static_cast<int>(patchNo[0]));
2044 vtkSmartPointer<vtkDataArray> bcflags =
2045 patchOfPartitionWithRealMesh->getDataSet()->GetCellData()->GetArray(
2048 bcflags->GetTuple(0, bcflag);
2050 vtkSmartPointer<vtkDataArray> cnstr_types =
2051 patchOfPartitionWithRealMesh->getDataSet()->GetCellData()->GetArray(
2053 double cnstr_type[1];
2054 cnstr_types->GetTuple(0, cnstr_type);
2056 if (numVirtualCells) {
2057 writer->setNCell(numVirtualCells);
2058 writer->setSection(
":t3:virtual", CGNS_ENUMV(TRI_3), cgConnVirtual);
2059 writer->setVirtElmRind(numVirtualCells);
2061 writer->setVirtElmRind(0);
2066 this->restructurePconn(this->
surfPconns[me][it->first], me, 1, old2New,
2068 writer->setPconnVec(this->
surfPconns[me][it->first]);
2072 writer->setGlobalSection(
"t3g:real#1of3", CGNS_ENUMV(TRI_3),
2074 writer->setGlobalNCell(cgConnRealGlobal1.size());
2075 writer->setGlobalSection(
"t3g:real#2of3", CGNS_ENUMV(TRI_3),
2077 writer->setGlobalNCell(cgConnRealGlobal2.size());
2078 writer->setGlobalSection(
"t3g:real#3of3", CGNS_ENUMV(TRI_3),
2080 writer->setGlobalNCell(cgConnRealGlobal3.size());
2081 writer->setGlobalSection(
"t3g:virtual#1of3", CGNS_ENUMV(TRI_3),
2082 cgConnVirtualGlobal1);
2083 writer->setGlobalNCell(cgConnVirtualGlobal1.size());
2084 writer->setGlobalSection(
"t3g:virtual#2of3", CGNS_ENUMV(TRI_3),
2085 cgConnVirtualGlobal2);
2086 writer->setGlobalNCell(cgConnVirtualGlobal2.size());
2087 writer->setGlobalSection(
"t3g:virtual#3of3", CGNS_ENUMV(TRI_3),
2088 cgConnVirtualGlobal3);
2089 writer->setGlobalNCell(cgConnVirtualGlobal3.size());
2092 writer->setGlobalSection(
"q4g:real#1of4", CGNS_ENUMV(TETRA_4));
2093 writer->setGlobalNCell(0);
2094 writer->setGlobalSection(
"q4g:real#2of4", CGNS_ENUMV(TETRA_4));
2095 writer->setGlobalNCell(0);
2096 writer->setGlobalSection(
"q4g:real#3of4", CGNS_ENUMV(TETRA_4));
2097 writer->setGlobalNCell(0);
2098 writer->setGlobalSection(
"q4g:real#4of4", CGNS_ENUMV(TETRA_4));
2099 writer->setGlobalNCell(0);
2100 writer->setGlobalSection(
"q4g:virtual#1of4", CGNS_ENUMV(TETRA_4));
2101 writer->setGlobalNCell(0);
2102 writer->setGlobalSection(
"q4g:virtual#2of4", CGNS_ENUMV(TETRA_4));
2103 writer->setGlobalNCell(0);
2104 writer->setGlobalSection(
"q4g:virtual#3of4", CGNS_ENUMV(TETRA_4));
2105 writer->setGlobalNCell(0);
2106 writer->setGlobalSection(
"q4g:virtual#4of4", CGNS_ENUMV(TETRA_4));
2107 writer->setGlobalNCell(0);
2109 writer->setPatchNo((
int)patchNo[0]);
2110 writer->setBcflag((
int)bcflag[0]);
2111 writer->setCnstrtype((
int)cnstr_type[0]);
2113 writer->setNCell(1);
2114 writer->setSection(
"Empty:t3:virtual", CGNS_ENUMV(TRI_3),
2116 writer->setVirtElmRind(numVirtualCells);
2120 if (!(prefix ==
"burn" || prefix ==
"iburn_all"))
2122 patchOfPartitionWithVirtualMesh->getDataSet()->GetNumberOfCells();
2125 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2127 writer->setTypeFlag(1);
2128 writer->writeZoneToFile();
2131 writer->setTypeFlag(2);
2132 writer->writeZoneToFile();
2143 std::shared_ptr<TransferBase> transfer;
2147 "Consistent Interpolation");
2151 patchOfPartitionWithRealMesh.get()->write(
2152 prefixPath +
"_" + std::to_string(me) +
"_real_patch_" +
2153 std::to_string(it->first) +
".vtu");
2162 this->
surfWithSol.get(), patchOfPartitionWithVirtualMesh.get(),
2163 "Consistent Interpolation");
2164 transfer->run(this->
surfWithSol->getNewArrayNames());
2167 patchOfPartitionWithVirtualMesh.get()->write(
2168 prefixPath +
"_" + std::to_string(me) +
"_virtual_patch_" +
2169 std::to_string(it->first) +
".vtu");
2171 int numPointDataArr = this->
surfWithSol->getDataSet()
2173 ->GetNumberOfArrays();
2176 if (numPointDataArr) {
2177 std::string nodeName(
"NodeData");
2179 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2180 writer->setTypeFlag(1);
2181 writer->writeSolutionNode(nodeName, CGNS_ENUMV(Vertex), 0, 1);
2182 for (
int i = 0; i < numPointDataArr; ++i) {
2183 std::vector<double> pointData;
2184 std::string dataName(
2185 this->
surfWithSol->getDataSet()->GetPointData()->GetArrayName(
2187 patchOfPartitionWithVirtualMesh->getPointDataArray(dataName,
2189 writer->setTypeFlag(1);
2192 this->mapOld2NewPointData(pointData, new2Old);
2194 writer->writeSolutionField(
2195 dataName, nodeName, CGNS_ENUMV(RealDouble), &pointData[0u]);
2198 writer->setTypeFlag(1);
2199 writer->writeSolutionNode(nodeName, CGNS_ENUMV(Vertex), 1, 1);
2205 if (prefix ==
"burn" || prefix ==
"iburn_all")
2208 ->GetNumberOfArrays();
2212 ->GetNumberOfArrays();
2215 if (numCellDataArr) {
2216 if (prefix !=
"burn") {
2217 std::string nodeName(
"ElemData");
2219 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2220 writer->setTypeFlag(1);
2221 writer->writeSolutionNode(nodeName, CGNS_ENUMV(CellCenter), 0, 1);
2222 }
else if (prefix ==
"iburn_all") {
2223 writer->setTypeFlag(2);
2224 writer->writeSolutionNode(nodeName, CGNS_ENUMV(CellCenter), 0, 0);
2227 for (
int i = 0; i < numCellDataArr; ++i) {
2228 std::vector<double> cellData;
2229 std::string dataName;
2230 if (!(prefix ==
"burn" || prefix ==
"iburn_all")) {
2234 patchOfPartitionWithVirtualMesh->getCellDataArray(dataName,
2236 }
else if (prefix ==
"iburn_all") {
2240 patchOfPartitionWithRealMesh->getCellDataArray(dataName,
2244 if (dataName !=
"bcflag" && dataName !=
"patchNo" &&
2245 dataName !=
"cnstr_type") {
2247 if (dataName ==
"gs")
2248 for (
double &itr : cellData) itr = 0;
2251 if (dataName ==
"centersX" || dataName ==
"centersY" ||
2252 dataName ==
"centersZ") {
2254 if (dataName ==
"centersX")
2256 else if (dataName ==
"centersY")
2258 else if (dataName ==
"centersZ")
2262 int nCells = cgConnReal.size() / 3;
2263 for (
int i = 0; i < nCells; i++)
2264 cellData.push_back((coords[ind][cgConnReal[3 * i]] +
2265 coords[ind][cgConnReal[3 * i + 1]] +
2266 coords[ind][cgConnReal[3 * i + 2]]) /
2271 if (prefix ==
"ifluid_ni" || prefix ==
"ifluid_b" ||
2272 prefix ==
"ifluid_nb") {
2273 writer->setTypeFlag(1);
2274 if (dataName ==
"bflag") {
2275 std::vector<int> bflag(cellData.begin(), cellData.end());
2276 writer->writeSolutionField(dataName, nodeName,
2277 CGNS_ENUMV(Integer), &bflag[0u]);
2280 writer->writeSolutionField(dataName, nodeName,
2281 CGNS_ENUMV(RealDouble),
2284 }
else if (prefix ==
"burn" || prefix ==
"iburn_all") {
2285 writer->setTypeFlag(2);
2286 if (dataName ==
"bflag") {
2287 std::vector<int> cellDataInt(cellData.begin(),
2291 writer->writeSolutionField(dataName, nodeName,
2292 CGNS_ENUMV(Integer),
2296 writer->writeSolutionField(dataName, nodeName,
2297 CGNS_ENUMV(RealDouble),
2308 writer->resetSections();
2309 writer->resetGlobalSections();
2313 if (patchesFound == 0) {
2314 writer->deleteFile();
2318 void RocPartCommGenRunner::writeVolCgns(
const std::string &prefix,
int proc,
2320 std::stringstream ss;
2322 << (proc < 1000 ? (proc < 100 ? (proc < 10 ?
"_000" :
"_00") :
"_0") :
"_")
2324 std::string cgFname(ss.str());
2325 std::unique_ptr<cgnsWriter> writer =
2326 std::unique_ptr<cgnsWriter>(
new cgnsWriter(cgFname,
"fluid", 3, 3, 0));
2329 writer->setFluidUnitsMap();
2330 writer->setFluidDimMap();
2331 writer->setFluidMagMap();
2332 writer->setiFluidUnitsMap();
2333 writer->setiFluidDimMap();
2334 writer->setiFluidMagMap();
2335 writer->setBurnUnitsMap();
2336 writer->setBurnDimMap();
2337 writer->setBurnMagMap();
2343 writer->setUnits(CGNS_ENUMV(Kilogram), CGNS_ENUMV(Meter), CGNS_ENUMV(Second),
2344 CGNS_ENUMV(Kelvin), CGNS_ENUMV(Degree));
2347 writer->setBaseItrData(
"TimeIterValues", 1, std::stod(this->
trimmed_base_t));
2350 std::string gridpntr(
"Grid");
2352 std::string flowsolpntr(
"NodeData");
2354 writer->setZoneItrData(
"ZoneIterativeData", gridpntr, flowsolpntr);
2357 ss << ((proc + 1) >= 10 ?
"" :
"0") << proc + 1 << (type < 10 ?
"0" :
"")
2362 std::vector<std::shared_ptr<meshBase>> partitionWithAllVirtualCells;
2363 partitionWithAllVirtualCells.push_back(this->
partitions[proc]);
2367 int numVirtualCells = 0;
2370 partitionWithAllVirtualCells.push_back(virtItr->second);
2371 numVirtualCells += virtItr->second->getNumberOfCells();
2376 std::shared_ptr<meshBase> partitionWithVirtualMesh =
2380 std::vector<std::vector<double>> coords(
2381 partitionWithVirtualMesh->getVertCrds());
2384 this->
procVolMesh.push_back(partitionWithVirtualMesh);
2387 writer->setZone(ss.str(), CGNS_ENUMV(Unstructured));
2390 writer->setNVrtx(
partitions[proc]->getNumberOfPoints());
2393 writer->setNCell(
partitions[proc]->getNumberOfCells());
2396 writer->setGridXYZ(coords[0], coords[1], coords[2]);
2399 writer->setCoordRind(partitionWithVirtualMesh->getNumberOfPoints() -
2403 std::vector<nemId_t> cgConnReal_nemId_t(
2406 std::vector<cgsize_t> cgConnReal(cgConnReal_nemId_t.begin(),
2407 cgConnReal_nemId_t.end());
2408 for (
auto &it : cgConnReal) it += 1;
2411 std::vector<nemId_t> cgConnVirtual_nemId_t(
2412 partitionWithVirtualMesh->getConnectivities());
2414 std::vector<cgsize_t> cgConnVirtual(cgConnVirtual_nemId_t.begin(),
2415 cgConnVirtual_nemId_t.end());
2417 cgConnVirtual.erase(cgConnVirtual.begin(),
2418 cgConnVirtual.begin() + cgConnReal.size());
2419 for (
auto &it : cgConnVirtual) it += 1;
2421 writer->setSection(
":T4:real", CGNS_ENUMV(TETRA_4), cgConnReal);
2422 writer->setNCell(numVirtualCells);
2423 writer->setSection(
":T4:virtual", CGNS_ENUMV(TETRA_4), cgConnVirtual);
2424 writer->setVirtElmRind(numVirtualCells);
2428 std::map<int, int> tmp{};
2429 this->restructurePconn(
volPconns[proc], proc, 0, tmp, nGhost);
2432 int ghostDescriptor = nGhost;
2435 writer->setPconnGhostDescriptor(ghostDescriptor);
2438 writer->setPconnVec(this->
volPconns[proc]);
2441 writer->setNCell(numVirtualCells);
2444 this->dimWriter(proc + 1, this->
partitions[proc], partitionWithVirtualMesh);
2445 this->clearBorderVector();
2446 this->cmpWriter(proc + 1,
2447 partitionWithVirtualMesh->getDataSet()->GetNumberOfCells());
2450 std::vector<std::vector<int>> allFaces;
2451 std::vector<int> idList;
2453 iCell < partitionWithVirtualMesh->getDataSet()->GetNumberOfCells();
2455 auto myCell = partitionWithVirtualMesh->getDataSet()->GetCell(iCell);
2456 for (
int iFace = 0; iFace < myCell->GetNumberOfFaces(); iFace++) {
2457 auto myFace = myCell->GetFace(iFace);
2459 auto ptIds = myFace->GetPointIds();
2460 for (
int iPt = 0; iPt < myFace->GetNumberOfPoints(); iPt++)
2461 idList.push_back(ptIds->GetId(iPt));
2462 std::sort(idList.begin(), idList.end());
2463 allFaces.push_back(idList);
2466 std::sort(allFaces.begin(), allFaces.end());
2467 allFaces.erase(std::unique(allFaces.begin(), allFaces.end()), allFaces.end());
2474 writer->writeGridToFile();
2475 writer->setTypeFlag(0);
2476 writer->writeZoneToFile();
2488 this->
volWithSol.get(), partitionWithVirtualMesh.get(),
2489 "Consistent Interpolation");
2490 transfer->run(this->
volWithSol->getNewArrayNames());
2494 partitionWithVirtualMesh.get()->write(
prefixPath +
"_vol_part_" +
2495 std::to_string(proc) +
".vtu");
2497 int numPointDataArr =
2498 this->
volWithSol->getDataSet()->GetPointData()->GetNumberOfArrays();
2499 if (numPointDataArr) {
2500 std::string nodeName(
"NodeData");
2502 writer->setTypeFlag(1);
2503 writer->writeSolutionNode(nodeName, CGNS_ENUMV(Vertex), 0, 1);
2506 for (
int i = 0; i < numPointDataArr; ++i) {
2507 std::vector<double> pointData;
2508 partitionWithVirtualMesh->getPointDataArray(i, pointData);
2509 std::string dataName(
2510 this->
volWithSol->getDataSet()->GetPointData()->GetArrayName(i));
2511 writer->setTypeFlag(0);
2512 writer->writeSolutionField(dataName, nodeName, CGNS_ENUMV(RealDouble),
2516 int numCellDataArr =
2517 this->
volWithSol->getDataSet()->GetCellData()->GetNumberOfArrays();
2518 if (numCellDataArr) {
2519 std::string nodeName(
"ElemData");
2521 writer->setTypeFlag(1);
2522 writer->writeSolutionNode(nodeName, CGNS_ENUMV(CellCenter), 0, 1);
2525 for (
int i = 0; i < numCellDataArr; ++i) {
2526 std::vector<double> cellData;
2527 partitionWithVirtualMesh->getCellDataArray(i, cellData);
2528 std::string dataName(
2529 this->
volWithSol->getDataSet()->GetCellData()->GetArrayName(i));
2530 writer->setTypeFlag(0);
2531 writer->writeSolutionField(dataName, nodeName, CGNS_ENUMV(RealDouble),
2538 void RocPartCommGenRunner::writeVolCellFaces(
const std::string &prefix,
2539 int proc,
int type)
const {
2540 std::stringstream ss;
2542 << (proc < 1000 ? (proc < 100 ? (proc < 10 ?
"_000" :
"_00") :
"_0") :
"_")
2544 std::string cgFname(ss.str());
2545 std::unique_ptr<cgnsWriter> writer =
2546 std::unique_ptr<cgnsWriter>(
new cgnsWriter(cgFname,
"fluid", 3, 3, 1));
2549 writer->setFluidDimMap();
2550 writer->setFluidUnitsMap();
2551 writer->setFluidMagMap();
2557 writer->setBaseItrData(
"TimeIterValues", 1, std::stod(this->
trimmed_base_t));
2562 writer->writeVolCellFacesNumber();
2565 void RocPartCommGenRunner::mapOld2NewPointData(
2566 std::vector<double> &nodeData,
const std::map<int, int> &new2Old)
const {
2567 std::vector<double> nodeDataTmp;
2568 for (
auto itr = new2Old.begin(); itr != new2Old.end(); ++itr) {
2569 nodeDataTmp.push_back(nodeData[itr->second - 1]);
2571 nodeData = nodeDataTmp;
2574 void RocPartCommGenRunner::restructurePconn(std::vector<int> &pConnVec,
2575 int proc,
int volOrSurf,
2576 const std::map<int, int> &old2New,
2580 std::map<int, std::vector<std::vector<int>>> zoneToBlocks;
2583 std::vector<int> idTmp;
2593 std::vector<int> foundZones;
2595 for (
auto itr = pConnVec.begin(); itr != pConnVec.end(); ++itr) {
2596 if (idCount != -1) {
2597 if (*itr > max && addflag) {
2600 }
else if (*itr < min && addflag) {
2604 if (!old2New.empty()) {
2605 idTmp.push_back(old2New.at(*itr));
2607 idTmp.push_back(*itr);
2611 if (zoneCount == 1) {
2613 auto it = find(foundZones.begin(), foundZones.end(), *itr);
2614 if (it != foundZones.end()) {
2618 foundZones.push_back(*itr);
2621 if (zoneCount == 2) {
2625 if (idCount == range) {
2628 zoneToBlocks[currZone].push_back(idTmp);
2635 if (volOrSurf == 0) {
2636 std::vector<int> volPconnsTmpProc;
2639 for (
int iBlock = 0; iBlock < 5; iBlock++) {
2640 volPconnsTmpProc.push_back(zoneToBlocks.size());
2652 for (
auto itr1 = zoneToBlocks.begin(); itr1 != zoneToBlocks.end();
2654 volPconnsTmpProc.push_back(itr1->first);
2667 if (itr1->second.size() > iBlock) {
2668 if (!(itr1->second)[iBlock].empty()) {
2669 volPconnsTmpProc.push_back((itr1->second)[iBlock].size());
2673 for (
auto itr2 = (itr1->second)[iBlock].begin();
2674 itr2 != (itr1->second)[iBlock].end(); ++itr2) {
2675 volPconnsTmpProc.push_back(*itr2);
2689 volPconnsTmpProc.push_back(0);
2695 volPconnsTmpProc.push_back(0);
2702 pConnVec = volPconnsTmpProc;
2704 std::vector<int> surfPconnsTmpProc;
2707 for (
int iBlock = 0; iBlock < 1; iBlock++) {
2708 surfPconnsTmpProc.push_back(zoneToBlocks.size());
2717 for (
auto itr1 = zoneToBlocks.begin(); itr1 != zoneToBlocks.end();
2719 surfPconnsTmpProc.push_back(itr1->first);
2728 if (itr1->second.size() > iBlock) {
2729 if (!(itr1->second)[iBlock].empty()) {
2730 surfPconnsTmpProc.push_back((itr1->second)[iBlock].size());
2731 for (
auto itr2 = (itr1->second)[iBlock].begin();
2732 itr2 != (itr1->second)[iBlock].end(); ++itr2) {
2733 surfPconnsTmpProc.push_back(*itr2);
2744 surfPconnsTmpProc.push_back(0);
2747 surfPconnsTmpProc.push_back(0);
2751 pConnVec = surfPconnsTmpProc;
2755 void RocPartCommGenRunner::clearPconnVectors() {
2763 void RocPartCommGenRunner::clearBorderVector() {
neighborProcsTmp.clear(); }
2767 void RocPartCommGenRunner::mapWriter()
const {
2773 std::ofstream mapFile;
2774 mapFile.open(fname);
2777 mapFile <<
"# ROCFLU region mapping file" 2781 mapFile <<
"# Number of regions" 2783 mapFile << std::setw(7) << std::to_string(nPart) <<
"\n";
2786 mapFile <<
"# Number of processes" 2788 mapFile << std::setw(7) << std::to_string(nPart) <<
"\n";
2791 for (
int iPart = 1; iPart < nPart + 1; iPart++) {
2792 std::string procStr = std::to_string(iPart);
2793 std::string procStrPadded =
2794 std::string(6 - procStr.length(),
'0') + procStr;
2795 mapFile <<
"# Process " << procStrPadded <<
"\n";
2797 mapFile << std::setw(7) << std::to_string(1) <<
"\n";
2798 mapFile << std::setw(7) << std::to_string(iPart) <<
"\n";
2801 mapFile <<
"# End" << std::endl;
2808 void RocPartCommGenRunner::cmpWriter(
int proc,
int nCells)
const {
2813 std::string procStr = std::to_string(proc);
2814 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
2815 std::string fname =
prefixPath + this->caseName +
".cmp_" + procStrPadded;
2816 std::ofstream cmpFile;
2817 cmpFile.open(fname);
2820 cmpFile <<
"# ROCFLU cell mapping file" 2822 cmpFile <<
"# Dimensions" 2824 cmpFile << std::setw(8) << std::to_string(nCells) << std::setw(8)
2825 << std::to_string(0) << std::setw(8) << std::to_string(0)
2826 << std::setw(8) << std::to_string(0) <<
"\n";
2827 cmpFile <<
"# Tetrahedra" 2830 std::string cellStr;
2831 for (
int iCell = 1; iCell < nCells + 1; iCell++) {
2832 cellStr = std::to_string(iCell);
2833 tmpStr += std::string(8 - cellStr.length(),
' ') + cellStr;
2834 if ((iCell) % 10 == 0) {
2835 cmpFile << tmpStr <<
"\n";
2839 if (!tmpStr.empty()) {
2840 cmpFile << tmpStr <<
"\n";
2843 cmpFile <<
"# End" << std::endl;
2849 void RocPartCommGenRunner::comWriter(
int proc)
const {
2855 std::vector<int> nBorders;
2857 memset(&nBorders[0], 0,
partitions.size() *
sizeof(int));
2858 for (
int i = 0; i <
partitions.size(); i++) {
2863 std::string procStr = std::to_string(proc);
2864 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
2865 std::string fname =
prefixPath + this->caseName +
".com_" + procStrPadded;
2866 std::ofstream comFile;
2867 comFile.open(fname);
2870 comFile <<
"# ROCFLU communication lists file" 2874 comFile <<
"# Dimensions" 2880 comFile <<
"# Information" 2883 std::string borderStr;
2887 procStr = std::to_string((*itr) + 1);
2888 borderStr = std::to_string(nBorders[*itr]);
2889 tmpStr += std::string(8 - procStr.length(),
' ') + procStr;
2890 tmpStr += std::string(8 - borderStr.length(),
' ') + borderStr;
2891 comFile << tmpStr <<
"\n";
2892 nBorders[*itr] += 1;
2896 comFile <<
"# Cells" 2899 std::string cellIdStr;
2900 std::string cellStr1;
2901 std::string cellStr2;
2906 cellStr1 = std::to_string(0);
2908 cellStr1 = std::to_string(this->
sentCellsTmp.at(*itr).size());
2911 cellStr2 = std::to_string(0);
2915 tmpStr += std::string(8 - cellStr1.length(),
' ') + cellStr1;
2916 tmpStr += std::string(8 - cellStr2.length(),
' ') + cellStr2;
2917 comFile << tmpStr <<
"\n";
2923 cellIdStr = std::to_string(*itr2);
2924 tmpStr += std::string(8 - cellIdStr.length(),
' ') + cellIdStr;
2925 if (((itr2 -
sentCellsTmp.at(*itr).begin()) + 1) % 10 == 0) {
2926 comFile << tmpStr <<
"\n";
2930 if (!tmpStr.empty()) {
2931 comFile << tmpStr <<
"\n";
2935 comFile << tmpStr <<
"\n";
2942 cellIdStr = std::to_string(*itr2);
2943 tmpStr += std::string(8 - cellIdStr.length(),
' ') + cellIdStr;
2947 comFile << tmpStr <<
"\n";
2951 if (!tmpStr.empty()) {
2952 comFile << tmpStr <<
"\n";
2956 comFile << tmpStr <<
"\n";
2962 comFile <<
"# Vertices" 2965 std::string vertIdStr;
2966 std::string vertStr1;
2967 std::string vertStr2;
2968 std::string vertStr3;
2973 vertStr1 = std::to_string(0);
2975 vertStr1 = std::to_string(this->
sentNodesTmp.at(*itr).size());
2979 vertStr2 = std::to_string(0);
2985 vertStr3 = std::to_string(0);
2990 tmpStr += std::string(8 - vertStr1.length(),
' ') + vertStr1;
2991 tmpStr += std::string(8 - vertStr2.length(),
' ') + vertStr2;
2992 tmpStr += std::string(8 - vertStr3.length(),
' ') + vertStr3;
2993 comFile << tmpStr <<
"\n";
2999 vertIdStr = std::to_string(*itr2);
3000 tmpStr += std::string(8 - vertIdStr.length(),
' ') + vertIdStr;
3001 if (((itr2 -
sentNodesTmp.at(*itr).begin()) + 1) % 10 == 0) {
3002 comFile << tmpStr <<
"\n";
3006 if (!tmpStr.empty()) {
3007 comFile << tmpStr <<
"\n";
3011 comFile << tmpStr <<
"\n";
3018 vertIdStr = std::to_string(*itr2);
3019 tmpStr += std::string(8 - vertIdStr.length(),
' ') + vertIdStr;
3021 comFile << tmpStr <<
"\n";
3025 if (!tmpStr.empty()) {
3026 comFile << tmpStr <<
"\n";
3030 comFile << tmpStr <<
"\n";
3037 vertIdStr = std::to_string(*itr2);
3038 tmpStr += std::string(8 - vertIdStr.length(),
' ') + vertIdStr;
3040 comFile << tmpStr <<
"\n";
3044 if (!tmpStr.empty()) {
3045 comFile << tmpStr <<
"\n";
3049 comFile << tmpStr <<
"\n";
3054 comFile <<
"# End" << std::endl;
3059 void RocPartCommGenRunner::dimWriter(
int proc, std::shared_ptr<meshBase> realMB,
3060 std::shared_ptr<meshBase> totalMB)
const {
3063 std::vector<double> nBorders;
3065 memset(&nBorders[0], 0,
partitions.size() *
sizeof(int));
3067 for (
int i = 0; i <
partitions.size(); i++) {
3072 std::string procStr = std::to_string(proc);
3073 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
3075 prefixPath + this->caseName +
".dim_" + procStrPadded +
"_0.00000E+00";
3076 std::ofstream dimFile;
3077 dimFile.open(fname);
3080 dimFile <<
"# ROCFLU dimensions file" 3084 dimFile <<
"# Vertices" 3086 dimFile << std::setw(8)
3087 << std::to_string(realMB->getDataSet()->GetNumberOfPoints());
3088 dimFile << std::setw(8)
3089 << std::to_string(totalMB->getDataSet()->GetNumberOfPoints());
3090 dimFile << std::setw(8)
3091 << std::to_string(totalMB->getDataSet()->GetNumberOfPoints() * 4)
3095 dimFile <<
"# Cells" 3097 dimFile << std::setw(8)
3098 << std::to_string(realMB->getDataSet()->GetNumberOfCells());
3099 dimFile << std::setw(8)
3100 << std::to_string(totalMB->getDataSet()->GetNumberOfCells());
3101 dimFile << std::setw(8)
3102 << std::to_string(totalMB->getDataSet()->GetNumberOfCells() * 4)
3106 dimFile <<
"# Tetrahedra" 3108 dimFile << std::setw(8)
3109 << std::to_string(realMB->getDataSet()->GetNumberOfCells());
3110 dimFile << std::setw(8)
3111 << std::to_string(totalMB->getDataSet()->GetNumberOfCells());
3112 dimFile << std::setw(8)
3113 << std::to_string(totalMB->getDataSet()->GetNumberOfCells() * 4)
3117 dimFile <<
"# Hexahedra" 3119 dimFile << std::setw(8) <<
"0";
3120 dimFile << std::setw(8) <<
"0";
3121 dimFile << std::setw(8) <<
"0" 3125 dimFile <<
"# Prisms" 3127 dimFile << std::setw(8) <<
"0";
3128 dimFile << std::setw(8) <<
"0";
3129 dimFile << std::setw(8) <<
"0" 3133 dimFile <<
"# Pyramids" 3135 dimFile << std::setw(8) <<
"0";
3136 dimFile << std::setw(8) <<
"0";
3137 dimFile << std::setw(8) <<
"0" 3141 dimFile <<
"# Patches (v2)" 3145 dimFile <<
"# Borders" 3148 dimFile << std::setw(8) <<
"0" 3157 std::string borderStr;
3158 std::string cellStr1;
3159 std::string cellStr2;
3160 std::string vertStr1;
3161 std::string vertStr2;
3162 std::string vertStr3;
3168 procStr = std::to_string((*itr) + 1);
3169 borderStr = std::to_string(nBorders[*itr]);
3170 tmpStr += std::string(8 - procStr.length(),
' ') + procStr;
3171 tmpStr += std::string(8 - borderStr.length(),
' ') + borderStr;
3172 nBorders[*itr] += 1;
3176 cellStr1 = std::to_string(0);
3178 cellStr1 = std::to_string(this->
sentCellsTmp.at(*itr).size());
3181 cellStr2 = std::to_string(0);
3185 tmpStr += std::string(8 - cellStr1.length(),
' ') + cellStr1;
3186 tmpStr += std::string(8 - cellStr2.length(),
' ') + cellStr2;
3190 vertStr1 = std::to_string(0);
3192 vertStr1 = std::to_string(this->
sentNodesTmp.at(*itr).size());
3195 vertStr2 = std::to_string(0);
3200 vertStr3 = std::to_string(0);
3204 tmpStr += std::string(8 - vertStr1.length(),
' ') + vertStr1;
3205 tmpStr += std::string(8 - vertStr2.length(),
' ') + vertStr2;
3206 tmpStr += std::string(8 - vertStr3.length(),
' ') + vertStr3;
3208 dimFile << tmpStr <<
"\n";
3213 dimFile <<
"# End" << std::endl;
3218 void RocPartCommGenRunner::dimSurfWriter(
3219 int proc,
const std::vector<cgsize_t> &cgConnReal,
3220 const std::vector<cgsize_t> &cgConnVirtual,
int patchNo) {
3222 std::string procStr = std::to_string(proc);
3223 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
3225 prefixPath + this->caseName +
".dim_" + procStrPadded +
"_0.00000E+00";
3228 std::vector<std::string> myLines;
3229 std::ifstream myfile(fname);
3232 while (std::getline(myfile, line)) myLines.push_back(line);
3235 std::set<int> patches;
3238 for (
auto itr2 = (*itr).begin(); itr2 != (*itr).end(); ++itr2)
3239 patches.insert(itr2->first);
3242 std::vector<std::string> newLines;
3243 std::string patchStr1;
3244 std::string patchStr2;
3245 std::string patchStr3;
3246 std::string patchStr4;
3248 for (
auto itr = myLines.begin(); itr != myLines.end(); ++itr) {
3249 if ((*itr).find(
"Borders") != std::string::npos) {
3250 if ((*(itr - 1)).find(
"Patches (v2)") != std::string::npos) {
3254 patchStr2 = std::to_string(*patches.rbegin());
3255 tmpStr += std::string(8 - patchStr1.length(),
' ') + patchStr1;
3256 tmpStr += std::string(8 - patchStr2.length(),
' ') + patchStr2;
3257 newLines.push_back(tmpStr);
3261 if (itr2->first == patchNo) {
3263 cgConnReal.size() + cgConnVirtual.size();
3265 patchStr1 = std::to_string(itr2->first);
3266 tmpStr += std::string(8 - patchStr1.length(),
' ') + patchStr1;
3267 patchStr2 = std::to_string(cgConnReal.size() / 3);
3268 tmpStr += std::string(8 - patchStr2.length(),
' ') + patchStr2;
3270 std::to_string((cgConnReal.size() + cgConnVirtual.size()) / 3);
3271 tmpStr += std::string(8 - patchStr3.length(),
' ') + patchStr3;
3272 patchStr4 = std::to_string(
3273 4 * (cgConnReal.size() + cgConnVirtual.size()) / 3);
3274 tmpStr += std::string(8 - patchStr4.length(),
' ') + patchStr4;
3275 tmpStr += std::string(8 - 1,
' ') +
'0';
3276 tmpStr += std::string(8 - 1,
' ') +
'0';
3277 tmpStr += std::string(8 - 1,
' ') +
'0';
3278 tmpStr += std::string(8 - 1,
' ') +
'0';
3279 newLines.push_back(tmpStr);
3283 newLines.push_back(*itr);
3287 std::ofstream dimFile;
3288 dimFile.open(fname);
3289 for (
auto itr = newLines.begin(); itr != newLines.end(); ++itr)
3290 dimFile << *itr <<
"\n";
3295 void RocPartCommGenRunner::dimSurfWriter(
int proc)
const {
3297 std::string procStr = std::to_string(proc);
3298 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
3300 prefixPath + this->caseName +
".dim_" + procStrPadded +
"_0.00000E+00";
3303 std::vector<std::string> myLines;
3304 std::ifstream myfile(fname);
3307 while (std::getline(myfile, line)) {
3308 myLines.push_back(line);
3312 std::set<int> patches;
3315 for (
auto itr2 = (*itr).begin(); itr2 != (*itr).end(); ++itr2) {
3316 patches.insert(itr2->first);
3321 std::vector<std::string> newLines;
3322 std::string patchStr1;
3323 std::string patchStr2;
3324 std::string patchStr3;
3325 std::string patchStr4;
3327 for (
auto itr = myLines.begin(); itr != myLines.end(); ++itr) {
3328 if ((*itr).find(
"Borders") != std::string::npos) {
3329 if ((*(itr - 1)).find(
"Patches (v2)") != std::string::npos) {
3331 patchStr1 = std::to_string(*patches.rbegin());
3332 tmpStr += std::string(8 - patchStr1.length(),
' ') + patchStr1;
3333 tmpStr += std::string(8 - patchStr1.length(),
' ') + patchStr1;
3334 newLines.push_back(tmpStr);
3336 for (
auto itr2 = patches.begin(); itr2 != patches.end(); ++itr2) {
3338 patchStr1 = std::to_string(*itr2);
3339 tmpStr += std::string(8 - patchStr1.length(),
' ') + patchStr1;
3341 tmpStr += std::string(8 - patchStr2.length(),
' ') + patchStr2;
3343 tmpStr += std::string(8 - patchStr3.length(),
' ') + patchStr3;
3345 tmpStr += std::string(8 - patchStr4.length(),
' ') + patchStr4;
3346 tmpStr += std::string(8 - 1,
' ') +
'0';
3347 tmpStr += std::string(8 - 1,
' ') +
'0';
3348 tmpStr += std::string(8 - 1,
' ') +
'0';
3349 tmpStr += std::string(8 - 1,
' ') +
'0';
3350 newLines.push_back(tmpStr);
3353 newLines.push_back(*itr);
3357 std::ofstream dimFile;
3358 dimFile.open(fname);
3359 for (
auto itr = newLines.begin(); itr != newLines.end(); ++itr) {
3360 dimFile << *itr <<
"\n";
3366 void RocPartCommGenRunner::txtWriter()
const {
3370 std::ofstream fluid_in;
3371 fluid_in.open(fname);
3373 fname =
prefixPath +
"ifluid_in_" + this->base_t +
".txt";
3374 std::ofstream ifluid_in;
3375 ifluid_in.open(fname);
3377 fname =
prefixPath +
"burn_in_" + this->base_t +
".txt";
3378 std::ofstream burn_in;
3379 burn_in.open(fname);
3381 fname =
prefixPath +
"iburn_in_" + this->base_t +
".txt";
3382 std::ofstream iburn_in;
3383 iburn_in.open(fname);
3389 std::string paneStr;
3390 for (
int iPart = 0; iPart < nPart; iPart++) {
3392 fluid_in <<
"@Proc: " << std::to_string(iPart) <<
"\n";
3393 fluid_in <<
"@Files: fluid_" + this->base_t +
"_%04p.cgns" 3396 tmpStr +=
" " + std::to_string(
volZoneMap[iPart]) +
"\n";
3397 fluid_in << tmpStr << std::endl;
3400 ifluid_in <<
"@Proc: " << std::to_string(iPart) <<
"\n";
3402 ifluid_in <<
"@Files: ifluid*_" + this->base_t +
"_%04p.cgns" 3406 std::string burnStrTmp;
3415 tmpStr +=
" " + std::to_string(iPart + 1);
3416 if (burnFlag) burnStrTmp +=
" " + std::to_string(iPart + 1);
3417 if ((itr1->second) < 10) {
3419 if (burnFlag) burnStrTmp +=
"0";
3421 tmpStr += std::to_string(itr1->second);
3422 if (burnFlag) burnStrTmp += std::to_string(itr1->second);
3426 ifluid_in << tmpStr << std::endl;
3429 iburn_in <<
"@Proc: " << std::to_string(iPart) <<
"\n";
3430 if (burnStrTmp.empty()) {
3431 iburn_in <<
"@Files:" 3434 iburn_in <<
"@Files: iburn*_" + this->base_t +
"_%04p.cgns" 3438 tmpStr += burnStrTmp;
3440 iburn_in << tmpStr << std::endl;
3443 burn_in <<
"@Proc: " << std::to_string(iPart) <<
"\n";
3444 if (burnStrTmp.empty()) {
3445 burn_in <<
"@Files:" 3448 burn_in <<
"@Files: burn*_" + this->base_t +
"_%04p.cgns" 3452 tmpStr += burnStrTmp;
3454 burn_in << tmpStr << std::endl;
3460 void RocPartCommGenRunner::swapTriOrdering(
3461 std::vector<cgsize_t> &connVec)
const {
3463 std::vector<cgsize_t> connVecTmp;
3466 for (
auto itr = connVec.begin(); itr != connVec.end(); ++itr) {
3468 connVecTmp.push_back(*itr);
3470 }
else if (ind == 2) {
3473 }
else if (ind == 3) {
3474 connVecTmp.push_back(*itr);
3475 connVecTmp.push_back(tmpInd);
3479 connVec = connVecTmp;
3482 std::string RocPartCommGenRunner::getPatchType(
int patchNo)
const {
3497 std::cerr <<
"Error: Can't get patch type for patch number " << patchNo
3503 void RocPartCommGenRunner::dimSurfSort(
int proc)
const {
3505 std::string procStr = std::to_string(proc);
3506 std::string procStrPadded = std::string(5 - procStr.length(),
'0') + procStr;
3508 prefixPath + this->caseName +
".dim_" + procStrPadded +
"_0.00000E+00";
3511 std::vector<std::string> myLines;
3512 std::ifstream myfile(fname);
3515 while (std::getline(myfile, line)) {
3516 myLines.push_back(line);
3519 std::map<int, std::string> patchLines;
3520 int patchCounter = 0;
3523 for (
auto itr = myLines.begin(); itr != myLines.end(); ++itr) {
3524 if ((std::distance(myLines.begin(), itr) > 1) &&
3525 (*(itr - 1)).find(
"Patches (v2)") != std::string::npos) {
3526 while ((*itr).find(
"Borders") == std::string::npos) {
3527 if (patchCounter > 0) {
3528 std::istringstream strs(*itr);
3530 std::vector<int> ints;
3531 while (strs >> tmp) {
3532 ints.push_back(tmp);
3534 patchLines[ints[0]] = *itr;
3543 for (
auto itr = myLines.begin(); itr != myLines.end(); ++itr) {
3544 if (std::distance(myLines.begin(), itr) > 2 &&
3545 (*(itr - 2)).find(
"Patches (v2)") != std::string::npos) {
3546 for (
auto itr2 = patchLines.begin(); itr2 != patchLines.end(); ++itr2) {
3547 *itr = itr2->second;
3554 std::ofstream dimFile;
3555 dimFile.open(fname);
3556 for (
auto itr = myLines.begin(); itr != myLines.end(); ++itr) {
3557 dimFile << *itr <<
"\n";
3566 std::string surfName,
3568 : volName(
std::move(volName)),
3569 surfName(
std::move(surfName)),
3570 numPartitions(numPartitions) {}
3577 RocPartCommGenRunner(this->
volName, this->
surfName, this->numPartitions);
std::vector< std::vector< nemId_t > > globalNodeIds
std::map< int, std::map< int, std::vector< int > > > sharedSurfNodes
std::vector< std::map< nemId_t, nemId_t > > partToGlobCellMap
std::map< int, std::vector< int > > receivedCellsTmp
std::vector< std::map< int, std::map< int, std::map< int, std::vector< int > > > > > sharedPatchNodes
std::vector< std::map< int, std::shared_ptr< meshBase > > > patchesOfSurfacePartitions
std::shared_ptr< meshBase > volWithSol
std::vector< std::map< nemId_t, nemId_t > > globToPartCellMap
static std::vector< std::shared_ptr< meshBase > > partition(const meshBase *mbObj, int numPartitions)
mesh partitioning (with METIS)
std::map< int, std::map< int, std::unordered_set< int > > > sentCells
std::map< int, int > totalTrisPerPatch
std::vector< std::map< nemId_t, nemId_t > > partToGlobNodeMap
A brief description of meshBase.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
std::map< int, std::vector< int > > receivedNodesTmp
std::map< int, std::vector< int > > sharedNodesTmp
std::vector< int > neighborProcsTmp
std::vector< std::map< int, int > > surfZoneMap
std::vector< std::vector< nemId_t > > globalCellIds
std::map< int, std::map< int, std::unordered_set< int > > > sentSurfCells
RocPartCommGenDriver()=default
std::map< int, int > nUniqueVolFaces
std::vector< int > notGhostInPconn
std::vector< std::map< int, std::shared_ptr< meshBase > > > virtualCellsOfSurfPartitions
std::shared_ptr< meshBase > remeshedSurf
std::map< int, std::map< int, std::unordered_set< int > > > receivedCells
std::vector< std::map< int, std::shared_ptr< meshBase > > > virtualCellsOfPartitions
std::map< int, std::map< int, std::unordered_set< int > > > receivedSurfNodes
vtkSmartPointer< vtkDataSet > getDataSet() const
get this meshes' dataSet
std::string trimmed_base_t
std::map< int, std::vector< int > > sentCellsTmp
vtkIdType id
id in .inp file
std::vector< std::shared_ptr< meshBase > > surfacePartitions
static constexpr const char * programType
std::vector< std::map< int, std::vector< int > > > surfPconns
static meshBase * stitchMB(const std::vector< meshBase *> &mbObjs)
stitch together several meshBases
std::shared_ptr< meshBase > mesh
static std::shared_ptr< meshBase > CreateShared(const std::string &fname)
Create shared ptr from fname.
std::map< int, std::map< int, std::unordered_set< int > > > receivedSurfCells
std::map< std::string, std::vector< int > > surfacePatchTypes
std::map< int, std::vector< int > > sentNodesTmp
std::vector< int > volZoneMap
std::vector< std::map< nemId_t, nemId_t > > globToPartNodeMap
std::vector< std::map< int, std::map< int, std::shared_ptr< meshBase > > > > virtualCellsOfPatchesOfSurfacePartitions
std::shared_ptr< meshBase > surfWithSol
void execute() const override
Run the workflow represented by the driver.
std::map< int, std::map< int, std::unordered_set< int > > > sentNodes
std::map< int, std::map< int, std::unordered_set< int > > > sentSurfNodes
std::map< int, int > pconnProcMin
static std::shared_ptr< TransferBase > CreateTransferObject(meshBase *srcmsh, meshBase *trgmsh, const std::string &method)
std::vector< std::shared_ptr< meshBase > > procVolMesh
static meshBase * extractSelectedCells(meshBase *mesh, const std::vector< nemId_t > &cellIds)
extract subset of mesh given list of cell ids and return meshBase obj
vtkIdType currId
If previous line was data line that is continued and current keyword is NODE or ELEMEMT, the ID of the node/cell being processed.
jsoncons::string_view getProgramType() const override
std::shared_ptr< meshBase > burnSurfWithSol
std::vector< std::map< int, int > > burnSurfZoneMap
std::vector< A > getSortedKeys(const std::map< A, B > &mapObj)
std::map< int, std::map< int, std::vector< int > > > sharedNodes
std::vector< std::vector< int > > volPconns
std::map< int, int > pconnProcMax
std::vector< std::shared_ptr< meshBase > > partitions
std::map< int, std::map< int, std::unordered_set< int > > > receivedNodes