Loading...
Searching...
No Matches
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-2022 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{
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 const fileName exportBase = exportName.lessExt();
91 const 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
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// ************************************************************************* //
static bool canWriteType(const word &fileType, bool verbose=false)
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
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:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
A class for handling file names.
Definition fileName.H:75
fileName lessExt() const
Return file name without extension (part before last .).
Definition fileNameI.H:238
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition polyMesh.H:92
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
A class for handling words, derived from Foam::string.
Definition word.H:66
word ext() const
Return file name extension (part after last .).
Definition wordI.H:171
dynamicFvMesh & mesh
engineTime & runTime
Required Variables.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Definition instantList.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
MeshedSurface< face > meshedSurface
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299