From 66c3cda39e25154c9a02d63d1f4c04e0ba1c7f2b Mon Sep 17 00:00:00 2001 From: HRN Date: Thu, 9 Jan 2025 19:16:18 +0330 Subject: [PATCH] Binary conversion from pointFiled files to vtk format - all vtk files are stored in the /particles/ folder - terminal output is modified - time series file are added. files with extntions .vtk.series can be loaded into paraview --- src/phasicFlow/fileSystem/fileSystem.cpp | 5 + src/phasicFlow/fileSystem/fileSystem.hpp | 3 + .../pointSorting/pointSorting.cpp | 4 +- .../pointStructure/pointStructure.cpp | 11 +- .../pointStructure/pointStructure.hpp | 2 +- .../Utilities/vtkFile/vtkByteSwapper.hpp | 96 ++++++++++ utilities/Utilities/vtkFile/vtkFile.cpp | 18 +- utilities/Utilities/vtkFile/vtkFile.hpp | 19 +- utilities/pFlowToVTK/CMakeLists.txt | 2 + utilities/pFlowToVTK/fileSeries.cpp | 85 +++++++++ utilities/pFlowToVTK/fileSeries.hpp | 41 +++++ utilities/pFlowToVTK/pFlowToVTK.cpp | 52 +++++- utilities/pFlowToVTK/pointFieldToVTK.cpp | 164 +++++++++++++----- utilities/pFlowToVTK/pointFieldToVTK.hpp | 64 +++++-- utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp | 50 ++++-- utilities/pFlowToVTK/triSurfaceFieldToVTK.hpp | 18 +- .../postprocessPhasicFlow/postprocess.cpp | 2 +- 17 files changed, 530 insertions(+), 106 deletions(-) create mode 100644 utilities/Utilities/vtkFile/vtkByteSwapper.hpp create mode 100644 utilities/pFlowToVTK/fileSeries.cpp create mode 100644 utilities/pFlowToVTK/fileSeries.hpp diff --git a/src/phasicFlow/fileSystem/fileSystem.cpp b/src/phasicFlow/fileSystem/fileSystem.cpp index a4275f56..8cccf447 100644 --- a/src/phasicFlow/fileSystem/fileSystem.cpp +++ b/src/phasicFlow/fileSystem/fileSystem.cpp @@ -167,6 +167,11 @@ pFlow::fileSystem pFlow::fileSystem::canonical return res; } +pFlow::fileSystem pFlow::fileSystem::relative(const fileSystem &base)const +{ + return fileSystem( std::filesystem::relative(path_, base.path_)); +} + bool pFlow::fileSystem::dirExist ( ) const diff --git a/src/phasicFlow/fileSystem/fileSystem.hpp b/src/phasicFlow/fileSystem/fileSystem.hpp index 9f0d63d7..61b97ca1 100644 --- a/src/phasicFlow/fileSystem/fileSystem.hpp +++ b/src/phasicFlow/fileSystem/fileSystem.hpp @@ -175,6 +175,9 @@ public: /// Canonical path of this (it should exist) fileSystem canonical()const; + /// relative path of this this with respect to base + fileSystem relative(const fileSystem& base)const; + /// Only operate on dir path /// Check if the dir path exists bool dirExist()const; diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure/pointSorting/pointSorting.cpp b/src/phasicFlow/structuredData/pointStructure/pointStructure/pointSorting/pointSorting.cpp index c8dda774..e318551d 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure/pointSorting/pointSorting.cpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure/pointSorting/pointSorting.cpp @@ -36,9 +36,9 @@ pFlow::pointSorting::pointSorting(const dictionary & dict) ) { if( performSorting_() ) - REPORT(1)<<"Point sorting is "<subDictOrCreate("pointSorting")), + //pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")), boundaries_ ( *this @@ -130,6 +130,8 @@ pFlow::pointStructure::pointStructure "Error in reading from file "<(simulationDomain_->subDictOrCreate("pointSorting")); } @@ -155,7 +157,7 @@ pFlow::pointStructure::pointStructure( ( simulationDomain::create(control) ), - pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")), + //pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")), boundaries_ ( *this @@ -167,15 +169,16 @@ pFlow::pointStructure::pointStructure( "Error in seting up pointStructure"<(simulationDomain_->subDictOrCreate("pointSorting")); } bool pFlow::pointStructure::beforeIteration() { const timeInfo ti = TimeInfo(); - if(pointSorting_.sortTime(ti.iter(), ti.t(), ti.dt())) + if(pointSorting_().sortTime(ti.iter(), ti.t(), ti.dt())) { - auto sortedIndices = pointSorting_.getSortedIndices( + auto sortedIndices = pointSorting_().getSortedIndices( simulationDomain_().globalBox(), pointPositionDevice(), activePointsMaskDevice() diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure/pointStructure.hpp b/src/phasicFlow/structuredData/pointStructure/pointStructure/pointStructure.hpp index e1a60ff2..929c7473 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure/pointStructure.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure/pointStructure.hpp @@ -54,7 +54,7 @@ private: //// - data members uniquePtr simulationDomain_ = nullptr; - pointSorting pointSorting_; + uniquePtr pointSorting_ = nullptr; boundaryList boundaries_; diff --git a/utilities/Utilities/vtkFile/vtkByteSwapper.hpp b/utilities/Utilities/vtkFile/vtkByteSwapper.hpp new file mode 100644 index 00000000..c1b78d3b --- /dev/null +++ b/utilities/Utilities/vtkFile/vtkByteSwapper.hpp @@ -0,0 +1,96 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +#ifndef __vtkByteSwapper_h__ +#define __vtkByteSwapper_h__ + +namespace pFlow +{ + +/* +This utility is used to re-order bytes when writing data in binary format to vtk file +These lines of code are exactly copied from the source code of https://github.com/Kitware/VTK/ +*/ + + +template +struct vtkByteSwapper; + +/// @brief with char, no re-ordering is required +template <> +struct vtkByteSwapper<1> +{ + static inline void Swap(char*) {} +}; + +/// @brief re-order 2-byte data +template <> +struct vtkByteSwapper<2> +{ + static inline void Swap(char* data) + { + const uint16_t& ref16 = *reinterpret_cast(data); + *reinterpret_cast(data) = (ref16 >> 8) | (ref16 << 8); + } +}; + +/// @brief re-order 4-byte data +template <> +struct vtkByteSwapper<4> +{ + static inline void Swap(char* data) + { + const uint32_t& ref32 = *reinterpret_cast(data); + *reinterpret_cast(data) = + (ref32 >> 24) | (ref32 << 24) | ((ref32 & 0x00ff0000) >> 8) | ((ref32 & 0x0000ff00) << 8); + } +}; + +/// @brief re-order of 8-byte data +template <> +struct vtkByteSwapper<8> +{ + static inline void Swap(char* data) + { + const uint64_t& ref64 = *reinterpret_cast(data); + *reinterpret_cast(data) = (ref64 >> 56) | (ref64 << 56) | + ((ref64 & 0x00ff000000000000) >> 40) | ((ref64 & 0x000000000000ff00) << 40) | + ((ref64 & 0x0000ff0000000000) >> 24) | ((ref64 & 0x0000000000ff0000) << 24) | + ((ref64 & 0x000000ff00000000) >> 8) | ((ref64 & 0x00000000ff000000) << 8); + } +}; + +template +inline T byteSwaper(const T& p) +{ + union + { + T value; + char data[sizeof(T)]; + } temp = { p }; + vtkByteSwapper::Swap(temp.data); + return temp.value; +} + + + +} // pFlow + +#endif //__vtkByteSwapper_h__ diff --git a/utilities/Utilities/vtkFile/vtkFile.cpp b/utilities/Utilities/vtkFile/vtkFile.cpp index dc4b9039..77d08773 100755 --- a/utilities/Utilities/vtkFile/vtkFile.cpp +++ b/utilities/Utilities/vtkFile/vtkFile.cpp @@ -23,7 +23,7 @@ Licence: bool pFlow::vtkFile::openStream(bool wHeader) { - oStream_ = makeUnique( fileName(), false, append_ ); + oStream_ = makeUnique( fileName(), binary_, append_ ); if( !oStream_ )return false; if(wHeader) return writeHeader(); @@ -36,11 +36,13 @@ bool pFlow::vtkFile::vtkFile::writeHeader() if(!oStream_) return false; - oStream_() << "# vtk DataFile Version 2.0" << endl; + oStream_() << "# vtk DataFile Version 3.0" << endl; oStream_() << "vtk file for time : " << time_ << endl; - - oStream_() << "ASCII" << endl; + if(binary_) + oStream_() << "BINARY" << endl; + else + oStream_() << "ASCII" << endl; if( oStream_().fail() ) return false; @@ -53,13 +55,15 @@ pFlow::vtkFile::vtkFile const fileSystem dir, const word& bName, real time, + bool bnry, bool append ) : - dirPath_(dir), - baseName_(bName), + binary_(bnry), + append_(append), time_(time), - append_(append) + dirPath_(dir), + baseName_(bName) { if(!openStream(!append)) diff --git a/utilities/Utilities/vtkFile/vtkFile.hpp b/utilities/Utilities/vtkFile/vtkFile.hpp index 9d3ad79e..ffb1ff6b 100755 --- a/utilities/Utilities/vtkFile/vtkFile.hpp +++ b/utilities/Utilities/vtkFile/vtkFile.hpp @@ -34,15 +34,17 @@ class vtkFile { protected: - fileSystem dirPath_; + uniquePtr oStream_= nullptr; - word baseName_; - - real time_ = 0.0; + bool binary_ = false; bool append_=false; - uniquePtr oStream_= nullptr; + real time_ = 0.0; + + fileSystem dirPath_; + + word baseName_; bool openStream(bool wHeader); @@ -54,6 +56,7 @@ public: const fileSystem dir, const word& bName, real time, + bool bnry, bool append = false); virtual ~vtkFile() = default; @@ -87,6 +90,12 @@ public: return false; } + inline + bool binary()const + { + return binary_; + } + virtual fileSystem fileName()const; }; diff --git a/utilities/pFlowToVTK/CMakeLists.txt b/utilities/pFlowToVTK/CMakeLists.txt index a79a7128..71cac3de 100644 --- a/utilities/pFlowToVTK/CMakeLists.txt +++ b/utilities/pFlowToVTK/CMakeLists.txt @@ -1,8 +1,10 @@ set(source_files +fileSeries.cpp pointFieldToVTK.cpp triSurfaceFieldToVTK.cpp pFlowToVTK.cpp + #geometric.cpp ) set(link_lib phasicFlow Kokkos::kokkos Utilities) diff --git a/utilities/pFlowToVTK/fileSeries.cpp b/utilities/pFlowToVTK/fileSeries.cpp new file mode 100644 index 00000000..13764fd6 --- /dev/null +++ b/utilities/pFlowToVTK/fileSeries.cpp @@ -0,0 +1,85 @@ +#include "fileSeries.hpp" +#include "oFstream.hpp" +#include "streams.hpp" + +void pFlow::PFtoVTK::fileSeries::writeOneBaseName(const word &baseName) +{ + auto& fList = timeFiles_[baseName]; + word fileName = baseName + ".vtk.series"; + oFstream os(destDir_+fileName); + + REPORT(1)<<"Writing to "<second; + os<<"\", \"time\" :"; + os<first; + if(iter == lastItem) + os<<"}\n"; + else + os<<"},\n"; + } + os<<" ]\n"; + os<<"}\n"; + +} + +pFlow::PFtoVTK::fileSeries::fileSeries(const fileSystem dest) + : destDir_(dest) +{ + + +} + +pFlow::PFtoVTK::fileSeries::~fileSeries() +{ + REPORT(0)<<"Writing time series files..."<second.insertIf(time, relFileName); + } + else + { + TimeFileType newList; + newList.insertIf(time, relFileName); + return timeFiles_.insertIf(baseName, newList); + } + +} + +bool pFlow::PFtoVTK::fileSeries::addTimeFile(const wordList &baseNames, real time, const wordList &fileNames) +{ + if(baseNames.size()!= fileNames.size() ) + { + fatalErrorInFunction<<"sizes of base names and file names are not equal\n"; + return false; + } + + for(size_t i=0; i; + + Map timeFiles_; + + fileSystem destDir_; + + void writeOneBaseName(const word& baseName); + +public: + + fileSeries(const fileSystem dest); + + ~fileSeries(); + + + bool addTimeFile(const word& baseName, real time, const word& fileName); + + bool addTimeFile(const wordList& baseNames, real time, const wordList& fileNames); +}; + +} + + +#endif //__fileSeries_hpp__ \ No newline at end of file diff --git a/utilities/pFlowToVTK/pFlowToVTK.cpp b/utilities/pFlowToVTK/pFlowToVTK.cpp index 8edbbc3c..d17b8798 100755 --- a/utilities/pFlowToVTK/pFlowToVTK.cpp +++ b/utilities/pFlowToVTK/pFlowToVTK.cpp @@ -27,8 +27,10 @@ Licence: #include "phasicFlowKokkos.hpp" #include "pointFieldToVTK.hpp" #include "triSurfaceFieldToVTK.hpp" +#include "fileSeries.hpp" //#include "readControlDict.hpp" +bool bindaryOutput__; int main(int argc, char** argv ) { @@ -52,6 +54,11 @@ int main(int argc, char** argv ) noParticle, "Do not convert particle fields to VTK file"); + bindaryOutput__ = false; + cmds.add_flag("-b, --binary", + bindaryOutput__, + "Wrtie vtk file (for particles only) in binary format. Default is ASCII"); + cmds.addOption("-o,--out-folder", outFolder, "path to output folder of VTK", @@ -85,9 +92,18 @@ int main(int argc, char** argv ) #include "initialize_Control.hpp" + if(!bindaryOutput__) + { + INFORMATION<<"Writing vtk file in binray format will accelerate the conversion (5~10x)"<< + " and visualization in paraview."<< + " Consider addig flag -b or --binary in the command line."<(0.0)) ) + !pFlow::equal(folders.time(),static_cast(0.0)), + fileName + ) ) { fatalExit; } - } + } + + timeSeries.addTimeFile("particles", folders.time(), fileName); + } pFlow::output<>> Writing pointStructure to vtk file with " << Yellow_Text(pStruct.numActive())<< " active particles" << END_REPORT; @@ -62,13 +67,14 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFields( if (fieldHeader.headerOk(true)) { + // 64-bit intergers are not supported for convertion if( convertRealx3TypePointField(vtk(), fieldHeader, pStruct) || convertRealTypePointField(vtk(), fieldHeader, pStruct) || convertIntPointField(vtk(), fieldHeader, pStruct) || - convertIntPointField(vtk(), fieldHeader, pStruct) || + //convertIntPointField(vtk(), fieldHeader, pStruct) || convertIntPointField(vtk(), fieldHeader, pStruct) || - convertIntPointField(vtk(), fieldHeader, pStruct)|| + //convertIntPointField(vtk(), fieldHeader, pStruct)|| fieldHeader.objectName() == pointStructureFile__ ) { continue; @@ -91,7 +97,8 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( const fileSystem &destPath, const word &bName, const wordVector &fieldsName, - bool mustExist) + bool mustExist, + word& filename) { fileSystem timeFolder = control.time().path(); // check if pointStructure exist in this folder @@ -111,11 +118,14 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( return true; } - vtkFile vtk(destPath, bName, control.time().currentTime()); + vtkFile vtk(destPath, bName, control.time().currentTime(), bindaryOutput__); if (!vtk) return false; + + filename = vtk.fileName().wordPath(); + REPORT(1); auto pStruct = pointStructure(control); // get a list of files in this timeFolder; @@ -123,7 +133,7 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( auto posVec = pStruct.pointPositionHost(); auto *pos = posVec.data(); - REPORT(1) << "Writing pointStructure to vtk file with " << + REPORT(2) << ">>> Writing pointStructure to vtk file with " << Yellow_Text(pStruct.numActive()) << " active particles" << END_REPORT; @@ -148,12 +158,13 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( if (fieldHeader.headerOk(true)) { if ( + // 64-bit intergers are not supported for convertion convertRealx3TypePointField(vtk(), fieldHeader, pStruct) || convertRealTypePointField(vtk(), fieldHeader, pStruct) || convertIntPointField(vtk(), fieldHeader, pStruct) || - convertIntPointField(vtk(), fieldHeader, pStruct) || + // convertIntPointField(vtk(), fieldHeader, pStruct) || convertIntPointField(vtk(), fieldHeader, pStruct) || - convertIntPointField(vtk(), fieldHeader, pStruct) || + //convertIntPointField(vtk(), fieldHeader, pStruct) || fieldHeader.objectName() == pointStructureFile__ ) { continue; @@ -176,7 +187,7 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( } else { - REPORT(1) << "Could not find " << Yellow_Text(fieldAddress) << + REPORT(2) << "Could not find " << Yellow_Text(fieldAddress) << ". Skipping this field . . ." << END_REPORT; } } @@ -185,45 +196,79 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( return true; } + bool pFlow::PFtoVTK::addUndstrcuturedGridField( - iOstream &os, + Ostream &os, realx3 *position, uint32 numPoints) { os << "DATASET UNSTRUCTURED_GRID\n"; - os << "POINTS " << numPoints << " float\n"; - + if (numPoints == 0) return true; - for (uint32 i = 0; i < numPoints; i++) - { - os << position[i].x() << - ' ' << position[i].y() << - ' ' << position[i].z() << '\n'; + os << "POINTS " << numPoints << " float"<<'\n'; + if(bindaryOutput__) + { + for(uint32 i=0; i(position[i].x())); + float y = byteSwaper(static_cast(position[i].y())); + float z = byteSwaper(static_cast(position[i].z())); + os.stdStream().write(reinterpret_cast(&x), sizeof(x)); + os.stdStream().write(reinterpret_cast(&y), sizeof(y)); + os.stdStream().write(reinterpret_cast(&z), sizeof(z)); + } + os<<'\n'; + os << "CELLS " << numPoints << ' ' << 2 * numPoints<<'\n'; + + const int32 one_ro = byteSwaper(1); + for (int i = 0; i < numPoints; i++) + { + int pN = byteSwaper(i); + os.stdStream().write(reinterpret_cast(&one_ro), sizeof(one_ro)); + os.stdStream().write(reinterpret_cast(&pN), sizeof(pN)); + } + os<<'\n'; + os << "CELL_TYPES " << numPoints<<'\n'; + for (int32 i = 0; i < numPoints; i++) + { + os.stdStream().write(reinterpret_cast(&one_ro), sizeof(one_ro)); + } + os<<'\n'; } - - os << "CELLS " << numPoints << ' ' << 2 * numPoints << '\n'; - for (uint32 i = 0; i < numPoints; i++) + else { - os << 1 << ' ' << i << '\n'; + for (uint32 i = 0; i < numPoints; i++) + { + os << position[i].x() << + ' ' << position[i].y() << + ' ' << position[i].z() << '\n'; + } + + os << "CELLS " << numPoints << ' ' << 2 * numPoints << '\n'; + for (uint32 i = 0; i < numPoints; i++) + { + os << 1 << ' ' << i << '\n'; + } + + os << "CELL_TYPES " << numPoints << '\n'; + + for (int32 i = 0; i < numPoints; i++) + { + os << 1 << '\n'; + } + } - - os << "CELL_TYPES " << numPoints << '\n'; - - for (int32 i = 0; i < numPoints; i++) - { - os << 1 << '\n'; - } - + os << "POINT_DATA " << numPoints << endl; return true; } bool pFlow::PFtoVTK::convertRealTypePointField( - iOstream &os, + Ostream &os, const IOfileHeader &header, pointStructure &pStruct) { @@ -232,6 +277,7 @@ bool pFlow::PFtoVTK::convertRealTypePointField( if (!checkFieldType(objectType)) return false; + REPORT(1); auto field = realPointField_H( header, pStruct, @@ -239,7 +285,7 @@ bool pFlow::PFtoVTK::convertRealTypePointField( real const *data = field.deviceViewAll().data(); - REPORT(1) << "writing " << Green_Text(header.objectName()) << + REPORT(2) << ">>> Writing " << Green_Text(header.objectName()) << " field to vtk." << END_REPORT; return addRealPointField( @@ -250,7 +296,7 @@ bool pFlow::PFtoVTK::convertRealTypePointField( } bool pFlow::PFtoVTK::convertRealx3TypePointField( - iOstream &os, + Ostream &os, const IOfileHeader &header, pointStructure &pStruct) { @@ -259,6 +305,7 @@ bool pFlow::PFtoVTK::convertRealx3TypePointField( if (!checkFieldType(objectType)) return false; + REPORT(1); auto field = realx3PointField_H( header, pStruct, @@ -266,7 +313,7 @@ bool pFlow::PFtoVTK::convertRealx3TypePointField( realx3 const *data = field.deviceViewAll().data(); - REPORT(1) << "writing " << Green_Text(header.objectName()) << + REPORT(2) << ">>> Writing " << Green_Text(header.objectName()) << " field to vtk." << END_REPORT; return addRealx3PointField( @@ -277,7 +324,7 @@ bool pFlow::PFtoVTK::convertRealx3TypePointField( } bool pFlow::PFtoVTK::addRealPointField( - iOstream &os, + Ostream &os, const word &fieldName, const real *field, uint32 numData) @@ -287,15 +334,28 @@ bool pFlow::PFtoVTK::addRealPointField( os << "FIELD FieldData 1\n" << fieldName << " 1 " << numData << " float\n"; - for (uint32 i = 0; i < numData; ++i) + if(bindaryOutput__) { - os << field[i] << '\n'; + for (uint32 i = 0; i < numData; ++i) + { + float x = byteSwaper(static_cast(field[i])); + os.stdStream().write(reinterpret_cast(&x), sizeof(x)); + } } + else + { + for (uint32 i = 0; i < numData; ++i) + { + os << field[i] << '\n'; + } + + } + return true; } bool pFlow::PFtoVTK::addRealx3PointField( - iOstream &os, + Ostream &os, const word &fieldName, const realx3 *field, uint32 numData) @@ -305,12 +365,30 @@ bool pFlow::PFtoVTK::addRealx3PointField( os << "FIELD FieldData 1\n" << fieldName << " 3 " << numData << " float\n"; - for (uint32 i = 0; i < numData; ++i) + + if(bindaryOutput__) { - os << field[i].x() << - ' ' << field[i].y() << - ' ' << field[i].z() << '\n'; + for(uint32 i=0; i(field[i].x())); + float y = byteSwaper(static_cast(field[i].y())); + float z = byteSwaper(static_cast(field[i].z())); + os.stdStream().write(reinterpret_cast(&x), sizeof(x)); + os.stdStream().write(reinterpret_cast(&y), sizeof(y)); + os.stdStream().write(reinterpret_cast(&z), sizeof(z)); + } + os<<'\n'; } + else + { + for (uint32 i = 0; i < numData; ++i) + { + os << field[i].x() << + ' ' << field[i].y() << + ' ' << field[i].z() << '\n'; + } + } + return true; } diff --git a/utilities/pFlowToVTK/pointFieldToVTK.hpp b/utilities/pFlowToVTK/pointFieldToVTK.hpp index 8b24088c..eed2d60d 100755 --- a/utilities/pFlowToVTK/pointFieldToVTK.hpp +++ b/utilities/pFlowToVTK/pointFieldToVTK.hpp @@ -24,6 +24,9 @@ Licence: #include "systemControl.hpp" #include "pointStructure.hpp" #include "pointFields.hpp" +#include "vtkByteSwapper.hpp" + +extern bool bindaryOutput__; namespace pFlow::PFtoVTK { @@ -31,45 +34,47 @@ namespace pFlow::PFtoVTK bool convertTimeFolderPointFields( systemControl &control, const fileSystem &destPath, - const word &bName); + const word &bName, + word& filename); bool convertTimeFolderPointFieldsSelected( systemControl &control, const fileSystem &destPath, const word &bName, const wordVector &fieldsName, - bool mustExist); + bool mustExist, + word& filename); bool addUndstrcuturedGridField( - iOstream &os, + Ostream &os, realx3 *position, uint32 numPoints); bool convertRealTypePointField( - iOstream &os, + Ostream &os, const IOfileHeader &header, pointStructure &pStruct); bool convertRealx3TypePointField( - iOstream &os, + Ostream &os, const IOfileHeader &header, pointStructure &pStruct); template bool addIntPointField( - iOstream &os, + Ostream &os, const word &fieldName, IntType *field, uint32 numData); bool addRealPointField( - iOstream &os, + Ostream &os, const word &fieldName, const real *field, uint32 numData); bool addRealx3PointField( - iOstream &os, + Ostream &os, const word &fieldName, const realx3 *field, uint32 numData); @@ -87,7 +92,7 @@ namespace pFlow::PFtoVTK template inline bool convertIntPointField( - iOstream &os, + Ostream &os, const IOfileHeader &header, pointStructure &pStruct) { @@ -101,6 +106,7 @@ namespace pFlow::PFtoVTK return false; } + REPORT(1); auto field = PointFieldType( header, pStruct, @@ -108,7 +114,7 @@ namespace pFlow::PFtoVTK const IntType *data = field.deviceViewAll().data(); - REPORT(1) << "writing " << Green_Text(header.objectName()) << " field to vtk.\n"; + REPORT(2) << ">>> Writing " << Green_Text(header.objectName()) << " field to vtk.\n"; return addIntPointField( os, @@ -119,21 +125,49 @@ namespace pFlow::PFtoVTK template inline bool addIntPointField( - iOstream &os, + Ostream &os, const word &fieldName, IntType *field, uint32 numData) { + if (numData == 0) return true; - os << "FIELD FieldData 1\n" - << fieldName << " 1 " << numData << " int\n"; - for (uint32 i = 0; i < numData; ++i) + if(std::is_same_v || std::is_same_v ) { - os << field[i] << '\n'; + os << "FIELD FieldData 1\n" + << fieldName << " 1 " << numData << " int\n"; + } + else if( std::is_same_v|| std::is_same_v) + { + os << "FIELD FieldData 1\n" + << fieldName << " 1 " << numData << " unsigned_int\n"; + } + else + { + WARNING<<"Field "<< fieldName<< " has invalid data type for conversion. Type is " + <()<(&val), sizeof(IntType)); + } + os<<'\n'; + } + else + { + for (uint32 i = 0; i < numData; ++i) + { + os << field[i] << '\n'; + } + } + return true; } diff --git a/utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp b/utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp index b7151db7..2d6987a2 100644 --- a/utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp +++ b/utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp @@ -6,10 +6,15 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields( systemControl &control, const fileSystem &destPath, const word &bName, - bool separate) + bool separate, + wordList& surfNames, + wordList& fileNames) { auto timeFolder = control.geometry().path(); + + surfNames.clear(); + fileNames.clear(); // check if pointStructure exist in this folder IOfileHeader triSurfaeHeader( @@ -40,7 +45,9 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields( triSurfaceObj, destPath, control.time().currentTime(), - bName); + bName, + surfNames, + fileNames); } else { @@ -48,12 +55,14 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields( triSurfaceObj, destPath, control.time().currentTime(), - bName ); + bName, + surfNames, + fileNames ); } } bool pFlow::TSFtoVTK::triSurfaceToVTK( - iOstream &os, + Ostream &os, const realx3 *points, const uint32x3 *vertices, const subSurface &subSurf) @@ -97,7 +106,7 @@ bool pFlow::TSFtoVTK::triSurfaceToVTK( } bool pFlow::TSFtoVTK::triSurfaceToVTK( - iOstream &os, + Ostream &os, const realx3 *points, const uint32x3 *vertices, uint32 numPoints, @@ -143,10 +152,12 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSingle multiTriSurface &surface, const fileSystem &destPath, real time, - const word &bName + const word &bName, + wordList& surfNames, + wordList& fileNames ) { - vtkFile vtk(destPath, bName, time); + vtkFile vtk(destPath, bName, time, false); if (!vtk) return false; @@ -157,7 +168,7 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSingle realx3 const* pData = hPoints.data(); uint32x3 const* vData = hVertices.data(); - REPORT(1) << "Wrting triSurface geometry to vtk file "<< + REPORT(2) << "Wrting surface to "<< Green_Text(vtk.fileName()) << END_REPORT; if (! triSurfaceToVTK( @@ -189,6 +200,9 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSingle convertRealx3TypetriSurfaceField(vtk(), fieldHeader, surface); } } + + surfNames.push_back(bName); + fileNames.push_back(vtk.fileName().wordPath()); output<