diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.H b/src/conversion/vtk/output/foamVtkInternalWriter.H index 2c0ac667c7..00360cab22 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.H +++ b/src/conversion/vtk/output/foamVtkInternalWriter.H @@ -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 + void writeUniform(const word& fieldName, const Type& val); + //- Write point field // Interpolate to originating cell centre for decomposed cells. template class PatchField> diff --git a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C index 95bea58f90..6195c4e1e7 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C @@ -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 +void Foam::vtk::internalWriter::writeUniform +( + const word& fieldName, + const Type& val +) +{ + if (isState(outputState::CELL_DATA)) + { + ++nCellData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfCells_); + } + else if (isState(outputState::POINT_DATA)) + { + ++nPointData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfPoints_); + } + else + { + WarningInFunction + << "Ignore bad writer state (" << stateNames[state_] + << ") for field " << fieldName << nl << endl + << exit(FatalError); + } +} + + template class PatchField> void Foam::vtk::internalWriter::write ( diff --git a/src/conversion/vtk/output/foamVtkPatchWriter.H b/src/conversion/vtk/output/foamVtkPatchWriter.H index 4e1b901a0e..43db7cc90e 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriter.H +++ b/src/conversion/vtk/output/foamVtkPatchWriter.H @@ -233,6 +233,10 @@ public: // Write + //- Write a uniform field of Cell (Face) or Point values + template + void writeUniform(const word& fieldName, const Type& val); + //- Write point field template class PatchField> void write diff --git a/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C b/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C index d8d59a35e4..5c0c1ba622 100644 --- a/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkPatchWriterTemplates.C @@ -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 +void Foam::vtk::patchWriter::writeUniform +( + const word& fieldName, + const Type& val +) +{ + if (isState(outputState::CELL_DATA)) + { + ++nCellData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfCells_); + } + else if (isState(outputState::POINT_DATA)) + { + ++nPointData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfPoints_); + } + else + { + WarningInFunction + << "Ignore bad writer state (" << stateNames[state_] + << ") for field " << fieldName << nl << endl + << exit(FatalError); + } +} + + template class PatchField> void Foam::vtk::patchWriter::write ( diff --git a/src/fileFormats/vtk/file/foamVtkFileWriter.H b/src/fileFormats/vtk/file/foamVtkFileWriter.H index e11c5f9091..2dc442193c 100644 --- a/src/fileFormats/vtk/file/foamVtkFileWriter.H +++ b/src/fileFormats/vtk/file/foamVtkFileWriter.H @@ -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 + 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 diff --git a/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C new file mode 100644 index 0000000000..606d522c4a --- /dev/null +++ b/src/fileFormats/vtk/file/foamVtkFileWriterTemplates.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include +#include "foamVtkOutput.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +void Foam::vtk::fileWriter::writeUniform +( + const word& fieldName, + const Type& val, + const label nValues +) +{ + static_assert + ( + ( + std::is_same::cmptType>::value + || std::is_floating_point::cmptType>::value + ), + "Label and Floating-point vector space only" + ); + + const direction nCmpt(pTraits::nComponents); + + if (format_) + { + if (std::is_same::cmptType>::value) + { + if (legacy()) + { + legacy::intField(format(), fieldName, nValues); + } + else + { + const uint64_t payLoad = vtk::sizeofData(nValues); + + format().beginDataArray(fieldName); + format().writeSize(payLoad); + } + } + else + { + if (legacy()) + { + legacy::floatField(format(), fieldName, nValues); + } + else + { + const uint64_t payLoad = vtk::sizeofData(nValues); + + format().beginDataArray(fieldName); + format().writeSize(payLoad); + } + } + } + + if (format_) + { + for (label i=0; i < nValues; ++i) + { + vtk::write(format(), val); + } + } + + if (format_) + { + format().flush(); + format().endDataArray(); + } +} + + +// ************************************************************************* // diff --git a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H index aa6348ff36..45e240734b 100644 --- a/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H +++ b/src/fileFormats/vtk/write/foamVtkSurfaceWriter.H @@ -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 + void writeUniform(const word& fieldName, const Type& val); + //- Write a list of Cell (Face) or Point values template void write(const word& fieldName, const UList& field); diff --git a/src/fileFormats/vtk/write/foamVtkSurfaceWriterTemplates.C b/src/fileFormats/vtk/write/foamVtkSurfaceWriterTemplates.C index 3c9bc0c582..65978ff395 100644 --- a/src/fileFormats/vtk/write/foamVtkSurfaceWriterTemplates.C +++ b/src/fileFormats/vtk/write/foamVtkSurfaceWriterTemplates.C @@ -25,6 +25,33 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::vtk::surfaceWriter::writeUniform +( + const word& fieldName, + const Type& val +) +{ + if (isState(outputState::CELL_DATA)) + { + ++nCellData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfCells_); + } + else if (isState(outputState::POINT_DATA)) + { + ++nPointData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfPoints_); + } + else + { + WarningInFunction + << "Ignore bad writer state (" << stateNames[state_] + << ") for field " << fieldName << nl << endl + << exit(FatalError); + } +} + + template void Foam::vtk::surfaceWriter::write ( diff --git a/src/meshTools/output/foamVtkIndPatchWriter.H b/src/meshTools/output/foamVtkIndPatchWriter.H index 9f3c40fb5d..29bd11fca4 100644 --- a/src/meshTools/output/foamVtkIndPatchWriter.H +++ b/src/meshTools/output/foamVtkIndPatchWriter.H @@ -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 + void writeUniform(const word& fieldName, const Type& val); + //- Write a list of Cell (Face) or Point values template void write(const word& fieldName, const UList& field); diff --git a/src/meshTools/output/foamVtkIndPatchWriterTemplates.C b/src/meshTools/output/foamVtkIndPatchWriterTemplates.C index 9db4cc9fde..f1c566db8b 100644 --- a/src/meshTools/output/foamVtkIndPatchWriterTemplates.C +++ b/src/meshTools/output/foamVtkIndPatchWriterTemplates.C @@ -25,6 +25,34 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::vtk::indirectPatchWriter::writeUniform +( + const word& fieldName, + const Type& val +) +{ + if (isState(outputState::CELL_DATA)) + { + ++nCellData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfCells_); + } + else if (isState(outputState::POINT_DATA)) + { + ++nPointData_; + vtk::fileWriter::writeUniform(fieldName, val, numberOfPoints_); + } + else + { + WarningInFunction + << "Bad writer state (" << stateNames[state_] + << ") for field " << fieldName << nl << endl + << exit(FatalError); + } +} + + template void Foam::vtk::indirectPatchWriter::write (