surfaceAutoPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  surfaceAutoPatch
26 
27 Description
28  Patches surface according to feature angle. Like autoPatch.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "triangle.H"
33 #include "triSurface.H"
34 #include "argList.H"
35 #include "surfaceFeatures.H"
36 #include "treeBoundBox.H"
37 #include "meshTools.H"
38 #include "OFstream.H"
39 
40 using namespace Foam;
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 int main(int argc, char *argv[])
45 {
46  #include "removeCaseOptions.H"
47 
48  argList::validArgs.append("surface file");
49  argList::validArgs.append("output surface file");
50  argList::validArgs.append("includedAngle [0..180]");
51  argList args(argc, argv);
52 
53  const fileName inFileName = args[1];
54  const fileName outFileName = args[2];
55  const scalar includedAngle = args.argRead<scalar>(3);
56 
57  Info<< "Surface : " << inFileName << nl << endl;
58 
59 
60  // Read
61  // ~~~~
62 
63  Info<< "Reading : " << inFileName << endl;
64  triSurface surf(inFileName);
65 
66  Info<< "Read surface:" << endl;
67  surf.writeStats(Info);
68  Info<< endl;
69 
70 
71 
72  // Construct features from surface&featureangle
73  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 
75  Info<< "Constructing feature set from included angle " << includedAngle
76  << endl;
77 
78  surfaceFeatures set(surf, includedAngle);
79 
80  Info<< nl
81  << "Feature set:" << nl
82  << " feature points : " << set.featurePoints().size() << nl
83  << " feature edges : " << set.featureEdges().size() << nl
84  << " of which" << nl
85  << " region edges : " << set.nRegionEdges() << nl
86  << " external edges : " << set.nExternalEdges() << nl
87  << " internal edges : " << set.nInternalEdges() << nl
88  << endl;
89 
90  // Get per-edge status.
91  boolList borderEdge(surf.nEdges(), false);
92  forAll(set.featureEdges(), i)
93  {
94  borderEdge[set.featureEdges()[i]] = true;
95  }
96 
97  labelList faceRegion(surf.size());
98  label nRegions = surf.markZones(borderEdge, faceRegion);
99 
100  // Reregion triangles.
101  forAll(surf, i)
102  {
103  surf[i].region() = faceRegion[i];
104  }
105 
106  // Create some patches
107  surf.patches().setSize(nRegions);
108 
109  forAll(surf.patches(), patchi)
110  {
111  surf.patches()[patchi].name() = "patch" + Foam::name(patchi);
112  surf.patches()[patchi].geometricType() = "empty";
113  }
114 
115 
116  Info<< "Writing : " << outFileName << endl;
117  surf.write(outFileName, true);
118 
119  Info<< "End\n" << endl;
120 
121  return 0;
122 }
123 
124 
125 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual Ostream & write(const char)=0
Write character.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:183
A class for handling file names.
Definition: fileName.H:82
Holds feature edges/points of surface.
Triangulated surface description with patch information.
Definition: triSurface.H:69
int main(int argc, char *argv[])
Definition: financialFoam.C:44
label patchi
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)