FreeFOAM The Cross-Platform CFD Toolkit
surfaceAutoPatch.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 Usage
31 
32  - surfaceAutoPatch [OPTIONS] <Foam surface file> <Foam output surface file> <included angle [0..180]>
33 
34  @param <Foam surface file> \n
35  @todo Detailed description of argument.
36 
37  @param <Foam output surface file> \n
38  @todo Detailed description of argument.
39 
40  @param <included angle [0..180]> \n
41  @todo Detailed description of argument.
42 
43  @param -case <dir>\n
44  Case directory.
45 
46  @param -help \n
47  Display help message.
48 
49  @param -doc \n
50  Display Doxygen API documentation page for this application.
51 
52  @param -srcDoc \n
53  Display Doxygen source documentation page for this application.
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #include <OpenFOAM/triangle.H>
58 #include <triSurface/triSurface.H>
59 #include <OpenFOAM/argList.H>
61 #include <meshTools/treeBoundBox.H>
62 #include <meshTools/meshTools.H>
63 #include <OpenFOAM/OFstream.H>
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 // Main program:
70 
71 int main(int argc, char *argv[])
72 {
75  argList::validArgs.append("input surface file");
76  argList::validArgs.append("output surface file");
77  argList::validArgs.append("included angle [0..180]");
78  argList args(argc, argv);
79 
80  fileName inFileName(args.additionalArgs()[0]);
81  fileName outFileName(args.additionalArgs()[1]);
82  scalar includedAngle(readScalar(IStringStream(args.additionalArgs()[2])()));
83 
84  Pout<< "Surface : " << inFileName << nl
85  << endl;
86 
87 
88  // Read
89  // ~~~~
90 
91  Info << "Reading : " << inFileName << endl;
92  triSurface surf(inFileName);
93 
94  Info<< "Read surface:" << endl;
95  surf.writeStats(Info);
96  Info<< endl;
97 
98 
99 
100  // Construct features from surface&featureangle
101  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102 
103  Info<< "Constructing feature set from included angle " << includedAngle
104  << endl;
105 
106  surfaceFeatures set(surf, includedAngle);
107 
108  Pout<< nl
109  << "Feature set:" << nl
110  << " feature points : " << set.featurePoints().size() << nl
111  << " feature edges : " << set.featureEdges().size() << nl
112  << " of which" << nl
113  << " region edges : " << set.nRegionEdges() << nl
114  << " external edges : " << set.nExternalEdges() << nl
115  << " internal edges : " << set.nInternalEdges() << nl
116  << endl;
117 
118  // Get per-edge status.
119  boolList borderEdge(surf.nEdges(), false);
120  forAll(set.featureEdges(), i)
121  {
122  borderEdge[set.featureEdges()[i]] = true;
123  }
124 
125  labelList faceRegion(surf.size());
126  label nRegions = surf.markZones(borderEdge, faceRegion);
127 
128  // Reregion triangles.
129  forAll(surf, i)
130  {
131  surf[i].region() = faceRegion[i];
132  }
133 
134  // Create some patches
135  surf.patches().setSize(nRegions);
136 
137  forAll(surf.patches(), patchI)
138  {
139  surf.patches()[patchI].name() = "patch" + Foam::name(patchI);
140  surf.patches()[patchI].geometricType() = "empty";
141  }
142 
143 
144  Info << "Writing : " << outFileName << endl;
145  surf.write(outFileName, true);
146 
147  Info<< "End\n" << endl;
148 
149  return 0;
150 }
151 
152 
153 // ************************ vim: set sw=4 sts=4 et: ************************ //