Begin code refactoring of third-party file formats.

This commit is contained in:
Mark Olesen
2010-01-15 14:35:50 +01:00
parent a132aadeb8
commit 0d49e4711c
21 changed files with 380 additions and 359 deletions

View File

@ -0,0 +1,4 @@
nas/NASCore.C
starcd/STARCDCore.C
LIB = $(FOAM_LIBBIN)/libfileFormats

View File

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "NASCore.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::NASCore::NASCore()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::scalar Foam::fileFormats::NASCore::parseNASCoord
(
const string& s
)
{
size_t expSign = s.find_last_of("+-");
if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1]))
{
scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))());
scalar exponent = readScalar(IStringStream(s.substr(expSign+1))());
if (s[expSign] == '-')
{
exponent = -exponent;
}
return mantissa * pow(10, exponent);
}
else
{
return readScalar(IStringStream(s)());
}
}
// ************************************************************************* //

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::NASCore
Description
Core routines used when reading/writing NASTRAN files.
SourceFiles
NASCore.C
\*---------------------------------------------------------------------------*/
#ifndef NASCore_H
#define NASCore_H
#include "scalar.H"
#include "string.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class fileFormats::NASCore Declaration
\*---------------------------------------------------------------------------*/
class NASCore
{
public:
// Public Member Functions
//- Do weird things to extract number
static scalar parseNASCoord(const string&);
// Constructors
//- Construct null
NASCore();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2006-2010 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "STARCDCore.H"
#include "ListOps.H"
#include "clock.H"
#include "PackedBoolList.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDCore::STARCDCore()
{}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDCore::readHeader
(
IFstream& is,
const word& signature
)
{
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDCore::readHeader(...)"
)
<< "cannot read " << signature << " " << is.name()
<< abort(FatalError);
}
word header;
label majorVersion;
string line;
is.getLine(line);
IStringStream(line)() >> header;
is.getLine(line);
IStringStream(line)() >> majorVersion;
// add other checks ...
if (header != signature)
{
Info<< "header mismatch " << signature << " " << is.name()
<< endl;
}
return true;
}
void Foam::fileFormats::STARCDCore::writeHeader
(
Ostream& os,
const word& filetype
)
{
os << "PROSTAR_" << filetype << nl
<< 4000
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< endl;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDCore::readPoints
(
IFstream& is,
pointField& points,
labelList& ids
)
{
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDedgeFormat::readPoints(...)"
)
<< "Cannot read file " << is.name()
<< exit(FatalError);
}
readHeader(is, "PROSTAR_VERTEX");
// reuse memory if possible
DynamicList<point> dynPoints(points.xfer());
DynamicList<label> dynPointId(ids.xfer()); // STAR-CD index of points
dynPoints.clear();
dynPointId.clear();
label lineLabel;
while ((is >> lineLabel).good())
{
scalar x, y, z;
is >> x >> y >> z;
dynPoints.append(point(x, y, z));
dynPointId.append(lineLabel);
}
points.transfer(dynPoints);
ids.transfer(dynPointId);
return true;
}
void Foam::fileFormats::STARCDCore::writePoints
(
Ostream& os,
const pointField& pointLst
)
{
writeHeader(os, "VERTEX");
// Set the precision of the points data to 10
os.precision(10);
// force decimal point for Fortran input
os.setf(std::ios::showpoint);
forAll(pointLst, ptI)
{
os
<< ptI + 1 << " "
<< pointLst[ptI].x() << " "
<< pointLst[ptI].y() << " "
<< pointLst[ptI].z() << nl;
}
os.flush();
}
// ************************************************************************* //

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2006-2010 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::STARCDCore
Description
Core routines used when reading/writing pro-STAR vrt/cel/bnd files.
SourceFiles
STARCDCore.C
\*---------------------------------------------------------------------------*/
#ifndef STARCDCore_H
#define STARCDCore_H
#include "IFstream.H"
#include "pointField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class fileFormats::STARCDCore Declaration
\*---------------------------------------------------------------------------*/
class STARCDCore
{
protected:
// Protected Member Functions
//- Read header
static bool readHeader(IFstream&, const word& fileSignature);
//- Write header for fileType (CELL|VERTEX|BOUNDARY)
static void writeHeader(Ostream&, const word& fileType);
protected:
enum cellType
{
starcdFluidType = 1,
starcdSolidType = 2,
starcdBaffleType = 3,
starcdShellType = 4,
starcdLineType = 5,
starcdPointType = 6
};
enum shapeType
{
starcdPoint = 1,
starcdLine = 2,
starcdShell = 3,
starcdHex = 11,
starcdPrism = 12,
starcdTet = 13,
starcdPyr = 14,
starcdPoly = 255
};
public:
// Public Member Functions
//- Read points from a (.vrt) file
// The file format is as follows:
// @verbatim
// Line 1:
// PROSTAR_VERTEX newline
//
// Line 2:
// {version} 0 0 0 0 0 0 0 newline
//
// Body:
// {vertexId} {x} {y} {z} newline
// @endverbatim
static bool readPoints(IFstream&, pointField&, labelList& ids);
//- Write header and points to (.vrt) file
static void writePoints(Ostream&, const pointField&);
// Constructors
//- Construct null
STARCDCore();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //