functionObjects: Clean up and completion of hooks

This commit is contained in:
Will Bainbridge
2022-08-04 15:55:09 +01:00
parent 3ce205e2b3
commit b0d2002e72
19 changed files with 372 additions and 485 deletions

View File

@ -168,4 +168,8 @@ void Foam::functionObject::mapMesh(const polyMeshMap&)
{} {}
void Foam::functionObject::distribute(const polyDistributionMap&)
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -134,6 +134,7 @@ class Time;
class polyMesh; class polyMesh;
class polyTopoChangeMap; class polyTopoChangeMap;
class polyMeshMap; class polyMeshMap;
class polyDistributionMap;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class functionObject Declaration Class functionObject Declaration
@ -248,6 +249,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -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);
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -54,6 +54,7 @@ namespace Foam
class polyTopoChangeMap; class polyTopoChangeMap;
class polyMeshMap; class polyMeshMap;
class polyDistributionMap;
class argList; class argList;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -282,6 +283,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -231,4 +231,16 @@ void Foam::functionObjects::timeControl::mapMesh
} }
void Foam::functionObjects::timeControl::distribute
(
const polyDistributionMap& map
)
{
if (active())
{
foPtr_->distribute(map);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -166,6 +166,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -59,21 +59,6 @@ void Foam::polyDistributionMap::calcPatchSizes()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyDistributionMap::polyDistributionMap()
:
nOldPoints_(0),
nOldFaces_(0),
nOldCells_(0),
oldPatchSizes_(0),
oldPatchStarts_(0),
oldPatchNMeshPoints_(0),
pointMap_(),
faceMap_(),
cellMap_(),
patchMap_()
{}
Foam::polyDistributionMap::polyDistributionMap Foam::polyDistributionMap::polyDistributionMap
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -101,6 +86,7 @@ Foam::polyDistributionMap::polyDistributionMap
const bool constructFaceHasFlip const bool constructFaceHasFlip
) )
: :
mesh_(mesh),
nOldPoints_(nOldPoints), nOldPoints_(nOldPoints),
nOldFaces_(nOldFaces), nOldFaces_(nOldFaces),
nOldCells_(nOldCells), 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::polyDistributionMap::distributePointIndices(labelList& lst) const
{ {
// Construct boolList from selected elements // 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -66,6 +66,9 @@ class polyDistributionMap
{ {
// Private Data // Private Data
//- Reference to the mesh
const polyMesh& mesh_;
//- Number of old live points //- Number of old live points
label nOldPoints_; label nOldPoints_;
@ -84,7 +87,6 @@ class polyDistributionMap
//- List of numbers of mesh points per old patch //- List of numbers of mesh points per old patch
labelList oldPatchNMeshPoints_; labelList oldPatchNMeshPoints_;
//- Point distribute map //- Point distribute map
distributionMap pointMap_; distributionMap pointMap_;
@ -100,6 +102,7 @@ class polyDistributionMap
// Private Member Functions // Private Member Functions
//- ...
void calcPatchSizes(); void calcPatchSizes();
@ -107,9 +110,6 @@ public:
// Constructors // Constructors
//- Construct null
polyDistributionMap();
//- Move constructor from components. //- Move constructor from components.
// Note that mesh has to be changed already // Note that mesh has to be changed already
// since uses mesh.nPoints etc as the new size. // since uses mesh.nPoints etc as the new size.
@ -140,29 +140,6 @@ public:
const bool constructFaceHasFlip = false 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 //- Disallow default bitwise copy construction
polyDistributionMap(const polyDistributionMap&) = delete; polyDistributionMap(const polyDistributionMap&) = delete;
@ -171,6 +148,12 @@ public:
// Access // Access
//- Return polyMesh
const polyMesh& mesh() const
{
return mesh_;
}
//- Number of points in mesh before distribution //- Number of points in mesh before distribution
label nOldPoints() const label nOldPoints() const
{ {
@ -234,9 +217,6 @@ public:
// Other // Other
//- Transfer the contents of the argument and annul the argument.
void transfer(polyDistributionMap&);
//- Distribute list of point data //- Distribute list of point data
template<class T> template<class T>
void distributePointData(List<T>& lst) const void distributePointData(List<T>& lst) const
@ -265,30 +245,27 @@ public:
patchMap_.distribute(lst); patchMap_.distribute(lst);
} }
//- Distribute list of point indices
//- Distribute list of point/face/cell/patch indices.
// (Converts to boolList, distributes boolList and reconstructs) // (Converts to boolList, distributes boolList and reconstructs)
void distributePointIndices(labelList& pointIDs) const; void distributePointIndices(labelList& pointIDs) const;
//- Distribute list of face indices
// (Converts to boolList, distributes boolList and reconstructs)
void distributeFaceIndices(labelList& faceIDs) const; void distributeFaceIndices(labelList& faceIDs) const;
//- Distribute list of cell indices
// (Converts to boolList, distributes boolList and reconstructs)
void distributeCellIndices(labelList& cellIDs) const; void distributeCellIndices(labelList& cellIDs) const;
//- Distribute list of patch indices
// (Converts to boolList, distributes boolList and reconstructs)
void distributePatchIndices(labelList& patchIDs) const; void distributePatchIndices(labelList& patchIDs) const;
// Member Operators // Member Operators
void operator=(const polyDistributionMap&); //- Disallow default bitwise assignment
void operator=(const polyDistributionMap&) = delete;
void operator=(polyDistributionMap&&);
// IOstream Operators
//- Read dictionary from Istream
friend Istream& operator>>(Istream&, polyDistributionMap&);
//- Write dictionary to Ostream
friend Ostream& operator<<(Ostream&, const polyDistributionMap&);
}; };

View File

@ -1300,6 +1300,8 @@ void Foam::fvMesh::distribute(const polyDistributionMap& map)
meshObject::distribute<fvMesh>(*this, map); meshObject::distribute<fvMesh>(*this, map);
meshObject::distribute<lduMesh>(*this, map); meshObject::distribute<lduMesh>(*this, map);
const_cast<Time&>(time()).functionObjects().distribute(map);
topoChanger_->distribute(map); topoChanger_->distribute(map);
distributor_->distribute(map); distributor_->distribute(map);
mover_->distribute(map); mover_->distribute(map);

View File

@ -33,6 +33,7 @@ License
#include "fvMeshStitcher.H" #include "fvMeshStitcher.H"
#include "polyTopoChangeMap.H" #include "polyTopoChangeMap.H"
#include "polyMeshMap.H" #include "polyMeshMap.H"
#include "polyDistributionMap.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * 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_);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -498,6 +498,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
}; };

View File

@ -32,6 +32,7 @@ License
#include "writeFile.H" #include "writeFile.H"
#include "polyTopoChangeMap.H" #include "polyTopoChangeMap.H"
#include "polyMeshMap.H" #include "polyMeshMap.H"
#include "polyDistributionMap.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * 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();
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -191,6 +191,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -37,6 +37,7 @@ License
#include "writeFile.H" #include "writeFile.H"
#include "polyTopoChangeMap.H" #include "polyTopoChangeMap.H"
#include "polyMeshMap.H" #include "polyMeshMap.H"
#include "polyDistributionMap.H"
#include "addToRunTimeSelectionTable.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_);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -247,6 +247,9 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Redistribute or update using the given distribution map
virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -31,6 +31,8 @@ License
#include "SortableList.H" #include "SortableList.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
#include "polyTopoChangeMap.H" #include "polyTopoChangeMap.H"
#include "polyMeshMap.H"
#include "polyDistributionMap.H"
#include "writeFile.H" #include "writeFile.H"
#include "OFstream.H" #include "OFstream.H"
#include "OSspecific.H" #include "OSspecific.H"
@ -53,8 +55,6 @@ namespace functionObjects
} }
} }
bool Foam::functionObjects::sampledSets::verbose_ = false;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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<sampledSet> newList
(
dict_.lookup("sets"),
sampledSet::iNew(mesh_, searchEngine_)
);
transfer(newList);
combineSampledSets();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::sampledSets::sampledSets Foam::functionObjects::sampledSets::sampledSets
@ -118,9 +136,42 @@ Foam::functionObjects::sampledSets::~sampledSets()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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<sampledSet> 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<sampledSet> 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<sampledSet> newList
(
dict_.lookup("sets"),
sampledSet::iNew(mesh_, searchEngine_)
);
transfer(newList);
combineSampledSets();
}
}
void Foam::functionObjects::sampledSets::movePoints(const polyMesh& mesh) void Foam::functionObjects::sampledSets::movePoints(const polyMesh& mesh)
{ {
if (&mesh == &mesh_) if (&mesh == &mesh_)
@ -307,16 +301,19 @@ void Foam::functionObjects::sampledSets::topoChange
void Foam::functionObjects::sampledSets::mapMesh(const polyMeshMap& map) 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(); correct();
} }

View File

@ -69,12 +69,6 @@ class sampledSets
public fvMeshFunctionObject, public fvMeshFunctionObject,
public PtrList<sampledSet> public PtrList<sampledSet>
{ {
// Static Data Members
//- Output verbosity
static bool verbose_;
// Private Data // Private Data
//- Keep the dictionary to recreate sets for moving mesh cases //- Keep the dictionary to recreate sets for moving mesh cases
@ -117,6 +111,9 @@ class sampledSets
// index list. Valid result only on master processor. // index list. Valid result only on master processor.
void combineSampledSets(); void combineSampledSets();
//- Correct for mesh changes
void correct();
//- Sample all fields of a type on a given set //- Sample all fields of a type on a given set
template<class Type> template<class Type>
PtrList<Field<Type>> sampleLocalType PtrList<Field<Type>> sampleLocalType
@ -163,9 +160,6 @@ public:
// Member Functions // Member Functions
//- Set verbosity level
void verbose(const bool verbosity = true);
//- Read the sampledSets //- Read the sampledSets
virtual bool read(const dictionary&); virtual bool read(const dictionary&);
@ -178,9 +172,6 @@ public:
//- Sample and write //- Sample and write
virtual bool write(); virtual bool write();
//- Correct for mesh changes
void correct();
//- Update for mesh point-motion //- Update for mesh point-motion
virtual void movePoints(const polyMesh&); virtual void movePoints(const polyMesh&);
@ -190,8 +181,8 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Update topology using the given map due to readUpdate //- Redistribute or update using the given distribution map
virtual void readUpdate(const polyMesh::readUpdateState state); virtual void distribute(const polyDistributionMap&);
// Member Operators // Member Operators

View File

@ -26,6 +26,8 @@ License
#include "sampledSurfaces.H" #include "sampledSurfaces.H"
#include "PatchTools.H" #include "PatchTools.H"
#include "polyTopoChangeMap.H" #include "polyTopoChangeMap.H"
#include "polyMeshMap.H"
#include "polyDistributionMap.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "writeFile.H" #include "writeFile.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -47,10 +49,111 @@ namespace functionObjects
} }
} }
bool Foam::functionObjects::sampledSurfaces::verbose_ = false;
Foam::scalar Foam::functionObjects::sampledSurfaces::mergeTol_ = 1e-10; 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<face>(s.faces(), s.faces().size()),
s.points()
),
mergeList_[si].points,
mergeList_[si].faces,
mergeList_[si].pointsMap
);
}
return updated;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::sampledSurfaces::sampledSurfaces Foam::functionObjects::sampledSurfaces::sampledSurfaces
@ -89,9 +192,75 @@ Foam::functionObjects::sampledSurfaces::~sampledSurfaces()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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<sampledSurface> 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<sampledSurface> 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) void Foam::functionObjects::sampledSurfaces::movePoints(const polyMesh& mesh)
{ {
if (&mesh == &mesh_) if (&mesh == &mesh_)
@ -296,8 +393,6 @@ void Foam::functionObjects::sampledSurfaces::topoChange
{ {
expire(); expire();
} }
// pointMesh and interpolation will have been reset in mesh.update
} }
@ -306,119 +401,22 @@ void Foam::functionObjects::sampledSurfaces::mapMesh
const polyMeshMap& map const polyMeshMap& map
) )
{ {
expire(); if (&map.mesh() == &mesh_)
}
void Foam::functionObjects::sampledSurfaces::readUpdate
(
const polyMesh::readUpdateState state
)
{
if (state != polyMesh::UNCHANGED)
{ {
expire(); 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()) expire();
{
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<face>(s.faces(), s.faces().size()),
s.points()
),
mergeList_[si].points,
mergeList_[si].faces,
mergeList_[si].pointsMap
);
}
return updated;
} }

View File

@ -127,9 +127,6 @@ class sampledSurfaces
// Static Data Members // Static Data Members
//- Output verbosity
static bool verbose_;
//- Tolerance for merging points (fraction of mesh bounding box) //- Tolerance for merging points (fraction of mesh bounding box)
static scalar mergeTol_; static scalar mergeTol_;
@ -166,6 +163,18 @@ class sampledSurfaces
// Private Member Functions // 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 //- Sample all fields of a type on a given surface
template<class Type> template<class Type>
PtrList<Field<Type>> sampleLocalType PtrList<Field<Type>> sampleLocalType
@ -212,21 +221,6 @@ public:
// Member Functions // 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 //- Read the sampledSurfaces dictionary
virtual bool read(const dictionary&); virtual bool read(const dictionary&);
@ -248,9 +242,8 @@ public:
//- Update from another mesh using the given map //- Update from another mesh using the given map
virtual void mapMesh(const polyMeshMap&); virtual void mapMesh(const polyMeshMap&);
//- Update topology using the given map due to readUpdate //- Redistribute or update using the given distribution map
// - expires the surfaces virtual void distribute(const polyDistributionMap&);
virtual void readUpdate(const polyMesh::readUpdateState state);
// Member Operators // Member Operators