Loading...
Searching...
No Matches
surfaceClean.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-2013 OpenFOAM Foundation
9 Copyright (C) 2020-2023 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 surfaceClean
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Utility to clean surfaces.
35
36 Current functionality
37 - removes baffles
38 - collapses small edges, removing triangles.
39 - converts sliver triangles into split edges by projecting point onto
40 base of triangle.
41
42\*---------------------------------------------------------------------------*/
43
44#include "triSurface.H"
45#include "argList.H"
46#include "OFstream.H"
47
48#include "collapseBase.H"
49#include "collapseEdge.H"
50
51using namespace Foam;
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55
56int main(int argc, char *argv[])
57{
59 (
60 "Clean surface by removing baffles, sliver faces,"
61 " collapsing small edges, etc."
62 );
63
65 argList::addArgument("input", "The input surface file");
66 argList::addArgument("length", "The min length");
67 argList::addArgument("quality", "The min quality");
68 argList::addArgument("output", "The output surface file");
69
71 (
72 "no-clean",
73 "Suppress surface checking/cleanup on the input surface"
74 );
75 argList::addOptionCompat("no-clean", {"noClean", -2006});
77
79 (
80 "scale",
81 "factor",
82 "Input geometry scaling factor"
83 );
84 argList args(argc, argv);
85
86 const auto inFileName = args.get<fileName>(1);
87 const auto minLen = args.get<scalar>(2);
88 const auto minQuality = args.get<scalar>(3);
89 const auto outFileName = args.get<fileName>(4);
90
91 const int optVerbose = args.verbose();
92
93 Info<< "Reading surface " << inFileName << nl
94 << "Collapsing all triangles with" << nl
95 << " edges or heights < " << minLen << nl
96 << " quality < " << minQuality << nl
97 << "Writing result to " << outFileName << nl << endl;
98
99
100 Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
101
102 triSurface surf
103 (
104 inFileName,
105 args.getOrDefault<scalar>("scale", -1)
106 );
107 surf.writeStats(Info);
108
109 if (!args.found("no-clean"))
110 {
111 Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
112 surf.cleanup(optVerbose);
113 }
114
115 Info<< "Collapsing triangles to edges ..." << nl << endl;
116
117 while (true)
118 {
119 const label nEdgeCollapse = collapseEdge(surf, minLen);
120
121 if (nEdgeCollapse == 0)
122 {
123 break;
124 }
125 }
126 while (true)
127 {
128 const label nSplitEdge = collapseBase(surf, minLen, minQuality);
129
130 if (nSplitEdge == 0)
131 {
132 break;
133 }
134 }
135
136 Info<< nl
137 << "Resulting surface:" << endl;
138 surf.writeStats(Info);
139
140 Info<< nl
141 << "Writing refined surface to " << outFileName << " ..." << endl;
142 surf.write(outFileName);
143
144 Info<< "\nEnd\n" << endl;
145
146 return 0;
147}
148
149
150// ************************************************************************* //
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
Definition argList.C:535
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
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition argList.C:433
A class for handling file names.
Definition fileName.H:75
Triangulated surface description with patch information.
Definition triSurface.H:74
Routines collapse sliver triangles by splitting the base edge.
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
Routines to collapse small edges.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
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:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)