Commit b6b61a4c authored by sergio's avatar sergio
Browse files

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

parents e3701a47 6e154d84
......@@ -40,7 +40,7 @@ Usage: $Script [OPTION] <file>
* Create bash completions for OpenFOAM applications and write to <file>.
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]/ && /</ {print $1}' <<< "$appHelp"))
optsWithArgs=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$appHelp"))
# Options without args
opts=($(awk '/^ *-[a-z]/ && !/</ {print $1}' <<< "$appHelp"))
opts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$appHelp"))
cat<<WRITECOMPLETION >> $outFile
unset -f _${appName}
......
......@@ -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<Field<point_type>> tPoints(new Field<point_type>(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<point_type> d(tPoints - compareOrigin);
List<scalar> magSqrD(d.size());
forAll(d, pointi)
List<scalar> 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<scalar> sortedTol(points.size());
Field<scalar> 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];
......
......@@ -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;
......
......@@ -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::coordFormat>
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::coordFormat, 5>
Foam::coordSet::coordFormatNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......
......@@ -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<coordFormat, 5> coordFormatNames_;
static const Enum<coordFormat> coordFormatNames_;
protected:
......
......@@ -27,24 +27,14 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::NamedEnum<Foam::fileFormats::FIRECore::fileExt3d, 4>
Foam::fileFormats::FIRECore::file3dExtensions;
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::fileFormats::FIRECore::fileExt3d,
4
>::names[] =
const Foam::Enum<Foam::fileFormats::FIRECore::fileExt3d>
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 * * * * * * * * * * * * * * //
......
......@@ -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<fileExt3d, 4> file3dExtensions;
static const Enum<fileExt3d> file3dExtensions;
// Protected Member Functions
......
......@@ -33,40 +33,22 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::NamedEnum<Foam::fileFormats::STARCDCore::fileHeader, 3>
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[] =
const Foam::Enum<Foam::fileFormats::STARCDCore::fileHeader>
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::fileExt>
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";
......
......@@ -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<fileHeader, 3> fileHeaders_;
static const NamedEnum<fileExt, 4> fileExtensions_;
static const Enum<fileHeader> fileHeaders_;
static const Enum<fileExt> fileExtensions_;
protected:
......
......@@ -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
);
}
// ************************************************************************* //
......@@ -61,7 +61,7 @@ class STLReader
bool sorted_;
//- The points supporting the facets
pointField points_;
List<STLpoint> points_;
//- The zones associated with the faces
List<label> zoneIds_;
......@@ -117,6 +117,15 @@ public:
//- Flush all values
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?
inline bool sorted() const
{
......@@ -124,7 +133,7 @@ public:
}
//- Return full access to the points
inline pointField& points()
inline List<STLpoint>& points()
{
return points_;
}
......
......@@ -23,9 +23,10 @@ License
\*---------------------------------------------------------------------------*/
%{
%option prefix="yySTL"
%option yyclass="yySTLFlexLexer"
#undef yyFlexLexer
%{
/* ------------------------------------------------------------------------ *\
------ local definitions
......@@ -35,9 +36,9 @@ License
#include "OSspecific.H"
using namespace Foam;
// Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called
//! \cond dummy
#if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION < 34
int yyFlexLexer::yylex()
{
FatalErrorInFunction
......@@ -45,29 +46,29 @@ int yyFlexLexer::yylex()
<< abort(FatalError);
return 0;
}
#endif
//! \endcond
// Dummy yywrap to keep yylex happy at compile time.
// It is called by yylex but is not used as the mechanism to change file.
// See <<EOF>>
//! \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()
#else
int yyFlexLexer::yywrap()
int yySTLFlexLexer::yywrap()
#endif
{
return 1;
}
//! \endcond
//- A lexer for parsing STL ASCII files.
// Returns DynamicList(s) of points and facets (zoneIds).
// The facets are within a solid/endsolid grouping
class STLASCIILexer
:
public yyFlexLexer
public yySTLFlexLexer
{
// Private data
......@@ -76,7 +77,7 @@ class STLASCIILexer
label lineNo_;
word startError_;
DynamicList<point> points_;
DynamicList<STLpoint> points_;
DynamicList<label> facets_;
DynamicList<word> names_;
DynamicList<label> sizes_;
......@@ -95,7 +96,7 @@ public:
//- The lexer function itself
int lex();
// Access
// Access
//- Do all the solid groups appear in order?
inline bool sorted() const
......@@ -104,7 +105,7 @@ public:
}
//- A list of unstitched triangle points
inline DynamicList<point>& points()
inline DynamicList<STLpoint>& points()
{
return points_;
}
......@@ -132,7 +133,7 @@ public:
STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
:
yyFlexLexer(is),
yySTLFlexLexer(is),
sorted_(true),
groupID_(-1),
lineNo_(1),
......@@ -145,6 +146,7 @@ STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
------ cppLexer::yylex()
\* ------------------------------------------------------------------------ */
#undef YY_DECL
#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
// char* endPtr;
STLpoint normal;
label cmpt = 0; // Component index when reading vertex
STLpoint vertex;
label cmpt = 0; // component index used for reading vertex
// STLpoint normal;
static const char* stateNames[7] =
{
......@@ -237,154 +239,167 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
/* ------ Reading control header ------ */
{solid} {
BEGIN(readSolidName);
}
BEGIN(readSolidName);
}
<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);
if (fnd != lookup_.end())
auto iter = lookup_.cfind(solidName);
if (iter.found())
{
if (groupID_ != iter.object())
{
if (groupID_ != fnd())
{
// group appeared out of order
sorted_ = false;
}
groupID_ = fnd();
sorted_ = false; // Group appeared out of order
groupID_ = iter.object();
}
else
}
else
{
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{
groupID_ = sizes_.size();
lookup_.insert(name, groupID_);
names_.append(name);
names_.append(solidName);
sizes_.append(0);
}
BEGIN(INITIAL);
else
{
FatalErrorInFunction<< "Duplicate solid-name: " << solidName
<< exit(FatalError);
}
}
BEGIN(INITIAL);
}
<readSolidName>{space}\n {
word name("solid");
const word solidName("solid"); // Could also use solid0, solid1, ...
HashTable<label>::const_iterator fnd = lookup_.find(name);
if (fnd != lookup_.end())
auto iter = lookup_.cfind(solidName);
if (iter.found())
{
if (groupID_ != iter.object())
{
if (groupID_ != fnd())
{
// group appeared out of order
sorted_ = false;
}
groupID_ = fnd();
sorted_ = false; // Group appeared out of order
groupID_ = iter.object();
}
else
}
else
{
groupID_ = sizes_.size();
if (lookup_.insert(solidName, groupID_))
{
groupID_ = sizes_.size();
lookup_.insert(name, groupID_);
names_.append(name);
names_.append(solidName);
sizes_.append(0);