From 737dee570544f239c3537d9abdbe3e618863aa57 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 16 May 2018 11:19:31 +0100 Subject: [PATCH] Changed resizing mechanism in load balancing topo change --- .../topoChangerFvMesh/topoChangerFvMesh.H | 4 +- .../topoChangerFvMeshLoadBalance.C | 64 +++++++++++++++++-- .../topoChangerFvMeshLoadBalanceTemplates.C | 22 +++++-- 3 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMesh.H b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMesh.H index 2d7c72760..75c1d5ffe 100644 --- a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMesh.H +++ b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMesh.H @@ -40,6 +40,8 @@ SourceFiles #include "dynamicFvMesh.H" #include "polyTopoChanger.H" +#include "mapPolyMesh.H" +#include "fvMeshMapper.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -100,7 +102,7 @@ class topoChangerFvMesh const HashTable& geoFields, const Reconstructor& reconstructor, const List >& receivedFields, - const boolList& patchesToReplace + const mapPolyMesh& meshMap ) const; diff --git a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalance.C b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalance.C index 4a689a1d8..ca7ec14bc 100644 --- a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalance.C +++ b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalance.C @@ -28,10 +28,8 @@ License #include "fvFieldDecomposer.H" #include "processorMeshesReconstructor.H" #include "fvFieldReconstructor.H" -#include "mapPolyMesh.H" -#include "addToRunTimeSelectionTable.H" - #include "passiveProcessorPolyPatch.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -543,6 +541,60 @@ bool Foam::topoChangerFvMesh::loadBalance(const dictionary& decompDict) } } + // Create mesh map. Note: map is dummy and it is used only for resizing + // HJ, 16/May/2018 + const polyBoundaryMesh& patches = boundaryMesh(); + labelList patchStarts(patches.size()); + labelList oldPatchNMeshPoints(patches.size()); + labelListList patchPointMap(patches.size()); + forAll(patches, patchI) + { + patchStarts[patchI] = patches[patchI].start(); + oldPatchNMeshPoints[patchI] = patches[patchI].nPoints(); + patchPointMap[patchI].setSize(patches[patchI].nPoints(), -1); + } + + mapPolyMesh meshMap + ( + *this, // const polyMesh& mesh, + nPoints(), // nOldPoints, + nFaces(), // nOldFaces, + nCells(), // nOldCells, + + labelList(reconMesh.nPoints(), -1), // pointMap, + List(0), // pointsFromPoints, + + labelList(reconMesh.nFaces(), -1), // faceMap, + List(0), // facesFromPoints, + List(0), // facesFromEdges, + List(0), // facesFromFaces, + + labelList(), // cellMap, + List(0), // cellsFromPoints, + List(0), // cellsFromEdges, + List(0), // cellsFromFaces, + List(0), // cellsFromCells, + + labelList(nPoints(), -1), // reversePointMap, + labelList(nFaces(), -1), // reverseFaceMap, + labelList(nCells(), -1), // reverseCellMap, + + labelHashSet(0), // flipFaceFlux, + + labelListList(0), // patchPointMap, + labelListList(0), // pointZoneMap, + labelListList(0), // faceZonePointMap, + labelListList(0), // faceZoneFaceMap, + labelListList(0), // cellZoneMap, + + resetFvPatchFlag, // resetPatchFlag + + pointField(0), // preMotionPoints, + patchStarts, // oldPatchStarts, + oldPatchNMeshPoints // oldPatchNMeshPoints + ); + + // Reset fvMesh and patches resetFvPrimitives ( @@ -573,7 +625,7 @@ bool Foam::topoChangerFvMesh::loadBalance(const dictionary& decompDict) volScalarFields, fieldReconstructor, receivedVolScalarFields, - resetFvPatchFlag + meshMap ); rebuildFields @@ -581,7 +633,7 @@ bool Foam::topoChangerFvMesh::loadBalance(const dictionary& decompDict) volVectorFields, fieldReconstructor, receivedVolVectorFields, - resetFvPatchFlag + meshMap ); rebuildFields @@ -589,7 +641,7 @@ bool Foam::topoChangerFvMesh::loadBalance(const dictionary& decompDict) surfaceScalarFields, fieldReconstructor, receivedSurfaceScalarFields, - resetFvPatchFlag + meshMap ); // Debug diff --git a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalanceTemplates.C b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalanceTemplates.C index 992d1b6ac..5b1470f42 100644 --- a/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalanceTemplates.C +++ b/src/dynamicMesh/topoChangerFvMesh/topoChangerFvMesh/topoChangerFvMeshLoadBalanceTemplates.C @@ -157,11 +157,14 @@ void Foam::topoChangerFvMesh::rebuildFields const HashTable& geoFields, const Reconstructor& reconstructor, const List >& receivedFields, - const boolList& patchesToReplace + const mapPolyMesh& meshMap ) const { label fieldI = 0; + // Make an fvMesh mapper + const fvMeshMapper mapper(*this, meshMap); + forAllConstIter ( typename HashTable, @@ -221,12 +224,17 @@ void Foam::topoChangerFvMesh::rebuildFields " const HashTable& geoFields,\n" " const Reconstructor& reconstructor,\n" " const List >& receivedFields,\n" + " const mapPolyMesh& meshMap,\n" ") const" ) << "Name mismatch when rebuilding field " << masterField.name() << abort(FatalError); } - if (patchesToReplace.size() != masterField.mesh().boundary().size()) + if + ( + meshMap.resetPatchFlag().size() + != masterField.mesh().boundary().size() + ) { FatalErrorIn ( @@ -235,10 +243,11 @@ void Foam::topoChangerFvMesh::rebuildFields " const HashTable& geoFields,\n" " const Reconstructor& reconstructor,\n" " const List >& receivedFields,\n" + " const mapPolyMesh& meshMap,\n" ") const" ) << "Bad size of patches to replace. Boundary: " << masterField.mesh().boundary().size() - << " patchesToReplace: " << patchesToReplace.size() + << " resetPatchFlag: " << meshMap.resetPatchFlag().size() << abort(FatalError); } @@ -280,7 +289,7 @@ void Foam::topoChangerFvMesh::rebuildFields // Resize patch fields forAll (patchFields, patchI) { - if (patchesToReplace[patchI]) + if (meshMap.resetPatchFlag()[patchI]) { // Create a new constrained patch field Pout<< "Inserting constrained patch field for patch " @@ -319,9 +328,10 @@ void Foam::topoChangerFvMesh::rebuildFields << masterField.mesh().boundary()[patchI].size() << endl; - patchFields[patchI].resetSize + // Reset patch field size + patchFields[patchI].autoMap ( - masterField.mesh().boundary()[patchI].size() + mapper.boundaryMap()[patchI] ); } }