ENH: support direct writing of fields from vtk::internalWriter

- eliminates the PtrList requirement (more flexible)

COMP: use tmp intermediate for volPointInterpolation return value

- gcc 4.8.5 had some weird issue of otherwise not binding a const-ref.
  (in foamVtkInternalWriterTemplates.C)
This commit is contained in:
Mark Olesen
2017-06-14 00:28:58 +02:00
parent 8221111245
commit 2a72baf29f
2 changed files with 199 additions and 155 deletions

View File

@ -153,7 +153,44 @@ public:
void writeFooter();
//- Write internal fields
// Write fields (individually)
//- Write the internal field
template<class Type>
void write(const DimensionedField<Type, volMesh>& field);
//- Write the volume field (internal part)
template<class Type, template<class> class PatchField>
void write(const GeometricField<Type, PatchField, volMesh>& field);
//- Write the point field
// Interpolate to originating cell centre for decomposed cells.
template<class Type, template<class> class PatchField>
void write
(
const GeometricField<Type, PatchField, pointMesh>& field
);
//- Write point-interpolated internal field
template<class Type>
void write
(
const volPointInterpolation& pInterp,
const DimensionedField<Type, volMesh>& vfield
);
//- Write point-interpolated volume field
template<class Type>
void write
(
const volPointInterpolation& pInterp,
const GeometricField<Type, fvPatchField, volMesh>& vfield
);
// Write fields (collectively)
//- Write multiple internal fields
template<class Type>
void write
(
@ -163,29 +200,18 @@ public:
>& flds
);
//- Write volFields
template<class Type, template<class> class PatchField>
//- Write multiple volume/point fields
template<class Type, template<class> class PatchField, class GeoMesh>
void write
(
const UPtrList
<
const GeometricField<Type, PatchField, volMesh>
>& flds
);
//- Write pointFields on all mesh points.
// Interpolate to cell centre for decomposed cell centres.
template<class Type, template<class> class PatchField>
void write
(
const UPtrList
<
const GeometricField<Type, PatchField, pointMesh>
const GeometricField<Type, PatchField, GeoMesh>
>& flds
);
//- Interpolated internal fields
//- Write multiple point-interpolated internal fields
template<class Type>
void write
(
@ -196,14 +222,14 @@ public:
>& flds
);
//- Interpolated volFields
template<class Type, template<class> class PatchField>
//- Write multiple point-interpolated volume fields
template<class Type>
void write
(
const volPointInterpolation& pInterp,
const UPtrList
<
const GeometricField<Type, PatchField, volMesh>
const GeometricField<Type, fvPatchField, volMesh>
>& flds
);

View File

@ -33,7 +33,7 @@ License
template<class Type>
void Foam::vtk::internalWriter::write
(
const UPtrList<const DimensionedField<Type, volMesh>>& flds
const DimensionedField<Type, volMesh>& field
)
{
const labelList& cellMap = vtuCells_.cellMap();
@ -41,27 +41,22 @@ void Foam::vtk::internalWriter::write
const int nCmpt(pTraits<Type>::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<float, nCmpt>(field.name())
.closeTag();
}
if (legacy_)
{
legacy::floatField(os(), fld.name(), nCmpt, cellMap.size());
}
else
{
format().openDataArray<float, nCmpt>(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 Type, template<class> class PatchField>
void Foam::vtk::internalWriter::write
(
const UPtrList<const GeometricField<Type, PatchField, volMesh>>& flds
const GeometricField<Type, PatchField, volMesh>& field
)
{
const labelList& cellMap = vtuCells_.cellMap();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(fld.name())
.closeTag();
}
// writeField includes payload size
vtk::writeField(format(), fld, cellMap);
if (!legacy_)
{
format().endDataArray();
}
}
write(field.internalField());
}
template<class Type, template<class> class PatchField>
void Foam::vtk::internalWriter::write
(
const UPtrList<const GeometricField<Type, PatchField, pointMesh>>& flds
const GeometricField<Type, PatchField, pointMesh>& field
)
{
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(field.name())
.closeTag();
}
if (legacy_)
{
legacy::floatField(os(), fld.name(), nCmpt, nVals);
}
else
{
format().openDataArray<float, nCmpt>(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<class Type>
void Foam::vtk::internalWriter::write
(
const volPointInterpolation& pInterp,
const DimensionedField<Type, volMesh>& vfield
)
{
typedef DimensionedField<Type, pointMesh> PointFieldType;
// Use tmp intermediate. Compiler sometimes weird otherwise.
tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
const PointFieldType& pfield = tfield();
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(vfield.name())
.closeTag();
}
format().writeSize(payLoad);
vtk::writeList(format(), pfield);
vtk::writeList(format(), vfield, addPointCellLabels);
format().flush();
if (!legacy_)
{
format().endDataArray();
}
}
template<class Type>
void Foam::vtk::internalWriter::write
(
const volPointInterpolation& pInterp,
const GeometricField<Type, fvPatchField, volMesh>& vfield
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> PointFieldType;
// Use tmp intermediate. Compiler sometimes weird otherwise.
tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
const PointFieldType& pfield = tfield();
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(vfield.name())
.closeTag();
}
format().writeSize(payLoad);
vtk::writeList(format(), pfield);
vtk::writeList(format(), vfield, addPointCellLabels);
format().flush();
if (!legacy_)
{
format().endDataArray();
}
}
template<class Type>
void Foam::vtk::internalWriter::write
(
const UPtrList<const DimensionedField<Type, volMesh>>& flds
)
{
for (const auto& field : flds)
{
write(field);
}
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::vtk::internalWriter::write
(
const UPtrList<const GeometricField<Type, PatchField, GeoMesh>>& flds
)
{
for (const auto& field : flds)
{
write(field);
}
}
@ -156,81 +232,23 @@ void Foam::vtk::internalWriter::write
const UPtrList<const DimensionedField<Type, volMesh>>& flds
)
{
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(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 Type, template<class> class PatchField>
template<class Type>
void Foam::vtk::internalWriter::write
(
const volPointInterpolation& pInterp,
const UPtrList<const GeometricField<Type, PatchField, volMesh>>& flds
const UPtrList<const GeometricField<Type, fvPatchField, volMesh>>& flds
)
{
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
const int nCmpt(pTraits<Type>::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<float, nCmpt>(vfield.name())
.closeTag();
}
format().writeSize(payLoad);
vtk::writeList(format(), pfield);
vtk::writeList(format(), vfield, addPointCellLabels);
format().flush();
if (!legacy_)
{
format().endDataArray();
}
write(pInterp, field);
}
}