mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Enhance edgeMesh to support more formats.
Read only support:
.bdf, .nas - NASTRAN format. Handles both CBEAM and CROD as lines.
CROD is what Hypermesh happens to output.
Write only support:
.vtk - VTK legacy format in ASCII
Read/write support:
.eMesh - native format, which is simply a list of points, edges
with an additional IOobject header that lets them be moved about
easily to use as a featureEdgeMesh.
.inp - STAR-CD inp/cel/vrt combination
IOobject header)
.obj - Alias waverfront format
Radically simplify surfaceFeatureConvert by using the new edgeMesh
functionality.
This commit is contained in:
@ -21,7 +21,7 @@ surfaceFind
|
|||||||
- Finds nearest vertex and face to given point.
|
- Finds nearest vertex and face to given point.
|
||||||
|
|
||||||
surfaceMeshTriangulate
|
surfaceMeshTriangulate
|
||||||
- Triangulate external facses of mesh and write as surface.
|
- Triangulate external faces of mesh and write as surface.
|
||||||
|
|
||||||
surfacePointMerge
|
surfacePointMerge
|
||||||
- Explicit point merge of surface.
|
- Explicit point merge of surface.
|
||||||
|
|||||||
@ -26,266 +26,85 @@ Application
|
|||||||
surfaceFeatureConvert
|
surfaceFeatureConvert
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Extracts and writes surface features to file
|
Convert between edgeMesh formats
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "featureEdgeMesh.H"
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "IFstream.H"
|
|
||||||
#include "IStringStream.H"
|
#include "edgeMesh.H"
|
||||||
#include "OFstream.H"
|
|
||||||
#include "Map.H"
|
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void readNASEdges
|
|
||||||
(
|
|
||||||
const fileName& inFileName,
|
|
||||||
pointField& allPoints,
|
|
||||||
edgeList& allEdges
|
|
||||||
)
|
|
||||||
{
|
|
||||||
IFstream is(inFileName);
|
|
||||||
|
|
||||||
if (!is.good())
|
|
||||||
{
|
|
||||||
FatalErrorIn("readNASEdges")
|
|
||||||
<< "Cannot read file " << inFileName
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// coordinates of point
|
|
||||||
DynamicList<point> points;
|
|
||||||
// Nastran index of point
|
|
||||||
DynamicList<label> pointIndices;
|
|
||||||
|
|
||||||
// beams
|
|
||||||
DynamicList<edge> edges;
|
|
||||||
DynamicList<label> edgeIndices;
|
|
||||||
|
|
||||||
|
|
||||||
while (is.good())
|
|
||||||
{
|
|
||||||
string line;
|
|
||||||
is.getLine(line);
|
|
||||||
|
|
||||||
if (line.empty() || line[0] == '$')
|
|
||||||
{
|
|
||||||
// Skip empty and comment
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if character 72 is continuation
|
|
||||||
if (line.size() > 72 && line[72] == '+')
|
|
||||||
{
|
|
||||||
line = line.substr(0, 72);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
string buf;
|
|
||||||
is.getLine(buf);
|
|
||||||
|
|
||||||
if (buf.size() > 72 && buf[72] == '+')
|
|
||||||
{
|
|
||||||
line += buf.substr(8, 64);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
line += buf.substr(8, buf.size()-8);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read first word
|
|
||||||
IStringStream lineStream(line);
|
|
||||||
word cmd;
|
|
||||||
lineStream >> cmd;
|
|
||||||
|
|
||||||
if (cmd == "GRID")
|
|
||||||
{
|
|
||||||
label index;
|
|
||||||
lineStream >> index;
|
|
||||||
pointIndices.append(index);
|
|
||||||
|
|
||||||
scalar x = readScalar(IStringStream(line.substr(24, 8))());
|
|
||||||
scalar y = readScalar(IStringStream(line.substr(32, 8))());
|
|
||||||
scalar z = readScalar(IStringStream(line.substr(40, 8))());
|
|
||||||
points.append(point(x, y, z));
|
|
||||||
}
|
|
||||||
else if (cmd == "CBEAM")
|
|
||||||
{
|
|
||||||
// Read shell type since gives patchnames.
|
|
||||||
label index, group, v0, v1;
|
|
||||||
lineStream >> index >> group >> v0 >> v1;
|
|
||||||
|
|
||||||
edgeIndices.append(index);
|
|
||||||
edges.append(edge(v0, v1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
points.shrink();
|
|
||||||
pointIndices.shrink();
|
|
||||||
edges.shrink();
|
|
||||||
edgeIndices.shrink();
|
|
||||||
|
|
||||||
Pout<< "Read from " << inFileName
|
|
||||||
<< " edges:" << edges.size() << " points:" << points.size()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
{
|
|
||||||
// Build inverse mapping (index to point)
|
|
||||||
Map<label> indexToPoint(2*pointIndices.size());
|
|
||||||
forAll(pointIndices, i)
|
|
||||||
{
|
|
||||||
indexToPoint.insert(pointIndices[i], i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Relabel edges
|
|
||||||
forAll(edges, i)
|
|
||||||
{
|
|
||||||
edge& e = edges[i];
|
|
||||||
e[0] = indexToPoint[e[0]];
|
|
||||||
e[1] = indexToPoint[e[1]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allPoints.transfer(points);
|
|
||||||
allEdges.transfer(edges);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void write
|
|
||||||
(
|
|
||||||
const Time& runTime,
|
|
||||||
const fileName& inFileName,
|
|
||||||
const fileName& outFileName,
|
|
||||||
const edgeMesh& eMesh
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (outFileName.ext() == "eMesh")
|
|
||||||
{
|
|
||||||
featureEdgeMesh fem
|
|
||||||
(
|
|
||||||
IOobject
|
|
||||||
(
|
|
||||||
outFileName, // name
|
|
||||||
runTime.constant(), // instance
|
|
||||||
runTime, // registry
|
|
||||||
IOobject::NO_READ,
|
|
||||||
IOobject::AUTO_WRITE,
|
|
||||||
false
|
|
||||||
),
|
|
||||||
eMesh.points(),
|
|
||||||
eMesh.edges()
|
|
||||||
);
|
|
||||||
|
|
||||||
Pout<< "Writing feature edge mesh to " << fem.objectPath()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
fem.write();
|
|
||||||
}
|
|
||||||
else if (outFileName.ext() == "vtk")
|
|
||||||
{
|
|
||||||
OFstream str(outFileName);
|
|
||||||
|
|
||||||
str << "# vtk DataFile Version 2.0" << nl
|
|
||||||
<< "featureEdgeMesh " << inFileName << nl
|
|
||||||
<< "ASCII" << nl
|
|
||||||
<< "DATASET POLYDATA" << nl;
|
|
||||||
|
|
||||||
str << "POINTS " << eMesh.points().size() << " float" << nl;
|
|
||||||
forAll(eMesh.points(), pointI)
|
|
||||||
{
|
|
||||||
const point& pt = eMesh.points()[pointI];
|
|
||||||
|
|
||||||
str << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
str << "LINES " << eMesh.edges().size() << ' '
|
|
||||||
<< 3*eMesh.edges().size() << nl;
|
|
||||||
forAll(eMesh.edges(), edgeI)
|
|
||||||
{
|
|
||||||
const edge& e = eMesh.edges()[edgeI];
|
|
||||||
|
|
||||||
str << "2 " << e[0] << ' ' << e[1] << nl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FatalErrorIn("write")
|
|
||||||
<< "Supported output formats: .eMesh, .vtk"
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Main program:
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
argList::addNote
|
||||||
|
(
|
||||||
|
"Convert between edgeMesh formats"
|
||||||
|
);
|
||||||
argList::noParallel();
|
argList::noParallel();
|
||||||
argList::validArgs.append("input file");
|
argList::validArgs.append("inputFile");
|
||||||
argList::validArgs.append("output file");
|
argList::validArgs.append("outputFile");
|
||||||
# include "setRootCase.H"
|
argList::addOption
|
||||||
# include "createTime.H"
|
|
||||||
|
|
||||||
const fileName inFileName(args.additionalArgs()[0]);
|
|
||||||
const word outFileName(args.additionalArgs()[1]);
|
|
||||||
|
|
||||||
Pout<< "Input features file : " << inFileName << nl
|
|
||||||
<< "Output features file : " << outFileName << nl
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
|
|
||||||
// Read
|
|
||||||
// ~~~~
|
|
||||||
|
|
||||||
if (inFileName.ext() == "nas")
|
|
||||||
{
|
|
||||||
pointField points;
|
|
||||||
edgeList edges;
|
|
||||||
readNASEdges(inFileName, points, edges);
|
|
||||||
|
|
||||||
edgeMesh eMesh(points, edges);
|
|
||||||
|
|
||||||
write(runTime, inFileName, outFileName, eMesh);
|
|
||||||
}
|
|
||||||
else if (inFileName.ext() == "eMesh")
|
|
||||||
{
|
|
||||||
featureEdgeMesh fem
|
|
||||||
(
|
(
|
||||||
IOobject
|
"scale",
|
||||||
(
|
"factor",
|
||||||
inFileName, // name
|
"specify a scaling factor for the points"
|
||||||
runTime.constant(), // instance
|
|
||||||
runTime, // registry
|
|
||||||
IOobject::MUST_READ,
|
|
||||||
IOobject::AUTO_WRITE,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Pout<< "Read from " << inFileName
|
argList args(argc, argv);
|
||||||
<< " edges:" << fem.edges().size()
|
Time runTime(args.rootPath(), args.caseName());
|
||||||
<< " points:" << fem.points().size()
|
const stringList& params = args.additionalArgs();
|
||||||
<< endl;
|
|
||||||
|
|
||||||
write(runTime, inFileName, outFileName, fem);
|
const fileName importName(params[0]);
|
||||||
}
|
const fileName exportName(params[1]);
|
||||||
else
|
|
||||||
|
// disable inplace editing
|
||||||
|
if (importName == exportName)
|
||||||
{
|
{
|
||||||
FatalErrorIn(args.executable())
|
FatalErrorIn(args.executable())
|
||||||
<< "Can only handle NASTRAN data formats (.nas extension)."
|
<< "Output file " << exportName << " would overwrite input file."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pout<< "End\n" << endl;
|
// check that reading/writing is supported
|
||||||
|
if
|
||||||
|
(
|
||||||
|
!edgeMesh::canReadType(importName.ext(), true)
|
||||||
|
|| !edgeMesh::canWriteType(exportName.ext(), true)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
edgeMesh mesh(importName);
|
||||||
|
|
||||||
|
Info<< "\nRead edgeMesh " << importName << nl;
|
||||||
|
mesh.writeStats(Info);
|
||||||
|
Info<< nl
|
||||||
|
<< "\nwriting " << exportName;
|
||||||
|
|
||||||
|
scalar scaleFactor = 0;
|
||||||
|
if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||||
|
{
|
||||||
|
Info<< " with scaling " << scaleFactor << endl;
|
||||||
|
mesh.scalePoints(scaleFactor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< " without scaling" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh.write(exportName);
|
||||||
|
mesh.writeStats(Info);
|
||||||
|
Info<< endl;
|
||||||
|
|
||||||
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,26 @@
|
|||||||
edgeMesh.C
|
edgeMesh.C
|
||||||
edgeMeshIO.C
|
edgeMeshIO.C
|
||||||
featureEdgeMesh.C
|
edgeMeshNew.C
|
||||||
|
|
||||||
|
edgeFormats = edgeFormats
|
||||||
|
$(edgeFormats)/edgeFormatsCore.C
|
||||||
|
|
||||||
|
$(edgeFormats)/emesh/EMESHedgeFormat.C
|
||||||
|
$(edgeFormats)/emesh/EMESHedgeFormatRunTime.C
|
||||||
|
|
||||||
|
$(edgeFormats)/nas/NASedgeFormat.C
|
||||||
|
$(edgeFormats)/nas/NASedgeFormatRunTime.C
|
||||||
|
|
||||||
|
$(edgeFormats)/obj/OBJedgeFormat.C
|
||||||
|
$(edgeFormats)/obj/OBJedgeFormatRunTime.C
|
||||||
|
|
||||||
|
$(edgeFormats)/starcd/STARCDedgeFormat.C
|
||||||
|
$(edgeFormats)/starcd/STARCDedgeFormatRunTime.C
|
||||||
|
|
||||||
|
$(edgeFormats)/vtk/VTKedgeFormat.C
|
||||||
|
$(edgeFormats)/vtk/VTKedgeFormatRunTime.C
|
||||||
|
|
||||||
|
featureEdgeMesh/featureEdgeMesh.C
|
||||||
|
|
||||||
|
|
||||||
LIB = $(FOAM_LIBBIN)/libedgeMesh
|
LIB = $(FOAM_LIBBIN)/libedgeMesh
|
||||||
|
|||||||
200
src/edgeMesh/edgeFormats/edgeFormatsCore.C
Normal file
200
src/edgeMesh/edgeFormats/edgeFormatsCore.C
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "edgeFormatsCore.H"
|
||||||
|
|
||||||
|
#include "Time.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::word Foam::fileFormats::edgeFormatsCore::nativeExt("eMesh");
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::string Foam::fileFormats::edgeFormatsCore::getLineNoComment
|
||||||
|
(
|
||||||
|
IFstream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
is.getLine(line);
|
||||||
|
}
|
||||||
|
while ((line.empty() || line[0] == '#') && is.good());
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
Foam::fileName Foam::fileFormats::edgeFormatsCore::localMeshFileName
|
||||||
|
(
|
||||||
|
const word& meshName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const word name(meshName.size() ? meshName : surfaceRegistry::defaultName);
|
||||||
|
|
||||||
|
return fileName
|
||||||
|
(
|
||||||
|
surfaceRegistry::prefix/name/surfMesh::meshSubDir
|
||||||
|
/ name + "." + nativeExt
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::fileFormats::edgeFormatsCore::findMeshInstance
|
||||||
|
(
|
||||||
|
const Time& t,
|
||||||
|
const word& meshName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fileName localName = localMeshFileName(meshName);
|
||||||
|
|
||||||
|
// Search back through the time directories list to find the time
|
||||||
|
// closest to and lower than current time
|
||||||
|
|
||||||
|
instantList ts = t.times();
|
||||||
|
label instanceI;
|
||||||
|
|
||||||
|
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
||||||
|
{
|
||||||
|
if (ts[instanceI].value() <= t.timeOutputValue())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Noting that the current directory has already been searched
|
||||||
|
// for mesh data, start searching from the previously stored time directory
|
||||||
|
|
||||||
|
if (instanceI >= 0)
|
||||||
|
{
|
||||||
|
for (label i = instanceI; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (isFile(t.path()/ts[i].name()/localName))
|
||||||
|
{
|
||||||
|
return ts[i].name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "constant";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::fileFormats::edgeFormatsCore::findMeshFile
|
||||||
|
(
|
||||||
|
const Time& t,
|
||||||
|
const word& meshName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fileName localName = localMeshFileName(meshName);
|
||||||
|
|
||||||
|
// Search back through the time directories list to find the time
|
||||||
|
// closest to and lower than current time
|
||||||
|
|
||||||
|
instantList ts = t.times();
|
||||||
|
label instanceI;
|
||||||
|
|
||||||
|
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
||||||
|
{
|
||||||
|
if (ts[instanceI].value() <= t.timeOutputValue())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Noting that the current directory has already been searched
|
||||||
|
// for mesh data, start searching from the previously stored time directory
|
||||||
|
|
||||||
|
if (instanceI >= 0)
|
||||||
|
{
|
||||||
|
for (label i = instanceI; i >= 0; --i)
|
||||||
|
{
|
||||||
|
fileName testName(t.path()/ts[i].name()/localName);
|
||||||
|
|
||||||
|
if (isFile(testName))
|
||||||
|
{
|
||||||
|
return testName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to "constant"
|
||||||
|
return t.path()/"constant"/localName;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::fileFormats::edgeFormatsCore::checkSupport
|
||||||
|
(
|
||||||
|
const wordHashSet& available,
|
||||||
|
const word& ext,
|
||||||
|
const bool verbose,
|
||||||
|
const word& functionName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (available.found(ext))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (verbose)
|
||||||
|
{
|
||||||
|
wordList known = available.sortedToc();
|
||||||
|
|
||||||
|
Info<<"Unknown file extension for " << functionName
|
||||||
|
<< " : " << ext << nl
|
||||||
|
<<"Valid types: (";
|
||||||
|
// compact output:
|
||||||
|
forAll(known, i)
|
||||||
|
{
|
||||||
|
Info<<" " << known[i];
|
||||||
|
}
|
||||||
|
Info<<" )" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::edgeFormatsCore::edgeFormatsCore()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::edgeFormatsCore::~edgeFormatsCore()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
118
src/edgeMesh/edgeFormats/edgeFormatsCore.H
Normal file
118
src/edgeMesh/edgeFormats/edgeFormatsCore.H
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::edgeFormatsCore
|
||||||
|
|
||||||
|
Description
|
||||||
|
A collection of helper functions for reading/writing edge formats.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
edgeFormatsCore.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef edgeFormatsCore_H
|
||||||
|
#define edgeFormatsCore_H
|
||||||
|
|
||||||
|
#include "Map.H"
|
||||||
|
#include "HashSet.H"
|
||||||
|
#include "labelList.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
// Forward declaration of friend functions and operators
|
||||||
|
|
||||||
|
class IFstream;
|
||||||
|
class Time;
|
||||||
|
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class edgeFormatsCore Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class edgeFormatsCore
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//- Read non-comment line
|
||||||
|
static string getLineNoComment(IFstream&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Static Data
|
||||||
|
|
||||||
|
//- The file extension corresponding to 'native' edge format
|
||||||
|
// Normally "eMesh" (edge-mesh)
|
||||||
|
static word nativeExt;
|
||||||
|
|
||||||
|
// Static Member Functions
|
||||||
|
|
||||||
|
static bool checkSupport
|
||||||
|
(
|
||||||
|
const wordHashSet& available,
|
||||||
|
const word& ext,
|
||||||
|
const bool verbose,
|
||||||
|
const word& functionName
|
||||||
|
);
|
||||||
|
|
||||||
|
// //- Return the local file name (within time directory)
|
||||||
|
// // NEEDS FIXING
|
||||||
|
// static fileName localMeshFileName(const word& edgeName="");
|
||||||
|
//
|
||||||
|
// //- Find instance with edgeName
|
||||||
|
// // NEEDS FIXING
|
||||||
|
// static fileName findMeshInstance(const Time&, const word& edgeName="");
|
||||||
|
//
|
||||||
|
// //- Find mesh file with edgeName
|
||||||
|
// // NEEDS FIXING
|
||||||
|
// static fileName findMeshFile(const Time&, const word& edgeName="");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
edgeFormatsCore();
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~edgeFormatsCore();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
195
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
Normal file
195
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "EMESHedgeFormat.H"
|
||||||
|
#include "IOobject.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#include "clock.H"
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::EMESHedgeFormat::EMESHedgeFormat
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
read(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::fileFormats::EMESHedgeFormat::read
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
IFstream is(filename);
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::EMESHedgeFormat::read(const fileName&)"
|
||||||
|
)
|
||||||
|
<< "Cannot read file " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return read(is, this->storedPoints(), this->storedEdges());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::fileFormats::EMESHedgeFormat::read
|
||||||
|
(
|
||||||
|
Istream& is,
|
||||||
|
pointField& pointLst,
|
||||||
|
edgeList& edgeLst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::EMESHedgeFormat::read"
|
||||||
|
"(Istream&, pointField&, edgeList&)"
|
||||||
|
)
|
||||||
|
<< "read error "
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
token firstToken(is);
|
||||||
|
|
||||||
|
// swallow IOobject header
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalIOErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::EMESHedgeFormat::read"
|
||||||
|
"(Istream&, pointField&, edgeList&)",
|
||||||
|
is
|
||||||
|
)
|
||||||
|
<< "First token could not be read" << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (firstToken.isWord() && firstToken.wordToken() == "FoamFile")
|
||||||
|
{
|
||||||
|
// read and discard
|
||||||
|
dictionary headerDict(is);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
is.putBack(firstToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read points:
|
||||||
|
is >> pointLst;
|
||||||
|
|
||||||
|
// read edges:
|
||||||
|
is >> edgeLst;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream&
|
||||||
|
Foam::fileFormats::EMESHedgeFormat::write
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const pointField& pointLst,
|
||||||
|
const edgeList& edgeLst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!os.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::EMESHedgeFormat::write"
|
||||||
|
"(Ostream&, const fileName&, const edgeMesh&)"
|
||||||
|
)
|
||||||
|
<< "bad output stream " << os.name()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "\n// points:" << nl << pointLst << nl
|
||||||
|
<< "\n// edges:" << nl << edgeLst << nl;
|
||||||
|
|
||||||
|
IOobject::writeDivider(os);
|
||||||
|
|
||||||
|
// Check state of Ostream
|
||||||
|
os.check
|
||||||
|
(
|
||||||
|
"EMESHedgeFormat::write"
|
||||||
|
"(Ostream&, const pointField&, const edgeList&)"
|
||||||
|
);
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::fileFormats::EMESHedgeFormat::write
|
||||||
|
(
|
||||||
|
const fileName& filename,
|
||||||
|
const edgeMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
OFstream os(filename);
|
||||||
|
if (!os.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::EMESHedgeFormat::write"
|
||||||
|
"(const fileName&, const edgeMesh&)"
|
||||||
|
)
|
||||||
|
<< "Cannot open file for writing " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// just emit some information until we get a nicer IOobject
|
||||||
|
IOobject::writeBanner(os)
|
||||||
|
<< "FoamFile\n{\n"
|
||||||
|
<< " version " << os.version() << ";\n"
|
||||||
|
<< " format " << os.format() << ";\n"
|
||||||
|
<< " class " << "featureEdgeMesh" << ";\n"
|
||||||
|
<< " note " << "written " + clock::dateTime() << nl
|
||||||
|
<< " object " << filename.name() << ";\n"
|
||||||
|
<< "}" << nl;
|
||||||
|
|
||||||
|
IOobject::writeDivider(os);
|
||||||
|
|
||||||
|
write(os, mesh.points(), mesh.edges());
|
||||||
|
|
||||||
|
// Check state of Ostream
|
||||||
|
os.check("EMESHedgeFormat::write(Ostream&)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
148
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.H
Normal file
148
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.H
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::EMESHedgeFormat
|
||||||
|
|
||||||
|
Description
|
||||||
|
Provide a means of reading/writing the single-file OpenFOAM edge format.
|
||||||
|
|
||||||
|
Note
|
||||||
|
This class provides more methods than the regular edge format interface.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
EMESHedgeFormat.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef EMESHedgeFormat_H
|
||||||
|
#define EMESHedgeFormat_H
|
||||||
|
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
#include "Ostream.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class EMESHedgeFormat Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class EMESHedgeFormat
|
||||||
|
:
|
||||||
|
public edgeMesh
|
||||||
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
EMESHedgeFormat(const EMESHedgeFormat&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const EMESHedgeFormat&);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Write header information
|
||||||
|
static void writeHeader
|
||||||
|
(
|
||||||
|
Ostream&,
|
||||||
|
const pointField&,
|
||||||
|
const edgeList&
|
||||||
|
);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from file name
|
||||||
|
EMESHedgeFormat(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Read file and return edgeMesh
|
||||||
|
static autoPtr<edgeMesh> New(const fileName& name)
|
||||||
|
{
|
||||||
|
return autoPtr<edgeMesh>
|
||||||
|
(
|
||||||
|
new EMESHedgeFormat(name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~EMESHedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Read edgeMesh components from stream
|
||||||
|
static bool read
|
||||||
|
(
|
||||||
|
Istream&,
|
||||||
|
pointField&,
|
||||||
|
edgeList&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write edgeMesh components to stream
|
||||||
|
static Ostream& write
|
||||||
|
(
|
||||||
|
Ostream&,
|
||||||
|
const pointField&,
|
||||||
|
const edgeList&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write edgeMesh with a mimicked IOobject header
|
||||||
|
static void write(const fileName&, const edgeMesh&);
|
||||||
|
|
||||||
|
//- Read from file
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
|
||||||
|
//- Write object
|
||||||
|
virtual void write(const fileName& name) const
|
||||||
|
{
|
||||||
|
write(name, *this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
61
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/emesh/EMESHedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "EMESHedgeFormat.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
// read edgeMesh
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
EMESHedgeFormat,
|
||||||
|
fileExtension,
|
||||||
|
eMesh
|
||||||
|
);
|
||||||
|
|
||||||
|
// write edgeMesh
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
EMESHedgeFormat,
|
||||||
|
write,
|
||||||
|
fileExtension,
|
||||||
|
eMesh
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
260
src/edgeMesh/edgeFormats/nas/NASedgeFormat.C
Normal file
260
src/edgeMesh/edgeFormats/nas/NASedgeFormat.C
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "NASedgeFormat.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#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
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
read(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::fileFormats::NASedgeFormat::read
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
IFstream is(filename);
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::NASedgeFormat::read(const fileName&)"
|
||||||
|
)
|
||||||
|
<< "Cannot read file " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicList<point> dynPoints;
|
||||||
|
DynamicList<edge> dynEdges;
|
||||||
|
DynamicList<label> pointId; // Nastran index of points
|
||||||
|
|
||||||
|
while (is.good())
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
is.getLine(line);
|
||||||
|
|
||||||
|
// Skip empty or comment
|
||||||
|
if (line.empty() || line[0] == '$')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if character 72 is continuation
|
||||||
|
if (line.size() > 72 && line[72] == '+')
|
||||||
|
{
|
||||||
|
line = line.substr(0, 72);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
string buf;
|
||||||
|
is.getLine(buf);
|
||||||
|
|
||||||
|
if (buf.size() > 72 && buf[72] == '+')
|
||||||
|
{
|
||||||
|
line += buf.substr(8, 64);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line += buf.substr(8, buf.size()-8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Read first word
|
||||||
|
IStringStream lineStream(line);
|
||||||
|
word cmd;
|
||||||
|
lineStream >> cmd;
|
||||||
|
|
||||||
|
if (cmd == "CBEAM" || cmd == "CROD")
|
||||||
|
{
|
||||||
|
edge e;
|
||||||
|
|
||||||
|
// label groupId = readLabel(IStringStream(line.substr(16,8))());
|
||||||
|
e[0] = readLabel(IStringStream(line.substr(24,8))());
|
||||||
|
e[1] = readLabel(IStringStream(line.substr(32,8))());
|
||||||
|
|
||||||
|
// discard groupID
|
||||||
|
dynEdges.append(e);
|
||||||
|
}
|
||||||
|
else if (cmd == "GRID")
|
||||||
|
{
|
||||||
|
label index = readLabel(IStringStream(line.substr(8,8))());
|
||||||
|
scalar x = parseNASCoord(line.substr(24, 8));
|
||||||
|
scalar y = parseNASCoord(line.substr(32, 8));
|
||||||
|
scalar z = parseNASCoord(line.substr(40, 8));
|
||||||
|
|
||||||
|
pointId.append(index);
|
||||||
|
dynPoints.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(IStringStream(line.substr(8,16))());
|
||||||
|
scalar x = parseNASCoord(line.substr(40, 16));
|
||||||
|
scalar y = parseNASCoord(line.substr(56, 16));
|
||||||
|
|
||||||
|
is.getLine(line);
|
||||||
|
if (line[0] != '*')
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::NASedgeFormat::read(const fileName&)"
|
||||||
|
)
|
||||||
|
<< "Expected continuation symbol '*' when reading GRID*"
|
||||||
|
<< " (double precision coordinate) format" << nl
|
||||||
|
<< "Read:" << line << nl
|
||||||
|
<< "File:" << is.name() << " line:" << is.lineNumber()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
scalar z = parseNASCoord(line.substr(8, 16));
|
||||||
|
|
||||||
|
pointId.append(index);
|
||||||
|
dynPoints.append(point(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// transfer to normal lists
|
||||||
|
storedPoints().transfer(dynPoints);
|
||||||
|
|
||||||
|
pointId.shrink();
|
||||||
|
dynEdges.shrink();
|
||||||
|
|
||||||
|
// Build inverse mapping (NASTRAN pointId -> index)
|
||||||
|
Map<label> mapPointId(2*pointId.size());
|
||||||
|
forAll(pointId, i)
|
||||||
|
{
|
||||||
|
mapPointId.insert(pointId[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// note which points were really used and which can be culled
|
||||||
|
PackedBoolList usedPoints(points().size());
|
||||||
|
|
||||||
|
|
||||||
|
// Pass1: relabel edges
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~
|
||||||
|
forAll(dynEdges, i)
|
||||||
|
{
|
||||||
|
edge& e = dynEdges[i];
|
||||||
|
e[0] = mapPointId[e[0]];
|
||||||
|
e[1] = mapPointId[e[1]];
|
||||||
|
|
||||||
|
usedPoints.set(e[0]);
|
||||||
|
usedPoints.set(e[1]);
|
||||||
|
}
|
||||||
|
pointId.clearStorage();
|
||||||
|
mapPointId.clear();
|
||||||
|
|
||||||
|
// not all the points were used, cull them accordingly
|
||||||
|
if (unsigned(points().size()) != usedPoints.count())
|
||||||
|
{
|
||||||
|
label nUsed = 0;
|
||||||
|
|
||||||
|
pointField& pts = storedPoints();
|
||||||
|
forAll(pts, pointI)
|
||||||
|
{
|
||||||
|
if (usedPoints.get(pointI))
|
||||||
|
{
|
||||||
|
if (nUsed != pointI)
|
||||||
|
{
|
||||||
|
pts[nUsed] = pts[pointI];
|
||||||
|
}
|
||||||
|
|
||||||
|
// map prev -> new id
|
||||||
|
mapPointId[pointI] = nUsed;
|
||||||
|
|
||||||
|
++nUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pts.setSize(nUsed);
|
||||||
|
|
||||||
|
// renumber edge vertices
|
||||||
|
forAll(dynEdges, edgeI)
|
||||||
|
{
|
||||||
|
edge& e = dynEdges[edgeI];
|
||||||
|
|
||||||
|
e[0] = mapPointId[e[0]];
|
||||||
|
e[1] = mapPointId[e[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// transfer to normal lists
|
||||||
|
storedEdges().transfer(dynEdges);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
113
src/edgeMesh/edgeFormats/nas/NASedgeFormat.H
Normal file
113
src/edgeMesh/edgeFormats/nas/NASedgeFormat.H
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::NASedgeFormat
|
||||||
|
|
||||||
|
Description
|
||||||
|
Nastran edge reader.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
NASedgeFormat.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef NASedgeFormat_H
|
||||||
|
#define NASedgeFormat_H
|
||||||
|
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class NASedgeFormat Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class NASedgeFormat
|
||||||
|
:
|
||||||
|
public edgeMesh
|
||||||
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
NASedgeFormat(const 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
|
||||||
|
|
||||||
|
//- Construct from file name
|
||||||
|
NASedgeFormat(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Read file and return edge mesh
|
||||||
|
static autoPtr<edgeMesh> New(const fileName& name)
|
||||||
|
{
|
||||||
|
return autoPtr<edgeMesh>
|
||||||
|
(
|
||||||
|
new NASedgeFormat(name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
|
||||||
|
virtual ~NASedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Read from a file
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
60
src/edgeMesh/edgeFormats/nas/NASedgeFormatRunTime.C
Normal file
60
src/edgeMesh/edgeFormats/nas/NASedgeFormatRunTime.C
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "NASedgeFormat.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
// read edgeMesh - .bdf (Bulk Data Format)
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
NASedgeFormat,
|
||||||
|
fileExtension,
|
||||||
|
bdf
|
||||||
|
);
|
||||||
|
|
||||||
|
// read edgeMesh - .nas (Nastran Data Format)
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
NASedgeFormat,
|
||||||
|
fileExtension,
|
||||||
|
nas
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
245
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.C
Normal file
245
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.C
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "OBJedgeFormat.H"
|
||||||
|
#include "clock.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#include "IStringStream.H"
|
||||||
|
#include "Ostream.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
#include "ListOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::OBJedgeFormat::OBJedgeFormat
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
read(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::fileFormats::OBJedgeFormat::read
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
IFstream is(filename);
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::OBJedgeFormat::read(const fileName&)"
|
||||||
|
)
|
||||||
|
<< "Cannot read file " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicList<point> dynPoints;
|
||||||
|
DynamicList<edge> dynEdges;
|
||||||
|
DynamicList<label> dynUsedPoints;
|
||||||
|
|
||||||
|
while (is.good())
|
||||||
|
{
|
||||||
|
string line = this->getLineNoComment(is);
|
||||||
|
|
||||||
|
// handle continuations
|
||||||
|
if (line[line.size()-1] == '\\')
|
||||||
|
{
|
||||||
|
line.substr(0, line.size()-1);
|
||||||
|
line += this->getLineNoComment(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read first word
|
||||||
|
IStringStream lineStream(line);
|
||||||
|
word cmd;
|
||||||
|
lineStream >> cmd;
|
||||||
|
|
||||||
|
if (cmd == "v")
|
||||||
|
{
|
||||||
|
scalar x, y, z;
|
||||||
|
lineStream >> x >> y >> z;
|
||||||
|
|
||||||
|
dynPoints.append(point(x, y, z));
|
||||||
|
dynUsedPoints.append(-1);
|
||||||
|
}
|
||||||
|
else if (cmd == "l")
|
||||||
|
{
|
||||||
|
edge edgeRead;
|
||||||
|
|
||||||
|
// Assume 'l' is followed by space.
|
||||||
|
string::size_type endNum = 1;
|
||||||
|
|
||||||
|
int nVerts = 0;
|
||||||
|
for (int count = 0; count < 2; ++count)
|
||||||
|
{
|
||||||
|
string::size_type startNum =
|
||||||
|
line.find_first_not_of(' ', 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
edgeRead[nVerts++] = (vertI - 1); // change to zero-offset
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nVerts >= 2)
|
||||||
|
{
|
||||||
|
dynUsedPoints[edgeRead[0]] = edgeRead[0];
|
||||||
|
dynUsedPoints[edgeRead[1]] = edgeRead[1];
|
||||||
|
|
||||||
|
dynEdges.append(edgeRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cull unused points
|
||||||
|
label nUsed = 0;
|
||||||
|
|
||||||
|
forAll(dynPoints, pointI)
|
||||||
|
{
|
||||||
|
if (dynUsedPoints[pointI] >= 0)
|
||||||
|
{
|
||||||
|
if (nUsed != pointI)
|
||||||
|
{
|
||||||
|
dynPoints[nUsed] = dynPoints[pointI];
|
||||||
|
dynUsedPoints[pointI] = nUsed; // new position
|
||||||
|
}
|
||||||
|
++nUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dynPoints.setSize(nUsed);
|
||||||
|
|
||||||
|
// transfer to normal lists
|
||||||
|
storedPoints().transfer(dynPoints);
|
||||||
|
|
||||||
|
// renumber edge vertices
|
||||||
|
if (nUsed != dynUsedPoints.size())
|
||||||
|
{
|
||||||
|
forAll(dynEdges, edgeI)
|
||||||
|
{
|
||||||
|
edge& e = dynEdges[edgeI];
|
||||||
|
|
||||||
|
e[0] = dynUsedPoints[e[0]];
|
||||||
|
e[1] = dynUsedPoints[e[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storedEdges().transfer(dynEdges);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::fileFormats::OBJedgeFormat::write
|
||||||
|
(
|
||||||
|
const fileName& filename,
|
||||||
|
const edgeMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const pointField& pointLst = mesh.points();
|
||||||
|
const edgeList& edgeLst = mesh.edges();
|
||||||
|
|
||||||
|
OFstream os(filename);
|
||||||
|
if (!os.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::OBJedgeFormat::write"
|
||||||
|
"(const fileName&, const edgeMesh&)"
|
||||||
|
)
|
||||||
|
<< "Cannot open file for writing " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
|
||||||
|
<< "o " << os.name().lessExt().name() << nl
|
||||||
|
<< nl
|
||||||
|
<< "# points : " << pointLst.size() << nl
|
||||||
|
<< "# lines : " << edgeLst.size() << nl;
|
||||||
|
|
||||||
|
os << nl
|
||||||
|
<< "# <points count=\"" << pointLst.size() << "\">" << nl;
|
||||||
|
|
||||||
|
// Write vertex coords
|
||||||
|
forAll(pointLst, ptI)
|
||||||
|
{
|
||||||
|
const point& p = pointLst[ptI];
|
||||||
|
|
||||||
|
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "# </points>" << nl
|
||||||
|
<< nl
|
||||||
|
<< "# <edges count=\"" << edgeLst.size() << "\">" << endl;
|
||||||
|
|
||||||
|
// Write line connectivity
|
||||||
|
forAll(edgeLst, edgeI)
|
||||||
|
{
|
||||||
|
const edge& e = edgeLst[edgeI];
|
||||||
|
|
||||||
|
os << "l " << (e[0] + 1) << " " << (e[1] + 1) << nl;
|
||||||
|
}
|
||||||
|
os << "# </edges>" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
121
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.H
Normal file
121
src/edgeMesh/edgeFormats/obj/OBJedgeFormat.H
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::OBJedgeFormat
|
||||||
|
|
||||||
|
Description
|
||||||
|
Provide a means of reading/writing Alias/Wavefront OBJ format.
|
||||||
|
|
||||||
|
Does not handle negative vertex indices.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
OBJedgeFormat.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef OBJedgeFormat_H
|
||||||
|
#define OBJedgeFormat_H
|
||||||
|
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#include "Ostream.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class OBJedgeFormat Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class OBJedgeFormat
|
||||||
|
:
|
||||||
|
public edgeMesh
|
||||||
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
OBJedgeFormat(const OBJedgeFormat&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const OBJedgeFormat&);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from file name
|
||||||
|
OBJedgeFormat(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Read file and return surface
|
||||||
|
static autoPtr<edgeMesh> New(const fileName& name)
|
||||||
|
{
|
||||||
|
return autoPtr<edgeMesh>
|
||||||
|
(
|
||||||
|
new OBJedgeFormat(name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
|
||||||
|
virtual ~OBJedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Write surface mesh components by proxy
|
||||||
|
static void write(const fileName&, const edgeMesh&);
|
||||||
|
|
||||||
|
//- Read from file
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
|
||||||
|
//- Write object file
|
||||||
|
virtual void write(const fileName& name) const
|
||||||
|
{
|
||||||
|
write(name, *this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
61
src/edgeMesh/edgeFormats/obj/OBJedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/obj/OBJedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "OBJedgeFormat.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
// read edgeMesh
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
OBJedgeFormat,
|
||||||
|
fileExtension,
|
||||||
|
obj
|
||||||
|
);
|
||||||
|
|
||||||
|
// write edgeMesh
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
OBJedgeFormat,
|
||||||
|
write,
|
||||||
|
fileExtension,
|
||||||
|
obj
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
387
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C
Normal file
387
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "STARCDedgeFormat.H"
|
||||||
|
#include "ListOps.H"
|
||||||
|
#include "clock.H"
|
||||||
|
#include "PackedBoolList.H"
|
||||||
|
#include "IStringStream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline void Foam::fileFormats::STARCDedgeFormat::writeLines
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const edgeList& edges
|
||||||
|
)
|
||||||
|
{
|
||||||
|
writeHeader(os, "CELL");
|
||||||
|
|
||||||
|
forAll(edges, edgeI)
|
||||||
|
{
|
||||||
|
const edge& e = edges[edgeI];
|
||||||
|
const label cellId = edgeI + 1;
|
||||||
|
|
||||||
|
os << cellId // includes 1 offset
|
||||||
|
<< ' ' << starcdLineShape_ // 2(line) shape
|
||||||
|
<< ' ' << e.size()
|
||||||
|
<< ' ' << 401 // arbitrary value
|
||||||
|
<< ' ' << starcdLineType_; // 5(line)
|
||||||
|
|
||||||
|
os << nl << " " << cellId << " "
|
||||||
|
<< (e[0]+1) << " " << (e[1]+1) << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * 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,
|
||||||
|
const pointField& pointLst,
|
||||||
|
const label nEdges
|
||||||
|
)
|
||||||
|
{
|
||||||
|
word caseName = os.name().lessExt().name();
|
||||||
|
|
||||||
|
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
|
||||||
|
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
|
||||||
|
<< "! case " << caseName << nl
|
||||||
|
<< "! ------------------------------" << nl;
|
||||||
|
|
||||||
|
// forAll(zoneLst, zoneI)
|
||||||
|
// {
|
||||||
|
// os << "ctable " << zoneI + 1 << " line" << nl
|
||||||
|
// << "ctname " << zoneI + 1 << " "
|
||||||
|
// << zoneLst[zoneI].name() << nl;
|
||||||
|
// }
|
||||||
|
|
||||||
|
os << "! ------------------------------" << nl
|
||||||
|
<< "*set icvo mxv - 1" << nl
|
||||||
|
<< "vread " << caseName << ".vrt icvo,,,coded" << nl
|
||||||
|
<< "cread " << caseName << ".cel icvo,,,add,coded" << nl
|
||||||
|
<< "*set icvo" << nl
|
||||||
|
<< "! end" << nl;
|
||||||
|
|
||||||
|
os.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::STARCDedgeFormat::STARCDedgeFormat
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
read(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::fileFormats::STARCDedgeFormat::read
|
||||||
|
(
|
||||||
|
const fileName& filename
|
||||||
|
)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
|
||||||
|
fileName baseName = filename.lessExt();
|
||||||
|
|
||||||
|
// STAR-CD index of points
|
||||||
|
List<label> pointId;
|
||||||
|
|
||||||
|
// read points from .vrt file
|
||||||
|
readPoints
|
||||||
|
(
|
||||||
|
IFstream(baseName + ".vrt")(),
|
||||||
|
storedPoints(),
|
||||||
|
pointId
|
||||||
|
);
|
||||||
|
|
||||||
|
// Build inverse mapping (STAR-CD pointId -> index)
|
||||||
|
Map<label> mapPointId(2*pointId.size());
|
||||||
|
forAll(pointId, i)
|
||||||
|
{
|
||||||
|
mapPointId.insert(pointId[i], i);
|
||||||
|
}
|
||||||
|
pointId.clear();
|
||||||
|
|
||||||
|
// note which points were really used and which can be culled
|
||||||
|
PackedBoolList usedPoints(points().size());
|
||||||
|
|
||||||
|
//
|
||||||
|
// read .cel file
|
||||||
|
// ~~~~~~~~~~~~~~
|
||||||
|
IFstream is(baseName + ".cel");
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::STARCDedgeFormat::read(const fileName&)"
|
||||||
|
)
|
||||||
|
<< "Cannot read file " << is.name()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
readHeader(is, "PROSTAR_CELL");
|
||||||
|
|
||||||
|
DynamicList<edge> dynEdges;
|
||||||
|
|
||||||
|
label lineLabel, shapeId, nLabels, cellTableId, typeId;
|
||||||
|
DynamicList<label> vertexLabels(64);
|
||||||
|
|
||||||
|
while ((is >> lineLabel).good())
|
||||||
|
{
|
||||||
|
is >> shapeId >> nLabels >> cellTableId >> typeId;
|
||||||
|
|
||||||
|
vertexLabels.clear();
|
||||||
|
vertexLabels.reserve(nLabels);
|
||||||
|
|
||||||
|
// read indices - max 8 per line
|
||||||
|
for (label i = 0; i < nLabels; ++i)
|
||||||
|
{
|
||||||
|
label vrtId;
|
||||||
|
if ((i % 8) == 0)
|
||||||
|
{
|
||||||
|
is >> lineLabel;
|
||||||
|
}
|
||||||
|
is >> vrtId;
|
||||||
|
|
||||||
|
// convert original vertex id to point label
|
||||||
|
vertexLabels.append(mapPointId[vrtId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeId == starcdLineType_)
|
||||||
|
{
|
||||||
|
if (vertexLabels.size() >= 2)
|
||||||
|
{
|
||||||
|
dynEdges.append(edge(vertexLabels[0], vertexLabels[1]));
|
||||||
|
|
||||||
|
usedPoints.set(vertexLabels[0]);
|
||||||
|
usedPoints.set(vertexLabels[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mapPointId.clear();
|
||||||
|
|
||||||
|
// not all the points were used, cull them accordingly
|
||||||
|
if (unsigned(points().size()) != usedPoints.count())
|
||||||
|
{
|
||||||
|
label nUsed = 0;
|
||||||
|
|
||||||
|
pointField& pts = storedPoints();
|
||||||
|
forAll(pts, pointI)
|
||||||
|
{
|
||||||
|
if (usedPoints.get(pointI))
|
||||||
|
{
|
||||||
|
if (nUsed != pointI)
|
||||||
|
{
|
||||||
|
pts[nUsed] = pts[pointI];
|
||||||
|
}
|
||||||
|
|
||||||
|
// map prev -> new id
|
||||||
|
mapPointId.set(pointI, nUsed);
|
||||||
|
|
||||||
|
++nUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pts.setSize(nUsed);
|
||||||
|
|
||||||
|
// renumber edge vertices
|
||||||
|
forAll(dynEdges, edgeI)
|
||||||
|
{
|
||||||
|
edge& e = dynEdges[edgeI];
|
||||||
|
|
||||||
|
e[0] = mapPointId[e[0]];
|
||||||
|
e[1] = mapPointId[e[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
storedEdges().transfer(dynEdges);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::fileFormats::STARCDedgeFormat::write
|
||||||
|
(
|
||||||
|
const fileName& filename,
|
||||||
|
const edgeMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const pointField& pointLst = mesh.points();
|
||||||
|
const edgeList& edgeLst = mesh.edges();
|
||||||
|
|
||||||
|
fileName baseName = filename.lessExt();
|
||||||
|
|
||||||
|
writePoints(OFstream(baseName + ".vrt")(), pointLst);
|
||||||
|
writeLines(OFstream(baseName + ".cel")(), edgeLst);
|
||||||
|
|
||||||
|
// write a simple .inp file
|
||||||
|
writeCase
|
||||||
|
(
|
||||||
|
OFstream(baseName + ".inp")(),
|
||||||
|
pointLst,
|
||||||
|
edgeLst.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
159
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.H
Normal file
159
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.H
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::STARCDedgeFormat
|
||||||
|
|
||||||
|
Description
|
||||||
|
Read/write the lines from pro-STAR vrt/cel files.
|
||||||
|
|
||||||
|
Note
|
||||||
|
Uses the extension @a .inp (input) to denote the format.
|
||||||
|
|
||||||
|
See Also
|
||||||
|
Foam::meshReaders::STARCD
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
STARCDedgeFormat.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef STARCDedgeFormat_H
|
||||||
|
#define STARCDedgeFormat_H
|
||||||
|
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
#include "IFstream.H"
|
||||||
|
#include "Ostream.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class STARCDedgeFormat Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class STARCDedgeFormat
|
||||||
|
:
|
||||||
|
public edgeMesh
|
||||||
|
{
|
||||||
|
// Private Data
|
||||||
|
|
||||||
|
//- STAR-CD identifier for line shapes (1d elements)
|
||||||
|
static const int starcdLineShape_ = 2;
|
||||||
|
|
||||||
|
//- STAR-CD identifier for line type
|
||||||
|
static const int starcdLineType_ = 5;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
static inline void writeLines
|
||||||
|
(
|
||||||
|
Ostream&,
|
||||||
|
const edgeList&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
STARCDedgeFormat(const STARCDedgeFormat&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const STARCDedgeFormat&);
|
||||||
|
|
||||||
|
|
||||||
|
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&,
|
||||||
|
const pointField&,
|
||||||
|
const label nEdges
|
||||||
|
);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from file name
|
||||||
|
STARCDedgeFormat(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Read file and return edgeMesh
|
||||||
|
static autoPtr<edgeMesh> New(const fileName& name)
|
||||||
|
{
|
||||||
|
return autoPtr<edgeMesh>
|
||||||
|
(
|
||||||
|
new STARCDedgeFormat(name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~STARCDedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Write edge mesh
|
||||||
|
static void write(const fileName&, const edgeMesh&);
|
||||||
|
|
||||||
|
//- Read from file
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
|
||||||
|
//- Write object
|
||||||
|
virtual void write(const fileName& name) const
|
||||||
|
{
|
||||||
|
write(name, *this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
61
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormatRunTime.C
Normal file
61
src/edgeMesh/edgeFormats/starcd/STARCDedgeFormatRunTime.C
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "STARCDedgeFormat.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
// read edgeMesh
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
STARCDedgeFormat,
|
||||||
|
fileExtension,
|
||||||
|
inp
|
||||||
|
);
|
||||||
|
|
||||||
|
// write edgeMesh
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
STARCDedgeFormat,
|
||||||
|
write,
|
||||||
|
fileExtension,
|
||||||
|
inp
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
107
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.C
Normal file
107
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.C
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "VTKedgeFormat.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
#include "clock.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::fileFormats::VTKedgeFormat::writeHeader
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const pointField& pointLst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Write header
|
||||||
|
os << "# vtk DataFile Version 2.0" << nl
|
||||||
|
<< "featureEdgeMesh written " << clock::dateTime().c_str() << nl
|
||||||
|
<< "ASCII" << nl
|
||||||
|
<< nl
|
||||||
|
<< "DATASET POLYDATA" << nl;
|
||||||
|
|
||||||
|
// Write vertex coords
|
||||||
|
os << "POINTS " << pointLst.size() << " float" << nl;
|
||||||
|
forAll(pointLst, ptI)
|
||||||
|
{
|
||||||
|
const point& pt = pointLst[ptI];
|
||||||
|
|
||||||
|
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::fileFormats::VTKedgeFormat::writeEdges
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const UList<edge>& edgeLst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
os << "LINES " << edgeLst.size() << ' '
|
||||||
|
<< 3*edgeLst.size() << nl;
|
||||||
|
|
||||||
|
forAll(edgeLst, edgeI)
|
||||||
|
{
|
||||||
|
const edge& e = edgeLst[edgeI];
|
||||||
|
|
||||||
|
os << "2 " << e[0] << ' ' << e[1] << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::fileFormats::VTKedgeFormat::VTKedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::fileFormats::VTKedgeFormat::write
|
||||||
|
(
|
||||||
|
const fileName& filename,
|
||||||
|
const edgeMesh& eMesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
OFstream os(filename);
|
||||||
|
if (!os.good())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"fileFormats::VTKedgeFormat::write"
|
||||||
|
"(const fileName&, const edgeMesh&)"
|
||||||
|
)
|
||||||
|
<< "Cannot open file for writing " << filename
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeHeader(os, eMesh.points());
|
||||||
|
writeEdges(os, eMesh.edges());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
116
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.H
Normal file
116
src/edgeMesh/edgeFormats/vtk/VTKedgeFormat.H
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fileFormats::VTKedgeFormat
|
||||||
|
|
||||||
|
Description
|
||||||
|
Provide a means of writing VTK legacy format.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
VTKedgeFormat.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef VTKedgeFormat_H
|
||||||
|
#define VTKedgeFormat_H
|
||||||
|
|
||||||
|
#include "edgeMesh.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class VTKedgeFormat Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class VTKedgeFormat
|
||||||
|
:
|
||||||
|
public edgeMesh
|
||||||
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
VTKedgeFormat(const VTKedgeFormat&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const VTKedgeFormat&);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Write header information with points
|
||||||
|
static void writeHeader
|
||||||
|
(
|
||||||
|
Ostream&,
|
||||||
|
const pointField&
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write edges
|
||||||
|
static void writeEdges(Ostream&, const UList<edge>&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
VTKedgeFormat();
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~VTKedgeFormat()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
// Write
|
||||||
|
|
||||||
|
//- Write edgeMesh
|
||||||
|
static void write(const fileName&, const edgeMesh&);
|
||||||
|
|
||||||
|
// //- Write object
|
||||||
|
// virtual void write(Ostream& os) const
|
||||||
|
// {
|
||||||
|
// write(os, *this);
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace fileFormats
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
51
src/edgeMesh/edgeFormats/vtk/VTKedgeFormatRunTime.C
Normal file
51
src/edgeMesh/edgeFormats/vtk/VTKedgeFormatRunTime.C
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "VTKedgeFormat.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace fileFormats
|
||||||
|
{
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
edgeMesh,
|
||||||
|
VTKedgeFormat,
|
||||||
|
write,
|
||||||
|
fileExtension,
|
||||||
|
vtk
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -26,6 +26,76 @@ License
|
|||||||
|
|
||||||
#include "edgeMesh.H"
|
#include "edgeMesh.H"
|
||||||
#include "mergePoints.H"
|
#include "mergePoints.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(edgeMesh, 0);
|
||||||
|
defineRunTimeSelectionTable(edgeMesh, fileExtension);
|
||||||
|
defineMemberFunctionSelectionTable(edgeMesh,write,fileExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
Foam::wordHashSet Foam::edgeMesh::readTypes()
|
||||||
|
{
|
||||||
|
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
Foam::wordHashSet Foam::edgeMesh::writeTypes()
|
||||||
|
{
|
||||||
|
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::edgeMesh::canReadType
|
||||||
|
(
|
||||||
|
const word& ext,
|
||||||
|
const bool verbose
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return checkSupport
|
||||||
|
(
|
||||||
|
readTypes(),
|
||||||
|
ext,
|
||||||
|
verbose,
|
||||||
|
"reading"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Foam::edgeMesh::canWriteType
|
||||||
|
(
|
||||||
|
const word& ext,
|
||||||
|
const bool verbose
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return checkSupport
|
||||||
|
(
|
||||||
|
writeTypes(),
|
||||||
|
ext,
|
||||||
|
verbose,
|
||||||
|
"writing"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::edgeMesh::canRead
|
||||||
|
(
|
||||||
|
const fileName& name,
|
||||||
|
const bool verbose
|
||||||
|
)
|
||||||
|
{
|
||||||
|
word ext = name.ext();
|
||||||
|
if (ext == "gz")
|
||||||
|
{
|
||||||
|
ext = name.lessExt().ext();
|
||||||
|
}
|
||||||
|
return canReadType(ext, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -63,10 +133,10 @@ void Foam::edgeMesh::calcPointEdges() const
|
|||||||
forAll(edges_, edgeI)
|
forAll(edges_, edgeI)
|
||||||
{
|
{
|
||||||
const edge& e = edges_[edgeI];
|
const edge& e = edges_[edgeI];
|
||||||
|
const label p0 = e[0];
|
||||||
|
const label p1 = e[1];
|
||||||
|
|
||||||
label p0 = e[0];
|
|
||||||
pointEdges[p0][nEdgesPerPoint[p0]++] = edgeI;
|
pointEdges[p0][nEdgesPerPoint[p0]++] = edgeI;
|
||||||
label p1 = e[1];
|
|
||||||
pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
|
pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,32 +144,102 @@ void Foam::edgeMesh::calcPointEdges() const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// construct from components
|
Foam::edgeMesh::edgeMesh()
|
||||||
Foam::edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
|
|
||||||
:
|
:
|
||||||
points_(points),
|
points_(0),
|
||||||
edges_(edges)
|
edges_(0),
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// construct as copy
|
|
||||||
Foam::edgeMesh::edgeMesh(const edgeMesh& em)
|
|
||||||
:
|
|
||||||
points_(em.points_),
|
|
||||||
edges_(em.edges_),
|
|
||||||
pointEdgesPtr_(NULL)
|
pointEdgesPtr_(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::edgeMesh::edgeMesh
|
||||||
|
(
|
||||||
|
const pointField& points,
|
||||||
|
const edgeList& edges
|
||||||
|
)
|
||||||
|
:
|
||||||
|
points_(points),
|
||||||
|
edges_(edges),
|
||||||
|
pointEdgesPtr_(NULL)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::edgeMesh::edgeMesh
|
||||||
|
(
|
||||||
|
const Xfer<pointField>& pointLst,
|
||||||
|
const Xfer<edgeList>& edgeLst
|
||||||
|
)
|
||||||
|
:
|
||||||
|
points_(0),
|
||||||
|
edges_(0),
|
||||||
|
pointEdgesPtr_(NULL)
|
||||||
|
{
|
||||||
|
points_.transfer(pointLst());
|
||||||
|
edges_.transfer(edgeLst());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::edgeMesh::~edgeMesh()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::edgeMesh::clear()
|
||||||
|
{
|
||||||
|
points_.clear();
|
||||||
|
edges_.clear();
|
||||||
|
pointEdgesPtr_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::edgeMesh::reset
|
||||||
|
(
|
||||||
|
const Xfer< pointField >& pointLst,
|
||||||
|
const Xfer< edgeList >& edgeLst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Take over new primitive data.
|
||||||
|
// Optimized to avoid overwriting data at all
|
||||||
|
if (&pointLst)
|
||||||
|
{
|
||||||
|
points_.transfer(pointLst());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (&edgeLst)
|
||||||
|
{
|
||||||
|
edges_.transfer(edgeLst());
|
||||||
|
|
||||||
|
// connectivity likely changed
|
||||||
|
pointEdgesPtr_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::edgeMesh::transfer(edgeMesh& mesh)
|
||||||
|
{
|
||||||
|
points_.transfer(mesh.points_);
|
||||||
|
edges_.transfer(mesh.edges_);
|
||||||
|
pointEdgesPtr_ = mesh.pointEdgesPtr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Xfer< Foam::edgeMesh >
|
||||||
|
Foam::edgeMesh::xfer()
|
||||||
|
{
|
||||||
|
return xferMove(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
||||||
{
|
{
|
||||||
edgeRegion.setSize(edges_.size());
|
edgeRegion.setSize(edges_.size());
|
||||||
edgeRegion = -1;
|
edgeRegion = -1;
|
||||||
|
|
||||||
label startEdgeI = 0;
|
label startEdgeI = 0;
|
||||||
|
|
||||||
label currentRegion = 0;
|
label currentRegion = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
@ -159,6 +299,16 @@ Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::edgeMesh::scalePoints(const scalar scaleFactor)
|
||||||
|
{
|
||||||
|
// avoid bad scaling
|
||||||
|
if (scaleFactor > 0 && scaleFactor != 1.0)
|
||||||
|
{
|
||||||
|
points_ *= scaleFactor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
||||||
{
|
{
|
||||||
pointField newPoints;
|
pointField newPoints;
|
||||||
@ -180,7 +330,7 @@ void Foam::edgeMesh::mergePoints(const scalar mergeDist)
|
|||||||
|
|
||||||
points_.transfer(newPoints);
|
points_.transfer(newPoints);
|
||||||
|
|
||||||
// Renumber and make sure e[0] < e[1] (not really nessecary)
|
// Renumber and make sure e[0] < e[1] (not really necessary)
|
||||||
forAll(edges_, edgeI)
|
forAll(edges_, edgeI)
|
||||||
{
|
{
|
||||||
edge& e = edges_[edgeI];
|
edge& e = edges_[edgeI];
|
||||||
@ -243,7 +393,7 @@ void Foam::edgeMesh::operator=(const edgeMesh& rhs)
|
|||||||
{
|
{
|
||||||
points_ = rhs.points_;
|
points_ = rhs.points_;
|
||||||
edges_ = rhs.edges_;
|
edges_ = rhs.edges_;
|
||||||
pointEdgesPtr_.reset(NULL);
|
pointEdgesPtr_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ Class
|
|||||||
Foam::edgeMesh
|
Foam::edgeMesh
|
||||||
|
|
||||||
Description
|
Description
|
||||||
points connected by edges.
|
Points connected by edges.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
edgeMeshI.H
|
edgeMeshI.H
|
||||||
@ -40,17 +40,33 @@ SourceFiles
|
|||||||
|
|
||||||
#include "pointField.H"
|
#include "pointField.H"
|
||||||
#include "edgeList.H"
|
#include "edgeList.H"
|
||||||
|
#include "edgeFormatsCore.H"
|
||||||
|
#include "runTimeSelectionTables.H"
|
||||||
|
#include "memberFunctionSelectionTables.H"
|
||||||
|
#include "HashSet.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declaration of classes
|
||||||
|
class Istream;
|
||||||
|
class Ostream;
|
||||||
|
|
||||||
|
// Forward declaration of friend functions and operators
|
||||||
|
class edgeMesh;
|
||||||
|
Istream& operator>>(Istream&, edgeMesh&);
|
||||||
|
Ostream& operator<<(Ostream&, const edgeMesh&);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class edgeMesh Declaration
|
Class edgeMesh Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class edgeMesh
|
class edgeMesh
|
||||||
|
:
|
||||||
|
public fileFormats::edgeFormatsCore
|
||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
@ -68,39 +84,179 @@ class edgeMesh
|
|||||||
//- Calculate point-edge addressing (inverse of edges)
|
//- Calculate point-edge addressing (inverse of edges)
|
||||||
void calcPointEdges() const;
|
void calcPointEdges() const;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Non-const access to global points
|
||||||
|
inline pointField& storedPoints();
|
||||||
|
|
||||||
|
//- Non-const access to the edges
|
||||||
|
inline edgeList& storedEdges();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("edgeMesh");
|
||||||
|
|
||||||
|
// Static
|
||||||
|
|
||||||
|
//- Can we read this file format?
|
||||||
|
static bool canRead(const fileName&, const bool verbose=false);
|
||||||
|
|
||||||
|
//- Can we read this file format?
|
||||||
|
static bool canReadType(const word& ext, const bool verbose=false);
|
||||||
|
|
||||||
|
//- Can we write this file format type?
|
||||||
|
static bool canWriteType(const word& ext, const bool verbose=false);
|
||||||
|
|
||||||
|
static wordHashSet readTypes();
|
||||||
|
static wordHashSet writeTypes();
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
edgeMesh();
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
edgeMesh(const pointField&, const edgeList&);
|
edgeMesh(const pointField&, const edgeList&);
|
||||||
|
|
||||||
//- Construct from file
|
//- Construct by transferring components (points, edges).
|
||||||
edgeMesh(const fileName&);
|
edgeMesh
|
||||||
|
(
|
||||||
//- Construct from Istream
|
const Xfer< pointField >&,
|
||||||
edgeMesh(Istream&);
|
const Xfer< edgeList >&
|
||||||
|
);
|
||||||
|
|
||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
edgeMesh(const edgeMesh&);
|
edgeMesh(const edgeMesh&);
|
||||||
|
|
||||||
|
//- Construct from file name (uses extension to determine type)
|
||||||
|
edgeMesh(const fileName&);
|
||||||
|
|
||||||
|
//- Construct from file name (uses extension to determine type)
|
||||||
|
edgeMesh(const fileName&, const word& ext);
|
||||||
|
|
||||||
|
//- Construct from Istream
|
||||||
|
edgeMesh(Istream&);
|
||||||
|
|
||||||
|
// Declare run-time constructor selection table
|
||||||
|
|
||||||
|
declareRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
autoPtr,
|
||||||
|
edgeMesh,
|
||||||
|
fileExtension,
|
||||||
|
(
|
||||||
|
const fileName& name
|
||||||
|
),
|
||||||
|
(name)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Select constructed from filename (explicit extension)
|
||||||
|
static autoPtr<edgeMesh> New
|
||||||
|
(
|
||||||
|
const fileName&,
|
||||||
|
const word& ext
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Select constructed from filename (implicit extension)
|
||||||
|
static autoPtr<edgeMesh> New(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~edgeMesh();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Function Selectors
|
||||||
|
|
||||||
|
declareMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
void,
|
||||||
|
edgeMesh,
|
||||||
|
write,
|
||||||
|
fileExtension,
|
||||||
|
(
|
||||||
|
const fileName& name,
|
||||||
|
const edgeMesh& mesh
|
||||||
|
),
|
||||||
|
(name, mesh)
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write to file
|
||||||
|
static void write(const fileName&, const edgeMesh&);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
|
//- Transfer the contents of the argument and annul the argument
|
||||||
|
void transfer(edgeMesh&);
|
||||||
|
|
||||||
|
//- Transfer contents to the Xfer container
|
||||||
|
Xfer< edgeMesh > xfer();
|
||||||
|
|
||||||
|
// Read
|
||||||
|
|
||||||
|
//- Read from file. Chooses reader based on explicit extension
|
||||||
|
bool read(const fileName&, const word& ext);
|
||||||
|
|
||||||
|
//- Read from file. Chooses reader based on detected extension
|
||||||
|
virtual bool read(const fileName&);
|
||||||
|
|
||||||
|
|
||||||
|
// Access
|
||||||
|
|
||||||
|
//- Return points
|
||||||
inline const pointField& points() const;
|
inline const pointField& points() const;
|
||||||
|
|
||||||
|
//- Return edges
|
||||||
inline const edgeList& edges() const;
|
inline const edgeList& edges() const;
|
||||||
|
|
||||||
|
//- Return edges
|
||||||
inline const labelListList& pointEdges() const;
|
inline const labelListList& pointEdges() const;
|
||||||
|
|
||||||
//- Find connected regions. Set region number per edge.
|
//- Find connected regions. Set region number per edge.
|
||||||
// Returns number of regions.
|
// Returns number of regions.
|
||||||
label regions(labelList& edgeRegion) const;
|
label regions(labelList& edgeRegion) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Edit
|
||||||
|
|
||||||
|
//- Clear all storage
|
||||||
|
virtual void clear();
|
||||||
|
|
||||||
|
//- Reset primitive data (points, edges)
|
||||||
|
// Note, optimized to avoid overwriting data (with Xfer::null)
|
||||||
|
virtual void reset
|
||||||
|
(
|
||||||
|
const Xfer< pointField >& points,
|
||||||
|
const Xfer< edgeList >& edges
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Scale points. A non-positive factor is ignored
|
||||||
|
virtual void scalePoints(const scalar);
|
||||||
|
|
||||||
//- Merge common points (points within mergeDist)
|
//- Merge common points (points within mergeDist)
|
||||||
void mergePoints(const scalar mergeDist);
|
void mergePoints(const scalar mergeDist);
|
||||||
|
|
||||||
|
|
||||||
|
// Write
|
||||||
|
|
||||||
|
void writeStats(Ostream&) const;
|
||||||
|
|
||||||
|
// Write
|
||||||
|
|
||||||
|
//- Generic write routine. Chooses writer based on extension.
|
||||||
|
virtual void write(const fileName& name) const
|
||||||
|
{
|
||||||
|
write(name, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
inline void operator=(const edgeMesh&);
|
inline void operator=(const edgeMesh&);
|
||||||
@ -109,6 +265,7 @@ public:
|
|||||||
|
|
||||||
friend Ostream& operator<<(Ostream&, const edgeMesh&);
|
friend Ostream& operator<<(Ostream&, const edgeMesh&);
|
||||||
friend Istream& operator>>(Istream&, edgeMesh&);
|
friend Istream& operator>>(Istream&, edgeMesh&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -24,14 +24,14 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::edgeMesh::edgeMesh(const edgeMesh& em)
|
||||||
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
|
:
|
||||||
|
points_(em.points_),
|
||||||
|
edges_(em.edges_),
|
||||||
|
pointEdgesPtr_(NULL)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
@ -58,15 +58,16 @@ inline const Foam::labelListList& Foam::edgeMesh::pointEdges() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
inline Foam::pointField& Foam::edgeMesh::storedPoints()
|
||||||
|
{
|
||||||
|
return points_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
|
inline Foam::edgeList& Foam::edgeMesh::storedEdges()
|
||||||
|
{
|
||||||
|
return edges_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -25,42 +25,107 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "edgeMesh.H"
|
#include "edgeMesh.H"
|
||||||
#include "IFstream.H"
|
#include "boundBox.H"
|
||||||
|
#include "EMESHedgeFormat.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// construct from file
|
Foam::edgeMesh::edgeMesh
|
||||||
Foam::edgeMesh::edgeMesh(const fileName& fname)
|
(
|
||||||
|
const fileName& name,
|
||||||
|
const word& ext
|
||||||
|
)
|
||||||
:
|
:
|
||||||
points_(0),
|
points_(0),
|
||||||
edges_(0),
|
edges_(0),
|
||||||
pointEdgesPtr_(NULL)
|
pointEdgesPtr_(NULL)
|
||||||
{
|
{
|
||||||
IFstream is(fname);
|
read(name, ext);
|
||||||
|
}
|
||||||
|
|
||||||
if (is.good())
|
|
||||||
|
Foam::edgeMesh::edgeMesh(const fileName& name)
|
||||||
|
:
|
||||||
|
points_(0),
|
||||||
|
edges_(0),
|
||||||
|
pointEdgesPtr_(NULL)
|
||||||
|
{
|
||||||
|
read(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::edgeMesh::read(const fileName& name)
|
||||||
|
{
|
||||||
|
word ext = name.ext();
|
||||||
|
if (ext == "gz")
|
||||||
{
|
{
|
||||||
is >> points_ >> edges_;
|
fileName unzipName = name.lessExt();
|
||||||
|
return read(unzipName, unzipName.ext());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorIn("edgeMesh::edgeMesh(const fileName&)")
|
return read(name, ext);
|
||||||
<< "cannot open file " << fname
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// construct from Istream
|
// Read from file in given format
|
||||||
Foam::edgeMesh::edgeMesh(Istream& is)
|
bool Foam::edgeMesh::read
|
||||||
:
|
(
|
||||||
points_(is),
|
const fileName& name,
|
||||||
edges_(is),
|
const word& ext
|
||||||
pointEdgesPtr_(NULL)
|
)
|
||||||
{
|
{
|
||||||
// Check state of Istream
|
// read via selector mechanism
|
||||||
is.check("edgeMesh::edgeMesh(Istream&)");
|
transfer(New(name, ext)());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::edgeMesh::write
|
||||||
|
(
|
||||||
|
const fileName& name,
|
||||||
|
const edgeMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "edgeMesh::write"
|
||||||
|
"(const fileName&, const edgeMesh&) : "
|
||||||
|
"writing to " << name
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const word ext = name.ext();
|
||||||
|
|
||||||
|
writefileExtensionMemberFunctionTable::iterator mfIter =
|
||||||
|
writefileExtensionMemberFunctionTablePtr_->find(ext);
|
||||||
|
|
||||||
|
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"MeshedSurface::write"
|
||||||
|
"(const fileName&, const MeshedSurface&)"
|
||||||
|
) << "Unknown file extension " << ext << nl << nl
|
||||||
|
<< "Valid types are :" << endl
|
||||||
|
<< writefileExtensionMemberFunctionTablePtr_->sortedToc()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mfIter()(name, mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::edgeMesh::writeStats(Ostream& os) const
|
||||||
|
{
|
||||||
|
os << "points : " << points().size() << nl;
|
||||||
|
os << "edges : " << edges().size() << nl;
|
||||||
|
os << "boundingBox : " << boundBox(this->points()) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,7 +133,7 @@ Foam::edgeMesh::edgeMesh(Istream& is)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
|
||||||
{
|
{
|
||||||
os << em.points_ << nl << em.edges_ << endl;
|
fileFormats::EMESHedgeFormat::write(os, em.points_, em.edges_);
|
||||||
|
|
||||||
// Check state of Ostream
|
// Check state of Ostream
|
||||||
os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
|
os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
|
||||||
@ -79,7 +144,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
|
|||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
|
Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
|
||||||
{
|
{
|
||||||
is >> em.points_ >> em.edges_;
|
fileFormats::EMESHedgeFormat::read(is, em.points_, em.edges_);
|
||||||
|
|
||||||
|
em.pointEdgesPtr_.clear();
|
||||||
|
|
||||||
// Check state of Istream
|
// Check state of Istream
|
||||||
is.check("Istream& operator>>(Istream&, edgeMesh&)");
|
is.check("Istream& operator>>(Istream&, edgeMesh&)");
|
||||||
|
|||||||
65
src/edgeMesh/edgeMeshNew.C
Normal file
65
src/edgeMesh/edgeMeshNew.C
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2009-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 "edgeMesh.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
|
Foam::autoPtr< Foam::edgeMesh >
|
||||||
|
Foam::edgeMesh::New(const fileName& name, const word& ext)
|
||||||
|
{
|
||||||
|
fileExtensionConstructorTable::iterator cstrIter =
|
||||||
|
fileExtensionConstructorTablePtr_->find(ext);
|
||||||
|
|
||||||
|
if (cstrIter == fileExtensionConstructorTablePtr_->end())
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"edgeMesh<Face>::New(const fileName&, const word&) : "
|
||||||
|
"constructing edgeMesh"
|
||||||
|
) << "Unknown file extension " << ext << nl << nl
|
||||||
|
<< "Valid types are :" << nl
|
||||||
|
<< fileExtensionConstructorTablePtr_->sortedToc()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return autoPtr< edgeMesh >(cstrIter()(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::autoPtr< Foam::edgeMesh >
|
||||||
|
Foam::edgeMesh::New(const fileName& name)
|
||||||
|
{
|
||||||
|
word ext = name.ext();
|
||||||
|
if (ext == "gz")
|
||||||
|
{
|
||||||
|
ext = name.lessExt().ext();
|
||||||
|
}
|
||||||
|
return New(name, ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -28,21 +28,7 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
defineTypeNameAndDebug(Foam::featureEdgeMesh, 0);
|
||||||
{
|
|
||||||
|
|
||||||
defineTypeNameAndDebug(featureEdgeMesh, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
@ -73,20 +59,6 @@ Foam::featureEdgeMesh::featureEdgeMesh(const IOobject& io)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Construct from components
|
|
||||||
Foam::featureEdgeMesh::featureEdgeMesh
|
|
||||||
(
|
|
||||||
const IOobject& io,
|
|
||||||
const pointField& points,
|
|
||||||
const edgeList& edges
|
|
||||||
)
|
|
||||||
:
|
|
||||||
regIOobject(io),
|
|
||||||
edgeMesh(points, edges)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// Construct as copy
|
|
||||||
Foam::featureEdgeMesh::featureEdgeMesh
|
Foam::featureEdgeMesh::featureEdgeMesh
|
||||||
(
|
(
|
||||||
const IOobject& io,
|
const IOobject& io,
|
||||||
@ -98,6 +70,28 @@ Foam::featureEdgeMesh::featureEdgeMesh
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::featureEdgeMesh::featureEdgeMesh
|
||||||
|
(
|
||||||
|
const IOobject& io,
|
||||||
|
const Xfer< pointField >& pointLst,
|
||||||
|
const Xfer< edgeList >& edgeLst
|
||||||
|
)
|
||||||
|
:
|
||||||
|
regIOobject(io),
|
||||||
|
edgeMesh(pointLst, edgeLst)
|
||||||
|
{
|
||||||
|
if
|
||||||
|
(
|
||||||
|
io.readOpt() == IOobject::MUST_READ
|
||||||
|
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
readStream(typeName) >> *this;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::featureEdgeMesh::readData(Istream& is)
|
bool Foam::featureEdgeMesh::readData(Istream& is)
|
||||||
@ -115,7 +109,4 @@ bool Foam::featureEdgeMesh::writeData(Ostream& os) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
@ -56,25 +56,28 @@ class featureEdgeMesh
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
TypeName("featureEdgeMesh");
|
TypeName("featureEdgeMesh");
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct (read) given an IOobject
|
//- Construct (read) given an IOobject
|
||||||
featureEdgeMesh(const IOobject&);
|
explicit featureEdgeMesh(const IOobject&);
|
||||||
|
|
||||||
//- Construct from featureEdgeMesh data
|
//- Construct as copy
|
||||||
|
explicit featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
|
||||||
|
|
||||||
|
//- Construct by transferring components (points, edges)
|
||||||
featureEdgeMesh
|
featureEdgeMesh
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject&,
|
||||||
const pointField&,
|
const Xfer<pointField>&,
|
||||||
const edgeList&
|
const Xfer<edgeList>&
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy
|
//- Give precedence to the regIOobject write
|
||||||
featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
|
using regIOobject::write;
|
||||||
|
|
||||||
|
|
||||||
//- ReadData function required for regIOobject read operation
|
//- ReadData function required for regIOobject read operation
|
||||||
virtual bool readData(Istream&);
|
virtual bool readData(Istream&);
|
||||||
Reference in New Issue
Block a user