diff --git a/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.C b/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.C index 4add751668f357bbc37cbd493660df5ba5820500..647b78b6cd692a1a43e470f473f2c53f2569c09b 100644 --- a/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.C +++ b/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.C @@ -165,17 +165,81 @@ bool Foam::meshToMeshNew::findInitialSeeds const pointField pts(srcCells[srcI].points(srcFaces, srcPts).xfer()); - forAll(pts, ptI) + switch (method_) { - const point& pt = pts[ptI]; - label tgtI = tgt.cellTree().findInside(pt); - - if (tgtI != -1 && intersect(src, tgt, srcI, tgtI)) + case imDirect: + case imCellVolumeWeight: { - srcSeedI = srcI; - tgtSeedI = tgtI; + forAll(pts, ptI) + { + const point& pt = pts[ptI]; + label tgtI = tgt.cellTree().findInside(pt); + + if (tgtI != -1 && intersect(src, tgt, srcI, tgtI)) + { + srcSeedI = srcI; + tgtSeedI = tgtI; + + return true; + } + } - return true; + break; + } + case imMapNearest: + { + const point& pt = pts[0]; + pointIndexHit hit = tgt.cellTree().findNearest(pt, GREAT); + + if (hit.hit()) + { + srcSeedI = srcI; + tgtSeedI = hit.index(); + + return true; + } + else + { + FatalErrorIn + ( + "bool Foam::meshToMeshNew::findInitialSeeds" + "(" + "const polyMesh&, " + "const polyMesh&, " + "const labelList&, " + "const boolList&, " + "const label, " + "label&, " + "label&" + ") const" + ) + << "Unable to find nearest target cell" + << " for source cell " << srcI + << " with centre " + << srcCells[srcI].centre(srcPts, srcFaces) + << abort(FatalError); + } + + break; + } + default: + { + FatalErrorIn + ( + "bool Foam::meshToMeshNew::findInitialSeeds" + "(" + "const polyMesh&, " + "const polyMesh&, " + "const labelList&, " + "const boolList&, " + "const label, " + "label&, " + "label&" + ") const" + ) + << "Unhandled method: " + << interpolationMethodNames_[method_] + << abort(FatalError); } } } @@ -577,6 +641,48 @@ void Foam::meshToMeshNew::calculate() } +Foam::AMIPatchToPatchInterpolation::interpolationMethod +Foam::meshToMeshNew::interpolationMethodAMI +( + const interpolationMethod method +) const +{ + switch (method_) + { + case imDirect: + { + return AMIPatchToPatchInterpolation::imDirect; + break; + } + case imMapNearest: + { + return AMIPatchToPatchInterpolation::imMapNearest; + break; + } + case imCellVolumeWeight: + { + return AMIPatchToPatchInterpolation::imFaceAreaWeight; + break; + } + default: + { + FatalErrorIn + ( + "Foam::AMIPatchToPatchInterpolation::interpolationMethod" + "Foam::meshToMeshNew::interpolationMethodAMI" + "(" + "const interpolationMethod method" + ") const" + ) + << "Unhandled enumeration " << method_ + << abort(FatalError); + } + } + + return AMIPatchToPatchInterpolation::imDirect; +} + + const Foam::PtrList<Foam::AMIPatchToPatchInterpolation>& Foam::meshToMeshNew::patchAMIs() const { @@ -593,7 +699,9 @@ Foam::meshToMeshNew::patchAMIs() const const polyPatch& tgtPP = tgtRegion_.boundaryMesh()[tgtPatchI]; Info<< "Creating AMI between source patch " << srcPP.name() - << " and target patch " << tgtPP.name() << endl; + << " and target patch " << tgtPP.name() + << " using " << interpolationMethodAMI(method_) + << endl; Info<< incrIndent; @@ -605,6 +713,7 @@ Foam::meshToMeshNew::patchAMIs() const srcPP, tgtPP, faceAreaIntersect::tmMesh, + interpolationMethodAMI(method_), true // flip target patch since patch normals are aligned ) ); diff --git a/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.H b/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.H index 8404ce7b9fa077ecc07ea02671d4673dfeb6981c..19ec3b3e0d6be48431ec606a65079bbfe1befc95 100644 --- a/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.H +++ b/src/sampling/meshToMeshInterpolation/meshToMeshNew/meshToMeshNew.H @@ -70,7 +70,7 @@ public: // Public data types - //- Enumeration specifying required accuracy + //- Enumeration specifying interpolation method enum interpolationMethod { imDirect, @@ -302,6 +302,13 @@ private: //- Calculate - main driver function void calculate(); + //- Conversion between mesh and patch interpolation methods + AMIPatchToPatchInterpolation::interpolationMethod + interpolationMethodAMI + ( + const interpolationMethod method + ) const; + //- Return the list of AMIs between source and target patches const PtrList<AMIPatchToPatchInterpolation>& patchAMIs() const;