mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- with the xml append format it is possible to write raw binary
(instead of base64), but the writer becomes more complicated.
Either needs two passes to create, or need to allocate a block
of space for the header information (like VTK itself does) and
write later.
* internalWriter
* patchWriter
* surfaceMeshWriter
* lagrangianWriter
Also these special purpose ones:
* foamVtkWriteSurfFields
109 lines
3.3 KiB
C
109 lines
3.3 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
|
\\/ M anipulation | Copyright (C) 2017 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 "foamVtkWriteFaceSet.H"
|
|
#include "foamVtkOutputOptions.H"
|
|
#include "OFstream.H"
|
|
#include "primitiveMesh.H"
|
|
#include "faceSet.H"
|
|
#include "uindirectPrimitivePatch.H"
|
|
|
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
|
|
|
void Foam::foamVtkOutput::writeFaceSet
|
|
(
|
|
const primitiveMesh& mesh,
|
|
const faceSet& set,
|
|
const fileName& baseName,
|
|
const foamVtkOutput::outputOptions outOpts
|
|
)
|
|
{
|
|
outputOptions opts(outOpts);
|
|
opts.legacy(true); // Legacy only, no append
|
|
|
|
const bool legacy_(opts.legacy());
|
|
|
|
std::ofstream os((baseName + (legacy_ ? ".vtk" : ".vtp")).c_str());
|
|
|
|
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
|
|
|
|
if (legacy_)
|
|
{
|
|
legacy::fileHeader(format(), set.name(), vtkFileTag::POLY_DATA);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Faces of set with OpenFOAM faceID as value
|
|
const labelList faceLabels = set.sortedToc();
|
|
|
|
uindirectPrimitivePatch pp
|
|
(
|
|
UIndirectList<face>(mesh.faces(), faceLabels),
|
|
mesh.points()
|
|
);
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Write points and faces as polygons
|
|
legacy::beginPoints(os, pp.nPoints());
|
|
|
|
foamVtkOutput::writeList(format(), pp.localPoints());
|
|
format().flush();
|
|
|
|
// connectivity count without additional storage (done internally)
|
|
uint64_t nConnectivity = 0;
|
|
forAll(pp, facei)
|
|
{
|
|
nConnectivity += pp[facei].size();
|
|
}
|
|
legacy::beginPolys(os, pp.size(), nConnectivity);
|
|
|
|
|
|
// legacy: size + connectivity together
|
|
// [nPts, id1, id2, ..., nPts, id1, id2, ...]
|
|
forAll(pp, facei)
|
|
{
|
|
const face& f = pp.localFaces()[facei];
|
|
|
|
format().write(f.size()); // The size prefix
|
|
foamVtkOutput::writeList(format(), f);
|
|
}
|
|
format().flush();
|
|
|
|
|
|
// Write data - faceId/cellId
|
|
|
|
legacy::dataHeader(os, vtkFileTag::CELL_DATA, pp.size(), 1);
|
|
|
|
os << "faceID 1 " << pp.size() << " int" << nl;
|
|
|
|
foamVtkOutput::writeList(format(), faceLabels);
|
|
format().flush();
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|