Added line number counting, more accommodating point parsing and updated

handling of "uniform", "mixed" and "polygonal" face lists.  Now converts
.cas files as well as .msh files.
This commit is contained in:
henry
2008-11-18 14:57:44 +00:00
parent a622a9a0ec
commit 7c0048e878

View File

@ -54,7 +54,10 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Scalae factor used to scale points (optional command line argument) // Line number
label lineNo = 1;
// Scale factor used to scale points (optional command line argument)
scalar scaleFactor = 1.0; scalar scaleFactor = 1.0;
label dimensionOfGrid = 0; label dimensionOfGrid = 0;
@ -131,8 +134,6 @@ one_space [ \t\f]
space {one_space}* space {one_space}*
some_space {one_space}+ some_space {one_space}+
cspace ","{space} cspace ","{space}
nl (\n|\r)
spaceNl ({space}|{nl})*
alpha [_[:alpha:]] alpha [_[:alpha:]]
digit [[:digit:]] digit [[:digit:]]
@ -146,7 +147,7 @@ quote \"
dash "-" dash "-"
dotColonDash [.:-] dotColonDash [.:-]
schemeSpecialInitial [!$%&*/\\:<=>?~_^#.@] schemeSpecialInitial [!$%&*/\\:<=>?~_^#.@']
schemeSpecialSubsequent [.+-] schemeSpecialSubsequent [.+-]
schemeSymbol (({some_space}|{alpha}|{quote}|{schemeSpecialInitial})({alpha}|{quote}|{digit}|{schemeSpecialInitial}|{schemeSpecialSubsequent})*) schemeSymbol (({some_space}|{alpha}|{quote}|{schemeSpecialInitial})({alpha}|{quote}|{digit}|{schemeSpecialInitial}|{schemeSpecialSubsequent})*)
@ -187,23 +188,23 @@ time ({digit}{digit}":"{digit}{digit}":"{digit}{digit})
versionNumber ({digit}|".")* versionNumber ({digit}|".")*
header {spaceNl}"(1"{space} header {space}"(1"{space}
dimension {spaceNl}"(2"{space} dimension {space}"(2"{space}
points {spaceNl}"(10"{space} points {space}"(10"{space}
faces {spaceNl}"(13"{space} faces {space}"(13"{space}
cells {spaceNl}"(12"{space} cells {space}"(12"{space}
zoneVariant1 {spaceNl}"(39"{space} zoneVariant1 {space}"(39"{space}
zoneVariant2 {spaceNl}"(45"{space} zoneVariant2 {space}"(45"{space}
faceTree {spaceNl}"(59"{space} faceTree {space}"(59"{space}
comment "0"{space} comment "0"{space}
unknownPeriodicFace "17"{space} unknownPeriodicFace "17"{space}
periodicFace "18"{space} periodicFace "18"{space}
cellTree "58"{space} cellTree "58"{space}
faceParents "61"{space} faceParents "61"{space}
ignoreBlocks ("4"|"37"|"38"|"41"|"60"|"64"){space} ignoreBlocks ("4"|"37"|"38"|"40"|"41"|"60"|"64"){space}
redundantBlock {spaceNl}({comment}|{unknownPeriodicFace}|{periodicFace}|{cellTree}|{faceParents}|{ignoreBlocks}){space} redundantBlock {space}({comment}|{unknownPeriodicFace}|{periodicFace}|{cellTree}|{faceParents}|{ignoreBlocks}){space}
endOfSection {space}")"{space} endOfSection {space}")"{space}
@ -290,7 +291,7 @@ endOfSection {space}")"{space}
BEGIN(readPointHeader); BEGIN(readPointHeader);
} }
<readPointHeader>{spaceNl}{lbrac}{space}"0"{space}"1"{space} { <readPointHeader>{space}{lbrac}{space}"0"{space}"1"{space} {
BEGIN(readNumberOfPoints); BEGIN(readNumberOfPoints);
} }
@ -302,7 +303,7 @@ endOfSection {space}")"{space}
// Ignore rest of stream // Ignore rest of stream
} }
<readPointHeader>{spaceNl}{lbrac} { <readPointHeader>{space}{lbrac} {
BEGIN(readPointGroupData); BEGIN(readPointGroupData);
} }
@ -342,7 +343,7 @@ endOfSection {space}")"{space}
BEGIN(readPointData); BEGIN(readPointData);
} }
<readPointData>{spaceNl}{lbrac}{spaceNl} { <readPointData>{space}{lbrac}{space} {
Info<< ". Reading points..." << flush; Info<< ". Reading points..." << flush;
cmpt = 0; cmpt = 0;
yy_push_state(readScalarList); yy_push_state(readScalarList);
@ -350,19 +351,32 @@ endOfSection {space}")"{space}
<readScalarList>{signedInteger}{space} { <readScalarList>{signedInteger}{space} {
points[pointi][cmpt++] = scaleFactor*atol(YYText()); points[pointi][cmpt++] = scaleFactor*atol(YYText());
if (cmpt == pointGroupNumberOfComponents)
{
if (pointGroupNumberOfComponents == 2)
{
points[pointi].z() = 0.0;
}
cmpt = 0;
pointi++;
}
} }
<readScalarList>{scalar}{space} { <readScalarList>{scalar}{space} {
points[pointi][cmpt++] = scaleFactor*atof(YYText()); points[pointi][cmpt++] = scaleFactor*atof(YYText());
}
<readScalarList>{spaceNl} { if (cmpt == pointGroupNumberOfComponents)
if (pointGroupNumberOfComponents == 2)
{ {
points[pointi].z() = 0.0; if (pointGroupNumberOfComponents == 2)
{
points[pointi].z() = 0.0;
}
cmpt = 0;
pointi++;
} }
cmpt = 0;
pointi++;
} }
<readScalarList>{endOfSection} { <readScalarList>{endOfSection} {
@ -372,12 +386,13 @@ endOfSection {space}")"{space}
if (pointi != pointGroupEndIndex[pointGroupEndIndex.size()-1]+1) if (pointi != pointGroupEndIndex[pointGroupEndIndex.size()-1]+1)
{ {
Warning Warning
<< "Problem with reading points: " << "Problem with reading points: " << nl
<< "start index: " << " start index: "
<< pointGroupStartIndex[pointGroupStartIndex.size()-1] << pointGroupStartIndex[pointGroupStartIndex.size()-1]
<< " end index: " << " end index: "
<< pointGroupEndIndex[pointGroupEndIndex.size()-1] << pointGroupEndIndex[pointGroupEndIndex.size()-1]
<< " last points read: " << pointi << endl; << " last points read: " << pointi << nl
<< " on line " << lineNo << endl;
} }
yy_pop_state(); yy_pop_state();
@ -387,7 +402,7 @@ endOfSection {space}")"{space}
BEGIN(readFaceHeader); BEGIN(readFaceHeader);
} }
<readFaceHeader>{spaceNl}{lbrac}{space}"0"{space}"1"{space} { <readFaceHeader>{space}{lbrac}{space}"0"{space}"1"{space} {
BEGIN(readNumberOfFaces); BEGIN(readNumberOfFaces);
} }
@ -403,7 +418,7 @@ endOfSection {space}")"{space}
// Type and element type not read // Type and element type not read
} }
<readFaceHeader>{spaceNl}{lbrac} { <readFaceHeader>{space}{lbrac} {
BEGIN(readFaceGroupData); BEGIN(readFaceGroupData);
} }
@ -431,12 +446,12 @@ endOfSection {space}")"{space}
<< faceGroupEndIndex[faceGroupEndIndex.size()-1] << flush; << faceGroupEndIndex[faceGroupEndIndex.size()-1] << flush;
} }
<readNumberOfFaces,readFaceGroupData>{spaceNl}{endOfSection} { <readNumberOfFaces,readFaceGroupData>{space}{endOfSection} {
BEGIN(readFaceData); BEGIN(readFaceData);
} }
<readFaceData>{spaceNl}{lbrac} { <readFaceData>{space}{lbrac} {
if (faceGroupElementType == 0) if (faceGroupElementType == 0 || faceGroupElementType > 4)
{ {
Info<< ". Reading mixed faces..." << flush; Info<< ". Reading mixed faces..." << flush;
yy_push_state(readFacesMixed); yy_push_state(readFacesMixed);
@ -448,7 +463,7 @@ endOfSection {space}")"{space}
} }
} }
<readFacesMixed>{spaceNl}{hexLabelList} { <readFacesMixed>{space}{hexLabelList} {
face& curFaceLabels = faces[facei]; face& curFaceLabels = faces[facei];
// set size of label list // set size of label list
@ -465,7 +480,7 @@ endOfSection {space}")"{space}
facei++; facei++;
} }
<readFacesUniform>{spaceNl}{hexLabelList} { <readFacesUniform>{space}{hexLabelList} {
face& curFaceLabels = faces[facei]; face& curFaceLabels = faces[facei];
// Set size of label list. // Set size of label list.
@ -484,19 +499,20 @@ endOfSection {space}")"{space}
facei++; facei++;
} }
<readFacesMixed,readFacesUniform>{spaceNl}{endOfSection} { <readFacesMixed,readFacesUniform>{space}{endOfSection} {
Info<< "done." << endl; Info<< "done." << endl;
// check read of fluentFaces // check read of fluentFaces
if (facei != faceGroupEndIndex[faceGroupEndIndex.size()-1]+1) if (facei != faceGroupEndIndex[faceGroupEndIndex.size()-1]+1)
{ {
Warning Warning
<< "Problem with reading fluentFaces: " << "Problem with reading fluentFaces: " << nl
<< "start index: " << " start index: "
<< faceGroupStartIndex[faceGroupStartIndex.size()-1] << faceGroupStartIndex[faceGroupStartIndex.size()-1]
<< " end index: " << " end index: "
<< faceGroupEndIndex[faceGroupEndIndex.size()-1] << faceGroupEndIndex[faceGroupEndIndex.size()-1]
<< " last fluentFaces read: " << facei << endl; << " last fluentFaces read: " << facei << nl
<< " on line " << lineNo << endl;
} }
yy_pop_state(); yy_pop_state();
@ -507,7 +523,7 @@ endOfSection {space}")"{space}
BEGIN(readCellHeader); BEGIN(readCellHeader);
} }
<readCellHeader>{spaceNl}{lbrac}{space}"0"{space}"1"{space} { <readCellHeader>{space}{lbrac}{space}"0"{space}"1"{space} {
BEGIN(readNumberOfCells); BEGIN(readNumberOfCells);
} }
@ -516,7 +532,7 @@ endOfSection {space}")"{space}
Info<< "Number of cells: " << nCells << endl; Info<< "Number of cells: " << nCells << endl;
} }
<readCellHeader>{spaceNl}{lbrac} { <readCellHeader>{space}{lbrac} {
BEGIN(readCellGroupData); BEGIN(readCellGroupData);
} }
@ -526,7 +542,8 @@ endOfSection {space}")"{space}
// non-standard cell definition from Tgrid, which misses the type label. // non-standard cell definition from Tgrid, which misses the type label.
Warning Warning
<< "Tgrid syntax problem: " << YYText() << endl; << "Tgrid syntax problem: " << YYText() << nl
<< " on line " << lineNo << endl;
// read cell zone-ID, start and end-label // read cell zone-ID, start and end-label
cellGroupZoneID.append(strtol(YYText(), &endPtr, 16)); cellGroupZoneID.append(strtol(YYText(), &endPtr, 16));
@ -580,7 +597,7 @@ endOfSection {space}")"{space}
BEGIN(readCellData); BEGIN(readCellData);
} }
<readCellData>{spaceNl}{lbrac} { <readCellData>{space}{lbrac} {
// Quickly scan to the end of the cell data block and discard // Quickly scan to the end of the cell data block and discard
register int c; register int c;
while ((c = yyinput()) != 0 && c != ')') while ((c = yyinput()) != 0 && c != ')')
@ -601,7 +618,7 @@ endOfSection {space}")"{space}
BEGIN(readZoneHeader); BEGIN(readZoneHeader);
} }
<readZoneHeader>{spaceNl}{lbrac} { <readZoneHeader>{space}{lbrac} {
BEGIN(readZoneGroupData); BEGIN(readZoneGroupData);
} }
@ -623,17 +640,18 @@ endOfSection {space}")"{space}
BEGIN(readZoneData); BEGIN(readZoneData);
} }
<readZoneData>{spaceNl}{lbrac} { <readZoneData>{space}{lbrac} {
Info<< ". Reading zone data..." << flush; Info<< ". Reading zone data..." << flush;
yy_push_state(readZoneBlock); yy_push_state(readZoneBlock);
} }
<readZoneBlock>{spaceNl}{schemeSymbolList} { <readZoneBlock>{space}{schemeSymbolList} {
} }
<readZoneBlock>{lbrac} { <readZoneBlock>{lbrac} {
Warning //Warning
<< "Found unknown block in zone: " << YYText() << endl; // << "Found unknown block in zone: " << YYText() << nl
// << " on line " << lineNo << endl;
yy_push_state(ignoreBlock); yy_push_state(ignoreBlock);
} }
@ -646,7 +664,7 @@ endOfSection {space}")"{space}
/* ------ Reading end of section and others ------ */ /* ------ Reading end of section and others ------ */
<readHeader,readDimension,readPointData,readFaceData,readCellData,readZoneData>{spaceNl}{endOfSection} { <readHeader,readDimension,readPointData,readFaceData,readCellData,readZoneData>{space}{endOfSection} {
BEGIN(INITIAL); BEGIN(INITIAL);
} }
@ -655,7 +673,8 @@ endOfSection {space}")"{space}
{lbrac}{label} { {lbrac}{label} {
Warning Warning
<< "Found unknown block of type: " << "Found unknown block of type: "
<< Foam::string(YYText())(1, YYLeng()-1) << endl; << Foam::string(YYText())(1, YYLeng()-1) << nl
<< " on line " << lineNo << endl;
yy_push_state(ignoreBlock); yy_push_state(ignoreBlock);
} }
@ -664,40 +683,47 @@ endOfSection {space}")"{space}
yy_push_state(ignoreBlock); yy_push_state(ignoreBlock);
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{quote}{text}{quote} { <ignoreBlock,ignoreEmbeddedBlock>{space}{quote}{text}{quote} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{schemeSymbol} { <ignoreBlock,ignoreEmbeddedBlock>{space}{schemeSymbol} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{lbrac} { <ignoreBlock,ignoreEmbeddedBlock>{space}{lbrac} {
yy_push_state(ignoreEmbeddedBlock); yy_push_state(ignoreEmbeddedBlock);
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{endOfSection} { <ignoreBlock,ignoreEmbeddedBlock>{space}{endOfSection} {
yy_pop_state(); yy_pop_state();
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{labelList} { <ignoreBlock,ignoreEmbeddedBlock>{space}{labelList} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{hexLabelList} { <ignoreBlock,ignoreEmbeddedBlock>{space}{hexLabelList} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{scalarList} { <ignoreBlock,ignoreEmbeddedBlock>{space}{scalarList} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{schemeSymbolList} { <ignoreBlock,ignoreEmbeddedBlock>{space}{schemeSymbolList} {
} }
<ignoreBlock,ignoreEmbeddedBlock>{spaceNl}{text} { <ignoreBlock,ignoreEmbeddedBlock>{space}{text} {
} }
/* ------ Ignore remaining space and \n s. ------ */ /* ------ Count newlines. ------ */
<*>{some_space}|\n|\r { <*>\n {
lineNo++;
}
/* ------ Ignore remaining space. ------ */
<*>{some_space}|\r {
} }
@ -706,7 +732,8 @@ endOfSection {space}")"{space}
<*>. { <*>. {
// This is a catch all. // This is a catch all.
FatalErrorIn("fluentMeshToFoam::lexer") FatalErrorIn("fluentMeshToFoam::lexer")
<< "Do not understand characters: " << YYText() << "Do not understand characters: " << YYText() << nl
<< " on line " << lineNo
<< exit(FatalError); << exit(FatalError);
} }
@ -882,11 +909,8 @@ int main(int argc, char *argv[])
// Check the face groups for boundary patches, baffles and faceZones // Check the face groups for boundary patches, baffles and faceZones
// ignoring the interior zones in ignoreCellGroups // ignoring the interior zones in ignoreCellGroups
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
label nPatches = 0; DynamicList<label> patchIDs(faceGroupZoneID.size());
labelList patchIDs(faceGroupZoneID.size()); DynamicList<label> faceZoneIDs(faceGroupZoneID.size());
label nFaceZones = 0;
labelList faceZoneIDs(faceGroupZoneID.size());
forAll(faceGroupZoneID, fgi) forAll(faceGroupZoneID, fgi)
{ {
@ -900,13 +924,13 @@ int main(int argc, char *argv[])
// Check the first element of neighbour for boundary group // Check the first element of neighbour for boundary group
if (neighbour[start] == -1 || fluentGroupToFoamPatch.found(type)) if (neighbour[start] == -1 || fluentGroupToFoamPatch.found(type))
{ {
patchIDs[nPatches++] = fgi; patchIDs.append(fgi);
} }
else else
{ {
if (!ignoreFaceGroups.found(groupName[faceGroupZoneID[fgi] ])) if (!ignoreFaceGroups.found(groupName[faceGroupZoneID[fgi]]))
{ {
faceZoneIDs[nFaceZones++] = fgi; faceZoneIDs.append(fgi);
} }
} }
} }
@ -928,20 +952,32 @@ int main(int argc, char *argv[])
} }
else else
{ {
FatalErrorIn(args.executable()) if (neighbour[start] == -1)
<< "Unknown FaceGroup " << zoneID << " not in a zone" {
<< exit(FatalError); // Boundary face in unknown group. Create a patch for it.
groupType.insert(zoneID, "unknown");
groupName.insert(zoneID, "FaceGroup" + Foam::name(zoneID));
patchIDs.append(fgi);
Info<< "Created patch " << fgi << " for unknown FaceGroup "
<< zoneID << '.' << endl;
}
else
{
WarningIn(args.executable())
<< "Unknown FaceGroup " << zoneID << " not in a zone"
<< endl;
}
} }
} }
patchIDs.setSize(nPatches); patchIDs.shrink();
faceZoneIDs.setSize(nFaceZones); faceZoneIDs.shrink();
// Add empty patches // Add empty patches
// ~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~
List<polyPatch*> newPatches(nPatches); List<polyPatch*> newPatches(patchIDs.size());
HashSet<word> patchNames; HashSet<word> patchNames;
forAll(patchIDs, patchi) forAll(patchIDs, patchi)
@ -1024,7 +1060,7 @@ int main(int argc, char *argv[])
} }
// Face zones // Face zones
mesh.faceZones().setSize(nFaceZones); mesh.faceZones().setSize(faceZoneIDs.size());
HashSet<word> faceZoneNames; HashSet<word> faceZoneNames;
forAll(faceZoneIDs, faceZonei) forAll(faceZoneIDs, faceZonei)
@ -1098,6 +1134,8 @@ int main(int argc, char *argv[])
} }
bool doneWarning = false;
// Add faceZone faces // Add faceZone faces
forAll(faceZoneIDs, faceZonei) forAll(faceZoneIDs, faceZonei)
{ {
@ -1113,19 +1151,36 @@ int main(int argc, char *argv[])
for (label facei = start; facei <= end; facei++) for (label facei = start; facei <= end; facei++)
{ {
meshMod.addFace if (owner[facei] >= nCells || neighbour[facei] >= nCells)
( {
faces[facei], if (!doneWarning)
owner[facei], {
neighbour[facei], WarningIn(args.executable())
-1, // masterPointID << "Ignoring internal face " << facei
-1, // masterEdgeID << " on FaceZone " << zoneID
facei, // masterFace << " since owner " << owner[facei] << " or neighbour "
false, // flipFaceFlux << neighbour[facei] << " outside range of cells 0.."
-1, // patchID << nCells-1 << endl
faceZonei, // zoneID << " Suppressing future warnings." << endl;
false // zoneFlip doneWarning = true;
); }
}
else
{
meshMod.addFace
(
faces[facei],
owner[facei],
neighbour[facei],
-1, // masterPointID
-1, // masterEdgeID
facei, // masterFace
false, // flipFaceFlux
-1, // patchID
faceZonei, // zoneID
false // zoneFlip
);
}
// Mark face as being done // Mark face as being done
owner[facei] = -1; owner[facei] = -1;
@ -1147,27 +1202,26 @@ int main(int argc, char *argv[])
for (label facei = start; facei <= end; facei++) for (label facei = start; facei <= end; facei++)
{ {
meshMod.addFace if (owner[facei] >= nCells || neighbour[facei] >= nCells)
( {
faces[facei], if (!doneWarning)
owner[facei], {
-1, WarningIn(args.executable())
-1, // masterPointID << "Ignoring patch face " << facei
-1, // masterEdgeID << " on FaceZone " << zoneID
facei, // masterFace << " since owner " << owner[facei] << " or neighbour "
false, // flipFaceFlux << neighbour[facei] << " outside range of cells 0.."
patchi, // patchID << nCells-1 << endl
-1, // zoneID << " Suppressing future warnings." << endl;
false // zoneFlip doneWarning = true;
); }
}
// For baffles create the opposite face else
if (neighbour[start] != -1)
{ {
meshMod.addFace meshMod.addFace
( (
faces[facei].reverseFace(), faces[facei],
neighbour[facei], owner[facei],
-1, -1,
-1, // masterPointID -1, // masterPointID
-1, // masterEdgeID -1, // masterEdgeID
@ -1177,8 +1231,25 @@ int main(int argc, char *argv[])
-1, // zoneID -1, // zoneID
false // zoneFlip false // zoneFlip
); );
}
// For baffles create the opposite face
if (neighbour[start] != -1)
{
meshMod.addFace
(
faces[facei].reverseFace(),
neighbour[facei],
-1,
-1, // masterPointID
-1, // masterEdgeID
facei, // masterFace
false, // flipFaceFlux
patchi, // patchID
-1, // zoneID
false // zoneFlip
);
}
}
// Mark face as being done // Mark face as being done
owner[facei] = -1; owner[facei] = -1;
} }
@ -1198,19 +1269,35 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
meshMod.addFace if (owner[facei] >= nCells || neighbour[facei] >= nCells)
( {
faces[facei], if (!doneWarning)
owner[facei], {
neighbour[facei], WarningIn(args.executable())
-1, //masterPointID << "Ignoring internal face " << facei
-1, //masterEdgeID << " since owner " << owner[facei] << " or neighbour "
facei, //masterFace << neighbour[facei] << " outside range of cells 0.."
false, //flipFaceFlux << nCells-1 << endl
-1, //patchID << " Suppressing future warnings." << endl;
-1, //zoneID doneWarning = true;
false //zoneFlip }
); }
else
{
meshMod.addFace
(
faces[facei],
owner[facei],
neighbour[facei],
-1, //masterPointID
-1, //masterEdgeID
facei, //masterFace
false, //flipFaceFlux
-1, //patchID
-1, //zoneID
false //zoneFlip
);
}
} }
} }