diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index 3787156a53..6c1925f064 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -722,10 +722,15 @@ void Foam::autoSnapDriver::preSmoothPatch if (debug) { const_cast(mesh.time())++; - Pout<< "Writing patch smoothed mesh to time " << meshRefiner_.timeName() - << endl; - - mesh.write(); + Pout<< "Writing patch smoothed mesh to time " + << meshRefiner_.timeName() << '.' << endl; + meshRefiner_.write + ( + debug, + mesh.time().path()/meshRefiner_.timeName() + ); + Pout<< "Dumped mesh in = " + << mesh.time().cpuTimeIncrement() << " s\n" << nl << endl; } Info<< "Patch points smoothed in = " @@ -956,25 +961,6 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface vector(GREAT, GREAT, GREAT) // null value (note: cannot use VGREAT) ); - - // Check for displacement being outwards. - outwardsDisplacement(pp, patchDisp); - - // Set initial distribution of displacement field (on patches) from - // patchDisp and make displacement consistent with b.c. on displacement - // pointVectorField. - meshMover.setDisplacement(patchDisp); - - if (debug) - { - dumpMove - ( - mesh.time().path()/"patchDisplacement.obj", - pp.localPoints(), - pp.localPoints() + patchDisp - ); - } - return patchDisp; } @@ -1128,8 +1114,8 @@ Foam::autoPtr Foam::autoSnapDriver::repatchToSurface indirectPrimitivePatch& pp = ppPtr(); // Divide surfaces into zoned and unzoned - labelList zonedSurfaces = meshRefiner_.surfaces().getNamedSurfaces(); - labelList unzonedSurfaces = meshRefiner_.surfaces().getUnnamedSurfaces(); + labelList zonedSurfaces = surfaces.getNamedSurfaces(); + labelList unzonedSurfaces = surfaces.getUnnamedSurfaces(); // Faces that do not move @@ -1344,19 +1330,6 @@ void Foam::autoSnapDriver::doSnap // Pre-smooth patch vertices (so before determining nearest) preSmoothPatch(snapParams, nInitErrors, baffles, meshMover); - if (debug) - { - Pout<< "Writing patch smoothed mesh to time " - << meshRefiner_.timeName() << '.' << endl; - meshRefiner_.write - ( - debug, - mesh.time().path()/meshRefiner_.timeName() - ); - Pout<< "Dumped mesh in = " - << mesh.time().cpuTimeIncrement() << " s\n" << nl << endl; - } - for (label iter = 0; iter < nFeatIter; iter++) { @@ -1382,6 +1355,15 @@ void Foam::autoSnapDriver::doSnap ); } + // Check for displacement being outwards. + outwardsDisplacement(ppPtr(), disp); + + // Set initial distribution of displacement field (on patches) + // from patchDisp and make displacement consistent with b.c. + // on displacement pointVectorField. + meshMover.setDisplacement(disp); + + if (debug&meshRefinement::OBJINTERSECTIONS) { dumpMove @@ -1467,7 +1449,7 @@ void Foam::autoSnapDriver::doSnap meshRefiner_.write ( debug, - mesh.time().path()/meshRefiner_.timeName() + meshRefiner_.timeName() ); } } diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H index 4b0e1a30fd..59cd772a98 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H @@ -117,12 +117,12 @@ class autoSnapDriver const List& constraints, vectorField& disp ) const; - void calcNearest - ( - const pointField& points, - vectorField& disp, - vectorField& surfaceNormal - ) const; + //void calcNearest + //( + // const pointField& points, + // vectorField& disp, + // vectorField& surfaceNormal + //) const; void calcNearestFace ( const label iter, diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C index cc73efbe51..0227234822 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C @@ -135,63 +135,6 @@ void Foam::autoSnapDriver::smoothAndConstrain } -void Foam::autoSnapDriver::calcNearest -( - const pointField& points, - vectorField& disp, - vectorField& surfaceNormal -) const -{ - const refinementSurfaces& surfaces = meshRefiner_.surfaces(); - - // Displacement and orientation per pp face. - disp.setSize(points.size()); - disp = vector::zero; - surfaceNormal.setSize(points.size()); - surfaceNormal = vector::zero; - - { - // Divide surfaces into zoned and unzoned - labelList zonedSurfaces = - meshRefiner_.surfaces().getNamedSurfaces(); - labelList unzonedSurfaces = - meshRefiner_.surfaces().getUnnamedSurfaces(); - - { - List hitInfo; - labelList hitSurface; - labelList hitRegion; - surfaces.findNearestRegion - ( - unzonedSurfaces, - points, - sqr(scalarField(points.size(), GREAT)),// sqr of attract dist - hitSurface, - hitInfo, - hitRegion, - surfaceNormal - ); - - forAll(hitInfo, i) - { - if (hitInfo[i].hit()) - { - disp[i] = - hitInfo[i].hitPoint() - - points[i]; - } - else - { - WarningIn("calcNearest(..)") - << "Did not hit anything from face:" << i - << " at:" << points[i] << endl; - } - } - } - } -} - - void Foam::autoSnapDriver::calcNearestFace ( const label iter, @@ -202,6 +145,7 @@ void Foam::autoSnapDriver::calcNearestFace ) const { const fvMesh& mesh = meshRefiner_.mesh(); + const refinementSurfaces& surfaces = meshRefiner_.surfaces(); // Displacement and orientation per pp face. faceDisp.setSize(pp.size()); @@ -209,7 +153,148 @@ void Foam::autoSnapDriver::calcNearestFace faceSurfaceNormal.setSize(pp.size()); faceSurfaceNormal = vector::zero; - calcNearest(pp.faceCentres(), faceDisp, faceSurfaceNormal); + // Divide surfaces into zoned and unzoned + labelList zonedSurfaces = surfaces.getNamedSurfaces(); + labelList unzonedSurfaces = surfaces.getUnnamedSurfaces(); + + // Per pp face the current surface snapped to + labelList snapSurf(pp.size(), -1); + + + // Do zoned surfaces + // ~~~~~~~~~~~~~~~~~ + // Zoned faces only attract to corresponding surface + + // Extract faces per zone + const wordList& faceZoneNames = surfaces.faceZoneNames(); + + forAll(zonedSurfaces, i) + { + label zoneSurfI = zonedSurfaces[i]; + + // Get indices of faces on pp that are also in zone + label zoneI = mesh.faceZones().findZoneID(faceZoneNames[zoneSurfI]); + if (zoneI == -1) + { + FatalErrorIn + ( + "autoSnapDriver::calcNearestFace(..)" + ) << "Problem. Cannot find zone " << faceZoneNames[zoneSurfI] + << exit(FatalError); + } + const faceZone& fZone = mesh.faceZones()[zoneI]; + PackedBoolList isZonedFace(mesh.nFaces()); + forAll(fZone, i) + { + isZonedFace[fZone[i]] = 1; + } + + DynamicList