diff --git a/src/regionModels/regionModel/regionModel/regionModel.C b/src/regionModels/regionModel/regionModel/regionModel.C index da1ab6e953..227af0adb4 100644 --- a/src/regionModels/regionModel/regionModel/regionModel.C +++ b/src/regionModels/regionModel/regionModel/regionModel.C @@ -190,6 +190,66 @@ bool Foam::regionModels::regionModel::read(const dictionary& dict) } +Foam::label Foam::regionModels::regionModel::nbrCoupledPatchID +( + const regionModel& nbrRegion, + const label regionPatchI +) const +{ + label nbrPatchI = -1; + + // region + const fvMesh& nbrRegionMesh = nbrRegion.regionMesh(); + + // boundary mesh + const polyBoundaryMesh& nbrPbm = nbrRegionMesh.boundaryMesh(); + + const mappedPatchBase& mpb = + refCast + ( + regionMesh().boundaryMesh()[regionPatchI] + ); + + // sample patch name on the primary region + const word& primaryPatchName = mpb.samplePatch(); + + // find patch on nbr region that has the same sample patch name + forAll(nbrRegion.intCoupledPatchIDs(), j) + { + const label nbrRegionPatchI = nbrRegion.intCoupledPatchIDs()[j]; + + const mappedPatchBase& mpb = + refCast(nbrPbm[nbrRegionPatchI]); + + if (mpb.samplePatch() == primaryPatchName) + { + nbrPatchI = nbrRegionPatchI; + break; + } + } + + if (nbrPatchI == -1) + { + const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI]; + + FatalErrorIn + ( + "Foam::tmp > " + "Foam::regionModels::regionModel::nbrCoupledPatchID" + "(" + "const regionModel& , " + "const label" + ") const" + ) + << "Unable to find patch pair for local patch " + << p.name() << " and region " << nbrRegion.name() + << abort(FatalError); + } + + return nbrPatchI; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::regionModels::regionModel::regionModel(const fvMesh& mesh) diff --git a/src/regionModels/regionModel/regionModel/regionModel.H b/src/regionModels/regionModel/regionModel/regionModel.H index 0b02fd1a58..9f2ec23e67 100644 --- a/src/regionModels/regionModel/regionModel/regionModel.H +++ b/src/regionModels/regionModel/regionModel/regionModel.H @@ -219,6 +219,46 @@ public: // Helper + //- Return the coupled patch ID paired with coupled patch + // regionPatchI + label nbrCoupledPatchID + ( + const regionModel& nbrRegion, + const label regionPatchI + ) const; + + //- Map patch field from another region model to local patch + template + tmp > mapRegionPatchField + ( + const regionModel& nbrRegion, + const label regionPatchI, + const label nbrPatchI, + const Field& nbrField, + const bool flip = false + ) const; + + //- Map patch field from another region model to local patch + template + tmp > mapRegionPatchField + ( + const word& regionModelName, + const word& fieldName, + const label regionPatchI, + const bool flip = false + ) const; + + //- Map patch internal field from another region model to local + // patch + template + tmp > mapRegionPatchInternalField + ( + const word& regionModelName, + const word& fieldName, + const label regionPatchI, + const bool flip = false + ) const; + //- Convert a local region field to the primary region template void toPrimary diff --git a/src/regionModels/regionModel/regionModel/regionModelTemplates.C b/src/regionModels/regionModel/regionModel/regionModelTemplates.C index b78772de01..4e98b2e2fb 100644 --- a/src/regionModels/regionModel/regionModel/regionModelTemplates.C +++ b/src/regionModels/regionModel/regionModel/regionModelTemplates.C @@ -23,6 +23,164 @@ License \*---------------------------------------------------------------------------*/ +template +Foam::tmp > +Foam::regionModels::regionModel::mapRegionPatchField +( + const regionModel& nbrRegion, + const label regionPatchI, + const label nbrPatchI, + const Field& nbrField, + const bool flip +) const +{ + const fvMesh& nbrRegionMesh = nbrRegion.regionMesh(); + + const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI]; + + const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI]; + + int oldTag = UPstream::msgType(); + UPstream::msgType() = oldTag + 1; + + AMIPatchToPatchInterpolation ami(p, nbrP, faceAreaIntersect::tmMesh, flip); + + tmp > tresult(ami.interpolateToSource(nbrField)); + + UPstream::msgType() = oldTag; + + return tresult; +} + + +template +Foam::tmp > +Foam::regionModels::regionModel::mapRegionPatchField +( + const word& regionModelName, + const word& fieldName, + const label regionPatchI, + const bool flip +) const +{ + typedef GeometricField fieldType; + + const regionModel& nbrRegion = + this->primaryMesh_.lookupObject(regionModelName); + + const fvMesh& nbrRegionMesh = nbrRegion.regionMesh(); + + const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI]; + + if (nbrRegionMesh.foundObject(fieldName)) + { + const fieldType& nbrField = + nbrRegionMesh.lookupObject(fieldName); + + const label nbrPatchI = nbrCoupledPatchID(nbrRegion, regionPatchI); + + const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI]; + + int oldTag = UPstream::msgType(); + UPstream::msgType() = oldTag + 1; + + AMIPatchToPatchInterpolation ami + ( + p, + nbrP, + faceAreaIntersect::tmMesh, + flip + ); + + const Field& nbrFieldp = nbrField.boundaryField()[nbrPatchI]; + + tmp > tresult(ami.interpolateToSource(nbrFieldp)); + + UPstream::msgType() = oldTag; + + return tresult; + } + else + { + return + tmp > + ( + new Field + ( + p.size(), + pTraits::zero + ) + ); + } +} + + +template +Foam::tmp > +Foam::regionModels::regionModel::mapRegionPatchInternalField +( + const word& regionModelName, + const word& fieldName, + const label regionPatchI, + const bool flip +) const +{ + typedef GeometricField fieldType; + + const regionModel& nbrRegion = + this->primaryMesh_.lookupObject(regionModelName); + + const fvMesh& nbrRegionMesh = nbrRegion.regionMesh(); + + const polyPatch& p = regionMesh().boundaryMesh()[regionPatchI]; + + if (nbrRegionMesh.foundObject(fieldName)) + { + const fieldType& nbrField = + nbrRegionMesh.lookupObject(fieldName); + + const label nbrPatchI = nbrCoupledPatchID(nbrRegion, regionPatchI); + + const polyPatch& nbrP = nbrRegionMesh.boundaryMesh()[nbrPatchI]; + + int oldTag = UPstream::msgType(); + UPstream::msgType() = oldTag + 1; + + AMIPatchToPatchInterpolation ami + ( + p, + nbrP, + faceAreaIntersect::tmMesh, + flip + ); + + const fvPatchField& nbrFieldp = + nbrField.boundaryField()[nbrPatchI]; + + tmp > tresult + ( + ami.interpolateToSource(nbrFieldp.patchInternalField()) + ); + + UPstream::msgType() = oldTag; + + return tresult; + } + else + { + return + tmp > + ( + new Field + ( + p.size(), + pTraits::zero + ) + ); + } +} + + template void Foam::regionModels::regionModel::toPrimary (