surfaceFeatureConvert.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2015-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Application
28 surfaceFeatureConvert
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Convert between edgeMesh formats.
35
36\*---------------------------------------------------------------------------*/
37
38#include "argList.H"
39#include "Time.H"
40
41#include "edgeMesh.H"
42
43using namespace Foam;
44
45static word getExtension(const fileName& name)
46{
47 word ext(name.ext());
48 if (ext == "gz")
49 {
50 ext = name.lessExt().ext();
51 }
52
53 return ext;
54}
55
56
57// Non-short-circuiting check to get all warnings
58static bool hasReadWriteTypes(const word& readType, const word& writeType)
59{
60 volatile bool good = true;
61
62 if (!edgeMesh::canReadType(readType, true))
63 {
64 good = false;
65 }
66
67 if (!edgeMesh::canWriteType(writeType, true))
68 {
69 good = false;
70 }
71
72 return good;
73}
74
75
76// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77
78int main(int argc, char *argv[])
79{
80 argList::addNote
81 (
82 "Convert between edgeMesh formats"
83 );
84 argList::noParallel();
85 argList::addArgument("input", "The input edge file");
86 argList::addArgument("output", "The output edge file");
87 argList::addOption
88 (
89 "read-format",
90 "type",
91 "The input format (default: use file extension)"
92 );
93 argList::addOption
94 (
95 "write-format",
96 "type",
97 "The output format (default: use file extension)"
98 );
99 argList::addOption
100 (
101 "scale",
102 "factor",
103 "Input geometry scaling factor"
104 );
105
106 argList args(argc, argv);
108
109 const auto importName = args.get<fileName>(1);
110 const auto exportName = args.get<fileName>(2);
111
112 // Disable inplace editing
113 if (importName == exportName)
114 {
116 << "Output file would overwrite input file."
117 << exit(FatalError);
118 }
119
120 const word readFileType
121 (
122 args.getOrDefault<word>("read-format", getExtension(importName))
123 );
124
125 const word writeFileType
126 (
127 args.getOrDefault<word>("write-format", getExtension(exportName))
128 );
129
130 // Check that reading/writing is supported
131 if (!hasReadWriteTypes(readFileType, writeFileType))
132 {
134 << "Unsupported file format(s)" << nl
135 << exit(FatalError);
136 }
137
138 edgeMesh mesh(importName, readFileType);
139
140 Info<< "\nRead edgeMesh " << importName << nl;
141 mesh.writeStats(Info);
142 Info<< nl
143 << "\nwriting " << exportName;
144
145 scalar scaleFactor(0);
146 if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
147 {
148 Info<< " with scaling " << scaleFactor << endl;
149 mesh.scalePoints(scaleFactor);
150 }
151 else
152 {
153 Info<< " without scaling" << endl;
154 }
155
156 mesh.write(exportName, writeFileType);
157 mesh.writeStats(Info);
158
159 Info<< "\nEnd\n" << endl;
160
161 return 0;
162}
163
164
165// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:63
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:323
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:56
A class for handling file names.
Definition: fileName.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
word lessExt() const
Return word without extension (part before last .)
Definition: word.C:113
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)