diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index fdf89f4123b23c22d5e092eedb01e906ace6c6aa..f24117e15f7e81cc2062e1f29c7124c4c5d37e92 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -218,7 +218,8 @@ Foam::label Foam::autoSnapDriver::getCollocatedPoints // Calculate displacement as average of patch points. Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement ( - const motionSmoother& meshMover + const motionSmoother& meshMover, + const List<labelPair>& baffles ) const { const indirectPrimitivePatch& pp = meshMover.patch(); @@ -253,6 +254,34 @@ Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement const pointField& points = pp.points(); const polyMesh& mesh = meshMover.mesh(); + // Get labels of faces to count (master of coupled faces and baffle pairs) + PackedList<1> isMasterFace(syncTools::getMasterFaces(mesh)); + + { + forAll(baffles, i) + { + label f0 = baffles[i].first(); + label f1 = baffles[i].second(); + + if (isMasterFace.get(f0) == 1) + { + // Make f1 a slave + isMasterFace.set(f1, 0); + } + else if (isMasterFace.get(f1) == 1) + { + isMasterFace.set(f0, 0); + } + else + { + FatalErrorIn("autoSnapDriver::smoothPatchDisplacement(..)") + << "Both sides of baffle consisting of faces " << f0 + << " and " << f1 << " are already slave faces." + << abort(FatalError); + } + } + } + // Get average position of boundary face centres // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -266,9 +295,14 @@ Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement forAll(pFaces, pfI) { - avgBoundary[patchPointI] += pp[pFaces[pfI]].centre(points); + label faceI = pFaces[pfI]; + + if (isMasterFace.get(pp.addressing()[faceI]) == 1) + { + avgBoundary[patchPointI] += pp[faceI].centre(points); + nBoundary[patchPointI]++; + } } - nBoundary[patchPointI] = pFaces.size(); } syncTools::syncPointList @@ -886,7 +920,7 @@ void Foam::autoSnapDriver::preSmoothPatch checkFaces[faceI] = faceI; } - pointField patchDisp(smoothPatchDisplacement(meshMover)); + pointField patchDisp(smoothPatchDisplacement(meshMover, baffles)); // The current mesh is the starting mesh to smooth from. meshMover.setDisplacement(patchDisp); @@ -1008,9 +1042,11 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface // Displacement per patch point vectorField patchDisp(localPoints.size(), vector::zero); - if (returnReduce(localPoints.size(), sumOp<label>()) > 0) { + // Current surface snapped to + labelList snapSurf(localPoints.size(), -1); + // Divide surfaces into zoned and unzoned labelList zonedSurfaces; labelList unzonedSurfaces; @@ -1039,16 +1075,9 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface patchDisp[pointI] = hitInfo[pointI].hitPoint() - localPoints[pointI]; + + snapSurf[pointI] = hitSurface[pointI]; } - //else - //{ - // WarningIn("autoSnapDriver::calcNearestSurface(..)") - // << "For point:" << pointI - // << " coordinate:" << localPoints[pointI] - // << " did not find any surface within:" - // << 4*snapDist[pointI] - // << " meter." << endl; - //} } } @@ -1060,6 +1089,7 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface // Surfaces with zone information const wordList& faceZoneNames = surfaces.faceZoneNames(); + // Current best snap distance scalarField minSnapDist(snapDist); forAll(zonedSurfaces, i) @@ -1105,19 +1135,25 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface minSnapDist[pointI], mag(patchDisp[pointI]) ); - } - else - { - WarningIn("autoSnapDriver::calcNearestSurface(..)") - << "For point:" << pointI - << " coordinate:" << localPoints[pointI] - << " did not find any surface within:" - << 4*minSnapDist[pointI] - << " meter." << endl; + + snapSurf[pointI] = zoneSurfI; } } } + // Check if all points are being snapped + forAll(snapSurf, pointI) + { + if (snapSurf[pointI] == -1) + { + WarningIn("autoSnapDriver::calcNearestSurface(..)") + << "For point:" << pointI + << " coordinate:" << localPoints[pointI] + << " did not find any surface within:" + << minSnapDist[pointI] + << " meter." << endl; + } + } { scalarField magDisp(mag(patchDisp)); diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H index 1604e358593d6bab3969820c9a5af5ee2b8b36f0..dc19397243da4556b9833a7c263ffbe0c3446f17 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H @@ -100,7 +100,11 @@ class autoSnapDriver //- Calculate displacement per patch point to smooth out patch. // Quite complicated in determining which points to move where. - pointField smoothPatchDisplacement(const motionSmoother&) const; + pointField smoothPatchDisplacement + ( + const motionSmoother&, + const List<labelPair>& + ) const; //- Check that face zones are synced void checkCoupledFaceZones() const;