61 static const scalar defaultMergeTol = 1
e-7;
74 elems[i] = map[elems[i]];
87 const label masterMeshProcStart,
88 const label masterMeshProcEnd,
90 const label meshToAddProcStart,
91 const label meshToAddProcEnd,
93 const scalar mergeDist
96 if (fullMatch || masterMesh.
nCells() == 0)
128 if (isA<processorPolyPatch>(pp))
132 label proci=meshToAddProcStart;
133 proci<meshToAddProcEnd;
137 const string toProcString(
"to" +
name(proci));
139 pp.
name().rfind(toProcString)
140 == (pp.
name().size()-toProcString.size())
146 masterFaces.append(meshFacei++);
154 masterFaces.shrink();
172 if (isA<processorPolyPatch>(pp))
174 bool isConnected =
false;
178 label mergedProci=masterMeshProcStart;
179 !isConnected && (mergedProci < masterMeshProcEnd);
185 label proci = meshToAddProcStart;
186 proci < meshToAddProcEnd;
190 const word fromProcString
195 if (pp.
name() == fromProcString)
208 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];
287 constructMap[i] = -newPointi-2;
289 else if (newPointi >= 0)
296 <<
"Problem. oldPointi:" << oldPointi
310 const word& regionDir
319 databases[proci].findInstance
326 if (pointsInstance != databases[proci].
timeName())
329 <<
"Your time was specified as " << databases[proci].timeName()
330 <<
" but there is no polyMesh/points in that time." << endl
331 <<
"(there is a points file in " << pointsInstance
333 <<
"Please rerun with the correct time specified" 334 <<
" (through the -constant, -time or -latestTime " 335 <<
"(at your option)." 339 Info<<
"Reading points from " 340 << databases[proci].caseName()
341 <<
" for time = " << databases[proci].timeName()
349 databases[proci].findInstance
372 void writeCellDistance
396 forAll(cellProcAddressing, proci)
398 const labelList& pCells = cellProcAddressing[proci];
402 cellDecomposition.write();
404 Info<<
nl <<
"Wrote decomposition to " 405 << cellDecomposition.objectPath()
406 <<
" for use in manual decomposition." <<
endl;
412 const scalar oldTime = runTime.
value();
416 runTime.
setTime(0, oldIndex+1);
431 extrapolatedCalculatedFvPatchScalarField::typeName
434 forAll(cellDecomposition, celli)
436 cellDist[celli] = cellDecomposition[celli];
438 cellDist.correctBoundaryConditions();
442 Info<<
nl <<
"Wrote decomposition as volScalarField to " 443 << cellDist.name() <<
" for use in postprocessing." 447 runTime.
setTime(oldTime, oldIndex);
452 int main(
int argc,
char *argv[])
456 "reconstruct a mesh using geometric information only" 467 "specify the merge distance relative to the bounding box size " 473 "do (slower) geometric matching on all boundary faces" 478 "write cell distribution as a labelList - for use with 'manual' " 479 "decomposition method or as a volScalarField for post-processing." 487 Info<<
"This is an experimental tool which tries to merge" 488 <<
" individual processor" <<
nl 489 <<
"meshes back into one master mesh. Use it if the original" 490 <<
" master mesh has" <<
nl 491 <<
"been deleted or if the processor meshes have been modified" 492 <<
" (topology change)." <<
nl 493 <<
"This tool will write the resulting mesh to a new time step" 494 <<
" and construct" <<
nl 495 <<
"xxxxProcAddressing files in the processor meshes so" 496 <<
" reconstructPar can be" <<
nl 497 <<
"used to regenerate the fields on the master mesh." <<
nl 499 <<
"Not well tested & use at your own risk!" <<
nl 504 if (regionNames.size() > 1)
506 Info<<
"Operating on regions " << regionNames[0];
507 for (
label regioni = 1; regioni < regionNames.size() - 1; ++ regioni)
509 Info<<
", " << regionNames[regioni];
511 Info<<
" and " << regionNames.last() <<
nl <<
endl;
515 Info<<
"Operating on region " << regionNames[0] <<
nl <<
endl;
519 scalar mergeTol = defaultMergeTol;
524 Info<<
"Merge tolerance : " << mergeTol <<
nl 525 <<
"Write tolerance : " << writeTol <<
endl;
530 <<
"Your current settings specify ASCII writing with " 532 <<
"Your merging tolerance (" << mergeTol <<
") is finer than this." 534 <<
"Please change your writeFormat to binary" 535 <<
" or increase the writePrecision" << endl
536 <<
"or adjust the merge tolerance (-mergeTol)." 541 const bool fullMatch = args.
optionFound(
"fullMatch");
545 Info<<
"Doing geometric matching on all boundary faces." <<
nl <<
endl;
549 Info<<
"Doing geometric matching on correct procBoundaries only." 550 <<
nl <<
"This assumes a correct decomposition." <<
endl;
558 Info<<
"Found " << nProcs <<
" processor directories" <<
nl <<
endl;
566 Info<<
"Reading database " 586 databases[0].times(),
594 runTime.
setTime(timeDirs[timeI], timeI);
601 databases[proci].setTime(timeDirs[timeI], timeI);
604 forAll(regionNames, regioni)
606 const word& regionName = regionNames[regioni];
607 const word regionDir =
636 const boundBox bb = procBounds(args, databases, regionDir);
637 const scalar mergeDist = mergeTol*bb.
mag();
639 Info<<
"Overall mesh bounding box : " << bb <<
nl 640 <<
"Relative tolerance : " << mergeTol <<
nl 641 <<
"Absolute matching distance : " << mergeDist <<
nl 652 label masterInternalFaces;
662 for (
label proci=0; proci<nProcs; proci++)
696 boundaryProcAddressing[proci] =
721 renumber(map().addedCellMap(), cellProcAddressing[proci]);
722 renumber(map().addedFaceMap(), faceProcAddressing[proci]);
723 renumber(map().addedPointMap(), pointProcAddressing[proci]);
726 map().addedPatchMap(),
727 boundaryProcAddressing[proci]
730 for (
label step=2; step<nProcs*2; step*=2)
732 for (
label proci=0; proci<nProcs; proci+=step)
734 label next = proci + step/2;
740 Info<<
"Merging mesh " << proci <<
" with " << next
765 for (
label mergedI=proci; mergedI<next; mergedI++)
770 cellProcAddressing[mergedI]
776 faceProcAddressing[mergedI]
782 pointProcAddressing[mergedI]
789 boundaryProcAddressing[mergedI]
797 addedI<
min(proci+step, nProcs);
803 map().addedCellMap(),
804 cellProcAddressing[addedI]
809 map().addedFaceMap(),
810 faceProcAddressing[addedI]
815 map().addedPointMap(),
816 pointProcAddressing[addedI]
821 map().addedPatchMap(),
822 boundaryProcAddressing[addedI]
826 masterMesh.
set(next,
nullptr);
830 for (
label proci=0; proci<nProcs; proci++)
832 Info<<
"Reading mesh to add from " 833 << databases[proci].caseName()
834 <<
" for time = " << databases[proci].timeName()
852 Info<<
"\nWriting merged mesh to " 856 if (!masterMesh[0].
write())
859 <<
"Failed writing polyMesh." 877 Info<<
"Reconstructing the addressing from the processor meshes" 878 <<
" to the newly reconstructed mesh" <<
nl <<
endl;
882 Info<<
"Reading processor " << proci <<
" mesh from " 883 << databases[proci].caseName() <<
endl;
898 Info<<
"Writing pointProcAddressing to " 899 << databases[proci].caseName()
900 /procMesh.facesInstance()
908 "pointProcAddressing",
909 procMesh.facesInstance(),
916 pointProcAddressing[proci]
922 Info<<
"Writing faceProcAddressing to " 923 << databases[proci].caseName()
924 /procMesh.facesInstance()
932 "faceProcAddressing",
933 procMesh.facesInstance(),
940 faceProcAddressing[proci]
945 forAll(faceProcAddr, procFacei)
947 const label masterFacei = faceProcAddr[procFacei];
951 !procMesh.isInternalFace(procFacei)
952 && masterFacei < masterInternalFaces
958 label procOwn = procMesh.faceOwner()[procFacei];
959 label masterOwn = masterOwner[masterFacei];
961 if (cellProcAddressing[proci][procOwn] == masterOwn)
964 faceProcAddr[procFacei]++;
969 faceProcAddr[procFacei] =
970 -1 - faceProcAddr[procFacei];
976 faceProcAddr[procFacei]++;
980 faceProcAddr.write();
985 Info<<
"Writing cellProcAddressing to " 986 << databases[proci].caseName()
987 /procMesh.facesInstance()
995 "cellProcAddressing",
996 procMesh.facesInstance(),
1003 cellProcAddressing[proci]
1010 Info<<
"Writing boundaryProcAddressing to " 1011 << databases[proci].caseName()
1012 /procMesh.facesInstance()
1020 "boundaryProcAddressing",
1021 procMesh.facesInstance(),
1028 boundaryProcAddressing[proci]
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
#define forAll(list, i)
Loop across all elements in list.
fileName path() const
Return path.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
A class for handling file names.
bool set(const label) const
Is element set.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const fileName & facesInstance() const
Return the current instance directory for faces.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label nInternalFaces() const
const fileName & rootPath() const
Return root path.
PtrList< labelIOList > & faceProcAddressing
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static unsigned int defaultPrecision()
Return the default precision.
static word defaultRegion
Return the default region name.
static word newName(const label myProcNo, const label neighbProcNo)
Return the name of a processorPolyPatch.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
static void noParallel()
Remove the parallel options.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
A bounding box defined in terms of the points at its extremities.
Xfer< T > xferCopy(const T &)
Construct by copying the contents of the arg.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Container for information needed to couple to meshes. When constructed from two meshes and a geometri...
vectorField pointField
pointField is a vectorField.
static void mergePoints(const polyMesh &, const Map< label > &pointToMaster, polyTopoChange &meshMod)
Helper: Merge points.
virtual void updateMesh(const mapPolyMesh &mpm)
Update the mesh corresponding to given map.
A class for handling words, derived from string.
Extract command arguments and options from the supplied argc and argv parameters. ...
scalar mag() const
The magnitude of the bounding box span.
const word & constant() const
Return constant name.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
virtual const labelList & faceOwner() const
Return face owner.
const Type & value() const
Return const reference to value.
static const word null
An empty word.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
const fileOperation & fileHandler()
Get current file handler.
static word controlDictName
The default control dictionary name (normally "controlDict")
errorManip< error > abort(error &err)
static autoPtr< mapAddedPolyMesh > add(fvMesh &mesh0, const fvMesh &mesh1, const faceCoupleInfo &coupleInfo, const bool validBoundary=true)
Inplace add mesh to fvMesh. Maps all stored fields. Returns map.
instantList select(const instantList &) const
Select a list of Time values that are within the ranges.
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
IOstream::streamFormat writeFormat() const
Default write format.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
fileName path() const
Return the path to the caseName.
label size() const
Return the number of elements in the UPtrList.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
const point & max() const
Maximum describing the bounding box.
bool set(const Key &, const T &newElmt)
Assign a new hashedEntry, overwriting existing entries.
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- vGreat.
label timeIndex() const
Return current time index.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Mesh data needed to do the Finite Volume discretisation.
A List with indirect addressing.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label start() const
Return start label of this patch in the polyMesh face list.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
const doubleScalar e
Elementary charge.
Mesh consisting of general polyhedral cells.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
const point & min() const
Minimum describing the bounding box.
static void addNote(const string &)
Add extra notes for the usage information.
A patch is a list of labels that address the faces in the global face list.
virtual bool write(const bool valid=true) const
Write using setting from DB.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
A primitive field of type <T> with automated input and output.
List< cell > cellList
list of cells
wordList selectRegionNames(const argList &args, const Time &runTime)
static Map< label > findSharedPoints(const polyMesh &, const scalar mergeTol)
Find topologically and geometrically shared points.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
IOList< label > labelIOList
Label container classes.