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-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Application
28  surfaceFeatureConvert
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
34  Convert between edgeMesh formats.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "Time.H"
40 
41 #include "edgeMesh.H"
42 
43 using namespace Foam;
44 
45 static 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
58 static 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 
78 int main(int argc, char *argv[])
79 {
81  (
82  "Convert between edgeMesh formats"
83  );
85  argList::addArgument("input", "The input edge file");
86  argList::addArgument("output", "The output edge file");
88  (
89  "read-format",
90  "type",
91  "The input format (default: use file extension)"
92  );
94  (
95  "write-format",
96  "type",
97  "The output format (default: use file extension)"
98  );
100  (
101  "scale",
102  "factor",
103  "Input geometry scaling factor"
104  );
105 
106  argList args(argc, argv);
108 
109  const fileName importName(args[1]);
110  const fileName exportName(args[2]);
111 
112  // Disable inplace editing
113  if (importName == exportName)
114  {
115  FatalError
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  {
133  FatalError
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 // ************************************************************************* //
Foam::word::lessExt
word lessExt() const
Return word without extension (part before last .)
Definition: word.C:113
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::edgeMesh::canReadType
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:61
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:895
Foam::argList::getOrDefault
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:286
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::word::ext
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
Foam::argList::readIfPresent
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:302
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:63
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
edgeMesh.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
argList.H
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::edgeMesh::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:73
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
Foam::argList::addOption
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:336
args
Foam::argList args(argc, argv)
Foam::edgeMesh
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:52