From 996a258e529d5b7603d8b4c5eb9f494733efbc2b Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 18 Nov 2008 15:00:10 +0000 Subject: [PATCH] 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. --- .../fluent3DMeshToFoam/fluent3DMeshToFoam.L | 327 +++++++++++++-------- 1 file changed, 207 insertions(+), 120 deletions(-) diff --git a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L index 46eb810..e9a96a6 100644 --- a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L +++ b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L @@ -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; label dimensionOfGrid = 0; @@ -131,8 +134,6 @@ one_space [ \t\f] space {one_space}* some_space {one_space}+ cspace ","{space} -nl (\n|\r) -spaceNl ({space}|{nl})* alpha [_[:alpha:]] digit [[:digit:]] @@ -146,7 +147,7 @@ quote \" dash "-" dotColonDash [.:-] -schemeSpecialInitial [!$%&*/\\:<=>?~_^#.@] +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}|".")* -header {spaceNl}"(1"{space} -dimension {spaceNl}"(2"{space} -points {spaceNl}"(10"{space} -faces {spaceNl}"(13"{space} -cells {spaceNl}"(12"{space} -zoneVariant1 {spaceNl}"(39"{space} -zoneVariant2 {spaceNl}"(45"{space} -faceTree {spaceNl}"(59"{space} +header {space}"(1"{space} +dimension {space}"(2"{space} +points {space}"(10"{space} +faces {space}"(13"{space} +cells {space}"(12"{space} +zoneVariant1 {space}"(39"{space} +zoneVariant2 {space}"(45"{space} +faceTree {space}"(59"{space} comment "0"{space} unknownPeriodicFace "17"{space} periodicFace "18"{space} cellTree "58"{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} @@ -290,7 +291,7 @@ endOfSection {space}")"{space} BEGIN(readPointHeader); } -{spaceNl}{lbrac}{space}"0"{space}"1"{space} { +{space}{lbrac}{space}"0"{space}"1"{space} { BEGIN(readNumberOfPoints); } @@ -302,7 +303,7 @@ endOfSection {space}")"{space} // Ignore rest of stream } -{spaceNl}{lbrac} { +{space}{lbrac} { BEGIN(readPointGroupData); } @@ -342,7 +343,7 @@ endOfSection {space}")"{space} BEGIN(readPointData); } -{spaceNl}{lbrac}{spaceNl} { +{space}{lbrac}{space} { Info<< ". Reading points..." << flush; cmpt = 0; yy_push_state(readScalarList); @@ -350,19 +351,32 @@ endOfSection {space}")"{space} {signedInteger}{space} { points[pointi][cmpt++] = scaleFactor*atol(YYText()); + + if (cmpt == pointGroupNumberOfComponents) + { + if (pointGroupNumberOfComponents == 2) + { + points[pointi].z() = 0.0; + } + + cmpt = 0; + pointi++; + } } {scalar}{space} { points[pointi][cmpt++] = scaleFactor*atof(YYText()); - } -{spaceNl} { - if (pointGroupNumberOfComponents == 2) + if (cmpt == pointGroupNumberOfComponents) { - points[pointi].z() = 0.0; + if (pointGroupNumberOfComponents == 2) + { + points[pointi].z() = 0.0; + } + + cmpt = 0; + pointi++; } - cmpt = 0; - pointi++; } {endOfSection} { @@ -372,12 +386,13 @@ endOfSection {space}")"{space} if (pointi != pointGroupEndIndex[pointGroupEndIndex.size()-1]+1) { Warning - << "Problem with reading points: " - << "start index: " + << "Problem with reading points: " << nl + << " start index: " << pointGroupStartIndex[pointGroupStartIndex.size()-1] << " end index: " << pointGroupEndIndex[pointGroupEndIndex.size()-1] - << " last points read: " << pointi << endl; + << " last points read: " << pointi << nl + << " on line " << lineNo << endl; } yy_pop_state(); @@ -387,7 +402,7 @@ endOfSection {space}")"{space} BEGIN(readFaceHeader); } -{spaceNl}{lbrac}{space}"0"{space}"1"{space} { +{space}{lbrac}{space}"0"{space}"1"{space} { BEGIN(readNumberOfFaces); } @@ -403,7 +418,7 @@ endOfSection {space}")"{space} // Type and element type not read } -{spaceNl}{lbrac} { +{space}{lbrac} { BEGIN(readFaceGroupData); } @@ -431,12 +446,12 @@ endOfSection {space}")"{space} << faceGroupEndIndex[faceGroupEndIndex.size()-1] << flush; } -{spaceNl}{endOfSection} { +{space}{endOfSection} { BEGIN(readFaceData); } -{spaceNl}{lbrac} { - if (faceGroupElementType == 0) +{space}{lbrac} { + if (faceGroupElementType == 0 || faceGroupElementType > 4) { Info<< ". Reading mixed faces..." << flush; yy_push_state(readFacesMixed); @@ -448,7 +463,7 @@ endOfSection {space}")"{space} } } -{spaceNl}{hexLabelList} { +{space}{hexLabelList} { face& curFaceLabels = faces[facei]; // set size of label list @@ -465,7 +480,7 @@ endOfSection {space}")"{space} facei++; } -{spaceNl}{hexLabelList} { +{space}{hexLabelList} { face& curFaceLabels = faces[facei]; // Set size of label list. @@ -484,19 +499,20 @@ endOfSection {space}")"{space} facei++; } -{spaceNl}{endOfSection} { +{space}{endOfSection} { Info<< "done." << endl; // check read of fluentFaces if (facei != faceGroupEndIndex[faceGroupEndIndex.size()-1]+1) { Warning - << "Problem with reading fluentFaces: " - << "start index: " + << "Problem with reading fluentFaces: " << nl + << " start index: " << faceGroupStartIndex[faceGroupStartIndex.size()-1] << " end index: " << faceGroupEndIndex[faceGroupEndIndex.size()-1] - << " last fluentFaces read: " << facei << endl; + << " last fluentFaces read: " << facei << nl + << " on line " << lineNo << endl; } yy_pop_state(); @@ -507,7 +523,7 @@ endOfSection {space}")"{space} BEGIN(readCellHeader); } -{spaceNl}{lbrac}{space}"0"{space}"1"{space} { +{space}{lbrac}{space}"0"{space}"1"{space} { BEGIN(readNumberOfCells); } @@ -516,7 +532,7 @@ endOfSection {space}")"{space} Info<< "Number of cells: " << nCells << endl; } -{spaceNl}{lbrac} { +{space}{lbrac} { BEGIN(readCellGroupData); } @@ -526,7 +542,8 @@ endOfSection {space}")"{space} // non-standard cell definition from Tgrid, which misses the type label. Warning - << "Tgrid syntax problem: " << YYText() << endl; + << "Tgrid syntax problem: " << YYText() << nl + << " on line " << lineNo << endl; // read cell zone-ID, start and end-label cellGroupZoneID.append(strtol(YYText(), &endPtr, 16)); @@ -580,7 +597,7 @@ endOfSection {space}")"{space} BEGIN(readCellData); } -{spaceNl}{lbrac} { +{space}{lbrac} { // Quickly scan to the end of the cell data block and discard register int c; while ((c = yyinput()) != 0 && c != ')') @@ -601,7 +618,7 @@ endOfSection {space}")"{space} BEGIN(readZoneHeader); } -{spaceNl}{lbrac} { +{space}{lbrac} { BEGIN(readZoneGroupData); } @@ -623,17 +640,18 @@ endOfSection {space}")"{space} BEGIN(readZoneData); } -{spaceNl}{lbrac} { +{space}{lbrac} { Info<< ". Reading zone data..." << flush; yy_push_state(readZoneBlock); } -{spaceNl}{schemeSymbolList} { +{space}{schemeSymbolList} { } {lbrac} { - Warning - << "Found unknown block in zone: " << YYText() << endl; + //Warning + // << "Found unknown block in zone: " << YYText() << nl + // << " on line " << lineNo << endl; yy_push_state(ignoreBlock); } @@ -646,7 +664,7 @@ endOfSection {space}")"{space} /* ------ Reading end of section and others ------ */ -{spaceNl}{endOfSection} { +{space}{endOfSection} { BEGIN(INITIAL); } @@ -655,7 +673,8 @@ endOfSection {space}")"{space} {lbrac}{label} { Warning << "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); } @@ -664,40 +683,47 @@ endOfSection {space}")"{space} yy_push_state(ignoreBlock); } -{spaceNl}{quote}{text}{quote} { +{space}{quote}{text}{quote} { } -{spaceNl}{schemeSymbol} { +{space}{schemeSymbol} { } -{spaceNl}{lbrac} { +{space}{lbrac} { yy_push_state(ignoreEmbeddedBlock); } -{spaceNl}{endOfSection} { +{space}{endOfSection} { yy_pop_state(); } -{spaceNl}{labelList} { +{space}{labelList} { } -{spaceNl}{hexLabelList} { +{space}{hexLabelList} { } -{spaceNl}{scalarList} { +{space}{scalarList} { } -{spaceNl}{schemeSymbolList} { +{space}{schemeSymbolList} { } -{spaceNl}{text} { +{space}{text} { + } + + + /* ------ Count newlines. ------ */ + +<*>\n { + lineNo++; } - /* ------ Ignore remaining space and \n s. ------ */ + /* ------ Ignore remaining space. ------ */ -<*>{some_space}|\n|\r { +<*>{some_space}|\r { } @@ -706,7 +732,8 @@ endOfSection {space}")"{space} <*>. { // This is a catch all. FatalErrorIn("fluentMeshToFoam::lexer") - << "Do not understand characters: " << YYText() + << "Do not understand characters: " << YYText() << nl + << " on line " << lineNo << exit(FatalError); } @@ -882,11 +909,8 @@ int main(int argc, char *argv[]) // Check the face groups for boundary patches, baffles and faceZones // ignoring the interior zones in ignoreCellGroups // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - label nPatches = 0; - labelList patchIDs(faceGroupZoneID.size()); - - label nFaceZones = 0; - labelList faceZoneIDs(faceGroupZoneID.size()); + DynamicList