FreeFOAM The Cross-Platform CFD Toolkit
surfaceMeshConvertTesting.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  surfaceMeshConvertTesting
26 
27 Description
28  Converts from one surface mesh format to another, but primarily
29  used for testing functionality.
30 
31 Usage
32  - surfaceMeshConvertTesting inputFile outputFile [OPTION]
33 
34  @param <inputfile> \n
35  Surface file to be converted.
36 
37  @param <outputFile> \n
38  File into which to write the converted surface.
39 
40  @param -clean \n
41  Perform some surface checking/cleanup on the input surface.
42 
43  @param -orient \n
44  Check face orientation on the input surface.
45 
46  @param -scale <scale> \n
47  Specify a scaling factor for writing the files.
48 
49  @param -triSurface \n
50  Use triSurface library for input/output.
51 
52  @param -keyed \n
53  Use keyedSurface for input/output.
54 
55  @param -case <dir> \n
56  Specify the case directory.
57 
58  @param -help \n
59  Display short usage message.
60 
61  @param -doc \n
62  Display Doxygen documentation page.
63 
64  @param -srcDoc \n
65  Display source code.
66 
67 Note
68  The filename extensions are used to determine the file format type.
69 
70 \*---------------------------------------------------------------------------*/
71 
72 #include <OpenFOAM/argList.H>
73 #include <OpenFOAM/timeSelector.H>
74 #include <OpenFOAM/Time.H>
75 #include <OpenFOAM/polyMesh.H>
76 #include <triSurface/triSurface.H>
77 #include <surfMesh/surfMesh.H>
78 #include <surfMesh/surfFields.H>
81 
84 
85 using namespace Foam;
86 
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 // Main program:
89 
90 int main(int argc, char *argv[])
91 {
93  argList::validArgs.append("inputFile");
94  argList::validArgs.append("outputFile");
95  argList::validOptions.insert("clean", "");
96  argList::validOptions.insert("orient", "");
97  argList::validOptions.insert("surfMesh", "");
98  argList::validOptions.insert("scale", "scale");
99  argList::validOptions.insert("triSurface", "");
100  argList::validOptions.insert("unsorted", "");
101  argList::validOptions.insert("triFace", "");
102 # include <OpenFOAM/setRootCase.H>
103  const stringList& params = args.additionalArgs();
104 
105  scalar scaleFactor = 0;
106  args.optionReadIfPresent("scale", scaleFactor);
107 
108  fileName importName(params[0]);
109  fileName exportName(params[1]);
110 
111  if (importName == exportName)
112  {
114  << "Output file " << exportName << " would overwrite input file."
115  << exit(FatalError);
116  }
117 
118  if
119  (
120  !MeshedSurface<face>::canRead(importName, true)
121  || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
122  )
123  {
124  return 1;
125  }
126 
127  if (args.optionFound("triSurface"))
128  {
129  triSurface surf(importName);
130 
131  Info<< "Read surface:" << endl;
132  surf.writeStats(Info);
133  Info<< endl;
134 
135  if (args.optionFound("orient"))
136  {
137  Info<< "Checking surface orientation" << endl;
138  PatchTools::checkOrientation(surf, true);
139  Info<< endl;
140  }
141 
142  if (args.optionFound("clean"))
143  {
144  Info<< "Cleaning up surface" << endl;
145  surf.cleanup(true);
146  surf.writeStats(Info);
147  Info<< endl;
148  }
149 
150  Info<< "writing " << exportName;
151  if (scaleFactor <= 0)
152  {
153  Info<< " without scaling" << endl;
154  }
155  else
156  {
157  Info<< " with scaling " << scaleFactor << endl;
158  surf.scalePoints(scaleFactor);
159  surf.writeStats(Info);
160  Info<< endl;
161  }
162 
163  // write sorted by region
164  surf.write(exportName, true);
165  }
166  else if (args.optionFound("unsorted"))
167  {
168  UnsortedMeshedSurface<face> surf(importName);
169 
170  Info<< "Read surface:" << endl;
171  surf.writeStats(Info);
172  Info<< endl;
173 
174  if (args.optionFound("orient"))
175  {
176  Info<< "Checking surface orientation" << endl;
177  PatchTools::checkOrientation(surf, true);
178  Info<< endl;
179  }
180 
181  if (args.optionFound("clean"))
182  {
183  Info<< "Cleaning up surface" << endl;
184  surf.cleanup(true);
185  surf.writeStats(Info);
186  Info<< endl;
187  }
188 
189  Info<< "writing " << exportName;
190  if (scaleFactor <= 0)
191  {
192  Info<< " without scaling" << endl;
193  }
194  else
195  {
196  Info<< " with scaling " << scaleFactor << endl;
197  surf.scalePoints(scaleFactor);
198  surf.writeStats(Info);
199  Info<< endl;
200  }
201  surf.write(exportName);
202  }
203 #if 1
204  else if (args.optionFound("triFace"))
205  {
206  MeshedSurface<triFace> surf(importName);
207 
208  Info<< "Read surface:" << endl;
209  surf.writeStats(Info);
210  Info<< endl;
211 
212  if (args.optionFound("orient"))
213  {
214  Info<< "Checking surface orientation" << endl;
215  PatchTools::checkOrientation(surf, true);
216  Info<< endl;
217  }
218 
219  if (args.optionFound("clean"))
220  {
221  Info<< "Cleaning up surface" << endl;
222  surf.cleanup(true);
223  surf.writeStats(Info);
224  Info<< endl;
225  }
226 
227  Info<< "writing " << exportName;
228  if (scaleFactor <= 0)
229  {
230  Info<< " without scaling" << endl;
231  }
232  else
233  {
234  Info<< " with scaling " << scaleFactor << endl;
235  surf.scalePoints(scaleFactor);
236  surf.writeStats(Info);
237  Info<< endl;
238  }
239  surf.write(exportName);
240  }
241 #endif
242  else
243  {
244  MeshedSurface<face> surf(importName);
245 
246  Info<< "Read surface:" << endl;
247  surf.writeStats(Info);
248  Info<< endl;
249 
250  if (args.optionFound("orient"))
251  {
252  Info<< "Checking surface orientation" << endl;
253  PatchTools::checkOrientation(surf, true);
254  Info<< endl;
255  }
256 
257  if (args.optionFound("clean"))
258  {
259  Info<< "Cleaning up surface" << endl;
260  surf.cleanup(true);
261  surf.writeStats(Info);
262  Info<< endl;
263  }
264 
265 
266  Info<< "writing " << exportName;
267  if (scaleFactor <= 0)
268  {
269  Info<< " without scaling" << endl;
270  }
271  else
272  {
273  Info<< " with scaling " << scaleFactor << endl;
274  surf.scalePoints(scaleFactor);
275  surf.writeStats(Info);
276  Info<< endl;
277  }
278  surf.write(exportName);
279 
280  if (args.optionFound("surfMesh"))
281  {
282  Foam::Time runTime
283  (
284  args.rootPath(),
285  args.caseName()
286  );
287 
288  // start with "constant"
289  runTime.setTime(instant(0, runTime.constant()), 0);
290 
291  Info<< "runTime.instance() = " << runTime.instance() << endl;
292  Info<< "runTime.timeName() = " << runTime.timeName() << endl;
293 
294 
295  Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
296  << endl;
297  surf.write
298  (
299  runTime,
300  "yetAnother"
301  );
302 
303  surfMesh surfIn
304  (
305  IOobject
306  (
307  "default",
308  runTime.timeName(),
309  runTime,
312  )
313  );
314 
315 
316  MeshedSurface<face> surfIn2(runTime, "foobar");
317 
318  Info<<"surfIn2 = " << surfIn2.size() << endl;
319 
320  Info<< "surfIn = " << surfIn.size() << endl;
321 
322 
323  Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
324  surfIn.write("oldSurfIn.obj");
325 
326 
327  Info<< "runTime.instance() = " << runTime.instance() << endl;
328 
329  surfMesh surfOut
330  (
331  IOobject
332  (
333  "mySurf",
334  runTime.instance(),
335  runTime,
338  false
339  ),
340  surf.xfer()
341  );
342 
343  Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
344  surfOut.write();
345 
346  surfLabelField zoneIds
347  (
348  IOobject
349  (
350  "zoneIds",
351  surfOut.instance(),
352  surfOut,
355  ),
356  surfOut,
357  dimless
358  );
359 
360  Info<<" surf name= " << surfOut.name() <<nl;
361  Info<< "rename to anotherSurf" << endl;
362  surfOut.rename("anotherSurf");
363 
364  Info<<" surf name= " << surfOut.name() <<nl;
365 
366  // advance time to 1
367  runTime.setTime(instant(1), 1);
368  surfOut.setInstance(runTime.timeName());
369 
370 
371 
372  Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
373  surfOut.write();
374 
375  // write directly
376  surfOut.write("someName.ofs");
377 
378 #if 1
379  const surfZoneList& zones = surfOut.surfZones();
380  forAll(zones, zoneI)
381  {
383  (
384  zoneIds,
385  zones[zoneI].size(),
386  zones[zoneI].start()
387  ) = zoneI;
388  }
389 
390  Info<< "write zoneIds (for testing only): "
391  << zoneIds.objectPath() << endl;
392  zoneIds.write();
393 
394  surfPointLabelField pointIds
395  (
396  IOobject
397  (
398  "zoneIds.",
399 // "pointIds",
400  surfOut.instance(),
401 // "pointFields",
402  surfOut,
405  ),
406  surfOut,
407  dimless
408  );
409 
410  forAll(pointIds, i)
411  {
412  pointIds[i] = i;
413  }
414 
415  Info<< "write pointIds (for testing only): "
416  << pointIds.objectPath() << endl;
417  pointIds.write();
418 
419  Info<<"surfMesh with these names: " << surfOut.names() << endl;
420 
421 #endif
422  }
423  }
424 
425  Info<< "\nEnd\n" << endl;
426 
427  return 0;
428 }
429 
430 // ************************ vim: set sw=4 sts=4 et: ************************ //