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) 2011-2016 OpenFOAM Foundation
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  \b surfaceConvert inputFile outputFile [OPTION]
32 
33  Options:
34  - \par -clean
35  Perform some surface checking/cleanup on the input surface
36 
37  - \par -scale <scale>
38  Specify a scaling factor for writing the files
39 
40  - \par -group
41  Orders faces by region
42 
43 Note
44  The filename extensions are used to determine the file format type.
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #include "argList.H"
49 #include "fileName.H"
50 #include "triSurface.H"
51 #include "OFstream.H"
52 #include "OSspecific.H"
53 #include "Time.H"
54 
55 using namespace Foam;
56 
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 int main(int argc, char *argv[])
61 {
63  (
64  "convert between surface formats"
65  );
66 
68  argList::validArgs.append("inputFile");
69  argList::validArgs.append("outputFile");
70 
72  (
73  "clean",
74  "perform some surface checking/cleanup on the input surface"
75  );
77  (
78  "group",
79  "reorder faces into groups; one per region"
80  );
82  (
83  "scale",
84  "factor",
85  "geometry scaling factor - default is 1"
86  );
88  (
89  "writePrecision",
90  "label",
91  "write to output with the specified precision"
92  );
93 
94  argList args(argc, argv);
95 
96  if (args.optionFound("writePrecision"))
97  {
98  label writePrecision = args.optionRead<label>("writePrecision");
99 
100  IOstream::defaultPrecision(writePrecision);
101  Sout.precision(writePrecision);
102 
103  Info<< "Output write precision set to " << writePrecision << endl;
104  }
105 
106  const fileName importName = args[1];
107  const fileName exportName = args[2];
108 
109  if (importName == exportName)
110  {
112  << "Output file " << exportName << " would overwrite input file."
113  << exit(FatalError);
114  }
115 
116  Info<< "Reading : " << importName << endl;
117  triSurface surf(importName);
118 
119  Info<< "Read surface:" << endl;
120  surf.writeStats(Info);
121  Info<< endl;
122 
123  if (args.optionFound("clean"))
124  {
125  Info<< "Cleaning up surface" << endl;
126  surf.cleanup(true);
127 
128  Info<< "After cleaning up surface:" << endl;
129  surf.writeStats(Info);
130  Info<< endl;
131  }
132 
133  const bool sortByRegion = args.optionFound("group");
134  if (sortByRegion)
135  {
136  Info<< "Reordering faces into groups; one per region." << endl;
137  }
138  else
139  {
140  Info<< "Maintaining face ordering" << endl;
141  }
142 
143  Info<< "writing " << exportName;
144 
145  scalar scaleFactor = 0;
146  if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
147  {
148  Info<< " with scaling " << scaleFactor;
149  surf.scalePoints(scaleFactor);
150  }
151  Info<< endl;
152 
153  surf.write(exportName, sortByRegion);
154 
155  Info<< "\nEnd\n" << endl;
156 
157  return 0;
158 }
159 
160 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
T optionRead(const word &opt) const
Read a value from the named option.
Definition: argListI.H:187
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
OSstream Sout(cout,"Sout")
Definition: IOstreams.H:51
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:285
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
Triangulated surface description with patch information.
Definition: triSurface.H:65
Foam::argList args(argc, argv)
Namespace for OpenFOAM.