diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index f7bd85937a..f817d1584b 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -86,179 +86,21 @@ const Foam::NamedEnum // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::pointIndexHit Foam::mappedPatchBase::facePoint -( - const polyMesh& mesh, - const label facei, - const polyMesh::cellDecomposition decompMode -) -{ - const point& fc = mesh.faceCentres()[facei]; - - switch (decompMode) - { - case polyMesh::FACE_PLANES: - case polyMesh::FACE_CENTRE_TRIS: - { - // For both decompositions the face centre is guaranteed to be - // on the face - return pointIndexHit(true, fc, facei); - } - break; - - case polyMesh::FACE_DIAG_TRIS: - case polyMesh::CELL_TETS: - { - // Find the intersection of a ray from face centre to cell centre - // Find intersection of (face-centre-decomposition) centre to - // cell-centre with face-diagonal-decomposition triangles. - - const pointField& p = mesh.points(); - const face& f = mesh.faces()[facei]; - - if (f.size() <= 3) - { - // Return centre of triangle. - return pointIndexHit(true, fc, 0); - } - - label celli = mesh.faceOwner()[facei]; - const point& cc = mesh.cellCentres()[celli]; - vector d = fc-cc; - - const label fp0 = mesh.tetBasePtIs()[facei]; - const point& basePoint = p[f[fp0]]; - - label fp = f.fcIndex(fp0); - for (label i = 2; i < f.size(); i++) - { - const point& thisPoint = p[f[fp]]; - label nextFp = f.fcIndex(fp); - const point& nextPoint = p[f[nextFp]]; - - const triPointRef tri(basePoint, thisPoint, nextPoint); - pointHit hitInfo = tri.intersection - ( - cc, - d, - intersection::algorithm::halfRay - ); - - if (hitInfo.hit() && hitInfo.distance() > 0) - { - return pointIndexHit(true, hitInfo.hitPoint(), i-2); - } - - fp = nextFp; - } - - // Fall-back - return pointIndexHit(false, fc, -1); - } - break; - - default: - { - FatalErrorInFunction - << "problem" << abort(FatalError); - return pointIndexHit(); - } - } -} - - -Foam::tmp Foam::mappedPatchBase::facePoints -( - const polyPatch& pp -) const -{ - const polyMesh& mesh = pp.boundaryMesh().mesh(); - - // Force construction of min-tet decomp - (void)mesh.tetBasePtIs(); - - // Initialise to face-centre - tmp tfacePoints(new pointField(patch_.size())); - pointField& facePoints = tfacePoints.ref(); - - forAll(pp, facei) - { - facePoints[facei] = facePoint - ( - mesh, - pp.start()+facei, - polyMesh::FACE_DIAG_TRIS - ).rawPoint(); - } - - return tfacePoints; -} - - -Foam::tmp Foam::mappedPatchBase::samplePoints -( - const pointField& fc -) const -{ - tmp tfld(new pointField(fc)); - pointField& fld = tfld.ref(); - - switch (offsetMode_) - { - case UNIFORM: - { - fld += offset_; - break; - } - case NONUNIFORM: - { - fld += offsets_; - break; - } - case NORMAL: - { - // Get outwards pointing normal - vectorField n(patch_.faceAreas()); - n /= mag(n); - - fld += distance_*n; - break; - } - } - - return tfld; -} - - void Foam::mappedPatchBase::collectSamples ( - const pointField& facePoints, pointField& samples, labelList& patchFaceProcs, - labelList& patchFaces, - pointField& patchFc + labelList& patchFaces ) const { // Collect all sample points and the faces they come from. - { - List globalFc(Pstream::nProcs()); - globalFc[Pstream::myProcNo()] = facePoints; - Pstream::gatherList(globalFc); - Pstream::scatterList(globalFc); - // Rework into straight list - patchFc = ListListOps::combine - ( - globalFc, - accessOp() - ); - } { List globalSamples(Pstream::nProcs()); - globalSamples[Pstream::myProcNo()] = samplePoints(facePoints); + globalSamples[Pstream::myProcNo()] = samplePoints(); Pstream::gatherList(globalSamples); Pstream::scatterList(globalSamples); - // Rework into straight list + samples = ListListOps::combine ( globalSamples, @@ -269,7 +111,6 @@ void Foam::mappedPatchBase::collectSamples { labelListList globalFaces(Pstream::nProcs()); globalFaces[Pstream::myProcNo()] = identity(patch_.size()); - // Distribute to all processors Pstream::gatherList(globalFaces); Pstream::scatterList(globalFaces); @@ -300,15 +141,12 @@ void Foam::mappedPatchBase::collectSamples } -// Find the processor/cell containing the samples. Does not account -// for samples being found in two processors. void Foam::mappedPatchBase::findSamples ( const sampleMode mode, const pointField& samples, labelList& sampleProcs, - labelList& sampleIndices, - pointField& sampleLocations + labelList& sampleIndices ) const { // Lookup the correct region @@ -506,12 +344,10 @@ void Foam::mappedPatchBase::findSamples } } - // Find nearest. Combine on master. Pstream::listCombineGather(nearest, nearestEqOp()); Pstream::listCombineScatter(nearest); - if (debug) { InfoInFunction @@ -533,7 +369,6 @@ void Foam::mappedPatchBase::findSamples // Convert back into proc+local index sampleProcs.setSize(samples.size()); sampleIndices.setSize(samples.size()); - sampleLocations.setSize(samples.size()); forAll(nearest, sampleI) { @@ -541,13 +376,11 @@ void Foam::mappedPatchBase::findSamples { sampleProcs[sampleI] = -1; sampleIndices[sampleI] = -1; - sampleLocations[sampleI] = vector::max; } else { sampleProcs[sampleI] = nearest[sampleI].second().second(); sampleIndices[sampleI] = nearest[sampleI].first().index(); - sampleLocations[sampleI] = nearest[sampleI].first().hitPoint(); } } } @@ -585,105 +418,64 @@ Foam::label Foam::mappedPatchBase::sampleSize() const void Foam::mappedPatchBase::calcMapping() const { - static bool hasWarned = false; if (mapPtr_.valid()) { FatalErrorInFunction << "Mapping already calculated" << exit(FatalError); } - // Get points on face (since cannot use face-centres - might be off - // face-diagonal decomposed tets. - tmp patchPoints(facePoints(patch_)); - - // Get offsetted points - const pointField offsettedPoints(samplePoints(patchPoints())); - - // Do a sanity check - am I sampling my own patch? - // This only makes sense for a non-zero offset. - bool sampleMyself = + /* + // Do a sanity check. Am I sampling my own patch? This only makes sense if + // the position is transformed. + if ( mode_ == NEARESTPATCHFACE && sampleRegion() == patch_.boundaryMesh().mesh().name() && samplePatch() == patch_.name() - ); - - // Check offset - vectorField d(offsettedPoints-patchPoints()); - bool coincident = (gAverage(mag(d)) <= rootVSmall); - - if (sampleMyself && coincident) + && !transform_.transformsPosition() + ) { - WarningInFunction - << "Invalid offset " << d << endl - << "Offset is the vector added to the patch face centres to" - << " find the patch face supplying the data." << endl - << "Setting it to " << d - << " on the same patch, on the same region" - << " will find the faces themselves which does not make sense" - << " for anything but testing." << endl - << "patch_:" << patch_.name() << endl - << "sampleRegion_:" << sampleRegion() << endl - << "mode_:" << sampleModeNames_[mode_] << endl - << "samplePatch_:" << samplePatch() << endl - << "offsetMode_:" << offsetModeNames_[offsetMode_] << endl; + FatalErrorInFunction + << "Patch " << patch_.name() << " is sampling itself with no " + << "transformation. The patch face values are undefined." + << exit(FatalError); + } + */ // Get global list of all samples and the processor and face they come from. pointField samples; labelList patchFaceProcs; labelList patchFaces; - pointField patchFc; - collectSamples - ( - patchPoints, - samples, - patchFaceProcs, - patchFaces, - patchFc - ); + collectSamples(samples, patchFaceProcs, patchFaces); // Find processor and cell/face samples are in and actual location. labelList sampleProcs; labelList sampleIndices; - pointField sampleLocations; - findSamples(mode_, samples, sampleProcs, sampleIndices, sampleLocations); + findSamples(mode_, samples, sampleProcs, sampleIndices); // Check for samples that were not found. This will only happen for - // NEARESTCELL since finds cell containing a location + // NEARESTCELL since this finds a cell containing a location. if (mode_ == NEARESTCELL) { - label nNotFound = 0; - forAll(sampleProcs, sampleI) - { - if (sampleProcs[sampleI] == -1) - { - nNotFound++; - } - } - reduce(nNotFound, sumOp