Commit c6d4035c authored by mattijs's avatar mattijs

Added master-slave addressing for coupled points.

- Rewrote globalPoints to use globalIndex class so now only transfers
single label instead of labelPair
- Added addressing in globalMeshData
    - from coupled master points to slave points
    -         ,,          edges     ,,    edges
    - from coupled points (master or slave) to uncoupled boundary faces
    -               ,,                    ,,                      cells
- See test/globalMeshData for simple test
parent 0e0ffa40
globalMeshDataTest.C
EXE = $(FOAM_USER_APPBIN)/globalMeshDataTest
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
globalMeshDataTest
Description
Test global point communication
\*---------------------------------------------------------------------------*/
#include "globalMeshData.H"
#include "argList.H"
#include "polyMesh.H"
#include "Time.H"
#include "mapDistribute.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createPolyMesh.H"
const globalMeshData& globalData = mesh.globalData();
const indirectPrimitivePatch& coupledPatch = globalData.coupledPatch();
// Test:print shared points
{
const labelListList& globalPointSlaves =
globalData.globalPointSlaves();
const mapDistribute& globalPointSlavesMap =
globalData.globalPointSlavesMap();
pointField coords(globalPointSlavesMap.constructSize());
SubList<point>(coords, coupledPatch.nPoints()).assign
(
coupledPatch.localPoints()
);
// Exchange data
globalPointSlavesMap.distribute(coords);
// Print
forAll(globalPointSlaves, pointI)
{
const labelList& slavePoints = globalPointSlaves[pointI];
if (slavePoints.size() > 0)
{
Pout<< "Master point:" << pointI
<< " coord:" << coords[pointI]
<< " connected to slave points:" << endl;
forAll(slavePoints, i)
{
Pout<< " " << coords[slavePoints[i]] << endl;
}
}
}
}
// Test: point to faces addressing
{
const labelListList& globalPointBoundaryFaces =
globalData.globalPointBoundaryFaces();
const mapDistribute& globalPointBoundaryFacesMap =
globalData.globalPointBoundaryFacesMap();
label nBnd = mesh.nFaces()-mesh.nInternalFaces();
pointField fc(globalPointBoundaryFacesMap.constructSize());
SubList<point>(fc, nBnd).assign
(
primitivePatch
(
SubList<face>
(
mesh.faces(),
nBnd,
mesh.nInternalFaces()
),
mesh.points()
).faceCentres()
);
// Exchange data
globalPointBoundaryFacesMap.distribute(fc);
// Print
forAll(globalPointBoundaryFaces, pointI)
{
const labelList& bFaces = globalPointBoundaryFaces[pointI];
Pout<< "Point:" << pointI
<< " at:" << coupledPatch.localPoints()[pointI]
<< " connected to faces:" << endl;
forAll(bFaces, i)
{
Pout<< " " << fc[bFaces[i]] << endl;
}
}
}
// Test:point to cells addressing
{
const labelList& boundaryCells = globalData.boundaryCells();
const labelListList& globalPointBoundaryCells =
globalData.globalPointBoundaryCells();
const mapDistribute& globalPointBoundaryCellsMap =
globalData.globalPointBoundaryCellsMap();
pointField cc(globalPointBoundaryCellsMap.constructSize());
forAll(boundaryCells, i)
{
cc[i] = mesh.cellCentres()[boundaryCells[i]];
}
// Exchange data
globalPointBoundaryCellsMap.distribute(cc);
// Print
forAll(globalPointBoundaryCells, pointI)
{
const labelList& bCells = globalPointBoundaryCells[pointI];
Pout<< "Point:" << pointI
<< " at:" << coupledPatch.localPoints()[pointI]
<< " connected to cells:" << endl;
forAll(bCells, i)
{
Pout<< " " << cc[bCells[i]] << endl;
}
}
}
// Test:print shared edges
{
const labelListList& globalEdgeSlaves =
globalData.globalEdgeSlaves();
const mapDistribute& globalEdgeSlavesMap =
globalData.globalEdgeSlavesMap();
// Test: distribute edge centres
pointField ec(globalEdgeSlavesMap.constructSize());
forAll(coupledPatch.edges(), edgeI)
{
ec[edgeI] = coupledPatch.edges()[edgeI].centre
(
coupledPatch.localPoints()
);
}
// Exchange data
globalEdgeSlavesMap.distribute(ec);
// Print
forAll(globalEdgeSlaves, edgeI)
{
const labelList& slaveEdges = globalEdgeSlaves[edgeI];
if (slaveEdges.size() > 0)
{
Pout<< "Master edge:" << edgeI
<< " centre:" << ec[edgeI]
<< " connected to slave edges:" << endl;
forAll(slaveEdges, i)
{
Pout<< " " << ec[slaveEdges[i]] << endl;
}
}
}
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
......@@ -74,10 +74,13 @@ SourceFiles
#ifndef globalMeshData_H
#define globalMeshData_H
#include "polyMesh.H"
//#include "polyMesh.H"
#include "Switch.H"
#include "processorTopology.H"
#include "labelPair.H"
#include "indirectPrimitivePatch.H"
#include "boundBox.H"
#include "IOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -88,7 +91,10 @@ namespace Foam
class globalMeshData;
Ostream& operator<<(Ostream&, const globalMeshData&);
class globalIndex;
class polyMesh;
class mapDistribute;
template<class T> class EdgeMap;
/*---------------------------------------------------------------------------*\
Class globalMeshData Declaration
......@@ -194,6 +200,39 @@ class globalMeshData
mutable labelList* sharedEdgeAddrPtr_;
// Coupled point addressing
// This is addressing from coupled point to coupled points,faces,cells
// This is a full schedule so includes points only used by two
// coupled patches.
mutable autoPtr<indirectPrimitivePatch> coupledPatchPtr_;
// Coupled point to coupled points
mutable autoPtr<globalIndex> globalPointNumberingPtr_;
mutable autoPtr<labelListList> globalPointSlavesPtr_;
mutable autoPtr<mapDistribute> globalPointSlavesMapPtr_;
// Coupled edge to coupled edges
mutable autoPtr<globalIndex> globalEdgeNumberingPtr_;
mutable autoPtr<labelListList> globalEdgeSlavesPtr_;
mutable autoPtr<mapDistribute> globalEdgeSlavesMapPtr_;
// Coupled point to boundary faces
mutable autoPtr<globalIndex> globalBoundaryFaceNumberingPtr_;
mutable autoPtr<labelListList> globalPointBoundaryFacesPtr_;
mutable autoPtr<mapDistribute> globalPointBoundaryFacesMapPtr_;
// Coupled point to boundary cells
mutable autoPtr<labelList> boundaryCellsPtr_;
mutable autoPtr<globalIndex> globalBoundaryCellNumberingPtr_;
mutable autoPtr<labelListList> globalPointBoundaryCellsPtr_;
mutable autoPtr<mapDistribute> globalPointBoundaryCellsMapPtr_;
// Private Member Functions
//- Set up processor patch addressing
......@@ -202,8 +241,8 @@ class globalMeshData
//- Helper function for shared edge addressing
static void countSharedEdges
(
const HashTable<labelList, edge, Hash<edge> >& procSharedEdges,
HashTable<label, edge, Hash<edge> >&,
const EdgeMap<labelList>&,
EdgeMap<label>&,
label&
);
......@@ -217,6 +256,22 @@ class globalMeshData
const vectorField& separationDist
);
//- Calculate global point addressing.
void calcGlobalPointSlaves() const;
//- Calculate global edge addressing.
void calcGlobalEdgeSlaves() const;
//- Calculate coupled point to uncoupled boundary faces. Local only.
void calcPointBoundaryFaces(labelListList& pointBoundaryFaces) const;
//- Calculate global point to global boundary face addressing.
void calcGlobalPointBoundaryFaces() const;
//- Calculate global point to global boundary cell addressing.
void calcGlobalPointBoundaryCells() const;
//- Disallow default bitwise copy construct
globalMeshData(const globalMeshData&);
......@@ -388,6 +443,47 @@ public:
const labelList& sharedEdgeAddr() const;
// Global master - slave point communication
//- Return patch of all coupled faces
const indirectPrimitivePatch& coupledPatch() const;
// Coupled point to coupled points. Coupled points are points on
// any coupled patch.
//- Numbering of coupled points is according to coupledPatch.
const globalIndex& globalPointNumbering() const;
//- For every coupled point the indices into the field
// distributed by below map.
const labelListList& globalPointSlaves() const;
const mapDistribute& globalPointSlavesMap() const;
// Coupled edge to coupled edges.
const globalIndex& globalEdgeNumbering() const;
const labelListList& globalEdgeSlaves() const;
const mapDistribute& globalEdgeSlavesMap() const;
// Coupled point to boundary faces. These are uncoupled boundary
// faces only but include empty patches.
//- Numbering of boundary faces is face-mesh.nInternalFaces()
const globalIndex& globalBoundaryFaceNumbering() const;
const labelListList& globalPointBoundaryFaces() const;
const mapDistribute& globalPointBoundaryFacesMap() const;
// Coupled point to boundary cell
//- From boundary cell to mesh cell
const labelList& boundaryCells() const;
//- Numbering of boundary cells is according to boundaryCells()
const globalIndex& globalBoundaryCellNumbering() const;
const labelListList& globalPointBoundaryCells() const;
const mapDistribute& globalPointBoundaryCellsMap() const;
// Edit
//- Update for moving points.
......
......@@ -29,9 +29,8 @@ Description
Calculates points shared by more than two processor patches or cyclic
patches.
Is used in globalMeshData. (this info is needed for point-edge
communication where you do all but these shared points with patch to
patch communication but need to do a reduce on these shared points)
Is used in globalMeshData. (this info is needed for point/edge
communication where processor swaps are not enough to exchange data)
Works purely topological and using local communication only.
Needs:
......@@ -41,8 +40,8 @@ Description
- f[0] ordering on patch faces to be ok.
Works by constructing equivalence lists for all the points on processor
patches. These list are procPointList and give processor and meshPoint
label on that processor.
patches. These list are in globalIndex numbering (so consecutively numbered
per processor)
E.g.
@verbatim
((7 93)(4 731)(3 114))
......@@ -85,6 +84,9 @@ Description
endloop until nothing changes.
Note: the data held is either mesh point labels (construct from mesh only)
or patch point labels (construct from mesh and patch).
SourceFiles
globalPoints.C
......@@ -95,11 +97,11 @@ SourceFiles
#include "DynamicList.H"
#include "Map.H"
#include "labelList.H"
#include "FixedList.H"
#include "primitivePatch.H"
#include "className.H"
#include "edgeList.H"
#include "globalIndex.H"
#include "indirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -119,30 +121,29 @@ class globalPoints
{
// Private classes
//- Define procPointList as holding a list of meshPoint/processor labels
typedef FixedList<label, 2> procPoint;
typedef List<procPoint> procPointList;
// Private data
//- Mesh reference
const polyMesh& mesh_;
//- Global numbering of points
globalIndex globalIndices_;
//- Sum of points on processor patches (unfiltered, point on 2 patches
// counts as 2)
const label nPatchPoints_;
//- All points on boundaries and their corresponding connected points
// on other processors.
DynamicList<procPointList> procPoints_;
DynamicList<labelList> procPoints_;
//- Map from mesh point to index in procPoints
//- Map from mesh (or patch) point to index in procPoints
Map<label> meshToProcPoint_;
//- Shared points used by this processor (= global point number)
labelList sharedPointAddr_;
//- My meshpoints corresponding to the shared points
//- My mesh(or patch) points corresponding to the shared points
labelList sharedPointLabels_;
//- Total number of shared points.
......@@ -155,56 +156,108 @@ class globalPoints
// information is collected.
static label countPatchPoints(const polyBoundaryMesh&);
////- Get all faces on coupled patches
//static labelListl coupledFaces(const polyBoundaryMesh&);
//- Add information about patchPointI in relative indices to send
// buffers (patchFaces, indexInFace etc.)
static void addToSend
(
const primitivePatch&,
const label patchPointI,
const procPointList&,
const labelList&,
DynamicList<label>& patchFaces,
DynamicList<label>& indexInFace,
DynamicList<procPointList>& allInfo
DynamicList<labelList>& allInfo
);
//- Merge info from neighbour into my data
static bool mergeInfo
(
const procPointList& nbrInfo,
procPointList& myInfo
const labelList& nbrInfo,
labelList& myInfo
);
//- From mesh point to 'local point'. Is the mesh point itself
// if meshToPatchPoint is empty.
static label meshToLocalPoint
(
const Map<label>& meshToPatchPoint,
const label meshPointI
);
//- Opposite of meshToLocalPoint.
static label localToMeshPoint
(
const labelList& patchToMeshPoint,
const label localPointI
);
//- Store (and merge) info for meshPointI
bool storeInfo(const procPointList& nbrInfo, const label meshPointI);
bool storeInfo
(
const labelList& nbrInfo,
const label localPointI
);
//- Initialize procPoints_ to my patch points. allPoints = true:
// seed with all patch points, = false: only boundaryPoints().
void initOwnPoints(const bool allPoints, labelHashSet& changedPoints);
void initOwnPoints
(
const Map<label>& meshToPatchPoint,
const bool allPoints,
labelHashSet& changedPoints
);
//- Send subset of procPoints to neighbours
void sendPatchPoints(const labelHashSet& changedPoints) const;
void sendPatchPoints
(
const Map<label>&,
PstreamBuffers&,
const labelHashSet&
) const;
//- Receive neighbour points and merge into my procPoints.
void receivePatchPoints(labelHashSet& changedPoints);
void receivePatchPoints
(
const Map<label>&,
PstreamBuffers&,
labelHashSet&
);
//- Remove entries of size 2 where meshPoint is in provided Map.
// Used to remove normal face-face connected points.
void remove(const Map<label>&);
void remove(const labelList& patchToMeshPoint, const Map<label>&);
//- Compact out unused elements of procPoints.
void compact();
//- Get indices of point for which I am master (lowest numbered proc)
labelList getMasterPoints() const;
labelList getMasterPoints(const labelList& patchToMeshPoint) const;
//- Send subset of shared points to neighbours
void sendSharedPoints(const labelList& changedIndices) const;
void sendSharedPoints(PstreamBuffers&, const labelList&) const;
//- Receive shared points and update subset.
void receiveSharedPoints(labelList& changedIndices);
void receiveSharedPoints
(
const Map<label>&,
PstreamBuffers&,
labelList&
);
//- Should move into cyclicPolyPatch but some ordering problem
//- Should move into cyclicPolyPatch ordering problem
// keeps on giving problems.
static edgeList coupledPoints(const cyclicPolyPatch&);
//- Do all calculations.
void calculateSharedPoints
(
const Map<label>&,
const labelList&,
const bool keepAllPoints
);
//- Disallow default bitwise copy construct
globalPoints(const globalPoints&);
......@@ -220,22 +273,44 @@ public:
// Constructors
//- Construct from mesh
globalPoints(const polyMesh& mesh);
//- Construct from mesh.
// keepAllPoints = false : filter out points that are on two
// neighbouring coupled patches (so can be swapped)
globalPoints(const polyMesh& mesh, const bool keepAllPoints);
//- Construct from mesh and patch of coupled faces. Difference with
// construct from mesh only is that this stores the meshToProcPoint,
// procPoints and sharedPointLabels as patch local point labels
// instead of mesh point labels.
globalPoints
(
const polyMesh& mesh,
const indirectPrimitivePatch& coupledPatch,
const bool keepAllPoints
);
// Member Functions
// Access
label nPatchPoints() const