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
This commit is contained in:
HRN 2025-01-09 19:16:18 +03:30
parent d39e1ec27b
commit 66c3cda39e
17 changed files with 530 additions and 106 deletions

View File

@ -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

View File

@ -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;

View File

@ -36,9 +36,9 @@ pFlow::pointSorting::pointSorting(const dictionary & dict)
)
{
if( performSorting_() )
REPORT(1)<<"Point sorting is "<<Yellow_Text("active")<<" in simulation"<<END_REPORT;
REPORT(2)<<"Point sorting is "<<Yellow_Text("active")<<" in simulation"<<END_REPORT;
else
REPORT(1)<<"Point sorting is "<<Yellow_Text("inactive")<<" in simulation"<<END_REPORT;
REPORT(2)<<"Point sorting is "<<Yellow_Text("inactive")<<" in simulation"<<END_REPORT;
}
pFlow::uint32IndexContainer

View File

@ -113,7 +113,7 @@ pFlow::pointStructure::pointStructure
(
simulationDomain::create(control)
),
pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
//pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
boundaries_
(
*this
@ -130,6 +130,8 @@ pFlow::pointStructure::pointStructure
"Error in reading from file "<<IOobject::path()<<endl;
fatalExit;
}
pointSorting_ = makeUnique<pointSorting>(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"<<endl;
fatalExit;
}
pointSorting_ = makeUnique<pointSorting>(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()

View File

@ -54,7 +54,7 @@ private:
//// - data members
uniquePtr<simulationDomain> simulationDomain_ = nullptr;
pointSorting pointSorting_;
uniquePtr<pointSorting> pointSorting_ = nullptr;
boundaryList boundaries_;

View File

@ -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 <size_t s>
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<uint16_t*>(data);
*reinterpret_cast<uint16_t*>(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<uint32_t*>(data);
*reinterpret_cast<uint32_t*>(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<uint64_t*>(data);
*reinterpret_cast<uint64_t*>(data) = (ref64 >> 56) | (ref64 << 56) |
((ref64 & 0x00ff000000000000) >> 40) | ((ref64 & 0x000000000000ff00) << 40) |
((ref64 & 0x0000ff0000000000) >> 24) | ((ref64 & 0x0000000000ff0000) << 24) |
((ref64 & 0x000000ff00000000) >> 8) | ((ref64 & 0x00000000ff000000) << 8);
}
};
template<typename T>
inline T byteSwaper(const T& p)
{
union
{
T value;
char data[sizeof(T)];
} temp = { p };
vtkByteSwapper<sizeof(T)>::Swap(temp.data);
return temp.value;
}
} // pFlow
#endif //__vtkByteSwapper_h__

View File

@ -23,7 +23,7 @@ Licence:
bool pFlow::vtkFile::openStream(bool wHeader)
{
oStream_ = makeUnique<oFstream>( fileName(), false, append_ );
oStream_ = makeUnique<oFstream>( 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))

View File

@ -34,15 +34,17 @@ class vtkFile
{
protected:
fileSystem dirPath_;
uniquePtr<oFstream> oStream_= nullptr;
word baseName_;
real time_ = 0.0;
bool binary_ = false;
bool append_=false;
uniquePtr<oFstream> 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;
};

View File

@ -1,8 +1,10 @@
set(source_files
fileSeries.cpp
pointFieldToVTK.cpp
triSurfaceFieldToVTK.cpp
pFlowToVTK.cpp
#geometric.cpp
)
set(link_lib phasicFlow Kokkos::kokkos Utilities)

View File

@ -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 "<<os.name()<<END_REPORT;
os<<"{\n";
os<<" \"file-series-version\" : \"1.0\",\n";
os<<" \"files\" : [\n";
const auto lastItem = std::prev(fList.end());
for(auto iter = fList.begin(); iter != fList.end(); ++iter)
{
os<<" {\"name\" : \"";
os<< iter->second;
os<<"\", \"time\" :";
os<<iter->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..."<<END_REPORT;
for(const auto& fSeries:timeFiles_)
{
writeOneBaseName(fSeries.first);
}
}
bool pFlow::PFtoVTK::fileSeries::addTimeFile(const word& baseName, real time, const word &fileName)
{
fileSystem fs(fileName);
word relFileName = fs.relative(destDir_).wordPath();
if( auto [iter, found]=timeFiles_.findIf(baseName); found )
{
return iter->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<baseNames.size(); i++)
{
if(!addTimeFile(baseNames[i], time, fileNames[i]))
{
fatalErrorInFunction<<"Error in adding multiple time files\n";
return false;
}
}
return true;
}

View File

@ -0,0 +1,41 @@
#ifndef __fileSeries_hpp__
#define __fileSeries_hpp__
#include "fileStream.hpp"
#include "Map.hpp"
namespace pFlow::PFtoVTK
{
class fileSeries
{
private:
using TimeFileType = Map<real, word>;
Map<word, TimeFileType> 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__

View File

@ -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."<<END_INFO;
}
pFlow::word formatName = bindaryOutput__?"binary":"ascii";
pFlow::timeFolder folders(Control);
auto destFolder = pFlow::fileSystem(outFolder)/pFlow::word(pFlow::geometryFolder__);
auto destFolderField = pFlow::fileSystem(outFolder);
auto destFolderGeometry = pFlow::fileSystem(outFolder)/pFlow::word(pFlow::geometryFolder__);
auto destFolderField = pFlow::fileSystem(outFolder)/pFlow::word("particles");
pFlow::wordList geomfiles{"triSurface"};
@ -109,6 +125,12 @@ int main(int argc, char** argv )
validRange.addIntervalRange(folders.startTime(), folders.endTime());
}
{
pFlow::PFtoVTK::fileSeries timeSeries{pFlow::fileSystem(outFolder)};
pFlow::word fileName;
pFlow::wordList geomFileNames;
pFlow::wordList surfNames;
do
{
Control.time().setTime(folders.time());
@ -119,22 +141,27 @@ int main(int argc, char** argv )
{
if(!pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields(
Control, destFolder, "surface", separateSurfaces))
Control, destFolderGeometry, "surface", separateSurfaces, surfNames, geomFileNames))
{
fatalExit;
return 1;
}
}
timeSeries.addTimeFile(surfNames, folders.time(), geomFileNames);
}
if(!noParticle)
{
REPORT(1)<< "Converting pointFields to vtk file in "<< formatName<< " format ..."<<END_REPORT;
if(allFields)
{
if( !pFlow::PFtoVTK::convertTimeFolderPointFields(
Control,
destFolderField,
"sphereFields" ))
"particles",
fileName
)
)
{
fatalExit;
}
@ -143,14 +170,19 @@ int main(int argc, char** argv )
if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected(
Control,
destFolderField,
"sphereFields",
"particles",
fields,
!pFlow::equal(folders.time(),static_cast<pFlow::real>(0.0)) )
!pFlow::equal(folders.time(),static_cast<pFlow::real>(0.0)),
fileName
)
)
{
fatalExit;
}
}
}
timeSeries.addTimeFile("particles", folders.time(), fileName);
}
pFlow::output<<pFlow::endl;
@ -158,6 +190,8 @@ int main(int argc, char** argv )
}
while( folders++ );
}
pFlow::output<< "\nFinished successfully.\n";

View File

@ -4,10 +4,12 @@
#include "vocabs.hpp"
#include "pointFieldToVTK.hpp"
bool pFlow::PFtoVTK::convertTimeFolderPointFields(
systemControl &control,
const fileSystem &destPath,
const word &bName)
const word &bName,
word& filename)
{
fileSystem timeFolder = control.time().path();
@ -27,11 +29,14 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFields(
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;
@ -39,7 +44,7 @@ bool pFlow::PFtoVTK::convertTimeFolderPointFields(
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;
@ -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<uint32>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
//convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<int32>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<int64>(vtk(), fieldHeader, pStruct)||
//convertIntPointField<int64>(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<uint32>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
// convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<int32>(vtk(), fieldHeader, pStruct) ||
convertIntPointField<int64>(vtk(), fieldHeader, pStruct) ||
//convertIntPointField<int64>(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<numPoints; i++)
{
float x = byteSwaper(static_cast<float>(position[i].x()));
float y = byteSwaper(static_cast<float>(position[i].y()));
float z = byteSwaper(static_cast<float>(position[i].z()));
os.stdStream().write(reinterpret_cast<const char*>(&x), sizeof(x));
os.stdStream().write(reinterpret_cast<const char*>(&y), sizeof(y));
os.stdStream().write(reinterpret_cast<const char*>(&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<const char*>(&one_ro), sizeof(one_ro));
os.stdStream().write(reinterpret_cast<const char*>(&pN), sizeof(pN));
}
os<<'\n';
os << "CELL_TYPES " << numPoints<<'\n';
for (int32 i = 0; i < numPoints; i++)
{
os.stdStream().write(reinterpret_cast<const char*>(&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<real>(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<realx3>(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<float>(field[i]));
os.stdStream().write(reinterpret_cast<const char*>(&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<numData; i++)
{
float x = byteSwaper(static_cast<float>(field[i].x()));
float y = byteSwaper(static_cast<float>(field[i].y()));
float z = byteSwaper(static_cast<float>(field[i].z()));
os.stdStream().write(reinterpret_cast<const char*>(&x), sizeof(x));
os.stdStream().write(reinterpret_cast<const char*>(&y), sizeof(y));
os.stdStream().write(reinterpret_cast<const char*>(&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;
}

View File

@ -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 <typename IntType>
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 <typename IntType>
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 <typename IntType>
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<IntType, int> || std::is_same_v<IntType, const int> )
{
os << field[i] << '\n';
os << "FIELD FieldData 1\n"
<< fieldName << " 1 " << numData << " int\n";
}
else if( std::is_same_v<IntType, unsigned int>|| std::is_same_v<IntType, const unsigned int>)
{
os << "FIELD FieldData 1\n"
<< fieldName << " 1 " << numData << " unsigned_int\n";
}
else
{
WARNING<<"Field "<< fieldName<< " has invalid data type for conversion. Type is "
<<getTypeName<IntType>()<<END_WARNING;
return false;
}
if(bindaryOutput__)
{
for (uint32 i = 0; i < numData; ++i)
{
IntType val = byteSwaper(field[i]);
os.stdStream().write(reinterpret_cast<const char*>(&val), sizeof(IntType));
}
os<<'\n';
}
else
{
for (uint32 i = 0; i < numData; ++i)
{
os << field[i] << '\n';
}
}
return true;
}

View File

@ -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<<endl;
return true;
@ -198,7 +212,9 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSeparate(
multiTriSurface &surface,
const fileSystem &destPath,
real time,
const word &bName)
const word &bName,
wordList& surfNames,
wordList& fileNames)
{
auto hPoints = surface.points().hostView();
@ -210,17 +226,23 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSeparate(
REPORT(1) << "Wrting triSurface geometry to vtk file . . ."<<
END_REPORT;
wordList sNames, fNames;
auto nSurf = surface.numSurfaces();
for(auto nS=0; nS<nSurf; nS++)
{
auto sName = surface.subSurfaceName(nS);
vtkFile vtk(destPath, groupNames(bName,sName), time);
auto sName = surface.subSurfaceName(nS);
word fName = groupNames(bName,sName,'_');
vtkFile vtk(destPath, fName, time, false);
REPORT(2) << "Wrting sub-surface to "<<
Green_Text(vtk.fileName())<<END_REPORT;
if (!vtk)
return false;
fNames.push_back(vtk.fileName().wordPath());
sNames.push_back(fName);
if (! triSurfaceToVTK(
vtk(),
pData,
@ -257,13 +279,15 @@ bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSeparate(
}
fileNames = fNames;
surfNames = sNames;
output<<endl;
return true;
}
bool pFlow::TSFtoVTK::convertRealx3TypetriSurfaceField(
iOstream& os,
Ostream& os,
const IOfileHeader& header,
multiTriSurface& tSurface)
{
@ -325,7 +349,7 @@ bool pFlow::TSFtoVTK::convertRealx3TypetriSurfaceFieldSeparate
auto& subSurf = tSurface.subSurfaces()[nS];
auto sName = subSurf.name();
vtkFile vtk(destPath, groupNames(bName,sName), time, true);
vtkFile vtk(destPath, groupNames(bName,sName,'_'), time, false, true);
REPORT(2) << "Wrting sub-surface to "<<
Green_Text(vtk.fileName())<<END_REPORT;

View File

@ -37,15 +37,17 @@ bool convertTimeFolderTriSurfaceFields(
systemControl& control,
const fileSystem& destPath,
const word& bName,
bool separate);
bool separate,
wordList& surfNames,
wordList& fileNames);
bool triSurfaceToVTK(iOstream &os,
bool triSurfaceToVTK(Ostream &os,
const realx3 *points,
const uint32x3 *vertices,
const subSurface &subSurf);
bool triSurfaceToVTK(iOstream &os,
bool triSurfaceToVTK(Ostream &os,
const realx3* points,
const uint32x3* vertices,
uint32 numPoints,
@ -55,13 +57,17 @@ bool convertTimeFolderTriSurfaceFieldsSingle(
multiTriSurface& surface,
const fileSystem& destPath,
real time,
const word& bName);
const word& bName,
wordList& surfNames,
wordList& fileNames);
bool convertTimeFolderTriSurfaceFieldsSeparate(
multiTriSurface& surface,
const fileSystem& destPath,
real time,
const word& bName);
const word& bName,
wordList& surfNames,
wordList& fileNames);
inline
bool regexCheck(const word& TYPENAME, const word& fieldType)
@ -84,7 +90,7 @@ bool checkTriFieldType(word objectType)
}
bool convertRealx3TypetriSurfaceField(
iOstream& os,
Ostream& os,
const IOfileHeader& header,
multiTriSurface& tSurface);

View File

@ -132,7 +132,7 @@ bool pFlow::postprocess::processTimeFolder(const timeFolder& tFolder)
bool pFlow::postprocess::writeToVTK(fileSystem destPath, word bName)const
{
vtkFile vtk(destPath, bName, time_);
vtkFile vtk(destPath, bName, time_, false);
if(!vtk) return false;