83 static const scalar defaultMergeTol = 1
e-7;
93 const label masterMeshProcStart,
94 const label masterMeshProcEnd,
96 const label meshToAddProcStart,
97 const label meshToAddProcEnd,
99 const scalar mergeDist
102 if (fullMatch || masterMesh.
nCells() == 0)
127 forAll(masterPatches, patchi)
129 const polyPatch& pp = masterPatches[patchi];
131 if (isA<processorPolyPatch>(pp))
135 label proci=meshToAddProcStart;
136 proci<meshToAddProcEnd;
140 const string toProcString(
"to" +
name(proci));
142 pp.
name().rfind(toProcString)
143 == (pp.
name().size()-toProcString.size())
146 label meshFacei = pp.
start();
149 masterFaces.append(meshFacei++);
157 masterFaces.shrink();
171 forAll(addPatches, patchi)
173 const polyPatch& pp = addPatches[patchi];
175 if (isA<processorPolyPatch>(pp))
177 bool isConnected =
false;
181 label mergedProci=masterMeshProcStart;
182 !isConnected && (mergedProci < masterMeshProcEnd);
188 label proci = meshToAddProcStart;
189 proci < meshToAddProcEnd;
193 const word fromProcString
198 if (pp.
name() == fromProcString)
208 label meshFacei = pp.
start();
211 addFaces.append(meshFacei++);
236 const scalar mergeDist,
252 Info<<
"mergeSharedPoints : detected " << pointToMaster.size()
253 <<
" points that are to be merged." <<
endl;
274 forAll(pointProcAddressing, proci)
276 labelList& constructMap = pointProcAddressing[proci];
280 label oldPointi = constructMap[i];
283 label
newPointi = map().reversePointMap()[oldPointi];
296 <<
"Problem. oldPointi:" << oldPointi
314 for (
const Time& procDb : databases)
325 if (pointsInstance != procDb.timeName())
328 <<
"Your time was specified as " << procDb.timeName()
329 <<
" but there is no polyMesh/points in that time." <<
nl
330 <<
"(points file at " << pointsInstance <<
')' <<
nl
331 <<
"Please rerun with the correct time specified"
332 <<
" (through the -constant, -time or -latestTime "
333 <<
"(at your option)."
337 Info<<
"Reading points from "
339 <<
" for time = " << procDb.timeName()
367 void writeDistribution
390 forAll(cellProcAddressing, proci)
392 const labelList& pCells = cellProcAddressing[proci];
396 cellDecomposition.write();
398 Info<<
nl <<
"Wrote decomposition to "
399 << cellDecomposition.objectRelPath()
400 <<
" for use in manual decomposition." <<
endl;
425 extrapolatedCalculatedFvPatchScalarField::typeName
428 forAll(cellDecomposition, celli)
430 cellDist[celli] = cellDecomposition[celli];
433 cellDist.correctBoundaryConditions();
436 Info<<
nl <<
"Wrote decomposition to "
437 << cellDist.objectRelPath()
438 <<
" (volScalarField) for visualization."
468 Info<<
nl <<
"Writing merged mesh to "
474 <<
"Failed writing polyMesh."
483 const label masterInternalFaces,
519 Info<<
"Writing addressing : " << outputDir <<
nl;
523 Info<<
" pointProcAddressing" <<
endl;
524 ioAddr.rename(
"pointProcAddressing");
530 Info<<
" faceProcAddressing" <<
endl;
531 ioAddr.rename(
"faceProcAddressing");
537 forAll(faceProcAddr, procFacei)
539 const label masterFacei = faceProcAddr[procFacei];
544 && masterFacei < masterInternalFaces
550 label procOwn = procMesh.
faceOwner()[procFacei];
551 label masterOwn = masterOwner[masterFacei];
553 if (cellProcAddressing[procOwn] == masterOwn)
556 faceProcAddr[procFacei]++;
561 faceProcAddr[procFacei] = -1 - faceProcAddr[procFacei];
567 faceProcAddr[procFacei]++;
571 faceProcAddr.write();
576 Info<<
" cellProcAddressing" <<
endl;
577 ioAddr.rename(
"cellProcAddressing");
583 Info<<
" boundaryProcAddressing" <<
endl;
584 ioAddr.rename(
"boundaryProcAddressing");
594 "Merge individual processor meshes back into one master mesh.\n"
595 "Use if the original master mesh has been deleted or the processor meshes\n"
596 "have been modified (topology change).\n"
597 "This tool will write the resulting mesh to a new time step and construct\n"
598 "xxxxProcAddressing files in the processor meshes so reconstructPar can be\n"
599 "used to regenerate the fields on the master mesh.\n\n"
600 "Not well tested & use at your own risk!\n\n";
604 int main(
int argc,
char *argv[])
608 "Reconstruct a mesh using geometric/topological information only"
620 "Create procAddressing only without overwriting the mesh"
626 "The merge distance relative to the bounding box size (default 1e-7)"
631 "Do (slower) geometric matching on all boundary faces"
636 "Do matching on processor faces only"
641 "Write cell distribution as a labelList - for use with 'manual' "
642 "decomposition method or as a volScalarField for post-processing."
652 const bool fullMatch =
args.
found(
"fullMatch");
653 const bool procMatch =
args.
found(
"procMatch");
654 const bool writeCellDist =
args.
found(
"cellDist");
656 const bool writeAddrOnly =
args.
found(
"addressing-only");
658 const scalar mergeTol =
663 Info<<
"Use geometric matching on all boundary faces." <<
nl <<
endl;
667 Info<<
"Use geometric matching on correct procBoundaries only." <<
nl
668 <<
"This assumes a correct decomposition." <<
endl;
672 Info<<
"Merge assuming correct, fully matched procBoundaries." <<
nl
676 if (fullMatch || procMatch)
678 const scalar writeTol =
681 Info<<
"Merge tolerance : " << mergeTol <<
nl
682 <<
"Write tolerance : " << writeTol <<
endl;
687 <<
"Your current settings specify ASCII writing with "
689 <<
"Your merging tolerance (" << mergeTol <<
")"
690 <<
" is finer than this." <<
endl
691 <<
"Please change your writeFormat to binary"
692 <<
" or increase the writePrecision" <<
endl
693 <<
"or adjust the merge tolerance (-mergeTol)."
707 <<
"No regions specified or detected."
727 <<
"No processor* directories found"
734 Info<<
"Found " << nProcs <<
" processor directories" <<
endl;
737 Info<<
" Reading database "
758 databases[0].times(),
771 databases[proci].setTime(timeDirs[timei], timei);
777 label nMeshChanged = 0;
807 hasRegionMesh[regioni] =
true;
831 if (!hasRegionMesh[regioni])
851 label masterInternalFaces;
863 const scalar mergeDist = mergeTol*bb.
mag();
865 Info<<
"Overall mesh bounding box : " << bb <<
nl
866 <<
"Relative tolerance : " << mergeTol <<
nl
867 <<
"Absolute matching distance : " << mergeDist <<
nl
874 for (label proci=0; proci<nProcs; proci++)
906 boundProcAddressing[proci] =
931 renumber(map().addedCellMap(), cellProcAddressing[proci]);
933 renumber(map().addedPointMap(), pointProcAddressing[proci]);
934 renumber(map().addedPatchMap(), boundProcAddressing[proci]);
936 for (label step=2; step<nProcs*2; step*=2)
938 for (label proci=0; proci<nProcs; proci+=step)
940 label next = proci + step/2;
946 Info<<
"Merging mesh " << proci <<
" with "
971 for (label mergedI=proci; mergedI<next; mergedI++)
976 cellProcAddressing[mergedI]
988 pointProcAddressing[mergedI]
995 boundProcAddressing[mergedI]
1003 addedI<
min(proci+step, nProcs);
1009 map().addedCellMap(),
1010 cellProcAddressing[addedI]
1015 map().addedFaceMap(),
1021 map().addedPointMap(),
1022 pointProcAddressing[addedI]
1027 map().addedPatchMap(),
1028 boundProcAddressing[addedI]
1032 masterMesh.
set(next,
nullptr);
1036 for (label proci=0; proci<nProcs; proci++)
1038 Info<<
"Reading mesh to add from "
1039 << databases[proci].caseName()
1040 <<
" for time = " << databases[proci].timeName()
1046 mergeSharedPoints(mergeDist,masterMesh[0],pointProcAddressing);
1050 masterOwner = masterMesh[0].
faceOwner();
1056 <<
"Disabled writing of merged mesh (-addressing-only)"
1062 writeMesh(masterMesh[0], cellProcAddressing);
1078 for (label proci=0; proci<nProcs; proci++)
1134 const labelList& procFaces = localBoundaryFace[proci];
1135 remoteFaceStart[proci].
setSize(procFaces.size(), 0);
1150 patchMap[proci].setSize(nGlobalPatches);
1162 const labelList oldFaceOwner(fvMeshes[0].faceOwner());
1175 boundProcAddressing,
1188 const auto& pp = pbm[patchi];
1189 if (!isA<processorPolyPatch>(pp) || pp.size())
1191 oldToNew[patchi] = newi++;
1194 const label nNonProcPatches = newi;
1199 if (oldToNew[patchi] == -1)
1201 oldToNew[patchi] = newi++;
1212 masterMeshPtr = fvMeshes[0];
1216 const fvMesh& masterMesh = masterMeshPtr();
1236 <<
"Disabled writing of merged mesh (-addressing-only)"
1241 Time& masterTime =
const_cast<Time&
>(masterMesh.
time());
1248 writeMesh(masterMesh, cellProcAddressing);
1258 masterTime.
caseName() = oldCaseName;
1266 Info<<
"Reconstructing addressing from processor meshes"
1267 <<
" to the newly reconstructed mesh" <<
nl <<
endl;
1271 Info<<
"Processor " << proci <<
nl
1272 <<
"Read processor mesh: "
1287 masterInternalFaces,
1290 cellProcAddressing[proci],
1292 pointProcAddressing[proci],
1293 boundProcAddressing[proci]