Files
openfoam/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
Mark Olesen 6b3b6bb99f ENH: add stream format options for surface writers (#1595)
- additional boundaryData options (header, binary, compression)

- remove vtkSurfaceWriter "writePrecision" keyword (1806 compatibilty)
  and use "precision" in format option sub-dictionary.
2020-02-19 21:30:55 +01:00

137 lines
4.0 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "SMESHsurfaceFormat.H"
#include "clock.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf,
IOstreamOption streamOpt,
const dictionary&
)
{
// ASCII only, allow output compression
streamOpt.format(IOstream::ASCII);
const UList<point>& pointLst = surf.points();
const UList<Face>& faceLst = surf.surfFaces();
const UList<label>& faceMap = surf.faceMap();
const surfZoneList zones =
(
surf.surfZones().empty()
? surfaceFormatsCore::oneZone(faceLst)
: surf.surfZones()
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename, streamOpt);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// Write header
os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl
<< "# <points count=\"" << pointLst.size() << "\">" << nl
<< pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords
forAll(pointLst, pti)
{
const point& pt = pointLst[pti];
os << pti << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
os << faceLst.size() << " 1" << endl; // one attribute: zone number
label faceIndex = 0;
label zoneIndex = 0;
for (const surfZone& zone : zones)
{
const label nLocalFaces = zone.size();
if (useFaceMap)
{
for (label i=0; i<nLocalFaces; ++i)
{
const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
for (const label verti : f)
{
os << ' ' << verti;
}
os << ' ' << zoneIndex << nl;
}
}
else
{
for (label i=0; i<nLocalFaces; ++i)
{
const Face& f = faceLst[faceIndex++];
os << f.size();
for (const label verti : f)
{
os << ' ' << verti;
}
os << ' ' << zoneIndex << nl;
}
}
++zoneIndex;
}
// write tail
os << "# </faces>" << nl
<< nl
<< "# no holes or regions:" << nl
<< '0' << nl // holes
<< '0' << endl; // regions
}
// ************************************************************************* //