1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Converts Fluent data to OpenFOAM format
31 \*---------------------------------------------------------------------------*/
37 /* ------------------------------------------------------------------------- *\
38 ------ local definitions
39 \* ------------------------------------------------------------------------- */
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 label dimensionOfGrid = 0;
70 SLList<label> fieldID;
72 SLList<label> nEntriesPerObject;
73 SLList<label> firstID;
76 SLPtrList<FieldField<Field, scalar> > zoneData;
78 // Dummy yywrap to keep yylex happy at compile time.
79 // It is called by yylex but is not used as the mechanism to change file.
81 #if YY_FLEX_SUBMINOR_VERSION < 34
82 extern "C" int yywrap()
84 int yyFlexLexer::yywrap()
94 some_space {one_space}+
96 spaceNl ({space}|\n|\r)*
102 hexDigit [[:xdigit:]]
111 schemeSpecialInitial [!$%&*/:<=>?~_^#.]
112 schemeSpecialSubsequent [.+-]
113 schemeSymbol (({some_space}|{alpha}|{quote}|{schemeSpecialInitial})({alpha}|{quote}|{digit}|{schemeSpecialInitial}|{schemeSpecialSubsequent})*)
116 identifier {alpha}({alpha}|{digit})*
118 label [1-9]{decDigit}*
122 word ({alpha}|{digit}|{dotColonDash})*
124 exponent_part [eE][-+]?{digit}+
125 fractional_constant [-+]?(({digit}*"."{digit}+)|({digit}+".")|({digit}))
127 double ((({fractional_constant}{exponent_part}?)|({digit}+{exponent_part}))|0)
133 labelListElement {space}{zeroLabel}
134 hexLabelListElement {space}{hexLabel}
135 scalarListElement {space}{double}
136 schemeSymbolListElement {space}{schemeSymbol}
137 labelList ({labelListElement}+{space})
138 hexLabelList ({hexLabelListElement}+{space})
139 scalarList ({scalarListElement}+{space})
140 schemeSymbolList ({schemeSymbolListElement}+{space})
143 text ({space}({comma}*{word}*{space})*)
145 dateDDMMYYYY ({digit}{digit}"/"{digit}{digit}"/"{digit}{digit}{digit}{digit})
146 dateDDMonYYYY ((({digit}{digit}{space})|({digit}{space})){alpha}*{space}{digit}{digit}{digit}{digit})
147 time ({digit}{digit}":"{digit}{digit}":"{digit}{digit})
149 versionNumber ({digit}|".")*
151 comment {spaceNl}"(0"{space}
152 header {spaceNl}"(1"{space}
153 dimension {spaceNl}"(2"{space}
154 machineConfig {spaceNl}"(4"{space}
155 gridSize {spaceNl}"(33"{space}
156 variables {spaceNl}"(37"{space}
157 fieldData {spaceNl}"(300"{space}
159 endOfSection {space}")"{space}
163 /* ------------------------------------------------------------------------- *\
164 ----- Exclusive start states -----
165 \* ------------------------------------------------------------------------- */
170 %x embeddedCommentState
173 %x readMachineConfigHeader
175 %x readGridSizeHeader
179 %x readFieldDataHeader
184 %x embeddedUnknownBlock
189 label curNEntriesPerObject = 0;
195 label curFirstID = 0;
199 FieldField<Field, scalar>* curZdPtr = NULL;
203 /* ------------------------------------------------------------------------- *\
204 ------ Start Lexing ------
205 \* ------------------------------------------------------------------------- */
207 /* ------ Reading control header ------ */
210 yy_push_state(readComment);
214 <readComment>{quote}{text}{quote} {
218 <readComment>{spaceNl}{endOfSection} {
226 <readHeader>{quote}{text}{quote} {
227 Info<< "Reading header: " << YYText() << endl;
232 BEGIN(readDimension);
235 <readDimension>{space}{label}{space} {
236 IStringStream dimOfGridStream(YYText());
238 dimensionOfGrid = readLabel(dimOfGridStream);
240 Info<< "Dimension of grid: " << dimensionOfGrid << endl;
245 yy_push_state(readMachineConfigHeader);
248 <readMachineConfigHeader>{spaceNl}{lbrac} {
249 yy_push_state(readMachineConfig);
252 <readMachineConfig>{space}{labelList} {
253 IStringStream machineConfigStream(YYText());
255 mc1 = readLabel(machineConfigStream);
256 mc2 = readLabel(machineConfigStream);
257 mc3 = readLabel(machineConfigStream);
258 mc4 = readLabel(machineConfigStream);
259 mc5 = readLabel(machineConfigStream);
260 mc6 = readLabel(machineConfigStream);
261 mc7 = readLabel(machineConfigStream);
262 mc8 = readLabel(machineConfigStream);
263 mc9 = readLabel(machineConfigStream);
264 mc10 = readLabel(machineConfigStream);
265 mc11 = readLabel(machineConfigStream);
267 Info<< "Machine config: "
268 << mc1 << mc2 << mc3 << mc4 << mc5 << mc6
269 << mc7 << mc8 << mc9 << mc10 << mc11
275 yy_push_state(readGridSizeHeader);
279 <readGridSizeHeader>{spaceNl}{lbrac} {
280 yy_push_state(readGridSize);
284 <readGridSize>{space}{labelList} {
285 IStringStream gridSizeStream(YYText());
287 nCells = readLabel(gridSizeStream);
288 nFaces = readLabel(gridSizeStream);
289 nPoints = readLabel(gridSizeStream);
291 Info<< "Grid size: nCells = " << nCells << " nFaces = " << nFaces
292 << " nPoints = " << nPoints << endl;
297 yy_push_state(readComment);
302 yy_push_state(readFieldDataHeader);
306 <readFieldDataHeader>{spaceNl}{lbrac} {
307 BEGIN(readFieldSize);
311 <readFieldSize>{space}{labelList} {
312 IStringStream fieldDataStream(YYText());
315 fieldID.append(readLabel(fieldDataStream));
316 zoneID.append(readLabel(fieldDataStream));
318 // Number of entries per object (cell/face)
319 curNEntriesPerObject = readLabel(fieldDataStream);
320 nEntriesPerObject.append(curNEntriesPerObject);
323 nTimeLevels = readLabel(fieldDataStream);
324 nPhases = readLabel(fieldDataStream);
326 // Start and end of list
327 curFirstID = readLabel(fieldDataStream);
328 firstID.append(curFirstID);
329 curLastID = readLabel(fieldDataStream);
330 lastID.append(curLastID);
332 // Create field for data
333 // Info << "Create : " << curNEntriesPerObject << endl;
334 curZdPtr = new FieldField<Field, scalar>(curNEntriesPerObject);
336 // Info<< "Setting field with " << curNEntriesPerObject
337 // << " components of length " << curLastID - curFirstID +1 << endl;
339 for (label cmptI = 0; cmptI < curNEntriesPerObject; cmptI++)
341 curZdPtr->set(cmptI, new scalarField(curLastID - curFirstID + 1));
344 zoneData.append(curZdPtr);
348 <readFieldSize>{endOfSection} {
349 BEGIN(readFieldData);
353 <readFieldData>{spaceNl}{lbrac} {
354 // Info<< "Reading field. nEntries = " << curNEntriesPerObject
355 // << " firstID = " << curFirstID << " lastID = " << curLastID << endl;
360 yy_push_state(readField);
364 <readField>{spaceNl}{scalarList} {
366 IStringStream fieldStream(YYText());
368 FieldField<Field, scalar>& zd = *curZdPtr;
371 for (label entryI = 0; entryI < curNEntriesPerObject; entryI++)
373 zd[entryI][objI] = readScalar(fieldStream);
379 <readMachineConfig,readMachineConfigHeader,readGridSize,readGridSizeHeader,readFieldData,readField>{spaceNl}{endOfSection} {
384 /* ------ Reading end of section and others ------ */
386 <readHeader,readDimension>{spaceNl}{endOfSection} {
390 /* ------ Reading unknown type or non-standard comment ------ */
394 // Info<< "Found unknown block:" << YYText() << endl;
395 yy_push_state(unknownBlock);
398 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{schemeSymbol} {
401 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{lbrac} {
402 // Info<< "Embedded blocks in comment or unknown:" << YYText() << endl;
403 yy_push_state(embeddedUnknownBlock);
407 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{endOfSection} {
408 // Info<< "Found end of section in unknown:" << YYText() << endl;
412 <unknownBlock,embeddedUnknownBlock>{spaceNl}{labelList} {
415 <unknownBlock,embeddedUnknownBlock>{spaceNl}{hexLabelList} {
418 <unknownBlock,embeddedUnknownBlock>{spaceNl}{scalarList} {
421 <unknownBlock,embeddedUnknownBlock>{spaceNl}{schemeSymbolList} {
424 <unknownBlock,embeddedUnknownBlock>{spaceNl}{text} {
428 /* ------ Ignore remaining space and \n s. Any other characters are errors. */
430 /* ------ On EOF return to previous file, if none exists terminate. ------ */
438 #include "fileName.H"
439 #include "fluentDataConverter.H"
441 int main(int argc, char *argv[])
443 argList::noParallel();
444 argList::validArgs.append("Fluent data file");
446 argList args(argc, argv);
453 # include "createTime.H"
455 fileName fluentFile(args.additionalArgs()[0]);
456 std::ifstream fluentStream(fluentFile.c_str());
460 FatalErrorIn("fluentToFoam::main(int argc, char *argv[])")
462 << ": file " << fluentFile << " not found"
466 yyFlexLexer lexer(&fluentStream);
467 while(lexer.yylex() != 0)
470 Info<< "\n\nFINISHED LEXING\n\n\n";
472 // Re-package the fields into OpenFOAM data
474 // Warning: syncronous iterators, check size
476 const label iterSize = fieldID.size();
477 Info << "Number of entries read: " << iterSize << nl << endl;
481 zoneID.size() != iterSize
482 || nEntriesPerObject.size() != iterSize
483 || firstID.size() != iterSize
484 || lastID.size() != iterSize
485 || zoneData.size() != iterSize
488 FatalErrorIn(args.executable())
489 << "Problem in reading: incorrect iterator size: " << iterSize
490 << abort(FatalError);
497 SLList<label>::const_iterator fieldIDIter = fieldID.begin();
498 fieldIDIter != fieldID.end();
502 fields.insert(fieldIDIter());
505 // Info: Available units
507 labelList u = fields.toc();
509 Info<< "Available units: " << u << endl;
513 # include "createMesh.H"
515 // Create a converter
516 fluentDataConverter fdc
528 Info << "Converting pressure field" << endl;
532 1, // fluent Unit number
533 dimensionedScalar("zero", dimPressure, 0)
539 Info << "Converting momentum field" << endl;
542 "momentum", // field name
543 2, // fluent Unit number
544 dimensionedScalar("zero", dimDensity*dimVelocity, 0)
550 Info << "Converting temperature field" << endl;
554 3, // fluent Unit number
555 dimensionedScalar("zero", dimTemperature, 273.15)
561 Info << "Converting enthalpy field" << endl;
565 4, // fluent Unit number
566 dimensionedScalar("zero", dimensionSet(0, 2, -2, 0, 0, 0, 0), 0)
572 Info << "Converting turbulence kinetic energy field" << endl;
576 5, // fluent Unit number
577 dimensionedScalar("zero", sqr(dimVelocity), 0)
581 // Species not done yet. HJ, 29/May/2009
585 Info << "Converting G field" << endl;
589 8, // fluent Unit number
590 dimensionedScalar("zero", dimless, 0)
594 if (fields.found(15))
596 Info << "Converting body force field" << endl;
599 "bodyForce", // field name
600 15, // fluent Unit number
601 dimensionedScalar("zero", dimAcceleration, 0)
605 if (fields.found(101))
607 Info << "Converting density field" << endl;
611 101, // fluent Unit number
612 dimensionedScalar("zero", dimDensity, 0)
616 if (fields.found(102))
618 Info << "Converting laminar viscosity field" << endl;
621 "muLam", // field name
622 102, // fluent Unit number
623 dimensionedScalar("zero", dimPressure*dimTime, 0)
627 if (fields.found(103))
629 Info << "Converting turbulent field" << endl;
633 103, // fluent Unit number
634 dimensionedScalar("zero", dimPressure*dimTime, 0)
638 if (fields.found(104))
640 Info << "Converting field" << endl;
644 104, // fluent Unit number
645 dimensionedScalar("zero", dimSpecificHeatCapacity, 0)
650 if (fields.found(111) || fields.found(112) || fields.found(113))
652 Info << "Converting velocity field" << endl;
658 mesh.time().timeName(),
664 dimensionedVector("zero", dimVelocity, vector::zero)
667 if (fields.found(111))
675 111, // fluent Unit number
676 dimensionedScalar("zero", dimVelocity, 0)
681 if (fields.found(112))
689 112, // fluent Unit number
690 dimensionedScalar("zero", dimVelocity, 0)
695 if (fields.found(113))
703 113, // fluent Unit number
704 dimensionedScalar("zero", dimVelocity, 0)
713 Info<< nl << "End" << endl;
718 /* ------------------------------------------------------------------------- *\
719 ------ End of fluentDataToFoam.L
720 \* ------------------------------------------------------------------------- */