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:
@ -1,8 +1,10 @@
|
||||
|
||||
set(source_files
|
||||
fileSeries.cpp
|
||||
pointFieldToVTK.cpp
|
||||
triSurfaceFieldToVTK.cpp
|
||||
pFlowToVTK.cpp
|
||||
|
||||
#geometric.cpp
|
||||
)
|
||||
set(link_lib phasicFlow Kokkos::kokkos Utilities)
|
||||
|
85
utilities/pFlowToVTK/fileSeries.cpp
Normal file
85
utilities/pFlowToVTK/fileSeries.cpp
Normal 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;
|
||||
}
|
41
utilities/pFlowToVTK/fileSeries.hpp
Normal file
41
utilities/pFlowToVTK/fileSeries.hpp
Normal 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__
|
@ -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";
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user