68 Foam::label Foam::snappySnapDriver::getCollocatedPoints
72 bitSet& isCollocatedPoint
83 bool hasMerged = (nUnique <
points.size());
91 label nCollocated = 0;
96 forAll(pointMap, oldPointi)
108 isCollocatedPoint.set(oldPointi);
114 isCollocatedPoint.set(firstOldPoint[
newPointi]);
117 isCollocatedPoint.set(oldPointi);
130 const meshRefinement& meshRefiner,
131 const motionSmoother& meshMover
135 const polyMesh&
mesh = meshMover.mesh();
138 const hexRef8& cutter = meshRefiner.meshCutter();
139 const labelList& cellLevel = cutter.cellLevel();
183 label nInterface = 0;
190 if (!isFront.test(facei) && ownLevel != neiLevel)
193 isMovingPoint.
set(
f);
207 if (!isFront.test(facei) && ownLevel != neiLevel)
210 isMovingPoint.
set(
f);
220 <<
" inbetween refinement regions." <<
endl;
237 Field<weightedPosition> sumLocation
243 forAll(isMovingPoint, pointi)
245 if (isMovingPoint.test(pointi))
249 sumLocation[pointi].
first() = pCells.size();
250 for (
const label celli : pCells)
261 pointField& displacement = tdisplacement.ref();
265 forAll(displacement, pointi)
267 const weightedPosition& wp = sumLocation[pointi];
268 if (
mag(wp.first()) > VSMALL)
270 displacement[pointi] =
271 wp.second()/wp.first()
278 <<
" points inbetween refinement regions." 281 return tdisplacement;
288 const motionSmoother& meshMover,
289 const List<labelPair>& baffles
296 label nNonManifoldPoints = getCollocatedPoints
302 Info<<
"Found " << nNonManifoldPoints <<
" non-manifold point(s)." 322 const polyMesh&
mesh = meshMover.mesh();
330 label f0 = baffles[i].first();
331 label f1 = baffles[i].second();
333 if (isMasterFace.test(f0))
336 isMasterFace.unset(f1);
338 else if (isMasterFace.test(f1))
340 isMasterFace.unset(f0);
345 <<
"Both sides of baffle consisting of faces " << f0
346 <<
" and " << f1 <<
" are already slave faces." 356 Field<weightedPosition> avgBoundary
362 forAll(pointFaces, patchPointi)
368 label facei =
pFaces[pfi];
370 if (isMasterFace.test(
pp.addressing()[facei]))
372 avgBoundary[patchPointi].first() += 1.0;
373 avgBoundary[patchPointi].second() +=
386 if (
mag(avgBoundary[i].first()) > VSMALL)
388 avgBoundary[i].second() /= avgBoundary[i].first();
397 Field<weightedPosition> avgInternal;
399 Field<weightedPosition> globalSum
410 const face&
f = faces[facei];
415 weightedPosition& wp = globalSum[
f[fp]];
429 && refCast<const coupledPolyPatch>(
patches[patchi]).owner()
432 const coupledPolyPatch&
pp =
433 refCast<const coupledPolyPatch>(
patches[patchi]);
439 const face&
f =
pp[i];
440 const point& fc = faceCentres[i];
444 weightedPosition& wp = globalSum[
f[fp]];
455 avgInternal.setSize(meshPoints.size());
457 forAll(avgInternal, patchPointi)
459 label meshPointi = meshPoints[patchPointi];
460 const weightedPosition& wp = globalSum[meshPointi];
462 avgInternal[patchPointi].first() = wp.first();
463 if (
mag(wp.first()) < VSMALL)
466 avgInternal[patchPointi].second() = wp.second();
470 avgInternal[patchPointi].second() = wp.second()/wp.first();
487 anyCell[
f[fp]] = own;
493 tmp<pointField> tpatchDisp(
new pointField(meshPoints.size(),
Zero));
498 label meshPointi = meshPoints[i];
507 const weightedPosition&
internal = avgInternal[i];
508 const weightedPosition&
boundary = avgBoundary[i];
512 if (!nonManifoldPoint.test(i))
516 scalar internalBlend = 0.1;
521 internalBlend*
internal.first()*
internal.second()
525 internalBlend*
internal.first()
529 newPos = (1-blend)*avgPos + blend*currentPos;
531 else if (
internal.first() == 0)
539 scalar cellCBlend = 0.8;
542 point avgPos = (1-cellCBlend)*
boundary.second() + cellCBlend*cc;
544 newPos = (1-blend)*avgPos + blend*currentPos;
549 scalar internalBlend = 0.9;
553 internalBlend*
internal.second()
554 + (1-internalBlend)*
boundary.second();
556 newPos = (1-blend)*avgPos + blend*currentPos;
559 patchDisp[i] = newPos - currentPos;
629 const pointMesh& pMesh,
633 const polyMesh&
mesh = pMesh();
636 List<pointEdgePoint> wallInfo(
pp.
nPoints());
647 List<pointEdgePoint> allEdgeInfo(
mesh.
nEdges());
649 PointEdgeWave<pointEdgePoint> wallCalc
664 forAll(allEdgeInfo, edgei)
666 edgeDist[edgei] =
Foam::sqrt(allEdgeInfo[edgei].distSqr());
673 void Foam::snappySnapDriver::dumpMove
675 const fileName& fName,
681 Info<<
"Dumping move direction to " << fName <<
endl;
683 OFstream nearestStream(fName);
695 nearestStream<<
"l " << verti-1 <<
' ' << verti <<
nl;
702 bool Foam::snappySnapDriver::outwardsDisplacement
711 forAll(pointFaces, pointi)
715 vector disp(patchDisp[pointi]);
717 scalar magDisp =
mag(disp);
727 Warning<<
"Displacement " << patchDisp[pointi]
730 <<
" points through the surrounding patch faces" <<
endl;
743 void Foam::snappySnapDriver::freezeExposedPoints
745 const meshRefinement& meshRefiner,
752 const fvMesh&
mesh = meshRefiner.mesh();
758 const label pointZonei = pointZones.
findZoneID(pzName);
759 if (pointZonei != -1)
761 isFrozenPoint.set(pointZones[pointZonei]);
766 const label faceZonei = faceZones.
findZoneID(fzName);
771 UIndirectList<face>(
mesh.
faces(), faceZones[faceZonei]),
776 const labelList nEdgeFaces(meshRefiner.countEdgeFaces(
pp));
781 if (nEdgeFaces[edgei] != 1)
794 orEqOp<unsigned int>(),
798 for (
const label pointi : isFrozenPoint)
800 const auto iter = outside.meshPointMap().find(pointi);
803 outsideDisp[iter.val()] =
Zero;
811 Foam::snappySnapDriver::snappySnapDriver
819 meshRefiner_(meshRefiner),
820 globalToMasterPatch_(globalToMasterPatch),
821 globalToSlavePatch_(globalToSlavePatch),
841 forAll(pointEdges, pointi)
843 const labelList& pEdges = pointEdges[pointi];
847 const edge&
e = edges[pEdges[pEdgei]];
849 scalar len =
e.mag(localPoints);
851 maxEdgeLen[pointi] =
max(maxEdgeLen[pointi], len);
872 const label nInitErrors,
884 Info<<
"Smoothing patch and internal points ..." <<
endl;
888 Info<<
"Smoothing patch points ..." <<
endl;
895 label smoothIter = 0;
900 Info<<
"Smoothing iteration " << smoothIter <<
endl;
904 checkFaces[facei] = facei;
911 pointDisp = smoothInternalDisplacement(meshRefiner, meshMover);
915 pointField patchDisp(smoothPatchDisplacement(meshMover, baffles));
928 scalar oldErrorReduction = -1;
930 for (label snapIter = 0; snapIter < 2*snapParams.
nSnap(); snapIter++)
932 Info<<
nl <<
"Scaling iteration " << snapIter <<
endl;
934 if (snapIter == snapParams.
nSnap())
936 Info<<
"Displacement scaling for error reduction set to 0." 943 if (meshMover.
scaleMesh(checkFaces, baffles,
true, nInitErrors))
945 Info<<
"Successfully moved mesh" <<
endl;
950 if (oldErrorReduction >= 0)
964 Info<<
"Writing patch smoothed mesh to time " 976 Info<<
"Dumped mesh in = " 980 Info<<
"Patch points smoothed in = " 986 void Foam::snappySnapDriver::getZoneSurfacePoints
990 const word& zoneName,
1000 <<
"Cannot find zone " << zoneName
1016 label meshPointi =
f[fp];
1022 const label pointi = iter.
val();
1023 pointOnZone[pointi] =
true;
1038 Field<weightedPosition> avgBoundary
1044 forAll(pointFaces, pointi)
1048 avgBoundary[pointi].first() =
pFaces.size();
1051 label facei =
pFaces[pfi];
1060 tmp<pointField> tavgBoundary(
new pointField(avgBoundary.size()));
1063 return tavgBoundary;
1117 const scalar planarCos,
1125 Info<<
"Detecting near surfaces ..." <<
endl;
1414 forAll(localPoints, pointi)
1416 const point& pt = localPoints[pointi];
1417 const vector d = 2*(avgCc[pointi]-pt);
1418 start[pointi] = pt - d;
1419 end[pointi] = pt + d;
1431 /
"detectNearSurfaces_" + meshRefiner_.timeName() +
".obj" 1437 const bitSet isPatchMasterPoint
1446 label nOverride = 0;
1454 meshRefiner_.surfaces().surfZones()
1485 forAll(localPoints, pointi)
1488 const point& pt = localPoints[pointi];
1490 bool override =
false;
1529 if (hit1[pointi].hit() && hit2[pointi].hit())
1536 hit1[pointi].point(),
1538 hit2[pointi].point(),
1548 gapStr().writeLine(pt, hit2[pointi].
point());
1552 disp[pointi] = hit2[pointi].point()-pt;
1557 if (
override && isPatchMasterPoint[pointi])
1579 label zoneSurfi = zonedSurfaces[i];
1580 const labelList surfacesToTest(1, zoneSurfi);
1583 surfZones[zoneSurfi].faceZoneNames();
1584 forAll(faceZoneNames, namei)
1586 const word& faceZoneName = faceZoneNames[namei];
1590 getZoneSurfacePoints
1597 const labelList zonePointIndices(pointOnZone.toc());
1629 label pointi = zonePointIndices[i];
1632 const point& pt = localPoints[pointi];
1634 bool override =
false;
1673 if (hit1[i].hit() && hit2[i].hit())
1689 gapStr().writeLine(pt, hit2[i].
point());
1692 disp[pointi] = hit2[i].point()-pt;
1697 if (
override && isPatchMasterPoint[pointi])
1706 Info<<
"Overriding nearest with intersection of close gaps at " 1709 <<
" points." <<
endl;
1713 void Foam::snappySnapDriver::calcNearestSurface
1736 if (nearestNormal.
size() == localPoints.
size())
1756 if (hitInfo[i].hit())
1758 label pointi = zonePointIndices[i];
1759 nearestPoint[pointi] = hitInfo[i].point();
1760 nearestNormal[pointi] = hitNormal[i];
1781 if (hitInfo[i].hit())
1783 label pointi = zonePointIndices[i];
1785 patchDisp[pointi] = hitInfo[i].point() - localPoints[pointi];
1786 minSnapDist[pointi] =
mag(patchDisp[pointi]);
1787 snapSurf[pointi] = hitSurface[i];
1795 const bool strictRegionSnap,
1796 const meshRefinement& meshRefiner,
1805 Info<<
"Calculating patchDisplacement as distance to nearest surface" 1806 <<
" point ..." <<
endl;
1807 if (strictRegionSnap)
1809 Info<<
" non-zone points : attract to local region on surface only" 1811 <<
" zone points : attract to local region on surface only" 1817 Info<<
" non-zone points :" 1818 <<
" attract to nearest of all non-zone surfaces" 1820 <<
" zone points : attract to zone surface only" <<
nl 1826 const refinementSurfaces& surfaces = meshRefiner.
surfaces();
1827 const fvMesh&
mesh = meshRefiner.mesh();
1836 labelList snapSurf(localPoints.size(), -1);
1843 if (strictRegionSnap)
1847 forAll(surfaces.surfaces(), surfi)
1849 label geomi = surfaces.surfaces()[surfi];
1850 label nRegions = surfaces.geometry()[geomi].regions().size();
1852 const labelList surfacesToTest(1, surfi);
1854 for (label regioni = 0; regioni < nRegions; regioni++)
1856 label globali = surfaces.globalRegion(surfi, regioni);
1857 label masterPatchi = globalToMasterPatch[globali];
1888 if (globalToSlavePatch[globali] != masterPatchi)
1890 label slavePatchi = globalToSlavePatch[globali];
1930 meshRefiner.surfaces().surfZones()
1937 List<pointIndexHit> hitInfo;
1940 if (nearestNormal.size() == localPoints.size())
1944 surfaces.findNearestRegion
1957 if (hitInfo[pointi].hit())
1959 nearestPoint[pointi] = hitInfo[pointi].point();
1960 nearestNormal[pointi] = hitNormal[pointi];
1966 surfaces.findNearest
1978 if (hitInfo[pointi].hit())
1981 hitInfo[pointi].point()
1982 - localPoints[pointi];
1984 snapSurf[pointi] = hitSurface[pointi];
1991 meshRefiner.surfaces().surfZones()
2000 const PtrList<surfaceZonesInfo>& surfZones = surfaces.surfZones();
2004 label surfi = zonedSurfaces[i];
2005 const labelList surfacesToTest(1, surfi);
2006 const label geomi = surfaces.surfaces()[surfi];
2007 const label nRegions =
2008 surfaces.geometry()[geomi].regions().size();
2011 surfZones[surfi].faceZoneNames();
2015 forAll(faceZoneNames, locali)
2017 getZoneSurfacePoints
2021 faceZoneNames[locali],
2025 const labelList zonePointIndices(pointOnZone.toc());
2052 if (snapSurf[pointi] == -1)
2054 static label nWarn = 0;
2059 <<
"For point:" << pointi
2060 <<
" coordinate:" << localPoints[pointi]
2061 <<
" did not find any surface within:" 2062 << minSnapDist[pointi] <<
" metre." <<
endl;
2067 <<
"Reached warning limit " << nWarn
2068 <<
". Suppressing further warnings." <<
endl;
2075 const bitSet isPatchMasterPoint
2086 Info<<
"Wanted displacement : average:" 2088 <<
" min:" <<
gMin(magDisp)
2089 <<
" max:" <<
gMax(magDisp) <<
endl;
2093 Info<<
"Calculated surface displacement in = " 2099 forAll(patchDisp, patchPointi)
2101 scalar magDisp =
mag(patchDisp[patchPointi]);
2103 if (magDisp > snapDist[patchPointi])
2105 patchDisp[patchPointi] *= snapDist[patchPointi] / magDisp;
2107 Pout<<
"Limiting displacement for " << patchPointi
2108 <<
" from " << magDisp <<
" to " << snapDist[patchPointi]
2120 minMagSqrEqOp<point>(),
2121 vector(GREAT, GREAT, GREAT)
2139 const fvMesh&
mesh = meshRefiner_.mesh();
2142 Info<<
"Smoothing displacement ..." <<
endl;
2152 for (label iter = 0; iter < snapParams.
nSmoothDispl(); iter++)
2154 if ((iter % 10) == 0)
2156 Info<<
"Iteration " << iter <<
endl;
2159 meshMover.
smooth(oldDisp, edgeGamma, disp);
2161 Info<<
"Displacement smoothed in = " 2167 Info<<
"Writing smoothed mesh to time " << meshRefiner_.timeName()
2184 Info<<
"Writing displacement field ..." <<
endl;
2186 tmp<pointScalarField> magDisp(
mag(disp));
2189 Info<<
"Writing actual patch displacement ..." <<
endl;
2194 /
"actualPatchDisplacement_" + meshRefiner_.timeName() +
".obj",
2204 const snapParameters& snapParams,
2205 const label nInitErrors,
2206 const List<labelPair>& baffles,
2207 motionSmoother& meshMover
2211 const fvMesh&
mesh = meshRefiner_.mesh();
2217 scalar oldErrorReduction = -1;
2219 bool meshOk =
false;
2222 for (label iter = 0; iter < 2*snapParams.nSnap(); iter++)
2226 if (iter == snapParams.nSnap())
2228 Info<<
"Displacement scaling for error reduction set to 0." <<
endl;
2229 oldErrorReduction = meshMover.setErrorReduction(0.0);
2232 meshOk = meshMover.scaleMesh(checkFaces, baffles,
true, nInitErrors);
2236 Info<<
"Successfully moved mesh" <<
endl;
2242 Info<<
"Writing scaled mesh to time " << meshRefiner_.timeName()
2246 Info<<
"Writing displacement field ..." <<
endl;
2247 meshMover.displacement().
write();
2248 tmp<pointScalarField> magDisp(
mag(meshMover.displacement()));
2253 if (oldErrorReduction >= 0)
2255 meshMover.setErrorReduction(oldErrorReduction);
2257 Info<<
"Moved mesh in = " 2279 Info<<
"Repatching faces according to nearest surface ..." <<
endl;
2303 forAll(preserveFaces, facei)
2305 if (preserveFaces[facei] != -1)
2307 isZonedFace.set(facei);
2317 const label zoneSurfi = zonedSurfaces[i];
2318 const wordList& fZoneNames = surfZones[zoneSurfi].faceZoneNames();
2321 const faceZone& fZone = fZones[fZoneNames[i]];
2322 isZonedFace.
set(fZone);
2350 forAll(localFaces, facei)
2352 const face&
f = localFaces[facei];
2356 faceSnapDist[facei] =
max 2358 faceSnapDist[facei],
2382 label facei =
pp.addressing()[i];
2384 if (hitSurface[i] != -1 && !isZonedFace.test(facei))
2386 closestPatch[i] = globalToMasterPatch_
2413 ownPatch[
pp.start()+i] = patchi;
2414 neiPatch[
pp.start()+i] = patchi;
2421 label facei =
pp.addressing()[i];
2423 if (closestPatch[i] != -1 && closestPatch[i] != ownPatch[facei])
2425 ownPatch[facei] = closestPatch[i];
2426 neiPatch[facei] = closestPatch[i];
2435 return meshRefiner_.createBaffles(ownPatch, neiPatch);
2439 void Foam::snappySnapDriver::detectWarpedFaces
2441 const scalar featureCos,
2464 forAll(localFaces, facei)
2466 const face&
f = localFaces[facei];
2474 scalar minCos(GREAT);
2476 for (label startFp = 0; startFp <
f.
size()-2; startFp++)
2483 endFp <
f.
size() && endFp != minFp;
2488 f0.setSize(endFp-startFp+1);
2490 for (label fp = startFp; fp <= endFp; fp++)
2496 for (label fp = endFp; fp != startFp; fp =
f.
fcIndex(fp))
2500 f1[i1++] =
f[startFp];
2505 const vector n0 = f0.areaNormal(localPoints);
2506 const scalar n0Mag =
mag(n0);
2508 const vector n1 = f1.areaNormal(localPoints);
2509 const scalar n1Mag =
mag(n1);
2511 if (n0Mag > ROOTVSMALL && n1Mag > ROOTVSMALL)
2513 scalar cosAngle = (n0/n0Mag) & (n1/n1Mag);
2514 if (cosAngle < minCos)
2524 if (minCos < featureCos)
2526 splitFaces.
append(bFaces[facei]);
2534 Foam::labelList Foam::snappySnapDriver::getInternalOrBaffleDuplicateFace()
const 2536 const fvMesh&
mesh = meshRefiner_.mesh();
2540 List<surfaceZonesInfo::faceZoneType> fzTypes(2);
2543 internalOrBaffleFaceZones = meshRefiner_.getZones(fzTypes);
2546 List<labelPair> baffles
2548 meshRefiner_.subsetBaffles
2551 internalOrBaffleFaceZones,
2560 faceToDuplicate[
p[0]] =
p[1];
2561 faceToDuplicate[
p[1]] =
p[0];
2564 return faceToDuplicate;
2573 const scalar featureCos,
2574 const scalar planarAngle,
2582 <<
"Morphing phase" <<
nl 2583 <<
"--------------" <<
nl 2622 meshRefiner_.getZones
2638 meshRefiner_.createZoneBaffles
2647 meshRefiner_.dupNonManifoldBoundaryPoints();
2650 bool doFeatures =
false;
2651 label nFeatIter = 1;
2661 Info<<
"Snapping to features in " << nFeatIter
2662 <<
" iterations ..." <<
endl;
2666 bool meshOk =
false;
2670 labelList adaptPatchIDs(meshRefiner_.meshedPatches());
2675 autoPtr<indirectPrimitivePatch> ppPtr
2690 Info<<
"Constructing mesh displacer ..." <<
endl;
2691 Info<<
"Using mesh parameters " << motionDict <<
nl <<
endl;
2693 autoPtr<motionSmoother> meshMoverPtr
2712 Info<<
"Checking initial mesh ..." <<
endl;
2721 Info<<
"Detected " << nInitErrors <<
" illegal faces" 2722 <<
" (concave, zero area or negative cell pyramid volume)" 2726 Info<<
"Checked initial mesh in = " 2733 meshRefiner_.subsetBaffles
2760 List<pointConstraint> patchConstraints;
2764 DynamicList<label> splitFaces;
2766 DynamicList<labelPair> splits;
2769 for (label iter = 0; iter < nFeatIter; iter++)
2772 <<
"Morph iteration " << iter <<
nl 2773 <<
"-----------------" <<
endl;
2776 bool doSplit =
false;
2782 (iter == nFeatIter-1)
2793 motionSmoother& meshMover = meshMoverPtr();
2812 globalToMasterPatch_,
2813 globalToSlavePatch_,
2841 disp = calcNearestSurfaceFeature
2847 scalar(iter+1)/nFeatIter,
2863 outwardsDisplacement(
pp, disp);
2878 meshMover.setDisplacement(disp);
2886 /
"patchDisplacement_" +
name(iter) +
".obj",
2893 smoothDisplacement(snapParams, meshMover);
2907 <<
"Did not successfully snap mesh." 2908 <<
" Continuing to snap to resolve easy" <<
nl 2909 <<
" surfaces but the" 2910 <<
" resulting mesh will not satisfy your quality" 2911 <<
" constraints" <<
nl <<
endl;
2917 Info<<
"Writing scaled mesh to time " 2918 << meshRefiner_.timeName() <<
endl;
2929 Info<<
"Writing displacement field ..." <<
endl;
2930 meshMover.displacement().
write();
2931 tmp<pointScalarField> magDisp
2933 mag(meshMover.displacement())
2939 meshMover.correct();
2944 label nTotalSplit =
returnReduce(splitFaces.size(), sumOp<label>());
2945 if (nTotalSplit && doSplit)
2950 labelList duplicateFace(getInternalOrBaffleDuplicateFace());
2953 labelList oldSplitFaces(std::move(splitFaces));
2954 List<labelPair> oldSplits(std::move(splits));
2957 if (duplicateFace[oldSplitFaces[i]] == -1)
2959 splitFaces.append(oldSplitFaces[i]);
2960 splits.append(oldSplits[i]);
2971 meshRefiner_.splitFacesUndo
2982 meshMoverPtr.clear();
3005 snapDist = calcSnapDistance(
mesh, snapParams, ppPtr());
3011 Info<<
"Writing split-faces mesh to time " 3012 << meshRefiner_.timeName() <<
endl;
3029 forAll(internalBaffles, i)
3035 if (
mag(fc0-fc1) > meshRefiner_.mergeDistance())
3038 <<
"Separated baffles : f0:" <<
p[0]
3039 <<
" centre:" << fc0
3040 <<
" f1:" <<
p[1] <<
" centre:" << fc1
3041 <<
" distance:" <<
mag(fc0-fc1)
3052 autoPtr<mapPolyMesh> mapPtr = meshRefiner_.mergeZoneBaffles
3063 Info<<
"Writing baffle-merged mesh to time " 3064 << meshRefiner_.timeName() <<
endl;
3073 meshRefiner_.timeName()
3081 labelList duplicateFace(getInternalOrBaffleDuplicateFace());
3083 repatchToSurface(snapParams, adaptPatchIDs, duplicateFace);
3088 mergeType == meshRefinement::FaceMergeType::GEOMETRIC
3089 || mergeType == meshRefinement::FaceMergeType::IGNOREPATCH
3092 labelList duplicateFace(getInternalOrBaffleDuplicateFace());
3097 label nChanged = meshRefiner_.mergePatchFacesUndo
3101 meshRefiner_.meshedPatches(),
3107 nChanged += meshRefiner_.mergeEdgesUndo(featureCos, motionDict);
3112 Info<<
"Writing patchFace merged mesh to time " 3113 << meshRefiner_.timeName() <<
endl;
3122 meshRefiner_.timeName()
Given a displacement moves the mesh by scaling the displacement back until there are no more mesh err...
const labelListList & pointEdges() const
Return point-edge addressing.
Switch detectNearSurfacesSnap() const
Override attraction to nearest with intersection location.
static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces, const bool dryRun=false)
Check mesh with mesh settings in dict. Collects incorrect faces.
label nPoints() const
Number of points supporting patch faces.
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
reference val() const
Const access to referenced object (value)
void size(const label n)
Older name for setAddressableSize.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
fileName path() const
Return path.
label nSmoothDispl() const
Number of mesh displacement smoothing iterations.
const labelList & surfaces() const
bool scaleMesh(const snapParameters &snapParams, const label nInitErrors, const List< labelPair > &baffles, motionSmoother &)
Do the hard work: move the mesh according to displacement,.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const Field< point_type > & localPoints() const
Return pointField of points in patch.
label nPoints() const noexcept
Number of mesh points.
void doSnap(const dictionary &snapDict, const dictionary &motionDict, const meshRefinement::FaceMergeType mergeType, const scalar featureCos, const scalar planarAngle, const snapParameters &snapParams)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Type gMin(const FieldField< Field, Type > &f)
virtual const labelList & faceNeighbour() const
Return face neighbour.
static const weightedPosition zero
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Unit conversion functions.
bool scaleMesh(labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
constexpr char nl
The newline '\n' character (0x0a)
const pointMesh & pMesh() const
Reference to pointMesh.
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
label nSmoothPatch() const
Number of patch smoothing iterations before finding.
void detectNearSurfaces(const scalar planarCos, const indirectPrimitivePatch &, const pointField &nearestPoint, const vectorField &nearestNormal, vectorField &disp) const
Per patch point override displacement if in gap situation.
T & first()
Access first element of the list, position [0].
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static writeType writeLevel()
Get/set write level.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
void setCapacity(const label len)
Alter the size of the underlying storage.
List< labelPair > labelPairList
List of labelPair.
static void getPoints(const UList< weightedPosition > &in, List< point > &out)
Get points.
const Time & time() const
Return the top-level database.
label nFaces() const noexcept
Number of mesh faces.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
List< labelList > labelListList
List of labelList.
void findNearest(const labelList &surfacesToTest, const pointField &samples, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &) const
Find nearest point on surfaces.
label nFeatureSnap() const
const labelList & meshPoints() const
Return labelList of mesh points in patch.
void smooth(volScalarField &field, const scalar coeff)
const fvMesh & mesh() const
Reference to mesh.
static labelPairList findDuplicateFacePairs(const polyMesh &)
Helper routine to find all baffles (two boundary faces.
label nTotalPoints() const noexcept
Return total number of points in decomposed mesh. Not compensated for duplicate points! ...
Container for data on surfaces used for surface-driven refinement. Contains all the data about the le...
virtual const pointField & points() const
Return raw points.
#define forAll(list, i)
Loop across all elements in list.
void correct()
Take over existing mesh position.
label fcIndex(const label i) const noexcept
The forward circular index. The next index in the list which returns to the first at the end of the l...
label mergePoints(const PointList &points, labelList &pointToUnique, labelList &uniquePoints, const scalar mergeTol=SMALL, const bool verbose=false)
Calculate merge mapping, preserving the original point order. All points closer/equal mergeTol are to...
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
List< face > faceList
List of faces.
A list of faces which address into the list of points.
const Map< label > & meshPointMap() const
Mesh point map.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
FaceMergeType
Enumeration for what to do with co-planar patch faces on a single.
dimensionedScalar cos(const dimensionedScalar &ds)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
void findNearestRegion(const labelList &surfacesToTest, const pointField &samples, const scalarField &nearestDistSqr, labelList &hitSurface, labelList &hitRegion) const
Find nearest point on surfaces. Return surface and region on.
label nFaceSplitInterval() const
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Simple container to keep together snap specific information.
autoPtr< mapPolyMesh > repatchToSurface(const snapParameters &snapParams, const labelList &adaptPatchIDs, const labelList &preserveFaces)
Repatch faces according to surface nearest the face centre.
label size() const noexcept
The number of entries in the list.
const Field< point_type > & faceCentres() const
Return face centres for patch.
virtual const labelList & faceOwner() const
Return face owner.
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
void smoothDisplacement(const snapParameters &snapParams, motionSmoother &) const
Smooth the displacement field to the internal.
const globalMeshData & globalData() const
Return parallel info.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
static void preSmoothPatch(const meshRefinement &meshRefiner, const snapParameters &snapParams, const label nInitErrors, const List< labelPair > &baffles, motionSmoother &)
Smooth the mesh (patch and internal) to increase visibility.
label nInternalFaces() const noexcept
Number of internal faces.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
const Field< point_type > & points() const noexcept
Return reference to global points.
void append(const T &val)
Copy append an element to the end of this list.
virtual const faceList & faces() const
Return raw faces.
const PtrList< surfaceZonesInfo > & surfZones() const
const vectorField & cellCentres() const
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
errorManip< error > abort(error &err)
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
label nEdges() const
Number of mesh edges.
const labelListList & pointCells() const
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
void smooth(const GeometricField< Type, pointPatchField, pointMesh > &fld, const scalarField &edgeWeight, GeometricField< Type, pointPatchField, pointMesh > &newFld) const
Fully explicit smoothing of fields (not positions)
word timeName() const
Replacement for Time::timeName() that returns oldInstance (if overwrite_)
static scalarField calcSnapDistance(const fvMesh &mesh, const snapParameters &snapParams, const indirectPrimitivePatch &)
Calculate edge length per patch point.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
const labelListList & pointFaces() const
Return point-face addressing.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
int debug
Static debugging option.
Pair< label > labelPair
A pair of labels.
Type gMax(const FieldField< Field, Type > &f)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
defineTypeNameAndDebug(combustionModel, 0)
const indirectPrimitivePatch & patch() const
Reference to patch.
static tmp< pointField > avgCellCentres(const fvMesh &mesh, const indirectPrimitivePatch &)
Helper: calculate average cell centre per point.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Geometric merging of points. See below.
static autoPtr< indirectPrimitivePatch > makePatch(const polyMesh &, const labelList &)
Create patch from set of patches.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text...
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
pointVectorField & pointDisplacement()
Return reference to the point motion displacement field.
const vectorField & faceCentres() const
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
List< word > wordList
List of word.
label nSnap() const
Maximum number of snapping relaxation iterations. Should stop.
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
scalar snapTol() const
Relative distance for points to be attracted by surface.
vector point
Point is a vector.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
#define WarningInFunction
Report a warning using Foam::Warning.
Switch strictRegionSnap() const
Attract point to corresponding surface region only.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
static bitSet getMasterPoints(const polyMesh &mesh, const labelList &meshPoints)
Determine master point for subset of points. If coupled.
Mesh data needed to do the Finite Volume discretisation.
const polyBoundaryMesh & patches
label globalRegion(const label surfI, const label regionI) const
From surface and region on surface to global region.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
label nTotalFaces() const noexcept
Return total number of faces in decomposed mesh. Not compensated for duplicate faces! ...
SubField< vector > subField
Declare type of subField.
writeType
Enumeration for what to write. Used as a bit-pattern.
Field< vector > vectorField
Specialisation of Field<T> for vector.
debugType
Enumeration for what to debug. Used as a bit-pattern.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
A subset of mesh faces organised as a primitive patch.
static void syncPoints(const polyMesh &mesh, List< weightedPosition > &)
Synchronisation for mesh point positions.
bool write() const
Write mesh and all data.
List< label > labelList
A List of labels.
static tmp< pointVectorField > makeDisplacementField(const pointMesh &pMesh, const labelList &adaptPatchIDs)
Helper function to make a pointVectorField with correct.
A class for managing temporary objects.
label nSmoothInternal() const
Number of internal point smoothing iterations (combined with.
A patch is a list of labels that address the faces in the global face list.
static T gAverage(const bitSet &isMasterElem, const UList< T > &values)
Helper: calculate average.
void findNearestIntersection(const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surface1, List< pointIndexHit > &hit1, labelList ®ion1, labelList &surface2, List< pointIndexHit > &hit2, labelList ®ion2) const
Find intersection nearest to the endpoints. surface1,2 are.
label rcIndex(const label i) const noexcept
The reverse circular index. The previous index in the list which returns to the last at the beginning...
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
pointVectorField & displacement()
Reference to displacement field.
static constexpr const zero Zero
Global zero (0)