From 0cf4aede6eaf357a382f6c91dcd1eac69ec37e64 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 11 May 2021 07:30:00 +0200 Subject: [PATCH] ENH: initial revamp of faMesh to improve modularity (#2084) - improved separation of patch creation that is also parallel-aware, which now allows creation in parallel - memory-safe use of PtrList for adding patches, with a more generalized faPatchData helper - use uindirectPrimitivePatch instead of indirectPrimitivePatch for internal patch handling. - align boundary methods with polyMesh equivalents - system/faMeshDefinition instead of constant/faMesh/faMeshDefinition as per blockMesh convention. Easier to manage definitions, easier for cleanup. - drop inheritence from GeoMesh. --- .../finiteArea/makeFaMesh/Make/options | 6 +- .../finiteArea/makeFaMesh/decomposeFaFields.H | 23 + .../makeFaMesh/findMeshDefinitionDict.H | 97 ++ .../finiteArea/makeFaMesh/makeFaMesh.C | 307 +------ .../decomposePar/faMeshDecomposition.C | 122 +-- .../foamToVTK/writeAreaFields.H | 4 +- .../interfaceTrackingFvMesh.C | 4 +- src/finiteArea/Make/files | 2 + .../faMesh/faBoundaryMesh/faBoundaryMesh.C | 109 ++- .../faMesh/faBoundaryMesh/faBoundaryMesh.H | 117 ++- src/finiteArea/faMesh/faMesh.C | 853 ++++-------------- src/finiteArea/faMesh/faMesh.H | 198 ++-- .../faMesh/faMeshDemandDrivenData.C | 111 +-- src/finiteArea/faMesh/faMeshI.H | 142 +++ src/finiteArea/faMesh/faMeshPatches.C | 572 ++++++++++++ src/finiteArea/faMesh/faMeshUpdate.C | 9 +- .../faPatches/basic/coupled/coupledFaPatch.C | 6 - .../faPatches/basic/coupled/coupledFaPatch.H | 2 +- .../faPatches/constraint/empty/emptyFaPatch.C | 41 +- .../faPatches/constraint/empty/emptyFaPatch.H | 20 +- .../constraint/processor/processorFaPatch.H | 3 +- .../constraint/symmetry/symmetryFaPatch.C | 2 +- .../faPatches/constraint/wedge/wedgeFaPatch.C | 18 +- .../faMesh/faPatches/faPatch/faPatch.C | 78 +- .../faMesh/faPatches/faPatch/faPatch.H | 35 +- .../faMesh/faPatches/faPatch/faPatchData.C | 130 +++ .../faMesh/faPatches/faPatch/faPatchData.H | 88 +- .../faPatch/faPatchFaMeshTemplates.C | 7 +- 28 files changed, 1757 insertions(+), 1349 deletions(-) create mode 100644 applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H create mode 100644 applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H create mode 100644 src/finiteArea/faMesh/faMeshI.H create mode 100644 src/finiteArea/faMesh/faMeshPatches.C create mode 100644 src/finiteArea/faMesh/faPatches/faPatch/faPatchData.C diff --git a/applications/utilities/finiteArea/makeFaMesh/Make/options b/applications/utilities/finiteArea/makeFaMesh/Make/options index 98ba4f7225..3300bd23e7 100644 --- a/applications/utilities/finiteArea/makeFaMesh/Make/options +++ b/applications/utilities/finiteArea/makeFaMesh/Make/options @@ -1,8 +1,12 @@ EXE_INC = \ -I$(LIB_SRC)/finiteArea/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/cfdTools/general/lnInclude EXE_LIBS = \ -lfiniteArea \ - -lfiniteVolume + -lfiniteVolume \ + -lfileFormats \ + -lmeshTools diff --git a/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H b/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H new file mode 100644 index 0000000000..23b0c2c1e6 --- /dev/null +++ b/applications/utilities/finiteArea/makeFaMesh/decomposeFaFields.H @@ -0,0 +1,23 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. + +Description + placeholder for decomposing fields + +\*---------------------------------------------------------------------------*/ + +if (Pstream::parRun()) +{ +} + + +// ************************************************************************* // diff --git a/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H b/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H new file mode 100644 index 0000000000..8a678fdcc8 --- /dev/null +++ b/applications/utilities/finiteArea/makeFaMesh/findMeshDefinitionDict.H @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM, distributed under GPL-3.0-or-later. + +Description + Search for the appropriate faMeshDefinition dictionary.... + +\*---------------------------------------------------------------------------*/ + +const word dictName("faMeshDefinition"); + +autoPtr meshDictPtr; + +{ + fileName dictPath; + + const word& regionDir = + (regionName == polyMesh::defaultRegion ? word::null : regionName); + + if (args.readIfPresent("dict", dictPath)) + { + // Dictionary specified on the command-line ... + + if (isDir(dictPath)) + { + dictPath /= dictName; + } + } + else if + ( + // Check global location + exists + ( + runTime.path()/runTime.caseConstant() + /regionDir/faMesh::meshSubDir/dictName + ) + ) + { + // Dictionary present in constant faMesh directory (old-style) + + dictPath = + runTime.constant() + /regionDir/faMesh::meshSubDir/dictName; + + // Warn that constant/faMesh/faMeshDefinition was used + // instead of system/faMeshDefinition + #if 0 + WarningIn(args.executable()) + << "Using the old faMeshDefinition location: " + << dictPath << nl + << " instead of default location: " + << runTime.system()/regionDir/dictName << nl + << endl; + #endif + } + else + { + // Assume dictionary is in the system directory + + dictPath = runTime.system()/regionDir/dictName; + } + + IOobject meshDictIO + ( + dictPath, + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false, // no registerObject + true // is globalObject + ); + + if (!meshDictIO.typeHeaderOk(true)) + { + FatalErrorInFunction + << meshDictIO.objectPath() << nl + << exit(FatalError); + } + + Info<< "Creating faMesh from definition: " + << runTime.relativePath(meshDictIO.objectPath()) << endl; + + meshDictPtr = autoPtr::New(meshDictIO); +} + +IOdictionary& meshDefDict = *meshDictPtr; + + +// ************************************************************************* // diff --git a/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C b/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C index 0010be3dab..2751ca3154 100644 --- a/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C +++ b/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,30 +42,12 @@ Author #include "OSspecific.H" #include "faMesh.H" #include "fvMesh.H" +#include "IOdictionary.H" +#include "globalIndex.H" +#include "globalMeshData.H" using namespace Foam; -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -class faPatchData -{ -public: - word name_; - word type_; - dictionary dict_; - label ownPolyPatchID_; - label ngbPolyPatchID_; - labelList edgeLabels_; - faPatchData() - : - name_(word::null), - type_(word::null), - ownPolyPatchID_(-1), - ngbPolyPatchID_(-1) - {} -}; - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) @@ -73,286 +56,40 @@ int main(int argc, char *argv[]) ( "A mesh generator for finiteArea mesh" ); + argList::addOption + ( + "empty-patch", + "name", + "Specify name for a default empty patch", + false // An advanced option, but not enough to worry about that + ); + argList::addOption("dict", "file", "Alternative faMeshDefinition"); #include "addRegionOption.H" - argList::noParallel(); - #include "setRootCase.H" #include "createTime.H" #include "createNamedMesh.H" // Reading faMeshDefinition dictionary - IOdictionary faMeshDefinition - ( - IOobject - ( - "faMeshDefinition", - runTime.constant(), - "faMesh", - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ); + #include "findMeshDefinitionDict.H" - wordList polyMeshPatches - ( - faMeshDefinition.get("polyMeshPatches") - ); - - const dictionary& bndDict = faMeshDefinition.subDict("boundary"); - - const wordList faPatchNames(bndDict.toc()); - - List faPatches(faPatchNames.size()+1); - - forAll(faPatchNames, patchI) + // Inject/overwrite name for optional 'empty' patch + word patchName; + if (args.readIfPresent("empty-patch", patchName)) { - const dictionary& curPatchDict = bndDict.subDict(faPatchNames[patchI]); - - faPatches[patchI].name_ = faPatchNames[patchI]; - - faPatches[patchI].type_ = curPatchDict.get("type"); - - const word ownName(curPatchDict.get("ownerPolyPatch")); - - faPatches[patchI].ownPolyPatchID_ = - mesh.boundaryMesh().findPatchID(ownName); - - if (faPatches[patchI].ownPolyPatchID_ < 0) - { - FatalErrorIn("makeFaMesh:") - << "neighbourPolyPatch " << ownName << " does not exist" - << exit(FatalError); - } - - const word neiName(curPatchDict.get("neighbourPolyPatch")); - - faPatches[patchI].ngbPolyPatchID_ = - mesh.boundaryMesh().findPatchID(neiName); - - if (faPatches[patchI].ngbPolyPatchID_ < 0) - { - FatalErrorIn("makeFaMesh:") - << "neighbourPolyPatch " << neiName << " does not exist" - << exit(FatalError); - } + meshDefDict.add("emptyPatch", patchName, true); } - // Setting faceLabels list size - label size = 0; - - labelList patchIDs(polyMeshPatches.size(), -1); - - forAll(polyMeshPatches, patchI) - { - patchIDs[patchI] = - mesh.boundaryMesh().findPatchID(polyMeshPatches[patchI]); - - if (patchIDs[patchI] < 0) - { - FatalErrorIn("makeFaMesh:") - << "Patch " << polyMeshPatches[patchI] << " does not exist" - << exit(FatalError); - } - - size += mesh.boundaryMesh()[patchIDs[patchI]].size(); - } - - labelList faceLabels(size, -1); - - sort(patchIDs); - - - // Filling of faceLabels list - label faceI = -1; - - forAll(polyMeshPatches, patchI) - { - label start = mesh.boundaryMesh()[patchIDs[patchI]].start(); - - label size = mesh.boundaryMesh()[patchIDs[patchI]].size(); - - for (label i = 0; i < size; ++i) - { - faceLabels[++faceI] = start + i; - } - } - - // Creating faMesh - Info << "Create faMesh ... "; - - faMesh areaMesh - ( - mesh, - faceLabels - ); - Info << "Done" << endl; - - - // Determination of faPatch ID for each boundary edge. - // Result is in the bndEdgeFaPatchIDs list - const indirectPrimitivePatch& patch = areaMesh.patch(); - - labelList faceCells(faceLabels.size(), -1); - - forAll(faceCells, faceI) - { - label faceID = faceLabels[faceI]; - - faceCells[faceI] = mesh.faceOwner()[faceID]; - } - - labelList meshEdges = - patch.meshEdges - ( - mesh.edges(), - mesh.cellEdges(), - faceCells - ); - - const labelListList& edgeFaces = mesh.edgeFaces(); - - const label nTotalEdges = patch.nEdges(); - const label nInternalEdges = patch.nInternalEdges(); - - labelList bndEdgeFaPatchIDs(nTotalEdges - nInternalEdges, -1); - - for (label edgeI = nInternalEdges; edgeI < nTotalEdges; ++edgeI) - { - label curMeshEdge = meshEdges[edgeI]; - - labelList curEdgePatchIDs(2, label(-1)); - - label patchI = -1; - - forAll(edgeFaces[curMeshEdge], faceI) - { - label curFace = edgeFaces[curMeshEdge][faceI]; - - label curPatchID = mesh.boundaryMesh().whichPatch(curFace); - - if (curPatchID != -1) - { - curEdgePatchIDs[++patchI] = curPatchID; - } - } - - for (label pI = 0; pI < faPatches.size() - 1; ++pI) - { - if - ( - ( - curEdgePatchIDs[0] == faPatches[pI].ownPolyPatchID_ - && curEdgePatchIDs[1] == faPatches[pI].ngbPolyPatchID_ - ) - || - ( - curEdgePatchIDs[1] == faPatches[pI].ownPolyPatchID_ - && curEdgePatchIDs[0] == faPatches[pI].ngbPolyPatchID_ - ) - ) - { - bndEdgeFaPatchIDs[edgeI - nInternalEdges] = pI; - break; - } - } - } - - - // Set edgeLabels for each faPatch - for (label pI=0; pI<(faPatches.size()-1); ++pI) - { - SLList