1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 surfaceMeshConvertTesting
29 Converts from one surface mesh format to another, but primarily
30 used for testing functionality.
33 - surfaceMeshConvertTesting inputFile outputFile [OPTION]
36 Perform some surface checking/cleanup on the input surface
39 Check face orientation on the input surface
41 @param -scale \<scale\> \n
42 Specify a scaling factor for writing the files
45 Use triSurface library for input/output
48 Use keyedSurface for input/output
51 The filename extensions are used to determine the file format type.
53 \*---------------------------------------------------------------------------*/
56 #include "timeSelector.H"
59 #include "triSurface.H"
61 #include "surfFields.H"
62 #include "surfPointFields.H"
63 #include "PackedBoolList.H"
65 #include "MeshedSurfaces.H"
66 #include "UnsortedMeshedSurfaces.H"
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 int main(int argc, char *argv[])
75 argList::noParallel();
76 argList::validArgs.append("inputFile");
77 argList::validArgs.append("outputFile");
78 argList::validOptions.insert("clean", "");
79 argList::validOptions.insert("orient", "");
80 argList::validOptions.insert("surfMesh", "");
81 argList::validOptions.insert("scale", "scale");
82 argList::validOptions.insert("triSurface", "");
83 argList::validOptions.insert("unsorted", "");
84 argList::validOptions.insert("triFace", "");
85 # include "setRootCase.H"
86 const stringList& params = args.additionalArgs();
88 scalar scaleFactor = 0;
89 args.optionReadIfPresent("scale", scaleFactor);
91 fileName importName(params[0]);
92 fileName exportName(params[1]);
94 if (importName == exportName)
96 FatalErrorIn(args.executable())
97 << "Output file " << exportName << " would overwrite input file."
103 !MeshedSurface<face>::canRead(importName, true)
104 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
110 if (args.optionFound("triSurface"))
112 triSurface surf(importName);
114 Info<< "Read surface:" << endl;
115 surf.writeStats(Info);
118 if (args.optionFound("orient"))
120 Info<< "Checking surface orientation" << endl;
121 PatchTools::checkOrientation(surf, true);
125 if (args.optionFound("clean"))
127 Info<< "Cleaning up surface" << endl;
129 surf.writeStats(Info);
133 Info<< "writing " << exportName;
134 if (scaleFactor <= 0)
136 Info<< " without scaling" << endl;
140 Info<< " with scaling " << scaleFactor << endl;
141 surf.scalePoints(scaleFactor);
142 surf.writeStats(Info);
146 // write sorted by region
147 surf.write(exportName, true);
149 else if (args.optionFound("unsorted"))
151 UnsortedMeshedSurface<face> surf(importName);
153 Info<< "Read surface:" << endl;
154 surf.writeStats(Info);
157 if (args.optionFound("orient"))
159 Info<< "Checking surface orientation" << endl;
160 PatchTools::checkOrientation(surf, true);
164 if (args.optionFound("clean"))
166 Info<< "Cleaning up surface" << endl;
168 surf.writeStats(Info);
172 Info<< "writing " << exportName;
173 if (scaleFactor <= 0)
175 Info<< " without scaling" << endl;
179 Info<< " with scaling " << scaleFactor << endl;
180 surf.scalePoints(scaleFactor);
181 surf.writeStats(Info);
184 surf.write(exportName);
187 else if (args.optionFound("triFace"))
189 MeshedSurface<triFace> surf(importName);
191 Info<< "Read surface:" << endl;
192 surf.writeStats(Info);
195 if (args.optionFound("orient"))
197 Info<< "Checking surface orientation" << endl;
198 PatchTools::checkOrientation(surf, true);
202 if (args.optionFound("clean"))
204 Info<< "Cleaning up surface" << endl;
206 surf.writeStats(Info);
210 Info<< "writing " << exportName;
211 if (scaleFactor <= 0)
213 Info<< " without scaling" << endl;
217 Info<< " with scaling " << scaleFactor << endl;
218 surf.scalePoints(scaleFactor);
219 surf.writeStats(Info);
222 surf.write(exportName);
227 MeshedSurface<face> surf(importName);
229 Info<< "Read surface:" << endl;
230 surf.writeStats(Info);
233 if (args.optionFound("orient"))
235 Info<< "Checking surface orientation" << endl;
236 PatchTools::checkOrientation(surf, true);
240 if (args.optionFound("clean"))
242 Info<< "Cleaning up surface" << endl;
244 surf.writeStats(Info);
249 Info<< "writing " << exportName;
250 if (scaleFactor <= 0)
252 Info<< " without scaling" << endl;
256 Info<< " with scaling " << scaleFactor << endl;
257 surf.scalePoints(scaleFactor);
258 surf.writeStats(Info);
261 surf.write(exportName);
263 if (args.optionFound("surfMesh"))
271 // start with "constant"
272 runTime.setTime(instant(0, runTime.constant()), 0);
274 Info<< "runTime.instance() = " << runTime.instance() << endl;
275 Info<< "runTime.timeName() = " << runTime.timeName() << endl;
278 Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
299 MeshedSurface<face> surfIn2(runTime, "foobar");
301 Info<<"surfIn2 = " << surfIn2.size() << endl;
303 Info<< "surfIn = " << surfIn.size() << endl;
306 Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
307 surfIn.write("oldSurfIn.obj");
310 Info<< "runTime.instance() = " << runTime.instance() << endl;
326 Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
329 surfLabelField zoneIds
343 Info<<" surf name= " << surfOut.name() <<nl;
344 Info<< "rename to anotherSurf" << endl;
345 surfOut.rename("anotherSurf");
347 Info<<" surf name= " << surfOut.name() <<nl;
350 runTime.setTime(instant(1), 1);
351 surfOut.setInstance(runTime.timeName());
355 Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
359 surfOut.write("someName.ofs");
362 const surfZoneList& zones = surfOut.surfZones();
373 Info<< "write zoneIds (for testing only): "
374 << zoneIds.objectPath() << endl;
377 surfPointLabelField pointIds
398 Info<< "write pointIds (for testing only): "
399 << pointIds.objectPath() << endl;
402 Info<<"surfMesh with these names: " << surfOut.names() << endl;
408 Info<< "\nEnd\n" << endl;
413 // ************************************************************************* //