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 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  surfaceClean
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
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 
51 using namespace Foam;
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 
56 int 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  "noClean",
73  "Suppress surface checking/cleanup on the input surface"
74  );
76  (
77  "scale",
78  "factor",
79  "Input geometry scaling factor"
80  );
81  argList args(argc, argv);
82 
83  const fileName inFileName = args[1];
84  const scalar minLen = args.get<scalar>(2);
85  const scalar minQuality = args.get<scalar>(3);
86  const fileName outFileName = args[4];
87 
88  Info<< "Reading surface " << inFileName << nl
89  << "Collapsing all triangles with" << nl
90  << " edges or heights < " << minLen << nl
91  << " quality < " << minQuality << nl
92  << "Writing result to " << outFileName << nl << endl;
93 
94 
95  Info<< "Reading surface from " << inFileName << " ..." << nl << endl;
96 
97  triSurface surf
98  (
99  inFileName,
100  args.getOrDefault<scalar>("scale", -1)
101  );
102  surf.writeStats(Info);
103 
104  if (!args.found("noClean"))
105  {
106  Info<< "Removing duplicate and illegal triangles ..." << nl << endl;
107  surf.cleanup(true);
108  }
109 
110  Info<< "Collapsing triangles to edges ..." << nl << endl;
111 
112  while (true)
113  {
114  const label nEdgeCollapse = collapseEdge(surf, minLen);
115 
116  if (nEdgeCollapse == 0)
117  {
118  break;
119  }
120  }
121  while (true)
122  {
123  const label nSplitEdge = collapseBase(surf, minLen, minQuality);
124 
125  if (nSplitEdge == 0)
126  {
127  break;
128  }
129  }
130 
131  Info<< nl
132  << "Resulting surface:" << endl;
133  surf.writeStats(Info);
134 
135  Info<< nl
136  << "Writing refined surface to " << outFileName << " ..." << endl;
137  surf.write(outFileName);
138 
139  Info<< "\nEnd\n" << endl;
140 
141  return 0;
142 }
143 
144 
145 // ************************************************************************* //
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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:286
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
triSurface.H
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:257
OFstream.H
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
collapseEdge.H
Routines to collapse small edges.
argList.H
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::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:325
collapseBase.H
Routines collapse sliver triangles by splitting the base edge.
collapseBase
label collapseBase(triSurface &surf, const scalar minLen, const scalar minQuality)
Keep collapsing all triangles whose height is < minLen or quality < minQ.
Foam::nl
constexpr char nl
Definition: Ostream.H:385
collapseEdge
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
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:336
args
Foam::argList args(argc, argv)
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:157