From 0d8fff3a5f31df3e1f7ab91d0652cda3a04dbf32 Mon Sep 17 00:00:00 2001 From: mattijs Date: Sat, 17 Aug 2013 05:28:31 +0100 Subject: [PATCH 1/4] ENH: codeStream: function in dictionary context --- .../functionEntries/codeStream/codeStream.C | 40 +++++++++++++++++++ .../functionEntries/codeStream/codeStream.H | 6 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 66065c4528..1c774c352b 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -39,6 +39,14 @@ namespace functionEntries { defineTypeNameAndDebug(codeStream, 0); + addToMemberFunctionSelectionTable + ( + functionEntry, + codeStream, + execute, + dictionaryIstream + ); + addToMemberFunctionSelectionTable ( functionEntry, @@ -364,6 +372,38 @@ bool Foam::functionEntries::codeStream::execute IStringStream resultStream(os.str()); entry.read(parentDict, resultStream); + return true; +} + + +bool Foam::functionEntries::codeStream::execute +( + dictionary& parentDict, + Istream& is +) +{ + Info<< "Using #codeStream at line " << is.lineNumber() + << " in file " << parentDict.name() << endl; + + dynamicCode::checkSecurity + ( + "functionEntries::codeStream::execute(..)", + parentDict + ); + + // get code dictionary + // must reference parent for stringOps::expand to work nicely + dictionary codeDict("#codeStream", parentDict, is); + + streamingFunctionType function = getFunction(parentDict, codeDict); + + // use function to write stream + OStringStream os(is.format()); + (*function)(os, parentDict); + + // get the entry from this stream + IStringStream resultStream(os.str()); + parentDict.read(resultStream); return true; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index b8baa0183c..1dc2b57c87 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -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 @@ -160,6 +160,10 @@ public: // Member Functions + //- Execute the functionEntry in a sub-dict context + static bool execute(dictionary& parentDict, Istream&); + + //- Execute the functionEntry in a primitiveEntry context static bool execute ( const dictionary& parentDict, From 331368b308b007d584ec564f4426564fa51187b2 Mon Sep 17 00:00:00 2001 From: mattijs Date: Sat, 17 Aug 2013 05:36:14 +0100 Subject: [PATCH 2/4] STYLE: topoSet: unused code --- src/meshTools/sets/topoSets/topoSet.C | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/meshTools/sets/topoSets/topoSet.C b/src/meshTools/sets/topoSets/topoSet.C index 37fe9a0595..691339102a 100644 --- a/src/meshTools/sets/topoSets/topoSet.C +++ b/src/meshTools/sets/topoSets/topoSet.C @@ -472,7 +472,6 @@ void Foam::topoSet::invert(const label maxLen) insert(cellI); } } - } @@ -550,20 +549,6 @@ void Foam::topoSet::writeDebug(Ostream& os, const label maxLen) const } -//void Foam::topoSet::writeDebug -//( -// Ostream&, -// const primitiveMesh&, -// const label -//) const -//{ -// notImplemented -// ( -// "topoSet::writeDebug(Ostream&, const primitiveMesh&, const label)" -// ); -//} - - bool Foam::topoSet::writeData(Ostream& os) const { return (os << *this).good(); @@ -576,14 +561,6 @@ void Foam::topoSet::updateMesh(const mapPolyMesh&) } -////- Return max index+1. -//label topoSet::maxSize(const polyMesh&) const -//{ -// notImplemented("topoSet::maxSize(const polyMesh&)"); -// -// return -1; -//} - // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // void Foam::topoSet::operator=(const topoSet& rhs) From 77d47e9125037430ca82873b3896d07897ee2120 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 20 Aug 2013 16:01:18 +0100 Subject: [PATCH 3/4] ENH: surfaceToCell: use surface orientation --- .../advanced/autoRefineMesh/autoRefineMesh.C | 7 +-- .../mesh/manipulation/topoSet/topoSetDict | 3 ++ .../cellSources/surfaceToCell/surfaceToCell.C | 52 +++++++++++++++++-- .../cellSources/surfaceToCell/surfaceToCell.H | 26 ++++++---- 4 files changed, 72 insertions(+), 16 deletions(-) diff --git a/applications/utilities/mesh/advanced/autoRefineMesh/autoRefineMesh.C b/applications/utilities/mesh/advanced/autoRefineMesh/autoRefineMesh.C index 44a02e234a..2a958b3a3c 100644 --- a/applications/utilities/mesh/advanced/autoRefineMesh/autoRefineMesh.C +++ b/applications/utilities/mesh/advanced/autoRefineMesh/autoRefineMesh.C @@ -269,9 +269,10 @@ void selectCurvatureCells querySurf.surface(), querySurf, pointField(1, mesh.cellCentres()[0]), - false, - false, - false, + false, // includeCut + false, // includeInside + false, // includeOutside + false, // geometricOnly nearDist, curvature ); diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index 11dccf942b..9dee4d1df9 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -143,6 +143,9 @@ FoamFile // sourceInfo // { // file "www.avl.com-geometry.stl"; +// useSurfaceOrientation false; // use closed surface inside/outside +// // test (ignores includeCut, +// // outsidePoints) // outsidePoints ((-99 -99 -59)); // definition of outside // includeCut false; // cells cut by surface // includeInside false; // cells not on outside of surf diff --git a/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.C b/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.C index ff37610fad..f4a0009028 100644 --- a/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.C +++ b/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.C @@ -157,7 +157,30 @@ void Foam::surfaceToCell::combine(topoSet& set, const bool add) const { cpuTime timer; - if (includeCut_ || includeInside_ || includeOutside_) + + if (useSurfaceOrientation_ && (includeInside_ || includeOutside_)) + { + const meshSearch queryMesh(mesh_); + + //- Calculate for each searchPoint inside/outside status. + boolList isInside(querySurf().calcInside(mesh_.cellCentres())); + + Info<< " Marked inside/outside using surface orientation in = " + << timer.cpuTimeIncrement() << " s" << endl << endl; + + forAll(isInside, cellI) + { + if (isInside[cellI] && includeInside_) + { + addOrDelete(set, cellI, add); + } + else if (!isInside[cellI] && includeOutside_) + { + addOrDelete(set, cellI, add); + } + } + } + else if (includeCut_ || includeInside_ || includeOutside_) { // // Cut cells with surface and classify cells @@ -166,7 +189,7 @@ void Foam::surfaceToCell::combine(topoSet& set, const bool add) const // Construct search engine on mesh - meshSearch queryMesh(mesh_); + const meshSearch queryMesh(mesh_); // Check all 'outside' points @@ -196,10 +219,10 @@ void Foam::surfaceToCell::combine(topoSet& set, const bool add) const ); - Info<< " Marked inside/outside in = " + Info<< " Marked inside/outside using surface intersection in = " << timer.cpuTimeIncrement() << " s" << endl << endl; - + //- Add/remove cells using set forAll(cellType, cellI) { label cType = cellType[cellI]; @@ -326,6 +349,18 @@ void Foam::surfaceToCell::checkSettings() const << " or set curvature to a value -1 .. 1." << exit(FatalError); } + + if (useSurfaceOrientation_ && includeCut_) + { + FatalErrorIn + ( + "surfaceToCell:checkSettings()" + ) << "Illegal include cell specification." + << " You cannot specify both 'useSurfaceOrientation'" + << " and 'includeCut'" + << " since 'includeCut' specifies a topological split" + << exit(FatalError); + } } @@ -340,6 +375,7 @@ Foam::surfaceToCell::surfaceToCell const bool includeCut, const bool includeInside, const bool includeOutside, + const bool useSurfaceOrientation, const scalar nearDist, const scalar curvature ) @@ -350,6 +386,7 @@ Foam::surfaceToCell::surfaceToCell includeCut_(includeCut), includeInside_(includeInside), includeOutside_(includeOutside), + useSurfaceOrientation_(useSurfaceOrientation), nearDist_(nearDist), curvature_(curvature), surfPtr_(new triSurface(surfName_)), @@ -371,6 +408,7 @@ Foam::surfaceToCell::surfaceToCell const bool includeCut, const bool includeInside, const bool includeOutside, + const bool useSurfaceOrientation, const scalar nearDist, const scalar curvature ) @@ -381,6 +419,7 @@ Foam::surfaceToCell::surfaceToCell includeCut_(includeCut), includeInside_(includeInside), includeOutside_(includeOutside), + useSurfaceOrientation_(useSurfaceOrientation), nearDist_(nearDist), curvature_(curvature), surfPtr_(&surf), @@ -404,6 +443,10 @@ Foam::surfaceToCell::surfaceToCell includeCut_(readBool(dict.lookup("includeCut"))), includeInside_(readBool(dict.lookup("includeInside"))), includeOutside_(readBool(dict.lookup("includeOutside"))), + useSurfaceOrientation_ + ( + dict.lookupOrDefault("useSurfaceOrientation", false) + ), nearDist_(readScalar(dict.lookup("nearDistance"))), curvature_(readScalar(dict.lookup("curvature"))), surfPtr_(new triSurface(surfName_)), @@ -427,6 +470,7 @@ Foam::surfaceToCell::surfaceToCell includeCut_(readBool(checkIs(is))), includeInside_(readBool(checkIs(is))), includeOutside_(readBool(checkIs(is))), + useSurfaceOrientation_(false), nearDist_(readScalar(checkIs(is))), curvature_(readScalar(checkIs(is))), surfPtr_(new triSurface(surfName_)), diff --git a/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.H b/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.H index cfaf80dd30..931f412a2a 100644 --- a/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.H +++ b/src/meshTools/sets/cellSources/surfaceToCell/surfaceToCell.H @@ -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 @@ -29,6 +29,8 @@ Description Selects: - all cells inside/outside/cut by surface + - all cells inside/outside surface ('useSurfaceOrientation', requires closed + surface) - cells with centre nearer than XXX to surface - cells with centre nearer than XXX to surface \b and with normal at nearest point to centre and cell-corners differing by @@ -67,27 +69,31 @@ class surfaceToCell static addToUsageTable usage_; //- Name of surface file - fileName surfName_; + const fileName surfName_; //- Points which are outside - pointField outsidePoints_; + const pointField outsidePoints_; //- Include cut cells - bool includeCut_; + const bool includeCut_; //- Include inside cells - bool includeInside_; + const bool includeInside_; //- Include outside cells - bool includeOutside_; + const bool includeOutside_; + + //- Determine inside/outside purely using geometric test + // (does not allow includeCut) + const bool useSurfaceOrientation_; //- if > 0 : include cells with distance from cellCentre to surface // less than nearDist. - scalar nearDist_; + const scalar nearDist_; //- if > -1 : include cells with normals at nearest surface points // varying more than curvature_. - scalar curvature_; + const scalar curvature_; //- triSurface to search on. On pointer since can be external. const triSurface* surfPtr_; @@ -97,7 +103,7 @@ class surfaceToCell //- whether I allocated above surface ptrs or whether they are // external. - bool IOwnPtrs_; + const bool IOwnPtrs_; // Private Member Functions @@ -155,6 +161,7 @@ public: const bool includeCut, const bool includeInside, const bool includeOutside, + const bool useSurfaceOrientation, const scalar nearDist, const scalar curvature ); @@ -170,6 +177,7 @@ public: const bool includeCut, const bool includeInside, const bool includeOutside, + const bool useSurfaceOrientation, const scalar nearDist, const scalar curvature ); From 491e4821d03a9e8f6dfa377b09a219c900854b43 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 2 Sep 2013 11:12:17 +0100 Subject: [PATCH 4/4] ENH: plane sampling: make triangulation optional --- .../postProcessing/sampling/sample/sampleDict | 4 ++++ .../sampledSurface/sampledPlane/sampledPlane.C | 10 +++++++--- .../sampledSurface/sampledPlane/sampledPlane.H | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 86ba1b4849..60e1d7d0ee 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -165,6 +165,10 @@ surfaces //- Optional: restrict to a particular zone // zone zone1; + + //- Optional: do not triangulate (only for surfaceFormats that support + // polygons) + //triangulate false; } interpolatedPlane diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 3873962cca..87167b572c 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -45,12 +45,14 @@ Foam::sampledPlane::sampledPlane const word& name, const polyMesh& mesh, const plane& planeDesc, - const keyType& zoneKey + const keyType& zoneKey, + const bool triangulate ) : sampledSurface(name, mesh), cuttingPlane(planeDesc), zoneKey_(zoneKey), + triangulate_(triangulate), needsUpdate_(true) { if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0) @@ -71,6 +73,7 @@ Foam::sampledPlane::sampledPlane sampledSurface(name, mesh, dict), cuttingPlane(plane(dict.lookup("basePoint"), dict.lookup("normalVector"))), zoneKey_(keyType::null), + triangulate_(dict.lookupOrDefault("triangulate", true)), needsUpdate_(true) { // make plane relative to the coordinateSystem (Cartesian) @@ -138,11 +141,11 @@ bool Foam::sampledPlane::update() if (selectedCells.empty()) { - reCut(mesh(), true); // always triangulate. Note:Make option? + reCut(mesh(), triangulate_); } else { - reCut(mesh(), true, selectedCells); + reCut(mesh(), triangulate_, selectedCells); } if (debug) @@ -250,6 +253,7 @@ void Foam::sampledPlane::print(Ostream& os) const os << "sampledPlane: " << name() << " :" << " base:" << refPoint() << " normal:" << normal() + << " triangulate:" << triangulate_ << " faces:" << faces().size() << " points:" << points().size(); } diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H index 1c6a1b8058..3b24a09e52 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H @@ -25,7 +25,7 @@ Class Foam::sampledPlane Description - A sampledSurface defined by a cuttingPlane. Always triangulated. + A sampledSurface defined by a cuttingPlane. Triangulated by default. Note Does not actually cut until update() called. @@ -60,6 +60,9 @@ class sampledPlane //- If restricted to zones, name of this zone or a regular expression keyType zoneKey_; + //- Triangulated faces or keep faces as is + const bool triangulate_; + //- Track if the surface needs an update mutable bool needsUpdate_; @@ -92,7 +95,8 @@ public: const word& name, const polyMesh& mesh, const plane& planeDesc, - const keyType& zoneKey = word::null + const keyType& zoneKey = word::null, + const bool triangulate = true ); //- Construct from dictionary