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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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  surfaceMeshInfo
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
34  Miscellaneous information about surface meshes.
35  To simplify parsing of the output, the normal banner information
36  is suppressed.
37 
38 Usage
39  \b surfaceMeshInfo surfaceFile [OPTION]
40 
41  Options:
42  - \par -areas
43  Report area for each face.
44 
45  - \par -scale <scale>
46  Specify a scaling factor when reading files.
47 
48  - \par -xml
49  Write output in XML format.
50 
51 Note
52  The filename extensions are used to determine the file format type.
53 
54  The XML-like output can be useful for extraction with other tools,
55  but either output format can be easily extracted with a simple sed
56  command:
57  \verbatim
58  surfaceMeshInfo surfaceFile -areas | \
59  sed -ne '/areas/,/:/{ /:/!p }'
60 
61  surfaceMeshInfo surfaceFile -areas -xml | \
62  sed -ne '/<areas/,/</{ /</!p }'
63  \endverbatim
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #include "argList.H"
68 #include "profiling.H"
69 #include "Time.H"
70 
71 #include "UnsortedMeshedSurfaces.H"
72 
73 using namespace Foam;
74 
75 
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 
78 int main(int argc, char *argv[])
79 {
81  (
82  "Information about surface meshes"
83  );
84 
87  argList::addArgument("surface", "The input surface file");
88 
90  (
91  "scale",
92  "factor",
93  "Input geometry scaling factor"
94  );
96  (
97  "areas",
98  "Display area of each face"
99  );
101  (
102  "xml",
103  "Write output in XML format"
104  );
105  profiling::disable(); // Disable profiling (and its output)
106 
107  argList args(argc, argv);
109 
110  const fileName importName = args[1];
111 
112  // check that reading is supported
113  if (!UnsortedMeshedSurface<face>::canRead(importName, true))
114  {
115  return 1;
116  }
117 
118  const bool writeXML = args.found("xml");
119  const bool writeAreas = args.found("areas");
120 
121 
122  // use UnsortedMeshedSurface, not MeshedSurface to maintain ordering
123  UnsortedMeshedSurface<face> surf(importName);
124 
125  const scalar scaling = args.getOrDefault<scalar>("scale", -1);
126  if (scaling > 0)
127  {
128  DetailInfo << " -scale " << scaling << nl;
129  surf.scalePoints(scaling);
130  }
131 
132  scalar areaTotal = 0;
133 
134  if (writeXML)
135  {
136  Info<<"<?xml version='1.0' encoding='utf-8'?>" << nl
137  <<"<surfaceMeshInfo>" << nl
138  << "<npoints>" << surf.nPoints() << "</npoints>" << nl
139  << "<nfaces>" << surf.size() << "</nfaces>" << nl;
140 
141  if (writeAreas)
142  {
143  Info<<"<areas size='" << surf.size() << "'>" << nl;
144  }
145  }
146  else
147  {
148  Info<< "nPoints : " << surf.nPoints() << nl
149  << "nFaces : " << surf.size() << nl;
150 
151  if (writeAreas)
152  {
153  Info<< "areas : " << nl;
154  }
155  }
156 
157  forAll(surf, facei)
158  {
159  const scalar fArea(surf[facei].mag(surf.points()));
160  areaTotal += fArea;
161 
162  if (writeAreas)
163  {
164  Info<< fArea << nl;
165  }
166  }
167 
168  if (writeXML)
169  {
170  if (writeAreas)
171  {
172  Info<<"</areas>" << nl;
173  }
174 
175  Info<< "<area>" << areaTotal << "</area>" << nl
176  << "</surfaceMeshInfo>" << nl;
177  }
178  else
179  {
180  Info<< "area : " << areaTotal << nl;
181  }
182 
183  return 0;
184 }
185 
186 // ************************************************************************* //
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:442
profiling.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
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::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:63
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:83
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
DetailInfo
#define DetailInfo
Definition: evalEntry.C:36
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::profiling::disable
static void disable()
Disallow profiling by forcing the InfoSwitch off.
Definition: profiling.C:118
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
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
UnsortedMeshedSurfaces.H
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:69
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