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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  foamToSurface
29 
30 Group
31  grpMeshConversionUtilities
32 
33 Description
34  Extract boundaries from an OpenFOAM mesh and write in a surface format
35 
36 Usage
37  \b foamToSurface [OPTION]
38 
39  Options:
40  - \par -scale <factor>
41  Specify an alternative geometry scaling factor.
42  E.g. use \b 1000 to scale \em [m] to \em [mm].
43 
44  - \par -tri
45  Triangulate surface.
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #include "argList.H"
50 #include "timeSelector.H"
51 #include "Time.H"
52 #include "polyMesh.H"
53 #include "IOdictionary.H"
54 #include "MeshedSurfaces.H"
55 
56 using namespace Foam;
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 int main(int argc, char *argv[])
61 {
63  (
64  "Extract boundaries from an OpenFOAM mesh and write in a surface format"
65  );
67  argList::addArgument("output", "The output surface file");
68 
70 
72  (
73  "scale",
74  "factor",
75  "Geometry scaling factor - default is 1"
76  );
78  (
79  "tri",
80  "Triangulate surface"
81  );
82 
83  #include "setRootCase.H"
84 
85  auto exportName = args.get<fileName>(1);
86 
87  const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
88  const bool doTriangulate = args.found("tri");
89 
90  fileName exportBase = exportName.lessExt();
91  word exportExt = exportName.ext();
92 
93  if (!meshedSurface::canWriteType(exportExt, true))
94  {
95  return 1;
96  }
97 
98  #include "createTime.H"
100  #include "createPolyMesh.H"
101 
102  forAll(timeDirs, timeI)
103  {
104  runTime.setTime(timeDirs[timeI], timeI);
105  #include "getTimeIndex.H"
106 
108 
109  if (timeI == 0 || state != polyMesh::UNCHANGED)
110  {
111  if (state == polyMesh::UNCHANGED)
112  {
113  exportName = exportBase + "." + exportExt;
114  }
115  else
116  {
117  exportName =
118  exportBase + '_' + runTime.timeName() + "." + exportExt;
119  }
120 
122  surf.scalePoints(scaleFactor);
123 
124  Info<< "writing " << exportName;
125  if (doTriangulate)
126  {
127  Info<< " triangulated";
128  surf.triangulate();
129  }
130 
131  if (scaleFactor <= 0)
132  {
133  Info<< " without scaling" << endl;
134  }
135  else
136  {
137  Info<< " with scaling " << scaleFactor << endl;
138  }
139  surf.write(exportName);
140  }
141 
142  Info<< nl << endl;
143  }
144 
145  Info<< "End\n" << endl;
146 
147  return 0;
148 }
149 
150 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::argList::getOrDefault
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::MeshedSurface::scalePoints
virtual void scalePoints(const scalar scaleFactor)
Scale points. A non-positive factor is ignored.
Definition: MeshedSurface.C:623
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:230
Foam::word::ext
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
Foam::MeshedSurface< face >::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format? Also checks proxy types.
Definition: MeshedSurface.C:77
polyMesh.H
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:648
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:301
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
argList.H
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:324
IOdictionary.H
Time.H
setRootCase.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Definition: timeSelector.C:102
Foam::List< instant >
Foam::Time::setTime
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:1003
MeshedSurfaces.H
timeSelector.H
createTime.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Definition: timeSelector.C:235
Foam::MeshedSurface< face >
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:335
args
Foam::argList args(argc, argv)
createPolyMesh.H
Required Variables.
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178