mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-12 16:26:23 +00:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user