From 725a1b3eb03759fefbd2fceae1a3b68edb19b4fd Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 26 Oct 2012 16:47:04 +0100 Subject: [PATCH] BUG: snappyHexMesh: multi-patch from surrounding regions, not raw patchIDs --- .../autoHexMeshDriver/autoSnapDriver.C | 11 +- .../autoHexMeshDriver/autoSnapDriver.H | 26 +- .../autoHexMeshDriver/autoSnapDriverFeature.C | 510 +++++++++--------- .../snapParameters/snapParameters.C | 6 +- .../snapParameters/snapParameters.H | 7 + 5 files changed, 283 insertions(+), 277 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index e358ba4ffa..54a78f477c 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -1406,9 +1406,10 @@ void Foam::autoSnapDriver::doSnap adaptPatchIDs ) ); + indirectPrimitivePatch& pp = ppPtr(); // Distance to attract to nearest feature on surface - const scalarField snapDist(calcSnapDistance(snapParams, ppPtr())); + const scalarField snapDist(calcSnapDistance(snapParams, pp)); // Construct iterative mesh mover. @@ -1420,7 +1421,7 @@ void Foam::autoSnapDriver::doSnap motionSmoother meshMover ( mesh, - ppPtr(), + pp, adaptPatchIDs, meshRefinement::makeDisplacementField(pMesh, adaptPatchIDs), motionDict @@ -1475,7 +1476,7 @@ void Foam::autoSnapDriver::doSnap } // Check for displacement being outwards. - outwardsDisplacement(ppPtr(), disp); + outwardsDisplacement(pp, disp); // Set initial distribution of displacement field (on patches) // from patchDisp and make displacement consistent with b.c. @@ -1489,8 +1490,8 @@ void Foam::autoSnapDriver::doSnap ( mesh.time().path() / "patchDisplacement_" + name(iter) + ".obj", - ppPtr().localPoints(), - ppPtr().localPoints() + disp + pp.localPoints(), + pp.localPoints() + disp ); } diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H index bd5dd86188..7cf1e79f61 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.H @@ -141,14 +141,6 @@ class autoSnapDriver vectorField& pointSurfaceNormal, vectorField& pointRotation ) const; - //void calcNearestFace - //( - // const label iter, - // const indirectPrimitivePatch& pp, - // vectorField& faceDisp, - // vectorField& faceSurfaceNormal, - // vectorField& faceRotation - //) const; void calcNearestFace ( const label iter, @@ -158,15 +150,19 @@ class autoSnapDriver labelList& faceSurfaceRegion, vectorField& faceRotation ) const; - void interpolateFaceToPoint + void calcNearestFacePointProperties ( const label iter, const indirectPrimitivePatch& pp, - const List >& pointFaceDisp, - const List >& pointFaceRotation, - const List >& pointFaceCentres, - vectorField& patchDisp - //vectorField& patchRotationDisp + + const vectorField& faceDisp, + const vectorField& faceSurfaceNormal, + const labelList& faceSurfaceRegion, + + List >& pointFaceSurfNormals, + List >& pointFaceDisp, + List >& pointFaceCentres, + List& pointFacePatchID ) const; void correctAttraction ( @@ -276,6 +272,7 @@ class autoSnapDriver ( const label iter, const scalar featureCos, + const bool multiRegionFeatureSnap, const indirectPrimitivePatch&, const scalarField&, @@ -339,6 +336,7 @@ class autoSnapDriver ( const label iter, const scalar featureCos, + const bool multiRegionFeatureSnap, const indirectPrimitivePatch& pp, const scalarField& snapDist, diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C index 8bcd9c6270..f32d9ce4bd 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C @@ -321,7 +321,7 @@ void Foam::autoSnapDriver::calcNearestFace const indirectPrimitivePatch& pp, vectorField& faceDisp, vectorField& faceSurfaceNormal, - labelList& faceSurfaceRegion, + labelList& faceSurfaceGlobalRegion, vectorField& faceRotation ) const { @@ -333,8 +333,8 @@ void Foam::autoSnapDriver::calcNearestFace faceDisp = vector::zero; faceSurfaceNormal.setSize(pp.size()); faceSurfaceNormal = vector::zero; - faceSurfaceRegion.setSize(pp.size()); - faceSurfaceRegion = -1; + faceSurfaceGlobalRegion.setSize(pp.size()); + faceSurfaceGlobalRegion = -1; // Divide surfaces into zoned and unzoned labelList zonedSurfaces = surfaces.getNamedSurfaces(); @@ -419,7 +419,7 @@ void Foam::autoSnapDriver::calcNearestFace label faceI = ppFaces[hitI]; faceDisp[faceI] = hitInfo[hitI].hitPoint() - fc[hitI]; faceSurfaceNormal[faceI] = hitNormal[hitI]; - faceSurfaceRegion[faceI] = surfaces.globalRegion + faceSurfaceGlobalRegion[faceI] = surfaces.globalRegion ( hitSurface[hitI], hitRegion[hitI] @@ -477,7 +477,11 @@ void Foam::autoSnapDriver::calcNearestFace label faceI = ppFaces[hitI]; faceDisp[faceI] = hitInfo[hitI].hitPoint() - fc[hitI]; faceSurfaceNormal[faceI] = hitNormal[hitI]; - faceSurfaceRegion[faceI] = hitRegion[hitI]; + faceSurfaceGlobalRegion[faceI] = surfaces.globalRegion + ( + hitSurface[hitI], + hitRegion[hitI] + ); } } @@ -517,6 +521,169 @@ void Foam::autoSnapDriver::calcNearestFace } +// Collect (possibly remote) per point data of all surrounding faces +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// - faceSurfaceNormal +// - faceDisp +// - faceCentres&faceNormal +void Foam::autoSnapDriver::calcNearestFacePointProperties +( + const label iter, + const indirectPrimitivePatch& pp, + + const vectorField& faceDisp, + const vectorField& faceSurfaceNormal, + const labelList& faceSurfaceGlobalRegion, + + List >& pointFaceSurfNormals, + List >& pointFaceDisp, + List >& pointFaceCentres, + List& pointFacePatchID +) const +{ + const fvMesh& mesh = meshRefiner_.mesh(); + + // For now just get all surrounding face data. Expensive - should just + // store and sync data on coupled points only + // (see e.g PatchToolsNormals.C) + + pointFaceSurfNormals.setSize(pp.nPoints()); + pointFaceDisp.setSize(pp.nPoints()); + pointFaceCentres.setSize(pp.nPoints()); + pointFacePatchID.setSize(pp.nPoints()); + + // Fill local data + forAll(pp.pointFaces(), pointI) + { + const labelList& pFaces = pp.pointFaces()[pointI]; + List& pNormals = pointFaceSurfNormals[pointI]; + pNormals.setSize(pFaces.size()); + List& pDisp = pointFaceDisp[pointI]; + pDisp.setSize(pFaces.size()); + List& pFc = pointFaceCentres[pointI]; + pFc.setSize(pFaces.size()); + labelList& pFid = pointFacePatchID[pointI]; + pFid.setSize(pFaces.size()); + + forAll(pFaces, i) + { + label faceI = pFaces[i]; + pNormals[i] = faceSurfaceNormal[faceI]; + pDisp[i] = faceDisp[faceI]; + pFc[i] = pp.faceCentres()[faceI]; + //label meshFaceI = pp.addressing()[faceI]; + //pFid[i] = mesh.boundaryMesh().whichPatch(meshFaceI); + pFid[i] = globalToPatch_[faceSurfaceGlobalRegion[faceI]]; + } + } + + + // Collect additionally 'normal' boundary faces for boundaryPoints of pp + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // points on the boundary of pp should pick up non-pp normals + // as well for the feature-reconstruction to behave correctly. + // (the movement is already constrained outside correctly so it + // is only that the unconstrained attraction vector is calculated + // correctly) + { + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); + labelList patchID(pbm.patchID()); + + // Unmark all non-coupled boundary faces + forAll(pbm, patchI) + { + const polyPatch& pp = pbm[patchI]; + + if (pp.coupled() || isA(pp)) + { + forAll(pp, i) + { + label meshFaceI = pp.start()+i; + patchID[meshFaceI-mesh.nInternalFaces()] = -1; + } + } + } + + // Remove any meshed faces + forAll(pp.addressing(), i) + { + label meshFaceI = pp.addressing()[i]; + patchID[meshFaceI-mesh.nInternalFaces()] = -1; + } + + // See if pp point uses any non-meshed boundary faces + + const labelList& boundaryPoints = pp.boundaryPoints(); + forAll(boundaryPoints, i) + { + label pointI = boundaryPoints[i]; + label meshPointI = pp.meshPoints()[pointI]; + const point& pt = mesh.points()[meshPointI]; + const labelList& pFaces = mesh.pointFaces()[meshPointI]; + + List& pNormals = pointFaceSurfNormals[pointI]; + List& pDisp = pointFaceDisp[pointI]; + List& pFc = pointFaceCentres[pointI]; + labelList& pFid = pointFacePatchID[pointI]; + + forAll(pFaces, i) + { + label meshFaceI = pFaces[i]; + if (!mesh.isInternalFace(meshFaceI)) + { + label patchI = patchID[meshFaceI-mesh.nInternalFaces()]; + + if (patchI != -1) + { + vector fn = mesh.faceAreas()[meshFaceI]; + pNormals.append(fn/mag(fn)); + pDisp.append(mesh.faceCentres()[meshFaceI]-pt); + pFc.append(mesh.faceCentres()[meshFaceI]); + pFid.append(patchI); + } + } + } + } + } + + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceSurfNormals, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceDisp, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFaceCentres, + listPlusEqOp(), + List(), + listTransform() + ); + syncTools::syncPointList + ( + mesh, + pp.meshPoints(), + pointFacePatchID, + listPlusEqOp