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-2021 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 auto importName = args.get<fileName>(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()
Definition: argList.C:434
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:69
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::argList::getOrDefault
T getOrDefault(const word &optName, const T &deflt) const
Definition: argListI.H:300
Foam::argList::caseName
const fileName & caseName() const noexcept
Definition: argListI.H:62
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:119
Foam::argList::get
T get(const label index) const
Definition: argListI.H:271
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Definition: argList.C:294
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:79
Foam::Info
messageStream Info
argList.H
DetailInfo
#define DetailInfo
Definition: evalEntry.C:30
Foam
Definition: atmBoundaryLayer.C:26
Foam::profiling::disable
static void disable()
Definition: profiling.C:110
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Definition: argList.C:317
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
UnsortedMeshedSurfaces.H
Foam::argList::noParallel
static void noParallel()
Definition: argList.C:503
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Definition: argList.C:328
args
Foam::argList args(argc, argv)
Foam::argList::rootPath
const fileName & rootPath() const noexcept
Definition: argListI.H:56
Foam::argList::found
bool found(const word &optName) const
Definition: argListI.H:171