diff --git a/src/conversion/vtk/output/foamVtkInternalWriter.H b/src/conversion/vtk/output/foamVtkInternalWriter.H index 2751cd6785..7fd4aa4f5d 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriter.H +++ b/src/conversion/vtk/output/foamVtkInternalWriter.H @@ -153,7 +153,44 @@ public: void writeFooter(); - //- Write internal fields + // Write fields (individually) + + //- Write the internal field + template + void write(const DimensionedField& field); + + //- Write the volume field (internal part) + template class PatchField> + void write(const GeometricField& field); + + //- Write the point field + // Interpolate to originating cell centre for decomposed cells. + template class PatchField> + void write + ( + const GeometricField& field + ); + + //- Write point-interpolated internal field + template + void write + ( + const volPointInterpolation& pInterp, + const DimensionedField& vfield + ); + + //- Write point-interpolated volume field + template + void write + ( + const volPointInterpolation& pInterp, + const GeometricField& vfield + ); + + + // Write fields (collectively) + + //- Write multiple internal fields template void write ( @@ -163,29 +200,18 @@ public: >& flds ); - //- Write volFields - template class PatchField> + //- Write multiple volume/point fields + template class PatchField, class GeoMesh> void write ( const UPtrList < - const GeometricField - >& flds - ); - - //- Write pointFields on all mesh points. - // Interpolate to cell centre for decomposed cell centres. - template class PatchField> - void write - ( - const UPtrList - < - const GeometricField + const GeometricField >& flds ); - //- Interpolated internal fields + //- Write multiple point-interpolated internal fields template void write ( @@ -196,14 +222,14 @@ public: >& flds ); - //- Interpolated volFields - template class PatchField> + //- Write multiple point-interpolated volume fields + template void write ( const volPointInterpolation& pInterp, const UPtrList < - const GeometricField + const GeometricField >& flds ); diff --git a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C index c316c36d14..77689e5ec7 100644 --- a/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C +++ b/src/conversion/vtk/output/foamVtkInternalWriterTemplates.C @@ -33,7 +33,7 @@ License template void Foam::vtk::internalWriter::write ( - const UPtrList>& flds + const DimensionedField& field ) { const labelList& cellMap = vtuCells_.cellMap(); @@ -41,27 +41,22 @@ void Foam::vtk::internalWriter::write const int nCmpt(pTraits::nComponents); // const uint64_t payLoad(cellMap.size() * nCmpt * sizeof(float)); - forAll(flds, i) + if (legacy_) { - const auto& fld = flds[i]; + legacy::floatField(os(), field.name(), nCmpt, cellMap.size()); + } + else + { + format().openDataArray(field.name()) + .closeTag(); + } - if (legacy_) - { - legacy::floatField(os(), fld.name(), nCmpt, cellMap.size()); - } - else - { - format().openDataArray(fld.name()) - .closeTag(); - } + // writeField includes payload size, and flush + vtk::writeField(format(), field, cellMap); - // writeField includes payload size - vtk::writeField(format(), fld, cellMap); - - if (!legacy_) - { - format().endDataArray(); - } + if (!legacy_) + { + format().endDataArray(); } } @@ -69,82 +64,163 @@ void Foam::vtk::internalWriter::write template class PatchField> void Foam::vtk::internalWriter::write ( - const UPtrList>& flds + const GeometricField& field ) { - const labelList& cellMap = vtuCells_.cellMap(); - - const int nCmpt(pTraits::nComponents); - // const uint64_t payLoad(cellMap.size() * nCmpt * sizeof(float)); - - forAll(flds, i) - { - const auto& fld = flds[i]; - - if (legacy_) - { - legacy::floatField(os(), fld.name(), nCmpt, cellMap.size()); - } - else - { - format().openDataArray(fld.name()) - .closeTag(); - } - - // writeField includes payload size - vtk::writeField(format(), fld, cellMap); - - if (!legacy_) - { - format().endDataArray(); - } - } + write(field.internalField()); } template class PatchField> void Foam::vtk::internalWriter::write ( - const UPtrList>& flds + const GeometricField& field ) { const labelList& addPointCellLabels = vtuCells_.addPointCellLabels(); const int nCmpt(pTraits::nComponents); - const int nVals(vtuCells_.nFieldPoints()); + const label nVals(vtuCells_.nFieldPoints()); // Only needed for non-legacy const uint64_t payLoad(nVals * nCmpt * sizeof(float)); - forAll(flds, i) + if (legacy_) { - const auto& fld = flds[i]; + legacy::floatField(os(), field.name(), nCmpt, nVals); + } + else + { + format().openDataArray(field.name()) + .closeTag(); + } - if (legacy_) - { - legacy::floatField(os(), fld.name(), nCmpt, nVals); - } - else - { - format().openDataArray(fld.name()) - .closeTag(); - } + format().writeSize(payLoad); + vtk::writeList(format(), field); - format().writeSize(payLoad); - vtk::writeList(format(), fld); + for (const label cellId : addPointCellLabels) + { + const Type val = interpolatePointToCell(field, cellId); + vtk::write(format(), val); + } - forAll(addPointCellLabels, i) - { - const Type val = interpolatePointToCell(fld, addPointCellLabels[i]); - vtk::write(format(), val); - } + format().flush(); - format().flush(); + if (!legacy_) + { + format().endDataArray(); + } +} - if (!legacy_) - { - format().endDataArray(); - } + +template +void Foam::vtk::internalWriter::write +( + const volPointInterpolation& pInterp, + const DimensionedField& vfield +) +{ + typedef DimensionedField PointFieldType; + + // Use tmp intermediate. Compiler sometimes weird otherwise. + tmp tfield = pInterp.interpolate(vfield); + const PointFieldType& pfield = tfield(); + + const labelList& addPointCellLabels = vtuCells_.addPointCellLabels(); + + const int nCmpt(pTraits::nComponents); + const label nVals(vtuCells_.nFieldPoints()); + + // Only needed for non-legacy + const uint64_t payLoad(nVals * nCmpt * sizeof(float)); + + if (legacy_) + { + legacy::floatField(os(), vfield.name(), nCmpt, nVals); + } + else + { + format().openDataArray(vfield.name()) + .closeTag(); + } + + format().writeSize(payLoad); + vtk::writeList(format(), pfield); + vtk::writeList(format(), vfield, addPointCellLabels); + format().flush(); + + if (!legacy_) + { + format().endDataArray(); + } +} + + +template +void Foam::vtk::internalWriter::write +( + const volPointInterpolation& pInterp, + const GeometricField& vfield +) +{ + typedef GeometricField PointFieldType; + + // Use tmp intermediate. Compiler sometimes weird otherwise. + tmp tfield = pInterp.interpolate(vfield); + const PointFieldType& pfield = tfield(); + + const labelList& addPointCellLabels = vtuCells_.addPointCellLabels(); + + const int nCmpt(pTraits::nComponents); + const label nVals(vtuCells_.nFieldPoints()); + + // Only needed for non-legacy + const uint64_t payLoad(nVals * nCmpt * sizeof(float)); + + if (legacy_) + { + legacy::floatField(os(), vfield.name(), nCmpt, nVals); + } + else + { + format().openDataArray(vfield.name()) + .closeTag(); + } + + format().writeSize(payLoad); + vtk::writeList(format(), pfield); + vtk::writeList(format(), vfield, addPointCellLabels); + format().flush(); + + if (!legacy_) + { + format().endDataArray(); + } +} + + +template +void Foam::vtk::internalWriter::write +( + const UPtrList>& flds +) +{ + for (const auto& field : flds) + { + write(field); + } +} + + +template class PatchField, class GeoMesh> +void Foam::vtk::internalWriter::write +( + const UPtrList>& flds +) +{ + for (const auto& field : flds) + { + write(field); } } @@ -156,81 +232,23 @@ void Foam::vtk::internalWriter::write const UPtrList>& flds ) { - const labelList& addPointCellLabels = vtuCells_.addPointCellLabels(); - - const int nCmpt(pTraits::nComponents); - const int nVals(vtuCells_.nFieldPoints()); - - // Only needed for non-legacy - const uint64_t payLoad(nVals * nCmpt * sizeof(float)); - - forAll(flds, i) + for (const auto& field : flds) { - const auto& vfield = flds[i]; - const auto& pfield = pInterp.interpolate(vfield)(); - - if (legacy_) - { - legacy::floatField(os(), vfield.name(), nCmpt, nVals); - } - else - { - format().openDataArray(vfield.name()) - .closeTag(); - } - - format().writeSize(payLoad); - vtk::writeList(format(), pfield); - vtk::writeList(format(), vfield, addPointCellLabels); - format().flush(); - - if (!legacy_) - { - format().endDataArray(); - } + write(pInterp, field); } } -template class PatchField> +template void Foam::vtk::internalWriter::write ( const volPointInterpolation& pInterp, - const UPtrList>& flds + const UPtrList>& flds ) { - const labelList& addPointCellLabels = vtuCells_.addPointCellLabels(); - - const int nCmpt(pTraits::nComponents); - const int nVals(vtuCells_.nFieldPoints()); - - // Only needed for non-legacy - const uint64_t payLoad(nVals * nCmpt * sizeof(float)); - - forAll(flds, i) + for (const auto& field : flds) { - const auto& vfield = flds[i]; - const auto& pfield = pInterp.interpolate(vfield)(); - - if (legacy_) - { - legacy::floatField(os(), vfield.name(), nCmpt, nVals); - } - else - { - format().openDataArray(vfield.name()) - .closeTag(); - } - - format().writeSize(payLoad); - vtk::writeList(format(), pfield); - vtk::writeList(format(), vfield, addPointCellLabels); - format().flush(); - - if (!legacy_) - { - format().endDataArray(); - } + write(pInterp, field); } }