surfaceMeshInfo.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) 2011-2016 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  surfaceMeshInfo
26 
27 Description
28  Miscellaneous information about surface meshes.
29 
30 Usage
31  \b surfaceMeshInfo surfaceFile [OPTION]
32 
33  Options:
34  - \par -areas
35  Report area for each face.
36 
37  - \par -scale <scale>
38  Specify a scaling factor when reading files.
39 
40  - \par -xml
41  Write output in XML format.
42 
43 Note
44  The filename extensions are used to determine the file format type.
45 
46  The XML-like output can be useful for extraction with other tools,
47  but either output format can be easily extracted with a simple sed
48  command:
49  \verbatim
50  surfaceMeshInfo surfaceFile -areas | \
51  sed -ne '/areas/,/:/{ /:/!p }'
52 
53  surfaceMeshInfo surfaceFile -areas -xml | \
54  sed -ne '/<areas/,/</{ /</!p }'
55  \endverbatim
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #include "argList.H"
60 #include "Time.H"
61 
62 #include "UnsortedMeshedSurfaces.H"
63 
64 using namespace Foam;
65 
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 int main(int argc, char *argv[])
70 {
72  (
73  "information about surface meshes"
74  );
75 
78  argList::validArgs.append("surfaceFile");
79 
81  (
82  "scale",
83  "factor",
84  "geometry scaling factor - default is 1"
85  );
87  (
88  "areas",
89  "display area of each face"
90  );
92  (
93  "xml",
94  "write output in XML format"
95  );
96 
97  argList args(argc, argv);
98  Time runTime(args.rootPath(), args.caseName());
99 
100  const fileName importName = args[1];
101 
102  // check that reading is supported
103  if (!UnsortedMeshedSurface<face>::canRead(importName, true))
104  {
105  return 1;
106  }
107 
108  const bool writeXML = args.optionFound("xml");
109  const bool writeAreas = args.optionFound("areas");
110 
111 
112  // use UnsortedMeshedSurface, not MeshedSurface to maintain ordering
113  UnsortedMeshedSurface<face> surf(importName);
114 
115  scalar scaling = 0;
116  if (args.optionReadIfPresent("scale", scaling) && scaling > 0)
117  {
118  Info<< " -scale " << scaling << endl;
119  surf.scalePoints(scaling);
120  }
121 
122  scalar areaTotal = 0;
123 
124  if (writeXML)
125  {
126  Info<<"<?xml version='1.0' encoding='utf-8'?>" << nl
127  <<"<surfaceMeshInfo>" << nl
128  << "<npoints>" << surf.nPoints() << "</npoints>" << nl
129  << "<nfaces>" << surf.size() << "</nfaces>" << nl;
130 
131  if (writeAreas)
132  {
133  Info<<"<areas size='" << surf.size() << "'>" << nl;
134  }
135  }
136  else
137  {
138  Info<< "nPoints : " << surf.nPoints() << nl
139  << "nFaces : " << surf.size() << nl;
140 
141  if (writeAreas)
142  {
143  Info<< "areas : " << nl;
144  }
145  }
146 
147  forAll(surf, facei)
148  {
149  const scalar fArea(surf[facei].mag(surf.points()));
150  areaTotal += fArea;
151 
152  if (writeAreas)
153  {
154  Info<< fArea << nl;
155  }
156  }
157 
158  if (writeXML)
159  {
160  if (writeAreas)
161  {
162  Info<<"</areas>" << nl;
163  }
164 
165  Info<< "<area>" << areaTotal << "</area>" << nl
166  << "</surfaceMeshInfo>" << nl;
167  }
168  else
169  {
170  Info<< "area : " << areaTotal << nl;
171  }
172 
173  return 0;
174 }
175 
176 // ************************************************************************* //
A surface geometry mesh, in which the surface zone information is conveyed by the &#39;zoneId&#39; associated...
Definition: MeshedSurface.H:74
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A class for handling file names.
Definition: fileName.H:69
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
static const char nl
Definition: Ostream.H:262
messageStream Info
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:140
dimensioned< scalar > mag(const dimensioned< Type > &)
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
Foam::argList args(argc, argv)
Namespace for OpenFOAM.