FLMAToSurface.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  Reads the AVL's surface mesh
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "triSurf.H"
31 #include "triSurfModifier.H"
32 #include "triFaceList.H"
33 #include "labelLongList.H"
34 #include "IFstream.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( inFileName.ext() != "flma" )
53  {
54  Info << "Cannot convert this mesh" << endl;
55  return 0;
56  }
57 
58  //- create the surface mesh
59  triSurf ts;
60  triSurfModifier tsm(ts);
61 
62  label counter;
63 
64  IFstream inFile(inFileName);
65 
66  inFile >> counter;
67 
68  //- read vertices
70  points.setSize(counter);
71  forAll(points, pointI)
72  {
73  point& p = points[pointI];
74 
75  inFile >> p.x();
76  inFile >> p.y();
77  inFile >> p.z();
78  }
79 
80  //- read facets
81  inFile >> counter;
83  patches[0].name() = "patch";
84  LongList<labelledTri>& triangles = tsm.facetsAccess();
85  triangles.setSize(counter);
86  forAll(triangles, triI)
87  {
88  inFile >> counter;
89 
90  if( counter != 3 )
91  {
92  Info << "Facet " << triI << " is not a triangle!!" << endl;
93  Warning << "Cannot convert this surface!" << endl;
94  return 0;
95  }
96 
97  for(label j=0;j<3;++j)
98  inFile >> triangles[triI][2-j];
99 
100  triangles[triI].region() = 0;
101  }
102 
103  //- read cell types
104  inFile >> counter;
105  forAll(triangles, triI)
106  inFile >> counter;
107 
108  //- start reading selections
109  inFile >> counter;
110  for(label selI=0;selI<counter;++selI)
111  {
112  //- read selection name
113  word selName;
114  inFile >> selName;
115 
116  //- read selection type
117  label selType;
118  inFile >> selType;
119 
120  //- read selection entries
121  label size;
122  inFile >> size;
123  labelLongList entries(size);
124  for(label i=0;i<size;++i)
125  inFile >> entries[i];
126 
127  //- store cell selections
128  if( selType == 2 )
129  {
130  Info << "Adding subset " << selName << endl;
131  const label setID = ts.addFacetSubset(selName);
132 
133  forAll(entries, i)
134  ts.addFacetToSubset(setID, entries[i]);
135  }
136  }
137 
138  //- write the surface
139  ts.writeSurface(outFileName);
140 
141  Info << "End\n" << endl;
142  return 0;
143 }
144 
145 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurf.H
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
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::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::Warning
messageStream Warning
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
triSurfModifier.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::triSurfModifier
Definition: triSurfModifier.H:48
labelLongList
This is a typedef for LongList<label>
Foam::LongList::setSize
void setSize(const label)
Reset size of List.
Definition: LongListI.H:223
Foam::LongList
Definition: LongList.H:55
Foam::triSurfFacets::addFacetToSubset
void addFacetToSubset(const label, const label)
Definition: triSurfFacetsI.H:60
main
int main(int argc, char *argv[])
Definition: FLMAToSurface.C:40
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::triSurfModifier::pointsAccess
pointField & pointsAccess()
non-const access to points
Definition: triSurfModifierI.H:37
argList.H
Foam::triSurfModifier::facetsAccess
LongList< labelledTri > & facetsAccess()
access to facets
Definition: triSurfModifierI.H:42
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::Vector< scalar >
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
labelLongList.H
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
patches
patches[0]
Definition: createSingleCellMesh.H:36
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