From 539bf2f34eb9b5edf197c9dbe72f402c2294a3d4 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 12 Dec 2011 11:39:36 +0000 Subject: [PATCH 01/70] STYLE: Minor code formatting --- .../cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.H | 2 -- .../conformalVoronoi2DMesh/cv2DControls/cv2DControlsI.H | 1 - 2 files changed, 3 deletions(-) diff --git a/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.H b/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.H index 9470badb2f..4ab8bdb167 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.H +++ b/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControls.H @@ -237,8 +237,6 @@ public: Ostream& os, const cv2DControls& s ); - - }; diff --git a/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControlsI.H b/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControlsI.H index 3ff16735a8..f5187100b6 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControlsI.H +++ b/applications/utilities/mesh/generation/cv2DMesh/conformalVoronoi2DMesh/cv2DControls/cv2DControlsI.H @@ -23,7 +23,6 @@ License \*---------------------------------------------------------------------------*/ - inline Foam::scalar Foam::cv2DControls::minCellSize() const { return minCellSize_; From 2d7b3363edc7ffabb092a0c5daa3543a76fe5b4b Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 12 Dec 2011 16:33:11 +0000 Subject: [PATCH 02/70] ENH: patchToFace: allow patch groups in patchToFace --- .../mesh/manipulation/topoSet/topoSetDict | 3 +- .../faceSources/patchToFace/patchToFace.C | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index 9c910aa7ec..5b8a4b73bb 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -211,7 +211,8 @@ FoamFile // source patchToFace; // sourceInfo // { -// name ".*Wall"; // Name of patch, regular expressions allowed +// name ".*Wall"; // Name of patch or patch group, +// // (regular expressions allowed) // } // // // All faces of faceZone diff --git a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C index 4ee6ead863..4dec426303 100644 --- a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C +++ b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C @@ -54,33 +54,34 @@ Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_ void Foam::patchToFace::combine(topoSet& set, const bool add) const { - bool hasMatched = false; + labelHashSet patchIDs = mesh_.boundaryMesh().patchSet + ( + List(1, patchName_), + true, // warn if not found + true // use patch groups if available + ); - forAll(mesh_.boundaryMesh(), patchI) + forAllConstIter(labelHashSet, patchIDs, iter) { + label patchI = iter.key(); + const polyPatch& pp = mesh_.boundaryMesh()[patchI]; - if (patchName_.match(pp.name())) + Info<< " Found matching patch " << pp.name() + << " with " << pp.size() << " faces." << endl; + + for + ( + label faceI = pp.start(); + faceI < pp.start() + pp.size(); + faceI++ + ) { - Info<< " Found matching patch " << pp.name() - << " with " << pp.size() << " faces." << endl; - - hasMatched = true; - - - for - ( - label faceI = pp.start(); - faceI < pp.start() + pp.size(); - faceI++ - ) - { - addOrDelete(set, faceI, add); - } + addOrDelete(set, faceI, add); } } - if (!hasMatched) + if (patchIDs.empty()) { WarningIn("patchToFace::combine(topoSet&, const bool)") << "Cannot find any patch named " << patchName_ << endl From da4f8e69dce21656ac700949bb838893f06b9936 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 12 Dec 2011 17:34:54 +0000 Subject: [PATCH 03/70] STYLE: Minor code formatting --- applications/utilities/mesh/generation/cv2DMesh/indexedFaceI.H | 2 ++ .../utilities/mesh/generation/cv2DMesh/indexedVertexI.H | 3 +++ 2 files changed, 5 insertions(+) diff --git a/applications/utilities/mesh/generation/cv2DMesh/indexedFaceI.H b/applications/utilities/mesh/generation/cv2DMesh/indexedFaceI.H index 89bdf68691..c3151fffc5 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/indexedFaceI.H +++ b/applications/utilities/mesh/generation/cv2DMesh/indexedFaceI.H @@ -106,3 +106,5 @@ inline int CGAL::indexedFace::faceIndex() const return index_; } + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/generation/cv2DMesh/indexedVertexI.H b/applications/utilities/mesh/generation/cv2DMesh/indexedVertexI.H index 6fef3fc7d4..65b254aabd 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/indexedVertexI.H +++ b/applications/utilities/mesh/generation/cv2DMesh/indexedVertexI.H @@ -228,3 +228,6 @@ bool CGAL::outsideTriangle || (v1.farPoint() || v1.ppSlave()) || (v2.farPoint() || v2.ppSlave()); } + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From a723468c9d4e59b412740eb4f1127c7e78a39cbb Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 12 Dec 2011 17:35:25 +0000 Subject: [PATCH 04/70] ENH: Using const for liquid thermo pvInvert function --- .../liquidProperties/liquidProperties/liquidProperties.C | 2 +- .../liquidProperties/liquidProperties/liquidProperties.H | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.C b/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.C index 877462f3b7..b4ae047fd9 100644 --- a/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.C +++ b/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.C @@ -342,7 +342,7 @@ Foam::scalar Foam::liquidProperties::D(scalar p, scalar T, scalar Wb) const } -Foam::scalar Foam::liquidProperties::pvInvert(scalar p) +Foam::scalar Foam::liquidProperties::pvInvert(scalar p) const { scalar T = Tc_; scalar deltaT = 10.0; diff --git a/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.H b/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.H index b72826d5e5..7cb4aa0710 100644 --- a/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.H +++ b/src/thermophysicalModels/properties/liquidProperties/liquidProperties/liquidProperties.H @@ -253,7 +253,7 @@ public: //- Invert the vapour pressure relationship to retrieve the // boiling temperuture as a function of temperature - virtual scalar pvInvert(scalar p); + virtual scalar pvInvert(scalar p) const; // I-O From 2499ad10a7f9d08cb916cee1ad19a7c6ddb291ab Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 13 Dec 2011 12:43:55 +0000 Subject: [PATCH 05/70] ENH: mappedPatchBase: make robust w.r.t. warped faces --- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 2 + src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C | 2 + src/meshTools/Make/files | 2 + .../mappedPolyPatch/mappedPatchBase.C | 317 ++++++++++++++---- .../mappedPolyPatch/mappedPatchBase.H | 10 +- .../meshSearchFACECENTRETETSMeshObject.C | 48 +++ .../meshSearchFACECENTRETETSMeshObject.H | 92 +++++ .../meshSearch/meshSearchMeshObject.C | 45 +++ .../meshSearch/meshSearchMeshObject.H | 92 +++++ 9 files changed, 537 insertions(+), 73 deletions(-) create mode 100644 src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.C create mode 100644 src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.H create mode 100644 src/meshTools/meshSearch/meshSearchMeshObject.C create mode 100644 src/meshTools/meshSearch/meshSearchMeshObject.H diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 960e35ddd4..8dd2eaf423 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -1172,6 +1172,8 @@ Foam::tmp Foam::polyMesh::movePoints ) ).movePoints(points_); } + meshSearchMeshObject::Delete(*this); + meshSearchFACECENTRETETSMeshObject::Delete(*this); return sweptVols; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C b/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C index bba7367e8b..4dc64d17d8 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C @@ -95,6 +95,8 @@ void Foam::polyMesh::updateMesh(const mapPolyMesh& mpm) ) ).updateMesh(mpm); } + meshSearchMeshObject::Delete(*this); + meshSearchFACECENTRETETSMeshObject::Delete(*this); } diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index d8687b042b..2be634334c 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -27,6 +27,8 @@ polyMeshZipUpCells/polyMeshZipUpCells.C primitiveMeshGeometry/primitiveMeshGeometry.C meshSearch/meshSearch.C +meshSearch/meshSearchFACECENTRETETSMeshObject.C +meshSearch/meshSearchMeshObject.C meshTools/meshTools.C diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 2b62b29e34..9950b9b061 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -26,7 +26,7 @@ License #include "mappedPatchBase.H" #include "addToRunTimeSelectionTable.H" #include "ListListOps.H" -#include "meshSearch.H" +#include "meshSearchMeshObject.H" #include "meshTools.H" #include "OFstream.H" #include "Random.H" @@ -37,6 +37,7 @@ License #include "Time.H" #include "mapDistribute.H" #include "SubField.H" +#include "triPointRef.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,64 +81,144 @@ const Foam::NamedEnum // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +Foam::tmp Foam::mappedPatchBase::facePoints +( + const polyPatch& pp +) const +{ + const polyMesh& mesh = pp.boundaryMesh().mesh(); + const labelList& tetBasePts = mesh.tetBasePtIs(); + const pointField& p = pp.points(); + const pointField& cellCentres = mesh.cellCentres(); + const labelList& faceCells = pp.faceCells(); + + // Initialise to face-centre + tmp tfacePoints(new pointField(patch_.faceCentres())); + pointField& facePoints = tfacePoints(); + + forAll(pp, faceI) + { + const face& f = pp[faceI]; + + if (f.size() <= 3) + { + // Point already on tets of cell. + } + else + { + // Find intersection of (face-centre-decomposition) centre to + // cell-centre with face-diagonal-decomposition triangles. + const point& cc = cellCentres[faceCells[faceI]]; + vector d = facePoints[faceI]-cc; + + const label fp0 = tetBasePts[faceI]; + const point& basePoint = p[f[fp0]]; + + //bool foundPoint = false; + + label fp = f.fcIndex(fp0); + for (label i = 2; i < f.size(); i++) + { + const point& thisPoint = p[f[fp]]; + label nextFp = f.fcIndex(fp); + const point& nextPoint = p[f[nextFp]]; + + const triPointRef tri(basePoint, thisPoint, nextPoint); + pointHit hitInfo = tri.intersection + ( + cc, + d, + intersection::HALF_RAY + ); + + if (hitInfo.hit() && hitInfo.distance() > 0) + { + facePoints[faceI] = hitInfo.hitPoint(); + //foundPoint = true; + break; + } + + fp = nextFp; + } + + //if (!foundPoint) + //{ + // Pout<< "cell:" << faceCells[faceI] << " at:" << cc + // << " face-centre:" << patch_.faceCentres()[faceI] + // << " did not find any intersection." << endl; + //} + } + } + + return tfacePoints; +} + + void Foam::mappedPatchBase::collectSamples ( + const pointField& facePoints, pointField& samples, labelList& patchFaceProcs, labelList& patchFaces, pointField& patchFc ) const { - // Collect all sample points and the faces they come from. - List globalFc(Pstream::nProcs()); - List globalSamples(Pstream::nProcs()); - labelListList globalFaces(Pstream::nProcs()); + { + List globalFc(Pstream::nProcs()); + globalFc[Pstream::myProcNo()] = facePoints; + Pstream::gatherList(globalFc); + Pstream::scatterList(globalFc); + // Rework into straight list + patchFc = ListListOps::combine + ( + globalFc, + accessOp() + ); + } - globalFc[Pstream::myProcNo()] = patch_.faceCentres(); - globalSamples[Pstream::myProcNo()] = samplePoints(); - globalFaces[Pstream::myProcNo()] = identity(patch_.size()); + { + List globalSamples(Pstream::nProcs()); + globalSamples[Pstream::myProcNo()] = samplePoints(facePoints); + Pstream::gatherList(globalSamples); + Pstream::scatterList(globalSamples); + // Rework into straight list + samples = ListListOps::combine + ( + globalSamples, + accessOp() + ); + } - // Distribute to all processors - Pstream::gatherList(globalSamples); - Pstream::scatterList(globalSamples); - Pstream::gatherList(globalFaces); - Pstream::scatterList(globalFaces); - Pstream::gatherList(globalFc); - Pstream::scatterList(globalFc); + { + labelListList globalFaces(Pstream::nProcs()); + globalFaces[Pstream::myProcNo()] = identity(patch_.size()); + // Distribute to all processors + Pstream::gatherList(globalFaces); + Pstream::scatterList(globalFaces); - // Rework into straight list - samples = ListListOps::combine - ( - globalSamples, - accessOp() - ); - patchFaces = ListListOps::combine - ( - globalFaces, - accessOp() - ); - patchFc = ListListOps::combine - ( - globalFc, - accessOp() - ); - - patchFaceProcs.setSize(patchFaces.size()); - labelList nPerProc - ( - ListListOps::subSizes + patchFaces = ListListOps::combine ( globalFaces, accessOp() - ) - ); - label sampleI = 0; - forAll(nPerProc, procI) + ); + } + { - for (label i = 0; i < nPerProc[procI]; i++) + labelList nPerProc(Pstream::nProcs()); + nPerProc[Pstream::myProcNo()] = patch_.size(); + Pstream::gatherList(nPerProc); + Pstream::scatterList(nPerProc); + + patchFaceProcs.setSize(patchFaces.size()); + + label sampleI = 0; + forAll(nPerProc, procI) { - patchFaceProcs[sampleI++] = procI; + for (label i = 0; i < nPerProc[procI]; i++) + { + patchFaceProcs[sampleI++] = procI; + } } } } @@ -173,8 +254,9 @@ void Foam::mappedPatchBase::findSamples << sampleModeNames_[mode_] << " mode." << exit(FatalError); } - // Octree based search engine - meshSearch meshSearchEngine(mesh); + //- Note: face-diagonal decomposition + const meshSearchMeshObject& meshSearchEngine = + meshSearchMeshObject::New(mesh); forAll(samples, sampleI) { @@ -290,8 +372,9 @@ void Foam::mappedPatchBase::findSamples << sampleModeNames_[mode_] << " mode." << exit(FatalError); } - // Octree based search engine - meshSearch meshSearchEngine(mesh); + //- Note: face-diagonal decomposition + const meshSearchMeshObject& meshSearchEngine = + meshSearchMeshObject::New(mesh); forAll(samples, sampleI) { @@ -355,23 +438,6 @@ void Foam::mappedPatchBase::findSamples } } - // Check for samples not being found - forAll(nearest, sampleI) - { - if (!nearest[sampleI].first().hit()) - { - FatalErrorIn - ( - "mappedPatchBase::findSamples" - "(const pointField&, labelList&" - ", labelList&, pointField&)" - ) << "Did not find sample " << samples[sampleI] - << " on any processor of region " << sampleRegion_ - << exit(FatalError); - } - } - - // Convert back into proc+local index sampleProcs.setSize(samples.size()); sampleIndices.setSize(samples.size()); @@ -379,21 +445,40 @@ void Foam::mappedPatchBase::findSamples forAll(nearest, sampleI) { - sampleProcs[sampleI] = nearest[sampleI].second().second(); - sampleIndices[sampleI] = nearest[sampleI].first().index(); - sampleLocations[sampleI] = nearest[sampleI].first().hitPoint(); + if (!nearest[sampleI].first().hit()) + { + sampleProcs[sampleI] = -1; + sampleIndices[sampleI] = -1; + sampleLocations[sampleI] = vector::max; + } + else + { + sampleProcs[sampleI] = nearest[sampleI].second().second(); + sampleIndices[sampleI] = nearest[sampleI].first().index(); + sampleLocations[sampleI] = nearest[sampleI].first().hitPoint(); + } } } void Foam::mappedPatchBase::calcMapping() const { + static bool hasWarned = false; + if (mapPtr_.valid()) { FatalErrorIn("mappedPatchBase::calcMapping() const") << "Mapping already calculated" << exit(FatalError); } + // Get points on face (since cannot use face-centres - might be off + // face-diagonal decomposed tets. + tmp patchPoints(facePoints(patch_)); + + // Get offsetted points + const pointField offsettedPoints = samplePoints(patchPoints()); + + // Do a sanity check // Am I sampling my own patch? This only makes sense for a non-zero // offset. @@ -405,8 +490,10 @@ void Foam::mappedPatchBase::calcMapping() const ); // Check offset - vectorField d(samplePoints()-patch_.faceCentres()); - if (sampleMyself && gAverage(mag(d)) <= ROOTVSMALL) + vectorField d(offsettedPoints-patchPoints()); + bool coincident = (gAverage(mag(d)) <= ROOTVSMALL); + + if (sampleMyself && coincident) { WarningIn ( @@ -438,7 +525,15 @@ void Foam::mappedPatchBase::calcMapping() const labelList patchFaceProcs; labelList patchFaces; pointField patchFc; - collectSamples(samples, patchFaceProcs, patchFaces, patchFc); + collectSamples + ( + patchPoints, + samples, + patchFaceProcs, + patchFaces, + patchFc + ); + // Find processor and cell/face samples are in and actual location. labelList sampleProcs; @@ -446,6 +541,75 @@ void Foam::mappedPatchBase::calcMapping() const pointField sampleLocations; findSamples(samples, sampleProcs, sampleIndices, sampleLocations); + // Check for samples that were not found. This will only happen for + // NEARESTCELL since finds cell containing a location + if (mode_ == NEARESTCELL) + { + label nNotFound = 0; + forAll(sampleProcs, sampleI) + { + if (sampleProcs[sampleI] == -1) + { + nNotFound++; + } + } + reduce(nNotFound, sumOp