mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consolidate surfaceFormats for reading/writing triSurface (issue #294)
- eliminates previous code duplication and improves maintainability
This commit is contained in:
@ -38,15 +38,16 @@ Foam::word Foam::fileFormats::edgeMeshFormatsCore::nativeExt("eMesh");
|
||||
|
||||
Foam::string Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
|
||||
(
|
||||
IFstream& is
|
||||
ISstream& is,
|
||||
const char comment
|
||||
)
|
||||
{
|
||||
string line;
|
||||
Foam::string line;
|
||||
do
|
||||
{
|
||||
is.getLine(line);
|
||||
}
|
||||
while ((line.empty() || line[0] == '#') && is.good());
|
||||
while ((line.empty() || line[0] == comment) && is.good());
|
||||
|
||||
return line;
|
||||
}
|
||||
@ -183,16 +184,4 @@ bool Foam::fileFormats::edgeMeshFormatsCore::checkSupport
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::edgeMeshFormatsCore::edgeMeshFormatsCore()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::edgeMeshFormatsCore::~edgeMeshFormatsCore()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -46,7 +46,7 @@ namespace Foam
|
||||
|
||||
// Forward declaration of classes
|
||||
|
||||
class IFstream;
|
||||
class ISstream;
|
||||
class Time;
|
||||
|
||||
namespace fileFormats
|
||||
@ -63,7 +63,7 @@ protected:
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read non-comment line
|
||||
static string getLineNoComment(IFstream&);
|
||||
static string getLineNoComment(ISstream& is, const char comment='#');
|
||||
|
||||
public:
|
||||
|
||||
@ -103,11 +103,11 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
edgeMeshFormatsCore();
|
||||
edgeMeshFormatsCore() = default;
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~edgeMeshFormatsCore();
|
||||
virtual ~edgeMeshFormatsCore() = default;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -30,10 +30,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::NASedgeFormat::NASedgeFormat
|
||||
(
|
||||
const fileName& filename
|
||||
)
|
||||
Foam::fileFormats::NASedgeFormat::NASedgeFormat(const fileName& filename)
|
||||
{
|
||||
read(filename);
|
||||
}
|
||||
@ -62,13 +59,13 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string::size_type linei = 0; // parsing position within current line
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
// Skip empty or comment
|
||||
if (line.empty() || line[0] == '$')
|
||||
{
|
||||
continue;
|
||||
continue; // Skip empty or comment
|
||||
}
|
||||
|
||||
// Check if character 72 is continuation
|
||||
@ -94,39 +91,38 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
}
|
||||
|
||||
|
||||
// Read first word
|
||||
IStringStream lineStream(line);
|
||||
word cmd;
|
||||
lineStream >> cmd;
|
||||
// First word (column 0-8)
|
||||
const word cmd(word::validate(nextNasField(line, linei, 8)));
|
||||
|
||||
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));
|
||||
e[0] = readLabel(line.substr(24,8));
|
||||
e[1] = readLabel(line.substr(32,8));
|
||||
label a = readLabel(nextNasField(line, linei, 8)); // 24-32
|
||||
label b = readLabel(nextNasField(line, linei, 8)); // 32-40
|
||||
|
||||
// discard groupID
|
||||
dynEdges.append(e);
|
||||
dynEdges.append(edge(a,b));
|
||||
}
|
||||
else if (cmd == "PLOTEL")
|
||||
{
|
||||
edge e;
|
||||
// discard elementId (8-16)
|
||||
(void) nextNasField(line, linei, 8); // 8-16
|
||||
|
||||
// label groupId = readLabel(line.substr(16,8));
|
||||
e[0] = readLabel(line.substr(16,8));
|
||||
e[1] = readLabel(line.substr(24,8));
|
||||
label a = readLabel(nextNasField(line, linei, 8)); // 16-24
|
||||
label b = readLabel(nextNasField(line, linei, 8)); // 24-32
|
||||
|
||||
// discard groupID
|
||||
dynEdges.append(e);
|
||||
dynEdges.append(edge(a,b));
|
||||
}
|
||||
else if (cmd == "GRID")
|
||||
{
|
||||
label index = readLabel(line.substr(8,8));
|
||||
scalar x = readNasScalar(line.substr(24, 8));
|
||||
scalar y = readNasScalar(line.substr(32, 8));
|
||||
scalar z = readNasScalar(line.substr(40, 8));
|
||||
label index = readLabel(nextNasField(line, linei, 8)); // 8-16
|
||||
(void) nextNasField(line, linei, 8); // 16-24
|
||||
scalar x = readNasScalar(nextNasField(line, linei, 8)); // 24-32
|
||||
scalar y = readNasScalar(nextNasField(line, linei, 8)); // 32-40
|
||||
scalar z = readNasScalar(nextNasField(line, linei, 8)); // 40-48
|
||||
|
||||
pointId.append(index);
|
||||
dynPoints.append(point(x, y, z));
|
||||
@ -139,10 +135,12 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
||||
// * 2.14897901E+02
|
||||
|
||||
label index = readLabel(line.substr(8,16));
|
||||
scalar x = readNasScalar(line.substr(40, 16));
|
||||
scalar y = readNasScalar(line.substr(56, 16));
|
||||
label index = readLabel(nextNasField(line, linei, 16)); // 8-24
|
||||
(void) nextNasField(line, linei, 16); // 24-40
|
||||
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);
|
||||
if (line[0] != '*')
|
||||
{
|
||||
@ -153,7 +151,8 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
<< "File:" << is.name() << " line:" << is.lineNumber()
|
||||
<< 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);
|
||||
dynPoints.append(point(x, y, z));
|
||||
@ -179,9 +178,8 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
|
||||
// Pass1: relabel edges
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
forAll(dynEdges, i)
|
||||
for (edge& e : dynEdges)
|
||||
{
|
||||
edge& e = dynEdges[i];
|
||||
e[0] = mapPointId[e[0]];
|
||||
e[1] = mapPointId[e[1]];
|
||||
|
||||
@ -191,7 +189,7 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
pointId.clearStorage();
|
||||
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())
|
||||
{
|
||||
label nUsed = 0;
|
||||
@ -215,11 +213,9 @@ bool Foam::fileFormats::NASedgeFormat::read
|
||||
|
||||
pts.setSize(nUsed);
|
||||
|
||||
// renumber edge vertices
|
||||
forAll(dynEdges, edgeI)
|
||||
// Renumber edge vertices
|
||||
for (edge& e : dynEdges)
|
||||
{
|
||||
edge& e = dynEdges[edgeI];
|
||||
|
||||
e[0] = mapPointId[e[0]];
|
||||
e[1] = mapPointId[e[1]];
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,13 @@ Class
|
||||
Description
|
||||
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
|
||||
NASedgeFormat.C
|
||||
|
||||
@ -57,17 +64,17 @@ class NASedgeFormat
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
NASedgeFormat(const NASedgeFormat&);
|
||||
NASedgeFormat(const NASedgeFormat&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const NASedgeFormat&);
|
||||
void operator=(const NASedgeFormat&) = delete;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from file name
|
||||
NASedgeFormat(const fileName&);
|
||||
NASedgeFormat(const fileName& filename);
|
||||
|
||||
|
||||
// Selectors
|
||||
@ -83,14 +90,14 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~NASedgeFormat()
|
||||
{}
|
||||
virtual ~NASedgeFormat() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read from a file
|
||||
virtual bool read(const fileName&);
|
||||
virtual bool read(const fileName& filename);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user