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 | Copyright (C) 2011-2015 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  surfaceFeatureConvert
26 
27 Description
28  Convert between edgeMesh formats.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 
35 #include "edgeMesh.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 
42 int main(int argc, char *argv[])
43 {
45  (
46  "Convert between edgeMesh formats"
47  );
49  argList::validArgs.append("inputFile");
50  argList::validArgs.append("outputFile");
52  (
53  "scale",
54  "factor",
55  "geometry scaling factor - default is 1"
56  );
57 
58  argList args(argc, argv);
59  Time runTime(args.rootPath(), args.caseName());
60 
61  const fileName importName = args[1];
62  const fileName exportName = args[2];
63 
64  // disable inplace editing
65  if (importName == exportName)
66  {
68  << "Output file " << exportName << " would overwrite input file."
69  << exit(FatalError);
70  }
71 
72  // check that reading/writing is supported
73  if
74  (
75  !edgeMesh::canReadType(importName.ext(), true)
76  || !edgeMesh::canWriteType(exportName.ext(), true)
77  )
78  {
79  return 1;
80  }
81 
82  edgeMesh mesh(importName);
83 
84  Info<< "\nRead edgeMesh " << importName << nl;
85  mesh.writeStats(Info);
86  Info<< nl
87  << "\nwriting " << exportName;
88 
89  scalar scaleFactor = 0;
90  if (args.optionReadIfPresent("scale", scaleFactor) && scaleFactor > 0)
91  {
92  Info<< " with scaling " << scaleFactor << endl;
93  mesh.scalePoints(scaleFactor);
94  }
95  else
96  {
97  Info<< " without scaling" << endl;
98  }
99 
100  mesh.write(exportName);
101  mesh.writeStats(Info);
102  Info<< endl;
103 
104  Info<< "\nEnd\n" << endl;
105 
106  return 0;
107 }
108 
109 
110 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: edgeMesh.C:58
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
dynamicFvMesh & mesh
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
static const char nl
Definition: Ostream.H:262
Points connected by edges.
Definition: edgeMesh.H:69
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:283
messageStream Info
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
Foam::argList args(argc, argv)
virtual bool write() const
Write mesh using IO settings from time.
Definition: fvMesh.C:870
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format type?
Definition: edgeMesh.C:74
Namespace for OpenFOAM.