Handling starting from 0 or 1 on indexing

This commit is contained in:
mattijs 2008-05-14 12:42:26 +01:00
parent 238b126c6c
commit aac95d1038

View File

@ -56,18 +56,14 @@ NOTE:
always. Might use some geometric check instead. always. Might use some geometric check instead.
- marked faces might not actually be boundary faces of mesh. This is not handled - marked faces might not actually be boundary faces of mesh. This is not handled
and you'll have to run without face file (-noFaceFile option) and you'll have to run without face file (-noFaceFile option)
- default is to have indices starting at 1. Use -startAt0 if starting at 0.
- all input is expected to be ordered.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "IFstream.H" #include "IFstream.H"
#include "polyPatch.H"
#include "cellModeller.H" #include "cellModeller.H"
#include "ListOps.H"
#include <fstream>
using namespace Foam; using namespace Foam;
@ -79,7 +75,6 @@ int main(int argc, char *argv[])
{ {
argList::validArgs.append("file prefix"); argList::validArgs.append("file prefix");
argList::validOptions.insert("noFaceFile", ""); argList::validOptions.insert("noFaceFile", "");
argList::validOptions.insert("startAt0", "");
# include "setRootCase.H" # include "setRootCase.H"
# include "createTime.H" # include "createTime.H"
@ -87,34 +82,29 @@ int main(int argc, char *argv[])
bool readFaceFile = !args.options().found("noFaceFile"); bool readFaceFile = !args.options().found("noFaceFile");
bool startAt1 = !args.options().found("startAt0");
fileName prefix(args.additionalArgs()[0]); fileName prefix(args.additionalArgs()[0]);
fileName nodeFile(prefix + ".node"); fileName nodeFile(prefix + ".node");
fileName eleFile(prefix + ".ele"); fileName eleFile(prefix + ".ele");
fileName faceFile(prefix + ".face"); fileName faceFile(prefix + ".face");
Info<< "Files:" << endl if (!readFaceFile)
<< " nodes : " << nodeFile << endl
<< " elems : " << eleFile << endl
<< " faces : " << faceFile << endl
<< endl;
if (readFaceFile)
{ {
Info<< "Reading .file for boundary information" << nl << endl; Info<< "Files:" << endl
} << " nodes : " << nodeFile << endl
if (startAt1) << " elems : " << eleFile << endl
{ << endl;
Info<< "Numbering in files starts at 1" << nl << endl;
} }
else else
{ {
Info<< "Numbering in files starts at 0" << nl << endl; Info<< "Files:" << endl
} << " nodes : " << nodeFile << endl
<< " elems : " << eleFile << endl
<< " faces : " << faceFile << endl
<< endl;
Info<< "Reading .face file for boundary information" << nl << endl;
}
if (!exists(nodeFile) || !exists(eleFile)) if (!exists(nodeFile) || !exists(eleFile))
{ {
@ -134,7 +124,7 @@ int main(int argc, char *argv[])
} }
std::ifstream nodeStream(nodeFile.c_str()); IFstream nodeStream(nodeFile);
// //
// Read nodes. // Read nodes.
@ -145,7 +135,7 @@ int main(int argc, char *argv[])
do do
{ {
std::getline(nodeStream, line); nodeStream.getLine(line);
} }
while((line.size() > 0) && (line[0] == '#')); while((line.size() > 0) && (line[0] == '#'));
@ -169,61 +159,60 @@ int main(int argc, char *argv[])
// //
pointField points(nNodes); pointField points(nNodes);
Map<label> nodeToPoint(nNodes);
label pointI = 0;
while (nodeStream.good())
{ {
std::getline(nodeStream, line); labelList pointIndex(nNodes);
if ((line.size() > 0) && (line[0] != '#')) label pointI = 0;
while (nodeStream.good())
{ {
IStringStream nodeLine(line); nodeStream.getLine(line);
label nodeI; if ((line.size() > 0) && (line[0] != '#'))
scalar x, y, z;
label dummy;
nodeLine >> nodeI >> x >> y >> z;
for (label i = 0; i < nNodeAttr; i++)
{ {
nodeLine >> dummy; IStringStream nodeLine(line);
}
if (hasRegion) label nodeI;
{ scalar x, y, z;
nodeLine >> dummy; label dummy;
}
// Store point and node number. nodeLine >> nodeI >> x >> y >> z;
if
(
(!startAt1 && nodeI != pointI)
|| (startAt1 && nodeI-1 != pointI)
)
{
FatalErrorIn(args.executable())
<< "point numbering not consecutive for node " << nodeI
<< " or numbering starts"
<< " at 0 or 1. Perhaps rerun w/o -startAt0 option?"
<< exit(FatalError);
}
points[pointI++] = point(x, y, z); for (label i = 0; i < nNodeAttr; i++)
{
nodeLine >> dummy;
}
if (hasRegion)
{
nodeLine >> dummy;
}
// Store point and node number.
points[pointI] = point(x, y, z);
nodeToPoint.insert(nodeI, pointI);
pointI++;
}
}
if (pointI != nNodes)
{
FatalIOErrorIn(args.executable().c_str(), nodeStream)
<< "Only " << pointI << " nodes present instead of " << nNodes
<< " from header." << exit(FatalIOError);
} }
} }
// //
// read elements // read elements
// //
std::ifstream eleStream(eleFile.c_str()); IFstream eleStream(eleFile);
do do
{ {
std::getline(eleStream, line); eleStream.getLine(line);
} }
while((line.size() > 0) && (line[0] == '#')); while((line.size() > 0) && (line[0] == '#'));
@ -242,10 +231,11 @@ int main(int argc, char *argv[])
if (nPtsPerTet != 4) if (nPtsPerTet != 4)
{ {
FatalErrorIn(args.executable()) << "Cannot handle tets with " FatalIOErrorIn(args.executable().c_str(), eleStream)
<< "Cannot handle tets with "
<< nPtsPerTet << " points per tetrahedron in .ele file" << endl << nPtsPerTet << " points per tetrahedron in .ele file" << endl
<< "Can only handle tetrahedra with four points" << "Can only handle tetrahedra with four points"
<< exit(FatalError); << exit(FatalIOError);
} }
if (nElemAttr != 0) if (nElemAttr != 0)
@ -262,39 +252,27 @@ int main(int argc, char *argv[])
labelList tetPoints(4); labelList tetPoints(4);
cellShapeList cells(nTets); cellShapeList cells(nTets);
label cellI = 0;
while (eleStream.good()) while (eleStream.good())
{ {
std::getline(eleStream, line); eleStream.getLine(line);
if ((line.size() > 0) && (line[0] != '#')) if ((line.size() > 0) && (line[0] != '#'))
{ {
IStringStream eleLine(line); IStringStream eleLine(line);
label elemI; label elemI;
eleLine >> elemI; eleLine >> elemI;
if (startAt1)
{
--elemI;
}
for (label i = 0; i < 4; i++) for (label i = 0; i < 4; i++)
{ {
label nodeI; label nodeI;
eleLine >> nodeI; eleLine >> nodeI;
tetPoints[i] = nodeToPoint[nodeI];
if (startAt1)
{
--nodeI;
}
tetPoints[i] = nodeI;
} }
cells[elemI] = cellShape(tet, tetPoints); cells[cellI++] = cellShape(tet, tetPoints);
// Skip attributes // Skip attributes
for (label i = 0; i < nElemAttr; i++) for (label i = 0; i < nElemAttr; i++)
@ -321,11 +299,11 @@ int main(int argc, char *argv[])
// read boundary faces // read boundary faces
// //
std::ifstream faceStream(faceFile.c_str()); IFstream faceStream(faceFile);
do do
{ {
std::getline(faceStream, line); faceStream.getLine(line);
} }
while((line.size() > 0) && (line[0] == '#')); while((line.size() > 0) && (line[0] == '#'));
@ -344,10 +322,11 @@ int main(int argc, char *argv[])
if (nFaceAttr != 1) if (nFaceAttr != 1)
{ {
FatalErrorIn(args.executable()) << "Expect boundary markers to be" FatalIOErrorIn(args.executable().c_str(), faceStream)
<< "Expect boundary markers to be"
<< " present in .face file." << endl << " present in .face file." << endl
<< "This is the second number in the header which is now:" << "This is the second number in the header which is now:"
<< nFaceAttr << exit(FatalError); << nFaceAttr << exit(FatalIOError);
} }
// List of Foam vertices per boundary face // List of Foam vertices per boundary face
@ -357,6 +336,8 @@ int main(int argc, char *argv[])
boundaryPatch.setSize(nFaces); boundaryPatch.setSize(nFaces);
boundaryPatch = -1; boundaryPatch = -1;
label faceI = 0;
// Region to patch conversion // Region to patch conversion
Map<label> regionToPatch; Map<label> regionToPatch;
@ -364,35 +345,23 @@ int main(int argc, char *argv[])
while (faceStream.good()) while (faceStream.good())
{ {
std::getline(faceStream, line); faceStream.getLine(line);
if ((line.size() > 0) && (line[0] != '#')) if ((line.size() > 0) && (line[0] != '#'))
{ {
IStringStream faceLine(line); IStringStream faceLine(line);
label faceI, dummy, region; label tetGenFaceI, dummy, region;
faceLine >> faceI; faceLine >> tetGenFaceI;
if (startAt1)
{
--faceI;
}
// Read face and reverse orientation (Foam needs outwards // Read face and reverse orientation (Foam needs outwards
// pointing) // pointing)
for (label i = 0; i < 3; i++) for (label i = 0; i < 3; i++)
{ {
label nodeI; label nodeI;
faceLine >> nodeI; faceLine >> nodeI;
f[2-i] = nodeToPoint[nodeI];
if (startAt1)
{
--nodeI;
}
f[2-i] = nodeI;
} }
boundaryFaces[faceI] = f; boundaryFaces[faceI] = f;
@ -431,6 +400,8 @@ int main(int argc, char *argv[])
faceLine >> dummy; faceLine >> dummy;
} }
} }
faceI++;
} }
} }