Commit 6332402a authored by Franjo's avatar Franjo
Browse files

Implemented sending of coordinates with range

parent fc671971
......@@ -22,20 +22,20 @@ License
along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
Class
labelledMeshOctreeCubeCoordinates
meshOctreCubeCoordinatesScalar
Description
A class containing point label and meshOctreeCubeCoordinates.
A class containing meshOctreeCubeCoordinates and a scalar value.
It is used for exchanging data over processors
SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef labelledMeshOctreeCubeCoordinates_H
#define labelledMeshOctreeCubeCoordinates_H
#ifndef meshOctreeCubeCoordinatesScalar_H
#define meshOctreeCubeCoordinatesScalar_H
#include "label.H"
#include "scalar.H"
#include "meshOctreeCubeCoordinates.H"
#include "contiguous.H"
......@@ -45,129 +45,137 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class labelledMeshOctreeCubeCoordinates Declaration
Class meshOctreeCubeCoordinatesScalar Declaration
\*---------------------------------------------------------------------------*/
class labelledMeshOctreeCubeCoordinates
class meshOctreeCubeCoordinatesScalar
{
// Private data
//- label
label cLabel_;
//- scalar
scalar sValue_;
//- cube coordinates
meshOctreeCubeCoordinates coordinates_;
public:
// Constructors
//- Null construct
labelledMeshOctreeCubeCoordinates()
meshOctreeCubeCoordinatesScalar()
:
cLabel_(-1),
sValue_(0.0),
coordinates_()
{}
//- Construct from label and cube coordinates
labelledMeshOctreeCubeCoordinates
meshOctreeCubeCoordinatesScalar
(
const label cl,
const scalar s,
const meshOctreeCubeCoordinates& cc
)
:
cLabel_(cl),
sValue_(s),
coordinates_(cc)
{}
// Destructor
~labelledMeshOctreeCubeCoordinates()
~meshOctreeCubeCoordinatesScalar()
{}
// Member functions
//- return cube label
inline label cubeLabel() const
inline scalar scalarValue() const
{
return cLabel_;
return sValue_;
}
//- return the value
inline const meshOctreeCubeCoordinates& coordinates() const
{
return coordinates_;
}
// Member operators
inline void operator=(const labelledMeshOctreeCubeCoordinates& lcc)
inline bool operator<(const meshOctreeCubeCoordinatesScalar& scc) const
{
cLabel_ = lcc.cLabel_;
coordinates_ = lcc.coordinates_;
if( coordinates_ < scc.coordinates_ )
return true;
return false;
}
inline void operator=(const meshOctreeCubeCoordinatesScalar& scc)
{
sValue_ = scc.sValue_;
coordinates_ = scc.coordinates_;
}
inline bool operator==
(
const labelledMeshOctreeCubeCoordinates& lcc
const meshOctreeCubeCoordinatesScalar& scc
) const
{
if( cLabel_ == lcc.cLabel_ )
if( coordinates_ == scc.coordinates_ )
return true;
return false;
}
inline bool operator!=
(
const labelledMeshOctreeCubeCoordinates& lcc
const meshOctreeCubeCoordinatesScalar& scc
) const
{
return !this->operator==(lcc);
return !this->operator==(scc);
}
// Friend operators
friend Ostream& operator<<
(
Ostream& os,
const labelledMeshOctreeCubeCoordinates& lcc
const meshOctreeCubeCoordinatesScalar& scc
)
{
os << token::BEGIN_LIST;
os << lcc.cLabel_ << token::SPACE;
os << lcc.coordinates_ << token::END_LIST;
os << scc.sValue_ << token::SPACE;
os << scc.coordinates_ << token::END_LIST;
// Check state of Ostream
os.check
(
"operator<<(Ostream&, const labelledMeshOctreeCubeCoordinates&"
"operator<<(Ostream&, const meshOctreCubeCoordinatesScalar&"
);
return os;
}
friend Istream& operator>>
(
Istream& is,
labelledMeshOctreeCubeCoordinates& lcc
meshOctreeCubeCoordinatesScalar& scc
)
{
// Read beginning of labelledMeshOctreeCubeCoordinates
is.readBegin("labelledMeshOctreeCubeCoordinates");
is >> lcc.cLabel_;
is >> lcc.coordinates_;
// Read end of labelledMeshOctreeCubeCoordinates
is.readEnd("labelledMeshOctreeCubeCoordinates");
// Read beginning of meshOctreCubeCoordinatesScalar
is.readBegin("meshOctreCubeCoordinatesScalar");
is >> scc.sValue_;
is >> scc.coordinates_;
// Read end of meshOctreCubeCoordinatesScalar
is.readEnd("meshOctreCubeCoordinatesScalar");
// Check state of Istream
is.check("operator>>(Istream&, labelledMeshOctreeCubeCoordinates");
is.check("operator>>(Istream&, meshOctreCubeCoordinatesScalar");
return is;
}
};
//- Specify data associated with labelledMeshOctreeCubeCoordinates
//- Specify data associated with meshOctreCubeCoordinatesScalar
//- type is contiguous
template<>
inline bool contiguous<labelledMeshOctreeCubeCoordinates>() {return true;}
inline bool contiguous<meshOctreeCubeCoordinatesScalar>() {return true;}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -138,6 +138,14 @@ public:
//- find a cube containing the vertex
label findLeafContainingVertex(const point&) const;
//- find leaves within the given range from the given point
void findLeavesInSphere
(
const point&,
const scalar,
DynList<label>&
) const;
//- is octree a quadtree or an octree
inline bool isQuadtree() const;
......@@ -334,6 +342,15 @@ public:
LongList<meshOctreeCubeCoordinates>& dataToReceive
) const;
//- exchange requests with other processors generating the octree
void exchangeRequestsWithNeighbourProcessors
(
const LongList<meshOctreeCubeCoordinates>& dataToSend,
const LongList<scalar>& rangesToSend,
LongList<meshOctreeCubeCoordinates>& dataToReceive,
LongList<scalar>& receivedRanges
) const;
//- neighbour processors of the current one
inline const labelList& neiProcs() const;
};
......
......@@ -91,6 +91,18 @@ label meshOctree::findLeafContainingVertex
return meshOctreeCubeBasic::OTHERPROC;
}
void meshOctree::findLeavesInSphere
(
const point& c,
const scalar r,
DynList<label>& containedLeaves
) const
{
containedLeaves.clear();
initialCubePtr_->leavesInSphere(rootBox_, c, r, containedLeaves);
}
label meshOctree::findNeighbourOverNode
(
const meshOctreeCubeCoordinates& cc,
......
......@@ -188,6 +188,226 @@ void meshOctree::exchangeRequestsWithNeighbourProcessors
toOtherProc << toProcs[neiProcI];
}
}
void meshOctree::exchangeRequestsWithNeighbourProcessors
(
const LongList<meshOctreeCubeCoordinates>& dataToSend,
const LongList<scalar>& rangesToSend,
LongList<meshOctreeCubeCoordinates>& dataToReceive,
LongList<scalar>& receivedRanges
) const
{
if( !Pstream::parRun() || (neiProcs_.size() == 0) )
{
//- this is a serial run
return;
}
List<LongList<meshOctreeCubeCoordinates> > toProcs
(
neiProcs_.size(),
LongList<meshOctreeCubeCoordinates>()
);
List<LongList<scalar> > attributesToProcs
(
neiProcs_.size(),
LongList<scalar>()
);
meshOctreeCubeCoordinates minCoord, maxCoord;
forAll(dataToSend, i)
{
dataToSend[i].neighbourRange(minCoord, maxCoord);
const scalar size = dataToSend[i].size(rootBox_);
const label nLayers = ceil(rangesToSend[i] / size);
minCoord =
meshOctreeCubeCoordinates
(
minCoord.posX() - nLayers,
minCoord.posY() - nLayers,
minCoord.posZ() - nLayers,
minCoord.level()
);
maxCoord =
meshOctreeCubeCoordinates
(
nLayers + maxCoord.posX(),
nLayers + maxCoord.posY(),
nLayers + maxCoord.posZ(),
maxCoord.level()
);
# ifdef OCTREE_DEBUG
label counter(0);
# endif
forAll(neiProcs_, procI)
{
if( maxCoord >= neiRange_[procI].first() )
{
if( minCoord <= neiRange_[procI].second() )
{
toProcs[procI].append(dataToSend[i]);
attributesToProcs[procI].append(rangesToSend[i]);
# ifdef OCTREE_DEBUG
++counter;
# endif
}
}
else
{
break;
}
}
}
//- send an receive the size of data chunk which will be exchanged
forAll(neiProcs_, neiProcI)
{
OPstream toOtherProc
(
Pstream::blocking,
neiProcs_[neiProcI],
sizeof(label)
);
toOtherProc << toProcs[neiProcI].size();
}
labelList sizeOfOtherProc(neiProcs_.size());
forAll(neiProcs_, neiProcI)
{
IPstream fromOtherProc
(
Pstream::blocking,
neiProcs_[neiProcI],
sizeof(label)
);
fromOtherProc >> sizeOfOtherProc[neiProcI];
}
//- exchange data between processors
//- upper-diagonal communication
forAll(neiProcs_, neiProcI)
{
if( sizeOfOtherProc[neiProcI] == 0 )
continue;
if( neiProcs_[neiProcI] >= Pstream::myProcNo() )
continue;
//- receive data from other processor
IPstream fromOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
dataToReceive.appendFromStream(fromOtherProc);
}
forAll(neiProcs_, neiProcI)
{
if( toProcs[neiProcI].size() == 0 )
continue;
if( neiProcs_[neiProcI] <= Pstream::myProcNo() )
continue;
//- send data to other processor
OPstream toOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
toOtherProc << toProcs[neiProcI];
}
//- lower-diagonal communication
forAllReverse(neiProcs_, neiProcI)
{
if( sizeOfOtherProc[neiProcI] == 0 )
continue;
if( neiProcs_[neiProcI] <= Pstream::myProcNo() )
continue;
//- receive data from other processor
IPstream fromOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
dataToReceive.appendFromStream(fromOtherProc);
}
forAllReverse(neiProcs_, neiProcI)
{
if( toProcs[neiProcI].size() == 0 )
continue;
if( neiProcs_[neiProcI] >= Pstream::myProcNo() )
continue;
//- send data to other processor
OPstream toOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
toOtherProc << toProcs[neiProcI];
}
//- exchange attributes
//- exchange data between processors
//- upper-diagonal communication
forAll(neiProcs_, neiProcI)
{
if( sizeOfOtherProc[neiProcI] == 0 )
continue;
if( neiProcs_[neiProcI] >= Pstream::myProcNo() )
continue;
//- receive data from other processor
IPstream fromOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
receivedRanges.appendFromStream(fromOtherProc);
}
forAll(neiProcs_, neiProcI)
{
if( toProcs[neiProcI].size() == 0 )
continue;
if( neiProcs_[neiProcI] <= Pstream::myProcNo() )
continue;
//- send data to other processor
OPstream toOtherProc
(
Pstream::scheduled,
neiProcs_[neiProcI],
attributesToProcs[neiProcI].byteSize()
);
toOtherProc << attributesToProcs[neiProcI];
}
//- lower-diagonal communication
forAllReverse(neiProcs_, neiProcI)
{
if( sizeOfOtherProc[neiProcI] == 0 )
continue;
if( neiProcs_[neiProcI] <= Pstream::myProcNo() )
continue;
//- receive data from other processor
IPstream fromOtherProc(Pstream::scheduled, neiProcs_[neiProcI]);
receivedRanges.appendFromStream(fromOtherProc);
}
forAllReverse(neiProcs_, neiProcI)
{
if( toProcs[neiProcI].size() == 0 )
continue;
if( neiProcs_[neiProcI] >= Pstream::myProcNo() )
continue;
//- send data to other processor
OPstream toOtherProc
(
Pstream::scheduled,
neiProcs_[neiProcI],
attributesToProcs[neiProcI].byteSize()
);
toOtherProc << attributesToProcs[neiProcI];
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment