foamToVTK: Added support for vol internal fields

This commit is contained in:
Henry Weller
2019-07-20 20:16:18 +01:00
parent 5c49d24b7d
commit 53e8458153
5 changed files with 128 additions and 75 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,8 +27,8 @@ Application
Description Description
Legacy VTK file format writer. Legacy VTK file format writer.
- Handles volFields, pointFields, surfaceScalarField, surfaceVectorField - Handles volFields, volFields::Internal, pointFields,
fields. surfaceScalarField and surfaceVectorField.
- Mesh topo changes. - Mesh topo changes.
- Both ascii and binary. - Both ascii and binary.
- Single time step writing. - Single time step writing.
@ -497,7 +497,6 @@ int main(int argc, char *argv[])
Info<< " Read new mesh" << nl << endl; Info<< " Read new mesh" << nl << endl;
} }
// If faceSet: write faceSet only (as polydata) // If faceSet: write faceSet only (as polydata)
if (faceSetName.size()) if (faceSetName.size())
{ {
@ -521,6 +520,7 @@ int main(int argc, char *argv[])
continue; continue;
} }
// If pointSet: write pointSet only (as polydata) // If pointSet: write pointSet only (as polydata)
if (pointSetName.size()) if (pointSetName.size())
{ {
@ -556,12 +556,61 @@ int main(int argc, char *argv[])
selectedFields selectedFields
); );
// Construct the vol internal fields (on the original mesh if subsetted)
PtrList<const volScalarField::Internal> visf;
PtrList<const volVectorField::Internal> vivf;
PtrList<const volSphericalTensorField::Internal> visptf;
PtrList<const volSymmTensorField::Internal> visytf;
PtrList<const volTensorField::Internal> vitf;
if (!specifiedFields || selectedFields.size())
{
readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, visf);
print(" volScalarField::Internal :", Info, visf);
readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vivf);
print(" volVectorField::Internal :", Info, vivf);
readFields
(
vMesh,
vMesh.baseMesh(),
objects,
selectedFields,
visptf
);
print(" volSphericalTensorFields::Internal :", Info, visptf);
readFields
(
vMesh,
vMesh.baseMesh(),
objects,
selectedFields,
visytf
);
print(" volSymmTensorFields::Internal :", Info, visytf);
readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vitf);
print(" volTensorFields::Internal :", Info, vitf);
}
label nVolInternalFields =
visf.size()
+ vivf.size()
+ visptf.size()
+ visytf.size()
+ vitf.size();
// Construct the vol fields (on the original mesh if subsetted) // Construct the vol fields (on the original mesh if subsetted)
PtrList<const volScalarField> vsf; PtrList<const volScalarField> vsf;
PtrList<const volVectorField> vvf; PtrList<const volVectorField> vvf;
PtrList<const volSphericalTensorField> vSpheretf; PtrList<const volSphericalTensorField> vsptf;
PtrList<const volSymmTensorField> vSymmtf; PtrList<const volSymmTensorField> vsytf;
PtrList<const volTensorField> vtf; PtrList<const volTensorField> vtf;
if (!specifiedFields || selectedFields.size()) if (!specifiedFields || selectedFields.size())
@ -578,9 +627,9 @@ int main(int argc, char *argv[])
vMesh.baseMesh(), vMesh.baseMesh(),
objects, objects,
selectedFields, selectedFields,
vSpheretf vsptf
); );
print(" volSphericalTensorFields :", Info, vSpheretf); print(" volSphericalTensorFields :", Info, vsptf);
readFields readFields
( (
@ -588,9 +637,9 @@ int main(int argc, char *argv[])
vMesh.baseMesh(), vMesh.baseMesh(),
objects, objects,
selectedFields, selectedFields,
vSymmtf vsytf
); );
print(" volSymmTensorFields :", Info, vSymmtf); print(" volSymmTensorFields :", Info, vsytf);
readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf); readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf);
print(" volTensorFields :", Info, vtf); print(" volTensorFields :", Info, vtf);
@ -599,13 +648,12 @@ int main(int argc, char *argv[])
label nVolFields = label nVolFields =
vsf.size() vsf.size()
+ vvf.size() + vvf.size()
+ vSpheretf.size() + vsptf.size()
+ vSymmtf.size() + vsytf.size()
+ vtf.size(); + vtf.size();
// Construct pointMesh only if necessary since constructs edge // Construct pointMesh only if requested
// addressing (expensive on polyhedral meshes)
if (noPointValues) if (noPointValues)
{ {
Info<< " pointScalarFields : switched off" Info<< " pointScalarFields : switched off"
@ -616,8 +664,8 @@ int main(int argc, char *argv[])
PtrList<const pointScalarField> psf; PtrList<const pointScalarField> psf;
PtrList<const pointVectorField> pvf; PtrList<const pointVectorField> pvf;
PtrList<const pointSphericalTensorField> pSpheretf; PtrList<const pointSphericalTensorField> psptf;
PtrList<const pointSymmTensorField> pSymmtf; PtrList<const pointSymmTensorField> psytf;
PtrList<const pointTensorField> ptf; PtrList<const pointTensorField> ptf;
if (!noPointValues && !(specifiedFields && selectedFields.empty())) if (!noPointValues && !(specifiedFields && selectedFields.empty()))
@ -648,9 +696,9 @@ int main(int argc, char *argv[])
pointMesh::New(vMesh.baseMesh()), pointMesh::New(vMesh.baseMesh()),
objects, objects,
selectedFields, selectedFields,
pSpheretf psptf
); );
print(" pointSphericalTensorFields :", Info, pSpheretf); print(" pointSphericalTensorFields :", Info, psptf);
readFields readFields
( (
@ -658,9 +706,9 @@ int main(int argc, char *argv[])
pointMesh::New(vMesh.baseMesh()), pointMesh::New(vMesh.baseMesh()),
objects, objects,
selectedFields, selectedFields,
pSymmtf psytf
); );
print(" pointSymmTensorFields :", Info, pSymmtf); print(" pointSymmTensorFields :", Info, psytf);
readFields readFields
( (
@ -677,8 +725,8 @@ int main(int argc, char *argv[])
label nPointFields = label nPointFields =
psf.size() psf.size()
+ pvf.size() + pvf.size()
+ pSpheretf.size() + psptf.size()
+ pSymmtf.size() + psytf.size()
+ ptf.size(); + ptf.size();
if (doWriteInternal) if (doWriteInternal)
@ -697,22 +745,29 @@ int main(int argc, char *argv[])
// Write mesh // Write mesh
internalWriter writer(vMesh, binary, vtkFileName); internalWriter writer(vMesh, binary, vtkFileName);
// VolFields + cellID // cellID + volFields::Internal + VolFields
writeFuns::writeCellDataHeader writeFuns::writeCellDataHeader
( (
writer.os(), writer.os(),
vMesh.nFieldCells(), vMesh.nFieldCells(),
1+nVolFields 1 + nVolInternalFields + nVolFields
); );
// Write cellID field // Write cellID field
writer.writeCellIDs(); writer.writeCellIDs();
// Write volFields::Internal
writer.write(visf);
writer.write(vivf);
writer.write(visptf);
writer.write(visytf);
writer.write(vitf);
// Write volFields // Write volFields
writer.write(vsf); writer.write(vsf);
writer.write(vvf); writer.write(vvf);
writer.write(vSpheretf); writer.write(vsptf);
writer.write(vSymmtf); writer.write(vsytf);
writer.write(vtf); writer.write(vtf);
if (!noPointValues) if (!noPointValues)
@ -721,22 +776,22 @@ int main(int argc, char *argv[])
( (
writer.os(), writer.os(),
vMesh.nFieldPoints(), vMesh.nFieldPoints(),
nVolFields+nPointFields nVolFields + nPointFields
); );
// pointFields // pointFields
writer.write(psf); writer.write(psf);
writer.write(pvf); writer.write(pvf);
writer.write(pSpheretf); writer.write(psptf);
writer.write(pSymmtf); writer.write(psytf);
writer.write(ptf); writer.write(ptf);
// Interpolated volFields // Interpolated volFields
volPointInterpolation pInterp(mesh); volPointInterpolation pInterp(mesh);
writer.write(pInterp, vsf); writer.write(pInterp, vsf);
writer.write(pInterp, vvf); writer.write(pInterp, vvf);
writer.write(pInterp, vSpheretf); writer.write(pInterp, vsptf);
writer.write(pInterp, vSymmtf); writer.write(pInterp, vsytf);
writer.write(pInterp, vtf); writer.write(pInterp, vtf);
} }
} }
@ -776,7 +831,7 @@ int main(int argc, char *argv[])
// Rework the scalar fields into vectorfields. // Rework the scalar fields into vectorfields.
label sz = svf.size(); label sz = svf.size();
svf.setSize(sz+ssf.size()); svf.setSize(sz + ssf.size());
surfaceVectorField n(mesh.Sf()/mesh.magSf()); surfaceVectorField n(mesh.Sf()/mesh.magSf());
@ -858,7 +913,7 @@ int main(int argc, char *argv[])
( (
writer.os(), writer.os(),
writer.nFaces(), writer.nFaces(),
1+nVolFields 1 + nVolFields
); );
// Write patchID field // Write patchID field
@ -867,8 +922,8 @@ int main(int argc, char *argv[])
// Write volFields // Write volFields
writer.write(vsf); writer.write(vsf);
writer.write(vvf); writer.write(vvf);
writer.write(vSpheretf); writer.write(vsptf);
writer.write(vSymmtf); writer.write(vsytf);
writer.write(vtf); writer.write(vtf);
if (!noPointValues) if (!noPointValues)
@ -883,12 +938,9 @@ int main(int argc, char *argv[])
// Write pointFields // Write pointFields
writer.write(psf); writer.write(psf);
writer.write(pvf); writer.write(pvf);
writer.write(pSpheretf); writer.write(psptf);
writer.write(pSymmtf); writer.write(psytf);
writer.write(ptf); writer.write(ptf);
// no interpolated volFields since I cannot be bothered to
// create the patchInterpolation for all subpatches.
} }
} }
else else
@ -938,7 +990,7 @@ int main(int argc, char *argv[])
( (
writer.os(), writer.os(),
writer.nFaces(), writer.nFaces(),
1+nVolFields 1 + nVolFields
); );
// Write patchID field // Write patchID field
@ -947,8 +999,8 @@ int main(int argc, char *argv[])
// Write volFields // Write volFields
writer.write(vsf); writer.write(vsf);
writer.write(vvf); writer.write(vvf);
writer.write(vSpheretf); writer.write(vsptf);
writer.write(vSymmtf); writer.write(vsytf);
writer.write(vtf); writer.write(vtf);
if (!noPointValues) if (!noPointValues)
@ -964,8 +1016,8 @@ int main(int argc, char *argv[])
// Write pointFields // Write pointFields
writer.write(psf); writer.write(psf);
writer.write(pvf); writer.write(pvf);
writer.write(pSpheretf); writer.write(psptf);
writer.write(pSymmtf); writer.write(psytf);
writer.write(ptf); writer.write(ptf);
PrimitivePatchInterpolation<primitivePatch> pInter PrimitivePatchInterpolation<primitivePatch> pInter
@ -976,8 +1028,8 @@ int main(int argc, char *argv[])
// Write interpolated volFields // Write interpolated volFields
writer.write(pInter, vsf); writer.write(pInter, vsf);
writer.write(pInter, vvf); writer.write(pInter, vvf);
writer.write(pInter, vSpheretf); writer.write(pInter, vsptf);
writer.write(pInter, vSymmtf); writer.write(pInter, vsytf);
writer.write(pInter, vtf); writer.write(pInter, vtf);
} }
} }
@ -1063,7 +1115,7 @@ int main(int argc, char *argv[])
( (
writer.os(), writer.os(),
pp.size(), pp.size(),
ssf.size()+svf.size() ssf.size() + svf.size()
); );
writer.write(ssf); writer.write(ssf);
@ -1212,7 +1264,7 @@ int main(int argc, char *argv[])
fileNameList dirs(readDir(procVTK, fileType::directory)); fileNameList dirs(readDir(procVTK, fileType::directory));
label sz = dirs.size(); label sz = dirs.size();
dirs.setSize(sz+1); dirs.setSize(sz + 1);
dirs[sz] = "."; dirs[sz] = ".";
forAll(dirs, i) forAll(dirs, i)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -64,6 +64,7 @@ class internalWriter
std::ofstream os_; std::ofstream os_;
public: public:
// Constructors // Constructors
@ -87,6 +88,10 @@ public:
//- Write cellIDs //- Write cellIDs
void writeCellIDs(); void writeCellIDs();
//- Write generic GeometricFields
template<class Type, class GeoMesh>
void write(const UPtrList<const DimensionedField<Type, GeoMesh>>&);
//- Write generic GeometricFields //- Write generic GeometricFields
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
void write void write

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,6 +28,19 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
void Foam::internalWriter::write
(
const UPtrList<const DimensionedField<Type, GeoMesh>>& flds
)
{
forAll(flds, i)
{
writeFuns::write(os_, binary_, flds[i], vMesh_);
}
}
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::internalWriter::write void Foam::internalWriter::write
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -113,7 +113,7 @@ public:
( (
std::ostream&, std::ostream&,
const bool binary, const bool binary,
const GeometricField<Type, fvPatchField, volMesh>&, const DimensionedField<Type, volMesh>&,
const vtkMesh& const vtkMesh&
); );

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,7 +28,6 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Store List in dest
template<class Type> template<class Type>
void Foam::writeFuns::insert void Foam::writeFuns::insert
( (
@ -43,28 +42,12 @@ void Foam::writeFuns::insert
} }
//// Store List (indexed through map) in dest
//template<class Type>
//void Foam::writeFuns::insert
//(
// const labelList& map,
// const List<Type>& source,
// DynamicList<floatScalar>& dest
//)
//{
// forAll(map, i)
// {
// insert(source[map[i]], dest);
// }
//}
template<class Type> template<class Type>
void Foam::writeFuns::write void Foam::writeFuns::write
( (
std::ostream& os, std::ostream& os,
const bool binary, const bool binary,
const GeometricField<Type, fvPatchField, volMesh>& vvf, const DimensionedField<Type, volMesh>& df,
const vtkMesh& vMesh const vtkMesh& vMesh
) )
{ {
@ -74,18 +57,18 @@ void Foam::writeFuns::write
label nValues = mesh.nCells() + superCells.size(); label nValues = mesh.nCells() + superCells.size();
os << vvf.name() << ' ' << pTraits<Type>::nComponents << ' ' os << df.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nValues << " float" << std::endl; << nValues << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nValues); DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nValues);
insert(vvf.primitiveField(), fField); insert(df, fField);
forAll(superCells, superCelli) forAll(superCells, superCelli)
{ {
label origCelli = superCells[superCelli]; label origCelli = superCells[superCelli];
insert(vvf[origCelli], fField); insert(df[origCelli], fField);
} }
write(os, binary, fField); write(os, binary, fField);
} }