From c6e18e7593ea24cb67fdc6aabaf0933b30e58fea Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 18 May 2020 07:41:46 +0100 Subject: [PATCH] ENH: AMI code refactoring --- .../cyclicACMI/cyclicACMIFvPatchField.C | 9 +- .../constraint/cyclicACMI/cyclicACMIFvPatch.C | 17 +- .../constraint/cyclicAMI/cyclicAMIFvPatch.C | 3 +- .../constraint/cyclicAMI/cyclicAMIFvPatch.H | 6 +- .../AMIInterpolation/AMIInterpolation.C | 867 +++++------------- .../AMIInterpolation/AMIInterpolation.H | 300 +++--- .../AMIInterpolation/AMIInterpolationI.H | 161 ++-- .../AMIInterpolation/AMIInterpolationName.C | 38 - .../AMIMethodNew.C => AMIInterpolationNew.C} | 63 +- .../AMIInterpolationTemplates.C | 318 +++++++ .../AMIMethod/AMIMethod/AMIMethod.H | 380 -------- .../AMIMethod/mapNearestAMI/nearestFaceAMI.C | 361 -------- .../AMIPatchToPatchInterpolation.C | 46 - .../AMIPatchToPatchInterpolation.H | 4 +- .../advancingFrontAMI.C} | 289 +++--- .../advancingFrontAMI/advancingFrontAMI.H | 271 ++++++ .../advancingFrontAMII.H} | 39 +- .../advancingFrontAMIParallelOps.C} | 72 +- .../faceAreaWeightAMI/faceAreaWeightAMI.C | 524 +++++------ .../faceAreaWeightAMI/faceAreaWeightAMI.H | 89 +- .../nearestFaceAMI/nearestFaceAMI.C | 408 +++++++++ .../nearestFaceAMI.H | 76 +- .../partialFaceAreaWeightAMI.C | 124 +-- .../partialFaceAreaWeightAMI.H | 73 +- .../faceAreaIntersect/faceAreaIntersect.H | 1 + .../cyclicACMIPolyPatch/cyclicACMIPolyPatch.C | 159 ++-- .../cyclicACMIPolyPatch/cyclicACMIPolyPatch.H | 22 +- .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C | 289 +++--- .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.H | 59 +- .../cyclicAMIPolyPatch/cyclicAMIPolyPatchI.H | 14 +- .../cyclicAMIPolyPatchTopologyChange.C | 48 +- .../cyclicPeriodicAMIPolyPatch.C | 51 +- .../cyclicPeriodicAMIPolyPatch.H | 6 +- src/meshTools/Make/files | 9 +- .../mappedPolyPatch/mappedPatchBase.C | 65 +- .../mappedPolyPatch/mappedPatchBase.H | 6 +- 36 files changed, 2440 insertions(+), 2827 deletions(-) delete mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationName.C rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod/AMIMethod/AMIMethodNew.C => AMIInterpolationNew.C} (59%) create mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationTemplates.C delete mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H delete mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/nearestFaceAMI.C delete mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/AMIPatchToPatchInterpolation.C rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod/AMIMethod/AMIMethod.C => advancingFrontAMI/advancingFrontAMI.C} (63%) create mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMI.H rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod/AMIMethod/AMIMethodI.H => advancingFrontAMI/advancingFrontAMII.H} (68%) rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod/AMIMethod/AMIMethodParallelOps.C => advancingFrontAMI/advancingFrontAMIParallelOps.C} (85%) rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod => }/faceAreaWeightAMI/faceAreaWeightAMI.C (58%) rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod => }/faceAreaWeightAMI/faceAreaWeightAMI.H (74%) create mode 100644 src/meshTools/AMIInterpolation/AMIInterpolation/nearestFaceAMI/nearestFaceAMI.C rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod/mapNearestAMI => nearestFaceAMI}/nearestFaceAMI.H (68%) rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod => }/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.C (55%) rename src/meshTools/AMIInterpolation/AMIInterpolation/{AMIMethod => }/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H (70%) diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C index beb923b899..96415c00e5 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C @@ -226,10 +226,9 @@ void Foam::cyclicACMIFvPatchField::updateInterfaceMatrix { const cyclicACMIPolyPatch& cpp = cyclicACMIPatch_.cyclicACMIPatch(); - // note: only applying coupled contribution + // Note: only applying coupled contribution - const labelUList& nbrFaceCellsCoupled = - cpp.neighbPatch().faceCells(); + const labelUList& nbrFaceCellsCoupled = cpp.neighbPatch().faceCells(); solveScalarField pnf(psiInternal, nbrFaceCellsCoupled); @@ -254,7 +253,7 @@ void Foam::cyclicACMIFvPatchField::updateInterfaceMatrix { const cyclicACMIPolyPatch& cpp = cyclicACMIPatch_.cyclicACMIPatch(); - // note: only applying coupled contribution + // Note: only applying coupled contribution const labelUList& nbrFaceCellsCoupled = cpp.neighbPatch().faceCells(); @@ -277,7 +276,7 @@ void Foam::cyclicACMIFvPatchField::manipulateMatrix { const scalarField& mask = cyclicACMIPatch_.cyclicACMIPatch().mask(); - // nothing to be done by the AMI, but re-direct to non-overlap patch + // Nothing to be done by the AMI, but re-direct to non-overlap patch // with non-overlap patch weights const fvPatchField& npf = nonOverlapPatchField(); diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicACMI/cyclicACMIFvPatch.C b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicACMI/cyclicACMIFvPatch.C index 23a12796ad..a66ae7d06b 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicACMI/cyclicACMIFvPatch.C +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicACMI/cyclicACMIFvPatch.C @@ -46,6 +46,7 @@ namespace Foam void Foam::cyclicACMIFvPatch::resetPatchAreas(const fvPatch& fvp) const { const_cast(fvp.Sf()) = fvp.patch().faceAreas(); + const_cast(fvp.Cf()) = fvp.patch().faceCentres(); const_cast(fvp.magSf()) = mag(fvp.patch().faceAreas()); DebugPout @@ -117,7 +118,7 @@ Foam::tmp Foam::cyclicACMIFvPatch::delta() const vectorField nbrPatchD(interpolate(nbrPatch.coupledFvPatch::delta())); - tmp tpdv(new vectorField(patchD.size())); + auto tpdv = tmp::New(patchD.size()); vectorField& pdv = tpdv.ref(); // do the transformation if necessary @@ -204,6 +205,9 @@ void Foam::cyclicACMIFvPatch::movePoints() scalarField& phiNonOverlapp = meshPhiBf[nonOverlapPatch.patch().index()]; + const auto& localFaces = cyclicACMIPolyPatch_.localFaces(); + const auto& localPoints = cyclicACMIPolyPatch_.localPoints(); + forAll(phip, facei) { if (newSrcAddr[facei].empty()) @@ -214,12 +218,12 @@ void Foam::cyclicACMIFvPatch::movePoints() else { // Scale the mesh flux according to the area fraction - const face& fAMI = cyclicACMIPolyPatch_.localFaces()[facei]; + const face& fAMI = localFaces[facei]; // Note: using raw point locations to calculate the geometric // area - faces areas are currently scaled (decoupled from // mesh points) - const scalar geomArea = fAMI.mag(cyclicACMIPolyPatch_.localPoints()); + const scalar geomArea = fAMI.mag(localPoints); phip[facei] *= magSf()[facei]/geomArea; } } @@ -234,6 +238,9 @@ void Foam::cyclicACMIFvPatch::movePoints() scalarField& nbrPhiNonOverlapp = meshPhiBf[nbrNonOverlapPatch.patch().index()]; + const auto& nbrLocalFaces = nbrACMI.patch().localFaces(); + const auto& nbrLocalPoints = nbrACMI.patch().localPoints(); + forAll(nbrPhip, facei) { if (newTgtAddr[facei].empty()) @@ -242,12 +249,12 @@ void Foam::cyclicACMIFvPatch::movePoints() } else { - const face& fAMI = nbrACMI.patch().localFaces()[facei]; + const face& fAMI = nbrLocalFaces[facei]; // Note: using raw point locations to calculate the geometric // area - faces areas are currently scaled (decoupled from // mesh points) - const scalar geomArea = fAMI.mag(nbrACMI.patch().localPoints()); + const scalar geomArea = fAMI.mag(nbrLocalPoints); nbrPhip[facei] *= nbrACMI.magSf()[facei]/geomArea; } } diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C index a9c03e340c..baba50933c 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -123,7 +124,7 @@ Foam::tmp Foam::cyclicAMIFvPatch::delta() const const vectorField& nbrPatchD = tnbrPatchD(); - tmp tpdv(new vectorField(patchD.size())); + auto tpdv = tmp::New(patchD.size()); vectorField& pdv = tpdv.ref(); // do the transformation if necessary diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H index 4245dd4be8..4d9daf3852 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.H @@ -159,8 +159,8 @@ public: } //- Return true if this patch is coupled. This is equivalent - // to the coupledPolyPatch::coupled() if parallel running or - // both sides present, false otherwise + //- to the coupledPolyPatch::coupled() if parallel running or + //- both sides present, false otherwise virtual bool coupled() const; //- Return delta (P to N) vectors across coupled patch @@ -190,7 +190,7 @@ public: // Interface transfer functions //- Return the values of the given internal data adjacent to - // the interface as a field + //- the interface as a field virtual tmp interfaceInternalField ( const labelUList& internalData diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index eaf1ebeb5a..f01f8570da 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2018 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,81 +27,104 @@ License \*---------------------------------------------------------------------------*/ #include "AMIInterpolation.H" -#include "AMIMethod.H" #include "meshTools.H" #include "mapDistribute.H" #include "flipOp.H" #include "profiling.H" - -#define DEBUGAMI(msg){Pout<< "[" << __FILE__ << ":" << __LINE__ << "]: " << #msg << "=" << msg << endl;} +#include "triPointRef.H" +#include "OFstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -template -const Foam::Enum -< - typename Foam::AMIInterpolation:: - interpolationMethod -> -Foam::AMIInterpolation::interpolationMethodNames_ -({ - { interpolationMethod::imNearestFace, "nearestFaceAMI" }, - { interpolationMethod::imFaceAreaWeight, "faceAreaWeightAMI" }, - { interpolationMethod::imPartialFaceAreaWeight, "partialFaceAreaWeightAMI" } -}); - - -template -bool Foam::AMIInterpolation::cacheIntersections_ = - false; - - -template -template -Foam::tmp -Foam::AMIInterpolation::patchMagSf -( - const Patch& patch, - const faceAreaIntersect::triangulationMode triMode -) +namespace Foam { - auto tResult = tmp::New(patch.size(), Zero); - scalarField& result = tResult.ref(); + defineTypeNameAndDebug(AMIInterpolation, 0); + defineRunTimeSelectionTable(AMIInterpolation, dict); + defineRunTimeSelectionTable(AMIInterpolation, component); +} - const pointField& patchPoints = patch.localPoints(); +bool Foam::AMIInterpolation::cacheIntersections_ = false; - faceList patchFaceTris; - forAll(result, patchFacei) - { - faceAreaIntersect::triangulate +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::autoPtr> +Foam::AMIInterpolation::createTree +( + const primitivePatch& patch +) const +{ + treeBoundBox bb(patch.points(), patch.meshPoints()); + bb.inflate(0.01); + + return autoPtr>::New + ( + treeType ( - patch.localFaces()[patchFacei], - patchPoints, - triMode, - patchFaceTris - ); - - forAll(patchFaceTris, i) - { - result[patchFacei] += - triPointRef - ( - patchPoints[patchFaceTris[i][0]], - patchPoints[patchFaceTris[i][1]], - patchPoints[patchFaceTris[i][2]] - ).mag(); - } - } - - return tResult; + false, + patch, + indexedOctree::perturbTol() + ), + bb, // overall search domain + 8, // maxLevel + 10, // leaf size + 3.0 // duplicity + ); } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +Foam::label Foam::AMIInterpolation::calcDistribution +( + const primitivePatch& srcPatch, + const primitivePatch& tgtPatch +) const +{ + label proci = 0; -template -void Foam::AMIInterpolation::projectPointsToSurface + if (Pstream::parRun()) + { + labelList facesPresentOnProc(Pstream::nProcs(), Zero); + if ((srcPatch.size() > 0) || (tgtPatch.size() > 0)) + { + facesPresentOnProc[Pstream::myProcNo()] = 1; + } + else + { + facesPresentOnProc[Pstream::myProcNo()] = 0; + } + + Pstream::gatherList(facesPresentOnProc); + Pstream::scatterList(facesPresentOnProc); + + label nHaveFaces = sum(facesPresentOnProc); + + if (nHaveFaces > 1) + { + proci = -1; + if (debug) + { + InfoInFunction + << "AMI split across multiple processors" << endl; + } + } + else if (nHaveFaces == 1) + { + proci = facesPresentOnProc.find(1); + if (debug) + { + InfoInFunction + << "AMI local to processor" << proci << endl; + } + } + } + + + // Either not parallel or no faces on any processor + return proci; +} + + +void Foam::AMIInterpolation::projectPointsToSurface ( const searchableSurface& surf, pointField& pts @@ -141,8 +164,7 @@ void Foam::AMIInterpolation::projectPointsToSurface } -template -void Foam::AMIInterpolation::normaliseWeights +void Foam::AMIInterpolation::normaliseWeights ( const scalarList& patchAreas, const word& patchName, @@ -170,7 +192,6 @@ void Foam::AMIInterpolation::normaliseWeights scalar s = sum(w); scalar t = s/denom; - if (conformal) { denom = s; @@ -182,10 +203,9 @@ void Foam::AMIInterpolation::normaliseWeights } wghtSum[facei] = t; - if (t < lowWeightTol) { - nLowWeight++; + ++nLowWeight; } } else @@ -194,7 +214,6 @@ void Foam::AMIInterpolation::normaliseWeights } } - if (output) { const label nFace = returnReduce(wght.size(), sumOp