ENH: replace writeFuncs in setSet with foamVtk library utilities

This commit is contained in:
Mark Olesen 2017-05-19 12:28:13 +02:00
parent c685f70c82
commit 418ebe4a87
12 changed files with 390 additions and 647 deletions

View File

@ -1,7 +1,3 @@
writePointSet.C
writeFuns.C
writePatch.C
setSet.C
EXE = $(FOAM_APPBIN)/setSet

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,8 +44,9 @@ Description
#include "OFstream.H"
#include "IFstream.H"
#include "demandDrivenData.H"
#include "writePatch.H"
#include "writePointSet.H"
#include "foamVtkWriteCellSetFaces.H"
#include "foamVtkWriteFaceSet.H"
#include "foamVtkWritePointSet.H"
#include "IOobjectList.H"
#include "cellZoneSet.H"
#include "faceZoneSet.H"
@ -81,93 +82,28 @@ void writeVTK
if (isA<faceSet>(currentSet))
{
// Faces of set with OpenFOAM faceID as value
faceList setFaces(currentSet.size());
labelList faceValues(currentSet.size());
label setFacei = 0;
forAllConstIter(topoSet, currentSet, iter)
{
setFaces[setFacei] = mesh.faces()[iter.key()];
faceValues[setFacei] = iter.key();
setFacei++;
}
primitiveFacePatch fp(setFaces, mesh.points());
writePatch
foamVtkOutput::writeFaceSet
(
true,
currentSet.name(),
fp,
"faceID",
faceValues,
mesh,
currentSet,
mesh.time().path()/vtkName
);
}
else if (isA<cellSet>(currentSet))
{
// External faces of cellset with OpenFOAM cellID as value
Map<label> cellFaces(currentSet.size());
forAllConstIter(cellSet, currentSet, iter)
{
label celli = iter.key();
const cell& cFaces = mesh.cells()[celli];
forAll(cFaces, i)
{
label facei = cFaces[i];
if (mesh.isInternalFace(facei))
{
label otherCelli = mesh.faceOwner()[facei];
if (otherCelli == celli)
{
otherCelli = mesh.faceNeighbour()[facei];
}
if (!currentSet.found(otherCelli))
{
cellFaces.insert(facei, celli);
}
}
else
{
cellFaces.insert(facei, celli);
}
}
}
faceList setFaces(cellFaces.size());
labelList faceValues(cellFaces.size());
label setFacei = 0;
forAllConstIter(Map<label>, cellFaces, iter)
{
setFaces[setFacei] = mesh.faces()[iter.key()];
faceValues[setFacei] = iter(); // Cell ID
setFacei++;
}
primitiveFacePatch fp(setFaces, mesh.points());
writePatch
foamVtkOutput::writeCellSetFaces
(
true,
currentSet.name(),
fp,
"cellID",
faceValues,
mesh,
currentSet,
mesh.time().path()/vtkName
);
}
else if (isA<pointSet>(currentSet))
{
writePointSet
foamVtkOutput::writePointSet
(
true,
mesh,

View File

@ -1,225 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "writeFuns.H"
#include "endian.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::writeFuns::swapWord(int32_t& word32)
{
char* mem = reinterpret_cast<char*>(&word32);
char a = mem[0];
mem[0] = mem[3];
mem[3] = a;
a = mem[1];
mem[1] = mem[2];
mem[2] = a;
}
void Foam::writeFuns::swapWords(const label nWords, int32_t* words32)
{
for (label i=0; i<nWords; i++)
{
swapWord(words32[i]);
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
List<floatScalar>& fField
)
{
if (binary)
{
#ifdef WM_LITTLE_ENDIAN
swapWords(fField.size(), reinterpret_cast<int32_t*>(fField.begin()));
#endif
os.write
(
reinterpret_cast<char*>(fField.begin()),
fField.size()*sizeof(float)
);
os << std::endl;
}
else
{
forAll(fField, i)
{
os << fField[i] << ' ';
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<floatScalar>& fField
)
{
List<floatScalar>& fld = fField.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
labelList& elems
)
{
if (binary)
{
#ifdef WM_LITTLE_ENDIAN
swapWords
(
(sizeof(label)/4)*elems.size(),
reinterpret_cast<int32_t*>(elems.begin())
);
#endif
os.write
(
reinterpret_cast<char*>(elems.begin()),
elems.size()*sizeof(label)
);
os << std::endl;
}
else
{
forAll(elems, i)
{
os << elems[i] << ' ';
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<label>& elems
)
{
labelList& fld = elems.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::insert(const point& pt, DynamicList<floatScalar>& dest)
{
dest.append(float(pt.x()));
dest.append(float(pt.y()));
dest.append(float(pt.z()));
}
void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest)
{
forAll(source, i)
{
dest.append(source[i]);
}
}
void Foam::writeFuns::insert
(
const List<scalar>& source,
DynamicList<floatScalar>& dest
)
{
forAll(source, i)
{
dest.append(float(source[i]));
}
}
void Foam::writeFuns::insert
(
const labelList& map,
const List<scalar>& source,
DynamicList<floatScalar>& dest
)
{
forAll(map, i)
{
dest.append(float(source[map[i]]));
}
}
void Foam::writeFuns::insert
(
const List<point>& source,
DynamicList<floatScalar>& dest
)
{
forAll(source, i)
{
insert(source[i], dest);
}
}
void Foam::writeFuns::insert
(
const labelList& map,
const List<point>& source,
DynamicList<floatScalar>& dest
)
{
forAll(map, i)
{
insert(source[map[i]], dest);
}
}
// ************************************************************************* //

View File

@ -1,127 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
Class
Foam::writeFuns
Description
Various functions for collecting and writing binary data.
The LITTLE_ENDIAN is based on 32bit words.
It is not clear how 64bit labels should be handled, currently they are
split into two 32bit words and swapWord applied to these two.
writeFuns should be a namespace rather than a class.
SourceFiles
writeFuns.C
\*---------------------------------------------------------------------------*/
#ifndef writeFuns_H
#define writeFuns_H
#include "labelList.H"
#include "floatScalar.H"
#include "OFstream.H"
#include "DynamicList.H"
#include "point.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class writeFuns Declaration
\*---------------------------------------------------------------------------*/
class writeFuns
{
// Private member functions
//- Swap halves of word
static void swapWord(int32_t& word32);
//- Swap halves of word
static void swapWords(const label nWords, int32_t* words32);
public:
//- Write floats ascii or binary.
// If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, DynamicList<floatScalar>&);
//- Write labels ascii or binary.
// If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, DynamicList<label>&);
//- Write floats ascii or binary.
// If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, List<floatScalar>&);
//- Write labels ascii or binary.
// If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, labelList&);
//- Append point to given DynamicList
static void insert(const point&, DynamicList<floatScalar>& dest);
//- Append elements of labelList to given DynamicList
static void insert(const labelList&, DynamicList<label>&);
//- Append elements of scalarList to given DynamicList
static void insert(const List<scalar>&, DynamicList<floatScalar>&);
//- Append elements of scalarList to given DynamicList using map
static void insert
(
const labelList& map,
const List<scalar>& source,
DynamicList<floatScalar>&
);
//- Append points to given DynamicList of floats
static void insert(const List<point>& source, DynamicList<floatScalar>&);
//- Append points to given DynamicList of floats using map
static void insert
(
const labelList& map,
const List<point>& source,
DynamicList<floatScalar>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,127 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "writePatch.H"
#include "OFstream.H"
#include "writeFuns.H"
#include "primitiveFacePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void writePatch
(
const bool binary,
const word& setName,
const primitiveFacePatch& fp,
const word& fieldName,
labelList& fieldValues,
const fileName& fileName
)
{
std::ofstream pStream(fileName.c_str());
pStream
<< "# vtk DataFile Version 2.0" << std::endl
<< setName << std::endl;
if (binary)
{
pStream << "BINARY" << std::endl;
}
else
{
pStream << "ASCII" << std::endl;
}
pStream << "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------
//
// Write topology
//
//------------------------------------------------------------------
// Write points and faces as polygons
pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*fp.nPoints());
writeFuns::insert(fp.localPoints(), ptField);
writeFuns::write(pStream, binary, ptField);
label nFaceVerts = 0;
forAll(fp.localFaces(), facei)
{
nFaceVerts += fp.localFaces()[facei].size() + 1;
}
pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
<< std::endl;
DynamicList<label> vertLabels(nFaceVerts);
forAll(fp.localFaces(), facei)
{
const face& f = fp.localFaces()[facei];
vertLabels.append(f.size());
writeFuns::insert(f, vertLabels);
}
writeFuns::write(pStream, binary, vertLabels);
//-----------------------------------------------------------------
//
// Write data
//
//-----------------------------------------------------------------
// Write faceID
pStream
<< "CELL_DATA " << fp.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// Cell ids first
pStream << fieldName << " 1 " << fp.size() << " int" << std::endl;
writeFuns::write(pStream, binary, fieldValues);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -266,6 +266,10 @@ meshStructure/meshStructure.C
meshStructure/topoDistanceData.C
meshStructure/pointTopoDistanceData.C
output/foamVtkWriteFaceSet.C
output/foamVtkWritePointSet.C
output/foamVtkWriteCellSetFaces.C
regionCoupled/patches/regionCoupledPolyPatch/regionCoupledBase.C
regionCoupled/patches/regionCoupledPolyPatch/regionCoupledPolyPatch.C
regionCoupled/patches/regionCoupledPolyPatch/regionCoupledWallPolyPatch.C

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "foamVtkWriteCellSetFaces.H"
#include "foamVtkOutputOptions.H"
#include "OFstream.H"
#include "primitiveMesh.H"
#include "cellSet.H"
#include "uindirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::writeCellSetFaces
(
const bool binary,
const primitiveMesh& mesh,
const cellSet& set,
const fileName& fileName
)
{
std::ofstream os(fileName.c_str());
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
//-------------------------------------------------------------------------
// External faces of cellset with OpenFOAM cellID as value
Map<label> cellFaces(2*set.size());
forAllConstIters(set, iter)
{
label celli = iter.key();
const cell& cFaces = mesh.cells()[celli];
forAll(cFaces, i)
{
label facei = cFaces[i];
if (mesh.isInternalFace(facei))
{
label otherCelli = mesh.faceOwner()[facei];
if (otherCelli == celli)
{
otherCelli = mesh.faceNeighbour()[facei];
}
if (!set.found(otherCelli))
{
cellFaces.insert(facei, celli);
}
}
else
{
cellFaces.insert(facei, celli);
}
}
}
labelList faceLabels = cellFaces.sortedToc();
labelList faceValues(cellFaces.size());
forAll(faceLabels, facei)
{
faceValues[facei] = cellFaces[faceLabels[facei]]; // Cell ID
}
uindirectPrimitivePatch pp
(
UIndirectList<face>(mesh.faces(), faceLabels),
mesh.points()
);
//-------------------------------------------------------------------------
// Write points and faces as polygons
os << "POINTS " << pp.nPoints() << " float" << nl;
foamVtkOutput::writeList(format(), pp.localPoints());
format().flush();
label count = pp.size();
forAll(pp, facei)
{
count += pp.localFaces()[facei].size();
}
os << "POLYGONS " << pp.size() << ' ' << count << nl;
forAll(pp, facei)
{
const face& f = pp.localFaces()[facei];
format().write(f.size());
foamVtkOutput::writeList(format(), f);
}
format().flush();
// Write data - faceId/cellId
foamVtkOutput::legacy::cellDataHeader(os, pp.size(), 1);
os << "cellID 1 " << pp.size() << " int" << nl;
foamVtkOutput::writeList(format(), faceValues);
format().flush();
}
// ************************************************************************* //

View File

@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
InNamespace
Foam::foamVtkOutput
Description
Write faces of cellSet to vtk polydata file.
The data are the original cell ids
SourceFiles
foamVtkWriteCellSetFaces.C
\*---------------------------------------------------------------------------*/
#ifndef foamVtkWriteCellSetFaces_H
#define foamVtkWriteCellSetFaces_H
#include "primitiveMesh.H"
#include "uindirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class primitiveMesh;
class cellSet;
class fileName;
namespace foamVtkOutput
{
//- Write perimeter faces of cellset to vtk polydata file.
// The data are the original cell ids
void writeCellSetFaces
(
const bool binary,
const primitiveMesh& mesh,
const cellSet& set,
const fileName& fileName
);
} // End namespace foamVtkOutput
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -23,83 +23,75 @@ License
\*---------------------------------------------------------------------------*/
#include "writePointSet.H"
#include "foamVtkWriteFaceSet.H"
#include "foamVtkOutputOptions.H"
#include "OFstream.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
#include "primitiveMesh.H"
#include "faceSet.H"
#include "uindirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void writePointSet
void Foam::foamVtkOutput::writeFaceSet
(
const bool binary,
const primitiveMesh& mesh,
const topoSet& set,
const faceSet& set,
const fileName& fileName
)
{
std::ofstream pStream(fileName.c_str());
std::ofstream os(fileName.c_str());
pStream
<< "# vtk DataFile Version 2.0" << std::endl
<< set.name() << std::endl;
if (binary)
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
//-------------------------------------------------------------------------
// Faces of set with OpenFOAM faceID as value
labelList faceLabels = set.sortedToc();
uindirectPrimitivePatch pp
(
UIndirectList<face>(mesh.faces(), faceLabels),
mesh.points()
);
//-------------------------------------------------------------------------
// Write points and faces as polygons
os << "POINTS " << pp.nPoints() << " float" << nl;
foamVtkOutput::writeList(format(), pp.localPoints());
format().flush();
label count = pp.size();
forAll(pp, facei)
{
pStream << "BINARY" << std::endl;
count += pp.localFaces()[facei].size();
}
else
os << "POLYGONS " << pp.size() << ' ' << count << nl;
forAll(pp, facei)
{
pStream << "ASCII" << std::endl;
const face& f = pp.localFaces()[facei];
format().write(f.size());
foamVtkOutput::writeList(format(), f);
}
pStream << "DATASET POLYDATA" << std::endl;
format().flush();
// Write data - faceId/cellId
os << "faceID 1 " << pp.size() << " int" << nl;
//------------------------------------------------------------------
//
// Write topology
//
//------------------------------------------------------------------
labelList pointLabels(set.toc());
pointField setPoints(mesh.points(), pointLabels);
// Write points
pStream << "POINTS " << pointLabels.size() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*pointLabels.size());
writeFuns::insert(setPoints, ptField);
writeFuns::write(pStream, binary, ptField);
//-----------------------------------------------------------------
//
// Write data
//
//-----------------------------------------------------------------
// Write pointID
pStream
<< "POINT_DATA " << pointLabels.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// Cell ids first
pStream << "pointID 1 " << pointLabels.size() << " int" << std::endl;
writeFuns::write(pStream, binary, pointLabels);
foamVtkOutput::writeList(format(), faceLabels);
format().flush();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -22,38 +22,43 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InNamespace
Foam
Foam::foamVtkOutput
Description
Write pointSet to vtk polydata file. Only one data which is original
pointID.
Write faceSet to vtk polydata file.
The data are the original point ids.
SourceFiles
writePointSet.C
foamVtkWritePointSet.C
\*---------------------------------------------------------------------------*/
#ifndef writePointSet_H
#define writePointSet_H
#include "primitiveMesh.H"
#include "pointSet.H"
#ifndef foamVtkWriteFaceSet_H
#define foamVtkWriteFaceSet_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class primitiveMesh;
class faceSet;
class fileName;
namespace foamVtkOutput
{
//- Write pointSet to vtk polydata file.
// Only one data which is original pointID.
void writePointSet
void writeFaceSet
(
const bool binary,
const primitiveMesh& mesh,
const topoSet& set,
const faceSet& set,
const fileName& fileName
);
} // End namespace foamVtkOutput
} // End namespace Foam

View File

@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "foamVtkWritePointSet.H"
#include "foamVtkOutputOptions.H"
#include "OFstream.H"
#include "primitiveMesh.H"
#include "pointSet.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::writePointSet
(
const bool binary,
const primitiveMesh& mesh,
const pointSet& set,
const fileName& fileName
)
{
std::ofstream os(fileName.c_str());
autoPtr<foamVtkOutput::formatter> format =
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl;
//-------------------------------------------------------------------------
const labelList pointLabels(set.sortedToc());
// Write points
os << "POINTS " << pointLabels.size() << " float" << nl;
foamVtkOutput::writeList(format(), mesh.points(), pointLabels);
format().flush();
// Write data - pointID
foamVtkOutput::legacy::pointDataHeader(os, pointLabels.size(), 1);
os << "pointID 1 " << pointLabels.size() << " int" << nl;
foamVtkOutput::writeList(format(), pointLabels);
format().flush();
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -21,40 +21,44 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InClass
Foam::writePatch
InNamespace
Foam::foamVtkOutput
Description
Write faceSet to vtk polydata file. Only one data which is original
faceID.
Write pointSet to vtk polydata file.
The data are the original point ids.
SourceFiles
writePatch.C
foamVtkWritePointSet.C
\*---------------------------------------------------------------------------*/
#ifndef writePatch_H
#define writePatch_H
#include "primitiveMesh.H"
#include "primitiveFacePatch.H"
#ifndef foamVtkWritePointSet_H
#define foamVtkWritePointSet_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class primitiveMesh;
class pointSet;
class fileName;
// Write faceSet
void writePatch
namespace foamVtkOutput
{
//- Write pointSet to vtk polydata file.
// The data are the original point ids.
void writePointSet
(
const bool binary,
const word& setName,
const primitiveFacePatch& fp,
const word& fieldName,
labelList& fieldValues,
const primitiveMesh& mesh,
const pointSet& set,
const fileName& fileName
);
} // End namespace foamVtkOutput
} // End namespace Foam