diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C index 888281fb13..1f38a37854 100644 --- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C +++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,7 +45,6 @@ Description #include "cyclicPolyPatch.H" #include "syncTools.H" #include "argList.H" -#include "polyMesh.H" #include "Time.H" #include "OFstream.H" #include "meshTools.H" @@ -56,6 +55,10 @@ Description #include "wordRes.H" #include "processorMeshes.H" #include "IOdictionary.H" +#include "regionProperties.H" +#include "faceAreaWeightAMI2D.H" +#include "fvMeshTools.H" +#include "ReadFields.H" using namespace Foam; @@ -66,9 +69,294 @@ namespace Foam defineTemplateTypeNameAndDebug(IOPtrList, 0); } + +word patchName(const word& name, const fvMesh& mesh0, const fvMesh& mesh1) +{ + word pName(name != "none" ? name : word::null); + pName += mesh0.name(); + pName += "_to_"; + pName += mesh1.name(); + return pName; +} + + +void matchPatchFaces +( + const word& entryName, + const word& AMIMethod, + const dictionary& AMIDict, + const PtrList& meshes, + + const label meshi, + const label nSourcei, + const label sourcei, + const labelList& patchesi, + + const label meshj, + const label nSourcej, + const label sourcej, + const labelList& patchesj, + + DynamicList& interfaceMesh0, + DynamicList& interfacePatch0, + DynamicList& interfaceNames0, + DynamicList>>& interfaceFaces0, + + DynamicList& interfaceMesh1, + DynamicList& interfacePatch1, + DynamicList& interfaceNames1, + DynamicList>>& interfaceFaces1 +) +{ + // Now we have: + // - meshi, sourcei, patchesi + // - meshj, sourcej, patchesj + + + // Attempt to match patches + forAll(patchesi, i) + { + const auto& ppi = meshes[meshi].boundaryMesh()[patchesi[i]]; + + forAll(patchesj, j) + { + const auto& ppj = meshes[meshj].boundaryMesh()[patchesj[j]]; + + // Use AMI to try and find matches + auto AMPtr(AMIInterpolation::New(AMIMethod, AMIDict)); + + AMPtr->calculate(ppi, ppj, nullptr); + if + ( + gAverage(AMPtr->tgtWeightsSum()) > SMALL + || gAverage(AMPtr->srcWeightsSum()) > SMALL + ) + { + const label inti = interfaceMesh0.size(); + + Info<< "Introducing interface " << inti << " between" + << " mesh " << meshes[meshi].name() + << " patch " << ppi.name() + << " and mesh " << meshes[meshj].name() + << " patch " << ppj.name() + << endl; + + // Mesh 0 + //~~~~~~~ + + interfaceMesh0.append(labelList()); + auto& intMesh0 = interfaceMesh0.last(); + intMesh0.setSize(nSourcei, -1); + intMesh0[sourcei] = meshi; + + interfacePatch0.append(labelList()); + auto& intPatch0 = interfacePatch0.last(); + intPatch0.setSize(nSourcei, -1); + intPatch0[sourcei] = ppi.index(); + + interfaceNames0.append(wordList()); + auto& intNames0 = interfaceNames0.last(); + intNames0.setSize(nSourcei); + //intNames0[sourcei] = + // meshes[meshi].name() + // + "_to_" + // + meshes[meshj].name(); + intNames0[sourcei] = + patchName(entryName, meshes[meshi], meshes[meshj]); + + + // Mesh 0 + //~~~~~~~ + + interfaceMesh1.append(labelList()); + auto& intMesh1 = interfaceMesh1.last(); + intMesh1.setSize(nSourcej, -1); + intMesh1[sourcej] = meshj; + + interfacePatch1.append(labelList()); + auto& intPatch1 = interfacePatch1.last(); + intPatch1.setSize(nSourcej, -1); + intPatch1[sourcej] = ppj.index(); + + interfaceNames1.append(wordList()); + auto& intNames1 = interfaceNames1.last(); + intNames1.setSize(nSourcej); + //intNames1[sourcej] = + // meshes[meshj].name() + // + "_to_" + // + meshes[meshi].name(); + intNames1[sourcej] = + patchName(entryName, meshes[meshj], meshes[meshi]); + + interfaceFaces0.append(List>()); + auto& intFaces0 = interfaceFaces0.last(); + intFaces0.setSize(nSourcei); + DynamicList