mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -153,7 +153,44 @@ public:
|
|||||||
void writeFooter();
|
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>
|
template<class Type>
|
||||||
void write
|
void write
|
||||||
(
|
(
|
||||||
@ -163,29 +200,18 @@ public:
|
|||||||
>& flds
|
>& flds
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write volFields
|
//- Write multiple volume/point fields
|
||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
void write
|
void write
|
||||||
(
|
(
|
||||||
const UPtrList
|
const UPtrList
|
||||||
<
|
<
|
||||||
const GeometricField<Type, PatchField, volMesh>
|
const GeometricField<Type, PatchField, GeoMesh>
|
||||||
>& 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>
|
|
||||||
>& flds
|
>& flds
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
//- Interpolated internal fields
|
//- Write multiple point-interpolated internal fields
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void write
|
void write
|
||||||
(
|
(
|
||||||
@ -196,14 +222,14 @@ public:
|
|||||||
>& flds
|
>& flds
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Interpolated volFields
|
//- Write multiple point-interpolated volume fields
|
||||||
template<class Type, template<class> class PatchField>
|
template<class Type>
|
||||||
void write
|
void write
|
||||||
(
|
(
|
||||||
const volPointInterpolation& pInterp,
|
const volPointInterpolation& pInterp,
|
||||||
const UPtrList
|
const UPtrList
|
||||||
<
|
<
|
||||||
const GeometricField<Type, PatchField, volMesh>
|
const GeometricField<Type, fvPatchField, volMesh>
|
||||||
>& flds
|
>& flds
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ License
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::vtk::internalWriter::write
|
void Foam::vtk::internalWriter::write
|
||||||
(
|
(
|
||||||
const UPtrList<const DimensionedField<Type, volMesh>>& flds
|
const DimensionedField<Type, volMesh>& field
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const labelList& cellMap = vtuCells_.cellMap();
|
const labelList& cellMap = vtuCells_.cellMap();
|
||||||
@ -41,27 +41,22 @@ void Foam::vtk::internalWriter::write
|
|||||||
const int nCmpt(pTraits<Type>::nComponents);
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
// const uint64_t payLoad(cellMap.size() * nCmpt * sizeof(float));
|
// 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_)
|
// writeField includes payload size, and flush
|
||||||
{
|
vtk::writeField(format(), field, cellMap);
|
||||||
legacy::floatField(os(), fld.name(), nCmpt, cellMap.size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
|
||||||
.closeTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeField includes payload size
|
if (!legacy_)
|
||||||
vtk::writeField(format(), fld, cellMap);
|
{
|
||||||
|
format().endDataArray();
|
||||||
if (!legacy_)
|
|
||||||
{
|
|
||||||
format().endDataArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,82 +64,163 @@ void Foam::vtk::internalWriter::write
|
|||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField>
|
||||||
void Foam::vtk::internalWriter::write
|
void Foam::vtk::internalWriter::write
|
||||||
(
|
(
|
||||||
const UPtrList<const GeometricField<Type, PatchField, volMesh>>& flds
|
const GeometricField<Type, PatchField, volMesh>& field
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const labelList& cellMap = vtuCells_.cellMap();
|
write(field.internalField());
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField>
|
||||||
void Foam::vtk::internalWriter::write
|
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 labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
|
||||||
|
|
||||||
const int nCmpt(pTraits<Type>::nComponents);
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
const int nVals(vtuCells_.nFieldPoints());
|
const label nVals(vtuCells_.nFieldPoints());
|
||||||
|
|
||||||
// Only needed for non-legacy
|
// Only needed for non-legacy
|
||||||
const uint64_t payLoad(nVals * nCmpt * sizeof(float));
|
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_)
|
format().writeSize(payLoad);
|
||||||
{
|
vtk::writeList(format(), field);
|
||||||
legacy::floatField(os(), fld.name(), nCmpt, nVals);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
|
||||||
.closeTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
format().writeSize(payLoad);
|
for (const label cellId : addPointCellLabels)
|
||||||
vtk::writeList(format(), fld);
|
{
|
||||||
|
const Type val = interpolatePointToCell(field, cellId);
|
||||||
|
vtk::write(format(), val);
|
||||||
|
}
|
||||||
|
|
||||||
forAll(addPointCellLabels, i)
|
format().flush();
|
||||||
{
|
|
||||||
const Type val = interpolatePointToCell(fld, addPointCellLabels[i]);
|
|
||||||
vtk::write(format(), val);
|
|
||||||
}
|
|
||||||
|
|
||||||
format().flush();
|
if (!legacy_)
|
||||||
|
{
|
||||||
|
format().endDataArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!legacy_)
|
|
||||||
{
|
template<class Type>
|
||||||
format().endDataArray();
|
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 UPtrList<const DimensionedField<Type, volMesh>>& flds
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
|
for (const auto& field : flds)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const auto& vfield = flds[i];
|
write(pInterp, field);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type, template<class> class PatchField>
|
template<class Type>
|
||||||
void Foam::vtk::internalWriter::write
|
void Foam::vtk::internalWriter::write
|
||||||
(
|
(
|
||||||
const volPointInterpolation& pInterp,
|
const volPointInterpolation& pInterp,
|
||||||
const UPtrList<const GeometricField<Type, PatchField, volMesh>>& flds
|
const UPtrList<const GeometricField<Type, fvPatchField, volMesh>>& flds
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
|
for (const auto& field : flds)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const auto& vfield = flds[i];
|
write(pInterp, field);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user