ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / applications / utilities / surface / surfaceMeshConvertTesting / surfaceMeshConvertTesting.C
blob34b56d5477afd92eef7b2f6ace09ae46ca044af2
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.
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
19     for more details.
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/>.
24 Application
25     surfaceMeshConvertTesting
27 Description
28     Converts from one surface mesh format to another, but primarily
29     used for testing functionality.
31 Usage
32     - surfaceMeshConvertTesting inputFile outputFile [OPTION]
34     @param -clean \n
35     Perform some surface checking/cleanup on the input surface
37     @param -orient \n
38     Check face orientation on the input surface
40     @param -scale \<scale\> \n
41     Specify a scaling factor for writing the files
43     @param -triSurface \n
44     Use triSurface library for input/output
46     @param -keyed \n
47     Use keyedSurface for input/output
49 Note
50     The filename extensions are used to determine the file format type.
52 \*---------------------------------------------------------------------------*/
54 #include "argList.H"
55 #include "timeSelector.H"
56 #include "Time.H"
57 #include "polyMesh.H"
58 #include "triSurface.H"
59 #include "surfMesh.H"
60 #include "surfFields.H"
61 #include "surfPointFields.H"
62 #include "PackedBoolList.H"
64 #include "MeshedSurfaces.H"
65 #include "UnsortedMeshedSurfaces.H"
67 using namespace Foam;
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 //  Main program:
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)
94     {
95         FatalErrorIn(args.executable())
96             << "Output file " << exportName << " would overwrite input file."
97             << exit(FatalError);
98     }
100     if
101     (
102         !MeshedSurface<face>::canRead(importName, true)
103      || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
104     )
105     {
106         return 1;
107     }
109     if (args.optionFound("triSurface"))
110     {
111         triSurface surf(importName);
113         Info<< "Read surface:" << endl;
114         surf.writeStats(Info);
115         Info<< endl;
117         if (args.optionFound("orient"))
118         {
119             Info<< "Checking surface orientation" << endl;
120             PatchTools::checkOrientation(surf, true);
121             Info<< endl;
122         }
124         if (args.optionFound("clean"))
125         {
126             Info<< "Cleaning up surface" << endl;
127             surf.cleanup(true);
128             surf.writeStats(Info);
129             Info<< endl;
130         }
132         Info<< "writing " << exportName;
133         if (scaleFactor <= 0)
134         {
135             Info<< " without scaling" << endl;
136         }
137         else
138         {
139             Info<< " with scaling " << scaleFactor << endl;
140             surf.scalePoints(scaleFactor);
141             surf.writeStats(Info);
142             Info<< endl;
143         }
145         // write sorted by region
146         surf.write(exportName, true);
147     }
148     else if (args.optionFound("unsorted"))
149     {
150         UnsortedMeshedSurface<face> surf(importName);
152         Info<< "Read surface:" << endl;
153         surf.writeStats(Info);
154         Info<< endl;
156         if (args.optionFound("orient"))
157         {
158             Info<< "Checking surface orientation" << endl;
159             PatchTools::checkOrientation(surf, true);
160             Info<< endl;
161         }
163         if (args.optionFound("clean"))
164         {
165             Info<< "Cleaning up surface" << endl;
166             surf.cleanup(true);
167             surf.writeStats(Info);
168             Info<< endl;
169         }
171         Info<< "writing " << exportName;
172         if (scaleFactor <= 0)
173         {
174             Info<< " without scaling" << endl;
175         }
176         else
177         {
178             Info<< " with scaling " << scaleFactor << endl;
179             surf.scalePoints(scaleFactor);
180             surf.writeStats(Info);
181             Info<< endl;
182         }
183         surf.write(exportName);
184     }
185 #if 1
186     else if (args.optionFound("triFace"))
187     {
188         MeshedSurface<triFace> surf(importName);
190         Info<< "Read surface:" << endl;
191         surf.writeStats(Info);
192         Info<< endl;
194         if (args.optionFound("orient"))
195         {
196             Info<< "Checking surface orientation" << endl;
197             PatchTools::checkOrientation(surf, true);
198             Info<< endl;
199         }
201         if (args.optionFound("clean"))
202         {
203             Info<< "Cleaning up surface" << endl;
204             surf.cleanup(true);
205             surf.writeStats(Info);
206             Info<< endl;
207         }
209         Info<< "writing " << exportName;
210         if (scaleFactor <= 0)
211         {
212             Info<< " without scaling" << endl;
213         }
214         else
215         {
216             Info<< " with scaling " << scaleFactor << endl;
217             surf.scalePoints(scaleFactor);
218             surf.writeStats(Info);
219             Info<< endl;
220         }
221         surf.write(exportName);
222     }
223 #endif
224     else
225     {
226         MeshedSurface<face> surf(importName);
228         Info<< "Read surface:" << endl;
229         surf.writeStats(Info);
230         Info<< endl;
232         if (args.optionFound("orient"))
233         {
234             Info<< "Checking surface orientation" << endl;
235             PatchTools::checkOrientation(surf, true);
236             Info<< endl;
237         }
239         if (args.optionFound("clean"))
240         {
241             Info<< "Cleaning up surface" << endl;
242             surf.cleanup(true);
243             surf.writeStats(Info);
244             Info<< endl;
245         }
248         Info<< "writing " << exportName;
249         if (scaleFactor <= 0)
250         {
251             Info<< " without scaling" << endl;
252         }
253         else
254         {
255             Info<< " with scaling " << scaleFactor << endl;
256             surf.scalePoints(scaleFactor);
257             surf.writeStats(Info);
258             Info<< endl;
259         }
260         surf.write(exportName);
262         if (args.optionFound("surfMesh"))
263         {
264             Foam::Time runTime
265             (
266                 args.rootPath(),
267                 args.caseName()
268             );
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"
278                 << endl;
279             surf.write
280             (
281                 runTime,
282                 "yetAnother"
283             );
285             surfMesh surfIn
286             (
287                 IOobject
288                 (
289                     "default",
290                     runTime.timeName(),
291                     runTime,
292                     IOobject::MUST_READ,
293                     IOobject::NO_WRITE
294                 )
295             );
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;
311             surfMesh surfOut
312             (
313                 IOobject
314                 (
315                     "mySurf",
316                     runTime.instance(),
317                     runTime,
318                     IOobject::NO_READ,
319                     IOobject::NO_WRITE,
320                     false
321                 ),
322                 surf.xfer()
323             );
325             Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
326             surfOut.write();
328             surfLabelField zoneIds
329             (
330                 IOobject
331                 (
332                     "zoneIds",
333                     surfOut.instance(),
334                     surfOut,
335                     IOobject::NO_READ,
336                     IOobject::NO_WRITE
337                 ),
338                 surfOut,
339                 dimless
340             );
342             Info<<" surf name= " << surfOut.name() <<nl;
343             Info<< "rename to anotherSurf" << endl;
344             surfOut.rename("anotherSurf");
346             Info<<" surf name= " << surfOut.name() <<nl;
348             // advance time to 1
349             runTime.setTime(instant(1), 1);
350             surfOut.setInstance(runTime.timeName());
354             Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
355             surfOut.write();
357             // write directly
358             surfOut.write("someName.ofs");
360 #if 1
361             const surfZoneList& zones = surfOut.surfZones();
362             forAll(zones, zoneI)
363             {
364                 SubList<label>
365                 (
366                     zoneIds,
367                     zones[zoneI].size(),
368                     zones[zoneI].start()
369                 ) = zoneI;
370             }
372             Info<< "write zoneIds (for testing only): "
373                 << zoneIds.objectPath() << endl;
374             zoneIds.write();
376             surfPointLabelField pointIds
377             (
378                 IOobject
379                 (
380                     "zoneIds.",
381 //                    "pointIds",
382                     surfOut.instance(),
383 //                    "pointFields",
384                     surfOut,
385                     IOobject::NO_READ,
386                     IOobject::NO_WRITE
387                 ),
388                 surfOut,
389                 dimless
390             );
392             forAll(pointIds, i)
393             {
394                 pointIds[i] = i;
395             }
397             Info<< "write pointIds (for testing only): "
398                 << pointIds.objectPath() << endl;
399             pointIds.write();
401             Info<<"surfMesh with these names: " << surfOut.names() << endl;
403 #endif
404         }
405     }
407     Info<< "\nEnd\n" << endl;
409     return 0;
412 // ************************************************************************* //