diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/Make/options b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/Make/options index 921245b6a9a5d547d82e31d4d70c44fa218cdc7f..8ff7c976e8f78e3d244876b78023e8a04382afb4 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/Make/options +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/Make/options @@ -16,6 +16,7 @@ EXE_INC = \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude \ -I../vectorTools EXE_LIBS = \ @@ -25,4 +26,5 @@ EXE_LIBS = \ -ldecompose \ -lmeshTools \ -ldynamicMesh \ + -lsampling \ -lfiniteVolume diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 111ef191ccf9afc6ae9e8aff1aada58598aea41f..5e562a7f246221924a33278c1db76a261641de41 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -311,7 +311,7 @@ tmp<scalarField> signedDistance ) { tmp<scalarField> tfld(new scalarField(points.size(), Foam::sqr(GREAT))); - scalarField& fld = tfld(); + scalarField& fld = tfld.ref(); // Find nearest List<pointIndexHit> nearest; @@ -713,8 +713,7 @@ int main(int argc, char *argv[]) fvm, cellDistance, pointDistance, - 0, //distance, - false //regularise + scalar(0) // distance ); isoFaces.setSize(iso.size()); diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 5a9670931bbd255f058315dc1695029dcf6ede93..b075b4c99b652b716dbec6b49ed6b13243115eb0 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -28,9 +28,10 @@ surface/cutting/cuttingSurfaceCuts.C surface/cutting/cuttingSurfaceBase.C surface/cutting/cuttingSurfaceBaseSelection.C surface/distanceSurface/distanceSurface.C -surface/isoSurface/isoSurface.C surface/isoSurface/isoSurfaceBase.C +surface/isoSurface/isoSurfaceParams.C surface/isoSurface/isoSurfaceCell.C +surface/isoSurface/isoSurface.C surface/isoSurface/isoSurfaceTopo.C surface/thresholdCellFaces/thresholdCellFaces.C diff --git a/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H index 56f84ca8bf5ab985541881f84038e9421638f23a..3d7c9b5f8c3c29471fe148ae504d79bddab05d8a 100644 --- a/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -50,7 +50,7 @@ Usage type | distanceSurface | yes | distance | Distance from surface | yes | signed | Use sign when distance is positive | partly | - isoAlgorithm | (cell/topo/point) | no | cell + isoMethod | Iso-algorithm (cell/topo/point) | no | cell regularise | Point snapping for iso-surface | no | true average | Cell values from averaged point values | no | false bounds | Limit with bounding box | no | @@ -58,9 +58,6 @@ Usage surfaceName | Name of surface in \c triSurface/ | no | dict name \endtable -Note - For compatibility, the keyword 'cell' (as a bool) is accepted - SourceFiles sampledDistanceSurface.C @@ -89,7 +86,7 @@ class sampledDistanceSurface // Private data //- Whether to recalculate cell values as average of point values - const bool average_; + bool average_; //- Track if the surface needs an update mutable bool needsUpdate_; diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index ba2c157ee734d0599d56f4d91ad061e070b9869b..901692e0226b41103f2b04bdf979ae976e16836c 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -370,9 +370,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const vfld, *pointSubFieldPtr_, isoVal_, - filter_, - bounds_, - mergeTol_ + isoParams_ ) ); } @@ -387,9 +385,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const vfld, *pointFieldPtr_, isoVal_, - filter_, - bounds_, - mergeTol_ + isoParams_ ) ); } @@ -399,14 +395,15 @@ bool Foam::sampledIsoSurface::updateGeometry() const { Pout<< "sampledIsoSurface::updateGeometry() : constructed iso:" << nl - << " filter : " << Switch(bool(filter_)) << nl - << " average : " << Switch(average_) << nl << " isoField : " << isoField_ << nl - << " isoValue : " << isoVal_ << nl; + << " isoValue : " << isoVal_ << nl + << " average : " << Switch(average_) << nl + << " filter : " + << Switch(bool(isoParams_.filter())) << nl; if (subMeshPtr_) { - Pout<< " zone size : " << subMeshPtr_->subMesh().nCells() - << nl; + Pout<< " zone size : " + << subMeshPtr_->subMesh().nCells() << nl; } Pout<< " points : " << points().size() << nl << " faces : " << surface().size() << nl @@ -430,17 +427,8 @@ Foam::sampledIsoSurface::sampledIsoSurface sampledSurface(name, mesh, dict), isoField_(dict.get<word>("isoField")), isoVal_(dict.get<scalar>("isoValue")), - mergeTol_(dict.getOrDefault<scalar>("mergeTol", 1e-6)), - filter_ - ( - isoSurfaceBase::getFilterType - ( - dict, - isoSurfaceBase::filterType::DIAGCELL - ) - ), + isoParams_(dict), average_(dict.getOrDefault("average", false)), - bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), zoneNames_(), exposedPatchName_(), surfPtr_(nullptr), @@ -449,6 +437,8 @@ Foam::sampledIsoSurface::sampledIsoSurface volFieldPtr_(nullptr), pointFieldPtr_(nullptr) { + isoParams_.algorithm(isoSurfaceParams::ALGO_POINT); // Force + if (!sampledSurface::interpolate()) { FatalIOErrorInFunction(dict) diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index c67ddc987f967788390a575bc212f711e74e0aaa..96ad8b2e27c81a14623e1be0d6470b0898e364e6 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -96,17 +96,11 @@ class sampledIsoSurface //- Iso value const scalar isoVal_; - //- Merge tolerance - const scalar mergeTol_; - - //- Filtering for iso-surface triangles - const isoSurfaceBase::filterType filter_; + //- Parameters (filtering etc) for iso-surface + isoSurfaceParams isoParams_; //- Whether to recalculate cell values as average of point values - const bool average_; - - //- Optional bounding box to trim triangles against - const boundBox bounds_; + bool average_; //- The zone or zones for the iso-surface wordRes zoneNames_; diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C index af2643fc5b6a996826db691f34f9bd3b0670a61f..fbade62037134b74fe426b14039b02518d48085b 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C @@ -145,9 +145,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const tcellValues(), tpointFld().primitiveField(), isoVal_, - filter_, - bounds_, - 1e-6 // mergeTol + isoParams_ ); // Replace current geomety @@ -161,11 +159,12 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const { Pout<< "isoSurfaceCell::updateGeometry() : constructed iso:" << nl - << " filter : " << Switch(bool(filter_)) << nl - << " average : " << Switch(average_) << nl << " isoField : " << isoField_ << nl << " isoValue : " << isoVal_ << nl - << " bounds : " << bounds_ << nl + << " average : " << Switch(average_) << nl + << " filter : " + << Switch(bool(isoParams_.filter())) << nl + << " bounds : " << isoParams_.getClipBounds() << nl << " points : " << points().size() << nl << " faces : " << Mesh::size() << nl << " cut cells : " << meshCells_.size() << endl; @@ -188,19 +187,13 @@ Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell Mesh(), isoField_(dict.get<word>("isoField")), isoVal_(dict.get<scalar>("isoValue")), - filter_ - ( - isoSurfaceBase::getFilterType - ( - dict, - isoSurfaceBase::filterType::DIAGCELL - ) - ), + isoParams_(dict), average_(dict.getOrDefault("average", true)), - bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), prevTimeIndex_(-1), meshCells_() -{} +{ + isoParams_.algorithm(isoSurfaceParams::ALGO_CELL); // Force +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H index a6c6e032aca84909a5544ca0115b45f1c2125766..83b97edeeaffc97515b28fc6f31bce42644f9101 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H @@ -102,14 +102,11 @@ class sampledIsoSurfaceCell //- Iso value const scalar isoVal_; - //- Filtering for iso-surface triangles - const isoSurfaceBase::filterType filter_; + //- Parameters (filtering etc) for iso-surface + isoSurfaceParams isoParams_; //- Whether to recalculate cell values as average of point values - const bool average_; - - //- Optional bounding box to trim triangles against - const boundBox bounds_; + bool average_; // Recreated for every isoSurface diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C index 1f77bc2710da8d358ca6cc7f0e07ba6bc3abd23f..cd8a1b484a31c43b02ee78bf7dda7f6edb9092fb 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.C @@ -27,12 +27,12 @@ License \*---------------------------------------------------------------------------*/ #include "sampledIsoSurfaceTopo.H" +#include "isoSurfaceTopo.H" #include "dictionary.H" +#include "fvMesh.H" #include "volFields.H" #include "volPointInterpolation.H" #include "addToRunTimeSelectionTable.H" -#include "fvMesh.H" -#include "isoSurfaceTopo.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -119,7 +119,7 @@ bool Foam::sampledIsoSurfaceTopo::updateGeometry() const cellFld.primitiveField(), tpointFld().primitiveField(), isoVal_, - filter_ + isoParams_ ); mySurface.transfer(static_cast<meshedSurface&>(surf)); @@ -138,13 +138,13 @@ bool Foam::sampledIsoSurfaceTopo::updateGeometry() const if (debug) { - Pout<< "sampledIsoSurfaceTopo::updateGeometry() : constructed iso:" - << nl - << " filter : " << isoSurfaceBase::filterNames[filter_] - << nl - << " triangulate : " << Switch(triangulate_) << nl + Pout<< "isoSurfaceTopo::updateGeometry() : constructed iso:" << nl << " isoField : " << isoField_ << nl << " isoValue : " << isoVal_ << nl + << " filter : " + << isoSurfaceParams::filterNames[isoParams_.filter()] << nl + << " triangulate : " << Switch(triangulate_) << nl + << " bounds : " << isoParams_.getClipBounds() << nl << " points : " << points().size() << nl << " faces : " << Mesh::size() << nl << " cut cells : " << meshCells_.size() << endl; @@ -167,19 +167,18 @@ Foam::sampledIsoSurfaceTopo::sampledIsoSurfaceTopo Mesh(), isoField_(dict.get<word>("isoField")), isoVal_(dict.get<scalar>("isoValue")), - filter_ - ( - isoSurfaceBase::getFilterType - ( - dict, - isoSurfaceBase::filterType::DIAGCELL - ) - ), + isoParams_(dict), triangulate_(dict.getOrDefault("triangulate", false)), prevTimeIndex_(-1), meshCells_() { - if (triangulate_ && filter_ == isoSurfaceBase::filterType::NONE) + isoParams_.algorithm(isoSurfaceParams::ALGO_TOPO); // Force + + if + ( + triangulate_ + && (isoParams_.filter() == isoSurfaceParams::filterType::NONE) + ) { FatalIOErrorInFunction(dict) << "Cannot triangulate without a regularise filter" << nl @@ -328,7 +327,7 @@ Foam::sampledIsoSurfaceTopo::interpolate void Foam::sampledIsoSurfaceTopo::print(Ostream& os) const { - os << "sampledIsoSurfaceTopo: " << name() << " :" + os << "isoSurfaceTopo: " << name() << " :" << " field:" << isoField_ << " value:" << isoVal_; //<< " faces:" << faces().size() // possibly no geom yet diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.H index a6cbea9e7a052a258157c07aa914bb43ad2ad6b1..1263af215858f9f4433360eafb78077601280171 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTopo.H @@ -100,11 +100,11 @@ class sampledIsoSurfaceTopo //- Iso value const scalar isoVal_; - //- Filtering for iso-surface triangles - const isoSurfaceBase::filterType filter_; + //- Parameters (filtering etc) for iso-surface + isoSurfaceParams isoParams_; //- Whether to triangulate (after filtering) - const bool triangulate_; + bool triangulate_; // Recreated for every isoSurface diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 4d846848eb315f3038291aed8d46303ca90cef5e..889b5367fb02b442ad507a1b349865cba333c81d 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -57,27 +57,29 @@ void Foam::sampledCuttingPlane::checkBoundsIntersection ) const { // Verify specified bounding box - if (bounds_.valid()) + const boundBox& clipBb = isoParams_.getClipBounds(); + + if (clipBb.valid()) { // Bounding box does not overlap with (global) mesh! - if (!bounds_.overlaps(meshBb)) + if (!clipBb.overlaps(meshBb)) { WarningInFunction << nl << name() << " : " - << "Bounds " << bounds_ + << "Bounds " << clipBb << " do not overlap the mesh bounding box " << meshBb << nl << endl; } // Plane does not intersect the bounding box - if (!bounds_.intersects(pln)) + if (!clipBb.intersects(pln)) { WarningInFunction << nl << name() << " : " << "Plane "<< pln << " does not intersect the bounds " - << bounds_ + << clipBb << nl << endl; } } @@ -138,7 +140,9 @@ void Foam::sampledCuttingPlane::createGeometry() // If we will use a fvMeshSubset so can apply bounds as well to make // the initial selection smaller. - if (bounds_.valid() && cellsToSelect.any()) + + const boundBox& clipBb = isoParams_.getClipBounds(); + if (clipBb.valid() && cellsToSelect.any()) { const auto& cellCentres = fvm.C(); @@ -146,7 +150,7 @@ void Foam::sampledCuttingPlane::createGeometry() { const point& cc = cellCentres[celli]; - if (!bounds_.contains(cc)) + if (!clipBb.contains(cc)) { cellsToSelect.unset(celli); } @@ -297,49 +301,45 @@ void Foam::sampledCuttingPlane::createGeometry() // Direct from cell field and point field. - if (isoAlgo_ == isoSurfaceBase::ALGO_CELL) + if (isoParams_.algorithm() == isoSurfaceParams::ALGO_POINT) { - isoSurfCellPtr_.reset + isoSurfPtr_.reset ( - new isoSurfaceCell + new isoSurface ( - fvm, cellDistance, pointDistance_, - 0, - filter_, - bounds_, - mergeTol_ + scalar(0), // distance + isoParams_ ) ); } - else if (isoAlgo_ == isoSurfaceBase::ALGO_TOPO) + else if (isoParams_.algorithm() == isoSurfaceParams::ALGO_CELL) { - isoSurfTopoPtr_.reset + isoSurfCellPtr_.reset ( - new isoSurfaceTopo + new isoSurfaceCell ( fvm, cellDistance, pointDistance_, - 0, - filter_, - bounds_ + scalar(0), // distance + isoParams_ ) ); } else { - isoSurfPtr_.reset + // ALGO_TOPO + isoSurfTopoPtr_.reset ( - new isoSurface + new isoSurfaceTopo ( + fvm, cellDistance, pointDistance_, - 0, - filter_, - bounds_, - mergeTol_ + scalar(0), // distance + isoParams_ ) ); } @@ -363,24 +363,11 @@ Foam::sampledCuttingPlane::sampledCuttingPlane : sampledSurface(name, mesh, dict), plane_(dict), - bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), - mergeTol_(dict.getOrDefault<scalar>("mergeTol", 1e-6)), - isoAlgo_ + isoParams_ ( - isoSurfaceBase::algorithmNames.getOrDefault - ( - "isoAlgorithm", - dict, - isoSurfaceBase::ALGO_POINT - ) - ), - filter_ - ( - isoSurfaceBase::getFilterType - ( - dict, - isoSurfaceBase::filterType::DIAGCELL - ) + dict, + isoSurfaceParams::ALGO_POINT, + isoSurfaceParams::filterType::DIAGCELL ), average_(dict.getOrDefault("average", false)), zoneNames_(), diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index f470645a51b16f06ba81b7dc51312a11d0d9bd98..cf660d128bcc299b49a35fb0bc8c12fa8464faf7 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,7 +56,7 @@ Usage type | cuttingPlane | yes | planeType | plane description (pointAndNormal etc) | yes | mergeTol | tolerance for merging points | no | 1e-6 - isoAlgorithm | (cell/topo/point) | no | point + isoMethod | Iso-algorithm (cell/topo/point) | no | point regularise | point snapping (bool or enum) | no | true bounds | limit with bounding box | no | zone | limit to cell zone (name or regex) | no | @@ -98,25 +98,16 @@ class sampledCuttingPlane : public sampledSurface { - // Private data + // Private Data //- Plane const plane plane_; - //- Optional bounding box to trim triangles against - const boundBox bounds_; - - //- Merge tolerance - const scalar mergeTol_; - - //- The iso-surface algorithm type - const isoSurfaceBase::algorithmType isoAlgo_; - - //- Filtering for iso-surface triangles - const isoSurfaceBase::filterType filter_; + //- Parameters (filtering etc) for iso-surface + isoSurfaceParams isoParams_; //- Whether to recalculate cell values as average of point values - const bool average_; + bool average_; //- The zone or zones in which cutting is to occur wordRes zoneNames_; diff --git a/src/sampling/surface/distanceSurface/distanceSurface.C b/src/sampling/surface/distanceSurface/distanceSurface.C index 9a1204988de2926abb44f626d4a2df24d9fff775..b7f9e6fde94c30ee2a58d529afbd96da6af67579 100644 --- a/src/sampling/surface/distanceSurface/distanceSurface.C +++ b/src/sampling/surface/distanceSurface/distanceSurface.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,47 +41,6 @@ namespace Foam } -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace Foam -{ - static isoSurfaceBase::algorithmType getIsoAlgorithm(const dictionary& dict) - { - // Previously 'cell' (bool), but now 'isoAlgorithm' (enum) - - // Default (bool) for 1906 and earlier - bool useCell = true; - - // Default (enum) after 1906 - isoSurfaceBase::algorithmType algo = isoSurfaceBase::ALGO_CELL; - - if - ( - !isoSurfaceBase::algorithmNames.readIfPresent - ( - "isoAlgorithm", dict, algo - ) - // When above fails, use 'compat' to also get upgrade messages - && dict.readIfPresentCompat - ( - "isoAlgorithm", {{"cell", 1906}}, useCell - ) - ) - { - return - ( - useCell - ? isoSurfaceBase::ALGO_CELL - : isoSurfaceBase::ALGO_POINT - ); - } - - return algo; - } - -} // End namespace Foam - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::distanceSurface::distanceSurface @@ -114,16 +73,12 @@ Foam::distanceSurface::distanceSurface ( distance_ < 0 || equal(distance_, Zero) || dict.get<bool>("signed") ), - isoAlgo_(getIsoAlgorithm(dict)), - filter_ + isoParams_ ( - isoSurfaceBase::getFilterType - ( - dict, - isoSurfaceBase::filterType::DIAGCELL - ) + dict, + isoSurfaceParams::ALGO_CELL, + isoSurfaceParams::filterType::DIAGCELL ), - bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), isoSurfPtr_(nullptr), isoSurfCellPtr_(nullptr), isoSurfTopoPtr_(nullptr) @@ -137,10 +92,8 @@ Foam::distanceSurface::distanceSurface const word& surfaceType, const word& surfaceName, const scalar distance, - const bool signedDistance, - const isoSurfaceBase::algorithmType algo, - const isoSurfaceBase::filterType filter, - const boundBox& bounds + const bool useSignedDistance, + const isoSurfaceParams& params ) : mesh_(mesh), @@ -164,11 +117,9 @@ Foam::distanceSurface::distanceSurface distance_(distance), signed_ ( - signedDistance || distance_ < 0 || equal(distance_, Zero) + useSignedDistance || distance_ < 0 || equal(distance_, Zero) ), - isoAlgo_(algo), - filter_(filter), - bounds_(bounds), + isoParams_(params), isoSurfPtr_(nullptr), isoSurfCellPtr_(nullptr), isoSurfTopoPtr_(nullptr) @@ -220,7 +171,7 @@ void Foam::distanceSurface::createGeometry() const bool filterCells = ( isZeroDist - && isoAlgo_ != isoSurfaceBase::ALGO_POINT + && isoParams_.algorithm() != isoSurfaceParams::ALGO_POINT ); bitSet ignoreCells; @@ -408,51 +359,48 @@ void Foam::distanceSurface::createGeometry() // Direct from cell field and point field. - if (isoAlgo_ == isoSurfaceBase::ALGO_CELL) + if (isoParams_.algorithm() == isoSurfaceParams::ALGO_POINT) { - isoSurfCellPtr_.reset + isoSurfPtr_.reset ( - new isoSurfaceCell + new isoSurface ( - fvm, cellDistance, pointDistance_, distance_, - filter_, - bounds_, - 1e-6, // mergeTol + isoParams_, ignoreCells ) ); } - else if (isoAlgo_ == isoSurfaceBase::ALGO_TOPO) + else if (isoParams_.algorithm() == isoSurfaceParams::ALGO_CELL) { - isoSurfTopoPtr_.reset + isoSurfCellPtr_.reset ( - new isoSurfaceTopo + new isoSurfaceCell ( fvm, cellDistance, pointDistance_, distance_, - filter_, - bounds_, + isoParams_, ignoreCells ) ); } else { - isoSurfPtr_.reset + // ALGO_TOPO + isoSurfTopoPtr_.reset ( - new isoSurface + new isoSurfaceTopo ( + fvm, cellDistance, pointDistance_, distance_, - filter_, - bounds_, - 1e-6 + isoParams_, + ignoreCells ) ); } diff --git a/src/sampling/surface/distanceSurface/distanceSurface.H b/src/sampling/surface/distanceSurface/distanceSurface.H index f4d5221226cebfc0a8168d2903ffd6ccb106f7b4..d41ff12e0aa691b6d2a5d8938e18f707e7e18cba 100644 --- a/src/sampling/surface/distanceSurface/distanceSurface.H +++ b/src/sampling/surface/distanceSurface/distanceSurface.H @@ -38,7 +38,7 @@ Usage Property | Description | Required | Default distance | distance from surface | yes | signed | Use sign when distance is positive | partly | - isoAlgorithm | (cell/topo/point) | no | cell + isoMethod | Iso-algorithm (cell/topo/point) | no | cell regularise | Point snapping (enum or bool) | no | true bounds | Limit with bounding box | no | surfaceType | Type of surface | yes | @@ -54,7 +54,8 @@ Note surface. The resulting surface elements will not, however, contain partial cell coverage. - For compatibility, the keyword 'cell' (as a bool) is accepted +The keyword \c cell (bool value) which was use in 1906 and earlier to switch +between point/cell algorithms is now ignored (2020-12). SourceFiles distanceSurface.C @@ -95,14 +96,8 @@ class distanceSurface //- Signed distance const bool signed_; - //- The iso-surface algorithm type - const isoSurfaceBase::algorithmType isoAlgo_; - - //- Filtering for iso-surface triangles - const isoSurfaceBase::filterType filter_; - - //- Optional bounding box to trim against - const boundBox bounds_; + //- Parameters for iso-surface (algorithm, filter, mergeTol, etc) + isoSurfaceParams isoParams_; //- Distance to cell centres autoPtr<volScalarField> cellDistancePtr_; @@ -143,10 +138,8 @@ public: const word& surfaceType, const word& surfaceName, const scalar distance, - const bool signedDistance, - const isoSurfaceBase::algorithmType algo, - const isoSurfaceBase::filterType filter, - const boundBox& bounds = boundBox::invertedBox + const bool useSignedDistance, + const isoSurfaceParams& params = isoSurfaceParams() ); diff --git a/src/sampling/surface/isoSurface/isoSurface.C b/src/sampling/surface/isoSurface/isoSurface.C index d8fce742fdd6a38279784ec9c241a27c2e039239..e25bc2341210b2c1180c1617d084133d18d8b493 100644 --- a/src/sampling/surface/isoSurface/isoSurface.C +++ b/src/sampling/surface/isoSurface/isoSurface.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1340,39 +1340,17 @@ Foam::isoSurface::isoSurface const volScalarField& cellValues, const scalarField& pointValues, const scalar iso, - const isoSurfaceBase::filterType filter, - const boundBox& bounds, - const scalar mergeTol + const isoSurfaceParams& params, + const bitSet& /*unused*/ ) : - isoSurface - ( - cellValues, - pointValues, - iso, - (filter != filterType::NONE), - bounds, - mergeTol - ) -{} - - -Foam::isoSurface::isoSurface -( - const volScalarField& cellValues, - const scalarField& pointValues, - const scalar iso, - const bool regularise, - const boundBox& bounds, - const scalar mergeTol -) -: - isoSurfaceBase(iso, bounds), + isoSurfaceBase(iso, params), mesh_(cellValues.mesh()), pVals_(pointValues), - regularise_(regularise), - mergeDistance_(mergeTol*mesh_.bounds().mag()) + mergeDistance_(params.mergeTol()*mesh_.bounds().mag()) { + const bool regularise = (params.filter() != filterType::NONE); + if (debug) { Pout<< "isoSurface:" << nl @@ -1381,8 +1359,8 @@ Foam::isoSurface::isoSurface << minMax(cellValues.primitiveField()) << nl << " point min/max : " << minMax(pVals_) << nl << " isoValue : " << iso << nl - << " filter : " << Switch(regularise_) << nl - << " mergeTol : " << mergeTol << nl + << " filter : " << Switch(regularise) << nl + << " mergeTol : " << params.mergeTol() << nl << endl; } @@ -1530,7 +1508,7 @@ Foam::isoSurface::isoSurface // Per cc -1 or a point inside snappedPoints. labelList snappedCc; - if (regularise_) + if (regularise) { calcSnappedCc ( @@ -1562,7 +1540,7 @@ Foam::isoSurface::isoSurface // Per point -1 or a point inside snappedPoints. labelList snappedPoint; - if (regularise_) + if (regularise) { // Determine if point is on boundary. bitSet isBoundaryPoint(mesh_.nPoints()); @@ -1661,11 +1639,11 @@ Foam::isoSurface::isoSurface DynamicList<label> trimTriMap; // Trimmed to original point labelList trimTriPointMap; - if (bounds_.valid()) + if (getClipBounds().valid()) { trimToBox ( - treeBoundBox(bounds_), + treeBoundBox(getClipBounds()), triPoints, // new points trimTriMap, // map from (new) triangle to original trimTriPointMap, // map from (new) point to original @@ -1694,7 +1672,7 @@ Foam::isoSurface::isoSurface } - if (bounds_.valid()) + if (getClipBounds().valid()) { // Adjust interpolatedPoints_ inplaceRenumber(triPointMergeMap_, interpolatedPoints_); diff --git a/src/sampling/surface/isoSurface/isoSurface.H b/src/sampling/surface/isoSurface/isoSurface.H index 27b5ca9fc2dc234b0a5be76e61c5f6b8775f130e..95c7460ae3cf6be87647ad118aa9dafaabc5bd22 100644 --- a/src/sampling/surface/isoSurface/isoSurface.H +++ b/src/sampling/surface/isoSurface/isoSurface.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -116,9 +116,6 @@ class isoSurface //- Input volScalarField with separated coupled patches rewritten autoPtr<slicedVolScalarField> cValsPtr_; - //- Regularise? - const bool regularise_; - //- When to merge points const scalar mergeDistance_; @@ -386,9 +383,6 @@ public: friend class isoSurfaceCell; friend class isoSurfaceTopo; - //- Filtering type - using isoSurfaceBase::filterType; - //- Runtime type information TypeName("isoSurface"); @@ -400,33 +394,16 @@ public: // Uses boundaryField for boundary values. // Holds reference to cellIsoVals and pointIsoVals. // - // \param bounds optional bounding box for trimming - // \param mergeTol fraction of mesh bounding box for merging points - isoSurface - ( - const volScalarField& cellValues, - const scalarField& pointValues, - const scalar iso, - const isoSurfaceBase::filterType filter, - const boundBox& bounds = boundBox::invertedBox, - const scalar mergeTol = 1e-6 - ); - - - //- Construct from cell values and point values. - // Uses boundaryField for boundary values. - // Holds reference to cellIsoVals and pointIsoVals. - // - // \param bounds optional bounding box for trimming - // \param mergeTol fraction of mesh bounding box for merging points + // Control parameters include + // - bounds optional bounding box for trimming + // - mergeTol fraction of mesh bounding box for merging points isoSurface ( const volScalarField& cellValues, const scalarField& pointValues, const scalar iso, - const bool regularise, - const boundBox& bounds = boundBox::invertedBox, - const scalar mergeTol = 1e-6 + const isoSurfaceParams& params = isoSurfaceParams(), + const bitSet& ignoreCells = bitSet() //!< unused ); diff --git a/src/sampling/surface/isoSurface/isoSurfaceBase.C b/src/sampling/surface/isoSurface/isoSurfaceBase.C index 8c8dbf2c13b002e38694f99182e2b91fb753bc87..b8546926e8161e3e0b90ce49c85f65af88cd4a74 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceBase.C +++ b/src/sampling/surface/isoSurface/isoSurfaceBase.C @@ -27,87 +27,17 @@ License #include "isoSurfaceBase.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const Foam::Enum -< - Foam::isoSurfaceBase::algorithmType -> -Foam::isoSurfaceBase::algorithmNames -({ - { algorithmType::ALGO_CELL, "cell" }, - { algorithmType::ALGO_TOPO, "topo" }, - { algorithmType::ALGO_POINT, "point" }, -}); - - -const Foam::Enum -< - Foam::isoSurfaceBase::filterType -> -Foam::isoSurfaceBase::filterNames -({ - { filterType::NONE, "none" }, - { filterType::CELL, "cell" }, - { filterType::DIAGCELL, "diagcell" }, - { filterType::PARTIAL, "partial" }, - { filterType::FULL, "full" }, -}); - - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -Foam::isoSurfaceBase::filterType -Foam::isoSurfaceBase::getFilterType -( - const dictionary& dict, - const isoSurfaceBase::filterType deflt -) -{ - word filterName; - - if (!dict.readIfPresent("regularise", filterName, keyType::LITERAL)) - { - return deflt; - } - - // Try as bool/switch - Switch sw = Switch::find(filterName); - - if (sw.good()) - { - return - ( - sw - ? deflt - : isoSurfaceBase::filterType::NONE - ); - } - - // As enum - if (!isoSurfaceBase::filterNames.found(filterName)) - { - FatalIOErrorInFunction(dict) - << filterName << " is not in enumeration: " - << isoSurfaceBase::filterNames << nl - << exit(FatalIOError); - } - - return isoSurfaceBase::filterNames[filterName]; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::isoSurfaceBase::isoSurfaceBase ( const scalar iso, - const boundBox& bounds + const isoSurfaceParams& params ) : meshedSurface(), - iso_(iso), - bounds_(bounds) + isoSurfaceParams(params), + iso_(iso) {} diff --git a/src/sampling/surface/isoSurface/isoSurfaceBase.H b/src/sampling/surface/isoSurface/isoSurfaceBase.H index 0806f92293336103a2ac72be367ccd5370282a2c..0faf2cf15578a5cb3f5916055486aba86d8bf64d 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceBase.H +++ b/src/sampling/surface/isoSurface/isoSurfaceBase.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,9 +37,8 @@ SourceFiles #ifndef isoSurfaceBase_H #define isoSurfaceBase_H +#include "isoSurfaceParams.H" #include "scalar.H" -#include "Enum.H" -#include "boundBox.H" #include "MeshedSurface.H" #include "MeshedSurfacesFwd.H" @@ -54,7 +53,8 @@ namespace Foam class isoSurfaceBase : - public meshedSurface + public meshedSurface, + public isoSurfaceParams { protected: @@ -66,81 +66,38 @@ protected: //- Iso value const scalar iso_; - //- Optional bounds - const boundBox bounds_; - //- For every face, the original cell in mesh labelList meshCells_; public: - //- The algorithm types - enum algorithmType : uint8_t - { - ALGO_POINT, - ALGO_CELL, - ALGO_TOPO - }; - - - //- The filtering (regularization) to apply - enum class filterType : uint8_t - { - NONE = 0, //!< No filtering - CELL, //!< Remove points from pyramid edges - DIAGCELL, //!< Remove points from pyramid edges and face-diagonals - PARTIAL = CELL, //!< Same as CELL - FULL = DIAGCELL, //!< Same as DIAGCELL - }; - - - // Public Data - - //- Names for the iso-surface algorithms - static const Enum<algorithmType> algorithmNames; - - //- Names for the filtering types - static const Enum<filterType> filterNames; - - - - // Static Member Functions - - //- Get 'regularise' as bool or enumeration - static filterType getFilterType - ( - const dictionary& dict, - const isoSurfaceBase::filterType deflt - ); - - // Constructors - //- Construct with iso value - explicit isoSurfaceBase + //- Create for specified algorithm type/filter and iso-value + isoSurfaceBase ( const scalar iso, - const boundBox& bounds = boundBox::invertedBox + const isoSurfaceParams& params = isoSurfaceParams() ); // Member Functions //- The iso-value associated with the surface - inline scalar isoValue() const + scalar isoValue() const noexcept { return iso_; } //- For each face, the original cell in mesh - const labelList& meshCells() const + const labelList& meshCells() const noexcept { return meshCells_; } //- For each face, the original cell in mesh - labelList& meshCells() + labelList& meshCells() noexcept { return meshCells_; } diff --git a/src/sampling/surface/isoSurface/isoSurfaceCell.C b/src/sampling/surface/isoSurface/isoSurfaceCell.C index f6e0d37b42016c938be8c48cf1e3ab43eb5428a6..c1906dc1758e7a66da489613bf6313044baae360 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCell.C +++ b/src/sampling/surface/isoSurface/isoSurfaceCell.C @@ -1294,45 +1294,19 @@ Foam::isoSurfaceCell::isoSurfaceCell const scalarField& cellValues, const scalarField& pointValues, const scalar iso, - const isoSurfaceBase::filterType filter, - const boundBox& bounds, - const scalar mergeTol, + const isoSurfaceParams& params, const bitSet& ignoreCells ) : - isoSurfaceCell - ( - mesh, - cellValues, - pointValues, - iso, - (filter != filterType::NONE), - bounds, - mergeTol, - ignoreCells - ) -{} - - -Foam::isoSurfaceCell::isoSurfaceCell -( - const polyMesh& mesh, - const scalarField& cellValues, - const scalarField& pointValues, - const scalar iso, - const bool regularise, - const boundBox& bounds, - const scalar mergeTol, - const bitSet& ignoreCells -) -: - isoSurfaceBase(iso, bounds), + isoSurfaceBase(iso, params), mesh_(mesh), cVals_(cellValues), pVals_(pointValues), ignoreCells_(ignoreCells), - mergeDistance_(mergeTol*mesh.bounds().mag()) + mergeDistance_(params.mergeTol()*mesh.bounds().mag()) { + const bool regularise = (params.filter() != filterType::NONE); + if (debug) { Pout<< "isoSurfaceCell:" << nl @@ -1340,7 +1314,7 @@ Foam::isoSurfaceCell::isoSurfaceCell << " point min/max : " << minMax(pVals_) << nl << " isoValue : " << iso << nl << " filter : " << Switch(regularise) << nl - << " mergeTol : " << mergeTol << nl + << " mergeTol : " << params.mergeTol() << nl << " mesh span : " << mesh.bounds().mag() << nl << " mergeDistance : " << mergeDistance_ << nl << " ignoreCells : " << ignoreCells_.count() @@ -1489,11 +1463,11 @@ Foam::isoSurfaceCell::isoSurfaceCell DynamicList<label> trimTriMap; // Trimmed to original point labelList trimTriPointMap; - if (bounds_.valid()) + if (getClipBounds().valid()) { isoSurface::trimToBox ( - treeBoundBox(bounds_), + treeBoundBox(getClipBounds()), triPoints, // new points trimTriMap, // map from (new) triangle to original trimTriPointMap, // map from (new) point to original @@ -1521,7 +1495,7 @@ Foam::isoSurfaceCell::isoSurfaceCell << " merged triangles." << endl; } - if (bounds_.valid()) + if (getClipBounds().valid()) { // Adjust interpolatedPoints_ inplaceRenumber(triPointMergeMap_, interpolatedPoints_); diff --git a/src/sampling/surface/isoSurface/isoSurfaceCell.H b/src/sampling/surface/isoSurface/isoSurfaceCell.H index 66b61b3ecb80254a1048f40ee980f36adcb332fa..592cb7aaf1f4e0db0ebad2639bd00b810121b42a 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCell.H +++ b/src/sampling/surface/isoSurface/isoSurfaceCell.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,7 +58,7 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class polyMesh; class triSurface; @@ -303,9 +303,6 @@ class isoSurfaceCell public: - //- Filtering type - using isoSurfaceBase::filterType; - //- Runtime type information TypeName("isoSurfaceCell"); @@ -315,35 +312,18 @@ public: //- Construct from cell and point values // - // \param bounds optional bounding box for trimming - // \param mergeTol fraction of mesh bounding box for merging points // \param ignoreCells cells to ignore in the cellValues - isoSurfaceCell - ( - const polyMesh& mesh, - const scalarField& cellValues, - const scalarField& pointValues, - const scalar iso, - const isoSurfaceBase::filterType filter, - const boundBox& bounds = boundBox::invertedBox, - const scalar mergeTol = 1e-6, - const bitSet& ignoreCells = bitSet() - ); - - //- Construct from cell and point values // - // \param bounds optional bounding box for trimming - // \param mergeTol fraction of mesh bounding box for merging points - // \param ignoreCells cells to ignore in the cellValues + // Control parameters include + // - bounds optional bounding box for trimming + // - mergeTol fraction of mesh bounding box for merging points isoSurfaceCell ( const polyMesh& mesh, const scalarField& cellValues, const scalarField& pointValues, const scalar iso, - const bool regularise, - const boundBox& bounds = boundBox::invertedBox, - const scalar mergeTol = 1e-6, + const isoSurfaceParams& params = isoSurfaceParams(), const bitSet& ignoreCells = bitSet() ); diff --git a/src/sampling/surface/isoSurface/isoSurfaceParams.C b/src/sampling/surface/isoSurface/isoSurfaceParams.C new file mode 100644 index 0000000000000000000000000000000000000000..cf9494ed5d39d9167e93134ae7c1f568e9923a75 --- /dev/null +++ b/src/sampling/surface/isoSurface/isoSurfaceParams.C @@ -0,0 +1,179 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "isoSurfaceParams.H" +#include "dictionary.H" +#include "Switch.H" +#include "boundBox.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::Enum +< + Foam::isoSurfaceParams::algorithmType +> +Foam::isoSurfaceParams::algorithmNames +({ + { algorithmType::ALGO_DEFAULT, "default" }, + { algorithmType::ALGO_CELL, "cell" }, + { algorithmType::ALGO_POINT, "point" }, + { algorithmType::ALGO_TOPO, "topo" }, +}); + + +const Foam::Enum +< + Foam::isoSurfaceParams::filterType +> +Foam::isoSurfaceParams::filterNames +({ + { filterType::NONE, "none" }, + { filterType::CELL, "cell" }, + { filterType::DIAGCELL, "diagcell" }, + { filterType::PARTIAL, "partial" }, + { filterType::FULL, "full" }, +}); + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::isoSurfaceParams::algorithmType +Foam::isoSurfaceParams::getAlgorithmType +( + const dictionary& dict, + const algorithmType deflt +) +{ + word enumName; + if + ( + !dict.readIfPresentCompat + ( + "isoMethod", {{"isoAlgorithm", 0}}, + enumName, keyType::LITERAL + ) + ) + { + return deflt; + } + + if (!algorithmNames.found(enumName)) + { + FatalIOErrorInFunction(dict) + << enumName << " is not in enumeration: " + << (algorithmNames) << nl + << exit(FatalIOError); + } + + return algorithmNames[enumName]; +} + + +Foam::isoSurfaceParams::filterType +Foam::isoSurfaceParams::getFilterType +( + const dictionary& dict, + const filterType deflt +) +{ + word enumName; + if (!dict.readIfPresent("regularise", enumName, keyType::LITERAL)) + { + return deflt; + } + + // Try as bool/switch + const Switch sw = Switch::find(enumName); + + if (sw.good()) + { + return (sw ? deflt : filterType::NONE); + } + + // As enum + if (!filterNames.found(enumName)) + { + FatalIOErrorInFunction(dict) + << enumName << " is not in enumeration: " + << (filterNames) << nl + << exit(FatalIOError); + } + + return filterNames[enumName]; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::isoSurfaceParams::isoSurfaceParams +( + const algorithmType algo, + const filterType filter +) noexcept +: + algo_(algo), + filter_(filter), + mergeTol_(1e-6), + clipBounds_(boundBox::invertedBox) +{} + + +Foam::isoSurfaceParams::isoSurfaceParams +( + const dictionary& dict, + const isoSurfaceParams& params +) +: + isoSurfaceParams(params) +{ + algo_ = getAlgorithmType(dict, algo_); + filter_ = getFilterType(dict, filter_); + dict.readIfPresent("mergeTol", mergeTol_); + dict.readIfPresent("bounds", clipBounds_); +} + + +Foam::isoSurfaceParams::isoSurfaceParams +( + const dictionary& dict, + const algorithmType algo, + const filterType filter +) +: + isoSurfaceParams(dict, isoSurfaceParams(algo, filter)) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::isoSurfaceParams::setClipBounds(const boundBox& bb) +{ + clipBounds_ = bb; +} + + +// ************************************************************************* // diff --git a/src/sampling/surface/isoSurface/isoSurfaceParams.H b/src/sampling/surface/isoSurface/isoSurfaceParams.H new file mode 100644 index 0000000000000000000000000000000000000000..1b794f70595cbcb5efbdb934f996d73bf0687d1b --- /dev/null +++ b/src/sampling/surface/isoSurface/isoSurfaceParams.H @@ -0,0 +1,226 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 <http://www.gnu.org/licenses/>. + +Class + Foam::isoSurfaceParams + +Description + Preferences for controlling iso-surface algorithms. + + Some common dictionary properties: + \table + Property | Description | Required | Default + isoMethod | Algorithm (cell/topo/point/default) | no | default + regularise | Face simplification (enum or bool) | no | true + mergeTol | Point merge tolerance (cell/point) | no | 1e-6 + bounds | Optional clip bounds | no | inverted + \endtable + + The default algorithm denotes the use of the current \em standard + algorithm. + +SourceFiles + isoSurfaceParams.C + +\*---------------------------------------------------------------------------*/ + +#ifndef isoSurfaceParams_H +#define isoSurfaceParams_H + +#include "boundBox.H" +#include "Enum.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward Declarations +class dictionary; + +/*---------------------------------------------------------------------------*\ + Class isoSurfaceSelector Declaration +\*---------------------------------------------------------------------------*/ + +class isoSurfaceParams +{ +public: + + // Data Types + + //- The algorithm types + enum algorithmType : uint8_t + { + ALGO_DEFAULT = 0, //!< Use current 'standard' algorithm + ALGO_TOPO, + ALGO_CELL, + ALGO_POINT + }; + + //- The filtering (regularization) to apply + enum class filterType : uint8_t + { + NONE = 0, //!< No filtering + CELL, //!< Remove pyramid edge points + DIAGCELL, //!< Remove pyramid edge points, face-diagonals + PARTIAL = CELL, //!< Same as CELL + FULL = DIAGCELL, //!< Same as DIAGCELL + }; + + +private: + + // Private Data + + //- Algorithm type + algorithmType algo_; + + //- Filtering for iso-surface faces/points + filterType filter_; + + //- Merge tolerance for cell/point (default: 1e-6) + scalar mergeTol_; + + //- Optional bounding box for clipping (default: inverted) + boundBox clipBounds_; + + +public: + + // Public Data + + //- Names for the iso-surface algorithms + static const Enum<algorithmType> algorithmNames; + + //- Names for the filtering types + static const Enum<filterType> filterNames; + + + // Static Member Functions + + //- Get 'isoMethod' or 'isoAlgorithm' as enumeration + static algorithmType getAlgorithmType + ( + const dictionary& dict, + const algorithmType deflt + ); + + //- Get 'regularise' as bool or enumeration + static filterType getFilterType + ( + const dictionary& dict, + const filterType deflt + ); + + + // Constructors + + //- Default construct, or with specified algorithm + explicit isoSurfaceParams + ( + const algorithmType algo = algorithmType::ALGO_DEFAULT, + const filterType filter = filterType::DIAGCELL + ) noexcept; + + //- Default construct, setting parameters from dictionary + explicit isoSurfaceParams + ( + const dictionary& dict, + const isoSurfaceParams& params = isoSurfaceParams() + ); + + //- Default construct, setting parameters from dictionary + explicit isoSurfaceParams + ( + const dictionary& dict, + const algorithmType algo, + const filterType filter = filterType::DIAGCELL + ); + + + // Member Functions + + //- Get current algorithm + algorithmType algorithm() const noexcept + { + return algo_; + } + + //- Set algorithm + void algorithm(algorithmType algo) noexcept + { + algo_ = algo; + } + + //- Get current filter type + filterType filter() const noexcept + { + return filter_; + } + + //- Set filter type + void filter(filterType fltr) noexcept + { + filter_ = fltr; + } + + //- Get current merge tolerance + scalar mergeTol() const noexcept + { + return mergeTol_; + } + + //- Set merge tolerance (cell/point algo) + void mergeTol(const scalar relTol) noexcept + { + mergeTol_ = relTol; + } + + //- Get optional clipping bounding box + const boundBox& getClipBounds() const noexcept + { + return clipBounds_; + } + + //- Access optional clipping bounding box + boundBox& getClipBounds() noexcept + { + return clipBounds_; + } + + //- Set optional clipping bounding box + void setClipBounds(const boundBox& bb); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/surface/isoSurface/isoSurfaceTopo.C b/src/sampling/surface/isoSurface/isoSurfaceTopo.C index a56377e540e4b9f1a22e1e4e9882f62816cedd08..ac385a9a4dfa2003ec5b9850b8e2307db4bd52de 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceTopo.C +++ b/src/sampling/surface/isoSurface/isoSurfaceTopo.C @@ -27,7 +27,6 @@ License \*---------------------------------------------------------------------------*/ #include "isoSurfaceTopo.H" -#include "isoSurface.H" #include "polyMesh.H" #include "volFields.H" #include "tetMatcher.H" @@ -1193,12 +1192,11 @@ Foam::isoSurfaceTopo::isoSurfaceTopo const scalarField& cVals, const scalarField& pVals, const scalar iso, - const filterType filter, - const boundBox& bounds, + const isoSurfaceParams& params, const bitSet& ignoreCells ) : - isoSurfaceBase(iso, bounds), + isoSurfaceBase(iso, params), mesh_(mesh), cVals_(cVals), pVals_(pVals), @@ -1210,8 +1208,8 @@ Foam::isoSurfaceTopo::isoSurfaceTopo << " cell min/max : " << minMax(cVals_) << nl << " point min/max : " << minMax(pVals_) << nl << " isoValue : " << iso << nl - << " filter : " << isoSurfaceBase::filterNames[filter] - << nl + << " filter : " + << isoSurfaceParams::filterNames[params.filter()] << nl << " mesh span : " << mesh.bounds().mag() << nl << " ignoreCells : " << ignoreCells_.count() << " / " << cVals_.size() << nl @@ -1345,7 +1343,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo } - if (filter != filterType::NONE) + if (params.filter() != filterType::NONE) { // Triangulate outside (filter edges to cell centres and optionally // face diagonals) @@ -1355,7 +1353,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo ( removeInsidePoints ( - (filter == filterType::DIAGCELL ? true : false), + (params.filter() == filterType::DIAGCELL ? true : false), *this, pointFromDiag, pointToFace_, @@ -1378,7 +1376,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo } - if (filter == filterType::DIAGCELL) + if (params.filter() == filterType::DIAGCELL) { // We remove verts on face diagonals. This is in fact just // straightening the edges of the face through the cell. This can diff --git a/src/sampling/surface/isoSurface/isoSurfaceTopo.H b/src/sampling/surface/isoSurface/isoSurfaceTopo.H index 5ecdb7e5c256d5b6f727c307fd9791a573414cc0..490216016835143a630301de2359c27094a74d91 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceTopo.H +++ b/src/sampling/surface/isoSurface/isoSurfaceTopo.H @@ -185,9 +185,6 @@ class isoSurfaceTopo public: - //- Filtering type - using isoSurfaceBase::filterType; - //- Runtime type information TypeName("isoSurfaceTopo"); @@ -195,15 +192,20 @@ public: // Constructors - //- Construct from dictionary + //- Construct from cell and point values + // + // \param ignoreCells cells to ignore in the cellValues + // + // Control parameters include + // - bounds optional bounding box for trimming + // - mergeTol fraction of mesh bounding box for merging points isoSurfaceTopo ( const polyMesh& mesh, const scalarField& cellValues, const scalarField& pointValues, const scalar iso, - const filterType filter = filterType::DIAGCELL, - const boundBox& bounds = boundBox::invertedBox, + const isoSurfaceParams& params = isoSurfaceParams(), const bitSet& ignoreCells = bitSet() );