From cee6887d68e1c74a1cdd69eaf3f8ec72af8dd778 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 26 Nov 2015 10:41:34 +0000 Subject: [PATCH] ENH: sampledSurfaces: added 'bounds' option - bounds option (see $FOAM_UTILITIES/postProcessing/sampling/sample/sampleDict) - fixes memory error http://www.openfoam.org/mantisbt/view.php?id=1487 - cleans up iso surface normal orientation --- .../postProcessing/sampling/sample/sampleDict | 85 +- .../primitiveShapes/triangle/triangle.C | 242 +++ .../primitiveShapes/triangle/triangle.H | 122 +- .../primitiveShapes/triangle/triangleI.H | 75 +- .../planeExtrusion/planeExtrusion.H | 4 +- .../sampledSet/patchSeed/patchSeedSet.C | 158 +- .../sampledSet/patchSeed/patchSeedSet.H | 13 +- .../distanceSurface/distanceSurface.C | 13 +- .../distanceSurface/distanceSurface.H | 6 +- .../sampledSurface/isoSurface/isoSurface.C | 1561 ++++++++++------- .../sampledSurface/isoSurface/isoSurface.H | 130 +- .../isoSurface/isoSurfaceCell.C | 279 +-- .../isoSurface/isoSurfaceCell.H | 62 +- .../isoSurface/isoSurfaceCellTemplates.C | 354 ++-- .../isoSurface/isoSurfaceTemplates.C | 320 ++-- .../isoSurface/sampledIsoSurface.C | 125 +- .../isoSurface/sampledIsoSurface.H | 5 +- .../isoSurface/sampledIsoSurfaceCell.C | 10 +- .../isoSurface/sampledIsoSurfaceCell.H | 3 + .../sampledCuttingPlane/sampledCuttingPlane.C | 4 +- .../sampledCuttingPlane/sampledCuttingPlane.H | 3 + .../sampledPatch/sampledPatch.C | 8 +- .../sampledSurfaces/sampledSurfaces.C | 18 +- .../sampledTriSurfaceMesh.C | 19 +- 24 files changed, 2249 insertions(+), 1370 deletions(-) create mode 100644 src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.C diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 92b1c02e35..88c86bf482 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -31,18 +31,66 @@ setFormat raw; // dx : DX scalar or vector format // vtk : VTK ascii format // raw : x y z value format for use with e.g. gnuplot 'splot'. +// boundaryData: written in a form that can be used with timeVaryingMapped +// boundary conditions (move to constant/boundaryData) +// starcd : Star-CD format (geometry in .cel/.vrt, data in .usr) +// nastran : Nastran (.nas) format // // Note: -// other formats such as obj, stl, etc can also be written (by proxy) -// but without any values! +// - other formats such as obj, stl, etc can also be written (by proxy) +// but without any values! +// - boundaryData format: typical use: +// - use a surfaces functionObject to sample a patch: +// type surfaces; +// surfaceFormat boundaryData; +// fields ( p ); +// surfaces +// ( +// inlet +// { +// type patch; +// patches (inpletPatch); +// interpolate false; +// } +// ); +// - the boundaryData writer will write postProcessing/surfaces/inlet/ +// - move this to constant/boundaryData/inlet of the destination case +// - use a timeVaryingMappedFixedValue bc to read&interpolate and use +// as fixedValue. +// - boundaryData: 'interpolate false' writes face centres, 'interpolate true' +// writes points. For 2D case the face centres might only be a single column +// so cannot be used in timeVaryingMapped with standard mapping (since +// uses triangulation to do interpolation). + surfaceFormat vtk; -// optionally define extra controls for the output formats +// Optionally define extra controls for the output formats formatOptions { ensight { + // ascii/binary format format ascii; + //collateTimes true; // write single file containing multiple timesteps + // (only for static surfaces) + } + nastran + { + // From OpenFOAM field name to Nastran field name + fields + ( + (U PLOAD4) + (p PLOAD2) + ); + // Optional scale + scale 1.0; + // Optional format + // short/long/free format + // short: scalar field width 8. default. + // long : scalar field width 16 + // free : comma separated, field width according to writePrecision + // setting + format short; // short/long/free } } @@ -143,9 +191,19 @@ sets type patchSeed; axis xyz; patches (".*Wall.*"); - // Number of points to seed. Divided amongst all processors according - // to fraction of patches they hold. + + // Subset patch faces by: + + // 1. Number of points to seed. Divided amongst all processors + // according to fraction of patches they hold. maxPoints 100; + + // 2. Specified set of locations. This selects for every the specified + // point the nearest patch face. (in addition the number of points + // is also truncated by the maxPoints setting) + // The difference with patchCloud is that this selects patch + // face centres, not an arbitrary location on the face. + points ((0.049 0.099 0.005)(0.051 0.054 0.005)); } ); @@ -249,8 +307,10 @@ surfaces isoValue 0.5; interpolate true; - //zone ABC; // Optional: zone only - //exposedPatchName fixedWalls; // Optional: zone only + // zone ABC; // Optional: zone only + // exposedPatchName fixedWalls; // Optional: zone only + + // bounds (1 1 1)(2 2 2); // Optional: limit extent // regularise false; // Optional: do not simplify // mergeTol 1e-10; // Optional: fraction of mesh bounding box @@ -265,6 +325,9 @@ surfaces isoValue 0.5; interpolate false; regularise false; // do not simplify + + // bounds (1 1 1)(2 2 2); // Optional: limit extent + // mergeTol 1e-10; // Optional: fraction of mesh bounding box // to merge points (default=1e-6) } @@ -281,8 +344,10 @@ surfaces } interpolate true; - //zone ABC; // Optional: zone only - //exposedPatchName fixedWalls; // Optional: zone only + // zone ABC; // Optional: zone only + // exposedPatchName fixedWalls; // Optional: zone only + + // bounds (1 1 1)(2 2 2); // Optional: limit extent // regularise false; // Optional: do not simplify // mergeTol 1e-10; // Optional: fraction of mesh bounding box @@ -305,6 +370,8 @@ surfaces // of isoSurfaceCell interpolate false; regularise false; // Optional: do not simplify + // bounds (1 1 1)(2 2 2); // Optional: limit extent + // mergeTol 1e-10; // Optional: fraction of mesh bounding box // to merge points (default=1e-6) } diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.C b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.C new file mode 100644 index 0000000000..8085ccd8f0 --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.C @@ -0,0 +1,242 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "triangle.H" +#include "triPoints.H" +#include "plane.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +template +inline void Foam::triangle::triSliceWithPlane +( + const plane& pl, + const triPoints& tri, + AboveOp& aboveOp, + BelowOp& belowOp +) +{ + // distance to cutting plane + FixedList d; + + // determine how many of the points are above the cutting plane + label nPos = 0; + label posI = -1; + label negI = -1; + forAll(tri, i) + { + d[i] = ((tri[i] - pl.refPoint()) & pl.normal()); + + if (d[i] > 0) + { + nPos++; + posI = i; + } + else + { + negI = i; + } + } + + if (nPos == 3) + { + aboveOp(tri); + } + else if (nPos == 2) + { + // point under the plane + label i0 = negI; + + // indices of remaining points + label i1 = d.fcIndex(i0); + label i2 = d.fcIndex(i1); + + // determine the two intersection points + point p01 = planeIntersection(d, tri, i0, i1); + point p02 = planeIntersection(d, tri, i0, i2); + + aboveOp(triPoints(tri[i1], tri[i2], p02)); + aboveOp(triPoints(tri[i1], p02, p01)); + belowOp(triPoints(tri[i0], p01, p02)); + } + else if (nPos == 1) + { + // point above the plane + label i0 = posI; + + // indices of remaining points + label i1 = d.fcIndex(i0); + label i2 = d.fcIndex(i1); + + // determine the two intersection points + point p01 = planeIntersection(d, tri, i0, i1); + point p02 = planeIntersection(d, tri, i0, i2); + + belowOp(triPoints(tri[i1], tri[i2], p02)); + belowOp(triPoints(tri[i1], p02, p01)); + aboveOp(triPoints(tri[i0], p01, p02)); + } + else + { + // All below + belowOp(tri); + } +} + + +template +template +inline void Foam::triangle::sliceWithPlane +( + const plane& pl, + AboveOp& aboveOp, + BelowOp& belowOp +) const +{ + triSliceWithPlane(pl, triPoints(a_, b_, c_), aboveOp, belowOp); +} + + +template +template +inline void Foam::triangle::triangleOverlap +( + const vector& n, + const triangle& tgt, + InsideOp& insideOp, + OutsideOp& outsideOp +) const +{ + // There are two possibilities with this algorithm - we either cut + // the outside triangles with all the edges or not (and keep them + // as disconnected triangles). In the first case + // we cannot do any evaluation short cut so we've chosen not to re-cut + // the outside triangles. + + + triIntersectionList insideTrisA; + label nInsideA = 0; + storeOp insideOpA(insideTrisA, nInsideA); + + triIntersectionList outsideTrisA; + label nOutsideA = 0; + storeOp outsideOpA(outsideTrisA, nOutsideA); + + + const triPoints thisTri(a_, b_, c_); + + + // Cut original triangle with tgt edge 0. + // From *this to insideTrisA, outsideTrisA. + { + scalar s = Foam::mag(tgt.b() - tgt.a()); + const plane pl0(tgt.a(), tgt.b(), tgt.b() + s*n); + triSliceWithPlane(pl0, thisTri, insideOpA, outsideOpA); + } + + // Shortcut if nothing cut + + if (insideOpA.nTris_ == 0) + { + outsideOp(thisTri); + return; + } + + if (outsideOpA.nTris_ == 0) + { + insideOp(thisTri); + return; + } + + + // Cut all triangles with edge 1. + // From insideTrisA to insideTrisB, outsideTrisA + + triIntersectionList insideTrisB; + label nInsideB = 0; + storeOp insideOpB(insideTrisB, nInsideB); + + //triIntersectionList outsideTrisB; + //label nOutsideB = 0; + //storeOp outsideOpB(outsideTrisB, nOutsideB); + + { + scalar s = Foam::mag(tgt.c() - tgt.b()); + const plane pl0(tgt.b(), tgt.c(), tgt.c() + s*n); + + for (label i = 0; i < insideOpA.nTris_; i++) + { + const triPoints& tri = insideOpA.tris_[i]; + triSliceWithPlane(pl0, tri, insideOpB, outsideOpA); + } + + //// Recut outside triangles (not necessary if only interested in + //// intersection properties) + //for (label i = 0; i < outsideOpA.nTris_; i++) + //{ + // const triPoints& tri = outsideOpA.tris_[i]; + // triSliceWithPlane(pl0, tri, outsideOpB, outsideOpB); + //} + } + + + // Cut all triangles with edge 2. + // From insideTrisB to insideTrisA, outsideTrisA + { + scalar s = Foam::mag(tgt.a() - tgt.c()); + const plane pl0(tgt.c(), tgt.a(), tgt.a() + s*n); + + insideOpA.nTris_ = 0; + //outsideOpA.nTris_ = 0; + for (label i = 0; i < insideOpB.nTris_; i++) + { + const triPoints& tri = insideOpB.tris_[i]; + triSliceWithPlane(pl0, tri, insideOpA, outsideOpA); + } + + //// Recut outside triangles (not necessary if only interested in + //// intersection properties) + //for (label i = 0; i < outsideOpB.nTris_; i++) + //{ + // const triPoints& tri = outsideOpB.tris_[i]; + // triSliceWithPlane(pl0, tri, outsideOpA, outsideOpA); + //} + } + + // Transfer from A to argument + for (label i = 0; i < insideOpA.nTris_; i++) + { + insideOp(insideOpA.tris_[i]); + } + + for (label i = 0; i < outsideOpA.nTris_; i++) + { + outsideOp(outsideOpA.tris_[i]); + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H index 6e8030c797..de477d20e0 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,6 +52,8 @@ namespace Foam class Istream; class Ostream; +class triPoints; +class plane; // Forward declaration of friend functions and operators @@ -71,6 +73,8 @@ inline Ostream& operator<< const triangle& ); +typedef triangle triPointRef; + /*---------------------------------------------------------------------------*\ Class triangle Declaration @@ -79,27 +83,98 @@ inline Ostream& operator<< template class triangle { +public: + + // Public typedefs + + //- Storage type for triangles originating from intersecting triangle + // with another triangle + typedef FixedList triIntersectionList; + + //- Return types for classify + enum proxType + { + NONE, + POINT, // Close to point + EDGE // Close to edge + }; + + + // Public classes + + // Classes for use in sliceWithPlane. What to do with decomposition + // of triangle. + + //- Dummy + class dummyOp + { + public: + inline void operator()(const triPoints&); + }; + + //- Sum resulting areas + class sumAreaOp + { + public: + scalar area_; + + inline sumAreaOp(); + + inline void operator()(const triPoints&); + }; + + //- Store resulting tris + class storeOp + { + public: + triIntersectionList& tris_; + label& nTris_; + + inline storeOp(triIntersectionList&, label&); + + inline void operator()(const triPoints&); + }; + + +private: + // Private data PointRef a_, b_, c_; + // Private Member Functions + + //- Helper: calculate intersection point + inline static point planeIntersection + ( + const FixedList& d, + const triPoints& t, + const label negI, + const label posI + ); + + //- Helper: slice triangle with plane + template + inline static void triSliceWithPlane + ( + const plane& pl, + const triPoints& tri, + AboveOp& aboveOp, + BelowOp& belowOp + ); + + public: - //- Return types for classify - enum proxType - { - NONE, - POINT, // Close to point - EDGE // Close to edge - }; - - // Constructors //- Construct from three points inline triangle(const Point& a, const Point& b, const Point& c); + //- Construct from three points + inline triangle(const FixedList&); + //- Construct from three points in the list of points // The indices could be from triFace etc. inline triangle @@ -237,6 +312,27 @@ public: pointHit& edgePoint ) const; + //- Decompose triangle into triangles above and below plane + template + inline void sliceWithPlane + ( + const plane& pl, + AboveOp& aboveOp, + BelowOp& belowOp + ) const; + + //- Decompose triangle into triangles inside and outside + // (with respect to user provided normal) other + // triangle. + template + inline void triangleOverlap + ( + const vector& n, + const triangle& tri, + InsideOp& insideOp, + OutsideOp& outsideOp + ) const; + // IOstream operators @@ -264,6 +360,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository +# include "triangle.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H index fbc5a14286..e3f8993e2e 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ License #include "IOstreams.H" #include "pointHit.H" +#include "triPoints.H" #include "mathematicalConstants.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -43,6 +44,18 @@ inline Foam::triangle::triangle {} +template +inline Foam::triangle::triangle +( + const FixedList& tri +) +: + a_(tri[0]), + b_(tri[1]), + c_(tri[2]) +{} + + template inline Foam::triangle::triangle ( @@ -804,6 +817,66 @@ inline Foam::pointHit Foam::triangle::nearestPoint } +template +inline void Foam::triangle::dummyOp::operator() +( + const triPoints& +) +{} + + +template +inline Foam::triangle::sumAreaOp::sumAreaOp() +: + area_(0.0) +{} + + +template +inline void Foam::triangle::sumAreaOp::operator() +( + const triPoints& tri +) +{ + area_ += triangle(tri).mag(); +} + + +template +inline Foam::triangle::storeOp::storeOp +( + triIntersectionList& tris, + label& nTris +) +: + tris_(tris), + nTris_(nTris) +{} + + +template +inline void Foam::triangle::storeOp::operator() +( + const triPoints& tri +) +{ + tris_[nTris_++] = tri; +} + + +template +inline Foam::point Foam::triangle::planeIntersection +( + const FixedList& d, + const triPoints& t, + const label negI, + const label posI +) +{ + return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI] + d[posI]); +} + + // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template diff --git a/src/mesh/extrudeModel/planeExtrusion/planeExtrusion.H b/src/mesh/extrudeModel/planeExtrusion/planeExtrusion.H index 9fea06cf2c..b832f7e2be 100644 --- a/src/mesh/extrudeModel/planeExtrusion/planeExtrusion.H +++ b/src/mesh/extrudeModel/planeExtrusion/planeExtrusion.H @@ -33,8 +33,8 @@ SeeAlso \*---------------------------------------------------------------------------*/ -#ifndef plane_H -#define plane_H +#ifndef planeExtrusion_H +#define planeExtrusion_H #include "linearNormal.H" diff --git a/src/sampling/sampledSet/patchSeed/patchSeedSet.C b/src/sampling/sampledSet/patchSeed/patchSeedSet.C index 3560fe4204..9cdcc7d230 100644 --- a/src/sampling/sampledSet/patchSeed/patchSeedSet.C +++ b/src/sampling/sampledSet/patchSeed/patchSeedSet.C @@ -30,9 +30,8 @@ License #include "treeDataFace.H" #include "Time.H" #include "meshTools.H" -//#include "Random.H" -// For 'facePoint' helper function only #include "mappedPatchBase.H" +#include "indirectPrimitivePatch.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -85,19 +84,145 @@ void Foam::patchSeedSet::calcSamples } - label totalSize = returnReduce(sz, sumOp