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 -------------------------------------------------------------------------------
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 auto importName = args.get<fileName>(1);
110  const auto exportName = args.get<fileName>(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
Definition: word.C:106
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:69
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::edgeMesh::canReadType
static bool canReadType(const word &fileType, bool verbose=false)
Definition: edgeMesh.C:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Definition: fvMesh.C:1034
Foam::argList::getOrDefault
T getOrDefault(const word &optName, const T &deflt) const
Definition: argListI.H:300
Foam::argList::caseName
const fileName & caseName() const noexcept
Definition: argListI.H:62
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:119
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::word::ext
word ext() const
Definition: word.C:119
Foam::argList::get
T get(const label index) const
Definition: argListI.H:271
Foam::argList::readIfPresent
bool readIfPresent(const word &optName, T &val) const
Definition: argListI.H:316
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Definition: argList.C:294
edgeMesh.H
Foam::Info
messageStream Info
argList.H
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Definition: atmBoundaryLayer.C:26
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Foam::edgeMesh::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Definition: edgeMesh.C:66
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::argList::noParallel
static void noParallel()
Definition: argList.C:503
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Definition: argList.C:328
args
Foam::argList args(argc, argv)
Foam::edgeMesh
Mesh data needed to do the Finite Area discretisation.
Definition: edgeFaMesh.H:47
Foam::argList::rootPath
const fileName & rootPath() const noexcept
Definition: argListI.H:56