OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

foamDataToFluent.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Translates FOAM data to Fluent format.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "fvCFD.H"
00031 #include "writeFluentFields.H"
00032 #include "OFstream.H"
00033 #include "IOobjectList.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 // Main program:
00037 
00038 int main(int argc, char *argv[])
00039 {
00040     argList::noParallel();
00041     timeSelector::addOptions(false);   // no constant
00042 
00043 #   include "setRootCase.H"
00044 #   include "createTime.H"
00045 
00046     instantList timeDirs = timeSelector::select0(runTime, args);
00047 
00048 #   include "createMesh.H"
00049 
00050     // make a directory called proInterface in the case
00051     mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
00052 
00053     forAll(timeDirs, timeI)
00054     {
00055         runTime.setTime(timeDirs[timeI], timeI);
00056 
00057         Info<< "Time = " << runTime.timeName() << endl;
00058 
00059         if (mesh.readUpdate())
00060         {
00061             Info<< "    Read new mesh" << endl;
00062         }
00063 
00064         // make a directory called proInterface in the case
00065         mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
00066 
00067         // open a file for the mesh
00068         OFstream fluentDataFile
00069         (
00070             runTime.rootPath()/
00071             runTime.caseName()/
00072             "fluentInterface"/
00073             runTime.caseName() + runTime.timeName() + ".dat"
00074         );
00075 
00076         fluentDataFile
00077             << "(0 \"FOAM to Fluent data File\")" << endl << endl;
00078 
00079         // Writing number of faces
00080         label nFaces = mesh.nFaces();
00081 
00082         forAll (mesh.boundary(), patchI)
00083         {
00084             nFaces += mesh.boundary()[patchI].size();
00085         }
00086 
00087         fluentDataFile
00088             << "(33 (" << mesh.nCells() << " " << nFaces << " "
00089             << mesh.nPoints() << "))" << endl;
00090 
00091         IOdictionary foamDataToFluentDict
00092         (
00093             IOobject
00094             (
00095                 "foamDataToFluentDict",
00096                 runTime.system(),
00097                 mesh,
00098                 IOobject::MUST_READ,
00099                 IOobject::NO_WRITE
00100             )
00101         );
00102 
00103 
00104         // Search for list of objects for this time
00105         IOobjectList objects(mesh, runTime.timeName());
00106 
00107 
00108         // Converting volScalarField
00109         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00110 
00111         // Search list of objects for volScalarFields
00112         IOobjectList scalarFields(objects.lookupClass("volScalarField"));
00113 
00114         for
00115         (
00116             IOobjectList::iterator scalarFieldIter = scalarFields.begin();
00117             scalarFieldIter != scalarFields.end();
00118             ++scalarFieldIter
00119         )
00120         {
00121             // Read field
00122             volScalarField field
00123             (
00124                 *scalarFieldIter(),
00125                 mesh
00126             );
00127 
00128             // lookup field from dictionary
00129             if (foamDataToFluentDict.found(field.name()))
00130             {
00131                 label unitNumber
00132                 (
00133                     readLabel(foamDataToFluentDict.lookup(field.name()))
00134                 );
00135 
00136                 // Convert field
00137                 if (unitNumber > 0)
00138                 {
00139                     Info<< "    Converting field " << field.name() << endl;
00140                     writeFluentField(field, unitNumber, fluentDataFile);
00141                 }
00142             }
00143         }
00144 
00145 
00146         // Converting volVectorField
00147         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00148 
00149         // Search list of objects for volVectorFields
00150         IOobjectList vectorFields(objects.lookupClass("volVectorField"));
00151 
00152         for
00153         (
00154             IOobjectList::iterator vectorFieldIter = vectorFields.begin();
00155             vectorFieldIter != vectorFields.end();
00156             ++vectorFieldIter
00157         )
00158         {
00159             // Read field
00160             volVectorField field
00161             (
00162                 *vectorFieldIter(),
00163                 mesh
00164             );
00165 
00166             // lookup field from dictionary
00167             if (foamDataToFluentDict.found(field.name()))
00168             {
00169                 label unitNumber
00170                 (
00171                     readLabel(foamDataToFluentDict.lookup(field.name()))
00172                 );
00173 
00174                 // Convert field
00175                 if (unitNumber > 0)
00176                 {
00177                     Info<< "    Converting field " << field.name() << endl;
00178                     writeFluentField(field, unitNumber, fluentDataFile);
00179                 }
00180             }
00181         }
00182 
00183         Info<< endl;
00184     }
00185 
00186     Info << "End\n" << endl;
00187 
00188     return 0;
00189 }
00190 
00191 
00192 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd