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 ...@@ -74,10 +74,13 @@ SourceFiles
#ifndef globalMeshData_H #ifndef globalMeshData_H
#define globalMeshData_H #define globalMeshData_H
#include "polyMesh.H" //#include "polyMesh.H"
#include "Switch.H" #include "Switch.H"
#include "processorTopology.H" #include "processorTopology.H"
#include "labelPair.H" #include "labelPair.H"
#include "indirectPrimitivePatch.H"
#include "boundBox.H"
#include "IOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -88,7 +91,10 @@ namespace Foam ...@@ -88,7 +91,10 @@ namespace Foam
class globalMeshData; class globalMeshData;
Ostream& operator<<(Ostream&, const globalMeshData&); Ostream& operator<<(Ostream&, const globalMeshData&);
class globalIndex;
class polyMesh;
class mapDistribute;
template<class T> class EdgeMap;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class globalMeshData Declaration Class globalMeshData Declaration
...@@ -194,6 +200,39 @@ class globalMeshData ...@@ -194,6 +200,39 @@ class globalMeshData
mutable labelList* sharedEdgeAddrPtr_; 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 // Private Member Functions
//- Set up processor patch addressing //- Set up processor patch addressing
...@@ -202,8 +241,8 @@ class globalMeshData ...@@ -202,8 +241,8 @@ class globalMeshData
//- Helper function for shared edge addressing //- Helper function for shared edge addressing
static void countSharedEdges static void countSharedEdges
( (
const HashTable<labelList, edge, Hash<edge> >& procSharedEdges, const EdgeMap<labelList>&,
HashTable<label, edge, Hash<edge> >&, EdgeMap<label>&,
label& label&
); );
...@@ -217,6 +256,22 @@ class globalMeshData ...@@ -217,6 +256,22 @@ class globalMeshData
const vectorField& separationDist 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 //- Disallow default bitwise copy construct
globalMeshData(const globalMeshData&); globalMeshData(const globalMeshData&);
...@@ -388,6 +443,47 @@ public: ...@@ -388,6 +443,47 @@ public:
const labelList& sharedEdgeAddr() const; 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 // Edit
//- Update for moving points. //- Update for moving points.
......
...@@ -29,9 +29,8 @@ Description ...@@ -29,9 +29,8 @@ Description
Calculates points shared by more than two processor patches or cyclic Calculates points shared by more than two processor patches or cyclic
patches. patches.
Is used in globalMeshData. (this info is needed for point-edge Is used in globalMeshData. (this info is needed for point/edge
communication where you do all but these shared points with patch to communication where processor swaps are not enough to exchange data)
patch communication but need to do a reduce on these shared points)
Works purely topological and using local communication only. Works purely topological and using local communication only.
Needs: Needs:
...@@ -41,8 +40,8 @@ Description ...@@ -41,8 +40,8 @@ Description
- f[0] ordering on patch faces to be ok. - f[0] ordering on patch faces to be ok.
Works by constructing equivalence lists for all the points on processor Works by constructing equivalence lists for all the points on processor
patches. These list are procPointList and give processor and meshPoint patches. These list are in globalIndex numbering (so consecutively numbered
label on that processor. per processor)
E.g. E.g.
@verbatim @verbatim
((7 93)(4 731)(3 114)) ((7 93)(4 731)(3 114))
...@@ -85,6 +84,9 @@ Description ...@@ -85,6 +84,9 @@ Description
endloop until nothing changes. 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 SourceFiles
globalPoints.C globalPoints.C
...@@ -95,11 +97,11 @@ SourceFiles ...@@ -95,11 +97,11 @@ SourceFiles
#include "DynamicList.H" #include "DynamicList.H"
#include "Map.H" #include "Map.H"
#include "labelList.H"
#include "FixedList.H"
#include "primitivePatch.H" #include "primitivePatch.H"
#include "className.H" #include "className.H"
#include "edgeList.H" #include "edgeList.H"
#include "globalIndex.H"
#include "indirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -119,30 +121,29 @@ class globalPoints ...@@ -119,30 +121,29 @@ class globalPoints
{ {
// Private classes // Private classes
//- Define procPointList as holding a list of meshPoint/processor labels
typedef FixedList<label, 2> procPoint;
typedef List<procPoint> procPointList;
// Private data // Private data
//- Mesh reference //- Mesh reference
const polyMesh& mesh_; const polyMesh& mesh_;
//- Global numbering of points
globalIndex globalIndices_;
//- Sum of points on processor patches (unfiltered, point on 2 patches //- Sum of points on processor patches (unfiltered, point on 2 patches
// counts as 2) // counts as 2)
const label nPatchPoints_; const label nPatchPoints_;
//- All points on boundaries and their corresponding connected points //- All points on boundaries and their corresponding connected points
// on other processors. // 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_; Map<label> meshToProcPoint_;
//- Shared points used by this processor (= global point number) //- Shared points used by this processor (= global point number)
labelList sharedPointAddr_; labelList sharedPointAddr_;
//- My meshpoints corresponding to the shared points //- My mesh(or patch) points corresponding to the shared points
labelList sharedPointLabels_; labelList sharedPointLabels_;
//- Total number of shared points. //- Total number of shared points.
...@@ -155,56 +156,108 @@ class globalPoints ...@@ -155,56 +156,108 @@ class globalPoints
// information is collected. // information is collected.
static label countPatchPoints(const polyBoundaryMesh&); 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 //- Add information about patchPointI in relative indices to send
// buffers (patchFaces, indexInFace etc.) // buffers (patchFaces, indexInFace etc.)
static void addToSend static void addToSend
( (
const primitivePatch&, const primitivePatch&,
const label patchPointI, const label patchPointI,
const procPointList&, const labelList&,
DynamicList<label>& patchFaces, DynamicList<label>& patchFaces,
DynamicList<label>& indexInFace, DynamicList<label>& indexInFace,
DynamicList<procPointList>& allInfo DynamicList<labelList>& allInfo
); );
//- Merge info from neighbour into my data //- Merge info from neighbour into my data
static bool mergeInfo static bool mergeInfo
( (
const procPointList& nbrInfo, const labelList& nbrInfo,
procPointList& myInfo 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 //- 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: //- Initialize procPoints_ to my patch points. allPoints = true:
// seed with all patch points, = false: only boundaryPoints(). // 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 //- Send subset of procPoints to neighbours
void sendPatchPoints(const labelHashSet& changedPoints) const;