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."<