41 Foam::label Foam::mergePatchPairs::findPatchIndex(
const word& patchName)
const
57 const Pair<word>& patchNamePair
62 findPatchIndex(patchNamePair.first()),
63 findPatchIndex(patchNamePair.second())
70 const List<Pair<word>>& patchNamePairs
73 List<Pair<label>> patchPairs(patchNamePairs.size());
75 forAll(patchNamePairs, pairi)
77 patchPairs[pairi] = findPatchIndices(patchNamePairs[pairi]);
84 void Foam::mergePatchPairs::removePoints
86 polyTopoChange& meshMod,
87 const List<Pair<label>>& patchPairs
90 boolList removedPoints(mesh_.nPoints(),
false);
97 mesh_.boundaryMesh()[patchPairs[ppi].first()].meshPoints()
103 mesh_.boundaryMesh()[patchPairs[ppi].second()].meshPoints()
109 if (removedPoints[
pi])
111 meshMod.removePoint(
pi, -1);
117 void Foam::mergePatchPairs::addPoints
119 polyTopoChange& meshMod,
120 const polyPatchIntersection& intersection
123 const pointField& intersectionPoints = intersection.points();
124 newPoints_.
setSize(intersectionPoints.size(), -1);
128 const label pointi = meshMod.addPoint
130 intersectionPoints[
pi],
137 Info<<
"Adding point "
139 << intersectionPoints[
pi]
143 newPoints_[
pi] = pointi;
148 void Foam::mergePatchPairs::removeFaces
150 polyTopoChange& meshMod,
151 const polyPatchIntersection& intersection
154 const polyPatch& srcPatch = intersection.srcPatch();
155 const polyPatch& tgtPatch = intersection.tgtPatch();
160 meshMod.removeFace(srcPatch.start() + fi, -1);
166 meshMod.removeFace(tgtPatch.start() + fi, -1);
171 Foam::face Foam::mergePatchPairs::mapFace(
const face&
f)
const
177 newFace[fpi] = newPoints_[newFace[fpi]];
184 void Foam::mergePatchPairs::addFaces
186 polyTopoChange& meshMod,
187 const polyPatchIntersection& intersection
190 const faceList& faces = intersection.faces();
191 const DynamicList<label>& faceSrcFaces = intersection.faceSrcFaces();
192 const DynamicList<label>& faceTgtFaces = intersection.faceTgtFaces();
194 const label srcPatchi = intersection.srcPatch().index();
195 const label srcPatchStart = intersection.srcPatch().start();
197 const label tgtPatchi = intersection.tgtPatch().index();
198 const label tgtPatchStart = intersection.tgtPatch().start();
202 const face f = mapFace(faces[fi]);
204 if (faceSrcFaces[fi] != -1 && faceTgtFaces[fi] != -1)
206 const label srcFacei = srcPatchStart + faceSrcFaces[fi];
207 const label tgtFacei = tgtPatchStart + faceTgtFaces[fi];
209 const label srcOwn = mesh_.faceOwner()[srcFacei];
210 const label tgtOwn = mesh_.faceOwner()[tgtFacei];
226 Info<<
"Adding internal face " <<
f
227 <<
" owner celli:" << srcOwn
228 <<
" neighbour celli:" << tgtOwn <<
endl;
245 Info<<
"Adding internal face " <<
f
246 <<
" owner celli:" << tgtOwn
247 <<
" neighbour celli:" << srcOwn <<
endl;
251 else if (faceSrcFaces[fi] != -1 && faceTgtFaces[fi] == -1)
253 const label srcFacei = srcPatchStart + faceSrcFaces[fi];
254 const label srcOwn = mesh_.faceOwner()[srcFacei];
268 Info<<
"Adding patch face " <<
f
269 <<
" owner celli:" << srcOwn
270 <<
" patchi:" << srcPatchi <<
endl;
273 else if (faceSrcFaces[fi] == -1 && faceTgtFaces[fi] != -1)
275 const label tgtFacei = tgtPatchStart + faceTgtFaces[fi];
276 const label tgtOwn = mesh_.faceOwner()[tgtFacei];
290 Info<<
"Adding patch face " <<
f
291 <<
" owner celli:" << tgtOwn
292 <<
" patchi:" << tgtPatchi <<
endl;
298 <<
"Both faceSrcFaces and faceTgtFaces are -1 for face " << fi
305 void Foam::mergePatchPairs::addEdgeAddedPoints
307 HashTable<
labelList, edge, Hash<edge>>& edgeAddedPoints,
309 const List<DynamicList<label>>& patchEdgeAddedPoints
312 const edgeList& patchEdges = patch.edges();
313 const labelList& pmp = patch.meshPoints();
315 forAll(patchEdgeAddedPoints, ei)
317 if (patchEdgeAddedPoints[ei].size())
319 labelList newEdgePoints(patchEdgeAddedPoints[ei].size());
321 forAll(newEdgePoints, npi)
323 newEdgePoints[npi] = newPoints_[patchEdgeAddedPoints[ei][npi]];
326 edgeAddedPoints.insert
328 edge(pmp[patchEdges[ei].start()], pmp[patchEdges[ei].end()]),
336 void Foam::mergePatchPairs::updatePoints
343 const labelList& pmp = patch.meshPoints();
347 pointMap[pmp[ppi]] = newPoints_[pointPoints[ppi]];
352 void Foam::mergePatchPairs::modifyFaces
354 polyTopoChange& meshMod,
355 const polyPatchIntersection& intersection
358 HashTable<labelList, edge, Hash<edge>> edgeAddedPoints;
362 intersection.srcPatch(),
363 intersection.srcEdgePoints()
368 intersection.tgtPatch(),
369 intersection.tgtEdgePoints()
376 intersection.srcPatch(),
377 intersection.srcPointPoints()
382 intersection.tgtPatch(),
383 intersection.tgtPointPoints()
386 DynamicList<label> modifiedFace;
388 const faceList& meshFaces = mesh_.faces();
392 if (meshMod.faceRemoved(fi))
397 const face&
f = meshFaces[fi];
400 bool modified =
false;
406 const HashTable<labelList, edge, Hash<edge>>::const_iterator iter =
407 edgeAddedPoints.find(
e);
409 if (iter != edgeAddedPoints.end())
420 || modifiedFace[modifiedFace.size() - 1]
424 modifiedFace.append(addedPoints[i]);
435 || modifiedFace[modifiedFace.size() - 1]
439 modifiedFace.append(addedPoints[i]);
448 modifiedFace.erase(modifiedFace.begin());
458 modifiedFace.append(pointMap[
f[
pi]]);
472 if (pointMap[
f[
pi]] !=
f[
pi])
480 modifiedFace[
pi] = pointMap[
f[
pi]];
487 if (mesh_.isInternalFace(fi))
491 Info<<
"Modifying internal face " << fi
492 <<
" newface:" << modifiedFace
494 <<
" centre:" << mesh_.faceCentres()[fi]
495 <<
" owner:" << mesh_.faceOwner()[fi]
496 <<
" neighbour:" << mesh_.faceNeighbour()[fi]
504 mesh_.faceOwner()[fi],
505 mesh_.faceNeighbour()[fi],
514 Info<<
"Modifying boundary face " << fi
515 <<
" newface:" << modifiedFace
517 <<
" centre:" << mesh_.faceCentres()[fi]
518 <<
" owner:" << mesh_.faceOwner()[fi]
519 <<
" patch:" << mesh_.boundaryMesh().whichPatch(fi)
527 mesh_.faceOwner()[fi],
530 mesh_.boundaryMesh().whichPatch(fi)
535 modifiedFace.clear();
540 void Foam::mergePatchPairs::intersectPatchPair
542 polyTopoChange& meshMod,
543 const polyPatch& srcPatch,
544 const polyPatch& tgtPatch
547 polyPatchIntersection intersection(srcPatch, tgtPatch, snapTol_);
548 removeFaces(meshMod, intersection);
549 addPoints(meshMod, intersection);
550 addFaces(meshMod, intersection);
551 modifyFaces(meshMod, intersection);
557 const List<Pair<label>>& patchPairs
561 polyTopoChange meshMod(mesh_);
563 removePoints(meshMod, patchPairs);
572 mesh_.boundaryMesh()[patchPairs[ppi].first()],
573 mesh_.boundaryMesh()[patchPairs[ppi].second()]
578 return meshMod.changeMesh(mesh_);
582 bool Foam::mergePatchPairs::connected
592 if (patchPoints[pmp[
pi]])
597 patchPoints[pmp[
pi]] =
true;
605 inline void Foam::mergePatchPairs::merge
608 const List<Pair<word>>& patchPairNames
611 const List<Pair<label>> patchPairs(this->patchPairs(patchPairNames));
613 bool connected =
false;
615 if (patchPairs.size() > 1)
617 boolList patchPoints(mesh_.nPoints(),
false);
623 this->connected(patchPoints, patchPairs[ppi].
first())
624 || this->connected(patchPoints, patchPairs[ppi].
second())
636 forAll(patchPairNames, ppi)
638 Info<<
"Merging patch pair " << patchPairNames[ppi] <<
endl;
642 merge(List<Pair<label>>(patchPairs[ppi]))
648 Info<<
"Merging patch pairs " << patchPairNames <<
endl;
660 zeroSizedMergedPatches.insert(patchPairs[ppi].
first());
665 zeroSizedMergedPatches.insert(patchPairs[ppi].
second());
678 if (!zeroSizedMergedPatches.found(
patchi))
680 remainingPatches[rpi++] =
patchi;
685 mesh_.reorderPatches(remainingPatches,
true);
702 merge(
mesh, patchPairNames);
717 merge(
mesh, patchPairNames);
#define forAll(list, i)
Loop across all elements in list.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(const label)
Reset size of List.
An ordered pair of two objects of type <Type> with first() and second() elements.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
label size() const
Return the number of elements in the UPtrList.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static int compare(const edge &, const edge &)
Compare edges.
A face is a list of labels corresponding to mesh vertices.
Mesh data needed to do the Finite Volume discretisation.
virtual void topoChange(const polyTopoChangeMap &map)
Update mesh corresponding to the given map.
Class to stitch mesh by merging patch-pairs.
mergePatchPairs(polyMesh &mesh, const List< Pair< word >> &patchPairNames, const scalar snapTol)
label findIndex(const word &patchName) const
Find patch index given a name.
Mesh consisting of general polyhedral cells.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList second(const UList< labelPair > &p)
vectorField pointField
pointField is a vectorField.
List< bool > boolList
Bool container classes.
defineDebugSwitch(mergePatchPairs, 0)
labelList first(const UList< labelPair > &p)
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.