diff --git a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C index 3c3edde47d70c5667dc7d0de676ef669ad9ee965..79efcbc1be1223b12a34585ca44020e465bb0355 100644 --- a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C +++ b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -1484,12 +1484,13 @@ void Foam::faceCoupleInfo::perfectPointMatch // Faces do not have to be ordered (but all have // to match). Note: Faces will be already ordered if we enter here from // construct from meshes. + matchedAllFaces = matchPoints ( calcFaceCentres<List> ( cutFaces(), - cutPoints_, + cutFaces().points(), 0, cutFaces().size() ), @@ -1501,9 +1502,43 @@ void Foam::faceCoupleInfo::perfectPointMatch slavePatch().size() ), scalarField(slavePatch().size(), absTol), - true, + false, cutToSlaveFaces_ ); + + // If some of the face centres did not match, then try to match the + // point averages instead. There is no division by the face area in + // calculating the point average, so this is more stable when faces + // collapse onto a line or point. + if (!matchedAllFaces) + { + labelList cutToSlaveFacesTemp(cutToSlaveFaces_.size(), -1); + + matchPoints + ( + calcFacePointAverages<List> + ( + cutFaces(), + cutFaces().points(), + 0, + cutFaces().size() + ), + calcFacePointAverages<IndirectList> + ( + slavePatch(), + slavePatch().points(), + 0, + slavePatch().size() + ), + scalarField(slavePatch().size(), absTol), + true, + cutToSlaveFacesTemp + ); + + cutToSlaveFaces_ = max(cutToSlaveFaces_, cutToSlaveFacesTemp); + + matchedAllFaces = min(cutToSlaveFaces_) != -1; + } } diff --git a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.H b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.H index e406bb852f8fe749ef86b722572f794c34a4c753..45810798371da1d1bd0827469d8289984afef112 100644 --- a/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.H +++ b/src/dynamicMesh/polyMeshAdder/faceCoupleInfo.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -218,6 +218,16 @@ class faceCoupleInfo const label size ); + //- Calculate face point averages from (subset of) faces. + template<template<class> class FaceList> + static pointField calcFacePointAverages + ( + const FaceList<face>&, + const pointField&, + const label start, + const label size + ); + //- Write edges static void writeOBJ ( diff --git a/src/dynamicMesh/polyMeshAdder/faceCoupleInfoTemplates.C b/src/dynamicMesh/polyMeshAdder/faceCoupleInfoTemplates.C index 3b25a6da516c998785d32663adfb510980df71a8..2158c0c92a554bd7dbf55ef997653722f824e14a 100644 --- a/src/dynamicMesh/polyMeshAdder/faceCoupleInfoTemplates.C +++ b/src/dynamicMesh/polyMeshAdder/faceCoupleInfoTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,4 +49,29 @@ Foam::pointField Foam::faceCoupleInfo::calcFaceCentres } +template<template<class> class FaceList> +Foam::pointField Foam::faceCoupleInfo::calcFacePointAverages +( + const FaceList<face>& faces, + const pointField& points, + const label start, + const label size +) +{ + pointField fpa(size, Zero); + + label facei = start; + + forAll(fpa, i) + { + forAll(faces[facei], j) + { + fpa[i] += points[faces[facei][j]]; + } + fpa[i] /= faces[facei++].size(); + } + return fpa; +} + + // ************************************************************************* //