Loading...
Searching...
No Matches
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-2022 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 return
48 (
49 name.has_ext("gz")
50 ? name.stem().ext()
51 : name.ext()
52 );
53}
54
55
56// Non-short-circuiting check to get all warnings
57static bool hasReadWriteTypes(const word& readType, const word& writeType)
58{
59 volatile bool good = true;
60
61 if (!edgeMesh::canReadType(readType, true))
62 {
63 good = false;
64 }
65
66 if (!edgeMesh::canWriteType(writeType, true))
67 {
68 good = false;
69 }
70
71 return good;
72}
73
74
75// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76
77int main(int argc, char *argv[])
78{
80 (
81 "Convert between edgeMesh formats"
82 );
84 argList::addArgument("input", "The input edge file");
85 argList::addArgument("output", "The output edge file");
87 (
88 "read-format",
89 "type",
90 "The input format (default: use file extension)"
91 );
93 (
94 "write-format",
95 "type",
96 "The output format (default: use file extension)"
97 );
99 (
100 "scale",
101 "factor",
102 "Input geometry scaling factor"
103 );
104
105 argList args(argc, argv);
106 Time runTime(args.rootPath(), args.caseName());
107
108 const auto importName = args.get<fileName>(1);
109 const auto exportName = args.get<fileName>(2);
110
111 // Disable inplace editing
112 if (importName == exportName)
113 {
115 << "Output file would overwrite input file."
116 << exit(FatalError);
117 }
118
119 const word readFileType
120 (
121 args.getOrDefault<word>("read-format", getExtension(importName))
122 );
123
124 const word writeFileType
125 (
126 args.getOrDefault<word>("write-format", getExtension(exportName))
127 );
128
129 // Check that reading/writing is supported
130 if (!hasReadWriteTypes(readFileType, writeFileType))
131 {
133 << "Unsupported file format(s)" << nl
134 << exit(FatalError);
135 }
136
137 edgeMesh mesh(importName, readFileType);
138
139 Info<< "\nRead edgeMesh " << importName << nl;
140 mesh.writeStats(Info);
141 Info<< nl
142 << "\nwriting " << exportName;
143
144 scalar scaleFactor(0);
145 if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
146 {
147 Info<< " with scaling " << scaleFactor << endl;
148 mesh.scalePoints(scaleFactor);
149 }
150 else
151 {
152 Info<< " without scaling" << endl;
153 }
154
155 mesh.write(exportName, writeFileType);
156 mesh.writeStats(Info);
157
158 Info<< "\nEnd\n" << endl;
159
160 return 0;
161}
162
163
164// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Mesh data needed to do the Finite Area discretisation.
Definition edgeFaMesh.H:50
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format type?
Definition edgeMesh.C:66
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format?
Definition edgeMesh.C:54
A class for handling file names.
Definition fileName.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
auto & name
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:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)