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