Commit 11ff01f4 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: refactor vtk::internalWriter, vtk::patchWriter

- new vtk::internalMeshWriter, vtk::patchMeshWriter
  intermediate classes without finiteVolume dependencies.

  Enables direct use with a polyMesh.
  Makes vtk::internalWriter, vtk::patchWriter header/template only.
parent ea4c8f4b
......@@ -16,8 +16,6 @@ starcd/STARCDMeshWriter.C
polyDualMesh/polyDualMesh.C
vtk/output/foamVtkInternalWriter.H
vtk/output/foamVtkPatchWriter.H
vtk/output/foamVtkSurfaceFieldWriter.C
LIB = $(FOAM_LIBBIN)/libconversion
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -40,8 +40,10 @@ Note
In the future, the duplicate points at processor connections
may be addressed using ghost points.
See Also
Foam::vtk::internalMeshWriter
SourceFiles
foamVtkInternalWriter.C
foamVtkInternalWriterTemplates.C
\*---------------------------------------------------------------------------*/
......@@ -49,8 +51,7 @@ SourceFiles
#ifndef foamVtkInternalWriter_H
#define foamVtkInternalWriter_H
#include "foamVtkFileWriter.H"
#include "foamVtuCells.H"
#include "foamVtkInternalMeshWriter.H"
#include "volFields.H"
#include "pointFields.H"
......@@ -59,7 +60,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class volPointInterpolation;
namespace vtk
......@@ -71,44 +72,10 @@ namespace vtk
class internalWriter
:
public vtk::fileWriter
public vtk::internalMeshWriter
{
// Private Member Data
//- Reference to the OpenFOAM mesh (or subset)
const fvMesh& mesh_;
//- The volume cells (internalMesh)
const vtuCells& vtuCells_;
//- The number of field points for the current Piece
label numberOfPoints_;
//- The number of field cells for the current Piece
label numberOfCells_;
// Private Member Functions
//- Begin piece
void beginPiece();
//- Write mesh points
void writePoints();
//- Write cells (connectivity and type), legacy format
// \param pointOffset processor-local point offset
void writeCellsLegacy(const label pointOffset);
//- Write cells connectivity
// \param pointOffset processor-local point offset
void writeCellsConnectivity(const label pointOffset);
//- Write cells face streams
// \param pointOffset processor-local point offset
void writeCellsFaces(const label pointOffset);
//- No copy construct
internalWriter(const internalWriter&) = delete;
......@@ -118,43 +85,46 @@ class internalWriter
public:
//- Debug information
static int debug;
//- File extension for given output type
// constexpr static vtk::fileTag content = vtk::fileTag::UNSTRUCTURED_GRID;
// Constructors
//- Construct from components (default format INLINE_BASE64),
internalWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const vtk::vtuCells& cells,
const vtk::outputOptions opts = vtk::formatType::INLINE_BASE64
);
)
:
vtk::internalMeshWriter(mesh, cells, opts)
{}
//- Construct from components (default format INLINE_BASE64),
// The file name is with/without an extension.
internalWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const vtk::vtuCells& cells,
const fileName& file,
bool parallel = Pstream::parRun()
);
)
:
vtk::internalMeshWriter(mesh, cells, file, parallel)
{}
//- Construct from components (default format INLINE_BASE64),
// The file name is with/without an extension.
internalWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const vtk::vtuCells& cells,
const vtk::outputOptions opts,
const fileName& file,
bool parallel = Pstream::parRun()
);
)
:
vtk::internalMeshWriter(mesh, cells, opts, file, parallel)
{}
//- Destructor
......@@ -163,63 +133,8 @@ public:
// Member Functions
//- File extension for current format type.
using vtk::fileWriter::ext;
//- File extension for given output type
inline static word ext(vtk::outputOptions opts)
{
return opts.ext(vtk::fileTag::UNSTRUCTURED_GRID);
}
//- Write file header (non-collective)
// \note Expected calling states: (OPENED)
virtual bool beginFile(std::string title = "");
//- Write mesh topology.
// Also writes the file header if not previously written.
// \note Must be called prior to writing CellData or PointData
virtual bool writeGeometry();
//- Begin CellData output section for specified number of fields.
// Must be called prior to writing any cell data fields.
// \param nFields is for legacy format only.
// When nFields=0, this a no-op for legacy format.
// \note Expected calling states: (PIECE | POINT_DATA).
//
// \return True if the state changed
virtual bool beginCellData(label nFields = 0);
//- Begin PointData for specified number of fields.
// Must be called prior to writing any point data fields.
// \param nFields is for legacy format only.
// When nFields=0, this a no-op for legacy format.
// \note Expected calling states: (PIECE | CELL_DATA).
//
// \return True if the state changed
virtual bool beginPointData(label nFields = 0);
//- Write cell ids as CellData.
// Must be called within the CELL_DATA state.
void writeCellIDs();
//- Write processor ids as CellData. This is no-op in serial.
// Must be called within the CELL_DATA state.
bool writeProcIDs();
//- Write point ids as PointData.
// Must be called within the POINT_DATA state.
void writePointIDs();
// Write
//- Write a uniform field of Cell or Point values
template<class Type>
void writeUniform(const word& fieldName, const Type& val);
//- Write point field
// Interpolate to originating cell centre for decomposed cells.
template<class Type, template<class> class PatchField>
......@@ -228,7 +143,7 @@ public:
const GeometricField<Type, PatchField, pointMesh>& field
);
//- Write the internal field
//- Write the internal field (CellData)
template<class Type>
void write
(
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -32,33 +32,6 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtk::internalWriter::writeUniform
(
const word& fieldName,
const Type& val
)
{
if (isState(outputState::CELL_DATA))
{
++nCellData_;
vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfCells_);
}
else if (isState(outputState::POINT_DATA))
{
++nPointData_;
vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfPoints_);
}
else
{
WarningInFunction
<< "Ignore bad writer state (" << stateNames[state_]
<< ") for field " << fieldName << nl << endl
<< exit(FatalError);
}
}
template<class Type, template<class> class PatchField>
void Foam::vtk::internalWriter::write
(
......@@ -135,53 +108,7 @@ void Foam::vtk::internalWriter::write
const DimensionedField<Type, volMesh>& field
)
{
if (isState(outputState::CELL_DATA))
{
++nCellData_;
}
else
{
FatalErrorInFunction
<< "Bad writer state (" << stateNames[state_]
<< ") - should be (" << stateNames[outputState::CELL_DATA]
<< ") for field " << field.name() << nl << endl
<< exit(FatalError);
}
const direction nCmpt(pTraits<Type>::nComponents);
const labelList& cellMap = vtuCells_.cellMap();
if (format_)
{
if (legacy())
{
legacy::floatField<nCmpt>(format(), field.name(), numberOfCells_);
}
else
{
const uint64_t payLoad =
vtk::sizeofData<float, nCmpt>(numberOfCells_);
format().beginDataArray<float, nCmpt>(field.name());
format().writeSize(payLoad);
}
}
if (parallel_)
{
vtk::writeListParallel(format_.ref(), field, cellMap);
}
else
{
vtk::writeList(format(), field, cellMap);
}
if (format_)
{
format().flush();
format().endDataArray();
}
writeCellData(field.name(), field.field());
}
......@@ -191,7 +118,7 @@ void Foam::vtk::internalWriter::write
const GeometricField<Type, PatchField, volMesh>& field
)
{
write(field.internalField());
writeCellData(field.name(), field.primitiveField());
}
......@@ -221,7 +148,7 @@ void Foam::vtk::internalWriter::write
// Use tmp intermediate. Compiler sometimes weird otherwise.
tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
const PointFieldType& pfield = tfield();
const auto& pfield = tfield();
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
......@@ -290,7 +217,7 @@ void Foam::vtk::internalWriter::write
// Use tmp intermediate. Compiler sometimes weird otherwise.
tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
const PointFieldType& pfield = tfield();
const auto& pfield = tfield();
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -39,8 +39,10 @@ Note
In the future, the duplicate points at processor connections
may be addressed using ghost points.
See Also
Foam::vtk::patchMeshWriter
SourceFiles
foamVtkPatchWriter.C
foamVtkPatchWriterTemplates.C
\*---------------------------------------------------------------------------*/
......@@ -48,7 +50,7 @@ SourceFiles
#ifndef foamVtkPatchWriter_H
#define foamVtkPatchWriter_H
#include "foamVtkFileWriter.H"
#include "foamVtkPatchMeshWriter.H"
#include "volFields.H"
#include "pointFields.H"
#include "PrimitivePatchInterpolation.H"
......@@ -66,53 +68,16 @@ namespace vtk
class patchWriter
:
public vtk::fileWriter
public vtk::patchMeshWriter
{
// Private Member Data
//- Reference to the OpenFOAM mesh (or subset)
const fvMesh& mesh_;
//- The selected patch ids
labelList patchIDs_;
//- Use internal field value instead of patch value
bool useNearCellValue_;
//- The number of field points for the current Piece
label numberOfPoints_;
//- The number of field cells (faces) for the current Piece
label numberOfCells_;
//- Local number of points
label nLocalPoints_;
//- Local number of faces
label nLocalFaces_;
//- Local face vertices (connectivity) count. Sum of face sizes.
label nLocalVerts_;
// Private Member Functions
//- Determine sizes (nLocalPoints_, nLocalFaces_, nLocalVerts_),
//- and begin piece.
void beginPiece();
//- Write patch points
void writePoints();
//- Write patch faces, legacy format
// \param pointOffset processor-local point offset
void writePolysLegacy(const label pointOffset);
//- Write patch faces
// \param pointOffset processor-local point offset
void writePolys(const label pointOffset);
//- No copy construct
patchWriter(const patchWriter&) = delete;
......@@ -125,50 +90,68 @@ public:
// Constructors
//- Construct from components (default format INLINE_BASE64)
//
// \param useNearCellValue to use cell instead of patch values
patchWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelList& patchIDs,
const vtk::outputOptions opts = vtk::formatType::INLINE_BASE64,
const bool useNearCellValue = false
);
)
:
vtk::patchMeshWriter(mesh, patchIDs, opts),
useNearCellValue_(useNearCellValue)
{}
//- Construct from components (default format INLINE_BASE64),
//- and open the file for writing.
// The file name is with/without an extension.
patchWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelList& patchIDs,
const fileName& file,
bool parallel = Pstream::parRun()
);
)
:
vtk::patchMeshWriter(mesh, patchIDs, file, parallel),
useNearCellValue_(false)
{}
//- Construct from components (default format INLINE_BASE64),
//- Construct from components and open the file for writing.
//- and open the file for writing.
// The file name is with/without an extension.
patchWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelList& patchIDs,
const vtk::outputOptions opts,
const fileName& file,
bool parallel = Pstream::parRun()
);
)
:
vtk::patchMeshWriter(mesh, patchIDs, opts, file, parallel),
useNearCellValue_(false)
{}
//- Construct from components and open the file for writing.
// The file name is with/without an extension.
//
// \param useNearCellValue to use cell instead of patch values
patchWriter
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelList& patchIDs,
const vtk::outputOptions opts,
const bool useNearCellValue,
const fileName& file,
bool parallel = Pstream::parRun()
);
)
:
vtk::patchMeshWriter(mesh, patchIDs, opts, file, parallel),
useNearCellValue_(useNearCellValue)
{}
//- Destructor
......@@ -177,68 +160,8 @@ public:
// Member Functions
//- File extension for current format type.
using vtk::fileWriter::ext;
//- File extension for given output type
inline static word ext(vtk::outputOptions opts)
{
return opts.ext(vtk::fileTag::POLY_DATA);
}
//- The patch IDs
inline const labelList& patchIDs() const
{
return patchIDs_;
}
//- Write file header (non-collective)
// \note Expected calling states: (OPENED).
virtual bool beginFile(std::string title = "");
//- Write patch topology
// Also writes the file header if not previously written.
// \note Must be called prior to writing CellData or PointData
virtual bool writeGeometry();
//- Begin CellData output section for specified number of fields.
// Must be called prior to writing any cell data fields.
// \param nFields is for legacy format only.
// When nFields=0, this a no-op for legacy format.
// \note Expected calling states: (PIECE | POINT_DATA).
//
// \return True if the state changed
virtual bool beginCellData(label nFields = 0);
//- Begin PointData for specified number of fields.
// Must be called prior to writing any point data fields.
// \param nFields is for legacy format only.
// When nFields=0, this a no-op for legacy format.
// \note Expected calling states: (PIECE | CELL_DATA).
//
// \return True if the state changed
virtual bool beginPointData(label nFields = 0);
//- Write patch ids as CellData.
// Must be called within the CELL_DATA state.
void writePatchIDs();
//- Write processor ids as CellData. This is no-op in serial.
// Must be called within the CELL_DATA state.
bool writeProcIDs();
//- Write processor neighbour ids as CellData. This is no-op in serial.
// Must be called within the CELL_DATA state.
bool writeNeighIDs();
// Write
//- Write a uniform field of Cell (Face) or Point values
template<class Type>
void writeUniform(const word& fieldName, const Type& val);
//- Write point field
template<class Type, template<class> class PatchField>
void write
......@@ -282,7 +205,6 @@ public:
#include "foamVtkPatchWriterTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,33 +30,6 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtk::patchWriter::writeUniform
(
const word& fieldName,
const Type& val
)
{
if (isState(outputState::CELL_DATA))
{
++nCellData_;
vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfCells_);
}
else if (isState(outputState::POINT_DATA))
{
++nPointData_;
vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfPoints_);
}
else
{
WarningInFunction
<< "Ignore bad writer state (" << stateNames[state_]
<< ") for field " << fieldName << nl << endl