Merge branch 'feature-trisurface-cleanup' into 'develop'

consolidate surfaceFormats for reading/writing triSurface

See merge request Development/OpenFOAM-plus!174
This commit is contained in:
Andrew Heather
2017-11-30 08:46:43 +00:00
111 changed files with 2646 additions and 4610 deletions

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
{ {
argList::addNote argList::addNote
( (
"convert between surface formats" "convert between surface formats, using triSurface library components"
); );
argList::noParallel(); argList::noParallel();
@ -96,16 +96,6 @@ int main(int argc, char *argv[])
argList args(argc, argv); argList args(argc, argv);
if (args.optionFound("writePrecision"))
{
label writePrecision = args.optionRead<label>("writePrecision");
IOstream::defaultPrecision(writePrecision);
Sout.precision(writePrecision);
Info<< "Output write precision set to " << writePrecision << endl;
}
const fileName importName = args[1]; const fileName importName = args[1];
const fileName exportName = args[2]; const fileName exportName = args[2];
@ -116,6 +106,26 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
// Check that reading/writing is supported
if
(
!triSurface::canRead(importName, true)
|| !triSurface::canWriteType(exportName.ext(), true)
)
{
return 1;
}
if (args.optionFound("writePrecision"))
{
label writePrecision = args.optionRead<label>("writePrecision");
IOstream::defaultPrecision(writePrecision);
Sout.precision(writePrecision);
Info<< "Output write precision set to " << writePrecision << endl;
}
const scalar scaleFactor = args.optionLookupOrDefault<scalar>("scale", -1); const scalar scaleFactor = args.optionLookupOrDefault<scalar>("scale", -1);
Info<< "Reading : " << importName << endl; Info<< "Reading : " << importName << endl;

View File

@ -75,7 +75,7 @@ int main(int argc, char *argv[])
{ {
argList::addNote argList::addNote
( (
"convert between surface formats" "convert between surface formats, using MeshSurface library components"
); );
argList::noParallel(); argList::noParallel();
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
// check that reading/writing is supported // Check that reading/writing is supported
if if
( (
!MeshedSurface<face>::canRead(importName, true) !MeshedSurface<face>::canRead(importName, true)

View File

@ -288,6 +288,10 @@ public:
// Member Functions // Member Functions
//- Suppress direct swapping, since storage containers may be const
void swap(PrimitivePatch&) = delete;
// Access // Access
//- Return reference to global points //- Return reference to global points
@ -320,9 +324,9 @@ public:
label nInternalEdges() const; label nInternalEdges() const;
//- Is internal edge? //- Is internal edge?
bool isInternalEdge(const label edgeI) const bool isInternalEdge(const label edgei) const
{ {
return edgeI < nInternalEdges(); return edgei < nInternalEdges();
} }
//- Return list of boundary points, //- Return list of boundary points,

View File

@ -365,13 +365,18 @@ namespace stringOps
const std::string& delim const std::string& delim
); );
//- Split string into sub-strings using a fixed field width //- Split string into sub-strings using a fixed field width.
// Behaviour is ill-defined if width is zero. // Behaviour is ill-defined if width is zero.
// \param str the string to be split
// \param width the fixed field width for each sub-string
// \param start the optional offset of where to start the splitting.
// Any text prior to start is ignored in the operation.
template<class StringType> template<class StringType>
Foam::SubStrings<StringType> splitFixed Foam::SubStrings<StringType> splitFixed
( (
const StringType& str, const StringType& str,
const std::string::size_type width const std::string::size_type width,
const std::string::size_type start = 0
); );
//- Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC) //- Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)

View File

@ -183,7 +183,8 @@ template<class StringType>
Foam::SubStrings<StringType> Foam::stringOps::splitFixed Foam::SubStrings<StringType> Foam::stringOps::splitFixed
( (
const StringType& str, const StringType& str,
const std::string::size_type width const std::string::size_type width,
const std::string::size_type start
) )
{ {
Foam::SubStrings<StringType> lst; Foam::SubStrings<StringType> lst;
@ -195,7 +196,7 @@ Foam::SubStrings<StringType> Foam::stringOps::splitFixed
const auto len = str.size(); const auto len = str.size();
lst.reserve(1 + (len / width)); lst.reserve(1 + (len / width));
for (std::string::size_type pos = 0; pos < len; pos += width) for (std::string::size_type pos = start; pos < len; pos += width)
{ {
const auto end = (pos + width); const auto end = (pos + width);

View File

@ -40,12 +40,6 @@ Foam::fileFormats::FIRECore::file3dExtensions
}; };
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::FIRECore::FIRECore()
{}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam::label Foam::fileFormats::FIRECore::readPoints Foam::label Foam::fileFormats::FIRECore::readPoints

View File

@ -108,7 +108,7 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Construct null //- Construct null
FIRECore(); FIRECore() = default;
//- Read points. //- Read points.

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / 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) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,11 +24,27 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "NASCore.H" #include "NASCore.H"
#include "IOmanip.H"
#include "Ostream.H"
#include "parsing.H" #include "parsing.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::Enum
<
Foam::fileFormats::NASCore::fieldFormat
>
Foam::fileFormats::NASCore::fieldFormatNames
{
{ fieldFormat::SHORT, "short" },
{ fieldFormat::LONG, "long" },
{ fieldFormat::FREE, "free" },
};
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str) Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const std::string& str)
{ {
const auto signPos = str.find_last_of("+-"); const auto signPos = str.find_last_of("+-");
@ -54,7 +70,7 @@ Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str)
if if
( (
readScalar(str.substr(0, signPos), value) // Mantissa readScalar(str.substr(0, signPos), value) // Mantissa
&& readInt(str.substr(signPos), exponent) // Exponent (with sign) && readInt(str.substr(signPos), exponent) // Exponent (with sign)
) )
{ {
// Note: this does not catch underflow/overflow // Note: this does not catch underflow/overflow
@ -74,10 +90,98 @@ Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str)
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // std::string Foam::fileFormats::NASCore::nextNasField
(
const std::string& str,
std::string::size_type& pos,
std::string::size_type len
)
{
const auto beg = pos;
const auto end = str.find(',', pos);
Foam::fileFormats::NASCore::NASCore() if (end == std::string::npos)
{} {
pos = beg + len; // Continue after field width
}
else
{
len = (end - beg); // Efffective width
pos = end + 1; // Continue after comma
}
return str.substr(beg, len);
}
void Foam::fileFormats::NASCore::setPrecision
(
Ostream& os,
const fieldFormat format
)
{
os.setf(ios_base::scientific);
// Capitalise the E marker
os.setf(ios_base::uppercase);
const label offset = 7;
label prec = 16 - offset;
switch (format)
{
case fieldFormat::SHORT :
{
prec = 8 - offset;
break;
}
case fieldFormat::LONG :
case fieldFormat::FREE :
{
prec = 16 - offset;
break;
}
}
os.precision(prec);
}
Foam::Ostream& Foam::fileFormats::NASCore::writeKeyword
(
Ostream& os,
const word& keyword,
const fieldFormat format
)
{
os.setf(ios_base::left);
switch (format)
{
case fieldFormat::SHORT :
{
os << setw(8) << keyword;
break;
}
case fieldFormat::LONG :
{
os << setw(8) << word(keyword + '*');
break;
}
case fieldFormat::FREE :
{
os << keyword;
break;
}
}
os.unsetf(ios_base::left);
return os;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / 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) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,11 +37,16 @@ SourceFiles
#include "scalar.H" #include "scalar.H"
#include "string.H" #include "string.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declarations
class Ostream;
namespace fileFormats namespace fileFormats
{ {
@ -53,23 +58,64 @@ class NASCore
{ {
public: public:
// Public Member Functions //- File field formats
enum fieldFormat
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
static scalar readNasScalar(const string& str);
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
// \deprecated use readNasScalar instead (deprecated Sep 2017)
inline static scalar parseNASCoord(const string& str)
{ {
return readNasScalar(str); SHORT, //<! Short format (field width = 8)
} LONG, //<! Long format (field width = 16)
FREE //<! Free format (comma-separated fields)
};
//- Selection names for the NASTRAN file field formats
static const Enum<fieldFormat> fieldFormatNames;
// Constructors // Constructors
//- Construct null //- Construct null
NASCore(); NASCore() = default;
// Public Static Member Functions
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
static scalar readNasScalar(const std::string& str);
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
// \deprecated use readNasScalar instead (deprecated Sep 2017)
inline static scalar parseNASCoord(const std::string& str)
{
return readNasScalar(str);
}
//- A string::substr() to handle fixed-format and free-format NASTRAN.
// Returns the substr to the next comma (if found) or the given length
//
// \param str The string to extract from
// \param pos On input, the position of the first character of the
// substring. On output, advances to the next position to use.
// \param len The fixed-format length to use if a comma is not found.
static std::string nextNasField
(
const std::string& str,
std::string::size_type& pos,
std::string::size_type len
);
//- Set output stream precision and format flags
static void setPrecision(Ostream& os, const fieldFormat format);
//- Write initial keyword (eg, 'GRID' or 'GRID*') followed by the
//- requisite number of spaces for the field-width
static Ostream& writeKeyword
(
Ostream& os,
const word& keyword,
const fieldFormat format
);
}; };

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 | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "clock.H" #include "clock.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
#include "DynamicList.H"
#include "StringStream.H" #include "StringStream.H"
#include "OSspecific.H" #include "OSspecific.H"
@ -85,12 +86,6 @@ Foam::fileFormats::STARCDCore::starToFoamFaceAddr =
}; };
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDCore::STARCDCore()
{}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDCore::readHeader bool Foam::fileFormats::STARCDCore::readHeader
@ -173,8 +168,8 @@ void Foam::fileFormats::STARCDCore::removeFiles(const fileName& base)
Foam::label Foam::fileFormats::STARCDCore::readPoints Foam::label Foam::fileFormats::STARCDCore::readPoints
( (
IFstream& is, IFstream& is,
pointField& points, List<point>& points,
labelList& ids List<label>& ids
) )
{ {
label maxId = 0; label maxId = 0;
@ -219,7 +214,7 @@ Foam::label Foam::fileFormats::STARCDCore::readPoints
void Foam::fileFormats::STARCDCore::writePoints void Foam::fileFormats::STARCDCore::writePoints
( (
Ostream& os, Ostream& os,
const pointField& points, const UList<point>& points,
const scalar scaleFactor const scalar scaleFactor
) )
{ {

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 | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,9 +37,10 @@ SourceFiles
#include "IFstream.H" #include "IFstream.H"
#include "Enum.H" #include "Enum.H"
#include "pointField.H"
#include "Map.H" #include "Map.H"
#include "point.H"
#include "FixedList.H" #include "FixedList.H"
#include "List.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -133,13 +134,13 @@ protected:
// Constructors // Constructors
//- Construct null //- Construct null
STARCDCore(); STARCDCore() = default;
//- Read header and check signature PROSTAR_(CELL|VERTEX|BOUNDARY) //- Read header and check signature PROSTAR_(CELL|VERTEX|BOUNDARY)
static bool readHeader(IFstream&, const enum fileHeader); static bool readHeader(IFstream& is, const enum fileHeader header);
//- Write header for fileType (CELL|VERTEX|BOUNDARY) //- Write header for fileType (CELL|VERTEX|BOUNDARY)
static void writeHeader(Ostream&, const enum fileHeader); static void writeHeader(Ostream& os, const enum fileHeader header);
public: public:
@ -150,7 +151,7 @@ public:
static fileName starFileName static fileName starFileName
( (
const fileName& baseName, const fileName& baseName,
const enum fileExt const enum fileExt ext
); );
@ -173,16 +174,16 @@ public:
// \endverbatim // \endverbatim
static label readPoints static label readPoints
( (
IFstream&, IFstream& is,
pointField&, List<point>& points,
labelList& ids List<label>& ids
); );
//- Write header and points to (.vrt) file, optionally with scaling //- Write header and points to (.vrt) file, optionally with scaling
static void writePoints static void writePoints
( (
Ostream&, Ostream& os,
const pointField&, const UList<point>& points,
const scalar scaleFactor = 1.0 const scalar scaleFactor = 1.0
); );

View File

@ -59,21 +59,20 @@ static bool startsWithSolid(const char header[STLHeaderSize])
//! \endcond //! \endcond
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STLCore::STLCore()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STLCore::isBinaryName bool Foam::fileFormats::STLCore::isBinaryName
( (
const fileName& filename, const fileName& filename,
const STLFormat& format const STLFormat format
) )
{ {
return (format == UNKNOWN ? (filename.ext() == "stlb") : format == BINARY); return
(
format == STLFormat::UNKNOWN
? (filename.ext() == "stlb")
: format == STLFormat::BINARY
);
} }

View File

@ -69,11 +69,12 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Detect 'stlb' extension as binary //- Detect 'stlb' extension as binary when format = UNKNOWN.
// Otherwise test if format == BINARY.
static bool isBinaryName static bool isBinaryName
( (
const fileName& filename, const fileName& filename,
const STLFormat& format const STLFormat format
); );
@ -98,7 +99,7 @@ protected:
// Constructors // Constructors
//- Construct null //- Construct null
STLCore(); STLCore() = default;
}; };

View File

@ -38,7 +38,7 @@ bool Foam::fileFormats::STLReader::readBINARY
) )
{ {
sorted_ = true; sorted_ = true;
format_ = UNKNOWN; format_ = STLFormat::UNKNOWN;
label nTris = 0; label nTris = 0;
autoPtr<istream> streamPtr = readBinaryHeader(filename, nTris); autoPtr<istream> streamPtr = readBinaryHeader(filename, nTris);
@ -125,7 +125,7 @@ bool Foam::fileFormats::STLReader::readBINARY
names_.clear(); names_.clear();
sizes_.transfer(dynSizes); sizes_.transfer(dynSizes);
format_ = BINARY; format_ = STLFormat::BINARY;
return true; return true;
} }
@ -133,10 +133,15 @@ bool Foam::fileFormats::STLReader::readBINARY
bool Foam::fileFormats::STLReader::readFile bool Foam::fileFormats::STLReader::readFile
( (
const fileName& filename, const fileName& filename,
const STLFormat& format const STLFormat format
) )
{ {
if (format == UNKNOWN ? detectBinaryHeader(filename) : format == BINARY) if
(
format == STLFormat::UNKNOWN
? detectBinaryHeader(filename)
: format == STLFormat::BINARY
)
{ {
return readBINARY(filename); return readBINARY(filename);
} }
@ -159,17 +164,17 @@ Foam::fileFormats::STLReader::STLReader
zoneIds_(), zoneIds_(),
names_(), names_(),
sizes_(), sizes_(),
format_(STLCore::UNKNOWN) format_(STLFormat::UNKNOWN)
{ {
// Auto-detect ASCII/BINARY format // Auto-detect ASCII/BINARY format
readFile(filename, STLCore::UNKNOWN); readFile(filename, STLFormat::UNKNOWN);
} }
Foam::fileFormats::STLReader::STLReader Foam::fileFormats::STLReader::STLReader
( (
const fileName& filename, const fileName& filename,
const STLFormat& format const STLFormat format
) )
: :
sorted_(true), sorted_(true),
@ -177,7 +182,7 @@ Foam::fileFormats::STLReader::STLReader
zoneIds_(), zoneIds_(),
names_(), names_(),
sizes_(), sizes_(),
format_(STLCore::UNKNOWN) format_(STLFormat::UNKNOWN)
{ {
// Manually specified ASCII/BINARY format // Manually specified ASCII/BINARY format
readFile(filename, format); readFile(filename, format);
@ -199,7 +204,7 @@ void Foam::fileFormats::STLReader::clear()
zoneIds_.clear(); zoneIds_.clear();
names_.clear(); names_.clear();
sizes_.clear(); sizes_.clear();
format_ = UNKNOWN; format_ = STLFormat::UNKNOWN;
} }
@ -215,7 +220,7 @@ Foam::label Foam::fileFormats::STLReader::mergePointsMap
return mergePointsMap return mergePointsMap
( (
(format_ == BINARY ? 10 : 100) * doubleScalarSMALL, (format_ == STLFormat::BINARY ? 10 : 100) * doubleScalarSMALL,
pointMap pointMap
); );
} }

View File

@ -85,7 +85,7 @@ class STLReader
bool readBINARY(const fileName& filename); bool readBINARY(const fileName& filename);
//- Read ASCII or BINARY //- Read ASCII or BINARY
bool readFile(const fileName& filename, const STLFormat& format); bool readFile(const fileName& filename, const STLFormat format);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
@ -105,7 +105,7 @@ public:
//- Read from file, filling in the information. //- Read from file, filling in the information.
// Manually selected choice of ASCII/BINARY/UNKNOWN(detect) formats. // Manually selected choice of ASCII/BINARY/UNKNOWN(detect) formats.
STLReader(const fileName& filename, const STLFormat& format); STLReader(const fileName& filename, const STLFormat format);
//- Destructor //- Destructor

View File

@ -411,7 +411,7 @@ bool Foam::fileFormats::STLReader::readASCII
const fileName& filename const fileName& filename
) )
{ {
format_ = UNKNOWN; format_ = STLFormat::UNKNOWN;
IFstream is(filename); IFstream is(filename);
if (!is) if (!is)
@ -434,7 +434,7 @@ bool Foam::fileFormats::STLReader::readASCII
names_.transfer(lexer.names()); names_.transfer(lexer.names());
sizes_.transfer(lexer.sizes()); sizes_.transfer(lexer.sizes());
format_ = ASCII; format_ = STLFormat::ASCII;
return true; return true;
} }

View File

@ -44,17 +44,21 @@ Foam::lumpedPointState::formatNames
}; };
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
//! \cond fileScope //! \cond fileScope
static Foam::string getLineNoComment(Foam::ISstream& is) static Foam::string getLineNoComment
(
Foam::ISstream& is,
const char comment = '#'
)
{ {
Foam::string line; Foam::string line;
do do
{ {
is.getLine(line); is.getLine(line);
} }
while ((line.empty() || line[0] == '#') && is.good()); while ((line.empty() || line[0] == comment) && is.good());
return line; return line;
} }

View File

@ -38,15 +38,16 @@ Foam::word Foam::fileFormats::edgeMeshFormatsCore::nativeExt("eMesh");
Foam::string Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment Foam::string Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
( (
IFstream& is ISstream& is,
const char comment
) )
{ {
string line; Foam::string line;
do do
{ {
is.getLine(line); is.getLine(line);
} }
while ((line.empty() || line[0] == '#') && is.good()); while ((line.empty() || line[0] == comment) && is.good());
return line; return line;
} }
@ -183,16 +184,4 @@ bool Foam::fileFormats::edgeMeshFormatsCore::checkSupport
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::edgeMeshFormatsCore::edgeMeshFormatsCore()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileFormats::edgeMeshFormatsCore::~edgeMeshFormatsCore()
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -46,7 +46,7 @@ namespace Foam
// Forward declaration of classes // Forward declaration of classes
class IFstream; class ISstream;
class Time; class Time;
namespace fileFormats namespace fileFormats
@ -63,7 +63,7 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Read non-comment line //- Read non-comment line
static string getLineNoComment(IFstream&); static string getLineNoComment(ISstream& is, const char comment='#');
public: public:
@ -103,11 +103,11 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
edgeMeshFormatsCore(); edgeMeshFormatsCore() = default;
//- Destructor //- Destructor
virtual ~edgeMeshFormatsCore(); virtual ~edgeMeshFormatsCore() = default;
}; };

View File

@ -30,10 +30,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::NASedgeFormat::NASedgeFormat Foam::fileFormats::NASedgeFormat::NASedgeFormat(const fileName& filename)
(
const fileName& filename
)
{ {
read(filename); read(filename);
} }
@ -62,13 +59,13 @@ bool Foam::fileFormats::NASedgeFormat::read
while (is.good()) while (is.good())
{ {
string::size_type linei = 0; // parsing position within current line
string line; string line;
is.getLine(line); is.getLine(line);
// Skip empty or comment
if (line.empty() || line[0] == '$') if (line.empty() || line[0] == '$')
{ {
continue; continue; // Skip empty or comment
} }
// Check if character 72 is continuation // Check if character 72 is continuation
@ -94,39 +91,38 @@ bool Foam::fileFormats::NASedgeFormat::read
} }
// Read first word // First word (column 0-8)
IStringStream lineStream(line); const word cmd(word::validate(nextNasField(line, linei, 8)));
word cmd;
lineStream >> cmd;
if (cmd == "CBEAM" || cmd == "CROD") if (cmd == "CBEAM" || cmd == "CROD")
{ {
edge e; // discard elementId (8-16)
(void) nextNasField(line, linei, 8); // 8-16
// discard groupId (16-24)
(void) nextNasField(line, linei, 8); // 16-24
// label groupId = readLabel(line.substr(16,8)); label a = readLabel(nextNasField(line, linei, 8)); // 24-32
e[0] = readLabel(line.substr(24,8)); label b = readLabel(nextNasField(line, linei, 8)); // 32-40
e[1] = readLabel(line.substr(32,8));
// discard groupID dynEdges.append(edge(a,b));
dynEdges.append(e);
} }
else if (cmd == "PLOTEL") else if (cmd == "PLOTEL")
{ {
edge e; // discard elementId (8-16)
(void) nextNasField(line, linei, 8); // 8-16
// label groupId = readLabel(line.substr(16,8)); label a = readLabel(nextNasField(line, linei, 8)); // 16-24
e[0] = readLabel(line.substr(16,8)); label b = readLabel(nextNasField(line, linei, 8)); // 24-32
e[1] = readLabel(line.substr(24,8));
// discard groupID dynEdges.append(edge(a,b));
dynEdges.append(e);
} }
else if (cmd == "GRID") else if (cmd == "GRID")
{ {
label index = readLabel(line.substr(8,8)); label index = readLabel(nextNasField(line, linei, 8)); // 8-16
scalar x = readNasScalar(line.substr(24, 8)); (void) nextNasField(line, linei, 8); // 16-24
scalar y = readNasScalar(line.substr(32, 8)); scalar x = readNasScalar(nextNasField(line, linei, 8)); // 24-32
scalar z = readNasScalar(line.substr(40, 8)); scalar y = readNasScalar(nextNasField(line, linei, 8)); // 32-40
scalar z = readNasScalar(nextNasField(line, linei, 8)); // 40-48
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -139,10 +135,12 @@ bool Foam::fileFormats::NASedgeFormat::read
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02 // * 2.14897901E+02
label index = readLabel(line.substr(8,16)); label index = readLabel(nextNasField(line, linei, 16)); // 8-24
scalar x = readNasScalar(line.substr(40, 16)); (void) nextNasField(line, linei, 16); // 24-40
scalar y = readNasScalar(line.substr(56, 16)); scalar x = readNasScalar(nextNasField(line, linei, 16)); // 40-56
scalar y = readNasScalar(nextNasField(line, linei, 16)); // 56-72
linei = 0; // restart at index 0
is.getLine(line); is.getLine(line);
if (line[0] != '*') if (line[0] != '*')
{ {
@ -153,7 +151,8 @@ bool Foam::fileFormats::NASedgeFormat::read
<< "File:" << is.name() << " line:" << is.lineNumber() << "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError); << exit(FatalError);
} }
scalar z = readNasScalar(line.substr(8, 16)); (void) nextNasField(line, linei, 8); // 0-8
scalar z = readNasScalar(nextNasField(line, linei, 16)); // 8-16
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -179,9 +178,8 @@ bool Foam::fileFormats::NASedgeFormat::read
// Pass1: relabel edges // Pass1: relabel edges
// ~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~
forAll(dynEdges, i) for (edge& e : dynEdges)
{ {
edge& e = dynEdges[i];
e[0] = mapPointId[e[0]]; e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]]; e[1] = mapPointId[e[1]];
@ -191,7 +189,7 @@ bool Foam::fileFormats::NASedgeFormat::read
pointId.clearStorage(); pointId.clearStorage();
mapPointId.clear(); mapPointId.clear();
// not all the points were used, cull them accordingly // Not all the points were used, cull them accordingly
if (unsigned(points().size()) != usedPoints.count()) if (unsigned(points().size()) != usedPoints.count())
{ {
label nUsed = 0; label nUsed = 0;
@ -215,11 +213,9 @@ bool Foam::fileFormats::NASedgeFormat::read
pts.setSize(nUsed); pts.setSize(nUsed);
// renumber edge vertices // Renumber edge vertices
forAll(dynEdges, edgeI) for (edge& e : dynEdges)
{ {
edge& e = dynEdges[edgeI];
e[0] = mapPointId[e[0]]; e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]]; e[1] = mapPointId[e[1]];
} }

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 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,13 @@ Class
Description Description
Nastran edge reader. Nastran edge reader.
- Interprets "CBEAM", "CROD" and "PLOTEL" entries as edges.
- Handles Nastran short, long formats and comma-separated free format.
- Properly handles the Nastran compact floating point notation: \n
\verbatim
GRID 28 10.20269-.030265-2.358-8
\endverbatim
SourceFiles SourceFiles
NASedgeFormat.C NASedgeFormat.C
@ -57,17 +64,17 @@ class NASedgeFormat
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
NASedgeFormat(const NASedgeFormat&); NASedgeFormat(const NASedgeFormat&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const NASedgeFormat&); void operator=(const NASedgeFormat&) = delete;
public: public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
NASedgeFormat(const fileName&); NASedgeFormat(const fileName& filename);
// Selectors // Selectors
@ -83,14 +90,14 @@ public:
//- Destructor //- Destructor
virtual ~NASedgeFormat() virtual ~NASedgeFormat() = default;
{}
// Member Functions // Member Functions
//- Read from a file //- Read from a file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
}; };

View File

@ -40,164 +40,84 @@ namespace Foam
defineSurfaceWriterWriteFields(nastranSurfaceWriter); defineSurfaceWriterWriteFields(nastranSurfaceWriter);
} }
const Foam::Enum const Foam::Enum
< <
Foam::nastranSurfaceWriter::writeFormat Foam::nastranSurfaceWriter::loadFormat
> >
Foam::nastranSurfaceWriter::writeFormatNames_ Foam::nastranSurfaceWriter::loadFormatNames_
{ {
{ writeFormat::wfShort, "short" }, { loadFormat::PLOAD2, "PLOAD2" },
{ writeFormat::wfLong, "long" }, { loadFormat::PLOAD4, "PLOAD4" },
{ writeFormat::wfFree, "free" },
};
const Foam::Enum
<
Foam::nastranSurfaceWriter::dataFormat
>
Foam::nastranSurfaceWriter::dataFormatNames_
{
{ dataFormat::dfPLOAD2, "PLOAD2" },
{ dataFormat::dfPLOAD4, "PLOAD4" },
}; };
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::nastranSurfaceWriter::formatOS(Ostream& os) const
{
os.setf(ios_base::scientific);
// Capitalise the E marker
os.setf(ios_base::uppercase);
label prec = 0;
label offset = 7;
switch (writeFormat_)
{
case wfShort:
{
prec = 8 - offset;
break;
}
case wfFree:
case wfLong:
{
prec = 16 - offset;
break;
}
default:
{
FatalErrorInFunction
<< "Unknown writeFormat enumeration" << abort(FatalError);
}
}
os.precision(prec);
}
Foam::Ostream& Foam::nastranSurfaceWriter::writeKeyword Foam::Ostream& Foam::nastranSurfaceWriter::writeKeyword
( (
Ostream& os, Ostream& os,
const word& keyword const word& keyword
) const ) const
{ {
os.setf(ios_base::left); return fileFormats::NASCore::writeKeyword(os, keyword, writeFormat_);
switch (writeFormat_)
{
case wfShort:
{
os << setw(8) << keyword;
break;
}
case wfLong:
{
os << setw(8) << word(keyword + '*');
break;
}
case wfFree:
{
os << keyword;
break;
}
}
os.unsetf(ios_base::left);
return os;
} }
void Foam::nastranSurfaceWriter::writeCoord void Foam::nastranSurfaceWriter::writeCoord
( (
Ostream& os, Ostream& os,
const point& p, const point& pt,
const label pointI const label pointI
) const ) const
{ {
// Fixed short/long formats: // Fixed short/long formats:
// 1 GRID // 1 GRID
// 2 ID : point ID - requires starting index of 1 // 2 ID : point ID - requires starting index of 1
// 3 CP : co-ordinate system ID (blank) // 3 CP : coordinate system ID (blank)
// 4 X1 : point x cp-ordinate // 4 X1 : point x coordinate
// 5 X2 : point x cp-ordinate // 5 X2 : point x coordinate
// 6 X3 : point x cp-ordinate // 6 X3 : point x coordinate
// 7 CD : co-ordinate system for displacements (blank) // 7 CD : coordinate system for displacements (blank)
// 8 PS : single point constraints (blank) // 8 PS : single point constraints (blank)
// 9 SEID : super-element ID // 9 SEID : super-element ID
writeKeyword(os, "GRID") << separator_; writeKeyword(os, "GRID") << separator_;
os.setf(ios_base::right); os.setf(std::ios_base::right);
writeValue(os, pointI+1) << separator_; writeValue(os, pointI+1) << separator_;
writeValue(os, "") << separator_; writeValue(os, "") << separator_;
writeValue(os, p.x()) << separator_; writeValue(os, pt.x()) << separator_;
writeValue(os, p.y()) << separator_; writeValue(os, pt.y()) << separator_;
switch (writeFormat_) switch (writeFormat_)
{ {
case wfShort: case fieldFormat::SHORT :
{ {
os << setw(8) << p.z() os << setw(8) << pt.z() << nl;
<< nl; os.unsetf(std::ios_base::right);
os.unsetf(ios_base::right);
break; break;
} }
case wfLong: case fieldFormat::LONG :
{ {
os << nl; os << nl;
os.unsetf(ios_base::right); os.unsetf(std::ios_base::right);
writeKeyword(os, ""); writeKeyword(os, "");
os.setf(ios_base::right); os.setf(std::ios_base::right);
writeValue(os, p.z()) << nl; writeValue(os, pt.z()) << nl;
break; break;
} }
case wfFree: case fieldFormat::FREE :
{ {
writeValue(os, p.z()) << nl; writeValue(os, pt.z()) << nl;
break; break;
} }
default:
{
FatalErrorInFunction
<< "Unknown writeFormat enumeration" << abort(FatalError);
}
} }
os.unsetf(ios_base::right); os.unsetf(std::ios_base::right);
} }
@ -226,23 +146,24 @@ void Foam::nastranSurfaceWriter::writeFace
writeKeyword(os, faceType) << separator_; writeKeyword(os, faceType) << separator_;
os.setf(ios_base::right); os.setf(std::ios_base::right);
writeValue(os, nFace) << separator_; writeValue(os, nFace) << separator_;
writeValue(os, PID); writeValue(os, PID);
switch (writeFormat_) switch (writeFormat_)
{ {
case wfShort: case fieldFormat::SHORT :
{ {
forAll(facePts, i) for (const label pointi : facePts)
{ {
writeValue(os, facePts[i] + 1); writeValue(os, pointi + 1);
} }
break; break;
} }
case wfLong:
case fieldFormat::LONG :
{ {
forAll(facePts, i) forAll(facePts, i)
{ {
@ -250,33 +171,29 @@ void Foam::nastranSurfaceWriter::writeFace
if (i == 1) if (i == 1)
{ {
os << nl; os << nl;
os.unsetf(ios_base::right); os.unsetf(std::ios_base::right);
writeKeyword(os, ""); writeKeyword(os, "");
os.setf(ios_base::right); os.setf(std::ios_base::right);
} }
} }
break; break;
} }
case wfFree:
case fieldFormat::FREE :
{ {
forAll(facePts, i) for (const label pointi : facePts)
{ {
os << separator_; os << separator_;
writeValue(os, facePts[i] + 1); writeValue(os, pointi + 1);
} }
break; break;
} }
default:
{
FatalErrorInFunction
<< "Unknown writeFormat enumeration" << abort(FatalError);
}
} }
os << nl; os << nl;
os.unsetf(ios_base::right); os.unsetf(std::ios_base::right);
} }
@ -375,7 +292,7 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeFooter
// use single material ID // use single material ID
label MID = 1; const label MID = 1;
writeKeyword(os, "MAT1") << separator_; writeKeyword(os, "MAT1") << separator_;
writeValue(os, MID); writeValue(os, MID);
@ -397,49 +314,48 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeFooter
Foam::nastranSurfaceWriter::nastranSurfaceWriter() Foam::nastranSurfaceWriter::nastranSurfaceWriter()
: :
surfaceWriter(), surfaceWriter(),
writeFormat_(wfShort), writeFormat_(fieldFormat::SHORT),
fieldMap_(), fieldMap_(),
scale_(1.0) scale_(1.0),
separator_()
{} {}
Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& options) Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& options)
: :
surfaceWriter(), surfaceWriter(),
writeFormat_(writeFormat::wfLong), writeFormat_
fieldMap_(),
scale_(options.lookupOrDefault("scale", 1.0)),
separator_("")
{
writeFormat_ = writeFormatNames_.lookupOrDefault
( (
"format", fileFormats::NASCore::fieldFormatNames.lookupOrDefault
options, (
writeFormat::wfLong "format",
); options,
fieldFormat::LONG
if (writeFormat_ == wfFree) )
),
fieldMap_(),
scale_(options.lookupOrDefault<scalar>("scale", 1.0)),
separator_()
{
if (writeFormat_ == fieldFormat::FREE)
{ {
separator_ = ","; separator_ = ",";
} }
List<Pair<word>> fieldSet(options.lookup("fields")); List<Pair<word>> fieldPairs(options.lookup("fields"));
forAll(fieldSet, i) for (const Pair<word>& item : fieldPairs)
{ {
dataFormat format = dataFormatNames_[fieldSet[i].second()]; // (field name => load format)
fieldMap_.insert
fieldMap_.insert(fieldSet[i].first(), format); (
item.first(),
loadFormatNames_[item.second()]
);
} }
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::nastranSurfaceWriter::~nastranSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::nastranSurfaceWriter::write Foam::fileName Foam::nastranSurfaceWriter::write
@ -456,7 +372,7 @@ Foam::fileName Foam::nastranSurfaceWriter::write
} }
OFstream os(outputDir/surfaceName + ".nas"); OFstream os(outputDir/surfaceName + ".nas");
formatOS(os); fileFormats::NASCore::setPrecision(os, writeFormat_);
if (verbose) if (verbose)
{ {
@ -472,7 +388,7 @@ Foam::fileName Foam::nastranSurfaceWriter::write
writeGeometry(os, surf, decomposedFaces); writeGeometry(os, surf, decomposedFaces);
writeFooter(os, surf) writeFooter(os, surf)
<< "ENDDATA" << endl; << "ENDDATA" << nl;
return os.name(); return os.name();
} }

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) 2012-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,16 +32,16 @@ Description
{ {
nastran nastran
{ {
// From OpenFOAM field name to Nastran field name // From OpenFOAM field name to NASTRAN field name
fields fields
( (
(pMean PLOAD2) (pMean PLOAD2)
(p PLOAD4) (p PLOAD4)
); );
// Optional scale // Optional scale
scale 2.0; scale 2.0;
// Optional format // Optional format
format free; //short, long, free format free; // short, long, free
} }
}; };
\endverbatim \endverbatim
@ -56,7 +56,7 @@ SourceFiles
#define nastranSurfaceWriter_H #define nastranSurfaceWriter_H
#include "surfaceWriter.H" #include "surfaceWriter.H"
#include "Enum.H" #include "NASCore.H"
#include "OFstream.H" #include "OFstream.H"
#include "HashTable.H" #include "HashTable.H"
@ -75,17 +75,14 @@ class nastranSurfaceWriter
{ {
public: public:
enum writeFormat //- File field formats
{ using fieldFormat = Foam::fileFormats::NASCore::fieldFormat;
wfShort,
wfLong,
wfFree
};
enum dataFormat //- Output load format
enum loadFormat
{ {
dfPLOAD2, PLOAD2,
dfPLOAD4 PLOAD4
}; };
@ -93,14 +90,13 @@ private:
// Private data // Private data
static const Enum<writeFormat> writeFormatNames_; static const Enum<loadFormat> loadFormatNames_;
static const Enum<dataFormat> dataFormatNames_;
//- Write option //- Field format (width and separator)
writeFormat writeFormat_; fieldFormat writeFormat_;
//- Mapping from field name to data format enumeration //- Mapping from field name to data format enumeration
HashTable<dataFormat> fieldMap_; HashTable<loadFormat> fieldMap_;
//- Scale to apply to values (default = 1.0) //- Scale to apply to values (default = 1.0)
scalar scale_; scalar scale_;
@ -111,14 +107,11 @@ private:
// Private Member Functions // Private Member Functions
//- Initialise the output stream format parameters
void formatOS(Ostream& os) const;
//- Write a coordinate //- Write a coordinate
void writeCoord void writeCoord
( (
Ostream& os, Ostream& os,
const point& p, const point& pt,
const label pointI //!< 0-based Point Id const label pointI //!< 0-based Point Id
) const; ) const;
@ -159,7 +152,7 @@ private:
Ostream& writeFaceValue Ostream& writeFaceValue
( (
Ostream& os, Ostream& os,
const dataFormat& format, const loadFormat format,
const Type& value, const Type& value,
const label EID //!< 1-based Element Id const label EID //!< 1-based Element Id
) const; ) const;
@ -195,7 +188,7 @@ public:
//- Destructor //- Destructor
virtual ~nastranSurfaceWriter(); virtual ~nastranSurfaceWriter() = default;
// Member Functions // Member Functions

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) 2012-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,17 +38,19 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeValue
{ {
switch (writeFormat_) switch (writeFormat_)
{ {
case wfShort: case fieldFormat::SHORT :
{ {
os << setw(8) << value; os << setw(8) << value;
break; break;
} }
case wfLong:
case fieldFormat::LONG :
{ {
os << setw(16) << value; os << setw(16) << value;
break; break;
} }
case wfFree:
case fieldFormat::FREE :
{ {
os << value; os << value;
break; break;
@ -63,7 +65,7 @@ template<class Type>
Foam::Ostream& Foam::nastranSurfaceWriter::writeFaceValue Foam::Ostream& Foam::nastranSurfaceWriter::writeFaceValue
( (
Ostream& os, Ostream& os,
const dataFormat& format, const loadFormat format,
const Type& value, const Type& value,
const label EID const label EID
) const ) const
@ -87,16 +89,16 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeFaceValue
Type scaledValue = scale_*value; Type scaledValue = scale_*value;
// Write keyword // Write keyword
writeKeyword(os, dataFormatNames_[format]) << separator_; writeKeyword(os, loadFormatNames_[format]) << separator_;
// Write load set ID // Write load set ID
os.setf(ios_base::right); os.setf(std::ios_base::right);
writeValue(os, SID) << separator_; writeValue(os, SID) << separator_;
switch (format) switch (format)
{ {
case dfPLOAD2: case loadFormat::PLOAD2 :
{ {
if (pTraits<Type>::nComponents == 1) if (pTraits<Type>::nComponents == 1)
{ {
@ -105,7 +107,7 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeFaceValue
else else
{ {
WarningInFunction WarningInFunction
<< dataFormatNames_[format] << " requires scalar values " << loadFormatNames_[format] << " requires scalar values "
<< "and cannot be used for higher rank values" << "and cannot be used for higher rank values"
<< endl; << endl;
@ -116,27 +118,20 @@ Foam::Ostream& Foam::nastranSurfaceWriter::writeFaceValue
break; break;
} }
case dfPLOAD4: case loadFormat::PLOAD4 :
{ {
writeValue(os, EID); writeValue(os, EID);
for (direction dirI = 0; dirI < pTraits<Type>::nComponents; ++dirI) for (direction d = 0; d < pTraits<Type>::nComponents; ++d)
{ {
os << separator_; os << separator_;
writeValue(os, component(scaledValue, dirI)); writeValue(os, component(scaledValue, d));
} }
break; break;
} }
default:
{
FatalErrorInFunction
<< "Unhandled enumeration " << dataFormatNames_[format]
<< exit(FatalError);
}
} }
os.unsetf(ios_base::right); os.unsetf(std::ios_base::right);
os << nl; os << nl;
@ -167,7 +162,7 @@ Foam::fileName Foam::nastranSurfaceWriter::writeTemplate
return fileName::null; return fileName::null;
} }
const dataFormat& format(fieldMap_[fieldName]); const loadFormat& format(fieldMap_[fieldName]);
if (!isDir(outputDir/fieldName)) if (!isDir(outputDir/fieldName))
{ {
@ -178,7 +173,7 @@ Foam::fileName Foam::nastranSurfaceWriter::writeTemplate
const scalar timeValue = 0.0; const scalar timeValue = 0.0;
OFstream os(outputDir/fieldName/surfaceName + ".nas"); OFstream os(outputDir/fieldName/surfaceName + ".nas");
formatOS(os); fileFormats::NASCore::setPrecision(os, writeFormat_);
if (verbose) if (verbose)
{ {
@ -199,21 +194,19 @@ Foam::fileName Foam::nastranSurfaceWriter::writeTemplate
<< "$ Field data" << nl << "$ Field data" << nl
<< "$" << nl; << "$" << nl;
label elemId = 0;
if (isNodeValues) if (isNodeValues)
{ {
label elemId = 0; for (const DynamicList<face>& dFaces : decomposedFaces)
forAll(decomposedFaces, i)
{ {
const DynamicList<face>& dFaces = decomposedFaces[i]; for (const face& f : dFaces)
forAll(dFaces, facei)
{ {
Type v = Zero; Type v = Zero;
const face& f = dFaces[facei];
forAll(f, fptI) for (const label verti : f)
{ {
v += values[f[fptI]]; v += values[verti];
} }
v /= f.size(); v /= f.size();
@ -223,11 +216,8 @@ Foam::fileName Foam::nastranSurfaceWriter::writeTemplate
} }
else else
{ {
label elemId = 0; for (const DynamicList<face>& dFaces : decomposedFaces)
forAll(decomposedFaces, i)
{ {
const DynamicList<face>& dFaces = decomposedFaces[i];
forAll(dFaces, facei) forAll(dFaces, facei)
{ {
writeFaceValue(os, format, values[facei], ++elemId); writeFaceValue(os, format, values[facei], ++elemId);

View File

@ -55,9 +55,8 @@ void Foam::vtkSurfaceWriter::writeGeometry
// Write vertex coords // Write vertex coords
os << "POINTS " << points.size() << " double" << nl; os << "POINTS " << points.size() << " double" << nl;
forAll(points, pointi) for (const point& pt : points)
{ {
const point& pt = points[pointi];
os << float(pt.x()) << ' ' os << float(pt.x()) << ' '
<< float(pt.y()) << ' ' << float(pt.y()) << ' '
<< float(pt.z()) << nl; << float(pt.z()) << nl;
@ -67,22 +66,20 @@ void Foam::vtkSurfaceWriter::writeGeometry
// Write faces // Write faces
label nNodes = 0; label nNodes = 0;
forAll(faces, facei) for (const face& f : faces)
{ {
nNodes += faces[facei].size(); nNodes += f.size();
} }
os << "POLYGONS " << faces.size() << ' ' os << "POLYGONS " << faces.size() << ' '
<< faces.size() + nNodes << nl; << faces.size() + nNodes << nl;
forAll(faces, facei) for (const face& f : faces)
{ {
const face& f = faces[facei];
os << f.size(); os << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
os << nl; os << nl;
} }
@ -130,9 +127,8 @@ namespace Foam
{ {
os << "3 " << values.size() << " float" << nl; os << "3 " << values.size() << " float" << nl;
forAll(values, elemI) for (const vector& v : values)
{ {
const vector& v = values[elemI];
os << float(v[0]) << ' ' os << float(v[0]) << ' '
<< float(v[1]) << ' ' << float(v[1]) << ' '
<< float(v[2]) << nl; << float(v[2]) << nl;
@ -149,9 +145,8 @@ namespace Foam
{ {
os << "1 " << values.size() << " float" << nl; os << "1 " << values.size() << " float" << nl;
forAll(values, elemI) for (const sphericalTensor& v : values)
{ {
const sphericalTensor& v = values[elemI];
os << float(v[0]) << nl; os << float(v[0]) << nl;
} }
} }
@ -166,9 +161,8 @@ namespace Foam
{ {
os << "6 " << values.size() << " float" << nl; os << "6 " << values.size() << " float" << nl;
forAll(values, elemI) for (const symmTensor& v : values)
{ {
const symmTensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' ' << ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
@ -187,9 +181,8 @@ namespace Foam
{ {
os << "9 " << values.size() << " float" << nl; os << "9 " << values.size() << " float" << nl;
forAll(values, elemI) for (const tensor& v : values)
{ {
const tensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' ' << ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
@ -211,12 +204,12 @@ Foam::vtkSurfaceWriter::vtkSurfaceWriter()
{} {}
Foam::vtkSurfaceWriter::vtkSurfaceWriter(const dictionary& dict) Foam::vtkSurfaceWriter::vtkSurfaceWriter(const dictionary& options)
: :
surfaceWriter(), surfaceWriter(),
writePrecision_ writePrecision_
( (
dict.lookupOrDefault options.lookupOrDefault
( (
"writePrecision", "writePrecision",
IOstream::defaultPrecision() IOstream::defaultPrecision()
@ -225,12 +218,6 @@ Foam::vtkSurfaceWriter::vtkSurfaceWriter(const dictionary& dict)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkSurfaceWriter::~vtkSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::vtkSurfaceWriter::write Foam::fileName Foam::vtkSurfaceWriter::write
@ -260,7 +247,7 @@ Foam::fileName Foam::vtkSurfaceWriter::write
} }
// create write methods // Create write methods
defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter); defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter);

View File

@ -93,7 +93,7 @@ public:
//- Destructor //- Destructor
virtual ~vtkSurfaceWriter(); virtual ~vtkSurfaceWriter() = default;
// Member Functions // Member Functions

View File

@ -25,6 +25,7 @@ $(surfaceFormats)/ac3d/AC3DsurfaceFormatCore.C
$(surfaceFormats)/ac3d/AC3DsurfaceFormatRunTime.C $(surfaceFormats)/ac3d/AC3DsurfaceFormatRunTime.C
$(surfaceFormats)/fire/FLMAsurfaceFormatRunTime.C $(surfaceFormats)/fire/FLMAsurfaceFormatRunTime.C
$(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C $(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
$(surfaceFormats)/gts/triSurfaceGTSformat.C
$(surfaceFormats)/nas/NASsurfaceFormatRunTime.C $(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
$(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C $(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
$(surfaceFormats)/obj/OBJstream.C $(surfaceFormats)/obj/OBJstream.C
@ -33,7 +34,8 @@ $(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C $(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C $(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C
$(surfaceFormats)/stl/STLsurfaceFormatRunTime.C $(surfaceFormats)/stl/STLsurfaceFormatRunTime.C
$(surfaceFormats)/tri/TRIsurfaceFormatCore.C $(surfaceFormats)/stl/triSurfaceSTLformat.C
$(surfaceFormats)/tri/TRIReader.C
$(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C $(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C
$(surfaceFormats)/vtk/VTKsurfaceFormatCore.C $(surfaceFormats)/vtk/VTKsurfaceFormatCore.C
$(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C $(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C
@ -43,29 +45,12 @@ $(surfaceFormats)/x3d/X3DsurfaceFormatCore.C
$(surfaceFormats)/x3d/X3DsurfaceFormatRunTime.C $(surfaceFormats)/x3d/X3DsurfaceFormatRunTime.C
triSurface/triSurface.C triSurface/triSurface.C
triSurface/triSurfaceIO.C
triSurface/triSurfaceAddressing.C triSurface/triSurfaceAddressing.C
triSurface/stitchTriangles.C triSurface/triSurfaceStitch.C
triSurface/fields/triSurfaceFields.C triSurface/fields/triSurfaceFields.C
triSurface/patches/geometricSurfacePatch.C triSurface/patches/geometricSurfacePatch.C
triSurface/patches/surfacePatch.C triSurface/patches/surfacePatch.C
interfaces = triSurface/interfaces
$(interfaces)/STL/writeSTL.C
$(interfaces)/STL/readSTL.C
$(interfaces)/GTS/writeGTS.C
$(interfaces)/GTS/readGTS.C
$(interfaces)/OBJ/readOBJ.C
$(interfaces)/OBJ/writeOBJ.C
$(interfaces)/SMESH/writeSMESH.C
$(interfaces)/OFF/readOFF.C
$(interfaces)/OFF/writeOFF.C
$(interfaces)/TRI/writeTRI.C
$(interfaces)/TRI/readTRI.C
$(interfaces)/AC3D/readAC.C
$(interfaces)/AC3D/writeAC.C
$(interfaces)/VTK/readVTK.C
$(interfaces)/VTK/writeVTK.C
$(interfaces)/NAS/readNAS.C
LIB = $(FOAM_LIBBIN)/libsurfMesh LIB = $(FOAM_LIBBIN)/libsurfMesh

View File

@ -107,10 +107,11 @@ template<class Face>
void Foam::MeshedSurface<Face>::write void Foam::MeshedSurface<Face>::write
( (
const fileName& name, const fileName& name,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
write(name, name.ext(), surf); write(name, name.ext(), surf, options);
} }
@ -119,7 +120,8 @@ void Foam::MeshedSurface<Face>::write
( (
const fileName& name, const fileName& name,
const word& ext, const word& ext,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
if (debug) if (debug)
@ -136,7 +138,7 @@ void Foam::MeshedSurface<Face>::write
if (delegate.found(ext)) if (delegate.found(ext))
{ {
MeshedSurfaceProxy<Face>(surf).write(name, ext); MeshedSurfaceProxy<Face>(surf).write(name, ext, options);
} }
else else
{ {
@ -149,7 +151,7 @@ void Foam::MeshedSurface<Face>::write
} }
else else
{ {
mfIter()(name, surf); mfIter()(name, surf, options);
} }
} }
@ -159,7 +161,8 @@ void Foam::MeshedSurface<Face>::write
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface() Foam::MeshedSurface<Face>::MeshedSurface()
: :
ParentType(List<Face>(), pointField()) ParentType(List<Face>(), pointField()),
zones_()
{} {}
@ -171,8 +174,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
const Xfer<surfZoneList>& zoneLst const Xfer<surfZoneList>& zoneLst
) )
: :
ParentType(List<Face>(), pointField()), MeshedSurface<Face>()
zones_()
{ {
reset(pointLst, faceLst, zoneLst); reset(pointLst, faceLst, zoneLst);
} }
@ -187,7 +189,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
const UList<word>& zoneNames const UList<word>& zoneNames
) )
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
reset(pointLst, faceLst, Xfer<surfZoneList>()); reset(pointLst, faceLst, Xfer<surfZoneList>());
@ -242,7 +244,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh) Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh)
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
// same face type as surfMesh // same face type as surfMesh
MeshedSurface<face> surf MeshedSurface<face> surf
@ -263,7 +265,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
const bool useGlobalPoints const bool useGlobalPoints
) )
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
const polyMesh& mesh = bMesh.mesh(); const polyMesh& mesh = bMesh.mesh();
const polyPatchList& bPatches = bMesh; const polyPatchList& bPatches = bMesh;
@ -312,7 +314,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
nZone nZone
); );
nZone++; ++nZone;
startFacei += p.size(); startFacei += p.size();
} }
} }
@ -332,38 +334,27 @@ Foam::MeshedSurface<Face>::MeshedSurface
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name, const word& ext)
(
const fileName& name,
const word& ext
)
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
read(name, ext); read(name, ext);
} }
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name)
(
const fileName& name
)
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
read(name); read(name);
} }
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface(Istream& is)
(
Istream& is
)
: :
ParentType(List<Face>(), pointField()), MeshedSurface<Face>()
zones_()
{ {
read(is); read(is);
} }
@ -376,7 +367,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
const word& surfName const word& surfName
) )
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
surfMesh mesh surfMesh mesh
( (
@ -407,10 +398,10 @@ Foam::MeshedSurface<Face>::MeshedSurface
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface
( (
const Xfer<UnsortedMeshedSurface<Face>>& surf const Xfer<MeshedSurface<Face>>& surf
) )
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
transfer(surf()); transfer(surf());
} }
@ -419,16 +410,15 @@ Foam::MeshedSurface<Face>::MeshedSurface
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface
( (
const Xfer<MeshedSurface<Face>>& surf const Xfer<UnsortedMeshedSurface<Face>>& surf
) )
: :
ParentType(List<Face>(), pointField()) MeshedSurface<Face>()
{ {
transfer(surf()); transfer(surf());
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -446,44 +436,43 @@ void Foam::MeshedSurface<Face>::remapFaces
const labelUList& faceMap const labelUList& faceMap
) )
{ {
// recalculate the zone start/size if (isNull(faceMap) || faceMap.empty())
if (notNull(faceMap) && faceMap.size())
{ {
surfZoneList& zones = storedZones(); return;
}
if (zones.size() == 1) surfZoneList& zones = storedZones();
if (zones.size() == 1)
{
zones[0].size() = faceMap.size(); // Single zone case is trivial
return;
}
// Recalculate the zone start/size
label newFacei = 0;
label origEndI = 0;
for (surfZone& zone : zones)
{
// Adjust zone start
zone.start() = newFacei;
origEndI += zone.size();
for (label facei = newFacei; facei < faceMap.size(); ++facei)
{ {
// optimized for single zone case if (faceMap[facei] < origEndI)
zones[0].size() = faceMap.size();
}
else if (zones.size())
{
label newFacei = 0;
label origEndI = 0;
forAll(zones, zoneI)
{ {
surfZone& zone = zones[zoneI]; ++newFacei;
}
// adjust zone start else
zone.start() = newFacei; {
origEndI += zone.size(); break;
for (label facei = newFacei; facei < faceMap.size(); ++facei)
{
if (faceMap[facei] < origEndI)
{
++newFacei;
}
else
{
break;
}
}
// adjust zone size
zone.size() = newFacei - zone.start();
} }
} }
// Adjust zone size
zone.size() = newFacei - zone.start();
} }
} }
@ -664,7 +653,7 @@ bool Foam::MeshedSurface<Face>::stitchFaces
faceLst[newFacei] = f; faceLst[newFacei] = f;
} }
faceMap[newFacei] = facei; faceMap[newFacei] = facei;
newFacei++; ++newFacei;
} }
else if (verbose) else if (verbose)
{ {
@ -730,7 +719,7 @@ bool Foam::MeshedSurface<Face>::checkFaces
} }
faceMap[facei] = facei; faceMap[facei] = facei;
newFacei++; ++newFacei;
} }
else else
{ {
@ -801,7 +790,7 @@ bool Foam::MeshedSurface<Face>::checkFaces
if (okay) if (okay)
{ {
faceMap[facei] = facei; faceMap[facei] = facei;
newFacei++; ++newFacei;
} }
else else
{ {
@ -834,7 +823,7 @@ bool Foam::MeshedSurface<Face>::checkFaces
faceLst[newFacei] = faceLst[facei]; faceLst[newFacei] = faceLst[facei];
} }
faceMap[newFacei] = facei; faceMap[newFacei] = facei;
newFacei++; ++newFacei;
} }
} }
@ -990,11 +979,11 @@ Foam::label Foam::MeshedSurface<Face>::triangulate
for (label fp = 1; fp < f.size() - 1; ++fp) for (label fp = 1; fp < f.size() - 1; ++fp)
{ {
label fp1 = f.fcIndex(fp); const label fp1 = f.fcIndex(fp);
newFaces[nTri] = Face{f[0], f[fp], f[fp1]}; newFaces[nTri] = Face{f[0], f[fp], f[fp1]};
faceMap[nTri] = facei; faceMap[nTri] = facei;
nTri++; ++nTri;
} }
} }
} }
@ -1018,7 +1007,7 @@ Foam::label Foam::MeshedSurface<Face>::triangulate
static_cast<labelUList&>(tmpTri[triI]) static_cast<labelUList&>(tmpTri[triI])
); );
faceMap[nTri] = facei; faceMap[nTri] = facei;
nTri++; ++nTri;
} }
} }
} }
@ -1239,20 +1228,17 @@ Foam::MeshedSurface<Face>::xferZones()
} }
// Read from file, determine format from extension
template<class Face> template<class Face>
bool Foam::MeshedSurface<Face>::read(const fileName& name) bool Foam::MeshedSurface<Face>::read(const fileName& name)
{ {
word ext = name.ext(); const word ext(name.ext());
if (ext == "gz") if (ext == "gz")
{ {
fileName unzipName = name.lessExt(); fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext()); return read(unzipName, unzipName.ext());
} }
else
{ return read(name, ext);
return read(name, ext);
}
} }

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -52,19 +52,18 @@ SourceFiles
#include "pointField.H" #include "pointField.H"
#include "face.H" #include "face.H"
#include "labelledTri.H" #include "labelledTri.H"
#include "HashSet.H"
#include "surfZoneList.H" #include "surfZoneList.H"
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H" #include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
class Time; class Time;
class surfMesh; class surfMesh;
@ -124,10 +123,10 @@ private:
// Private Member functions // Private Member functions
//- Read/construct from Istream //- Read/construct from Istream
Istream& read(Istream&); Istream& read(Istream& is);
//- Write to Ostream //- Write to Ostream
Ostream& write(Ostream&) const; Ostream& write(Ostream& os) const;
protected: protected:
@ -138,7 +137,7 @@ protected:
// Eg, transcribe face to triFace, or face -> labelledTri, including // Eg, transcribe face to triFace, or face -> labelledTri, including
// any addZonesToFaces adjustment. // any addZonesToFaces adjustment.
// No general form, only specializations. // No general form, only specializations.
void transcribe(MeshedSurface<face>&); void transcribe(MeshedSurface<face>& surf);
//- Basic sanity check on zones //- Basic sanity check on zones
void checkZones(); void checkZones();
@ -195,7 +194,10 @@ public:
//- Can we write this file format? //- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false); static bool canWriteType(const word& ext, const bool verbose=false);
//- Known readable file-types
static wordHashSet readTypes(); static wordHashSet readTypes();
//- Known writable file-types
static wordHashSet writeTypes(); static wordHashSet writeTypes();
@ -222,10 +224,10 @@ public:
const UList<word>& zoneNames = UList<word>() const UList<word>& zoneNames = UList<word>()
); );
//- Construct as copy //- Copy construct
MeshedSurface(const MeshedSurface& surf); MeshedSurface(const MeshedSurface& surf);
//- Construct from a UnsortedMeshedSurface //- Copy construct from an UnsortedMeshedSurface
MeshedSurface(const UnsortedMeshedSurface<Face>& surf); MeshedSurface(const UnsortedMeshedSurface<Face>& surf);
//- Construct from a boundary mesh with local points/faces //- Construct from a boundary mesh with local points/faces
@ -238,11 +240,11 @@ public:
//- Construct from a surfMesh //- Construct from a surfMesh
MeshedSurface(const surfMesh& mesh); MeshedSurface(const surfMesh& mesh);
//- Construct by transferring the contents from a UnsortedMeshedSurface
MeshedSurface(const Xfer<UnsortedMeshedSurface<Face>>&);
//- Construct by transferring the contents from a MeshedSurface //- Construct by transferring the contents from a MeshedSurface
MeshedSurface(const Xfer<MeshedSurface<Face>>&); MeshedSurface(const Xfer<MeshedSurface<Face>>& surf);
//- Construct by transferring the contents from a UnsortedMeshedSurface
MeshedSurface(const Xfer<UnsortedMeshedSurface<Face>>& surf);
//- Construct from file name (uses extension to determine type) //- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName& name); MeshedSurface(const fileName& name);
@ -285,7 +287,7 @@ public:
); );
//- Select constructed from filename (implicit extension) //- Select constructed from filename (implicit extension)
static autoPtr<MeshedSurface> New(const fileName&); static autoPtr<MeshedSurface> New(const fileName& name);
//- Destructor //- Destructor
@ -302,16 +304,18 @@ public:
fileExtension, fileExtension,
( (
const fileName& name, const fileName& name,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary& options
), ),
(name, surf) (name, surf, options)
); );
//- Write to file, selecting writer based on its extension //- Write to file, selecting writer based on its extension
static void write static void write
( (
const fileName& name, const fileName& name,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write to file, selecting writer based on the given extension //- Write to file, selecting writer based on the given extension
@ -319,7 +323,8 @@ public:
( (
const fileName& name, const fileName& name,
const word& ext, const word& ext,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
@ -405,15 +410,15 @@ public:
//- Move points //- Move points
virtual void movePoints(const pointField&); virtual void movePoints(const pointField& newPoints);
//- Scale points. A non-positive factor is ignored //- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar); virtual void scalePoints(const scalar scaleFactor);
//- Reset by transferring contents of the argument and annul it //- Reset by transferring contents of the argument and annul it
virtual void reset virtual void reset
( (
const Xfer<MeshedSurface<Face>>& const Xfer<MeshedSurface<Face>>& surf
); );
//- Reset primitive data (points, faces and zones) //- Reset primitive data (points, faces and zones)
@ -500,10 +505,10 @@ public:
// Read // Read
//- Read from file. Chooses reader based on explicit extension //- Read from file. Chooses reader based on explicit extension
bool read(const fileName&, const word& ext); bool read(const fileName& name, const word& ext);
//- Read from file. Chooses reader based on detected extension //- Read from file. Chooses reader based on detected extension
virtual bool read(const fileName&); virtual bool read(const fileName& name);
// Write // Write
@ -511,15 +516,19 @@ public:
void writeStats(Ostream& os) const; void writeStats(Ostream& os) const;
//- Generic write routine. Chooses writer based on extension. //- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, *this); write(name, *this, options);
} }
//- Write to database //- Write to database
void write void write
( (
const Time&, const Time& t,
const word& surfName = word::null const word& surfName = word::null
) const; ) const;

View File

@ -65,19 +65,18 @@ void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
} }
else else
{ {
label nTri = 0; label nTri = 0, nQuad = 0;
label nQuad = 0; for (const Face& f : *this)
forAll(*this, i)
{ {
const label n = this->operator[](i).size(); const label n = f.size();
if (n == 3) if (n == 3)
{ {
nTri++; ++nTri;
} }
else if (n == 4) else if (n == 4)
{ {
nQuad++; ++nQuad;
} }
} }

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "ListOps.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -74,27 +75,26 @@ void Foam::MeshedSurface<Face>::sortFacesAndStore
if (sorted) if (sorted)
{ {
// already sorted - simply transfer faces // Already sorted - simply transfer faces
this->storedFaces().transfer(oldFaces); this->storedFaces().transfer(oldFaces);
}
else
{
// unsorted - determine the sorted order:
// avoid SortableList since we discard the main list anyhow
List<label> faceMap;
sortedOrder(zones, faceMap);
zones.clear(); zones.clear();
return;
// sorted faces
List<Face> newFaces(faceMap.size());
forAll(faceMap, facei)
{
// use transfer to recover memory where possible
newFaces[facei].transfer(oldFaces[faceMap[facei]]);
}
this->storedFaces().transfer(newFaces);
} }
// Determine the sorted order:
// use sortedOrder directly since we discard the intermediate list anyhow
List<label> faceMap;
sortedOrder(zones, faceMap);
zones.clear(); zones.clear();
// Sorted faces
List<Face> newFaces(faceMap.size());
forAll(faceMap, facei)
{
// use transfer to recover memory where possible
newFaces[facei].transfer(oldFaces[faceMap[facei]]);
}
this->storedFaces().transfer(newFaces);
} }
@ -116,7 +116,7 @@ void Foam::MeshedSurface<Face>::addZones
if (srfZones[zoneI].size() || !cullEmpty) if (srfZones[zoneI].size() || !cullEmpty)
{ {
zones[nZone] = surfZone(srfZones[zoneI], nZone); zones[nZone] = surfZone(srfZones[zoneI], nZone);
nZone++; ++nZone;
} }
} }
zones.setSize(nZone); zones.setSize(nZone);
@ -148,7 +148,7 @@ void Foam::MeshedSurface<Face>::addZones
nZone nZone
); );
start += sizes[zoneI]; start += sizes[zoneI];
nZone++; ++nZone;
} }
} }
zones.setSize(nZone); zones.setSize(nZone);
@ -179,7 +179,7 @@ void Foam::MeshedSurface<Face>::addZones
nZone nZone
); );
start += sizes[zoneI]; start += sizes[zoneI];
nZone++; ++nZone;
} }
} }
zones.setSize(nZone); zones.setSize(nZone);

View File

@ -58,10 +58,11 @@ template<class Face>
void Foam::MeshedSurfaceProxy<Face>::write void Foam::MeshedSurfaceProxy<Face>::write
( (
const fileName& name, const fileName& name,
const MeshedSurfaceProxy& surf const MeshedSurfaceProxy& surf,
const dictionary& options
) )
{ {
write(name, name.ext(), surf); write(name, name.ext(), surf, options);
} }
@ -70,7 +71,8 @@ void Foam::MeshedSurfaceProxy<Face>::write
( (
const fileName& name, const fileName& name,
const word& ext, const word& ext,
const MeshedSurfaceProxy& surf const MeshedSurfaceProxy& surf,
const dictionary& options
) )
{ {
if (debug) if (debug)
@ -89,7 +91,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
<< exit(FatalError); << exit(FatalError);
} }
mfIter()(name, surf); mfIter()(name, surf, options);
} }
@ -180,8 +182,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
if (this->useFaceMap()) if (this->useFaceMap())
{ {
// this is really a bit annoying (and wasteful) but no other way os << UIndirectList<Face>(this->surfFaces(), this->faceMap());
os << reorder(this->faceMap(), this->surfFaces());
} }
else else
{ {
@ -226,9 +227,9 @@ template<class Face>
Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
( (
const pointField& pointLst, const pointField& pointLst,
const List<Face>& faceLst, const UList<Face>& faceLst,
const List<surfZone>& zoneLst, const UList<surfZone>& zoneLst,
const List<label>& faceMap const labelUList& faceMap
) )
: :
points_(pointLst), points_(pointLst),
@ -238,13 +239,6 @@ Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face>
Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -254,17 +248,14 @@ inline Foam::label Foam::MeshedSurfaceProxy<Face>::nTriangles() const
{ {
return this->size(); return this->size();
} }
else
{
label nTri = 0;
const List<Face>& faceLst = this->surfFaces();
forAll(faceLst, facei)
{
nTri += faceLst[facei].nTriangles();
}
return nTri; label nTri = 0;
for (const Face& f : this->surfFaces())
{
nTri += f.nTriangles();
} }
return nTri;
} }

View File

@ -39,12 +39,11 @@ SourceFiles
#include "pointField.H" #include "pointField.H"
#include "labelledTri.H" #include "labelledTri.H"
#include "HashSet.H"
#include "surfZoneList.H" #include "surfZoneList.H"
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H" #include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,16 +63,15 @@ class MeshedSurfaceProxy
: :
public fileFormats::surfaceFormatsCore public fileFormats::surfaceFormatsCore
{ {
//- Private data // Private Member Data
const pointField& points_; const pointField& points_;
const List<Face>& faces_; const UList<Face>& faces_;
const List<surfZone>& zones_; const UList<surfZone>& zones_;
const List<label>& faceMap_;
const UList<label>& faceMap_;
public: public:
@ -101,14 +99,14 @@ public:
MeshedSurfaceProxy MeshedSurfaceProxy
( (
const pointField& pointLst, const pointField& pointLst,
const List<Face>& faceLst, const UList<Face>& faceLst,
const List<surfZone>& zoneLst = List<surfZone>(), const UList<surfZone>& zoneLst = List<surfZone>(),
const List<label>& faceMap = List<label>() const labelUList& faceMap = List<label>()
); );
//- Destructor //- Destructor
virtual ~MeshedSurfaceProxy(); virtual ~MeshedSurfaceProxy() = default;
// Member Function Selectors // Member Function Selectors
@ -121,16 +119,18 @@ public:
fileExtension, fileExtension,
( (
const fileName& name, const fileName& name,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
), ),
(name, surf) (name, surf, options)
); );
//- Write to file, selected based on its extension //- Write to file, select based on its extension
static void write static void write
( (
const fileName& name, const fileName& name,
const MeshedSurfaceProxy& surf const MeshedSurfaceProxy& surf,
const dictionary& options
); );
//- Write to file, selected based on given extension //- Write to file, selected based on given extension
@ -138,7 +138,8 @@ public:
( (
const fileName& name, const fileName& name,
const word& ext, const word& ext,
const MeshedSurfaceProxy& surf const MeshedSurfaceProxy& surf,
const dictionary& options
); );
@ -159,7 +160,7 @@ public:
} }
//- Return const access to the faces //- Return const access to the faces
inline const List<Face>& surfFaces() const inline const UList<Face>& surfFaces() const
{ {
return faces_; return faces_;
} }
@ -167,13 +168,13 @@ public:
//- Const access to the surface zones. //- Const access to the surface zones.
// If zones are defined, they must be contiguous and cover the // If zones are defined, they must be contiguous and cover the
// entire surface // entire surface
inline const List<surfZone>& surfZones() const inline const UList<surfZone>& surfZones() const
{ {
return zones_; return zones_;
} }
//- Const access to the faceMap, zero-sized when unused //- Const access to the faceMap, zero-sized when unused
inline const List<label>& faceMap() const inline const labelUList& faceMap() const
{ {
return faceMap_; return faceMap_;
} }
@ -190,16 +191,25 @@ public:
// Write // Write
//- Generic write routine. Chooses writer based on extension. //- Generic write routine. Chooses writer based on its extension.
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, *this); write(name, *this, options);
} }
//- Generic write routine. Chooses writer based on extension. //- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name, const word& ext) const virtual void write
(
const fileName& name,
const word& ext,
const dictionary& options = dictionary::null
) const
{ {
write(name, ext, *this); write(name, ext, *this, options);
} }
//- Write to database //- Write to database

View File

@ -83,8 +83,7 @@ public:
//- Destructor //- Destructor
virtual ~ModifiableMeshedSurface() virtual ~ModifiableMeshedSurface() = default;
{}
// Member Functions // Member Functions

View File

@ -102,7 +102,21 @@ template<class Face>
void Foam::UnsortedMeshedSurface<Face>::write void Foam::UnsortedMeshedSurface<Face>::write
( (
const fileName& name, const fileName& name,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
)
{
write(name, name.ext(), surf, options);
}
template<class Face>
void Foam::UnsortedMeshedSurface<Face>::write
(
const fileName& name,
const word& ext,
const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
if (debug) if (debug)
@ -110,8 +124,6 @@ void Foam::UnsortedMeshedSurface<Face>::write
InfoInFunction << "Writing to " << name << endl; InfoInFunction << "Writing to " << name << endl;
} }
const word ext = name.ext();
auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext); auto mfIter = writefileExtensionMemberFunctionTablePtr_->cfind(ext);
if (!mfIter.found()) if (!mfIter.found())
@ -121,7 +133,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
if (delegate.found(ext)) if (delegate.found(ext))
{ {
MeshedSurfaceProxy<Face>(surf).write(name, ext); MeshedSurfaceProxy<Face>(surf).write(name, ext, options);
} }
else else
{ {
@ -134,7 +146,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
} }
else else
{ {
mfIter()(name, surf); mfIter()(name, surf, options);
} }
} }
@ -230,7 +242,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
const Xfer<UnsortedMeshedSurface<Face>>& surf const Xfer<UnsortedMeshedSurface<Face>>& surf
) )
: :
ParentType() UnsortedMeshedSurface<Face>()
{ {
transfer(surf()); transfer(surf());
} }
@ -242,7 +254,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
const Xfer<MeshedSurface<Face>>& surf const Xfer<MeshedSurface<Face>>& surf
) )
: :
ParentType() UnsortedMeshedSurface<Face>()
{ {
transfer(surf()); transfer(surf());
} }
@ -255,7 +267,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
const word& ext const word& ext
) )
: :
ParentType() UnsortedMeshedSurface<Face>()
{ {
read(name, ext); read(name, ext);
} }
@ -267,7 +279,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
const fileName& name const fileName& name
) )
: :
ParentType() UnsortedMeshedSurface<Face>()
{ {
read(name); read(name);
} }
@ -279,9 +291,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
Istream& is Istream& is
) )
: :
ParentType(), UnsortedMeshedSurface<Face>()
zoneIds_(),
zoneToc_()
{ {
read(is); read(is);
} }
@ -294,20 +304,13 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
const word& surfName const word& surfName
) )
: :
ParentType() UnsortedMeshedSurface<Face>()
{ {
MeshedSurface<Face> surf(t, surfName); MeshedSurface<Face> surf(t, surfName);
transfer(surf); transfer(surf);
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face>
Foam::UnsortedMeshedSurface<Face>::~UnsortedMeshedSurface()
{}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Face> template<class Face>
@ -410,27 +413,28 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
) )
{ {
// re-assign the zone Ids // re-assign the zone Ids
if (notNull(faceMap) && faceMap.size()) if (isNull(faceMap) || faceMap.empty())
{ {
if (zoneToc_.empty()) return;
{ }
setOneZone();
}
else if (zoneToc_.size() == 1)
{
// optimized for single-zone case
zoneIds_ = 0;
}
else
{
List<label> newZones(faceMap.size());
forAll(faceMap, facei) if (zoneToc_.empty())
{ {
newZones[facei] = zoneIds_[faceMap[facei]]; setOneZone();
} }
zoneIds_.transfer(newZones); else if (zoneToc_.size() == 1)
{
zoneIds_ = 0; // Optimized for single-zone case
}
else
{
List<label> newZones(faceMap.size());
forAll(faceMap, facei)
{
newZones[facei] = zoneIds_[faceMap[facei]];
} }
zoneIds_.transfer(newZones);
} }
} }
@ -732,16 +736,14 @@ Foam::UnsortedMeshedSurface<Face>::xferZoneIds()
template<class Face> template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::read(const fileName& name) bool Foam::UnsortedMeshedSurface<Face>::read(const fileName& name)
{ {
word ext = name.ext(); const word ext(name.ext());
if (ext == "gz") if (ext == "gz")
{ {
fileName unzipName = name.lessExt(); fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext()); return read(unzipName, unzipName.ext());
} }
else
{ return read(name, ext);
return read(name, ext);
}
} }

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,9 +50,9 @@ SourceFiles
#include "surfZoneIdentifierList.H" #include "surfZoneIdentifierList.H"
#include "surfZoneList.H" #include "surfZoneList.H"
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "HashSet.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H" #include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -163,7 +163,10 @@ public:
//- Can we write this file format? //- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false); static bool canWriteType(const word& ext, const bool verbose=false);
//- Known readable file-types
static wordHashSet readTypes(); static wordHashSet readTypes();
//- Known writable file-types
static wordHashSet writeTypes(); static wordHashSet writeTypes();
@ -240,16 +243,16 @@ public:
//- Select constructed from filename (explicit extension) //- Select constructed from filename (explicit extension)
static autoPtr<UnsortedMeshedSurface> New static autoPtr<UnsortedMeshedSurface> New
( (
const fileName&, const fileName& name,
const word& ext const word& ext
); );
//- Select constructed from filename (implicit extension) //- Select constructed from filename (implicit extension)
static autoPtr<UnsortedMeshedSurface> New(const fileName&); static autoPtr<UnsortedMeshedSurface> New(const fileName& name);
//- Destructor //- Destructor
virtual ~UnsortedMeshedSurface(); virtual ~UnsortedMeshedSurface() = default;
// Member Function Selectors // Member Function Selectors
@ -262,16 +265,27 @@ public:
fileExtension, fileExtension,
( (
const fileName& name, const fileName& name,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
), ),
(name, surf) (name, surf, options)
); );
//- Write to file //- Write to file, select based on its extension
static void write static void write
( (
const fileName&, const fileName& name,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
);
//- Write to file, selected based on given extension
static void write
(
const fileName& name,
const word& ext,
const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
); );
@ -381,16 +395,20 @@ public:
// Write // Write
//- Generic write routine. Chooses writer based on extension. //- Generic write routine. Chooses writer based on its extension.
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, *this); write(name, *this, options);
} }
//- Write to database //- Write to database
void write void write
( (
const Time&, const Time& t,
const word& surfName = word::null const word& surfName = word::null
) const; ) const;

View File

@ -30,7 +30,11 @@ License
template<class Face> template<class Face>
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>> Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>>
Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext) Foam::UnsortedMeshedSurface<Face>::New
(
const fileName& name,
const word& ext
)
{ {
if (debug) if (debug)
{ {

View File

@ -50,12 +50,6 @@ Foam::mergedSurf::mergedSurf
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::mergedSurf::~mergedSurf()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::mergedSurf::use() bool Foam::mergedSurf::use()

View File

@ -72,7 +72,7 @@ public:
//- Destructor //- Destructor
virtual ~mergedSurf(); virtual ~mergedSurf() = default;
// Access Member Functions // Access Member Functions

View File

@ -34,7 +34,7 @@ Description
#include "pointField.H" #include "pointField.H"
#include "faceList.H" #include "faceList.H"
#include "ListOps.H" #include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,13 +52,11 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
meshedSurf() meshedSurf() = default;
{}
//- Destructor //- Destructor
virtual ~meshedSurf() virtual ~meshedSurf() = default;
{}
// Access Member Functions // Access Member Functions

View File

@ -33,7 +33,6 @@ Description
#define meshedSurfRef_H #define meshedSurfRef_H
#include "meshedSurf.H" #include "meshedSurf.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,8 +62,6 @@ class meshedSurfRef
public: public:
// Public Member Functions
// Constructors // Constructors
//- Construct from components //- Construct from components
@ -82,8 +79,7 @@ public:
//- Destructor //- Destructor
virtual ~meshedSurfRef() virtual ~meshedSurfRef() = default;
{}
// Access Member Functions // Access Member Functions

View File

@ -424,9 +424,9 @@ void Foam::surfMesh::addZones
{ {
surfZoneList& zones = Allocator::storedIOZones(); surfZoneList& zones = Allocator::storedIOZones();
forAll(zones, zoneI) forAll(zones, zonei)
{ {
zones[zoneI] = surfZone(srfZones[zoneI], zoneI); zones[zonei] = surfZone(srfZones[zonei], zonei);
} }
if (validate) if (validate)
@ -452,20 +452,29 @@ void Foam::surfMesh::removeFiles() const
} }
void Foam::surfMesh::write(const fileName& name, const surfMesh& surf) void Foam::surfMesh::write
(
const fileName& name,
const dictionary& options
) const
{ {
MeshedSurfaceProxy<face> write(name, name.ext(), options);
(
surf.points(),
surf.faces(),
surf.surfZones()
).write(name);
} }
void Foam::surfMesh::write(const fileName& name) void Foam::surfMesh::write
(
const fileName& name,
const word& ext,
const dictionary& options
) const
{ {
write(name, *this); MeshedSurfaceProxy<face>
(
this->points(),
this->faces(),
this->surfZones()
).write(name, ext, options);
} }

View File

@ -69,7 +69,7 @@ public:
//- Enumeration defining the state of the mesh after a read update. //- Enumeration defining the state of the mesh after a read update.
// Used for post-processing applications, where the mesh // Used for post-processing applications, where the mesh
// needs to update based on the files written in time directores // needs to update based on the files written in time directories
enum readUpdateState enum readUpdateState
{ {
UNCHANGED, UNCHANGED,
@ -157,7 +157,7 @@ public:
//- Construct from IOobject, with alternative surface name //- Construct from IOobject, with alternative surface name
explicit surfMesh explicit surfMesh
( (
const IOobject&, const IOobject& io,
const word& surfName = word::null const word& surfName = word::null
); );
@ -165,16 +165,16 @@ public:
// surfZones are added using addZones() member function // surfZones are added using addZones() member function
surfMesh surfMesh
( (
const IOobject&, const IOobject& io,
const Xfer<pointField>&, const Xfer<pointField>& pointLst,
const Xfer<faceList>&, const Xfer<faceList>& faceLst,
const word& surfName = word::null const word& surfName = word::null
); );
//- Construct copy/move from MeshedSurface //- Construct copy/move from MeshedSurface
surfMesh surfMesh
( (
const IOobject&, const IOobject& io,
const Xfer<MeshedSurface<face>>& surf, const Xfer<MeshedSurface<face>>& surf,
const word& surfName = word::null const word& surfName = word::null
); );
@ -192,7 +192,7 @@ public:
fileName meshDir() const; fileName meshDir() const;
//- Return the current instance directory for points //- Return the current instance directory for points
// Used in the consruction of geometric mesh data dependent // Used in the construction of geometric mesh data dependent
// on points // on points
const fileName& pointsInstance() const; const fileName& pointsInstance() const;
@ -262,7 +262,7 @@ public:
//- Add surface zones //- Add surface zones
void addZones void addZones
( (
const List<surfZone>&, const surfZoneList& srfZones,
const bool validate = true const bool validate = true
); );
@ -294,7 +294,7 @@ public:
//- Transfer the contents of the argument and annul the argument //- Transfer the contents of the argument and annul the argument
void transfer(MeshedSurface<face>&); void transfer(MeshedSurface<face>& surf);
// Writing // Writing
@ -311,11 +311,23 @@ public:
const bool valid const bool valid
) const; ) const;
//- Write to file
static void write(const fileName&, const surfMesh&);
//- Write to file //- Write to file, choosing writer based on its extension.
void write(const fileName&); // Uses MeshedSurfaceProxy for writing.
void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const;
//- Write to file, choosing writer given extension.
// Uses MeshedSurfaceProxy for writing.
void write
(
const fileName& name,
const word& ext,
const dictionary& options = dictionary::null
) const;
// Storage management // Storage management

View File

@ -62,29 +62,32 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
is.getLine(line); is.getLine(line);
string version = line.substr(4); // Verify version
if (version != "b")
{ {
WarningInFunction const string version = line.substr(4);
<< "When reading AC3D file " << filename
<< " read header " << line << " with version " if (version != "b")
<< version << endl {
<< "Only tested reading with version 'b'." WarningInFunction
<< " This might give problems" << endl; << "When reading AC3D file " << filename
<< " read header " << line << " with version "
<< version << endl
<< "Only tested reading with version 'b'."
<< " This might give problems" << endl;
}
} }
if (!cueTo(is, "OBJECT", args) || (args != "world")) if (!cueTo(is, "OBJECT", args) || args != "world")
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Cannot find \"OBJECT world\" in file " << filename << "Cannot find \"OBJECT world\" in file " << filename
<< exit(FatalError); << exit(FatalError);
} }
// # of kids is the # of zones // Number of kids is the number of zones
args = cueToOrDie(is, "kids"); args = cueToOrDie(is, "kids");
label nZones = parse<int>(args); const label nZones = parse<int>(args);
// Start of vertices for object/zones // Start of vertices for object/zones
label vertexOffset = 0; label vertexOffset = 0;
@ -170,11 +173,11 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
} }
else if (cmd == "numsurf") else if (cmd == "numsurf")
{ {
label nFaces = parse<int>(args); const label nFaces = parse<int>(args);
for (label facei = 0; facei < nFaces; ++facei) for (label facei = 0; facei < nFaces; ++facei)
{ {
static string errorMsg = const string errorMsg =
string(" while reading face ") string(" while reading face ")
+ Foam::name(facei) + " on zone " + Foam::name(facei) + " on zone "
+ Foam::name(zoneI) + Foam::name(zoneI)
@ -184,13 +187,13 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
cueToOrDie(is, "mat", errorMsg); cueToOrDie(is, "mat", errorMsg);
args = cueToOrDie(is, "refs", errorMsg); args = cueToOrDie(is, "refs", errorMsg);
label nVert = parse<int>(args); const label nVert = parse<int>(args);
List<label> verts(nVert); List<label> verts(nVert);
forAll(verts, vertI) forAll(verts, vertI)
{ {
is.getLine(line); is.getLine(line);
verts[vertI] = parse<int>(line) + vertexOffset; verts[vertI] = vertexOffset + parse<int>(line);
} }
const labelUList& f = static_cast<const labelUList&>(verts); const labelUList& f = static_cast<const labelUList&>(verts);
@ -221,7 +224,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
else if (cmd == "kids") else if (cmd == "kids")
{ {
// 'kids' denotes the end of the current zone. // 'kids' denotes the end of the current zone.
label nKids = parse<int>(args); const label nKids = parse<int>(args);
if (nKids != 0) if (nKids != 0)
{ {
@ -275,26 +278,22 @@ static void writeZone
os << "numvert " << patch.nPoints() << nl; os << "numvert " << patch.nPoints() << nl;
forAll(patch.localPoints(), pti) for (const point& pt : patch.localPoints())
{ {
const point& pt = patch.localPoints()[pti];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
os << "numsurf " << patch.size() << nl; os << "numsurf " << patch.size() << nl;
forAll(patch.localFaces(), facei) for (const Face& f : patch.localFaces())
{ {
const Face& f = patch.localFaces()[facei];
os << "SURF 0x20" << nl // polygon os << "SURF 0x20" << nl // polygon
<< "mat " << zoneI << nl << "mat " << zoneI << nl
<< "refs " << f.size() << nl; << "refs " << f.size() << nl;
forAll(f, fp) for (const label verti : f)
{ {
os << f[fp] << " 0 0" << nl; os << verti << " 0 0" << nl;
} }
} }
@ -306,13 +305,14 @@ template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().size() surf.surfZones().size()
? surf.surfZones() ? surf.surfZones()
@ -342,10 +342,9 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
return; return;
} }
forAll(zones, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI];
if (useFaceMap) if (useFaceMap)
{ {
SubList<label> zoneMap(surf.faceMap(), zone.size(), zone.start()); SubList<label> zoneMap(surf.faceMap(), zone.size(), zone.start());
@ -355,7 +354,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
pointLst pointLst
); );
writeZone(os, patch, zone.name(), zoneI); writeZone(os, patch, zone.name(), zoneIndex);
} }
else else
{ {
@ -365,8 +364,10 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
pointLst pointLst
); );
writeZone(os, patch, zone.name(), zoneI); writeZone(os, patch, zone.name(), zoneIndex);
} }
++zoneIndex;
} }
} }
@ -375,7 +376,8 @@ template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary&
) )
{ {
OFstream os(filename); OFstream os(filename);
@ -404,10 +406,10 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
} }
writeHeader(os, zoneLst); writeHeader(os, zoneLst);
forAll(zoneLst, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
label zoneIndex = 0;
for (const surfZone& zone : zoneLst)
{
SubList<label> zoneMap(faceMap, zone.size(), zone.start()); SubList<label> zoneMap(faceMap, zone.size(), zone.start());
PrimitivePatch<Face, UIndirectList, const pointField&> patch PrimitivePatch<Face, UIndirectList, const pointField&> patch
( (
@ -415,7 +417,9 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
surf.points() surf.points()
); );
writeZone(os, patch, zone.name(), zoneI); writeZone(os, patch, zone.name(), zoneIndex);
++zoneIndex;
} }
} }

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::fileFormats::AC3DsurfaceFormat Foam::fileFormats::AC3DsurfaceFormat
Description Description
Provide a means of reading/writing AC3D format. Read/write AC3D format.
http://www.inivis.com/ac3d/man/ac3dfileformat.html http://www.inivis.com/ac3d/man/ac3dfileformat.html
@ -55,7 +55,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class AC3DsurfaceFormat Declaration Class fileFormats::AC3DsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -78,49 +78,45 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
AC3DsurfaceFormat(const fileName&); AC3DsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new AC3DsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~AC3DsurfaceFormat() virtual ~AC3DsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, the output is always sorted by zones. //- Write UnsortedMeshedSurface, the output is always sorted by zones.
static void write static void write
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -28,6 +28,22 @@ License
#include "IFstream.H" #include "IFstream.H"
#include "StringStream.H" #include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Define 8 standard colours as r,g,b components
static float colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
@ -42,9 +58,9 @@ bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
string line; string line;
is.getLine(line); is.getLine(line);
string::size_type space = line.find(' '); const auto space = line.find(' ');
if (space != string::npos) if (space && space != string::npos)
{ {
cmd = line.substr(0, space); cmd = line.substr(0, space);
args = line.substr(space+1); args = line.substr(space+1);
@ -52,12 +68,11 @@ bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
return true; return true;
} }
} }
return false; return false;
} }
// Read up to line starting with cmd. Sets args to rest of line.
// Returns true if found, false if stream is not good anymore.
bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
( (
IFstream& is, IFstream& is,
@ -70,23 +85,20 @@ bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
string line; string line;
is.getLine(line); is.getLine(line);
string::size_type space = line.find(' '); const auto space = line.find(' ');
if (space != string::npos) if (space && space != string::npos && cmd == line.substr(0, space))
{ {
if (line.substr(0, space) == cmd) args = line.substr(space+1);
{
args = line.substr(space+1);
return true; return true;
}
} }
} }
return false; return false;
} }
// Similar to cueTo(), but throws error if cmd not found
Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
( (
IFstream& is, IFstream& is,
@ -110,35 +122,22 @@ Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
( (
Ostream& os, Ostream& os,
const UList<surfZone>& zoneLst const UList<surfZone>& zones
) )
{ {
// Write with zones as separate objects under "world" object. // Write with zones as separate objects under "world" object.
// Header is taken over from sample file. // Header is taken over from sample file.
// Defines separate materials for all zones. Recycle colours. // Defines separate materials for all zones. Recycle colours.
// Define 8 standard colours as r,g,b components
static scalar colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// Write header. Define materials. // Write header. Define materials.
os << "AC3Db" << nl; os << "AC3Db" << nl;
forAll(zoneLst, zoneI) forAll(zones, zonei)
{ {
label colourI = zoneI % 8; const label colourI = zonei % 8;
label colourCompI = 3 * colourI; const label colourCompI = 3 * colourI;
os << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb " os << "MATERIAL \"" << zones[zonei].name() << "Mat\" rgb "
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1] << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
<< ' ' << colourMap[colourCompI+2] << ' ' << colourMap[colourCompI+2]
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10" << " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
@ -147,7 +146,7 @@ void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
} }
os << "OBJECT world" << nl os << "OBJECT world" << nl
<< "kids " << zoneLst.size() << endl; << "kids " << zones.size() << endl;
} }

View File

@ -36,8 +36,7 @@ SourceFiles
#define AC3DsurfaceFormatCore_H #define AC3DsurfaceFormatCore_H
#include "Fstream.H" #include "Fstream.H"
#include "Ostream.H" #include "surfZone.H"
#include "MeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,27 +46,32 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class AC3DsurfaceFormatCore Declaration Class fileFormats::AC3DsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class AC3DsurfaceFormatCore class AC3DsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Static Member Functions
//- Read a type via IStringStream //- Read a type via IStringStream
template<class Type> template<class Type>
static Type parse(const string&); static Type parse(const string& str);
//- Read cmd, args from IFstream //- Read cmd, args from IFstream
static bool readCmd(IFstream&, string& cmd, string& args); // The cmd is the content up to the first space, args is the balance
// of the line (after the space).
// \return if the command was read
static bool readCmd(IFstream& is, string& cmd, string& args);
//- Cue up to cmd, reading args //- Read up to a line starting with cmd. Sets args to rest of line.
//
// \return true if found, false if stream is not good anymore.
static bool cueTo(IFstream&, const string& cmd, string& args); static bool cueTo(IFstream&, const string& cmd, string& args);
//- Cue up to cmd, reading args or exit with a FatalError //- Like cueTo(), but FatalError if not found.
// returns the command args // \return the command args on success
static string cueToOrDie static string cueToOrDie
( (
IFstream&, IFstream&,
@ -75,8 +79,8 @@ protected:
const string& errorMsg=string::null const string& errorMsg=string::null
); );
//- Write header with materials //- Write header with materials for each zone
static void writeHeader(Ostream&, const UList<surfZone>&); static void writeHeader(Ostream& os, const UList<surfZone>& zones);
}; };

View File

@ -29,12 +29,13 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
Type Foam::fileFormats::AC3DsurfaceFormatCore::parse(const string& s) Type Foam::fileFormats::AC3DsurfaceFormatCore::parse(const string& str)
{ {
IStringStream ss(s); IStringStream is(str);
Type t; Type t;
ss >> t; is >> t;
return t; return t;
} }

View File

@ -2,7 +2,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) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,7 +34,7 @@ inline static void newline(Foam::OSstream& os)
{ {
if (os.format() == Foam::IOstream::ASCII) if (os.format() == Foam::IOstream::ASCII)
{ {
os << Foam::endl; os << '\n';
} }
} }
@ -61,9 +61,9 @@ inline void Foam::fileFormats::FLMAsurfaceFormat<Face>::writeShell
if (f.size() == 3 || f.size() == 4) if (f.size() == 3 || f.size() == 4)
{ {
putFireLabel(os, f.size()); putFireLabel(os, f.size());
forAll(f, fp) for (const label verti : f)
{ {
putFireLabel(os, f[fp]); putFireLabel(os, verti);
} }
} }
else else
@ -72,7 +72,7 @@ inline void Foam::fileFormats::FLMAsurfaceFormat<Face>::writeShell
// better triangulation should have been done before // better triangulation should have been done before
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{ {
label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
putFireLabel(os, 3); putFireLabel(os, 3);
putFireLabel(os, f[0]); putFireLabel(os, f[0]);
@ -87,9 +87,9 @@ inline void Foam::fileFormats::FLMAsurfaceFormat<Face>::writeShell
if (f.size() == 3 || f.size() == 4) if (f.size() == 3 || f.size() == 4)
{ {
os << ' ' << f.size(); os << ' ' << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
os << nl; os << nl;
} }
@ -97,7 +97,7 @@ inline void Foam::fileFormats::FLMAsurfaceFormat<Face>::writeShell
{ {
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{ {
label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
os << ' ' << 3 << ' ' os << ' ' << 3 << ' '
<< f[0] << ' ' << f[fp1] << ' ' << f[fp2] << f[0] << ' ' << f[fp1] << ' ' << f[fp2]
<< nl; << nl;
@ -164,9 +164,9 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
<< exit(FatalError); << exit(FatalError);
} }
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const List<surfZone>& zones =
@ -222,10 +222,10 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
putFireLabel(os, pointLst.size()); putFireLabel(os, pointLst.size());
newline(os); newline(os);
forAll(pointLst, ptI) for (const point& pt : pointLst)
{ {
// scaling is normally 1 // scaling is normally 1
putFirePoint(os, pointLst[ptI]); putFirePoint(os, pt);
} }
newline(os); // readability newline(os); // readability
@ -236,20 +236,20 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
newline(os); newline(os);
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFaceI) for (label i=0; i<nLocalFaces; ++i)
{ {
writeShell(os, faceLst[faceMap[faceIndex++]]); writeShell(os, faceLst[faceMap[faceIndex++]]);
} }
} }
else else
{ {
forAll(zone, localFaceI) for (label i=0; i<nLocalFaces; ++i)
{ {
writeShell(os, faceLst[faceIndex++]); writeShell(os, faceLst[faceIndex++]);
} }
@ -266,20 +266,20 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
newline(os); newline(os);
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFaceI) for (label i=0; i<nLocalFaces; ++i)
{ {
writeType(os, faceLst[faceMap[faceIndex++]]); writeType(os, faceLst[faceMap[faceIndex++]]);
} }
} }
else else
{ {
forAll(zone, localFaceI) for (label i=0; i<nLocalFaces; ++i)
{ {
writeType(os, faceLst[faceIndex++]); writeType(os, faceLst[faceIndex++]);
} }
@ -316,9 +316,9 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
template<class Face> template<class Face>
void Foam::fileFormats::FLMAsurfaceFormat<Face>::write void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
( (
bool compress,
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf, const MeshedSurfaceProxy<Face>& surf
bool compress
) )
{ {
autoPtr<OFstream> osPtr autoPtr<OFstream> osPtr
@ -361,10 +361,11 @@ template<class Face>
void Foam::fileFormats::FLMAsurfaceFormat<Face>::write void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
write(filename, surf, false); write(false, filename, surf);
} }
@ -372,10 +373,11 @@ template<class Face>
void Foam::fileFormats::FLMAZsurfaceFormat<Face>::write void Foam::fileFormats::FLMAZsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
FLMAsurfaceFormat<Face>::write(filename, surf, true); FLMAsurfaceFormat<Face>::write(true, filename, surf);
} }

View File

@ -2,7 +2,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) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,7 +47,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class FLMAsurfaceFormat Declaration Class fileFormats::FLMAsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -58,8 +58,8 @@ class FLMAsurfaceFormat
{ {
// Private Member Functions // Private Member Functions
static inline void writeShell(OSstream&, const Face&); static inline void writeShell(OSstream& os, const Face& f);
static inline void writeType(OSstream&, const Face&); static inline void writeType(OSstream& os, const Face& f);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
FLMAsurfaceFormat(const FLMAsurfaceFormat<Face>&) = delete; FLMAsurfaceFormat(const FLMAsurfaceFormat<Face>&) = delete;
@ -75,17 +75,17 @@ protected:
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
OSstream&, OSstream& os,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf
); );
//- Write surface mesh components by proxy with/without compression //- Write surface mesh components by proxy with/without compression
static void write static void write
( (
const fileName&, bool compress,
const MeshedSurfaceProxy<Face>&, const fileName& filename,
bool compress const MeshedSurfaceProxy<Face>& surf
); );
@ -94,28 +94,34 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
FLMAsurfaceFormat() FLMAsurfaceFormat() = default;
{}
//- Destructor //- Destructor
virtual ~FLMAsurfaceFormat() virtual ~FLMAsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Write flma file //- Write flma file
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };
@ -144,28 +150,34 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
FLMAZsurfaceFormat() FLMAZsurfaceFormat() = default;
{}
//- Destructor //- Destructor
virtual ~FLMAZsurfaceFormat() virtual ~FLMAZsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Write flmaz file //- Write flmaz file
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -30,6 +30,40 @@ License
#include "StringStream.H" #include "StringStream.H"
#include "faceTraits.H" #include "faceTraits.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Face>
bool Foam::fileFormats::GTSsurfaceFormat<Face>::checkIfTriangulated
(
const UList<Face>& faceLst
)
{
label nNonTris = 0;
if (!faceTraits<Face>::isTri())
{
for (const auto& f : faceLst)
{
if (f.size() != 3)
{
++nNonTris;
}
}
}
if (nNonTris)
{
FatalErrorInFunction
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
}
return nNonTris == 0;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -96,7 +130,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
pointLst[pointi] = point(x, y, z); pointLst[pointi] = point(x, y, z);
} }
// Read edges (Foam indexing) // Read edges (OpenFOAM indexing)
edgeList edges(nEdges); edgeList edges(nEdges);
forAll(edges, edgei) forAll(edges, edgei)
{ {
@ -159,10 +193,10 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
<< exit(FatalError); << exit(FatalError);
} }
label e0Far = e0.otherVertex(common01); const label e0Far = e0.otherVertex(common01);
label e1Far = e1.otherVertex(common01); const label e1Far = e1.otherVertex(common01);
label common12 = e1.commonVertex(e2); const label common12 = e1.commonVertex(e2);
if (common12 == -1) if (common12 == -1)
{ {
FatalErrorInFunction FatalErrorInFunction
@ -172,7 +206,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
<< " edge2:" << e2 << " edge2:" << e2
<< exit(FatalError); << exit(FatalError);
} }
label e2Far = e2.otherVertex(common12); const label e2Far = e2.otherVertex(common12);
// Does edge2 sit between edge1 and 0? // Does edge2 sit between edge1 and 0?
if (common12 != e1Far || e2Far != e0Far) if (common12 != e1Far || e2Far != e0Far)
@ -212,41 +246,21 @@ template<class Face>
void Foam::fileFormats::GTSsurfaceFormat<Face>::write void Foam::fileFormats::GTSsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().size() surf.surfZones().size()
? surf.surfZones() ? surf.surfZones()
: surfaceFormatsCore::oneZone(faceLst) : surfaceFormatsCore::oneZone(faceLst)
); );
// check if output triangulation would be required checkIfTriangulated(faceLst);
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
if (!faceTraits<Face>::isTri())
{
label nNonTris = 0;
forAll(faceLst, facei)
{
if (faceLst[facei].size() != 3)
{
++nNonTris;
}
}
if (nNonTris)
{
FatalErrorInFunction
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
return;
}
}
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
@ -270,14 +284,12 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
os << "# nPoints nEdges nTriangles" << nl os << "# nPoints nEdges nTriangles" << nl
<< pointLst.size() << ' ' << surf.nEdges() << ' ' << pointLst.size() << ' ' << surf.nEdges() << ' '
<< surf.size() << endl; << surf.size() << nl;
// Write vertex coords // Write vertex coords
forAll(pointLst, pointi) for (const point& pt : pointLst)
{ {
const point& pt = pointLst[pointi];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
@ -287,29 +299,32 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
const edgeList& es = surf.edges(); const edgeList& es = surf.edges();
const labelList& meshPts = surf.meshPoints(); const labelList& meshPts = surf.meshPoints();
forAll(es, edgei) for (const edge& e : es)
{ {
os << meshPts[es[edgei].start()] + 1 << ' ' os << meshPts[e.start()] + 1 << ' '
<< meshPts[es[edgei].end()] + 1 << endl; << meshPts[e.end()] + 1 << nl;
} }
// Write faces in terms of edges. // Write faces in terms of edges.
const labelListList& faceEs = surf.faceEdges(); const labelListList& faceEs = surf.faceEdges();
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const labelList& fEdges = faceEs[faceIndex++]; const labelList& fEdges = faceEs[faceIndex++];
os << fEdges[0] + 1 << ' ' os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' ' << fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' ' << fEdges[2] + 1 << ' '
<< zoneI << endl; << zoneIndex << nl;
} }
++zoneIndex;
} }
} }
@ -318,36 +333,16 @@ template<class Face>
void Foam::fileFormats::GTSsurfaceFormat<Face>::write void Foam::fileFormats::GTSsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& zoneIds = surf.zoneIds(); const UList<label>& zoneIds = surf.zoneIds();
const List<surfZoneIdentifier>& zoneToc = surf.zoneToc(); const UList<surfZoneIdentifier>& zoneToc = surf.zoneToc();
// check if output triangulation would be required checkIfTriangulated(faceLst);
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
if (!faceTraits<Face>::isTri())
{
label nNonTris = 0;
forAll(faceLst, facei)
{
if (faceLst[facei].size() != 3)
{
++nNonTris;
}
}
if (nNonTris)
{
FatalErrorInFunction
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
return;
}
}
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
@ -367,20 +362,18 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
os << "# " << zoneI << " " os << "# " << zoneI << " "
<< zoneToc[zoneI].name() << nl; << zoneToc[zoneI].name() << nl;
} }
os << "#" << endl; os << "#" << nl;
os << "# nPoints nEdges nTriangles" << nl os << "# nPoints nEdges nTriangles" << nl
<< pointLst.size() << ' ' << surf.nEdges() << ' ' << pointLst.size() << ' ' << surf.nEdges() << ' '
<< surf.size() << endl; << surf.size() << nl;
// Write vertex coords // Write vertex coords
forAll(pointLst, pointi) for (const point& pt : pointLst)
{ {
os << pointLst[pointi].x() << ' ' os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
<< pointLst[pointi].y() << ' '
<< pointLst[pointi].z() << endl;
} }
@ -389,13 +382,12 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
const edgeList& es = surf.edges(); const edgeList& es = surf.edges();
const labelList& meshPts = surf.meshPoints(); const labelList& meshPts = surf.meshPoints();
forAll(es, edgeI) for (const edge& e : es)
{ {
os << meshPts[es[edgeI].start()] + 1 << ' ' os << meshPts[e.start()] + 1 << ' '
<< meshPts[es[edgeI].end()] + 1 << endl; << meshPts[e.end()] + 1 << nl;
} }
// Write faces in terms of edges. // Write faces in terms of edges.
const labelListList& faceEs = surf.faceEdges(); const labelListList& faceEs = surf.faceEdges();
@ -406,7 +398,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
os << fEdges[0] + 1 << ' ' os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' ' << fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' ' << fEdges[2] + 1 << ' '
<< zoneIds[facei] << endl; << zoneIds[facei] << nl;
} }
} }

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,8 @@ Class
Foam::fileFormats::GTSsurfaceFormat Foam::fileFormats::GTSsurfaceFormat
Description Description
Provide a means of reading/writing GTS format. Read/write GTS format.
The output is never sorted by zone and is only written if it consists The output is never sorted by zone and is only written if it consists
entirely of triangles. entirely of triangles.
@ -49,7 +50,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class GTSsurfaceFormat Declaration Class fileFormats::GTSsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -59,6 +60,10 @@ class GTSsurfaceFormat
{ {
// Private Member Functions // Private Member Functions
//- Check and raise FatalError if output is not triangulated
// Triangulatinng on-the-fly is otherwise too annoying
static bool checkIfTriangulated(const UList<Face>& faceLst);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
GTSsurfaceFormat(const GTSsurfaceFormat<Face>&) = delete; GTSsurfaceFormat(const GTSsurfaceFormat<Face>&) = delete;
@ -71,49 +76,45 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
GTSsurfaceFormat(const fileName&); GTSsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<UnsortedMeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<UnsortedMeshedSurface<Face>>
(
new GTSsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~GTSsurfaceFormat() virtual ~GTSsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write MeshedSurface //- Write MeshedSurface
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurface<Face>& const MeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, the output remains unsorted //- Write UnsortedMeshedSurface, the output remains unsorted
static void write static void write
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, *this); write(name, *this, options);
} }
}; };

View File

@ -24,45 +24,48 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "triSurface.H" #include "triSurface.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void triSurface::writeGTS(const bool writeSorted, Ostream& os) const void Foam::triSurface::writeGTS
(
const fileName& filename,
const bool sort
) const
{ {
OFstream os(filename);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// Write header // Write header
os << "# GTS file" << endl os << "# GTS file" << endl
<< "# Regions:" << endl; << "# Regions:" << endl;
labelList faceMap; labelList faceMap;
surfacePatchList patches(calcPatches(faceMap)); surfacePatchList patches(calcPatches(faceMap));
// Print patch names as comment // Print patch names as comment
forAll(patches, patchi) forAll(patches, patchi)
{ {
os << "# " << patchi << " " os << "# " << patchi << " "
<< patches[patchi].name() << endl; << patches[patchi].name() << nl;
} }
os << "#" << endl; os << "#" << nl;
const pointField& pts = points();
const pointField& ps = points(); os << "# nPoints nEdges nTriangles" << nl
<< pts.size() << ' ' << nEdges() << ' ' << size() << nl;
os << "# nPoints nEdges nTriangles" << endl
<< ps.size() << ' ' << nEdges() << ' ' << size() << endl;
// Write vertex coords // Write vertex coords
for (const point& pt : pts)
forAll(ps, pointi)
{ {
os << ps[pointi].x() << ' ' os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
<< ps[pointi].y() << ' '
<< ps[pointi].z() << endl;
} }
// Write edges. // Write edges.
@ -70,26 +73,23 @@ void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
const edgeList& es = edges(); const edgeList& es = edges();
const labelList& meshPts = meshPoints(); const labelList& meshPts = meshPoints();
forAll(es, edgei) for (const edge& e : es)
{ {
os << meshPts[es[edgei].start()] + 1 << ' ' os << meshPts[e.start()] + 1 << ' '
<< meshPts[es[edgei].end()] + 1 << endl; << meshPts[e.end()] + 1 << nl;
} }
// Write faces in terms of edges. // Write faces in terms of edges.
const labelListList& faceEs = faceEdges(); const labelListList& faceEs = faceEdges();
if (writeSorted) if (sort)
{ {
label faceIndex = 0; label faceIndex = 0;
forAll(patches, patchi) for (const surfacePatch& p : patches)
{ {
for const label nLocalFaces = p.size();
(
label patchFacei = 0; for (label i = 0; i<nLocalFaces; ++i)
patchFacei < patches[patchi].size();
patchFacei++
)
{ {
const label facei = faceMap[faceIndex++]; const label facei = faceMap[faceIndex++];
@ -98,7 +98,7 @@ void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
os << fEdges[0] + 1 << ' ' os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' ' << fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' ' << fEdges[2] + 1 << ' '
<< (*this)[facei].region() << endl; << (*this)[facei].region() << nl;
} }
} }
} }
@ -111,14 +111,10 @@ void triSurface::writeGTS(const bool writeSorted, Ostream& os) const
os << fEdges[0] + 1 << ' ' os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' ' << fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' ' << fEdges[2] + 1 << ' '
<< (*this)[facei].region() << endl; << (*this)[facei].region() << nl;
} }
} }
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -25,9 +25,62 @@ License
#include "NASsurfaceFormat.H" #include "NASsurfaceFormat.H"
#include "IFstream.H" #include "IFstream.H"
#include "StringStream.H" #include "IOmanip.H"
#include "faceTraits.H" #include "faceTraits.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Face>
inline Foam::label Foam::fileFormats::NASsurfaceFormat<Face>::writeShell
(
Ostream& os,
const Face& f,
const label groupId,
label elementId
)
{
const label n = f.size();
if (n == 3)
{
os << "CTRIA3" << ','
<< ++elementId << ','
<< (groupId + 1) << ','
<< (f[0] + 1) << ','
<< (f[1] + 1) << ','
<< (f[2] + 1) << nl;
}
else if (n == 4)
{
os << "CTRIA3" << ','
<< ++elementId << ','
<< (groupId + 1) << ','
<< (f[0] + 1) << ','
<< (f[1] + 1) << ','
<< (f[2] + 1) << ','
<< (f[3] + 1) << nl;
}
else
{
// simple triangulation about f[0].
// better triangulation should have been done before
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
const label fp2 = f.fcIndex(fp1);
os << "CTRIA3" << ','
<< ++elementId << ','
<< (groupId + 1) << ','
<< (f[0] + 1) << ','
<< (f[fp1] + 1) << ','
<< (f[fp2] + 1) << nl;
}
}
return elementId;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -64,7 +117,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
DynamicList<Face> dynFaces; DynamicList<Face> dynFaces;
DynamicList<label> dynZones; DynamicList<label> dynZones;
DynamicList<label> dynSizes; DynamicList<label> dynSizes;
Map<label> lookup; Map<label> zoneLookup;
// assume the types are not intermixed // assume the types are not intermixed
// leave faces that didn't have a group in 0 // leave faces that didn't have a group in 0
@ -86,10 +139,13 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
while (is.good()) while (is.good())
{ {
string::size_type linei = 0; // parsing position within current line
string line; string line;
is.getLine(line); is.getLine(line);
// ANSA extension // ANSA extension
// line 1: $ANSA_NAME;<int>;<word>;
// line 2: $partName
if (line.startsWith("$ANSA_NAME")) if (line.startsWith("$ANSA_NAME"))
{ {
const auto sem0 = line.find(';', 0); const auto sem0 = line.find(';', 0);
@ -98,9 +154,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if if
( (
sem0 != string::npos sem0 != std::string::npos
&& sem1 != string::npos && sem1 != std::string::npos
&& sem2 != string::npos && sem2 != std::string::npos
) )
{ {
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1)); ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
@ -108,7 +164,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
string rawName; string rawName;
is.getLine(rawName); is.getLine(rawName);
rawName.removeEnd("\r"); rawName.removeEnd("\r"); // Possible CR-NL
ansaName = word::validate(rawName.substr(1)); ansaName = word::validate(rawName.substr(1));
// Info<< "ANSA tag for NastranID:" << ansaId // Info<< "ANSA tag for NastranID:" << ansaId
@ -118,26 +174,22 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
// Hypermesh extension // HYPERMESH extension
// $HMNAME COMP 1"partName" // $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos) if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{ {
label groupId = readLabel(line.substr(16, 16)); label groupId = readLabel(line.substr(16, 16));
IStringStream lineStream(line.substr(32));
string rawName; // word::validate automatically removes quotes too
lineStream >> rawName; const word groupName = word::validate(line.substr(32));
const word groupName = word::validate(rawName);
nameLookup.insert(groupId, groupName); nameLookup.insert(groupId, groupName);
// Info<< "group " << groupId << " => " << groupName << endl; // Info<< "group " << groupId << " => " << groupName << endl;
} }
// Skip empty or comment
if (line.empty() || line[0] == '$') if (line.empty() || line[0] == '$')
{ {
continue; continue; // Skip empty or comment
} }
// Check if character 72 is continuation // Check if character 72 is continuation
@ -162,22 +214,20 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
} }
// First word (column 0-8)
// Read first word const word cmd(word::validate(nextNasField(line, linei, 8)));
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "CTRIA3") if (cmd == "CTRIA3")
{ {
label groupId = readLabel(line.substr(16,8)); (void) nextNasField(line, linei, 8); // 8-16
label a = readLabel(line.substr(24,8)); label groupId = readLabel(nextNasField(line, linei, 8)); // 16-24
label b = readLabel(line.substr(32,8)); label a = readLabel(nextNasField(line, linei, 8)); // 24-32
label c = readLabel(line.substr(40,8)); label b = readLabel(nextNasField(line, linei, 8)); // 32-40
label c = readLabel(nextNasField(line, linei, 8)); // 40-48
// Convert groupID into zoneId // Convert groupId into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); const auto fnd = zoneLookup.cfind(groupId);
if (fnd != lookup.end()) if (fnd.found())
{ {
if (zoneI != fnd()) if (zoneI != fnd())
{ {
@ -189,7 +239,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
else else
{ {
zoneI = dynSizes.size(); zoneI = dynSizes.size();
lookup.insert(groupId, zoneI); zoneLookup.insert(groupId, zoneI);
dynSizes.append(0); dynSizes.append(0);
// Info<< "zone" << zoneI << " => group " << groupId <<endl; // Info<< "zone" << zoneI << " => group " << groupId <<endl;
} }
@ -200,15 +250,16 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
else if (cmd == "CQUAD4") else if (cmd == "CQUAD4")
{ {
label groupId = readLabel(line.substr(16,8)); (void) nextNasField(line, linei, 8); // 8-16
label a = readLabel(line.substr(24,8)); label groupId = readLabel(nextNasField(line, linei, 8)); // 16-24
label b = readLabel(line.substr(32,8)); label a = readLabel(nextNasField(line, linei, 8)); // 24-32
label c = readLabel(line.substr(40,8)); label b = readLabel(nextNasField(line, linei, 8)); // 32-40
label d = readLabel(line.substr(48,8)); label c = readLabel(nextNasField(line, linei, 8)); // 40-48
label d = readLabel(nextNasField(line, linei, 8)); // 48-56
// Convert groupID into zoneId // Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); const auto fnd = zoneLookup.cfind(groupId);
if (fnd != lookup.end()) if (fnd.found())
{ {
if (zoneI != fnd()) if (zoneI != fnd())
{ {
@ -220,7 +271,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
else else
{ {
zoneI = dynSizes.size(); zoneI = dynSizes.size();
lookup.insert(groupId, zoneI); zoneLookup.insert(groupId, zoneI);
dynSizes.append(0); dynSizes.append(0);
// Info<< "zone" << zoneI << " => group " << groupId <<endl; // Info<< "zone" << zoneI << " => group " << groupId <<endl;
} }
@ -242,10 +293,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
else if (cmd == "GRID") else if (cmd == "GRID")
{ {
label index = readLabel(line.substr(8,8)); label index = readLabel(nextNasField(line, linei, 8)); // 8-16
scalar x = readNasScalar(line.substr(24, 8)); (void) nextNasField(line, linei, 8); // 16-24
scalar y = readNasScalar(line.substr(32, 8)); scalar x = readNasScalar(nextNasField(line, linei, 8)); // 24-32
scalar z = readNasScalar(line.substr(40, 8)); scalar y = readNasScalar(nextNasField(line, linei, 8)); // 32-40
scalar z = readNasScalar(nextNasField(line, linei, 8)); // 40-48
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
@ -258,10 +310,12 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02 // * 2.14897901E+02
label index = readLabel(line.substr(8,16)); label index = readLabel(nextNasField(line, linei, 16)); // 8-24
scalar x = readNasScalar(line.substr(40, 16)); (void) nextNasField(line, linei, 16); // 24-40
scalar y = readNasScalar(line.substr(56, 16)); scalar x = readNasScalar(nextNasField(line, linei, 16)); // 40-56
scalar y = readNasScalar(nextNasField(line, linei, 16)); // 56-72
linei = 0; // restart at index 0
is.getLine(line); is.getLine(line);
if (line[0] != '*') if (line[0] != '*')
{ {
@ -272,20 +326,21 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
<< "File:" << is.name() << " line:" << is.lineNumber() << "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError); << exit(FatalError);
} }
scalar z = readNasScalar(line.substr(8, 16)); (void) nextNasField(line, linei, 8); // 0-8
scalar z = readNasScalar(nextNasField(line, linei, 16)); // 8-16
pointId.append(index); pointId.append(index);
dynPoints.append(point(x, y, z)); dynPoints.append(point(x, y, z));
} }
else if (cmd == "PSHELL") else if (cmd == "PSHELL")
{ {
// pshell type for zone names with the Ansa extension // Read shell type since group gives patchnames (ANSA extension)
label groupId = readLabel(line.substr(8,8)); label groupId = readLabel(nextNasField(line, linei, 8)); // 8-16
if (groupId == ansaId && ansaType == "PSHELL") if (groupId == ansaId && ansaType == "PSHELL")
{ {
nameLookup.insert(ansaId, ansaName); const word groupName = word::validate(ansaName);
// Info<< "group " << groupId << " => " << ansaName << endl; nameLookup.insert(groupId, groupName);
// Info<< "group " << groupId << " => " << groupName << endl;
} }
} }
else if (unhandledCmd.insert(cmd)) else if (unhandledCmd.insert(cmd))
@ -315,9 +370,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// Relabel faces // Relabel faces
// ~~~~~~~~~~~~~ // ~~~~~~~~~~~~~
forAll(dynFaces, i) for (Face& f : dynFaces)
{ {
Face& f = dynFaces[i];
forAll(f, fp) forAll(f, fp)
{ {
f[fp] = mapPointId[f[fp]]; f[fp] = mapPointId[f[fp]];
@ -329,19 +383,19 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// create default zone names, or from ANSA/Hypermesh information // create default zone names, or from ANSA/Hypermesh information
List<word> names(dynSizes.size()); List<word> names(dynSizes.size());
forAllConstIter(Map<label>, lookup, iter) forAllConstIters(zoneLookup, iter)
{ {
const label zoneI = iter(); const label groupId = iter.key();
const label groupI = iter.key(); const label zoneId = iter.object();
Map<word>::const_iterator fnd = nameLookup.find(groupI); const auto fnd = nameLookup.cfind(groupId);
if (fnd != nameLookup.end()) if (fnd.found())
{ {
names[zoneI] = fnd(); names[zoneId] = fnd();
} }
else else
{ {
names[zoneI] = word("zone") + ::Foam::name(zoneI); names[zoneId] = word("zone") + ::Foam::name(zoneId);
} }
} }
@ -353,4 +407,94 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
template<class Face>
void Foam::fileFormats::NASsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
)
{
const UList<point>& pointLst = surf.points();
const UList<Face>& faceLst = surf.surfFaces();
const UList<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name
const UList<surfZone>& zones =
(
surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst, "")
: surf.surfZones()
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// For simplicity, use fieldFormat::FREE throughout
fileFormats::NASCore::setPrecision(os, fieldFormat::FREE);
os << "CEND" << nl
<< "TITLE = " << os.name().nameLessExt() << nl;
// Print zone names as comment
forAll(zones, zonei)
{
// HYPERMESH extension
os << "$HMNAME COMP" << setw(20) << (zonei+1)
<< '"' << zones[zonei].name() << '"' << nl;
}
// Write vertex coords with 1-based point Id
os << "$ GRID POINTS" << nl
<< "BEGIN BULK" << nl;
label pointId = 0;
for (const point& pt : pointLst)
{
os << "GRID" << ','
<< ++pointId << ','
<< 0 << ',' // global coordinate system
<< pt.x() << ',' << pt.y() << ',' << pt.z() << nl;
}
os << "$ ELEMENTS" << nl;
label faceIndex = 0;
label zoneIndex = 0;
label elementId = 0;
for (const surfZone& zone : zones)
{
const label nLocalFaces = zone.size();
if (useFaceMap)
{
for (label i=0; i<nLocalFaces; ++i)
{
const Face& f = faceLst[faceMap[faceIndex++]];
elementId = writeShell(os, f, zoneIndex, elementId);
}
}
else
{
for (label i=0; i<nLocalFaces; ++i)
{
const Face& f = faceLst[faceIndex++];
elementId = writeShell(os, f, zoneIndex, elementId);
}
}
++zoneIndex;
}
os << "ENDDATA" << nl;
}
// ************************************************************************* // // ************************************************************************* //

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,7 +29,7 @@ Description
- Uses the Ansa "$ANSA_NAME" or the Hypermesh "$HMNAME COMP" extensions - Uses the Ansa "$ANSA_NAME" or the Hypermesh "$HMNAME COMP" extensions
to obtain zone names. to obtain zone names.
- Handles Nastran short and long formats, but not free format. - Handles Nastran short, long formats and comma-separated free format.
- Properly handles the Nastran compact floating point notation: \n - Properly handles the Nastran compact floating point notation: \n
\verbatim \verbatim
GRID 28 10.20269-.030265-2.358-8 GRID 28 10.20269-.030265-2.358-8
@ -56,7 +56,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class NASsurfaceFormat Declaration Class fileFormats::NASsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -67,6 +67,15 @@ class NASsurfaceFormat
{ {
// Private Member Functions // Private Member Functions
//- Output CTRIA3 or CQUAD4
inline static label writeShell
(
Ostream& os,
const Face& f,
const label groupId,
label elementId
);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
NASsurfaceFormat(const NASsurfaceFormat<Face>&) = delete; NASsurfaceFormat(const NASsurfaceFormat<Face>&) = delete;
@ -79,30 +88,38 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
NASsurfaceFormat(const fileName&); NASsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new NASsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~NASsurfaceFormat() virtual ~NASsurfaceFormat() = default;
{}
// Static Member Functions
//- Write surface mesh components by proxy
static void write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
);
// Member Functions // Member Functions
//- Read from a file //- Read from a file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object file
virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{
write(name, MeshedSurfaceProxy<Face>(*this), options);
}
}; };

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 | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,6 +87,36 @@ addNamedTemplatedToRunTimeSelectionTable
nas nas
); );
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
NASsurfaceFormat,
face,
write,
fileExtension,
nas
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
NASsurfaceFormat,
triFace,
write,
fileExtension,
nas
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
NASsurfaceFormat,
labelledTri,
write,
fileExtension,
nas
);
} }
} }

View File

@ -72,12 +72,6 @@ Foam::OBJstream::OBJstream
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::OBJstream::~OBJstream()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::Ostream& Foam::OBJstream::write(const char c) Foam::Ostream& Foam::OBJstream::write(const char c)

View File

@ -87,10 +87,10 @@ public:
//- Destructor //- Destructor
~OBJstream(); ~OBJstream() = default;
// Member functions // Member Functions
// Access // Access

View File

@ -146,7 +146,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
} }
else else
{ {
vertexSpec = line.substr(startNum, line.size() - startNum); vertexSpec = line.substr(startNum);
} }
string::size_type slashPos = vertexSpec.find('/'); string::size_type slashPos = vertexSpec.find('/');
@ -176,7 +176,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
// points may be incomplete // points may be incomplete
for (label fp1 = 1; fp1 < f.size() - 1; fp1++) for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{ {
label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
dynFaces.append(Face{f[0], f[fp1], f[fp2]}); dynFaces.append(Face{f[0], f[fp1], f[fp2]});
dynZones.append(zoneI); dynZones.append(zoneI);
@ -208,15 +208,16 @@ template<class Face>
void Foam::fileFormats::OBJsurfaceFormat<Face>::write void Foam::fileFormats::OBJsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst, "") ? surfaceFormatsCore::oneZone(faceLst, "")
@ -242,41 +243,39 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
<< "# zones : " << zones.size() << nl; << "# zones : " << zones.size() << nl;
// Print zone names as comment // Print zone names as comment
forAll(zones, zoneI) forAll(zones, zonei)
{ {
os << "# " << zoneI << " " << zones[zoneI].name() os << "# " << zonei << " " << zones[zonei].name()
<< " (nFaces: " << zones[zoneI].size() << ")" << nl; << " (nFaces: " << zones[zonei].size() << ")" << nl;
} }
os << nl os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << nl; << "# <points count=\"" << pointLst.size() << "\">" << nl;
// Write vertex coords // Write vertex coords
forAll(pointLst, ptI) for (const point& pt : pointLst)
{ {
const point& pt = pointLst[ptI];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
os << "# </points>" << nl os << "# </points>" << nl
<< nl << nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl; << "# <faces count=\"" << faceLst.size() << "\">" << nl;
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI];
if (zone.name().size()) if (zone.name().size())
{ {
os << "g " << zone.name() << endl; os << "g " << zone.name() << nl;
} }
const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
@ -285,12 +284,12 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
{ {
os << ' ' << f[fp] + 1; os << ' ' << f[fp] + 1;
} }
os << endl; os << nl;
} }
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
@ -299,11 +298,11 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
{ {
os << ' ' << f[fp] + 1; os << ' ' << f[fp] + 1;
} }
os << endl; os << nl;
} }
} }
} }
os << "# </faces>" << endl; os << "# </faces>" << nl;
} }

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::fileFormats::OBJsurfaceFormat Foam::fileFormats::OBJsurfaceFormat
Description Description
Provide a means of reading/writing Alias/Wavefront OBJ format. Read/write Alias/Wavefront OBJ format.
Does not handle negative face indices. Does not handle negative face indices.
@ -49,7 +49,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OBJsurfaceFormat Declaration Class fileFormats::OBJsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -71,42 +71,37 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
OBJsurfaceFormat(const fileName&); OBJsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new OBJsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~OBJsurfaceFormat() virtual ~OBJsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object file //- Write object file
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -143,13 +143,14 @@ template<class Face>
void Foam::fileFormats::OFFsurfaceFormat<Face>::write void Foam::fileFormats::OFFsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zoneLst = surf.surfZones(); const UList<surfZone>& zoneLst = surf.surfZones();
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
@ -197,16 +198,18 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
{ {
os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl; os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl;
const label nLocalFaces = zoneLst[zoneI].size();
if (surf.useFaceMap()) if (surf.useFaceMap())
{ {
forAll(zoneLst[zoneI], localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size(); os << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
// add optional zone information // add optional zone information
@ -215,14 +218,14 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
} }
else else
{ {
forAll(zoneLst[zoneI], localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << f.size(); os << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
// add optional zone information // add optional zone information

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,8 +25,7 @@ Class
Foam::fileFormats::OFFsurfaceFormat Foam::fileFormats::OFFsurfaceFormat
Description Description
Provide a means of reading/writing Geomview OFF polyList format. Read/write Geomview OFF polyList format.
See also See also
The <a href="http://www.geoview.org">Geoview</a> The <a href="http://www.geoview.org">Geoview</a>
@ -57,7 +56,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OFFsurfaceFormat Declaration Class fileFormats::OFFsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -79,42 +78,37 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
OFFsurfaceFormat(const fileName&); OFFsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new OFFsurfaceFormat(name)
);
}
//- Destructor //- Destructor
virtual ~OFFsurfaceFormat() virtual ~OFFsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,27 +27,21 @@ License
#include "clock.H" #include "clock.H"
#include "OFstream.H" #include "OFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face> template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst) ? surfaceFormatsCore::oneZone(faceLst)
@ -71,11 +65,11 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
<< pointLst.size() << " 3" << nl; // 3: dimensions << pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords // Write vertex coords
forAll(pointLst, ptI) forAll(pointLst, pti)
{ {
const point& pt = pointLst[ptI]; const point& pt = pointLst[pti];
os << ptI << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << pti << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
os << "# </points>" << nl os << "# </points>" << nl
<< nl << nl
@ -85,38 +79,41 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size(); os << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
os << ' ' << zoneI << endl; os << ' ' << zoneIndex << nl;
} }
} }
else else
{ {
forAll(zones[zoneI], localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << f.size(); os << f.size();
forAll(f, fp) for (const label verti : f)
{ {
os << ' ' << f[fp]; os << ' ' << verti;
} }
os << ' ' << zoneI << endl; os << ' ' << zoneIndex << nl;
} }
} }
++zoneIndex;
} }
// write tail // write tail

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::fileFormats::SMESHsurfaceFormat Foam::fileFormats::SMESHsurfaceFormat
Description Description
Provide a means of writing tetgen SMESH format. Write tetgen SMESH format.
Tetgen http://tetgen.berlios.de Tetgen http://tetgen.berlios.de
@ -53,7 +53,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class SMESHsurfaceFormat Declaration Class fileFormats::SMESHsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -75,27 +75,34 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
SMESHsurfaceFormat(); SMESHsurfaceFormat() = default;
//- Destructor //- Destructor
virtual ~SMESHsurfaceFormat() virtual ~SMESHsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -47,16 +47,16 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
// primitives have <= 8 vertices, but prevent overrun anyhow // primitives have <= 8 vertices, but prevent overrun anyhow
// indent following lines for ease of reading // indent following lines for ease of reading
label count = 0; label count = 0;
forAll(f, fp) for (const label verti : f)
{ {
if ((count % 8) == 0) if ((count % 8) == 0)
{ {
os << nl << " " << cellId; os << nl << " " << cellId;
} }
os << ' ' << f[fp] + 1; os << ' ' << verti + 1;
count++; ++count;
} }
os << endl; os << nl;
} }
@ -160,8 +160,8 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
if (typeId == starcdShellType) if (typeId == starcdShellType)
{ {
// Convert groupID into zoneID // Convert groupID into zoneID
Map<label>::const_iterator fnd = lookup.find(cellTableId); const auto fnd = lookup.cfind(cellTableId);
if (fnd != lookup.end()) if (fnd.found())
{ {
if (zoneI != fnd()) if (zoneI != fnd())
{ {
@ -175,20 +175,19 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
zoneI = dynSizes.size(); zoneI = dynSizes.size();
lookup.insert(cellTableId, zoneI); lookup.insert(cellTableId, zoneI);
Map<word>::const_iterator tableNameIter = const auto tableNameIter = cellTableLookup.cfind(cellTableId);
cellTableLookup.find(cellTableId);
if (tableNameIter == cellTableLookup.end()) if (tableNameIter.found())
{
dynNames.append(tableNameIter());
}
else
{ {
dynNames.append dynNames.append
( (
word("cellTable_") + ::Foam::name(cellTableId) word("cellTable_") + ::Foam::name(cellTableId)
); );
} }
else
{
dynNames.append(tableNameIter());
}
dynSizes.append(0); dynSizes.append(0);
} }
@ -203,10 +202,10 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
label nTri = 0; label nTri = 0;
f.triangles(this->points(), nTri, trias); f.triangles(this->points(), nTri, trias);
forAll(trias, facei) for (const face& tri : trias)
{ {
// a triangular 'face', convert to 'triFace' etc // a triangular 'face', convert to 'triFace' etc
dynFaces.append(Face(trias[facei])); dynFaces.append(Face(tri));
dynZones.append(zoneI); dynZones.append(zoneI);
dynSizes[zoneI]++; dynSizes[zoneI]++;
} }
@ -234,14 +233,15 @@ template<class Face>
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst) ? surfaceFormatsCore::oneZone(faceLst)
@ -250,7 +250,6 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
fileName baseName = filename.lessExt(); fileName baseName = filename.lessExt();
writePoints writePoints
@ -265,10 +264,11 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
forAll(zones, zoneI) forAll(zones, zoneI)
{ {
const surfZone& zone = zones[zoneI]; const surfZone& zone = zones[zoneI];
const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, f, faceIndex, zoneI + 1); writeShell(os, f, faceIndex, zoneI + 1);
@ -276,7 +276,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
writeShell(os, f, faceIndex, zoneI + 1); writeShell(os, f, faceIndex, zoneI + 1);
@ -284,7 +284,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
} }
} }
// write simple .inp file // Write simple .inp file
writeCase writeCase
( (
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(), OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),

View File

@ -54,7 +54,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class STARCDsurfaceFormat Declaration Class fileFormats::STARCDsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -67,8 +67,8 @@ class STARCDsurfaceFormat
static inline void writeShell static inline void writeShell
( (
Ostream&, Ostream& os,
const Face&, const Face& f,
const label cellId, const label cellId,
const label cellTableId const label cellTableId
); );
@ -85,42 +85,37 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
STARCDsurfaceFormat(const fileName&); STARCDsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new STARCDsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~STARCDsurfaceFormat() virtual ~STARCDsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -37,7 +37,7 @@ License
Foam::Map<Foam::word> Foam::Map<Foam::word>
Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
( (
IFstream& is ISstream& is
) )
{ {
Map<word> lookup; Map<word> lookup;
@ -80,7 +80,7 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const UList<point>& pts,
const label nFaces, const label nFaces,
const UList<surfZone>& zoneLst const UList<surfZone>& zoneLst
) )
@ -88,7 +88,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
const word caseName = os.name().nameLessExt(); const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nFaces << " faces" << nl << "! " << pts.size() << " points, " << nFaces << " faces" << nl
<< "! case " << caseName << nl << "! case " << caseName << nl
<< "! ------------------------------" << nl; << "! ------------------------------" << nl;

View File

@ -48,7 +48,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class STARCDsurfaceFormatCore Declaration Class fileFormats::STARCDsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class STARCDsurfaceFormatCore class STARCDsurfaceFormatCore
@ -57,16 +57,16 @@ class STARCDsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Static Member Functions
static Map<word> readInpCellTable(IFstream&); static Map<word> readInpCellTable(ISstream& is);
static void writeCase static void writeCase
( (
Ostream&, Ostream& os,
const pointField&, const UList<point>& pts,
const label nFaces, const label nFaces,
const UList<surfZone>& const UList<surfZone>& zoneLst
); );
}; };

View File

@ -25,6 +25,7 @@ License
#include "STLsurfaceFormat.H" #include "STLsurfaceFormat.H"
#include "triPointRef.H" #include "triPointRef.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -32,22 +33,18 @@ template<class Face>
inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const UList<point>& pts,
const Face& f const Face& f
) )
{ {
// calculate the normal ourselves, for flexibility and speed // calculate the normal ourselves, for flexibility and speed
vector norm = triPointRef vector norm = triPointRef(pts[f[0]], pts[f[1]], pts[f[2]]).normal();
(
pointLst[f[0]],
pointLst[f[1]],
pointLst[f[2]]
).normal();
norm /= mag(norm) + VSMALL; norm /= mag(norm) + VSMALL;
// simple triangulation about f[0]. // simple triangulation about f[0].
// better triangulation should have been done before // better triangulation should have been done before
const point& p0 = pointLst[f[0]]; const point& p0 = pts[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{ {
const label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
@ -58,8 +55,8 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
os, os,
norm, norm,
p0, p0,
pointLst[f[fp1]], pts[f[fp1]],
pointLst[f[fp2]] pts[f[fp2]]
); );
} }
} }
@ -69,23 +66,19 @@ template<class Face>
inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
( (
ostream& os, ostream& os,
const pointField& pointLst, const UList<point>& pts,
const Face& f, const Face& f,
const label zoneI const label zoneI
) )
{ {
// calculate the normal ourselves, for flexibility and speed // calculate the normal ourselves, for flexibility and speed
vector norm = triPointRef vector norm = triPointRef(pts[f[0]], pts[f[1]], pts[f[2]]).normal();
(
pointLst[f[0]],
pointLst[f[1]],
pointLst[f[2]]
).normal();
norm /= mag(norm) + VSMALL; norm /= mag(norm) + VSMALL;
// simple triangulation about f[0]. // simple triangulation about f[0].
// better triangulation should have been done before // better triangulation should have been done before
const point& p0 = pointLst[f[0]]; const point& p0 = pts[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{ {
const label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
@ -95,8 +88,8 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
( (
norm, norm,
p0, p0,
pointLst[f[fp1]], pts[f[fp1]],
pointLst[f[fp2]], pts[f[fp2]],
zoneI zoneI
).write(os); ).write(os);
} }
@ -148,7 +141,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
List<label> sizes(reader.sizes().xfer()); List<label> sizes(reader.sizes().xfer());
List<label> zoneIds(reader.zoneIds().xfer()); List<label> zoneIds(reader.zoneIds().xfer());
// generate the (sorted) faces // Generate the (sorted) faces
List<Face> faceLst(zoneIds.size()); List<Face> faceLst(zoneIds.size());
if (reader.sorted()) if (reader.sorted())
@ -167,12 +160,12 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
} }
else else
{ {
// Unsorted - determine the sorted order: // Determine the sorted order:
// avoid SortableList since we discard the main list anyhow // use sortedOrder directly (the intermediate list is discared anyhow)
List<label> faceMap; labelList faceMap;
sortedOrder(zoneIds, faceMap); sortedOrder(zoneIds, faceMap);
// generate sorted faces // Generate sorted faces
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
@ -186,7 +179,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
} }
zoneIds.clear(); zoneIds.clear();
// transfer: // Transfer:
this->storedFaces().transfer(faceLst); this->storedFaces().transfer(faceLst);
if (names.size()) if (names.size())
@ -218,11 +211,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
<< exit(FatalError); << exit(FatalError);
} }
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst) ? surfaceFormatsCore::oneZone(faceLst)
@ -232,24 +225,22 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1); const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) for (const surfZone& zone : zones)
{ {
// Print all faces belonging to this zone const label nLocalFaces = zone.size();
const surfZone& zone = zones[zoneI];
os << "solid " << zone.name() << nl; os << "solid " << zone.name() << nl;
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const label facei = faceMap[faceIndex++]; writeShell(os, pointLst, faceLst[faceMap[faceIndex++]]);
writeShell(os, pointLst, faceLst[facei]);
} }
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
writeShell(os, pointLst, faceLst[faceIndex++]); writeShell(os, pointLst, faceLst[faceIndex++]);
} }
@ -274,11 +265,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
<< exit(FatalError); << exit(FatalError);
} }
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().size() > 1 surf.surfZones().size() > 1
? surf.surfZones() ? surf.surfZones()
@ -292,36 +283,29 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
STLCore::writeBinaryHeader(os, nTris); STLCore::writeBinaryHeader(os, nTris);
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
writeShell const Face& f = faceLst[faceMap[faceIndex++]];
( writeShell(os, pointLst, f, zoneIndex);
os,
pointLst,
faceLst[faceMap[faceIndex++]],
zoneI
);
} }
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
writeShell const Face& f = faceLst[faceIndex++];
( writeShell(os, pointLst, f, zoneIndex);
os,
pointLst,
faceLst[faceIndex++],
zoneI
);
} }
} }
++zoneIndex;
} }
} }
@ -342,35 +326,35 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
} }
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
// a single zone - we can skip sorting // A single zone - we can skip sorting
if (surf.zoneToc().size() == 1) if (surf.zoneToc().size() == 1)
{ {
os << "solid " << surf.zoneToc()[0].name() << nl; os << "solid " << surf.zoneToc()[0].name() << nl;
forAll(faceLst, facei) for (const Face& f : faceLst)
{ {
writeShell(os, pointLst, faceLst[facei]); writeShell(os, pointLst, f);
} }
os << "endsolid " << surf.zoneToc()[0].name() << endl; os << "endsolid " << surf.zoneToc()[0].name() << nl;
} }
else else
{ {
labelList faceMap; labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap); List<surfZone> zoneLst = surf.sortedZones(faceMap);
writeAscii writeAscii
( (
filename, filename,
MeshedSurfaceProxy<Face> MeshedSurfaceProxy<Face>
( (
pointLst, pointLst,
faceLst, faceLst,
zoneLst, zoneLst,
faceMap faceMap
) )
); );
} }
} }
@ -389,15 +373,15 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
<< exit(FatalError); << exit(FatalError);
} }
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& zoneIds = surf.zoneIds(); const UList<label>& zoneIds = surf.zoneIds();
// Write the STL header // Write the STL header
unsigned int nTris = surf.nTriangles(); unsigned int nTris = surf.nTriangles();
STLCore::writeBinaryHeader(os, nTris); STLCore::writeBinaryHeader(os, nTris);
// always write unsorted // Always write unsorted
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
writeShell writeShell
@ -415,11 +399,21 @@ template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
) )
{ {
// Auto-detect ASCII/BINARY extension // Detect "stlb" extension
write(filename, surf, STLCore::UNKNOWN); bool useBinary = STLCore::isBinaryName(filename, STLCore::UNKNOWN);
if (useBinary)
{
writeBinary(filename, surf);
}
else
{
writeAscii(filename, surf);
}
} }
@ -428,7 +422,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf, const MeshedSurfaceProxy<Face>& surf,
const STLFormat& format const STLFormat format
) )
{ {
if (STLCore::isBinaryName(filename, format)) if (STLCore::isBinaryName(filename, format))
@ -446,11 +440,21 @@ template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
// Auto-detect ASCII/BINARY extension // Detect "stlb" extension
write(filename, surf, STLCore::UNKNOWN); bool useBinary = STLCore::isBinaryName(filename, STLCore::UNKNOWN);
if (useBinary)
{
writeBinary(filename, surf);
}
else
{
writeAscii(filename, surf);
}
} }
@ -459,7 +463,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf, const UnsortedMeshedSurface<Face>& surf,
const STLFormat& format const STLFormat format
) )
{ {
if (STLCore::isBinaryName(filename, format)) if (STLCore::isBinaryName(filename, format))

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,7 +53,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class STLsurfaceFormat Declaration Class fileFormats::STLsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -67,17 +67,17 @@ class STLsurfaceFormat
//- Write Face (ASCII) //- Write Face (ASCII)
static inline void writeShell static inline void writeShell
( (
Ostream&, Ostream& os,
const pointField&, const UList<point>& pts,
const Face& const Face& f
); );
//- Write Face (BINARY) //- Write Face (BINARY)
static inline void writeShell static inline void writeShell
( (
ostream&, ostream& os,
const pointField&, const UList<point>& pts,
const Face&, const Face& f,
const label zoneI const label zoneI
); );
@ -94,97 +94,94 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
STLsurfaceFormat(const fileName&); STLsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new STLsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~STLsurfaceFormat() virtual ~STLsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy (as ASCII) //- Write surface mesh components by proxy (as ASCII)
static void writeAscii static void writeAscii
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf
); );
//- Write surface mesh components by proxy (as BINARY) //- Write surface mesh components by proxy (as BINARY)
static void writeBinary static void writeBinary
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf
);
//- Write surface mesh components by proxy
// as ASCII or BINARY, depending on the extension
static void write
(
const fileName&,
const MeshedSurfaceProxy<Face>&
);
//- Write surface mesh components by proxy
// as ASCII or BINARY or dependent on the extension
static void write
(
const fileName&,
const MeshedSurfaceProxy<Face>&,
const STLFormat&
); );
//- Write UnsortedMeshedSurface (as ASCII) sorted by zone //- Write UnsortedMeshedSurface (as ASCII) sorted by zone
static void writeAscii static void writeAscii
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf
); );
//- Write UnsortedMeshedSurface (as BINARY) unsorted by zone //- Write UnsortedMeshedSurface (as BINARY) unsorted by zone
static void writeBinary static void writeBinary
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf
); );
//- Write UnsortedMeshedSurface //- Write surface mesh components by proxy
// as ASCII or BINARY, depending on the extension // as ASCII or BINARY or dependent on the extension
static void write static void write
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const MeshedSurfaceProxy<Face>& surf,
const STLFormat format
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// as ASCII or BINARY or dependent on the extension // as ASCII or BINARY or dependent on the extension
static void write static void write
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>&, const UnsortedMeshedSurface<Face>& surf,
const STLFormat& const STLFormat format
); );
//- Write surface mesh components by proxy
// as ASCII or BINARY, depending on the extension
static void write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
);
//- Write UnsortedMeshedSurface
// as ASCII or BINARY, depending on the extension
static void write
(
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
);
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / 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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -23,10 +23,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "STLCore.H" #include "STLCore.H"
#include "primitivePatch.H" #include "STLReader.H"
#include "Fstream.H"
#include "triSurface.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -42,13 +42,86 @@ struct triSurfaceSTLCore
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const bool Foam::triSurface::readSTL(const fileName& filename, bool forceBinary)
{ {
labelList faceMap; // Read in the values
fileFormats::STLReader reader
(
filename,
(
forceBinary
? fileFormats::STLCore::BINARY
: fileFormats::STLCore::UNKNOWN
)
);
// Get the map for stitched surface points, with merge tolerance depending
// on the input format
labelList pointMap;
const label nUniquePoints = reader.mergePointsMap(pointMap);
const auto& readpts = reader.points();
const labelList& zoneIds = reader.zoneIds();
pointField& pointLst = storedPoints();
List<Face>& faceLst = storedFaces();
// Sizing
pointLst.setSize(nUniquePoints);
faceLst.setSize(zoneIds.size());
// Assign points
forAll(readpts, pointi)
{
pointLst[pointMap[pointi]] = readpts[pointi];
}
// Assign triangles
label pointi = 0;
forAll(faceLst, i)
{
Face& f = faceLst[i];
f[0] = pointMap[pointi++];
f[1] = pointMap[pointi++];
f[2] = pointMap[pointi++];
f.region() = zoneIds[i];
}
// Set patch name/index.
if (reader.stlFormat() == fileFormats::STLCore::ASCII)
{
const List<word>& names = reader.names();
patches_.setSize(names.size());
forAll(patches_, patchi)
{
patches_[patchi] = geometricSurfacePatch(names[patchi], patchi);
}
}
return true;
}
void Foam::triSurface::writeSTLASCII
(
const fileName& filename,
const bool sort
) const
{
OFstream os(filename);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
labelList faceMap;
surfacePatchList patches(calcPatches(faceMap)); surfacePatchList patches(calcPatches(faceMap));
if (writeSorted) if (sort)
{ {
label faceIndex = 0; label faceIndex = 0;
forAll(patches, patchi) forAll(patches, patchi)
@ -62,7 +135,7 @@ void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const
( (
label patchFacei = 0; label patchFacei = 0;
patchFacei < patch.size(); patchFacei < patch.size();
patchFacei++ ++patchFacei
) )
{ {
const label facei = faceMap[faceIndex++]; const label facei = faceMap[faceIndex++];
@ -81,58 +154,60 @@ void Foam::triSurface::writeSTLASCII(const bool writeSorted, Ostream& os) const
os << "endsolid " << patch.name() << endl; os << "endsolid " << patch.name() << endl;
} }
return;
} }
else
// Get patch (=compact region) per face
labelList patchIDs(size());
forAll(patches, patchi)
{ {
// Get patch (=compact region) per face label facei = patches[patchi].start();
labelList patchIDs(size());
forAll(patches, patchi)
{
label facei = patches[patchi].start();
forAll(patches[patchi], i) forAll(patches[patchi], i)
{
patchIDs[faceMap[facei++]] = patchi;
}
}
label currentPatchi = -1;
forAll(*this, facei)
{
if (currentPatchi != patchIDs[facei])
{
if (currentPatchi != -1)
{ {
patchIDs[faceMap[facei++]] = patchi; // Close previous solid
os << "endsolid " << patches[currentPatchi].name() << nl;
} }
currentPatchi = patchIDs[facei];
os << "solid " << patches[currentPatchi].name() << nl;
} }
label currentPatchi = -1; const labelledTri& f = (*this)[facei];
forAll(*this, facei)
{
if (currentPatchi != patchIDs[facei])
{
if (currentPatchi != -1)
{
// Close previous solid
os << "endsolid " << patches[currentPatchi].name() << nl;
}
currentPatchi = patchIDs[facei];
os << "solid " << patches[currentPatchi].name() << nl;
}
const labelledTri& f = (*this)[facei]; // Write ASCII
STLtriangle::write
(
os,
faceNormals()[facei],
points()[f[0]],
points()[f[1]],
points()[f[2]]
);
}
// Write ASCII if (currentPatchi != -1)
STLtriangle::write {
( os << "endsolid " << patches[currentPatchi].name() << nl;
os,
faceNormals()[facei],
points()[f[0]],
points()[f[1]],
points()[f[2]]
);
}
if (currentPatchi != -1)
{
os << "endsolid " << patches[currentPatchi].name() << nl;
}
} }
} }
void Foam::triSurface::writeSTLBINARY(std::ostream& os) const void Foam::triSurface::writeSTLBINARY(const fileName& filename) const
{ {
std::ofstream os(filename, std::ios::binary);
// Write the STL header // Write the STL header
triSurfaceSTLCore::writeBinaryHeader(os, this->size()); triSurfaceSTLCore::writeBinaryHeader(os, this->size());

View File

@ -34,19 +34,21 @@ License
Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs"); Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment
( (
IFstream& is ISstream& is,
const char comment
) )
{ {
string line; Foam::string line;
do do
{ {
is.getLine(line); is.getLine(line);
} }
while ((line.empty() || line[0] == '#') && is.good()); while ((line.empty() || line[0] == comment) && is.good());
return line; return line;
} }
@ -168,23 +170,12 @@ bool Foam::fileFormats::surfaceFormatsCore::checkSupport
{ {
Info<<"Unknown file extension for " << functionName Info<<"Unknown file extension for " << functionName
<< " : " << ext << nl << " : " << ext << nl
<< "Valid types: " << flatOutput(available.sortedToc()) << endl; << "Valid types: " << flatOutput(available.sortedToc()) << nl
<< endl;
} }
return false; return false;
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore()
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -55,15 +55,19 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfaceFormatsCore Declaration Class fileFormats::surfaceFormatsCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class surfaceFormatsCore class surfaceFormatsCore
{ {
protected: protected:
//- Read non-empty and non-comment line
static string getLineNoComment(ISstream& is, const char comment='#');
//- Return a surfZone list with a single entry, the size of which //- Return a surfZone list with a single entry, the size of which
// corresponds to that of the container //- corresponds to that of the container
template<class Container> template<class Container>
static List<surfZone> oneZone static List<surfZone> oneZone
( (
@ -74,10 +78,6 @@ protected:
return List<surfZone>(1, surfZone(name, container.size(), 0, 0)); return List<surfZone>(1, surfZone(name, container.size(), 0, 0));
} }
//- Read non-comment line
static string getLineNoComment(IFstream&);
public: public:
// Static Data // Static Data
@ -125,11 +125,11 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
surfaceFormatsCore(); surfaceFormatsCore() = default;
//- Destructor //- Destructor
virtual ~surfaceFormatsCore(); virtual ~surfaceFormatsCore() = default;
}; };

View File

@ -23,41 +23,36 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "TRIsurfaceFormat.H" #include "TRIReader.H"
#include "surfaceFormatsCore.H"
#include "IFstream.H" #include "IFstream.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "StringStream.H" #include "StringStream.H"
#include "mergePoints.H" #include "mergePoints.H"
#include "Map.H" #include "Map.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
Foam::fileFormats::TRIsurfaceFormatCore::TRIsurfaceFormatCore static Foam::string getLineNoComment
( (
const fileName& filename Foam::ISstream& is,
const char comment='#'
) )
:
sorted_(true),
points_(0),
zoneIds_(0),
sizes_(0)
{ {
read(filename); Foam::string line;
do
{
is.getLine(line);
}
while ((line.empty() || line[0] == comment) && is.good());
return line;
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::fileFormats::TRIsurfaceFormatCore::~TRIsurfaceFormatCore() bool Foam::fileFormats::TRIReader::readFile(const fileName& filename)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::TRIsurfaceFormatCore::read
(
const fileName& filename
)
{ {
this->clear(); this->clear();
sorted_ = true; sorted_ = true;
@ -74,6 +69,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
// the rest of the reader resembles the STL binary reader // the rest of the reader resembles the STL binary reader
DynamicList<STLpoint> dynPoints; DynamicList<STLpoint> dynPoints;
DynamicList<label> dynZones; DynamicList<label> dynZones;
DynamicList<word> dynNames;
DynamicList<label> dynSizes; DynamicList<label> dynSizes;
HashTable<label> lookup; HashTable<label> lookup;
@ -84,13 +80,14 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
while (is.good()) while (is.good())
{ {
string line = this->getLineNoComment(is); string line = getLineNoComment(is);
// Handle continuations? if (line.empty())
// if (line.removeEnd("\\")) {
// { break;
// line += this->getLineNoComment(is); }
// }
// Do not handle continuations
IStringStream lineStream(line); IStringStream lineStream(line);
@ -133,21 +130,23 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
const word rawName(lineStream); const word rawName(lineStream);
const word name("zone" + rawName.substr(1)); const word name("zone" + rawName.substr(1));
HashTable<label>::const_iterator fnd = lookup.cfind(name); const auto iter = lookup.cfind(name);
if (fnd.found()) if (iter.found())
{ {
if (zoneI != fnd()) if (zoneI != iter.object())
{ {
// group appeared out of order sorted_ = false; // Group appeared out of order
sorted_ = false; zoneI = iter.object();
} }
zoneI = fnd();
} }
else else
{ {
zoneI = dynSizes.size(); zoneI = dynSizes.size();
lookup.insert(name, zoneI); if (lookup.insert(name, zoneI))
dynSizes.append(0); {
dynNames.append(name);
dynSizes.append(0);
}
} }
dynZones.append(zoneI); dynZones.append(zoneI);
@ -156,44 +155,68 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
// skip empty groups // skip empty groups
label nZone = 0; label nZone = 0;
forAll(dynSizes, zoneI) forAll(dynSizes, zonei)
{ {
if (dynSizes[zoneI]) if (dynSizes[zonei])
{ {
if (nZone != zoneI) if (nZone != zonei)
{ {
dynSizes[nZone] = dynSizes[zoneI]; dynNames[nZone] = dynNames[zonei];
dynSizes[nZone] = dynSizes[zonei];
} }
nZone++; ++nZone;
} }
} }
// truncate addressed size // truncate addressed size
dynNames.setCapacity(nZone);
dynSizes.setCapacity(nZone); dynSizes.setCapacity(nZone);
// transfer to normal lists // transfer to normal lists
points_.transfer(dynPoints); points_.transfer(dynPoints);
zoneIds_.transfer(dynZones); zoneIds_.transfer(dynZones);
names_.transfer(dynNames);
sizes_.transfer(dynSizes); sizes_.transfer(dynSizes);
return true; return true;
} }
void Foam::fileFormats::TRIsurfaceFormatCore::clear() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::TRIReader::TRIReader
(
const fileName& filename
)
:
sorted_(true),
points_(),
zoneIds_(),
names_(),
sizes_()
{
readFile(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::TRIReader::clear()
{ {
sorted_ = true; sorted_ = true;
points_.clear(); points_.clear();
zoneIds_.clear(); zoneIds_.clear();
names_.clear();
sizes_.clear(); sizes_.clear();
} }
Foam::label Foam::fileFormats::TRIsurfaceFormatCore::mergePointsMap Foam::label Foam::fileFormats::TRIReader::mergePointsMap
( (
labelList& pointMap labelList& pointMap
) const ) const
{ {
// Use merge tolerance as per STL ascii // Use merge tolerance as per STL ASCII
return mergePointsMap return mergePointsMap
( (
100 * doubleScalarSMALL, 100 * doubleScalarSMALL,
@ -202,7 +225,7 @@ Foam::label Foam::fileFormats::TRIsurfaceFormatCore::mergePointsMap
} }
Foam::label Foam::fileFormats::TRIsurfaceFormatCore::mergePointsMap Foam::label Foam::fileFormats::TRIReader::mergePointsMap
( (
const scalar mergeTol, const scalar mergeTol,
labelList& pointMap labelList& pointMap

View File

@ -22,21 +22,27 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::fileFormats::TRIsurfaceFormatCore Foam::fileFormats::TRIReader
Description Description
Internal class used by the TRIsurfaceFormat TRI (triangle) file reader.
For TRI format (eg, AC3D).
Each input line has 9 floats (3 points, each 3 floats) followed by hex
colour. The colour is used to build regions numbered from 0 upwards.
Reading and stitching similar to the STLReader.
SourceFiles SourceFiles
TRIsurfaceFormatCore.C TRIReader.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef TRIsurfaceFormatCore_H #ifndef TRIReader_H
#define TRIsurfaceFormatCore_H #define TRIReader_H
#include "surfaceFormatsCore.H"
#include "STLpoint.H" #include "STLpoint.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,12 +52,10 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class TRIsurfaceFormatCore Declaration Class fileFormats::TRIReader Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class TRIsurfaceFormatCore class TRIReader
:
public surfaceFormatsCore
{ {
// Private Data // Private Data
@ -63,19 +67,22 @@ class TRIsurfaceFormatCore
//- The zones associated with the faces //- The zones associated with the faces
List<label> zoneIds_; List<label> zoneIds_;
//- The zone names, in the order of their first appearance
List<word> names_;
//- The solid count, in the order of their first appearance //- The solid count, in the order of their first appearance
List<label> sizes_; List<label> sizes_;
// Private Member Functions // Private Member Functions
bool readFile(const fileName& filename);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
TRIsurfaceFormatCore(const TRIsurfaceFormatCore&) = delete; TRIReader(const TRIReader&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const TRIsurfaceFormatCore&) = delete; TRIReader& operator=(const TRIReader&) = delete;
bool read(const fileName&);
public: public:
@ -83,11 +90,11 @@ public:
// Constructors // Constructors
//- Read from file, filling in the information //- Read from file, filling in the information
TRIsurfaceFormatCore(const fileName& filename); TRIReader(const fileName& filename);
//- Destructor //- Destructor
~TRIsurfaceFormatCore(); ~TRIReader() = default;
// Member Functions // Member Functions
@ -123,6 +130,12 @@ public:
return zoneIds_; return zoneIds_;
} }
//- The list of solid names in the order of their first appearance
inline List<word>& names()
{
return names_;
}
//- The list of zone sizes in the order of their first appearance //- The list of zone sizes in the order of their first appearance
inline List<label>& sizes() inline List<label>& sizes()
{ {

View File

@ -24,7 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "TRIsurfaceFormat.H" #include "TRIsurfaceFormat.H"
#include "TRIReader.H"
#include "OFstream.H" #include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -32,20 +34,20 @@ template<class Face>
inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const UList<point>& pts,
const Face& f, const Face& f,
const label zoneI const label zoneI
) )
{ {
// simple triangulation about f[0]. // simple triangulation about f[0].
// better triangulation should have been done before // better triangulation should have been done before
const point& p0 = pointLst[f[0]]; const point& p0 = pts[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{ {
label fp2 = f.fcIndex(fp1); const label fp2 = f.fcIndex(fp1);
const point& p1 = pointLst[f[fp1]]; const point& p1 = pts[f[fp1]];
const point& p2 = pointLst[f[fp2]]; const point& p2 = pts[f[fp2]];
os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' ' os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' '
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' '
@ -79,7 +81,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
this->clear(); this->clear();
// Read in the values // Read in the values
TRIsurfaceFormatCore reader(filename); TRIReader reader(filename);
// Get the map for stitched surface points // Get the map for stitched surface points
labelList pointMap; labelList pointMap;
@ -99,7 +101,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
List<label> sizes(reader.sizes().xfer()); List<label> sizes(reader.sizes().xfer());
List<label> zoneIds(reader.zoneIds().xfer()); List<label> zoneIds(reader.zoneIds().xfer());
// generate the (sorted) faces // Generate the (sorted) faces
List<Face> faceLst(zoneIds.size()); List<Face> faceLst(zoneIds.size());
if (reader.sorted()) if (reader.sorted())
@ -118,12 +120,12 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
} }
else else
{ {
// Unsorted - determine the sorted order: // Determine the sorted order:
// avoid SortableList since we discard the main list anyhow // use sortedOrder directly (the intermediate list is discared anyhow)
List<label> faceMap; labelList faceMap;
sortedOrder(zoneIds, faceMap); sortedOrder(zoneIds, faceMap);
// generate sorted faces // Generate sorted faces
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
@ -137,7 +139,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
} }
zoneIds.clear(); zoneIds.clear();
// transfer: // Transfer:
this->storedFaces().transfer(faceLst); this->storedFaces().transfer(faceLst);
this->addZones(sizes); this->addZones(sizes);
@ -151,14 +153,15 @@ template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write void Foam::fileFormats::TRIsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst) ? surfaceFormatsCore::oneZone(faceLst)
@ -176,26 +179,29 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
} }
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, pointLst, f, zoneI); writeShell(os, pointLst, f, zoneIndex);
} }
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
writeShell(os, pointLst, f, zoneI); writeShell(os, pointLst, f, zoneIndex);
} }
} }
++zoneIndex;
} }
} }
@ -204,11 +210,12 @@ template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write void Foam::fileFormats::TRIsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
@ -218,11 +225,10 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
<< exit(FatalError); << exit(FatalError);
} }
// A single zone needs no sorting
// a single zone needs no sorting
if (surf.zoneToc().size() == 1) if (surf.zoneToc().size() == 1)
{ {
const List<label>& zoneIds = surf.zoneIds(); const UList<label>& zoneIds = surf.zoneIds();
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
@ -235,13 +241,18 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
List<surfZone> zoneLst = surf.sortedZones(faceMap); List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0; label faceIndex = 0;
forAll(zoneLst, zoneI) label zoneIndex = 0;
for (const surfZone& zone : zoneLst)
{ {
forAll(zoneLst[zoneI], localFacei) const label nLocalFaces = zone.size();
for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, pointLst, f, zoneI); writeShell(os, pointLst, f, zoneIndex);
} }
++zoneIndex;
} }
} }
} }

View File

@ -39,7 +39,6 @@ SourceFiles
#ifndef TRIsurfaceFormat_H #ifndef TRIsurfaceFormat_H
#define TRIsurfaceFormat_H #define TRIsurfaceFormat_H
#include "TRIsurfaceFormatCore.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H" #include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
@ -52,7 +51,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class TRIsurfaceFormat Declaration Class fileFormats::TRIsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -64,9 +63,9 @@ class TRIsurfaceFormat
static inline void writeShell static inline void writeShell
( (
Ostream&, Ostream& os,
const pointField&, const UList<point>& pts,
const Face&, const Face& f,
const label zoneI const label zoneI
); );
@ -82,50 +81,46 @@ public:
// Constructors // Constructors
//- Construct from file name //- Construct from file name
TRIsurfaceFormat(const fileName&); TRIsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new TRIsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~TRIsurfaceFormat() virtual ~TRIsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, //- Write UnsortedMeshedSurface,
// by default the output is not sorted by zones // by default the output is not sorted by zones
static void write static void write
( (
const fileName&, const fileName& filename,
const UnsortedMeshedSurface<Face>& const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName& filename);
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -53,7 +53,7 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::writePolys
{ {
// connectivity count without additional storage (done internally) // connectivity count without additional storage (done internally)
label nConnectivity = 0; label nConnectivity = 0;
for (const auto& f : faces) for (const Face& f : faces)
{ {
nConnectivity += f.size(); nConnectivity += f.size();
} }
@ -109,7 +109,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
<< exit(FatalError); << exit(FatalError);
} }
// assume that the groups are not intermixed // Assume groups are not intermixed
bool sorted = true; bool sorted = true;
@ -187,9 +187,9 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
label nTri = 0; label nTri = 0;
if (faceTraits<Face>::isTri()) if (faceTraits<Face>::isTri())
{ {
forAll(faces, facei) for (const face& f : faces)
{ {
nTri += faces[facei].nTriangles(); nTri += f.nTriangles();
} }
} }
@ -214,9 +214,9 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
// Count // Count
labelList zoneSizes(nZones, 0); labelList zoneSizes(nZones, 0);
forAll(dynZones, triI) for (const label zonei : dynZones)
{ {
zoneSizes[dynZones[triI]]++; zoneSizes[zonei]++;
} }
this->sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted); this->sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
@ -227,17 +227,16 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
else else
{ {
DynamicList<Face> dynFaces(faces.size()); DynamicList<Face> dynFaces(faces.size());
forAll(faces, facei) for (const face& f : faces)
{ {
const face& f = faces[facei];
dynFaces.append(Face(f)); dynFaces.append(Face(f));
} }
// Count // Count
labelList zoneSizes(nZones, 0); labelList zoneSizes(nZones, 0);
forAll(zones, facei) for (const label zonei : zones)
{ {
zoneSizes[zones[facei]]++; zoneSizes[zonei]++;
} }
this->sortFacesAndStore(dynFaces.xfer(), zones.xfer(), sorted); this->sortFacesAndStore(dynFaces.xfer(), zones.xfer(), sorted);
@ -258,14 +257,15 @@ template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write void Foam::fileFormats::VTKsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst) ? surfaceFormatsCore::oneZone(faceLst)
@ -285,7 +285,7 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
{ {
// connectivity count without additional storage (done internally) // connectivity count without additional storage (done internally)
label nConnectivity = 0; label nConnectivity = 0;
for (const auto& f : faceLst) for (const Face& f : faceLst)
{ {
nConnectivity += f.size(); nConnectivity += f.size();
} }
@ -329,7 +329,8 @@ template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write void Foam::fileFormats::VTKsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
std::ofstream os(filename); std::ofstream os(filename);

View File

@ -25,7 +25,8 @@ Class
Foam::fileFormats::VTKsurfaceFormat Foam::fileFormats::VTKsurfaceFormat
Description Description
Provide a means of reading/writing VTK legacy format. Read/write VTK legacy format (ASCII) for surfaces.
The output is never sorted by zone. The output is never sorted by zone.
SourceFiles SourceFiles
@ -49,7 +50,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class VTKsurfaceFormat Declaration Class fileFormats::VTKsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -83,48 +84,42 @@ public:
VTKsurfaceFormat(const fileName& filename); VTKsurfaceFormat(const fileName& filename);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face>> New(const fileName& name)
{
return autoPtr<MeshedSurface<Face>>
(
new VTKsurfaceFormat<Face>(name)
);
}
//- Destructor //- Destructor
virtual ~VTKsurfaceFormat() virtual ~VTKsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
// Write
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, the output remains unsorted //- Write UnsortedMeshedSurface, the output remains unsorted
static void write static void write
( (
const fileName& fileName, const fileName& fileName,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Read from file //- Read from file
virtual bool read(const fileName& filename); virtual bool read(const fileName& filename);
//- Write object file //- Write object file
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -32,7 +32,7 @@ License
void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader
( (
vtk::formatter& format, vtk::formatter& format,
const pointField& pts const UList<point>& pts
) )
{ {
vtk::legacy::fileHeader vtk::legacy::fileHeader

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / 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) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,8 +35,9 @@ SourceFiles
#ifndef VTKsurfaceFormatCore_H #ifndef VTKsurfaceFormatCore_H
#define VTKsurfaceFormatCore_H #define VTKsurfaceFormatCore_H
#include "MeshedSurface.H"
#include "foamVtkFormatter.H" #include "foamVtkFormatter.H"
#include "point.H"
#include "surfZone.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,20 +47,20 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class VTKsurfaceFormatCore Declaration Class fileFormats::VTKsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class VTKsurfaceFormatCore class VTKsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Static Member Functions
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
vtk::formatter& format, vtk::formatter& format,
const pointField& pts const UList<point>& pts
); );
//- Write regions (zones) information as CellData //- Write regions (zones) information as CellData

View File

@ -66,7 +66,7 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::writePolys
format.writeSize(payLoad * sizeof(label)); format.writeSize(payLoad * sizeof(label));
for (const Face& f : faces) for (const auto& f : faces)
{ {
vtk::writeList(format, f); vtk::writeList(format, f);
} }
@ -104,25 +104,19 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::writePolys
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::VTPsurfaceFormat<Face>::VTPsurfaceFormat()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face> template<class Face>
void Foam::fileFormats::VTPsurfaceFormat<Face>::write void Foam::fileFormats::VTPsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
const List<surfZone>& zones = const List<surfZone>& zones =
( (
@ -226,7 +220,8 @@ template<class Face>
void Foam::fileFormats::VTPsurfaceFormat<Face>::write void Foam::fileFormats::VTPsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options
) )
{ {
std::ofstream os(filename, std::ios::binary); std::ofstream os(filename, std::ios::binary);
@ -234,7 +229,7 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::write
autoPtr<vtk::formatter> format = autoPtr<vtk::formatter> format =
vtk::newFormatter(os, fmtType); vtk::newFormatter(os, fmtType);
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
writeHeader(format(), surf.points(), faceLst.size()); writeHeader(format(), surf.points(), faceLst.size());

View File

@ -25,7 +25,8 @@ Class
Foam::fileFormats::VTPsurfaceFormat Foam::fileFormats::VTPsurfaceFormat
Description Description
Provide a means of writing VTP (xml) format. Write surfaces in VTP (xml) format.
The output is never sorted by zone. The output is never sorted by zone.
SourceFiles SourceFiles
@ -49,7 +50,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class VTPsurfaceFormat Declaration Class fileFormats::VTPsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -80,36 +81,42 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
VTPsurfaceFormat(); VTPsurfaceFormat() = default;
//- Destructor //- Destructor
virtual ~VTPsurfaceFormat() virtual ~VTPsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
// Write
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
//- Write UnsortedMeshedSurface, the output remains unsorted //- Write UnsortedMeshedSurface, the output remains unsorted
static void write static void write
( (
const fileName& filename, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Write object file //- Write object file
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -32,7 +32,7 @@ License
void Foam::fileFormats::VTPsurfaceFormatCore::writeHeader void Foam::fileFormats::VTPsurfaceFormatCore::writeHeader
( (
vtk::formatter& format, vtk::formatter& format,
const pointField& pts, const UList<point>& pts,
const label nFaces const label nFaces
) )
{ {
@ -142,7 +142,6 @@ void Foam::fileFormats::VTPsurfaceFormatCore::writeCellData
format.endDataArray(); format.endDataArray();
format.endTag(vtk::fileTag::CELL_DATA); format.endTag(vtk::fileTag::CELL_DATA);
} }

View File

@ -35,8 +35,9 @@ SourceFiles
#ifndef VTPsurfaceFormatCore_H #ifndef VTPsurfaceFormatCore_H
#define VTPsurfaceFormatCore_H #define VTPsurfaceFormatCore_H
#include "MeshedSurface.H"
#include "foamVtkFormatter.H" #include "foamVtkFormatter.H"
#include "point.H"
#include "surfZone.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,27 +47,26 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class VTPsurfaceFormatCore Declaration Class fileFormats::VTPsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class VTPsurfaceFormatCore class VTPsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Static Member Functions
//- Write file header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
vtk::formatter& format, vtk::formatter& format,
const pointField& pts, const UList<point>& pts,
const label nFaces const label nFaces
); );
//- Write file footer //- Write footer
static void writeFooter(vtk::formatter& format); static void writeFooter(vtk::formatter& format);
//- Write regions (zones) information as CellData //- Write regions (zones) information as CellData
static void writeCellData static void writeCellData
( (

View File

@ -26,28 +26,22 @@ License
#include "X3DsurfaceFormat.H" #include "X3DsurfaceFormat.H"
#include "OFstream.H" #include "OFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::X3DsurfaceFormat<Face>::X3DsurfaceFormat()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face> template<class Face>
void Foam::fileFormats::X3DsurfaceFormat<Face>::write void Foam::fileFormats::X3DsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurfaceProxy<Face>& surf const MeshedSurfaceProxy<Face>& surf,
const dictionary&
) )
{ {
const pointField& pointLst = surf.points(); const UList<point>& pointLst = surf.points();
const List<Face>& faceLst = surf.surfFaces(); const UList<Face>& faceLst = surf.surfFaces();
const List<label>& faceMap = surf.faceMap(); const UList<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name // for no zones, suppress the group name
const List<surfZone>& zones = const UList<surfZone>& zones =
( (
surf.surfZones().empty() surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst, word::null) ? surfaceFormatsCore::oneZone(faceLst, word::null)
@ -80,13 +74,13 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
" <IndexedFaceSet coordIndex='\n"; " <IndexedFaceSet coordIndex='\n";
label faceIndex = 0; label faceIndex = 0;
forAll(zones, zoneI) for (const surfZone& zone : zones)
{ {
const surfZone& zone = zones[zoneI]; const label nLocalFaces = zone.size();
if (useFaceMap) if (useFaceMap)
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
@ -99,7 +93,7 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
} }
else else
{ {
forAll(zone, localFacei) for (label i=0; i<nLocalFaces; ++i)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
@ -116,11 +110,8 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
"' >\n" "' >\n"
" <Coordinate point='\n"; " <Coordinate point='\n";
// Write vertex coords for (const point& pt : pointLst)
forAll(pointLst, ptI)
{ {
const point& pt = pointLst[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
@ -130,7 +121,6 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
" </Shape>\n" " </Shape>\n"
" </Group>\n" " </Group>\n"
"</X3D>\n"; "</X3D>\n";
} }

View File

@ -48,7 +48,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class X3DsurfaceFormat Declaration Class fileFormats::X3DsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -70,28 +70,34 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
X3DsurfaceFormat(); X3DsurfaceFormat() = default;
//- Destructor //- Destructor
virtual ~X3DsurfaceFormat() virtual ~X3DsurfaceFormat() = default;
{}
// Member Functions // Static Member Functions
//- Write surface mesh components by proxy //- Write surface mesh components by proxy
static void write static void write
( (
const fileName&, const fileName& filename,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy<Face>& surf,
const dictionary& options = dictionary::null
); );
// Member Functions
//- Write object //- Write object
virtual void write(const fileName& name) const virtual void write
(
const fileName& name,
const dictionary& options = dictionary::null
) const
{ {
write(name, MeshedSurfaceProxy<Face>(*this)); write(name, MeshedSurfaceProxy<Face>(*this), options);
} }
}; };

View File

@ -35,7 +35,6 @@ SourceFiles
#ifndef X3DsurfaceFormatCore_H #ifndef X3DsurfaceFormatCore_H
#define X3DsurfaceFormatCore_H #define X3DsurfaceFormatCore_H
#include "MeshedSurface.H"
#include "Ostream.H" #include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,7 +45,7 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class X3DsurfaceFormatCore Declaration Class fileFormats::X3DsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class X3DsurfaceFormatCore class X3DsurfaceFormatCore
@ -55,10 +54,10 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Write file header //- Write file header
static void writeHeader(Ostream&); static void writeHeader(Ostream& os);
//- Write appearance node //- Write appearance node
static void writeAppearance(Ostream&); static void writeAppearance(Ostream& os);
}; };

View File

@ -30,11 +30,11 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(surfaceRegistry, 0); defineTypeNameAndDebug(surfaceRegistry, 0);
} }
const Foam::word Foam::surfaceRegistry::prefix("surfaces"); const Foam::word Foam::surfaceRegistry::prefix("surfaces");
Foam::word Foam::surfaceRegistry::defaultName("default"); Foam::word Foam::surfaceRegistry::defaultName("default");
@ -61,10 +61,4 @@ Foam::surfaceRegistry::surfaceRegistry
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::surfaceRegistry::~surfaceRegistry()
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -57,7 +57,7 @@ class surfaceRegistry
surfaceRegistry(const surfaceRegistry&) = delete; surfaceRegistry(const surfaceRegistry&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const surfaceRegistry&) = delete; surfaceRegistry& operator=(const surfaceRegistry&) = delete;
public: public:
@ -77,13 +77,14 @@ public:
//- Construct for the given objectRegistry and named surface //- Construct for the given objectRegistry and named surface
surfaceRegistry surfaceRegistry
( (
const objectRegistry&, const objectRegistry& obr,
const word& surfName = word::null const word& surfName = word::null
); );
//- Destructor //- Destructor
virtual ~surfaceRegistry(); virtual ~surfaceRegistry() = default;
}; };

View File

@ -1,349 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Reader for .ac files generated by AC3D.
See http://www.ac3d.org/ac3d/man/ac3dfileformat.html
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "IFstream.H"
#include "StringStream.H"
#include "transform.H"
#include "tensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
static label parseInt(const string& str)
{
IStringStream intStream(str);
label a;
intStream >> a;
return a;
}
static bool readCmd(IFstream& ACfile, string& cmd, string& args)
{
if (ACfile.good())
{
string line;
ACfile.getLine(line);
string::size_type space = line.find(' ');
if (space != string::npos)
{
cmd = line.substr(0, space);
args = line.substr(space+1);
return true;
}
}
return false;
}
// Read up to line starting with cmd. Sets args to rest of line.
// Returns true if found, false if stream is not good anymore.
static bool readUpto
(
const string& cmd,
IFstream& ACfile,
string& args
)
{
while (ACfile.good())
{
string line;
ACfile.getLine(line);
string::size_type space = line.find(' ');
if (space != string::npos && line.substr(0, space) == cmd)
{
args = line.substr(space+1);
return true;
}
}
return false;
}
// Likewise but throws error if cmd not found
static void readUpto
(
const string& cmd,
IFstream& ACfile,
string& args,
const string errorMsg
)
{
if (!readUpto(cmd, ACfile, args))
{
FatalErrorInFunction
<< "Cannot find command " << cmd
<< errorMsg << exit(FatalError);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool triSurface::readAC(const fileName& ACfileName)
{
IFstream ACfile(ACfileName);
if (!ACfile.good())
{
FatalErrorInFunction
<< "Cannot read file " << ACfileName
<< exit(FatalError);
}
string line;
ACfile.getLine(line);
string version = line.substr(4);
if (version != "b")
{
WarningInFunction
<< "When reading AC3D file " << ACfileName
<< " read header " << line << " with version " << version
<< endl << "Only tested reading with version 'b'."
<< " This might give problems" << endl;
}
string cmd;
string args;
if (!readUpto("OBJECT", ACfile, args) || (args != "world"))
{
FatalErrorInFunction
<< "Cannot find \"OBJECT world\" in file " << ACfileName
<< exit(FatalError);
}
// Number of kids = patches
readUpto("kids", ACfile, args, "");
label nPatches = parseInt(args);
// Storage for patches and unmerged points and faces
DynamicList<point> points;
DynamicList<labelledTri> faces;
geometricSurfacePatchList patches(nPatches);
// Start of vertices for object/patch
label patchStartVert = 0;
for (label patchi = 0; patchi < nPatches; patchi++)
{
readUpto
(
"OBJECT",
ACfile,
args,
" while reading patch " + Foam::name(patchi)
);
// Object global values
string patchName = string("patch") + Foam::name(patchi);
label nVerts = 0;
tensor rot(I);
vector loc(0, 0, 0);
// Read all info for current patch
while (ACfile.good())
{
// Read line and get first word. If end of file break since
// patch should always end with 'kids' command ?not sure.
if (!readCmd(ACfile, cmd, args))
{
FatalErrorInFunction
<< "Did not read up to \"kids 0\" while reading patch "
<< patchi << " from file " << ACfileName
<< exit(FatalError);
}
if (cmd == "name")
{
IStringStream nameStream(args);
nameStream >> patchName;
}
else if (cmd == "rot")
{
// rot %f %f %f %f %f %f %f %f %f
IStringStream lineStream(args);
lineStream
>> rot.xx() >> rot.xy() >> rot.xz()
>> rot.yx() >> rot.yy() >> rot.yz()
>> rot.zx() >> rot.zy() >> rot.zz();
WarningInFunction
<< "rot (rotation tensor) command not implemented"
<< "Line:" << cmd << ' ' << args << endl
<< "while reading patch " << patchi << endl;
}
else if (cmd == "loc")
{
IStringStream lineStream(args);
lineStream >> loc.x() >> loc.y() >> loc.z();
}
else if (cmd == "numvert")
{
nVerts = parseInt(args);
for (label vertI = 0; vertI < nVerts; vertI++)
{
ACfile.getLine(line);
IStringStream lineStream(line);
point pt;
lineStream >> pt.x() >> pt.y() >> pt.z();
// Offset with current translation vector
points.append(pt+loc);
}
}
else if (cmd == "numsurf")
{
label nTris = parseInt(args);
for (label triI = 0; triI < nTris; triI++)
{
static string errorMsg =
string(" while reading face ")
+ name(triI) + " on patch " + name(patchi)
+ " from file " + ACfileName;
readUpto("SURF", ACfile, args, errorMsg);
readUpto("mat", ACfile, args, errorMsg);
readUpto("refs", ACfile, args, errorMsg);
label size = parseInt(args);
if (size != 3)
{
FatalErrorInFunction
<< "Can only read surfaces with 3 vertices."
<< endl
<< "Detected " << size << " when reading triangle "
<< triI << " of patch " << patchi
<< exit(FatalError);
}
ACfile.getLine(line);
label v0 = parseInt(line);
ACfile.getLine(line);
label v1 = parseInt(line);
ACfile.getLine(line);
label v2 = parseInt(line);
faces.append
(
labelledTri
(
v0 + patchStartVert,
v1 + patchStartVert,
v2 + patchStartVert,
patchi
)
);
}
// Done the current patch. Increment the offset vertices are
// stored at
patchStartVert += nVerts;
}
else if (cmd == "kids")
{
// 'kids' denotes the end of the current patch.
label nKids = parseInt(args);
if (nKids != 0)
{
FatalErrorInFunction
<< "Can only read objects without kids."
<< " Encountered " << nKids << " kids when"
<< " reading patch " << patchi
<< exit(FatalError);
}
patches[patchi] =
geometricSurfacePatch
(
word(patchName),
patchi
);
// Stop reading current patch
break;
}
}
}
faces.shrink();
// Transfer DynamicLists to straight ones.
pointField allPoints(points.xfer());
*this = triSurface(faces, patches, allPoints, true);
stitchTriangles();
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,139 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "IOmanip.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::triSurface::writeAC(Ostream& os) const
{
// Write with patches as separate objects under "world" object.
// Header is taken over from sample file.
// Defines separate materials for all patches. Recycle colours.
// Define 8 standard colours as r,g,b components
static scalar colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// Calculate patch face indexing
labelList faceMap;
surfacePatchList patches(calcPatches(faceMap));
// Write header. Define materials.
os << "AC3Db" << endl;
forAll(patches, patchi)
{
const word& pName = patches[patchi].name();
label colourI = patchi % 8;
label colourCompI = 3 * colourI;
os << "MATERIAL \"" << pName << "Mat\" rgb "
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
<< ' ' << colourMap[colourCompI+2]
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
<< " trans 0"
<< endl;
}
os << "OBJECT world" << endl
<< "kids " << patches.size() << endl;
// Write patch points & faces.
label faceIndex = 0;
forAll(patches, patchi)
{
const surfacePatch& sp = patches[patchi];
os << "OBJECT poly" << endl
<< "name \"" << sp.name() << '"' << endl;
// Create patch with only patch faces included for ease of addressing
boolList include(size(), false);
forAll(sp, patchFacei)
{
const label facei = faceMap[faceIndex++];
include[facei] = true;
}
labelList pointMap;
labelList faceMap;
triSurface patch = subsetMesh(include, pointMap, faceMap);
// Now we have triSurface for this patch alone. Write it.
os << "numvert " << patch.nPoints() << endl;
forAll(patch.localPoints(), ptI)
{
const point& pt = patch.localPoints()[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
}
os << "numsurf " << patch.localFaces().size() << endl;
forAll(patch.localFaces(), facei)
{
const labelledTri& f = patch.localFaces()[facei];
os << "SURF 0x20" << endl // polygon
<< "mat " << patchi << endl
<< "refs " << f.size() << endl;
os << f[0] << " 0 0" << endl;
os << f[1] << " 0 0" << endl;
os << f[2] << " 0 0" << endl;
}
os << "kids 0" << endl;
}
}
// ************************************************************************* //

View File

@ -1,161 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "IFstream.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::triSurface::readGTS(const fileName& GTSfileName)
{
IFstream GTSfile(GTSfileName);
if (!GTSfile.good())
{
FatalErrorInFunction
<< "Cannot read file " << GTSfileName
<< exit(FatalError);
}
// Read header
label nPoints, nEdges, nElems;
string line = getLineNoComment(GTSfile);
{
IStringStream lineStream(line);
lineStream >> nPoints >> nEdges >> nElems;
}
// Read points
pointField& points_ = const_cast<pointField&>(points());
points_.setSize(nPoints);
forAll(points_, pointi)
{
scalar x, y, z;
line = getLineNoComment(GTSfile);
{
IStringStream lineStream(line);
lineStream >> x >> y >> z;
}
points_[pointi] = point(x, y, z);
}
// Read edges (Foam indexing)
edgeList edges(nEdges);
forAll(edges, edgei)
{
label start, end;
line = getLineNoComment(GTSfile);
{
IStringStream lineStream(line);
lineStream >> start >> end;
}
edges[edgei] = edge(start - 1, end - 1);
}
// Read triangles. Convert references to edges into pointlabels
setSize(nElems);
forAll(*this, trianglei)
{
label e0Label, e1Label, e2Label;
label region = 0;
line = getLineNoComment(GTSfile);
{
IStringStream lineStream(line);
lineStream >> e0Label >> e1Label >> e2Label;
// Optional region number: read first, then check state on stream
if (lineStream)
{
label num;
lineStream >> num;
if (!lineStream.bad())
{
region = num;
}
}
}
// Determine ordering of edges e0, e1
// common:common vertex, shared by e0 and e1
// e0Far:vertex on e0 which is not common
// e1Far: ,, e1 ,,
const edge& e0 = edges[e0Label - 1];
const edge& e1 = edges[e1Label - 1];
const edge& e2 = edges[e2Label - 1];
label common01 = e0.commonVertex(e1);
if (common01 == -1)
{
FatalErrorInFunction
<< "Edges 0 and 1 of triangle " << trianglei
<< " do not share a point.\n"
<< " edge0:" << e0 << endl
<< " edge1:" << e1
<< exit(FatalError);
}
label e0Far = e0.otherVertex(common01);
label e1Far = e1.otherVertex(common01);
label common12 = e1.commonVertex(e2);
if (common12 == -1)
{
FatalErrorInFunction
<< "Edges 1 and 2 of triangle " << trianglei
<< " do not share a point.\n"
<< " edge1:" << e1 << endl
<< " edge2:" << e2
<< exit(FatalError);
}
label e2Far = e2.otherVertex(common12);
// Does edge2 sit between edge1 and 0?
if ((common12 != e1Far) || (e2Far != e0Far))
{
FatalErrorInFunction
<< "Edges of triangle " << trianglei
<< " reference more than three points.\n"
<< " edge0:" << e0 << endl
<< " edge1:" << e1 << endl
<< " edge2:" << e2 << endl
<< exit(FatalError);
}
operator[](trianglei) = labelledTri(e0Far, common01, e1Far, region);
}
// Construct patch names
setDefaultPatches();
return true;
}
// ************************************************************************* //

View File

@ -1,359 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 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/>.
Description
Nastran surface reader.
- Uses the Ansa "$ANSA_NAME" or the Hypermesh "$HMNAME COMP" extensions
to obtain patch names.
- Handles Nastran short, long, and comma-separated free formats.
- Properly handles the Nastran compact floating point notation: \n
\verbatim
GRID 28 10.20269-.030265-2.358-8
\endverbatim
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "NASCore.H"
#include "IFstream.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Do weird things to extract number
static inline scalar readNasScalar(const string& s)
{
return Foam::fileFormats::NASCore::readNasScalar(s);
}
// Read a column of a given width from either a fixed-format NAS file, or a
// comma-separated free-format NAS file
static std::string readNASToken
(
const string& line,
const size_t& width,
size_t& index
)
{
size_t indexStart = index;
size_t indexEnd = line.find(',', indexStart);
index = indexEnd + 1;
if (indexEnd == std::string::npos)
{
indexEnd = indexStart + width;
index = indexEnd;
}
return line.substr(indexStart, indexEnd - indexStart);
}
bool triSurface::readNAS(const fileName& fName)
{
IFstream is(fName);
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << fName
<< exit(FatalError);
}
// coordinates of point
DynamicList<point> points;
// Nastran index of point
DynamicList<label> indices;
// Faces in terms of Nastran point indices
DynamicList<labelledTri> faces;
// From face group to patch
Map<label> groupToPatch;
label nPatches = 0;
// Name for face group
Map<word> groupToName;
// Ansa tags. Denoted by $ANSA_NAME. These will appear just before the
// first use of a type. We read them and store the pshell types which
// are used to name the patches.
label ansaId = -1;
word ansaType;
string ansaName;
// A single warning per unrecognized command
HashSet<word> unhandledCmd;
while (is.good())
{
size_t linei = 0;
string line;
is.getLine(line);
// ANSA extension
if (line.startsWith("$ANSA_NAME"))
{
const auto sem0 = line.find(';', 0);
const auto sem1 = line.find(';', sem0+1);
const auto sem2 = line.find(';', sem1+1);
if
(
sem0 != string::npos
&& sem1 != string::npos
&& sem2 != string::npos
)
{
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
ansaType = line.substr(sem1+1, sem2-sem1-1);
string nameString;
is.getLine(ansaName);
ansaName.removeEnd("\r"); // Possible CR-NL
ansaName = ansaName.substr(1);
// Info<< "ANSA tag for NastranID:" << ansaId
// << " of type " << ansaType
// << " name " << ansaName << endl;
}
}
// Hypermesh extension
// $HMNAME COMP 1"partName"
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
{
label groupId = readLabel(line.substr(16, 16));
IStringStream lineStream(line.substr(32));
string rawName;
lineStream >> rawName;
const word groupName = word::validate(rawName);
groupToName.insert(groupId, groupName);
Info<< "group " << groupId << " => " << groupName << endl;
}
if (line.empty() || line[0] == '$')
{
// Skip empty or comment
continue;
}
// Check if character 72 is continuation
if (line.size() > 72 && line[72] == '+')
{
line.resize(72);
while (true)
{
string buf;
is.getLine(buf);
if (buf.size() > 72 && buf[72] == '+')
{
line += buf.substr(8, 64);
}
else
{
line += buf.substr(8);
break;
}
}
}
// Read first word
word cmd(IStringStream(readNASToken(line, 8, linei))());
if (cmd == "CTRIA3")
{
readNASToken(line, 8, linei);
label groupId = readLabel(readNASToken(line, 8, linei));
label a = readLabel(readNASToken(line, 8, linei));
label b = readLabel(readNASToken(line, 8, linei));
label c = readLabel(readNASToken(line, 8, linei));
// Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId);
label patchi;
if (iter == groupToPatch.end())
{
patchi = nPatches++;
groupToPatch.insert(groupId, patchi);
Info<< "patch " << patchi << " => group " << groupId << endl;
}
else
{
patchi = iter();
}
faces.append(labelledTri(a, b, c, patchi));
}
else if (cmd == "CQUAD4")
{
readNASToken(line, 8, linei);
label groupId = readLabel(readNASToken(line, 8, linei));
label a = readLabel(readNASToken(line, 8, linei));
label b = readLabel(readNASToken(line, 8, linei));
label c = readLabel(readNASToken(line, 8, linei));
label d = readLabel(readNASToken(line, 8, linei));
// Convert group into patch
Map<label>::const_iterator iter = groupToPatch.find(groupId);
label patchi;
if (iter == groupToPatch.end())
{
patchi = nPatches++;
groupToPatch.insert(groupId, patchi);
Info<< "patch " << patchi << " => group " << groupId << endl;
}
else
{
patchi = iter();
}
faces.append(labelledTri(a, b, c, patchi));
faces.append(labelledTri(c, d, a, patchi));
}
else if (cmd == "PSHELL")
{
// Read shell type since group gives patchnames
label groupId = readLabel(readNASToken(line, 8, linei));
if (groupId == ansaId && ansaType == "PSHELL")
{
const word groupName = word::validate(ansaName);
groupToName.insert(groupId, groupName);
Info<< "group " << groupId << " => " << groupName << endl;
}
}
else if (cmd == "GRID")
{
label index = readLabel(readNASToken(line, 8, linei));
readNASToken(line, 8, linei);
scalar x = readNasScalar(readNASToken(line, 8, linei));
scalar y = readNasScalar(readNASToken(line, 8, linei));
scalar z = readNasScalar(readNASToken(line, 8, linei));
indices.append(index);
points.append(point(x, y, z));
}
else if (cmd == "GRID*")
{
// Long format is on two lines with '*' continuation symbol
// on start of second line.
// Typical line (spaces compacted)
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02
label index = readLabel(readNASToken(line, 16, linei));
readNASToken(line, 16, linei);
scalar x = readNasScalar(readNASToken(line, 16, linei));
scalar y = readNasScalar(readNASToken(line, 16, linei));
linei = 0;
is.getLine(line);
if (line[0] != '*')
{
FatalErrorInFunction
<< "Expected continuation symbol '*' when reading GRID*"
<< " (double precision coordinate) output" << nl
<< "Read:" << line << nl
<< "File:" << is.name()
<< " line:" << is.lineNumber()
<< exit(FatalError);
}
readNASToken(line, 8, linei);
scalar z = readNasScalar(readNASToken(line, 16, linei));
indices.append(index);
points.append(point(x, y, z));
}
else if (unhandledCmd.insert(cmd))
{
Info<< "Unhandled Nastran command " << line << nl
<< "File:" << is.name() << " line:" << is.lineNumber() << endl;
}
}
points.shrink();
indices.shrink();
faces.shrink();
Info<< "Read triangles:" << faces.size() << " points:" << points.size()
<< endl;
{
// Build inverse mapping (index to point)
Map<label> indexToPoint(2*indices.size());
forAll(indices, i)
{
indexToPoint.insert(indices[i], i);
}
// Relabel faces
forAll(faces, i)
{
labelledTri& f = faces[i];
f[0] = indexToPoint[f[0]];
f[1] = indexToPoint[f[1]];
f[2] = indexToPoint[f[2]];
}
}
// Convert groupToPatch to patchList.
geometricSurfacePatchList patches(nPatches);
forAllConstIters(groupToName, iter)
{
const label patchIdx = groupToPatch[iter.key()];
patches[patchIdx] = geometricSurfacePatch(iter.object(), patchIdx);
}
Info<< "patches:" << patches << endl;
// Transfer DynamicLists to straight ones.
pointField allPoints(points.xfer());
// Create triSurface
*this = triSurface(faces, patches, allPoints, true);
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,199 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "IFstream.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::triSurface::readOBJ(const fileName& OBJfileName)
{
IFstream OBJfile(OBJfileName);
if (!OBJfile.good())
{
FatalErrorInFunction
<< "Cannot read file " << OBJfileName
<< exit(FatalError);
}
DynamicList<point> points;
DynamicList<labelledTri> faces;
HashTable<label> groupToPatch;
label groupID = 0;
label maxGroupID = 0;
while (OBJfile.good())
{
string line = getLineNoComment(OBJfile);
if (line.size())
{
if (line.removeEnd("\\"))
{
line += getLineNoComment(OBJfile);
}
// Read first word
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "v")
{
scalar x, y, z;
lineStream >> x >> y >> z;
points.append(point(x, y, z));
}
else if (cmd == "g")
{
word group;
lineStream >> group;
HashTable<label>::const_iterator findGroup =
groupToPatch.find(group);
if (findGroup != groupToPatch.end())
{
groupID = findGroup();
}
else
{
groupID = maxGroupID;
groupToPatch.insert(group, groupID);
maxGroupID++;
}
}
else if (cmd == "f")
{
DynamicList<label> verts;
// Assume 'f' is followed by space.
string::size_type endNum = 1;
while (true)
{
string::size_type startNum =
line.find_first_not_of(" \r", endNum);
if (startNum == string::npos)
{
break;
}
endNum = line.find(' ', startNum);
string vertexSpec;
if (endNum != string::npos)
{
vertexSpec = line.substr(startNum, endNum-startNum);
}
else
{
vertexSpec = line.substr
(
startNum,
line.size() - startNum
);
}
string::size_type slashPos = vertexSpec.find('/');
label vertI = 0;
if (slashPos != string::npos)
{
IStringStream intStream(vertexSpec.substr(0, slashPos));
intStream >> vertI;
}
else
{
IStringStream intStream(vertexSpec);
intStream >> vertI;
}
verts.append(vertI - 1);
}
verts.shrink();
// Do simple face triangulation around f[0].
// Cannot use face::triangulation since no complete points yet.
for (label fp = 1; fp < verts.size() - 1; fp++)
{
label fp1 = verts.fcIndex(fp);
labelledTri tri(verts[0], verts[fp], verts[fp1], groupID);
faces.append(tri);
}
}
}
}
points.shrink();
faces.shrink();
// Convert groupToPatch to patchList.
geometricSurfacePatchList patches(maxGroupID);
if (maxGroupID == 0)
{
// Add single (default) patch
patches = { geometricSurfacePatch("patch0", 0) };
}
else
{
forAllConstIters(groupToPatch, iter)
{
const label patchIdx = iter.object();
patches[patchIdx] = geometricSurfacePatch
(
iter.key(),
patchIdx
);
}
}
// Transfer DynamicLists to straight ones.
pointField allPoints(points.xfer());
// Create triSurface
*this = triSurface(faces, patches, allPoints, true);
return true;
}
// ************************************************************************* //

View File

@ -1,140 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Lightwave OBJ format.
Note: Java obj loader does not support '#' on line
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void triSurface::writeOBJ(const bool writeSorted, Ostream& os) const
{
// Write header
os << "# Wavefront OBJ file" << nl
<< "# Regions:" << nl;
labelList faceMap;
surfacePatchList patches(calcPatches(faceMap));
const pointField& ps = points();
// Print patch names as comment
forAll(patches, patchi)
{
os << "# " << patchi << " "
<< patches[patchi].name() << nl;
}
os << "#" << nl;
os << "# points : " << ps.size() << nl
<< "# triangles : " << size() << nl
<< "#" << nl;
// Write vertex coords
forAll(ps, pointi)
{
os << "v "
<< ps[pointi].x() << ' '
<< ps[pointi].y() << ' '
<< ps[pointi].z() << nl;
}
if (writeSorted)
{
label faceIndex = 0;
forAll(patches, patchi)
{
// Print all faces belonging to this patch
os << "g " << patches[patchi].name() << nl;
for
(
label patchFacei = 0;
patchFacei < patches[patchi].size();
patchFacei++
)
{
const label facei = faceMap[faceIndex++];
os << "f "
<< operator[](facei)[0] + 1 << ' '
<< operator[](facei)[1] + 1 << ' '
<< operator[](facei)[2] + 1
//<< " # " << operator[](facei).region()
<< nl;
}
}
}
else
{
// Get patch (=compact region) per face
labelList patchIDs(size());
forAll(patches, patchi)
{
label facei = patches[patchi].start();
forAll(patches[patchi], i)
{
patchIDs[faceMap[facei++]] = patchi;
}
}
label prevPatchi = -1;
forAll(*this, facei)
{
if (prevPatchi != patchIDs[facei])
{
prevPatchi = patchIDs[facei];
os << "g " << patches[patchIDs[facei]].name() << nl;
}
os << "f "
<< operator[](facei)[0] + 1 << ' '
<< operator[](facei)[1] + 1 << ' '
<< operator[](facei)[2] + 1
<< nl;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,134 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Geomview OFF polyList format. Does triangulation.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "IFstream.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::triSurface::readOFF(const fileName& OFFfileName)
{
IFstream OFFfile(OFFfileName);
if (!OFFfile.good())
{
FatalErrorInFunction
<< "Cannot read file " << OFFfileName
<< exit(FatalError);
}
// Read header
string hdr = getLineNoComment(OFFfile);
if (hdr != "OFF")
{
FatalErrorInFunction
<< "OFF file " << OFFfileName
<< " does not start with 'OFF'"
<< exit(FatalError);
}
label nPoints, nEdges, nElems;
string line = getLineNoComment(OFFfile);
{
IStringStream lineStream(line);
lineStream >> nPoints >> nElems >> nEdges;
}
// Read points
pointField points(nPoints);
forAll(points, pointi)
{
scalar x, y, z;
line = getLineNoComment(OFFfile);
{
IStringStream lineStream(line);
lineStream >> x >> y >> z;
}
points[pointi] = point(x, y, z);
}
// Read faces & triangulate them,
DynamicList<labelledTri> tris(nElems);
for (label facei = 0; facei < nElems; facei++)
{
line = getLineNoComment(OFFfile);
{
IStringStream lineStream(line);
label nVerts;
lineStream >> nVerts;
face f(nVerts);
forAll(f, fp)
{
lineStream >> f[fp];
}
// Triangulate.
if (nVerts == 3)
{
tris.append(labelledTri(f[0], f[1], f[2], 0));
}
else if (nVerts == 4)
{
tris.append(labelledTri(f[0], f[1], f[2], 0));
tris.append(labelledTri(f[2], f[3], f[0], 0));
}
else
{
faceList triFaces(f.nTriangles(points));
label nTri = 0;
f.triangles(points, nTri, triFaces);
forAll(triFaces, triFacei)
{
const face& f = triFaces[triFacei];
tris.append(labelledTri(f[0], f[1], f[2], 0));
}
}
}
}
tris.shrink();
*this = triSurface(tris, points);
return true;
}
// ************************************************************************* //

View File

@ -1,116 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void triSurface::writeOFF(const bool writeSorted, Ostream& os) const
{
// Write header
os << "OFF" << endl
<< "# Geomview OFF file" << endl
<< "# Regions:" << endl;
labelList faceMap;
surfacePatchList patches(calcPatches(faceMap));
// Print patch names as comment
forAll(patches, patchi)
{
os << "# " << patchi << " "
<< patches[patchi].name() << endl;
}
os << nl << endl;
const pointField& ps = points();
os << "# nPoints nTriangles nEdges" << endl
<< ps.size()
<< ' ' << size()
<< ' ' << nEdges()
<< nl << endl;
// Write vertex coords
forAll(ps, pointi)
{
os << ps[pointi].x() << ' '
<< ps[pointi].y() << ' '
<< ps[pointi].z() << " #" << pointi << endl;
}
os << endl;
if (writeSorted)
{
label faceIndex = 0;
forAll(patches, patchi)
{
// Print all faces belonging to this patch
for
(
label patchFacei = 0;
patchFacei < patches[patchi].size();
patchFacei++
)
{
const label facei = faceMap[faceIndex++];
os << "3 "
<< operator[](facei)[0] << ' '
<< operator[](facei)[1] << ' '
<< operator[](facei)[2] << ' '
<< operator[](facei).region()
<< endl;
}
}
}
else
{
forAll(*this, facei)
{
os << "3 "
<< operator[](facei)[0] << ' '
<< operator[](facei)[1] << ' '
<< operator[](facei)[2] << ' '
<< operator[](facei).region()
<< endl;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,111 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void triSurface::writeSMESH(const bool writeSorted, Ostream& os) const
{
const pointField& ps = points();
// Write header
os << "# tetgen .smesh file" << endl
<< ps.size() << " 3" << endl; // 3 dimensions
// Write vertex coords
forAll(ps, pointi)
{
os << pointi << ' '
<< ps[pointi].x() << ' '
<< ps[pointi].y() << ' '
<< ps[pointi].z() << endl;
}
if (writeSorted)
{
labelList faceMap;
surfacePatchList patches(calcPatches(faceMap));
os << size() << " 1" << endl; // 1 attribute: region number
label faceIndex = 0;
forAll(patches, patchi)
{
// Print all faces belonging to this patch
for
(
label patchFacei = 0;
patchFacei < patches[patchi].size();
patchFacei++
)
{
const label facei = faceMap[faceIndex++];
os << "3 " // triangles
<< operator[](facei)[0] << ' '
<< operator[](facei)[1] << ' '
<< operator[](facei)[2] << ' '
<< operator[](facei).region() // region number
<< endl;
}
}
os << '0' << endl // holes
<< '0' << endl; // regions
}
else
{
os << size() << " 1" << endl; // 1 attribute: region number
forAll(*this, facei)
{
os << "3 "
<< operator[](facei)[0] << ' '
<< operator[](facei)[1] << ' '
<< operator[](facei)[2] << ' '
<< operator[](facei).region() // region number
<< endl;
}
os << '0' << endl // holes
<< '0' << endl; // regions
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,92 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "STLReader.H"
#include "triSurface.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::triSurface::readSTL(const fileName& STLfileName, bool forceBinary)
{
// Read in the values
fileFormats::STLReader reader
(
STLfileName,
(
forceBinary
? fileFormats::STLCore::BINARY
: fileFormats::STLCore::UNKNOWN
)
);
// Get the map for stitched surface points, with merge tolerance depending
// on the input format
labelList pointMap;
const label nUniquePoints = reader.mergePointsMap(pointMap);
const auto& readpts = reader.points();
const labelList& zoneIds = reader.zoneIds();
pointField& pointLst = storedPoints();
List<Face>& faceLst = storedFaces();
// Sizing
pointLst.setSize(nUniquePoints);
faceLst.setSize(zoneIds.size());
// Assign points
forAll(readpts, pointi)
{
pointLst[pointMap[pointi]] = readpts[pointi];
}
// Assign triangles
label pointi = 0;
forAll(faceLst, i)
{
Face& f = faceLst[i];
f[0] = pointMap[pointi++];
f[1] = pointMap[pointi++];
f[2] = pointMap[pointi++];
f.region() = zoneIds[i];
}
// Set patch name/index.
if (reader.stlFormat() == fileFormats::STLCore::ASCII)
{
const List<word>& names = reader.names();
patches_.setSize(names.size());
forAll(patches_, patchi)
{
patches_[patchi] = geometricSurfacePatch(names[patchi], patchi);
}
}
return true;
}
// ************************************************************************* //

Some files were not shown because too many files have changed in this diff Show More