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