foamToStarMesh.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-2018 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  foamToStarMesh
26 
27 Description
28  Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
29 
30 Usage
31  \b foamToStarMesh [OPTION]
32 
33  Options:
34  - \par -noBnd
35  Suppress writing the \c .bnd file
36 
37  - \par -scale <factor>
38  Specify an alternative geometry scaling factor.
39  The default is \b 1000 (scale \em [m] to \em [mm]).
40 
41 Note
42  The cellTable information available in the files
43  \c constant/cellTable and \c constant/polyMesh/cellTableId
44  will be used if available. Otherwise the cellZones are used when
45  creating the cellTable information.
46 
47 See also
48  Foam::cellTable, Foam::meshWriter and Foam::meshWriters::STARCD
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #include "argList.H"
53 #include "timeSelector.H"
54 #include "Time.H"
55 #include "polyMesh.H"
56 #include "STARCDMeshWriter.H"
57 #include "IOdictionary.H"
58 
59 using namespace Foam;
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 int main(int argc, char *argv[])
64 {
66  (
67  "read OpenFOAM mesh and write a pro-STAR (v4) bnd/cel/vrt format"
68  );
71 
73  (
74  "scale",
75  "factor",
76  "geometry scaling factor - default is 1000 ([m] to [mm])"
77  );
79  (
80  "noBnd",
81  "suppress writing a boundary (.bnd) file"
82  );
83 
84  #include "setRootCase.H"
85  #include "createTime.H"
86 
88 
90  if (args.optionFound("case"))
91  {
92  exportName += '-' + args.globalCaseName();
93  }
94 
95  // default: rescale from [m] to [mm]
96  scalar scaleFactor = 1000;
97  if (args.optionReadIfPresent("scale", scaleFactor))
98  {
99  if (scaleFactor <= 0)
100  {
101  scaleFactor = 1;
102  }
103  }
104 
105  #include "createPolyMesh.H"
106 
107  forAll(timeDirs, timeI)
108  {
109  runTime.setTime(timeDirs[timeI], timeI);
110 
111  #include "getTimeIndex.H"
112 
114 
115  if (!timeI || state != polyMesh::UNCHANGED)
116  {
117  meshWriters::STARCD writer(mesh, scaleFactor);
118 
119  if (args.optionFound("noBnd"))
120  {
121  writer.noBoundary();
122  }
123 
124  fileName meshName(exportName);
125  if (state != polyMesh::UNCHANGED)
126  {
127  meshName += '_' + runTime.timeName();
128  }
129 
131  }
132 
133  Info<< nl << endl;
134  }
135 
136  Info<< "End\n" << endl;
137 
138  return 0;
139 }
140 
141 // ************************************************************************* //
static string defaultMeshName
Specify a default mesh name.
Definition: meshWriter.H:126
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
const fileName & globalCaseName() const
Return case name.
Definition: argListI.H:48
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > *> &, Ostream &) const =0
General entry point for writing.
static void noParallel()
Remove the parallel options.
Definition: argList.C:174
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Writes polyMesh in pro-STAR (v4) bnd/cel/vrt format.
dynamicFvMesh & mesh
static char meshName[]
Definition: globalFoam.H:7
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:489
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:127
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
Definition: Time.C:873
static const char nl
Definition: Ostream.H:265
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:252
messageStream Info
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:117
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:158
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::argList args(argc, argv)
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.