star4ToFoam.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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  star4ToFoam
29 
30 Group
31  grpMeshConversionUtilities
32 
33 Description
34  Convert a STARCD/PROSTAR (v4) mesh into OpenFOAM format.
35 
36 Usage
37  \b star4ToFoam [OPTION] prostarMesh
38 
39  Options:
40  - \par -ascii
41  Write in ASCII format instead of binary
42 
43  - \par -scale <factor>
44  Specify an alternative geometry scaling factor.
45  The default is \b 0.001 (scale \em [mm] to \em [m]).
46 
47  - \par -solids
48  Treat any solid cells present just like fluid cells.
49  The default is to discard them.
50 
51 Note
52  Baffles are written as interfaces for later use
53 
54 See also
55  Foam::cellTable, Foam::meshReader and Foam::fileFormats::STARCDMeshReader
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #include "argList.H"
60 #include "Time.H"
61 #include "STARCDMeshReader.H"
62 #include "OFstream.H"
63 
64 using namespace Foam;
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 int main(int argc, char *argv[])
69 {
71  (
72  "Convert STARCD/PROSTAR (v4) mesh to OpenFOAM"
73  );
74 
76  argList::addArgument("prefix", "The prefix for the input PROSTAR files");
78  (
79  "ascii",
80  "Write in ASCII instead of binary format"
81  );
83  (
84  "scale",
85  "factor",
86  "Geometry scaling factor - default is 0.001 ([mm] to [m])"
87  );
89  (
90  "solids",
91  "Retain solid cells and treat like fluid cells"
92  );
93 
94 
95  argList args(argc, argv);
97 
98  // Binary output, unless otherwise specified
100  (
101  args.found("ascii")
104  );
105 
106  // Increase the precision of the points data
108 
109 
110  // Remove extensions and/or trailing '.'
111  const auto prefix = args.get<fileName>(1).lessExt();
112 
113 
115  (
116  prefix,
117  runTime,
118  // Default rescale from [mm] to [m]
119  args.getOrDefault<scalar>("scale", 0.001),
120  args.found("solids")
121  );
122 
123 
124  autoPtr<polyMesh> mesh = reader.mesh(runTime);
125  reader.writeMesh(mesh(), format);
126 
127 
128  Info<< "\nEnd\n" << endl;
129 
130  return 0;
131 }
132 
133 // ************************************************************************* //
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::fileName
A class for handling file names.
Definition: fileName.H:73
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:307
STARCDMeshReader.H
Foam::argList::caseName
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
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:369
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
OFstream.H
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:301
format
word format(conversionProperties.get< word >("format"))
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
argList.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::fileFormats::STARCDMeshReader
Read PROSTAR vrt/cel/bnd files. The protected data in meshReader are filled.
Definition: STARCDMeshReader.H:68
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:324
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
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:335
args
Foam::argList args(argc, argv)
Foam::argList::rootPath
const fileName & rootPath() const noexcept
Return root path.
Definition: argListI.H:63
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178