diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 2e4087c459..b33426a6f5 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -168,4 +168,8 @@ void Foam::functionObject::mapMesh(const polyMeshMap&) {} +void Foam::functionObject::distribute(const polyDistributionMap&) +{} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index d837ead0b3..f763b5e7f9 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H @@ -134,6 +134,7 @@ class Time; class polyMesh; class polyTopoChangeMap; class polyMeshMap; +class polyDistributionMap; /*---------------------------------------------------------------------------*\ Class functionObject Declaration @@ -248,6 +249,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); + // Member Operators diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 8a2e609246..ea511e683c 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -880,4 +880,16 @@ void Foam::functionObjectList::mapMesh(const polyMeshMap& map) } +void Foam::functionObjectList::distribute(const polyDistributionMap& map) +{ + if (execution_) + { + forAll(*this, oi) + { + operator[](oi).distribute(map); + } + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index ace432fa63..923297737f 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -54,6 +54,7 @@ namespace Foam class polyTopoChangeMap; class polyMeshMap; +class polyDistributionMap; class argList; /*---------------------------------------------------------------------------*\ @@ -282,6 +283,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); + // Member Operators diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C index 664bed605d..295a8bde8a 100644 --- a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C @@ -231,4 +231,16 @@ void Foam::functionObjects::timeControl::mapMesh } +void Foam::functionObjects::timeControl::distribute +( + const polyDistributionMap& map +) +{ + if (active()) + { + foPtr_->distribute(map); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H index 4f6714afe6..8df3f1dc1c 100644 --- a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H @@ -166,6 +166,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); + // Member Operators diff --git a/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.C b/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.C index 5c23682468..2ee3b006e0 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.C +++ b/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.C @@ -59,21 +59,6 @@ void Foam::polyDistributionMap::calcPatchSizes() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::polyDistributionMap::polyDistributionMap() -: - nOldPoints_(0), - nOldFaces_(0), - nOldCells_(0), - oldPatchSizes_(0), - oldPatchStarts_(0), - oldPatchNMeshPoints_(0), - pointMap_(), - faceMap_(), - cellMap_(), - patchMap_() -{} - - Foam::polyDistributionMap::polyDistributionMap ( const polyMesh& mesh, @@ -101,6 +86,7 @@ Foam::polyDistributionMap::polyDistributionMap const bool constructFaceHasFlip ) : + mesh_(mesh), nOldPoints_(nOldPoints), nOldFaces_(nOldFaces), nOldCells_(nOldCells), @@ -128,78 +114,8 @@ Foam::polyDistributionMap::polyDistributionMap } -Foam::polyDistributionMap::polyDistributionMap -( - // mesh before changes - const label nOldPoints, - const label nOldFaces, - const label nOldCells, - labelList&& oldPatchStarts, - labelList&& oldPatchNMeshPoints, - - // how to transfer pieces of mesh - distributionMap&& pointMap, - distributionMap&& faceMap, - distributionMap&& cellMap, - distributionMap&& patchMap -) -: - nOldPoints_(nOldPoints), - nOldFaces_(nOldFaces), - nOldCells_(nOldCells), - oldPatchSizes_(oldPatchStarts.size()), - oldPatchStarts_(move(oldPatchStarts)), - oldPatchNMeshPoints_(move(oldPatchNMeshPoints)), - pointMap_(move(pointMap)), - faceMap_(move(faceMap)), - cellMap_(move(cellMap)), - patchMap_(move(patchMap)) -{ - calcPatchSizes(); -} - - -Foam::polyDistributionMap::polyDistributionMap -( - polyDistributionMap&& map -) -: - nOldPoints_(map.nOldPoints_), - nOldFaces_(map.nOldFaces_), - nOldCells_(map.nOldCells_), - oldPatchSizes_(move(map.oldPatchSizes_)), - oldPatchStarts_(move(map.oldPatchStarts_)), - oldPatchNMeshPoints_(move(map.oldPatchNMeshPoints_)), - pointMap_(move(map.pointMap_)), - faceMap_(move(map.faceMap_)), - cellMap_(move(map.cellMap_)), - patchMap_(move(map.patchMap_)) -{} - - -Foam::polyDistributionMap::polyDistributionMap(Istream& is) -{ - is >> *this; -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::polyDistributionMap::transfer(polyDistributionMap& rhs) -{ - nOldPoints_ = rhs.nOldPoints_; - nOldFaces_ = rhs.nOldFaces_; - nOldCells_ = rhs.nOldCells_; - oldPatchSizes_.transfer(rhs.oldPatchSizes_); - oldPatchStarts_.transfer(rhs.oldPatchStarts_); - oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_); - pointMap_.transfer(rhs.pointMap_); - faceMap_.transfer(rhs.faceMap_); - cellMap_.transfer(rhs.cellMap_); - patchMap_.transfer(rhs.patchMap_); -} - - void Foam::polyDistributionMap::distributePointIndices(labelList& lst) const { // Construct boolList from selected elements @@ -288,79 +204,4 @@ void Foam::polyDistributionMap::distributePatchIndices(labelList& lst) const } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -void Foam::polyDistributionMap::operator= -( - const polyDistributionMap& rhs -) -{ - nOldPoints_ = rhs.nOldPoints_; - nOldFaces_ = rhs.nOldFaces_; - nOldCells_ = rhs.nOldCells_; - oldPatchSizes_ = rhs.oldPatchSizes_; - oldPatchStarts_ = rhs.oldPatchStarts_; - oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_; - pointMap_ = rhs.pointMap_; - faceMap_ = rhs.faceMap_; - cellMap_ = rhs.cellMap_; - patchMap_ = rhs.patchMap_; -} - - -void Foam::polyDistributionMap::operator=(polyDistributionMap&& rhs) -{ - nOldPoints_ = rhs.nOldPoints_; - nOldFaces_ = rhs.nOldFaces_; - nOldCells_ = rhs.nOldCells_; - oldPatchSizes_ = move(rhs.oldPatchSizes_); - oldPatchStarts_ = move(rhs.oldPatchStarts_); - oldPatchNMeshPoints_ = move(rhs.oldPatchNMeshPoints_); - pointMap_ = move(rhs.pointMap_); - faceMap_ = move(rhs.faceMap_); - cellMap_ = move(rhs.cellMap_); - patchMap_ = move(rhs.patchMap_); -} - - -// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * // - -Foam::Istream& Foam::operator>>(Istream& is, polyDistributionMap& map) -{ - is.fatalCheck("operator>>(Istream&, polyDistributionMap&)"); - - is >> map.nOldPoints_ - >> map.nOldFaces_ - >> map.nOldCells_ - >> map.oldPatchSizes_ - >> map.oldPatchStarts_ - >> map.oldPatchNMeshPoints_ - >> map.pointMap_ - >> map.faceMap_ - >> map.cellMap_ - >> map.patchMap_; - - return is; -} - - -// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const polyDistributionMap& map) -{ - os << map.nOldPoints_ - << token::SPACE << map.nOldFaces_ - << token::SPACE << map.nOldCells_ << token::NL - << map.oldPatchSizes_ << token::NL - << map.oldPatchStarts_ << token::NL - << map.oldPatchNMeshPoints_ << token::NL - << map.pointMap_ << token::NL - << map.faceMap_ << token::NL - << map.cellMap_ << token::NL - << map.patchMap_; - - return os; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.H b/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.H index 5e51ab84d9..0eb73a2fbc 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.H +++ b/src/OpenFOAM/meshes/polyMesh/polyDistributionMap/polyDistributionMap.H @@ -66,6 +66,9 @@ class polyDistributionMap { // Private Data + //- Reference to the mesh + const polyMesh& mesh_; + //- Number of old live points label nOldPoints_; @@ -84,7 +87,6 @@ class polyDistributionMap //- List of numbers of mesh points per old patch labelList oldPatchNMeshPoints_; - //- Point distribute map distributionMap pointMap_; @@ -100,6 +102,7 @@ class polyDistributionMap // Private Member Functions + //- ... void calcPatchSizes(); @@ -107,9 +110,6 @@ public: // Constructors - //- Construct null - polyDistributionMap(); - //- Move constructor from components. // Note that mesh has to be changed already // since uses mesh.nPoints etc as the new size. @@ -140,29 +140,6 @@ public: const bool constructFaceHasFlip = false ); - //- Move constructor from components - polyDistributionMap - ( - // mesh before changes - const label nOldPoints, - const label nOldFaces, - const label nOldCells, - labelList&& oldPatchStarts, - labelList&& oldPatchNMeshPoints, - - // how to subset pieces of mesh to send across - distributionMap&& pointMap, - distributionMap&& faceMap, - distributionMap&& cellMap, - distributionMap&& patchMap - ); - - //- Move constructor - polyDistributionMap(polyDistributionMap&&); - - //- Construct from Istream - polyDistributionMap(Istream&); - //- Disallow default bitwise copy construction polyDistributionMap(const polyDistributionMap&) = delete; @@ -171,6 +148,12 @@ public: // Access + //- Return polyMesh + const polyMesh& mesh() const + { + return mesh_; + } + //- Number of points in mesh before distribution label nOldPoints() const { @@ -234,9 +217,6 @@ public: // Other - //- Transfer the contents of the argument and annul the argument. - void transfer(polyDistributionMap&); - //- Distribute list of point data template void distributePointData(List& lst) const @@ -265,30 +245,27 @@ public: patchMap_.distribute(lst); } - - //- Distribute list of point/face/cell/patch indices. + //- Distribute list of point indices // (Converts to boolList, distributes boolList and reconstructs) void distributePointIndices(labelList& pointIDs) const; + //- Distribute list of face indices + // (Converts to boolList, distributes boolList and reconstructs) void distributeFaceIndices(labelList& faceIDs) const; + + //- Distribute list of cell indices + // (Converts to boolList, distributes boolList and reconstructs) void distributeCellIndices(labelList& cellIDs) const; + + //- Distribute list of patch indices + // (Converts to boolList, distributes boolList and reconstructs) void distributePatchIndices(labelList& patchIDs) const; // Member Operators - void operator=(const polyDistributionMap&); - - void operator=(polyDistributionMap&&); - - - // IOstream Operators - - //- Read dictionary from Istream - friend Istream& operator>>(Istream&, polyDistributionMap&); - - //- Write dictionary to Ostream - friend Ostream& operator<<(Ostream&, const polyDistributionMap&); + //- Disallow default bitwise assignment + void operator=(const polyDistributionMap&) = delete; }; diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index f69f6a81af..7404ea407e 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -1300,6 +1300,8 @@ void Foam::fvMesh::distribute(const polyDistributionMap& map) meshObject::distribute(*this, map); meshObject::distribute(*this, map); + const_cast(time()).functionObjects().distribute(map); + topoChanger_->distribute(map); distributor_->distribute(map); mover_->distribute(map); diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index cb3580452b..98c86b3e1a 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -33,6 +33,7 @@ License #include "fvMeshStitcher.H" #include "polyTopoChangeMap.H" #include "polyMeshMap.H" +#include "polyDistributionMap.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -858,4 +859,16 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::mapMesh } +void Foam::functionObjects::fieldValues::surfaceFieldValue::distribute +( + const polyDistributionMap& map +) +{ + if (&map.mesh() == &mesh_) + { + initialise(dict_); + } +} + + // ************************************************************************* // diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H index 7e23d05b3e..f19f9e8191 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.H @@ -498,6 +498,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); }; diff --git a/src/functionObjects/field/layerAverage/layerAverage.C b/src/functionObjects/field/layerAverage/layerAverage.C index 36fb046ce6..0055b9cdc0 100644 --- a/src/functionObjects/field/layerAverage/layerAverage.C +++ b/src/functionObjects/field/layerAverage/layerAverage.C @@ -32,6 +32,7 @@ License #include "writeFile.H" #include "polyTopoChangeMap.H" #include "polyMeshMap.H" +#include "polyDistributionMap.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -384,4 +385,17 @@ void Foam::functionObjects::layerAverage::mapMesh(const polyMeshMap& map) } +void Foam::functionObjects::layerAverage::distribute +( + const polyDistributionMap& map +) +{ + if (&map.mesh() == &mesh_) + { + Info<< type() << " " << name() << ":" << nl; + calcLayers(); + } +} + + // ************************************************************************* // diff --git a/src/functionObjects/field/layerAverage/layerAverage.H b/src/functionObjects/field/layerAverage/layerAverage.H index 489eaa5b5e..3634a961a7 100644 --- a/src/functionObjects/field/layerAverage/layerAverage.H +++ b/src/functionObjects/field/layerAverage/layerAverage.H @@ -191,6 +191,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); + // Member Operators diff --git a/src/functionObjects/field/streamlines/streamlines.C b/src/functionObjects/field/streamlines/streamlines.C index 736b1b5316..4949d744ec 100644 --- a/src/functionObjects/field/streamlines/streamlines.C +++ b/src/functionObjects/field/streamlines/streamlines.C @@ -37,6 +37,7 @@ License #include "writeFile.H" #include "polyTopoChangeMap.H" #include "polyMeshMap.H" +#include "polyDistributionMap.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -620,4 +621,16 @@ void Foam::functionObjects::streamlines::mapMesh } +void Foam::functionObjects::streamlines::distribute +( + const polyDistributionMap& map +) +{ + if (&map.mesh() == &mesh_) + { + read(dict_); + } +} + + // ************************************************************************* // diff --git a/src/functionObjects/field/streamlines/streamlines.H b/src/functionObjects/field/streamlines/streamlines.H index cf76c587ce..44220e5aab 100644 --- a/src/functionObjects/field/streamlines/streamlines.H +++ b/src/functionObjects/field/streamlines/streamlines.H @@ -247,6 +247,9 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); + // Member Operators diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C index 6d8a0a4cb8..bbf9f73c1a 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.C +++ b/src/sampling/sampledSet/sampledSets/sampledSets.C @@ -31,6 +31,8 @@ License #include "SortableList.H" #include "volPointInterpolation.H" #include "polyTopoChangeMap.H" +#include "polyMeshMap.H" +#include "polyDistributionMap.H" #include "writeFile.H" #include "OFstream.H" #include "OSspecific.H" @@ -53,8 +55,6 @@ namespace functionObjects } } -bool Foam::functionObjects::sampledSets::verbose_ = false; - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -82,6 +82,24 @@ void Foam::functionObjects::sampledSets::combineSampledSets() } +void Foam::functionObjects::sampledSets::correct() +{ + bool setsFound = dict_.found("sets"); + if (setsFound) + { + searchEngine_.correct(); + + PtrList newList + ( + dict_.lookup("sets"), + sampledSet::iNew(mesh_, searchEngine_) + ); + transfer(newList); + combineSampledSets(); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::sampledSets::sampledSets @@ -118,9 +136,42 @@ Foam::functionObjects::sampledSets::~sampledSets() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::functionObjects::sampledSets::verbose(const bool verbosity) +bool Foam::functionObjects::sampledSets::read(const dictionary& dict) { - verbose_ = verbosity; + dict_ = dict; + + bool setsFound = dict_.found("sets"); + if (setsFound) + { + dict_.lookup("fields") >> fields_; + + dict.lookup("interpolationScheme") >> interpolationScheme_; + + const word writeType(dict.lookup("setFormat")); + + // Define the set formatter + formatter_ = setWriter::New(writeType, dict); + + PtrList newList + ( + dict_.lookup("sets"), + sampledSet::iNew(mesh_, searchEngine_) + ); + transfer(newList); + combineSampledSets(); + + if (this->size()) + { + Info<< "Reading set description:" << nl; + forAll(*this, seti) + { + Info<< " " << operator[](seti).name() << nl; + } + Info<< endl; + } + } + + return true; } @@ -226,63 +277,6 @@ bool Foam::functionObjects::sampledSets::write() } -bool Foam::functionObjects::sampledSets::read(const dictionary& dict) -{ - dict_ = dict; - - bool setsFound = dict_.found("sets"); - if (setsFound) - { - dict_.lookup("fields") >> fields_; - - dict.lookup("interpolationScheme") >> interpolationScheme_; - - const word writeType(dict.lookup("setFormat")); - - // Define the set formatter - formatter_ = setWriter::New(writeType, dict); - - PtrList newList - ( - dict_.lookup("sets"), - sampledSet::iNew(mesh_, searchEngine_) - ); - transfer(newList); - combineSampledSets(); - - if (this->size()) - { - Info<< "Reading set description:" << nl; - forAll(*this, seti) - { - Info<< " " << operator[](seti).name() << nl; - } - Info<< endl; - } - } - - return true; -} - - -void Foam::functionObjects::sampledSets::correct() -{ - bool setsFound = dict_.found("sets"); - if (setsFound) - { - searchEngine_.correct(); - - PtrList newList - ( - dict_.lookup("sets"), - sampledSet::iNew(mesh_, searchEngine_) - ); - transfer(newList); - combineSampledSets(); - } -} - - void Foam::functionObjects::sampledSets::movePoints(const polyMesh& mesh) { if (&mesh == &mesh_) @@ -307,16 +301,19 @@ void Foam::functionObjects::sampledSets::topoChange void Foam::functionObjects::sampledSets::mapMesh(const polyMeshMap& map) { - correct(); + if (&map.mesh() == &mesh_) + { + correct(); + } } -void Foam::functionObjects::sampledSets::readUpdate +void Foam::functionObjects::sampledSets::distribute ( - const polyMesh::readUpdateState state + const polyDistributionMap& map ) { - if (state != polyMesh::UNCHANGED) + if (&map.mesh() == &mesh_) { correct(); } diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.H b/src/sampling/sampledSet/sampledSets/sampledSets.H index 2d920439a4..b968f123ff 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.H +++ b/src/sampling/sampledSet/sampledSets/sampledSets.H @@ -69,12 +69,6 @@ class sampledSets public fvMeshFunctionObject, public PtrList { - // Static Data Members - - //- Output verbosity - static bool verbose_; - - // Private Data //- Keep the dictionary to recreate sets for moving mesh cases @@ -117,6 +111,9 @@ class sampledSets // index list. Valid result only on master processor. void combineSampledSets(); + //- Correct for mesh changes + void correct(); + //- Sample all fields of a type on a given set template PtrList> sampleLocalType @@ -163,9 +160,6 @@ public: // Member Functions - //- Set verbosity level - void verbose(const bool verbosity = true); - //- Read the sampledSets virtual bool read(const dictionary&); @@ -178,9 +172,6 @@ public: //- Sample and write virtual bool write(); - //- Correct for mesh changes - void correct(); - //- Update for mesh point-motion virtual void movePoints(const polyMesh&); @@ -190,8 +181,8 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); - //- Update topology using the given map due to readUpdate - virtual void readUpdate(const polyMesh::readUpdateState state); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); // Member Operators diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 4d76c9b857..498addb005 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -26,6 +26,8 @@ License #include "sampledSurfaces.H" #include "PatchTools.H" #include "polyTopoChangeMap.H" +#include "polyMeshMap.H" +#include "polyDistributionMap.H" #include "OSspecific.H" #include "writeFile.H" #include "addToRunTimeSelectionTable.H" @@ -47,10 +49,111 @@ namespace functionObjects } } -bool Foam::functionObjects::sampledSurfaces::verbose_ = false; Foam::scalar Foam::functionObjects::sampledSurfaces::mergeTol_ = 1e-10; +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::sampledSurfaces::needsUpdate() const +{ + forAll(*this, si) + { + if (operator[](si).needsUpdate()) + { + return true; + } + } + + return false; +} + + +bool Foam::functionObjects::sampledSurfaces::expire() +{ + bool justExpired = false; + + forAll(*this, si) + { + if (operator[](si).expire()) + { + justExpired = true; + } + + // Clear merge information + if (Pstream::parRun()) + { + mergeList_[si].clear(); + } + } + + // true if any surfaces just expired + return justExpired; +} + + +bool Foam::functionObjects::sampledSurfaces::update() +{ + bool updated = false; + + if (!needsUpdate()) + { + return updated; + } + + // Serial: quick and easy, no merging required + if (!Pstream::parRun()) + { + forAll(*this, si) + { + if (operator[](si).update()) + { + updated = true; + } + } + + return updated; + } + + // Dimension as fraction of mesh bounding box + scalar mergeDim = mergeTol_ * mesh_.bounds().mag(); + + if (Pstream::master() && debug) + { + Pout<< nl << "Merging all points within " + << mergeDim << " metre" << endl; + } + + forAll(*this, si) + { + sampledSurface& s = operator[](si); + + if (s.update()) + { + updated = true; + } + else + { + continue; + } + + PatchTools::gatherAndMerge + ( + mergeDim, + primitivePatch + ( + SubList(s.faces(), s.faces().size()), + s.points() + ), + mergeList_[si].points, + mergeList_[si].faces, + mergeList_[si].pointsMap + ); + } + + return updated; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::sampledSurfaces::sampledSurfaces @@ -89,9 +192,75 @@ Foam::functionObjects::sampledSurfaces::~sampledSurfaces() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::functionObjects::sampledSurfaces::verbose(const bool verbosity) +bool Foam::functionObjects::sampledSurfaces::read(const dictionary& dict) { - verbose_ = verbosity; + bool surfacesFound = dict.found("surfaces"); + + if (surfacesFound) + { + dict.lookup("fields") >> fields_; + + dict.lookup("interpolationScheme") >> interpolationScheme_; + + dict.readIfPresent("writeEmpty", writeEmpty_); + + const word writeType(dict.lookup("surfaceFormat")); + + // Define the surface formatter + formatter_ = surfaceWriter::New(writeType, dict); + + PtrList newList + ( + dict.lookup("surfaces"), + sampledSurface::iNew(mesh_) + ); + transfer(newList); + + if (Pstream::parRun()) + { + mergeList_.setSize(size()); + } + + // Ensure all surfaces and merge information are expired + expire(); + + if (this->size()) + { + Info<< "Reading surface description:" << nl; + forAll(*this, si) + { + Info<< " " << operator[](si).name() << nl; + } + Info<< endl; + } + } + + if (Pstream::master() && debug) + { + Pout<< "sample fields:" << fields_ << nl + << "sample surfaces:" << nl << "(" << nl; + + forAll(*this, si) + { + Pout<< " " << operator[](si) << endl; + } + Pout<< ")" << endl; + } + + return true; +} + + +Foam::wordList Foam::functionObjects::sampledSurfaces::fields() const +{ + wordList fields(fields_); + + forAll(*this, si) + { + fields.append(operator[](si).fields()); + } + + return fields; } @@ -206,78 +375,6 @@ bool Foam::functionObjects::sampledSurfaces::write() } -bool Foam::functionObjects::sampledSurfaces::read(const dictionary& dict) -{ - bool surfacesFound = dict.found("surfaces"); - - if (surfacesFound) - { - dict.lookup("fields") >> fields_; - - dict.lookup("interpolationScheme") >> interpolationScheme_; - - dict.readIfPresent("writeEmpty", writeEmpty_); - - const word writeType(dict.lookup("surfaceFormat")); - - // Define the surface formatter - formatter_ = surfaceWriter::New(writeType, dict); - - PtrList newList - ( - dict.lookup("surfaces"), - sampledSurface::iNew(mesh_) - ); - transfer(newList); - - if (Pstream::parRun()) - { - mergeList_.setSize(size()); - } - - // Ensure all surfaces and merge information are expired - expire(); - - if (this->size()) - { - Info<< "Reading surface description:" << nl; - forAll(*this, si) - { - Info<< " " << operator[](si).name() << nl; - } - Info<< endl; - } - } - - if (Pstream::master() && debug) - { - Pout<< "sample fields:" << fields_ << nl - << "sample surfaces:" << nl << "(" << nl; - - forAll(*this, si) - { - Pout<< " " << operator[](si) << endl; - } - Pout<< ")" << endl; - } - - return true; -} - - -Foam::wordList Foam::functionObjects::sampledSurfaces::fields() const -{ - wordList fields(fields_); - - forAll(*this, si) - { - fields.append(operator[](si).fields()); - } - - return fields; -} - - void Foam::functionObjects::sampledSurfaces::movePoints(const polyMesh& mesh) { if (&mesh == &mesh_) @@ -296,8 +393,6 @@ void Foam::functionObjects::sampledSurfaces::topoChange { expire(); } - - // pointMesh and interpolation will have been reset in mesh.update } @@ -306,119 +401,22 @@ void Foam::functionObjects::sampledSurfaces::mapMesh const polyMeshMap& map ) { - expire(); -} - - -void Foam::functionObjects::sampledSurfaces::readUpdate -( - const polyMesh::readUpdateState state -) -{ - if (state != polyMesh::UNCHANGED) + if (&map.mesh() == &mesh_) { expire(); } } -bool Foam::functionObjects::sampledSurfaces::needsUpdate() const +void Foam::functionObjects::sampledSurfaces::distribute +( + const polyDistributionMap& map +) { - forAll(*this, si) + if (&map.mesh() == &mesh_) { - if (operator[](si).needsUpdate()) - { - return true; - } + expire(); } - - return false; -} - - -bool Foam::functionObjects::sampledSurfaces::expire() -{ - bool justExpired = false; - - forAll(*this, si) - { - if (operator[](si).expire()) - { - justExpired = true; - } - - // Clear merge information - if (Pstream::parRun()) - { - mergeList_[si].clear(); - } - } - - // true if any surfaces just expired - return justExpired; -} - - -bool Foam::functionObjects::sampledSurfaces::update() -{ - bool updated = false; - - if (!needsUpdate()) - { - return updated; - } - - // Serial: quick and easy, no merging required - if (!Pstream::parRun()) - { - forAll(*this, si) - { - if (operator[](si).update()) - { - updated = true; - } - } - - return updated; - } - - // Dimension as fraction of mesh bounding box - scalar mergeDim = mergeTol_ * mesh_.bounds().mag(); - - if (Pstream::master() && debug) - { - Pout<< nl << "Merging all points within " - << mergeDim << " metre" << endl; - } - - forAll(*this, si) - { - sampledSurface& s = operator[](si); - - if (s.update()) - { - updated = true; - } - else - { - continue; - } - - PatchTools::gatherAndMerge - ( - mergeDim, - primitivePatch - ( - SubList(s.faces(), s.faces().size()), - s.points() - ), - mergeList_[si].points, - mergeList_[si].faces, - mergeList_[si].pointsMap - ); - } - - return updated; } diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index d731c01a3f..108dd6c98d 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -127,9 +127,6 @@ class sampledSurfaces // Static Data Members - //- Output verbosity - static bool verbose_; - //- Tolerance for merging points (fraction of mesh bounding box) static scalar mergeTol_; @@ -166,6 +163,18 @@ class sampledSurfaces // Private Member Functions + //- Does any of the surfaces need an update? + bool needsUpdate() const; + + //- Mark the surfaces as needing an update. + // May also free up unneeded data. + // Return false if all surfaces were already marked as expired. + bool expire(); + + //- Update the surfaces as required and merge surface points (parallel). + // Return false if no surfaces required an update. + bool update(); + //- Sample all fields of a type on a given surface template PtrList> sampleLocalType @@ -212,21 +221,6 @@ public: // Member Functions - //- Does any of the surfaces need an update? - virtual bool needsUpdate() const; - - //- Mark the surfaces as needing an update. - // May also free up unneeded data. - // Return false if all surfaces were already marked as expired. - virtual bool expire(); - - //- Update the surfaces as required and merge surface points (parallel). - // Return false if no surfaces required an update. - virtual bool update(); - - //- Set verbosity level - void verbose(const bool verbosity = true); - //- Read the sampledSurfaces dictionary virtual bool read(const dictionary&); @@ -248,9 +242,8 @@ public: //- Update from another mesh using the given map virtual void mapMesh(const polyMeshMap&); - //- Update topology using the given map due to readUpdate - // - expires the surfaces - virtual void readUpdate(const polyMesh::readUpdateState state); + //- Redistribute or update using the given distribution map + virtual void distribute(const polyDistributionMap&); // Member Operators