diff --git a/applications/utilities/mesh/generation/Allwmake b/applications/utilities/mesh/generation/Allwmake index 9749745acd..224921ce65 100755 --- a/applications/utilities/mesh/generation/Allwmake +++ b/applications/utilities/mesh/generation/Allwmake @@ -5,8 +5,9 @@ cd ${0%/*} || exit 1 # Run from this directory . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments wmake -all $targetType blockMesh -wmake -all $targetType extrude wmake -all $targetType extrude2DMesh +wmake -all $targetType extrudeMesh +wmake -all $targetType extrudeToRegionMesh wmake -all $targetType snappyHexMesh if [ -n "$FOAMY_HEX_MESH" ] @@ -14,5 +15,4 @@ then foamyMesh/Allwmake $targetType $* fi - #------------------------------------------------------------------------------ diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/Make/files b/applications/utilities/mesh/generation/extrudeMesh/Make/files similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/Make/files rename to applications/utilities/mesh/generation/extrudeMesh/Make/files diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/Make/options b/applications/utilities/mesh/generation/extrudeMesh/Make/options similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/Make/options rename to applications/utilities/mesh/generation/extrudeMesh/Make/options diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/createTimeExtruded.H b/applications/utilities/mesh/generation/extrudeMesh/createTimeExtruded.H similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/createTimeExtruded.H rename to applications/utilities/mesh/generation/extrudeMesh/createTimeExtruded.H diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C rename to applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C similarity index 95% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.C rename to applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C index 9b78f1df18..e507a3d67b 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.H b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.H similarity index 98% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.H rename to applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.H index c129f729a3..96f49c1024 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMesh.H +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C similarity index 99% rename from applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C rename to applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C index d0fa419deb..fce4ddbe3e 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMeshTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/Make/files b/applications/utilities/mesh/generation/extrudeToRegionMesh/Make/files similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/Make/files rename to applications/utilities/mesh/generation/extrudeToRegionMesh/Make/files diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/Make/options b/applications/utilities/mesh/generation/extrudeToRegionMesh/Make/options similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/Make/options rename to applications/utilities/mesh/generation/extrudeToRegionMesh/Make/options diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C similarity index 100% rename from applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C rename to applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.C b/src/functionObjects/field/nearWallFields/nearWallFields.C index 4b1fa93d55..7d4861e1be 100644 --- a/src/functionObjects/field/nearWallFields/nearWallFields.C +++ b/src/functionObjects/field/nearWallFields/nearWallFields.C @@ -26,7 +26,6 @@ License #include "nearWallFields.H" #include "wordReList.H" #include "findCellParticle.H" -#include "mappedPatchBase.H" #include "OBJstream.H" #include "addToRunTimeSelectionTable.H" diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index f0338596e3..07c31357ec 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -242,16 +242,16 @@ $(AMICycPatches)/cyclicAMIPointPatchField/cyclicAMIPointPatchFields.C patchToPatch/patchToPatch/patchToPatch.C patchToPatch/patchToPatch/patchToPatchParallelOps.C +patchToPatch/matching/matchingPatchToPatch.C patchToPatch/nearest/nearestPatchToPatch.C patchToPatch/inverseDistance/inverseDistancePatchToPatch.C patchToPatch/intersection/intersectionPatchToPatch.C patchToPatch/rays/raysPatchToPatch.C -mappedPatches/mappedPolyPatch/mappedPatchBase.C +mappedPatches/mappedPatchBase/mappedPatchBase.C mappedPatches/mappedPolyPatch/mappedPolyPatch.C mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C mappedPatches/mappedPolyPatch/mappedExtrudedWallPolyPatch.C - mappedPatches/mappedPointPatch/mappedPointPatch.C mappedPatches/mappedPointPatch/mappedWallPointPatch.C mappedPatches/mappedPointPatch/mappedExtrudedWallPointPatch.C diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.C similarity index 94% rename from src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C rename to src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.C index 729b4fb004..24e29f1eae 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.C @@ -37,6 +37,7 @@ License #include "distributionMap.H" #include "triPointRef.H" #include "RemoteData.H" +#include "intersectionPatchToPatch.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,12 +50,13 @@ namespace Foam const char* Foam::NamedEnum < Foam::mappedPatchBase::sampleMode, - 4 + 5 >::names[] = { "nearestCell", "nearestPatchFace", "nearestPatchFaceAMI", + "patchToPatch", "nearestFace" }; @@ -72,7 +74,7 @@ namespace Foam } -const Foam::NamedEnum +const Foam::NamedEnum Foam::mappedPatchBase::sampleModeNames_; const Foam::NamedEnum @@ -272,6 +274,11 @@ void Foam::mappedPatchBase::findSamples { break; } + + case PATCHTOPATCH: + { + break; + } } // Find nearest. Combine on master. @@ -379,6 +386,10 @@ Foam::label Foam::mappedPatchBase::sampleSize() const { return samplePolyPatch().size(); } + case PATCHTOPATCH: + { + return samplePolyPatch().size(); + } case NEARESTFACE: { return sampleMesh().nFaces() - sampleMesh().nInternalFaces(); @@ -539,6 +550,25 @@ void Foam::mappedPatchBase::calcAMI() const } +void Foam::mappedPatchBase::calcPatchToPatch() const +{ + if (patchToPatchIsValid_) + { + FatalErrorInFunction + << "Patch-to-patch already calculated" << exit(FatalError); + } + + patchToPatchPtr_->update + ( + patch_, + patch_.pointNormals(), + samplePolyPatch() + ); + + patchToPatchIsValid_ = true; +} + + // Hack to read old (List-based) format. See Field.C. The difference // is only that in case of falling back to old format it expects a non-uniform // list instead of a single vector. @@ -630,7 +660,9 @@ Foam::mappedPatchBase::mappedPatchBase AMIPtr_(nullptr), AMIReverse_(false), surfPtr_(nullptr), - surfDict_(fileName("surface")) + surfDict_(fileName("surface")), + patchToPatchIsValid_(false), + patchToPatchPtr_(nullptr) {} @@ -656,7 +688,14 @@ Foam::mappedPatchBase::mappedPatchBase AMIPtr_(nullptr), AMIReverse_(false), surfPtr_(nullptr), - surfDict_(fileName("surface")) + surfDict_(fileName("surface")), + patchToPatchIsValid_(false), + patchToPatchPtr_ + ( + mode == PATCHTOPATCH + ? new patchToPatches::intersection(false) + : nullptr + ) {} @@ -690,7 +729,14 @@ Foam::mappedPatchBase::mappedPatchBase AMIPtr_(nullptr), AMIReverse_(dict.lookupOrDefault("flipNormals", false)), surfPtr_(nullptr), - surfDict_(dict.subOrEmptyDict("surface")) + surfDict_(dict.subOrEmptyDict("surface")), + patchToPatchIsValid_(false), + patchToPatchPtr_ + ( + mode_ == PATCHTOPATCH + ? patchToPatch::New(dict.lookup("patchToPatchMode"), false) + : autoPtr(nullptr) + ) { if (!coupleGroup_.valid() && sampleRegion_.empty()) { @@ -721,7 +767,14 @@ Foam::mappedPatchBase::mappedPatchBase AMIPtr_(nullptr), AMIReverse_(mpb.AMIReverse_), surfPtr_(nullptr), - surfDict_(mpb.surfDict_) + surfDict_(mpb.surfDict_), + patchToPatchIsValid_(false), + patchToPatchPtr_ + ( + mode_ == PATCHTOPATCH + ? patchToPatch::New(mpb.patchToPatchPtr_->type(), false) + : autoPtr(nullptr) + ) {} @@ -843,6 +896,7 @@ void Foam::mappedPatchBase::clearOut() mapIndices_.clear(); AMIPtr_.clear(); surfPtr_.clear(); + patchToPatchIsValid_ = false; } @@ -886,6 +940,11 @@ void Foam::mappedPatchBase::write(Ostream& os) const os << surfDict_; } } + + if (mode_ == PATCHTOPATCH) + { + writeEntry(os, "patchToPatchMode", patchToPatchPtr_->type()); + } } diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H similarity index 92% rename from src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H rename to src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H index 2e5146464a..b976117805 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H @@ -77,6 +77,7 @@ SourceFiles #include "pointField.H" #include "AMIInterpolation.H" +#include "patchToPatch.H" #include "coupleGroupIdentifier.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -105,6 +106,7 @@ public: NEARESTCELL, // nearest cell containing sample NEARESTPATCHFACE, // nearest face on selected patch NEARESTPATCHFACEAMI, // nearest patch face + AMI interpolation + PATCHTOPATCH, // ... NEARESTFACE // nearest face }; @@ -116,7 +118,7 @@ public: DIRECTION // offset with a specified vector }; - static const NamedEnum sampleModeNames_; + static const NamedEnum sampleModeNames_; static const NamedEnum offsetModeNames_; @@ -177,6 +179,15 @@ protected: dictionary surfDict_; + //- Patch-to-patch intersection engine (only for PATCHTOPATCH) + + //- Is the patch-to-patch intersection engine up to date? + mutable bool patchToPatchIsValid_; + + //- Patch-to-patch intersection engine + mutable autoPtr patchToPatchPtr_; + + // Protected Member Functions //- Read the offset mode from a dictionary @@ -199,6 +210,9 @@ protected: //- Calculate AMI interpolator void calcAMI() const; + //- Calculate the patch-to-patch intersection engine + void calcPatchToPatch() const; + //- Helper to read field or non-uniform list from dictionary static tmp readListOrField ( @@ -207,6 +221,12 @@ protected: const label size ); + //- Return whether or not the sample patch (if any) is of mapped type + inline bool sampleIsMappedPatch() const; + + //- Get the mapped sample patch + inline const mappedPatchBase& sampleMappedPatch() const; + public: @@ -300,22 +320,6 @@ public: const tmp>& fld ) const; - //- Wrapper around map/interpolate data distribution with operation - template - tmp> reverseDistribute - ( - const Field& fld, - const CombineOp& cop - ) const; - - //- Wrapper around map/interpolate data distribution with operation - template - tmp> reverseDistribute - ( - const tmp>& fld, - const CombineOp& cop - ) const; - // I/O diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseI.H similarity index 83% rename from src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H rename to src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseI.H index b26f5d6dde..96b3c0e5ec 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseI.H @@ -25,6 +25,31 @@ License #include "mappedPatchBase.H" +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +inline bool Foam::mappedPatchBase::sampleIsMappedPatch() const +{ + switch (mode_) + { + case NEARESTCELL: + case NEARESTFACE: + return false; + case NEARESTPATCHFACE: + case NEARESTPATCHFACEAMI: + case PATCHTOPATCH: + return isA(samplePolyPatch()); + } + return false; +} + + +inline const Foam::mappedPatchBase& +Foam::mappedPatchBase::sampleMappedPatch() const +{ + return refCast(samplePolyPatch()); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // inline const Foam::mappedPatchBase::sampleMode& diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseTemplates.C b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C similarity index 74% rename from src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseTemplates.C rename to src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C index 011f3fe178..1342806c7b 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseTemplates.C +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C @@ -41,6 +41,25 @@ Foam::mappedPatchBase::distribute(const Field& fld) const } return AMIPtr_->interpolateToSource(fld); } + case PATCHTOPATCH: + { + if + ( + !patchToPatchIsValid_ + && !( + sampleIsMappedPatch() + && sampleMappedPatch().patchToPatchIsValid_ + ) + ) + { + calcPatchToPatch(); + } + + return + patchToPatchIsValid_ + ? patchToPatchPtr_->tgtToSrc(fld) + : sampleMappedPatch().patchToPatchPtr_->srcToTgt(fld); + } default: { if (mapPtr_.empty()) @@ -91,12 +110,33 @@ Foam::mappedPatchBase::reverseDistribute(const Field& fld) const } return AMIPtr_->interpolateToTarget(fld); } + case PATCHTOPATCH: + { + if + ( + !patchToPatchIsValid_ + && !( + sampleIsMappedPatch() + && sampleMappedPatch().patchToPatchIsValid_ + ) + ) + { + calcPatchToPatch(); + } + + return + patchToPatchIsValid_ + ? patchToPatchPtr_->srcToTgt(fld) + : sampleMappedPatch().patchToPatchPtr_->tgtToSrc(fld); + + } default: { FatalErrorInFunction << "Reverse distribute can only be used in " - << sampleModeNames_[NEARESTPATCHFACE] << " or " - << sampleModeNames_[NEARESTPATCHFACEAMI] << "mode" + << sampleModeNames_[NEARESTPATCHFACE] << ", " + << sampleModeNames_[NEARESTPATCHFACEAMI] << " or " + << sampleModeNames_[PATCHTOPATCH] << " mode" << exit(FatalError); return tmp>(nullptr); diff --git a/src/meshTools/nonConformal/polyPatches/nonConformalCyclic/nonConformalCyclicPolyPatch.H b/src/meshTools/nonConformal/polyPatches/nonConformalCyclic/nonConformalCyclicPolyPatch.H index bd160dd7f6..288dafb120 100644 --- a/src/meshTools/nonConformal/polyPatches/nonConformalCyclic/nonConformalCyclicPolyPatch.H +++ b/src/meshTools/nonConformal/polyPatches/nonConformalCyclic/nonConformalCyclicPolyPatch.H @@ -68,10 +68,10 @@ protected: //- Patch-to-patch intersection engine mutable patchToPatches::intersection intersection_; - //- Is the intersection engine up to date? + //- Is the rays engine up to date? mutable bool raysIsValid_; - //- Patch-to-patch intersection engine + //- Patch-to-patch rays engine mutable patchToPatches::rays rays_; diff --git a/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.C b/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.C index 2891936565..e6f0ce5697 100644 --- a/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.C +++ b/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.C @@ -544,13 +544,12 @@ void Foam::patchToPatches::intersection::initialise void Foam::patchToPatches::intersection::rDistributeTgt ( - const primitiveOldTimePatch& tgtPatch, - const distributionMap& tgtMap + const primitiveOldTimePatch& tgtPatch ) { - patchToPatch::rDistributeTgt(tgtPatch, tgtMap); + patchToPatch::rDistributeTgt(tgtPatch); - rDistributeListList(tgtPatch.size(), tgtMap, tgtCouples_); + rDistributeListList(tgtPatch.size(), tgtMapPtr_(), tgtCouples_); } @@ -655,6 +654,44 @@ Foam::label Foam::patchToPatches::intersection::finalise } } + // Calculate coverage and total areas on both sides + auto coverage = [] + ( + const primitivePatch& patch, + const List>& couples, + scalar& area, + scalar& coupleArea, + List& coverage + ) + { + area = 0; + coupleArea = 0; + coverage.resize(patch.size()); + + forAll(patch, facei) + { + const scalar magA = mag(patch.faceAreas()[facei]); + + vector aCouple = Zero; + forAll(couples[facei], i) + { + aCouple += couples[facei][i].area; + } + const scalar magACouple = mag(aCouple); + + area += magA; + coupleArea += magACouple; + coverage[facei] = magACouple/magA; + } + + reduce(area, sumOp()); + reduce(coupleArea, sumOp()); + }; + scalar srcArea = 0, srcCoupleArea = 0; + scalar tgtArea = 0, tgtCoupleArea = 0; + coverage(srcPatch, srcCouples_, srcArea, srcCoupleArea, srcCoverage_); + coverage(tgtPatch, tgtCouples_, tgtArea, tgtCoupleArea, tgtCoverage_); + // Clear the triangulation workspace srcTriPoints_.clear(); srcTriFaceEdges_.clear(); @@ -669,8 +706,6 @@ Foam::label Foam::patchToPatches::intersection::finalise // Checking and reporting if (nCouples != 0) { - scalar srcArea = 0, srcCoupleArea = 0; - scalarField srcCoverage(srcPatch.size()); scalarField srcOpenness(srcPatch.size()); scalarField srcError(srcPatch.size()); scalarField srcDepth(srcPatch.size()); @@ -689,11 +724,6 @@ Foam::label Foam::patchToPatches::intersection::finalise Cpl += cpl; Cpl.nbr += cpl.nbr; } - const scalar magCA = mag(Cpl.area); - - srcArea += magA; - srcCoupleArea += magCA; - srcCoverage[srcFacei] = magCA/magA; vector projectionA = Zero; scalar projectionV = 0; @@ -736,36 +766,15 @@ Foam::label Foam::patchToPatches::intersection::finalise srcDepth[srcFacei] = mag(projectionV)/pow3(sqrt(magA)); } - reduce(srcArea, sumOp()); - reduce(srcCoupleArea, sumOp()); - - scalar tgtArea = 0, tgtCoupleArea = 0; - scalarField tgtCoverage(tgtPatch.size()); - forAll(tgtPatch, tgtFacei) - { - const scalar magA = mag(tgtPatch.faceAreas()[tgtFacei]); - - vector aCouple = Zero; - forAll(tgtCouples_[tgtFacei], tgtSrcFacei) - { - aCouple += tgtCouples_[tgtFacei][tgtSrcFacei].area; - } - const scalar magACouple = mag(aCouple); - - tgtArea += magA; - tgtCoupleArea += magACouple; - tgtCoverage[tgtFacei] = magACouple/magA; - } - reduce(tgtArea, sumOp()); reduce(tgtCoupleArea, sumOp()); Info<< indent << "Source min/average/max coverage = " - << gMin(srcCoverage) << '/' << srcCoupleArea/srcArea << '/' - << gMax(srcCoverage) << endl + << gMin(srcCoverage_) << '/' << srcCoupleArea/srcArea << '/' + << gMax(srcCoverage_) << endl << indent << "Target min/average/max coverage = " - << gMin(tgtCoverage) << '/' << tgtCoupleArea/tgtArea << '/' - << gMax(tgtCoverage) << endl + << gMin(tgtCoverage_) << '/' << tgtCoupleArea/tgtArea << '/' + << gMax(tgtCoverage_) << endl << indent << "Source average openness/error/depth/angle = " << gAverage(srcOpenness) << '/' << gAverage(srcError) << '/' << gAverage(srcDepth) << '/' << gAverage(srcAngle) << endl @@ -815,7 +824,7 @@ Foam::label Foam::patchToPatches::intersection::finalise labelList(), labelListList(), srcPatch.localFaces(), - "coverage", false, srcCoverage, + "coverage", false, scalarField(srcCoverage_), "openness", false, srcOpenness, "error", false, srcError, "depth", false, srcDepth, @@ -833,7 +842,7 @@ Foam::label Foam::patchToPatches::intersection::finalise labelList(), labelListList(), tgtPatch.localFaces(), - "coverage", false, tgtCoverage + "coverage", false, scalarField(tgtCoverage_) ); } } @@ -842,6 +851,68 @@ Foam::label Foam::patchToPatches::intersection::finalise } +Foam::tmpNrc>> +Foam::patchToPatches::intersection::srcWeights() const +{ + List>* resultPtr + ( + new List>(srcCouples_.size()) + ); + List>& result = *resultPtr; + + forAll(srcCouples_, srcFacei) + { + result[srcFacei].resize(srcCouples_[srcFacei].size()); + scalar aSum = 0; + + forAll(srcCouples_[srcFacei], i) + { + const scalar a = mag(srcCouples_[srcFacei][i].area); + result[srcFacei][i] = a; + aSum += a; + } + + forAll(srcCouples_[srcFacei], i) + { + result[srcFacei][i] *= srcCoverage_[srcFacei]/aSum; + } + } + + return tmpNrc>>(resultPtr); +} + + +Foam::tmpNrc>> +Foam::patchToPatches::intersection::tgtWeights() const +{ + List>* resultPtr + ( + new List>(tgtCouples_.size()) + ); + List>& result = *resultPtr; + + forAll(tgtCouples_, tgtFacei) + { + result[tgtFacei].resize(tgtCouples_[tgtFacei].size()); + scalar aSum = 0; + + forAll(tgtCouples_[tgtFacei], i) + { + const scalar a = mag(tgtCouples_[tgtFacei][i].area); + result[tgtFacei][i] = a; + aSum += a; + } + + forAll(tgtCouples_[tgtFacei], i) + { + result[tgtFacei][i] *= tgtCoverage_[tgtFacei]/aSum; + } + } + + return tmpNrc>>(resultPtr); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::patchToPatches::intersection::intersection(const bool reverse) @@ -849,9 +920,11 @@ Foam::patchToPatches::intersection::intersection(const bool reverse) patchToPatch(reverse), srcCouples_(), + srcCoverage_(), srcEdgeParts_(), srcErrorParts_(), tgtCouples_(), + tgtCoverage_(), triEngine_(), @@ -884,62 +957,4 @@ Foam::patchToPatches::intersection::~intersection() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -Foam::tmpNrc>> -Foam::patchToPatches::intersection::srcWeights -( - const primitivePatch& srcPatch -) const -{ - List>* resultPtr - ( - new List>(srcCouples_.size()) - ); - List>& result = *resultPtr; - - forAll(srcCouples_, srcFacei) - { - result[srcFacei].resize(srcCouples_[srcFacei].size()); - - const scalar magA = mag(srcPatch.faceAreas()[srcFacei]); - - forAll(srcCouples_[srcFacei], i) - { - result[srcFacei][i] = mag(srcCouples_[srcFacei][i].area)/magA; - } - } - - return tmpNrc>>(resultPtr); -} - - -Foam::tmpNrc>> -Foam::patchToPatches::intersection::tgtWeights -( - const primitivePatch& tgtPatch -) const -{ - List>* resultPtr - ( - new List>(tgtCouples_.size()) - ); - List>& result = *resultPtr; - - forAll(tgtCouples_, tgtFacei) - { - result[tgtFacei].resize(tgtCouples_[tgtFacei].size()); - - const scalar magA = mag(tgtPatch.faceAreas()[tgtFacei]); - - forAll(tgtCouples_[tgtFacei], i) - { - result[tgtFacei][i] = mag(tgtCouples_[tgtFacei][i].area)/magA; - } - } - - return tmpNrc>>(resultPtr); -} - - // ************************************************************************* // diff --git a/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.H b/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.H index a9e14ace17..2dce50493d 100644 --- a/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.H +++ b/src/meshTools/patchToPatch/intersection/intersectionPatchToPatch.H @@ -75,7 +75,7 @@ public: part() : area(Zero), - centre(point::uniform(NaN)) + centre(NaN()) {} //- Default construct @@ -210,6 +210,9 @@ private: //- The coupling geometry for for each source face List> srcCouples_; + //- The proportion of the source faces that are coupled + List srcCoverage_; + //- The non-coupled geometry associated with each source edge List srcEdgeParts_; @@ -220,6 +223,9 @@ private: //- The coupling geometry for for each target face List> tgtCouples_; + //- The proportion of the target faces that are coupled + List tgtCoverage_; + //- Triangulation engine mutable polygonTriangulate triEngine_; @@ -325,11 +331,7 @@ private: //- Send data that resulted from an intersection between the source // patch and a distributed source-local-target patch back to the // original target processes. - virtual void rDistributeTgt - ( - const primitiveOldTimePatch& tgtPatch, - const distributionMap& tgtMap - ); + virtual void rDistributeTgt(const primitiveOldTimePatch& tgtPatch); //- Finalise the intersection virtual label finalise @@ -341,6 +343,12 @@ private: const transformer& tgtToSrc ); + //- For each source face, the coupled target weights + virtual tmpNrc>> srcWeights() const; + + //- For each target face, the coupled source weights + virtual tmpNrc>> tgtWeights() const; + public: @@ -393,18 +401,6 @@ public: //- For each target face, the target and source areas for each // source coupling inline const List>& tgtCouples() const; - - //- For each source face, the coupled target weights - virtual tmpNrc>> srcWeights - ( - const primitivePatch& srcPatch - ) const; - - //- For each target face, the coupled source weights - virtual tmpNrc>> tgtWeights - ( - const primitivePatch& tgtPatch - ) const; }; diff --git a/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.C b/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.C index 0ba290ab6e..fa4e0ff5a3 100644 --- a/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.C +++ b/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.C @@ -190,13 +190,12 @@ void Foam::patchToPatches::inverseDistance::initialise void Foam::patchToPatches::inverseDistance::rDistributeTgt ( - const primitiveOldTimePatch& tgtPatch, - const distributionMap& tgtMap + const primitiveOldTimePatch& tgtPatch ) { - patchToPatch::rDistributeTgt(tgtPatch, tgtMap); + patchToPatch::rDistributeTgt(tgtPatch); - rDistributeListList(tgtPatch.size(), tgtMap, tgtWeights_); + rDistributeListList(tgtPatch.size(), tgtMapPtr_(), tgtWeights_); } @@ -243,6 +242,20 @@ Foam::label Foam::patchToPatches::inverseDistance::finalise } +Foam::tmpNrc>> +Foam::patchToPatches::inverseDistance::srcWeights() const +{ + return srcWeights_; +} + + +Foam::tmpNrc>> +Foam::patchToPatches::inverseDistance::tgtWeights() const +{ + return tgtWeights_; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::patchToPatches::inverseDistance::inverseDistance(const bool reverse) @@ -259,26 +272,4 @@ Foam::patchToPatches::inverseDistance::~inverseDistance() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -Foam::tmpNrc>> -Foam::patchToPatches::inverseDistance::srcWeights -( - const primitivePatch& srcPatch -) const -{ - return srcWeights_; -} - - -Foam::tmpNrc>> -Foam::patchToPatches::inverseDistance::tgtWeights -( - const primitivePatch& tgtPatch -) const -{ - return tgtWeights_; -} - - // ************************************************************************* // diff --git a/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.H b/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.H index fe650274fb..a18d96a878 100644 --- a/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.H +++ b/src/meshTools/patchToPatch/inverseDistance/inverseDistancePatchToPatch.H @@ -117,11 +117,7 @@ class inverseDistance //- Send data that resulted from an intersection between the source // patch and a distributed source-local-target patch back to the // original target processes. - virtual void rDistributeTgt - ( - const primitiveOldTimePatch& tgtPatch, - const distributionMap& tgtMap - ); + virtual void rDistributeTgt(const primitiveOldTimePatch& tgtPatch); //- Finalise the intersection virtual label finalise @@ -133,6 +129,12 @@ class inverseDistance const transformer& tgtToSrc ); + //- For each source face, the coupled target weights + virtual tmpNrc>> srcWeights() const; + + //- For each target face, the coupled source weights + virtual tmpNrc>> tgtWeights() const; + public: @@ -148,21 +150,6 @@ public: //- Destructor ~inverseDistance(); - - - // Member Functions - - //- For each source face, the coupled target weights - virtual tmpNrc>> srcWeights - ( - const primitivePatch& srcPatch - ) const; - - //- For each target face, the coupled source weights - virtual tmpNrc>> tgtWeights - ( - const primitivePatch& tgtPatch - ) const; }; diff --git a/src/meshTools/patchToPatch/matching/matchingPatchToPatch.C b/src/meshTools/patchToPatch/matching/matchingPatchToPatch.C new file mode 100644 index 0000000000..7f6f663240 --- /dev/null +++ b/src/meshTools/patchToPatch/matching/matchingPatchToPatch.C @@ -0,0 +1,163 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "matchingPatchToPatch.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace patchToPatches +{ + defineTypeNameAndDebug(matching, 0); + addToRunTimeSelectionTable(patchToPatch, matching, bool); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::label Foam::patchToPatches::matching::finalise +( + const primitiveOldTimePatch& srcPatch, + const vectorField& srcPointNormals, + const vectorField& srcPointNormals0, + const primitiveOldTimePatch& tgtPatch, + const transformer& tgtToSrc +) +{ + const label nCouples = + nearest::finalise + ( + srcPatch, + srcPointNormals, + srcPointNormals0, + tgtPatch, + tgtToSrc + ); + + // Make sure every face references exactly one face + auto forwardCheck = [] + ( + const primitiveOldTimePatch& patch, + const List>& localOtherFaces, + const bool isSrc + ) + { + forAll(localOtherFaces, facei) + { + if (localOtherFaces[facei].size() != 1) + { + FatalErrorInFunction + << (isSrc ? "Source" : "Target") + << " face #" << facei << " at " + << patch.faceCentres()[facei] + << " did not match a face on the " + << (isSrc ? "target" : "source") + << " side" << exit(FatalError); + } + } + }; + forwardCheck(srcPatch, srcLocalTgtFaces_, true); + forwardCheck(tgtPatch, tgtLocalSrcFaces_, false); + + // Make sure every face is referenced by exactly one face + auto reverseCheck = [] + ( + const primitiveOldTimePatch& patch, + const List>& otherLocalFaces, + const autoPtr& mapPtr, + const bool isSrc + ) + { + labelList count + ( + mapPtr.valid() ? mapPtr->constructSize() : patch.size(), + 0 + ); + + forAll(otherLocalFaces, otherFacei) + { + forAll(otherLocalFaces[otherFacei], i) + { + count[otherLocalFaces[otherFacei][i]] ++; + } + } + + if (mapPtr.valid()) + { + distributionMapBase::distribute + ( + Pstream::commsTypes::nonBlocking, + List(), + patch.size(), + mapPtr->constructMap(), + false, + mapPtr->subMap(), + false, + count, + plusEqOp