diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options index d0cdd781d7..9f63402d64 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/Make/options @@ -3,6 +3,8 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/conversion/lnInclude \ -I$(ParaView_INCLUDE_DIR) \ -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ -I../../vtkPVReaders/lnInclude \ @@ -10,7 +12,7 @@ EXE_INC = \ LIB_LIBS = \ -ldynamicMesh \ - -ldynamicMesh \ + -lconversion \ -lgenericPatchFields \ -llagrangian \ -L$(FOAM_LIBBIN) -lvtkPVReaders \ diff --git a/src/conversion/Make/files b/src/conversion/Make/files index 0266423e35..3f2c0a0c98 100644 --- a/src/conversion/Make/files +++ b/src/conversion/Make/files @@ -24,4 +24,7 @@ starcd/STARCDMeshWriter.C polyDualMesh/polyDualMesh.C +vtk/part/foamVtkCells.C +vtk/output/foamVtkOutput.C + LIB = $(FOAM_LIBBIN)/libconversion diff --git a/src/conversion/vtk/output/foamVtkOutput.C b/src/conversion/vtk/output/foamVtkOutput.C new file mode 100644 index 0000000000..4ece681a85 --- /dev/null +++ b/src/conversion/vtk/output/foamVtkOutput.C @@ -0,0 +1,126 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkOutput.H" +#include "foamVtkAsciiFormatter.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::word Foam::foamVtkOutput::legacy::EXT = "vtk"; + + +//! \cond fileScope +static inline std::ostream& legacyDataHeader +( + std::ostream& os, + const char* tag, + const Foam::label nItems, + const Foam::label nFields +) +{ + os << tag << ' ' << nItems << '\n' + << "FIELD attributes " << nFields << '\n'; + + return os; +} +//! \endcond + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::label Foam::foamVtkOutput::writeVtmFile +( + std::ostream& os, + const UList& files +) +{ + const word& content = "vtkMultiBlockDataSet"; + + foamVtkAsciiFormatter vtmFile(os); + + vtmFile + .xmlHeader() + .openTag("VTKFile") + ( "type", content ) + ( "version", "1.0" ) + ( "byte_order", foamVtkFormatter::byteOrder ) + ( "header_type", foamVtkFormatter::headerType ) + .closeTag(); + + vtmFile.tag(content); + + forAll(files, i) + { + vtmFile + .openTag("DataSet") + ( "index", i ) + ( "file", files[i] ) + .closeTag(true); + } + + vtmFile.endTag(content).endTag("VTKFile"); + + return files.size(); +} + + +std::ostream& Foam::foamVtkOutput::legacy::writeHeader +( + std::ostream& os, + const std::string& title, + const bool binary +) +{ + os << "# vtk DataFile Version 2.0" << nl + << title << nl + << (binary ? "BINARY" : "ASCII") << nl; + + return os; +} + + +std::ostream& Foam::foamVtkOutput::legacy::writeCellDataHeader +( + std::ostream& os, + const label nCells, + const label nFields +) +{ + return legacyDataHeader(os, "CELL_DATA", nCells, nFields); +} + + +std::ostream& Foam::foamVtkOutput::legacy::writePointDataHeader +( + std::ostream& os, + const label nPoints, + const label nFields +) +{ + return legacyDataHeader(os, "POINT_DATA", nPoints, nFields); +} + + +// ************************************************************************* // diff --git a/src/conversion/vtk/output/foamVtkOutput.H b/src/conversion/vtk/output/foamVtkOutput.H new file mode 100644 index 0000000000..ad7964bfff --- /dev/null +++ b/src/conversion/vtk/output/foamVtkOutput.H @@ -0,0 +1,216 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 . + +Class + foamVtkOutput + +Description + A collection of functions for writing vtk file content. + +SourceFiles + foamVtkOutput.C + foamVtkOutputTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtkOutput_H +#define foamVtkOutput_H + +#include "floatScalar.H" +#include "volFields.H" +#include "foamVtkFormatter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class foamVtkOutput Declaration +\*---------------------------------------------------------------------------*/ + +class foamVtkOutput +{ + // Private Member Functions + + //- Disallow construction + foamVtkOutput() = delete; + +public: + + // Forward declarations + class legacy; + + + // Static Members + + //- Write vtm datasets for specified files + static Foam::label writeVtmFile + ( + std::ostream& os, + const UList& files + ); + + + //- Write a value component-wise. + template + inline static void write(foamVtkFormatter&, const Type&); + + + //- Write a list of values. + // The output does not include the payload size. + template + static void writeList + ( + foamVtkFormatter&, + const UList& + ); + + + //- Write a list of values via indirect addressing. + // The output does not include the payload size. + template + static void writeList + ( + foamVtkFormatter&, + const UList&, + const UList