ENH: use PstreamBuffers for finiteArea handling (as per volume)

This commit is contained in:
Mark Olesen
2022-03-08 19:10:56 +01:00
parent 0e2ef5db3b
commit 71772f17ab
9 changed files with 225 additions and 112 deletions

View File

@ -174,14 +174,46 @@ void Foam::faBoundaryMesh::calcGeometry()
// force construction. // force construction.
(void)mesh_.pointAreaNormals(); (void)mesh_.pointAreaNormals();
PstreamBuffers pBufs(Pstream::defaultCommsType);
if
(
pBufs.commsType() == Pstream::commsTypes::blocking
|| pBufs.commsType() == Pstream::commsTypes::nonBlocking
)
{
forAll(*this, patchi) forAll(*this, patchi)
{ {
operator[](patchi).initGeometry(); operator[](patchi).initGeometry(pBufs);
} }
pBufs.finishedSends();
forAll(*this, patchi) forAll(*this, patchi)
{ {
operator[](patchi).calcGeometry(); operator[](patchi).calcGeometry(pBufs);
}
}
else if (pBufs.commsType() == Pstream::commsTypes::scheduled)
{
const lduSchedule& patchSchedule = mesh().globalData().patchSchedule();
// Dummy.
pBufs.finishedSends();
for (const auto& patchEval : patchSchedule)
{
const label patchi = patchEval.patch;
if (patchEval.init)
{
operator[](patchi).initGeometry(pBufs);
}
else
{
operator[](patchi).calcGeometry(pBufs);
}
}
} }
} }
@ -633,32 +665,92 @@ void Foam::faBoundaryMesh::movePoints(const pointField& p)
// force construction. // force construction.
(void)mesh_.pointAreaNormals(); (void)mesh_.pointAreaNormals();
faPatchList& patches = *this; PstreamBuffers pBufs(Pstream::defaultCommsType);
forAll(patches, patchi) if
(
pBufs.commsType() == Pstream::commsTypes::blocking
|| pBufs.commsType() == Pstream::commsTypes::nonBlocking
)
{ {
patches[patchi].initMovePoints(p); forAll(*this, patchi)
{
operator[](patchi).initMovePoints(pBufs, p);
} }
forAll(patches, patchi) pBufs.finishedSends();
forAll(*this, patchi)
{ {
patches[patchi].movePoints(p); operator[](patchi).movePoints(pBufs, p);
}
}
else if (pBufs.commsType() == Pstream::commsTypes::scheduled)
{
const lduSchedule& patchSchedule = mesh().globalData().patchSchedule();
// Dummy.
pBufs.finishedSends();
for (const auto& schedEval : patchSchedule)
{
const label patchi = schedEval.patch;
if (schedEval.init)
{
operator[](patchi).initMovePoints(pBufs, p);
}
else
{
operator[](patchi).movePoints(pBufs, p);
}
}
} }
} }
void Foam::faBoundaryMesh::updateMesh() void Foam::faBoundaryMesh::updateMesh()
{ {
faPatchList& patches = *this; PstreamBuffers pBufs(Pstream::defaultCommsType);
forAll(patches, patchi) if
(
pBufs.commsType() == Pstream::commsTypes::blocking
|| pBufs.commsType() == Pstream::commsTypes::nonBlocking
)
{ {
patches[patchi].initUpdateMesh(); forAll(*this, patchi)
{
operator[](patchi).initUpdateMesh(pBufs);
} }
forAll(patches, patchi) pBufs.finishedSends();
forAll(*this, patchi)
{ {
patches[patchi].updateMesh(); operator[](patchi).updateMesh(pBufs);
}
}
else if (pBufs.commsType() == Pstream::commsTypes::scheduled)
{
const lduSchedule& patchSchedule = mesh().globalData().patchSchedule();
// Dummy.
pBufs.finishedSends();
for (const auto& schedEval : patchSchedule)
{
const label patchi = schedEval.patch;
if (schedEval.init)
{
operator[](patchi).initUpdateMesh(pBufs);
}
else
{
operator[](patchi).updateMesh(pBufs);
}
}
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1090,7 +1090,7 @@ void Foam::faMesh::calcPointAreaNormals_orig(vectorField& result) const
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
patchPointNormals.cdata_bytes(), patchPointNormals.cdata_bytes(),
patchPointNormals.byteSize() patchPointNormals.size_bytes()
); );
} }
@ -1106,7 +1106,7 @@ void Foam::faMesh::calcPointAreaNormals_orig(vectorField& result) const
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
ngbPatchPointNormals.data_bytes(), ngbPatchPointNormals.data_bytes(),
ngbPatchPointNormals.byteSize() ngbPatchPointNormals.size_bytes()
); );
} }
@ -1330,7 +1330,7 @@ void Foam::faMesh::calcPointAreaNormals(vectorField& result) const
( (
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
reinterpret_cast<const char*>(patchPointNormals.cdata()), patchPointNormals.cdata_bytes(),
patchPointNormals.size_bytes() patchPointNormals.size_bytes()
); );
} }
@ -1343,7 +1343,7 @@ void Foam::faMesh::calcPointAreaNormals(vectorField& result) const
( (
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
reinterpret_cast<char*>(patchPointNormals.data()), patchPointNormals.data_bytes(),
patchPointNormals.size_bytes() patchPointNormals.size_bytes()
); );
} }
@ -1656,8 +1656,8 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit(vectorField& result) const
( (
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
toNgbProcLsPoints.byteSize() toNgbProcLsPoints.size_bytes()
+ toNgbProcLsPointStarts.byteSize() + toNgbProcLsPointStarts.size_bytes()
+ 10*sizeof(label) + 10*sizeof(label)
); );
@ -1686,7 +1686,7 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit(vectorField& result) const
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
procPatch.neighbProcNo(), procPatch.neighbProcNo(),
10*patchPointLabels.size()*sizeof(vector) 10*patchPointLabels.size()*sizeof(vector)
+ fromNgbProcLsPointStarts.byteSize() + fromNgbProcLsPointStarts.size_bytes()
+ 10*sizeof(label) + 10*sizeof(label)
); );

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -150,7 +151,16 @@ public:
return true; return true;
} }
//- Are the coupled planes separated //- Does this side own the patch ?
virtual bool owner() const = 0;
//- Does the coupled side own the patch ?
virtual bool neighbour() const
{
return !owner();
}
//- Are the coupled planes separated?
bool separated() const bool separated() const
{ {
return separation_.size(); return separation_.size();
@ -204,16 +214,16 @@ public:
//- Initialise the calculation of the patch geometry //- Initialise the calculation of the patch geometry
virtual void initGeometry() = 0; virtual void initGeometry(PstreamBuffers&) = 0;
//- Calculate the patch geometry //- Calculate the patch geometry
virtual void calcGeometry() = 0; virtual void calcGeometry(PstreamBuffers&) = 0;
//- Initialise the patches for moving points //- Initialise the patches for moving points
virtual void initMovePoints(const pointField&) = 0; virtual void initMovePoints(PstreamBuffers&, const pointField&) = 0;
//- Correct patches after moving points //- Correct patches after moving points
virtual void movePoints(const pointField&) = 0; virtual void movePoints(PstreamBuffers&, const pointField&) = 0;
// Access functions for demand driven data // Access functions for demand driven data

View File

@ -236,28 +236,36 @@ void Foam::cyclicFaPatch::makeDeltaCoeffs(scalarField& dc) const
} }
void Foam::cyclicFaPatch::initGeometry() void Foam::cyclicFaPatch::initGeometry(PstreamBuffers& pBufs)
{ {
faPatch::initGeometry(); faPatch::initGeometry(pBufs);
} }
void Foam::cyclicFaPatch::calcGeometry() void Foam::cyclicFaPatch::calcGeometry(PstreamBuffers& pBufs)
{ {
faPatch::calcGeometry(); faPatch::calcGeometry(pBufs);
calcTransforms(); calcTransforms();
} }
void Foam::cyclicFaPatch::initMovePoints(const pointField& p) void Foam::cyclicFaPatch::initMovePoints
(
PstreamBuffers& pBufs,
const pointField& p
)
{ {
faPatch::initMovePoints(p); faPatch::initMovePoints(pBufs, p);
} }
void Foam::cyclicFaPatch::movePoints(const pointField& p) void Foam::cyclicFaPatch::movePoints
(
PstreamBuffers& pBufs,
const pointField& p
)
{ {
faPatch::movePoints(p); faPatch::movePoints(pBufs, p);
calcTransforms(); calcTransforms();
} }

View File

@ -109,8 +109,9 @@ public:
// Access // Access
//- Is this the master side? Yes: it contains both sets of faces //- Does this side own the patch ?
virtual bool master() const //- Yes: it contains both sets of faces
virtual bool owner() const
{ {
return true; return true;
} }
@ -122,11 +123,6 @@ public:
return index(); return index();
} }
virtual bool owner() const
{
return master();
}
//- Return processor number //- Return processor number
virtual const cyclicLduInterface& neighbPatch() const virtual const cyclicLduInterface& neighbPatch() const
{ {
@ -147,16 +143,16 @@ public:
} }
//- Initialise the calculation of the patch geometry //- Initialise the calculation of the patch geometry
virtual void initGeometry(); virtual void initGeometry(PstreamBuffers&);
//- Calculate the patch geometry //- Calculate the patch geometry
virtual void calcGeometry(); virtual void calcGeometry(PstreamBuffers&);
//- Initialise the patches for moving points //- Initialise the patches for moving points
virtual void initMovePoints(const pointField&); virtual void initMovePoints(PstreamBuffers&, const pointField&);
//- Correct patches after moving points //- Correct patches after moving points
virtual void movePoints(const pointField&); virtual void movePoints(PstreamBuffers&, const pointField&);
//- Return delta (P to N) vectors across coupled patch //- Return delta (P to N) vectors across coupled patch
virtual tmp<vectorField> delta() const; virtual tmp<vectorField> delta() const;

View File

@ -128,12 +128,6 @@ Foam::label Foam::processorFaPatch::comm() const
} }
int Foam::processorFaPatch::tag() const
{
return Pstream::msgType();
}
void Foam::processorFaPatch::makeNonGlobalPatchPoints() const void Foam::processorFaPatch::makeNonGlobalPatchPoints() const
{ {
// If it is not running parallel or there are no global points // If it is not running parallel or there are no global points
@ -181,16 +175,21 @@ void Foam::processorFaPatch::makeNonGlobalPatchPoints() const
} }
void Foam::processorFaPatch::initGeometry() void Foam::processorFaPatch::initGeometry(PstreamBuffers& pBufs)
{ {
if (Pstream::parRun()) if (Pstream::parRun())
{ {
OPstream toNeighbProc if (neighbProcNo() >= Pstream::nProcs(pBufs.comm()))
( {
Pstream::commsTypes::blocking, FatalErrorInFunction
neighbProcNo(), << "On patch " << name()
3*(sizeof(label) + size()*sizeof(vector)) << " trying to access out of range neighbour processor "
); << neighbProcNo() << ". This can happen if" << nl
<< " trying to run on an incorrect number of processors"
<< exit(FatalError);
}
UOPstream toNeighbProc(neighbProcNo(), pBufs);
toNeighbProc toNeighbProc
<< edgeCentres() << edgeCentres()
@ -200,17 +199,13 @@ void Foam::processorFaPatch::initGeometry()
} }
void Foam::processorFaPatch::calcGeometry() void Foam::processorFaPatch::calcGeometry(PstreamBuffers& pBufs)
{ {
if (Pstream::parRun()) if (Pstream::parRun())
{ {
{ {
IPstream fromNeighbProc UIPstream fromNeighbProc(neighbProcNo(), pBufs);
(
Pstream::commsTypes::blocking,
neighbProcNo(),
3*(sizeof(label) + size()*sizeof(vector))
);
fromNeighbProc fromNeighbProc
>> neighbEdgeCentres_ >> neighbEdgeCentres_
>> neighbEdgeLengths_ >> neighbEdgeLengths_
@ -246,28 +241,46 @@ void Foam::processorFaPatch::calcGeometry()
} }
void Foam::processorFaPatch::initMovePoints(const pointField& p) void Foam::processorFaPatch::initMovePoints
(
PstreamBuffers& pBufs,
const pointField& p
)
{ {
faPatch::movePoints(p); faPatch::movePoints(pBufs, p);
initGeometry(); initGeometry(pBufs);
} }
void Foam::processorFaPatch::movePoints(const pointField&) void Foam::processorFaPatch::movePoints
(
PstreamBuffers& pBufs,
const pointField&
)
{ {
calcGeometry(); processorFaPatch::calcGeometry(pBufs);
} }
void Foam::processorFaPatch::initUpdateMesh() void Foam::processorFaPatch::initUpdateMesh(PstreamBuffers& pBufs)
{ {
// For completeness // For completeness
faPatch::initUpdateMesh(); faPatch::initUpdateMesh(pBufs);
neighbPointsPtr_.clear(); neighbPointsPtr_.clear();
if (Pstream::parRun()) if (Pstream::parRun())
{ {
if (neighbProcNo() >= Pstream::nProcs(pBufs.comm()))
{
FatalErrorInFunction
<< "On patch " << name()
<< " trying to access out of range neighbour processor "
<< neighbProcNo() << ". This can happen if" << nl
<< " trying to run on an incorrect number of processors"
<< exit(FatalError);
}
// Express all points as patch edge and index in edge. // Express all points as patch edge and index in edge.
labelList patchEdge(nPoints()); labelList patchEdge(nPoints());
labelList indexInEdge(nPoints()); labelList indexInEdge(nPoints());
@ -288,12 +301,7 @@ void Foam::processorFaPatch::initUpdateMesh()
indexInEdge[patchPointI] = e.find(pointLabels()[patchPointI]); indexInEdge[patchPointI] = e.find(pointLabels()[patchPointI]);
} }
OPstream toNeighbProc UOPstream toNeighbProc(neighbProcNo(), pBufs);
(
Pstream::commsTypes::blocking,
neighbProcNo(),
2*sizeof(label) + 2*nPoints()*sizeof(label)
);
toNeighbProc toNeighbProc
<< patchEdge << patchEdge
@ -302,10 +310,12 @@ void Foam::processorFaPatch::initUpdateMesh()
} }
void Foam::processorFaPatch::updateMesh() void Foam::processorFaPatch::updateMesh(PstreamBuffers& pBufs)
{ {
// For completeness // For completeness
faPatch::updateMesh(); faPatch::updateMesh(pBufs);
neighbPointsPtr_.clear();
if (Pstream::parRun()) if (Pstream::parRun())
{ {
@ -315,11 +325,8 @@ void Foam::processorFaPatch::updateMesh()
{ {
// Note cannot predict exact size since edgeList not (yet) sent as // Note cannot predict exact size since edgeList not (yet) sent as
// binary entity but as List of edges. // binary entity but as List of edges.
IPstream fromNeighbProc
( UIPstream fromNeighbProc(neighbProcNo(), pBufs);
Pstream::commsTypes::blocking,
neighbProcNo()
);
fromNeighbProc fromNeighbProc
>> nbrPatchEdge >> nbrPatchEdge
@ -352,7 +359,6 @@ void Foam::processorFaPatch::updateMesh()
{ {
// Differing number of points. Probably patch includes // Differing number of points. Probably patch includes
// part of a cyclic. // part of a cyclic.
neighbPointsPtr_.clear();
} }
} }
} }

View File

@ -115,22 +115,22 @@ protected:
// Geometry Functions // Geometry Functions
//- Initialise the calculation of the patch geometry //- Initialise the calculation of the patch geometry
void initGeometry(); void initGeometry(PstreamBuffers&);
//- Calculate the patch geometry //- Calculate the patch geometry
void calcGeometry(); void calcGeometry(PstreamBuffers&);
//- Initialise the patches for moving points //- Initialise the patches for moving points
void initMovePoints(const pointField&); void initMovePoints(PstreamBuffers&, const pointField&);
//- Correct patches after moving points //- Correct patches after moving points
void movePoints(const pointField&); void movePoints(PstreamBuffers&, const pointField&);
//- Initialise the update of the patch topology //- Initialise the update of the patch topology
virtual void initUpdateMesh(); virtual void initUpdateMesh(PstreamBuffers&);
//- Update of the patch topology //- Update of the patch topology
virtual void updateMesh(); virtual void updateMesh(PstreamBuffers&);
public: public:
@ -194,21 +194,22 @@ public:
return Pstream::parRun(); return Pstream::parRun();
} }
//- Is this the master side? //- Does this side own the patch ?
virtual bool master() const noexcept virtual bool owner() const noexcept
{ {
return (myProcNo_ < neighbProcNo_); return (myProcNo_ < neighbProcNo_);
} }
// Communications support //- The message tag to use for communication
virtual int tag() const
{
return UPstream::msgType();
}
//- Return communicator used for communication //- Return communicator used for communication
virtual label comm() const; virtual label comm() const;
//- Return message tag to use for communication
virtual int tag() const;
//- Return face transformation tensor //- Return face transformation tensor
virtual const tensorField& forwardT() const virtual const tensorField& forwardT() const

View File

@ -531,7 +531,7 @@ const Foam::scalarField& Foam::faPatch::weights() const
} }
void Foam::faPatch::movePoints(const pointField& points) void Foam::faPatch::movePoints(PstreamBuffers&, const pointField&)
{} {}

View File

@ -116,26 +116,26 @@ protected:
void calcPointEdges() const; void calcPointEdges() const;
//- Initialise the calculation of the patch geometry //- Initialise the calculation of the patch geometry
virtual void initGeometry() virtual void initGeometry(PstreamBuffers&)
{} {}
//- Calculate the patch geometry //- Calculate the patch geometry
virtual void calcGeometry() virtual void calcGeometry(PstreamBuffers&)
{} {}
//- Initialise the patches for moving points //- Initialise the patches for moving points
virtual void initMovePoints(const pointField&) virtual void initMovePoints(PstreamBuffers&, const pointField&)
{} {}
//- Correct patch after moving points //- Correct patch after moving points
virtual void movePoints(const pointField&); virtual void movePoints(PstreamBuffers&, const pointField&);
//- Initialise the update of the patch topology //- Initialise the update of the patch topology
virtual void initUpdateMesh() virtual void initUpdateMesh(PstreamBuffers&)
{} {}
//- Update of the patch topology //- Update of the patch topology
virtual void updateMesh() virtual void updateMesh(PstreamBuffers&)
{} {}