1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 surfaceMeshConvertTesting
28 Converts from one surface mesh format to another, but primarily
29 used for testing functionality.
32 - surfaceMeshConvertTesting inputFile outputFile [OPTION]
35 Perform some surface checking/cleanup on the input surface
38 Check face orientation on the input surface
40 @param -scale \<scale\> \n
41 Specify a scaling factor for writing the files
44 Use triSurface library for input/output
47 Use keyedSurface for input/output
50 The filename extensions are used to determine the file format type.
52 \*---------------------------------------------------------------------------*/
55 #include "timeSelector.H"
58 #include "triSurface.H"
60 #include "surfFields.H"
61 #include "surfPointFields.H"
62 #include "PackedBoolList.H"
64 #include "MeshedSurfaces.H"
65 #include "UnsortedMeshedSurfaces.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 int main(int argc, char *argv[])
74 argList::noParallel();
75 argList::validArgs.append("inputFile");
76 argList::validArgs.append("outputFile");
77 argList::validOptions.insert("clean", "");
78 argList::validOptions.insert("orient", "");
79 argList::validOptions.insert("surfMesh", "");
80 argList::validOptions.insert("scale", "scale");
81 argList::validOptions.insert("triSurface", "");
82 argList::validOptions.insert("unsorted", "");
83 argList::validOptions.insert("triFace", "");
84 # include "setRootCase.H"
85 const stringList& params = args.additionalArgs();
87 scalar scaleFactor = 0;
88 args.optionReadIfPresent("scale", scaleFactor);
90 fileName importName(params[0]);
91 fileName exportName(params[1]);
93 if (importName == exportName)
95 FatalErrorIn(args.executable())
96 << "Output file " << exportName << " would overwrite input file."
102 !MeshedSurface<face>::canRead(importName, true)
103 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
109 if (args.optionFound("triSurface"))
111 triSurface surf(importName);
113 Info<< "Read surface:" << endl;
114 surf.writeStats(Info);
117 if (args.optionFound("orient"))
119 Info<< "Checking surface orientation" << endl;
120 PatchTools::checkOrientation(surf, true);
124 if (args.optionFound("clean"))
126 Info<< "Cleaning up surface" << endl;
128 surf.writeStats(Info);
132 Info<< "writing " << exportName;
133 if (scaleFactor <= 0)
135 Info<< " without scaling" << endl;
139 Info<< " with scaling " << scaleFactor << endl;
140 surf.scalePoints(scaleFactor);
141 surf.writeStats(Info);
145 // write sorted by region
146 surf.write(exportName, true);
148 else if (args.optionFound("unsorted"))
150 UnsortedMeshedSurface<face> surf(importName);
152 Info<< "Read surface:" << endl;
153 surf.writeStats(Info);
156 if (args.optionFound("orient"))
158 Info<< "Checking surface orientation" << endl;
159 PatchTools::checkOrientation(surf, true);
163 if (args.optionFound("clean"))
165 Info<< "Cleaning up surface" << endl;
167 surf.writeStats(Info);
171 Info<< "writing " << exportName;
172 if (scaleFactor <= 0)
174 Info<< " without scaling" << endl;
178 Info<< " with scaling " << scaleFactor << endl;
179 surf.scalePoints(scaleFactor);
180 surf.writeStats(Info);
183 surf.write(exportName);
186 else if (args.optionFound("triFace"))
188 MeshedSurface<triFace> surf(importName);
190 Info<< "Read surface:" << endl;
191 surf.writeStats(Info);
194 if (args.optionFound("orient"))
196 Info<< "Checking surface orientation" << endl;
197 PatchTools::checkOrientation(surf, true);
201 if (args.optionFound("clean"))
203 Info<< "Cleaning up surface" << endl;
205 surf.writeStats(Info);
209 Info<< "writing " << exportName;
210 if (scaleFactor <= 0)
212 Info<< " without scaling" << endl;
216 Info<< " with scaling " << scaleFactor << endl;
217 surf.scalePoints(scaleFactor);
218 surf.writeStats(Info);
221 surf.write(exportName);
226 MeshedSurface<face> surf(importName);
228 Info<< "Read surface:" << endl;
229 surf.writeStats(Info);
232 if (args.optionFound("orient"))
234 Info<< "Checking surface orientation" << endl;
235 PatchTools::checkOrientation(surf, true);
239 if (args.optionFound("clean"))
241 Info<< "Cleaning up surface" << endl;
243 surf.writeStats(Info);
248 Info<< "writing " << exportName;
249 if (scaleFactor <= 0)
251 Info<< " without scaling" << endl;
255 Info<< " with scaling " << scaleFactor << endl;
256 surf.scalePoints(scaleFactor);
257 surf.writeStats(Info);
260 surf.write(exportName);
262 if (args.optionFound("surfMesh"))
270 // start with "constant"
271 runTime.setTime(instant(0, runTime.constant()), 0);
273 Info<< "runTime.instance() = " << runTime.instance() << endl;
274 Info<< "runTime.timeName() = " << runTime.timeName() << endl;
277 Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
298 MeshedSurface<face> surfIn2(runTime, "foobar");
300 Info<<"surfIn2 = " << surfIn2.size() << endl;
302 Info<< "surfIn = " << surfIn.size() << endl;
305 Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
306 surfIn.write("oldSurfIn.obj");
309 Info<< "runTime.instance() = " << runTime.instance() << endl;
325 Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
328 surfLabelField zoneIds
342 Info<<" surf name= " << surfOut.name() <<nl;
343 Info<< "rename to anotherSurf" << endl;
344 surfOut.rename("anotherSurf");
346 Info<<" surf name= " << surfOut.name() <<nl;
349 runTime.setTime(instant(1), 1);
350 surfOut.setInstance(runTime.timeName());
354 Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
358 surfOut.write("someName.ofs");
361 const surfZoneList& zones = surfOut.surfZones();
372 Info<< "write zoneIds (for testing only): "
373 << zoneIds.objectPath() << endl;
376 surfPointLabelField pointIds
397 Info<< "write pointIds (for testing only): "
398 << pointIds.objectPath() << endl;
401 Info<<"surfMesh with these names: " << surfOut.names() << endl;
407 Info<< "\nEnd\n" << endl;
412 // ************************************************************************* //