diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 9aee1a35bf..6e52395a48 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -47,6 +47,10 @@ x 5; varName x; +//Indirection for keys +key inlet_9; + + boundaryField { Default_Boundary_Region @@ -63,6 +67,7 @@ boundaryField inlet_6 { $.inactive } // Test scoping inlet_7 { ${inactive}} // Test variable expansion inlet_8 { $inactive } + ${key} { $inactive } #include "testDictInc" diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index 4e5b20e4ab..f448faa40c 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -402,9 +402,10 @@ addLayersControls nLayerIter 50; // Max number of iterations after which relaxed meshQuality controls - // get used. Up to nRelaxIter it uses the settings in + // get used. Up to nRelaxedIter it uses the settings in // meshQualityControls, - // after nRelaxIter it uses the values in meshQualityControls::relaxed. + // after nRelaxedIter it uses the values in + // meshQualityControls::relaxed. nRelaxedIter 20; // Additional reporting: if there are just a few faces where there diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C index e30a1e69cd..ce4fa0073a 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomerationTemplates.C @@ -126,8 +126,7 @@ void Foam::GAMGAgglomeration::restrictField const List& procIDs = agglomProcIDs(coarseLevelIndex); const labelList& offsets = cellOffsets(coarseLevelIndex); - const globalIndex cellOffsetter(offsets); - cellOffsetter.gather(fineComm, procIDs, cf); + globalIndex::gather(offsets, fineComm, procIDs, cf); } } @@ -192,19 +191,10 @@ void Foam::GAMGAgglomeration::prolongField const List& procIDs = agglomProcIDs(coarseLevelIndex); const labelList& offsets = cellOffsets(coarseLevelIndex); - const globalIndex cellOffsetter(offsets); - label localSize = nCells_[levelIndex]; - Field allCf(localSize); - cellOffsetter.scatter - ( - coarseComm, - procIDs, - cf, - allCf - ); + globalIndex::scatter(offsets, coarseComm, procIDs, cf, allCf); forAll(fineToCoarse, i) { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C index f825ca769d..d3a83dac79 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C @@ -25,6 +25,7 @@ License #include "GAMGProcAgglomeration.H" #include "GAMGAgglomeration.H" +#include "lduMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -114,6 +115,152 @@ void Foam::GAMGProcAgglomeration::printStats } +Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells +( + const lduMesh& mesh +) +{ + const lduAddressing& addr = mesh.lduAddr(); + lduInterfacePtrsList interfaces = mesh.interfaces(); + + const label myProcID = Pstream::myProcNo(mesh.comm()); + + globalIndex globalNumbering + ( + addr.size(), + Pstream::msgType(), + mesh.comm(), + Pstream::parRun() + ); + + labelList globalIndices(addr.size()); + forAll(globalIndices, cellI) + { + globalIndices[cellI] = globalNumbering.toGlobal(myProcID, cellI); + } + + + // Get the interface cells + PtrList nbrGlobalCells(interfaces.size()); + { + // Initialise transfer of restrict addressing on the interface + forAll(interfaces, inti) + { + if (interfaces.set(inti)) + { + interfaces[inti].initInternalFieldTransfer + ( + Pstream::nonBlocking, + globalIndices + ); + } + } + + if (Pstream::parRun()) + { + Pstream::waitRequests(); + } + + forAll(interfaces, inti) + { + if (interfaces.set(inti)) + { + nbrGlobalCells.set + ( + inti, + new labelList + ( + interfaces[inti].internalFieldTransfer + ( + Pstream::nonBlocking, + globalIndices + ) + ) + ); + } + } + } + + + // Scan the neighbour list to find out how many times the cell + // appears as a neighbour of the face. Done this way to avoid guessing + // and resizing list + labelList nNbrs(addr.size(), 1); + + const labelUList& nbr = addr.upperAddr(); + const labelUList& own = addr.lowerAddr(); + + { + forAll(nbr, faceI) + { + nNbrs[nbr[faceI]]++; + nNbrs[own[faceI]]++; + } + + forAll(interfaces, inti) + { + if (interfaces.set(inti)) + { + const labelUList& faceCells = interfaces[inti].faceCells(); + + forAll(faceCells, i) + { + nNbrs[faceCells[i]]++; + } + } + } + } + + + // Create cell-cells addressing + labelListList cellCells(addr.size()); + + forAll(cellCells, cellI) + { + cellCells[cellI].setSize(nNbrs[cellI], -1); + } + + // Reset the list of number of neighbours to zero + nNbrs = 0; + + // Scatter the neighbour faces + forAll(nbr, faceI) + { + label c0 = own[faceI]; + label c1 = nbr[faceI]; + + cellCells[c0][nNbrs[c0]++] = globalIndices[c1]; + cellCells[c1][nNbrs[c1]++] = globalIndices[c0]; + } + forAll(interfaces, inti) + { + if (interfaces.set(inti)) + { + const labelUList& faceCells = interfaces[inti].faceCells(); + + forAll(faceCells, i) + { + label c0 = faceCells[i]; + cellCells[c0][nNbrs[c0]++] = nbrGlobalCells[inti][i]; + } + } + } + + forAll(cellCells, cellI) + { + Foam::stableSort(cellCells[cellI]); + } + + // Replace the initial element (always -1) with the local cell + forAll(cellCells, cellI) + { + cellCells[cellI][0] = globalIndices[cellI]; + } + + return cellCells; +} + + bool Foam::GAMGProcAgglomeration::agglomerate ( const label fineLevelIndex, @@ -243,7 +390,4 @@ Foam::GAMGProcAgglomeration::~GAMGProcAgglomeration() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - - // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.H index cf27f44bc0..c3acc01521 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.H @@ -44,6 +44,7 @@ namespace Foam { class GAMGAgglomeration; +class lduMesh; /*---------------------------------------------------------------------------*\ Class GAMGProcAgglomeration Declaration @@ -74,6 +75,9 @@ protected: const label procAgglomComm ); + //- Debug: calculate global cell-cells + static labelListList globalCellCells(const lduMesh&); + private: // Private data @@ -139,7 +143,7 @@ public: // Member Functions - //- Modify agglomeration. Return true if modified + //- Modify agglomeration. Return true if modified virtual bool agglomerate() = 0; }; diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/processorGAMGInterface/processorGAMGInterface.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/processorGAMGInterface/processorGAMGInterface.H index df868544d0..3d0c9d28c3 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/processorGAMGInterface/processorGAMGInterface.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/processorGAMGInterface/processorGAMGInterface.H @@ -29,7 +29,6 @@ Description SourceFiles processorGAMGInterface.C - processorGAMGInterfaceTemplates.C \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C index 68069c88cf..070edd4b69 100644 --- a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C +++ b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C @@ -360,6 +360,7 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh + procMesh.lduAddr().size(); } + // Faces initially get added in order, sorted later labelList internalFaceOffsets(nMeshes+1); internalFaceOffsets[0] = 0; @@ -818,9 +819,37 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh { const labelPairList& elems = iter(); - // Sort processors in increasing order - labelList order(identity(elems.size())); - Foam::sort(order, procLess(elems)); + // Sort processors in increasing order so both sides walk through in + // same order. + labelPairList procPairs(elems.size()); + forAll(elems, i) + { + const labelPair& elem = elems[i]; + label procMeshI = elem[0]; + label interfaceI = elem[1]; + const lduInterfacePtrsList interfaces = mesh + ( + myMesh, + otherMeshes, + procMeshI + ).interfaces(); + + const processorLduInterface& pldui = + refCast + ( + interfaces[interfaceI] + ); + label myProcNo = pldui.myProcNo(); + label nbrProcNo = pldui.neighbProcNo(); + procPairs[i] = labelPair + ( + min(myProcNo, nbrProcNo), + max(myProcNo, nbrProcNo) + ); + } + + labelList order; + sortedOrder(procPairs, order); // Count label n = 0; @@ -837,11 +866,6 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh procMeshI ).interfaces(); - //Pout<< " adding interface:" << " procMeshI:" << procMeshI - // << " interface:" << interfaceI - // << " size:" << interfaces[interfaceI].faceCells().size() - // << endl; - n += interfaces[interfaceI].faceCells().size(); } @@ -868,6 +892,7 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh const labelUList& l = interfaces[interfaceI].faceCells(); bfMap.setSize(l.size()); + forAll(l, faceI) { allFaceCells[n] = cellOffsets[procMeshI]+l[faceI]; @@ -947,7 +972,10 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh patchSchedule_ = nonBlockingSchedule(interfaces_); - checkUpperTriangular(cellOffsets.last(), lowerAddr_, upperAddr_); + if (debug) + { + checkUpperTriangular(cellOffsets.last(), lowerAddr_, upperAddr_); + } } diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H index 4e92401489..80263b91d3 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H @@ -150,6 +150,19 @@ public: // Other + //- Collect data in processor order on master (== procIDs[0]). + // Needs offsets only on master. + template + static void gather + ( + const labelUList& offsets, + const label comm, + const labelList& procIDs, + const UList& fld, + List& allFld, + const int tag = UPstream::msgType() + ); + //- Collect data in processor order on master (== procIDs[0]). // Needs offsets only on master. template @@ -160,7 +173,22 @@ public: const UList& fld, List& allFld, const int tag = UPstream::msgType() - ) const; + ) const + { + gather(offsets_, comm, procIDs, fld, allFld, tag); + } + + //- Inplace collect data in processor order on master + // (== procIDs[0]). Needs offsets only on master. + template + static void gather + ( + const labelUList& offsets, + const label comm, + const labelList& procIDs, + List& fld, + const int tag = UPstream::msgType() + ); //- Inplace collect data in processor order on master // (== procIDs[0]). Needs offsets only on master. @@ -171,7 +199,22 @@ public: const labelList& procIDs, List& fld, const int tag = UPstream::msgType() - ) const; + ) const + { + gather(offsets_, comm, procIDs, fld, tag); + } + + //- Distribute data in processor order. Requires fld to be sized! + template + static void scatter + ( + const labelUList& offsets, + const label comm, + const labelList& procIDs, + const UList& allFld, + UList& fld, + const int tag = UPstream::msgType() + ); //- Distribute data in processor order. Requires fld to be sized! template @@ -182,7 +225,10 @@ public: const UList& allFld, UList& fld, const int tag = UPstream::msgType() - ) const; + ) const + { + scatter(offsets_, comm, procIDs, allFld, fld, tag); + } // IOstream Operators diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C index 2beb2cfe7a..73d2ea25a8 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C @@ -30,28 +30,24 @@ License template void Foam::globalIndex::gather ( + const labelUList& offsets, const label comm, const labelList& procIDs, const UList& fld, List& allFld, const int tag -) const +) { if (Pstream::myProcNo(comm) == procIDs[0]) { - allFld.setSize(size()); + allFld.setSize(offsets.last()); // Assign my local data SubList(allFld, fld.size(), 0).assign(fld); for (label i = 1; i < procIDs.size(); i++) { - SubList procSlot - ( - allFld, - offsets_[i+1]-offsets_[i], - offsets_[i] - ); + SubList procSlot(allFld, offsets[i+1]-offsets[i], offsets[i]); if (contiguous()) { @@ -112,27 +108,23 @@ void Foam::globalIndex::gather template void Foam::globalIndex::gather ( + const labelUList& offsets, const label comm, const labelList& procIDs, List& fld, const int tag -) const +) { if (Pstream::myProcNo(comm) == procIDs[0]) { - List allFld(size()); + List allFld(offsets.last()); // Assign my local data SubList(allFld, fld.size(), 0).assign(fld); for (label i = 1; i < procIDs.size(); i++) { - SubList procSlot - ( - allFld, - offsets_[i+1]-offsets_[i], - offsets_[i] - ); + SubList procSlot(allFld, offsets[i+1]-offsets[i], offsets[i]); if (contiguous()) { @@ -195,31 +187,25 @@ void Foam::globalIndex::gather template void Foam::globalIndex::scatter ( + const labelUList& offsets, const label comm, const labelList& procIDs, const UList& allFld, UList& fld, const int tag -) const +) { if (Pstream::myProcNo(comm) == procIDs[0]) { - fld.assign - ( - SubList - ( - allFld, - offsets_[1]-offsets_[0] - ) - ); + fld.assign(SubList(allFld, offsets[1]-offsets[0])); for (label i = 1; i < procIDs.size(); i++) { const SubList procSlot ( allFld, - offsets_[i+1]-offsets_[i], - offsets_[i] + offsets[i+1]-offsets[i], + offsets[i] ); if (contiguous()) diff --git a/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C b/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C index 24a68b5a05..99680f8bb6 100644 --- a/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C +++ b/src/triSurface/triSurface/interfaces/OBJ/writeOBJ.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,8 +52,12 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const // Print patch names as comment forAll(myPatches, patchI) { - os << "# " << patchI << " " - << myPatches[patchI].name() << nl; + const surfacePatch& patch = myPatches[patchI]; + + if (patch.size() > 0) + { + os << "# " << patchI << " " << patch.name() << nl; + } } os << "#" << nl; @@ -77,25 +81,29 @@ void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const forAll(myPatches, patchI) { + const surfacePatch& patch = myPatches[patchI]; + // Print all faces belonging to this patch - - os << "g " << myPatches[patchI].name() << nl; - - for - ( - label patchFaceI = 0; - patchFaceI < myPatches[patchI].size(); - patchFaceI++ - ) + if (patch.size() > 0) { - const label faceI = faceMap[faceIndex++]; + os << "g " << patch.name() << nl; - os << "f " - << operator[](faceI)[0] + 1 << ' ' - << operator[](faceI)[1] + 1 << ' ' - << operator[](faceI)[2] + 1 - //<< " # " << operator[](faceI).region() - << nl; + for + ( + label patchFaceI = 0; + patchFaceI < patch.size(); + patchFaceI++ + ) + { + const label faceI = faceMap[faceIndex++]; + + os << "f " + << operator[](faceI)[0] + 1 << ' ' + << operator[](faceI)[1] + 1 << ' ' + << operator[](faceI)[2] + 1 + //<< " # " << operator[](faceI).region() + << nl; + } } } } diff --git a/src/triSurface/triSurface/interfaces/STL/writeSTL.C b/src/triSurface/triSurface/interfaces/STL/writeSTL.C index 655787c40a..63874b185e 100644 --- a/src/triSurface/triSurface/interfaces/STL/writeSTL.C +++ b/src/triSurface/triSurface/interfaces/STL/writeSTL.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,39 +43,42 @@ void Foam::triSurface::writeSTLASCII(Ostream& os) const // Print all faces belonging to this region const surfacePatch& patch = myPatches[patchI]; - os << "solid " << patch.name() << endl; - - for - ( - label patchFaceI = 0; - patchFaceI < patch.size(); - patchFaceI++ - ) + if (patch.size() > 0) { - const label faceI = faceMap[faceIndex++]; + os << "solid " << patch.name() << endl; - const vector& n = faceNormals()[faceI]; + for + ( + label patchFaceI = 0; + patchFaceI < patch.size(); + patchFaceI++ + ) + { + const label faceI = faceMap[faceIndex++]; - os << " facet normal " - << n.x() << ' ' << n.y() << ' ' << n.z() << nl - << " outer loop" << endl; + const vector& n = faceNormals()[faceI]; - const labelledTri& f = (*this)[faceI]; - const point& pa = points()[f[0]]; - const point& pb = points()[f[1]]; - const point& pc = points()[f[2]]; + os << " facet normal " + << n.x() << ' ' << n.y() << ' ' << n.z() << nl + << " outer loop" << endl; - os << " vertex " - << pa.x() << ' ' << pa.y() << ' ' << pa.z() << nl - << " vertex " - << pb.x() << ' ' << pb.y() << ' ' << pb.z() << nl - << " vertex " - << pc.x() << ' ' << pc.y() << ' ' << pc.z() << nl - << " endloop" << nl - << " endfacet" << endl; + const labelledTri& f = (*this)[faceI]; + const point& pa = points()[f[0]]; + const point& pb = points()[f[1]]; + const point& pc = points()[f[2]]; + + os << " vertex " + << pa.x() << ' ' << pa.y() << ' ' << pa.z() << nl + << " vertex " + << pb.x() << ' ' << pb.y() << ' ' << pb.z() << nl + << " vertex " + << pc.x() << ' ' << pc.y() << ' ' << pc.z() << nl + << " endloop" << nl + << " endfacet" << endl; + } + + os << "endsolid " << patch.name() << endl; } - - os << "endsolid " << patch.name() << endl; } }