FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     foamDataToFluent
00026 
00027 Description
00028     Translates FOAM data to Fluent format.
00029 
00030 Usage
00031 
00032     - foamDataToFluent [OPTIONS]
00033 
00034     @param -noZero \n
00035     Ignore timestep 0.
00036 
00037     @param -constant \n
00038     Include the constant directory.
00039 
00040     @param -time <time>\n
00041     Apply only to specific time.
00042 
00043     @param -latestTime \n
00044     Only apply to latest time step.
00045 
00046     @param -case <dir>\n
00047     Case directory.
00048 
00049     @param -help \n
00050     Display help message.
00051 
00052     @param -doc \n
00053     Display Doxygen API documentation page for this application.
00054 
00055     @param -srcDoc \n
00056     Display Doxygen source documentation page for this application.
00057 
00058 \*---------------------------------------------------------------------------*/
00059 
00060 #include <finiteVolume/fvCFD.H>
00061 #include "writeFluentFields.H"
00062 #include <OpenFOAM/OFstream.H>
00063 #include <OpenFOAM/IOobjectList.H>
00064 
00065 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00066 // Main program:
00067 
00068 int main(int argc, char *argv[])
00069 {
00070     argList::noParallel();
00071     timeSelector::addOptions(false);   // no constant
00072 
00073 #   include <OpenFOAM/setRootCase.H>
00074 #   include <OpenFOAM/createTime.H>
00075 
00076     instantList timeDirs = timeSelector::select0(runTime, args);
00077 
00078 #   include <OpenFOAM/createMesh.H>
00079 
00080     // make a directory called proInterface in the case
00081     mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
00082 
00083     forAll(timeDirs, timeI)
00084     {
00085         runTime.setTime(timeDirs[timeI], timeI);
00086 
00087         Info<< "Time = " << runTime.timeName() << endl;
00088 
00089         if (mesh.readUpdate())
00090         {
00091             Info<< "    Read new mesh" << endl;
00092         }
00093 
00094         // make a directory called proInterface in the case
00095         mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
00096 
00097         // open a file for the mesh
00098         OFstream fluentDataFile
00099         (
00100             runTime.rootPath()/
00101             runTime.caseName()/
00102             "fluentInterface"/
00103             runTime.caseName() + runTime.timeName() + ".dat"
00104         );
00105 
00106         fluentDataFile
00107             << "(0 \"FOAM to Fluent data File\")" << endl << endl;
00108 
00109         // Writing number of faces
00110         label nFaces = mesh.nFaces();
00111 
00112         forAll (mesh.boundary(), patchI)
00113         {
00114             nFaces += mesh.boundary()[patchI].size();
00115         }
00116 
00117         fluentDataFile
00118             << "(33 (" << mesh.nCells() << " " << nFaces << " "
00119             << mesh.nPoints() << "))" << endl;
00120 
00121         IOdictionary foamDataToFluentDict
00122         (
00123             IOobject
00124             (
00125                 "foamDataToFluentDict",
00126                 runTime.system(),
00127                 mesh,
00128                 IOobject::MUST_READ,
00129                 IOobject::NO_WRITE
00130             )
00131         );
00132 
00133 
00134         // Search for list of objects for this time
00135         IOobjectList objects(mesh, runTime.timeName());
00136 
00137 
00138         // Converting volScalarField
00139         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00140 
00141         // Search list of objects for volScalarFields
00142         IOobjectList scalarFields(objects.lookupClass("volScalarField"));
00143 
00144         for
00145         (
00146             IOobjectList::iterator scalarFieldIter = scalarFields.begin();
00147             scalarFieldIter != scalarFields.end();
00148             ++scalarFieldIter
00149         )
00150         {
00151             // Read field
00152             volScalarField field
00153             (
00154                 *scalarFieldIter(),
00155                 mesh
00156             );
00157 
00158             // lookup field from dictionary
00159             if (foamDataToFluentDict.found(field.name()))
00160             {
00161                 label unitNumber
00162                 (
00163                     readLabel(foamDataToFluentDict.lookup(field.name()))
00164                 );
00165 
00166                 // Convert field
00167                 if (unitNumber > 0)
00168                 {
00169                     Info<< "    Converting field " << field.name() << endl;
00170                     writeFluentField(field, unitNumber, fluentDataFile);
00171                 }
00172             }
00173         }
00174 
00175 
00176         // Converting volVectorField
00177         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00178 
00179         // Search list of objects for volVectorFields
00180         IOobjectList vectorFields(objects.lookupClass("volVectorField"));
00181 
00182         for
00183         (
00184             IOobjectList::iterator vectorFieldIter = vectorFields.begin();
00185             vectorFieldIter != vectorFields.end();
00186             ++vectorFieldIter
00187         )
00188         {
00189             // Read field
00190             volVectorField field
00191             (
00192                 *vectorFieldIter(),
00193                 mesh
00194             );
00195 
00196             // lookup field from dictionary
00197             if (foamDataToFluentDict.found(field.name()))
00198             {
00199                 label unitNumber
00200                 (
00201                     readLabel(foamDataToFluentDict.lookup(field.name()))
00202                 );
00203 
00204                 // Convert field
00205                 if (unitNumber > 0)
00206                 {
00207                     Info<< "    Converting field " << field.name() << endl;
00208                     writeFluentField(field, unitNumber, fluentDataFile);
00209                 }
00210             }
00211         }
00212 
00213         Info<< endl;
00214     }
00215 
00216     Info << "End\n" << endl;
00217 
00218     return 0;
00219 }
00220 
00221 
00222 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines