95 static const scalar defaultMergeTol = 1
E-7;
108 elems[i] = map[elems[i]];
120 const bool fullMatch,
124 const scalar mergeDist
127 if (fullMatch || masterMesh.
nCells() == 0)
147 const string toProcString(
"to" +
name(procI));
155 forAll(masterPatches, patchI)
157 const polyPatch& pp = masterPatches[patchI];
161 isA<processorPolyPatch>(pp)
163 pp.
name().rfind(toProcString)
164 == (pp.
name().size()-toProcString.size())
168 label meshFaceI = pp.
start();
171 masterFaces.append(meshFaceI++);
175 masterFaces.shrink();
189 forAll(addPatches, patchI)
191 const polyPatch& pp = addPatches[patchI];
193 if (isA<processorPolyPatch>(pp))
195 bool isConnected =
false;
197 for (label mergedProcI = 0; mergedProcI < procI; mergedProcI++)
199 const string fromProcString
207 if (pp.
name() == fromProcString)
216 label meshFaceI = pp.
start();
219 addFaces.append(meshFaceI++);
247 const scalar mergeDist,
263 Info<<
"mergeSharedPoints : detected " << pointToMaster.size()
264 <<
" points that are to be merged." <<
endl;
285 forAll(pointProcAddressing, procI)
287 labelList& constructMap = pointProcAddressing[procI];
291 label oldPointI = constructMap[i];
294 label newPointI = map().reversePointMap()[oldPointI];
298 constructMap[i] = -newPointI-2;
300 else if (newPointI >= 0)
302 constructMap[i] = newPointI;
307 <<
"Problem. oldPointI:" << oldPointI
317 int main(
int argc,
char *argv[])
328 Info<<
"This is an experimental tool which tries to merge"
329 <<
" individual processor" <<
nl
330 <<
"meshes back into one master mesh. Use it if the original"
331 <<
" master mesh has" <<
nl
332 <<
"been deleted or if the processor meshes have been modified"
333 <<
" (topology change)." <<
nl
334 <<
"This tool will write the resulting mesh to a new time step"
335 <<
" and construct" <<
nl
336 <<
"xxxxProcAddressing files in the processor meshes so"
337 <<
" reconstructPar can be" <<
nl
338 <<
"used to regenerate the fields on the master mesh." <<
nl
340 <<
"Not well tested & use at your own risk!" <<
nl
350 Info<<
"Operating on region " << regionName <<
nl <<
endl;
353 scalar mergeTol = defaultMergeTol;
358 Info<<
"Merge tolerance : " << mergeTol <<
nl
359 <<
"Write tolerance : " << writeTol <<
endl;
364 <<
"Your current settings specify ASCII writing with "
366 <<
"Your merging tolerance (" << mergeTol <<
") is finer than this."
368 <<
"Please change your writeFormat to binary"
369 <<
" or increase the writePrecision" << endl
370 <<
"or adjust the merge tolerance (-mergeTol)."
379 Info<<
"Doing geometric matching on all boundary faces." <<
nl <<
endl;
383 Info<<
"Doing geometric matching on correct procBoundaries only."
384 <<
nl <<
"This assumes a correct decomposition." <<
endl;
404 Info<<
"Found " << nProcs <<
" processor directories" <<
nl <<
endl;
412 Info<<
"Reading database "
427 Time& procTime = databases[procI];
436 if (procI > 0 && databases[procI-1].value() != procTime.
value())
439 <<
"Time not equal on processors." <<
nl
440 <<
"Processor:" << procI-1
441 <<
" time:" << databases[procI-1].value() <<
nl
442 <<
"Processor:" << procI
443 <<
" time:" << procTime.
value()
449 Info<<
"Setting master time to " << databases[0].timeName() <<
nl <<
endl;
450 runTime.setTime(databases[0]);
458 for (label procI = 0; procI < nProcs; procI++)
462 databases[procI].findInstance
469 if (pointsInstance != databases[procI].
timeName())
472 <<
"Your time was specified as " << databases[procI].
timeName()
473 <<
" but there is no polyMesh/points in that time." << endl
474 <<
"(there is a points file in " << pointsInstance
476 <<
"Please rerun with the correct time specified"
477 <<
" (through the -constant, -time or -latestTime option)."
481 Info<<
"Reading points from "
482 << databases[procI].caseName()
483 <<
" for time = " << databases[procI].timeName()
491 databases[procI].findInstance
509 const scalar mergeDist = mergeTol * bb.
mag();
511 Info<<
"Overall mesh bounding box : " << bb <<
nl
512 <<
"Relative tolerance : " << mergeTol <<
nl
513 <<
"Absolute matching distance : " << mergeDist <<
nl
524 label masterInternalFaces;
530 Info<<
"Constructing empty mesh to add to." <<
nl <<
endl;
545 for (label procI = 0; procI < nProcs; procI++)
547 Info<<
"Reading mesh to add from "
548 << databases[procI].caseName()
549 <<
" for time = " << databases[procI].timeName()
566 boundaryProcAddressing[procI] =
595 for (label mergedI = 0; mergedI < procI; mergedI++)
597 renumber(map().oldCellMap(), cellProcAddressing[mergedI]);
598 renumber(map().oldFaceMap(), faceProcAddressing[mergedI]);
599 renumber(map().oldPointMap(), pointProcAddressing[mergedI]);
601 renumber(map().oldPatchMap(), boundaryProcAddressing[mergedI]);
605 renumber(map().addedCellMap(), cellProcAddressing[procI]);
606 renumber(map().addedFaceMap(), faceProcAddressing[procI]);
607 renumber(map().addedPointMap(), pointProcAddressing[procI]);
608 renumber(map().addedPatchMap(), boundaryProcAddressing[procI]);
615 mergeSharedPoints(mergeDist, masterMesh, pointProcAddressing);
622 Info<<
"\nWriting merged mesh to "
623 << runTime.path()/runTime.timeName()
626 if (!masterMesh.
write())
629 <<
"Failed writing polyMesh."
637 Info<<
"Reconstructing the addressing from the processor meshes"
638 <<
" to the newly reconstructed mesh" <<
nl <<
endl;
642 Info<<
"Reading processor " << procI <<
" mesh from "
643 << databases[procI].caseName() <<
endl;
658 Info<<
"Writing pointProcAddressing to "
659 << databases[procI].caseName()
660 /procMesh.facesInstance()
668 "pointProcAddressing",
669 procMesh.facesInstance(),
676 pointProcAddressing[procI]
682 Info<<
"Writing faceProcAddressing to "
683 << databases[procI].caseName()
684 /procMesh.facesInstance()
692 "faceProcAddressing",
693 procMesh.facesInstance(),
700 faceProcAddressing[procI]
705 forAll(faceProcAddr, procFaceI)
707 label masterFaceI = faceProcAddr[procFaceI];
711 !procMesh.isInternalFace(procFaceI)
712 && masterFaceI < masterInternalFaces
718 label procOwn = procMesh.faceOwner()[procFaceI];
719 label masterOwn = masterOwner[masterFaceI];
721 if (cellProcAddressing[procI][procOwn] == masterOwn)
724 faceProcAddr[procFaceI]++;
729 faceProcAddr[procFaceI] =
730 -1 - faceProcAddr[procFaceI];
736 faceProcAddr[procFaceI]++;
740 faceProcAddr.write();
745 Info<<
"Writing cellProcAddressing to "
746 << databases[procI].caseName()
747 /procMesh.facesInstance()
755 "cellProcAddressing",
756 procMesh.facesInstance(),
763 cellProcAddressing[procI]
770 Info<<
"Writing boundaryProcAddressing to "
771 << databases[procI].caseName()
772 /procMesh.facesInstance()
780 "boundaryProcAddressing",
781 procMesh.facesInstance(),
788 boundaryProcAddressing[procI]