From 3c426d3b2ec711759e377d86a92607ecc4cd7003 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 16 Jan 2009 17:14:24 +0000 Subject: [PATCH 1/6] wildcard usage --- .../utilities/mesh/manipulation/cellSet/cellSetDict | 2 +- .../utilities/mesh/manipulation/faceSet/faceSetDict | 4 ++-- .../utilities/mesh/manipulation/pointSet/pointSetDict | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/applications/utilities/mesh/manipulation/cellSet/cellSetDict b/applications/utilities/mesh/manipulation/cellSet/cellSetDict index 3bda8ccd01..9589b484eb 100644 --- a/applications/utilities/mesh/manipulation/cellSet/cellSetDict +++ b/applications/utilities/mesh/manipulation/cellSet/cellSetDict @@ -82,7 +82,7 @@ topoSetSources // Cells in cell zone zoneToCell { - name cellZone; // name of cellZone + name ".*Zone"; // name of cellZone, wildcards allowed. } // values of field within certain range diff --git a/applications/utilities/mesh/manipulation/faceSet/faceSetDict b/applications/utilities/mesh/manipulation/faceSet/faceSetDict index 4f6c0d1509..4d5abe2a5e 100644 --- a/applications/utilities/mesh/manipulation/faceSet/faceSetDict +++ b/applications/utilities/mesh/manipulation/faceSet/faceSetDict @@ -56,13 +56,13 @@ topoSetSources // All faces of patch patchToFace { - name movingWall; + name ".*Wall"; // Name of patch, regular expressions allowed } // All faces of faceZone zoneToFace { - name faceZone1; // Name of faceZone + name ".*Zone1"; // Name of faceZone, regular expressions allowed } // Faces with face centre within box diff --git a/applications/utilities/mesh/manipulation/pointSet/pointSetDict b/applications/utilities/mesh/manipulation/pointSet/pointSetDict index 27a43d3ad9..5c19ea60fe 100644 --- a/applications/utilities/mesh/manipulation/pointSet/pointSetDict +++ b/applications/utilities/mesh/manipulation/pointSet/pointSetDict @@ -57,6 +57,12 @@ topoSetSources box (0 0 0) (1 1 1); } + // All points in pointzone + zoneToPoint + { + name ".*Zone"; // name of pointZone, wildcards allowed. + } + // Select based on surface surfaceToPoint { From e5f598542b0ab75fd7781d45780a202be14c8788 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 16 Jan 2009 17:14:52 +0000 Subject: [PATCH 2/6] debug message --- .../searchableSurface/searchablePlate.C | 22 +++++++++++++++++-- .../searchableSurface/searchablePlate.H | 9 +++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/meshTools/searchableSurface/searchablePlate.C b/src/meshTools/searchableSurface/searchablePlate.C index 8d61564287..c72e28a7de 100644 --- a/src/meshTools/searchableSurface/searchablePlate.C +++ b/src/meshTools/searchableSurface/searchablePlate.C @@ -218,7 +218,16 @@ Foam::searchablePlate::searchablePlate origin_(origin), span_(span), normalDir_(calcNormal(span_)) -{} +{ + if (debug) + { + Info<< "searchablePlate::searchablePlate :" + << " origin:" << origin_ + << " origin+span:" << origin_+span_ + << " normal:" << vector::componentNames[normalDir_] + << endl; + } +} Foam::searchablePlate::searchablePlate @@ -231,7 +240,16 @@ Foam::searchablePlate::searchablePlate origin_(dict.lookup("origin")), span_(dict.lookup("span")), normalDir_(calcNormal(span_)) -{} +{ + if (debug) + { + Info<< "searchablePlate::searchablePlate :" + << " origin:" << origin_ + << " origin+span:" << origin_+span_ + << " normal:" << vector::componentNames[normalDir_] + << endl; + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurface/searchablePlate.H b/src/meshTools/searchableSurface/searchablePlate.H index 957f51ee91..7bc900f554 100644 --- a/src/meshTools/searchableSurface/searchablePlate.H +++ b/src/meshTools/searchableSurface/searchablePlate.H @@ -27,7 +27,14 @@ Class Description Searching on finite plate. Plate has to be aligned with coordinate - axes! + axes. + Plate defined as origin and span. One of the components of span has + to be 0 which defines the normal direction. E.g. + + span = (Sx Sy 0) // plate in x-y plane + origin = (Ox Oy Oz) + + now plane is from (Ox Oy Oz) to (Ox+Sx Oy+Sy Oz) SourceFiles searchablePlate.C From db88110676dc0cc3e2594dc1cba081f334e3fce3 Mon Sep 17 00:00:00 2001 From: mattijs Date: Sat, 17 Jan 2009 13:59:12 +0000 Subject: [PATCH 3/6] signed distance surface error --- .../distanceSurface/distanceSurface.C | 86 ++++++++++++++-- .../sampledSurface/isoSurface/isoSurface.C | 97 +++++++++++-------- .../sampledSurface/isoSurface/isoSurface.H | 14 ++- .../isoSurface/isoSurfaceTemplates.C | 25 +++-- 4 files changed, 167 insertions(+), 55 deletions(-) diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index f3821e1d91..888b51b9c6 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -45,6 +45,11 @@ namespace Foam void Foam::distanceSurface::createGeometry() { + if (debug) + { + Pout<< "distanceSurface::createGeometry :updating geometry." << endl; + } + // Clear any stored topologies facesPtr_.clear(); @@ -67,7 +72,7 @@ void Foam::distanceSurface::createGeometry() false ), fvm, - dimensionedScalar("zero", dimless/dimTime, 0) + dimensionedScalar("zero", dimLength, 0) ) ); volScalarField& cellDistance = cellDistancePtr_(); @@ -157,6 +162,7 @@ void Foam::distanceSurface::createGeometry() } } + // On processor patches the mesh.C() will already be the cell centre // on the opposite side so no need to swap cellDistance. @@ -164,23 +170,70 @@ void Foam::distanceSurface::createGeometry() // Distance to points pointDistance_.setSize(fvm.nPoints()); { + const pointField& pts = fvm.points(); + List nearest; surfPtr_().findNearest ( - fvm.points(), - scalarField(fvm.nPoints(), GREAT), + pts, + scalarField(pts.size(), GREAT), nearest ); - forAll(pointDistance_, pointI) + + if (signed_) { - pointDistance_[pointI] = Foam::mag - ( - nearest[pointI].hitPoint() - - fvm.points()[pointI] - ); + vectorField normal; + surfPtr_().getNormal(nearest, normal); + + forAll(nearest, i) + { + vector d(pts[i]-nearest[i].hitPoint()); + + if ((d&normal[i]) > 0) + { + pointDistance_[i] = Foam::mag(d); + } + else + { + pointDistance_[i] = -Foam::mag(d); + } + } + } + else + { + forAll(nearest, i) + { + pointDistance_[i] = Foam::mag(pts[i]-nearest[i].hitPoint()); + } } } + + if (debug) + { + Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl; + cellDistance.write(); + pointScalarField pDist + ( + IOobject + ( + "pointDistance", + fvm.time().timeName(), + fvm.time(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + pointMesh::New(fvm), + dimensionedScalar("zero", dimLength, 0) + ); + pDist.internalField() = pointDistance_; + + Pout<< "Writing point distance:" << pDist.objectPath() << endl; + pDist.write(); + } + + //- Direct from cell field and point field. isoSurfPtr_.reset ( @@ -196,6 +249,7 @@ void Foam::distanceSurface::createGeometry() if (debug) { print(Pout); + Pout<< endl; } } @@ -264,6 +318,13 @@ bool Foam::distanceSurface::needsUpdate() const bool Foam::distanceSurface::expire() { + if (debug) + { + Pout<< "distanceSurface::expire :" + << " have-facesPtr_:" << facesPtr_.valid() + << " needsUpdate_:" << needsUpdate_ << endl; + } + // Clear any stored topologies facesPtr_.clear(); @@ -280,6 +341,13 @@ bool Foam::distanceSurface::expire() bool Foam::distanceSurface::update() { + if (debug) + { + Pout<< "distanceSurface::update :" + << " have-facesPtr_:" << facesPtr_.valid() + << " needsUpdate_:" << needsUpdate_ << endl; + } + if (!needsUpdate_) { return false; diff --git a/src/sampling/sampledSurface/isoSurface/isoSurface.C b/src/sampling/sampledSurface/isoSurface/isoSurface.C index 8522dd8442..3571df4a49 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/isoSurface.C @@ -58,6 +58,31 @@ Foam::scalar Foam::isoSurface::isoFraction } +bool Foam::isoSurface::isEdgeOfFaceCut +( + const scalarField& pVals, + const face& f, + const bool ownLower, + const bool neiLower +) const +{ + forAll(f, fp) + { + bool fpLower = (pVals[f[fp]] < iso_); + if + ( + (fpLower != ownLower) + || (fpLower != neiLower) + || (fpLower != (pVals[f[f.fcIndex(fp)]] < iso_)) + ) + { + return true; + } + } + return false; +} + + // Determine for every face/cell whether it (possibly) generates triangles. void Foam::isoSurface::calcCutTypes ( @@ -84,22 +109,13 @@ void Foam::isoSurface::calcCutTypes } else { - // Mesh edge. + // See if any mesh edge is cut by looping over all the edges of the + // face. const face f = mesh_.faces()[faceI]; - forAll(f, fp) + if (isEdgeOfFaceCut(pVals, f, ownLower, neiLower)) { - bool fpLower = (pVals[f[fp]] < iso_); - if - ( - (fpLower != (pVals[f[f.fcIndex(fp)]] < iso_)) - || (fpLower != ownLower) - || (fpLower != neiLower) - ) - { - faceCutType_[faceI] = CUT; - break; - } + faceCutType_[faceI] = CUT; } } } @@ -117,22 +133,13 @@ void Foam::isoSurface::calcCutTypes { bool ownLower = (cVals[own[faceI]] < iso_); - // Mesh edge. const face f = mesh_.faces()[faceI]; - forAll(f, fp) + if (isEdgeOfFaceCut(pVals, f, ownLower, ownLower)) { - bool fpLower = (pVals[f[fp]] < iso_); - if - ( - (fpLower != (pVals[f[f.fcIndex(fp)]] < iso_)) - || (fpLower != ownLower) - ) - { - faceCutType_[faceI] = CUT; - break; - } + faceCutType_[faceI] = CUT; } + faceI++; } } @@ -152,19 +159,9 @@ void Foam::isoSurface::calcCutTypes // Mesh edge. const face f = mesh_.faces()[faceI]; - forAll(f, fp) + if (isEdgeOfFaceCut(pVals, f, ownLower, neiLower)) { - bool fpLower = (pVals[f[fp]] < iso_); - if - ( - (fpLower != (pVals[f[f.fcIndex(fp)]] < iso_)) - || (fpLower != ownLower) - || (fpLower != neiLower) - ) - { - faceCutType_[faceI] = CUT; - break; - } + faceCutType_[faceI] = CUT; } } faceI++; @@ -1355,6 +1352,30 @@ Foam::isoSurface::isoSurface iso_(iso), mergeDistance_(mergeTol*mesh_.bounds().mag()) { + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + const labelList& own = mesh_.faceOwner(); + + // Check + forAll(patches, patchI) + { + if (isA(patches[patchI])) + { + FatalErrorIn + ( + "isoSurface::isoSurface\n" + "(\n" + " const volScalarField& cVals,\n" + " const scalarField& pVals,\n" + " const scalar iso,\n" + " const bool regularise,\n" + " const scalar mergeTol\n" + ")\n" + ) << "Iso surfaces not supported on case with empty patches." + << exit(FatalError); + } + } + + // Determine if any cut through face/cell calcCutTypes(cVals, pVals); @@ -1364,8 +1385,6 @@ Foam::isoSurface::isoSurface PackedList<1> isBoundaryPoint(mesh_.nPoints()); labelList boundaryRegion(mesh_.nFaces()-mesh_.nInternalFaces()); - const polyBoundaryMesh& patches = mesh_.boundaryMesh(); - const labelList& own = mesh_.faceOwner(); forAll(patches, patchI) { diff --git a/src/sampling/sampledSurface/isoSurface/isoSurface.H b/src/sampling/sampledSurface/isoSurface/isoSurface.H index 832773018e..abe3d51b56 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/isoSurface.H @@ -31,6 +31,9 @@ Description G.M. Treece, R.W. Prager and A.H. Gee. Note: + - not possible on patches of type 'empty'. There are no values on + 'empty' patch fields so even the api would have to change + (no volScalarField as argument). Too messy. - in parallel the regularisation (coarsening) always takes place and slightly different surfaces will be created compared to non-parallel. The surface will still be continuous though! @@ -123,6 +126,15 @@ class isoSurface const scalar s1 ) const; + //- Check if any edge of a face is cut + bool isEdgeOfFaceCut + ( + const scalarField& pVals, + const face& f, + const bool ownLower, + const bool neiLower + ) const; + //- Set faceCutType,cellCutType. void calcCutTypes ( @@ -217,7 +229,7 @@ class isoSurface ) const; template - label generateTriPoints + label generateFaceTriPoints ( const volScalarField& cVals, const scalarField& pVals, diff --git a/src/sampling/sampledSurface/isoSurface/isoSurfaceTemplates.C b/src/sampling/sampledSurface/isoSurface/isoSurfaceTemplates.C index ffff99f104..67d05a5a1c 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurfaceTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/isoSurfaceTemplates.C @@ -200,7 +200,7 @@ void Foam::isoSurface::generateTriPoints template -Foam::label Foam::isoSurface::generateTriPoints +Foam::label Foam::isoSurface::generateFaceTriPoints ( const volScalarField& cVals, const scalarField& pVals, @@ -288,6 +288,19 @@ void Foam::isoSurface::generateTriPoints const labelList& own = mesh_.faceOwner(); const labelList& nei = mesh_.faceNeighbour(); + if + ( + (cVals.size() != mesh_.nCells()) + || (pVals.size() != mesh_.nPoints()) + || (cCoords.size() != mesh_.nCells()) + || (pCoords.size() != mesh_.nPoints()) + || (snappedCc.size() != mesh_.nCells()) + || (snappedPoint.size() != mesh_.nPoints()) + ) + { + FatalErrorIn("isoSurface::generateTriPoints(..)") + << "Incorrect size." << abort(FatalError); + } // Determine neighbouring snap status labelList neiSnappedCc(mesh_.nFaces()-mesh_.nInternalFaces(), -1); @@ -319,7 +332,7 @@ void Foam::isoSurface::generateTriPoints { if (faceCutType_[faceI] != NOTCUT) { - generateTriPoints + generateFaceTriPoints ( cVals, pVals, @@ -357,7 +370,7 @@ void Foam::isoSurface::generateTriPoints { if (faceCutType_[faceI] != NOTCUT) { - generateTriPoints + generateFaceTriPoints ( cVals, pVals, @@ -384,14 +397,14 @@ void Foam::isoSurface::generateTriPoints } else if (isA(pp)) { - // Assume zero-gradient. + // Assume zero-gradient. But what about coordinates? label faceI = pp.start(); forAll(pp, i) { if (faceCutType_[faceI] != NOTCUT) { - generateTriPoints + generateFaceTriPoints ( cVals, pVals, @@ -423,7 +436,7 @@ void Foam::isoSurface::generateTriPoints { if (faceCutType_[faceI] != NOTCUT) { - generateTriPoints + generateFaceTriPoints ( cVals, pVals, From ba6f878f6bbb0f4859aa152cdbfecce9caddf75f Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 19 Jan 2009 12:46:00 +0000 Subject: [PATCH 4/6] added copy constructor since List copy constructor does not know about allocated size --- .../containers/Lists/DynamicList/DynamicList.H | 6 ++++++ .../containers/Lists/DynamicList/DynamicListI.H | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index dbbcb82b80..d6553dcfab 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -101,6 +101,12 @@ public: //- Construct given size. explicit inline DynamicList(const label); + //- Construct copy. + explicit inline DynamicList + ( + const DynamicList& + ); + //- Construct from UList. Size set to UList size. explicit inline DynamicList(const UList&); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 62301bb123..f1e7d40dd6 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -49,6 +49,17 @@ inline Foam::DynamicList::DynamicList } +template +inline Foam::DynamicList::DynamicList +( + const DynamicList& lst +) +: + List(lst), + capacity_(lst.size()) +{} + + template inline Foam::DynamicList::DynamicList ( From fc2d438c973bc954d0ad307a8ebfd1a566300f6e Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 19 Jan 2009 18:13:10 +0000 Subject: [PATCH 5/6] parallel operation --- .../sets/cellSources/nbrToCell/nbrToCell.C | 38 +++++++-- .../sets/cellSources/nbrToCell/nbrToCell.H | 2 +- .../sets/faceSources/cellToFace/cellToFace.C | 81 ++++++++++--------- .../sets/faceSources/cellToFace/cellToFace.H | 1 + 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.C b/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.C index 5b1ae0ae69..208a913f5d 100644 --- a/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.C +++ b/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.C @@ -22,8 +22,6 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ #include "nbrToCell.H" @@ -58,22 +56,46 @@ Foam::topoSetSource::addToUsageTable Foam::nbrToCell::usage_ void Foam::nbrToCell::combine(topoSet& set, const bool add) const { const cellList& cells = mesh().cells(); + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + + boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false); + + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + if (pp.coupled()) + { + label faceI = pp.start(); + forAll(pp, i) + { + isCoupled[faceI-mesh_.nInternalFaces()] = true; + faceI++; + } + } + } forAll(cells, cellI) { - const cell& cll = cells[cellI]; + const cell& cFaces = cells[cellI]; - label nInternalFaces = 0; + label nNbrCells = 0; - forAll(cll, i) + forAll(cFaces, i) { - if (mesh().isInternalFace(cll[i])) + label faceI = cFaces[i]; + + if (mesh_.isInternalFace(faceI)) { - nInternalFaces++; + nNbrCells++; + } + else if (isCoupled[faceI-mesh_.nInternalFaces()]) + { + nNbrCells++; } } - if (nInternalFaces <= minNbrs_) + if (nNbrCells <= minNbrs_) { addOrDelete(set, cellI, add); } diff --git a/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.H b/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.H index a30a48ebde..708c38c11e 100644 --- a/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.H +++ b/src/meshTools/sets/cellSources/nbrToCell/nbrToCell.H @@ -27,7 +27,7 @@ Class Description A topoSetSource to select cells based on number of neighbouring cells - (i.e. number of internal faces) + (i.e. number of internal or coupled faces) SourceFiles nbrToCell.C diff --git a/src/meshTools/sets/faceSources/cellToFace/cellToFace.C b/src/meshTools/sets/faceSources/cellToFace/cellToFace.C index ae75c3d207..59d3e2e9eb 100644 --- a/src/meshTools/sets/faceSources/cellToFace/cellToFace.C +++ b/src/meshTools/sets/faceSources/cellToFace/cellToFace.C @@ -22,14 +22,13 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ #include "cellToFace.H" #include "polyMesh.H" #include "cellSet.H" #include "Time.H" +#include "syncTools.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -102,48 +101,58 @@ void Foam::cellToFace::combine(topoSet& set, const bool add) const { // Add all faces whose both neighbours are in set. - // Count number of cells using face. - Map