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::patchWriter
- eliminates the PtrList requirement (more flexible)
This commit is contained in:
@ -61,9 +61,9 @@ void Foam::vtk::patchWriter::writePoints()
|
|||||||
|
|
||||||
format().writeSize(payLoad);
|
format().writeSize(payLoad);
|
||||||
|
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
vtk::writeList(format(), pp.localPoints());
|
vtk::writeList(format(), pp.localPoints());
|
||||||
}
|
}
|
||||||
@ -84,9 +84,9 @@ void Foam::vtk::patchWriter::writePolysLegacy()
|
|||||||
|
|
||||||
// connectivity count without additional storage (done internally)
|
// connectivity count without additional storage (done internally)
|
||||||
uint64_t nConnectivity = 0;
|
uint64_t nConnectivity = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
forAll(pp, facei)
|
forAll(pp, facei)
|
||||||
{
|
{
|
||||||
@ -101,9 +101,9 @@ void Foam::vtk::patchWriter::writePolysLegacy()
|
|||||||
// [nPts, id1, id2, ..., nPts, id1, id2, ...]
|
// [nPts, id1, id2, ..., nPts, id1, id2, ...]
|
||||||
|
|
||||||
label off = 0;
|
label off = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
forAll(pp, facei)
|
forAll(pp, facei)
|
||||||
{
|
{
|
||||||
@ -138,14 +138,13 @@ void Foam::vtk::patchWriter::writePolys()
|
|||||||
{
|
{
|
||||||
// payload count
|
// payload count
|
||||||
uint64_t payLoad = 0;
|
uint64_t payLoad = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
forAll(pp, facei)
|
forAll(pp, facei)
|
||||||
{
|
{
|
||||||
const face& f = pp.localFaces()[facei];
|
payLoad += pp[facei].size();
|
||||||
payLoad += f.size();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,9 +155,9 @@ void Foam::vtk::patchWriter::writePolys()
|
|||||||
format().writeSize(payLoad * sizeof(label));
|
format().writeSize(payLoad * sizeof(label));
|
||||||
|
|
||||||
label off = 0;
|
label off = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
forAll(pp, facei)
|
forAll(pp, facei)
|
||||||
{
|
{
|
||||||
@ -191,9 +190,9 @@ void Foam::vtk::patchWriter::writePolys()
|
|||||||
format().writeSize(nFaces_ * sizeof(label));
|
format().writeSize(nFaces_ * sizeof(label));
|
||||||
|
|
||||||
label off = 0;
|
label off = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
forAll(pp, facei)
|
forAll(pp, facei)
|
||||||
{
|
{
|
||||||
@ -262,9 +261,9 @@ Foam::vtk::patchWriter::patchWriter
|
|||||||
|
|
||||||
// Basic sizes
|
// Basic sizes
|
||||||
nPoints_ = nFaces_ = 0;
|
nPoints_ = nFaces_ = 0;
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchIDs_[i]];
|
const polyPatch& pp = patches[patchId];
|
||||||
|
|
||||||
nPoints_ += pp.nPoints();
|
nPoints_ += pp.nPoints();
|
||||||
nFaces_ += pp.size();
|
nFaces_ += pp.size();
|
||||||
@ -384,10 +383,8 @@ void Foam::vtk::patchWriter::writePatchIDs()
|
|||||||
|
|
||||||
format().writeSize(payLoad);
|
format().writeSize(payLoad);
|
||||||
|
|
||||||
forAll(patchIDs_, i)
|
for (const label patchId : patchIDs_)
|
||||||
{
|
{
|
||||||
const label patchId = patchIDs_[i];
|
|
||||||
|
|
||||||
const label sz = mesh_.boundaryMesh()[patchId].size();
|
const label sz = mesh_.boundaryMesh()[patchId].size();
|
||||||
|
|
||||||
for (label facei = 0; facei < sz; ++facei)
|
for (label facei = 0; facei < sz; ++facei)
|
||||||
|
|||||||
@ -167,27 +167,38 @@ public:
|
|||||||
void writeFooter();
|
void writeFooter();
|
||||||
|
|
||||||
|
|
||||||
//- Write volFields
|
// Write fields (individually)
|
||||||
|
|
||||||
|
//- Write volume field
|
||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField>
|
||||||
|
void write(const GeometricField<Type, PatchField, volMesh>& field);
|
||||||
|
|
||||||
|
//- Write point fields
|
||||||
|
template<class Type, template<class> class PatchField>
|
||||||
|
void write(const GeometricField<Type, PatchField, pointMesh>& field);
|
||||||
|
|
||||||
|
//- Write point-interpolated volume field
|
||||||
|
template<class Type>
|
||||||
|
void write
|
||||||
|
(
|
||||||
|
const PrimitivePatchInterpolation<primitivePatch>& pInterp,
|
||||||
|
const GeometricField<Type, fvPatchField, volMesh>& field
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Write fields (collectively)
|
||||||
|
|
||||||
|
//- Write multiple volume/point fields
|
||||||
|
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
|
>& flds
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write pointFields
|
//- Write multiple point-interpolated volume fields
|
||||||
template<class Type, template<class> class PatchField>
|
|
||||||
void write
|
|
||||||
(
|
|
||||||
const UPtrList
|
|
||||||
<
|
|
||||||
const GeometricField<Type, PatchField, pointMesh>
|
|
||||||
>&
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Interpolated volFields
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void write
|
void write
|
||||||
(
|
(
|
||||||
|
|||||||
@ -31,48 +31,43 @@ License
|
|||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField>
|
||||||
void Foam::vtk::patchWriter::write
|
void Foam::vtk::patchWriter::write
|
||||||
(
|
(
|
||||||
const UPtrList<const GeometricField<Type, PatchField, volMesh>>& flds
|
const GeometricField<Type, PatchField, volMesh>& field
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nCmpt(pTraits<Type>::nComponents);
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
const uint64_t payLoad(nFaces_ * nCmpt * sizeof(float));
|
const uint64_t payLoad(nFaces_ * nCmpt * sizeof(float));
|
||||||
|
|
||||||
forAll(flds, fieldi)
|
if (legacy_)
|
||||||
{
|
{
|
||||||
const auto& fld = flds[fieldi];
|
legacy::floatField(os_, field.name(), nCmpt, nFaces_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format().openDataArray<float, nCmpt>(field.name())
|
||||||
|
.closeTag();
|
||||||
|
}
|
||||||
|
|
||||||
if (legacy_)
|
format().writeSize(payLoad);
|
||||||
|
|
||||||
|
for (const label patchId : patchIDs_)
|
||||||
|
{
|
||||||
|
const auto& pfld = field.boundaryField()[patchId];
|
||||||
|
|
||||||
|
if (nearCellValue_)
|
||||||
{
|
{
|
||||||
legacy::floatField(os_, fld.name(), nCmpt, nFaces_);
|
vtk::writeList(format(), pfld.patchInternalField()());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
vtk::writeList(format(), pfld);
|
||||||
.closeTag();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
format().writeSize(payLoad);
|
format().flush();
|
||||||
|
|
||||||
forAll(patchIDs_, i)
|
if (!legacy_)
|
||||||
{
|
{
|
||||||
const auto& pfld = fld.boundaryField()[patchIDs_[i]];
|
format().endDataArray();
|
||||||
|
|
||||||
if (nearCellValue_)
|
|
||||||
{
|
|
||||||
vtk::writeList(format(), pfld.patchInternalField()());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vtk::writeList(format(), pfld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
format().flush();
|
|
||||||
|
|
||||||
if (!legacy_)
|
|
||||||
{
|
|
||||||
format().endDataArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,41 +75,99 @@ void Foam::vtk::patchWriter::write
|
|||||||
template<class Type, template<class> class PatchField>
|
template<class Type, template<class> class PatchField>
|
||||||
void Foam::vtk::patchWriter::write
|
void Foam::vtk::patchWriter::write
|
||||||
(
|
(
|
||||||
const UPtrList<const GeometricField<Type, PatchField, pointMesh>>& flds
|
const GeometricField<Type, PatchField, pointMesh>& field
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nCmpt(pTraits<Type>::nComponents);
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
const uint64_t payLoad(nPoints_ * nCmpt * sizeof(float));
|
const uint64_t payLoad(nPoints_ * nCmpt * sizeof(float));
|
||||||
|
|
||||||
forAll(flds, fieldi)
|
if (legacy_)
|
||||||
{
|
{
|
||||||
const auto& fld = flds[fieldi];
|
legacy::floatField(os_, field.name(), nCmpt, nPoints_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format().openDataArray<float, nCmpt>(field.name())
|
||||||
|
.closeTag();
|
||||||
|
}
|
||||||
|
|
||||||
if (legacy_)
|
format().writeSize(payLoad);
|
||||||
|
|
||||||
|
for (const label patchId : patchIDs_)
|
||||||
|
{
|
||||||
|
const auto& pfld = field.boundaryField()[patchId];
|
||||||
|
|
||||||
|
vtk::writeList(format(), pfld.patchInternalField()());
|
||||||
|
}
|
||||||
|
|
||||||
|
format().flush();
|
||||||
|
|
||||||
|
if (!legacy_)
|
||||||
|
{
|
||||||
|
format().endDataArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::vtk::patchWriter::write
|
||||||
|
(
|
||||||
|
const PrimitivePatchInterpolation<primitivePatch>& pInter,
|
||||||
|
const GeometricField<Type, fvPatchField, volMesh>& field
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
|
const uint64_t payLoad(nPoints_ * nCmpt * sizeof(float));
|
||||||
|
|
||||||
|
if (legacy_)
|
||||||
|
{
|
||||||
|
legacy::floatField(os_, field.name(), nCmpt, nPoints_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format().openDataArray<float, nCmpt>(field.name())
|
||||||
|
.closeTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
format().writeSize(payLoad);
|
||||||
|
|
||||||
|
for (const label patchId : patchIDs_)
|
||||||
|
{
|
||||||
|
const auto& pfld = field.boundaryField()[patchId];
|
||||||
|
|
||||||
|
if (nearCellValue_)
|
||||||
{
|
{
|
||||||
legacy::floatField(os_, fld.name(), nCmpt, nPoints_);
|
auto tfield =
|
||||||
|
pInter.faceToPointInterpolate(pfld.patchInternalField()());
|
||||||
|
|
||||||
|
vtk::writeList(format(), tfield());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
auto tfield = pInter.faceToPointInterpolate(pfld);
|
||||||
.closeTag();
|
|
||||||
|
vtk::writeList(format(), tfield());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
format().writeSize(payLoad);
|
format().flush();
|
||||||
|
|
||||||
forAll(patchIDs_, i)
|
if (!legacy_)
|
||||||
{
|
{
|
||||||
const auto& pfld = fld.boundaryField()[patchIDs_[i]];
|
format().endDataArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vtk::writeList(format(), pfld.patchInternalField()());
|
|
||||||
}
|
|
||||||
|
|
||||||
format().flush();
|
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||||
|
void Foam::vtk::patchWriter::write
|
||||||
if (!legacy_)
|
(
|
||||||
{
|
const UPtrList<const GeometricField<Type, PatchField, GeoMesh>>& flds
|
||||||
format().endDataArray();
|
)
|
||||||
}
|
{
|
||||||
|
for (const auto& field : flds)
|
||||||
|
{
|
||||||
|
write(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,50 +179,9 @@ void Foam::vtk::patchWriter::write
|
|||||||
const UPtrList<const GeometricField<Type, fvPatchField, volMesh>>& flds
|
const UPtrList<const GeometricField<Type, fvPatchField, volMesh>>& flds
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nCmpt(pTraits<Type>::nComponents);
|
for (const auto& field : flds)
|
||||||
const uint64_t payLoad(nPoints_ * nCmpt * sizeof(float));
|
|
||||||
|
|
||||||
forAll(flds, fieldi)
|
|
||||||
{
|
{
|
||||||
const auto& fld = flds[fieldi];
|
write(pInter, field);
|
||||||
|
|
||||||
if (legacy_)
|
|
||||||
{
|
|
||||||
legacy::floatField(os_, fld.name(), nCmpt, nPoints_);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
|
||||||
.closeTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
format().writeSize(payLoad);
|
|
||||||
|
|
||||||
forAll(patchIDs_, i)
|
|
||||||
{
|
|
||||||
const auto& pfld = fld.boundaryField()[patchIDs_[i]];
|
|
||||||
|
|
||||||
if (nearCellValue_)
|
|
||||||
{
|
|
||||||
auto tfield =
|
|
||||||
pInter.faceToPointInterpolate(pfld.patchInternalField()());
|
|
||||||
|
|
||||||
vtk::writeList(format(), tfield());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto tfield = pInter.faceToPointInterpolate(pfld);
|
|
||||||
|
|
||||||
vtk::writeList(format(), tfield());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
format().flush();
|
|
||||||
|
|
||||||
if (!legacy_)
|
|
||||||
{
|
|
||||||
format().endDataArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -135,13 +135,26 @@ public:
|
|||||||
void writeFooter();
|
void writeFooter();
|
||||||
|
|
||||||
|
|
||||||
//- Get face field
|
//- Get face field (internal face or boundary face)
|
||||||
template<class Type>
|
template<class Type>
|
||||||
tmp<Field<Type>> getFaceField
|
tmp<Field<Type>> getFaceField
|
||||||
(
|
(
|
||||||
const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld
|
const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Write fields (individually)
|
||||||
|
|
||||||
|
//- Write surface field
|
||||||
|
template<class Type>
|
||||||
|
void write
|
||||||
|
(
|
||||||
|
const GeometricField<Type, fvsPatchField, surfaceMesh>& field
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Write fields (collectively)
|
||||||
|
|
||||||
//- Write surface fields
|
//- Write surface fields
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void write
|
void write
|
||||||
|
|||||||
@ -59,6 +59,37 @@ Foam::vtk::surfaceMeshWriter::getFaceField
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::vtk::surfaceMeshWriter::write
|
||||||
|
(
|
||||||
|
const GeometricField<Type, fvsPatchField, surfaceMesh>& field
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const int nCmpt(pTraits<Type>::nComponents);
|
||||||
|
const uint64_t payLoad(pp_.size() * nCmpt * sizeof(float));
|
||||||
|
|
||||||
|
if (legacy_)
|
||||||
|
{
|
||||||
|
legacy::floatField(os(), field.name(), nCmpt, pp_.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format().openDataArray<float, nCmpt>(field.name())
|
||||||
|
.closeTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
format().writeSize(payLoad);
|
||||||
|
vtk::writeList(format(), getFaceField(field)());
|
||||||
|
|
||||||
|
format().flush();
|
||||||
|
|
||||||
|
if (!legacy_)
|
||||||
|
{
|
||||||
|
format().endDataArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::vtk::surfaceMeshWriter::write
|
void Foam::vtk::surfaceMeshWriter::write
|
||||||
(
|
(
|
||||||
@ -68,32 +99,9 @@ void Foam::vtk::surfaceMeshWriter::write
|
|||||||
>& sflds
|
>& sflds
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int nCmpt(pTraits<Type>::nComponents);
|
for (const auto& field : sflds)
|
||||||
const uint64_t payLoad(pp_.size() * nCmpt * sizeof(float));
|
|
||||||
|
|
||||||
forAll(sflds, fieldi)
|
|
||||||
{
|
{
|
||||||
const auto& fld = sflds[fieldi];
|
write(field);
|
||||||
|
|
||||||
if (legacy_)
|
|
||||||
{
|
|
||||||
legacy::floatField(os(), fld.name(), nCmpt, pp_.size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
format().openDataArray<float, nCmpt>(fld.name())
|
|
||||||
.closeTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
format().writeSize(payLoad);
|
|
||||||
vtk::writeList(format(), getFaceField(fld)());
|
|
||||||
|
|
||||||
format().flush();
|
|
||||||
|
|
||||||
if (!legacy_)
|
|
||||||
{
|
|
||||||
format().endDataArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user