1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Converts Fluent data to FOAM format
30 \*---------------------------------------------------------------------------*/
36 /* ------------------------------------------------------------------------- *\
37 ------ local definitions
38 \* ------------------------------------------------------------------------- */
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 label dimensionOfGrid = 0;
69 SLList<label> fieldID;
71 SLList<label> nEntriesPerObject;
72 SLList<label> firstID;
75 SLPtrList<FieldField<Field, scalar> > zoneData;
77 // Dummy yywrap to keep yylex happy at compile time.
78 // It is called by yylex but is not used as the mechanism to change file.
80 #if YY_FLEX_MINOR_VERSION < 6 && YY_FLEX_SUBMINOR_VERSION < 34
81 extern "C" int yywrap()
83 int yyFlexLexer::yywrap()
93 some_space {one_space}+
95 spaceNl ({space}|\n|\r)*
101 hexDigit [[:xdigit:]]
110 schemeSpecialInitial [!$%&*/:<=>?~_^#.]
111 schemeSpecialSubsequent [.+-]
112 schemeSymbol (({some_space}|{alpha}|{quote}|{schemeSpecialInitial})({alpha}|{quote}|{digit}|{schemeSpecialInitial}|{schemeSpecialSubsequent})*)
115 identifier {alpha}({alpha}|{digit})*
117 label [1-9]{decDigit}*
121 word ({alpha}|{digit}|{dotColonDash})*
123 exponent_part [eE][-+]?{digit}+
124 fractional_constant [-+]?(({digit}*"."{digit}+)|({digit}+".")|({digit}))
126 double ((({fractional_constant}{exponent_part}?)|({digit}+{exponent_part}))|0)
132 labelListElement {space}{zeroLabel}
133 hexLabelListElement {space}{hexLabel}
134 scalarListElement {space}{double}
135 schemeSymbolListElement {space}{schemeSymbol}
136 labelList ({labelListElement}+{space})
137 hexLabelList ({hexLabelListElement}+{space})
138 scalarList ({scalarListElement}+{space})
139 schemeSymbolList ({schemeSymbolListElement}+{space})
142 text ({space}({comma}*{word}*{space})*)
144 dateDDMMYYYY ({digit}{digit}"/"{digit}{digit}"/"{digit}{digit}{digit}{digit})
145 dateDDMonYYYY ((({digit}{digit}{space})|({digit}{space})){alpha}*{space}{digit}{digit}{digit}{digit})
146 time ({digit}{digit}":"{digit}{digit}":"{digit}{digit})
148 versionNumber ({digit}|".")*
150 comment {spaceNl}"(0"{space}
151 header {spaceNl}"(1"{space}
152 dimension {spaceNl}"(2"{space}
153 machineConfig {spaceNl}"(4"{space}
154 gridSize {spaceNl}"(33"{space}
155 variables {spaceNl}"(37"{space}
156 fieldData {spaceNl}"(300"{space}
158 endOfSection {space}")"{space}
162 /* ------------------------------------------------------------------------- *\
163 ----- Exclusive start states -----
164 \* ------------------------------------------------------------------------- */
169 %x embeddedCommentState
172 %x readMachineConfigHeader
174 %x readGridSizeHeader
178 %x readFieldDataHeader
183 %x embeddedUnknownBlock
188 label curNEntriesPerObject = 0;
190 label curFirstID = 0;
194 FieldField<Field, scalar>* curZdPtr = NULL;
198 /* ------------------------------------------------------------------------ *\
199 ------ Start Lexing ------
200 \* ------------------------------------------------------------------------ */
202 /* ------ Reading control header ------ */
205 yy_push_state(readComment);
209 <readComment>{quote}{text}{quote} {
213 <readComment>{spaceNl}{endOfSection} {
221 <readHeader>{quote}{text}{quote} {
222 Info<< "Reading header: " << YYText() << endl;
227 BEGIN(readDimension);
230 <readDimension>{space}{label}{space} {
231 IStringStream dimOfGridStream(YYText());
233 dimensionOfGrid = readLabel(dimOfGridStream);
235 Info<< "Dimension of grid: " << dimensionOfGrid << endl;
240 yy_push_state(readMachineConfigHeader);
243 <readMachineConfigHeader>{spaceNl}{lbrac} {
244 yy_push_state(readMachineConfig);
247 <readMachineConfig>{space}{labelList} {
248 IStringStream machineConfigStream(YYText());
250 mc1 = readLabel(machineConfigStream);
251 mc2 = readLabel(machineConfigStream);
252 mc3 = readLabel(machineConfigStream);
253 mc4 = readLabel(machineConfigStream);
254 mc5 = readLabel(machineConfigStream);
255 mc6 = readLabel(machineConfigStream);
256 mc7 = readLabel(machineConfigStream);
257 mc8 = readLabel(machineConfigStream);
258 mc9 = readLabel(machineConfigStream);
259 mc10 = readLabel(machineConfigStream);
260 mc11 = readLabel(machineConfigStream);
262 Info<< "Machine config: "
263 << mc1 << mc2 << mc3 << mc4 << mc5 << mc6
264 << mc7 << mc8 << mc9 << mc10 << mc11
270 yy_push_state(readGridSizeHeader);
274 <readGridSizeHeader>{spaceNl}{lbrac} {
275 yy_push_state(readGridSize);
279 <readGridSize>{space}{labelList} {
280 IStringStream gridSizeStream(YYText());
282 nCells = readLabel(gridSizeStream);
283 nFaces = readLabel(gridSizeStream);
284 nPoints = readLabel(gridSizeStream);
286 Info<< "Grid size: nCells = " << nCells << " nFaces = " << nFaces
287 << " nPoints = " << nPoints << endl;
292 yy_push_state(readComment);
297 yy_push_state(readFieldDataHeader);
301 <readFieldDataHeader>{spaceNl}{lbrac} {
302 BEGIN(readFieldSize);
306 <readFieldSize>{space}{labelList} {
307 IStringStream fieldDataStream(YYText());
310 fieldID.append(readLabel(fieldDataStream));
311 zoneID.append(readLabel(fieldDataStream));
313 // Number of entries per object (cell/face)
314 curNEntriesPerObject = readLabel(fieldDataStream);
315 nEntriesPerObject.append(curNEntriesPerObject);
319 readLabel(fieldDataStream);
321 readLabel(fieldDataStream);
323 // Start and end of list
324 curFirstID = readLabel(fieldDataStream);
325 firstID.append(curFirstID);
326 curLastID = readLabel(fieldDataStream);
327 lastID.append(curLastID);
329 // Create field for data
330 // Info << "Create : " << curNEntriesPerObject << endl;
331 curZdPtr = new FieldField<Field, scalar>(curNEntriesPerObject);
333 // Info<< "Setting field with " << curNEntriesPerObject
334 // << " components of length " << curLastID - curFirstID +1 << endl;
336 for (label cmptI = 0; cmptI < curNEntriesPerObject; cmptI++)
338 curZdPtr->set(cmptI, new scalarField(curLastID - curFirstID + 1));
341 zoneData.append(curZdPtr);
345 <readFieldSize>{endOfSection} {
346 BEGIN(readFieldData);
350 <readFieldData>{spaceNl}{lbrac} {
351 // Info<< "Reading field. nEntries = " << curNEntriesPerObject
352 // << " firstID = " << curFirstID << " lastID = " << curLastID << endl;
357 yy_push_state(readField);
361 <readField>{spaceNl}{scalarList} {
363 IStringStream fieldStream(YYText());
365 FieldField<Field, scalar>& zd = *curZdPtr;
368 for (label entryI = 0; entryI < curNEntriesPerObject; entryI++)
370 zd[entryI][objI] = readScalar(fieldStream);
376 <readMachineConfig,readMachineConfigHeader,readGridSize,readGridSizeHeader,readFieldData,readField>{spaceNl}{endOfSection} {
381 /* ------ Reading end of section and others ------ */
383 <readHeader,readDimension>{spaceNl}{endOfSection} {
387 /* ------ Reading unknown type or non-standard comment ------ */
391 // Info<< "Found unknown block:" << YYText() << endl;
392 yy_push_state(unknownBlock);
395 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{schemeSymbol} {
398 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{lbrac} {
399 // Info<< "Embedded blocks in comment or unknown:" << YYText() << endl;
400 yy_push_state(embeddedUnknownBlock);
404 <readComment,unknownBlock,embeddedUnknownBlock>{spaceNl}{endOfSection} {
405 // Info<< "Found end of section in unknown:" << YYText() << endl;
409 <unknownBlock,embeddedUnknownBlock>{spaceNl}{labelList} {
412 <unknownBlock,embeddedUnknownBlock>{spaceNl}{hexLabelList} {
415 <unknownBlock,embeddedUnknownBlock>{spaceNl}{scalarList} {
418 <unknownBlock,embeddedUnknownBlock>{spaceNl}{schemeSymbolList} {
421 <unknownBlock,embeddedUnknownBlock>{spaceNl}{text} {
425 /* ------ Ignore remaining space and \n s. Any other characters are errors. */
427 /* ------ On EOF return to previous file, if none exists terminate. ------ */
435 #include "fileName.H"
436 #include "fluentDataConverter.H"
438 int main(int argc, char *argv[])
440 argList::noParallel();
441 argList::validArgs.append("Fluent data file");
443 argList args(argc, argv);
450 # include "createTime.H"
452 fileName fluentFile(args.additionalArgs()[0]);
453 std::ifstream fluentStream(fluentFile.c_str());
457 FatalErrorIn("fluentToFoam::main(int argc, char *argv[])")
459 << ": file " << fluentFile << " not found"
463 yyFlexLexer lexer(&fluentStream);
464 while(lexer.yylex() != 0)
467 Info<< "\n\nFINISHED LEXING\n\n\n";
469 // Re-package the fields into foam data
471 // Warning: syncronous iterators, check size
473 const label iterSize = fieldID.size();
474 Info << "Number of entries read: " << iterSize << nl << endl;
478 zoneID.size() != iterSize
479 || nEntriesPerObject.size() != iterSize
480 || firstID.size() != iterSize
481 || lastID.size() != iterSize
482 || zoneData.size() != iterSize
485 FatalErrorIn(args.executable())
486 << "Problem in reading: incorrect iterator size: " << iterSize
487 << abort(FatalError);
494 SLList<label>::const_iterator fieldIDIter = fieldID.begin();
495 fieldIDIter != fieldID.end();
499 fields.insert(fieldIDIter());
502 // Info: Available units
504 labelList u = fields.toc();
506 Info<< "Available units: " << u << endl;
510 # include "createMesh.H"
512 // Create a converter
513 fluentDataConverter fdc
525 Info << "Converting pressure field" << endl;
529 1, // fluent Unit number
530 dimensionedScalar("zero", dimPressure, 0)
536 Info << "Converting momentum field" << endl;
539 "momentum", // field name
540 2, // fluent Unit number
541 dimensionedScalar("zero", dimDensity*dimVelocity, 0)
547 Info << "Converting temperature field" << endl;
551 3, // fluent Unit number
552 dimensionedScalar("zero", dimTemperature, 273.15)
558 Info << "Converting enthalpy field" << endl;
562 4, // fluent Unit number
563 dimensionedScalar("zero", dimensionSet(0, 2, -2, 0, 0, 0, 0), 0)
569 Info << "Converting turbulence kinetic energy field" << endl;
573 5, // fluent Unit number
574 dimensionedScalar("zero", sqr(dimVelocity), 0)
578 // Species not done yet. HJ, 29/May/2009
582 Info << "Converting G field" << endl;
586 8, // fluent Unit number
587 dimensionedScalar("zero", dimless, 0)
591 if (fields.found(15))
593 Info << "Converting body force field" << endl;
596 "bodyForce", // field name
597 15, // fluent Unit number
598 dimensionedScalar("zero", dimAcceleration, 0)
602 if (fields.found(101))
604 Info << "Converting density field" << endl;
608 101, // fluent Unit number
609 dimensionedScalar("zero", dimDensity, 0)
613 if (fields.found(102))
615 Info << "Converting laminar viscosity field" << endl;
618 "muLam", // field name
619 102, // fluent Unit number
620 dimensionedScalar("zero", dimPressure*dimTime, 0)
624 if (fields.found(103))
626 Info << "Converting turbulent field" << endl;
630 103, // fluent Unit number
631 dimensionedScalar("zero", dimPressure*dimTime, 0)
635 if (fields.found(104))
637 Info << "Converting field" << endl;
641 104, // fluent Unit number
642 dimensionedScalar("zero", dimSpecificHeatCapacity, 0)
647 if (fields.found(111) || fields.found(112) || fields.found(113))
649 Info << "Converting velocity field" << endl;
655 mesh.time().timeName(),
661 dimensionedVector("zero", dimVelocity, vector::zero)
664 if (fields.found(111))
672 111, // fluent Unit number
673 dimensionedScalar("zero", dimVelocity, 0)
678 if (fields.found(112))
686 112, // fluent Unit number
687 dimensionedScalar("zero", dimVelocity, 0)
692 if (fields.found(113))
700 113, // fluent Unit number
701 dimensionedScalar("zero", dimVelocity, 0)
710 Info<< nl << "End" << endl;
715 /* ------------------------------------------------------------------------- *\
716 ------ End of fluentDataToFoam.L
717 \* ------------------------------------------------------------------------- */