mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: handle msh2.2 format
This commit is contained in:
@ -233,6 +233,44 @@ void storeCellInZone
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Reads mesh format
|
||||||
|
scalar readMeshFormat(IFstream& inFile)
|
||||||
|
{
|
||||||
|
Info<< "Starting to read mesh format at line " << inFile.lineNumber() << endl;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
inFile.getLine(line);
|
||||||
|
IStringStream lineStr(line);
|
||||||
|
|
||||||
|
scalar version;
|
||||||
|
label asciiFlag, nBytes;
|
||||||
|
lineStr >> version >> asciiFlag >> nBytes;
|
||||||
|
|
||||||
|
Info<< "Read format version " << version << " ascii " << asciiFlag << endl;
|
||||||
|
|
||||||
|
if (asciiFlag != 0)
|
||||||
|
{
|
||||||
|
FatalIOErrorIn("readMeshFormat(IFstream&)", inFile)
|
||||||
|
<< "Can only read ascii msh files."
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
inFile.getLine(line);
|
||||||
|
IStringStream tagStr(line);
|
||||||
|
word tag(tagStr);
|
||||||
|
|
||||||
|
if (tag != "$EndMeshFormat")
|
||||||
|
{
|
||||||
|
FatalIOErrorIn("readMeshFormat(IFstream&)", inFile)
|
||||||
|
<< "Did not find $ENDNOD tag on line "
|
||||||
|
<< inFile.lineNumber() << exit(FatalIOError);
|
||||||
|
}
|
||||||
|
Info<< endl;
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reads points and map
|
// Reads points and map
|
||||||
void readPoints(IFstream& inFile, pointField& points, Map<label>& mshToFoam)
|
void readPoints(IFstream& inFile, pointField& points, Map<label>& mshToFoam)
|
||||||
{
|
{
|
||||||
@ -278,9 +316,9 @@ void readPoints(IFstream& inFile, pointField& points, Map<label>& mshToFoam)
|
|||||||
|
|
||||||
if (tag != "$ENDNOD" && tag != "$EndNodes")
|
if (tag != "$ENDNOD" && tag != "$EndNodes")
|
||||||
{
|
{
|
||||||
FatalErrorIn("readPoints(..)")
|
FatalIOErrorIn("readPoints(..)", inFile)
|
||||||
<< "Did not find $ENDNOD tag on line "
|
<< "Did not find $ENDNOD tag on line "
|
||||||
<< inFile.lineNumber() << exit(FatalError);
|
<< inFile.lineNumber() << exit(FatalIOError);
|
||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
}
|
}
|
||||||
@ -351,9 +389,9 @@ void readPhysNames(IFstream& inFile, Map<word>& physicalNames)
|
|||||||
|
|
||||||
if (tag != "$EndPhysicalNames")
|
if (tag != "$EndPhysicalNames")
|
||||||
{
|
{
|
||||||
FatalErrorIn("readPhysicalNames(..)")
|
FatalIOErrorIn("readPhysicalNames(..)", inFile)
|
||||||
<< "Did not find $EndPhysicalNames tag on line "
|
<< "Did not find $EndPhysicalNames tag on line "
|
||||||
<< inFile.lineNumber() << exit(FatalError);
|
<< inFile.lineNumber() << exit(FatalIOError);
|
||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
}
|
}
|
||||||
@ -362,7 +400,7 @@ void readPhysNames(IFstream& inFile, Map<word>& physicalNames)
|
|||||||
// Reads cells and patch faces
|
// Reads cells and patch faces
|
||||||
void readCells
|
void readCells
|
||||||
(
|
(
|
||||||
const bool version2Format,
|
const scalar versionFormat,
|
||||||
const bool keepOrientation,
|
const bool keepOrientation,
|
||||||
const pointField& points,
|
const pointField& points,
|
||||||
const Map<label>& mshToFoam,
|
const Map<label>& mshToFoam,
|
||||||
@ -426,23 +464,18 @@ void readCells
|
|||||||
|
|
||||||
label elmNumber, elmType, regPhys;
|
label elmNumber, elmType, regPhys;
|
||||||
|
|
||||||
if (version2Format)
|
if (versionFormat >= 2)
|
||||||
{
|
{
|
||||||
lineStr >> elmNumber >> elmType;
|
lineStr >> elmNumber >> elmType;
|
||||||
|
|
||||||
label nTags;
|
label nTags;
|
||||||
lineStr>> nTags;
|
lineStr>> nTags;
|
||||||
|
|
||||||
label regElem, partition;
|
if (nTags > 0)
|
||||||
|
|
||||||
if (nTags == 3)
|
|
||||||
{
|
{
|
||||||
lineStr >> regPhys >> regElem >> partition;
|
// Assume the first tag is the physical surface
|
||||||
}
|
lineStr >> regPhys;
|
||||||
else
|
for (label i = 1; i < nTags; i++)
|
||||||
{
|
|
||||||
regPhys = 0;
|
|
||||||
for (label i = 0; i < nTags; i++)
|
|
||||||
{
|
{
|
||||||
label dummy;
|
label dummy;
|
||||||
lineStr>> dummy;
|
lineStr>> dummy;
|
||||||
@ -659,9 +692,9 @@ void readCells
|
|||||||
|
|
||||||
if (tag != "$ENDELM" && tag != "$EndElements")
|
if (tag != "$ENDELM" && tag != "$EndElements")
|
||||||
{
|
{
|
||||||
FatalErrorIn("readCells(..)")
|
FatalIOErrorIn("readCells(..)", inFile)
|
||||||
<< "Did not find $ENDELM tag on line "
|
<< "Did not find $ENDELM tag on line "
|
||||||
<< inFile.lineNumber() << exit(FatalError);
|
<< inFile.lineNumber() << exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -683,13 +716,13 @@ void readCells
|
|||||||
|
|
||||||
if (cells.size() == 0)
|
if (cells.size() == 0)
|
||||||
{
|
{
|
||||||
FatalErrorIn("readCells(..)")
|
FatalIOErrorIn("readCells(..)", inFile)
|
||||||
<< "No cells read from file " << inFile.name() << nl
|
<< "No cells read from file " << inFile.name() << nl
|
||||||
<< "Does your file specify any 3D elements (hex=" << MSHHEX
|
<< "Does your file specify any 3D elements (hex=" << MSHHEX
|
||||||
<< ", prism=" << MSHPRISM << ", pyramid=" << MSHPYR
|
<< ", prism=" << MSHPRISM << ", pyramid=" << MSHPYR
|
||||||
<< ", tet=" << MSHTET << ")?" << nl
|
<< ", tet=" << MSHTET << ")?" << nl
|
||||||
<< "Perhaps you have not exported the 3D elements?"
|
<< "Perhaps you have not exported the 3D elements?"
|
||||||
<< exit(FatalError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< "CellZones:" << nl
|
Info<< "CellZones:" << nl
|
||||||
@ -749,7 +782,8 @@ int main(int argc, char *argv[])
|
|||||||
Map<word> physicalNames;
|
Map<word> physicalNames;
|
||||||
|
|
||||||
// Version 1 or 2 format
|
// Version 1 or 2 format
|
||||||
bool version2Format = false;
|
scalar versionFormat = 1;
|
||||||
|
|
||||||
|
|
||||||
while (inFile.good())
|
while (inFile.good())
|
||||||
{
|
{
|
||||||
@ -761,14 +795,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (tag == "$MeshFormat")
|
if (tag == "$MeshFormat")
|
||||||
{
|
{
|
||||||
Info<< "Found $MeshFormat tag; assuming version 2 file format."
|
versionFormat = readMeshFormat(inFile);
|
||||||
<< endl;
|
|
||||||
version2Format = true;
|
|
||||||
|
|
||||||
if (!skipSection(inFile))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (tag == "$PhysicalNames")
|
else if (tag == "$PhysicalNames")
|
||||||
{
|
{
|
||||||
@ -782,7 +809,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
readCells
|
readCells
|
||||||
(
|
(
|
||||||
version2Format,
|
versionFormat,
|
||||||
keepOrientation,
|
keepOrientation,
|
||||||
points,
|
points,
|
||||||
mshToFoam,
|
mshToFoam,
|
||||||
|
|||||||
Reference in New Issue
Block a user