Branch merge + conflict resolution

This commit is contained in:
andy 2009-12-15 11:38:23 +00:00
commit 1e086391b7
42 changed files with 3250 additions and 383 deletions

View File

@ -67,9 +67,15 @@ int main(int argc, char *argv[])
while (is.good())
{
token tok(is);
// char ch;
// is.get(ch);
// is.putback(ch);
int lookahead = is.peek();
if (count == 0)
{
Info<< "token: " << tok.info() << endl;
Info<< "token: " << tok.info();
Info<< " lookahead: '" << char(lookahead) << "'" << endl;
}
}

View File

@ -42,7 +42,7 @@ Usage
@param -region \<name\> \n
Specify an alternative mesh region.
@param -dict \<dictionary\> \n
@param -dict \<filename\> \n
Specify an alternative dictionary for the block mesh description.
\*---------------------------------------------------------------------------*/
@ -80,7 +80,7 @@ int main(int argc, char *argv[])
argList::addOption
(
"dict",
"NAME",
"file",
"specify an alternative dictionary for the blockMesh description"
);

View File

@ -142,16 +142,43 @@ void rotateFields(const argList& args, const Time& runTime, const tensor& T)
int main(int argc, char *argv[])
{
# include "addRegionOption.H"
argList::addOption("translate", "vector");
argList::addOption("rotate", "(vector vector)");
argList::addOption("rollPitchYaw", "(roll pitch yaw)");
argList::addOption("yawPitchRoll", "(yaw pitch roll)");
#include "addRegionOption.H"
argList::addOption
(
"translate",
"vector",
"translate by the specified <vector> - eg, '(1 0 0)'"
);
argList::addOption
(
"rotate",
"(vectorA vectorB)",
"transform in terms of a rotation between <vectorA> and <vectorB> "
"- eg, '( (1 0 0) (0 0 1) )'"
);
argList::addOption
(
"rollPitchYaw",
"vector",
"transform in terms of '( roll pitch yaw )' in degrees"
);
argList::addOption
(
"yawPitchRoll",
"vector",
"transform in terms of '( yaw pitch roll )' in degrees"
);
argList::addBoolOption("rotateFields");
argList::addOption("scale", "vector");
argList::addOption
(
"scale",
"vector",
"scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
"uniform [mm] to [m] scaling"
);
# include "setRootCase.H"
# include "createTime.H"
#include "setRootCase.H"
#include "createTime.H"
word regionName = polyMesh::defaultRegion;
fileName meshDir;

View File

@ -101,13 +101,13 @@ int main(int argc, char *argv[])
argList::addBoolOption
(
"noPatches",
"Suppress writing any patches"
"suppress writing any patches"
);
argList::addOption
(
"patches",
"patchList",
"Specify particular patches to write. "
"wordList",
"specify particular patches to write - eg '(inlet outlet)'. "
"An empty list suppresses writing the internalMesh."
);

View File

@ -94,7 +94,7 @@ int main(int argc, char *argv[])
argList::addBoolOption
(
"noMesh",
"Suppress writing the geometry. "
"suppress writing the geometry. "
"Can be useful for converting partial results for a static geometry"
);

View File

@ -241,20 +241,46 @@ int main(int argc, char *argv[])
# include "addRegionOption.H"
argList::addOption("fields", "fields");
argList::addOption("cellSet", "cellSet name");
argList::addOption("faceSet", "faceSet name");
argList::addOption("pointSet", "pointSet name");
argList::addBoolOption("ascii");
argList::addOption
(
"fields", "wordList",
"only convert the specified fields - eg '(p T U)'"
);
argList::addOption
(
"cellSet",
"name",
"convert a mesh subset corresponding to the specified cellSet"
);
argList::addOption("faceSet", "name");
argList::addOption("pointSet", "name");
argList::addBoolOption
(
"ascii",
"write in ASCII format instead of binary"
);
argList::addBoolOption("surfaceFields");
argList::addBoolOption("nearCellValue");
argList::addBoolOption("noInternal");
argList::addBoolOption("noPointValues");
argList::addBoolOption("allPatches");
argList::addOption("excludePatches","patches to exclude");
argList::addOption
(
"excludePatches",
"wordReList",
"a list of patches to exclude - eg '( inlet \".*Wall\" )' "
);
argList::addBoolOption("noFaceZones");
argList::addBoolOption("noLinks");
argList::addBoolOption("useTimeName");
argList::addBoolOption
(
"noLinks",
"don't link processor VTK files - parallel only"
);
argList::addBoolOption
(
"useTimeName",
"use the time name instead of the time index when naming the files"
);
# include "setRootCase.H"
# include "createTime.H"

View File

@ -21,7 +21,7 @@ surfaceFind
- Finds nearest vertex and face to given point.
surfaceMeshTriangulate
- Triangulate external facses of mesh and write as surface.
- Triangulate external faces of mesh and write as surface.
surfacePointMerge
- Explicit point merge of surface.

View File

@ -26,266 +26,85 @@ Application
surfaceFeatureConvert
Description
Extracts and writes surface features to file
Convert between edgeMesh formats
\*---------------------------------------------------------------------------*/
#include "featureEdgeMesh.H"
#include "argList.H"
#include "Time.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "OFstream.H"
#include "Map.H"
#include "edgeMesh.H"
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:
int main(int argc, char *argv[])
{
argList::addNote
(
"Convert between edgeMesh formats"
);
argList::noParallel();
argList::validArgs.append("input file");
argList::validArgs.append("output file");
# include "setRootCase.H"
# include "createTime.H"
argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile");
argList::addOption
(
"scale",
"factor",
"specify a scaling factor for the points"
);
const fileName inFileName(args.additionalArgs()[0]);
const word outFileName(args.additionalArgs()[1]);
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const stringList& params = args.additionalArgs();
Pout<< "Input features file : " << inFileName << nl
<< "Output features file : " << outFileName << nl
<< endl;
const fileName importName(params[0]);
const fileName exportName(params[1]);
// 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
(
inFileName, // name
runTime.constant(), // instance
runTime, // registry
IOobject::MUST_READ,
IOobject::AUTO_WRITE,
false
)
);
Pout<< "Read from " << inFileName
<< " edges:" << fem.edges().size()
<< " points:" << fem.points().size()
<< endl;
write(runTime, inFileName, outFileName, fem);
}
else
// disable inplace editing
if (importName == exportName)
{
FatalErrorIn(args.executable())
<< "Can only handle NASTRAN data formats (.nas extension)."
<< "Output file " << exportName << " would overwrite input file."
<< 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;
}

View File

@ -199,7 +199,7 @@ int main(int argc, char *argv[])
}
// Trim away small groups of features
if (minLen > 0 || minLen > 0)
if (minElem > 0 || minLen > 0)
{
set.trimFeatures(minLen, minElem);
Pout<< endl << "Removed small features" << endl;

View File

@ -23,8 +23,8 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Transform (scale/rotate) a surface. Like transformPoints but then for
surfaces.
Transform (scale/rotate) a surface.
Like transformPoints but for surfaces.
The rollPitchYaw option takes three angles (degrees):
- roll (rotation about x) followed by
@ -54,16 +54,47 @@ using namespace Foam::constant::mathematical;
int main(int argc, char *argv[])
{
argList::addNote
(
"Transform (scale/rotate) a surface. "
"Like transformPoints but for surfaces."
);
argList::noParallel();
argList::validArgs.clear();
argList::validArgs.append("surface file");
argList::validArgs.append("output surface file");
argList::addOption("translate", "vector");
argList::addOption("rotate", "(vector vector)");
argList::addOption("scale", "vector");
argList::addOption("rollPitchYaw", "(roll pitch yaw)");
argList::addOption("yawPitchRoll", "(yaw pitch roll)");
argList::addOption
(
"translate",
"vector",
"translate by the specified <vector> - eg, '(1 0 0)'"
);
argList::addOption
(
"rotate",
"(vectorA vectorB)",
"transform in terms of a rotation between <vectorA> and <vectorB> "
"- eg, '( (1 0 0) (0 0 1) )'"
);
argList::addOption
(
"scale",
"vector",
"scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
"uniform [mm] to [m] scaling"
);
argList::addOption
(
"rollPitchYaw",
"vector",
"transform in terms of '( roll pitch yaw )' in degrees"
);
argList::addOption
(
"yawPitchRoll",
"vector",
"transform in terms of '( yaw pitch roll )' in degrees"
);
argList args(argc, argv);
fileName surfFileName(args.additionalArgs()[0]);

View File

@ -22,9 +22,9 @@ wmake libso OpenFOAM
wmake libso lagrangian/basic
wmake libso triSurface
wmake libso edgeMesh
wmake libso surfMesh
wmake libso triSurface
# Decomposition methods needed by meshTools
wmake libso parallel/decompositionMethods

View File

@ -137,6 +137,12 @@ public:
//- Raw, low-level get character function.
inline ISstream& get(char&);
//- Raw, low-level peek function.
// Does not remove the character from the stream.
// Returns the next character in the stream or EOF if the
// end of file is read.
inline int peek();
//- Raw, low-level getline into a string function.
inline ISstream& getLine(string&);

View File

@ -69,6 +69,12 @@ inline Foam::ISstream& Foam::ISstream::get(char& c)
}
inline int Foam::ISstream::peek()
{
return is_.peek();
}
inline Foam::ISstream& Foam::ISstream::getLine(string& s)
{
getline(is_, s);

View File

@ -43,7 +43,8 @@ Foam::SLList<Foam::string> Foam::argList::validArgs;
Foam::HashTable<Foam::string> Foam::argList::validOptions;
Foam::HashTable<Foam::string> Foam::argList::validParOptions;
Foam::HashTable<Foam::string> Foam::argList::optionUsage;
Foam::string::size_type Foam::argList::usageMin = 16;
Foam::SLList<Foam::string> Foam::argList::notes;
Foam::string::size_type Foam::argList::usageMin = 20;
Foam::string::size_type Foam::argList::usageMax = 80;
@ -51,7 +52,7 @@ Foam::argList::initValidTables::initValidTables()
{
argList::addOption
(
"case", "DIR",
"case", "dir",
"specify alternate case directory, default is the cwd"
);
argList::addBoolOption("parallel", "run in parallel");
@ -108,6 +109,15 @@ void Foam::argList::addUsage
}
void Foam::argList::addNote(const string& note)
{
if (!note.empty())
{
notes.append(note);
}
}
void Foam::argList::removeOption(const word& opt)
{
validOptions.erase(opt);
@ -765,12 +775,13 @@ void Foam::argList::printUsage() const
HashTable<string>::const_iterator iter = validOptions.find(optionName);
Info<< " -" << optionName;
label len = optionName.size() + 3; // include leading " -"
label len = optionName.size() + 3; // length includes leading ' -'
if (iter().size())
{
len += iter().size() + 1; // include space between option and param
Info<< ' ' << iter().c_str();
// length includes space and between option/param and '<>'
len += iter().size() + 3;
Info<< " <" << iter().c_str() << '>';
}
HashTable<string>::const_iterator usageIter =
@ -814,6 +825,22 @@ void Foam::argList::printUsage() const
"print the usage"
);
// output notes directly - no automatic text wrapping
if (!notes.empty())
{
Info<< nl;
for
(
SLList<string>::const_iterator iter = notes.begin();
iter != notes.end();
++iter
)
{
Info<< iter().c_str() << nl;
}
}
Info<< nl
<<"Using OpenFOAM-" << Foam::FOAMversion
<<" (build: " << Foam::FOAMbuild << ") - see www.OpenFOAM.org"

View File

@ -153,7 +153,10 @@ public:
//- Short usage information for validOptions
static HashTable<string> optionUsage;
//- Min offset for displaying usage (default: 16)
//- Additional notes for usage
static SLList<string> notes;
//- Min offset for displaying usage (default: 20)
static string::size_type usageMin;
//- Max screen width for displaying usage (default: 80)
@ -287,6 +290,10 @@ public:
const string& usage
);
//- Add extra notes for the usage information
// This string is used "as-is" without additional formatting
static void addNote(const string&);
//- Remove option from validOptions and from optionUsage
static void removeOption(const word& opt);

View File

@ -1,5 +1,26 @@
edgeMesh.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

View 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()
{}
// ************************************************************************* //

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

View 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&)");
}
// ************************************************************************* //

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

View 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
);
}
}
// ************************************************************************* //

View 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;
}
// ************************************************************************* //

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

View 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
);
}
}
// ************************************************************************* //

View 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;
}
// ************************************************************************* //

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

View 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
);
}
}
// ************************************************************************* //

View 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()
);
}
// ************************************************************************* //

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

View 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
);
}
}
// ************************************************************************* //

View 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());
}
// ************************************************************************* //

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

View 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
);
}
}
// ************************************************************************* //

View File

@ -26,6 +26,76 @@ License
#include "edgeMesh.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 * * * * * * * * * * * //
@ -63,10 +133,10 @@ void Foam::edgeMesh::calcPointEdges() const
forAll(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;
label p1 = e[1];
pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
}
}
@ -74,32 +144,102 @@ void Foam::edgeMesh::calcPointEdges() const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// construct from components
Foam::edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
Foam::edgeMesh::edgeMesh()
:
points_(points),
edges_(edges)
{}
// construct as copy
Foam::edgeMesh::edgeMesh(const edgeMesh& em)
:
points_(em.points_),
edges_(em.edges_),
points_(0),
edges_(0),
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 * * * * * * * * * * * * * //
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
{
edgeRegion.setSize(edges_.size());
edgeRegion = -1;
label startEdgeI = 0;
label currentRegion = 0;
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)
{
pointField newPoints;
@ -180,7 +330,7 @@ void Foam::edgeMesh::mergePoints(const scalar mergeDist)
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)
{
edge& e = edges_[edgeI];
@ -243,7 +393,7 @@ void Foam::edgeMesh::operator=(const edgeMesh& rhs)
{
points_ = rhs.points_;
edges_ = rhs.edges_;
pointEdgesPtr_.reset(NULL);
pointEdgesPtr_.clear();
}

View File

@ -26,7 +26,7 @@ Class
Foam::edgeMesh
Description
points connected by edges.
Points connected by edges.
SourceFiles
edgeMeshI.H
@ -40,17 +40,33 @@ SourceFiles
#include "pointField.H"
#include "edgeList.H"
#include "edgeFormatsCore.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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
:
public fileFormats::edgeFormatsCore
{
// Private data
@ -68,39 +84,179 @@ class edgeMesh
//- Calculate point-edge addressing (inverse of edges)
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:
//- 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
//- Construct null
edgeMesh();
//- Construct from components
edgeMesh(const pointField&, const edgeList&);
//- Construct from file
edgeMesh(const fileName&);
//- Construct from Istream
edgeMesh(Istream&);
//- Construct by transferring components (points, edges).
edgeMesh
(
const Xfer< pointField >&,
const Xfer< edgeList >&
);
//- Construct as copy
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
//- 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;
//- Return edges
inline const edgeList& edges() const;
//- Return edges
inline const labelListList& pointEdges() const;
//- Find connected regions. Set region number per edge.
// Returns number of regions.
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)
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
inline void operator=(const edgeMesh&);
@ -109,6 +265,7 @@ public:
friend Ostream& operator<<(Ostream&, const edgeMesh&);
friend Istream& operator>>(Istream&, edgeMesh&);
};

View File

@ -24,14 +24,14 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
inline Foam::edgeMesh::edgeMesh(const edgeMesh& em)
:
points_(em.points_),
edges_(em.edges_),
pointEdgesPtr_(NULL)
{}
// * * * * * * * * * * * * * * * 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 * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -25,42 +25,107 @@ License
\*---------------------------------------------------------------------------*/
#include "edgeMesh.H"
#include "IFstream.H"
#include "boundBox.H"
#include "EMESHedgeFormat.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// construct from file
Foam::edgeMesh::edgeMesh(const fileName& fname)
Foam::edgeMesh::edgeMesh
(
const fileName& name,
const word& ext
)
:
points_(0),
edges_(0),
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
{
FatalErrorIn("edgeMesh::edgeMesh(const fileName&)")
<< "cannot open file " << fname
<< abort(FatalError);
return read(name, ext);
}
}
// construct from Istream
Foam::edgeMesh::edgeMesh(Istream& is)
:
points_(is),
edges_(is),
pointEdgesPtr_(NULL)
// Read from file in given format
bool Foam::edgeMesh::read
(
const fileName& name,
const word& ext
)
{
// Check state of Istream
is.check("edgeMesh::edgeMesh(Istream&)");
// read via selector mechanism
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)
{
os << em.points_ << nl << em.edges_ << endl;
fileFormats::EMESHedgeFormat::write(os, em.points_, em.edges_);
// Check state of Ostream
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)
{
is >> em.points_ >> em.edges_;
fileFormats::EMESHedgeFormat::read(is, em.points_, em.edges_);
em.pointEdgesPtr_.clear();
// Check state of Istream
is.check("Istream& operator>>(Istream&, edgeMesh&)");

View 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);
}
// ************************************************************************* //

View File

@ -28,21 +28,7 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(featureEdgeMesh, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::featureEdgeMesh, 0);
// * * * * * * * * * * * * * * * * 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
(
const IOobject& io,
@ -98,24 +70,43 @@ 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 * * * * * * * * * * * * * //
bool Foam::featureEdgeMesh::readData(Istream& is)
{
is >> *this;
is >> *this;
return !is.bad();
}
bool Foam::featureEdgeMesh::writeData(Ostream& os) const
{
os << *this;
os << *this;
return os.good();
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -45,7 +45,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class featureEdgeMesh Declaration
Class featureEdgeMesh Declaration
\*---------------------------------------------------------------------------*/
class featureEdgeMesh
@ -56,25 +56,28 @@ class featureEdgeMesh
public:
//- Runtime type information
TypeName("featureEdgeMesh");
// Constructors
//- 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
(
const IOobject&,
const pointField&,
const edgeList&
const Xfer<pointField>&,
const Xfer<edgeList>&
);
//- Construct as copy
featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
//- Give precedence to the regIOobject write
using regIOobject::write;
//- ReadData function required for regIOobject read operation
virtual bool readData(Istream&);

View File

@ -110,9 +110,6 @@ private:
//- Disable setSize with value
void setSize(const label, const Face&);
//- Read OpenFOAM Surface format
bool read(Istream&);
protected:
@ -198,9 +195,6 @@ public:
//- Construct from file name (uses extension to determine type)
UnsortedMeshedSurface(const fileName&, const word&);
//- Construct from Istream
UnsortedMeshedSurface(Istream&);
//- Construct from objectRegistry and a named surface
UnsortedMeshedSurface(const Time&, const word& surfName="");

View File

@ -31,7 +31,7 @@ License
void Foam::surfMesh::setInstance(const fileName& inst)
{
if (debug or true)
if (debug)
{
Info<< "void surfMesh::setInstance(const fileName& inst) : "
<< "Resetting file instance to " << inst << endl;