FreeFOAM The Cross-Platform CFD Toolkit
fluentFvMesh.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 \*---------------------------------------------------------------------------*/
25 
26 #include <fstream>
27 #include <iostream>
28 
29 using std::ofstream;
30 using std::ios;
31 
32 #include <OpenFOAM/Time.H>
33 #include "fluentFvMesh.H"
34 #include <OpenFOAM/primitiveMesh.H>
37 #include <OpenFOAM/cellModeller.H>
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
42 :
43  fvMesh(io)
44 {}
45 
46 
47 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48 
50 {
51  // make a directory called proInterface in the case
52  mkDir(time().rootPath()/time().caseName()/"fluentInterface");
53 
54  // open a file for the mesh
55  ofstream fluentMeshFile
56  (
57  (
58  time().rootPath()/
59  time().caseName()/
60  "fluentInterface"/
61  time().caseName() + ".msh"
62  ).c_str()
63  );
64 
65  Info << "Writing Header" << endl;
66 
67  fluentMeshFile
68  << "(0 \"FOAM to Fluent Mesh File\")" << std::endl << std::endl
69  << "(0 \"Dimension:\")" << std::endl
70  << "(2 3)" << std::endl << std::endl
71  << "(0 \"Grid dimensions:\")" << std::endl;
72 
73  // Writing number of points
74  fluentMeshFile
75  << "(10 (0 1 ";
76 
77  // Writing hex
78  fluentMeshFile.setf(ios::hex, ios::basefield);
79 
80  fluentMeshFile
81  << nPoints() << " 0 3))" << std::endl;
82 
83  // Writing number of cells
84  fluentMeshFile
85  << "(12 (0 1 "
86  << nCells() << " 0 0))" << std::endl;
87 
88  // Writing number of faces
89  label nFcs = nFaces();
90 
91  fluentMeshFile
92  << "(13 (0 1 ";
93 
94  // Still writing hex
95  fluentMeshFile
96  << nFcs << " 0 0))" << std::endl << std::endl;
97 
98  // Return to dec
99  fluentMeshFile.setf(ios::dec, ios::basefield);
100 
101  // Writing points
102  fluentMeshFile
103  << "(10 (1 1 ";
104 
105  fluentMeshFile.setf(ios::hex, ios::basefield);
106  fluentMeshFile
107  << nPoints() << " 1 3)"
108  << std::endl << "(" << std::endl;
109 
110  fluentMeshFile.precision(10);
111  fluentMeshFile.setf(ios::scientific);
112 
113  const pointField& p = points();
114 
115  forAll (p, pointI)
116  {
117  fluentMeshFile
118  << " "
119  << p[pointI].x() << " "
120  << p[pointI].y()
121  << " " << p[pointI].z() << std::endl;
122  }
123 
124  fluentMeshFile
125  << "))" << std::endl << std::endl;
126 
127  const unallocLabelList& own = owner();
128  const unallocLabelList& nei = neighbour();
129 
130  const faceList& fcs = faces();
131 
132  // Writing (mixed) internal faces
133  fluentMeshFile
134  << "(13 (2 1 "
135  << own.size() << " 2 0)" << std::endl << "(" << std::endl;
136 
137  forAll (own, faceI)
138  {
139  const labelList& l = fcs[faceI];
140 
141  fluentMeshFile << " ";
142 
143  fluentMeshFile << l.size() << " ";
144 
145  forAll (l, lI)
146  {
147  fluentMeshFile << l[lI] + 1 << " ";
148  }
149 
150  fluentMeshFile << nei[faceI] + 1 << " ";
151  fluentMeshFile << own[faceI] + 1 << std::endl;
152  }
153 
154  fluentMeshFile << "))" << std::endl;
155 
156  label nWrittenFaces = own.size();
157 
158  // Writing boundary faces
159  forAll (boundary(), patchI)
160  {
161  const unallocFaceList& patchFaces = boundaryMesh()[patchI];
162 
163  const labelList& patchFaceCells =
164  boundaryMesh()[patchI].faceCells();
165 
166  // The face group will be offset by 10 from the patch label
167 
168  // Write header
169  fluentMeshFile
170  << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
171  << " " << nWrittenFaces + patchFaces.size() << " ";
172 
173  nWrittenFaces += patchFaces.size();
174 
175  // Write patch type
176  if (isA<wallFvPatch>(boundary()[patchI]))
177  {
178  fluentMeshFile << 3;
179  }
180  else if (isA<symmetryFvPatch>(boundary()[patchI]))
181  {
182  fluentMeshFile << 7;
183  }
184  else
185  {
186  fluentMeshFile << 4;
187  }
188 
189  fluentMeshFile
190  <<" 0)" << std::endl << "(" << std::endl;
191 
192  forAll (patchFaces, faceI)
193  {
194  const labelList& l = patchFaces[faceI];
195 
196  fluentMeshFile << " ";
197 
198  fluentMeshFile << l.size() << " ";
199 
200  // Note: In Fluent, all boundary faces point inwards, which is
201  // opposite from the FOAM convention. Turn them round on printout
202  forAllReverse (l, lI)
203  {
204  fluentMeshFile << l[lI] + 1 << " ";
205  }
206 
207  fluentMeshFile << patchFaceCells[faceI] + 1 << " 0" << std::endl;
208  }
209 
210  fluentMeshFile << "))" << std::endl;
211  }
212 
213  // Writing cells
214  fluentMeshFile
215  << "(12 (1 1 "
216  << nCells() << " 1 0)(" << std::endl;
217 
218  const cellModel& hex = *(cellModeller::lookup("hex"));
219  const cellModel& prism = *(cellModeller::lookup("prism"));
220  const cellModel& pyr = *(cellModeller::lookup("pyr"));
221  const cellModel& tet = *(cellModeller::lookup("tet"));
222 
223  const cellShapeList& cells = cellShapes();
224 
225  bool hasWarned = false;
226 
227  forAll (cells, cellI)
228  {
229  if (cells[cellI].model() == tet)
230  {
231  fluentMeshFile << " " << 2;
232  }
233  else if (cells[cellI].model() == hex)
234  {
235  fluentMeshFile << " " << 4;
236  }
237  else if (cells[cellI].model() == pyr)
238  {
239  fluentMeshFile << " " << 5;
240  }
241  else if (cells[cellI].model() == prism)
242  {
243  fluentMeshFile << " " << 6;
244  }
245  else
246  {
247  if (!hasWarned)
248  {
249  hasWarned = true;
250 
251  WarningIn("void fluentFvMesh::writeFluentMesh() const")
252  << "foamMeshToFluent: cell shape for cell "
253  << cellI << " only supported by Fluent polyhedral meshes."
254  << nl
255  << " Suppressing any further messages for polyhedral"
256  << " cells." << endl;
257  }
258  fluentMeshFile << " " << 7;
259  }
260  }
261 
262  fluentMeshFile << ")())" << std::endl;
263 
264  // Return to dec
265  fluentMeshFile.setf(ios::dec, ios::basefield);
266 
267  // Writing patch types
268  fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
269  fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
270 
271  // Writing boundary patch types
272  forAll (boundary(), patchI)
273  {
274  fluentMeshFile
275  << "(39 (" << patchI + 10 << " ";
276 
277  // Write patch type
278  if (isA<wallFvPatch>(boundary()[patchI]))
279  {
280  fluentMeshFile << "wall ";
281  }
282  else if (isA<symmetryFvPatch>(boundary()[patchI]))
283  {
284  fluentMeshFile << "symmetry ";
285  }
286  else
287  {
288  fluentMeshFile << "pressure-outlet ";
289  }
290 
291  fluentMeshFile
292  << boundary()[patchI].name() << ")())" << std::endl;
293  }
294 }
295 
296 
297 // ************************ vim: set sw=4 sts=4 et: ************************ //