surfaceMeshInfo.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-2022 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 {
71  writeInfoHeader = false;
72 
74  (
75  "information about surface meshes"
76  );
77 
79  argList::validArgs.append("surface file");
80 
82  (
83  "scale",
84  "factor",
85  "geometry scaling factor - default is 1"
86  );
88  (
89  "areas",
90  "display area of each face"
91  );
93  (
94  "xml",
95  "write output in XML format"
96  );
97 
98  argList args(argc, argv);
99  Time runTime(args.rootPath(), args.caseName());
100 
101  const fileName importName = args[1];
102 
103  // check that reading is supported
104  if (!UnsortedMeshedSurface<face>::canRead(importName, true))
105  {
106  return 1;
107  }
108 
109  const bool writeXML = args.optionFound("xml");
110  const bool writeAreas = args.optionFound("areas");
111 
112 
113  // use UnsortedMeshedSurface, not MeshedSurface to maintain ordering
114  UnsortedMeshedSurface<face> surf(importName);
115 
116  scalar scaling = 0;
117  if (args.optionReadIfPresent("scale", scaling) && scaling > 0)
118  {
119  Info<< " -scale " << scaling << endl;
120  surf.scalePoints(scaling);
121  }
122 
123  scalar areaTotal = 0;
124 
125  if (writeXML)
126  {
127  Info<<"<?xml version='1.0' encoding='utf-8'?>" << nl
128  <<"<surfaceMeshInfo>" << nl
129  << "<npoints>" << surf.nPoints() << "</npoints>" << nl
130  << "<nfaces>" << surf.size() << "</nfaces>" << nl;
131 
132  if (writeAreas)
133  {
134  Info<<"<areas size='" << surf.size() << "'>" << nl;
135  }
136  }
137  else
138  {
139  Info<< "nPoints : " << surf.nPoints() << nl
140  << "nFaces : " << surf.size() << nl;
141 
142  if (writeAreas)
143  {
144  Info<< "areas : " << nl;
145  }
146  }
147 
148  forAll(surf, facei)
149  {
150  const scalar fArea(surf[facei].mag(surf.points()));
151  areaTotal += fArea;
152 
153  if (writeAreas)
154  {
155  Info<< fArea << nl;
156  }
157  }
158 
159  if (writeXML)
160  {
161  if (writeAreas)
162  {
163  Info<<"</areas>" << nl;
164  }
165 
166  Info<< "<area>" << areaTotal << "</area>" << nl
167  << "</surfaceMeshInfo>" << nl;
168  }
169  else
170  {
171  Info<< "area : " << areaTotal << nl;
172  }
173 
174  return 0;
175 }
176 
177 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:48
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:204
static void noParallel()
Remove the parallel options.
Definition: argList.C:175
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
A class for handling file names.
Definition: fileName.H:82
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool writeInfoHeader
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)