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

@ -18,6 +18,7 @@ EXE_LIBS = \
-lengine \
-lerrorEstimation \
-lfieldFunctionObjects \
-lfileFormats \
-lfiniteVolume \
-lforces \
-lfvMotionSolvers \

View File

@ -100,10 +100,8 @@ int main(int argc, char *argv[])
meshSubsetDict.lookup("addFaceNeighbours")
);
Switch invertSelection
(
meshSubsetDict.lookup("invertSelection")
);
const bool invertSelection =
meshSubsetDict.lookupOrDefault<bool>("invertSelection", false);
// Mark the cells for the subset
@ -246,7 +244,7 @@ int main(int argc, char *argv[])
// bb of surface
treeBoundBox bb(selectSurf.localPoints());
// Radnom number generator
// Random number generator
Random rndGen(354543);
// search engine
@ -269,14 +267,11 @@ int main(int argc, char *argv[])
indexedOctree<treeDataTriSurface>::volumeType t =
selectTree.getVolumeType(fc);
if (t == indexedOctree<treeDataTriSurface>::INSIDE && !outside)
{
facesToSubset[faceI] = true;
}
else if
if
(
t == indexedOctree<treeDataTriSurface>::OUTSIDE
&& outside
outside
? (t == indexedOctree<treeDataTriSurface>::OUTSIDE)
: (t == indexedOctree<treeDataTriSurface>::INSIDE)
)
{
facesToSubset[faceI] = true;
@ -346,20 +341,11 @@ int main(int argc, char *argv[])
if (invertSelection)
{
Info<< "Inverting selection." << endl;
boolList newFacesToSubset(facesToSubset.size());
forAll(facesToSubset, i)
{
if (facesToSubset[i])
{
newFacesToSubset[i] = false;
}
else
{
newFacesToSubset[i] = true;
}
facesToSubset[i] = facesToSubset[i] ? false : true;
}
facesToSubset.transfer(newFacesToSubset);
}

View File

@ -36,7 +36,7 @@ zone
surface
{
name "sphere.stl";
outside yes;
outside yes;
}
// Extend selection with edge neighbours

View File

@ -22,6 +22,7 @@ wmake libso OpenFOAM
wmake libso lagrangian/basic
wmake libso fileFormats
wmake libso edgeMesh
wmake libso surfMesh
wmake libso triSurface

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude
LIB_LIBS = \
-lfileFormats

View File

@ -29,34 +29,6 @@ License
#include "IStringStream.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// Do weird things to extract a floating point number
Foam::scalar Foam::fileFormats::NASedgeFormat::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)());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::NASedgeFormat::NASedgeFormat

View File

@ -37,6 +37,7 @@ SourceFiles
#define NASedgeFormat_H
#include "edgeMesh.H"
#include "NASCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,7 +52,8 @@ namespace fileFormats
class NASedgeFormat
:
public edgeMesh
public edgeMesh,
public NASCore
{
// Private Member Functions
@ -61,13 +63,6 @@ class NASedgeFormat
//- Disallow default bitwise assignment
void operator=(const NASedgeFormat&);
protected:
// Protected Member Functions
//- Do weird things to extract number
static scalar parseNASCoord(const string&);
public:
// Constructors

View File

@ -59,134 +59,6 @@ inline void Foam::fileFormats::STARCDedgeFormat::writeLines
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::STARCDedgeFormat::readHeader
(
IFstream& is,
const word& signature
)
{
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDedgeFormat::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::STARCDedgeFormat::writeHeader
(
Ostream& os,
const char* filetype
)
{
os << "PROSTAR_" << filetype << nl
<< 4000
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< endl;
}
bool Foam::fileFormats::STARCDedgeFormat::readPoints
(
IFstream& is,
pointField& points,
labelList& ids
)
{
//
// read .vrt file
// ~~~~~~~~~~~~~~
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDedgeFormat::readPoints(...)"
)
<< "Cannot read file " << is.name()
<< exit(FatalError);
}
readHeader(is, "PROSTAR_VERTEX");
DynamicList<point> dynPoints;
DynamicList<label> dynPointId; // STAR-CD index of points
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::STARCDedgeFormat::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();
}
void Foam::fileFormats::STARCDedgeFormat::writeCase
(
Ostream& os,

View File

@ -43,6 +43,8 @@ SourceFiles
#define STARCDedgeFormat_H
#include "edgeMesh.H"
#include "STARCDCore.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
@ -60,7 +62,8 @@ namespace fileFormats
class STARCDedgeFormat
:
public edgeMesh
public edgeMesh,
public STARCDCore
{
// Private Data
@ -90,14 +93,6 @@ protected:
// Protected Member Functions
static bool readHeader(IFstream&, const word&);
static void writeHeader(Ostream&, const char* filetype);
static bool readPoints(IFstream&, pointField&, labelList& ids);
static void writePoints(Ostream&, const pointField&);
static void writeCase
(
Ostream&,

View File

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

View File

View File

@ -24,13 +24,18 @@ License
\*---------------------------------------------------------------------------*/
#include "NASsurfaceFormatCore.H"
#include "NASCore.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Do weird things to extract a floating point number
Foam::scalar Foam::fileFormats::NASsurfaceFormatCore::parseNASCoord
Foam::fileFormats::NASCore::NASCore()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::scalar Foam::fileFormats::NASCore::parseNASCoord
(
const string& s
)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,21 +23,21 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::NASsurfaceFormatCore
Foam::fileFormats::NASCore
Description
Internal class used by the NASsurfaceFormat
Core routines used when reading/writing NASTRAN files.
SourceFiles
NASsurfaceFormatCore.C
NASCore.C
\*---------------------------------------------------------------------------*/
#ifndef NASsurfaceFormatCore_H
#define NASsurfaceFormatCore_H
#ifndef NASCore_H
#define NASCore_H
#include "Ostream.H"
#include "OFstream.H"
#include "scalar.H"
#include "string.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,17 +47,25 @@ namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class NASsurfaceFormatCore Declaration
Class fileFormats::NASCore Declaration
\*---------------------------------------------------------------------------*/
class NASsurfaceFormatCore
class NASCore
{
protected:
public:
// Protected Member Functions
// Public Member Functions
//- Do weird things to extract number
static scalar parseNASCoord(const string&);
// Constructors
//- Construct null
NASCore();
};

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
// ************************************************************************* //

View File

@ -24,7 +24,6 @@ $(surfaceFormats)/ac3d/AC3DsurfaceFormatCore.C
$(surfaceFormats)/ac3d/AC3DsurfaceFormatRunTime.C
$(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C
$(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
$(surfaceFormats)/nas/NASsurfaceFormatCore.C
$(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
$(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
$(surfaceFormats)/off/OFFsurfaceFormatRunTime.C

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude
LIB_LIBS = \
-lfileFormats

View File

@ -47,7 +47,7 @@ SourceFiles
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "NASsurfaceFormatCore.H"
#include "NASCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,7 +64,7 @@ template<class Face>
class NASsurfaceFormat
:
public MeshedSurface<Face>,
public NASsurfaceFormatCore
public NASCore
{
// Private Member Functions

View File

@ -31,63 +31,6 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
(
IFstream& is,
const word& signature
)
{
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDsurfaceFormatCore::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::STARCDsurfaceFormatCore::writeHeader
(
Ostream& os,
const char* filetype
)
{
os << "PROSTAR_" << filetype << nl
<< 4000
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< endl;
}
// parse things like this:
// CTNAME 1 someName
// don't bother with the older comma-delimited format
@ -102,12 +45,12 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
regExp ctnameRE
(
" *CTNA[^ ]*" // keyword - min 4 chars
"[[:space:]]+" // space delimited
"([0-9]+)" // 1: <digits>
"[[:space:]]+" // space delimited
" *CTNA[^ ]*" // keyword - min 4 chars
"[[:space:]]+" // space delimited
"([0-9]+)" // 1: <digits>
"[[:space:]]+" // space delimited
"([^,[:space:]].*)", // 2: <name>
true // ignore case
true // ignore case
);
string line;
@ -132,78 +75,6 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
}
bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints
(
IFstream& is,
pointField& points,
labelList& ids
)
{
//
// read .vrt file
// ~~~~~~~~~~~~~~
if (!is.good())
{
FatalErrorIn
(
"fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
)
<< "Cannot read file " << is.name()
<< exit(FatalError);
}
readHeader(is, "PROSTAR_VERTEX");
DynamicList<point> dynPoints;
// STAR-CD index of points
DynamicList<label> dynPointId;
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::STARCDsurfaceFormatCore::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();
}
void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
(
Ostream& os,
@ -238,4 +109,3 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
// ************************************************************************* //

View File

@ -40,6 +40,7 @@ SourceFiles
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "STARCDCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,21 +54,15 @@ namespace fileFormats
\*---------------------------------------------------------------------------*/
class STARCDsurfaceFormatCore
:
public STARCDCore
{
protected:
// Protected Member Functions
static bool readHeader(IFstream&, const word&);
static void writeHeader(Ostream&, const char* filetype);
static Map<word> readInpCellTable(IFstream&);
static bool readPoints(IFstream&, pointField&, labelList& ids);
static void writePoints(Ostream&, const pointField&);
static void writeCase
(
Ostream&,

View File

@ -1 +1,5 @@
EXE_INC =
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude
LIB_LIBS = \
-lfileFormats