42 void Foam::meshRefinement::markBoundaryFace
50 isBoundaryFace[faceI] =
true;
56 isBoundaryEdge[fEdges[fp]] =
true;
59 const face&
f = mesh_.
faces()[faceI];
63 isBoundaryPoint[f[fp]] =
true;
68 void Foam::meshRefinement::findNearest
71 List<pointIndexHit>& nearestInfo,
80 fc[i] = mesh_.faceCentres()[meshFaces[i]];
95 nearestNormal.setSize(nearestInfo.size());
96 nearestRegion.setSize(nearestInfo.size());
100 DynamicList<pointIndexHit> localHits;
104 if (nearestSurface[i] == surfI)
106 localHits.append(nearestInfo[i]);
110 label geomI = surfaces_.surfaces()[surfI];
113 surfaces_.geometry()[geomI].getNormal(localHits, localNormals);
116 surfaces_.geometry()[geomI].getRegion(localHits, localRegion);
121 if (nearestSurface[i] == surfI)
123 nearestNormal[i] = localNormals[localI];
124 nearestRegion[i] = localRegion[localI];
139 autoPtr<indirectPrimitivePatch> ppPtr
153 DynamicList<label> candidateFaces(pp.size()/20);
157 const labelList& cellLevel = meshCutter_.cellLevel();
161 const labelList& eFaces = edgeFaces[edgeI];
163 if (eFaces.size() == 2)
165 label face0 = pp.addressing()[eFaces[0]];
166 label face1 = pp.addressing()[eFaces[1]];
168 label cell0 = mesh_.faceOwner()[face0];
169 label cell1 = mesh_.faceOwner()[face1];
171 if (cellLevel[cell0] > cellLevel[cell1])
174 const vector& n0 = pp.faceNormals()[eFaces[0]];
175 const vector& n1 = pp.faceNormals()[eFaces[1]];
177 if (
mag(n0 & n1) < 0.1)
179 candidateFaces.append(face0);
182 else if (cellLevel[cell1] > cellLevel[cell0])
185 const vector& n0 = pp.faceNormals()[eFaces[0]];
186 const vector& n1 = pp.faceNormals()[eFaces[1]];
188 if (
mag(n0 & n1) < 0.1)
190 candidateFaces.append(face1);
195 candidateFaces.shrink();
198 <<
" faces on edge-connected cells of differing level."
203 faceSet fSet(mesh_,
"edgeConnectedFaces", candidateFaces);
204 Pout<<
"Writing " << fSet.size()
205 <<
" with problematic topology to faceSet "
206 << fSet.objectPath() <<
endl;
214 List<pointIndexHit> nearestInfo;
231 Map<label> candidateCells(candidateFaces.size());
233 faceSet perpFaces(mesh_,
"perpendicularFaces", pp.size()/100);
237 label faceI = candidateFaces[i];
239 vector n = mesh_.faceAreas()[faceI];
242 label region = surfaces_.globalRegion
249 perpendicularAngle[region]
257 perpFaces.insert(faceI);
258 candidateCells.insert
260 mesh_.faceOwner()[faceI],
261 globalToPatch[region]
269 Pout<<
"Writing " << perpFaces.size()
270 <<
" faces that are perpendicular to the surface to set "
271 << perpFaces.objectPath() <<
endl;
274 return candidateCells;
281 bool Foam::meshRefinement::isCollapsedFace
285 const scalar minFaceArea,
286 const scalar maxNonOrtho,
290 vector s = mesh_.faces()[faceI].normal(points);
291 scalar magS =
mag(s);
294 if (magS < minFaceArea)
300 const point& ownCc = mesh_.cellCentres()[mesh_.faceOwner()[faceI]];
302 if (mesh_.isInternalFace(faceI))
304 label nei = mesh_.faceNeighbour()[faceI];
305 vector d = ownCc - mesh_.cellCentres()[nei];
307 scalar dDotS = (d & s)/(
mag(d)*magS + VSMALL);
309 if (dDotS < maxNonOrtho)
320 label patchI = mesh_.boundaryMesh().whichPatch(faceI);
322 if (mesh_.boundaryMesh()[patchI].coupled())
324 vector d = ownCc - neiCc[faceI-mesh_.nInternalFaces()];
326 scalar dDotS = (d & s)/(
mag(d)*magS + VSMALL);
328 if (dDotS < maxNonOrtho)
348 bool Foam::meshRefinement::isCollapsedCell
351 const scalar volFraction,
355 scalar vol = mesh_.cells()[cellI].mag(points, mesh_.faces());
357 if (vol/mesh_.cellVolumes()[cellI] < volFraction)
376 const dictionary& motionDict,
377 const bool removeEdgeConnectedCells,
382 const labelList& cellLevel = meshCutter_.cellLevel();
383 const labelList& pointLevel = meshCutter_.pointLevel();
384 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
392 boolList isBoundaryPoint(mesh_.nPoints(),
false);
393 boolList isBoundaryEdge(mesh_.nEdges(),
false);
394 boolList isBoundaryFace(mesh_.nFaces(),
false);
398 labelList adaptPatchIDs(meshedPatches());
402 label patchI = adaptPatchIDs[i];
404 const polyPatch& pp = patches[patchI];
406 label faceI = pp.start();
423 labelList neiLevel(mesh_.nFaces()-mesh_.nInternalFaces());
424 pointField neiCc(mesh_.nFaces()-mesh_.nInternalFaces());
425 calcNeighbourData(neiLevel, neiCc);
429 label nBaffleFaces = 0;
432 label nPrevented = 0;
434 if (removeEdgeConnectedCells &&
max(perpendicularAngle) >= 0)
436 Info<<
"markFacesOnProblemCells :"
437 <<
" Checking for edge-connected cells of highly differing sizes."
442 Map<label> problemCells
444 findEdgeConnectedProblemCells
454 const cell& cFaces = mesh_.cells()[iter.key()];
458 label faceI = cFaces[i];
460 if (facePatch[faceI] == -1 && mesh_.isInternalFace(faceI))
462 facePatch[faceI] = getBafflePatch(facePatch, faceI);
476 Info<<
"markFacesOnProblemCells : Marked "
478 <<
" additional internal faces to be converted into baffles"
481 <<
" cells edge-connected to lower level cells." <<
endl;
485 cellSet problemCellSet(mesh_,
"problemCells", problemCells.toc());
486 Pout<<
"Writing " << problemCellSet.size()
487 <<
" cells that are edge connected to coarser cell to set "
488 << problemCellSet.objectPath() <<
endl;
489 problemCellSet.
write();
524 scalar volFraction = -1;
525 if (motionDict.found(
"minVolCollapseRatio"))
527 volFraction =
readScalar(motionDict.lookup(
"minVolCollapseRatio"));
529 const bool checkCollapse = (volFraction > 0);
531 scalar maxNonOrtho = -1;
539 minArea =
readScalar(motionDict.lookup(
"minArea"));
540 maxNonOrtho =
readScalar(motionDict.lookup(
"maxNonOrtho"));
542 Info<<
"markFacesOnProblemCells :"
543 <<
" Deleting all-anchor surface cells only if"
544 <<
"snapping them violates mesh quality constraints:" <<
nl
545 <<
" snapped/original cell volume < " << volFraction <<
nl
546 <<
" face area < " << minArea <<
nl
547 <<
" non-orthogonality > " << maxNonOrtho <<
nl
551 autoPtr<indirectPrimitivePatch> ppPtr
560 const pointField& localPoints = pp.localPoints();
561 const labelList& meshPoints = pp.meshPoints();
563 List<pointIndexHit> hitInfo;
565 surfaces_.findNearest
567 surfaces_.getUnnamedSurfaces(),
575 newPoints = mesh_.points();
579 if (hitInfo[i].hit())
581 newPoints[meshPoints[i]] = hitInfo[i].hitPoint();
605 DynamicList<label> dynFEdges;
606 DynamicList<label> dynCPoints;
610 const labelList& cPoints = mesh_.cellPoints(cellI, dynCPoints);
614 label nBoundaryAnchors = 0;
615 label nNonAnchorBoundary = 0;
616 label nonBoundaryAnchor = -1;
620 label pointI = cPoints[i];
622 if (pointLevel[pointI] <= cellLevel[cellI])
625 if (isBoundaryPoint[pointI])
632 nonBoundaryAnchor = pointI;
635 else if (isBoundaryPoint[pointI])
637 nNonAnchorBoundary++;
641 if (nBoundaryAnchors == 8)
643 const cell& cFaces = mesh_.cells()[cellI];
650 if (isBoundaryFace[cFaces[cFaceI]])
666 && !isCollapsedCell(newPoints, volFraction, cellI)
682 label faceI = cFaces[cf];
686 facePatch[faceI] == -1
687 && mesh_.isInternalFace(faceI)
690 facePatch[faceI] = getBafflePatch(facePatch, faceI);
706 else if (nBoundaryAnchors == 7)
709 hasSevenBoundaryAnchorPoints.set(cellI, 1u);
710 nonBoundaryAnchors.insert(nonBoundaryAnchor);
719 DynamicList<label> dynPCells;
723 label pointI = iter.key();
725 const labelList& pCells = mesh_.pointCells(pointI, dynPCells);
732 if (hasSevenBoundaryAnchorPoints.get(pCells[i]) == 1u)
743 label cellI = pCells[i];
745 if (hasSevenBoundaryAnchorPoints.get(cellI) == 1u)
750 && !isCollapsedCell(newPoints, volFraction, cellI)
765 const cell& cFaces = mesh_.cells()[cellI];
769 label faceI = cFaces[cf];
773 facePatch[faceI] == -1
774 && mesh_.isInternalFace(faceI)
777 facePatch[faceI] = getBafflePatch
832 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
834 if (facePatch[faceI] == -1)
836 const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
837 label nFaceBoundaryEdges = 0;
841 if (isBoundaryEdge[fEdges[fe]])
843 nFaceBoundaryEdges++;
847 if (nFaceBoundaryEdges == fEdges.size())
870 facePatch[faceI] = getBafflePatch(facePatch, faceI);
882 const polyPatch& pp = patches[patchI];
886 label faceI = pp.start();
890 if (facePatch[faceI] == -1)
892 const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
893 label nFaceBoundaryEdges = 0;
897 if (isBoundaryEdge[fEdges[fe]])
899 nFaceBoundaryEdges++;
903 if (nFaceBoundaryEdges == fEdges.size())
927 facePatch[faceI] = getBafflePatch(facePatch, faceI);
941 Info<<
"markFacesOnProblemCells : marked "
943 <<
" additional internal faces to be converted into baffles."
948 Info<<
"markFacesOnProblemCells : prevented "
950 <<
" internal faces fom getting converted into baffles."