ensightToFoam.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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  ensightToFoam
28 
29 Group
30  grpMeshConversionUtilities
31 
32 Description
33  Convert an Ensight Gold mesh into OpenFOAM format.
34 
35 Usage
36  \b ensightToFoam [OPTION] <ensightGeometryFile>
37 
38  Options:
39  - \par -mergeTol <factor>
40  Specify an alternative merging tolerance as a fraction of
41  the bounding box of the points.
42 
43  - \par -scale <factor>
44  Specify an optional geometry scaling factor.
45 
46  - \par -keepHandedness
47  Do not automatically flip negative volume cells
48 
49 See also
50  Foam::meshReader and Foam::fileFormats::STARCDMeshReader
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #include "argList.H"
55 #include "Time.H"
56 #include "ensightMeshReader.H"
57 
58 using namespace Foam;
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 int main(int argc, char *argv[])
63 {
65  (
66  "Convert Ensight mesh to OpenFOAM"
67  );
68 
70  argList::addArgument(".geo file", "The file containing the geometry");
72  (
73  "mergeTol",
74  "factor",
75  "Merge tolerance as a fraction of bounding box - 0 to disable merging"
76  );
78  (
79  "scale",
80  "factor",
81  "Geometry scaling factor - default is 1"
82  );
84  (
85  "keepHandedness",
86  "Do not automatically flip inverted cells"
87  " (default is to do a geometric test)"
88  );
89 
90  argList args(argc, argv);
92 
93  // Increase the precision of the points data
95 
96  const fileName geomFile(args.get<fileName>(1));
97 
98  {
100  (
101  geomFile,
102  runTime,
103  args.getOrDefault<scalar>("mergeTol", 1e-10),
104  args.getOrDefault<scalar>("scale", 1.0),
105  args.found("keepHandedness")
106  );
107 
108  autoPtr<polyMesh> mesh = reader.mesh(runTime);
110  mesh().write();
111  }
112 
113  Info<< "\nEnd\n" << endl;
114 
115  return 0;
116 }
117 
118 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
A class for handling file names.
Definition: fileName.H:71
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1072
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:416
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:365
static void noParallel()
Remove the parallel options.
Definition: argList.C:551
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:300
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dynamicFvMesh & mesh
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
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:376
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:62
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:89
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:56
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
Definition: polyMeshIO.C:29
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:342
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.