Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
sergio
2017-06-12 11:29:53 -07:00
21 changed files with 414 additions and 322 deletions

View File

@ -40,7 +40,7 @@ Usage: $Script [OPTION] <file>
* Create bash completions for OpenFOAM applications and write to <file>. * Create bash completions for OpenFOAM applications and write to <file>.
By default searches directories \$FOAM_APPBIN and \$FOAM_USER_APPBIN By default searches directories \$FOAM_APPBIN and \$FOAM_USER_APPBIN
Options: Options:
-d | -directory Directory to process -d | -directory Directory to process
@ -149,10 +149,10 @@ do
echo "Processing $appName" echo "Processing $appName"
# Options with args # Options with args
optsWithArgs=($(awk '/^ *-[a-z]/ && /</ {print $1}' <<< "$appHelp")) optsWithArgs=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$appHelp"))
# Options without args # Options without args
opts=($(awk '/^ *-[a-z]/ && !/</ {print $1}' <<< "$appHelp")) opts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$appHelp"))
cat<<WRITECOMPLETION >> $outFile cat<<WRITECOMPLETION >> $outFile
unset -f _${appName} unset -f _${appName}

View File

@ -41,22 +41,28 @@ Foam::label Foam::mergePoints
{ {
typedef typename PointList::value_type point_type; typedef typename PointList::value_type point_type;
// Create a old to new point mapping array const label nPoints = points.size();
pointMap.setSize(points.size());
// Create an old to new point mapping array
pointMap.setSize(nPoints);
pointMap = -1; pointMap = -1;
if (points.empty()) if (!nPoints)
{ {
return 0; return 0;
} }
// Explicitly convert to Field to support various list types
tmp<Field<point_type>> tPoints(new Field<point_type>(points));
point_type compareOrigin = origin; point_type compareOrigin = origin;
if (origin == point_type::max) 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. // 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*... // x^2+y^2+z^2 + 2*mergeTol*(x+z+y) + mergeTol^2*...
// so the difference will be 2*mergeTol*(x+y+z) // 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 // Sort points by magSqr
const Field<point_type> d(tPoints - compareOrigin); List<scalar> magSqrDist(nPoints);
forAll(points, pointi)
List<scalar> magSqrD(d.size());
forAll(d, pointi)
{ {
magSqrD[pointi] = magSqr(d[pointi]); magSqrDist[pointi] = magSqr(points[pointi] - compareOrigin);
} }
labelList order; labelList order;
Foam::sortedOrder(magSqrD, order); Foam::sortedOrder(magSqrDist, order);
Field<scalar> sortedTol(points.size()); Field<scalar> sortedTol(nPoints);
forAll(order, sortI) forAll(order, sortI)
{ {
const label pointi = order[sortI]; const point_type& pt = points[order[sortI]];
// Convert to scalar precision // Use scalar precision
// NOTE: not yet using point_type template parameter sortedTol[sortI] =
const point pt 2*mergeTol*
( (
scalar(d[pointi].x()), mag(scalar(pt.x() - compareOrigin.x())),
scalar(d[pointi].y()), + mag(scalar(pt.y() - compareOrigin.y())),
scalar(d[pointi].z()) + mag(scalar(pt.z() - compareOrigin.z()))
); );
sortedTol[sortI] = 2*mergeTol*(mag(pt.x())+mag(pt.y())+mag(pt.z()));
} }
label newPointi = 0; label newPointi = 0;
@ -104,11 +107,11 @@ Foam::label Foam::mergePoints
label pointi = order[0]; label pointi = order[0];
pointMap[pointi] = newPointi++; pointMap[pointi] = newPointi++;
for (label sortI = 1; sortI < order.size(); sortI++) for (label sortI = 1; sortI < order.size(); ++sortI)
{ {
// Get original point index // Get original point index
const label pointi = order[sortI]; const label pointi = order[sortI];
const scalar mag2 = magSqrD[order[sortI]]; const scalar mag2 = magSqrDist[order[sortI]];
// Convert to scalar precision // Convert to scalar precision
// NOTE: not yet using point_type template parameter // NOTE: not yet using point_type template parameter
@ -127,8 +130,8 @@ Foam::label Foam::mergePoints
( (
label prevSortI = sortI - 1; label prevSortI = sortI - 1;
prevSortI >= 0 prevSortI >= 0
&& (mag(magSqrD[order[prevSortI]] - mag2) <= sortedTol[sortI]); && (mag(magSqrDist[order[prevSortI]] - mag2) <= sortedTol[sortI]);
prevSortI-- --prevSortI
) )
{ {
const label prevPointi = order[prevSortI]; const label prevPointi = order[prevSortI];

View File

@ -281,22 +281,22 @@ bool Foam::fileFormats::FIREMeshWriter::write(const fileName& meshName) const
if (FIRECore::file3dExtensions.hasEnum(ext)) if (FIRECore::file3dExtensions.hasEnum(ext))
{ {
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext]; FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
if (fireFileType == FIRECore::POLY_ASCII) if (fireFileType == FIRECore::fileExt3d::POLY_ASCII)
{ {
useBinary = false; useBinary = false;
useCompress = false; useCompress = false;
} }
else if (fireFileType == FIRECore::POLY_BINARY) else if (fireFileType == FIRECore::fileExt3d::POLY_BINARY)
{ {
useBinary = true; useBinary = true;
useCompress = false; useCompress = false;
} }
else if (fireFileType == FIRECore::POLY_ASCII_COMPRESSED) else if (fireFileType == FIRECore::fileExt3d::POLY_ASCII_Z)
{ {
useBinary = false; useBinary = false;
useCompress = true; useCompress = true;
} }
else if (fireFileType == FIRECore::POLY_BINARY_COMPRESSED) else if (fireFileType == FIRECore::fileExt3d::POLY_BINARY_Z)
{ {
useBinary = true; useBinary = true;
useCompress = true; useCompress = true;

View File

@ -27,26 +27,15 @@ License
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
namespace Foam const Foam::Enum<Foam::coordSet::coordFormat>
{ Foam::coordSet::coordFormatNames_
template<>
const char* Foam::NamedEnum
<
Foam::coordSet::coordFormat,
5
>::names[] =
{ {
"xyz", { coordFormat::XYZ, "xyz" },
"x", { coordFormat::X, "x" },
"y", { coordFormat::Y, "y" },
"z", { coordFormat::Z, "z" },
"distance" { coordFormat::DISTANCE, "distance" }
}; };
}
const Foam::NamedEnum<Foam::coordSet::coordFormat, 5>
Foam::coordSet::coordFormatNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -37,6 +37,7 @@ SourceFiles
#include "pointField.H" #include "pointField.H"
#include "word.H" #include "word.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,7 +71,7 @@ public:
private: private:
//- String representation of coordFormat enums //- String representation of coordFormat enums
static const NamedEnum<coordFormat, 5> coordFormatNames_; static const Enum<coordFormat> coordFormatNames_;
protected: protected:

View File

@ -27,24 +27,14 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::NamedEnum<Foam::fileFormats::FIRECore::fileExt3d, 4> const Foam::Enum<Foam::fileFormats::FIRECore::fileExt3d>
Foam::fileFormats::FIRECore::file3dExtensions; Foam::fileFormats::FIRECore::file3dExtensions
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::fileFormats::FIRECore::fileExt3d,
4
>::names[] =
{ {
"fpma", { fileExt3d::POLY_ASCII, "fpma" },
"fpmb", { fileExt3d::POLY_BINARY, "fpmb" },
"fpmaz", { fileExt3d::POLY_ASCII_Z, "fpmaz" },
"fpmbz" { fileExt3d::POLY_BINARY_Z, "fpmbz" }
}; };
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -40,7 +40,7 @@ SourceFiles
#include "labelList.H" #include "labelList.H"
#include "pointField.H" #include "pointField.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "NamedEnum.H" #include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -86,8 +86,8 @@ public:
{ {
POLY_ASCII, POLY_ASCII,
POLY_BINARY, POLY_BINARY,
POLY_ASCII_COMPRESSED, POLY_ASCII_Z,
POLY_BINARY_COMPRESSED POLY_BINARY_Z
}; };
@ -97,11 +97,12 @@ public:
//- Float type (binary format) //- Float type (binary format)
typedef double fireReal_t; typedef double fireReal_t;
protected: protected:
// Protected Data // Protected Data
static const NamedEnum<fileExt3d, 4> file3dExtensions; static const Enum<fileExt3d> file3dExtensions;
// Protected Member Functions // Protected Member Functions

View File

@ -33,40 +33,22 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::NamedEnum<Foam::fileFormats::STARCDCore::fileHeader, 3> const Foam::Enum<Foam::fileFormats::STARCDCore::fileHeader>
Foam::fileFormats::STARCDCore::fileHeaders_; Foam::fileFormats::STARCDCore::fileHeaders_
const Foam::NamedEnum<Foam::fileFormats::STARCDCore::fileExt, 4>
Foam::fileFormats::STARCDCore::fileExtensions_;
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::fileFormats::STARCDCore::fileHeader,
3
>::names[] =
{ {
"PROSTAR_CELL", { fileHeader::HEADER_CEL, "PROSTAR_CELL" },
"PROSTAR_VERTEX", { fileHeader::HEADER_VRT, "PROSTAR_VERTEX" },
"PROSTAR_BOUNDARY" { fileHeader::HEADER_BND, "PROSTAR_BOUNDARY" }
}; };
template<> const Foam::Enum<Foam::fileFormats::STARCDCore::fileExt>
const char* Foam::NamedEnum Foam::fileFormats::STARCDCore::fileExtensions_
<
Foam::fileFormats::STARCDCore::fileExt,
4
>::names[] =
{ {
"cel", { fileExt::CEL_FILE, "cel" },
"vrt", { fileExt::VRT_FILE, "vrt" },
"bnd", { fileExt::BND_FILE, "bnd" },
"inp" { fileExt::INP_FILE, "inp" }
}; };
}
const char* const Foam::fileFormats::STARCDCore::defaultBoundaryName = const char* const Foam::fileFormats::STARCDCore::defaultBoundaryName =
"Default_Boundary_Region"; "Default_Boundary_Region";

View File

@ -36,7 +36,7 @@ SourceFiles
#define STARCDCore_H #define STARCDCore_H
#include "IFstream.H" #include "IFstream.H"
#include "NamedEnum.H" #include "Enum.H"
#include "pointField.H" #include "pointField.H"
#include "Map.H" #include "Map.H"
#include "FixedList.H" #include "FixedList.H"
@ -113,8 +113,8 @@ private:
// Private Data // Private Data
static const NamedEnum<fileHeader, 3> fileHeaders_; static const Enum<fileHeader> fileHeaders_;
static const NamedEnum<fileExt, 4> fileExtensions_; static const Enum<fileExt> fileExtensions_;
protected: protected:

View File

@ -26,6 +26,7 @@ License
#include "STLReader.H" #include "STLReader.H"
#include "Map.H" #include "Map.H"
#include "IFstream.H" #include "IFstream.H"
#include "mergePoints.H"
#undef DEBUG_STLBINARY #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
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -61,7 +61,7 @@ class STLReader
bool sorted_; bool sorted_;
//- The points supporting the facets //- The points supporting the facets
pointField points_; List<STLpoint> points_;
//- The zones associated with the faces //- The zones associated with the faces
List<label> zoneIds_; List<label> zoneIds_;
@ -117,6 +117,15 @@ public:
//- Flush all values //- Flush all values
void clear(); void clear();
//- Calculate merge points mapping, return old to new pointMap.
// The merge tolerance based on ASCII or BINARY input format.
// \return number of unique points
label mergePointsMap(labelList& pointMap) const;
//- Calculate merge points mapping, return old to new pointMap.
// \return number of unique points
label mergePointsMap(const scalar mergeTol, labelList& pointMap) const;
//- File read was already sorted? //- File read was already sorted?
inline bool sorted() const inline bool sorted() const
{ {
@ -124,7 +133,7 @@ public:
} }
//- Return full access to the points //- Return full access to the points
inline pointField& points() inline List<STLpoint>& points()
{ {
return points_; return points_;
} }

View File

@ -23,9 +23,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
%{ %option prefix="yySTL"
%option yyclass="yySTLFlexLexer"
#undef yyFlexLexer %{
/* ------------------------------------------------------------------------ *\ /* ------------------------------------------------------------------------ *\
------ local definitions ------ local definitions
@ -35,9 +36,9 @@ License
#include "OSspecific.H" #include "OSspecific.H"
using namespace Foam; using namespace Foam;
// Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called // Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called
//! \cond dummy //! \cond dummy
#if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION < 34
int yyFlexLexer::yylex() int yyFlexLexer::yylex()
{ {
FatalErrorInFunction FatalErrorInFunction
@ -45,29 +46,29 @@ int yyFlexLexer::yylex()
<< abort(FatalError); << abort(FatalError);
return 0; return 0;
} }
#endif
//! \endcond //! \endcond
// Dummy yywrap to keep yylex happy at compile time. // Dummy yywrap to keep yylex happy at compile time.
// It is called by yylex but is not used as the mechanism to change file. // It is called by yylex but is not used as the mechanism to change file.
// See <<EOF>> // See <<EOF>>
//! \cond dummy //! \cond dummy
#if YY_FLEX_MINOR_VERSION < 6 && YY_FLEX_SUBMINOR_VERSION < 34 #if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION < 34
extern "C" int yywrap() extern "C" int yywrap()
#else #else
int yyFlexLexer::yywrap() int yySTLFlexLexer::yywrap()
#endif #endif
{ {
return 1; return 1;
} }
//! \endcond //! \endcond
//- A lexer for parsing STL ASCII files. //- A lexer for parsing STL ASCII files.
// Returns DynamicList(s) of points and facets (zoneIds). // Returns DynamicList(s) of points and facets (zoneIds).
// The facets are within a solid/endsolid grouping // The facets are within a solid/endsolid grouping
class STLASCIILexer class STLASCIILexer
: :
public yyFlexLexer public yySTLFlexLexer
{ {
// Private data // Private data
@ -76,7 +77,7 @@ class STLASCIILexer
label lineNo_; label lineNo_;
word startError_; word startError_;
DynamicList<point> points_; DynamicList<STLpoint> points_;
DynamicList<label> facets_; DynamicList<label> facets_;
DynamicList<word> names_; DynamicList<word> names_;
DynamicList<label> sizes_; DynamicList<label> sizes_;
@ -95,7 +96,7 @@ public:
//- The lexer function itself //- The lexer function itself
int lex(); int lex();
// Access // Access
//- Do all the solid groups appear in order? //- Do all the solid groups appear in order?
inline bool sorted() const inline bool sorted() const
@ -104,7 +105,7 @@ public:
} }
//- A list of unstitched triangle points //- A list of unstitched triangle points
inline DynamicList<point>& points() inline DynamicList<STLpoint>& points()
{ {
return points_; return points_;
} }
@ -132,7 +133,7 @@ public:
STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints) STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
: :
yyFlexLexer(is), yySTLFlexLexer(is),
sorted_(true), sorted_(true),
groupID_(-1), groupID_(-1),
lineNo_(1), lineNo_(1),
@ -145,6 +146,7 @@ STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
------ cppLexer::yylex() ------ cppLexer::yylex()
\* ------------------------------------------------------------------------ */ \* ------------------------------------------------------------------------ */
#undef YY_DECL
#define YY_DECL int STLASCIILexer::lex() #define YY_DECL int STLASCIILexer::lex()
%} %}
@ -202,9 +204,9 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
// End of read character pointer returned by strtof // End of read character pointer returned by strtof
// char* endPtr; // char* endPtr;
STLpoint normal; label cmpt = 0; // Component index when reading vertex
STLpoint vertex; STLpoint vertex;
label cmpt = 0; // component index used for reading vertex // STLpoint normal;
static const char* stateNames[7] = static const char* stateNames[7] =
{ {
@ -237,154 +239,167 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
/* ------ Reading control header ------ */ /* ------ Reading control header ------ */
{solid} { {solid} {
BEGIN(readSolidName); BEGIN(readSolidName);
} }
<readSolidName>{string} { <readSolidName>{string} {
word name(Foam::string::validate<word>(YYText())); const word solidName(Foam::string::validate<word>(YYText()));
HashTable<label>::const_iterator fnd = lookup_.find(name); auto iter = lookup_.cfind(solidName);
if (fnd != lookup_.end()) if (iter.found())
{
if (groupID_ != iter.object())
{ {
if (groupID_ != fnd()) sorted_ = false; // Group appeared out of order
{ groupID_ = iter.object();
// group appeared out of order }
sorted_ = false; }
} else
groupID_ = fnd(); {
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{
names_.append(solidName);
sizes_.append(0);
} }
else else
{ {
groupID_ = sizes_.size(); FatalErrorInFunction<< "Duplicate solid-name: " << solidName
lookup_.insert(name, groupID_); << exit(FatalError);
names_.append(name);
sizes_.append(0);
} }
BEGIN(INITIAL);
} }
BEGIN(INITIAL);
}
<readSolidName>{space}\n { <readSolidName>{space}\n {
word name("solid"); const word solidName("solid"); // Could also use solid0, solid1, ...
HashTable<label>::const_iterator fnd = lookup_.find(name); auto iter = lookup_.cfind(solidName);
if (fnd != lookup_.end()) if (iter.found())
{
if (groupID_ != iter.object())
{ {
if (groupID_ != fnd()) sorted_ = false; // Group appeared out of order
{ groupID_ = iter.object();
// group appeared out of order }
sorted_ = false; }
} else
groupID_ = fnd(); {
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{
names_.append(solidName);
sizes_.append(0);
} }
else else
{ {
groupID_ = sizes_.size(); FatalErrorInFunction<< "Duplicate solid-name: " << solidName
lookup_.insert(name, groupID_); << exit(FatalError);
names_.append(name);
sizes_.append(0);
} }
lineNo_++;
BEGIN(INITIAL);
} }
++lineNo_;
BEGIN(INITIAL);
}
{color} { {color} {
} /* ignore 'color' */
}
{facet} { {facet} {
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{normal} { <readFacet>{normal} {
BEGIN(readNormal); BEGIN(readNormal);
} }
<readNormal>{point} { <readNormal>{point} {
/* /*
skip reading normals: skip reading normals:
normal.x() = strtof(YYText(), &endPtr); normal.x() = strtof(YYText(), &endPtr);
normal.y() = strtof(endPtr, &endPtr); normal.y() = strtof(endPtr, &endPtr);
normal.z() = strtof(endPtr, &endPtr); normal.z() = strtof(endPtr, &endPtr);
normals_.append(normal); normals_.append(normal);
*/ */
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{outerloop} { <readFacet>{outerloop} {
BEGIN(readVertices); BEGIN(readVertices);
} }
<readVertices>{vertex} { <readVertices>{vertex} {
BEGIN(readVertex); BEGIN(readVertex);
} }
<readVertex>{space}{signedInteger}{space} { <readVertex>{space}{signedInteger}{space} {
vertex[cmpt++] = atol(YYText()); vertex[cmpt++] = atol(YYText());
if (cmpt == 3) if (cmpt == 3)
{ {
cmpt = 0; cmpt = 0;
points_.append(vertex); points_.append(vertex);
BEGIN(readVertices); BEGIN(readVertices);
}
} }
}
<readVertex>{space}{floatNum}{space} { <readVertex>{space}{floatNum}{space} {
vertex[cmpt++] = atof(YYText()); vertex[cmpt++] = atof(YYText());
if (cmpt == 3) if (cmpt == 3)
{ {
cmpt = 0; cmpt = 0;
points_.append(vertex); points_.append(vertex);
BEGIN(readVertices); BEGIN(readVertices);
}
} }
}
<readVertices>{endloop} { <readVertices>{endloop} {
BEGIN(readFacet); BEGIN(readFacet);
} }
<readFacet>{endfacet} { <readFacet>{endfacet} {
facets_.append(groupID_); facets_.append(groupID_);
sizes_[groupID_]++; sizes_[groupID_]++;
BEGIN(INITIAL); BEGIN(INITIAL);
} }
{endsolid} { {endsolid} {
} }
/* ------------------ Ignore remaining space and \n s. -------------------- */ /* ---------------- Ignore remaining spaces and newlines ------------------ */
<*>{space} {} <*>{space} {}
<*>\n { lineNo_++; } <*>\n { ++lineNo_; }
/* ------------------- Any other characters are errors -------------------- */ /* ------------------- Any other characters are errors -------------------- */
<*>. { <*>. {
startError_ = YYText(); startError_ = YYText();
yy_push_state(stlError); yy_push_state(stlError);
} }
/* ---------------------------- Error handler ----------------------------- */ /* ---------------------------- Error handler ----------------------------- */
<stlError>.* { <stlError>.* {
yy_pop_state(); yy_pop_state();
FatalErrorInFunction FatalErrorInFunction
<< "while " << stateNames[YY_START] << " on line " << lineNo_ << nl << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl
<< " expected " << stateExpects[YY_START] << " expected " << stateExpects[YY_START]
<< " but found '" << startError_.c_str() << YYText() << "'" << " but found '" << startError_.c_str() << YYText() << "'"
<< exit(FatalError); << exit(FatalError);
} }
/* ------------------------ On EOF terminate ---------------------------- */ /* ------------------------ On EOF terminate ---------------------------- */
<<EOF>> { <<EOF>> {
yyterminate(); yyterminate();
} }
%% %%

View File

@ -47,7 +47,7 @@ namespace Foam
class STLpoint class STLpoint
: :
public Vector<float> public floatVector
{ {
public: public:
@ -58,28 +58,34 @@ public:
inline STLpoint() inline STLpoint()
{} {}
//- Construct from base class
inline STLpoint(const floatVector& v)
:
floatVector(v)
{}
//- Construct from components //- Construct from components
inline STLpoint(float x, float y, float z) inline STLpoint(float x, float y, float z)
: :
Vector<float>(x, y, z) floatVector(x, y, z)
{} {}
//- Construct from components //- Construct from components
inline STLpoint(double x, double y, double z) inline STLpoint(double x, double y, double z)
: :
Vector<float>(float(x), float(y), float(z)) floatVector(float(x), float(y), float(z))
{} {}
//- Construct from point //- Construct from point
inline STLpoint(const point& pt) inline STLpoint(const point& pt)
: :
Vector<float>(float(pt.x()), float(pt.y()), float(pt.z())) floatVector(float(pt.x()), float(pt.y()), float(pt.z()))
{} {}
//- Construct from istream //- Construct from istream
inline STLpoint(Istream& is) inline STLpoint(Istream& is)
: :
Vector<float>(is) floatVector(is)
{} {}

View File

@ -35,50 +35,39 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(vtkUnstructuredReader, 1); defineTypeNameAndDebug(vtkUnstructuredReader, 1);
template<>
const char*
NamedEnum<vtkUnstructuredReader::vtkDataType, 8>::names[] =
{
"int",
"unsigned_int",
"long",
"unsigned_long",
"float",
"double",
"string",
"vtkIdType"
};
const NamedEnum<vtkUnstructuredReader::vtkDataType, 8>
vtkUnstructuredReader::vtkDataTypeNames;
template<>
const char*
NamedEnum<vtkUnstructuredReader::vtkDataSetType, 3>::names[] =
{
"FIELD",
"SCALARS",
"VECTORS"
};
const NamedEnum<vtkUnstructuredReader::vtkDataSetType, 3>
vtkUnstructuredReader::vtkDataSetTypeNames;
template<>
const char*
NamedEnum<vtkUnstructuredReader::parseMode, 5>::names[] =
{
"NOMODE",
"UNSTRUCTURED_GRID",
"POLYDATA",
"CELL_DATA",
"POINT_DATA"
};
const NamedEnum<vtkUnstructuredReader::parseMode, 5>
vtkUnstructuredReader::parseModeNames;
} }
const Foam::Enum<Foam::vtkUnstructuredReader::vtkDataType>
Foam::vtkUnstructuredReader::vtkDataTypeNames
{
{ vtkDataType::VTK_INT, "int" },
{ vtkDataType::VTK_UINT, "unsigned_int" },
{ vtkDataType::VTK_LONG, "long" },
{ vtkDataType::VTK_ULONG, "unsigned_long" },
{ vtkDataType::VTK_FLOAT, "float" },
{ vtkDataType::VTK_DOUBLE, "double" },
{ vtkDataType::VTK_STRING, "string" },
{ vtkDataType::VTK_ID, "vtkIdType" }
};
const Foam::Enum<Foam::vtkUnstructuredReader::vtkDataSetType>
Foam::vtkUnstructuredReader::vtkDataSetTypeNames
{
{ vtkDataSetType::VTK_FIELD, "FIELD" },
{ vtkDataSetType::VTK_SCALARS, "SCALARS" },
{ vtkDataSetType::VTK_VECTORS, "VECTORS" }
};
const Foam::Enum<Foam::vtkUnstructuredReader::parseMode>
Foam::vtkUnstructuredReader::parseModeNames
{
{ parseMode::NOMODE, "NOMODE" },
{ parseMode::UNSTRUCTURED_GRID, "UNSTRUCTURED_GRID" },
{ parseMode::POLYDATA, "POLYDATA" },
{ parseMode::CELL_DATA, "CELL_DATA" },
{ parseMode::POINT_DATA, "POINT_DATA" }
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -51,7 +51,7 @@ SourceFiles
#include "objectRegistry.H" #include "objectRegistry.H"
#include "cellShapeList.H" #include "cellShapeList.H"
#include "HashSet.H" #include "HashSet.H"
#include "NamedEnum.H" #include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -83,7 +83,7 @@ public:
VTK_ID VTK_ID
}; };
static const NamedEnum<vtkDataType, 8> vtkDataTypeNames; static const Enum<vtkDataType> vtkDataTypeNames;
//- Enumeration defining the vtk dataset types //- Enumeration defining the vtk dataset types
@ -94,11 +94,10 @@ public:
VTK_VECTORS VTK_VECTORS
}; };
static const NamedEnum<vtkDataSetType, 3> vtkDataSetTypeNames; static const Enum<vtkDataSetType> vtkDataSetTypeNames;
//- Enumeration defining the parse mode - what type of data is being //- Enumeration defining the parse mode - type of data being read
// read
enum parseMode enum parseMode
{ {
NOMODE, NOMODE,
@ -108,7 +107,7 @@ public:
POINT_DATA POINT_DATA
}; };
static const NamedEnum<parseMode, 5> parseModeNames; static const Enum<parseMode> parseModeNames;
private: private:

View File

@ -222,7 +222,7 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
// Set the precision of the points data to 10 // Set the precision of the points data to 10
os.precision(10); os.precision(10);
Info<< "points: " << pointLst.size() << endl; Info<< nl << "points: " << pointLst.size() << endl;
putFireLabel(os, pointLst.size()); putFireLabel(os, pointLst.size());
newline(os); newline(os);

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STLsurfaceFormat.H" #include "STLsurfaceFormat.H"
#include "labelledTri.H"
#include "triPointRef.H" #include "triPointRef.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -126,13 +125,25 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
{ {
this->clear(); this->clear();
// read in the values // Read in the values
STLReader reader(filename); STLReader reader(filename);
// transfer points // Get the map for stitched surface points, with merge tolerance depending
this->storedPoints().transfer(reader.points()); // on the input format
labelList pointMap;
const label nUniquePoints = reader.mergePointsMap(pointMap);
// retrieve the original zone information const auto& readpts = reader.points();
// Assign points
pointField& pointLst = this->storedPoints();
pointLst.setSize(nUniquePoints);
forAll(readpts, pointi)
{
pointLst[pointMap[pointi]] = readpts[pointi];
}
// Retrieve the original zone information
List<word> names(reader.names().xfer()); List<word> names(reader.names().xfer());
List<label> sizes(reader.sizes().xfer()); List<label> sizes(reader.sizes().xfer());
List<label> zoneIds(reader.zoneIds().xfer()); List<label> zoneIds(reader.zoneIds().xfer());
@ -142,16 +153,21 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
if (reader.sorted()) if (reader.sorted())
{ {
// already sorted - generate directly // Already sorted - generate directly
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
const label startPt = 3*facei; const label startPt = 3*facei;
faceLst[facei] = Face{startPt, startPt+1, startPt+2}; faceLst[facei] = Face
{
pointMap[startPt],
pointMap[startPt+1],
pointMap[startPt+2]
};
} }
} }
else else
{ {
// unsorted - determine the sorted order: // Unsorted - determine the sorted order:
// avoid SortableList since we discard the main list anyhow // avoid SortableList since we discard the main list anyhow
List<label> faceMap; List<label> faceMap;
sortedOrder(zoneIds, faceMap); sortedOrder(zoneIds, faceMap);
@ -160,7 +176,12 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
faceLst[facei] = Face{startPt, startPt+1, startPt+2}; faceLst[facei] = Face
{
pointMap[startPt],
pointMap[startPt+1],
pointMap[startPt+2]
};
} }
} }
zoneIds.clear(); zoneIds.clear();
@ -177,7 +198,6 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
this->addZones(sizes); this->addZones(sizes);
} }
this->addZonesToFaces(); // for labelledTri this->addZonesToFaces(); // for labelledTri
this->stitchFaces(SMALL);
return true; return true;
} }

View File

@ -78,13 +78,24 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
{ {
this->clear(); this->clear();
// read in the values // Read in the values
TRIsurfaceFormatCore reader(filename); TRIsurfaceFormatCore reader(filename);
// transfer points // Get the map for stitched surface points
this->storedPoints().transfer(reader.points()); labelList pointMap;
const label nUniquePoints = reader.mergePointsMap(pointMap);
// retrieve the original zone information const auto& readpts = reader.points();
// Assign points
pointField& pointLst = this->storedPoints();
pointLst.setSize(nUniquePoints);
forAll(readpts, pointi)
{
pointLst[pointMap[pointi]] = readpts[pointi];
}
// Retrieve the original zone information
List<label> sizes(reader.sizes().xfer()); List<label> sizes(reader.sizes().xfer());
List<label> zoneIds(reader.zoneIds().xfer()); List<label> zoneIds(reader.zoneIds().xfer());
@ -93,16 +104,21 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
if (reader.sorted()) if (reader.sorted())
{ {
// already sorted - generate directly // Already sorted - generate directly
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
const label startPt = 3*facei; const label startPt = 3*facei;
faceLst[facei] = Face{startPt, startPt+1, startPt+2}; faceLst[facei] = Face
{
pointMap[startPt],
pointMap[startPt+1],
pointMap[startPt+2]
};
} }
} }
else else
{ {
// unsorted - determine the sorted order: // Unsorted - determine the sorted order:
// avoid SortableList since we discard the main list anyhow // avoid SortableList since we discard the main list anyhow
List<label> faceMap; List<label> faceMap;
sortedOrder(zoneIds, faceMap); sortedOrder(zoneIds, faceMap);
@ -111,7 +127,12 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
faceLst[facei] = Face{startPt, startPt+1, startPt+2}; faceLst[facei] = Face
{
pointMap[startPt],
pointMap[startPt+1],
pointMap[startPt+2]
};
} }
} }
zoneIds.clear(); zoneIds.clear();
@ -121,7 +142,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
this->addZones(sizes); this->addZones(sizes);
this->addZonesToFaces(); // for labelledTri this->addZonesToFaces(); // for labelledTri
this->stitchFaces(SMALL);
return true; return true;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
#include "IFstream.H" #include "IFstream.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "mergePoints.H"
#include "Map.H" #include "Map.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -71,7 +72,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
// uses similar structure as STL, just some points // uses similar structure as STL, just some points
// the rest of the reader resembles the STL binary reader // the rest of the reader resembles the STL binary reader
DynamicList<point> dynPoints; DynamicList<STLpoint> dynPoints;
DynamicList<label> dynZones; DynamicList<label> dynZones;
DynamicList<label> dynSizes; DynamicList<label> dynSizes;
HashTable<label> lookup; HashTable<label> lookup;
@ -94,7 +95,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
IStringStream lineStream(line); IStringStream lineStream(line);
point p STLpoint p
( (
readScalar(lineStream), readScalar(lineStream),
readScalar(lineStream), readScalar(lineStream),
@ -106,7 +107,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
dynPoints.append(p); dynPoints.append(p);
dynPoints.append dynPoints.append
( (
point STLpoint
( (
readScalar(lineStream), readScalar(lineStream),
readScalar(lineStream), readScalar(lineStream),
@ -115,7 +116,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
); );
dynPoints.append dynPoints.append
( (
point STLpoint
( (
readScalar(lineStream), readScalar(lineStream),
readScalar(lineStream), readScalar(lineStream),
@ -179,4 +180,43 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
} }
void Foam::fileFormats::TRIsurfaceFormatCore::clear()
{
sorted_ = true;
points_.clear();
zoneIds_.clear();
sizes_.clear();
}
Foam::label Foam::fileFormats::TRIsurfaceFormatCore::mergePointsMap
(
labelList& pointMap
) const
{
// Use merge tolerance as per STL ascii
return mergePointsMap
(
100 * doubleScalarSMALL,
pointMap
);
}
Foam::label Foam::fileFormats::TRIsurfaceFormatCore::mergePointsMap
(
const scalar mergeTol,
labelList& pointMap
) const
{
return Foam::mergePoints
(
points_,
mergeTol,
false, // verbose
pointMap
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,7 +36,7 @@ SourceFiles
#define TRIsurfaceFormatCore_H #define TRIsurfaceFormatCore_H
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "triFace.H" #include "STLpoint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,7 +58,7 @@ class TRIsurfaceFormatCore
bool sorted_; bool sorted_;
//- The points supporting the facets //- The points supporting the facets
pointField points_; List<STLpoint> points_;
//- The zones associated with the faces //- The zones associated with the faces
List<label> zoneIds_; List<label> zoneIds_;
@ -83,7 +83,7 @@ public:
// Constructors // Constructors
//- Read from file, filling in the information //- Read from file, filling in the information
TRIsurfaceFormatCore(const fileName&); TRIsurfaceFormatCore(const fileName& filename);
//- Destructor //- Destructor
@ -92,35 +92,39 @@ public:
// Member Functions // Member Functions
//- Flush all values
void clear();
//- Calculate merge points mapping, return old to new pointMap.
// Use merge tolerance as per STL ascii
// \return number of unique points
label mergePointsMap(labelList& pointMap) const;
//- Calculate merge points mapping, return old to new pointMap.
// \return number of unique points
label mergePointsMap(const scalar mergeTol, labelList& pointMap) const;
//- File read was already sorted //- File read was already sorted
bool sorted() const inline bool sorted() const
{ {
return sorted_; return sorted_;
} }
//- Flush all values
void clear()
{
sorted_ = true;
points_.clear();
zoneIds_.clear();
sizes_.clear();
}
//- Return full access to the points //- Return full access to the points
pointField& points() inline List<STLpoint>& points()
{ {
return points_; return points_;
} }
//- Return full access to the zones //- Return full access to the zones
List<label>& zoneIds() inline List<label>& zoneIds()
{ {
return zoneIds_; return zoneIds_;
} }
//- The list of zone sizes in the order of their first appearance //- The list of zone sizes in the order of their first appearance
List<label>& sizes() inline List<label>& sizes()
{ {
return sizes_; return sizes_;
} }

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STLReader.H" #include "STLReader.H"
#include "mergePoints.H"
#include "triSurface.H" #include "triSurface.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -42,22 +41,13 @@ bool Foam::triSurface::readSTL(const fileName& STLfileName, bool forceBinary)
) )
); );
// Stitch points // Get the map for stitched surface points, with merge tolerance depending
// on the input format
labelList pointMap; labelList pointMap;
label nUniquePoints = mergePoints const label nUniquePoints = reader.mergePointsMap(pointMap);
(
reader.points(),
(
// With the merge distance depending on the input format
(reader.stlFormat() == fileFormats::STLCore::BINARY ? 10 : 100)
* SMALL
),
false, // verbose
pointMap // old to new point map
);
const pointField& readpts = reader.points(); const auto& readpts = reader.points();
const labelList& zoneIds = reader.zoneIds(); const labelList& zoneIds = reader.zoneIds();
pointField& pointLst = storedPoints(); pointField& pointLst = storedPoints();
List<Face>& faceLst = storedFaces(); List<Face>& faceLst = storedFaces();
@ -84,18 +74,16 @@ bool Foam::triSurface::readSTL(const fileName& STLfileName, bool forceBinary)
f.region() = zoneIds[i]; f.region() = zoneIds[i];
} }
// Set patch names (and sizes) // Set patch name/index.
// - there is likely a more efficient means of doing this
if (reader.stlFormat() == fileFormats::STLCore::ASCII) if (reader.stlFormat() == fileFormats::STLCore::ASCII)
{ {
const List<word>& names = reader.names(); const List<word>& names = reader.names();
patches_.setSize(names.size()); patches_.setSize(names.size());
forAll(names, namei) forAll(patches_, patchi)
{ {
patches_[namei].name() = names[namei]; patches_[patchi] = geometricSurfacePatch(names[patchi], patchi);
} }
setDefaultPatches();
} }
return true; return true;