From 99fa12c059f3882c559bef3d9603aa2d2ff7f659 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 3 Feb 2011 12:55:05 +0000 Subject: [PATCH 1/5] ENH: added noParallel option to chemFoam (single cell cases only) --- applications/solvers/combustion/chemFoam/chemFoam.C | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/applications/solvers/combustion/chemFoam/chemFoam.C b/applications/solvers/combustion/chemFoam/chemFoam.C index 9a19930ee5..15f4a33747 100644 --- a/applications/solvers/combustion/chemFoam/chemFoam.C +++ b/applications/solvers/combustion/chemFoam/chemFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,6 +47,8 @@ Description int main(int argc, char *argv[]) { + argList::noParallel(); + #include "setRootCase.H" #include "createTime.H" #include "createSingleCellMesh.H" From ed6650ed8d7026acad8313304864e14848cc528b Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 3 Feb 2011 22:07:00 +0000 Subject: [PATCH 2/5] BUG: etc/cellModels : wrong edge numbering --- etc/cellModels | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/cellModels b/etc/cellModels index a90eaa94e7..68fdd9f42b 100644 --- a/etc/cellModels +++ b/etc/cellModels @@ -149,7 +149,7 @@ pyr (0 1) (1 2) (2 3) - (3 4) + (0 3) (0 4) (1 4) (2 4) From d54624b9013b45884817db17d626859beba02c4e Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 3 Feb 2011 22:08:56 +0000 Subject: [PATCH 3/5] BUG: globalMeshData,globalIndexAndTransform: work with <3 cyclics --- .../polyMesh/globalMeshData/globalMeshData.C | 9 +- .../polyMesh/globalMeshData/globalMeshData.H | 11 + .../globalMeshData/globalMeshDataTemplates.C | 53 +++ .../polyMesh/globalMeshData/globalPoints.C | 28 +- .../polyMesh/globalMeshData/globalPoints.H | 8 +- .../polyMesh/syncTools/syncToolsTemplates.C | 396 ++++-------------- .../globalIndexAndTransform.H | 26 +- .../globalIndexAndTransformI.H | 76 ++-- 8 files changed, 238 insertions(+), 369 deletions(-) diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C index aec5e8ffd3..aeb05000b7 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C @@ -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. diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.H b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.H index 08537ed3c9..94d0cf5715 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.H +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.H @@ -470,6 +470,17 @@ public: const bool isPosition ); + //- Helper: synchronise data without transforms + template + static void syncData + ( + List& 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. diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshDataTemplates.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshDataTemplates.C index 2a853e5970..93005abcac 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshDataTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshDataTemplates.C @@ -90,6 +90,59 @@ void Foam::globalMeshData::syncData } +template +void Foam::globalMeshData::syncData +( + List& 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 void Foam::globalMeshData::syncPointData ( diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.C index ce2b0cfc21..9a1954c507 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.C @@ -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::globalPoints::transformBits -( - const label transformIndex -) const -{ - label t = transformIndex; - - // Decode permutation as 3 integers - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Note: FixedList for speed reasons. - FixedList 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()) { diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.H b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.H index b4cad63052..8b4372a89a 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.H +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalPoints.H @@ -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 transformBits(const label transformIndex) const; - + //- Debug printing void printProcPoints ( const labelList& patchToMeshPoint, diff --git a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C index dc93a7dfeb..d135e2b73a 100644 --- a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C @@ -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 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::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 sharedPointValues(sharedPtAddr.size()); - - - // Fill my entries in the shared points - forAll(sharedPtLabels, i) - { - label meshPointI = sharedPtLabels[i]; - - typename Map::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 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 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 cppFld(UIndirectList(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 cppFld(gd.globalPointSlavesMap().constructSize()); + forAll(meshPoints, i) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - // Send - - forAll(patches, patchI) - { - if - ( - isA(patches[patchI]) - && patches[patchI].nPoints() > 0 - ) - { - const processorPolyPatch& procPatch = - refCast(patches[patchI]); - - List 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(patches[patchI]) - && patches[patchI].nPoints() > 0 - ) - { - const processorPolyPatch& procPatch = - refCast(patches[patchI]); - - List 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; - } - } - } + cppFld[i] = pointValues[meshPoints[i]]; } - // Do the cyclics. - forAll(patches, patchI) + globalMeshData::syncData + ( + cppFld, + gd.globalPointSlaves(), + gd.globalPointTransformedSlaves(), + gd.globalPointSlavesMap(), + cop + ); + + // Extract back to mesh + forAll(meshPoints, i) { - if (isA(patches[patchI])) - { - const cyclicPolyPatch& cycPatch = - refCast(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 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 cppFld(gd.globalEdgeSlavesMap().constructSize()); + forAll(meshEdges, i) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - // Send - - forAll(patches, patchI) - { - if - ( - isA(patches[patchI]) - && patches[patchI].nEdges() > 0 - ) - { - const processorPolyPatch& procPatch = - refCast(patches[patchI]); - - List 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(patches[patchI]) - && patches[patchI].nEdges() > 0 - ) - { - const processorPolyPatch& procPatch = - refCast(patches[patchI]); - - // Receive from neighbour. - List 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; - } - } - } + cppFld[i] = edgeValues[meshEdges[i]]; } - // Do the cyclics. - forAll(patches, patchI) + globalMeshData::syncData + ( + cppFld, + gd.globalEdgeSlaves(), + gd.globalEdgeTransformedSlaves(), + gd.globalEdgeSlavesMap(), + cop + ); + + // Extract back to mesh + forAll(meshEdges, i) { - if (isA(patches[patchI])) - { - const cyclicPolyPatch& cycPatch = - refCast(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 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]; } } diff --git a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.H b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.H index 556071d6ac..5b7d2fc238 100644 --- a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.H +++ b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.H @@ -138,11 +138,17 @@ private: bool checkBothSigns ) const; + //- Encode transform index. Hardcoded to 3 independent transforms max. + inline label encodeTransformIndex + ( + const FixedList& permutationIndices + ) const; + //- Decode transform index. Hardcoded to 3 independent transforms max. - inline static FixedList decodeTransformIndex + inline FixedList 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 diff --git a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H index 13d987bbaf..7de6eab86c 100644 --- a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H +++ b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H @@ -118,20 +118,56 @@ Foam::label Foam::globalIndexAndTransform::encodeTransformIndex } +Foam::label Foam::globalIndexAndTransform::encodeTransformIndex +( + const FixedList& 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::globalIndexAndTransform::decodeTransformIndex ( const label transformIndex -) +) const { - FixedList permutation; + FixedList permutation(0); label t = transformIndex; - permutation[0] = (t%3)-1; - t /= 3; - permutation[1] = (t%3)-1; - t /= 3; - permutation[2] = (t%3)-1; + 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 permutation0 = decodeTransformIndex(transformIndex0); FixedList 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 permutation0 = decodeTransformIndex(transformIndex0); FixedList 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 permutation0 = decodeTransformIndex(transformIndex0); FixedList 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); } From a6e8df4aa2bc9d5450fb90e1346d2e0af7d441fb Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 3 Feb 2011 22:20:32 +0000 Subject: [PATCH 4/5] ENH: Test-syncTools : remove warning about transformations --- applications/test/syncTools/Test-syncTools.C | 38 ++++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/applications/test/syncTools/Test-syncTools.C b/applications/test/syncTools/Test-syncTools.C index e7fa0ae0b0..094068e94a 100644 --- a/applications/test/syncTools/Test-syncTools.C +++ b/applications/test/syncTools/Test-syncTools.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -130,6 +130,7 @@ void testPackedList(const polyMesh& mesh, Random& rndGen) { FatalErrorIn("testPackedList()") << "point:" << i + << " at:" << mesh.points()[i] << " minlabel:" << pointValues[i] << " minbits:" << bits.get(i) << " maxLabel:" << maxPointValues[i] @@ -186,6 +187,10 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) { Info<< nl << "Testing Map synchronisation." << endl; + WarningIn("testSparseData()") + << "Position test of sparse data only correct for cases without cyclics" + << " with shared points." << endl; + primitivePatch allBoundary ( SubList @@ -204,7 +209,7 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) { // Create some data. Use slightly perturbed positions. - Map sparseData; + Map sparseData; pointField fullData(mesh.nPoints(), point::max); forAll(localPoints, i) @@ -223,14 +228,14 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) ( mesh, sparseData, - minEqOp() + minMagSqrEqOp() // true // apply separation ); syncTools::syncPointList ( mesh, fullData, - minEqOp(), + minMagSqrEqOp(), point::max // true // apply separation ); @@ -257,7 +262,7 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) } // 2. Does sparseData contain more? - forAllConstIter(Map, sparseData, iter) + forAllConstIter(Map, sparseData, iter) { const point& sparsePt = iter(); label meshPointI = iter.key(); @@ -374,16 +379,12 @@ void testPointSync(const polyMesh& mesh, Random& rndGen) // Test position. { - WarningIn("testPointSync()") - << "Position test only correct for cases without cyclics" - << " with shared points." << endl; - pointField syncedPoints(mesh.points()); - syncTools::syncPointList + syncTools::syncPointPositions ( mesh, syncedPoints, - minEqOp(), + minMagSqrEqOp(), point::max ); @@ -450,20 +451,16 @@ void testEdgeSync(const polyMesh& mesh, Random& rndGen) // Test position. { - WarningIn("testEdgeSync()") - << "Position test only correct for cases without cyclics" - << " with shared edges." << endl; - pointField syncedMids(edges.size()); forAll(syncedMids, edgeI) { syncedMids[edgeI] = edges[edgeI].centre(mesh.points()); } - syncTools::syncEdgeList + syncTools::syncEdgePositions ( mesh, syncedMids, - minEqOp(), + minMagSqrEqOp(), point::max ); @@ -509,10 +506,11 @@ void testEdgeSync(const polyMesh& mesh, Random& rndGen) { if (nMasters[edgeI] != 1) { + const edge& e = edges[edgeI]; //FatalErrorIn("testEdgeSync()") WarningIn("testEdgeSync()") << "Edge " << edgeI - << " midpoint " << edges[edgeI].centre(mesh.points()) + << " at:" << mesh.points()[e[0]] << mesh.points()[e[1]] << " has " << nMasters[edgeI] << " masters." //<< exit(FatalError); @@ -532,11 +530,11 @@ void testFaceSync(const polyMesh& mesh, Random& rndGen) { pointField syncedFc(mesh.faceCentres()); - syncTools::syncFaceList + syncTools::syncFacePositions ( mesh, syncedFc, - maxEqOp() + maxMagSqrEqOp() ); forAll(syncedFc, faceI) From 8bc92b876137d9cbb44e42b286810f37c71541be Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 7 Feb 2011 12:59:14 +0000 Subject: [PATCH 5/5] ENH: Added mapMethod, [source|target]Region options to mapFields --- .../mapFields/MapConsistentVolFields.H | 18 +- .../preProcessing/mapFields/MapVolFields.H | 12 +- .../preProcessing/mapFields/mapFields.C | 164 ++++++++++++++---- 3 files changed, 138 insertions(+), 56 deletions(-) diff --git a/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H b/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H index 62f30fb90a..5d36e45fce 100644 --- a/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H +++ b/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,7 +39,8 @@ template void MapConsistentVolFields ( const IOobjectList& objects, - const meshToMesh& meshToMeshInterp + const meshToMesh& meshToMeshInterp, + const meshToMesh::order& mapOrder ) { const fvMesh& meshSource = meshToMeshInterp.fromMesh(); @@ -83,12 +84,7 @@ void MapConsistentVolFields ); // Interpolate field - meshToMeshInterp.interpolate - ( - fieldTarget, - fieldSource, - meshToMesh::INTERPOLATE - ); + meshToMeshInterp.interpolate(fieldTarget, fieldSource, mapOrder); // Write field fieldTarget.write(); @@ -101,11 +97,7 @@ void MapConsistentVolFields GeometricField fieldTarget ( fieldTargetIOobject, - meshToMeshInterp.interpolate - ( - fieldSource, - meshToMesh::INTERPOLATE - ) + meshToMeshInterp.interpolate(fieldSource, mapOrder) ); // Write field diff --git a/applications/utilities/preProcessing/mapFields/MapVolFields.H b/applications/utilities/preProcessing/mapFields/MapVolFields.H index 226211552e..2d31297967 100644 --- a/applications/utilities/preProcessing/mapFields/MapVolFields.H +++ b/applications/utilities/preProcessing/mapFields/MapVolFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,7 +39,8 @@ template void MapVolFields ( const IOobjectList& objects, - const meshToMesh& meshToMeshInterp + const meshToMesh& meshToMeshInterp, + const meshToMesh::order& mapOrder ) { const fvMesh& meshSource = meshToMeshInterp.fromMesh(); @@ -83,12 +84,7 @@ void MapVolFields ); // Interpolate field - meshToMeshInterp.interpolate - ( - fieldTarget, - fieldSource, - meshToMesh::INTERPOLATE - ); + meshToMeshInterp.interpolate(fieldTarget, fieldSource, mapOrder); // Write field fieldTarget.write(); diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 883418619a..9f7fd25a17 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,7 +45,8 @@ Description void mapConsistentMesh ( const fvMesh& meshSource, - const fvMesh& meshTarget + const fvMesh& meshTarget, + const meshToMesh::order& mapOrder ) { // Create the interpolation scheme @@ -61,11 +62,16 @@ void mapConsistentMesh // Map volFields // ~~~~~~~~~~~~~ - MapConsistentVolFields(objects, meshToMeshInterp); - MapConsistentVolFields(objects, meshToMeshInterp); - MapConsistentVolFields(objects, meshToMeshInterp); - MapConsistentVolFields(objects, meshToMeshInterp); - MapConsistentVolFields(objects, meshToMeshInterp); + MapConsistentVolFields(objects, meshToMeshInterp, mapOrder); + MapConsistentVolFields(objects, meshToMeshInterp, mapOrder); + MapConsistentVolFields + ( + objects, + meshToMeshInterp, + mapOrder + ); + MapConsistentVolFields(objects, meshToMeshInterp, mapOrder); + MapConsistentVolFields(objects, meshToMeshInterp, mapOrder); } { @@ -98,7 +104,8 @@ void mapSubMesh const fvMesh& meshSource, const fvMesh& meshTarget, const HashTable& patchMap, - const wordList& cuttingPatches + const wordList& cuttingPatches, + const meshToMesh::order& mapOrder ) { // Create the interpolation scheme @@ -120,11 +127,11 @@ void mapSubMesh // Map volFields // ~~~~~~~~~~~~~ - MapVolFields(objects, meshToMeshInterp); - MapVolFields(objects, meshToMeshInterp); - MapVolFields(objects, meshToMeshInterp); - MapVolFields(objects, meshToMeshInterp); - MapVolFields(objects, meshToMeshInterp); + MapVolFields(objects, meshToMeshInterp, mapOrder); + MapVolFields(objects, meshToMeshInterp, mapOrder); + MapVolFields(objects, meshToMeshInterp, mapOrder); + MapVolFields(objects, meshToMeshInterp, mapOrder); + MapVolFields(objects, meshToMeshInterp, mapOrder); } { @@ -155,7 +162,8 @@ void mapSubMesh void mapConsistentSubMesh ( const fvMesh& meshSource, - const fvMesh& meshTarget + const fvMesh& meshTarget, + const meshToMesh::order& mapOrder ) { HashTable patchMap; @@ -181,7 +189,14 @@ void mapConsistentSubMesh } } - mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatchTable.toc()); + mapSubMesh + ( + meshSource, + meshTarget, + patchMap, + cuttingPatchTable.toc(), + mapOrder + ); } @@ -240,6 +255,18 @@ int main(int argc, char *argv[]) "scalar", "specify the source time" ); + argList::addOption + ( + "sourceRegion", + "word", + "specify the source region" + ); + argList::addOption + ( + "targetRegion", + "word", + "specify the target region" + ); argList::addBoolOption ( "parallelSource", @@ -255,12 +282,18 @@ int main(int argc, char *argv[]) "consistent", "source and target geometry and boundary conditions identical" ); + argList::addOption + ( + "mapMethod", + "word", + "specify the mapping method" + ); argList args(argc, argv); if (!args.check()) { - FatalError.exit(); + FatalError.exit(); } fileName rootDirTarget(args.rootPath()); @@ -270,12 +303,52 @@ int main(int argc, char *argv[]) const fileName rootDirSource = casePath.path(); const fileName caseDirSource = casePath.name(); - Info<< "Source: " << rootDirSource << " " << caseDirSource << nl - << "Target: " << rootDirTarget << " " << caseDirTarget << endl; + Info<< "Source: " << rootDirSource << " " << caseDirSource << endl; + word sourceRegion = fvMesh::defaultRegion; + if (args.optionFound("sourceRegion")) + { + sourceRegion = args["sourceRegion"]; + Info<< "Source region: " << sourceRegion << endl; + } + + Info<< "Target: " << rootDirTarget << " " << caseDirTarget << endl; + word targetRegion = fvMesh::defaultRegion; + if (args.optionFound("targetRegion")) + { + targetRegion = args["targetRegion"]; + Info<< "Target region: " << targetRegion << endl; + } const bool parallelSource = args.optionFound("parallelSource"); const bool parallelTarget = args.optionFound("parallelTarget"); - const bool consistent = args.optionFound("consistent"); + const bool consistent = args.optionFound("consistent"); + + meshToMesh::order mapOrder = meshToMesh::INTERPOLATE; + if (args.optionFound("mapMethod")) + { + const word mapMethod(args["mapMethod"]); + if (mapMethod == "mapNearest") + { + mapOrder = meshToMesh::MAP; + } + else if (mapMethod == "interpolate") + { + mapOrder = meshToMesh::INTERPOLATE; + } + else if (mapMethod == "cellPointInterpolate") + { + mapOrder = meshToMesh::CELL_POINT_INTERPOLATE; + } + else + { + FatalErrorIn(args.executable()) + << "Unknown mapMethod " << mapMethod << ". Valid options are: " + << "mapNearest, interpolate and cellPointInterpolate" + << exit(FatalError); + } + + Info<< "Mapping method: " << mapMethod << endl; + } #include "createTimes.H" @@ -323,7 +396,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + targetRegion, runTimeTarget.timeName(), runTimeTarget ) @@ -348,7 +421,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + sourceRegion, runTimeSource.timeName(), runTimeSource ) @@ -358,11 +431,18 @@ int main(int argc, char *argv[]) if (consistent) { - mapConsistentSubMesh(meshSource, meshTarget); + mapConsistentSubMesh(meshSource, meshTarget, mapOrder); } else { - mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatches); + mapSubMesh + ( + meshSource, + meshTarget, + patchMap, + cuttingPatches, + mapOrder + ); } } } @@ -390,7 +470,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + sourceRegion, runTimeSource.timeName(), runTimeSource ) @@ -413,7 +493,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + targetRegion, runTimeTarget.timeName(), runTimeTarget ) @@ -423,7 +503,7 @@ int main(int argc, char *argv[]) if (consistent) { - mapConsistentSubMesh(meshSource, meshTarget); + mapConsistentSubMesh(meshSource, meshTarget, mapOrder); } else { @@ -432,7 +512,8 @@ int main(int argc, char *argv[]) meshSource, meshTarget, patchMap, - addProcessorPatches(meshTarget, cuttingPatches) + addProcessorPatches(meshTarget, cuttingPatches), + mapOrder ); } } @@ -494,7 +575,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + sourceRegion, runTimeSource.timeName(), runTimeSource ) @@ -529,7 +610,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + targetRegion, runTimeTarget.timeName(), runTimeTarget ) @@ -544,7 +625,12 @@ int main(int argc, char *argv[]) { if (consistent) { - mapConsistentSubMesh(meshSource, meshTarget); + mapConsistentSubMesh + ( + meshSource, + meshTarget, + mapOrder + ); } else { @@ -553,7 +639,8 @@ int main(int argc, char *argv[]) meshSource, meshTarget, patchMap, - addProcessorPatches(meshTarget, cuttingPatches) + addProcessorPatches(meshTarget, cuttingPatches), + mapOrder ); } } @@ -571,7 +658,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + sourceRegion, runTimeSource.timeName(), runTimeSource ) @@ -581,7 +668,7 @@ int main(int argc, char *argv[]) ( IOobject ( - fvMesh::defaultRegion, + targetRegion, runTimeTarget.timeName(), runTimeTarget ) @@ -592,11 +679,18 @@ int main(int argc, char *argv[]) if (consistent) { - mapConsistentMesh(meshSource, meshTarget); + mapConsistentMesh(meshSource, meshTarget, mapOrder); } else { - mapSubMesh(meshSource, meshTarget, patchMap, cuttingPatches); + mapSubMesh + ( + meshSource, + meshTarget, + patchMap, + cuttingPatches, + mapOrder + ); } }