writeSMESH.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "triSurface.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 void triSurface::writeSMESH(const bool writeSorted, Ostream& os) const
36 {
37  const pointField& ps = points();
38 
39  // Write header
40  os << "# tetgen .smesh file" << endl
41  << ps.size() << " 3" << endl; // 3 dimensions
42 
43  // Write vertex coords
44  forAll(ps, pointi)
45  {
46  os << pointi << ' '
47  << ps[pointi].x() << ' '
48  << ps[pointi].y() << ' '
49  << ps[pointi].z() << endl;
50  }
51 
52  if (writeSorted)
53  {
55 
56  surfacePatchList patches(calcPatches(faceMap));
57 
58  os << size() << " 1" << endl; // 1 attribute: region number
59 
60  label faceIndex = 0;
61 
63  {
64  // Print all faces belonging to this patch
65 
66  for
67  (
68  label patchFacei = 0;
69  patchFacei < patches[patchi].size();
70  patchFacei++
71  )
72  {
73  const label facei = faceMap[faceIndex++];
74 
75  os << "3 " // triangles
76  << operator[](facei)[0] << ' '
77  << operator[](facei)[1] << ' '
78  << operator[](facei)[2] << ' '
79  << operator[](facei).region() // region number
80  << endl;
81  }
82  }
83 
84  os << '0' << endl // holes
85  << '0' << endl; // regions
86  }
87  else
88  {
89  os << size() << " 1" << endl; // 1 attribute: region number
90 
91  forAll(*this, facei)
92  {
93  os << "3 "
94  << operator[](facei)[0] << ' '
95  << operator[](facei)[1] << ' '
96  << operator[](facei)[2] << ' '
97  << operator[](facei).region() // region number
98  << endl;
99  }
100 
101  os << '0' << endl // holes
102  << '0' << endl; // regions
103  }
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 } // End namespace Foam
110 
111 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Field< PointType > & points() const
Return reference to global points.
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
const geometricSurfacePatchList & patches() const
Definition: triSurface.H:322
label patchi
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< surfacePatch > surfacePatchList