surfaceConvert.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 
54 using namespace Foam;
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 int main(int argc, char *argv[])
59 {
60  #include "removeCaseOptions.H"
61 
63  (
64  "convert between surface formats"
65  );
66 
67  argList::validArgs.append("surface file");
68  argList::validArgs.append("output surface file");
69 
71  (
72  "clean",
73  "perform some surface checking/cleanup on the input surface"
74  );
76  (
77  "group",
78  "reorder faces into groups; one per region"
79  );
81  (
82  "scale",
83  "factor",
84  "geometry scaling factor - default is 1"
85  );
87  (
88  "writePrecision",
89  "label",
90  "write to output with the specified precision"
91  );
92 
93  argList args(argc, argv);
94 
95  if (args.optionFound("writePrecision"))
96  {
97  label writePrecision = args.optionRead<label>("writePrecision");
98 
99  IOstream::defaultPrecision(writePrecision);
100  Sout.precision(writePrecision);
101 
102  Info<< "Output write precision set to " << writePrecision << endl;
103  }
104 
105  const fileName importName = args[1];
106  const fileName exportName = args[2];
107 
108  if (importName == exportName)
109  {
111  << "Output file " << exportName << " would overwrite input file."
112  << exit(FatalError);
113  }
114 
115  Info<< "Reading : " << importName << endl;
116  triSurface surf(importName);
117 
118  Info<< "Read surface:" << endl;
119  surf.writeStats(Info);
120  Info<< endl;
121 
122  if (args.optionFound("clean"))
123  {
124  Info<< "Cleaning up surface" << endl;
125  surf.cleanup(true);
126 
127  Info<< "After cleaning up surface:" << endl;
128  surf.writeStats(Info);
129  Info<< endl;
130  }
131 
132  const bool sortByRegion = args.optionFound("group");
133  if (sortByRegion)
134  {
135  Info<< "Reordering faces into groups; one per region." << endl;
136  }
137  else
138  {
139  Info<< "Maintaining face ordering" << endl;
140  }
141 
142  Info<< "writing " << exportName;
143 
144  scalar scaleFactor = 0;
145  if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
146  {
147  Info<< " with scaling " << scaleFactor;
148  surf.scalePoints(scaleFactor);
149  }
150  Info<< endl;
151 
152  surf.write(exportName, sortByRegion);
153 
154  Info<< "\nEnd\n" << endl;
155 
156  return 0;
157 }
158 
159 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:246
virtual Ostream & write(const char)=0
Write character.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
T optionRead(const word &opt) const
Read a value from the named option.
Definition: argListI.H:193
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:204
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
A class for handling file names.
Definition: fileName.H:82
Triangulated surface description with patch information.
Definition: triSurface.H:69
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
error FatalError
prefixOSstream Sout(cout, "Sout")
Definition: IOstreams.H:51
Foam::argList args(argc, argv)