FreeFOAM The Cross-Platform CFD Toolkit
SMESHsurfaceFormat.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) 1991-2010 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
25 
26 #include "SMESHsurfaceFormat.H"
27 #include <OpenFOAM/clock.H>
28 #include <OpenFOAM/IFstream.H>
29 #include <OpenFOAM/OFstream.H>
30 #include <OpenFOAM/Ostream.H>
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Face>
36 {}
37 
38 
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 
41 template<class Face>
43 (
44  const fileName& filename,
45  const MeshedSurfaceProxy<Face>& surf
46 )
47 {
48  const pointField& pointLst = surf.points();
49  const List<Face>& faceLst = surf.faces();
50  const List<label>& faceMap = surf.faceMap();
51 
52  const List<surfZone>& zones =
53  (
54  surf.surfZones().size() > 1
55  ? surf.surfZones()
56  : oneZone(faceLst)
57  );
58 
59  const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
60 
61 
62  OFstream os(filename);
63  if (!os.good())
64  {
66  (
67  "fileFormats::SMESHsurfaceFormat::write"
68  "(const fileName&, const MeshedSurfaceProxy<Face>&)"
69  )
70  << "Cannot open file for writing " << filename
71  << exit(FatalError);
72  }
73 
74 
75  // Write header
76  os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl
77  << "# <points count=\"" << pointLst.size() << "\">" << nl
78  << pointLst.size() << " 3" << nl; // 3: dimensions
79 
80  // Write vertex coords
81  forAll(pointLst, ptI)
82  {
83  const point& pt = pointLst[ptI];
84 
85  os << ptI << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
86  }
87  os << "# </points>" << nl
88  << nl
89  << "# <faces count=\"" << faceLst.size() << "\">" << endl;
90 
91  os << faceLst.size() << " 1" << endl; // one attribute: zone number
92 
93 
94  label faceIndex = 0;
95  forAll(zones, zoneI)
96  {
97  const surfZone& zone = zones[zoneI];
98 
99  if (useFaceMap)
100  {
101  forAll(zone, localFaceI)
102  {
103  const Face& f = faceLst[faceMap[faceIndex++]];
104 
105  os << f.size();
106  forAll(f, fp)
107  {
108  os << ' ' << f[fp];
109  }
110  os << ' ' << zoneI << endl;
111  }
112  }
113  else
114  {
115  forAll(zones[zoneI], localFaceI)
116  {
117  const Face& f = faceLst[faceIndex++];
118 
119  os << f.size();
120  forAll(f, fp)
121  {
122  os << ' ' << f[fp];
123  }
124  os << ' ' << zoneI << endl;
125  }
126  }
127  }
128 
129  // write tail
130 
131  os << "# </faces>" << nl
132  << nl
133  << "# no holes or regions:" << nl
134  << '0' << nl // holes
135  << '0' << endl; // regions
136 }
137 
138 
139 // ************************ vim: set sw=4 sts=4 et: ************************ //