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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "SMESHsurfaceFormat.H"
30 #include "clock.H"
31 #include "OFstream.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<class Face>
37 (
38  const fileName& filename,
39  const MeshedSurfaceProxy<Face>& surf,
40  IOstreamOption streamOpt,
41  const dictionary&
42 )
43 {
44  // ASCII only, allow output compression
45  streamOpt.format(IOstream::ASCII);
46 
47  const UList<point>& pointLst = surf.points();
48  const UList<Face>& faceLst = surf.surfFaces();
49  const UList<label>& faceMap = surf.faceMap();
50 
51  const surfZoneList zones =
52  (
53  surf.surfZones().empty()
54  ? surfaceFormatsCore::oneZone(faceLst)
55  : surf.surfZones()
56  );
57 
58  const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
59 
60  OFstream os(filename, streamOpt);
61  if (!os.good())
62  {
64  << "Cannot write file " << filename << nl
65  << exit(FatalError);
66  }
67 
68 
69  // Write header
70  os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl
71  << "# <points count=\"" << pointLst.size() << "\">" << nl
72  << pointLst.size() << " 3" << nl; // 3: dimensions
73 
74  // Write vertex coords
75  forAll(pointLst, pti)
76  {
77  const point& pt = pointLst[pti];
78 
79  os << pti << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
80  }
81  os << "# </points>" << nl
82  << nl
83  << "# <faces count=\"" << faceLst.size() << "\">" << endl;
84 
85  os << faceLst.size() << " 1" << endl; // one attribute: zone number
86 
87 
88  label faceIndex = 0;
89  label zoneIndex = 0;
90 
91  for (const surfZone& zone : zones)
92  {
93  for (label nLocal = zone.size(); nLocal--; ++faceIndex)
94  {
95  const label facei =
96  (useFaceMap ? faceMap[faceIndex] : faceIndex);
97 
98  const Face& f = faceLst[facei];
99 
100  os << f.size();
101  for (const label verti : f)
102  {
103  os << ' ' << verti;
104  }
105  os << ' ' << zoneIndex << nl;
106  }
107 
108  ++zoneIndex;
109  }
110 
111  // write tail
112 
113  os << "# </faces>" << nl
114  << nl
115  << "# no holes or regions:" << nl
116  << '0' << nl // holes
117  << '0' << endl; // regions
118 }
119 
120 
121 // ************************************************************************* //
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::MeshedSurfaceProxy::useFaceMap
bool useFaceMap() const
Can/should use faceMap?
Definition: MeshedSurfaceProxy.H:203
Foam::zone
Base class for mesh zones.
Definition: zone.H:63
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::MeshedSurfaceProxy::points
const pointField & points() const
Return const access to the points.
Definition: MeshedSurfaceProxy.H:171
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:82
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::MeshedSurfaceProxy::faceMap
const labelUList & faceMap() const
Const access to the faceMap, zero-sized when unused.
Definition: MeshedSurfaceProxy.H:191
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
SMESHsurfaceFormat.H
Foam::fileFormats::SMESHsurfaceFormat::write
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &=dictionary::null)
Write surface mesh components by proxy.
Definition: SMESHsurfaceFormat.C:37
clock.H
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List< surfZone >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:56
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::MeshedSurfaceProxy::surfFaces
const UList< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurfaceProxy.H:177
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::MeshedSurfaceProxy::surfZones
const UList< surfZone > & surfZones() const
Const access to the surface zones.
Definition: MeshedSurfaceProxy.H:185