mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add VTP, VTU output for most vtk writers (insitu only)
- 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
This commit is contained in:
@ -65,7 +65,7 @@ Foam::foamVtkOutput::formatter::xmlHeader()
|
||||
|
||||
|
||||
Foam::foamVtkOutput::formatter&
|
||||
Foam::foamVtkOutput::formatter::comment(const std::string& text)
|
||||
Foam::foamVtkOutput::formatter::xmlComment(const std::string& comment)
|
||||
{
|
||||
if (inTag_)
|
||||
{
|
||||
@ -75,7 +75,7 @@ Foam::foamVtkOutput::formatter::comment(const std::string& text)
|
||||
}
|
||||
|
||||
indent();
|
||||
os_ << "<!-- " << text << " -->" << nl;
|
||||
os_ << "<!-- " << comment << " -->" << nl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public:
|
||||
|
||||
//- Write XML comment (at the current indentation level)
|
||||
// \return formatter for chaining
|
||||
formatter& comment(const std::string& text);
|
||||
formatter& xmlComment(const std::string& comment);
|
||||
|
||||
|
||||
//- Open XML tag
|
||||
|
||||
@ -36,15 +36,11 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Static Data * * * * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::Enum<Foam::foamVtkOutput::legacy::textElemType>
|
||||
Foam::foamVtkOutput::legacy::textNames
|
||||
const Foam::Enum<Foam::vtkFileTag>
|
||||
Foam::foamVtkOutput::legacy::contentNames
|
||||
{
|
||||
{ textElemType::POINTS, "POINTS" },
|
||||
{ textElemType::CELLS, "CELLS" },
|
||||
{ textElemType::POLYS, "POLYGONS" },
|
||||
{ textElemType::VERTS, "VERTICES" },
|
||||
{ textElemType::POLY_DATA, "POLYDATA" },
|
||||
{ textElemType::UNSTRUCTURED_GRID, "UNSTRUCTURED_GRID" },
|
||||
{ vtkFileTag::POLY_DATA, "POLYDATA" },
|
||||
{ vtkFileTag::UNSTRUCTURED_GRID, "UNSTRUCTURED_GRID" },
|
||||
};
|
||||
|
||||
|
||||
@ -128,66 +124,23 @@ Foam::label Foam::foamVtkOutput::writeVtmFile
|
||||
}
|
||||
|
||||
|
||||
std::ostream& Foam::foamVtkOutput::legacy::fileHeader
|
||||
(
|
||||
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::fileHeader
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const std::string& title
|
||||
const std::string& title,
|
||||
const std::string& contentType
|
||||
)
|
||||
{
|
||||
return fileHeader(fmt.os(), title, isType<legacyRawFormatter>(fmt));
|
||||
}
|
||||
std::ostream& os = fmt.os();
|
||||
|
||||
|
||||
std::ostream& Foam::foamVtkOutput::legacy::dataHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const vtkFileTag& dataTypeTag,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
)
|
||||
{
|
||||
os << dataTypeNames[dataTypeTag] << ' ' << nEntries << nl
|
||||
<< "FIELD attributes " << nFields << nl;
|
||||
fileHeader(os, title, isType<legacyRawFormatter>(fmt));
|
||||
if (!contentType.empty())
|
||||
{
|
||||
os << "DATASET " << contentType.c_str() << nl;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& Foam::foamVtkOutput::legacy::cellDataHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
)
|
||||
{
|
||||
return dataHeader(os, vtkFileTag::CELL_DATA, nEntries, nFields);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& Foam::foamVtkOutput::legacy::pointDataHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
)
|
||||
{
|
||||
return dataHeader(os, vtkFileTag::POINT_DATA, nEntries, nFields);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -32,7 +32,7 @@ Namespace
|
||||
Foam::foamVtkOutput::legacy
|
||||
|
||||
Description
|
||||
Namespace for legacy VTK output functions.
|
||||
Namespace for legacy VTK output constants and functions.
|
||||
|
||||
SourceFiles
|
||||
foamVtkOutput.C
|
||||
@ -65,6 +65,9 @@ namespace foamVtkOutput
|
||||
typedef formatter::headerType headerType;
|
||||
|
||||
|
||||
// Constants
|
||||
|
||||
|
||||
// General Functions
|
||||
|
||||
//- Return a default asciiFormatter
|
||||
@ -101,6 +104,15 @@ namespace foamVtkOutput
|
||||
const UList<Type>& lst
|
||||
);
|
||||
|
||||
//- Write a list of values.
|
||||
// The output does not include the payload size.
|
||||
template<class Type, unsigned Size>
|
||||
void writeList
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const FixedList<Type, Size>& lst
|
||||
);
|
||||
|
||||
|
||||
//- Write a list of values via indirect addressing.
|
||||
// The output does not include the payload size.
|
||||
@ -120,49 +132,68 @@ namespace foamVtkOutput
|
||||
//- Some minimal additional support for writing legacy files
|
||||
namespace legacy
|
||||
{
|
||||
//- Some standard text elements for legacy vtk files
|
||||
enum class textElemType
|
||||
{
|
||||
POINTS, //!< "POINTS"
|
||||
CELLS, //!< "CELLS"
|
||||
POLYS, //!< "POLYGONS"
|
||||
VERTS, //!< "VERTICES"
|
||||
POLY_DATA, //!< "POLYDATA"
|
||||
UNSTRUCTURED_GRID, //!< "UNSTRUCTURED_GRID"
|
||||
};
|
||||
|
||||
//- Strings corresponding to the elements
|
||||
extern const Foam::Enum<textElemType> textNames;
|
||||
// Constants
|
||||
|
||||
//- Strings corresponding to the elements
|
||||
extern const Foam::Enum<vtkFileTag> dataTypeNames;
|
||||
//- Strings corresponding to the (POLYDATA, UNSTRUCTURED_GRID) elements
|
||||
extern const Foam::Enum<vtkFileTag> contentNames;
|
||||
|
||||
//- Strings corresponding to the (CELL_DATA, POINT_DATA) elements
|
||||
extern const Foam::Enum<vtkFileTag> dataTypeNames;
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
//- Emit header for legacy file.
|
||||
// Writes "ASCII" or "BINARY" depending on specified type.
|
||||
std::ostream& fileHeader
|
||||
inline std::ostream& fileHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const std::string& title,
|
||||
const bool binary = false
|
||||
const bool binary
|
||||
);
|
||||
|
||||
//- Emit header for legacy file.
|
||||
// Writes "ASCII" or "BINARY" depending on the formatter type.
|
||||
//- Emit header for legacy file, with "ASCII" or "BINARY" depending on
|
||||
// the formatter type.
|
||||
// Includes "DATASET" with the specified dataset type.
|
||||
inline void fileHeader
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const std::string& title,
|
||||
const vtkFileTag& contentTypeTag
|
||||
);
|
||||
|
||||
//- Emit header for legacy file, with "ASCII" or "BINARY" depending on
|
||||
// the formatter type.
|
||||
// If the contentType is non-empty, it is used for "DATASET" line.
|
||||
std::ostream& fileHeader
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const std::string& title
|
||||
const std::string& title,
|
||||
const std::string& contentType
|
||||
);
|
||||
|
||||
|
||||
//- Emit header for legacy CELL_DATA or POINT_DATA, corresponding to the
|
||||
// enumeration textElemType::CELLS or textElemType::POINTS, respectively.
|
||||
//- Emit header for POINTS (with trailing newline).
|
||||
inline void beginPoints(std::ostream& os, const label nPoints);
|
||||
|
||||
//- Emit header for POLYGONS (with trailing newline).
|
||||
// The nConnectivity is the sum of all connectivity points used,
|
||||
// but \b without additional space for the size prefixes.
|
||||
// The additional prefix sizes are added internally.
|
||||
inline void beginPolys
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nPolys,
|
||||
const label nConnectivity
|
||||
);
|
||||
|
||||
|
||||
//- Use the enumerations vtkFileTag::CELL_DATA, vtkFileTag::POINT_DATA,
|
||||
// to emit a legacy CELL_DATA, POINT_DATA element.
|
||||
// The nEntries corresponds similarly to the number of cells or points,
|
||||
// respectively.
|
||||
std::ostream& dataHeader
|
||||
inline void dataHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const vtkFileTag& dataTypeTag,
|
||||
@ -170,62 +201,36 @@ namespace legacy
|
||||
const label nFields
|
||||
);
|
||||
|
||||
//- Emit header for legacy CELL_DATA.
|
||||
// The nEntries should normally correspond to the number of cells.
|
||||
std::ostream& cellDataHeader
|
||||
//- Start output of float field with the specified name.
|
||||
inline void floatField
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
const word& name,
|
||||
const label nCmpt,
|
||||
const label nEntries
|
||||
);
|
||||
|
||||
//- Emit header for legacy POINT_DATA
|
||||
// The nEntries should normally correspond to the number of points.
|
||||
std::ostream& pointDataHeader
|
||||
//- Start output of int field with the specified name.
|
||||
inline void intField
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
const word& name,
|
||||
const label nCmpt,
|
||||
const label nEntries
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Template specialization for label
|
||||
template<>
|
||||
inline void write<label>(foamVtkOutput::formatter& fmt, const label& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
|
||||
//- Template specialization for float
|
||||
template<>
|
||||
inline void write<float>(foamVtkOutput::formatter& fmt, const float& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
|
||||
//- Template specialization for double
|
||||
template<>
|
||||
inline void write<double>(foamVtkOutput::formatter& fmt, const double& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
} // End namespace foamVtkOutput
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "foamVtkOutputI.H"
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "foamVtkOutputTemplates.C"
|
||||
#endif
|
||||
|
||||
146
src/fileFormats/vtk/output/foamVtkOutputI.H
Normal file
146
src/fileFormats/vtk/output/foamVtkOutputI.H
Normal file
@ -0,0 +1,146 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace foamVtkOutput
|
||||
{
|
||||
|
||||
//- Template specialization for label
|
||||
template<>
|
||||
inline void write<label>(foamVtkOutput::formatter& fmt, const label& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
|
||||
//- Template specialization for float
|
||||
template<>
|
||||
inline void write<float>(foamVtkOutput::formatter& fmt, const float& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
|
||||
//- Template specialization for double
|
||||
template<>
|
||||
inline void write<double>(foamVtkOutput::formatter& fmt, const double& val)
|
||||
{
|
||||
fmt.write(val);
|
||||
}
|
||||
|
||||
} // End namespace foamVtkOutput
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
inline std::ostream& Foam::foamVtkOutput::legacy::fileHeader
|
||||
(
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::fileHeader
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const std::string& title,
|
||||
const vtkFileTag& contentTypeTag
|
||||
)
|
||||
{
|
||||
fileHeader(fmt, title, contentNames[contentTypeTag]);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::beginPoints
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nPoints
|
||||
)
|
||||
{
|
||||
os << "POINTS " << nPoints << " float" << nl;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::beginPolys
|
||||
(
|
||||
std::ostream& os,
|
||||
const label nPolys,
|
||||
const label nConnectivity
|
||||
)
|
||||
{
|
||||
os << "POLYGONS " << nPolys << ' ' << (nPolys + nConnectivity) << nl;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::dataHeader
|
||||
(
|
||||
std::ostream& os,
|
||||
const vtkFileTag& dataTypeTag,
|
||||
const label nEntries,
|
||||
const label nFields
|
||||
)
|
||||
{
|
||||
os << dataTypeNames[dataTypeTag] << ' ' << nEntries << nl
|
||||
<< "FIELD attributes " << nFields << nl;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::floatField
|
||||
(
|
||||
std::ostream& os,
|
||||
const word& fieldName,
|
||||
const label nCmpt,
|
||||
const label nEntries
|
||||
)
|
||||
{
|
||||
os << fieldName << ' ' << nCmpt << ' ' << nEntries << " float" << nl;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::foamVtkOutput::legacy::intField
|
||||
(
|
||||
std::ostream& os,
|
||||
const word& fieldName,
|
||||
const label nCmpt,
|
||||
const label nEntries
|
||||
)
|
||||
{
|
||||
os << fieldName << ' ' << nCmpt << ' ' << nEntries << " int" << nl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -53,6 +53,20 @@ void Foam::foamVtkOutput::writeList
|
||||
}
|
||||
|
||||
|
||||
template<class Type, unsigned Size>
|
||||
void Foam::foamVtkOutput::writeList
|
||||
(
|
||||
foamVtkOutput::formatter& fmt,
|
||||
const FixedList<Type, Size>& lst
|
||||
)
|
||||
{
|
||||
for (unsigned i=0; i<Size; ++i)
|
||||
{
|
||||
write(fmt, lst[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::foamVtkOutput::writeList
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user