Skip to content

Commit

Permalink
fvMeshDistributors: New framework within fvMesh to handle run-time me…
Browse files Browse the repository at this point in the history
…sh redistribution

for e.g. load-balancing.  The fvMeshDistributor is selected via the new optional
distributor entry in dynamicMeshDict, e.g.

distributor
{
    type            decomposer;

    libs            ("libfvMeshDistributors.so");
}

Note that currently only the framework is included in this commit, the
fvMeshDistributors library is not yet fully functional and hence not released
yet.
  • Loading branch information
Henry Weller committed Nov 18, 2021
1 parent daf9d6e commit 6879967
Show file tree
Hide file tree
Showing 31 changed files with 692 additions and 94 deletions.
15 changes: 11 additions & 4 deletions src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
Expand Up @@ -572,7 +572,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::repatch
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);

// Update fields. No inflation, parallel sync.
mesh_.updateMesh(map);
mapFields(map);

// Map patch fields using stored boundary fields. Note: assumes order
// of fields has not changed in object registry!
Expand Down Expand Up @@ -769,7 +769,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);

// Update fields. No inflation, parallel sync.
mesh_.updateMesh(map);
mapFields(map);

// Adapt constructMaps for merged points.
forAll(constructPointMap, proci)
Expand Down Expand Up @@ -798,6 +798,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
}
}
}

return map;
}

Expand Down Expand Up @@ -1282,8 +1283,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, false);

// Update fields
mesh_.updateMesh(map);

mapFields(map);

// Any exposed faces in a surfaceField will not be mapped. Map the value
// of these separately (until there is support in all PatchFields for
Expand All @@ -1310,6 +1310,13 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
}


void Foam::fvMeshDistribute::mapFields(const mapPolyMesh& map)
{
mesh_.mapFields(map);
meshObject::updateMesh<fvMesh>(mesh_, map);
}


// Delete and add processor patches. Changes mesh and returns per neighbour proc
// the processor patchID.
void Foam::fvMeshDistribute::addProcPatches
Expand Down
3 changes: 3 additions & 0 deletions src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.H
Expand Up @@ -160,6 +160,9 @@ class fvMeshDistribute
labelListList& constructPointMap
);

//- Map the fields
void mapFields(const mapPolyMesh& map);


// Coupling information

Expand Down
18 changes: 12 additions & 6 deletions src/finiteVolume/Make/files
Expand Up @@ -93,18 +93,24 @@ $(faceToCell)/extendedFaceToCellStencil.C
$(faceToCell)/extendedCentredFaceToCellStencil.C
$(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C

fvMeshMovers = fvMesh/fvMeshMovers

$(fvMeshMovers)/fvMeshMover/fvMeshMover.C
$(fvMeshMovers)/fvMeshMover/fvMeshMoverNew.C
$(fvMeshMovers)/none/fvMeshMoversNone.C

fvMeshTopoChangers = fvMesh/fvMeshTopoChangers

$(fvMeshTopoChangers)/fvMeshTopoChanger/fvMeshTopoChanger.C
$(fvMeshTopoChangers)/fvMeshTopoChanger/fvMeshTopoChangerNew.C
$(fvMeshTopoChangers)/none/fvMeshTopoChangersNone.C

fvMeshDistributors = fvMesh/fvMeshDistributors

$(fvMeshDistributors)/fvMeshDistributor/fvMeshDistributor.C
$(fvMeshDistributors)/fvMeshDistributor/fvMeshDistributorNew.C
$(fvMeshDistributors)/none/fvMeshDistributorsNone.C

fvMeshMovers = fvMesh/fvMeshMovers

$(fvMeshMovers)/fvMeshMover/fvMeshMover.C
$(fvMeshMovers)/fvMeshMover/fvMeshMoverNew.C
$(fvMeshMovers)/none/fvMeshMoversNone.C

functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C
functionObjects/volRegion/volRegion.C

Expand Down
37 changes: 35 additions & 2 deletions src/finiteVolume/fvMesh/fvMesh.C
Expand Up @@ -32,6 +32,7 @@ License
#include "demandDrivenData.H"
#include "fvMeshLduAddressing.H"
#include "fvMeshTopoChanger.H"
#include "fvMeshDistributor.H"
#include "fvMeshMover.H"
#include "mapPolyMesh.H"
#include "MapFvFields.H"
Expand Down Expand Up @@ -271,6 +272,12 @@ Foam::fvMesh::fvMesh(const IOobject& io, const bool changers)
? fvMeshTopoChanger::New(*this)
: autoPtr<fvMeshTopoChanger>(nullptr)
),
distributor_
(
changers
? fvMeshDistributor::New(*this)
: autoPtr<fvMeshDistributor>(nullptr)
),
mover_
(
changers
Expand Down Expand Up @@ -476,6 +483,7 @@ bool Foam::fvMesh::dynamic() const
bool Foam::fvMesh::update()
{
bool updated = topoChanger_->update();
updated = distributor_->update() || updated;
updated = mover_->update() || updated;

return updated;
Expand Down Expand Up @@ -591,6 +599,12 @@ const Foam::fvMeshTopoChanger& Foam::fvMesh::topoChanger() const
}


const Foam::fvMeshDistributor& Foam::fvMesh::distributor() const
{
return distributor_();
}


const Foam::fvMeshMover& Foam::fvMesh::mover() const
{
return mover_();
Expand Down Expand Up @@ -891,6 +905,16 @@ void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
meshObject::updateMesh<fvMesh>(*this, mpm);
meshObject::updateMesh<lduMesh>(*this, mpm);

if (topoChanger_.valid())
{
topoChanger_->updateMesh(mpm);
}

if (distributor_.valid())
{
distributor_->updateMesh(mpm);
}

if (mover_.valid())
{
mover_->updateMesh(mpm);
Expand All @@ -904,10 +928,10 @@ void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
}


void Foam::fvMesh::updateMesh(const mapDistributePolyMesh& mdpm)
void Foam::fvMesh::distribute(const mapDistributePolyMesh& mdpm)
{
// Update polyMesh. This needs to keep volume existent!
// polyMesh::updateMesh(mdpm);
// polyMesh::distribute(mdpm);

// if (VPtr_)
// {
Expand Down Expand Up @@ -960,6 +984,10 @@ void Foam::fvMesh::updateMesh(const mapDistributePolyMesh& mdpm)

// meshObject::updateMesh<fvMesh>(*this, mdpm);
// meshObject::updateMesh<lduMesh>(*this, mdpm);

topoChanger_->distribute(mdpm);
distributor_->distribute(mdpm);
mover_->distribute(mdpm);
}


Expand Down Expand Up @@ -1145,6 +1173,11 @@ bool Foam::fvMesh::writeObject
topoChanger_->write(write);
}

if (distributor_.valid())
{
distributor_->write(write);
}

if (mover_.valid())
{
mover_->write(write);
Expand Down
9 changes: 8 additions & 1 deletion src/finiteVolume/fvMesh/fvMesh.H
Expand Up @@ -70,6 +70,7 @@ namespace Foam

class fvMeshLduAddressing;
class fvMeshTopoChanger;
class fvMeshDistributor;
class fvMeshMover;
class volMesh;
class mapDistributePolyMesh;
Expand All @@ -95,6 +96,9 @@ class fvMesh
//- The topo-changer function class
autoPtr<fvMeshTopoChanger> topoChanger_;

//- The distributor function class
autoPtr<fvMeshDistributor> distributor_;

//- The mover function class
autoPtr<fvMeshMover> mover_;

Expand Down Expand Up @@ -299,6 +303,9 @@ public:
//- Return the topo-changer function class
const fvMeshTopoChanger& topoChanger() const;

//- Return the distributor function class
const fvMeshDistributor& distributor() const;

//- Return the mover function class
const fvMeshMover& mover() const;

Expand Down Expand Up @@ -368,7 +375,7 @@ public:
//- Update mesh corresponding to the given distribution map
// This is a prototype implementation without field mapping
// or handling of old-time volumes for mesh-morphing
virtual void updateMesh(const mapDistributePolyMesh& mdpm);
virtual void distribute(const mapDistributePolyMesh& mdpm);

//- Move points, returns volumes swept by faces in motion
virtual tmp<scalarField> movePoints(const pointField&);
Expand Down
@@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/

#include "fvMeshDistributor.H"
#include "volFields.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
defineTypeNameAndDebug(fvMeshDistributor, 0);
defineRunTimeSelectionTable(fvMeshDistributor, fvMesh);
}


// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::fvMeshDistributor::fvMeshDistributor(fvMesh& mesh)
:
mesh_(mesh),
dynamicMeshDict_
(
IOdictionary
(
IOobject
(
"dynamicMeshDict",
mesh.time().constant(),
mesh.dbDir(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
)
)
{}


Foam::fvMeshDistributor::velocityMotionCorrection::velocityMotionCorrection
(
const fvMesh& mesh,
const dictionary& dict
)
:
mesh_(mesh),
velocityFields_(dict.lookupOrDefault("velocityFields", wordList()))
{}


// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

Foam::fvMeshDistributor::~fvMeshDistributor()
{}


// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

void Foam::fvMeshDistributor::velocityMotionCorrection::update() const
{
forAll(velocityFields_, i)
{
if (mesh_.foundObject<volVectorField>(velocityFields_[i]))
{
mesh_.lookupObjectRef<volVectorField>
(
velocityFields_[i]
).correctBoundaryConditions();
}
}
}

// ************************************************************************* //

0 comments on commit 6879967

Please sign in to comment.