BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamDataToFluent / foamDataToFluent.C
blob48ce66b4a9b33322cfa76ab5dcea527d578091a9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     Translates FOAM data to Fluent format.
28 \*---------------------------------------------------------------------------*/
30 #include "fvCFD.H"
31 #include "writeFluentFields.H"
32 #include "OFstream.H"
33 #include "IOobjectList.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // Main program:
38 int main(int argc, char *argv[])
40     argList::noParallel();
41     timeSelector::addOptions(false);   // no constant
43 #   include "setRootCase.H"
44 #   include "createTime.H"
46     instantList timeDirs = timeSelector::select0(runTime, args);
48 #   include "createMesh.H"
50     // make a directory called proInterface in the case
51     mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
53     forAll(timeDirs, timeI)
54     {
55         runTime.setTime(timeDirs[timeI], timeI);
57         Info<< "Time = " << runTime.timeName() << endl;
59         if (mesh.readUpdate())
60         {
61             Info<< "    Read new mesh" << endl;
62         }
64         // make a directory called proInterface in the case
65         mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
67         // open a file for the mesh
68         OFstream fluentDataFile
69         (
70             runTime.rootPath()/
71             runTime.caseName()/
72             "fluentInterface"/
73             runTime.caseName() + runTime.timeName() + ".dat"
74         );
76         fluentDataFile
77             << "(0 \"FOAM to Fluent data File\")" << endl << endl;
79         // Writing number of faces
80         label nFaces = mesh.nFaces();
82         forAll (mesh.boundary(), patchI)
83         {
84             nFaces += mesh.boundary()[patchI].size();
85         }
87         fluentDataFile
88             << "(33 (" << mesh.nCells() << " " << nFaces << " "
89             << mesh.nPoints() << "))" << endl;
91         IOdictionary foamDataToFluentDict
92         (
93             IOobject
94             (
95                 "foamDataToFluentDict",
96                 runTime.system(),
97                 mesh,
98                 IOobject::MUST_READ,
99                 IOobject::NO_WRITE
100             )
101         );
104         // Search for list of objects for this time
105         IOobjectList objects(mesh, runTime.timeName());
108         // Converting volScalarField
109         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111         // Search list of objects for volScalarFields
112         IOobjectList scalarFields(objects.lookupClass("volScalarField"));
114         for
115         (
116             IOobjectList::iterator scalarFieldIter = scalarFields.begin();
117             scalarFieldIter != scalarFields.end();
118             ++scalarFieldIter
119         )
120         {
121             // Read field
122             volScalarField field
123             (
124                 *scalarFieldIter(),
125                 mesh
126             );
128             // lookup field from dictionary
129             if (foamDataToFluentDict.found(field.name()))
130             {
131                 label unitNumber
132                 (
133                     readLabel(foamDataToFluentDict.lookup(field.name()))
134                 );
136                 // Convert field
137                 if (unitNumber > 0)
138                 {
139                     Info<< "    Converting field " << field.name() << endl;
140                     writeFluentField(field, unitNumber, fluentDataFile);
141                 }
142             }
143         }
146         // Converting volVectorField
147         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149         // Search list of objects for volVectorFields
150         IOobjectList vectorFields(objects.lookupClass("volVectorField"));
152         for
153         (
154             IOobjectList::iterator vectorFieldIter = vectorFields.begin();
155             vectorFieldIter != vectorFields.end();
156             ++vectorFieldIter
157         )
158         {
159             // Read field
160             volVectorField field
161             (
162                 *vectorFieldIter(),
163                 mesh
164             );
166             // lookup field from dictionary
167             if (foamDataToFluentDict.found(field.name()))
168             {
169                 label unitNumber
170                 (
171                     readLabel(foamDataToFluentDict.lookup(field.name()))
172                 );
174                 // Convert field
175                 if (unitNumber > 0)
176                 {
177                     Info<< "    Converting field " << field.name() << endl;
178                     writeFluentField(field, unitNumber, fluentDataFile);
179                 }
180             }
181         }
183         Info<< endl;
184     }
186     Info << "End\n" << endl;
188     return 0;
192 // ************************************************************************* //