mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support VTK output of uniform field
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -214,6 +214,10 @@ public:
|
||||
|
||||
// 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>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -30,6 +30,33 @@ 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
|
||||
(
|
||||
|
||||
@ -233,6 +233,10 @@ public:
|
||||
|
||||
// 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
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -28,6 +28,33 @@ 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
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type, template<class> class PatchField>
|
||||
void Foam::vtk::patchWriter::write
|
||||
(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -126,6 +126,16 @@ protected:
|
||||
//- True if the output state does not correspond to the test state.
|
||||
inline bool notState(outputState test) const;
|
||||
|
||||
//- Write uniform field content.
|
||||
// No context checking (eg, file-open, CellData, PointData, etc)
|
||||
template<class Type>
|
||||
void writeUniform
|
||||
(
|
||||
const word& fieldName,
|
||||
const Type& val,
|
||||
const label nValues
|
||||
);
|
||||
|
||||
|
||||
//- Trigger change state to Piece. Resets nCellData_, nPointData_.
|
||||
bool enter_Piece();
|
||||
@ -282,6 +292,10 @@ public:
|
||||
|
||||
#include "foamVtkFileWriterI.H"
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "foamVtkFileWriterTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
98
src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C
Normal file
98
src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C
Normal file
@ -0,0 +1,98 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <type_traits>
|
||||
#include "foamVtkOutput.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::vtk::fileWriter::writeUniform
|
||||
(
|
||||
const word& fieldName,
|
||||
const Type& val,
|
||||
const label nValues
|
||||
)
|
||||
{
|
||||
static_assert
|
||||
(
|
||||
(
|
||||
std::is_same<label, typename pTraits<Type>::cmptType>::value
|
||||
|| std::is_floating_point<typename pTraits<Type>::cmptType>::value
|
||||
),
|
||||
"Label and Floating-point vector space only"
|
||||
);
|
||||
|
||||
const direction nCmpt(pTraits<Type>::nComponents);
|
||||
|
||||
if (format_)
|
||||
{
|
||||
if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
|
||||
{
|
||||
if (legacy())
|
||||
{
|
||||
legacy::intField<nCmpt>(format(), fieldName, nValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64_t payLoad = vtk::sizeofData<label, nCmpt>(nValues);
|
||||
|
||||
format().beginDataArray<label, nCmpt>(fieldName);
|
||||
format().writeSize(payLoad);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (legacy())
|
||||
{
|
||||
legacy::floatField<nCmpt>(format(), fieldName, nValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint64_t payLoad = vtk::sizeofData<float, nCmpt>(nValues);
|
||||
|
||||
format().beginDataArray<float, nCmpt>(fieldName);
|
||||
format().writeSize(payLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (format_)
|
||||
{
|
||||
for (label i=0; i < nValues; ++i)
|
||||
{
|
||||
vtk::write(format(), val);
|
||||
}
|
||||
}
|
||||
|
||||
if (format_)
|
||||
{
|
||||
format().flush();
|
||||
format().endDataArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -100,14 +100,14 @@ class surfaceWriter
|
||||
//- and begin piece
|
||||
void beginPiece();
|
||||
|
||||
//- Write patch points
|
||||
//- Write points
|
||||
void writePoints();
|
||||
|
||||
//- Write patch faces, legacy format
|
||||
//- Write faces, legacy format
|
||||
// \param pointOffset processor-local point offset
|
||||
void writePolysLegacy(const label pointOffset);
|
||||
|
||||
//- Write patch faces
|
||||
//- Write faces
|
||||
// \param pointOffset processor-local point offset
|
||||
void writePolys(const label pointOffset);
|
||||
|
||||
@ -212,6 +212,10 @@ public:
|
||||
|
||||
// Write
|
||||
|
||||
//- Write a uniform field of Cell (Face) or Point values
|
||||
template<class Type>
|
||||
void writeUniform(const word& fieldName, const Type& val);
|
||||
|
||||
//- Write a list of Cell (Face) or Point values
|
||||
template<class Type>
|
||||
void write(const word& fieldName, const UList<Type>& field);
|
||||
|
||||
@ -25,6 +25,33 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::vtk::surfaceWriter::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>
|
||||
void Foam::vtk::surfaceWriter::write
|
||||
(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -195,6 +195,10 @@ public:
|
||||
|
||||
// Write
|
||||
|
||||
//- Write a uniform field of Cell (Face) or Point values
|
||||
template<class Type>
|
||||
void writeUniform(const word& fieldName, const Type& val);
|
||||
|
||||
//- Write a list of Cell (Face) or Point values
|
||||
template<class Type>
|
||||
void write(const word& fieldName, const UList<Type>& field);
|
||||
|
||||
@ -25,6 +25,34 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::vtk::indirectPatchWriter::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
|
||||
<< "Bad writer state (" << stateNames[state_]
|
||||
<< ") for field " << fieldName << nl << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::vtk::indirectPatchWriter::write
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user