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) 2011-2015 OpenFOAM Foundation
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 -clean \n
35  Perform some surface checking/cleanup on the input surface
36 
37  \param -orient \n
38  Check face orientation on the input surface
39 
40  \param -scale <scale> \n
41  Specify a scaling factor for writing the files
42 
43  \param -triSurface \n
44  Use triSurface library for input/output
45 
46  \param -keyed \n
47  Use keyedSurface for input/output
48 
49 Note
50  The filename extensions are used to determine the file format type.
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #include "argList.H"
55 #include "Time.H"
56 #include "polyMesh.H"
57 #include "triSurface.H"
58 #include "surfMesh.H"
59 #include "surfFields.H"
60 #include "surfPointFields.H"
61 #include "PackedBoolList.H"
62 
63 #include "MeshedSurfaces.H"
64 #include "UnsortedMeshedSurfaces.H"
65 
66 using namespace Foam;
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 int main(int argc, char *argv[])
71 {
73  (
74  "convert between surface formats, "
75  "but primarily for testing functionality\n"
76  "Normally use surfaceMeshConvert instead."
77  );
78 
80  argList::validArgs.append("inputFile");
81  argList::validArgs.append("outputFile");
82 
83  argList::addBoolOption("clean");
84  argList::addBoolOption("orient");
85  argList::addBoolOption("surfMesh");
86  argList::addBoolOption("triSurface");
87  argList::addBoolOption("unsorted");
88  argList::addBoolOption("triFace");
89 
91  (
92  "scale",
93  "factor",
94  "geometry scaling factor - default is 1"
95  );
96 
97  #include "setRootCase.H"
98 
99  const scalar scaleFactor = args.optionLookupOrDefault("scale", 0.0);
100 
101  const fileName importName = args[1];
102  const fileName exportName = args[2];
103 
104  if (importName == exportName)
105  {
107  << "Output file " << exportName << " would overwrite input file."
108  << exit(FatalError);
109  }
110 
111  if
112  (
113  !MeshedSurface<face>::canRead(importName, true)
114  || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
115  )
116  {
117  return 1;
118  }
119 
120  if (args.optionFound("triSurface"))
121  {
122  triSurface surf(importName);
123 
124  Info<< "Read surface:" << endl;
125  surf.writeStats(Info);
126  Info<< endl;
127 
128  if (args.optionFound("orient"))
129  {
130  Info<< "Checking surface orientation" << endl;
131  PatchTools::checkOrientation(surf, true);
132  Info<< endl;
133  }
134 
135  if (args.optionFound("clean"))
136  {
137  Info<< "Cleaning up surface" << endl;
138  surf.cleanup(true);
139  surf.writeStats(Info);
140  Info<< endl;
141  }
142 
143  Info<< "writing " << exportName;
144  if (scaleFactor <= 0)
145  {
146  Info<< " without scaling" << endl;
147  }
148  else
149  {
150  Info<< " with scaling " << scaleFactor << endl;
151  surf.scalePoints(scaleFactor);
152  surf.writeStats(Info);
153  Info<< endl;
154  }
155 
156  // write sorted by region
157  surf.write(exportName, true);
158  }
159  else if (args.optionFound("unsorted"))
160  {
161  UnsortedMeshedSurface<face> surf(importName);
162 
163  Info<< "Read surface:" << endl;
164  surf.writeStats(Info);
165  Info<< endl;
166 
167  if (args.optionFound("orient"))
168  {
169  Info<< "Checking surface orientation" << endl;
170  PatchTools::checkOrientation(surf, true);
171  Info<< endl;
172  }
173 
174  if (args.optionFound("clean"))
175  {
176  Info<< "Cleaning up surface" << endl;
177  surf.cleanup(true);
178  surf.writeStats(Info);
179  Info<< endl;
180  }
181 
182  Info<< "writing " << exportName;
183  if (scaleFactor <= 0)
184  {
185  Info<< " without scaling" << endl;
186  }
187  else
188  {
189  Info<< " with scaling " << scaleFactor << endl;
190  surf.scalePoints(scaleFactor);
191  surf.writeStats(Info);
192  Info<< endl;
193  }
194  surf.write(exportName);
195  }
196 #if 1
197  else if (args.optionFound("triFace"))
198  {
199  MeshedSurface<triFace> surf(importName);
200 
201  Info<< "Read surface:" << endl;
202  surf.writeStats(Info);
203  Info<< endl;
204 
205  if (args.optionFound("orient"))
206  {
207  Info<< "Checking surface orientation" << endl;
208  PatchTools::checkOrientation(surf, true);
209  Info<< endl;
210  }
211 
212  if (args.optionFound("clean"))
213  {
214  Info<< "Cleaning up surface" << endl;
215  surf.cleanup(true);
216  surf.writeStats(Info);
217  Info<< endl;
218  }
219 
220  Info<< "writing " << exportName;
221  if (scaleFactor <= 0)
222  {
223  Info<< " without scaling" << endl;
224  }
225  else
226  {
227  Info<< " with scaling " << scaleFactor << endl;
228  surf.scalePoints(scaleFactor);
229  surf.writeStats(Info);
230  Info<< endl;
231  }
232  surf.write(exportName);
233  }
234 #endif
235  else
236  {
237  MeshedSurface<face> surf(importName);
238 
239  Info<< "Read surface:" << endl;
240  surf.writeStats(Info);
241  Info<< endl;
242 
243  if (args.optionFound("orient"))
244  {
245  Info<< "Checking surface orientation" << endl;
246  PatchTools::checkOrientation(surf, true);
247  Info<< endl;
248  }
249 
250  if (args.optionFound("clean"))
251  {
252  Info<< "Cleaning up surface" << endl;
253  surf.cleanup(true);
254  surf.writeStats(Info);
255  Info<< endl;
256  }
257 
258 
259  Info<< "writing " << exportName;
260  if (scaleFactor <= 0)
261  {
262  Info<< " without scaling" << endl;
263  }
264  else
265  {
266  Info<< " with scaling " << scaleFactor << endl;
267  surf.scalePoints(scaleFactor);
268  surf.writeStats(Info);
269  Info<< endl;
270  }
271  surf.write(exportName);
272 
273  if (args.optionFound("surfMesh"))
274  {
275  Foam::Time runTime
276  (
277  args.rootPath(),
278  args.caseName()
279  );
280 
281  // start with "constant"
282  runTime.setTime(instant(0, runTime.constant()), 0);
283 
284  Info<< "runTime.instance() = " << runTime.instance() << endl;
285  Info<< "runTime.timeName() = " << runTime.timeName() << endl;
286 
287 
288  Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
289  << endl;
290  surf.write
291  (
292  runTime,
293  "yetAnother"
294  );
295 
296  surfMesh surfIn
297  (
298  IOobject
299  (
300  "default",
301  runTime.timeName(),
302  runTime,
305  )
306  );
307 
308 
309  MeshedSurface<face> surfIn2(runTime, "foobar");
310 
311  Info<<"surfIn2 = " << surfIn2.size() << endl;
312 
313  Info<< "surfIn = " << surfIn.size() << endl;
314 
315 
316  Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
317  surfIn.write("oldSurfIn.obj");
318 
319 
320  Info<< "runTime.instance() = " << runTime.instance() << endl;
321 
322  surfMesh surfOut
323  (
324  IOobject
325  (
326  "mySurf",
327  runTime.instance(),
328  runTime,
331  false
332  ),
333  surf.xfer()
334  );
335 
336  Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
337  surfOut.write();
338 
339  surfLabelField zoneIds
340  (
341  IOobject
342  (
343  "zoneIds",
344  surfOut.instance(),
345  surfOut,
348  ),
349  surfOut,
350  dimless
351  );
352 
353  Info<<" surf name= " << surfOut.name() <<nl;
354  Info<< "rename to anotherSurf" << endl;
355  surfOut.rename("anotherSurf");
356 
357  Info<<" surf name= " << surfOut.name() <<nl;
358 
359  // advance time to 1
360  runTime.setTime(instant(1), 1);
361  surfOut.setInstance(runTime.timeName());
362 
363 
364 
365  Info<< "writing surfMesh again well: " << surfOut.objectPath()
366  << endl;
367  surfOut.write();
368 
369  // write directly
370  surfOut.write("someName.ofs");
371 
372 #if 1
373  const surfZoneList& zones = surfOut.surfZones();
374  forAll(zones, zoneI)
375  {
377  (
378  zoneIds,
379  zones[zoneI].size(),
380  zones[zoneI].start()
381  ) = zoneI;
382  }
383 
384  Info<< "write zoneIds (for testing only): "
385  << zoneIds.objectPath() << endl;
386  zoneIds.write();
387 
388  surfPointLabelField pointIds
389  (
390  IOobject
391  (
392  "zoneIds.",
393 // "pointIds",
394  surfOut.instance(),
395 // "pointFields",
396  surfOut,
399  ),
400  surfOut,
401  dimless
402  );
403 
404  forAll(pointIds, i)
405  {
406  pointIds[i] = i;
407  }
408 
409  Info<< "write pointIds (for testing only): "
410  << pointIds.objectPath() << endl;
411  pointIds.write();
412 
413  Info<<"surfMesh with these names: " << surfOut.names() << endl;
414 
415 #endif
416  }
417  }
418 
419  Info<< "\nEnd\n" << endl;
420 
421  return 0;
422 }
423 
424 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::surfMesh
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:74
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
PackedBoolList.H
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam::argList::optionLookupOrDefault
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:237
Foam::FatalError
error FatalError
surfMesh.H
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
setRootCase.H
surfPointFields.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
MeshedSurfaces.H
surfFields.H
UnsortedMeshedSurfaces.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:64
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::MeshedSurface
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:72
args
Foam::argList args(argc, argv)
Foam::PatchTools::checkOrientation
static bool checkOrientation(const PrimitivePatch< Face, FaceList, PointField, PointType > &, const bool report=false, labelHashSet *marked=0)
Check for orientation issues.
Definition: PatchToolsCheck.C:40
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51