Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Application
28 surfaceMeshInfo
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Miscellaneous information about surface meshes.
35 To simplify parsing of the output, the normal banner information
36 is suppressed.
37
38Usage
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
51Note
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
72
73using namespace Foam;
74
75
76// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77
78int 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);
108 Time runTime(args.rootPath(), args.caseName());
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// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void noBanner()
Disable emitting the banner information.
Definition argList.C:506
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
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:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
A class for handling file names.
Definition fileName.H:75
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
Definition profiling.C:113
engineTime & runTime
#define DetailInfo
Definition evalEntry.C:30
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299