initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / surface / surfaceMeshConvertTesting / surfaceMeshConvertTesting.C
blobe53a8616d824e3ad1d61a6542f8a35fcb7c940e1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 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
19     for more details.
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
25 Application
26     surfaceMeshConvertTesting
28 Description
29     Converts from one surface mesh format to another, but primarily
30     used for testing functionality.
32 Usage
33     - surfaceMeshConvertTesting inputFile outputFile [OPTION]
35     @param -clean \n
36     Perform some surface checking/cleanup on the input surface
38     @param -orient \n
39     Check face orientation on the input surface
41     @param -scale \<scale\> \n
42     Specify a scaling factor for writing the files
44     @param -triSurface \n
45     Use triSurface library for input/output
47     @param -keyed \n
48     Use keyedSurface for input/output
50 Note
51     The filename extensions are used to determine the file format type.
53 \*---------------------------------------------------------------------------*/
55 #include "argList.H"
56 #include "timeSelector.H"
57 #include "Time.H"
58 #include "polyMesh.H"
59 #include "triSurface.H"
60 #include "surfMesh.H"
61 #include "surfFields.H"
62 #include "surfPointFields.H"
63 #include "PackedBoolList.H"
65 #include "MeshedSurfaces.H"
66 #include "UnsortedMeshedSurfaces.H"
68 using namespace Foam;
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 //  Main program:
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)
95     {
96         FatalErrorIn(args.executable())
97             << "Output file " << exportName << " would overwrite input file."
98             << exit(FatalError);
99     }
101     if
102     (
103         !MeshedSurface<face>::canRead(importName, true)
104      || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
105     )
106     {
107         return 1;
108     }
110     if (args.optionFound("triSurface"))
111     {
112         triSurface surf(importName);
114         Info<< "Read surface:" << endl;
115         surf.writeStats(Info);
116         Info<< endl;
118         if (args.optionFound("orient"))
119         {
120             Info<< "Checking surface orientation" << endl;
121             PatchTools::checkOrientation(surf, true);
122             Info<< endl;
123         }
125         if (args.optionFound("clean"))
126         {
127             Info<< "Cleaning up surface" << endl;
128             surf.cleanup(true);
129             surf.writeStats(Info);
130             Info<< endl;
131         }
133         Info<< "writing " << exportName;
134         if (scaleFactor <= 0)
135         {
136             Info<< " without scaling" << endl;
137         }
138         else
139         {
140             Info<< " with scaling " << scaleFactor << endl;
141             surf.scalePoints(scaleFactor);
142             surf.writeStats(Info);
143             Info<< endl;
144         }
146         // write sorted by region
147         surf.write(exportName, true);
148     }
149     else if (args.optionFound("unsorted"))
150     {
151         UnsortedMeshedSurface<face> surf(importName);
153         Info<< "Read surface:" << endl;
154         surf.writeStats(Info);
155         Info<< endl;
157         if (args.optionFound("orient"))
158         {
159             Info<< "Checking surface orientation" << endl;
160             PatchTools::checkOrientation(surf, true);
161             Info<< endl;
162         }
164         if (args.optionFound("clean"))
165         {
166             Info<< "Cleaning up surface" << endl;
167             surf.cleanup(true);
168             surf.writeStats(Info);
169             Info<< endl;
170         }
172         Info<< "writing " << exportName;
173         if (scaleFactor <= 0)
174         {
175             Info<< " without scaling" << endl;
176         }
177         else
178         {
179             Info<< " with scaling " << scaleFactor << endl;
180             surf.scalePoints(scaleFactor);
181             surf.writeStats(Info);
182             Info<< endl;
183         }
184         surf.write(exportName);
185     }
186 #if 1
187     else if (args.optionFound("triFace"))
188     {
189         MeshedSurface<triFace> surf(importName);
191         Info<< "Read surface:" << endl;
192         surf.writeStats(Info);
193         Info<< endl;
195         if (args.optionFound("orient"))
196         {
197             Info<< "Checking surface orientation" << endl;
198             PatchTools::checkOrientation(surf, true);
199             Info<< endl;
200         }
202         if (args.optionFound("clean"))
203         {
204             Info<< "Cleaning up surface" << endl;
205             surf.cleanup(true);
206             surf.writeStats(Info);
207             Info<< endl;
208         }
210         Info<< "writing " << exportName;
211         if (scaleFactor <= 0)
212         {
213             Info<< " without scaling" << endl;
214         }
215         else
216         {
217             Info<< " with scaling " << scaleFactor << endl;
218             surf.scalePoints(scaleFactor);
219             surf.writeStats(Info);
220             Info<< endl;
221         }
222         surf.write(exportName);
223     }
224 #endif
225     else
226     {
227         MeshedSurface<face> surf(importName);
229         Info<< "Read surface:" << endl;
230         surf.writeStats(Info);
231         Info<< endl;
233         if (args.optionFound("orient"))
234         {
235             Info<< "Checking surface orientation" << endl;
236             PatchTools::checkOrientation(surf, true);
237             Info<< endl;
238         }
240         if (args.optionFound("clean"))
241         {
242             Info<< "Cleaning up surface" << endl;
243             surf.cleanup(true);
244             surf.writeStats(Info);
245             Info<< endl;
246         }
249         Info<< "writing " << exportName;
250         if (scaleFactor <= 0)
251         {
252             Info<< " without scaling" << endl;
253         }
254         else
255         {
256             Info<< " with scaling " << scaleFactor << endl;
257             surf.scalePoints(scaleFactor);
258             surf.writeStats(Info);
259             Info<< endl;
260         }
261         surf.write(exportName);
263         if (args.optionFound("surfMesh"))
264         {
265             Foam::Time runTime
266             (
267                 args.rootPath(),
268                 args.caseName()
269             );
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"
279                 << endl;
280             surf.write
281             (
282                 runTime,
283                 "yetAnother"
284             );
286             surfMesh surfIn
287             (
288                 IOobject
289                 (
290                     "default",
291                     runTime.timeName(),
292                     runTime,
293                     IOobject::MUST_READ,
294                     IOobject::NO_WRITE
295                 )
296             );
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;
312             surfMesh surfOut
313             (
314                 IOobject
315                 (
316                     "mySurf",
317                     runTime.instance(),
318                     runTime,
319                     IOobject::NO_READ,
320                     IOobject::NO_WRITE,
321                     false
322                 ),
323                 surf.xfer()
324             );
326             Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
327             surfOut.write();
329             surfLabelField zoneIds
330             (
331                 IOobject
332                 (
333                     "zoneIds",
334                     surfOut.instance(),
335                     surfOut,
336                     IOobject::NO_READ,
337                     IOobject::NO_WRITE
338                 ),
339                 surfOut,
340                 dimless
341             );
343             Info<<" surf name= " << surfOut.name() <<nl;
344             Info<< "rename to anotherSurf" << endl;
345             surfOut.rename("anotherSurf");
347             Info<<" surf name= " << surfOut.name() <<nl;
349             // advance time to 1
350             runTime.setTime(instant(1), 1);
351             surfOut.setInstance(runTime.timeName());
355             Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
356             surfOut.write();
358             // write directly
359             surfOut.write("someName.ofs");
361 #if 1
362             const surfZoneList& zones = surfOut.surfZones();
363             forAll(zones, zoneI)
364             {
365                 SubList<label>
366                 (
367                     zoneIds,
368                     zones[zoneI].size(),
369                     zones[zoneI].start()
370                 ) = zoneI;
371             }
373             Info<< "write zoneIds (for testing only): "
374                 << zoneIds.objectPath() << endl;
375             zoneIds.write();
377             surfPointLabelField pointIds
378             (
379                 IOobject
380                 (
381                     "zoneIds.",
382 //                    "pointIds",
383                     surfOut.instance(),
384 //                    "pointFields",
385                     surfOut,
386                     IOobject::NO_READ,
387                     IOobject::NO_WRITE
388                 ),
389                 surfOut,
390                 dimless
391             );
393             forAll(pointIds, i)
394             {
395                 pointIds[i] = i;
396             }
398             Info<< "write pointIds (for testing only): "
399                 << pointIds.objectPath() << endl;
400             pointIds.write();
402             Info<<"surfMesh with these names: " << surfOut.names() << endl;
404 #endif
405         }
406     }
408     Info<< "\nEnd\n" << endl;
410     return 0;
413 // ************************************************************************* //