foamToSurface.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-2017 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  foamToSurface
26 
27 Description
28  Reads an OpenFOAM mesh and writes the boundaries in a surface format.
29 
30 Usage
31  \b foamToSurface [OPTION]
32 
33  Options:
34  - \par -scale <factor>
35  Specify an alternative geometry scaling factor.
36  E.g. use \b 1000 to scale \em [m] to \em [mm].
37 
38  - \par -tri
39  Triangulate surface.
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #include "argList.H"
44 #include "timeSelector.H"
45 #include "Time.H"
46 #include "polyMesh.H"
47 #include "IOdictionary.H"
48 #include "MeshedSurfaces.H"
49 
50 using namespace Foam;
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 int main(int argc, char *argv[])
55 {
57  argList::validArgs.append("output surface file");
59 
61  (
62  "scale",
63  "factor",
64  "geometry scaling factor - default is 1"
65  );
67  (
68  "tri",
69  "triangulate surface"
70  );
71 
72  #include "setRootCase.H"
73 
74  fileName exportName = args[1];
75 
76  scalar scaleFactor = 0;
77  args.optionReadIfPresent<scalar>("scale", scaleFactor);
78  const bool doTriangulate = args.optionFound("tri");
79 
80  fileName exportBase = exportName.lessExt();
81  word exportExt = exportName.ext();
82 
83  if (!meshedSurface::canWriteType(exportExt, true))
84  {
85  return 1;
86  }
87 
88  #include "createTime.H"
89  instantList timeDirs = timeSelector::select0(runTime, args);
90  #include "createPolyMesh.H"
91 
92  forAll(timeDirs, timeI)
93  {
94  runTime.setTime(timeDirs[timeI], timeI);
95  #include "getTimeIndex.H"
96 
98 
99  if (timeI == 0 || state != polyMesh::UNCHANGED)
100  {
101  if (state == polyMesh::UNCHANGED)
102  {
103  exportName = exportBase + "." + exportExt;
104  }
105  else
106  {
107  exportName =
108  exportBase + '_' + runTime.timeName() + "." + exportExt;
109  }
110 
112  surf.scalePoints(scaleFactor);
113 
114  Info<< "writing " << exportName;
115  if (doTriangulate)
116  {
117  Info<< " triangulated";
118  surf.triangulate();
119  }
120 
121  if (scaleFactor <= 0)
122  {
123  Info<< " without scaling" << endl;
124  }
125  else
126  {
127  Info<< " with scaling " << scaleFactor << endl;
128  }
129  surf.write(exportName);
130  }
131 
132  Info<< nl << endl;
133  }
134 
135  Info<< "End\n" << endl;
136 
137  return 0;
138 }
139 
140 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A class for handling file names.
Definition: fileName.H:69
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static void noParallel()
Remove the parallel options.
Definition: argList.C:148
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:284
dynamicFvMesh & mesh
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:494
A class for handling words, derived from string.
Definition: word.H:59
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:95
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
Definition: MeshedSurface.C:82
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:257
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:269
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:85
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.