foamToStarMesh.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-2016 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 
58 using namespace Foam;
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 int main(int argc, char *argv[])
63 {
65  (
66  "read OpenFOAM mesh and write a pro-STAR (v4) bnd/cel/vrt format"
67  );
70 
72  (
73  "scale",
74  "factor",
75  "geometry scaling factor - default is 1000 ([m] to [mm])"
76  );
78  (
79  "noBnd",
80  "suppress writing a boundary (.bnd) file"
81  );
82 
83  #include "setRootCase.H"
84  #include "createTime.H"
85 
86  instantList timeDirs = timeSelector::select0(runTime, args);
87 
89  if (args.optionFound("case"))
90  {
91  exportName += '-' + args.globalCaseName();
92  }
93 
94  // default: rescale from [m] to [mm]
95  scalar scaleFactor = 1000;
96  if (args.optionReadIfPresent("scale", scaleFactor))
97  {
98  if (scaleFactor <= 0)
99  {
100  scaleFactor = 1;
101  }
102  }
103 
104  #include "createPolyMesh.H"
105 
106  forAll(timeDirs, timeI)
107  {
108  runTime.setTime(timeDirs[timeI], timeI);
109 
110  #include "getTimeIndex.H"
111 
113 
114  if (!timeI || state != polyMesh::UNCHANGED)
115  {
116  meshWriters::STARCD writer(mesh, scaleFactor);
117 
118  if (args.optionFound("noBnd"))
119  {
120  writer.noBoundary();
121  }
122 
123  fileName meshName(exportName);
124  if (state != polyMesh::UNCHANGED)
125  {
126  meshName += '_' + runTime.timeName();
127  }
128 
130  }
131 
132  Info<< nl << endl;
133  }
134 
135  Info<< "End\n" << endl;
136 
137  return 0;
138 }
139 
140 // ************************************************************************* //
static string defaultMeshName
Specify a default mesh name.
Definition: meshWriter.H:135
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A class for handling file names.
Definition: fileName.H:69
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
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:494
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
const fileName & globalCaseName() const
Return case name.
Definition: argListI.H:48
static const char nl
Definition: Ostream.H:262
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
messageStream Info
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
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.