FreeFOAM The Cross-Platform CFD Toolkit
foamDataToFluent.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  foamDataToFluent
26 
27 Description
28  Translates FOAM data to Fluent format.
29 
30 Usage
31 
32  - foamDataToFluent [OPTIONS]
33 
34  @param -noZero \n
35  Ignore timestep 0.
36 
37  @param -constant \n
38  Include the constant directory.
39 
40  @param -time <time>\n
41  Apply only to specific time.
42 
43  @param -latestTime \n
44  Only apply to latest time step.
45 
46  @param -case <dir>\n
47  Case directory.
48 
49  @param -help \n
50  Display help message.
51 
52  @param -doc \n
53  Display Doxygen API documentation page for this application.
54 
55  @param -srcDoc \n
56  Display Doxygen source documentation page for this application.
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include <finiteVolume/fvCFD.H>
61 #include "writeFluentFields.H"
62 #include <OpenFOAM/OFstream.H>
63 #include <OpenFOAM/IOobjectList.H>
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 // Main program:
67 
68 int main(int argc, char *argv[])
69 {
70  argList::noParallel();
71  timeSelector::addOptions(false); // no constant
72 
73 # include <OpenFOAM/setRootCase.H>
74 # include <OpenFOAM/createTime.H>
75 
76  instantList timeDirs = timeSelector::select0(runTime, args);
77 
78 # include <OpenFOAM/createMesh.H>
79 
80  // make a directory called proInterface in the case
81  mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
82 
83  forAll(timeDirs, timeI)
84  {
85  runTime.setTime(timeDirs[timeI], timeI);
86 
87  Info<< "Time = " << runTime.timeName() << endl;
88 
89  if (mesh.readUpdate())
90  {
91  Info<< " Read new mesh" << endl;
92  }
93 
94  // make a directory called proInterface in the case
95  mkDir(runTime.rootPath()/runTime.caseName()/"fluentInterface");
96 
97  // open a file for the mesh
98  OFstream fluentDataFile
99  (
100  runTime.rootPath()/
101  runTime.caseName()/
102  "fluentInterface"/
103  runTime.caseName() + runTime.timeName() + ".dat"
104  );
105 
106  fluentDataFile
107  << "(0 \"FOAM to Fluent data File\")" << endl << endl;
108 
109  // Writing number of faces
110  label nFaces = mesh.nFaces();
111 
112  forAll (mesh.boundary(), patchI)
113  {
114  nFaces += mesh.boundary()[patchI].size();
115  }
116 
117  fluentDataFile
118  << "(33 (" << mesh.nCells() << " " << nFaces << " "
119  << mesh.nPoints() << "))" << endl;
120 
121  IOdictionary foamDataToFluentDict
122  (
123  IOobject
124  (
125  "foamDataToFluentDict",
126  runTime.system(),
127  mesh,
128  IOobject::MUST_READ,
129  IOobject::NO_WRITE
130  )
131  );
132 
133 
134  // Search for list of objects for this time
135  IOobjectList objects(mesh, runTime.timeName());
136 
137 
138  // Converting volScalarField
139  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140 
141  // Search list of objects for volScalarFields
142  IOobjectList scalarFields(objects.lookupClass("volScalarField"));
143 
144  for
145  (
146  IOobjectList::iterator scalarFieldIter = scalarFields.begin();
147  scalarFieldIter != scalarFields.end();
148  ++scalarFieldIter
149  )
150  {
151  // Read field
152  volScalarField field
153  (
154  *scalarFieldIter(),
155  mesh
156  );
157 
158  // lookup field from dictionary
159  if (foamDataToFluentDict.found(field.name()))
160  {
161  label unitNumber
162  (
163  readLabel(foamDataToFluentDict.lookup(field.name()))
164  );
165 
166  // Convert field
167  if (unitNumber > 0)
168  {
169  Info<< " Converting field " << field.name() << endl;
170  writeFluentField(field, unitNumber, fluentDataFile);
171  }
172  }
173  }
174 
175 
176  // Converting volVectorField
177  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178 
179  // Search list of objects for volVectorFields
180  IOobjectList vectorFields(objects.lookupClass("volVectorField"));
181 
182  for
183  (
184  IOobjectList::iterator vectorFieldIter = vectorFields.begin();
185  vectorFieldIter != vectorFields.end();
186  ++vectorFieldIter
187  )
188  {
189  // Read field
190  volVectorField field
191  (
192  *vectorFieldIter(),
193  mesh
194  );
195 
196  // lookup field from dictionary
197  if (foamDataToFluentDict.found(field.name()))
198  {
199  label unitNumber
200  (
201  readLabel(foamDataToFluentDict.lookup(field.name()))
202  );
203 
204  // Convert field
205  if (unitNumber > 0)
206  {
207  Info<< " Converting field " << field.name() << endl;
208  writeFluentField(field, unitNumber, fluentDataFile);
209  }
210  }
211  }
212 
213  Info<< endl;
214  }
215 
216  Info << "End\n" << endl;
217 
218  return 0;
219 }
220 
221 
222 // ************************ vim: set sw=4 sts=4 et: ************************ //