From 9dada5f3f204cfb2d2041644b851c14916fd3c1d Mon Sep 17 00:00:00 2001 From: HenningScheufler Date: Wed, 12 May 2021 14:32:53 +0200 Subject: [PATCH] ENH: geoVoF module has the capability to run AMR with load balancing code style and quality improvements renamed recon::centre to interfaceCentre.{groupName} ranmed recon::normal to interfaceNormal.{groupName} centre and normal field are not written by default --- .../fvMesh/zoneDistribute/zoneDistribute.C | 45 +++---- .../fvMesh/zoneDistribute/zoneDistribute.H | 25 ++-- .../fvMesh/zoneDistribute/zoneDistributeI.H | 13 +- .../zoneStencils/zoneCPCStencil.C | 29 +++-- .../zoneStencils/zoneCPCStencil.H | 18 ++- .../zoneStencils/zoneCellStencils.C | 54 +++----- .../zoneStencils/zoneCellStencils.H | 38 +++--- src/functionObjects/field/setFlow/setFlow.C | 60 ++++----- .../isoAdvection/isoAdvection.C | 115 +++++++++++------- .../isoAdvection/isoAdvection.H | 24 ++-- .../isoAdvection/isoAdvectionTemplates.C | 60 +++++---- .../geometricVoF/cellCuts/cutCell/cutCell.C | 32 ++++- .../geometricVoF/cellCuts/cutCell/cutCell.H | 2 +- .../cellCuts/cutCell/cutCellIso.C | 46 +------ .../cellCuts/cutCell/cutCellIso.H | 41 +++++-- .../cellCuts/cutCell/cutCellPLIC.C | 46 +------ .../cellCuts/cutCell/cutCellPLIC.H | 35 ++++-- .../geometricVoF/cellCuts/cutFace/cutFace.C | 17 +-- .../cellCuts/cutFace/cutFaceAdvect.C | 28 +---- .../cellCuts/cutFace/cutFaceAdvect.H | 23 +++- .../cellCuts/cutFace/cutFaceIso.C | 24 ---- .../cellCuts/cutFace/cutFaceIso.H | 20 ++- .../cellCuts/cutFace/cutFacePLIC.C | 24 ---- .../cellCuts/cutFace/cutFacePLIC.H | 20 ++- .../reconstructedDistanceFunction.C | 5 +- .../reconstructedDistanceFunction.H | 4 +- .../plicSchemes/gradAlpha/gradAlpha.C | 15 +-- .../plicSchemes/gradAlpha/gradAlpha.H | 4 - .../plicSchemes/plicRDF/plicRDF.C | 58 ++++----- .../plicSchemes/plicRDF/plicRDF.H | 3 - .../reconstructionSchemes.C | 12 +- .../reconstructionSchemes.H | 24 +++- .../interIsoFoam/damBreak/system/fvSolution | 1 + 33 files changed, 481 insertions(+), 484 deletions(-) diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C index 3cafff4ff9..aad80178c0 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.C @@ -91,10 +91,11 @@ Foam::zoneDistribute::coupledFacesPatch() const Foam::zoneDistribute::zoneDistribute(const fvMesh& mesh) : - MeshObject(mesh), - stencil_(mesh), + MeshObject(mesh), coupledBoundaryPoints_(coupledFacesPatch()().meshPoints()), - send_(Pstream::nProcs()) + send_(Pstream::nProcs()), + stencil_(zoneCPCStencil::New(mesh)), + gblIdx_(stencil_.globalNumbering()) { } @@ -103,15 +104,11 @@ Foam::zoneDistribute::zoneDistribute(const fvMesh& mesh) Foam::zoneDistribute& Foam::zoneDistribute::New(const fvMesh& mesh) { - zoneDistribute* ptr = mesh.thisDb().getObjectPtr - ( - zoneDistribute::typeName - ); + auto* ptr = mesh.thisDb().getObjectPtr("zoneDistribute"); if (!ptr) { ptr = new zoneDistribute(mesh); - regIOobject::store(ptr); } @@ -123,24 +120,22 @@ Foam::zoneDistribute& Foam::zoneDistribute::New(const fvMesh& mesh) void Foam::zoneDistribute::updateStencil(const boolList& zone) { - stencil_.updateStencil(zone); + zoneCPCStencil::New(mesh_).updateStencil(zone); } -void Foam::zoneDistribute::setUpCommforZone -( - const boolList& zone, - bool updateStencil -) +void Foam::zoneDistribute::setUpCommforZone(const boolList& zone,bool updateStencil) { + zoneCPCStencil& stencil = zoneCPCStencil::New(mesh_); + if (updateStencil) { - stencil_.updateStencil(zone); + stencil.updateStencil(zone); } - const labelHashSet comms = stencil_.needsComm(); + const labelHashSet comms = stencil.needsComm(); - List needed_(Pstream::nProcs()); + List needed(Pstream::nProcs()); if (Pstream::parRun()) { @@ -150,11 +145,10 @@ void Foam::zoneDistribute::setUpCommforZone { for (const label gblIdx : stencil_[celli]) { - if (!globalNumbering().isLocal(gblIdx)) + if (!gblIdx_.isLocal(gblIdx)) { - const label procID = - globalNumbering().whichProcID(gblIdx); - needed_[procID].insert(gblIdx); + const label procID = gblIdx_.whichProcID (gblIdx); + needed[procID].insert(gblIdx); } } } @@ -170,7 +164,7 @@ void Foam::zoneDistribute::setUpCommforZone // Put data into send buffer UOPstream toDomain(domain, pBufs); - toDomain << needed_[domain]; + toDomain << needed[domain]; } } @@ -193,13 +187,6 @@ void Foam::zoneDistribute::setUpCommforZone } -void Foam::zoneDistribute::updateMesh(const mapPolyMesh& mpm) -{ - if (mesh_.topoChanging()) - { - coupledBoundaryPoints_ = coupledFacesPatch()().meshPoints(); - } -} // ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.H b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.H index dc432c7745..4edaf8b62b 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.H +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistribute.H @@ -64,12 +64,10 @@ namespace Foam class zoneDistribute : - public MeshObject + public MeshObject { // Private Data - //- cell-point-cell stencil elements are in global addressing - zoneCPCStencil stencil_; //- labels of the points on coupled patches labelList coupledBoundaryPoints_; @@ -80,6 +78,10 @@ class zoneDistribute //- Return patch of all coupled faces. autoPtr coupledFacesPatch() const; + zoneCPCStencil& stencil_; + + const globalIndex& gblIdx_; + //- Gives patchNumber and patchFaceNumber for a given //- Geometric volume field @@ -118,6 +120,11 @@ public: static zoneDistribute& New(const fvMesh&); + //- Destructor + + virtual ~zoneDistribute() = default; + + // Member Functions //- Update stencil with boolList the size has to match mesh nCells @@ -127,15 +134,15 @@ public: void updateStencil(const boolList& zone); //- Stencil reference - const labelListList& getStencil() + const labelListList& getStencil() noexcept { return stencil_; } //- Addressing reference - const globalIndex& globalNumbering() const + const globalIndex& globalNumbering() const noexcept { - return stencil_.globalNumbering(); + return gblIdx_; } //- Gives patchNumber and patchFaceNumber for a given @@ -164,13 +171,7 @@ public: const GeometricField& phi ); - virtual void updateMesh(const mapPolyMesh& mpm); - virtual bool movePoints() - { - // do nothing - return false; - } }; diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H index 2c733ec6bb..4dd0309075 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneDistributeI.H @@ -43,11 +43,8 @@ Type Foam::zoneDistribute::getLocalValue { return phi[localIdx]; } - else - { - return faceValue(phi,localIdx); - } + return faceValue(phi,localIdx); } @@ -88,9 +85,9 @@ Type Foam::zoneDistribute::getValue const label gblIdx ) const { - if (globalNumbering().isLocal(gblIdx)) + if (gblIdx_.isLocal(gblIdx)) { - const label idx = globalNumbering().toLocal(gblIdx); + const label idx = gblIdx_.toLocal(gblIdx); return getLocalValue(phi,idx); } else // from other proc @@ -115,7 +112,6 @@ Foam::Map> Foam::zoneDistribute::getFields << "do not match. Did the mesh change?" << exit(FatalError); - return Map>(); } @@ -160,7 +156,6 @@ Foam::Map Foam::zoneDistribute::getDatafromOtherProc << "do not match. Did the mesh change?" << exit(FatalError); - return Map(); } @@ -177,7 +172,7 @@ Foam::Map Foam::zoneDistribute::getDatafromOtherProc sendValues[domaini].insert ( sendIdx, - getLocalValue(phi,globalNumbering().toLocal(sendIdx)) + getLocalValue(phi,gblIdx_.toLocal(sendIdx)) ); } } diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.C b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.C index 1c91f5478a..c32751b733 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.C +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.C @@ -123,6 +123,7 @@ void Foam::zoneCPCStencil::calcPointBoundaryData Foam::zoneCPCStencil::zoneCPCStencil(const fvMesh& mesh) : + MeshObject(mesh), zoneCellStencils(mesh), nonEmptyBoundaryPoints_(nonEmptyFacesPatch()().meshPoints()), uptodate_(mesh.nCells(), false) @@ -131,6 +132,19 @@ Foam::zoneCPCStencil::zoneCPCStencil(const fvMesh& mesh) validBoundaryFaces(isValidBFace_); } +Foam::zoneCPCStencil& Foam::zoneCPCStencil::New(const fvMesh& mesh) +{ + auto* ptr = mesh.thisDb().getObjectPtr("zoneCPCStencil"); + + if (!ptr) + { + ptr = new zoneCPCStencil(mesh); + regIOobject::store(ptr); + } + + return *ptr; +} + void Foam::zoneCPCStencil::calculateStencil ( @@ -224,19 +238,4 @@ void Foam::zoneCPCStencil::calculateStencil } -void Foam::zoneCPCStencil::updateMesh(const mapPolyMesh& mpm) -{ - if (mesh_.topoChanging()) - { - // resize map and globalIndex - zoneCellStencils::updateMesh(mpm); - - nonEmptyBoundaryPoints_ = nonEmptyFacesPatch()().meshPoints(); - uptodate_.resize(mesh_.nCells()); - uptodate_ = false; - validBoundaryFaces(isValidBFace_); - } -} - - // ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.H b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.H index 318fa38d97..23fcb624c4 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.H +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCPCStencil.H @@ -58,6 +58,12 @@ namespace Foam class zoneCPCStencil : + public MeshObject + < + fvMesh, + TopologicalMeshObject, + zoneCPCStencil + >, public zoneCellStencils { // Private Data @@ -97,6 +103,11 @@ class zoneCPCStencil labelListList& globalCellCells ); + //- No copy construct + zoneCPCStencil(const zoneCPCStencil&) = delete; + + //- No copy assignment + void operator=(const zoneCPCStencil&) = delete; public: @@ -109,13 +120,10 @@ public: //- Construct from all cells and boundary faces explicit zoneCPCStencil(const fvMesh&); + // Selectors - // Member Functions + static zoneCPCStencil& New(const fvMesh&); - //- Calculates per cell the neighbour data - //- (= cell or boundary in global numbering). - //- First element is always cell itself! - virtual void updateMesh(const mapPolyMesh& mpm); }; diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.C b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.C index a397e036ab..9a20a57cc7 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.C +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.C @@ -43,7 +43,7 @@ namespace Foam Foam::autoPtr Foam::zoneCellStencils::nonEmptyFacesPatch() const { - const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + const polyBoundaryMesh& patches = meshRef_.boundaryMesh(); label nNonEmpty = 0; @@ -74,10 +74,10 @@ Foam::zoneCellStencils::nonEmptyFacesPatch() const ( IndirectList ( - mesh_.faces(), + meshRef_.faces(), nonEmptyFaces ), - mesh_.points() + meshRef_.points() ); } @@ -85,7 +85,7 @@ Foam::zoneCellStencils::nonEmptyFacesPatch() const Foam::autoPtr Foam::zoneCellStencils::allCoupledFacesPatch() const { - const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + const polyBoundaryMesh& patches = meshRef_.boundaryMesh(); label nCoupled = 0; @@ -116,19 +116,19 @@ Foam::zoneCellStencils::allCoupledFacesPatch() const ( IndirectList ( - mesh_.faces(), + meshRef_.faces(), coupledFaces ), - mesh_.points() + meshRef_.points() ); } void Foam::zoneCellStencils::validBoundaryFaces(boolList& isValidBFace) const { - const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + const polyBoundaryMesh& patches = meshRef_.boundaryMesh(); - isValidBFace.setSize(mesh_.nBoundaryFaces()); + isValidBFace.setSize(meshRef_.nBoundaryFaces()); isValidBFace = true; @@ -136,7 +136,7 @@ void Foam::zoneCellStencils::validBoundaryFaces(boolList& isValidBFace) const { if (pp.coupled() || isA(pp)) { - label bFacei = pp.start()-mesh_.nInternalFaces(); + label bFacei = pp.start() - meshRef_.nInternalFaces(); forAll(pp, i) { isValidBFace[bFacei++] = false; @@ -190,22 +190,20 @@ void Foam::zoneCellStencils::insertFaceCells labelHashSet& globals ) const { - const labelList& own = mesh_.faceOwner(); - const labelList& nei = mesh_.faceNeighbour(); + const labelList& own = meshRef_.faceOwner(); + const labelList& nei = meshRef_.faceNeighbour(); - forAll(faceLabels, i) + for (const label facei : faceLabels) { - label facei = faceLabels[i]; - - label globalOwn = globalNumbering().toGlobal(own[facei]); + const label globalOwn = globalNumbering().toGlobal(own[facei]); if (globalOwn != exclude0 && globalOwn != exclude1) { globals.insert(globalOwn); } - if (mesh_.isInternalFace(facei)) + if (meshRef_.isInternalFace(facei)) { - label globalNei = globalNumbering().toGlobal(nei[facei]); + const label globalNei = globalNumbering().toGlobal(nei[facei]); if (globalNei != exclude0 && globalNei != exclude1) { globals.insert(globalNei); @@ -213,13 +211,14 @@ void Foam::zoneCellStencils::insertFaceCells } else { - const label bFacei = facei-mesh_.nInternalFaces(); + const label bFacei = facei - meshRef_.nInternalFaces(); if (isValidBFace[bFacei]) { label globalI = globalNumbering().toGlobal ( - mesh_.nCells() + bFacei + meshRef_.nCells() + + bFacei ); if (globalI != exclude0 && globalI != exclude1) @@ -258,25 +257,12 @@ Foam::labelList Foam::zoneCellStencils::calcFaceCells Foam::zoneCellStencils::zoneCellStencils(const fvMesh& mesh) : - MeshObject(mesh), labelListList(mesh.nCells()), + meshRef_(mesh), needComm_(), - globalNumbering_(mesh_.nCells() + mesh_.nBoundaryFaces()) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::zoneCellStencils::updateMesh(const mapPolyMesh& mpm) + globalNumbering_(meshRef_.nCells() + meshRef_.nBoundaryFaces()) { - if (mesh_.topoChanging()) - { - globalNumbering_ = - globalIndex(mesh_.nCells() + mesh_.nBoundaryFaces()); - static_cast(*this) = labelListList(mesh_.nCells()); - needComm_.clear(); - } } diff --git a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.H b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.H index 16a1cde11b..fd937329d8 100644 --- a/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.H +++ b/src/finiteVolume/fvMesh/zoneDistribute/zoneStencils/zoneCellStencils.H @@ -58,15 +58,19 @@ namespace Foam class zoneCellStencils : - public MeshObject, public labelListList { protected: - // Protected Members + // Protected Data + //- const reference to fvMesh + const fvMesh& meshRef_; + + //- cells requiring processor communciation labelHashSet needComm_; + //- Global numbering for cells and boundary faces globalIndex globalNumbering_; @@ -114,6 +118,12 @@ protected: ) = 0; + //- No copy construct + zoneCellStencils(const zoneCellStencils&) = delete; + + //- No copy assignment + void operator=(const zoneCellStencils&) = delete; + public: // Declare name of the class and its debug switch @@ -125,12 +135,15 @@ public: //- Construct from all cells and boundary faces explicit zoneCellStencils(const fvMesh&); - - // Member Functions - //- Calculates per cell the neighbour data // (= cell or boundary in global numbering). // First element is always cell itself! + //- Destructor + virtual ~zoneCellStencils() = default; + + + // Member Functions + void updateStencil ( const boolList& zone @@ -139,23 +152,20 @@ public: calculateStencil(zone,*this); } - const labelHashSet& needsComm() + const labelHashSet& needsComm() noexcept { return needComm_; } - //- Global numbering for cells and boundary faces - const globalIndex& globalNumbering() const + const polyMesh& mesh() const noexcept { - return globalNumbering_; + return meshRef_; } - virtual void updateMesh(const mapPolyMesh& mpm); - - virtual bool movePoints() + //- Global numbering for cells and boundary faces + const globalIndex& globalNumbering() const noexcept { - // Do nothing - return false; + return globalNumbering_; } }; diff --git a/src/functionObjects/field/setFlow/setFlow.C b/src/functionObjects/field/setFlow/setFlow.C index ede4083de6..fbd45ac896 100644 --- a/src/functionObjects/field/setFlow/setFlow.C +++ b/src/functionObjects/field/setFlow/setFlow.C @@ -291,48 +291,42 @@ bool Foam::functionObjects::setFlow::execute() Uc.replace(vector::Z, sin(2*pi*x)*sqr(sin(pi*z))); U = U & R_; + U.correctBoundaryConditions(); - // Calculating incompressible flux based on stream function + // Calculating phi // Note: R_ rotation not implemented in phi calculation - const scalarField xp(mesh_.points().component(0) - origin_[0]); - const scalarField yp(mesh_.points().component(1) - origin_[1]); - const scalarField zp(mesh_.points().component(2) - origin_[2]); - const scalarField psi((1.0/pi)*sqr(sin(pi*xp))*sqr(sin(pi*zp))); + const vectorField Cf(mesh_.Cf().primitiveField() - origin_); + const scalarField Xf(Cf.component(vector::X)); + const scalarField Yf(Cf.component(vector::Y)); + const scalarField Zf(Cf.component(vector::Z)); + vectorField Uf(Xf.size()); + Uf.replace(vector::X, -sin(2*pi*Zf)*sqr(sin(pi*Xf))); + Uf.replace(vector::Y, scalar(0)); + Uf.replace(vector::Z, sin(2*pi*Xf)*sqr(sin(pi*Zf))); scalarField& phic = phi.primitiveFieldRef(); - forAll(phic, fi) - { - phic[fi] = 0; - const face& f = mesh_.faces()[fi]; - const label nPoints = f.size(); - - forAll(f, fpi) - { - const label p1 = f[fpi]; - const label p2 = f[(fpi + 1) % nPoints]; - phic[fi] += 0.5*(psi[p1] + psi[p2])*(yp[p2] - yp[p1]); - } - } + const vectorField& Sfc = mesh_.Sf().primitiveField(); + phic = Uf & Sfc; surfaceScalarField::Boundary& phibf = phi.boundaryFieldRef(); + const surfaceVectorField::Boundary& Sfbf = + mesh_.Sf().boundaryField(); + const surfaceVectorField::Boundary& Cfbf = + mesh_.Cf().boundaryField(); + forAll(phibf, patchi) { scalarField& phif = phibf[patchi]; - const label start = mesh_.boundaryMesh()[patchi].start(); - - forAll(phif, fi) - { - phif[fi] = 0; - const face& f = mesh_.faces()[start + fi]; - const label nPoints = f.size(); - - forAll(f, fpi) - { - const label p1 = f[fpi]; - const label p2 = f[(fpi + 1) % nPoints]; - phif[fi] += 0.5*(psi[p1] + psi[p2])*(yp[p2] - yp[p1]); - } - } + const vectorField& Sff = Sfbf[patchi]; + const vectorField& Cff = Cfbf[patchi]; + const scalarField xf(Cff.component(vector::X)); + const scalarField yf(Cff.component(vector::Y)); + const scalarField zf(Cff.component(vector::Z)); + vectorField Ufb(xf.size()); + Ufb.replace(vector::X, -sin(2*pi*zf)*sqr(sin(pi*xf))); + Ufb.replace(vector::Y, scalar(0)); + Ufb.replace(vector::Z, sin(2*pi*xf)*sqr(sin(pi*zf))); + phif = Ufb & Sff; } break; diff --git a/src/transportModels/geometricVoF/advectionSchemes/isoAdvection/isoAdvection.C b/src/transportModels/geometricVoF/advectionSchemes/isoAdvection/isoAdvection.C index e64d80dbee..13d80e8250 100644 --- a/src/transportModels/geometricVoF/advectionSchemes/isoAdvection/isoAdvection.C +++ b/src/transportModels/geometricVoF/advectionSchemes/isoAdvection/isoAdvection.C @@ -38,6 +38,9 @@ License #include "cellSet.H" #include "meshTools.H" #include "OBJstream.H" +#include "syncTools.H" + +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -88,6 +91,7 @@ Foam::isoAdvection::isoAdvection dimensionedScalar(dimVol/dimTime, Zero) ), advectionTime_(0), + timeIndex_(-1), // Tolerances and solution controls nAlphaBounds_(dict_.getOrDefault