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 | Copyright (C) 2011-2013 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  - star4ToFoam [OPTION] ccmMesh\n
32  convert pro-STAR mesh to OpenFOAM
33 
34  \param -ascii \n
35  Write in ASCII format instead of binary
36 
37  \param -scale <factor>\n
38  Specify an alternative geometry scaling factor.
39  The default is \b 0.001 (scale \em [mm] to \em [m]).
40 
41  \param -solids \n
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 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
format
word format(conversionProperties.lookup("format"))
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
STARCDMeshReader.H
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:313
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
OFstream.H
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam::argList::optionLookupOrDefault
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:237
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::IOstream::BINARY
@ BINARY
Definition: IOstream.H:89
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
Foam::meshReaders::STARCD::keepSolids
static bool keepSolids
Keep solids (default false)
Definition: STARCDMeshReader.H:152
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::meshReaders::STARCD
Read pro-STAR vrt/cel/bnd files. The protected data in meshReader are filled.
Definition: STARCDMeshReader.H:61
args
Foam::argList args(argc, argv)
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86