BUG: globalMeshData,globalIndexAndTransform: work with <3 cyclics

This commit is contained in:
mattijs
2011-02-03 22:08:56 +00:00
parent ed6650ed8d
commit d54624b901
8 changed files with 238 additions and 369 deletions

View File

@ -841,7 +841,7 @@ Foam::label Foam::globalMeshData::findTransform
<< abort(FatalError);
}
return globalIndexAndTransform::subtractTransformIndex
return globalTransforms().subtractTransformIndex
(
remoteTransformI,
localTransformI
@ -859,7 +859,6 @@ void Foam::globalMeshData::calcGlobalEdgeSlaves() const
const edgeList& edges = coupledPatch().edges();
const globalIndex& globalEdgeNumbers = globalEdgeNumbering();
const pointField& localPoints = coupledPatch().localPoints();
// The whole problem with deducting edge-connectivity from
@ -920,7 +919,11 @@ void Foam::globalMeshData::calcGlobalEdgeSlaves() const
{
forAll(pEdges1, j)
{
if (pEdges0[i] == pEdges1[j] && pEdges0[i] != edgeI)
if
(
pEdges0[i] == pEdges1[j]
&& pEdges0[i] != globalEdgeNumbers.toGlobal(edgeI)
)
{
// Found a shared edge. Now check if the endpoints
// go through the same transformation.

View File

@ -470,6 +470,17 @@ public:
const bool isPosition
);
//- Helper: synchronise data without transforms
template<class Type, class CombineOp>
static void syncData
(
List<Type>& pointData,
const labelListList& slaves,
const labelListList& transformedSlaves,
const mapDistribute& slavesMap,
const CombineOp& cop
);
// Coupled point to coupled points. Coupled points are
// points on any coupled patch.

View File

@ -90,6 +90,59 @@ void Foam::globalMeshData::syncData
}
template<class Type, class CombineOp>
void Foam::globalMeshData::syncData
(
List<Type>& elems,
const labelListList& slaves,
const labelListList& transformedSlaves,
const mapDistribute& slavesMap,
const CombineOp& cop
)
{
// Pull slave data onto master
slavesMap.distribute(elems);
// Combine master data with slave data
forAll(slaves, i)
{
Type& elem = elems[i];
const labelList& slavePoints = slaves[i];
const labelList& transformSlavePoints = transformedSlaves[i];
if (slavePoints.size()+transformSlavePoints.size() > 0)
{
// Combine master with untransformed slave data
forAll(slavePoints, j)
{
cop(elem, elems[slavePoints[j]]);
}
// Combine master with transformed slave data
forAll(transformSlavePoints, j)
{
cop(elem, elems[transformSlavePoints[j]]);
}
// Copy result back to slave slots
forAll(slavePoints, j)
{
elems[slavePoints[j]] = elem;
}
forAll(transformSlavePoints, j)
{
elems[transformSlavePoints[j]] = elem;
}
}
}
// Push slave-slot data back to slaves
slavesMap.reverseDistribute(elems.size(), elems);
}
template<class Type, class CombineOp>
void Foam::globalMeshData::syncPointData
(

View File

@ -125,7 +125,7 @@ bool Foam::globalPoints::mergeInfo
const labelPairList& nbrInfo,
const label localPointI,
labelPairList& myInfo
)
) const
{
bool anyChanged = false;
@ -167,7 +167,7 @@ bool Foam::globalPoints::mergeInfo
);
// Combine mine and nbr transform
label t = globalIndexAndTransform::mergeTransformIndex
label t = globalTransforms_.mergeTransformIndex
(
nbrTransform,
myTransform
@ -315,27 +315,6 @@ bool Foam::globalPoints::storeInitialInfo
}
Foam::FixedList<Foam::label, 3> Foam::globalPoints::transformBits
(
const label transformIndex
) const
{
label t = transformIndex;
// Decode permutation as 3 integers
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Note: FixedList for speed reasons.
FixedList<label, 3> permutation;
permutation[0] = (t%3)-1;
t /= 3;
permutation[1] = (t%3)-1;
t /= 3;
permutation[2] = (t%3)-1;
return permutation;
}
void Foam::globalPoints::printProcPoints
(
const labelList& patchToMeshPoint,
@ -352,7 +331,8 @@ void Foam::globalPoints::printProcPoints
Pout<< " localpoint:";
Pout<< index;
Pout<< " through transform:"
<< trafoI << " bits:" << transformBits(trafoI);
<< trafoI << " bits:"
<< globalTransforms_.decodeTransformIndex(trafoI);
if (procI == Pstream::myProcNo())
{

View File

@ -162,12 +162,12 @@ class globalPoints
) const;
//- Merge info from neighbour into my data
static bool mergeInfo
bool mergeInfo
(
const labelPairList& nbrInfo,
const label localPointI,
labelPairList& myInfo
);
) const;
//- From mesh point to 'local point'. Is the mesh point itself
// if meshToPatchPoint is empty.
@ -198,9 +198,7 @@ class globalPoints
const label localPointI
);
//- Get the signs for the individual transforms
FixedList<label, 3> transformBits(const label transformIndex) const;
//- Debug printing
void printProcPoints
(
const labelList& patchToMeshPoint,

View File

@ -91,6 +91,43 @@ void Foam::syncTools::syncPointMap
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Synchronize multiple shared points.
const globalMeshData& pd = mesh.globalData();
// Values on shared points. Keyed on global shared index.
Map<T> sharedPointValues(0);
if (pd.nGlobalPoints() > 0)
{
// meshPoint per local index
const labelList& sharedPtLabels = pd.sharedPointLabels();
// global shared index per local index
const labelList& sharedPtAddr = pd.sharedPointAddr();
sharedPointValues.resize(sharedPtAddr.size());
// Fill my entries in the shared points
forAll(sharedPtLabels, i)
{
label meshPointI = sharedPtLabels[i];
typename Map<T>::const_iterator fnd =
pointValues.find(meshPointI);
if (fnd != pointValues.end())
{
combine
(
sharedPointValues,
cop,
sharedPtAddr[i], // index
fnd() // value
);
}
}
}
if (Pstream::parRun())
{
PstreamBuffers pBufs(Pstream::nonBlocking);
@ -254,8 +291,6 @@ void Foam::syncTools::syncPointMap
}
// Synchronize multiple shared points.
const globalMeshData& pd = mesh.globalData();
if (pd.nGlobalPoints() > 0)
{
// meshPoint per local index
@ -263,30 +298,6 @@ void Foam::syncTools::syncPointMap
// global shared index per local index
const labelList& sharedPtAddr = pd.sharedPointAddr();
// Values on shared points. Keyed on global shared index.
Map<T> sharedPointValues(sharedPtAddr.size());
// Fill my entries in the shared points
forAll(sharedPtLabels, i)
{
label meshPointI = sharedPtLabels[i];
typename Map<T>::const_iterator fnd =
pointValues.find(meshPointI);
if (fnd != pointValues.end())
{
combine
(
sharedPointValues,
cop,
sharedPtAddr[i], // index
fnd() // value
);
}
}
// Reduce on master.
if (Pstream::parRun())
@ -367,13 +378,7 @@ void Foam::syncTools::syncPointMap
if (sharedFnd != sharedPointValues.end())
{
combine
(
pointValues,
cop,
iter(), // index
sharedFnd() // value
);
pointValues.set(iter(), sharedFnd());
}
}
}
@ -779,6 +784,23 @@ void Foam::syncTools::syncEdgeMap
//
// const polyBoundaryMesh& patches = mesh.boundaryMesh();
//
// // Synchronize multiple shared points.
// const globalMeshData& pd = mesh.globalData();
//
// // Values on shared points.
// Field<T> sharedPts(0);
// if (pd.nGlobalPoints() > 0)
// {
// // Values on shared points.
// sharedPts.setSize(pd.nGlobalPoints(), nullValue);
//
// forAll(pd.sharedPointLabels(), i)
// {
// label meshPointI = pd.sharedPointLabels()[i];
// // Fill my entries in the shared points
// sharedPts[pd.sharedPointAddr()[i]] = pointValues[meshPointI];
// }
// }
//
// if (Pstream::parRun())
// {
@ -899,16 +921,6 @@ void Foam::syncTools::syncEdgeMap
//
// if (pd.nGlobalPoints() > 0)
// {
// // Values on shared points.
// Field<T> sharedPts(pd.nGlobalPoints(), nullValue);
//
// forAll(pd.sharedPointLabels(), i)
// {
// label meshPointI = pd.sharedPointLabels()[i];
// // Fill my entries in the shared points
// sharedPts[pd.sharedPointAddr()[i]] = pointValues[meshPointI];
// }
//
// // Combine on master.
// Pstream::listCombineGather(sharedPts, cop);
// Pstream::listCombineScatter(sharedPts);
@ -1208,6 +1220,8 @@ void Foam::syncTools::syncEdgePositions
const globalMeshData& gd = mesh.globalData();
const labelList& meshEdges = gd.coupledPatchMeshEdges();
const globalIndexAndTransform& git = gd.globalTransforms();
const mapDistribute& map = gd.globalEdgeSlavesMap();
List<point> cppFld(UIndirectList<point>(edgeValues, meshEdges));
@ -1216,8 +1230,8 @@ void Foam::syncTools::syncEdgePositions
cppFld,
gd.globalEdgeSlaves(),
gd.globalEdgeTransformedSlaves(),
gd.globalEdgeSlavesMap(),
gd.globalTransforms(),
map,
git,
cop,
true //position?
);
@ -1505,140 +1519,28 @@ void Foam::syncTools::syncPointList
<< mesh.nPoints() << abort(FatalError);
}
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const globalMeshData& gd = mesh.globalData();
const labelList& meshPoints = gd.coupledPatch().meshPoints();
if (Pstream::parRun())
List<unsigned int> cppFld(gd.globalPointSlavesMap().constructSize());
forAll(meshPoints, i)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
cppFld[i] = pointValues[meshPoints[i]];
}
// Send
forAll(patches, patchI)
{
if
globalMeshData::syncData
(
isA<processorPolyPatch>(patches[patchI])
&& patches[patchI].nPoints() > 0
)
cppFld,
gd.globalPointSlaves(),
gd.globalPointTransformedSlaves(),
gd.globalPointSlavesMap(),
cop
);
// Extract back to mesh
forAll(meshPoints, i)
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(patches[patchI]);
List<unsigned int> patchInfo(procPatch.nPoints());
const labelList& meshPts = procPatch.meshPoints();
const labelList& nbrPts = procPatch.neighbPoints();
forAll(nbrPts, pointI)
{
label nbrPointI = nbrPts[pointI];
patchInfo[nbrPointI] = pointValues[meshPts[pointI]];
}
UOPstream toNbr(procPatch.neighbProcNo(), pBufs);
toNbr << patchInfo;
}
}
pBufs.finishedSends();
// Receive and combine.
forAll(patches, patchI)
{
if
(
isA<processorPolyPatch>(patches[patchI])
&& patches[patchI].nPoints() > 0
)
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(patches[patchI]);
List<unsigned int> nbrPatchInfo(procPatch.nPoints());
{
// We do not know the number of points on the other side
// so cannot use Pstream::read.
UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
fromNbr >> nbrPatchInfo;
}
const labelList& meshPts = procPatch.meshPoints();
forAll(meshPts, pointI)
{
label meshPointI = meshPts[pointI];
unsigned int pointVal = pointValues[meshPointI];
cop(pointVal, nbrPatchInfo[pointI]);
pointValues[meshPointI] = pointVal;
}
}
}
}
// Do the cyclics.
forAll(patches, patchI)
{
if (isA<cyclicPolyPatch>(patches[patchI]))
{
const cyclicPolyPatch& cycPatch =
refCast<const cyclicPolyPatch>(patches[patchI]);
if (cycPatch.owner())
{
// Owner does all.
const edgeList& coupledPoints = cycPatch.coupledPoints();
const labelList& meshPts = cycPatch.meshPoints();
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
const labelList& nbrMeshPts = nbrPatch.meshPoints();
forAll(coupledPoints, i)
{
const edge& e = coupledPoints[i];
label meshPoint0 = meshPts[e[0]];
label meshPoint1 = nbrMeshPts[e[1]];
unsigned int val0 = pointValues[meshPoint0];
unsigned int val1 = pointValues[meshPoint1];
unsigned int t = val0;
cop(val0, val1);
pointValues[meshPoint0] = val0;
cop(val1, t);
pointValues[meshPoint1] = val1;
}
}
}
}
// Synchronize multiple shared points.
const globalMeshData& pd = mesh.globalData();
if (pd.nGlobalPoints() > 0)
{
// Values on shared points. Use unpacked storage for ease!
List<unsigned int> sharedPts(pd.nGlobalPoints(), nullValue);
forAll(pd.sharedPointLabels(), i)
{
label meshPointI = pd.sharedPointLabels()[i];
// Fill my entries in the shared points
sharedPts[pd.sharedPointAddr()[i]] = pointValues[meshPointI];
}
// Combine on master.
Pstream::listCombineGather(sharedPts, cop);
Pstream::listCombineScatter(sharedPts);
// Now we will all have the same information. Merge it back with
// my local information.
forAll(pd.sharedPointLabels(), i)
{
label meshPointI = pd.sharedPointLabels()[i];
pointValues[meshPointI] = sharedPts[pd.sharedPointAddr()[i]];
}
pointValues[meshPoints[i]] = cppFld[i];
}
}
@ -1664,140 +1566,28 @@ void Foam::syncTools::syncEdgeList
<< mesh.nEdges() << abort(FatalError);
}
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const globalMeshData& gd = mesh.globalData();
const labelList& meshEdges = gd.coupledPatchMeshEdges();
if (Pstream::parRun())
List<unsigned int> cppFld(gd.globalEdgeSlavesMap().constructSize());
forAll(meshEdges, i)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
cppFld[i] = edgeValues[meshEdges[i]];
}
// Send
forAll(patches, patchI)
{
if
globalMeshData::syncData
(
isA<processorPolyPatch>(patches[patchI])
&& patches[patchI].nEdges() > 0
)
cppFld,
gd.globalEdgeSlaves(),
gd.globalEdgeTransformedSlaves(),
gd.globalEdgeSlavesMap(),
cop
);
// Extract back to mesh
forAll(meshEdges, i)
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(patches[patchI]);
List<unsigned int> patchInfo(procPatch.nEdges());
const labelList& meshEdges = procPatch.meshEdges();
const labelList& neighbEdges = procPatch.neighbEdges();
forAll(neighbEdges, edgeI)
{
label nbrEdgeI = neighbEdges[edgeI];
patchInfo[nbrEdgeI] = edgeValues[meshEdges[edgeI]];
}
UOPstream toNbr(procPatch.neighbProcNo(), pBufs);
toNbr << patchInfo;
}
}
pBufs.finishedSends();
// Receive and combine.
forAll(patches, patchI)
{
if
(
isA<processorPolyPatch>(patches[patchI])
&& patches[patchI].nEdges() > 0
)
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(patches[patchI]);
// Receive from neighbour.
List<unsigned int> nbrPatchInfo(procPatch.nEdges());
{
UIPstream fromNeighb(procPatch.neighbProcNo(), pBufs);
fromNeighb >> nbrPatchInfo;
}
const labelList& meshEdges = procPatch.meshEdges();
forAll(meshEdges, edgeI)
{
unsigned int patchVal = nbrPatchInfo[edgeI];
label meshEdgeI = meshEdges[edgeI];
unsigned int edgeVal = edgeValues[meshEdgeI];
cop(edgeVal, patchVal);
edgeValues[meshEdgeI] = edgeVal;
}
}
}
}
// Do the cyclics.
forAll(patches, patchI)
{
if (isA<cyclicPolyPatch>(patches[patchI]))
{
const cyclicPolyPatch& cycPatch =
refCast<const cyclicPolyPatch>(patches[patchI]);
if (cycPatch.owner())
{
// Owner does all.
const edgeList& coupledEdges = cycPatch.coupledEdges();
const labelList& meshEdges = cycPatch.meshEdges();
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
const labelList& nbrMeshEdges = nbrPatch.meshEdges();
forAll(coupledEdges, i)
{
const edge& e = coupledEdges[i];
label edge0 = meshEdges[e[0]];
label edge1 = nbrMeshEdges[e[1]];
unsigned int val0 = edgeValues[edge0];
unsigned int t = val0;
unsigned int val1 = edgeValues[edge1];
cop(t, val1);
edgeValues[edge0] = t;
cop(val1, val0);
edgeValues[edge1] = val1;
}
}
}
}
// Synchronize multiple shared edges.
const globalMeshData& pd = mesh.globalData();
if (pd.nGlobalEdges() > 0)
{
// Values on shared edges. Use unpacked storage for ease!
List<unsigned int> sharedPts(pd.nGlobalEdges(), nullValue);
forAll(pd.sharedEdgeLabels(), i)
{
label meshEdgeI = pd.sharedEdgeLabels()[i];
// Fill my entries in the shared edges
sharedPts[pd.sharedEdgeAddr()[i]] = edgeValues[meshEdgeI];
}
// Combine on master.
Pstream::listCombineGather(sharedPts, cop);
Pstream::listCombineScatter(sharedPts);
// Now we will all have the same information. Merge it back with
// my local information.
forAll(pd.sharedEdgeLabels(), i)
{
label meshEdgeI = pd.sharedEdgeLabels()[i];
edgeValues[meshEdgeI] = sharedPts[pd.sharedEdgeAddr()[i]];
}
edgeValues[meshEdges[i]] = cppFld[i];
}
}

View File

@ -138,11 +138,17 @@ private:
bool checkBothSigns
) const;
//- Encode transform index. Hardcoded to 3 independent transforms max.
inline label encodeTransformIndex
(
const FixedList<Foam::label, 3>& permutationIndices
) const;
//- Decode transform index. Hardcoded to 3 independent transforms max.
inline static FixedList<label, 3> decodeTransformIndex
inline FixedList<label, 3> decodeTransformIndex
(
const label transformIndex
);
) const;
//- Disallow default bitwise copy construct
globalIndexAndTransform(const globalIndexAndTransform&);
@ -153,6 +159,10 @@ private:
public:
//- Declare friendship with the entry class for IO
friend class globalPoints;
// Constructors
//- Construct from components
@ -184,25 +194,25 @@ public:
) const;
//- Combine two transformIndices
static inline label mergeTransformIndex
inline label mergeTransformIndex
(
const label transformIndex0,
const label transformIndex1
);
) const;
//- Combine two transformIndices
static inline label minimumTransformIndex
inline label minimumTransformIndex
(
const label transformIndex0,
const label transformIndex1
);
) const;
//- Subtract two transformIndices
static inline label subtractTransformIndex
inline label subtractTransformIndex
(
const label transformIndex0,
const label transformIndex1
);
) const;
//- Encode index and bare index as components on own processor
inline static labelPair encode

View File

@ -118,20 +118,56 @@ Foam::label Foam::globalIndexAndTransform::encodeTransformIndex
}
Foam::label Foam::globalIndexAndTransform::encodeTransformIndex
(
const FixedList<Foam::label, 3>& permutation
) const
{
if (nIndependentTransforms() == 0)
{
return 0;
}
if (nIndependentTransforms() == 1)
{
return permutation[0]+1;
}
else if (nIndependentTransforms() == 2)
{
return (permutation[1]+1)*3 + (permutation[0]+1);
}
else
{
return
(permutation[2]+1)*9
+ (permutation[1]+1)*3
+ (permutation[0]+1);
}
}
Foam::FixedList<Foam::label, 3>
Foam::globalIndexAndTransform::decodeTransformIndex
(
const label transformIndex
)
) const
{
FixedList<label, 3> permutation;
FixedList<label, 3> permutation(0);
label t = transformIndex;
if (nIndependentTransforms() > 0)
{
permutation[0] = (t%3)-1;
if (nIndependentTransforms() > 1)
{
t /= 3;
permutation[1] = (t%3)-1;
if (nIndependentTransforms() > 2)
{
t /= 3;
permutation[2] = (t%3)-1;
}
}
}
# ifdef FULLDEBUG
t /= 3;
@ -222,10 +258,7 @@ Foam::label Foam::globalIndexAndTransform::addToTransformIndex
// Re-encode permutation
// ~~~~~~~~~~~~~~~~~~~~~
return
(permutation[2]+1)*9
+ (permutation[1]+1)*3
+ (permutation[0]+1);
return encodeTransformIndex(permutation);
}
else
{
@ -238,7 +271,7 @@ Foam::label Foam::globalIndexAndTransform::mergeTransformIndex
(
const label transformIndex0,
const label transformIndex1
)
) const
{
FixedList<label, 3> permutation0 = decodeTransformIndex(transformIndex0);
FixedList<label, 3> permutation1 = decodeTransformIndex(transformIndex1);
@ -269,10 +302,7 @@ Foam::label Foam::globalIndexAndTransform::mergeTransformIndex
<< exit(FatalError);
}
}
return
(permutation0[2]+1)*9
+ (permutation0[1]+1)*3
+ (permutation0[0]+1);
return encodeTransformIndex(permutation0);
}
@ -280,7 +310,7 @@ Foam::label Foam::globalIndexAndTransform::minimumTransformIndex
(
const label transformIndex0,
const label transformIndex1
)
) const
{
FixedList<label, 3> permutation0 = decodeTransformIndex(transformIndex0);
FixedList<label, 3> permutation1 = decodeTransformIndex(transformIndex1);
@ -315,10 +345,7 @@ Foam::label Foam::globalIndexAndTransform::minimumTransformIndex
<< exit(FatalError);
}
}
return
(permutation0[2]+1)*9
+ (permutation0[1]+1)*3
+ (permutation0[0]+1);
return encodeTransformIndex(permutation0);
}
@ -326,7 +353,7 @@ Foam::label Foam::globalIndexAndTransform::subtractTransformIndex
(
const label transformIndex0,
const label transformIndex1
)
) const
{
FixedList<label, 3> permutation0 = decodeTransformIndex(transformIndex0);
FixedList<label, 3> permutation1 = decodeTransformIndex(transformIndex1);
@ -336,10 +363,7 @@ Foam::label Foam::globalIndexAndTransform::subtractTransformIndex
permutation0[i] -= permutation1[i];
}
return
(permutation0[2]+1)*9
+ (permutation0[1]+1)*3
+ (permutation0[0]+1);
return encodeTransformIndex(permutation0);
}