50 const Foam::vector Foam::boundaryMesh::splitNormal_(3, 2, 1);
53 const Foam::scalar Foam::boundaryMesh::distanceTol_ = 1
e-2;
59 Foam::label Foam::boundaryMesh::nFeatureEdges(label pointi)
const
67 label edgeI = pEdges[pEdgeI];
69 if (edgeToFeature_[edgeI] != -1)
79 Foam::label Foam::boundaryMesh::nextFeatureEdge
89 label nbrEdgeI = pEdges[pEdgeI];
91 if (nbrEdgeI != edgeI)
93 label featI = edgeToFeature_[nbrEdgeI];
112 const label startEdgeI,
118 label edgeI = startEdgeI;
122 label vertI =
e.start();
124 while (!isFeaturePoint[vertI])
128 edgeI = nextFeatureEdge(edgeI, vertI);
130 if ((edgeI == -1) || (edgeI == startEdgeI))
139 vertI =
e.otherVertex(vertI);
151 labelList featLabels(featureEdges_.size());
153 label featLabelI = 0;
155 label initEdgeI = edgeI;
160 label featI = edgeToFeature_[edgeI];
167 featLabels[featLabelI++] = featI;
169 featVisited[featI] =
true;
175 vertI =
e.otherVertex(vertI);
179 edgeI = nextFeatureEdge(edgeI, vertI);
181 if ((edgeI == -1) || (edgeI == initEdgeI))
186 while (!isFeaturePoint[vertI]);
190 featLabels.setSize(featLabelI);
196 void Foam::boundaryMesh::markEdges
198 const label maxDistance,
202 DynamicList<label>& visited
209 if (minDistance[edgeI] == -1)
212 visited.append(edgeI);
214 else if (minDistance[edgeI] <=
distance)
227 forAll(startEdges, pEdgeI)
257 Foam::label Foam::boundaryMesh::findPatchID
260 const word& patchName
281 names[patchi] = patches_[patchi].name();
287 Foam::label Foam::boundaryMesh::whichPatch
297 if ((facei >= pp.
start()) && (facei < (pp.
start() + pp.size())))
321 label facei = changedFaces[i];
327 label edgeI = fEdges[fEdgeI];
329 if (!regionEdge[edgeI] && (edgeRegion[edgeI] == -1))
331 edgeRegion[edgeI] = region;
333 changedEdges[changedI++] = edgeI;
338 changedEdges.setSize(changedI);
357 label edgeI = changedEdges[i];
363 label facei = eFaces[eFacei];
365 if (faceRegion[facei] == -1)
367 faceRegion[facei] = region;
369 changedFaces[changedI++] = facei;
374 changedFaces.setSize(changedI);
381 void Foam::boundaryMesh::markZone
389 faceZone[facei] = currentZone;
401 changedEdges = faceToEdge
411 Pout<<
"From changedFaces:" << changedFaces.size()
412 <<
" to changedEdges:" << changedEdges.size()
416 if (changedEdges.empty())
421 changedFaces = edgeToFace(currentZone, changedEdges, faceZone);
425 Pout<<
"From changedEdges:" << changedEdges.size()
426 <<
" to changedFaces:" << changedFaces.size()
430 if (changedFaces.empty())
458 meshPtr_.reset(
nullptr);
473 meshFace_.setSize(nBFaces);
498 meshFace_[bFacei] = pp.
start() + patchFacei;
500 bFaces[bFacei] = pp[patchFacei];
509 Pout<<
"read : patches now:" <<
endl;
535 new bMesh(globalPatch.localFaces(), globalPatch.localPoints())
540 const bMesh& msh = *meshPtr_;
542 Pout<<
"** Start of Faces **" <<
endl;
546 const face&
f = msh[facei];
562 Pout<<
"** End of Faces **" <<
endl;
564 Pout<<
"** Start of Points **" <<
endl;
569 <<
" coord:" << msh.
points()[pointi]
573 Pout<<
"** End of Points **" <<
endl;
577 featurePoints_.clear();
578 featureEdges_.clear();
580 featureToEdge_.clear();
581 edgeToFeature_.resize(meshPtr_->nEdges());
584 featureSegments_.clear();
603 regions[triI] = surf[triI].region();
610 label oldRegion = -1111;
611 label boundPatch = 0;
615 if (regions[i] != oldRegion)
617 regionToBoundaryPatch.insert(regions[i], boundPatch);
619 oldRegion = regions[i];
628 if (surfPatches.size() == regionToBoundaryPatch.size())
633 patches_.setSize(surfPatches.size());
636 forAll(surfPatches, patchi)
658 patches_.setSize(regionToBoundaryPatch.size());
681 const labelList& indices = regions.indices();
685 meshFace_.
setSize(surf.size());
690 label surfRegion = regions[0];
691 label foamRegion = regionToBoundaryPatch[surfRegion];
693 Pout<<
"Surface region " << surfRegion <<
" becomes boundary patch "
694 << foamRegion <<
" with name " << patches_[foamRegion].
name() <<
endl;
698 label startFacei = 0;
702 label triI = indices[indexI];
706 if (tri.
region() != surfRegion)
711 bp.
size() = bFacei - startFacei;
712 bp.
start() = startFacei;
714 surfRegion = tri.
region();
715 foamRegion = regionToBoundaryPatch[surfRegion];
717 Pout<<
"Surface region " << surfRegion <<
" becomes boundary patch "
718 << foamRegion <<
" with name " << patches_[foamRegion].
name()
724 meshFace_[bFacei] = triI;
726 bFaces[bFacei++] =
face(tri);
732 bp.
size() = bFacei - startFacei;
733 bp.
start() = startFacei;
745 featurePoints_.clear();
746 featureEdges_.clear();
748 featureToEdge_.clear();
749 edgeToFeature_.resize(meshPtr_->nEdges());
752 featureSegments_.clear();
765 surfPatches[patchi] =
781 label totalNTris = getNTris(0,
mesh().size(), nTris);
790 startTri[facei] = triI;
792 triI += nTris[facei];
798 triangulate(0,
mesh().size(), totalNTris, triVerts);
812 label facei = bp.
start() + patchFacei;
814 label triVertI = 3*startTri[facei];
816 for (label faceTriI = 0; faceTriI < nTris[facei]; faceTriI++)
818 label v0 = triVerts[triVertI++];
819 label v1 = triVerts[triVertI++];
820 label v2 = triVerts[triVertI++];
831 surf.
write(surfStream);
861 scalar
sign =
mesh().faceNormals()[bFacei] & splitNormal_;
865 rightFaces.
append(bFacei);
878 Pout<<
"getNearest :"
879 <<
" rightBin:" << rightFaces.size()
880 <<
" leftBin:" << leftFaces.size()
901 scalar tol = 1
e-6 * overallBb.
avgDim();
913 const scalar planarTol =
954 Pout<<
"getNearest : built trees" <<
endl;
969 const scalar searchDimSqr =
magSqr(searchSpan);
971 forAll(nearestBFacei, patchFacei)
977 if (
debug && (patchFacei % 1000) == 0)
979 Pout<<
"getNearest : patchFace:" << patchFacei
980 <<
" meshFacei:" << meshFacei <<
" ctr:" << ctr <<
endl;
989 scalar typDim = -GREAT;
998 pointIndexHit rightInfo = rightTree.findNearest(ctr, searchDimSqr);
1002 pointIndexHit leftInfo = leftTree.findNearest(ctr, searchDimSqr);
1004 if (rightInfo.
hit())
1009 label rightFacei = rightFaces[rightInfo.
index()];
1010 label leftFacei = leftFaces[leftInfo.
index()];
1015 scalar rightSign =
n & ns[rightFacei];
1016 scalar leftSign =
n & ns[leftFacei];
1020 (rightSign > 0 && leftSign > 0)
1021 || (rightSign < 0 && leftSign < 0)
1025 if (rightDist < leftDist)
1027 nearestBFacei[patchFacei] = rightFacei;
1031 nearestBFacei[patchFacei] = leftFacei;
1043 typDim *= distanceTol_;
1045 if (rightDist < typDim && leftDist < typDim)
1050 nearestBFacei[patchFacei] = rightFacei;
1054 nearestBFacei[patchFacei] = leftFacei;
1060 if (rightDist < leftDist)
1062 nearestBFacei[patchFacei] = rightFacei;
1066 nearestBFacei[patchFacei] = leftFacei;
1075 label rightFacei = rightFaces[rightInfo.
index()];
1076 nearestBFacei[patchFacei] = rightFacei;
1087 nearestBFacei[patchFacei] = leftFaces[leftInfo.
index()];
1092 nearestBFacei[patchFacei] = -1;
1097 return nearestBFacei;
1116 Map<word> indexToName(2*patches_.size());
1119 label nNewPatches = patches_.size();
1121 forAll(oldPatches, oldPatchi)
1124 const label newPatchi = findPatchID(
patch.name());
1126 if (newPatchi != -1)
1128 nameToIndex.insert(
patch.name(), newPatchi);
1129 indexToName.insert(newPatchi,
patch.name());
1135 forAll(patches_, bPatchi)
1139 if (!nameToIndex.found(bp.
name()))
1141 nameToIndex.insert(bp.
name(), bPatchi);
1142 indexToName.insert(bPatchi, bp.
name());
1159 forAll(patches_, bPatchi)
1163 const label newPatchi = nameToIndex[bp.
name()];
1166 const label oldPatchi = findPatchID(oldPatches, bp.
name());
1168 if (oldPatchi == -1)
1173 Pout<<
"patchify : Creating new polyPatch:" << bp.
name()
1187 meshFacei += facesToBeDone;
1195 const polyPatch& oldPatch = oldPatches[oldPatchi];
1199 Pout<<
"patchify : Cloning existing polyPatch:"
1203 newPatchPtrList[newPatchi] = oldPatch.
clone
1211 meshFacei += facesToBeDone;
1221 Pout<<
"Patchify : new polyPatch list:" <<
endl;
1223 forAll(newPatchPtrList, patchi)
1225 const polyPatch& newPatch = *newPatchPtrList[patchi];
1230 <<
" type :" << newPatch.typeName <<
endl
1231 <<
" size :" << newPatch.size() <<
endl
1232 <<
" start:" << newPatch.
start() <<
endl
1233 <<
" index:" << patchi <<
endl;
1246 if (newPatchPtrList.size())
1253 forAll(patchFaces, newPatchi)
1255 patchFaces[newPatchi].setCapacity(nAvgFaces);
1263 forAll(oldPatches, oldPatchi)
1271 label meshFacei =
patch.start() + patchFacei;
1275 patchFaces[whichPatch(nearest[bFacei])].
append(meshFacei);
1279 forAll(patchFaces, newPatchi)
1281 patchFaces[newPatchi].shrink();
1288 for (label newPatchi = 1; newPatchi < patchFaces.size(); newPatchi++)
1305 edgeToFeature_.setSize(
mesh().nEdges());
1307 edgeToFeature_ = -1;
1312 featureToEdge_.setSize(
mesh().nEdges());
1316 if (minCos >= 0.9999)
1321 edgeToFeature_[edgeI] = featureI;
1322 featureToEdge_[featureI++] = edgeI;
1331 if (eFaces.size() == 2)
1333 label face0I = eFaces[0];
1335 label face1I = eFaces[1];
1346 const vector& n0 =
mesh().faceNormals()[face0I];
1348 const vector& n1 =
mesh().faceNormals()[face1I];
1350 float cosAng = n0 & n1;
1352 if (cosAng < minCos)
1354 edgeToFeature_[edgeI] = featureI;
1355 featureToEdge_[featureI++] = edgeI;
1362 edgeToFeature_[edgeI] = featureI;
1363 featureToEdge_[featureI++] = edgeI;
1369 featureToEdge_.setSize(featureI);
1375 featureEdges_.setSize(featureI);
1382 forAll(featureToEdge_, fEdgeI)
1384 label edgeI = featureToEdge_[fEdgeI];
1388 label start = featToMeshPoint[
e.start()];
1392 featToMeshPoint[
e.start()] = featPtI;
1394 featurePoints_[featPtI] =
mesh().
points()[
e.start()];
1401 label
end = featToMeshPoint[
e.end()];
1405 featToMeshPoint[
e.end()] = featPtI;
1407 featurePoints_[featPtI] =
mesh().
points()[
e.end()];
1415 featureEdges_[fEdgeI] =
edge(start,
end);
1419 featurePoints_.setSize(featPtI);
1431 forAll(featureToEdge_, featI)
1433 label edgeI = featureToEdge_[featI];
1437 if (nFeatureEdges(
e.start()) != 2)
1439 isFeaturePoint[
e.start()] =
true;
1442 if (nFeatureEdges(
e.end()) != 2)
1444 isFeaturePoint[
e.end()] =
true;
1457 boolList featVisited(featureToEdge_.size(),
false);
1461 label startFeatI = -1;
1463 forAll(featVisited, featI)
1465 if (!featVisited[featI])
1473 if (startFeatI == -1)
1484 featureToEdge_[startFeatI],
1495 featureSegments_.setSize(segments.size());
1497 forAll(featureSegments_, segmentI)
1499 featureSegments_[segmentI] = segments[segmentI];
1512 markEdges(8, edgeI, 0, minDistance, visitedEdges);
1515 extraEdges_.transfer(visitedEdges);
1519 Foam::label Foam::boundaryMesh::whichPatch(
const label facei)
const
1532 <<
"Cannot find face " << facei <<
" in list of boundaryPatches "
1540 Foam::label Foam::boundaryMesh::findPatchID(
const word& patchName)
const
1544 if (patches_[patchi].
name() == patchName)
1556 patches_.setSize(patches_.size() + 1);
1560 label patchi = patches_.size()-1;
1571 patches_.set(patchi, bpPtr);
1575 Pout<<
"addPatch : patches now:" <<
endl;
1593 const label delPatchi = findPatchID(patchName);
1595 if (delPatchi == -1)
1598 <<
"Can't find patch named " << patchName
1602 if (patches_[delPatchi].size())
1605 <<
"Trying to delete non-empty patch " << patchName
1606 <<
endl <<
"Current size:" << patches_[delPatchi].size()
1612 for (label patchi = 0; patchi < delPatchi; patchi++)
1614 newPatches.
set(patchi, patches_[patchi].clone());
1619 for (label patchi = delPatchi + 1; patchi < patches_.size(); patchi++)
1621 newPatches.set(patchi - 1, patches_[patchi].clone());
1626 patches_ = newPatches;
1630 Pout<<
"deletePatch : patches now:" <<
endl;
1648 const word& patchName,
1649 const word& patchType
1652 const label changeI = findPatchID(patchName);
1657 <<
"Can't find patch named " << patchName
1670 if (patchi == changeI)
1684 newPatches.set(patchi, bpPtr);
1689 newPatches.set(patchi, patches_[patchi].clone());
1693 patches_ = newPatches;
1703 if (patchIDs.size() !=
mesh().
size())
1706 <<
"List of patchIDs not equal to number of faces." <<
endl
1707 <<
"PatchIDs size:" << patchIDs.size()
1718 label
patchID = patchIDs[facei];
1720 if (patchID < 0 || patchID >= patches_.size())
1723 <<
"PatchID " <<
patchID <<
" out of range"
1736 for (label patchi = 1; patchi < patches_.size(); patchi++)
1738 startFace[patchi] = startFace[patchi-1] + nFaces[patchi-1];
1761 patches_ = newPatches;
1765 Pout<<
"changeFaces : patches now:" <<
endl;
1781 oldToNew.
setSize(patchIDs.size());
1785 int patchID = patchIDs[facei];
1787 oldToNew[facei] = startFace[
patchID]++;
1797 newFaces[oldToNew[facei]] =
mesh()[facei];
1798 newMeshFace[oldToNew[facei]] = meshFace_[facei];
1806 meshFace_.transfer(newMeshFace);
1813 meshPtr_ = std::move(newMeshPtr);
1827 const label startFacei,
1832 label totalNTris = 0;
1836 for (label i = 0; i < nFaces; i++)
1838 label faceNTris = getNTris(startFacei + i);
1840 nTris[i] = faceNTris;
1842 totalNTris += faceNTris;
1852 const label startFacei,
1854 const label totalNTris,
1859 triVerts.
setSize(3*totalNTris);
1863 for (label i = 0; i < nFaces; i++)
1865 label facei = startFacei + i;
1878 forAll(triFaces, triFacei)
1880 const face& triF = triFaces[triFacei];
1882 triVerts[vertI++] = triF[0];
1883 triVerts[vertI++] = triF[1];
1884 triVerts[vertI++] = triF[2];
1893 const label startFacei,
1901 return patch.nPoints();
1908 const label startFacei,
1910 const label totalNTris,
1920 localToGlobal =
patch.meshPoints();
1923 triVerts.
setSize(3*totalNTris);
1927 for (label i = 0; i < nFaces; i++)
1937 f.triangles(
patch.localPoints(), nTri, triFaces);
1941 forAll(triFaces, triFacei)
1943 const face& triF = triFaces[triFacei];
1945 triVerts[vertI++] = triF[0];
1946 triVerts[vertI++] = triF[1];
1947 triVerts[vertI++] = triF[2];
1956 const label seedFacei,
1962 forAll(protectedEdges, i)
1964 protectedEdge[protectedEdges[i]] =
true;
1972 markZone(protectedEdge, seedFacei, 0, currentZone);
1977 forAll(currentZone, facei)
1979 if (currentZone[facei] == 0)
1981 visited[facei] =
true;
1985 visited[facei] =
false;