FreeFOAM The Cross-Platform CFD Toolkit
surfaceConvert.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) 1991-2010 OpenCFD Ltd.
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  surfaceConvert
26 
27 Description
28  Converts from one surface mesh format to another
29 
30 Usage
31 
32  - surfaceConvert [OPTIONS] <Foam surface file> <Foam output surface file>
33 
34  @param <Foam surface file> \n
35  @todo Detailed description of argument.
36 
37  @param <Foam output surface file> \n
38  @todo Detailed description of argument.
39 
40  @param -clean \n
41  Perform some surface checking/cleanup on the input surface
42 
43  @param -scale <scale> \n
44  Specify a scaling factor for writing the files
45 
46  @param -group \n
47  Reorder faces into groups by region.
48 
49  @param -case <dir>\n
50  Case directory.
51 
52  @param -help \n
53  Display help message.
54 
55  @param -doc \n
56  Display Doxygen API documentation page for this application.
57 
58  @param -srcDoc \n
59  Display Doxygen source documentation page for this application.
60 
61 Note
62  The filename extensions are used to determine the file format type.
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #include <OpenFOAM/argList.H>
67 #include <OpenFOAM/fileName.H>
68 #include <triSurface/triSurface.H>
69 #include <OpenFOAM/OFstream.H>
70 #include <OpenFOAM/OSspecific.H>
71 
72 using namespace Foam;
73 
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 // Main program:
77 
78 int main(int argc, char *argv[])
79 {
82  argList::validArgs.append("inputFile");
83  argList::validArgs.append("outputFile");
84  argList::validOptions.insert("clean", "");
85  argList::validOptions.insert("scale", "scale");
86  argList::validOptions.insert("group", "");
87 
88  argList args(argc, argv);
89  const stringList& params = args.additionalArgs();
90 
91  fileName importName(params[0]);
92  fileName exportName(params[1]);
93 
94  if (importName == exportName)
95  {
97  << "Output file " << exportName << " would overwrite input file."
98  << exit(FatalError);
99  }
100 
101  Info<< "Reading : " << importName << endl;
102  triSurface surf(importName);
103 
104  Info<< "Read surface:" << endl;
105  surf.writeStats(Info);
106  Info<< endl;
107 
108  if (args.optionFound("clean"))
109  {
110  Info<< "Cleaning up surface" << endl;
111  surf.cleanup(true);
112 
113  Info<< "After cleaning up surface:" << endl;
114  surf.writeStats(Info);
115  Info<< endl;
116  }
117 
118  bool sortByRegion = args.optionFound("group");
119 
120  if (sortByRegion)
121  {
122  Info<< "Reordering faces into groups; one per region." << endl;
123  }
124  else
125  {
126  Info<< "Maintaining face ordering" << endl;
127  }
128 
129  Info<< "writing " << exportName;
130 
131  scalar scaleFactor = 0;
132  if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
133  {
134  Info<< " with scaling " << scaleFactor;
135  surf.scalePoints(scaleFactor);
136  }
137  Info<< endl;
138 
139  surf.write(exportName, sortByRegion);
140 
141  Info<< "\nEnd\n" << endl;
142 
143  return 0;
144 }
145 
146 // ************************ vim: set sw=4 sts=4 et: ************************ //