From 942ecf88c1e47ed2120b1ae8e622ac66c6ebd1c6 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Tue, 24 Apr 2018 11:05:21 +0100 Subject: [PATCH] Load balancing support, fvMesh --- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.C | 58 ++++++++++++++----- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.H | 5 ++ src/finiteVolume/fvMesh/fvMesh.C | 38 +++++++++++- src/finiteVolume/fvMesh/fvMesh.H | 19 ++++++ src/finiteVolume/fvMesh/fvMeshGeometry.C | 6 +- .../fvMesh/fvPatches/fvPatch/fvPatch.C | 3 +- 6 files changed, 109 insertions(+), 20 deletions(-) diff --git a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C index 264a8620d..c8cf5195a 100644 --- a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C +++ b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C @@ -27,33 +27,63 @@ License #include "fvBoundaryMesh.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void fvBoundaryMesh::addFvPatches() +void Foam::fvBoundaryMesh::addFvPatches() { const polyBoundaryMesh& bMesh = mesh_.boundaryMesh(); - + + // Clear existing patches and resize the list + clear(); setSize(bMesh.size()); // Set boundary patches, using the patches added to the polyMesh // Bug fix. HJ, 1/Mar/2018 fvPatchList& Patches = *this; - forAll(Patches, patchI) + forAll (Patches, patchI) { Patches.set(patchI, fvPatch::New(bMesh[patchI], *this)); } } +void Foam::fvBoundaryMesh::resetFvPatches(const boolList& resetFvPatchFlag) +{ + const polyBoundaryMesh& bMesh = mesh_.boundaryMesh(); + + if (resetFvPatchFlag.size() != bMesh.size()) + { + FatalErrorIn("void resetFvPatches(const boolList& resetFvPatchFlag)") + << "Incorrect size of reset list. Boundary size: " + << bMesh.size() << " reset size: " << resetFvPatchFlag.size() + << abort(FatalError); + } + + // Reset list size. This will delete pointers to patches + // if the list is truncated + setSize(bMesh.size()); + + // Set boundary patches, using the patches added to the polyMesh + // Bug fix. HJ, 1/Mar/2018 + fvPatchList& Patches = *this; + + // In order to preserve patch links on resize of boundary, + // only reset the empty slots + forAll (Patches, patchI) + { + if (resetFvPatchFlag[patchI]) + { + // Set new patch. This also deletes old pointer + Patches.set(patchI, fvPatch::New(bMesh[patchI], *this)); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -fvBoundaryMesh::fvBoundaryMesh +Foam::fvBoundaryMesh::fvBoundaryMesh ( const fvMesh& m ) @@ -67,7 +97,7 @@ fvBoundaryMesh::fvBoundaryMesh // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void fvBoundaryMesh::movePoints() +void Foam::fvBoundaryMesh::movePoints() { forAll(*this, patchi) { @@ -81,7 +111,7 @@ void fvBoundaryMesh::movePoints() } -lduInterfacePtrsList fvBoundaryMesh::interfaces() const +Foam::lduInterfacePtrsList Foam::fvBoundaryMesh::interfaces() const { lduInterfacePtrsList interfaces(size()); @@ -101,15 +131,11 @@ lduInterfacePtrsList fvBoundaryMesh::interfaces() const } -void fvBoundaryMesh::readUpdate() +void Foam::fvBoundaryMesh::readUpdate() { clear(); addFvPatches(); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.H b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.H index e9e5d55f4..e6a420db3 100644 --- a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.H +++ b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.H @@ -73,6 +73,11 @@ private: //- Add fvPatches corresponding to the polyBoundaryMesh void addFvPatches(); + //- Reset fvPatches corresponding to the polyBoundaryMesh + // When the mesh is resized, the existing patches may be preserved + // or reset depending on the resetFlag + void resetFvPatches(const boolList& resetFvPatchFlag); + protected: diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index f5b87e4b1..713cfc919 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -392,13 +392,49 @@ void Foam::fvMesh::removeFvBoundary() // Remove fvBoundaryMesh data first. boundary_.clear(); - boundary_.setSize(0); polyMesh::removeBoundary(); clearOut(); } +void Foam::fvMesh::resetFvPrimitives +( + const Xfer& points, + const Xfer& faces, + const Xfer& owner, + const Xfer& neighbour, + const labelList& patchSizes, + const labelList& patchStarts, + const boolList& resetFvPatchFlag, + const bool validBoundary +) +{ + // Reset polyMesh primitives + polyMesh::resetPrimitives + ( + points, + faces, + owner, + neighbour, + patchSizes, + patchStarts, + validBoundary + ); + + boundary_.resetFvPatches(resetFvPatchFlag); + surfaceInterpolation::clearOut(); + clearGeomNotOldVol(); + + // Reset fvPatches? HJ, 16/Apr/2018 + + // Clear LDU + clearAddressing(); + + // Clear cell volumes? +} + + Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate() { if (debug) diff --git a/src/finiteVolume/fvMesh/fvMesh.H b/src/finiteVolume/fvMesh/fvMesh.H index 22f973efc..90d23af20 100644 --- a/src/finiteVolume/fvMesh/fvMesh.H +++ b/src/finiteVolume/fvMesh/fvMesh.H @@ -360,6 +360,25 @@ public: // these fvPatches. void removeFvBoundary(); + //- Reset mesh primitive data. Assumes all patch info correct + // (so does e.g. parallel communication). If not, use + // validBoundary = false + // (still assumes patchStarts[0] = nInternalFaces and last + // patch ends at nActiveFaces) and change patches with addPatches. + // resetFvPatchFlag indicates which fvPatches will be rebuilt + // if the flag is set to false, original patch is preserved + void resetFvPrimitives + ( + const Xfer& points, + const Xfer& faces, + const Xfer& owner, + const Xfer& neighbour, + const labelList& patchSizes, + const labelList& patchStarts, + const boolList& resetFvPatchFlag, + const bool validBoundary = true + ); + //- Return cell face motion fluxes surfaceScalarField& setPhi(); diff --git a/src/finiteVolume/fvMesh/fvMeshGeometry.C b/src/finiteVolume/fvMesh/fvMeshGeometry.C index e5286a3fb..6f83ec2ee 100644 --- a/src/finiteVolume/fvMesh/fvMeshGeometry.C +++ b/src/finiteVolume/fvMesh/fvMeshGeometry.C @@ -155,7 +155,8 @@ void fvMesh::makeC() const *this, dimLength, cellCentres(), - faceCentres() + faceCentres(), + false // Do not preserve couples in geometry fields ); // This piece of code is necessary for cyclic and cyclicGgi interfaces @@ -231,7 +232,8 @@ void fvMesh::makeCf() const ), *this, dimLength, - faceCentres() + faceCentres(), + false // Do not preserve couples in geometry fields ); // Boundary update. Used in complex geometries, eg. immersed boundary diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C index 4fd439f4e..fc99a18f6 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C @@ -146,7 +146,8 @@ tmp fvPatch::Cn() const // Get reference to global cell centres // Bugfix: access cell centres from fvMesh data, not polyMesh. // HJ, 30/Nov/2017 - const vectorField& gcc = boundaryMesh().mesh().C().internalField(); + // const vectorField& gcc = boundaryMesh().mesh().C().internalField(); + const vectorField& gcc = boundaryMesh().mesh().cellCentres(); forAll (faceCells, faceI) {