diff --git a/src/fileFormats/vtk/vtkWriteOps.C b/src/fileFormats/vtk/vtkWriteOps.C index 67c2216d3d..a3dffc236c 100644 --- a/src/fileFormats/vtk/vtkWriteOps.C +++ b/src/fileFormats/vtk/vtkWriteOps.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,7 +90,7 @@ void Foam::vtkWriteOps::write os.write ( reinterpret_cast(fField.begin()), - fField.size()*sizeof(float) + fField.size()*sizeof(floatScalar) ); os << std::endl; @@ -228,7 +228,7 @@ void Foam::vtkWriteOps::writePointDataHeader void Foam::vtkWriteOps::insert(const scalar src, DynamicList& dest) { - dest.append(float(src)); + dest.append(cast(src)); } @@ -240,7 +240,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -253,7 +253,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -264,12 +264,12 @@ void Foam::vtkWriteOps::insert DynamicList& dest ) { - dest.append(float(src.xx())); - dest.append(float(src.yy())); - dest.append(float(src.zz())); - dest.append(float(src.xy())); - dest.append(float(src.yz())); - dest.append(float(src.xz())); + dest.append(cast(src.xx())); + dest.append(cast(src.yy())); + dest.append(cast(src.zz())); + dest.append(cast(src.xy())); + dest.append(cast(src.yz())); + dest.append(cast(src.xz())); } @@ -281,7 +281,7 @@ void Foam::vtkWriteOps::insert { for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt) { - dest.append(float(src[cmpt])); + dest.append(cast(src[cmpt])); } } @@ -301,7 +301,7 @@ void Foam::vtkWriteOps::insert { forAll(map, i) { - dest.append(float(source[map[i]])); + dest.append(cast(source[map[i]])); } } diff --git a/src/fileFormats/vtk/vtkWriteOps.H b/src/fileFormats/vtk/vtkWriteOps.H index 494c54f8fc..5643d3b8ff 100644 --- a/src/fileFormats/vtk/vtkWriteOps.H +++ b/src/fileFormats/vtk/vtkWriteOps.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,6 +58,17 @@ namespace vtkWriteOps //- Swap halves of word void swapWords(const label nWords, label* words32); + //- Cast an integer to the corresponding VTK write type. Does nothing. + inline label cast(const label& x); + + //- Cast a float to the corresponding VTK write type. Does nothing. + inline floatScalar cast(const floatScalar& x); + + //- Cast a scalar to the corresponding VTK write type. Clips to + // pTraits::max. + template + inline floatScalar cast(const Scalar& x); + //- Write header void writeHeader ( @@ -66,6 +77,7 @@ namespace vtkWriteOps const std::string& title ); + //- Write cell data header void writeCellDataHeader ( std::ostream&, @@ -73,6 +85,7 @@ namespace vtkWriteOps const label nFields ); + //- Write point data header void writePointDataHeader ( std::ostream&, @@ -80,7 +93,6 @@ namespace vtkWriteOps const label nFields ); - //- Write floats ascii or binary. // If binary optionally in-place swaps argument void write(std::ostream& os, const bool binary, List& fField); @@ -97,7 +109,6 @@ namespace vtkWriteOps // If binary optionally in-place swaps argument void write(std::ostream&, const bool, DynamicList