surfaceRefineRedGreen.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-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  surfaceRefineRedGreen
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
34  Refine by splitting all three edges of triangle ('red' refinement).
35 
36  Neighbouring triangles (which are not marked for refinement get split
37  in half ('green' refinement).
38 
39  Reference:
40  \verbatim
41  R. Verfuerth, "A review of a posteriori
42  error estimation and adaptive mesh refinement techniques",
43  Wiley-Teubner, 1996)
44  \endverbatim
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #include "triSurface.H"
49 #include "triSurfaceTools.H"
50 #include "argList.H"
51 #include "OFstream.H"
52 
53 using namespace Foam;
54 
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 int main(int argc, char *argv[])
59 {
61  (
62  "Refine by splitting all three edges of triangle"
63  );
65  argList::addArgument("input", "The input surface file");
66  argList::addArgument("output", "The output surface file");
68  (
69  "steps",
70  "N",
71  "Number of refinement steps (default: 1)"
72  );
73  argList args(argc, argv);
74 
75  const auto surfFileName = args.get<fileName>(1);
76  const auto outFileName = args.get<fileName>(2);
77 
78  Info<< "Reading surface from " << surfFileName << " ..." << endl;
79 
80  triSurface surf(surfFileName);
81 
82  Info<< "Original surface:" << nl
83  << " triangles :" << surf.size() << nl
84  << " vertices(used):" << surf.nPoints() << endl;
85 
86 
87  const label nsteps =
88  args.getCheckOrDefault<label>("steps", 1, labelMinMax::ge(1));
89 
90 
91  Info<< "Refining " << nsteps << " times" << flush;
92 
93  for (label step = 0; step < nsteps; ++step)
94  {
95  Info<< '.' << flush;
96 
98  (
99  surf,
100  identity(surf.size()) // Refine all
101  );
102  }
103  Info<< endl;
104 
105  Info<< "Refined surface:" << nl
106  << " triangles :" << surf.size() << nl
107  << " vertices(used):" << surf.nPoints() << endl;
108 
109  Info<< nl
110  << "Writing refined surface to " << outFileName << " ..." << endl;
111 
112  surf.write(outFileName);
113 
114  Info<< "End\n" << endl;
115 
116  return 0;
117 }
118 
119 
120 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
A class for handling file names.
Definition: fileName.H:72
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
static triSurface redGreenRefine(const triSurface &surf, const labelList &refineFaces)
Refine face by splitting all edges. Neighbouring face is.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Definition: MinMaxI.H:24
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:385
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
T getCheckOrDefault(const word &optName, const T &deflt, const Predicate &pred) const
Get a value from the named option with additional checking (if present), or return default...
Definition: argListI.H:463
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:521
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Triangulated surface description with patch information.
Definition: triSurface.H:71
Foam::argList args(argc, argv)
Namespace for OpenFOAM.