BUG: eof errors in the STARCD, VTK file reader (#1059)

- previously simply read files until the input stream went bad and no
  more lines could be read.  With the more stringent checking of
  values read (commit 0ce7e364a4) this approach causes problems.

  Use the underlying tokenizer instead to decide about termination.
This commit is contained in:
Mark Olesen
2018-11-03 15:46:37 +01:00
parent 1f9533ed5c
commit fd54070c3a
14 changed files with 402 additions and 457 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,23 +30,27 @@ License
#include "symmetryPolyPatch.H"
#include "cellModel.H"
#include "ListOps.H"
#include "stringOps.H"
#include "IFstream.H"
#include "IOMap.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
//! \cond fileScope
//- Read and discard to newline
static void readToNewline(Foam::IFstream& is)
namespace Foam
{
char ch = '\n';
do
// Read and discard to newline
static inline void readToNewline(ISstream& is)
{
(is).get(ch);
char ch = '\n';
do
{
is.get(ch);
}
while ((is) && ch != '\n');
}
while ((is) && ch != '\n');
}
//! \endcond
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -61,7 +65,7 @@ void Foam::fileFormats::STARCDMeshReader::readAux
}
// read in the points from the .vrt file
// Read points from <.vrt> file
//
/*---------------------------------------------------------------------------*\
Line 1:
@ -81,6 +85,7 @@ Foam::label Foam::fileFormats::STARCDMeshReader::readPoints
)
{
label nPoints = 0, maxId = 0;
token tok;
// Pass 1:
// get # points and maximum vertex label
@ -88,20 +93,22 @@ Foam::label Foam::fileFormats::STARCDMeshReader::readPoints
IFstream is(inputName);
readHeader(is, STARCDCore::HEADER_VRT);
label lineLabel;
scalar x, y, z;
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
nPoints++;
maxId = max(maxId, lineLabel);
const label starVertexId = tok.labelToken();
is >> x >> y >> z;
maxId = max(maxId, starVertexId);
++nPoints;
}
}
Info<< "Number of points = " << nPoints << endl;
// set sizes and reset to invalid values
// Set sizes and reset to invalid values
points_.setSize(nPoints);
mapToFoamPointId_.setSize(maxId+1);
@ -116,24 +123,30 @@ Foam::label Foam::fileFormats::STARCDMeshReader::readPoints
// Pass 2:
// construct pointList and conversion table
// from Star vertex numbers to Foam point labels
if (nPoints > 0)
if (!nPoints)
{
FatalErrorInFunction
<< "no points in file " << inputName
<< abort(FatalError);
}
else
{
IFstream is(inputName);
readHeader(is, STARCDCore::HEADER_VRT);
label lineLabel;
label pointi = 0;
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
const label starVertexId = tok.labelToken();
is >> points_[pointi].x()
>> points_[pointi].y()
>> points_[pointi].z();
// might need again in the future
//// origPointId[pointi] = lineLabel;
mapToFoamPointId_[lineLabel] = pointi;
pointi++;
//// origPointId[pointi] = starVertexId;
mapToFoamPointId_[starVertexId] = pointi;
++pointi;
}
if (nPoints > pointi)
@ -144,23 +157,21 @@ Foam::label Foam::fileFormats::STARCDMeshReader::readPoints
//// origPointId.setSize(nPoints);
}
if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
if
(
scaleFactor > 0
&& (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
)
{
points_ *= scaleFactor;
}
}
else
{
FatalErrorInFunction
<< "no points in file " << inputName
<< abort(FatalError);
}
return maxId;
}
// read in the cells from the .cel file
// Read cells from <.cel> file
//
/*---------------------------------------------------------------------------*\
Line 1:
@ -204,6 +215,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
{
label nFluids = 0, nSolids = 0, nBaffles = 0, nShells = 0;
label maxId = 0;
token tok;
bool unknownVertices = false;
@ -215,20 +227,21 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
IFstream is(inputName);
readHeader(is, STARCDCore::HEADER_CEL);
label lineLabel, shapeId, nLabels, cellTableId, typeId;
label shapeId, nLabels, cellTableId, typeId;
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
label starCellId = lineLabel;
const label starCellId = tok.labelToken();
is >> shapeId
>> nLabels
>> cellTableId
>> typeId;
// skip the rest of the line
// Skip the rest of the line
readToNewline(is);
// max 8 indices per line
// Max 8 indices per line
while (nLabels > 0)
{
readToNewline(is);
@ -237,7 +250,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
if (typeId == STARCDCore::starcdFluidType)
{
nFluids++;
++nFluids;
maxId = max(maxId, starCellId);
if (!cellTable_.found(cellTableId))
@ -248,7 +261,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
}
else if (typeId == STARCDCore::starcdSolidType)
{
nSolids++;
++nSolids;
if (keepSolids_)
{
maxId = max(maxId, starCellId);
@ -264,12 +277,12 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
else if (typeId == STARCDCore::starcdBaffleType)
{
// baffles have no cellTable entry
nBaffles++;
++nBaffles;
maxId = max(maxId, starCellId);
}
else if (typeId == STARCDCore::starcdShellType)
{
nShells++;
++nShells;
if (!cellTable_.found(cellTableId))
{
cellTable_.setName(cellTableId);
@ -336,14 +349,14 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
readHeader(is, STARCDCore::HEADER_CEL);
labelList starLabels(64);
label lineLabel, shapeId, nLabels, cellTableId, typeId;
label ignoredLabel, shapeId, nLabels, cellTableId, typeId;
label celli = 0;
label baffleI = 0;
label celli = 0, bafflei = 0;
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
label starCellId = lineLabel;
const label starCellId = tok.labelToken();
is >> shapeId
>> nLabels
>> cellTableId
@ -355,17 +368,17 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
}
starLabels = -1;
// read indices - max 8 per line
// Read indices - max 8 per line
for (label i = 0; i < nLabels; ++i)
{
if ((i % 8) == 0)
{
is >> lineLabel;
is >> ignoredLabel; // Skip cellId for continuation lines
}
is >> starLabels[i];
}
// skip solid cells
// Skip solid cells
if
(
typeId == STARCDCore::starcdSolidType
@ -375,7 +388,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
continue;
}
// determine the OpenFOAM cell shape
// Determine the OpenFOAM cell shape
const cellModel* curModelPtr = nullptr;
// fluid/solid cells
@ -432,7 +445,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
);
cellFaces_[celli] = cellShapes_[celli].faces();
celli++;
++celli;
}
else if (shapeId == STARCDCore::starcdPoly)
{
@ -509,7 +522,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
cellTableId_[celli] = cellTableId;
cellShapes_[celli] = genericShape;
cellFaces_[celli] = faces;
celli++;
++celli;
}
else if (typeId == STARCDCore::starcdBaffleType)
{
@ -547,16 +560,16 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
// valid faces only
if (f.size() >= 3)
{
baffleFaces_[baffleI] = f;
baffleFaces_[bafflei] = f;
// insert lookup addressing in normal list
mapToFoamCellId_[starCellId] = nCells + baffleI;
origCellId_[nCells + baffleI] = starCellId;
baffleI++;
mapToFoamCellId_[starCellId] = nCells + bafflei;
origCellId_[nCells + bafflei] = starCellId;
++bafflei;
}
}
}
baffleFaces_.setSize(baffleI);
baffleFaces_.setSize(bafflei);
}
if (unknownVertices)
@ -577,7 +590,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
}
// read in the boundaries from the .bnd file
// Read boundaries from <.bnd> file
//
/*---------------------------------------------------------------------------*\
Line 1:
@ -603,7 +616,8 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
)
{
label nPatches = 0, nFaces = 0, nBafflePatches = 0, maxId = 0;
label lineLabel, starCellId, cellFaceId, starRegion, configNumber;
label starCellId, cellFaceId, starRegion, configNumber;
token tok;
word patchType;
labelList mapToFoamPatchId(1000, label(-1));
@ -641,9 +655,12 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
{
readHeader(is, STARCDCore::HEADER_BND);
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
nFaces++;
// Ignore boundary id (not needed)
++nFaces;
is >> starCellId
>> cellFaceId
>> starRegion
@ -664,12 +681,12 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
// should actually be case-insensitive
if (patchType == "BAFF")
{
nBafflePatches++;
++nBafflePatches;
}
nPatches++;
++nPatches;
}
nPatchFaces[patchLabel]++;
++nPatchFaces[patchLabel];
}
if (nPatches == 0)
@ -684,7 +701,7 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
}
// keep empty patch region in reserve
nPatches++;
++nPatches;
Info<< "Number of patches = " << nPatches
<< " (including extra for missing)" << endl;
@ -703,37 +720,22 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
// - use 'Label' entry from "constant/boundaryRegion" dictionary
forAll(patchTypes_, patchi)
{
bool foundName = false, foundType = false;
bool fndName = false, fndType = false;
Map<dictionary>::const_iterator
iter = boundaryRegion_.find(origRegion[patchi]);
auto iter = boundaryRegion_.cfind(origRegion[patchi]);
if
(
iter != boundaryRegion_.end()
)
if (iter.found())
{
foundType = iter().readIfPresent
(
"BoundaryType",
patchTypes_[patchi]
);
const dictionary& dict = *iter;
foundName = iter().readIfPresent
(
"Label",
patchNames_[patchi]
);
fndType = dict.readIfPresent("BoundaryType", patchTypes_[patchi]);
fndName = dict.readIfPresent("Label", patchNames_[patchi]);
}
// consistent names, in long form and in lowercase
if (!foundType)
// Consistent names. Long form and in lowercase
if (!fndType)
{
// transform
forAllIter(string, patchTypes_[patchi], i)
{
*i = tolower(*i);
}
stringOps::inplaceLower(patchTypes_[patchi]);
if (patchTypes_[patchi] == "symp")
{
@ -753,19 +755,19 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
}
}
// create a name if needed
if (!foundName)
// Create a name if needed
if (!fndName)
{
patchNames_[patchi] =
patchTypes_[patchi] + "_" + name(origRegion[patchi]);
}
}
// enforce name "Default_Boundary_Region"
// Enforce name "Default_Boundary_Region"
patchNames_[nPatches-1] = defaultBoundaryName;
// sort according to ascending region numbers, but leave
// Default_Boundary_Region as the final patch
// Sort according to ascending region numbers, but leave
// "Default_Boundary_Region" as the final patch
{
labelList sortedIndices;
sortedOrder(SubList<label>(origRegion, nPatches-1), sortedIndices);
@ -829,8 +831,10 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
IFstream is(inputName);
readHeader(is, STARCDCore::HEADER_BND);
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
// Ignore boundary id (not needed)
is
>> starCellId
>> cellFaceId
@ -885,8 +889,8 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
#ifdef DEBUG_BOUNDARY
Info<< "bnd " << cellId << " " << cellFaceId << endl;
#endif
// increment counter of faces in current patch
nPatchFaces[patchi]++;
// Increment counter of faces in current patch
++nPatchFaces[patchi];
}
}
}
@ -969,7 +973,7 @@ void Foam::fileFormats::STARCDMeshReader::cullPoints()
}
}
// the new ordering and the count of unused points
// The new ordering and the count of unused points
label pointi = 0;
forAll(oldToNew, i)
{
@ -979,30 +983,29 @@ void Foam::fileFormats::STARCDMeshReader::cullPoints()
}
}
// report unused points
// Report unused points
if (nPoints > pointi)
{
Info<< "Unused points = " << (nPoints - pointi) << endl;
nPoints = pointi;
// adjust points and truncate
// Adjust points and truncate
inplaceReorder(oldToNew, points_);
points_.setSize(nPoints);
// adjust cellFaces - with mesh shapes this might be faster
forAll(cellFaces_, celli)
// Adjust cellFaces - with mesh shapes this might be faster
for (faceList& faces : cellFaces_)
{
faceList& faces = cellFaces_[celli];
forAll(faces, i)
for (face& f : faces)
{
inplaceRenumber(oldToNew, faces[i]);
inplaceRenumber(oldToNew, f);
}
}
// adjust baffles
forAll(baffleFaces_, facei)
// Adjust baffles
for (face& f : baffleFaces_)
{
inplaceRenumber(oldToNew, baffleFaces_[facei]);
inplaceRenumber(oldToNew, f);
}
}
}
@ -1051,10 +1054,4 @@ Foam::fileFormats::STARCDMeshReader::STARCDMeshReader
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDMeshReader::~STARCDMeshReader()
{}
// ************************************************************************* //

View File

@ -71,15 +71,6 @@ class STARCDMeshReader
bool keepSolids_;
// Private member functions
//- No copy construct
STARCDMeshReader(const STARCDMeshReader&) = delete;
//- No copy assignment
void operator=(const STARCDMeshReader&) = delete;
protected:
// Protected Data
@ -126,15 +117,14 @@ public:
STARCDMeshReader
(
const fileName& prefix,
const objectRegistry&,
const objectRegistry& registry,
const scalar scaleFactor = 1.0,
const bool keepSolids = false
);
//- Destructor
virtual ~STARCDMeshReader();
virtual ~STARCDMeshReader() = default;
};

View File

@ -24,9 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "STARCDMeshWriter.H"
#include "Time.H"
#include "SortableList.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -35,7 +33,7 @@ Foam::label Foam::fileFormats::STARCDMeshWriter::findDefaultBoundary() const
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
// find Default_Boundary_Region if it exists
// Find "Default_Boundary_Region" if it exists
forAll(patches, patchi)
{
if (defaultBoundaryName == patches[patchi].name())
@ -51,7 +49,7 @@ Foam::label Foam::fileFormats::STARCDMeshWriter::findDefaultBoundary() const
void Foam::fileFormats::STARCDMeshWriter::getCellTable()
{
// read constant/polyMesh/propertyName
// Read constant/polyMesh/propertyName
IOList<label> ioList
(
IOobject
@ -112,9 +110,8 @@ void Foam::fileFormats::STARCDMeshWriter::getCellTable()
// get the cellZone <-> cellTable correspondence
Info<< "matching cellZones to cellTable" << endl;
forAll(mesh_.cellZones(), zoneI)
for (const cellZone& cZone : mesh_.cellZones())
{
const cellZone& cZone = mesh_.cellZones()[zoneI];
if (cZone.size())
{
nUnzoned -= cZone.size();
@ -129,9 +126,9 @@ void Foam::fileFormats::STARCDMeshWriter::getCellTable()
tableId = cellTable_.append(dict);
}
forAll(cZone, i)
for (const label celli : cZone)
{
cellTableId_[cZone[i]] = tableId;
cellTableId_[celli] = tableId;
}
}
}
@ -142,7 +139,7 @@ void Foam::fileFormats::STARCDMeshWriter::getCellTable()
dict.add("Label", "__unZonedCells__");
dict.add("MaterialType", "fluid");
label tableId = cellTable_.append(dict);
const label tableId = cellTable_.append(dict);
forAll(cellTableId_, i)
{
@ -205,36 +202,36 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
const cellShape& shape = shapes[cellId];
const label mapIndex = shape.model().index();
// a registered primitive type
// A registered primitive type
if (shapeLookupIndex.found(mapIndex))
{
const label shapeId = shapeLookupIndex[mapIndex];
const labelList& vrtList = shapes[cellId];
os << cellId + 1
<< " " << shapeId
<< " " << vrtList.size()
<< " " << tableId
<< " " << materialType;
<< ' ' << shapeId
<< ' ' << vrtList.size()
<< ' ' << tableId
<< ' ' << materialType;
// primitives have <= 8 vertices, but prevent overrun anyhow
// Primitives have <= 8 vertices, but prevent overrun anyhow
// indent following lines for ease of reading
label count = 0;
forAll(vrtList, i)
for (const label pointi : vrtList)
{
if ((count % 8) == 0)
{
os << nl
<< " " << cellId + 1;
}
os << " " << vrtList[i] + 1;
count++;
os << ' ' << pointi + 1;
++count;
}
os << endl;
os << nl;
}
else
{
// treat as general polyhedral
// Treat as general polyhedral
const label shapeId = STARCDCore::starcdPoly;
const labelList& cFaces = cells[cellId];
@ -251,29 +248,28 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
}
os << cellId + 1
<< " " << shapeId
<< " " << count
<< " " << tableId
<< " " << materialType;
<< ' ' << shapeId
<< ' ' << count
<< ' ' << tableId
<< ' ' << materialType;
// write indices - max 8 per line
// Write indices - max 8 per line
// indent following lines for ease of reading
count = 0;
forAll(indices, i)
for (const label pointi : indices)
{
if ((count % 8) == 0)
{
os << nl
<< " " << cellId + 1;
}
os << " " << indices[i];
count++;
os << ' ' << pointi;
++count;
}
// write faces - max 8 per line
forAll(cFaces, facei)
for (const label meshFace : cFaces)
{
label meshFace = cFaces[facei];
face f;
if (owner[meshFace] == cellId)
@ -285,7 +281,7 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
f = faces[meshFace].reverseFace();
}
forAll(f, i)
for (const label pointi : f)
{
if ((count % 8) == 0)
{
@ -293,8 +289,8 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
<< " " << cellId + 1;
}
os << " " << f[i] + 1;
count++;
os << ' ' << pointi + 1;
++count;
}
}
@ -349,7 +345,7 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
}
else if (defaultId == -1 || regionId < defaultId)
{
regionId++;
++regionId;
}
label patchStart = patches[patchi].start();
@ -377,7 +373,7 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
// as defined by primitiveMesh::cellShapes()
// Thus, for registered primitive types, do the lookup ourselves.
// Finally, the cellModel face number is re-mapped to the
// STAR-CD local face number
// STARCD local face number
label mapIndex = shape.model().index();
@ -400,15 +396,15 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
}
// Info<< endl;
boundId++;
++boundId;
os
<< boundId
<< " " << cellId + 1
<< " " << cellFaceId + 1
<< " " << regionId
<< " " << 0
<< " " << bndType.c_str()
<< ' ' << cellId + 1
<< ' ' << cellFaceId + 1
<< ' ' << regionId
<< ' ' << 0
<< ' ' << bndType.c_str()
<< endl;
}
}
@ -433,12 +429,6 @@ Foam::fileFormats::STARCDMeshWriter::STARCDMeshWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDMeshWriter::~STARCDMeshWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDMeshWriter::write(const fileName& meshName) const
@ -461,7 +451,7 @@ bool Foam::fileFormats::STARCDMeshWriter::write(const fileName& meshName) const
STARCDCore::removeFiles(baseName);
// points
// Points
{
OFstream os
(
@ -474,10 +464,10 @@ bool Foam::fileFormats::STARCDMeshWriter::write(const fileName& meshName) const
writePoints(os, mesh_.points(), scaleFactor_);
}
// cells
// Cells
writeCells(baseName);
// boundaries
// Boundaries
if (writeBoundary_)
{
writeBoundary(baseName);

View File

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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,14 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "STARCDCore.H"
#include "ListOps.H"
#include "clock.H"
#include "bitSet.H"
#include "DynamicList.H"
#include "StringStream.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::Enum
@ -85,9 +80,41 @@ Foam::fileFormats::STARCDCore::starToFoamFaceAddr =
{ starcdPyr, { 0, -1, 4, 2, 1, 3 } }
};
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Read and discard to newline
static inline void readToNewline(ISstream& is)
{
char ch = '\n';
do
{
is.get(ch);
}
while ((is) && ch != '\n');
}
} // End namespace Foam
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
// Read two-line header
//
/*---------------------------------------------------------------------------*\
Line 1:
PROSTAR_(BOUNDARY|CELL|VERTEX) [newline]
Line 2:
<version> 0 0 0 0 0 0 0 [newline]
Body:
...
\*---------------------------------------------------------------------------*/
bool Foam::fileFormats::STARCDCore::readHeader
(
IFstream& is,
@ -100,23 +127,20 @@ bool Foam::fileFormats::STARCDCore::readHeader
<< abort(FatalError);
}
word magic;
word magic;
is >> magic;
readToNewline(is);
label majorVersion;
is >> majorVersion;
readToNewline(is);
string line;
is.getLine(line);
IStringStream(line)() >> magic;
is.getLine(line);
IStringStream(line)() >> majorVersion;
// add other checks ...
// Add other checks ...
if (magic != fileHeaders_[header])
{
Info<< "header mismatch " << fileHeaders_[header]
Info<< "Header mismatch " << fileHeaders_[header]
<< " " << is.name()
<< endl;
<< nl;
return false;
}
@ -133,14 +157,14 @@ void Foam::fileFormats::STARCDCore::writeHeader
{
os << fileHeaders_[header] << nl
<< 4000
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< endl;
<< ' ' << 0
<< ' ' << 0
<< ' ' << 0
<< ' ' << 0
<< ' ' << 0
<< ' ' << 0
<< ' ' << 0
<< nl;
}
@ -173,6 +197,7 @@ Foam::label Foam::fileFormats::STARCDCore::readPoints
)
{
label maxId = 0;
token tok;
if (!is.good())
{
@ -183,24 +208,26 @@ Foam::label Foam::fileFormats::STARCDCore::readPoints
readHeader(is, HEADER_VRT);
// reuse memory if possible
// Reuse memory if possible
DynamicList<point> dynPoints(std::move(points));
DynamicList<label> dynPointId(std::move(ids)); // STAR-CD index of points
DynamicList<label> dynPointId(std::move(ids)); // STARCD index of points
dynPoints.clear();
dynPointId.clear();
{
label lineLabel;
scalar x, y, z;
while ((is >> lineLabel).good())
while (is.read(tok).good() && tok.isLabel())
{
maxId = max(maxId, lineLabel);
const label starVertexId = tok.labelToken();
is >> x >> y >> z;
maxId = max(maxId, starVertexId);
dynPoints.append(point(x, y, z));
dynPointId.append(lineLabel);
dynPointId.append(starVertexId);
}
}
@ -223,18 +250,23 @@ void Foam::fileFormats::STARCDCore::writePoints
// Set the precision of the points data to 10
os.precision(10);
// force decimal point for Fortran input
// Force decimal point for Fortran input
os.setf(std::ios::showpoint);
forAll(points, ptI)
label starVertId = 1; // 1-based vertex labels
for (const point& p : points)
{
// convert [m] -> [mm] etc
// Convert [m] -> [mm] etc
os
<< ptI + 1 << ' '
<< scaleFactor * points[ptI].x() << ' '
<< scaleFactor * points[ptI].y() << ' '
<< scaleFactor * points[ptI].z() << '\n';
<< starVertId << ' '
<< scaleFactor * p.x() << ' '
<< scaleFactor * p.y() << ' '
<< scaleFactor * p.z() << nl;
++starVertId;
}
os.flush();
}

View File

@ -93,7 +93,7 @@ void Foam::vtkUnstructuredReader::warnUnhandledType
if (warningGiven.insert(type))
{
IOWarningInFunction(inFile)
<< "Skipping unknown cell type " << type << endl;
<< "Skipping unknown cell type " << type << nl;
}
}
@ -344,10 +344,9 @@ void Foam::vtkUnstructuredReader::extractCells
}
}
if (debug)
{
Info<< "Read " << celli << " cells;" << facei << " faces." << endl;
}
DebugInfo
<< "Read " << celli << " cells;" << facei << " faces." << nl;
cells_.setSize(celli);
cellMap_.setSize(celli);
faces_.setSize(facei);
@ -401,10 +400,9 @@ void Foam::vtkUnstructuredReader::readField
case VTK_STRING:
{
if (debug)
{
Info<< "Reading strings:" << size << endl;
}
DebugInfo
<< "Reading strings:" << size << nl;
auto fieldVals = autoPtr<stringIOList>::New
(
IOobject(arrayName, "", obj),
@ -425,9 +423,9 @@ void Foam::vtkUnstructuredReader::readField
default:
{
IOWarningInFunction(inFile)
<< "Unhandled type " << dataType << endl
<< "Unhandled type " << dataType << nl
<< "Skipping " << size
<< " words." << endl;
<< " words." << nl;
scalarField fieldVals;
readBlock(inFile, size, fieldVals);
}
@ -437,9 +435,9 @@ void Foam::vtkUnstructuredReader::readField
else
{
IOWarningInFunction(inFile)
<< "Unhandled type " << dataType << endl
<< "Unhandled type " << dataType << nl
<< "Skipping " << size
<< " words." << endl;
<< " words." << nl;
scalarField fieldVals;
readBlock(inFile, size, fieldVals);
}
@ -456,14 +454,14 @@ Foam::wordList Foam::vtkUnstructuredReader::readFieldArray
DynamicList<word> fields;
word dataName(inFile);
if (debug)
{
Info<< "dataName:" << dataName << endl;
}
DebugInfo
<< "dataName:" << dataName << nl;
label numArrays(readLabel(inFile));
if (debug)
{
Pout<< "numArrays:" << numArrays << endl;
Pout<< "numArrays:" << numArrays << nl;
}
for (label i = 0; i < numArrays; i++)
{
@ -472,11 +470,9 @@ Foam::wordList Foam::vtkUnstructuredReader::readFieldArray
label numTuples(readLabel(inFile));
word dataType(inFile);
if (debug)
{
Info<< "Reading field " << arrayName
<< " of " << numTuples << " tuples of rank " << numComp << endl;
}
DebugInfo
<< "Reading field " << arrayName
<< " of " << numTuples << " tuples of rank " << numComp << nl;
if (wantedSize != -1 && numTuples != wantedSize)
{
@ -536,20 +532,13 @@ Foam::vtkUnstructuredReader::vtkUnstructuredReader
void Foam::vtkUnstructuredReader::read(ISstream& inFile)
{
inFile.getLine(header_);
if (debug)
{
Info<< "Header : " << header_ << endl;
}
DebugInfo<< "Header : " << header_ << nl;
inFile.getLine(title_);
if (debug)
{
Info<< "Title : " << title_ << endl;
}
DebugInfo<< "Title : " << title_ << nl;
inFile.getLine(dataType_);
if (debug)
{
Info<< "dataType : " << dataType_ << endl;
}
DebugInfo<< "dataType : " << dataType_ << nl;
if (dataType_ == "BINARY")
{
@ -564,28 +553,21 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
// Temporary storage for vertices of cells.
labelList cellVerts;
while (inFile.good())
token tok;
while (inFile.read(tok).good() && tok.isWord())
{
word tag(inFile);
const word tag = tok.wordToken();
if (!inFile.good())
{
break;
}
if (debug)
{
Info<< "line:" << inFile.lineNumber()
<< " tag:" << tag << endl;
}
DebugInfo
<< "line:" << inFile.lineNumber()
<< " tag:" << tag << nl;
if (tag == "DATASET")
{
word geomType(inFile);
if (debug)
{
Info<< "geomType : " << geomType << endl;
}
DebugInfo<< "geomType : " << geomType << nl;
readMode = parseModeNames[geomType];
wantedSize = -1;
}
@ -593,11 +575,10 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
{
label nPoints(readLabel(inFile));
points_.setSize(nPoints); ///3);
if (debug)
{
Info<< "Reading " << nPoints << " numbers representing "
<< points_.size() << " coordinates." << endl;
}
DebugInfo
<< "Reading " << nPoints << " numbers representing "
<< points_.size() << " coordinates." << nl;
word primitiveTag(inFile);
if (primitiveTag != "float" && primitiveTag != "double")
@ -607,19 +588,18 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
<< primitiveTag
<< exit(FatalIOError);
}
forAll(points_, i)
for (point& p : points_)
{
inFile >> points_[i].x() >> points_[i].y() >> points_[i].z();
inFile >> p.x() >> p.y() >> p.z();
}
}
else if (tag == "CELLS")
{
label nCells(readLabel(inFile));
label nNumbers(readLabel(inFile));
if (debug)
{
Info<< "Reading " << nCells << " cells or faces." << endl;
}
DebugInfo
<< "Reading " << nCells << " cells or faces." << nl;
readBlock(inFile, nNumbers, cellVerts);
}
else if (tag == "CELL_TYPES")
@ -644,10 +624,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
{
label nLines(readLabel(inFile));
label nNumbers(readLabel(inFile));
if (debug)
{
Info<< "Reading " << nLines << " lines." << endl;
}
DebugInfo
<< "Reading " << nLines << " lines." << nl;
labelList lineVerts;
readBlock(inFile, nNumbers, lineVerts);
@ -674,10 +653,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
label nFaces(readLabel(inFile));
label nNumbers(readLabel(inFile));
if (debug)
{
Info<< "Reading " << nFaces << " faces." << endl;
}
DebugInfo
<< "Reading " << nFaces << " faces." << nl;
labelList faceVerts;
readBlock(inFile, nNumbers, faceVerts);
@ -740,12 +718,10 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
word dataType(is);
//label numComp(readLabel(inFile));
if (debug)
{
Info<< "Reading scalar " << dataName
<< " of type " << dataType
<< " from lookup table" << endl;
}
DebugInfo
<< "Reading scalar " << dataName
<< " of type " << dataType
<< " from lookup table" << nl;
word lookupTableTag(inFile);
if (lookupTableTag != "LOOKUP_TABLE")
@ -775,11 +751,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
IStringStream is(line);
word dataName(is);
word dataType(is);
if (debug)
{
Info<< "Reading vector " << dataName
<< " of type " << dataType << endl;
}
DebugInfo
<< "Reading vector " << dataName
<< " of type " << dataType << nl;
objectRegistry& reg = selectRegistry(readMode);
@ -827,12 +801,10 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
label dim(readLabel(is));
word dataType(is);
if (debug)
{
Info<< "Reading texture coords " << dataName
<< " dimension " << dim
<< " of type " << dataType << endl;
}
DebugInfo
<< "Reading texture coords " << dataName
<< " dimension " << dim
<< " of type " << dataType << nl;
scalarField coords(dim*points_.size());
readBlock(inFile, coords.size(), coords);
@ -841,10 +813,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
{
label nStrips(readLabel(inFile));
label nNumbers(readLabel(inFile));
if (debug)
{
Info<< "Reading " << nStrips << " triangle strips." << endl;
}
DebugInfo
<< "Reading " << nStrips << " triangle strips." << nl;
labelList faceVerts;
readBlock(inFile, nNumbers, faceVerts);
@ -897,11 +868,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
<< infoTag << exit(FatalIOError);
}
label nInfo(readLabel(inFile));
if (debug)
{
Info<< "Consuming " << nInfo << " metadata information."
<< endl;
}
DebugInfo
<< "Consuming " << nInfo << " metadata information." << nl;
string line;
// Consume rest of line
inFile.getLine(line);
@ -926,9 +895,8 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
label nSwapped = 0;
forAll(cells_, celli)
for (cellShape& shape : cells_)
{
cellShape& shape = cells_[celli];
if (shape.model() == prism)
{
const triPointRef bottom
@ -961,7 +929,7 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
if (nSwapped > 0)
{
WarningInFunction << "Swapped " << nSwapped << " prismatic cells"
<< endl;
<< nl;
}
}
@ -971,23 +939,23 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
<< " cellShapes:" << cells_.size()
<< " faces:" << faces_.size()
<< " lines:" << lines_.size()
<< nl << endl;
<< nl << nl;
Info<< "Cell fields:" << endl;
Info<< "Cell fields:" << nl;
printFieldStats<vectorIOField>(cellData_);
printFieldStats<scalarIOField>(cellData_);
printFieldStats<labelIOField>(cellData_);
printFieldStats<stringIOList>(cellData_);
Info<< nl << endl;
Info<< nl << nl;
Info<< "Point fields:" << endl;
Info<< "Point fields:" << nl;
printFieldStats<vectorIOField>(pointData_);
printFieldStats<scalarIOField>(pointData_);
printFieldStats<labelIOField>(pointData_);
printFieldStats<stringIOList>(pointData_);
Info<< nl << endl;
Info<< nl << nl;
Info<< "Other fields:" << endl;
Info<< "Other fields:" << nl;
printFieldStats<vectorIOField>(otherData_);
printFieldStats<scalarIOField>(otherData_);
printFieldStats<labelIOField>(otherData_);

View File

@ -41,9 +41,9 @@ void Foam::vtkUnstructuredReader::readBlock
) const
{
list.setSize(n);
forAll(list, i)
for (T& val : list)
{
inFile >> list[i];
inFile >> val;
}
}

View File

@ -39,19 +39,21 @@ inline void Foam::fileFormats::STARCDedgeFormat::writeLines
{
writeHeader(os, STARCDCore::HEADER_CEL);
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
const label cellId = edgeI + 1;
label starCellId = 1; // 1-based cellId
os << cellId // includes 1 offset
for (const edge& e : edges)
{
os << starCellId
<< ' ' << starcdLine // 2(line) shape
<< ' ' << e.size()
<< ' ' << 401 // arbitrary value
<< ' ' << starcdLineType; // 5(line)
os << nl << " " << cellId << " "
os << nl
<< " " << starCellId << " "
<< (e[0]+1) << " " << (e[1]+1) << nl;
++starCellId;
}
}
@ -67,7 +69,7 @@ void Foam::fileFormats::STARCDedgeFormat::writeCase
{
const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
os << "! STARCD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
<< "! case " << caseName << nl
<< "! ------------------------------" << nl;
@ -112,10 +114,10 @@ bool Foam::fileFormats::STARCDedgeFormat::read
fileName baseName = filename.lessExt();
// STAR-CD index of points
// STARCD index of points
List<label> pointId;
// read points from .vrt file
// Read points from .vrt file
readPoints
(
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
@ -123,7 +125,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
pointId
);
// Build inverse mapping (STAR-CD pointId -> index)
// Build inverse mapping (STARCD pointId -> index)
Map<label> mapPointId(2*pointId.size());
forAll(pointId, i)
{
@ -131,11 +133,11 @@ bool Foam::fileFormats::STARCDedgeFormat::read
}
pointId.clear();
// note which points were really used and which can be culled
// Note which points were really used and which can be culled
bitSet usedPoints(points().size());
//
// read .cel file
// Read .cel file
// ~~~~~~~~~~~~~~
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
if (!is.good())
@ -147,29 +149,35 @@ bool Foam::fileFormats::STARCDedgeFormat::read
readHeader(is, STARCDCore::HEADER_CEL);
DynamicList<edge> dynEdges;
DynamicList<edge> dynEdges;
label lineLabel, shapeId, nLabels, cellTableId, typeId;
label ignoredLabel, shapeId, nLabels, cellTableId, typeId;
DynamicList<label> vertexLabels(64);
while ((is >> lineLabel).good())
token tok;
while (is.read(tok).good() && tok.isLabel())
{
is >> shapeId >> nLabels >> cellTableId >> typeId;
// const label starCellId = tok.labelToken();
is >> shapeId
>> nLabels
>> cellTableId
>> typeId;
vertexLabels.clear();
vertexLabels.reserve(nLabels);
// read indices - max 8 per line
// Read indices - max 8 per line
for (label i = 0; i < nLabels; ++i)
{
label vrtId;
if ((i % 8) == 0)
{
is >> lineLabel;
is >> ignoredLabel; // Skip cellId for continuation lines
}
is >> vrtId;
// convert original vertex id to point label
// Convert original vertex id to point label
vertexLabels.append(mapPointId[vrtId]);
}
@ -200,7 +208,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
pts[nUsed] = pts[pointi];
}
// map prev -> new id
// Map prev -> new id
mapPointId.set(pointi, nUsed);
++nUsed;
@ -208,10 +216,8 @@ bool Foam::fileFormats::STARCDedgeFormat::read
pts.resize(nUsed);
// Renumber edge vertices
forAll(dynEdges, edgeI)
for (edge& e : dynEdges)
{
edge& e = dynEdges[edgeI];
e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]];
}
@ -245,7 +251,7 @@ void Foam::fileFormats::STARCDedgeFormat::write
edgeLst
);
// write a simple .inp file
// Write a simple .inp file
writeCase
(
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),

View File

@ -38,32 +38,30 @@ namespace Foam
void Foam::ensightSurfaceReader::skip(const label n, Istream& is) const
{
label i = 0;
token t;
token tok;
while (is.good() && (i < n))
{
is >> t;
i++;
is >> tok;
++i;
if (debug)
{
Info<< "Skipping token " << t << endl;
}
DebugInfo
<< "Skipping token " << tok << nl;
}
if (i != n)
{
WarningInFunction
<< "Requested to skip " << n << "tokens, but stream exited after "
<< i << " tokens. Last token read: " << t
<< endl;
<< i << " tokens. Last token read: " << tok
<< nl;
}
}
void Foam::ensightSurfaceReader::readLine(IFstream& is, string& buffer) const
{
buffer = "";
while (is.good() && buffer == "")
buffer.clear();
while (is.good() && buffer.empty())
{
is.getLine(buffer);
}
@ -76,7 +74,7 @@ void Foam::ensightSurfaceReader::debugSection
IFstream& is
) const
{
string actual = "";
string actual;
readLine(is, actual);
if (expected != actual)
@ -87,10 +85,8 @@ void Foam::ensightSurfaceReader::debugSection
<< exit(FatalIOError);
}
if (debug)
{
Info<< "Read section header: " << expected << endl;
}
DebugInfo
<< "Read section header: " << expected << nl;
}
@ -103,45 +99,42 @@ void Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
// Ensight Geometry File
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Description - 1
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Node info
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Element info
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Part
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Part number
label ibuffer;
is.read(ibuffer);
if (debug) Info<< "ibuffer: " << ibuffer << endl;
DebugInfo<< "ibuffer: " << ibuffer << nl;
// Description - 2
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Coordinates
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
}
void Foam::ensightSurfaceReader::readCase(IFstream& is)
{
if (debug)
{
InfoInFunction<< endl;
}
DebugInFunction<< nl;
if (!is.good())
{
@ -211,11 +204,9 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
fieldNames_.transfer(fieldNames);
fieldFileNames_.transfer(fieldFileNames);
if (debug)
{
Info<< "fieldNames: " << fieldNames_ << nl
<< "fieldFileNames: " << fieldFileNames_ << endl;
}
DebugInfo
<< "fieldNames: " << fieldNames_ << nl
<< "fieldFileNames: " << fieldFileNames_ << nl;
// Start reading time information
readLine(is, buffer); // time set: <int>
@ -227,12 +218,10 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
readLine(is, buffer);
readFromLine(2, buffer, timeIncrement_); // filename increment: <int>
if (debug)
{
Info<< "nTimeSteps: " << nTimeSteps_ << nl
<< "timeStartIndex: " << timeStartIndex_ << nl
<< "timeIncrement: " << timeIncrement_ << endl;
}
DebugInfo
<< "nTimeSteps: " << nTimeSteps_ << nl
<< "timeStartIndex: " << timeStartIndex_ << nl
<< "timeIncrement: " << timeIncrement_ << nl;
// Read the time values
readLine(is, buffer); // time values:
@ -274,10 +263,7 @@ Foam::ensightSurfaceReader::ensightSurfaceReader(const fileName& fName)
const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
{
if (debug)
{
InfoInFunction<< endl;
}
DebugInFunction<< nl;
if (!surfPtr_.valid())
{
@ -337,20 +323,16 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
ensightReadFile is(baseDir_/meshFileName_, streamFormat_);
if (debug)
{
Info<< "File: " << is.name() << endl;
}
DebugInfo
<< "File: " << is.name() << nl;
readGeometryHeader(is);
label nPoints;
is.read(nPoints);
if (debug)
{
Info<< "nPoints: " << nPoints << endl;
}
DebugInfo
<< "nPoints: " << nPoints << nl;
pointField points(nPoints);
{
@ -381,16 +363,14 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
break;
}
if (debug)
{
Info<< "faceType: " << faceType << endl;
}
DebugInfo
<< "faceType: " << faceType << endl;
if (faceType == "tria3")
{
is.read(nFace);
label np = 3;
const label np = 3;
for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
@ -406,7 +386,7 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
{
is.read(nFace);
label np = 4;
const label np = 4;
for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
@ -455,20 +435,16 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
schema_.transfer(schema);
if (debug)
{
Info<< "read nFaces: " << faces.size() << nl
<< "file schema: " << schema_ << endl;
}
DebugInfo
<< "read nFaces: " << faces.size() << nl
<< "file schema: " << schema_ << nl;
// Convert from 1-based Ensight addressing to 0-based OF addressing
forAll(faces, faceI)
for (face& f : faces)
{
face& f = faces[faceI];
forAll(f, fpI)
for (label& pointi : f)
{
f[fpI]--;
--pointi;
}
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,16 +44,16 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
<< ' ' << cellTableId
<< ' ' << starcdShellType; // 4(shell)
// primitives have <= 8 vertices, but prevent overrun anyhow
// Primitives have <= 8 vertices, but prevent overrun anyhow
// indent following lines for ease of reading
label count = 0;
for (const label verti : f)
for (const label pointi : f)
{
if ((count % 8) == 0)
{
os << nl << " " << cellId;
}
os << ' ' << verti + 1;
os << ' ' << pointi + 1;
++count;
}
os << nl;
@ -91,7 +91,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
);
// STAR-CD index of points
// STARCD index of points
List<label> pointId;
// read points from .vrt file
@ -102,7 +102,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
pointId
);
// Build inverse mapping (STAR-CD pointId -> index)
// Build inverse mapping (STARCD pointId -> index)
Map<label> mapPointId(2*pointId.size());
forAll(pointId, i)
{
@ -133,27 +133,33 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
bool sorted = true;
label zoneId = 0;
label lineLabel, shapeId, nLabels, cellTableId, typeId;
label ignoredLabel, shapeId, nLabels, cellTableId, typeId;
DynamicList<label> vertexLabels(64);
while ((is >> lineLabel).good())
token tok;
while (is.read(tok).good() && tok.isLabel())
{
is >> shapeId >> nLabels >> cellTableId >> typeId;
// const label starCellId = tok.labelToken();
is >> shapeId
>> nLabels
>> cellTableId
>> typeId;
vertexLabels.clear();
vertexLabels.reserve(nLabels);
// read indices - max 8 per line
// Read indices - max 8 per line
for (label i = 0; i < nLabels; ++i)
{
label vrtId;
if ((i % 8) == 0)
{
is >> lineLabel;
is >> ignoredLabel; // Skip cellId for continuation lines
}
is >> vrtId;
// convert original vertex id to point label
// Convert original vertex id to point label
vertexLabels.append(mapPointId[vrtId]);
}
@ -183,10 +189,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
}
else
{
dynNames.append
(
word("cellTable_") + ::Foam::name(cellTableId)
);
dynNames.append("cellTable_" + ::Foam::name(cellTableId));
}
dynSizes.append(0);
@ -204,7 +207,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
for (const face& tri : trias)
{
// a triangular 'face', convert to 'triFace' etc
// A triangular 'face', convert to 'triFace' etc
dynFaces.append(Face(tri));
dynZones.append(zoneId);
dynSizes[zoneId]++;

View File

@ -86,7 +86,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
{
const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
os << "! STARCD file written " << clock::dateTime().c_str() << nl
<< "! " << pts.size() << " points, " << nFaces << " faces" << nl
<< "! case " << caseName << nl
<< "! ------------------------------" << nl;

View File

@ -46,9 +46,8 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
class IFstream;
// Forward declarations
class ISstream;
class Time;
namespace fileFormats

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,25 +31,6 @@ License
#include "mergePoints.H"
#include "Map.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
static Foam::string getLineNoComment
(
Foam::ISstream& is,
const char comment='#'
)
{
Foam::string line;
do
{
is.getLine(line);
}
while ((line.empty() || line[0] == comment) && is.good());
return line;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::TRIReader::readFile(const fileName& filename)
@ -80,7 +61,7 @@ bool Foam::fileFormats::TRIReader::readFile(const fileName& filename)
while (is.good())
{
string line = getLineNoComment(is);
string line = this->getLineNoComment(is);
if (line.empty())
{

View File

@ -43,6 +43,7 @@ SourceFiles
#include "STLpoint.H"
#include "labelList.H"
#include "surfaceFormatsCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -56,6 +57,8 @@ namespace fileFormats
\*---------------------------------------------------------------------------*/
class TRIReader
:
public surfaceFormatsCore
{
// Private Data