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-------------------------------------------------------------------------------
11License
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
27Application
28 foamToSurface
29
30Group
31 grpMeshConversionUtilities
32
33Description
34 Extract boundaries from an OpenFOAM mesh and write in a surface format
35
36Usage
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
56using namespace Foam;
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60int main(int argc, char *argv[])
61{
62 argList::addNote
63 (
64 "Extract boundaries from an OpenFOAM mesh and write in a surface format"
65 );
66 argList::noParallel();
67 argList::addArgument("output", "The output surface file");
68
69 timeSelector::addOptions();
70
71 argList::addOption
72 (
73 "scale",
74 "factor",
75 "Geometry scaling factor - default is 1"
76 );
77 argList::addBoolOption
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"
99 instantList timeDirs = timeSelector::select0(runTime, args);
100 #include "createPolyMesh.H"
101
102 forAll(timeDirs, timeI)
103 {
104 runTime.setTime(timeDirs[timeI], timeI);
105 #include "getTimeIndex.H"
106
107 polyMesh::readUpdateState state = mesh.readUpdate();
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
121 meshedSurface surf(mesh.boundaryMesh());
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// ************************************************************************* //
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
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
A class for handling file names.
Definition: fileName.H:76
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:230
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333