From dc999ad07ef585ecedd9468847e45f03d1499a58 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 7 Aug 2009 11:27:48 +0100 Subject: [PATCH 1/4] fvMesh xfer constructor change --- .../mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C b/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C index 47ec7f9137..f4bf559009 100644 --- a/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C +++ b/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C @@ -908,10 +908,10 @@ int main(int argc, char *argv[]) runTime.constant(), runTime ), - foamPoints, - foamFaces, - foamOwner, - foamNeighbour + xferMove(foamPoints), + xferMove(foamFaces), + xferCopy(foamOwner), + xferMove(foamNeighbour) ); // Create patches. Use patch types to determine what Foam types to generate. From c635b44ae55ac3d6466e644e484bdb95bb36c49a Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 10 Aug 2009 11:30:52 +0100 Subject: [PATCH 2/4] stabilisation for zero-area faces --- .../primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C index 3534519ca7..29841d3ec8 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C @@ -626,7 +626,8 @@ bool Foam::primitiveMesh::checkFaceSkewness vector d = cellCtrs[nei[faceI]] - cellCtrs[own[faceI]]; // Skewness vector - vector sv = Cpf - ((fAreas[faceI] & Cpf)/(fAreas[faceI] & d))*d; + vector sv = + Cpf - ((fAreas[faceI] & Cpf)/((fAreas[faceI] & d) + SMALL))*d; vector svHat = sv/(mag(sv) + VSMALL); // Normalisation distance calculated as the approximate distance From 6059bc7cc18b4a435c82015fd28f362f3e5fd349 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 10 Aug 2009 11:39:51 +0100 Subject: [PATCH 3/4] reduce synchronisation --- src/postProcessing/functionObjects/Allwmake | 1 + .../field/fieldMinMax/fieldMinMax.C | 10 ++-- .../field/fieldMinMax/fieldMinMaxTemplates.C | 47 +++++++++-------- .../faceZonesIntegration.C | 50 +++++++++++-------- .../faceZonesIntegration.H | 20 ++++---- 5 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/postProcessing/functionObjects/Allwmake b/src/postProcessing/functionObjects/Allwmake index 6c642dfe7b..b068fe51cb 100755 --- a/src/postProcessing/functionObjects/Allwmake +++ b/src/postProcessing/functionObjects/Allwmake @@ -7,5 +7,6 @@ wmake libso forces wmake libso IO wmake libso utilities wmake libso systemCall +wmake libso zones # ----------------------------------------------------------------- end-of-file diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C index ec77782df4..31e511377e 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C @@ -197,13 +197,13 @@ void Foam::fieldMinMax::calcMinMaxFields { if (obr_.foundObject(fieldName)) { + const volScalarField& field = + obr_.lookupObject(fieldName); + scalar minValue = min(field).value(); + scalar maxValue = max(field).value(); + if (Pstream::master()) { - const volScalarField& field = - obr_.lookupObject(fieldName); - scalar minValue = min(field).value(); - scalar maxValue = max(field).value(); - fieldMinMaxFilePtr_() << obr_.time().value() << tab << fieldName << tab << minValue << tab << maxValue << endl; diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index 25daf62dd6..66f212f4c3 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -38,16 +38,16 @@ void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName) if (obr_.foundObject(fieldName)) { - if (Pstream::master()) + const fieldType& field = obr_.lookupObject(fieldName); + switch (mode_) { - const fieldType& field = obr_.lookupObject(fieldName); - switch (mode_) + case mdMag: { - case mdMag: - { - scalar minValue = min(mag(field)).value(); - scalar maxValue = max(mag(field)).value(); + scalar minValue = min(mag(field)).value(); + scalar maxValue = max(mag(field)).value(); + if (Pstream::master()) + { fieldMinMaxFilePtr_() << obr_.time().value() << tab << fieldName << tab << minValue << tab << maxValue << endl; @@ -61,13 +61,16 @@ void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName) << maxValue << nl << endl; } - break; } - case mdCmpt: - { - Type minValue = min(field).value(); - Type maxValue = max(field).value(); + break; + } + case mdCmpt: + { + Type minValue = min(field).value(); + Type maxValue = max(field).value(); + if (Pstream::master()) + { fieldMinMaxFilePtr_() << obr_.time().value() << tab << fieldName << tab << minValue << tab << maxValue << endl; @@ -81,17 +84,17 @@ void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName) << maxValue << nl << endl; } - break; - } - default: - { - FatalErrorIn - ( - "Foam::fieldMinMax::calcMinMaxFields" - "(const word& fieldName)" - )<< "Unknown min/max mode: " << modeTypeNames_[mode_] - << exit(FatalError); } + break; + } + default: + { + FatalErrorIn + ( + "Foam::fieldMinMax::calcMinMaxFields" + "(const word& fieldName)" + )<< "Unknown min/max mode: " << modeTypeNames_[mode_] + << exit(FatalError); } } } diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C index 0b8314667c..e048920899 100644 --- a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.C @@ -191,7 +191,7 @@ void Foam::faceZonesIntegration::write() if (active_) { makeFile(); - scalar dm = 0.0; + forAll(fItems_, fieldI) { const word& fieldName = fItems_[fieldI]; @@ -201,8 +201,30 @@ void Foam::faceZonesIntegration::write() const fvMesh& mesh = fD.mesh(); + // 1. integrate over all face zones + + scalarField integralVals(faceZonesSet_.size()); + + forAll(faceZonesSet_, setI) + { + const word name = faceZonesSet_[setI]; + + label zoneID = mesh.faceZones().findZoneID(name); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + integralVals[setI] = returnReduce + ( + calcFaceZonesIntegral(fD, fz), + sumOp() + ); + } + + unsigned int w = IOstream::defaultPrecision() + 7; + // 2. Write only on master + if ( Pstream::master() @@ -213,26 +235,14 @@ void Foam::faceZonesIntegration::write() os << obr_.time().value(); - const faceZoneMesh& faceZoneList = mesh.faceZones(); - - forAll(faceZonesSet_, zoneI) + forAll(integralVals, setI) { - const word name = faceZonesSet_[zoneI]; - - label zoneID = faceZoneList.findZoneID(name); - - const faceZone& fz = mesh.faceZones()[zoneID]; - - dm = calcFaceZonesIntegral(fD, fz); - - reduce(dm, sumOp()); - - os << ' ' << setw(w) << dm; + os << ' ' << setw(w) << integralVals[setI]; if (log_) { Info<< "faceZonesIntegration output:" << nl - << " Integration" << dm << endl; + << " Integration" << integralVals[setI] << endl; } } @@ -258,7 +268,7 @@ Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral if (mesh.isInternalFace(faceI)) { - if (fz.flipMap()[faceI]) + if (fz.flipMap()[i]) { dm -= fD[faceI]; } @@ -275,7 +285,7 @@ Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral { if (refCast(pp).owner()) { - if (fz.flipMap()[faceI]) + if (fz.flipMap()[i]) { dm -= fD.boundaryField()[patchI][pp.whichFace(faceI)]; } @@ -290,7 +300,7 @@ Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral label patchFaceI = faceI - pp.start(); if (patchFaceI < pp.size()/2) { - if (fz.flipMap()[patchFaceI]) + if (fz.flipMap()[i]) { dm -= fD.boundaryField()[patchI][patchFaceI]; } @@ -303,7 +313,7 @@ Foam::scalar Foam::faceZonesIntegration::calcFaceZonesIntegral else if (!isA(pp)) { label patchFaceI = faceI - pp.start(); - if (fz.flipMap()[patchFaceI]) + if (fz.flipMap()[i]) { dm -= fD.boundaryField()[patchI][patchFaceI]; } diff --git a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H index 5fc957bba7..87659ac340 100644 --- a/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H +++ b/src/postProcessing/functionObjects/zones/faceZoneIntegration/faceZonesIntegration.H @@ -73,17 +73,14 @@ protected: const objectRegistry& obr_; - //- on/off switch - bool active_; - - //- Switch to send output to Info as well as to file - Switch log_; - - //- Current open files - HashPtrTable faceZonesIntegrationFilePtr_; - // Read from dictionary + //- on/off switch + bool active_; + + //- Switch to send output to Info as well as to file + Switch log_; + //- faceZones to integrate over wordList faceZonesSet_; @@ -91,6 +88,11 @@ protected: wordList fItems_; + //- Current open files + HashPtrTable faceZonesIntegrationFilePtr_; + + + // Private Member Functions //- If the integration file has not been created create it From b90ee94d022cc9d2ebe7ad44c343644422eb51bd Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 10 Aug 2009 11:43:56 +0100 Subject: [PATCH 4/4] weighted decomposition --- .../decompositionMethod/decompositionMethod.C | 42 +- .../decompositionMethod/decompositionMethod.H | 31 +- .../hierarchGeomDecomp/hierarchGeomDecomp.C | 353 +++++++++++- .../hierarchGeomDecomp/hierarchGeomDecomp.H | 58 ++ .../manualDecomp/manualDecomp.C | 18 +- .../manualDecomp/manualDecomp.H | 11 +- .../metisDecomp/metisDecomp.C | 165 +++--- .../metisDecomp/metisDecomp.H | 25 +- .../scotchDecomp/scotchDecomp.C | 193 ++----- .../scotchDecomp/scotchDecomp.H | 21 +- .../simpleGeomDecomp/simpleGeomDecomp.C | 144 ++++- .../simpleGeomDecomp/simpleGeomDecomp.H | 27 +- .../parMetisDecomp/parMetisDecomp.C | 530 +++++++++--------- .../parMetisDecomp/parMetisDecomp.H | 22 +- 14 files changed, 1111 insertions(+), 529 deletions(-) diff --git a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C index 01b1a56d03..c38e0494ae 100644 --- a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C +++ b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C @@ -25,8 +25,6 @@ License InClass decompositionMethod -Description - \*---------------------------------------------------------------------------*/ #include "decompositionMethod.H" @@ -104,14 +102,26 @@ Foam::autoPtr Foam::decompositionMethod::New } +Foam::labelList Foam::decompositionMethod::decompose +( + const pointField& points +) +{ + scalarField weights(0); + + return decompose(points, weights); +} + + Foam::labelList Foam::decompositionMethod::decompose ( const labelList& fineToCoarse, - const pointField& coarsePoints + const pointField& coarsePoints, + const scalarField& coarseWeights ) { // Decompose based on agglomerated points - labelList coarseDistribution(decompose(coarsePoints)); + labelList coarseDistribution(decompose(coarsePoints, coarseWeights)); // Rework back into decomposition for original mesh_ labelList fineDistribution(fineToCoarse.size()); @@ -125,6 +135,18 @@ Foam::labelList Foam::decompositionMethod::decompose } +Foam::labelList Foam::decompositionMethod::decompose +( + const labelList& fineToCoarse, + const pointField& coarsePoints +) +{ + scalarField coarseWeights(0); + + return decompose(fineToCoarse, coarsePoints, coarseWeights); +} + + void Foam::decompositionMethod::calcCellCells ( const polyMesh& mesh, @@ -170,4 +192,16 @@ void Foam::decompositionMethod::calcCellCells } +Foam::labelList Foam::decompositionMethod::decompose +( + const labelListList& globalCellCells, + const pointField& cc +) +{ + scalarField cWeights(0); + + return decompose(globalCellCells, cc, cWeights); +} + + // ************************************************************************* // diff --git a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H index 7055f24d7b..7f66e9f50d 100644 --- a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H +++ b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H @@ -150,20 +150,37 @@ public: //- Return for every coordinate the wanted processor number. Use the // mesh connectivity (if needed) - virtual labelList decompose(const pointField&) = 0; + virtual labelList decompose + ( + const pointField& points, + const scalarField& pointWeights + ) = 0; + + //- Like decompose but with uniform weights on the points + virtual labelList decompose(const pointField&); + //- Return for every coordinate the wanted processor number. Gets // passed agglomeration map (from fine to coarse cells) and coarse cell // location. Can be overridden by decomposers that provide this // functionality natively. Coarse cells are local to the processor // (if in parallel). If you want to have coarse cells spanning - // processors use the next function below instead. + // processors use the globalCellCells instead. + virtual labelList decompose + ( + const labelList& cellToRegion, + const pointField& regionPoints, + const scalarField& regionWeights + ); + + //- Like decompose but with uniform weights on the regions virtual labelList decompose ( const labelList& cellToRegion, const pointField& regionPoints ); + //- Return for every coordinate the wanted processor number. Explicitly // provided connectivity - does not use mesh_. // The connectivity is equal to mesh.cellCells() except for @@ -174,9 +191,17 @@ public: virtual labelList decompose ( const labelListList& globalCellCells, - const pointField& cc + const pointField& cc, + const scalarField& cWeights ) = 0; + //- Like decompose but with uniform weights on the cells + virtual labelList decompose + ( + const labelListList& globalCellCells, + const pointField& cc + ); + }; diff --git a/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C b/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C index 72d39d215c..bde1181c09 100644 --- a/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C +++ b/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C @@ -142,6 +142,38 @@ Foam::label Foam::hierarchGeomDecomp::findLower } +// Create a mapping between the index and the weighted size. +// For convenience, sortedWeightedSize is one size bigger than current. This +// avoids extra tests. +void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes +( + const labelList& current, + const labelList& indices, + const scalarField& weights, + const label globalCurrentSize, + + scalarField& sortedWeightedSizes +) +{ + // Evaluate cumulative weights. + sortedWeightedSizes[0] = 0; + forAll(current, i) + { + label pointI = current[indices[i]]; + sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointI]; + } + // Non-dimensionalise and multiply by size. + scalar globalCurrentLength = returnReduce + ( + sortedWeightedSizes[current.size()], + sumOp() + ); + // Normalise weights by global sum of weights and multiply through + // by global size. + sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength); +} + + // Find position in values so between minIndex and this position there // are wantedSize elements. void Foam::hierarchGeomDecomp::findBinary @@ -170,7 +202,6 @@ void Foam::hierarchGeomDecomp::findBinary label midPrev = -1; label highPrev = -1; - //while (low <= high) while (true) { label size = returnReduce(mid-minIndex, sumOp