patchesToSubsets.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Converts specified patches into subsets
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "triSurf.H"
31 #include "triFaceList.H"
32 #include "labelLongList.H"
33 #include "IFstream.H"
34 #include "OFstream.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 int main(int argc, char *argv[])
41 {
43  argList::validArgs.clear();
44 
45  argList::validArgs.append("input surface file");
46  argList::validArgs.append("output surface file");
47  argList args(argc, argv);
48 
49  fileName inFileName(args.args()[1]);
50  fileName outFileName(args.args()[2]);
51 
52  if( outFileName.ext() != "fms" )
53  Warning << "The subsets cann only be saved in the .fms format" << endl;
54 
55  triSurf origSurf(inFileName);
56 
57  wordList patchNames(origSurf.patches().size());
58  forAll(origSurf.patches(), patchI)
59  patchNames[patchI] = origSurf.patches()[patchI].name();
60 
61  forAll(patchNames, patchI)
62  {
63  labelLongList subsetFacets;
64  forAll(origSurf, triI)
65  {
66  if( origSurf[triI].region() == patchI )
67  subsetFacets.append(triI);
68  }
69 
70  const label subsetId = origSurf.addFacetSubset(patchNames[patchI]);
71 
72  forAll(subsetFacets, i)
73  origSurf.addFacetToSubset(subsetId, subsetFacets[i]);
74  }
75 
76  origSurf.writeSurface(outFileName);
77 
78  Info << "End\n" << endl;
79 
80  return 0;
81 }
82 
83 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurf.H
Foam::argList::args
const stringList & args() const
Return arguments.
Definition: argListI.H:66
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::Warning
messageStream Warning
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
labelLongList
This is a typedef for LongList<label>
OFstream.H
Foam::triSurfFacets::addFacetToSubset
void addFacetToSubset(const label, const label)
Definition: triSurfFacetsI.H:60
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: patchesToSubsets.C:40
Foam::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
patchNames
wordList patchNames(nPatches)
Foam::triSurfFacets::addFacetSubset
label addFacetSubset(const word &)
point subsets
Definition: triSurfFacets.C:105
IFstream.H
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
labelLongList.H
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
triFaceList.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::triSurf
Definition: triSurf.H:59