star4ToFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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  star4ToFoam
26 
27 Description
28  Converts a Star-CD (v4) pro-STAR mesh into OpenFOAM format.
29 
30 Usage
31  \b star4ToFoam [OPTION] ccmMesh
32 
33  Options:
34  - \par -ascii
35  Write in ASCII format instead of binary
36 
37  - \par -scale <factor>
38  Specify an alternative geometry scaling factor.
39  The default is \b 0.001 (scale \em [mm] to \em [m]).
40 
41  - \par -solids
42  Treat any solid cells present just like fluid cells.
43  The default is to discard them.
44 
45  Note:
46  Baffles are written as interfaces for later use
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #include "argList.H"
51 #include "Time.H"
52 #include "STARCDMeshReader.H"
53 #include "OFstream.H"
54 
55 using namespace Foam;
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 int main(int argc, char *argv[])
60 {
62  (
63  "convert pro-STAR (v4) mesh to OpenFOAM"
64  );
65 
67  argList::validArgs.append("pro-STAR prefix");
69  (
70  "ascii",
71  "write in ASCII instead of binary format"
72  );
74  (
75  "scale",
76  "factor",
77  "geometry scaling factor - default is 0.001 ([mm] to [m])"
78  );
80  (
81  "solids",
82  "retain solid cells and treat them like fluid cells"
83  );
84 
85  argList args(argc, argv);
86  Time runTime(args.rootPath(), args.caseName());
87 
88  // default rescale from [mm] to [m]
89  scalar scaleFactor = args.optionLookupOrDefault("scale", 0.001);
90  if (scaleFactor <= 0)
91  {
92  scaleFactor = 1;
93  }
94 
96 
97  // default to binary output, unless otherwise specified
99  if (args.optionFound("ascii"))
100  {
102  }
103 
104  // increase the precision of the points data
106 
107  // remove extensions and/or trailing '.'
108  const fileName prefix = fileName(args[1]).lessExt();
109 
110  meshReaders::STARCD reader(prefix, runTime, scaleFactor);
111 
112  autoPtr<polyMesh> mesh = reader.mesh(runTime);
113  reader.writeMesh(mesh, format);
114 
115 
116  Info<< "\nEnd\n" << endl;
117 
118  return 0;
119 }
120 
121 // ************************************************************************* //
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:48
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static void noParallel()
Remove the parallel options.
Definition: argList.C:175
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:243
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A class for handling file names.
Definition: fileName.H:82
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:284
Read pro-STAR vrt/cel/bnd files. The protected data in meshReader are filled.
static bool keepSolids
Keep solids (default false)
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
word format(conversionProperties.lookup("format"))
Foam::argList args(argc, argv)