diff --git a/bin/foamCreateBashCompletions b/bin/foamCreateBashCompletions index a941a23f33..ea366c1f0f 100755 --- a/bin/foamCreateBashCompletions +++ b/bin/foamCreateBashCompletions @@ -40,7 +40,7 @@ Usage: $Script [OPTION] * Create bash completions for OpenFOAM applications and write to . By default searches directories \$FOAM_APPBIN and \$FOAM_USER_APPBIN - + Options: -d | -directory Directory to process @@ -149,10 +149,10 @@ do echo "Processing $appName" # Options with args - optsWithArgs=($(awk '/^ *-[a-z]/ && /> $outFile unset -f _${appName} diff --git a/src/OpenFOAM/meshes/meshTools/mergePoints.C b/src/OpenFOAM/meshes/meshTools/mergePoints.C index 2b99235b72..041a6f8194 100644 --- a/src/OpenFOAM/meshes/meshTools/mergePoints.C +++ b/src/OpenFOAM/meshes/meshTools/mergePoints.C @@ -41,22 +41,28 @@ Foam::label Foam::mergePoints { typedef typename PointList::value_type point_type; - // Create a old to new point mapping array - pointMap.setSize(points.size()); + const label nPoints = points.size(); + + // Create an old to new point mapping array + pointMap.setSize(nPoints); pointMap = -1; - if (points.empty()) + if (!nPoints) { return 0; } - // Explicitly convert to Field to support various list types - tmp> tPoints(new Field(points)); - point_type compareOrigin = origin; if (origin == point_type::max) { - compareOrigin = sum(tPoints())/points.size(); + // Use average of input points to define a comparison origin. + // Same as sum(points)/nPoints, but handles different list types + compareOrigin = points[0]; + for (label pointi=1; pointi < nPoints; ++pointi) + { + compareOrigin += points[pointi]; + } + compareOrigin /= nPoints; } // We're comparing distance squared to origin first. @@ -68,34 +74,31 @@ Foam::label Foam::mergePoints // x^2+y^2+z^2 + 2*mergeTol*(x+z+y) + mergeTol^2*... // so the difference will be 2*mergeTol*(x+y+z) - const scalar mergeTolSqr = Foam::sqr(scalar(mergeTol)); + const scalar mergeTolSqr = Foam::sqr(mergeTol); // Sort points by magSqr - const Field d(tPoints - compareOrigin); - - List magSqrD(d.size()); - forAll(d, pointi) + List magSqrDist(nPoints); + forAll(points, pointi) { - magSqrD[pointi] = magSqr(d[pointi]); + magSqrDist[pointi] = magSqr(points[pointi] - compareOrigin); } labelList order; - Foam::sortedOrder(magSqrD, order); + Foam::sortedOrder(magSqrDist, order); - Field sortedTol(points.size()); + Field sortedTol(nPoints); forAll(order, sortI) { - const label pointi = order[sortI]; + const point_type& pt = points[order[sortI]]; - // Convert to scalar precision - // NOTE: not yet using point_type template parameter - const point pt - ( - scalar(d[pointi].x()), - scalar(d[pointi].y()), - scalar(d[pointi].z()) - ); - sortedTol[sortI] = 2*mergeTol*(mag(pt.x())+mag(pt.y())+mag(pt.z())); + // Use scalar precision + sortedTol[sortI] = + 2*mergeTol* + ( + mag(scalar(pt.x() - compareOrigin.x())), + + mag(scalar(pt.y() - compareOrigin.y())), + + mag(scalar(pt.z() - compareOrigin.z())) + ); } label newPointi = 0; @@ -104,11 +107,11 @@ Foam::label Foam::mergePoints label pointi = order[0]; pointMap[pointi] = newPointi++; - for (label sortI = 1; sortI < order.size(); sortI++) + for (label sortI = 1; sortI < order.size(); ++sortI) { // Get original point index const label pointi = order[sortI]; - const scalar mag2 = magSqrD[order[sortI]]; + const scalar mag2 = magSqrDist[order[sortI]]; // Convert to scalar precision // NOTE: not yet using point_type template parameter @@ -127,8 +130,8 @@ Foam::label Foam::mergePoints ( label prevSortI = sortI - 1; prevSortI >= 0 - && (mag(magSqrD[order[prevSortI]] - mag2) <= sortedTol[sortI]); - prevSortI-- + && (mag(magSqrDist[order[prevSortI]] - mag2) <= sortedTol[sortI]); + --prevSortI ) { const label prevPointi = order[prevSortI]; diff --git a/src/conversion/fire/FIREMeshWriter.C b/src/conversion/fire/FIREMeshWriter.C index 9c6146c3e0..2fc9de6e1f 100644 --- a/src/conversion/fire/FIREMeshWriter.C +++ b/src/conversion/fire/FIREMeshWriter.C @@ -281,22 +281,22 @@ bool Foam::fileFormats::FIREMeshWriter::write(const fileName& meshName) const if (FIRECore::file3dExtensions.hasEnum(ext)) { FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext]; - if (fireFileType == FIRECore::POLY_ASCII) + if (fireFileType == FIRECore::fileExt3d::POLY_ASCII) { useBinary = false; useCompress = false; } - else if (fireFileType == FIRECore::POLY_BINARY) + else if (fireFileType == FIRECore::fileExt3d::POLY_BINARY) { useBinary = true; useCompress = false; } - else if (fireFileType == FIRECore::POLY_ASCII_COMPRESSED) + else if (fireFileType == FIRECore::fileExt3d::POLY_ASCII_Z) { useBinary = false; useCompress = true; } - else if (fireFileType == FIRECore::POLY_BINARY_COMPRESSED) + else if (fireFileType == FIRECore::fileExt3d::POLY_BINARY_Z) { useBinary = true; useCompress = true; diff --git a/src/fileFormats/coordSet/coordSet.C b/src/fileFormats/coordSet/coordSet.C index 5d7dd92b79..c4149dc943 100644 --- a/src/fileFormats/coordSet/coordSet.C +++ b/src/fileFormats/coordSet/coordSet.C @@ -27,26 +27,15 @@ License // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // -namespace Foam -{ - template<> - const char* Foam::NamedEnum - < - Foam::coordSet::coordFormat, - 5 - >::names[] = +const Foam::Enum + Foam::coordSet::coordFormatNames_ { - "xyz", - "x", - "y", - "z", - "distance" + { coordFormat::XYZ, "xyz" }, + { coordFormat::X, "x" }, + { coordFormat::Y, "y" }, + { coordFormat::Z, "z" }, + { coordFormat::DISTANCE, "distance" } }; -} - - -const Foam::NamedEnum - Foam::coordSet::coordFormatNames_; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/fileFormats/coordSet/coordSet.H b/src/fileFormats/coordSet/coordSet.H index 5492f37b43..bf764cc143 100644 --- a/src/fileFormats/coordSet/coordSet.H +++ b/src/fileFormats/coordSet/coordSet.H @@ -37,6 +37,7 @@ SourceFiles #include "pointField.H" #include "word.H" +#include "Enum.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -70,7 +71,7 @@ public: private: //- String representation of coordFormat enums - static const NamedEnum coordFormatNames_; + static const Enum coordFormatNames_; protected: diff --git a/src/fileFormats/fire/FIRECore.C b/src/fileFormats/fire/FIRECore.C index ab57611634..4cf9896080 100644 --- a/src/fileFormats/fire/FIRECore.C +++ b/src/fileFormats/fire/FIRECore.C @@ -27,24 +27,14 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::NamedEnum - Foam::fileFormats::FIRECore::file3dExtensions; - -namespace Foam -{ - template<> - const char* Foam::NamedEnum - < - Foam::fileFormats::FIRECore::fileExt3d, - 4 - >::names[] = +const Foam::Enum + Foam::fileFormats::FIRECore::file3dExtensions { - "fpma", - "fpmb", - "fpmaz", - "fpmbz" + { fileExt3d::POLY_ASCII, "fpma" }, + { fileExt3d::POLY_BINARY, "fpmb" }, + { fileExt3d::POLY_ASCII_Z, "fpmaz" }, + { fileExt3d::POLY_BINARY_Z, "fpmbz" } }; -} // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/fileFormats/fire/FIRECore.H b/src/fileFormats/fire/FIRECore.H index 3f9c654cc1..96eb73ee5f 100644 --- a/src/fileFormats/fire/FIRECore.H +++ b/src/fileFormats/fire/FIRECore.H @@ -40,7 +40,7 @@ SourceFiles #include "labelList.H" #include "pointField.H" #include "IOstreams.H" -#include "NamedEnum.H" +#include "Enum.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -86,8 +86,8 @@ public: { POLY_ASCII, POLY_BINARY, - POLY_ASCII_COMPRESSED, - POLY_BINARY_COMPRESSED + POLY_ASCII_Z, + POLY_BINARY_Z }; @@ -97,11 +97,12 @@ public: //- Float type (binary format) typedef double fireReal_t; + protected: // Protected Data - static const NamedEnum file3dExtensions; + static const Enum file3dExtensions; // Protected Member Functions diff --git a/src/fileFormats/starcd/STARCDCore.C b/src/fileFormats/starcd/STARCDCore.C index 7ea833b488..412738131e 100644 --- a/src/fileFormats/starcd/STARCDCore.C +++ b/src/fileFormats/starcd/STARCDCore.C @@ -33,40 +33,22 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::NamedEnum - Foam::fileFormats::STARCDCore::fileHeaders_; - -const Foam::NamedEnum - Foam::fileFormats::STARCDCore::fileExtensions_; - -namespace Foam -{ - template<> - const char* Foam::NamedEnum - < - Foam::fileFormats::STARCDCore::fileHeader, - 3 - >::names[] = +const Foam::Enum + Foam::fileFormats::STARCDCore::fileHeaders_ { - "PROSTAR_CELL", - "PROSTAR_VERTEX", - "PROSTAR_BOUNDARY" + { fileHeader::HEADER_CEL, "PROSTAR_CELL" }, + { fileHeader::HEADER_VRT, "PROSTAR_VERTEX" }, + { fileHeader::HEADER_BND, "PROSTAR_BOUNDARY" } }; - template<> - const char* Foam::NamedEnum - < - Foam::fileFormats::STARCDCore::fileExt, - 4 - >::names[] = +const Foam::Enum + Foam::fileFormats::STARCDCore::fileExtensions_ { - "cel", - "vrt", - "bnd", - "inp" + { fileExt::CEL_FILE, "cel" }, + { fileExt::VRT_FILE, "vrt" }, + { fileExt::BND_FILE, "bnd" }, + { fileExt::INP_FILE, "inp" } }; -} - const char* const Foam::fileFormats::STARCDCore::defaultBoundaryName = "Default_Boundary_Region"; diff --git a/src/fileFormats/starcd/STARCDCore.H b/src/fileFormats/starcd/STARCDCore.H index cae3d1e7c0..21f64cae72 100644 --- a/src/fileFormats/starcd/STARCDCore.H +++ b/src/fileFormats/starcd/STARCDCore.H @@ -36,7 +36,7 @@ SourceFiles #define STARCDCore_H #include "IFstream.H" -#include "NamedEnum.H" +#include "Enum.H" #include "pointField.H" #include "Map.H" #include "FixedList.H" @@ -113,8 +113,8 @@ private: // Private Data - static const NamedEnum fileHeaders_; - static const NamedEnum fileExtensions_; + static const Enum fileHeaders_; + static const Enum fileExtensions_; protected: diff --git a/src/fileFormats/stl/STLReader.C b/src/fileFormats/stl/STLReader.C index b7b91a0bb7..ca7451d886 100644 --- a/src/fileFormats/stl/STLReader.C +++ b/src/fileFormats/stl/STLReader.C @@ -26,6 +26,7 @@ License #include "STLReader.H" #include "Map.H" #include "IFstream.H" +#include "mergePoints.H" #undef DEBUG_STLBINARY @@ -202,4 +203,38 @@ void Foam::fileFormats::STLReader::clear() } +Foam::label Foam::fileFormats::STLReader::mergePointsMap +( + labelList& pointMap +) const +{ + // With the merge distance depending on the input format (ASCII | BINARY), + // but must be independent of WM_SP or WM_DP flag. + // - floatScalarSMALL = 1e-6 + // - doubleScalarSMALL = 1e-15 + + return mergePointsMap + ( + (format_ == BINARY ? 10 : 100) * doubleScalarSMALL, + pointMap + ); +} + + +Foam::label Foam::fileFormats::STLReader::mergePointsMap +( + const scalar mergeTol, + labelList& pointMap +) const +{ + return Foam::mergePoints + ( + points_, + mergeTol, + false, // verbose + pointMap + ); +} + + // ************************************************************************* // diff --git a/src/fileFormats/stl/STLReader.H b/src/fileFormats/stl/STLReader.H index 9ed6838bc1..e9873aafe7 100644 --- a/src/fileFormats/stl/STLReader.H +++ b/src/fileFormats/stl/STLReader.H @@ -61,7 +61,7 @@ class STLReader bool sorted_; //- The points supporting the facets - pointField points_; + List points_; //- The zones associated with the faces List