2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2010-05-12 13:27:55 +00:00
|
|
|
\\ / O peration |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / A nd | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
\\/ M anipulation |
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "patchWriter.H"
|
|
|
|
#include "writeFuns.H"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Construct from components
|
|
|
|
Foam::patchWriter::patchWriter
|
|
|
|
(
|
|
|
|
const vtkMesh& vMesh,
|
|
|
|
const bool binary,
|
|
|
|
const bool nearCellValue,
|
|
|
|
const fileName& fName,
|
|
|
|
const labelList& patchIDs
|
|
|
|
)
|
|
|
|
:
|
|
|
|
vMesh_(vMesh),
|
|
|
|
binary_(binary),
|
|
|
|
nearCellValue_(nearCellValue),
|
2010-08-26 14:22:03 +00:00
|
|
|
fName_(fName),
|
2010-05-12 13:27:55 +00:00
|
|
|
patchIDs_(patchIDs),
|
|
|
|
os_(fName.c_str())
|
|
|
|
{
|
|
|
|
const fvMesh& mesh = vMesh_.mesh();
|
|
|
|
const polyBoundaryMesh& patches = mesh.boundaryMesh();
|
|
|
|
|
|
|
|
// Write header
|
|
|
|
if (patchIDs_.size() == 1)
|
|
|
|
{
|
|
|
|
writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
writeFuns::writeHeader(os_, binary_, "patches");
|
|
|
|
}
|
|
|
|
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
|
|
|
|
|
|
|
|
// Write topology
|
|
|
|
nPoints_ = 0;
|
|
|
|
nFaces_ = 0;
|
|
|
|
label nFaceVerts = 0;
|
|
|
|
|
|
|
|
forAll(patchIDs_, i)
|
|
|
|
{
|
|
|
|
const polyPatch& pp = patches[patchIDs_[i]];
|
|
|
|
|
|
|
|
nPoints_ += pp.nPoints();
|
|
|
|
nFaces_ += pp.size();
|
|
|
|
|
|
|
|
forAll(pp, faceI)
|
|
|
|
{
|
|
|
|
nFaceVerts += pp[faceI].size() + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
os_ << "POINTS " << nPoints_ << " float" << std::endl;
|
|
|
|
|
|
|
|
DynamicList<floatScalar> ptField(3*nPoints_);
|
|
|
|
|
|
|
|
forAll(patchIDs_, i)
|
|
|
|
{
|
|
|
|
const polyPatch& pp = patches[patchIDs_[i]];
|
|
|
|
|
|
|
|
writeFuns::insert(pp.localPoints(), ptField);
|
|
|
|
}
|
|
|
|
writeFuns::write(os_, binary_, ptField);
|
|
|
|
|
|
|
|
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
DynamicList<label> vertLabels(nFaceVerts);
|
|
|
|
DynamicList<label> faceTypes(nFaceVerts);
|
|
|
|
|
|
|
|
label offset = 0;
|
|
|
|
|
|
|
|
forAll(patchIDs_, i)
|
|
|
|
{
|
|
|
|
const polyPatch& pp = patches[patchIDs_[i]];
|
|
|
|
|
|
|
|
forAll(pp, faceI)
|
|
|
|
{
|
|
|
|
const face& f = pp.localFaces()[faceI];
|
|
|
|
|
|
|
|
const label fSize = f.size();
|
|
|
|
vertLabels.append(fSize);
|
|
|
|
|
|
|
|
writeFuns::insert(f + offset, vertLabels);
|
|
|
|
|
|
|
|
if (fSize == 3)
|
|
|
|
{
|
|
|
|
faceTypes.append(vtkTopo::VTK_TRIANGLE);
|
|
|
|
}
|
|
|
|
else if (fSize == 4)
|
|
|
|
{
|
|
|
|
faceTypes.append(vtkTopo::VTK_QUAD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
faceTypes.append(vtkTopo::VTK_POLYGON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += pp.nPoints();
|
|
|
|
}
|
|
|
|
writeFuns::write(os_, binary_, vertLabels);
|
|
|
|
|
|
|
|
os_ << "CELL_TYPES " << nFaces_ << std::endl;
|
|
|
|
|
|
|
|
writeFuns::write(os_, binary_, faceTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
void Foam::patchWriter::writePatchIDs()
|
|
|
|
{
|
|
|
|
const fvMesh& mesh = vMesh_.mesh();
|
|
|
|
|
|
|
|
DynamicList<floatScalar> fField(nFaces_);
|
|
|
|
|
|
|
|
os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
|
|
|
|
|
|
|
|
forAll(patchIDs_, i)
|
|
|
|
{
|
|
|
|
label patchI = patchIDs_[i];
|
|
|
|
|
|
|
|
const polyPatch& pp = mesh.boundaryMesh()[patchI];
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (!isA<emptyPolyPatch>(pp))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
writeFuns::insert(scalarField(pp.size(), patchI), fField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeFuns::write(os_, binary_, fField);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|