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-2015 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  - foamToSurface [OPTION] \n
32  Reads an OpenFOAM mesh and writes the boundaries in a surface format.
33 
34  \param -scale <factor>\n
35  Specify an alternative geometry scaling factor.
36  Eg, use \b 1000 to scale \em [m] to \em [mm].
37 
38  \param -tri \n
39  Triangulate surface.
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #include "argList.H"
44 #include "timeSelector.H"
45 #include "Time.H"
46 #include "polyMesh.H"
47 
48 #include "MeshedSurfaces.H"
49 
50 using namespace Foam;
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 int main(int argc, char *argv[])
55 {
57  argList::validArgs.append("outputFile.ext");
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"
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 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
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::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
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
polyMesh.H
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:498
Foam::MeshedSurface< face >::canWriteType
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
Definition: MeshedSurface.C:82
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
MeshedSurfaces.H
timeSelector.H
createTime.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
Foam::MeshedSurface< face >
args
Foam::argList args(argc, argv)
Foam::argList::optionReadIfPresent
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
createPolyMesh.H