From 815b134e1ea3793f7935312bfc3a0d47d8b89587 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Sat, 30 Mar 2024 01:42:51 -0700 Subject: [PATCH 1/2] pFlowToVTK enhanced - pointField conversion is completed, tested (finalized). - geometry conversion is not complete yet. --- utilities/pFlowToVTK/CMakeLists.txt | 1 + utilities/pFlowToVTK/pFlowToVTK.cpp | 13 +- utilities/pFlowToVTK/pointFieldToVTK.cpp | 332 +++++++++++++++ utilities/pFlowToVTK/pointFieldToVTK.hpp | 499 +++++------------------ 4 files changed, 438 insertions(+), 407 deletions(-) create mode 100644 utilities/pFlowToVTK/pointFieldToVTK.cpp diff --git a/utilities/pFlowToVTK/CMakeLists.txt b/utilities/pFlowToVTK/CMakeLists.txt index 353daa6b..15f37471 100644 --- a/utilities/pFlowToVTK/CMakeLists.txt +++ b/utilities/pFlowToVTK/CMakeLists.txt @@ -1,5 +1,6 @@ set(source_files +pointFieldToVTK.cpp pFlowToVTK.cpp #geometric.cpp ) diff --git a/utilities/pFlowToVTK/pFlowToVTK.cpp b/utilities/pFlowToVTK/pFlowToVTK.cpp index 9046fb63..be53c75d 100755 --- a/utilities/pFlowToVTK/pFlowToVTK.cpp +++ b/utilities/pFlowToVTK/pFlowToVTK.cpp @@ -78,7 +78,7 @@ int main(int argc, char** argv ) "a space separated lists of time folders, or a strided range begin:stride:end, or an interval begin:end", " "); - bool isCoupling = false; + //bool isCoupling = false; if(!cmds.parse(argc, argv)) return 0; @@ -88,8 +88,8 @@ int main(int argc, char** argv ) timeFolder folders(Control); - fileSystem destFolder = fileSystem(outFolder)/word(geometryFolder__); - fileSystem destFolderField = fileSystem(outFolder); + auto destFolder = fileSystem(outFolder)/word(geometryFolder__); + auto destFolderField = fileSystem(outFolder); wordList geomfiles{"triSurface"}; @@ -141,9 +141,8 @@ int main(int argc, char** argv ) } }else { - /*if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( - folders.folder(), - folders.time(), + if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( + Control, destFolderField, "sphereFields", fields, @@ -151,7 +150,7 @@ int main(int argc, char** argv ) ) { fatalExit; - }*/ + } } } diff --git a/utilities/pFlowToVTK/pointFieldToVTK.cpp b/utilities/pFlowToVTK/pointFieldToVTK.cpp new file mode 100644 index 00000000..f2e076cd --- /dev/null +++ b/utilities/pFlowToVTK/pointFieldToVTK.cpp @@ -0,0 +1,332 @@ +#include + +#include "vtkFile.hpp" +#include "vocabs.hpp" +#include "pointFieldToVTK.hpp" + +bool pFlow::PFtoVTK::convertTimeFolderPointFields( + systemControl &control, + const fileSystem &destPath, + const word &bName) +{ + + fileSystem timeFolder = control.time().path(); + // check if pointStructure exist in this folder + IOfileHeader pStructHeader( + objectFile( + pointStructureFile__, + timeFolder, + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS)); + + if (!pStructHeader.headerOk(true)) + { + output << yellowColor << "Time folder " << + control.time().path() << " does not contain any pStructure data file."<< + " Skipping this folder . . ."<< defaultColor << nl; + return true; + } + + vtkFile vtk(destPath, bName, control.time().currentTime()); + + if (!vtk) + return false; + + auto pStruct = pointStructure(control); + + // get a list of files in this timeFolder; + + auto posVec = pStruct.pointPositionHost(); + auto *pos = posVec.data(); + + REPORT(1) << "Writing pointStructure to vtk file with " << + Yellow_Text(pStruct.numActive())<< + " active particles" << END_REPORT; + + addUndstrcuturedGridField( + vtk(), + pos, + pStruct.numActive()); + + auto fileList = containingFiles(timeFolder); + + for (const auto &file : fileList) + { + + IOfileHeader fieldHeader( + objectFile( + file.fileName(), + file.dirPath(), + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS)); + + if (fieldHeader.headerOk(true)) + { + 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)|| + fieldHeader.objectName() == pointStructureFile__ ) + { + continue; + } + else + { + WARNING << " This object type, " << + fieldHeader.objectType() << " is not supported" << + END_WARNING; + } + } + output << endl; + } + + return true; +} + +bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected( + systemControl &control, + const fileSystem &destPath, + const word &bName, + const wordVector &fieldsName, + bool mustExist) +{ + fileSystem timeFolder = control.time().path(); + // check if pointStructure exist in this folder + IOfileHeader pStructHeader( + objectFile( + pointStructureFile__, + timeFolder, + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS)); + + if (!pStructHeader.headerOk(true)) + { + output << yellowColor << "Time folder " << + control.time().path() << + " does not contain any pStructure data file."<< + " Skipping this folder . . ."<< defaultColor << nl; + return true; + } + + vtkFile vtk(destPath, bName, control.time().currentTime()); + + if (!vtk) + return false; + + auto pStruct = pointStructure(control); + + // get a list of files in this timeFolder; + + auto posVec = pStruct.pointPositionHost(); + auto *pos = posVec.data(); + + REPORT(1) << "Writing pointStructure to vtk file with " << + Yellow_Text(pStruct.numActive()) + << " active particles" << END_REPORT; + + addUndstrcuturedGridField( + vtk(), + pos, + pStruct.numActive()); + + auto fileList = containingFiles(timeFolder); + + for (const auto &fname : fieldsName) + { + fileSystem fieldAddress = timeFolder + fname; + + IOfileHeader fieldHeader( + objectFile( + fname, + timeFolder, + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS)); + + if (fieldHeader.headerOk(true)) + { + 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) || + fieldHeader.objectName() == pointStructureFile__ ) + { + continue; + } + else + { + + WARNING << " This object type, " << + fieldHeader.objectType() << " is not supported" << + END_WARNING; + } + } + else + { + if (mustExist) + { + fatalErrorInFunction << "Field " << fieldAddress << + " does not exist." << endl; + return false; + } + else + { + REPORT(1) << "Could not find " << Yellow_Text(fieldAddress) << + ". Skipping this field . . ." << END_REPORT; + } + } + } + + return true; +} + +bool pFlow::PFtoVTK::addUndstrcuturedGridField( + iOstream &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 << "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 << "POINT_DATA " << numPoints << endl; + + return true; +} + +bool pFlow::PFtoVTK::convertRealTypePointField( + iOstream &os, + const IOfileHeader &header, + pointStructure &pStruct) +{ + word objectType = header.objectType(); + + if (!checkFieldType(objectType)) + return false; + + auto field = realPointField_H( + header, + pStruct, + static_cast(0)); + + real const *data = field.deviceViewAll().data(); + + REPORT(1) << "writing " << Green_Text(header.objectName()) << + " field to vtk." << END_REPORT; + + return addRealPointField( + os, + header.objectName(), + data, + pStruct.numActive()); +} + +bool pFlow::PFtoVTK::convertRealx3TypePointField( + iOstream &os, + const IOfileHeader &header, + pointStructure &pStruct) +{ + word objectType = header.objectType(); + + if (!checkFieldType(objectType)) + return false; + + auto field = realx3PointField_H( + header, + pStruct, + {0.0, 0.0, 0.0}); + + realx3 const *data = field.deviceViewAll().data(); + + REPORT(1) << "writing " << Green_Text(header.objectName()) << + " field to vtk." << END_REPORT; + + return addRealx3PointField( + os, + header.objectName(), + data, + pStruct.numActive()); +} + +bool pFlow::PFtoVTK::addRealPointField( + iOstream &os, + const word &fieldName, + const real *field, + uint32 numData) +{ + if (numData == 0) + return true; + + os << "FIELD FieldData 1\n" + << fieldName << " 1 " << numData << " float\n"; + for (uint32 i = 0; i < numData; ++i) + { + os << field[i] << '\n'; + } + return true; +} + +bool pFlow::PFtoVTK::addRealx3PointField( + iOstream &os, + const word &fieldName, + const realx3 *field, + uint32 numData) +{ + if (numData == 0) + return true; + + os << "FIELD FieldData 1\n" + << fieldName << " 3 " << numData << " float\n"; + for (uint32 i = 0; i < numData; ++i) + { + os << field[i].x() << + ' ' << field[i].y() << + ' ' << field[i].z() << '\n'; + } + + return true; +} + +bool pFlow::PFtoVTK::regexCheck(const word &TYPENAME, const word &fieldType) +{ + std::regex match("pointField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>"); + std::smatch search1; + std::smatch search2; + if (!std::regex_match(fieldType, search1, match)) + return false; + if (!std::regex_match(TYPENAME, search2, match)) + return false; + if (search1.size() != 3) + return false; + if (search1.size() != search2.size()) + return false; + return search1[1] == search2[1]; +} \ No newline at end of file diff --git a/utilities/pFlowToVTK/pointFieldToVTK.hpp b/utilities/pFlowToVTK/pointFieldToVTK.hpp index 587ee6a4..8b24088c 100755 --- a/utilities/pFlowToVTK/pointFieldToVTK.hpp +++ b/utilities/pFlowToVTK/pointFieldToVTK.hpp @@ -1,443 +1,142 @@ /*------------------------------- phasicFlow --------------------------------- - O C enter of - O O E ngineering and - O O M ultiscale modeling of - OOOOOOO F luid flow + 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 + 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 + 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 __pointFieldToVTK_hpp__ #define __pointFieldToVTK_hpp__ -#include - -#include "vtkFile.hpp" #include "systemControl.hpp" #include "pointStructure.hpp" #include "pointFields.hpp" - namespace pFlow::PFtoVTK { -/*template -bool addIntPointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - IntType* field, - IncludeMaskType includeMask ); + bool convertTimeFolderPointFields( + systemControl &control, + const fileSystem &destPath, + const word &bName); -template -bool addRealPointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - real* field, - IncludeMaskType includeMask ); + bool convertTimeFolderPointFieldsSelected( + systemControl &control, + const fileSystem &destPath, + const word &bName, + const wordVector &fieldsName, + bool mustExist); -template -bool addRealx3PointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - realx3* field, - IncludeMaskType includeMask );*/ + bool addUndstrcuturedGridField( + iOstream &os, + realx3 *position, + uint32 numPoints); -bool regexCheck(word TYPENAME, word fieldType) -{ - std::regex match("pointField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>"); - std::smatch search1, search2; - if(!std::regex_match(fieldType, search1, match))return false; - if(!std::regex_match(TYPENAME, search2, match))return false; - if(search1.size()!=3)return false; - if(search1.size()!=search2.size())return false; - return search1[1] == search2[1]; -} + bool convertRealTypePointField( + iOstream &os, + const IOfileHeader &header, + pointStructure &pStruct); -template -bool checkFieldType(word objectType) -{ - return regexCheck(pointField::TYPENAME(), objectType); -} + bool convertRealx3TypePointField( + iOstream &os, + const IOfileHeader &header, + pointStructure &pStruct); -/*template -bool convertIntPointField -( - iOstream& os, - const IOfileHeader& header, - const pointStructure& pStruct -) -{ + template + bool addIntPointField( + iOstream &os, + const word &fieldName, + IntType *field, + uint32 numData); - using PointFieldType = pointField; + bool addRealPointField( + iOstream &os, + const word &fieldName, + const real *field, + uint32 numData); - word objectType = header.objectType(); + bool addRealx3PointField( + iOstream &os, + const word &fieldName, + const realx3 *field, + uint32 numData); - if(!checkFieldType(objectType)) + template + bool checkFieldType(word objectType); + + bool regexCheck(const word &TYPENAME, const word &fieldType); + + template + inline bool checkFieldType(word objectType) { - return false; + return regexCheck(pointField::TYPENAME(), objectType); } - auto objField = IOobject::make - ( - header, - pStruct, - static_cast(0) - ); - - auto& Field = objField().template getObject(); - - T* data = Field.deviceVectorAll().data(); - - REPORT(2)<<"writing "<< greenColor <(objectType))return false; - - auto objField = IOobject::make - ( - header, - pStruct, - static_cast(0) - ); - - auto& Field = objField().getObject(); - - real* data = Field.hostVectorAll().data(); - - REPORT(2)<<"writing "<< greenColor <(objectType))return false; - - auto objField = IOobject::make - ( - header, - pStruct, - static_cast(0) - ); - - auto& Field = objField().getObject(); - - realx3* data = Field.hostVectorAll().data(); - - REPORT(2)<<"writing "<< greenColor < + inline bool convertIntPointField( + iOstream &os, + const IOfileHeader &header, + pointStructure &pStruct) { - os<< position[i].x()<<' '<< position[i].y()<<' '<; + + word objectType = header.objectType(); + + if (!checkFieldType(objectType)) + { + return false; + } + + auto field = PointFieldType( + header, + pStruct, + static_cast(0)); + + const IntType *data = field.deviceViewAll().data(); + + REPORT(1) << "writing " << Green_Text(header.objectName()) << " field to vtk.\n"; + + return addIntPointField( + os, + header.objectName(), + data, + pStruct.numActive()); } - os<<"CELLS "<< numPoints<<' '<< 2*numPoints<<'\n'; - for(uint32 i=0; i + inline bool addIntPointField( + iOstream &os, + const word &fieldName, + IntType *field, + uint32 numData) { - os<< 1 <<' '<< i<<'\n'; - } + if (numData == 0) + return true; - os<<"CELL_TYPES "<< numPoints<<'\n'; + os << "FIELD FieldData 1\n" + << fieldName << " 1 " << numData << " int\n"; + for (uint32 i = 0; i < numData; ++i) + { + os << field[i] << '\n'; + } - for(int32 i=0; i -bool addIntPointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - IntType* field, - IncludeMaskType includeMask ) -{ - if(numActivePoints==0) return true; - - auto [iFirst, iLast] = includeMask.activeRange(); - - os << "FIELD FieldData 1\n"<< - fieldName << " 1 " << numActivePoints << " int\n"; - for(int32 i=iFirst; i -bool addRealPointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - real* field, - IncludeMaskType includeMask ) -{ - if(numActivePoints==0) return true; - - auto [iFirst, iLast] = includeMask.activeRange(); - - os << "FIELD FieldData 1\n"<< - fieldName << " 1 " << numActivePoints << " float\n"; - for(int32 i=iFirst; i -bool addRealx3PointField( - iOstream& os, - word fieldName, - int32 numActivePoints, - realx3* field, - IncludeMaskType includeMask ) -{ - if(numActivePoints==0) return true; - - auto [iFirst, iLast] = includeMask.activeRange(); - - os << "FIELD FieldData 1\n"<< - fieldName << " 3 " << numActivePoints << " float\n"; - for(int32 i=iFirst; i(vtk(), fieldHeader, pStruct); - convertIntPointField(vtk(), fieldHeader, pStruct); - convertIntPointField(vtk(), fieldHeader, pStruct); - convertRealTypePointField(vtk(), fieldHeader, pStruct); - convertRealx3TypePointField(vtk(), fieldHeader, pStruct); - } - }*/ - - return true; } - - -bool convertTimeFolderPointFieldsSelected( - fileSystem timeFolder, - real time, - fileSystem destPath, - word bName, - wordVector fieldsName, - bool mustExist) -{ - - // check if pointStructure exist in this folder - /*IOfileHeader pStructHeader( - objectFile( - pointStructureFile__, - timeFolder, - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS) - ); - - if( !pStructHeader.headerOk(true) ) - { - output<(pStructHeader); - auto& pStruct = pStructObjPtr().getObject(); - - // get a list of files in this timeFolder; - - auto posVec = std::as_const(pStruct).pointPosition().hostVectorAll(); - auto* pos = posVec.data(); - - REPORT(1)<<"Writing pointStructure to vtk file with "<< yellowText(pStruct.numActive()) - <<" active particles"<(vtk(), fieldHeader, pStruct); - convertIntPointField(vtk(), fieldHeader, pStruct); - convertIntPointField(vtk(), fieldHeader, pStruct); - convertRealTypePointField(vtk(), fieldHeader, pStruct); - convertRealx3TypePointField(vtk(), fieldHeader, pStruct); - } - else - { - if(mustExist) - { - fatalErrorInFunction<<"Field " << fieldAddress << - " does not exist."< Date: Sat, 30 Mar 2024 08:35:16 -0700 Subject: [PATCH 2/2] pFlowToVTK finalized and tested - geometry conversion now can handle separate vtk files. --- src/phasicFlow/fileSystem/fileSystem.cpp | 10 +- src/phasicFlow/streams/Fstream/fileStream.cpp | 29 +- src/phasicFlow/streams/Fstream/fileStream.hpp | 4 +- src/phasicFlow/streams/Fstream/oFstream.cpp | 4 +- src/phasicFlow/streams/Fstream/oFstream.hpp | 2 +- utilities/Utilities/vtkFile/vtkFile.cpp | 17 +- utilities/Utilities/vtkFile/vtkFile.hpp | 12 +- utilities/pFlowToVTK/CMakeLists.txt | 1 + utilities/pFlowToVTK/geometric.cpp | 87 ----- utilities/pFlowToVTK/geometric.hpp | 78 ---- utilities/pFlowToVTK/pFlowToVTK.cpp | 15 +- utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp | 349 ++++++++++++++++++ utilities/pFlowToVTK/triSurfaceFieldToVTK.hpp | 234 +++--------- 13 files changed, 460 insertions(+), 382 deletions(-) delete mode 100755 utilities/pFlowToVTK/geometric.cpp delete mode 100755 utilities/pFlowToVTK/geometric.hpp create mode 100644 utilities/pFlowToVTK/triSurfaceFieldToVTK.cpp diff --git a/src/phasicFlow/fileSystem/fileSystem.cpp b/src/phasicFlow/fileSystem/fileSystem.cpp index 3423ac0b..a4275f56 100644 --- a/src/phasicFlow/fileSystem/fileSystem.cpp +++ b/src/phasicFlow/fileSystem/fileSystem.cpp @@ -33,7 +33,6 @@ bool pFlow::fileSystem::checkFileName(const word& name) "Invalid file name supplied " << name << "the following characters are not allowd: " << notPermittedCharsFile << endl; - fatalExit; return false; } @@ -57,9 +56,9 @@ pFlow::fileSystem::fileSystem( const word& dir, const word& file) { isDir_ = file.empty(); - if( !isDir_) + if( !isDir_ && !checkFileName(file)) { - checkFileName(file); + fatalExit; } try @@ -240,7 +239,10 @@ pFlow::fileSystem pFlow::fileSystem::operator() void pFlow::fileSystem::operator += (const word& fileName) { - checkFileName(fileName); + if(!checkFileName(fileName)) + { + fatalExit; + } if( isDir()) { diff --git a/src/phasicFlow/streams/Fstream/fileStream.cpp b/src/phasicFlow/streams/Fstream/fileStream.cpp index a577d83c..cbd14ae8 100755 --- a/src/phasicFlow/streams/Fstream/fileStream.cpp +++ b/src/phasicFlow/streams/Fstream/fileStream.cpp @@ -70,13 +70,30 @@ void pFlow::fileStream::openOutFile if(binary_) { - outStream_ = makeUnique< std::ofstream>( + if(append_) + { + outStream_ = makeUnique< std::ofstream>( + path.wordPath(), std::ios_base::out| std::ios::binary|std::ios::app); + } + else + { + outStream_ = makeUnique< std::ofstream>( path.wordPath(), std::ios_base::out| std::ios::binary); + } } else - outStream_ = makeUnique< std::ofstream>( + { + if(append_) + { + outStream_ = makeUnique< std::ofstream>( + path.wordPath(), std::ios_base::out|std::ios::app); + } + else + { + outStream_ = makeUnique< std::ofstream>( path.wordPath(), std::ios_base::out); - + } + } if(!outStream_->is_open()) { @@ -103,12 +120,14 @@ pFlow::fileStream::fileStream ( const fileSystem& path, bool outStream, - bool binary + bool binary, + bool append ) : inStream_(nullptr), outStream_(nullptr), - binary_(binary) + binary_(binary), + append_(append) { if(outStream) diff --git a/src/phasicFlow/streams/Fstream/fileStream.hpp b/src/phasicFlow/streams/Fstream/fileStream.hpp index 0cf6f34b..670c13e3 100755 --- a/src/phasicFlow/streams/Fstream/fileStream.hpp +++ b/src/phasicFlow/streams/Fstream/fileStream.hpp @@ -52,6 +52,8 @@ protected: bool binary_ = false; + bool append_ = false; + /// open input file void openInFile(const fileSystem& path); @@ -66,7 +68,7 @@ public: //// - Constructors /// From file path and input type and format. - fileStream( const fileSystem& path, bool outStream = false, bool binary = false); + fileStream( const fileSystem& path, bool outStream = false, bool binary = false, bool append = false); /// No copy fileStream(const fileStream&)= delete; diff --git a/src/phasicFlow/streams/Fstream/oFstream.cpp b/src/phasicFlow/streams/Fstream/oFstream.cpp index 54e1606a..95da62ae 100755 --- a/src/phasicFlow/streams/Fstream/oFstream.cpp +++ b/src/phasicFlow/streams/Fstream/oFstream.cpp @@ -22,9 +22,9 @@ Licence: #include "oFstream.hpp" -pFlow::oFstream::oFstream (const fileSystem& path, bool binary) +pFlow::oFstream::oFstream (const fileSystem& path, bool binary, bool append) : - fileStream(path, true, binary), + fileStream(path, true, binary, append), Ostream ( fileStream::outStream(), diff --git a/src/phasicFlow/streams/Fstream/oFstream.hpp b/src/phasicFlow/streams/Fstream/oFstream.hpp index 3092b2ca..1b1699f6 100755 --- a/src/phasicFlow/streams/Fstream/oFstream.hpp +++ b/src/phasicFlow/streams/Fstream/oFstream.hpp @@ -45,7 +45,7 @@ public: //// - Constructors /// From file path and format - oFstream (const fileSystem& path, bool binary = false); + oFstream (const fileSystem& path, bool binary = false, bool append = false); /// No copy constructor oFstream( const oFstream& src) = delete; diff --git a/utilities/Utilities/vtkFile/vtkFile.cpp b/utilities/Utilities/vtkFile/vtkFile.cpp index fe0755f4..dc4b9039 100755 --- a/utilities/Utilities/vtkFile/vtkFile.cpp +++ b/utilities/Utilities/vtkFile/vtkFile.cpp @@ -21,11 +21,14 @@ Licence: #include "vtkFile.hpp" -bool pFlow::vtkFile::openStream() +bool pFlow::vtkFile::openStream(bool wHeader) { - oStream_ = makeUnique( fileName() ); + oStream_ = makeUnique( fileName(), false, append_ ); if( !oStream_ )return false; - return writeHeader(); + if(wHeader) + return writeHeader(); + else + return true; } bool pFlow::vtkFile::vtkFile::writeHeader() @@ -49,15 +52,17 @@ pFlow::vtkFile::vtkFile ( const fileSystem dir, const word& bName, - real time + real time, + bool append ) : dirPath_(dir), baseName_(bName), - time_(time) + time_(time), + append_(append) { - if(!openStream()) + if(!openStream(!append)) { fatalErrorInFunction << " error in creating vtkFile "< oStream_= nullptr; - bool openStream(); + bool openStream(bool wHeader); virtual bool writeHeader(); public: - vtkFile(const fileSystem dir, const word& bName, real time); + vtkFile( + const fileSystem dir, + const word& bName, + real time, + bool append = false); virtual ~vtkFile() = default; @@ -56,7 +62,7 @@ public: { if(!oStream_) { - if(!openStream()) + if(!openStream(!append_)) { fatalErrorInFunction<< " error in opening vtkFile "<< fileName() < -bool pFlow::dataToVTK( vtkFile& vtk, const triSurface& surface ) -{ - - - auto nP = surface.numPoints(); - auto hPoints = surface.points().hostVector(); - - vtk() << "DATASET POLYDATA" << endl; - vtk() << "POINTS " << nP << " float" << endl; - - - for ( auto i=0; i -bool pFlow::dataToVTK( vtkFile& vtk, const multiTriSurface& surface ) -{ - - auto nP = surface.numPoints(); - auto hPoints = surface.points().hostVector(); - - vtk() << "DATASET POLYDATA" << endl; - vtk() << "POINTS " << nP << " float" << endl; - - - for ( auto i=0; i -bool geomObjectToVTK(IOfileHeader& header, real time, fileSystem destPath, word bName) -{ - - if( ObjType::TYPENAME() != header.objectType() )return false; - - auto ioObjPtr = IOobject::make(header); - - auto& data = ioObjPtr().template getObject(); - - vtkFile vtk(destPath, bName, time); - - if(!vtk) return false; - - REPORT(1)<<"Converting geometry to vtk."< -bool dataToVTK(vtkFile& vtk, const Type& dataEntity) -{ - fatalErrorInFunction<< - "not implemented function!"; - fatalExit; - return false; -} - -template<> -bool dataToVTK( vtkFile& vtk, const triSurface& surface ); - -template<> -bool dataToVTK( vtkFile& vtk, const multiTriSurface& surface ); - - -} - -#endif //__geometric_hpp__ diff --git a/utilities/pFlowToVTK/pFlowToVTK.cpp b/utilities/pFlowToVTK/pFlowToVTK.cpp index be53c75d..44cc6ed8 100755 --- a/utilities/pFlowToVTK/pFlowToVTK.cpp +++ b/utilities/pFlowToVTK/pFlowToVTK.cpp @@ -26,7 +26,7 @@ Licence: #include "Vectors.hpp" #include "phasicFlowKokkos.hpp" #include "pointFieldToVTK.hpp" -//#include "triSurfaceFieldToVTK.hpp" +#include "triSurfaceFieldToVTK.hpp" //#include "readControlDict.hpp" @@ -60,10 +60,10 @@ int main(int argc, char** argv ) "path"); bool separateSurfaces = false; - cmds.addOption( + cmds.add_flag( "-s,--separate-surfaces", separateSurfaces, - "surfaces in the geometry are converted separatedly"); + "use this when you want to have sub-surfaces in separate files"); wordVector fields; bool allFields = true; @@ -117,15 +117,16 @@ int main(int argc, char** argv ) if( !validRange.isMember( folders.time() ) )continue; output<< "time: " << Cyan_Text( folders.time() )<<" s" <(objectType))return false; + + auto field = realx3TriSurfaceField_H + ( + header, + tSurface, + static_cast(0) + ); + + const realx3* data = field.deviceViewAll().data(); + + REPORT(1)<<"writing "<< greenColor <(objectType))return false; + + auto field = realx3TriSurfaceField_H + ( + header, + tSurface, + static_cast(0) + ); + + const realx3* data = field.deviceViewAll().data(); + + /*REPORT(1)<<"writing "<< greenColor < -#include "vtkFile.hpp" +#include "pointFieldToVTK.hpp" #include "triSurface.hpp" #include "multiTriSurface.hpp" #include "triSurfaceFields.hpp" -#include "IOobject.hpp" + namespace pFlow::TSFtoVTK { -bool regexCheck(word TYPENAME, word fieldType) +bool convertTimeFolderTriSurfaceFields( + systemControl& control, + const fileSystem& destPath, + const word& bName, + bool separate); + + +bool triSurfaceToVTK(iOstream &os, + const realx3 *points, + const uint32x3 *vertices, + const subSurface &subSurf); + +bool triSurfaceToVTK(iOstream &os, + const realx3* points, + const uint32x3* vertices, + uint32 numPoints, + uint32 numTris); + +bool convertTimeFolderTriSurfaceFieldsSingle( + multiTriSurface& surface, + const fileSystem& destPath, + real time, + const word& bName); + +bool convertTimeFolderTriSurfaceFieldsSeparate( + multiTriSurface& surface, + const fileSystem& destPath, + real time, + const word& bName); + +inline +bool regexCheck(const word& TYPENAME, const word& fieldType) { std::regex match("triSurfaceField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>"); - std::smatch search1, search2; + std::smatch search1; + std::smatch search2; if(!std::regex_match(fieldType, search1, match))return false; if(!std::regex_match(TYPENAME, search2, match))return false; if(search1.size()!=3)return false; @@ -45,201 +77,27 @@ bool regexCheck(word TYPENAME, word fieldType) } template -bool checkFieldType(word objectType) +inline +bool checkTriFieldType(word objectType) { - //if( pointField::TYPENAME() == objectType )return true; - //if( pointField::TYPENAME() == objectType ) return true; - //if( pointField::TYPENAME() == objectType )return true; - return regexCheck(triSurfaceField::TYPENAME(), objectType); - -} - -template -bool triDataToVTK(iOstream& os, const Type& dataEntity) -{ - fatalErrorInFunction<< - "not implemented function!"; - fatalExit; - return false; -} - -template<> -bool triDataToVTK(iOstream& os, const triSurface& surface ) -{ - auto nP = surface.numPoints(); - auto hPoints = surface.points().hostVector(); - - os << "DATASET POLYDATA" << endl; - os << "POINTS " << nP << " float" << endl; - - - for ( auto i=0; i -bool triDataToVTK(iOstream& os, const multiTriSurface& surface ) -{ - auto nP = surface.numPoints(); - auto hPoints = surface.points().hostVector(); - - os << "DATASET UNSTRUCTURED_GRID" << endl; - os << "POINTS " << nP << " float" << endl; - - - for ( auto i=0; i::TYPENAME(), objectType); } bool convertRealx3TypetriSurfaceField( iOstream& os, const IOfileHeader& header, - const multiTriSurface& tSurface) -{ - word objectType = header.objectType(); + multiTriSurface& tSurface); - if(!checkFieldType(objectType))return false; - - auto objField = IOobject::make - ( - header, - tSurface, - static_cast(0) - ); - - auto& Field = objField().getObject(); - - realx3* data = Field.hostVectorAll().data(); - - REPORT(2)<<"writing "<< greenColor <(triSurfaeHeader); - auto& tSurface = triSurfaceObjPtr().getObject(); - - // get a list of files in this timeFolder; - REPORT(1)<<"Wrting triSurface mesh/Geometry to vtk file."<